/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'delete_for_user': $input = $ma->getInput(); if (isset($input['users_id'])) { $user = new User(); $user->getFromDB($input['users_id']); foreach ($ids as $id) { if ($input['users_id'] == Session::getLoginUserID()) { if ($item->deleteByCriteria(array('users_id' => $input['users_id'], 'itemtype' => $id))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($user->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($user->getErrorMessage(ERROR_RIGHT)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case "use_filter_assign_group": $escalade_user = new self(); $input = $ma->getInput(); foreach ($ids as $id) { if ($escalade_user->getFromDBByQuery("WHERE users_id = {$id}")) { $escalade_user->fields['use_filter_assign_group'] = $input['use_filter_assign_group']; if ($escalade_user->update($escalade_user->fields)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } } }
/** * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'sendmail': foreach ($ids as $id) { if ($item->canEdit($id)) { if ($item->sendMailById($id)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @see CommonDBTM::processMassiveActionsForOneItemtype() * @param MassiveAction $ma * @param CommonDBTM $item * @param array $ids * @return void */ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'deleteSelected': if (isset($_POST['items']['PluginFpsoftwareCommon']) && is_array($_POST['items']['PluginFpsoftwareCommon'])) { foreach ($_POST['items']['PluginFpsoftwareCommon'] as $id => $val) { self::deleteItem($id); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } } break; } }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $CFG_GLPI; switch ($ma->getAction()) { case "uninstall": $itemtype = $ma->getItemtype(false); foreach ($ids as $id) { if ($item->getFromDB($id)) { //Session::addMessageAfterRedirect(sprintf(__('Form duplicated: %s', 'formcreator'), $item->getName())); $_SESSION['glpi_uninstalllist'][$itemtype][$id] = $id; $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } } Html::redirect($CFG_GLPI["root_doc"] . '/plugins/uninstall/front/action.php?device_type=' . $itemtype . "&model_id=" . $_POST["model_id"]); return; break; } return; }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'duplicate': // For calendar duplicate in another entity if (method_exists($item, 'duplicate')) { $input = $ma->getInput(); $options = array(); if ($item->isEntityAssign()) { $options = array('entities_id' => $input['entities_id']); } foreach ($ids as $id) { if ($item->getFromDB($id)) { if (!$item->isEntityAssign() || $input['entities_id'] != $item->getEntityID()) { if ($item->can(-1, CREATE, $options)) { if ($item->duplicate($options)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_COMPAT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $CFG_GLPI; switch ($ma->getAction()) { case "transfert": $input = $ma->getInput(); $entities_id = $input['entities_id']; foreach ($ids as $id) { if ($item->getFromDB($id)) { $item->update(array("id" => $id, "entities_id" => $entities_id, "update" => __('Update'))); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } } return; break; } return; }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() * @param MassiveAction $ma * @param CommonDBTM $item * @param array $ids * @return nothing|void */ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case "plugin_ocsinventoryng_update_networkport_type": $networkport = new PluginOcsinventoryngNetworkPort(); $input = $ma->getInput(); foreach ($ids as $id) { if ($networkport->getFromDBByQuery("WHERE `networkports_id` = '{$id}'")) { if ($networkport->transformAccordingTypes()) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'add_followup': $input = $ma->getInput(); $fup = new self(); foreach ($ids as $id) { if ($item->getFromDB($id)) { $input2 = array('tickets_id' => $id, 'is_private' => $input['is_private'], 'requesttypes_id' => $input['requesttypes_id'], 'content' => $input['content']); if ($fup->can(-1, CREATE, $input2)) { if ($fup->add($input2)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() * */ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case "transfer": $input = $ma->getInput(); if ($item->getType() == 'PluginTasklistsTask') { foreach ($ids as $key) { $item->getFromDB($key); $type = PluginTasklistsTaskType::transfer($item->fields["plugin_tasklists_tasktypes_id"], $input['entities_id']); if ($type > 0) { $values["id"] = $key; $values["plugin_tasklists_tasktypes_id"] = $type; $item->update($values); } unset($values); $values["id"] = $key; $values["entities_id"] = $input['entities_id']; if ($item->update($values)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'reset': if (Config::canUpdate()) { foreach ($ids as $key) { if ($item->getFromDB($key)) { if ($item->resetDate()) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'force_user_ldap_update': foreach ($ids as $id) { if ($item->can($id, UPDATE)) { if ($item->fields["authtype"] == Auth::LDAP || $item->fields["authtype"] == Auth::EXTERNAL) { if (AuthLdap::ldapImportUserByServerId(array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $item->fields["name"]), 1, $item->fields["auths_id"])) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; case 'change_authtype': $input = $ma->getInput(); if (!isset($input["authtype"]) || !isset($input["auths_id"])) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); return; } if (Session::haveRight(self::$rightname, self::UPDATEAUTHENT)) { if (User::changeAuthMethod($ids, $input["authtype"], $input["auths_id"])) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'duplicate': // For calendar duplicate in another entity if (method_exists($item, 'duplicate')) { $input = $ma->getInput(); $options = array(); if ($item->isEntityAssign()) { $options = array('entities_id' => $input['entities_id']); } foreach ($ids as $id) { if ($item->getFromDB($id)) { if (!$item->isEntityAssign() || $input['entities_id'] != $item->getEntityID()) { if ($item->can(-1, CREATE, $options)) { if ($item->duplicate($options)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_COMPAT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; case 'addholiday': // add an holiday with massive action $input = $ma->getInput(); if ($input['holidays_id'] > 0) { $holiday = new Holiday(); $calendar_holiday = new Calendar_Holiday(); $holiday->getFromDB($input['holidays_id']); $entities = array($holiday->getEntityID() => $holiday->getEntityID()); if ($holiday->isRecursive()) { $entities = getSonsOf("glpi_entities", $holiday->getEntityID()); } foreach ($ids as $id) { $entities_id = CommonDBTM::getItemEntity('Calendar', $id); if (isset($entities[$entities_id])) { $input = array('calendars_id' => $id, 'holidays_id' => $input['holidays_id']); if ($calendar_holiday->add($input)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $baseitem, array $ids) { global $DB; switch ($ma->getAction()) { case 'unlock': $input = $ma->getInput(); if (isset($input['attached_item'])) { $attached_items = $input['attached_item']; if (($device_key = array_search('Device', $attached_items)) !== false) { unset($attached_items[$device_key]); $attached_items = array_merge($attached_items, Item_Devices::getDeviceTypes()); } $links = array(); foreach ($attached_items as $attached_item) { $infos = self::getLocksQueryInfosByItemType($attached_item, $baseitem->getType()); if ($item = getItemForItemtype($infos['type'])) { $infos['item'] = $item; $links[$attached_item] = $infos; } } foreach ($ids as $id) { $action_valid = false; foreach ($links as $infos) { $infos['condition'][$infos['field']] = $id; foreach ($DB->request($infos['table'], $infos['condition']) as $data) { // Restore without history $action_valid = $infos['item']->restore(array('id' => $data['id'])); } } if ($action_valid) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($infos['item']->getErrorMessage(ERROR_ON_ACTION)); } } } return; } parent::processMassiveActionsForOneItemtype($ma, $baseitem, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'solveticket': $input = $ma->getInput(); $ticket = new Ticket(); foreach ($ids as $id) { if ($item->can($id, READ)) { if ($ticket->getFromDB($item->fields['tickets_id']) && $ticket->canSolve()) { $toupdate = array(); $toupdate['id'] = $ticket->getID(); $toupdate['solutiontypes_id'] = $input['solutiontypes_id']; $toupdate['solution'] = $input['solution']; if ($ticket->update($toupdate)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($ticket->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT)); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $CFG_GLPI; switch ($ma->getAction()) { case 'Generate': $pbQRcode = new PluginBarcodeQRcode(); $rand = mt_rand(); $number = 0; $codes = array(); if ($ma->POST['eliminate'] > 0) { for ($nb = 0; $nb < $ma->POST['eliminate']; $nb++) { $codes[] = ''; } } if ($ma->POST['type'] == 'QRcode') { foreach ($ids as $key) { $filename = $pbQRcode->generateQRcode($item->getType(), $key, $rand, $number, $ma->POST); if ($filename) { $codes[] = $filename; $number++; } } } else { foreach ($ids as $key) { $item->getFromDB($key); if ($item->isField('otherserial')) { $codes[] = $item->getField('otherserial'); } } } if (count($codes) > 0) { $params['codes'] = $codes; $params['type'] = $ma->POST['type']; $params['size'] = $ma->POST['size']; $params['border'] = $ma->POST['border']; $params['orientation'] = $ma->POST['orientation']; $barcode = new PluginBarcodeBarcode(); $file = $barcode->printPDF($params); $filePath = explode('/', $file); $filename = $filePath[count($filePath) - 1]; $msg = "<a href='" . $CFG_GLPI['root_doc'] . '/plugins/barcode/front/send.php?file=' . urlencode($filename) . "'>" . __('Generated file', 'barcode') . "</a>"; Session::addMessageAfterRedirect($msg); $pbQRcode->cleanQRcodefiles($rand, $number); } $ma->itemDone($item->getType(), 0, MassiveAction::ACTION_OK); return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'move_license': $input = $ma->getInput(); if (isset($input['softwarelicenses_id'])) { foreach ($ids as $id) { if ($item->can($id, UPDATE)) { //Process rules if ($item->update(array('id' => $id, 'softwarelicenses_id' => $input['softwarelicenses_id']))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; case 'install': $csl = new self(); $csv = new Computer_SoftwareVersion(); foreach ($ids as $id) { if ($csl->getFromDB($id)) { $sl = new SoftwareLicense(); if ($sl->getFromDB($csl->fields["softwarelicenses_id"])) { $version = 0; if ($sl->fields["softwareversions_id_use"] > 0) { $version = $sl->fields["softwareversions_id_use"]; } else { $version = $sl->fields["softwareversions_id_buy"]; } if ($version > 0) { $params = array('computers_id' => $csl->fields['computers_id'], 'softwareversions_id' => $version); //Get software name and manufacturer if ($csv->can(-1, CREATE, $params)) { //Process rules if ($csv->add($params)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'duplicate': $rulecollection = new RuleCollection(); foreach ($ids as $id) { if ($item->getFromDB($id)) { if ($rulecollection->duplicateRule($id)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } break; case 'export': if (count($ids)) { $_SESSION['exportitems'] = $ids; $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK); $ma->setRedirect('rule.backup.php?action=download&itemtype=' . $item->getType()); } break; case 'move_rule': $input = $ma->getInput(); $collectionname = $input['rule_class_name'] . 'Collection'; $rulecollection = new $collectionname(); if ($rulecollection->canUpdate()) { foreach ($ids as $id) { if ($item->getFromDB($id)) { if ($rulecollection->moveRule($id, $input['ranking'], $input['move_type'])) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } break; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'add_task': if (!($task = getItemForItemtype('TicketTask'))) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); break; } $ticket = new Ticket(); $field = $ticket->getForeignKeyField(); $input = $ma->getInput(); foreach ($ids as $id) { if ($item->can($id, READ)) { if ($ticket->getFromDB($item->fields['tickets_id'])) { $input2 = array($field => $item->fields['tickets_id'], 'taskcategories_id' => $input['taskcategories_id'], 'actiontime' => $input['actiontime'], 'content' => $input['content']); if ($task->can(-1, CREATE, $input2)) { if ($task->add($input2)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } } return; case 'solveticket': $input = $ma->getInput(); $ticket = new Ticket(); foreach ($ids as $id) { if ($item->can($id, READ)) { if ($ticket->getFromDB($item->fields['tickets_id']) && $ticket->canSolve()) { $toupdate = array(); $toupdate['id'] = $ticket->getID(); $toupdate['solutiontypes_id'] = $input['solutiontypes_id']; $toupdate['solution'] = $input['solution']; if ($ticket->update($toupdate)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($ticket->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT)); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'transform_to': $input = $ma->getInput(); if (isset($input["transform_to"]) && !empty($input["transform_to"])) { $networkport = new NetworkPort(); foreach ($ids as $id) { if ($networkport->canEdit($id) && $item->can($id, DELETE)) { if (empty($networkport->fields['instantiation_type'])) { if ($networkport->switchInstantiationType($input['transform_to']) !== false) { $instantiation = $networkport->getInstantiation(); $input2 = $item->fields; $input2['networkports_id'] = $input2['id']; unset($input2['id']); if ($instantiation->add($input2)) { $item->delete(array('id' => $id)); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($networkport->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($networkport->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($networkport->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($networkport->getErrorMessage(ERROR_RIGHT)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'changegroup': $input = $ma->getInput(); if (isset($input["field"]) && isset($input['groups_id'])) { foreach ($ids as $id) { if ($item->can($id, UPDATE)) { if ($item->update(array('id' => $id, $input["field"] => $input["groups_id"]))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } return; } parent::processMassiveActionsForOneItemtype($ma, $baseitem, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() * @param MassiveAction $ma * @param CommonDBTM $item * @param array $ids * @return nothing|void */ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { $notimport = new PluginOcsinventoryngNotimportedcomputer(); switch ($ma->getAction()) { case "plugin_ocsinventoryng_import": $input = $ma->getInput(); foreach ($ids as $id) { if (PluginOcsinventoryngNotimportedcomputer::computerImport(array('id' => $id, 'force' => true, 'entity' => $input['entity']))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } return; case "plugin_ocsinventoryng_replayrules": foreach ($ids as $id) { if (PluginOcsinventoryngNotimportedcomputer::computerImport(array('id' => $id))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } return; case "plugin_ocsinventoryng_delete": foreach ($ids as $id) { if ($notimport->deleteNotImportedComputer($id)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $CFG_GLPI; $input = $ma->getInput(); switch ($ma->getAction()) { case 'import_group': $group = new Group(); if (!Session::haveRight("user", User::UPDATEAUTHENT) || !$group->canGlobal(UPDATE)) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); return; } foreach ($ids as $id) { if (isset($input["dn"][$id])) { $group_dn = $input["dn"][$id]; if (isset($input["ldap_import_entities"][$id])) { $entity = $input["ldap_import_entities"][$id]; } else { $entity = $_SESSION["glpiactive_entity"]; } // Is recursive is in the main form and thus, don't pass through // zero_on_empty mechanism inside massive action form ... $is_recursive = empty($input['ldap_import_recursive'][$id]) ? 0 : 1; $options = array('authldaps_id' => $_SESSION['ldap_server'], 'entities_id' => $entity, 'is_recursive' => $is_recursive, 'type' => $input['ldap_import_type'][$id]); if (AuthLdap::ldapImportGroup($group_dn, $options)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION, $group_dn)); } } // Clean history as id does not correspond to group $_SESSION['glpimassiveactionselected'] = array(); } return; case 'import': case 'sync': if (!Session::haveRight("user", User::IMPORTEXTAUTHUSERS)) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); return; } foreach ($ids as $id) { if (AuthLdap::ldapImportUserByServerId(array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $id), $_SESSION['ldap_import']['mode'], $_SESSION['ldap_import']['authldaps_id'], true)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION, $id)); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'export': foreach ($ids as $key) { if ($item->can($key, UPDATE)) { $item->exportPackage($key); $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } } break; case 'transfert': $pfDeployPackage = new PluginFusioninventoryDeployPackage(); foreach ($ids as $key) { if ($pfDeployPackage->getFromDB($key)) { $input = array(); $input['id'] = $key; $input['entities_id'] = $ma->POST['entities_id']; $pfDeployPackage->update($input); } } break; case 'import': foreach ($ids as $key) { $item->importPackage($key); $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } break; } return; }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case "transfer": $input = $ma->getInput(); if ($item->getType() == 'PluginRacksRack') { foreach ($ids as $key) { $values["id"] = $key; $values["entities_id"] = $input['entities_id']; if ($item->update($values)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } break; } }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'uninstall': foreach ($ids as $key) { if ($item->can($key, UPDATE)) { if ($item->uninstall($key)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; case 'backtostock': foreach ($ids as $id) { if ($item->can($id, UPDATE)) { if ($item->backToStock(array("id" => $id))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; case 'updatepages': $input = $ma->getInput(); if (isset($input['pages'])) { foreach ($ids as $key) { if ($item->can($key, UPDATE)) { if ($item->update(array('id' => $key, 'pages' => $input['pages']))) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'add_actor': $input = $ma->getInput(); foreach ($ids as $id) { $input2 = array('id' => $id); if (isset($input['_itil_requester'])) { $input2['_itil_requester'] = $input['_itil_requester']; } if (isset($input['_itil_observer'])) { $input2['_itil_observer'] = $input['_itil_observer']; } if (isset($input['_itil_assign'])) { $input2['_itil_assign'] = $input['_itil_assign']; } if ($item->can($id, UPDATE)) { if ($item->update($input2)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; case 'update_notif': $input = $ma->getInput(); foreach ($ids as $id) { if ($item->can($id, UPDATE)) { $linkclass = new $item->userlinkclass(); foreach ($linkclass->getActors($id) as $type => $users) { foreach ($users as $data) { $data['use_notification'] = $input['use_notification']; $linkclass->update($data); } } $linkclass = new $this->supplierlinkclass(); foreach ($linkclass->getActors($id) as $type => $users) { foreach ($users as $data) { $data['use_notification'] = $input['use_notification']; $linkclass->update($data); } } $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; case 'add_task': if (!($task = getItemForItemtype($item->getType() . 'Task'))) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); break; } $field = $item->getForeignKeyField(); $input = $ma->getInput(); foreach ($ids as $id) { if ($item->getFromDB($id)) { $input2 = array($field => $id, 'taskcategories_id' => $input['taskcategories_id'], 'content' => $input['content']); if ($task->can(-1, CREATE, $input2)) { if ($task->add($input2)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case "add_model": $model = new PluginManufacturersimportsModel(); $input = $ma->getInput(); foreach ($ma->items as $itemtype => $myitem) { foreach ($myitem as $key => $value) { $input = array('model_name' => $ma->POST['model_name'], 'items_id' => $key, 'itemtype' => $itemtype); if ($model->addModel($input)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } break; } }
/** * @since version 0.90 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'merge': foreach ($ids as $key) { if ($item->can($key, UPDATE)) { if ($item->getEntityID() == $_SESSION['glpiactive_entity']) { if ($item->update(array('id' => $key, 'is_recursive' => 1))) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $input2 = $item->fields; // Change entity $input2['entities_id'] = $_SESSION['glpiactive_entity']; $input2['is_recursive'] = 1; $input2 = Toolbox::addslashes_deep($input2); if (!$item->import($input2)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'activate': $ic = new self(); if ($ic->canCreate()) { $itemtype = $item->getType(); foreach ($ids as $key) { if (!$ic->getFromDBforDevice($itemtype, $key)) { $input = array('itemtype' => $itemtype, 'items_id' => $key); if ($ic->can(-1, CREATE, $input)) { if ($ic->add($input)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($ic->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($ic->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($ic->getErrorMessage(ERROR_NOT_FOUND)); } } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }