getsearchoptions.php 2.3 KB
Newer Older
1
<?php
2 3 4
/**
 * ---------------------------------------------------------------------
 * GLPI - Gestionnaire Libre de Parc Informatique
5
 * Copyright (C) 2015-2018 Teclib' and contributors.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * http://glpi-project.org
 *
 * based on GLPI - Gestionnaire Libre de Parc Informatique
 * Copyright (C) 2003-2014 by the INDEPNET Development Team.
 *
 * ---------------------------------------------------------------------
 *
 * LICENSE
 *
 * This file is part of GLPI.
 *
 * GLPI 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.
 *
 * GLPI 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 GLPI. If not, see <http://www.gnu.org/licenses/>.
 * ---------------------------------------------------------------------
31
 */
remi's avatar
remi committed
32

remi's avatar
remi committed
33 34
define('DO_NOT_CHECK_HTTP_REFERER', 1);

35
// Ensure current directory when run from crontab
Remi Collet's avatar
Remi Collet committed
36
chdir(__DIR__);
37 38

if (isset($_SERVER['argv'])) {
Anael Mobilia's avatar
Anael Mobilia committed
39 40 41
   for ($i=1; $i<$_SERVER['argc']; $i++) {
      $it = explode("=", $_SERVER['argv'][$i], 2);
      $it[0] = preg_replace('/^--/', '', $it[0]);
42 43 44 45 46

      $_GET[$it[0]] = (isset($it[1]) ? $it[1] : true);
   }
}

Johan Cwiklinski's avatar
Johan Cwiklinski committed
47
function help () {
48
   echo "\nUsage : php getsearchoptions.php --type=<itemtype> [ --lang=<locale> ]\n\n";
Johan Cwiklinski's avatar
Johan Cwiklinski committed
49 50 51 52
}

if (isset($_GET['help'])) {
   help();
53 54 55
   exit (0);
}

56
include ('../inc/includes.php');
57 58

if (!isset($_GET['type'])) {
Johan Cwiklinski's avatar
Johan Cwiklinski committed
59
   help();
60 61 62 63 64 65
   die("** mandatory option 'type' is missing\n");
}
if (!class_exists($_GET['type'])) {
   die("** unknown type\n");
}
if (isset($_GET['lang'])) {
yllen's avatar
yllen committed
66
   Session::loadLanguage($_GET['lang']);
67 68 69
}

$opts = &Search::getOptions($_GET['type']);
70
$sort = [];
71 72 73
$group = 'N/A';

foreach ($opts as $ref => $opt) {
74
   if (isset($opt['field'])) {
75 76
      $sort[$ref] = $group . " / " . $opt['name'];
   } else {
77 78 79 80 81
      if (is_array($opt)) {
         $group = $opt['name'];
      } else {
         $group = $opt;
      }
82 83 84 85 86 87 88
   }
}
ksort($sort);
if (!isCommandLine()) {
   header("Content-type: text/plain");
}
print_r($sort);