function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if ($item->getType() == 'Profile') {
         return PluginDatabasesDatabase::getTypeName(2);
     }
     return '';
 }
예제 #2
0
function plugin_init_databases()
{
    global $PLUGIN_HOOKS;
    $PLUGIN_HOOKS['csrf_compliant']['databases'] = true;
    $PLUGIN_HOOKS['change_profile']['databases'] = array('PluginDatabasesProfile', 'changeProfile');
    $PLUGIN_HOOKS['assign_to_ticket']['databases'] = true;
    if (Session::getLoginUserID()) {
        Plugin::registerClass('PluginDatabasesDatabase', array('linkgroup_tech_types' => true, 'linkuser_tech_types' => true, 'document_types' => true, 'ticket_types' => true, 'helpdesk_visible_types' => true, 'addtabon' => 'Supplier'));
        Plugin::registerClass('PluginDatabasesProfile', array('addtabon' => 'Profile'));
        if (class_exists('PluginAccountsAccount')) {
            PluginAccountsAccount::registerType('PluginDatabasesDatabase');
        }
        if (isset($_SESSION["glpi_plugin_environment_installed"]) && $_SESSION["glpi_plugin_environment_installed"] == 1) {
            $_SESSION["glpi_plugin_environment_databases"] = 1;
            // Display a menu entry ?
            if (plugin_databases_haveRight("databases", "r")) {
                $PLUGIN_HOOKS['submenu_entry']['environment']['options']['databases']['title'] = PluginDatabasesDatabase::getTypeName(2);
                $PLUGIN_HOOKS['submenu_entry']['environment']['options']['databases']['page'] = '/plugins/databases/front/database.php';
                $PLUGIN_HOOKS['submenu_entry']['environment']['options']['databases']['links']['search'] = '/plugins/databases/front/database.php';
            }
            if (plugin_databases_haveRight("databases", "w")) {
                $PLUGIN_HOOKS['submenu_entry']['environment']['options']['databases']['links']['add'] = '/plugins/databases/front/database.form.php';
                $PLUGIN_HOOKS['use_massive_action']['databases'] = 1;
            }
        } else {
            // Display a menu entry ?
            if (plugin_databases_haveRight("databases", "r")) {
                $PLUGIN_HOOKS['menu_entry']['databases'] = 'front/database.php';
                $PLUGIN_HOOKS['submenu_entry']['databases']['search'] = 'front/database.php';
            }
            if (plugin_databases_haveRight("databases", "w")) {
                $PLUGIN_HOOKS['submenu_entry']['databases']['add'] = 'front/database.form.php?new=1';
                $PLUGIN_HOOKS['use_massive_action']['databases'] = 1;
            }
        }
        if (class_exists('PluginDatabasesDatabase_Item')) {
            // only if plugin activated
            $PLUGIN_HOOKS['pre_item_purge']['databases'] = array('Profile' => array('PluginDatabasesProfile', 'purgeProfiles'));
            $PLUGIN_HOOKS['plugin_datainjection_populate']['databases'] = 'plugin_datainjection_populate_databases';
        }
        // End init, when all types are registered
        $PLUGIN_HOOKS['post_init']['databases'] = 'plugin_databases_postinit';
        // Import from Data_Injection plugin
        $PLUGIN_HOOKS['migratetypes']['databases'] = 'plugin_datainjection_migratetypes_databases';
    }
}
예제 #3
0
		
This file is part of databases.

Databases 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.

