Email on homework creation - CT#570

skala
Guillaume Viguier 15 years ago
parent 3500ab37c8
commit 2b10bc0d01
  1. 10
      main/course_info/infocours.php
  2. 1
      main/inc/lib/add_course.lib.inc.php
  3. 3
      main/install/migrate-db-1.8.6.2-1.8.7-pre.sql
  4. 25
      main/work/work.lib.php
  5. 4
      main/work/work.php

@ -165,6 +165,10 @@ $form->addElement('radio', 'email_alert_to_teacher_on_new_user_in_course', null,
$form->addElement('radio', 'email_alert_to_teacher_on_new_user_in_course', null, get_lang('NewUserEmailAlertDisable'), 0);
$form -> addElement('html', $linebreak);
$form->addElement('radio', 'email_alert_students_on_new_homework', get_lang('NewHomeworkEmailAlert'), get_lang('NewHomeworkEmailAlertEnable'), 1);
$form->addElement('radio', 'email_alert_students_on_new_homework', null, get_lang('NewHomeworkEmailAlertDisable'), 0);
$form->addElement('html', $linebreak);
$form->addElement('radio', 'email_alert_manager_on_new_doc', get_lang('WorkEmailAlert'), get_lang('WorkEmailAlertActivate'), 1);
$form->addElement('radio', 'email_alert_manager_on_new_doc', null, get_lang('WorkEmailAlertDeactivate'), 0);
$form -> addElement('html', $linebreak);
@ -283,6 +287,7 @@ $values['allow_learning_path_theme'] = api_get_course_setting('allow_learning_pa
$values['allow_user_view_user_list'] = api_get_course_setting('allow_user_view_user_list');
//Get allow show user list
$values['display_info_advance_inside_homecourse'] = api_get_course_setting('display_info_advance_inside_homecourse');
$values['email_alert_students_on_new_homework'] = api_get_course_setting('email_alert_students_on_new_homework');
$form->setDefaults($values);
@ -360,6 +365,11 @@ if ($form->validate() && is_settings_editable()) {
$sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['display_info_advance_inside_homecourse']." WHERE variable = 'display_info_advance_inside_homecourse' ";
Database::query($sql);
}
if ($update_values['email_alert_students_on_new_homework'] != $values['email_alert_students_on_new_homework']) {
$sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_students_on_new_homework']." WHERE variable = 'email_alert_students_on_new_homework' ";
Database::query($sql);
}
$cidReset = true;
$cidReq = $course_code;

@ -2214,6 +2214,7 @@ function fill_Db_course($courseDbName, $courseRepository, $language,$default_doc
Database::query("INSERT INTO `".$TABLESETTING . "`(variable,value,category) VALUES ('email_alert_to_teacher_on_new_user_in_course',0,'registration')");
Database::query("INSERT INTO `".$TABLESETTING . "`(variable,value,category) VALUES ('allow_user_view_user_list',1,'user')");
Database::query("INSERT INTO `".$TABLESETTING . "`(variable,value,category) VALUES ('display_info_advance_inside_homecourse',1,'thematic_advance')");
Database::query("INSERT INTO ".$TABLESETTING . " (variable,value,category) VALUES ('email_alert_students_on_new_homework',0,'work')");
/*
-----------------------------------------------------------
Course homepage tools for platform admin only

@ -138,4 +138,5 @@ INSERT INTO course_setting (variable,value,category) VALUES ('display_info_advan
INSERT INTO tool(name, link, image, visibility, admin, address, added_tool, target, category) VALUES ('course_progress','course_progress/index.php','course_progress.gif',0,'0','squaregrey.gif',0,'_self','authoring');
ALTER TABLE lp ADD prerequisite int unsigned NOT NULL DEFAULT 0;
ALTER TABLE student_publication MODIFY COLUMN description TEXT DEFAULT NULL;
ALTER TABLE student_publication ADD COLUMN user_id INTEGER NOT NULL AFTER session_id;
ALTER TABLE student_publication ADD COLUMN user_id INTEGER NOT NULL AFTER session_id;
INSERT INTO course_setting(variable,value,category) VALUES ('email_alert_students_on_new_homework',0,'work');

@ -1514,3 +1514,28 @@ function send_reminder_users_without_publication($task_id) {
@api_mail($name_user, $user[3], $emailsubject, $emailbody_user, $sender_name, $email_admin);
}
}
/**
* Sends an email to the students of a course when a homework is created
*
* @param string course_id
*
* @author Guillaume Viguier <guillaume.viguier@beeznest.com>
*/
function send_email_on_homework_creation($course_id) {
require_once api_get_path(LIBRARY_PATH).'course.lib.php';
// Get the students of the course
$students = CourseManager::get_student_list_from_course_code($course_id);
$emailsubject = '[' . api_get_setting('siteName') . '] '.get_lang('HomeworkCreated');
$currentUser = api_get_user_info(api_get_user_id());
foreach($students as $student) {
$user_info = api_get_user_info($student["user_id"]);
if(!empty($user_info["mail"])) {
$name_user = api_get_person_name($user_info["firstname"], $user_info["lastname"], null, PERSON_NAME_EMAIL_ADDRESS);
$emailbody = get_lang('Dear')." ".$name.",\n\n";
$emailbody .= get_lang('HomeworkHasBeenCreatedForTheCourse')." ".$course_id.". ".get_lang('PleaseCheckHomeworkPage');
$emailbody .= "\n\n".api_get_person_name($currentUser["firstname"], $currentUser["lastname"]);
@api_mail($name_user, $user_info["mail"], $emailsubject, $emailbody, api_get_person_name($currentUser["firstname"], $currentUser["lastname"], null, PERSON_NAME_EMAIL_ADDRESS), $currentUser["mail"]);
}
}
}

@ -618,6 +618,10 @@ if (!empty($_REQUEST['new_dir'])) {
}
// end features
if(api_get_course_setting('email_alert_students_on_new_homework') == 1) {
send_email_on_homework_creation(api_get_course_id());
}
// update all the parents in the table item propery
$list_id = get_parent_directories($my_cur_dir_path);

Loading…
Cancel
Save