Exemplo n.º 1
0
function plugin_barcode_install()
{
    global $DB;
    $migration = new Migration(PLUGIN_BARCODE_VERSION);
    if (!file_exists(GLPI_PLUGIN_DOC_DIR . "/barcode")) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/barcode");
    }
    $migration->renameTable("glpi_plugin_barcode_config", "glpi_plugin_barcode_configs");
    if (!TableExists("glpi_plugin_barcode_configs")) {
        $query = "CREATE TABLE `glpi_plugin_barcode_configs` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `type` varchar(20) collate utf8_unicode_ci default NULL,\n                  PRIMARY KEY  (`ID`)\n               ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("error creating glpi_plugin_barcode_configs " . $DB->error());
        $query = "INSERT INTO `glpi_plugin_barcode_configs` \n                     (`id`, `type`)\n                VALUES\n                     ('1', 'code128')";
        $DB->query($query) or die("error populate glpi_plugin_barcode_configs " . $DB->error());
    }
    $migration->renameTable("glpi_plugin_barcode_config_type", "glpi_plugin_barcode_configs_types");
    if (!TableExists("glpi_plugin_barcode_configs_types")) {
        $query = "CREATE TABLE `glpi_plugin_barcode_configs_types` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `type` varchar(20) collate utf8_unicode_ci default NULL,\n                  `size` varchar(20) collate utf8_unicode_ci default NULL,\n                  `orientation` varchar(9) collate utf8_unicode_ci default NULL,\n                  `marginTop` int(11) NULL,\n                  `marginBottom` int(11) NULL,\n                  `marginLeft` int(11) NULL,\n                  `marginRight` int(11) NULL,\n                  `marginHorizontal` int(11) NULL,\n                  `marginVertical` int(11) NULL,\n                  `maxCodeWidth` int(11) NULL,\n                  `maxCodeHeight` int(11) NULL,\n                  PRIMARY KEY  (`ID`),\n                  UNIQUE  (`type`)\n               ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->query($query) or die("error creating glpi_plugin_barcode_configs_types " . $DB->error());
        $query = "INSERT INTO `glpi_plugin_barcode_configs_types`\n                     (`type`, `size`, `orientation`,\n                     `marginTop`, `marginBottom`, `marginLeft`, `marginRight`,\n                     `marginHorizontal`, `marginVertical`, `maxCodeWidth`, `maxCodeHeight`)\n                VALUES\n                     ('Code39', 'A4', 'Portrait',\n                     '30', '30', '30', '30',\n                     '25', '30', '128', '50'),\n                     ('code128', 'A4', 'Portrait',\n                     '30', '30', '30', '30',\n                     '25', '30', '110', '70'),\n                     ('ean13', 'A4', 'Portrait',\n                     '30', '30', '30', '30',\n                     '25', '30', '110', '70'),\n                     ('int25', 'A4', 'Portrait',\n                     '30', '30', '30', '30',\n                     '25', '30', '110', '70'),\n                     ('postnet', 'A4', 'Portrait',\n                     '30', '30', '30', '30',\n                     '25', '30', '110', '70'),\n                     ('upca', 'A4', 'Portrait',\n                     '30', '30', '30', '30',\n                     '25', '30', '110', '70'),\n                     ('QRcode', 'A4', 'Portrait',\n                     '30', '30', '30', '30',\n                     '25', '30', '110', '100')";
        $DB->query($query) or die("error populate glpi_plugin_barcode_configs_types " . $DB->error());
    }
    if (countElementsInTable("glpi_plugin_barcode_configs_types", "`type`='QRcode'") == 0) {
        $query = "INSERT INTO `glpi_plugin_barcode_configs_types`\n                     (`type`, `size`, `orientation`,\n                     `marginTop`, `marginBottom`, `marginLeft`, `marginRight`,\n                     `marginHorizontal`, `marginVertical`, `maxCodeWidth`, `maxCodeHeight`)\n                VALUES\n                     ('QRcode', 'A4', 'Portrait',\n                     '30', '30', '30', '30',\n                     '25', '30', '110', '100')";
        $DB->query($query) or die("error populate glpi_plugin_barcode_configs_types " . $DB->error());
    }
    include_once GLPI_ROOT . '/plugins/barcode/inc/profile.class.php';
    include_once GLPI_ROOT . '/plugins/barcode/inc/config.class.php';
    PluginBarcodeProfile::initProfile();
    if (TableExists("glpi_plugin_barcode_profiles")) {
        $query = "DROP TABLE `glpi_plugin_barcode_profiles`";
        $DB->query($query) or die("error deleting glpi_plugin_barcode_profiles");
    }
    return true;
}
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if ($item->getID() > 0) {
         if (get_class($item) == 'PluginFusioninventoryCollect') {
             if ($item->fields['type'] == 'wmi') {
                 $a_colregs = getAllDatasFromTable('glpi_plugin_fusioninventory_collects_wmis', "`plugin_fusioninventory_collects_id`='" . $item->getID() . "'");
                 if (count($a_colregs) == 0) {
                     return array();
                 }
                 $in = array();
                 foreach ($a_colregs as $id => $data) {
                     $in[] = $id;
                 }
                 if (countElementsInTable('glpi_plugin_fusioninventory_collects_wmis_contents', "`plugin_fusioninventory_collects_wmis_id` IN ('" . implode("','", $in) . "')") > 0) {
                     return array(__('Windows WMI content', 'fusioninventory'));
                 }
             }
         } else {
             if (get_class($item) == 'Computer') {
                 if (countElementsInTable('glpi_plugin_fusioninventory_collects_wmis_contents', "`computers_id`='" . $item->getID() . "'") > 0) {
                     return array(__('Windows WMI content', 'fusioninventory'));
                 }
             }
         }
     }
     return array();
 }
