Exemple #1
0
 function showForm($ID, $options = array())
 {
     if (!$this->canview()) {
         return false;
     }
     $plugin_databases_databases_id = -1;
     if (isset($options['plugin_databases_databases_id'])) {
         $plugin_databases_databases_id = $options['plugin_databases_databases_id'];
     }
     if ($ID > 0) {
         $this->check($ID, 'r');
     } else {
         $database = new PluginDatabasesDatabase();
         $database->getFromDB($plugin_databases_databases_id);
         // Create item
         $input = array('plugin_databases_databases_id' => $plugin_databases_databases_id, 'entities_id' => $database->getEntityID(), 'is_recursive' => $database->isRecursive());
         $this->check(-1, 'w', $input);
     }
     if ($ID > 0) {
         $this->showTabs($options);
     }
     $this->showFormHeader($options);
     echo "<input type='hidden' name='plugin_databases_databases_id' value='{$plugin_databases_databases_id}'>";
     echo "<input type='hidden' name='entities_id' value='" . $this->fields["entities_id"] . "'>";
     echo "<input type='hidden' name='is_recursive' value='" . $this->fields["is_recursive"] . "'>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Name') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "name");
     echo "</td>";
     echo "<td>" . __('Type') . "</td>";
     echo "<td>";
     Dropdown::show('PluginDatabasesScriptType', array('name' => "plugin_databases_scripttypes_id", 'value' => $this->fields["plugin_databases_scripttypes_id"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Path', 'databases') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "path");
     echo "</td>";
     echo "<td></td>";
     echo "<td></td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan = '4'>";
     echo "<table cellpadding='2' cellspacing='2' border='0'><tr><td>";
     echo __('Comments') . "</td></tr>";
     echo "<tr>";
     echo "<td class='center'>";
     echo "<textarea cols='125' rows='3' name='comment'>" . $this->fields["comment"] . "</textarea>";
     echo "</td></tr></table>";
     echo "</td>";
     echo "</tr>";
     $options['candel'] = false;
     $this->showFormButtons($options);
     if ($ID > 0) {
         $this->addDivForTabs();
     }
     return true;
 }
function plugin_databases_giveItem($type, $ID, $data, $num)
{
    global $DB;
    $searchopt =& Search::getOptions($type);
    $table = $searchopt[$ID]["table"];
    $field = $searchopt[$ID]["field"];
    switch ($table . '.' . $field) {
        case "glpi_plugin_databases_databases_items.items_id":
            $query_device = "SELECT DISTINCT `itemtype`\n                     FROM `glpi_plugin_databases_databases_items`\n                     WHERE `plugin_databases_databases_id` = '" . $data['id'] . "'\n                     ORDER BY `itemtype`";
            $result_device = $DB->query($query_device);
            $number_device = $DB->numrows($result_device);
            $y = 0;
            $out = '';
            $databases = $data['id'];
            if ($number_device > 0) {
                for ($i = 0; $i < $number_device; $i++) {
                    $column = "name";
                    $itemtype = $DB->result($result_device, $i, "itemtype");
                    if (!class_exists($itemtype)) {
                        continue;
                    }
                    $item = new $itemtype();
                    if ($item->canView()) {
                        $table_item = getTableForItemType($itemtype);
                        $query = "SELECT `" . $table_item . "`.*, `glpi_plugin_databases_databases_items`.`id` AS items_id, `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_databases_databases_items`, `" . $table_item . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $table_item . "`.`entities_id`) " . " WHERE `" . $table_item . "`.`id` = `glpi_plugin_databases_databases_items`.`items_id`\n                  AND `glpi_plugin_databases_databases_items`.`itemtype` = '{$itemtype}'\n                  AND `glpi_plugin_databases_databases_items`.`plugin_databases_databases_id` = '" . $databases . "' " . getEntitiesRestrictRequest(" AND ", $table_item, '', '', $item->maybeRecursive());
                        if ($item->maybeTemplate()) {
                            $query .= " AND `" . $table_item . "`.`is_template` = '0'";
                        }
                        $query .= " ORDER BY `glpi_entities`.`completename`, `" . $table_item . "`.`{$column}`";
                        if ($result_linked = $DB->query($query)) {
                            if ($DB->numrows($result_linked)) {
                                $item = new $itemtype();
                                while ($data = $DB->fetch_assoc($result_linked)) {
                                    if ($item->getFromDB($data['id'])) {
                                        $out .= $item::getTypeName(1) . " - " . $item->getLink() . "<br>";
                                    }
                                }
                            } else {
                                $out .= ' ';
                            }
                        }
                    } else {
                        $out .= ' ';
                    }
                }
            }
            return $out;
            break;
        case 'glpi_plugin_databases_databases.name':
            if ($type == 'Ticket') {
                $databases_id = array();
                if ($data['raw']["ITEM_{$num}"] != '') {
                    $databases_id = explode('$$$$', $data['raw']["ITEM_{$num}"]);
                } else {
                    $databases_id = explode('$$$$', $data['raw']["ITEM_" . $num . "_2"]);
                }
                $ret = array();
                $paDatabase = new PluginDatabasesDatabase();
                foreach ($databases_id as $ap_id) {
                    $paDatabase->getFromDB($ap_id);
                    $ret[] = $paDatabase->getLink();
                }
                return implode('<br>', $ret);
            }
            break;
    }
    return "";
}
 /**
  * Show databases associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated databases must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!Session::haveRight('plugin_databases', READ)) {
         return false;
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginDatabasesDatabase');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_databases_databases_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_databases_databases`.`name` AS assocName,\n                       `glpi_plugin_databases_databases`.*\n                FROM `glpi_plugin_databases_databases_items`\n                LEFT JOIN `glpi_plugin_databases_databases`\n                 ON (`glpi_plugin_databases_databases_items`.`plugin_databases_databases_id`=`glpi_plugin_databases_databases`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_databases_databases`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_databases_databases_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_databases_databases_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_databases_databases", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $databases = array();
     $database = new PluginDatabasesDatabase();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $databases[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_databases_databases", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_databases_databases`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (Session::haveRight('plugin_databases', READ) && $nb > count($used)) {
             echo "<form name='database_form{$rand}' id='database_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginDatabasesDatabase') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='entities_id' value='{$entity}'>";
             echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             PluginDatabasesDatabase::dropdownDatabase(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a database', 'databases') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . PluginDatabasesServerType::getTypeName(1) . "</th>";
     echo "<th>" . PluginDatabasesDatabaseCategory::getTypeName(1) . "</th>";
     echo "<th>" . __('Supplier') . "</th>";
     echo "<th>" . __('Editor', 'databases') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginDatabasesDatabase', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($databases as $data) {
             $databaseID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($database->getFromDB($databaseID)) {
                 $link = $database->getLink();
             }
             Session::addToNavigateListItems('PluginDatabasesDatabase', $databaseID);
             $used[$databaseID] = $databaseID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td>" . Dropdown::getDropdownName("glpi_plugin_databases_servertypes", $data["plugin_databases_servertypes_id"]) . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_plugin_databases_databasetypes", $data["plugin_databases_databasetypes_id"]) . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]) . "</td>";
             echo "<td>";
             echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/supplier.form.php?id=" . $data["suppliers_id"] . "\">";
             echo Dropdown::getDropdownName("glpi_suppliers", $data["suppliers_id"]);
             if ($_SESSION["glpiis_ids_visible"] == 1) {
                 echo " (" . $data["suppliers_id"] . ")";
             }
             echo "</a></td>";
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }