diff --git a/calendar.js b/calendar.js
new file mode 100644
index 0000000..eb32974
--- /dev/null
+++ b/calendar.js
@@ -0,0 +1,96 @@
+document.body.className += ' yui-skin-sam';
+
+YAHOO.util.Event.onDOMReady(function(){
+
+ var Event = YAHOO.util.Event,
+ Dom = YAHOO.util.Dom,
+ dialog, calendar;
+
+ var showBtn = Dom.get("show");
+
+ Event.on(showBtn, "click", function() {
+
+ // Lazy Dialog Creation - Wait to create the Dialog, and setup document click listeners, until the first time the button is clicked.
+ if (!dialog) {
+
+ // Hide Calendar if we click anywhere in the document other than the calendar
+ Event.on(document, "click", function(e) {
+ var el = Event.getTarget(e);
+ var dialogEl = dialog.element;
+ if (el != dialogEl && !Dom.isAncestor(dialogEl, el) && el != showBtn && !Dom.isAncestor(showBtn, el)) {
+ dialog.hide();
+ }
+ });
+
+ function resetHandler() {
+ calendar.cfg.setProperty("pagedate", calendar.today);
+ calendar.render();
+ }
+
+ function closeHandler() {
+ dialog.hide();
+ }
+
+ dialog = new YAHOO.widget.Dialog("container", {
+ visible:false,
+ context:["show", "tl", "bl"],
+ buttons:[{text: cal_today, handler: resetHandler, isDefault:true}, {text: cal_close, handler: closeHandler}],
+ draggable:false,
+ close:false
+ });
+ dialog.setHeader('');
+ dialog.setBody('
');
+ dialog.render(document.body);
+
+ dialog.showEvent.subscribe(function() {
+ if (YAHOO.env.ua.ie) {
+ // Since we're hiding the table using yui-overlay-hidden, we
+ // want to let the dialog know that the content size has changed, when
+ // shown
+ dialog.fireEvent("changeContent");
+ }
+ });
+ }
+
+ // Lazy Calendar Creation - Wait to create the Calendar until the first time the button is clicked.
+ if (!calendar) {
+
+ calendar = new YAHOO.widget.Calendar("cal", {
+ iframe:false, // Turn iframe off, since container has iframe support.
+ hide_blank_weeks:true // Enable, to demonstrate how we handle changing height, using changeContent
+ });
+
+ calendar.cfg.setProperty("start_weekday", cal_start_weekday);
+ calendar.cfg.setProperty("MONTHS_LONG", cal_months);
+ calendar.cfg.setProperty("WEEKDAYS_SHORT", cal_week_days);
+ calendar.select(new Date(cal_cur_date*1000));
+ calendar.render();
+
+ calendar.selectEvent.subscribe(function() {
+ if (calendar.getSelectedDates().length > 0) {
+
+ Dom.get("current").value = calendar.getSelectedDates()[0] / 1000;
+
+ Dom.get("currentdate").submit();
+ }
+ dialog.hide();
+ });
+
+ calendar.renderEvent.subscribe(function() {
+ // Tell Dialog it's contents have changed, which allows
+ // container to redraw the underlay (for IE6/Safari2)
+ dialog.fireEvent("changeContent");
+ });
+ }
+
+ var seldate = calendar.getSelectedDates();
+
+ if (seldate.length > 0) {
+ // Set the pagedate to show the selected date if it exists
+ calendar.cfg.setProperty("pagedate", seldate[0]);
+ calendar.render();
+ }
+
+ dialog.show();
+ });
+});
diff --git a/lang/en_utf8/attforblock.php b/lang/en_utf8/attforblock.php
index c693e6b..eb4c0b6 100644
--- a/lang/en_utf8/attforblock.php
+++ b/lang/en_utf8/attforblock.php
@@ -15,6 +15,7 @@ $string['add'] = 'Add';
$string['addmultiplesessions'] = 'Add multiple sessions';
$string['addsession'] = 'Add session';
$string['allcourses'] = 'All courses';
+$string['all'] = 'All';
$string['alltaken'] = 'All taken';
$string['attendanceforthecourse'] = 'Attendance for the course';
$string['attendancegrade'] = 'Attendance grade';
@@ -37,6 +38,7 @@ $string['commonsession'] = 'Common';
$string['countofselected'] = 'Count of selected';
$string['createmultiplesessions'] = 'Create multiple sessions';
$string['createonesession'] = 'Create one session for the course';
+$string['days'] = 'Day';
$string['defaults'] = 'Defaults';
$string['delete'] = 'Delete';
$string['deletelogs'] = 'Delete attendance data';
diff --git a/lang/ru_utf8/attforblock.php b/lang/ru_utf8/attforblock.php
index 4d07759..1e90c91 100644
--- a/lang/ru_utf8/attforblock.php
+++ b/lang/ru_utf8/attforblock.php
@@ -14,6 +14,7 @@ $string['acronym'] = 'Сокращ.';
$string['add'] = 'Добавить';
$string['addmultiplesessions'] = 'Добавить несколько занятий';
$string['addsession'] = 'Добавить занятие';
+$string['all'] = 'Все';
$string['alltaken'] = 'Все прошедшие';
$string['attendanceforthecourse'] = 'Посещаемость для курса';
$string['attendancegrade'] = 'Оценка за посещаемость';
@@ -30,12 +31,18 @@ $string['attforblock:takeattendances'] = 'Отметка посещаемост
$string['attforblock:view'] = 'Просмотр посещаемости';
$string['attforblock:viewreports'] = 'Просмотр отчетов';
$string['attrecords'] = 'Отметок о посещаемости';
+$string['calclose'] = 'Закрыть';
+$string['calmonths'] = '\"Январь\", \"Февраль\", \"Март\", \"Апрель\", \"Май\", \"Июнь\", \"Июль\", \"Август\", \"Сентябрь\", \"Октябрь\", \"Ноябрь\", \"Декабрь\"';
+$string['calshow'] = 'Выбрать дату';
+$string['caltoday'] = 'Сегодня';
+$string['calweekdays'] = ' \"Вс\", \"Пн\", \"Вт\", \"Ср\", \"Чт\", \"Пт\", \"Сб\"';
$string['changeduration'] = 'Изменить продолжительность';
$string['changesession'] = 'Изменить занятие';
$string['commonsession'] = 'Общее';
$string['countofselected'] = 'Выбрано занятий';
$string['createmultiplesessions'] = 'Создать несколько занятий';
$string['createonesession'] = 'Создать одно занятие для курса';
+$string['days'] = 'День';
$string['defaults'] = 'По умолчанию';
$string['delete'] = 'Удалить';
$string['deleteselected'] = 'Удалить выбранные';
@@ -61,7 +68,7 @@ $string['indetail'] = 'Подробнее...';
$string['moduledescription'] = 'Вы можете добавить только один данный модуль в каждый курс.
Удаление этого модуля не повлечет удаление данных о посещаемости!';
$string['modulename'] = 'Посещаемость';
$string['modulenameplural'] = 'Посещаемость';
-$string['months'] = 'По месяцам';
+$string['months'] = 'Месяц';
$string['myvariables'] = 'Мои переменные';
$string['newdate'] = 'Новая дата';
$string['newduration'] = 'New duration';
@@ -113,7 +120,7 @@ $string['variable'] = 'переменную';
$string['variablesupdated'] = 'Переменные успешно обновлены';
$string['versionforprinting'] = 'версия для печати';
$string['week'] = 'неделя(и)';
-$string['weeks'] = 'По неделям';
+$string['weeks'] = 'Неделя';
$string['youcantdo'] = 'Вы ничего не можете сделать';
?>
diff --git a/locallib.php b/locallib.php
index f452ab0..40310bb 100644
--- a/locallib.php
+++ b/locallib.php
@@ -184,13 +184,28 @@ function set_current_view($courseid, $view) {
return $SESSION->currentattview[$courseid] = $view;
}
-function get_current_view($courseid) {
+function get_current_view($courseid, $defaultview='weeks') {
global $SESSION;
if (isset($SESSION->currentattview[$courseid]))
return $SESSION->currentattview[$courseid];
else
- return 'all';
+ 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) {
@@ -220,7 +235,7 @@ function print_attendance_table($user, $course, $attforblock) {
}
function print_user_attendaces($user, $cm, $attforblock, $course = 0, $printing = null) {
- global $CFG, $COURSE, $mode;
+ global $CFG, $COURSE, $mode, $current, $view, $id;
echo '';
if (!$printing) {
@@ -248,7 +263,7 @@ function print_user_attendaces($user, $cm, $attforblock, $course = 0, $printing
echo get_string('attendancenotstarted','attforblock');
}
} else {
- $stqry = "SELECT ats.id,ats.courseid
+ $stqry = "SELECT ats.id,ats.courseid
FROM {$CFG->prefix}attendance_log al
JOIN {$CFG->prefix}attendance_sessions ats
ON al.sessionid = ats.id
@@ -275,44 +290,158 @@ function print_user_attendaces($user, $cm, $attforblock, $course = 0, $printing
if ($course) {
+ if ($current == 0)
+ $current = get_current_date($course->id);
+ else
+ set_current_date ($course->id, $current);
+
+ list($startdate, $enddate) =
+ print_filter_controls("view.php", $id);
+
+ if ($startdate && $enddate) {
+ $where = "ats.courseid={$course->id} AND al.studentid = {$user->id} AND ats.sessdate >= $startdate AND ats.sessdate < $enddate";
+ } else {
+ $where = "ats.courseid={$course->id} AND al.studentid = {$user->id}";
+ }
+
$stqry = "SELECT ats.sessdate,ats.description,al.statusid,al.remarks
FROM {$CFG->prefix}attendance_log al
JOIN {$CFG->prefix}attendance_sessions ats
- ON al.sessionid = ats.id
- WHERE ats.courseid = {$course->id} AND al.studentid = {$user->id}
- ORDER BY ats.sessdate asc";
+ ON al.sessionid = ats.id";
+ $stqry .= " WHERE " . $where;
+ $stqry .= " ORDER BY ats.sessdate asc";
+
if ($sessions = get_records_sql($stqry)) {
$statuses = get_statuses($course->id);
- ?>
-
-
-
- # |
- |
- |
- |
- |
- |
-
- $session)
+
+ $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)
{
- ?>
-
- |
- sessdate, get_string('strftimedmyw', 'attforblock')); //userdate($students->sessdate,'%d.%m.%y (%a)', 99, false);?> |
- sessdate, get_string('strftimehm', 'attforblock')); ?> |
- description) ? get_string('nodescription', 'attforblock') : $session->description; ?> |
- statusid]->description ?> |
- remarks;?> |
-
- ';
+ $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 ' |
';
}
+
+function print_filter_controls($url, $id, $sort=NULL, $printgroupselector=false) {
+
+ global $current, $view, $cm;
+
+ list(,,,$mday, $wday, $month, $year) = array_values(usergetdate($current));
+ $currentdatecontrols = '';
+ switch ($view) {
+ case 'days':
+ $format = get_string('strftimedm', 'attforblock');
+ $startdate = make_timestamp($year, $month, $mday);
+ $enddate = make_timestamp($year, $month, $mday + 1);
+ $prevcur = make_timestamp($year, $month, $mday - 1);
+ $nextcur = make_timestamp($year, $month, $mday + 1);
+ $curdatetxt = userdate($startdate, $format);
+ break;
+ case 'weeks':
+ $format = get_string('strftimedm', 'attforblock');
+ $startdate = make_timestamp($year, $month, $mday - $wday + 1);
+ $enddate = make_timestamp($year, $month, $mday + 7 - $wday);
+ $prevcur = $startdate - WEEKSECS;
+ $nextcur = $startdate + WEEKSECS;
+ $curdatetxt = userdate($startdate, $format)." - ".userdate($enddate, $format);
+ break;
+ case 'months':
+ $format = '%B';
+ $startdate = make_timestamp($year, $month);
+ $enddate = make_timestamp($year, $month + 1);
+ $prevcur = make_timestamp($year, $month - 1);
+ $nextcur = make_timestamp($year, $month + 1);
+ $curdatetxt = userdate($startdate, $format);
+ break;
+ case 'alltaken':
+ $startdate = 1;
+ $enddate = $current;
+ break;
+ case 'all':
+ $startdate = 0;
+ $enddate = 0;
+ break;
+ }
+
+ $link = $url . "?id=$id" . ($sort ? "&sort=$sort" : "");
+
+ if ($printgroupselector) {
+ $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, $link, true);
+ }
+ }
+
+ $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 = '';
+ foreach ($views as $key => $sview) {
+ if ($key != $view)
+ $viewcontrols .= "$sview";
+ else
+ $viewcontrols .= "$sview";
+ }
+ $viewcontrols .= '';
+
+ echo "";
+ echo "
";
+ echo "$groupselector | ";
+
+ if ($curdatetxt) {
+ $curdatecontrols = "◄";
+ $curdatecontrols .= "";
+ $curdatecontrols .= "►";
+ plug_yui_calendar($current);
+ }
+ echo "$curdatecontrols | ";
+ echo "$viewcontrols |
";
+
+ echo "
";
+
+ return array($startdate, $enddate, $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 "\n";
+
+ require_js($CFG->wwwroot . '/mod/attforblock/calendar.js');
+}
?>
diff --git a/manage.php b/manage.php
index 916a608..4a28fc6 100644
--- a/manage.php
+++ b/manage.php
@@ -6,8 +6,10 @@
require_once('../../config.php');
require_once('locallib.php');
- $id = required_param('id', PARAM_INT); // Course Module ID, or
- $from = optional_param('from', PARAM_ACTION);
+ $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);
if (! $cm = get_record('course_modules', 'id', $id)) {
error('Course Module ID was incorrect');
@@ -30,6 +32,11 @@
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
@@ -78,12 +85,26 @@
function print_sessions_list($course) {
- global $CFG, $context, $cm;
+ global $CFG, $context, $cm, $current, $view, $id;
$strhours = get_string('hours');
$strmins = get_string('min');
- $qry = get_records_select('attendance_sessions', "courseid = $course->id AND sessdate >= $course->startdate", 'sessdate asc');
+ if ($current == 0)
+ $current = get_current_date($course->id);
+ else
+ set_current_date ($course->id, $current);
+
+ list($startdate, $enddate) =
+ print_filter_controls("manage.php", $id);
+
+ if ($startdate && $enddate) {
+ $where = "courseid={$course->id} AND sessdate >= $course->startdate AND sessdate >= $startdate AND sessdate < $enddate";
+ } else {
+ $where = "courseid={$course->id} AND sessdate >= $course->startdate";
+ }
+
+ $qry = get_records_select('attendance_sessions', $where/*"courseid = $course->id AND sessdate >= $course->startdate"*/, 'sessdate asc');
$i = 0;
$table->width = '100%';
//$table->tablealign = 'center';
@@ -140,7 +161,7 @@ function print_sessions_list($course) {
$table->data[$sessdata->id][] = '';
unset($desc, $actions);
}
- echo '