Ejemplo n.º 1
0
 /**
  * Actions done after the ADD of a item in the database
  *
  * @param $item : the item added
  *
  * @return nothing
  **/
 static function addItem($item)
 {
     $values = array();
     $plugin = new Plugin();
     $typo_item = new self();
     if ($plugin->isActivated("typology")) {
         $ruleCollection = new PluginTypologyRuleTypologyCollection($item->fields['entities_id']);
         $fields = array();
         //si massive action ajouter tous les champs de la rules
         if (!isset($item->input['_update'])) {
             $rule = new PluginTypologyRuleTypology();
             foreach ($rule->getCriterias() as $ID => $crit) {
                 if (!isset($item->input[$ID])) {
                     if (isset($item->fields[$ID])) {
                         $item->input[$ID] = $item->fields[$ID];
                     }
                 }
             }
         }
         $fields = $ruleCollection->processAllRules($item->input, $fields, array());
         //Store rule that matched
         if (isset($fields['_ruleid'])) {
             $values = array('plugin_typology_typologies_id' => $fields['plugin_typology_typologies_id'], 'items_id' => $item->fields['id'], 'itemtype' => $item->getType());
             //verifie si tu as deja une typo
             $ID = self::checkIfExist($values, false);
             //si pas de typo, ajout
             if ($ID == 0) {
                 $values['_ruleid'] = $fields['_ruleid'];
                 $self = new self();
                 $self->add($values);
                 self::addLog($values, self::LOG_ADD);
             } else {
                 //si typo, return ID typo_item
                 $values['id'] = $ID;
             }
         } else {
             //math no rules
             $values = array('items_id' => $item->fields['id'], 'itemtype' => $item->getType());
             $ID = self::checkIfExist($values, false);
             //si typo, delete
             if ($ID != '0') {
                 $values['id'] = $ID;
                 $self = new self();
                 $self->getFromDB($ID);
                 $values['plugin_typology_typologies_id'] = $self->fields['plugin_typology_typologies_id'];
                 $self->delete($values);
                 self::addLog($values, self::LOG_DELETE);
                 return false;
             }
         }
         return $values;
     }
 }
