Browse Source

Removed old (1.9) files

MOODLE_23_STABLE
Artem Andreev 13 years ago
parent
commit
4fff322892
  1. 322
      _attendances.php
  2. 180
      _attsettings.php
  3. 206
      _backuplib.php
  4. 188
      _export.php
  5. 555
      _locallib.php
  6. 212
      _manage.php
  7. 201
      _report.php
  8. 264
      _restorelib.php
  9. 286
      _sessions.php
  10. 66
      _styles.php
  11. 125
      _view.php

322
_attendances.php

@ -1,322 +0,0 @@
<?PHP // $Id: attendances.php,v 1.2.2.5 2009/02/23 19:22:40 dlnsk Exp $
// Lists all the sessions for a course
require_once('../../config.php');
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');
}
$id = required_param('id', PARAM_INT);
$sessionid = required_param('sessionid', PARAM_INT);
$grouptype = required_param('grouptype', PARAM_INT);
$group = optional_param('group', -1, PARAM_INT); // Group to show
$sort = optional_param('sort','lastname', PARAM_ALPHA);
$copyfrom = optional_param('copyfrom', -1, PARAM_INT);
if (! $cm = $DB->get_record('course_modules', array('id'=>$id))) {
error('Course Module ID was incorrect');
}
if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
error('Course is misconfigured');
}
require_login($course->id);
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect");
}
if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course");
}
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
$statlist = implode(',', array_keys( (array)get_statuses($attforblock->id) ));
if ($form = data_submitted()) {
$students = array(); // stores students ids
$formarr = (array)$form;
$i = 0;
$now = time();
foreach($formarr as $key => $value) {
if(substr($key,0,7) == 'student' && $value !== '') {
$students[$i] = new Object();
$sid = substr($key,7); // gets studeent id from radiobutton name
$students[$i]->studentid = $sid;
$students[$i]->statusid = $value;
$students[$i]->statusset = $statlist;
$students[$i]->remarks = array_key_exists('remarks'.$sid, $formarr) ? $formarr['remarks'.$sid] : '';
$students[$i]->sessionid = $sessionid;
$students[$i]->timetaken = $now;
$students[$i]->takenby = $USER->id;
$i++;
}
}
$attforblockrecord = $DB->get_record('attforblock', array('attendanceid' => $attforblock->id));
foreach($students as $student) {
if ($log = $DB->get_record('attendance_log', array('sessionid' => $sessionid, 'studentid'=> $student->studentid))) {
$student->id = $log->id; // this is id of log
$DB->update_record('attendance_log', $student);
} else {
$DB->insert_record('attendance_log', $student);
}
}
$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);
redirect('manage.php?id='.$id, get_string('attendancesuccess','attforblock'), 3);
exit();
}
/// Print headers
$url = new moodle_url('/mod/attforblock/manage.php', array('id'=> $id, 'sessionid'=> $sessionid, 'grouptype' => $grouptype, 'group' => $group, 'sort' => $sort, 'copyfrom' => $copyfrom));
$PAGE->set_url($url);
$PAGE->set_title($course->shortname. ": ".$attforblock->name . ' - ' .get_string('update','attforblock'));
$PAGE->set_heading($course->fullname);
$PAGE->set_focuscontrol('');
$PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id,'attforblock'));
$PAGE->navbar->add($attforblock->name);
echo $OUTPUT->header();
/*$navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activity');
$navlinks[] = array('name' => get_string('update', 'attforblock'), 'link' => null, 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: ".$attforblock->name.' - ' .get_string('update','attforblock'), $course->fullname,
$navigation, "", "", true, "&nbsp;", navmenu($course));*/
//check for hack
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 = $DB->count_records('attendance_log', array('sessionid'=> $sessionid));
if ($update) {
require_capability('mod/attforblock:changeattendances', $context);
print_heading(get_string('update','attforblock').' ' .get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname.$help);
} else {
require_capability('mod/attforblock:takeattendances', $context);
echo $OUTPUT->heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname.$help);
}
/// find out current groups mode
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
// get the viewmode & grid columns
$attforblockrecord = $DB->get_record('attforblock', array('id'=> $cm->instance));//'course', $course->id);'course', $course->id);
$view = optional_param('view', -1, PARAM_INT);
if ($view != -1) {
set_user_preference("attforblock_viewmode", $view);
}
else {
$view = get_user_preferences("attforblock_viewmode", SORTEDLISTVIEW);
}
$gridcols = optional_param('gridcols', -1, PARAM_INT);
if ($gridcols != -1) {
set_user_preference("attforblock_gridcolumns", $gridcols);
}
else {
$gridcols = get_user_preferences("attforblock_gridcolumns",5);
}
echo '<table class="controls" cellspacing="0"><tr>'; //echo '<center>';
$options = array (SORTEDLISTVIEW => get_string('sortedlist','attforblock'), SORTEDGRIDVIEW => get_string('sortedgrid','attforblock'));
$dataurl = "/mod/attforblock/attendances.php?id=$id&grouptype=$grouptype&gridcols=$gridcols";
if ($group!=-1) {
$dataurl = $dataurl . "&group=$group";
}
$today = usergetmidnight($sessdata->sessdate);
$select = "sessdate>=? AND sessdate<? AND attendanceid=?";
$tomorrow = $today + 86400;
$todaysessions = $DB->get_records_select('attendance_sessions', $select, array($today, $tomorrow, $cm->instance), 'sessdate ASC');
$optionssesions = array();
if (count($todaysessions)>1) {
echo '<td class="right"><label for="fastsessionmenu_jump">'. get_string('jumpto','attforblock') . "&nbsp;</label>";
foreach($todaysessions as $sessdatarow) {
$descr = userdate($sessdatarow->sessdate, get_string('strftimehm', 'attforblock')) . "-" . userdate($sessdatarow->sessdate+$sessdatarow->duration, get_string('strftimehm', 'attforblock'));
if ($sessdatarow->description) {
$descr = $sessdatarow->description . ' ('.$descr.')';
}
$optionssessions[$sessdatarow->id] = $descr;
}
//popup_form("$dataurl&sessionid=", $optionssessions, 'fastsessionmenu', $sessionid, '');
echo $OUTPUT->single_select(new moodle_url('/mod/attforblock/attendances.php', array('id'=> $id, 'grouptype' => $grouptype, 'group' => $group, 'sort' => $sort)),'sessionid',$optionssessions, $sessionid);
echo "<td/><tr/><tr>";
}
$dataurl .= "&sessionid=$sessionid";
echo '<td class="right"><label for="viewmenu_jump">'. get_string('viewmode','attforblock') . "&nbsp;</label>";
//popup_form("$dataurl&view=", $options, 'viewmenu', $view, '');
echo $OUTPUT->single_select(new moodle_url('/mod/attforblock/attendances.php', array('id'=> $id, 'sessionid'=>$sessionid, 'grouptype' => $grouptype, 'group' => $group, 'sort' => $sort)),'view',$options, $view);
if ($view == SORTEDGRIDVIEW) {
$options = array (1 => '1 '.get_string('column','attforblock'),'2 '.get_string('columns','attforblock'),'3 '.get_string('columns','attforblock'),
'4 '.get_string('columns','attforblock'),'5 '.get_string('columns','attforblock'),'6 '.get_string('columns','attforblock'),
'7 '.get_string('columns','attforblock'),'8 '.get_string('columns','attforblock'),'9 '.get_string('columns','attforblock'),
'10 '.get_string('columns','attforblock'));
$dataurl .= "&view=$view";
//popup_form("$dataurl&gridcols=", $options, 'colsmenu', $gridcols, '');
echo $OUTPUT->single_select(new moodle_url('/mod/attforblock/attendances.php', array('id'=> $id, 'sessionid'=>$sessionid, 'view'=>$view, 'grouptype' => $grouptype, 'group' => $group, 'sort' => $sort)),'gridcols',$options, $gridcols);
}
echo '</td></tr></table>';//</center>';
if ($grouptype === 0) {
if ($currentgroup) {
$students = get_users_by_capability($context, 'mod/attforblock:canbelisted', '', "u.$sort ASC", '', '', $currentgroup, '', false);
} else {
$students = get_users_by_capability($context, 'mod/attforblock:canbelisted', '', "u.$sort ASC", '', '', '', '', false);
}
} else {
$students = get_users_by_capability($context, 'mod/attforblock:canbelisted', '', "u.$sort ASC", '', '', $grouptype, '', false);
}
$sort = $sort == 'firstname' ? 'firstname' : 'lastname';
/// Now we need a menu for separategroups as well!
if ($grouptype === 0 &&
($groupmode == VISIBLEGROUPS ||
($groupmode && has_capability('moodle/site:accessallgroups', $context)))) {
groups_print_activity_menu($cm, "attendances.php?id=$id&amp;sessionid=$sessionid&amp;grouptype=$grouptype&amp;sort=$sort");
}
$table->data[][] = '<b>'.get_string('sessiondate','attforblock').': '.userdate($sessdata->sessdate, get_string('strftimedate').', '.get_string('strftimehm', 'attforblock')).
', "'.($sessdata->description ? $sessdata->description : get_string('nodescription', 'attforblock')).'"</b>';
print_table($table);
$statuses = get_statuses($attforblock->id);
$i = 3;
$tabhead = array();
foreach($statuses as $st) {
switch($view) {
case SORTEDLISTVIEW:
$tabhead[] = "<a href=\"javascript:select_all_in('TD', 'cell c{$i}', null);\"><u>$st->acronym</u></a>";
break;
case SORTEDGRIDVIEW:
$tabhead[] = "<a href=\"javascript:select_all_in('INPUT', '". $st->acronym . "', null);\"><u>$st->acronym</u></a>";
break;
}
$i++;
}
if ($view == SORTEDLISTVIEW) {
$tabhead[] = get_string('remarks','attforblock');
}
$firstname = "<a href=\"attendances.php?id=$id&amp;sessionid=$sessionid&amp;sort=firstname\">".get_string('firstname').'</a>';
$lastname = "<a href=\"attendances.php?id=$id&amp;sessionid=$sessionid&amp;sort=lastname\">".get_string('lastname').'</a>';
if ($CFG->fullnamedisplay == 'lastname firstname') { // for better view (dlnsk)
$fullnamehead = "$lastname / $firstname";
} else {
$fullnamehead = "$firstname / $lastname";
}
if ($students) {
unset($table);
switch($view) {
case SORTEDLISTVIEW: // sorted list
$table->width = '0%';
$table->head[] = '#';
$table->align[] = 'center';
$table->size[] = '20px';
$table->head[] = '';
$table->align[] = '';
$table->size[] = '1px';
$table->head[] = $fullnamehead;
$table->align[] = 'left';
$table->size[] = '';
$table->wrap[2] = 'nowrap';
foreach ($tabhead as $hd) {
$table->head[] = $hd;
$table->align[] = 'center';
$table->size[] = '20px';
}
$i = 0;
foreach($students as $student) {
$i++;
$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][] = 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>';
foreach($statuses as $st) {
$copyid = ($copyfrom == "-1") ? $sessionid : $copyfrom;
$att = $DB->get_record('attendance_log', array('sessionid'=> $copyid, 'studentid'=> $student->id));
$currentstatusid = $att===false ? -1 : $att->statusid;
@$table->data[$student->id][] = '<input name="student'.$student->id.'" type="radio" value="'.$st->id.'" '.($st->id == $currentstatusid ? 'checked' : '').'>';
}
$table->data[$student->id][] = '<input type="text" name="remarks'.$student->id.'" size="" value="'.($att ? $att->remarks : '').'">';
}
break;
case SORTEDGRIDVIEW: // sorted grid
$table->width = '0%';
$data = '';
foreach ($tabhead as $hd) {
$data = $data . $hd . '&nbsp';
}
print_heading($data,'center');
$i = 0;
// sanity check
$gridcols = $gridcols < 1 ? 1 : $gridcols;
for ($i=0; $i<$gridcols; $i++) {
$table->head[] = '&nbsp;';
$table->align[] = 'center';
$table->size[] = '110px';
}
$i = 0;
foreach($students as $student) {
$i++;
$copyid = ($copyfrom == "-1") ? $sessionid : $copyfrom;
$att = $DB->get_record('attendance_log', array('sessionid'=> $copyid, 'studentid'=> $student->id));
$currentstatusid = $att===false ? -1 : $att->statusid;
$data = "<span class='userinfobox' style='font-size:80%;border:none'>" . print_user_picture($student, $course->id, $student->picture, true, true, '', fullname($student)) . "<br/>" . fullname($student) . "<br/></span>";//, $returnstring=false, $link=true, $target='');
foreach($statuses as $st) {
$data = $data . '<nobr><input name="student'.$student->id.'" type="radio" class="' . $st->acronym . '" value="'.$st->id.'" '.($st->id == $currentstatusid ? 'checked' : '').'>&nbsp;' . $st->acronym . "</nobr> ";
}
$table->data[($i-1) / ($gridcols)][] = $data;
}
break;
}
echo '<form name="takeattendance" method="post" action="attendances.php">';
print_table($table);
echo '<input type="hidden" name="id" value="'.$id.'">';
echo '<input type="hidden" name="sessionid" value="'.$sessionid.'">';
echo '<input type="hidden" name="grouptype" value="'.$grouptype.'">';
echo '<input type="hidden" name="formfrom" value="editsessvals">';
echo '<center><input type="submit" name="esv" value="'.get_string('save','attforblock').'"></center>';
echo '</form>';
if (count($todaysessions)>1) {
echo '<br/><table class="controls" cellspacing="0"><tr><td class="center">';
echo '<label for="copysessionmenu_jump">'. get_string('copyfrom','attforblock') . "&nbsp;</label>";
//popup_form("$dataurl&copyfrom=", $optionssessions, 'copysessionmenu', $sessionid, '');
echo $OUTPUT->single_select(new moodle_url('/mod/attforblock/attendances.php', array('id'=> $id, 'sessionid'=>$sessionid, 'grouptype' => $grouptype, 'group' => $group, 'sort' => $sort)),'copyfrom',$optionssessions, $sessionid);
echo '</td></tr></table>';
}
} else {
print_heading(get_string('nothingtodisplay'), 'center');
}
echo get_string('status','attforblock').':<br />';
foreach($statuses as $st) {
echo $st->acronym.' - '.$st->description.'<br />';
}
$OUTPUT->footer($course);
?>

180
_attsettings.php

@ -1,180 +0,0 @@
<?PHP
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 = $DB->get_record('course_modules', array('id'=> $id))) {
error('Course Module ID was incorrect');
}
if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
error('Course is misconfigured');
}
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect");
}
}
//$attforblockrecord = get_record('attforblock','course',$course->id);
if (! $attforblockrecord = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect");
}
require_login($course->id);
if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course");
}
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_capability('mod/attforblock:manageattendances', $context);
/// Print headers
$navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activity');
$navlinks[] = array('name' => get_string('settings', 'attforblock'), 'link' => null, 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: ".$attforblock->name.' - '.get_string('settings','attforblock'), $course->fullname,
$navigation, "", "", true, "&nbsp;", navmenu($course));
if (!empty($action)) {
switch ($action) {
case 'delete':
if (!$rec = $DB->get_record('attendance_statuses', array('attendanceid'=> $$attforblockrecord->id, 'id'=> $stid))) {
print_error('notfoundstatus', 'attforblock', "attsettings.php?id=$id");
}
if ($DB->count_records('attendance_log', array('statusid'=> $stid))) {
print_error('cantdeletestatus', 'attforblock', "attsettings.php?id=$id");
}
$confirm = optional_param('confirm');
if (isset($confirm)) {
$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);
}
print_heading(get_string('deletingstatus','attforblock').' :: ' .$course->fullname);
notice_yesno(get_string('deletecheckfull', '', get_string('variable', 'attforblock')).
'<br /><br />'.$rec->acronym.': '.
($rec->description ? $rec->description : get_string('nodescription', 'attforblock')),
"attsettings.php?id=$id&amp;st=$stid&amp;action=delete&amp;confirm=1", $_SERVER['HTTP_REFERER']);
exit;
case 'show':
$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 (!$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");
}
break;
default: //Adding new status
$newacronym = optional_param('newacronym', '', PARAM_MULTILANG);
$newdescription = optional_param('newdescription', '', PARAM_MULTILANG);
$newgrade = optional_param('newgrade', 0, PARAM_INT);
if (!empty($newacronym) && !empty($newdescription)) {
unset($rec);
$rec->courseid = $course->id;
$rec->attendanceid = $attforblock->id;
$rec->acronym = $newacronym;
$rec->description = $newdescription;
$rec->grade = $newgrade;
$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");
}
break;
}
}
show_tabs($cm, $context, 'settings');
if ($submitsettings) {
config_save(); //////////////////////////////
notice(get_string('variablesupdated','attforblock'), 'attsettings.php?id='.$id);
}
$i = 1;
$table->width = '100%';
//$table->tablealign = 'center';
$table->head = array('#',
get_string('acronym','attforblock'),
get_string('description'),
get_string('grade'),
get_string('action'));
$table->align = array('center', 'center', 'center', 'center', 'center', 'center');
//$table->size = array('1px', '1px', '*', '1px', '1px', '1px');
$statuses = get_statuses($attforblockrecord->id, false);
$deltitle = get_string('delete');
foreach($statuses as $st)
{
$table->data[$i][] = $i;
// $table->data[$i][] = $st->status;
$table->data[$i][] = '<input type="text" name="acronym['.$st->id.']" size="2" maxlength="2" value="'.$st->acronym.'" />';
$table->data[$i][] = '<input type="text" name="description['.$st->id.']" size="30" maxlength="30" value="'.$st->description.'" />';
$table->data[$i][] = '<input type="text" name="grade['.$st->id.']" size="4" maxlength="4" value="'.$st->grade.'" />';
$action = $st->visible ? 'hide' : 'show';
$titlevis = get_string($action);
$deleteact = '';
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\">".
"<img src=\"{$CFG->pixpath}/t/delete.gif\" alt=\"$deltitle\" /></a>&nbsp;";
}
$table->data[$i][] = "<a title=\"$titlevis\" href=\"attsettings.php?id=$cm->id&amp;st={$st->id}&amp;action=$action\">".
"<img src=\"{$CFG->pixpath}/t/{$action}.gif\" alt=\"$titlevis\" /></a>&nbsp;".
$deleteact;
$i++;
}
$new_row = array('*',
'<input type="text" name="newacronym" size="2" maxlength="2" value="" />',
'<input type="text" name="newdescription" size="30" maxlength="30" value="" />',
'<input type="text" name="newgrade" size="4" maxlength="4" value="" />',
'<input type="submit" name="action" value="'.get_string('add', 'attforblock').'">'
);
$table->data[$i] = $new_row;
echo '<div align="center"><div class="generalbox boxwidthwide">';
echo '<form aname="gsess" method="post" action="attsettings.php" onSubmit="return validateSession()">';
echo '<h1 class="main help">'.get_string('myvariables','attforblock').helpbutton ('myvariables', get_string('myvariables','attforblock'), 'attforblock', true, false, '', true).'</h1>';
print_table($table);
echo '<input type="hidden" name="id" value="'.$id.'"><br />';
echo '<input type="submit" name="submitsettings" value="'.get_string("update",'attforblock').'">';
echo '</form></div></div>';
print_footer($course);
function config_save()
{
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 = $DB->get_record('attendance_statuses', array('id'=> $id));
$rec->acronym = $acronym[$id];
$rec->description = $description[$id];
$rec->grade = $grade[$id];
$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);
}
?>

206
_backuplib.php

@ -1,206 +0,0 @@
<?php
function attforblock_check_backup_mods($course, $user_data=false, $backup_unique_code=null, $instances=null) {
if (!empty($instances) && is_array($instances) && count($instances)) {
$info = array();
foreach ($instances as $id => $instance) {
$info += attforblock_check_backup_mods_instances($course, $instance, $backup_unique_code);
}
return $info;
}
return $info;
}
function attforblock_check_backup_mods_instances($course, $instance, $backup_unique_code) {
global $DB;
//First the course data
$info[$instance->id.'0'][0] = '<b>'.$instance->name.'</b>';
$info[$instance->id.'0'][1] = '';
$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);
//Now, if requested, the user_data
if (!empty($instance->userdata)) {
$info[$instance->id.'2'][0] = get_string('attrecords', 'attforblock');
$sesslist = implode(',', array_keys($sessions));
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;
}
}
return $info;
}
function attforblock_backup_mods($bf, $preferences) {
global $CFG, $DB;
$status = true;
//Iterate over attforblock table
$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)) {
$status = attforblock_backup_one_mod($bf, $preferences, $attforblock);
}
}
}
return $status;
}
function attforblock_backup_one_mod($bf, $preferences, $attforblock) {
global $CFG, $DB;
if (is_numeric($attforblock)) {
$attforblock = $DB->get_record('attforblock', array('id'=> $attforblock));
}
$status = true;
//Start mod
fwrite ($bf,start_tag('MOD',3,true));
//Print attforblock data
fwrite ($bf,full_tag('ID',4,false,$attforblock->id));
fwrite ($bf,full_tag('MODTYPE',4,false,'attforblock'));
fwrite ($bf,full_tag('COURSE',4,false,$attforblock->course));
fwrite ($bf,full_tag('NAME',4,false,$attforblock->name));
fwrite ($bf,full_tag('GRADE',4,false,$attforblock->grade));
attforblock_backup_attendance_statuses ($bf,$preferences,$attforblock);
attforblock_backup_attendance_sessions ($bf,$preferences,$attforblock);
if (backup_userdata_selected($preferences, 'attforblock', $attforblock->id)) {
attforblock_backup_attendance_log ($bf,$preferences,$attforblock);
}
//End mod
$status =fwrite ($bf,end_tag('MOD',3,true));
return $status;
}
function attforblock_backup_attendance_sessions ($bf,$preferences,$attforblock) {
global $CFG, $DB;
$status = true;
$datas = $DB->get_records('attendance_sessions', array('attendanceid'=> $attforblock->id));
if ($datas) {
//Write start tag
$status =fwrite ($bf,start_tag('SESSIONS',4,true));
//Iterate over each session
foreach ($datas as $item) {
//Start session
$status =fwrite ($bf,start_tag('SESSION',5,true));
//Print contents
fwrite ($bf,full_tag('ID',6,false,$item->id));
fwrite ($bf,full_tag('COURSEID',6,false,$item->courseid));
fwrite ($bf,full_tag('GROUPID',6,false,$item->groupid));
fwrite ($bf,full_tag('SESSDATE',6,false,$item->sessdate));
fwrite ($bf,full_tag('DURATION',6,false,$item->duration));
fwrite ($bf,full_tag('TIMEMODIFIED',6,false,$item->timemodified));
fwrite ($bf,full_tag('DESCRIPTION',6,false,$item->description));
if (backup_userdata_selected($preferences, 'attforblock', $attforblock->id)) {
fwrite ($bf,full_tag('LASTTAKEN',6,false,$item->lasttaken));
fwrite ($bf,full_tag('LASTTAKENBY',6,false,$item->lasttakenby));
} else {
fwrite ($bf,full_tag('LASTTAKEN',6,false,0));
fwrite ($bf,full_tag('LASTTAKENBY',6,false,0));
}
//End submission
$status =fwrite ($bf,end_tag('SESSION',5,true));
}
//Write end tag
$status =fwrite ($bf,end_tag('SESSIONS',4,true));
}
return $status;
}
function attforblock_backup_attendance_statuses ($bf,$preferences,$attforblock) {
global $CFG, $DB;
$status = true;
$datas = $DB->get_records('attendance_statuses', array('courseid'=> $attforblock->course, 'attendanceid' => $attforblock->id));
//If there is levels
if ($datas) {
//Write start tag
$status =fwrite ($bf,start_tag('STATUSES',4,true));
//Iterate over each status
foreach ($datas as $item) {
//Start status
$status =fwrite ($bf,start_tag('STATUS',5,true));
//Print status contents
fwrite ($bf,full_tag('ID',6,false,$item->id));
fwrite ($bf,full_tag('COURSEID',6,false,$item->courseid));
fwrite ($bf,full_tag('ACRONYM',6,false,$item->acronym));
fwrite ($bf,full_tag('DESCRIPTION',6,false,$item->description));
fwrite ($bf,full_tag('GRADE',6,false,$item->grade));
fwrite ($bf,full_tag('VISIBLE',6,false,$item->visible));
fwrite ($bf,full_tag('DELETED',6,false,$item->deleted));
//End submission
$status =fwrite ($bf,end_tag('STATUS',5,true));
}
//Write end tag
$status =fwrite ($bf,end_tag('STATUSES',4,true));
}
return $status;
}
function attforblock_backup_attendance_log ($bf,$preferences,$attforblock) {
global $CFG, $DB;
$status = true;
$sessions = $DB->get_records_menu('attendance_sessions', array('courseid'=> $attforblock->course, 'attendanceid' => $attforblock->id));
$sesslist = implode(',', array_keys($sessions));
$datas = $DB->get_records_list('attendance_log', array('sessionid'=> $sesslist));
//If there is levels
if ($datas) {
//Write start tag
$status = fwrite ($bf,start_tag('LOGS',4,true));
//Iterate over each log
foreach ($datas as $item) {
//Start log
$status = fwrite ($bf,start_tag('LOG',5,true));
//Print log contents
fwrite ($bf,full_tag('ID',6,false,$item->id));
fwrite ($bf,full_tag('SESSIONID',6,false,$item->sessionid));
fwrite ($bf,full_tag('STUDENTID',6,false,$item->studentid));
fwrite ($bf,full_tag('STATUSID',6,false,$item->statusid));
fwrite ($bf,full_tag('TIMETAKEN',6,false,$item->timetaken));
fwrite ($bf,full_tag('TAKENBY',6,false,$item->takenby));
fwrite ($bf,full_tag('STATUSSET',6,false,$item->statusset));
fwrite ($bf,full_tag('REMARKS',6,false,$item->remarks));
//End submission
$status = fwrite ($bf,end_tag('LOG',5,true));
}
//Write end tag
$status = fwrite ($bf,end_tag('LOGS',4,true));
}
return $status;
}
?>

188
_export.php

@ -1,188 +0,0 @@
<?PHP // $Id: export.php,v 1.1.2.2 2009/02/23 19:22:40 dlnsk Exp $
// Lists all the sessions for a course
require_once('../../config.php');
require_once('locallib.php');
// require_once('grouplib.php');
require_once('export_form.php');
$id = required_param('id', PARAM_INT);
// $format = optional_param('format', '', PARAM_ACTION);
if (! $cm = $DB->get_record("course_modules", array("id"=> $id))) {
error("Course Module ID was incorrect");
}
if (! $course = $DB->get_record("course", array("id"=> $cm->course))) {
error("Course is misconfigured");
}
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect");
}
require_login($course->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/attforblock:export', $context);
$mform_export = new mod_attforblock_export_form('export.php', array('course'=>$course, 'cm'=>$cm, 'modcontext'=>$context));
if ($fromform = $mform_export->get_data()) {
$group = groups_get_group($fromform->group);
if ($group) {
$students = get_users_by_capability($context, 'moodle/legacy:student', '', 'u.lastname ASC', '', '', $group->id, '', false);
} else {
$students = get_users_by_capability($context, 'moodle/legacy:student', '', 'u.lastname ASC', '', '', '', '', false);
}
if ($students) {
$filename = clean_filename($course->shortname.'_Attendances_'.userdate(time(), '%Y%m%d-%H%M'));
$data->tabhead = array();
// $data->sheettitle = $course->fullname.' - ';
// $data->sheettitle .= $group ? $group->name : get_string('allparticipants');
$data->course = $course->fullname;
$data->group = $group ? $group->name : get_string('allparticipants');
if (isset($fromform->ident['id'])) {
$data->tabhead[] = get_string('studentid','attforblock');
}
if (isset($fromform->ident['uname'])) {
$data->tabhead[] = get_string('username');
}
$data->tabhead[] = get_string('lastname');
$data->tabhead[] = get_string('firstname');
$select = "courseid = :cid AND sessdate >= :cstartdate";
if (isset($fromform->includenottaken)) {
$select .= " AND sessdate <= :cenddate";
} else {
$select .= " AND lasttaken != 0";
}
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'));
}
} else {
error('Sessions not found!', 'report.php?id='.$id);
}
$data->tabhead[] = '%';
$i = 0;
$data->table = array();
$statuses = get_statuses($attforblock->id);
foreach($students as $student) {
if (isset($fromform->ident['id'])) {
$data->table[$i][] = $student->id;
}
if (isset($fromform->ident['uname'])) {
$data->table[$i][] = $student->username;
}
$data->table[$i][] = $student->lastname;
$data->table[$i][] = $student->firstname;
foreach ($sessions as $sess) {
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][] = '-';
}
}
$data->table[$i][] = get_percent($student->id, $course, $attforblock).'%';
$i++;
}
if ($fromform->format === 'text') {
ExportToCSV($data, $filename);
} else {
ExportToTableEd($data, $filename, $fromform->format);
}
exit;
} else {
error('Students not found!', 'report.php?id='.$id);
}
} else {
/// Print headers
$navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activity');
$navlinks[] = array('name' => get_string('export', 'quiz'), 'link' => null, 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: ".$attforblock->name.' - ' .get_string('export', 'quiz'), $course->fullname,
$navigation, "", "", true, "&nbsp;", navmenu($course));
show_tabs($cm, $context, 'export');
$mform_export->display();
}
print_footer($course);
/////////////////////////////////////////////////////////////////////////////////
function ExportToTableEd($data, $filename, $format) {
global $CFG;
if ($format === 'excel') {
require_once("$CFG->libdir/excellib.class.php");
$filename .= ".xls";
$workbook = new MoodleExcelWorkbook("-");
} else {
require_once("$CFG->libdir/odslib.class.php");
$filename .= ".ods";
$workbook = new MoodleODSWorkbook("-");
}
/// Sending HTTP headers
$workbook->send($filename);
/// Creating the first worksheet
$myxls =& $workbook->add_worksheet('Attendances');
/// format types
$formatbc =& $workbook->add_format();
$formatbc->set_bold(1);
$myxls->write(0, 0, get_string('course'), $formatbc);
$myxls->write(0, 1, $data->course);
$myxls->write(1, 0, get_string('group'), $formatbc);
$myxls->write(1, 1, $data->group);
$i = 3;
$j = 0;
foreach ($data->tabhead as $cell) {
$myxls->write($i, $j++, $cell, $formatbc);
}
$i++;
$j = 0;
foreach ($data->table as $row) {
foreach ($row as $cell) {
$myxls->write($i, $j++, $cell);
// if (is_numeric($cell)) {
// $myxls->write_number($i, $j++, $cell);
// } else {
// $myxls->write_string($i, $j++, $cell);
// }
}
$i++;
$j = 0;
}
$workbook->close();
}
function ExportToCSV($data, $filename) {
$filename .= ".txt";
header("Content-Type: application/download\n");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Expires: 0");
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Pragma: public");
echo get_string('course')."\t".$data->course."\n";
echo get_string('group')."\t".$data->group."\n\n";
echo implode("\t", $data->tabhead)."\n";
foreach ($data->table as $row) {
echo implode("\t", $row)."\n";
}
}
?>

555
_locallib.php

