Index: mails/es_utf8/teachercancelled_html.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/es_utf8/teachercancelled_html.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 teachercancelled_html.tpl
--- mails/es_utf8/teachercancelled_html.tpl	17 Feb 2008 20:35:22 -0000	1.2.2.2
+++ mails/es_utf8/teachercancelled_html.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 <p>Your appointment on <b><%%DATE%%></b> at <b><%%TIME%%> </b>,<br/> 
-with the <%%STAFFROLE%%> <b><%%USER%%></b> for course:</p>
+with the <%%STAFFROLE%%> <b><a href="<%%ATTENDANT_URL%%>"><%%ATTENDANT%%></a></b> for course:</p>
 
 <p><b><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></b></p>
 
Index: mails/es_utf8/applied_html.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/es_utf8/applied_html.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 applied_html.tpl
--- mails/es_utf8/applied_html.tpl	17 Feb 2008 20:35:21 -0000	1.2.2.2
+++ mails/es_utf8/applied_html.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 <p>An appointment has been applied for on <%%DATE%%> at <%%TIME%%>,<br/>
-by the student <%%USER%%> for course:
+by the student <a href="<%%ATTENDEE_URL%%>"><%%ATTENDEE%%></a> for course:
 
 <p><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></p>
 
Index: mails/es_utf8/applied.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/es_utf8/applied.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 applied.tpl
--- mails/es_utf8/applied.tpl	17 Feb 2008 20:35:21 -0000	1.2.2.2
+++ mails/es_utf8/applied.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 An appointment has been applied for on <%%DATE%%> at <%%TIME%%>, 
-by the student <%%USER%%> for course:
+by the student <%%ATTENDEE%%> for course:
 
 <%%COURSE_SHORT%%> : <%%COURSE%%>
 
Index: mails/es_utf8/cancelled_html.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/es_utf8/cancelled_html.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 cancelled_html.tpl
--- mails/es_utf8/cancelled_html.tpl	17 Feb 2008 20:35:22 -0000	1.2.2.2
+++ mails/es_utf8/cancelled_html.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 <p>Your appointment on <b><%%DATE%%></b> at <b><%%TIME%%></b>,<br/> 
-with the student <b><%%USER%%></b> for course :</p>
+with the student <b><a href="<%%ATTENDEE_URL%%>"><%%ATTENDEE%%></a></b> for course :</p>
 
 <p><b><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></b></p>
 
Index: mails/es_utf8/teachercancelled.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/es_utf8/teachercancelled.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 teachercancelled.tpl
--- mails/es_utf8/teachercancelled.tpl	17 Feb 2008 20:35:22 -0000	1.2.2.2
+++ mails/es_utf8/teachercancelled.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 Your appointment on <%%DATE%%> at <%%TIME%%>, 
-with the <%%STAFFROLE%%> <%%USER%%> for course:
+with the <%%STAFFROLE%%> <%%ATTENDANT%%> for course:
 
 <%%COURSE_SHORT%%> : <%%COURSE%%>
 
Index: mails/es_utf8/cancelled.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/es_utf8/cancelled.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 cancelled.tpl
--- mails/es_utf8/cancelled.tpl	17 Feb 2008 20:35:22 -0000	1.2.2.2
+++ mails/es_utf8/cancelled.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 Your appointment on  <%%DATE%%> at <%%TIME%%>, 
-with the student <%%USER%%> for course:
+with the student <%%ATTENDEE%%> for course:
 
 <%%COURSE_SHORT%%> : <%%COURSE%%>
 
Index: mails/fr_utf8/applied.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/fr_utf8/applied.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 applied.tpl
--- mails/fr_utf8/applied.tpl	17 Feb 2008 20:36:18 -0000	1.2.2.2
+++ mails/fr_utf8/applied.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 Un rendez-vous a été réservé le <%%DATE%%> à <%%TIME%%> heures, 
-par l'étudiant <%%USER%%> pour le cours :
+par l'étudiant <%%ATTENDEE%%> pour le cours :
 
 <%%COURSE_SHORT%%> : <%%COURSE%%>
 
Index: mails/fr_utf8/cancelled_html.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/fr_utf8/cancelled_html.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 cancelled_html.tpl
--- mails/fr_utf8/cancelled_html.tpl	17 Feb 2008 20:36:19 -0000	1.2.2.2
+++ mails/fr_utf8/cancelled_html.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 <p>Votre rendez-vous du <b><%%DATE%%></b> à <b><%%TIME%%> heures</b>,<br/> 
-pris par l'étudiant <b><%%USER%%></b> pour le cours :</p>
+pris par l'étudiant <b><a href="<%%ATTENDEE_URL%%>"><%%ATTENDEE%%></a></b> pour le cours :</p>
 
 <p><b><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></b></p>
 