Exemplo n.º 3
0
 static function showSummary()
 {
     echo "<div class='center'><table class='tab_cadre' cellpadding='5' width='50%'>";
     echo "<tr><th>" . __('Summary') . "</th></tr>";
     if (countElementsInTable('glpi_plugin_archires_views', "`entities_id`='" . $_SESSION["glpiactive_entity"] . "'") > 0) {
         echo "<tr class='tab_bg_1'><td>";
         echo "<a href='view.php'>" . PluginArchiresView::getTypeName(2) . "</a>";
         echo "</td></tr>";
         echo "<tr class='tab_bg_1'><td>";
         echo "<a href='locationquery.php'>" . sprintf(__('%1$s - %2$s'), self::getTypeName(1), PluginArchiresLocationQuery::getTypeName(1)) . "</a>";
         echo "</td></tr>";
         echo "<tr class='tab_bg_1'><td>";
         echo "<a href='networkequipmentquery.php'>" . sprintf(__('%1$s - %2$s'), self::getTypeName(1), PluginArchiresNetworkEquipmentQuery::getTypeName(1)) . "</a>";
         echo "</td></tr>";
         $plugin = new Plugin();
         if ($plugin->isActivated("appliances")) {
             echo "<tr class='tab_bg_1'><td>";
             echo "<a href='appliancequery.php'>" . sprintf(__('%1$s - %2$s'), self::getTypeName(1), PluginAppliancesAppliance::getTypeName(1)) . "</a>";
             echo "</td></tr>";
         }
     } else {
         echo "<tr class='tab_bg_1'><td>";
         echo "<a href='view.form.php?new=1'>" . __('Add view', 'archires') . "</a>";
         echo "</td></tr>";
     }
     echo "</table></div>";
 }
Exemplo n.º 4
0
 static function countForResourceTask(PluginResourcesTask $item)
 {
     $types = implode("','", PluginResourcesResource::getTypes());
     if (empty($types)) {
         return 0;
     }
     return countElementsInTable('glpi_plugin_resources_tasks_items', "`itemtype` IN ('{$types}')\n                                   AND `plugin_resources_tasks_id` = '" . $item->getID() . "'");
 }
Exemplo n.º 5
0
   protected function setUp() {
      global $DB;
      
      $DB->connect();

      // Store Max(id) for each glpi tables
      $result = $DB->list_tables();
      while ($data=$DB->fetch_row($result)) {
         $query = "SELECT MAX(`id`) AS MAXID
                   FROM `".$data[0]."`";
         foreach ($DB->request($query) as $row) {
            $this->tables[$data[0]] = (empty($row['MAXID']) ? 0 : $row['MAXID']);
         }
      }
      $DB->free_result($result);

      $tab  = array();
      $auth = new Auth();
      // First session
      $auth->Login('glpi', 'glpi') ;

      // Create entity tree
      $entity = new Entity();
      $tab['entity'][0] = $entity->add(array('name' => 'PHP Unit root',
                                             'entities_id' => 0));

      if (!$tab['entity'][0]                                   // Crash detection
          || !FieldExists('glpi_profiles','notification')   // Schema detection
          || countElementsInTable('glpi_rules')!=6) {    // Old rules

         if (!$tab['entity'][0]) {
            echo "Couldn't run test (previous run not cleaned)\n";
         } else {
            echo "Schema need to be updated\n";
         }
         echo "Loading a fresh empty database:";
         $DB->runFile(GLPI_ROOT ."/install/mysql/glpi-0.84-empty.sql");
         die(" done\nTry again\n");
      }

      $tab['entity'][1] = $entity->add(array('name'        => 'PHP Unit Child 1',
                                             'entities_id' => $tab['entity'][0]));

      $tab['entity'][2] = $entity->add(array('name'        => 'PHP Unit Child 2',
                                             'entities_id' => $tab['entity'][0]));

      $tab['entity'][3] = $entity->add(array('name'        => 'PHP Unit Child 2.1',
                                             'entities_id' => $tab['entity'][2]));

      $tab['entity'][4] = $entity->add(array('name'        => 'PHP Unit Child 2.2',
                                             'entities_id' => $tab['entity'][2]));

      // New session with all the entities
      $auth->Login('glpi', 'glpi') or die("Login glpi/glpi invalid !\n");

      // Shared this with all tests
      $this->sharedFixture = $tab;
   }
 static function isMonitoredNetworkport($networkports_id)
 {
     global $DB;
     $nb = countElementsInTable("glpi_plugin_monitoring_networkports", "`networkports_id` = '" . $networkports_id . "'");
     if ($nb > 0) {
         return true;
     }
     return false;
 }
 public function testLog()
 {
     global $DB;
     $DB->connect();
     $pfFormatconvert = new PluginFusioninventoryFormatconvert();
     $computer = new Computer();
     $pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
     $date = date('Y-m-d H:i:s');
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $_SESSION['glpiactiveentities_string'] = 0;
     $_SESSION['glpishowallentities'] = 1;
     $_SESSION["glpiname"] = 'Plugin_FusionInventory';
     $this->a_inventory = array('fusioninventorycomputer' => array('winowner' => 'test', 'wincompany' => 'siprossii', 'operatingsystem_installationdate' => '2012-10-16 08:12:56', 'last_fusioninventory_update' => $date), 'soundcard' => array(), 'graphiccard' => array(), 'controller' => array(), 'processor' => array(), 'computerdisk' => array(), 'memory' => array(), 'monitor' => array(), 'printer' => array(), 'peripheral' => array(), 'networkport' => array(), 'SOFTWARES' => array(), 'harddrive' => array(), 'virtualmachine' => array(), 'antivirus' => array(), 'storage' => array(), 'licenseinfo' => array(), 'networkcard' => array(), 'drive' => array(), 'batteries' => array(), 'itemtype' => 'Computer');
     $this->a_inventory['Computer'] = array('name' => 'pc', 'users_id' => 0, 'operatingsystems_id' => 'freebsd', 'operatingsystemversions_id' => '9.1-RELEASE', 'uuid' => '68405E00-E5BE-11DF-801C-B05981201220', 'domains_id' => 'mydomain.local', 'os_licenseid' => '', 'os_license_number' => '', 'operatingsystemservicepacks_id' => 'GENERIC ()root@farrell.cse.buffalo.edu', 'manufacturers_id' => '', 'computermodels_id' => '', 'serial' => 'XB63J7D', 'computertypes_id' => 'Notebook', 'is_dynamic' => 1, 'contact' => 'ddurieux');
     $this->a_inventory['processor'] = array(array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400));
     $this->a_inventory['memory'] = array(array('size' => 2048, 'serial' => '98F6FF18', 'frequence' => '1067 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 1), array('size' => 2048, 'serial' => '95F1833E', 'frequence' => '1067 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 2));
     $this->a_inventory['monitor'] = array(array('name' => '', 'serial' => '', 'manufacturers_id' => ''));
     $this->a_inventory['networkport'] = array('em0-00:23:18:cf:0d:93' => array('name' => 'em0', 'netmask' => '255.255.255.0', 'subnet' => '192.168.30.0', 'mac' => '00:23:18:cf:0d:93', 'instantiation_type' => 'NetworkPortEthernet', 'virtualdev' => 0, 'ssid' => '', 'gateway' => '', 'dhcpserver' => '', 'logical_number' => 0, 'ipaddress' => array('192.168.30.198')), 'lo0-' => array('name' => 'lo0', 'virtualdev' => 1, 'mac' => '', 'instantiation_type' => 'NetworkPortLocal', 'subnet' => '', 'ssid' => '', 'gateway' => '', 'netmask' => '', 'dhcpserver' => '', 'logical_number' => 1, 'ipaddress' => array('::1', 'fe80::1', '127.0.0.1')));
     $this->a_inventory['software'] = array('gentiumbasic$$$$110$$$$1$$$$0' => array('name' => 'GentiumBasic', 'version' => 110, 'manufacturers_id' => 1, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1), 'imagemagick$$$$6.8.0.7_1$$$$2$$$$0' => array('name' => 'ImageMagick', 'version' => '6.8.0.7_1', 'manufacturers_id' => 2, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1), 'orbit2$$$$2.14.19$$$$3$$$$0' => array('name' => 'ORBit2', 'version' => '2.14.19', 'manufacturers_id' => 3, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1));
     $this->a_inventory = $pfFormatconvert->replaceids($this->a_inventory);
     $serialized = gzcompress(serialize($this->a_inventory));
     $this->a_inventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized);
     $computer->add(array('serial' => 'XB63J7D', 'entities_id' => 0));
     // truncate glpi_logs
     $DB->query('TRUNCATE TABLE `glpi_logs`;');
     $this->assertEquals(0, countElementsInTable('glpi_logs'), "Log must be empty (truncate)");
     $_SESSION['glpiactive_entity'] = 0;
     $pfiComputerLib->updateComputer($this->a_inventory, 1, TRUE);
     $a_logs = getAllDatasFromTable('glpi_logs');
     foreach ($a_logs as $id => $data) {
         unset($data['date_mod']);
         $a_logs[$id] = $data;
     }
     $a_reference = array(1 => array('id' => 1, 'itemtype' => 'Software', 'items_id' => 1, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 2 => array('id' => 2, 'itemtype' => 'Software', 'items_id' => 2, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 3 => array('id' => 3, 'itemtype' => 'Software', 'items_id' => 3, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 4 => array('id' => 4, 'itemtype' => 'SoftwareVersion', 'items_id' => 1, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 5 => array('id' => 5, 'itemtype' => 'SoftwareVersion', 'items_id' => 2, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 6 => array('id' => 6, 'itemtype' => 'SoftwareVersion', 'items_id' => 3, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''));
     $this->assertEquals($a_reference, $a_logs, "Log must be 6 " . print_r($a_logs, true));
     $DB->query('TRUNCATE `glpi_logs`');
     // Update a second time and must not have any new lines in glpi_logs
     $pfiComputerLib->updateComputer($this->a_inventory, 1, FALSE);
     $a_logs = getAllDatasFromTable('glpi_logs');
     $a_reference = array();
     $this->assertEquals($a_reference, $a_logs, "Log may be empty at second update " . print_r($a_logs, true));
     // * Modify: contact
     // * remove a processor
     // * Remove a software
     $this->a_inventory['Computer']['contact'] = 'root';
     unset($this->a_inventory['processor'][3]);
     unset($this->a_inventory['software']['orbit2$$$$2.14.19$$$$3$$$$0']);
     $DB->query('TRUNCATE `glpi_logs`');
     $pfiComputerLib->updateComputer($this->a_inventory, 1, FALSE);
     $a_logs = getAllDatasFromTable('glpi_logs');
     foreach ($a_logs as $id => $data) {
         unset($data['date_mod']);
         $a_logs[$id] = $data;
     }
     $a_reference = array(1 => array('id' => '1', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => '', 'linked_action' => '0', 'user_name' => '', 'id_search_option' => '7', 'old_value' => 'ddurieux', 'new_value' => 'root'), 2 => array('id' => '2', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => 'DeviceProcessor', 'linked_action' => '3', 'user_name' => '', 'id_search_option' => '0', 'old_value' => 'Core i3 (1)', 'new_value' => ''), 3 => array('id' => '3', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => 'SoftwareVersion', 'linked_action' => '5', 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => '0', 'old_value' => 'ORBit2 - 2.14.19 (3)', 'new_value' => ''), 4 => array('id' => '4', 'itemtype' => 'SoftwareVersion', 'items_id' => '3', 'itemtype_link' => 'Computer', 'linked_action' => '5', 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => '0', 'old_value' => 'pc (1)', 'new_value' => ''));
     $this->assertEquals($a_reference, $a_logs, "May have 5 logs (update contact, remove processor\n         and remove a software)");
 }
Exemplo n.º 8
0
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if (self::canView()) {
         if ($_SESSION['glpishow_count_on_tabs']) {
             return self::createTabEntry(_n('Link', 'Links', Session::getPluralNumber()), countElementsInTable('glpi_links_itemtypes', "`itemtype` = '" . $item->getType() . "'"));
         }
         return _n('Link', 'Links', Session::getPluralNumber());
     }
     return '';
 }
 /**
  * Report if a dropdown have Child
  * Used to (dis)allow delete action
  **/
 function haveChildren()
 {
     if (parent::haveChildren()) {
         return true;
     }
     $kb = new KnowbaseItem();
     $fk = $this->getForeignKeyField();
     $id = $this->fields['id'];
     return countElementsInTable($kb->getTable(), "`{$fk}`='{$id}'") > 0;
 }
Exemplo n.º 10
0
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if (!$withtemplate && $item->getType() == 'Computer' && Session::haveRight("computer", "r")) {
         if ($_SESSION['glpishow_count_on_tabs']) {
             return self::createTabEntry(self::getTypeName(2), countElementsInTable('glpi_computervirtualmachines', "computers_id = '" . $item->getID() . "'\n                                                                 AND `is_deleted`='0'"));
         }
         return self::getTypeName(2);
     }
     return '';
 }
Exemplo n.º 11
0
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if (Session::haveRight("link", "r")) {
         if ($_SESSION['glpishow_count_on_tabs']) {
             return self::createTabEntry(_n('Link', 'Links', 2), countElementsInTable('glpi_links_itemtypes', "`itemtype` = '" . $item->getType() . "'"));
         }
         return _n('Link', 'Links', 2);
     }
     return '';
 }
Exemplo n.º 12
0
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if (self::canView()) {
         if ($_SESSION['glpishow_count_on_tabs']) {
             $restrict = "`glpi_links_itemtypes`.`links_id` = `glpi_links`.`id`\n                         AND `glpi_links_itemtypes`.`itemtype` = '" . $item->getType() . "'" . getEntitiesRestrictRequest(" AND ", "glpi_links", '', '', true);
             return self::createTabEntry(_n('Link', 'Links', Session::getPluralNumber()), countElementsInTable(array('glpi_links_itemtypes', 'glpi_links'), $restrict));
         }
         return _n('Link', 'Links', Session::getPluralNumber());
     }
     return '';
 }
