Author: Anis BEREJEB Toolbox class
 static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
 {
     echo "<form name='notificationtargets_form' id='notificationtargets_form'\n             method='post' action=' ";
     echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<table class    ='tab_cadre_fixe'>";
     echo '<tr><th colspan="2">' . __('Access type', 'formcreator') . '</th></tr>';
     echo '<td>' . __('Access', 'formcreator') . '</td>';
     echo '<td>';
     Dropdown::showFromArray('access_rights', array(PluginFormcreatorForm::ACCESS_PUBLIC => __('Public access', 'formcreator'), PluginFormcreatorForm::ACCESS_PRIVATE => __('Private access', 'formcreator'), PluginFormcreatorForm::ACCESS_RESTRICTED => __('Restricted access', 'formcreator')), array('value' => isset($item->fields["access_rights"]) ? $item->fields["access_rights"] : 1));
     echo '</td>';
     if ($item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_RESTRICTED) {
         echo '<tr><th colspan="2">' . self::getTypeName(2) . '</th></tr>';
         $table = getTableForItemType(__CLASS__);
         $table_profile = getTableForItemType('Profile');
         $query = "SELECT p.`id`, p.`name`, IF(f.`plugin_formcreator_profiles_id` IS NOT NULL, 1, 0) AS `profile`\n                   FROM {$table_profile} p\n                   LEFT JOIN {$table} f\n                     ON p.`id` = f.`plugin_formcreator_profiles_id`\n                     AND f.`plugin_formcreator_forms_id` = " . (int) $item->fields['id'];
         $result = $GLOBALS['DB']->query($query);
         while (list($id, $name, $profile) = $GLOBALS['DB']->fetch_array($result)) {
             $checked = $profile ? ' checked' : '';
             echo '<tr><td colspan="2"><label>';
             echo '<input type="checkbox" name="profiles_id[]" value="' . $id . '" ' . $checked . '> ';
             echo $name;
             echo '</label></td></tr>';
         }
     }
     echo '<tr>';
     echo '<td class="center" colspan="2">';
     echo '<input type="hidden" name="profiles_id[]" value="0" />';
     echo '<input type="hidden" name="form_id" value="' . (int) $item->fields['id'] . '" />';
     echo '<input type="submit" name="update" value="' . __('Save') . '" class="submit" />';
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
 }
 /**
  * Show form
  * 
  * @global type $CFG_GLPI
  * @param type $ID
  * @param type $options
  */
 function showForm($ID = 0, $options = array())
 {
     global $CFG_GLPI;
     echo "<div class='center first-bloc'>";
     echo "<form name='field_form' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . self::getTypeName() . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td class='tab_bg_2 center'>";
     echo PluginShellcommandsCommandGroup::getTypeName(1) . " ";
     Dropdown::show('PluginShellcommandsCommandGroup', array('entity' => $_SESSION['glpiactive_entity'], 'width' => 200));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td class='tab_bg_2 center'>";
     $this->getEditValue();
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td class='tab_bg_2 center'>";
     echo "<input type='button' class='submit' onclick='shellcommand_advanced_execution(\"" . $CFG_GLPI['root_doc'] . "\",\"field_form\", \"advanced_execution_result\");' name='advanced_execution' value='" . __('Execute') . "'/>";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
     echo "<div class='spaced' id='advanced_execution_result'></div>";
 }
 static function showForDocumentCategory($item)
 {
     $documentCategory = new self();
     if (!$documentCategory->getFromDBByQuery(" WHERE `documentcategories_id` = " . $item->fields['id'])) {
         $documentCategory->getEmpty();
     }
     echo "<form name='form' method='post' action='" . Toolbox::getItemTypeFormURL($documentCategory->getType()) . "'>";
     echo "<div align='center'><table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2'>" . __('Document category prefix', 'order') . "</th></tr>";
     echo "<tr class='tab_bg_1'>";
     // Dropdown group
     echo "<td>";
     echo __('Document category prefix', 'order');
     echo "</td>";
     echo "<td>";
     echo "<input type='text' name='documentcategories_prefix' value='" . $documentCategory->fields['documentcategories_prefix'] . "'>";
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td class='tab_bg_2 center' colspan='6'>";
     echo "<input type='submit' name='update' class='submit' value='" . _sx('button', 'Save') . "' >";
     echo "<input type='hidden' name='documentcategories_id' class='submit' value='" . $item->fields['id'] . "' >";
     echo "</td>";
     echo "</tr>";
     echo "</table></div>";
     Html::closeForm();
 }
Exemple #4
0
 public function showForm($ID, $options = array())
 {
     if (!$this->isNewID($ID)) {
         $this->check($ID, READ);
     } else {
         $this->check(-1, UPDATE);
     }
     $options['colspan'] = 2;
     $options['target'] = Toolbox::getItemTypeFormURL(__CLASS__);
     $this->showFormHeader($options);
     echo '<table class="tab_cadre_fixe">';
     echo "<tr class='line0'><td>" . __('Name') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "name");
     echo "</td>";
     echo "</tr>";
     echo "<tr class='line1'><td>" . __('Content') . "</td>";
     echo "<td>";
     echo "<textarea name='comment' id ='comment' >" . $this->fields['comment'] . "</textarea>";
     Html::initEditorSystem('comment');
     echo "</td>";
     echo "</tr>";
     $this->showFormButtons($options);
     return true;
 }
Exemple #5
0
 /**
  * Constructor
  *
  **/
 function __construct()
 {
     global $CFG_GLPI;
     $this->WordWrap = 80;
     $this->CharSet = "utf-8";
     // Comes from config
     $this->SetLanguage("en", Config::getLibraryDir("PHPMailer") . "/language/");
     if ($CFG_GLPI['smtp_mode'] != MAIL_MAIL) {
         $this->Mailer = "smtp";
         $this->Host = $CFG_GLPI['smtp_host'] . ':' . $CFG_GLPI['smtp_port'];
         if ($CFG_GLPI['smtp_username'] != '') {
             $this->SMTPAuth = true;
             $this->Username = $CFG_GLPI['smtp_username'];
             $this->Password = Toolbox::decrypt($CFG_GLPI['smtp_passwd'], GLPIKEY);
         }
         if ($CFG_GLPI['smtp_mode'] == MAIL_SMTPSSL) {
             $this->SMTPSecure = "ssl";
         }
         if ($CFG_GLPI['smtp_mode'] == MAIL_SMTPTLS) {
             $this->SMTPSecure = "tls";
         }
         if (!$CFG_GLPI['smtp_check_certificate']) {
             $this->SMTPOptions = array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true));
         }
     }
     if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
         $this->do_debug = 3;
     }
 }
 /**
  * CSV File parsing methods
  *
  * @param $fic
  * @param $data
  * @param $encoding  (default 1)
  **/
 static function parseLine($fic, $data, $encoding = 1)
 {
     global $DB;
     $csv = array();
     $num = count($data);
     for ($c = 0; $c < $num; $c++) {
         //If field is not the last, or if field is the last of the line and is not empty
         if ($c < $num - 1 || $c == $num - 1 && $data[$num - 1] != PluginDatainjectionCommonInjectionLib::EMPTY_VALUE) {
             $tmp = trim($DB->escape($data[$c]));
             switch ($encoding) {
                 //If file is ISO8859-1 : encode the datas in utf8
                 case PluginDatainjectionBackend::ENCODING_ISO8859_1:
                     if (!Toolbox::seems_utf8($tmp)) {
                         $csv[0][] = utf8_encode($tmp);
                     } else {
                         $csv[0][] = $tmp;
                     }
                     break;
                 case PluginDatainjectionBackend::ENCODING_UFT8:
                     $csv[0][] = $tmp;
                     break;
                 default:
                     //PluginDatainjectionBackend :: ENCODING_AUTO :
                     $csv[0][] = PluginDatainjectionBackend::toUTF8($tmp);
             }
         }
     }
     return $csv;
 }
