Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print rack sheet #3912

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/tools/racks/index.php
Expand Up @@ -25,6 +25,7 @@
elseif (isset($_GET['subnetId'])) {
# map
if($_GET['subnetId']=="map") { include("print-racks.php"); }
elseif(isset($_GET['sPage'])){ include("print-rack-page.php"); }
else { include("print-single-rack.php"); }
}
else { include("print-racks.php"); }
else { include("print-racks.php"); }
209 changes: 209 additions & 0 deletions app/tools/racks/print-rack-page.php
@@ -0,0 +1,209 @@
<?php

/**
* Script to print racks
***************************/

# verify that user is logged in
$User->check_user_session();

# verify module permissions
$User->check_module_permissions ("racks", User::ACCESS_R, true);

# check that rack support isenabled
if ($User->settings->enableRACK!="1") {
$Result->show("danger", _("RACK management disabled."), false);
}
else {
# validate integer
if(!is_numeric($_GET['subnetId'])) { header("Location: ".create_link($_GET['page'], "racks")); $error =_("Invalid rack Id"); }
# init racks object
$Racks = new phpipam_rack ($Database);
# fetch all racks
$rack = $Racks->fetch_rack_details ($_GET['subnetId']);
$rack_devices = $Racks->fetch_rack_devices ($_GET['subnetId']);
//$rack_contents = $Racks->fetch_rack_contents ($_GET['subnetId']);
$rack_contents = false;
$Racks->add_rack_start_print($rack_devices);
$Racks->add_rack_start_print($rack_contents);

// rack check
if($rack===false) { header("Location: ".create_link($_GET['page'], "racks")); $error =_("Invalid rack Id"); }

// get custom fields
$cfields = $Tools->fetch_custom_fields ('racks');
}

# if error set print it, otherwise print rack
if (isset($error)) { ?>
<h4><?php print _('RACK details'); ?></h4>
<hr>

<div class="btn-group">
<a href='javascript:history.back()' class='btn btn-sm btn-default' style='margin-bottom:10px;'><i class='fa fa-chevron-left'></i> <?php print _('Racks'); ?></a>
</div>
<br>
<?php
$Result->show("danger", $error, false);
die();
}

$location = $Tools->fetch_object("locations", "id", $rack->location);
?>
<style>
@page {
margin-left: 5mm;
margin-right: 5mm;
}
@media print {
body {
margin-left: 5mm;
margin-right: 5mm;
}
}
html body, html .wrapper {
background-image: none;
margin: 0;
}
td#subnetsContent {
padding-top: 0 !important;
}
html h1, html h2, html h3, html h4, html h5, * {
color: black !important;
margin: 0;
}
h2 {
float: left;
}
h3 {
float: right;
}
hr {
clear: both;
}
#header, .content, #subnetsLeft, .footer {
display: none;
}
html hr {
border-top: none;
border-bottom: 1px solid rgba(0,0,0,0.1);
}
table#deviceList {
margin-left: 20px;
}
table#deviceList td {
font-size: 8pt;
border-bottom: 1px solid black;
padding: 3px;
}
table#deviceListWrapper {
margin: auto;
width: auto;
margin-top: 20px;
}
</style>
<h2>Rack <?php print preg_replace('/^' . preg_quote($location->name) . '-/', '', $rack->name); ?></h2>
<h3><?php print $location->name; ?> <?php print $location->description ?></h3>
<hr>
<div style="float: right;"><?php print _('Date') . ': ' . date('Y-m-d');?></div>
<?php print $rack->description; ?>
<?php
if(sizeof($cfields) > 0) {
print '<br>';
foreach($cfields as $key=>$field) {
if(empty($rack->{$key})) continue;
$rack->{$key} = str_replace("\n", "<br>",$rack->{$key});
print $Tools->print_custom_field_name($key) . ": ";
print $rack->{$key};
print '<br>';
}
}
?>

<table id="deviceListWrapper">
<tr>
<td>
<img src="<?php print $Tools->create_rack_link($rack->id); ?>" style="width: 180px;">
<?php if($rack->hasBack!="0") { ?>
<img src="<?php print $Tools->create_rack_link($rack->id, NULL, true); ?>" style="width: 180px;">
<?php } ?>
</td>
<td>

