/** * Store a newly created resource in storage. * * @return Response */ public function store() { $rules = array('first_name' => 'required', 'last_name' => 'required', 'email' => 'required | email', 'password' => 'required', 'password_confirmation' => 'required | same:password'); $validator = Validator::make(Input::all(), $rules); $input = Input::all(); if ($validator->fails()) { $input['autoOpenModal'] = true; //var_dump($input);die; return Redirect::back()->withErrors($validator)->withInput($input); } else { $user = new User(); $user->first_name = Input::get('first_name'); $user->last_name = Input::get('last_name'); $user->password = Hash::make(Input::get('password')); $user->status = 3; $user->save(); $userEmail = new UserEmail(); $userEmail->address = Input::get('email'); $userEmail->token = $userEmail->createToken(); $userEmail->confirmed = true; $user->email()->save($userEmail); $user->roles()->attach(3); $users = User::with(['roles', 'email'])->get(); //Session::flash('message', 'Successfully created nerd!'); return Redirect::to('admin/user')->with('users', $users); } //return "hello"; }
function createAction() { $this->_helper->layout->disableLayout(); $postData = $this->_request->getPost(); $accessCode = $postData['accessCode']; $email = $postData['email']; $currentTime = date("Y-m-d H:i:s"); if ($this->checkEmail($email)) { $useremailModel = new UserEmail(); $useremail = $useremailModel->createRow(); $useremail->accessCode = $accessCode; $useremail->email = $email; $useremail->create_date = $currentTime; $useremail->save(); $this->view->message = "发送成功, 再推荐一位吧"; } else { $this->view->message = "请输入正确的Email地址"; } if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $this->view->ajax = true; } else { $this->view->type = $postData['type']; $this->view->ajax = false; } }
private static function fetchFromDB($username) { try { $ue = new UserEmail($username); return $ue->getEmail(); } catch (fNotFoundException $e) { return NULL; } }
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); } }
public static function hasEmailVerified($username = NULL) { if ($username === NULL) { $username = fAuthorization::getUserToken(); } $email = UserEmail::fetch($username); if ($email === NULL) { return FALSE; } return strlen($email) > 0; }
public function run() { $user_emails = array(0 => array('user_id' => 1, 'address' => '*****@*****.**', 'token' => '1234567890qrtghnjy6Yjd2784jdkm81'), 1 => array('user_id' => 2, 'address' => '*****@*****.**', 'token' => '1234567890qrtghnjy6Yjd2784kjkm81')); DB::beginTransaction(); try { foreach ($user_emails as $a) { UserEmail::create(['user_id' => trim($a['user_id']), 'address' => trim($a['address']), 'token' => trim($a['token'])]); } DB::commit(); $this->command->info('user_emails table seeded'); } catch (\Exception $e) { DB::rollBack(); throw $e; } }
static function fromVars($vars) { // Try and lookup by email address $user = static::lookupByEmail($vars['email']); if (!$user) { $name = $vars['name']; if (!$name) { list($name) = explode('@', $vars['email'], 2); } $user = User::create(array('name' => Format::htmldecode(Format::sanitize($name, false)), 'created' => new SqlFunction('NOW'), 'updated' => new SqlFunction('NOW'), 'default_email' => UserEmail::ensure($vars['email']))); // Is there an organization registered for this domain list($mailbox, $domain) = explode('@', $vars['email'], 2); if (isset($vars['org_id'])) { $user->set('org_id', $vars['org_id']); } elseif ($org = Organization::forDomain($domain)) { $user->setOrganization($org, false); } try { $user->save(true); $user->emails->add($user->default_email); // Attach initial custom fields $user->addDynamicData($vars); } catch (OrmException $e) { return null; } } return $user; }
static function fromVars($vars, $update = false) { // Try and lookup by email address $user = static::lookupByEmail($vars['email']); if (!$user) { $name = $vars['name']; if (!$name) { list($name) = explode('@', $vars['email'], 2); } $user = User::create(array('name' => Format::htmldecode(Format::sanitize($name, false)), 'created' => new SqlFunction('NOW'), 'updated' => new SqlFunction('NOW'), 'default_email' => UserEmail::ensure($vars['email']))); // Is there an organization registered for this domain list($mailbox, $domain) = explode('@', $vars['email'], 2); if (isset($vars['org_id'])) { $user->set('org_id', $vars['org_id']); } elseif ($org = Organization::forDomain($domain)) { $user->setOrganization($org, false); } try { $user->save(true); $user->emails->add($user->default_email); // Attach initial custom fields $user->addDynamicData($vars); } catch (OrmException $e) { return null; } } elseif ($update) { $errors = array(); $user->updateInfo($vars, $errors, true); } /* INICIO Anthony Parisi */ if (isset($_SESSION["crmEmail"])) { $mysqli = new mysqli("localhost", "root", "ip15x0", "vtigercrm600"); $sqlUser = $mysqli->query("SELECT MAX(id) FROM `vtigercrm600`.vtiger_modtracker_detail;"); $resUser = $sqlUser->fetch_array(); $mysqli->query("UPDATE `vtigercrm600`.`vtiger_contactdetails` SET `mobile` = '" . $_SESSION["crmPhone"] . "' WHERE UPPER(`vtiger_contactdetails`.`email`) = UPPER('" . $_SESSION["crmEmail"] . "');"); $mysqli->query("INSERT INTO `vtigercrm600`.vtiger_modtracker_detail(id,fieldname,prevalue,postvalue) VALUES('" . $resUser[0] . "','email',NULL,'" . $_SESSION["crmPhone"] . "');"); unset($_SESSION["crmEmail"]); unset($_SESSION["crmPhone"]); } /* FIN */ return $user; }
/** * 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); }
?> </td> <td><?php echo $profile->getMajor(); ?> </td> <td><?php echo $profile->getGrade(); ?> </td> <td><?php echo $profile->getPhoneNumber(); ?> </td> <td><?php echo UserEmail::fetch($profile->getUsername()); ?> </td> <td><?php echo $profile->getQq(); ?> </td> <td><?php echo $profile->getClassName(); ?> </td> <td> <?php foreach (array('A', 'B', 'C', 'D') as $category) { ?> <?php
function edit() { $id = WebApp::post('id') === NULL ? '' : intval(WebApp::post('id')); $this->parent->parent->debug($id); if (!is_int($id)) { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to edit user.<br />Error: <code>User ID must be an integer</code>', B_T_FAIL); } if ($id == $this->parent->parent->user->getUserID() && !$this->parent->inGroup(1)) { $this->parent->parent->logEvent($this::name_space, 'Attempted to edit themself'); return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to edit user.<br />Error: <code>You cannot edit yourself</code>', B_T_FAIL); } $f_name = WebApp::post('f_name') === NULL ? '' : WebApp::post('f_name'); $s_name = WebApp::post('s_name') === NULL ? '' : WebApp::post('s_name'); $username = WebApp::post('username') === NULL ? '' : WebApp::post('username'); $email = WebApp::post('email') === NULL ? '' : WebApp::post('email'); $n_pwd = WebApp::post('n_pwd') === NULL ? '' : WebApp::post('n_pwd'); $n_pwd_c = WebApp::post('c_pwd') === NULL ? '' : WebApp::post('c_pwd'); $chgPwd = WebApp::post('chgPwd') === NULL ? '' : WebApp::post('chgPwd'); $enabled = WebApp::post('enabled') === NULL ? false : WebApp::post('enabled'); $p_group = WebApp::post('p_group') === NULL ? 3 : WebApp::post('p_group'); $s_groups = WebApp::post('s_group') === NULL ? array() : strgetcsv(WebApp::post('s_group')); if ($f_name == '') { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to add user.<br />Error: <code>First Name must not be blank</code>', B_T_FAIL); } if ($s_name == '') { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to add user.<br />Error: <code>Surname must not be blank</code>', B_T_FAIL); } if ($username == '') { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to add user.<br />Error: <code>Username must not be blank</code>', B_T_FAIL); } if ($email == '') { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to add user.<br />Error: <code>Email must not be blank</code>', B_T_FAIL); } if ($chgPwd == '') { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to add user.<br />Error: <code>Change Password must not be blank</code>', B_T_FAIL); } if ($enabled == '') { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to add user.<br />Error: <code>Enabled must not be blank</code>', B_T_FAIL); } if ($p_group == '') { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to add user.<br />Error: <code>Primary Group must not be blank</code>', B_T_FAIL); } if ($this->parent->inGroup(2, false) && $p_group == 1) { $this->parent->parent->logEvent($this::name_space, 'Tried to make "' . $username . '" a Super Admin'); return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to edit user.<br />Error: <code>You cannot escalate privileges</code>', B_T_FAIL); } if ($this->parent->parent->user->getUserID() == $id && $enabled == false) { $this->parent->parent->logEvent($this::name_space, 'Tried to disable themself'); return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to edit user.<br />Error: <code>You cannot disable yourself</code>', B_T_FAIL); } if ($n_pwd != $n_pwd_c) { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed to edit user.<br />Error: <code>New passwords must match, or both be empty</code>', B_T_FAIL); } $clear_sgroup = $this->mySQL_w->prepare("DELETE FROM `core_sgroup` WHERE `user`=?"); $update_sgroup = $this->mySQL_w->prepare("INSERT INTO `core_sgroup` (`user`, `group`) VALUES (?, ?)"); if ($clear_sgroup === false) { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed edit user!<br />Error: <code>Clear query failed</code>', B_T_FAIL); } if ($update_sgroup === false) { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed edit user!<br />Error: <code>Update sgroup query failed</code>', B_T_FAIL); } if ($n_pwd != '') { $userCtrl = $this->parent->parent->user; $hash = $userCtrl->ranHash(); $new_pwd = $userCtrl->pwd_hash($n_pwd, $hash) . ':' . $hash; $update = $this->mySQL_w->prepare("UPDATE `core_users` SET `f_name`=?,`s_name`=?,`email`=?,`en`=?,`chgPwd`=?,`p_group`=?,`pass`=?, `pwd_reset`=`pwd_reset`+1 WHERE `id`=? AND `username`=?"); if ($update === false) { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed edit user!<br />Error: <code>Update query failed</code>', B_T_FAIL); } $update->bind_param('sssiiisis', $f_name, $s_name, $email, $enabled, $chgPwd, $p_group, $new_pwd, $id, $username); } else { $update = $this->mySQL_w->prepare("UPDATE `core_users` SET `f_name`=?,`s_name`=?,`email`=?,`en`=?,`chgPwd`=?,`p_group`=? WHERE `id`=? AND `username`=?"); if ($update === false) { return new ActionResult($this, '/admin/user/user_edit', 0, 'Failed edit user!<br />Error: <code>Update query failed</code>', B_T_FAIL); } $update->bind_param('sssiiiis', $f_name, $s_name, $email, $enabled, $chgPwd, $p_group, $id, $username); } $clear_sgroup->bind_param('i', $id); $update_sgroup->bind_param('ii', $id, $sgroup); $clear_sgroup->execute(); if (count($s_groups) != 0) { foreach ($s_groups as $sgroup) { $this->parent->parent->debug($sgroup); $update_sgroup->bind_param('ii', $id, $sgroup); $update_sgroup->execute(); } } if ($n_pwd != '') { $mail = new Emailer(); $mail->Subject = 'Password Changed'; $mail->msgHTML(UserEmail::adminPasswordChange($f_name)['html']); $mail->AltBody = UserEmail::adminPasswordChange($f_name)['text']; $mail->addAddress($email, $f_name . ' ' . $s_name); $mail->send(); } $update->execute(); $update->store_result(); $this->parent->parent->logEvent($this::name_space, 'Edited user "' . $username . '"'); return new ActionResult($this, '/admin/user/user_view', 1, 'User was edited.', B_T_SUCCESS, array('form' => array('n_pwd' => '', 'c_pwd' => ''))); }
/** * @return UserEmail */ public function getEmail() { return $this->email->getEmail(); }
function _addContactUser($a_contacts, $users_id, $i) { $pmContact = new PluginMonitoringContact(); $pmNotificationcommand = new PluginMonitoringNotificationcommand(); $pmContacttemplate = new PluginMonitoringContacttemplate(); $user = new User(); $calendar = new Calendar(); $user->getFromDB($users_id); // Get contact template $a_pmcontact = current($pmContact->find("`users_id`='".$users_id."'", "", 1)); if (empty($a_pmcontact) OR (isset($a_pmcontact['plugin_monitoring_contacttemplates_id']) AND $a_pmcontact['plugin_monitoring_contacttemplates_id'] == '0')) { // Use default template $a_pmcontact = current($pmContacttemplate->find("`is_default`='1'", "", 1)); } else { // Use contact defined template $a_pmcontact = current($pmContacttemplate->find("`id`='".$a_pmcontact['plugin_monitoring_contacttemplates_id']."'", "", 1)); } $a_contacts[$i]['contact_name'] = $user->fields['name']; $a_contacts[$i]['alias'] = $user->getName(); PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "- contact ".$user->fields['name']." - ".$user->getName()."\n" ); // Toolbox::logInFile("pm-contacts", "- contact ".serialize($user->fields)."\n"); if (!isset($a_pmcontact['host_notification_period'])) { $a_calendars = current($calendar->find("", "", 1)); $cal = '24x7'; if (isset($a_calendars['name'])) { $cal = $a_calendars['name']; } $a_pmcontact['host_notifications_enabled'] = '0'; $a_pmcontact['service_notifications_enabled'] = '0'; $a_pmcontact['service_notification_period'] = $cal; $a_pmcontact['host_notification_period'] = $cal; $a_pmcontact['service_notification_options_w'] = '0'; $a_pmcontact['service_notification_options_u'] = '0'; $a_pmcontact['service_notification_options_c'] = '0'; $a_pmcontact['service_notification_options_r'] = '0'; $a_pmcontact['service_notification_options_f'] = '0'; $a_pmcontact['service_notification_options_n'] = '0'; $a_pmcontact['host_notification_options_d'] = '0'; $a_pmcontact['host_notification_options_u'] = '0'; $a_pmcontact['host_notification_options_r'] = '0'; $a_pmcontact['host_notification_options_f'] = '0'; $a_pmcontact['host_notification_options_s'] = '0'; $a_pmcontact['host_notification_options_n'] = '0'; $a_pmcontact['service_notification_commands'] = '2'; $a_pmcontact['host_notification_commands'] = '1'; } $a_contacts[$i]['host_notifications_enabled'] = $a_pmcontact['host_notifications_enabled']; $a_contacts[$i]['service_notifications_enabled'] = $a_pmcontact['service_notifications_enabled']; $calendar->getFromDB($a_pmcontact['service_notification_period']); if (isset($calendar->fields['name'])) { $a_contacts[$i]['service_notification_period'] = $calendar->fields['name']; } else { $a_contacts[$i]['service_notification_period'] = '24x7'; } $calendar->getFromDB($a_pmcontact['host_notification_period']); if (isset($calendar->fields['name'])) { $a_contacts[$i]['host_notification_period'] = $calendar->fields['name']; } else { $a_contacts[$i]['host_notification_period'] = '24x7'; } $a_servicenotif = array(); if ($a_pmcontact['service_notification_options_w'] == '1') $a_servicenotif[] = "w"; if ($a_pmcontact['service_notification_options_u'] == '1') $a_servicenotif[] = "u"; if ($a_pmcontact['service_notification_options_c'] == '1') $a_servicenotif[] = "c"; if ($a_pmcontact['service_notification_options_r'] == '1') $a_servicenotif[] = "r"; if ($a_pmcontact['service_notification_options_f'] == '1') $a_servicenotif[] = "f"; if ($a_pmcontact['service_notification_options_n'] == '1') $a_servicenotif = array("n"); if (count($a_servicenotif) == "0") $a_servicenotif = array("n"); $a_contacts[$i]['service_notification_options'] = implode(",", $a_servicenotif); $a_hostnotif = array(); if ($a_pmcontact['host_notification_options_d'] == '1') $a_hostnotif[] = "d"; if ($a_pmcontact['host_notification_options_u'] == '1') $a_hostnotif[] = "u"; if ($a_pmcontact['host_notification_options_r'] == '1') $a_hostnotif[] = "r"; if ($a_pmcontact['host_notification_options_f'] == '1') $a_hostnotif[] = "f"; if ($a_pmcontact['host_notification_options_s'] == '1') $a_hostnotif[] = "s"; if ($a_pmcontact['host_notification_options_n'] == '1') $a_hostnotif = array("n"); if (count($a_hostnotif) == "0") $a_hostnotif = array("n"); $a_contacts[$i]['host_notification_options'] = implode(",", $a_hostnotif); $pmNotificationcommand->getFromDB($a_pmcontact['service_notification_commands']); if (isset($pmNotificationcommand->fields['command_name'])) { $a_contacts[$i]['service_notification_commands'] = PluginMonitoringCommand::$command_prefix . $pmNotificationcommand->fields['command_name']; } else { $a_contacts[$i]['service_notification_commands'] = ''; } $pmNotificationcommand->getFromDB($a_pmcontact['host_notification_commands']); if (isset($pmNotificationcommand->fields['command_name'])) { $a_contacts[$i]['host_notification_commands'] = PluginMonitoringCommand::$command_prefix . $pmNotificationcommand->fields['command_name']; } else { $a_contacts[$i]['host_notification_commands'] = ''; } // Get first email $a_emails = UserEmail::getAllForUser($users_id); $first = 0; foreach ($a_emails as $email) { if ($first == 0) { $a_contacts[$i]['email'] = $email; } $first++; } if (!isset($a_contacts[$i]['email'])) { $a_contacts[$i]['email'] = ''; } $a_contacts[$i]['pager'] = $user->fields['phone']; if (isset($a_pmcontact['shinken_administrator'])) { $a_contacts[$i]['is_admin'] = $a_pmcontact['shinken_administrator']; } else { $a_contacts[$i]['is_admin'] = self::$shinkenParameters['webui']['contacts']['is_admin']; } if (isset($a_pmcontact['shinken_can_submit_commands'])) { $a_contacts[$i]['can_submit_commands'] = $a_pmcontact['shinken_can_submit_commands']; } else { $a_contacts[$i]['can_submit_commands'] = self::$shinkenParameters['webui']['contacts']['can_submit_commands']; } if (empty($user->fields['password'])) { $a_contacts[$i]['password'] = self::$shinkenParameters['webui']['contacts']['password']; } else { $a_contacts[$i]['password'] = $user->fields['password']; } /* TODO: address1, address2, ..., address6 are available in Shinken */ return $a_contacts; }
/** * @param $values * @param $add (true by default) * @param $rights array */ function processAfterInsertOrUpdate($values, $add = true, $rights = array()) { global $DB; //Manage user emails if (isset($values['User']['useremails_id']) && $rights['add_dropdown'] && Session::haveRight('user', 'w')) { if (!countElementsInTable("glpi_useremails", "`users_id`='" . $values['User']['id'] . "'\n AND `email`='" . $values['User']['useremails_id'] . "'")) { $useremail = new UserEmail(); $tmp['users_id'] = $values['User']['id']; $tmp['email'] = $values['User']['useremails_id']; $useremail->add($tmp); } } if (isset($values['User']['password']) && $values['User']['password'] != '') { //We use an SQL request because updating the password is unesasy //(self reset password process in $user->prepareInputForUpdate()) $password = sha1(Toolbox::unclean_cross_side_scripting_deep(stripslashes($values['User']["password"]))); $query = "UPDATE `glpi_users`\n SET `password` = '" . $password . "'\n WHERE `id` = '" . $values['User']['id'] . "'"; $DB->query($query); } }
function getSender($options = array()) { $mails = new UserEmail(); if (isset($_SESSION['glpiID']) && $_SESSION['glpiID'] > 0 && isset($_SESSION['glpilock_directunlock_notification']) && $_SESSION['glpilock_directunlock_notification'] > 0 && $mails->getFromDBByQuery(" WHERE users_id = " . $_SESSION['glpiID'] . "\n AND is_default = 1 ")) { $ret = array('email' => $mails->fields['email'], 'name' => formatUserName(0, $_SESSION["glpiname"], $_SESSION["glpirealname"], $_SESSION["glpifirstname"])); } else { $ret = parent::getSender($options); } return $ret; }
function _addContactUser($a_contacts, $users_id, $i) { $pmContact = new PluginMonitoringContact(); $pmNotificationcommand = new PluginMonitoringNotificationcommand(); $pmContacttemplate = new PluginMonitoringContacttemplate(); $user = new User(); $calendar = new Calendar(); $user->getFromDB($users_id); // Get template $a_pmcontact = current($pmContact->find("`users_id`='" . $users_id . "'", "", 1)); if (empty($a_pmcontact) or isset($a_pmcontact['plugin_monitoring_contacttemplates_id']) and $a_pmcontact['plugin_monitoring_contacttemplates_id'] == '0') { $a_pmcontact = current($pmContacttemplate->find("`is_default`='1'", "", 1)); } else { $a_pmcontact = current($pmContacttemplate->find("`id`='" . $a_pmcontact['plugin_monitoring_contacttemplates_id'] . "'", "", 1)); } $a_contacts[$i]['contact_name'] = $user->fields['name']; $a_contacts[$i]['alias'] = $user->getName(); if (!isset($a_pmcontact['host_notification_period'])) { $a_calendars = current($calendar->find("", "", 1)); $a_pmcontact['host_notifications_enabled'] = '0'; $a_pmcontact['service_notifications_enabled'] = '0'; $a_pmcontact['service_notification_period'] = $a_calendars['id']; $a_pmcontact['host_notification_period'] = $a_calendars['id']; $a_pmcontact['service_notification_options_w'] = '0'; $a_pmcontact['service_notification_options_u'] = '0'; $a_pmcontact['service_notification_options_c'] = '0'; $a_pmcontact['service_notification_options_r'] = '0'; $a_pmcontact['service_notification_options_f'] = '0'; $a_pmcontact['service_notification_options_n'] = '0'; $a_pmcontact['host_notification_options_d'] = '0'; $a_pmcontact['host_notification_options_u'] = '0'; $a_pmcontact['host_notification_options_r'] = '0'; $a_pmcontact['host_notification_options_f'] = '0'; $a_pmcontact['host_notification_options_s'] = '0'; $a_pmcontact['host_notification_options_n'] = '0'; $a_pmcontact['service_notification_commands'] = '2'; $a_pmcontact['host_notification_commands'] = '1'; } $a_contacts[$i]['host_notifications_enabled'] = $a_pmcontact['host_notifications_enabled']; $a_contacts[$i]['service_notifications_enabled'] = $a_pmcontact['service_notifications_enabled']; $calendar->getFromDB($a_pmcontact['service_notification_period']); $a_contacts[$i]['service_notification_period'] = $calendar->fields['name']; $calendar->getFromDB($a_pmcontact['host_notification_period']); $a_contacts[$i]['host_notification_period'] = $calendar->fields['name']; $a_servicenotif = array(); if ($a_pmcontact['service_notification_options_w'] == '1') { $a_servicenotif[] = "w"; } if ($a_pmcontact['service_notification_options_u'] == '1') { $a_servicenotif[] = "u"; } if ($a_pmcontact['service_notification_options_c'] == '1') { $a_servicenotif[] = "c"; } if ($a_pmcontact['service_notification_options_r'] == '1') { $a_servicenotif[] = "r"; } if ($a_pmcontact['service_notification_options_f'] == '1') { $a_servicenotif[] = "f"; } if ($a_pmcontact['service_notification_options_n'] == '1') { $a_servicenotif = array("n"); } if (count($a_servicenotif) == "0") { $a_servicenotif = array("n"); } $a_contacts[$i]['service_notification_options'] = implode(",", $a_servicenotif); $a_hostnotif = array(); if ($a_pmcontact['host_notification_options_d'] == '1') { $a_hostnotif[] = "d"; } if ($a_pmcontact['host_notification_options_u'] == '1') { $a_hostnotif[] = "u"; } if ($a_pmcontact['host_notification_options_r'] == '1') { $a_hostnotif[] = "r"; } if ($a_pmcontact['host_notification_options_f'] == '1') { $a_hostnotif[] = "f"; } if ($a_pmcontact['host_notification_options_s'] == '1') { $a_hostnotif[] = "s"; } if ($a_pmcontact['host_notification_options_n'] == '1') { $a_hostnotif = array("n"); } if (count($a_hostnotif) == "0") { $a_hostnotif = array("n"); } $a_contacts[$i]['host_notification_options'] = implode(",", $a_hostnotif); $pmNotificationcommand->getFromDB($a_pmcontact['service_notification_commands']); $a_contacts[$i]['service_notification_commands'] = $pmNotificationcommand->fields['command_name']; $pmNotificationcommand->getFromDB($a_pmcontact['host_notification_commands']); $a_contacts[$i]['host_notification_commands'] = $pmNotificationcommand->fields['command_name']; // Get first email $a_emails = UserEmail::getAllForUser($users_id); $first = 0; foreach ($a_emails as $email) { if ($first == 0) { $a_contacts[$i]['email'] = $email; } $first++; } if (!isset($a_contacts[$i]['email'])) { $a_contacts[$i]['email'] = ''; } $a_contacts[$i]['pager'] = $user->fields['phone']; return $a_contacts; }
/** * postEmail * * After some security and sanity checks, attaches the body and subject * of the message in reply to this thread item * * Parameters: * mailinfo - (array) of information about the email, with at least the * following keys * - mid - (string) email message-id * - name - (string) personal name of email originator * - email - (string<email>) originating email address * - subject - (string) email subject line (decoded) * - body - (string) email message body (decoded) */ function postEmail($mailinfo) { global $ost; // +==================+===================+=============+ // | Orig Thread-Type | Reply Thread-Type | Requires | // +==================+===================+=============+ // | * | Message (M) | From: Owner | // | * | Note (N) | From: Staff | // | Response (R) | Message (M) | | // | Message (M) | Response (R) | From: Staff | // +------------------+-------------------+-------------+ if (!($ticket = $this->getTicket())) { // Kind of hard to continue a discussion without a ticket ... return false; } elseif ($this->getEmailMessageId() == $mailinfo['mid']) { // Reporting success so the email can be moved or deleted. return true; } // Mail sent by this system will have a message-id format of // <*****@*****.**> // where code is a predictable string based on the SECRET_SALT of // this osTicket installation. If this incoming mail matches the // code, then it very likely originated from this system and looped $msgId_info = Mailer::decodeMessageId($mailinfo['mid']); if ($msgId_info['loopback']) { // This mail was sent by this system. It was received due to // some kind of mail delivery loop. It should not be considered // a response to an existing thread entry if ($ost) { $ost->log(LOG_ERR, _S('Email loop detected'), sprintf(_S('It appears as though <%s> is being used as a forwarded or fetched email account and is also being used as a user / system account. Please correct the loop or seek technical assistance.'), $mailinfo['email']), false, true); } return true; } $vars = array('mid' => $mailinfo['mid'], 'header' => $mailinfo['header'], 'ticketId' => $ticket->getId(), 'poster' => $mailinfo['name'], 'origin' => 'Email', 'source' => 'Email', 'ip' => '', 'reply_to' => $this, 'recipients' => $mailinfo['recipients'], 'to-email-id' => $mailinfo['to-email-id']); $errors = array(); if (isset($mailinfo['attachments'])) { $vars['attachments'] = $mailinfo['attachments']; } $body = $mailinfo['message']; // Disambiguate if the user happens also to be a staff member of the // system. The current ticket owner should _always_ post messages // instead of notes or responses if ($mailinfo['userId'] || strcasecmp($mailinfo['email'], $ticket->getEmail()) == 0) { $vars['message'] = $body; $vars['userId'] = $mailinfo['userId'] ?: $ticket->getUserId(); return $ticket->postMessage($vars, 'Email'); } elseif (($E = UserEmail::lookup($mailinfo['email'])) && ($C = Collaborator::lookup(array('ticketId' => $ticket->getId(), 'userId' => $E->user_id)))) { $vars['userId'] = $C->getUserId(); $vars['message'] = $body; return $ticket->postMessage($vars, 'Email'); } elseif ($mailinfo['staffId'] || ($mailinfo['staffId'] = Staff::getIdByEmail($mailinfo['email']))) { $vars['staffId'] = $mailinfo['staffId']; $poster = Staff::lookup($mailinfo['staffId']); $vars['note'] = $body; return $ticket->postNote($vars, $errors, $poster); } elseif (Email::getIdByEmail($mailinfo['email'])) { // Don't process the email -- it came FROM this system return true; } elseif (isset($mailinfo['thread-type'])) { switch ($mailinfo['thread-type']) { case 'N': $vars['note'] = $body; $poster = $mailinfo['email']; return $ticket->postNote($vars, $errors, $poster); } } else { //XXX: Are we potentially leaking the email address to // collaborators? $header = sprintf("Received From: %s <%s>\n\n", $mailinfo['name'], $mailinfo['email']); if ($body instanceof HtmlThreadBody) { $header = nl2br(Format::htmlchars($header)); } // Add the banner to the top of the message if ($body instanceof ThreadBody) { $body->prepend($header); } $vars['message'] = $body; $vars['userId'] = 0; //Unknown user! //XXX: Assume ticket owner? return $ticket->postMessage($vars, 'Email'); } // Currently impossible, but indicate that this thread object could // not append the incoming email. return false; }
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); } } }
/** * Summary of setLockedByMessage * Shows 'Locked by ' message and proposes to request unlock from locker **/ private function setLockedByMessage() { global $CFG_GLPI; // should get locking user info $user = new User(); $user->getFromDBByQuery(" WHERE id = " . $this->fields['users_id']); $useremail = new UserEmail(); $showAskUnlock = $useremail->getFromDBByQuery(" WHERE users_id = " . $this->fields['users_id'] . "\n AND is_default = 1 ") && $CFG_GLPI['use_mailing'] == 1; $completeUserName = formatUserName(0, $user->fields['name'], $user->fields['realname'], $user->fields['firstname']); if ($showAskUnlock) { $ret = Html::scriptBlock("\n function askUnlock() {\n \$('#message_after_lock').fadeToggle() ;\n " . Html::jsConfirmCallback(__('Ask for unlock item?'), $this->itemtypename . " #" . $this->itemid, "function() {\n \$.ajax({\n url: '" . $CFG_GLPI['root_doc'] . "/ajax/unlockobject.php',\n cache: false,\n data: 'requestunlock=1&id=" . $this->fields['id'] . "',\n success: function( data, textStatus, jqXHR ) {\n " . Html::jsAlertCallback($completeUserName, __('Request sent to'), "function() { \$('#message_after_lock').fadeToggle() ; }") . "\n }\n });\n }", "function() {\n \$('#message_after_lock').fadeToggle() ;\n }") . "\n }\n\n "); echo $ret; } $ret = Html::scriptBlock("\n \$(function(){\n var lockStatusTimer ;\n \$('#alertMe').change(function( eventObject ){\n if( this.checked ) {\n lockStatusTimer = setInterval( function() {\n \$.ajax({\n url: '" . $CFG_GLPI['root_doc'] . "/ajax/unlockobject.php',\n cache: false,\n data: 'lockstatus=1&id=" . $this->fields['id'] . "',\n success: function( data, textStatus, jqXHR ) {\n if( data == 0 ) {\n clearInterval(lockStatusTimer);\n \$('#message_after_lock').fadeToggle() ;" . Html::jsConfirmCallback(__('Reload page?'), __('Item unlocked!'), "function() {\n window.location.reload(true);\n }") . "\n }\n }\n });\n },15000)\n } else {\n clearInterval(lockStatusTimer);\n }\n });\n });\n "); echo $ret; $msg = "<table><tr><td class=red nowrap>"; $msg .= __('Locked by ') . "<a href='" . $user->getLinkURL() . "'>{$completeUserName}</a> -> " . Html::convDateTime($this->fields['date_mod']); $msg .= "</td><td nowrap>"; if ($showAskUnlock) { $msg .= "<a class='vsubmit' onclick='javascript:askUnlock();'>" . __('Ask for unlock') . "</a>"; } $msg .= "</td><td> </td><td>" . __('Alert me when unlocked') . "</td><td> " . Html::getCheckbox(array('id' => 'alertMe')) . "</td></tr></table>"; $this->displayLockMessage($msg); }
/** * 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; } } }
/** * Summary of setLockedByMessage * Shows 'Locked by ' message and proposes to request unlock from locker **/ private function setLockedByMessage() { global $CFG_GLPI; // should get locking user info $user = new User(); $user->getFromDBByQuery(" WHERE id = " . $this->fields['users_id']); $useremail = new UserEmail(); $showAskUnlock = $useremail->getFromDBByQuery(" WHERE users_id = " . $this->fields['users_id'] . "\n AND is_default = 1 ") && $CFG_GLPI['use_mailing'] == 1; $completeUserName = formatUserName(0, $user->fields['name'], $user->fields['realname'], $user->fields['firstname']); if ($showAskUnlock) { $ret = Html::scriptBlock("\n function askUnlock() {\n \$('#message_after_lock').fadeToggle() ;\n " . Html::jsConfirmCallback(__('Ask for unlock item?'), $this->itemtypename . " #" . $this->itemid, "function() {\n \$.ajax({\n url: '" . $CFG_GLPI['root_doc'] . "/ajax/unlockobject.php',\n cache: false,\n data: 'requestunlock=1&id=" . $this->fields['id'] . "',\n success: function( jqXHR, textStatus ) {\n " . Html::jsAlertCallback($completeUserName, __('Request sent to'), "function() { \$('#message_after_lock').fadeToggle() ; }") . "\n }\n });\n }", "function() {\n \$('#message_after_lock').fadeToggle() ;\n }") . "\n }\n\n "); echo $ret; } $msg = "<table><tr><td class=red nowrap>"; $msg .= __('Locked by ') . "<a href='" . $user->getLinkURL() . "'>{$completeUserName}</a> -> " . Html::convDateTime($this->fields['date_mod']); $msg .= "</td><td nowrap>"; if ($showAskUnlock) { $msg .= "<a class='vsubmit' onclick='javascript:askUnlock();'>" . __('Ask for unlock') . "</a>"; } $msg .= "</td></tr></table>"; $this->displayLockMessage($msg); }
public function checkVericode($id, $vericode) { try { $v = new Vericode($id); if ($v->getUsername() != fAuthorization::getUserToken() or $v->getVericode() != $vericode) { throw new fValidationException('Invalid verification code.'); } $ue = new UserEmail(); $ue->setUsername($v->getUsername()); $ue->setEmail($v->getEmail()); $ue->store(); fMessaging::create('success', 'Your email address is verified successfully.'); $referer = fMessaging::retrieve('referer', SITE_BASE . '/email/verify'); if ($referer == NULL) { $referer = SITE_BASE; } fURL::redirect($referer); } catch (fException $e) { fMessaging::create('error', 'Email verification failed: ' . $e->getMessage()); Util::redirect('/email/verify'); } }
/** * Sends the newly generated password to the email of user using the given username in the model. * @return boolean whether successfuly send password */ public function send_password($user_id) { $userModel = new SuUser(); $model = new Admin_ajax(); $password = $userModel->random_password(); $this->user_password = md5($password); $userData = $this->getUserData($user_id); $userData['user_password'] = $password; /////////////////////////////////////////////////////////////////////// ///////////Create Forgot password email Template ////////////////////// /////////////////////////////////////////////////////////////////////// $tempemaildata = $model->customOneRowQuery("SELECT * FROM `su_notification_templates` WHERE type='email' and alias='forgotpassward'"); $emailtemplate = new Template(); $emailtemplate->setKeys($userData); $emailText = $emailtemplate->replace($tempemaildata['content']); /////////////////////////////////////////////////////////////////////// ///////////End Create Forgot password email Template ////////////////// /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// ///////////Create Forgot password email Template ////////////////////// /////////////////////////////////////////////////////////////////////// $tempsmsdata = $model->customOneRowQuery("SELECT * FROM `su_notification_templates` WHERE type='sms' and alias='forgotpassward'"); $smstemplate = new Template(); $smstemplate->setKeys($userData); $smsText = $smstemplate->replace($tempsmsdata['content']); //print_r($userData);die; /////////////////////////////////////////////////////////////////////// ///////////End Create Forgot password email Template ////////////////// /////////////////////////////////////////////////////////////////////// // $data = array("name" => $userData["user_fname"], "email" => $userData["user_email"], "password" => $password); // $msg_data = 'Below are the new password for PayWayhelp account : // // Username/Email : ' . $userData["user_email"] . ' // // Password : '******''; // if ($insert) { if (isset($userData["user_notification"]) && $userData["user_notification"] == 'both') { //$UserEmail = new UserEmail($this->username,$this->user_password); $UserEmail = new UserEmail(); //$status = $UserEmail->SendMail($userData["user_email"], 'Reset Password', 'reset_password', $data); $UserEmail->SendCustomMail($userData["user_email"], "Paywayhelp : Reset Password", $emailText); //sms api //$msg_id = $this->send_sms_via_gateway($userData["user_fname"], 'Reset Password', $msg_data); $msg_id = $this->send_sms_via_gateway($userData["user_phoneNumber"], 'Reset Password', $smsText); //add message data $admin_ajax->insert_data('su_message', array('message_id' => $msg_id, 'message_user' => $user_id, 'message_date' => date('Y-m-d H:i:s'))); } elseif (isset($userData["user_notification"]) && $userData["user_notification"] == 'mail') { $UserEmail = new UserEmail(); //$status = $UserEmail->SendMail($userData["user_email"], 'Reset Password', 'reset_password', $data); $UserEmail->SendCustomMail($userData["user_email"], "Paywayhelp : Reset Password", $emailText); } elseif (isset($userData["user_notification"]) && $userData["user_notification"] == 'sms') { //sms api $msg_id = $this->send_sms_via_gateway($userData["user_phoneNumber"], 'Reset Password', $smsText); //add message data $admin_ajax->insert_data('su_message', array('message_id' => $msg_id, 'message_user' => $user_id, 'message_date' => date('Y-m-d H:i:s'))); } return $msg_id; /* } else { return false; } */ }
/** * 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(); } }
/** * 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; }
/** * 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(); } }
function showContacts($itemtype, $items_id) { global $DB,$CFG_GLPI; $this->addContact($itemtype, $items_id); $group = new Group(); $user = new User(); $rand = mt_rand(); echo "<form method='post' name='contact_item_form$rand' id='contact_item_form$rand' action=\"". $CFG_GLPI["root_doc"]."/plugins/monitoring/front/contact_item.form.php\">"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th>"; echo __('Contacts', 'monitoring'); echo "</th>"; echo "</tr>"; echo "</table>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th width='10'> </th>"; echo "<th>".__('Group')." - ".__('Name')."</th>"; echo "<th colspan='3'></th>"; echo "</tr>"; $used = array(); // Display groups first $query = "SELECT * FROM `".$this->getTable()."` WHERE `items_id`='".$items_id."' AND `itemtype`='".$itemtype."' AND `groups_id` > 0"; $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { $group->getFromDB($data['groups_id']); echo "<tr>"; echo "<td>"; echo "<input type='checkbox' name='item[".$data["id"]."]' value='1'>"; echo "</td>"; echo "<td class='center'>"; echo $group->getLink(1); echo "</td>"; echo "<td colspan='3'>"; echo "</td>"; echo "</tr>"; } echo "<tr>"; echo "<th width='10'> </th>"; echo "<th>".__('User')." - ".__('Name')."</th>"; echo "<th>".__('Entity')."</th>"; echo "<th>".__('Email address')."</th>"; echo "<th>".__('Phone')."</th>"; echo "</tr>"; $entity = new Entity(); $used = array(); // Display Users $query = "SELECT * FROM `".$this->getTable()."` WHERE `items_id`='".$items_id."' AND `itemtype`='".$itemtype."' AND `users_id` > 0"; $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { $user->getFromDB($data['users_id']); echo "<tr>"; echo "<td>"; echo "<input type='checkbox' name='item[".$data["id"]."]' value='1'>"; echo "</td>"; echo "<td class='center'>"; echo $user->getLink(1); echo "</td>"; $entity->getFromDB($data['entities_id']); echo "<td class='center'>"; echo $entity->getName()." <strong>(R)</strong>"; echo "</td>"; echo "<td class='center'>"; $a_emails = UserEmail::getAllForUser($data['users_id']); $first = 0; foreach ($a_emails as $email) { if ($first == 0) { echo $email; } $first++; } echo "</td>"; echo "<td class='center'>"; echo $user->fields['phone']; echo "</td>"; echo "</tr>"; } Html::openArrowMassives("contact_item_form$rand", true); Html::closeArrowMassives(array('deleteitem' => _sx('button', 'Delete permanently'))); Html::closeForm(); echo "</table>"; }
/** * Print the user preference form * * @param $target form target * @param $ID integer Id of the user * * @return boolean : user found **/ function showMyForm($target, $ID) { global $CFG_GLPI, $PLUGIN_HOOKS; // Affiche un formulaire User if ($ID != Session::getLoginUserID() && !$this->currentUserHaveMoreRightThan($ID)) { return false; } if ($this->getFromDB($ID)) { $authtype = $this->getAuthMethodsByID(); $extauth = !($this->fields["authtype"] == Auth::DB_GLPI || $this->fields["authtype"] == Auth::NOT_YET_AUTHENTIFIED && !empty($this->fields["password"])); // No autocopletion : $save_autocompletion = $CFG_GLPI["use_ajax_autocompletion"]; $CFG_GLPI["use_ajax_autocompletion"] = false; echo "<div class='center'>"; echo "<form method='post' name='user_manager' action='" . $target . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . sprintf(__('%1$s: %2$s'), __('Login'), $this->fields["name"]); echo "<input type='hidden' name='name' value='" . $this->fields["name"] . "'>"; echo "<input type='hidden' name='id' value='" . $this->fields["id"] . "'>"; echo "</th></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Surname') . "</td><td>"; if ($extauth && isset($authtype['realname_field']) && !empty($authtype['realname_field'])) { echo $this->fields["realname"]; } else { Html::autocompletionTextField($this, "realname"); } echo "</td>"; //do some rights verification if (!$extauth && Session::haveRight("password_update", "1")) { echo "<td>" . __('Password') . "</td>"; echo "<td><input id='password' type='password' name='password' value='' size='30' autocomplete='off' onkeyup=\"return passwordCheck();\">"; echo "</td></tr>"; } else { echo "<td colspan='2'></tr>"; } echo "<tr class='tab_bg_1'><td>" . __('First name') . "</td><td>"; if ($extauth && isset($authtype['firstname_field']) && !empty($authtype['firstname_field'])) { echo $this->fields["firstname"]; } else { Html::autocompletionTextField($this, "firstname"); } echo "</td>"; if (!$extauth && Session::haveRight("password_update", "1")) { echo "<td>" . __('Password confirmation') . "</td>"; echo "<td><input type='password' name='password2' value='' size='30' autocomplete='off'>"; echo "</td></tr>"; } else { echo "<td colspan='2'></tr>"; } echo "<tr class='tab_bg_1'><td class='top'>" . _n('Email', 'Emails', 2); UserEmail::showAddEmailButton($this); echo "</td><td>"; UserEmail::showForUser($this); echo "</td>"; if (!$extauth && Session::haveRight("password_update", "1")) { echo "<td>" . __('Password security policy') . "</td>"; echo "<td>"; Config::displayPasswordSecurityChecks(); echo "</td>"; } else { echo "<td colspan='2'>"; } echo "</tr>"; echo "<tr class='tab_bg_1'><td>" . __('Mobile phone') . " :</td><td>"; if ($extauth && isset($authtype['mobile_field']) && !empty($authtype['mobile_field'])) { echo $this->fields["mobile"]; } else { Html::autocompletionTextField($this, "mobile"); } echo "</td>"; if (!GLPI_DEMO_MODE) { echo "<td>" . __('Language') . "</td><td>"; // Use session variable because field in table may be null if same of the global config Dropdown::showLanguages("language", array('value' => $_SESSION["glpilanguage"])); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Phone') . "</td><td>"; if ($extauth && isset($authtype['phone_field']) && !empty($authtype['phone_field'])) { echo $this->fields["phone"]; } else { Html::autocompletionTextField($this, "phone"); } echo "</td>"; if (count($_SESSION['glpiprofiles']) > 1) { echo "<td>" . __('Default profile') . "</td><td>"; $options = array(0 => Dropdown::EMPTY_VALUE); $options += Dropdown::getDropdownArrayNames('glpi_profiles', Profile_User::getUserProfiles($this->fields['id'])); Dropdown::showFromArray("profiles_id", $options, array('value' => $this->fields["profiles_id"])); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Phone 2') . "</td><td>"; if ($extauth && isset($authtype['phone2_field']) && !empty($authtype['phone2_field'])) { echo $this->fields["phone2"]; } else { Html::autocompletionTextField($this, "phone2"); } echo "</td>"; $entities = Profile_User::getUserEntities($this->fields['id'], 1); if (!GLPI_DEMO_MODE && count($_SESSION['glpiactiveentities']) > 1) { echo "<td>" . __('Default entity') . "</td><td>"; Entity::dropdown(array('value' => $this->fields['entities_id'], 'entity' => $entities)); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Location') . "</td><td>"; $entities = Profile_User::getUserEntities($ID, true); Location::dropdown(array('value' => $this->fields['locations_id'], 'entity' => $entities)); if (Session::haveRight("config", "w")) { echo "<td>" . __('Use GLPI in mode') . "</td><td>"; $modes[Session::NORMAL_MODE] = __('Normal'); //$modes[Session::TRANSLATION_MODE] = __('Translation'); $modes[Session::DEBUG_MODE] = __('Debug'); Dropdown::showFromArray('use_mode', $modes, array('value' => $this->fields["use_mode"])); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr><td class='tab_bg_2 center' colspan='4'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; $CFG_GLPI["use_ajax_autocompletion"] = $save_autocompletion; return true; } return false; }
static function getEmail($userid) { if (!UserEmail::getDefaultForUser($userid)) { return ''; } return UserEmail::getDefaultForUser($userid); }