Example #1
0
 function showForm($ID, $options = array())
 {
     $this->initForm($ID, $options);
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Name') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "name");
     echo "</td>";
     echo "<td>" . PluginDatabasesDatabaseCategory::getTypeName(1) . "</td>";
     echo "<td>";
     Dropdown::show('PluginDatabasesDatabaseCategory', array('name' => "plugin_databases_databasecategories_id", 'value' => $this->fields["plugin_databases_databasecategories_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Location') . "</td>";
     echo "<td>";
     Location::dropdown(array('value' => $this->fields["locations_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "<td>" . PluginDatabasesServerType::getTypeName(1) . "</td>";
     echo "<td>";
     Dropdown::show('PluginDatabasesServerType', array('name' => "plugin_databases_servertypes_id", 'value' => $this->fields["plugin_databases_servertypes_id"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Technician in charge of the hardware') . "</td><td>";
     User::dropdown(array('name' => "users_id_tech", 'value' => $this->fields["users_id_tech"], 'entity' => $this->fields["entities_id"], 'right' => 'interface'));
     echo "</td>";
     echo "<td>" . PluginDatabasesDatabaseType::getTypeName(1) . "</td>";
     echo "<td>";
     Dropdown::show('PluginDatabasesDatabaseType', array('name' => "plugin_databases_databasetypes_id", 'value' => $this->fields["plugin_databases_databasetypes_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Group in charge of the hardware') . "</td><td>";
     Group::dropdown(array('name' => 'groups_id_tech', 'value' => $this->fields['groups_id_tech'], 'entity' => $this->fields['entities_id'], 'condition' => '`is_assign`'));
     echo "</td>";
     echo "<td>" . __('Editor', 'databases') . "</td>";
     echo "<td>";
     Dropdown::show('Manufacturer', array('name' => "manufacturers_id", 'value' => $this->fields["manufacturers_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Supplier') . "</td>";
     echo "<td>";
     Dropdown::show('Supplier', array('name' => "suppliers_id", 'value' => $this->fields["suppliers_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "<td>" . __('Associable to a ticket') . "</td><td>";
     Dropdown::showYesNo('is_helpdesk_visible', $this->fields['is_helpdesk_visible']);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td class='center' colspan = '4'>";
     printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"]));
     echo "</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>";
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
function plugin_databases_getAddSearchOptions($itemtype)
{
    $sopt = array();
    if (in_array($itemtype, PluginDatabasesDatabase::getTypes(true))) {
        if (Session::haveRight("plugin_databases", READ)) {
            $sopt[2410]['table'] = 'glpi_plugin_databases_databases';
            $sopt[2410]['field'] = 'name';
            $sopt[2410]['name'] = PluginDatabasesDatabase::getTypeName(2) . " - " . __('Name');
            $sopt[2410]['forcegroupby'] = true;
            $sopt[2410]['datatype'] = 'itemlink';
            $sopt[2410]['massiveaction'] = false;
            $sopt[2410]['itemlink_type'] = 'PluginDatabasesDatabase';
            $sopt[2410]['joinparams'] = array('beforejoin' => array('table' => 'glpi_plugin_databases_databases_items', 'joinparams' => array('jointype' => 'itemtype_item')));
            $sopt[2411]['table'] = 'glpi_plugin_databases_databasecategories';
            $sopt[2411]['field'] = 'name';
            $sopt[2411]['name'] = PluginDatabasesDatabase::getTypeName(2) . " - " . PluginDatabasesDatabaseCategory::getTypeName(1);
            $sopt[2411]['forcegroupby'] = true;
            $sopt[2411]['joinparams'] = array('beforejoin' => array(array('table' => 'glpi_plugin_databases_databases', 'joinparams' => $sopt[2410]['joinparams'])));
            $sopt[2411]['datatype'] = 'dropdown';
            $sopt[2411]['massiveaction'] = false;
            $sopt[2412]['table'] = 'glpi_plugin_databases_servertypes';
            $sopt[2412]['field'] = 'name';
            $sopt[2412]['name'] = PluginDatabasesDatabase::getTypeName(2) . " - " . PluginDatabasesServerType::getTypeName(1);
            $sopt[2412]['forcegroupby'] = true;
            $sopt[2412]['joinparams'] = array('beforejoin' => array(array('table' => 'glpi_plugin_databases_databases', 'joinparams' => $sopt[2410]['joinparams'])));
            $sopt[2412]['datatype'] = 'dropdown';
            $sopt[2412]['massiveaction'] = false;
            $sopt[2413]['table'] = 'glpi_plugin_databases_databasetypes';
            $sopt[2413]['field'] = 'name';
            $sopt[2413]['name'] = PluginDatabasesDatabase::getTypeName(2) . " - " . PluginDatabasesDatabaseType::getTypeName(1);
            $sopt[2413]['forcegroupby'] = true;
            $sopt[2413]['joinparams'] = array('beforejoin' => array(array('table' => 'glpi_plugin_databases_databases', 'joinparams' => $sopt[2410]['joinparams'])));
            $sopt[2413]['datatype'] = 'dropdown';
            $sopt[2413]['massiveaction'] = false;
        }
    }
    /*if ($itemtype == 'Ticket') {
         if (Session::haveRight("plugin_databases", READ)) {
            $sopt[2414]['table']         = 'glpi_plugin_databases_databases';
            $sopt[2414]['field']         = 'name';
            $sopt[2414]['linkfield']     = 'items_id';
            $sopt[2414]['datatype']      = 'itemlink';
            $sopt[2414]['massiveaction'] = false;
            $sopt[2414]['name']          = __('Database', 'databases')." - ".
                                           __('Name');
         }
      }*/
    return $sopt;
}
 /**
  * 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>";
 }