Ejemplo n.º 2
0
 if (isset($_POST["purge"])) {
     $typo->check($_POST['id'], 'w');
     $typo->delete($_POST, 1);
     $typo->redirectToList();
 } else {
     if (isset($_POST["restore"])) {
         $typo->check($_POST["id"], 'w');
         $typo->restore($_POST);
         $typo->redirectToList();
     } else {
         if (isset($_POST["add_item"])) {
             if (!empty($_POST['itemtype'])) {
                 $input = array('plugin_typology_typologies_id' => $_POST['plugin_typology_typologies_id'], 'items_id' => $_POST['items_id'], 'itemtype' => $_POST['itemtype']);
                 $item = new $_POST['itemtype']();
                 if ($item->getFromDB($_POST['items_id'])) {
                     $ruleCollection = new PluginTypologyRuleTypologyCollection($item->fields['entities_id']);
                     $fields = array();
                     $item->input = $_POST['plugin_typology_typologies_id'];
                     $fields = $ruleCollection->processAllRules($item->fields, $fields, array());
                     //Store rule that matched
                     if (isset($fields['_ruleid'])) {
                         if ($input['plugin_typology_typologies_id'] != $fields['plugin_typology_typologies_id']) {
                             $message = __('Element not match with the rule for assigning the typology:', 'typology') . " " . Dropdown::getDropdownName('glpi_plugin_typology_typologies', $input['plugin_typology_typologies_id']);
                             Session::addMessageAfterRedirect($message, ERROR, true);
                         } else {
                             $typo_item->add($input);
                             $values = array('plugin_typology_typologies_id' => $input['plugin_typology_typologies_id'], 'items_id' => $input['items_id'], 'itemtype' => $input['itemtype']);
                             PluginTypologyTypology_Item::addLog($values, PluginTypologyTypology_Item::LOG_ADD);
                         }
                     } else {
                         $message = __('Element not match with rules for assigning a typology', 'typology');
Ejemplo n.º 3
0
function plugin_typology_MassiveActionsProcess($data)
{
    $typo = new PluginTypologyTypology();
    $typo_item = new PluginTypologyTypology_Item();
    $criteria = new PluginTypologyTypologyCriteria();
    $definition = new PluginTypologyTypologyCriteriaDefinition();
    switch ($data['action']) {
        //      case "plugin_typology_transfert":
        //         if ($data['itemtype'] == 'PluginTypologyTypology') {
        //            foreach ($data["item"] as $key => $val) {
        //               if ($val == 1) {
        //                  $typo->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"] = $data['entities_id'];
        //                              $definition->update($values);
        //                           }
        //                        }
        //                        unset($values);
        //                        $values["id"] = $crit["id"];
        //                        $values["entities_id"] = $data['entities_id'];
        //                        $criteria->update($values);
        //                     }
        //                  }
        //                  unset($values);
        //                  $values["id"] = $key;
        //                  $values["entities_id"] = $data['entities_id'];
        //                  $typo->update($values);
        //               }
        //            }
        //         }
        //         break;
        //      case "plugin_typology_duplicate":
        //         if ($data['itemtype'] == 'PluginTypologyTypology') {
        //            foreach ($data["item"] as $key => $val) {
        //               if ($val == 1) {
        //
        //                  $typo->getFromDB($key);
        //
        //                  $restrict = "`plugin_typology_typologies_id` = '".$key."'";
        //                  $crits = getAllDatasFromTable("glpi_plugin_typology_typologycriterias", $restrict);
        //
        //                  unset($typo->fields["id"]);
        //                  $typo->fields["name"]=addslashes($typo->fields["name"]." Copy");
        //                  $typo->fields["comment"]=addslashes($typo->fields["comment"]);
        //                  $typo->fields["notepad"]=addslashes($typo->fields["notepad"]);
        //                  $newIDtypo=$typo->add($typo->fields);
        //
        //                  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;
        //add item to a typo
        case "plugin_typology_add_item":
            foreach ($data["item"] as $key => $val) {
                if ($val == 1) {
                    $input = array('plugin_typology_typologies_id' => $data['plugin_typology_typologies_id'], 'items_id' => $key, 'itemtype' => $data['itemtype']);
                    $item = new $data['itemtype']();
                    if ($item->getFromDB($key)) {
                        $ruleCollection = new PluginTypologyRuleTypologyCollection($item->fields['entities_id']);
                        $fields = array();
                        $item->input = $input['plugin_typology_typologies_id'];
                        $fields = $ruleCollection->processAllRules($item->fields, $fields, array());
                        //Store rule that matched
                        if (isset($fields['_ruleid'])) {
                            if ($input['plugin_typology_typologies_id'] != $fields['plugin_typology_typologies_id']) {
                                $message = __('Element not match with the rule for assigning the typology:', 'typology') . " " . Dropdown::getDropdownName('glpi_plugin_typology_typologies', $input['plugin_typology_typologies_id']);
                                Session::addMessageAfterRedirect($message, ERROR, true);
                            } else {
                                $typo_item->add($input);
                            }
                        } else {
                            $message = __('Element not match with rules for assigning a typology', 'typology');
                            Session::addMessageAfterRedirect($message, ERROR, true);
                        }
                    }
                }
            }
            break;
            //get out an item from a store
        //get out an item from a store
        case "plugin_typology_del_item":
            foreach ($data["item"] as $key => $val) {
                if ($val == 1) {
                    $input = array('items_id' => $key, 'itemtype' => $data['itemtype']);
                    $restrict = "`items_id` = '" . $key . "'\n                        AND `itemtype` = '" . $data['itemtype'] . "'";
                    $items = getAllDatasFromTable("glpi_plugin_typology_typologies_items", $restrict);
                    if (!empty($items)) {
                        foreach ($items as $item) {
                            $input = array('id' => $item["id"], 'delete' => 'delete');
                        }
                        $typo_item->delete($input);
                    }
                }
            }
            break;
            //add item to a typo
        //add item to a typo
        case "plugin_typology_compute_item":
            foreach ($data["item"] as $key => $val) {
                if ($val == 1) {
                    $restrict = "`items_id` = '" . $key . "'\n                        AND `itemtype` = '" . $data['itemtype'] . "'";
                    $items = getAllDatasFromTable("glpi_plugin_typology_typologies_items", $restrict);
                    if (!empty($items)) {
                        foreach ($items as $item) {
                            $values = array('id' => $item["id"], 'plugin_typology_typologies_id' => $item['plugin_typology_typologies_id'], 'items_id' => $key, 'itemtype' => $data['itemtype']);
                            $input = PluginTypologyTypology_Item::checkValidated($values);
                            $typo_item->update($input);
                        }
                    }
                }
            }
            break;
    }
}