Add 'User homework upload e-mail notification' feature - refs BT#9681

1.10.x
Imanol Losada 10 years ago
parent 6983525bac
commit cbde5138f4
  1. 2
      main/course_info/infocours.php
  2. 6
      main/inc/lib/api.lib.php
  3. 50
      main/work/work.lib.php

@ -229,6 +229,8 @@ $group[]=$form->createElement('radio', 'email_alert_students_on_new_homework', n
$form->addGroup($group, '', array(get_lang("NewHomeworkEmailAlert")), '');
$group = array();
$group[]=$form->createElement('radio', 'email_alert_manager_on_new_doc', null, get_lang('WorkEmailAlertActivateOnlyForTeachers'), 3);
$group[]=$form->createElement('radio', 'email_alert_manager_on_new_doc', null, get_lang('WorkEmailAlertActivateOnlyForStudents'), 2);
$group[]=$form->createElement('radio', 'email_alert_manager_on_new_doc', get_lang('WorkEmailAlert'), get_lang('WorkEmailAlertActivate'), 1);
$group[]=$form->createElement('radio', 'email_alert_manager_on_new_doc', null, get_lang('WorkEmailAlertDeactivate'), 0);
$form->addGroup($group, '', array(get_lang("WorkEmailAlert")), '');

@ -71,6 +71,12 @@ define('COURSE_REQUEST_ACCEPTED', 1);
define('COURSE_REQUEST_REJECTED', 2);
define('DELETE_ACTION_ENABLED', false);
// EMAIL SENDING RECIPIENT CONSTANTS
define('SEND_EMAIL_EVERYONE', 1);
define('SEND_EMAIL_STUDENTS', 2);
define('SEND_EMAIL_TEACHERS', 3);
// SESSION VISIBILITY CONSTANTS
define('SESSION_VISIBLE_READ_ONLY', 1);
define('SESSION_VISIBLE', 2);

@ -3825,14 +3825,15 @@ function uploadWork($my_folder_data, $_course)
* @param array $courseInfo
* @param int $session_id
*/
function sendAlertToTeacher($workId, $courseInfo, $session_id)
function sendAlertToUsers($workId, $courseInfo, $session_id)
{
$user_list = array();
$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) {
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
@ -3853,9 +3854,37 @@ function sendAlertToTeacher($workId, $courseInfo, $session_id)
2
);
}
}
$subject = "[" . api_get_setting('siteName') . "] ".get_lang('SendMailBody')."\n".get_lang('CourseName')." : ".$courseInfo['name']." ";
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('emailAdministrator');
$senderName = api_get_person_name(
api_get_setting('administratorName'),
api_get_setting('administratorSurname'),
null,
PERSON_NAME_EMAIL_ADDRESS
);
$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);
@ -3865,8 +3894,19 @@ function sendAlertToTeacher($workId, $courseInfo, $session_id)
$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);
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
);
}
}
}
@ -3958,7 +3998,7 @@ function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId,
$userId,
$groupId
);
sendAlertToTeacher($workId, $courseInfo, $sessionId);
sendAlertToUsers($workId, $courseInfo, $sessionId);
Event::event_upload($workId);
$message = Display::return_message(get_lang('DocAdd'));
}

Loading…
Cancel
Save