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 * @since version 0.85 */ include '../inc/includes.php'; $rule = new Rule(); $rule->getFromDB(intval($_POST['rules_id'])); $criteria = new RuleCriteria($rule->fields['sub_type']); if (isset($_POST["add"])) { $criteria->check(-1, CREATE, $_POST); $criteria->add($_POST); Html::back(); } else { if (isset($_POST["update"])) { $criteria->check($_POST['id'], UPDATE); $criteria->update($_POST); Html::back(); } else { if (isset($_POST["purge"])) { $criteria->check($_POST['id'], PURGE); $criteria->delete($_POST, 1); Html::back(); } } }
public function submitForm($postvars) { if (isset($postvars['forcestart'])) { Session::checkRight('plugin_fusioninventory_task', UPDATE); /** * TODO: forcing the task execution should be done in the task object */ $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfTaskjob->forceRunningTask($postvars['id']); Html::back(); } else { if (isset($postvars["add"])) { Session::checkRight('plugin_fusioninventory_task', CREATE); $items_id = $this->add($postvars); Html::redirect(str_replace("add=1", "", $_SERVER['HTTP_REFERER']) . "?id=" . $items_id); } else { if (isset($postvars["purge"])) { Session::checkRight('plugin_fusioninventory_task', PURGE); $pfTaskJob = new PluginFusioninventoryTaskjob(); $taskjobs = $pfTaskJob->find("`plugin_fusioninventory_tasks_id` = '" . $postvars['id'] . "' "); foreach ($taskjobs as $taskjob) { $pfTaskJob->delete($taskjob); } $this->delete($postvars); Html::redirect(Toolbox::getItemTypeSearchURL(get_class($this))); } else { if (isset($_POST["update"])) { Session::checkRight('plugin_fusioninventory_task', UPDATE); $this->getFromDB($postvars['id']); //Ensure empty value are set to NULL for datetime fields if (isset($postvars['datetime_start']) and $postvars['datetime_start'] === '') { $postvars['datetime_start'] = 'NULL'; } if (isset($postvars['datetime_end']) and $postvars['datetime_end'] === '') { $postvars['datetime_end'] = 'NULL'; } $this->update($postvars); Html::back(); } } } } }
/** * @since version 0.83 (before addRule) * * @param $input array of values **/ function executeAddRule($input) { $this->check($_POST["affectentity"], UPDATE); $collection = RuleCollection::getClassByType($_POST['sub_type']); $rule = $collection->getRuleClass($_POST['sub_type']); $ruleid = $rule->add($_POST); if ($ruleid) { //Add an action associated to the rule $ruleAction = new RuleAction(); //Action is : affect computer to this entity $ruleAction->addActionByAttributes("assign", $ruleid, "entities_id", $_POST["affectentity"]); switch ($_POST['sub_type']) { case 'RuleRight': if ($_POST["profiles_id"]) { $ruleAction->addActionByAttributes("assign", $ruleid, "profiles_id", $_POST["profiles_id"]); } $ruleAction->addActionByAttributes("assign", $ruleid, "is_recursive", $_POST["is_recursive"]); } } Event::log($ruleid, "rules", 4, "setup", sprintf(__('%s adds the item'), $_SESSION["glpiname"])); Html::back(); }
public function saveForm() { $valid = true; $tab_section = array(); $sections = new PluginFormcreatorSection(); $found_sections = $sections->find('`plugin_formcreator_forms_id` = ' . $this->getID()); foreach ($found_sections as $id => $fields) { $tab_section[] = $id; } $questions = new PluginFormcreatorQuestion(); $found_questions = $questions->find('`plugin_formcreator_sections_id` IN (' . implode(',', $tab_section) . ')'); // Validate form fields foreach ($found_questions as $id => $fields) { // If field was not post, it's value is empty if (isset($_POST['formcreator_field_' . $id])) { $datas[$id] = is_array($_POST['formcreator_field_' . $id]) ? json_encode($_POST['formcreator_field_' . $id]) : $_POST['formcreator_field_' . $id]; // Replace "," by "." if field is a float field and remove spaces if ($fields['fieldtype'] == 'float') { $datas[$id] = str_replace(',', '.', $datas[$id]); $datas[$id] = str_replace(' ', '', $datas[$id]); } unset($_POST['formcreator_field_' . $id]); } else { $datas[$id] = ''; } $className = $fields['fieldtype'] . 'Field'; $filePath = dirname(__FILE__) . '/fields/' . $fields['fieldtype'] . '-field.class.php'; if (is_file($filePath)) { include_once $filePath; if (class_exists($className)) { $obj = new $className($fields, $datas); if (!$obj->isValid($datas[$id])) { $valid = false; } } } else { $valid = false; } } $datas = $datas + $_POST; // Check required_validator if ($this->fields['validation_required'] && empty($datas['formcreator_validator'])) { Session::addMessageAfterRedirect(__('You must select validator !', 'formcreator'), false, ERROR); $valid = false; } // If not valid back to form if (!$valid) { foreach ($datas as $key => $value) { if (is_array($value)) { foreach ($value as $key2 => $value2) { $datas[$key][$key2] = plugin_formcreator_encode($value2); } } elseif (is_array(json_decode($value))) { $value = json_decode($value); foreach ($value as $key2 => $value2) { $value[$key2] = plugin_formcreator_encode($value2); } $datas[$key] = json_encode($value); } else { $datas[$key] = plugin_formcreator_encode($value); } } $_SESSION['formcreator']['datas'] = $datas; Html::back(); // Save form } else { $formanswer = new PluginFormcreatorFormanswer(); $formanswer->saveAnswers($datas); } }
/** * Submit Form values */ public function submitForm($postvars) { if (isset($postvars['definition_add'])) { // * Add a definition $mytaskjob->getFromDB($postvars['id']); $a_listdef = importArrayFromDB($mytaskjob->fields['definition']); $add = 1; foreach ($a_listdef as $dataDB) { if (isset($dataDB[$postvars['DefinitionType']]) and $dataDB[$postvars['DefinitionType']] == $postvars['definitionselectiontoadd']) { $add = 0; break; } } if ($add == '1') { if (isset($postvars['DefinitionType']) and $postvars['DefinitionType'] != '') { $a_listdef[] = array($postvars['DefinitionType'] => $postvars['definitionselectiontoadd']); } } $input = array(); $input['id'] = $postvars['id']; $input['definition'] = exportArrayToDB($a_listdef); $mytaskjob->update($input); Html::back(); } else { if (isset($postvars['action_add'])) { // * Add an action $mytaskjob->getFromDB($postvars['id']); $a_listact = importArrayFromDB($mytaskjob->fields['action']); $add = 1; foreach ($a_listact as $dataDB) { if (isset($dataDB[$postvars['ActionType']]) and $dataDB[$postvars['ActionType']] == $postvars['actionselectiontoadd']) { $add = 0; break; } } if ($add == '1') { if (isset($postvars['ActionType']) and $postvars['ActionType'] != '') { $a_listact[] = array($postvars['ActionType'] => $postvars['actionselectiontoadd']); } } $input = array(); $input['id'] = $postvars['id']; $input['action'] = exportArrayToDB($a_listact); $mytaskjob->update($input); Html::back(); } else { if (isset($postvars['definition_delete'])) { // * Delete definition $mytaskjob->getFromDB($postvars['id']); $a_listdef = importArrayFromDB($mytaskjob->fields['definition']); foreach ($postvars['definition_to_delete'] as $itemdelete) { $datadel = explode('-', $itemdelete); foreach ($a_listdef as $num => $dataDB) { if (isset($dataDB[$datadel[0]]) and $dataDB[$datadel[0]] == $datadel[1]) { unset($a_listdef[$num]); } } } $input = array(); $input['id'] = $postvars['id']; $input['definition'] = exportArrayToDB($a_listdef); $mytaskjob->update($input); Html::back(); } else { if (isset($postvars['action_delete'])) { // * Delete action $mytaskjob->getFromDB($postvars['id']); $a_listact = importArrayFromDB($mytaskjob->fields['action']); foreach ($postvars['action_to_delete'] as $itemdelete) { $datadel = explode('-', $itemdelete); foreach ($a_listact as $num => $dataDB) { if (isset($dataDB[$datadel[0]]) and $dataDB[$datadel[0]] == $datadel[1]) { unset($a_listact[$num]); } } } $input = array(); $input['id'] = $postvars['id']; $input['action'] = exportArrayToDB($a_listact); $mytaskjob->update($input); Html::back(); /** * Wizard related method disabled for 0.85 * TODO: cf. TaskJob::showQuickForm() */ //} else if (isset($postvars['quickform'])) { // $pfTask = new PluginFusioninventoryTask(); // if (isset($postvars['update'])) { // $mytaskjob->getFromDB($postvars['id']); // $pfTask->getFromDB($mytaskjob->fields['plugin_fusioninventory_tasks_id']); // } // $inputtaskjob = array(); // $inputtask = array(); // if (isset($postvars['update'])) { // $inputtaskjob['id'] = $postvars['id']; // $inputtask['id'] = $mytaskjob->fields['plugin_fusioninventory_tasks_id']; // } // $inputtaskjob['name'] = $postvars['name']; // if (isset($postvars['add']) OR $pfTask->fields['name'] == '') { // $inputtask['name'] = $postvars['name']; // } // $inputtask['is_active'] = $postvars['is_active']; // $inputtaskjob['method'] = $postvars['method']; // $inputtask['communication'] = $postvars['communication']; // $inputtask['periodicity_count'] = $postvars['periodicity_count']; // $inputtask['periodicity_type'] = $postvars['periodicity_type']; // $inputtask['entities_id'] = $_SESSION['glpiactive_entity']; // $inputtaskjob['entities_id'] = $_SESSION['glpiactive_entity']; // if (isset($postvars['update'])) { // $mytaskjob->update($inputtaskjob); // $pfTask->update($inputtask); // Html::back(); // } else if (isset($postvars['add'])) { // if (!isset($postvars['entities_id'])) { // $postvars['entities_id'] = $_SESSION['glpidefault_entity']; // } // // Get entity of task // if (isset($postvars['plugin_fusioninventory_tasks_id'])) { // $pfTask = new PluginFusioninventoryTask(); // $pfTask->getFromDB($postvars['plugin_fusioninventory_tasks_id']); // $entities_list = getSonsOf('glpi_entities', $pfTask->fields['entities_id']); // if (!in_array($postvars['entities_id'], $entities_list)) { // $postvars['entities_id'] = $pfTask->fields['entities_id']; // } // } else { // $inputtask['date_scheduled'] = date("Y-m-d H:i:s"); // $task_id = $pfTask->add($inputtask); // $inputtaskjob['plugin_fusioninventory_tasks_id'] = $task_id; // } // if (isset($postvars['method_id'])) { // $postvars['method'] = $postvars['method_id']; // } // $inputtaskjob['plugins_id'] = $postvars['method-'.$postvars['method']]; // $taskjobs_id = $mytaskjob->add($inputtaskjob); // $redirect = $_SERVER['HTTP_REFERER']; // $redirect = str_replace('&id=0', '&id='.$taskjobs_id, $redirect); // Html::redirect($redirect); // } } else { if (isset($postvars['taskjobstoforcerun'])) { // * Force running many tasks (wizard) Session::checkRight('plugin_fusioninventory_task', UPDATE); $pfTaskjob = new PluginFusioninventoryTaskjob(); $_SESSION["plugin_fusioninventory_forcerun"] = array(); foreach ($postvars['taskjobstoforcerun'] as $taskjobs_id) { $pfTaskjob->getFromDB($taskjobs_id); $uniqid = $pfTaskjob->forceRunningTask($pfTaskjob->fields['plugin_fusioninventory_tasks_id']); $_SESSION["plugin_fusioninventory_forcerun"][$taskjobs_id] = $uniqid; } unset($_SESSION["MESSAGE_AFTER_REDIRECT"]); } else { if (isset($postvars['add']) || isset($postvars['update'])) { // * Add and update taskjob Session::checkRight('plugin_fusioninventory_task', CREATE); if (isset($postvars['add'])) { if (!isset($postvars['entities_id'])) { $postvars['entities_id'] = $_SESSION['glpidefault_entity']; } // Get entity of task $pfTask = new PluginFusioninventoryTask(); $pfTask->getFromDB($postvars['plugin_fusioninventory_tasks_id']); $entities_list = getSonsOf('glpi_entities', $pfTask->fields['entities_id']); if (!in_array($postvars['entities_id'], $entities_list)) { $postvars['entities_id'] = $pfTask->fields['entities_id']; } //$postvars['execution_id'] = $pfTask->fields['execution_id']; $this->add($postvars); } else { if (isset($postvars['method_id'])) { $postvars['method'] = $postvars['method_id']; } $targets = array(); if (array_key_exists('targets', $postvars) and is_array($postvars['targets']) and count($postvars['targets']) > 0) { foreach ($postvars['targets'] as $target) { list($itemtype, $itemid) = explode('-', $target); $targets[] = array($itemtype => $itemid); } } $postvars['targets'] = exportArrayToDB($targets); $actors = array(); if (array_key_exists('actors', $postvars) and is_array($postvars['actors']) and count($postvars['actors']) > 0) { foreach ($postvars['actors'] as $actor) { list($itemtype, $itemid) = explode('-', $actor); $actors[] = array($itemtype => $itemid); } } $postvars['actors'] = exportArrayToDB($actors); //TODO: get rid of plugins_id and just use method //$postvars['plugins_id'] = $postvars['method-'.$postvars['method']]; $this->update($postvars); } } else { if (isset($postvars["delete"])) { // * delete taskjob Session::checkRight('plugin_fusioninventory_task', PURGE); $this->delete($postvars); } elseif (isset($postvars['itemaddaction'])) { $array = explode("||", $postvars['methodaction']); $module = $array[0]; $method = $array[1]; // Add task $mytask = new PluginFusioninventoryTask(); $input = array(); $input['name'] = $method; $task_id = $mytask->add($input); // Add job with this device $input = array(); $input['plugin_fusioninventory_tasks_id'] = $task_id; $input['name'] = $method; $input['datetime_start'] = $postvars['datetime_start']; $input['plugins_id'] = PluginFusioninventoryModule::getModuleId($module); $input['method'] = $method; $a_selectionDB = array(); $a_selectionDB[][$postvars['itemtype']] = $postvars['items_id']; $input['definition'] = exportArrayToDB($a_selectionDB); $taskname = "plugin_" . $module . "_task_selection_type_" . $method; if (is_callable($taskname)) { $input['selection_type'] = call_user_func($taskname, $postvars['itemtype']); } $mytaskjob->add($input); // Upsate task to activate it $mytask->getFromDB($task_id); $mytask->fields['is_active'] = "1"; $mytask->update($mytask->fields); // force running this job (?) } elseif (isset($postvars['forceend'])) { $taskjobstate = new PluginFusioninventoryTaskjobstate(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $mytaskjobstate->getFromDB($postvars['taskjobstates_id']); $jobstate = $mytaskjobstate->fields; $a_taskjobstates = $mytaskjobstate->find("`uniqid`='" . $mytaskjobstate->fields['uniqid'] . "'"); foreach ($a_taskjobstates as $data) { if ($data['state'] != PluginFusioninventoryTaskjobstate::FINISHED) { $mytaskjobstate->changeStatusFinish($data['id'], 0, '', 1, "Action cancelled by user", 0, 0); } } $pfTaskjob->getFromDB($jobstate['plugin_fusioninventory_taskjobs_id']); $pfTaskjob->reinitializeTaskjobs($pfTaskjob->fields['plugin_fusioninventory_tasks_id']); } elseif (isset($postvars['delete_taskjobs'])) { foreach ($postvars['taskjobs'] as $taskjob_id) { $input = array('id' => $taskjob_id); $this->delete($input, true); } } } } } } } } }
/** * assign a previous group to the ticket * @param int $tickets_id the ticket to change * @param int $groups_id the group to assign * @return nothing */ static function climb_group($tickets_id, $groups_id, $full_history = false) { //don't add group if already exist for this ticket $group_ticket = new Group_Ticket(); $condition = "tickets_id = {$tickets_id} AND groups_id = {$groups_id} AND type = 2"; if (!$group_ticket->find($condition)) { // add group to ticket $ticket = new Ticket(); $ticket->update(array('id' => $tickets_id, '_itil_assign' => array('_type' => "group", 'groups_id' => $groups_id))); } if (!$full_history) { Html::back(); } else { //reload parent window and close popup echo "<script type='text/javascript'>\n if (window.opener && !window.opener.closed) {\n window.opener.location.reload();\n }\n window.close();\n </script>"; } }
function pre_updateInDB() { $PluginResourcesResource_Item = new PluginResourcesResource_Item(); $PluginResourcesChecklist = new PluginResourcesChecklist(); //if leaving field is updated && isset($this->input["withtemplate"]) && $this->input["withtemplate"]!=1 $this->input["checkbadge"] = 0; if (isset($this->input["is_leaving"]) && $this->input["is_leaving"] == 1 && in_array("is_leaving", $this->updates)) { if (!isset($this->input["date_end"]) || $this->input["date_end"] == 'NULL' || (!isset($this->fields["date_end"]) || $this->fields["date_end"] == 'NULL')) { Session::addMessageAfterRedirect(__('End date was not completed. Please try again.', 'resources'), false, ERROR); Html::back(); } else { $this->fields["users_id_recipient_leaving"] = Session::getLoginUserID(); $this->updates[] = "users_id_recipient_leaving"; $resources_checklist = PluginResourcesChecklist::checkIfChecklistExist($this->fields["id"]); if (!$resources_checklist) { $PluginResourcesChecklistconfig = new PluginResourcesChecklistconfig(); $PluginResourcesChecklistconfig->addChecklistsFromRules($this, PluginResourcesChecklist::RESOURCES_CHECKLIST_OUT); } } } //if location field is updated if (isset($this->fields["locations_id"]) && isset($this->input["_old_locations_id"]) && !isset($this->input["_UpdateFromUser_"]) && $this->fields["locations_id"] != $this->input["_old_locations_id"]) { $PluginResourcesResource_Item->updateLocation($this->fields, "PluginResourcesResource"); } $this->input["addchecklist"] = 0; if (isset($this->fields["plugin_resources_contracttypes_id"]) && isset($this->input["_old_plugin_resources_contracttypes_id"]) && $this->fields["plugin_resources_contracttypes_id"] != $this->input["_old_plugin_resources_contracttypes_id"]) { $this->input["addchecklist"] = 1; } }
public function saveToTargets($datas) { $valid = true; // Validate form fields foreach ($_POST as $key => $value) { if (substr($key, 0, 18) == 'formcreator_field_') { $question_id = (int) substr($key, 18); $question = new PluginFormcreatorQuestion(); $question->getFromDB($question_id); $className = $question->fields['fieldtype'] . 'Field'; $filePath = dirname(__FILE__) . '/fields/' . $question->fields['fieldtype'] . '-field.class.php'; if ($question->fields['fieldtype'] == 'float') { $value = str_replace(',', '.', $datas['formcreator_field_' . $question_id]); $datas['formcreator_field_' . $question_id] = $value; } if (is_file($filePath)) { include_once $filePath; if (class_exists($className)) { if (!$className::isValid($question->fields, $value, $datas)) { $valid = false; } } } else { $valid = false; } } } // If not valid back to form if (!$valid) { $_SESSION['formcreator']['datas'] = $datas; Html::back(); // Otherwize generate targets } else { $_SESSION['formcreator_documents'] = array(); // Save files as Documents foreach ($_FILES as $question_name => $file) { if (isset($file['tmp_name']) && is_file($file['tmp_name'])) { $doc = new Document(); $question_id = trim(strrchr($question_name, '_'), '_'); $question = new PluginFormcreatorQuestion(); $question->getFromDB($question_id); $file_datas = array(); $file_datas["name"] = $this->fields['name'] . ' - ' . $question->fields['name']; $file_datas["entities_id"] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $this->fields['entities_id']; $file_datas["is_recursive"] = $this->fields['is_recursive']; Document::uploadDocument($file_datas, $file); if ($docID = $doc->add($file_datas)) { $_SESSION['formcreator_documents'][] = $docID; $table = getTableForItemType('Document'); $query = "UPDATE {$table} SET filename = '" . addslashes($file['name']) . "' WHERE id = " . $docID; $GLOBALS['DB']->query($query); } } } // Get all targets $target_class = new PluginFormcreatorTarget(); $founded_targets = $target_class->find('plugin_formcreator_forms_id = ' . $this->getID()); foreach ($founded_targets as $target) { $obj = new $target['itemtype'](); $obj->getFromDB($target['items_id']); $obj->save($this, $datas); } Session::addMessageAfterRedirect(__('The form have been successfully saved!', 'formcreator'), true, INFO); unset($_SESSION['formcreator_documents']); } }