Exemple #7
0
 /**
  * Konstruktor der Klasse
  *
  * @since   0.1
  * @change  0.1
  */
 public static function init()
 {
     /* Optionen */
     $options = get_option('toolbox');
     /* Sicherheit */
     if (!empty($options['secure'])) {
         if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE or defined('DOING_CRON') && DOING_CRON or defined('DOING_AJAX') && DOING_AJAX or defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) {
             return;
         }
     }
     /* Init */
     self::$plugin_path = plugin_basename(__FILE__);
     self::$modules_path = plugin_dir_path(__FILE__) . 'modules/';
     /* Module einbinden */
     self::_require_modules($options);
     /* Backend */
     if (is_admin()) {
         add_action('wpmu_new_blog', array(__CLASS__, 'install_later'));
         add_action('delete_blog', array(__CLASS__, 'uninstall_later'));
         add_action('admin_init', array(__CLASS__, 'register_settings'));
         add_action('admin_menu', array(__CLASS__, 'add_page'));
         add_filter('plugin_row_meta', array(__CLASS__, 'row_meta'), 10, 2);
         add_filter('plugin_action_links_' . self::$plugin_path, array(__CLASS__, 'action_links'));
     }
 }
 /**
  * Log when extra-debug is activated
  */
 static function logIfExtradebug($file, $message)
 {
     if (!PluginFusioninventoryConfig::isExtradebugActive()) {
         return;
     }
     Toolbox::logInFile($file, $message);
 }
 static function showForGroup(Group $group)
 {
     global $DB;
     $ID = $group->getField('id');
     if (!$group->can($ID, READ)) {
         return false;
     }
     $canedit = $group->can($ID, UPDATE);
     if ($canedit) {
         // Get data
         $item = new self();
         if (!$item->getFromDB($ID)) {
             $item->getEmpty();
         }
         $rand = mt_rand();
         echo "<form name='group_level_form{$rand}' id='group_level_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<input type='hidden' name='" . self::$items_id . "' value='{$ID}' />";
         echo "<div class='spaced'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th>" . __('Level attribution', 'itilcategorygroups') . "</th></tr>";
         echo "<tr class='tab_bg_2'><td class='center'>";
         Dropdown::showFromArray('lvl', array(NULL => "---", 1 => __('Level 1', 'itilcategorygroups'), 2 => __('Level 2', 'itilcategorygroups'), 3 => __('Level 3', 'itilcategorygroups'), 4 => __('Level 4', 'itilcategorygroups')), array('value' => $item->fields['lvl']));
         echo "</td></tr>";
         echo "</td><td class='center'>";
         if ($item->fields["id"]) {
             echo "<input type='hidden' name='id' value='" . $item->fields["id"] . "'>";
             echo "<input type='submit' name='update' value=\"" . __('Save') . "\"\n                   class='submit'>";
         } else {
             echo "<input type='submit' name='add' value=\"" . __('Save') . "\" class='submit'>";
         }
         echo "</td></tr>";
         echo "</table></div>";
         Html::closeForm();
     }
 }
 function sendProlog($input)
 {
     $input = gzcompress($input);
     $fp = fsockopen($this->server_ip, 80, $errno, $errstr, 30);
     if (!$fp) {
         echo "{$errstr} ({$errno})\n";
     } else {
         $out = "POST " . $this->server_urlpath . " HTTP/1.1\r\n";
         $out .= "Host: " . $this->server_ip . " \r\n";
         $out .= "Content-Length: " . strlen($input) . "\r\n";
         $out .= "Connection: close\r\n\r\n";
         fputs($fp, $out . $input);
         $zipped = "";
         while (!feof($fp)) {
             $line = fgets($fp, 4096);
             $zipped .= $line;
             if ($line == "\r\n") {
                 $zipped = "";
             }
         }
         fclose($fp);
         Toolbox::logInFile("RETSERV", $zipped . "\n");
         if (!gzuncompress($zipped)) {
             echo $zipped;
         }
         return gzuncompress($zipped);
     }
 }
