$criteria->check($_POST['id'], 'w');
     $criteria->delete($_POST);
     $criteria->redirectToList();
     //   }
     Html::back();
 } else {
     if (isset($_POST["add_action"])) {
         $criteria->check($_POST['plugin_typology_typologycriterias_id'], 'w');
         $definition = new PluginTypologyTypologyCriteriaDefinition();
         $definition->add($_POST);
         // Mise à jour de l'heure de modification pour le critère
         $criteria->update(array('id' => $_POST['plugin_typology_typologycriterias_id'], 'date_mod' => $_SESSION['glpi_currenttime']));
         Html::back();
     } else {
         if (isset($_POST["delete_action"])) {
             $definition = new PluginTypologyTypologyCriteriaDefinition();
             if (isset($_POST["item"]) && count($_POST["item"])) {
                 foreach ($_POST["item"] as $key => $val) {
                     if ($val == 1) {
                         if ($definition->can($key, 'w')) {
                             $definition->delete(array('id' => $key));
                         }
                     }
                 }
             } else {
                 if (isset($_POST['id'])) {
                     $definition->check($_POST['id'], 'w');
                     $definition->delete($_POST);
                 }
             }
             $criteria->check($_POST['plugin_typology_typologycriterias_id'], 'w');
Esempio n. 2
0
 /**
  * Display a management console in order to see the difference between the typology linkked
  * and data from each computer
  *
  * @param $ID : id item
  *
  * @return Nothing (displays)
  **/
 static function showManagementConsole($ID, $typo_ID, $display = true)
 {
     $notOK = array();
     //image type
     $options['seeResult'] = 1;
     $options['seeItemtype'] = 1;
     $restrict = "`glpi_plugin_typology_typologycriterias`.`plugin_typology_typologies_id` = '{$typo_ID}'\n                     AND `glpi_plugin_typology_typologycriterias`.`is_active` = 1\n                     ORDER BY `glpi_plugin_typology_typologycriterias`.`itemtype`";
     $criterias = getAllDatasFromTable('glpi_plugin_typology_typologycriterias', $restrict);
     //typology criteria exist -> managmentconsole will be not empty
     if (!empty($criterias)) {
         if ($display) {
             echo "<div class='center'><table class='tab_cadre_fixe'>";
             //title
             echo "<tr><th colspan='7'>";
             _e('Management console', 'typology');
             echo "</th></tr>";
             //column name
             echo "<tr>";
             echo "<th rowspan='2'>" . __('Item') . "</th>";
             echo "<th colspan='2' rowspan='2'>" . _n('Field', 'Fields', 2) . "</th>";
             echo "<th rowspan='2'>" . __('Comparison', 'typology') . "</th>";
             echo "<th colspan='2'>" . __('Detail of the assigned typology', 'typology') . "</th>";
             echo "<th>" . __('Detail of the encountered configuration', 'typology') . "</th>";
             echo "</tr>";
             //sub-column name
             echo "<tr>";
             echo "<th class='center b'>" . __('Logical operator') . "</th>";
             echo "<th class='center b'>" . __('Waiting value', 'typology') . "</th>";
             echo "<th class='center b'>" . __('Real value', 'typology') . "</th>";
             echo "</tr>";
         }
         foreach ($criterias as $criteria) {
             $tabCrit[$criteria['itemtype']][] = $criteria['id'];
         }
         foreach ($tabCrit as $itemtype => $tabCritID) {
             $datas = PluginTypologyTypologyCriteriaDefinition::getConsoleData($tabCritID, $ID, $itemtype, $display);
             if (!$display) {
                 foreach ($datas[$itemtype] as $k => $critId) {
                     if ($critId['result'] == 'not_ok') {
                         $notOK[] = $k;
                     }
                 }
             } else {
                 foreach ($datas as $itemtype => $allCrit) {
                     if (!empty($allCrit)) {
                         foreach ($allCrit as $key1 => $allDef) {
                             if (!empty($allDef)) {
                                 foreach ($allDef as $key2 => $def) {
                                     if (!empty($def)) {
                                         echo "<tr class='tab_bg_1'>";
                                         $def['itemtype'] = $itemtype;
                                         PluginTypologyTypologyCriteriaDefinition::showMinimalDefinitionForm($def, $options);
                                         echo "</tr>";
                                     }
                                 }
                             }
                             echo "<tr>";
                             echo "<th colspan='7' class='center b'></th>";
                             echo "</tr>";
                         }
                     }
                 }
             }
         }
         if ($display) {
             echo "</table></div>";
         }
         return $notOK;
     }
 }
 /**
  * Display the typologycriteria form, typology side
  *
  * @param PluginTypologyTypology $typo
  * @param bool $showAdd
  */
 public static function showForTypology(PluginTypologyTypology $typo, $showAdd = true)
 {
     $ID = $typo->getField('id');
     $crit = new PluginTypologyTypologyCriteria();
     $canedit = $typo->can($ID, 'w');
     $rand = mt_rand();
     if ($canedit) {
         if ($showAdd) {
             echo "<div class='center first-bloc'>";
             echo "<form name='typocrit_form{$rand}' id='typocrit_form{$rand}' method='post' action='";
             echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'><th colspan='7'>" . __('Add a criterion', 'typology') . "</tr>";
             echo "<tr class='tab_bg_2'><td class='center'>" . __('Name') . "</td>";
             echo "<input type='hidden' name='plugin_typology_typologies_id' value='{$ID}'>";
             echo "<input type='hidden' name='entities_id' value='" . $typo->getEntityID() . "'>";
             echo "<input type='hidden' name='is_recursive' value='" . $typo->isRecursive() . "'>";
             echo "</td><td class='center'>";
             Html::autocompletionTextField($crit, "name");
             echo "</td><td class='center'>" . __('Item') . "</td><td class='center'>";
             PluginTypologyTypologyCriteria::dropdownItemtype();
             echo "</td><td>" . __('Logical operator') . "</td><td>";
             Dropdown::showFromArray('link', array(0 => __('and'), 1 => __('or')));
             echo "</td><td>";
             echo "<input type='hidden' name='is_active' value='1'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
             echo "</td></tr>";
             echo "</table>";
             Html::closeForm();
             echo "</div>";
         }
         //         echo "<form name='massiveaction_form$rand' id='massiveaction_form$rand' method='post'
         //                     action=\"../ajax/massiveaction.php\">";
         $restrict = "`plugin_typology_typologies_id` = '{$ID}'\n                     ORDER BY `itemtype`";
         $criterias = getAllDatasFromTable('glpi_plugin_typology_typologycriterias', $restrict);
         Session::initNavigateListItems("PluginTypologyTypologyCriteria", PluginTypologyTypology::getTypeName(1) . " = " . $typo->getName());
         if (!empty($criterias)) {
             echo "<div class='spaced'>";
             if ($canedit) {
                 Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
                 $massiveactionparams = array();
                 Html::showMassiveActions(__CLASS__, $massiveactionparams);
             }
             echo "<table class='tab_cadre_fixe'>";
             if ($canedit) {
                 echo "<tr>";
                 echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
                 echo "<th colspan=5>" . __('Criteria\'s list', 'typology') . "</th>";
                 echo "</tr>";
             }
             foreach ($criterias as $criteria) {
                 Session::addToNavigateListItems("PluginTypologyTypologyCriteria", $criteria["id"]);
                 if ($showAdd) {
                     $colspan = 6;
                 } else {
                     $colspan = 5;
                 }
                 if ($showAdd) {
                     $type = 'tab_cadre_fixehov';
                 } else {
                     $type = 'tab_cadre';
                 }
                 echo "<div class='center'><table class={$type}>";
                 if ($showAdd) {
                     echo "<tr><th colspan={$colspan}>" . PluginTypologyTypologyCriteria::getTypeName(1) . "</th>";
                 } else {
                     echo "<tr><th colspan={$colspan}>" . __('Detail of the assigned typology', 'typology') . "</th>";
                 }
                 echo "</tr>";
                 echo "<tr class='tab_bg_2'>";
                 if ($showAdd) {
                     echo "<th colspan='2'>" . __('Name') . "</th>";
                 }
                 echo "<th class='center b'>" . __('Active') . "</th>";
                 echo "<th class='center b'>" . __('Item') . "</th>";
                 echo "<th class='center b'>" . __('Logical operator') . "</th>";
                 echo "<th class='center b'>" . PluginTypologyTypologyCriteriaDefinition::getTypeName(2) . "</th>";
                 echo "</tr>";
                 echo "<tr class='tab_bg_2'>";
                 if ($canedit && $showAdd) {
                     echo "<td width='10'>";
                     //                  echo "<input type='checkbox' name='item[".$criteria["id"]."]' value='1'>";
                     Html::showMassiveActionCheckBox(__CLASS__, $criteria["id"]);
                     echo "</td>";
                 }
                 echo "<td width='10%'>";
                 if ($canedit) {
                     echo "<a href='" . Toolbox::getItemTypeFormURL('PluginTypologyTypologyCriteria') . "?id=" . $criteria["id"] . "'>";
                 }
                 echo $criteria["name"];
                 if (empty($criteria["name"])) {
                     echo "(" . $criteria['id'] . ")";
                 }
                 if ($canedit) {
                     echo "</a>";
                 }
                 echo "</td>";
                 echo "<td width='10%' align='center'>";
                 echo Dropdown::getYesNo($criteria['is_active']);
                 echo "</td>";
                 $item = new $criteria['itemtype']();
                 echo "<td width='10%'>" . $item::getTypeName(0) . "</td>";
                 echo "<td width='10%' align='center'>";
                 if ($criteria['link'] == 0) {
                     echo __('and');
                 } else {
                     if ($criteria['link'] == 1) {
                         echo __('or');
                     }
                 }
                 echo "</td><td>";
                 $condition = "`glpi_plugin_typology_typologycriteriadefinitions`.`plugin_typology_typologycriterias_id` " . " = '" . $criteria['id'] . "' ORDER BY `glpi_plugin_typology_typologycriteriadefinitions`.`id`";
                 $definitions = getAllDatasFromTable('glpi_plugin_typology_typologycriteriadefinitions', $condition);
                 if (!empty($definitions)) {
                     echo "<table class='tab_cadre' width='100%'>";
                     echo "<tr>";
                     echo "<th class='center b' width='33%'>" . _n('Field', 'Fields', 2) . "</th>";
                     echo "<th class='center b' width='33%'>" . __('Logical operator') . "</th>";
                     echo "<th class='center b'>" . __('Value') . "</th>";
                     echo "</tr>";
                     foreach ($definitions as $definition) {
                         echo "<tr>";
                         $definition['itemtype'] = $criteria['itemtype'];
                         PluginTypologyTypologyCriteriaDefinition::showMinimalDefinitionForm($definition);
                         echo "</tr>";
                     }
                     echo "</table>";
                 }
                 echo "</td></tr>";
             }
             echo "</table>";
             if ($canedit) {
                 $paramsma['ontop'] = false;
                 Html::showMassiveActions(__CLASS__, $paramsma);
                 Html::closeForm();
             }
             echo "</div>";
             //            if ($showAdd){
             //               Html::openArrowMassives("massiveaction_form$rand",true);
             //               self::dropdownMassiveAction($rand);
             //               Html::closeArrowMassives(array());
             //            }
         }
     }
     //      Html::closeForm();
 }
Esempio n. 4
0
 https://forge.indepnet.net/projects/typology
 -------------------------------------------------------------------------

 LICENSE

 This file is part of Typology.

 Typology is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 Typology is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Typology. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
*/
// Direct access to file
if (strpos($_SERVER['PHP_SELF'], "dropdownAction.php")) {
    include '../../../inc/includes.php';
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
//Display list of logical operator depending on field
PluginTypologyTypologyCriteriaDefinition::dropdownSelect($_POST['itemtype'], $_POST['typocrit_id'], $_POST['field']);
Esempio n. 5
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;
 }
 /**
  * Display the add Definition form
  *
  * @param $typocrit_id typocrit ID
  **/
 static function showForCriteria(PluginTypologyTypologyCriteria $typocrit)
 {
     global $DB;
     $typocrit_id = $typocrit->getField('id');
     $query = "SELECT `glpi_plugin_typology_typologycriteriadefinitions`.`id`,\n                        `glpi_plugin_typology_typologycriterias`.`itemtype`,\n                        `glpi_plugin_typology_typologycriterias`.`link`,\n                       `glpi_plugin_typology_typologycriteriadefinitions`.`field`,\n                       `glpi_plugin_typology_typologycriteriadefinitions`.`action_type`,\n                       `glpi_plugin_typology_typologycriteriadefinitions`.`value`,\n                       `glpi_plugin_typology_typologycriteriadefinitions`.`plugin_typology_typologycriterias_id`\n                FROM `glpi_plugin_typology_typologycriteriadefinitions`\n                  LEFT JOIN `glpi_plugin_typology_typologycriterias`\n                     ON (`glpi_plugin_typology_typologycriterias`.`id`\n                           = `glpi_plugin_typology_typologycriteriadefinitions`.`plugin_typology_typologycriterias_id`)\n                WHERE `plugin_typology_typologycriterias_id` = '" . $typocrit_id . "'\n                ORDER BY `glpi_plugin_typology_typologycriteriadefinitions`.`id`";
     echo "<div class='firstbloc'>";
     if ($result = $DB->query($query)) {
         echo "<form method='post' action='./typologycriteria.form.php'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='6'>" . PluginTypologyTypologyCriteriaDefinition::getTypeName(1) . "</tr>";
         echo "<input type='hidden' name='plugin_typology_typologycriterias_id' value='{$typocrit_id}'>";
         echo "<input type='hidden' name='entities_id' value='" . $typocrit->getField('entities_id') . "'>";
         echo "<input type='hidden' name='is_recursive' value='" . $typocrit->getField('is_recursive') . "'>";
         echo "<tr class='tab_bg_1 center'>";
         echo "<td>" . _n('Field', 'Fields', 2) . "</td><td>";
         PluginTypologyTypologyCriteriaDefinition::dropdownFields($typocrit_id);
         echo "</td>";
         echo "<td>";
         echo "<span id='span_actions' name='span_actions'></span></td>";
         echo "<td>";
         echo "<span id='span_values' name='span_values'></span></td>";
         echo "<td class='tab_bg_2 left' width='80px'>";
         echo "<input type='submit' name='add_action' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>\n";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
         if ($DB->num_fields($result) > 0) {
             if (plugin_typology_haveRight('typology', 'w')) {
                 echo "<form name='critDef_form' id='critDef_form' method='post' action='./typologycriteria.form.php'>";
             }
             echo "<div class='center'><table class='tab_cadre_fixe'>";
             echo "<tr><th colspan='4'>" . PluginTypologyTypologyCriteriaDefinition::getTypeName(2) . "</th></tr>";
             echo "<tr class='tab_bg_1 center'>";
             echo "<th colspan='2'>" . _n('Field', 'Fields', 2) . "</th>";
             echo "<th class='center b'>" . __('Logical operator') . "</th>";
             echo "<th class='center b'>" . __('Value') . "</th>";
             echo "</tr>";
             while ($ligne = $DB->fetch_array($result)) {
                 echo "<tr class='tab_bg_2'>";
                 if (plugin_typology_haveRight('typology', 'w')) {
                     echo "<td width='10'>";
                     echo "<input type='checkbox' name='item[" . $ligne["id"] . "]' value='1'>";
                     echo "<input type='hidden' name='plugin_typology_typologycriterias_id' value='{$typocrit_id}'>";
                     echo "</td>";
                 }
                 self::showMinimalDefinitionForm($ligne);
                 echo "</tr>";
             }
             if (plugin_typology_haveRight('typology', 'w')) {
                 Html::openArrowMassives("critDef_form", true);
                 Html::closeArrowMassives(array('delete_action' => __('Delete permanently')));
             }
             echo "</table></div>";
             if (plugin_typology_haveRight('typology', 'w')) {
                 Html::closeForm();
             }
         }
     }
 }
Esempio n. 7
0
 LICENSE

 This file is part of Typology.

 Typology is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 Typology is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Typology. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
*/
// Direct access to file
if (strpos($_SERVER['PHP_SELF'], "dropdownCaseValue.php")) {
    include '../../../inc/includes.php';
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
if (!defined('GLPI_ROOT')) {
    die("Can not acces directly to this file");
}
$options = array('itemtype' => $_POST['itemtype'], 'typocrit_id' => $_POST['typocrit_id'], 'field' => $_POST['field'], 'action_type' => $_POST['action_type']);
//Display list of values or text field depending on action_type
PluginTypologyTypologyCriteriaDefinition::dropdownValues($options);