Exemplo n.º 13
0
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if (!$withtemplate && $item->getType() == 'Computer' && Computer::canView()) {
         $nb = 0;
         if ($_SESSION['glpishow_count_on_tabs']) {
             $nb = countElementsInTable('glpi_computervirtualmachines', "computers_id = '" . $item->getID() . "' AND `is_deleted`='0'");
         }
         return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb);
     }
     return '';
 }
 /**
  * @test
  */
 public function addTimeslot()
 {
     $pfTimeslot = new PluginFusioninventoryTimeslot();
     $input = array('entities_id' => 0, 'is_recursive' => 0, 'name' => 'unitdefault');
     $pfTimeslot->add($input);
     $cnt = countElementsInTable('glpi_plugin_fusioninventory_timeslots');
     $this->assertEquals(1, $cnt, "Timeslot may be added");
     $GLPIlog = new GLPIlogs();
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
 }
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     // can exists for template
     if ($item->getType() == 'TicketTemplate' && Session::haveRight("tickettemplate", READ)) {
         if ($_SESSION['glpishow_count_on_tabs']) {
             return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), countElementsInTable($this->getTable(), "`tickettemplates_id`\n                                                               = '" . $item->getID() . "'"));
         }
         return self::getTypeName(Session::getPluralNumber());
     }
     return '';
 }
