function showForm($ID, $options = array()) { global $DB, $CFG_GLPI, $LANG; $canupdate = haveRight('update_ticket', '1'); $canpriority = haveRight('update_priority', '1'); $showuserlink = 0; if (haveRight('user', 'r')) { $showuserlink = 1; } if ($ID > 0) { $this->check($ID, 'r'); } else { // Create item $this->check(-1, 'w', $options); } $this->showTabs($options); $canupdate_descr = $canupdate || $this->fields['status'] == 'new' && $this->isUser(self::REQUESTER, getLoginUserID()) && $this->numberOfFollowups() == 0 && $this->numberOfTasks() == 0; if (!$ID) { //Get all the user's entities $all_entities = Profile_User::getUserEntities($options["_users_id_requester"], true); $this->userentities = array(); //For each user's entity, check if the technician which creates the ticket have access to it foreach ($all_entities as $tmp => $ID_entity) { if (haveAccessToEntity($ID_entity)) { $this->userentities[] = $ID_entity; } } $this->countentitiesforuser = count($this->userentities); if ($this->countentitiesforuser > 0 && !in_array($this->fields["entities_id"], $this->userentities)) { // If entity is not in the list of user's entities, // then use as default value the first value of the user's entites list $this->fields["entities_id"] = $this->userentities[0]; } } echo "<form method='post' name='form_ticket' enctype='multipart/form-data' action='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php'>"; echo "<div class='spaced' id='tabsbody'>"; echo "<table class='tab_cadre_fixe'>"; // Optional line $ismultientities = isMultiEntitiesMode(); echo '<tr><th colspan="4">'; if ($ID) { echo $this->getTypeName() . " - " . $LANG['common'][2] . " {$ID} "; if ($ismultientities) { echo "(" . Dropdown::getDropdownName('glpi_entities', $this->fields['entities_id']) . ")"; } } else { if ($ismultientities) { echo $LANG['job'][46] . " : " . Dropdown::getDropdownName("glpi_entities", $this->fields['entities_id']); } else { echo $LANG['job'][13]; } } echo '</th></tr>'; echo "<tr>"; echo "<th class='left' colspan='2'>"; echo "<table>"; echo "<tr>"; echo "<td><span class='tracking_small'>" . $LANG['joblist'][11] . " : </span></td>"; echo "<td>"; $date = $this->fields["date"]; if (!$ID) { $date = date("Y-m-d H:i:s"); } if ($canupdate) { showDateTimeFormItem("date", $date, 1, false); } else { echo convDateTime($date); } echo "</td></tr>"; if ($ID) { echo "<tr><td><span class='tracking_small'>" . $LANG['common'][95] . " :</span></td><td>"; if ($canupdate) { User::dropdown(array('name' => 'users_id_recipient', 'value' => $this->fields["users_id_recipient"], 'entity' => $this->fields["entities_id"], 'right' => 'all')); } else { echo getUserName($this->fields["users_id_recipient"], $showuserlink); } echo "</td></tr>"; } echo "</table>"; echo "</th>"; echo "<th class='left' colspan='2'>"; echo "<table>"; if ($ID) { echo "<tr><td><span class='tracking_small'>" . $LANG['common'][26] . " :</span></td>"; echo "<td><span class='tracking_small'>" . convDateTime($this->fields["date_mod"]) . "\n"; if ($this->fields['users_id_lastupdater'] > 0) { echo $LANG['common'][95] . " "; echo getUserName($this->fields["users_id_lastupdater"], $showuserlink); } echo "</span>"; echo "</td></tr>"; } // SLA echo "<tr>"; echo "<td><span class='tracking_small'>" . $LANG['sla'][5] . " : </span></td>"; echo "<td>"; if ($ID) { if ($this->fields["slas_id"] > 0) { echo "<span class='tracking_small'> "; echo convDateTime($this->fields["due_date"]) . "</span>"; echo "</td></tr><tr><td><span class='tracking_small'>" . $LANG['sla'][1] . " :</span></td>"; echo "<td><span class='tracking_small'>"; echo Dropdown::getDropdownName("glpi_slas", $this->fields["slas_id"]); $commentsla = ""; $slalevel = new SlaLevel(); if ($slalevel->getFromDB($this->fields['slalevels_id'])) { $commentsla .= '<strong>' . $LANG['sla'][6] . " : </strong>" . $slalevel->getName() . '<br><br>'; } $nextaction = new SlaLevel_Ticket(); if ($nextaction->getFromDBForTicket($this->fields["id"])) { $commentsla .= '<strong>' . $LANG['sla'][8] . " : </strong>" . convDateTime($nextaction->fields['date']) . '<br>'; if ($slalevel->getFromDB($nextaction->fields['slalevels_id'])) { $commentsla .= '<strong>' . $LANG['sla'][6] . " : </strong>" . $slalevel->getName() . '<br>'; } } $slaoptions = array(); if (haveRight('config', 'r')) { } $slaoptions['link'] = getItemTypeFormURL('SLA') . "?id=" . $this->fields["slas_id"]; showToolTip($commentsla, $slaoptions); if ($canupdate) { echo " <input type='submit' class='submit' name='sla_delete' value='" . $LANG['sla'][7] . "'>"; } echo "</span>"; } else { showDateTimeFormItem("due_date", $this->fields["due_date"], 1, false, $canupdate); } } else { // New Ticket if ($this->fields["due_date"] == 'NULL') { $this->fields["due_date"] = ''; } showDateTimeFormItem("due_date", $this->fields["due_date"], 1, false, $canupdate); /* echo $LANG['choice'][2]." ".$LANG['sla'][1]." : "; Dropdown::show('Sla',array('entity' => $this->fields["entities_id"], 'value' =>$this->fields["slas_id"]));*/ } echo "</td></tr>"; if ($ID) { switch ($this->fields["status"]) { case 'closed': echo "<tr>"; echo "<td><span class='tracking_small'>" . $LANG['joblist'][12] . " : </span></td>"; echo "<td>"; showDateTimeFormItem("closedate", $this->fields["closedate"], 1, false, $canupdate); echo "</td></tr>"; break; case 'solved': echo "<tr>"; echo "<td><span class='tracking_small'>" . $LANG['joblist'][14] . " : </span></td>"; echo "<td>"; showDateTimeFormItem("solvedate", $this->fields["solvedate"], 1, false, $canupdate); echo "</td></tr>"; break; } } echo "</table>"; echo "</th></tr>"; echo "</table>"; if (!$ID) { $this->showActorsPartForm($ID, $options); } echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th width='10%'>" . $LANG['joblist'][0] . " : </th>"; echo "<td width='40%'>"; if ($canupdate) { self::dropdownStatus("status", $this->fields["status"], 2); // Allowed status } else { echo self::getStatus($this->fields["status"]); } echo "</td>"; echo "<th>" . $LANG['common'][17] . " : </th>"; echo "<td >"; // Permit to set type when creating ticket without update right if ($canupdate || !$ID) { self::dropdownType('type', $this->fields["type"]); } else { echo self::getTicketTypeName($this->fields["type"]); } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . $LANG['joblist'][29] . " : </th>"; echo "<td>"; if ($canupdate && $canpriority || !$ID || $canupdate_descr) { // Only change during creation OR when allowed to change priority OR when user is the creator $idurgency = self::dropdownUrgency("urgency", $this->fields["urgency"]); } else { $idurgency = "value_urgency" . mt_rand(); echo "<input id='{$idurgency}' type='hidden' name='urgency' value='" . $this->fields["urgency"] . "'>"; echo self::getUrgencyName($this->fields["urgency"]); } echo "</td>"; echo "<th>" . $LANG['common'][36] . " : </th>"; echo "<td >"; // Permit to set category when creating ticket without update right if ($canupdate || !$ID || $canupdate_descr) { $opt = array('value' => $this->fields["ticketcategories_id"], 'entity' => $this->fields["entities_id"]); if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") { $opt['condition'] = '`is_helpdeskvisible`=1'; } if ($ID && $CFG_GLPI["is_ticket_category_mandatory"]) { $opt['display_emptychoice'] = false; } Dropdown::show('TicketCategory', $opt); } else { echo Dropdown::getDropdownName("glpi_ticketcategories", $this->fields["ticketcategories_id"]); } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . $LANG['joblist'][30] . " : </th>"; echo "<td>"; if ($canupdate) { $idimpact = self::dropdownImpact("impact", $this->fields["impact"]); } else { echo self::getImpactName($this->fields["impact"]); } echo "</td>"; echo "<th class='left' rowspan='2'>" . $LANG['document'][14] . " : </th>"; echo "<td rowspan='2'>"; // Select hardware on creation or if have update right if ($canupdate || !$ID || $canupdate_descr) { if ($ID) { if ($this->fields['itemtype'] && class_exists($this->fields['itemtype']) && $this->fields["items_id"]) { $item = new $this->fields['itemtype'](); if ($item->can($this->fields["items_id"], 'r')) { echo $item->getTypeName() . " - " . $item->getLink(true); } else { echo $item->getTypeName() . " " . $item->getNameID(); } } } $dev_user_id = 0; if (!$ID) { $dev_user_id = $options['_users_id_requester']; } else { if (isset($this->users[self::REQUESTER]) && count($this->users[self::REQUESTER]) == 1) { foreach ($this->users[self::REQUESTER] as $user_id_single) { $dev_user_id = $user_id_single['users_id']; } } } if ($dev_user_id > 0) { self::dropdownMyDevices($dev_user_id, $this->fields["entities_id"], $this->fields["itemtype"], $this->fields["items_id"]); } self::dropdownAllDevices("itemtype", $this->fields["itemtype"], $this->fields["items_id"], 1, $this->fields["entities_id"]); } else { if ($ID && $this->fields['itemtype'] && class_exists($this->fields['itemtype'])) { $item = new $this->fields['itemtype'](); $item->getFromDB($this->fields['items_id']); echo $item->getTypeName() . " - " . $item->getNameID(); } else { echo $LANG['help'][30]; } } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th class='left'>" . $LANG['joblist'][2] . " : </th>"; echo "<td>"; if ($canupdate && $canpriority) { $idpriority = self::dropdownPriority("priority", $this->fields["priority"], false, true); $idajax = 'change_priority_' . mt_rand(); echo " <span id='{$idajax}' style='display:none'></span>"; } else { $idajax = 'change_priority_' . mt_rand(); $idpriority = 0; echo "<span id='{$idajax}'>" . self::getPriorityName($this->fields["priority"]) . "</span>"; } if ($canupdate) { $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => $idpriority); ajaxUpdateItemOnSelectEvent(array($idurgency, $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params); } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th class='left'>" . $LANG['job'][44] . " : </th>"; echo "<td>"; if ($canupdate) { Dropdown::show('RequestType', array('value' => $this->fields["requesttypes_id"])); } else { echo Dropdown::getDropdownName('glpi_requesttypes', $this->fields["requesttypes_id"]); } echo "</td>"; // Display validation state echo "<th>"; if (!$ID) { echo $LANG['validation'][26] . " : "; } else { echo $LANG['validation'][0] . " : "; } echo "</th>"; echo "<td>"; if (!$ID) { User::dropdown(array('name' => "_add_validation", 'entity' => $this->fields['entities_id'], 'right' => 'validate_ticket')); } else { if ($canupdate) { TicketValidation::dropdownStatus('global_validation', array('global' => true, 'value' => $this->fields['global_validation'])); } else { echo TicketValidation::getStatus($this->fields['global_validation']); } } echo "</td></tr>"; // Need comment right to add a followup with the actiontime if (!$ID && haveRight("global_add_followups", "1")) { echo "<tr class='tab_bg_1'>"; echo "<th>" . $LANG['job'][20] . " : </th>"; echo "<td class='left' colspan='3'>"; Dropdown::showInteger('hour', $options['hour'], 0, 100); echo " " . $LANG['job'][21] . " "; Dropdown::showInteger('minute', $options['minute'], 0, 59); echo " " . $LANG['job'][22] . " "; echo "</td>"; echo "</tr>"; } echo '</table>'; if ($ID) { $this->showActorsPartForm($ID, $options); } echo "<table class='tab_cadre_fixe'>"; $view_linked_tickets = $ID || $canupdate; echo "<tr class='tab_bg_1'>"; echo "<th width='10%'>" . $LANG['common'][57] . " :</th>"; echo "<td width='50%'>"; if (!$ID || $canupdate_descr) { $rand = mt_rand(); echo "<script type='text/javascript' >\n"; echo "function showName{$rand}() {\n"; echo "Ext.get('name{$rand}').setDisplayed('none');"; $params = array('maxlength' => 250, 'size' => 60, 'name' => 'name', 'data' => rawurlencode($this->fields["name"])); ajaxUpdateItemJsCode("viewname{$rand}", $CFG_GLPI["root_doc"] . "/ajax/inputtext.php", $params, false); echo "}"; echo "</script>\n"; echo "<div id='name{$rand}' class='tracking left' onClick='showName{$rand}()'>\n"; if (empty($this->fields["name"])) { echo $LANG['reminder'][15]; } else { echo $this->fields["name"]; } echo "</div>\n"; echo "<div id='viewname{$rand}'>\n"; echo "</div>\n"; if (!$ID) { echo "<script type='text/javascript' >\n\n showName{$rand}();\n </script>"; } } else { if (empty($this->fields["name"])) { echo $LANG['reminder'][15]; } else { echo $this->fields["name"]; } } echo "</td>"; // Permit to add doc when creating a ticket if (!$ID) { echo "<th>" . $LANG['document'][2] . " (" . Document::getMaxUploadSize() . ") :"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/aide.png' class='pointer' alt=\"" . $LANG['central'][7] . "\" onclick=\"window.open('" . $CFG_GLPI["root_doc"] . "/front/documenttype.list.php','Help','scrollbars=1,resizable=1,width=1000,height=800')\">"; echo "</th>"; echo "<td>"; echo "<input type='file' name='filename' value=\"\" size='25'></td>"; } else { echo "<th colspan='2'>"; echo $LANG['document'][20] . ' : ' . Document_Item::countForItem($this); echo "</th>"; } echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th width='10%'>" . $LANG['joblist'][6] . " : </th>"; echo "<td width='50%'>"; if (!$ID || $canupdate_descr) { // Admin =oui on autorise la modification de la description $rand = mt_rand(); echo "<script type='text/javascript' >\n"; echo "function showDesc{$rand}() {\n"; echo "Ext.get('desc{$rand}').setDisplayed('none');"; $params = array('rows' => 6, 'cols' => 60, 'name' => 'content', 'data' => rawurlencode($this->fields["content"])); ajaxUpdateItemJsCode("viewdesc{$rand}", $CFG_GLPI["root_doc"] . "/ajax/textarea.php", $params, false); echo "}"; echo "</script>\n"; echo "<div id='desc{$rand}' class='tracking' onClick='showDesc{$rand}()'>\n"; if (!empty($this->fields["content"])) { echo nl2br($this->fields["content"]); } else { echo $LANG['job'][33]; } echo "</div>\n"; echo "<div id='viewdesc{$rand}'></div>\n"; if (!$ID) { echo "<script type='text/javascript' >\n\n showDesc{$rand}();\n </script>"; } } else { echo nl2br($this->fields["content"]); } echo "</td>"; if ($view_linked_tickets) { echo "<th width='10%'>"; echo $LANG['job'][55]; if ($canupdate) { $rand_linked_ticket = mt_rand(); echo " <a class='tracking'\n onClick=\"Ext.get('linkedticket{$rand_linked_ticket}').setDisplayed('block')\">\n"; echo $LANG['buttons'][8]; echo "</a>\n"; } echo '</th>'; echo "<td>"; Ticket_Ticket::displayLinkedTicketsTo($ID); if ($canupdate) { echo "<div style='display:none' id='linkedticket{$rand_linked_ticket}'>"; Ticket_Ticket::dropdownLinks('_link[link]'); echo " " . $LANG['job'][38] . " " . $LANG['common'][2] . " : "; echo "<input type='hidden' name='_link[tickets_id_1]' value='{$ID}'>\n"; echo "<input type='text' name='_link[tickets_id_2]' value='' size='10'>\n"; echo " "; echo "</div>"; } echo "</td>"; } echo "</tr>"; if (!$ID || $canupdate || $canupdate_descr || haveRight("assign_ticket", "1") || haveRight("steal_ticket", "1")) { echo "<tr class='tab_bg_1'>"; if ($ID) { if (haveRight('delete_ticket', 1)) { echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='submit' class='submit' name='update' value='" . $LANG['buttons'][7] . "'></td>"; echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='submit' class='submit' name='delete' value='" . $LANG['buttons'][22] . "'" . addConfirmationOnAction($LANG['common'][50]) . ">"; } else { echo "<td class='tab_bg_2 center' colspan='4'>"; echo "<input type='submit' class='submit' name='update' value='" . $LANG['buttons'][7] . "'>"; } } else { echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</td><td class='tab_bg_2 center' colspan='2'>"; echo "<input type='button' value=\"" . $LANG['buttons'][16] . "\" class='submit'\n onclick=\"window.location='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php'\">"; } echo "</td></tr>"; } echo "</table>"; echo "<input type='hidden' name='id' value='{$ID}'>"; echo "</div>"; echo "</form>"; $this->addDivForTabs(); return true; }
/** * Display a 2 columns Footer for Form buttons * Close the form is user can edit * * @param $options array * - withtemplate : 1 for newtemplate, 2 for newobject from template * - colspan for each column (default 2) * - candel : set to false to hide "delete" button * - canedit : set to false to hide all buttons * **/ function showFormButtons($options = array()) { global $LANG, $CFG_GLPI; // for single object like config if (isset($this->fields['id'])) { $ID = $this->fields['id']; } else { $ID = 1; } $params['colspan'] = 2; $params['withtemplate'] = ''; $params['candel'] = true; $params['canedit'] = true; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $params[$key] = $val; } } if (!$params['canedit'] || !$this->can($ID, 'w') && !$this->can($ID, 'd')) { echo "</table></div>"; // Form Header always open form if (!$params['canedit']) { echo "</form>"; } return false; } echo "<tr>"; if ($params['withtemplate'] || $this->isNewID($ID)) { echo "<td class='tab_bg_2 center' colspan='" . $params['colspan'] * 2 . "'>"; if ($ID <= 0 || $params['withtemplate'] == 2) { echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; } else { echo "<input type='submit' name='update' value=\"" . $LANG['buttons'][7] . "\" class='submit'>"; } } else { if ($params['candel'] && !$this->can($ID, 'd')) { $params['candel'] = false; } if ($params['candel']) { echo "<td class='tab_bg_2 center' colspan='" . $params['colspan'] . "'>\n"; echo "<input type='submit' name='update' value=\"" . $LANG['buttons'][7] . "\" class='submit'>"; echo "</td>\n"; echo "<td class='tab_bg_2 center' colspan='" . $params['colspan'] . "' >\n"; if ($this->isDeleted()) { echo "<input type='submit' name='restore' value=\"" . $LANG['buttons'][21] . "\"\n class='submit'>"; echo "<span class='small_space'>\n <input type='submit' name='purge' value=\"" . $LANG['buttons'][22] . "\"\n class='submit'>\n </span>"; } else { if (!$this->maybeDeleted()) { echo "<input type='submit' name='delete' value=\"" . $LANG['buttons'][22] . "\"\n class='submit' " . addConfirmationOnAction($LANG['common'][50]) . ">"; } else { echo "<input type='submit' name='delete' value='" . $LANG['buttons'][6] . "'\n class='submit'>"; } } } else { echo "<td class='tab_bg_2 center' colspan='" . $params['colspan'] * 2 . "'>\n"; echo "<input type='submit' name='update' value=\"" . $LANG['buttons'][7] . "\"\n class='submit'>"; } } if ($ID > 0) { echo "<input type='hidden' name='id' value='{$ID}'>"; } echo "</td>"; echo "</tr>\n"; // Close for Form echo "</table></div></form>"; }
/** * Generic Search and list function * * Build the query, make the search and list items after a search. * * @param $itemtype item type * @param $params parameters array may include field, contains, searchtype, sort, order, start, deleted, link, link2, contains2, field2, itemtype2, searchtype2 * * @return Nothing (display) **/ static function showList($itemtype, $params) { global $DB, $CFG_GLPI, $LANG; // Instanciate an object to access method $item = NULL; if ($itemtype != 'States' && 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['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; } // Manage defautll 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 = getItemTypeSearchURL($itemtype); $limitsearchopt = self::getCleanedOptions($itemtype); if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $itemtable = $CFG_GLPI['union_search_type'][$itemtype]; } else { $itemtable = getTableForItemType($itemtype); } $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == GLOBAL_SEARCH) { $LIST_LIMIT = GLOBAL_SEARCH_DISPLAY_COUNT; } } // hack for States if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $entity_restrict = true; } else { $entity_restrict = $item->isEntityAssign(); } $metanames = array(); // Get the items to display $toview = self::addDefaultToView($itemtype); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser($itemtype, 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']); } // Special case for Ticket : put ID in front if ($itemtype == 'Ticket') { array_unshift($toview, 2); } // Clean toview array $toview = array_unique($toview); foreach ($toview as $key => $val) { if (!isset($limitsearchopt[$val])) { unset($toview[$key]); } } $toview_count = count($toview); // Construct the request //// 1 - SELECT // request currentuser for SQL supervision, not displayed $SELECT = "SELECT '" . $_SESSION['glpiname'] . "' AS currentuser, " . self::addDefaultSelect($itemtype); // Add select for all toview item foreach ($toview as $key => $val) { $SELECT .= self::addSelect($itemtype, $val, $key, 0); } //// 2 - FROM AND LEFT JOIN // Set reference table $FROM = " 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 = self::addDefaultJoin($itemtype, $itemtable, $already_link_tables); $FROM .= $COMMONLEFTJOIN; $searchopt = array(); $searchopt[$itemtype] =& self::getOptions($itemtype); // Add all table for toview items foreach ($toview as $key => $val) { $FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$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)) { $FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]); } } } //// 3 - WHERE // default string $COMMONWHERE = self::addDefaultWhere($itemtype); $first = empty($COMMONWHERE); // Add deleted if item have it if ($item && $item->maybeDeleted()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_deleted` = '" . $p['is_deleted'] . "' "; } // Remove template items if ($item && $item->maybeTemplate()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_template` = '0' "; } // Add Restrict to current entities if ($entity_restrict) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } if ($itemtype == 'Entity') { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, 'id', '', true); } else { if (isset($CFG_GLPI["union_search_type"][$itemtype])) { // Will be replace below in Union/Recursivity Hack $COMMONWHERE .= $LINK . " ENTITYRESTRICT "; } else { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, '', '', $item->maybeRecursive()); } } } $WHERE = ""; $HAVING = ""; // Add search conditions // If there is search items if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $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[$itemtype][$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 .= self::addHaving($LINK, $NOT, $itemtype, $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, $itemtype, $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[$itemtype]; } else { // toview case : populate toview foreach ($toview as $key2 => $val2) { $items[$val2] = $searchopt[$itemtype][$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, $itemtype, $key2, $p['searchtype'][$key], $p['contains'][$key]); } } } $WHERE .= " ) "; } } } } //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = self::addOrderBy($itemtype, $p['sort'], $p['order'], $key); } } //// 5 - META SEARCH // Preprocessing if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { // a - SELECT for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { $SELECT .= self::addSelect($p['itemtype2'][$i], $p['field2'][$i], $i, 1, $p['itemtype2'][$i]); } } // b - ADD LEFT JOIN // Already link meta table in order not to linked a table several times $already_link_tables2 = array(); // Link reference tables for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!in_array(getTableForItemType($p['itemtype2'][$i]), $already_link_tables2)) { $FROM .= self::addMetaLeftJoin($itemtype, $p['itemtype2'][$i], $already_link_tables2, $p['contains2'][$i] == "NULL" || strstr($p['link2'][$i], "NOT")); } } } // Link items tables for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!isset($searchopt[$p['itemtype2'][$i]])) { $searchopt[$p['itemtype2'][$i]] =& self::getOptions($p['itemtype2'][$i]); } if (!in_array($searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"] . "_" . $p['itemtype2'][$i], $already_link_tables2)) { $FROM .= self::addLeftJoin($p['itemtype2'][$i], getTableForItemType($p['itemtype2'][$i]), $already_link_tables2, $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["linkfield"], 1, $p['itemtype2'][$i], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["joinparams"]); } } } } //// 6 - Add item ID // Add ID to the select if (!empty($itemtable)) { $SELECT .= "`{$itemtable}`.`id` AS id "; } //// 7 - Manage GROUP BY $GROUPBY = ""; // Meta Search / Search All / Count tickets if ($_SESSION["glpisearchcount2"][$itemtype] > 0 || !empty($HAVING) || 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[$itemtype][$val2]["forcegroupby"])) { $GROUPBY = " GROUP BY `{$itemtable}`.`id`"; } } } // Specific search for others item linked (META search) if (is_array($p['itemtype2'])) { for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) { if (isset($p['itemtype2'][$key]) && !empty($p['itemtype2'][$key]) && isset($p['contains2'][$key]) && strlen($p['contains2'][$key]) > 0) { $LINK = ""; // For AND NOT statement need to take into account all the group by items if (strstr($p['link2'][$key], "AND NOT") || isset($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["usehaving"])) { $NOT = 0; if (strstr($p['link2'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link2'][$key]; } if (!empty($HAVING)) { $LINK = $tmplink; } $HAVING .= self::addHaving($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1, $key); } else { // Meta Where Search $LINK = " "; $NOT = 0; // Manage Link if not first item if (is_array($p['link2']) && isset($p['link2'][$key]) && strstr($p['link2'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]); $NOT = 1; } else { if (is_array($p['link2']) && isset($p['link2'][$key])) { $tmplink = " " . $p['link2'][$key]; } else { $tmplink = " AND "; } } if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= self::addWhere($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1); } } } } // Use a ReadOnly connection if available and configured to be used $DBread = DBConnection::getReadConnection(); // If no research limit research to display item and compute number of item using simple request $nosearch = true; for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) { if (isset($p['contains'][$i]) && strlen($p['contains'][$i]) > 0) { $nosearch = false; } } if ($_SESSION["glpisearchcount2"][$itemtype] > 0) { $nosearch = false; } $LIMIT = ""; $numrows = 0; //No search : count number of items using a simple count(ID) request and LIMIT search if ($nosearch) { $LIMIT = " LIMIT " . $p['start'] . ", " . $LIST_LIMIT; // Force group by for all the type -> need to count only on table ID if (!isset($searchopt[$itemtype][1]['forcegroupby'])) { $count = "count(*)"; } else { $count = "count(DISTINCT `{$itemtable}`.`id`)"; } // request currentuser for SQL supervision, not displayed $query_num = "SELECT {$count}, '" . $_SESSION['glpiname'] . "' AS currentuser\n FROM `{$itemtable}`" . $COMMONLEFTJOIN; $first = true; if (!empty($COMMONWHERE)) { $LINK = " AND "; if ($first) { $LINK = " WHERE "; $first = false; } $query_num .= $LINK . $COMMONWHERE; } // Union Search : if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $tmpquery = $query_num; $numrows = 0; foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) { $ctable = getTableForItemType($ctype); $citem = new $ctype(); if ($citem->canView()) { // State case if ($itemtype == 'States') { $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $query_num .= " AND {$ctable}.`states_id` > '0' "; // Add deleted if item have it if ($citem && $citem->maybeDeleted()) { $query_num .= " AND `{$ctable}`.`is_deleted` = '0' "; } // Remove template items if ($citem && $citem->maybeTemplate()) { $query_num .= " AND `{$ctable}`.`is_template` = '0' "; } } else { // Ref table case $reftable = getTableForItemType($itemtype); $replace = "FROM `{$reftable}`\n INNER JOIN `{$ctable}`\n ON (`{$reftable}`.`items_id` =`{$ctable}`.`id`\n AND `{$reftable}`.`itemtype` = '{$ctype}')"; $query_num = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery); $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $query_num); } $query_num = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $query_num); $result_num = $DBread->query($query_num); $numrows += $DBread->result($result_num, 0, 0); } } } else { $result_num = $DBread->query($query_num); $numrows = $DBread->result($result_num, 0, 0); } } // If export_all reset LIMIT condition if ($p['export_all']) { $LIMIT = ""; } if (!empty($WHERE) || !empty($COMMONWHERE)) { if (!empty($COMMONWHERE)) { $WHERE = ' WHERE ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : ''); } else { $WHERE = ' WHERE ' . $WHERE . ' '; } $first = false; } if (!empty($HAVING)) { $HAVING = ' HAVING ' . $HAVING; } // Create QUERY if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $first = true; $QUERY = ""; foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) { $ctable = getTableForItemType($ctype); $citem = new $ctype(); if ($citem->canView()) { if ($first) { $first = false; } else { $QUERY .= " UNION "; } $tmpquery = ""; // State case if ($itemtype == 'States') { $tmpquery = $SELECT . ", '{$ctype}' AS TYPE " . $FROM . $WHERE; $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $tmpquery .= " AND `{$ctable}`.`states_id` > '0' "; // Add deleted if item have it if ($citem && $citem->maybeDeleted()) { $tmpquery .= " AND `{$ctable}`.`is_deleted` = '0' "; } // Remove template items if ($citem && $citem->maybeTemplate()) { $tmpquery .= " AND `{$ctable}`.`is_template` = '0' "; } } else { // Ref table case $reftable = getTableForItemType($itemtype); $tmpquery = $SELECT . ", '{$ctype}' AS TYPE,\n `{$reftable}`.`id` AS refID, " . "\n `{$ctable}`.`entities_id` AS ENTITY " . $FROM . $WHERE; $replace = "FROM `{$reftable}`" . "\n INNER JOIN `{$ctable}`" . "\n ON (`{$reftable}`.`items_id`=`{$ctable}`.`id`" . "\n AND `{$reftable}`.`itemtype` = '{$ctype}')"; $tmpquery = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery); $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); } $tmpquery = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $tmpquery); // SOFTWARE HACK if ($ctype == 'Software') { $tmpquery = str_replace("glpi_softwares.serial", "''", $tmpquery); $tmpquery = str_replace("glpi_softwares.otherserial", "''", $tmpquery); } $QUERY .= $tmpquery; } } if (empty($QUERY)) { echo self::showError($output_type); return; } $QUERY .= str_replace($CFG_GLPI["union_search_type"][$itemtype] . ".", "", $ORDER) . $LIMIT; } else { $QUERY = $SELECT . $FROM . $WHERE . $GROUPBY . $HAVING . $ORDER . $LIMIT; } $DBread->query("SET SESSION group_concat_max_len = 4096;"); $result = $DBread->query($QUERY); /// Check group concat limit : if warning : increase limit if ($result2 = $DBread->query('SHOW WARNINGS')) { if ($DBread->numrows($result2) > 0) { $data = $DBread->fetch_assoc($result2); if ($data['Code'] == 1260) { $DBread->query("SET SESSION group_concat_max_len = 4194304;"); $result = $DBread->query($QUERY); } } } // Get it from database and DISPLAY if ($result) { // if real search or complete export : get numrows from request if (!$nosearch || $p['export_all']) { $numrows = $DBread->numrows($result); } // Contruct Pager parameters $globallinkto = self::getArrayUrlLink("field", $p['field']) . self::getArrayUrlLink("link", $p['link']) . self::getArrayUrlLink("contains", $p['contains']) . self::getArrayUrlLink("searchtype", $p['searchtype']) . self::getArrayUrlLink("field2", $p['field2']) . self::getArrayUrlLink("contains2", $p['contains2']) . self::getArrayUrlLink("itemtype2", $p['itemtype2']) . self::getArrayUrlLink("searchtype2", $p['searchtype2']) . self::getArrayUrlLink("link2", $p['link2']); $parameters = "sort=" . $p['sort'] . "&order=" . $p['order'] . $globallinkto; // Not more used : clean pages : try to comment it /* $tmp=explode('?',$target,2); if (count($tmp)>1) { $target = $tmp[0]; $parameters = $tmp[1].'&'.$parameters; } */ if ($output_type == GLOBAL_SEARCH) { if (class_exists($itemtype)) { echo "<div class='center'><h2>" . $item->getTypeName(); // More items if ($numrows > $p['start'] + GLOBAL_SEARCH_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}'>" . $LANG['common'][66] . "</a>"; } echo "</h2></div>\n"; } else { return false; } } // If the begin of the view is before the number of items if ($p['start'] < $numrows) { // Display pager only for HTML if ($output_type == HTML_OUTPUT) { // For plugin add new parameter if available if ($plug = isPluginItemType($itemtype)) { $function = 'plugin_' . $plug['plugin'] . '_addParamFordynamicReport'; if (function_exists($function)) { $out = $function($itemtype); if (is_array($out) && count($out)) { foreach ($out as $key => $val) { if (is_array($val)) { $parameters .= self::getArrayUrlLink($key, $val); } else { $parameters .= "&{$key}={$val}"; } } } } } printPager($p['start'], $numrows, $target, $parameters, $itemtype); } // Form to massive actions $isadmin = $item && $item->canUpdate(); if (!$isadmin && in_array($itemtype, $CFG_GLPI["infocom_types"])) { $infoc = new Infocom(); $isadmin = $infoc->canUpdate() || $infoc->canCreate(); } if ($isadmin && $output_type == HTML_OUTPUT) { echo "<form method='post' name='massiveaction_form' id='massiveaction_form' action=\"" . $CFG_GLPI["root_doc"] . "/front/massiveaction.php\">"; } // Compute number of columns to display // Add toview elements $nbcols = $toview_count; $already_printed = array(); // Add meta search elements if real search (strlen>0) or only NOT search if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0 && !empty($p['itemtype2'][$i]) && (!isset($p['link2'][$i]) || !strstr($p['link2'][$i], "NOT"))) { if (!isset($already_printed[$p['itemtype2'][$i] . $p['field2'][$i]])) { $nbcols++; $already_printed[$p['itemtype2'][$i] . $p['field2'][$i]] = 1; } } } } if ($output_type == HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = $p['start'] + $LIST_LIMIT; // No search Case if ($nosearch) { $begin_display = 0; $end_display = min($numrows - $p['start'], $LIST_LIMIT); } // Export All case if ($p['export_all']) { $begin_display = 0; $end_display = $numrows; } // Display List Header echo self::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); // New Line for Header Items Line echo self::showNewLine($output_type); $header_num = 1; if ($output_type == HTML_OUTPUT) { // HTML display - massive modif $search_config = ""; if (haveRight("search_config", "w") || haveRight("search_config_global", "w")) { $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=\"" . $LANG['setup'][252] . "\" title=\"" . $LANG['setup'][252] . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config .= $tmp . ">"; } echo self::showHeaderItem($output_type, $search_config, $header_num, "", 0, $p['order']); } // Display column Headers for toview items foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) { $linkto = "{$target}?itemtype={$itemtype}&sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto; } echo self::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']); } // Display columns Headers for meta items $already_printed = array(); if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!isset($already_printed[$p['itemtype2'][$i] . $p['field2'][$i]])) { if (!isset($metanames[$p['itemtype2'][$i]])) { $metaitem = new $p['itemtype2'][$i](); $metanames[$p['itemtype2'][$i]] = $metaitem->getTypeName(); } echo self::showHeaderItem($output_type, $metanames[$p['itemtype2'][$i]] . " - " . $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["name"], $header_num); $already_printed[$p['itemtype2'][$i] . $p['field2'][$i]] = 1; } } } } // Add specific column Header if ($itemtype == 'CartridgeItem') { echo self::showHeaderItem($output_type, $LANG['cartridges'][0], $header_num); } if ($itemtype == 'ConsumableItem') { echo self::showHeaderItem($output_type, $LANG['consumables'][0], $header_num); } if ($itemtype == 'States' || $itemtype == 'ReservationItem') { echo self::showHeaderItem($output_type, $LANG['state'][6], $header_num); } if ($itemtype == 'ReservationItem' && $output_type == HTML_OUTPUT) { if (haveRight("reservation_central", "w")) { echo self::showHeaderItem($output_type, $LANG['reservation'][4], $header_num); echo self::showHeaderItem($output_type, " ", $header_num); } echo self::showHeaderItem($output_type, " ", $header_num); } // End Line for column headers echo self::showEndLine($output_type); // if real search seek to begin of items to display (because of complete search) if (!$nosearch) { $DBread->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 == HTML_OUTPUT) { initNavigateListItems($itemtype); } // Num of the row (1=header_line) $row_num = 1; // Display Loop while ($i < $numrows && $i < $end_display) { // Column num $item_num = 1; // Get data and increment loop variables $data = $DBread->fetch_assoc($result); $i++; $row_num++; // New line echo self::showNewLine($output_type, $i % 2, $p['is_deleted']); // Add item in item list addToNavigateListItems($itemtype, $data["id"]); if ($output_type == HTML_OUTPUT) { // HTML display - massive modif $tmpcheck = ""; if ($isadmin) { if ($itemtype == 'Entity' && !in_array($data["id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { if ($item->maybeRecursive() && !in_array($data["entities_id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } if (isset($_SESSION['glpimassiveactionselected'][$data["id"]])) { $sel = "checked"; } $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1'\n {$sel}>"; } } } echo self::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'"); } // Print other toview items foreach ($toview as $key => $val) { echo self::showItem($output_type, self::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, self::displayConfigItem($itemtype, $val, $data, $key)); } // Print Meta Item $already_printed = array(); if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($j = 0; $j < $_SESSION["glpisearchcount2"][$itemtype]; $j++) { if (isset($p['itemtype2'][$j]) && !empty($p['itemtype2'][$j]) && isset($p['contains2'][$j]) && strlen($p['contains2'][$j]) > 0) { if (!isset($already_printed[$p['itemtype2'][$j] . $p['field2'][$j]])) { // General case if (strpos($data["META_{$j}"], "\$\$\$\$") === false) { $out = self::giveItem($p['itemtype2'][$j], $p['field2'][$j], $data, $j, 1); echo self::showItem($output_type, $out, $item_num, $row_num); // Case of GROUP_CONCAT item : split item and multilline display } else { $split = explode("\$\$\$\$", $data["META_{$j}"]); $count_display = 0; $out = ""; $unit = ""; $separate = '<br>'; if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['splititems']) && $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['splititems']) { $separate = '<hr>'; } if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['unit'])) { $unit = $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['unit']; } for ($k = 0; $k < count($split); $k++) { if ($p['contains2'][$j] == "NULL" || strlen($p['contains2'][$j]) == 0 || preg_match('/' . $p['contains2'][$j] . '/i', $split[$k]) || isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['forcegroupby'])) { if ($count_display) { $out .= $separate; } $count_display++; // Manage Link to item $split2 = explode("\$\$", $split[$k]); if (isset($split2[1])) { $out .= "<a id='" . $p['itemtype2'][$j] . '_' . $data["id"] . '_' . $split2[1] . "' "; $out .= "href=\"" . getItemTypeFormURL($p['itemtype2'][$j]) . "?id=" . $p['itemtype2'][$j] . "\">"; $out .= $split2[0] . $unit; if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $out .= " (" . $split2[1] . ")"; } $out .= "</a>"; } else { $out .= $split[$k] . $unit; } } } echo self::showItem($output_type, $out, $item_num, $row_num); } $already_printed[$p['itemtype2'][$j] . $p['field2'][$j]] = 1; } } } } // Specific column display if ($itemtype == 'CartridgeItem') { echo self::showItem($output_type, Cartridge::getCount($data["id"], $data["ALARM"], $output_type != HTML_OUTPUT), $item_num, $row_num); } if ($itemtype == 'ConsumableItem') { echo self::showItem($output_type, Consumable::getCount($data["id"], $data["ALARM"], $output_type != HTML_OUTPUT), $item_num, $row_num); } if ($itemtype == 'States' || $itemtype == 'ReservationItem') { $typename = $data["TYPE"]; if (class_exists($data["TYPE"])) { $itemtmp = new $data["TYPE"](); $typename = $itemtmp->getTypeName(); } echo self::showItem($output_type, $typename, $item_num, $row_num); } if ($itemtype == 'ReservationItem' && $output_type == HTML_OUTPUT) { if (haveRight("reservation_central", "w")) { if (!haveAccessToEntity($data["ENTITY"])) { echo self::showItem($output_type, " ", $item_num, $row_num); echo self::showItem($output_type, " ", $item_num, $row_num); } else { echo self::showItem($output_type, "<a href=\"" . getItemTypeFormURL($itemtype) . "?id=" . $data["refID"] . "&is_active=" . ($data["ACTIVE"] ? 0 : 1) . "&update=update\" " . "title=\"" . ($data["ACTIVE"] ? $LANG['buttons'][42] : $LANG['buttons'][41]) . "\">" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($data["ACTIVE"] ? "moins" : "plus") . ".png\" alt=''\n title=''></a>", $item_num, $row_num, "class='center'"); echo self::showItem($output_type, "<a href='" . getItemTypeFormURL($itemtype) . "?id=" . $data["refID"] . "&delete=delete' " . addConfirmationOnAction(array($LANG['reservation'][38], $LANG['reservation'][39])) . " title=\"" . $LANG['reservation'][6] . "\">" . "<img src='" . $CFG_GLPI["root_doc"] . "/pics/delete.png'\n alt='' title=''></a>", $item_num, $row_num, "class='center'"); } } if ($data["ACTIVE"]) { echo self::showItem($output_type, "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title=\"" . $LANG['reservation'][21] . "\">" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png\" alt='' title=''></a>", $item_num, $row_num, "class='center'"); } else { echo self::showItem($output_type, " ", $item_num, $row_num); } } // End Line echo self::showEndLine($output_type); } $title = ""; // Create title if ($output_type == PDF_OUTPUT_LANDSCAPE || $output_type == PDF_OUTPUT_PORTRAIT) { if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) { if (strlen($p['contains'][$key]) > 0) { if (isset($p["link"][$key])) { $title .= " " . $p["link"][$key] . " "; } switch ($p['field'][$key]) { case "all": $title .= $LANG['common'][66]; break; case "view": $title .= $LANG['search'][11]; break; default: $title .= $searchopt[$itemtype][$p['field'][$key]]["name"]; } switch ($p['searchtype'][$key]) { case "equals": if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) { $title .= ' = ' . Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]); } else { $title .= ' = ' . $p['contains'][$key]; } break; case "notequals": if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) { $title .= ' <> ' . Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]); } else { $title .= ' <> ' . $p['contains'][$key]; } break; case "lessthan": $title .= ' < ' . $p['contains'][$key]; break; case "morethan": $title .= ' > ' . $p['contains'][$key]; break; case "contains": $title .= ' = %' . $p['contains'][$key] . '%'; break; default: $title .= ' = ' . $p['contains'][$key]; break; } } } } if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && count($p['contains2']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) { if (strlen($p['contains2'][$key]) > 0) { if (isset($p['link2'][$key])) { $title .= " " . $p['link2'][$key] . " "; } $title .= $metanames[$p['itemtype2'][$key]] . "/"; $title .= $searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["name"]; switch ($p['searchtype2'][$key]) { case "equals": if (in_array($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["field"], array('name', 'completename'))) { $title .= ' = ' . Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]); } else { $title .= ' = ' . $p['contains2'][$key]; } break; case "notequals": if (in_array($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["field"], array('name', 'completename'))) { $title .= ' <> ' . Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]); } else { $title .= ' <> ' . $p['contains2'][$key]; } break; case "lessthan": $title .= ' < ' . $p['contains2'][$key]; break; case "morethan": $title .= ' > ' . $p['contains2'][$key]; break; case "contains": $title .= ' = %' . $p['contains2'][$key] . '%'; break; default: $title .= ' = ' . $p['contains2'][$key]; break; } } } } } // Display footer echo self::showFooter($output_type, $title); // Delete selected item if ($output_type == HTML_OUTPUT) { if ($isadmin) { openArrowMassive("massiveaction_form"); Dropdown::showForMassiveAction($itemtype, $p['is_deleted']); closeArrowMassive(); // End form for delete item echo "</form>\n"; } else { echo "<br>"; } } if ($output_type == HTML_OUTPUT) { // In case of HTML display printPager($p['start'], $numrows, $target, $parameters); } } else { echo self::showError($output_type); } } else { echo $DBread->error(); } // Clean selection $_SESSION['glpimassiveactionselected'] = array(); }
static function showActivationFormForItem($itemtype, $items_id) { global $CFG_GLPI, $LANG; if (!haveRight("reservation_central", "w")) { return false; } if (class_exists($itemtype)) { $item = new $itemtype(); if (!$item->getFromDB($items_id)) { return false; } // Recursive type case => need entity right if ($item->isRecursive()) { if (!haveAccessToEntity($item->fields["entities_id"])) { return false; } } } else { return false; } $ri = new ReservationItem(); echo "<div><form method='post' name=form action='" . getItemTypeFormURL('ReservationItem') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $LANG['reservation'][9] . "</th></tr>"; echo "<tr class='tab_bg_1'>"; if ($ri->getFromDBbyItem($itemtype, $items_id)) { echo "<td class='center'>"; //Switch reservation state echo "<input type='hidden' name='id' value='" . $ri->fields['id'] . "'>"; if ($ri->fields["is_active"]) { echo "<input type='hidden' name='is_active' value='0'>"; echo "<input type='submit' name='update' value=\"" . $LANG['reservation'][3] . "\"\n class='submit'>"; } else { echo "<input type='hidden' name='is_active' value='1'>"; echo "<input type='submit' name='update' value=\"" . $LANG['reservation'][5] . "\"\n class='submit'>"; } echo "<span class='small_space'>"; echo "<input type='submit' name='delete' value=\"" . $LANG['reservation'][6] . "\"\n class='submit' " . addConfirmationOnAction(array($LANG['reservation'][38], $LANG['reservation'][39])) . ">"; echo "</span></td>"; } else { echo "<td class='center'>"; echo "<input type='hidden' name='items_id' value='{$items_id}'>"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; echo "<input type='hidden' name='entities_id' value='" . $item->getEntityID() . "'>"; echo "<input type='hidden' name='is_recursive' value='" . $item->isRecursive() . "'>"; echo "<input type='submit' name='add' value=\"" . $LANG['reservation'][7] . "\" class='submit'>"; echo "</td>"; } echo "</tr></table></form></div>"; }
/** * Print the reminder form * * @param $ID Integer : Id of the item to print * @param $options array * - target filename : where to go when done. **/ function showForm($ID, $options = array()) { global $CFG_GLPI, $LANG; // Show Reminder or blank form $onfocus = ""; if ($ID > 0) { $this->check($ID, 'r'); } else { // Create item : do getempty before check right to set default values $this->check(-1, 'w'); $onfocus = "onfocus=\"if (this.value=='" . $this->fields['name'] . "') this.value='';\""; } $canedit = $this->can($ID, 'w'); if ($canedit) { echo "<form method='post' name='remind' action='" . $this->getFormURL() . "'>"; } echo "<div class='center'><table class='tab_cadre' width='450'>"; echo "<tr><th> </th><th>"; if (!$ID) { echo $LANG['reminder'][6]; } else { echo $LANG['common'][2] . " {$ID}"; } echo "</th></tr>\n"; echo "<tr class='tab_bg_2'><td>" . $LANG['common'][57] . " : </td>"; echo "<td>"; if ($canedit) { autocompletionTextField($this, "name", array('size' => 80, 'entity' => -1, 'user' => $this->fields["users_id"], 'option' => $onfocus)); } else { echo $this->fields['name']; } echo "</td></tr>\n"; if (!$canedit) { echo "<tr class='tab_bg_2'><td>" . $LANG['common'][95] . " : </td>"; echo "<td>"; echo getUserName($this->fields["users_id"]); echo "</td></tr>\n"; } echo "<tr class='tab_bg_2'><td>" . $LANG['common'][17] . " : </td>"; echo "<td>"; if ($canedit && haveRight("reminder_public", "w")) { if (!$ID) { if (isset($_GET["is_private"])) { $this->fields["is_private"] = $_GET["is_private"]; } if (isset($_GET["is_recursive"])) { $this->fields["is_recursive"] = $_GET["is_recursive"]; } } Dropdown::showPrivatePublicSwitch($this->fields["is_private"], $this->fields["entities_id"], $this->fields["is_recursive"]); } else { if ($this->fields["is_private"]) { echo $LANG['common'][77]; } else { echo $LANG['common'][76]; } } echo "</td></tr>\n"; if (haveRight("reminder_public", "w") && !$this->fields["is_private"]) { echo "<tr class='tab_bg_2'><td>" . $LANG['tracking'][39] . " : </td>"; echo "<td>"; if ($canedit) { Dropdown::showYesNo('is_helpdesk_visible', $this->fields['is_helpdesk_visible']); } else { echo Dropdpown::getYesNo($this->fields['is_helpdesk_visible']); } echo "</td></tr>\n"; } echo "<tr class='tab_bg_2'><td >" . $LANG['buttons'][15] . " : </td>"; echo "<td class='center'>"; if ($canedit) { echo "<script type='text/javascript' >\n"; echo "function showPlan() {\n"; echo "Ext.get('plan').setDisplayed('none');"; $params = array('form' => 'remind'); if ($ID && $this->fields["is_planned"]) { $params['state'] = $this->fields["state"]; $params['begin'] = $this->fields["begin"]; $params['end'] = $this->fields["end"]; } ajaxUpdateItemJsCode('viewplan', $CFG_GLPI["root_doc"] . "/ajax/planning.php", $params, false); echo "}"; echo "</script>\n"; } if (!$ID || !$this->fields["is_planned"]) { if (haveRight("show_planning", "1") || haveRight("show_group_planning", "1") || haveRight("show_all_planning", "1")) { echo "<div id='plan' onClick='showPlan()'>\n"; echo "<span class='showplan'>" . $LANG['reminder'][12] . "</span>"; } } else { if ($canedit) { echo "<div id='plan' onClick='showPlan()'>\n"; echo "<span class='showplan'>"; } echo Planning::getState($this->fields["state"]) . ": " . convDateTime($this->fields["begin"]) . "->" . convDateTime($this->fields["end"]); if ($canedit) { echo "</span>"; } } if ($canedit) { echo "</div>\n"; echo "<div id='viewplan'>\n"; echo "</div>\n"; } echo "</td></tr>\n"; echo "<tr class='tab_bg_2'><td>" . $LANG['reminder'][9] . " : </td><td>"; if ($canedit) { echo "<textarea cols='80' rows='15' name='text'>" . $this->fields["text"] . "</textarea>"; } else { echo nl2br($this->fields["text"]); } echo "</td></tr>\n"; if (!$ID) { // add echo "<tr><td class='tab_bg_2 top' colspan='2'>"; echo "<input type='hidden' name='users_id' value='" . $this->fields['users_id'] . "'>\n"; echo "<div class='center'>"; echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</div>"; echo "</td></tr>\n"; } else { if ($canedit) { echo "<tr><td class='tab_bg_2 top' colspan='2'>"; echo "<input type='hidden' name='id' value='{$ID}'>\n"; echo "<div class='center'>"; echo "<input type='submit' name='update' value=\"" . $LANG['buttons'][7] . "\" class='submit'>"; echo "<input type='hidden' name='id' value='{$ID}'><span class='medium_space'>"; echo "<input type='submit' name='delete' value=\"" . $LANG['buttons'][22] . "\"\n class='submit' " . addConfirmationOnAction($LANG['common'][50]) . ">\n </span>"; echo "</div>"; echo "</td></tr>\n"; } } echo "</table></div>\n"; if ($canedit) { echo "</form>"; } return true; }