Get default email for user. If no default email get first one
static public getDefaultForUser ( $users_id ) : default | ||
$users_id | user ID | |
Résultat | default | email, empty if no email set |
function getUserCommentAddress() { global $DB; $query = "SELECT DISTINCT `glpi_users`.`id` AS id\n FROM `glpi_plugin_ideabox_comments`\n LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_plugin_ideabox_comments`.`users_id`)\n WHERE `glpi_plugin_ideabox_comments`.`plugin_ideabox_ideaboxes_id` = '" . $this->obj->fields["id"] . "'"; foreach ($DB->request($query) as $data) { $data['email'] = UserEmail::getDefaultForUser($data['id']); $this->addToAddressesList($data); } }
/** * Get the default email of the user * * @return default user email **/ function getDefaultEmail() { if (!isset($this->fields['id'])) { return ''; } return UserEmail::getDefaultForUser($this->fields['id']); }
/** * Print the helpdesk form * * @param $ID integer ID of the user who want to display the Helpdesk * @param $ticket_template boolean ticket template for preview : false if not used for preview * (false by default) * * @return nothing (print the helpdesk) **/ function showFormHelpdesk($ID, $ticket_template = false) { global $DB, $CFG_GLPI; if (!self::canCreate()) { return false; } if (!$ticket_template && Session::haveRightsOr('ticketvalidation', TicketValidation::getValidateRights())) { $opt = array(); $opt['reset'] = 'reset'; $opt['criteria'][0]['field'] = 55; // validation status $opt['criteria'][0]['searchtype'] = 'equals'; $opt['criteria'][0]['value'] = CommonITILValidation::WAITING; $opt['criteria'][0]['link'] = 'AND'; $opt['criteria'][1]['field'] = 59; // validation aprobator $opt['criteria'][1]['searchtype'] = 'equals'; $opt['criteria'][1]['value'] = Session::getLoginUserID(); $opt['criteria'][1]['link'] = 'AND'; $url_validate = $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($opt, '&'); if (TicketValidation::getNumberToValidate(Session::getLoginUserID()) > 0) { echo "<a href='{$url_validate}' title=\"" . __s('Ticket waiting for your approval') . "\"\n alt=\"" . __s('Ticket waiting for your approval') . "\">" . __('Tickets awaiting approval') . "</a><br><br>"; } } $email = UserEmail::getDefaultForUser($ID); $default_use_notif = Entity::getUsedConfig('is_notif_enable_default', $_SESSION['glpiactive_entity'], '', 1); // Set default values... $default_values = array('_users_id_requester_notif' => array('use_notification' => $email == "" ? 0 : $default_use_notif), 'nodelegate' => 1, '_users_id_requester' => 0, '_users_id_observer' => array(0), '_users_id_observer_notif' => array('use_notification' => $default_use_notif), 'name' => '', 'content' => '', 'itilcategories_id' => 0, 'locations_id' => 0, 'urgency' => 3, 'items_id' => 0, 'entities_id' => $_SESSION['glpiactive_entity'], 'plan' => array(), 'global_validation' => CommonITILValidation::NONE, '_add_validation' => 0, 'type' => Entity::getUsedConfig('tickettype', $_SESSION['glpiactive_entity'], '', Ticket::INCIDENT_TYPE), '_right' => "id", '_filename' => array(), '_tag_filename' => array()); // Get default values from posted values on reload form if (!$ticket_template) { if (isset($_POST)) { $values = Html::cleanPostForTextArea($_POST); } } // 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; } } } // 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; } } } if (!$ticket_template) { echo "<form method='post' name='helpdeskform' action='" . $CFG_GLPI["root_doc"] . "/front/tracking.injector.php' enctype='multipart/form-data'>"; } $delegating = User::getDelegateGroupsForUser($values['entities_id']); if (count($delegating)) { echo "<div class='center'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>" . __('This ticket concerns me') . " "; $rand = Dropdown::showYesNo("nodelegate", $values['nodelegate']); $params = array('nodelegate' => '__VALUE__', 'rand' => $rand, 'right' => "delegate", '_users_id_requester' => $values['_users_id_requester'], '_users_id_requester_notif' => $values['_users_id_requester_notif'], 'use_notification' => $values['_users_id_requester_notif']['use_notification'], 'entity_restrict' => $_SESSION["glpiactive_entity"]); Ajax::UpdateItemOnSelectEvent("dropdown_nodelegate" . $rand, "show_result" . $rand, $CFG_GLPI["root_doc"] . "/ajax/dropdownDelegationUsers.php", $params); $class = 'right'; if ($CFG_GLPI['use_check_pref'] && $values['nodelegate']) { echo "</th><th>" . __('Check your personnal information'); $class = 'center'; } echo "</th></tr>"; echo "<tr class='tab_bg_1'><td colspan='2' class='" . $class . "'>"; echo "<div id='show_result{$rand}'>"; $self = new self(); if ($values["_users_id_requester"] == 0) { $values['_users_id_requester'] = Session::getLoginUserID(); } else { $values['_right'] = "delegate"; } $self->showActorAddFormOnCreate(CommonITILActor::REQUESTER, $values); echo "</div>"; if ($CFG_GLPI['use_check_pref'] && $values['nodelegate']) { echo "</td><td class='center'>"; User::showPersonalInformation(Session::getLoginUserID()); } echo "</td></tr>"; echo "</table></div>"; echo "<input type='hidden' name='_users_id_recipient' value='" . Session::getLoginUserID() . "'>"; } else { // User as requester $values['_users_id_requester'] = Session::getLoginUserID(); if ($CFG_GLPI['use_check_pref']) { echo "<div class='center'><table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Check your personnal information') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; User::showPersonalInformation(Session::getLoginUserID()); echo "</td></tr>"; echo "</table></div>"; } } echo "<input type='hidden' name='_from_helpdesk' value='1'>"; echo "<input type='hidden' name='requesttypes_id' value='" . RequestType::getDefault('helpdesk') . "'>"; // Load ticket template if available : $tt = $this->getTicketTemplateToUse($ticket_template, $values['type'], $values['itilcategories_id'], $_SESSION["glpiactive_entity"]); // 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 $predefined_fields = array(); if (isset($tt->predefined) && count($tt->predefined)) { foreach ($tt->predefined as $predeffield => $predefvalue) { if (isset($values[$predeffield]) && 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()) { $values[$predeffield] = $predefvalue; $predefined_fields[$predeffield] = $predefvalue; } } else { // Not defined options set as hidden field echo "<input type='hidden' name='{$predeffield}' value='{$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]; } } } } if ($CFG_GLPI['urgency_mask'] == 1 << 3 || $tt->isHiddenField('urgency')) { // Dont show dropdown if only 1 value enabled or field is hidden echo "<input type='hidden' name='urgency' value='" . $values['urgency'] . "'>"; } // Display predefined fields if hidden if ($tt->isHiddenField('items_id')) { if (!empty($values['items_id'])) { foreach ($values['items_id'] as $itemtype => $items) { foreach ($items as $items_id) { echo "<input type='hidden' name='items_id[{$itemtype}][{$items_id}]' value='{$items_id}'>"; } } } } if ($tt->isHiddenField('locations_id')) { echo "<input type='hidden' name='locations_id' value='" . $values['locations_id'] . "'>"; } echo "<input type='hidden' name='entities_id' value='" . $_SESSION["glpiactive_entity"] . "'>"; echo "<div class='center'><table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Describe the incident or request') . "</th><th>"; if (Session::isMultiEntitiesMode()) { echo "(" . Dropdown::getDropdownName("glpi_entities", $_SESSION["glpiactive_entity"]) . ")"; } echo "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Type'), $tt->getMandatoryMark('type')) . "</td>"; echo "<td>"; self::dropdownType('type', array('value' => $values['type'], 'on_change' => 'this.form.submit()')); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Category'), $tt->getMandatoryMark('itilcategories_id')) . "</td>"; echo "<td>"; $condition = "`is_helpdeskvisible`='1'"; switch ($values['type']) { case self::DEMAND_TYPE: $condition .= " AND `is_request`='1'"; break; default: // self::INCIDENT_TYPE : $condition .= " AND `is_incident`='1'"; } $opt = array('value' => $values['itilcategories_id'], 'condition' => $condition, 'entity' => $_SESSION["glpiactive_entity"], 'on_change' => 'this.form.submit()'); if ($values['itilcategories_id'] && $tt->isMandatoryField("itilcategories_id")) { $opt['display_emptychoice'] = false; } ITILCategory::dropdown($opt); echo "</td></tr>"; if ($CFG_GLPI['urgency_mask'] != 1 << 3) { if (!$tt->isHiddenField('urgency')) { echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Urgency'), $tt->getMandatoryMark('urgency')) . "</td>"; echo "<td>"; self::dropdownUrgency(array('value' => $values["urgency"])); echo "</td></tr>"; } } if (empty($delegating) && NotificationTargetTicket::isAuthorMailingActivatedForHelpdesk()) { echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Inform me about the actions taken') . "</td>"; echo "<td>"; if ($values["_users_id_requester"] == 0) { $values['_users_id_requester'] = Session::getLoginUserID(); } $_POST['value'] = $values['_users_id_requester']; $_POST['field'] = '_users_id_requester_notif'; $_POST['use_notification'] = $values['_users_id_requester_notif']['use_notification']; include GLPI_ROOT . "/ajax/uemailUpdate.php"; echo "</td></tr>"; } if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] != 0 && count($_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) { if (!$tt->isHiddenField('itemtype')) { echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Hardware type'), $tt->getMandatoryMark('items_id')) . "</td>"; echo "<td>"; $values['_canupdate'] = Session::haveRight('ticket', CREATE); Item_Ticket::itemAddForm($this, $values); echo "</td></tr>"; } } if (!$tt->isHiddenField('locations_id')) { echo "<tr class='tab_bg_1'><td>"; printf(__('%1$s%2$s'), __('Location'), $tt->getMandatoryMark('locations_id')); echo "</td><td>"; Location::dropdown(array('value' => $values["locations_id"])); echo "</td></tr>"; } if (!$tt->isHiddenField('_users_id_observer') || $tt->isPredefinedField('_users_id_observer')) { echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), _n('Watcher', 'Watchers', 2), $tt->getMandatoryMark('_users_id_observer')) . "</td>"; echo "<td>"; $values['_right'] = "groups"; if (!$tt->isHiddenField('_users_id_observer')) { // Observer if ($tt->isPredefinedField('_users_id_observer') && !is_array($values['_users_id_observer'])) { //convert predefined value to array $values['_users_id_observer'] = array($values['_users_id_observer']); $values['_users_id_observer_notif']['use_notification'] = array($values['_users_id_observer_notif']['use_notification']); // add new line to permit adding more observers $values['_users_id_observer'][1] = 0; $values['_users_id_observer_notif']['use_notification'][1] = 1; } echo "<div class='actor_single first-actor'>"; if (isset($values['_users_id_observer'])) { $observers = $values['_users_id_observer']; foreach ($observers as $index_observer => $observer) { $options = array_merge($values, array('_user_index' => $index_observer)); self::showFormHelpdeskObserver($options); } } echo "</div>"; } else { // predefined value if (isset($values["_users_id_observer"]) && $values["_users_id_observer"]) { echo self::getActorIcon('user', CommonITILActor::OBSERVER) . " "; echo Dropdown::getDropdownName("glpi_users", $values["_users_id_observer"]); echo "<input type='hidden' name='_users_id_observer' value=\"" . $values["_users_id_observer"] . "\">"; } } echo "</td></tr>"; } if (!$tt->isHiddenField('name') || $tt->isPredefinedField('name')) { echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Title'), $tt->getMandatoryMark('name')) . "<td>"; if (!$tt->isHiddenField('name')) { echo "<input type='text' maxlength='250' size='80' name='name'\n value=\"" . $values['name'] . "\">"; } else { echo $values['name']; echo "<input type='hidden' name='name' value=\"" . $values['name'] . "\">"; } echo "</td></tr>"; } if (!$tt->isHiddenField('content') || $tt->isPredefinedField('content')) { echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Description'), $tt->getMandatoryMark('content')) . "</td><td>"; $rand = mt_rand(); $rand_text = mt_rand(); $cols = 90; $rows = 6; $content_id = "content{$rand}"; if ($CFG_GLPI["use_rich_text"]) { $values["content"] = $this->setRichTextContent($content_id, $values["content"], $rand); $cols = 100; $rows = 10; } else { $values["content"] = $this->setSimpleTextContent($values["content"]); } echo "<div id='content{$rand_text}'>"; echo "<textarea id='{$content_id}' name='content' cols='{$cols}' rows='{$rows}'>" . $values['content'] . "</textarea></div>"; echo "</td></tr>"; } // File upload system $width = '100%'; if ($CFG_GLPI['use_rich_text']) { $width = '50%'; } echo "<tr class='tab_bg_1'>"; echo "<td class='top'>" . sprintf(__('%1$s (%2$s)'), __('File'), Document::getMaxUploadSize()); DocumentType::showAvailableTypesLink(); echo "</td>"; echo "<td class='top'>"; echo "<div id='fileupload_info'></div>"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4'>"; echo "<table width='100%'><tr>"; echo "<td width='{$width} '>"; echo Html::file(array('multiple' => true, 'values' => array('filename' => $values['_filename'], 'tag' => $values['_tag_filename']))); echo "</td>"; if ($CFG_GLPI['use_rich_text']) { echo "<td width='{$width} '>"; if (!isset($rand)) { $rand = mt_rand(); } echo Html::initImagePasteSystem($content_id, $rand); echo "</td>"; } echo "</tr></table>"; echo "</td>"; echo "</tr>"; if (!$ticket_template) { echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' class='center'>"; 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 "<input type='submit' name='add' value=\"" . __s('Submit message') . "\" class='submit'>"; echo "</td></tr>"; } echo "</table></div>"; if (!$ticket_template) { Html::closeForm(); } }
/** * clone of function Ticket::showFormHelpdesk() */ static function getHelpdesk($ID = 0, $ticket_template = false) { global $DB, $CFG_GLPI; // * Added by plugin survey ticket $ticket = new Ticket(); // * End of adding if (!Session::haveRight("create_ticket", "1")) { return false; } if (!$ticket_template && (Session::haveRight('validate_incident', 1) || Session::haveRight('validate_request', 1))) { $opt = array(); $opt['reset'] = 'reset'; $opt['field'][0] = 55; // validation status $opt['searchtype'][0] = 'equals'; $opt['contains'][0] = 'waiting'; $opt['link'][0] = 'AND'; $opt['field'][1] = 59; // validation aprobator $opt['searchtype'][1] = 'equals'; $opt['contains'][1] = Session::getLoginUserID(); $opt['link'][1] = 'AND'; $url_validate = $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($opt, '&'); if (TicketValidation::getNumberTicketsToValidate(Session::getLoginUserID()) > 0) { echo "<a href='{$url_validate}' title=\"" . __s('Ticket waiting for your approval') . "\"\n alt=\"" . __s('Ticket waiting for your approval') . "\">" . __('Tickets awaiting approval') . "</a><br><br>"; } } $query = "SELECT `realname`, `firstname`, `name`\n FROM `glpi_users`\n WHERE `id` = '{$ID}'"; $result = $DB->query($query); $email = UserEmail::getDefaultForUser($ID); // Set default values... $default_values = array('_users_id_requester_notif' => array('use_notification' => $email == "" ? 0 : 1), 'nodelegate' => 1, '_users_id_requester' => 0, 'name' => '', 'content' => '', 'itilcategories_id' => 0, 'locations_id' => 0, 'urgency' => 3, 'itemtype' => '', 'items_id' => 0, 'entities_id' => $_SESSION['glpiactive_entity'], 'plan' => array(), 'global_validation' => 'none', 'due_date' => 'NULL', 'slas_id' => 0, '_add_validation' => 0, 'type' => Entity::getUsedConfig('tickettype', $_SESSION['glpiactive_entity'], '', Ticket::INCIDENT_TYPE), '_right' => "id"); // Get default values from posted values on reload form if (!$ticket_template) { 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; } } } if (!$ticket_template) { echo "<form method='post' name='helpdeskform' action='" . $CFG_GLPI["root_doc"] . "/front/tracking.injector.php' enctype='multipart/form-data'>"; } $delegating = User::getDelegateGroupsForUser($values['entities_id']); if (count($delegating)) { echo "<div class='center'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>" . __('This ticket concerns me') . " "; $rand = Dropdown::showYesNo("nodelegate", $values['nodelegate']); $params = array('nodelegate' => '__VALUE__', 'rand' => $rand, 'right' => "delegate", '_users_id_requester' => $values['_users_id_requester'], '_users_id_requester_notif' => $values['_users_id_requester_notif'], 'use_notification' => $values['_users_id_requester_notif']['use_notification'], 'entity_restrict' => $_SESSION["glpiactive_entity"]); Ajax::UpdateItemOnSelectEvent("dropdown_nodelegate" . $rand, "show_result" . $rand, $CFG_GLPI["root_doc"] . "/ajax/dropdownDelegationUsers.php", $params); if ($CFG_GLPI['use_check_pref'] && $values['nodelegate']) { echo "</th><th>" . __('Check your personnal information'); } echo "</th></tr>"; echo "<tr class='tab_bg_1'><td colspan='2' class='center'>"; echo "<div id='show_result{$rand}'>"; $self = new Ticket(); if ($values["_users_id_requester"] == 0) { $values['_users_id_requester'] = Session::getLoginUserID(); } else { $values['_right'] = "delegate"; } $self->showActorAddFormOnCreate(CommonITILActor::REQUESTER, $values); echo "</div>"; if ($CFG_GLPI['use_check_pref'] && $values['nodelegate']) { echo "</td><td class='center'>"; User::showPersonalInformation(Session::getLoginUserID()); } echo "</td></tr>"; echo "</table></div>"; echo "<input type='hidden' name='_users_id_recipient' value='" . Session::getLoginUserID() . "'>"; } else { // User as requester $values['_users_id_requester'] = Session::getLoginUserID(); if ($CFG_GLPI['use_check_pref']) { echo "<div class='center'><table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Check your personnal information') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; User::showPersonalInformation(Session::getLoginUserID()); echo "</td></tr>"; echo "</table></div>"; } } echo "<input type='hidden' name='_from_helpdesk' value='1'>"; echo "<input type='hidden' name='requesttypes_id' value='" . RequestType::getDefault('helpdesk') . "'>"; // Load ticket template if available : $tt = $ticket->getTicketTemplateToUse($ticket_template, $values['type'], $values['itilcategories_id'], $_SESSION["glpiactive_entity"]); // 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 $predefined_fields = array(); if (isset($tt->predefined) && count($tt->predefined)) { foreach ($tt->predefined as $predeffield => $predefvalue) { if (isset($values[$predeffield]) && 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()) { $values[$predeffield] = $predefvalue; $predefined_fields[$predeffield] = $predefvalue; } } else { // Not defined options set as hidden field echo "<input type='hidden' name='{$predeffield}' value='{$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]; } } } } if ($CFG_GLPI['urgency_mask'] == 1 << 3 || $tt->isHiddenField('urgency')) { // Dont show dropdown if only 1 value enabled or field is hidden echo "<input type='hidden' name='urgency' value='" . $values['urgency'] . "'>"; } // Display predefined fields if hidden if ($tt->isHiddenField('itemtype')) { echo "<input type='hidden' name='itemtype' value='" . $values['itemtype'] . "'>"; echo "<input type='hidden' name='items_id' value='" . $values['items_id'] . "'>"; } if ($tt->isHiddenField('locations_id')) { echo "<input type='hidden' name='locations_id' value='" . $values['locations_id'] . "'>"; } echo "<input type='hidden' name='entities_id' value='" . $_SESSION["glpiactive_entity"] . "'>"; echo "<div class='center'><table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Describe the incident or request') . "</th><th>"; if (Session::isMultiEntitiesMode()) { echo "(" . Dropdown::getDropdownName("glpi_entities", $_SESSION["glpiactive_entity"]) . ")"; } echo "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Type'), $tt->getMandatoryMark('type')) . "</td>"; echo "<td>"; Ticket::dropdownType('type', array('value' => $values['type'], 'on_change' => 'submit()')); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Category'), $tt->getMandatoryMark('itilcategories_id')) . "</td>"; echo "<td>"; $condition = "`is_helpdeskvisible`='1'"; switch ($values['type']) { case Ticket::DEMAND_TYPE: $condition .= " AND `is_request`='1'"; break; default: // Ticket::INCIDENT_TYPE : $condition .= " AND `is_incident`='1'"; } $opt = array('value' => $values['itilcategories_id'], 'condition' => $condition, 'on_change' => 'submit()'); if ($values['itilcategories_id'] && $tt->isMandatoryField("itilcategories_id")) { $opt['display_emptychoice'] = false; } ITILCategory::dropdown($opt); echo "</td></tr>"; if ($CFG_GLPI['urgency_mask'] != 1 << 3) { if (!$tt->isHiddenField('urgency')) { echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Urgency'), $tt->getMandatoryMark('urgency')) . "</td>"; echo "<td>"; Ticket::dropdownUrgency(array('value' => $values["urgency"])); echo "</td></tr>"; } } if (empty($delegating) && NotificationTargetTicket::isAuthorMailingActivatedForHelpdesk()) { echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Inform me about the actions taken') . "</td>"; echo "<td>"; if ($values["_users_id_requester"] == 0) { $values['_users_id_requester'] = Session::getLoginUserID(); } $_POST['value'] = $values['_users_id_requester']; $_POST['field'] = '_users_id_requester_notif'; $_POST['use_notification'] = $values['_users_id_requester_notif']['use_notification']; include GLPI_ROOT . "/ajax/uemailUpdate.php"; echo "</td></tr>"; } if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] != 0) { if (!$tt->isHiddenField('itemtype')) { echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Hardware type'), $tt->getMandatoryMark('itemtype')) . "</td>"; echo "<td>"; Ticket::dropdownMyDevices($values['_users_id_requester'], $_SESSION["glpiactive_entity"], $values['itemtype'], $values['items_id']); Ticket::dropdownAllDevices("itemtype", $values['itemtype'], $values['items_id'], 0, $values['_users_id_requester'], $_SESSION["glpiactive_entity"]); echo "<span id='item_ticket_selection_information'></span>"; echo "</td></tr>"; } } if (!$tt->isHiddenField('locations_id')) { echo "<tr class='tab_bg_1'><td>"; printf(__('%1$s%2$s'), __('Location'), $tt->getMandatoryMark('locations_id')); echo "</td><td>"; Location::dropdown(array('value' => $values["locations_id"])); echo "</td></tr>"; } if (!$tt->isHiddenField('name') || $tt->isPredefinedField('name')) { echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Title'), $tt->getMandatoryMark('name')) . "</td>"; echo "<td><input type='text' maxlength='250' size='80' name='name'\n value=\"" . $values['name'] . "\"></td></tr>"; } if (!$tt->isHiddenField('content') || $tt->isPredefinedField('content')) { echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Description'), $tt->getMandatoryMark('content')) . "</td>"; // * Changed by plugin surveyticket // * 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_helpdesk`='1'")); if (isset($a_tickettemplates['plugin_surveyticket_surveys_id'])) { echo "<td>"; $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 { echo "<td><textarea name='content' cols='80' rows='14'>" . $values['content'] . "</textarea>"; } // * End of change echo "</td></tr>"; } echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s (%2$s)'), __('File'), 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(60); echo "</td>"; echo "<td><div id='uploadfiles'><input type='file' name='filename[]' value='' size='60'></div>"; echo "</td></tr>"; if (!$ticket_template) { echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' class='center'>"; 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 "<input type='submit' name='add' value=\"" . __s('Submit message') . "\" class='submit'>"; echo "</td></tr>"; } echo "</table></div>"; if (!$ticket_template) { Html::closeForm(); } }
/** * Add new mail with lang to current email array * * @param $data array of data (mail, lang[, id for user]) **/ function addToAddressesList(array $data) { global $CFG_GLPI; // No email set : get default for user if (!isset($data['email']) && isset($data['users_id'])) { $data['email'] = UserEmail::getDefaultForUser($data['users_id']); } $new_mail = trim(Toolbox::strtolower($data['email'])); $new_lang = ''; // Default USER TYPE is ANONYMOUS $notificationoption = array('usertype' => self::ANONYMOUS_USER); if (isset($data['language'])) { $new_lang = trim($data['language']); } $username = ''; if (isset($data['name']) && !empty($data['name'])) { $username = $data['name']; } if (isset($data['users_id']) && $data['users_id'] > 0) { $user = new User(); if (!$user->getFromDB($data['users_id']) || $user->getField('is_deleted') == 1 || $user->getField('is_active') == 0 || !is_null($user->getField('begin_date')) && $user->getField('begin_date') > $_SESSION["glpi_currenttime"] || !is_null($user->getField('end_date')) && $user->getField('end_date') < $_SESSION["glpi_currenttime"]) { // unknown, deleted or disabled user return false; } $filt = getEntitiesRestrictRequest('AND', 'glpi_profiles_users', '', $this->getEntity(), true); $prof = Profile_User::getUserProfiles($data['users_id'], $filt); if (!count($prof)) { // No right on the entity of the object return false; } if (empty($username)) { $username = formatUserName(0, $user->getField('name'), $user->getField('realname'), $user->getField('firstname'), 0, 0, true); } // It is a GLPI user : $notificationoption['usertype'] = self::GLPI_USER; if (Auth::isAlternateAuth($user->fields['authtype']) || $user->fields['authtype'] == Auth::NOT_YET_AUTHENTIFIED && Auth::isAlternateAuth(Auth::checkAlternateAuthSystems())) { $notificationoption['usertype'] = self::EXTERNAL_USER; } } // Pass user type as argument ? forced for specific cases if (isset($data['usertype'])) { $notificationoption['usertype'] = $data['usertype']; } $notificationoption = array_merge($this->addAdditionnalUserInfo($data), $notificationoption); if (!empty($new_mail)) { if (NotificationMail::isUserAddressValid($new_mail) && !isset($this->target[$new_mail])) { $param = array('language' => empty($new_lang) ? $CFG_GLPI["language"] : $new_lang, 'email' => $new_mail, 'additionnaloption' => $notificationoption, 'username' => $username); if (isset($data['users_id']) && $data['users_id']) { $param['users_id'] = $data['users_id']; } $this->target[$new_mail] = $param; } } }
/** * This method try to identicate a user * * @param $params array of options ignored * @param $protocol the communication protocol used * * @return an response ready to be encode * => fields of glpi_users **/ static function methodGetMyInfo($params, $protocol) { if (isset($params['help'])) { return array('help' => 'bool,optional', 'id2name' => 'bool,optional'); } if (!Session::getLoginUserID()) { return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); } $user = new User(); if ($user->getFromDB($uid = Session::getLoginUserID())) { $resp = $user->fields; $resp['email'] = UserEmail::getDefaultForUser($uid); $resp['emails'] = UserEmail::getAllForUser($uid); if (isset($params['id2name'])) { $resp['locations_name'] = Html::clean(Dropdown::getDropdownName('glpi_locations', $resp['locations_id'])); $resp['usertitles_name'] = Html::clean(Dropdown::getDropdownName('glpi_usertitles', $resp['usertitles_id'])); $resp['usercategories_name'] = Html::clean(Dropdown::getDropdownName('glpi_usercategories', $resp['usercategories_id'])); $resp['default_requesttypes_name'] = Html::clean(Dropdown::getDropdownName('glpi_requesttypes', $resp['default_requesttypes_id'])); } return $resp; } return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND); }
/** * Get name of the user with ID=$ID (optional with link to user.form.php) * *@param $ID integer ID of the user. *@param $link integer 1 = Show link to user.form.php 2 = return array with comments and link * (default =0) * *@return string : username string (realname if not empty and name if realname is empty). **/ function getUserName($ID, $link = 0) { global $DB, $CFG_GLPI; $user = ""; if ($link == 2) { $user = array("name" => "", "link" => "", "comment" => ""); } if ($ID) { $query = "SELECT *\n FROM `glpi_users`\n WHERE `id` = '{$ID}'"; $result = $DB->query($query); if ($link == 2) { $user = array("name" => "", "comment" => "", "link" => ""); } if ($DB->numrows($result) == 1) { $data = $DB->fetch_assoc($result); $username = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], $link); if ($link == 2) { $user["name"] = $username; $user["link"] = $CFG_GLPI["root_doc"] . "/front/user.form.php?id=" . $ID; $user['comment'] = ''; $comments = array(); $comments[] = array('name' => __('Name'), 'value' => $username); $comments[] = array('name' => __('Login'), 'value' => $data["name"]); $email = UserEmail::getDefaultForUser($ID); if (!empty($email)) { $comments[] = array('name' => __('Email'), 'value' => $email); } if (!empty($data["phone"])) { $comments[] = array('name' => __('Phone'), 'value' => $data["phone"]); } if (!empty($data["mobile"])) { $comments[] = array('name' => __('Mobile phone'), 'value' => $data["mobile"]); } if ($data["locations_id"] > 0) { $comments[] = array('name' => __('Location'), 'value' => Dropdown::getDropdownName("glpi_locations", $data["locations_id"])); } if ($data["usertitles_id"] > 0) { $comments[] = array('name' => _x('person', 'Title'), 'value' => Dropdown::getDropdownName("glpi_usertitles", $data["usertitles_id"])); } if ($data["usercategories_id"] > 0) { $comments[] = array('name' => __('Category'), 'value' => Dropdown::getDropdownName("glpi_usercategories", $data["usercategories_id"])); } if (count($comments)) { $user['comment'] = $user['comment']; foreach ($comments as $datas) { // Do not use SPAN here $user['comment'] .= sprintf(__('%1$s: %2$s') . "<br>", "<strong>" . $datas['name'] . "</strong>", $datas['value']); } } if (!empty($data['picture'])) { $user['comment'] = "<div class='tooltip_picture_border'>" . "<img class='tooltip_picture' src='" . User::getThumbnailURLForPicture($data['picture']) . "' /></div>" . "<div class='tooltip_text'>" . $user['comment'] . "</div>"; } } else { $user = $username; } } } return $user; }
function getOldAssignTechnicianAddress() { global $CFG_GLPI; if (isset($this->options['_old_user']) && $this->options['_old_user']['type'] == CommonITILActor::ASSIGN && $this->options['_old_user']['use_notification']) { $user = new User(); $user->getFromDB($this->options['_old_user']['users_id']); $author_email = UserEmail::getDefaultForUser($user->fields['id']); $author_lang = $user->fields["language"]; $author_id = $user->fields['id']; if (!empty($this->options['_old_user']['alternative_email']) && $this->options['_old_user']['alternative_email'] != $author_email && NotificationMail::isUserAddressValid($this->options['_old_user']['alternative_email'])) { $author_email = $this->options['_old_user']['alternative_email']; } if (empty($author_lang)) { $author_lang = $CFG_GLPI["language"]; } if (empty($author_id)) { $author_id = -1; } $this->addToAddressesList(array('email' => $author_email, 'language' => $author_lang, 'users_id' => $author_id)); } }
function getTaskTechAddress($options = array()) { global $DB; if (isset($options['tasks_id'])) { $query = "SELECT DISTINCT `glpi_users`.`id` AS id,\n `glpi_users`.`language` AS language\n FROM `glpi_plugin_projet_tasks`\n LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_plugin_projet_tasks`.`users_id`)\n WHERE `glpi_plugin_projet_tasks`.`id` = '" . $options['tasks_id'] . "'"; foreach ($DB->request($query) as $data) { $data['email'] = UserEmail::getDefaultForUser($data['id']); $this->addToAddressesList($data); } } }
static function getEmail($userid) { if (!UserEmail::getDefaultForUser($userid)) { return ''; } return UserEmail::getDefaultForUser($userid); }