Databases 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 Databases. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
$plugin = new Plugin();
if ($plugin->isActivated("environment")) {
    Html::header(PluginDatabasesDatabase::getTypeName(2), '', "plugins", "environment", "databases");
} else {
    Html::header(PluginDatabasesDatabase::getTypeName(2), '', "plugins", "databases");
}
$database = new PluginDatabasesDatabase();
if ($database->canView() || Session::haveRight("config", "w")) {
    Search::show('PluginDatabasesDatabase');
} else {
    Html::displayRightError();
}
Html::footer();
예제 #4
0
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;
}
예제 #5
0
 function showScripts(PluginDatabasesDatabase $database)
 {
     global $DB, $CFG_GLPI;
     $instID = $database->fields['id'];
     if (!$database->can($instID, "r")) {
         return false;
     }
     $rand = mt_rand();
     $canedit = $database->can($instID, 'w');
     $query = "SELECT `glpi_plugin_databases_scripts`.`name` AS name,\n                        `glpi_plugin_databases_scripts`.`id`,\n                        `glpi_plugin_databases_scripts`.`plugin_databases_databases_id`,\n                        `glpi_plugin_databases_scripts`.`path`,\n                        `glpi_plugin_databases_scripts`.`comment`,\n                        `glpi_plugin_databases_scripttypes`.`name` AS type\n               FROM `glpi_plugin_databases_scripts` ";
     $query .= " LEFT JOIN `glpi_plugin_databases_scripttypes`\n      ON (`glpi_plugin_databases_scripttypes`.`id` = `glpi_plugin_databases_scripts`.`plugin_databases_scripttypes_id`)";
     $query .= " LEFT JOIN `glpi_plugin_databases_databases`\n      ON (`glpi_plugin_databases_databases`.`id` = `glpi_plugin_databases_scripts`.`plugin_databases_databases_id`)";
     $query .= " WHERE `glpi_plugin_databases_scripts`.`plugin_databases_databases_id` = '{$instID}'\n          ORDER BY `glpi_plugin_databases_scripts`.`name`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array();
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     if ($number != 0) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr>";
         if ($canedit && $number) {
             echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
         }
         echo "<th>" . __('Name') . "</th>";
         echo "<th>" . __('Type') . "</th>";
         echo "<th>" . __('Path', 'databases') . "</th>";
         echo "<th>" . __('Comments') . "</th>";
         echo "</tr>";
         Session::initNavigateListItems($this->getType(), PluginDatabasesDatabase::getTypeName(2) . " = " . $database->fields["name"]);
         $i = 0;
         $row_num = 1;
         while ($data = $DB->fetch_array($result)) {
             Session::addToNavigateListItems($this->getType(), $data['id']);
             $i++;
             $row_num++;
             echo "<tr class='tab_bg_1 center'>";
             echo "<td width='10'>";
             if ($canedit) {
                 Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
             }
             echo "</td>";
             echo "<td class='center'>";
             echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/databases/front/script.form.php?id=" . $data["id"] . "&amp;plugin_databases_databases_id=" . $data["plugin_databases_databases_id"] . "'>";
             echo $data["name"];
             if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                 echo " (" . $data["id"] . ")";
             }
             echo "</a></td>";
             echo "<td class='center'>" . $data["type"] . "</td>";
             echo "<td class='left'>" . $data["path"] . "</td>";
             echo "<td class='center'>" . nl2br($data["comment"]) . "</td>";
             echo "</tr>";
         }
         echo "</table>";
     }
     if ($canedit && $number) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }
                                $input = array('id' => $key);
                                if ($val == 1) {
                                    $database_item->check($key, UPDATE);
                                    $database_item->delete($input);
                                }
                            }
                            Html::back();
                        } else {
                            if (isset($_POST["deletedatabases"])) {
                                $input = array('id' => $_POST["id"]);
                                $database_item->check($_POST["id"], UPDATE);
                                $database_item->delete($input);
                                Html::back();
                            } else {
                                $database->checkGlobal(READ);
                                $plugin = new Plugin();
                                if ($plugin->isActivated("environment")) {
                                    Html::header(PluginDatabasesDatabase::getTypeName(2), '', "assets", "pluginenvironmentdisplay", "databases");
                                } else {
                                    Html::header(PluginDatabasesDatabase::getTypeName(2), '', "assets", "plugindatabasesmenu");
                                }
                                $database->display($_GET);
                                Html::footer();
                            }
                        }
                    }
                }
            }
        }
    }
}
 /**
  * Show items links to a database
  *
  * @since version 0.84
  *
  * @param $database PluginDatabasesDatabase object
  *
  * @return nothing (HTML display)
  **/
 public static function showForDatabase(PluginDatabasesDatabase $database)
 {
     global $DB;
     $instID = $database->fields['id'];
     if (!$database->can($instID, READ)) {
         return false;
     }
     $rand = mt_rand();
     $canedit = $database->can($instID, UPDATE);
     $query = "SELECT DISTINCT `itemtype`\n             FROM `glpi_plugin_databases_databases_items`\n             WHERE `plugin_databases_databases_id` = '{$instID}'\n             ORDER BY `itemtype`\n             LIMIT " . count(PluginDatabasesDatabase::getTypes(true));
     $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='databases_form{$rand}' id='databases_form{$rand}'\n         action='" . Toolbox::getItemTypeFormURL("PluginDatabasesDatabase") . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='" . ($canedit ? 5 + $colsup : 4 + $colsup) . "'>" . __('Add an item') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td colspan='" . (3 + $colsup) . "' class='center'>";
         echo "<input type='hidden' name='plugin_databases_databases_id' value='{$instID}'>";
         Dropdown::showAllItems("items_id", 0, 0, $database->fields['is_recursive'] ? -1 : $database->fields['entities_id'], PluginDatabasesDatabase::getTypes());
         echo "</td>";
         echo "<td colspan='2' class='tab_bg_2'>";
         echo "<input type='submit' name='additem' 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($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<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 "</tr>";
     for ($i = 0; $i < $number; $i++) {
         $itemType = $DB->result($result, $i, "itemtype");
         if (!($item = getItemForItemtype($itemType))) {
             continue;
         }
         if ($item->canView()) {
             $column = "name";
             $itemTable = getTableForItemType($itemType);
             $query = "SELECT `" . $itemTable . "`.*,\n                             `glpi_plugin_databases_databases_items`.`id` AS items_id,\n                             `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_databases_databases_items`, `" . $itemTable . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemTable . "`.`entities_id`) " . " WHERE `" . $itemTable . "`.`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` = '{$instID}' " . 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, PluginDatabasesDatabase::getTypeName(2) . " = " . $database->fields['name']);
                     while ($data = $DB->fetch_assoc($result_linked)) {
                         $item->getFromDB($data["id"]);
                         Session::addToNavigateListItems($itemType, $data["id"]);
                         $ID = "";
                         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                             $ID = " (" . $data["id"] . ")";
                         }
                         $link = Toolbox::getItemTypeFormURL($itemType);
                         $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $data["name"] . "{$ID}</a>";
                         echo "<tr class='tab_bg_1'>";
                         if ($canedit) {
                             echo "<td width='10'>";
                             Html::showMassiveActionCheckBox(__CLASS__, $data["items_id"]);
                             echo "</td>";
                         }
                         echo "<td class='center'>" . $item::getTypeName(1) . "</td>";
                         echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>";
                         if (Session::isMultiEntitiesMode()) {
                             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>";
                         }
                         echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>";
                         echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>";
                         echo "</tr>";
                     }
                 }
             }
         }
     }
     echo "</table>";
     if ($canedit && $number) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions($paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }
예제 #8
0
 function showForm($ID, $options = array())
 {
     if (!Session::haveRight("profile", "r")) {
         return false;
     }
     $prof = new Profile();
     if ($ID) {
         $this->getFromDBByProfile($ID);
         $prof->getFromDB($ID);
     }
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_2'>";
     echo "<th colspan='4'>" . sprintf(__('%1$s - %2$s'), __('Rights management', 'databases'), $prof->fields["name"]) . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . PluginDatabasesDatabase::getTypeName(2) . "</td><td>";
     if ($prof->fields['interface'] != 'helpdesk') {
         Profile::dropdownNoneReadWrite("databases", $this->fields["databases"], 1, 1, 1);
     } else {
         _e('No access');
         // No access;
     }
     echo "</td>";
     echo "<td>" . __('Associable items to a ticket') . " - " . PluginDatabasesDatabase::getTypeName(2) . "</td><td>";
     if ($prof->fields['create_ticket']) {
         Dropdown::showYesNo("open_ticket", $this->fields["open_ticket"]);
     } else {
         echo Dropdown::getYesNo(0);
     }
     echo "</td>";
     echo "</tr>";
     echo "<input type='hidden' name='id' value=" . $this->fields["id"] . ">";
     $options['candel'] = false;
     $this->showFormButtons($options);
 }