Exemplo n.º 16
0
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     // can exists for template
     if ($item->getType() == static::$itemtype && static::canView()) {
         if ($_SESSION['glpishow_count_on_tabs']) {
             return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), countElementsInTable($this->getTable(), "`" . $item->getForeignKeyField() . "`\n                                                                = '" . $item->getID() . "'"));
         }
         return self::getTypeName(Session::getPluralNumber());
     }
     return '';
 }
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if ($item->getID() > 0) {
         if (get_class($item) == 'Computer') {
             if (countElementsInTable('glpi_plugin_fusioninventory_computerlicenseinfos', "`computers_id`='" . $item->getID() . "'") > 0) {
                 return array(__('Software licenses', 'fusioninventory'));
             }
         }
     }
     return array();
 }
Exemplo n.º 18
0
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     // can exists for template
     if ($item->getType() == 'Contract' && Contract::canView()) {
         if ($_SESSION['glpishow_count_on_tabs']) {
             return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), countElementsInTable('glpi_contractcosts', "contracts_id = '" . $item->getID() . "'"));
         }
         return self::getTypeName(Session::getPluralNumber());
     }
     return '';
 }
Exemplo n.º 19
0
 /**
  * Display tab for each users
  *
  * @param CommonGLPI $item
  * @param int $withtemplate
  * @return array|string
  */
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if (!$withtemplate) {
         if ($item->getType() == 'PluginBadgesBadge') {
             if ($_SESSION['glpishow_count_on_tabs']) {
                 return self::createTabEntry(PluginBadgesRequest::getTypeName(), countElementsInTable($this->getTable(), "`badges_id` = '" . $item->getID() . "'"));
             }
             return PluginBadgesRequest::getTypeName();
         }
     }
     return '';
 }