@ -1,555 +0,0 @@
<?php
global $CFG;
require_once($CFG->libdir.'/gradelib.php');
define('ONE_DAY', 86400); // Seconds in one day
define('ONE_WEEK', 604800); // Seconds in one week
define('COMMONSESSION', 0);
define('GROUPSESSION', 1);
define('WITHOUT_SELECTOR', 0);
define('GROUP_SELECTOR', 1);
define('SESSION_TYPE_SELECTOR', 2);
define('SORTEDLISTVIEW', 0);
define('SORTEDGRIDVIEW', 1);
function show_tabs($cm, $context, $currenttab='sessions')
{
$toprow = array();
if (has_capability('mod/attforblock:manageattendances', $context) or
has_capability('mod/attforblock:takeattendances', $context) or
has_capability('mod/attforblock:changeattendances', $context)) {
$toprow[] = new tabobject('sessions', 'manage.php?id='.$cm->id,
get_string('sessions','attforblock'));
}
if (has_capability('mod/attforblock:manageattendances', $context)) {
$toprow[] = new tabobject('add', "sessions.php?id=$cm->id&amp;action=add",
get_string('add','attforblock'));
}
if (has_capability('mod/attforblock:viewreports', $context)) {
$toprow[] = new tabobject('report', 'report.php?id='.$cm->id,
get_string('report','attforblock'));
}
if (has_capability('mod/attforblock:export', $context)) {
$toprow[] = new tabobject('export', 'export.php?id='.$cm->id,
get_string('export','quiz'));
}
if (has_capability('mod/attforblock:changepreferences', $context)) {
$toprow[] = new tabobject('settings', 'attsettings.php?id='.$cm->id,
get_string('settings','attforblock'));
}
$tabs = array($toprow);
print_tabs($tabs, $currenttab);
}
//getting settings for course
function get_statuses($attendanceid, $onlyvisible = true)
{
global $DB;
if ($onlyvisible) {
$result = $DB->get_records_select('attendance_statuses', "attendanceid = :aid AND visible = 1 AND deleted = 0", array('aid' => $attendanceid), 'grade DESC');
} else {
$result = $DB->get_records_select('attendance_statuses', "attendanceid = :aid AND deleted = 0", array('aid' => $attendanceid), 'grade DESC');
// $result = get_records('attendance_statuses', 'courseid', $courseid, 'grade DESC');
}
return $result;
}
//gets attendance status for a student, returns count
function get_attendance($userid, $course, $attendance, $statusid=0)
{
global $CFG, $DB;
$qry = "SELECT count(*) as cnt
FROM {attendance_log} al
JOIN {attendance_sessions} ats
ON al.sessionid = ats.id
WHERE ats.attendanceid = :aid
AND ats.sessdate >= :cstartdate
AND al.studentid = :uid";
if ($statusid) {
$qry .= " AND al.statusid = :sid";
}
return $DB->count_records_sql($qry, array('aid' => $attendance->id, 'cstartdate' => $course->startdate, 'uid'=>$userid, 'sid'=>$statusid ));
}
function get_grade($userid, $course, $attendance)
{
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 = :usid
AND s.attendanceid = :aid
AND s.courseid = :cid
AND s.sessdate >= :cstartdate", array('usid' => $userid, 'aid' => $attendance->id, 'cid' => $course->id, 'cstartdate' => $course->startdate ));
$result = 0;
if ($logs) {
$stat_grades = $DB->records_to_menu($DB->get_records('attendance_statuses', array('attendanceid'=> $attendance->id)), 'id', 'grade');
foreach ($logs as $log) {
$result += $stat_grades[$log->statusid];
}
}
return $result;
}
//temporary solution, for support PHP 4.3.0 which minimal requirement for Moodle 1.9.x
function local_array_intersect_key($array1, $array2) {
$result = array();
foreach ($array1 as $key => $value) {
if (isset($array2[$key])) {
$result[$key] = $value;
}
}
return $result;
}
function get_maxgrade($userid, $course, $attendance)
{
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 = :usid
AND s.attendanceid = :aid
AND s.courseid = :cid
AND s.sessdate >= :cstartdate", array('usid' => $userid, 'aid' => $attendance->id, 'cid' => $course->id, 'cstartdate' => $course->startdate ));
$maxgrade = 0;
if ($logs) {
$stat_grades = $DB->records_to_menu($DB->get_records('attendance_statuses', array('attendanceid'=> $attendance->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
$grades = local_array_intersect_key($stat_grades, $ids); //temporary solution, for support PHP 4.3.0 which minimal requirement for Moodle 1.9.x
$maxgrade += max($grades);
}
}
return $maxgrade;
}
function get_percent_adaptive($userid, $course) // NOT USED
{
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 = :usid
AND s.attendanceid = :aid
AND s.courseid = :cid
AND s.sessdate >= :cstartdate", array('usid' => $userid, 'aid' => $attendance->id, 'cid' => $course->id, 'cstartdate' => $course->startdate ));
$result = 0;
if ($logs) {
$stat_grades = $DB->records_to_menu($DB->get_records('attendance_statuses', array('attendanceid'=> $attendance->id)), 'id', 'grade');
$percent = 0;
foreach ($logs as $log) {
$ids = array_flip(explode(',', $log->statusset));
$grades = array_intersect_key($stat_grades, $ids);
$delta = max($grades) - min($grades);
$percent += $stat_grades[$log->statusid] / $delta;
}
$result = $percent / count($logs) * 100;
}
if (!$dp = grade_get_setting($course->id, 'decimalpoints')) {
$dp = $CFG->grade_decimalpoints;
}
return sprintf("%0.{$dp}f", $result);
}
function get_percent($userid, $course, $attforblock)
{
global $CFG;
$maxgrd = get_maxgrade($userid, $course, $attforblock);
if ($maxgrd == 0) {
$result = 0;
} else {
$result = get_grade($userid, $course, $attforblock) / $maxgrd * 100;
}
if ($result < 0) {
$result = 0;
}
if (!$dp = grade_get_setting($course->id, 'decimalpoints')) {
$dp = $CFG->grade_decimalpoints;
}
return sprintf("%0.{$dp}f", $result);
}
function set_current_view($courseid, $view) {
global $SESSION;
return $SESSION->currentattview[$courseid] = $view;
}
function get_current_view($courseid, $defaultview='weeks') {
global $SESSION;
if (isset($SESSION->currentattview[$courseid]))
return $SESSION->currentattview[$courseid];
else
return $defaultview;
}
function set_current_date($courseid, $date) {
global $SESSION;
return $SESSION->currentattdate[$courseid] = $date;
}
function get_current_date($courseid) {
global $SESSION;
if (isset($SESSION->currentattdate[$courseid]))
return $SESSION->currentattdate[$courseid];
else
return time();
}
function print_row($left, $right) {
echo "\n<tr><td nowrap=\"nowrap\" align=\"right\" valign=\"top\" class=\"cell c0\">$left</td><td align=\"left\" valign=\"top\" class=\"info c1\">$right</td></tr>\n";
}
function print_attendance_table($user, $course, $attforblock) {
$complete = get_attendance($user->id, $course, $attforblock);
echo '<table border="0" cellpadding="0" cellspacing="0" class="list">';
print_row(get_string('sessionscompleted','attforblock').':', "<strong>$complete</strong>");
$statuses = get_statuses($attforblock->id);
foreach($statuses as $st) {
print_row($st->description.': ', '<strong>'.get_attendance($user->id, $course, $attforblock, $st->id).'</strong>');
}
if ($attforblock->grade) {
$percent = get_percent($user->id, $course, $attforblock).'&nbsp;%';
$grade = get_grade($user->id, $course, $attforblock);
print_row(get_string('attendancepercent','attforblock').':', "<strong>$percent</strong>");
print_row(get_string('attendancegrade','attforblock').':', "<strong>$grade</strong> / ".get_maxgrade($user->id, $course, $attforblock));
}
print_row('&nbsp;', '&nbsp;');
echo '</table>';
}
function print_user_attendaces($user, $cm, $attforblock, $course = 0, $printing = null) {
global $CFG, $COURSE, $mode, $current, $view, $id, $studentid, $DB;
echo '<table class="userinfobox">';
if (!$printing) {
echo '<tr>';
echo '<td colspan="2" class="generalboxcontent"><div align="right">'.
helpbutton('studentview', get_string('attendancereport','attforblock'), 'attforblock', true, false, '', true).
"<a href=\"view.php?id={$cm->id}&amp;student={$user->id}&amp;mode=$mode&amp;printing=yes\" target=\"_blank\">[".get_string('versionforprinting','attforblock').']</a></div></td>';
echo '</tr>';
}
// echo '<tr>';
// echo '<th colspan="2"><h2 class="main help"><center>'.get_string('attendancereport','attforblock').helpbutton('studentview', get_string('attendancereport','attforblock'), 'attforblock', true, false, '', true).'</center></h1></th>';
// echo '</tr>';
echo '<tr>';
echo '<td class="left side">';
print_user_picture($user->id, $COURSE->id, $user->picture, true);
echo '</td>';
echo '<td class="generalboxcontent">';
echo '<font size="+1"><b>'.fullname($user).'</b></font>';
if ($course) {
echo '<hr />';
$complete = get_attendance($user->id, $course, $attforblock);
if($complete) {
print_attendance_table($user, $course, $attforblock);
} else {
echo get_string('attendancenotstarted','attforblock');
}
} else {
$stqry = "SELECT ats.id,ats.courseid AS 'cid',ats.attendanceid AS 'aid'
FROM {attendance_log} al
JOIN {attendance_sessions} ats
ON al.sessionid = ats.id
WHERE al.studentid = ?
GROUP BY cid
ORDER BY cid,aid asc";
$recs = $DB->get_records_sql($stqry, array($user->id));
foreach ($recs as $rec) {
echo '<hr />';
echo '<table border="0" cellpadding="0" cellspacing="0" width="100%" class="list1">';
$nextcourse = $DB->get_record('course', array('id'=> $rec['cid']));
$nextattendance = $DB->get_record('attforblock', array('id'=> $rec['aid']));
echo '<tr><td valign="top"><strong>'.$nextcourse->fullname.' - '.$nextattendance->name . '</strong></td>';
echo '<td align="right">';
$complete = get_attendance($user->id, $nextcourse, $nextattendance);
if($complete) {
print_attendance_table($user, $nextcourse, $nextattendance);
} else {
echo get_string('attendancenotstarted','attforblock');
}
echo '</td></tr>';
echo '</table>';
}
}
if ($course) {
if ($current == 0)
$current = get_current_date($course->id);
else
set_current_date ($course->id, $current);
$ret = print_filter_controls("view.php", $id, $studentid);
$startdate = $ret['startdate'];
$enddate = $ret['enddate'];
if ($startdate && $enddate) {
$where = "ats.courseid=:cid AND al.studentid = :uid AND ats.sessdate >= :sdate AND ats.sessdate < :edate";
} else {
$where = "ats.courseid=:cid AND al.studentid = :uid";
}
$stqry = "SELECT ats.id,ats.sessdate,ats.description,al.statusid,al.remarks
FROM {attendance_log} al
JOIN {attendance_sessions} ats
ON al.sessionid = ats.id";
$stqry .= " WHERE " . $where;
$stqry .= " ORDER BY ats.sessdate asc";
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;
$table->head = array('#', get_string('date'), get_string('time'), get_string('description','attforblock'), get_string('status','attforblock'), get_string('remarks','attforblock'));
$table->align = array('', '', 'left', 'left', 'center', 'left');
$table->size = array('1px', '1px', '1px', '*', '1px', '1px');
$table->class = 'generaltable attwidth';
foreach($sessions as $key=>$sessdata)
{
$i++;
$table->data[$sessdata->id][] = $i;
$table->data[$sessdata->id][] = userdate($sessdata->sessdate, get_string('strftimedmyw', 'attforblock'));
$table->data[$sessdata->id][] = userdate($sessdata->sessdate, get_string('strftimehm', 'attforblock'));
$table->data[$sessdata->id][] = empty($sessdata->description) ? get_string('nodescription', 'attforblock') : $sessdata->description;
$table->data[$sessdata->id][] = $statuses[$sessdata->statusid]->description;
$table->data[$sessdata->id][] = $sessdata->remarks;
}
print_table($table);
}
}
echo '</td></tr><tr><td>&nbsp;</td></tr></table></div>';
}
function print_filter_controls($url, $id, $studentid=0, $sort=NULL, $printselector=WITHOUT_SELECTOR) {
global $CFG, $SESSION, $current, $view, $cm;
$date = usergetdate($current);
$mday = $date['mday'];
$wday = $date['wday'];
$mon = $date['mon'];
$year = $date['year'];
$curdatecontrols = '';
$curdatetxt = '';
switch ($view) {
case 'days':
$format = get_string('strftimedm', 'attforblock');
$startdate = make_timestamp($year, $mon, $mday);
$enddate = make_timestamp($year, $mon, $mday + 1);
$prevcur = make_timestamp($year, $mon, $mday - 1);
$nextcur = make_timestamp($year, $mon, $mday + 1);
$curdatetxt = userdate($startdate, $format);
break;
case 'weeks':
$format = get_string('strftimedm', 'attforblock');
$startdate = make_timestamp($year, $mon, $mday - $wday + 1);
$enddate = make_timestamp($year, $mon, $mday + 7 - $wday + 1) - 1;
$prevcur = $startdate - WEEKSECS;
$nextcur = $startdate + WEEKSECS;
$curdatetxt = userdate($startdate, $format)." - ".userdate($enddate, $format);
break;
case 'months':
$format = '%B';
$startdate = make_timestamp($year, $mon);
$enddate = make_timestamp($year, $mon + 1);
$prevcur = make_timestamp($year, $mon - 1);
$nextcur = make_timestamp($year, $mon + 1);
$curdatetxt = userdate($startdate, $format);
break;
case 'alltaken':
$startdate = 1;
$enddate = time();
break;
case 'all':
$startdate = 0;
$enddate = 0;
break;
}
$link = $url . "?id=$id" . ($sort ? "&amp;sort=$sort" : "") . ($studentid ? "&amp;student=$studentid" : "");
$currentgroup = -1;
$sessiontypeselector = '';
if ($printselector === GROUP_SELECTOR) {
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
$groupselector = '';
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if ($groupmode == VISIBLEGROUPS ||
($groupmode && has_capability('moodle/site:accessallgroups', $context))) {
$groupselector = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/attforblock/' . $link, true);
}
} elseif ($printselector === SESSION_TYPE_SELECTOR and $groupmode = groups_get_activity_groupmode($cm)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $context)) {
$allowedgroups = groups_get_all_groups($cm->course, 0, $cm->groupingid); // any group in grouping (all if groupings not used)
// detect changes related to groups and fix active group
if (!empty($SESSION->activegroup[$cm->course][VISIBLEGROUPS][$cm->groupingid])) {
if (!array_key_exists($SESSION->activegroup[$cm->course][VISIBLEGROUPS][$cm->groupingid], $allowedgroups)) {
// active group does not exist anymore
unset($SESSION->activegroup[$cm->course][VISIBLEGROUPS][$cm->groupingid]);
}
}
if (!empty($SESSION->activegroup[$cm->course]['aag'][$cm->groupingid])) {
if (!array_key_exists($SESSION->activegroup[$cm->course]['aag'][$cm->groupingid], $allowedgroups)) {
// active group does not exist anymore
unset($SESSION->activegroup[$cm->course]['aag'][$cm->groupingid]);
}
}
} else {
$allowedgroups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid); // only assigned groups
// detect changes related to groups and fix active group
if (isset($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid])) {
if ($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid] == 0) {
if ($allowedgroups) {
// somebody must have assigned at least one group, we can select it now - yay!
unset($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid]);
}
} else {
if (!array_key_exists($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid], $allowedgroups)) {
// active group not allowed or does not exist anymore
unset($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid]);
}
}
}
}
$group = optional_param('group', -2, PARAM_INT);
if (!array_key_exists('attsessiontype', $SESSION)) {
$SESSION->attsessiontype = array();
}
if ($group > -2) {
$SESSION->attsessiontype[$cm->course] = $group;
} elseif (!array_key_exists($cm->course, $SESSION->attsessiontype)) {
$SESSION->attsessiontype[$cm->course] = -1;
}
if ($group == -1) {
$currentgroup = $group;
unset($SESSION->activegroup[$cm->course][VISIBLEGROUPS][$cm->groupingid]);
unset($SESSION->activegroup[$cm->course]['aag'][$cm->groupingid]);
unset($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid]);
} else {
$currentgroup = groups_get_activity_group($cm, true);
if ($currentgroup == 0 and $SESSION->attsessiontype[$cm->course] == -1) {
$currentgroup = -1;
}
}
$selector = array();
if ($allowedgroups or $groupmode == VISIBLEGROUPS or
has_capability('moodle/site:accessallgroups', $context)) {
$selector[-1] = get_string('all', 'attforblock');
}
if ($groupmode == VISIBLEGROUPS) {
$selector[0] = get_string('commonsessions', 'attforblock');
}
if ($allowedgroups) {
foreach ($allowedgroups as $group) {
$selector[$group->id] = format_string($group->name);
}
}
if (count($selector) > 1) {
$sessiontypeselector = popup_form($url.'?id='.$cm->id.'&amp;group=', $selector, 'selectgroup', $currentgroup, '', '', '', true, 'self', get_string('sessions', 'attforblock'));
}
$sessiontypeselector = '<div class="groupselector">'.$sessiontypeselector.'</div>';
}
$views['all'] = get_string('all','attforblock');
$views['alltaken'] = get_string('alltaken','attforblock');
$views['months'] = get_string('months','attforblock');
$views['weeks'] = get_string('weeks','attforblock');
$views['days'] = get_string('days','attforblock');
$viewcontrols = '<nobr>';
foreach ($views as $key => $sview) {
if ($key != $view)
$viewcontrols .= "<span class=\"attbtn\"><a href=\"{$link}&amp;view={$key}\">$sview</a></span>";
else
$viewcontrols .= "<span class=\"attcurbtn\">$sview</span>";
}
$viewcontrols .= '</nobr>';
echo "<div class=\"attfiltercontrols attwidth\">";
echo "<table width=\"100%\"><tr>";
if ($printselector === GROUP_SELECTOR) {
echo "<td width=\"45%\">$groupselector</td>";
} elseif ($printselector === SESSION_TYPE_SELECTOR) {
echo "<td width=\"45%\">$sessiontypeselector</td>";
}
if ($curdatetxt) {
$curdatecontrols = "<a href=\"{$link}&amp;current=$prevcur\"><span class=\"arrow \"></span></a>";
$curdatecontrols .= "<form id =\"currentdate\" action=\"$url\" method=\"get\" style=\"display:inline;\">";
$curdatecontrols .= " <button title=\"" . get_string('calshow','attforblock') . "\" id=\"show\" type=\"button\">$curdatetxt</button> ";
$curdatecontrols .= "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
if ($sort)
$curdatecontrols .= "<input type=\"hidden\" name=\"sort\" value=\"$sort\" />";
if ($studentid)
$curdatecontrols .= "<input type=\"hidden\" name=\"student\" value=\"$studentid\" />";
$curdatecontrols .= "<input type=\"hidden\" id=\"current\" name=\"current\" value=\"\" />";
$curdatecontrols .= "</form>";
$curdatecontrols .= "<a href=\"{$link}&amp;current=$nextcur\"><span class=\"arrow \"></span></a>";
plug_yui_calendar($current);
}
echo "<td width=\"20%\" align=\"center\">$curdatecontrols</td>";
echo "<td width=\"35%\" align=\"right\">$viewcontrols</td></tr></table>";
echo "</div>";
return array('startdate' => $startdate, 'enddate' => $enddate, 'currentgroup' => $currentgroup);
}
function plug_yui_calendar($current) {
global $CFG;
require_js(array('yui_dom-event', 'yui_dragdrop', 'yui_element', 'yui_button', 'yui_container', 'yui_calendar'));
echo "<script type=\"text/javascript\">\n";
echo "var cal_close = \"" . get_string('calclose','attforblock') . "\";";
echo "var cal_today = \"" . get_string('caltoday','attforblock') . "\";";
echo "var cal_months = [" . get_string('calmonths','attforblock') . "];";
echo "var cal_week_days = [" . get_string('calweekdays','attforblock') . "];";
echo "var cal_start_weekday = " . $CFG->calendar_startwday . ";";
echo "var cal_cur_date = " . $current . ";";
echo "</script>\n";
require_js($CFG->wwwroot . '/mod/attforblock/calendar.js');
}
?>