Exemple #11
0
 public function testSlugify()
 {
     $original = 'My - string èé  Ê À ß';
     $expected = 'my-string-ee-e-a-sz';
     $result = Toolbox::slugify($original);
     $this->assertEquals($expected, $result);
 }
 static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item)
 {
     global $DB;
     $ID = $item->getField('id');
     if (!Session::haveRight('knowbase', 'r') || !Session::haveRight('faq', 'r')) {
         return false;
     }
     $knowbaseitemcategories_id = $item->getField('knowbaseitemcategories_id');
     $fullcategoryname = Html::clean(getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id));
     $question = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('name'), ENT_QUOTES, "UTF-8")));
     $answer = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('answer'), ENT_QUOTES, "UTF-8")));
     $pdf->setColumnsSize(100);
     if (Toolbox::strlen($fullcategoryname) > 0) {
         $pdf->displayTitle('<b>' . __('Category name') . '</b>');
         $pdf->displayLine($fullcategoryname);
     }
     if (Toolbox::strlen($question) > 0) {
         $pdf->displayTitle('<b>' . __('Subject') . '</b>');
         $pdf->displayText('', $question, 5);
     } else {
         $pdf->displayTitle('<b>' . __('No question found', 'pdf') . '</b>');
     }
     if (Toolbox::strlen($answer) > 0) {
         $pdf->displayTitle('<b>' . __('Content') . '</b>');
         $pdf->displayText('', $answer, 5);
     } else {
         $pdf->displayTitle('<b>' . __('No answer found') . '</b>');
     }
     $pdf->setColumnsSize(50, 15, 15, 10, 10);
     $pdf->displayTitle(__('Writer'), __('Creation date'), __('Last update'), __('FAQ'), _n('View', 'Views', 2));
     $pdf->displayLine(getUserName($item->fields["users_id"]), Html::convDateTime($item->fields["date"]), Html::convDateTime($item->fields["date_mod"]), Dropdown::getYesNo($item->fields["is_faq"]), $item->fields["view"]);
     $pdf->displaySpace();
 }
 /**
  * @see CommonDBTM::prepareInputForAdd()
  **/
 function prepareInputForAdd($input)
 {
     //LDAP parameters MUST be in lower case
     //because the are retieved in lower case  from the directory
     $input["value"] = Toolbox::strtolower($input["value"]);
     return $input;
 }
Exemple #14
0
 static function getMenuContent()
 {
     global $CFG_GLPI;
     $menu = array();
     $menu['title'] = self::getMenuName();
     $menu['page'] = '/plugins/datainjection/front/clientinjection.form.php';
     if (Session::haveRight(static::$rightname, READ)) {
         $image_model = "<img src='" . $CFG_GLPI["root_doc"] . "/pics/rdv.png' title='";
         $image_model .= PluginDatainjectionModel::getTypeName();
         $image_model .= "' alt='" . PluginDatainjectionModel::getTypeName() . "'>";
         $image_import = "<img src='" . $CFG_GLPI["root_doc"] . "/pics/actualiser.png' title='";
         $image_import .= __s('Injection of the file', 'datainjection');
         $image_import .= "' alt='" . __s('Injection of the file', 'datainjection') . "'>";
         $menu['options']['client']['title'] = self::getMenuName();
         $menu['options']['client']['page'] = Toolbox::getItemTypeSearchUrl('PluginDatainjectionModel', false);
         $menu['options']['client']['links']['search'] = '/plugins/datainjection/front/clientinjection.form.php';
         if (Session::haveRight('plugin_datainjection_model', READ)) {
             $menu['options']['model']['title'] = PluginDatainjectionModel::getTypeName();
             $menu['options']['model']['page'] = Toolbox::getItemTypeSearchUrl('PluginDatainjectionModel', false);
             $menu['options']['model']['links']['search'] = Toolbox::getItemTypeSearchUrl('PluginDatainjectionModel', false);
             $menu['options']['client']['links'][$image_model] = Toolbox::getItemTypeSearchUrl('PluginDatainjectionModel', false);
         }
         //$menu['options']['client']['links'][$image_model]  = Toolbox::getItemTypeSearchUrl('PluginDatainjectionModel', false);
         $menu['options']['model']['links'][$image_import] = '/plugins/datainjection/front/clientinjection.form.php';
         if (Session::haveRight('plugin_datainjection_model', UPDATE) || Session::haveRight('plugin_datainjection_model', CREATE)) {
             $menu['options']['model']['links']['add'] = Toolbox::getItemTypeFormUrl('PluginDatainjectionModel', false);
             $menu['options']['client']['links'][$image_model] = Toolbox::getItemTypeSearchUrl('PluginDatainjectionModel', false);
         }
     }
     return $menu;
 }
