diff --git a/admin/message.php b/admin/message.php new file mode 100644 index 00000000000..4eccb33d917 --- /dev/null +++ b/admin/message.php @@ -0,0 +1,56 @@ +libdir.'/adminlib.php'); + +// This is an admin page +admin_externalpage_setup('managemessageoutputs'); + +// Require site configuration capability +require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); + +// Get the submitted params +$disable = optional_param('disable', 0, PARAM_INT); +$enable = optional_param('enable', 0, PARAM_INT); + +if (!empty($disable) && confirm_sesskey()) { + if (!$processor = $DB->get_record('message_processors', array('id'=>$disable))) { + print_error('outputdoesnotexist', 'message'); + } + $DB->set_field('message_processors', 'enabled', '0', array('id'=>$processor->id)); // Disable output +} + +if (!empty($enable) && confirm_sesskey() ) { + if (!$processor = $DB->get_record('message_processors', array('id'=>$enable))) { + print_error('outputdoesnotexist', 'message'); + } + $DB->set_field('message_processors', 'enabled', '1', array('id'=>$processor->id)); // Enable output +} + +if ($disable || $enable) { + $url = new moodle_url('message.php'); + redirect($url); +} +// Page settings +$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); + +// Grab the renderer +$renderer = $PAGE->get_renderer('core', 'message'); + +// Display the manage message outputs interface +$processors = get_message_processors(); +$messageoutputs = $renderer->manage_messageoutputs($processors); + +// Display the page +echo $OUTPUT->header(); +echo $OUTPUT->heading(get_string('managemessageoutputs', 'message')); +echo $messageoutputs; +echo $OUTPUT->footer(); \ No newline at end of file diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index bf8060500e5..525d45f4ab8 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -46,6 +46,11 @@ if ($hassiteconfig) { } } + // message outputs + $ADMIN->add('modules', new admin_category('messageoutputs', get_string('messageoutputs', 'message'))); + $ADMIN->add('messageoutputs', new admin_page_managemessageoutputs()); + + // authentication plugins $ADMIN->add('modules', new admin_category('authsettings', get_string('authentication', 'admin'))); diff --git a/lang/en/message.php b/lang/en/message.php index fa805a3bbf3..590392a9fb9 100644 --- a/lang/en/message.php +++ b/lang/en/message.php @@ -64,6 +64,8 @@ $string['loggedindescription'] = 'When I\'m logged in'; $string['loggedoff'] = 'Not online'; $string['loggedoffdescription'] = 'When I\'m offline'; $string['managecontacts'] = 'Manage my contacts'; +$string['managemessageoutputs'] = 'Manage message outputs'; +$string['messageoutputs'] = 'Message outputs'; $string['mostrecent'] = 'Recent messages'; $string['mostrecentconversations'] = 'Recent conversations'; $string['mostrecentnotifications'] = 'Recent notifications'; @@ -90,6 +92,11 @@ $string['onlinecontacts'] = 'Online contacts ({$a})'; $string['onlyfromme'] = 'Only messages from me'; $string['onlymycourses'] = 'Only in my courses'; $string['onlytome'] = 'Only messages to me'; +$string['outputdisabled'] = 'Output disabled'; +$string['outputdoesnotexist'] = 'Message output does not exists'; +$string['outputenabled'] = 'Output enabled'; +$string['outputnotavailable'] = 'Not available'; +$string['outputnotconfigured'] = 'Not configured'; $string['pagerefreshes'] = 'This page refreshes automatically every {$a} seconds'; $string['private_config'] = 'Popup message window'; $string['processortag'] = 'Destination'; diff --git a/lib/adminlib.php b/lib/adminlib.php index 49289ddc1ff..c4b888df914 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -4909,6 +4909,60 @@ class admin_page_manageblocks extends admin_externalpage { } } +/** + * Message outputs configuration + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class admin_page_managemessageoutputs extends admin_externalpage { + /** + * Calls parent::__construct with specific arguments + */ + public function __construct() { + global $CFG; + parent::__construct('managemessageoutputs', get_string('managemessageoutputs', 'message'), "$CFG->wwwroot/$CFG->admin/message.php"); + } + + /** + * Search for a specific block + * + * @param string $query The string to search for + * @return array + */ + public function search($query) { + global $CFG, $DB; + if ($result = parent::search($query)) { + return $result; + } + + $found = false; + if ($blocks = $DB->get_records('block')) { + $textlib = textlib_get_instance(); + foreach ($blocks as $block) { + if (!file_exists("$CFG->dirroot/blocks/$block->name/")) { + continue; + } + if (strpos($block->name, $query) !== false) { + $found = true; + break; + } + $strblockname = get_string('pluginname', 'block_'.$block->name); + if (strpos($textlib->strtolower($strblockname), $query) !== false) { + $found = true; + break; + } + } + } + if ($found) { + $result = new stdClass(); + $result->page = $this; + $result->settings = array(); + return array($this->name => $result); + } else { + return array(); + } + } +} /** * Question type manage page diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 2918eb1bde4..8812c86900a 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -6112,6 +6112,17 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint(true, 2011052300.02); } + if ($oldversion < 2011052500.01) { + // Add enabled filed to message_processors + $table = new xmldb_table('message_processors'); + $field = new xmldb_field('enabled'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'name'); + + // Launch add field addition + if (!$dbman->field_exists($table,$field)) { + $dbman->add_field($table, $field); + } + } return true; } diff --git a/message/lib.php b/message/lib.php index acf231b5fe0..32f6d4cb9b8 100644 --- a/message/lib.php +++ b/message/lib.php @@ -2167,3 +2167,34 @@ function message_print_heading($title, $colspan=3) { echo html_writer::tag('td', $title, array('colspan' => $colspan, 'class' => 'heading')); echo html_writer::end_tag('tr'); } + +/** + * Get all message processors and validate corresponding plugin existance and + * configuration + * @return array $processors array of objects containing information on message processors + */ +function get_message_processors() { + global $DB, $CFG; + + $processors = $DB->get_records('message_processors', null, 'name'); + foreach ($processors as &$processor){ + $processorfile = $CFG->dirroot. '/message/output/'.$processor->name.'/message_output_'.$processor->name.'.php'; + if (is_readable($processorfile)) { + include_once($processorfile); + $processclass = 'message_output_' . $processor->name; + if (class_exists($processclass)) { + $pclass = new $processclass(); + $processor->configured = 0; + if ($pclass->is_system_configured()) { + $processor->configured = 1; + } + $processor->available = 1; + } else { + print_error('errorcallingprocessor', 'message'); + } + } else { + $processor->available = 0; + } + } + return $processors; +} diff --git a/message/renderer.php b/message/renderer.php new file mode 100644 index 00000000000..4fcf586965a --- /dev/null +++ b/message/renderer.php @@ -0,0 +1,92 @@ +attributes['class'] = 'generaltable'; + $table->head = array(); + $table->colclasses = array(); + $table->data = array(); + $table->head = array( + get_string('name'), + get_string('enable'), + get_string('settings'), + ); + $table->colclasses = array( + 'displayname', 'availability', 'settings', + ); + + foreach ( $processors as $processor ){ + $row = new html_table_row(); + $row->attributes['class'] = 'workflow'; + + // Name + $name = new html_table_cell($processor->name); + + // Enable + $enable = new html_table_cell(); + if (!$processor->available) { + $enable->text = html_writer::nonempty_tag('span', get_string('outputnotavailable', 'message'), array('class' => 'error')); + } else if (!$processor->configured) { + $enable->text = html_writer::nonempty_tag('span', get_string('outputnotconfigured', 'message'), array('class' => 'error')); + } else if ($processor->enabled) { + $row->attributes['class'] .= 'enabled'; + $url = new moodle_url('/admin/message.php', array('disable' => $processor->id, 'sesskey' => sesskey())); + $enable->text = html_writer::link($url, html_writer::empty_tag('img', + array('src' => $this->output->pix_url('i/hide'), + 'class' => 'icon', + 'title' => get_string('outputenabled', 'message'), + 'alt' => get_string('outputenabled', 'message'), + ) + )); + } else { + $row->attributes['class'] .= 'disabled'; + $url = new moodle_url('/admin/message.php', array('enable' => $processor->id, 'sesskey' => sesskey())); + $enable->text = html_writer::link($url, html_writer::empty_tag('img', + array('src' => $this->output->pix_url('i/show'), + 'class' => 'icon', + 'title' => get_string('outputdisabled', 'message'), + 'alt' => get_string('outputdisabled', 'message'), + ) + )); + } + + $settings = new html_table_cell(); + if ($processor->available) { + $settingsurl = new moodle_url('/message/output/'.$processor->name.'/settings.php'); + $settings->text = html_writer::link($settingsurl, get_string('settings', 'message')); + } + + $row->cells = array($name, $enable, $settings); + $table->data[] = $row; + } + return html_writer::table($table); + } +} diff --git a/version.php b/version.php index 81ffcf47944..0f5963dcdd7 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2011052500.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2011052500.01; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes