From 76494677c77d9eda80b9c7255f64bbb9bc3dc330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Sch=C3=BCtte?= Date: Fri, 10 Nov 2017 16:23:59 +0100 Subject: [PATCH 01/30] make mrbs multiple, remove cron, add scheduled task, add edit_form.php --- block_mrbs.php | 36 ++--- classes/task/mrbs_import.php | 38 +++++ db/tasks.php | 11 ++ edit_form.php | 280 +++++++++++++++++++++++++++++++++++ lang/en/block_mrbs.php | 2 + version.php | 7 +- 6 files changed, 352 insertions(+), 22 deletions(-) create mode 100644 classes/task/mrbs_import.php create mode 100644 db/tasks.php create mode 100644 edit_form.php diff --git a/block_mrbs.php b/block_mrbs.php index 9f71e12..fa271d9 100644 --- a/block_mrbs.php +++ b/block_mrbs.php @@ -19,7 +19,7 @@ class block_mrbs extends block_base { function init() { $this->title = get_string('blockname', 'block_mrbs'); - $this->content_type = BLOCK_TYPE_TEXT; + //TODO: $this->content_type = BLOCK_TYPE_TEXT; } function has_config() { @@ -30,30 +30,36 @@ function applicable_formats() { return array('all' => true); } + function specialization() { + $this->title = isset($this->config->title) ? format_string($this->config->title) : format_string(get_string('newmrbsblock', 'block_mrbs')); + } + + function instance_allow_multiple() { + return true; + } + function get_content() { global $CFG, $OUTPUT; if ($this->content !== null) { return $this->content; } - - $cfg_mrbs = get_config('block/mrbs'); - + $context = context_system::instance(); if (has_capability('block/mrbs:viewmrbs', $context) or has_capability('block/mrbs:editmrbs', $context) or has_capability('block/mrbs:administermrbs', $context)) { - if (isset($CFG->block_mrbs_serverpath)) { - $serverpath = $CFG->block_mrbs_serverpath; - } else { - $serverpath = $CFG->wwwroot.'/blocks/mrbs/web'; - } $go = get_string('accessmrbs', 'block_mrbs'); - $icon = ''; + $icon = $OUTPUT->pix_icon('web', 'MRBS icon', 'block_mrbs', array('height' => "16", 'width' => "16")); $target = ''; - if ($cfg_mrbs->newwindow) { + if (isset($this->config->newwindow) and $this->config->newwindow) { $target = ' target="_blank" '; } - $this->content = new stdClass(); + if (isset($this->config->serverpath)) { + $serverpath = $this->config->serverpath; + } else { + $serverpath = $CFG->wwwroot.'/blocks/mrbs/web'; + } + $this->content = new stdClass; $this->content->text = ''.$icon.'  '.$go.''; $this->content->footer = ''; return $this->content; @@ -62,10 +68,4 @@ function get_content() { return null; } - function cron() { - global $CFG; - include($CFG->dirroot.'/blocks/mrbs/import.php'); - - return true; - } } diff --git a/classes/task/mrbs_import.php b/classes/task/mrbs_import.php new file mode 100644 index 0000000..b015919 --- /dev/null +++ b/classes/task/mrbs_import.php @@ -0,0 +1,38 @@ +. + +/** + * The block_mrbs booking created event. + * + * @package block_mrbs + * @copyright 2014 Davo Smith + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace block_mrbs\task; + +class mrbs_import extends \core\task\scheduled_task { + public function get_name() { + return get_string('mrbs:import', 'block_mrbs'); + } + + public function execute() { + global $CFG; + include($CFG->dirroot.'/blocks/mrbs/import.php'); + + return true; + } +} diff --git a/db/tasks.php b/db/tasks.php new file mode 100644 index 0000000..5576d7a --- /dev/null +++ b/db/tasks.php @@ -0,0 +1,11 @@ +$tasks = array( + array( + 'classname' => 'block_mrbs\task\mrbs_import', + 'blocking' => 0, + 'minute' => '*/15', + 'hour' => '*', + 'day' => '*', + 'dayofweek' => '*', + 'month' => '*' + ) +); diff --git a/edit_form.php b/edit_form.php new file mode 100644 index 0000000..5b808c1 --- /dev/null +++ b/edit_form.php @@ -0,0 +1,280 @@ +. + +/** + * Form for editing MRBS block instances. + * + * @package block_mrbs + * @copyright 2017 Frank Schütte + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +class block_mrbs_edit_form extends block_edit_form { + protected function specific_definition($mform) { + global $CFG; + + // Fields for editing MRBS block title and contents. + $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); + + $mform->addElement('text', 'config_title', get_string('configtitle', 'block_html')); + $mform->setType('config_title', PARAM_TEXT); + + $cfg_mrbs = get_config('block/mrbs'); + + $options = array(0 => get_string('pagewindow', 'block_mrbs'), 1 => get_string('newwindow', 'block_mrbs')); + $mform->addElement('select', 'config_newwindow', get_string('config_new_window', 'block_mrbs'), $options); + $mform->setDefault('config_newwindow',1); + $mform->addElement('static', '', '', get_string('config_new_window2', 'block_mrbs')); + + $mform->addElement('text', 'config_serverpath', get_string('serverpath', 'block_mrbs')); + $mform->setType('config_serverpath', PARAM_URL); + $mform->setDefault('config_serverpath',$CFG->wwwroot.'/blocks/mrbs/web'); + $mform->addElement('static', '', '', get_string('adminview','block_mrbs')); + + $mform->addElement('text', 'config_admin', get_string('config_admin', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_admin2', 'block_mrbs')); + $mform->setDefault('config_admin', $CFG->supportname); + $mform->setType('config_admin', PARAM_TEXT); + $mform->addElement('text', 'config_admin_email', get_string('config_admin_email', 'block_mrbs'), get_string('config_admin_email2', 'block_mrbs'), $CFG->supportemail, PARAM_TEXT); + $options = array(0 => get_string('no'), 1 => get_string('yes')); + $mform->addElement('selectyesno', 'config_enable_periods', get_string('config_enable_periods', 'block_mrbs')); + $mform->addElement('static','','',get_string('config_enable_periods2','block_mrbs')); + $mform->setDefault('config_enable_periods', 1); + + if (isset($cfg_mrbs->enable_periods)) { + if ($cfg_mrbs->enable_periods == 0) { + + // Resolution + + unset($options); + $strunits = get_string('resolution_units', 'block_mrbs'); + $options = array( + '900' => '15'.$strunits, '1800' => '30'.$strunits, '2700' => '45'.$strunits, '3600' => '60'.$strunits, + '4500' => '75'.$strunits, '5400' => '90'.$strunits, '6300' => '105'.$strunits, '7200' => '120'.$strunits + ); + $mform->addElement('advcheckbox', 'config_resolution', get_string('config_resolution', 'block_mrbs'), get_string('config_resolution2', 'block_mrbs'), '1800', $options); + + // Start Time (Hours) + unset($options); + $options = array( + 1 => '01', 2 => '02', 3 => '03', 4 => '04', 5 => '05', 6 => '06', 7 => '07', 8 => '08', 9 => '09', 10 => '10', + 11 => '11', 12 => '12', 13 => '13', 14 => '14', 15 => '15', 16 => '16', 17 => '17', 18 => '18', 19 => '19', 20 => '20', + 21 => '21', 22 => '22', 23 => '23' + ); + $mform->addElement('advcheckbox', 'config_morningstarts', get_string('config_morningstarts', 'block_mrbs'), get_string('config_morningstarts2', 'block_mrbs'), 7, $options); + + // Start Time (Min) + unset($options); + $options = array( + 0 => '00', 5 => '05', 10 => '10', 15 => '15', 20 => '20', 25 => '25', 30 => '30', 35 => '35', 40 => '40', 45 => '45', + 50 => '50', 55 => '55' + ); + $mform->addElement('advcheckbox', 'config_morningstarts_min', get_string('config_morningstarts_min', 'block_mrbs'), get_string('config_morningstarts_min2', 'block_mrbs'), 0, $options); + + // End Time (Hours) + unset($options); + $options = array( + 1 => '01', 2 => '02', 3 => '03', 4 => '04', 5 => '05', 6 => '06', 7 => '07', 8 => '08', 9 => '09', 10 => '10', + 11 => '11', 12 => '12', 13 => '13', 14 => '14', 15 => '15', 16 => '16', 17 => '17', 18 => '18', 19 => '19', 20 => '20', + 21 => '21', 22 => '22', 23 => '23' + ); + $mform->addElement('advcheckbox', 'config_eveningends', get_string('config_eveningends', 'block_mrbs'), get_string('config_eveningends2', 'block_mrbs'), 19, $options); + + // End Time Time (Min) + unset($options); + $options = array( + 0 => '00', 5 => '05', 10 => '10', 15 => '15', 20 => '20', 25 => '25', 30 => '30', 35 => '35', 40 => '40', 45 => '45', + 50 => '50', 55 => '55' + ); + $mform->addElement('advcheckbox', 'config_eveningends_min', get_string('config_eveningends_min', 'block_mrbs'), get_string('config_eveningends_min2', 'block_mrbs'), 0, $options); + } else { //Use Custom Periods + $mform->addElement('textarea', 'periods', get_string('config_periods', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_periods2', 'block_mrbs')); + $mform->setType('periods', PARAM_TEXT); + } + } + + // Date Information + + //Start of Week + unset($options); + $options = array( + 0 => get_string('sunday', 'calendar'), 1 => get_string('monday', 'calendar'), 2 => get_string('tuesday', 'calendar'), + 3 => get_string('wednesday', 'calendar'), 4 => get_string('thursday', 'calendar'), 5 => get_string('friday', 'calendar'), + 6 => get_string('saturday', 'calendar') + ); + $mform->addElement('select', 'config_weekstarts', get_string('config_weekstarts', 'block_mrbs'), $options); + $mform->setDefault('config_weekstarts', 0); + $mform->addElement('static', '', '', get_string('config_weekstarts2', 'block_mrbs')); + + //Length of week + $mform->addElement('text', 'config_weeklength', get_string('config_weeklength', 'block_mrbs')); + $mform->setDefault('config_weeklength', 7); + $mform->setType(PARAM_INT); + $mform->addElement('static', '', '', get_string('config_weeklength2', 'block_mrbs')); + + //Date Format + unset($options); + $options = array(0 => get_string('config_date_mmddyy', 'block_mrbs'), 1 => get_string('config_date_ddmmyy', 'block_mrbs')); + $mform->addElement('select', 'config_dateformat', get_string('config_dateformat', 'block_mrbs'), $options); + $mform->setDefault('config_dateformat', 0); + $mform->addElement('static', '', '', get_string('config_dateformat2', 'block_mrbs')); + + //Time format + unset($options); + $options = array(0 => get_string('timeformat_12', 'calendar'), 1 => get_string('timeformat_24', 'calendar')); + $mform->addElement('select', 'config_timeformat', get_string('config_timeformat', 'block_mrbs'), $options); + $mform->setDefault('config_timeformat', 1); + $mform->addElement('static', '', '', get_string('config_timeformat2', 'block_mrbs')); + + // Misc Settings + $mform->addElement('text', 'config_max_rep_entrys', get_string('config_max_rep_entrys', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_max_rep_entrys2', 'block_mrbs')); + $mform->setDefault('config_max_rep_entrys', 365); + $mform->setType('config_max_rep_entrys', PARAM_INT); + + $mform->addElement('text', 'config_max_advance_days', get_string('config_max_advance_days', 'block_mrbs'), get_string('config_max_advance_days2', 'block_mrbs'), -1, PARAM_INT); + $mform->addElement('text', 'config_default_report_days', get_string('config_default_report_days', 'block_mrbs'), get_string('config_default_report_days2', 'block_mrbs'), 60, PARAM_INT); + $mform->addElement('text', 'config_search_count', get_string('config_search_count', 'block_mrbs'), get_string('config_search_count2', 'block_mrbs'), 20, PARAM_INT); + /* + $mform->addElement('text', 'config_refresh_rate', get_string('config_refresh_rate', 'block_mrbs'), get_string('config_refresh_rate2', 'block_mrbs'), 0, PARAM_INT); + + */ + + $options = array('list' => get_string('list'), 'select' => get_string('select')); + $mform->addElement('select', 'config_area_list_format', get_string('config_area_list_format', 'block_mrbs'), $options); + $mform->setDefault('config_area_list_format', 'list'); + $mform->addElement('static', '', '', get_string('config_area_list_format2', 'block_mrbs')); + + $options = array( + 'both' => get_string('both', 'block_mrbs'), 'description' => get_string('description'), + 'slot' => get_string('slot', 'block_mrbs') + ); + $mform->addElement('select', 'config_monthly_view_entries_details', get_string('config_monthly_view_entries_details', 'block_mrbs'), $options); + $mform->setDefault('config_monthly_view_entries_details', 'both'); + $mform->addElement('static', '', '', get_string('config_monthly_view_entries_details2', 'block_mrbs')); + + $mform->addElement('selectyesno', 'config_view_week_number', get_string('config_view_week_number', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_view_week_number2', 'block_mrbs')); + + $mform->addElement('selectyesno', 'config_times_right_side', get_string('config_times_right_side', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_times_right_side2', 'block_mrbs')); + + $mform->addElement('selectyesno', 'config_javascript_cursor', get_string('config_javascript_cursor', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_javascript_cursor2', 'block_mrbs')); + $mform->setDefault('config_javascript_cursor', 1); + + $mform->addElement('selectyesno', 'config_show_plus_link', get_string('config_show_plus_link', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_show_plus_link2', 'block_mrbs')); + $mform->setDefault('config_show_plus_link', 1); + + $options = array( + 'bgcolor' => get_string('bgcolor', 'block_mrbs'), 'class' => get_string('class', 'block_mrbs'), + 'hybrid' => get_string('hybrid', 'block_mrbs') + ); + $mform->addElement('select', 'config_highlight_method', get_string('config_highlight_method', 'block_mrbs'), $options); + $mform->setDefault('config_highlight_method', 'hybrid'); + $mform->addElement('static', '', '', get_string('config_highlight_method2', 'block_mrbs')); + + $options = array('day' => get_string('day'), 'month' => get_string('month', 'block_mrbs'), 'week' => get_string('week')); + $mform->addElement('select', 'config_default_view', get_string('config_default_view', 'block_mrbs'), $options); + $mform->setDefault('config_default_view', 'day'); + $mform->addElement('static', '', '', get_string('config_default_view2', 'block_mrbs')); + + $mform->addElement('text', 'config_default_room', get_string('config_default_room', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_default_room2', 'block_mrbs')); + $mform->setType('config_default_room', PARAM_INT); + + // should this be the same as the Moodle Site cookie path? + // $mform->addElement('text', 'cookie_path_override', get_string('config_cookie_path_override', 'block_mrbs'), get_string('config_cookie_path_override2', 'block_mrbs'), '', PARAM_LOCALURL); + // + /* + //select + $options = array('' => get_string('', 'block_mrbs'), '' => get_string('', 'block_mrbs')); + $mform->addElement('advcheckbox', '', get_string('config_', 'block_mrbs'), get_string('config_2', 'block_mrbs'), '', $options); + //text or int + $mform->addElement('text', '', get_string('config_', 'block_mrbs'), get_string('config_2', 'block_mrbs'), 0, PARAM_INT); + */ + + $mform->addElement('text', 'config_entry_type_a', get_string('config_entry_type', 'block_mrbs', 'A'), get_string('config_entry_type2', 'block_mrbs', 'A'), null, PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_b', get_string('config_entry_type', 'block_mrbs', 'B'), get_string('config_entry_type2', 'block_mrbs', 'B'), null, PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_c', get_string('config_entry_type', 'block_mrbs', 'C'), get_string('config_entry_type2', 'block_mrbs', 'C'), null, PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_d', get_string('config_entry_type', 'block_mrbs', 'D'), get_string('config_entry_type2', 'block_mrbs', 'D'), null, PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_e', get_string('config_entry_type', 'block_mrbs', 'E'), get_string('config_entry_type2', 'block_mrbs', 'E'), get_string('external', 'block_mrbs'), PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_f', get_string('config_entry_type', 'block_mrbs', 'F'), get_string('config_entry_type2', 'block_mrbs', 'F'), null, PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_g', get_string('config_entry_type', 'block_mrbs', 'G'), get_string('config_entry_type2', 'block_mrbs', 'G'), null, PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_h', get_string('config_entry_type', 'block_mrbs', 'H'), get_string('config_entry_type2', 'block_mrbs', 'H'), null, PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_i', get_string('config_entry_type', 'block_mrbs', 'I'), get_string('config_entry_type2', 'block_mrbs', 'I'), get_string('internal', 'block_mrbs'), PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_j', get_string('config_entry_type', 'block_mrbs', 'J'), get_string('config_entry_type2', 'block_mrbs', 'J'), null, PARAM_TEXT); + $options = array('0' => get_string('no'), '1' => get_string('yes')); + $mform->addElement('advcheckbox', 'config_mail_admin_on_bookings', get_string('config_mail_admin_on_bookings', 'block_mrbs'), get_string('config_mail_admin_on_bookings2', 'block_mrbs'), '0', $options); + $options = array('0' => get_string('no'), '1' => get_string('yes')); + $mform->addElement('advcheckbox', 'config_mail_area_admin_on_bookings', get_string('config_mail_area_admin_on_bookings', 'block_mrbs'), get_string('config_mail_area_admin_on_bookings2', 'block_mrbs'), 0, $options); + $options = array('0' => get_string('no'), '1' => get_string('yes')); + $mform->addElement('advcheckbox', 'config_mail_room_admin_on_bookings', get_string('config_mail_room_admin_on_bookings', 'block_mrbs'), get_string('config_mail_room_admin_on_bookings2', 'block_mrbs'), 0, $options); + $options = array('0' => get_string('no'), '1' => get_string('yes')); + $mform->addElement('advcheckbox', 'config_mail_admin_on_delete', get_string('config_mail_admin_on_delete', 'block_mrbs'), get_string('config_mail_admin_on_delete2', 'block_mrbs'), 0, $options); + $options = array('0' => get_string('no'), '1' => get_string('yes')); + $mform->addElement('advcheckbox', 'config_mail_admin_all', get_string('config_mail_admin_all', 'block_mrbs'), get_string('config_mail_admin_all2', 'block_mrbs'), 0, $options); + $options = array('0' => get_string('no'), '1' => get_string('yes')); + $mform->addElement('advcheckbox', 'config_mail_details', get_string('config_mail_details', 'block_mrbs'), get_string('config_mail_details2', 'block_mrbs'), 0, $options); + $options = array('0' => get_string('no'), '1' => get_string('yes')); + $mform->addElement('advcheckbox', 'config_mail_booker', get_string('config_mail_booker', 'block_mrbs'), get_string('config_mail_booker2', 'block_mrbs'), 0, $options); + $mform->addElement('text', 'config_mail_from', get_string('config_mail_from', 'block_mrbs'), get_string('config_mail_from2', 'block_mrbs'), $CFG->supportemail, PARAM_TEXT); + $mform->addElement('text', 'config_mail_recipients', get_string('config_mail_recipients', 'block_mrbs'), get_string('config_mail_recipients2', 'block_mrbs'), $CFG->supportemail, PARAM_TEXT); + $mform->addElement('text', 'config_mail_cc', get_string('config_mail_cc', 'block_mrbs'), get_string('config_mail_cc2', 'block_mrbs'), null, PARAM_TEXT); + $mform->addElement('text', 'config_cronfile', get_string('cronfile', 'block_mrbs'), get_string('cronfiledesc', 'block_mrbs'), null, PARAM_TEXT); + } + + function set_data($defaults) { + if (!empty($this->block->config) && is_object($this->block->config)) { + $text = $this->block->config->text; + $draftid_editor = file_get_submitted_draft_itemid('config_text'); + if (empty($text)) { + $currenttext = ''; + } else { + $currenttext = $text; + } + $defaults->config_text['text'] = file_prepare_draft_area($draftid_editor, $this->block->context->id, 'block_html', 'content', 0, array('subdirs'=>true), $currenttext); + $defaults->config_text['itemid'] = $draftid_editor; + $defaults->config_text['format'] = $this->block->config->format; + } else { + $text = ''; + } + + if (!$this->block->user_can_edit() && !empty($this->block->config->title)) { + // If a title has been set but the user cannot edit it format it nicely + $title = $this->block->config->title; + $defaults->config_title = format_string($title, true, $this->page->context); + // Remove the title from the config so that parent::set_data doesn't set it. + unset($this->block->config->title); + } + + // have to delete text here, otherwise parent::set_data will empty content + // of editor + unset($this->block->config->text); + parent::set_data($defaults); + // restore $text + if (!isset($this->block->config)) { + $this->block->config = new stdClass(); + } + $this->block->config->text = $text; + if (isset($title)) { + // Reset the preserved title + $this->block->config->title = $title; + } + } +} diff --git a/lang/en/block_mrbs.php b/lang/en/block_mrbs.php index 7710eb1..65dfc93 100644 --- a/lang/en/block_mrbs.php +++ b/lang/en/block_mrbs.php @@ -217,6 +217,7 @@ $string['mrbs:doublebook'] = 'Double Book Rooms'; $string['mrbs:editmrbsunconfirmed'] = 'Only create \'unconfirmed\' bookings (overriden by \'editmrbs\')'; $string['mrbs:forcebook'] = 'Force Book Rooms (auto move existing bookings)'; +$string['mrbs:import'] = 'MRBS Import'; $string['mrbs:ignoremaxadvancedays'] = 'Ignore the \'max_advance_days\' setting'; $string['mrbs:myaddinstance'] = 'Add new MRBS block'; $string['mrbs:viewalltt'] = 'View All Users\' Timetables'; @@ -232,6 +233,7 @@ $string['must_set_description'] = 'You must set a description'; $string['must_set_name'] = 'You must set a name'; $string['namebooker'] = 'Reservation for'; +$string['newmrbsblock'] = 'New MRBS'; $string['newwindow'] = 'New window'; //see MDL-15952 $string['no_rooms_for_area'] = 'No rooms defined for this area'; $string['no_user_with_email'] = 'No Moodle users found with an email address of: {$a}. All MRBS related email(s) must be associated with a Moodle user account.'; diff --git a/version.php b/version.php index 7bf1a65..3609834 100644 --- a/version.php +++ b/version.php @@ -14,9 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -$plugin->version = 2016101700; +$plugin->version = 2017110900; $plugin->requires = 2014051200; // Moodle 2.7+ -$plugin->cron = 300; $plugin->component = 'block_mrbs'; -$plugin->maturity = MATURITY_STABLE; -$plugin->release = '2.x (Build: 2016101700)'; +$plugin->maturity = MATURITY_ALPHA; +$plugin->release = '3.x (Build: 2017110900)'; From 5e6194c137397b49e7fe40753f492a3124947584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Sch=C3=BCtte?= Date: Tue, 14 Nov 2017 19:34:57 +0100 Subject: [PATCH 02/30] added instance, added upgrade code, added title to config --- block_mrbs.php | 36 +++- classes/event/booking_created.php | 9 +- classes/event/booking_updated.php | 9 +- db/install.xml | 4 + db/upgrade.php | 70 +++++++ edit_form.php | 194 +++++++++++--------- import.php | 292 +++++++++++++++--------------- lang/en/block_mrbs.php | 1 + version.php | 4 +- web/add.php | 8 +- web/admin.php | 24 +-- web/config.inc.php | 15 +- web/day.php | 37 ++-- web/del.php | 20 +- web/del_entry.php | 12 +- web/edit_area_room.php | 20 +- web/edit_entry.php | 19 +- web/edit_entry_handler.php | 39 ++-- web/force_book.php | 13 +- web/functions.php | 56 +++--- web/gotoroom.php | 10 +- web/help.php | 6 +- web/index.php | 10 +- web/mincals.php | 15 +- web/month.php | 37 ++-- web/mrbs_auth.php | 4 +- web/mrbs_sql.php | 68 ++++--- web/report.php | 13 +- web/request_vacate.php | 3 +- web/request_vacate_send.php | 5 +- web/roomsearch.js | 9 +- web/roomsearch.php | 3 +- web/roomsearch_ss.php | 6 +- web/search.php | 14 +- web/session_php.php | 6 +- web/trailer.php | 6 +- web/updatefreerooms.js | 5 +- web/updatefreerooms.php | 2 +- web/userweek.php | 6 +- web/view_entry.php | 22 +-- web/week.php | 34 ++-- 41 files changed, 692 insertions(+), 474 deletions(-) diff --git a/block_mrbs.php b/block_mrbs.php index fa271d9..e004681 100644 --- a/block_mrbs.php +++ b/block_mrbs.php @@ -44,7 +44,7 @@ function get_content() { if ($this->content !== null) { return $this->content; } - + $context = context_system::instance(); if (has_capability('block/mrbs:viewmrbs', $context) or has_capability('block/mrbs:editmrbs', $context) or has_capability('block/mrbs:administermrbs', $context)) { @@ -59,13 +59,45 @@ function get_content() { } else { $serverpath = $CFG->wwwroot.'/blocks/mrbs/web'; } + if (isset($this->instance->id)) { + $instance = $this->instance->id; + } else { + $instance = 0; + } $this->content = new stdClass; - $this->content->text = ''.$icon.'  '.$go.''; + $this->content->text = ''.$icon.'  '.$go.''; $this->content->footer = ''; return $this->content; } return null; } + + function instance_config_save($data, $nolongerused = false) { + // modify type of select fields to be int + $data->newwindow = intval($data->newwindow); + $data->enable_periods = intval($data->enable_periods); + if ($data->enable_periods == 0) { + $data->morningstarts = intval($data->morningstarts); + $data->morningstarts_min = intval($data->morningstarts_min); + $data->eveningends = intval($data->eveningends); + $data->eveningends_min = intval($data->eveningends_min); + } + $data->weekstarts = intval($data->weekstarts); + $data->dateformat = intval($data->dateformat); + $data->timeformat = intval($data->timeformat); + $data->view_week_number = intval($data->view_week_number); + $data->times_right_side = intval($data->times_right_side); + $data->javascript_cursor = intval($data->javascript_cursor); + $data->show_plus_link = intval($data->show_plus_link); + $data->mail_admin_on_bookings = intval($data->mail_admin_on_bookings); + $data->mail_area_admin_on_bookings = intval($data->mail_area_admin_on_bookings); + $data->mail_room_admin_on_bookings = intval($data->mail_room_admin_on_bookings); + $data->mail_admin_on_delete = intval($data->mail_admin_on_delete); + $data->mail_admin_all = intval($data->mail_admin_all); + $data->mail_details = intval($data->mail_details); + $data->mail_booker = intval($data->mail_booker); + parent::instance_config_save($data, $nolongerused); + } } diff --git a/classes/event/booking_created.php b/classes/event/booking_created.php index 855ddd3..9631202 100644 --- a/classes/event/booking_created.php +++ b/classes/event/booking_created.php @@ -63,7 +63,7 @@ public static function get_name() { * @return string */ public function get_description() { - return "The user with id '$this->userid' has updated a new booking in '{$this->other['room']}' for '{$this->other['name']}'"; + return "The user with id '$this->userid' has updated a new booking for '{$this->other['instance']}' in '{$this->other['room']}' for '{$this->other['name']}'"; } /** @@ -72,7 +72,7 @@ public function get_description() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/blocks/mrbs/web/view_entry.php', array('id' => $this->objectid)); + return new \moodle_url('/blocks/mrbs/web/view_entry.php', array('instance' => $this->other['instance'], 'id' => $this->objectid)); } /** @@ -82,11 +82,14 @@ public function get_url() { */ protected function get_legacy_logdata() { global $CFG; - return array(SITEID, 'mrbs', 'add booking', $CFG->wwwroot.'blocks/mrbs/web/view_entry.php?id='.$this->objectid, + return array(SITEID, 'mrbs', 'add booking', $CFG->wwwroot.'blocks/mrbs/web/view_entry.php?instance='.$this->other['instance'].'&id='.$this->objectid, $this->other['name']); } protected function validate_data() { + if (!isset($this->other['instance'])) { + throw new \coding_exception('Must specify the instance of the booking as \'other[\'instance\']\''); + } if (!isset($this->other['name'])) { throw new \coding_exception('Must specify the name of the booking as \'other[\'name\']\''); } diff --git a/classes/event/booking_updated.php b/classes/event/booking_updated.php index 6298e6a..a5afc8c 100644 --- a/classes/event/booking_updated.php +++ b/classes/event/booking_updated.php @@ -63,7 +63,7 @@ public static function get_name() { * @return string */ public function get_description() { - return "The user with id '$this->userid' has updated a booking in '{$this->other['room']}' for '{$this->other['name']}'"; + return "The user with id '$this->userid' has updated a booking for '{$this->other['instance']}'in '{$this->other['room']}' for '{$this->other['name']}'"; } /** @@ -72,7 +72,7 @@ public function get_description() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/blocks/mrbs/web/view_entry.php', array('id' => $this->objectid)); + return new \moodle_url('/blocks/mrbs/web/view_entry.php', array('instance' => $this->other['instance'], 'id' => $this->objectid)); } /** @@ -82,11 +82,14 @@ public function get_url() { */ protected function get_legacy_logdata() { global $CFG; - return array(SITEID, 'mrbs', 'edit booking', $CFG->wwwroot.'blocks/mrbs/web/view_entry.php?id='.$this->objectid, + return array(SITEID, 'mrbs', 'edit booking', $CFG->wwwroot.'blocks/mrbs/web/view_entry.php?instance='.$this->other['instance'].'&id='.$this->objectid, $this->other['name']); } protected function validate_data() { + if (!isset($this->other['instance'])) { + throw new \coding_exception('Must specify the instance of the booking as \'other[\'instance\']\''); + } if (!isset($this->other['name'])) { throw new \coding_exception('Must specify the name of the booking as \'other[\'name\']\''); } diff --git a/db/install.xml b/db/install.xml index 0051f83..6ba17b3 100644 --- a/db/install.xml +++ b/db/install.xml @@ -7,6 +7,7 @@ + @@ -17,6 +18,7 @@
+ @@ -36,6 +38,7 @@
+ @@ -56,6 +59,7 @@
+ diff --git a/db/upgrade.php b/db/upgrade.php index a82e07f..176ec97 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -168,5 +168,75 @@ function xmldb_block_mrbs_upgrade($oldversion=0) { } } + if ($oldversion < 2017111401) { + // Create system context instance from global config and move data to that instance. + echo "Moving first instance to block in system context on site-index page
\n"; + + // Add this block to the blocks on site-index. + $blockname = 'mrbs'; + $page = new moodle_page(); + $page->set_context(context_system::instance()); + + // Check to see if this block is already on the site-index page. + $criteria = array( + 'blockname' => $blockname, + 'pagetypepattern' => 'site-index', + ); + + if (!$DB->record_exists('block_instances', $criteria)) { + // Add the block to site-index. + $page->blocks->add_region(BLOCK_POS_LEFT); + $page->blocks->add_block($blockname, BLOCK_POS_LEFT, -8, false, 'site-index'); + + // Move configuration from global config to instance + $cfg_mrbs = get_config('block/mrbs'); + $tmp = $DB->get_record('block_instances', $criteria, '*', MUST_EXIST); + if(!isset($tmp)) { + throw new \coding_exception('block_instance with id '.$instance_id.' must exist.'); + } + $instance_id = $tmp->id; + $tmp->configdata = base64_encode(serialize($cfg_mrbs)); + $DB->update_record('block_instances', $tmp); + } else { + $instance_id = $DB->get_field('block_instances', 'id', $criteria, MUST_EXIST); + } + if(!isset($instance_id)) { + throw new \coding_exception('block instance \'block_mrbs\' must exist on \'site-index\''); + } + + // Add instance field to each table. + echo "Adding instance field to each mrbs table
\n"; + + $table = new xmldb_table('block_mrbs_area'); + $field = new xmldb_field('instance', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, $instance_id, 'id'); + // Conditionally launch add field instance + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + echo "Added instance field to mrbs table block_mrbs_area
\n"; + } + $table = new xmldb_table('block_mrbs_entry'); + $field = new xmldb_field('instance', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, $instance_id, 'id'); + // Conditionally launch add field instance + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + echo "Added instance field to mrbs table block_mrbs_entry
\n"; + } + $table = new xmldb_table('block_mrbs_repeat'); + $field = new xmldb_field('instance', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, $instance_id, 'id'); + // Conditionally launch add field instance + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + echo "Added instance field to mrbs table block_mrbs_repeat
\n"; + } + $table = new xmldb_table('block_mrbs_room'); + $field = new xmldb_field('instance', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, $instance_id, 'id'); + // Conditionally launch add field instance + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + echo "Added instance field to mrbs table block_mrbs_room
\n"; + } + // mrbs savepoint reached + upgrade_block_savepoint(true, 2017111401, 'mrbs'); + } return true; } diff --git a/edit_form.php b/edit_form.php index 5b808c1..be75db6 100644 --- a/edit_form.php +++ b/edit_form.php @@ -48,7 +48,12 @@ protected function specific_definition($mform) { $mform->addElement('static', '', '', get_string('config_admin2', 'block_mrbs')); $mform->setDefault('config_admin', $CFG->supportname); $mform->setType('config_admin', PARAM_TEXT); - $mform->addElement('text', 'config_admin_email', get_string('config_admin_email', 'block_mrbs'), get_string('config_admin_email2', 'block_mrbs'), $CFG->supportemail, PARAM_TEXT); + + $mform->addElement('text', 'config_admin_email', get_string('config_admin_email', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_admin_email2', 'block_mrbs')); + $mform->setDefault('config_admin_email', $CFG->supportemail); + $mform->setType('config_admin_email', PARAM_TEXT); + $options = array(0 => get_string('no'), 1 => get_string('yes')); $mform->addElement('selectyesno', 'config_enable_periods', get_string('config_enable_periods', 'block_mrbs')); $mform->addElement('static','','',get_string('config_enable_periods2','block_mrbs')); @@ -65,8 +70,10 @@ protected function specific_definition($mform) { '900' => '15'.$strunits, '1800' => '30'.$strunits, '2700' => '45'.$strunits, '3600' => '60'.$strunits, '4500' => '75'.$strunits, '5400' => '90'.$strunits, '6300' => '105'.$strunits, '7200' => '120'.$strunits ); - $mform->addElement('advcheckbox', 'config_resolution', get_string('config_resolution', 'block_mrbs'), get_string('config_resolution2', 'block_mrbs'), '1800', $options); - + $mform->addElement('select', 'config_resolution', get_string('config_resolution', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_resolution2', 'block_mrbs')); + $mform->setDefault('config_resolution', '1800'); + // Start Time (Hours) unset($options); $options = array( @@ -74,15 +81,19 @@ protected function specific_definition($mform) { 11 => '11', 12 => '12', 13 => '13', 14 => '14', 15 => '15', 16 => '16', 17 => '17', 18 => '18', 19 => '19', 20 => '20', 21 => '21', 22 => '22', 23 => '23' ); - $mform->addElement('advcheckbox', 'config_morningstarts', get_string('config_morningstarts', 'block_mrbs'), get_string('config_morningstarts2', 'block_mrbs'), 7, $options); - + $mform->addElement('select', 'config_morningstarts', get_string('config_morningstarts', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_morningstarts2', 'block_mrbs')); + $mform->setDefault('config_morningstarts', 7); + // Start Time (Min) unset($options); $options = array( 0 => '00', 5 => '05', 10 => '10', 15 => '15', 20 => '20', 25 => '25', 30 => '30', 35 => '35', 40 => '40', 45 => '45', 50 => '50', 55 => '55' ); - $mform->addElement('advcheckbox', 'config_morningstarts_min', get_string('config_morningstarts_min', 'block_mrbs'), get_string('config_morningstarts_min2', 'block_mrbs'), 0, $options); + $mform->addElement('select', 'config_morningstarts_min', get_string('config_morningstarts_min', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_morningstarts_min2', 'block_mrbs')); + $mform->setDefault('config_morningstarts_min', 0); // End Time (Hours) unset($options); @@ -91,7 +102,9 @@ protected function specific_definition($mform) { 11 => '11', 12 => '12', 13 => '13', 14 => '14', 15 => '15', 16 => '16', 17 => '17', 18 => '18', 19 => '19', 20 => '20', 21 => '21', 22 => '22', 23 => '23' ); - $mform->addElement('advcheckbox', 'config_eveningends', get_string('config_eveningends', 'block_mrbs'), get_string('config_eveningends2', 'block_mrbs'), 19, $options); + $mform->addElement('select', 'config_eveningends', get_string('config_eveningends', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_eveningends2', 'block_mrbs')); + $mform->setDefault('config_eveningends', 19); // End Time Time (Min) unset($options); @@ -99,8 +112,10 @@ protected function specific_definition($mform) { 0 => '00', 5 => '05', 10 => '10', 15 => '15', 20 => '20', 25 => '25', 30 => '30', 35 => '35', 40 => '40', 45 => '45', 50 => '50', 55 => '55' ); - $mform->addElement('advcheckbox', 'config_eveningends_min', get_string('config_eveningends_min', 'block_mrbs'), get_string('config_eveningends_min2', 'block_mrbs'), 0, $options); - } else { //Use Custom Periods + $mform->addElement('select', 'config_eveningends_min', get_string('config_eveningends_min', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_eveningends_min2', 'block_mrbs')); + $mform->setDefault('config_eveningends_min', 0); + } else { //Use Custom Periods $mform->addElement('textarea', 'periods', get_string('config_periods', 'block_mrbs')); $mform->addElement('static', '', '', get_string('config_periods2', 'block_mrbs')); $mform->setType('periods', PARAM_TEXT); @@ -119,11 +134,11 @@ protected function specific_definition($mform) { $mform->addElement('select', 'config_weekstarts', get_string('config_weekstarts', 'block_mrbs'), $options); $mform->setDefault('config_weekstarts', 0); $mform->addElement('static', '', '', get_string('config_weekstarts2', 'block_mrbs')); - + //Length of week $mform->addElement('text', 'config_weeklength', get_string('config_weeklength', 'block_mrbs')); $mform->setDefault('config_weeklength', 7); - $mform->setType(PARAM_INT); + $mform->setType('config_weeklength', PARAM_INT); $mform->addElement('static', '', '', get_string('config_weeklength2', 'block_mrbs')); //Date Format @@ -132,23 +147,34 @@ protected function specific_definition($mform) { $mform->addElement('select', 'config_dateformat', get_string('config_dateformat', 'block_mrbs'), $options); $mform->setDefault('config_dateformat', 0); $mform->addElement('static', '', '', get_string('config_dateformat2', 'block_mrbs')); - + //Time format unset($options); $options = array(0 => get_string('timeformat_12', 'calendar'), 1 => get_string('timeformat_24', 'calendar')); $mform->addElement('select', 'config_timeformat', get_string('config_timeformat', 'block_mrbs'), $options); $mform->setDefault('config_timeformat', 1); $mform->addElement('static', '', '', get_string('config_timeformat2', 'block_mrbs')); - + // Misc Settings $mform->addElement('text', 'config_max_rep_entrys', get_string('config_max_rep_entrys', 'block_mrbs')); $mform->addElement('static', '', '', get_string('config_max_rep_entrys2', 'block_mrbs')); $mform->setDefault('config_max_rep_entrys', 365); $mform->setType('config_max_rep_entrys', PARAM_INT); - $mform->addElement('text', 'config_max_advance_days', get_string('config_max_advance_days', 'block_mrbs'), get_string('config_max_advance_days2', 'block_mrbs'), -1, PARAM_INT); - $mform->addElement('text', 'config_default_report_days', get_string('config_default_report_days', 'block_mrbs'), get_string('config_default_report_days2', 'block_mrbs'), 60, PARAM_INT); - $mform->addElement('text', 'config_search_count', get_string('config_search_count', 'block_mrbs'), get_string('config_search_count2', 'block_mrbs'), 20, PARAM_INT); + $mform->addElement('text', 'config_max_advance_days', get_string('config_max_advance_days', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_max_advance_days2', 'block_mrbs')); + $mform->setDefault('config_max_advance_days', -1); + $mform->setType('config_max_advance_days', PARAM_INT); + + $mform->addElement('text', 'config_default_report_days', get_string('config_default_report_days', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_default_report_days2', 'block_mrbs')); + $mform->setDefault('config_default_report_days', 60); + $mform->setType('config_default_report_days', PARAM_INT); + + $mform->addElement('text', 'config_search_count', get_string('config_search_count', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_search_count2', 'block_mrbs')); + $mform->setDefault('config_search_count', 20); + $mform->setType('config_search_count', PARAM_INT); /* $mform->addElement('text', 'config_refresh_rate', get_string('config_refresh_rate', 'block_mrbs'), get_string('config_refresh_rate2', 'block_mrbs'), 0, PARAM_INT); @@ -169,10 +195,10 @@ protected function specific_definition($mform) { $mform->addElement('selectyesno', 'config_view_week_number', get_string('config_view_week_number', 'block_mrbs')); $mform->addElement('static', '', '', get_string('config_view_week_number2', 'block_mrbs')); - + $mform->addElement('selectyesno', 'config_times_right_side', get_string('config_times_right_side', 'block_mrbs')); $mform->addElement('static', '', '', get_string('config_times_right_side2', 'block_mrbs')); - + $mform->addElement('selectyesno', 'config_javascript_cursor', get_string('config_javascript_cursor', 'block_mrbs')); $mform->addElement('static', '', '', get_string('config_javascript_cursor2', 'block_mrbs')); $mform->setDefault('config_javascript_cursor', 1); @@ -209,72 +235,72 @@ protected function specific_definition($mform) { $mform->addElement('text', '', get_string('config_', 'block_mrbs'), get_string('config_2', 'block_mrbs'), 0, PARAM_INT); */ - $mform->addElement('text', 'config_entry_type_a', get_string('config_entry_type', 'block_mrbs', 'A'), get_string('config_entry_type2', 'block_mrbs', 'A'), null, PARAM_TEXT); - $mform->addElement('text', 'config_entry_type_b', get_string('config_entry_type', 'block_mrbs', 'B'), get_string('config_entry_type2', 'block_mrbs', 'B'), null, PARAM_TEXT); - $mform->addElement('text', 'config_entry_type_c', get_string('config_entry_type', 'block_mrbs', 'C'), get_string('config_entry_type2', 'block_mrbs', 'C'), null, PARAM_TEXT); - $mform->addElement('text', 'config_entry_type_d', get_string('config_entry_type', 'block_mrbs', 'D'), get_string('config_entry_type2', 'block_mrbs', 'D'), null, PARAM_TEXT); - $mform->addElement('text', 'config_entry_type_e', get_string('config_entry_type', 'block_mrbs', 'E'), get_string('config_entry_type2', 'block_mrbs', 'E'), get_string('external', 'block_mrbs'), PARAM_TEXT); - $mform->addElement('text', 'config_entry_type_f', get_string('config_entry_type', 'block_mrbs', 'F'), get_string('config_entry_type2', 'block_mrbs', 'F'), null, PARAM_TEXT); - $mform->addElement('text', 'config_entry_type_g', get_string('config_entry_type', 'block_mrbs', 'G'), get_string('config_entry_type2', 'block_mrbs', 'G'), null, PARAM_TEXT); - $mform->addElement('text', 'config_entry_type_h', get_string('config_entry_type', 'block_mrbs', 'H'), get_string('config_entry_type2', 'block_mrbs', 'H'), null, PARAM_TEXT); - $mform->addElement('text', 'config_entry_type_i', get_string('config_entry_type', 'block_mrbs', 'I'), get_string('config_entry_type2', 'block_mrbs', 'I'), get_string('internal', 'block_mrbs'), PARAM_TEXT); - $mform->addElement('text', 'config_entry_type_j', get_string('config_entry_type', 'block_mrbs', 'J'), get_string('config_entry_type2', 'block_mrbs', 'J'), null, PARAM_TEXT); - $options = array('0' => get_string('no'), '1' => get_string('yes')); - $mform->addElement('advcheckbox', 'config_mail_admin_on_bookings', get_string('config_mail_admin_on_bookings', 'block_mrbs'), get_string('config_mail_admin_on_bookings2', 'block_mrbs'), '0', $options); - $options = array('0' => get_string('no'), '1' => get_string('yes')); - $mform->addElement('advcheckbox', 'config_mail_area_admin_on_bookings', get_string('config_mail_area_admin_on_bookings', 'block_mrbs'), get_string('config_mail_area_admin_on_bookings2', 'block_mrbs'), 0, $options); - $options = array('0' => get_string('no'), '1' => get_string('yes')); - $mform->addElement('advcheckbox', 'config_mail_room_admin_on_bookings', get_string('config_mail_room_admin_on_bookings', 'block_mrbs'), get_string('config_mail_room_admin_on_bookings2', 'block_mrbs'), 0, $options); - $options = array('0' => get_string('no'), '1' => get_string('yes')); - $mform->addElement('advcheckbox', 'config_mail_admin_on_delete', get_string('config_mail_admin_on_delete', 'block_mrbs'), get_string('config_mail_admin_on_delete2', 'block_mrbs'), 0, $options); - $options = array('0' => get_string('no'), '1' => get_string('yes')); - $mform->addElement('advcheckbox', 'config_mail_admin_all', get_string('config_mail_admin_all', 'block_mrbs'), get_string('config_mail_admin_all2', 'block_mrbs'), 0, $options); - $options = array('0' => get_string('no'), '1' => get_string('yes')); - $mform->addElement('advcheckbox', 'config_mail_details', get_string('config_mail_details', 'block_mrbs'), get_string('config_mail_details2', 'block_mrbs'), 0, $options); - $options = array('0' => get_string('no'), '1' => get_string('yes')); - $mform->addElement('advcheckbox', 'config_mail_booker', get_string('config_mail_booker', 'block_mrbs'), get_string('config_mail_booker2', 'block_mrbs'), 0, $options); - $mform->addElement('text', 'config_mail_from', get_string('config_mail_from', 'block_mrbs'), get_string('config_mail_from2', 'block_mrbs'), $CFG->supportemail, PARAM_TEXT); - $mform->addElement('text', 'config_mail_recipients', get_string('config_mail_recipients', 'block_mrbs'), get_string('config_mail_recipients2', 'block_mrbs'), $CFG->supportemail, PARAM_TEXT); - $mform->addElement('text', 'config_mail_cc', get_string('config_mail_cc', 'block_mrbs'), get_string('config_mail_cc2', 'block_mrbs'), null, PARAM_TEXT); - $mform->addElement('text', 'config_cronfile', get_string('cronfile', 'block_mrbs'), get_string('cronfiledesc', 'block_mrbs'), null, PARAM_TEXT); - } - - function set_data($defaults) { - if (!empty($this->block->config) && is_object($this->block->config)) { - $text = $this->block->config->text; - $draftid_editor = file_get_submitted_draft_itemid('config_text'); - if (empty($text)) { - $currenttext = ''; - } else { - $currenttext = $text; - } - $defaults->config_text['text'] = file_prepare_draft_area($draftid_editor, $this->block->context->id, 'block_html', 'content', 0, array('subdirs'=>true), $currenttext); - $defaults->config_text['itemid'] = $draftid_editor; - $defaults->config_text['format'] = $this->block->config->format; - } else { - $text = ''; - } + $mform->addElement('text', 'config_entry_type_a', get_string('config_entry_type', 'block_mrbs', 'A')); + $mform->addElement('static', '', '', get_string('config_entry_type2', 'block_mrbs', 'A')); + $mform->setType('config_entry_type_a', PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_b', get_string('config_entry_type', 'block_mrbs', 'B')); + $mform->addElement('static', '', '', get_string('config_entry_type2', 'block_mrbs', 'B')); + $mform->setType('config_entry_type_b', PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_c', get_string('config_entry_type', 'block_mrbs', 'C')); + $mform->addElement('static', '', '', get_string('config_entry_type2', 'block_mrbs', 'C')); + $mform->setType('config_entry_type_c', PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_d', get_string('config_entry_type', 'block_mrbs', 'D')); + $mform->addElement('static', '', '', get_string('config_entry_type2', 'block_mrbs', 'D')); + $mform->setType('config_entry_type_d', PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_e', get_string('config_entry_type', 'block_mrbs', 'E')); + $mform->addElement('static', '', '', get_string('config_entry_type2', 'block_mrbs', 'E')); + $mform->setType('config_entry_type_e', PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_f', get_string('config_entry_type', 'block_mrbs', 'F')); + $mform->addElement('static', '', '', get_string('config_entry_type2', 'block_mrbs', 'F')); + $mform->setType('config_entry_type_f', PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_g', get_string('config_entry_type', 'block_mrbs', 'G')); + $mform->addElement('static', '', '', get_string('config_entry_type2', 'block_mrbs', 'G')); + $mform->setType('config_entry_type_g', PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_h', get_string('config_entry_type', 'block_mrbs', 'H')); + $mform->addElement('static', '', '', get_string('config_entry_type2', 'block_mrbs', 'H')); + $mform->setType('config_entry_type_h', PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_i', get_string('config_entry_type', 'block_mrbs', 'I')); + $mform->addElement('static', '', '', get_string('config_entry_type2', 'block_mrbs', 'I')); + $mform->setType('config_entry_type_i', PARAM_TEXT); + $mform->addElement('text', 'config_entry_type_j', get_string('config_entry_type', 'block_mrbs', 'J')); + $mform->addElement('static', '', '', get_string('config_entry_type2', 'block_mrbs', 'J')); + $mform->setType('config_entry_type_j', PARAM_TEXT); - if (!$this->block->user_can_edit() && !empty($this->block->config->title)) { - // If a title has been set but the user cannot edit it format it nicely - $title = $this->block->config->title; - $defaults->config_title = format_string($title, true, $this->page->context); - // Remove the title from the config so that parent::set_data doesn't set it. - unset($this->block->config->title); - } + $mform->addElement('selectyesno', 'config_mail_admin_on_bookings', get_string('config_mail_admin_on_bookings', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_mail_admin_on_bookings2', 'block_mrbs')); + + $mform->addElement('selectyesno', 'config_mail_area_admin_on_bookings', get_string('config_mail_area_admin_on_bookings', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_mail_area_admin_on_bookings2', 'block_mrbs')); + + $mform->addElement('selectyesno', 'config_mail_room_admin_on_bookings', get_string('config_mail_room_admin_on_bookings', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_mail_room_admin_on_bookings2', 'block_mrbs')); + + $mform->addElement('selectyesno', 'config_mail_admin_on_delete', get_string('config_mail_admin_on_delete', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_mail_admin_on_delete2', 'block_mrbs')); + + $mform->addElement('selectyesno', 'config_mail_admin_all', get_string('config_mail_admin_all', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_mail_admin_all2', 'block_mrbs')); + + $mform->addElement('selectyesno', 'config_mail_details', get_string('config_mail_details', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_mail_details2', 'block_mrbs')); + + $mform->addElement('selectyesno', 'config_mail_booker', get_string('config_mail_booker', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_mail_booker2', 'block_mrbs')); + + $mform->addElement('text', 'config_mail_from', get_string('config_mail_from', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_mail_from2', 'block_mrbs')); + $mform->setDefault('config_mail_from', $CFG->supportemail); + $mform->setType('config_mail_from', PARAM_TEXT); + $mform->addElement('text', 'config_mail_recipients', get_string('config_mail_recipients', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_mail_recipients2', 'block_mrbs')); + $mform->setDefault('config_mail_recipients', $CFG->supportemail); + $mform->setType('config_mail_recipients', PARAM_TEXT); + $mform->addElement('text', 'config_mail_cc', get_string('config_mail_cc', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('config_mail_cc2', 'block_mrbs')); + $mform->setType('config_mail_cc', PARAM_TEXT); + $mform->addElement('text', 'config_cronfile', get_string('cronfile', 'block_mrbs')); + $mform->addElement('static', '', '', get_string('cronfiledesc', 'block_mrbs')); + $mform->setType('config_cronfile', PARAM_TEXT); + } - // have to delete text here, otherwise parent::set_data will empty content - // of editor - unset($this->block->config->text); - parent::set_data($defaults); - // restore $text - if (!isset($this->block->config)) { - $this->block->config = new stdClass(); - } - $this->block->config->text = $text; - if (isset($title)) { - // Reset the preserved title - $this->block->config->title = $title; - } - } } diff --git a/import.php b/import.php index 7a3c4ae..7dcfceb 100644 --- a/import.php +++ b/import.php @@ -21,7 +21,6 @@ * regularly, it will replace any non-edited imported bookings with a new copy but * not any that have been edited. * - * It is included by the blocks cron() function each time it runs */ //TODO:maybe set it up like tutorlink etc so that it can take uploaded files directly? @@ -32,147 +31,153 @@ //record time for time taken stat $script_start_time = time(); -$cfg_mrbs = get_config('block/mrbs'); //get Moodle config settings for the MRBS block -if (!isset($cfg_mrbs->periods) or empty($cfg_mrbs->periods)) { - $cfg_mrbs->periods = array(); - $cfg_mrbs->periods[] = "Period 1"; - $cfg_mrbs->periods[] = "Period 2"; - $cfg_mrbs->periods[] = "Period 3"; - $cfg_mrbs->periods[] = "Period 4"; - $cfg_mrbs->periods[] = "Period 5"; - $cfg_mrbs->periods[] = "Period 6"; - $cfg_mrbs->periods[] = "Period 7"; - $cfg_mrbs->periods[] = "Period 8"; - $cfg_mrbs->periods[] = "Period 9"; - $cfg_mrbs->periods[] = "Period 10"; - $cfg_mrbs->periods[] = "Period 11"; - $cfg_mrbs->periods[] = "Period 12"; -} else { - $pds = explode("\n", $cfg_mrbs->periods); - $cfg_mrbs->periods = array(); - foreach ($pds as $pd) { - $pd = trim($pd); - $cfg_mrbs->periods[] = $pd; - } -} -$output = ''; -if (!empty($cfg_mrbs->cronfile) && file_exists($cfg_mrbs->cronfile)) { - if ($mrbs_sessions = fopen($cfg_mrbs->cronfile, 'r')) { - $output .= get_string('startedimport', 'block_mrbs')."\n"; - $now = time(); - $DB->set_field_select('block_mrbs_entry', 'type', 'M', 'type=\'K\' and start_time > ?', array($now)); // Change old imported (type K) records to temporary type M - while ($array = fgetcsv($mrbs_sessions)) { //import timetable into mrbs - $csvrow = new stdClass(); - $csvrow->start_time = clean_param($array[0], PARAM_TEXT); - $csvrow->end_time = clean_param($array[1], PARAM_TEXT); - $csvrow->first_date = clean_param($array[2], PARAM_TEXT); - $csvrow->weekpattern = clean_param($array[3], PARAM_TEXT); - $csvrow->room_name = clean_param($array[4], PARAM_TEXT); - $csvrow->username = clean_param($array[5], PARAM_TEXT); - $csvrow->name = clean_param($array[6], PARAM_TEXT); - $csvrow->description = clean_param($array[7], PARAM_TEXT); - - list($year, $month, $day) = explode('/', $csvrow->first_date); - $date = mktime(00, 00, 00, $month, $day, $year); - $room = room_id_lookup($csvrow->room_name); - $weeks = str_split($csvrow->weekpattern); - foreach ($weeks as $week) { - if (($week == 1) and ($date > $now)) { - $start_time = time_to_datetime($date, $csvrow->start_time); - $end_time = time_to_datetime($date, $csvrow->end_time); - if (!is_timetabled($csvrow->name, $start_time)) { ////only timetable class if it isn't already timetabled elsewhere (class been moved) - $entry = new stdClass(); - $entry->start_time = $start_time; - $entry->end_time = $end_time; - $entry->room_id = $room; - $entry->timestamp = $now; - $entry->create_by = $csvrow->username; - $entry->name = $csvrow->name; - $entry->type = 'K'; - $entry->description = $csvrow->description; - $newentryid = $DB->insert_record('block_mrbs_entry', $entry); - - //If there is another non-imported booking there, send emails. It is assumed that simultanious imported classes are intentional - $sql = "SELECT * - FROM {block_mrbs_entry} AS e - WHERE - ((e.start_time < ? AND e.end_time > ?) - OR (e.start_time < ? AND e.end_time > ?) - OR (e.start_time >= ? AND e.end_time <= ? )) - AND e.room_id = ? AND type <>'K'"; - - //limit to 1 to keep this simpler- if there is a 3-way clash it will be noticed by one of the 2 teachers notified - if ($existingclass = $DB->get_record_sql($sql, array( - $start_time, $start_time, $end_time, - $end_time, $start_time, $end_time, $room - )) - ) { - $hr_start_time = date("j F, Y", $start_time).", ".to_hr_time($start_time); - $a = new stdClass(); - $a->oldbooking = $existingclass->description.'('.$existingclass->id.')'; - $a->newbooking = $csvrow->description.'('.$newentryid.')'; - $a->time = $hr_start_time; - $a->room = $csvrow->room_name; - $a->admin = $cfg_mrbs->admin.' ('.$cfg_mrbs->admin_email.')'; - $output .= get_string('clash', 'block_mrbs', $a); - - $existingteacher = $DB->get_record('user', array('username' => $existingclass->create_by)); - $newteacher = $DB->get_record('user', array('username' => $csvrow->username)); - - $body = get_string('clashemailbody', 'block_mrbs', $a); - - if (email_to_user($existingteacher, $newteacher, get_string('clashemailsub', 'block_mrbs', $a), $body)) { - $output .= ', '.get_string('clashemailsent', 'block_mrbs').' '.$existingteacher->firstname.' '.$existingteacher->lastname.'<'.$existingteacher->email.'>'; - } else { - $output .= get_string('clashemailnotsent', 'block_mrbs').$existingclass->description.'('.$existingclass->id.')'; - } - if (email_to_user($newteacher, $existingteacher, get_string('clashemailsub', 'block_mrbs', $a), $body)) { - $output .= ', '.get_string('clashemailsent', 'block_mrbs').' '.$newteacher->firstname.' '.$newteacher->lastname.'<'.$newteacher->email.'>'; - } else { - $output .= get_string('clashemailnotsent', 'block_mrbs').$csvrow->description.'('.$newentryid.')'; - } - $output .= "\n"; - } - } - } - $date += 604800; - - //checks for being an hour out due to BST/GMT change and corrects - if (date('G', $date) == 01) { - $date = $date + 3600; - } - if (date('G', $date) == 23) { - $date = $date - 3600; - } - } - } +$instances = $DB->get_records('block_instances', array('blockname' => 'mrbs')); +foreach($instances as $instance){ + $instance_id = $instance->id; + $cfg_mrbs = unserialize(base64_decode($instance->configdata)); //get Moodle config settings for this instance of the MRBS block + if (!isset($cfg_mrbs->periods) or empty($cfg_mrbs->periods)) { + $cfg_mrbs->periods = array(); + $cfg_mrbs->periods[] = "Period 1"; + $cfg_mrbs->periods[] = "Period 2"; + $cfg_mrbs->periods[] = "Period 3"; + $cfg_mrbs->periods[] = "Period 4"; + $cfg_mrbs->periods[] = "Period 5"; + $cfg_mrbs->periods[] = "Period 6"; + $cfg_mrbs->periods[] = "Period 7"; + $cfg_mrbs->periods[] = "Period 8"; + $cfg_mrbs->periods[] = "Period 9"; + $cfg_mrbs->periods[] = "Period 10"; + $cfg_mrbs->periods[] = "Period 11"; + $cfg_mrbs->periods[] = "Period 12"; + } else { + $pds = explode("\n", $cfg_mrbs->periods); + $cfg_mrbs->periods = array(); + foreach ($pds as $pd) { + $pd = trim($pd); + $cfg_mrbs->periods[] = $pd; + } + } + $output = ''; + if (!empty($cfg_mrbs->cronfile) && file_exists($cfg_mrbs->cronfile)) { + if ($mrbs_sessions = fopen($cfg_mrbs->cronfile, 'r')) { + $output .= get_string('startedimport', 'block_mrbs')." for instance ".$instance_id."\n"; + $now = time(); + $DB->set_field_select('block_mrbs_entry', 'type', 'M', 'type=\'K\' and instance = ? and start_time > ?', array($instance_id, $now)); // Change old imported (type K) records to temporary type M + while ($array = fgetcsv($mrbs_sessions)) { //import timetable into mrbs + $csvrow = new stdClass(); + $csvrow->instance = $instance_id; + $csvrow->start_time = clean_param($array[0], PARAM_TEXT); + $csvrow->end_time = clean_param($array[1], PARAM_TEXT); + $csvrow->first_date = clean_param($array[2], PARAM_TEXT); + $csvrow->weekpattern = clean_param($array[3], PARAM_TEXT); + $csvrow->room_name = clean_param($array[4], PARAM_TEXT); + $csvrow->username = clean_param($array[5], PARAM_TEXT); + $csvrow->name = clean_param($array[6], PARAM_TEXT); + $csvrow->description = clean_param($array[7], PARAM_TEXT); - // any remaining type M records are no longer in the import file, so delete - $DB->delete_records_select('block_mrbs_entry', 'type=\'M\''); + list($year, $month, $day) = explode('/', $csvrow->first_date); + $date = mktime(00, 00, 00, $month, $day, $year); + $room = room_id_lookup($csvrow->instance, $csvrow->room_name); + $weeks = str_split($csvrow->weekpattern); + foreach ($weeks as $week) { + if (($week == 1) and ($date > $now)) { + $start_time = time_to_datetime($cfg_mrbs->enable_periods, $cfg_mrbs->periods, $date, $csvrow->start_time); + $end_time = time_to_datetime($cfg_mrbs->enable_periods, $cfg_mrbs->periods, $date, $csvrow->end_time); + if (!is_timetabled($csvrow->name, $start_time)) { ////only timetable class if it isn't already timetabled elsewhere (class been moved) + $entry = new stdClass(); + $entry->instance = $instance_id; + $entry->start_time = $start_time; + $entry->end_time = $end_time; + $entry->room_id = $room; + $entry->timestamp = $now; + $entry->create_by = $csvrow->username; + $entry->name = $csvrow->name; + $entry->type = 'K'; + $entry->description = $csvrow->description; + $newentryid = $DB->insert_record('block_mrbs_entry', $entry); - //move the processed file to prevent wasted time re-processing TODO: option for how long to keep these- I've found them useful for debugging but obviously can't keep them for ever - $date = date('Ymd'); - if (rename($cfg_mrbs->cronfile, $cfg_mrbs->cronfile.'.'.$date)) { - $output .= $cfg_mrbs->cronfile.get_string('movedto', 'block_mrbs').$cfg_mrbs->cronfile.'.'.$date."\n"; - } - $script_time_taken = time() - $script_start_time; - $output .= get_string('finishedimport', 'block_mrbs', $script_time_taken); + //If there is another non-imported booking there, send emails. It is assumed that simultanious imported classes are intentional + $sql = "SELECT * + FROM {block_mrbs_entry} AS e + WHERE + ((e.start_time < ? AND e.end_time > ?) + OR (e.start_time < ? AND e.end_time > ?) + OR (e.start_time >= ? AND e.end_time <= ? )) + AND e.room_id = ? AND e.instance = ? AND type <>'K'"; - echo $output; //will only show up if being run via apache + //limit to 1 to keep this simpler- if there is a 3-way clash it will be noticed by one of the 2 teachers notified + if ($existingclass = $DB->get_record_sql($sql, array( + $start_time, $start_time, $end_time, + $end_time, $start_time, $end_time, $room, $instance_id + )) + ) { + $hr_start_time = date("j F, Y", $start_time).", ".to_hr_time($cfg_mrbs->enable_periods, $cfg_mrbs->periods, $start_time); + $a = new stdClass(); + $a->oldbooking = $existingclass->description.'('.$existingclass->id.')'; + $a->newbooking = $csvrow->description.'('.$newentryid.')'; + $a->time = $hr_start_time; + $a->room = $csvrow->room_name; + $a->admin = $cfg_mrbs->admin.' ('.$cfg_mrbs->admin_email.')'; + $output .= get_string('clash', 'block_mrbs', $a); - //email output to admin - if ($mrbsadmin = $DB->get_record('user', array('email' => $cfg_mrbs->admin_email))) { - email_to_user($mrbsadmin, $mrbsadmin, get_string('importlog', 'block_mrbs'), $output); - } + $existingteacher = $DB->get_record('user', array('username' => $existingclass->create_by)); + $newteacher = $DB->get_record('user', array('username' => $csvrow->username)); + + $body = get_string('clashemailbody', 'block_mrbs', $a); + + if (email_to_user($existingteacher, $newteacher, get_string('clashemailsub', 'block_mrbs', $a), $body)) { + $output .= ', '.get_string('clashemailsent', 'block_mrbs').' '.$existingteacher->firstname.' '.$existingteacher->lastname.'<'.$existingteacher->email.'>'; + } else { + $output .= get_string('clashemailnotsent', 'block_mrbs').$existingclass->description.'('.$existingclass->id.')'; + } + if (email_to_user($newteacher, $existingteacher, get_string('clashemailsub', 'block_mrbs', $a), $body)) { + $output .= ', '.get_string('clashemailsent', 'block_mrbs').' '.$newteacher->firstname.' '.$newteacher->lastname.'<'.$newteacher->email.'>'; + } else { + $output .= get_string('clashemailnotsent', 'block_mrbs').$csvrow->description.'('.$newentryid.')'; + } + $output .= "\n"; + } + } + } + $date += 604800; + + //checks for being an hour out due to BST/GMT change and corrects + if (date('G', $date) == 01) { + $date = $date + 3600; + } + if (date('G', $date) == 23) { + $date = $date - 3600; + } + } + } + + // any remaining type M records are no longer in the import file, so delete + $DB->delete_records_select('block_mrbs_entry', 'type=\'M\' and instance=?', array($instance_id)); + + //move the processed file to prevent wasted time re-processing TODO: option for how long to keep these- I've found them useful for debugging but obviously can't keep them for ever + $date = date('Ymd'); + if (rename($cfg_mrbs->cronfile, $cfg_mrbs->cronfile.'.'.$date)) { + $output .= $cfg_mrbs->cronfile.get_string('movedto', 'block_mrbs').$cfg_mrbs->cronfile.'.'.$date."\n"; + } + $script_time_taken = time() - $script_start_time; + $output .= get_string('finishedimport', 'block_mrbs', $script_time_taken).' instance: '.$instance_id."\n"; + + echo $output; //will only show up if being run via apache + + //email output to admin + if ($mrbsadmin = $DB->get_record('user', array('email' => $cfg_mrbs->admin_email))) { + email_to_user($mrbsadmin, $mrbsadmin, get_string('importlog', 'block_mrbs'), $output); + } + } } } //==========================================FUNCTIONS============================================================== //looks up the room id from the name -function room_id_lookup($name) { +function room_id_lookup($instance_id, $name) { global $DB; - if (!$room = $DB->get_record('block_mrbs_room', array('room_name' => $name))) { - $error = "ERROR: failed to return id from database (room $name probably doesn't exist)"; + if (!$room = $DB->get_record('block_mrbs_room', array('instance' => $instance_id, 'room_name' => $name))) { + $error = "ERROR: failed to return id from database (room $name in instanced $instance_id probably doesn't exist)"; echo $error."\n"; return 'error'; } else { @@ -190,15 +195,16 @@ function room_id_lookup($name) { * @param $time int start time of the booking in unix timestamp format * @return bool does a previous booking exist? */ -function is_timetabled($name, $time) { +function is_timetabled($instance_id, $name, $time) { global $DB; - if ($DB->get_record('block_mrbs_entry', array('name' => $name, 'start_time' => $time, 'type' => 'L'))) { + if ($DB->get_record('block_mrbs_entry', array('instance' => $instance_id, 'name' => $name, 'start_time' => $time, 'type' => 'L'))) { return true; } else if ($record = $DB->get_record('block_mrbs_entry', array( - 'name' => $name, 'start_time' => $time, 'type' => 'M' + 'instance' => $instance_id, 'name' => $name, 'start_time' => $time, 'type' => 'M' )) ) { $upd = new stdClass; + $upd->instance =$instance_id; $upd->id = $record->id; $upd->type = 'K'; if ($DB->update_record('block_mrbs_entry', $upd)) { @@ -214,16 +220,17 @@ function is_timetabled($name, $time) { /** * Adds together a date (unixtime) and a time (hh:mm) * + * @param $enable_periods bool custom periods enabled + * @param $periods array custom periods * @param $date integer date in seconds since epoch * @param $time string time in hh:mm format * @return integer date/time in seconds since epoch */ -function time_to_datetime($date, $time) { - global $cfg_mrbs; +function time_to_datetime($enable_periods, $periods, $date, $time) { list($hours, $mins) = explode(':', $time); $hours = intval($hours); $mins = intval($mins); - if ($cfg_mrbs->enable_periods && $hours == 0 && $mins < count($cfg_mrbs->periods)) { + if ($enable_periods && $hours == 0 && $mins < count($periods)) { $hours = 12; // Periods are imported as P1 - 00:00, P2 - 00:01, P3 - 00:02, etc. // but stored internally as P1 - 12:00, P2 - 12:01, P3 - 12:02, etc. } @@ -235,14 +242,15 @@ function time_to_datetime($date, $time) { * If periods are enabled then gives the name of the period starting at this time * Will probably break is some idiot has more than 59 periods per day (seems very unlikely though) * + * @param $enable_periods bool custom periods enabled + * @param $periods array custom periods * @param $time integer unix timestamp * @return string either the time formatted as hh:mm or the name of the period starting at this time */ -function to_hr_time($time) { - $cfg_mrbs = get_config('block/mrbs'); - if ($cfg_mrbs->enable_periods) { +function to_hr_time($enable_periods, $periods, $time) { + if ($enable_periods) { $period = intval(date('i', $time)); - return $cfg_mrbs->periods[$period]; + return $periods[$period]; } else { return date('G:i', $time); } diff --git a/lang/en/block_mrbs.php b/lang/en/block_mrbs.php index 65dfc93..2c1b3dc 100644 --- a/lang/en/block_mrbs.php +++ b/lang/en/block_mrbs.php @@ -233,6 +233,7 @@ $string['must_set_description'] = 'You must set a description'; $string['must_set_name'] = 'You must set a name'; $string['namebooker'] = 'Reservation for'; +$string['newbooking'] = 'New Booking'; $string['newmrbsblock'] = 'New MRBS'; $string['newwindow'] = 'New window'; //see MDL-15952 $string['no_rooms_for_area'] = 'No rooms defined for this area'; diff --git a/version.php b/version.php index 3609834..402be41 100644 --- a/version.php +++ b/version.php @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -$plugin->version = 2017110900; +$plugin->version = 2017111401; $plugin->requires = 2014051200; // Moodle 2.7+ $plugin->component = 'block_mrbs'; $plugin->maturity = MATURITY_ALPHA; -$plugin->release = '3.x (Build: 2017110900)'; +$plugin->release = '3.x (Build: 2017111401)'; diff --git a/web/add.php b/web/add.php index d8c1df6..156aef8 100644 --- a/web/add.php +++ b/web/add.php @@ -27,7 +27,7 @@ $capacity = optional_param('capacity', 0, PARAM_INT); $area = optional_param('area', 0, PARAM_INT); -$thisurl = new moodle_url('/blocks/mrbs/web/add.php', array('type' => $type, 'name' => $name)); +$thisurl = new moodle_url('/blocks/mrbs/web/add.php', array('instance' =>$instance_id, 'type' => $type, 'name' => $name)); if (!empty($description)) { $thisurl->param('description', $description); } @@ -41,7 +41,7 @@ require_login(); if (!getAuthorised(2)) { - showAccessDenied($day, $month, $year, $area); + showAccessDenied($day, $month, $year, $instance_id, $area); exit(); } require_sesskey(); @@ -54,16 +54,18 @@ if ($type == "area") { $newarea = new stdClass; $newarea->area_name = $name; + $newarea->instance = $instance_id; $area = $DB->insert_record('block_mrbs_area', $newarea); } if ($type == "room") { $newroom = new stdClass; $newroom->room_name = $name; + $newroom->instance = $instance_id; $newroom->description = $description; $newroom->capacity = $capacity; $newroom->area_id = $area; $DB->insert_record('block_mrbs_room', $newroom); } -redirect(new moodle_url('/blocks/mrbs/web/admin.php', array('area' => $area))); +redirect(new moodle_url('/blocks/mrbs/web/admin.php', array('instance' => $instance_id, 'area' => $area))); diff --git a/web/admin.php b/web/admin.php index cfb7e86..fcff09b 100644 --- a/web/admin.php +++ b/web/admin.php @@ -34,11 +34,11 @@ $year = date("Y"); } -$thisurl = new moodle_url('/blocks/mrbs/web/admin.php', array('day' => $day, 'month' => $month, 'year' => $year)); +$thisurl = new moodle_url('/blocks/mrbs/web/admin.php', array('instance' => $instance_id, 'day' => $day, 'month' => $month, 'year' => $year)); if ($area) { $thisurl->param('area', $area); } else { - $area = get_default_area(); + $area = get_default_area($instance_id); } $PAGE->set_url($thisurl); @@ -49,12 +49,12 @@ exit(); } -print_header_mrbs($day, $month, $year, isset($area) ? $area : ""); +print_header_mrbs($day, $month, $year, $instance_id, isset($area) ? $area : ""); // If area is set but area name is not known, get the name. if ($area) { if (empty($area_name)) { - $dbarea = $DB->get_record('block_mrbs_area', array('id' => $area), 'area_name', MUST_EXIST); + $dbarea = $DB->get_record('block_mrbs_area', array('instance' => $instance_id, 'id' => $area), 'area_name', MUST_EXIST); $area_name = $dbarea->area_name; } } @@ -69,7 +69,7 @@ echo '
"; //Draw the three month calendars - minicals($year, $month, $day, $area, '', 'day'); + minicals($year, $month, $day, $instance_id, $area, '', 'day'); echo "
'; // 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 +78,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 '
  • '.s($dbarea->area_name).' ('.get_string('edit').') ('.get_string('delete').")\n"; } @@ -92,7 +92,7 @@ // This one has the rooms if ($area) { - $rooms = $DB->get_records('block_mrbs_room', array('area_id' => $area), 'room_name'); + $rooms = $DB->get_records('block_mrbs_room', array('instance' => $instance_id, 'area_id' => $area), 'room_name'); if (empty($rooms)) { // $res = sql_query("select id, room_name, description, capacity from $tbl_room where area_id=$area order by room_name"); echo get_string('norooms', 'block_mrbs'); @@ -100,10 +100,10 @@ echo '
      '; foreach ($rooms as $dbroom) { $editroomurl = new moodle_url('/blocks/mrbs/web/edit_area_room.php', array( - 'room' => $dbroom->id, 'sesskey' => sesskey() + 'instance' => $instance_id, 'room' => $dbroom->id, 'sesskey' => sesskey() )); $delroomurl = new moodle_url('/blocks/mrbs/web/del.php', array( - 'area' => $area, 'room' => $dbroom->id, 'type' => 'room', 'sesskey' => sesskey() + 'instance' => $instance_id, 'area' => $area, 'room' => $dbroom->id, 'type' => 'room', 'sesskey' => sesskey() )); $info = array(); $desc = trim(s($dbroom->description)); @@ -126,7 +126,7 @@ echo get_string('noarea', 'block_mrbs'); } -$addareaurl = new moodle_url('/blocks/mrbs/web/add.php', array('type' => 'area', 'sesskey' => sesskey())); +$addareaurl = new moodle_url('/blocks/mrbs/web/add.php', array('instance' => $instance_id, 'type' => 'area', 'sesskey' => sesskey())); $addroomurl = new moodle_url($addareaurl, array('type' => 'room', 'area' => $area)); echo '
  • '.get_string('addarea', 'block_mrbs').'

    '; diff --git a/web/config.inc.php b/web/config.inc.php index 9c52e5e..77d67f2 100644 --- a/web/config.inc.php +++ b/web/config.inc.php @@ -21,8 +21,21 @@ ########################################################################### //For integration with Moodle +# debug function +function kill($data){ var_dump($data); exit; } +@ini_set('display_errors','1'); 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; + +$instance_id = required_param('instance', 0, PARAM_INT); +if(! isset($instance_id)) { + throw new \coding_exception('instance_id is a required param.'); +} +$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)); //get Moodle config settings for this instance of the MRBS block ################### # Database settings ################### diff --git a/web/day.php b/web/day.php index 156cea1..c74c370 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) { @@ -121,7 +120,8 @@ } echo "

    ".get_string('findroom', 'block_mrbs')."

    - + + @@ -129,7 +129,7 @@
    "; } @@ -168,11 +168,12 @@ $sql = "SELECT e.id AS eid, r.id AS rid, e.start_time, e.end_time, e.name, e.type, e.description FROM {block_mrbs_entry} e, {block_mrbs_room} r - WHERE e.room_id = r.id + WHERE e.instance = ? + AND e.room_id = r.id AND r.area_id = ? AND e.start_time <= ? AND e.end_time > ?"; - $entries = $DB->get_records_sql($sql, array($area, $pm7, $am7)); + $entries = $DB->get_records_sql($sql, array($instance_id, $area, $pm7, $am7)); foreach ($entries as $entry) { // $today is a map of the screen that will be displayed @@ -242,7 +243,7 @@ // We need to know what all the rooms area called, so we can show them all // pull the data from the db and store it. Convienently we can print the room // headings and capacities at the same time - $rooms = $DB->get_records('block_mrbs_room', array('area_id' => $area), 'room_name'); + $rooms = $DB->get_records('block_mrbs_room', array('instance' => $instance_id, 'area_id' => $area), 'room_name'); foreach ($rooms as $room) { $room->allowedtobook = allowed_to_book($USER, $room); } @@ -286,7 +287,7 @@ $room_column_width = (int)(95 / count($rooms)); $weekurl = new moodle_url('/blocks/mrbs/web/week.php', array( - 'year' => $year, 'month' => $month, 'day' => $day, 'area' => $area + 'instance' => $instance_id, 'year' => $year, 'month' => $month, 'day' => $day, 'area' => $area )); foreach ($rooms as $room) { echo " @@ -384,13 +385,15 @@ // Not allowed to book this room echo '
    '; $title = get_string('notallowedbook', 'block_mrbs'); - echo ''.$title.''; + echo $OUTPUT->pix_icon('toofaradvance', $title, 'block_mrbs', + array('width' => '10', 'height' => '10', 'border' => '0', 'title' => $title)); echo '
    '; } else if (!$advanceok) { // Too far in advance to edit echo '
    '; $title = get_string('toofaradvance', 'block_mrbs', $max_advance_days); - echo ''.$title.''; + echo $OUTPUT->pix_icon('toofaradvance', $title, 'block_mrbs', + array('width' => '10', 'height' => '10', 'border' => '0', 'title' => $title)); echo '
    '; } else { if ($javascript_cursor) { @@ -401,6 +404,7 @@ echo "
    "; $editurl = new moodle_url('/blocks/mrbs/web/edit_entry.php', array( + 'instance' => $instance_id, 'room' => $room->id, 'area' => $area, 'year' => $year, 'month' => $month, 'day' => $day )); @@ -409,7 +413,9 @@ } else { echo "out(true, array('hour' => $hour, 'minute' => $minute)))."\">"; } - echo ''; + $title = get_string('newbooking', 'block_mrbs'); + echo $OUTPUT->pix_icon('new', $title, 'block_mrbs', array('width' => '10', 'height' => '10', 'border' => '0')); + echo ''; echo "
    "; if ($javascript_cursor) { echo ""; } $editurl = new moodle_url('/blocks/mrbs/web/edit_entry.php', - array('room' => $room, 'area' => $area, 'year' => $year, 'month' => $month, 'day' => $cday)); + array('instance' => $instance_id, + 'room' => $room, 'area' => $area, 'year' => $year, 'month' => $month, 'day' => $cday)); if ($enable_periods) { echo ''; } else { echo ''; } - echo ''; + $title = get_string('newbooking', 'block_mrbs'); + echo $OUTPUT->pix_icon('new', $title, 'block_mrbs', array('width' => '10', 'height' => '10', 'border' => '0')); + echo ''; if ($javascript_cursor) { echo ""; } $editurl = new moodle_url('/blocks/mrbs/web/edit_entry.php', - array('room' => $room, 'area' => $area, 'year' => $year, 'month' => $month, 'day' => $cday)); + array('instance' => $instance_id, + 'room' => $room, 'area' => $area, 'year' => $year, 'month' => $month, 'day' => $cday)); if ($enable_periods) { echo ''; } else { echo ''; } - echo ''; + $title = get_string('newbooking', 'block_mrbs'); + echo $OUTPUT->pix_icon('new', $title, 'block_mrbs', array('width' => '10', 'height' => '10', 'border' => '0')); + echo ''; if ($javascript_cursor) { echo ""; } $editurl = new moodle_url('/blocks/mrbs/web/edit_entry.php', - array('room' => $room, 'area' => $area, 'year' => $year, 'month' => $month, 'day' => $cday)); + array('instance' => $instance_id, + 'room' => $room, 'area' => $area, 'year' => $year, 'month' => $month, 'day' => $cday)); if ($enable_periods) { echo ''; } else { echo ''; } - echo ''; + $title = get_string('newbooking', 'block_mrbs'); + echo $OUTPUT->pix_icon('new', $title, 'block_mrbs', array('width' => '10', 'height' => '10', 'border' => '0')); + echo ''; if ($javascript_cursor) { echo "