/**
  * @since version 0.85
  *
  * @see CommonDBTM::getForbiddenStandardMassiveAction()
  **/
 function getForbiddenStandardMassiveAction()
 {
     $forbidden = parent::getForbiddenStandardMassiveAction();
     if (count(static::getSpecificities()) == 0 && !InfoCom::canApplyOn($this)) {
         $forbidden[] = 'update';
     }
     return $forbidden;
 }
Ejemplo n.º 2
0
 /**
  * Is the search item related to infocoms
  *
  * @param $itemtype  item type
  * @param $searchID  ID of the element in $SEARCHOPTION
  *
  * @return boolean
  **/
 static function isInfocomOption($itemtype, $searchID)
 {
     global $CFG_GLPI;
     return ($searchID >= 25 && $searchID <= 28 || $searchID >= 37 && $searchID <= 38 || $searchID >= 50 && $searchID <= 59 || $searchID >= 120 && $searchID <= 125) && InfoCom::canApplyOn($itemtype);
 }
Ejemplo n.º 3
0
 /**
  * to list infos in debug tab
  **/
 function showDebugInfo()
 {
     global $CFG_GLPI;
     $class = $this->getType();
     if (method_exists($class, 'showDebug')) {
         $this->showDebug();
     }
     if (InfoCom::canApplyOn($class)) {
         $infocom = new Infocom();
         if ($infocom->getFromDBforDevice($class, $this->fields['id'])) {
             $infocom->showDebug();
         }
     }
     if (in_array($class, $CFG_GLPI["reservation_types"])) {
         $resitem = new ReservationItem();
         if ($resitem->getFromDBbyItem($class, $this->fields['id'])) {
             $resitem->showDebugResa();
         }
     }
 }
