コード例 #1
0
 /**
  * Constructor
  *
  * @param $ID ID of the ocs server ID
  **/
 function __construct($ID)
 {
     global $CFG_GLPI;
     $this->ocsservers_id = $ID;
     if ($CFG_GLPI["use_ocs_mode"]) {
         $data = OcsServer::getConfig($ID);
         $this->dbhost = $data["ocs_db_host"];
         $this->dbuser = $data["ocs_db_user"];
         $this->dbpassword = rawurldecode($data["ocs_db_passwd"]);
         $this->dbdefault = $data["ocs_db_name"];
         $this->dbenc = $data["ocs_db_utf8"] ? "utf8" : "latin1";
         parent::__construct();
     }
 }
コード例 #2
0
 /**
  * Print the computer form
  *
  * @param $ID integer ID of the item
  * @param $options array
  *     - target for the Form
  *     - withtemplate template or basic computer
  *
  *@return Nothing (display)
  *
  **/
 function showForm($ID, $options = array())
 {
     global $LANG, $CFG_GLPI, $DB;
     if (!haveRight("computer", "r")) {
         return false;
     }
     if ($ID > 0) {
         $this->check($ID, 'r');
     } else {
         // Create item
         $this->check(-1, 'w');
     }
     if (isset($options['withtemplate']) && $options['withtemplate'] == 2) {
         $template = "newcomp";
         $datestring = $LANG['computers'][14] . " : ";
         $date = convDateTime($_SESSION["glpi_currenttime"]);
     } else {
         if (isset($options['withtemplate']) && $options['withtemplate'] == 1) {
             $template = "newtemplate";
             $datestring = $LANG['computers'][14] . " : ";
             $date = convDateTime($_SESSION["glpi_currenttime"]);
         } else {
             $datestring = $LANG['common'][26] . ": ";
             $date = convDateTime($this->fields["date_mod"]);
             $template = false;
         }
     }
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['common'][16] . ($template ? "*" : "") . "&nbsp;:</td>";
     echo "<td>";
     $objectName = autoName($this->fields["name"], "name", $template === "newcomp", $this->getType(), $this->fields["entities_id"]);
     autocompletionTextField($this, 'name', array('value' => $objectName));
     echo "</td>";
     echo "<td>" . $LANG['state'][0] . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::show('State', array('value' => $this->fields["states_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['common'][15] . "&nbsp;: </td>";
     echo "<td>";
     Dropdown::show('Location', array('value' => $this->fields["locations_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "<td>" . $LANG['common'][17] . "&nbsp;: </td>";
     echo "<td>";
     Dropdown::show('ComputerType', array('value' => $this->fields["computertypes_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['common'][10] . "&nbsp;: </td>";
     echo "<td>";
     User::dropdown(array('name' => 'users_id_tech', 'value' => $this->fields["users_id_tech"], 'right' => 'interface', 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "<td>" . $LANG['common'][5] . "&nbsp;: </td>";
     echo "<td>";
     Dropdown::show('Manufacturer', array('value' => $this->fields["manufacturers_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['common'][21] . "&nbsp;: </td>";
     echo "<td >";
     autocompletionTextField($this, 'contact_num');
     echo "</td>";
     echo "<td>" . $LANG['common'][22] . "&nbsp;: </td>";
     echo "<td>";
     Dropdown::show('ComputerModel', array('value' => $this->fields["computermodels_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['common'][18] . "&nbsp;:</td>";
     echo "<td>";
     autocompletionTextField($this, 'contact');
     echo "</td>";
     echo "<td>" . $LANG['common'][19] . "&nbsp;:</td>";
     echo "<td >";
     autocompletionTextField($this, 'serial');
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['common'][34] . "&nbsp;: </td>";
     echo "<td>";
     User::dropdown(array('value' => $this->fields["users_id"], 'entity' => $this->fields["entities_id"], 'right' => 'all'));
     echo "</td>";
     echo "<td>" . $LANG['common'][20] . ($template ? "*" : "") . "&nbsp;:</td>";
     echo "<td>";
     $objectName = autoName($this->fields["otherserial"], "otherserial", $template === "newcomp", $this->getType(), $this->fields["entities_id"]);
     autocompletionTextField($this, 'otherserial', array('value' => $objectName));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['common'][35] . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::show('Group', array('value' => $this->fields["groups_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "<td>" . $LANG['setup'][88] . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::show('Network', array('value' => $this->fields["networks_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['setup'][89] . "&nbsp;:</td>";
     echo "<td >";
     Dropdown::show('Domain', array('value' => $this->fields["domains_id"]));
     echo "</td>";
     echo "<td rowspan='8'>" . $LANG['common'][25] . "&nbsp;:</td>";
     echo "<td rowspan='8' class='middle'>";
     echo "<textarea cols='45' rows='11' name='comment' >" . $this->fields["comment"] . "</textarea>";
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['computers'][9] . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::show('OperatingSystem', array('value' => $this->fields["operatingsystems_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['computers'][53] . "&nbsp;:</td>";
     echo "<td >";
     Dropdown::show('OperatingSystemServicePack', array('value' => $this->fields["operatingsystemservicepacks_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['computers'][52] . "&nbsp;:</td>";
     echo "<td >";
     Dropdown::show('OperatingSystemVersion', array('value' => $this->fields["operatingsystemversions_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['computers'][11] . "&nbsp;:</td>";
     echo "<td >";
     autocompletionTextField($this, 'os_licenseid');
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['computers'][10] . "&nbsp;:</td>";
     echo "<td >";
     autocompletionTextField($this, 'os_license_number');
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['computers'][58] . "&nbsp;:</td>";
     echo "<td >";
     autocompletionTextField($this, 'uuid');
     echo "</td></tr>\n";
     // Get OCS Datas :
     $dataocs = array();
     if (!empty($ID) && $this->fields["is_ocs_import"] && haveRight("view_ocsng", "r")) {
         $query = "SELECT *\n                   FROM `glpi_ocslinks`\n                   WHERE `computers_id` = '{$ID}'";
         $result = $DB->query($query);
         if ($DB->numrows($result) == 1) {
             $dataocs = $DB->fetch_array($result);
         }
     }
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='2' class='center'>" . $datestring . $date;
     if (!$template && !empty($this->fields['template_name'])) {
         echo "<span class='small_space'>(" . $LANG['common'][13] . "&nbsp;: " . $this->fields['template_name'] . ")</span>";
     }
     if (!empty($ID) && $this->fields["is_ocs_import"] && haveRight("view_ocsng", "r") && count($dataocs)) {
         echo "<br>";
         echo $LANG['ocsng'][14] . "&nbsp;: " . convDateTime($dataocs["last_ocs_update"]);
         echo "<br>";
         echo $LANG['ocsng'][13] . "&nbsp;: " . convDateTime($dataocs["last_update"]);
         echo "<br>";
         if (haveRight("ocsng", "r")) {
             echo $LANG['common'][52] . " <a href='" . $CFG_GLPI["root_doc"] . "/front/ocsserver.form.php?id=" . OcsServer::getByMachineID($ID) . "'>" . OcsServer::getServerNameByID($ID) . "</a>";
             $query = "SELECT `ocs_agent_version`, `ocsid`\n                      FROM `glpi_ocslinks`\n                      WHERE `computers_id` = '{$ID}'";
             $result_agent_version = $DB->query($query);
             $data_version = $DB->fetch_array($result_agent_version);
             $ocs_config = OcsServer::getConfig(OcsServer::getByMachineID($ID));
             //If have write right on OCS and ocsreports url is not empty in OCS config
             if (haveRight("ocsng", "w") && $ocs_config["ocs_url"] != '') {
                 echo ", " . OcsServer::getComputerLinkToOcsConsole(OcsServer::getByMachineID($ID), $data_version["ocsid"], $LANG['ocsng'][57]);
             }
             if ($data_version["ocs_agent_version"] != NULL) {
                 echo " , " . $LANG['ocsng'][49] . "&nbsp;: " . $data_version["ocs_agent_version"];
             }
         } else {
             echo $LANG['common'][52] . " " . OcsServer::getServerNameByID($ID);
         }
     }
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     if (!empty($ID) && $this->fields["is_ocs_import"] && haveRight("view_ocsng", "r") && haveRight("sync_ocsng", "w") && count($dataocs)) {
         echo "<td >" . $LANG['ocsng'][6] . " " . $LANG['Menu'][33] . "&nbsp;:</td>";
         echo "<td >";
         Dropdown::showYesNo("_auto_update_ocs", $dataocs["use_auto_update"]);
         echo "</td>";
     } else {
         echo "<td colspan=2></td>";
     }
     echo "<td>" . $LANG['computers'][51] . "&nbsp;:</td>";
     echo "<td >";
     Dropdown::show('AutoUpdateSystem', array('value' => $this->fields["autoupdatesystems_id"]));
     echo "</td></tr>";
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
コード例 #3
0
 /**
  * Actions done when item is deleted from the database
  * Overloaded to manage autoupdate feature
  *
  *@return nothing
  **/
 function cleanDBonPurge()
 {
     global $CFG_GLPI;
     if (!isset($this->input['_no_auto_action'])) {
         //Get the computer name
         $computer = new Computer();
         $computer->getFromDB($this->fields['computers_id']);
         //Get device fields
         if (class_exists($this->fields['itemtype'])) {
             $device = new $this->fields['itemtype']();
             if ($device->getFromDB($this->fields['items_id'])) {
                 if (!$device->getField('is_global')) {
                     $updates = array();
                     if ($CFG_GLPI["is_location_autoclean"] && $device->isField('locations_id')) {
                         $updates['locations_id'] = 0;
                     }
                     if ($CFG_GLPI["is_user_autoclean"] && $device->isField('users_id')) {
                         $updates['users_id'] = 0;
                     }
                     if ($CFG_GLPI["is_group_autoclean"] && $device->isField('groups_id')) {
                         $updates['groups_id'] = 0;
                     }
                     if ($CFG_GLPI["is_contact_autoclean"] && $device->isField('contact')) {
                         $updates['contact'] = "";
                     }
                     if ($CFG_GLPI["is_contact_autoclean"] && $device->isField('contact_num')) {
                         $updates['contact_num'] = "";
                     }
                     if ($CFG_GLPI["state_autoclean_mode"] < 0 && $device->isField('states_id')) {
                         $updates['states_id'] = 0;
                     }
                     if ($CFG_GLPI["state_autoclean_mode"] > 0 && $device->isField('states_id') && $device->getField('states_id') != $CFG_GLPI["state_autoclean_mode"]) {
                         $updates['states_id'] = $CFG_GLPI["state_autoclean_mode"];
                     }
                     if (count($updates)) {
                         $updates['id'] = $this->fields['items_id'];
                         $device->update($updates);
                     }
                 }
                 if (isset($this->input['_ocsservers_id'])) {
                     $ocsservers_id = $this->input['_ocsservers_id'];
                 } else {
                     $ocsservers_id = OcsServer::getByMachineID($this->fields['computers_id']);
                 }
                 if ($ocsservers_id > 0) {
                     //Get OCS configuration
                     $ocs_config = OcsServer::getConfig($ocsservers_id);
                     //Get the management mode for this device
                     $mode = OcsServer::getDevicesManagementMode($ocs_config, $this->fields['itemtype']);
                     $decoConf = $ocs_config["deconnection_behavior"];
                     //Change status if :
                     // 1 : the management mode IS NOT global
                     // 2 : a deconnection's status have been defined
                     // 3 : unique with serial
                     if ($mode >= 2 && strlen($decoConf) > 0) {
                         //Delete periph from glpi
                         if ($decoConf == "delete") {
                             $tmp["id"] = $this->fields['items_id'];
                             $device->delete($tmp, 1);
                             //Put periph in trash
                         } else {
                             if ($decoConf == "trash") {
                                 $tmp["id"] = $this->fields['items_id'];
                                 $device->delete($tmp, 0);
                             }
                         }
                     }
                 }
                 // $ocsservers_id>0
             }
         }
     }
 }
コード例 #4
0
}
if (isset($_SESSION["ocs_import"]["id"])) {
    if ($count = count($_SESSION["ocs_import"]["id"])) {
        $percent = min(100, round(100 * ($_SESSION["ocs_import_count"] - $count) / $_SESSION["ocs_import_count"], 0));
        $key = array_pop($_SESSION["ocs_import"]["id"]);
        if (isset($_SESSION["ocs_import"]["entities_id"][$key])) {
            $entity = $_SESSION["ocs_import"]["entities_id"][$key];
        } else {
            $entity = -1;
        }
        if (isset($_SESSION["ocs_import"]["locations_id"][$key])) {
            $location = $_SESSION["ocs_import"]["locations_id"][$key];
        } else {
            $location = -1;
        }
        $conf = OcsServer::getConfig($_SESSION["ocsservers_id"]);
        $action = OcsServer::processComputer($key, $_SESSION["ocsservers_id"], 0, $entity, $location);
        OcsServer::manageImportStatistics($_SESSION["ocs_import"]['statistics'], $action['status']);
        OcsServer::showStatistics($_SESSION["ocs_import"]['statistics']);
        displayProgressBar(400, $percent);
        glpi_header($_SERVER['PHP_SELF']);
    } else {
        //displayProgressBar(400, 100);
        OcsServer::showStatistics($_SESSION["ocs_import"]['statistics'], true);
        unset($_SESSION["ocs_import"]);
        echo "<div class='center b'><br>";
        echo "<a href='" . $_SERVER['PHP_SELF'] . "'>" . $LANG['buttons'][13] . "</a></div>";
        $display_list = false;
    }
}
if (!isset($_POST["import_ok"])) {