Exemple #15
0
 public function update_password($password, $email)
 {
     $password = Toolbox::helper('Hash')->encrypt($password);
     $q = "UPDATE users SET password = ? WHERE email = ?";
     $r = $this->db->prepare($q);
     $r->execute(array($password, $email));
 }
 function getDatasForTemplate($event, $options = array())
 {
     global $CFG_GLPI;
     if ($event == 'AlertNotValidatedTypology') {
         $this->datas['##typology.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
         $this->datas['##lang.typology.entity##'] = __('Entity');
         $this->datas['##typology.action##'] = __('Elements not match with the typology', 'typology');
         $this->datas['##lang.typology.name##'] = PluginTypologyTypology::getTypeName(1);
         $this->datas['##lang.typology.itemtype##'] = __('Type');
         $this->datas['##lang.typology.items_id##'] = __('Name');
         $this->datas['##lang.typology.error##'] = __('Error');
         $this->datas['##lang.typology.url##'] = __('Link to the typology', 'typology');
         $this->datas['##lang.typology.itemurl##'] = __('Link to the element', 'typology');
         $this->datas['##lang.typology.itemuser##'] = __('User');
         $this->datas['##lang.typology.itemlocation##'] = __('Location');
         foreach ($options['items'] as $id => $item) {
             $tmp = array();
             $tmp['##typology.name##'] = $item['name'];
             $itemtype = new $item['itemtype']();
             $itemtype->getFromDB($item["items_id"]);
             $tmp['##typology.itemtype##'] = $itemtype->getTypeName();
             $tmp['##typology.items_id##'] = $itemtype->getName();
             $tmp['##typology.error##'] = PluginTypologyTypology_Item::displayErrors($item['error'], false);
             $tmp['##typology.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=plugin_typology_" . $item['plugin_typology_typologies_id']);
             $tmp['##typology.itemurl##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=" . Toolbox::strtolower($item['itemtype']) . "_" . $item["items_id"]);
             $tmp['##typology.itemuser##'] = getUserName($itemtype->fields["users_id"]);
             $tmp['##typology.itemlocation##'] = Dropdown::getDropdownName("glpi_locations", $itemtype->fields['locations_id']);
             $this->datas['typologyitems'][] = $tmp;
         }
     }
 }
Exemple #17
0
 /**
  * Constructor
  *
  **/
 function __construct()
 {
     global $CFG_GLPI;
     $this->WordWrap = 80;
     $this->CharSet = "utf-8";
     // Comes from config
     $this->SetLanguage("en", GLPI_PHPMAILER_DIR . "/language/");
     if ($CFG_GLPI['smtp_mode'] != MAIL_MAIL) {
         $this->Mailer = "smtp";
         $this->Host = $CFG_GLPI['smtp_host'] . ':' . $CFG_GLPI['smtp_port'];
         if ($CFG_GLPI['smtp_username'] != '') {
             $this->SMTPAuth = true;
             $this->Username = $CFG_GLPI['smtp_username'];
             $this->Password = Toolbox::decrypt($CFG_GLPI['smtp_passwd'], GLPIKEY);
         }
         if ($CFG_GLPI['smtp_mode'] == MAIL_SMTPSSL) {
             $this->SMTPSecure = "ssl";
         }
         if ($CFG_GLPI['smtp_mode'] == MAIL_SMTPTLS) {
             $this->SMTPSecure = "tls";
         }
     }
     if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
         $this->do_debug = 3;
     }
 }
 public function showForm($ID, $options = array())
 {
     if (!$this->isNewID($ID)) {
         $this->check($ID, READ);
     } else {
         $this->check(-1, UPDATE);
     }
     $options['colspan'] = 2;
     $options['target'] = Toolbox::getItemTypeFormURL(__CLASS__);
     $this->showFormHeader($options);
     echo '<table class="tab_cadre_fixe">';
     echo "<tr class='line0'><td>" . __('Name') . " <span class='red'>*</span></td>";
     echo "<td>";
     //Html::autocompletionTextField($this, "name");
     echo '<input type="text" name="name" value="' . $this->fields['name'] . '" size="40" required>';
     echo "</td>";
     echo "</tr>";
     echo "<tr class='line1'><td>" . __('Description') . "</td>";
     echo "<td>";
     echo "<textarea name='comment' id ='comment' cols='45' rows='2'>" . $this->fields['comment'] . "</textarea>";
     //Html::initEditorSystem('comment');
     echo "</td>";
     echo "</tr>";
     echo "<tr class='line1'><td>" . __('HTML color', 'tag') . "</td>";
     echo "<td>";
     Html::showColorField('color', array('value' => $this->fields['color']));
     echo "</td>";
     echo "</tr>";
     $this->showFormButtons($options);
     return true;
 }
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     return;
     if ($item->getType() == 'PluginCustomTab' && $item->canView()) {
         return Toolbox::ucfirst(_n("Profile", "Profiles", 1));
     }
     return '';
 }
 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)");
 }
 /**
  * Function to update Printer
  *
  * @param array $a_inventory data fron agent inventory
  * @param id $items_id id of the printer
  *
  * @return nothing
  */
 function updatePrinter($a_inventory, $items_id)
 {
     global $DB;
     $printer = new Printer();
     $pfPrinter = new PluginFusioninventoryPrinter();
     $printer->getFromDB($items_id);
     if (!isset($_SESSION['glpiactiveentities_string'])) {
         $_SESSION['glpiactiveentities_string'] = $printer->fields['entities_id'];
     }
     if (!isset($_SESSION['glpiactiveentities'])) {
         $_SESSION['glpiactiveentities'] = array($printer->fields['entities_id']);
     }
     if (!isset($_SESSION['glpiactive_entity'])) {
         $_SESSION['glpiactive_entity'] = $printer->fields['entities_id'];
     }
     // * Printer
     $db_printer = $printer->fields;
     $a_lockable = PluginFusioninventoryLock::getLockFields('glpi_printers', $items_id);
     $a_ret = PluginFusioninventoryToolbox::checkLock($a_inventory['Printer'], $db_printer, $a_lockable);
     $a_inventory['Printer'] = $a_ret[0];
     $input = $a_inventory['Printer'];
     $input['id'] = $items_id;
     $printer->update($input);
     // * Printer fusion (ext)
     $db_printer = array();
     $query = "SELECT *\n            FROM `" . getTableForItemType("PluginFusioninventoryPrinter") . "`\n            WHERE `printers_id` = '{$items_id}'";
     $result = $DB->query($query);
     while ($data = $DB->fetch_assoc($result)) {
         foreach ($data as $key => $value) {
             $db_printer[$key] = Toolbox::addslashes_deep($value);
         }
     }
     if (count($db_printer) == '0') {
         // Add
         $a_inventory['PluginFusioninventoryPrinter']['printers_id'] = $items_id;
         $pfPrinter->add($a_inventory['PluginFusioninventoryPrinter']);
     } else {
         // Update
         $idtmp = $db_printer['id'];
         unset($db_printer['id']);
         unset($db_printer['printers_id']);
         unset($db_printer['plugin_fusioninventory_configsecurities_id']);
         $a_ret = PluginFusioninventoryToolbox::checkLock($a_inventory['PluginFusioninventoryPrinter'], $db_printer);
         $a_inventory['PluginFusioninventoryPrinter'] = $a_ret[0];
         $input = $a_inventory['PluginFusioninventoryPrinter'];
         $input['id'] = $idtmp;
         $pfPrinter->update($input);
     }
     // * Ports
     $this->importPorts($a_inventory, $items_id);
     // Page counters
     $this->importPageCounters($a_inventory['pagecounters'], $items_id);
     // Cartridges
     $this->importCartridges($a_inventory['cartridge'], $items_id);
 }
