Exemplo n.º 1
0
 /**
  * Do the specific massive actions
  *
  * @since version 0.84
  *
  * @param $input array of input datas
  *
  * @return an array of results (nbok, nbko, nbnoright counts)
  **/
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     $criteria = new PluginTypologyTypologyCriteria();
     $definition = new PluginTypologyTypologyCriteriaDefinition();
     switch ($input['action']) {
         case "Transfert":
             if ($input['itemtype'] == 'PluginTypologyTypology') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $this->getFromDB($key);
                         $restrict = "`plugin_typology_typologies_id` = '" . $key . "'";
                         $crits = getAllDatasFromTable("glpi_plugin_typology_typologycriterias", $restrict);
                         if (!empty($crits)) {
                             foreach ($crits as $crit) {
                                 $criteria->getFromDB($crit["id"]);
                                 $condition = "`plugin_typology_typologycriterias_id` = '" . $crit["id"] . "'";
                                 $defs = getAllDatasFromTable("glpi_plugin_typology_typologycriteriadefinitions", $condition);
                                 if (!empty($defs)) {
                                     foreach ($defs as $def) {
                                         $definition->getFromDB($def["id"]);
                                         unset($values);
                                         $values["id"] = $def["id"];
                                         $values["entities_id"] = $input['entities_id'];
                                         $definition->update($values);
                                     }
                                 }
                                 unset($values);
                                 $values["id"] = $crit["id"];
                                 $values["entities_id"] = $input['entities_id'];
                                 $criteria->update($values);
                             }
                         }
                         unset($values);
                         $values["id"] = $key;
                         $values["entities_id"] = $input['entities_id'];
                         if ($this->update($values)) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         case "Duplicate":
             if ($input['itemtype'] == 'PluginTypologyTypology') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $this->getFromDB($key);
                         $restrict = "`plugin_typology_typologies_id` = '" . $key . "'";
                         $crits = getAllDatasFromTable("glpi_plugin_typology_typologycriterias", $restrict);
                         unset($this->fields["id"]);
                         $this->fields["name"] = addslashes($this->fields["name"] . " Copy");
                         $this->fields["comment"] = addslashes($this->fields["comment"]);
                         $this->fields["notepad"] = addslashes($this->fields["notepad"]);
                         $newIDtypo = $this->add($this->fields);
                         if ($newIDtypo) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                         if (!empty($crits)) {
                             foreach ($crits as $crit) {
                                 $criteria->getFromDB($crit["id"]);
                                 $condition = "`plugin_typology_typologycriterias_id` = '" . $crit["id"] . "'";
                                 $defs = getAllDatasFromTable("glpi_plugin_typology_typologycriteriadefinitions", $condition);
                                 unset($criteria->fields["id"]);
                                 $criteria->fields["name"] = addslashes($criteria->fields["name"]);
                                 $criteria->fields["plugin_typology_typologies_id"] = $newIDtypo;
                                 $criteria->fields["itemtype"] = addslashes($criteria->fields["itemtype"]);
                                 $newIDcrit = $criteria->add($criteria->fields);
                                 if (!empty($defs)) {
                                     foreach ($defs as $def) {
                                         $definition->getFromDB($def["id"]);
                                         unset($definition->fields["id"]);
                                         $definition->fields["plugin_typology_typologycriterias_id"] = $newIDcrit;
                                         $definition->fields["field"] = addslashes($definition->fields["field"]);
                                         $definition->fields["action_type"] = addslashes($definition->fields["action_type"]);
                                         $definition->fields["value"] = addslashes($definition->fields["value"]);
                                         $definition->add($definition->fields);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }
Exemplo n.º 2
0
 /**
  * See typology errors
  *
  * @param $error list
  *
  * @return nothing
  **/
 static function displayErrors($error, $withlink = true)
 {
     global $CFG_GLPI;
     $items = explode(",", $error);
     $i = 0;
     $display = "";
     if ($items[0] != NULL) {
         foreach ($items as $critID) {
             $crit = new PluginTypologyTypologyCriteria();
             if ($crit->getFromDB($critID)) {
                 if ($i == 0) {
                     $display .= " ";
                     $i++;
                 } else {
                     $display .= ", ";
                 }
                 $itemtype = $crit->fields["itemtype"];
                 $criteria = "";
                 if ($withlink) {
                     $criteria = "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/typology/front/typologycriteria.form.php?id=" . $crit->fields["id"] . "' target='_blank'>";
                 }
                 $criteria .= $crit->fields["name"];
                 if ($_SESSION["glpiis_ids_visible"] || empty($crit->fields["name"])) {
                     $criteria .= " (" . $crit->fields["id"] . ")";
                 }
                 if ($withlink) {
                     $criteria .= "</a>";
                 }
                 $criteria .= " (" . $itemtype::getTypeName(0) . ")";
                 $display .= $criteria;
             }
         }
     }
     return $display;
 }
 /**
  * Display all values available depending on field selected
  *
  * @static
  * @param $options
  * @param int $value
  */
 static function dropdownValues($options, $value = 0)
 {
     $itemtype = $options['itemtype'];
     $typocrit_id = $options['typocrit_id'];
     $field = $options['field'];
     $action = $options['action_type'];
     $item = new $itemtype();
     $test = explode(";", $field);
     $itemField = $test[0];
     $itemTable = $test[1];
     $itemDataType = $test[2];
     $typoCritDef = new PluginTypologyTypologyCriteriaDefinition();
     $typoCritDef->fields['plugin_typology_typologycriterias_id'] = $typocrit_id;
     $typoCritDef->fields['field'] = $field;
     $typoCrit = new PluginTypologyTypologyCriteria();
     $typoCrit->getFromDB($typocrit_id);
     if ($action == 'contains' || $action == 'notcontains' || $action == 'regex_match' || $action == 'regex_not_match') {
         Html::autocompletionTextField($typoCritDef, "value");
     } else {
         switch ($itemDataType) {
             case "bool":
                 Dropdown::showYesNo('value');
                 break;
             case "number":
                 Html::autocompletionTextField($typoCritDef, "value");
                 if ($itemField == 'size') {
                     echo "\"";
                 }
                 break;
             case "string":
                 Html::autocompletionTextField($typoCritDef, "value");
                 break;
             case "text":
                 Html::autocompletionTextField($typoCritDef, "value");
                 if ($itemtype == 'DeviceHardDrive') {
                     echo " " . __('Mio');
                 } else {
                     if ($itemField == 'frequence') {
                         echo " " . __('MHz');
                     } else {
                         if ($itemtype == 'DeviceMemory' && $itemField == 'specif_default') {
                             echo " " . __('Mio');
                         } else {
                             if ($itemtype == 'DeviceProcessor' && $itemField == 'specif_default') {
                                 echo " " . __('MHz');
                             }
                         }
                     }
                 }
                 break;
                 //            case "ip" :
                 //               Html::autocompletionTextField($typoCritDef, "value");
                 //               break;
             //            case "ip" :
             //               Html::autocompletionTextField($typoCritDef, "value");
             //               break;
             default:
                 switch ($itemTable) {
                     case "glpi_users":
                         User::dropdown(array('right' => 'all', 'name' => 'value'));
                         break;
                     case "glpi_softwareversions":
                         Software::dropdownSoftwareToInstall("value", $typoCrit->fields['entities_id']);
                         break;
                     default:
                         $itemclass = getItemTypeForTable($itemTable);
                         Dropdown::show($itemclass, array('name' => 'value', 'entity' => $typoCrit->fields['entities_id']));
                         break;
                 }
                 break;
         }
     }
     echo "</span></td>";
 }