/** * Is the current user have right to create the current change ? * * @return boolean **/ function canCreateItem() { if (!Session::haveAccessToEntity($this->getEntityID())) { return false; } return Session::haveRight(self::$rightname, CREATE); }
function canCreateItem() { if ($this->isPrivate() && $this->fields['users_id'] != Session::getLoginUserID()) { return false; } if (!$this->isPrivate() && !Session::haveAccessToEntity($this->getEntityID())) { return false; } return self::checkRightOnModel($this->fields['id']); }
static function methodInject($params, $protocol) { if (isset($params['help'])) { return array('uri' => 'string,mandatory', 'base64' => 'string,optional', 'additional' => 'array,optional', 'models_id' => 'integer, mandatory', 'entities_id' => 'integer,mandatory', 'mandatory' => 'array,optional', 'uri' => 'uri,mandatory', 'help' => 'bool,optional'); } $model = new PluginDatainjectionModel(); //----------------------------------------------------------------- //-------------------------- Check parameters --------------------- //----------------------------------------------------------------- if (!isset($_SESSION['glpiID'])) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); } if (!isset($params['uri']) && !isset($params['base64'])) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'uri or base64'); } if (!isset($params['models_id'])) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, 'models_id'); } if (!$model->getFromDB($params['models_id'])) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTFOUND, __('Model unknown', 'datainjection')); } if (!$model->can($params['models_id'], 'r')) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, __('You cannot access this model', 'datainjection')); } if ($model->fields['step'] < PluginDatainjectionModel::READY_TO_USE_STEP) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, __('You cannot access this model', 'datainjection')); } //Check entity if (!isset($params['entities_id'])) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, 'entities_id'); } $entities_id = $params['entities_id']; if ($entities_id > 0) { $entity = new Entity(); if (!$entity->getFromDB($entities_id)) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTFOUND, __('Entity unknown', 'datainjection')); } if (!Session::haveAccessToEntity($entities_id)) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, __('You cannot access this entity', 'datainjection')); } } //Mandatory fields $additional_infos = array(); if (isset($params['additional']) && is_array($params['additional'])) { $additional_infos = $params['additional']; } //Upload CSV file $document_name = basename($params['uri']); $filename = tempnam(PLUGIN_DATAINJECTION_UPLOAD_DIR, 'PWS'); $response = PluginWebservicesMethodCommon::uploadDocument($params, $protocol, $filename, $document_name); if (PluginWebservicesMethodCommon::isError($protocol, $response)) { return $response; } //Uploade successful : now perform import ! $options = array('file_encoding' => PluginDatainjectionBackend::ENCODING_AUTO, 'webservice' => true, 'original_filename' => $params['uri'], 'unique_filename' => $filename, 'mode' => PluginDatainjectionModel::PROCESS, 'delete_file' => false, 'protocol' => $protocol); //The Webservice protocol used $results = array(); $response = $model->processUploadedFile($options); if (!PluginWebservicesMethodCommon::isError($protocol, $response)) { $engine = new PluginDatainjectionEngine($model, $additional_infos, $params['entities_id']); //Remove first line if header is present $first = true; foreach ($model->injectionData->getDatas() as $id => $data) { if ($first && $model->getSpecificModel()->isHeaderPresent()) { $first = false; } else { $results[] = $engine->injectLine($data[0], $id); } } $model->cleanData(); return $results; } return $response; }
function pre_deleteItem() { global $DB; $entities = Profile_User::getUserEntities($this->fields["id"]); $view_all = Session::isViewAllEntities(); // Have right on all entities ? $all = true; if (!$view_all) { foreach ($entities as $ent) { if (!Session::haveAccessToEntity($ent)) { $all = false; } } } if ($all) { // Mark as deleted return true; } // only delete profile foreach ($entities as $ent) { if (Session::haveAccessToEntity($ent)) { $all = false; $query = "DELETE\n FROM `glpi_profiles_users`\n WHERE `users_id` = '" . $this->fields["id"] . "'\n AND `entities_id` = '{$ent}'"; $DB->query($query); } return false; } }
function showForm($ID, $options = array()) { global $DB, $CFG_GLPI; $default_values = self::getDefaultValues(); // Get default values from posted values on reload form // On get because of tabs // we use REQUEST because method differ with layout (lefttab : GET, vsplit: POST) if (!isset($options['template_preview'])) { if (isset($_REQUEST)) { $values = Html::cleanPostForTextArea($_REQUEST); } } // Restore saved value or override with page parameter $saved = $this->restoreInput(); foreach ($default_values as $name => $value) { if (!isset($values[$name])) { if (isset($saved[$name])) { $values[$name] = $saved[$name]; } else { $values[$name] = $value; } } } if (isset($values['content'])) { // Clean new lines to be fix encoding $order = array('\\r', '\\n', "\\"); $replace = array("", "", ""); $values['content'] = str_replace($order, $replace, $values['content']); } if (isset($values['name'])) { $values['name'] = str_replace("\\", "", $values['name']); } if (!$ID) { // Override defaut values from projecttask if needed if (isset($options['_projecttasks_id'])) { $pt = new ProjectTask(); if ($pt->getFromDB($options['_projecttasks_id'])) { $values['name'] = $pt->getField('name'); $values['content'] = $pt->getField('name'); } } } // Check category / type validity if ($values['itilcategories_id']) { $cat = new ITILCategory(); if ($cat->getFromDB($values['itilcategories_id'])) { switch ($values['type']) { case self::INCIDENT_TYPE: if (!$cat->getField('is_incident')) { $values['itilcategories_id'] = 0; } break; case self::DEMAND_TYPE: if (!$cat->getField('is_request')) { $values['itilcategories_id'] = 0; } break; default: break; } } } // Default check if ($ID > 0) { $this->check($ID, READ); } else { // Create item $this->check(-1, CREATE, $values); } if (!$ID) { $this->userentities = array(); if ($values["_users_id_requester"]) { //Get all the user's entities $all_entities = Profile_User::getUserEntities($values["_users_id_requester"], true, true); //For each user's entity, check if the technician which creates the ticket have access to it foreach ($all_entities as $tmp => $ID_entity) { if (Session::haveAccessToEntity($ID_entity)) { $this->userentities[] = $ID_entity; } } } $this->countentitiesforuser = count($this->userentities); if ($this->countentitiesforuser > 0 && !in_array($this->fields["entities_id"], $this->userentities)) { // If entity is not in the list of user's entities, // then use as default value the first value of the user's entites list $this->fields["entities_id"] = $this->userentities[0]; // Pass to values $values['entities_id'] = $this->userentities[0]; } } if ($values['type'] <= 0) { $values['type'] = Entity::getUsedConfig('tickettype', $values['entities_id'], '', Ticket::INCIDENT_TYPE); } if (!isset($options['template_preview'])) { $options['template_preview'] = 0; } // Load ticket template if available : if ($ID) { $tt = $this->getTicketTemplateToUse($options['template_preview'], $this->fields['type'], $this->fields['itilcategories_id'], $this->fields['entities_id']); } else { $tt = $this->getTicketTemplateToUse($options['template_preview'], $values['type'], $values['itilcategories_id'], $values['entities_id']); } // Predefined fields from template : reset them if (isset($values['_predefined_fields'])) { $values['_predefined_fields'] = Toolbox::decodeArrayFromInput($values['_predefined_fields']); } else { $values['_predefined_fields'] = array(); } // Store predefined fields to be able not to take into account on change template // Only manage predefined values on ticket creation $predefined_fields = array(); if (!$ID) { if (isset($tt->predefined) && count($tt->predefined)) { foreach ($tt->predefined as $predeffield => $predefvalue) { if (isset($default_values[$predeffield])) { // Is always default value : not set // Set if already predefined field // Set if ticket template change if (count($values['_predefined_fields']) == 0 && $values[$predeffield] == $default_values[$predeffield] || isset($values['_predefined_fields'][$predeffield]) && $values[$predeffield] == $values['_predefined_fields'][$predeffield] || isset($values['_tickettemplates_id']) && $values['_tickettemplates_id'] != $tt->getID() || $predeffield == 'requesttypes_id' && empty($saved)) { // Load template data $values[$predeffield] = $predefvalue; $this->fields[$predeffield] = $predefvalue; $predefined_fields[$predeffield] = $predefvalue; } } } // All predefined override : add option to say predifined exists if (count($predefined_fields) == 0) { $predefined_fields['_all_predefined_override'] = 1; } } else { // No template load : reset predefined values if (count($values['_predefined_fields'])) { foreach ($values['_predefined_fields'] as $predeffield => $predefvalue) { if ($values[$predeffield] == $predefvalue) { $values[$predeffield] = $default_values[$predeffield]; } } } } } // Put ticket template on $values for actors $values['_tickettemplate'] = $tt; $canupdate = Session::haveRight(self::$rightname, UPDATE); $canpriority = Session::haveRight(self::$rightname, self::CHANGEPRIORITY); $canstatus = $canupdate; if ($ID && in_array($this->fields['status'], $this->getClosedStatusArray())) { $canupdate = false; // No update for actors $values['_noupdate'] = true; } $showuserlink = 0; if (Session::haveRight('user', READ)) { $showuserlink = 1; } if ($options['template_preview']) { // Add all values to fields of tickets for template preview foreach ($values as $key => $val) { if (!isset($this->fields[$key])) { $this->fields[$key] = $val; } } } // In percent $colsize1 = '13'; $colsize2 = '29'; $colsize3 = '13'; $colsize4 = '45'; $canupdate_descr = $canupdate || $this->fields['status'] == self::INCOMING && $this->isUser(CommonITILActor::REQUESTER, Session::getLoginUserID()) && $this->numberOfFollowups() == 0 && $this->numberOfTasks() == 0; if (!$options['template_preview']) { echo "<form method='post' name='form_ticket' enctype='multipart/form-data' action='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php'>"; if (isset($options['_projecttasks_id'])) { echo "<input type='hidden' name='_projecttasks_id' value='" . $options['_projecttasks_id'] . "'>"; } } echo "<div class='spaced' id='tabsbody'>"; echo "<table class='tab_cadre_fixe' id='mainformtable'>"; // Optional line $ismultientities = Session::isMultiEntitiesMode(); echo "<tr class='headerRow responsive_hidden'>"; echo "<th colspan='4'>"; if ($ID) { $text = sprintf(__('%1$s - %2$s'), $this->getTypeName(1), sprintf(__('%1$s: %2$s'), __('ID'), $ID)); if ($ismultientities) { $text = sprintf(__('%1$s (%2$s)'), $text, Dropdown::getDropdownName('glpi_entities', $this->fields['entities_id'])); } echo $text; } else { if ($ismultientities) { printf(__('The ticket will be added in the entity %s'), Dropdown::getDropdownName("glpi_entities", $this->fields['entities_id'])); } else { _e('New ticket'); } } echo "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>"; echo $tt->getBeginHiddenFieldText('date'); if (!$ID) { printf(__('%1$s%2$s'), __('Opening date'), $tt->getMandatoryMark('date')); } else { _e('Opening date'); } echo $tt->getEndHiddenFieldText('date'); echo "</th>"; echo "<td width='{$colsize2}%'>"; echo $tt->getBeginHiddenFieldValue('date'); $date = $this->fields["date"]; if ($canupdate) { Html::showDateTimeField("date", array('value' => $date, 'timestep' => 1, 'maybeempty' => false)); } else { echo Html::convDateTime($date); } echo $tt->getEndHiddenFieldValue('date', $this); echo "</td><td colspan='2'></td></tr>"; // SLTs echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('time_to_own'); if (!$ID) { printf(__('%1$s%2$s'), __('Time to own'), $tt->getMandatoryMark('time_to_own')); } else { _e('Time to own'); } echo $tt->getEndHiddenFieldText('time_to_own'); echo "</th>"; echo "<td width='{$colsize2}%' class='nopadding'>"; $slt = new SLT(); $slt->showSltForTicket($this, SLT::TTO, $tt, $canupdate); echo "</td>"; echo "<th width='{$colsize3}%'>" . $tt->getBeginHiddenFieldText('due_date'); if (!$ID) { printf(__('%1$s%2$s'), __('Time to resolve'), $tt->getMandatoryMark('due_date')); } else { _e('Time to resolve'); } echo $tt->getEndHiddenFieldText('due_date'); echo "</th>"; echo "<td width='{$colsize4}%' class='nopadding'>"; $slt->showSltForTicket($this, SLT::TTR, $tt, $canupdate); echo "</td>"; echo "</tr>"; if ($ID) { echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . __('By') . "</th>"; echo "<td width='{$colsize2}%'>"; if ($canupdate) { User::dropdown(array('name' => 'users_id_recipient', 'value' => $this->fields["users_id_recipient"], 'entity' => $this->fields["entities_id"], 'right' => 'all')); } else { echo getUserName($this->fields["users_id_recipient"], $showuserlink); } echo "</td>"; echo "<th width='{$colsize3}%'>" . __('Last update') . "</th>"; echo "<td width='{$colsize4}%'>"; if ($this->fields['users_id_lastupdater'] > 0) { //TRANS: %1$s is the update date, %2$s is the last updater name printf(__('%1$s by %2$s'), Html::convDateTime($this->fields["date_mod"]), getUserName($this->fields["users_id_lastupdater"], $showuserlink)); } echo "</td>"; echo "</tr>"; } if ($ID && (in_array($this->fields["status"], $this->getSolvedStatusArray()) || in_array($this->fields["status"], $this->getClosedStatusArray()))) { echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . __('Resolution date') . "</th>"; echo "<td width='{$colsize2}%'>"; Html::showDateTimeField("solvedate", array('value' => $this->fields["solvedate"], 'timestep' => 1, 'maybeempty' => false, 'canedit' => $canupdate)); echo "</td>"; if (in_array($this->fields["status"], $this->getClosedStatusArray())) { echo "<th width='{$colsize3}%'>" . __('Close date') . "</th>"; echo "<td width='{$colsize4}%'>"; Html::showDateTimeField("closedate", array('value' => $this->fields["closedate"], 'timestep' => 1, 'maybeempty' => false, 'canedit' => $canupdate)); echo "</td>"; } else { echo "<td colspan='2'> </td>"; } echo "</tr>"; } if ($ID) { echo "</table>"; echo "<table class='tab_cadre_fixe' id='mainformtable2'>"; } echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . sprintf(__('%1$s%2$s'), __('Type'), $tt->getMandatoryMark('type')) . "</th>"; echo "<td width='{$colsize2}%'>"; // Permit to set type when creating ticket without update right if ($canupdate || !$ID) { $opt = array('value' => $this->fields["type"]); /// Auto submit to load template if (!$ID) { $opt['on_change'] = 'this.form.submit()'; } $rand = self::dropdownType('type', $opt); if ($ID) { $params = array('type' => '__VALUE__', 'entity_restrict' => $this->fields['entities_id'], 'value' => $this->fields['itilcategories_id'], 'currenttype' => $this->fields['type']); Ajax::updateItemOnSelectEvent("dropdown_type{$rand}", "show_category_by_type", $CFG_GLPI["root_doc"] . "/ajax/dropdownTicketCategories.php", $params); } } else { echo self::getTicketTypeName($this->fields["type"]); } echo "</td>"; echo "<th width='{$colsize3}%'>" . sprintf(__('%1$s%2$s'), __('Category'), $tt->getMandatoryMark('itilcategories_id')) . "</th>"; echo "<td width='{$colsize4}%'>"; // Permit to set category when creating ticket without update right if ($canupdate || !$ID || $canupdate_descr) { $opt = array('value' => $this->fields["itilcategories_id"], 'entity' => $this->fields["entities_id"]); if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") { $opt['condition'] = "`is_helpdeskvisible`='1' AND "; } else { $opt['condition'] = ''; } /// Auto submit to load template if (!$ID) { $opt['on_change'] = 'this.form.submit()'; } /// if category mandatory, no empty choice /// no empty choice is default value set on ticket creation, else yes if (($ID || $values['itilcategories_id']) && $tt->isMandatoryField("itilcategories_id") && $this->fields["itilcategories_id"] > 0) { $opt['display_emptychoice'] = false; } switch ($this->fields["type"]) { case self::INCIDENT_TYPE: $opt['condition'] .= "`is_incident`='1'"; break; case self::DEMAND_TYPE: $opt['condition'] .= "`is_request`='1'"; break; default: break; } echo "<span id='show_category_by_type'>"; ITILCategory::dropdown($opt); echo "</span>"; } else { echo Dropdown::getDropdownName("glpi_itilcategories", $this->fields["itilcategories_id"]); } echo "</td>"; echo "</tr>"; if (!$ID) { echo "</table>"; $this->showActorsPartForm($ID, $values); echo "<table class='tab_cadre_fixe' id='mainformtable3'>"; } echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('status'); printf(__('%1$s%2$s'), __('Status'), $tt->getMandatoryMark('status')); echo $tt->getEndHiddenFieldText('status') . "</th>"; echo "<td width='{$colsize2}%'>"; echo $tt->getBeginHiddenFieldValue('status'); if ($canstatus) { self::dropdownStatus(array('value' => $this->fields["status"], 'showtype' => 'allowed')); TicketValidation::alertValidation($this, 'status'); } else { echo self::getStatus($this->fields["status"]); if (in_array($this->fields["status"], $this->getClosedStatusArray()) && $this->isAllowedStatus($this->fields['status'], Ticket::INCOMING)) { echo " <a class='vsubmit' href='" . $this->getLinkURL() . "&forcetab=TicketFollowup\$1&_openfollowup=1'>" . __('Reopen') . "</a>"; } } echo $tt->getEndHiddenFieldValue('status', $this); echo "</td>"; echo "<th width='{$colsize3}%'>" . $tt->getBeginHiddenFieldText('requesttypes_id'); printf(__('%1$s%2$s'), __('Request source'), $tt->getMandatoryMark('requesttypes_id')); echo $tt->getEndHiddenFieldText('requesttypes_id') . "</th>"; echo "<td width='{$colsize4}%'>"; echo $tt->getBeginHiddenFieldValue('requesttypes_id'); if ($canupdate) { RequestType::dropdown(array('value' => $this->fields["requesttypes_id"], 'condition' => 'is_active = 1 AND is_ticketheader = 1')); } else { echo Dropdown::getDropdownName('glpi_requesttypes', $this->fields["requesttypes_id"]); echo Html::hidden('requesttypes_id', array('value' => $this->fields["requesttypes_id"])); } echo $tt->getEndHiddenFieldValue('requesttypes_id', $this); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . $tt->getBeginHiddenFieldText('urgency'); printf(__('%1$s%2$s'), __('Urgency'), $tt->getMandatoryMark('urgency')); echo $tt->getEndHiddenFieldText('urgency') . "</th>"; echo "<td>"; if ($canupdate && $canpriority || !$ID || $canupdate_descr) { // Only change during creation OR when allowed to change priority OR when user is the creator echo $tt->getBeginHiddenFieldValue('urgency'); $idurgency = self::dropdownUrgency(array('value' => $this->fields["urgency"])); echo $tt->getEndHiddenFieldValue('urgency', $this); } else { $idurgency = "value_urgency" . mt_rand(); echo "<input id='{$idurgency}' type='hidden' name='urgency' value='" . $this->fields["urgency"] . "'>"; echo $tt->getBeginHiddenFieldValue('urgency'); echo parent::getUrgencyName($this->fields["urgency"]); echo $tt->getEndHiddenFieldValue('urgency', $this); } echo "</td>"; // Display validation state echo "<th>"; if (!$ID) { echo $tt->getBeginHiddenFieldText('_add_validation'); printf(__('%1$s%2$s'), __('Approval request'), $tt->getMandatoryMark('_add_validation')); echo $tt->getEndHiddenFieldText('_add_validation'); } else { echo $tt->getBeginHiddenFieldText('global_validation'); _e('Approval'); echo $tt->getEndHiddenFieldText('global_validation'); } echo "</th>"; echo "<td>"; if (!$ID) { echo $tt->getBeginHiddenFieldValue('_add_validation'); $validation_right = ''; if ($values['type'] == self::INCIDENT_TYPE && Session::haveRight('ticketvalidation', TicketValidation::CREATEINCIDENT)) { $validation_right = 'validate_incident'; } if ($values['type'] == self::DEMAND_TYPE && Session::haveRight('ticketvalidation', TicketValidation::CREATEREQUEST)) { $validation_right = 'validate_request'; } if (!empty($validation_right)) { echo "<input type='hidden' name='_add_validation' value='" . $values['_add_validation'] . "'>"; $params = array('name' => "users_id_validate", 'entity' => $this->fields['entities_id'], 'right' => $validation_right, 'users_id_validate' => $values['users_id_validate']); TicketValidation::dropdownValidator($params); } echo $tt->getEndHiddenFieldValue('_add_validation', $this); if ($tt->isPredefinedField('global_validation')) { echo "<input type='hidden' name='global_validation' value='" . $tt->predefined['global_validation'] . "'>"; } } else { echo $tt->getBeginHiddenFieldValue('global_validation'); if (Session::haveRightsOr('ticketvalidation', TicketValidation::getCreateRights()) && $canupdate) { TicketValidation::dropdownStatus('global_validation', array('global' => true, 'value' => $this->fields['global_validation'])); } else { echo TicketValidation::getStatus($this->fields['global_validation']); } echo $tt->getEndHiddenFieldValue('global_validation', $this); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . $tt->getBeginHiddenFieldText('impact'); printf(__('%1$s%2$s'), __('Impact'), $tt->getMandatoryMark('impact')); echo $tt->getEndHiddenFieldText('impact') . "</th>"; echo "<td>"; echo $tt->getBeginHiddenFieldValue('impact'); if ($canupdate) { $idimpact = self::dropdownImpact(array('value' => $this->fields["impact"])); } else { $idimpact = "value_impact" . mt_rand(); echo "<input id='{$idimpact}' type='hidden' name='impact' value='" . $this->fields["impact"] . "'>"; echo parent::getImpactName($this->fields["impact"]); } echo $tt->getEndHiddenFieldValue('impact', $this); echo "</td>"; echo "<th>" . $tt->getBeginHiddenFieldText('locations_id'); printf(__('%1$s%2$s'), __('Location'), $tt->getMandatoryMark('locations_id')); echo $tt->getEndHiddenFieldText('locations_id') . "</th>"; echo "<td>"; echo $tt->getBeginHiddenFieldValue('locations_id'); if ($canupdate || !$ID) { Location::dropdown(array('value' => $this->fields['locations_id'], 'entity' => $this->fields['entities_id'])); } else { echo Dropdown::getDropdownName('glpi_locations', $this->fields["locations_id"]); } echo $tt->getEndHiddenFieldValue('locations_id', $this); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . $tt->getBeginHiddenFieldText('priority'); printf(__('%1$s%2$s'), __('Priority'), $tt->getMandatoryMark('priority')); echo $tt->getEndHiddenFieldText('priority') . "</th>"; echo "<td>"; $idajax = 'change_priority_' . mt_rand(); if ($canpriority && !$tt->isHiddenField('priority')) { $idpriority = parent::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true)); $idpriority = 'dropdown_priority' . $idpriority; echo " <span id='{$idajax}' style='display:none'></span>"; } else { $idpriority = 0; echo $tt->getBeginHiddenFieldValue('priority'); echo "<span id='{$idajax}'>" . parent::getPriorityName($this->fields["priority"]) . "</span>"; echo $tt->getEndHiddenFieldValue('priority', $this); } if ($canupdate || $canupdate_descr) { $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => $idpriority); Ajax::updateItemOnSelectEvent(array('dropdown_urgency' . $idurgency, 'dropdown_impact' . $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params); } echo "</td>"; echo "<th rowspan='2'>" . $tt->getBeginHiddenFieldText('items_id'); printf(__('%1$s%2$s'), _n('Associated element', 'Associated elements', Session::getPluralNumber()), $tt->getMandatoryMark('items_id')); if ($ID && $canupdate) { echo " <a href='" . $this->getFormURL() . "?id=" . $ID . "&forcetab=Item_Ticket\$1'><img title='" . __s('Update') . "' alt='" . __s('Update') . "'\n class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/showselect.png'></a>"; } echo $tt->getEndHiddenFieldText('items_id'); echo "</th>"; if (!$ID) { echo "<td rowspan='2'>"; echo $tt->getBeginHiddenFieldValue('items_id'); $values['_canupdate'] = Session::haveRight('ticket', CREATE); if ($values['_canupdate']) { Item_Ticket::itemAddForm($this, $values); } echo $tt->getEndHiddenFieldValue('items_id', $this); echo "</td>"; } else { echo "<td>"; echo $tt->getBeginHiddenFieldValue('items_id'); $values['_canupdate'] = $canupdate || $canupdate_descr; Item_Ticket::itemAddForm($this, $values); echo $tt->getEndHiddenFieldValue('items_id', $this); echo "</td>"; } echo "</tr>"; echo "<tr class='tab_bg_1'>"; // Need comment right to add a followup with the actiontime if (!$ID && Session::haveRight('followup', TicketFollowup::ADDALLTICKET)) { echo "<th>" . $tt->getBeginHiddenFieldText('actiontime'); printf(__('%1$s%2$s'), __('Total duration'), $tt->getMandatoryMark('actiontime')); echo $tt->getEndHiddenFieldText('actiontime') . "</th>"; echo "<td>"; echo $tt->getBeginHiddenFieldValue('actiontime'); Dropdown::showTimeStamp('actiontime', array('value' => $values['actiontime'], 'addfirstminutes' => true)); echo $tt->getEndHiddenFieldValue('actiontime', $this); echo "</td>"; } echo "</tr>"; echo "</table>"; if ($ID) { $this->showActorsPartForm($ID, $values); } $view_linked_tickets = $ID || $canupdate; echo "<table class='tab_cadre_fixe' id='mainformtable4'>"; echo "<tr class='tab_bg_1'>"; echo "<th style='width:{$colsize1}%'>" . $tt->getBeginHiddenFieldText('name'); printf(__('%1$s%2$s'), __('Title'), $tt->getMandatoryMark('name')); echo $tt->getEndHiddenFieldText('name') . "</th>"; echo "<td colspan='3'>"; if (!$ID || $canupdate_descr) { echo $tt->getBeginHiddenFieldValue('name'); echo "<input type='text' style='width:98%' maxlength=250 name='name' " . " value=\"" . Html::cleanInputText($this->fields["name"]) . "\">"; echo $tt->getEndHiddenFieldValue('name', $this); } else { if (empty($this->fields["name"])) { _e('Without title'); } else { echo $this->fields["name"]; } } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th style='width:{$colsize1}%'>" . $tt->getBeginHiddenFieldText('content'); printf(__('%1$s%2$s'), __('Description'), $tt->getMandatoryMark('content')); if (!$ID || $canupdate_descr) { $content = Toolbox::unclean_cross_side_scripting_deep(Html::entity_decode_deep($this->fields['content'])); Html::showTooltip(nl2br(Html::Clean($content))); } echo $tt->getEndHiddenFieldText('content') . "</th>"; echo "<td colspan='3'>"; if (!$ID || $canupdate_descr) { // Admin =oui on autorise la modification de la description echo $tt->getBeginHiddenFieldValue('content'); $rand = mt_rand(); $rand_text = mt_rand(); $rows = 6; $content_id = "content{$rand}"; if ($CFG_GLPI["use_rich_text"]) { $this->fields["content"] = $this->setRichTextContent($content_id, $this->fields["content"], $rand); $rows = 10; } else { $this->fields["content"] = $this->setSimpleTextContent($this->fields["content"]); } echo "<div id='content{$rand_text}'>"; echo "<textarea id='{$content_id}' name='content' style='width:100%' rows='{$rows}'>" . $this->fields["content"] . "</textarea></div>"; echo Html::scriptBlock("\$(document).ready(function() { \$('#{$content_id}').autogrow(); });"); echo $tt->getEndHiddenFieldValue('content', $this); } else { $content = Toolbox::unclean_cross_side_scripting_deep(Html::entity_decode_deep($this->fields['content'])); echo nl2br(Html::Clean($content)); } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; if ($view_linked_tickets) { echo "<th style='width:{$colsize1}%'>" . _n('Linked ticket', 'Linked tickets', Session::getPluralNumber()); $rand_linked_ticket = mt_rand(); if ($canupdate) { echo " "; echo "<img onClick=\"" . Html::jsShow("linkedticket{$rand_linked_ticket}") . "\"\n title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\"\n class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>"; } echo '</th>'; echo "<td colspan='3'>"; if ($canupdate) { echo "<div style='display:none' id='linkedticket{$rand_linked_ticket}'>"; echo "<table class='tab_format' width='100%'><tr><td width='30%'>"; Ticket_Ticket::dropdownLinks('_link[link]', isset($values["_link"]) ? $values["_link"]['link'] : ''); echo "<input type='hidden' name='_link[tickets_id_1]' value='{$ID}'>\n"; echo "</td><td width='70%'>"; $linkparam = array('name' => '_link[tickets_id_2]', 'displaywith' => array('id')); if (isset($values["_link"])) { $linkparam['value'] = $values["_link"]['tickets_id_2']; } Ticket::dropdown($linkparam); echo "</td></tr></table>"; echo "</div>"; if (isset($values["_link"]) && !empty($values["_link"]['tickets_id_2'])) { echo "<script language='javascript'>"; echo Html::jsShow("linkedticket{$rand_linked_ticket}"); echo "</script>"; } } Ticket_Ticket::displayLinkedTicketsTo($ID); echo "</td>"; } echo "</tr>"; // View files added echo "<tr class='tab_bg_1'>"; // Permit to add doc when creating a ticket echo "<th style='width:{$colsize1}%'>"; echo $tt->getBeginHiddenFieldText('_documents_id'); $doctitle = sprintf(__('File (%s)'), Document::getMaxUploadSize()); printf(__('%1$s%2$s'), $doctitle, $tt->getMandatoryMark('_documents_id')); // Do not show if hidden. if (!$tt->isHiddenField('_documents_id')) { DocumentType::showAvailableTypesLink(); } echo $tt->getEndHiddenFieldText('_documents_id'); echo "</th>"; echo "<td colspan='3'>"; // Do not set values echo $tt->getEndHiddenFieldValue('_documents_id'); if ($tt->isPredefinedField('_documents_id')) { if (isset($values['_documents_id']) && is_array($values['_documents_id']) && count($values['_documents_id'])) { echo "<span class='b'>" . __('Default documents:') . '</span>'; echo "<br>"; $doc = new Document(); foreach ($values['_documents_id'] as $key => $val) { if ($doc->getFromDB($val)) { echo "<input type='hidden' name='_documents_id[{$key}]' value='{$val}'>"; echo "- " . $doc->getNameID() . "<br>"; } } } } echo "<div id='fileupload_info'></div>"; echo "</td>"; echo "</tr>"; if ((!$ID || $canupdate || $canupdate_descr || Session::haveRightsOr(self::$rightname, array(self::ASSIGN, self::STEAL, DELETE, PURGE))) && !$options['template_preview']) { echo "<tr class='tab_bg_1'>"; if ($ID) { if (Session::haveRightsOr(self::$rightname, array(UPDATE, DELETE, PURGE)) || $this->canDeleteItem() || $this->canUpdateItem()) { echo "<td class='tab_bg_2 center' colspan='4'>"; if ($this->fields["is_deleted"] == 1) { if (self::canPurge()) { echo "<input type='submit' class='submit' name='restore' value='" . _sx('button', 'Restore') . "'> "; } } else { if (self::canUpdate()) { echo "<input type='submit' class='submit' name='update' value='" . _sx('button', 'Save') . "'> "; } } if ($this->fields["is_deleted"] == 1) { if (self::canPurge()) { echo "<input type='submit' class='submit' name='purge' value='" . _sx('button', 'Delete permanently') . "' " . Html::addConfirmationOnAction(__('Confirm the final deletion?')) . ">"; } } else { if ($this->canDeleteItem()) { echo "<input type='submit' class='submit' name='delete' value='" . _sx('button', 'Put in dustbin') . "'>"; } } echo "<input type='hidden' name='_read_date_mod' value='" . $this->getField('date_mod') . "'>"; echo "</td>"; } } else { echo "<td class='tab_bg_2 center' colspan='4'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; if ($tt->isField('id') && $tt->fields['id'] > 0) { echo "<input type='hidden' name='_tickettemplates_id' value='" . $tt->fields['id'] . "'>"; echo "<input type='hidden' name='_predefined_fields'\n value=\"" . Toolbox::prepareArrayForInput($predefined_fields) . "\">"; } } } // File upload system $colspan = 3; if (!$CFG_GLPI['use_rich_text']) { $colspan = 4; } echo "<tr class='tab_bg_1'>"; echo "<td colspan='{$colspan}'>"; echo $tt->getBeginHiddenFieldValue('_documents_id'); echo Html::file(array('multiple' => true, 'showfilecontainer' => 'fileupload_info', 'values' => array('filename' => $values['_filename'], 'tag' => $values['_tag_filename']))); echo "</td>"; if ($CFG_GLPI['use_rich_text']) { echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='{$colspan}'>"; if (!isset($rand)) { $rand = mt_rand(); } if ($canupdate_descr) { echo Html::initImagePasteSystem($content_id, $rand); } echo "</td>"; } echo "</tr>"; echo "</table>"; echo "<input type='hidden' name='id' value='{$ID}'>"; echo "</div>"; if (!$options['template_preview']) { Html::closeForm(); } return true; }
function canCreateItem() { $user = new User(); return $user->can($this->fields['users_id'], READ) && Profile::currentUserHaveMoreRightThan(array($this->fields['profiles_id'] => $this->fields['profiles_id'])) && Session::haveAccessToEntity($this->fields['entities_id']); }
static function showNotificationOptions(Entity $entity) { $con_spotted = false; $ID = $entity->getField('id'); if (!$entity->can($ID, 'r')) { return false; } // Notification right applied $canedit = Session::haveRight('notification', 'w') && Session::haveAccessToEntity($ID); // Get data $entitynotification = new PluginAdditionalalertsOcsAlert(); if (!$entitynotification->getFromDBbyEntity($ID)) { $entitynotification->getEmpty(); } if ($canedit) { echo "<form method='post' name=form action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; } echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td>" . __('New imported computers from OCS-NG', 'additionalalerts') . "</td><td>"; $default_value = $entitynotification->fields['use_newocs_alert']; Alert::dropdownYesNo(array('name' => "use_newocs_alert", 'value' => $default_value, 'inherit_global' => 1)); echo "</td></tr>"; echo "<tr class='tab_bg_1'><td >" . __('OCS-NG Synchronization alerts', 'additionalalerts') . "</td><td>"; Alert::dropdownIntegerNever('delay_ocs', $entitynotification->fields["delay_ocs"], array('max' => 99, 'inherit_global' => 1)); echo " " . _n('Day', 'Days', 2) . "</td>"; echo "</tr>"; if ($canedit) { echo "<tr>"; echo "<td class='tab_bg_2 center' colspan='4'>"; echo "<input type='hidden' name='entities_id' value='{$ID}'>"; if ($entitynotification->fields["id"]) { echo "<input type='hidden' name='id' value=\"" . $entitynotification->fields["id"] . "\">"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit' >"; } else { echo "<input type='submit' name='add' value=\"" . _sx('button', 'Save') . "\" class='submit' >"; } echo "</td></tr>"; echo "</table>"; Html::closeForm(); } else { echo "</table>"; } }
/** * Display for reservation * * @param $ID ID a the reservation item (empty to show all) * @param $date date to display **/ static function displayReservationDay($ID, $date) { global $DB; if (!empty($ID)) { self::displayReservationsForAnItem($ID, $date); } else { $debut = $date . " 00:00:00"; $fin = $date . " 23:59:59"; $query = "SELECT DISTINCT `glpi_reservationitems`.`id`\n FROM `glpi_reservationitems`\n INNER JOIN `glpi_reservations`\n ON (`glpi_reservationitems`.`id` = `glpi_reservations`.`reservationitems_id`)\n WHERE `is_active` = '1'\n AND '" . $debut . "' < `end`\n AND '" . $fin . "' > `begin`\n ORDER BY `begin`"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $m = new ReservationItem(); while ($data = $DB->fetch_assoc($result)) { $m->getFromDB($data['id']); if (!($item = getItemForItemtype($m->fields["itemtype"]))) { continue; } if ($item->getFromDB($m->fields["items_id"]) && Session::haveAccessToEntity($item->fields["entities_id"])) { $typename = $item->getTypeName(); if ($m->fields["itemtype"] == 'Peripheral') { if (isset($item->fields["peripheraltypes_id"]) && $item->fields["peripheraltypes_id"] != 0) { $typename = Dropdown::getDropdownName("glpi_peripheraltypes", $item->fields["peripheraltypes_id"]); } } list($annee, $mois, $jour) = explode("-", $date); echo "<tr class='tab_bg_1'><td>"; echo "<a href='reservation.php?reservationitems_id=" . $data['id'] . "&mois_courant={$mois}&annee_courante={$annee}'>" . sprintf(__('%1$s - %2$s'), $typename, $item->getName()) . "</a></td></tr>\n"; echo "<tr><td>"; self::displayReservationsForAnItem($data['id'], $date); echo "</td></tr>\n"; } } } } }
/** Show groups of a user * * @param $user User object **/ static function showForUser(User $user) { global $CFG_GLPI; $ID = $user->fields['id']; if (!Group::canView() || !$user->can($ID, READ)) { return false; } $canedit = $user->can($ID, UPDATE); $rand = mt_rand(); $groups = self::getUserGroups($ID); $used = array(); if (!empty($groups)) { foreach ($groups as $data) { $used[$data["id"]] = $data["id"]; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='groupuser_form{$rand}' id='groupuser_form{$rand}' method='post'"; echo " action='" . Toolbox::getItemTypeFormURL('User') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='6'>" . __('Associate to a group') . "</th></tr>"; echo "<tr class='tab_bg_2'><td class='center'>"; echo "<input type='hidden' name='users_id' value='{$ID}'>"; // All entities "edited user" have access $strict_entities = Profile_User::getUserEntities($ID, true); // Keep only entities "connected user" have access foreach ($strict_entities as $key => $val) { if (!Session::haveAccessToEntity($val)) { unset($strict_entities[$key]); } } $nb = countElementsInTableForEntity("glpi_groups", $strict_entities, '`is_usergroup`'); if ($nb > count($used)) { Group::dropdown(array('entity' => $strict_entities, 'used' => $used, 'condition' => '`is_usergroup`')); echo "</td><td>" . __('Manager') . "</td><td>"; Dropdown::showYesNo('is_manager'); echo "</td><td>" . __('Delegatee') . "</td><td>"; Dropdown::showYesNo('is_userdelegate'); echo "</td><td class='tab_bg_2 center'>"; echo "<input type='submit' name='addgroup' value=\"" . _sx('button', 'Add') . "\"\n class='submit'>"; } else { _e('None'); } echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && count($used)) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); echo "<input type='hidden' name='users_id' value='" . $user->fields['id'] . "'>"; $massiveactionparams = array('num_displayed' => count($used), 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov table-striped table-hover'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit && count($used)) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end .= "</th>"; } $header_end .= "<th>" . Group::getTypeName(1) . "</th>"; $header_end .= "<th>" . __('Dynamic') . "</th>"; $header_end .= "<th>" . __('Manager') . "</th>"; $header_end .= "<th>" . __('Delegatee') . "</th></tr>"; echo $header_begin . $header_top . $header_end; $group = new Group(); if (!empty($groups)) { Session::initNavigateListItems('Group', sprintf(__('%1$s = %2$s'), User::getTypeName(1), $user->getName())); foreach ($groups as $data) { if (!$group->getFromDB($data["id"])) { continue; } Session::addToNavigateListItems('Group', $data["id"]); echo "<tr class='tab_bg_1'>"; if ($canedit && count($used)) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]); echo "</td>"; } $link = $data["completename"]; if ($_SESSION["glpiis_ids_visible"]) { $link = sprintf(__('%1$s (%2$s)'), $link, $data["id"]); } $href = "<a href='" . $CFG_GLPI["root_doc"] . "/front/group.form.php?id=" . $data["id"] . "'>" . $link . "</a>"; if ($data["is_dynamic"]) { $href = sprintf(__('%1$s (%2$s)'), $href, "<span class='b'>" . __('D') . "</span>"); } echo "<td>" . $group->getLink() . "</td>"; echo "<td class='center'>"; if ($data['is_dynamic']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Dynamic') . "\">"; } echo "<td class='center'>"; if ($data['is_manager']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Manager') . "\">"; } echo "</td><td class='center'>"; if ($data['is_userdelegate']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Delegatee') . "\">"; } echo "</td></tr>"; } echo $header_begin . $header_bottom . $header_end; } else { echo "<tr class='tab_bg_1'>"; echo "<td colspan='5' class='center'>" . __('None') . "</td></tr>"; } echo "</table>"; if ($canedit && count($used)) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
static function showNotificationOptions(Entity $entity) { $con_spotted = false; $ID = $entity->getField('id'); if (!$entity->can($ID, 'r')) { return false; } // Notification right applied $canedit = Session::haveRight('notification', 'w') && Session::haveAccessToEntity($ID); // Get data $entitynotification = new PluginAdditionalalertsInfocomAlert(); if (!$entitynotification->getFromDBbyEntity($ID)) { $entitynotification->getEmpty(); } if ($canedit) { echo "<form method='post' name=form action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; } echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>" . __('Alarms options') . "</th></tr>"; echo "<tr class='tab_bg_1'><td>" . PluginAdditionalalertsInfocomAlert::getTypeName(2) . "</td><td>"; $default_value = $entitynotification->fields['use_infocom_alert']; Alert::dropdownYesNo(array('name' => "use_infocom_alert", 'value' => $default_value, 'inherit_global' => 1)); echo "</td></tr>"; if ($canedit) { echo "<tr>"; echo "<td class='tab_bg_2 center' colspan='4'>"; echo "<input type='hidden' name='entities_id' value='{$ID}'>"; if ($entitynotification->fields["id"]) { echo "<input type='hidden' name='id' value=\"" . $entitynotification->fields["id"] . "\">"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit' >"; } else { echo "<input type='submit' name='add' value=\"" . _sx('button', 'Save') . "\" class='submit' >"; } echo "</td></tr>"; echo "</table>"; Html::closeForm(); } else { echo "</table>"; } }
/** * show notes for item * * @return nothing **/ function showNotesForm() { if (!Session::haveRight("notes", "r")) { return false; } if (!$this->isField('notepad') || !isset($this->fields[static::getIndexName()])) { return false; } //getFromDB $canedit = Session::haveRight("notes", "w") && (!$this->isEntityAssign() || Session::haveAccessToEntity($this->getEntityID())); $target = $this->getFormURL(); if ($canedit) { echo "<form name='form' method='post' action='" . $target . "'>"; } echo "<div class='center'>"; echo "<table class='tab_cadre_fixe' >"; echo "<tr><th>" . __('Notes') . "</th></tr>"; echo "<tr><td class='tab_bg_1 center middle'>"; echo "<textarea class='textarea_notes' cols='100' rows='35' name='notepad'>" . $this->getField('notepad') . "</textarea></td></tr>"; echo "<tr><td class='tab_bg_2 center'>"; echo "<input type='hidden' name='id' value='" . $this->fields['id'] . "'>"; // for all objects without id as primary key if (static::getIndexName() != 'id') { echo "<input type='hidden' name='" . static::getIndexName() . "' value='" . $this->fields[static::getIndexName()] . "'>"; } if ($canedit) { echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit'>"; } echo "</td></tr>"; echo "</table></div>"; if ($canedit) { Html::closeForm(); } }
/** * Is the current user have right to delete the current problem ? * * @since version 0.84 * * @return boolean **/ function canDeleteItem() { if (!Session::haveAccessToEntity($this->getEntityID())) { return false; } return Session::haveRight('delete_problem', '1'); }
function canUpdateItem() { return $this->fields['users_id'] == Session::getLoginUserID() || !$this->fields['is_private'] && Session::haveRight('bookmark_public', 'w') && Session::haveAccessToEntity($this->fields['entities_id']); }
/** * Do automatic transfer if option is enable * * @param $line_links array : data from glpi_plugin_ocsinventoryng_ocslinks table * @param $line_ocs array : data from ocs tables * * @return nothing **/ static function transferComputer($line_links, $line_ocs) { global $DB, $PluginOcsinventoryngDBocs, $CFG_GLPI; // Get all rules for the current plugin_ocsinventoryng_ocsservers_id $rule = new RuleImportEntityCollection(); $data = array(); $data = $rule->processAllRules(array('ocsservers_id' => $line_links["plugin_ocsinventoryng_ocsservers_id"], '_source' => 'ocsinventoryng'), array(), array('ocsid' => $line_links["ocsid"])); // If entity is changing move items to the new entities_id if (isset($data['entities_id']) && $data['entities_id'] != $line_links['entities_id']) { if (!isCommandLine() && !Session::haveAccessToEntity($data['entities_id'])) { Html::displayRightError(); } $transfer = new Transfer(); $transfer->getFromDB($CFG_GLPI['transfers_id_auto']); $item_to_transfer = array("Computer" => array($line_links['computers_id'] => $line_links['computers_id'])); $transfer->moveItems($item_to_transfer, $data['entities_id'], $transfer->fields); } //If location is update by a rule self::updateLocation($line_links, $data); }
/** * Check if have right on this entity * * @param $recursive boolean set true to accept recursive items of ancestors * of active entities (View case for example) (default false) * @since version 0.85 * * @return booleen **/ function checkEntity($recursive = false) { // Is an item assign to an entity if ($this->isEntityAssign()) { // Can be recursive check if ($recursive && $this->maybeRecursive()) { return Session::haveAccessToEntity($this->getEntityID(), $this->isRecursive()); } // else : No recursive item // Have access to entity return Session::haveAccessToEntity($this->getEntityID()); } // else : Global item return true; }
public function checkIfTemplateExistsInEntity($detailID, $itemtype, $entity) { global $DB; $table = $this->getTable(); $query = "SELECT ref.`templates_id`\n FROM `glpi_plugin_order_orders_items` item, `{$table}` ref\n WHERE item.`plugin_order_references_id` = ref.`id`\n AND item.`id` = '{$detailID}';"; $result = $DB->query($query); if (!$DB->numrows($result)) { return 0; } else { $item = new $itemtype(); $item->getFromDB($DB->result($result, 0, "templates_id")); if ($item->getField('entities_id') == $entity || $item->maybeRecursive() && $item->fields['is_recursive'] && Session::haveAccessToEntity($entity, true)) { return $item->getField('id'); } else { //Workaround when templates are not recursive (ie computers, monitors, etc.) //If templates have the same name in several entities : search for a template with //the same name if ($item->getField('template_name') != NOT_AVAILABLE) { $query = "SELECT `id` FROM `" . $item->getTable() . "`\n WHERE `entities_id`='{$entity}'\n AND `template_name`='" . $item->fields['template_name'] . "'\n AND `is_template`='1'"; $result_template = $DB->query($query); if ($DB->numrows($result_template) >= 1) { return $DB->result($result_template, 0, "id"); } else { return 0; } } else { return 0; } } } }
static function getHelpdeskListFormParam($filtro) { global $DB, $CFG_GLPI; //incluir db echo '<div class="center">'; $sqlservicios = "select s.id as services_id, s.name as servicio, f.id as forms_id, f.name as pedido, f.content, f.entities_id, f.is_recursive, f.language from glpi_plugin_formcreator_forms f\n\t\t\t\t\t\t\t\t\tleft outer join (select r.parent_id, s.id, s.name from glpi_plugin_relation_relations r \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tleft outer join glpi_plugin_servicios_servicios s on (s.id =r.items_id)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhere r.parent_type='PluginFormcreatorForm' \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand r.itemtype='PluginServiciosServicio' ) s on (s.parent_id = f.id) \n\t\t\t\t\t\t\t\t\twhere f.is_active = '1' \n\t\t\t\t\t\t\t\t\tand (f.name like '%{$filtro}%' or s.name like '%{$filtro}%' or f.content like '%{$filtro}%')\n\t\t\t\t\t\t\t\t\torder by s.name, f.name"; $result = $DB->query($sqlservicios); $nbForm = 0; if ($DB->numrows($result) == 0) { # No formular yet echo __("No se ha encontrado ningún pedido de catálogo.", "No se ha encontrado ningún pedido de catálogo."); } else { echo "<table class='tab_cadre_fixe fix_tab_height'>"; echo "<tr>"; echo "<th>" . __("Servicio", "Servicio") . "</th>"; echo "<th>" . __("Pedido de catálogo", "Pedido de catálogo") . "</th>"; echo "<th>" . __("Descripcion", "Descripcion") . "</th>"; echo "</tr>"; while ($data = $DB->fetch_assoc($result)) { if (PluginFormcreatorForm::viewFormInListForm($data['forms_id']) == 1) { if (Session::haveAccessToEntity($data['entities_id'], $data['is_recursive'])) { $link = $CFG_GLPI["root_doc"] . "/plugins/formcreator/front/showform.php"; $links = $CFG_GLPI["root_doc"] . "/plugins/servicios/front/servicio.form.php"; if (Session::haveRight('config', UPDATE) || empty($data['language']) || $data['language'] == $_SESSION["glpilanguage"]) { echo "<tr>"; $servicio = ""; if (!empty($data['servicio'])) { $servicio = "<a href=" . $links . "?id=" . $data['services_id'] . ">" . $data['servicio'] . "</a>"; } echo '<td>' . $servicio . '</td>'; echo '<td><a href=' . $link . '?id=' . $data['forms_id'] . '>' . $data['pedido'] . '</a></td>'; echo "<td>" . $data['content'] . "</td>"; echo "</tr>"; $nbForm++; } } } } if (!$nbForm) { echo '<tr>'; echo '<td class="center" colspan="4">' . __("No se ha encontrado ningún pedido de catálogo.", "No se ha encontrado ningún pedido de catálogo.") . '</td>'; echo '</tr>'; } echo "</table>"; } echo "</div>"; }
/** * Manage login redirection * * @param $where string: where to redirect ? **/ static function manageRedirect($where) { global $CFG_GLPI, $PLUGIN_HOOKS; if (!empty($where)) { if (isset($_SESSION["glpiactiveprofile"]["interface"]) && !empty($_SESSION["glpiactiveprofile"]["interface"])) { $decoded_where = rawurldecode($where); // redirect to URL : URL must be rawurlencoded if ($link = preg_match('/https?:\\/\\/.+/', $decoded_where)) { Html::redirect($decoded_where); } // Redirect based on GLPI_ROOT : URL must be rawurlencoded if ($decoded_where[0] == '/') { // echo $decoded_where;exit(); Html::redirect($CFG_GLPI["root_doc"] . $decoded_where); } $data = explode("_", $where); $forcetab = ''; // forcetab for simple items if (isset($data[1])) { $forcetab = 'forcetab=' . $data[1]; } if (isset($data[2])) { $forcetab = 'forcetab=' . $data[2]; } switch ($_SESSION["glpiactiveprofile"]["interface"]) { case "helpdesk": switch (strtolower($data[0])) { // Use for compatibility with old name case "tracking": case "ticket": $data[0] = 'Ticket'; // redirect to item if (isset($data[1]) && is_numeric($data[1]) && $data[1] > 0) { // Check entity if (($item = getItemForItemtype($data[0])) && $item->isEntityAssign()) { if ($item->getFromDB($data[1])) { if (!Session::haveAccessToEntity($item->getEntityID())) { Session::changeActiveEntities($item->getEntityID(), 1); } } } Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $data[1] . "&{$forcetab}"); // redirect to list } else { if (!empty($data[0])) { if ($item = getItemForItemtype($data[0])) { Html::redirect($item->getSearchURL() . "?{$forcetab}"); } } } Html::redirect($CFG_GLPI["root_doc"] . "/front/helpdesk.public.php"); break; case "preference": Html::redirect($CFG_GLPI["root_doc"] . "/front/preference.php?{$forcetab}"); break; default: Html::redirect($CFG_GLPI["root_doc"] . "/front/helpdesk.public.php"); break; } break; case "central": switch (strtolower($data[0])) { case "preference": Html::redirect($CFG_GLPI["root_doc"] . "/front/preference.php?{$forcetab}"); break; // Use for compatibility with old name // no break // Use for compatibility with old name // no break case "tracking": $data[0] = "Ticket"; default: // redirect to item if (!empty($data[0]) && isset($data[1]) && is_numeric($data[1]) && $data[1] > 0) { // Check entity if ($item = getItemForItemtype($data[0])) { if ($item->isEntityAssign()) { if ($item->getFromDB($data[1])) { if (!Session::haveAccessToEntity($item->getEntityID())) { Session::changeActiveEntities($item->getEntityID(), 1); } } } Html::redirect($item->getFormURL() . "?id=" . $data[1] . "&{$forcetab}"); } // redirect to list } else { if (!empty($data[0])) { if ($item = getItemForItemtype($data[0])) { Html::redirect($item->getSearchURL() . "?{$forcetab}"); } } } Html::redirect($CFG_GLPI["root_doc"] . "/front/central.php"); break; } break; } } } }
static function getHomeHelpdeskListForm() { global $LANG, $CFG_GLPI; $form = new PluginFormcreatorForm(); $listForm = $form->find("is_active = '1'"); echo "<table style='float: right;'>"; echo "<tr><td class='top' width='450px'>"; echo '<table class="tab_cadrehov">'; echo '<tr>'; echo '<th>'; echo '<div class="relative">' . $LANG['plugin_formcreator']["headings"][6] . '</div>'; echo '</th>'; echo '</tr>'; $nbForm = 0; foreach ($listForm as $form_id => $value) { $question = new PluginFormcreatorQuestion(); $listQuestion = $question->find("plugin_formcreator_forms_id = '" . $form_id . "'"); if (!empty($listQuestion)) { if (Session::haveAccessToEntity($value['entities_id'], $value['is_recursive'])) { $link = $CFG_GLPI["root_doc"] . "/plugins/formcreator/front/form.helpdesk.php"; echo "<tr>"; echo '<td><a href=' . $link . '?form=' . $form_id . '>' . $value['name'] . '</a></td>'; echo "</tr>"; $nbForm++; } } } if (!$nbForm) { echo '<tr>'; echo '<td class="center" colspan="3">' . $LANG['plugin_formcreator']["helpdesk"][1] . '</td>'; echo '</tr>'; } echo '</table>'; echo "</td></tr>"; echo "</table>"; }
/** * Is the current user have right to create the current problem ? * * @return boolean **/ function canCreateItem() { if (!Session::haveAccessToEntity($this->getEntityID())) { return false; } return Session::haveRight('edit_all_problem', 1); }
/** * Is the current user have right to update the current notification ? * * @return boolean **/ function canCreateItem() { if (($this->fields['itemtype'] == 'Crontask' || $this->fields['itemtype'] == 'DBConnection') && !Config::canUpdate()) { return false; } return Session::haveAccessToEntity($this->getEntityID()); }
/** * @since version 0.84 (before in entitydata.class) * * @param $entity Entity object **/ static function showHelpdeskOptions(Entity $entity) { global $CFG_GLPI; $ID = $entity->getField('id'); if (!$entity->can($ID, READ) || !Session::haveRightsOr(self::$rightname, array(self::READHELPDESK, self::UPDATEHELPDESK))) { return false; } $canedit = Session::haveRight(self::$rightname, self::UPDATEHELPDESK) && Session::haveAccessToEntity($ID); echo "<div class='spaced'>"; if ($canedit) { echo "<form method='post' name=form action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; } echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td colspan='2'>" . _n('Ticket template', 'Ticket templates', 1) . "</td>"; echo "<td colspan='2'>"; $toadd = array(); if ($ID != 0) { $toadd = array(self::CONFIG_PARENT => __('Inheritance of the parent entity')); } $options = array('value' => $entity->fields["tickettemplates_id"], 'entity' => $ID, 'toadd' => $toadd); TicketTemplate::dropdown($options); if ($entity->fields["tickettemplates_id"] == self::CONFIG_PARENT && $ID != 0) { echo "<font class='green'> "; $tt = new TicketTemplate(); $tid = self::getUsedConfig('tickettemplates_id', $ID, '', 0); if (!$tid) { echo Dropdown::EMPTY_VALUE; } else { if ($tt->getFromDB($tid)) { echo $tt->getLink(); } } echo "</font>"; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td colspan='2'>" . __('Calendar') . "</td>"; echo "<td colspan='2'>"; $options = array('value' => $entity->fields["calendars_id"], 'emptylabel' => __('24/7')); if ($ID != 0) { $options['toadd'] = array(self::CONFIG_PARENT => __('Inheritance of the parent entity')); } Calendar::dropdown($options); if ($entity->fields["calendars_id"] == self::CONFIG_PARENT && $ID != 0) { echo "<font class='green'> "; $calendar = new Calendar(); $cid = self::getUsedConfig('calendars_id', $ID, '', 0); if (!$cid) { _e('24/7'); } else { if ($calendar->getFromDB($cid)) { echo $calendar->getLink(); } } echo "</font>"; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td colspan='2'>" . __('Tickets default type') . "</td>"; echo "<td colspan='2'>"; $toadd = array(); if ($ID != 0) { $toadd = array(self::CONFIG_PARENT => __('Inheritance of the parent entity')); } Ticket::dropdownType('tickettype', array('value' => $entity->fields["tickettype"], 'toadd' => $toadd)); if ($entity->fields['tickettype'] == self::CONFIG_PARENT && $ID != 0) { echo "<font class='green'> "; echo Ticket::getTicketTypeName(self::getUsedConfig('tickettype', $ID, '', Ticket::INCIDENT_TYPE)); echo "</font>"; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td colspan='2'>" . __('Automatic assignment of tickets') . "</td>"; echo "<td colspan='2'>"; $autoassign = self::getAutoAssignMode(); if ($ID == 0) { unset($autoassign[self::CONFIG_PARENT]); } Dropdown::showFromArray('auto_assign_mode', $autoassign, array('value' => $entity->fields["auto_assign_mode"])); if ($entity->fields['auto_assign_mode'] == self::CONFIG_PARENT && $ID != 0) { $auto_assign_mode = self::getUsedConfig('auto_assign_mode', $entity->fields['entities_id']); echo "<font class='green'> "; echo $autoassign[$auto_assign_mode]; echo "</font>"; } echo "</td></tr>"; echo "<tr><th colspan='4'>" . __('Automatic closing configuration') . "</th></tr>"; echo "<tr class='tab_bg_1'>" . "<td colspan='2'>" . __('Automatic closing of solved tickets after') . "</td>"; echo "<td colspan='2'>"; $autoclose = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'), self::CONFIG_NEVER => __('Never'), 0 => __('Immediatly')); if ($ID == 0) { unset($autoclose[self::CONFIG_PARENT]); } Dropdown::showNumber('autoclose_delay', array('value' => $entity->fields['autoclose_delay'], 'min' => 1, 'max' => 99, 'step' => 1, 'toadd' => $autoclose, 'unit' => 'day')); if ($entity->fields['autoclose_delay'] == self::CONFIG_PARENT && $ID != 0) { $autoclose_mode = self::getUsedConfig('autoclose_delay', $entity->fields['entities_id'], '', self::CONFIG_NEVER); echo "<br><font class='green'> "; if ($autoclose_mode >= 0) { printf(_n('%d day', '%d days', $autoclose_mode), $autoclose_mode); } else { echo $autoclose[$autoclose_mode]; } echo "</font>"; } echo "</td></tr>"; echo "<tr><th colspan='4'>" . __('Configuring the satisfaction survey') . "</th></tr>"; echo "<tr class='tab_bg_1'>" . "<td colspan='2'>" . __('Configuring the satisfaction survey') . "</td>"; echo "<td colspan='2'>"; /// no inquest case = rate 0 $typeinquest = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'), 1 => __('Internal survey'), 2 => __('External survey')); // No inherit from parent for root entity if ($ID == 0) { unset($typeinquest[self::CONFIG_PARENT]); if ($entity->fields['inquest_config'] == self::CONFIG_PARENT) { $entity->fields['inquest_config'] = 1; } } $rand = Dropdown::showFromArray('inquest_config', $typeinquest, $options = array('value' => $entity->fields['inquest_config'])); echo "</td></tr>\n"; // Do not display for root entity in inherit case if ($entity->fields['inquest_config'] == self::CONFIG_PARENT && $ID != 0) { $inquestconfig = self::getUsedConfig('inquest_config', $entity->fields['entities_id']); $inquestrate = self::getUsedConfig('inquest_config', $entity->fields['entities_id'], 'inquest_rate'); echo "<tr class='tab_bg_1'><td colspan='4' class='green center'>"; if ($inquestrate == 0) { _e('Disabled'); } else { echo $typeinquest[$inquestconfig] . '<br>'; $inqconf = self::getUsedConfig('inquest_config', $entity->fields['entities_id'], 'inquest_delay'); printf(_n('%d day', '%d days', $inqconf), $inqconf); echo "<br>"; //TRANS: %d is the percentage. %% to display % printf(__('%d%%'), $inquestrate); if ($inquestconfig == 2) { echo "<br>"; echo self::getUsedConfig('inquest_config', $entity->fields['entities_id'], 'inquest_URL'); } } echo "</td></tr>\n"; } echo "<tr class='tab_bg_1'><td colspan='4'>"; $_POST = array('inquest_config' => $entity->fields['inquest_config'], 'entities_id' => $ID); $params = array('inquest_config' => '__VALUE__', 'entities_id' => $ID); echo "<div id='inquestconfig'>"; include GLPI_ROOT . '/ajax/ticketsatisfaction.php'; echo "</div>\n"; echo "</td></tr>"; if ($canedit) { echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='4'>"; echo "<input type='hidden' name='id' value='" . $entity->fields["id"] . "'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); } else { echo "</table>"; } echo "</div>"; Ajax::updateItemOnSelectEvent("dropdown_inquest_config{$rand}", "inquestconfig", $CFG_GLPI["root_doc"] . "/ajax/ticketsatisfaction.php", $params); }
/** * List the tickets for an authenticated user * * @param $params array of options (author, group, category, status, startdate, enddate, itemtype) * @param $protocol the communication protocol used * * @return array of hashtable **/ static function methodListTickets($params, $protocol) { global $DB, $CFG_GLPI; if (isset($params['help'])) { return array('count' => 'bool,optional', 'start' => 'integer,optional', 'limit' => 'integer,optional', 'user' => 'integer,optional', 'recipient' => 'integer,optional', 'mine' => 'bool,optional', 'group' => 'integer,optional', 'mygroups' => 'bool,optional', 'category' => 'integer,optional', 'status' => 'integer,optional', 'startdate' => 'datetime,optional', 'enddate' => 'datetime,optional', 'itemtype' => 'string,optional', 'item' => 'integer,optional', 'entity' => 'integer,optional', 'satisfaction' => 'integer,optional', 'approval' => 'text,optional', 'approver' => 'integer,optional', 'id2name' => 'bool,optional', 'order' => 'array,optional', 'help' => 'bool,optional'); } if (!Session::getLoginUserID()) { return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); } $resp = array(); $start = 0; if (isset($params['start']) && is_numeric($params['start'])) { $start = $params['start']; } $limit = $_SESSION['glpilist_limit']; if (isset($params['limit']) && is_numeric($params['limit'])) { $limit = $params['limit']; } $where = $join = ''; // User (victim) if (isset($params['user'])) { if (!is_numeric($params['user']) || $params['user'] < 0) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user'); } if (Session::haveRight('show_all_ticket', '1') || Session::haveRight('show_group_ticket', '1') || $params['user'] == Session::getLoginUserID()) { // restrict to author parameter $where = " AND `glpi_tickets_users_request`.`users_id` = '" . $params['user'] . "'"; } else { return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED); } } else { if (Session::haveRight('show_all_ticket', '1') || Session::haveRight('show_group_ticket', '1')) { $where = ''; // Restrict will come from group (if needed) } else { // Only connected user's tickets' $where = " AND `glpi_tickets_users_request`.`users_id`\n = '" . Session::getLoginUserID() . "'"; } } // Group if (isset($params['group'])) { if (!is_numeric($params['group']) || $params['group'] < 0) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'group'); } if (Session::haveRight('show_all_ticket', '1') || Session::haveRight('show_group_ticket', '1') && in_array($params['group'], $_SESSION['glpigroups'])) { // restrict to group parameter $where = " AND `glpi_groups_tickets_request`.`groups_id` = '" . $params['group'] . "'"; } else { return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED); } } else { if (Session::haveRight('show_group_ticket', '1') && !Session::haveRight('show_all_ticket', '1')) { // Connected user's group' if (count($_SESSION['glpigroups']) > 0) { $where = " AND `glpi_groups_tickets_request`.`groups_id`\n IN (" . implode(',', $_SESSION['glpigroups']) . ")"; } else { $where = " AND `glpi_tickets_users_request`.`users_id`\n = '" . Session::getLoginUserID() . "'"; } } } // Security if (empty($where) && !Session::haveRight('show_all_ticket', '1')) { return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', 'profil'); } // Recipient (person creating the ticket) if (isset($params['recipient'])) { if (!is_numeric($params['recipient']) || $params['recipient'] < 0) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'recipient'); } // restrict to recipient parameter $where = " AND `users_id_recipient`='" . $params['recipient'] . "'"; } // Mine (user or recipient for the ticket) if (isset($params['mine'])) { $where = " AND (`glpi_tickets_users_request`.`users_id` = '" . Session::getLoginUserID() . "'\n OR `users_id_recipient` = '" . Session::getLoginUserID() . "')"; } // Mygroups if (isset($param['mygroups'])) { $where = " AND `glpi_groups_tickets`.`groups_id`\n IN (" . implode(',', $_SESSION['glpigroups']) . ")"; } // Entity if (isset($params['entity'])) { if (!Session::haveAccessToEntity($params['entity'])) { return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', 'entity'); } $where = getEntitiesRestrictRequest("WHERE", "glpi_tickets", '', $params['entity']) . $where; } else { $where = getEntitiesRestrictRequest("WHERE", "glpi_tickets") . $where; } // Category if (isset($params['category'])) { if (!is_numeric($params['category']) || $params['category'] <= 0) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'category'); } $where .= " AND " . getRealQueryForTreeItem("glpi_itilcategories", $params['category'], "glpi_tickets.itilcategories_id"); } if (isset($params['approval']) || isset($params['approver'])) { $join .= "INNER JOIN `glpi_ticketvalidations`\n ON (`glpi_tickets`.`id` = `glpi_ticketvalidations`.`tickets_id` ) "; if (isset($params['approver']) && is_numeric($params['approver'])) { $where .= " AND `glpi_ticketvalidations`.`users_id_validate`=" . $params['approver']; } $tabstatus = TicketValidation::getAllStatusArray(); if (isset($params['approval']) && isset($tabstatus[$params['approval']])) { $where .= " AND `glpi_ticketvalidations`.`status`='" . $params['approval'] . "'"; } } if (isset($params['satisfaction'])) { $join .= "INNER JOIN `glpi_ticketsatisfactions`\n ON (`glpi_tickets`.`id` = `glpi_ticketsatisfactions`.`tickets_id` ) "; switch ($params['satisfaction']) { case 1: $where .= " AND `glpi_ticketsatisfactions`.`date_answered` IS NULL"; break; case 2: $where .= " AND `glpi_ticketsatisfactions`.`date_answered` IS NOT NULL"; break; default: // survey exists (by Inner Join) } $params['status'] = Ticket::CLOSED; } // Status if (isset($params['status'])) { if (!in_array($params['status'], Ticket::getAllowedStatusArray(true))) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'status'); } switch ($params['status']) { case 'all': // No restriction break; case 'notclosed': $status = Ticket::getAllStatusArray(); unset($status[CLOSED]); $where .= " AND `glpi_tickets`.`status` IN ('" . implode("','", $status) . "') "; break; case 'notold': $status = Ticket::getAllStatusArray(); unset($status[SOLVED], $status[CLOSED]); $where .= " AND `glpi_tickets`.`status` IN ('" . implode("','", $status) . "') "; break; case 'old': $status = array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray()); $where .= " AND `glpi_tickets`.`status` IN ('" . implode("','", $status) . "') "; break; case 'process': $status = Ticket::getProcessStatusArray(); $where .= " AND `glpi_tickets`.`status` IN ('" . implode("','", $status) . "') "; break; default: $where .= " AND `glpi_tickets`.`status` = '" . $params['status'] . "' "; } } // Dates if (isset($params["startdate"])) { if (preg_match(WEBSERVICES_REGEX_DATETIME, $params["startdate"]) || preg_match(WEBSERVICES_REGEX_DATE, $params["startdate"])) { $where .= " AND `glpi_tickets`.`date` >= '" . $params['startdate'] . "' "; } else { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'date'); } } if (isset($params["enddate"])) { if (preg_match(WEBSERVICES_REGEX_DATETIME, $params["enddate"]) || preg_match(WEBSERVICES_REGEX_DATE, $params["enddate"])) { $where .= " AND `glpi_tickets`.`date` <= '" . $params['enddate'] . "' "; } else { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'date'); } } if (isset($params['itemtype'])) { if (!empty($params['itemtype']) && !class_exists($params['itemtype'])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'itemtype'); } $where .= " AND `glpi_tickets`.`itemtype`='" . $params['itemtype'] . "'"; } if (isset($params['item'])) { if (!isset($params['itemtype'])) { return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'itemtype'); } if (!is_numeric($params['item']) || $params['item'] <= 0) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'item'); } $where .= " AND `glpi_tickets`.`items_id`='" . $params['item'] . "'"; } $orders = array(); if (isset($params['order'])) { if (is_array($params['order'])) { $tab = $params['order']; } else { $tab = array($params['order'] => 'DESC'); } foreach ($tab as $key => $val) { if ($val != 'ASC') { $val = 'DESC'; } $sqlkey = array('id' => '`glpi_tickets`.`id`', 'date' => '`glpi_tickets`.`date`', 'closedate' => '`glpi_tickets`.`closedate`', 'date_mod' => '`glpi_tickets`.`date_mod`', 'status' => '`glpi_tickets`.`status`', 'entities_id' => '`glpi_tickets`.`entities_id`', 'priority' => '`glpi_tickets`.`priority`'); if (isset($sqlkey[$key])) { $orders[] = $sqlkey[$key] . " {$val}"; } else { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'order=$key'); } } } if (count($orders)) { $order = implode(',', $orders); } else { $order = "`glpi_tickets`.`date_mod` DESC"; } $resp = array(); if (isset($params['count'])) { $query = "SELECT COUNT(DISTINCT `glpi_tickets`.`id`) AS count\n FROM `glpi_tickets`\n {$join}\n LEFT JOIN `glpi_tickets_users` AS glpi_tickets_users_request\n ON (`glpi_tickets`.`id` = `glpi_tickets_users_request`.`tickets_id`\n AND `glpi_tickets_users_request`.`type` = 1)\n LEFT JOIN `glpi_groups_tickets` AS glpi_groups_tickets_request\n ON (`glpi_tickets`.`id` = `glpi_groups_tickets_request`.`tickets_id`\n AND `glpi_groups_tickets_request`.`type` = 1 )\n {$where}"; $resp = $DB->request($query)->next(); //debug $resp['query'] = $query; } else { $query = "SELECT `glpi_tickets`.*,\n GROUP_CONCAT(DISTINCT `glpi_tickets_users_request`.`users_id` SEPARATOR ',')\n AS users_id_request,\n GROUP_CONCAT(DISTINCT `glpi_tickets_users_observer`.`users_id` SEPARATOR ',')\n AS users_id_observer,\n GROUP_CONCAT(DISTINCT `glpi_tickets_users_assign`.`users_id` SEPARATOR ',')\n AS users_id_assign,\n GROUP_CONCAT(DISTINCT `glpi_groups_tickets_request`.`groups_id` SEPARATOR ',')\n AS groups_id_request,\n GROUP_CONCAT(DISTINCT `glpi_groups_tickets_observer`.`groups_id` SEPARATOR ',')\n AS groups_id_observer,\n GROUP_CONCAT(DISTINCT `glpi_groups_tickets_assign`.`groups_id` SEPARATOR ',')\n AS groups_id_assign\n FROM `glpi_tickets`\n {$join}\n LEFT JOIN `glpi_tickets_users` AS glpi_tickets_users_request\n ON (`glpi_tickets`.`id` = `glpi_tickets_users_request`.`tickets_id`\n AND `glpi_tickets_users_request`.`type` = 1)\n LEFT JOIN `glpi_tickets_users` AS glpi_tickets_users_assign\n ON (`glpi_tickets`.`id` = `glpi_tickets_users_assign`.`tickets_id`\n AND `glpi_tickets_users_assign`.`type` = 2)\n LEFT JOIN `glpi_tickets_users` AS glpi_tickets_users_observer\n ON (`glpi_tickets`.`id` = `glpi_tickets_users_observer`.`tickets_id`\n AND `glpi_tickets_users_observer`.`type` = 3)\n LEFT JOIN `glpi_groups_tickets` AS glpi_groups_tickets_request\n ON (`glpi_tickets`.`id` = `glpi_groups_tickets_request`.`tickets_id`\n AND `glpi_groups_tickets_request`.`type` = 1)\n LEFT JOIN `glpi_groups_tickets` AS glpi_groups_tickets_assign\n ON (`glpi_tickets`.`id` = `glpi_groups_tickets_assign`.`tickets_id`\n AND `glpi_groups_tickets_assign`.`type` = 2)\n LEFT JOIN `glpi_groups_tickets` AS glpi_groups_tickets_observer\n ON (`glpi_tickets`.`id` = `glpi_groups_tickets_observer`.`tickets_id`\n AND `glpi_groups_tickets_observer`.`type` = 3)\n {$where}\n GROUP BY `glpi_tickets`.`id`\n ORDER BY {$order}\n LIMIT {$start},{$limit}"; foreach ($DB->request($query) as $data) { $tmp = explode(',', $data['users_id_request']); $data['users']['requester'] = array(); foreach ($tmp as $id) { $data['users']['requester'][]['id'] = $id; } $tmp = explode(',', $data['users_id_observer']); $data['users']['observer'] = array(); foreach ($tmp as $id) { $data['users']['observer'][]['id'] = $id; } $tmp = explode(',', $data['users_id_assign']); $data['users']['assign'] = array(); foreach ($tmp as $id) { $data['users']['assign'][]['id'] = $id; } $tmp = explode(',', $data['groups_id_request']); $data['groups']['requester'] = array(); foreach ($tmp as $id) { $data['groups']['requester'][]['id'] = $id; } $tmp = explode(',', $data['groups_id_observer']); $data['groups']['observer'] = array(); foreach ($tmp as $id) { $data['groups']['observer'][]['id'] = $id; } $tmp = explode(',', $data['groups_id_assign']); $data['groups']['assign'] = array(); foreach ($tmp as $id) { $data['groups']['assign'][]['id'] = $id; } unset($data['groups_id_request'], $data['groups_id_observer'], $data['groups_id_assign'], $data['users_id_request'], $data['users_id_observer'], $data['users_id_assign']); $data['solution'] = Html::clean(Toolbox::unclean_cross_side_scripting_deep($data['solution'])); if (isset($params['id2name'])) { if ($data['itemtype'] && ($item = getItemForItemtype($data['itemtype']))) { $data['itemtype_name'] = Html::clean($item->getTypeName()); if ($item->getFromDB($data['items_id'])) { $data['items_name'] = Html::clean($item->getNameID()); } else { $data['items_name'] = NOT_AVAILABLE; } } foreach ($data['groups'] as $type => $tab) { foreach ($tab as $key => $grp) { $data['groups'][$type][$key]['name'] = Html::clean(Dropdown::getDropdownName('glpi_groups', $grp['id'])); } } foreach ($data['users'] as $type => $tab) { foreach ($tab as $key => $usr) { $data['users'][$type][$key]['name'] = Html::clean(getUserName($usr['id'])); } } $data['status_name'] = Html::clean(Ticket::getStatus($data['status'])); $data['urgency_name'] = Ticket::getUrgencyName($data['urgency']); $data['impact_name'] = Ticket::getImpactName($data['impact']); $data['priority_name'] = Ticket::getPriorityName($data['priority']); $data['users_name_recipient'] = Html::clean(getUserName($data['users_id_recipient'])); $data['entities_name'] = Html::clean(Dropdown::getDropdownName('glpi_entities', $data['entities_id'])); $data['suppliers_name_assign'] = Html::clean(Dropdown::getDropdownName('glpi_suppliers', $data['suppliers_id_assign'])); $data['ticketcategories_name'] = Html::clean(Dropdown::getDropdownName('glpi_itilcategories', $data['itilcategories_id'])); $data['requesttypes_name'] = Html::clean(Dropdown::getDropdownName('glpi_requesttypes', $data['requesttypes_id'])); $data['solutiontypes_name'] = Html::clean(Dropdown::getDropdownName('glpi_solutiontypes', $data['solutiontypes_id'])); $data['slas_name'] = Html::clean(Dropdown::getDropdownName('glpi_slas', $data['slas_id'])); $data['slalevels_name'] = Html::clean(Dropdown::getDropdownName('glpi_slalevels', $data['slalevels_id'])); } $resp[] = $data; } } return $resp; }
/** * Clone of Ticket::showForm() * Change '$this' by '$ticket', 'self' by 'Ticket' and 'parent' by 'Ticket' */ static function getCentral($ID = 0, $options = array()) { global $CFG_GLPI; // * Added by plugin survey ticket $ticket = new Ticket(); // * End of adding $default_values = Ticket::getDefaultValues(); // Get default values from posted values on reload form if (!isset($options['template_preview'])) { if (isset($_POST)) { $values = $_POST; } } // Restore saved value or override with page parameter $saved = $ticket->restoreInput(); foreach ($default_values as $name => $value) { if (!isset($values[$name])) { if (isset($saved[$name])) { $values[$name] = $saved[$name]; } else { $values[$name] = $value; } } } // Default check if ($ID > 0) { $ticket->check($ID, 'r'); } else { // Create item $ticket->check(-1, 'w', $values); } if (!$ID) { $ticket->userentities = array(); if ($values["_users_id_requester"]) { //Get all the user's entities $all_entities = Profile_User::getUserEntities($values["_users_id_requester"], true, true); //For each user's entity, check if the technician which creates the ticket have access to it foreach ($all_entities as $tmp => $ID_entity) { if (Session::haveAccessToEntity($ID_entity)) { $ticket->userentities[] = $ID_entity; } } } $ticket->countentitiesforuser = count($ticket->userentities); if ($ticket->countentitiesforuser > 0 && !in_array($ticket->fields["entities_id"], $ticket->userentities)) { // If entity is not in the list of user's entities, // then use as default value the first value of the user's entites list $ticket->fields["entities_id"] = $ticket->userentities[0]; // Pass to values $values['entities_id'] = $ticket->userentities[0]; } } if ($values['type'] <= 0) { $values['type'] = Entity::getUsedConfig('tickettype', $values['entities_id'], '', Ticket::INCIDENT_TYPE); } if (!isset($options['template_preview'])) { $options['template_preview'] = 0; } // Load ticket template if available : $tt = $ticket->getTicketTemplateToUse($options['template_preview'], $values['type'], $values['itilcategories_id'], $values['entities_id']); // Predefined fields from template : reset them if (isset($values['_predefined_fields'])) { $values['_predefined_fields'] = Toolbox::decodeArrayFromInput($values['_predefined_fields']); } else { $values['_predefined_fields'] = array(); } // Store predefined fields to be able not to take into account on change template // Only manage predefined values on ticket creation $predefined_fields = array(); if (!$ID) { if (isset($tt->predefined) && count($tt->predefined)) { foreach ($tt->predefined as $predeffield => $predefvalue) { if (isset($default_values[$predeffield])) { // Is always default value : not set // Set if already predefined field // Set if ticket template change if ($values[$predeffield] == $default_values[$predeffield] || isset($values['_predefined_fields'][$predeffield]) && $values[$predeffield] == $values['_predefined_fields'][$predeffield] || isset($values['_tickettemplates_id']) && $values['_tickettemplates_id'] != $tt->getID()) { // Load template data $values[$predeffield] = $predefvalue; $ticket->fields[$predeffield] = $predefvalue; $predefined_fields[$predeffield] = $predefvalue; } } } } else { // No template load : reset predefined values if (count($values['_predefined_fields'])) { foreach ($values['_predefined_fields'] as $predeffield => $predefvalue) { if ($values[$predeffield] == $predefvalue) { $values[$predeffield] = $default_values[$predeffield]; } } } } } // Put ticket template on $values for actors $values['_tickettemplate'] = $tt; $canupdate = Session::haveRight('update_ticket', '1'); $canpriority = Session::haveRight('update_priority', '1'); $canstatus = $canupdate; if (in_array($ticket->fields['status'], $ticket->getClosedStatusArray())) { $canupdate = false; } $showuserlink = 0; if (Session::haveRight('user', 'r')) { $showuserlink = 1; } if (!$options['template_preview']) { $ticket->showTabs($options); } else { // Add all values to fields of tickets for template preview foreach ($values as $key => $val) { if (!isset($ticket->fields[$key])) { $ticket->fields[$key] = $val; } } } // In percent $colsize1 = '13'; $colsize2 = '29'; $colsize3 = '13'; $colsize4 = '45'; $canupdate_descr = $canupdate || $ticket->fields['status'] == Ticket::INCOMING && $ticket->isUser(CommonITILActor::REQUESTER, Session::getLoginUserID()) && $ticket->numberOfFollowups() == 0 && $ticket->numberOfTasks() == 0; if (!$options['template_preview']) { echo "<form method='post' name='form_ticket' enctype='multipart/form-data' action='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php'>"; } echo "<div class='spaced' id='tabsbody'>"; echo "<table class='tab_cadre_fixe' id='mainformtable'>"; // Optional line $ismultientities = Session::isMultiEntitiesMode(); echo "<tr class='headerRow'>"; echo "<th colspan='4'>"; if ($ID) { $text = sprintf(__('%1$s - %2$s'), $ticket->getTypeName(1), sprintf(__('%1$s: %2$s'), __('ID'), $ID)); if ($ismultientities) { $text = sprintf(__('%1$s (%2$s)'), $text, Dropdown::getDropdownName('glpi_entities', $ticket->fields['entities_id'])); } echo $text; } else { if ($ismultientities) { printf(__('The ticket will be added in the entity %s'), Dropdown::getDropdownName("glpi_entities", $ticket->fields['entities_id'])); } else { _e('New ticket'); } } echo "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>"; echo $tt->getBeginHiddenFieldText('date'); if (!$ID) { printf(__('%1$s%2$s'), __('Opening date'), $tt->getMandatoryMark('date')); } else { _e('Opening date'); } echo $tt->getEndHiddenFieldText('date'); echo "</th>"; echo "<td width='{$colsize2}%'>"; echo $tt->getBeginHiddenFieldValue('date'); $date = $ticket->fields["date"]; if ($canupdate) { Html::showDateTimeFormItem("date", $date, 1, false); } else { echo Html::convDateTime($date); } echo $tt->getEndHiddenFieldValue('date', $ticket); echo "</td>"; // SLA echo "<th width='{$colsize3}%'>" . $tt->getBeginHiddenFieldText('due_date'); if (!$ID) { printf(__('%1$s%2$s'), __('Due date'), $tt->getMandatoryMark('due_date')); } else { _e('Due date'); } echo $tt->getEndHiddenFieldText('due_date'); echo "</th>"; echo "<td width='{$colsize4}%' class='nopadding'>"; if ($ID) { if ($ticket->fields["slas_id"] > 0) { echo "<table width='100%'><tr><td class='nopadding'>"; echo Html::convDateTime($ticket->fields["due_date"]); echo "</td><td class='b'>" . __('SLA') . "</td>"; echo "<td class='nopadding'>"; echo Dropdown::getDropdownName("glpi_slas", $ticket->fields["slas_id"]); $commentsla = ""; $slalevel = new SlaLevel(); if ($slalevel->getFromDB($ticket->fields['slalevels_id'])) { $commentsla .= '<span class="b spaced">' . sprintf(__('%1$s: %2$s'), __('Escalation level'), $slalevel->getName()) . '</span><br>'; } $nextaction = new SlaLevel_Ticket(); if ($nextaction->getFromDBForTicket($ticket->fields["id"])) { $commentsla .= '<span class="b spaced">' . sprintf(__('Next escalation: %s'), Html::convDateTime($nextaction->fields['date'])) . '</span>'; if ($slalevel->getFromDB($nextaction->fields['slalevels_id'])) { $commentsla .= '<span class="b spaced">' . sprintf(__('%1$s: %2$s'), __('Escalation level'), $slalevel->getName()) . '</span>'; } } $slaoptions = array(); if (Session::haveRight('config', 'r')) { $slaoptions['link'] = Toolbox::getItemTypeFormURL('SLA') . "?id=" . $ticket->fields["slas_id"]; } Html::showToolTip($commentsla, $slaoptions); if ($canupdate) { echo " <input type='submit' class='submit' name='sla_delete' value='" . _sx('button', 'Delete permanently') . "'>"; } echo "</td>"; echo "</tr></table>"; } else { echo "<table><tr><td class='nopadding'>"; echo $tt->getBeginHiddenFieldValue('due_date'); Html::showDateTimeFormItem("due_date", $ticket->fields["due_date"], 1, true, $canupdate); echo $tt->getEndHiddenFieldValue('due_date', $ticket); echo "</td>"; if ($canupdate) { echo "<td>"; echo $tt->getBeginHiddenFieldText('slas_id'); echo "<span id='sla_action'>"; echo "<a class='vsubmit' " . Html::addConfirmationOnAction(array(__('The assignment of a SLA to a ticket causes the recalculation of the due date.'), __("Escalations defined in the SLA will be triggered under this new date.")), "cleanhide('sla_action');cleandisplay('sla_choice');") . ">" . __('Assign a SLA') . '</a>'; echo "</span>"; echo "<span id='sla_choice' style='display:none'>"; echo "<span class='b'>" . __('SLA') . "</span> "; Sla::dropdown(array('entity' => $ticket->fields["entities_id"], 'value' => $ticket->fields["slas_id"])); echo "</span>"; echo $tt->getEndHiddenFieldText('slas_id'); echo "</td>"; } echo "</tr></table>"; } } else { // New Ticket echo "<table><tr><td class='nopadding'>"; if ($ticket->fields["due_date"] == 'NULL') { $ticket->fields["due_date"] = ''; } echo $tt->getBeginHiddenFieldValue('due_date'); Html::showDateTimeFormItem("due_date", $ticket->fields["due_date"], 1, false, $canupdate); echo $tt->getEndHiddenFieldValue('due_date', $ticket); echo "</td>"; if ($canupdate) { echo "<td class='nopadding b'>" . $tt->getBeginHiddenFieldText('slas_id'); printf(__('%1$s%2$s'), __('SLA'), $tt->getMandatoryMark('slas_id')); echo $tt->getEndHiddenFieldText('slas_id') . "</td>"; echo "<td class='nopadding'>" . $tt->getBeginHiddenFieldValue('slas_id'); Sla::dropdown(array('entity' => $ticket->fields["entities_id"], 'value' => $ticket->fields["slas_id"])); echo $tt->getEndHiddenFieldValue('slas_id', $ticket); echo "</td>"; } echo "</tr></table>"; } echo "</td></tr>"; if ($ID) { echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . __('By') . "</th>"; echo "<td width='{$colsize2}%'>"; if ($canupdate) { User::dropdown(array('name' => 'users_id_recipient', 'value' => $ticket->fields["users_id_recipient"], 'entity' => $ticket->fields["entities_id"], 'right' => 'all')); } else { echo getUserName($ticket->fields["users_id_recipient"], $showuserlink); } echo "</td>"; echo "<th width='{$colsize3}%'>" . __('Last update') . "</th>"; echo "<td width='{$colsize4}%'>"; if ($ticket->fields['users_id_lastupdater'] > 0) { //TRANS: %1$s is the update date, %2$s is the last updater name printf(__('%1$s by %2$s'), Html::convDateTime($ticket->fields["date_mod"]), getUserName($ticket->fields["users_id_lastupdater"], $showuserlink)); } echo "</td>"; echo "</tr>"; } if ($ID && (in_array($ticket->fields["status"], $ticket->getSolvedStatusArray()) || in_array($ticket->fields["status"], $ticket->getClosedStatusArray()))) { echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . __('Resolution date') . "</th>"; echo "<td width='{$colsize2}%'>"; Html::showDateTimeFormItem("solvedate", $ticket->fields["solvedate"], 1, false, $canupdate); echo "</td>"; if (in_array($ticket->fields["status"], $ticket->getClosedStatusArray())) { echo "<th width='{$colsize3}%'>" . __('Close date') . "</th>"; echo "<td width='{$colsize4}%'>"; Html::showDateTimeFormItem("closedate", $ticket->fields["closedate"], 1, false, $canupdate); echo "</td>"; } else { echo "<td colspan='2'> </td>"; } echo "</tr>"; } if ($ID) { echo "</table>"; echo "<table class='tab_cadre_fixe' id='mainformtable2'>"; } echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . sprintf(__('%1$s%2$s'), __('Type'), $tt->getMandatoryMark('type')) . "</th>"; echo "<td width='{$colsize2}%'>"; // Permit to set type when creating ticket without update right if ($canupdate || !$ID) { $opt = array('value' => $ticket->fields["type"]); /// Auto submit to load template if (!$ID) { $opt['on_change'] = 'submit()'; } $rand = Ticket::dropdownType('type', $opt); if ($ID) { $params = array('type' => '__VALUE__', 'entity_restrict' => $ticket->fields['entities_id'], 'value' => $ticket->fields['itilcategories_id'], 'currenttype' => $ticket->fields['type']); Ajax::updateItemOnSelectEvent("dropdown_type{$rand}", "show_category_by_type", $CFG_GLPI["root_doc"] . "/ajax/dropdownTicketCategories.php", $params); } } else { echo Ticket::getTicketTypeName($ticket->fields["type"]); } echo "</td>"; echo "<th width='{$colsize3}%'>" . sprintf(__('%1$s%2$s'), __('Category'), $tt->getMandatoryMark('itilcategories_id')) . "</th>"; echo "<td width='{$colsize4}%'>"; // Permit to set category when creating ticket without update right if ($canupdate || !$ID || $canupdate_descr) { $opt = array('value' => $ticket->fields["itilcategories_id"], 'entity' => $ticket->fields["entities_id"]); if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") { $opt['condition'] = "`is_helpdeskvisible`='1' AND "; } else { $opt['condition'] = ''; } /// Auto submit to load template if (!$ID) { $opt['on_change'] = 'submit()'; } /// if category mandatory, no empty choice /// no empty choice is default value set on ticket creation, else yes if (($ID || $values['itilcategories_id']) && $tt->isMandatoryField("itilcategories_id") && $ticket->fields["itilcategories_id"] > 0) { $opt['display_emptychoice'] = false; } switch ($ticket->fields["type"]) { case Ticket::INCIDENT_TYPE: $opt['condition'] .= "`is_incident`='1'"; break; case Ticket::DEMAND_TYPE: $opt['condition'] .= "`is_request`='1'"; break; default: break; } echo "<span id='show_category_by_type'>"; ITILCategory::dropdown($opt); echo "</span>"; } else { echo Dropdown::getDropdownName("glpi_itilcategories", $ticket->fields["itilcategories_id"]); } echo "</td>"; echo "</tr>"; if (!$ID) { echo "</table>"; $ticket->showActorsPartForm($ID, $values); echo "<table class='tab_cadre_fixe' id='mainformtable3'>"; } echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('status'); printf(__('%1$s%2$s'), __('Status'), $tt->getMandatoryMark('status')); echo $tt->getEndHiddenFieldText('status') . "</th>"; echo "<td width='{$colsize2}%'>"; echo $tt->getBeginHiddenFieldValue('status'); if ($canstatus) { Ticket::dropdownStatus(array('value' => $ticket->fields["status"], 'showtype' => 'allowed')); } else { echo Ticket::getStatus($ticket->fields["status"]); } echo $tt->getEndHiddenFieldValue('status', $ticket); echo "</td>"; echo "<th width='{$colsize3}%'>" . $tt->getBeginHiddenFieldText('requesttypes_id'); printf(__('%1$s%2$s'), __('Request source'), $tt->getMandatoryMark('requesttypes_id')); echo $tt->getEndHiddenFieldText('requesttypes_id') . "</th>"; echo "<td width='{$colsize4}%'>"; echo $tt->getBeginHiddenFieldValue('requesttypes_id'); if ($canupdate) { RequestType::dropdown(array('value' => $ticket->fields["requesttypes_id"])); } else { echo Dropdown::getDropdownName('glpi_requesttypes', $ticket->fields["requesttypes_id"]); } echo $tt->getEndHiddenFieldValue('requesttypes_id', $ticket); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . $tt->getBeginHiddenFieldText('urgency'); printf(__('%1$s%2$s'), __('Urgency'), $tt->getMandatoryMark('urgency')); echo $tt->getEndHiddenFieldText('urgency') . "</th>"; echo "<td>"; if ($canupdate && $canpriority || !$ID || $canupdate_descr) { // Only change during creation OR when allowed to change priority OR when user is the creator echo $tt->getBeginHiddenFieldValue('urgency'); $idurgency = Ticket::dropdownUrgency(array('value' => $ticket->fields["urgency"])); echo $tt->getEndHiddenFieldValue('urgency', $ticket); } else { $idurgency = "value_urgency" . mt_rand(); echo "<input id='{$idurgency}' type='hidden' name='urgency' value='" . $ticket->fields["urgency"] . "'>"; echo Ticket::getUrgencyName($ticket->fields["urgency"]); } echo "</td>"; // Display validation state echo "<th>"; if (!$ID) { echo $tt->getBeginHiddenFieldText('_add_validation'); printf(__('%1$s%2$s'), __('Approval request'), $tt->getMandatoryMark('_add_validation')); echo $tt->getEndHiddenFieldText('_add_validation'); } else { echo $tt->getBeginHiddenFieldText('global_validation'); _e('Approval'); echo $tt->getEndHiddenFieldText('global_validation'); } echo "</th>"; echo "<td>"; if (!$ID) { echo $tt->getBeginHiddenFieldValue('_add_validation'); $validation_right = ''; if ($values['type'] == Ticket::INCIDENT_TYPE && Session::haveRight('create_incident_validation', 1)) { $validation_right = 'validate_incident'; } if ($values['type'] == Ticket::DEMAND_TYPE && Session::haveRight('create_request_validation', 1)) { $validation_right = 'validate_request'; } if (!empty($validation_right)) { User::dropdown(array('name' => "_add_validation", 'entity' => $ticket->fields['entities_id'], 'right' => $validation_right, 'value' => $values['_add_validation'])); } echo $tt->getEndHiddenFieldValue('_add_validation', $ticket); if ($tt->isPredefinedField('global_validation')) { echo "<input type='hidden' name='global_validation' value='" . $tt->predefined['global_validation'] . "'>"; } } else { echo $tt->getBeginHiddenFieldValue('global_validation'); if ($canupdate) { TicketValidation::dropdownStatus('global_validation', array('global' => true, 'value' => $ticket->fields['global_validation'])); } else { echo TicketValidation::getStatus($ticket->fields['global_validation']); } echo $tt->getEndHiddenFieldValue('global_validation', $ticket); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . $tt->getBeginHiddenFieldText('impact'); printf(__('%1$s%2$s'), __('Impact'), $tt->getMandatoryMark('impact')); echo $tt->getEndHiddenFieldText('impact') . "</th>"; echo "<td>"; echo $tt->getBeginHiddenFieldValue('impact'); if ($canupdate) { $idimpact = Ticket::dropdownImpact(array('value' => $ticket->fields["impact"])); } else { $idimpact = "value_impact" . mt_rand(); echo "<input id='{$idimpact}' type='hidden' name='impact' value='" . $ticket->fields["impact"] . "'>"; echo Ticket::getImpactName($ticket->fields["impact"]); } echo $tt->getEndHiddenFieldValue('impact', $ticket); echo "</td>"; echo "<th rowspan='2'>" . $tt->getBeginHiddenFieldText('itemtype'); printf(__('%1$s%2$s'), __('Associated element'), $tt->getMandatoryMark('itemtype')); if ($ID && $canupdate) { echo " <img title='" . __s('Update') . "' alt='" . __s('Update') . "'\n onClick=\"Ext.get('tickethardwareselection{$ID}').setDisplayed('block')\"\n class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/showselect.png'>"; } echo $tt->getEndHiddenFieldText('itemtype'); echo "</th>"; echo "<td rowspan='2'>"; echo $tt->getBeginHiddenFieldValue('itemtype'); // Select hardware on creation or if have update right if ($canupdate || !$ID || $canupdate_descr) { if ($ID) { if ($ticket->fields['itemtype'] && ($item = getItemForItemtype($ticket->fields['itemtype'])) && $ticket->fields["items_id"]) { if ($item->can($ticket->fields["items_id"], 'r')) { printf(__('%1$s - %2$s'), $item->getTypeName(), $item->getLink(array('comments' => true))); } else { printf(__('%1$s - %2$s'), $item->getTypeName(), $item->getNameID()); } } } $dev_user_id = 0; $dev_itemtype = $ticket->fields["itemtype"]; $dev_items_id = $ticket->fields["items_id"]; if (!$ID) { $dev_user_id = $values['_users_id_requester']; $dev_itemtype = $values["itemtype"]; $dev_items_id = $values["items_id"]; } else { if (isset($ticket->users[CommonITILActor::REQUESTER]) && count($ticket->users[CommonITILActor::REQUESTER]) == 1) { foreach ($ticket->users[CommonITILActor::REQUESTER] as $user_id_single) { $dev_user_id = $user_id_single['users_id']; } } } if ($ID) { echo "<div id='tickethardwareselection{$ID}' style='display:none'>"; } if ($dev_user_id > 0) { Ticket::dropdownMyDevices($dev_user_id, $ticket->fields["entities_id"], $dev_itemtype, $dev_items_id); } Ticket::dropdownAllDevices("itemtype", $dev_itemtype, $dev_items_id, 1, $dev_user_id, $ticket->fields["entities_id"]); if ($ID) { echo "</div>"; } echo "<span id='item_ticket_selection_information'></span>"; } else { if ($ID && $ticket->fields['itemtype'] && ($item = getItemForItemtype($ticket->fields['itemtype']))) { $item->getFromDB($ticket->fields['items_id']); printf(__('%1$s - %2$s'), $item->getTypeName(), $item->getNameID()); } else { _e('General'); } } echo $tt->getEndHiddenFieldValue('itemtype', $ticket); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . sprintf(__('%1$s%2$s'), __('Priority'), $tt->getMandatoryMark('priority')) . "</th>"; echo "<td>"; $idajax = 'change_priority_' . mt_rand(); if ($canupdate && $canpriority && !$tt->isHiddenField('priority')) { $idpriority = Ticket::dropdownPriority(array('value' => $ticket->fields["priority"], 'withmajor' => true)); echo " <span id='{$idajax}' style='display:none'></span>"; } else { $idpriority = 0; echo "<span id='{$idajax}'>" . Ticket::getPriorityName($ticket->fields["priority"]) . "</span>"; } if ($canupdate || $canupdate_descr) { $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => $idpriority); Ajax::updateItemOnSelectEvent(array($idurgency, $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params); } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; // Need comment right to add a followup with the actiontime if (!$ID && Session::haveRight("global_add_followups", "1")) { echo "<th>" . $tt->getBeginHiddenFieldText('actiontime'); printf(__('%1$s%2$s'), __('Total duration'), $tt->getMandatoryMark('actiontime')); echo $tt->getEndHiddenFieldText('actiontime') . "</th>"; echo "<td>"; echo $tt->getBeginHiddenFieldValue('actiontime'); Dropdown::showTimeStamp('actiontime', array('value' => $values['actiontime'], 'addfirstminutes' => true)); echo $tt->getEndHiddenFieldValue('actiontime', $ticket); echo "</td>"; } else { echo "<th></th><td></td>"; } echo "<th>" . $tt->getBeginHiddenFieldText('locations_id'); printf(__('%1$s%2$s'), __('Location'), $tt->getMandatoryMark('locations_id')); echo $tt->getEndHiddenFieldText('locations_id') . "</th>"; echo "<td>"; echo $tt->getBeginHiddenFieldValue('locations_id'); if ($canupdate) { Location::dropdown(array('value' => $ticket->fields['locations_id'], 'entity' => $ticket->fields['entities_id'])); } else { echo Dropdown::getDropdownName('glpi_locations', $ticket->fields["locations_id"]); } echo $tt->getEndHiddenFieldValue('locations_id', $ticket); echo "</td></tr>"; echo "</table>"; if ($ID) { $values['canupdate'] = $canupdate; $ticket->showActorsPartForm($ID, $values); } $view_linked_tickets = $ID || $canupdate; echo "<table class='tab_cadre_fixe' id='mainformtable4'>"; echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('name'); printf(__('%1$s%2$s'), __('Title'), $tt->getMandatoryMark('name')); echo $tt->getEndHiddenFieldText('name') . "</th>"; echo "<td width='" . (100 - $colsize1) . "%' colspan='3'>"; if (!$ID || $canupdate_descr) { echo $tt->getBeginHiddenFieldValue('name'); $rand = mt_rand(); echo "<script type='text/javascript' >\n"; echo "function showName{$rand}() {\n"; echo "Ext.get('name{$rand}').setDisplayed('none');"; $params = array('maxlength' => 250, 'size' => 90, 'name' => 'name', 'data' => rawurlencode($ticket->fields["name"])); Ajax::updateItemJsCode("viewname{$rand}", $CFG_GLPI["root_doc"] . "/ajax/inputtext.php", $params); echo "}"; echo "</script>\n"; echo "<div id='name{$rand}' class='tracking left' onClick='showName{$rand}()'>\n"; if (empty($ticket->fields["name"])) { _e('Without title'); } else { echo $ticket->fields["name"]; } echo "</div>\n"; echo "<div id='viewname{$rand}'>\n"; echo "</div>\n"; if (!$ID) { echo "<script type='text/javascript' >\n\n showName{$rand}();\n </script>"; } echo $tt->getEndHiddenFieldValue('name', $ticket); } else { if (empty($ticket->fields["name"])) { _e('Without title'); } else { echo $ticket->fields["name"]; } } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('content'); printf(__('%1$s%2$s'), __('Description'), $tt->getMandatoryMark('content')); echo $tt->getEndHiddenFieldText('content') . "</th>"; echo "<td width='" . (100 - $colsize1) . "%' colspan='3'>"; // * Added by plugin surveyticket $psTicketTemplate = new PluginSurveyticketTicketTemplate(); $psSurvey = new PluginSurveyticketSurvey(); $plugin_surveyticket_surveys_id = 0; $a_tickettemplates = current($psTicketTemplate->find("`tickettemplates_id`='" . $tt->fields['id'] . "'\n AND `type`='" . $values['type'] . "'\n AND `is_central`='1'")); if (isset($a_tickettemplates['plugin_surveyticket_surveys_id'])) { $psSurvey = new PluginSurveyticketSurvey(); $psSurvey->getFromDB($a_tickettemplates['plugin_surveyticket_surveys_id']); if ($psSurvey->fields['is_active'] == 1) { $plugin_surveyticket_surveys_id = $a_tickettemplates['plugin_surveyticket_surveys_id']; $psSurvey = new PluginSurveyticketSurvey(); $psSurvey->startSurvey($plugin_surveyticket_surveys_id); } } else { // End of adding by plugin if (!$ID || $canupdate_descr) { // Admin =oui on autorise la modification de la description echo $tt->getBeginHiddenFieldValue('content'); $rand = mt_rand(); echo "<script type='text/javascript' >\n"; echo "function showDesc{$rand}() {\n"; echo "Ext.get('desc{$rand}').setDisplayed('none');"; $params = array('rows' => 6, 'cols' => 90, 'name' => 'content', 'data' => rawurlencode($ticket->fields["content"])); Ajax::updateItemJsCode("viewdesc{$rand}", $CFG_GLPI["root_doc"] . "/ajax/textarea.php", $params); echo "}"; echo "</script>\n"; echo "<div id='desc{$rand}' class='tracking' onClick='showDesc{$rand}()'>\n"; if (!empty($ticket->fields["content"])) { echo nl2br($ticket->fields["content"]); } else { _e('Empty description'); } echo "</div>\n"; echo "<div id='viewdesc{$rand}'></div>\n"; if (!$ID) { echo "<script type='text/javascript' >\n\n showDesc{$rand}();\n </script>"; } echo $tt->getEndHiddenFieldValue('content', $ticket); } else { echo nl2br($ticket->fields["content"]); } // * Added by plugin surveyticket } // End of adding by plugin echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; // Permit to add doc when creating a ticket if (!$ID) { echo "<th width='{$colsize1}%'>" . sprintf(__('File (%s)'), Document::getMaxUploadSize()); echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/aide.png' class='pointer' alt=\"" . __s('Help') . "\" onclick=\"window.open('" . $CFG_GLPI["root_doc"] . "/front/documenttype.list.php','Help','scrollbars=1,resizable=1,width=1000," . "height=800')\">"; echo " "; Ticket::showDocumentAddButton(); echo "</th>"; echo "<td width='{$colsize2}%'>"; echo "<div id='uploadfiles'><input type='file' name='filename[]' size='20'></div></td>"; } else { echo "<th colspan='2'>"; $docnb = Document_Item::countForItem($ticket); echo "<a href=\"" . $ticket->getLinkURL() . "&forcetab=Document_Item\$1\">"; //TRANS: %d is the document number echo sprintf(_n('%d associated document', '%d associated documents', $docnb), $docnb); echo "</a></th>"; } if ($view_linked_tickets) { echo "<th width='{$colsize3}%'>" . _n('Linked ticket', 'Linked tickets', 2); $rand_linked_ticket = mt_rand(); if ($canupdate) { echo " "; echo "<img onClick=\"Ext.get('linkedticket{$rand_linked_ticket}').setDisplayed('block')\"\n title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\"\n class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>"; } echo '</th>'; echo "<td width='{$colsize4}%'>"; if ($canupdate) { echo "<div style='display:none' id='linkedticket{$rand_linked_ticket}'>"; Ticket_Ticket::dropdownLinks('_link[link]', isset($values["_link"]) ? $values["_link"]['link'] : ''); printf(__('%1$s: %2$s'), __('Ticket'), __('ID')); echo "<input type='hidden' name='_link[tickets_id_1]' value='{$ID}'>\n"; echo "<input type='text' name='_link[tickets_id_2]'\n value='" . (isset($values["_link"]) ? $values["_link"]['tickets_id_2'] : '') . "'\n size='10'>\n"; echo " "; echo "</div>"; if (isset($values["_link"]) && !empty($values["_link"]['tickets_id_2'])) { echo "<script language='javascript'>Ext.get('linkedticket{$rand_linked_ticket}').\n setDisplayed('block');</script>"; } } Ticket_Ticket::displayLinkedTicketsTo($ID); echo "</td>"; } else { echo "<td></td>"; } echo "</tr>"; if ((!$ID || $canupdate || $canupdate_descr || Session::haveRight("assign_ticket", "1") || Session::haveRight("steal_ticket", "1")) && !$options['template_preview']) { echo "<tr class='tab_bg_1'>"; if ($ID) { if (Session::haveRight('delete_ticket', 1)) { echo "<td class='tab_bg_2 center' colspan='2'>"; if ($ticket->fields["is_deleted"] == 1) { echo "<input type='submit' class='submit' name='restore' value='" . _sx('button', 'Restore') . "'></td>"; } else { echo "<input type='submit' class='submit' name='update' value='" . _sx('button', 'Save') . "'></td>"; } echo "<td class='tab_bg_2 center' colspan='2'>"; if ($ticket->fields["is_deleted"] == 1) { echo "<input type='submit' class='submit' name='purge' value='" . _sx('button', 'Delete permanently') . "' " . Html::addConfirmationOnAction(__('Confirm the final deletion?')) . ">"; } else { echo "<input type='submit' class='submit' name='delete' value='" . _sx('button', 'Put in dustbin') . "'></td>"; } } else { echo "<td class='tab_bg_2 center' colspan='4'>"; echo "<input type='submit' class='submit' name='update' value='" . _sx('button', 'Save') . "'>"; } echo "<input type='hidden' name='_read_date_mod' value='" . $ticket->getField('date_mod') . "'>"; } else { echo "<td class='tab_bg_2 center' colspan='4'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; if ($tt->isField('id') && $tt->fields['id'] > 0) { echo "<input type='hidden' name='_tickettemplates_id' value='" . $tt->fields['id'] . "'>"; echo "<input type='hidden' name='_predefined_fields'\n value=\"" . Toolbox::prepareArrayForInput($predefined_fields) . "\">"; } } } echo "</table>"; echo "<input type='hidden' name='id' value='{$ID}'>"; echo "</div>"; if (!$options['template_preview']) { Html::closeForm(); $ticket->addDivForTabs(); } return true; }
/** * List all users of the current entity, with search criterias * for an authenticated user * * @param $params array of options (user, group, location, login, name) * @param $protocol the commonication protocol used * * @return array of hashtable **/ static function methodListUsers($params, $protocol) { global $DB, $CFG_GLPI; if (isset($params['help'])) { return array('count' => 'bool,optional', 'start' => 'integer,optional', 'limit' => 'integer,optional', 'order' => 'string,optional', 'entity' => 'integer,optional', 'parent' => 'bool,optional', 'user' => 'integer,optional', 'group' => 'integer,optional', 'location' => 'integer,optional', 'login' => 'string,optional', 'name' => 'string,optional', 'help' => 'bool,optional'); } if (!Session::getLoginUserID()) { return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); } $orders = array('id' => '`glpi_users`.`id`', 'name' => $_SESSION['glpinames_format'] == User::FIRSTNAME_BEFORE ? '`glpi_users`.`firstname`,`glpi_users`.`realname`' : '`glpi_users`.`realname`,`glpi_users`.`firstname`', 'login' => '`glpi_users`.`name`'); $parent = 1; if (isset($params['parent'])) { $parent = $params['parent'] ? 1 : 0; } if (isset($params['entity'])) { if (!Session::haveAccessToEntity($params['entity'])) { return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', 'entity'); } $ent = $params['entity']; } else { $ent = ''; } $query = "LEFT JOIN `glpi_profiles_users`\n ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n LEFT JOIN `glpi_useremails`\n ON (`glpi_users`.`id` = `glpi_useremails`.`users_id`\n AND `glpi_useremails`.`is_default`)\n WHERE `glpi_users`.`is_deleted` = '0'\n AND `glpi_users`.`is_active` = '1' " . getEntitiesRestrictRequest('AND', "glpi_profiles_users", '', $ent, $parent); if (isset($params['user']) && is_numeric($params['user'])) { $query .= " AND `glpi_users`.`id` = '" . $params['user'] . "'"; } if (isset($params['group']) && is_numeric($params['group'])) { $query .= " AND `glpi_users`.`id` IN (SELECT `users_id`\n FROM `glpi_groups_users`\n WHERE `groups_id` = '" . $params['group'] . "')"; } if (isset($params['location']) && is_numeric($params['location'])) { $query .= " AND `glpi_users`.`locations_id` = '" . $params['location'] . "'"; } if (isset($params['login'])) { $query .= " AND `glpi_users`.`name` LIKE '" . addslashes($params['login']) . "'"; } if (isset($params['name'])) { if ($_SESSION['glpinames_format'] == User::FIRSTNAME_BEFORE) { $query .= " AND CONCAT(`glpi_users`.`firstname`,' ',`glpi_users`.`realname`)"; } else { $query .= " AND CONCAT(`glpi_users`.`realname`,' ',`glpi_users`.`firstname`)"; } $query .= " LIKE '" . addslashes($params['name']) . "'"; } $resp = array(); if (isset($params['count'])) { $query = "SELECT COUNT(DISTINCT `glpi_users`.`id`) AS count\n FROM `glpi_users`\n {$query}"; $resp = $DB->request($query)->next(); } else { $start = 0; $limit = $_SESSION['glpilist_limit']; if (isset($params['limit']) && is_numeric($params['limit'])) { $limit = $params['limit']; } if (isset($params['start']) && is_numeric($params['start'])) { $start = $params['start']; } if (isset($params['order']) && isset($orders[$params['order']])) { $order = $orders[$params['order']]; } else { $order = $orders['id']; } $query = "SELECT DISTINCT(`glpi_users`.`id`) AS id,\n `glpi_users`.`name`, `firstname`,\n `realname`, `email`, `phone`, `glpi_users`.`locations_id`,\n `glpi_locations`.`completename` AS locations_name\n FROM `glpi_users`\n LEFT JOIN `glpi_locations`\n ON (`glpi_users`.`locations_id` = `glpi_locations`.`id`)\n {$query}\n ORDER BY {$order}\n LIMIT {$start},{$limit}"; foreach ($DB->request($query) as $data) { $data['displayname'] = formatUserName(0, $data['name'], $data['realname'], $data['firstname']); $resp[] = $data; } } return $resp; }
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'; Html::header(__('Transfer'), '', 'admin', 'rule', 'transfer'); $transfer = new Transfer(); $transfer->checkGlobal(READ); if (isset($_POST['transfer'])) { if (isset($_SESSION['glpitransfer_list'])) { if (!Session::haveAccessToEntity($_POST['to_entity'])) { Html::displayRightError(); } $transfer->moveItems($_SESSION['glpitransfer_list'], $_POST['to_entity'], $_POST); unset($_SESSION['glpitransfer_list']); echo "<div class='b center'>" . __('Operation successful') . "<br>"; echo "<a href='central.php'>" . __('Back') . "</a></div>"; Html::footer(); exit; } } else { if (isset($_POST['clear'])) { unset($_SESSION['glpitransfer_list']); echo "<div class='b center'>" . __('Operation successful') . "<br>"; echo "<a href='central.php'>" . __('Back') . "</a></div>"; echo "</div>";
/** * Is the current user have right to edit the current task ? * * @return boolean **/ function canUpdateItem() { if (!Session::haveAccessToEntity($this->getEntityID())) { return false; } $project = new Project(); if ($project->getFromDB($this->fields['projects_id'])) { return Session::haveRight(self::$rightname, UPDATE) || Session::haveRight('projecttask', ProjectTask::UPDATEMY) && ($this->fields["users_id"] === Session::getLoginUserID() || $this->isInTheTeam()); } return false; }
/** * @param $item CommonDBTM object **/ static function showActivationFormForItem(CommonDBTM $item) { if (!self::canUpdate()) { return false; } if ($item->getID()) { // Recursive type case => need entity right if ($item->isRecursive()) { if (!Session::haveAccessToEntity($item->fields["entities_id"])) { return false; } } } else { return false; } $ri = new self(); echo "<div>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>" . __('Reserve an item') . "</th></tr>"; echo "<tr class='tab_bg_1'>"; if ($ri->getFromDBbyItem($item->getType(), $item->getID())) { echo "<td class='center'>"; //Switch reservation state if ($ri->fields["is_active"]) { Html::showSimpleForm(static::getFormURL(), 'update', __('Make unavailable'), array('id' => $ri->fields['id'], 'is_active' => 0)); } else { Html::showSimpleForm(static::getFormURL(), 'update', __('Make available'), array('id' => $ri->fields['id'], 'is_active' => 1)); } echo '</td><td>'; Html::showSimpleForm(static::getFormURL(), 'purge', __('Prohibit reservations'), array('id' => $ri->fields['id']), '', '', array(__('Are you sure you want to return this non-reservable item?'), __('That will remove all the reservations in progress.'))); echo "</td>"; } else { echo "<td class='center'>"; Html::showSimpleForm(static::getFormURL(), 'add', __('Authorize reservations'), array('items_id' => $item->getID(), 'itemtype' => $item->getType(), 'entities_id' => $item->getEntityID(), 'is_recursive' => $item->isRecursive())); echo "</td>"; } echo "</tr></table>"; echo "</div>"; }
/** * Do automatic transfer if option is enable * * @param $line_links array : data from glpi_plugin_ocsinventoryng_ocslinks table * @return nothing * @internal param array $line_ocs : data from ocs tables * */ static function transferComputer($line_links) { global $DB, $CFG_GLPI; $ocsClient = self::getDBocs($line_links["plugin_ocsinventoryng_ocsservers_id"]); $cfg_ocs = self::getConfig($line_links["plugin_ocsinventoryng_ocsservers_id"]); $ocsComputer = $ocsClient->getComputer($line_links["ocsid"]); $locations_id = 0; $contact = isset($ocsComputer['META']["USERID"]) ? $ocsComputer['META']["USERID"] : ""; if (!empty($contact)) { $query = "SELECT `id`\n FROM `glpi_users`\n WHERE `name` = '" . $contact . "';"; $result = $DB->query($query); if ($DB->numrows($result) == 1) { $user_id = $DB->result($result, 0, 0); $user = new User(); $user->getFromDB($user_id); $locations_id = $user->fields["locations_id"]; } } // Get all rules for the current plugin_ocsinventoryng_ocsservers_id $rule = new RuleImportEntityCollection(); $data = array(); $data = $rule->processAllRules(array('ocsservers_id' => $line_links["plugin_ocsinventoryng_ocsservers_id"], '_source' => 'ocsinventoryng', 'locations_id' => $locations_id), array('locations_id' => $locations_id), array('ocsid' => $line_links["ocsid"])); // If entity is changing move items to the new entities_id if (isset($data['entities_id']) && $data['entities_id'] > -1 && $data['entities_id'] != $line_links['entities_id']) { if (!isCommandLine() && !Session::haveAccessToEntity($data['entities_id'])) { Html::displayRightError(); } $transfer = new Transfer(); $transfer->getFromDB($CFG_GLPI['transfers_id_auto']); $item_to_transfer = array("Computer" => array($line_links['computers_id'] => $line_links['computers_id'])); $transfer->moveItems($item_to_transfer, $data['entities_id'], $transfer->fields); } //If location is update by a rule self::updateLocation($line_links, $data, $cfg_ocs); }