diff --git a/lang/en/message.php b/lang/en/message.php index 3d562fd5747..60993bc4ca6 100644 --- a/lang/en/message.php +++ b/lang/en/message.php @@ -44,6 +44,8 @@ $string['couldnotfindpreference'] = 'Could not load preference {$a}. Does the co $string['defaultmessageoutputs'] = 'Default message outputs'; $string['defaults'] = 'Defaults'; $string['deletemessagesdays'] = 'Number of days before old messages are automatically deleted'; +$string['disableall'] = 'Temporarily disable notifications'; +$string['disableall_help'] = 'Temporarily disable all notifications except those marked as "forced" by the site administrator'; $string['disabled'] = 'Messaging is disabled on this site'; $string['disallowed'] = 'Disallowed'; $string['discussion'] = 'Discussion'; diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index a4f88097e60..50833c259ca 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -6696,8 +6696,16 @@ FROM upgrade_main_savepoint(true, 2011083100.02); } + if ($oldversion < 2011091200.00) { + //preference not required since 2.0 + $DB->delete_records('user_preferences', array('name'=>'message_showmessagewindow')); + + //re-introducing emailstop. check that its turned off so people dont suddenly stop getting notifications + $DB->set_field('user', 'emailstop', 0, array('emailstop' => 1)); + + upgrade_main_savepoint(true, 2011091200.00); + } + return true; } - -//TODO: AFTER 2.0 remove the column user->emailstop and the user preference "message_showmessagewindow" diff --git a/lib/messagelib.php b/lib/messagelib.php index d6a6c975d56..ec2970c753a 100644 --- a/lib/messagelib.php +++ b/lib/messagelib.php @@ -131,6 +131,7 @@ function message_send($eventdata) { } // Find out if user has configured this output + // Some processors cannot function without settings from the user $userisconfigured = $processor->object->is_user_configured($eventdata->userto); // DEBUG: notify if we are forcing unconfigured output @@ -142,7 +143,7 @@ function message_send($eventdata) { if ($permitted == 'forced' && $userisconfigured) { // We force messages for this processor, so use this processor unconditionally if user has configured it $processorlist[] = $processor->name; - } else if ($permitted == 'permitted' && $userisconfigured) { + } else if ($permitted == 'permitted' && $userisconfigured && !$eventdata->userto->emailstop) { // User settings are permitted, see if user set any, otherwise use site default ones $userpreferencename = 'message_provider_'.$preferencebase.'_'.$userstate; if ($userpreference = get_user_preferences($userpreferencename, null, $eventdata->userto->id)) { diff --git a/message/edit.php b/message/edit.php index 479d876a4d7..3e35825eb72 100644 --- a/message/edit.php +++ b/message/edit.php @@ -28,6 +28,7 @@ require_once($CFG->dirroot . '/message/lib.php'); $userid = optional_param('id', $USER->id, PARAM_INT); // user id $course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site) +$disableall = optional_param('disableall', 0, PARAM_BOOL); //disable all of this user's notifications $url = new moodle_url('/message/edit.php'); if ($userid !== $USER->id) { @@ -68,6 +69,7 @@ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $PAGE->set_context($personalcontext); $PAGE->set_pagelayout('course'); +$PAGE->requires->js_init_call('M.core_message.init_editsettings'); // check access control if ($user->id == $USER->id) { @@ -99,13 +101,20 @@ $providers = message_get_providers_for_user($user->id); if (($form = data_submitted()) && confirm_sesskey()) { $preferences = array(); + //only update the user's "emailstop" if its actually changed + if ( $user->emailstop != $disableall ) { + $user->emailstop = $disableall; + $DB->set_field('user', 'emailstop', $user->emailstop, array("id"=>$user->id)); + } + + foreach ($providers as $provider) { $componentproviderbase = $provider->component.'_'.$provider->name; foreach (array('loggedin', 'loggedoff') as $state) { $linepref = ''; $componentproviderstate = $componentproviderbase.'_'.$state; if (array_key_exists($componentproviderstate, $form)) { - foreach (array_keys($form->{$componentproviderstate}) as $process){ + foreach (array_keys($form->{$componentproviderstate}) as $process) { if ($linepref == ''){ $linepref = $process; } else { @@ -185,7 +194,7 @@ $renderer = $PAGE->get_renderer('core', 'message'); // Fetch default (site) preferences $defaultpreferences = get_message_output_default_preferences(); -$messagingoptions = $renderer->manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences); +$messagingoptions = $renderer->manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences, $user->emailstop); echo $OUTPUT->header(); echo $messagingoptions; diff --git a/message/module.js b/message/module.js index d92f7484b8a..f0d17c1273f 100644 --- a/message/module.js +++ b/message/module.js @@ -87,4 +87,28 @@ M.core_message.init_defaultoutputs = function(Y) { } defaultoutputs.init(); +} + +M.core_message.init_editsettings = function(Y) { + var editsettings = { + + init : function() { + var disableall = Y.one(".disableallcheckbox"); + disableall.on('change', editsettings.changeState); + disableall.simulate("change"); + }, + + changeState : function(e) { + Y.all('.notificationpreference').each(function(node) { + var disabled = e.target.get('checked'); + + node.removeAttribute('disabled'); + if (disabled) { + node.setAttribute('disabled', 1) + } + }, this); + } + } + + editsettings.init(); } \ No newline at end of file diff --git a/message/renderer.php b/message/renderer.php index b3dfef94db7..d941c9523a6 100644 --- a/message/renderer.php +++ b/message/renderer.php @@ -210,9 +210,11 @@ class core_message_renderer extends plugin_renderer_base { * @param mixed $providers array of objects containing message providers * @param mixed $preferences array of objects containing current preferences * @param mixed $defaultpreferences array of objects containing site default preferences + * $param boolean $notificationsdisabled indicates whether the user's "emailstop" flag is + * set so shouldn't receive any non-forced notifications * @return string The text to render */ - public function manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences) { + public function manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences, $notificationsdisabled = false) { // Filter out enabled, available system_configured and user_configured processors only. $readyprocessors = array_filter($processors, create_function('$a', 'return $a->enabled && $a->configured && $a->object->is_user_configured();')); @@ -281,7 +283,10 @@ class core_message_renderer extends plugin_renderer_base { $disabled['disabled'] = 1; } else { $checked = false; - // See if hser has touched this preference + if ($notificationsdisabled) { + $disabled['disabled'] = 1; + } + // See if user has touched this preference if (isset($preferences->{$preferencebase.'_'.$state})) { // User have some preferneces for this state in the database, use them $checked = isset($preferences->{$preferencebase.'_'.$state}[$processor->name]); @@ -304,7 +309,7 @@ class core_message_renderer extends plugin_renderer_base { ); $label = get_string('sendingviawhen', 'message', $labelparams); $cellcontent = html_writer::label($label, $elementname, true, array('class' => 'accesshide')); - $cellcontent .= html_writer::checkbox($elementname, 1, $checked, '', array_merge(array('id' => $elementname), $disabled)); + $cellcontent .= html_writer::checkbox($elementname, 1, $checked, '', array_merge(array('id' => $elementname, 'class' => 'notificationpreference'), $disabled)); $optioncell = new html_table_cell($cellcontent); $optioncell->attributes['class'] = 'mdl-align'; } @@ -316,6 +321,10 @@ class core_message_renderer extends plugin_renderer_base { $output .= html_writer::start_tag('div'); $output .= html_writer::table($table); $output .= html_writer::end_tag('div'); + + $disableallcheckbox = $this->output->help_icon('disableall', 'message') . get_string('disableall', 'message') . html_writer::checkbox('disableall', 1, $notificationsdisabled, '', array('class'=>'disableallcheckbox')); + $output .= html_writer::nonempty_tag('div', $disableallcheckbox, array('class'=>'disableall')); + $output .= html_writer::end_tag('fieldset'); foreach ($processors as $processor) { diff --git a/version.php b/version.php index 55f7a21360a..6f6c42ec367 100644 --- a/version.php +++ b/version.php @@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2011090700.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2011091200.00; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes