]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8877, specify time of manual enrolments and related improvements for changing...
authortoyomoyo <toyomoyo>
Tue, 22 May 2007 02:08:22 +0000 (02:08 +0000)
committertoyomoyo <toyomoyo>
Tue, 22 May 2007 02:08:22 +0000 (02:08 +0000)
admin/roles/assign.html
admin/roles/assign.php
lang/en_utf8/moodle.php
lib/gradelib.php
user/action_redir.php
user/extendenrol.php
user/index.php

index b350b4bb1cad90ef3cde0cd2cc8f967a1f02a9a8..158c5ca87c3bd1d931d8cf38a7dcde37a3389558 100755 (executable)
@@ -1,5 +1,8 @@
 <form id="assignform" method="post" action="">
-<div>
+<div style="text-align:center;">
+<label for="extendperiod"><?php print_string('enrolperiod') ?></label> <?php choose_from_menu($periodmenu, "extendperiod", $defaultperiod, $unlimitedperiod); ?>
+<label for="extendperiod"><?php print_string('startingfrom') ?></label> <?php choose_from_menu($basemenu, "extendbase", 3, ""); ?>
+
 <input type="hidden" name="previoussearch" value="<?php p($previoussearch) ?>" />
 <input type="hidden" name="userid" value="<?php p($userid) ?>" />
 <input type="hidden" name="courseid" value="<?php p($courseid) ?>" />
index 3cc60513ff1b288bb473fbc574e3071de9427efb..a0788e5259033211c420a933576c9e96df25b067 100755 (executable)
@@ -17,6 +17,7 @@
     $hidden         = optional_param('hidden', 0, PARAM_BOOL); // whether this assignment is hidden
     $timestart      = optional_param('timestart', 0, PARAM_INT);
     $timeend        = optional_param('timened', 0, PARAM_INT);
+    $extendperiod   = optional_param('extendperiod', 0, PARAM_INT);
     $userid         = optional_param('userid', 0, PARAM_INT); // needed for user tabs
     $courseid       = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
 
     $strparticipants = get_string('participants');
     $strsearchresults = get_string('searchresults');
 
+    $unlimitedperiod = get_string('unlimited');
+    $defaultperiod = $course->enrolperiod;
+    for ($i=1; $i<=365; $i++) {
+        $seconds = $i * 86400;
+        $periodmenu[$seconds] = get_string('numdays', '', $i);
+    }
 
-
+    $timeformat = get_string('strftimedate');
+    $basemenu[0] = get_string('startdate') . ' (' . userdate($course->startdate, $timeformat) . ')';
+    if(time() > $course->startdate) {
+        $basemenu[3] = get_string('today') . ' (' . userdate(time(), $timeformat) . ')' ;
+    }
+    if($course->enrollable == 2) {
+        if($course->enrolstartdate > 0) {
+            $basemenu[4] = get_string('courseenrolstartdate') . ' (' . userdate($course->enrolstartdate, $timeformat) . ')';
+        }
+        if($course->enrolenddate > 0) {
+            $basemenu[5] = get_string('courseenrolenddate') . ' (' . userdate($course->enrolenddate, $timeformat) . ')';
+        }
+    }
+    
 /// Make sure this user can assign that role
 
     if ($roleid) {
                     }
                 }
                 if ($allow) {
+                    $timestart = $timemodified;
+                    if($extendperiod > 0) {
+                        $timeend = $timestart + $extendperiod;
+                    } else {
+                        $timeend = 0;
+                    }
                     if (! role_assign($roleid, $adduser, 0, $context->id, $timestart, $timeend, $hidden)) {
                         $errors[] = "Could not add user with id $adduser to this role!";
                     }
index f2743ec19e8f80951a40fa0b67ea3a36ef3ba151..fbb1a51b6ddbce62d2e5fc75f493d969746bd898 100644 (file)
@@ -584,6 +584,10 @@ Please contact your $a->teacherstr for any further enquiries.';
 $string['expirythreshold'] = 'Threshold';
 $string['explanation'] = 'Explanation';
 $string['extendenrol'] = 'Extend enrolment';
+$string['groupextendenrol'] = 'Extend enrolment for all';
+$string['courseenrolstartdate'] = 'Course enrolment start date';
+$string['courseenrolenddate'] = 'Course enrolment end date';
+$string['startingfrom'] = 'Starting from';
 $string['extendperiod'] = 'Extended period';
 $string['failedloginattempts'] = '$a->attempts failed logins since your last login';
 $string['failedloginattemptsall'] = '$a->attempts failed logins for $a->accounts accounts';
index 12340effa054648cbbc862eabd8e157383b1c9a2..a1df02f103a15400c7c595d9b1d6a94e64f2c9ca 100644 (file)
@@ -195,7 +195,7 @@ function grades_grab_grades() {
             if (function_exists($gradefunc) && !event_is_registered($mod, $gradefunc)) {
                 // get all instance of the mod
                 $module = get_record('modules', 'name', $mod);
-                if ($module && $modinstances = get_records('course_modules', 'module', $module->id)) {
+                if ($module && $modinstances = get_records_select('course_modules cm, '.$CFG->prefix.$mod.' m', 'cm.module = '.$module->id.' AND m.id = cm.instance')) {
                     foreach ($modinstances as $modinstance) {
                         // for each instance, call the xxx_grades() function
                         if ($grades = $gradefunc($modinstance->instance)) {
@@ -210,6 +210,7 @@ function grades_grab_grades() {
                                 $eventdata->gradetype = 0;
                                 $eventdata->userid = $userid;
                                 $eventdata->gradevalue = $usergrade;
+                                $eventdata->itemname = $modinstance->name;
                                 trigger_event('grade_added', $eventdata);                             
                                                        
                             }
index 157ff1b096086ab96ff9ddee999e1d04bdd8e9c9..4351c3f3918d4574c54685a520afdd2af4a9467f 100644 (file)
@@ -11,7 +11,8 @@ $id = required_param('id', PARAM_INT);
 // Add every page will be redirected by this script
 $actions = array(
         'messageselect.php',
-        'extendenrol.php'
+        'extendenrol.php',
+        'groupextendenrol.php',
         );
 
 if (array_search($formaction, $actions) === false) {
index 304922264f36b67c7ff1791663e62fc997b3418c..f0ae686917c46894325a1514afc3015f2fc4a329 100644 (file)
@@ -15,7 +15,7 @@ require_login($course->id);
 require_capability('moodle/role:assign', $context);
 
 if ((count($users) > 0) and ($form = data_submitted()) and confirm_sesskey()) {
-    if (count($form->userid) != count($form->extendperiod)) {
+    if (count($form->userid) != count($form->extendperiod) || count($form->userid) != count($form->extendbase)) {
         error('Parameters malformation', $CFG->wwwroot.'/user/index.php?id='.$id);
     }
 
@@ -30,7 +30,48 @@ if ((count($users) > 0) and ($form = data_submitted()) and confirm_sesskey()) {
             foreach ($students as $student) {
                 // only extend if the user can make role assignments on this role
                 if (user_can_assign($context, $student->roleid)) {
-                    role_assign($student->roleid, $v, 0, $context->id, $student->timestart, $student->timeend + $form->extendperiod[$k], 0);
+                    switch($form->extendperiod[$k]) {
+                        case 0: // No change
+                            break;
+                        case -1: // unlimited
+                            $student->timeend = 0;
+                            break;
+                        default: // extend
+                            switch($form->extendbase[$k]) {
+                                case 0: // course start date
+                                    $student->timeend = $course->startdate + $form->extendperiod[$k];
+                                    break;
+                                case 1: // student enrolment start date
+                                    // we check for student enrolment date because Moodle versions before 1.9 did not set this for
+                                    // unlimited enrolment courses, so it might be 0
+                                    if($student->timestart > 0) {
+                                        $student->timeend = $student->timestart + $form->extendperiod[$k];
+                                    }
+                                    break;
+                                case 2: // student enrolment start date
+                                    // enrolment end equals 0 means Unlimited, so adding some time to that will still yield Unlimited
+                                    if($student->timeend > 0) {
+                                        $student->timeend = $student->timeend + $form->extendperiod[$k];
+                                    }
+                                    break;
+                                case 3: // current date
+                                    if(time() > $course->startdate) {
+                                        $student->timeend = time() + $form->extendperiod[$k];
+                                    }
+                                    break;
+                                case 4: // course enrolment start date
+                                    if($course->enrolstartdate > 0) {
+                                        $student->timeend = $course->enrolstartdate + $form->extendperiod[$k];
+                                    }
+                                    break;
+                                case 5: // course enrolment end date
+                                    if($course->enrolenddate > 0) {
+                                        $student->timeend = $course->enrolenddate + $form->extendperiod[$k];
+                                    }
+                                    break;
+                            }
+                    } 
+                    role_assign($student->roleid, $v, 0, $context->id, $student->timestart, $student->timeend, 0);
                 }
             }
         }
@@ -50,22 +91,40 @@ if ($course->id != SITEID) {
     get_string('extendenrol'), "", "", true, "&nbsp;", navmenu($course));
 }
 
+$timeformat = get_string('strftimedate');
+$unlimited = get_string('unlimited');
+$periodmenu[-1] = $unlimited;
 for ($i=1; $i<=365; $i++) {
     $seconds = $i * 86400;
     $periodmenu[$seconds] = get_string('numdays', '', $i);
 }
 
-print_heading(get_string('extendenrol'));
+// this will contain all available the based On select options, but we'll disable some on them on a per user basis
+$basemenu[0] = get_string('startdate') . ' (' . userdate($course->startdate, $timeformat) . ')';
+$basemenu[1] = get_string('enrolmentstart');
+$basemenu[2] = get_string('enrolmentend');
+if(time() > $course->startdate) {
+    $basemenu[3] = get_string('today') . ' (' . userdate(time(), $timeformat) . ')' ;
+}
+if($course->enrollable == 2) {
+    if($course->enrolstartdate > 0) {
+        $basemenu[4] = get_string('courseenrolstartdate') . ' (' . userdate($course->enrolstartdate, $timeformat) . ')';
+    }
+    if($course->enrolenddate > 0) {
+        $basemenu[5] = get_string('courseenrolenddate') . ' (' . userdate($course->enrolenddate, $timeformat) . ')';
+    }
+}
+
+$title = get_string('extendenrol');
+print_heading($title . helpbutton('extendenrol', $title, 'moodle', true, false, '', true));
 echo "<form method=\"post\" action=\"extendenrol.php\">\n";
 echo '<input type="hidden" name="id" value="'.$course->id.'" />';
 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
-$table->head  = array (get_string('fullname'), get_string('enrolmentstart'), get_string('enrolmentend'), get_string('extendperiod'));
+$table->head  = array (get_string('fullname'), get_string('enrolmentstart'), get_string('enrolmentend'), get_string('extendperiod'), get_string('startingfrom'));
 $table->align = array ('left', 'center', 'center', 'center');
 $table->width = "600";
-$timeformat = get_string('strftimedate');
 $nochange = get_string('nochange');
 $notavailable = get_string('notavailable');
-$unlimited = get_string('unlimited');
 foreach ($_POST as $k => $v) {
     if (preg_match('/^user(\d+)$/',$k,$m)) {
         
@@ -74,23 +133,27 @@ foreach ($_POST as $k => $v) {
                                     WHERE u.id={$m[1]} AND ra.contextid = $context->id"))) {
             continue;
         }
+        $userbasemenu = $basemenu;
         if ($user->timestart) {
             $timestart = userdate($user->timestart, $timeformat);
         } else {
             $timestart = $notavailable;
+            unset($userbasemenu[1]);
         }
         if ($user->timeend) {
             $timeend = userdate($user->timeend, $timeformat);
-            $checkbox = choose_from_menu($periodmenu, "extendperiod[{$m[1]}]", "0", $nochange, '', '0', true);
         } else {
             $timeend = $unlimited;
-            $checkbox = '<input type="hidden" name="extendperiod['.$m[1].']" value="0" />'.$nochange;
+            unset($userbasemenu[2]);
         }
+        $checkbox = choose_from_menu($periodmenu, "extendperiod[{$m[1]}]", "0", $nochange, '', '0', true);
+        $checkbox2 = choose_from_menu($userbasemenu, "extendbase[{$m[1]}]", "2", "", '', '0', true);
         $table->data[] = array(
         fullname($user, true),
         $timestart,
         $timeend,
-        '<input type="hidden" name="userid['.$m[1].']" value="'.$m[1].'" />'.$checkbox
+        '<input type="hidden" name="userid['.$m[1].']" value="'.$m[1].'" />'.$checkbox,
+        $checkbox2
         );
     }
 }
index c92f2508817b9c5cb48a0bd5bb50291d562240bf..db71b6ce57bec46787c33dc33fd32942b2045663 100644 (file)
         echo '</td>';
     }
 
-    if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/site:accessallgroups', $context))) {
-        if ($groups_names = groups_get_groups_names($course->id)) { //TODO:
-            echo '<td class="left">';
-            print_group_menu($groups_names, $groupmode, $currentgroup, $baseurl);
-            echo '</td>';
-        }
-    }
+    echo '<td class="left">';
+    setup_and_print_groups($course, $groupmode, $baseurl);
+    echo '</td>';
 
     // get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
     // this might not work anymore because you always going to get yourself as the most recent entry? added $USER!=$user ch
         if (has_capability('moodle/site:readallmessages', $context)) {
             $displaylist['messageselect.php'] = get_string('messageselectadd');
         }
-        if ($course->enrolperiod) {
-            $displaylist['extendenrol.php'] = get_string('extendenrol');
-        }
+        
+        $displaylist['extendenrol.php'] = get_string('extendenrol');
+        $displaylist['groupextendenrol.php'] = get_string('groupextendenrol');
+        
         helpbutton("participantswithselectedusers", get_string("withselectedusers"));
         choose_from_menu ($displaylist, "formaction", "", get_string("withselectedusers"), "if(checksubmit(this.form))this.form.submit();", "");
         echo '<input type="hidden" name="id" value="'.$course->id.'" />';