sanitize() public static method

Sanitize received values
public static sanitize ( array $array ) : array
$array array
return array
Esempio n. 1
0
 /**
  * update an object to GLPI
  *
  * @param $itemtype     string    itemtype (class) of object
  * @param $params       array     with theses options :
  *    - 'input' : Array of objects with fields of itemtype to be updated.
  *                Mandatory.
  *                You must provide in each object a key named 'id' to identify item to update.
  *
  * @return   array of boolean
  **/
 protected function updateItems($itemtype, $params = array())
 {
     $this->initEndpoint();
     $input = isset($params['input']) ? $params["input"] : null;
     $item = new $itemtype();
     $response = "";
     if (is_object($input)) {
         $input = array($input);
         $isMultiple = false;
     }
     $isMultiple = true;
     if (is_array($input)) {
         $idCollection = array();
         $failed = 0;
         foreach ($input as $object) {
             if (isset($object->id)) {
                 if (!$item->getFromDB($object->id)) {
                     $failed++;
                     $idCollection[] = array($object->id => false, 'message' => __("Item not found"));
                     continue;
                 }
                 //check rights
                 if (!$item->can($object->id, UPDATE)) {
                     $failed++;
                     $idCollection[] = array($object->id => false, 'message' => __("You don't have permission to perform this action."));
                 } else {
                     //update item
                     $object = Toolbox::sanitize((array) $object);
                     $update_return = $item->update($object);
                     if ($update_return === false) {
                         $failed++;
                     }
                     $idCollection[] = array($item->fields["id"] => $update_return, 'message' => $this->getGlpiLastMessage());
                 }
             }
         }
         if ($isMultiple) {
             if ($failed == count($input)) {
                 $this->returnError($idCollection, 400, "ERROR_GLPI_UPDATE", false);
             } else {
                 if ($failed > 0) {
                     $this->returnError($idCollection, 207, "ERROR_GLPI_PARTIAL_UPDATE", false);
                 }
             }
         } else {
             if ($failed > 0) {
                 $this->returnError($idCollection[0]['message'], 400, "ERROR_GLPI_UPDATE", false);
             } else {
                 return $idCollection;
                 // Return collection, even if the request affects a single item
             }
         }
         return $idCollection;
     } else {
         $this->messageBadArrayError();
     }
 }
Esempio n. 2
0
}
// Security system
if (isset($_POST)) {
    if (isset($_POST['_glpi_simple_form'])) {
        $_POST = array_map('urldecode', $_POST);
    }
    $_POST = Toolbox::sanitize($_POST);
}
if (isset($_GET)) {
    $_GET = Toolbox::sanitize($_GET);
}
if (isset($_REQUEST)) {
    $_REQUEST = Toolbox::sanitize($_REQUEST);
}
if (isset($_FILES)) {
    $_FILES = Toolbox::sanitize($_FILES);
}
// Mark if Header is loaded or not :
$HEADER_LOADED = false;
$FOOTER_LOADED = false;
if (isset($AJAX_INCLUDE)) {
    $HEADER_LOADED = true;
}
/* On startup, register all plugins configured for use. */
if (!isset($AJAX_INCLUDE) && !isset($PLUGINS_INCLUDED)) {
    // PLugin already included
    $PLUGINS_INCLUDED = 1;
    $LOADED_PLUGINS = array();
    $plugin = new Plugin();
    if (!isset($_SESSION["glpi_plugins"])) {
        $plugin->init();