]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10294, MDL-10028, changing messaging/bulk messaging system
authortoyomoyo <toyomoyo>
Wed, 21 Nov 2007 07:53:42 +0000 (07:53 +0000)
committertoyomoyo <toyomoyo>
Wed, 21 Nov 2007 07:53:42 +0000 (07:53 +0000)
lang/en_utf8/role.php
lib/db/access.php
message/discussion.php
message/lib.php
message/send.php
user/index.php
user/messageselect.php
user/view.php
version.php

index 3141c4458f01e6b4d0e38bf26012faba059b799f..e90d35f041f1dd07f83f19d54a73ec6eb3db26cb 100644 (file)
@@ -141,6 +141,7 @@ $string['site:langeditmaster'] = 'Edit master language packages';
 $string['site:manageblocks'] = 'Manage site-level blocks';
 $string['site:readallmessages'] = 'Read all messages on site';
 $string['site:restore'] = 'Restore courses';
+$string['site:sendmessage'] = 'Send messages to any user';
 $string['site:trustcontent'] = 'Trust submitted content';
 $string['site:uploadusers'] = 'Upload new users from file';
 $string['site:viewfullnames'] = 'Always see full names of users';
index 953d7627147512c4134d5a47669f8b5cfa3bc619..29fc73547a4314424374413b96bd8fff1da3fa73 100644 (file)
@@ -120,6 +120,18 @@ $moodle_capabilities = array(
             'editingteacher' => CAP_ALLOW
         )
     ),
+    
+    'moodle/site:sendmessage' => array(
+
+        'riskbitmask' => RISK_PERSONAL,
+
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'admin' => CAP_ALLOW,
+            'user' => CAP_ALLOW
+        )
+    ),   
 
     'moodle/site:approvecourse' => array(
 
index d1c61834d978aa9f3e64836cfbdfc6005563ab80..bfd4e20574f841232d2b800ced57f56c9f2f9a90 100644 (file)
@@ -46,6 +46,7 @@
               scrolling="yes" marginwidth="10" marginheight="10" frameborder="0" />
        <frame src="refresh.php?id=<?php p($user->id)?>&amp;name=<?php echo urlencode(fullname($user)) ?>"  name="refresh"
               scrolling="no"  marginwidth="0" marginheight="0" frameborder="0" />
+       
        <frame src="send.php?id=<?php p($user->id)?>"     name="send"
               scrolling="no"  marginwidth="2" marginheight="2" frameborder="0" />
      </frameset>
index e134fe03ef16de06fc25e467f0b31eec59f1ec75..5c8c4452aebb406d02f54b0c92ce627ad244e0e1 100644 (file)
@@ -113,9 +113,11 @@ function message_print_contacts() {
                     print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow');
                     echo '</td>';
                     echo '<td class="contact">';
+                    
                     link_to_popup_window("/message/discussion.php?id=$contact->id", "message_$contact->id",
                                          $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname),
                                          'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
+
                     echo '</td>';
                     echo '<td class="link">'.$strcontact.'&nbsp;'.$strhistory.'</td>';
                     echo '</tr>';
@@ -148,8 +150,9 @@ function message_print_contacts() {
                 echo '</td>';
                 echo '<td class="contact">';
                 link_to_popup_window("/message/discussion.php?id=$contact->id", "message_$contact->id",
-                        $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname),
-                        'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
+                            $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname),
+                            'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
+
                 echo '</td>';
                 echo '<td class="link">'.$strcontact.'&nbsp;'.$strhistory.'</td>';
                 echo '</tr>';
@@ -180,9 +183,11 @@ function message_print_contacts() {
                 print_user_picture($messageuser->useridfrom, SITEID, $messageuser->picture, 20, false, true, 'userwindow');
                 echo '</td>';
                 echo '<td class="contact">';
+                
                 link_to_popup_window("/message/discussion.php?id=$messageuser->useridfrom", "message_$messageuser->useridfrom",
                                      $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname),
                                      'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
+
                 echo '</td>';
                 echo '<td class="link">&nbsp;'.$strcontact.'&nbsp;'.$strblock.'&nbsp;'.$strhistory.'</td>';
                 echo '</tr>';
@@ -396,6 +401,7 @@ function message_print_search_results($frm) {
                 link_to_popup_window("/message/discussion.php?id=$user->id", "message_$user->id", fullname($user),
                                      500, 500, get_string('sendmessageto', 'message', fullname($user)),
                                      'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
+
                 echo '</td>';
 
                 echo '<td class="link">'.$strcontact.'</td>';
@@ -564,6 +570,7 @@ function message_print_user ($user=false, $iscontact=false, $isblocked=false) {
             message_contact_link($user->id, 'block');
         }
         echo '<br />';
+
         link_to_popup_window("/message/discussion.php?id=$user->id", "message_$user->id",
                              fullname($user), 400, 400, get_string('sendmessageto', 'message', fullname($user)),
                              'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
@@ -987,22 +994,28 @@ function message_post_message($userfrom, $userto, $message, $format, $messagetyp
     $savemessage->timecreated   = time();
     $savemessage->messagetype   = 'direct';
 
-    if (!$savemessage->id = insert_record('message', $savemessage)) {
-        return false;
+    if ($CFG->messaging) {
+        if (!$savemessage->id = insert_record('message', $savemessage)) {
+            return false;
+        }
+        $emailforced = false;
+    } else { // $CFG->messaging is not on, we need to force sending of emails
+        $emailforced = true;
+        $savemessage->id = true; 
     }
 
 /// Check to see if anything else needs to be done with it
 
     $preference = (object)get_user_preferences(NULL, NULL, $userto->id);
 
-    if (!isset($preference->message_emailmessages) || $preference->message_emailmessages) {  // Receiver wants mail forwarding
+    if ($emailforced || (!isset($preference->message_emailmessages) || $preference->message_emailmessages)) {  // Receiver wants mail forwarding
         if (!isset($preference->message_emailtimenosee)) {
             $preference->message_emailtimenosee = 10;
         }
         if (!isset($preference->message_emailformat)) {
             $preference->message_emailformat = FORMAT_HTML;
         }
-        if ((time() - $userto->lastaccess) > ((int)$preference->message_emailtimenosee * 60)) { // Long enough
+        if ($emailforced || (time() - $userto->lastaccess) > ((int)$preference->message_emailtimenosee * 60)) { // Long enough
 
             $message = stripslashes_safe($message);
             $tagline = get_string('emailtagline', 'message', $SITE->shortname);
@@ -1014,7 +1027,10 @@ function message_post_message($userfrom, $userto, $message, $format, $messagetyp
 
             if (isset($preference->message_emailformat) and $preference->message_emailformat == FORMAT_HTML) {
                 $messagehtml  = format_text($message, $format);
-                $messagehtml .= '<hr /><p><a href="'.$CFG->wwwroot.'/message/index.php?popup=1">'.$tagline.'</a></p>';
+                // MDL-10294, do not print link if messaging is disabled
+                if ($CFG->messaging) {
+                    $messagehtml .= '<hr /><p><a href="'.$CFG->wwwroot.'/message/index.php?popup=1">'.$tagline.'</a></p>';
+                }
             } else {
                 $messagehtml = NULL;
             }
@@ -1022,9 +1038,11 @@ function message_post_message($userfrom, $userto, $message, $format, $messagetyp
             if (!empty($preference->message_emailaddress)) {
                 $userto->email = $preference->message_emailaddress;   // Use custom messaging address
             }
+
             if (email_to_user($userto, $userfrom, $messagesubject, $messagetext, $messagehtml)) {
                 $CFG->messagewasjustemailed = true;
             }
+
             sleep(3);
         }
     }
index 6edc15c8c8edee6a9b9eaa16932fc66248b22718..c8d085a5331b464f3f9179489c868729c2598dcb 100644 (file)
@@ -1,17 +1,20 @@
 <?php // $Id$
 
-    require('../config.php');
-    require('lib.php');
+require('../config.php');
+require('lib.php');
 
-    require_login();
+require_login();
 
-    if (isguest()) {
-        redirect($CFG->wwwroot);
-    }
+if (isguest()) {
+    redirect($CFG->wwwroot);
+}
+
+if (empty($CFG->messaging)) {
+    error("Messaging is disabled on this site");
+}
+
+if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM))) {
 
-    if (empty($CFG->messaging)) {
-        error("Messaging is disabled on this site");
-    }
 
 /// Don't use print_header, for more speed
     $stylesheetshtml = '';
     echo "\n-->\n</script>\n\n";
 
     echo '</body></html>';
-
+}
 ?>
index fcc43594b0dfd383d52dc7473f6ff27793b6dd3e..b8e250429d464329fc203de3bc8ff581d3051a72 100644 (file)
         echo '<input type="button" onclick="checkall()" value="'.get_string('selectall').'" /> ';
         echo '<input type="button" onclick="checknone()" value="'.get_string('deselectall').'" /> ';
         $displaylist = array();
-        // fix for MDL-8885, only show this if user has capability
-        if (has_capability('moodle/site:readallmessages', $context) && !empty($CFG->messaging)) {
-            $displaylist['messageselect.php'] = get_string('messageselectadd');
-        }
+        $displaylist['messageselect.php'] = get_string('messageselectadd');
         if (has_capability('moodle/notes:manage', $context) && $context->id != $frontpagectx->id) {
             $displaylist['addnote.php'] = get_string('addnewnote', 'notes');
             $displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes');
         }
-        
+
         if ($context->id != $frontpagectx->id) {
             $displaylist['extendenrol.php'] = get_string('extendenrol');
             $displaylist['groupextendenrol.php'] = get_string('groupextendenrol');
index 49ee850d73b62d520e1c106932a0a687f26b3574..28f1e89c6da75c78de4c635dfa6bb5976c21e144 100644 (file)
     }
 
     require_login();
-    require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_COURSE, $id));
 
-    // fix for MDL-10112
-    if (empty($CFG->messaging)) {
-        error("Messaging is disabled on this site");
-    }
+    require_capability('moodle/course:bulkmessaging', get_context_instance(CONTEXT_COURSE, $id));
+
 
     if (empty($SESSION->emailto)) {
         $SESSION->emailto = array();
 
     print_header($strtitle,$strtitle,$navigation,$formstart);
 
+    // if messaging is disabled on site, we can still allow users with capabilities to send emails instead
+    if (empty($CFG->messaging)) {
+        notify("Messaging is disabled on this site, emails will be sent instead");  
+    }
 
     if ($count) {
         if ($count == 1) {
index 0dc5e48529c0783ede73af5158b63b0168e8a90f..f25006bd2f750c3ee9c2da294c0c302f14b7d541 100644 (file)
         echo '</form>';
     }
 
-    if (!empty($CFG->messaging) and !isguest()) {
+    if (!empty($CFG->messaging) and !isguest() and has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM))) {
         if (!empty($USER->id) and ($USER->id == $user->id)) {
             if ($countmessages = count_records('message', 'useridto', $user->id)) {
                 $messagebuttonname = get_string("messages", "message")."($countmessages)";
index 9d234f5631a7da1bd583a22932ec1fff30236425..c7523a6c8b8f1b9a79a487b5fe3c7c58867fc4e3 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2007101503;  // YYYYMMDD = date
+    $version = 2007101504;  // YYYYMMDD = date
                             //       XY = increments within a single day
 
     $release = '2.0 dev';   // Human-friendly version name