212
_manage.php

@ -1,212 +0,0 @@
<?PHP // $Id: manage.php,v 1.2.2.4 2009/02/28 19:20:14 dlnsk Exp $
/// This page prints a particular instance of attforblock
/// (Replace attforblock with the name of your module)
require_once('../../config.php');
require_once('locallib.php');
$id = required_param('id', PARAM_INT); // Course Module ID, or
$from = optional_param('from', '', PARAM_ACTION);
$view = optional_param('view', NULL, PARAM_ALPHA); // which page to show
$current = optional_param('current', 0, PARAM_INT);
$showendtime = optional_param('showendtime', get_user_preferences("attforblock_showendtime",0), PARAM_INT);
if (! $cm = $DB->get_record('course_modules', array('id'=> $id))) {
error('Course Module ID was incorrect');
}
if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
error("Course is misconfigured");
}
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect");
}
require_login($course->id);
if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course");
}
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
if ($view)
set_current_view($course->id, $_GET['view']);
else
$view = get_current_view($course->id);
if (!has_capability('mod/attforblock:manageattendances', $context) AND
!has_capability('mod/attforblock:takeattendances', $context) AND
!has_capability('mod/attforblock:changeattendances', $context)) {
redirect("view.php?id=$cm->id");
}
set_user_preference("attforblock_showendtime",$showendtime);
//if teacher is coming from block, then check for a session exists for today
if($from === 'block') {
$today = time(); // because we compare with database, we don't need to use usertime()
$sql = "SELECT id, groupid, lasttaken
FROM {attendance_sessions}
WHERE ? BETWEEN sessdate AND (sessdate + duration)
AND courseid = ? AND attendanceid = ?";
if($atts = $DB->get_records_sql($sql, array($today, $course->id, $attforblock->id))) {
$size = count($atts);
if ($size == 1) {
$att = reset($atts);
if ((!$att->lasttaken and has_capability('mod/attforblock:takeattendances', $context)) or
($att->lasttaken and has_capability('mod/attforblock:changeattendances', $context))) {
redirect('attendances.php?id='.$id.'&amp;sessionid='.$att->id.'&amp;grouptype='.$att->groupid);
}
} elseif ($size > 1) {
$current = $today;
//temporally set $view for single access to page from block
$view = 'days';
}
}
}
/// Print headers
$url = new moodle_url('/mod/attforblock/manage.php', array('id'=> $id, 'from'=> $from, 'view' => $view, 'current' => $current, 'showendtime' => $showendtime));
$PAGE->set_url($url);
$PAGE->set_title($course->shortname. ": ".$attforblock->name);
$PAGE->set_heading($course->fullname);
$PAGE->set_focuscontrol('');
$PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id,'attforblock'));
$PAGE->navbar->add($attforblock->name);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname);
if(!$DB->count_records_select('attendance_sessions', "courseid = ? AND attendanceid = ? AND sessdate >= ?", array($course->id, $attforblock->id, $course->startdate))) { // no session exists for this course
show_tabs($cm, $context);
print_heading(get_string('nosessionexists','attforblock'));
$hiddensess = $DB->count_records_select('attendance_sessions', "courseid = ? AND attendanceid = ? AND sessdate < ?", array($course->id, $attforblock->id, $course->startdate));
echo '<div align="left">'.helpbutton('hiddensessions', '--', 'attforblock', true, true, '', true); //TODO: fix '--'
echo get_string('hiddensessions', 'attforblock').': '.$hiddensess.'</div>';
} else { //sessions generated , display them
add_to_log($course->id, 'attendance', 'manage attendances', 'mod/attforblock/manage.php?course='.$course->id, $user->lastname.' '.$user->firstname);
show_tabs($cm, $context);
print_sessions_list($course, $attforblock);
}
// require_once('lib.php');
// $t = attforblock_get_user_grades($attforblock); ////////////////////////////////////////////
$OUTPUT->footer();//print_footer($course);
function print_sessions_list($course, $attforblock) {
global $CFG, $context, $cm, $current, $view, $id, $showendtime, $DB, $OUTPUT;
$strhours = get_string('hours');
$strmins = get_string('min');
if ($current == 0)
$current = get_current_date($course->id);
else
set_current_date ($course->id, $current);
$ret = print_filter_controls("manage.php", $id, 0, NULL, SESSION_TYPE_SELECTOR);
$startdate = $ret['startdate'];
$enddate = $ret['enddate'];
$currentgroup = $ret['currentgroup'];
if ($startdate && $enddate) {
$where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :sdate AND sessdate >= :sdate2 AND sessdate < :edate";
} else {
$where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :sdate";
}
if ($currentgroup > -1) {
$where .= " AND groupid=:cgroup";
}
$qry = $DB->get_records_select('attendance_sessions', $where, array('cid' => $course->id, 'aid' => $attforblock->id, 'sdate' => $course->startdate,'sdate2' => $startdate, 'edate'=> $enddate, 'cgroup'=> $currentgroup), 'sessdate asc');
$i = 0;
$table = new html_table();
$table->width = '100%';
//$table->tablealign = 'center';
$table->head = array('#', get_string('sessiontypeshort', 'attforblock'), get_string('date'), get_string('from'), ($showendtime=='0') ? get_string('duration', 'attforblock') : get_string('to'), get_string('description','attforblock'), get_string('actions'), get_string('select'));
$table->align = array('', '', '', 'right', 'left', 'center', 'center');
$table->size = array('1px', '', '1px', '1px', '1px', '*', '1px', '1px');
$allowtake = has_capability('mod/attforblock:takeattendances', $context);
$allowchange = has_capability('mod/attforblock:changeattendances', $context);
$allowmanage = has_capability('mod/attforblock:manageattendances', $context);
$groups = groups_get_all_groups($course->id);
if ($qry) {
foreach($qry as $key=>$sessdata)
{
$i++;
$actions = '';
// if ($allowtake) {
if($sessdata->lasttaken > 0) //attendance has taken
{
if ($allowchange) {
$desc = "<a href=\"attendances.php?id=$cm->id&amp;sessionid={$sessdata->id}&amp;grouptype={$sessdata->groupid}\">".
($sessdata->description ? $sessdata->description : get_string('nodescription', 'attforblock')).
'</a>';
} else {
$desc = '<i>'.(empty($sessdata->description) ? get_string('nodescription', 'attforblock') : $sessdata->description).'</i>';
}
} else {
$desc = empty($sessdata->description) ? get_string('nodescription', 'attforblock') : $sessdata->description;
if ($allowtake) {
$title = get_string('takeattendance','attforblock');
$actions = "<a title=\"$title\" href=\"attendances.php?id=$cm->id&amp;sessionid={$sessdata->id}&amp;grouptype={$sessdata->groupid}\">".
"<img src=\"" . $OUTPUT->pix_url('t/go') . "\" alt=\"$title\" /></a>&nbsp;";
}
}
// }
if($allowmanage) {
$title = get_string('editsession','attforblock');
$actions .= "<a title=\"$title\" href=\"sessions.php?id=$cm->id&amp;sessionid={$sessdata->id}&amp;action=update\">".
"<img src=\"" . $OUTPUT->pix_url('t/edit') . "\" alt=\"$title\" /></a>&nbsp;";
$title = get_string('deletesession','attforblock');
$actions .= "<a title=\"$title\" href=\"sessions.php?id=$cm->id&amp;sessionid={$sessdata->id}&amp;action=delete\">".
"<img src=\"" . $OUTPUT->pix_url('t/delete') . "\" alt=\"$title\" /></a>&nbsp;";
}
$table->data[$sessdata->id][] = $i;
$table->data[$sessdata->id][] = $sessdata->groupid ? $groups[$sessdata->groupid]->name : get_string('commonsession', 'attforblock');
$table->data[$sessdata->id][] = userdate($sessdata->sessdate, get_string('strftimedmyw', 'attforblock'));
$table->data[$sessdata->id][] = userdate($sessdata->sessdate, get_string('strftimehm', 'attforblock'));
$hours = floor($sessdata->duration / HOURSECS);
$mins = floor(($sessdata->duration - $hours * HOURSECS) / MINSECS);
$mins = $mins < 10 ? "0$mins" : "$mins";
$table->data[$sessdata->id][] = ($showendtime=='0') ? ($hours ? "{$hours}&nbsp;{$strhours}&nbsp;{$mins}&nbsp;{$strmins}" : "{$mins}&nbsp;{$strmins}") : userdate($sessdata->sessdate+$sessdata->duration, get_string('strftimehm', 'attforblock'));;
$table->data[$sessdata->id][] = $desc;
$table->data[$sessdata->id][] = $actions;
$table->data[$sessdata->id][] = '<input type="checkbox" name="sessid['.$sessdata->id.']" />';
unset($desc, $actions);
}
}
echo '<div align="center"><div class="generalbox attwidth">';
echo "<form method=\"post\" action=\"sessions.php?id={$cm->id}\">"; //&amp;sessionid={$sessdata->id}
print_table($table);//echo $OUTPUT->table($table);
$hiddensess = $DB->count_records_select('attendance_sessions', "courseid = ? AND attendanceid = ? AND sessdate < ?", array($course->id, $attforblock->id, $course->startdate));
echo '<table width="100%"><tr><td valign="top">';
echo '<div align="left">'.helpbutton('hiddensessions', '--', 'attforblock', true, true, '', true); //TODO: Change '--'
echo get_string('hiddensessions', 'attforblock').': '.$hiddensess.'</div></td>';
echo '<td><div align="right"><a href="javascript:checkall();">'.get_string('selectall').'</a> /'.
' <a href="javascript:checknone();">'.get_string('deselectall').'</a><br /><br />';
echo '<strong>'.get_string('withselected', 'quiz').':</strong>&nbsp;';
if ($allowmanage) {
$actionlist = array('deleteselected' => get_string('delete'),
'changeduration' => get_string('changeduration', 'attforblock'));
choose_from_menu($actionlist, 'action');
echo '<input type="submit" name="ok" value="'.get_string('ok')."\" />\n";
} else {
echo get_string('youcantdo', 'attforblock'); //You can't do anything
}
echo '<div align="right">'.helpbutton ('sessions', get_string('help'), 'attforblock', true, true, '', true).'</div>';
echo '</div></td></tr></table>';
echo '</form></div></div>';
}
?>

201
_report.php

@ -1,201 +0,0 @@
<?PHP // $Id: report.php,v 1.1.2.4 2009/02/28 16:49:17 dlnsk Exp $
// generates sessions
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);
$id = required_param('id', PARAM_INT);
$group = optional_param('group', -1, PARAM_INT); // Group to show
$view = optional_param('view', NULL, PARAM_ALPHA); // which page to show
$current = optional_param('current', 0, PARAM_INT);
$sort = optional_param('sort', 'lastname', PARAM_ALPHA);
if ($id) {
if (! $cm = $DB->get_record('course_modules', array('id'=> $id))) {
error('Course Module ID was incorrect');
}
if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
error('Course is misconfigured');
}
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect");
}
}
require_login($course->id);
if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course");
}
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
if ($view)
set_current_view($course->id, $_GET['view']);
else
$view = get_current_view($course->id);
require_capability('mod/attforblock:viewreports', $context);
//add info to log
add_to_log($course->id, 'attendance', 'report displayed', 'mod/attforblock/report.php?id='.$id, $user->lastname.' '.$user->firstname);
/// Print headers
$navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activity');
$navlinks[] = array('name' => get_string('report', 'attforblock'), 'link' => null, 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: ".$attforblock->name.' - ' .get_string('report','attforblock'), $course->fullname,
$navigation, "", "", true, "&nbsp;", navmenu($course));
show_tabs($cm, $context, 'report');
$sort = $sort == 'firstname' ? 'firstname' : 'lastname';
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");
} else {
if ($current == 0)
$current = get_current_date($course->id);
else
set_current_date ($course->id, $current);
$ret = print_filter_controls("report.php", $id, 0, $sort, GROUP_SELECTOR);
$startdate = $ret['startdate'];
$enddate = $ret['enddate'];
$currentgroup = $ret['currentgroup'];
if ($startdate && $enddate) {
$where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :sdate AND sessdate >= :sdate2 AND sessdate < :edate";
} else {
$where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :sdate";
}
if ($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);
}
$statuses = get_statuses($attforblock->id);
$allstatuses = get_statuses($attforblock->id, false);
if ($students and
($course_sess = $DB->get_records_select('attendance_sessions', $where, array('cid' => $course->id, 'aid'=> $attforblock->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>';
$lastname = "<a href=\"report.php?id=$id&amp;sort=lastname\">".get_string('lastname').'</a>';
if ($CFG->fullnamedisplay == 'lastname firstname') { // for better view (dlnsk)
$fullnamehead = "$lastname / $firstname";
} else {
$fullnamehead = "$firstname / $lastname";
}
$table->head[] = '';
$table->align[] = '';
$table->size[] = '1px';
$table->head[] = $fullnamehead;
$table->align[] = 'left';
$table->size[] = '';
$table->class = 'generaltable attwidth';
$allowtake = has_capability('mod/attforblock:takeattendances', $context);
$allowchange = has_capability('mod/attforblock:changeattendances', $context);
$groups = groups_get_all_groups($course->id);
foreach($course_sess as $sessdata) {
if ($DB->count_records('attendance_log', array('sessionid'=> $sessdata->id))) {
if ($allowchange) {
$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').')').
'</a>';
} else {
$sessdate = userdate($sessdata->sessdate, get_string('strftimedm', 'attforblock').'<br />('.get_string('strftimehm', 'attforblock').')');
}
$sesstype = $sessdata->groupid ? $groups[$sessdata->groupid]->name : get_string('commonsession', 'attforblock');
$table->head[] = $sessdate.'<br />'.$sesstype;
} else {
if ($allowtake) {
$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').')').
'</a>';
} else {
$sessdate = userdate($sessdata->sessdate, get_string('strftimedm', 'attforblock').'<br />('.get_string('strftimehm', 'attforblock').')');
}
$sesstype = $sessdata->groupid ? $groups[$sessdata->groupid]->name : get_string('commonsession', 'attforblock');
$table->head[] = $sessdate.'<br />'.$sesstype;
}
$table->align[] = 'center';
$table->size[] = '1px';
}
for ($i=0; $i<5; $i++) {
$table->align[] = 'center';
$table->size[] = '1px';
}
foreach($statuses as $st) {
$table->head[] = $st->acronym;
}
if ($attforblock->grade) {
$table->head[] = get_string('grade');//.'&nbsp;/&nbsp;'.$maxgrade;
$table->align[] = 'right';
$table->size[] = '1px';
$table->head[] = '%';
}
foreach($students as $student) {
$table->data[$student->id][] = print_user_picture($student->id, $course->id, $student->picture, 20, true, true);
$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);
foreach($course_sess as $sessdata) {
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 {
$table->data[$student->id][] = '<font color="red"><b>'.$allstatuses[$att->statusid]->acronym.'</b></font>';
}
} else {
if (!$studgroups || $sessdata->groupid && !array_key_exists($sessdata->groupid, $studgroups))
// student is not memeber of any group OR it is session of other group
$table->data[$student->id][] = '';
else
if($sessdata->lasttaken > 0) {
// student began to study in the group later this session
$table->data[$student->id][] = '–';
} else {
// no attendance data for session
$table->data[$student->id][] = '?';
}
}
}
foreach($statuses as $st) {
$table->data[$student->id][] = get_attendance($student->id, $course, $attforblock, $st->id);
}
if ($attforblock->grade) {
$table->data[$student->id][] = get_grade($student->id, $course, $attforblock).'&nbsp;/&nbsp;'.get_maxgrade($student->id, $course, $attforblock);
$table->data[$student->id][] = get_percent($student->id, $course, $attforblock).'%';
}
}
print_table($table);
} else {
print_heading(get_string('nothingtodisplay'), 'center');
}
echo get_string('status','attforblock').':<br />';
foreach($statuses as $st) {
echo $st->acronym.' - '.$st->description.'<br />';
}
}
print_footer($course);
exit;
?>

264
_restorelib.php

@ -1,264 +0,0 @@
<?php
function attforblock_restore_mods($mod,$restore) {
global $CFG, $oldidarray, $DB;
$status = true;
//Get record from backup_ids
$data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
if ($data) {
//Now get completed xmlized object
$info = $data->info;
/*if (count_records('attforblock', 'course', $restore->course_id)) {
return false;
}*/
//Now, build the attforblock record structure
$attforblock->course = $restore->course_id;
// $attforblock->teacher = backup_todb($info['MOD']['#']['TEACHER']['0']['#']);
$attforblock->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
if (isset($info['MOD']['#']['GRADE'])) {
$attforblock->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
} else {
$attforblock->grade = 100;
}
//The structure is equal to the db, so insert the 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);
attforblock_restore_attendance_statuses ($mod->id, $newid, $info, $restore);
attforblock_restore_attendance_sessions ($mod->id, $newid, $info, $restore);
//Now check if want to restore user data and do it.
if (restore_userdata_selected($restore, 'attforblock', $mod->id)) {
attforblock_restore_attendance_log ($mod->id, $newid, $info, $restore);
}
} else {
$status = false;
}
} else {
$status = false;
}
return $status;
}
function attforblock_restore_attendance_sessions ($old_attforblock_id, $new_attforblock_id, $info, $restore) {
global $CFG, $oldidarray, $DB;
$status = true;
if (isset($info['MOD']['#']['SESSIONS'])) {
@$stats = $info['MOD']['#']['SESSIONS']['0']['#']['SESSION'];
}else {
@$stats = $info['MOD']['#']['ATTFORBLOCK_SESSIONS']['0']['#']['ROWS'];
}
for($i = 0; $i < sizeof($stats); $i++) {
$stat_info = $stats[$i];
//Now, build the attforblock_SESSIONS record structure
$stat->courseid = $restore->course_id;
$stat->attendanceid = $new_attforblock_id;
$stat->groupid = backup_todb($stat_info['#']['GROUPID']['0']['#']);
$group = restore_group_getid($restore, $stat->groupid);
if ($group) {
$stat->groupid = $group->new_id;
}
// $stat->creator = backup_todb($stat_info['#']['CREATOR']['0']['#']);
$stat->sessdate = backup_todb($stat_info['#']['SESSDATE']['0']['#']);
$stat->timemodified = backup_todb($stat_info['#']['TIMEMODIFIED']['0']['#']);
$stat->description = backup_todb($stat_info['#']['DESCRIPTION']['0']['#']);
if (isset($info['MOD']['#']['SESSIONS'])) {
$stat->duration = backup_todb($stat_info['#']['DURATION']['0']['#']);;
$stat->lasttaken = backup_todb($stat_info['#']['LASTTAKEN']['0']['#']);
$stat->lasttakenby = backup_todb($stat_info['#']['LASTTAKENBY']['0']['#']);
} else { //Old backup
$stat->duration = 0;
$stat->lasttaken = backup_todb($stat_info['#']['TIMETAKEN']['0']['#']);
$stat->lasttakenby = backup_todb($stat_info['#']['TAKENBY']['0']['#']);
}
if (restore_userdata_selected($restore, 'attforblock', $old_attforblock_id)) {
if ($user = backup_getid($restore->backup_unique_code, 'user', $stat->lasttakenby)) {
$stat->lasttakenby = $user->new_id;
}
} else {
$stat->lasttaken = 0;
$stat->lasttakenby = 0;
}
$newid = $DB->insert_record ('attendance_sessions', $stat);
$oldidarray[$old_attforblock_id]['attendance_sessions'][backup_todb($stat_info['#']['ID']['0']['#'])] = $newid;
}
return $status;
}
function attforblock_restore_attendance_statuses ($old_attforblock_id, $new_attforblock_id,$info,$restore) {
global $CFG, $oldidarray, $DB;
$status = true;
//Get the statuses array
if (isset($info['MOD']['#']['STATUSES'])) {
$stats = $info['MOD']['#']['STATUSES']['0']['#']['STATUS'];
for($i = 0; $i < sizeof($stats); $i++) {
$stat_info = $stats[$i];
//Now, build the attforblock_STATUS record structure
$stat->courseid = $restore->course_id;
$stat->attendanceid = $new_attforblock_id;
$stat->acronym = backup_todb($stat_info['#']['ACRONYM']['0']['#']);
$stat->description = backup_todb($stat_info['#']['DESCRIPTION']['0']['#']);
$stat->grade = backup_todb($stat_info['#']['GRADE']['0']['#']);
$stat->visible = backup_todb($stat_info['#']['VISIBLE']['0']['#']);
$stat->deleted = backup_todb($stat_info['#']['DELETED']['0']['#']);
//if user's data not required, we don't restore invisible and deleted statuses
if (!restore_userdata_selected($restore, 'attforblock', $old_attforblock_id)
and (!$stat->visible or $stat->deleted)) {
continue;
}
$newid = $DB->insert_record ('attendance_statuses', $stat);
$oldidarray[$old_attforblock_id]['attendance_statuses'][backup_todb($stat_info['#']['ID']['0']['#'])] = $newid;
}
} elseif (isset($info['MOD']['#']['ATTFORBLOCK_SETTINGS'])) {
$stats = $info['MOD']['#']['ATTFORBLOCK_SETTINGS']['0']['#']['ROWS'];
for($i = 0; $i < sizeof($stats); $i++) {
$stat_info = $stats[$i];
//Now, build the attforblock_STATUS record structure
$stat->courseid = $restore->course_id;
$stat->attendanceid = $new_attforblock_id;
$stat->acronym = backup_todb($stat_info['#']['ACRONYM']['0']['#']);
$stat->description = backup_todb($stat_info['#']['DESCRIPTION']['0']['#']);
$stat->grade = backup_todb($stat_info['#']['GRADE']['0']['#']);
$stat->visible = 1;
$stat->deleted = 0;
$newid = $DB->insert_record ('attendance_statuses', $stat);
$oldidarray[$old_attforblock_id]['attendance_statuses'][backup_todb($stat_info['#']['STATUS']['0']['#'])] = $newid;
}
} else {
// ATTFORBLOCK_SETTINGS tag don't exists
// so course used default statuses (can be only in old version)
$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;
$stat->attendanceid = $new_attforblock_id;
$newid = $DB->insert_record('attendance_statuses', $stat);
$oldidarray[$old_attforblock_id]['attendance_statuses'][$oldstats[$i++]] = $newid;
// $i++;
}
}
return $status;
}
function attforblock_restore_attendance_log ($old_attforblock_id, $new_attforblock_id,$info,$restore) {
global $CFG, $oldidarray, $DB;
$status = true;
//Get the logs array
if (isset($info['MOD']['#']['LOGS'])) {
@$logs = $info['MOD']['#']['LOGS']['0']['#']['LOG'];
} else {
@$logs = $info['MOD']['#']['ATTFORBLOCK_LOG']['0']['#']['ROWS'];
}
$stats = $DB->get_records_menu('attendance_statuses', array('attendanceid'=> $new_attforblock_id));
$statslist = implode(',', array_keys($stats));
$sessions = $DB->get_records('attendance_sessions', array('attendanceid'=> $new_attforblock_id));
//Iterate over logs
for($i = 0; $i < sizeof($logs); $i++) {
$log_info = $logs[$i];
//Now, build the attforblock_LOG record structure
$log->studentid = backup_todb($log_info['#']['STUDENTID']['0']['#']);
$log->remarks = backup_todb($log_info['#']['REMARKS']['0']['#']);
$user = backup_getid($restore->backup_unique_code, 'user', $log->studentid);
if ($user) {
$log->studentid = $user->new_id;
}
if (isset($info['MOD']['#']['LOGS'])) {
$log->sessionid = $oldidarray[$old_attforblock_id]['attendance_sessions'][backup_todb($log_info['#']['SESSIONID']['0']['#'])];
$log->statusid = $oldidarray[$old_attforblock_id]['attendance_statuses'][backup_todb($log_info['#']['STATUSID']['0']['#'])];
$log->timetaken = backup_todb($log_info['#']['TIMETAKEN']['0']['#']);
$log->statusset = backup_todb($log_info['#']['STATUSSET']['0']['#']);
$ids = explode(',', $log->statusset);
foreach ($ids as $id) {
$new_ids[] = $oldidarray[$old_attforblock_id]['attendance_statuses'][$id];
}
$log->statusset = implode(',', $new_ids);
$log->takenby = backup_todb($log_info['#']['TAKENBY']['0']['#']);
$user = backup_getid($restore->backup_unique_code, 'user', $log->takenby);
if ($user) {
$log->takenby = $user->new_id;
}
} else { //Old version
// Catching bug of first version of backup
if (isset($oldidarray[$old_attforblock_id]['attendance_sessions'][backup_todb($log_info['#']['ATTSID']['0']['#'])])) {
$log->sessionid = $oldidarray[$old_attforblock_id]['attendance_sessions'][backup_todb($log_info['#']['ATTSID']['0']['#'])];
} else {
continue;
}
$log->statusid = $oldidarray[$old_attforblock_id]['attendance_statuses'][backup_todb($log_info['#']['STATUS']['0']['#'])];
$log->statusset = $statslist;
// $log->timetaken = get_field('attendance_sessions', 'lasttaken', 'id', $log->sessionid);
$log->timetaken = $sessions[$log->sessionid]->lasttaken;
$log->takenby = $sessions[$log->sessionid]->lasttakenby;
// $log->takenby = backup_todb($log_info['#']['TAKENBY']['0']['#']);
}
$newid = $DB->insert_record ('attendance_log', $log);
$oldidarray[$old_attforblock_id]['attendance_log'][backup_todb($log_info['#']['ID']['0']['#'])] = $newid;
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo '.';
if (($i+1) % 1000 == 0) {
echo '<br />';
}
}
backup_flush(300);
}
}
return $status;
}
// function attforblock_restore_logs($restore,$log) {
//
// $status = true;
//
// return $status;
// }
?>

286
_sessions.php

