Beispiel #1
0
 /**
  * Function that try to load from LDAP the user information...
  *
  * @param $ldap_connection          ldap connection descriptor
  * @param $ldap_method              LDAP method
  * @param $userdn                   Basedn of the user
  * @param $login                    User Login
  * @param $import          boolean  true for import, false for update (true by default)
  *
  * @return boolean : true if found / false if not founded
  **/
 function getFromLDAP($ldap_connection, $ldap_method, $userdn, $login, $import = true)
 {
     global $DB, $CFG_GLPI;
     // we prevent some delay...
     if (empty($ldap_method["host"])) {
         return false;
     }
     if ($ldap_connection) {
         //Set all the search fields
         $this->fields['password'] = "";
         $fields = AuthLDAP::getSyncFields($ldap_method);
         //Hook to allow plugin to request more attributes from ldap
         $fields = Plugin::doHookFunction("retrieve_more_field_from_ldap", $fields);
         $fields = array_filter($fields);
         $f = array_values($fields);
         $sr = @ldap_read($ldap_connection, $userdn, "objectClass=*", $f);
         $v = AuthLDAP::get_entries_clean($ldap_connection, $sr);
         if (!is_array($v) || count($v) == 0 || empty($v[0][$fields['name']][0])) {
             return false;
         }
         //Store user's dn
         $this->fields['user_dn'] = addslashes($userdn);
         //Store date_sync
         $this->fields['date_sync'] = $_SESSION['glpi_currenttime'];
         // Empty array to ensure than syncDynamicEmails will be done
         $this->fields["_emails"] = array();
         foreach ($fields as $k => $e) {
             if (empty($v[0][$e][0])) {
                 switch ($k) {
                     case "language":
                         // Not set value : managed but user class
                         break;
                     case "usertitles_id":
                     case "usercategories_id":
                         $this->fields[$k] = 0;
                         break;
                     default:
                         $this->fields[$k] = "";
                 }
             } else {
                 switch ($k) {
                     case "email1":
                     case "email2":
                     case "email3":
                     case "email4":
                         // Manage multivaluable fields
                         if (!empty($v[0][$e])) {
                             foreach ($v[0][$e] as $km => $m) {
                                 if (!preg_match('/count/', $km)) {
                                     $this->fields["_emails"][] = addslashes($m);
                                 }
                             }
                             // Only get them once if duplicated
                             $this->fields["_emails"] = array_unique($this->fields["_emails"]);
                         }
                         break;
                     case "language":
                         $language = Config::getLanguage($v[0][$e][0]);
                         if ($language != '') {
                             $this->fields[$k] = $language;
                         }
                         break;
                     case "usertitles_id":
                         $this->fields[$k] = Dropdown::importExternal('UserTitle', addslashes($v[0][$e][0]));
                         break;
                     case "usercategories_id":
                         $this->fields[$k] = Dropdown::importExternal('UserCategory', addslashes($v[0][$e][0]));
                         break;
                     default:
                         if (!empty($v[0][$e][0])) {
                             $this->fields[$k] = addslashes($v[0][$e][0]);
                         } else {
                             $this->fields[$k] = "";
                         }
                 }
             }
         }
         // Empty array to ensure than syncLdapGroups will be done
         $this->fields["_groups"] = array();
         ///The groups are retrieved by looking into an ldap user object
         if ($ldap_method["group_search_type"] == 0 || $ldap_method["group_search_type"] == 2) {
             $this->getFromLDAPGroupVirtual($ldap_connection, $ldap_method, $userdn, $login);
         }
         ///The groups are retrived by looking into an ldap group object
         if ($ldap_method["group_search_type"] == 1 || $ldap_method["group_search_type"] == 2) {
             $this->getFromLDAPGroupDiscret($ldap_connection, $ldap_method, $userdn, $login);
         }
         ///Only process rules if working on the master database
         if (!$DB->isSlave()) {
             //Instanciate the affectation's rule
             $rule = new RuleRightCollection();
             //Process affectation rules :
             //we don't care about the function's return because all
             //the datas are stored in session temporary
             if (isset($this->fields["_groups"])) {
                 $groups = $this->fields["_groups"];
             } else {
                 $groups = array();
             }
             $this->fields = $rule->processAllRules($groups, Toolbox::stripslashes_deep($this->fields), array('type' => 'LDAP', 'ldap_server' => $ldap_method["id"], 'connection' => $ldap_connection, 'userdn' => $userdn));
             $this->fields['_ruleright_process'] = true;
             //If rule  action is ignore import
             if ($import && isset($this->fields["_stop_import"])) {
                 return false;
             }
             //or no rights found & do not import users with no rights
             if ($import && !$CFG_GLPI["use_noright_users_add"]) {
                 $ok = false;
                 if (isset($this->fields["_ldap_rules"]) && count($this->fields["_ldap_rules"])) {
                     if (isset($this->fields["_ldap_rules"]["rules_entities_rights"]) && count($this->fields["_ldap_rules"]["rules_entities_rights"])) {
                         $ok = true;
                     }
                     if (!$ok) {
                         $entity_count = 0;
                         $right_count = 0;
                         if (Profile::getDefault()) {
                             $right_count++;
                         }
                         if (isset($this->fields["_ldap_rules"]["rules_entities"])) {
                             $entity_count += count($this->fields["_ldap_rules"]["rules_entities"]);
                         }
                         if (isset($this->input["_ldap_rules"]["rules_rights"])) {
                             $right_count += count($this->fields["_ldap_rules"]["rules_rights"]);
                         }
                         if ($entity_count && $right_count) {
                             $ok = true;
                         }
                     }
                 }
                 if (!$ok) {
                     $this->fields["_stop_import"] = true;
                     return false;
                 }
             }
             // Add ldap result to data send to the hook
             $this->fields['_ldap_result'] = $v;
             $this->fields['_ldap_conn'] = $ldap_connection;
             //Hook to retrieve more information for ldap
             $this->fields = Plugin::doHookFunction("retrieve_more_data_from_ldap", $this->fields);
             unset($this->fields['_ldap_result']);
         }
         return true;
     }
     return false;
 }
