Browse Source

Initial database migration to Moodle 2.0

MOODLE_23_STABLE
Luis Ramon Lopez 14 years ago
parent
commit
cde262c260
  1. 28
      attendances.php
  2. 34
      attsettings.php
  3. 29
      backuplib.php
  4. 56
      db/install.xml
  5. 242
      db/upgrade.php
  6. 15
      export.php
  7. 2
      index.php
  8. 2
      lang/en/attforblock.php
  9. 0
      lang/en/help/attforblock/createmultiplesessions.html
  10. 0
      lang/en/help/attforblock/createonesession.html
  11. 0
      lang/en/help/attforblock/defaultstatuses.html
  12. 0
      lang/en/help/attforblock/display.html
  13. 0
      lang/en/help/attforblock/export.html
  14. 0
      lang/en/help/attforblock/hiddensessions.html
  15. 0
      lang/en/help/attforblock/myvariables.html
  16. 0
      lang/en/help/attforblock/report.html
  17. 0
      lang/en/help/attforblock/sessions.html
  18. 0
      lang/en/help/attforblock/sessiontypes.html
  19. 0
      lang/en/help/attforblock/studentview.html
  20. 1
      lang/es/attforblock.php
  21. 0
      lang/es/help/attforblock/changesession.html
  22. 0
      lang/es/help/attforblock/createmultiplesessions.html
  23. 0
      lang/es/help/attforblock/createonesession.html
  24. 0
      lang/es/help/attforblock/defaultstatuses.html
  25. 0
      lang/es/help/attforblock/display.html
  26. 0
      lang/es/help/attforblock/export.html
  27. 0
      lang/es/help/attforblock/hiddensessions.html
  28. 0
      lang/es/help/attforblock/mods.html
  29. 0
      lang/es/help/attforblock/myvariables.html
  30. 0
      lang/es/help/attforblock/report.html
  31. 0
      lang/es/help/attforblock/sessions.html
  32. 0
      lang/es/help/attforblock/sessiontypes.html
  33. 0
      lang/es/help/attforblock/studentview.html
  34. 0
      lang/es/help/attforblock/updateattendance.html
  35. 82
      lib.php
  36. 85
      locallib.php
  37. 34
      manage.php
  38. 24
      report.php
  39. 28
      restorelib.php
  40. 36
      sessions.php
  41. 4
      update_form.php
  42. 14
      view.php

28
attendances.php

@ -6,7 +6,7 @@
require_once($CFG->libdir.'/blocklib.php'); require_once($CFG->libdir.'/blocklib.php');
require_once('locallib.php'); require_once('locallib.php');
require_once('lib.php'); require_once('lib.php');
if (!function_exists('grade_update')) { //workaround for buggy PHP versions if (!function_exists('grade_update')) { //workaround for buggy PHP versions
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
} }
@ -17,20 +17,20 @@
$group = optional_param('group', -1, PARAM_INT); // Group to show $group = optional_param('group', -1, PARAM_INT); // Group to show
$sort = optional_param('sort','lastname', PARAM_ALPHA); $sort = optional_param('sort','lastname', PARAM_ALPHA);
if (! $cm = get_record('course_modules', 'id', $id)) { if (! $cm = $DB->get_record('course_modules', array('id'=>$id))) {
error('Course Module ID was incorrect'); error('Course Module ID was incorrect');
} }
if (! $course = get_record('course', 'id', $cm->course)) { if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
error('Course is misconfigured'); error('Course is misconfigured');
} }
require_login($course->id); require_login($course->id);
if (! $attforblock = get_record('attforblock', 'id', $cm->instance)) { if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect"); error("Course module is incorrect");
} }
if (! $user = get_record('user', 'id', $USER->id) ) { if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course"); error("No such user in this course");
} }
@ -58,18 +58,18 @@
$i++; $i++;
} }
} }
$attforblockrecord = get_record('attforblock', 'course', $course->id); $attforblockrecord = $DB->get_record('attforblock', array('course' => $course->id));
foreach($students as $student) { foreach($students as $student) {
if ($log = get_record('attendance_log', 'sessionid', $sessionid, 'studentid', $student->studentid)) { if ($log = $DB->get_record('attendance_log', array('sessionid' => $sessionid, 'studentid'=> $student->studentid))) {
$student->id = $log->id; // this is id of log $student->id = $log->id; // this is id of log
update_record('attendance_log', $student); $DB->update_record('attendance_log', $student);
} else { } else {
insert_record('attendance_log', $student); $DB->insert_record('attendance_log', $student);
} }
} }
set_field('attendance_sessions', 'lasttaken', $now, 'id', $sessionid); $DB->set_field('attendance_sessions', 'lasttaken', $now, array('id' => $sessionid));
set_field('attendance_sessions', 'lasttakenby', $USER->id, 'id', $sessionid); $DB->set_field('attendance_sessions', 'lasttakenby', $USER->id, array('id' => $sessionid));
attforblock_update_grades($attforblockrecord); attforblock_update_grades($attforblockrecord);
add_to_log($course->id, 'attendance', 'updated', 'mod/attforblock/report.php?id='.$id, $user->lastname.' '.$user->firstname); add_to_log($course->id, 'attendance', 'updated', 'mod/attforblock/report.php?id='.$id, $user->lastname.' '.$user->firstname);
@ -85,11 +85,11 @@
$navigation, "", "", true, " ", navmenu($course)); $navigation, "", "", true, " ", navmenu($course));
//check for hack //check for hack
if (!$sessdata = get_record('attendance_sessions', 'id', $sessionid)) { if (!$sessdata = $DB->get_record('attendance_sessions', array('id'=> $sessionid))) {
error("Required Information is missing", "manage.php?id=".$id); error("Required Information is missing", "manage.php?id=".$id);
} }
$help = helpbutton ('updateattendance', get_string('help'), 'attforblock', true, false, '', true); $help = helpbutton ('updateattendance', get_string('help'), 'attforblock', true, false, '', true);
$update = count_records('attendance_log', 'sessionid', $sessionid); $update = $DB->count_records('attendance_log', array('sessionid'=> $sessionid));
if ($update) { if ($update) {
require_capability('mod/attforblock:changeattendances', $context); require_capability('mod/attforblock:changeattendances', $context);
@ -164,7 +164,7 @@
$i = 0; $i = 0;
foreach($students as $student) { foreach($students as $student) {
$i++; $i++;
$att = get_record('attendance_log', 'sessionid', $sessionid, 'studentid', $student->id); $att = $DB->get_record('attendance_log', array('sessionid'=> $sessionid, 'studentid'=> $student->id));
$table->data[$student->id][] = (!$att && $update) ? "<font color=\"red\"><b>$i</b></font>" : $i; $table->data[$student->id][] = (!$att && $update) ? "<font color=\"red\"><b>$i</b></font>" : $i;
$table->data[$student->id][] = print_user_picture($student->id, $course->id, $student->picture, 20, true, true);//, $returnstring=false, $link=true, $target=''); $table->data[$student->id][] = print_user_picture($student->id, $course->id, $student->picture, 20, true, true);//, $returnstring=false, $link=true, $target='');
$table->data[$student->id][] = "<a href=\"view.php?id=$id&amp;student={$student->id}\">".((!$att && $update) ? '<font color="red"><b>' : '').fullname($student).((!$att && $update) ? '</b></font>' : '').'</a>'; $table->data[$student->id][] = "<a href=\"view.php?id=$id&amp;student={$student->id}\">".((!$att && $update) ? '<font color="red"><b>' : '').fullname($student).((!$att && $update) ? '</b></font>' : '').'</a>';

34
attsettings.php

@ -3,29 +3,29 @@
require_once('../../config.php'); require_once('../../config.php');
require_once('locallib.php'); require_once('locallib.php');
require_once('lib.php'); require_once('lib.php');
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$submitsettings = optional_param('submitsettings'); $submitsettings = optional_param('submitsettings');
$action = optional_param('action', '', PARAM_MULTILANG); $action = optional_param('action', '', PARAM_MULTILANG);
$stid = optional_param('st', 0, PARAM_INT); $stid = optional_param('st', 0, PARAM_INT);
if ($id) { if ($id) {
if (! $cm = get_record('course_modules', 'id', $id)) { if (! $cm = $DB->get_record('course_modules', array('id'=> $id))) {
error('Course Module ID was incorrect'); error('Course Module ID was incorrect');
} }
if (! $course = get_record('course', 'id', $cm->course)) { if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
error('Course is misconfigured'); error('Course is misconfigured');
} }
if (! $attforblock = get_record('attforblock', 'id', $cm->instance)) { if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect"); error("Course module is incorrect");
} }
} }
$attforblockrecord = get_record('attforblock','course',$course->id); $attforblockrecord = $DB->get_record('attforblock',array('course'=>$course->id));
require_login($course->id); require_login($course->id);
if (! $user = get_record('user', 'id', $USER->id) ) { if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course"); error("No such user in this course");
} }
@ -45,16 +45,16 @@
if (!empty($action)) { if (!empty($action)) {
switch ($action) { switch ($action) {
case 'delete': case 'delete':
if (!$rec = get_record('attendance_statuses', 'courseid', $course->id, 'id', $stid)) { if (!$rec = $DB->get_record('attendance_statuses', array('courseid'=> $course->id, 'id'=> $stid))) {
print_error('notfoundstatus', 'attforblock', "attsettings.php?id=$id"); print_error('notfoundstatus', 'attforblock', "attsettings.php?id=$id");
} }
if (count_records('attendance_log', 'statusid', $stid)) { if ($DB->count_records('attendance_log', array('statusid'=> $stid))) {
print_error('cantdeletestatus', 'attforblock', "attsettings.php?id=$id"); print_error('cantdeletestatus', 'attforblock', "attsettings.php?id=$id");
} }
$confirm = optional_param('confirm'); $confirm = optional_param('confirm');
if (isset($confirm)) { if (isset($confirm)) {
set_field('attendance_statuses', 'deleted', 1, 'id', $rec->id); $DB->set_field('attendance_statuses', 'deleted', 1, array('id' => $rec->id));
// delete_records('attendance_statuses', 'id', $rec->id); // delete_records('attendance_statuses', 'id', $rec->id);
redirect('attsettings.php?id='.$id, get_string('statusdeleted','attforblock'), 3); redirect('attsettings.php?id='.$id, get_string('statusdeleted','attforblock'), 3);
} }
@ -66,13 +66,13 @@
"attsettings.php?id=$id&amp;st=$stid&amp;action=delete&amp;confirm=1", $_SERVER['HTTP_REFERER']); "attsettings.php?id=$id&amp;st=$stid&amp;action=delete&amp;confirm=1", $_SERVER['HTTP_REFERER']);
exit; exit;
case 'show': case 'show':
set_field('attendance_statuses', 'visible', 1, 'id', $stid); $DB->set_field('attendance_statuses', 'visible', 1, array('id' => $stid));
break; break;
case 'hide': case 'hide':
$students = get_users_by_capability($context, 'moodle/legacy:student', '', '', '', '', '', '', false); $students = get_users_by_capability($context, 'moodle/legacy:student', '', '', '', '', '', '', false);
$studlist = implode(',', array_keys($students)); $studlist = implode(',', array_keys($students));
if (!count_records_select('attendance_log', "studentid IN ($studlist) AND statusid = $stid")) { if (!$DB->count_records_select('attendance_log', "studentid IN (?) AND statusid = ?", array( $studlist, $stid) )) {
set_field('attendance_statuses', 'visible', 0, 'id', $stid); $DB->set_field('attendance_statuses', 'visible', 0, array('id' => $stid));
} else { } else {
print_error('canthidestatus', 'attforblock', "attsettings.php?id=$id"); print_error('canthidestatus', 'attforblock', "attsettings.php?id=$id");
} }
@ -87,7 +87,7 @@
$rec->acronym = $newacronym; $rec->acronym = $newacronym;
$rec->description = $newdescription; $rec->description = $newdescription;
$rec->grade = $newgrade; $rec->grade = $newgrade;
insert_record('attendance_statuses', $rec); $DB->insert_record('attendance_statuses', $rec);
add_to_log($course->id, 'attendance', 'setting added', 'mod/attforblock/attsettings.php?course='.$course->id, $user->lastname.' '.$user->firstname); add_to_log($course->id, 'attendance', 'setting added', 'mod/attforblock/attsettings.php?course='.$course->id, $user->lastname.' '.$user->firstname);
} else { } else {
print_error('cantaddstatus', 'attforblock', "attsettings.php?id=$id"); print_error('cantaddstatus', 'attforblock', "attsettings.php?id=$id");
@ -126,7 +126,7 @@
$action = $st->visible ? 'hide' : 'show'; $action = $st->visible ? 'hide' : 'show';
$titlevis = get_string($action); $titlevis = get_string($action);
$deleteact = ''; $deleteact = '';
if (!count_records('attendance_log', 'statusid', $st->id)) { if (!$DB->count_records('attendance_log', array('statusid'=> $st->id))) {
$deleteact = "<a title=\"$deltitle\" href=\"attsettings.php?id=$cm->id&amp;st={$st->id}&amp;action=delete\">". $deleteact = "<a title=\"$deltitle\" href=\"attsettings.php?id=$cm->id&amp;st={$st->id}&amp;action=delete\">".
"<img src=\"{$CFG->pixpath}/t/delete.gif\" alt=\"$deltitle\" /></a>&nbsp;"; "<img src=\"{$CFG->pixpath}/t/delete.gif\" alt=\"$deltitle\" /></a>&nbsp;";
} }
@ -156,18 +156,18 @@
function config_save() function config_save()
{ {
global $course, $user, $attforblockrecord; global $course, $user, $attforblockrecord, $DB;
$acronym = required_param('acronym'); $acronym = required_param('acronym');
$description = required_param('description'); $description = required_param('description');
$grade = required_param('grade',PARAM_INT); $grade = required_param('grade',PARAM_INT);
foreach ($acronym as $id => $v) { foreach ($acronym as $id => $v) {
$rec = get_record('attendance_statuses', 'id', $id); $rec = $DB->get_record('attendance_statuses', array('id'=> $id));
$rec->acronym = $acronym[$id]; $rec->acronym = $acronym[$id];
$rec->description = $description[$id]; $rec->description = $description[$id];
$rec->grade = $grade[$id]; $rec->grade = $grade[$id];
update_record('attendance_statuses', $rec); $DB->update_record('attendance_statuses', $rec);
add_to_log($course->id, 'attendance', 'settings updated', 'mod/attforblock/attsettings.php?course='.$course->id, $user->lastname.' '.$user->firstname); add_to_log($course->id, 'attendance', 'settings updated', 'mod/attforblock/attsettings.php?course='.$course->id, $user->lastname.' '.$user->firstname);
} }
attforblock_update_grades($attforblockrecord); attforblock_update_grades($attforblockrecord);

29
backuplib.php

@ -16,11 +16,14 @@
function attforblock_check_backup_mods_instances($course, $instance, $backup_unique_code) { function attforblock_check_backup_mods_instances($course, $instance, $backup_unique_code) {
global $DB;
//First the course data //First the course data
$info[$instance->id.'0'][0] = '<b>'.$instance->name.'</b>'; $info[$instance->id.'0'][0] = '<b>'.$instance->name.'</b>';
$info[$instance->id.'0'][1] = ''; $info[$instance->id.'0'][1] = '';
$sessions = get_records_menu('attendance_sessions', 'courseid', $course); $sessions = $DB->get_records_menu('attendance_sessions', array('courseid'=> $course));
$info[$instance->id.'1'][0] = get_string('sessions', 'attforblock'); $info[$instance->id.'1'][0] = get_string('sessions', 'attforblock');
$info[$instance->id.'1'][1] = count($sessions); $info[$instance->id.'1'][1] = count($sessions);
@ -28,7 +31,7 @@
if (!empty($instance->userdata)) { if (!empty($instance->userdata)) {
$info[$instance->id.'2'][0] = get_string('attrecords', 'attforblock'); $info[$instance->id.'2'][0] = get_string('attrecords', 'attforblock');
$sesslist = implode(',', array_keys($sessions)); $sesslist = implode(',', array_keys($sessions));
if ($datas = get_records_list('attendance_log', 'sessionid', $sesslist)) { if ($datas = $DB->get_records_list('attendance_log', array('sessionid'=> $sesslist))) {
$info[$instance->id.'2'][1] = count($datas); $info[$instance->id.'2'][1] = count($datas);
} else { } else {
$info[$instance->id.'2'][1] = 0; $info[$instance->id.'2'][1] = 0;
@ -40,12 +43,12 @@
function attforblock_backup_mods($bf, $preferences) { function attforblock_backup_mods($bf, $preferences) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
//Iterate over attforblock table //Iterate over attforblock table
$attforblocks = get_records ('attforblock', 'course', $preferences->backup_course, 'id'); $attforblocks = $DB->get_records ('attforblock', 'course', array($preferences->backup_course=> 'id'));
if ($attforblocks) { if ($attforblocks) {
foreach ($attforblocks as $attforblock) { foreach ($attforblocks as $attforblock) {
if (backup_mod_selected($preferences, 'attforblock', $attforblock->id)) { if (backup_mod_selected($preferences, 'attforblock', $attforblock->id)) {
@ -61,10 +64,10 @@
function attforblock_backup_one_mod($bf, $preferences, $attforblock) { function attforblock_backup_one_mod($bf, $preferences, $attforblock) {
global $CFG; global $CFG, $DB;
if (is_numeric($attforblock)) { if (is_numeric($attforblock)) {
$attforblock = get_record('attforblock', 'id', $attforblock); $attforblock = $DB->get_record('attforblock', array('id'=> $attforblock));
} }
$status = true; $status = true;
@ -93,11 +96,11 @@
function attforblock_backup_attendance_sessions ($bf,$preferences,$attforblock) { function attforblock_backup_attendance_sessions ($bf,$preferences,$attforblock) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
$datas = get_records('attendance_sessions', 'courseid', $attforblock->course); $datas = $DB->get_records('attendance_sessions', array('courseid'=> $attforblock->course));
if ($datas) { if ($datas) {
//Write start tag //Write start tag
$status =fwrite ($bf,start_tag('SESSIONS',4,true)); $status =fwrite ($bf,start_tag('SESSIONS',4,true));
@ -132,11 +135,11 @@
function attforblock_backup_attendance_statuses ($bf,$preferences,$attforblock) { function attforblock_backup_attendance_statuses ($bf,$preferences,$attforblock) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
$datas = get_records('attendance_statuses', 'courseid', $attforblock->course); $datas = $DB->get_records('attendance_statuses', array('courseid'=> $attforblock->course));
//If there is levels //If there is levels
if ($datas) { if ($datas) {
//Write start tag //Write start tag
@ -166,13 +169,13 @@
function attforblock_backup_attendance_log ($bf,$preferences,$attforblock) { function attforblock_backup_attendance_log ($bf,$preferences,$attforblock) {
global $CFG; global $CFG, $DB;
$status = true; $status = true;
$sessions = get_records_menu('attendance_sessions', 'courseid', $attforblock->course); $sessions = $DB->get_records_menu('attendance_sessions', array('courseid'=> $attforblock->course));
$sesslist = implode(',', array_keys($sessions)); $sesslist = implode(',', array_keys($sessions));
$datas = get_records_list('attendance_log', 'sessionid', $sesslist); $datas = $DB->get_records_list('attendance_log', array('sessionid'=> $sesslist));
//If there is levels //If there is levels
if ($datas) { if ($datas) {
//Write start tag //Write start tag

56
db/install.xml

@ -6,10 +6,10 @@
<TABLES> <TABLES>
<TABLE NAME="attforblock" COMMENT="Module for support Attendances" NEXT="attendance_sessions"> <TABLE NAME="attforblock" COMMENT="Module for support Attendances" NEXT="attendance_sessions">
<FIELDS> <FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="course"/> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" COMMENT="id of the table, please edit me" NEXT="course"/>
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="name"/> <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="name"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="course" NEXT="grade"/> <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="course" NEXT="grade"/>
<FIELD NAME="grade" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="100" SEQUENCE="false" ENUM="false" COMMENT="This is maximum grade for instance" PREVIOUS="name"/> <FIELD NAME="grade" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="100" SEQUENCE="false" COMMENT="This is maximum grade for instance" PREVIOUS="name"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attforblock"/> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attforblock"/>
@ -20,15 +20,15 @@
</TABLE> </TABLE>
<TABLE NAME="attendance_sessions" COMMENT="attendance_sessions table retrofitted from MySQL" PREVIOUS="attforblock" NEXT="attendance_log"> <TABLE NAME="attendance_sessions" COMMENT="attendance_sessions table retrofitted from MySQL" PREVIOUS="attforblock" NEXT="attendance_log">
<FIELDS> <FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="courseid"/> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="groupid"/> <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="groupid"/>
<FIELD NAME="groupid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="courseid" NEXT="sessdate"/> <FIELD NAME="groupid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="courseid" NEXT="sessdate"/>
<FIELD NAME="sessdate" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="groupid" NEXT="duration"/> <FIELD NAME="sessdate" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="groupid" NEXT="duration"/>
<FIELD NAME="duration" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="sessdate" NEXT="lasttaken"/> <FIELD NAME="duration" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="sessdate" NEXT="lasttaken"/>
<FIELD NAME="lasttaken" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="duration" NEXT="lasttakenby"/> <FIELD NAME="lasttaken" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="duration" NEXT="lasttakenby"/>
<FIELD NAME="lasttakenby" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="lasttaken" NEXT="timemodified"/> <FIELD NAME="lasttakenby" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="lasttaken" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="lasttakenby" NEXT="description"/> <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="lasttakenby" NEXT="description"/>
<FIELD NAME="description" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="timemodified"/> <FIELD NAME="description" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="timemodified"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance_sessions"/> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance_sessions"/>
@ -41,14 +41,14 @@
</TABLE> </TABLE>
<TABLE NAME="attendance_log" COMMENT="attendance_log table retrofitted from MySQL" PREVIOUS="attendance_sessions" NEXT="attendance_statuses"> <TABLE NAME="attendance_log" COMMENT="attendance_log table retrofitted from MySQL" PREVIOUS="attendance_sessions" NEXT="attendance_statuses">
<FIELDS> <FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="sessionid"/> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="sessionid"/>
<FIELD NAME="sessionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="studentid"/> <FIELD NAME="sessionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="studentid"/>
<FIELD NAME="studentid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="sessionid" NEXT="statusid"/> <FIELD NAME="studentid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="sessionid" NEXT="statusid"/>
<FIELD NAME="statusid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="link with attendance_status table" PREVIOUS="studentid" NEXT="statusset"/> <FIELD NAME="statusid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="link with attendance_status table" PREVIOUS="studentid" NEXT="statusset"/>
<FIELD NAME="statusset" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="statusid" NEXT="timetaken"/> <FIELD NAME="statusset" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" PREVIOUS="statusid" NEXT="timetaken"/>
<FIELD NAME="timetaken" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="When attendance of this student was taken" PREVIOUS="statusset" NEXT="takenby"/> <FIELD NAME="timetaken" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="When attendance of this student was taken" PREVIOUS="statusset" NEXT="takenby"/>
<FIELD NAME="takenby" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timetaken" NEXT="remarks"/> <FIELD NAME="takenby" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timetaken" NEXT="remarks"/>
<FIELD NAME="remarks" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="takenby"/> <FIELD NAME="remarks" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="takenby"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance_log"/> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance_log"/>
@ -61,13 +61,13 @@
</TABLE> </TABLE>
<TABLE NAME="attendance_statuses" COMMENT="attendance_statuses table retrofitted from MySQL" PREVIOUS="attendance_log"> <TABLE NAME="attendance_statuses" COMMENT="attendance_statuses table retrofitted from MySQL" PREVIOUS="attendance_log">
<FIELDS> <FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="courseid"/> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="acronym"/> <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="acronym"/>
<FIELD NAME="acronym" TYPE="char" LENGTH="2" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="courseid" NEXT="description"/> <FIELD NAME="acronym" TYPE="char" LENGTH="2" NOTNULL="true" SEQUENCE="false" PREVIOUS="courseid" NEXT="description"/>
<FIELD NAME="description" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="acronym" NEXT="grade"/> <FIELD NAME="description" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" PREVIOUS="acronym" NEXT="grade"/>
<FIELD NAME="grade" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="description" NEXT="visible"/> <FIELD NAME="grade" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="visible"/>
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="grade" NEXT="deleted"/> <FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="grade" NEXT="deleted"/>
<FIELD NAME="deleted" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="visible"/> <FIELD NAME="deleted" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="visible"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance_settings"/> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance_settings"/>

242
db/upgrade.php

@ -19,7 +19,9 @@
function xmldb_attforblock_upgrade($oldversion=0) { function xmldb_attforblock_upgrade($oldversion=0) {
global $CFG, $THEME, $db; global $CFG, $THEME, $DB;
$dbman = $DB->get_manager(); /// loads ddl manager and xmldb classes
$result = true; $result = true;
@ -28,157 +30,160 @@ function xmldb_attforblock_upgrade($oldversion=0) {
/// this comment lines once this file start handling proper /// this comment lines once this file start handling proper
/// upgrade code. /// upgrade code.
if ($result && $oldversion < 2008021904) { //New version in version.php if ($oldversion < 2008021904) { //New version in version.php
global $USER; global $USER;
if ($sessions = get_records('attendance_sessions', 'takenby', 0)) { if ($sessions = $DB->get_records('attendance_sessions', array('takenby'=> 0))) {
foreach ($sessions as $sess) { foreach ($sessions as $sess) {
if (count_records('attendance_log', 'attsid', $sess->id) > 0) { if ($DB->count_records('attendance_log', array('attsid'=> $sess->id)) > 0) {
$sess->takenby = $USER->id; $sess->takenby = $USER->id;
$sess->timetaken = $sess->timemodified ? $sess->timemodified : time(); $sess->timetaken = $sess->timemodified ? $sess->timemodified : time();
$sess->description = addslashes($sess->description); $sess->description = addslashes($sess->description);
$result = update_record('attendance_sessions', $sess) and $result; $result = $DB->update_record('attendance_sessions', $sess) and $result;
} }
} }
} }
upgrade_mod_savepoint(true, 2008021904, 'attforblock');
} }
if ($oldversion < 2008102401 and $result) { if ($oldversion < 2008102401) {
$table = new XMLDBTable('attforblock'); $table = new xmldb_table('attforblock');
$field = new XMLDBField('grade'); $field = new xmldb_field('grade');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '100', 'name'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '100', 'name');
$result = $result && add_field($table, $field); $dbman->add_field($table, $field);
$table = new XMLDBTable('attendance_sessions'); $table = new xmldb_table('attendance_sessions');
$field = new XMLDBField('courseid'); $field = new xmldb_field('courseid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$result = $result && change_field_unsigned($table, $field); $dbman->change_field_unsigned($table, $field);
// $field = new XMLDBField('creator'); // $field = new xmldb_field('creator');
// $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid'); // $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid');
// $result = $result && change_field_unsigned($table, $field); // change_field_unsigned($table, $field);
$field = new XMLDBField('sessdate'); $field = new xmldb_field('sessdate');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'creator'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'creator');
$result = $result && change_field_unsigned($table, $field); $dbman->change_field_unsigned($table, $field);
$field = new XMLDBField('duration'); $field = new xmldb_field('duration');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'sessdate'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'sessdate');
$result = $result && add_field($table, $field); $dbman->add_field($table, $field);
$field = new XMLDBField('timetaken'); $field = new xmldb_field('timetaken');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'takenby'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'takenby');
$result = $result && change_field_unsigned($table, $field); $dbman->change_field_unsigned($table, $field);
$result = $result && rename_field($table, $field, 'lasttaken'); $dbman->rename_field($table, $field, 'lasttaken');
$field = new XMLDBField('takenby'); $field = new xmldb_field('takenby');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'lasttaken'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'lasttaken');
$result = $result && change_field_unsigned($table, $field); $dbman->change_field_unsigned($table, $field);
$result = $result && rename_field($table, $field, 'lasttakenby'); $dbman->rename_field($table, $field, 'lasttakenby');
$field = new XMLDBField('timemodified'); $field = new xmldb_field('timemodified');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'lasttaken'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'lasttaken');
$result = $result && change_field_unsigned($table, $field); $dbman->change_field_unsigned($table, $field);
$table = new XMLDBTable('attendance_log'); $table = new xmldb_table('attendance_log');
$field = new XMLDBField('attsid'); $field = new xmldb_field('attsid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$result = $result && change_field_unsigned($table, $field); $dbman->change_field_unsigned($table, $field);
$field = new XMLDBField('studentid'); $field = new xmldb_field('studentid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'attsid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'attsid');
$result = $result && change_field_unsigned($table, $field); $dbman->change_field_unsigned($table, $field);
$field = new XMLDBField('statusid'); $field = new xmldb_field('statusid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'status'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'status');
$result = $result && add_field($table, $field); $dbman->add_field($table, $field);
$field = new XMLDBField('statusset'); $field = new xmldb_field('statusset');
$field->setAttributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null, 'statusid'); $field->set_attributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, 'statusid');
$result = $result && add_field($table, $field); $dbman->add_field($table, $field);
$field = new XMLDBField('timetaken'); $field = new xmldb_field('timetaken');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'statusid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'statusid');
$result = $result && add_field($table, $field); $dbman->add_field($table, $field);
$field = new XMLDBField('takenby'); $field = new xmldb_field('takenby');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timetaken'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timetaken');
$result = $result && add_field($table, $field); $dbman->add_field($table, $field);
//Indexes //Indexes
$index = new XMLDBIndex('statusid'); $index = new xmldb_index('statusid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('statusid')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('statusid'));
$result = $result && add_index($table, $index); $dbman->add_index($table, $index);
$index = new XMLDBIndex('attsid'); $index = new xmldb_index('attsid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('attsid')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('attsid'));
$result = $result && drop_index($table, $index); $dbman->drop_index($table, $index);
$field = new XMLDBField('attsid'); //Rename field $field = new xmldb_field('attsid'); //Rename field
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$result = $result && rename_field($table, $field, 'sessionid'); $dbman->rename_field($table, $field, 'sessionid');
$index = new XMLDBIndex('sessionid'); $index = new xmldb_index('sessionid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid'));
$result = $result && add_index($table, $index); $dbman->add_index($table, $index);
$table = new XMLDBTable('attendance_settings'); $table = new xmldb_table('attendance_settings');
$field = new XMLDBField('courseid'); $field = new xmldb_field('courseid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$result = $result && change_field_unsigned($table, $field); $dbman->change_field_unsigned($table, $field);
$field = new XMLDBField('visible'); $field = new xmldb_field('visible');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'grade'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'grade');
$result = $result && add_field($table, $field); $dbman->add_field($table, $field);
$field = new XMLDBField('deleted'); $field = new xmldb_field('deleted');
$field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'visible'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'visible');
$result = $result && add_field($table, $field); $dbman->add_field($table, $field);
//Indexes //Indexes
$index = new XMLDBIndex('visible'); $index = new xmldb_index('visible');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('visible')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('visible'));
$result = $result && add_index($table, $index); $dbman->add_index($table, $index);
$index = new XMLDBIndex('deleted'); $index = new xmldb_index('deleted');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('deleted')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('deleted'));
$result = $result && add_index($table, $index); $dbman->add_index($table, $index);
$result = $result && rename_table($table, 'attendance_statuses'); $dbman->rename_table($table, 'attendance_statuses');
upgrade_mod_savepoint(true, 2008102401, 'attforblock');
} }
if ($oldversion < 2008102406 and $result) { if ($oldversion < 2008102406) {
if ($courses = get_records_sql("SELECT courseid FROM {$CFG->prefix}attendance_sessions GROUP BY courseid")) { if ($courses = $DB->get_records_sql("SELECT courseid FROM {attendance_sessions} GROUP BY courseid")) {
foreach ($courses as $c) { foreach ($courses as $c) {
//Adding own status for course (now it must have own) //Adding own status for course (now it must have own)
if (!count_records('attendance_statuses', 'courseid', $c->courseid)) { if (!$DB->count_records('attendance_statuses', array( 'courseid'=> $c->courseid))) {
$statuses = get_records('attendance_statuses', 'courseid', 0); $statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0));
foreach($statuses as $stat) { foreach($statuses as $stat) {
$rec = $stat; $rec = $stat;
$rec->courseid = $c->courseid; $rec->courseid = $c->courseid;
insert_record('attendance_statuses', $rec); $DB->insert_record('attendance_statuses', $rec);
} }
} }
$statuses = get_records('attendance_statuses', 'courseid', $c->courseid); $statuses = $DB->get_records('attendance_statuses', array('courseid'=> $c->courseid));
$statlist = implode(',', array_keys($statuses)); $statlist = implode(',', array_keys($statuses));
$sess = get_records_select_menu('attendance_sessions', "courseid = $c->courseid AND lasttakenby > 0"); $sess = $DB->get_records_select_menu('attendance_sessions', "courseid = ? AND lasttakenby > 0", array($c->courseid));
$sesslist = implode(',', array_keys($sess)); $sesslist = implode(',', array_keys($sess));
foreach($statuses as $stat) { foreach($statuses as $stat) {
execute_sql("UPDATE {$CFG->prefix}attendance_log execute("UPDATE {attendance_log}
SET statusid = {$stat->id}, statusset = '$statlist' SET statusid = {$stat->id}, statusset = '$statlist'
WHERE sessionid IN ($sesslist) AND status = '$stat->status'"); WHERE sessionid IN ($sesslist) AND status = '$stat->status'");
} }
$sessions = get_records_list('attendance_sessions', 'id', $sesslist); $sessions = $DB->get_records_list('attendance_sessions', array('id'=> $sesslist));
foreach($sessions as $sess) { foreach($sessions as $sess) {
execute_sql("UPDATE {$CFG->prefix}attendance_log execute("UPDATE {attendance_log}
SET timetaken = {$sess->lasttaken}, SET timetaken = {$sess->lasttaken},
takenby = {$sess->lasttakenby} takenby = {$sess->lasttakenby}
WHERE sessionid = {$sess->id}"); WHERE sessionid = {$sess->id}");
@ -186,49 +191,52 @@ function xmldb_attforblock_upgrade($oldversion=0) {
} }
} }
upgrade_mod_savepoint(true, 2008102406, 'attforblock');
} }
if ($oldversion < 2008102409 and $result) { if ($oldversion < 2008102409) {
$table = new XMLDBTable('attendance_statuses'); $table = new xmldb_table('attendance_statuses');
$field = new XMLDBField('status'); $field = new xmldb_field('status');
$result = $result && drop_field($table, $field); $dbman->drop_field($table, $field);
$index = new XMLDBIndex('status'); $index = new xmldb_index('status');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('status')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('status'));
$result = $result && drop_index($table, $index); $dbman->drop_index($table, $index);
$table = new XMLDBTable('attendance_log'); $table = new xmldb_table('attendance_log');
$field = new XMLDBField('status'); $field = new xmldb_field('status');
$result = $result && drop_field($table, $field); $dbman->drop_field($table, $field);
$index = new XMLDBIndex('status'); $index = new xmldb_index('status');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('status')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('status'));
$result = $result && drop_index($table, $index); $dbman->drop_index($table, $index);
$table = new XMLDBTable('attendance_sessions'); $table = new xmldb_table('attendance_sessions');
$field = new XMLDBField('creator'); $field = new xmldb_field('creator');
$result = $result && drop_field($table, $field); $dbman->drop_field($table, $field);
upgrade_mod_savepoint(true, 2008102409, 'attforblock');
} }
if ($oldversion < 2010070900 and $result) { if ($oldversion < 2010070900) {
$table = new XMLDBTable('attendance_sessions'); $table = new xmldb_table('attendance_sessions');
$field = new XMLDBField('groupid'); $field = new xmldb_field('groupid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'courseid');
$result = $result && add_field($table, $field); $dbman->add_field($table, $field);
$index = new XMLDBIndex('groupid'); $index = new xmldb_index('groupid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('groupid')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('groupid'));
$result = $result && add_index($table, $index); $dbman->add_index($table, $index);
upgrade_mod_savepoint(true, 2010070900, 'attforblock');
} }
return $result; return true;
} }
?> ?>

15
export.php

@ -11,15 +11,15 @@
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
// $format = optional_param('format', '', PARAM_ACTION); // $format = optional_param('format', '', PARAM_ACTION);
if (! $cm = get_record("course_modules", "id", $id)) { if (! $cm = $DB->get_record("course_modules", array("id"=> $id))) {
error("Course Module ID was incorrect"); error("Course Module ID was incorrect");
} }
if (! $course = get_record("course", "id", $cm->course)) { if (! $course = $DB->get_record("course", array("id"=> $cm->course))) {
error("Course is misconfigured"); error("Course is misconfigured");
} }
if (! $attforblock = get_record('attforblock', 'id', $cm->instance)) { if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect"); error("Course module is incorrect");
} }
@ -56,14 +56,15 @@
$data->tabhead[] = get_string('lastname'); $data->tabhead[] = get_string('lastname');
$data->tabhead[] = get_string('firstname'); $data->tabhead[] = get_string('firstname');
$select = "courseid = {$course->id} AND sessdate >= {$course->startdate}"; $select = "courseid = :cid AND sessdate >= :cstartdate";
if (isset($fromform->includenottaken)) { if (isset($fromform->includenottaken)) {
$select .= " AND sessdate <= {$fromform->sessionenddate}"; $select .= " AND sessdate <= :cenddate";
} else { } else {
$select .= " AND lasttaken != 0"; $select .= " AND lasttaken != 0";
} }
if ($sessions = get_records_select('attendance_sessions', $select, 'sessdate ASC')) { if ($sessions = $DB->get_records_select('attendance_sessions', $select,
array('cid' => $course->id, 'cstartdate' => $course->startdate, 'cenddate' => $fromform->sessionenddate ), 'sessdate ASC')) {
foreach($sessions as $sess) { foreach($sessions as $sess) {
$data->tabhead[] = userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock')); $data->tabhead[] = userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock'));
} }
@ -85,7 +86,7 @@
$data->table[$i][] = $student->lastname; $data->table[$i][] = $student->lastname;
$data->table[$i][] = $student->firstname; $data->table[$i][] = $student->firstname;
foreach ($sessions as $sess) { foreach ($sessions as $sess) {
if ($rec = get_record('attendance_log', 'sessionid', $sess->id, 'studentid', $student->id)) { if ($rec = $DB->get_record('attendance_log', array('sessionid'=> $sess->id, 'studentid'=> $student->id))) {
$data->table[$i][] = $statuses[$rec->statusid]->acronym; $data->table[$i][] = $statuses[$rec->statusid]->acronym;
} else { } else {
$data->table[$i][] = '-'; $data->table[$i][] = '-';

2
index.php

@ -7,7 +7,7 @@
$id = required_param('id', PARAM_INT); // Course id $id = required_param('id', PARAM_INT); // Course id
if (! $course = get_record('course', 'id', $id)) { if (! $course = $DB->get_record('course', array('id'=> $id))) {
error('Course ID is incorrect'); error('Course ID is incorrect');
} }

2
lang/en_utf8/attforblock.php → lang/en/attforblock.php

@ -89,7 +89,7 @@ $string['nosessionexists'] = 'No Session exists for this course';
$string['notfound'] = 'Attendance activity not found in this course!'; $string['notfound'] = 'Attendance activity not found in this course!';
$string['olddate'] = 'Old date'; $string['olddate'] = 'Old date';
$string['period'] = 'Frequency'; $string['period'] = 'Frequency';
$string['remarks'] = 'Remarks'; $string['pluginname'] = 'Attendance';
$string['report'] = 'Report'; $string['report'] = 'Report';
$string['resetdescription'] = 'Remember that deleting attendance data will erase information from database. You can just hide older sessions having changed start date of course!'; $string['resetdescription'] = 'Remember that deleting attendance data will erase information from database. You can just hide older sessions having changed start date of course!';
$string['resetstatuses'] = 'Reset statuses to default'; $string['resetstatuses'] = 'Reset statuses to default';

0
lang/en_utf8/help/attforblock/createmultiplesessions.html → lang/en/help/attforblock/createmultiplesessions.html

0
lang/en_utf8/help/attforblock/createonesession.html → lang/en/help/attforblock/createonesession.html

0
lang/en_utf8/help/attforblock/defaultstatuses.html → lang/en/help/attforblock/defaultstatuses.html

0
lang/en_utf8/help/attforblock/display.html → lang/en/help/attforblock/display.html

0
lang/en_utf8/help/attforblock/export.html → lang/en/help/attforblock/export.html

0
lang/en_utf8/help/attforblock/hiddensessions.html → lang/en/help/attforblock/hiddensessions.html

0
lang/en_utf8/help/attforblock/myvariables.html → lang/en/help/attforblock/myvariables.html

0
lang/en_utf8/help/attforblock/report.html → lang/en/help/attforblock/report.html

0
lang/en_utf8/help/attforblock/sessions.html → lang/en/help/attforblock/sessions.html

0
lang/en_utf8/help/attforblock/sessiontypes.html → lang/en/help/attforblock/sessiontypes.html

0
lang/en_utf8/help/attforblock/studentview.html → lang/en/help/attforblock/studentview.html

1
lang/es_utf8/attforblock.php → lang/es/attforblock.php

@ -89,6 +89,7 @@ $string['nosessionexists'] = 'No existen Sesiones para este curso';
$string['notfound'] = 'No se ha encontrado ninguna actividad Asistencia en este curso'; $string['notfound'] = 'No se ha encontrado ninguna actividad Asistencia en este curso';
$string['olddate'] = 'Fecha Anterior'; $string['olddate'] = 'Fecha Anterior';
$string['period'] = 'Frecuencia'; $string['period'] = 'Frecuencia';
$string['pluginname'] = 'Asistencia';
$string['remarks'] = 'Observaciones'; $string['remarks'] = 'Observaciones';
$string['report'] = 'Informe'; $string['report'] = 'Informe';
$string['resetdescription'] = 'Recuerde que eliminando los datos de la asistencia provocará el borrado de información en la base de datos. Usted puede ocultar sesiones anteriores cambiando la fecha de inicio del curso en la zona de administración.'; $string['resetdescription'] = 'Recuerde que eliminando los datos de la asistencia provocará el borrado de información en la base de datos. Usted puede ocultar sesiones anteriores cambiando la fecha de inicio del curso en la zona de administración.';

0
lang/es_utf8/help/attforblock/changesession.html → lang/es/help/attforblock/changesession.html

0
lang/es_utf8/help/attforblock/createmultiplesessions.html → lang/es/help/attforblock/createmultiplesessions.html

0
lang/es_utf8/help/attforblock/createonesession.html → lang/es/help/attforblock/createonesession.html

0
lang/es_utf8/help/attforblock/defaultstatuses.html → lang/es/help/attforblock/defaultstatuses.html

0
lang/es_utf8/help/attforblock/display.html → lang/es/help/attforblock/display.html

0
lang/es_utf8/help/attforblock/export.html → lang/es/help/attforblock/export.html

0
lang/es_utf8/help/attforblock/hiddensessions.html → lang/es/help/attforblock/hiddensessions.html

0
lang/es_utf8/help/attforblock/mods.html → lang/es/help/attforblock/mods.html

0
lang/es_utf8/help/attforblock/myvariables.html → lang/es/help/attforblock/myvariables.html

0
lang/es_utf8/help/attforblock/report.html → lang/es/help/attforblock/report.html

0
lang/es_utf8/help/attforblock/sessions.html → lang/es/help/attforblock/sessions.html

0
lang/es_utf8/help/attforblock/sessiontypes.html → lang/es/help/attforblock/sessiontypes.html

0
lang/es_utf8/help/attforblock/studentview.html → lang/es/help/attforblock/studentview.html

0
lang/es_utf8/help/attforblock/updateattendance.html → lang/es/help/attforblock/updateattendance.html

82
lib.php

@ -5,7 +5,9 @@
$attforblock_CONSTANT = 7; /// for example $attforblock_CONSTANT = 7; /// for example
function attforblock_install() { function attforblock_install() {
global $DB;
$result = true; $result = true;
$arr = array('P' => 2, 'A' => 0, 'L' => 1, 'E' => 1); $arr = array('P' => 2, 'A' => 0, 'L' => 1, 'E' => 1);
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
@ -16,7 +18,7 @@ function attforblock_install() {
$rec->grade = $v; $rec->grade = $v;
$rec->visible = 1; $rec->visible = 1;
$rec->deleted = 0; $rec->deleted = 0;
$result = $result && insert_record('attendance_statuses', $rec); $result = $result && $DB->insert_record('attendance_statuses', $rec);
} }
return $result; return $result;
} }
@ -27,27 +29,29 @@ function attforblock_add_instance($attforblock) {
/// will create a new instance and return the id number /// will create a new instance and return the id number
/// of the new instance. /// of the new instance.
global $DB;
$attforblock->timemodified = time(); $attforblock->timemodified = time();
if ($att = get_record('attforblock', 'course', $attforblock->course)) { if ($att = $DB->get_record('attforblock', array('course'=> $attforblock->course))) {
$modnum = get_field('modules', 'id', 'name', 'attforblock'); $modnum = $DB->get_field('modules', 'id', array('name'=> 'attforblock'));
if (!get_record('course_modules', 'course', $attforblock->course, 'module', $modnum)) { if (!$DB->get_record('course_modules', array('course'=> $attforblock->course, 'module'=> $modnum))) {
delete_records('attforblock', 'course', $attforblock->course); $DB->delete_records('attforblock', array('course'=> $attforblock->course));
$attforblock->id = insert_record('attforblock', $attforblock); $attforblock->id = $DB->insert_record('attforblock', $attforblock);
} else { } else {
return false; return false;
} }
} else { } else {
$attforblock->id = insert_record('attforblock', $attforblock); $attforblock->id = $DB->insert_record('attforblock', $attforblock);
} }
//Copy statuses for new instance from defaults //Copy statuses for new instance from defaults
if (!get_records('attendance_statuses', 'courseid', $attforblock->course)) { if (!$DB->get_records('attendance_statuses', array('courseid'=> $attforblock->course))) {
$statuses = get_records('attendance_statuses', 'courseid', 0, 'id'); $statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0), 'id');
foreach($statuses as $stat) { foreach($statuses as $stat) {
$rec = $stat; $rec = $stat;
$rec->courseid = $attforblock->course; $rec->courseid = $attforblock->course;
insert_record('attendance_statuses', $rec); $DB->insert_record('attendance_statuses', $rec);
} }
} }
@ -62,10 +66,12 @@ function attforblock_update_instance($attforblock) {
/// (defined by the form in mod.html) this function /// (defined by the form in mod.html) this function
/// will update an existing instance with new data. /// will update an existing instance with new data.
global $DB;
$attforblock->timemodified = time(); $attforblock->timemodified = time();
$attforblock->id = $attforblock->instance; $attforblock->id = $attforblock->instance;
if (! update_record('attforblock', $attforblock)) { if (! $DB->update_record('attforblock', $attforblock)) {
return false; return false;
} }
@ -80,11 +86,13 @@ function attforblock_delete_instance($id) {
/// this function will permanently delete the instance /// this function will permanently delete the instance
/// and any data that depends on it. /// and any data that depends on it.
if (! $attforblock = get_record('attforblock', 'id', $id)) { global $DB;
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $id))) {
return false; return false;
} }
$result = delete_records('attforblock', 'id', $id); $result = $DB->delete_records('attforblock', array('id'=> $id));
attforblock_grade_item_delete($attforblock); attforblock_grade_item_delete($attforblock);
@ -92,13 +100,15 @@ function attforblock_delete_instance($id) {
} }
function attforblock_delete_course($course, $feedback=true){ function attforblock_delete_course($course, $feedback=true){
if ($sess = get_records('attendance_sessions', 'courseid', $course->id, '', 'id')) { global $DB;
if ($sess = $DB->get_records('attendance_sessions', array('courseid'=> $course->id), '', 'id')) {
$slist = implode(',', array_keys($sess)); $slist = implode(',', array_keys($sess));
delete_records_select('attendance_log', "sessionid IN ($slist)"); $DB->delete_records_select('attendance_log', "sessionid IN ($slist)");
delete_records('attendance_sessions', 'courseid', $course->id); $DB->delete_records('attendance_sessions', array('courseid'=> $course->id));
} }
delete_records('attendance_statuses', 'courseid', $course->id); $DB->delete_records('attendance_statuses', array('courseid'=> $course->id));
//Inform about changes performed if feedback is enabled //Inform about changes performed if feedback is enabled
// if ($feedback) { // if ($feedback) {
@ -135,23 +145,25 @@ function attforblock_reset_course_form_defaults($course) {
} }
function attforblock_reset_userdata($data) { function attforblock_reset_userdata($data) {
global $DB;
if (!empty($data->reset_attendance_log)) { if (!empty($data->reset_attendance_log)) {
$sess = get_records('attendance_sessions', 'courseid', $data->courseid, '', 'id'); $sess = $DB->get_records('attendance_sessions', array('courseid'=> $data->courseid), '', 'id');
$slist = implode(',', array_keys($sess)); $slist = implode(',', array_keys($sess));
delete_records_select('attendance_log', "sessionid IN ($slist)"); $DB->delete_records_select('attendance_log', "sessionid IN ($slist)");
set_field('attendance_sessions', 'lasttaken', 0, 'courseid', $data->courseid); $DB->set_field('attendance_sessions', 'lasttaken', 0, array('courseid' => $data->courseid));
} }
if (!empty($data->reset_attendance_statuses)) { if (!empty($data->reset_attendance_statuses)) {
delete_records('attendance_statuses', 'courseid', $data->courseid); $DB->delete_records('attendance_statuses', array('courseid'=> $data->courseid));
$statuses = get_records('attendance_statuses', 'courseid', 0, 'id'); $statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0), 'id');
foreach($statuses as $stat) { foreach($statuses as $stat) {
$rec = $stat; $rec = $stat;
$rec->courseid = $data->courseid; $rec->courseid = $data->courseid;
insert_record('attendance_statuses', $rec); $DB->insert_record('attendance_statuses', $rec);
} }
} }
if (!empty($data->reset_attendance_sessions)) { if (!empty($data->reset_attendance_sessions)) {
delete_records('attendance_sessions', 'courseid', $data->courseid); $DB->delete_records('attendance_sessions', array('courseid'=> $data->courseid));
} }
} }
@ -217,11 +229,11 @@ function attforblock_cron () {
* @return array array of grades, false if none * @return array array of grades, false if none
*/ */
function attforblock_get_user_grades($attforblock, $userid=0) { function attforblock_get_user_grades($attforblock, $userid=0) {
global $CFG; global $CFG, $DB;
require_once('locallib.php'); require_once('locallib.php');
if (! $course = get_record('course', 'id', $attforblock->course)) { if (! $course = $DB->get_record('course', array('id'=> $attforblock->course))) {
error("Course is misconfigured"); error("Course is misconfigured");
} }
@ -250,7 +262,7 @@ function attforblock_get_user_grades($attforblock, $userid=0) {
* @param int $userid specific user only, 0 mean all * @param int $userid specific user only, 0 mean all
*/ */
function attforblock_update_grades($attforblock=null, $userid=0, $nullifnone=true) { function attforblock_update_grades($attforblock=null, $userid=0, $nullifnone=true) {
global $CFG; global $CFG, $DB;
if (!function_exists('grade_update')) { //workaround for buggy PHP versions if (!function_exists('grade_update')) { //workaround for buggy PHP versions
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
} }
@ -269,17 +281,17 @@ function attforblock_update_grades($attforblock=null, $userid=0, $nullifnone=tru
} else { } else {
$sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid $sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid
FROM {$CFG->prefix}attforblock a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m FROM {attforblock} a, {course_modules} cm, {modules} m
WHERE m.name='attforblock' AND m.id=cm.module AND cm.instance=a.id"; WHERE m.name='attforblock' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = get_recordset_sql($sql)) { if ($rs = $DB->get_records_sql($sql)) {
while ($attforblock = rs_fetch_next_record($rs)) { foreach ($rs as $attforblock) {
// if ($attforblock->grade != 0) { // if ($attforblock->grade != 0) {
attforblock_update_grades($attforblock); attforblock_update_grades($attforblock);
// } else { // } else {
// attforblock_grade_item_update($attforblock); // attforblock_grade_item_update($attforblock);
// } // }
} }
rs_close($rs); $rs->close($rs);
} }
} }
} }
@ -292,7 +304,7 @@ function attforblock_update_grades($attforblock=null, $userid=0, $nullifnone=tru
* @return int 0 if ok, error code otherwise * @return int 0 if ok, error code otherwise
*/ */
function attforblock_grade_item_update($attforblock, $grades=NULL) { function attforblock_grade_item_update($attforblock, $grades=NULL) {
global $CFG; global $CFG, $DB;
require_once('locallib.php'); require_once('locallib.php');
@ -303,7 +315,7 @@ function attforblock_grade_item_update($attforblock, $grades=NULL) {
if (!isset($attforblock->courseid)) { if (!isset($attforblock->courseid)) {
$attforblock->courseid = $attforblock->course; $attforblock->courseid = $attforblock->course;
} }
if (! $course = get_record('course', 'id', $attforblock->course)) { if (! $course = $DB->get_record('course', array('id'=> $attforblock->course))) {
error("Course is misconfigured"); error("Course is misconfigured");
} }
//$attforblock->grade = get_maxgrade($course); //$attforblock->grade = get_maxgrade($course);

85
locallib.php

@ -48,10 +48,12 @@ function show_tabs($cm, $context, $currenttab='sessions')
function get_statuses($courseid, $onlyvisible = true) function get_statuses($courseid, $onlyvisible = true)
{ {
if ($onlyvisible) { global $DB;
$result = get_records_select('attendance_statuses', "courseid = $courseid AND visible = 1 AND deleted = 0", 'grade DESC');
if ($onlyvisible) {
$result = $DB->get_records_select('attendance_statuses', "courseid = ? AND visible = 1 AND deleted = 0", array( $courseid ), 'grade DESC');
} else { } else {
$result = get_records_select('attendance_statuses', "courseid = $courseid AND deleted = 0", 'grade DESC'); $result = $DB->get_records_select('attendance_statuses', "courseid = ? AND deleted = 0", array( $courseid ), 'grade DESC');
// $result = get_records('attendance_statuses', 'courseid', $courseid, 'grade DESC'); // $result = get_records('attendance_statuses', 'courseid', $courseid, 'grade DESC');
} }
return $result; return $result;
@ -61,10 +63,10 @@ function get_statuses($courseid, $onlyvisible = true)
function get_attendance($userid, $course, $statusid=0) function get_attendance($userid, $course, $statusid=0)
{ {
global $CFG; global $CFG, $DB;
$qry = "SELECT count(*) as cnt $qry = "SELECT count(*) as cnt
FROM {$CFG->prefix}attendance_log al FROM {attendance_log} al
JOIN {$CFG->prefix}attendance_sessions ats JOIN {attendance_sessions} ats
ON al.sessionid = ats.id ON al.sessionid = ats.id
WHERE ats.courseid = $course->id WHERE ats.courseid = $course->id
AND ats.sessdate >= $course->startdate AND ats.sessdate >= $course->startdate
@ -73,22 +75,22 @@ function get_attendance($userid, $course, $statusid=0)
$qry .= " AND al.statusid = $statusid"; $qry .= " AND al.statusid = $statusid";
} }
return count_records_sql($qry); return $DB->count_records_sql($qry);
} }
function get_grade($userid, $course) function get_grade($userid, $course)
{ {
global $CFG; global $CFG, $DB;
$logs = get_records_sql("SELECT l.id, l.statusid, l.statusset $logs = $DB->get_records_sql("SELECT l.id, l.statusid, l.statusset
FROM {$CFG->prefix}attendance_log l FROM {attendance_log} l
JOIN {$CFG->prefix}attendance_sessions s JOIN {attendance_sessions} s
ON l.sessionid = s.id ON l.sessionid = s.id
WHERE l.studentid = $userid WHERE l.studentid = :usid
AND s.courseid = $course->id AND s.courseid = :cid
AND s.sessdate >= $course->startdate"); AND s.sessdate >= :cstartdate", array('usid' => $userid, 'cid' => $course->id, 'cstartdate' => $course->startdate ));
$result = 0; $result = 0;
if ($logs) { if ($logs) {
$stat_grades = records_to_menu(get_records('attendance_statuses', 'courseid', $course->id), 'id', 'grade'); $stat_grades = $DB->records_to_menu($DB->get_records('attendance_statuses', array('courseid'=> $course->id)), 'id', 'grade');
foreach ($logs as $log) { foreach ($logs as $log) {
$result += $stat_grades[$log->statusid]; $result += $stat_grades[$log->statusid];
} }
@ -110,17 +112,18 @@ function local_array_intersect_key($array1, $array2) {
function get_maxgrade($userid, $course) function get_maxgrade($userid, $course)
{ {
global $CFG; global $CFG, $DB;
$logs = get_records_sql("SELECT l.id, l.statusid, l.statusset $logs = $DB->get_records_sql("SELECT l.id, l.statusid, l.statusset
FROM {$CFG->prefix}attendance_log l FROM {attendance_log} l
JOIN {$CFG->prefix}attendance_sessions s JOIN {attendance_sessions} s
ON l.sessionid = s.id ON l.sessionid = s.id
WHERE l.studentid = $userid WHERE l.studentid = :usid
AND s.courseid = $course->id AND s.courseid = :cid
AND s.sessdate >= $course->startdate"); AND s.sessdate >= :cstartdate", array('usid' => $userid, 'cid' => $course->id, 'cstartdate' => $course->startdate ));
$maxgrade = 0; $maxgrade = 0;
if ($logs) { if ($logs) {
$stat_grades = records_to_menu(get_records('attendance_statuses', 'courseid', $course->id), 'id', 'grade'); $stat_grades = $DB->records_to_menu($DB->get_records('attendance_statuses', array('courseid'=> $course->id)), 'id', 'grade');
foreach ($logs as $log) { foreach ($logs as $log) {
$ids = array_flip(explode(',', $log->statusset)); $ids = array_flip(explode(',', $log->statusset));
// $grades = array_intersect_key($stat_grades, $ids); // require PHP 5.1.0 and higher // $grades = array_intersect_key($stat_grades, $ids); // require PHP 5.1.0 and higher
@ -134,17 +137,17 @@ function get_maxgrade($userid, $course)
function get_percent_adaptive($userid, $course) // NOT USED function get_percent_adaptive($userid, $course) // NOT USED
{ {
global $CFG; global $CFG, $DB;
$logs = get_records_sql("SELECT l.id, l.statusid, l.statusset $logs = $DB->get_records_sql("SELECT l.id, l.statusid, l.statusset
FROM {$CFG->prefix}attendance_log l FROM {attendance_log} l
JOIN {$CFG->prefix}attendance_sessions s JOIN {attendance_sessions} s
ON l.sessionid = s.id ON l.sessionid = s.id
WHERE l.studentid = $userid WHERE l.studentid = :usid
AND s.courseid = $course->id AND s.courseid = :cid
AND s.sessdate >= $course->startdate"); AND s.sessdate >= :cstartdate", array('usid' => $userid, 'cid' => $course->id, 'cstartdate' => $course->startdate ));
$result = 0; $result = 0;
if ($logs) { if ($logs) {
$stat_grades = records_to_menu(get_records('attendance_statuses', 'courseid', $course->id), 'id', 'grade'); $stat_grades = $DB->records_to_menu($DB->get_records('attendance_statuses', array('courseid'=> $course->id)), 'id', 'grade');
$percent = 0; $percent = 0;
foreach ($logs as $log) { foreach ($logs as $log) {
@ -239,7 +242,7 @@ function print_attendance_table($user, $course, $attforblock) {
} }
function print_user_attendaces($user, $cm, $attforblock, $course = 0, $printing = null) { function print_user_attendaces($user, $cm, $attforblock, $course = 0, $printing = null) {
global $CFG, $COURSE, $mode, $current, $view, $id, $studentid; global $CFG, $COURSE, $mode, $current, $view, $id, $studentid, $DB;
echo '<table class="userinfobox">'; echo '<table class="userinfobox">';
if (!$printing) { if (!$printing) {
@ -268,17 +271,17 @@ function print_user_attendaces($user, $cm, $attforblock, $course = 0, $printing
} }
} else { } else {
$stqry = "SELECT ats.id,ats.courseid $stqry = "SELECT ats.id,ats.courseid
FROM {$CFG->prefix}attendance_log al FROM {attendance_log} al
JOIN {$CFG->prefix}attendance_sessions ats JOIN {attendance_sessions} ats
ON al.sessionid = ats.id ON al.sessionid = ats.id
WHERE al.studentid = {$user->id} WHERE al.studentid = {$user->id}
GROUP BY ats.courseid GROUP BY ats.courseid
ORDER BY ats.courseid asc"; ORDER BY ats.courseid asc";
$recs = get_records_sql_menu($stqry); $recs = $DB->get_records_sql_menu($stqry);
foreach ($recs as $id => $courseid) { foreach ($recs as $id => $courseid) {
echo '<hr />'; echo '<hr />';
echo '<table border="0" cellpadding="0" cellspacing="0" width="100%" class="list1">'; echo '<table border="0" cellpadding="0" cellspacing="0" width="100%" class="list1">';
$nextcourse = get_record('course', 'id', $courseid); $nextcourse = $DB->get_record('course', array('id'=> $courseid));
echo '<tr><td valign="top"><strong>'.$nextcourse->fullname.'</strong></td>'; echo '<tr><td valign="top"><strong>'.$nextcourse->fullname.'</strong></td>';
echo '<td align="right">'; echo '<td align="right">';
$complete = get_attendance($user->id, $nextcourse); $complete = get_attendance($user->id, $nextcourse);
@ -304,19 +307,19 @@ function print_user_attendaces($user, $cm, $attforblock, $course = 0, $printing
$enddate = $ret['enddate']; $enddate = $ret['enddate'];
if ($startdate && $enddate) { if ($startdate && $enddate) {
$where = "ats.courseid={$course->id} AND al.studentid = {$user->id} AND ats.sessdate >= $startdate AND ats.sessdate < $enddate"; $where = "ats.courseid=:cid AND al.studentid = :uid AND ats.sessdate >= :sdate AND ats.sessdate < :edate";
} else { } else {
$where = "ats.courseid={$course->id} AND al.studentid = {$user->id}"; $where = "ats.courseid=:cid AND al.studentid = :uid";
} }
$stqry = "SELECT ats.id,ats.sessdate,ats.description,al.statusid,al.remarks $stqry = "SELECT ats.id,ats.sessdate,ats.description,al.statusid,al.remarks
FROM {$CFG->prefix}attendance_log al FROM {attendance_log} al
JOIN {$CFG->prefix}attendance_sessions ats JOIN {attendance_sessions} ats
ON al.sessionid = ats.id"; ON al.sessionid = ats.id";
$stqry .= " WHERE " . $where; $stqry .= " WHERE " . $where;
$stqry .= " ORDER BY ats.sessdate asc"; $stqry .= " ORDER BY ats.sessdate asc";
if ($sessions = get_records_sql($stqry)) { if ($sessions = $DB->get_records_sql($stqry, array('cid' => $course->id, 'uid'=> $user->id, 'sdate'=> $startdate, 'edate'=> $enddate))) {
$statuses = get_statuses($course->id); $statuses = get_statuses($course->id);
$i = 0; $i = 0;

34
manage.php

@ -11,21 +11,21 @@
$view = optional_param('view', NULL, PARAM_ALPHA); // which page to show $view = optional_param('view', NULL, PARAM_ALPHA); // which page to show
$current = optional_param('current', 0, PARAM_INT); $current = optional_param('current', 0, PARAM_INT);
if (! $cm = get_record('course_modules', 'id', $id)) { if (! $cm = $DB->get_record('course_modules', array('id'=> $id))) {
error('Course Module ID was incorrect'); error('Course Module ID was incorrect');
} }
if (! $course = get_record('course', 'id', $cm->course)) { if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
error("Course is misconfigured"); error("Course is misconfigured");
} }
if (! $attforblock = get_record('attforblock', 'id', $cm->instance)) { if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect"); error("Course module is incorrect");
} }
require_login($course->id); require_login($course->id);
if (! $user = get_record('user', 'id', $USER->id) ) { if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course"); error("No such user in this course");
} }
@ -48,10 +48,10 @@
if($from === 'block') { if($from === 'block') {
$today = time(); // because we compare with database, we don't need to use usertime() $today = time(); // because we compare with database, we don't need to use usertime()
$sql = "SELECT id, groupid, lasttaken $sql = "SELECT id, groupid, lasttaken
FROM {$CFG->prefix}attendance_sessions FROM {attendance_sessions}
WHERE $today BETWEEN sessdate AND (sessdate + duration) WHERE ? BETWEEN sessdate AND (sessdate + duration)
AND courseid = $course->id"; AND courseid = $course->id";
if($atts = get_records_sql($sql)) { if($atts = $DB->get_records_sql($sql, array($today))) {
$size = count($atts); $size = count($atts);
if ($size == 1) { if ($size == 1) {
$att = reset($atts); $att = reset($atts);
@ -76,11 +76,11 @@
print_heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname); print_heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname);
if(!count_records_select('attendance_sessions', "courseid = $course->id AND sessdate >= $course->startdate")) { // no session exists for this course if(!$DB->count_records_select('attendance_sessions', "courseid = ? AND sessdate >= ?", array($course->id, $course->startdate))) { // no session exists for this course
show_tabs($cm, $context); show_tabs($cm, $context);
print_heading(get_string('nosessionexists','attforblock')); print_heading(get_string('nosessionexists','attforblock'));
$hiddensess = count_records_select('attendance_sessions', "courseid = $course->id AND sessdate < $course->startdate"); $hiddensess = $DB->count_records_select('attendance_sessions', "courseid = ? AND sessdate < ?", array($course->id, $course->startdate));
echo '<div align="left">'.helpbutton('hiddensessions', '', 'attforblock', true, true, '', true); echo '<div align="left">'.helpbutton('hiddensessions', '--', 'attforblock', true, true, '', true); //TODO: fix '--'
echo get_string('hiddensessions', 'attforblock').': '.$hiddensess.'</div>'; echo get_string('hiddensessions', 'attforblock').': '.$hiddensess.'</div>';
} else { //sessions generated , display them } else { //sessions generated , display them
add_to_log($course->id, 'attendance', 'manage attendances', 'mod/attforblock/manage.php?course='.$course->id, $user->lastname.' '.$user->firstname); add_to_log($course->id, 'attendance', 'manage attendances', 'mod/attforblock/manage.php?course='.$course->id, $user->lastname.' '.$user->firstname);
@ -93,7 +93,7 @@
function print_sessions_list($course) { function print_sessions_list($course) {
global $CFG, $context, $cm, $current, $view, $id; global $CFG, $context, $cm, $current, $view, $id, $DB;
$strhours = get_string('hours'); $strhours = get_string('hours');
$strmins = get_string('min'); $strmins = get_string('min');
@ -109,16 +109,16 @@ function print_sessions_list($course) {
$currentgroup = $ret['currentgroup']; $currentgroup = $ret['currentgroup'];
if ($startdate && $enddate) { if ($startdate && $enddate) {
$where = "courseid={$course->id} AND sessdate >= $course->startdate AND sessdate >= $startdate AND sessdate < $enddate"; $where = "courseid=:cid AND sessdate >= :sdate AND sessdate >= :sdate2 AND sessdate < :edate";
} else { } else {
$where = "courseid={$course->id} AND sessdate >= $course->startdate"; $where = "courseid=:cid AND sessdate >= :sdate";
} }
if ($currentgroup > -1) { if ($currentgroup > -1) {
$where .= " AND groupid=$currentgroup"; $where .= " AND groupid=:cgroup";
} }
$qry = get_records_select('attendance_sessions', $where, 'sessdate asc'); $qry = $DB->get_records_select('attendance_sessions', $where, array('cid' => $course->id, 'sdate' => $course->startdate,'sdate2' => $startdate, 'edate'=> $enddate, 'cgroup'=> $currentgroup), 'sessdate asc');
$i = 0; $i = 0;
$table->width = '100%'; $table->width = '100%';
//$table->tablealign = 'center'; //$table->tablealign = 'center';
@ -180,9 +180,9 @@ function print_sessions_list($course) {
echo '<div align="center"><div class="generalbox attwidth">'; echo '<div align="center"><div class="generalbox attwidth">';
echo "<form method=\"post\" action=\"sessions.php?id={$cm->id}\">"; //&amp;sessionid={$sessdata->id} echo "<form method=\"post\" action=\"sessions.php?id={$cm->id}\">"; //&amp;sessionid={$sessdata->id}
print_table($table); print_table($table);
$hiddensess = count_records_select('attendance_sessions', "courseid = $course->id AND sessdate < $course->startdate"); $hiddensess = $DB->count_records_select('attendance_sessions', "courseid = ? AND sessdate < ?", array($course->id,$course->startdate));
echo '<table width="100%"><tr><td valign="top">'; echo '<table width="100%"><tr><td valign="top">';
echo '<div align="left">'.helpbutton('hiddensessions', '', 'attforblock', true, true, '', true); echo '<div align="left">'.helpbutton('hiddensessions', '--', 'attforblock', true, true, '', true); //TODO: Change '--'
echo get_string('hiddensessions', 'attforblock').': '.$hiddensess.'</div></td>'; echo get_string('hiddensessions', 'attforblock').': '.$hiddensess.'</div></td>';
echo '<td><div align="right"><a href="javascript:checkall();">'.get_string('selectall').'</a> /'. echo '<td><div align="right"><a href="javascript:checkall();">'.get_string('selectall').'</a> /'.
' <a href="javascript:checknone();">'.get_string('deselectall').'</a><br /><br />'; ' <a href="javascript:checknone();">'.get_string('deselectall').'</a><br /><br />';

24
report.php

@ -5,7 +5,7 @@
require_once('../../config.php'); require_once('../../config.php');
require_once($CFG->libdir.'/blocklib.php'); require_once($CFG->libdir.'/blocklib.php');
require_once('locallib.php'); require_once('locallib.php');
define('USER_SMALL_CLASS', 20); // Below this is considered small define('USER_SMALL_CLASS', 20); // Below this is considered small
define('USER_LARGE_CLASS', 200); // Above this is considered large define('USER_LARGE_CLASS', 200); // Above this is considered large
define('DEFAULT_PAGE_SIZE', 20); define('DEFAULT_PAGE_SIZE', 20);
@ -17,20 +17,20 @@
$sort = optional_param('sort', 'lastname', PARAM_ALPHA); $sort = optional_param('sort', 'lastname', PARAM_ALPHA);
if ($id) { if ($id) {
if (! $cm = get_record('course_modules', 'id', $id)) { if (! $cm = $DB->get_record('course_modules', array('id'=> $id))) {
error('Course Module ID was incorrect'); error('Course Module ID was incorrect');
} }
if (! $course = get_record('course', 'id', $cm->course)) { if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
error('Course is misconfigured'); error('Course is misconfigured');
} }
if (! $attforblock = get_record('attforblock', 'id', $cm->instance)) { if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect"); error("Course module is incorrect");
} }
} }
require_login($course->id); require_login($course->id);
if (! $user = get_record('user', 'id', $USER->id) ) { if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course"); error("No such user in this course");
} }
@ -60,7 +60,7 @@
$sort = $sort == 'firstname' ? 'firstname' : 'lastname'; $sort = $sort == 'firstname' ? 'firstname' : 'lastname';
if(!count_records('attendance_sessions', 'courseid', $course->id)) { // no session exists for this course if(!$DB->count_records('attendance_sessions', array('courseid'=> $course->id))) { // no session exists for this course
redirect("sessions.php?id=$cm->id&amp;action=add"); redirect("sessions.php?id=$cm->id&amp;action=add");
} else { } else {
if ($current == 0) if ($current == 0)
@ -74,13 +74,13 @@
$currentgroup = $ret['currentgroup']; $currentgroup = $ret['currentgroup'];
if ($startdate && $enddate) { if ($startdate && $enddate) {
$where = "courseid={$course->id} AND sessdate >= $course->startdate AND sessdate >= $startdate AND sessdate < $enddate"; $where = "courseid=:cid AND sessdate >= :sdate AND sessdate >= :sdate2 AND sessdate < :edate";
} else { } else {
$where = "courseid={$course->id} AND sessdate >= $course->startdate"; $where = "courseid=:cid AND sessdate >= :sdate";
} }
if ($currentgroup) { if ($currentgroup) {
$where .= " AND (groupid=0 OR groupid=".$currentgroup.")"; $where .= " AND (groupid=0 OR groupid=:cgroup)";
$students = get_users_by_capability($context, 'moodle/legacy:student', '', "u.$sort ASC", '', '', $currentgroup, '', false); $students = get_users_by_capability($context, 'moodle/legacy:student', '', "u.$sort ASC", '', '', $currentgroup, '', false);
} else { } else {
$students = get_users_by_capability($context, 'moodle/legacy:student', '', "u.$sort ASC", '', '', '', '', false); $students = get_users_by_capability($context, 'moodle/legacy:student', '', "u.$sort ASC", '', '', '', '', false);
@ -91,7 +91,7 @@
if ($students and if ($students and
($course_sess = get_records_select('attendance_sessions', $where, 'sessdate ASC'))) { ($course_sess = $DB->get_records_select('attendance_sessions', $where, array('cid' => $course->id, 'sdate' => $course->startdate,'sdate2' => $startdate, 'edate'=> $enddate, 'cgroup'=> $currentgroup), 'sessdate ASC'))) {
$firstname = "<a href=\"report.php?id=$id&amp;sort=firstname\">".get_string('firstname').'</a>'; $firstname = "<a href=\"report.php?id=$id&amp;sort=firstname\">".get_string('firstname').'</a>';
$lastname = "<a href=\"report.php?id=$id&amp;sort=lastname\">".get_string('lastname').'</a>'; $lastname = "<a href=\"report.php?id=$id&amp;sort=lastname\">".get_string('lastname').'</a>';
@ -112,7 +112,7 @@
$allowchange = has_capability('mod/attforblock:changeattendances', $context); $allowchange = has_capability('mod/attforblock:changeattendances', $context);
$groups = groups_get_all_groups($course->id); $groups = groups_get_all_groups($course->id);
foreach($course_sess as $sessdata) { foreach($course_sess as $sessdata) {
if (count_records('attendance_log', 'sessionid', $sessdata->id)) { if ($DB->count_records('attendance_log', array('sessionid'=> $sessdata->id))) {
if ($allowchange) { if ($allowchange) {
$sessdate = "<a href=\"attendances.php?id=$id&amp;sessionid={$sessdata->id}&amp;grouptype={$sessdata->groupid}\">". $sessdate = "<a href=\"attendances.php?id=$id&amp;sessionid={$sessdata->id}&amp;grouptype={$sessdata->groupid}\">".
userdate($sessdata->sessdate, get_string('strftimedm', 'attforblock').'<br />('.get_string('strftimehm', 'attforblock').')'). userdate($sessdata->sessdate, get_string('strftimedm', 'attforblock').'<br />('.get_string('strftimehm', 'attforblock').')').
@ -158,7 +158,7 @@
$table->data[$student->id][] = "<a href=\"view.php?id=$id&amp;student={$student->id}\">".fullname($student).'</a>'; $table->data[$student->id][] = "<a href=\"view.php?id=$id&amp;student={$student->id}\">".fullname($student).'</a>';
$studgroups = groups_get_all_groups($COURSE->id, $student->id); $studgroups = groups_get_all_groups($COURSE->id, $student->id);
foreach($course_sess as $sessdata) { foreach($course_sess as $sessdata) {
if ($att = get_record('attendance_log', 'sessionid', $sessdata->id, 'studentid', $student->id)) { if ($att = $DB->get_record('attendance_log', array('sessionid'=> $sessdata->id, 'studentid'=> $student->id))) {
if (isset($statuses[$att->statusid])) { if (isset($statuses[$att->statusid])) {
$table->data[$student->id][] = $statuses[$att->statusid]->acronym; $table->data[$student->id][] = $statuses[$att->statusid]->acronym;
} else { } else {

28
restorelib.php

@ -2,7 +2,7 @@
function attforblock_restore_mods($mod,$restore) { function attforblock_restore_mods($mod,$restore) {
global $CFG, $oldidarray; global $CFG, $oldidarray, $DB;
$status = true; $status = true;
@ -13,7 +13,7 @@
//Now get completed xmlized object //Now get completed xmlized object
$info = $data->info; $info = $data->info;
if (count_records('attforblock', 'course', $restore->course_id)) { if ($DB->count_records('attforblock', array('course'=> $restore->course_id))) {
return false; return false;
} }
@ -28,7 +28,7 @@
} }
//The structure is equal to the db, so insert the attforblock //The structure is equal to the db, so insert the attforblock
$newid = insert_record ('attforblock', $attforblock); $newid = $DB->insert_record ('attforblock', $attforblock);
if ($newid) { if ($newid) {
//We have the newid, update backup_ids //We have the newid, update backup_ids
backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid); backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
@ -53,7 +53,7 @@
function attforblock_restore_attendance_sessions ($old_attforblock_id, $new_attforblock_id, $info, $restore) { function attforblock_restore_attendance_sessions ($old_attforblock_id, $new_attforblock_id, $info, $restore) {
global $CFG, $oldidarray; global $CFG, $oldidarray, $DB;
$status = true; $status = true;
@ -94,7 +94,7 @@
$stat->lasttakenby = 0; $stat->lasttakenby = 0;
} }
$newid = insert_record ('attendance_sessions', $stat); $newid = $DB->insert_record ('attendance_sessions', $stat);
$oldidarray[$old_attforblock_id]['attendance_sessions'][backup_todb($stat_info['#']['ID']['0']['#'])] = $newid; $oldidarray[$old_attforblock_id]['attendance_sessions'][backup_todb($stat_info['#']['ID']['0']['#'])] = $newid;
} }
@ -105,7 +105,7 @@
function attforblock_restore_attendance_statuses ($old_attforblock_id, $new_attforblock_id,$info,$restore) { function attforblock_restore_attendance_statuses ($old_attforblock_id, $new_attforblock_id,$info,$restore) {
global $CFG, $oldidarray; global $CFG, $oldidarray, $DB;
$status = true; $status = true;
@ -128,7 +128,7 @@
continue; continue;
} }
$newid = insert_record ('attendance_statuses', $stat); $newid = $DB->insert_record ('attendance_statuses', $stat);
$oldidarray[$old_attforblock_id]['attendance_statuses'][backup_todb($stat_info['#']['ID']['0']['#'])] = $newid; $oldidarray[$old_attforblock_id]['attendance_statuses'][backup_todb($stat_info['#']['ID']['0']['#'])] = $newid;
} }
@ -145,7 +145,7 @@
$stat->visible = 1; $stat->visible = 1;
$stat->deleted = 0; $stat->deleted = 0;
$newid = insert_record ('attendance_statuses', $stat); $newid = $DB->insert_record ('attendance_statuses', $stat);
$oldidarray[$old_attforblock_id]['attendance_statuses'][backup_todb($stat_info['#']['STATUS']['0']['#'])] = $newid; $oldidarray[$old_attforblock_id]['attendance_statuses'][backup_todb($stat_info['#']['STATUS']['0']['#'])] = $newid;
} }
@ -153,13 +153,13 @@
} else { } else {
// ATTFORBLOCK_SETTINGS tag don't exists // ATTFORBLOCK_SETTINGS tag don't exists
// so course used default statuses (can be only in old version) // so course used default statuses (can be only in old version)
$stats = get_records('attendance_statuses', 'courseid', 0, 'id ASC'); $stats = $DB->get_records('attendance_statuses', array('courseid'=> 0), 'id ASC');
$oldstats = array('P', 'A', 'L', 'E'); $oldstats = array('P', 'A', 'L', 'E');
$i = 0; $i = 0;
foreach($stats as $stat) { foreach($stats as $stat) {
// $stat = $stats[$i]; // $stat = $stats[$i];
$stat->courseid = $restore->course_id; $stat->courseid = $restore->course_id;
$newid = insert_record('attendance_statuses', $stat); $newid = $DB->insert_record('attendance_statuses', $stat);
$oldidarray[$old_attforblock_id]['attendance_statuses'][$oldstats[$i++]] = $newid; $oldidarray[$old_attforblock_id]['attendance_statuses'][$oldstats[$i++]] = $newid;
// $i++; // $i++;
} }
@ -171,7 +171,7 @@
function attforblock_restore_attendance_log ($old_attforblock_id, $new_attforblock_id,$info,$restore) { function attforblock_restore_attendance_log ($old_attforblock_id, $new_attforblock_id,$info,$restore) {
global $CFG, $oldidarray; global $CFG, $oldidarray, $DB;
$status = true; $status = true;
@ -182,9 +182,9 @@
@$logs = $info['MOD']['#']['ATTFORBLOCK_LOG']['0']['#']['ROWS']; @$logs = $info['MOD']['#']['ATTFORBLOCK_LOG']['0']['#']['ROWS'];
} }
$stats = get_records_menu('attendance_statuses', 'courseid', $restore->course_id); $stats = $DB->get_records_menu('attendance_statuses', array('courseid'=> $restore->course_id));
$statslist = implode(',', array_keys($stats)); $statslist = implode(',', array_keys($stats));
$sessions = get_records('attendance_sessions', 'courseid', $restore->course_id); $sessions = $DB->get_records('attendance_sessions', 'courseid', $restore->course_id);
//Iterate over logs //Iterate over logs
for($i = 0; $i < sizeof($logs); $i++) { for($i = 0; $i < sizeof($logs); $i++) {
@ -230,7 +230,7 @@
// $log->takenby = backup_todb($log_info['#']['TAKENBY']['0']['#']); // $log->takenby = backup_todb($log_info['#']['TAKENBY']['0']['#']);
} }
$newid = insert_record ('attendance_log', $log); $newid = $DB->insert_record ('attendance_log', $log);
$oldidarray[$old_attforblock_id]['attendance_log'][backup_todb($log_info['#']['ID']['0']['#'])] = $newid; $oldidarray[$old_attforblock_id]['attendance_log'][backup_todb($log_info['#']['ID']['0']['#'])] = $newid;

36
sessions.php

@ -7,7 +7,7 @@
require_once('add_form.php'); require_once('add_form.php');
require_once('update_form.php'); require_once('update_form.php');
require_once('duration_form.php'); require_once('duration_form.php');
if (!function_exists('grade_update')) { //workaround for buggy PHP versions if (!function_exists('grade_update')) { //workaround for buggy PHP versions
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
} }
@ -16,20 +16,20 @@
$action = required_param('action', PARAM_ACTION); $action = required_param('action', PARAM_ACTION);
if ($id) { if ($id) {
if (! $cm = get_record('course_modules', 'id', $id)) { if (! $cm = $DB->get_record('course_modules', array('id'=> $id))) {
error('Course Module ID was incorrect'); error('Course Module ID was incorrect');
} }
if (! $course = get_record('course', 'id', $cm->course)) { if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
error('Course is misconfigured'); error('Course is misconfigured');
} }
if (! $attforblock = get_record('attforblock', 'id', $cm->instance)) { if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect"); error("Course module is incorrect");
} }
} }
require_login($course->id); require_login($course->id);
if (! $user = get_record('user', 'id', $USER->id) ) { if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course"); error("No such user in this course");
} }
@ -96,7 +96,7 @@
$rec->description = $fromform->sdescription; $rec->description = $fromform->sdescription;
$rec->timemodified = $now; $rec->timemodified = $now;
if ($fromform->sessiontype == COMMONSESSION) { if ($fromform->sessiontype == COMMONSESSION) {
if(!insert_record('attendance_sessions', $rec)) if(!$DB->insert_record('attendance_sessions', $rec))
error(get_string('erroringeneratingsessions','attforblock'), "sessions.php?id=$id&amp;action=add"); error(get_string('erroringeneratingsessions','attforblock'), "sessions.php?id=$id&amp;action=add");
} else { } else {
foreach ($fromform->groups as $groupid) { foreach ($fromform->groups as $groupid) {
@ -156,7 +156,7 @@
redirect('manage.php?id='.$id); redirect('manage.php?id='.$id);
} }
if ($fromform = $mform_update->get_data()) { if ($fromform = $mform_update->get_data()) {
if (!$att = get_record('attendance_sessions', 'id', $sessionid) ) { if (!$att = $DB->get_record('attendance_sessions', array('id'=> $sessionid) )) {
error('No such session in this course'); error('No such session in this course');
} }
@ -174,7 +174,7 @@
$att->duration = $fromform->durtime['hours']*HOURSECS + $fromform->durtime['minutes']*MINSECS; $att->duration = $fromform->durtime['hours']*HOURSECS + $fromform->durtime['minutes']*MINSECS;
$att->description = $fromform->sdescription; $att->description = $fromform->sdescription;
$att->timemodified = time(); $att->timemodified = time();
update_record('attendance_sessions', $att); $DB->update_record('attendance_sessions', $att);
add_to_log($course->id, 'attendance', 'Session updated', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname); add_to_log($course->id, 'attendance', 'Session updated', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
//notice(get_string('sessionupdated','attforblock'), 'manage.php?id='.$id); //notice(get_string('sessionupdated','attforblock'), 'manage.php?id='.$id);
redirect('manage.php?id='.$id, get_string('sessionupdated','attforblock'), 3); redirect('manage.php?id='.$id, get_string('sessionupdated','attforblock'), 3);
@ -193,15 +193,15 @@
$sessionid = required_param('sessionid'); $sessionid = required_param('sessionid');
$confirm = optional_param('confirm'); $confirm = optional_param('confirm');
if (!$att = get_record('attendance_sessions', 'id', $sessionid) ) { if (!$att = $DB->get_record('attendance_sessions', array('id'=> $sessionid) )) {
error('No such session in this course'); error('No such session in this course');
} }
if (isset($confirm)) { if (isset($confirm)) {
delete_records('attendance_log', 'sessionid', $sessionid); $DB->delete_records('attendance_log', array('sessionid'=> $sessionid));
delete_records('attendance_sessions', 'id', $sessionid); $DB->delete_records('attendance_sessions', array('id'=> $sessionid));
add_to_log($course->id, 'attendance', 'Session deleted', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname); add_to_log($course->id, 'attendance', 'Session deleted', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
$attforblockrecord = get_record('attforblock', 'course', $course->id); $attforblockrecord = $DB->get_record('attforblock', array('course'=> $course->id));
attforblock_update_grades($attforblockrecord); attforblock_update_grades($attforblockrecord);
redirect('manage.php?id='.$id, get_string('sessiondeleted','attforblock'), 3); redirect('manage.php?id='.$id, get_string('sessiondeleted','attforblock'), 3);
} }
@ -219,18 +219,18 @@
if (isset($confirm)) { if (isset($confirm)) {
$sessionid = required_param('sessionid'); $sessionid = required_param('sessionid');
$ids = implode(',', explode('_', $sessionid)); $ids = implode(',', explode('_', $sessionid));
delete_records_select('attendance_log', "sessionid IN ($ids)"); $DB->delete_records_select('attendance_log', "sessionid IN ($ids)");
delete_records_select('attendance_sessions', "id IN ($ids)"); $DB->delete_records_select('attendance_sessions', "id IN ($ids)");
add_to_log($course->id, 'attendance', 'Several sessions deleted', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname); add_to_log($course->id, 'attendance', 'Several sessions deleted', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
$attforblockrecord = get_record('attforblock','course',$course->id); $attforblockrecord = $DB->get_record('attforblock',array('course'=> $course->id));
attforblock_update_grades($attforblockrecord); attforblock_update_grades($attforblockrecord);
redirect('manage.php?id='.$id, get_string('sessiondeleted','attforblock'), 3); redirect('manage.php?id='.$id, get_string('sessiondeleted','attforblock'), 3);
} }
$fromform = data_submitted(); $fromform = data_submitted();
$slist = implode(',', array_keys($fromform->sessid)); $slist = implode(',', array_keys($fromform->sessid));
$sessions = get_records_list('attendance_sessions', 'id', $slist, 'sessdate'); $sessions = $DB->get_records_list('attendance_sessions', array('id'=> $slist), 'sessdate');
print_heading(get_string('deletingsession','attforblock').' :: ' .$course->fullname); print_heading(get_string('deletingsession','attforblock').' :: ' .$course->fullname);
$message = '<br />'; $message = '<br />';
@ -262,13 +262,13 @@
if ($fromform = $mform_duration->get_data()) { if ($fromform = $mform_duration->get_data()) {
$now = time(); $now = time();
$slist = implode(',', explode('_', $fromform->ids)); $slist = implode(',', explode('_', $fromform->ids));
if (!$sessions = get_records_list('attendance_sessions', 'id', $slist) ) { if (!$sessions = $DB->get_records_list('attendance_sessions', array('id'=> $slist) )) {
error('No such session in this course'); error('No such session in this course');
} }
foreach ($sessions as $sess) { foreach ($sessions as $sess) {
$sess->duration = $fromform->durtime['hours']*HOURSECS + $fromform->durtime['minutes']*MINSECS; $sess->duration = $fromform->durtime['hours']*HOURSECS + $fromform->durtime['minutes']*MINSECS;
$sess->timemodified = $now; $sess->timemodified = $now;
update_record('attendance_sessions', $sess); $DB->update_record('attendance_sessions', $sess);
} }
add_to_log($course->id, 'attendance', 'Session updated', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname); add_to_log($course->id, 'attendance', 'Session updated', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
redirect('manage.php?id='.$id, get_string('sessionupdated','attforblock'), 3); redirect('manage.php?id='.$id, get_string('sessionupdated','attforblock'), 3);

4
update_form.php

@ -6,7 +6,7 @@ class mod_attforblock_update_form extends moodleform {
function definition() { function definition() {
global $CFG; global $CFG, $DB;
$mform =& $this->_form; $mform =& $this->_form;
$course = $this->_customdata['course']; $course = $this->_customdata['course'];
@ -16,7 +16,7 @@ class mod_attforblock_update_form extends moodleform {
$sessionid = $this->_customdata['sessionid']; $sessionid = $this->_customdata['sessionid'];
if (!$att = get_record('attendance_sessions', 'id', $sessionid) ) { if (!$att = $DB->get_record('attendance_sessions', array('id'=> $sessionid) )) {
error('No such session in this course'); error('No such session in this course');
} }
$mform->addElement('header', 'general', get_string('changesession','attforblock')); $mform->addElement('header', 'general', get_string('changesession','attforblock'));

14
view.php

@ -9,21 +9,21 @@
$id = optional_param('id', -1, PARAM_INT); // Course Module ID, or $id = optional_param('id', -1, PARAM_INT); // Course Module ID, or
// $a = optional_param('a', -1, PARAM_INT); // attforblock ID // $a = optional_param('a', -1, PARAM_INT); // attforblock ID
$studentid = optional_param('student', 0, PARAM_INT); $studentid = optional_param('student', 0, PARAM_INT);
$printing = optional_param('printing'); $printing = optional_param('printing', 0, PARAM_INT);
$mode = optional_param('mode', 'thiscourse'); $mode = optional_param('mode', 'thiscourse', PARAM_ALPHA);
$view = optional_param('view', NULL, PARAM_ALPHA); // which page to show $view = optional_param('view', NULL, PARAM_ALPHA); // which page to show
$current = optional_param('current', 0, PARAM_INT); $current = optional_param('current', 0, PARAM_INT);
if ($id) { if ($id) {
if (! $cm = get_record("course_modules", "id", $id)) { if (! $cm = $DB->get_record("course_modules", array("id"=> $id))) {
error("Course Module ID was incorrect"); error("Course Module ID was incorrect");
} }
if (! $course = get_record("course", "id", $cm->course)) { if (! $course = $DB->get_record("course", array("id"=> $cm->course))) {
error("Course is misconfigured"); error("Course is misconfigured");
} }
if (! $attforblock = get_record("attforblock", "id", $cm->instance)) { if (! $attforblock = $DB->get_record("attforblock", array("id"=> $cm->instance))) {
error("Course module is incorrect"); error("Course module is incorrect");
} }
@ -55,7 +55,7 @@
redirect("report.php?id=$cm->id"); redirect("report.php?id=$cm->id");
} }
if (! $user = get_record('user', 'id', $USER->id) ) { if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course"); error("No such user in this course");
} }
@ -69,7 +69,7 @@
$student = false; $student = false;
if ($studentid) { if ($studentid) {
if ($studentid == $USER->id or has_capability('mod/attforblock:viewreports', $context)) { if ($studentid == $USER->id or has_capability('mod/attforblock:viewreports', $context)) {
if (!$student = get_record('user', 'id', $studentid) ) { if (!$student = $DB->get_record('user', array('id'=> $studentid) )) {
error("No such user in this course"); error("No such user in this course");
} }
} }

Loading…
Cancel
Save