';
// This cell has the areas
-$areas = $DB->get_records('block_mrbs_area', null, 'area_name');
+$areas = $DB->get_records('block_mrbs_area', array('instance' => $instance_id), 'area_name');
if (empty($areas)) {
echo get_string('noareas', 'block_mrbs');
@@ -78,11 +77,11 @@
foreach ($areas as $dbarea) {
$area_name_q = urlencode($dbarea->area_name);
$adminurl = new moodle_url('/blocks/mrbs/web/admin.php', array(
- 'area' => $dbarea->id, 'area_name' => $area_name_q, 'sesskey' => sesskey()
+ 'instance' => $instance_id, 'area' => $dbarea->id, 'area_name' => $area_name_q, 'sesskey' => sesskey()
));
- $editroomurl = new moodle_url('/blocks/mrbs/web/edit_area_room.php', array('area' => $dbarea->id, 'sesskey' => sesskey()));
+ $editroomurl = new moodle_url('/blocks/mrbs/web/edit_area_room.php', array('instance' => $instance_id, 'area' => $dbarea->id, 'sesskey' => sesskey()));
$delareaurl = new moodle_url('/blocks/mrbs/web/del.php', array(
- 'area' => $dbarea->id, 'type' => 'area', 'sesskey' => sesskey()
+ 'instance' => $instance_id, 'area' => $dbarea->id, 'type' => 'area', 'sesskey' => sesskey()
));
echo '
| |
'.get_string('addarea', 'block_mrbs').''; diff --git a/web/auth_moodle.php b/web/auth_moodle.php index d3c9d4f..d82fa69 100644 --- a/web/auth_moodle.php +++ b/web/auth_moodle.php @@ -39,16 +39,15 @@ * $auth["session"] = "moodle"; * */ - require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); //for Moodle integration function authValidateUser($user, $pass) { return 1; } -function authGetUserLevel($user) { +function authGetUserLevel($instance_id, $user) { // HACK For Moodle 1.7 With Roles Block... - $context = context_system::instance(); + $context = context_block::instance($instance_id); // Set Access leve for users via MRBS block and Moodle 1.7 roles if (has_capability('block/mrbs:administermrbs', $context)) { diff --git a/web/config.inc.php b/web/config.inc.php index 9c52e5e..4a68726 100644 --- a/web/config.inc.php +++ b/web/config.inc.php @@ -19,10 +19,23 @@ # MRBS Configuration File # You shouldn't have to modify this file as all options can be set via Moode - see CONTRIB-422 ########################################################################### - //For integration with Moodle require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); -$cfg_mrbs = get_config('block/mrbs'); //get Moodle config settings for the MRBS block +global $DB,$CFG; + +$cfg_mrbs = get_config('block/mrbs'); +$instance_id = optional_param('instance', $cfg_mrbs->default_instance, PARAM_INT); +if(! isset($instance_id)) { + throw new \coding_exception('Either instance_id or mrbs->default_instance is required.'); +} +if( $instance_id != $cfg_mrbs->default_instance ){ //get Moodle config settings for this instance of the MRBS block + $tmp = $DB->get_record('block_instances', array('id' => $instance_id), '*', MUST_EXIST); + if(! isset($tmp)) { + throw new \coding_exception('block_instance with id '.$instance_id.' must exist.'); + } + $cfg_mrbs = unserialize(base64_decode($tmp->configdata)); +} + ################### # Database settings ################### diff --git a/web/day.php b/web/day.php index e2a9d99..9e80480 100644 --- a/web/day.php +++ b/web/day.php @@ -21,7 +21,6 @@ include "functions.php"; require_once('mrbs_auth.php'); include "mincals.php"; - $day = optional_param('day', 0, PARAM_INT); $month = optional_param('month', 0, PARAM_INT); $year = optional_param('year', 0, PARAM_INT); @@ -55,13 +54,13 @@ } $baseurl = new moodle_url('/blocks/mrbs/web/day.php', array( - 'day' => $day, 'month' => $month, 'year' => $year + 'instance' => $instance_id, 'day' => $day, 'month' => $month, 'year' => $year )); // Used as basis for URLs throughout this file $thisurl = new moodle_url($baseurl); if ($area > 0) { $thisurl->param('area', $area); } else { - $area = get_default_area(); + $area = get_default_area($instance_id); } if ($morningstarts_minutes > 0) { $thisurl->param('morningstarts_minutes', $morningstarts_minutes); @@ -74,7 +73,7 @@ require_login(); // print the page header -print_header_mrbs($day, $month, $year, $area); +print_header_mrbs($day, $month, $year, $instance_id, $area); // Define the start and end of each day in a way which is not affected by // daylight saving... @@ -95,10 +94,10 @@ // need to show either a select box or a normal html list, // depending on the settings in config.inc.php if ($area_list_format == "select") { - echo make_area_select_html(new moodle_url('/blocks/mrbs/web/day.php'), $area, $year, $month, $day); // from functions.php + echo make_area_select_html(new moodle_url('/blocks/mrbs/web/day.php'), $area, $instance_id, $year, $month, $day); // from functions.php } else { // show the standard html list - $areas = $DB->get_records('block_mrbs_area', null, 'area_name'); + $areas = $DB->get_records('block_mrbs_area', array('instance' => $instance_id), 'area_name'); foreach ($areas as $dbarea) { echo ''; if ($dbarea->id == $area) { @@ -111,7 +110,7 @@ echo " | \n";
//insert the goto room form
- $gotoroom = new moodle_url('/blocks/mrbs/web/gotoroom.php');
+ $gotoroom = new moodle_url('/blocks/mrbs/web/gotoroom.php', array('instance' => $instance_id));
$gostr = get_string('goroom', 'block_mrbs');
$gotoval = '';
$gotomsg = '';
@@ -121,7 +120,8 @@
}
echo "".get_string('findroom', 'block_mrbs')." | ";
//Draw the three month calendars
- minicals($year, $month, $day, $area, '', 'day');
+ minicals($year, $month, $day, $instance_id, $area, '', 'day');
echo "
'.get_string('delarea', 'block_mrbs').'
'; echo ''.get_string('backadmin', 'block_mrbs').""; diff --git a/web/del_entry.php b/web/del_entry.php index 8bb78e5..b9b333f 100644 --- a/web/del_entry.php +++ b/web/del_entry.php @@ -25,35 +25,36 @@ $id = required_param('id', PARAM_INT); $series = optional_param('series', 0, PARAM_INT); -$PAGE->set_url('/blocks/mrbs/web/del_entry.php', array('id' => $id)); +$PAGE->set_url('/blocks/mrbs/web/del_entry.php', array('instance' => $instance_id, 'id' => $id)); require_login(); require_sesskey(); -if (getAuthorised(1) && ($info = mrbsGetEntryInfo($id))) { +if (getAuthorised($instance_id, 1) && ($info = mrbsGetEntryInfo($instance_id, $id))) { $day = userdate($info->start_time, "%d"); $month = userdate($info->start_time, "%m"); $year = userdate($info->start_time, "%Y"); - $area = mrbsGetRoomArea($info->room_id); + $area = mrbsGetRoomArea($instance_id, $info->room_id); if (MAIL_ADMIN_ON_DELETE) { // Gather all fields values for use in emails. $mail_previous = getPreviousEntryData($id, $series); } $roomadmin = false; - $context = context_system::instance(); + $context = context_block::instance($instance_id); + $PAGE->set_context($context); if (has_capability('block/mrbs:editmrbsunconfirmed', $context, null, false)) { - $adminemail = $DB->get_field('block_mrbs_room', 'room_admin_email', array('id' => $info->room_id)); + $adminemail = $DB->get_field('block_mrbs_room', 'room_admin_email', array('instance' => $instance_id, 'id' => $info->room_id)); if ($adminemail == $USER->email) { $roomadmin = true; } } - $result = mrbsDelEntry(getUserName(), $id, $series, 1, $roomadmin); + $result = mrbsDelEntry(getUserName(), $instance_id, $id, $series, 1, $roomadmin); if ($result) { // Send a mail to the Administrator - (MAIL_ADMIN_ON_DELETE) ? $result = notifyAdminOnDelete($mail_previous) : ''; + (MAIL_ADMIN_ON_DELETE) ? $result = notifyAdminOnDelete($instance_id, $mail_previous) : ''; $desturl = new moodle_url('/blocks/mrbs/web/day.php', array( - 'day' => $day, 'month' => $month, 'year' => $year, 'area' => $area + 'instance' => $instance_id, 'day' => $day, 'month' => $month, 'year' => $year, 'area' => $area )); redirect($desturl); exit(); @@ -61,4 +62,4 @@ } // If you got this far then we got an access denied. -showAccessDenied($day, $month, $year, $area); +showAccessDenied($day, $month, $year, $instance_id, $area); diff --git a/web/edit_area_room.php b/web/edit_area_room.php index 1a0a7dd..4681d06 100644 --- a/web/edit_area_room.php +++ b/web/edit_area_room.php @@ -54,7 +54,7 @@ } $thisurl = new moodle_url('/blocks/mrbs/web/edit_area_room.php', array( - 'day' => $day, 'month' => $month, 'year' => $year, 'sesskey' => sesskey() + 'instance' => $instance_id, 'day' => $day, 'month' => $month, 'year' => $year, 'sesskey' => sesskey() )); if ($room) { $thisurl->param('room', $room); @@ -66,8 +66,8 @@ $PAGE->set_url($thisurl); require_login(); -if (!getAuthorised(2)) { - showAccessDenied($day, $month, $year, $area); +if (!getAuthorised($instance_id, 2)) { + showAccessDenied($day, $month, $year, $instance_id, $area); exit(); } require_sesskey(); @@ -76,16 +76,16 @@ if (($change_done)) { if (!empty($room)) // Get the area the room is in { - $area = $DB->get_field('block_mrbs_room', 'area_id', array('id' => $room)); + $area = $DB->get_field('block_mrbs_room', 'area_id', array('instance' => $instance_id, 'id' => $room)); } $adminurl = new moodle_url('/blocks/mrbs/web/admin.php', array( - 'day' => $day, 'month' => $month, 'year' => $year, 'area' => $area + 'instance' => $instance_id, 'day' => $day, 'month' => $month, 'year' => $year, 'area' => $area )); redirect($adminurl); exit(); } -print_header_mrbs($day, $month, $year, isset($area) ? $area : ""); +print_header_mrbs($day, $month, $year, $instance_id, isset($area) ? $area : ""); echo $OUTPUT->heading(get_string('editroomarea', 'block_mrbs'), 2); @@ -118,6 +118,7 @@ if ($change_room && $valid_email && $valid_email2) { $updroom = new stdClass; $updroom->id = $room; + $updroom->instance = $instance_id; $updroom->room_name = substr(trim($room_name), 0, 25); $updroom->description = $description; $updroom->capacity = $capacity; @@ -127,9 +128,10 @@ $DB->update_record('block_mrbs_room', $updroom); } - $dbroom = $DB->get_record('block_mrbs_room', array('id' => $room), '*', MUST_EXIST); + $dbroom = $DB->get_record('block_mrbs_room', array('instance' => $instance_id, 'id' => $room), '*', MUST_EXIST); echo '