/* For licensing terms, see /license.txt */ /** * Responses to AJAX calls */ //require_once '../global.inc.php'; $action = $_GET['a']; switch ($action) { case 'send_message': $subject = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : null; $messageContent = isset($_REQUEST['content']) ? trim($_REQUEST['content']) : null; if (empty($subject) || empty($messageContent)) { echo Display::display_error_message(get_lang('ErrorSendingMessage')); exit; } $result = MessageManager::send_message($_REQUEST['user_id'], $subject, $messageContent); if ($result) { echo Display::display_confirmation_message(get_lang('MessageHasBeenSent')); } else { echo Display::display_error_message(get_lang('ErrorSendingMessage')); } break; case 'send_invitation': $subject = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : null; $invitationContent = isset($_REQUEST['content']) ? trim($_REQUEST['content']) : null; SocialManager::send_invitation_friend_user($_REQUEST['user_id'], $subject, $invitationContent); break; case 'find_users': if (api_is_anonymous()) { echo ''; break;
/** * Subscribes users (students) to the given session and optionally (default) unsubscribes previous users * @author Carlos Vargas from existing code * @param integer Session ID * @param array List of user IDs * @param bool Whether to unsubscribe existing users (true, default) or not (false) * @return void Nothing, or false on error **/ public static function suscribe_users_to_session($id_session, $user_list, $session_visibility = SESSION_VISIBLE_READ_ONLY, $empty_users = true, $send_email = false) { if ($id_session != strval(intval($id_session))) { return false; } foreach ($user_list as $intUser) { if ($intUser != strval(intval($intUser))) { return false; } } $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $session_info = api_get_session_info($id_session); if ($session_info) { $session_name = $session_info['name']; } else { return false; } //from function parameter if (empty($session_visibility)) { $session_visibility = $session_info['visibility']; //loaded from DB //default status loaded if empty if (empty($session_visibility)) { $session_visibility = SESSION_VISIBLE_READ_ONLY; } // by default readonly 1 } else { if (!in_array($session_visibility, array(SESSION_VISIBLE_READ_ONLY, SESSION_VISIBLE, SESSION_INVISIBLE))) { $session_visibility = SESSION_VISIBLE_READ_ONLY; } } $sql = "SELECT id_user FROM {$tbl_session_rel_course_rel_user} WHERE id_session = '{$id_session}' AND status = 0"; $result = Database::query($sql); $existingUsers = array(); while ($row = Database::fetch_array($result)) { $existingUsers[] = $row['id_user']; } $sql = "SELECT c_id FROM {$tbl_session_rel_course} WHERE id_session = '{$id_session}'"; $result = Database::query($sql); $course_list = array(); while ($row = Database::fetch_array($result)) { $course_list[] = $row['c_id']; } if ($send_email) { //sending emails only if (is_array($user_list) && count($user_list) > 0) { foreach ($user_list as $user_id) { if (!in_array($user_id, $existingUsers)) { $subject = '[' . get_setting('siteName') . '] ' . get_lang('YourReg') . ' ' . get_setting('siteName'); $user_info = api_get_user_info($user_id); $content = get_lang('Dear') . " " . stripslashes($user_info['complete_name']) . ",\n\n" . sprintf(get_lang('YouAreRegisterToSessionX'), $session_name) . " \n\n" . get_lang('Address') . " " . api_get_setting('siteName') . " " . get_lang('Is') . " : " . api_get_path(WEB_PATH) . "\n\n" . get_lang('Problem') . "\n\n" . get_lang('Formula') . ",\n\n" . get_setting('administratorName') . " " . get_setting('administratorSurname') . "\n" . get_lang('Manager') . " " . get_setting('siteName') . "\nT. " . get_setting('administratorTelephone') . "\n" . get_lang('Email') . " : " . get_setting('emailAdministrator'); MessageManager::send_message($user_id, $subject, $content, array(), array(), null, null, null, null, null); } } } } foreach ($course_list as $courseId) { // for each course in the session $nbr_users = 0; $courseId = Database::escape_string($courseId); // delete existing users if ($empty_users) { foreach ($existingUsers as $existing_user) { if (!in_array($existing_user, $user_list)) { $sql = "DELETE FROM {$tbl_session_rel_course_rel_user} WHERE id_session='{$id_session}' AND c_id ='{$courseId}' AND id_user='******' AND status = 0"; $result = Database::query($sql); if (Database::affected_rows($result)) { $nbr_users--; } } } } //Replace with this new function // // insert new users into session_rel_course_rel_user and ignore if they already exist foreach ($user_list as $enreg_user) { if (!in_array($enreg_user, $existingUsers)) { $enreg_user = Database::escape_string($enreg_user); $insert_sql = "INSERT IGNORE INTO {$tbl_session_rel_course_rel_user}(id_session, c_id, id_user, visibility, status) VALUES('{$id_session}','{$courseId}','{$enreg_user}','{$session_visibility}', '0')"; $result = Database::query($insert_sql); if (Database::affected_rows($result)) { $nbr_users++; } } } // count users in this session-course relation $sql = "SELECT COUNT(id_user) as nbUsers FROM {$tbl_session_rel_course_rel_user} WHERE id_session='{$id_session}' AND c_id ='{$courseId}' AND status<>2"; $rs = Database::query($sql); list($nbr_users) = Database::fetch_array($rs); // update the session-course relation to add the users total $update_sql = "UPDATE {$tbl_session_rel_course} SET nbr_users = {$nbr_users} WHERE id_session='{$id_session}' AND c_id ='{$courseId}'"; Database::query($update_sql); } // Delete users from the session if ($empty_users === true) { Database::query("DELETE FROM {$tbl_session_rel_user} WHERE id_session = {$id_session} AND relation_type<>" . SESSION_RELATION_TYPE_RRHH . ""); } // Insert missing users into session $nbr_users = 0; foreach ($user_list as $enreg_user) { $enreg_user = Database::escape_string($enreg_user); $insert_sql = "INSERT IGNORE INTO {$tbl_session_rel_user} (id_session, id_user) VALUES ('{$id_session}', '{$enreg_user}')"; Database::query($insert_sql); //Reset moved_to just in case $update_sql = "UPDATE {$tbl_session_rel_user} SET moved_to = 0, moved_status = 0, moved_at ='0000-00-00 00:00:00'\n WHERE id_session = {$id_session} AND id_user = {$enreg_user}"; Database::query($update_sql); $nbr_users++; } // update number of users in the session $nbr_users = count($user_list); if ($empty_users) { // update number of users in the session $update_sql = "UPDATE {$tbl_session} SET nbr_users = {$nbr_users} WHERE id='{$id_session}' "; Database::query($update_sql); } else { $update_sql = "UPDATE {$tbl_session} SET nbr_users = nbr_users + {$nbr_users} WHERE id='{$id_session}' "; Database::query($update_sql); } }
$user_list = isset($_POST['invitation']) ? $_POST['invitation'] : null; $group_id = intval($_POST['id']); if (!is_array($user_list)) { $user_list = array(); } if ($form_sent == 1) { // invite this users $result = $usergroup->add_users_to_groups($user_list, array($group_id), GROUP_USER_PERMISSION_PENDING_INVITATION); $title = get_lang('YouAreInvitedToGroup') . ' ' . $group_info['name']; $content = get_lang('YouAreInvitedToGroupContent') . ' ' . $group_info['name'] . ' <br />'; $content .= get_lang('ToSubscribeClickInTheLinkBelow') . ' <br />'; $content .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php?accept=' . $group_id . '">' . get_lang('Subscribe') . '</a>'; if (is_array($user_list) && count($user_list) > 0) { //send invitation message foreach ($user_list as $user_id) { $result = MessageManager::send_message($user_id, $title, $content); } Display::addFlash(Display::return_message(get_lang('InvitationSent'))); } header('Location: ' . api_get_self() . '?id=' . $group_id); exit; } } $nosessionUsersList = $sessionUsersList = array(); $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; $friends = SocialManager::get_friends(api_get_user_id()); $suggest_friends = false; $Users = array(); if (!$friends) { $suggest_friends = true; } else {
/** * Send the invitation by mail. * * @param int invitedUser - the userId (course user) or emailaddress of additional user * $param string $invitation_code - the unique invitation code for the URL * @return void */ public static function send_invitation_mail($invitedUser, $invitation_code, $invitation_title, $invitation_text) { $_user = api_get_user_info(); $_course = api_get_course_info(); // Replacing the **link** part with a valid link for the user $survey_link = api_get_path(WEB_CODE_PATH) . 'survey/fillsurvey.php?course=' . $_course['code'] . '&invitationcode=' . $invitation_code; $text_link = '<a href="' . $survey_link . '">' . get_lang('ClickHereToAnswerTheSurvey') . "</a><br />\r\n<br />\r\n" . get_lang('OrCopyPasteTheFollowingUrl') . " <br />\r\n " . $survey_link; $replace_count = 0; $full_invitation_text = api_str_ireplace('**link**', $text_link, $invitation_text, $replace_count); if ($replace_count < 1) { $full_invitation_text = $full_invitation_text . "<br />\r\n<br />\r\n" . $text_link; } // Sending the mail $sender_name = api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS); $sender_email = $_user['mail']; $sender_user_id = api_get_user_id(); $replyto = array(); if (api_get_setting('survey.survey_email_sender_noreply') == 'noreply') { $noreply = api_get_setting('mail.noreply_email_address'); if (!empty($noreply)) { $replyto['Reply-to'] = $noreply; $sender_name = $noreply; $sender_email = $noreply; $sender_user_id = null; } } // Optionally: finding the e-mail of the course user if (is_numeric($invitedUser)) { $table_user = Database::get_main_table(TABLE_MAIN_USER); $sql = "SELECT firstname, lastname, email FROM {$table_user}\n WHERE user_id='" . Database::escape_string($invitedUser) . "'"; $result = Database::query($sql); $row = Database::fetch_array($result); $recipient_email = $row['email']; $recipient_name = api_get_person_name($row['firstname'], $row['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); MessageManager::send_message($invitedUser, $invitation_title, $full_invitation_text, [], [], null, null, null, null, $sender_user_id); } else { /** @todo check if the address is a valid email */ $recipient_email = $invitedUser; @api_mail_html($recipient_name, $recipient_email, $invitation_title, $full_invitation_text, $sender_name, $sender_email, $replyto); } }
/** * @param int $receiver_user_id * @param int $subject * @param string $message * @param int $sender_id * @param bool $sendCopyToDrhUsers send copy to related DRH users * @param bool $directMessage * * @return bool */ public static function send_message_simple($receiver_user_id, $subject, $message, $sender_id = null, $sendCopyToDrhUsers = false, $directMessage = false) { $result = MessageManager::send_message($receiver_user_id, $subject, $message, null, null, null, null, null, null, $sender_id, $directMessage); if ($sendCopyToDrhUsers) { $userInfo = api_get_user_info($receiver_user_id); $drhList = UserManager::getDrhListFromUser($receiver_user_id); if (!empty($drhList)) { foreach ($drhList as $drhInfo) { $message = sprintf(get_lang('CopyOfMessageSentToXUser'), $userInfo['complete_name']) . ' <br />' . $message; MessageManager::send_message_simple($drhInfo['user_id'], $subject, $message, $sender_id, false, $directMessage); } } } return $result; }
/** * A handy way to send message */ public static function send_message_simple($receiver_user_id, $subject, $htmlBody, $sender_id = null, $textBody = null) { return MessageManager::send_message($receiver_user_id, $subject, $htmlBody, null, null, null, null, null, null, $sender_id, $textBody); }
$emailbody = get_lang('ApprovalForNewAccount', null, $values['language']) . "\n"; $emailbody .= get_lang('UserName', null, $values['language']) . ': ' . $values['username'] . "\n"; if (api_is_western_name_order()) { $emailbody .= get_lang('FirstName', null, $values['language']) . ': ' . $values['firstname'] . "\n"; $emailbody .= get_lang('LastName', null, $values['language']) . ': ' . $values['lastname'] . "\n"; } else { $emailbody .= get_lang('LastName', null, $values['language']) . ': ' . $values['lastname'] . "\n"; $emailbody .= get_lang('FirstName', null, $values['language']) . ': ' . $values['firstname'] . "\n"; } $emailbody .= get_lang('Email', null, $values['language']) . ': ' . $values['email'] . "\n"; $emailbody .= get_lang('Status', null, $values['language']) . ': ' . $values['status'] . "\n\n"; $url_edit = Display::url(api_get_path(WEB_CODE_PATH) . 'admin/user_edit.php?user_id=' . $user_id, api_get_path(WEB_CODE_PATH) . 'admin/user_edit.php?user_id=' . $user_id); $emailbody .= get_lang('ManageUser', null, $values['language']) . ": {$url_edit}"; $admins = UserManager::get_all_administrators(); foreach ($admins as $admin_info) { MessageManager::send_message($admin_info['user_id'], $emailsubject, $emailbody, null, null, null, null, null, null, $user_id); } // 3. exit the page unset($user_id); Display::display_header($tool_name); echo Display::page_header($tool_name); echo $content; Display::display_footer(); exit; } } } // Terms & Conditions if (api_get_setting('registration.allow_terms_conditions') == 'true') { // Update the terms & conditions. if (isset($values['legal_accept_type'])) {
/** * This function sends the mails for the mail notification * * @param array * @param array * @return void * * @author Patrick Cool <*****@*****.**>, Ghent University * @version february 2006, dokeos 1.8 */ function send_mail($user_info = array(), $thread_information = array()) { $_course = api_get_course_info(); $user_id = api_get_user_id(); $subject = get_lang('NewForumPost') . ' - ' . $_course['official_code']; if (isset($thread_information) && is_array($thread_information)) { $thread_link = api_get_path(WEB_CODE_PATH) . 'forum/viewthread.php?' . api_get_cidreq() . '&forum=' . $thread_information['forum_id'] . '&thread=' . $thread_information['thread_id']; } $email_body = get_lang('Dear') . ' ' . api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS) . ", <br />\n\r"; $email_body .= get_lang('NewForumPost') . "\n"; $email_body .= get_lang('Course') . ': ' . $_course['name'] . ' - [' . $_course['official_code'] . "] - <br />\n"; $email_body .= get_lang('YouWantedToStayInformed') . "<br />\n"; $email_body .= get_lang('ThreadCanBeFoundHere') . " : <br /><a href=\"" . $thread_link . "\">" . $thread_link . "</a>\n"; if ($user_info['user_id'] != $user_id) { MessageManager::send_message($user_info['user_id'], $subject, $email_body, null, null, null, null, null, null, $user_id); } }
$title = urldecode($info_reply[0]); $content = str_replace("\\", "", urldecode($info_reply[1])); $user_reply = $info_reply[2]; $user_email_base = str_replace(')', '(', $info_reply[5]); $user_email_prepare = explode('(', $user_email_base); if (count($user_email_prepare) == 1) { $user_email = trim($user_email_prepare[0]); } elseif (count($user_email_prepare) == 3) { $user_email = trim($user_email_prepare[1]); } $user_id_by_email = MessageManager::get_user_id_by_email($user_email); if ($info_reply[6] == 'save_form') { $user_id_by_email = $info_reply[2]; } if (isset($user_reply) && !is_null($user_id_by_email) && strlen($info_reply[0]) > 0) { MessageManager::send_message($user_id_by_email, $title, $content); Display::addFlash(MessageManager::return_message($user_id_by_email, 'confirmation')); $social_right_content .= MessageManager::inbox_display(); exit; } elseif (is_null($user_id_by_email)) { $message_box = get_lang('ErrorSendingMessage'); Display::return_message(api_xml_http_response_encode($message_box), 'error'); $social_right_content .= MessageManager::inbox_display(); exit; } } elseif (trim($info_delete[0]) == 'delete') { for ($i = 1; $i <= $count_delete; $i++) { MessageManager::delete_message_by_user_receiver(api_get_user_id(), $info_delete[$i]); } $message_box = get_lang('SelectedMessagesDeleted'); Display::return_message(api_xml_http_response_encode($message_box));
/** * Sends invitations to friends * @author Isaac Flores Paz <*****@*****.**> * @author Julio Montoya <*****@*****.**> Cleaning code * @param void * @return string message invitation */ public static function send_invitation_friend_user($userfriend_id, $subject_message = '', $content_message = '') { global $charset; $user_info = api_get_user_info($userfriend_id); $succes = get_lang('MessageSentTo'); $succes .= ' : ' . api_get_person_name($user_info['firstName'], $user_info['lastName']); if (isset($subject_message) && isset($content_message) && isset($userfriend_id)) { $send_message = MessageManager::send_message($userfriend_id, $subject_message, $content_message); if ($send_message) { Display::addFlash(Display::display_confirmation_message($succes, true, true)); } else { Display::addFlash(Display::display_error_message(get_lang('ErrorSendingMessage'), true, true)); } return false; } elseif (isset($userfriend_id) && !isset($subject_message)) { $count_is_true = false; if (isset($userfriend_id) && $userfriend_id > 0) { $message_title = get_lang('Invitation'); $count_is_true = self::send_invitation_friend(api_get_user_id(), $userfriend_id, $message_title, $content_message); if ($count_is_true) { Display::addFlash(Display::display_confirmation_message(api_htmlentities(get_lang('InvitationHasBeenSent'), ENT_QUOTES, $charset), false, true)); } else { Display::addFlash(Display::display_warning_message(api_htmlentities(get_lang('YouAlreadySentAnInvitation'), ENT_QUOTES, $charset), false, true)); } } } }
/** * A handy way to send message */ public static function send_message_simple($receiver_user_id, $subject, $message, $sender_id = null) { return MessageManager::send_message($receiver_user_id, $subject, $message, null, null, null, null, null, null, $sender_id); }
/** * Send reminder to users who have not given the task * * @param int * @return array * @author cvargas carlos.vargas@beeznest.com cfasanando, christian.fasanado@beeznest.com */ function send_reminder_users_without_publication($task_data) { global $_course; $task_id = $task_data['id']; $task_title = !empty($task_data['title']) ? $task_data['title'] : basename($task_data['url']); $subject = '[' . api_get_setting('siteName') . '] '; // The body can be as long as you wish, and any combination of text and variables $content = get_lang('ReminderToSubmitPendingTask')."\n".get_lang('CourseName').' : '.$_course['name']."\n"; $content .= get_lang('WorkName').' : '.$task_title."\n"; $list_users = get_list_users_without_publication($task_id); $mails_sent_to = array(); foreach ($list_users as $user) { $name_user = api_get_person_name($user[1], $user[0], null, PERSON_NAME_EMAIL_ADDRESS); $dear_line = get_lang('Dear')." ".api_get_person_name($user[1], $user[0]) .", \n\n"; $body = $dear_line.$content; MessageManager::send_message($user[3], $subject, $body); $mails_sent_to[] = $name_user; } return $mails_sent_to; }
/** * Get all the users who need to receive a notification of a new post (those subscribed to * the forum or the thread) * * @param integer $forum_id the id of the forum * @param integer $thread_id the id of the thread * @param integer $post_id the id of the post * @return bool * * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium * @version May 2008, dokeos 1.8.5 * @since May 2008, dokeos 1.8.5 */ function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0) { global $_user; $_course = api_get_course_info(); // The content of the mail $thread_link = api_get_path(WEB_CODE_PATH) . 'forum/viewthread.php?' . api_get_cidreq() . '&forum=' . $forum_id . '&thread=' . $thread_id; // Users who subscribed to the forum if ($forum_id != 0) { $users_to_be_notified_by_forum = get_notifications('forum', $forum_id); } else { return false; } $current_thread = get_thread_information($thread_id); $current_forum = get_forum_information($current_thread['forum_id']); $subject = get_lang('NewForumPost') . ' - ' . $_course['official_code'] . ' - ' . $current_forum['forum_title'] . ' - ' . $current_thread['thread_title']; // User who subscribed to the thread if ($thread_id != 0) { $users_to_be_notified_by_thread = get_notifications('thread', $thread_id); } // Merging the two $users_to_be_notified = array_merge($users_to_be_notified_by_forum, $users_to_be_notified_by_thread); $sender_id = api_get_user_id(); if (is_array($users_to_be_notified)) { foreach ($users_to_be_notified as $value) { if ($value['email'] != $_user['email']) { $user_info = api_get_user_info($value['user_id']); $email_body = get_lang('Dear') . ' ' . api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS) . ", <br />\n\r"; $email_body .= get_lang('NewForumPost') . ": " . $current_forum['forum_title'] . ' - ' . $current_thread['thread_title'] . " <br />\n"; $email_body .= get_lang('Course') . ': ' . $_course['name'] . ' - [' . $_course['official_code'] . "] <br />\n"; $email_body .= get_lang('YouWantedToStayInformed') . "<br />\n"; $email_body .= get_lang('ThreadCanBeFoundHere') . ': <br /> <a href="' . $thread_link . '">' . $thread_link . "</a>\n"; MessageManager::send_message($value['user_id'], $subject, $email_body, null, null, null, null, null, null, $sender_id); } } } }
<?php /* For licensing terms, see /license.txt */ /** * Responses to AJAX calls */ $language_file = array('messages', 'userInfo'); require_once '../global.inc.php'; $action = $_GET['a']; switch ($action) { case 'send_message': $result = MessageManager::send_message($_REQUEST['user_id'], $_REQUEST['subject'], $_REQUEST['content']); if ($result) { echo Display::display_confirmation_message(get_lang('MessageHasBeenSent')); } else { echo Display::display_error_message(get_lang('ErrorSendingMessage')); } break; case 'send_invitation': $subject = isset($_REQUEST['subject']) ? $_REQUEST['subject'] : null; SocialManager::send_invitation_friend_user($_REQUEST['user_id'], $subject, $_REQUEST['content']); break; case 'find_users': if (api_is_anonymous()) { echo ''; break; } $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); $tbl_my_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_my_user_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$group_id, $parent_id, $edit_message_id, 0, $topic_id ); } else { if ($_POST['action'] == 'add_message_group' && !$is_member) { api_not_allowed(); } $res = MessageManager::send_message( 0, $title, $content, $_FILES, '', $group_id, $parent_id, 0, $topic_id ); } // display error messages if (!$res) { $social_right_content .= Display::return_message( get_lang('Error'), 'error' ); } $topic_id = intval($_GET['topic_id']);
/** * Send the invitation by mail. * * @param invitedUser - the userId (course user) or emailaddress of additional user * $param $invitation_code - the unique invitation code for the URL * @return void */ static function send_invitation_mail($invitedUser, $invitation_code, $invitation_title, $invitation_text) { global $_user, $_course, $_configuration; $portal_url = api_get_path(WEB_CODE_PATH); if (api_is_multiple_url_enabled()) { $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1) { $url = api_get_access_url($access_url_id); $portal_url = $url['url']; } } // Replacing the **link** part with a valid link for the user $survey_link = api_get_path(WEB_CODE_PATH) . 'survey/fillsurvey.php?course=' . $_course['code'] . '&invitationcode=' . $invitation_code; $text_link = '<a href="' . $survey_link . '">' . get_lang('ClickHereToAnswerTheSurvey') . "</a><br />\r\n<br />\r\n" . get_lang('OrCopyPasteTheFollowingUrl') . " <br />\r\n " . $survey_link; $replace_count = 0; $full_invitation_text = api_str_ireplace('**link**', $text_link, $invitation_text, $replace_count); if ($replace_count < 1) { $full_invitation_text = $full_invitation_text . "<br />\r\n<br />\r\n" . $text_link; } // Sending the mail $sender_name = api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS); $sender_email = $_user['mail']; $sender_user_id = api_get_user_id(); $replyto = array(); if (api_get_setting('survey_email_sender_noreply') == 'noreply') { $noReply = api_get_setting('noreply_email_address'); if (!empty($noReply)) { $sender_name = $noReply; $sender_email = $noReply; $sender_user_id = null; } } // Optionally: finding the e-mail of the user if (is_numeric($invitedUser)) { MessageManager::send_message($invitedUser, $invitation_title, $full_invitation_text, null, null, null, null, null, null, $sender_user_id); } else { /** @todo check if the address is a valid email */ $recipient_email = $invitedUser; @api_mail_html(null, $recipient_email, $invitation_title, $full_invitation_text, $sender_name, $sender_email); } }
function manage_form($default, $select_from_user_list = null, $sent_to = null) { $group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null; $message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null; $param_f = isset($_GET['f']) && $_GET['f'] == 'social' ? 'social' : null; $form = new FormValidator('compose_message', null, api_get_self() . '?f=' . $param_f, null, array('enctype' => 'multipart/form-data')); if (empty($group_id)) { if (isset($select_from_user_list)) { $form->addText('id_text_name', get_lang('SendMessageTo'), true, array('id' => 'id_text_name', 'onkeyup' => 'send_request_and_search()', 'autocomplete' => 'off')); $form->addRule('id_text_name', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('html', '<div id="id_div_search" style="padding:0px" class="message-select-box" > </div>'); $form->addElement('hidden', 'user_list', 0, array('id' => 'user_list')); } else { if (!empty($sent_to)) { $form->addLabel(get_lang('SendMessageTo'), $sent_to); } if (empty($default['users'])) { //fb select $form->addElement('select_ajax', 'users', get_lang('SendMessageTo'), array(), ['multiple' => 'multiple', 'url' => api_get_path(WEB_AJAX_PATH) . 'message.ajax.php?a=find_users']); } else { $form->addElement('hidden', 'hidden_user', $default['users'][0], array('id' => 'hidden_user')); } } } else { $userGroup = new UserGroup(); $group_info = $userGroup->get($group_id); $form->addElement('label', get_lang('ToGroup'), api_xml_http_response_encode($group_info['name'])); $form->addElement('hidden', 'group_id', $group_id); $form->addElement('hidden', 'parent_id', $message_id); } $form->addText('title', get_lang('Subject'), true); $form->addHtmlEditor('content', get_lang('Message'), false, false, array('ToolbarSet' => 'Messages', 'Width' => '100%', 'Height' => '250')); if (isset($_GET['re_id'])) { $message_reply_info = MessageManager::get_message_by_id($_GET['re_id']); $default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_reply_info['title']; $form->addElement('hidden', 're_id', intval($_GET['re_id'])); $form->addElement('hidden', 'save_form', 'save_form'); //adding reply mail $user_reply_info = api_get_user_info($message_reply_info['user_sender_id']); $default['content'] = '<p><br/></p>' . sprintf(get_lang('XWroteY'), $user_reply_info['complete_name'], Security::filter_terms($message_reply_info['content'])); } if (empty($group_id)) { $form->addElement('label', '', '<div id="filepaths" class="form-group"> <div id="filepath_1"> <label>' . get_lang('FilesAttachment') . '</label> <input type="file" name="attach_1"/> <label>' . get_lang('Description') . '</label> <input id="file-descrtiption" type="text" name="legend[]" class="form-control"/> </div> </div>'); $form->addElement('label', '', '<span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()">' . get_lang('AddOneMoreFile') . '</a></span> (' . sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message.message_max_upload_filesize'))) . ')'); } $form->addButtonSend(get_lang('SendMessage'), 'compose'); $form->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>'); if (!empty($group_id) && !empty($message_id)) { $message_info = MessageManager::get_message_by_id($message_id); $default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_info['title']; } $form->setDefaults($default); $html = ''; if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $user_list = $default['users']; $file_comments = $_POST['legend']; $title = $default['title']; $content = $default['content']; $group_id = isset($default['group_id']) ? $default['group_id'] : null; $parent_id = isset($default['parent_id']) ? $default['parent_id'] : null; if (is_array($user_list) && count($user_list) > 0) { //all is well, send the message foreach ($user_list as $user) { $res = MessageManager::send_message($user, $title, $content, $_FILES, $file_comments, $group_id, $parent_id); if ($res) { $html .= MessageManager::display_success_message($user); } } } else { Display::display_error_message('ErrorSendingMessage'); } } Security::clear_token(); } else { $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $html .= $form->returnForm(); } return $html; }
/** * Send message for the student subscription approval to a specific session * @param int|array $studentId * @param int $receiverId * @param string $subject * @param string $content * @param int $sessionId * @param bool $save * @param array $fileAttachments * @return bool|int */ public function sendMailMessage($studentId, $receiverId, $subject, $content, $sessionId, $save = false, $fileAttachments = array()) { if (!empty($fileAttachments) && is_array($fileAttachments) && isset($fileAttachments['files']) && isset($fileAttachments['comments'])) { $mailId = MessageManager::send_message($receiverId, $subject, $content, $fileAttachments['files'], $fileAttachments['comments']); } else { $mailId = MessageManager::send_message($receiverId, $subject, $content); } if ($save && !empty($mailId)) { // Save as sent message if (is_array($studentId) && !empty($studentId)) { foreach ($studentId as $student) { $this->saveLastMessage($mailId, $student['user_id'], $sessionId); } } else { $studentId = intval($studentId); $this->saveLastMessage($mailId, $studentId, $sessionId); } } elseif (!empty($mailId)) { // Update queue row, updated_at Database::update(Database::get_main_table(TABLE_ADVANCED_SUBSCRIPTION_QUEUE), array('updated_at' => api_get_utc_datetime()), array('user_id = ? AND session_id = ?' => array($studentId, $sessionId))); } return $mailId; }