From cde262c26083a23ccf839906562e116c70672114 Mon Sep 17 00:00:00 2001 From: Luis Ramon Lopez Date: Wed, 9 Feb 2011 04:02:18 +0100 Subject: [PATCH] Initial database migration to Moodle 2.0 --- attendances.php | 28 +- attsettings.php | 34 +-- backuplib.php | 29 ++- db/install.xml | 56 ++-- db/upgrade.php | 242 +++++++++--------- export.php | 15 +- index.php | 2 +- lang/{en_utf8 => en}/attforblock.php | 2 +- .../attforblock/createmultiplesessions.html | 0 .../help/attforblock/createonesession.html | 0 .../help/attforblock/defaultstatuses.html | 0 .../help/attforblock/display.html | 0 .../help/attforblock/export.html | 0 .../help/attforblock/hiddensessions.html | 0 .../help/attforblock/myvariables.html | 0 .../help/attforblock/report.html | 0 .../help/attforblock/sessions.html | 0 .../help/attforblock/sessiontypes.html | 0 .../help/attforblock/studentview.html | 0 lang/{es_utf8 => es}/attforblock.php | 1 + .../help/attforblock/changesession.html | 0 .../attforblock/createmultiplesessions.html | 0 .../help/attforblock/createonesession.html | 0 .../help/attforblock/defaultstatuses.html | 0 .../help/attforblock/display.html | 0 .../help/attforblock/export.html | 0 .../help/attforblock/hiddensessions.html | 0 .../help/attforblock/mods.html | 0 .../help/attforblock/myvariables.html | 0 .../help/attforblock/report.html | 0 .../help/attforblock/sessions.html | 0 .../help/attforblock/sessiontypes.html | 0 .../help/attforblock/studentview.html | 0 .../help/attforblock/updateattendance.html | 0 lib.php | 82 +++--- locallib.php | 85 +++--- manage.php | 34 +-- report.php | 24 +- restorelib.php | 28 +- sessions.php | 36 +-- update_form.php | 4 +- view.php | 14 +- 42 files changed, 372 insertions(+), 344 deletions(-) rename lang/{en_utf8 => en}/attforblock.php (99%) rename lang/{en_utf8 => en}/help/attforblock/createmultiplesessions.html (100%) rename lang/{en_utf8 => en}/help/attforblock/createonesession.html (100%) rename lang/{en_utf8 => en}/help/attforblock/defaultstatuses.html (100%) rename lang/{en_utf8 => en}/help/attforblock/display.html (100%) rename lang/{en_utf8 => en}/help/attforblock/export.html (100%) rename lang/{en_utf8 => en}/help/attforblock/hiddensessions.html (100%) rename lang/{en_utf8 => en}/help/attforblock/myvariables.html (100%) rename lang/{en_utf8 => en}/help/attforblock/report.html (100%) rename lang/{en_utf8 => en}/help/attforblock/sessions.html (100%) rename lang/{en_utf8 => en}/help/attforblock/sessiontypes.html (100%) rename lang/{en_utf8 => en}/help/attforblock/studentview.html (100%) rename lang/{es_utf8 => es}/attforblock.php (99%) rename lang/{es_utf8 => es}/help/attforblock/changesession.html (100%) rename lang/{es_utf8 => es}/help/attforblock/createmultiplesessions.html (100%) rename lang/{es_utf8 => es}/help/attforblock/createonesession.html (100%) rename lang/{es_utf8 => es}/help/attforblock/defaultstatuses.html (100%) rename lang/{es_utf8 => es}/help/attforblock/display.html (100%) rename lang/{es_utf8 => es}/help/attforblock/export.html (100%) rename lang/{es_utf8 => es}/help/attforblock/hiddensessions.html (100%) rename lang/{es_utf8 => es}/help/attforblock/mods.html (100%) rename lang/{es_utf8 => es}/help/attforblock/myvariables.html (100%) rename lang/{es_utf8 => es}/help/attforblock/report.html (100%) rename lang/{es_utf8 => es}/help/attforblock/sessions.html (100%) rename lang/{es_utf8 => es}/help/attforblock/sessiontypes.html (100%) rename lang/{es_utf8 => es}/help/attforblock/studentview.html (100%) rename lang/{es_utf8 => es}/help/attforblock/updateattendance.html (100%) diff --git a/attendances.php b/attendances.php index 237ce6c..77c642c 100644 --- a/attendances.php +++ b/attendances.php @@ -6,7 +6,7 @@ require_once($CFG->libdir.'/blocklib.php'); require_once('locallib.php'); require_once('lib.php'); - + if (!function_exists('grade_update')) { //workaround for buggy PHP versions require_once($CFG->libdir.'/gradelib.php'); } @@ -17,20 +17,20 @@ $group = optional_param('group', -1, PARAM_INT); // Group to show $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'); } - if (! $course = get_record('course', 'id', $cm->course)) { + if (! $course = $DB->get_record('course', array('id'=> $cm->course))) { error('Course is misconfigured'); } 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"); } - 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"); } @@ -58,18 +58,18 @@ $i++; } } - $attforblockrecord = get_record('attforblock', 'course', $course->id); + $attforblockrecord = $DB->get_record('attforblock', array('course' => $course->id)); 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 - update_record('attendance_log', $student); + $DB->update_record('attendance_log', $student); } else { - insert_record('attendance_log', $student); + $DB->insert_record('attendance_log', $student); } } - set_field('attendance_sessions', 'lasttaken', $now, 'id', $sessionid); - set_field('attendance_sessions', 'lasttakenby', $USER->id, 'id', $sessionid); + $DB->set_field('attendance_sessions', 'lasttaken', $now, array('id' => $sessionid)); + $DB->set_field('attendance_sessions', 'lasttakenby', $USER->id, array('id' => $sessionid)); attforblock_update_grades($attforblockrecord); 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)); //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); } $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) { require_capability('mod/attforblock:changeattendances', $context); @@ -164,7 +164,7 @@ $i = 0; foreach($students as $student) { $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) ? "$i" : $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][] = "id}\">".((!$att && $update) ? '' : '').fullname($student).((!$att && $update) ? '' : '').''; diff --git a/attsettings.php b/attsettings.php index c10a9c2..a7bc7f0 100644 --- a/attsettings.php +++ b/attsettings.php @@ -3,29 +3,29 @@ require_once('../../config.php'); require_once('locallib.php'); require_once('lib.php'); - + $id = required_param('id', PARAM_INT); $submitsettings = optional_param('submitsettings'); $action = optional_param('action', '', PARAM_MULTILANG); $stid = optional_param('st', 0, PARAM_INT); 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'); } - if (! $course = get_record('course', 'id', $cm->course)) { + if (! $course = $DB->get_record('course', array('id'=> $cm->course))) { 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"); } } - $attforblockrecord = get_record('attforblock','course',$course->id); + $attforblockrecord = $DB->get_record('attforblock',array('course'=>$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"); } @@ -45,16 +45,16 @@ if (!empty($action)) { switch ($action) { 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"); } - if (count_records('attendance_log', 'statusid', $stid)) { + if ($DB->count_records('attendance_log', array('statusid'=> $stid))) { print_error('cantdeletestatus', 'attforblock', "attsettings.php?id=$id"); } $confirm = optional_param('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); redirect('attsettings.php?id='.$id, get_string('statusdeleted','attforblock'), 3); } @@ -66,13 +66,13 @@ "attsettings.php?id=$id&st=$stid&action=delete&confirm=1", $_SERVER['HTTP_REFERER']); exit; case 'show': - set_field('attendance_statuses', 'visible', 1, 'id', $stid); + $DB->set_field('attendance_statuses', 'visible', 1, array('id' => $stid)); break; case 'hide': $students = get_users_by_capability($context, 'moodle/legacy:student', '', '', '', '', '', '', false); $studlist = implode(',', array_keys($students)); - if (!count_records_select('attendance_log', "studentid IN ($studlist) AND statusid = $stid")) { - set_field('attendance_statuses', 'visible', 0, 'id', $stid); + if (!$DB->count_records_select('attendance_log', "studentid IN (?) AND statusid = ?", array( $studlist, $stid) )) { + $DB->set_field('attendance_statuses', 'visible', 0, array('id' => $stid)); } else { print_error('canthidestatus', 'attforblock', "attsettings.php?id=$id"); } @@ -87,7 +87,7 @@ $rec->acronym = $newacronym; $rec->description = $newdescription; $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); } else { print_error('cantaddstatus', 'attforblock', "attsettings.php?id=$id"); @@ -126,7 +126,7 @@ $action = $st->visible ? 'hide' : 'show'; $titlevis = get_string($action); $deleteact = ''; - if (!count_records('attendance_log', 'statusid', $st->id)) { + if (!$DB->count_records('attendance_log', array('statusid'=> $st->id))) { $deleteact = "id&st={$st->id}&action=delete\">". "pixpath}/t/delete.gif\" alt=\"$deltitle\" /> "; } @@ -156,18 +156,18 @@ function config_save() { - global $course, $user, $attforblockrecord; + global $course, $user, $attforblockrecord, $DB; $acronym = required_param('acronym'); $description = required_param('description'); $grade = required_param('grade',PARAM_INT); 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->description = $description[$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); } attforblock_update_grades($attforblockrecord); diff --git a/backuplib.php b/backuplib.php index 0c36cc7..2912007 100644 --- a/backuplib.php +++ b/backuplib.php @@ -16,11 +16,14 @@ function attforblock_check_backup_mods_instances($course, $instance, $backup_unique_code) { + + global $DB; + //First the course data $info[$instance->id.'0'][0] = ''.$instance->name.''; $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'][1] = count($sessions); @@ -28,7 +31,7 @@ if (!empty($instance->userdata)) { $info[$instance->id.'2'][0] = get_string('attrecords', 'attforblock'); $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); } else { $info[$instance->id.'2'][1] = 0; @@ -40,12 +43,12 @@ function attforblock_backup_mods($bf, $preferences) { - global $CFG; + global $CFG, $DB; $status = true; //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) { foreach ($attforblocks as $attforblock) { if (backup_mod_selected($preferences, 'attforblock', $attforblock->id)) { @@ -61,10 +64,10 @@ function attforblock_backup_one_mod($bf, $preferences, $attforblock) { - global $CFG; + global $CFG, $DB; if (is_numeric($attforblock)) { - $attforblock = get_record('attforblock', 'id', $attforblock); + $attforblock = $DB->get_record('attforblock', array('id'=> $attforblock)); } $status = true; @@ -93,11 +96,11 @@ function attforblock_backup_attendance_sessions ($bf,$preferences,$attforblock) { - global $CFG; + global $CFG, $DB; $status = true; - $datas = get_records('attendance_sessions', 'courseid', $attforblock->course); + $datas = $DB->get_records('attendance_sessions', array('courseid'=> $attforblock->course)); if ($datas) { //Write start tag $status =fwrite ($bf,start_tag('SESSIONS',4,true)); @@ -132,11 +135,11 @@ function attforblock_backup_attendance_statuses ($bf,$preferences,$attforblock) { - global $CFG; + global $CFG, $DB; $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 ($datas) { //Write start tag @@ -166,13 +169,13 @@ function attforblock_backup_attendance_log ($bf,$preferences,$attforblock) { - global $CFG; + global $CFG, $DB; $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)); - $datas = get_records_list('attendance_log', 'sessionid', $sesslist); + $datas = $DB->get_records_list('attendance_log', array('sessionid'=> $sesslist)); //If there is levels if ($datas) { //Write start tag diff --git a/db/install.xml b/db/install.xml index d4a7667..3e7ae64 100644 --- a/db/install.xml +++ b/db/install.xml @@ -6,10 +6,10 @@ - - - - + + + + @@ -20,15 +20,15 @@
- - - - - - - - - + + + + + + + + + @@ -41,14 +41,14 @@
- - - - - - - - + + + + + + + + @@ -61,13 +61,13 @@
- - - - - - - + + + + + + + diff --git a/db/upgrade.php b/db/upgrade.php index 8b4cc7a..884438a 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -19,7 +19,9 @@ 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; @@ -28,157 +30,160 @@ function xmldb_attforblock_upgrade($oldversion=0) { /// this comment lines once this file start handling proper /// upgrade code. - if ($result && $oldversion < 2008021904) { //New version in version.php + if ($oldversion < 2008021904) { //New version in version.php global $USER; - if ($sessions = get_records('attendance_sessions', 'takenby', 0)) { + if ($sessions = $DB->get_records('attendance_sessions', array('takenby'=> 0))) { 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->timetaken = $sess->timemodified ? $sess->timemodified : time(); $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->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '100', 'name'); - $result = $result && add_field($table, $field); + $field = new xmldb_field('grade'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '100', 'name'); + $dbman->add_field($table, $field); - $table = new XMLDBTable('attendance_sessions'); + $table = new xmldb_table('attendance_sessions'); - $field = new XMLDBField('courseid'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); - $result = $result && change_field_unsigned($table, $field); + $field = new xmldb_field('courseid'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); + $dbman->change_field_unsigned($table, $field); -// $field = new XMLDBField('creator'); -// $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid'); -// $result = $result && change_field_unsigned($table, $field); +// $field = new xmldb_field('creator'); +// $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid'); +// change_field_unsigned($table, $field); - $field = new XMLDBField('sessdate'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'creator'); - $result = $result && change_field_unsigned($table, $field); + $field = new xmldb_field('sessdate'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'creator'); + $dbman->change_field_unsigned($table, $field); - $field = new XMLDBField('duration'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'sessdate'); - $result = $result && add_field($table, $field); + $field = new xmldb_field('duration'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'sessdate'); + $dbman->add_field($table, $field); - $field = new XMLDBField('timetaken'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'takenby'); - $result = $result && change_field_unsigned($table, $field); - $result = $result && rename_field($table, $field, 'lasttaken'); + $field = new xmldb_field('timetaken'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'takenby'); + $dbman->change_field_unsigned($table, $field); + $dbman->rename_field($table, $field, 'lasttaken'); - $field = new XMLDBField('takenby'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'lasttaken'); - $result = $result && change_field_unsigned($table, $field); - $result = $result && rename_field($table, $field, 'lasttakenby'); + $field = new xmldb_field('takenby'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'lasttaken'); + $dbman->change_field_unsigned($table, $field); + $dbman->rename_field($table, $field, 'lasttakenby'); - $field = new XMLDBField('timemodified'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'lasttaken'); - $result = $result && change_field_unsigned($table, $field); + $field = new xmldb_field('timemodified'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'lasttaken'); + $dbman->change_field_unsigned($table, $field); - $table = new XMLDBTable('attendance_log'); + $table = new xmldb_table('attendance_log'); - $field = new XMLDBField('attsid'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); - $result = $result && change_field_unsigned($table, $field); + $field = new xmldb_field('attsid'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); + $dbman->change_field_unsigned($table, $field); - $field = new XMLDBField('studentid'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'attsid'); - $result = $result && change_field_unsigned($table, $field); + $field = new xmldb_field('studentid'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'attsid'); + $dbman->change_field_unsigned($table, $field); - $field = new XMLDBField('statusid'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'status'); - $result = $result && add_field($table, $field); + $field = new xmldb_field('statusid'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'status'); + $dbman->add_field($table, $field); - $field = new XMLDBField('statusset'); - $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null, 'statusid'); - $result = $result && add_field($table, $field); + $field = new xmldb_field('statusset'); + $field->set_attributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, 'statusid'); + $dbman->add_field($table, $field); - $field = new XMLDBField('timetaken'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'statusid'); - $result = $result && add_field($table, $field); + $field = new xmldb_field('timetaken'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'statusid'); + $dbman->add_field($table, $field); - $field = new XMLDBField('takenby'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timetaken'); - $result = $result && add_field($table, $field); + $field = new xmldb_field('takenby'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timetaken'); + $dbman->add_field($table, $field); //Indexes - $index = new XMLDBIndex('statusid'); - $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('statusid')); - $result = $result && add_index($table, $index); + $index = new xmldb_index('statusid'); + $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('statusid')); + $dbman->add_index($table, $index); - $index = new XMLDBIndex('attsid'); - $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('attsid')); - $result = $result && drop_index($table, $index); + $index = new xmldb_index('attsid'); + $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('attsid')); + $dbman->drop_index($table, $index); - $field = new XMLDBField('attsid'); //Rename field - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); - $result = $result && rename_field($table, $field, 'sessionid'); + $field = new xmldb_field('attsid'); //Rename field + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); + $dbman->rename_field($table, $field, 'sessionid'); - $index = new XMLDBIndex('sessionid'); - $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid')); - $result = $result && add_index($table, $index); + $index = new xmldb_index('sessionid'); + $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid')); + $dbman->add_index($table, $index); - $table = new XMLDBTable('attendance_settings'); + $table = new xmldb_table('attendance_settings'); - $field = new XMLDBField('courseid'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); - $result = $result && change_field_unsigned($table, $field); + $field = new xmldb_field('courseid'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); + $dbman->change_field_unsigned($table, $field); - $field = new XMLDBField('visible'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'grade'); - $result = $result && add_field($table, $field); + $field = new xmldb_field('visible'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'grade'); + $dbman->add_field($table, $field); - $field = new XMLDBField('deleted'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'visible'); - $result = $result && add_field($table, $field); + $field = new xmldb_field('deleted'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'visible'); + $dbman->add_field($table, $field); //Indexes - $index = new XMLDBIndex('visible'); - $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('visible')); - $result = $result && add_index($table, $index); + $index = new xmldb_index('visible'); + $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('visible')); + $dbman->add_index($table, $index); - $index = new XMLDBIndex('deleted'); - $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('deleted')); - $result = $result && add_index($table, $index); + $index = new xmldb_index('deleted'); + $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('deleted')); + $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) { //Adding own status for course (now it must have own) - if (!count_records('attendance_statuses', 'courseid', $c->courseid)) { - $statuses = get_records('attendance_statuses', 'courseid', 0); + if (!$DB->count_records('attendance_statuses', array( 'courseid'=> $c->courseid))) { + $statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0)); foreach($statuses as $stat) { $rec = $stat; $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)); - $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)); foreach($statuses as $stat) { - execute_sql("UPDATE {$CFG->prefix}attendance_log + execute("UPDATE {attendance_log} SET statusid = {$stat->id}, statusset = '$statlist' 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) { - execute_sql("UPDATE {$CFG->prefix}attendance_log + execute("UPDATE {attendance_log} SET timetaken = {$sess->lasttaken}, takenby = {$sess->lasttakenby} 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) { - $table = new XMLDBTable('attendance_statuses'); + if ($oldversion < 2008102409) { + $table = new xmldb_table('attendance_statuses'); - $field = new XMLDBField('status'); - $result = $result && drop_field($table, $field); + $field = new xmldb_field('status'); + $dbman->drop_field($table, $field); - $index = new XMLDBIndex('status'); - $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('status')); - $result = $result && drop_index($table, $index); + $index = new xmldb_index('status'); + $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('status')); + $dbman->drop_index($table, $index); - $table = new XMLDBTable('attendance_log'); + $table = new xmldb_table('attendance_log'); - $field = new XMLDBField('status'); - $result = $result && drop_field($table, $field); + $field = new xmldb_field('status'); + $dbman->drop_field($table, $field); - $index = new XMLDBIndex('status'); - $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('status')); - $result = $result && drop_index($table, $index); + $index = new xmldb_index('status'); + $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('status')); + $dbman->drop_index($table, $index); - $table = new XMLDBTable('attendance_sessions'); + $table = new xmldb_table('attendance_sessions'); - $field = new XMLDBField('creator'); - $result = $result && drop_field($table, $field); + $field = new xmldb_field('creator'); + $dbman->drop_field($table, $field); + upgrade_mod_savepoint(true, 2008102409, 'attforblock'); } - if ($oldversion < 2010070900 and $result) { - $table = new XMLDBTable('attendance_sessions'); + if ($oldversion < 2010070900) { + $table = new xmldb_table('attendance_sessions'); - $field = new XMLDBField('groupid'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid'); - $result = $result && add_field($table, $field); + $field = new xmldb_field('groupid'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'courseid'); + $dbman->add_field($table, $field); - $index = new XMLDBIndex('groupid'); - $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('groupid')); - $result = $result && add_index($table, $index); + $index = new xmldb_index('groupid'); + $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('groupid')); + $dbman->add_index($table, $index); + upgrade_mod_savepoint(true, 2010070900, 'attforblock'); } - return $result; + return true; } ?> diff --git a/export.php b/export.php index d2ec5ce..9c19021 100644 --- a/export.php +++ b/export.php @@ -11,15 +11,15 @@ $id = required_param('id', PARAM_INT); // $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"); } - if (! $course = get_record("course", "id", $cm->course)) { + if (! $course = $DB->get_record("course", array("id"=> $cm->course))) { 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"); } @@ -56,14 +56,15 @@ $data->tabhead[] = get_string('lastname'); $data->tabhead[] = get_string('firstname'); - $select = "courseid = {$course->id} AND sessdate >= {$course->startdate}"; + $select = "courseid = :cid AND sessdate >= :cstartdate"; if (isset($fromform->includenottaken)) { - $select .= " AND sessdate <= {$fromform->sessionenddate}"; + $select .= " AND sessdate <= :cenddate"; } else { $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) { $data->tabhead[] = userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock')); } @@ -85,7 +86,7 @@ $data->table[$i][] = $student->lastname; $data->table[$i][] = $student->firstname; 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; } else { $data->table[$i][] = '-'; diff --git a/index.php b/index.php index e9ad94b..7450aa9 100644 --- a/index.php +++ b/index.php @@ -7,7 +7,7 @@ $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'); } diff --git a/lang/en_utf8/attforblock.php b/lang/en/attforblock.php similarity index 99% rename from lang/en_utf8/attforblock.php rename to lang/en/attforblock.php index 7bda8a4..28eb00f 100644 --- a/lang/en_utf8/attforblock.php +++ b/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['olddate'] = 'Old date'; $string['period'] = 'Frequency'; -$string['remarks'] = 'Remarks'; +$string['pluginname'] = 'Attendance'; $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['resetstatuses'] = 'Reset statuses to default'; diff --git a/lang/en_utf8/help/attforblock/createmultiplesessions.html b/lang/en/help/attforblock/createmultiplesessions.html similarity index 100% rename from lang/en_utf8/help/attforblock/createmultiplesessions.html rename to lang/en/help/attforblock/createmultiplesessions.html diff --git a/lang/en_utf8/help/attforblock/createonesession.html b/lang/en/help/attforblock/createonesession.html similarity index 100% rename from lang/en_utf8/help/attforblock/createonesession.html rename to lang/en/help/attforblock/createonesession.html diff --git a/lang/en_utf8/help/attforblock/defaultstatuses.html b/lang/en/help/attforblock/defaultstatuses.html similarity index 100% rename from lang/en_utf8/help/attforblock/defaultstatuses.html rename to lang/en/help/attforblock/defaultstatuses.html diff --git a/lang/en_utf8/help/attforblock/display.html b/lang/en/help/attforblock/display.html similarity index 100% rename from lang/en_utf8/help/attforblock/display.html rename to lang/en/help/attforblock/display.html diff --git a/lang/en_utf8/help/attforblock/export.html b/lang/en/help/attforblock/export.html similarity index 100% rename from lang/en_utf8/help/attforblock/export.html rename to lang/en/help/attforblock/export.html diff --git a/lang/en_utf8/help/attforblock/hiddensessions.html b/lang/en/help/attforblock/hiddensessions.html similarity index 100% rename from lang/en_utf8/help/attforblock/hiddensessions.html rename to lang/en/help/attforblock/hiddensessions.html diff --git a/lang/en_utf8/help/attforblock/myvariables.html b/lang/en/help/attforblock/myvariables.html similarity index 100% rename from lang/en_utf8/help/attforblock/myvariables.html rename to lang/en/help/attforblock/myvariables.html diff --git a/lang/en_utf8/help/attforblock/report.html b/lang/en/help/attforblock/report.html similarity index 100% rename from lang/en_utf8/help/attforblock/report.html rename to lang/en/help/attforblock/report.html diff --git a/lang/en_utf8/help/attforblock/sessions.html b/lang/en/help/attforblock/sessions.html similarity index 100% rename from lang/en_utf8/help/attforblock/sessions.html rename to lang/en/help/attforblock/sessions.html diff --git a/lang/en_utf8/help/attforblock/sessiontypes.html b/lang/en/help/attforblock/sessiontypes.html similarity index 100% rename from lang/en_utf8/help/attforblock/sessiontypes.html rename to lang/en/help/attforblock/sessiontypes.html diff --git a/lang/en_utf8/help/attforblock/studentview.html b/lang/en/help/attforblock/studentview.html similarity index 100% rename from lang/en_utf8/help/attforblock/studentview.html rename to lang/en/help/attforblock/studentview.html diff --git a/lang/es_utf8/attforblock.php b/lang/es/attforblock.php similarity index 99% rename from lang/es_utf8/attforblock.php rename to lang/es/attforblock.php index a2b6bd9..3016381 100644 --- a/lang/es_utf8/attforblock.php +++ b/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['olddate'] = 'Fecha Anterior'; $string['period'] = 'Frecuencia'; +$string['pluginname'] = 'Asistencia'; $string['remarks'] = 'Observaciones'; $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.'; diff --git a/lang/es_utf8/help/attforblock/changesession.html b/lang/es/help/attforblock/changesession.html similarity index 100% rename from lang/es_utf8/help/attforblock/changesession.html rename to lang/es/help/attforblock/changesession.html diff --git a/lang/es_utf8/help/attforblock/createmultiplesessions.html b/lang/es/help/attforblock/createmultiplesessions.html similarity index 100% rename from lang/es_utf8/help/attforblock/createmultiplesessions.html rename to lang/es/help/attforblock/createmultiplesessions.html diff --git a/lang/es_utf8/help/attforblock/createonesession.html b/lang/es/help/attforblock/createonesession.html similarity index 100% rename from lang/es_utf8/help/attforblock/createonesession.html rename to lang/es/help/attforblock/createonesession.html diff --git a/lang/es_utf8/help/attforblock/defaultstatuses.html b/lang/es/help/attforblock/defaultstatuses.html similarity index 100% rename from lang/es_utf8/help/attforblock/defaultstatuses.html rename to lang/es/help/attforblock/defaultstatuses.html diff --git a/lang/es_utf8/help/attforblock/display.html b/lang/es/help/attforblock/display.html similarity index 100% rename from lang/es_utf8/help/attforblock/display.html rename to lang/es/help/attforblock/display.html diff --git a/lang/es_utf8/help/attforblock/export.html b/lang/es/help/attforblock/export.html similarity index 100% rename from lang/es_utf8/help/attforblock/export.html rename to lang/es/help/attforblock/export.html diff --git a/lang/es_utf8/help/attforblock/hiddensessions.html b/lang/es/help/attforblock/hiddensessions.html similarity index 100% rename from lang/es_utf8/help/attforblock/hiddensessions.html rename to lang/es/help/attforblock/hiddensessions.html diff --git a/lang/es_utf8/help/attforblock/mods.html b/lang/es/help/attforblock/mods.html similarity index 100% rename from lang/es_utf8/help/attforblock/mods.html rename to lang/es/help/attforblock/mods.html diff --git a/lang/es_utf8/help/attforblock/myvariables.html b/lang/es/help/attforblock/myvariables.html similarity index 100% rename from lang/es_utf8/help/attforblock/myvariables.html rename to lang/es/help/attforblock/myvariables.html diff --git a/lang/es_utf8/help/attforblock/report.html b/lang/es/help/attforblock/report.html similarity index 100% rename from lang/es_utf8/help/attforblock/report.html rename to lang/es/help/attforblock/report.html diff --git a/lang/es_utf8/help/attforblock/sessions.html b/lang/es/help/attforblock/sessions.html similarity index 100% rename from lang/es_utf8/help/attforblock/sessions.html rename to lang/es/help/attforblock/sessions.html diff --git a/lang/es_utf8/help/attforblock/sessiontypes.html b/lang/es/help/attforblock/sessiontypes.html similarity index 100% rename from lang/es_utf8/help/attforblock/sessiontypes.html rename to lang/es/help/attforblock/sessiontypes.html diff --git a/lang/es_utf8/help/attforblock/studentview.html b/lang/es/help/attforblock/studentview.html similarity index 100% rename from lang/es_utf8/help/attforblock/studentview.html rename to lang/es/help/attforblock/studentview.html diff --git a/lang/es_utf8/help/attforblock/updateattendance.html b/lang/es/help/attforblock/updateattendance.html similarity index 100% rename from lang/es_utf8/help/attforblock/updateattendance.html rename to lang/es/help/attforblock/updateattendance.html diff --git a/lib.php b/lib.php index e1bc832..cf04335 100644 --- a/lib.php +++ b/lib.php @@ -5,7 +5,9 @@ $attforblock_CONSTANT = 7; /// for example function attforblock_install() { - + + global $DB; + $result = true; $arr = array('P' => 2, 'A' => 0, 'L' => 1, 'E' => 1); foreach ($arr as $k => $v) { @@ -16,7 +18,7 @@ function attforblock_install() { $rec->grade = $v; $rec->visible = 1; $rec->deleted = 0; - $result = $result && insert_record('attendance_statuses', $rec); + $result = $result && $DB->insert_record('attendance_statuses', $rec); } return $result; } @@ -27,27 +29,29 @@ function attforblock_add_instance($attforblock) { /// will create a new instance and return the id number /// of the new instance. + global $DB; + $attforblock->timemodified = time(); - if ($att = get_record('attforblock', 'course', $attforblock->course)) { - $modnum = get_field('modules', 'id', 'name', 'attforblock'); - if (!get_record('course_modules', 'course', $attforblock->course, 'module', $modnum)) { - delete_records('attforblock', 'course', $attforblock->course); - $attforblock->id = insert_record('attforblock', $attforblock); + if ($att = $DB->get_record('attforblock', array('course'=> $attforblock->course))) { + $modnum = $DB->get_field('modules', 'id', array('name'=> 'attforblock')); + if (!$DB->get_record('course_modules', array('course'=> $attforblock->course, 'module'=> $modnum))) { + $DB->delete_records('attforblock', array('course'=> $attforblock->course)); + $attforblock->id = $DB->insert_record('attforblock', $attforblock); } else { return false; } } else { - $attforblock->id = insert_record('attforblock', $attforblock); + $attforblock->id = $DB->insert_record('attforblock', $attforblock); } //Copy statuses for new instance from defaults - if (!get_records('attendance_statuses', 'courseid', $attforblock->course)) { - $statuses = get_records('attendance_statuses', 'courseid', 0, 'id'); + if (!$DB->get_records('attendance_statuses', array('courseid'=> $attforblock->course))) { + $statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0), 'id'); foreach($statuses as $stat) { $rec = $stat; $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 /// will update an existing instance with new data. + global $DB; + $attforblock->timemodified = time(); $attforblock->id = $attforblock->instance; - if (! update_record('attforblock', $attforblock)) { + if (! $DB->update_record('attforblock', $attforblock)) { return false; } @@ -80,11 +86,13 @@ function attforblock_delete_instance($id) { /// this function will permanently delete the instance /// 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; } - $result = delete_records('attforblock', 'id', $id); + $result = $DB->delete_records('attforblock', array('id'=> $id)); attforblock_grade_item_delete($attforblock); @@ -92,13 +100,15 @@ function attforblock_delete_instance($id) { } 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)); - delete_records_select('attendance_log', "sessionid IN ($slist)"); - delete_records('attendance_sessions', 'courseid', $course->id); + $DB->delete_records_select('attendance_log', "sessionid IN ($slist)"); + $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 // if ($feedback) { @@ -135,23 +145,25 @@ function attforblock_reset_course_form_defaults($course) { } function attforblock_reset_userdata($data) { + global $DB; + 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)); - delete_records_select('attendance_log', "sessionid IN ($slist)"); - set_field('attendance_sessions', 'lasttaken', 0, 'courseid', $data->courseid); + $DB->delete_records_select('attendance_log', "sessionid IN ($slist)"); + $DB->set_field('attendance_sessions', 'lasttaken', 0, array('courseid' => $data->courseid)); } if (!empty($data->reset_attendance_statuses)) { - delete_records('attendance_statuses', 'courseid', $data->courseid); - $statuses = get_records('attendance_statuses', 'courseid', 0, 'id'); + $DB->delete_records('attendance_statuses', array('courseid'=> $data->courseid)); + $statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0), 'id'); foreach($statuses as $stat) { $rec = $stat; $rec->courseid = $data->courseid; - insert_record('attendance_statuses', $rec); + $DB->insert_record('attendance_statuses', $rec); } } 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 */ function attforblock_get_user_grades($attforblock, $userid=0) { - global $CFG; + global $CFG, $DB; 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"); } @@ -250,7 +262,7 @@ function attforblock_get_user_grades($attforblock, $userid=0) { * @param int $userid specific user only, 0 mean all */ 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 require_once($CFG->libdir.'/gradelib.php'); } @@ -269,17 +281,17 @@ function attforblock_update_grades($attforblock=null, $userid=0, $nullifnone=tru } else { $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"; - if ($rs = get_recordset_sql($sql)) { - while ($attforblock = rs_fetch_next_record($rs)) { + if ($rs = $DB->get_records_sql($sql)) { + foreach ($rs as $attforblock) { // if ($attforblock->grade != 0) { attforblock_update_grades($attforblock); // } else { // 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 */ function attforblock_grade_item_update($attforblock, $grades=NULL) { - global $CFG; + global $CFG, $DB; require_once('locallib.php'); @@ -303,7 +315,7 @@ function attforblock_grade_item_update($attforblock, $grades=NULL) { if (!isset($attforblock->courseid)) { $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"); } //$attforblock->grade = get_maxgrade($course); diff --git a/locallib.php b/locallib.php index 1f42c6c..aa27d36 100644 --- a/locallib.php +++ b/locallib.php @@ -48,10 +48,12 @@ function show_tabs($cm, $context, $currenttab='sessions') function get_statuses($courseid, $onlyvisible = true) { - if ($onlyvisible) { - $result = get_records_select('attendance_statuses', "courseid = $courseid AND visible = 1 AND deleted = 0", 'grade DESC'); + global $DB; + + if ($onlyvisible) { + $result = $DB->get_records_select('attendance_statuses', "courseid = ? AND visible = 1 AND deleted = 0", array( $courseid ), 'grade DESC'); } 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'); } return $result; @@ -61,10 +63,10 @@ function get_statuses($courseid, $onlyvisible = true) function get_attendance($userid, $course, $statusid=0) { - global $CFG; + global $CFG, $DB; $qry = "SELECT count(*) as cnt - FROM {$CFG->prefix}attendance_log al - JOIN {$CFG->prefix}attendance_sessions ats + FROM {attendance_log} al + JOIN {attendance_sessions} ats ON al.sessionid = ats.id WHERE ats.courseid = $course->id AND ats.sessdate >= $course->startdate @@ -73,22 +75,22 @@ function get_attendance($userid, $course, $statusid=0) $qry .= " AND al.statusid = $statusid"; } - return count_records_sql($qry); + return $DB->count_records_sql($qry); } function get_grade($userid, $course) { - global $CFG; - $logs = get_records_sql("SELECT l.id, l.statusid, l.statusset - FROM {$CFG->prefix}attendance_log l - JOIN {$CFG->prefix}attendance_sessions s + global $CFG, $DB; + $logs = $DB->get_records_sql("SELECT l.id, l.statusid, l.statusset + FROM {attendance_log} l + JOIN {attendance_sessions} s ON l.sessionid = s.id - WHERE l.studentid = $userid - AND s.courseid = $course->id - AND s.sessdate >= $course->startdate"); + WHERE l.studentid = :usid + AND s.courseid = :cid + AND s.sessdate >= :cstartdate", array('usid' => $userid, 'cid' => $course->id, 'cstartdate' => $course->startdate )); $result = 0; 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) { $result += $stat_grades[$log->statusid]; } @@ -110,17 +112,18 @@ function local_array_intersect_key($array1, $array2) { function get_maxgrade($userid, $course) { - global $CFG; - $logs = get_records_sql("SELECT l.id, l.statusid, l.statusset - FROM {$CFG->prefix}attendance_log l - JOIN {$CFG->prefix}attendance_sessions s + global $CFG, $DB; + $logs = $DB->get_records_sql("SELECT l.id, l.statusid, l.statusset + FROM {attendance_log} l + JOIN {attendance_sessions} s ON l.sessionid = s.id - WHERE l.studentid = $userid - AND s.courseid = $course->id - AND s.sessdate >= $course->startdate"); + WHERE l.studentid = :usid + AND s.courseid = :cid + AND s.sessdate >= :cstartdate", array('usid' => $userid, 'cid' => $course->id, 'cstartdate' => $course->startdate )); + $maxgrade = 0; 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) { $ids = array_flip(explode(',', $log->statusset)); // $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 { - global $CFG; - $logs = get_records_sql("SELECT l.id, l.statusid, l.statusset - FROM {$CFG->prefix}attendance_log l - JOIN {$CFG->prefix}attendance_sessions s + global $CFG, $DB; + $logs = $DB->get_records_sql("SELECT l.id, l.statusid, l.statusset + FROM {attendance_log} l + JOIN {attendance_sessions} s ON l.sessionid = s.id - WHERE l.studentid = $userid - AND s.courseid = $course->id - AND s.sessdate >= $course->startdate"); + WHERE l.studentid = :usid + AND s.courseid = :cid + AND s.sessdate >= :cstartdate", array('usid' => $userid, 'cid' => $course->id, 'cstartdate' => $course->startdate )); $result = 0; 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; 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) { - global $CFG, $COURSE, $mode, $current, $view, $id, $studentid; + global $CFG, $COURSE, $mode, $current, $view, $id, $studentid, $DB; echo '
'; if (!$printing) { @@ -268,17 +271,17 @@ function print_user_attendaces($user, $cm, $attforblock, $course = 0, $printing } } else { $stqry = "SELECT ats.id,ats.courseid - FROM {$CFG->prefix}attendance_log al - JOIN {$CFG->prefix}attendance_sessions ats + FROM {attendance_log} al + JOIN {attendance_sessions} ats ON al.sessionid = ats.id WHERE al.studentid = {$user->id} GROUP BY ats.courseid ORDER BY ats.courseid asc"; - $recs = get_records_sql_menu($stqry); + $recs = $DB->get_records_sql_menu($stqry); foreach ($recs as $id => $courseid) { echo '
'; echo '
'; - $nextcourse = get_record('course', 'id', $courseid); + $nextcourse = $DB->get_record('course', array('id'=> $courseid)); echo ''; echo '
'.$nextcourse->fullname.''; $complete = get_attendance($user->id, $nextcourse); @@ -304,19 +307,19 @@ function print_user_attendaces($user, $cm, $attforblock, $course = 0, $printing $enddate = $ret['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 { - $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 - FROM {$CFG->prefix}attendance_log al - JOIN {$CFG->prefix}attendance_sessions ats + FROM {attendance_log} al + JOIN {attendance_sessions} ats ON al.sessionid = ats.id"; $stqry .= " WHERE " . $where; $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); $i = 0; diff --git a/manage.php b/manage.php index d61952a..c1c48da 100644 --- a/manage.php +++ b/manage.php @@ -11,21 +11,21 @@ $view = optional_param('view', NULL, PARAM_ALPHA); // which page to show $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'); } - if (! $course = get_record('course', 'id', $cm->course)) { + if (! $course = $DB->get_record('course', array('id'=> $cm->course))) { 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"); } 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"); } @@ -48,10 +48,10 @@ if($from === 'block') { $today = time(); // because we compare with database, we don't need to use usertime() $sql = "SELECT id, groupid, lasttaken - FROM {$CFG->prefix}attendance_sessions - WHERE $today BETWEEN sessdate AND (sessdate + duration) + FROM {attendance_sessions} + WHERE ? BETWEEN sessdate AND (sessdate + duration) AND courseid = $course->id"; - if($atts = get_records_sql($sql)) { + if($atts = $DB->get_records_sql($sql, array($today))) { $size = count($atts); if ($size == 1) { $att = reset($atts); @@ -76,11 +76,11 @@ 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); print_heading(get_string('nosessionexists','attforblock')); - $hiddensess = count_records_select('attendance_sessions', "courseid = $course->id AND sessdate < $course->startdate"); - echo '
'.helpbutton('hiddensessions', '', 'attforblock', true, true, '', true); + $hiddensess = $DB->count_records_select('attendance_sessions', "courseid = ? AND sessdate < ?", array($course->id, $course->startdate)); + echo '
'.helpbutton('hiddensessions', '--', 'attforblock', true, true, '', true); //TODO: fix '--' echo get_string('hiddensessions', 'attforblock').': '.$hiddensess.'
'; } else { //sessions generated , display them 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) { - global $CFG, $context, $cm, $current, $view, $id; + global $CFG, $context, $cm, $current, $view, $id, $DB; $strhours = get_string('hours'); $strmins = get_string('min'); @@ -109,16 +109,16 @@ function print_sessions_list($course) { $currentgroup = $ret['currentgroup']; 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 { - $where = "courseid={$course->id} AND sessdate >= $course->startdate"; + $where = "courseid=:cid AND sessdate >= :sdate"; } 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; $table->width = '100%'; //$table->tablealign = 'center'; @@ -180,9 +180,9 @@ function print_sessions_list($course) { echo '
'; echo "
id}\">"; //&sessionid={$sessdata->id} 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 ''; echo '
'; - echo '
'.helpbutton('hiddensessions', '', 'attforblock', true, true, '', true); + echo '
'.helpbutton('hiddensessions', '--', 'attforblock', true, true, '', true); //TODO: Change '--' echo get_string('hiddensessions', 'attforblock').': '.$hiddensess.'
'.get_string('selectall').' /'. ' '.get_string('deselectall').'

'; diff --git a/report.php b/report.php index 098f260..81ed56b 100644 --- a/report.php +++ b/report.php @@ -5,7 +5,7 @@ require_once('../../config.php'); require_once($CFG->libdir.'/blocklib.php'); require_once('locallib.php'); - + define('USER_SMALL_CLASS', 20); // Below this is considered small define('USER_LARGE_CLASS', 200); // Above this is considered large define('DEFAULT_PAGE_SIZE', 20); @@ -17,20 +17,20 @@ $sort = optional_param('sort', 'lastname', PARAM_ALPHA); 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'); } - if (! $course = get_record('course', 'id', $cm->course)) { + if (! $course = $DB->get_record('course', array('id'=> $cm->course))) { 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"); } } 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"); } @@ -60,7 +60,7 @@ $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&action=add"); } else { if ($current == 0) @@ -74,13 +74,13 @@ $currentgroup = $ret['currentgroup']; 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 { - $where = "courseid={$course->id} AND sessdate >= $course->startdate"; + $where = "courseid=:cid AND sessdate >= :sdate"; } 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); } else { $students = get_users_by_capability($context, 'moodle/legacy:student', '', "u.$sort ASC", '', '', '', '', false); @@ -91,7 +91,7 @@ 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 = "".get_string('firstname').''; $lastname = "".get_string('lastname').''; @@ -112,7 +112,7 @@ $allowchange = has_capability('mod/attforblock:changeattendances', $context); $groups = groups_get_all_groups($course->id); 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) { $sessdate = "id}&grouptype={$sessdata->groupid}\">". userdate($sessdata->sessdate, get_string('strftimedm', 'attforblock').'
('.get_string('strftimehm', 'attforblock').')'). @@ -158,7 +158,7 @@ $table->data[$student->id][] = "
id}\">".fullname($student).''; $studgroups = groups_get_all_groups($COURSE->id, $student->id); 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])) { $table->data[$student->id][] = $statuses[$att->statusid]->acronym; } else { diff --git a/restorelib.php b/restorelib.php index 26320ad..5d70761 100644 --- a/restorelib.php +++ b/restorelib.php @@ -2,7 +2,7 @@ function attforblock_restore_mods($mod,$restore) { - global $CFG, $oldidarray; + global $CFG, $oldidarray, $DB; $status = true; @@ -13,7 +13,7 @@ //Now get completed xmlized object $info = $data->info; - if (count_records('attforblock', 'course', $restore->course_id)) { + if ($DB->count_records('attforblock', array('course'=> $restore->course_id))) { return false; } @@ -28,7 +28,7 @@ } //The structure is equal to the db, so insert the attforblock - $newid = insert_record ('attforblock', $attforblock); + $newid = $DB->insert_record ('attforblock', $attforblock); if ($newid) { //We have the newid, update backup_ids 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) { - global $CFG, $oldidarray; + global $CFG, $oldidarray, $DB; $status = true; @@ -94,7 +94,7 @@ $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; } @@ -105,7 +105,7 @@ function attforblock_restore_attendance_statuses ($old_attforblock_id, $new_attforblock_id,$info,$restore) { - global $CFG, $oldidarray; + global $CFG, $oldidarray, $DB; $status = true; @@ -128,7 +128,7 @@ 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; } @@ -145,7 +145,7 @@ $stat->visible = 1; $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; } @@ -153,13 +153,13 @@ } else { // ATTFORBLOCK_SETTINGS tag don't exists // 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'); $i = 0; foreach($stats as $stat) { // $stat = $stats[$i]; $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; // $i++; } @@ -171,7 +171,7 @@ function attforblock_restore_attendance_log ($old_attforblock_id, $new_attforblock_id,$info,$restore) { - global $CFG, $oldidarray; + global $CFG, $oldidarray, $DB; $status = true; @@ -182,9 +182,9 @@ @$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)); - $sessions = get_records('attendance_sessions', 'courseid', $restore->course_id); + $sessions = $DB->get_records('attendance_sessions', 'courseid', $restore->course_id); //Iterate over logs for($i = 0; $i < sizeof($logs); $i++) { @@ -230,7 +230,7 @@ // $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; diff --git a/sessions.php b/sessions.php index 79d11fb..15e112d 100644 --- a/sessions.php +++ b/sessions.php @@ -7,7 +7,7 @@ require_once('add_form.php'); require_once('update_form.php'); require_once('duration_form.php'); - + if (!function_exists('grade_update')) { //workaround for buggy PHP versions require_once($CFG->libdir.'/gradelib.php'); } @@ -16,20 +16,20 @@ $action = required_param('action', PARAM_ACTION); 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'); } - if (! $course = get_record('course', 'id', $cm->course)) { + if (! $course = $DB->get_record('course', array('id'=> $cm->course))) { 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"); } } 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"); } @@ -96,7 +96,7 @@ $rec->description = $fromform->sdescription; $rec->timemodified = $now; 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&action=add"); } else { foreach ($fromform->groups as $groupid) { @@ -156,7 +156,7 @@ redirect('manage.php?id='.$id); } 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'); } @@ -174,7 +174,7 @@ $att->duration = $fromform->durtime['hours']*HOURSECS + $fromform->durtime['minutes']*MINSECS; $att->description = $fromform->sdescription; $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); //notice(get_string('sessionupdated','attforblock'), 'manage.php?id='.$id); redirect('manage.php?id='.$id, get_string('sessionupdated','attforblock'), 3); @@ -193,15 +193,15 @@ $sessionid = required_param('sessionid'); $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'); } if (isset($confirm)) { - delete_records('attendance_log', 'sessionid', $sessionid); - delete_records('attendance_sessions', 'id', $sessionid); + $DB->delete_records('attendance_log', array('sessionid'=> $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); - $attforblockrecord = get_record('attforblock', 'course', $course->id); + $attforblockrecord = $DB->get_record('attforblock', array('course'=> $course->id)); attforblock_update_grades($attforblockrecord); redirect('manage.php?id='.$id, get_string('sessiondeleted','attforblock'), 3); } @@ -219,18 +219,18 @@ if (isset($confirm)) { $sessionid = required_param('sessionid'); $ids = implode(',', explode('_', $sessionid)); - delete_records_select('attendance_log', "sessionid IN ($ids)"); - delete_records_select('attendance_sessions', "id IN ($ids)"); + $DB->delete_records_select('attendance_log', "sessionid 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); - $attforblockrecord = get_record('attforblock','course',$course->id); + $attforblockrecord = $DB->get_record('attforblock',array('course'=> $course->id)); attforblock_update_grades($attforblockrecord); redirect('manage.php?id='.$id, get_string('sessiondeleted','attforblock'), 3); } $fromform = data_submitted(); $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); $message = '
'; @@ -262,13 +262,13 @@ if ($fromform = $mform_duration->get_data()) { $now = time(); $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'); } foreach ($sessions as $sess) { $sess->duration = $fromform->durtime['hours']*HOURSECS + $fromform->durtime['minutes']*MINSECS; $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); redirect('manage.php?id='.$id, get_string('sessionupdated','attforblock'), 3); diff --git a/update_form.php b/update_form.php index 7bc8d6b..6ba9e2b 100644 --- a/update_form.php +++ b/update_form.php @@ -6,7 +6,7 @@ class mod_attforblock_update_form extends moodleform { function definition() { - global $CFG; + global $CFG, $DB; $mform =& $this->_form; $course = $this->_customdata['course']; @@ -16,7 +16,7 @@ class mod_attforblock_update_form extends moodleform { $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'); } $mform->addElement('header', 'general', get_string('changesession','attforblock')); diff --git a/view.php b/view.php index b16bb03..02e3ba1 100644 --- a/view.php +++ b/view.php @@ -9,21 +9,21 @@ $id = optional_param('id', -1, PARAM_INT); // Course Module ID, or // $a = optional_param('a', -1, PARAM_INT); // attforblock ID $studentid = optional_param('student', 0, PARAM_INT); - $printing = optional_param('printing'); - $mode = optional_param('mode', 'thiscourse'); + $printing = optional_param('printing', 0, PARAM_INT); + $mode = optional_param('mode', 'thiscourse', PARAM_ALPHA); $view = optional_param('view', NULL, PARAM_ALPHA); // which page to show $current = optional_param('current', 0, PARAM_INT); 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"); } - if (! $course = get_record("course", "id", $cm->course)) { + if (! $course = $DB->get_record("course", array("id"=> $cm->course))) { 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"); } @@ -55,7 +55,7 @@ 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"); } @@ -69,7 +69,7 @@ $student = false; if ($studentid) { 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"); } }