@ -1,286 +0,0 @@
<?PHP // $Id: sessions.php,v 1.2.2.3 2009/02/23 19:22:41 dlnsk Exp $
require_once('../../config.php');
require_once($CFG->libdir.'/blocklib.php');
require_once('locallib.php');
require_once('lib.php');
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');
}
$id = required_param('id', PARAM_INT);
$action = required_param('action', PARAM_ACTION);
if ($id) {
if (! $cm = $DB->get_record('course_modules', array('id'=> $id))) {
error('Course Module ID was incorrect');
}
if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
error('Course is misconfigured');
}
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect");
}
}
require_login($course->id);
if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course");
}
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_capability('mod/attforblock:manageattendances', $context);
$navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activity');
$navlinks[] = array('name' => get_string($action, 'attforblock'), 'link' => null, 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: ".$attforblock->name.' - '.get_string($action,'attforblock'), $course->fullname,
$navigation, "", "", true, "&nbsp;", navmenu($course));
//////////////////////////////////////////////////////////
// Adding sessions
//////////////////////////////////////////////////////////
if ($action === 'add') {
show_tabs($cm, $context, 'add');
$mform_add = new mod_attforblock_add_form('sessions.php', array('course'=>$course, 'cm'=>$cm, 'modcontext'=>$context));
if ($fromform = $mform_add->get_data()) {
$duration = $fromform->durtime['hours']*HOURSECS + $fromform->durtime['minutes']*MINSECS;
$now = time();
if (isset($fromform->addmultiply)) {
$startdate = $fromform->sessiondate;// + $fromform->stime['hour']*3600 + $fromform->stime['minute']*60;
$starttime = $startdate - usergetmidnight($startdate);
$enddate = $fromform->sessionenddate + ONE_DAY; // because enddate in 0:0am
//get number of days
$days = (int)ceil(($enddate - $startdate) / ONE_DAY);
if($days <= 0)
error(get_string('wrongdatesselected','attforblock'), "sessions.php?id=$id&amp;action=add");
else {
add_to_log($course->id, 'attendance', 'multiply sessions added', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
// Getting first day of week
$sdate = $startdate;
$dinfo = usergetdate($sdate);
if ($CFG->calendar_startwday === '0') { //week start from sunday
$startweek = $startdate - $dinfo['wday'] * ONE_DAY; //call new variable
} else {
$wday = $dinfo['wday'] === 0 ? 7 : $dinfo['wday'];
$startweek = $startdate - ($wday-1) * ONE_DAY;
}
// Adding sessions
$wdaydesc = array(0=>'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
while ($sdate < $enddate) {
if($sdate < $startweek + ONE_WEEK) {
$dinfo = usergetdate($sdate);
if(key_exists($wdaydesc[$dinfo['wday']] ,$fromform->sdays)) {
//check whether this date there is in our session days
// if(count_records('attendance_sessions', 'courseid', $course->id, 'sessdate', $sdate) > 0) {
// notify(strftime(get_string('strftimedmy', 'attforblock'), $sdate).': '.get_string('sessionexist','attforblock'));
// $sdate += ONE_DAY;
// continue;
// }
$rec->courseid = $course->id;
$rec->attendanceid = $attforblock->id;
$rec->sessdate = usergetmidnight($sdate) + $starttime;
$rec->duration = $duration;
$rec->description = $fromform->sdescription;
$rec->timemodified = $now;
if ($fromform->sessiontype == COMMONSESSION) {
if(!$DB->insert_record('attendance_sessions', $rec))
error(get_string('erroringeneratingsessions','attforblock'), "sessions.php?id=$id&amp;action=add");
} else {
foreach ($fromform->groups as $groupid) {
$rec->groupid = $groupid;
if(!insert_record('attendance_sessions', $rec))
error(get_string('erroringeneratingsessions','attforblock'), "sessions.php?id=$id&amp;action=add");
}
}
}
$sdate += ONE_DAY;
} else {
$startweek += ONE_WEEK * $fromform->period;
$sdate = $startweek;
}
}
notice(get_string('sessionsgenerated','attforblock'));
}
} else {
// insert one session
$rec->courseid = $course->id;
$rec->attendanceid = $attforblock->id;
$rec->sessdate = $fromform->sessiondate;
$rec->duration = $duration;
$rec->description = $fromform->sdescription;
$rec->timemodified = $now;
if ($fromform->sessiontype == COMMONSESSION) {
if(insert_record('attendance_sessions', $rec)) {
add_to_log($course->id, 'attendance', 'one session added', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
notice(get_string('sessionadded','attforblock'));
} else
error(get_string('errorinaddingsession','attforblock'), "sessions.php?id=$id&amp;action=add");
} else {
foreach ($fromform->groups as $groupid) {
$rec->groupid = $groupid;
if(!insert_record('attendance_sessions', $rec))
error(get_string('errorinaddingsession','attforblock'), "sessions.php?id=$id&amp;action=add");
}
add_to_log($course->id, 'attendance', 'one session added', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
notice(get_string('sessionadded','attforblock'));
}
}
}
$mform_add->display();
}
//////////////////////////////////////////////////////////
// Updating sessions
//////////////////////////////////////////////////////////
if ($action === 'update') {
$sessionid = required_param('sessionid');
$mform_update = new mod_attforblock_update_form('sessions.php', array('course'=>$course,
'cm'=>$cm,
'modcontext'=>$context,
'sessionid'=>$sessionid));
if ($mform_update->is_cancelled()) {
redirect('manage.php?id='.$id);
}
if ($fromform = $mform_update->get_data()) {
if (!$att = $DB->get_record('attendance_sessions', array('id'=> $sessionid) )) {
error('No such session in this course');
}
// $newdate = mktime($newhour, $newminute, 0, $newmonth, $newday, $newyear); //new variables called here
//check for duplicate
// $count = count_records('attendance_sessions','courseid', $course->id, 'sessdate', $newdate);
// if($count != 0 && $newdate != $att->sessdate) //duplicate session exists
// error(get_string('sessionalreadyexists','attforblock'),"sessions.php?id=".$id."&amp;sessionid=".
// $sessionid."&amp;sessdate=".$att->sessdate."&amp;action=update");
// else
// {
//update session
$att->sessdate = $fromform->sessiondate;
$att->duration = $fromform->durtime['hours']*HOURSECS + $fromform->durtime['minutes']*MINSECS;
$att->description = $fromform->sdescription;
$att->timemodified = time();
$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);
// }
}
print_heading(get_string('update','attforblock').' ' .get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname);
$mform_update->display();
}
//////////////////////////////////////////////////////////
// Deleting sessions
//////////////////////////////////////////////////////////
if ($action === 'delete') {
$sessionid = required_param('sessionid');
$confirm = optional_param('confirm');
if (!$att = $DB->get_record('attendance_sessions', array('id'=> $sessionid) )) {
error('No such session in this course');
}
if (isset($confirm)) {
$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 = $DB->get_record('attforblock', array('course'=> $course->id));
attforblock_update_grades($attforblockrecord);
redirect('manage.php?id='.$id, get_string('sessiondeleted','attforblock'), 3);
}
print_heading(get_string('deletingsession','attforblock').' :: ' .$course->fullname);
notice_yesno(get_string('deletecheckfull', '', get_string('session', 'attforblock')).
'<br /><br />'.userdate($att->sessdate, get_string('strftimedmyhm', 'attforblock')).': '.
($att->description ? $att->description : get_string('nodescription', 'attforblock')),
"sessions.php?id=$id&amp;sessionid=$sessionid&amp;action=delete&amp;confirm=1", $_SERVER['HTTP_REFERER']);
}
if ($action === 'deleteselected') {
$confirm = optional_param('confirm');
if (isset($confirm)) {
$sessionid = required_param('sessionid');
$ids = implode(',', explode('_', $sessionid));
$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 = $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 = $DB->get_records_list('attendance_sessions', array('id'=> $slist), 'sessdate');
print_heading(get_string('deletingsession','attforblock').' :: ' .$course->fullname);
$message = '<br />';
foreach ($sessions as $att) {
$message .= '<br />'.userdate($att->sessdate, get_string('strftimedmyhm', 'attforblock')).': '.
($att->description ? $att->description : get_string('nodescription', 'attforblock'));
}
$slist = implode('_', array_keys($fromform->sessid));
notice_yesno(get_string('deletecheckfull', '', get_string('sessions', 'attforblock')).$message,
"sessions.php?id=$id&amp;sessionid=$slist&amp;action=deleteselected&amp;confirm=1", $_SERVER['HTTP_REFERER']);
}
//////////////////////////////////////////////////////////
// Change duration
//////////////////////////////////////////////////////////
if ($action === 'changeduration') {
$fromform = data_submitted();
$slist = isset($fromform->sessid) ? implode('_', array_keys($fromform->sessid)) : '';
$mform_duration = new mod_attforblock_duration_form('sessions.php', array('course'=>$course,
'cm'=>$cm,
'modcontext'=>$context,
'ids'=>$slist));
if ($mform_duration->is_cancelled()) {
redirect('manage.php?id='.$id);
}
if ($fromform = $mform_duration->get_data()) {
$now = time();
$slist = implode(',', explode('_', $fromform->ids));
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;
$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);
}
print_heading(get_string('update','attforblock').' ' .get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname);
$mform_duration->display();
}
print_footer($course);
?>

66
_styles.php

File diff suppressed because one or more lines are too long

125
_view.php

@ -1,125 +0,0 @@
<?PHP // $Id: view.php,v 1.3.2.2 2009/02/23 19:22:41 dlnsk Exp $
/// This page prints a particular instance of attforblock
/// (Replace attforblock with the name of your module)
require_once("../../config.php");
require_once('locallib.php');
$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', 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 = $DB->get_record("course_modules", array("id"=> $id))) {
error("Course Module ID was incorrect");
}
if (! $course = $DB->get_record("course", array("id"=> $cm->course))) {
error("Course is misconfigured");
}
if (! $attforblock = $DB->get_record("attforblock", array("id"=> $cm->instance))) {
error("Course module is incorrect");
}
} else {
error("Module id is incorrect.");
// if (! $attforblock = get_record("attforblock", "id", $a)) {
// error("Course module is incorrect");
// }
// if (! $course = get_record("course", "id", $attforblock->course)) {
// error("Course is misconfigured");
// }
// if (! $cm = get_coursemodule_from_instance("attforblock", $attforblock->id, $course->id)) {
// error("Course Module ID was incorrect");
// }
}
require_login($course->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
if (!$studentid && (has_capability('mod/attforblock:manageattendances', $context) ||
has_capability('mod/attforblock:takeattendances', $context) ||
has_capability('mod/attforblock:changeattendances', $context))) {
redirect("manage.php?id=$cm->id");
}
if (!$studentid && has_capability('mod/attforblock:viewreports', $context)) {
redirect("report.php?id=$cm->id");
}
if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course");
}
if ($view)
set_current_view($course->id, $_GET['view']);
else
$view = get_current_view($course->id, 'months');
require_capability('mod/attforblock:view', $context);
$student = false;
if ($studentid) {
if ($studentid == $USER->id or has_capability('mod/attforblock:viewreports', $context)) {
if (!$student = $DB->get_record('user', array('id'=> $studentid) )) {
error("No such user in this course");
}
}
}
// if (empty($student) && has_capability('mod/attforblock:manageattendances', $context)) {
// redirect("manage.php?id=$cm->id");
// }
if ($student) {
$user = $student;
}
if ($printing) {
if ($mode === 'thiscourse') {
print_header('', $course->fullname.' - '.get_string('attendancereport','attforblock'));
print_user_attendaces($user, $cm, $attforblock, $course, 'printing');
} else {
print_header('', get_string('attendancereport','attforblock'));
print_user_attendaces($user, $cm, $attforblock, 0, 'printing');
}
exit();
}
/// Print headers
$navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activityinstance');
$navlinks[] = array('name' => get_string('attendancereport', 'attforblock'), 'link' => null, 'type' => 'title');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: ".$attforblock->name.' - ' .get_string('export', 'quiz'), $course->fullname,
$navigation, "", "", true, "&nbsp;", navmenu($course));
//add info to log
add_to_log($course->id, 'attendance', 'student view', "mod/attforblock/view.php?course=$course->id&amp;student=$USER->id", $USER->lastname.' '.$USER->firstname);
// print_heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname);
/// Prints out tabs
$currenttab = $mode;
$studstr = $student ? '&amp;student='.$student->id : '';
$toprow = array();
$toprow[] = new tabobject('thiscourse', "view.php?id=$id&amp;mode=thiscourse{$studstr}",
get_string('thiscourse','attforblock'));
$toprow[] = new tabobject('allcourses', "view.php?id=$id&amp;mode=allcourses{$studstr}",
get_string('allcourses','attforblock'));
print_tabs(array($toprow), $currenttab);
if ($mode === 'thiscourse') {
print_user_attendaces($user, $cm, $attforblock, $course);
} else {
print_user_attendaces($user, $cm, $attforblock);
}
print_footer($course);
?>
Loading…
Cancel
Save