/** * Show for PDF an resources : tasks informations * * @param $pdf object for the output * @param $ID of the resources */ static function pdfForResource(PluginPdfSimplePDF $pdf, PluginResourcesResource $appli) { global $DB; $ID = $appli->fields['id']; if (!$appli->can($ID, "r")) { return false; } if (!plugin_resources_haveRight("resources", "r")) { return false; } $query = "SELECT * \n FROM `glpi_plugin_resources_tasks` \n WHERE `plugin_resources_resources_id` = '{$ID}'\n AND `is_deleted` ='0'"; $result = $DB->query($query); $number = $DB->numrows($result); $i = $j = 0; $pdf->setColumnsSize(100); if ($number > 0) { $pdf->displayTitle('<b>' . self::getTypeName(2) . '</b>'); $pdf->setColumnsSize(14, 14, 14, 14, 16, 14, 14); $pdf->displayTitle('<b><i>' . __('Name'), __('Type'), __('Comments'), __('Duration'), __('Planning'), __('Resource manager', 'resources'), __('Group') . '</i></b>'); $i++; while ($j < $number) { $tID = $DB->result($result, $j, "id"); $actiontime_ID = $DB->result($result, $j, "actiontime"); $actiontime = ''; $units = Toolbox::getTimestampTimeUnits($actiontime_ID); $hour = $units['hour']; $minute = $units['minute']; if ($hour) { $actiontime = $hour . __('Hour', 'Hours', 2); } if ($minute || !$hour) { $actiontime .= $minute . __('Minute', 'Minutes', 2); } $restrict = " `plugin_resources_tasks_id` = '" . $tID . "' "; $plans = getAllDatasFromTable("glpi_plugin_resources_taskplannings", $restrict); if (!empty($plans)) { foreach ($plans as $plan) { $planification = Html::convDateTime($plan["begin"]) . " -> " . Html::convDateTime($plan["end"]); } } else { $planification = __('None'); } $users_id = $DB->result($result, $j, "users_id"); $managers = Html::clean(getUserName($users_id)); $name = $DB->result($result, $j, "name"); $task_type = $DB->result($result, $j, "plugin_resources_tasktypes_id"); $comment = $DB->result($result, $j, "comment"); $groups_id = $DB->result($result, $j, "groups_id"); $pdf->displayLine(Html::clean($name), Html::clean(Dropdown::getDropdownName("glpi_plugin_resources_tasktypes", $task_type)), $comment, $actiontime, Html::clean($planification), $managers, Html::clean(Dropdown::getDropdownName("glpi_groups", $groups_id))); $j++; } } else { $pdf->displayLine(__('No item found')); } $pdf->displaySpace(); }
/** * Show for PDF an resources - asociated devices * * @param $pdf object for the output * @param $ID of the resources */ static function pdfForResource(PluginPdfSimplePDF $pdf, PluginResourcesResource $appli) { global $DB, $CFG_GLPI; $ID = $appli->fields['id']; if (!$appli->can($ID, "r")) { return false; } if (!plugin_resources_haveRight("resources", "r")) { return false; } $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . _n('Associated item', 'Associated items', 2) . '</b>'); $query = "SELECT DISTINCT `itemtype` \n FROM `glpi_plugin_resources_resources_items` \n WHERE `plugin_resources_resources_id` = '{$ID}' \n ORDER BY `itemtype` "; $result = $DB->query($query); $number = $DB->numrows($result); if (Session::isMultiEntitiesMode()) { $pdf->setColumnsSize(12, 27, 25, 18, 18); $pdf->displayTitle('<b><i>' . __('Type'), __('Name'), __('Entity'), __('Serial Number'), __('Inventory number') . '</i></b>'); } else { $pdf->setColumnsSize(25, 31, 22, 22); $pdf->displayTitle('<b><i>' . __('Type'), __('Name'), __('Serial Number'), __('Inventory number') . '</i></b>'); } if (!$number) { $pdf->displayLine(__('No item found')); } else { for ($i = 0; $i < $number; $i++) { $type = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($type))) { continue; } if ($item->canView()) { $column = "name"; $table = getTableForItemType($type); $items = new $type(); $query = "SELECT `" . $table . "`.*, `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_resources_resources_items`, `" . $table . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $table . "`.`entities_id`) " . " WHERE `" . $table . "`.`id` = `glpi_plugin_resources_resources_items`.`items_id` \n AND `glpi_plugin_resources_resources_items`.`itemtype` = '{$type}' \n AND `glpi_plugin_resources_resources_items`.`plugin_resources_resources_id` = '{$ID}' "; if ($type != 'User') { $query .= getEntitiesRestrictRequest(" AND ", $table, '', '', $items->maybeRecursive()); } if ($items->maybeTemplate()) { $query .= " AND `" . $table . "`.`is_template` = '0'"; } $query .= " ORDER BY `glpi_entities`.`completename`, `" . $table . "`.`{$column}`"; if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { while ($data = $DB->fetch_assoc($result_linked)) { if (!$items->getFromDB($data["id"])) { continue; } $items_id_display = ""; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $items_id_display = " (" . $data["id"] . ")"; } if ($type == 'User') { $name = Html::clean(getUserName($data["id"])) . $items_id_display; } else { $name = $data["name"] . $items_id_display; } if ($type != 'User') { $entity = Html::clean(Dropdown::getDropdownName("glpi_entities", $data['entity'])); } else { $entity = "-"; } if (Session::isMultiEntitiesMode()) { $pdf->setColumnsSize(12, 27, 25, 18, 18); $pdf->displayLine($items->getTypeName(), $name, $entity, isset($data["serial"]) ? "" . $data["serial"] . "" : "-", isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-"); } else { $pdf->setColumnsSize(25, 31, 22, 22); $pdf->displayTitle($items->getTypeName(), $name, isset($data["serial"]) ? "" . $data["serial"] . "" : "-", isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-"); } } // Each device } } // numrows device } // type right } // each type } // numrows type }
function showMinimalList($params) { global $DB, $CFG_GLPI; $itemtype = "PluginResourcesDirectory"; $itemtable = $this->table; if (class_exists($itemtype)) { $item = new $itemtype(); } // Default values of parameters $p['link'] = array(); // $p['field'] = array(); // $p['contains'] = array(); // $p['searchtype'] = array(); // $p['sort'] = '1'; // $p['order'] = 'ASC'; // $p['start'] = 0; // $p['is_deleted'] = 0; $p['id'] = 0; $p['withtemplate'] = 0; $p['export_all'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; // $p['field2'] = ''; // $p['itemtype2'] = ''; $p['searchtype2'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } if ($p['export_all']) { $p['start'] = 0; } $PluginResourcesResource = new PluginResourcesResource(); $canedit = $PluginResourcesResource->can($p['id'], 'w'); // Manage defautlt seachtype value : for bookmark compatibility if (count($p['contains'])) { foreach ($p['contains'] as $key => $val) { if (!isset($p['searchtype'][$key])) { $p['searchtype'][$key] = 'contains'; } } } if (is_array($p['contains2']) && count($p['contains2'])) { foreach ($p['contains2'] as $key => $val) { if (!isset($p['searchtype2'][$key])) { $p['searchtype2'][$key] = 'contains'; } } } $target = $CFG_GLPI["root_doc"] . "/plugins/resources/front/directory.php"; $limitsearchopt = Search::getCleanedOptions("PluginResourcesDirectory"); $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == Search::GLOBAL_SEARCH) { $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT; } } $entity_restrict = $PluginResourcesResource->isEntityAssign(); // Get the items to display $toview = Search::addDefaultToView("User"); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser("PluginResourcesDirectory", Session::getLoginUserID()); if (count($displaypref)) { foreach ($displaypref as $val) { array_push($toview, $val); } } // Add searched items if (count($p['field']) > 0) { foreach ($p['field'] as $key => $val) { if (!in_array($val, $toview) && $val != 'all' && $val != 'view') { array_push($toview, $val); } } } // Add order item if (!in_array($p['sort'], $toview)) { array_push($toview, $p['sort']); } // Clean toview array $toview = array_unique($toview); foreach ($toview as $key => $val) { if (!isset($limitsearchopt[$val])) { unset($toview[$key]); } } $toview_count = count($toview); //// 1 - SELECT $query = "SELECT " . Search::addDefaultSelect("User"); // Add select for all toview item foreach ($toview as $key => $val) { $query .= self::addSelect("PluginResourcesDirectory", $val, $key, 0); } $query .= "`glpi_plugin_resources_resources`.`id` AS id "; //// 2 - FROM AND LEFT JOIN // Set reference table $query .= " FROM `" . $itemtable . "`"; // Init already linked tables array in order not to link a table several times $already_link_tables = array(); // Put reference table array_push($already_link_tables, $itemtable); // Add default join $COMMONLEFTJOIN = Search::addDefaultJoin("PluginResourcesDirectory", $itemtable, $already_link_tables); $query .= $COMMONLEFTJOIN; $searchopt = array(); $searchopt["PluginResourcesDirectory"] =& Search::getOptions("PluginResourcesDirectory"); // Add all table for toview items foreach ($toview as $key => $val) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$val]["table"], $searchopt["PluginResourcesDirectory"][$val]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$val]["joinparams"]); } // Search all case : if (in_array("all", $p['field'])) { foreach ($searchopt[$itemtype] as $key => $val) { // Do not search on Group Name if (is_array($val)) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$key]["table"], $searchopt["PluginResourcesDirectory"][$key]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$key]["joinparams"]); } } } $ASSIGN = " `glpi_plugin_resources_resources`.`is_leaving` = 0 AND `glpi_users`.`is_active` = 1 AND "; //// 3 - WHERE // default string $COMMONWHERE = Search::addDefaultWhere($itemtype); $first = empty($COMMONWHERE); // Add deleted if item have it if ($PluginResourcesResource && $PluginResourcesResource->maybeDeleted()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`glpi_plugin_resources_resources`.`is_deleted` = '" . $p['is_deleted'] . "' "; } // Remove template items if ($PluginResourcesResource && $PluginResourcesResource->maybeTemplate()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`glpi_plugin_resources_resources`.`is_template` = '0' "; } // Add Restrict to current entities if ($entity_restrict) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } if (isset($CFG_GLPI["union_search_type"][$itemtype])) { // Will be replace below in Union/Recursivity Hack $COMMONWHERE .= $LINK . " ENTITYRESTRICT "; } else { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, "glpi_plugin_resources_resources", '', '', $PluginResourcesResource->maybeRecursive()); } } $WHERE = ""; $HAVING = ""; // Add search conditions // If there is search items if ($_SESSION["glpisearchcount"]["PluginResourcesDirectory"] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"]["PluginResourcesDirectory"]; $key++) { // if real search (strlen >0) and not all and view search if (isset($p['contains'][$key]) && strlen($p['contains'][$key]) > 0) { // common search if ($p['field'][$key] != "all" && $p['field'][$key] != "view") { $LINK = " "; $NOT = 0; $tmplink = ""; if (is_array($p['link']) && isset($p['link'][$key])) { if (strstr($p['link'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link'][$key]; } } else { $tmplink = " AND "; } if (isset($searchopt["PluginResourcesDirectory"][$p['field'][$key]]["usehaving"])) { // Manage Link if not first item if (!empty($HAVING)) { $LINK = $tmplink; } // Find key $item_num = array_search($p['field'][$key], $toview); $HAVING .= Search::addHaving($LINK, $NOT, "PluginResourcesDirectory", $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key], 0, $item_num); } else { // Manage Link if not first item if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= self::addWhere($LINK, $NOT, "PluginResourcesDirectory", $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key]); } // view and all search } else { $LINK = " OR "; $NOT = 0; $globallink = " AND "; if (is_array($p['link']) && isset($p['link'][$key])) { switch ($p['link'][$key]) { case "AND": $LINK = " OR "; $globallink = " AND "; break; case "AND NOT": $LINK = " AND "; $NOT = 1; $globallink = " AND "; break; case "OR": $LINK = " OR "; $globallink = " OR "; break; case "OR NOT": $LINK = " AND "; $NOT = 1; $globallink = " OR "; break; } } else { $tmplink = " AND "; } // Manage Link if not first item if (!empty($WHERE)) { $WHERE .= $globallink; } $WHERE .= " ( "; $first2 = true; $items = array(); if ($p['field'][$key] == "all") { $items = $searchopt["PluginResourcesDirectory"]; } else { // toview case : populate toview foreach ($toview as $key2 => $val2) { $items[$val2] = $searchopt["PluginResourcesDirectory"][$val2]; } } foreach ($items as $key2 => $val2) { if (is_array($val2)) { // Add Where clause if not to be done in HAVING CLAUSE if (!isset($val2["usehaving"])) { $tmplink = $LINK; if ($first2) { $tmplink = " "; $first2 = false; } $WHERE .= self::addWhere($tmplink, $NOT, "PluginResourcesDirectory", $key2, $p['searchtype'][$key], $p['contains'][$key]); } } } $WHERE .= " ) "; } } } } if (!empty($WHERE) || !empty($COMMONWHERE)) { if (!empty($COMMONWHERE)) { $WHERE = ' WHERE ' . $ASSIGN . ' ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : ''); } else { $WHERE = ' WHERE ' . $ASSIGN . ' ' . $WHERE . ' '; } $first = false; } $query .= $WHERE; //// 7 - Manage GROUP BY $GROUPBY = ""; // Meta Search / Search All / Count tickets if (in_array('all', $p['field'])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } if (empty($GROUPBY)) { foreach ($toview as $key2 => $val2) { if (!empty($GROUPBY)) { break; } if (isset($searchopt["PluginResourcesDirectory"][$val2]["forcegroupby"])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } } } $query .= $GROUPBY; //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key); } } $query .= $ORDER; // Get it from database if ($result = $DB->query($query)) { $numrows = $DB->numrows($result); $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("searchtype", $p['searchtype']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("searchtype2", $p['searchtype2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']); $parameters = "sort=" . $p['sort'] . "&order=" . $p['order'] . $globallinkto; if ($output_type == Search::GLOBAL_SEARCH) { if (class_exists($itemtype)) { echo "<div class='center'><h2>" . $this->getTypeName(); // More items if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>"; } echo "</h2></div>\n"; } else { return false; } } if ($p['start'] < $numrows) { // Pager if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $search_config = ""; if ($item->canCreate() && $canedit) { $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&itemtype=" . $itemtype . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' ); w.focus();\""; $search_config = "<img alt='" . __('Select default items to show') . "' title='" . __('Select default items to show') . "' src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config .= $tmp . ">"; } //echo Search::showHeaderItem($output_type,$search_config,$header_num,"",0,$p['order']); } // Pager if ($output_type == Search::HTML_OUTPUT) { Html::printPager($p['start'], $numrows, $target, $parameters, $itemtype, 0, $search_config); echo "<br>"; } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = $p['start'] + $LIST_LIMIT; // Export All case if ($p['export_all']) { $begin_display = 0; $end_display = $numrows; } //massive action $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { Html::openMassiveActionsForm('massform' . $itemtype); $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => false, 'is_deleted' => $p['is_deleted']); Html::showMassiveActions("PluginResourcesDirectory", $massiveactionparams); } // Add toview elements $nbcols = $toview_count; if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Display List Header echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); $header_num = 1; // Display column Headers for toview items $headers_line = ''; $headers_line_top = ''; $headers_line_bottom = ''; echo Search::showNewLine($output_type); if ($output_type == Search::HTML_OUTPUT && $item->canCreate() && $canedit) { // HTML display - massive modif $headers_line_top .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); $headers_line_bottom .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); } // Display column Headers for toview items foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt["PluginResourcesDirectory"][$val]['nosort']) || !$searchopt["PluginResourcesDirectory"][$val]['nosort']) { $linkto = "javascript:reloadTab('sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto . "')"; } $headers_line .= Search::showHeaderItem($output_type, $searchopt["PluginResourcesDirectory"][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']); } // End Line for column headers $headers_line .= Search::showEndLine($output_type); $headers_line_top .= $headers_line; $headers_line_bottom .= $headers_line; echo $headers_line_top; $DB->data_seek($result, $p['start']); // Define begin and end var for loop // Search case $i = $begin_display; // Init list of items displayed if ($output_type == Search::HTML_OUTPUT) { Session::initNavigateListItems($itemtype); } // Num of the row (1=header_line) $row_num = 1; // Display Loop while ($i < $numrows && $i < $end_display) { $item_num = 1; $data = $DB->fetch_array($result); $i++; $row_num++; echo Search::showNewLine($output_type, $i % 2); Session::addToNavigateListItems($itemtype, $data['id']); $tmpcheck = ""; if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { $sel = ""; $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>"; echo Search::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'"); } foreach ($toview as $key => $val) { echo Search::showItem($output_type, Search::giveItem("PluginResourcesDirectory", $val, $data, $key), $item_num, $row_num, Search::displayConfigItem("PluginResourcesDirectory", $val, $data, $key)); } echo Search::showEndLine($output_type); } // Close Table $title = ""; // Create title if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) { $title .= self::getTypeName(1); } // Display footer echo Search::showFooter($output_type, $title); //massive action if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { $massiveactionparams['ontop'] = false; $massiveactionparams['fixed'] = false; Html::showMassiveActions("PluginResourcesDirectory", $massiveactionparams); Html::closeForm(); } else { echo "</table></div>"; } // Pager if ($output_type == Search::HTML_OUTPUT) { echo "<br>"; Html::printPager($p['start'], $numrows, $target, $parameters, "PluginResourcesDirectory", 0, $search_config); } } else { echo Search::showError($output_type); } } }
/** * Show for PDF an resources : employee informations * * @param $pdf object for the output * @param $appli PluginResourcesResource Class */ static function pdfForResource(PluginPdfSimplePDF $pdf, PluginResourcesResource $appli) { global $DB; $ID = $appli->fields['id']; if (!$appli->can($ID, "r")) { return false; } if (!plugin_resources_haveRight("resources", "r")) { return false; } $query = "SELECT * \n FROM `glpi_plugin_resources_employees` \n WHERE `plugin_resources_resources_id` = '{$ID}'"; $result = $DB->query($query); $number = $DB->numrows($result); $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . self::getTypeName(1) . '</b>'); $pdf->setColumnsSize(33, 33, 34); $pdf->displayTitle('<b><i>' . PluginResourcesEmployer::getTypeName(1), PluginResourcesClient::getTypeName(1) . '</i></b>'); if (!$number) { $pdf->displayLine(__('No item found')); } else { for ($i = 0; $i < $number; $i++) { $employer = $DB->result($result, $i, "plugin_resources_employers_id"); $client = $DB->result($result, $i, "plugin_resources_clients_id"); $pdf->displayLine(Html::clean(Dropdown::getDropdownName("glpi_plugin_resources_employers", $employer)), Html::clean(Dropdown::getDropdownName("glpi_plugin_resources_clients", $client))); } } $pdf->displaySpace(); }
static function showReports($ID, $withtemplate = '') { global $DB, $CFG_GLPI; $rand = mt_rand(); $resource = new PluginResourcesResource(); $resource->getFromDB($ID); $canedit = $resource->can($ID, 'w'); Session::initNavigateListItems("PluginResourcesReportConfig", PluginResourcesResource::getTypeName(1) . " = " . $resource->fields["name"]); $query = "SELECT `glpi_plugin_resources_reportconfigs`.`id`,\n `glpi_plugin_resources_reportconfigs`.`plugin_resources_resources_id`,\n `glpi_plugin_resources_reportconfigs`.`information`, \n `glpi_plugin_resources_reportconfigs`.`comment`\n FROM `glpi_plugin_resources_reportconfigs` "; $query .= " LEFT JOIN `glpi_plugin_resources_resources` ON (`glpi_plugin_resources_resources`.`id` = `glpi_plugin_resources_reportconfigs`.`plugin_resources_resources_id`)"; $query .= " WHERE `glpi_plugin_resources_reportconfigs`.`plugin_resources_resources_id` = '{$ID}'"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $row_num = 1; if ($number != "0") { if ($withtemplate < 2) { echo "<form method='post' name='form_reports{$rand}' id='form_reports{$rand}' action=\"./reportconfig.form.php\">"; } echo "<div align='center'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='5'>" . self::getTypeName(1) . "</th></tr>"; $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } echo "<tr>"; if (plugin_resources_haveRight('resources', 'w') && $canedit && $withtemplate < 2) { echo "<th> </th>"; } echo "<th>" . __('Comments') . "</th>"; echo "<th>" . __('Information', 'Informations', 2) . "</th>"; if ($withtemplate < 2) { echo "<th> </th>"; } echo "</tr>"; while ($data = $DB->fetch_array($result)) { Session::addToNavigateListItems("PluginResourcesReportConfig", $data['id']); $i++; $row_num++; echo "<tr class='tab_bg_1 center'>"; if (plugin_resources_haveRight('resources', 'w') && $canedit && $withtemplate < 2) { echo "<td width='10'>"; echo "<input type='checkbox' name='check[" . $data["id"] . "]'"; if (isset($_POST['check']) && $_POST['check'] == 'all') { echo " checked "; } echo ">"; echo "</td>"; } echo "<td class='left'>" . nl2br($data["comment"]) . "</td>"; echo "<td class='left'>" . nl2br($data["information"]) . "</td>"; if ($withtemplate < 2) { echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/reportconfig.form.php?id=" . $data["id"] . "&plugin_resources_resources_id=" . $data["plugin_resources_resources_id"] . "'>"; _e('Update'); if ($_SESSION["glpiis_ids_visible"]) { echo " (" . $data["id"] . ")"; } echo "</a></td>"; } echo "</tr>"; } echo "</table></div>"; if ($number && $canedit && $withtemplate < 2) { if (plugin_resources_haveRight('resources', 'w')) { Html::openArrowMassives("form_reports{$rand}", true); Html::closeArrowMassives(array('delete_report' => _sx('button', 'Delete permanently'))); } } if ($withtemplate < 2) { Html::closeForm(); } } }
function showItemFromPlugin($instID, $withtemplate = '') { global $DB, $CFG_GLPI; if (empty($withtemplate)) { $withtemplate = 0; } $PluginResourcesTask = new PluginResourcesTask(); if ($PluginResourcesTask->getFromDB($instID)) { $plugin_resources_resources_id = $PluginResourcesTask->fields["plugin_resources_resources_id"]; $PluginResourcesResource = new PluginResourcesResource(); $PluginResourcesResource->getFromDB($plugin_resources_resources_id); $canedit = $PluginResourcesResource->can($plugin_resources_resources_id, 'w'); $query = "SELECT `items_id`, `itemtype` \n FROM `" . $this->getTable() . "` \n WHERE `plugin_resources_tasks_id` = '{$instID}' \n ORDER BY `itemtype` "; $result = $DB->query($query); $number = $DB->numrows($result); echo "<form method='post' name='addtaskitem' action=\"./task.form.php\">"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th colspan='" . ($canedit ? 3 : 2) . "'>" . _n('Associated item', 'Associated items', 2); echo "</th></tr>"; echo "<tr><th>" . _n('Type', 'Types', 2) . "</th>"; echo "<th>" . __('Name') . "</th>"; if ($canedit && $this->canCreate() && $withtemplate < 2) { echo "<th> </th>"; } echo "</tr>"; $used = array(); if ($number != "0") { for ($i = 0; $i < $number; $i++) { $type = $DB->result($result, $i, "itemtype"); $items_id = $DB->result($result, $i, "items_id"); if (!class_exists($type)) { continue; } $item = new $type(); if ($item->canView()) { $table = getTableForItemType($type); $query = "SELECT `" . $table . "`.*, `" . $this->getTable() . "`.`id` as items_id \n FROM `" . $this->getTable() . "` \n INNER JOIN `" . $table . "` ON (`" . $table . "`.`id` = `" . $this->getTable() . "`.`items_id`) \n WHERE `" . $this->getTable() . "`.`itemtype` = '" . $type . "' \n AND `" . $this->getTable() . "`.`items_id` = '" . $items_id . "' \n AND `" . $this->getTable() . "`.`plugin_resources_tasks_id` = '{$instID}' "; $query .= "ORDER BY `" . $table . "`.`name` "; $result_linked = $DB->query($query); if ($DB->numrows($result_linked)) { while ($data = $DB->fetch_assoc($result_linked)) { $ID = ""; $itemID = $data["id"]; $used[] = $itemID; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $ID = " (" . $data["id"] . ")"; } $itemname = $data["name"]; if ($type == 'User') { $itemname = getUserName($itemID); } $link = Toolbox::getItemTypeFormURL($type); $name = "<a href=\"" . $link . "\">" . $itemname . "{$ID}</a>"; echo "<tr class='tab_bg_1'>"; echo "<td class='center'>" . $item->getTypeName() . "</td>"; echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] == '1' ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; if ($canedit && $this->canCreate() && $withtemplate < 2) { echo "<td class='center' class='tab_bg_2'>"; Html::showSimpleForm($CFG_GLPI['root_doc'] . '/plugins/resources/front/task.form.php', 'deletetaskitem', _x('button', 'Delete permanently'), array('id' => $data["items_id"])); echo "</td>"; } echo "</tr>"; } } } } } if ($canedit && $this->canCreate() && $withtemplate < 2) { echo "<tr class='tab_bg_1'><td colspan='2' class='right'>"; echo "<input type='hidden' name='plugin_resources_tasks_id' value='{$instID}'>"; $PluginResourcesResource_Item = new PluginResourcesResource_Item(); $PluginResourcesResource_Item->dropdownItems($plugin_resources_resources_id, $used); echo "</td>"; echo "<td class='center' colspan='2' class='tab_bg_2'>"; echo "<input type='submit' name='addtaskitem' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table></div>"; } else { echo "</table></div>"; } Html::closeForm(); echo "<br>"; } }
/** * Show for PDF an resources : checklists informations * * @param $pdf object for the output * @param $ID of the resources */ static function pdfForResource(PluginPdfSimplePDF $pdf, PluginResourcesResource $appli, $checklist_type) { global $DB; $ID = $appli->fields['id']; if (!$appli->can($ID, "r")) { return false; } if (!plugin_resources_haveRight("resources", "r")) { return false; } $query = "SELECT * \n FROM `glpi_plugin_resources_checklists` \n WHERE `plugin_resources_resources_id` = '{$ID}' \n AND `checklist_type` = '{$checklist_type}' \n ORDER BY `rank` "; $result = $DB->query($query); $number = $DB->numrows($result); $i = $j = 0; $pdf->setColumnsSize(100); if ($number > 0) { $pdf->displayTitle('<b>' . self::getChecklistType($checklist_type) . '</b>'); $pdf->setColumnsSize(85, 10, 5); $pdf->displayTitle('<b><i>' . __('Name'), __('Linked task', 'resources'), __('Checked', 'resources') . '</i></b>'); $i++; while ($j < $number) { $checkedID = $DB->result($result, $j, "is_checked"); $name = $DB->result($result, $j, "name"); $task_id = $DB->result($result, $j, "plugin_resources_tasks_id"); if ($checkedID == 1) { $checked = __('Yes'); } else { $checked = __('No'); } $pdf->displayLine($name, Dropdown::getYesNo($task_id), $checked); $j++; } } else { $pdf->displayLine(__('No checklist found', 'resources')); } $pdf->displaySpace(); }
function showItemHelpdesk($plugin_resources_resources_id, $exist, $withtemplate = '') { global $CFG_GLPI; $restrict = "`plugin_resources_resources_id` = '{$plugin_resources_resources_id}'"; $choices = getAllDatasFromTable($this->getTable(), $restrict); $resource = new PluginResourcesResource(); $resource->getFromDB($plugin_resources_resources_id); $canedit = $resource->can($plugin_resources_resources_id, 'w') && $withtemplate < 2 && $resource->fields["is_leaving"] != 1; if ($exist == 0) { echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/resource_item.list.php\">"; } else { if ($exist == 1) { echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/resource.form.php\">"; } } echo "<div align='center'><table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th colspan='4'>" . __('Element(s) to be affected', 'resources') . "</th>"; echo "</tr>"; echo "<tr>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Description') . "</th>"; echo "<th>" . __('Comments') . "</th>"; if ($canedit) { echo "<th> </th>"; } echo "</tr>"; $used = array(); if (!empty($choices)) { foreach ($choices as $choice) { $used[] = $choice["plugin_resources_choiceitems_id"]; echo "<tr class='tab_bg_1'>"; $items = Dropdown::getDropdownName("glpi_plugin_resources_choiceitems", $choice["plugin_resources_choiceitems_id"], 1); echo "<td class='left'>"; echo $items['name']; echo "</td>"; echo "<td class='left'>"; echo nl2br($items["comment"]); echo "</td>"; echo "<td class='center'>"; $rand = mt_rand(); if (!empty($choice["comment"])) { self::showModifyCommentFrom($choice, $rand); } else { self::showAddCommentForm($choice, $rand); } echo "</td>"; if ($canedit) { echo "<td class='center' class='tab_bg_2'>"; Html::showSimpleForm($CFG_GLPI['root_doc'] . '/plugins/resources/front/resource_item.list.php', 'deletehelpdeskitem', _x('button', 'Delete permanently'), array('id' => $choice["id"])); echo "</td>"; } echo "</tr>"; } } if ($canedit) { echo "<tr class='tab_bg_1'>"; echo "<th colspan='4'>" . __('Add a need', 'resources') . " :</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='plugin_resources_resources_id' value='{$plugin_resources_resources_id}'>"; $condition = ""; if ($_SESSION['glpiactiveprofile']['interface'] != 'central') { $condition = '`is_helpdesk_visible` = 1'; } Dropdown::show('PluginResourcesChoiceItem', array('name' => 'plugin_resources_choiceitems_id', 'entity' => $_SESSION['glpiactive_entity'], 'condition' => $condition, 'used' => $used)); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td class='center' colspan='4'>"; echo "<input type='submit' name='addhelpdeskitem' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "<input type='hidden' name='id' value=\"{$plugin_resources_resources_id}\">"; echo " "; if ($_SESSION['glpiactiveprofile']['interface'] != 'central') { if ($exist != 1) { echo "<input type='submit' name='finish' value=\"" . __('Terminate the declaration', 'resources') . "\" class='submit'>"; } else { echo "<input type='submit' name='resend' value=\"" . __('Resend the declaration', 'resources') . "\" class='submit'>"; } } echo "</td>"; echo "</tr>"; } echo "</table></div>"; Html::closeForm(); echo "<br>"; }