get_max_input_vars() static public method

Wrapper for max_input_vars
static public get_max_input_vars ( ) : integer
return integer
Ejemplo n.º 1
0
 /**
  * parse POST var to retrieve
  *  - Resource
  *  - Identifier
  *  - and parameters
  *
  *  And send to method corresponding identified resource
  *
  * @since version 9.1
  *
  * @return     xmlrpc response
  */
 public function call()
 {
     $resource = $this->parseIncomingParams();
     // retrieve session (if exist)
     $this->retrieveSession();
     $code = 200;
     if ($resource === "initSession") {
         $this->session_write = true;
         return $this->returnResponse($this->initSession($this->parameters));
     } else {
         if ($resource === "killSession") {
             // logout from glpi
             $this->session_write = true;
             return $this->returnResponse($this->killSession());
         } else {
             if ($resource === "changeActiveEntities") {
                 // change active entities
                 $this->session_write = true;
                 return $this->returnResponse($this->changeActiveEntities($this->parameters));
             } else {
                 if ($resource === "getMyEntities") {
                     // get all entities of logged user
                     return $this->returnResponse($this->getMyEntities($this->parameters));
                 } else {
                     if ($resource === "getActiveEntities") {
                         // get curent active entity
                         return $this->returnResponse($this->getActiveEntities($this->parameters));
                     } else {
                         if ($resource === "changeActiveProfile") {
                             // change active profile
                             $this->session_write = true;
                             return $this->returnResponse($this->changeActiveProfile($this->parameters));
                         } else {
                             if ($resource === "getMyProfiles") {
                                 // get all profiles of current logged user
                                 return $this->returnResponse($this->getMyProfiles($this->parameters));
                             } else {
                                 if ($resource === "getActiveProfile") {
                                     // get current active profile
                                     return $this->returnResponse($this->getActiveProfile($this->parameters));
                                 } else {
                                     if ($resource === "getFullSession") {
                                         // get complete php session
                                         return $this->returnResponse($this->getFullSession($this->parameters));
                                     } else {
                                         if ($resource === "getGlpiConfig") {
                                             // get complete php var $CFG_GLPI
                                             return $this->returnResponse($this->getGlpiConfig($this->parameters));
                                         } else {
                                             if ($resource === "getMultipleItems") {
                                                 // get multiple items (with various itemtype)
                                                 return $this->returnResponse($this->getMultipleItems($this->parameters));
                                             } else {
                                                 if ($resource === "listSearchOptions") {
                                                     // list searchOptions of an itemtype
                                                     return $this->returnResponse($this->listSearchOptions($this->parameters['itemtype'], $this->parameters));
                                                 } else {
                                                     if ($resource === "search") {
                                                         // Search on itemtype
                                                         self::checkSessionToken();
                                                         //search
                                                         $response = $this->searchItems($this->parameters['itemtype'], $this->parameters);
                                                         //add pagination headers
                                                         $additionalheaders = array();
                                                         $additionalheaders["Content-Range"] = $response['content-range'];
                                                         $additionalheaders["Accept-Range"] = $this->parameters['itemtype'] . " " . Toolbox::get_max_input_vars();
                                                         // diffent http return codes for complete or partial response
                                                         if ($response['count'] < $response['totalcount']) {
                                                             $code = 206;
                                                             // partial content
                                                         }
                                                         return $this->returnResponse($response, $code, $additionalheaders);
                                                     } else {
                                                         if (in_array($resource, array("getItem", "getItems", "createItems", "updateItems", "deleteItems"))) {
                                                             // commonDBTM manipulation
                                                             // check itemtype parameter
                                                             if (!isset($this->parameters['itemtype'])) {
                                                                 $this->returnError(__("missing itemtype"), 400, "ITEMTYPE_RESOURCE_MISSING");
                                                             }
                                                             if (!class_exists($this->parameters['itemtype']) || !is_subclass_of($this->parameters['itemtype'], 'CommonDBTM') && $this->parameters['itemtype'] != "AllAssets") {
                                                                 $this->returnError(__("itemtype not found or not an instance of CommonDBTM"), 400, "ERROR_ITEMTYPE_NOT_FOUND_NOR_COMMONDBTM");
                                                             } else {
                                                                 // get an CommonDBTM item
                                                                 if ($resource === "getItem") {
                                                                     // check id parameter
                                                                     if (!isset($this->parameters['id'])) {
                                                                         $this->returnError(__("missing id"), 400, "ID_RESOURCE_MISSING");
                                                                     }
                                                                     $response = $this->getItem($this->parameters['itemtype'], $this->parameters['id'], $this->parameters);
                                                                     $additionalheaders = array();
                                                                     if (isset($response['date_mod'])) {
                                                                         $datemod = strtotime($response['date_mod']);
                                                                         $additionalheaders['Last-Modified'] = gmdate("D, d M Y H:i:s", $datemod) . " GMT";
                                                                     }
                                                                     return $this->returnResponse($response, 200, $additionalheaders);
                                                                 } else {
                                                                     if ($resource === "getItems") {
                                                                         // get a collection of a CommonDBTM item
                                                                         // return collection of items
                                                                         $totalcount = 0;
                                                                         $response = $this->getItems($this->parameters['itemtype'], $this->parameters, $totalcount);
                                                                         //add pagination headers
                                                                         $range = [0, $_SESSION['glpilist_limit']];
                                                                         if (isset($this->parameters['range'])) {
                                                                             $range = explode("-", $this->parameters['range']);
                                                                             // fix end range
                                                                             if ($range[1] > $totalcount - 1) {
                                                                                 $range[1] = $totalcount - 1;
                                                                             }
                                                                             if ($range[1] - $range[0] + 1 < $totalcount) {
                                                                                 $code = 206;
                                                                                 // partial content
                                                                             }
                                                                         }
                                                                         $additionalheaders = array();
                                                                         $additionalheaders["Content-Range"] = implode('-', $range) . "/" . $totalcount;
                                                                         $additionalheaders["Accept-Range"] = $this->parameters['itemtype'] . " " . Toolbox::get_max_input_vars();
                                                                         return $this->returnResponse($response, $code, $additionalheaders);
                                                                     } else {
                                                                         if ($resource === "createItems") {
                                                                             // create one or many CommonDBTM items
                                                                             $response = $this->createItems($this->parameters['itemtype'], $this->parameters);
                                                                             $additionalheaders = array();
                                                                             if (count($response) == 1) {
                                                                                 // add a location targetting created element
                                                                                 $additionalheaders['location'] = self::$api_url . $this->parameters['itemtype'] . "/" . $response['id'];
                                                                             } else {
                                                                                 // add a link header targetting created elements
                                                                                 $additionalheaders['link'] = "";
                                                                                 foreach ($response as $created_item) {
                                                                                     if ($created_item['id']) {
                                                                                         $additionalheaders['link'] .= self::$api_url . $this->parameters['itemtype'] . "/" . $created_item['id'] . ",";
                                                                                     }
                                                                                 }
                                                                                 // remove last comma
                                                                                 $additionalheaders['link'] = trim($additionalheaders['link'], ",");
                                                                             }
                                                                             return $this->returnResponse($response, 201);
                                                                         } else {
                                                                             if ($resource === "updateItems") {
                                                                                 // update one or many CommonDBTM items
                                                                                 return $this->returnResponse($this->updateItems($this->parameters['itemtype'], $this->parameters));
                                                                             } else {
                                                                                 if ($resource === "deleteItems") {
                                                                                     // delete one or many CommonDBTM items
                                                                                     if (isset($this->parameters['id'])) {
                                                                                         //override input
                                                                                         $this->parameters['input'] = new stdClass();
                                                                                         $this->parameters['input']->id = $this->parameters['id'];
                                                                                     }
                                                                                     return $this->returnResponse($this->deleteItems($this->parameters['itemtype'], $this->parameters), $code);
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->messageLostError();
 }
Ejemplo n.º 2
0
 /**
  * Display massive actions
  *
  * @since 0.84 (before Search::displayMassiveActions)
  * @since version 0.85 only 1 parameter (in 0.84 $itemtype required)
  *
  * @todo replace 'hidden' by data-glpicore-ma-tags ?
  *
  * @param $options   array    of parameters
  * must contains :
  *    - container       : DOM ID of the container of the item checkboxes (since version 0.85)
  * may contains :
  *    - num_displayed   : integer number of displayed items. Permit to check suhosin limit. (default -1 not to check)
  *    - ontop           : boolean true if displayed on top (default true)
  *    - fixed           : boolean true if used with fixed table display (default true)
  *    - forcecreate     : boolean force creation of modal window (default = false).
  *            Modal is automatically created when displayed the ontop item.
  *            If only a bottom one is displayed use it
  *    - check_itemtype   : string alternate itemtype to check right if different from main itemtype (default empty)
  *    - check_items_id   : integer ID of the alternate item used to check right / optional (default empty)
  *    - is_deleted       : boolean is massive actions for deleted items ?
  *    - extraparams      : string extra URL parameters to pass to massive actions (default empty)
  *                         if ([extraparams]['hidden'] is set : add hidden fields to post)
  *    - specific_actions : array of specific actions (do not use standard one)
  *    - add_actions      : array of actions to add (do not use standard one)
  *    - confirm          : string of confirm message before massive action
  *    - item             : CommonDBTM object that has to be passed to the actions
  *    - tag_to_send      : the tag of the elements to send to the ajax window (default: common)
  *
  * @return nothing
  **/
 static function showMassiveActions($options = array())
 {
     global $CFG_GLPI;
     /// TODO : permit to pass several itemtypes to show possible actions of all types : need to clean visibility management after
     $p['ontop'] = true;
     $p['num_displayed'] = -1;
     $p['fixed'] = true;
     $p['forcecreate'] = false;
     $p['check_itemtype'] = '';
     $p['check_items_id'] = '';
     $p['is_deleted'] = false;
     $p['extraparams'] = array();
     $p['width'] = 800;
     $p['height'] = 400;
     $p['specific_actions'] = array();
     $p['add_actions'] = array();
     $p['confirm'] = '';
     $p['rand'] = '';
     $p['container'] = '';
     $p['display_arrow'] = true;
     $p['title'] = _n('Action', 'Actions', Session::getPluralNumber());
     $p['item'] = false;
     $p['tag_to_send'] = 'common';
     foreach ($options as $key => $val) {
         if (isset($p[$key])) {
             $p[$key] = $val;
         }
     }
     $url = $CFG_GLPI['root_doc'] . "/ajax/massiveaction.php";
     if ($p['container']) {
         $p['extraparams']['container'] = $p['container'];
     }
     if ($p['is_deleted']) {
         $p['extraparams']['is_deleted'] = 1;
     }
     if (!empty($p['check_itemtype'])) {
         $p['extraparams']['check_itemtype'] = $p['check_itemtype'];
     }
     if (!empty($p['check_items_id'])) {
         $p['extraparams']['check_items_id'] = $p['check_items_id'];
     }
     if (is_array($p['specific_actions']) && count($p['specific_actions'])) {
         $p['extraparams']['specific_actions'] = $p['specific_actions'];
     }
     if (is_array($p['add_actions']) && count($p['add_actions'])) {
         $p['extraparams']['add_actions'] = $p['add_actions'];
     }
     if ($p['item'] instanceof CommonDBTM) {
         $p['extraparams']['item_itemtype'] = $p['item']->getType();
         $p['extraparams']['item_items_id'] = $p['item']->getID();
     }
     // Manage modal window
     if (isset($_REQUEST['_is_modal']) && $_REQUEST['_is_modal']) {
         $p['extraparams']['hidden']['_is_modal'] = 1;
     }
     if ($p['fixed']) {
         $width = '950px';
     } else {
         $width = '95%';
     }
     $identifier = md5($url . serialize($p['extraparams']) . $p['rand']);
     $max = Toolbox::get_max_input_vars();
     if ($p['num_displayed'] >= 0 && $max > 0 && $max < $p['num_displayed'] + 10) {
         if (!$p['ontop'] || isset($p['forcecreate']) && $p['forcecreate']) {
             echo "<table class='tab_cadre' width='{$width}'><tr class='tab_bg_1'>" . "<td><span class='b'>";
             echo __('Selection too large, massive action disabled.') . "</span>";
             if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
                 echo "<br>" . __('To increase the limit: change max_input_vars or suhosin.post.max_vars in php configuration.');
             }
             echo "</td></tr></table>";
         }
     } else {
         // Create Modal window on top
         if ($p['ontop'] || isset($p['forcecreate']) && $p['forcecreate']) {
             echo "<div id='massiveactioncontent{$identifier}'></div>";
             if (!empty($p['tag_to_send'])) {
                 $js_modal_fields = "            var items = \$('";
                 if (!empty($p['container'])) {
                     $js_modal_fields .= '[id=' . $p['container'] . '] ';
                 }
                 $js_modal_fields .= "[data-glpicore-ma-tags~=" . $p['tag_to_send'] . "]')";
                 $js_modal_fields .= ".each(function( index ) {\n";
                 $js_modal_fields .= "              fields[\$(this).attr('name')] = \$(this).attr('value');\n";
                 $js_modal_fields .= "              if ((\$(this).attr('type') == 'checkbox') && (!\$(this).is(':checked'))) {\n";
                 $js_modal_fields .= "                 fields[\$(this).attr('name')] = 0;\n";
                 $js_modal_fields .= "              }\n";
                 $js_modal_fields .= "            });";
             } else {
                 $js_modal_fields = "";
             }
             Ajax::createModalWindow('massiveaction_window' . $identifier, $url, array('title' => $p['title'], 'container' => 'massiveactioncontent' . $identifier, 'extraparams' => $p['extraparams'], 'width' => $p['width'], 'height' => $p['height'], 'js_modal_fields' => $js_modal_fields));
         }
         echo "<table class='tab_glpi' width='{$width}'><tr>";
         if ($p['display_arrow']) {
             echo "<td width='30px'><img src='" . $CFG_GLPI["root_doc"] . "/pics/arrow-left" . ($p['ontop'] ? '-top' : '') . ".png' alt=''></td>";
         }
         echo "<td width='100%' class='left'>";
         echo "<a class='vsubmit' ";
         if (is_array($p['confirm'] || strlen($p['confirm']))) {
             echo self::addConfirmationOnAction($p['confirm'], "massiveaction_window{$identifier}.dialog(\"open\");");
         } else {
             echo "onclick='massiveaction_window{$identifier}.dialog(\"open\");'";
         }
         echo " href='#modal_massaction_content{$identifier}' title=\"" . htmlentities($p['title'], ENT_QUOTES, 'UTF-8') . "\">";
         echo $p['title'] . "</a>";
         echo "</td>";
         echo "</tr></table>";
         if (!$p['ontop'] || isset($p['forcecreate']) && $p['forcecreate']) {
             // Clean selection
             $_SESSION['glpimassiveactionselected'] = array();
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * parse url and http body to retrieve :
  *  - HTTP VERB (GET/POST/DELETE/PUT)
  *  - Resource : Rest endpoint
  *  - Identifier
  *  - and parameters
  *
  *  And send to method corresponding identified resource
  *
  * @return     json with response or error
  **/
 public function call()
 {
     //parse http request and find parts
     $this->request_uri = $_SERVER['REQUEST_URI'];
     $this->verb = $_SERVER['REQUEST_METHOD'];
     $path_info = str_replace("api/", "", trim($_SERVER['PATH_INFO'], '/'));
     $this->url_elements = explode('/', $path_info);
     // retrieve requested resource
     $resource = trim(strval($this->url_elements[0]));
     $is_inline_doc = strlen($resource) == 0 || $resource == "api";
     // Add headers for CORS
     $this->cors($this->verb);
     // retrieve paramaters (in body, query_string, headers)
     $this->parseIncomingParams($is_inline_doc);
     // show debug if required
     if (isset($this->parameters['debug'])) {
         $this->debug = $this->parameters['debug'];
         if (empty($this->debug)) {
             $this->debug = 1;
         }
         if ($this->debug >= 2) {
             $this->showDebug();
         }
     }
     // retrieve session (if exist)
     $this->retrieveSession();
     // retrieve param who permit session writing
     if (isset($this->parameters['session_write'])) {
         $this->session_write = (bool) $this->parameters['session_write'];
     }
     // inline documentation (api/)
     if ($is_inline_doc) {
         return $this->inlineDocumentation("apirest.md");
     } else {
         if ($resource === "initSession") {
             ## DECLARE ALL ENDPOINTS ##
             // login into glpi
             $this->session_write = true;
             return $this->returnResponse($this->initSession($this->parameters));
         } else {
             if ($resource === "killSession") {
                 // logout from glpi
                 $this->session_write = true;
                 return $this->returnResponse($this->killSession());
             } else {
                 if ($resource === "changeActiveEntities") {
                     // change active entities
                     $this->session_write = true;
                     return $this->returnResponse($this->changeActiveEntities($this->parameters));
                 } else {
                     if ($resource === "getMyEntities") {
                         // get all entities of logged user
                         return $this->returnResponse($this->getMyEntities($this->parameters));
                     } else {
                         if ($resource === "getActiveEntities") {
                             // get curent active entity
                             return $this->returnResponse($this->getActiveEntities($this->parameters));
                         } else {
                             if ($resource === "changeActiveProfile") {
                                 // change active profile
                                 $this->session_write = true;
                                 return $this->returnResponse($this->changeActiveProfile($this->parameters));
                             } else {
                                 if ($resource === "getMyProfiles") {
                                     // get all profiles of current logged user
                                     return $this->returnResponse($this->getMyProfiles($this->parameters));
                                 } else {
                                     if ($resource === "getActiveProfile") {
                                         // get current active profile
                                         return $this->returnResponse($this->getActiveProfile($this->parameters));
                                     } else {
                                         if ($resource === "getFullSession") {
                                             // get complete php session
                                             return $this->returnResponse($this->getFullSession($this->parameters));
                                         } else {
                                             if ($resource === "getGlpiConfig") {
                                                 // get complete php var $CFG_GLPI
                                                 return $this->returnResponse($this->getGlpiConfig($this->parameters));
                                             } else {
                                                 if ($resource === "listSearchOptions") {
                                                     // list searchOptions of an itemtype
                                                     $itemtype = $this->getItemtype(1);
                                                     return $this->returnResponse($this->listSearchOptions($itemtype, $this->parameters));
                                                 } else {
                                                     if ($resource === "getMultipleItems") {
                                                         // get multiple items (with various itemtype)
                                                         return $this->returnResponse($this->getMultipleItems($this->parameters));
                                                     } else {
                                                         if ($resource === "search") {
                                                             // Search on itemtype
                                                             self::checkSessionToken();
                                                             $itemtype = $this->getItemtype(1, true, true);
                                                             //clean stdObjects in parameter
                                                             $params = json_decode(json_encode($this->parameters), true);
                                                             //search
                                                             $response = $this->searchItems($itemtype, $params);
                                                             //add pagination headers
                                                             $additionalheaders = array();
                                                             $additionalheaders["Content-Range"] = $response['content-range'];
                                                             $additionalheaders["Accept-Range"] = $itemtype . " " . Toolbox::get_max_input_vars();
                                                             // diffent http return codes for complete or partial response
                                                             if ($response['count'] >= $response['totalcount']) {
                                                                 $code = 200;
                                                                 // full content
                                                             } else {
                                                                 $code = 206;
                                                                 // partial content
                                                             }
                                                             return $this->returnResponse($response, $code, $additionalheaders);
                                                         } else {
                                                             // commonDBTM manipulation
                                                             $itemtype = $this->getItemtype(0);
                                                             $id = $this->getId();
                                                             $additionalheaders = array();
                                                             $code = 200;
                                                             switch ($this->verb) {
                                                                 default:
                                                                 case "GET":
                                                                     // retrieve item(s)
                                                                     if ($id > 0 || $id == 0 && $itemtype == "Entity") {
                                                                         $response = $this->getItem($itemtype, $id, $this->parameters);
                                                                         if (isset($response['date_mod'])) {
                                                                             $datemod = strtotime($response['date_mod']);
                                                                             $additionalheaders['Last-Modified'] = gmdate("D, d M Y H:i:s", $datemod) . " GMT";
                                                                         }
                                                                     } else {
                                                                         // return collection of items
                                                                         $totalcount = 0;
                                                                         $response = $this->getItems($itemtype, $this->parameters, $totalcount);
                                                                         //add pagination headers
                                                                         $range = [0, $_SESSION['glpilist_limit']];
                                                                         if (isset($this->parameters['range'])) {
                                                                             $range = explode("-", $this->parameters['range']);
                                                                             // fix end range
                                                                             if ($range[1] > $totalcount - 1) {
                                                                                 $range[1] = $totalcount - 1;
                                                                             }
                                                                             if ($range[1] - $range[0] + 1 < $totalcount) {
                                                                                 $code = 206;
                                                                                 // partial content
                                                                             }
                                                                         }
                                                                         $additionalheaders["Content-Range"] = implode('-', $range) . "/" . $totalcount;
                                                                         $additionalheaders["Accept-Range"] = $itemtype . " " . Toolbox::get_max_input_vars();
                                                                     }
                                                                     break;
                                                                 case "POST":
                                                                     // create item(s)
                                                                     $response = $this->createItems($itemtype, $this->parameters);
                                                                     $code = 201;
                                                                     if (isset($response['id'])) {
                                                                         // add a location targetting created element
                                                                         $additionalheaders['location'] = self::$api_url . $itemtype . "/" . $response['id'];
                                                                     } else {
                                                                         // add a link header targetting created elements
                                                                         $additionalheaders['link'] = "";
                                                                         foreach ($response as $created_item) {
                                                                             if ($created_item['id']) {
                                                                                 $additionalheaders['link'] .= self::$api_url . $itemtype . "/" . $created_item['id'] . ",";
                                                                             }
                                                                         }
                                                                         // remove last comma
                                                                         $additionalheaders['link'] = trim($additionalheaders['link'], ",");
                                                                     }
                                                                     break;
                                                                 case "PUT":
                                                                     // update item(s)
                                                                     // if id is passed by query string, add it into input parameter
                                                                     $input = (array) $this->parameters['input'];
                                                                     if (($id > 0 || $id == 0 && $itemtype == "Entity") && !isset($input['id'])) {
                                                                         $this->parameters['input']->id = $id;
                                                                     }
                                                                     $response = $this->updateItems($itemtype, $this->parameters);
                                                                     break;
                                                                 case "DELETE":
                                                                     //delete item(s)
                                                                     // if id is passed by query string, construct an object with it
                                                                     if ($id !== false) {
                                                                         //override input
                                                                         $this->parameters['input'] = new stdClass();
                                                                         $this->parameters['input']->id = $id;
                                                                     }
                                                                     $response = $this->deleteItems($itemtype, $this->parameters);
                                                                     break;
                                                             }
                                                             return $this->returnResponse($response, $code, $additionalheaders);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->messageLostError();
 }
Ejemplo n.º 4
0
 /**
  * Display massive actions
  *
  * @since 0.84 (before Search::displayMassiveActions)
  *
  * @param $itemtype  string itemtype for massive actions
  * @param $options   array    of parameters
  * may contains :
  *    - num_displayed   : integer number of displayed items. Permit to check suhosin limit. (default -1 not to check)
  *    - ontop           : boolean true if displayed on top (default true)
  *    - fixed           : boolean true if used with fixed table display (default true)
  *    - forcecreate     : boolean force creation of modal window (default = false).
  *            Modal is automatically created when displayed the ontop item.
  *            If only a bottom one is displayed use it
  *    - check_itemtype   : string alternate itemtype to check right if different from main itemtype (default empty)
  *    - check_items_id   : integer ID of the alternate item used to check right / optional (default empty)
  *    - is_deleted       : boolean is massive actions for deleted items ?
  *    - extraparams      : string extra URL parameters to pass to massive actions (default empty)
  *    - specific_actions : array of specific actions (do not use standard one)
  *    - confirm          : string of confirm message before massive action
  *
  * @return nothing
  **/
 static function showMassiveActions($itemtype, $options = array())
 {
     global $CFG_GLPI;
     $p['ontop'] = true;
     $p['num_displayed'] = -1;
     $p['fixed'] = true;
     $p['forcecreate'] = false;
     $p['check_itemtype'] = '';
     $p['check_items_id'] = '';
     $p['is_deleted'] = false;
     $p['extraparams'] = array();
     $p['width'] = 800;
     $p['height'] = 400;
     $p['specific_actions'] = array();
     $p['confirm'] = '';
     $p['rand'] = '';
     foreach ($options as $key => $val) {
         if (isset($p[$key])) {
             $p[$key] = $val;
         }
     }
     $p['extraparams']['itemtype'] = $itemtype;
     $url = $CFG_GLPI['root_doc'] . "/ajax/massiveaction.php";
     if ($p['is_deleted']) {
         $p['extraparams']['is_deleted'] = 1;
     }
     if (!empty($p['check_itemtype'])) {
         $p['extraparams']['check_itemtype'] = $p['check_itemtype'];
     }
     if (!empty($p['check_items_id'])) {
         $p['extraparams']['check_items_id'] = $p['check_items_id'];
     }
     if (is_array($p['specific_actions']) && count($p['specific_actions'])) {
         $p['extraparams']['specific_actions'] = $p['specific_actions'];
     }
     if ($p['fixed']) {
         $width = '950px';
     } else {
         $width = '80%';
     }
     $identifier = md5($url . $itemtype . serialize($p['extraparams']) . $p['rand']);
     $max = Toolbox::get_max_input_vars();
     if ($p['num_displayed'] >= 0 && $max > 0 && $max < $p['num_displayed'] + 10) {
         if (!$p['ontop'] || isset($p['forcecreate']) && $p['forcecreate']) {
             echo "<table class='tab_cadre' width='{$width}'><tr class='tab_bg_1'>" . "<td><span class='b'>";
             echo __('Selection too large, massive action disabled.') . "</span>";
             if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
                 echo "<br>" . __('To increase the limit: change max_input_vars or suhosin.post.max_vars in php configuration.');
             }
             echo "</td></tr></table>";
         }
     } else {
         // Create Modal window on top
         if ($p['ontop'] || isset($p['forcecreate']) && $p['forcecreate']) {
             echo "<div id='massiveactioncontent{$identifier}'></div>";
             //             echo "<script type='text/javascript' >\n";
             //             echo "Ext.DomHelper.append(document.body, {tag: 'div', id: 'massiveactioncontent$identifier'});";
             //             echo "</script>";
             Ajax::createModalWindow('massiveaction_window' . $identifier, $url, array('title' => _n('Action', 'Actions', 2), 'container' => 'massiveactioncontent' . $identifier, 'extraparams' => $p['extraparams'], 'width' => $p['width'], 'height' => $p['height']));
         }
         echo "<table class='tab_glpi' width='{$width}'><tr>";
         echo "<td width='30px'><img src='" . $CFG_GLPI["root_doc"] . "/pics/arrow-left" . ($p['ontop'] ? '-top' : '') . ".png' alt=''></td>";
         echo "<td width='100%' class='left'>";
         echo "<a class='vsubmit' ";
         if (is_array($p['confirm'] || strlen($p['confirm']))) {
             echo self::addConfirmationOnAction($p['confirm'], "massiveaction_window{$identifier}.show();");
         } else {
             echo "onclick='massiveaction_window{$identifier}.show();'";
         }
         echo "href='#modal_massaction_content{$identifier}' title=\"" . _sn('Action', 'Actions', 2) . "\">";
         echo _n('Action', 'Actions', 2) . "</a>";
         echo "</td>";
         echo "</tr></table>";
         if (!$p['ontop'] || isset($p['forcecreate']) && $p['forcecreate']) {
             // Clean selection
             $_SESSION['glpimassiveactionselected'][$itemtype] = array();
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * show dropdown to select list limit
  *
  * @since version 0.83
  *
  * @param $onchange  String   optional, for ajax (default '')
  **/
 static function showListLimit($onchange = '')
 {
     global $CFG_GLPI;
     if (isset($_SESSION['glpilist_limit'])) {
         $list_limit = $_SESSION['glpilist_limit'];
     } else {
         $list_limit = $CFG_GLPI['list_limit'];
     }
     $values = array();
     for ($i = 5; $i < 20; $i += 5) {
         $values[$i] = $i;
     }
     for ($i = 20; $i < 50; $i += 10) {
         $values[$i] = $i;
     }
     for ($i = 50; $i < 250; $i += 50) {
         $values[$i] = $i;
     }
     for ($i = 250; $i < 1000; $i += 250) {
         $values[$i] = $i;
     }
     for ($i = 1000; $i < 5000; $i += 1000) {
         $values[$i] = $i;
     }
     for ($i = 5000; $i <= 10000; $i += 5000) {
         $values[$i] = $i;
     }
     $values[9999999] = 9999999;
     // Propose max input vars -10
     $max = Toolbox::get_max_input_vars();
     if ($max > 10) {
         $values[$max - 10] = $max - 10;
     }
     ksort($values);
     return self::showFromArray('glpilist_limit', $values, array('on_change' => $onchange, 'value' => $list_limit));
 }
Ejemplo n.º 6
0
 /**
  * show dropdown to select list limit
  *
  * @since version 0.83
  *
  * @param $onchange  String   optional, for ajax (default '')
  **/
 static function showListLimit($onchange = '')
 {
     global $CFG_GLPI;
     echo "<select name='glpilist_limit'";
     if ($onchange) {
         echo " onChange='{$onchange}'>";
     } else {
         echo ">";
     }
     if (isset($_SESSION['glpilist_limit'])) {
         $list_limit = $_SESSION['glpilist_limit'];
     } else {
         $list_limit = $CFG_GLPI['list_limit'];
     }
     $values = array();
     for ($i = 5; $i < 20; $i += 5) {
         $values[$i] = $i;
     }
     for ($i = 20; $i < 50; $i += 10) {
         $values[$i] = $i;
     }
     for ($i = 50; $i < 250; $i += 50) {
         $values[$i] = $i;
     }
     for ($i = 250; $i < 1000; $i += 250) {
         $values[$i] = $i;
     }
     for ($i = 1000; $i < 5000; $i += 1000) {
         $values[$i] = $i;
     }
     for ($i = 5000; $i <= 10000; $i += 5000) {
         $values[$i] = $i;
     }
     $values[9999999] = 9999999;
     // Propose max input vars -10
     $max = Toolbox::get_max_input_vars();
     if ($max > 10) {
         $values[$max - 10] = $max - 10;
     }
     ksort($values);
     foreach ($values as $val) {
         echo "<option value='{$val}' " . ($list_limit == $val ? " selected " : "") . ">{$val}</option>";
     }
     echo "</select>";
 }
 /**
  * Prints display pre import
  *
  * @param $type the type of device
  * @param $configID the ID of the supplier config
  * @param $start for pager display
  * @param $complete to see all device (already imported and not)
  * @return nothing (print out a table)
  *
  */
 static function seePreImport($params)
 {
     global $DB, $CFG_GLPI;
     // Default values of parameters
     $p['link'] = array();
     $p['field'] = array();
     $p['contains'] = array();
     $p['searchtype'] = array();
     $p['sort'] = '1';
     $p['order'] = 'ASC';
     $p['start'] = 0;
     $p['export_all'] = 0;
     $p['link2'] = '';
     $p['contains2'] = '';
     $p['field2'] = '';
     $p['itemtype2'] = '';
     $p['searchtype2'] = '';
     $p['itemtype'] = '';
     $p['manufacturers_id'] = '';
     $p['imported'] = '';
     foreach ($params as $key => $val) {
         $p[$key] = $val;
     }
     $globallinkto = self::getArrayUrlLink("field", $p['field']) . self::getArrayUrlLink("link", $p['link']) . self::getArrayUrlLink("contains", $p['contains']) . self::getArrayUrlLink("searchtype", $p['searchtype']) . self::getArrayUrlLink("field2", $p['field2']) . self::getArrayUrlLink("contains2", $p['contains2']) . self::getArrayUrlLink("searchtype2", $p['searchtype2']) . self::getArrayUrlLink("itemtype2", $p['itemtype2']) . self::getArrayUrlLink("link2", $p['link2']);
     $modeltable = "";
     $target = $CFG_GLPI["root_doc"] . "/plugins/manufacturersimports/front/import.php";
     if ($p['itemtype'] && $p['manufacturers_id']) {
         $config = new PluginManufacturersimportsConfig();
         $config->getFromDB($p['manufacturers_id']);
         $suppliername = $config->fields["name"];
         $supplierclass = "PluginManufacturersimports" . $suppliername;
         $supplier = new $supplierclass();
         $infocom = new Infocom();
         $canedit = Session::haveRight(static::$rightname, UPDATE) && $infocom->canUpdate();
         if (!$p['start']) {
             $p['start'] = 0;
         }
         $modeltable = getTableForItemType($p['itemtype'] . "Model");
         $modelfield = getForeignKeyFieldForTable(getTableForItemType($p['itemtype'] . "Model"));
         $item = new $p['itemtype']();
         $itemtable = getTableForItemType($p['itemtype']);
         $query = "SELECT `" . $itemtable . "`.`id`,\n                        `" . $itemtable . "`.`name`, \n                        `" . $itemtable . "`.`serial`,\n                        `" . $itemtable . "`.`entities_id`,\n                         `glpi_plugin_manufacturersimports_logs`.`import_status`,\n                          `glpi_plugin_manufacturersimports_logs`.`items_id`,\n                           `glpi_plugin_manufacturersimports_logs`.`itemtype`, \n                           `glpi_plugin_manufacturersimports_logs`.`documents_id`,\n                            `glpi_plugin_manufacturersimports_logs`.`date_import`, \n                            '" . $p['itemtype'] . "' AS type,\n                            `{$modeltable}`.`name` AS model_name\n                  FROM `" . $itemtable . "` ";
         //model device left join
         $query .= "LEFT JOIN `{$modeltable}` ON (`{$modeltable}`.`id` = `" . $itemtable . "`.`" . $modelfield . "`) ";
         $query .= " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemtable . "`.`entities_id`)";
         $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_configs` \n         ON (`glpi_plugin_manufacturersimports_configs`.`manufacturers_id` = `" . $itemtable . "`.`manufacturers_id`)";
         $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_logs` \n         ON (`glpi_plugin_manufacturersimports_logs`.`items_id` = `" . $itemtable . "`.`id` \n         AND `glpi_plugin_manufacturersimports_logs`.`itemtype` = '" . $p['itemtype'] . "')";
         $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_models` \n         ON (`glpi_plugin_manufacturersimports_models`.`items_id` = `" . $itemtable . "`.`id` \n         AND `glpi_plugin_manufacturersimports_models`.`itemtype` = '" . $p['itemtype'] . "')";
         //serial must be not empty
         $query .= " WHERE `" . $itemtable . "`.`is_deleted` = '0'\n          AND `" . $itemtable . "`.`is_template` = '0'\n          AND `glpi_plugin_manufacturersimports_configs`.`id` = '" . $p['manufacturers_id'] . "'\n          AND `" . $itemtable . "`.`serial` != '' ";
         //already imported
         if ($p['imported'] == self::IMPORTED) {
             $query .= " AND `import_status` != " . self::IMPORTED . "";
             //not imported
         } else {
             if ($p['imported'] == self::NOT_IMPORTED) {
                 $query .= " AND (`date_import` IS NULL OR `import_status` = " . self::IMPORTED . " ";
                 $query .= ") ";
             }
         }
         $entities = "";
         if ($config->isRecursive()) {
             $entities = getSonsOf('glpi_entities', $config->getEntityID());
         } else {
             $entities = $config->getEntityID();
         }
         $query .= "" . getEntitiesRestrictRequest(" AND", $itemtable, '', '', $item->maybeRecursive());
         //// 4 - ORDER
         $ORDER = " ORDER BY `entities_id`,`" . $itemtable . "`.`name` ";
         $toview = array("name" => 1);
         foreach ($toview as $key => $val) {
             if ($p['sort'] == $val) {
                 $ORDER = self::addOrderBy($p['itemtype'], $p['sort'], $p['order'], $key);
             }
         }
         $query .= $ORDER;
         $result = $DB->query($query);
         $numrows = $DB->numrows($result);
         if ($p['start'] < $numrows) {
             // Set display type for export if define
             $output_type = Search::HTML_OUTPUT;
             if (isset($_GET["display_type"])) {
                 $output_type = $_GET["display_type"];
             }
             $parameters = "itemtype=" . $p['itemtype'] . "&amp;manufacturers_id=" . $p['manufacturers_id'] . "&amp;imported=" . $p['imported'];
             $total = 0;
             if ($output_type == Search::HTML_OUTPUT) {
                 self::printPager($p['start'], $numrows, $target, $parameters, $p['itemtype']);
             }
             // Define begin and end var for loop
             // Search case
             $begin_display = $p['start'];
             $end_display = $p['start'] + $_SESSION["glpilist_limit"];
             // Export All case
             if (isset($_GET['export_all'])) {
                 $begin_display = 0;
                 $end_display = $numrows;
             }
             if (Session::isMultiEntitiesMode()) {
                 $colsup = 1;
             } else {
                 $colsup = 0;
             }
             //////////////////////HEADER///////////////
             if ($output_type == Search::HTML_OUTPUT) {
                 echo "<form method='post' name='massiveaction_form' id='massiveaction_form' action=\"../ajax/massiveaction.php\">";
             }
             //echo Search::displaySearchHeader($output_type,0); //table + div
             if ($canedit) {
                 $nbcols = 11 + $colsup;
             } else {
                 $nbcols = 10 + $colsup;
             }
             $LIST_LIMIT = $_SESSION['glpilist_limit'];
             $begin_display = $p['start'];
             $end_display = $p['start'] + $LIST_LIMIT;
             foreach ($toview as $key => $val) {
                 $linkto = '';
                 if (!isset($searchopt["PluginManufacturersimportsPreImport"][$val]['nosort']) || !$searchopt["PluginManufacturersimportsPreImport"][$val]['nosort']) {
                     $linkto = "{$target}?itemtype=" . $p['itemtype'] . "&amp;manufacturers_id=" . $p['manufacturers_id'] . "&amp;imported=" . $p['imported'] . "&amp;sort=" . $val . "&amp;order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&amp;start=" . $p['start'] . $globallinkto;
                 }
             }
             echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols);
             echo Search::showNewLine($output_type);
             $header_num = 1;
             echo Search::showHeaderItem($output_type, "", $header_num);
             echo Search::showHeaderItem($output_type, __('Name'), $header_num, $linkto, $p['sort'] == $val, $p['order']);
             if (Session::isMultiEntitiesMode()) {
                 echo Search::showHeaderItem($output_type, __('Entity'), $header_num);
             }
             echo Search::showHeaderItem($output_type, __('Serial number'), $header_num);
             echo $supplier->showItemTitle($output_type, $header_num);
             echo Search::showHeaderItem($output_type, __('Financial and administrative information'), $header_num);
             echo Search::showHeaderItem($output_type, __('Supplier attached', 'manufacturersimports'), $header_num);
             echo Search::showHeaderItem($output_type, __('New warranty attached', 'manufacturersimports'), $header_num);
             echo Search::showHeaderItem($output_type, _n('Link', 'Links', 1), $header_num);
             echo Search::showHeaderItem($output_type, _n('Status', 'Statuses', 1), $header_num);
             echo $supplier->showDocTitle($output_type, $header_num);
             // End Line for column headers
             echo Search::showEndLine($output_type);
             $i = $p['start'];
             if (isset($_GET['export_all'])) {
                 $i = 0;
             }
             if ($i > 0) {
                 $DB->data_seek($result, $i);
             }
             $row_num = 1;
             while ($i < $numrows && $i < $end_display) {
                 $i++;
                 $item_num = 1;
                 $line = $DB->fetch_array($result);
                 $compSerial = $line['serial'];
                 $compId = $line['id'];
                 $model = $line["model_name"];
                 if (!$line["itemtype"]) {
                     $line["itemtype"] = $p['itemtype'];
                 }
                 self::showImport($row_num, $item_num, $line, $output_type, $p['manufacturers_id'], $line["import_status"], $p['imported']);
                 //1.show already imported items && import_status not failed
                 if ($p['imported'] == 1) {
                     $total += 1;
                 }
             }
             echo "<tr class='tab_bg_1'><td colspan='" . ($canedit ? 11 + $colsup : 10 + $colsup) . "'>";
             echo sprintf(__('Total number of devices to import %s', 'manufacturersimports'), $total);
             echo "</td></tr>";
             // Close Table
             $title = "";
             // Create title
             if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) {
                 $title .= PluginManufacturersimportsPreImport::getTypeName(2) . " " . $suppliername;
             }
             echo Search::showFooter($output_type, $title);
             //massive action
             if ($canedit && $output_type == Search::HTML_OUTPUT) {
                 if ($_SESSION['glpilist_limit'] < Toolbox::get_max_input_vars()) {
                     Html::openArrowMassives("massiveaction_form", false);
                     self::dropdownMassiveAction($compId, $p['itemtype'], $p['manufacturers_id'], $p['start'], $p['imported']);
                     Html::closeArrowMassives(array());
                 } else {
                     echo "<table class='tab_cadre' width='80%'><tr class='tab_bg_1'>" . "<td><span class='b'>";
                     echo __('Selection too large, massive action disabled.') . "</span>";
                     if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
                         echo "<br>" . __('To increase the limit: change max_input_vars or suhosin.post.max_vars in php configuration.');
                     }
                     echo "</td></tr></table>";
                 }
                 Html::closeForm();
             } else {
                 echo "</table>";
                 echo "</div>";
             }
             echo "<br>";
             if ($output_type == Search::HTML_OUTPUT) {
                 self::printPager($p['start'], $numrows, $target, $parameters, $p['itemtype']);
             }
         } else {
             echo "<div align='center'><b>" . __('No device finded', 'manufacturersimports') . "</b></div>";
         }
     }
 }