/** * Get foreign fields needed to process criterias * * @return an array of needed fields **/ function getFKFieldsForQuery() { $rule = new RuleOcs(); $fields = array(); foreach ($rule->getCriterias() as $criteria) { //If the field name is not null AND a table name is provided if ((!isset($criteria['virtual']) || !$criteria['virtual']) && $criteria['linkfield'] != '') { $fields[] = $criteria['table'] . "." . $criteria['linkfield']; } } return $fields; }
/** * Display content of Tab * * @param $ID of the item * @param $tab number of the tab * * @return true if handled (for class stack) */ function showTabContent($ID, $tab) { global $CFG_GLPI; if (!$this->isNewID($ID)) { switch ($tab) { case -1: // All $this->showChildren($ID); EntityData::showStandardOptions($this); Profile_User::showForEntity($this); $collection = new RuleRightCollection(); if ($collection->canList()) { $ldaprule = new RuleRight(); $ldaprule->showAndAddRuleForm($this); } $collection = new RuleOcsCollection(); if ($collection->canList()) { $ocsrule = new RuleOcs(); $ocsrule->showAndAddRuleForm($this); } $collection = new RuleMailCollectorCollection(); if ($collection->canList()) { $mailcollector = new RuleMailCollector(); $mailcollector->showAndAddRuleForm($this); } Document::showAssociated($this); EntityData::showNotificationOptions($this); EntityData::showHelpdeskOptions($this); EntityData::showInventoryOptions($this); Plugin::displayAction($this, $tab); break; case 2: EntityData::showStandardOptions($this); break; case 3: Profile_User::showForEntity($this); break; case 4: $collection = new RuleRightCollection(); if ($collection->canList()) { $ldaprule = new RuleRight(); $ldaprule->showAndAddRuleForm($this); } $collection = new RuleOcsCollection(); if ($collection->canList()) { $ocsrule = new RuleOcs(); $ocsrule->showAndAddRuleForm($this); } $collection = new RuleMailCollectorCollection(); if ($collection->canList()) { $mailcollector = new RuleMailCollector(); $mailcollector->showAndAddRuleForm($this); } break; case 5: EntityData::showAdvancedOptions($this); break; case 6: Document::showAssociated($this); break; case 7: EntityData::showNotificationOptions($this); break; case 8: EntityData::showHelpdeskOptions($this); break; case 9: EntityData::showInventoryOptions($this); break; case 10: showNotesForm(getItemTypeFormURL('EntityData'), 'EntityData', $_POST["id"]); break; default: if (!Plugin::displayAction($this, $tab)) { $this->showChildren($ID); } return false; } } return false; }
/** * Display a list of computers to add or to link * * @param ocsservers_id the ID of the ocs server * @param advanced display detail about the computer import or not (target entity, matched rules, etc.) * @param check indicates if checkboxes are checked or not * @param start display a list of computers starting at row X * @param entity a list of entities in which computers can be added or linked * @param tolinked false for an import, true for a link * * @return nothing **/ static function showComputersToAdd($ocsservers_id, $advanced, $check, $start, $entity = 0, $tolinked = false) { global $DB, $DBocs, $LANG, $CFG_GLPI; if (!haveRight("ocsng", "w")) { return false; } $target = $CFG_GLPI['root_doc'] . '/front/ocsng.import.php'; if ($tolinked) { $target = $CFG_GLPI['root_doc'] . '/front/ocsng.link.php'; } $cfg_ocs = self::getConfig($ocsservers_id); $WHERE = self::getTagLimit($cfg_ocs); $query_ocs = "SELECT `hardware`.*,\n `accountinfo`.`TAG` AS TAG,\n `bios`.`SSN` AS SERIAL\n FROM `hardware`\n INNER JOIN `accountinfo` ON (`hardware`.`id` = `accountinfo`.`HARDWARE_ID`)\n INNER JOIN `bios` ON (`hardware`.`id` = `bios`.`HARDWARE_ID`)" . (!empty($WHERE) ? "WHERE {$WHERE}" : "") . "\n ORDER BY `hardware`.`NAME`"; $result_ocs = $DBocs->query($query_ocs); // Existing OCS - GLPI link $query_glpi = "SELECT *\n FROM `glpi_ocslinks`\n WHERE `ocsservers_id` = '{$ocsservers_id}'"; $result_glpi = $DB->query($query_glpi); if ($DBocs->numrows($result_ocs) > 0) { // Get all hardware from OCS DB $hardware = array(); while ($data = $DBocs->fetch_array($result_ocs)) { $data = clean_cross_side_scripting_deep(addslashes_deep($data)); $hardware[$data["ID"]]["date"] = $data["LASTDATE"]; $hardware[$data["ID"]]["name"] = $data["NAME"]; $hardware[$data["ID"]]["TAG"] = $data["TAG"]; $hardware[$data["ID"]]["id"] = $data["ID"]; $hardware[$data["ID"]]["serial"] = $data["SERIAL"]; $query_network = "SELECT *\n FROM `networks`\n WHERE `HARDWARE_ID` = '" . $data["ID"] . "'"; //Get network informations for this computer //Ignore informations that contains "??" foreach ($DBocs->request($query_network) as $network) { if (isset($network['IPADDRESS']) && $network['IPADDRESS'] != '??') { $hardware[$data["ID"]]['IPADDRESS'][] = $network['IPADDRESS']; } if (isset($network['IPSUBNET']) && $network['IPSUBNET'] != '??') { $hardware[$data["ID"]]['IPSUBNET'][] = $network['IPSUBNET']; } if (isset($network['MACADDRESS']) && $network['MACADDR'] != '??') { $hardware[$data["ID"]]['MACADDRESS'][] = $network['MACADDR']; } } } // Get all links between glpi and OCS $already_linked = array(); if ($DB->numrows($result_glpi) > 0) { while ($data = $DBocs->fetch_array($result_glpi)) { $already_linked[$data["ocsid"]] = $data["last_update"]; } } // Clean $hardware from already linked element if (count($already_linked) > 0) { foreach ($already_linked as $ID => $date) { if (isset($hardware[$ID]) && isset($already_linked[$ID])) { unset($hardware[$ID]); } } } if ($tolinked && count($hardware)) { echo "<div class='center'><strong>" . $LANG['ocsng'][22] . "</strong></div>"; } echo "<div class='center'>"; if (($numrows = count($hardware)) > 0) { $parameters = "check={$check}"; printPager($start, $numrows, $target, $parameters); // delete end array_splice($hardware, $start + $_SESSION['glpilist_limit']); // delete begin if ($start > 0) { array_splice($hardware, 0, $start); } //Show preview form only in import and in multi-entity mode if (!$tolinked && isMultiEntitiesMode()) { echo "<div class='firstbloc'>"; echo "<form method='post' name='ocsng_import_mode' id='ocsng_import_mode'\n action='{$target}'>\n"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $LANG['ocsng'][41] . "</th></tr>\n"; echo "<tr class='tab_bg_1'><td class='center'>"; if ($advanced) { $status = "false"; } else { $status = "true"; } echo "<a href='" . $target . "?change_import_mode=" . $status . "'>"; if ($advanced) { echo $LANG['ocsng'][38]; } else { echo $LANG['ocsng'][37]; } echo "</a></td></tr>"; echo "<tr class='tab_bg_1'><td class='center b'>" . $LANG['ocsconfig'][18] . "<br>"; echo "</tr></table></form></div>"; } echo "<form method='post' name='ocsng_form' id='ocsng_form' action='{$target}'>"; if (!$tolinked) { echo "<a href='" . $target . "?check=all&start={$start}' onclick= " . "\"if ( markCheckboxes('ocsng_form') ) return false;\">" . $LANG['buttons'][18] . "</a> / <a href='" . $target . "?check=none&start=" . "{$start}' onclick= \"if ( unMarkCheckboxes('ocsng_form') ) return false;\">" . $LANG['buttons'][19] . "</a>\n"; } echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td colspan='" . ($advanced ? 8 : 5) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . $LANG['buttons'][37] . "\">"; echo "</td></tr>\n"; echo "<tr><th>" . $LANG['ocsng'][5] . "</th>\n<th>" . $LANG['common'][19] . "</th>\n"; echo "<th>" . $LANG['common'][27] . "</th>\n<th>TAG</th>\n"; if ($advanced && !$tolinked) { echo "<th>" . $LANG['ocsng'][40] . "</th>\n"; echo "<th>" . $LANG['ocsng'][36] . "</th>\n"; echo "<th>" . $LANG['ocsng'][39] . "</th>\n"; } echo "<th> </th></tr>\n"; $rule = new RuleOcsCollection($ocsservers_id); foreach ($hardware as $ID => $tab) { $comp = new Computer(); $comp->fields["id"] = $tab["id"]; $data = array(); if ($advanced && !$tolinked) { $data = $rule->processAllRules(array(), array(), $tab["id"]); } echo "<tr class='tab_bg_2'><td>" . $tab["name"] . "</td>\n"; echo "<td>" . $tab["serial"] . "</td>\n"; echo "<td>" . convDateTime($tab["date"]) . "</td>\n"; echo "<td>" . $tab["TAG"] . "</td>\n"; if ($advanced && !$tolinked) { if (!isset($data['entities_id']) || $data['entities_id'] == -1) { echo "<td class='center'><img src=\"" . GLPI_ROOT . "/pics/redbutton.png\"></td>\n"; $data['entities_id'] = -1; } else { echo "<td class='center'>"; //echo "<td class='center'><img src=\"".GLPI_ROOT. "/pics/greenbutton.png\">"; //echo " "; $tmprule = new RuleOcs(); if ($tmprule->can($data['_ruleid'], 'r')) { echo "<a href='" . $tmprule->getLinkURL() . "'>" . $tmprule->getName() . "</a>"; } else { echo $tmprule->getName(); } echo "</td>\n"; } echo "<td>"; Dropdown::show('Entity', array('name' => "toimport_entities[" . $tab["id"] . "]\n =" . $data['entities_id'], 'value' => $data['entities_id'], 'comments' => 0)); echo "</td>\n"; echo "<td>"; if (!isset($data['locations_id'])) { $data['locations_id'] = 0; } Dropdown::show('Location', array('name' => "toimport_locations[" . $tab["id"] . "]\n =" . $data['locations_id'], 'value' => $data['locations_id'], 'comments' => 0)); echo "</td>\n"; } echo "<td>"; if (!$tolinked) { echo "<input type='checkbox' name='toimport[" . $tab["id"] . "]' " . ($check == "all" ? "checked" : "") . ">"; } else { $rulelink = new RuleImportComputerCollection(); $rulelink_results = array(); $params = array('entities_id' => $entity, 'ocsservers_id' => $ocsservers_id); $rulelink_results = $rulelink->processAllRules($tab, array(), $params); //Look for the computer using automatic link criterias as defined in OCSNG configuration $options = array('name' => "tolink[" . $tab["id"] . "]"); $show_dropdown = true; //If the computer is not explicitly refused by a rule if (!isset($rulelink_results['action']) || $rulelink_results['action'] != self::LINK_RESULT_NO_IMPORT) { if (!empty($rulelink_results['found_computers'])) { $options['value'] = $rulelink_results['found_computers'][0]; $options['entity'] = $entity; } Dropdown::show('Computer', $options); } else { echo "<img src='" . GLPI_ROOT . "/pics/redbutton.png'>"; } } echo "</td></tr>\n"; } echo "<tr class='tab_bg_1'><td colspan='" . ($advanced ? 8 : 5) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . $LANG['buttons'][37] . "\">\n"; echo "<input type=hidden name='ocsservers_id' value='{$ocsservers_id}'>"; echo "</td></tr>"; echo "</table></form>\n"; if (!$tolinked) { echo "<a href='" . $target . "?check=all&start={$start}' onclick=" . "\"if ( markCheckboxes('ocsng_form') ) return false;\">" . $LANG['buttons'][18] . "</a> / " . "<a href='" . $target . "?check=none&start=" . "{$start}' onclick=\"if (unMarkCheckboxes('ocsng_form')) return false;\">" . $LANG['buttons'][19] . "</a>\n"; } printPager($start, $numrows, $target, $parameters); } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $LANG['ocsng'][2] . "</th></tr>\n"; echo "<tr class='tab_bg_1'><td class='center b'>" . $LANG['ocsng'][9] . "</td></tr>\n"; echo "</table>"; } echo "</div>"; } else { echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $LANG['ocsng'][2] . "</th></tr>\n"; echo "<tr class='tab_bg_1'><td class='center b'>" . $LANG['ocsng'][9] . "</td></tr>\n"; echo "</table></div>"; } }