Ejemplo n.º 1
0
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if (in_array($item->getType(), self::getTypes(true)) && plugin_manufacturersimports_haveRight('manufacturersimports', 'r') && !isset($withtemplate) || empty($withtemplate)) {
         $suppliername = self::checkManufacturerName($item->getType(), $item->getID());
         if ($suppliername) {
             return PluginManufacturersimportsPreImport::getTypeName(2);
         }
     }
     return '';
 }
Ejemplo n.º 2
0
function plugin_init_manufacturersimports()
{
    global $PLUGIN_HOOKS, $CFG_GLPI;
    $PLUGIN_HOOKS['csrf_compliant']['manufacturersimports'] = true;
    $PLUGIN_HOOKS['change_profile']['manufacturersimports'] = array('PluginManufacturersimportsProfile', 'changeProfile');
    //Clean Plugin on Profile delete
    $PLUGIN_HOOKS['pre_item_purge']['manufacturersimports'] = array('Profile' => array('PluginManufacturersimportsProfile', 'purgeProfiles'));
    if (Session::getLoginUserID()) {
        Plugin::registerClass('PluginManufacturersimportsProfile', array('addtabon' => 'Profile'));
        if (plugin_manufacturersimports_haveRight("manufacturersimports", "r")) {
            $PLUGIN_HOOKS['menu_entry']['manufacturersimports'] = 'front/import.php';
            $PLUGIN_HOOKS['submenu_entry']['manufacturersimports']['config'] = 'front/config.php';
            $PLUGIN_HOOKS['add_css']['manufacturersimports'] = "manufacturersimports.css";
            $PLUGIN_HOOKS['use_massive_action']['manufacturersimports'] = 1;
        }
        if (plugin_manufacturersimports_haveRight("manufacturersimports", "w") || Session::haveRight("config", "w")) {
            $PLUGIN_HOOKS['config_page']['manufacturersimports'] = 'front/config.php';
            $PLUGIN_HOOKS['submenu_entry']['manufacturersimports']['options']['config']['links']['search'] = '/plugins/manufacturersimports/front/config.php';
            $PLUGIN_HOOKS['submenu_entry']['manufacturersimports']['options']['config']['links']['add'] = '/plugins/manufacturersimports/front/config.form.php';
        }
        // End init, when all types are registered
        $PLUGIN_HOOKS['post_init']['manufacturersimports'] = 'plugin_manufacturersimports_postinit';
    }
}
Ejemplo n.º 3
0
 /**
  * Prints the model add form (into devices)
  *
  * @param $device the device ID
  * @param $type the device type
  * @return nothing (print out a table)
  *
  */
 static function showForm($itemtype, $items_id)
 {
     global $DB, $CFG_GLPI;
     $canedit = plugin_manufacturersimports_haveRight('manufacturersimports', 'w');
     $query = "SELECT *\n          FROM `glpi_plugin_manufacturersimports_models`\n          WHERE `itemtype` = '" . $itemtype . "'\n          AND `items_id` = '" . $items_id . "'";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/manufacturersimports/front/config.form.php\">";
     echo "<div align=\"center\"><table class=\"tab_cadre_fixe\"  cellspacing=\"2\" cellpadding=\"2\">";
     echo "<tr>";
     echo "<th>" . PluginManufacturersimportsPreImport::getTypeName(2) . "</th>";
     echo "<th>" . __('Model Number', 'manufacturersimports') . "</th>";
     echo "</tr>";
     if ($number == 1) {
         while ($line = $DB->fetch_array($result)) {
             $ID = $line["id"];
             echo "<tr class='tab_bg_2'>";
             echo "<td class='left'>";
             echo "<input type='text' name='model_name' size='30' value='" . $line["model_name"] . "'>";
             echo "</td>";
             if ($canedit) {
                 echo "<td class='center' class='tab_bg_2'>";
                 Html::showSimpleForm($CFG_GLPI['root_doc'] . '/plugins/manufacturersimports/front/config.form.php', 'delete_model', _x('button', 'Delete permanently'), array('id' => $ID));
                 echo "</td>";
             } else {
                 echo "<td>";
                 echo "</td>";
             }
             echo "</tr>";
         }
     } else {
         if ($canedit) {
             echo "<tr>";
             echo "<th colspan='2'>";
             echo "<input type='text' name='model_name' size='30'>";
             echo "<input type='hidden' name='items_id' value='" . $items_id . "'>";
             echo "<input type='hidden' name='itemtype' value='" . $itemtype . "'>";
             echo "<input type=\"submit\" name=\"update_model\" class=\"submit\" value='" . _sx('button', 'Save') . "' >";
             echo "</th></tr>";
         }
     }
     echo "</table></div>";
     Html::closeForm();
 }
