Add text "This e-mail was sent via course %s" see BT#13672

- When sending a message to a teacher in the userportal page, add a text
that mentions the course/session.

- If "course_id "is set then add label
"This e-mail was sent via course %s" when sending emails from userportal

- If "course_id" is set and "session_id" is set
"This e-mail was sent via course %s in session %s" when sending emails
from userportal.
pull/2487/head
jmontoyaa 8 years ago
parent 1a97f60c13
commit f5906c1b33
  1. 23
      main/inc/ajax/message.ajax.php
  2. 58
      main/inc/ajax/user_manager.ajax.php
  3. 14
      main/inc/lib/course.lib.php
  4. 6
      main/inc/lib/message.lib.php
  5. 19
      main/inc/lib/notification.lib.php

@ -57,6 +57,29 @@ switch ($action) {
exit; exit;
} }
$courseId = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : 0;
$sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : 0;
// Add course info
if (!empty($courseId)) {
$courseInfo = api_get_course_info_by_id($courseId);
if (!empty($courseInfo)) {
if (empty($sessionId)) {
$courseNotification = sprintf(get_lang('ThisEmailWasSentViaCourseX'), $courseInfo['title']);
} else {
$sessionInfo = api_get_session_info($sessionId);
if (!empty($sessionInfo)) {
$courseNotification = sprintf(
get_lang('ThisEmailWasSentViaCourseXInSessionX'),
$courseInfo['title'],
$sessionInfo['name']
);
}
}
$messageContent .= '<br /><br />'.$courseNotification;
}
}
$result = MessageManager::send_message($_REQUEST['user_id'], $subject, $messageContent); $result = MessageManager::send_message($_REQUEST['user_id'], $subject, $messageContent);
if ($result) { if ($result) {
echo Display::return_message(get_lang('MessageHasBeenSent'), 'confirmation'); echo Display::return_message(get_lang('MessageHasBeenSent'), 'confirmation');

@ -31,8 +31,10 @@ switch ($action) {
echo json_encode($result); echo json_encode($result);
break; break;
case 'get_user_popup': case 'get_user_popup':
$courseId = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : 0;
$sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : 0;
$user_info = api_get_user_info($_REQUEST['user_id']); $user_info = api_get_user_info($_REQUEST['user_id']);
$ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php';
$isAnonymous = api_is_anonymous(); $isAnonymous = api_is_anonymous();
echo '<div class="row">'; echo '<div class="row">';
@ -66,13 +68,15 @@ switch ($action) {
echo '</div>'; echo '</div>';
echo '</div>'; echo '</div>';
$url = api_get_path(WEB_AJAX_PATH).'message.ajax.php?a=send_message&user_id='.$user_info['user_id'].'&course_id='.$courseId.'&session_id='.$sessionId;
if ($isAnonymous === false && if ($isAnonymous === false &&
api_get_setting('allow_message_tool') == 'true' api_get_setting('allow_message_tool') == 'true'
) { ) {
echo '<script>'; echo '<script>';
echo ' echo '
$("#send_message_link").on("click", function() { $("#send_message_link").on("click", function() {
var url = "'.$ajax_url.'?a=send_message&user_id='.$user_info['user_id'].'"; var url = "'.$url.'";
var params = $("#send_message").serialize(); var params = $("#send_message").serialize();
$.ajax({ $.ajax({
url: url+"&"+params, url: url+"&"+params,
@ -156,45 +160,45 @@ switch ($action) {
) )
) { ) {
$user_id = intval($_GET['user_id']); $user_id = intval($_GET['user_id']);
$status = intval($_GET['status']); $status = intval($_GET['status']);
if (!empty($user_id)) { if (!empty($user_id)) {
$user_table = Database::get_main_table(TABLE_MAIN_USER); $user_table = Database::get_main_table(TABLE_MAIN_USER);
$sql = "UPDATE $user_table $sql = "UPDATE $user_table
SET active='".$status."' SET active = '".$status."'
WHERE user_id='".$user_id."'"; WHERE user_id = '".$user_id."'";
$result = Database::query($sql); $result = Database::query($sql);
//Send and email if account is active // Send and email if account is active
if ($status == 1) { if ($status == 1) {
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$recipient_name = api_get_person_name( $recipientName = api_get_person_name(
$user_info['firstname'], $user_info['firstname'],
$user_info['lastname'], $user_info['lastname'],
null, null,
PERSON_NAME_EMAIL_ADDRESS PERSON_NAME_EMAIL_ADDRESS
); );
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$email_admin = api_get_setting('emailAdministrator'); $subject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$emailAdmin = api_get_setting('emailAdministrator');
$sender_name = api_get_person_name( $sender_name = api_get_person_name(
api_get_setting('administratorName'), api_get_setting('administratorName'),
api_get_setting('administratorSurname'), api_get_setting('administratorSurname'),
null, null,
PERSON_NAME_EMAIL_ADDRESS PERSON_NAME_EMAIL_ADDRESS
); );
$emailbody = get_lang('Dear')." ".stripslashes($recipient_name).",\n\n"; $body = get_lang('Dear')." ".stripslashes($recipientName).",\n\n";
$body .= sprintf(
$emailbody .= sprintf(
get_lang('YourAccountOnXHasJustBeenApprovedByOneOfOurAdministrators'), get_lang('YourAccountOnXHasJustBeenApprovedByOneOfOurAdministrators'),
api_get_setting('siteName') api_get_setting('siteName')
)."\n"; )."\n";
$emailbody .= sprintf( $body .= sprintf(
get_lang('YouCanNowLoginAtXUsingTheLoginAndThePasswordYouHaveProvided'), get_lang('YouCanNowLoginAtXUsingTheLoginAndThePasswordYouHaveProvided'),
api_get_path(WEB_PATH) api_get_path(WEB_PATH)
).",\n\n"; ).",\n\n";
$emailbody .= get_lang('HaveFun')."\n\n"; $body .= get_lang('HaveFun')."\n\n";
//$emailbody.=get_lang('Problem'). "\n\n". get_lang('SignatureFormula'); //$body.=get_lang('Problem'). "\n\n". get_lang('SignatureFormula');
$emailbody .= api_get_person_name( $body .= api_get_person_name(
api_get_setting('administratorName'), api_get_setting('administratorName'),
api_get_setting('administratorSurname') api_get_setting('administratorSurname')
)."\n". )."\n".
@ -207,17 +211,27 @@ switch ($action) {
'userId' => $user_id 'userId' => $user_id
); );
$result = api_mail_html( MessageManager::send_message_simple(
$recipient_name, $user_id,
$subject,
$body,
null,
false,
false,
$additionalParameters
);
/*$result = api_mail_html(
$recipientName,
$user_info['mail'], $user_info['mail'],
$emailsubject, $subject,
$emailbody, $body,
$sender_name, $sender_name,
$email_admin, $emailAdmin,
null, null,
null, null,
$additionalParameters $additionalParameters
); );*/
Event::addEvent(LOG_USER_ENABLE, LOG_USER_ID, $user_id); Event::addEvent(LOG_USER_ENABLE, LOG_USER_ID, $user_id);
} else { } else {
Event::addEvent(LOG_USER_DISABLE, LOG_USER_ID, $user_id); Event::addEvent(LOG_USER_DISABLE, LOG_USER_ID, $user_id);

@ -1963,7 +1963,7 @@ class CourseManager
$rs = Database::query($sql); $rs = Database::query($sql);
$listTeachers = array(); $listTeachers = array();
$teachers = array(); $teachers = array();
$url = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_popup'; $url = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_popup&course_id='.$courseId;
while ($teacher = Database::fetch_array($rs)) { while ($teacher = Database::fetch_array($rs)) {
$teachers['id'] = $teacher['user_id']; $teachers['id'] = $teacher['user_id'];
$teachers['lastname'] = $teacher['lastname']; $teachers['lastname'] = $teacher['lastname'];
@ -1992,7 +1992,7 @@ class CourseManager
* @param bool $orderList * @param bool $orderList
* @return string List of teachers teaching the course * @return string List of teachers teaching the course
*/ */
public static function get_teacher_list_from_course_code_to_string( public static function getTeacherListFromCourseCodeToString(
$course_code, $course_code,
$separator = self::USER_SEPARATOR, $separator = self::USER_SEPARATOR,
$add_link_to_profile = false, $add_link_to_profile = false,
@ -2025,7 +2025,10 @@ class CourseManager
if ($orderList === true) { if ($orderList === true) {
$html .= '<ul class="user-teacher">'; $html .= '<ul class="user-teacher">';
foreach ($list as $teacher) { foreach ($list as $teacher) {
$html .= Display::tag('li', Display::return_icon('teacher.png', $teacher, null, ICON_SIZE_TINY).' '.$teacher); $html .= Display::tag(
'li',
Display::return_icon('teacher.png', $teacher, null, ICON_SIZE_TINY).' '.$teacher
);
} }
$html .= '</ul>'; $html .= '</ul>';
} else { } else {
@ -2107,7 +2110,7 @@ class CourseManager
foreach ($coachList as $coach_course) { foreach ($coachList as $coach_course) {
$coach_name = $coach_course['full_name']; $coach_name = $coach_course['full_name'];
if ($add_link_to_profile) { if ($add_link_to_profile) {
$url = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_popup&user_id='.$coach_course['user_id']; $url = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_popup&user_id='.$coach_course['user_id'].'&course_id='.$courseId.'&session_id='.$session_id;
$coach_name = Display::url( $coach_name = Display::url(
$coach_name, $coach_name,
$url, $url,
@ -4210,6 +4213,7 @@ class CourseManager
null, null,
true true
); );
$params['real_id'] = $course_info['real_id'];
// Display the "what's new" icons // Display the "what's new" icons
$notifications = ''; $notifications = '';
@ -6329,7 +6333,7 @@ class CourseManager
} }
$teachers = ''; $teachers = '';
if (api_get_setting('display_teacher_in_courselist') === 'true') { if (api_get_setting('display_teacher_in_courselist') === 'true') {
$teachers = self::get_teacher_list_from_course_code_to_string( $teachers = self::getTeacherListFromCourseCodeToString(
$course['code'], $course['code'],
self::USER_SEPARATOR, self::USER_SEPARATOR,
true true

@ -446,7 +446,8 @@ class MessageManager
$subject, $subject,
$content, $content,
$sender_info, $sender_info,
$file_attachments $file_attachments,
$smsParameters
); );
} else { } else {
$usergroup = new UserGroup(); $usergroup = new UserGroup();
@ -478,7 +479,8 @@ class MessageManager
$subject, $subject,
$content, $content,
$group_info, $group_info,
$file_attachments $file_attachments,
$smsParameters
); );
} }

@ -429,6 +429,25 @@ class Notification extends Model
$content = $content.'<br /><br />'.$linkToNewMessage; $content = $content.'<br /><br />'.$linkToNewMessage;
} }
/*$courseInfo = api_get_course_info();
// Add course info
if (!empty($courseInfo)) {
$sessionId = api_get_session_id();
if (empty($sessionId)) {
$courseNotification = sprintf(get_lang('ThisEmailWasSentViaCourseX'), $courseInfo['title']);
} else {
$sessionInfo = api_get_session_info($sessionId);
if (!empty($sessionInfo)) {
$courseNotification = sprintf(
get_lang('ThisEmailWasSentViaCourseXInSessionX'),
$courseInfo['title'],
$sessionInfo['title']
);
}
}
$content = $content.'<br /><br />'.$courseNotification;
}*/
// You have received this message because you are subscribed text // You have received this message because you are subscribed text
$content = $content.'<br /><hr><i>'. $content = $content.'<br /><hr><i>'.
sprintf( sprintf(

Loading…
Cancel
Save