Exemple #22
0
 static function getMenuContent()
 {
     global $CFG_GLPI;
     $menu = array();
     $menu['title'] = self::getMenuName();
     $menu['page'] = '/plugins/connections/front/connection.php';
     $menu['links'] = array('add' => Toolbox::getItemTypeFormURL('PluginConnectionsConnection', false), 'search' => Toolbox::getItemTypeSearchURL('PluginConnectionsConnection', false));
     if (Session::haveRight(static::$rightname, READ)) {
         $menu['options']['connections'] = array('title' => self::getMenuName(), 'page' => Toolbox::getItemTypeFormURL('PluginConnectionsConnection', false), 'links' => array('add' => Toolbox::getItemTypeFormURL('PluginConnectionsConnection', false), 'search' => Toolbox::getItemTypeSearchURL('PluginConnectionsConnection', false)));
     }
     return $menu;
 }
 static function postClone(NotificationTemplate $clone, $oldid)
 {
     global $DB;
     $trad = new NotificationTemplateTranslation();
     $fkey = getForeignKeyFieldForTable($clone->getTable());
     $crit = array($fkey => $oldid);
     foreach ($DB->request($trad->getTable(), $crit) as $data) {
         unset($data['id']);
         $data[$fkey] = $clone->getID();
         $trad->add(Toolbox::addslashes_deep($data));
     }
 }
