Esempio n. 1
0
 /**
  * Display all the linked computers of a defined typology
  *
  *@param $typoID = typo ID.
  *
  *@return Nothing (displays)
  **/
 public static function showForTypology(PluginTypologyTypology $typo)
 {
     global $DB, $CFG_GLPI;
     $typoID = $typo->fields['id'];
     if (!$typo->can($typoID, 'r')) {
         return false;
     }
     $canedit = $typo->can($typoID, 'w');
     $canview = $typo->can($typoID, 'r');
     $rand = mt_rand();
     $query = "SELECT DISTINCT `itemtype`\n                    FROM `glpi_plugin_typology_typologies_items`\n                    WHERE `plugin_typology_typologies_id` = '{$typoID}'\n                    ORDER BY `itemtype`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form method='post' name='typologies_form{$rand}' id='typologies_form{$rand}' action='" . $CFG_GLPI["root_doc"] . "/plugins/typology/front/typology.form.php'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr>";
         echo "<th colspan='7'>" . __('Add an item') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td colspan='4' class='center'>";
         echo "<input type='hidden' name='plugin_typology_typologies_id' value='{$typoID}'>";
         Dropdown::showAllItems("items_id", 0, 0, $typo->fields['is_recursive'] ? -1 : $typo->fields['entities_id'], PluginTypologyTypology::getTypes());
         echo "</td>";
         echo "<td colspan='3' class='center' class='tab_bg_2'>";
         echo "<input type='submit' name='add_item' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array();
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th colspan='" . ($canedit ? 7 + $colsup : 6 + $colsup) . "'>";
     if ($DB->numrows($result) == 0) {
         _e('No linked element', 'typology');
     } else {
         _e('Linked elements', 'typology');
     }
     echo "</th></tr><tr>";
     if ($canedit && $number) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Type') . "</th>";
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Serial number') . "</th>";
     echo "<th>" . __('Inventory number') . "</th>";
     echo "<th>" . __('Responding to typology\'s criteria', 'typology') . "</th>";
     echo "</tr>";
     for ($i = 0; $i < $number; $i++) {
         $itemtype = $DB->result($result, $i, "itemtype");
         if (!($item = getItemForItemtype($itemtype))) {
             continue;
         }
         if ($canview) {
             $column = "name";
             $itemtable = getTableForItemType($itemtype);
             $query = "SELECT `" . $itemtable . "`.*,\n                                `glpi_plugin_typology_typologies_items`.`id` AS IDP,\n                                `glpi_plugin_typology_typologies_items`.`is_validated`,\n                                `glpi_plugin_typology_typologies_items`.`error`,\n                                `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_typology_typologies_items`, `" . $itemtable . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemtable . "`.`entities_id`) " . " WHERE `" . $itemtable . "`.`id` = `glpi_plugin_typology_typologies_items`.`items_id`\n                              AND `glpi_plugin_typology_typologies_items`.`itemtype` = '{$itemtype}'\n                              AND `glpi_plugin_typology_typologies_items`.`plugin_typology_typologies_id` = '{$typoID}'";
             if ($itemtype != 'User') {
                 $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive());
             }
             if ($item->maybeTemplate()) {
                 $query .= " AND " . $itemtable . ".is_template='0'";
             }
             $query .= " ORDER BY `glpi_entities`.`completename`, `" . $itemtable . "`.`{$column}` ";
             if ($result_linked = $DB->query($query)) {
                 if ($DB->numrows($result_linked)) {
                     Session::initNavigateListItems($itemtype, PluginTypologyTypology::getTypeName(1) . " = " . $typo->fields['name']);
                     while ($data = $DB->fetch_assoc($result_linked)) {
                         $ID = "";
                         $item->getFromDB($data["id"]);
                         Session::addToNavigateListItems($itemtype, $data["id"]);
                         if ($itemtype == 'User') {
                             $format = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], 1);
                         } else {
                             $format = $data["name"];
                         }
                         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                             $ID = " (" . $data["id"] . ")";
                         }
                         $link = Toolbox::getItemTypeFormURL($itemtype);
                         $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $format;
                         if ($itemtype != 'User') {
                             $name .= "&nbsp;" . $ID;
                         }
                         $name .= "</a>";
                         echo "<tr class='tab_bg_1'>";
                         if ($canedit) {
                             echo "<td width='10'>";
                             Html::showMassiveActionCheckBox(__CLASS__, $data["IDP"]);
                             echo "</td>";
                         }
                         echo "<input type='hidden' name='plugin_typology_typologies_id' value='{$typoID}'>";
                         echo "<td class='center'>" . $item->getTypeName() . "</td>";
                         echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>";
                         if (Session::isMultiEntitiesMode()) {
                             if ($itemtype != 'User') {
                                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>";
                             } else {
                                 echo "<td class='center'>-</td>";
                             }
                         }
                         echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>";
                         echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>";
                         if ($data["is_validated"] > 0) {
                             $critTypOK = __('Yes');
                         } else {
                             $critTypOK = "<font color='red'>" . __('No') . " " . __('for the criteria', 'typology') . " ";
                             $i = 0;
                             $critTypOK .= self::displayErrors($data["error"]);
                             $critTypOK .= "</font>";
                         }
                         echo "<td class ='center'><b>" . $critTypOK . "</b></td>";
                         echo "</tr>";
                     }
                 }
             }
         }
     }
     echo "</table>";
     if ($canedit && $number) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * 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();
 }