<table id="deviceList">
<?php
// attached devices
if($User->get_module_permissions ("devices")>=User::ACCESS_R) {
// devices
if ($rack_devices===false) $rack_devices = array();
if ($rack_contents===false) $rack_contents = array();
reset($rack_devices);
reset($rack_contents);
$prev = false;
$is_back = false;
do {
if (!($cd = current($rack_devices))) {
$cur = current($rack_contents);
next($rack_contents);
$ctype = 'content';
} elseif (!($cc = current($rack_contents))) {
$cur = current($rack_devices);
next($rack_devices);
$ctype = 'device';
} else {
if ($cd->rack_start < $cc->rack_start) {
$cur = $cd;
$ctype = 'device';
next($rack_devices);
} else {
$cur = $cc;
next($rack_contents);
$ctype = 'content';
}
}
if ($cur === false) break; # done here

// first
if($prev===false && $rack->hasBack!="0") {
print "<tr><th colspan=\"3\">"._("Front side").":</th></tr>";
}
if($prev===false){
print "<tr>";
foreach($config['print_rack_fields'] as $field => $headline){
print "<td>" . $headline . "</td>";
}
print "</tr>";
}

// first in back
if ($rack->hasBack!="0" && $cur->rack_start>$rack->size && !$is_back) {
print "<tr><th colspan=\"3\"><br>"._("Back side").":</th></tr>";
print "<tr>";
foreach($config['print_rack_fields'] as $field => $headline){
print "<td>" . $headline . "</td>";
}
print "</tr>";
$is_back = true;
}

if ($ctype == 'device') {
$cur->name = $cur->hostname;
}
print "<tr>";
foreach($config['print_rack_fields'] as $field => $headline){
print "<td>" . $cur->{$field} . "</td>";
}

print "</tr>";

# next
$prev = $cur;
} while ($cur);
}
?>
</table>
</td></tr>
</table>
<script>
window.print();
</script>
1 change: 1 addition & 0 deletions app/tools/racks/print-racks-list.php
Expand Up @@ -125,6 +125,7 @@
$links[] = ["type"=>"header", "text"=>_("Show rack")];
$links[] = ["type"=>"link", "text"=>_("Show rack"), "href"=>create_link($_GET['page'], "racks", $r->id), "icon"=>"eye", "visible"=>"dropdown"];
$links[] = ["type"=>"link", "text"=>_("Show popup"), "href"=>"", "class"=>"showRackPopup", "dataparams"=>"data-rackId='$r->id' data-deviceId='0'", "icon"=>"server"];
$links[] = ["type"=>"link", "text"=>_("Print rack"), "href"=>create_link('tools', 'racks', $r->id, 'print'), "icon"=>"print"];
$links[] = ["type"=>"divider"];
}
if($User->get_module_permissions ("racks")>=User::ACCESS_RW) {
Expand Down
1 change: 1 addition & 0 deletions app/tools/racks/print-single-rack.php
Expand Up @@ -151,6 +151,7 @@
$links = [];
# permissions
if($User->get_module_permissions ("racks")>=User::ACCESS_RW) {
$links[] = ["type"=>"link", "text"=>_("Print rack"), "href"=>create_link('tools', 'racks', $rack->id, 'print'), "icon"=>"print"];
$links[] = ["type"=>"header", "text"=>_("Manage")];
$links[] = ["type"=>"link", "text"=>_("Edit rack"), "href"=>"", "class"=>"editRack", "dataparams"=>" data-action='edit' data-rackid='$rack->id'", "icon"=>"pencil"];
}
Expand Down
5 changes: 5 additions & 0 deletions config.dist.php
Expand Up @@ -164,6 +164,11 @@
$config['requests_public'] = true; // Show IP request module on login page
$config['split_ip_custom_fields'] = false; // Show custom fields in separate table when editing IP address
$config['footer_message'] = ""; // Custom message included in the footer of every page
$config['print_rack_fields'] = [ // Fields to show in the table of a Rack printout
'rack_start_print' => '#', // <name of Fields> => <Headline>
'name' => 'Name',
'description' => 'Description',
];

/**
* PHP CLI binary for scanning and network discovery.
Expand Down
27 changes: 26 additions & 1 deletion functions/classes/class.Rackspace.php
Expand Up @@ -317,6 +317,7 @@ public function draw_rack ($id, $deviceId = false, $is_back = false, $draw_names
"name"=>$c->name,
"startLocation"=>$c->rack_start-$rack->size,
"size"=>$c->rack_size,
"type"=>"content",
"rackName"=>$rack->name
);
// if startlocation is not set
Expand All @@ -335,6 +336,7 @@ public function draw_rack ($id, $deviceId = false, $is_back = false, $draw_names
"name"=>$c->name,
"startLocation"=>$c->rack_start,
"size"=>$c->rack_size,
"type"=>"content",
"rackName"=>$rack->name
);
// if startlocation is not set
Expand All @@ -359,6 +361,7 @@ public function draw_rack ($id, $deviceId = false, $is_back = false, $draw_names
"name"=>$d->hostname,
"startLocation"=>$d->rack_start-$rack->size,
"size"=>$d->rack_size,
"type"=>"device",
"rackName"=>$rack->name
);
// if startlocation is not set
Expand All @@ -377,6 +380,7 @@ public function draw_rack ($id, $deviceId = false, $is_back = false, $draw_names
"name"=>$d->hostname,
"startLocation"=>$d->rack_start,
"size"=>$d->rack_size,
"type"=>"device",
"rackName"=>$rack->name
);
// if startlocation is not set
Expand Down Expand Up @@ -424,7 +428,7 @@ private function set_rack () {
*/
public function set_active_rack_device ($id) {
foreach ($this->Rack->getContent() as $content) {
if ($content->getId() == $id) {
if ($content->getId() == $id && $content->getType() == "device") {
$content->setActive();
}
}
Expand Down Expand Up @@ -957,6 +961,27 @@ public function setActive($active = true) {
$this->active = $active;
}

/**
* returns type
*
* @access public
* @return string
*/
public function getType() {
return $this->type;
}

/**
* Sets type
*
* @access public
* @param string $type
* @return void
*/
public function setType($type) {
$this->type = $type;
}

/**
* Returns start position
*
Expand Down