GNU General Public License for more details.

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
*/
include '../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
if (!isset($_POST["itemtype"]) || !($item = getItemForItemtype($_POST['itemtype']))) {
    exit;
}
if (InfoCom::canApplyOn($_POST["itemtype"])) {
    Session::checkSeveralRightsOr(array($_POST["itemtype"] => UPDATE, "infocom" => UPDATE));
} else {
    $item->checkGlobal(UPDATE);
}
$inline = false;
if (isset($_POST['inline']) && $_POST['inline']) {
    $inline = true;
}
$submitname = _sx('button', 'Post');
if (isset($_POST['submitname']) && $_POST['submitname']) {
    $submitname = stripslashes($_POST['submitname']);
}
if (isset($_POST["itemtype"]) && isset($_POST["id_field"]) && $_POST["id_field"]) {
    $search = Search::getOptions($_POST["itemtype"]);
    if (!isset($search[$_POST["id_field"]])) {
Ejemplo n.º 5
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::getMassiveActionsForItemtype()
  **/
 static function getMassiveActionsForItemtype(array &$actions, $itemtype, $is_deleted = 0, CommonDBTM $checkitem = NULL)
 {
     $action_name = __CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'activate';
     if (InfoCom::canApplyOn($itemtype) && static::canCreate()) {
         $actions[$action_name] = __('Enable the financial and administrative information');
     }
 }
Ejemplo n.º 6
0
 /**
  * transfer an item to another item (may be the same) in the new entity
  *
  * @param $itemtype     item type to transfer
  * @param $ID           ID of the item to transfer
  * @param $newID        new ID of the ite
  *
  * Transfer item to a new Item if $ID==$newID : only update entities_id field :
  *                                $ID!=$new ID -> copy datas (like template system)
  * @return nothing (diplays)
  **/
 function transferItem($itemtype, $ID, $newID)
 {
     global $CFG_GLPI, $DB;
     if (!($item = getItemForItemtype($itemtype))) {
         return;
     }
     // Is already transfer ?
     if (!isset($this->already_transfer[$itemtype][$ID])) {
         // Check computer exists ?
         if ($item->getFromDB($newID)) {
             // Network connection ? keep connected / keep_disconnected / delete
             if (in_array($itemtype, array('Computer', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer'))) {
                 $this->transferNetworkLink($itemtype, $ID, $newID);
             }
             // Device : keep / delete : network case : delete if net connection delete in import case
             if (in_array($itemtype, Item_Devices::getConcernedItems())) {
                 $this->transferDevices($itemtype, $ID, $newID);
             }
             // Reservation : keep / delete
             if (in_array($itemtype, $CFG_GLPI["reservation_types"])) {
                 $this->transferReservations($itemtype, $ID, $newID);
             }
             // History : keep / delete
             $this->transferHistory($itemtype, $ID, $newID);
             // Ticket : delete / keep and clean ref / keep and move
             $this->transferTickets($itemtype, $ID, $newID);
             // Infocoms : keep / delete
             if (InfoCom::canApplyOn($itemtype)) {
                 $this->transferInfocoms($itemtype, $ID, $newID);
             }
             if ($itemtype == 'Software') {
                 $this->transferSoftwareLicensesAndVersions($ID);
             }
             // Connected item is transfered
             if (in_array($itemtype, $CFG_GLPI["directconnect_types"])) {
                 $this->manageConnectionComputer($itemtype, $ID);
             }
             // Computer Direct Connect : delete link if it is the initial transfer item (no recursion)
             if ($this->inittype == $itemtype && in_array($itemtype, array('Monitor', 'Phone', 'Peripheral', 'Printer'))) {
                 $this->deleteDirectConnection($itemtype, $ID);
             }
             // Contract : keep / delete + clean unused / keep unused
             if (in_array($itemtype, $CFG_GLPI["contract_types"])) {
                 $this->transferContracts($itemtype, $ID, $newID);
             }
             // Contact / Supplier : keep / delete + clean unused / keep unused
             if ($itemtype == 'Supplier') {
                 $this->transferSupplierContacts($ID, $newID);
             }
             // Document : keep / delete + clean unused / keep unused
             if (Document::canApplyOn($itemtype)) {
                 $this->transferDocuments($itemtype, $ID, $newID);
             }
             // Transfer compatible printers
             if ($itemtype == 'CartridgeItem') {
                 $this->transferCompatiblePrinters($ID, $newID);
             }
             // Cartridges  and cartridges items linked to printer
             if ($itemtype == 'Printer') {
                 $this->transferPrinterCartridges($ID, $newID);
             }
             // Transfer Item
             $input = array('id' => $newID, 'entities_id' => $this->to);
             // Manage Location dropdown
             if (isset($item->fields['locations_id'])) {
                 $input['locations_id'] = $this->transferDropdownLocation($item->fields['locations_id']);
             }
             if (in_array($itemtype, array('Ticket', 'Problem', 'Change'))) {
                 $input2 = $this->transferHelpdeskAdditionalInformations($item->fields);
                 $input = array_merge($input, $input2);
                 $this->transferTaskCategory($itemtype, $ID, $newID);
                 $this->transferLinkedSuppliers($itemtype, $ID, $newID);
             }
             $item->update($input);
             $this->addToAlreadyTransfer($itemtype, $ID, $newID);
             // Do it after item transfer for entity checks
             if ($itemtype == 'Computer') {
                 // Monitor Direct Connect : keep / delete + clean unused / keep unused
                 $this->transferDirectConnection($itemtype, $ID, 'Monitor');
                 // Peripheral Direct Connect : keep / delete + clean unused / keep unused
                 $this->transferDirectConnection($itemtype, $ID, 'Peripheral');
                 // Phone Direct Connect : keep / delete + clean unused / keep unused
                 $this->transferDirectConnection($itemtype, $ID, 'Phone');
                 // Printer Direct Connect : keep / delete + clean unused / keep unused
                 $this->transferDirectConnection($itemtype, $ID, 'Printer');
                 // License / Software :  keep / delete + clean unused / keep unused
                 $this->transferComputerSoftwares($ID);
                 // Computer Disks :  delete them or not ?
                 $this->transferComputerDisks($ID);
             }
             Plugin::doHook("item_transfer", array('type' => $itemtype, 'id' => $ID, 'newID' => $newID, 'entities_id' => $this->to));
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * @see CommonDBTM::showMassiveActionsSubForm()
  **/
 static function showMassiveActionsSubForm(MassiveAction $ma)
 {
     global $CFG_GLPI;
     switch ($ma->getAction()) {
         case 'update':
             if (!isset($ma->POST['id_field'])) {
                 $itemtypes = array_keys($ma->items);
                 $options_per_type = array();
                 $options_counts = array();
                 foreach ($itemtypes as $itemtype) {
                     $options_per_type[$itemtype] = array();
                     $group = '';
                     $show_all = true;
                     $show_infocoms = true;
                     $itemtable = getTableForItemType($itemtype);
                     if (InfoCom::canApplyOn($itemtype) && (!$itemtype::canUpdate() || !Infocom::canUpdate())) {
                         $show_all = false;
                         $show_infocoms = Infocom::canUpdate();
                     }
                     foreach (Search::getCleanedOptions($itemtype, UPDATE) as $index => $option) {
                         if (!is_array($option)) {
                             $group = $option;
                             $options_per_type[$itemtype][$group] = array();
                         } else {
                             if ($option['field'] != 'id' && $index != 1 && ($option["linkfield"] != 'entities_id' || isset($option['massiveaction']) && $option['massiveaction'])) {
                                 if (!isset($option['massiveaction']) || $option['massiveaction']) {
                                     if ($show_all || ($show_infocoms && Search::isInfocomOption($itemtype, $index) || !$show_infocoms && !Search::isInfocomOption($itemtype, $index))) {
                                         $options_per_type[$itemtype][$group][$itemtype . ':' . $index] = $option['name'];
                                         if ($itemtable == $option['table']) {
                                             $field_key = 'MAIN:' . $option['field'] . ':' . $index;
                                         } else {
                                             $field_key = $option['table'] . ':' . $option['field'] . ':' . $index;
                                         }
                                         if (!isset($options_count[$field_key])) {
                                             $options_count[$field_key] = array();
                                         }
                                         $options_count[$field_key][] = $itemtype . ':' . $index . ':' . $group;
                                         if (isset($option['MA_common_field'])) {
                                             if (!isset($options_count[$option['MA_common_field']])) {
                                                 $options_count[$option['MA_common_field']] = array();
                                             }
                                             $options_count[$option['MA_common_field']][] = $itemtype . ':' . $index . ':' . $group;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (count($itemtypes) > 1) {
                     $common_options = array();
                     foreach ($options_count as $field => $users) {
                         if (count($users) > 1) {
                             $labels = array();
                             foreach ($users as $user) {
                                 $user = explode(':', $user);
                                 $itemtype = $user[0];
                                 $index = $itemtype . ':' . $user[1];
                                 $group = implode(':', array_slice($user, 2));
                                 if (isset($options_per_type[$itemtype][$group][$index])) {
                                     if (!in_array($options_per_type[$itemtype][$group][$index], $labels)) {
                                         $labels[] = $options_per_type[$itemtype][$group][$index];
                                     }
                                 }
                                 $common_options[$field][] = $index;
                             }
                             $options[$group][$field] = implode('/', $labels);
                         }
                     }
                     $choose_itemtype = true;
                     $itemtype_choices = array(-1 => Dropdown::EMPTY_VALUE);
                     foreach ($itemtypes as $itemtype) {
                         $itemtype_choices[$itemtype] = $itemtype::getTypeName(Session::getPluralNumber());
                     }
                 } else {
                     $options = $options_per_type[$itemtypes[0]];
                     $common_options = false;
                     $choose_itemtype = false;
                 }
                 $choose_field = count($options) > 1;
                 // Beware: "class='tab_cadre_fixe'" induce side effects ...
                 echo "<table width='100%'><tr>";
                 $colspan = 0;
                 if ($choose_field) {
                     $colspan++;
                     echo "<td>";
                     if ($common_options) {
                         echo __('Select the common field that you want to update');
                     } else {
                         echo __('Select the field that you want to update');
                     }
                     echo "</td>";
                     if ($choose_itemtype) {
                         $colspan++;
                         echo "<td rowspan='2'>" . __('or') . "</td>";
                     }
                 }
                 if ($choose_itemtype) {
                     $colspan++;
                     echo "<td>" . __('Select the type of the item on which applying this action') . "</td>";
                 }
                 echo "</tr><tr>";
                 if ($choose_field) {
                     echo "<td>";
                     $field_rand = Dropdown::showFromArray('id_field', $options, array('display_emptychoice' => true));
                     echo "</td>";
                 }
                 if ($choose_itemtype) {
                     echo "<td>";
                     $itemtype_rand = Dropdown::showFromArray('specialize_itemtype', $itemtype_choices);
                     echo "</td>";
                 }
                 $next_step_rand = mt_rand();
                 echo "</tr></table>";
                 echo "<span id='update_next_step{$next_step_rand}'>&nbsp;</span>";
                 if ($choose_field) {
                     $params = $ma->POST;
                     $params['id_field'] = '__VALUE__';
                     $params['common_options'] = $common_options;
                     Ajax::updateItemOnSelectEvent("dropdown_id_field{$field_rand}", "update_next_step{$next_step_rand}", $_SERVER['REQUEST_URI'], $params);
                 }
                 if ($choose_itemtype) {
                     $params = $ma->POST;
                     $params['specialize_itemtype'] = '__VALUE__';
                     $params['common_options'] = $common_options;
                     Ajax::updateItemOnSelectEvent("dropdown_specialize_itemtype{$itemtype_rand}", "update_next_step{$next_step_rand}", $_SERVER['REQUEST_URI'], $params);
                 }
                 // Only display the form for this stage
                 exit;
             }
             if (!isset($ma->POST['common_options'])) {
                 echo "<div class='center'><img src='" . $CFG_GLPI["root_doc"] . "/pics/warning.png' alt='" . __s('Warning') . "'><br><br>";
                 echo "<span class='b'>" . __('Implementation error !') . "</span><br>";
                 echo "</div>";
                 exit;
             }
             if ($ma->POST['common_options'] == 'false') {
                 $search_options = array($ma->POST['id_field']);
             } else {
                 if (isset($ma->POST['common_options'][$ma->POST['id_field']])) {
                     $search_options = $ma->POST['common_options'][$ma->POST['id_field']];
                 } else {
                     $search_options = array();
                 }
             }
             $items = array();
             foreach ($search_options as $search_option) {
                 $search_option = explode(':', $search_option);
                 $itemtype = $search_option[0];
                 $index = $search_option[1];
                 if (!($item = getItemForItemtype($itemtype))) {
                     continue;
                 }
                 if (InfoCom::canApplyOn($itemtype)) {
                     Session::checkSeveralRightsOr(array($itemtype => UPDATE, "infocom" => UPDATE));
                 } else {
                     $item->checkGlobal(UPDATE);
                 }
                 $search = Search::getOptions($itemtype);
                 if (!isset($search[$index])) {
                     exit;
                 }
                 $item->search = $search[$index];
                 $items[] = $item;
             }
             if (count($items) == 0) {
                 exit;
             }
             // TODO: ensure that all items are equivalent ...
             $item = $items[0];
             $search = $item->search;
             $plugdisplay = false;
             if (($plug = isPluginItemType($item->getType())) || ($plug = isPluginItemType(getItemTypeForTable($item->search['table'])))) {
                 $plugdisplay = Plugin::doOneHook($plug['plugin'], 'MassiveActionsFieldsDisplay', array('itemtype' => $item->getType(), 'options' => $item->search));
             }
             if (empty($search["linkfield"]) || $search['table'] == 'glpi_infocoms') {
                 $fieldname = $search["field"];
             } else {
                 $fieldname = $search["linkfield"];
             }
             if (!$plugdisplay) {
                 $options = array();
                 $values = array();
                 // For ticket template or aditional options of massive actions
                 if (isset($ma->POST['options'])) {
                     $options = $ma->POST['options'];
                 }
                 if (isset($ma->POST['additionalvalues'])) {
                     $values = $ma->POST['additionalvalues'];
                 }
                 $values[$search["field"]] = '';
                 echo $item->getValueToSelect($search, $fieldname, $values, $options);
             }
             $items_index = array();
             foreach ($search_options as $search_option) {
                 $search_option = explode(':', $search_option);
                 $items_index[$search_option[0]] = $search_option[1];
             }
             echo Html::hidden('search_options', array('value' => $items_index));
             echo Html::hidden('field', array('value' => $fieldname));
             echo "<br>\n";
             $submitname = _sx('button', 'Post');
             if (isset($ma->POST['submitname']) && $ma->POST['submitname']) {
                 $submitname = stripslashes($ma->POST['submitname']);
             }
             echo Html::submit($submitname, array('name' => 'massiveaction'));
             return true;
     }
     return false;
 }
Ejemplo n.º 8
0
 /**
  * Get comments of the Object
  *
  * @return String: comments of the object in the current language (HTML)
  **/
 function getComments()
 {
     $comment = "";
     $toadd = array();
     if ($this->isField('completename')) {
         $toadd[] = array('name' => __('Complete name'), 'value' => nl2br($this->getField('completename')));
     }
     if ($this->isField('serial')) {
         $toadd[] = array('name' => __('Serial number'), 'value' => nl2br($this->getField('serial')));
     }
     if ($this->isField('otherserial')) {
         $toadd[] = array('name' => __('Inventory number'), 'value' => nl2br($this->getField('otherserial')));
     }
     if ($this->isField('states_id') && $this->getType() != 'State') {
         $tmp = Dropdown::getDropdownName('glpi_states', $this->getField('states_id'));
         if (strlen($tmp) != 0 && $tmp != '&nbsp;') {
             $toadd[] = array('name' => __('Status'), 'value' => $tmp);
         }
     }
     if ($this->isField('locations_id') && $this->getType() != 'Location') {
         $tmp = Dropdown::getDropdownName("glpi_locations", $this->getField('locations_id'));
         if (strlen($tmp) != 0 && $tmp != '&nbsp;') {
             $toadd[] = array('name' => __('Location'), 'value' => $tmp);
         }
     }
     if ($this->isField('users_id')) {
         $tmp = getUserName($this->getField('users_id'));
         if (strlen($tmp) != 0 && $tmp != '&nbsp;') {
             $toadd[] = array('name' => __('User'), 'value' => $tmp);
         }
     }
     if ($this->isField('groups_id') && $this->getType() != 'Group') {
         $tmp = Dropdown::getDropdownName("glpi_groups", $this->getField('groups_id'));
         if (strlen($tmp) != 0 && $tmp != '&nbsp;') {
             $toadd[] = array('name' => __('Group'), 'value' => $tmp);
         }
     }
     if ($this->isField('users_id_tech')) {
         $tmp = getUserName($this->getField('users_id_tech'));
         if (strlen($tmp) != 0 && $tmp != '&nbsp;') {
             $toadd[] = array('name' => __('Technician in charge of the hardware'), 'value' => $tmp);
         }
     }
     if ($this->isField('contact')) {
         $toadd[] = array('name' => __('Alternate username'), 'value' => nl2br($this->getField('contact')));
     }
     if ($this->isField('contact_num')) {
         $toadd[] = array('name' => __('Alternate username number'), 'value' => nl2br($this->getField('contact_num')));
     }
     if (InfoCom::canApplyOn($this)) {
         $infocom = new Infocom();
         if ($infocom->getFromDBforDevice($this->getType(), $this->fields['id'])) {
             $toadd[] = array('name' => __('Warranty expiration date'), 'value' => Infocom::getWarrantyExpir($infocom->fields["warranty_date"], $infocom->fields["warranty_duration"], 0, true));
         }
     }
     if ($this instanceof CommonDropdown && $this->isField('comment')) {
         $toadd[] = array('name' => __('Comments'), 'value' => nl2br($this->getField('comment')));
     }
     if (count($toadd)) {
         foreach ($toadd as $data) {
             // Do not use SPAN here
             $comment .= sprintf(__('%1$s: %2$s') . "<br>", "<strong>" . $data['name'], "</strong>" . $data['value']);
         }
     }
     if (!empty($comment)) {
         return Html::showToolTip($comment, array('display' => false));
     }
     return $comment;
 }