function print_child_tree($id, $depth = 0) { $children = get_inventory_children($id); if ($children === false || sizeof($children) == 0) { return; } foreach ($children as $child) { print_inventory_object($child['id'], $children, array(), true, true, $depth); if ($child['id_contract']) { /* Only check ACLs if the inventory has a contract */ if (!give_acl($config['id_user'], get_inventory_group($child['id']), "VR")) { continue; } else { print_child_tree($child['id'], $depth + 1); } } } }
/** * Prints the details of an inventory object and, optionally, its children. * * @param int ID of the object. * @param array Array containing inventory objects. * @param array Inventory object tree. * @param bool Show child nodes. * @param bool Show incident statistics. * @param int Call depth, used for indentation. * @param bool Whether to return an output string or echo now (optional, echo by default). */ function print_inventory_object($id, $inventory, $tree, $show_children = false, $show_incidents = false, $depth = 0, $return = false) { global $config; $output = ''; if (!isset($inventory[$id])) { return ''; } $object = $inventory[$id]; if ($object['id_contract']) { /* Only check ACLs if the inventory has a contract */ if (!give_acl($config['id_user'], get_inventory_group($object['id']), "VR")) { return ''; } } $output .= '<tr id="result-' . $object['id'] . '">'; $output .= '<td><strong>#' . $object['id'] . '</strong></td>'; $output .= '<td>'; if ($depth > 0) { $output .= '<span class="indent">'; for ($i = 0; $i < $depth; $i++) { $output .= ' '; } $output .= '</span>'; $output .= '<img src="images/copy.png" />'; } $output .= $object['name'] . '</td>'; if ($show_incidents) { $incidents = get_incidents_on_inventory($object['id'], false); $total_incidents = sizeof($incidents); $output .= '<td>'; if ($total_incidents) { $actived = 0; foreach ($incidents as $incident) { if ($incident['estado'] != 7 && $incident['estado'] != 6) { $actived++; } } $output .= '<img src="images/info.png" /> <strong>' . $actived . '</strong> / ' . $total_incidents; } $output .= '</td>'; } $companies = get_inventory_affected_companies($object['id'], false); $output .= '<td>'; if (isset($companies[0]['name'])) { $output .= $companies[0]['name']; } $output .= '</td>'; $building = get_building($object['id_building']); $output .= '<td>'; if ($building) { $output .= $building['name']; } $output .= '</td>'; $output .= '<td>' . $object['description'] . '</td>'; $output .= '</tr>'; // Print child objects if (!$show_children || !isset($tree[$object['id']])) { if ($return) { return $output; } echo $output; return; } foreach ($tree[$object['id']] as $child) { $output .= print_inventory_object($child, $inventory, $tree, $show_children, $show_incidents, $depth + 1, true); } if ($return) { return $output; } echo $output; }
array_push($tree[$id_parent], $id); } else { array_push($tree_root, $id); } } echo '<h3>' . __('Inventory objects statistics') . '</h3>'; print_inventory_stats($inventories); echo '<div style="clear: both"></div>'; echo '<h3>' . __('Inventory objects list') . '</h3>'; echo '<table class="listing" width="95%">'; echo '<tr>'; echo '<th>' . __('ID') . '</th>'; echo '<th>' . __('Name') . '</th>'; echo '<th>' . __('Active Incidents') . '</th>'; echo '<th>' . __('Company') . '</th>'; echo '<th>' . __('Building') . '</th>'; echo '<th>' . __('Title') . '</th>'; echo '</tr>'; $total_inventories = 0; foreach ($tree_root as $object) { print_inventory_object($object, $inventories, $tree, true, true); $total_inventories++; } if ($total_inventories == 0) { echo '<tr><td colspan="6">' . __('No inventory objects found') . '</td></tr>'; } echo '</table>'; echo '<div style="width: 95%; text-align: left; ">'; include 'general/footer.php'; echo '</div>'; echo '</div>';