Index: mails/fr_utf8/teachercancelled_html.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/fr_utf8/teachercancelled_html.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 teachercancelled_html.tpl
--- mails/fr_utf8/teachercancelled_html.tpl	17 Feb 2008 20:36:19 -0000	1.2.2.2
+++ mails/fr_utf8/teachercancelled_html.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 <p>Votre rendez-vous du <b><%%DATE%%></b> à <b><%%TIME%%> heures</b>,<br/> 
-pris avec le <%%STAFFROLE%%> <b><%%USER%%></b> pour le cours :</p>
+pris avec le <%%STAFFROLE%%> <b><a href="<%%ATTENDANT_URL%%>"><%%ATTENDANT%%></a></b> pour le cours :</p>
 
 <p><b><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></b></p>
 
Index: mails/fr_utf8/teachercancelled.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/fr_utf8/teachercancelled.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 teachercancelled.tpl
--- mails/fr_utf8/teachercancelled.tpl	17 Feb 2008 20:36:19 -0000	1.2.2.2
+++ mails/fr_utf8/teachercancelled.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 Votre rendez-vous du <%%DATE%%> à <%%TIME%%> heures, 
-pris avec le <%%STAFFROLE%%> <%%USER%%> pour le cours :
+pris avec le <%%STAFFROLE%%> <%%ATTENDANT%%> pour le cours :
 
 <%%COURSE_SHORT%%> : <%%COURSE%%>
 
Index: mails/fr_utf8/applied_html.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/fr_utf8/applied_html.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 applied_html.tpl
--- mails/fr_utf8/applied_html.tpl	17 Feb 2008 20:36:19 -0000	1.2.2.2
+++ mails/fr_utf8/applied_html.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 <p>Un rendez-vous a été réservé le <%%DATE%%> à <%%TIME%%> heures,<br/>
-par l'étudiant <%%USER%%> pour le cours :
+par l'étudiant <a href="<%%ATTENDEE_URL%%>"><%%ATTENDEE%%></a> pour le cours :
 
 <p><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></p>
 
Index: mails/fr_utf8/cancelled.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/fr_utf8/cancelled.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 cancelled.tpl
--- mails/fr_utf8/cancelled.tpl	17 Feb 2008 20:36:19 -0000	1.2.2.2
+++ mails/fr_utf8/cancelled.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 Votre rendez-vous du <%%DATE%%> à <%%TIME%%> heures, 
-pris par l'étudiant <%%USER%%> pour le cours :
+pris par l'étudiant <%%ATTENDEE%%> pour le cours :
 
 <%%COURSE_SHORT%%> : <%%COURSE%%>
 
Index: lang/de_utf8/scheduler.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/lang/de_utf8/scheduler.php,v
retrieving revision 1.2.10.7
diff -u -r1.2.10.7 scheduler.php
--- lang/de_utf8/scheduler.php	7 Apr 2008 19:14:12 -0000	1.2.10.7
+++ lang/de_utf8/scheduler.php	11 Aug 2010 16:27:48 -0000
@@ -143,6 +143,7 @@
 $string['overlappings'] = 'Einige Termine überschneiden sich';
 $string['reminder'] = 'Erinnerung';
 $string['remindertext'] = 'Dies ist eine Erinnerung, einen Sprechtermin festzulegen. Bitte wählen Sie möglichst schnell eine Sprechzeit ';
+$string['remindtitle'] = '$a: Erinnerung an Termin';
 $string['remindwhere'] = 'Ort des Gesprächs: ';
 $string['remindwithwhom'] = 'Gespräch mit  ';
 $string['resetschedulers'] = 'Daten löschen ';
Index: mails/en_utf8/teachercancelled.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/en_utf8/teachercancelled.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 teachercancelled.tpl
--- mails/en_utf8/teachercancelled.tpl	17 Feb 2008 20:35:02 -0000	1.2.2.2
+++ mails/en_utf8/teachercancelled.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 Your appointment on <%%DATE%%> at <%%TIME%%>, 
-with the <%%STAFFROLE%%> <%%USER%%> for course:
+with the <%%STAFFROLE%%> <%%ATTENDANT%%> for course:
 
 <%%COURSE_SHORT%%> : <%%COURSE%%>
 
Index: mails/en_utf8/applied_html.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/en_utf8/applied_html.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 applied_html.tpl
--- mails/en_utf8/applied_html.tpl	17 Feb 2008 20:35:02 -0000	1.2.2.2
+++ mails/en_utf8/applied_html.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 <p>An appointment has been applied for on <%%DATE%%> at <%%TIME%%>,<br/>
-by the student <%%USER%%> for course:
+by the student <a href="<%%ATTENDEE_URL%%>"><%%ATTENDEE%%></a> for course:
 
 <p><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></p>
 
Index: mails/en_utf8/cancelled.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/en_utf8/cancelled.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 cancelled.tpl
--- mails/en_utf8/cancelled.tpl	17 Feb 2008 20:35:02 -0000	1.2.2.2
+++ mails/en_utf8/cancelled.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 Your appointment on  <%%DATE%%> at <%%TIME%%>, 
-with the student <%%USER%%> for course:
+with the student <%%ATTENDEE%%> for course:
 
 <%%COURSE_SHORT%%> : <%%COURSE%%>
 
