Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

Commit

Permalink
Initial commit. Version 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
andreev-artem committed Jul 9, 2010
0 parents commit b860850
Show file tree
Hide file tree
Showing 74 changed files with 6,013 additions and 0 deletions.
1,237 changes: 1,237 additions & 0 deletions CHANGES

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
*********************************************************************************************
****** WARNING: THIS MODULE IS IN DEVELOPMENT. USE WITH CAUTION ******
*********************************************************************************************

--------
ABOUT
--------
This is version 2.1.x of the "Attendance" module (attforblock). It is still IN DEVELOPMENT
and should not be considered a stable release unless otherwise noted.
It has been tested on Moodle 1.9+, MySQL and PHP 5.2+.

The "Attendance" module is developed by Dmitry Pupinin, Novosibirsk, Russia.

This block may be distributed under the terms of the General Public License
(see http://www.gnu.org/licenses/gpl.txt for details)

-----------
PURPOSE
-----------
The attendance module and block are designed to allow instructors of a course keep an attendance log of the students in their courses. The instructor will setup the frequency of his classes (# of days per week & length of course) and the attendance is ready for use. To take attendance, the instructor clicks on the "Update Attendance" button and is presented with a list of all the students in that course, along with 4 options: Present, Absent, Late & Excused, with a Remarks textbox. Instructors can download the attendance for their course in Excel format or text format.
Only the instructor can update the attendance data. However, a student gets to see his attendance record.

----------------
INSTALLATION
----------------
The attendance follows standard installation procedures. Place the "attendance" directory in your blocks directory, "attforblock" directory in your mod directory. Please delete old language files from your moodledata/lang/en directory if you are upgrading the module. Then visit the Admin page in Moodle to activate it.
49 changes: 49 additions & 0 deletions RELEASES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
****************************************************************************
****** WARNING: ATTENDANCE MODULE IS IN DEVELOPMENT. USE WITH CAUTION ******
****************************************************************************

--------------
RELEASE NOTES
--------------
1.0 - 09 jan 2006 Dmitry Pupinin [moodle.org member]
+ basic functions

1.0.1 - 23 jan 2006 Dmitry Pupinin [moodle.org member]
+ attendance displayed on user's quick and full report pages

2.0 - 10 may 2007 - Dmitry Pupinin [moodle.org member]
* code rewrited. General code moved from block to attforblock module.
* this version only compatible with latest Moodle 1.8 (without grouping!)

2.0.2 - 06 jul 2007 - Dmitry Pupinin [moodle.org member]
* bug fixed: empty Gradebook
* bug fixed: error if block instance added before module instance
* bug fixed: wrong link on report tab when no session added
* bug fixed: Activity report looks good
+ link from Activities block point directly to Attendances (because it can't be more than one)
* bug fixed: Wrong link when adding a session for a date that had already been added
* bug fixed: Error when settings updated
* en_utf8 lang updated (thanks to A. T. Wyatt)
+ en_us_utf8 lang added (contain only differences from en_utf8)

2.0.3 - 27 jan 2008 - Dmitry Pupinin [moodle.org member]
* bug fixed: If session have apostrophes in the description it can't will be changed to "taken"
(you can't lost any data but upgrading strongly recommended)
+ french language added
* bug fixed: functions for work with groups changed in Moodle 1.9

2.0.4 - 19 jun 2008 - Dmitry Pupinin [moodle.org member]
+ compatibility with Gradebook of Moodle 1.9

2.1.0 - 24 jan 2009 - Dmitry Pupinin [moodle.org member]
+ unlimited number of statuses
+ unlimited sessions in day
+ reset feature
* permissions improved
* backup/restore improved
* export improved

2.1.0 - 28 feb 2009 - Dmitry Pupinin [moodle.org member]
+ hidden sessions displayed
* format of backup changed
* bug fixes
89 changes: 89 additions & 0 deletions add_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php // $Id: add_form.php,v 1.1.2.2 2009/02/23 19:22:42 dlnsk Exp $

require_once($CFG->libdir.'/formslib.php');

class mod_attforblock_add_form extends moodleform {

function definition() {

global $CFG;
$mform =& $this->_form;

$course = $this->_customdata['course'];
$cm = $this->_customdata['cm'];
// $coursecontext = $this->_customdata['coursecontext'];
$modcontext = $this->_customdata['modcontext'];
// $forum = $this->_customdata['forum'];
// $post = $this->_customdata['post']; // hack alert


$mform->addElement('header', 'general', get_string('addsession','attforblock'));//fill in the data depending on page params
//later using set_data
$mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions','attforblock'));
$mform->setHelpButton('addmultiply', array('createmultiplesessions', get_string('createmultiplesessions','attforblock'), 'attforblock'));

// $mform->addElement('date_selector', 'sessiondate', get_string('sessiondate','attforblock'));
$mform->addElement('date_time_selector', 'sessiondate', get_string('sessiondate','attforblock'));

for ($i=0; $i<=23; $i++) {
$hours[$i] = sprintf("%02d",$i);
}
for ($i=0; $i<60; $i+=5) {
$minutes[$i] = sprintf("%02d",$i);
}
$durtime = array();
$durtime[] =& MoodleQuickForm::createElement('select', 'hours', get_string('hour', 'form'), $hours, false, true);
$durtime[] =& MoodleQuickForm::createElement('select', 'minutes', get_string('minute', 'form'), $minutes, false, true);
$mform->addGroup($durtime, 'durtime', get_string('duration','attforblock'), array(' '), true);

$mform->addElement('date_selector', 'sessionenddate', get_string('sessionenddate','attforblock'));
$mform->disabledIf('sessionenddate', 'addmultiply', 'notchecked');

$sdays = array();
if ($CFG->calendar_startwday === '0') { //week start from sunday
$sdays[] =& MoodleQuickForm::createElement('checkbox', 'Sun', '', get_string('sunday','calendar'));
}
$sdays[] =& MoodleQuickForm::createElement('checkbox', 'Mon', '', get_string('monday','calendar'));
$sdays[] =& MoodleQuickForm::createElement('checkbox', 'Tue', '', get_string('tuesday','calendar'));
$sdays[] =& MoodleQuickForm::createElement('checkbox', 'Wed', '', get_string('wednesday','calendar'));
$sdays[] =& MoodleQuickForm::createElement('checkbox', 'Thu', '', get_string('thursday','calendar'));
$sdays[] =& MoodleQuickForm::createElement('checkbox', 'Fri', '', get_string('friday','calendar'));
$sdays[] =& MoodleQuickForm::createElement('checkbox', 'Sat', '', get_string('saturday','calendar'));
if ($CFG->calendar_startwday !== '0') { //week start from sunday
$sdays[] =& MoodleQuickForm::createElement('checkbox', 'Sun', '', get_string('sunday','calendar'));
}
$mform->addGroup($sdays, 'sdays', get_string('sessiondays','attforblock'), array(' '), true);
$mform->disabledIf('sdays', 'addmultiply', 'notchecked');

$period = array(1=>1,2,3,4,5,6,7,8);
$periodgroup = array();
$periodgroup[] =& MoodleQuickForm::createElement('select', 'period', '', $period, false, true);
$periodgroup[] =& MoodleQuickForm::createElement('static', 'perioddesc', '', get_string('week','attforblock'));
$mform->addGroup($periodgroup, 'periodgroup', get_string('period','attforblock'), array(' '), false);
$mform->disabledIf('periodgroup', 'addmultiply', 'notchecked');

$mform->addElement('text', 'sdescription', get_string('description', 'attforblock'), 'size="48"');
$mform->setType('sdescription', PARAM_TEXT);
$mform->addRule('sdescription', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');

//-------------------------------------------------------------------------------
// buttons
$submit_string = get_string('addsession', 'attforblock');
$this->add_action_buttons(false, $submit_string);

$mform->addElement('hidden', 'id', $cm->id);
$mform->addElement('hidden', 'action', 'add');

}

// function validation($data, $files) {
// $errors = parent::validation($data, $files);
// if (($data['timeend']!=0) && ($data['timestart']!=0)
// && $data['timeend'] <= $data['timestart']) {
// $errors['timeend'] = get_string('timestartenderror', 'forum');
// }
// return $errors;
// }

}
?>
190 changes: 190 additions & 0 deletions attendances.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<?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);
$group = optional_param('group', -1, PARAM_INT); // Group to show
$sort = optional_param('sort','lastname', PARAM_ALPHA);

if (! $cm = get_record('course_modules', 'id', $id)) {
error('Course Module ID was incorrect');
}

if (! $course = get_record('course', 'id', $cm->course)) {
error('Course is misconfigured');
}

require_login($course->id);

if (! $attforblock = get_record('attforblock', 'id', $cm->instance)) {
error("Course module is incorrect");
}
if (! $user = get_record('user', '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($course->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 = get_record('attforblock', 'course', $course->id);

foreach($students as $student) {
if ($log = get_record('attendance_log', 'sessionid', $sessionid, 'studentid', $student->studentid)) {
$student->id = $log->id; // this is id of log
update_record('attendance_log', $student);
} else {
insert_record('attendance_log', $student);
}
}
set_field('attendance_sessions', 'lasttaken', $now, 'id', $sessionid);
set_field('attendance_sessions', 'lasttakenby', $USER->id, '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
$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 = get_record('attendance_sessions', 'id', $sessionid)) {
error("Required Information is missing", "manage.php?id=".$id);
}
$help = helpbutton ('updateattendance', get_string('help'), 'attforblock', true, false, '', true);
$update = count_records('attendance_log', 'sessionid', $sessionid);

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);
print_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);

if ($currentgroup) {
$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);
}

$sort = $sort == 'firstname' ? 'firstname' : 'lastname';
/// Now we need a menu for separategroups as well!
if ($groupmode == VISIBLEGROUPS ||
($groupmode && has_capability('moodle/site:accessallgroups', $context))) {
groups_print_activity_menu($cm, "attendances.php?id=$id&amp;sessionid=$sessionid&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($course->id);
$i = 3;
foreach($statuses as $st) {
$tabhead[] = "<a href=\"javascript:select_all_in('TD', 'cell c{$i}', null);\"><u>$st->acronym</u></a>";
$i++;
}
$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);
$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 = get_record('attendance_log', '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) {
@$table->data[$student->id][] = '<input name="student'.$student->id.'" type="radio" value="'.$st->id.'" '.($st->id == $att->statusid ? 'checked' : '').'>';
}
$table->data[$student->id][] = '<input type="text" name="remarks'.$student->id.'" size="" value="'.($att ? $att->remarks : '').'">';
}

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="formfrom" value="editsessvals">';
echo '<center><input type="submit" name="esv" value="'.get_string('ok').'"></center>';
echo '</form>';
} 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);

?>
Loading

0 comments on commit b860850

Please sign in to comment.