Database::query($sql); if (isset($_POST['send_notification'])) { //@todo move this somewhere else $subject = get_lang('ExamSheetVCC'); $message = '<p>' . get_lang('DearStudentEmailIntroduction') . '</p><p>' . get_lang('AttemptVCC'); $message .= '<h3>' . get_lang('CourseName') . '</h3><p>' . Security::remove_XSS($course_info['name']) . ''; $message .= '<h3>' . get_lang('Exercise') . '</h3><p>' . Security::remove_XSS($test); //Only for exercises not in a LP if ($lp_id == 0) { $message .= '<p>' . get_lang('ClickLinkToViewComment') . ' <a href="#url#">#url#</a><br />'; } $message .= '<p>' . get_lang('Regards') . '</p>'; $message .= $from_name; $message = str_replace("#test#", Security::remove_XSS($test), $message); $message = str_replace("#url#", $url, $message); MessageManager::send_message_simple($student_id, $subject, $message, api_get_user_id()); if ($allowCoachFeedbackExercises) { Display::addFlash(Display::return_message(get_lang('MessageSent'))); header('Location: ' . api_get_path(WEB_PATH)); exit; } } //Updating LP score here if (in_array($origin, array('tracking_course', 'user_course', 'correct_exercise_in_lp'))) { $sql = "UPDATE {$TBL_LP_ITEM_VIEW} SET score = '" . floatval($tot) . "'\n WHERE c_id = " . $course_id . " AND id = " . $lp_item_view_id; Database::query($sql); if ($origin == 'tracking_course') { //Redirect to the course detail in lp header('location: exercise.php?course=' . Security::remove_XSS($_GET['course'])); exit; } else {
/** * @param string $uniqueId * @param int $userId * @param int $courseId * @param int $sessionId */ public function sendMailLink($uniqueId, $userId, $courseId, $sessionId) { $courseInfo = api_get_course_info_by_id($courseId); $courseCode = $courseInfo['code']; $url = api_get_path(WEB_CODE_PATH) . 'course_info/legal.php?web_agreement_link=' . $uniqueId . '&course_code=' . Security::remove_XSS($courseCode) . '&session_id=' . $sessionId; $courseUrl = Display::url($url, $url); $sessionInfo = api_get_session_info($sessionId); $sesstionTitle = null; if (!empty($sessionInfo)) { $sesstionTitle = ' (' . $sessionInfo['name'] . ')'; } $courseTitle = $courseInfo['title'] . $sesstionTitle; $subject = $this->get_lang("MailAgreement"); $message = sprintf($this->get_lang("MailAgreementWasSentWithClickX"), $courseTitle, $courseUrl); MessageManager::send_message_simple($userId, $subject, $message); }
/** * @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; }
/** * Send a system announcement by e-mail to all teachers/students depending on parameters * @param string Title * @param string Content * @param int Whether to send to all teachers (1) or not (0) * @param int Whether to send to all students (1) or not (0) * @param string Language (optional, considered for all languages if left empty) * @return bool True if the message was sent or there was no destination matching. False on database or e-mail sending error. */ public static function send_system_announcement_by_email($title, $content, $teacher, $student, $language = null, $sendEmailTest = false) { global $charset; $title = api_html_entity_decode(stripslashes($title), ENT_QUOTES, $charset); $content = api_html_entity_decode(stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), '', $content)), ENT_QUOTES, $charset); if ($sendEmailTest) { MessageManager::send_message_simple(api_get_user_id(), $title, $content); return true; } $user_table = Database::get_main_table(TABLE_MAIN_USER); if (api_is_multiple_url_enabled()) { $current_access_url_id = api_get_current_access_url_id(); $url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $url_condition = " INNER JOIN {$url_rel_user} uu ON uu.user_id = u.user_id "; } if ($teacher != 0 and $student == 0) { $sql = "SELECT DISTINCT u.user_id FROM {$user_table} u {$url_condition} WHERE status = '1' "; } if ($teacher == 0 and $student != 0) { $sql = "SELECT DISTINCT u.user_id FROM {$user_table} u {$url_condition} WHERE status = '5' "; } if ($teacher != 0 and $student != 0) { $sql = "SELECT DISTINCT u.user_id FROM {$user_table} u {$url_condition} WHERE 1 = 1 "; } if (!empty($language)) { //special condition because language was already treated for SQL insert before $sql .= " AND language = '" . Database::escape_string($language) . "' "; } if (api_is_multiple_url_enabled()) { $sql .= " AND access_url_id = '" . $current_access_url_id . "' "; } // Sent to active users. $sql .= " AND email <>'' AND active = 1 "; if ((empty($teacher) or $teacher == '0') and (empty($student) or $student == '0')) { return true; } $result = Database::query($sql); if ($result === false) { return false; } $message_sent = false; while ($row = Database::fetch_array($result, 'ASSOC')) { MessageManager::send_message_simple($row['user_id'], $title, $content); $message_sent = true; } return $message_sent; //true if at least one e-mail was sent }
/** * Send emails to users. * @param bool $sendToUsersInSession * @param bool $sendToDrhUsers send a copy of the message to the DRH users * related to the main user */ public function send($sendToUsersInSession = false, $sendToDrhUsers = false) { $sender = $this->sender(); $subject = $this->subject(); // Send email one by one to avoid antispam $users = $this->sent_to(); foreach ($users as $user) { $message = $this->message($user['user_id']); MessageManager::send_message_simple($user['user_id'], $subject, $message, $sender['user_id'], $sendToDrhUsers, true); } if ($sendToUsersInSession) { $sessionList = SessionManager::get_session_by_course($this->course['real_id']); if (!empty($sessionList)) { foreach ($sessionList as $sessionInfo) { $sessionId = $sessionInfo['id']; $message = $this->message(null, $sessionId); $userList = CourseManager::get_user_list_from_course_code($this->course['code'], $sessionId); if (!empty($userList)) { foreach ($userList as $user) { MessageManager::send_message_simple($user['user_id'], $subject, $message, $sender['user_id'], false, true); } } } } } $this->log_mail_sent(); }
function send_notification_for_oral_questions($question_list_answers, $origin, $exe_id) { if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1) { return null; } // Email configuration settings $courseCode = api_get_course_id(); $course_info = api_get_course_info($courseCode); $url_email = api_get_path(WEB_CODE_PATH) . 'exercice/exercise_show.php?' . api_get_cidreq() . '&id_session=' . api_get_session_id() . '&id=' . $exe_id . '&action=qualify'; $user_info = api_get_user_info(api_get_user_id()); $oral_question_list = null; foreach ($question_list_answers as $item) { $question = $item['question']; $answer = $item['answer']; $answer_type = $item['answer_type']; if (!empty($question) && !empty($answer) && $answer_type == ORAL_EXPRESSION) { $oral_question_list .= '<br /><table width="730" height="136" border="0" cellpadding="3" cellspacing="3">' . '<tr>' . '<td width="220" valign="top" bgcolor="#E5EDF8"> ' . get_lang('Question') . '</td>' . '<td width="473" valign="top" bgcolor="#F3F3F3">' . $question . '</td>' . '</tr>' . '<tr>' . '<td width="220" valign="top" bgcolor="#E5EDF8"> ' . get_lang('Answer') . '</td>' . '<td valign="top" bgcolor="#F3F3F3">' . $answer . '</td>' . '</tr></table>'; } } if (!empty($oral_question_list)) { $msg = get_lang('OralQuestionsAttempted') . '<br /><br /> ' . get_lang('AttemptDetails') . ' : <br /><br />' . '<table>' . '<tr>' . '<td><em>' . get_lang('CourseName') . '</em></td>' . '<td> <b>#course#</b></td>' . '</tr>' . '<tr>' . '<td>' . get_lang('TestAttempted') . '</td>' . '<td> #exercise#</td>' . '</tr>' . '<tr>' . '<td>' . get_lang('StudentName') . '</td>' . '<td> #firstName# #lastName#</td>' . '</tr>' . '<tr>' . '<td>' . get_lang('StudentEmail') . '</td>' . '<td> #mail#</td>' . '</tr>' . '</table>'; $msg .= '<br />' . sprintf(get_lang('OralQuestionsAttemptedAreX'), $oral_question_list) . '<br />'; $msg1 = str_replace("#exercise#", $this->exercise, $msg); $msg = str_replace("#firstName#", $user_info['firstname'], $msg1); $msg1 = str_replace("#lastName#", $user_info['lastname'], $msg); $msg = str_replace("#mail#", $user_info['email'], $msg1); $msg = str_replace("#course#", $course_info['name'], $msg1); if ($origin != 'learnpath') { $msg .= '<br /><a href="#url#">' . get_lang('ClickToCommentAndGiveFeedback') . '</a>'; } $msg1 = str_replace("#url#", $url_email, $msg); $mail_content = $msg1; $subject = get_lang('OralQuestionsAttempted'); if (api_get_session_id()) { $teachers = CourseManager::get_coach_list_from_course_code($courseCode, api_get_session_id()); } else { $teachers = CourseManager::getTeacherListFromCourse($course_info['real_id']); } if (!empty($teachers)) { foreach ($teachers as $user_id => $teacher_data) { MessageManager::send_message_simple($user_id, $subject, $mail_content); } } } }
/** * @param int $workId * @param array $courseInfo * @param int $session_id */ function sendAlertToTeacher($workId, $courseInfo, $session_id) { $workData = get_work_assignment_by_id($workId, $courseInfo['real_id']); //last value is to check this is not "just" an edit //YW Tis part serve to send a e-mail to the tutors when a new file is sent $send = api_get_course_setting('email_alert_manager_on_new_doc'); if ($send > 0) { // Lets predefine some variables. Be sure to change the from address! if (empty($session_id)) { //Teachers $user_list = CourseManager::get_user_list_from_course_code( api_get_course_id(), null, null, null, COURSEMANAGER ); } else { // Coaches $user_list = CourseManager::get_user_list_from_course_code( api_get_course_id(), $session_id, null, null, 2 ); } $subject = "[" . api_get_setting('siteName') . "] ".get_lang('SendMailBody')."\n".get_lang('CourseName')." : ".$courseInfo['name']." "; foreach ($user_list as $user_data) { $to_user_id = $user_data['user_id']; $user_info = api_get_user_info($to_user_id); $message = get_lang('SendMailBody')."\n".get_lang('CourseName')." : ".$courseInfo['name']."\n"; $message .= get_lang('UserName')." : ".api_get_person_name($user_info['firstname'], $user_info['lastname'])."\n"; $message .= get_lang('DateSent')." : ".api_format_date(api_get_local_time())."\n"; $message .= get_lang('WorkName')." : ".$workData['title']."\n\n".get_lang('DownloadLink')."\n"; $url = api_get_path(WEB_CODE_PATH)."work/work.php?cidReq=".$courseInfo['code']."&id_session=".$session_id."&id=".$workData['id']; $message .= $url; MessageManager::send_message_simple($to_user_id, $subject, $message); } } }
/** * 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) { $_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) { $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_simple($value['user_id'], $subject, $email_body, $sender_id); } } }
if ($is_author) { $work_data = get_work_data_by_id($item_to_edit_id); if (!empty($_POST['title'])) { $title = isset($_POST['title']) ? $_POST['title'] : $work_data['title']; } $description = isset($_POST['description']) ? $_POST['description'] : $work_data['description']; $add_to_update = null; if ($is_allowed_to_edit && $_POST['qualification'] != '') { $add_to_update = ', qualificator_id =' . "'" . api_get_user_id() . "', "; $add_to_update .= ' qualification = ' . "'" . Database::escape_string($_POST['qualification']) . "',"; $add_to_update .= ' date_of_qualification = ' . "'" . api_get_utc_datetime() . "'"; if (isset($_POST['send_email'])) { $url = api_get_path(WEB_CODE_PATH) . 'work/view.php?' . api_get_cidreq() . '&id=' . $item_to_edit_id; $subject = sprintf(get_lang('ThereIsANewWorkFeedback'), $work_item['title']); $message = sprintf(get_lang('ThereIsANewWorkFeedbackInWorkXHere'), $work_item['title'], $url); MessageManager::send_message_simple($work_item['user_id'], $subject, $message, api_get_user_id(), isset($_POST['send_to_drh_users'])); } } if ($_POST['qualification'] > $_POST['qualification_over']) { $error_message .= Display::return_message(get_lang('QualificationMustNotBeMoreThanQualificationOver'), 'error'); } else { $sql = "UPDATE " . $work_table . "\n SET\ttitle = '" . Database::escape_string($title) . "',\n description = '" . Database::escape_string($description) . "'\n " . $add_to_update . "\n WHERE c_id = {$course_id} AND id = {$item_to_edit_id}"; Database::query($sql); } api_item_property_update($_course, 'work', $item_to_edit_id, 'DocumentUpdated', $user_id); $succeed = true; $error_message .= Display::return_message(get_lang('ItemUpdated')); } Security::clear_token(); } else { // Bad token or can't add works
/** * Send emails to users. */ public function send() { $sender = $this->sender(); $subject = $this->subject(); $message = $this->message(); // Send email one by one to avoid antispam $users = $this->sent_to(); foreach ($users as $user) { MessageManager::send_message_simple($user['user_id'], $subject, $message, $sender['user_id']); } $this->log_mail_sent(); }
/** * Send an e-mail to users related to this work (course teachers, usually, but * might include other group members) * @param int $workId * @param array $courseInfo * @param int $session_id */ function sendAlertToUsers($workId, $courseInfo, $session_id) { $user_list = array(); //$workData = get_work_assignment_by_id($workId, $courseInfo['real_id']); $workData = get_work_data_by_id($workId, $courseInfo['real_id'], $session_id); //last value is to check this is not "just" an edit //YW Tis part serve to send a e-mail to the tutors when a new file is sent $send = api_get_course_setting('email_alert_manager_on_new_doc'); if ($send == SEND_EMAIL_EVERYONE || $send == SEND_EMAIL_TEACHERS) { // Lets predefine some variables. Be sure to change the from address! if (empty($session_id)) { //Teachers $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), null, null, null, COURSEMANAGER); } else { // Coaches $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), $session_id, null, null, 2); } } if ($send == SEND_EMAIL_EVERYONE || $send == SEND_EMAIL_STUDENTS) { if (!$session_id) { $session_id = null; } $student = CourseManager::get_user_list_from_course_code(api_get_course_id(), $session_id, null, null, STUDENT, null, null, null, null, null, array(api_get_user_id())); $user_list = array_merge($user_list, $student); } if ($send) { $senderEmail = api_get_setting('admin.administrator_email'); $senderName = api_get_person_name(api_get_setting('admin.administrator_name'), api_get_setting('admin.administrator_surname'), null, PERSON_NAME_EMAIL_ADDRESS); $subject = "[" . api_get_setting('platform.site_name') . "] " . get_lang('SendMailBody') . "\n " . get_lang('CourseName') . ": " . $courseInfo['name'] . " "; foreach ($user_list as $user_data) { $to_user_id = $user_data['user_id']; $user_info = api_get_user_info($to_user_id); $message = get_lang('SendMailBody') . "\n" . get_lang('CourseName') . " : " . $courseInfo['name'] . "\n"; $message .= get_lang('UserName') . " : " . api_get_person_name($user_info['firstname'], $user_info['lastname']) . "\n"; $message .= get_lang('DateSent') . " : " . api_format_date(api_get_local_time()) . "\n"; $url = api_get_path(WEB_CODE_PATH) . "work/work.php?cidReq=" . $courseInfo['code'] . "&id_session=" . $session_id . "&id=" . $workData['id']; $message .= get_lang('WorkName') . " : " . $workData['title'] . "\n\n" . '<a href="' . $url . '">' . get_lang('DownloadLink') . "</a>\n"; //$message .= $url; MessageManager::send_message_simple($to_user_id, $subject, $message); api_mail_html(api_get_person_name($user_info['firstname'] . ' ' . $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS), $user_info['email'], $subject, $message, $senderName, $senderEmail); } } }
$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), null, null, null, COURSEMANAGER); } else { //Coaches $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), $session_id, null, null, 2); } $subject = "[" . api_get_setting('siteName') . "] " . get_lang('SendMailBody') . "\n" . get_lang('CourseName') . " : " . $_course['name'] . " "; foreach ($user_list as $user_data) { $to_user_id = $user_data['user_id']; $emailbody = get_lang('SendMailBody') . "\n" . get_lang('CourseName') . " : " . $_course['name'] . "\n"; $user_info = api_get_user_info($user_id); $emailbody .= get_lang('UserName') . " : " . api_get_person_name($user_info['firstname'], $user_info['lastname']) . "\n"; $emailbody .= get_lang('DateSent') . " : " . api_format_date(api_get_local_time()) . "\n"; $emailbody .= get_lang('WorkName') . " : " . $title . "\n\n" . get_lang('DownloadLink') . "\n"; $url = api_get_path(WEB_CODE_PATH) . "work/work.php?" . api_get_cidreq() . "&id=" . $work_id; $emailbody .= $url; MessageManager::send_message_simple($to_user_id, $subject, $emailbody); } } $message = get_lang('DocAdd'); event_upload($id); $error_message .= Display::return_message(get_lang('DocAdd')); $script = 'work_list.php'; if ($is_allowed_to_edit) { $script = 'work_list_all.php'; } header('Location: ' . api_get_path(WEB_CODE_PATH) . 'work/' . $script . '?' . api_get_cidreq() . '&id=' . $work_id . '&error_message=' . $error_message); exit; } } $htmlHeadXtra[] = to_javascript_work(); Display::display_header(null);
/** * Disables or enables a user * * @param int user_id * @param int Enable or disable * @return void * @assert (-1,0) === false * @assert (1,1) === true */ public static function change_active_state($user_id, $active, $send_email_if_activated = false) { $user_id = intval($user_id); $active = intval($active); $table_user = Database::get_main_table(TABLE_MAIN_USER); $sql = "UPDATE {$table_user} SET active = '{$active}' WHERE user_id = '{$user_id}';"; Database::query($sql); $log_event = LOG_USER_DEACTIVATED; if ($active == 1) { $log_event = LOG_USER_ACTIVATED; if ($send_email_if_activated) { $user_info = api_get_user_info($user_id); $recipient_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); $emailsubject = '[' . api_get_setting('siteName') . '] ' . get_lang('YourReg') . ' ' . api_get_setting('siteName'); $emailbody = get_lang('Dear') . " " . stripslashes($recipient_name) . ",\n\n"; $emailbody .= sprintf(get_lang('YourAccountOnXHasJustBeenApprovedByOneOfOurAdministrators'), api_get_setting('siteName')) . "\n"; $emailbody .= sprintf(get_lang('YouCanNowLoginAtXUsingTheLoginAndThePasswordYouHaveProvided'), api_get_path(WEB_PATH)) . ",\n\n"; $emailbody .= get_lang('HaveFun') . "\n\n"; $emailbody .= get_lang('Problem') . "\n\n" . get_lang('Formula'); $emailbody .= api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')) . "\n" . get_lang('Manager') . " " . api_get_setting('siteName') . "\nT. " . api_get_setting('administratorTelephone') . "\n" . get_lang('Email') . " : " . api_get_setting('emailAdministrator'); MessageManager::send_message_simple($user_id, $emailsubject, $emailbody); } } $user_info = api_get_user_info($user_id); event_system($log_event, LOG_USER_ID, $user_id, api_get_utc_datetime(), api_get_user_id()); event_system($log_event, LOG_USER_OBJECT, $user_info, api_get_utc_datetime(), api_get_user_id()); }