MDL-14522 - new capability "receivemail" for better control who gets the email after
authoragrabs <agrabs>
Wed, 14 May 2008 22:34:00 +0000 (22:34 +0000)
committeragrabs <agrabs>
Wed, 14 May 2008 22:34:00 +0000 (22:34 +0000)
 a response.
New option site_after_submit to define the url of the continue-button after completing
 a feedback

mod/feedback/backuplib.php
mod/feedback/complete.php
mod/feedback/complete_guest.php
mod/feedback/db/access.php
mod/feedback/db/install.xml
mod/feedback/db/upgrade.php
mod/feedback/lib.php
mod/feedback/mod_form.php
mod/feedback/restorelib.php
mod/feedback/version.php

index e9fc46a..80f2fce 100644 (file)
@@ -63,6 +63,7 @@
       fwrite ($bf,full_tag("EMAILNOTIFICATION",4,false,$feedback->email_notification));
       fwrite ($bf,full_tag("MULTIPLESUBMIT",4,false,$feedback->multiple_submit));
       fwrite ($bf,full_tag("AUTONUMBERING",4,false,$feedback->autonumbering));
+      fwrite ($bf,full_tag("SITEAFTERSUB",4,false,$feedback->site_after_submit));
       fwrite ($bf,full_tag("PAGEAFTERSUB",4,false,$feedback->page_after_submit));
       fwrite ($bf,full_tag("PUBLISHSTATS",4,false,$feedback->publish_stats));
       fwrite ($bf,full_tag("TIMEOPEN",4,false,$feedback->timeopen));
index 0fc3919..a1c8c93 100644 (file)
                 $savereturn = 'saved';
                 if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
                     add_to_log($course->id, 'feedback', 'submit', 'view.php?id='.$cm->id, $feedback->id, $cm->id, $userid);
-                    feedback_email_teachers($cm, $feedback, $course, $userid);
+                    feedback_send_email($cm, $feedback, $course, $userid);
                 }else {
-                    feedback_email_teachers_anonym($cm, $feedback, $course, $userid);
+                    feedback_send_email_anonym($cm, $feedback, $course, $userid);
                 }
                 //tracking the submit
                 $multiple_count = null;
                     echo '</p>';
                 }
             }
-            if($courseid) {
-                print_continue($CFG->wwwroot.'/course/view.php?id='.$courseid);
+            if($feedback->site_after_submit) {
+                print_continue(feedback_encode_target_url($feedback->site_after_submit));
             }else {
-                if($course->id == SITEID) {
-                    print_continue($CFG->wwwroot);
-                } else {
-                    print_continue($CFG->wwwroot.'/course/view.php?id='.$course->id);
+                if($courseid) {
+                    print_continue($CFG->wwwroot.'/course/view.php?id='.$courseid);
+                }else {
+                    if($course->id == SITEID) {
+                        print_continue($CFG->wwwroot);
+                    } else {
+                        print_continue($CFG->wwwroot.'/course/view.php?id='.$course->id);
+                    }
                 }
             }
         }else {
index aa29e8e..658d2d9 100644 (file)
                 feedback_delete_completedtmp($completedid);
             }else if($new_completed_id = feedback_save_tmp_values($feedbackcompletedtmp, false, $userid)) {
                 $savereturn = 'saved';
-                feedback_email_teachers_anonym($cm, $feedback, $course, $userid);
+                feedback_send_email_anonym($cm, $feedback, $course, $userid);
                 unset($SESSION->feedback->is_started);
                 
             }else {
                     echo '</p>';
                 }
             }
-            if($courseid) {
-                if($courseid == SITEID) {
-                    print_continue($CFG->wwwroot);
-                }else {
-                    print_continue($CFG->wwwroot.'/course/view.php?id='.$courseid);
-                }
+            if($feedback->site_after_submit) {
+                print_continue(feedback_encode_target_url($feedback->site_after_submit));
             }else {
-                if($course->id == SITEID) {
-                    print_continue($CFG->wwwroot);
-                } else {
-                    print_continue($CFG->wwwroot.'/course/view.php?id='.$course->id);
+                if($courseid) {
+                    if($courseid == SITEID) {
+                        print_continue($CFG->wwwroot);
+                    }else {
+                        print_continue($CFG->wwwroot.'/course/view.php?id='.$courseid);
+                    }
+                }else {
+                    if($course->id == SITEID) {
+                        print_continue($CFG->wwwroot);
+                    } else {
+                        print_continue($CFG->wwwroot.'/course/view.php?id='.$course->id);
+                    }
                 }
             }
         }else {
index ec726d2..74a399b 100644 (file)
@@ -139,6 +139,19 @@ $mod_feedback_capabilities = array(
         )
     ),
 
+    'mod/feedback:receivemail' => array(
+    
+        'riskbitmask' => RISK_PERSONAL,
+
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_MODULE,
+        'legacy' => array(
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'admin' => CAP_PREVENT
+        )
+    ),
+
 );
 
 ?>
index c457980..c25077a 100644 (file)
@@ -10,8 +10,9 @@
         <FIELD NAME="anonymous" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="summary" NEXT="email_notification"/>
         <FIELD NAME="email_notification" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="anonymous" NEXT="multiple_submit"/>
         <FIELD NAME="multiple_submit" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="email_notification" NEXT="autonumbering"/>
-        <FIELD NAME="autonumbering" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="multiple_submit" NEXT="page_after_submit"/>
-        <FIELD NAME="page_after_submit" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="autonumbering" NEXT="publish_stats"/>
+        <FIELD NAME="autonumbering" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="multiple_submit" NEXT="site_after_submit"/>
+        <FIELD NAME="site_after_submit" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="autonumbering" NEXT="page_after_submit"/>
+        <FIELD NAME="page_after_submit" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="site_after_submit" NEXT="publish_stats"/>
         <FIELD NAME="publish_stats" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="page_after_submit" NEXT="timeopen"/>
         <FIELD NAME="timeopen" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="publish_stats" NEXT="timeclose"/>
         <FIELD NAME="timeclose" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timeopen" NEXT="timemodified"/>
index 9da2372..24c27a8 100644 (file)
@@ -207,6 +207,15 @@ function xmldb_feedback_upgrade($oldversion=0) {
         /// Launch add field2
         $result = $result && add_field($table, $field);
     }
+
+    if ($result && $oldversion < 2008050104) {
+        /// Define field site_after_submit to be added to feedback
+        $table = new XMLDBTable('feedback');
+        $field = new XMLDBField('site_after_submit');
+        $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, false, null, null, '', 'autonumbering');
+        /// Launch add field2
+        $result = $result && add_field($table, $field);
+    }
     return $result;
 }
 
index c028a8a..3703bdf 100644 (file)
@@ -40,6 +40,9 @@ function feedback_add_instance($feedback) {
     if(empty($feedback->closeenable)) {
         $feedback->timeclose = 0;
     }
+    if(empty($feedback->site_after_submit)) {
+        $feedback->site_after_submit = '';
+    }
 
     //saving the feedback in db
     if(!$feedbackid = insert_record("feedback", $feedback)) {
@@ -68,6 +71,9 @@ function feedback_update_instance($feedback) {
     if(empty($feedback->closeenable)) {
         $feedback->timeclose = 0;
     }
+    if(empty($feedback->site_after_submit)) {
+        $feedback->site_after_submit = '';
+    }
 
     //save the feedback into the db
     if(!update_record("feedback", $feedback)) {
@@ -345,6 +351,7 @@ function feedback_load_capabilities($cmid) {
     $cb->mapcourse = has_capability('mod/feedback:mapcourse', $context, NULL, false);
     $cb->edititems = has_capability('mod/feedback:edititems', $context, NULL, false);
     $cb->viewreports = has_capability('mod/feedback:viewreports', $context, NULL, false);
+    $cb->receivemail = has_capability('mod/feedback:receivemail', $context, NULL, false);
     $cb->createprivatetemplate = has_capability('mod/feedback:createprivatetemplate', $context, NULL, false);
     $cb->createpublictemplate = has_capability('mod/feedback:createpublictemplate', $context, NULL, false);
     $cb->deletetemplate = has_capability('mod/feedback:deletetemplate', $context, NULL, false);
@@ -377,6 +384,7 @@ function feedback_load_course_capabilities($courseid) {
     $ccb->mapcourse = has_capability('mod/feedback:mapcourse', $context, NULL, false);
     $ccb->edititems = has_capability('mod/feedback:edititems', $context, NULL, false);
     $ccb->viewreports = has_capability('mod/feedback:viewreports', $context, NULL, false);
+    $ccb->receivemail = has_capability('mod/feedback:receivemail', $context, NULL, false);
     $ccb->createprivatetemplate = has_capability('mod/feedback:createprivatetemplate', $context, NULL, false);
     $ccb->createpublictemplate = has_capability('mod/feedback:createpublictemplate', $context, NULL, false);
     $ccb->deletetemplate = has_capability('mod/feedback:deletetemplate', $context, NULL, false);
@@ -433,6 +441,22 @@ function feedback_get_viewreports_users($cmid, $groups = false) {
     return get_users_by_capability($context, 'mod/feedback:viewreports', '', 'lastname', '', '', $groups, '', false);
 }
 
+/** 
+ *  get users which have the receivemail-capability
+ *  @param int $cmid
+ *  @param mixed $groups single groupid or array of groupids - group(s) user is in
+ *  @return object the userrecords
+ */
+function feedback_get_receivemail_users($cmid, $groups = false) {
+
+    if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) {
+            print_error('badcontext');
+    }
+    
+    //description of the call below: get_users_by_capability($context, $capability, $fields='', $sort='', $limitfrom='', $limitnum='', $groups='', $exceptions='', $doanything=true)
+    return get_users_by_capability($context, 'mod/feedback:receivemail', '', 'lastname', '', '', $groups, '', false);
+}
+
 ////////////////////////////////////////////////
 //functions to handle the templates
 ////////////////////////////////////////////////
@@ -1605,7 +1629,7 @@ function feedback_print_numeric_option_list($startval, $endval, $selectval = '',
  *  @param $userid
  *  @return void
  */
-function feedback_email_teachers($cm, $feedback, $course, $userid) {
+function feedback_send_email($cm, $feedback, $course, $userid) {
     
     global $CFG;
     
@@ -1625,9 +1649,9 @@ function feedback_email_teachers($cm, $feedback, $course, $userid) {
                                              ORDER BY name ASC");
         $groups = array_values($groups);
         
-        $teachers = feedback_get_viewreports_users($cm->id, $groups);
+        $teachers = feedback_get_receivemail_users($cm->id, $groups);
     } else {
-        $teachers = feedback_get_viewreports_users($cm->id);
+        $teachers = feedback_get_receivemail_users($cm->id);
     }
     
     if ($teachers) {
@@ -1644,8 +1668,8 @@ function feedback_email_teachers($cm, $feedback, $course, $userid) {
             $info->url = $CFG->wwwroot.'/mod/feedback/show_entries.php?id='.$cm->id.'&userid='.$userid.'&do_show=showentries';
 
             $postsubject = $strcompleted.': '.$info->username.' -> '.$feedback->name;
-            $posttext = feedback_email_teachers_text($info, $course);
-            $posthtml = ($teacher->mailformat == 1) ? feedback_email_teachers_html($info, $course, $cm) : '';
+            $posttext = feedback_send_email_text($info, $course);
+            $posthtml = ($teacher->mailformat == 1) ? feedback_send_email_html($info, $course, $cm) : '';
             
             if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
                 @email_to_user($teacher, $user, $postsubject, $posttext, $posthtml);
@@ -1663,7 +1687,7 @@ function feedback_email_teachers($cm, $feedback, $course, $userid) {
  *  @param $course
  *  @return void
  */
-function feedback_email_teachers_anonym($cm, $feedback, $course) {
+function feedback_send_email_anonym($cm, $feedback, $course) {
     
     global $CFG;
     
@@ -1672,7 +1696,7 @@ function feedback_email_teachers_anonym($cm, $feedback, $course) {
     }
     
     // $teachers = get_course_teachers($course->id);
-    $teachers = feedback_get_viewreports_users($cm->id);
+    $teachers = feedback_get_receivemail_users($cm->id);
 
     if ($teachers) {
 
@@ -1688,8 +1712,8 @@ function feedback_email_teachers_anonym($cm, $feedback, $course) {
             $info->url = $CFG->wwwroot.'/mod/feedback/show_entries_anonym.php?id='.$cm->id;
 
             $postsubject = $strcompleted.': '.$info->username.' -> '.$feedback->name;
-            $posttext = feedback_email_teachers_text($info, $course);
-            $posthtml = ($teacher->mailformat == 1) ? feedback_email_teachers_html($info, $course, $cm) : '';
+            $posttext = feedback_send_email_text($info, $course);
+            $posthtml = ($teacher->mailformat == 1) ? feedback_send_email_html($info, $course, $cm) : '';
             
             @email_to_user($teacher, $teacher, $postsubject, $posttext, $posthtml);
         }
@@ -1702,7 +1726,7 @@ function feedback_email_teachers_anonym($cm, $feedback, $course) {
  *  @param object $course
  *  @return string the text you want to post
  */
-function feedback_email_teachers_text($info, $course) {
+function feedback_send_email_text($info, $course) {
     $posttext  = $course->shortname.' -> '.get_string('modulenameplural', 'feedback').' -> '.
                     $info->feedback."\n";
     $posttext .= '---------------------------------------------------------------------'."\n";
@@ -1718,7 +1742,7 @@ function feedback_email_teachers_text($info, $course) {
  *  @param object $course
  *  @return string the text you want to post
  */
-function feedback_email_teachers_html($info, $course, $cm) {
+function feedback_send_email_html($info, $course, $cm) {
     global $CFG;
     $posthtml  = '<p><font face="sans-serif">'.
                 '<a href="'.$CFG->wwwroot.htmlspecialchars('/course/view.php?id='.$course->id).'">'.$course->shortname.'</a> ->'.
@@ -1756,4 +1780,12 @@ function feedback_print_errors() {
     $SESSION->feedback->errors = array(); //remove errors
 } 
 
+function feedback_encode_target_url($url) {
+    if (strpos($url, '?')) {
+        list($part1, $part2) = explode('?', $url, 2); //maximal 2 parts
+        return $part1 . '?' . htmlentities($part2);
+    } else {
+        return $url;
+    }
+}
 ?>
index af4be21..48d8200 100644 (file)
@@ -27,7 +27,6 @@ class mod_feedback_mod_form extends moodleform_mod {
         $mform->addElement('htmleditor', 'summary', get_string("description", "feedback"), array('rows' => 20));
         $mform->setType('summary', PARAM_RAW);
         $mform->addRule('summary', null, 'required', null, 'client');
-        $mform->setHelpButton('summary', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
 
         //-------------------------------------------------------------------------------
         $mform->addElement('header', 'timinghdr', get_string('timing', 'form'));
@@ -80,14 +79,18 @@ class mod_feedback_mod_form extends moodleform_mod {
         //-------------------------------------------------------------------------------
         $mform->addElement('header', 'aftersubmithdr', get_string('after_submit', 'feedback'));
         
+        $mform->addElement('text', 'site_after_submit', get_string('site_after_submit', 'feedback'), array('size'=>'64','maxlength'=>'255'));
+        $mform->setType('site_after_submit', PARAM_TEXT);
+
         $mform->addElement('htmleditor', 'page_after_submit', get_string("page_after_submit", "feedback"), array('rows' => 20));
         $mform->setType('page_after_submit', PARAM_RAW);
-        $mform->setHelpButton('page_after_submit', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
         //-------------------------------------------------------------------------------
         $features = new stdClass;
         $features->groups = true;
         $features->groupings = true;
         $features->groupmembersonly = true;
+        $features->gradecat = false;
+        $features->idnumber = false;
         $this->standard_coursemodule_elements($features);
         //-------------------------------------------------------------------------------
         // buttons
index 884f788..a4b27a3 100644 (file)
@@ -56,6 +56,7 @@
             $feedback->multiple_submit = backup_todb($info['MOD']['#']['MULTIPLESUBMIT']['0']['#']);
             $feedback->autonumbering = backup_todb($info['MOD']['#']['AUTONUMBERING']['0']['#']);
             $feedback->page_after_submit = backup_todb($info['MOD']['#']['PAGEAFTERSUB']['0']['#']);
+            $feedback->site_after_submit = backup_todb($info['MOD']['#']['SITEAFTERSUB']['0']['#']);
             $feedback->publish_stats = backup_todb($info['MOD']['#']['PUBLISHSTATS']['0']['#']);
             $feedback->timeopen = backup_todb($info['MOD']['#']['TIMEOPEN']['0']['#']);
             $feedback->timeclose = backup_todb($info['MOD']['#']['TIMECLOSE']['0']['#']);
index 02eafbe..703872f 100644 (file)
@@ -10,7 +10,7 @@
 */
 
    
-    $module->version = 2008042904; // The current module version (Date: YYYYMMDDXX)
+    $module->version = 2008050104; // The current module version (Date: YYYYMMDDXX)
     $module->requires = 2007101503;  // Requires this Moodle version
     $feedback_version_intern = 1; //this version is used for restore older backups
     $module->cron = 0; // Period for cron to check this module (secs)