Exemplo n.º 20
0
 /**
  * Display followup's tab for each users
  *
  * @param CommonGLPI $item
  * @param int $withtemplate
  * @return array string
  */
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if (!$withtemplate) {
         if ($item->getType() == 'PluginProjetProjet') {
             if ($_SESSION['glpishow_count_on_tabs']) {
                 return self::createTabEntry(self::getTypeName(2), countElementsInTable($this->getTable(), "`plugin_projet_projets_id` = '" . $item->getID() . "'"));
             }
             return self::getTypeName(2);
         }
     }
     return '';
 }
Exemplo n.º 21
0
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     // can exists for template
     if ($item->getType() == 'Computer' && Computer::canView()) {
         $nb = 0;
         if ($_SESSION['glpishow_count_on_tabs']) {
             $nb = countElementsInTable('glpi_computerdisks', ['computers_id' => $item->getID(), 'is_deleted' => 0]);
         }
         return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb);
     }
     return '';
 }
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if ($item->getType() == 'Computer') {
         if (Session::haveRight('computer', READ)) {
             $a_nb = countElementsInTable(getTableForItemType("PluginFusioninventoryInventoryComputerStorage"), "`computers_id`='" . $item->getID() . "'");
             if (count($a_nb) > 0) {
                 //               return self::createTabEntry(__('Storage', 'fusioninventory'));
             }
         }
     }
     return '';
 }
