Changing the add and update session interfaces
authorantonio.c.mariani <antonio.c.mariani@gmail.com>
Sun, 4 Oct 2015 13:13:12 +0000 (10:13 -0300)
committerDan Marsden <dan@danmarsden.com>
Mon, 14 Mar 2016 20:30:09 +0000 (09:30 +1300)
add_form.php
lang/en/attendance.php
locallib.php
renderables.php
renderer.php
sessions.php
update_form.php

index a7b9e15..be3cad8 100644 (file)
@@ -102,14 +102,7 @@ class mod_attendance_add_form extends moodleform {
             }
         }
 
-        $mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions', 'attendance'));
-        $mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attendance');
-
-        // Students can mark own attendance.
-        $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance'));
-        $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance');
-
-        $mform->addElement('date_time_selector', 'sessiondate', get_string('sessiondate', 'attendance'));
+        $mform->addElement('date_selector', 'sessiondate', get_string('sessiondate', 'attendance'));
 
         for ($i = 0; $i <= 23; $i++) {
             $hours[$i] = sprintf("%02d", $i);
@@ -117,13 +110,43 @@ class mod_attendance_add_form extends moodleform {
         for ($i = 0; $i < 60; $i += 5) {
             $minutes[$i] = sprintf("%02d", $i);
         }
-        $durtime = array();
-        $durtime[] =& $mform->createElement('select', 'hours', get_string('hour', 'form'), $hours, false, true);
-        $durtime[] =& $mform->createElement('select', 'minutes', get_string('minute', 'form'), $minutes, false, true);
-        $mform->addGroup($durtime, 'durtime', get_string('duration', 'attendance'), array(' '), true);
 
-        $mform->addElement('date_selector', 'sessionenddate', get_string('sessionenddate', 'attendance'));
-        $mform->disabledIf('sessionenddate', 'addmultiply', 'notchecked');
+        $sesendtime = array();
+        $sesendtime[] =& $mform->createElement('static', 'from', '', get_string('from', 'attendance'));
+        $sesendtime[] =& $mform->createElement('select', 'starthour', get_string('hour', 'form'), $hours, false, true);
+        $sesendtime[] =& $mform->createElement('select', 'startminute', get_string('minute', 'form'), $minutes, false, true);
+        $sesendtime[] =& $mform->createElement('static', 'to', '', get_string('to', 'attendance'));
+        $sesendtime[] =& $mform->createElement('select', 'endhour', get_string('hour', 'form'), $hours, false, true);
+        $sesendtime[] =& $mform->createElement('select', 'endminute', get_string('minute', 'form'), $minutes, false, true);
+        $mform->addGroup($sesendtime, 'sestime', get_string('time', 'attendance'), array(' '), true);
+
+        // Select which status set to use.
+        $maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id);
+        if ($maxstatusset > 0) {
+            $opts = array();
+            for ($i = 0; $i <= $maxstatusset; $i++) {
+                $opts[$i] = att_get_setname($this->_customdata['att']->id, $i);
+            }
+            $mform->addElement('select', 'statusset', get_string('usestatusset', 'mod_attendance'), $opts);
+        } else {
+            $mform->addElement('hidden', 'statusset', 0);
+            $mform->setType('statusset', PARAM_INT);
+        }
+
+        // Students can mark own attendance.
+        $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance'));
+        $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance');
+
+        $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), array('rows' => 1, 'columns' => 80),
+                            array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext));
+        $mform->setType('sdescription', PARAM_RAW);
+
+        // For multiple sessions.
+
+        $mform->addElement('header', 'headeraddmultiplesessions', get_string('addmultiplesessions', 'attendance'));
+
+        $mform->addElement('checkbox', 'addmultiply', '', get_string('repeatasfollows', 'attendance'));
+        $mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attendance');
 
         $sdays = array();
         if ($CFG->calendar_startwday === '0') { // Week start from sunday.
@@ -138,7 +161,7 @@ class mod_attendance_add_form extends moodleform {
         if ($CFG->calendar_startwday !== '0') { // Week start from sunday.
             $sdays[] =& $mform->createElement('checkbox', 'Sun', '', get_string('sunday', 'calendar'));
         }
-        $mform->addGroup($sdays, 'sdays', get_string('sessiondays', 'attendance'), array('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'), true);
+        $mform->addGroup($sdays, 'sdays', get_string('repeaton', 'attendance'), array('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'), true);
         $mform->disabledIf('sdays', 'addmultiply', 'notchecked');
 
         $period = array(1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
@@ -146,25 +169,11 @@ class mod_attendance_add_form extends moodleform {
         $periodgroup = array();
         $periodgroup[] =& $mform->createElement('select', 'period', '', $period, false, true);
         $periodgroup[] =& $mform->createElement('static', 'perioddesc', '', get_string('week', 'attendance'));
-        $mform->addGroup($periodgroup, 'periodgroup', get_string('period', 'attendance'), array(' '), false);
+        $mform->addGroup($periodgroup, 'periodgroup', get_string('repeatevery', 'attendance'), array(' '), false);
         $mform->disabledIf('periodgroup', 'addmultiply', 'notchecked');
 
-        // Select which status set to use.
-        $maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id);
-        if ($maxstatusset > 0) {
-            $opts = array();
-            for ($i = 0; $i <= $maxstatusset; $i++) {
-                $opts[$i] = att_get_setname($this->_customdata['att']->id, $i);
-            }
-            $mform->addElement('select', 'statusset', get_string('usestatusset', 'mod_attendance'), $opts);
-        } else {
-            $mform->addElement('hidden', 'statusset', 0);
-            $mform->setType('statusset', PARAM_INT);
-        }
-
-        $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), null,
-            array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext));
-        $mform->setType('sdescription', PARAM_RAW);
+        $mform->addElement('date_selector', 'sessionenddate', get_string('repeatuntil', 'attendance'));
+        $mform->disabledIf('sessionenddate', 'addmultiply', 'notchecked');
 
         $mform->addElement('hidden', 'coursestartdate', $course->startdate);
         $mform->setType('coursestartdate', PARAM_INT);
@@ -172,8 +181,7 @@ class mod_attendance_add_form extends moodleform {
         $mform->addElement('hidden', 'previoussessiondate', 0);
         $mform->setType('previoussessiondate', PARAM_INT);
 
-        $submitstring = get_string('addsession', 'attendance');
-        $this->add_action_buttons(false, $submitstring);
+        $this->add_action_buttons(true, get_string('add', 'attendance'));
     }
 
     /**
@@ -184,8 +192,14 @@ class mod_attendance_add_form extends moodleform {
     public function validation($data, $files) {
         $errors = parent::validation($data, $files);
 
+        $sesstarttime = $data['sestime']['starthour'] * HOURSECS + $data['sestime']['startminute'] * MINSECS;
+        $sesendtime = $data['sestime']['endhour'] * HOURSECS + $data['sestime']['endminute'] * MINSECS;
+        if ($sesendtime < $sesstarttime) {
+            $errors['sestime'] = get_string('invalidsessionendtime', 'attendance');
+        }
+
         if (!empty($data['addmultiply']) && $data['sessiondate'] != 0 && $data['sessionenddate'] != 0 &&
-                   $data['sessionenddate'] < $data['sessiondate']) {
+                $data['sessionenddate'] < $data['sessiondate']) {
             $errors['sessionenddate'] = get_string('invalidsessionenddate', 'attendance');
         }
 
index 7871676..8a80b17 100644 (file)
@@ -34,7 +34,7 @@ $string['Pacronym'] = 'P';
 $string['Pfull'] = 'Present';
 $string['acronym'] = 'Acronym';
 $string['add'] = 'Add';
-$string['addmultiplesessions'] = 'Add multiple sessions';
+$string['addmultiplesessions'] = 'Multiple sessions';
 $string['addsession'] = 'Add session';
 $string['allcourses'] = 'All courses';
 $string['all'] = 'All';
@@ -70,21 +70,21 @@ $string['changesession'] = 'Change session';
 $string['checkweekdays'] = 'Select weekdays that fall within your selected session date range.';
 $string['column'] = 'column';
 $string['columns'] = 'columns';
-$string['commonsession'] = 'Common';
-$string['commonsessions'] = 'Common';
+$string['commonsession'] = 'All students';
+$string['commonsessions'] = 'All students';
 $string['confirmdeleteuser'] = 'Are you sure you want to delete user \'{$a->fullname}\' ({$a->email})?<br/>All of their attendance records will be permanently deleted.';
 $string['countofselected'] = 'Count of selected';
 $string['copyfrom'] = 'Copy attendance data from';
 $string['createmultiplesessions'] = 'Create multiple sessions';
 $string['createmultiplesessions_help'] = 'This function allows you to create multiple sessions in one simple step.
+The sessions begin on the date of the base session and continue until the \'repeat until\' date.
 
-  * <strong>Session Start Date</strong>: Select the start date of your course (the first day of class)
-  * <strong>Session End Date</strong>: Select the last day of class (the last day you want to take attendance).
-  * <strong>Session Days</strong>: Select the days of the week when your class will meet (for example, Monday/Wednesday/Friday).
-  * <strong>Frequency</strong>: This allows for a frequency setting. If your class will meet every week, select 1; if it will meet every other week, select 2; every 3rd week, select 3, etc.
+  * <strong>Repeat on</strong>: Select the days of the week when your class will meet (for example, Monday/Wednesday/Friday).
+  * <strong>Repeat every</strong>: This allows for a frequency setting. If your class will meet every week, select 1; if it will meet every other week, select 2; every 3rd week, select 3, etc.
+  * <strong>Repeat until</strong>: Select the last day of class (the last day you want to take attendance).
 ';
 $string['createonesession'] = 'Create one session for the course';
-$string['days'] = 'Day';
+$string['days'] = 'Days';
 $string['defaults'] = 'Defaults';
 $string['defaultdisplaymode'] = 'Default display mode';
 $string['delete'] = 'Delete';
@@ -120,7 +120,7 @@ $string['gradebookexplanation_help'] = 'The Attendance module displays your curr
 
 For example, if you have earned 8 of 10 points to date (80% attendance) and attendance for the entire course is worth 50 points, the Attendance module will display 8/10 and the gradebook will display 40/50. You have not yet earned 40 points but 40 is the equivalent point value to your current attendance percentage of 80%. The point value you have earned in the Attendance module can never decrease, as it is based only on attendance to date; however, the attendance point value shown in the gradebook may increase or decrease depending on your future attendance, as it is based on attendance for the entire course.';
 $string['gridcolumns'] = 'Grid columns';
-$string['groupsession'] = 'Group';
+$string['groupsession'] = 'Group of students';
 $string['hiddensessions'] = 'Hidden sessions';
 $string['hiddensessions_help'] = 'Sessions are hidden if they are scheduled before the course start date.
 
@@ -130,7 +130,7 @@ $string['includeall'] = 'Select all sessions';
 $string['includenottaken'] = 'Include not taken sessions';
 $string['includeremarks'] = 'Include remarks';
 $string['indetail'] = 'In detail...';
-$string['invalidsessionenddate'] = 'The session end date can not be earlier than the session start date';
+$string['invalidsessionenddate'] = 'This date can not be earlier than the session date';
 $string['invalidaction'] = 'You must select an action';
 $string['jumpto'] = 'Jump to';
 $string['mergeuser'] = 'Merge user';
@@ -165,7 +165,6 @@ $string['olddate'] = 'Old date';
 $string['onlyselectedusers'] = 'Export specific users';
 $string['participant'] = 'Participant';
 $string['percentage'] = 'Percentage';
-$string['period'] = 'Frequency';
 $string['pluginname'] = 'Attendance';
 $string['pluginadministration'] = 'Attendance administration';
 $string['remark'] = 'Remark for: {$a}';
@@ -217,10 +216,9 @@ $string['session'] = 'Session';
 $string['session_help'] = 'Session';
 $string['sessionadded'] = 'Session successfully added';
 $string['sessionalreadyexists'] = 'Session already exists for this date';
-$string['sessiondate'] = 'Session Date';
+$string['sessiondate'] = 'Date';
 $string['sessiondays'] = 'Session Days';
 $string['sessiondeleted'] = 'Session successfully deleted';
-$string['sessionenddate'] = 'Session end date';
 $string['sessionexist'] = 'Session not added (already exists)!';
 $string['sessions'] = 'Sessions';
 $string['sessionscompleted'] = 'Sessions completed';
@@ -229,12 +227,12 @@ $string['sessiongenerated'] = 'One session was successfully generated';
 $string['sessionsgenerated'] = '{$a} sessions were successfully generated';
 $string['sessionsnotfound'] = 'There is no sessions in the selected timespan';
 $string['sessionstartdate'] = 'Session start date';
-$string['sessiontype'] = 'Session type';
-$string['sessiontype_help'] = 'There are two types of sessions: common and groups. Ability to add different types depends on activity group mode.
+$string['sessiontype'] = 'Type';
+$string['sessiontype_help'] = 'You can add sessions for all students or for a group of students. Ability to add different types depends on activity group mode.
 
-* In group mode "No groups" you can add only common sessions.
-* In group mode "Visible groups" you can add common and group sessions.
-* In group mode "Separate groups" you can add only group sessions.
+* In group mode "No groups" you can add only sessions for all students.
+* In group mode "Separate groups" you can add only sessions for a group of students.
+* In group mode "Visible groups" you can add both types of sessions.
 ';
 $string['sessiontypeshort'] = 'Type';
 $string['sessionupdated'] = 'Session successfully updated';
@@ -273,7 +271,7 @@ $string['tempusermerge'] = 'Merge temporary user';
 $string['tuseremail'] = 'Email';
 $string['tusername'] = 'Full name';
 $string['update'] = 'Update';
-$string['usestatusset'] = 'Use status set';
+$string['usestatusset'] = 'Status set';
 $string['userexists'] = 'There is already a real user with this email address';
 $string['users'] = 'Users to export';
 $string['variable'] = 'variable';
@@ -313,3 +311,11 @@ $string['hiddensessionsdeleted'] = 'All hidden sessions were delete';
 $string['timeahead'] = 'Multiple sessions that exceed one year cannot be created, please adjust the start and end dates.';
 $string['priorto'] = 'The session date is prior to the course start date ({$a}) so that the new sessions scheduled before this date will be hidden (not accessible). You can change the course start date at any time (see course settings) in order to have access to earlier sessions.<br><br>Please change the session date or just click the "Add session" button again to confirm?';
 $string['noattendanceusers'] = 'It is not possible to export any data as there are no students enrolled in the course.';
+$string['time'] = 'Time';
+$string['from'] = 'from:';
+$string['to'] = 'to:';
+$string['repeatasfollows'] = 'Repeat the session above as follows';
+$string['repeatevery'] = 'Repeat every';
+$string['repeatuntil'] = 'Repeat until';
+$string['repeaton'] = 'Repeat on';
+$string['invalidsessionendtime'] = 'The end time must be greater than start time';
index 1b8ed98..3e35287 100644 (file)
@@ -38,7 +38,6 @@ define('ATT_VIEW_NOTPRESENT', 6);
 define('ATT_SORT_LASTNAME', 1);
 define('ATT_SORT_FIRSTNAME', 2);
 
-
 class att_page_with_filter_controls {
     const SELECTOR_NONE         = 1;
     const SELECTOR_GROUP        = 2;
@@ -208,7 +207,7 @@ class att_page_with_filter_controls {
             // Show Common groups always.
             $this->sessgroupslist[self::SESSTYPE_COMMON] = get_string('commonsessions', 'attendance');
             foreach ($allowedgroups as $group) {
-                $this->sessgroupslist[$group->id] = format_string($group->name);
+                $this->sessgroupslist[$group->id] = get_string('group') . ': ' . format_string($group->name);
             }
         }
     }
@@ -757,13 +756,18 @@ class attendance {
             print_error('No such session in this course');
         }
 
-        $sess->sessdate = $formdata->sessiondate;
-        $sess->duration = $formdata->durtime['hours'] * HOURSECS + $formdata->durtime['minutes'] * MINSECS;
+        $sesstarttime = $formdata->sestime['starthour']*HOURSECS + $formdata->sestime['startminute'] * MINSECS;
+        $sesendtime = $formdata->sestime['endhour']*HOURSECS + $formdata->sestime['endminute'] * MINSECS;
+
+        $sess->sessdate = $formdata->sessiondate + $sesstarttime;
+        $sess->duration = $sesendtime - $sesstarttime;
+
         $description = file_save_draft_area_files($formdata->sdescription['itemid'],
                                 $this->context->id, 'mod_attendance', 'session', $sessionid,
                                 array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']);
         $sess->description = $description;
         $sess->descriptionformat = $formdata->sdescription['format'];
+
         $sess->timemodified = time();
         $DB->update_record('attendance_sessions', $sess);
 
index abe8cb6..64329f9 100644 (file)
@@ -43,6 +43,7 @@ class attendance_tabs implements renderable {
     const TAB_EXPORT        = 4;
     const TAB_PREFERENCES   = 5;
     const TAB_TEMPORARYUSERS = 6; // Tab for managing temporary users.
+    const TAB_UPDATE        = 7;
 
     public $currenttab;
 
@@ -74,31 +75,36 @@ class attendance_tabs implements renderable {
         );
         if (has_any_capability($capabilities, $context)) {
             $toprow[] = new tabobject(self::TAB_SESSIONS, $this->att->url_manage()->out(),
-                get_string('sessions', 'attendance'));
+                            get_string('sessions', 'attendance'));
         }
 
         if (has_capability('mod/attendance:manageattendances', $context)) {
             $toprow[] = new tabobject(self::TAB_ADD,
-                                     $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)),
-                        get_string('add', 'attendance'));
+                            $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)),
+                            get_string('addsession', 'attendance'));
         }
         if (has_capability('mod/attendance:viewreports', $context)) {
             $toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(),
-                        get_string('report', 'attendance'));
+                            get_string('report', 'attendance'));
         }
 
         if (has_capability('mod/attendance:export', $context)) {
             $toprow[] = new tabobject(self::TAB_EXPORT, $this->att->url_export()->out(),
-                        get_string('export', 'attendance'));
+                            get_string('export', 'attendance'));
         }
 
         if (has_capability('mod/attendance:changepreferences', $context)) {
             $toprow[] = new tabobject(self::TAB_PREFERENCES, $this->att->url_preferences()->out(),
-                        get_string('settings', 'attendance'));
+                            get_string('settings', 'attendance'));
         }
         if (has_capability('mod/attendance:managetemporaryusers', $context)) {
             $toprow[] = new tabobject(self::TAB_TEMPORARYUSERS, $this->att->url_managetemp()->out(),
-                                      get_string('tempusers', 'attendance'));
+                            get_string('tempusers', 'attendance'));
+        }
+        if ($this->currenttab == self::TAB_UPDATE && has_capability('mod/attendance:manageattendances', $context)) {
+            $toprow[] = new tabobject(self::TAB_UPDATE,
+                            $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_UPDATE)),
+                            get_string('changesession', 'attendance'));
         }
 
         return array($toprow);
@@ -138,7 +144,6 @@ class attendance_filter_controls implements renderable {
 
         $date = usergetdate($att->pageparams->curdate);
         $mday = $date['mday'];
-        $wday = $date['wday'];
         $mon = $date['mon'];
         $year = $date['year'];
 
@@ -355,7 +360,7 @@ class attendance_user_data implements renderable {
     private $urlparams;
 
     public function  __construct(attendance $att, $userid) {
-        global $CFG, $USER;
+        global $CFG;
 
         $this->user = $att->get_user($userid);
 
index fad4694..0ab4105 100644 (file)
@@ -234,7 +234,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
             $dta = $this->construct_date_time_actions($sessdata, $sess);
 
             $table->data[$sess->id][] = $i;
-            $table->data[$sess->id][] = $sess->groupid ? $sessdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance');
+            $table->data[$sess->id][] = $sess->groupid ? get_string('group') . ': ' . $sessdata->groups[$sess->groupid]->name :
+                                                         get_string('commonsession', 'attendance');
             $table->data[$sess->id][] = $dta['date'];
             $table->data[$sess->id][] = $dta['time'];
             $table->data[$sess->id][] = $sess->description;
@@ -769,7 +770,9 @@ class mod_attendance_renderer extends plugin_renderer_base {
 
             $row = new html_table_row();
             $row->cells[] = $i;
-            $row->cells[] = html_writer::tag('nobr', $sess->groupid ? $userdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance'));
+            $sessiontypeshort = $sess->groupid ? get_string('group') . ': ' . $userdata->groups[$sess->groupid]->name :
+                                                 get_string('commonsession', 'attendance');
+            $row->cells[] = html_writer::tag('nobr', $sessiontypeshort);
             $row->cells[] = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance'));
             $row->cells[] = $this->construct_time($sess->sessdate, $sess->duration);
             $row->cells[] = $sess->description;
@@ -847,7 +850,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
                 $sesstext = html_writer::link($reportdata->url_take($sess->id, $sess->groupid), $sesstext);
             }
             $sesstext .= html_writer::empty_tag('br');
-            $sesstext .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance');
+            $sesstext .= $sess->groupid ? get_string('group') . ': ' . $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance');
 
             $table->head[] = $sesstext;
             $table->align[] = 'center';
index 03d23f3..c2b1809 100644 (file)
@@ -62,16 +62,22 @@ $PAGE->set_cacheable(true);
 $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance'));
 $PAGE->navbar->add($att->name);
 
+$currenttab = attendance_tabs::TAB_ADD;
 $formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $context, 'att' => $att);
 switch ($att->pageparams->action) {
     case att_sessions_page_params::ACTION_ADD:
         $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD));
         $mform = new mod_attendance_add_form($url, $formparams);
 
+        if ($mform->is_cancelled()) {
+            redirect($att->url_manage());
+        }
+
         if ($formdata = $mform->get_data()) {
             $sessions = construct_sessions_data_for_add($formdata);
             $att->add_sessions($sessions);
-            $message = count($sessions) == 1 ? get_string('sessiongenerated', 'attendance') : get_string('sessionsgenerated', 'attendance', count($sessions));
+            $message = count($sessions) == 1 ? get_string('sessiongenerated', 'attendance') :
+                                               get_string('sessionsgenerated', 'attendance', count($sessions));
             mod_attendance_notifyqueue::notify_success($message);
             // Redirect to the sessions tab always showing all sessions.
             $SESSION->attcurrentattview[$cm->course] = ATT_VIEW_ALL;
@@ -95,6 +101,7 @@ switch ($att->pageparams->action) {
             mod_attendance_notifyqueue::notify_success(get_string('sessionupdated', 'attendance'));
             redirect($att->url_manage());
         }
+        $currenttab = attendance_tabs::TAB_UPDATE;
         break;
     case att_sessions_page_params::ACTION_DELETE:
         $sessionid = required_param('sessionid', PARAM_INT);
@@ -208,7 +215,7 @@ switch ($att->pageparams->action) {
 }
 
 $output = $PAGE->get_renderer('mod_attendance');
-$tabs = new attendance_tabs($att, attendance_tabs::TAB_ADD);
+$tabs = new attendance_tabs($att, $currenttab);
 echo $output->header();
 echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname));
 echo $output->render($tabs);
@@ -220,21 +227,21 @@ echo $OUTPUT->footer();
 function construct_sessions_data_for_add($formdata) {
     global $CFG;
 
-    $duration = $formdata->durtime['hours'] * HOURSECS + $formdata->durtime['minutes'] * MINSECS;
+    $sesstarttime = $formdata->sestime['starthour'] * HOURSECS + $formdata->sestime['startminute'] * MINSECS;
+    $sesendtime = $formdata->sestime['endhour'] * HOURSECS + $formdata->sestime['endminute'] * MINSECS;
+    $sessiondate = $formdata->sessiondate + $sesstarttime;
+    $duration = $sesendtime - $sesstarttime;
     $now = time();
 
     $sessions = array();
     if (isset($formdata->addmultiply)) {
-        $startdate = $formdata->sessiondate;
-        $starttime = $startdate - usergetmidnight($startdate);
+        $startdate = $sessiondate;
         $enddate = $formdata->sessionenddate + DAYSECS; // Because enddate in 0:0am.
 
         if ($enddate < $startdate) {
             return null;
         }
 
-        $days = (int)ceil(($enddate - $startdate) / DAYSECS);
-
         // Getting first day of week.
         $sdate = $startdate;
         $dinfo = usergetdate($sdate);
@@ -252,7 +259,7 @@ function construct_sessions_data_for_add($formdata) {
                 $dinfo = usergetdate($sdate);
                 if (isset($formdata->sdays) && array_key_exists($wdaydesc[$dinfo['wday']], $formdata->sdays)) {
                     $sess = new stdClass();
-                    $sess->sessdate = usergetmidnight($sdate) + $starttime;
+                    $sess->sessdate = usergetmidnight($sdate) + $sesstarttime;
                     $sess->duration = $duration;
                     $sess->descriptionitemid = $formdata->sdescription['itemid'];
                     $sess->description = $formdata->sdescription['text'];
@@ -273,7 +280,7 @@ function construct_sessions_data_for_add($formdata) {
         }
     } else {
         $sess = new stdClass();
-        $sess->sessdate = $formdata->sessiondate;
+        $sess->sessdate = $sessiondate;
         $sess->duration = $duration;
         $sess->descriptionitemid = $formdata->sdescription['itemid'];
         $sess->description = $formdata->sdescription['text'];
index cd579ee..fca1d84 100644 (file)
@@ -43,27 +43,44 @@ class mod_attendance_update_form extends moodleform {
         global $DB;
         $mform    =& $this->_form;
 
-        $course        = $this->_customdata['course'];
-        $cm            = $this->_customdata['cm'];
         $modcontext    = $this->_customdata['modcontext'];
         $sessionid     = $this->_customdata['sessionid'];
 
         if (!$sess = $DB->get_record('attendance_sessions', array('id' => $sessionid) )) {
             error('No such session in this course');
         }
-        $dhours = floor($sess->duration / HOURSECS);
-        $dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS);
         $defopts = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext);
         $sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attendance', 'session', $sess->id);
+
+        $starttime = $sess->sessdate - usergetmidnight($sess->sessdate);
+        $starthour = floor($starttime / HOURSECS);
+        $startminute = floor(($starttime - $starthour * HOURSECS) / MINSECS);
+
+        $enddate = $sess->sessdate + $sess->duration;
+        $endtime = $enddate - usergetmidnight($enddate);
+        $endhour = floor($endtime / HOURSECS);
+        $endminute = floor(($endtime - $endhour * HOURSECS) / MINSECS);
+
+        $sesendtime = $sess->sessdate + $sess->duration;
         $data = array('sessiondate' => $sess->sessdate,
-                'durtime' => array('hours' => $dhours, 'minutes' => $dmins),
+                'sestime' => array('starthour' => $starthour, 'startminute' => $startminute,
+                                   'endhour' => $endhour, 'endminute' => $endminute),
                 'sdescription' => $sess->description_editor);
 
         $mform->addElement('header', 'general', get_string('changesession', 'attendance'));
 
-        $mform->addElement('static', 'olddate', get_string('olddate', 'attendance'),
-                           userdate($sess->sessdate, get_string('strftimedmyhm', 'attendance')));
-        $mform->addElement('date_time_selector', 'sessiondate', get_string('newdate', 'attendance'));
+        if ($sess->groupid == 0) {
+            $strtype = get_string('commonsession', 'attendance');
+        } else {
+            $groupname = $DB->get_field('groups', 'name', array('id' => $sess->groupid));
+            $strtype = get_string('group') . ': ' . $groupname;
+        }
+        $mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attendance'), $strtype);
+
+        $olddate = construct_session_full_date_time($sess->sessdate, $sess->duration);
+        $mform->addElement('static', 'olddate', get_string('olddate', 'attendance'), $olddate);
+
+        $mform->addElement('date_selector', 'sessiondate', get_string('sessiondate', 'attendance'));
 
         for ($i = 0; $i <= 23; $i++) {
             $hours[$i] = sprintf("%02d", $i);
@@ -71,9 +88,15 @@ class mod_attendance_update_form extends moodleform {
         for ($i = 0; $i < 60; $i += 5) {
             $minutes[$i] = sprintf("%02d", $i);
         }
-        $durselect[] =& $mform->createElement('select', 'hours', '', $hours);
-        $durselect[] =& $mform->createElement('select', 'minutes', '', $minutes, false, true);
-        $mform->addGroup($durselect, 'durtime', get_string('duration', 'attendance'), array(' '), true);
+
+        $sesendtime = array();
+        $sesendtime[] =& $mform->createElement('static', 'from', '', get_string('from', 'attendance'));
+        $sesendtime[] =& $mform->createElement('select', 'starthour', get_string('hour', 'form'), $hours, false, true);
+        $sesendtime[] =& $mform->createElement('select', 'startminute', get_string('minute', 'form'), $minutes, false, true);
+        $sesendtime[] =& $mform->createElement('static', 'to', '', get_string('to', 'attendance'));
+        $sesendtime[] =& $mform->createElement('select', 'endhour', get_string('hour', 'form'), $hours, false, true);
+        $sesendtime[] =& $mform->createElement('select', 'endminute', get_string('minute', 'form'), $minutes, false, true);
+        $mform->addGroup($sesendtime, 'sestime', get_string('time', 'attendance'), array(' '), true);
 
         // Show which status set is in use.
         $maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id);
@@ -81,12 +104,30 @@ class mod_attendance_update_form extends moodleform {
             $mform->addElement('static', 'statusset', get_string('usestatusset', 'mod_attendance'),
                                att_get_setname($this->_customdata['att']->id, $sess->statusset));
         }
-        $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), null, $defopts);
+
+        $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'),
+                           array('rows' => 1, 'columns' => 80), $defopts);
         $mform->setType('sdescription', PARAM_RAW);
 
         $mform->setDefaults($data);
 
-        $submitstring = get_string('update', 'attendance');
-        $this->add_action_buttons(true, $submitstring);
+        $this->add_action_buttons(true);
+    }
+
+    /**
+     * Perform minimal validation on the settings form
+     * @param array $data
+     * @param array $files
+     */
+    public function validation($data, $files) {
+        $errors = parent::validation($data, $files);
+
+        $sesstarttime = $data['sestime']['starthour'] * HOURSECS + $data['sestime']['startminute'] * MINSECS;
+        $sesendtime = $data['sestime']['endhour'] * HOURSECS + $data['sestime']['endminute'] * MINSECS;
+        if ($sesendtime < $sesstarttime) {
+            $errors['sestime'] = get_string('invalidsessionendtime', 'attendance');
+        }
+
+        return $errors;
     }
 }