Ejemplo n.º 4
0
 /**
  * Prints display pre import
  *
  * @param $type the type of device
  * @param $configID the ID of the supplier config
  * @param $start for pager display
  * @param $complete to see all device (already imported and not)
  * @return nothing (print out a table)
  *
  */
 static function seePreImport($params)
 {
     global $DB, $CFG_GLPI;
     // Default values of parameters
     $p['link'] = array();
     //
     $p['field'] = array();
     //
     $p['contains'] = array();
     //
     $p['searchtype'] = array();
     //*/
     $p['sort'] = '1';
     //
     $p['order'] = 'ASC';
     //
     $p['start'] = 0;
     //
     $p['export_all'] = 0;
     $p['link2'] = '';
     //
     $p['contains2'] = '';
     //
     $p['field2'] = '';
     //
     $p['itemtype2'] = '';
     $p['searchtype2'] = '';
     $p['itemtype'] = '';
     $p['manufacturers_id'] = '';
     $p['imported'] = '';
     foreach ($params as $key => $val) {
         $p[$key] = $val;
     }
     $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("searchtype", $p['searchtype']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("searchtype2", $p['searchtype2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']);
     $modeltable = "";
     $target = $CFG_GLPI["root_doc"] . "/plugins/manufacturersimports/front/import.php";
     if ($p['itemtype'] && $p['manufacturers_id']) {
         $config = new PluginManufacturersimportsConfig();
         $config->GetFromDB($p['manufacturers_id']);
         $suppliername = $config->fields["name"];
         $supplierclass = "PluginManufacturersimports" . $suppliername;
         $supplier = new $supplierclass();
         $infocom = new Infocom();
         $canedit = plugin_manufacturersimports_haveRight("manufacturersimports", "w") && $infocom->canUpdate();
         if (!$p['start']) {
             $p['start'] = 0;
         }
         $modeltable = getTableForItemType($p['itemtype'] . "Model");
         $modelfield = getForeignKeyFieldForTable(getTableForItemType($p['itemtype'] . "Model"));
         $item = new $p['itemtype']();
         $itemtable = getTableForItemType($p['itemtype']);
         $query = "SELECT `" . $itemtable . "`.`id`,\n                        `" . $itemtable . "`.`name`, \n                        `" . $itemtable . "`.`serial`,\n                        `" . $itemtable . "`.`entities_id`,\n                         `glpi_plugin_manufacturersimports_logs`.`import_status`,\n                          `glpi_plugin_manufacturersimports_logs`.`items_id`,\n                           `glpi_plugin_manufacturersimports_logs`.`itemtype`, \n                           `glpi_plugin_manufacturersimports_logs`.`documents_id`,\n                            `glpi_plugin_manufacturersimports_logs`.`date_import`, \n                            '" . $p['itemtype'] . "' AS type,\n                            `{$modeltable}`.`name` AS model_name\n                  FROM `" . $itemtable . "` ";
         //model device left join
         $query .= "LEFT JOIN `{$modeltable}` ON (`{$modeltable}`.`id` = `" . $itemtable . "`.`" . $modelfield . "`) ";
         $query .= " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemtable . "`.`entities_id`)";
         $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_configs` \n         ON (`glpi_plugin_manufacturersimports_configs`.`manufacturers_id` = `" . $itemtable . "`.`manufacturers_id`)";
         $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_logs` \n         ON (`glpi_plugin_manufacturersimports_logs`.`items_id` = `" . $itemtable . "`.`id` \n         AND `glpi_plugin_manufacturersimports_logs`.`itemtype` = '" . $p['itemtype'] . "')";
         $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_models` \n         ON (`glpi_plugin_manufacturersimports_models`.`items_id` = `" . $itemtable . "`.`id` \n         AND `glpi_plugin_manufacturersimports_models`.`itemtype` = '" . $p['itemtype'] . "')";
         //serial must be not empty
         $query .= " WHERE `" . $itemtable . "`.`is_deleted` = '0'\n          AND `" . $itemtable . "`.`is_template` = '0'\n          AND `glpi_plugin_manufacturersimports_configs`.`id` = '" . $p['manufacturers_id'] . "'\n          AND `" . $itemtable . "`.`serial` != '' ";
         //already imported
         if ($p['imported'] == self::IMPORTED) {
             $query .= " AND `import_status` != " . self::IMPORTED . "";
             //not imported
         } else {
             if ($p['imported'] == self::NOT_IMPORTED) {
                 $query .= " AND (`date_import` IS NULL OR `import_status` = " . self::IMPORTED . " ";
                 $query .= ") ";
             }
         }
         $entities = "";
         if ($config->isRecursive()) {
             $entities = getSonsOf('glpi_entities', $config->getEntityID());
         } else {
             $entities = $config->getEntityID();
         }
         $query .= "" . getEntitiesRestrictRequest(" AND", $itemtable, '', '', $item->maybeRecursive());
         //// 4 - ORDER
         $ORDER = " ORDER BY `entities_id`,`" . $itemtable . "`.`name` ";
         $toview = array("name" => 1);
         foreach ($toview as $key => $val) {
             if ($p['sort'] == $val) {
                 $ORDER = self::addOrderBy($p['itemtype'], $p['sort'], $p['order'], $key);
             }
         }
         $query .= $ORDER;
         $result = $DB->query($query);
         $numrows = $DB->numrows($result);
         if ($p['start'] < $numrows) {
             // Set display type for export if define
             $output_type = Search::HTML_OUTPUT;
             if (isset($_GET["display_type"])) {
                 $output_type = $_GET["display_type"];
             }
             $parameters = "itemtype=" . $p['itemtype'] . "&amp;manufacturers_id=" . $p['manufacturers_id'] . "&amp;imported=" . $p['imported'];
             $total = 0;
             if ($output_type == Search::HTML_OUTPUT) {
                 self::printPager($p['start'], $numrows, $target, $parameters, $p['itemtype']);
             }
             // Define begin and end var for loop
             // Search case
             $begin_display = $p['start'];
             $end_display = $p['start'] + $_SESSION["glpilist_limit"];
             // Export All case
             if (isset($_GET['export_all'])) {
                 $begin_display = 0;
                 $end_display = $numrows;
             }
             if (Session::isMultiEntitiesMode()) {
                 $colsup = 1;
             } else {
                 $colsup = 0;
             }
             //////////////////////HEADER///////////////
             if ($output_type == Search::HTML_OUTPUT) {
                 echo "<form method='post' name='massiveaction_form' id='massiveaction_form' action=\"../ajax/massiveaction.php\">";
             }
             //echo Search::displaySearchHeader($output_type,0); //table + div
             if ($canedit) {
                 $nbcols = 11 + $colsup;
             } else {
                 $nbcols = 10 + $colsup;
             }
             $LIST_LIMIT = $_SESSION['glpilist_limit'];
             $begin_display = $p['start'];
             $end_display = $p['start'] + $LIST_LIMIT;
             foreach ($toview as $key => $val) {
                 $linkto = '';
                 if (!isset($searchopt["PluginManufacturersimportsPreImport"][$val]['nosort']) || !$searchopt["PluginManufacturersimportsPreImport"][$val]['nosort']) {
                     $linkto = "{$target}?itemtype=" . $p['itemtype'] . "&amp;manufacturers_id=" . $p['manufacturers_id'] . "&amp;imported=" . $p['imported'] . "&amp;sort=" . $val . "&amp;order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&amp;start=" . $p['start'] . $globallinkto;
                 }
             }
             echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols);
             echo Search::showNewLine($output_type);
             $header_num = 1;
             echo Search::showHeaderItem($output_type, "", $header_num);
             echo Search::showHeaderItem($output_type, __('Name'), $header_num, $linkto, $p['sort'] == $val, $p['order']);
             if (Session::isMultiEntitiesMode()) {
                 echo Search::showHeaderItem($output_type, __('Entity'), $header_num);
             }
             echo Search::showHeaderItem($output_type, __('Entity'), $header_num);
             echo $supplier->showItemTitle($output_type, $header_num);
             echo Search::showHeaderItem($output_type, __('Financial and administrative information'), $header_num);
             echo Search::showHeaderItem($output_type, __('Supplier attached', 'manufacturersimports'), $header_num);
             echo Search::showHeaderItem($output_type, __('New warranty attached', 'manufacturersimports'), $header_num);
             echo Search::showHeaderItem($output_type, _n('Link', 'Links', 1), $header_num);
             echo Search::showHeaderItem($output_type, _n('Status', 'Statuses', 1), $header_num);
             echo $supplier->showDocTitle($output_type, $header_num);
             // End Line for column headers
             echo Search::showEndLine($output_type);
             $i = $p['start'];
             if (isset($_GET['export_all'])) {
                 $i = 0;
             }
             if ($i > 0) {
                 $DB->data_seek($result, $i);
             }
             $row_num = 1;
             while ($i < $numrows && $i < $end_display) {
                 $i++;
                 $item_num = 1;
                 $line = $DB->fetch_array($result);
                 $compSerial = $line['serial'];
                 $compId = $line['id'];
                 $model = $line["model_name"];
                 if (!$line["itemtype"]) {
                     $line["itemtype"] = $p['itemtype'];
                 }
                 self::showImport($row_num, $item_num, $line, $output_type, $p['manufacturers_id'], $line["import_status"], $p['imported']);
                 //1.show already imported items && import_status not failed
                 if ($p['imported'] == 1) {
                     $total += 1;
                 }
             }
             echo "<tr class='tab_bg_1'><td colspan='" . ($canedit ? 11 + $colsup : 10 + $colsup) . "'>";
             echo sprintf(__('Total number of devices to import %s', 'manufacturersimports'), $total);
             echo "</td></tr>";
             // Close Table
             $title = "";
             // Create title
             if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) {
                 $title .= PluginManufacturersimportsPreImport::getTypeName(2) . " " . $suppliername;
             }
             echo Search::showFooter($output_type, $title);
             //massive action
             if ($canedit && $output_type == Search::HTML_OUTPUT) {
                 Html::openArrowMassives("massiveaction_form", false);
                 self::dropdownMassiveAction($compId, $p['itemtype'], $p['manufacturers_id'], $p['start'], $p['imported']);
                 Html::closeArrowMassives(array());
                 Html::closeForm();
             } else {
                 echo "</table>";
                 echo "</div>";
             }
             echo "<br>";
             if ($output_type == Search::HTML_OUTPUT) {
                 self::printPager($p['start'], $numrows, $target, $parameters, $p['itemtype']);
             }
         } else {
             echo "<div align='center'><b>" . __('No device finded', 'manufacturersimports') . "</b></div>";
         }
     }
 }
Ejemplo n.º 5
0
function plugin_manufacturersimports_getAddSearchOptions($itemtype)
{
    $sopt = array();
    if (in_array($itemtype, PluginManufacturersimportsConfig::getTypes())) {
        if (plugin_manufacturersimports_haveRight("manufacturersimports", "r")) {
            $sopt[2150]['table'] = 'glpi_plugin_manufacturersimports_models';
            $sopt[2150]['field'] = 'model_name';
            $sopt[2150]['linkfield'] = '';
            $sopt[2150]['name'] = _n('Suppliers import', 'Suppliers imports', 2, 'manufacturersimports') . " - " . __('Model number', 'manufacturersimports');
            $sopt[2150]['forcegroupby'] = true;
            $sopt[2150]['joinparams'] = array('jointype' => 'itemtype_item');
            $sopt[2150]['massiveaction'] = false;
        }
    }
    return $sopt;
}