Exemplo n.º 23
0
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     // can exists for template
     if ($item->getType() == 'Project' && Project::canView()) {
         $nb = 0;
         if ($_SESSION['glpishow_count_on_tabs']) {
             $nb = countElementsInTable('glpi_projectcosts', ['projects_id' => $item->getID()]);
         }
         return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb);
     }
     return '';
 }
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if (!$withtemplate && $item->getType() == 'PluginFusioninventoryDeployGroup' && $item->fields['type'] == PluginFusioninventoryDeployGroup::STATIC_GROUP) {
         $tabs[1] = _n('Criterion', 'Criteria', 2);
         $count = countElementsInTable(getTableForItemType(__CLASS__), "`itemtype`='Computer'\n                                    AND `plugin_fusioninventory_deploygroups_id`='" . $item->getID() . "'");
         if ($_SESSION['glpishow_count_on_tabs']) {
             $tabs[2] = self::createTabEntry(_n('Associated item', 'Associated items', $count), $count);
         } else {
             $tabs[2] = _n('Associated item', 'Associated items', $count);
         }
         return $tabs;
     }
     return '';
 }
 private function cleanDatabase()
 {
     global $DB;
     $networkport = new NetworkPort();
     if ($networkport->getFromDB($this->getID())) {
         if (!in_array($networkport->fields['instantiation_type'], NetworkPort::getNetworkPortInstantiations())) {
             $networkport->delete($networkport->fields);
         }
     }
     if (countElementsInTable($this->getTable()) == 0) {
         $query = "DROP TABLE `" . $this->getTable() . "`";
         $DB->query($query);
     }
 }
 /**
  * @param $values
  * @param $add             (true by default)
  * @param $rights    array
  **/
 function processAfterInsertOrUpdate($values, $add = true, $rights = array())
 {
     if (isset($values['Computer']['id'])) {
         $class = "Item_" . get_parent_class($this);
         $item = new $class();
         $foreign = getForeignKeyFieldForTable(getTableForItemType(get_parent_class($this)));
         if (!countElementsInTable($item->getTable(), "`{$foreign}`='" . $values[get_parent_class($this)]['id'] . "'\n                                       AND `itemtype`='Computer'\n                                       AND `items_id`='" . $values['Computer']['id'] . "'")) {
             $tmp[$foreign] = $values[get_parent_class($this)]['id'];
             $tmp['items_id'] = $values['Computer']['id'];
             $tmp['itemtype'] = 'Computer';
             $item->add($tmp);
         }
     }
 }
