/** * Display datas extracted from DB * * @param $data array of search datas prepared to get datas * * @return nothing **/ static function displayDatas(array &$data) { global $CFG_GLPI; $item = null; if (class_exists($data['itemtype'])) { $item = new $data['itemtype'](); } $rand = mt_rand(); if (!isset($data['data']) || !isset($data['data']['totalcount'])) { return false; } // Contruct Pager parameters $globallinkto = Toolbox::append_params(array('criteria' => Toolbox::stripslashes_deep($data['search']['criteria']), 'metacriteria' => Toolbox::stripslashes_deep($data['search']['metacriteria'])), '&'); $parameters = "sort=" . $data['search']['sort'] . "&order=" . $data['search']['order'] . '&' . $globallinkto; if (isset($_GET['_in_modal'])) { $parameters .= "&_in_modal=1"; } // Global search header if ($data['display_type'] == self::GLOBAL_SEARCH) { if ($data['item']) { echo "<div class='center'><h2>" . $data['item']->getTypeName(); // More items if ($data['data']['totalcount'] > $data['search']['start'] + self::GLOBAL_DISPLAY_COUNT) { echo " <a href='" . $data['search']['target'] . "?{$parameters}'>" . __('All') . "</a>"; } echo "</h2></div>\n"; } else { return false; } } // If the begin of the view is before the number of items if ($data['data']['count'] > 0) { // Display pager only for HTML if ($data['display_type'] == self::HTML_OUTPUT) { // For plugin add new parameter if available if ($plug = isPluginItemType($data['itemtype'])) { $function = 'plugin_' . $plug['plugin'] . '_addParamFordynamicReport'; if (function_exists($function)) { $out = $function($data['itemtype']); if (is_array($out) && count($out)) { $parameters .= Toolbox::append_params($out, '&'); } } } $search_config_top = ""; $search_config_bottom = ""; if (!isset($_GET['_in_modal']) && Session::haveRightsOr('search_config', array(DisplayPreference::PERSONAL, DisplayPreference::GENERAL))) { $search_config_top = $search_config_bottom = "<div class='pager_controls'><img alt=\"" . __s('Select default items to show') . "\" title=\"" . __s('Select default items to show') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config_top .= " class='pointer' onClick=\""; $search_config_top .= Html::jsGetElementbyID('search_config_top') . ".dialog('open');\">"; $search_config_bottom .= " class='pointer' onClick=\""; $search_config_bottom .= Html::jsGetElementbyID('search_config_bottom') . ".dialog('open');\">"; $search_config_top .= Ajax::createIframeModalWindow('search_config_top', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false)); $search_config_bottom .= Ajax::createIframeModalWindow('search_config_bottom', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false)); } if ($item !== null && $item->maybeDeleted()) { $delete_ctrl = self::isDeletedSwitch($data['search']['is_deleted']); $search_config_top .= $delete_ctrl; } Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, $data['itemtype'], 0, $search_config_top); $search_config_top .= "</div>"; $search_config_bottom .= "</div>"; } // Define begin and end var for loop // Search case $begin_display = $data['data']['begin']; $end_display = $data['data']['end']; // Form to massive actions $isadmin = $data['item'] && $data['item']->canUpdate(); if (!$isadmin && InfoCom::canApplyOn($data['itemtype'])) { $isadmin = Infocom::canUpdate() || Infocom::canCreate(); } if ($data['itemtype'] != 'AllAssets') { $showmassiveactions = count(MassiveAction::getAllMassiveActions($data['item'], $data['search']['is_deleted'])); } else { $showmassiveactions = true; } $massformid = 'massform' . $data['itemtype']; if ($showmassiveactions && $data['display_type'] == self::HTML_OUTPUT) { Html::openMassiveActionsForm($massformid); $massiveactionparams = $data['search']['massiveactionparams']; $massiveactionparams['num_displayed'] = $end_display - $begin_display; $massiveactionparams['fixed'] = false; $massiveactionparams['is_deleted'] = $data['search']['is_deleted']; $massiveactionparams['container'] = $massformid; Html::showMassiveActions($massiveactionparams); } // Compute number of columns to display // Add toview elements $nbcols = count($data['data']['cols']); if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $nbcols++; } // Display List Header echo self::showHeader($data['display_type'], $end_display - $begin_display + 1, $nbcols); // New Line for Header Items Line $headers_line = ''; $headers_line_top = ''; $headers_line_bottom = ''; $headers_line_top .= self::showBeginHeader($data['display_type']); $headers_line_top .= self::showNewLine($data['display_type']); if ($data['display_type'] == self::HTML_OUTPUT) { // $headers_line_bottom .= self::showBeginHeader($data['display_type']); $headers_line_bottom .= self::showNewLine($data['display_type']); } $header_num = 1; if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $headers_line_top .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']); if ($data['display_type'] == self::HTML_OUTPUT) { $headers_line_bottom .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']); } } // Display column Headers for toview items $metanames = array(); foreach ($data['data']['cols'] as $key => $val) { $linkto = ''; if (!$val['meta'] && (!isset($val['searchopt']['nosort']) || !$val['searchopt']['nosort'])) { $linkto = $data['search']['target'] . (strpos($data['search']['target'], '?') ? '&' : '?') . "itemtype=" . $data['itemtype'] . "&sort=" . $val['id'] . "&order=" . ($data['search']['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $data['search']['start'] . "&" . $globallinkto; } $name = $val["name"]; // prefix by group name (corresponding to optgroup in dropdown) if exists if (isset($val['groupname'])) { $name = $val['groupname'] . " - " . $name; } // Not main itemtype add itemtype to display if ($data['itemtype'] != $val['itemtype']) { if (!isset($metanames[$val['itemtype']])) { if ($metaitem = getItemForItemtype($val['itemtype'])) { $metanames[$val['itemtype']] = $metaitem->getTypeName(); } } $name = sprintf(__('%1$s - %2$s'), $metanames[$val['itemtype']], $val["name"]); } $headers_line .= self::showHeaderItem($data['display_type'], $name, $header_num, $linkto, !$val['meta'] && $data['search']['sort'] == $val['id'], $data['search']['order']); } // Add specific column Header if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { $headers_line .= self::showHeaderItem($data['display_type'], __('Item type'), $header_num); } // End Line for column headers $headers_line .= self::showEndLine($data['display_type']); $headers_line_top .= $headers_line; if ($data['display_type'] == self::HTML_OUTPUT) { $headers_line_bottom .= $headers_line; } $headers_line_top .= self::showEndHeader($data['display_type']); // $headers_line_bottom .= self::showEndHeader($data['display_type']); echo $headers_line_top; // Init list of items displayed if ($data['display_type'] == self::HTML_OUTPUT) { Session::initNavigateListItems($data['itemtype']); } // Num of the row (1=header_line) $row_num = 1; $massiveaction_field = 'id'; if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { $massiveaction_field = 'refID'; } $typenames = array(); // Display Loop foreach ($data['data']['rows'] as $rowkey => $row) { // Column num $item_num = 1; $row_num++; // New line echo self::showNewLine($data['display_type'], $row_num % 2, $data['search']['is_deleted']); $current_type = isset($row['TYPE']) ? $row['TYPE'] : $data['itemtype']; $massiveaction_type = $current_type; if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { $massiveaction_type = $data['itemtype']; } // Add item in item list Session::addToNavigateListItems($current_type, $row["id"]); if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $tmpcheck = ""; if ($data['itemtype'] == 'Entity' && !in_array($row["id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { if ($data['item'] instanceof CommonDBTM && $data['item']->maybeRecursive() && !in_array($row["entities_id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { $tmpcheck = Html::getMassiveActionCheckBox($massiveaction_type, $row[$massiveaction_field]); } } echo self::showItem($data['display_type'], $tmpcheck, $item_num, $row_num, "width='10'"); } // Print other toview items foreach ($data['data']['cols'] as $colkey => $col) { if (!$col['meta']) { echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num, self::displayConfigItem($data['itemtype'], $col['id'], $row, $colkey)); } else { // META case echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num); } } if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { if (!isset($typenames[$row["TYPE"]])) { if ($itemtmp = getItemForItemtype($row["TYPE"])) { $typenames[$row["TYPE"]] = $itemtmp->getTypeName(); } } echo self::showItem($data['display_type'], $typenames[$row["TYPE"]], $item_num, $row_num); } // End Line echo self::showEndLine($data['display_type']); } // Create title $title = ''; if ($data['display_type'] == self::PDF_OUTPUT_LANDSCAPE || $data['display_type'] == self::PDF_OUTPUT_PORTRAIT) { $title = self::computeTitle($data); } if ($data['display_type'] == self::HTML_OUTPUT) { echo $headers_line_bottom; } // Display footer echo self::showFooter($data['display_type'], $title); // Delete selected item if ($data['display_type'] == self::HTML_OUTPUT) { if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); // End form for delete item Html::closeForm(); } else { echo "<br>"; } } if ($data['display_type'] == self::HTML_OUTPUT) { // In case of HTML display Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, '', 0, $search_config_bottom); } } else { if ($item !== null && $item->maybeDeleted()) { echo "<div class='center'>" . self::isDeletedSwitch($data['search']['is_deleted']) . "</div><br/>"; } echo self::showError($data['display_type']); } }
/** * @since version 0.84 (before in entitydata.class) * * @param $entity Entity object **/ static function showInventoryOptions(Entity $entity) { $ID = $entity->getField('id'); if (!$entity->can($ID, READ)) { return false; } // Notification right applied $canedit = Infocom::canUpdate() && Session::haveAccessToEntity($ID); echo "<div class='spaced'>"; if ($canedit) { echo "<form method='post' name=form action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; } echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . __('Autofill dates for financial and administrative information') . "</th></tr>"; $options[0] = __('No autofill'); if ($ID > 0) { $options[self::CONFIG_PARENT] = __('Inheritance of the parent entity'); } foreach (getAllDatasFromTable('glpi_states') as $state) { $options[Infocom::ON_STATUS_CHANGE . '_' . $state['id']] = sprintf(__('Fill when shifting to state %s'), $state['name']); } $options[Infocom::COPY_WARRANTY_DATE] = __('Copy the start date of warranty'); //Buy date echo "<tr class='tab_bg_2'>"; echo "<td> " . __('Date of purchase') . "</td>"; echo "<td>"; Dropdown::showFromArray('autofill_buy_date', $options, array('value' => $entity->getField('autofill_buy_date'))); echo "</td>"; //Order date echo "<td> " . __('Order date') . "</td>"; echo "<td>"; $options[Infocom::COPY_BUY_DATE] = __('Copy the date of purchase'); Dropdown::showFromArray('autofill_order_date', $options, array('value' => $entity->getField('autofill_order_date'))); echo "</td></tr>"; //Delivery date echo "<tr class='tab_bg_2'>"; echo "<td> " . __('Delivery date') . "</td>"; echo "<td>"; $options[Infocom::COPY_ORDER_DATE] = __('Copy the order date'); Dropdown::showFromArray('autofill_delivery_date', $options, array('value' => $entity->getField('autofill_delivery_date'))); echo "</td>"; //Use date echo "<td> " . __('Startup date') . " </td>"; echo "<td>"; $options[Infocom::COPY_DELIVERY_DATE] = __('Copy the delivery date'); Dropdown::showFromArray('autofill_use_date', $options, array('value' => $entity->getField('autofill_use_date'))); echo "</td></tr>"; //Warranty date echo "<tr class='tab_bg_2'>"; echo "<td> " . __('Start date of warranty') . "</td>"; echo "<td>"; $options = array(0 => __('No autofill'), Infocom::COPY_BUY_DATE => __('Copy the date of purchase'), Infocom::COPY_ORDER_DATE => __('Copy the order date'), Infocom::COPY_DELIVERY_DATE => __('Copy the delivery date')); if ($ID > 0) { $options[self::CONFIG_PARENT] = __('Inheritance of the parent entity'); } Dropdown::showFromArray('autofill_warranty_date', $options, array('value' => $entity->getField('autofill_warranty_date'))); echo "</td><td colspan='2'></td></tr>"; echo "<tr><th colspan='4'>" . _n('Software', 'Software', Session::getPluralNumber()) . "</th></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td> " . __('Entity for software creation') . "</td>"; echo "<td>"; $toadd = array(self::CONFIG_NEVER => __('No change of entity')); // Keep software in PC entity if ($ID > 0) { $toadd[self::CONFIG_PARENT] = __('Inheritance of the parent entity'); } $entities = array($entity->fields['entities_id']); foreach (getAncestorsOf('glpi_entities', $entity->fields['entities_id']) as $ent) { if (Session::haveAccessToEntity($ent)) { $entities[] = $ent; } } self::dropdown(array('name' => 'entities_id_software', 'value' => $entity->getField('entities_id_software'), 'toadd' => $toadd, 'entity' => $entities, 'comments' => false)); if ($entity->fields['entities_id_software'] == self::CONFIG_PARENT) { $tid = self::getUsedConfig('entities_id_software', $entity->getField('entities_id')); echo "<font class='green'> "; echo self::getSpecificValueToDisplay('entities_id_software', $tid); echo "</font>"; } echo "</td><td colspan='2'></td></tr>"; if ($canedit) { echo "<tr>"; echo "<td class='tab_bg_2 center' colspan='4'>"; echo "<input type='hidden' name='id' value='" . $entity->fields["id"] . "'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); } else { echo "</table>"; } echo "</div>"; }
/** * @see CommonDBTM::showMassiveActionsSubForm() **/ static function showMassiveActionsSubForm(MassiveAction $ma) { global $CFG_GLPI; switch ($ma->getAction()) { case 'update': if (!isset($ma->POST['id_field'])) { $itemtypes = array_keys($ma->items); $options_per_type = array(); $options_counts = array(); foreach ($itemtypes as $itemtype) { $options_per_type[$itemtype] = array(); $group = ''; $show_all = true; $show_infocoms = true; $itemtable = getTableForItemType($itemtype); if (InfoCom::canApplyOn($itemtype) && (!$itemtype::canUpdate() || !Infocom::canUpdate())) { $show_all = false; $show_infocoms = Infocom::canUpdate(); } foreach (Search::getCleanedOptions($itemtype, UPDATE) as $index => $option) { if (!is_array($option)) { $group = $option; $options_per_type[$itemtype][$group] = array(); } else { if ($option['field'] != 'id' && $index != 1 && ($option["linkfield"] != 'entities_id' || isset($option['massiveaction']) && $option['massiveaction'])) { if (!isset($option['massiveaction']) || $option['massiveaction']) { if ($show_all || ($show_infocoms && Search::isInfocomOption($itemtype, $index) || !$show_infocoms && !Search::isInfocomOption($itemtype, $index))) { $options_per_type[$itemtype][$group][$itemtype . ':' . $index] = $option['name']; if ($itemtable == $option['table']) { $field_key = 'MAIN:' . $option['field'] . ':' . $index; } else { $field_key = $option['table'] . ':' . $option['field'] . ':' . $index; } if (!isset($options_count[$field_key])) { $options_count[$field_key] = array(); } $options_count[$field_key][] = $itemtype . ':' . $index . ':' . $group; if (isset($option['MA_common_field'])) { if (!isset($options_count[$option['MA_common_field']])) { $options_count[$option['MA_common_field']] = array(); } $options_count[$option['MA_common_field']][] = $itemtype . ':' . $index . ':' . $group; } } } } } } } if (count($itemtypes) > 1) { $common_options = array(); foreach ($options_count as $field => $users) { if (count($users) > 1) { $labels = array(); foreach ($users as $user) { $user = explode(':', $user); $itemtype = $user[0]; $index = $itemtype . ':' . $user[1]; $group = implode(':', array_slice($user, 2)); if (isset($options_per_type[$itemtype][$group][$index])) { if (!in_array($options_per_type[$itemtype][$group][$index], $labels)) { $labels[] = $options_per_type[$itemtype][$group][$index]; } } $common_options[$field][] = $index; } $options[$group][$field] = implode('/', $labels); } } $choose_itemtype = true; $itemtype_choices = array(-1 => Dropdown::EMPTY_VALUE); foreach ($itemtypes as $itemtype) { $itemtype_choices[$itemtype] = $itemtype::getTypeName(Session::getPluralNumber()); } } else { $options = $options_per_type[$itemtypes[0]]; $common_options = false; $choose_itemtype = false; } $choose_field = count($options) > 1; // Beware: "class='tab_cadre_fixe'" induce side effects ... echo "<table width='100%'><tr>"; $colspan = 0; if ($choose_field) { $colspan++; echo "<td>"; if ($common_options) { echo __('Select the common field that you want to update'); } else { echo __('Select the field that you want to update'); } echo "</td>"; if ($choose_itemtype) { $colspan++; echo "<td rowspan='2'>" . __('or') . "</td>"; } } if ($choose_itemtype) { $colspan++; echo "<td>" . __('Select the type of the item on which applying this action') . "</td>"; } echo "</tr><tr>"; if ($choose_field) { echo "<td>"; $field_rand = Dropdown::showFromArray('id_field', $options, array('display_emptychoice' => true)); echo "</td>"; } if ($choose_itemtype) { echo "<td>"; $itemtype_rand = Dropdown::showFromArray('specialize_itemtype', $itemtype_choices); echo "</td>"; } $next_step_rand = mt_rand(); echo "</tr></table>"; echo "<span id='update_next_step{$next_step_rand}'> </span>"; if ($choose_field) { $params = $ma->POST; $params['id_field'] = '__VALUE__'; $params['common_options'] = $common_options; Ajax::updateItemOnSelectEvent("dropdown_id_field{$field_rand}", "update_next_step{$next_step_rand}", $_SERVER['REQUEST_URI'], $params); } if ($choose_itemtype) { $params = $ma->POST; $params['specialize_itemtype'] = '__VALUE__'; $params['common_options'] = $common_options; Ajax::updateItemOnSelectEvent("dropdown_specialize_itemtype{$itemtype_rand}", "update_next_step{$next_step_rand}", $_SERVER['REQUEST_URI'], $params); } // Only display the form for this stage exit; } if (!isset($ma->POST['common_options'])) { echo "<div class='center'><img src='" . $CFG_GLPI["root_doc"] . "/pics/warning.png' alt='" . __s('Warning') . "'><br><br>"; echo "<span class='b'>" . __('Implementation error !') . "</span><br>"; echo "</div>"; exit; } if ($ma->POST['common_options'] == 'false') { $search_options = array($ma->POST['id_field']); } else { if (isset($ma->POST['common_options'][$ma->POST['id_field']])) { $search_options = $ma->POST['common_options'][$ma->POST['id_field']]; } else { $search_options = array(); } } $items = array(); foreach ($search_options as $search_option) { $search_option = explode(':', $search_option); $itemtype = $search_option[0]; $index = $search_option[1]; if (!($item = getItemForItemtype($itemtype))) { continue; } if (InfoCom::canApplyOn($itemtype)) { Session::checkSeveralRightsOr(array($itemtype => UPDATE, "infocom" => UPDATE)); } else { $item->checkGlobal(UPDATE); } $search = Search::getOptions($itemtype); if (!isset($search[$index])) { exit; } $item->search = $search[$index]; $items[] = $item; } if (count($items) == 0) { exit; } // TODO: ensure that all items are equivalent ... $item = $items[0]; $search = $item->search; $plugdisplay = false; if (($plug = isPluginItemType($item->getType())) || ($plug = isPluginItemType(getItemTypeForTable($item->search['table'])))) { $plugdisplay = Plugin::doOneHook($plug['plugin'], 'MassiveActionsFieldsDisplay', array('itemtype' => $item->getType(), 'options' => $item->search)); } if (empty($search["linkfield"]) || $search['table'] == 'glpi_infocoms') { $fieldname = $search["field"]; } else { $fieldname = $search["linkfield"]; } if (!$plugdisplay) { $options = array(); $values = array(); // For ticket template or aditional options of massive actions if (isset($ma->POST['options'])) { $options = $ma->POST['options']; } if (isset($ma->POST['additionalvalues'])) { $values = $ma->POST['additionalvalues']; } $values[$search["field"]] = ''; echo $item->getValueToSelect($search, $fieldname, $values, $options); } $items_index = array(); foreach ($search_options as $search_option) { $search_option = explode(':', $search_option); $items_index[$search_option[0]] = $search_option[1]; } echo Html::hidden('search_options', array('value' => $items_index)); echo Html::hidden('field', array('value' => $fieldname)); echo "<br>\n"; $submitname = _sx('button', 'Post'); if (isset($ma->POST['submitname']) && $ma->POST['submitname']) { $submitname = stripslashes($ma->POST['submitname']); } echo Html::submit($submitname, array('name' => 'massiveaction')); return true; } return false; }
/** * Show infocom link to display modal * * @param $itemtype integer item type * @param $device_id integer item ID * * @return float **/ static function showDisplayLink($itemtype, $device_id) { global $DB, $CFG_GLPI; if (!Session::haveRight(self::$rightname, READ) || !($item = getItemForItemtype($itemtype))) { return false; } $query = "SELECT COUNT(*)\n FROM `glpi_infocoms`\n WHERE `items_id` = '{$device_id}'\n AND `itemtype` = '{$itemtype}'"; $add = "add"; $text = __('Add'); $result = $DB->query($query); if ($DB->result($result, 0, 0) > 0) { $add = ""; $text = _x('button', 'Show'); } else { if (!Infocom::canUpdate()) { return false; } } if ($item->canView()) { echo "<span onClick=\"" . Html::jsGetElementbyID('infocom' . $itemtype . $device_id) . ".\n dialog('open');\" style='cursor:pointer'>\n <img src=\"" . $CFG_GLPI["root_doc"] . "/pics/dollar{$add}.png\" alt=\"{$text}\" title=\"{$text}\">\n </span>"; Ajax::createIframeModalWindow('infocom' . $itemtype . $device_id, $CFG_GLPI["root_doc"] . "/front/infocom.form.php" . "?itemtype={$itemtype}&items_id={$device_id}", array('height' => 600)); } }
/** * Generic Search and list function * * Build the query, make the search and list items after a search. * * @param $itemtype item type * @param $params array of parameters may include field, contains, searchtype, sort, order, * start, deleted, link, link2, contains2, field2, itemtype2, searchtype2 * * @return Nothing (display) **/ static function showList($itemtype, array $params) { global $DB, $CFG_GLPI; // Instanciate an object to access method $item = NULL; if ($itemtype != 'AllAssets') { $item = getItemForItemtype($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; } if (in_array('all', $p['field']) && !$CFG_GLPI['allow_search_all']) { Html::displayRightError(); } if (in_array('view', $p['field']) && !$CFG_GLPI['allow_search_view']) { Html::displayRightError(); } // 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 = Toolbox::getItemTypeSearchURL($itemtype); $limitsearchopt = self::getCleanedOptions($itemtype); $blacklist_tables = array(); if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $itemtable = $CFG_GLPI['union_search_type'][$itemtype]; $blacklist_tables[] = getTableForItemType($itemtype); } else { $itemtable = getTableForItemType($itemtype); } $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = self::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == self::GLOBAL_SEARCH) { $LIST_LIMIT = self::GLOBAL_DISPLAY_COUNT; } } // hack for AllAssets if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $entity_restrict = true; } else { $entity_restrict = $item->isEntityAssign(); } self::$output_type = $output_type; $metanames = array(); // Get the items to display $toview = self::addDefaultToView($itemtype); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser($itemtype, 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']); } // 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 '" . Toolbox::addslashes_deep($_SESSION['glpiname']) . "' AS currentuser,\n " . 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) { if (!in_array($searchopt[$itemtype][$val]["table"], $blacklist_tables)) { $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)) { if (!in_array($searchopt[$itemtype][$key]["table"], $blacklist_tables)) { $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 (isset($val2['nosearch']) && $val2['nosearch']) { continue; } 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},\n '" . Toolbox::addslashes_deep($_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); if (($citem = getItemForItemtype($ctype)) && $citem->canView()) { // State case if ($itemtype == 'AllAssets') { $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $query_num = str_replace($itemtype, $ctype, $query_num); $query_num .= " AND `{$ctable}`.`id` IS NOT NULL "; // 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); if ($item && $item->maybeDeleted()) { $tmpquery = str_replace("`" . $CFG_GLPI["union_search_type"][$itemtype] . "`.`is_deleted`", "`{$reftable}`.`is_deleted`", $tmpquery); } $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); if (($citem = getItemForItemtype($ctype)) && $citem->canView()) { if ($first) { $first = false; } else { $QUERY .= " UNION "; } $tmpquery = ""; // AllAssets case if ($itemtype == 'AllAssets') { $tmpquery = $SELECT . ", '{$ctype}' AS TYPE " . $FROM . $WHERE; if ($itemtype == 'AllAssets') { $tmpquery .= " AND `{$ctable}`.`id` IS NOT NULL "; } // 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' "; } $tmpquery .= $GROUPBY . $HAVING; $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $tmpquery = str_replace($itemtype, $ctype, $tmpquery); } 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; if ($item->maybeDeleted()) { $tmpquery = str_replace("`" . $CFG_GLPI["union_search_type"][$itemtype] . "`.`is_deleted`", "`{$reftable}`.`is_deleted`", $tmpquery); } $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 == self::GLOBAL_SEARCH) { if ($item = getItemForItemtype($itemtype)) { echo "<div class='center'><h2>" . $item->getTypeName(); // More items if ($numrows > $p['start'] + self::GLOBAL_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}'>" . __('All') . "</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 == self::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}"; } } } } } $search_config = ""; if (Session::haveRight("search_config", DisplayPreference::GENERAL)) { //|| Session::haveRight("search_config_global",CREATE)) { // Ajax::createModalWindow('searchconfig_window', // $CFG_GLPI['root_doc']."/ajax/searchconfig.php?itemtype=$itemtype", // array('title' => __('Select default items to show'), // 'width' => '1000')); // $tmp = " class='pointer' onClick=\"searchconfig_window.show()\""; $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=\"" . __s('Select default items to show') . "\" title=\"" . __s('Select default items to show') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config .= $tmp . ">"; } Html::printPager($p['start'], $numrows, $target, $parameters, $itemtype, 0, $search_config); } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = min($numrows, $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; } // Form to massive actions $isadmin = $item && $item->canUpdate(); if (!$isadmin && in_array($itemtype, $CFG_GLPI["infocom_types"])) { $isadmin = Infocom::canUpdate() || Infocom::canCreate(); } $showmassiveactions = false; if ($itemtype != 'AllAssets') { $showmassiveactions = count($item->getAllMassiveActions($p['is_deleted'])); if ($showmassiveactions && $output_type == self::HTML_OUTPUT) { Html::openMassiveActionsForm('massform' . $itemtype); $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => false, 'is_deleted' => $p['is_deleted']); Html::showMassiveActions($itemtype, $massiveactionparams); } } // 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]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0 && (!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 == self::HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Display List Header echo self::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); // New Line for Header Items Line $headers_line = ''; $headers_line_top = ''; $headers_line_bottom = ''; echo self::showNewLine($output_type); $header_num = 1; if ($output_type == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $headers_line_top .= self::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); $headers_line_bottom .= self::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[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) { $linkto = "{$target}?itemtype={$itemtype}&sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto; } $headers_line .= 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]])) { if ($metaitem = getItemForItemtype($p['itemtype2'][$i])) { $metanames[$p['itemtype2'][$i]] = $metaitem->getTypeName(); } } $headers_line .= self::showHeaderItem($output_type, sprintf(__('%1$s - %2$s'), $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') { $headers_line .= self::showHeaderItem($output_type, _n('Cartridge', 'Cartridges', 2), $header_num); } if ($itemtype == 'ConsumableItem') { $headers_line .= self::showHeaderItem($output_type, _n('Consumable', 'Consumables', 2), $header_num); } if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $headers_line .= self::showHeaderItem($output_type, __('Item type'), $header_num); } if ($itemtype == 'ReservationItem' && $output_type == self::HTML_OUTPUT) { $headers_line .= self::showHeaderItem($output_type, " ", $header_num); } // End Line for column headers $headers_line .= self::showEndLine($output_type); $headers_line_top .= $headers_line; $headers_line_bottom .= $headers_line; echo $headers_line_top; // 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 == self::HTML_OUTPUT) { Session::initNavigateListItems($itemtype); } // Num of the row (1=header_line) $row_num = 1; $massiveaction_field = 'id'; if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $massiveaction_field = 'refID'; } // 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 Session::addToNavigateListItems($itemtype, $data["id"]); if ($output_type == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $tmpcheck = ""; if ($itemtype == 'Entity' && !in_array($data["id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { if ($item->maybeRecursive() && !in_array($data["entities_id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { $tmpcheck = Html::getMassiveActionCheckBox($itemtype, $data[$massiveaction_field]); } } 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 = self::explodeWithID("\$\$", $split[$k]); if (isset($split2[1])) { if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['datatype']) && $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['datatype'] == 'itemlink') { $out .= "<a id='" . $p['itemtype2'][$j] . '_' . $data["id"] . '_' . $split2[1] . "' "; $out .= "href=\"" . Toolbox::getItemTypeFormURL($p['itemtype2'][$j]) . "?id=" . $split2[1] . "\">"; $out .= Dropdown::getValueWithUnit($split2[0], $unit); $linkout = $out; if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $linkout = sprintf(__('%1$s (%2$s)'), $linkout, $split2[1]); } $out = $linkout . "</a>"; } else { $out .= Dropdown::getValueWithUnit($split2[0], $unit); } } else { $out .= Dropdown::getValueWithUnit($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 != self::HTML_OUTPUT), $item_num, $row_num); } if ($itemtype == 'ConsumableItem') { echo self::showItem($output_type, Consumable::getCount($data["id"], $data["ALARM"], $output_type != self::HTML_OUTPUT), $item_num, $row_num); } if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $typename = $data["TYPE"]; if ($itemtmp = getItemForItemtype($data["TYPE"])) { $typename = $itemtmp->getTypeName(); } echo self::showItem($output_type, $typename, $item_num, $row_num); } if ($itemtype == 'ReservationItem' && $output_type == self::HTML_OUTPUT) { if ($data["ACTIVE"]) { echo self::showItem($output_type, "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title=\"" . __s('See planning') . "\">" . "<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 == self::PDF_OUTPUT_LANDSCAPE || $output_type == self::PDF_OUTPUT_PORTRAIT) { if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) { $titlecontain = ''; if (strlen($p['contains'][$key]) > 0) { if (isset($p["link"][$key])) { $titlecontain = " " . $p["link"][$key] . " "; } switch ($p['field'][$key]) { case "all": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, __('All')); break; case "view": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, __('Items seen')); break; default: $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, $searchopt[$itemtype][$p['field'][$key]]["name"]); } switch ($p['searchtype'][$key]) { case "equals": if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) { $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key])); } else { $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, $p['contains'][$key]); } break; case "notequals": if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) { $titlecontain = sprintf(__('%1$s <> %2$s'), $titlecontain, Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key])); } else { $titlecontain = sprintf(__('%1$s <> %2$s'), $titlecontain, $p['contains'][$key]); } break; case "lessthan": $titlecontain = sprintf(__('%1$s < %2$s'), $titlecontain, $p['contains'][$key]); break; case "morethan": $titlecontain = sprintf(__('%1$s > %2$s'), $titlecontain, $p['contains'][$key]); break; case "contains": $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, '%' . $p['contains'][$key] . '%'); break; case "under": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, sprintf(__('%1$s %2$s'), __('under'), Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]))); break; case "notunder": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, sprintf(__('%1$s %2$s'), __('not under'), Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]))); break; default: $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, $p['contains'][$key]); break; } } $title .= $titlecontain; } } if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && count($p['contains2']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) { $titlecontain2 = ''; if (strlen($p['contains2'][$key]) > 0) { if (isset($p['link2'][$key])) { $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, $p['link2'][$key]); } $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s / %2$s'), $metanames[$p['itemtype2'][$key]], $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'))) { $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key])); } else { $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, $p['contains2'][$key]); } break; case "notequals": if (in_array($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["field"], array('name', 'completename'))) { $titlecontain2 = sprintf(__('%1$s <> %2$s'), $titlecontain2, Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key])); } else { $titlecontain2 = sprintf(__('%1$s <> %2$s'), $titlecontain2, $p['contains2'][$key]); } break; case "lessthan": $titlecontain2 = sprintf(__('%1$s < %2$s'), $titlecontain2, $p['contains2'][$key]); break; case "morethan": $titlecontain2 = sprintf(__('%1$s > %2$s'), $titlecontain2, $p['contains2'][$key]); break; case "contains": $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, '%' . $p['contains2'][$key] . '%'); break; case "under": $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s %2$s'), __('under'), Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]))); break; case "notunder": $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s %2$s'), __('not under'), Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]))); break; default: $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, $p['contains2'][$key]); break; } } $title .= $titlecontain2; } } } if ($output_type == self::HTML_OUTPUT) { echo $headers_line_bottom; } // Display footer echo self::showFooter($output_type, $title); // Delete selected item if ($output_type == self::HTML_OUTPUT) { if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($itemtype, $massiveactionparams); // End form for delete item Html::closeForm(); } else { echo "<br>"; } } if ($output_type == self::HTML_OUTPUT) { // In case of HTML display Html::printPager($p['start'], $numrows, $target, $parameters, '', 0, $search_config); } } else { echo self::showError($output_type); } } else { echo $DBread->error(); } }
echo " <input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>"; break; case "duplicate": if ($item->isEntityAssign()) { Dropdown::show('Entity'); } echo " <input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>"; break; case "update": $first_group = true; $newgroup = ""; $items_in_group = 0; $show_all = true; $show_infocoms = true; $ic = new Infocom(); if (in_array($_POST["itemtype"], $CFG_GLPI["infocom_types"]) && (!$item->canUpdate() || !$ic->canUpdate())) { $show_all = false; $show_infocoms = $ic->canUpdate(); } $searchopt = Search::getCleanedOptions($_POST["itemtype"], 'w'); echo "<select name='id_field' id='massiveaction_field'>"; echo "<option value='0' selected>" . DROPDOWN_EMPTY_VALUE . "</option>"; foreach ($searchopt as $key => $val) { if (!is_array($val)) { if (!empty($newgroup) && $items_in_group > 0) { echo $newgroup; $first_group = false; } $items_in_group = 0; $newgroup = ""; if (!$first_group) {
/** * Get the standard massive actions * * @since version 0.84 * * This must not be overloaded in Class * @param $is_deleted massive action for deleted items ? (default 0) * @param $checkitem link item to check right (default NULL) * * @return an array of massive actions **/ function getAllMassiveActions($is_deleted = 0, $checkitem = NULL) { global $CFG_GLPI, $PLUGIN_HOOKS; if (!is_null($checkitem)) { $isadmin = $checkitem->canUpdate(); } else { $isadmin = static::canUpdate(); } $itemtype = $this->getType(); $actions = array(); if ($is_deleted) { if ($isadmin) { $actions['purge'] = _x('button', 'Delete permanently'); $actions['restore'] = _x('button', 'Restore'); } } else { if ($isadmin || in_array($itemtype, $CFG_GLPI["infocom_types"]) && Infocom::canUpdate()) { //TRANS: select action 'update' (before doing it) $actions['update'] = _x('button', 'Update'); } if (in_array($itemtype, $CFG_GLPI["infocom_types"]) && Infocom::canCreate()) { $actions['activate_infocoms'] = __('Enable the financial and administrative information'); } // No delete for entities and tracking of not have right if ($isadmin) { // do not take into account is_deleted if items may be dynamic if ($this->maybeDeleted() && !$this->useDeletedToLockIfDynamic()) { $actions['delete'] = _x('button', 'Put in dustbin'); } else { $actions['purge'] = _x('button', 'Delete permanently'); } } if (in_array($itemtype, $CFG_GLPI["document_types"])) { if (Document::canView()) { $actions['add_document'] = _x('button', 'Add a document'); $actions['remove_document'] = _x('button', 'Remove a document'); } } if (in_array($itemtype, $CFG_GLPI["contract_types"])) { if (Contract::canUpdate()) { $actions['add_contract_item'] = _x('button', 'Add a contract'); $actions['remove_contract_item'] = _x('button', 'Remove a contract'); } } // Specific actions $actions += $this->getSpecificMassiveActions($checkitem); // Plugin Specific actions if (isset($PLUGIN_HOOKS['use_massive_action'])) { foreach ($PLUGIN_HOOKS['use_massive_action'] as $plugin => $val) { $plug_actions = Plugin::doOneHook($plugin, 'MassiveActions', $itemtype); if (count($plug_actions)) { $actions += $plug_actions; } } } } //Add unlock if needed $actions += Lock::getUnlockMassiveActions($itemtype); // Manage forbidden actions $forbidden_actions = $this->getForbiddenStandardMassiveAction(); if (is_array($forbidden_actions) && count($forbidden_actions)) { foreach ($forbidden_actions as $actiontodel) { if (isset($actions[$actiontodel])) { unset($actions[$actiontodel]); } } } return $actions; }
/** * Dropdown of actions for massive action * * @param $itemtype item type * @param $is_deleted massive action for deleted items ? * @param $extraparams array of extra parameters **/ static function showForMassiveAction($itemtype, $is_deleted = 0, $extraparams = array()) { global $LANG, $CFG_GLPI, $PLUGIN_HOOKS; /// TODO include in CommonDBTM defining only getAdditionalMassiveAction in sub classes /// for specific actions (return a array of action name and title) if (!class_exists($itemtype)) { return false; } if ($itemtype == 'NetworkPort') { echo "<select name='massiveaction' id='massiveaction'>"; echo "<option value='-1' selected>" . DROPDOWN_EMPTY_VALUE . "</option>"; echo "<option value='delete'>" . $LANG['buttons'][6] . "</option>"; echo "<option value='assign_vlan'>" . $LANG['networking'][55] . "</option>"; echo "<option value='unassign_vlan'>" . $LANG['networking'][58] . "</option>"; // Interest of this massive action ? // echo "<option value='move'>".$LANG['buttons'][20]."</option>"; echo "</select>"; $params = array('action' => '__VALUE__', 'itemtype' => $itemtype); ajaxUpdateItemOnSelectEvent("massiveaction", "show_massiveaction", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveActionPorts.php", $params); echo "<span id='show_massiveaction'> </span>\n"; } else { $item = new $itemtype(); $infocom = new Infocom(); $isadmin = $item->canUpdate(); echo "<select name='massiveaction' id='massiveaction'>"; echo "<option value='-1' selected>" . DROPDOWN_EMPTY_VALUE . "</option>"; if (!in_array($itemtype, $CFG_GLPI["massiveaction_noupdate_types"]) && ($isadmin && $itemtype != 'Ticket' || in_array($itemtype, $CFG_GLPI["infocom_types"]) && $infocom->canUpdate() || $itemtype == 'Ticket' && haveRight('update_ticket', 1))) { echo "<option value='update'>" . $LANG['buttons'][14] . "</option>"; } if (in_array($itemtype, $CFG_GLPI["infocom_types"]) && $infocom->canCreate()) { echo "<option value='activate_infocoms'>" . $LANG['financial'][68] . "</option>"; } if ($is_deleted && !in_array($itemtype, $CFG_GLPI["massiveaction_nodelete_types"])) { if ($isadmin) { echo "<option value='purge'>" . $LANG['buttons'][22] . "</option>"; echo "<option value='restore'>" . $LANG['buttons'][21] . "</option>"; } } else { // No delete for entities and tracking of not have right if (!in_array($itemtype, $CFG_GLPI["massiveaction_nodelete_types"]) && ($isadmin && $itemtype != 'Ticket' || $itemtype == 'Ticket' && haveRight('delete_ticket', 1))) { if ($item->maybeDeleted()) { echo "<option value='delete'>" . $LANG['buttons'][6] . "</option>"; } else { echo "<option value='purge'>" . $LANG['buttons'][22] . "</option>"; } } if ($isadmin && in_array($itemtype, array('Phone', 'Printer', 'Peripheral', 'Monitor'))) { echo "<option value='connect'>" . $LANG['buttons'][9] . "</option>"; echo "<option value='disconnect'>" . $LANG['buttons'][10] . "</option>"; } if (in_array($itemtype, $CFG_GLPI["document_types"])) { $doc = new Document(); if ($doc->canView()) { echo "<option value='add_document'>" . $LANG['document'][16] . "</option>"; } } if (in_array($itemtype, $CFG_GLPI["contract_types"])) { $contract = new Contract(); if ($contract->canUpdate()) { echo "<option value='add_contract'>" . $LANG['financial'][36] . "</option>"; } } if (haveRight('transfer', 'r') && isMultiEntitiesMode() && in_array($itemtype, array('CartridgeItem', 'Computer', 'ConsumableItem', 'Contact', 'Contract', 'Supplier', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer', 'Software', 'SoftwareLicense', 'Ticket', 'Document', 'Group', 'Link')) && $isadmin) { echo "<option value='add_transfer_list'>" . $LANG['buttons'][48] . "</option>"; } switch ($itemtype) { case 'Software': if ($isadmin && countElementsInTable("glpi_rules", "sub_type='RuleSoftwareCategory'") > 0) { echo "<option value='compute_software_category'>" . $LANG['rulesengine'][38] . " " . $LANG['rulesengine'][40] . "</option>"; } if (haveRight("rule_dictionnary_software", "w") && countElementsInTable("glpi_rules", "sub_type='RuleDictionnarySoftware'") > 0) { echo "<option value='replay_dictionnary'>" . $LANG['rulesengine'][76] . "</option>"; } break; case 'Computer': if ($isadmin) { echo "<option value='connect_to_computer'>" . $LANG['buttons'][9] . "</option>"; echo "<option value='install'>" . $LANG['buttons'][4] . "</option>"; if ($CFG_GLPI['use_ocs_mode']) { if (haveRight("ocsng", "w") || haveRight("sync_ocsng", "w")) { echo "<option value='force_ocsng_update'>" . $LANG['ocsng'][24] . "</option>"; } echo "<option value='unlock_ocsng_field'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][16] . "</option>"; echo "<option value='unlock_ocsng_monitor'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][30] . "</option>"; echo "<option value='unlock_ocsng_peripheral'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][32] . "</option>"; echo "<option value='unlock_ocsng_printer'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][34] . "</option>"; echo "<option value='unlock_ocsng_software'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][52] . "</option>"; echo "<option value='unlock_ocsng_ip'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][50] . "</option>"; echo "<option value='unlock_ocsng_disk'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][55] . "</option>"; } } break; case 'Supplier': if ($isadmin) { echo "<option value='add_contact'>" . $LANG['financial'][24] . "</option>"; } break; case 'Calendar': echo "<option value='duplicate'>" . $LANG['buttons'][54] . "</option>"; break; case 'Contact': if ($isadmin) { echo "<option value='add_enterprise'>" . $LANG['financial'][25] . "</option>"; } break; case 'User': if ($isadmin) { echo "<option value='add_group'>" . $LANG['setup'][604] . "</option>"; echo "<option value='add_userprofile'>" . $LANG['setup'][607] . "</option>"; } if (haveRight("user_authtype", "w")) { echo "<option value='change_authtype'>" . $LANG['login'][30] . "</option>"; echo "<option value='force_user_ldap_update'>" . $LANG['ocsng'][24] . "</option>"; } break; case 'Ticket': $tmp = new TicketFollowup(); if ($tmp->canCreate()) { echo "<option value='add_followup'>" . $LANG['job'][29] . "</option>"; } $tmp = new TicketTask(); if ($tmp->canCreate()) { echo "<option value='add_task'>" . $LANG['job'][30] . "</option>"; } $tmp = new TicketValidation(); if ($tmp->canCreate()) { echo "<option value='submit_validation'>" . $LANG['validation'][26] . "</option>"; } if (haveRight("update_ticket", "1")) { echo "<option value='add_actor'>" . $LANG['job'][27] . "</option>"; echo "<option value='link_ticket'>" . $LANG['job'][56] . "</option>"; } break; case 'CronTask': echo "<option value='reset'>" . $LANG['buttons'][16] . " (" . $LANG['crontask'][40] . ")"; echo "</option>"; break; case 'NotImportedEmail': echo "<option value='delete_email'>" . $LANG['mailing'][133] . "</option>"; echo "<option value='import_email'>" . $LANG['buttons'][37] . "</option>"; break; } if ($item instanceof CommonTreeDropdown) { if ($isadmin) { echo "<option value='move_under'>" . $LANG['buttons'][20] . "</option>"; } } if ($itemtype != 'Entity' && $itemtype != 'Calendar' && $item instanceof CommonDropdown && $item->maybeRecursive()) { if ($isadmin) { echo "<option value='merge'>" . $LANG['buttons'][48] . " - " . $LANG['software'][48]; echo "</option>"; } } // Plugin Specific actions if (isset($PLUGIN_HOOKS['use_massive_action'])) { foreach ($PLUGIN_HOOKS['use_massive_action'] as $plugin => $val) { $actions = doOneHook($plugin, 'MassiveActions', $itemtype); if (count($actions)) { foreach ($actions as $key => $val) { echo "<option value = '{$key}'>{$val}</option>"; } } } } } echo "</select>"; $params = array('action' => '__VALUE__', 'is_deleted' => $is_deleted, 'itemtype' => $itemtype); if (count($extraparams)) { foreach ($extraparams as $key => $val) { $params['extra_' . $key] = $val; } } ajaxUpdateItemOnSelectEvent("massiveaction", "show_massiveaction", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveAction.php", $params); echo "<span id='show_massiveaction'> </span>\n"; } }
/** * Prints display pre import * * @param $type the type of device * @param $configID the ID of the supplier config * @param $start for pager display * @param $complete to see all device (already imported and not) * @return nothing (print out a table) * */ static function seePreImport($params) { global $DB, $CFG_GLPI; // 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['export_all'] = 0; $p['link2'] = ''; $p['contains2'] = ''; $p['field2'] = ''; $p['itemtype2'] = ''; $p['searchtype2'] = ''; $p['itemtype'] = ''; $p['manufacturers_id'] = ''; $p['imported'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } $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("searchtype2", $p['searchtype2']) . self::getArrayUrlLink("itemtype2", $p['itemtype2']) . self::getArrayUrlLink("link2", $p['link2']); $modeltable = ""; $target = $CFG_GLPI["root_doc"] . "/plugins/manufacturersimports/front/import.php"; if ($p['itemtype'] && $p['manufacturers_id']) { $config = new PluginManufacturersimportsConfig(); $config->getFromDB($p['manufacturers_id']); $suppliername = $config->fields["name"]; $supplierclass = "PluginManufacturersimports" . $suppliername; $supplier = new $supplierclass(); $infocom = new Infocom(); $canedit = Session::haveRight(static::$rightname, UPDATE) && $infocom->canUpdate(); if (!$p['start']) { $p['start'] = 0; } $modeltable = getTableForItemType($p['itemtype'] . "Model"); $modelfield = getForeignKeyFieldForTable(getTableForItemType($p['itemtype'] . "Model")); $item = new $p['itemtype'](); $itemtable = getTableForItemType($p['itemtype']); $query = "SELECT `" . $itemtable . "`.`id`,\n `" . $itemtable . "`.`name`, \n `" . $itemtable . "`.`serial`,\n `" . $itemtable . "`.`entities_id`,\n `glpi_plugin_manufacturersimports_logs`.`import_status`,\n `glpi_plugin_manufacturersimports_logs`.`items_id`,\n `glpi_plugin_manufacturersimports_logs`.`itemtype`, \n `glpi_plugin_manufacturersimports_logs`.`documents_id`,\n `glpi_plugin_manufacturersimports_logs`.`date_import`, \n '" . $p['itemtype'] . "' AS type,\n `{$modeltable}`.`name` AS model_name\n FROM `" . $itemtable . "` "; //model device left join $query .= "LEFT JOIN `{$modeltable}` ON (`{$modeltable}`.`id` = `" . $itemtable . "`.`" . $modelfield . "`) "; $query .= " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemtable . "`.`entities_id`)"; $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_configs` \n ON (`glpi_plugin_manufacturersimports_configs`.`manufacturers_id` = `" . $itemtable . "`.`manufacturers_id`)"; $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_logs` \n ON (`glpi_plugin_manufacturersimports_logs`.`items_id` = `" . $itemtable . "`.`id` \n AND `glpi_plugin_manufacturersimports_logs`.`itemtype` = '" . $p['itemtype'] . "')"; $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_models` \n ON (`glpi_plugin_manufacturersimports_models`.`items_id` = `" . $itemtable . "`.`id` \n AND `glpi_plugin_manufacturersimports_models`.`itemtype` = '" . $p['itemtype'] . "')"; //serial must be not empty $query .= " WHERE `" . $itemtable . "`.`is_deleted` = '0'\n AND `" . $itemtable . "`.`is_template` = '0'\n AND `glpi_plugin_manufacturersimports_configs`.`id` = '" . $p['manufacturers_id'] . "'\n AND `" . $itemtable . "`.`serial` != '' "; //already imported if ($p['imported'] == self::IMPORTED) { $query .= " AND `import_status` != " . self::IMPORTED . ""; //not imported } else { if ($p['imported'] == self::NOT_IMPORTED) { $query .= " AND (`date_import` IS NULL OR `import_status` = " . self::IMPORTED . " "; $query .= ") "; } } $entities = ""; if ($config->isRecursive()) { $entities = getSonsOf('glpi_entities', $config->getEntityID()); } else { $entities = $config->getEntityID(); } $query .= "" . getEntitiesRestrictRequest(" AND", $itemtable, '', '', $item->maybeRecursive()); //// 4 - ORDER $ORDER = " ORDER BY `entities_id`,`" . $itemtable . "`.`name` "; $toview = array("name" => 1); foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = self::addOrderBy($p['itemtype'], $p['sort'], $p['order'], $key); } } $query .= $ORDER; $result = $DB->query($query); $numrows = $DB->numrows($result); if ($p['start'] < $numrows) { // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET["display_type"])) { $output_type = $_GET["display_type"]; } $parameters = "itemtype=" . $p['itemtype'] . "&manufacturers_id=" . $p['manufacturers_id'] . "&imported=" . $p['imported']; $total = 0; if ($output_type == Search::HTML_OUTPUT) { self::printPager($p['start'], $numrows, $target, $parameters, $p['itemtype']); } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = $p['start'] + $_SESSION["glpilist_limit"]; // Export All case if (isset($_GET['export_all'])) { $begin_display = 0; $end_display = $numrows; } if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } //////////////////////HEADER/////////////// if ($output_type == Search::HTML_OUTPUT) { echo "<form method='post' name='massiveaction_form' id='massiveaction_form' action=\"../ajax/massiveaction.php\">"; } //echo Search::displaySearchHeader($output_type,0); //table + div if ($canedit) { $nbcols = 11 + $colsup; } else { $nbcols = 10 + $colsup; } $LIST_LIMIT = $_SESSION['glpilist_limit']; $begin_display = $p['start']; $end_display = $p['start'] + $LIST_LIMIT; foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt["PluginManufacturersimportsPreImport"][$val]['nosort']) || !$searchopt["PluginManufacturersimportsPreImport"][$val]['nosort']) { $linkto = "{$target}?itemtype=" . $p['itemtype'] . "&manufacturers_id=" . $p['manufacturers_id'] . "&imported=" . $p['imported'] . "&sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto; } } echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); echo Search::showNewLine($output_type); $header_num = 1; echo Search::showHeaderItem($output_type, "", $header_num); echo Search::showHeaderItem($output_type, __('Name'), $header_num, $linkto, $p['sort'] == $val, $p['order']); if (Session::isMultiEntitiesMode()) { echo Search::showHeaderItem($output_type, __('Entity'), $header_num); } echo Search::showHeaderItem($output_type, __('Serial number'), $header_num); echo $supplier->showItemTitle($output_type, $header_num); echo Search::showHeaderItem($output_type, __('Financial and administrative information'), $header_num); echo Search::showHeaderItem($output_type, __('Supplier attached', 'manufacturersimports'), $header_num); echo Search::showHeaderItem($output_type, __('New warranty attached', 'manufacturersimports'), $header_num); echo Search::showHeaderItem($output_type, _n('Link', 'Links', 1), $header_num); echo Search::showHeaderItem($output_type, _n('Status', 'Statuses', 1), $header_num); echo $supplier->showDocTitle($output_type, $header_num); // End Line for column headers echo Search::showEndLine($output_type); $i = $p['start']; if (isset($_GET['export_all'])) { $i = 0; } if ($i > 0) { $DB->data_seek($result, $i); } $row_num = 1; while ($i < $numrows && $i < $end_display) { $i++; $item_num = 1; $line = $DB->fetch_array($result); $compSerial = $line['serial']; $compId = $line['id']; $model = $line["model_name"]; if (!$line["itemtype"]) { $line["itemtype"] = $p['itemtype']; } self::showImport($row_num, $item_num, $line, $output_type, $p['manufacturers_id'], $line["import_status"], $p['imported']); //1.show already imported items && import_status not failed if ($p['imported'] == 1) { $total += 1; } } echo "<tr class='tab_bg_1'><td colspan='" . ($canedit ? 11 + $colsup : 10 + $colsup) . "'>"; echo sprintf(__('Total number of devices to import %s', 'manufacturersimports'), $total); echo "</td></tr>"; // Close Table $title = ""; // Create title if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) { $title .= PluginManufacturersimportsPreImport::getTypeName(2) . " " . $suppliername; } echo Search::showFooter($output_type, $title); //massive action if ($canedit && $output_type == Search::HTML_OUTPUT) { if ($_SESSION['glpilist_limit'] < Toolbox::get_max_input_vars()) { Html::openArrowMassives("massiveaction_form", false); self::dropdownMassiveAction($compId, $p['itemtype'], $p['manufacturers_id'], $p['start'], $p['imported']); Html::closeArrowMassives(array()); } else { echo "<table class='tab_cadre' width='80%'><tr class='tab_bg_1'>" . "<td><span class='b'>"; echo __('Selection too large, massive action disabled.') . "</span>"; if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { echo "<br>" . __('To increase the limit: change max_input_vars or suhosin.post.max_vars in php configuration.'); } echo "</td></tr></table>"; } Html::closeForm(); } else { echo "</table>"; echo "</div>"; } echo "<br>"; if ($output_type == Search::HTML_OUTPUT) { self::printPager($p['start'], $numrows, $target, $parameters, $p['itemtype']); } } else { echo "<div align='center'><b>" . __('No device finded', 'manufacturersimports') . "</b></div>"; } } }