Example #1
0
 function showPluginFromSupplier($ID, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $item = new Supplier();
     $canread = $item->can($ID, 'r');
     $canedit = $item->can($ID, 'w');
     $query = "SELECT `glpi_plugin_databases_databases`.* " . "FROM `glpi_plugin_databases_databases` " . " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `glpi_plugin_databases_databases`.`entities_id`) " . " WHERE `suppliers_id` = '{$ID}' " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_databases_databases", '', '', $this->maybeRecursive());
     $query .= " ORDER BY `glpi_plugin_databases_databases`.`name` ";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     if ($withtemplate != 2) {
         echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/databases/front/database.form.php\">";
     }
     echo "<div align='center'><table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='" . (4 + $colsup) . "'>" . _n('Database associated', 'Databases associated', 2, 'databases') . "</th></tr>";
     echo "<tr><th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . PluginDatabasesDatabaseCategory::getTypeName(1) . "</th>";
     echo "<th>" . __('Type') . "</th>";
     echo "<th>" . __('Comments') . "</th>";
     echo "</tr>";
     while ($data = $DB->fetch_array($result)) {
         echo "<tr class='tab_bg_1" . ($data["is_deleted"] == '1' ? "_2" : "") . "'>";
         if ($withtemplate != 3 && $canread && (in_array($data['entities_id'], $_SESSION['glpiactiveentities']) || $data["is_recursive"])) {
             echo "<td class='center'><a href='" . $CFG_GLPI["root_doc"] . "/plugins/databases/front/database.form.php?id=" . $data["id"] . "'>" . $data["name"];
             if ($_SESSION["glpiis_ids_visible"]) {
                 echo " (" . $data["id"] . ")";
             }
             echo "</a></td>";
         } else {
             echo "<td class='center'>" . $data["name"];
             if ($_SESSION["glpiis_ids_visible"]) {
                 echo " (" . $data["id"] . ")";
             }
             echo "</td>";
         }
         echo "</a></td>";
         if (Session::isMultiEntitiesMode()) {
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
         }
         echo "<td>" . Dropdown::getDropdownName("glpi_plugin_databases_databasetypes", $data["plugin_databases_databasetypes_id"]) . "</td>";
         echo "<td>" . Dropdown::getDropdownName("glpi_plugin_databases_servertypes", $data["plugin_databases_servertypes_id"]) . "</td>";
         echo "<td>" . $data["comment"] . "</td></tr>";
     }
     echo "</table></div>";
     Html::closeForm();
 }
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>";
 }