예제 #1
0
 static function showForm($type, $model_id, $tab_ids, $location)
 {
     global $DB, $CFG_GLPI;
     // Retrieve model informations and show details
     // It's just for helping user!
     $model = new PluginUninstallModel();
     $model->getConfig($model_id);
     echo "<div class='first_bloc'>";
     echo "<table class='tab_cadre_fixe' cellpadding='5'>";
     echo "<tr class='tab_bg_1 center'>" . "<th colspan='6'>" . sprintf(__('%1$s - %2$s'), __('Reminder of the replacement model', 'uninstall'), __('General informations', 'uninstall')) . "</th></tr>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), __('Name')) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_name"]) . "</td>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), __('Serial number')) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_serial"]) . "</td>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), __('Inventory number')) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_otherserial"]) . "</td>";
     echo "</tr>";
     echo "<tr><td colspan='6'></td></tr>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<td colspan='2'>" . __('Overwrite informations (from old item to the new)', 'uninstall') . "</td>";
     echo "<td>" . self::coloredYN($model->fields["overwrite"]) . "</td>";
     echo "<td colspan='2'>" . __('Archiving method of the old material', 'uninstall') . "</td>";
     echo "<td>";
     $methods = PluginUninstallModel::getReplacementMethods();
     switch ($model->fields["replace_method"]) {
         case self::METHOD_PURGE:
             echo "<span class='red b'>" . $methods[self::METHOD_PURGE] . "</span>";
             break;
         case self::METHOD_DELETE_AND_COMMENT:
             echo "<span class='green b'>" . $methods[self::METHOD_DELETE_AND_COMMENT] . "</span>";
             break;
     }
     echo "</td></tr>";
     echo "<tr><td colspan='6'></td></tr>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<td></td><td>" . __('New location of item', 'uninstall') . "</td>";
     switch ($location) {
         case -1:
             echo "<td><span class='red b'>" . __('Keep previous location', 'uninstall') . "</span></td>";
             break;
         case 0:
             echo "<td><span class='red b'>" . __('Empty location', 'uninstall') . "</span></td>";
             break;
         default:
             echo "<td><span class='green b'>";
             echo Dropdown::getDropdownName('glpi_locations', $location);
             echo "</span></td>";
             break;
     }
     echo "<td>" . __('New status of the computer', 'uninstall') . "</td>";
     echo "<td>";
     if ($model->fields['states_id'] == 0) {
         echo "<span class='red b'>" . __('Status') . "</span>";
     } else {
         echo "<span class='green b'>";
         echo Dropdown::getDropdownName('glpi_states', $model->fields['states_id']);
         echo "</span>";
     }
     echo "</td>";
     echo "<td></td></tr>";
     echo "</table>";
     echo "</div>";
     // CONNEXIONS with other items
     echo "<div class='firstbloc'>";
     echo "<table class='tab_cadre_fixe' cellpadding='5'>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<th colspan='4'>" . sprintf(__('%1$s - %2$s'), __('Reminder of the replacement model', 'uninstall'), __('Connections with other materials', 'uninstall')) . "</th></tr>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), _n('Document', 'Documents', 2)) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_documents"]) . "</td>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), _n('Contract', 'Contracts', 2)) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_contracts"]) . "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), __('Financial and administratives information')) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_infocoms"]) . "</td>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), _n('Reservation', 'Reservations', 2)) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_reservations"]) . "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), __('User')) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_users"]) . "</td>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), __('Group')) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_groups"]) . "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), _n('Ticket', 'Tickets', 2)) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_tickets"]) . "</td>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), sprintf(__('%1$s %2$s'), _n('Connection', 'Connections', 2), _n('Network', 'Networks', 2))) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_netports"]) . "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<td>" . sprintf(__('%1$s %2$s'), __('Copy'), __('Direct connections', 'uninstall')) . "</td>";
     echo "<td>" . self::coloredYN($model->fields["replace_direct_connections"]) . "</td>";
     echo "<td colspan='2'></td>";
     echo "</tr></table></div>";
     // Show form for selecting new items
     echo "<form action='../front/action.php' method='post'>";
     echo "<table class='tab_cadre_fixe' cellpadding='5'>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<th colspan='4'>" . __('Choices for item to replace', 'uninstall') . "</th></tr>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<th>" . __('Old item', 'uninstall') . "</th>";
     if (self::searchFieldInSearchOptions($type, 'otherserial')) {
         echo "<th>" . __('Inventory number') . "</th>";
     }
     if (self::searchFieldInSearchOptions($type, 'serial')) {
         echo "<th>" . __('Serial number') . "</th>";
     }
     echo "<th>" . __('New item', 'uninstall') . "</th>";
     echo "</tr>";
     $commonitem = new $type();
     foreach ($tab_ids[$type] as $id => $value) {
         $commonitem->getFromDB($id);
         echo "<tr class='tab_bg_1 center'>";
         echo "<td>" . $commonitem->getName() . "</td>";
         if (self::searchFieldInSearchOptions($type, 'otherserial')) {
             echo "<td>" . $commonitem->fields['otherserial'] . "</td>";
         }
         if (self::searchFieldInSearchOptions($type, 'serial')) {
             echo "<td>" . $commonitem->fields['serial'] . "</td>";
         }
         echo "<td>";
         $type::dropdown(array('name' => "newItems[{$id}]", 'displaywith' => array('serial', 'otherserial'), 'url' => $CFG_GLPI['root_doc'] . "/plugins/uninstall/ajax/dropdownReplaceFindDevice.php"));
         echo "</td></tr>";
     }
     echo "<tr class='tab_bg_1 center'>";
     echo "<td colspan='4' class='center'>";
     echo "<input type='hidden' name='device_type' value='" . $type . "' />";
     echo "<input type='hidden' name='model_id' value='" . $model_id . "' />";
     echo "<input type='hidden' name='locations_id' value='" . $location . "' />";
     echo "<input type='submit' name='replace' value=\"" . __('Replace', 'uninstall') . "\"\n             class='submit'>";
     echo "</td></tr>";
     echo "</table>";
     Html::closeForm();
 }
