/**
  * @param $report
  * @param $name            (default 'itemtype')
  * @param $label           (default '')
  * @param $types     array
  * @param $ignored   array
  **/
 function __construct($report, $name = 'itemtype', $label = '', $types = array(), $ignored = array())
 {
     global $CFG_GLPI;
     parent::__construct($report, $name, NOT_AVAILABLE, $label ? $label : __('Item type'));
     if (is_array($types) && count($types)) {
         // $types is an hashtable of itemtype => display name
         $this->types = $types;
     } else {
         if (is_string($types) && isset($CFG_GLPI[$types])) {
             // $types is the name of an configured type hashtable (infocom_types, doc_types, ...)
             foreach ($CFG_GLPI[$types] as $itemtype) {
                 if (($item = getItemForItemtype($itemtype)) && !in_array($itemtype, $ignored)) {
                     $this->types[$itemtype] = $item->getTypeName();
                 }
             }
             $this->types['all'] = __('All');
         } else {
             // No types, use helpdesk_types
             $this->types = Ticket::getAllTypesForHelpdesk();
             $this->types['all'] = __('All');
         }
     }
 }
 /**
  * Change the current entity(ies) of a authenticated user
  *
  * @param $params    array of options
  * @param $protocol        the communication protocol used
  *
  * @return array of hashtable
  **/
 static function methodListHelpdeskTypes($params, $protocol)
 {
     if (isset($params['help'])) {
         return array('help' => 'bool,optional');
     }
     if (!Session::getLoginUserID()) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     if (!isset($_SESSION["glpiactiveprofile"]["helpdesk_hardware"]) || !$_SESSION["glpiactiveprofile"]["helpdesk_hardware"]) {
         // No right to attach a item to a tickeet
         return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND);
     }
     $resp[] = array('id' => '', 'name' => __('General'));
     if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, Ticket::HELPDESK_MY_HARDWARE)) {
         $resp[] = array('id' => 'my', 'name' => __('My devices'));
     }
     if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, Ticket::HELPDESK_ALL_HARDWARE)) {
         $types = Ticket::getAllTypesForHelpdesk();
         foreach ($types as $id => $name) {
             $resp[] = array('id' => $id, 'name' => $name);
         }
     }
     return $resp;
 }
Beispiel #3
0
 /**
  * Get meta types available for search engine
  *
  * @param $itemtype type to display the form
  *
  * @return Array of available itemtype
  **/
 static function getMetaItemtypeAvailable($itemtype)
 {
     // Display meta search items
     $linked = array();
     // Define meta search items to linked
     switch (static::getMetaReferenceItemtype($itemtype)) {
         case 'Computer':
             $linked = array('Monitor', 'Peripheral', 'Phone', 'Printer', 'Software');
             break;
         case 'Ticket':
             if (Session::haveRight("ticket", Ticket::READALL)) {
                 $linked = array_keys(Ticket::getAllTypesForHelpdesk());
             }
             break;
         case 'Problem':
             if (Session::haveRight("problem", Problem::READALL)) {
                 $linked = array_keys(Problem::getAllTypesForHelpdesk());
             }
             break;
         case 'Printer':
         case 'Monitor':
         case "Peripheral":
         case "Software":
         case "Phone":
             $linked = array('Computer');
             break;
     }
     return $linked;
 }