Exemple #24
0
function decodeFromUtf8Array(&$arg)
{
    if (is_array($arg)) {
        foreach (array_keys($arg) as $key) {
            decodeFromUtf8Array($arg[$key]);
        }
    } else {
        if (is_string($arg)) {
            $arg = Toolbox::decodeFromUtf8($arg);
        }
    }
}
Exemple #25
0
 function post_addItem()
 {
     //only log in file, important events (connections and critical events; TODO : we need to add a general option to filter this in 9.1)
     if (isset($this->fields['level']) && $this->fields['level'] <= 3) {
         $message_type = "";
         if (isset($this->fields['type']) && $this->fields['type'] != 'system') {
             $message_type = "[" . $this->fields['type'] . " " . $this->fields['id'] . "] ";
         }
         $full_message = "[" . $this->fields['service'] . "] " . $message_type . $this->fields['level'] . ": " . Toolbox::stripslashes_deep($this->fields['message']) . "\n";
         Toolbox::logInFile("event", $full_message);
     }
 }
Exemple #26
0
 static function pdfDevice(PluginPdfSimplePDF $pdf, Computer $computer)
 {
     global $DB;
     $devtypes = Item_Devices::getDeviceTypes();
     $ID = $computer->getField('id');
     if (!$computer->can($ID, 'r')) {
         return false;
     }
     $pdf->setColumnsSize(100);
     $pdf->displayTitle('<b>' . Toolbox::ucfirst(_n('Component', 'Components', 2)) . '</b>');
     $pdf->setColumnsSize(3, 14, 42, 41);
     foreach ($devtypes as $itemtype) {
         $devicetypes = new $itemtype();
         $specificities = $devicetypes->getSpecificities();
         $specif_fields = array_keys($specificities);
         $specif_text = implode(',', $specif_fields);
         if (!empty($specif_text)) {
             $specif_text = " ," . $specif_text . " ";
         }
         $associated_type = str_replace('Item_', '', $itemtype);
         $linktable = getTableForItemType($itemtype);
         $fk = getForeignKeyFieldForTable(getTableForItemType($associated_type));
         $query = "SELECT count(*) AS NB, `id`, `" . $fk . "`" . $specif_text . "\n                   FROM `" . $linktable . "`\n                   WHERE `items_id` = '" . $ID . "'\n                   AND `itemtype` = 'Computer'\n                   GROUP BY `" . $fk . "`" . $specif_text;
         $device = new $associated_type();
         foreach ($DB->request($query) as $data) {
             if ($device->getFromDB($data[$fk])) {
                 $spec = $device->getAdditionalFields();
                 $col4 = '';
                 if (count($spec)) {
                     $colspan = 60 / count($spec);
                     foreach ($spec as $i => $label) {
                         if (isset($device->fields[$label["name"]]) && !empty($device->fields[$label["name"]])) {
                             if ($label["type"] == "dropdownValue" && $device->fields[$label["name"]] != 0) {
                                 $table = getTableNameForForeignKeyField($label["name"]);
                                 $value = Dropdown::getDropdownName($table, $device->fields[$label["name"]]);
                                 $col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', Html::clean($value) . " ");
                             } else {
                                 $value = $device->fields[$label["name"]];
                                 $col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $value . " ");
                             }
                         } else {
                             if (isset($device->fields[$label["name"] . "_default"]) && !empty($device->fields[$label["name"] . "_default"])) {
                                 $col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $device->fields[$label["name"] . "_default"] . " ");
                             }
                         }
                     }
                 }
                 $pdf->displayLine($data['NB'], $device->getTypeName(), $device->getName(), $col4);
             }
         }
     }
     $pdf->displaySpace();
 }
 /**
  * Set complete delivery address for this order.
  * @param $data
  */
 public function setDeliveryAddress($data)
 {
     $this->firstname = Toolbox::cleanName($data['firstname']);
     $this->lastname = Toolbox::cleanName($data['lastname']);
     $this->address1 = $data['address1'];
     $this->postcode = Toolbox::cleanPostCode($data['postcode']);
     $this->city = $data['city'];
     $this->id_country = (int) $data['id_country'];
     $this->id_state = (int) $data['id_state'];
     $this->phone = $data['phone'];
     $this->state_address = 1;
     $this->update();
 }
