diff --git a/lang/en_utf8/attforblock.php b/lang/en_utf8/attforblock.php
index 0c3406d..7bda8a4 100644
--- a/lang/en_utf8/attforblock.php
+++ b/lang/en_utf8/attforblock.php
@@ -40,6 +40,7 @@ $string['calweekdays'] = ' \"Su\", \"Mo\", \"Tu\", \"We\", \"Th\", \"Fr\", \"Sa\
$string['changeduration'] = 'Change duration';
$string['changesession'] = 'Change session';
$string['commonsession'] = 'Common';
+$string['commonsessions'] = 'Common';
$string['countofselected'] = 'Count of selected';
$string['createmultiplesessions'] = 'Create multiple sessions';
$string['createonesession'] = 'Create one session for the course';
diff --git a/lang/ru_utf8/attforblock.php b/lang/ru_utf8/attforblock.php
index 1e90c91..bc688c3 100644
--- a/lang/ru_utf8/attforblock.php
+++ b/lang/ru_utf8/attforblock.php
@@ -39,6 +39,7 @@ $string['calweekdays'] = ' \"Вс\", \"Пн\", \"Вт\", \"Ср\", \"Чт\", \"
$string['changeduration'] = 'Изменить продолжительность';
$string['changesession'] = 'Изменить занятие';
$string['commonsession'] = 'Общее';
+$string['commonsessions'] = 'Общие';
$string['countofselected'] = 'Выбрано занятий';
$string['createmultiplesessions'] = 'Создать несколько занятий';
$string['createonesession'] = 'Создать одно занятие для курса';
diff --git a/locallib.php b/locallib.php
index 147d58f..8e1dd22 100644
--- a/locallib.php
+++ b/locallib.php
@@ -8,6 +8,10 @@ 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);
+
function show_tabs($cm, $context, $currenttab='sessions')
{
$toprow = array();
@@ -335,9 +339,9 @@ function print_user_attendaces($user, $cm, $attforblock, $course = 0, $printing
echo '
|
';
}
-function print_filter_controls($url, $id, $sort=NULL, $printgroupselector=false) {
+function print_filter_controls($url, $id, $sort=NULL, $printselector=WITHOUT_SELECTOR) {
- global $current, $view, $cm;
+ global $SESSION, $current, $view, $cm;
$date = usergetdate($current);
$mday = $date['mday'];
@@ -383,7 +387,7 @@ function print_filter_controls($url, $id, $sort=NULL, $printgroupselector=false)
$link = $url . "?id=$id" . ($sort ? "&sort=$sort" : "");
- if ($printgroupselector) {
+ if ($printselector === GROUP_SELECTOR) {
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
$groupselector = '';
@@ -392,8 +396,84 @@ function print_filter_controls($url, $id, $sort=NULL, $printgroupselector=false)
($groupmode && has_capability('moodle/site:accessallgroups', $context))) {
$groupselector = groups_print_activity_menu($cm, $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 ($group > -2) {
+ if (!array_key_exists('attsessiontype', $SESSION)) {
+ $SESSION->attsessiontype = array();
+ }
+ $SESSION->attsessiontype[$cm->course] = $group;
+ }
+ 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.'&group=', $selector, 'selectgroup', $currentgroup, '', '', '', true, 'self', get_string('sessions', 'attforblock'));
+ }
+
+ $sessiontypeselector = ''.$sessiontypeselector.'
';
}
+
$views['all'] = get_string('all','attforblock');
$views['alltaken'] = get_string('alltaken','attforblock');
$views['months'] = get_string('months','attforblock');
@@ -410,7 +490,11 @@ function print_filter_controls($url, $id, $sort=NULL, $printgroupselector=false)
echo "";
echo "
";
- echo "$groupselector | ";
+ if ($printselector === GROUP_SELECTOR) {
+ echo "$groupselector | ";
+ } elseif ($printselector === SESSION_TYPE_SELECTOR) {
+ echo "$sessiontypeselector | ";
+ }
if ($curdatetxt) {
$curdatecontrols = "◄";
diff --git a/manage.php b/manage.php
index 94cadf5..518124e 100644
--- a/manage.php
+++ b/manage.php
@@ -103,8 +103,8 @@ function print_sessions_list($course) {
else
set_current_date ($course->id, $current);
- list($startdate, $enddate) =
- print_filter_controls("manage.php", $id);
+ list($startdate, $enddate, $currentgroup) =
+ print_filter_controls("manage.php", $id, NULL, SESSION_TYPE_SELECTOR);
if ($startdate && $enddate) {
$where = "courseid={$course->id} AND sessdate >= $course->startdate AND sessdate >= $startdate AND sessdate < $enddate";
@@ -112,6 +112,10 @@ function print_sessions_list($course) {
$where = "courseid={$course->id} AND sessdate >= $course->startdate";
}
+ if ($currentgroup > -1) {
+ $where .= " AND groupid=$currentgroup";
+ }
+
$qry = get_records_select('attendance_sessions', $where/*"courseid = $course->id AND sessdate >= $course->startdate"*/, 'sessdate asc');
$i = 0;
$table->width = '100%';
diff --git a/report.php b/report.php
index 6d2fb8d..5ac5d05 100644
--- a/report.php
+++ b/report.php
@@ -69,7 +69,7 @@
set_current_date ($course->id, $current);
list($startdate, $enddate, $currentgroup) =
- print_filter_controls("report.php", $id, $sort, true);
+ print_filter_controls("report.php", $id, $sort, GROUP_SELECTOR);
if ($startdate && $enddate) {
$where = "courseid={$course->id} AND sessdate >= $course->startdate AND sessdate >= $startdate AND sessdate < $enddate";