Esempio 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);
     $typo_item = new PluginTypologyTypology_Item();
     switch ($input['action']) {
         case "delete_item":
             if ($input['itemtype'] == 'PluginTypologyTypology_Item') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val != 0) {
                         $typo_item->getFromDB($key);
                         if ($typo_item->delete(array('id' => $key))) {
                             $values = array('plugin_typology_typologies_id' => $input['plugin_typology_typologies_id'], 'items_id' => $typo_item->fields['items_id'], 'itemtype' => $typo_item->fields['itemtype']);
                             PluginTypologyTypology_Item::addLog($values, PluginTypologyTypology_Item::LOG_DELETE);
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         case "update_allitem":
             if ($input['itemtype'] == 'PluginTypologyTypology_Item') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val != 0) {
                         $typo_item->getFromDB($key);
                         $result = PluginTypologyTypology_Item::checkValidated(array('items_id' => $typo_item->fields['items_id'], 'plugin_typology_typologies_id' => $typo_item->fields['plugin_typology_typologies_id'], 'id' => $typo_item->fields['id']));
                         if ($typo_item->update($result)) {
                             $values = array('plugin_typology_typologies_id' => $typo_item->fields['plugin_typology_typologies_id'], 'items_id' => $typo_item->fields['items_id'], 'itemtype' => $typo_item->fields['itemtype']);
                             PluginTypologyTypology_Item::addLog($values, PluginTypologyTypology_Item::LOG_UPDATE);
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }
Esempio n. 2
0
         }
     }
     Html::back();
 } else {
     if (isset($_POST["update_item"])) {
         if (!empty($_POST['itemtype'])) {
             $input = PluginTypologyTypology_Item::checkValidated($_POST);
             $typo_item->update($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_UPDATE);
         }
         Html::back();
     } else {
         if (isset($_POST["delete_item"])) {
             if (!empty($_POST['itemtype'])) {
                 $typo_item->delete($_POST);
                 $values = array('plugin_typology_typologies_id' => $_POST['plugin_typology_typologies_id'], 'items_id' => $_POST['items_id'], 'itemtype' => $_POST['itemtype']);
                 PluginTypologyTypology_Item::addLog($values, PluginTypologyTypology_Item::LOG_DELETE);
             } else {
                 foreach ($_POST["item"] as $key => $val) {
                     if ($val == 1) {
                         $typo_item->delete(array('id' => $key));
                     }
                 }
             }
             Html::back();
         } else {
             $typo->checkGlobal("r");
             Html::header(PluginTypologyTypology::getTypeName(2), '', "plugins", "typology");
             $typo->showForm($_GET["id"]);
             Html::footer();
Esempio 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;
    }
}