Index: mails/en_utf8/teachercancelled_html.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/en_utf8/teachercancelled_html.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 teachercancelled_html.tpl
--- mails/en_utf8/teachercancelled_html.tpl	17 Feb 2008 20:35:02 -0000	1.2.2.2
+++ mails/en_utf8/teachercancelled_html.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 <p>Your appointment on <b><%%DATE%%></b> at <b><%%TIME%%> </b>,<br/> 
-with the <%%STAFFROLE%%> <b><%%USER%%></b> for course:</p>
+with the <%%STAFFROLE%%> <b><a href="<%%ATTENDANT_URL%%>"><%%ATTENDANT%%></a></b> for course:</p>
 
 <p><b><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></b></p>
 
Index: mails/en_utf8/cancelled_html.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/en_utf8/cancelled_html.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 cancelled_html.tpl
--- mails/en_utf8/cancelled_html.tpl	17 Feb 2008 20:35:02 -0000	1.2.2.2
+++ mails/en_utf8/cancelled_html.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 <p>Your appointment on <b><%%DATE%%></b> at <b><%%TIME%%></b>,<br/> 
-with the student <b><%%USER%%></b> for course :</p>
+with the student <b><a href="<%%ATTENDEE_URL%%>"><%%ATTENDEE%%></a></b> for course :</p>
 
 <p><b><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></b></p>
 
Index: mails/en_utf8/applied.tpl
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mails/en_utf8/applied.tpl,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 applied.tpl
--- mails/en_utf8/applied.tpl	17 Feb 2008 20:35:01 -0000	1.2.2.2
+++ mails/en_utf8/applied.tpl	11 Aug 2010 16:27:48 -0000
@@ -1,5 +1,5 @@
 An appointment has been applied for on <%%DATE%%> at <%%TIME%%>, 
-by the student <%%USER%%> for course:
+by the student <%%ATTENDEE%%> for course:
 
 <%%COURSE_SHORT%%> : <%%COURSE%%>
 
Index: locallib.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/locallib.php,v
retrieving revision 1.3.2.10
diff -u -r1.3.2.10 locallib.php
--- locallib.php	7 Nov 2009 10:31:26 -0000	1.3.2.10
+++ locallib.php	11 Aug 2010 16:27:48 -0000
@@ -694,6 +694,45 @@
     return choose_from_menu($scalegrades, $id, $selected, 'choose', '', '', $return);
 }
 
+
+/**
+ * Construct an array with subtitution rules for mail templates, relating to 
+ * a single appointment. Any of the parameters can be null.
+ * @param object $scheduler The scheduler instance
+ * @param object $slot The slot data, obtained with get_record().
+ * @param user $attendant A {@link $USER} object describing the attendant (teacher)
+ * @param user $attendee A {@link $USER} object describing the attendee (student)
+ * @return array A hash with mail template substitutions 
+ */
+function scheduler_get_mail_variables ($scheduler, $slot, $attendant, $attendee) {
+    
+    global $CFG;
+    
+    $vars = array();
+    
+    if ($scheduler) {
+        $vars['MODULE']     = $scheduler->name;
+        $vars['STAFFROLE']  = format_string($scheduler->staffrolename);
+    }
+    if ($slot) {
+        $vars ['DATE']     = userdate($slot->starttime,get_string('strftimedate'));
+        $vars ['TIME']     = userdate($slot->starttime,get_string('strftimetime'));
+        $vars ['ENDTIME']  = userdate($slot->starttime+$slot->duration*60, get_string('strftimetime'));
+        $vars ['LOCATION'] = $slot->appointmentlocation;
+    }
+    if ($attendant) {
+        $vars['ATTENDANT']     = fullname($attendant);
+        $vars['ATTENDANT_URL'] = $CFG->wwwroot.'/user/view.php?id='.$attendant->id;
+    }
+    if ($attendee) {
+        $vars['ATTENDEE']     = fullname($attendee);
+        $vars['ATTENDEE_URL'] = $CFG->wwwroot.'/user/view.php?id='.$attendee->id;
+    }
+    
+    return $vars;
+    
+}
+
 /**
 * adds an error css marker in case of matching error
 * @param array $errors the current error set
Index: teacherview.controller.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/teacherview.controller.php,v
retrieving revision 1.2.2.9
diff -u -r1.2.2.9 teacherview.controller.php
--- teacherview.controller.php	6 Nov 2009 18:33:54 -0000	1.2.2.9
+++ teacherview.controller.php	11 Aug 2010 16:27:48 -0000
@@ -430,23 +430,13 @@
             // notify student
             if ($scheduler->allownotifications && $oldstudents){
                 foreach($oldstudents as $oldstudent){
+                    include_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php');
+
                     $student = get_record('user', 'id', $oldstudent->studentid);
                     $teacher = get_record('user', 'id', $slot->teacherid);
-                    include_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php');
-                    $vars = array( 'SITE' => $SITE->shortname,
-                                   'SITE_URL' => $CFG->wwwroot,
-                                   'COURSE_SHORT' => $COURSE->shortname,
-                                   'COURSE' => $COURSE->fullname,
-                                   'COURSE_URL' => $CFG->wwwroot.'/course/view.php?id='.$COURSE->id,
-                                   'MODULE' => $scheduler->name,
-                                   'USER' => fullname($teacher),
-                                   'STAFFROLE' => format_string($scheduler->staffrolename),
-                                   'DATE' => userdate($slot->starttime,get_string('strftimedate')),   // BUGFIX CONTRIB-937
-    	                           'TIME' => userdate($slot->starttime,get_string('strftimetime')),   // BUGFIX end
-                                   'DURATION' => $slot->duration );
-                    $notification = compile_mail_template('teachercancelled', $vars );
-                    $notificationHtml = compile_mail_template('teachercancelled_html', $vars );
-                    email_to_user($student, $teacher, get_string('cancelledbyteacher', 'scheduler', $SITE->shortname), $notification, $notificationHtml);
+
+                    $vars = scheduler_get_mail_variables($scheduler,$slot,$teacher,$student);
+                    send_email_from_template($student, $teacher, $COURSE, 'cancelledbyteacher', 'teachercancelled', $vars, 'scheduler');
                 }
             }
             
Index: mailtemplatelib.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/mailtemplatelib.php,v
retrieving revision 1.2.2.3
diff -u -r1.2.2.3 mailtemplatelib.php
--- mailtemplatelib.php	1 Apr 2008 23:16:02 -0000	1.2.2.3
+++ mailtemplatelib.php	11 Aug 2010 16:27:48 -0000
@@ -25,7 +25,7 @@
     return $notification;
 }
 
-/*
+/**
 * resolves and get the content of a Mail template, acoording to the user's current language.
 * @param virtual the virtual mail template name
 * @param module the current module
@@ -44,4 +44,57 @@
    notice("template $templateName not found");
    return array();
 }
+
+
+/**
+ * Sends an e-mail based on a template. 
+ * Several template substitution values are automatically filled by this routine.
+ *  
+ * @uses $CFG 
+ * @uses $SITE
+ * @param user $recipient A {@link $USER} object describing the recipient
+ * @param user $sender A {@link $USER} object describing the sender
+ * @param object $course The course that the activity is in. Can be null.
+ * @param string $title the identifier for the e-mail subject. 
+ *        Value can include one parameter, which will be substituted 
+ *        with the course shortname. 
+ * @param string $template the virtual mail template name (without "_html" part)
+ * @param array $infomap a hash containing pairs of parm => data to replace in template
+ * @param string $modulename the current module
+ * @param string $lang language to be used, if default language must be overriden
+ * @return bool|string Returns "true" if mail was sent OK, "emailstop" if email
+ *         was blocked by user and "false" if there was another sort of error.
+ */
+function send_email_from_template($recipient, $sender, $course, $title, $template, $infomap, $modulename , $lang = ''){
+    
+    global $CFG;
+    global $SITE;
+    
+    $defaultvars = array( 
+        'SITE' => $SITE->shortname,
+        'SITE_URL' => $CFG->wwwroot,
+        'SENDER'  => fullname($sender),
+        'RECIPIENT'  => fullname($recipient)
+    );
+    
+    $subjectPrefix = $SITE->shortname;
+    
+    if ($course) {
+        $subjectPrefix = $course->shortname;
+        $defaultvars['COURSE_SHORT'] = $course->shortname;
+        $defaultvars['COURSE']       = $course->fullname;
+        $defaultvars['COURSE_URL']   = $CFG->wwwroot.'/course/view.php?id='.$course->id;
+    }
+    
+    $vars = array_merge($defaultvars,$infomap);
+    
+    $subject = get_string($title,$modulename,$subjectPrefix);
+    $plainMail = compile_mail_template($template,$vars,$modulename);
+    $htmlMail = compile_mail_template($template.'_html',$vars,$modulename);
+    
+    $res = email_to_user ($recipient, $sender, $subject, $plainMail, $htmlMail); 
+    
+    return $res;
+}
+
 ?>
\ No newline at end of file
Index: studentview.controller.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/studentview.controller.php,v
retrieving revision 1.3.2.7
diff -u -r1.3.2.7 studentview.controller.php
--- studentview.controller.php	6 Nov 2009 17:48:21 -0000	1.3.2.7
+++ studentview.controller.php	11 Aug 2010 16:27:48 -0000
@@ -15,6 +15,9 @@
     die('Direct access to this script is forbidden.');    ///  It must be included from view.php in mod/scheduler
 }
 
