static function showAllItems($myname, $value_type = 0, $value = 0, $entity_restrict = -1, $types, $locations_id = -1, $action = 'showItem') { global $DB, $CFG_GLPI; $rand = mt_rand(); $plugin = new Plugin(); echo "<table border='0'><tr><td>\n"; if ($myname == 'type') { $newtypes = array_flip($types); unset($newtypes['Location']); unset($newtypes['Netpoint']); if ($plugin->isActivated("resources")) { unset($newtypes['PluginResourcesResource']); } $types = array_flip($newtypes); } $rand = Dropdown::showItemTypes($myname, $types, array('emptylabel' => Dropdown::EMPTY_VALUE, 'width' => 150)); $params = array('type' => '__VALUE__', 'value' => $value, 'myname' => $myname, 'action' => $action, 'entity_restrict' => $entity_restrict, 'locations_id' => $locations_id); Ajax::updateItemOnSelectEvent("dropdown_{$myname}{$rand}", "show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/positions/ajax/dropdownAllItems.php", $params); echo "</td><td>\n"; echo "<span id='show_{$myname}{$rand}'> </span>\n"; echo "</td></tr></table>\n"; if ($value > 0) { echo "<script type='text/javascript' >\n"; echo "document.getElementById('item_type{$rand}').value='" . $value_type . "';"; echo "</script>\n"; $params["typetable"] = $value_type; Ajax::updateItem("show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/positions/ajax/dropdownAllItems.php", $params); } return $rand; }
public function tabDropdown() { global $CFG_GLPI; echo "<br><span id='tabstab'> </span>\n"; if ($this->fields['id'] > 0) { $params = array('itemtype' => $this->fields['itemtype'], 'myname' => 'tabstab', 'value' => $this->fields['tab'], 'id' => $this->fields['id']); Ajax::updateItem('tabstab', $CFG_GLPI["root_doc"] . "/plugins/custom/ajax/dropdowntab.php", $params); } }
static function showAllItems($myname, $value_type = 0, $value = 0, $entity_restrict = -1, $types, $locations_id = -1) { global $DB, $CFG_GLPI; $rand = mt_rand(); $plugin = new Plugin(); echo "<table border='0'><tr><td>\n"; echo "<select name='type' id='item_type{$rand}'>\n"; echo "<option value='0;0'>" . Dropdown::EMPTY_VALUE . "</option>\n"; if ($myname == 'type') { $newtypes = array_flip($types); unset($newtypes['Location']); unset($newtypes['Netpoint']); if ($plugin->isActivated("resources")) { unset($newtypes['PluginResourcesResource']); } $types = array_flip($newtypes); } foreach ($types as $type => $label) { $item = new $label(); if ($myname == 'type') { $table = getTableForItemType($label . "Type"); } else { $table = getTableForItemType($label); } echo "<option value='" . $label . ";" . $table . "'>" . $item->getTypeName() . "</option>\n"; } echo "</select>"; $params = array('typetable' => '__VALUE__', 'value' => $value, 'myname' => $myname, 'entity_restrict' => $entity_restrict, 'locations_id' => $locations_id); Ajax::updateItemOnSelectEvent("item_type{$rand}", "show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/positions/ajax/dropdownAllItems.php", $params); echo "</td><td>\n"; echo "<span id='show_{$myname}{$rand}'> </span>\n"; echo "</td></tr></table>\n"; if ($value > 0) { echo "<script type='text/javascript' >\n"; echo "document.getElementById('item_type{$rand}').value='" . $value_type . "';"; echo "</script>\n"; $params["typetable"] = $value_type; Ajax::updateItem("show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/positions/ajax/dropdownAllItems.php", $params); } return $rand; }
/** * Show generic date search * * @param $element name of the html element * @param $value default value (default '') * @param $options array of possible options: * - with_time display with time selection ? (default false) * - with_future display with future date selection ? (default false) * - with_days display specific days selection TODAY, BEGINMONTH, LASTMONDAY... ? (default true) * * @return rand value of dropdown **/ static function showGenericDateTimeSearch($element, $value = '', $options = array()) { global $CFG_GLPI; $p['with_time'] = false; $p['with_future'] = false; $p['with_days'] = true; $p['with_specific_date'] = true; $p['display'] = true; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } $rand = mt_rand(); $output = ''; // Validate value if ($value != 'NOW' && $value != 'TODAY' && !preg_match("/\\d{4}-\\d{2}-\\d{2}.*/", $value) && !strstr($value, 'HOUR') && !strstr($value, 'DAY') && !strstr($value, 'WEEK') && !strstr($value, 'MONTH') && !strstr($value, 'YEAR')) { $value = ""; } if (empty($value)) { $value = 'NOW'; } $specific_value = date("Y-m-d H:i:s"); if (preg_match("/\\d{4}-\\d{2}-\\d{2}.*/", $value)) { $specific_value = $value; $value = 0; } $output .= "<table><tr><td>"; $output .= "<select id='genericdate{$element}{$rand}' name='_select_{$element}'>"; $dates = Html::getGenericDateTimeSearchItems($options); foreach ($dates as $key => $val) { $output .= "<option value='{$key}' " . ($value === $key ? 'selected' : '') . ">{$val}</option>"; } $output .= "</select>"; $output .= "</td><td>"; $output .= "<div id='displaygenericdate{$element}{$rand}'></div>"; $params = array('value' => '__VALUE__', 'name' => $element, 'withtime' => $p['with_time'], 'specificvalue' => $specific_value); $output .= Ajax::updateItemOnSelectEvent("genericdate{$element}{$rand}", "displaygenericdate{$element}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/genericdate.php", $params, false); $params['value'] = $value; $output .= Ajax::updateItem("displaygenericdate{$element}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/genericdate.php", $params, '', false); $output .= "</td></tr></table>"; if ($p['display']) { echo $output; return $rand; } return $output; }
/** * @param $model PluginDatainjectionModel object * @param $entities_id **/ static function processInjection(PluginDatainjectionModel $model, $entities_id) { global $CFG_GLPI; // To prevent problem of execution time during injection ini_set("max_execution_time", "0"); // Disable recording each SQL request in $_SESSION $CFG_GLPI["debug_sql"] = 0; $nblines = PluginDatainjectionSession::getParam('nblines'); $clientinjection = new PluginDatainjectionClientInjection(); //New injection engine $engine = new PluginDatainjectionEngine($model, PluginDatainjectionSession::getParam('infos'), $entities_id); $backend = $model->getBackend(); $model->loadSpecificModel(); //Open CSV file $backend->openFile(); $index = 0; //Read CSV file $line = $backend->getNextLine(); //If header is present, then get the second line if ($model->getSpecificModel()->isHeaderPresent()) { $line = $backend->getNextLine(); } //While CSV file is not EOF $prev = ''; $deb = time(); while ($line != null) { //Inject line $injectionline = $index + ($model->getSpecificModel()->isHeaderPresent() ? 2 : 1); $clientinjection->results[] = $engine->injectLine($line[0], $injectionline); $pos = number_format($index * 100 / $nblines, 1); if ($pos != $prev) { $prev = $pos; $fin = time() - $deb; //TODO yllen Html::changeProgressBarPosition($index, $nblines, sprintf(__('%1$s (%2$s)'), sprintf(__('Injection of the file... %d%%', 'datainjection'), $pos), Html::timestampToString(time() - $deb, true))); } $line = $backend->getNextLine(); $index++; } //EOF : change progressbar to 100% ! Html::changeProgressBarPosition(100, 100, sprintf(__('%1$s (%2$s)'), __('Injection finished', 'datainjection'), Html::timestampToString(time() - $deb, true))); // Restore $CFG_GLPI["debug_sql"] = 1; //Close CSV file $backend->closeFile(); //Delete CSV file $backend->deleteFile(); //Change step $_SESSION['datainjection']['step'] = self::STEP_RESULT; //Display results form PluginDatainjectionSession::setParam('results', json_encode($clientinjection->results)); PluginDatainjectionSession::setParam('error_lines', json_encode($engine->getLinesInError())); $p['models_id'] = $model->fields['id']; $p['nblines'] = $nblines; unset($_SESSION['datainjection']['go']); $_SESSION["MESSAGE_AFTER_REDIRECT"] = ""; $url = $CFG_GLPI["root_doc"] . "/plugins/datainjection/ajax/results.php"; Ajax::updateItem("span_injection", $url, $p); }
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI; along with Order. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- @package order @author the order plugin team @copyright Copyright (c) 2010-2011 Order plugin team @license GPLv2+ http://www.gnu.org/licenses/gpl.txt @link https://forge.indepnet.net/projects/order @link http://www.glpi-project.org/ @since 2009 ---------------------------------------------------------------------- */ include "../../../inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); if (!defined('GLPI_ROOT')) { die("Can not acces directly to this file"); } Session::checkCentralAccess(); $rand = $_POST["rand"]; $paramsaction = array('plugin_order_references_id' => '__VALUE__', 'entity_restrict' => $_POST["entity_restrict"], 'suppliers_id' => $_POST["suppliers_id"], 'itemtype' => $_POST['itemtype']); $fields = array("quantity", "priceht", "pricediscounted", "taxe", "validate"); foreach ($fields as $field) { $paramsaction['update'] = $field; Ajax::updateItem("show_{$field}", $CFG_GLPI["root_doc"] . "/plugins/order/ajax/referencedetail.php", $paramsaction, "dropdown_reference{$rand}"); Ajax::updateItemOnSelectEvent("dropdown_reference{$rand}", "show_{$field}", $CFG_GLPI["root_doc"] . "/plugins/order/ajax/referencedetail.php", $paramsaction); }
Session::checkLoginUser(); if (isset($_POST["sub_type"]) && ($rule = getItemForItemtype($_POST["sub_type"]))) { $criterias = $rule->getAllCriteria(); if (count($criterias)) { // First include -> first of the predefined array if (!isset($_POST["criteria"])) { $_POST["criteria"] = key($criterias); } if (isset($criterias[$_POST["criteria"]]['allow_condition'])) { $allow_condition = $criterias[$_POST["criteria"]]['allow_condition']; } else { $allow_condition = array(); } $condparam = array('criterion' => $_POST["criteria"], 'allow_conditions' => $allow_condition); if (isset($_POST['condition'])) { $condparam['value'] = $_POST['condition']; } echo "<table width='100%'><tr><td width='30%'>"; $randcrit = RuleCriteria::dropdownConditions($_POST["sub_type"], $condparam); echo "</td><td>"; echo "<span id='condition_span{$randcrit}'>\n"; echo "</span>\n"; $paramscriteria = array('condition' => '__VALUE__', 'criteria' => $_POST["criteria"], 'sub_type' => $_POST["sub_type"]); Ajax::updateItemOnSelectEvent("dropdown_condition{$randcrit}", "condition_span{$randcrit}", $CFG_GLPI["root_doc"] . "/ajax/rulecriteriavalue.php", $paramscriteria); if (isset($_POST['pattern'])) { $paramscriteria['value'] = stripslashes($_POST['pattern']); } Ajax::updateItem("condition_span{$randcrit}", $CFG_GLPI["root_doc"] . "/ajax/rulecriteriavalue.php", $paramscriteria, "dropdown_condition{$randcrit}"); echo "</td></tr></table>"; } }
} else { $end = date("Y-m-d H:i:s", strtotime($begin) + HOUR_TIMESTAMP); } echo "<table class='tab_cadre'>"; echo "<tr class='tab_bg_2'><td>" . __('Start date') . "</td><td>"; $rand_begin = Html::showDateTimeField("plan[begin]", array('value' => $begin, 'timestep' => -1, 'maybeempty' => false, 'canedit' => true, 'mindate' => '', 'maxdate' => '', 'mintime' => $CFG_GLPI["planning_begin"], 'maxtime' => $CFG_GLPI["planning_end"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_2'><td>" . __('Period') . " "; if (isset($_POST["rand_user"])) { echo "<span id='user_available" . $_POST["rand_user"] . "'>"; include_once GLPI_ROOT . '/ajax/planningcheck.php'; echo "</span>"; } echo "</td><td>"; $default_delay = floor((strtotime($end) - strtotime($begin)) / 15 / MINUTE_TIMESTAMP) * 15 * MINUTE_TIMESTAMP; $rand = Dropdown::showTimeStamp("plan[_duration]", array('min' => 0, 'max' => 50 * HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date'))); echo "<br><div id='date_end{$rand}'></div>"; $params = array('duration' => '__VALUE__', 'end' => $end, 'name' => "plan[end]", 'global_begin' => $CFG_GLPI["planning_begin"], 'global_end' => $CFG_GLPI["planning_end"]); Ajax::updateItemOnSelectEvent("dropdown_plan[_duration]{$rand}", "date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params); if ($default_delay == 0) { $params['duration'] = 0; Ajax::updateItem("date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params); } echo "</td></tr>\n"; if ((!isset($_POST["id"]) || $_POST["id"] == 0) && isset($_POST['itemtype']) && PlanningRecall::isAvailable()) { echo "<tr class='tab_bg_2'><td>" . _x('Planning', 'Reminder') . "</td><td>"; PlanningRecall::dropdown(array('itemtype' => $_POST['itemtype'], 'items_id' => $_POST['items_id'])); echo "</td></tr>"; } echo "</table>\n"; Html::ajaxFooter();
/** * Print generic search form * *@param $itemtype type to display the form *@param $params parameters array may include field, contains, sort, is_deleted, link, link2, contains2, field2, type2 * *@return nothing (displays) * **/ function showGenericSearch($params) { global $CFG_GLPI; $itemtype = "PluginResourcesDirectory"; $itemtable = $this->table; // Default values of parameters $p['link'] = array(); // $p['field'] = array(); $p['contains'] = array(); $p['searchtype'] = array(); $p['sort'] = ''; $p['is_deleted'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; $p['field2'] = ''; $p['itemtype2'] = ''; $p['searchtype2'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } $options = Search::getCleanedOptions("PluginResourcesDirectory"); $target = $CFG_GLPI["root_doc"] . "/plugins/resources/front/directory.php"; // Instanciate an object to access method $item = NULL; if (class_exists($itemtype)) { $item = new $itemtype(); } $linked = Search::getMetaItemtypeAvailable($itemtype); echo "<form name='searchform{$itemtype}' method='get' action=\"{$target}\">"; echo "<table class='tab_cadre_fixe' >"; echo "<tr class='tab_bg_1'>"; echo "<td>"; echo "<table>"; // Display normal search parameters for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) { echo "<tr><td class='left' width='50%'>"; // First line display add / delete images for normal and meta search items if ($i == 0) { echo "<input type='hidden' disabled id='add_search_count' name='add_search_count' value='1'>"; echo "<a href='#' onClick = \"document.getElementById('add_search_count').disabled=false;document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/plus.png\" alt='+' title='" . __s('Add a search criterion') . "'></a> "; if ($_SESSION["glpisearchcount"][$itemtype] > 1) { echo "<input type='hidden' disabled id='delete_search_count' name='delete_search_count' value='1'>"; echo "<a href='#' onClick = \"document.getElementById('delete_search_count').disabled=false;document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/moins.png\" alt='-' title='" . __s('Delete a search criterion') . "'></a> "; } if (is_array($linked) && count($linked) > 0) { echo "<input type='hidden' disabled id='add_search_count2' name='add_search_count2' value='1'>"; echo "<a href='#' onClick = \"document.getElementById('add_search_count2').disabled=false;document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_plus.png\" alt='+' title='" . __s('Add a global search criterion') . "'></a> "; if ($_SESSION["glpisearchcount2"][$itemtype] > 0) { echo "<input type='hidden' disabled id='delete_search_count2' name='delete_search_count2' value='1'>"; echo "<a href='#' onClick = \"document.getElementById('delete_search_count2').disabled=false;document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_moins.png\" alt='-' title='" . __s('Delete a global search criterion') . "'></a> "; } } $itemtable = getTableForItemType($itemtype); } // Display link item if ($i > 0) { echo "<select name='link[{$i}]'>"; echo "<option value='AND' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND") { echo "selected"; } echo ">AND</option>\n"; echo "<option value='OR' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR") { echo "selected"; } echo ">OR</option>\n"; echo "<option value='AND NOT' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND NOT") { echo "selected"; } echo ">AND NOT</option>\n"; echo "<option value='OR NOT' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR NOT") { echo "selected"; } echo ">OR NOT</option>"; echo "</select> "; } // display select box to define serach item echo "<select id='Search{$itemtype}{$i}' name=\"field[{$i}]\" size='1'>"; echo "<option value='view' "; if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "view") { echo "selected"; } echo ">" . __('Items seen') . "</option>\n"; reset($options); $first_group = true; $selected = 'view'; foreach ($options as $key => $val) { // print groups if (!is_array($val)) { if (!$first_group) { echo "</optgroup>\n"; } else { $first_group = false; } echo "<optgroup label='{$val}'>"; } else { if (!isset($val['nosearch']) || $val['nosearch'] == false) { echo "<option title=\"" . Html::cleanInputText($val["name"]) . "\" value='{$key}'"; if (is_array($p['field']) && isset($p['field'][$i]) && $key == $p['field'][$i]) { echo "selected"; $selected = $key; } echo ">" . Toolbox::substr($val["name"], 0, 28) . "</option>\n"; } } } if (!$first_group) { echo "</optgroup>\n"; } echo "<option value='all' "; if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "all") { echo "selected"; } echo ">" . __('All') . "</option>"; echo "</select> \n"; echo "</td><td class='left'>"; echo "<div id='SearchSpan{$itemtype}{$i}'>\n"; $_POST['itemtype'] = $itemtype; $_POST['num'] = $i; $_POST['field'] = $selected; $_POST['searchtype'] = is_array($p['searchtype']) && isset($p['searchtype'][$i]) ? $p['searchtype'][$i] : ""; $_POST['value'] = is_array($p['contains']) && isset($p['contains'][$i]) ? stripslashes($p['contains'][$i]) : ""; include GLPI_ROOT . "/ajax/searchoption.php"; echo "</div>\n"; $params = array('field' => '__VALUE__', 'itemtype' => $itemtype, 'num' => $i, 'value' => $_POST["value"], 'searchtype' => $_POST["searchtype"]); Ajax::updateItemOnSelectEvent("Search{$itemtype}{$i}", "SearchSpan{$itemtype}{$i}", $CFG_GLPI["root_doc"] . "/ajax/searchoption.php", $params, false); echo "</td></tr>\n"; } $metanames = array(); if (is_array($linked) && count($linked) > 0) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { echo "<tr><td class='left'>"; $rand = mt_rand(); // Display link item (not for the first item) echo "<select name='link2[{$i}]'>"; echo "<option value='AND' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "AND") { echo "selected"; } echo ">AND</option>\n"; echo "<option value='OR' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR") { echo "selected"; } echo ">OR</option>\n"; echo "<option value='AND NOT' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "AND NOT") { echo "selected"; } echo ">AND NOT</option>\n"; echo "<option value='OR NOT' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR NOT") { echo "selected"; } echo ">OR NOT</option>\n"; echo "</select> "; // Display select of the linked item type available echo "<select name='itemtype2[{$i}]' id='itemtype2_" . $itemtype . "_" . $i . "_{$rand}'>"; echo "<option value=''>" . Dropdown::EMPTY_VALUE . "</option>"; foreach ($linked as $key) { if (!isset($metanames[$key])) { $linkitem = new $key(); $metanames[$key] = $linkitem->getTypeName(); } echo "<option value='{$key}'>" . Toolbox::substr($metanames[$key], 0, 20) . "</option>\n"; } echo "</select> "; echo "</td><td>"; // Ajax script for display search met& item echo "<span id='show_" . $itemtype . "_" . $i . "_{$rand}'> </span>\n"; $params = array('itemtype' => '__VALUE__', 'num' => $i, 'field' => is_array($p['field2']) && isset($p['field2'][$i]) ? $p['field2'][$i] : "", 'value' => is_array($p['contains2']) && isset($p['contains2'][$i]) ? $p['contains2'][$i] : "", 'searchtype2' => is_array($p['searchtype2']) && isset($p['searchtype2'][$i]) ? $p['searchtype2'][$i] : ""); Ajax::updateItemOnSelectEvent("itemtype2_" . $itemtype . "_" . $i . "_{$rand}", "show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params, false); if (is_array($p['itemtype2']) && isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i])) { $params['itemtype'] = $p['itemtype2'][$i]; Ajax::updateItem("show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params, false); echo "<script type='text/javascript' >"; echo "window.document.getElementById('itemtype2_" . $itemtype . "_" . $i . "_{$rand}').value='" . $p['itemtype2'][$i] . "';"; echo "</script>\n"; } echo "</td></tr></table>"; echo "</td></tr>\n"; } } echo "</table>\n"; echo "</td>\n"; echo "<td width='150px'>"; echo "<table width='100%'>"; // Display deleted selection echo "<tr>"; // Display submit button echo "<td width='80' class='center'>"; echo "<input type='submit' value=\"" . _sx('button', 'Search') . "\" class='submit' >"; echo "</td><td>"; Bookmark::showSaveButton(Bookmark::SEARCH, $itemtype); echo "<a href='{$target}?reset=reset' >"; echo " <img title=\"" . __s('Blank') . "\" alt=\"" . __s('Blank') . "\" src='" . $CFG_GLPI["root_doc"] . "/templates/infotel/pics/reset.png' class='calendrier'></a>"; echo "</td></tr></table>\n"; echo "</td></tr>"; echo "</table>\n"; // For dropdown echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; // Reset to start when submit new search echo "<input type='hidden' name='start' value='0'>"; Html::closeForm(); }
case 'group': $name = !empty($_POST['name']) ? $_POST['name'] . '[groups_id]' : 'groups_id'; $value = isset($_POST['users_id_validate']['groups_id']) ? $_POST['users_id_validate']['groups_id'] : $_POST['groups_id']; $rand = Group::dropdown(array('name' => $name, 'value' => $value, 'entity' => $_POST["entity"])); $param = array('validatortype' => 'list_users'); $param['name'] = !empty($_POST['name']) ? $_POST['name'] : ''; $param['users_id_validate'] = isset($_POST['users_id_validate']) ? $_POST['users_id_validate'] : ''; $param['right'] = $_POST['right']; $param['entity'] = $_POST["entity"]; $param['groups_id'] = '__VALUE__'; Ajax::updateItemOnSelectEvent("dropdown_{$name}{$rand}", "show_list_users", $CFG_GLPI["root_doc"] . "/ajax/dropdownValidator.php", $param); if ($value) { $param['validatortype'] = 'list_users'; $param['groups_id'] = $value; unset($param['users_id_validate']['groups_id']); Ajax::updateItem('show_list_users', $CFG_GLPI["root_doc"] . "/ajax/dropdownValidator.php", $param); } echo "<br><span id='show_list_users'> </span>\n"; break; case 'list_users': if (isset($_POST['users_id_validate']['groups_id'])) { $_POST['users_id_validate'] = array(); } $opt = array('groups_id' => $_POST["groups_id"], 'right' => $_POST['right'], 'entity' => $_POST["entity"]); $data_users = TicketValidation::getGroupUserHaveRights($opt); $users = array(); $param['values'] = array(); $values = array(); if (isset($_POST['users_id_validate']) && is_array($_POST['users_id_validate'])) { $values = $_POST['users_id_validate']; }
/** * Make a select box for all items * * @param $myname select name * @param $value_type default value for the device type (default 0) * @param $value default value (default 0) * @param $entity_restrict Restrict to a defined entity (default -1) * @param $types Types used (default '') * @param $onlyglobal Restrict to global items (false by default) * @param $checkright Restrict to items with read rights (false by default) * @param $itemtypename name used for itemtype select * * @return nothing (print out an HTML select box) **/ static function showAllItems($myname, $value_type = 0, $value = 0, $entity_restrict = -1, $types = '', $onlyglobal = false, $checkright = false, $itemtypename = 'itemtype') { global $CFG_GLPI; $options = array(); $options['checkright'] = $checkright; $options['name'] = $itemtypename; $rand = self::showItemType($types, $options); if ($rand) { $params = array('idtable' => '__VALUE__', 'value' => $value, 'myname' => $myname, 'entity_restrict' => $entity_restrict); if ($onlyglobal) { $params['condition'] = "`is_global` = '1'"; } Ajax::updateItemOnSelectEvent("itemtype{$rand}", "show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/dropdownAllItems.php", $params); echo "<br><span id='show_{$myname}{$rand}'> </span>\n"; if ($value > 0) { echo "<script type='text/javascript' >\n"; echo "window.document.getElementById('itemtype{$rand}').value='" . $value_type . "';"; echo "</script>\n"; $params["idtable"] = $value_type; Ajax::updateItem("show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/dropdownAllItems.php", $params); } } return $rand; }
function showAllItems($myname, $value_type = 0, $value = 0, $entity_restrict = -1) { global $DB, $CFG_GLPI; $types = array('Computer', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer'); $rand = mt_rand(); echo "<table border='0'><tr><td>\n"; echo "<select name='type' id='item_type{$rand}'>\n"; echo "<option value='0;0'>" . Dropdown::EMPTY_VALUE . "</option>\n"; foreach ($types as $type => $label) { $item = new $label(); echo "<option value='" . $label . ";" . getTableForItemType($label . "Type") . "'>" . $item->getTypeName() . "</option>\n"; } echo "</select>"; $params = array('typetable' => '__VALUE__', 'value' => $value, 'myname' => $myname, 'entity_restrict' => $entity_restrict); Ajax::updateItemOnSelectEvent("item_type{$rand}", "show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/archires/ajax/dropdownAllItems.php", $params); echo "</td><td>\n"; echo "<span id='show_{$myname}{$rand}'> </span>\n"; echo "</td></tr></table>\n"; if ($value > 0) { echo "<script type='text/javascript' >\n"; echo "document.getElementById('item_type{$rand}').value='" . $value_type . "';"; echo "</script>\n"; $params["typetable"] = $value_type; Ajax::updateItem("show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/archires/ajax/dropdownAllItems.php", $params); } return $rand; }
Html::header_nocache(); // Make a select box if (isset($_POST["typetable"])) { $test = explode(";", $_POST['typetable']); $itemtype = $test[0]; $table = $test[1]; if (!empty($table)) { // Link to user for search only > normal users $rand = mt_rand(); $use_ajax = false; if ($CFG_GLPI["use_ajax"] && countElementsInTable($table) > $CFG_GLPI["ajax_limit_count"]) { $use_ajax = true; } $params = array('searchText' => '__VALUE__', 'itemtype' => $itemtype, 'table' => $table, 'rand' => $rand, 'myname' => $_POST["myname"], 'locations_id' => $_POST["locations_id"]); if (isset($_POST['value'])) { $params['value'] = $_POST['value']; } if (isset($_POST['entity_restrict'])) { $params['entity_restrict'] = $_POST['entity_restrict']; } $default = "<select name='" . $_POST["myname"] . "'><option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>"; Ajax::dropdown($use_ajax, "/plugins/positions/ajax/dropdownValue.php", $params, $default, $rand); if (isset($_POST['value']) && $_POST['value'] > 0) { $params['searchText'] = $CFG_GLPI["ajax_wildcard"]; echo "<script type='text/javascript' >\n"; echo "document.getElementById('search_{$rand}').value='" . $CFG_GLPI["ajax_wildcard"] . "';"; echo "</script>\n"; Ajax::updateItem("results_{$rand}", $CFG_GLPI["root_doc"] . "/plugins/positions/ajax/dropdownValue.php", $params); } } }
/** * @param $options array **/ static function dropdownFields($options = array()) { global $CFG_GLPI; $used = array(); $p['itemtype'] = self::NO_VALUE; $p['primary_type'] = ''; $p['mapping_or_info'] = array(); $p['called_by'] = ''; $p['need_decode'] = true; $p['fields_update'] = true; foreach ($options as $key => $value) { $p[$key] = $value; } if ($p['need_decode']) { $mapping_or_info = json_decode(Toolbox::stripslashes_deep($options['mapping_or_info']), true); } else { $mapping_or_info = $options['mapping_or_info']; } $fields = array(); $fields[self::NO_VALUE] = __('-------Choose a field-------', 'datainjection'); //By default field has no default value $mapping_value = self::NO_VALUE; if ($p['itemtype'] != self::NO_VALUE) { //If a value is still present for this mapping if ($mapping_or_info['value'] != self::NO_VALUE) { $mapping_value = $mapping_or_info['value']; } $injectionClass = PluginDatainjectionCommonInjectionLib::getInjectionClassInstance($p['itemtype']); foreach ($injectionClass->getOptions($p['primary_type']) as $option) { //If it's a real option (not a group label) and if field is not blacklisted //and if a linkfield is defined (meaning that the field can be updated) if (is_array($option) && isset($option['injectable']) && $option['injectable'] == PluginDatainjectionCommonInjectionLib::FIELD_INJECTABLE) { $fields[$option['linkfield']] = $option['name']; if ($mapping_value == self::NO_VALUE && $p['called_by'] == 'PluginDatainjectionMapping' && self::isEqual($option, $mapping_or_info)) { $mapping_value = $option['linkfield']; } } } $used = self::getUsedMappingsOrInfos($p); } asort($fields); $rand = Dropdown::showFromArray("data[" . $mapping_or_info['id'] . "][value]", $fields, array('value' => $mapping_value, 'used' => $used)); $url = $CFG_GLPI["root_doc"] . "/plugins/datainjection/ajax/dropdownMandatory.php"; Ajax::updateItem("span_mandatory_" . $mapping_or_info['id'], $url, $p, "dropdown_data[" . $mapping_or_info['id'] . "][value]{$rand}"); Ajax::updateItemOnSelectEvent("dropdown_data[" . $mapping_or_info['id'] . "][value]{$rand}", "span_mandatory_" . $mapping_or_info['id'], $url, $p); }
/** * Former front/planning.php before 9.1. * Display a classic form to plan an event (with begin fiel and duration) * * @since 9.1 * * @param $params (array): array of parameters whou should contain : * - id (integer): id of item who receive the planification * - itemtype (string): itemtype of item who receive the planification * - begin (string) : start date of event * - end (optionnal) (string) : end date of event. Ifg missing, it will computerd from begin+1hour * - rand_user (integer) : users_id to check planning avaibility */ static function showAddEventClassicForm($params = array()) { global $CFG_GLPI; if (isset($params["id"]) && $params["id"] > 0) { echo "<input type='hidden' name='plan[id]' value='" . $params["id"] . "'>"; } $mintime = $CFG_GLPI["planning_begin"]; if (isset($params["begin"]) && !empty($params["begin"])) { $begin = $params["begin"]; $begintime = date("H:i:s", strtotime($begin)); if ($begintime < $mintime) { $mintime = $begintime; } } else { $ts = $CFG_GLPI['time_step'] * 60; // passage en minutes $time = time() + $ts - 60; $time = floor($time / $ts) * $ts; $begin = date("Y-m-d H:i", $time); } if (isset($params["end"]) && !empty($params["end"])) { $end = $params["end"]; } else { $end = date("Y-m-d H:i:s", strtotime($begin) + HOUR_TIMESTAMP); } echo "<table class='tab_cadre'>"; echo "<tr class='tab_bg_2'><td>" . __('Start date') . "</td><td>"; $rand_begin = Html::showDateTimeField("plan[begin]", array('value' => $begin, 'timestep' => -1, 'maybeempty' => false, 'canedit' => true, 'mindate' => '', 'maxdate' => '', 'mintime' => $mintime, 'maxtime' => $CFG_GLPI["planning_end"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_2'><td>" . __('Period') . " "; if (isset($params["rand_user"])) { echo "<span id='user_available" . $params["rand_user"] . "'>"; include_once GLPI_ROOT . '/ajax/planningcheck.php'; echo "</span>"; } echo "</td><td>"; $default_delay = floor((strtotime($end) - strtotime($begin)) / 15 / MINUTE_TIMESTAMP) * 15 * MINUTE_TIMESTAMP; $rand = Dropdown::showTimeStamp("plan[_duration]", array('min' => 0, 'max' => 50 * HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date'))); echo "<br><div id='date_end{$rand}'></div>"; $event_options = array('duration' => '__VALUE__', 'end' => $end, 'name' => "plan[end]", 'global_begin' => $CFG_GLPI["planning_begin"], 'global_end' => $CFG_GLPI["planning_end"]); Ajax::updateItemOnSelectEvent("dropdown_plan[_duration]{$rand}", "date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $event_options); if ($default_delay == 0) { $params['duration'] = 0; Ajax::updateItem("date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params); } echo "</td></tr>\n"; if ((!isset($params["id"]) || $params["id"] == 0) && isset($params['itemtype']) && PlanningRecall::isAvailable()) { echo "<tr class='tab_bg_2'><td>" . _x('Planning', 'Reminder') . "</td><td>"; PlanningRecall::dropdown(array('itemtype' => $params['itemtype'], 'items_id' => $params['items_id'])); echo "</td></tr>"; } echo "</table>\n"; }
$value = ''; if (isset($metacriteria["link"])) { $value = $metacriteria["link"]; } Dropdown::showFromArray("metacriteria[" . $_POST["num"] . "][link]", Search::getLogicalOperators(), array('value' => $value, 'width' => '40%')); // Display select of the linked item type available foreach ($linked as $key) { if (!isset($metanames[$key])) { if ($linkitem = getItemForItemtype($key)) { $metanames[$key] = $linkitem->getTypeName(); } } } $value = ''; if (isset($metacriteria['itemtype']) && !empty($metacriteria['itemtype'])) { $value = $metacriteria['itemtype']; } $rand = Dropdown::showItemTypes("metacriteria[" . $_POST["num"] . "][itemtype]", $linked, array('width' => '50%', 'value' => $value)); $field_id = Html::cleanId("dropdown_metacriteria[" . $_POST["num"] . "][itemtype]{$rand}"); echo "</td><td>"; // Ajax script for display search met& item echo "<span id='show_" . $_POST["itemtype"] . "_" . $_POST["num"] . "_{$rand}'> </span>\n"; $params = array('itemtype' => '__VALUE__', 'num' => $_POST["num"], 'field' => isset($metacriteria['field']) ? $metacriteria['field'] : "", 'value' => isset($metacriteria['value']) ? stripslashes($metacriteria['value']) : "", 'searchtype' => isset($metacriteria['searchtype']) ? $metacriteria['searchtype'] : ""); Ajax::updateItemOnSelectEvent($field_id, "show_" . $_POST["itemtype"] . "_" . $_POST["num"] . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params); if (isset($metacriteria['itemtype']) && !empty($metacriteria['itemtype'])) { $params['itemtype'] = $metacriteria['itemtype']; Ajax::updateItem("show_" . $_POST["itemtype"] . "_" . $_POST["num"] . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params); } echo "</td></tr></table>"; echo "</td></tr>\n"; }
function showForm($computers_id) { global $CFG_GLPI; $pfLicenseInfo = new self(); $a_licenseInfo = $pfLicenseInfo->find("`computers_id`='" . $computers_id . "'"); if (count($a_licenseInfo)) { echo '<div align="center">'; echo '<table class="tab_cadre_fixe" style="margin: 0; margin-top: 5px;">'; echo '<tr>'; echo '<th colspan="4">' . __('License') . '</th>'; echo '</tr>'; foreach ($a_licenseInfo as $licenseInfo) { $licence_link = $licence_endlink = ""; if (!empty($licenseInfo['softwarelicenses_id'])) { $licence_link = "<a href='" . GLPI_ROOT . "/front/softwarelicense.form.php?id=" . $licenseInfo['softwarelicenses_id'] . "'>"; $licence_endlink = "</a>"; $licence_endlink .= "<form method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/licenseinfo.form.php'>"; $licence_endlink .= "<input type='hidden' name='fusioninventory_licenseinfos_id' " . "value='" . $licenseInfo['id'] . "' />"; $licence_endlink .= "<input type='hidden' name='softwarelicenses_id' value='0' />"; $licence_endlink .= "<input type='submit' class='submit' name='associate' " . "value='" . __('Dissociate') . "'>"; $licence_endlink .= Html::closeForm(FALSE); } echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Name') . " :</td>"; echo "<td>{$licence_link}" . $licenseInfo['name'] . "{$licence_endlink}</td>"; echo "<td>" . __('Serial number', 'fusioninventory') . " :</td>"; echo "<td>" . $licenseInfo['serial'] . "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Full name', 'fusioninventory') . " :</td>"; echo "<td>{$licence_link}" . $licenseInfo['fullname'] . "{$licence_endlink}</td>"; echo '<td>' . __('Option', 'fusioninventory') . ' :</td>'; echo "<td>"; if ($licenseInfo['is_update'] || $licenseInfo['is_trial'] || $licenseInfo['is_oem']) { $options = array(); if ($licenseInfo['is_update']) { array_push($options, 'update'); } if ($licenseInfo['is_trial']) { array_push($options, 'trial'); } if ($licenseInfo['is_oem']) { array_push($options, 'OEM'); } echo implode(', ', $options); } echo "</td>"; echo "</tr>"; if (empty($licenseInfo['softwarelicenses_id'])) { echo '<tr class="tab_bg_1">'; echo "<td>" . __('Union between computer and license', 'fusioninventory') . " :</td>"; echo "<td colspan='3'>"; echo "<form method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/licenseinfo.form.php'>"; echo "<input type='hidden' name='computers_id' value='{$computers_id}'>"; echo "<input type='hidden' name='fusioninventory_licenseinfos_id' value='" . $licenseInfo['id'] . "'>"; echo "<input type='hidden' name='key' value='" . $licenseInfo['serial'] . "'>"; $rand = mt_rand(); $params = array('softwarelicenses_id' => $licenseInfo['softwarelicenses_id'], 'name' => $licenseInfo['name'], 'fullname' => $licenseInfo['fullname'], 'serial' => $licenseInfo['serial']); Ajax::updateItem("softwarelicenses_id_{$rand}", $CFG_GLPI["root_doc"] . "/plugins/fusioninventory/ajax/" . "dropdownsoftwarelicenses.php?key=" . $licenseInfo['serial'], $params, FALSE); echo "<span id='softwarelicenses_id_{$rand}'></span>"; Html::closeForm(); echo "</td>"; echo "</tr>"; } echo "<tr class='tab_bg_3'>"; echo "<td colspan='4'></td>"; echo "</tr>"; } echo '</table>'; echo '</div>'; } }
/** * Display for reservation * * @param $ID ID of the reservation (empty for create new) * @param $options array of possibles options: * - item reservation items ID for creation process * - date date for creation process **/ function showForm($ID, $options = array()) { global $CFG_GLPI; if (!Session::haveRight("reservation", ReservationItem::RESERVEANITEM)) { return false; } $resa = new self(); if (!empty($ID)) { if (!$resa->getFromDB($ID)) { return false; } if (!$resa->can($ID, UPDATE)) { return false; } // Set item if not set if ((!isset($options['item']) || count($options['item']) == 0) && ($itemid = $resa->getField('reservationitems_id'))) { $options['item'][$itemid] = $itemid; } } else { $resa->getEmpty(); $resa->fields["begin"] = $options['begin']; if (!isset($options['end'])) { $resa->fields["end"] = date("Y-m-d H:00:00", strtotime($resa->fields["begin"]) + HOUR_TIMESTAMP); } else { $resa->fields["end"] = $options['end']; } } // No item : problem if (!isset($options['item']) || count($options['item']) == 0) { return false; } echo "<div class='center'><form method='post' name=form action='reservation.form.php'>"; if (!empty($ID)) { echo "<input type='hidden' name='id' value='{$ID}'>"; } echo "<table class='tab_cadre' width='700px'>"; echo "<tr><th colspan='2'>" . __('Reserve an item') . "</th></tr>\n"; // Add Hardware name $r = new ReservationItem(); echo "<tr class='tab_bg_1'><td>" . __('Item') . "</td>"; echo "<td>"; foreach ($options['item'] as $itemID) { $r->getFromDB($itemID); $type = $r->fields["itemtype"]; $name = NOT_AVAILABLE; $item = NULL; if ($item = getItemForItemtype($r->fields["itemtype"])) { $type = $item->getTypeName(); if ($item->getFromDB($r->fields["items_id"])) { $name = $item->getName(); } else { $item = NULL; } } echo "<span class='b'>" . sprintf(__('%1$s - %2$s'), $type, $name) . "</span><br>"; echo "<input type='hidden' name='items[{$itemID}]' value='{$itemID}'>"; } echo "</td></tr>\n"; if (!Session::haveRight("reservation", UPDATE) || is_null($item) || !Session::haveAccessToEntity($item->fields["entities_id"])) { echo "<input type='hidden' name='users_id' value='" . Session::getLoginUserID() . "'>"; } else { echo "<tr class='tab_bg_2'><td>" . __('By') . "</td>"; echo "<td>"; if (empty($ID)) { User::dropdown(array('value' => Session::getLoginUserID(), 'entity' => $item->getEntityID(), 'right' => 'all')); } else { User::dropdown(array('value' => $resa->fields["users_id"], 'entity' => $item->getEntityID(), 'right' => 'all')); } echo "</td></tr>\n"; } echo "<tr class='tab_bg_2'><td>" . __('Start date') . "</td><td>"; $rand_begin = Html::showDateTimeField("resa[begin]", array('value' => $resa->fields["begin"], 'timestep' => -1, 'maybeempty' => false)); echo "</td></tr>\n"; $default_delay = floor((strtotime($resa->fields["end"]) - strtotime($resa->fields["begin"])) / $CFG_GLPI['time_step'] / MINUTE_TIMESTAMP) * $CFG_GLPI['time_step'] * MINUTE_TIMESTAMP; echo "<tr class='tab_bg_2'><td>" . __('Duration') . "</td><td>"; $rand = Dropdown::showTimeStamp("resa[_duration]", array('min' => 0, 'max' => 24 * HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date'))); echo "<br><div id='date_end{$rand}'></div>"; $params = array('duration' => '__VALUE__', 'end' => $resa->fields["end"], 'name' => "resa[end]"); Ajax::updateItemOnSelectEvent("dropdown_resa[_duration]{$rand}", "date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params); if ($default_delay == 0) { $params['duration'] = 0; Ajax::updateItem("date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params); } Alert::displayLastAlert('Reservation', $ID); echo "</td></tr>\n"; if (empty($ID)) { echo "<tr class='tab_bg_2'><td>" . __('Rehearsal') . "</td>"; echo "<td>"; $values = array('' => _x('periodicity', 'None'), 'day' => _x('periodicity', 'Daily'), 'week' => _x('periodicity', 'Weekly'), 'month' => _x('periodicity', 'Monthly')); $rand = Dropdown::showFromArray('periodicity[type]', $values); $field_id = Html::cleanId("dropdown_periodicity[type]{$rand}"); $params = array('type' => '__VALUE__', 'end' => $resa->fields["end"]); Ajax::updateItemOnSelectEvent($field_id, "resaperiodcontent{$rand}", $CFG_GLPI["root_doc"] . "/ajax/resaperiod.php", $params); echo "<br><div id='resaperiodcontent{$rand}'></div>"; echo "</td></tr>\n"; } echo "<tr class='tab_bg_2'><td>" . __('Comments') . "</td>"; echo "<td><textarea name='comment' rows='8' cols='60'>" . $resa->fields["comment"] . "</textarea>"; echo "</td></tr>\n"; if (empty($ID)) { echo "<tr class='tab_bg_2'>"; echo "<td colspan='2' class='top center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>\n"; } else { if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRightsOr(static::$rightname, array(PURGE, UPDATE))) { echo "<tr class='tab_bg_2'>"; if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRight(static::$rightname, PURGE)) { echo "<td class='top center'>"; echo "<input type='submit' name='purge' value=\"" . _sx('button', 'Delete permanently') . "\"\n class='submit'>"; if ($resa->fields["group"] > 0) { echo "<br><input type='checkbox' name='_delete_group'> " . __s('Delete all rehearsals'); } echo "</td>"; } if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRight(static::$rightname, UPDATE)) { echo "<td class='top center'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n class='submit'>"; echo "</td>"; } echo "</tr>\n"; } } echo "</table>"; Html::closeForm(); echo "</div>\n"; }
/** * Dropdown of validator * * @param $options array of options * - name : select name * - id : ID of object > 0 Update, < 0 New * - entity : ID of entity * - right : validation rights * - groups_id : ID of group validator * - users_id_validate : ID of user validator * - applyto * * @return nothing (display) **/ static function dropdownValidator(array $options = array()) { global $CFG_GLPI; $params['name'] = ''; $params['id'] = 0; $params['entity'] = $_SESSION['glpiactive_entity']; $params['right'] = array('validate_request', 'validate_incident'); $params['groups_id'] = 0; $params['users_id_validate'] = array(); $params['applyto'] = 'show_validator_field'; foreach ($options as $key => $val) { $params[$key] = $val; } $types = array('user' => __('User'), 'group' => __('Group')); $type = ''; if (isset($params['users_id_validate']['groups_id'])) { $type = 'group'; } else { if (!empty($params['users_id_validate'])) { $type = 'user'; } } $rand = Dropdown::showFromArray("validatortype", $types, array('value' => $type, 'display_emptychoice' => true)); if ($type) { $params['validatortype'] = $type; Ajax::updateItem($params['applyto'], $CFG_GLPI["root_doc"] . "/ajax/dropdownValidator.php", $params); } $params['validatortype'] = '__VALUE__'; Ajax::updateItemOnSelectEvent("dropdown_validatortype{$rand}", $params['applyto'], $CFG_GLPI["root_doc"] . "/ajax/dropdownValidator.php", $params); if (!isset($options['applyto'])) { echo "<br><span id='" . $params['applyto'] . "'> </span>\n"; } }
/** * Make a select box for link tasklists * * Parameters which could be used in options array : * - name : string / name of the select (default is documents_id) * - entity : integer or array / restrict to a defined entity or array of entities * (default -1 : no restriction) * - used : array / Already used items ID: not to display in dropdown (default empty) * * @param $options array of possible options * * @return nothing (print out an HTML select box) * */ static function dropdownTasklists($options = array()) { global $DB, $CFG_GLPI; $p['name'] = 'plugin_tasklists_tasklists_id'; $p['entity'] = ''; $p['used'] = array(); $p['display'] = true; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } $rand = mt_rand(); $where = " WHERE `glpi_plugin_tasklists_tasklists`.`is_deleted` = '0' "; $where .= getEntitiesRestrictRequest("AND", 'glpi_plugin_tasklists_tasklists', '', $p['entity'], true); if (count($p['used'])) { $where .= " AND `id` NOT IN (0, " . implode(",", $p['used']) . ")"; } $query = "SELECT *\n FROM `glpi_plugin_tasklists_tasktypes`\n WHERE `id` IN (SELECT DISTINCT `plugin_tasklists_tasktypes_id`\n FROM `glpi_plugin_tasklists_tasks`\n {$where})\n ORDER BY `name`"; $result = $DB->query($query); $values = array(0 => Dropdown::EMPTY_VALUE); while ($data = $DB->fetch_assoc($result)) { $values[$data['id']] = $data['name']; } $out = Dropdown::showFromArray('_tasktype', $values, array('width' => '30%', 'rand' => $rand, 'display' => false)); $field_id = Html::cleanId("dropdown__tasktype{$rand}"); $params = array('tasktypes' => '__VALUE__', 'entity' => $p['entity'], 'rand' => $rand, 'myname' => $p['name'], 'used' => $p['used']); $out .= Ajax::updateItemOnSelectEvent($field_id, "show_" . $p['name'] . $rand, $CFG_GLPI["root_doc"] . "/plugins/tasklists/ajax/dropdownTypeTasks.php", $params, false); $out .= "<span id='show_" . $p['name'] . "{$rand}'>"; $out .= "</span>\n"; $params['tasktype'] = 0; $out .= Ajax::updateItem("show_" . $p['name'] . $rand, $CFG_GLPI["root_doc"] . "/plugins/tasklists/ajax/dropdownTypeTasks.php", $params, false); if ($p['display']) { echo $out; return $rand; } return $out; }
/** * Print generic search form * * @param $itemtype type to display the form * @param $params array of parameters may include field, contains, sort, is_deleted, link, * link2, contains2, field2, type2 * * @return nothing (displays) **/ static function showGenericSearch($itemtype, array $params) { global $CFG_GLPI; // Default values of parameters $p['link'] = array(); // $p['field'] = array(); $p['contains'] = array(); $p['searchtype'] = array(); $p['sort'] = ''; $p['is_deleted'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; $p['field2'] = ''; $p['itemtype2'] = ''; $p['searchtype2'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } $options = self::getCleanedOptions($itemtype); $target = Toolbox::getItemTypeSearchURL($itemtype); // Instanciate an object to access method $item = NULL; if ($itemtype != 'AllAssets') { $item = getItemForItemtype($itemtype); } $linked = self::getMetaItemtypeAvailable($itemtype); echo "<form name='searchform{$itemtype}' method='get' action=\"{$target}\">"; echo "<div id='searchcriterias'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; if ($_SESSION["glpisearchcount"][$itemtype] + $_SESSION["glpisearchcount2"][$itemtype] > 1) { echo "<td width='10' class='center'>"; echo "<a href=\"javascript:toggleTableDisplay('searchcriteriastable','searchcriteriasimg',\n '" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png',\n '" . $CFG_GLPI["root_doc"] . "/pics/deplier_up.png')\">"; echo "<img alt='' name='searchcriteriasimg' src=\"" . $CFG_GLPI["root_doc"] . "/pics/deplier_up.png\">"; echo "</td>"; } echo "<td>"; echo "<table id='searchcriteriastable'>"; // Display normal search parameters for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) { echo "<tr " . ($i == 0 ? "class='headerRow'" : '') . "><td class='left' width='50%'>"; // First line display add / delete images for normal and meta search items if ($i == 0) { echo "<input type='hidden' disabled id='add_search_count' name='add_search_count'\n value='1'>"; echo "<a href='#' onClick = \"document.getElementById('add_search_count').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/plus.png\" alt='+' title=\"" . __s('Add a search criterion') . "\"></a> "; if ($_SESSION["glpisearchcount"][$itemtype] > 1) { echo "<input type='hidden' disabled id='delete_search_count'\n name='delete_search_count' value='1'>"; echo "<a href='#' onClick = \"document.getElementById('delete_search_count').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/moins.png\" alt='-' title=\"" . __s('Delete a search criterion') . "\"></a> "; } if (is_array($linked) && count($linked) > 0) { echo "<input type='hidden' disabled id='add_search_count2' name='add_search_count2'\n value='1'>"; echo "<a href='#' onClick=\"document.getElementById('add_search_count2').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_plus.png\" alt='+' title=\"" . __s('Add a global search criterion') . "\"></a> "; if ($_SESSION["glpisearchcount2"][$itemtype] > 0) { echo "<input type='hidden' disabled id='delete_search_count2'\n name='delete_search_count2' value='1'>"; echo "<a href='#' onClick=\"document.getElementById('delete_search_count2').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_moins.png\" alt='-' title=\"" . __s('Delete a global search criterion') . "\"></a> "; } } $itemtable = getTableForItemType($itemtype); if ($item && $item->maybeDeleted()) { echo "<input type='hidden' id='is_deleted' name='is_deleted' value='" . $p['is_deleted'] . "'>"; echo "<a href='#' onClick = \"toogle('is_deleted','','','');\n document.forms['searchform{$itemtype}'].submit();\">\n <img src=\"" . $CFG_GLPI["root_doc"] . "/pics/showdeleted" . (!$p['is_deleted'] ? '_no' : '') . ".png\" name='img_deleted' alt=\"" . (!$p['is_deleted'] ? __s('Show the dustbin') : __s("Don't show deleted items")) . "\" title=\"" . (!$p['is_deleted'] ? __s('Show the dustbin') : __s("Don't show deleted items")) . "\"></a>"; echo ' '; } } // Display link item if ($i > 0) { echo "<select name='link[{$i}]'>"; echo "<option value = 'AND' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND") { echo "selected"; } echo ">AND</option>\n"; echo "<option value='OR' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR") { echo "selected"; } echo ">OR</option>\n"; echo "<option value='AND NOT' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND NOT") { echo "selected"; } echo ">AND NOT</option>\n"; echo "<option value='OR NOT' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR NOT") { echo "selected"; } echo ">OR NOT</option>"; echo "</select> "; } $selected = $first = ''; // display select box to define search item echo "<select id='Search{$itemtype}{$i}' name=\"field[{$i}]\" size='1'>"; if ($CFG_GLPI['allow_search_view'] == 2) { echo "<option value='view' "; if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "view") { echo "selected"; $selected = 'view'; } echo ">" . __('Items seen') . "</option>\n"; } reset($options); $first_group = true; $str_limit = 28; // Not $_SESSION['glpidropdown_chars_limit'] because must be really to short (5 or 10) and search engine will be unusable $nb_in_group = 0; $group = ''; foreach ($options as $key => $val) { // print groups if (!is_array($val)) { if (!$first_group) { $group .= "</optgroup>\n"; } else { $first_group = false; } if ($nb_in_group) { echo $group; } $group = ''; $nb_in_group = 0; $group .= "<optgroup label=\"" . Toolbox::substr($val, 0, $str_limit) . "\">"; } else { if (!isset($val['nosearch']) || $val['nosearch'] == false) { $nb_in_group++; $group .= "<option title=\"" . Html::cleanInputText($val["name"]) . "\" value='{$key}'"; if (is_array($p['field']) && isset($p['field'][$i]) && $key == $p['field'][$i]) { $group .= "selected"; $selected = $key; } else { if (empty($first)) { $first = $key; } } $group .= ">" . Toolbox::substr($val["name"], 0, $str_limit) . "</option>\n"; } } } if (!$first_group) { $group .= "</optgroup>\n"; } if ($nb_in_group) { echo $group; } if ($CFG_GLPI['allow_search_view'] == 1) { echo "<option value='view' "; if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "view") { echo "selected"; $selected = 'view'; } echo ">" . __('Items seen') . "</option>\n"; } if ($CFG_GLPI['allow_search_all']) { echo "<option value='all' "; if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "all") { echo "selected"; $selected = 'all'; } echo ">" . __('All') . "</option>"; } if (empty($selected)) { $selected = $first; } echo "</select>\n"; echo "</td><td class='left'>"; echo "<div id='SearchSpan{$itemtype}{$i}'>\n"; $used_itemtype = $itemtype; // Force Computer itemtype for AllAssets to permit to show specific items if ($itemtype == 'AllAssets') { $used_itemtype = 'Computer'; } $_POST['itemtype'] = $used_itemtype; $_POST['num'] = $i; $_POST['field'] = $selected; $_POST['searchtype'] = is_array($p['searchtype']) && isset($p['searchtype'][$i]) ? $p['searchtype'][$i] : ""; $_POST['value'] = is_array($p['contains']) && isset($p['contains'][$i]) ? stripslashes($p['contains'][$i]) : ""; include GLPI_ROOT . "/ajax/searchoption.php"; echo "</div>\n"; $params = array('field' => '__VALUE__', 'itemtype' => $used_itemtype, 'num' => $i, 'value' => $_POST["value"], 'searchtype' => $_POST["searchtype"]); Ajax::updateItemOnSelectEvent("Search{$itemtype}{$i}", "SearchSpan{$itemtype}{$i}", $CFG_GLPI["root_doc"] . "/ajax/searchoption.php", $params); echo "</td></tr>\n"; } $metanames = array(); if (is_array($linked) && count($linked) > 0) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { echo "<tr><td class='left' colspan='2'>"; $rand = mt_rand(); echo "<table width='100%'><tr class='left'><td width='35%'>"; // Display link item (not for the first item) echo "<select name='link2[{$i}]'>"; echo "<option value='AND' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "AND") { echo "selected"; } echo ">AND</option>\n"; echo "<option value='OR' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR") { echo "selected"; } echo ">OR</option>\n"; echo "<option value='AND NOT' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "AND NOT") { echo "selected"; } echo ">AND NOT</option>\n"; echo "<option value='OR NOT' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR NOT") { echo "selected"; } echo ">OR NOT</option>\n"; echo "</select> "; // Display select of the linked item type available echo "<select name='itemtype2[{$i}]' id='itemtype2_" . $itemtype . "_" . $i . "_{$rand}'>"; echo "<option value=''>" . Dropdown::EMPTY_VALUE . "</option>"; foreach ($linked as $key) { if (!isset($metanames[$key])) { if ($linkitem = getItemForItemtype($key)) { $metanames[$key] = $linkitem->getTypeName(); } } echo "<option value='{$key}'>" . Toolbox::substr($metanames[$key], 0, 20) . "</option>\n"; } echo "</select> "; echo "</td><td>"; // Ajax script for display search met& item echo "<span id='show_" . $itemtype . "_" . $i . "_{$rand}'> </span>\n"; $params = array('itemtype' => '__VALUE__', 'num' => $i, 'field' => is_array($p['field2']) && isset($p['field2'][$i]) ? $p['field2'][$i] : "", 'value' => is_array($p['contains2']) && isset($p['contains2'][$i]) ? $p['contains2'][$i] : "", 'searchtype2' => is_array($p['searchtype2']) && isset($p['searchtype2'][$i]) ? $p['searchtype2'][$i] : ""); Ajax::updateItemOnSelectEvent("itemtype2_" . $itemtype . "_" . $i . "_{$rand}", "show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params); if (is_array($p['itemtype2']) && isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i])) { $params['itemtype'] = $p['itemtype2'][$i]; Ajax::updateItem("show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params); echo "<script type='text/javascript' >"; echo "window.document.getElementById('itemtype2_" . $itemtype . "_" . $i . "_{$rand}').value='" . $p['itemtype2'][$i] . "';"; echo "</script>\n"; } echo "</td></tr></table>"; echo "</td></tr>\n"; } } echo "</table>\n"; echo "</td>\n"; echo "<td width='150px'>"; echo "<table width='100%'>"; // Display sort selection /* echo "<tr><td colspan='2'>".__('sorted by'); echo " <select name='sort' size='1'>"; reset($options); $first_group=true; foreach ($options as $key => $val) { if (!is_array($val)) { if (!$first_group) { echo "</optgroup>\n"; } else { $first_group=false; } echo "<optgroup label=\"$val\">"; } else { echo "<option value='$key'"; if ($key == $p['sort']) { echo " selected"; } echo ">".Toolbox::substr($val["name"],0,20)."</option>\n"; } } if (!$first_group) { echo "</optgroup>\n"; } echo "</select> "; echo "</td></tr>\n"; */ // Display deleted selection echo "<tr>"; // Display submit button echo "<td width='80' class='center'>"; echo "<input type='submit' value=\"" . _sx('button', 'Search') . "\" class='submit' >"; echo "</td><td>"; Bookmark::showSaveButton(Bookmark::SEARCH, $itemtype); echo "<a href='{$target}?reset=reset' >"; echo " <img title=\"" . __s('Blank') . "\" alt=\"" . __s('Blank') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/reset.png' class='calendrier'></a>"; echo "</td></tr></table>\n"; echo "</td></tr>"; echo "</table>\n"; // For dropdown echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; // Reset to start when submit new search echo "<input type='hidden' name='start' value='0'>"; echo "</div>"; Html::closeForm(); }
/** * Show generic date search * * @param $element name of the html element * @param $value default value (default '') * @param $options array of possible options: * - with_time display with time selection ? (default false) * - with_future display with future date selection ? (default false) * - with_days display specific days selection TODAY, BEGINMONTH, LASTMONDAY... ? (default true) * * @return rand value of dropdown **/ static function showGenericDateTimeSearch($element, $value = '', $options = array()) { global $CFG_GLPI; $p['with_time'] = false; $p['with_future'] = false; $p['with_days'] = true; $p['with_specific_date'] = true; $p['display'] = true; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } $rand = mt_rand(); $output = ''; // Validate value if ($value != 'NOW' && $value != 'TODAY' && !preg_match("/\\d{4}-\\d{2}-\\d{2}.*/", $value) && !strstr($value, 'HOUR') && !strstr($value, 'DAY') && !strstr($value, 'WEEK') && !strstr($value, 'MONTH') && !strstr($value, 'YEAR')) { $value = ""; } if (empty($value)) { $value = 'NOW'; } $specific_value = date("Y-m-d H:i:s"); if (preg_match("/\\d{4}-\\d{2}-\\d{2}.*/", $value)) { $specific_value = $value; $value = 0; } $output .= "<table width='100%'><tr><td width='50%'>"; $dates = Html::getGenericDateTimeSearchItems($p); $output .= Dropdown::showFromArray("_select_{$element}", $dates, array('value' => $value, 'display' => false, 'rand' => $rand)); $field_id = Html::cleanId("dropdown__select_{$element}{$rand}"); $output .= "</td><td width='50%'>"; $contentid = Html::cleanId("displaygenericdate{$element}{$rand}"); $output .= "<span id='{$contentid}'></span>"; $params = array('value' => '__VALUE__', 'name' => $element, 'withtime' => $p['with_time'], 'specificvalue' => $specific_value); $output .= Ajax::updateItemOnSelectEvent($field_id, $contentid, $CFG_GLPI["root_doc"] . "/ajax/genericdate.php", $params, false); $params['value'] = $value; $output .= Ajax::updateItem($contentid, $CFG_GLPI["root_doc"] . "/ajax/genericdate.php", $params, '', false); $output .= "</td></tr></table>"; if ($p['display']) { echo $output; return $rand; } return $output; }
function showAllItems($myname, $value_type = 0, $value = 0, $entity_restrict = -1) { global $CFG_GLPI; $types = PluginRacksRack::getTypes(); $types[] = 'PluginRacksOther'; $rand = mt_rand(); $options = array(); echo "<table border='0'><tr><td>\n"; echo "<select name='type' id='itemtype{$rand}'>\n"; echo "<option value='0'>" . Dropdown::EMPTY_VALUE . "</option>\n"; foreach ($types as $type) { $item = new $type(); echo "<option value='" . $type . "Model'>" . $item::getTypeName(2) . "</option>\n"; } echo "</select>"; $params = array('modeltable' => '__VALUE__', 'value' => $value, 'myname' => $myname, 'entity_restrict' => $entity_restrict); Ajax::UpdateItemOnSelectEvent("itemtype{$rand}", "show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/racks/ajax/dropdownAllItems.php", $params); echo "</td><td>\n"; echo "<span id='show_{$myname}{$rand}'> </span>\n"; echo "</td></tr></table>\n"; if ($value > 0) { echo "<script type='text/javascript' >\n"; echo "document.getElementById('itemtype{$rand}').value='" . $value_type . "';"; echo "</script>\n"; $params["modeltable"] = $value_type; Ajax::updateItem("show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/racks/ajax/dropdownAllItems.php", $params); } return $rand; }
exit; } if (!isset($_POST[$item->getRuleIdField()])) { exit; } // Existing action if ($_POST['ruleactions_id'] > 0) { $already_used = false; } else { // New action $ra = getItemForItemtype($item->getRuleActionClass()); $used = $ra->getAlreadyUsedForRuleID($_POST[$item->getRuleIdField()], $item->getType()); $already_used = in_array($_POST["field"], $used); } echo "<table width='100%'><tr><td width='30%'>"; $action_type = ''; if (isset($_POST["action_type"])) { $action_type = $_POST["action_type"]; } $randaction = RuleAction::dropdownActions(array('subtype' => $_POST["sub_type"], 'name' => "action_type", 'field' => $_POST["field"], 'value' => $action_type, 'alreadyused' => $already_used)); echo "</td><td>"; echo "<span id='action_type_span{$randaction}'>\n"; echo "</span>\n"; $paramsaction = array('action_type' => '__VALUE__', 'field' => $_POST["field"], 'sub_type' => $_POST["sub_type"], $item->getForeignKeyField() => $_POST[$item->getForeignKeyField()]); Ajax::updateItemOnSelectEvent("dropdown_action_type{$randaction}", "action_type_span{$randaction}", $CFG_GLPI["root_doc"] . "/ajax/ruleactionvalue.php", $paramsaction); if (isset($_POST['value'])) { $paramsaction['value'] = stripslashes($_POST['value']); } Ajax::updateItem("action_type_span{$randaction}", $CFG_GLPI["root_doc"] . "/ajax/ruleactionvalue.php", $paramsaction, "dropdown_action_type{$randaction}"); echo "</td></tr></table>"; }
/** * Make a select box for all items * * @since version 0.85 * * @param $options array: * - itemtype_name : the name of the field containing the itemtype (default 'itemtype') * - items_id_name : the name of the field containing the id of the selected item * (default 'items_id') * - itemtypes : all possible types to search for (default: $CFG_GLPI["state_types"]) * - default_itemtype : the default itemtype to select (don't define if you don't * need a default) (defaut 0) * - entity_restrict : restrict entity in searching items (default -1) * - onlyglobal : don't match item that don't have `is_global` == 1 (false by default) * - checkright : check to see if we can "view" the itemtype (false by default) * - showItemSpecificity : given an item, the AJAX file to open if there is special * treatment. For instance, select a Item_Device* for CommonDevice * - emptylabel : Empty choice's label (default self::EMPTY_VALUE) * - used : array / Already used items ID: not to display in dropdown (default empty) * * @return randomized value used to generate HTML IDs **/ static function showSelectItemFromItemtypes(array $options = array()) { global $CFG_GLPI; $params = array(); $params['itemtype_name'] = 'itemtype'; $params['items_id_name'] = 'items_id'; $params['itemtypes'] = ''; $params['default_itemtype'] = 0; $params['entity_restrict'] = -1; $params['onlyglobal'] = false; $params['checkright'] = false; $params['showItemSpecificity'] = ''; $params['emptylabel'] = self::EMPTY_VALUE; $params['used'] = array(); if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $params[$key] = $val; } } $rand = self::showItemType($params['itemtypes'], array('checkright' => $params['checkright'], 'name' => $params['itemtype_name'], 'emptylabel' => $params['emptylabel'])); if ($rand) { $p = array('idtable' => '__VALUE__', 'name' => $params['items_id_name'], 'entity_restrict' => $params['entity_restrict'], 'showItemSpecificity' => $params['showItemSpecificity']); // manage condition if ($params['onlyglobal']) { $p['condition'] = static::addNewCondition("`is_global` = 1"); } if ($params['used']) { $p['used'] = $params['used']; } $field_id = Html::cleanId("dropdown_" . $params['itemtype_name'] . $rand); $show_id = Html::cleanId("show_" . $params['items_id_name'] . $rand); Ajax::updateItemOnSelectEvent($field_id, $show_id, $CFG_GLPI["root_doc"] . "/ajax/dropdownAllItems.php", $p); echo "<br><span id='{$show_id}'> </span>\n"; // We check $options as the caller will set $options['default_itemtype'] only if it needs a // default itemtype and the default value can be '' thus empty won't be valid ! if (array_key_exists('default_itemtype', $options)) { echo "<script type='text/javascript' >\n"; echo Html::jsSetDropdownValue($field_id, $params['default_itemtype']); echo "</script>\n"; $p["idtable"] = $params['default_itemtype']; Ajax::updateItem($show_id, $CFG_GLPI["root_doc"] . "/ajax/dropdownAllItems.php", $p); } } return $rand; }
function showGenericSearch($itemtype, $params) { global $CFG_GLPI; // Default values of parameters $p = array(); $p['link'] = array(); // $p['field'] = array(); $p['contains'] = array(); $p['searchtype'] = array(); $p['sort'] = ''; $p['is_deleted'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; $p['field2'] = ''; $p['itemtype2'] = ''; $p['searchtype2'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } $options = Search::getCleanedOptions($itemtype); // $target = Toolbox::getItemTypeSearchURL($itemtype); // Instanciate an object to access method $item = NULL; if ($itemtype != 'States' && class_exists($itemtype)) { $item = new $itemtype(); } $linked = Search::getMetaItemtypeAvailable($itemtype); if (!isset($_GET['id']) || strstr($_SERVER['REQUEST_URI'], 'displayview_rule.form.php')) { $item->getEmpty(); } else { $item->getFromDB($_GET['id']); } if (strstr($_SERVER['REQUEST_URI'], 'displayview_rule.form.php')) { echo "<form name='searchform{$itemtype}' method='get' action=\"" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/displayview_rule.form.php\">"; } else { echo "<form name='searchform{$itemtype}' method='get' action=\"" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/componentscatalog_rule.form.php\">"; } $item->showFormHeader(); // echo "<form name='searchform$itemtype' method='get' action=\"". // $CFG_GLPI['root_doc']."/plugins/monitoring/front/componentscatalog_rule.form.php\">"; // echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td>"; echo __('Name') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='name' value='" . $_GET['name'] . "'/>"; echo "</td>"; echo "<td>"; echo __('Status') . " :"; echo "</td>"; echo "<td>"; echo $_GET['itemtype']; echo "</td>"; echo "</tr>"; if (isset($_GET['itemtype'])) { echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; echo "<table>"; // Display normal search parameters for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) { echo "<tr><td class='left' width='50%'>"; // First line display add / delete images for normal and meta search items if ($i == 0) { echo "<input type='hidden' disabled id='add_search_count' name='add_search_count'\n value='1'>"; echo "<a href='#' onClick = \"document.getElementById('add_search_count').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/plus.png\" alt='+' title=\"" . __s('Add a search criterion') . "\"></a> "; if ($_SESSION["glpisearchcount"][$itemtype] > 1) { echo "<input type='hidden' disabled id='delete_search_count'\n name='delete_search_count' value='1'>"; echo "<a href='#' onClick = \"document.getElementById('delete_search_count').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/moins.png\" alt='-' title=\"" . __s('Delete a search criterion') . "\"></a> "; } if (is_array($linked) && count($linked) > 0) { echo "<input type='hidden' disabled id='add_search_count2' name='add_search_count2'\n value='1'>"; echo "<a href='#' onClick=\"document.getElementById('add_search_count2').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_plus.png\" alt='+' title=\"" . __s('Add a global search criterion') . "\"></a> "; if ($_SESSION["glpisearchcount2"][$itemtype] > 0) { echo "<input type='hidden' disabled id='delete_search_count2'\n name='delete_search_count2' value='1'>"; echo "<a href='#' onClick=\"document.getElementById('delete_search_count2').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_moins.png\" alt='-' title=\"" . __s('Delete a global search criterion') . "\"></a> "; } } // $itemtable = getTableForItemType($itemtype); // if ($item && $item->maybeDeleted()) { // echo "<input type='hidden' id='is_deleted' name='is_deleted' value='". // $p['is_deleted']."'>"; // echo "<a href='#' onClick = \"toogle('is_deleted','','',''); // document.forms['searchform$itemtype'].submit();\"> // <img src=\"".$CFG_GLPI["root_doc"]."/pics/showdeleted". // (!$p['is_deleted']?'_no':'').".png\" name='img_deleted' alt=\"". // (!$p['is_deleted']?$LANG['common'][3]:$LANG['common'][81])."\" title=\"". // (!$p['is_deleted']?$LANG['common'][3]:$LANG['common'][81])."\" ></a>"; // // Dropdown::showYesNo("is_deleted",$p['is_deleted']); // echo ' '; // } } // Display link item if ($i > 0) { echo "<select name='link[{$i}]'>"; echo "<option value = 'AND' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND") { echo "selected"; } echo ">AND</option>\n"; echo "<option value='OR' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR") { echo "selected"; } echo ">OR</option>\n"; echo "<option value='AND NOT' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND NOT") { echo "selected"; } echo ">AND NOT</option>\n"; echo "<option value='OR NOT' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR NOT") { echo "selected"; } echo ">OR NOT</option>"; echo "</select> "; } // display select box to define search item echo "<select id='Search{$itemtype}{$i}' name=\"field[{$i}]\" size='1'>"; echo "<option value='view' "; if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "view") { echo "selected"; } echo ">" . __('Items seen') . "</option>\n"; reset($options); $first_group = true; $selected = 'view'; $str_limit = 28; $nb_in_group = 0; $group = ''; foreach ($options as $key => $val) { // print groups if (!is_array($val)) { if (!$first_group) { $group .= "</optgroup>\n"; } else { $first_group = false; } if ($nb_in_group) { echo $group; } $group = ''; $nb_in_group = 0; $group .= "<optgroup label=\"" . Toolbox::substr($val, 0, $str_limit) . "\">"; } else { if (!isset($val['nosearch']) || $val['nosearch'] == false) { $nb_in_group++; $group .= "<option title=\"" . Html::cleanInputText($val["name"]) . "\" value='{$key}'"; if (is_array($p['field']) && isset($p['field'][$i]) && $key == $p['field'][$i]) { $group .= "selected"; $selected = $key; } $group .= ">" . Toolbox::substr($val["name"], 0, $str_limit) . "</option>\n"; } } } if (!$first_group) { $group .= "</optgroup>\n"; } if ($nb_in_group) { echo $group; } echo "<option value='all' "; if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "all") { echo "selected"; } echo ">" . __('All') . "</option>"; echo "</select>\n"; echo "</td><td class='left'>"; echo "<div id='SearchSpan{$itemtype}{$i}'>\n"; $_POST['itemtype'] = $itemtype; $_POST['num'] = $i; $_POST['field'] = $selected; $_POST['searchtype'] = is_array($p['searchtype']) && isset($p['searchtype'][$i]) ? $p['searchtype'][$i] : ""; $_POST['value'] = is_array($p['contains']) && isset($p['contains'][$i]) ? stripslashes($p['contains'][$i]) : ""; include GLPI_ROOT . "/ajax/searchoption.php"; echo "</div>\n"; $params = array('field' => '__VALUE__', 'itemtype' => $itemtype, 'num' => $i, 'value' => $_POST["value"], 'searchtype' => $_POST["searchtype"]); Ajax::updateItemOnSelectEvent("Search{$itemtype}{$i}", "SearchSpan{$itemtype}{$i}", $CFG_GLPI["root_doc"] . "/ajax/searchoption.php", $params, false); echo "</td></tr>\n"; } $metanames = array(); if (is_array($linked) && count($linked) > 0) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { echo "<tr><td class='left' colspan='2'>"; $rand = mt_rand(); echo "<table width='100%'><tr class='left'><td width='35%'>"; // Display link item (not for the first item) echo "<select name='link2[{$i}]'>"; echo "<option value='AND' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "AND") { echo "selected"; } echo ">AND</option>\n"; echo "<option value='OR' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR") { echo "selected"; } echo ">OR</option>\n"; echo "<option value='AND NOT' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "AND NOT") { echo "selected"; } echo ">AND NOT</option>\n"; echo "<option value='OR NOT' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR NOT") { echo "selected"; } echo ">OR NOT</option>\n"; echo "</select> "; // Display select of the linked item type available echo "<select name='itemtype2[{$i}]' id='itemtype2_" . $itemtype . "_" . $i . "_{$rand}'>"; echo "<option value=''>" . Dropdown::EMPTY_VALUE . "</option>"; foreach ($linked as $key) { if (!isset($metanames[$key])) { $linkitem = new $key(); $metanames[$key] = $linkitem->getTypeName(); } echo "<option value='{$key}'>" . Toolbox::substr($metanames[$key], 0, 20) . "</option>\n"; } echo "</select> "; echo "</td><td>"; // Ajax script for display search met& item echo "<span id='show_" . $itemtype . "_" . $i . "_{$rand}'> </span>\n"; $params = array('itemtype' => '__VALUE__', 'num' => $i, 'field' => is_array($p['field2']) && isset($p['field2'][$i]) ? $p['field2'][$i] : "", 'value' => is_array($p['contains2']) && isset($p['contains2'][$i]) ? $p['contains2'][$i] : "", 'searchtype2' => is_array($p['searchtype2']) && isset($p['searchtype2'][$i]) ? $p['searchtype2'][$i] : ""); Ajax::updateItemOnSelectEvent("itemtype2_" . $itemtype . "_" . $i . "_{$rand}", "show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params, false); if (is_array($p['itemtype2']) && isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i])) { $params['itemtype'] = $p['itemtype2'][$i]; Ajax::updateItem("show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params, false); echo "<script type='text/javascript' >"; echo "window.document.getElementById('itemtype2_" . $itemtype . "_" . $i . "_{$rand}').value='" . $p['itemtype2'][$i] . "';"; echo "</script>\n"; } echo "</td></tr></table>"; echo "</td></tr>\n"; } } echo "</table>\n"; echo "</td>\n"; echo "<td width='150px'>"; echo "<table width='100%'>"; // Display sort selection /* echo "<tr><td colspan='2'>".$LANG['search'][4]; echo " <select name='sort' size='1'>"; reset($options); $first_group=true; foreach ($options as $key => $val) { if (!is_array($val)) { if (!$first_group) { echo "</optgroup>\n"; } else { $first_group=false; } echo "<optgroup label=\"$val\">"; } else { echo "<option value='$key'"; if ($key == $p['sort']) { echo " selected"; } echo ">".Toolbox::substr($val["name"],0,20)."</option>\n"; } } if (!$first_group) { echo "</optgroup>\n"; } echo "</select> "; echo "</td></tr>\n"; */ // Display deleted selection echo "<tr>"; // Display submit button echo "<td width='80' class='center'>"; echo "<input type='submit' value=\"" . _sx('button', 'Search') . "\" class='submit' >"; echo "</td><td>"; // Bookmark::showSaveButton(Bookmark::SEARCH,$itemtype); if (strstr($_SERVER['REQUEST_URI'], 'displayview_rule.form.php')) { echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/displayview_rule.form.php?" . "reset=reset" . "&name=" . $_GET['name'] . "&plugin_monitoring_displayviews_id=" . $_GET['plugin_monitoring_displayviews_id'] . "&itemtype=" . $_GET['itemtype'] . "' >"; } else { echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/componentscatalog_rule.form.php?" . "reset=reset" . "&name=" . $_GET['name'] . "&plugin_monitoring_componentscalalog_id=" . $_GET['plugin_monitoring_componentscalalog_id'] . "&itemtype=" . $_GET['itemtype'] . "' >"; } echo " <img title=\"" . __s('Blank') . "\" alt=\"" . __s('Blank') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/reset.png' class='calendrier'></a>"; echo "</td></tr>"; echo "</table>\n"; echo "</td></tr>"; echo "<tr>"; } if (isset($_GET['id'])) { echo "<td colspan='2' class='center'>"; if (strstr($_SERVER['REQUEST_URI'], 'displayview_rule.form.php')) { echo "<input type='hidden' name='plugin_monitoring_displayviews_id' value='" . $_GET['plugin_monitoring_displayviews_id'] . "' >"; } else { echo "<input type='hidden' name='plugin_monitoring_componentscalalog_id' value='" . $_GET['plugin_monitoring_componentscalalog_id'] . "' >"; } echo "<input type='hidden' name='id' value='" . $_GET['id'] . "' >"; echo "<input type='submit' name='updaterule' value=\"Update this rule\" class='submit' >"; echo "</td>"; echo "<td colspan='2' class='center'>"; echo "<input type='submit' name='deleterule' value=\"Delete this rule\" class='submit' >"; } else { echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='plugin_monitoring_componentscalalog_id' value='" . $_GET['plugin_monitoring_componentscalalog_id'] . "' >"; echo "<input type='submit' name='addrule' value=\"Add this rule\" class='submit' >"; } echo "</td>"; echo "</tr>"; echo "</table>\n"; // For dropdown echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; // Reset to start when submit new search echo "<input type='hidden' name='start' value='0'>"; Html::closeForm(); }
public static function dropdown($options = array()) { global $DB, $CFG_GLPI; $params['itemtype_name'] = 'itemtype'; $params['items_id_name'] = 'items_id'; $params['itemtypes'] = array(); $params['default_itemtype'] = 0; $params['entity_restrict'] = -1; $params['onlyglobal'] = false; $params['checkright'] = false; $params['showItemSpecificity'] = ''; $params['emptylabel'] = ''; //$p['entity'] = ''; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } $rand = mt_rand(); $query = "select id, name from glpi_plugin_relation_typerelations order by 1"; $result = $DB->query($query); $type_relations = "type_relations" . $p['name']; //Desplegable tipos de relaciones echo "<select name='_nombresrelaciones' id='nombresrelaciones'>\n"; if ($DB->numrows($result)) { while ($data = $DB->fetch_array($result)) { echo "<option value='" . $data[0] . "'>" . $data[1] . "</option>\n"; } } echo "</select>\n"; //Desplegable de las clases $query = "select rc.id, rc.classlist, c.viewname FROM glpi_plugin_relation_relationclases rc, glpi_plugin_relation_clases c where rc.classlist=c.name and classname='" . $p['itemtype'] . "' order by 1"; //echo $query; $result = $DB->query($query); $arraySelect = array(); if ($DB->numrows($result)) { while ($data = $DB->fetch_array($result)) { $arraySelect[] = $data[1]; } $params['itemtypes'] = $arraySelect; } $rand = Dropdown::showItemType($params['itemtypes'], array('checkright' => $params['checkright'], 'name' => $params['itemtype_name'], 'emptylabel' => $params['emptylabel'])); if ($rand) { $p = array('idtable' => '__VALUE__', 'name' => $params['items_id_name'], 'entity_restrict' => $params['entity_restrict'], 'width' => '120', 'display_emptychoice' => true, 'showItemSpecificity' => $params['showItemSpecificity']); if ($params['onlyglobal']) { $p['condition'] = "`is_global` = 1"; } $field_id = Html::cleanId("dropdown_" . $params['itemtype_name'] . $rand); $show_id = Html::cleanId("show_" . $params['items_id_name'] . $rand); Ajax::updateItemOnSelectEvent($field_id, $show_id, $CFG_GLPI["root_doc"] . "/plugins/relation/ajax/dropdownAllItems.php", $p); echo "<br><span id='{$show_id}'> </span>\n"; // We check $options as the caller will set $options['default_itemtype'] only if it needs a // default itemtype and the default value can be '' thus empty won't be valid ! if (array_key_exists('default_itemtype', $options)) { echo "<script type='text/javascript' >\n"; echo Html::jsSetDropdownValue($field_id, $params['default_itemtype']); echo "</script>\n"; $p["idtable"] = $params['default_itemtype']; Ajax::updateItem($show_id, $CFG_GLPI["root_doc"] . "/plugins/relation/ajax/dropdownAllItems.php", $p); } } return $rand; }