MDL-30544 message: prevented the temporarily disable notifications checkbox from...
authorAndrew Davis <andrew@moodle.com>
Thu, 1 Dec 2011 08:54:48 +0000 (16:54 +0800)
committerAndrew Davis <andrew@moodle.com>
Thu, 1 Dec 2011 08:54:48 +0000 (16:54 +0800)
message/edit.php

index 3e35825..17e0e75 100644 (file)
@@ -107,25 +107,29 @@ if (($form = data_submitted()) && confirm_sesskey()) {
         $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) {
-                    if ($linepref == ''){
-                        $linepref = $process;
-                    } else {
-                        $linepref .= ','.$process;
+    // Turning on emailstop disables the preference checkboxes in the browser.
+    // Disabled checkboxes may not be submitted with the form making them look (incorrectly) like they've been unchecked.
+    // Only alter the messaging preferences if emailstop is turned off
+    if (!$user->emailstop) {
+        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) {
+                        if ($linepref == ''){
+                            $linepref = $process;
+                        } else {
+                            $linepref .= ','.$process;
+                        }
                     }
                 }
+                if (empty($linepref)) {
+                    $linepref = 'none';
+                }
+                $preferences['message_provider_'.$provider->component.'_'.$provider->name.'_'.$state] = $linepref;
             }
-            if (empty($linepref)) {
-                $linepref = 'none';
-            }
-            $preferences['message_provider_'.$provider->component.'_'.$provider->name.'_'.$state] = $linepref;
         }
     }