+include_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php');
+
+
 /************************************************ Saving choice ************************************************/
 if ($action == 'savechoice') {
     // get parameters
@@ -92,28 +95,27 @@
     }
     if ($oldappointments = get_records_sql($sql)){
         foreach($oldappointments as $oldappointment){
-            scheduler_delete_appointment($oldappointment->appointmentid, $oldappointment, $scheduler);
     
-            // notify teacher
+            $oldappid  = $oldappointment->appointmentid;
+            $oldslotid = $oldappointment->id;
+
+            // prepare notification e-mail first - slot might be deleted if it's volatile 
             if ($scheduler->allownotifications){
                 $student = get_record('user', 'id', $USER->id);
                 $teacher = get_record('user', 'id', $oldappointment->teacherid);
-                include_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php');
-                $vars = array( 'SITE' => $SITE->shortname,
-                               'SITE_URL' => $CFG->wwwroot,
-                               'COURSE_SHORT' => $COURSE->shortname,
-                               'COURSE' => $COURSE->fullname,
-                               'COURSE_URL' => $CFG->wwwroot.'/course/view.php?id='.$COURSE->id,
-                               'MODULE' => $scheduler->name,
-                               'USER' => fullname($student),
-                               'DATE' => userdate($oldappointment->starttime,get_string('strftimedate')),   // BUGFIX CONTRIB-937
- 	                           'TIME' => userdate($oldappointment->starttime,get_string('strftimetime')),   // BUGFIX end
-                               'DURATION' => $oldappointment->duration );
-                $notification = compile_mail_template('cancelled', $vars );
-                $notificationHtml = compile_mail_template('cancelled_html', $vars );
-                email_to_user($teacher, $student, get_string('cancelledbystudent', 'scheduler', $SITE->shortname), $notification, $notificationHtml);
+                $vars = scheduler_get_mail_variables($scheduler,$oldappointment,$teacher,$student);
             }
+
+            // reload old slot
+            $oldslot = get_record('scheduler_slots','id', $oldslotid);
+            // delete the appointment (and possibly the slot)
+            scheduler_delete_appointment($oldappid, $oldslot, $scheduler);
             
+            // notify teacher
+            if ($scheduler->allownotifications){
+                send_email_from_template($teacher, $student, $course, 'cancelledbystudent', 'cancelled', $vars, 'scheduler');
+            }
+
             // delete all calendar events for that slot
             scheduler_delete_calendar_events($oldappointment);
             // renew all calendar events as some appointments may be left for other students
@@ -122,6 +124,8 @@
     }
     
 
+    $newslot = get_record('scheduler_slots', 'id', $slotid);
+
     /// create new appointment and add it for each member of the group
     foreach($oldslotowners as $astudentid){
         $appointment->slotid = $slotid;
@@ -133,26 +137,14 @@
         if (!insert_record('scheduler_appointment', $appointment)) {
            error('Couldn\'t save choice to database');
         }
-        scheduler_events_update($slot, $course);
+        scheduler_events_update($newslot, $course);
         
         // notify teacher
         if ($scheduler->allownotifications){
             $student = get_record('user', 'id', $appointment->studentid);
-            $teacher = get_record('user', 'id', $slot->teacherid);
-            include_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php');
-            $vars = array( 'SITE' => $SITE->shortname,
-                           'SITE_URL' => $CFG->wwwroot,
-                           'COURSE_SHORT' => $COURSE->shortname,
-                           'COURSE' => $COURSE->fullname,
-                           'COURSE_URL' => $CFG->wwwroot.'/course/view.php?id='.$COURSE->id,
-                           'MODULE' => $scheduler->name,
-                           'USER' => fullname($student),
-                           'DATE' => userdate($slot->starttime,get_string('strftimedate')),   // BUGFIX CONTRIB-937
- 	                       'TIME' => userdate($slot->starttime,get_string('strftimetime')),   // BUGFIX end
-                           'DURATION' => $slot->duration );
-            $notification = compile_mail_template('applied', $vars );
-            $notificationHtml = compile_mail_template('applied_html', $vars );
-            email_to_user($teacher, $student, get_string('newappointment', 'scheduler', $SITE->shortname), $notification, $notificationHtml);
+            $teacher = get_record('user', 'id', $newslot->teacherid);
+            $vars = scheduler_get_mail_variables($scheduler,$newslot,$teacher,$student);
+            send_email_from_template($teacher, $student, $course, 'newappointment', 'applied', $vars, 'scheduler');
         }
     }
 }
@@ -168,20 +160,8 @@
             if ($scheduler->allownotifications){
                 $student = get_record('user', 'id', $USER->id);
                 $teacher = get_record('user', 'id', $oldslot->teacherid);
-                include_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php');
-                $vars = array( 'SITE' => $SITE->shortname,
-                               'SITE_URL' => $CFG->wwwroot,
-                               'COURSE_SHORT' => $COURSE->shortname,
-                               'COURSE' => $COURSE->fullname,
-                               'COURSE_URL' => $CFG->wwwroot.'/course/view.php?id='.$COURSE->id,
-                               'MODULE' => $scheduler->name,
-                               'USER' => fullname($student), 
-                               'DATE' => userdate($oldslot->starttime,get_string('strftimedate')),  // BUGFIX CONTRIB-937
- 	                           'TIME' => userdate($oldslot->starttime,get_string('strftimetime')),  // BUGFIX end
-                               'DURATION' => $oldslot->duration );
-                $notification = compile_mail_template('cancelled', $vars );
-                $notificationHtml = compile_mail_template('cancelled_html', $vars );
-                email_to_user($teacher, $student, get_string('cancelledbystudent', 'scheduler', $SITE->shortname), $notification, $notificationHtml);
+                $vars = scheduler_get_mail_variables($scheduler,$oldslot,$teacher,$student);
+                send_email_from_template($teacher, $student, $COURSE, 'cancelledbystudent', 'cancelled', $vars, 'scheduler');
             }                    
         }
 
Index: lib.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/lib.php,v
retrieving revision 1.13.10.9
diff -u -r1.13.10.9 lib.php
--- lib.php	29 Jul 2009 19:02:13 -0000	1.13.10.9
+++ lib.php	11 Aug 2010 16:27:48 -0000
@@ -9,6 +9,7 @@
 
 /// Library of functions and constants for module scheduler
 include_once $CFG->dirroot.'/mod/scheduler/locallib.php';
+include_once $CFG->dirroot.'/mod/scheduler/mailtemplatelib.php';
 
 define('SCHEDULER_TIMEUNKNOWN', 0);  // This is used for appointments for which no time is entered
 define('SCHEDULER_SELF', 0); // Used for setting conflict search scope 
@@ -135,19 +136,26 @@
     global $CFG;
 
     $date = make_timestamp(date('Y'), date('m'), date('d'), date('H'), date('i'));
-
-    // for every appointment in all schedulers
+    
+    // Get all slots in all schedulers that need to have e-mail sent.
+    // Select only those slots that have start time in the future
+    // (safeguard for the case that the cron job was suspended for a long time)
     $select = "
         emaildate > 0 AND  
-        emaildate <= $date
-    ";
+        emaildate <= $date AND
+        starttime > $date
+        ";
     $slots = get_records_select('scheduler_slots', $select, 'starttime');
 
     if ($slots){
         foreach ($slots as $slot) {
             // get teacher
             $teacher = get_record('user', 'id', $slot->teacherid);
-
+            
+            // get course
+            $scheduler = get_record('scheduler', 'id', $slot->schedulerid);
+            $course = get_record('course', 'id', $scheduler->course);
+            
             // get appointed student list
             $select = "
                 slotid = {$slot->id}
@@ -157,22 +165,14 @@
             //if no email previously sent and one is required
             if ($appointments){
                 foreach($appointments as $appointed){
-                    $recipient = get_record('user', 'id', $appointed->studentid);                
-                    $message = get_string('remindwithwhom', 'scheduler').fullname($teacher).' ';
-                    $message .= get_string('on', 'scheduler').' ';
-                    $message .= date("l jS F Y",$slot->starttime).' ';
-                    $message .= get_string('from').' ';
-                    $message .= date("H:i",$slot->starttime).' ';
-                    $message .= get_string('to').' ';
-                    $message .= date("H:i",$slot->starttime + ($slot->duration * 60)).'. ';
-                    $message .= get_string('remindwhere', 'scheduler').$slot->appointmentlocation.'.';
-                    if(email_to_user($recicpient, $teacher, $title,$message)){
-                    }
+                    $student = get_record('user', 'id', $appointed->studentid);
+                    $vars = scheduler_get_mail_variables ($scheduler, $slot, $teacher, $student);
+                    send_email_from_template ($student,$teacher,$course,'remindtitle','reminder',$vars,'scheduler');
                 }
             }
             // mark as sent
             $slot->emaildate = -1;
-            update_record('scheduler_slots', $slot);
+            update_record('scheduler_slots', addslashes_object($slot));
         }
     }
     return true;
Index: lang/es_utf8/scheduler.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/lang/es_utf8/scheduler.php,v
retrieving revision 1.1.10.5
diff -u -r1.1.10.5 scheduler.php
--- lang/es_utf8/scheduler.php	1 Apr 2008 23:16:51 -0000	1.1.10.5
+++ lang/es_utf8/scheduler.php	11 Aug 2010 16:27:48 -0000
@@ -137,6 +137,7 @@
 $string['registeredlbl'] = 'Estudiantes con cita';
 $string['reminder'] = 'Recordatorio';
 $string['remindertext'] = 'Este es un recordatorio de que usted aún no ha concertado su cita. Por favor, elija una franja de tiempo tan pronto como le sea posible en ';
+$string['remindtitle'] = '$a: Recordatorio de cita';
 $string['remindwhere'] = 'Ubicación: ';
 $string['remindwithwhom'] = 'Cita con ';
 $string['resetschedulers'] = 'Deletear todos los datos de citas ';
Index: lang/en_utf8/scheduler.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/lang/en_utf8/scheduler.php,v
retrieving revision 1.1.10.6
diff -u -r1.1.10.6 scheduler.php
--- lang/en_utf8/scheduler.php	10 Dec 2008 15:25:49 -0000	1.1.10.6
+++ lang/en_utf8/scheduler.php	11 Aug 2010 16:27:48 -0000
@@ -146,6 +146,7 @@
 $string['registeredlbl'] = 'Student appointed';
 $string['reminder'] = 'Reminder';
 $string['remindertext'] = 'This is just a reminder that you have not yet set up your appointment. Please choose a time-slot as soon as possible at ';
+$string['remindtitle'] = '$a: Appointment reminder';
 $string['remindwhere'] = 'Location of the appointement: ';
 $string['remindwithwhom'] = 'Scheduled Appointment with ';
 $string['resetschedulers'] = 'Delete scheduler data ';
Index: lang/fr_utf8/scheduler.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/mod/scheduler/lang/fr_utf8/scheduler.php,v
retrieving revision 1.1.10.7
diff -u -r1.1.10.7 scheduler.php
--- lang/fr_utf8/scheduler.php	24 Jun 2009 22:59:21 -0000	1.1.10.7
+++ lang/fr_utf8/scheduler.php	11 Aug 2010 16:27:48 -0000
@@ -146,6 +146,7 @@
 $string['registeredlbl'] = 'Elèves enregistrés en rendez-vous ';
 $string['reminder'] = 'Rappel';
 $string['remindertext'] = 'Ce message pour vous rappeler que vous n\'avez pas encore fixé votre rendez-vous. Veuillez choisir une tranche horaire aussi vite que possible ici&nbsp;:';
+$string['remindtitle'] = '$a: Rappel de rendez-vous';
 $string['remindwhere'] = 'Lieu du rendez-vous : ';
 $string['remindwithwhom'] = 'Votre rendez-vous avec : ';
 $string['resetschedulers'] = 'Suppression des données de rendez-vous ';
Index: mails/es_utf8/reminder.tpl
===================================================================
RCS file: mails/es_utf8/reminder.tpl
diff -N mails/es_utf8/reminder.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/es_utf8/reminder.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,5 @@
+You have an upcoming appointment 
+on <%%DATE%%> from <%%TIME%%> to <%%ENDTIME%%>
+with <%%ATTENDANT%%>.
+
+Location: <%%LOCATION%%>
Index: mails/en_utf8/reminder_html.tpl
===================================================================
RCS file: mails/en_utf8/reminder_html.tpl
diff -N mails/en_utf8/reminder_html.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/en_utf8/reminder_html.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,5 @@
+<p>You have an upcoming appointment on <b><%%DATE%%></b> 
+from <b><%%TIME%%></b> to <b><%%ENDTIME%%></b><br/> 
+with <b><a href="<%%ATTENDANT_URL%%>"><%%ATTENDANT%%></a></b>.</p>
+
+<p>Location: <b><%%LOCATION%%></b></p>
Index: mails/en_utf8/reminder.tpl
===================================================================
RCS file: mails/en_utf8/reminder.tpl
diff -N mails/en_utf8/reminder.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/en_utf8/reminder.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,5 @@
+You have an upcoming appointment 
+on <%%DATE%%> from <%%TIME%%> to <%%ENDTIME%%>
+with <%%ATTENDANT%%>.
+
+Location: <%%LOCATION%%>
Index: mails/de_utf8/cancelled_html.tpl
===================================================================
RCS file: mails/de_utf8/cancelled_html.tpl
diff -N mails/de_utf8/cancelled_html.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/de_utf8/cancelled_html.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,8 @@
+<p>Ihr Termin am <b><%%DATE%%></b> um <b><%%TIME%%></b> Uhr<br/> 
+mit dem/der Teilnehmer/in <b><a href="<%%ATTENDEE_URL%%>"><%%ATTENDEE%%></a></b> im Kurs</p>
+
+<p><b><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></b></p>
+
+<p>im Terminplaner "<i><%%MODULE%%></i>" auf der Webseite <b><a href="<%%SITE_URL%%>"><%%SITE%%></a></b></p>
+
+<p><b><span style="color : red">wurde abgesagt oder verschoben</span></b>.</p>
Index: mails/de_utf8/applied_html.tpl
===================================================================
RCS file: mails/de_utf8/applied_html.tpl
diff -N mails/de_utf8/applied_html.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/de_utf8/applied_html.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,6 @@
+<p>Eine Terminreservierung für den <%%DATE%%> um <%%TIME%%> Uhr<br/>
+wurde durch den/die Teilnehmer/in <a href="<%%ATTENDEE_URL%%>"><%%ATTENDEE%%></a> eingetragen, und zwar im Kurs
+
+<p><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></p>
+
+<p>im Terminplaner "<i><%%MODULE%%></i>" auf der Webseite <b><a href="<%%SITE_URL%%>"><%%SITE%%></a></b>.</p>
Index: mails/fr_utf8/reminder.tpl
===================================================================
RCS file: mails/fr_utf8/reminder.tpl
diff -N mails/fr_utf8/reminder.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/fr_utf8/reminder.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,5 @@
+Vous avez un rendez-vous 
+le <%%DATE%%> de <%%TIME%%> à <%%ENDTIME%%> heures 
+avec <%%ATTENDANT%%>.
+
+Lieu du rendez-vous : <%%LOCATION%%>
Index: mails/es_utf8/reminder_html.tpl
===================================================================
RCS file: mails/es_utf8/reminder_html.tpl
diff -N mails/es_utf8/reminder_html.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/es_utf8/reminder_html.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,5 @@
+<p>You have an upcoming appointment on <b><%%DATE%%></b> 
+from <b><%%TIME%%></b> to <b><%%ENDTIME%%></b><br/> 
+with <b><a href="<%%ATTENDANT_URL%%>"><%%ATTENDANT%%></a></b>.</p>
+
+<p>Location: <b><%%LOCATION%%></b></p>
Index: mails/de_utf8/reminder.tpl
===================================================================
RCS file: mails/de_utf8/reminder.tpl
diff -N mails/de_utf8/reminder.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/de_utf8/reminder.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,4 @@
+Sie haben einen Termin mit <%%ATTENDANT%%>
+am <%%DATE%%> von <%%TIME%%> bis <%%ENDTIME%%> Uhr. 
+
+Ort: <%%LOCATION%%>
Index: mails/de_utf8/reminder_html.tpl
===================================================================
RCS file: mails/de_utf8/reminder_html.tpl
diff -N mails/de_utf8/reminder_html.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/de_utf8/reminder_html.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,5 @@
+<p>Sie haben einen Termin mit 
+<b><a href="<%%ATTENDANT_URL%%>"><%%ATTENDANT%%></a></b> 
+am <b><%%DATE%%></b> von <b><%%TIME%%></b> bis <b><%%ENDTIME%%></b> Uhr.</p>
+
+<p>Ort: <b><%%LOCATION%%></b></p>
Index: mails/de_utf8/teachercancelled.tpl
===================================================================
RCS file: mails/de_utf8/teachercancelled.tpl
diff -N mails/de_utf8/teachercancelled.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/de_utf8/teachercancelled.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,8 @@
+Ihr Termin am  <%%DATE%%> um <%%TIME%%> Uhr 
+mit <%%STAFFROLE%%> <%%ATTENDANT%%> im Kurs
+
+<%%COURSE_SHORT%%> : <%%COURSE%%>
+
+im Terminplaner "<%%MODULE%%>" auf der Webseite <%%SITE%%>
+
+wurde abgesagt. Bitte wählen Sie einen neuen Termin.
Index: mails/de_utf8/cancelled.tpl
===================================================================
RCS file: mails/de_utf8/cancelled.tpl
diff -N mails/de_utf8/cancelled.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/de_utf8/cancelled.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,8 @@
+Ihr Termin am  <%%DATE%%> um <%%TIME%%> Uhr 
+mit dem/der Teilnehmer/in <%%ATTENDEE%%> im Kurs
+
+<%%COURSE_SHORT%%> : <%%COURSE%%>
+
+im Terminplaner "<%%MODULE%%>" auf der Webseite <%%SITE%%>
+
+wurde abgesagt oder verschoben.
Index: mails/de_utf8/applied.tpl
===================================================================
RCS file: mails/de_utf8/applied.tpl
diff -N mails/de_utf8/applied.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/de_utf8/applied.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,7 @@
+Eine Terminreservierung für den <%%DATE%%> um <%%TIME%%> Uhr 
+wurde durch den/die Teilnehmer/in <%%ATTENDEE%%> eingetragen, 
+und zwar im Kurs 
+
+<%%COURSE_SHORT%%> : <%%COURSE%%>
+
+im Terminplaner "<%%MODULE%%>" auf der Webseite <%%SITE%%>.
Index: mails/de_utf8/teachercancelled_html.tpl
===================================================================
RCS file: mails/de_utf8/teachercancelled_html.tpl
diff -N mails/de_utf8/teachercancelled_html.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/de_utf8/teachercancelled_html.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,8 @@
+<p>Ihr Termin am <b><%%DATE%%></b> um <b><%%TIME%%></b> Uhr<br/> 
+mit <%%STAFFROLE%%> <b><a href="<%%ATTENDANT_URL%%>"><%%ATTENDANT%%></a></b> im Kurs</p>
+
+<p><b><%%COURSE_SHORT%%> : <a href="<%%COURSE_URL%%>"><%%COURSE%%></a></b></p>
+
+<p>im Terminplaner "<i><%%MODULE%%></i>" auf der Webseite <b><a href="<%%SITE_URL%%>"><%%SITE%%></a></b></p>
+
+<p><b><span style="color : red">wurde abgesagt.</span></b>. Bitte wählen Sie einen neuen Termin.</p>
Index: mails/fr_utf8/reminder_html.tpl
===================================================================
RCS file: mails/fr_utf8/reminder_html.tpl
diff -N mails/fr_utf8/reminder_html.tpl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mails/fr_utf8/reminder_html.tpl	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,5 @@
+<p>Vous avez un rendez-vous le <b><%%DATE%%></b> 
+de <b><%%TIME%%></b> à <b><%%ENDTIME%%></b> heures<br/> 
+avec<b><a href="<%%ATTENDANT_URL%%>"><%%ATTENDANT%%></a></b>.</p>
+
+<p>Lieu du rendez-vous : <b><%%LOCATION%%></b></p>