Beispiel #2
0
 /**
  * Display form to unlock fields and links
  *
  * @param CommonDBTM $item the source item
  **/
 static function showForItem(CommonDBTM $item)
 {
     global $DB;
     $ID = $item->getID();
     $itemtype = $item->getType();
     $header = false;
     //If user doesn't have write right on the item, lock form must not be displayed
     if (!$item->canCreate()) {
         return false;
     }
     echo "<div width='50%'>";
     echo "<form method='post' id='lock_form'\n             name='lock_form' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<input type='hidden' name='id' value='{$ID}'>\n";
     echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2''>" . __('Locked items') . "</th></tr>";
     //Use a hook to allow external inventory tools to manage per field lock
     $results = Plugin::doHookFunction('display_locked_fields', array('item' => $item, 'header' => $header));
     $header |= $results['header'];
     //Special locks for computers only
     if ($itemtype == 'Computer') {
         //Locks for items recorded in glpi_computers_items table
         $types = array('Monitor', 'Peripheral', 'Printer');
         foreach ($types as $type) {
             $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID, 'itemtype' => $type);
             $params['FIELDS'] = array('id', 'items_id');
             $first = true;
             foreach ($DB->request('glpi_computers_items', $params) as $line) {
                 $tmp = new $type();
                 $tmp->getFromDB($line['items_id']);
                 $header = true;
                 if ($first) {
                     echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
                     $first = false;
                 }
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='Computer_Item[" . $line['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>" . $tmp->getName() . "</td>";
                 echo "</tr>\n";
             }
         }
         $types = array('ComputerDisk', 'ComputerVirtualMachine');
         foreach ($types as $type) {
             $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
             $params['FIELDS'] = array('id', 'name');
             $first = true;
             foreach ($DB->request(getTableForItemType($type), $params) as $line) {
                 $header = true;
                 if ($first) {
                     echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
                     $first = false;
                 }
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='" . $type . "[" . $line['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>" . $line['name'] . "</td>";
                 echo "</tr>\n";
             }
         }
         //Software versions
         $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
         $first = true;
         $query = "SELECT `csv`.`id` AS `id`,\n                           `sv`.`name` AS `version`,\n                           `s`.`name` AS `software`\n                    FROM `glpi_computers_softwareversions` AS csv\n                    LEFT JOIN `glpi_softwareversions` AS sv\n                       ON (`csv`.`softwareversions_id` = `sv`.`id`)\n                    LEFT JOIN `glpi_softwares` AS s\n                       ON (`sv`.`softwares_id` = `s`.`id`)\n                    WHERE `csv`.`is_deleted` = '1'\n                          AND `csv`.`is_dynamic` = '1'\n                          AND `csv`.`computers_id` = '{$ID}'";
         foreach ($DB->request($query) as $line) {
             $header = true;
             if ($first) {
                 echo "<tr><th colspan='2'>" . Software::getTypeName(2) . "</th></tr>\n";
                 $first = false;
             }
             echo "<tr class='tab_bg_1'><td class='center' width='10'>";
             echo "<input type='checkbox' name='Computer_SoftwareVersion[" . $line['id'] . "]'></td>";
             echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
             echo "</tr>\n";
         }
         //Software licenses
         $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
         $first = true;
         $query = "SELECT `csv`.`id` AS `id`,\n                           `sv`.`name` AS `version`,\n                           `s`.`name` AS `software`\n                    FROM `glpi_computers_softwarelicenses` AS csv\n                    LEFT JOIN `glpi_softwarelicenses` AS sv\n                       ON (`csv`.`softwarelicenses_id` = `sv`.`id`)\n                    LEFT JOIN `glpi_softwares` AS s\n                       ON (`sv`.`softwares_id` = `s`.`id`)\n                    WHERE `csv`.`is_deleted` = '1'\n                          AND `csv`.`is_dynamic` = '1'\n                          AND `csv`.`computers_id` = '{$ID}'";
         foreach ($DB->request($query) as $line) {
             $header = true;
             if ($first) {
                 echo "<tr><th colspan='2'>" . SoftwareLicense::getTypeName(2) . "</th>" . "</tr>\n";
                 $first = false;
             }
             echo "<tr class='tab_bg_1'><td class='center' width='10'>";
             echo "<input type='checkbox' name='Computer_SoftwareLicense[" . $line['id'] . "]'></td>";
             echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
             echo "</tr>\n";
         }
     }
     $first = true;
     $item = new NetworkPort();
     $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'items_id' => $ID, 'itemtype' => $itemtype);
     $params['FIELDS'] = array('id');
     foreach ($DB->request('glpi_networkports', $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . NetworkPort::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='NetworkPort[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $first = true;
     $item = new NetworkName();
     $params = array('`glpi_networknames`.`is_dynamic`' => 1, '`glpi_networknames`.`is_deleted`' => 1, '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
     $params['FIELDS'] = array('glpi_networknames' => 'id');
     foreach ($DB->request(array('glpi_networknames', 'glpi_networkports'), $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . NetworkName::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='NetworkName[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $first = true;
     $item = new IPAddress();
     $params = array('`glpi_ipaddresses`.`is_dynamic`' => 1, '`glpi_ipaddresses`.`is_deleted`' => 1, '`glpi_ipaddresses`.`itemtype`' => 'Networkname', '`glpi_ipaddresses`.`items_id`' => '`glpi_networknames`.`id`', '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
     $params['FIELDS'] = array('glpi_ipaddresses' => 'id');
     foreach ($DB->request(array('glpi_ipaddresses', 'glpi_networknames', 'glpi_networkports'), $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . IPAddress::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='IPAddress[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $types = Item_Devices::getDeviceTypes();
     $nb = 0;
     foreach ($types as $old => $type) {
         $nb += countElementsInTable(getTableForItemType($type), "`items_id`='{$ID}'\n                                         AND `itemtype`='{$itemtype}'\n                                         AND `is_dynamic`='1'\n                                         AND `is_deleted`='1'");
     }
     if ($nb) {
         $header = true;
         echo "<tr><th colspan='2'>" . _n('Component', 'Components', 2) . "</th></tr>\n";
         foreach ($types as $old => $type) {
             $associated_type = str_replace('Item_', '', $type);
             $associated_table = getTableForItemType($associated_type);
             $fk = getForeignKeyFieldForTable($associated_table);
             $query = "SELECT `i`.`id`,\n                             `t`.`designation` AS `name`\n                      FROM `" . getTableForItemType($type) . "` AS i\n                      LEFT JOIN `{$associated_table}` AS t\n                         ON (`t`.`id` = `i`.`{$fk}`)\n                      WHERE `itemtype` = '{$itemtype}'\n                            AND `items_id` = '{$ID}'\n                            AND `is_dynamic` = '1'\n                            AND `is_deleted` = '1'";
             foreach ($DB->request($query) as $data) {
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='" . $type . "[" . $data['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>";
                 printf(__('%1$s: %2$s'), $associated_type::getTypeName(), $data['name']);
                 echo "</td></tr>\n";
             }
         }
     }
     if ($header) {
         echo "</table>";
         Html::openArrowMassives('lock_form', true);
         Html::closeArrowMassives(array('unlock' => _sx('button', 'Unlock')));
     } else {
         echo "<tr class='tab_bg_2'>";
         echo "<td class='center' colspan='2'>" . __('No locked item') . "</td></tr>";
         echo "</table>";
     }
     Html::closeForm();
     echo "</div>\n";
 }
Beispiel #3
0
 /**
  * Find a user in a LDAP and return is BaseDN
  * Based on GRR auth system
  *
  * @param $ldap_method  ldap_method array to use
  * @param $login        User Login
  * @param $password     User Password
  *
  * @return String : basedn of the user / false if not founded
  **/
 function connection_ldap($ldap_method, $login, $password)
 {
     // we prevent some delay...
     if (empty($ldap_method['host'])) {
         return false;
     }
     $this->ldap_connection = AuthLdap::tryToConnectToServer($ldap_method, $login, $password);
     $this->user_deleted_ldap = false;
     if ($this->ldap_connection) {
         $params['method'] = AuthLDAP::IDENTIFIER_LOGIN;
         $params['fields'][AuthLDAP::IDENTIFIER_LOGIN] = $ldap_method['login_field'];
         $infos = AuthLdap::searchUserDn($this->ldap_connection, array('basedn' => $ldap_method['basedn'], 'login_field' => $ldap_method['login_field'], 'search_parameters' => $params, 'user_params' => array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $login), 'condition' => $ldap_method['condition'], 'user_dn' => $this->user_dn));
         $dn = $infos['dn'];
         if (!empty($dn) && @ldap_bind($this->ldap_connection, $dn, $password)) {
             //Hook to implement to restrict access by checking the ldap directory
             if (Plugin::doHookFunction("restrict_ldap_auth", $dn)) {
                 return $dn;
             }
             $this->addToError(__('User not authorized to connect in GLPI'));
             //Use is present by has no right to connect because of a plugin
             return false;
         } else {
             // Incorrect login
             $this->addToError(__('Incorrect username or password'));
             //Use is not present anymore in the directory!
             if ($dn == '') {
                 $this->user_deleted_ldap = true;
             }
             return false;
         }
     } else {
         $this->addToError(__('Unable to connect to the LDAP directory'));
         //Directory is not available
         return false;
     }
 }
Beispiel #4
0
 public static function unsetUndisclosedFields(&$fields)
 {
     if (isset($fields['context']) && isset($fields['name'])) {
         if ($fields['context'] == 'core' && in_array($fields['name'], self::$undisclosedFields)) {
             unset($fields['value']);
         } else {
             $fields = Plugin::doHookFunction('undiscloseConfigValue', $fields);
         }
     }
 }
Beispiel #5
0
 You should have received a copy of the GNU General Public License
 along with GLPI. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
*/
/** @file
 * @brief
 * @since version 0.84
*/
include '../inc/includes.php';
if (isset($_POST['itemtype']) && isset($_POST["unlock"])) {
    $itemtype = $_POST['itemtype'];
    $source_item = new $itemtype();
    if ($source_item->canCreate()) {
        $source_item->check($_POST['id'], UPDATE);
        $actions = array("Computer_Item", "Computer_SoftwareLicense", "Computer_SoftwareVersion", "ComputerDisk", "ComputerVirtualMachine", "NetworkPort", "NetworkName", "IPAddress");
        $devices = Item_Devices::getDeviceTypes();
        $actions = array_merge($actions, array_values($devices));
        foreach ($actions as $type) {
            if (isset($_POST[$type]) && count($_POST[$type])) {
                $item = new $type();
                foreach ($_POST[$type] as $key => $val) {
                    //Force unlock
                    $item->restore(array('id' => $key));
                }
            }
        }
    }
}
//Execute hook to unlock fields managed by a plugin, if needed
Plugin::doHookFunction('unlock_fields', $_POST);
Html::back();
Beispiel #6
0
 /**
  * Requests the nodes from the GLPI database
  **/
 function getNodesFromDb()
 {
     global $DB, $CFG_GLPI;
     // get entity name
     foreach ($_SESSION['glpiactiveprofile']['entities'] as $entity) {
         $ID = $entity['id'];
     }
     $sql = "SELECT `glpi_entities`.`completename` AS entity\n                       FROM `glpi_entities`\n                       WHERE `id` = '{$ID}'";
     $req = $DB->request($sql);
     if ($nb = $req->numrows()) {
         foreach ($req as $data) {
             $ent = $data["entity"];
         }
     }
     // The tree object
     echo "var d = new dTree('d');\n";
     echo "d.add(0,-1,'" . __($ent, 'treeview') . "');\n";
     $config = new PluginTreeviewConfig();
     // Request the display settings from the database and store them in the global object $config
     $this->getFromDB(1);
     $itemName = $this->fields["itemName"];
     $locationName = $this->fields["locationName"];
     $target = $this->fields["target"];
     $folderLinks = $this->fields["folderLinks"];
     $useSelection = $this->fields["useSelection"];
     $useLines = $this->fields["useLines"];
     $useIcons = $this->fields["useIcons"];
     $closeSameLevel = $this->fields["closeSameLevel"];
     // Load the settings in JavaSript so that dTree script can apply them
     echo "d.config.target         = '" . $target . "';\n";
     echo "d.config.folderLinks    = " . $folderLinks . ";\n";
     echo "d.config.useSelection   = " . $useSelection . ";\n";
     echo "d.config.useLines       = " . $useLines . ";\n";
     echo "d.config.useIcons       = " . $useIcons . ";\n";
     echo "d.config.closeSameLevel = " . $closeSameLevel . ";\n";
     $dontLoad = 'false';
     // Get the lowest level of the tree nodes and the highest primary key
     $query = "  SELECT MAX(`id`) AS `max_id`,\n                         MAX(`level`) AS `max_level`\n                  FROM `glpi_locations` ";
     $query .= getEntitiesRestrictRequest(" WHERE ", "glpi_locations", '', '', true);
     $result = $DB->query($query);
     $max_level = $DB->result($result, 0, "max_level");
     $tv_id = $max_id = $DB->result($result, 0, "max_id");
     $tv_id++;
     // Is this the first time we load the page?
     if (isset($_GET['nodes']) && $_GET['nodes'] != "") {
         // If no then get all the nodes requested by the client
         $nodes = array_reverse(explode('.', $_GET['nodes']));
     } else {
         // If yes then get only the root node
         $nodes[0] = 0;
     }
     // If an item group is requested, then save its type to use it later in the openTo function
     if (isset($_GET['openedType']) && $_GET['openedType'] != "") {
         $openedType = $_GET['openedType'];
     } else {
         $openedType = -1;
     }
     // Characters which need to be removed from JS output.
     $trans = array("\"" => "`", "\r" => " ", "\n" => " ");
     for ($n = 1; $n <= count($nodes); $n++) {
         if ($nodes[$n - 1] <= $max_id && $n <= $max_level) {
             $query = "SELECT *\n                      FROM `glpi_locations`\n                      WHERE `level` = '{$n}'\n                            AND `locations_id` = '" . $nodes[$n - 1] . "'";
             $query .= getEntitiesRestrictRequest(" AND ", "glpi_locations", '', '', true);
             $query .= "ORDER BY `completename` ASC";
             $result = $DB->query($query);
             while ($r = $DB->fetch_assoc($result)) {
                 // Location's name schema
                 if ($locationName == 0) {
                     $l_name = $r['name'];
                 } else {
                     if ($locationName == 1) {
                         $l_name = $r['completename'];
                     } else {
                         if ($locationName == 2) {
                             $l_name = $r['name'];
                             if ($r['comment'] != "") {
                                 $l_name .= ' (' . $r['comment'] . ')';
                             }
                         } else {
                             if ($locationName == 3) {
                                 $l_name = $r['completename'];
                                 if ($r['comment'] != "") {
                                     $l_name .= ' (' . $r['comment'] . ')';
                                 }
                             }
                         }
                     }
                 }
                 // Is this location requested by the user to be opened
                 if (in_array($r['id'], $nodes)) {
                     echo "d.add(" . $r['id'] . ", " . $r['locations_id'] . ", \"" . strtr($l_name, $trans) . "\", true, -1,'');\n";
                     $dontLoad = 'true';
                     // Then add aloso its items
                     foreach (self::$types as $type) {
                         $item = new $type();
                         $itemtable = getTableForItemType($type);
                         $query = "SELECT *\n                               FROM `{$itemtable}`\n                               WHERE `locations_id` = '" . $r['id'] . "'";
                         if ($item->maybeTemplate()) {
                             $query .= " AND `{$itemtable}`.`is_template` = '0'";
                         }
                         if ($item->maybeDeleted()) {
                             $query .= " AND `{$itemtable}`.`is_deleted` = '0'";
                         }
                         if ($this->isEntityAssign()) {
                             $query .= " AND `{$itemtable}`.`entities_id` = '" . $_SESSION["glpiactive_entity"] . "'";
                         }
                         $query .= " ORDER BY `{$itemtable}`.`name`";
                         $result_1 = $DB->query($query);
                         if ($DB->numrows($result_1)) {
                             $pid = $tv_id;
                             $field_num = 3;
                             $query_location = "SELECT `completename`\n                                           FROM `glpi_locations`\n                                           WHERE `id` = '" . $r['id'] . "'";
                             $result_location = $DB->query($query_location);
                             while ($row = $DB->fetch_assoc($result_location)) {
                                 $name_location = $row['completename'];
                             }
                             $getParam = '?is_deleted=0' . '&criteria[0][field]=' . $field_num . '&criteria[0][searchtype]=equals&criteria[0][value]=' . $r['id'] . '&itemtype=' . $type;
                             // Add items parent node
                             echo "d.add({$tv_id}," . $r['id'] . ",\"" . strtr($item::getTypeName(2), $trans) . "\", {$dontLoad}, '" . $type . "', '" . Toolbox::getItemTypeSearchURL($type) . $getParam . "', '', '', '" . self::getPicbyType($type) . "', '" . self::getPicbyType($type) . "');\n";
                             if ($openedType == $type && $nodes[count($nodes) - 1] == $tv_id) {
                                 $openedType = $tv_id;
                             }
                             $tv_id++;
                         }
                         while ($r_1 = $DB->fetch_assoc($result_1)) {
                             // Item's name schema
                             if ($itemName == 0 || $type == 'Software') {
                                 $i_name = $r_1['name'];
                             } else {
                                 if ($itemName == 1) {
                                     if (isset($r_1['otherserial']) && !empty($r_1['otherserial'])) {
                                         $i_name = $r_1['otherserial'];
                                     } else {
                                         $i_name = $r_1['name'];
                                     }
                                 } else {
                                     if ($itemName == 2) {
                                         $i_name = $r_1['name'] != "" ? $r_1['name'] : "";
                                         if (isset($r_1['otherserial']) && !empty($r_1['otherserial'])) {
                                             $i_name .= $r_1['otherserial'] != "" ? $r_1['name'] != "" ? ' / ' . $r_1['otherserial'] : $r_1['otherserial'] : "";
                                         } else {
                                             $i_name .= '';
                                         }
                                     } else {
                                         if ($itemName == 3) {
                                             if (isset($r_1['otherserial']) && !empty($r_1['otherserial'])) {
                                                 $i_name = $r_1['otherserial'] != "" ? $r_1['otherserial'] : "";
                                                 $i_name .= $r_1['name'] != "" ? $r_1['otherserial'] != "" ? ' / ' . $r_1['name'] : $r_1['name'] : "";
                                             } else {
                                                 $i_name = $r_1['name'];
                                             }
                                         }
                                     }
                                 }
                             }
                             $url = Toolbox::getItemTypeFormURL($type) . "?id=" . $r_1['id'];
                             $pic = "pics/node.gif";
                             $name = strtr($i_name, $trans);
                             $opt = array('url' => $url, 'pic' => $pic, 'name' => $name);
                             $params = array('itemtype' => $type, 'id' => $r_1['id'], 'url' => $url, 'pic' => $pic, 'name' => $name);
                             $opt = Plugin::doHookFunction('treeview_params', $params);
                             // Add the item
                             echo "d.add(" . $tv_id++ . ", {$pid}, \"" . $opt['name'] . "\", true, -1, '" . $opt['url'] . "', '', '', '" . $opt['pic'] . "','" . $opt['pic'] . "');\n";
                         }
                     }
                     // Add only the location without its items
                 } else {
                     echo "d.add(" . $r['id'] . "," . $r['locations_id'] . ",\"" . strtr($l_name, $trans) . "\", false, -1,'', '', '', '', '', false, true);\n";
                 }
             }
         }
     }
     // Print the node from JavaScript
     echo "document.write(d);\n";
     // Open the tree to the desired node
     if ($openedType != -1) {
         echo "d.openTo(" . $openedType . ");\n";
     } else {
         echo "d.openTo(" . $nodes[count($nodes) - 1] . ");\n";
     }
 }
Beispiel #7
0
 static function addPluginInfos(CommonDBTM $item)
 {
     Plugin::doHookFunction("infocom", $item);
 }
Beispiel #8
0
function plugin_datainjection_update170_20()
{
    global $DB;
    $migration = new Migration('2.0');
    $migration->changeField('glpi_plugin_datainjection_models', 'ID', 'id', 'autoincrement');
    $migration->changeField('glpi_plugin_datainjection_models', 'type', 'filetype', 'string', array('value' => 'csv'));
    $migration->addField('glpi_plugin_datainjection_models', 'step', 'integer');
    $migration->changeField('glpi_plugin_datainjection_models', 'comments', 'comment', 'text');
    $migration->changeField('glpi_plugin_datainjection_models', 'device_type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_models', 'FK_entities', 'entities_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_models', 'private', 'is_private', 'bool');
    $migration->changeField('glpi_plugin_datainjection_models', 'FK_users', 'users_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_models', 'recursive', 'is_recursive', 'bool');
    $migration->migrationOneTable('glpi_plugin_datainjection_models');
    $query = "UPDATE `glpi_plugin_datainjection_models`\n             SET `step` = '5'";
    $DB->query($query);
    $query = "UPDATE `glpi_plugin_datainjection_models`\n             SET `filetype` = 'csv'";
    $DB->queryOrDie($query, "update filetype of glpi_plugin_datainjection_models");
    $migration->dropTable('glpi_plugin_datainjection_filetype');
    $migration->renameTable('glpi_plugin_datainjection_models_csv', 'glpi_plugin_datainjection_modelcsvs');
    $migration->changeField('glpi_plugin_datainjection_modelcsvs', 'model_id', 'models_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_modelcsvs', 'device_type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_modelcsvs', 'header_present', 'is_header_present', 'bool', array('value' => 1));
    $migration->changeField('glpi_plugin_datainjection_mappings', 'mandatory', 'is_mandatory', 'bool');
    $migration->changeField('glpi_plugin_datainjection_mappings', 'type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_mappings', 'model_id', 'models_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_infos', 'type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_infos', 'model_id', 'models_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_infos', 'mandatory', 'is_mandatory', 'bool');
    $glpitables = array('glpi_plugin_datainjection_models', 'glpi_plugin_datainjection_mappings', 'glpi_plugin_datainjection_infos', 'glpi_plugin_datainjection_modelcsvs', 'glpi_plugin_datainjection_profiles');
    foreach ($glpitables as $table) {
        $migration->changeField($table, 'ID', 'id', 'autoincrement');
    }
    $migration->migrationOneTable('glpi_plugin_datainjection_mappings');
    $migration->migrationOneTable('glpi_plugin_datainjection_infos');
    $migration->migrationOneTable('glpi_plugin_datainjection_modelcsvs');
    $glpitables = array('glpi_plugin_datainjection_models', 'glpi_plugin_datainjection_mappings', 'glpi_plugin_datainjection_infos', 'glpi_plugin_datainjection_modelcsvs');
    Plugin::migrateItemType(array(), array(), $glpitables);
    $query = "UPDATE `glpi_plugin_datainjection_mappings`\n             SET `itemtype` = 'none' ,\n                 `value`='none'\n             WHERE `itemtype` = '-1'";
    $DB->queryOrDie($query, "Datainjection mappings tables : error updating not mapped fields");
    $migration->migrationOneTable('glpi_plugin_datainjection_infos');
    $query = "UPDATE `glpi_plugin_datainjection_infos`\n             SET `itemtype` = 'none', `value` = 'none'\n             WHERE `itemtype` = '-1'";
    $DB->queryOrDie($query, "Datainjection infos table : error updating not mapped fields");
    $foreignkeys = array('assign' => array(array('to' => 'users_id_assign', 'tables' => array('glpi_tickets'))), 'assign_group' => array(array('to' => 'groups_id_assign', 'tables' => array('glpi_tickets'))), 'assign_ent' => array(array('to' => 'suppliers_id_assign', 'tables' => array('glpi_tickets'))), 'auth_method' => array(array('to' => 'authtype', 'noindex' => array('glpi_users'), 'tables' => array('glpi_users'))), 'author' => array(array('to' => 'users_id', 'tables' => array('glpi_ticketfollowups', 'glpi_knowbaseitems', 'glpi_tickets'))), 'auto_update' => array(array('to' => 'autoupdatesystems_id', 'tables' => array('glpi_computers'))), 'budget' => array(array('to' => 'budgets_id', 'tables' => array('glpi_infocoms'))), 'buy_version' => array(array('to' => 'softwareversions_id_buy', 'tables' => array('glpi_softwarelicenses'))), 'category' => array(array('to' => 'ticketcategories_id', 'tables' => array('glpi_tickets')), array('to' => 'softwarecategories_id', 'tables' => array('glpi_softwares'))), 'categoryID' => array(array('to' => 'knowbaseitemcategories_id', 'tables' => array('glpi_knowbaseitems'))), 'cID' => array(array('to' => 'computers_id', 'tables' => array('glpi_computers_softwareversions'))), 'computer' => array(array('to' => 'items_id', 'tables' => array('glpi_tickets'))), 'computer_id' => array(array('to' => 'computers_id', 'tables' => array('glpi_registrykeys'))), 'contract_type' => array(array('to' => 'contracttypes_id', 'tables' => array('glpi_contracts'))), 'default_rubdoc_tracking' => array(array('to' => 'documentcategories_id_forticket', 'tables' => array('glpi_configs'), 'comments' => array('glpi_configs' => 'default category for documents added with a ticket'))), 'device_type' => array(array('to' => 'itemtype', 'tables' => array('glpi_alerts', 'glpi_contracts_items', 'glpi_documents_items', 'glpi_infocoms', 'glpi_bookmarks', 'glpi_bookmarks_users', 'glpi_links_itemtypes', 'glpi_networkports', 'glpi_reservationitems', 'glpi_tickets'))), 'domain' => array(array('to' => 'domains_id', 'tables' => array('glpi_computers', 'glpi_networkequipments', 'glpi_printers'))), 'end1' => array(array('to' => 'items_id', 'tables' => array('glpi_computers_items'), 'comments' => array('glpi_computers_items' => 'RELATION to various table, according to itemtype (ID)')), array('to' => 'networkports_id_1', 'tables' => array('glpi_networkports_networkports'))), 'end2' => array(array('to' => 'computers_id', 'tables' => array('glpi_computers_items')), array('to' => 'networkports_id_2', 'tables' => array('glpi_networkports_networkports'))), 'firmware' => array(array('to' => 'networkequipmentfirmwares_id', 'tables' => array('glpi_networkequipments'))), 'FK_bookmark' => array(array('to' => 'bookmarks_id', 'tables' => array('glpi_bookmarks_users'))), 'FK_computers' => array(array('to' => 'computers_id', 'tables' => array('glpi_computerdisks', 'glpi_softwarelicenses'))), 'FK_contact' => array(array('to' => 'contacts_id', 'tables' => array('glpi_contacts_suppliers'))), 'FK_contract' => array(array('to' => 'contracts_id', 'tables' => array('glpi_contracts_suppliers', 'glpi_contracts_items'))), 'FK_device' => array(array('to' => 'items_id', 'tables' => array('glpi_alerts', 'glpi_contracts_items', 'glpi_documents_items', 'glpi_infocoms'))), 'FK_doc' => array(array('to' => 'documents_id', 'tables' => array('glpi_documents_items'))), 'manufacturer' => array(array('to' => 'suppliers_id', 'tables' => array('glpi_contacts_suppliers', 'glpi_contracts_suppliers', 'glpi_infocoms')), array('to' => 'manufacturers_id', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_devicecases', 'glpi_devicecontrols', 'glpi_devicedrives', 'glpi_devicegraphiccards', 'glpi_deviceharddrives', 'glpi_devicenetworkcards', 'glpi_devicemotherboards', 'glpi_devicepcis', 'glpi_devicepowersupplies', 'glpi_deviceprocessors', 'glpi_devicememories', 'glpi_devicesoundcards', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'FK_entities' => array(array('to' => 'entities_id', 'tables' => array('glpi_bookmarks', 'glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_locations', 'glpi_netpoints', 'glpi_suppliers', 'glpi_entitydatas', 'glpi_groups', 'glpi_knowbaseitems', 'glpi_links', 'glpi_mailcollectors', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_reminders', 'glpi_rules', 'glpi_softwares', 'glpi_softwarelicenses', 'glpi_softwareversions', 'glpi_tickets', 'glpi_users', 'glpi_profiles_users'), 'default' => array('glpi_bookmarks' => "-1"))), 'FK_filesystems' => array(array('to' => 'filesystems_id', 'tables' => array('glpi_computerdisks'))), 'FK_glpi_cartridges_type' => array(array('to' => 'cartridgeitems_id', 'tables' => array('glpi_cartridges', 'glpi_cartridges_printermodels'))), 'FK_glpi_consumables_type' => array(array('to' => 'consumableitems_id', 'tables' => array('glpi_consumables'))), 'FK_glpi_dropdown_model_printers' => array(array('to' => 'printermodels_id', 'tables' => array('glpi_cartridges_printermodels'))), 'FK_glpi_printers' => array(array('to' => 'printers_id', 'tables' => array('glpi_cartridges'))), 'FK_group' => array(array('to' => 'groups_id', 'tables' => array('glpi_tickets'))), 'FK_groups' => array(array('to' => 'groups_id', 'tables' => array('glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares', 'glpi_groups_users'))), 'FK_interface' => array(array('to' => 'interfacetypes_id', 'tables' => array('glpi_devicegraphiccards'))), 'FK_item' => array(array('to' => 'items_id', 'tables' => array('glpi_mailingsettings'))), 'FK_links' => array(array('to' => 'links_id', 'tables' => array('glpi_links_itemtypes'))), 'FK_port' => array(array('to' => 'networkports_id', 'tables' => array('glpi_networkports_vlans'))), 'FK_profiles' => array(array('to' => 'profiles_id', 'tables' => array('glpi_profiles_users', 'glpi_users'))), 'FK_users' => array(array('to' => 'users_id', 'tables' => array('glpi_bookmarks', 'glpi_displaypreferences', 'glpi_documents', 'glpi_groups', 'glpi_reminders', 'glpi_bookmarks_users', 'glpi_groups_users', 'glpi_profiles_users', 'glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'FK_vlan' => array(array('to' => 'vlans_id', 'tables' => array('glpi_networkports_vlans'))), 'glpi_id' => array(array('to' => 'computers_id', 'tables' => array('glpi_ocslinks'))), 'id_assign' => array(array('to' => 'users_id', 'tables' => array('glpi_ticketplannings'))), 'id_auth' => array(array('to' => 'auths_id', 'tables' => array('glpi_users'))), 'id_device' => array(array('to' => 'items_id', 'tables' => array('glpi_reservationitems'))), 'id_item' => array(array('to' => 'reservationitems_id', 'tables' => array('glpi_reservations'))), 'id_user' => array(array('to' => 'users_id', 'tables' => array('glpi_consumables', 'glpi_reservations'))), 'iface' => array(array('to' => 'networkinterfaces_id', 'tables' => array('glpi_networkports'))), 'interface' => array(array('to' => 'interfacetypes_id', 'tables' => array('glpi_devicecontrols', 'glpi_deviceharddrives', 'glpi_devicedrives'))), 'location' => array(array('to' => 'locations_id', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_netpoints', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_users', 'glpi_softwares'))), 'model' => array(array('to' => 'computermodels_id', 'tables' => array('glpi_computers')), array('to' => 'monitormodels_id', 'tables' => array('glpi_monitors')), array('to' => 'networkequipmentmodels_id', 'tables' => array('glpi_networkequipments')), array('to' => 'peripheralmodels_id', 'tables' => array('glpi_peripherals')), array('to' => 'phonemodels_id', 'tables' => array('glpi_phones')), array('to' => 'printermodels_id', 'tables' => array('glpi_printers'))), 'netpoint' => array(array('to' => 'netpoints_id', 'tables' => array('glpi_networkports'))), 'network' => array(array('to' => 'networks_id', 'tables' => array('glpi_computers', 'glpi_networkequipments', 'glpi_printers'))), 'on_device' => array(array('to' => 'items_id', 'tables' => array('glpi_networkports'))), 'os' => array(array('to' => 'operatingsystems_id', 'tables' => array('glpi_computers'))), 'os_license_id' => array(array('to' => 'os_licenseid', 'tables' => array('glpi_computers'))), 'os_version' => array(array('to' => 'operatingsystemversions_id', 'tables' => array('glpi_computers'))), 'parentID' => array(array('to' => 'knowbaseitemcategories_id', 'tables' => array('glpi_knowbaseitemcategories')), array('to' => 'locations_id', 'tables' => array('glpi_locations')), array('to' => 'ticketcategories_id', 'tables' => array('glpi_ticketcategories')), array('to' => 'entities_id', 'tables' => array('glpi_entities'))), 'platform' => array(array('to' => 'operatingsystems_id', 'tables' => array('glpi_softwares'))), 'power' => array(array('to' => 'phonepowersupplies_id', 'tables' => array('glpi_phones'))), 'recipient' => array(array('to' => 'users_id_recipient', 'tables' => array('glpi_tickets'))), 'rubrique' => array(array('to' => 'documentcategories_id', 'tables' => array('glpi_documents'))), 'sID' => array(array('to' => 'softwares_id', 'tables' => array('glpi_softwarelicenses', 'glpi_softwareversions'))), 'state' => array(array('to' => 'states_id', 'tables' => array('glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwareversions'))), 'tech_num' => array(array('to' => 'users_id_tech', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'title' => array(array('to' => 'usertitles_id', 'tables' => array('glpi_users'))), 'type' => array(array('to' => 'cartridgeitemtypes_id', 'tables' => array('glpi_cartridgeitems')), array('to' => 'computertypes_id', 'tables' => array('glpi_computers')), array('to' => 'consumableitemtypes_id', 'tables' => array('glpi_consumableitems')), array('to' => 'contacttypes_id', 'tables' => array('glpi_contacts')), array('to' => 'devicecasetypes_id', 'tables' => array('glpi_devicecases')), array('to' => 'devicememorytypes_id', 'tables' => array('glpi_devicememories')), array('to' => 'suppliertypes_id', 'tables' => array('glpi_suppliers')), array('to' => 'monitortypes_id', 'tables' => array('glpi_monitors')), array('to' => 'networkequipmenttypes_id', 'tables' => array('glpi_networkequipments')), array('to' => 'peripheraltypes_id', 'tables' => array('glpi_peripherals')), array('to' => 'phonetypes_id', 'tables' => array('glpi_phones')), array('to' => 'printertypes_id', 'tables' => array('glpi_printers')), array('to' => 'softwarelicensetypes_id', 'tables' => array('glpi_softwarelicenses')), array('to' => 'usercategories_id', 'tables' => array('glpi_users')), array('to' => 'itemtype', 'tables' => array('glpi_computers_items', 'glpi_displaypreferences'))), 'update_software' => array(array('to' => 'softwares_id', 'tables' => array('glpi_softwares'))), 'use_version' => array(array('to' => 'softwareversions_id_use', 'tables' => array('glpi_softwarelicenses'))), 'vID' => array(array('to' => 'softwareversions_id', 'tables' => array('glpi_computers_softwareversions'))), 'conpta_num' => array(array('to' => 'accounting_number', 'tables' => array('glpi_contracts'))), 'num_commande' => array(array('to' => 'order_number', 'tables' => array('glpi_infocoms'))), 'bon_livraison' => array(array('to' => 'delivery_number', 'tables' => array('glpi_infocoms'))), 'num_immo' => array(array('to' => 'immo_number', 'tables' => array('glpi_infocoms'))), 'facture' => array(array('to' => 'bill', 'tables' => array('glpi_infocoms'))), 'amort_time' => array(array('to' => 'sink_time', 'tables' => array('glpi_infocoms'))), 'amort_type' => array(array('to' => 'sink_type', 'tables' => array('glpi_infocoms'))), 'ifmac' => array(array('to' => 'mac', 'tables' => array('glpi_networkequipments'))), 'ifaddr' => array(array('to' => 'ip', 'tables' => array('glpi_networkequipments', 'glpi_networkports'))), 'ramSize' => array(array('to' => 'memory_size', 'tables' => array('glpi_printers'))), 'ramSize' => array(array('to' => 'memory_size', 'tables' => array('glpi_printers'))), 'facturation' => array(array('to' => 'billing', 'tables' => array('glpi_contracts'))), 'monday' => array(array('to' => 'use_monday', 'tables' => array('glpi_contracts'))), 'saturday' => array(array('to' => 'use_saturday', 'tables' => array('glpi_contracts'))), 'recursive' => array(array('to' => 'is_recursive', 'tables' => array('glpi_networkequipments', 'glpi_groups', 'glpi_contracts', 'glpi_contacts', 'glpi_suppliers', 'glpi_printers', 'glpi_softwares', 'glpi_softwareversions', 'glpi_softwarelicences'))), 'faq' => array(array('to' => 'is_faq', 'tables' => array('glpi_knowbaseitems'))), 'flags_micro' => array(array('to' => 'have_micro', 'tables' => array('glpi_monitors'))), 'flags_speaker' => array(array('to' => 'have_speaker', 'tables' => array('glpi_monitors'))), 'flags_subd' => array(array('to' => 'have_subd', 'tables' => array('glpi_monitors'))), 'flags_bnc' => array(array('to' => 'have_bnc', 'tables' => array('glpi_monitors'))), 'flags_dvi' => array(array('to' => 'have_dvi', 'tables' => array('glpi_monitors'))), 'flags_pivot' => array(array('to' => 'have_pivot', 'tables' => array('glpi_monitors'))), 'flags_hp' => array(array('to' => 'have_hp', 'tables' => array('glpi_phones'))), 'flags_casque' => array(array('to' => 'have_headset', 'tables' => array('glpi_phones'))), 'flags_usb' => array(array('to' => 'have_usb', 'tables' => array('glpi_printers'))), 'flags_par' => array(array('to' => 'have_parallel', 'tables' => array('glpi_printers'))), 'flags_serial' => array(array('to' => 'have_serial', 'tables' => array('glpi_printers'))), 'initial_pages' => array(array('to' => 'init_pages_counter', 'tables' => array('glpi_printers'))), 'global' => array(array('to' => 'is_global', 'tables' => array('glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'template' => array(array('to' => 'template_name', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_devicecases', 'glpi_devicecontrols', 'glpi_devicedrives', 'glpi_devicegraphiccards', 'glpi_deviceharddrives', 'glpi_devicenetworkcards', 'glpi_devicemotherboards', 'glpi_devicepcis', 'glpi_devicepowersupplies', 'glpi_deviceprocessors', 'glpi_devicememories', 'glpi_devicesoundcards', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'comments' => array(array('to' => 'comment', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_autoupdatesystems', 'glpi_budgets', 'glpi_cartridgeitemtypes', 'glpi_devicecasetypes', 'glpi_consumableitemtypes', 'glpi_contacttypes', 'glpi_contracttypes', 'glpi_domains', 'glpi_suppliertypes', 'glpi_filesystems', 'glpi_networkequipmentfirmwares', 'glpi_networkinterfaces', 'glpi_interfacetypes', 'glpi_knowbaseitemcategories', 'glpi_softwarelicensetypes', 'glpi_locations', 'glpi_manufacturers', 'glpi_computermodels', 'glpi_monitormodels', 'glpi_networkequipmentmodels', 'glpi_peripheralmodels', 'glpi_phonemodels', 'glpi_printermodels', 'glpi_netpoints', 'glpi_networks', 'glpi_operatingsystems', 'glpi_operatingsystemservicepacks', 'glpi_operatingsystemversions', 'glpi_phonepowersupplies', 'glpi_devicememorytypes', 'glpi_documentcategories', 'glpi_softwarecategories', 'glpi_states', 'glpi_ticketcategories', 'glpi_usertitles', 'glpi_usercategories', 'glpi_vlans', 'glpi_suppliers', 'glpi_entities', 'glpi_groups', 'glpi_infocoms', 'glpi_monitors', 'glpi_phones', 'glpi_printers', 'glpi_peripherals', 'glpi_networkequipments', 'glpi_reservationitems', 'glpi_rules', 'glpi_softwares', 'glpi_softwarelicenses', 'glpi_softwareversions', 'glpi_computertypes', 'glpi_monitortypes', 'glpi_networkequipmenttypes', 'glpi_peripheraltypes', 'glpi_phonetypes', 'glpi_printertypes', 'glpi_users'))), 'notes' => array(array('to' => 'notepad', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_suppliers', 'glpi_entitydatas', 'glpi_printers', 'glpi_monitors', 'glpi_phones', 'glpi_peripherals', 'glpi_networkequipments', 'glpi_softwares'))));
    $foreignkeys = Plugin::doHookFunction("plugin_datainjection_migratefields", $foreignkeys);
    $query = "SELECT `itemtype`, `value`\n              FROM `glpi_plugin_datainjection_mappings`\n              WHERE `itemtype` NOT IN ('none')\n              GROUP BY `itemtype`,`value`";
    foreach ($DB->request($query) as $data) {
        if (isset($foreignkeys[$data['value']])) {
            foreach ($foreignkeys[$data['value']] as $field_info) {
                $table = getTableForItemType($data['itemtype']);
                if (in_array($table, $field_info['tables'])) {
                    $query = "UPDATE `glpi_plugin_datainjection_mappings`\n                          SET `value` = '" . $field_info['to'] . "'\n                          WHERE `itemtype` = '" . $data['itemtype'] . "'\n                                AND `value` = '" . $data['value'] . "'";
                    $DB->queryOrDie($query, "Datainjection : error converting mapping fields");
                    $query = "UPDATE `glpi_plugin_datainjection_infos`\n                          SET `value` = '" . $field_info['to'] . "'\n                          WHERE `itemtype` = '" . $data['itemtype'] . "'\n                                AND `value` = '" . $data['value'] . "'";
                    $DB->queryOrDie($query, "Datainjection : error converting infos fields");
                }
            }
        }
    }
}