Get all emails for user.
static public getAllForUser ( $users_id ) : array | ||
$users_id | user ID | |
return | array | of emails |
/** * Get all emails of the user * * @return array of emails **/ function getAllEmails() { if (!isset($this->fields['id'])) { return ''; } return UserEmail::getAllForUser($this->fields['id']); }
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; }
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>"; }
/** * 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); }
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; }