Exemplo n.º 27
0
 /**
  * Check right on an contract - overloaded to check max_links_allowed
  *
  * @param $ID ID of the item (-1 if new item)
  * @param $right Right to check : r / w / recursive
  * @param $input array of input data (used for adding item)
  *
  * @return boolean
  **/
 function can($ID, $right, &$input = NULL)
 {
     if ($ID < 0) {
         // Ajout
         $contract = new Contract();
         if (!$contract->getFromDB($input['contracts_id'])) {
             return false;
         }
         if ($contract->fields['max_links_allowed'] > 0 && countElementsInTable($this->getTable(), "`contracts_id`='" . $input['contracts_id'] . "'") >= $contract->fields['max_links_allowed']) {
             return false;
         }
     }
     return parent::can($ID, $right, $input);
 }
Exemplo n.º 28
0
 static function canView()
 {
     if (!isset($_SESSION['glpishowmigrationcleaner'])) {
         if (TableExists('glpi_networkportmigrations') && countElementsInTable('glpi_networkportmigrations') > 0) {
             $_SESSION['glpishowmigrationcleaner'] = true;
         } else {
             $_SESSION['glpishowmigrationcleaner'] = false;
         }
     }
     if ($_SESSION['glpishowmigrationcleaner'] && (Session::haveRight("networking", UPDATE) || Session::haveRight("internet", UPDATE))) {
         return true;
     }
     return false;
 }
 /**
  * @param $profile
  **/
 static function addDefaultProfileInfos($profiles_id, $rights)
 {
     $profileRight = new ProfileRight();
     foreach ($rights as $right => $value) {
         if (!countElementsInTable('glpi_profilerights', "`profiles_id`='{$profiles_id}' AND `name`='{$right}'")) {
             $myright['profiles_id'] = $profiles_id;
             $myright['name'] = $right;
             $myright['rights'] = $value;
             $profileRight->add($myright);
             //Add right to the current session
             $_SESSION['glpiactiveprofile'][$right] = $value;
         }
     }
 }
Exemplo n.º 30
0
 /**
  * @covers NetworkPort::prepareInputForAdd
  * @covers NetworkPort::post_addItem
  */
 public function testAddCompleteNetworkPort()
 {
     $this->Login();
     $computer1 = getItemByTypeName('Computer', '_test_pc01');
     // Do some installations
     $ins = new NetworkPort();
     // Be sure added
     $nb_log = countElementsInTable('glpi_logs');
     $this->assertGreaterThan(0, $ins->add(['items_id' => $computer1->getID(), 'itemtype' => 'Computer', 'entities_id' => $computer1->fields['entities_id'], 'is_recursive' => 0, 'logical_number' => 3, 'mac' => '00:24:81:eb:c6:d2', 'instantiation_type' => 'NetworkPortEthernet', 'name' => 'em3', 'comment' => 'Comment me!', 'netpoints_id' => 0, 'items_devicenetworkcards_id' => 0, 'type' => 'T', 'speed' => 1000, 'speed_other_value' => '', 'NetworkName_name' => 'test1.me', 'NetworkName_fqdns_id' => 0, 'NetworkName__ipaddresses' => ['-1' => '192.168.20.1']]));
     $this->assertGreaterThan($nb_log, countElementsInTable('glpi_logs'));
     // be sure added and have no logs
     $nb_log = countElementsInTable('glpi_logs');
     $this->assertGreaterThan(0, $ins->add(['items_id' => $computer1->getID(), 'itemtype' => 'Computer', 'entities_id' => $computer1->fields['entities_id'], 'is_recursive' => 0, 'logical_number' => 4, 'mac' => '00:24:81:eb:c6:d4', 'instantiation_type' => 'NetworkPortEthernet', 'name' => 'em4', 'comment' => 'Comment me!', 'netpoints_id' => 0, 'items_devicenetworkcards_id' => 0, 'type' => 'T', 'speed' => 1000, 'speed_other_value' => '', 'NetworkName_name' => 'test2.me', 'NetworkName_fqdns_id' => 0, 'NetworkName__ipaddresses' => ['-1' => '192.168.20.2']], [], false));
     $this->assertEquals($nb_log, countElementsInTable('glpi_logs'));
 }