Beispiel #4
0
 /**
  * Display item used to select a pattern for a criteria
  *
  * @param $name      criteria name
  * @param $ID        the given criteria
  * @param $condition condition used
  * @param $value     the pattern (default '')
  * @param $test      Is to test rule ? (false by default)
  **/
 function displayCriteriaSelectPattern($name, $ID, $condition, $value = "", $test = false)
 {
     $crit = $this->getCriteria($ID);
     $display = false;
     $tested = false;
     if (isset($crit['type']) && ($test || in_array($condition, array(self::PATTERN_IS, self::PATTERN_IS_NOT, self::PATTERN_NOT_UNDER, self::PATTERN_UNDER)))) {
         switch ($crit['type']) {
             case "yesonly":
                 Dropdown::showYesNo($name, $crit['table'], 0);
                 $display = true;
                 break;
             case "yesno":
                 Dropdown::showYesNo($name, $crit['table']);
                 $display = true;
                 break;
             case "dropdown":
                 $param = array('name' => $name, 'value' => $value);
                 if (isset($crit['condition'])) {
                     $param['condition'] = $crit['condition'];
                 }
                 Dropdown::show(getItemTypeForTable($crit['table']), $param);
                 $display = true;
                 break;
             case "dropdown_users":
                 User::dropdown(array('value' => $value, 'name' => $name, 'right' => 'all'));
                 $display = true;
                 break;
             case "dropdown_tracking_itemtype":
                 Dropdown::showItemTypes($name, array_keys(Ticket::getAllTypesForHelpdesk()));
                 $display = true;
                 break;
             case "dropdown_urgency":
                 Ticket::dropdownUrgency(array('name' => $name, 'value' => $value));
                 $display = true;
                 break;
             case "dropdown_impact":
                 Ticket::dropdownImpact(array('name' => $name, 'value' => $value));
                 $display = true;
                 break;
             case "dropdown_priority":
                 Ticket::dropdownPriority(array('name' => $name, 'value' => $value));
                 $display = true;
                 break;
             case "dropdown_status":
                 Ticket::dropdownStatus(array('name' => $name, 'value' => $value));
                 $display = true;
                 break;
             case "dropdown_tickettype":
                 Ticket::dropdownType($name, array('value' => $value));
                 $display = true;
                 break;
         }
         $tested = true;
     }
     //Not a standard condition
     if (!$tested) {
         $display = $this->displayAdditionalRuleCondition($condition, $crit, $name, $value, $test);
     }
     if ($condition == self::PATTERN_EXISTS || $condition == self::PATTERN_DOES_NOT_EXISTS) {
         echo "<input type='hidden' name='{$name}' value='1'>";
         $display = true;
     }
     if (!$display && ($rc = getItemForItemtype($this->rulecriteriaclass))) {
         Html::autocompletionTextField($rc, "pattern", array('name' => $name, 'value' => $value, 'size' => 70));
     }
 }
Beispiel #5
0
 /**
  * Make a select box for Tracking All Devices
  *
  * @param $myname             select name
  * @param $itemtype           preselected value.for item type
  * @param $items_id           preselected value for item ID (default 0)
  * @param $admin              is an admin access ? (default 0)
  * @param $users_id           user ID used to display my devices (default 0
  * @param $entity_restrict    Restrict to a defined entity (default -1)
  * @param $options   array of possible options:
  *    - tickets_id : ID of the ticket
  *    - used       : ID of the requester user
  *    - multiple   : allow multiple choice
  *    - rand       : random number
  *
  * @return nothing (print out an HTML select box)
  **/
 static function dropdownAllDevices($myname, $itemtype, $items_id = 0, $admin = 0, $users_id = 0, $entity_restrict = -1, $options = array())
 {
     global $CFG_GLPI, $DB;
     $params = array('tickets_id' => 0, 'used' => array(), 'multiple' => 0, 'rand' => mt_rand());
     foreach ($options as $key => $val) {
         $params[$key] = $val;
     }
     $rand = $params['rand'];
     if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] == 0) {
         echo "<input type='hidden' name='{$myname}' value=''>";
         echo "<input type='hidden' name='items_id' value='0'>";
     } else {
         echo "<div id='tracking_all_devices{$rand}'>";
         if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, Ticket::HELPDESK_ALL_HARDWARE)) {
             // Display a message if view my hardware
             if ($users_id && $_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, Ticket::HELPDESK_MY_HARDWARE)) {
                 echo __('Or complete search') . "&nbsp;";
             }
             $types = Ticket::getAllTypesForHelpdesk();
             $emptylabel = __('General');
             if ($params['tickets_id'] > 0) {
                 $emptylabel = Dropdown::EMPTY_VALUE;
             }
             Dropdown::showItemTypes($myname, array_keys($types), array('emptylabel' => $emptylabel, 'value' => $itemtype, 'rand' => $rand, 'display_emptychoice' => true));
             $found_type = isset($types[$itemtype]);
             $p = array('itemtype' => '__VALUE__', 'entity_restrict' => $entity_restrict, 'admin' => $admin, 'used' => $params['used'], 'multiple' => $params['multiple'], 'rand' => $rand, 'myname' => "add_items_id");
             Ajax::updateItemOnSelectEvent("dropdown_{$myname}{$rand}", "results_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/dropdownTrackingDeviceType.php", $p);
             echo "<span id='results_{$myname}{$rand}'>\n";
             // Display default value if itemtype is displayed
             if ($found_type && $itemtype) {
                 if (($item = getItemForItemtype($itemtype)) && $items_id) {
                     if ($item->getFromDB($items_id)) {
                         Dropdown::showFromArray('items_id', array($items_id => $item->getName()), array('value' => $items_id));
                     }
                 } else {
                     $p['itemtype'] = $itemtype;
                     echo "<script type='text/javascript' >\n";
                     Ajax::updateItemJsCode("results_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/dropdownTrackingDeviceType.php", $p);
                     echo '</script>';
                 }
             }
             echo "</span>\n";
         }
         echo "</div>";
     }
     return $rand;
 }