예제 #2
0
 static function uninstall($type, $model_id, $tab_ids, $location)
 {
     global $UNINSTALL_DIRECT_CONNECTIONS_TYPE;
     //Get the model
     $model = new PluginUninstallModel();
     $model->getConfig($model_id);
     //Then destroy all the connexions
     $transfer = new Transfer();
     $transfer->getFromDB($model->fields["transfers_id"]);
     echo "<div class='center'>";
     echo "<table class='tab_cadre_fixe'><tr><th>" . __('Uninstall', 'uninstall') . "</th></tr>";
     echo "<tr class='tab_bg_2'><td>";
     $count = 0;
     $tot = count($tab_ids[$type]);
     Html::createProgressBar(__('Please wait, uninstallation is running...', 'uninstall'));
     foreach ($tab_ids[$type] as $id => $value) {
         $count++;
         $item = new $type();
         $item->getFromDB($id);
         //First clean object and change location and status if needed
         $entity = $item->fields["entities_id"];
         $input = array();
         $input["id"] = $id;
         $input["entities_id"] = $entity;
         $fields = array();
         //Hook to perform actions before item is being uninstalled
         $item->fields['_uninstall_event'] = $model->getID();
         $item->fields['_action'] = 'uninstall';
         Plugin::doHook("plugin_uninstall_before", $item);
         //--------------------//
         //Direct connections //
         //------------------//
         if (in_array($type, $UNINSTALL_DIRECT_CONNECTIONS_TYPE)) {
             $conn = new Computer_Item();
             $conn->deleteByCriteria(array('computers_id' => $id), true);
         }
         //--------------------//
         //-- Common fields --//
         //------------------//
         //RAZ contact and contactnumber
         if ($item->isField('contact') && $model->fields["raz_contact"] == 1) {
             $fields["contact"] = '';
             if ($item->isField('contact_num')) {
                 $fields["contact_num"] = '';
             }
         }
         //RAZ user
         if ($model->fields["raz_user"] == 1 && $item->isField('users_id')) {
             $fields["users_id"] = 0;
         }
         //RAZ status
         if ($model->fields["states_id"] > 0 && $item->isField('states_id')) {
             $fields["states_id"] = $model->fields["states_id"];
         }
         //RAZ machine's name
         if ($item->isField('name') && $model->fields["raz_name"] == 1) {
             $fields["name"] = '';
         }
         if ($item->isField('locations_id')) {
             if ($location == '') {
                 $location = 0;
             }
             switch ($location) {
                 case -1:
                     break;
                 default:
                     $fields["locations_id"] = $location;
                     break;
             }
         }
         if ($item->isField('groups_id')) {
             $nbgroup = countElementsInTableForEntity("glpi_groups", $entity, "`id`='" . $item->fields['groups_id'] . "'");
             if ($model->fields["groups_id"] > -1 && $nbgroup == 1) {
                 // If a new group is defined and if the group is accessible in the object's entity
                 $fields["groups_id"] = $model->fields["groups_id"];
             }
         }
         //------------------------------//
         //-- Computer specific fields --//
         //------------------------------//
         if ($type == 'Computer') {
             //RAZ all OS related informations
             if ($model->fields["raz_os"] == 1) {
                 $fields["operatingsystems_id"] = 0;
                 $fields["operatingsystemversions_id"] = 0;
                 $fields["operatingsystemservicepacks_id"] = 0;
                 $fields["os_licenseid"] = '';
                 $fields["os_license_number"] = '';
                 $fields["autoupdatesystems_id"] = 0;
             }
             $plug = new Plugin();
             if ($plug->isActivated('ocsinventoryng')) {
                 if ($item->fields["is_dynamic"] && ($model->fields["remove_from_ocs"] || $model->fields["delete_ocs_link"])) {
                     $input["is_dynamic"] = 0;
                 }
             }
             if ($item->isField('domains_id') && $model->fields["raz_domain"]) {
                 $fields["domains_id"] = 0;
             }
             //RAZ network
             if ($item->isField('networks_id') && $model->fields["raz_network"] == 1) {
                 $fields["networks_id"] = 0;
             }
         }
         //RAZ IPs from all the network cards
         if ($model->fields["raz_ip"] == 1) {
             self::razPortInfos($type, $id);
             // For NetworkEquiment
             if ($item->isField('ip')) {
                 $fields['ip'] = '';
             }
             if ($item->isField('mac')) {
                 $fields['mac'] = '';
             }
         }
         foreach ($fields as $name => $value) {
             if (!($item->getField($name) != NOT_AVAILABLE) || $item->getField($name) != $value) {
                 $input[$name] = $value;
             }
         }
         $item->dohistory = true;
         $item->update($input);
         if ($model->fields["raz_budget"] == 1) {
             $infocom_id = self::getInfocomPresentForDevice($type, $id);
             if ($infocom_id > 0) {
                 $infocom = new InfoCom();
                 $tmp["id"] = $infocom_id;
                 $tmp["budgets_id"] = 0;
                 $infocom->dohistory = false;
                 $infocom->update($tmp);
             }
         }
         //Delete machine from glpi_ocs_link
         if ($type == 'Computer') {
             //Delete computer's volumes
             self::purgeComputerVolumes($id);
             if ($model->fields["raz_history"] == 1) {
                 //Delete history related to software
                 self::deleteHistory($id, false);
             } else {
                 if ($model->fields["raz_soft_history"] == 1) {
                     //Delete history related to software
                     self::deleteHistory($id, true);
                 }
             }
             $plug = new Plugin();
             if ($plug->isActivated('ocsinventoryng')) {
                 //Delete computer from OCS
                 if ($model->fields["remove_from_ocs"] == 1) {
                     self::deleteComputerInOCSByGlpiID($id);
                 }
                 //Delete link in glpi_ocs_link
                 if ($model->fields["delete_ocs_link"] || $model->fields["remove_from_ocs"]) {
                     self::deleteOcsLink($id);
                 }
             }
             //Should never happend that transfer_id = 0, but just in case
             if ($model->fields["transfers_id"] > 0) {
                 $transfer->moveItems(array($type => array($id => $id)), $entity, $transfer->fields);
             }
         }
         if ($model->fields['raz_fusioninventory'] == 1) {
             self::deleteFusionInventoryLink($type, $id);
         }
         //Plugin hook after uninstall
         Plugin::doHook("plugin_uninstall_after", $item);
         Html::changeProgressBarPosition($count, $tot + 1);
     }
     //Add line in machine's history to say that machine was uninstalled
     self::addUninstallLog($type, $id);
     Html::changeProgressBarPosition($count, $tot, __('Uninstallation successful', 'uninstall'));
     echo "</td></tr>";
     echo "</table></div>";
 }