Exemple #28
0
 static function install(Migration $mig)
 {
     global $DB;
     $table = 'glpi_plugin_sccm_configs';
     if (!TableExists($table)) {
         $query = "CREATE TABLE `" . $table . "`(\n                     `id` int(11) NOT NULL,\n                     `sccmdb_host` VARCHAR(255) NULL,\n                     `sccmdb_dbname` VARCHAR(255) NULL,\n                     `sccmdb_user` VARCHAR(255) NULL,\n                     `sccmdb_password` VARCHAR(255) NULL,\n                     `fusioninventory_url` VARCHAR(255) NULL,\n                     `active_sync` tinyint(1) NOT NULL default '0',\n                     `date_mod` datetime default NULL,\n                     `comment` text,\n                     PRIMARY KEY  (`id`)\n                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
         $DB->queryOrDie($query, __("Error when using glpi_plugin_sccm_configs table.", "sccm") . "<br />" . $DB->error());
         $sccmdb_password = Toolbox::encrypt("", GLPIKEY);
         $query = "INSERT INTO `{$table}`\n                         (id, date_mod, sccmdb_host, sccmdb_dbname, \n                           sccmdb_user, sccmdb_password, fusioninventory_url)\n                   VALUES (1, NOW(), 'srv_sccm','bdd_sccm','user_sccm','" . $sccmdb_password . "',\n                           'http://glpi/plugins/fusioninventory/front/communication.php')";
         $DB->queryOrDie($query, __("Error when using glpi_plugin_sccm_configs table.", "sccm") . "<br />" . $DB->error());
     }
     return true;
 }
 function manageContacts($items_id)
 {
     $pmContact = new PluginMonitoringContact();
     $user = new User();
     $a_list = $this->find("`plugin_monitoring_hosts_id`='" . $items_id . "'");
     echo "<form name='contacts_form' id='contacts_form'\n             method='post' action=' ";
     echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th colspan='3'>";
     echo __('Contacts', 'monitoring');
     echo "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td class='right'>";
     $a_contacts = $pmContact->find();
     $a_elements = array();
     foreach ($a_contacts as $data) {
         $user->getFromDB($data['users_id']);
         $a_elements[$data['id']] = $user->getName();
     }
     asort($a_elements);
     Dropdown::showFromArray('plugin_monitoring_contacts_id', $a_elements);
     echo "</td>";
     echo "<td class='center'>";
     echo "<input type='submit' class='submit' name='parent_add' value='" . __('Add') . " >>'>";
     echo "<br><br>";
     if ($a_list) {
         echo "<input type='submit' class='submit' name='parent_delete' value='<< " . _sx('button', 'Delete permanently') . "'>";
     }
     echo "</td>";
     echo "<td>";
     if ($a_list) {
         echo "<select name='parent_to_delete[]' multiple size='5'>";
         foreach ($a_list as $data) {
             $pmContact->getFromDB($data['plugin_monitoring_contacts_id']);
             $user->getFromDB($pmContact->fields['users_id']);
             echo "<option value='" . $data['plugin_monitoring_contacts_id'] . "'>" . $user->getName() . "</option>";
         }
         echo "</select>";
     } else {
         echo "&nbsp;";
     }
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     echo "<input type='hidden' name='id' value='" . $items_id . "' />";
     Html::closeForm();
 }
Exemple #30
0
function plugin_positions_uninstall()
{
    global $DB;
    $tables = array("glpi_plugin_positions_positions", "glpi_plugin_positions_positions_items", "glpi_plugin_positions_profiles", "glpi_plugin_positions_imageitems", "glpi_plugin_positions_infos");
    foreach ($tables as $table) {
        $DB->query("DROP TABLE IF EXISTS `{$table}`;");
    }
    $rep_files_positions = GLPI_PLUGIN_DOC_DIR . "/positions";
    Toolbox::deleteDir($rep_files_positions);
    $tables_glpi = array("glpi_displaypreferences", "glpi_documents_items", "glpi_bookmarks", "glpi_logs", "glpi_tickets");
    foreach ($tables_glpi as $table_glpi) {
        $DB->query("DELETE FROM `{$table_glpi}` WHERE `itemtype` = 'PluginPositionsPosition' ;");
    }
    return true;
}