Beispiel #6
0
 /**
  * Get meta types available for search engine
  *
  * @param $itemtype type to display the form
  *
  * @return Array of available itemtype
  **/
 static function getMetaItemtypeAvailable($itemtype)
 {
     // Display meta search items
     $linked = array();
     // Define meta search items to linked
     switch ($itemtype) {
         case 'Computer':
             $linked = array('Monitor', 'Peripheral', 'Phone', 'Printer', 'Software');
             break;
         case 'Ticket':
             //if (Session::haveRight("show_all_ticket","1")) {
             if (Session::haveRight("ticket", Ticket::READALL)) {
                 $linked = array_keys(Ticket::getAllTypesForHelpdesk());
             }
             break;
         case 'Printer':
         case 'Monitor':
         case 'Peripheral':
         case 'Software':
         case 'Phone':
             $linked = array('Computer');
             break;
     }
     return $linked;
 }
 /**
  * Make a select box for Tracking All Devices
  *
  * @param $myname             select name
  * @param $itemtype           preselected value.for item type
  * @param $items_id           preselected value for item ID (default 0)
  * @param $admin              is an admin access ? (default 0)
  * @param $users_id           user ID used to display my devices (default 0
  * @param $entity_restrict    Restrict to a defined entity (default -1)
  * @param $tickets_id         Id of the ticket
  *
  * @return nothing (print out an HTML select box)
  **/
 static function dropdownAllDevices($myname, $itemtype, $items_id = 0, $admin = 0, $users_id = 0, $entity_restrict = -1, $tickets_id = 0)
 {
     global $CFG_GLPI, $DB;
     $rand = mt_rand();
     if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] == 0) {
         echo "<input type='hidden' name='{$myname}' value=''>";
         echo "<input type='hidden' name='items_id' value='0'>";
     } else {
         $rand = mt_rand();
         echo "<span id='tracking_all_devices{$rand}'>";
         if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, Ticket::HELPDESK_ALL_HARDWARE)) {
             if ($users_id && $_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, Ticket::HELPDESK_MY_HARDWARE)) {
                 echo __('Or complete search') . "&nbsp;";
             }
             $types = Ticket::getAllTypesForHelpdesk();
             $emptylabel = Dropdown::EMPTY_VALUE;
             $rand = Dropdown::showItemTypes($myname, array_keys($types), array('emptylabel' => $emptylabel, 'value' => $itemtype, 'width' => 200));
             $found_type = isset($types[$itemtype]);
             $width = 250;
             $params = array('itemtype' => '__VALUE__', 'entity_restrict' => $entity_restrict, 'admin' => $admin, 'width' => $width, 'myname' => "items_id");
             Ajax::updateItemOnSelectEvent("dropdown_{$myname}{$rand}", "results_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/shellcommands/ajax/dropdownTrackingDeviceType.php", $params);
             echo "<span id='results_{$myname}{$rand}'>\n";
             // Display default value if itemtype is displayed
             if ($found_type && $itemtype) {
                 if (($item = getItemForItemtype($itemtype)) && $items_id) {
                     if ($item->getFromDB($items_id)) {
                         Dropdown::showFromArray('items_id', array($items_id => $item->getName()), array('value' => $items_id, 'width' => $width));
                     }
                 } else {
                     $params['itemtype'] = $itemtype;
                     echo "<script type='text/javascript' >\n";
                     Ajax::updateItemJsCode("results_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/shellcommands/ajax/dropdownTrackingDeviceType.php", $params);
                     echo '</script>';
                 }
             }
             echo "</span>\n";
         }
         echo "</span>";
     }
     return $rand;
 }
 static function showGenericSearch($itemtype, array $params)
 {
     global $LANG, $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 = Search::getCleanedOptions($itemtype);
     //$target = Toolbox::getItemTypeSearchURL($itemtype);
     // Instanciate an object to access method
     $item = NULL;
     if ($itemtype != 'States' && class_exists($itemtype)) {
         $item = new $itemtype();
     }
     // Meta search names
     $metaactivated = array('Computer' => $LANG['Menu'][0], 'Printer' => $LANG['Menu'][2], 'Monitor' => $LANG['Menu'][3], 'Peripheral' => $LANG['Menu'][16], 'Software' => $LANG['Menu'][4], 'Phone' => $LANG['Menu'][34], 'Ticket' => $LANG['Menu'][5]);
     //$target = substr_replace($target, '/central.php#', strrpos($target, '/'), 1);
     //echo $target;
     //echo "<form name='searchform$itemtype' method='get' action='$target'>";
     echo "<form name='searchform{$itemtype}' method='get' action='" . $CFG_GLPI["root_doc"] . "/plugins/mobile/front/search.php'>";
     echo "<input type='hidden' name='menu' value='" . $_GET['menu'] . "' />";
     echo "<input type='hidden' name='ssmenu' value='" . $_GET['ssmenu'] . "' />";
     // Display normal search parameters
     for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) {
         // 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>";
             echo "<option value='OR' ";
             if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR") {
                 echo "selected";
             }
             echo ">OR</option>";
             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>";
             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 ">" . $LANG['search'][11] . "</option>";
         reset($options);
         $first_group = true;
         $selected = 'view';
         foreach ($options as $key => $val) {
             // print groups
             if (!is_array($val)) {
                 if (!$first_group) {
                     echo "</optgroup>";
                 } 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>";
                 }
             }
         }
         if (!$first_group) {
             echo "</optgroup>";
         }
         echo "<option value='all' ";
         if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "all") {
             echo "selected";
         }
         echo ">" . $LANG['common'][66] . "</option>";
         echo "</select>";
         echo "<span id='SearchSpan{$itemtype}{$i}'>\n";
         $_POST['itemtype'] = $itemtype;
         $_POST['num'] = $i;
         $_POST['field'] = $selected;
         //$_POST['meta']="type='search'";
         $_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 . "/plugins/mobile/inc/ajax.function.php";
         include GLPI_ROOT . "/plugins/mobile/ajax/searchoption.php";
         echo "</span>\n";
         $params = array('field' => '__VALUE__', 'itemtype' => $itemtype, 'num' => $i, 'value' => $_POST["value"], 'searchtype' => $_POST["searchtype"]);
         mobileAjaxUpdateItemOnSelectEvent("Search{$itemtype}{$i}", "SearchSpan{$itemtype}{$i}", $CFG_GLPI["root_doc"] . "/plugins/mobile/ajax/searchoption.php", $params, false);
     }
     // Display meta search items
     $linked = array();
     if ($_SESSION["glpisearchcount2"][$itemtype] > 0) {
         // Define meta search items to linked
         switch ($itemtype) {
             case 'Computer':
                 $linked = array('Printer', 'Monitor', 'Peripheral', 'Software', 'Phone');
                 break;
             case 'Ticket':
                 if (Session::haveRight("ticket", CREATE)) {
                     $linked = array_keys(Ticket::getAllTypesForHelpdesk());
                 }
                 break;
             case 'Printer':
             case 'Monitor':
             case 'Peripheral':
             case 'Software':
             case 'Phone':
                 $linked = array('Computer');
                 break;
         }
     }
     $metanames = array();
     if (is_array($linked) && count($linked) > 0) {
         for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) {
             $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>";
             echo "<option value='OR' ";
             if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR") {
                 echo "selected";
             }
             echo ">OR</option>";
             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>";
             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>";
             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>";
         }
     }
     // Display submit button
     echo "<br /><input type='submit' value=\"" . $LANG['buttons'][0] . "\" class='submit' data-theme='a' data-inline='true'>";
     // 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 "</form>";
     Html::closeForm();
 }