예제 #3
0
}
if (isset($_REQUEST["locations_id"])) {
    $location = $_REQUEST["locations_id"];
} else {
    $location = PluginUninstallPreference::getLocationByUserByEntity($_SESSION["glpiID"], $_REQUEST["model_id"], $_SESSION["glpiactive_entity"]);
}
if (isset($_REQUEST["replace"])) {
    PluginUninstallReplace::replace($_REQUEST["device_type"], $_REQUEST["model_id"], $_REQUEST['newItems'], $location);
    unset($_SESSION['glpi_uninstalllist']);
    Session::addMessageAfterRedirect(__('Replacement successful', 'uninstall'));
    Html::footer();
    $device_type = $_REQUEST["device_type"];
    Html::redirect($device_type::getSearchURL());
}
$model = new PluginUninstallModel();
$model->getConfig($_REQUEST["model_id"]);
//Case of a uninstallation initiated from the object form
if (isset($_REQUEST["uninstall"])) {
    //Uninstall only if a model is selected
    if ($model->fields['types_id'] == PluginUninstallModel::TYPE_MODEL_UNINSTALL) {
        //Massive uninstallation
        PluginUninstallUninstall::uninstall($_REQUEST["device_type"], $_REQUEST["model_id"], array($_REQUEST["device_type"] => array($_REQUEST["id"] => $_REQUEST["id"])), $location);
        Html::back();
    } else {
        PluginUninstallReplace::showForm($_REQUEST["device_type"], $_REQUEST["model_id"], array($_REQUEST["device_type"] => array($_REQUEST["id"] => $_REQUEST["id"])), $location);
        Html::footer();
    }
} else {
    if ($model->fields['types_id'] == PluginUninstallModel::TYPE_MODEL_UNINSTALL) {
        //Massive uninstallation
        if (isset($_SESSION['glpi_uninstalllist'])) {