From f950af3c43b2f7b285824ba5d1635e09da0cfd2f Mon Sep 17 00:00:00 2001
From: gustav_delius
Are you sure you wish to do this?';
$string['enrolmentkey'] = 'Enrolment key';
$string['enrolmentkeyfrom'] = 'This course requires an \'enrolment key\' - a one-time
diff --git a/lib/datalib.php b/lib/datalib.php
index 5f54fb1681..2c530787a8 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -947,8 +947,8 @@ function get_user_info_from_db($field, $value) {
$user->admin = true;
}
- if ($site = get_site()) { // Everyone is always a member of the top course
- $user->student[$site->id] = true;
+ if ($site = get_site()) {
+ $user->student[$site->id] = isstudent($site->id, $user->id);
}
/// Determine enrolments based on current enrolment module
@@ -1152,15 +1152,6 @@ function get_course_students($courseid, $sort="s.timeaccess", $dir="", $page=0,
global $CFG;
- $site = get_site();
- if (!$courseid or $courseid == $site->id) {
- $sort = str_replace('s.timeaccess', 'lastaccess', $sort); // site users can't be sorted by timeaccess
- if ($sort) {
- $sort = "$sort $dir";
- }
- return get_site_users($sort, '', $exceptions);
- }
-
switch ($CFG->dbtype) {
case "mysql":
$fullname = " CONCAT(firstname,\" \",lastname) ";
@@ -1179,7 +1170,15 @@ function get_course_students($courseid, $sort="s.timeaccess", $dir="", $page=0,
}
$groupmembers = '';
- $select = "s.course = '$courseid' AND s.userid = u.id AND u.deleted = '0' ";
+
+ // make sure it works on the site course
+ $select = "s.course = '$courseid' AND ";
+ $site = get_site();
+ if ($courseid == $site->id) {
+ $select = '';
+ }
+
+ $select .= "s.userid = u.id AND u.deleted = '0' ";
if (!$fields) {
$fields = 'u.id, u.confirmed, u.username, u.firstname, u.lastname, '.
@@ -1306,19 +1305,11 @@ function get_course_teachers($courseid, $sort="t.authority ASC", $exceptions='')
/**
* Returns all the users of a course: students and teachers
-*
-* If the "course" is actually the site, then return all site users.
*
* @param type description
*/
function get_course_users($courseid, $sort="timeaccess DESC", $exceptions='') {
- $site = get_site();
-
- if ($courseid == $site->id) {
- return get_site_users($sort, '', $exceptions);
- }
-
/// Using this method because the single SQL is too inefficient
// Note that this has the effect that teachers and students are
// sorted individually. Returns first all teachers, then all students
diff --git a/lib/db/mysql.php b/lib/db/mysql.php
index 8db8532e1a..cfc0648cc5 100644
--- a/lib/db/mysql.php
+++ b/lib/db/mysql.php
@@ -821,6 +821,14 @@ function main_upgrade($oldversion=0) {
execute_sql("UPDATE {$CFG->prefix}user SET auth = '$CFG->auth' WHERE id NOT IN ($adminlist)");
}
}
+
+ if ($oldversion < 2004082200) { // Making admins teachers on site course
+ $site = get_site();
+ $admins = get_admins();
+ foreach ($admins as $admin) {
+ add_teacher($admin->id, $site->id);
+ }
+ }
return $result;
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 285bad3a4b..752c0ebefe 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -430,6 +430,19 @@ function require_login($courseid=0, $autologinguest=true) {
}
}
+function require_course_login($course, $autologinguest=true) {
+// This is a weaker version of require_login which only requires login
+// when called from within a course rather than the site page, unless
+// the forcelogin option is turned on.
+ global $CFG;
+ if ($CFG->forcelogin) {
+ require_login();
+ }
+ if ($course->category) {
+ require_login($course->id, $autologinguest);
+ }
+}
+
function update_user_login_times() {
global $USER;
@@ -583,8 +596,8 @@ function isstudent($courseid, $userid=0) {
if (isguest($userid)) {
return false;
}
- return record_exists('user', 'id', $userid, 'confirmed', 1, 'deleted', 0);
- }
+ return record_exists('user_students', 'userid', $userid);
+ }
if (!$userid) {
return !empty($USER->student[$courseid]);
@@ -952,6 +965,15 @@ function add_admin($userid) {
if (!record_exists("user_admins", "userid", $userid)) {
if (record_exists("user", "id", $userid)) {
$admin->userid = $userid;
+
+ // any admin is also a teacher on the site course
+ $site = get_site();
+ if (!record_exists('user_teachers', 'course', $site->id, 'userid', $userid)) {
+ if (!add_teacher($userid, $site->id)) {
+ return false;
+ }
+ }
+
return insert_record("user_admins", $admin);
}
return false;
@@ -963,6 +985,10 @@ function remove_admin($userid) {
/// Removes an admin from a site
global $db;
+ // remove also from the list of site teachers
+ $site = get_site();
+ remove_teacher($userid, $site->id);
+
return delete_records("user_admins", "userid", $userid);
}
diff --git a/mod/assignment/index.php b/mod/assignment/index.php
index f288c48ec9..7cbe078eba 100644
--- a/mod/assignment/index.php
+++ b/mod/assignment/index.php
@@ -9,7 +9,7 @@
error("Course ID is incorrect");
}
- require_login($course->id);
+ require_course_login($course);
add_to_log($course->id, "assignment", "view all", "index.php?id=$course->id", "");
$strassignments = get_string("modulenameplural", "assignment");
@@ -52,6 +52,7 @@
$currentsection = "";
foreach ($assignments as $assignment) {
+ $submitted = get_string("no");
if (isteacher($course->id)) {
if ($assignment->type == OFFLINE) {
$submitted = "id\">" .
@@ -62,14 +63,14 @@
get_string("viewsubmissions", "assignment", $count) . "$groupname";
}
} else {
- if ($submission = assignment_get_submission($assignment, $USER)) {
- if ($submission->timemodified <= $assignment->timedue) {
- $submitted = userdate($submission->timemodified);
- } else {
- $submitted = "".userdate($submission->timemodified)."";
+ if (isset($USER->id)) {
+ if ($submission = assignment_get_submission($assignment, $USER)) {
+ if ($submission->timemodified <= $assignment->timedue) {
+ $submitted = userdate($submission->timemodified);
+ } else {
+ $submitted = "".userdate($submission->timemodified)."";
+ }
}
- } else {
- $submitted = get_string("no");
}
}
diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php
index 0fd16af2b6..234c83daa9 100644
--- a/mod/assignment/lib.php
+++ b/mod/assignment/lib.php
@@ -423,14 +423,18 @@ function assignment_count_real_submissions($assignment, $groupid=0) {
AND a.timemodified > 0
AND g.groupid = '$groupid'
AND a.userid = g.userid ");
- } else {
+ } else {
+ $select = "s.course = '$assignment->course' AND";
+ $site = get_site();
+ if ($assignment->course == $site->id) {
+ $select = '';
+ }
return count_records_sql("SELECT COUNT(*)
FROM {$CFG->prefix}assignment_submissions a,
{$CFG->prefix}user_students s
WHERE a.assignment = '$assignment->id'
AND a.timemodified > 0
- AND s.course = '$assignment->course'
- AND a.userid = s.userid ");
+ AND $select a.userid = s.userid ");
}
}
@@ -445,26 +449,36 @@ function assignment_get_all_submissions($assignment, $sort="", $dir="DESC") {
} else {
$sort = "a.$sort $dir";
}
+
+ $select = "s.course = '$assignment->course' AND";
+ $site = get_site();
+ if ($assignment->course == $site->id) {
+ $select = '';
+ }
return get_records_sql("SELECT a.*
FROM {$CFG->prefix}assignment_submissions a,
{$CFG->prefix}user_students s,
{$CFG->prefix}user u
WHERE a.userid = s.userid
AND u.id = a.userid
- AND s.course = '$assignment->course'
- AND a.assignment = '$assignment->id'
+ AND $select a.assignment = '$assignment->id'
ORDER BY $sort");
}
function assignment_get_users_done($assignment) {
/// Return list of users who have done an assignment
global $CFG;
+
+ $select = "s.course = '$assignment->course' AND";
+ $site = get_site();
+ if ($assignment->course == $site->id) {
+ $select = '';
+ }
return get_records_sql("SELECT u.*
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_students s,
{$CFG->prefix}assignment_submissions a
- WHERE s.course = '$assignment->course'
- AND s.userid = u.id
+ WHERE $select s.userid = u.id
AND u.id = a.userid
AND a.assignment = '$assignment->id'
ORDER BY a.timemodified DESC");
@@ -473,7 +487,7 @@ function assignment_get_users_done($assignment) {
function assignment_get_unmailed_submissions($cutofftime) {
/// Return list of marked submissions that have not been mailed out for currently enrolled students
global $CFG;
- return get_records_sql("SELECT s.*, a.course, a.name
+ $records = get_records_sql("SELECT s.*, a.course, a.name
FROM {$CFG->prefix}assignment_submissions s,
{$CFG->prefix}assignment a,
{$CFG->prefix}user_students us
@@ -483,6 +497,19 @@ function assignment_get_unmailed_submissions($cutofftime) {
AND s.assignment = a.id
AND s.userid = us.userid
AND a.course = us.course");
+ $site = get_site();
+ if (record_exists('assignment', 'course', $site->id)) {
+ $records += get_records_sql("SELECT s.*, a.course, a.name
+ FROM {$CFG->prefix}assignment_submissions s,
+ {$CFG->prefix}assignment a,
+ {$CFG->prefix}user_students us
+ WHERE s.mailed = 0
+ AND s.timemarked < $cutofftime
+ AND s.timemarked > 0
+ AND s.assignment = a.id
+ AND s.userid = us.userid
+ AND a.course = $site->id");
+ }
}
diff --git a/mod/assignment/view.php b/mod/assignment/view.php
index d2125115e0..1f058f30b4 100644
--- a/mod/assignment/view.php
+++ b/mod/assignment/view.php
@@ -31,7 +31,7 @@
}
}
- require_login($course->id);
+ require_course_login($course);
add_to_log($course->id, "assignment", "view", "view.php?id=$cm->id", $assignment->id, $cm->id);
@@ -94,7 +94,7 @@
print_simple_box_end();
echo "
";
- if (!isteacher($course->id) and !isguest()) {
+ if (isstudent($course->id)) {
$submission = assignment_get_submission($assignment, $USER);
if ($assignment->type == OFFLINE) {
diff --git a/mod/attendance/index.php b/mod/attendance/index.php
index 2055f4113c..7922744f01 100644
--- a/mod/attendance/index.php
+++ b/mod/attendance/index.php
@@ -13,7 +13,7 @@
error("Course ID is incorrect");
}
- require_login($course->id);
+ require_course_login($course);
add_to_log($course->id, "attendance", "viewall", "index.php?id=$course->id", "");
diff --git a/mod/attendance/lib.php b/mod/attendance/lib.php
index f37b96264b..bee964aff2 100755
--- a/mod/attendance/lib.php
+++ b/mod/attendance/lib.php
@@ -31,44 +31,44 @@ function attendance_add_module(&$mod) {
}
function attendance_add_instance($attendance) {
- global $mod;
+ global $mod;
$attendance->timemodified = time();
$attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
$attendance->autoattend = !empty($attendance->autoattend) ? 1 : 0;
$attendance->grade = !empty($attendance->grade) ? 1 : 0;
if (empty($attendance->day)) {
$attendance->day = make_timestamp($attendance->theyear,
- $attendance->themonth, $attendance->theday);
+ $attendance->themonth, $attendance->theday);
}
$attendance->notes = $attendance->name;
$attendance->name=userdate($attendance->day, get_string("strftimedate"));
- if ($attendance->notes) {
- $attendance->name = $attendance->name . " - " . $attendance->notes;
- }
- $attendance->edited = 0;
+ if ($attendance->notes) {
+ $attendance->name = $attendance->name . " - " . $attendance->notes;
+ }
+ $attendance->edited = 0;
if ($attendance->dynsection) {
- if ($mod->course) {
- if (! $course = get_record("course", "id", $mod->course)) {
- error("Course is misconfigured");
- }
- }
+ if ($mod->course) {
+ if (! $course = get_record("course", "id", $mod->course)) {
+ error("Course is misconfigured");
+ }
+ }
if ($course->format =="weeks") {
-// floor($date_relative / 604800) + 1
- $attendance->section = floor(($attendance->day - $course->startdate)/604800) +1;
- if($attendance->section > $course->numsections){
- $attendance->section = 0;
- }
- $attendance->section = "$attendance->section";
- $mod->section = "$attendance->section";
+// floor($date_relative / 604800) + 1
+ $attendance->section = floor(($attendance->day - $course->startdate)/604800) +1;
+ if($attendance->section > $course->numsections){
+ $attendance->section = 0;
+ }
+ $attendance->section = "$attendance->section";
+ $mod->section = "$attendance->section";
}
}
- // insert the main record first
- return $attendance->id = insert_record("attendance", $attendance);
+ // insert the main record first
+ return $attendance->id = insert_record("attendance", $attendance);
}
function attendance_update_instance($attendance) {
- global $mod;
+ global $mod;
$attendance->edited = 1;
$attendance->timemodified = time();
// $attendance->oldid=$attendance->id;
@@ -78,76 +78,76 @@ function attendance_update_instance($attendance) {
$attendance->grade = !empty($attendance->grade) ? 1 : 0;
$attendance->day = make_timestamp($attendance->theyear,
- $attendance->themonth, $attendance->theday);
+ $attendance->themonth, $attendance->theday);
$attendance->notes = $attendance->name;
$attendance->name=userdate($attendance->day, get_string("strftimedate"));
- if ($attendance->notes) {
- $attendance->name = $attendance->name . " - " . $attendance->notes;
- }
+ if ($attendance->notes) {
+ $attendance->name = $attendance->name . " - " . $attendance->notes;
+ }
if ($attendance->dynsection) {
- //get info about the course
- if ($attendance->course) {
- if (! $course = get_record("course", "id", $attendance->course)) {
- error("Course is misconfigured");
- }
- }
- //work out which section this should be in
- $attendance->section = floor(($attendance->day - $course->startdate)/604800) +1;
- if (($attendance->section > $course->numsections) || ($attendance->section < 0)){
- $attendance->section = 0;
- }
-// $attendance->section = "$attendance->section";
- }
- // get the data from the attendance grid
+ //get info about the course
+ if ($attendance->course) {
+ if (! $course = get_record("course", "id", $attendance->course)) {
+ error("Course is misconfigured");
+ }
+ }
+ //work out which section this should be in
+ $attendance->section = floor(($attendance->day - $course->startdate)/604800) +1;
+ if (($attendance->section > $course->numsections) || ($attendance->section < 0)){
+ $attendance->section = 0;
+ }
+// $attendance->section = "$attendance->section";
+ }
+ // get the data from the attendance grid
if ($data = data_submitted()) {
// Peel out all the data from variable names.
$attrec->dayid = $attendance->id;
if ($data) foreach ($data as $key => $val) {
$pieces = explode('_',$key);
if ($pieces[0] == 'student') {
- $attrec->userid=$pieces[1];
+ $attrec->userid=$pieces[1];
$attrec->hour=$pieces[2];
$attrec->status=$val;
// clear out any old records for the student
- delete_records("attendance_roll",
+ delete_records("attendance_roll",
"dayid",$attrec->dayid,
"hour", $attrec->hour,
"userid",$attrec->userid);
if ($attrec->status != 0) {
// student is registered as absent or tardy
- insert_record("attendance_roll",$attrec, false);
+ insert_record("attendance_roll",$attrec, false);
}
- } // if we have a piece of the student roll data
+ } // if we have a piece of the student roll data
} // foreach for all form variables
- } // if
-
-
- if(!update_record("attendance", $attendance)){
- error("Couldn't update record");
- }
-
- if ($attendance->dynsection) {
- //get section info
- $section = get_record("course_sections", "course", $attendance->course, "section", $attendance->section);
-
- //remove module from the current section
- if (! delete_mod_from_section($attendance->coursemodule, $mod->section)) {
- notify("Could not delete module from existing section");
- }
-
- //update course with new module location
- if(! set_field("course_modules", "section", $section->id, "id", $attendance->coursemodule)){
- notify("Could not update course module list");
- }
-
- //add module to the new section
- if (! add_mod_to_section($attendance, NULL)) {
- notify("Could not add module to new section");
- }
-
- rebuild_course_cache($section->course);
- }
- return true;
+ } // if
+
+
+ if(!update_record("attendance", $attendance)){
+ error("Couldn't update record");
+ }
+
+ if ($attendance->dynsection) {
+ //get section info
+ $section = get_record("course_sections", "course", $attendance->course, "section", $attendance->section);
+
+ //remove module from the current section
+ if (! delete_mod_from_section($attendance->coursemodule, $mod->section)) {
+ notify("Could not delete module from existing section");
+ }
+
+ //update course with new module location
+ if(! set_field("course_modules", "section", $section->id, "id", $attendance->coursemodule)){
+ notify("Could not update course module list");
+ }
+
+ //add module to the new section
+ if (! add_mod_to_section($attendance, NULL)) {
+ notify("Could not add module to new section");
+ }
+
+ rebuild_course_cache($section->course);
+ }
+ return true;
}
function attendance_delete_instance($id) {
@@ -174,46 +174,46 @@ function attendance_user_outline($course, $user, $mod, $attendance) {
/// $return->time = the time they did it
/// $return->info = a short text description
/// for attendance, this would be a list present and tardy for every hour of the day
- $tardies=count_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 1);
- $absences=count_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 2);
-
+ $tardies=count_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 1);
+ $absences=count_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 2);
+
// build longer string for tardies
- if ($tardies > 0) {
- $tardyrecs=attendance_get_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 1, "hour ASC");
- if ($tardies == 1) {
- $tardystring = "Tardy in hour " . $tardyrecs[0]->hour . ". ";
- } elseif ($tardies == $attendance->hours) {
- $tardystring = "Tardy in all hours. (" . $attendance->hours . ") ";
- } else {
- // build array of all tardies
- $tarr = array();
- if ($tardyrecs) foreach ($tardyrecs as $tardyrec) {
- array_push($tarr, $tardyrec->hour);
- $tardystring = $tardystring . ", " . $tardyrec->hour;
- }
- $end=array_pop($tarr);
- $tardystring = "Tardy in hours " . implode(", ", $tarr) . " and ". $end . ". ";
- }
- } else { $tardystring = "";}
+ if ($tardies > 0) {
+ $tardyrecs=attendance_get_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 1, "hour ASC");
+ if ($tardies == 1) {
+ $tardystring = "Tardy in hour " . $tardyrecs[0]->hour . ". ";
+ } elseif ($tardies == $attendance->hours) {
+ $tardystring = "Tardy in all hours. (" . $attendance->hours . ") ";
+ } else {
+ // build array of all tardies
+ $tarr = array();
+ if ($tardyrecs) foreach ($tardyrecs as $tardyrec) {
+ array_push($tarr, $tardyrec->hour);
+ $tardystring = $tardystring . ", " . $tardyrec->hour;
+ }
+ $end=array_pop($tarr);
+ $tardystring = "Tardy in hours " . implode(", ", $tarr) . " and ". $end . ". ";
+ }
+ } else { $tardystring = "";}
// build longer string for absences
- if ($absences > 0) {
- $absrecs=attendance_get_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 2, "hour ASC");
- if ($absences == 1) {
- $absstring = "Absent in hour " . $absrecs[0]->hour . ".";
- } elseif ($absences == $attendance->hours) {
- $absstring = "Absent in all hours. (" . $attendance->hours . ")";
- } else {
- // build array of all absences
- $aarr = array();
- if ($absrecs) foreach ($absrecs as $absrec) {
- array_push($aarr, $absrec->hour);
- }
- $end=array_pop($aarr);
- $absstring = "Absent in hours " . implode(", ", $aarr) . " and ". $end . ".";
- }
- } else { $absstring = "";}
- $return->info=$tardystring . $absstring;
- if ($return->info == "") $return->info = "No Tardies or Absences";
+ if ($absences > 0) {
+ $absrecs=attendance_get_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 2, "hour ASC");
+ if ($absences == 1) {
+ $absstring = "Absent in hour " . $absrecs[0]->hour . ".";
+ } elseif ($absences == $attendance->hours) {
+ $absstring = "Absent in all hours. (" . $attendance->hours . ")";
+ } else {
+ // build array of all absences
+ $aarr = array();
+ if ($absrecs) foreach ($absrecs as $absrec) {
+ array_push($aarr, $absrec->hour);
+ }
+ $end=array_pop($aarr);
+ $absstring = "Absent in hours " . implode(", ", $aarr) . " and ". $end . ".";
+ }
+ } else { $absstring = "";}
+ $return->info=$tardystring . $absstring;
+ if ($return->info == "") $return->info = "No Tardies or Absences";
return $return;
}
@@ -232,17 +232,17 @@ function attendance_user_complete($course, $user, $mod, $attendance) {
if ($attrecs) { foreach ($attrecs as $attrec) { $grid[$attrec->hour]=$attrec->status; } }
echo "
\n";
@@ -266,42 +266,42 @@ function attendance_cron () {
global $CFG;
echo "Attendance: Performing automatic attendance logging\n";
// look for all attendance instances set to autoattend
- if (!$attendances = get_records("attendance", "autoattend", 1, "course ASC")) {
+ if (!$attendances = get_records("attendance", "autoattend", 1, "course ASC")) {
return true;
}
- $td = attendance_find_today(time());
- $tm = attendance_find_tomorrow(time());
- if ($attendances) foreach($attendances as $attendance) {
+ $td = attendance_find_today(time());
+ $tm = attendance_find_tomorrow(time());
+ if ($attendances) foreach($attendances as $attendance) {
if (($attendance->day >=$td ) && ($attendance->day < $tm)) {
echo "Attendance: Taking attendance for $attendance->name\n";
- if(!isset($courses[$attendance->course]->students)) {
- $courses[$attendance->course]->students =
- attendance_get_course_students($attendance->course, "u.lastname ASC");
- }
+ if(!isset($courses[$attendance->course]->students)) {
+ $courses[$attendance->course]->students =
+ attendance_get_course_students($attendance->course, "u.lastname ASC");
+ }
if ($courses[$attendance->course]->students) {
- foreach ($courses[$attendance->course]->students as $student) {
- // first, clear out the records that may be there already
- delete_records("attendance_roll",
- "dayid",$attendance->id,
- "userid",$student->id);
- $wc = "userid = " . $student->id . " AND course = " . $attendance->course .
- " AND time >= " . $td . " AND time < " . $tm;
- $count = get_record_select("log",$wc,"COUNT(*) as c");
- if ($count->c == "0") { // then the student hasn't done anything today, so mark him absent
- $attrec->dayid = $attendance->id;
- $attrec->userid = $student->id;
- $attrec->status = 2; // status 2 is absent
- // mark ALL hours as absent for first version
- for ($i=1;$i<=$attendance->hours;$i++) {
- $attrec->hour = $i;
- insert_record("attendance_roll",$attrec, false);
- } // for loop to mark all hours absent
- } // if student has no activity
- } // foreach student in the list
- } // if students exist
+ foreach ($courses[$attendance->course]->students as $student) {
+ // first, clear out the records that may be there already
+ delete_records("attendance_roll",
+ "dayid",$attendance->id,
+ "userid",$student->id);
+ $wc = "userid = " . $student->id . " AND course = " . $attendance->course .
+ " AND time >= " . $td . " AND time < " . $tm;
+ $count = get_record_select("log",$wc,"COUNT(*) as c");
+ if ($count->c == "0") { // then the student hasn't done anything today, so mark him absent
+ $attrec->dayid = $attendance->id;
+ $attrec->userid = $student->id;
+ $attrec->status = 2; // status 2 is absent
+ // mark ALL hours as absent for first version
+ for ($i=1;$i<=$attendance->hours;$i++) {
+ $attrec->hour = $i;
+ insert_record("attendance_roll",$attrec, false);
+ } // for loop to mark all hours absent
+ } // if student has no activity
+ } // foreach student in the list
+ } // if students exist
} // if the attendance roll is for today
- } // for each attendance in the system
+ } // for each attendance in the system
return true;
} // function cron
@@ -313,21 +313,21 @@ function attendance_grades($attendanceid) {
if ($attendance->grade == "1") {
$students = get_course_students($attendance->course);
if ($students) {
- foreach ($students as $student) {
- $rolls = attendance_get_records("attendance_roll",
- "dayid",$attendance->id,
- "userid",$student->id);
- $abs=$tar=0;
- if ($rolls) {
- foreach ($rolls as $roll) {
- if ($roll->status == 1) {$tar++;}
- elseif ($roll->status == 2) {$abs++;}
- } // if rolls
- $total = $attendance->hours - attendance_tally_overall_absences_decimal($abs, $tar);
- $percent = ($total != 0)?$total/$attendance->hours:0;
- $return->grades[$student->id] = ($percent == 0)?0.0:$attendance->maxgrade * $percent;
- } else { $return->grades[$student->id] = $attendance->maxgrade; }
- } // foreach student
+ foreach ($students as $student) {
+ $rolls = attendance_get_records("attendance_roll",
+ "dayid",$attendance->id,
+ "userid",$student->id);
+ $abs=$tar=0;
+ if ($rolls) {
+ foreach ($rolls as $roll) {
+ if ($roll->status == 1) {$tar++;}
+ elseif ($roll->status == 2) {$abs++;}
+ } // if rolls
+ $total = $attendance->hours - attendance_tally_overall_absences_decimal($abs, $tar);
+ $percent = ($total != 0)?$total/$attendance->hours:0;
+ $return->grades[$student->id] = ($percent == 0)?0.0:$attendance->maxgrade * $percent;
+ } else { $return->grades[$student->id] = $attendance->maxgrade; }
+ } // foreach student
} // if students
$return->maxgrade = $attendance->maxgrade;
} else { // if attendance->grade == "1"
@@ -376,20 +376,26 @@ function attendance_get_participants($attendanceid) {
* STUDENT ID INTO THE RECORDSET
* if courseid = 0 then return ALL students in all courses
*
-* @param int $courseid the id of the course
-* @param string $sort a field name and ASC or DESC for a SQL 'ORDER BY' clause (optional)
-* @return array(recorset) a list of all students in the specified course
+* @param int $courseid the id of the course
+* @param string $sort a field name and ASC or DESC for a SQL 'ORDER BY' clause (optional)
+* @return array(recorset) a list of all students in the specified course
Returns
*/
function attendance_get_course_students($courseid, $sort="u.lastaccess DESC") {
global $CFG;
+ // make sure it works on the site course
+ $select = "s.course = '$courseid' AND";
+ $site = get_site();
+ if ($courseid == $site->id) {
+ $select = '';
+ }
return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat,
u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture, u.idnumber
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_students s
- WHERE s.course = '$courseid' AND s.userid = u.id AND u.deleted = '0'
+ WHERE $select s.userid = u.id AND u.deleted = '0'
ORDER BY $sort");
}
@@ -400,15 +406,15 @@ function attendance_get_course_students($courseid, $sort="u.lastaccess DESC") {
* Given a number of tardies and absences, determine the total
* number of equivalent absences it adds up to.
*
-* @param int $absences the total number of absences for a span of time
-* @param int $tardies the total number of tardies for a span of time
-* @return float the number of absences it adds up to - may be a decimal!
+* @param int $absences the total number of absences for a span of time
+* @param int $tardies the total number of tardies for a span of time
+* @return float the number of absences it adds up to - may be a decimal!
*/
function attendance_tally_overall_absences_decimal($absences, $tardies) {
global $CFG;
- if (isset($CFG->attendance_tardies_per_absence) && ($CFG->attendance_tardies_per_absence>0)) {
- return $absences + ($tardies/$CFG->attendance_tardies_per_absence);
- } else { return $absences; }
+ if (isset($CFG->attendance_tardies_per_absence) && ($CFG->attendance_tardies_per_absence>0)) {
+ return $absences + ($tardies/$CFG->attendance_tardies_per_absence);
+ } else { return $absences; }
}
/**
@@ -418,23 +424,23 @@ function attendance_tally_overall_absences_decimal($absences, $tardies) {
* number of equivalent absences it adds up to and express it as a string with
* a possible fractional remainder
*
-* @param int $absences the total number of absences for a span of time
-* @param int $tardies the total number of tardies for a span of time
-* @return string the number of absences it adds up to - may have a fractional component!
+* @param int $absences the total number of absences for a span of time
+* @param int $tardies the total number of tardies for a span of time
+* @return string the number of absences it adds up to - may have a fractional component!
*/
function attendance_tally_overall_absences_fraction($absences, $tardies) {
global $CFG;
- if (isset($CFG->attendance_tardies_per_absence) && ($CFG->attendance_tardies_per_absence>0)) {
- $whole = floor($tardies/$CFG->attendance_tardies_per_absence);
- $fractional=$tardies-($whole * $CFG->attendance_tardies_per_absence);
- if ($absences + $whole > 0) {
- return ($absences + $whole) . (($fractional > 0) ? " ". $fractional. "/". $CFG->attendance_tardies_per_absence : "");
- } else {
- return (($fractional > 0) ? $fractional. "/". $CFG->attendance_tardies_per_absence : "0");
- }
- } else {
- return $absences."";
- }
+ if (isset($CFG->attendance_tardies_per_absence) && ($CFG->attendance_tardies_per_absence>0)) {
+ $whole = floor($tardies/$CFG->attendance_tardies_per_absence);
+ $fractional=$tardies-($whole * $CFG->attendance_tardies_per_absence);
+ if ($absences + $whole > 0) {
+ return ($absences + $whole) . (($fractional > 0) ? " ". $fractional. "/". $CFG->attendance_tardies_per_absence : "");
+ } else {
+ return (($fractional > 0) ? $fractional. "/". $CFG->attendance_tardies_per_absence : "0");
+ }
+ } else {
+ return $absences."";
+ }
}
/**
@@ -490,9 +496,9 @@ function attendance_get_records($table, $field1="", $value1="", $field2="", $val
* first what section the specified attendance instance in the course is in, then all the
* attendance records that are in the same section, regardless of the format of the course
*
-* @param int $instance id of the attendance instance in course_modules
-* @param int $courseid the id of the course for which we're getting records
-* @return (object)recordset associative array of records containing the attendance records we wanted
+* @param int $instance id of the attendance instance in course_modules
+* @param int $courseid the id of the course for which we're getting records
+* @return (object)recordset associative array of records containing the attendance records we wanted
*/
function get_attendance_for_section($instance, $courseid) {
global $CFG;
@@ -548,9 +554,9 @@ AND md.name = 'attendance' AND md.id = cm.module AND m.id = cm.instance;
* function will work with non-weekly formatted courses, though the results won't easily
* correlate with the course view. But it will work regardless.
*
-* @param int $id the id of the attendance record we're using as a basis for the query
-* @param int $courseid the id of the course for which we're getting records
-* @return (object)recordset associative array of records containing the attendance records we wanted
+* @param int $id the id of the attendance record we're using as a basis for the query
+* @param int $courseid the id of the course for which we're getting records
+* @return (object)recordset associative array of records containing the attendance records we wanted
*/
function get_attendance_for_week($id, $courseid) {
global $CFG;
@@ -576,8 +582,8 @@ function get_attendance_for_week($id, $courseid) {
*
* This function returns the timestamp for midnight of the day specified in the timestamp
*
-* @param timestamp $d The time to find the beginning of the day for
-* @return timestamp midnight for that day
+* @param timestamp $d The time to find the beginning of the day for
+* @return timestamp midnight for that day
*/
function attendance_find_today($d) {
// $da = getdate($d);
@@ -594,8 +600,8 @@ function attendance_find_today($d) {
*
* This function returns the timestamp for midnight of the day after the timestamp specified
*
-* @param timestamp $d The time to find the next day of
-* @return timestamp midnight of the next day
+* @param timestamp $d The time to find the next day of
+* @return timestamp midnight of the next day
*/
function attendance_find_tomorrow($d) {
// add 24 hours to the current time - to solve end of month date issues
diff --git a/mod/chat/index.php b/mod/chat/index.php
index d5490644af..f2df2e3bd9 100644
--- a/mod/chat/index.php
+++ b/mod/chat/index.php
@@ -9,7 +9,7 @@
error("Course ID is incorrect");
}
- require_login($course->id);
+ require_course_login($course);
add_to_log($course->id, "chat", "view all", "index.php?id=$course->id", "");
diff --git a/mod/chat/view.php b/mod/chat/view.php
index f940210877..e611f64c63 100644
--- a/mod/chat/view.php
+++ b/mod/chat/view.php
@@ -37,7 +37,7 @@
}
}
- require_login($course->id);
+ require_course_login($course);
add_to_log($course->id, "chat", "view", "view.php?id=$cm->id", $chat->id, $cm->id);
diff --git a/mod/choice/index.php b/mod/choice/index.php
index 378ab7c0b4..a90f67f371 100644
--- a/mod/choice/index.php
+++ b/mod/choice/index.php
@@ -9,7 +9,7 @@
error("Course ID is incorrect");
}
- require_login($course->id);
+ require_course_login($course);
add_to_log($course->id, "choice", "view all", "index?id=$course->id", "");
@@ -24,7 +24,7 @@
notice("There are no choices", "../../course/view.php?id=$course->id");
}
- if ( $allanswers = get_records("choice_answers", "userid", $USER->id)) {
+ if ( isset($USER->id) and $allanswers = get_records("choice_answers", "userid", $USER->id)) {
foreach ($allanswers as $aa) {
$answers[$aa->choice] = $aa;
}
diff --git a/mod/choice/view.php b/mod/choice/view.php
index c33c86f92f..3940a60738 100644
--- a/mod/choice/view.php
+++ b/mod/choice/view.php
@@ -13,7 +13,7 @@
error("Course is misconfigured");
}
- require_login($course->id);
+ require_course_login($course);
if (!$choice = choice_get_choice($cm->instance)) {
error("Course module is incorrect");
@@ -22,8 +22,10 @@
for ($i=1; $i <= $CHOICE_MAX_NUMBER; $i++) {
$answerchecked[$i] = '';
}
- if ($current = get_record("choice_answers", "choice", $choice->id, "userid", $USER->id)) {
+ if (isset($USER->id) and $current = get_record("choice_answers", "choice", $choice->id, "userid", $USER->id)) {
$answerchecked[$current->answer] = 'CHECKED';
+ } else {
+ $current = false;
}
if ($form = data_submitted()) {
@@ -113,6 +115,8 @@
echo "id\">";
if (isstudent($course->id) or isteacher($course->id, 0, false)) {
echo "";
+ } else {
+ print_string('havetologin', 'choice');
}
echo "Hour: \n";
// echo out the table header
- for($j=1;$j<=$attendance->hours;$j++) {
- echo "".$j." \n";
- }
- echo "Status: ";
- for($j=1;$j<=$attendance->hours;$j++) {
+ for($j=1;$j<=$attendance->hours;$j++) {
+ echo "".$j." \n";
+ }
+ echo "Status: ";
+ for($j=1;$j<=$attendance->hours;$j++) {
// set the attendance defaults for each student
- if (isset($grid[$j])) {
- $status = (($grid[$j] == 1) ? $T : $A);
- } else {$status=$P;}
+ if (isset($grid[$j])) {
+ $status = (($grid[$j] == 1) ? $T : $A);
+ } else {$status=$P;}
echo "".$status." \n";
- } /// for loop
+ } /// for loop
echo "