if (!defined('GLPI_ROOT')) {
    include '../inc/includes.php';
}
Html::popHeader(__('Setup'), $_SERVER['PHP_SELF']);
Session::haveRightsOr('serach_config', array(DisplayPreference::PERSONAL, DisplayPreference::GENERAL));
$setupdisplay = new DisplayPreference();
if (isset($_POST["activate"])) {
    $setupdisplay->activatePerso($_POST);
} else {
    if (isset($_POST["disable"])) {
        if ($_POST['users_id'] == Session::getLoginUserID()) {
            $setupdisplay->deleteByCriteria(array('users_id' => $_POST['users_id'], 'itemtype' => $_POST['itemtype']));
        }
    } else {
        if (isset($_POST["add"])) {
            $setupdisplay->add($_POST);
        } else {
            if (isset($_POST["purge"]) || isset($_POST["purge_x"])) {
                $setupdisplay->delete($_POST, 1);
            } else {
                if (isset($_POST["up"]) || isset($_POST["up_x"])) {
                    $setupdisplay->orderItem($_POST, 'up');
                } else {
                    if (isset($_POST["down"]) || isset($_POST["down_x"])) {
                        $setupdisplay->orderItem($_POST, 'down');
                    }
                }
            }
        }
    }
}
Пример #2
0
 static function install(Migration $migration)
 {
     global $DB;
     $table = getTableForItemType(__CLASS__);
     if (!TableExists($table)) {
         $query = "CREATE TABLE `{$table}` (\n                           `id` INT( 11 ) NOT NULL AUTO_INCREMENT,\n                           `entities_id` INT( 11 ) NOT NULL DEFAULT 0,\n                           `itemtype` varchar(255) collate utf8_unicode_ci default NULL,\n                           `is_active` tinyint(1) NOT NULL default '0',\n                           `name` varchar(255) collate utf8_unicode_ci default NULL,\n                           `comment` text NULL,\n                           `date_mod` datetime NOT NULL default '0000-00-00 00:00:00',\n                           `use_global_search` tinyint(1) NOT NULL default '0',\n                           `use_unicity` tinyint(1) NOT NULL default '0',\n                           `use_history` tinyint(1) NOT NULL default '0',\n                           `use_infocoms` tinyint(1) NOT NULL default '0',\n                           `use_contracts` tinyint(1) NOT NULL default '0',\n                           `use_documents` tinyint(1) NOT NULL default '0',\n                           `use_tickets` tinyint(1) NOT NULL default '0',\n                           `use_links` tinyint(1) NOT NULL default '0',\n                           `use_loans` tinyint(1) NOT NULL default '0',\n                           `use_network_ports` tinyint(1) NOT NULL default '0',\n                           `use_direct_connections` tinyint(1) NOT NULL default '0',\n                           `use_plugin_datainjection` tinyint(1) NOT NULL default '0',\n                           `use_plugin_pdf` tinyint(1) NOT NULL default '0',\n                           `use_plugin_order` tinyint(1) NOT NULL default '0',\n                           `use_plugin_uninstall` tinyint(1) NOT NULL default '0',\n                           `use_plugin_geninventorynumber` tinyint(1) NOT NULL default '0',\n                           `use_menu_entry` tinyint(1) NOT NULL default '0',\n                           `linked_itemtypes` text NULL,\n                           PRIMARY KEY ( `id` )\n                           ) ENGINE = MYISAM COMMENT = 'Object types definition table' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->query($query) or die($DB->error());
     }
     $migration->addField($table, "use_network_ports", "bool");
     $migration->addField($table, "use_direct_connections", "bool");
     $migration->addField($table, "use_plugin_geninventorynumber", "bool");
     $migration->addField($table, "use_contracts", "bool");
     $migration->addField($table, "use_menu_entry", "bool");
     $migration->addField($table, "use_global_search", "bool");
     $migration->addField($table, "comment", "text");
     $migration->addField($table, "date_mod", "datetime");
     $migration->addField($table, "linked_itemtypes", "text");
     $migration->migrationOneTable($table);
     //Displayprefs
     $prefs = array(10 => 6, 9 => 5, 8 => 4, 7 => 3, 6 => 2, 2 => 1, 4 => 1, 11 => 7, 12 => 8, 14 => 10, 15 => 11);
     foreach ($prefs as $num => $rank) {
         if (!countElementsInTable("glpi_displaypreferences", "`itemtype`='" . __CLASS__ . "' AND `num`='{$num}'\n                                       AND `users_id`='0'")) {
             $preference = new DisplayPreference();
             $tmp['itemtype'] = __CLASS__;
             $tmp['num'] = $num;
             $tmp['rank'] = $rank;
             $tmp['users_id'] = 0;
             $preference->add($tmp);
         }
     }
     //If files are missing, recreate them!
     self::checkClassAndFilesForItemType();
 }
Пример #3
0
 /**
  * This test will add all serachoptions in each itemtype and check if the
  * search give a SQL error
  */
 public function testSearchOptions()
 {
     $displaypref = new DisplayPreference();
     // save table glpi_displaypreferences
     $dp = getAllDatasFromTable($displaypref->getTable());
     $itemtypeslist = $this->getClasses('getSearchOptions');
     foreach ($itemtypeslist as $itemtype) {
         $number = 0;
         if (!file_exists('front/' . strtolower($itemtype) . '.php') || substr($itemtype, 0, 4) === "Rule" || substr($itemtype, 0, 6) === "Common" || substr($itemtype, 0, 2) === "DB" || $itemtype == 'SlaLevel' || $itemtype == 'Reservation' || $itemtype == 'Event' || $itemtype == 'KnowbaseItem' || $itemtype == 'NetworkPortMigration') {
             // it's the case where not have search possible in this itemtype
             continue;
         }
         $item = getItemForItemtype($itemtype);
         foreach ($item->getSearchOptions() as $key => $data) {
             if (is_int($key)) {
                 $input = array('itemtype' => $itemtype, 'users_id' => 0, 'num' => $key);
                 $displaypref->add($input);
                 $number++;
             }
         }
         $this->assertEquals($number, countElementsInTable($displaypref->getTable(), "`itemtype`='" . $itemtype . "' AND `users_id`=0"));
         // do a search query
         $search_params = array('is_deleted' => 0, 'start' => 0, 'criteria' => array(), 'metacriteria' => array());
         $data = $this->doSearch($itemtype, $search_params);
         // check for sql error (data key missing or empty)
         $this->assertArrayHasKey('data', $data, $data['last_errors']);
         $this->assertNotCount(0, $data['data'], $data['last_errors']);
     }
     // restore displaypreference table
     foreach (getAllDatasFromTable($displaypref->getTable()) as $line) {
         $displaypref->delete($line, true);
     }
     $this->assertEquals(0, countElementsInTable($displaypref->getTable()));
     foreach ($dp as $input) {
         $displaypref->add($input);
     }
 }
Пример #4
0
 static function install(Migration $migration)
 {
     global $DB;
     $table = getTableForItemType(__CLASS__);
     if (!TableExists($table)) {
         $query = "CREATE TABLE `{$table}` (\n                           `id` INT( 11 ) NOT NULL AUTO_INCREMENT,\n                           `entities_id` INT( 11 ) NOT NULL DEFAULT 0,\n                           `itemtype` varchar(255) collate utf8_unicode_ci default NULL,\n                           `is_active` tinyint(1) NOT NULL default '0',\n                           `name` varchar(255) collate utf8_unicode_ci default NULL,\n                           `comment` text NULL,\n                           `date_mod` datetime DEFAULT NULL,\n                           `date_creation` datetime DEFAULT NULL,\n                           `use_global_search` tinyint(1) NOT NULL default '0',\n                           `use_unicity` tinyint(1) NOT NULL default '0',\n                           `use_history` tinyint(1) NOT NULL default '0',\n                           `use_infocoms` tinyint(1) NOT NULL default '0',\n                           `use_contracts` tinyint(1) NOT NULL default '0',\n                           `use_documents` tinyint(1) NOT NULL default '0',\n                           `use_tickets` tinyint(1) NOT NULL default '0',\n                           `use_links` tinyint(1) NOT NULL default '0',\n                           `use_loans` tinyint(1) NOT NULL default '0',\n                           `use_network_ports` tinyint(1) NOT NULL default '0',\n                           `use_direct_connections` tinyint(1) NOT NULL default '0',\n                           `use_plugin_datainjection` tinyint(1) NOT NULL default '0',\n                           `use_plugin_pdf` tinyint(1) NOT NULL default '0',\n                           `use_plugin_order` tinyint(1) NOT NULL default '0',\n                           `use_plugin_uninstall` tinyint(1) NOT NULL default '0',\n                           `use_plugin_geninventorynumber` tinyint(1) NOT NULL default '0',\n                           `use_menu_entry` tinyint(1) NOT NULL default '0',\n                           `use_projects` tinyint(1) NOT NULL default '0',\n                           `linked_itemtypes` text NULL,\n                           `plugin_genericobject_typefamilies_id` INT( 11 ) NOT NULL DEFAULT 0,\n                           PRIMARY KEY ( `id` )\n                           ) ENGINE = MYISAM COMMENT = 'Object types definition table' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->query($query) or die($DB->error());
     }
     $migration->addField($table, "use_network_ports", "bool");
     $migration->addField($table, "use_direct_connections", "bool");
     $migration->addField($table, "use_plugin_geninventorynumber", "bool");
     $migration->addField($table, "use_contracts", "bool");
     $migration->addField($table, "use_menu_entry", "bool");
     $migration->addField($table, "use_global_search", "bool");
     $migration->addField($table, "use_projects", "bool");
     $migration->addField($table, "use_notepad", "bool");
     $migration->addField($table, "comment", "text");
     if (!$migration->addField($table, "date_mod", "datetime")) {
         $migration->changeField($table, "date_mod", "date_mod", "datetime");
     }
     $migration->addField($table, "date_creation", "datetime");
     $migration->addField($table, "linked_itemtypes", "text");
     $migration->addField($table, "plugin_genericobject_typefamilies_id", "integer");
     $migration->addField($table, "use_plugin_simcard", "bool");
     $migration->migrationOneTable($table);
     // Migrate notepad data
     $allGenericObjectTypes = PluginGenericobjectType::getTypes(true);
     $notepad = new Notepad();
     foreach ($allGenericObjectTypes as $genericObjectType => $genericObjectData) {
         $genericObjectTypeInstance = new $genericObjectType();
         if (FieldExists($genericObjectTypeInstance->getTable(), "notepad")) {
             $query = "INSERT INTO `" . $notepad->getTable() . "`\n                  (`items_id`,\n                  `itemtype`,\n                  `date`,\n                  `date_mod`,\n                  `content`\n               )\n               SELECT\n                  `id` as `items_id`,\n                  '" . $genericObjectType . "' as `itemtype`,\n                  now() as `date`,\n                  now() as `date_mod`,\n                  `notepad` as `content`\n               FROM `" . $genericObjectTypeInstance->getTable() . "`\n               WHERE notepad IS NOT NULL\n               AND notepad <> ''";
             $DB->query($query) or die($DB->error());
         }
         $query = "UPDATE`" . $notepad->getTable() . "`";
         $migration->dropField($genericObjectTypeInstance->getTable(), "notepad");
         $migration->migrationOneTable($genericObjectTypeInstance->getTable());
     }
     //Displayprefs
     $prefs = array(10 => 6, 9 => 5, 8 => 4, 7 => 3, 6 => 2, 2 => 1, 4 => 1, 11 => 7, 12 => 8, 14 => 10, 15 => 11);
     foreach ($prefs as $num => $rank) {
         if (!countElementsInTable("glpi_displaypreferences", "`itemtype`='" . __CLASS__ . "' AND `num`='{$num}'\n                                       AND `users_id`='0'")) {
             $preference = new DisplayPreference();
             $tmp['itemtype'] = __CLASS__;
             $tmp['num'] = $num;
             $tmp['rank'] = $rank;
             $tmp['users_id'] = 0;
             $preference->add($tmp);
         }
     }
     //If files are missing, recreate them!
     self::checkClassAndFilesForItemType();
 }
Пример #5
0
    exit;
} else {
    $itemtype = $_GET["itemtype"];
}
if (!isset($_GET["type"])) {
    exit;
} else {
    $type = $_GET["type"];
}
Session::checkSeveralRightsOr(array("search_config_global" => "w", "search_config" => "w"));
$setupdisplay = new DisplayPreference();
if (isset($_GET["activate"])) {
    $setupdisplay->activatePerso($_GET);
} else {
    if (isset($_POST["add"])) {
        $setupdisplay->add($_REQUEST);
    } else {
        if (isset($_GET["delete"]) || isset($_GET["delete_x"])) {
            $setupdisplay->delete($_GET);
        } else {
            if (isset($_GET["up"]) || isset($_GET["up_x"])) {
                $setupdisplay->orderItem($_GET, 'up');
            } else {
                if (isset($_GET["down"]) || isset($_GET["down_x"])) {
                    $setupdisplay->orderItem($_GET, 'down');
                }
            }
        }
    }
}
header("location: " . GLPI_ROOT . "/plugins/mobile/front/searchconfig.php?type={$type}&itemtype={$itemtype}&rand=" . mt_rand());