files MDL-20601 Conversion of many of the uses of print_textarea, and the mforms...
authorSam Hemelryk <sam@moodle.com>
Wed, 4 Nov 2009 06:14:06 +0000 (06:14 +0000)
committerSam Hemelryk <sam@moodle.com>
Wed, 4 Nov 2009 06:14:06 +0000 (06:14 +0000)
Please forgive me if I have missed converting any output statements. If you do find an output statement that is not formatting correctly please refere to the table I added to this bug in regards to how it should be formatted.

58 files changed:
admin/report/spamcleaner/index.php
admin/uploaduser.php
admin/uploaduser_form.php
blocks/course_summary/block_course_summary.php
calendar/lib.php
course/category.php
course/edit.php
course/edit_form.php
course/editcategory.php
course/editcategory_form.php
course/format/topics/format.php
course/info.php
course/lib.php
course/pending.php
course/request.php
course/request_form.php
course/scales.php
course/search.php
grade/edit/outcome/edit.php
grade/edit/outcome/edit_form.php
grade/edit/outcome/export.php
grade/edit/scale/edit.php
grade/edit/scale/edit_form.php
grade/edit/tree/grade.php
grade/edit/tree/grade_form.php
group/group.php
group/group_form.php
group/grouping.php
group/grouping_form.php
group/lib.php
group/overview.php
lib/db/install.xml
lib/db/upgrade.php
lib/grade/grade_outcome.php
lib/grade/grade_scale.php
message/output/email/message_output_email.php
message/send.php
message/send_form.php [new file with mode: 0644]
pluginfile.php
tag/coursetags_more.php
tag/edit.php
tag/edit_form.php
tag/lib.php
tag/locallib.php
user/edit.php
user/edit_form.php
user/editadvanced.php
user/editadvanced_form.php
user/editlib.php
user/index.php
user/profile/definelib.php
user/profile/field/textarea/define.class.php
user/profile/field/textarea/field.class.php
user/profile/index.php
user/profile/index_field_form.php
user/profile/lib.php
user/view.php
version.php

index 724bfe3..478a56d 100755 (executable)
@@ -265,7 +265,11 @@ function print_user_entry($user, $keywords, $count) {
             $user->description = highlight($keyword, $user->description);
         }
 
-        $html .= '<td align="left">'.format_text($user->description, FORMAT_MOODLE).'</td>';
+        if (!isset($user->descriptionformat)) {
+            $user->descriptionformat = FORMAT_MOODLE;
+        }
+
+        $html .= '<td align="left">'.format_text($user->description, $user->descriptionformat).'</td>';
         $html .= '<td width="100px" align="center">';
         $html .= '<button onclick="del_user(this,'.$user->id.')">'.get_string('deleteuser', 'admin').'</button><br />';
         $html .= '<button onclick="ignore_user(this,'.$user->id.')">'.get_string('ignore', 'admin').'</button>';
index 944e1fd..1b4ad9a 100755 (executable)
@@ -72,7 +72,7 @@ $STD_FIELDS = array('id', 'firstname', 'lastname', 'username', 'email',
         'maildisplay', 'maildigest', 'htmleditor', 'ajax', 'autosubscribe',
         'mnethostid', 'institution', 'department', 'idnumber', 'skype',
         'msn', 'aim', 'yahoo', 'icq', 'phone1', 'phone2', 'address',
-        'url', 'description', 'oldusername', 'emailstop', 'deleted',
+        'url', 'description', 'descriptionformat', 'oldusername', 'emailstop', 'deleted',
         'password');
 
 $PRF_FIELDS = array();
index ecb2d97..19da955 100644 (file)
@@ -212,8 +212,9 @@ class admin_uploaduser_form2 extends moodleform {
         $mform->setDefault('lang', $templateuser->lang);
         $mform->setAdvanced('lang');
 
-        $mform->addElement('htmleditor', 'description', get_string('userdescription'));
-        $mform->setType('description', PARAM_CLEAN);
+        $editoroptions = array('maxfiles'=>0, 'maxbytes'=>0, 'trusttext'=>false, 'forcehttps'=>false);
+        $mform->addElement('editor', 'description', get_string('userdescription'), null, $editoroptions);
+        $mform->setType('description', PARAM_CLEANHTML);
         $mform->setHelpButton('description', array('text2', get_string('helptext')));
         $mform->setAdvanced('description');
 
@@ -334,5 +335,21 @@ class admin_uploaduser_form2 extends moodleform {
 
         return $errors;
     }
+
+    /**
+     * Used to reformat the data from the editor component
+     *
+     * @return stdClass
+     */
+    function get_data() {
+        $data = parent::get_data();
+
+        if ($data !== null) {
+            $data->descriptionformat = $data->description['format'];
+            $data->description = $data->description['text'];
+        }
+
+        return $data;
+    }
 }
 
index e999142..5605632 100644 (file)
@@ -26,7 +26,9 @@ class block_course_summary extends block_base {
         $this->content = new object();
         $options = new object();
         $options->noclean = true;    // Don't clean Javascripts etc
-        $this->content->text = format_text($this->page->course->summary, FORMAT_HTML, $options);
+        $context = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
+        $this->page->course->summary = file_rewrite_pluginfile_urls($this->page->course->summary, 'pluginfile.php', $context->id, 'course_summary', $this->page->course->id);
+        $this->content->text = format_text($this->page->course->summary, $this->page->course->summaryformat, $options);
         if ($this->page->user_is_editing()) {
             if($this->page->course->id == SITEID) {
                 $editpage = $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=frontpagesettings';
index 281b019..1102ada 100644 (file)
@@ -537,6 +537,9 @@ function calendar_print_event($event, $showactions=true) {
     static $strftimetime;
 
     $event = calendar_add_event_metadata($event);
+    if (!($event instanceof calendar_event)) {
+        $event = new calendar_event($event);
+    }
     echo '<a name="event_'.$event->id.'"></a><table class="event" cellspacing="0">';
     echo '<tr><td class="picture">';
     if (!empty($event->icon)) {
@@ -571,7 +574,8 @@ function calendar_print_event($event, $showactions=true) {
     } else {
         echo '<td class="description">'; 
     }
-    echo format_text($event->description, FORMAT_HTML);
+    
+    echo $event->description;
     if (calendar_edit_event_allowed($event) && $showactions) {
         echo '<div class="commands">';
         $calendarcourseid = '';
index b34e987..50034cd 100644 (file)
 /// Print current category description
     if (!$editingon && $category->description) {
         echo $OUTPUT->box_start();
-        echo format_text($category->description); // for multilang filter
+        $options = new stdClass;
+        $options->noclean = true;
+        $options->para = false;
+        if (!isset($category->descriptionformat)) {
+            $category->descriptionformat = FORMAT_MOODLE;
+        }
+        echo format_text($category->description, $category->descriptionformat, $options);
         echo $OUTPUT->box_end();
     }
 
index 70c1ef9..ffe4696 100644 (file)
@@ -1,4 +1,4 @@
-<?php // $Id$
+<?php
       // Edit course settings
 
     require_once('../config.php');
@@ -24,8 +24,8 @@
         }
         require_login($course->id);
         $category = $DB->get_record('course_categories', array('id'=>$course->category));
-        require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
-
+        $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+        require_capability('moodle/course:update', $coursecontext);
     } else if ($categoryid) { // creating new course in this category
         $course = null;
         require_login();
@@ -45,7 +45,8 @@
         $PAGE->url->param('category',$categoryid);
     }
 
-/// prepare course
+    /// Prepare course and the editor
+    $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
     if (!empty($course)) {
         $allowedmods = array();
         if (!empty($course)) {
             }
             $course->allowedmods = $allowedmods;
         }
+        $course = file_prepare_standard_editor($course, 'summary', $editoroptions, $coursecontext, 'course_summary', $course->id);
+    } else {
+        $course = file_prepare_standard_editor($course, 'summary', $editoroptions, null, 'course_summary', null);
     }
 
 /// first create the form
-    $editform = new course_edit_form('edit.php', compact('course', 'category'));
+    $editform = new course_edit_form('edit.php', compact('course', 'category', 'editoroptions'));
     // now override defaults if course already exists
-    if (!empty($course)) {
+    if (!empty($course->id)) {
         $course->enrolpassword = $course->password; // we need some other name for password field MDL-9929
         $editform->set_data($course);
     }
         //preprocess data
         $data->timemodified = time();
 
-        if (empty($course)) {
+        if (empty($course->id)) {
+            // In creating the course
             if (!$course = create_course($data)) {
                 print_error('coursenotcreated');
             }
 
+            // Get the context of the newly created course
             $context = get_context_instance(CONTEXT_COURSE, $course->id);
 
+            // Save the files used in the summary editor
+            $editordata = new stdClass;
+            $editordata->id = $course->id;
+            $editordata->summary_editor = $data->summary_editor;
+            $editordata = file_postupdate_standard_editor($editordata, 'summary', $editoroptions, $context, 'course_summary', $course->id);
+            $DB->update_record('course', $editordata);
+
             // assign default role to creator if not already having permission to manage course assignments
             if (!has_capability('moodle/course:view', $context) or !has_capability('moodle/role:assign', $context)) {
                 role_assign($CFG->creatornewroleid, $USER->id, 0, $context->id);
             }
 
         } else {
+            // Save any changes to the files used in the editor
+            $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $coursecontext, 'course_summary', $data->id);
             if (!update_course($data)) {
                 print_error('coursenotupdated');
             }
     $stradministration = get_string("administration");
     $strcategories = get_string("categories");
 
-    if (!empty($course)) {
+    if (!empty($course->id)) {
         $PAGE->navbar->add($streditcoursesettings);
         $title = $streditcoursesettings;
         $fullname = $course->fullname;
 
     echo $OUTPUT->footer();
 
-?>
+?>
\ No newline at end of file
index fc4a3ab..8591781 100644 (file)
@@ -1,4 +1,4 @@
-<?php  //$Id$
+<?php
 
 require_once($CFG->libdir.'/formslib.php');
 
@@ -12,13 +12,13 @@ class course_edit_form extends moodleform {
 
         $course   = $this->_customdata['course'];
         $category = $this->_customdata['category'];
+        $editoroptions = $this->_customdata['editoroptions'];
 
         $systemcontext = get_context_instance(CONTEXT_SYSTEM);
         $categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
 
         $disable_meta = false; // basic meta course state protection; server-side security checks not needed
-
-        if (!empty($course)) {
+        if (!empty($course->id)) {
             $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
             $context = $coursecontext;
 
@@ -52,7 +52,7 @@ class course_edit_form extends moodleform {
             $coursecontext = null;
             $context = $categorycontext;
         }
-
+        
 /// form definition with new course defaults
 //--------------------------------------------------------------------------------
         $mform->addElement('header','general', get_string('general', 'form'));
@@ -71,7 +71,7 @@ class course_edit_form extends moodleform {
         $mform->setDefault('category', $category->id);
         $mform->setType('category', PARAM_INT);
 
-        if ($course and !has_capability('moodle/course:changecategory', $coursecontext)) {
+        if (!empty($course->id) and !has_capability('moodle/course:changecategory', $coursecontext)) {
             $mform->hardFreeze('category');
             $mform->setConstant('category', $category->id);
         }
@@ -88,7 +88,7 @@ class course_edit_form extends moodleform {
         $mform->setHelpButton('fullname', array('coursefullname', get_string('fullnamecourse')), true);
         $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
         $mform->setType('fullname', PARAM_MULTILANG);
-        if ($course and !has_capability('moodle/course:changefullname', $coursecontext)) {
+        if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) {
             $mform->hardFreeze('fullname');
             $mform->setConstant('fullname', $course->fullname);
         }
@@ -99,7 +99,7 @@ class course_edit_form extends moodleform {
         $mform->setHelpButton('shortname', array('courseshortname', get_string('shortnamecourse')), true);
         $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
         $mform->setType('shortname', PARAM_MULTILANG);
-        if ($course and !has_capability('moodle/course:changeshortname', $coursecontext)) {
+        if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) {
             $mform->hardFreeze('shortname');
             $mform->setConstant('shortname', $course->shortname);
         }
@@ -109,17 +109,18 @@ class course_edit_form extends moodleform {
         $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100"  size="10"');
         $mform->setHelpButton('idnumber', array('courseidnumber', get_string('idnumbercourse')), true);
         $mform->setType('idnumber', PARAM_RAW);
-        if ($course and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
+        if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
             $mform->hardFreeze('idnumber');
             $mform->setConstants('idnumber', $course->idnumber);
         }
 
-        $mform->addElement('htmleditor','summary', get_string('summary'), array('rows'=> '10', 'cols'=>'65'));
-        $mform->setHelpButton('summary', array('text2', get_string('helptext')), true);
-        $mform->setType('summary', PARAM_RAW);
+        
+        $mform->addElement('editor','summary_editor', get_string('summary'), null, $editoroptions);
+        $mform->setHelpButton('summary_editor', array('text2', get_string('helptext')), true);
+        $mform->setType('summary_editor', PARAM_RAW);
 
-        if ($course and !has_capability('moodle/course:changesummary', $coursecontext)) {
-            $mform->hardFreeze('summary');
+        if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) {
+            $mform->hardFreeze('summary_editor');
         }
 
         $courseformats = get_plugin_list('format');
@@ -211,7 +212,7 @@ class course_edit_form extends moodleform {
 
 
         $roles = get_assignable_roles($context);
-        if (!empty($course)) {
+        if (!empty($course->id)) {
             // add current default role, so that it is selectable even when user can not assign it
             if ($current_role = $DB->get_record('role', array('id'=>$course->defaultrole))) {
                 $roles[$current_role->id] = strip_tags(format_string($current_role->name, true));
@@ -311,7 +312,7 @@ class course_edit_form extends moodleform {
         $mform->addElement('select', 'visible', get_string('availability'), $choices);
         $mform->setHelpButton('visible', array('courseavailability', get_string('availability')), true);
         $mform->setDefault('visible', $courseconfig->visible);
-        if ($course and !has_capability('moodle/course:visibility', $coursecontext)) {
+        if (!empty($course->id) and !has_capability('moodle/course:visibility', $coursecontext)) {
             $mform->hardFreeze('visible');
             $mform->setConstant('visible', $course->visible);
         }
@@ -322,7 +323,7 @@ class course_edit_form extends moodleform {
         $mform->setDefault('enrolpassword', $courseconfig->enrolpassword);
         $mform->setType('enrolpassword', PARAM_RAW);
 
-        if (empty($course) or ($course->password !== '' and $course->id != SITEID)) {
+        if (empty($course->id) or ($course->password !== '' and $course->id != SITEID)) {
             // do not require password in existing courses that do not have password yet - backwards compatibility ;-)
             if (!empty($CFG->enrol_manual_requirekey)) {
                 $mform->addRule('enrolpassword', get_string('required'), 'required', null, 'client');
@@ -339,7 +340,7 @@ class course_edit_form extends moodleform {
 
         // If we are creating a course, its enrol method isn't yet chosen, BUT the site has a default enrol method which we can use here
         $enrol_object = $CFG;
-        if (!empty($course)) {
+        if (!empty($course->id)) {
             $enrol_object = $course;
         }
         // If the print_entry method exists and the course enrol method isn't manual (both set or inherited from site), show cost
index cf2a48e..522cc28 100644 (file)
@@ -1,4 +1,4 @@
-<?php // $Id$
+<?php
 /**
  * Page for creating or editing course category name/parent/description.
  * When called with an id parameter, edits the category with that id.
@@ -18,8 +18,10 @@ if ($id) {
         print_error('unknowcategory');
     }
     $PAGE->set_url('course/editcategory.php', array('id' => $id));
-    require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $id));
+    $categorycontext = get_context_instance(CONTEXT_COURSECAT, $id);
+    require_capability('moodle/category:manage', $categorycontext);
     $strtitle = get_string('editcategorysettings');
+    $editorcontext = $categorycontext;
 } else {
     $parent = required_param('parent', PARAM_INT);
     $PAGE->set_url('course/editcategory.php', array('parent' => $parent));
@@ -36,9 +38,13 @@ if ($id) {
     $category->parent = $parent;
     require_capability('moodle/category:manage', $context);
     $strtitle = get_string("addnewcategory");
+    $editorcontext = null;
 }
 
-$mform = new editcategory_form('editcategory.php', $category);
+$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true);
+$category = file_prepare_standard_editor($category, 'description', $editoroptions, $editorcontext, 'category_description', $category->id);
+
+$mform = new editcategory_form('editcategory.php', compact('category', 'editoroptions'));
 $mform->set_data($category);
 
 if ($mform->is_cancelled()) {
@@ -52,7 +58,7 @@ if ($mform->is_cancelled()) {
 } else if ($data = $mform->get_data()) {
     $newcategory = new stdClass();
     $newcategory->name = $data->name;
-    $newcategory->description = $data->description;
+    $newcategory->description_editor = $data->description_editor;
     $newcategory->parent = $data->parent; // if $data->parent = 0, the new category will be a top-level category
 
     if (isset($data->theme) && !empty($CFG->allowcategorythemes)) {
@@ -66,17 +72,20 @@ if ($mform->is_cancelled()) {
             $parent_cat = $DB->get_record('course_categories', array('id' => $newcategory->parent));
             move_category($newcategory, $parent_cat);
         }
-        $DB->update_record('course_categories', $newcategory);
-        fix_course_sortorder();
-
     } else {
         // Create a new category.
+        $newcategory->description = $data->description_editor['text'];
         $newcategory->sortorder = 999;
         $newcategory->id = $DB->insert_record('course_categories', $newcategory);
         $newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
+        $categorycontext = $newcategory->context;
         mark_context_dirty($newcategory->context->path);
-        fix_course_sortorder(); // Required to build course_categories.depth and .path.
     }
+
+    $newcategory = file_postupdate_standard_editor($newcategory, 'description', $editoroptions, $categorycontext, 'category_description', $newcategory->id);
+    $DB->update_record('course_categories', $newcategory);
+    fix_course_sortorder();
+
     redirect('category.php?id='.$newcategory->id.'&categoryedit=on');
 }
 
index 2973e92..8da5a95 100644 (file)
@@ -6,7 +6,8 @@ class editcategory_form extends moodleform {
     function definition() {
         global $CFG;
         $mform =& $this->_form;
-        $category = $this->_customdata;
+        $category = $this->_customdata['category'];
+        $editoroptions = $this->_customdata['editoroptions'];
 
         // get list of categories to use as parents, with site as the first one
         $options = array(get_string('top'));
@@ -24,15 +25,15 @@ class editcategory_form extends moodleform {
         $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
         $mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
         $mform->addRule('name', get_string('required'), 'required', null);
-        $mform->addElement('htmleditor', 'description', get_string('description'));
-        $mform->setType('description', PARAM_RAW);
+        $mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions);
+        $mform->setType('description_editor', PARAM_RAW);
         if (!empty($CFG->allowcategorythemes)) {
             $themes=array();
             $themes[''] = get_string('forceno');
             $themes += get_list_of_themes();
             $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
         }
-        $mform->setHelpButton('description', array('writing', 'richtext2'), false, 'editorhelpbutton');
+        $mform->setHelpButton('description_editor', array('writing', 'richtext2'), false, 'editorhelpbutton');
 
         $mform->addElement('hidden', 'id', 0);
         $mform->setType('id', PARAM_INT);
index 09f59b9..a3b20eb 100644 (file)
@@ -1,6 +1,7 @@
-<?php // $Id$
-      // Display the whole course as "topics" made of of modules
-      // Included from "view.php"
+<?php
+
+// Display the whole course as "topics" made of of modules
+// Included from "view.php"
 /**
  * Evaluation topics format for course display - NO layout tables, for accessibility, etc.
  * 
  */
 //TODO (nfreear): Accessibility: evaluation, lang/en_utf8/moodle.php: $string['formattopicscss']
 
-    require_once($CFG->libdir.'/ajax/ajaxlib.php');
-    require_once($CFG->libdir.'/filelib.php');
+require_once($CFG->libdir.'/ajax/ajaxlib.php');
+require_once($CFG->libdir.'/filelib.php');
 
-    $topic = optional_param('topic', -1, PARAM_INT);
+$topic = optional_param('topic', -1, PARAM_INT);
 
-    if ($topic != -1) {
-        $displaysection = course_set_display($course->id, $topic);
+if ($topic != -1) {
+    $displaysection = course_set_display($course->id, $topic);
+} else {
+    if (isset($USER->display[$course->id])) {
+        $displaysection = $USER->display[$course->id];
     } else {
-        if (isset($USER->display[$course->id])) {
-            $displaysection = $USER->display[$course->id];
-        } else {
-            $displaysection = course_set_display($course->id, 0);
-        }
+        $displaysection = course_set_display($course->id, 0);
     }
+}
 
-    $context = get_context_instance(CONTEXT_COURSE, $course->id);
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
 
-    if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
-       $course->marker = $marker;
-       if (! $DB->set_field("course", "marker", $marker, array("id"=>$course->id))) {
-           print_error("cannotmarktopic");
-       }
+if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
+    $course->marker = $marker;
+    if (! $DB->set_field("course", "marker", $marker, array("id"=>$course->id))) {
+        print_error("cannotmarktopic");
     }
+}
+
+$streditsummary  = get_string('editsummary');
+$stradd          = get_string('add');
+$stractivities   = get_string('activities');
+$strshowalltopics = get_string('showalltopics');
+$strtopic         = get_string('topic');
+$strgroups       = get_string('groups');
+$strgroupmy      = get_string('groupmy');
+$editing         = $PAGE->user_is_editing();
+
+if ($editing) {
+    $strtopichide = get_string('hidetopicfromothers');
+    $strtopicshow = get_string('showtopicfromothers');
+    $strmarkthistopic = get_string('markthistopic');
+    $strmarkedthistopic = get_string('markedthistopic');
+    $strmoveup   = get_string('moveup');
+    $strmovedown = get_string('movedown');
+}
+
+// Print the Your progress icon if the track completion is enabled
+$completioninfo = new completion_info($course);
+$completioninfo->print_help_icon();
+
+echo $OUTPUT->heading(get_string('topicoutline'), 2, 'headingblock header outline');
+
+// Note, an ordered list would confuse - "1" could be the clipboard or summary.
+echo "<ul class='topics'>\n";
 
-    $streditsummary  = get_string('editsummary');
-    $stradd          = get_string('add');
-    $stractivities   = get_string('activities');
-    $strshowalltopics = get_string('showalltopics');
-    $strtopic         = get_string('topic');
-    $strgroups       = get_string('groups');
-    $strgroupmy      = get_string('groupmy');
-    $editing         = $PAGE->user_is_editing();
-
-    if ($editing) {
-        $strtopichide = get_string('hidetopicfromothers');
-        $strtopicshow = get_string('showtopicfromothers');
-        $strmarkthistopic = get_string('markthistopic');
-        $strmarkedthistopic = get_string('markedthistopic');
-        $strmoveup   = get_string('moveup');
-        $strmovedown = get_string('movedown');
-    }
+/// If currently moving a file then show the current clipboard
+if (ismoving($course->id)) {
+    $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
+    $strcancel= get_string('cancel');
+    echo '<li class="clipboard">';
+    echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
+    echo "</li>\n";
+}
 
-    // Print the Your progress icon if the track completion is enabled
-    $completioninfo = new completion_info($course);
-    $completioninfo->print_help_icon();
+/// Print Section 0 with general activities
 
-    echo $OUTPUT->heading(get_string('topicoutline'), 2, 'headingblock header outline');
+$section = 0;
+$thissection = $sections[$section];
+
+if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
+
+    // Note, no need for a 'left side' cell or DIV.
+    // Note, 'right side' is BEFORE content.
+    echo '<li id="section-0" class="section main" >';
+    echo '<div class="left side">&nbsp;</div>';
+    echo '<div class="right side" >&nbsp;</div>';
+    echo '<div class="content">';
+    echo '<div class="summary">';
+
+    $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+    $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
+    $summaryformatoptions = new object();
+    $summaryformatoptions->noclean = true;
+    echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
+
+    if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext)) {
+        echo '<a title="'.$streditsummary.'" '.
+             ' href="editsection.php?id='.$thissection->id.'"><img src="'.$OUTPUT->old_icon_url('t/edit') . '" '.
+             ' class="icon edit" alt="'.$streditsummary.'" /></a>';
+    }
+    echo '</div>';
 
-    // Note, an ordered list would confuse - "1" could be the clipboard or summary.
-    echo "<ul class='topics'>\n";
+    print_section($course, $thissection, $mods, $modnamesused);
 
-/// If currently moving a file then show the current clipboard
-    if (ismoving($course->id)) {
-        $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
-        $strcancel= get_string('cancel');
-        echo '<li class="clipboard">';
-        echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
-        echo "</li>\n";
+    if ($PAGE->user_is_editing()) {
+        print_section_add_menus($course, $section, $modnames);
     }
 
-/// Print Section 0 with general activities
+    echo '</div>';
+    echo "</li>\n";
+}
 
-    $section = 0;
-    $thissection = $sections[$section];
 
-    if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
+/// Now all the normal modules by topic
+/// Everything below uses "section" terminology - each "section" is a topic.
 
-        // Note, no need for a 'left side' cell or DIV.
-        // Note, 'right side' is BEFORE content.
-        echo '<li id="section-0" class="section main" >';
-       echo '<div class="left side">&nbsp;</div>';
-        echo '<div class="right side" >&nbsp;</div>';
-        echo '<div class="content">';
-        echo '<div class="summary">';
-
-        $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
-        $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
-        $summaryformatoptions = new object();
-        $summaryformatoptions->noclean = true;
-        echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
-
-        if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext)) {
-            echo '<a title="'.$streditsummary.'" '.
-                 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$OUTPUT->old_icon_url('t/edit') . '" '.
-                 ' class="icon edit" alt="'.$streditsummary.'" /></a>';
-        }
-        echo '</div>';
-        
-        print_section($course, $thissection, $mods, $modnamesused);
+$timenow = time();
+$section = 1;
+$sectionmenu = array();
 
-        if ($PAGE->user_is_editing()) {
-            print_section_add_menus($course, $section, $modnames);
-        }
+while ($section <= $course->numsections) {
 
-        echo '</div>';
-        echo "</li>\n";
-    }
+    if (!empty($sections[$section])) {
+        $thissection = $sections[$section];
 
+    } else {
+        unset($thissection);
+        $thissection->course  = $course->id;   // Create a new section structure
+        $thissection->section = $section;
+        $thissection->summary  = '';
+        $thissection->visible  = 1;
+        $thissection->id = $DB->insert_record('course_sections', $thissection);
+    }
 
-/// Now all the normal modules by topic
-/// Everything below uses "section" terminology - each "section" is a topic.
+    $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
 
-    $timenow = time();
-    $section = 1;
-    $sectionmenu = array();
+    if (!empty($displaysection) and $displaysection != $section) {  // Check this topic is visible
+        if ($showsection) {
+            $strsummary = strip_tags(format_string($thissection->summary,true));
+            if (strlen($strsummary) < 57) {
+                $strsummary = ' - '.$strsummary;
+            } else {
+                $strsummary = ' - '.substr($strsummary, 0, 60).'...';
+            }
+            $sectionmenu[$section] = s($section.$strsummary);
+        }
+        $section++;
+        continue;
+    }
 
-    while ($section <= $course->numsections) {
+    if ($showsection) {
 
-        if (!empty($sections[$section])) {
-            $thissection = $sections[$section];
+        $currenttopic = ($course->marker == $section);
 
+        $currenttext = '';
+        if (!$thissection->visible) {
+            $sectionstyle = ' hidden';
+        } else if ($currenttopic) {
+            $sectionstyle = ' current';
+            $currenttext = get_accesshide(get_string('currenttopic','access'));
         } else {
-            unset($thissection);
-            $thissection->course  = $course->id;   // Create a new section structure
-            $thissection->section = $section;
-            $thissection->summary  = '';
-            $thissection->visible  = 1;
-            $thissection->id = $DB->insert_record('course_sections', $thissection);
+            $sectionstyle = '';
         }
 
-        $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
-
-        if (!empty($displaysection) and $displaysection != $section) {  // Check this topic is visible
-            if ($showsection) {
-               $strsummary = strip_tags(format_string($thissection->summary,true));
-               if (strlen($strsummary) < 57) {
-                   $strsummary = ' - '.$strsummary;
-               } else {
-                   $strsummary = ' - '.substr($strsummary, 0, 60).'...';
-               }
-                $sectionmenu[$section] = s($section.$strsummary);
-            }
-            $section++;
-            continue;
+        echo '<li id="section-'.$section.'" class="section main'.$sectionstyle.'" >'; //'<div class="left side">&nbsp;</div>';
+
+            echo '<div class="left side">'.$currenttext.$section.'</div>';
+        // Note, 'right side' is BEFORE content.
+        echo '<div class="right side">';
+
+        if ($displaysection == $section) {     // Show the zoom boxes
+            echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
+                 '<img src="'.$OUTPUT->old_icon_url('i/all') . '" class="icon" alt="'.$strshowalltopics.'" /></a><br />';
+        } else {
+            $strshowonlytopic = get_string("showonlytopic", "", $section);
+            echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
+                 '<img src="'.$OUTPUT->old_icon_url('i/one') . '" class="icon" alt="'.$strshowonlytopic.'" /></a><br />';
         }
 
-        if ($showsection) {
+        if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
 
-            $currenttopic = ($course->marker == $section);
+            if ($course->marker == $section) {  // Show the "light globe" on/off
+                echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.'<img src="'.$OUTPUT->old_icon_url('i/marked') . '" alt="'.$strmarkedthistopic.'" /></a><br />';
+            } else {
+                echo '<a href="view.php?id='.$course->id.'&amp;marker='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkthistopic.'">'.'<img src="'.$OUTPUT->old_icon_url('i/marker') . '" alt="'.$strmarkthistopic.'" /></a><br />';
+            }
 
-            $currenttext = '';
-            if (!$thissection->visible) {
-                $sectionstyle = ' hidden';
-            } else if ($currenttopic) {
-                $sectionstyle = ' current';
-                $currenttext = get_accesshide(get_string('currenttopic','access'));
+            if ($thissection->visible) {        // Show the hide/show eye
+                echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopichide.'">'.
+                     '<img src="'.$OUTPUT->old_icon_url('i/hide') . '" class="icon hide" alt="'.$strtopichide.'" /></a><br />';
             } else {
-                $sectionstyle = '';
+                echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopicshow.'">'.
+                     '<img src="'.$OUTPUT->old_icon_url('i/show') . '" class="icon hide" alt="'.$strtopicshow.'" /></a><br />';
+            }
+            if ($section > 1) {                       // Add a arrow to move section up
+                echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'">'.
+                     '<img src="'.$OUTPUT->old_icon_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
             }
 
-            echo '<li id="section-'.$section.'" class="section main'.$sectionstyle.'" >'; //'<div class="left side">&nbsp;</div>';
+            if ($section < $course->numsections) {    // Add a arrow to move section down
+                echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'">'.
+                     '<img src="'.$OUTPUT->old_icon_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
+            }
+        }
+        echo '</div>';
 
-               echo '<div class="left side">'.$currenttext.$section.'</div>';
-            // Note, 'right side' is BEFORE content.
-            echo '<div class="right side">';
-            
-            if ($displaysection == $section) { // Show the zoom boxes
-                echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
-                     '<img src="'.$OUTPUT->old_icon_url('i/all') . '" class="icon" alt="'.$strshowalltopics.'" /></a><br />';
+        echo '<div class="content">';
+        if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {   // Hidden for students
+            echo get_string('notavailable').'</div>';
+        } else {
+            echo '<div class="summary">';
+            $summaryformatoptions->noclean = true;
+            if ($thissection->summary) {
+               echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
             } else {
-                $strshowonlytopic = get_string("showonlytopic", "", $section);
-                echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
-                     '<img src="'.$OUTPUT->old_icon_url('i/one') . '" class="icon" alt="'.$strshowonlytopic.'" /></a><br />';
+               echo '&nbsp;';
             }
 
             if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
-
-               if ($course->marker == $section) {  // Show the "light globe" on/off
-                           echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.'<img src="'.$OUTPUT->old_icon_url('i/marked') . '" alt="'.$strmarkedthistopic.'" /></a><br />';
-               } else {
-                    echo '<a href="view.php?id='.$course->id.'&amp;marker='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkthistopic.'">'.'<img src="'.$OUTPUT->old_icon_url('i/marker') . '" alt="'.$strmarkthistopic.'" /></a><br />';
-               }
-                
-                if ($thissection->visible) {        // Show the hide/show eye
-                    echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopichide.'">'.
-                         '<img src="'.$OUTPUT->old_icon_url('i/hide') . '" class="icon hide" alt="'.$strtopichide.'" /></a><br />';                                        
-                } else {
-                    echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopicshow.'">'.
-                         '<img src="'.$OUTPUT->old_icon_url('i/show') . '" class="icon hide" alt="'.$strtopicshow.'" /></a><br />';
-                }                   
-                if ($section > 1) {                       // Add a arrow to move section up
-                    echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'">'.
-                         '<img src="'.$OUTPUT->old_icon_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
-                }
-
-                if ($section < $course->numsections) {    // Add a arrow to move section down
-                    echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'">'.
-                         '<img src="'.$OUTPUT->old_icon_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
-                }
+                echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
+                     '<img src="'.$OUTPUT->old_icon_url('t/edit') . '" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
             }
             echo '</div>';
 
-            echo '<div class="content">';
-            if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {   // Hidden for students
-               echo get_string('notavailable').'</div>';
-           } else {
-                echo '<div class="summary">';
-                $summaryformatoptions->noclean = true;
-               if ($thissection->summary) {
-                   echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
-               } else {
-                  echo '&nbsp;';
-               }
-
-                if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
-                    echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
-                         '<img src="'.$OUTPUT->old_icon_url('t/edit') . '" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
-                }
-                echo '</div>';
-
-                print_section($course, $thissection, $mods, $modnamesused);
-                echo '<br />';
-                if ($PAGE->user_is_editing()) {
-                    print_section_add_menus($course, $section, $modnames);
-                }
+            print_section($course, $thissection, $mods, $modnamesused);
+            echo '<br />';
+            if ($PAGE->user_is_editing()) {
+                print_section_add_menus($course, $section, $modnames);
             }
-
-            echo '</div>';
-            echo "</li>\n";
         }
 
-        $section++;
-    }
-    echo "</ul>\n";
-
-    if (!empty($sectionmenu)) {
-        echo '<div class="jumpmenu">';
-        $popupurl = $CFG->wwwroot.'/course/view.php?id='.$course->id;
-        $select = html_select::make_popup_form($popupurl, 'topic', $sectionmenu, 'sectionmenu');
-        $select->set_label(get_string('jumpto'));
-        echo $OUTPUT->select($select);
         echo '</div>';
+        echo "</li>\n";
     }
+
+    $section++;
+}
+echo "</ul>\n";
+
+if (!empty($sectionmenu)) {
+    echo '<div class="jumpmenu">';
+    $popupurl = $CFG->wwwroot.'/course/view.php?id='.$course->id;
+    $select = html_select::make_popup_form($popupurl, 'topic', $sectionmenu, 'sectionmenu');
+    $select->set_label(get_string('jumpto'));
+    echo $OUTPUT->select($select);
+    echo '</div>';
+}
index 51fe034..2570956 100644 (file)
@@ -59,7 +59,8 @@
 
     echo $OUTPUT->box_start('generalbox info');
 
-    echo format_text($course->summary, FORMAT_MOODLE, NULL, $course->id);
+    $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course_summary', $course->id);
+    echo format_text($course->summary, $course->summaryformat, NULL, $course->id);
 
     if ($managerroles = get_config('', 'coursemanager')) {
         $coursemanagerroles = split(',', $managerroles);
index 3e2beca..44eaf7f 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 require_once($CFG->libdir.'/completionlib.php');
+require_once($CFG->libdir.'/filelib.php');
 
 define('COURSE_MAX_LOG_DISPLAY', 150);          // days
 define('COURSE_MAX_LOGS_PER_PAGE', 1000);       // records
@@ -2122,17 +2123,17 @@ function print_courses($category) {
             $category   = array_shift($categories);
             $courses    = get_courses_wmanagers($category->id,
                                                 'c.sortorder ASC',
-                                                array('password','summary','currency'));
+                                                array('password','summary','summaryformat','currency'));
         } else {
             $courses    = get_courses_wmanagers('all',
                                                 'c.sortorder ASC',
-                                                array('password','summary','currency'));
+                                                array('password','summary','summaryformat','currency'));
         }
         unset($categories);
     } else {
         $courses    = get_courses_wmanagers($category->id,
                                             'c.sortorder ASC',
-                                            array('password','summary','currency'));
+                                            array('password','summary','summaryformat','currency'));
     }
 
     if ($courses) {
@@ -2174,6 +2175,9 @@ function print_course($course, $highlightterms = '') {
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
     }
 
+    // Rewrite file URLs so that they are correct
+    $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course_summary', $course->id);
+
     $linkcss = $course->visible ? '' : ' class="dimmed" ';
 
     echo '<div class="coursebox clearfix">';
@@ -2267,7 +2271,10 @@ function print_course($course, $highlightterms = '') {
     $options = NULL;
     $options->noclean = true;
     $options->para = false;
-    echo highlight($highlightterms, format_text($course->summary, FORMAT_MOODLE, $options,  $course->id));
+    if (!isset($course->summaryformat)) {
+        $course->summaryformat = FORMAT_MOODLE;
+    }
+    echo highlight($highlightterms, format_text($course->summary, $course->summaryformat, $options,  $course->id));
     echo '</div>';
     echo '</div>';
 }
@@ -3590,3 +3597,405 @@ function get_course_by_idnumber ($idnumber) {
     global $DB;
     return $DB->get_record('course', array('idnumber' => $idnumber));
 }
+
+/**
+ * This class pertains to course requests and contains methods associated with
+ * create, approving, and removing course requests.
+ *
+ * @copyright 2009 Sam Hemelryk
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 2.0
+ *
+ * @property-read int $id
+ * @property-read string $fullname
+ * @property-read string $shortname
+ * @property-read string $summary
+ * @property-read int $summaryformat
+ * @property-read int $summarytrust
+ * @property-read string $reason
+ * @property-read int $requester
+ * @property-read string $password
+ */
+class course_request {
+
+    /**
+     * This is the stdClass that stores the properties for the course request
+     * and is externally acccessed through the __get magic method
+     * @var stdClass
+     */
+    protected $properties;
+
+    /**
+     * An array of options for the summary editor used by course request forms.
+     * This is initially set by {@link summary_editor_options()}
+     * @var array
+     * @static
+     */
+    protected static $summaryeditoroptions;
+
+    /**
+     * The context used when working with files for the summary editor
+     * This is initially set by {@link summary_editor_context()}
+     * @var stdClass
+     * @static
+     */
+    protected static $summaryeditorcontext;
+
+    /**
+     * The string used to identify the file area for course_requests
+     * This is initially set by {@link summary_editor_context()}
+     * @var string
+     * @static
+     */
+    protected static $summaryeditorfilearea = 'course_request_summary';
+
+    /**
+     * Static function to prepare the summary editor for working with a course
+     * request.
+     *
+     * @static
+     * @param null|stdClass $data Optional, an object containing the default values
+     *                       for the form, these may be modified when preparing the
+     *                       editor so this should be called before creating the form
+     * @return stdClass An object that can be used to set the default values for
+     *                   an mforms form
+     */
+    public static function prepare($data=null) {
+        if ($data === null) {
+            $data = new stdClass;
+        }
+        $data = file_prepare_standard_editor($data, 'summary', self::summary_editor_options(), self::summary_editor_context(), self::summary_editor_filearea(), null);
+        return $data;
+    }
+
+    /**
+     * Static function to create a new course request when passed an array of properties
+     * for it.
+     *
+     * This function also handles saving any files that may have been used in the editor
+     *
+     * @static
+     * @param stdClass $data
+     * @return course_request The newly created course request
+     */
+    public static function create($data) {
+        global $USER, $DB, $CFG;
+        $data->requester = $USER->id;
+        $editorused = (!empty($data->summary_editor));
+        // Has summary_editor been set. If so we have come through with a editor and
+        // may need to save files
+        if ($editorused && empty($data->summary)) {
+            // Summary is a required field so copy the text over
+            $data->summary = $data->summary_editor['text'];
+        }
+        $data->id = $DB->insert_record('course_request', $data);
+        if ($editorused) {
+            // Save any files and then update the course with the fixed data
+            $data = file_postupdate_standard_editor($data, 'summary', self::summary_editor_options(), self::summary_editor_context(), self::summary_editor_filearea(), $data->id);
+            $DB->update_record('course_request', $data);
+        }
+        // Create a new course_request object and return it
+        $request = new course_request($data);
+
+        // Notify the admin if required.
+        if ($CFG->courserequestnotify) {
+            $users = get_users_from_config($CFG->courserequestnotify, 'moodle/site:approvecourse');
+            
+            $a = new stdClass;
+            $a->link = "$CFG->wwwroot/course/pending.php";
+            $a->user = fullname($USER);
+            $subject = get_string('courserequest');
+            $message = get_string('courserequestnotifyemail', 'admin', $a);
+            foreach ($users as $user) {
+                $this->notify($user, $USER, 'courserequested', $subject, $message);
+            }
+        }
+
+        return $request;
+    }
+
+    /**
+     * Returns an array of options to use with a summary editor
+     *
+     * @uses course_request::$summaryeditoroptions
+     * @return array An array of options to use with the editor
+     */
+    public static function summary_editor_options() {
+        global $CFG;
+        if (self::$summaryeditoroptions === null) {
+            self::$summaryeditoroptions = array('maxfiles' => 0, 'maxbytes'=>0, 'trusttext'=>true);
+        }
+        return self::$summaryeditoroptions;
+    }
+
+    /**
+     * Returns the context to use with the summary editor
+     *
+     * @uses course_request::$summaryeditorcontext
+     * @return stdClass The context to use
+     */
+    public static function summary_editor_context() {
+        return null;
+    }
+
+    /**
+     * Returns the filearea to use with the summary editor
+     *
+     * @uses course_request::$summaryeditorfilearea
+     * @return string The filearea to use with the summary editor
+     */
+    public static function summary_editor_filearea() {
+        return self::$summaryeditorfilearea;
+    }
+
+    /**
+     * Loads the properties for this course request object. Id is required and if
+     * only id is provided then we load the rest of the properties from the database
+     *
+     * @param stdClass|int $properties Either an object containing properties
+     *                      or the course_request id to load
+     */
+    public function __construct($properties) {
+        global $DB;
+        if (empty($properties->id)) {
+            if (empty($properties)) {
+                throw new coding_exception('You must provide a course request id when creating a course_request object');
+            }
+            $id = $properties;
+            $properties = new stdClass;
+            $properties->id = (int)$id;
+            unset($id);
+        }
+        if (empty($properties->requester)) {
+            if (!($this->properties = $DB->get_record('course_request', array('id' => $properties->id)))) {
+                print_error('unknowncourserequest');
+            }
+        } else {
+            $this->properties = $properties;
+        }
+        $this->properties->collision = null;
+    }
+
+    /**
+     * Returns the requested property
+     *
+     * @param string $key
+     * @return mixed
+     */
+    public function __get($key) {
+        if ($key === 'summary' && self::summary_editor_context() !== null) {
+            return file_rewrite_pluginfile_urls($this->properties->summary, 'pluginfile.php', self::summary_editor_context()->id, self::summary_editor_filearea(), $this->properties->id);
+        }
+        return $this->properties->$key;
+    }
+
+    /**
+     * Override this to ensure empty($request->blah) calls return a reliable answer...
+     *
+     * This is required because we define the __get method
+     *
+     * @param mixed $key
+     * @return bool True is it not empty, false otherwise
+     */
+    public function __isset($key) {
+        return (!empty($this->properties->$key));
+    }
+
+    /**
+     * Returns the user who requested this course
+     *
+     * Uses a static var to cache the results and cut down the number of db queries
+     *
+     * @staticvar array $requesters An array of cached users
+     * @return stdClass The user who requested the course
+     */
+    public function get_requester() {
+        global $DB;
+        static $requesters= array();
+        if (!array_key_exists($this->properties->requester, $requesters)) {
+            $requesters[$this->properties->requester] = $DB->get_record('user', array('id'=>$this->properties->requester));
+        }
+        return $requesters[$this->properties->requester];
+    }
+
+    /**
+     * Checks that the shortname used by the course does not conflict with any other
+     * courses that exist
+     *
+     * @param string|null $shortnamemark The string to append to the requests shortname
+     *                     should a conflict be found
+     * @return bool true is there is a conflict, false otherwise
+     */
+    public function check_shortname_collision($shortnamemark = '[*]') {
+        global $DB;
+
+        if ($this->properties->collision !== null) {
+            return $this->properties->collision;
+        }
+
+        if (empty($this->properties->shortname)) {
+            debugging('Attempting to check a course request shortname before it has been set', DEBUG_DEVELOPER);
+            $this->properties->collision = false;
+        } else if ($DB->record_exists('course', array('shortname' => $this->properties->shortname))) {
+            if (!empty($shortnamemark)) {
+                $this->properties->shortname .= ' '.$shortnamemark;
+            }
+            $this->properties->collision = true;
+        } else {
+            $this->properties->collision = false;
+        }
+        return $this->properties->collision;
+    }
+
+    /**
+     * This function approves the request turning it into a course
+     *
+     * This function converts the course request into a course, at the same time
+     * transfering any files used in the summary to the new course and then removing
+     * the course request and the files associated with it.
+     *
+     * @return int The id of the course that was created from this request
+     */
+    public function approve() {
+        global $CFG, $DB, $USER;
+        $category = get_course_category($CFG->defaultrequestcategory);
+        $courseconfig = get_config('moodlecourse');
+
+        // Transfer appropriate settings
+        $course = clone($this->properties);
+        unset($course->id);
+        unset($course->reason);
+        unset($course->requester);
+
+        // Set category
+        $course->category = $category->id;
+        $course->sortorder = $category->sortorder; // place as the first in category
+
+        // Set misc settings
+        $course->requested = 1;
+        if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
+            $course->restrictmodules = 1;
+        }
+
+        // Apply course default settings
+        $course->format             = $courseconfig->format;
+        $course->numsections        = $courseconfig->numsections;
+        $course->hiddensections     = $courseconfig->hiddensections;
+        $course->newsitems          = $courseconfig->newsitems;
+        $course->showgrades         = $courseconfig->showgrades;
+        $course->showreports        = $courseconfig->showreports;
+        $course->maxbytes           = $courseconfig->maxbytes;
+        $course->enrol              = $courseconfig->enrol;
+        $course->enrollable         = $courseconfig->enrollable;
+        $course->enrolperiod        = $courseconfig->enrolperiod;
+        $course->expirynotify       = $courseconfig->expirynotify;
+        $course->notifystudents     = $courseconfig->notifystudents;
+        $course->expirythreshold    = $courseconfig->expirythreshold;
+        $course->groupmode          = $courseconfig->groupmode;
+        $course->groupmodeforce     = $courseconfig->groupmodeforce;
+        $course->visible            = $courseconfig->visible;
+        $course->enrolpassword      = $courseconfig->enrolpassword;
+        $course->guest              = $courseconfig->guest;
+        $course->lang               = $courseconfig->lang;
+
+        // Insert the record
+        $course->id = $DB->insert_record('course', $course);
+        if ($course->id) {
+            $course = $DB->get_record('course', array('id' => $course->id));
+            blocks_add_default_course_blocks($course);
+            $course->context = get_context_instance(CONTEXT_COURSE, $course->id);
+            role_assign($CFG->creatornewroleid, $this->properties->requester, 0, $course->context->id); // assing teacher role
+            if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
+                // if we're all or requested we're ok.
+                $allowedmods = explode(',',$CFG->defaultallowedmodules);
+                update_restricted_mods($course, $allowedmods);
+            }
+            $this->copy_summary_files_to_course($course);
+            $this->delete();
+            fix_course_sortorder();
+
+            $user = $DB->get_record('user', array('id' => $this->properties->requester));
+            $a->name = $course->fullname;
+            $a->url = $CFG->wwwroot.'/course/view.php?id=' . $course->id;
+            $this->notify($user, $USER, 'courserequestapproved', get_string('courseapprovedsubject'), get_string('courseapprovedemail2', 'moodle', $a));
+
+            return $course->id;
+        }
+        return false;
+    }
+
+    /**
+     * Reject a course request
+     *
+     * This function rejects a course request, emailing the requesting user the
+     * provided notice and then removing the request from the database
+     *
+     * @param string $notice The message to display to the user
+     */
+    public function reject($notice) {
+        global $USER;
+        $this->notify($user, $USER, 'courserequestrejected', get_string('courserejectsubject'), get_string('courserejectemail', 'moodle', $notice));
+        $this->delete();
+    }
+
+    /**
+     * Deletes the course request and any associated files
+     */
+    public function delete() {
+        global $DB;
+        $DB->delete_records('course_request', array('id' => $this->properties->id));
+        if (self::summary_editor_context() !== null) {
+            $fs = get_file_storage();
+            $files = $fs->get_area_files(self::summary_editor_context()->id, self::summary_editor_filearea(), $this->properties->id);
+            foreach ($files as $file) {
+                $file->delete();
+            }
+        }
+    }
+
+    /**
+     * This function copies all files used in the summary for the request to the
+     * summary of the course.
+     *
+     * This function copies, original files are left associated with the request
+     * and are removed only when the request is deleted
+     *
+     * @param stdClass $course An object representing the course to copy files to
+     */
+    protected function copy_summary_files_to_course($course) {
+        if (self::summary_editor_context() !== null) {
+            $fs = get_file_storage();
+            $files = $fs->get_area_files(self::summary_editor_context()->id, self::summary_editor_filearea(), $this->properties->id);
+            foreach ($files as $file) {
+                if (!$file->is_directory()) {
+                    $filerecord = array('contextid'=>$course->context->id, 'filearea'=>'course_summary', 'itemid'=>$course->id, 'filepath'=>$file->get_filepath(), 'filename'=>$file->get_filename());
+                    $fs->create_file_from_storedfile($filerecord, $file);
+                }
+            }
+        }
+    }
+
+    /**
+     * Send a message from one user to another using events_trigger
+     *
+     * @param object $touser
+     * @param object $fromuser
+     * @param string $name
+     * @param string $subject
+     * @param string $message
+     */
+    protected function notify($touser, $fromuser, $name='courserequested', $subject, $message) {
+        $eventdata = new object();
+        $eventdata->modulename        = 'moodle';
+        $eventdata->component         = 'course';
+        $eventdata->name              = $name;
+        $eventdata->userfrom          = $fromuser;
+        $eventdata->userto            = $touser;
+        $eventdata->subject           = $subject;
+        $eventdata->fullmessage       = $message;
+        $eventdata->fullmessageformat = FORMAT_PLAIN;
+        $eventdata->fullmessagehtml   = '';
+        $eventdata->smallmessage      = '';
+        events_trigger('message_send', $eventdata);
+    }
+}
\ No newline at end of file
index d9dfefa..f931f4e 100644 (file)
@@ -1,4 +1,4 @@
-<?php  // $Id$
+<?php
 
 ///////////////////////////////////////////////////////////////////////////
 //                                                                       //
  *
  * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  * @package course
- *//** */
+ */
 
-    require_once(dirname(__FILE__) . '/../config.php');
-    require_once($CFG->libdir . '/adminlib.php');
-    require_once($CFG->dirroot . '/course/lib.php');
-    require_once($CFG->dirroot . '/course/request_form.php');
+require_once(dirname(__FILE__) . '/../config.php');
+require_once($CFG->libdir . '/adminlib.php');
+require_once($CFG->dirroot . '/course/lib.php');
+require_once($CFG->dirroot . '/course/request_form.php');
 
-    require_login();
-    require_capability('moodle/site:approvecourse', get_context_instance(CONTEXT_SYSTEM));
+require_login();
+require_capability('moodle/site:approvecourse', get_context_instance(CONTEXT_SYSTEM));
 
-    $approve = optional_param('approve', 0, PARAM_INT);
-    $reject = optional_param('reject', 0, PARAM_INT);
+$approve = optional_param('approve', 0, PARAM_INT);
+$reject = optional_param('reject', 0, PARAM_INT);
 
-    $baseurl = $CFG->wwwroot . '/course/pending.php';
-    admin_externalpage_setup('coursespending');
+$baseurl = $CFG->wwwroot . '/course/pending.php';
+admin_externalpage_setup('coursespending');
 
 /// Process approval of a course.
-    if (!empty($approve) and confirm_sesskey()) {
+if (!empty($approve) and confirm_sesskey()) {
     /// Load the request.
-        if (!$course = $DB->get_record('course_request', array('id' => $approve))) {
-            print_error('unknowncourserequest');
-        }
-
-    /// Get the category courses are added to.
-        $category = get_course_category($CFG->defaultrequestcategory);
-
-    /// Build up a course record based on the request.
-        $course->category = $category->id;
-        $course->sortorder = $category->sortorder; // place as the first in category 
-        $course->requested = 1;
-        unset($course->reason);
-        unset($course->id);
-        $teacherid = $course->requester;
-        unset($course->requester);
-        if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
-            $course->restrictmodules = 1;
-        }
+    $course = new course_request($approve);
+    $courseid = $course->approve();
 
-    /// Apply course default settings
-        $courseconfig = get_config('moodlecourse');
-        $course->format             = $courseconfig->format;
-        $course->numsections        = $courseconfig->numsections;
-        $course->hiddensections     = $courseconfig->hiddensections;
-        $course->newsitems          = $courseconfig->newsitems;
-        $course->showgrades         = $courseconfig->showgrades;
-        $course->showreports        = $courseconfig->showreports;
-        $course->maxbytes           = $courseconfig->maxbytes;
-        $course->enrol              = $courseconfig->enrol;
-        $course->enrollable         = $courseconfig->enrollable;
-        $course->enrolperiod        = $courseconfig->enrolperiod;
-        $course->expirynotify       = $courseconfig->expirynotify;
-        $course->notifystudents     = $courseconfig->notifystudents;
-        $course->expirythreshold    = $courseconfig->expirythreshold;
-        $course->groupmode          = $courseconfig->groupmode;
-        $course->groupmodeforce     = $courseconfig->groupmodeforce;
-        $course->visible            = $courseconfig->visible;
-        $course->enrolpassword      = $courseconfig->enrolpassword;
-        $course->guest              = $courseconfig->guest;
-        $course->lang               = $courseconfig->lang;
-
-    /// Insert the record.
-        if ($courseid = $DB->insert_record('course', $course)) {
-            $course = $DB->get_record('course', array('id' => $courseid));
-            blocks_add_default_course_blocks($course);
-            $context = get_context_instance(CONTEXT_COURSE, $courseid);
-            role_assign($CFG->creatornewroleid, $teacherid, 0, $context->id); // assing teacher role
-            if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
-                // if we're all or requested we're ok.
-                $allowedmods = explode(',',$CFG->defaultallowedmodules);
-                update_restricted_mods($course,$allowedmods);
-            }
-            $DB->delete_records('course_request', array('id'=>$approve));
-            $success = 1;
-            fix_course_sortorder();
-        }
-        if (!empty($success)) {
-            $user = $DB->get_record('user', array('id' => $teacherid));
-            $a->name = $course->fullname;
-            $a->url = $CFG->wwwroot.'/course/view.php?id=' . $courseid;
-            $eventdata = new object();
-            $eventdata->modulename        = 'moodle';
-            $eventdata->component         = 'course';
-            $eventdata->name              = 'courserequestapproved';
-            $eventdata->userfrom          = $USER;
-            $eventdata->userto            = $user;
-            $eventdata->subject           = get_string('courseapprovedsubject');
-            $eventdata->fullmessage       = get_string('courseapprovedemail2', 'moodle', $a);
-            $eventdata->fullmessageformat = FORMAT_PLAIN;
-            $eventdata->fullmessagehtml   = '';
-            $eventdata->smallmessage      = '';
-            events_trigger('message_send', $eventdata);
-
-            redirect($CFG->wwwroot.'/course/edit.php?id=' . $courseid);
-        } else {
-            print_error('courseapprovedfailed');
-        }
+    if ($courseid !== false) {
+        redirect($CFG->wwwroot.'/course/edit.php?id=' . $courseid);
+    } else {
+        print_error('courseapprovedfailed');
     }
+}
 
 /// Process rejection of a course.
-    if (!empty($reject)) {
-    /// Load the request.
-        if (!$course = $DB->get_record('course_request', array('id' => $reject))) {
-            print_error('unknowncourserequest');
-        }
+if (!empty($reject)) {
+    // Load the request.
+    $course = new course_request($reject);
 
-    /// Prepare the form.
-        $rejectform = new reject_request_form($baseurl);
-        $default = new stdClass();
-        $default->reject = $reject;
-        $rejectform->set_data($default);
+    // Prepare the form.
+    $rejectform = new reject_request_form($baseurl);
+    $default = new stdClass();
+    $default->reject = $course->id;
+    $rejectform->set_data($default);
 
-    /// Standard form processing if statement.
-        if ($rejectform->is_cancelled()){
-            redirect($baseurl);
-    
-        } else if ($data = $rejectform->get_data()) {
-        /// Send an email to the requester.
-            $user = $DB->get_record('user', array('id' => $course->requester));
-            $eventdata = new object();
-            $eventdata->modulename        = 'moodle';
-            $eventdata->component         = 'course';
-            $eventdata->name              = 'courserequestrejected';
-            $eventdata->userfrom          = $USER;
-            $eventdata->userto            = $user;
-            $eventdata->subject           = get_string('courserejectsubject');
-            $eventdata->fullmessage       = get_string('courserejectemail', 'moodle', $data->rejectnotice);
-            $eventdata->fullmessageformat = FORMAT_PLAIN;
-            $eventdata->fullmessagehtml   = '';
-            $eventdata->smallmessage      = '';
-            events_trigger('message_send', $eventdata);
-
-        /// Delete the request
-            $DB->delete_records('course_request', array('id' => $course->id));
+/// Standard form processing if statement.
+    if ($rejectform->is_cancelled()){
+        redirect($baseurl);
 
-        /// Redirect back to the course listing.
-            redirect($baseurl, get_string('courserejected'));
-        }
+    } else if ($data = $rejectform->get_data()) {
 
-    /// Display the form for giving a reason for rejecting the request.
-        admin_externalpage_print_header($rejectform->focus());
-        $rejectform->display();
-        echo $OUTPUT->footer();
-        exit;
+        /// Reject the request
+        $course->reject($data->rejectnotice);
+
+        /// Redirect back to the course listing.
+        redirect($baseurl, get_string('courserejected'));
     }
 
-/// Print a list of all the pending requests.
-    admin_externalpage_print_header();
+/// Display the form for giving a reason for rejecting the request.
+    admin_externalpage_print_header($rejectform->focus());
+    $rejectform->display();
+    echo $OUTPUT->footer();
+    exit;
+}
 
-    $pending = $DB->get_records('course_request');
-    if (empty($pending)) {
-        echo $OUTPUT->heading(get_string('nopendingcourses'));
-    } else {
-        echo $OUTPUT->heading(get_string('coursespending'));
-
-    /// Build a table of all the requests.
-        $table = new html_table();
-        $table->add_class('pendingcourserequests generaltable');
-        $table->align = array('center', 'center', 'center', 'center', 'center', 'center', 'center');
-        $table->head = array('&nbsp;', get_string('shortname'), get_string('fullname'),
-                get_string('requestedby'), get_string('summary'), get_string('requestreason'), get_string('action'));
-        $strrequireskey = get_string('requireskey');
-
-    /// Loop over requested courses.
-        foreach ($pending as $course) {
-            $requester = $DB->get_record('user', array('id'=>$course->requester));
-            $row = array();
-
-        /// Check here for shortname collisions and warn about them.
-            if ($DB->record_exists('course', array('shortname' => $course->shortname))) {
-                $course->shortname .= ' [*]';
-                $collision = 1;
-            }
-
-        /// Show an enrolment key icon in the first column if applicable.
-            if (!empty($course->password)) {
-                $row[] = '<img hspace="1" alt="'.$strrequireskey.'" class="icon" src="'.$OUTPUT->old_icon_url('i/key') . '" />';
-            } else {
-                $row[] = '';
-            }
-
-        /// Info in the other columns.
-            $row[] = format_string($course->shortname);
-            $row[] = format_string($course->fullname);
-            $row[] = fullname($requester);
-            $row[] = format_string($course->summary);
-            $row[] = format_string($course->reason);
-            $row[] = $OUTPUT->button(html_form::make_button($baseurl, array('approve' => $course->id, 'sesskey' => sesskey()), get_string('approve'), 'get')) .
-                    $OUTPUT->button(html_form::make_button($baseurl, array('reject' => $course->id), get_string('rejectdots'), 'get'));
-
-        /// Add the row to the table.
-            $table->data[] = $row;
+/// Print a list of all the pending requests.
+admin_externalpage_print_header();
+
+$pending = $DB->get_records('course_request');
+if (empty($pending)) {
+    echo $OUTPUT->heading(get_string('nopendingcourses'));
+} else {
+    echo $OUTPUT->heading(get_string('coursespending'));
+
+/// Build a table of all the requests.
+    $table = new html_table();
+    $table->add_class('pendingcourserequests generaltable');
+    $table->align = array('center', 'center', 'center', 'center', 'center', 'center', 'center');
+    $table->head = array('&nbsp;', get_string('shortname'), get_string('fullname'),
+            get_string('requestedby'), get_string('summary'), get_string('requestreason'), get_string('action'));
+    $strrequireskey = get_string('requireskey');
+
+    // Loop over requested courses.
+    $keyicon = new html_image();
+    $keyicon->src = $OUTPUT->old_icon_url('i/key');
+    $keyicon->alt = $strrequireskey;
+    $keyicon->add_class('icon');
+    $keyicon = $OUTPUT->image($keyicon);
+    
+    foreach ($pending as $course) {
+        $course = new course_request($course);
+        
+        // Check here for shortname collisions and warn about them.
+        $course->check_shortname_collision();
+
+        $row = array();
+        // Show an enrolment key icon in the first column if applicable.
+        if (!empty($course->password)) {
+            $row[] = $keyicon;
+        } else {
+            $row[] = '';
         }
+        // Info in the other columns.
+        $row[] = format_string($course->shortname);
+        $row[] = format_string($course->fullname);
+        $row[] = fullname($course->get_requester());
+        $row[] = $course->summary;
+        $row[] = format_string($course->reason);
+        $row[] = $OUTPUT->button(html_form::make_button($baseurl, array('approve' => $course->id, 'sesskey' => sesskey()), get_string('approve'), 'get')) .
+                $OUTPUT->button(html_form::make_button($baseurl, array('reject' => $course->id), get_string('rejectdots'), 'get'));
+
+    /// Add the row to the table.
+        $table->data[] = $row;
+    }
 
-    /// Display the table.
-        echo $OUTPUT->table($table);
+/// Display the table.
+    echo $OUTPUT->table($table);
 
-    /// Message about name collisions, if necessary.
-        if (!empty($collision)) {
-            print_string('shortnamecollisionwarning');
-        }
+/// Message about name collisions, if necessary.
+    if (!empty($collision)) {
+        print_string('shortnamecollisionwarning');
     }
+}
 
 /// Finish off the page.
-    echo $OUTPUT->button(html_form::make_button($CFG->wwwroot . '/course/index.php', array(), get_string('backtocourselisting')));
-    echo $OUTPUT->footer();
-?>
+echo $OUTPUT->button(html_form::make_button($CFG->wwwroot . '/course/index.php', array(), get_string('backtocourselisting')));
+echo $OUTPUT->footer();
\ No newline at end of file
index d7b52c0..518b7d6 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 require_once(dirname(__FILE__) . '/../config.php');
+require_once($CFG->dirroot . '/course/lib.php');
 require_once($CFG->dirroot . '/course/request_form.php');
 
 $PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/request.php'));
@@ -39,65 +40,31 @@ if (isguestuser()) {
 if (empty($CFG->enablecourserequests)) {
     print_error('courserequestdisabled', '', $returnurl);
 }
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
-require_capability('moodle/course:request', $systemcontext);
+require_capability('moodle/course:request', get_context_instance(CONTEXT_SYSTEM));
 
 /// Set up the form.
-$requestform = new course_request_form($CFG->wwwroot . '/course/request.php');
+$data = course_request::prepare();
+$requestform = new course_request_form($CFG->wwwroot . '/course/request.php', compact('editoroptions'));
+$requestform->set_data($data);
 
 $strtitle = get_string('courserequest');
+$PAGE->set_title($strtitle);
+$PAGE->set_heading($strtitle);
 
 /// Standard form processing if statement.
 if ($requestform->is_cancelled()){
     redirect($returnurl);
 
-} else if ($data = $requestform->get_data()) {
-    $PAGE->set_title($strtitle);
-    $PAGE->set_heading($strtitle);
-    $PAGE->navbar->add($strtitle);
-    $PAGE->set_focuscontrol($requestform->focus());
-    echo $OUTPUT->header();
-    echo $OUTPUT->heading($strtitle);
-
-/// Record the request.
-    $data->requester = $USER->id;
-    $DB->insert_record('course_request', $data);
-
-/// Notify the admin if required.
-    if ($CFG->courserequestnotify) {
-        $users = get_users_from_config($CFG->courserequestnotify, 'moodle/site:approvecourse');
-        foreach ($users as $user) {
-            $eventdata = new object();
-            $eventdata->modulename        = 'moodle';
-            $eventdata->component         = 'course';
-            $eventdata->name              = 'courserequested';
-            $eventdata->userfrom          = $USER;
-            $eventdata->userto            = $user;
-            $eventdata->subject = get_string('courserequest');
-            $a = new object();
-            $a->link = "$CFG->wwwroot/course/pending.php";
-            $a->user = fullname($USER);
-            $eventdata->fullmessage = get_string('courserequestnotifyemail', 'admin', $a);
-            $eventdata->fullmessageformat = FORMAT_PLAIN;
-            $eventdata->fullmessagehtml   = '';
-            $eventdata->smallmessage      = '';
-            events_trigger('message_send', $eventdata);
-        }
-    }
+} else if ($data = $requestform->get_data()) {    
+    $request = course_request::create($data);
 
-/// and redirect back to the course listing.
+    // and redirect back to the course listing.
     notice(get_string('courserequestsuccess'), $returnurl);
 }
 
-/// Show the request form.
-
-$PAGE->set_title($strtitle);
-$PAGE->set_heading($strtitle);
 $PAGE->navbar->add($strtitle);
-$PAGE->set_focuscontrol($requestform->focus());
 echo $OUTPUT->header();
 echo $OUTPUT->heading($strtitle);
+// Show the request form.
 $requestform->display();
-echo $OUTPUT->footer();
-
-?>
\ No newline at end of file
+echo $OUTPUT->footer();
\ No newline at end of file
index d084fff..5fc5da7 100644 (file)
@@ -1,4 +1,4 @@
-<?php  // $Id$
+<?php
 
 ///////////////////////////////////////////////////////////////////////////
 //                                                                       //
@@ -29,7 +29,7 @@
  *
  * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  * @package course
- *//** */
+ */
 
 require_once($CFG->libdir.'/formslib.php');
 
@@ -64,9 +64,9 @@ class course_request_form extends moodleform {
         $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
         $mform->setType('shortname', PARAM_MULTILANG);
 
-        $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows'=>'15', 'cols'=>'50'));
-        $mform->setHelpButton('summary', array('text2', get_string('helptext')), true);
-        $mform->setType('summary', PARAM_RAW);
+        $mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request::summary_editor_options());
+        $mform->setHelpButton('summary_editor', array('text2', get_string('helptext')), true);
+        $mform->setType('summary_editor', PARAM_RAW);
 
         $mform->addElement('passwordunmask', 'password', get_string('enrolmentkey'), 'size="25"');
         $mform->setHelpButton('password', array('enrolmentkey', get_string('enrolmentkey')), true);
index d93415c..38139bd 100644 (file)
@@ -77,6 +77,8 @@ if ($scaleid) {
     }
 }
 
+$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+
 if ($scales = $DB->get_records("scale", array("courseid"=>$course->id), "name ASC")) {
     echo $OUTPUT->heading($strcustomscales);
 
@@ -87,6 +89,9 @@ if ($scales = $DB->get_records("scale", array("courseid"=>$course->id), "name AS
     }
 
     foreach ($scales as $scale) {
+
+        $scale->description = file_rewrite_pluginfile_urls($scale->description, 'pluginfile.php', $systemcontext->id, 'grade_scale', $scale->id);
+
         $scalemenu = make_menu_from_list($scale->scale);
 
         echo $OUTPUT->box_start();
@@ -110,6 +115,9 @@ if ($scales = $DB->get_records("scale", array("courseid"=>$course->id), "name AS
 if ($scales = $DB->get_records("scale", array("courseid"=>0), "name ASC")) {
     echo $OUTPUT->heading($strstandardscales);
     foreach ($scales as $scale) {
+
+        $scale->description = file_rewrite_pluginfile_urls($scale->description, 'pluginfile.php', $systemcontext->id, 'grade_scale', $scale->id);
+
         $scalemenu = make_menu_from_list($scale->scale);
 
         echo $OUTPUT->box_start();
index 738f111..763fed0 100644 (file)
 
         if (!$adminediting) {
             foreach ($courses as $course) {
+
+                if (isset($course->context)) {
+                    $coursecontext = $course->context;
+                } else {
+                    $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+                }
+
                 $course->summary .= "<br /><p class=\"category\">";
                 $course->summary .= "$strcategory: <a href=\"category.php?id=$course->category\">";
                 $course->summary .= $displaylist[$course->category];
index d5a3e11..a56abd6 100644 (file)
@@ -31,6 +31,11 @@ require_once 'edit_form.php';
 $courseid = optional_param('courseid', 0, PARAM_INT);
 $id       = optional_param('id', 0, PARAM_INT);
 
+$url = new moodle_url($CFG->wwwroot.'/grade/edit/outcome/edit.php');
+if ($courseid !== 0) $url->param('courseid', $courseid);
+if ($id !== 0) $url->param('id', $id);
+$PAGE->set_url($url);
+
 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
 $heading = null;
 
@@ -88,8 +93,15 @@ if ($id) {
 // default return url
 $gpr = new grade_plugin_return();
 $returnurl = $gpr->get_return_url('index.php?id='.$courseid);
+$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
+
+if (!empty($outcome_rec->id)) {
+    $outcome_rec = file_prepare_standard_editor($outcome_rec, 'description', $editoroptions, $systemcontext, 'grade_outcome', $outcome_rec->id);
+} else {
+    $outcome_rec = file_prepare_standard_editor($outcome_rec, 'description', $editoroptions, $systemcontext, 'grade_outcome', null);
+}
 
-$mform = new edit_outcome_form(null, array('gpr'=>$gpr));
+$mform = new edit_outcome_form(null, compact('gpr', 'editoroptions'));
 
 $mform->set_data($outcome_rec);
 
@@ -99,9 +111,10 @@ if ($mform->is_cancelled()) {
 } else if ($data = $mform->get_data()) {
     $outcome = new grade_outcome(array('id'=>$id));
     $data->usermodified = $USER->id;
-    grade_outcome::set_properties($outcome, $data);
 
     if (empty($outcome->id)) {
+        $data->description = $data->description_editor['text'];
+        grade_outcome::set_properties($outcome, $data);
         if (!has_capability('moodle/grade:manage', $systemcontext)) {
             $data->standard = 0;
         }
@@ -111,7 +124,11 @@ if ($mform->is_cancelled()) {
         }
         $outcome->insert();
 
+        $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade_outcome', $outcome->id);
+        $DB->set_field($outcome->table, 'description', $data->description, array('id'=>$outcome->id));
     } else {
+        $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade_outcome', $id);
+        grade_outcome::set_properties($outcome, $data);
         if (isset($data->standard)) {
             $outcome->courseid = !empty($data->standard) ? null : $courseid;
         } else {
index 3983b87..71e93bb 100644 (file)
@@ -43,7 +43,7 @@ class edit_outcome_form extends moodleform {
         $mform->setHelpButton('scaleid', array('scaleid', get_string('scale'), 'grade'));
         $mform->addRule('scaleid', get_string('required'), 'required');
 
-        $mform->addElement('htmleditor', 'description', get_string('description'), array('cols'=>80, 'rows'=>20));
+        $mform->addElement('editor', 'description_editor', get_string('description'), null, $this->_customdata['editoroptions']);
 
 
         // hidden params
index 5d226c1..e1ce6b0 100644 (file)
@@ -70,12 +70,12 @@ foreach($outcomes as $outcome) {
 
     $line[] = $outcome->get_name();
     $line[] = $outcome->get_shortname();
-    $line[] = $outcome->description;
+    $line[] = $outcome->get_description();
 
     $scale = $outcome->load_scale();
     $line[] = $scale->get_name();
     $line[] = $scale->compact_items();
-    $line[] = $scale->description;
+    $line[] = $scale->get_description();
 
     echo format_csv($line, ';', '"');
 }
index f958760..e8d3b6f 100644 (file)
@@ -87,8 +87,14 @@ if (!$courseid) {
 // default return url
 $gpr = new grade_plugin_return();
 $returnurl = $gpr->get_return_url('index.php?id='.$courseid);
+$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
 
-$mform = new edit_scale_form(null, array('gpr'=>$gpr));
+if (!empty($scale_rec->id)) {
+    $scale_rec = file_prepare_standard_editor($scale_rec, 'description', $editoroptions, $systemcontext, 'grade_scale', $scale_rec->id);
+} else {
+    $scale_rec = file_prepare_standard_editor($scale_rec, 'description', $editoroptions, $systemcontext, 'grade_scale', null);
+}
+$mform = new edit_scale_form(null, compact('gpr', 'editoroptions'));
 
 $mform->set_data($scale_rec);
 
@@ -98,16 +104,20 @@ if ($mform->is_cancelled()) {
 } else if ($data = $mform->get_data()) {
     $scale = new grade_scale(array('id'=>$id));
     $data->userid = $USER->id;
-    grade_scale::set_properties($scale, $data);
 
     if (empty($scale->id)) {
+        $data->description = $data->description_editor['text'];
+        grade_scale::set_properties($scale, $data);
         if (!has_capability('moodle/grade:manage', $systemcontext)) {
             $data->standard = 0;
         }
         $scale->courseid = !empty($data->standard) ? 0 : $courseid;
         $scale->insert();
-
+        $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade_scale', $scale->id);
+        $DB->set_field($scale->table, 'description', $data->description, array('id'=>$outcome->id));
     } else {
+        $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade_scale', $id);
+        grade_scale::set_properties($scale, $data);
         if (isset($data->standard)) {
             $scale->courseid = !empty($data->standard) ? 0 : $courseid;
         } else {
index be72751..7879856 100644 (file)
@@ -39,8 +39,7 @@ class edit_scale_form extends moodleform {
         $mform->addRule('scale', get_string('required'), 'required', null, 'client');
         $mform->setType('scale', PARAM_TEXT);
 
-        $mform->addElement('htmleditor', 'description', get_string('description'), array('cols'=>80, 'rows'=>20));
-
+        $mform->addElement('editor', 'description_editor', get_string('description'), null, $this->_customdata['editoroptions']);
 
         // hidden params
         $mform->addElement('hidden', 'id', 0);
index c533335..299ebe5 100644 (file)
@@ -147,9 +147,11 @@ if ($grade = $DB->get_record('grade_grades', array('itemid' => $grade_item->id,
     $grade->oldgrade    = $grade->finalgrade;
     $grade->oldfeedback = $grade->feedback;
 
-    $mform->set_data($grade);
+    $grade->feedback = array('text'=>$grade->feedback, 'format'=>$grade->feedbackformat);
 
+    $mform->set_data($grade);
 } else {
+    $grade->feedback = array('text'=>'', 'format'=>FORMAT_HTML);
     $mform->set_data(array('itemid'=>$itemid, 'userid'=>$userid, 'locked'=>$grade_item->locked, 'locktime'=>$grade_item->locktime));
 }
 
@@ -158,6 +160,12 @@ if ($mform->is_cancelled()) {
 
 // form processing
 } else if ($data = $mform->get_data(false)) {
+
+    if (is_array($data->feedback)) {
+        $data->feedbackformat = $data->feedback['format'];
+        $data->feedback = $data->feedback['text'];
+    }
+
     $old_grade_grade = new grade_grade(array('userid'=>$data->userid, 'itemid'=>$grade_item->id), true); //might not exist yet
 
     // fix no grade for scales
index c2f7c34..63cdd01 100755 (executable)
@@ -96,13 +96,10 @@ class edit_grade_form extends moodleform {
         $mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
 
         // Feedback format is automatically converted to html if user has enabled editor
-        $mform->addElement('htmleditor', 'feedback', get_string('feedback', 'grades'),
-            array('rows'=>'15', 'course'=>$COURSE->id, 'cols'=>'45'));
+        $feedbackoptions = array('maxfiles'=>0, 'maxbytes'=>0, 'trusttext'=>true);
+        $mform->addElement('editor', 'feedback', get_string('feedback', 'grades'), null, $feedbackoptions);
         $mform->setHelpButton('feedback', array('feedback', get_string('feedback', 'grades'), 'grade'));
         $mform->setType('text', PARAM_RAW); // to be cleaned before display, no XSS risk
-        $mform->addElement('format', 'feedbackformat', get_string('format'));
-        $mform->setHelpButton('feedbackformat', array('textformat', get_string('helpformatting')));
-        //TODO: unfortunately we can not disable html editor for external grades when overridden off :-(
 
         // hidden params
         $mform->addElement('hidden', 'oldgrade');
index ed5d4c9..4e35548 100644 (file)
@@ -29,7 +29,6 @@ if ($id) {
     if (!$group = $DB->get_record('groups', array('id'=>$id))) {
         print_error('invalidgroupid');
     }
-    $group->description = clean_text($group->description);
     if (empty($courseid)) {
         $courseid = $group->courseid;
 
@@ -83,8 +82,16 @@ if ($id and $delete) {
     }
 }
 
+// Prepare the description editor: We do support files for group descriptions
+$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>false, 'context'=>$context, 'noclean'=>true);
+if (!empty($group->id)) {
+    $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'course_group_description', $group->id);
+} else {
+    $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'course_group_description', null);
+}
+
 /// First create the form
-$editform = new group_form();
+$editform = new group_form(null, array('editoroptions'=>$editoroptions));
 $editform->set_data($group);
 
 if ($editform->is_cancelled()) {
index e99511d..3d03803 100644 (file)
@@ -1,5 +1,15 @@
 <?php
 
+/**
+ * Create//edit group form.
+ *
+ * @copyright &copy; 2006 The Open University
+ * @author N.D.Freear AT open.ac.uk
+ * @author J.White AT open.ac.uk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package groups
+ */
+
 require_once($CFG->dirroot.'/lib/formslib.php');
 
 /// get url variables
@@ -10,13 +20,14 @@ class group_form extends moodleform {
         global $USER, $CFG, $COURSE;
 
         $mform =& $this->_form;
+        $editoroptions = $this->_customdata['editoroptions'];
 
         $mform->addElement('text','name', get_string('groupname', 'group'),'maxlength="254" size="50"');
         $mform->addRule('name', get_string('required'), 'required', null, 'client');
         $mform->setType('name', PARAM_MULTILANG);
 
-        $mform->addElement('htmleditor', 'description', get_string('groupdescription', 'group'), array('rows'=> '15', 'course' => $COURSE->id, 'cols'=>'45'));
-        $mform->setType('description', PARAM_RAW);
+        $mform->addElement('editor', 'description_editor', get_string('groupdescription', 'group'), null, $editoroptions);
+        $mform->setType('description_editor', PARAM_RAW);
 
         $mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey'));
         $mform->setHelpButton('enrolmentkey', array('groupenrolmentkey', get_string('enrolmentkey', 'group')), true);
@@ -74,4 +85,8 @@ class group_form extends moodleform {
     function get_um() {
         return $this->_upload_manager;
     }
+
+    function get_editor_options() {
+        return $this->_customdata['editoroptions'];
+    }
 }
index d7ffbce..dbea9fc 100644 (file)
@@ -36,7 +36,7 @@ if ($id) {
     if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
         print_error('invalidcourseid');
     }
-
+    
 } else {
     $url->param('courseid', $courseid);
     if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
@@ -77,8 +77,16 @@ if ($id and $delete) {
     }
 }
 
+// Prepare the description editor: We do support files for grouping descriptions
+$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>true, 'context'=>$context, 'noclean'=>true);
+if (!empty($grouping->id)) {
+    $grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'course_grouping_description', $grouping->id);
+} else {
+    $grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'course_grouping_description', null);
+}
+
 /// First create the form
-$editform = new grouping_form();
+$editform = new grouping_form(null, compact('editoroptions'));
 $editform->set_data($grouping);
 
 if ($editform->is_cancelled()) {
@@ -88,10 +96,9 @@ if ($editform->is_cancelled()) {
     $success = true;
 
     if ($data->id) {
-        groups_update_grouping($data);
-
+        groups_update_grouping($data, $editoroptions);
     } else {
-        groups_create_grouping($data);
+        groups_create_grouping($data, $editoroptions);
     }
 
     redirect($returnurl);
@@ -108,7 +115,7 @@ if ($id) {
 }
 
 $PAGE->navbar->add($strparticipants, new moodle_url($CFG->wwwroot.'/user/index.php', array('id'=>$courseid)));
-$PAGE->navbar->add($strgroups, new moodle_url($CFG->wwwroot.'/group/groupings.php', array('id'=>$courseid)));
+$PAGE->navbar->add($strgroupings, new moodle_url($CFG->wwwroot.'/group/groupings.php', array('id'=>$courseid)));
 $PAGE->navbar->add($strheading);
 
 /// Print header
index 2d986f8..98d7a94 100644 (file)
@@ -1,4 +1,13 @@
 <?php
+/**
+ * Create/Edit grouping form.
+ *
+ * @copyright &copy; 2006 The Open University
+ * @author N.D.Freear AT open.ac.uk
+ * @author J.White AT open.ac.uk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package groups
+ */
 
 require_once($CFG->dirroot.'/lib/formslib.php');
 
@@ -10,13 +19,14 @@ class grouping_form extends moodleform {
         global $USER, $CFG, $COURSE;
 
         $mform =& $this->_form;
+        $editoroptions = $this->_customdata['editoroptions'];
 
         $mform->addElement('text','name', get_string('groupingname', 'group'),'maxlength="254" size="50"');
         $mform->addRule('name', get_string('required'), 'required', null, 'server');
         $mform->setType('name', PARAM_MULTILANG);
 
-        $mform->addElement('htmleditor', 'description', get_string('groupingdescription', 'group'), array('rows'=> '15', 'course' => $COURSE->id, 'cols'=>'45'));
-        $mform->setType('description', PARAM_RAW);
+        $mform->addElement('editor', 'description_editor', get_string('groupingdescription', 'group'), null, $editoroptions);
+        $mform->setType('description_editor', PARAM_RAW);
 
         $mform->addElement('hidden','id');
         $mform->setType('id', PARAM_INT);
index 0dc59a4..ddf2242 100644 (file)
@@ -116,7 +116,7 @@ function groups_remove_member($grouporid, $userorid) {
  * @param object $um upload manager with group picture
  * @return id of group or false if error
  */
-function groups_create_group($data, $editform=false) {
+function groups_create_group($data, $editform=false, $editoroptions=null) {
     global $CFG, $DB;
     require_once("$CFG->libdir/gdlib.php");
 
@@ -126,6 +126,12 @@ function groups_create_group($data, $editform=false) {
     $data->timecreated  = time();
     $data->timemodified = $data->timecreated;
     $data->name         = trim($data->name);
+
+    if ($editform) {
+        $data->description = $data->description_editor['text'];
+        $data->descriptionformat = $data->description_editor['format'];
+    }
+
     $id = $DB->insert_record('groups', $data);
 
     $data->id = $id;
@@ -135,6 +141,16 @@ function groups_create_group($data, $editform=false) {
             $DB->set_field('groups', 'picture', 1, array('id'=>$id));
         }
         $data->picture = 1;
+
+        if (method_exists($editform, 'get_editor_options')) {
+            // Update description from editor with fixed files
+            $editoroptions = $editform->get_editor_options();
+            $description = new stdClass;
+            $description->id = $data->id;
+            $description->description_editor = $data->description_editor;
+            $description = file_postupdate_standard_editor($description, 'description', $editoroptions, $editoroptions['context'], 'course_group_description', $description->id);
+            $DB->update_record('groups', $description);
+        }
     }
 
     //trigger groups events
@@ -148,16 +164,31 @@ function groups_create_group($data, $editform=false) {
  * @param object $data grouping properties (with magic quotes)
  * @return id of grouping or false if error
  */
-function groups_create_grouping($data) {
+function groups_create_grouping($data, $editoroptions=null) {
     global $DB;
 
     $data->timecreated  = time();
     $data->timemodified = $data->timecreated;
     $data->name         = trim($data->name);
+
+    if ($editoroptions !== null) {
+        $data->description = $data->description_editor['text'];
+        $data->descriptionformat = $data->description_editor['format'];
+    }
+
     $id = $DB->insert_record('groupings', $data);
 
     //trigger groups events
     $data->id = $id;
+
+    if ($editoroptions !== null) {
+        $description = new stdClass;
+        $description->id = $data->id;
+        $description->description_editor = $data->description_editor;
+        $description = file_postupdate_standard_editor($description, 'description', $editoroptions, $editoroptions['context'], 'course_grouping_description', $description->id);
+        $DB->update_record('groupings', $description);
+    }
+
     events_trigger('groups_grouping_created', $data);
 
     return $id;
@@ -175,6 +206,12 @@ function groups_update_group($data, $editform=false) {
 
     $data->timemodified = time();
     $data->name         = trim($data->name);
+
+    if ($editform && method_exists($editform, 'get_editor_options')) {
+        $editoroptions = $editform->get_editor_options();
+        $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $editoroptions['context'], 'course_group_description', $data->id);
+    }
+
     $DB->update_record('groups', $data);
 
     if ($editform) {
@@ -196,10 +233,13 @@ function groups_update_group($data, $editform=false) {
  * @param object $data grouping properties (with magic quotes)
  * @return boolean true or exception
  */
-function groups_update_grouping($data) {
+function groups_update_grouping($data, $editoroptions=null) {
     global $DB;
     $data->timemodified = time();
     $data->name         = trim($data->name);
+    if ($editoroptions !== null) {
+        $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $editoroptions['context'], 'course_grouping_description', $data->id);
+    }
     $DB->update_record('groupings', $data);
     //trigger groups events
     events_trigger('groups_grouping_updated', $data);
@@ -238,6 +278,15 @@ function groups_delete_group($grouporid) {
     delete_profile_image($groupid, 'groups');
     //group itself last
     $DB->delete_records('groups', array('id'=>$groupid));
+
+    // Delete all files associated with this group
+    $context = get_context_instace(CONTEXT_COURSE, $group->courseid);
+    $fs = get_file_storage();
+    $files = $fs->get_area_files($context->id, 'course_group_description', $groupid);
+    foreach ($files as $file) {
+        $file->delete();
+    }
+
     //trigger groups events
     events_trigger('groups_group_deleted', $group);
 
@@ -271,6 +320,14 @@ function groups_delete_grouping($groupingorid) {
     $DB->set_field('course_modules', 'groupingid', 0, array('groupingid'=>$groupingid));
     //group itself last
     $DB->delete_records('groupings', array('id'=>$groupingid));
+
+    $context = get_context_instace(CONTEXT_COURSE, $grouping->courseid);
+    $fs = get_file_storage();
+    $files = $fs->get_area_files($context->id, 'course_grouping_description', $groupingid);
+    foreach ($files as $file) {
+        $file->delete();
+    }
+
     //trigger groups events
     events_trigger('groups_grouping_deleted', $grouping);
 
@@ -329,6 +386,11 @@ function groups_delete_groupings_groups($courseid, $showfeedback=false) {
     $groupssql = "SELECT id FROM {groups} g WHERE g.courseid = ?";
     $DB->delete_records_select('groupings_groups', "groupid IN ($groupssql)", array($courseid));
 
+    // Delete all files associated with groupings for this course
+    $context = get_context_instace(CONTEXT_COURSE, $courseid);
+    $fs = get_file_storage();
+    $fs->delete_area_files($context->id, 'course_group_description');
+
     //trigger groups events
     events_trigger('groups_groupings_groups_removed', $courseid);
 
@@ -350,6 +412,7 @@ function groups_delete_groups($courseid, $showfeedback=false) {
     require_once($CFG->libdir.'/gdlib.php');
 
     // delete any uses of groups
+    // Any associated files are deleted as part of groups_delete_groupings_groups
     groups_delete_groupings_groups($courseid, $showfeedback);
     groups_delete_group_members($courseid, 0, $showfeedback);
 
@@ -397,6 +460,11 @@ function groups_delete_groupings($courseid, $showfeedback=false) {
 
     $DB->delete_records('groupings', array('courseid'=>$courseid));
 
+    // Delete all files associated with groupings for this course
+    $context = get_context_instace(CONTEXT_COURSE, $courseid);
+    $fs = get_file_storage();
+    $fs->delete_area_files($context->id, 'course_grouping_description');
+
     //trigger groups events
     events_trigger('groups_groupings_deleted', $courseid);
 
index c6a5ae6..9e40769 100644 (file)
@@ -175,7 +175,10 @@ foreach ($members as $gpgid=>$groupdata) {
         }
         $line = array();
         $name = format_string($groups[$gpid]->name);
-        $jsdescription = addslashes_js(trim(format_text($groups[$gpid]->description)));
+        $description = file_rewrite_pluginfile_urls($groups[$gpid]->description, 'pluginfile.php', $context->id, 'course_group_description', $gpid);
+        $options = new stdClass;
+        $options->noclean = true;
+        $jsdescription = addslashes_js(trim(format_text($description, $groups[$gpid]->descriptionformat, $options)));
         if (empty($jsdescription)) {
             $line[] = $name;
         } else {
@@ -200,7 +203,10 @@ foreach ($members as $gpgid=>$groupdata) {
             echo $OUTPUT->heading($strnotingrouping, 3);
         } else {
             echo $OUTPUT->heading(format_string($groupings[$gpgid]->name), 3);
-            echo $OUTPUT->box(format_text($groupings[$gpgid]->description), 'generalbox boxwidthnarrow boxaligncenter');
+            $description = file_rewrite_pluginfile_urls($groupings[$gpgid]->description, 'pluginfile.php', $context->id, 'course_grouping_description', $gpgid);
+            $options = new stdClass;
+            $options->noclean = true;
+            echo $OUTPUT->box(format_text($description, $groupings[$gpgid]->descriptionformat, $options), 'generalbox boxwidthnarrow boxaligncenter');
         }
     }
     echo $OUTPUT->table($table);
index 4b8ae9d..53cb9b0 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20091026" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20091029" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
@@ -75,8 +75,9 @@
         <FIELD NAME="fullname" TYPE="char" LENGTH="254" NOTNULL="true" SEQUENCE="false" PREVIOUS="password" NEXT="shortname"/>
         <FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="fullname" NEXT="idnumber"/>
         <FIELD NAME="idnumber" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="shortname" NEXT="summary"/>
-        <FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="idnumber" NEXT="format"/>
-        <FIELD NAME="format" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="topics" SEQUENCE="false" PREVIOUS="summary" NEXT="showgrades"/>
+        <FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="idnumber" NEXT="summaryformat"/>
+        <FIELD NAME="summaryformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="summary" NEXT="format"/>
+        <FIELD NAME="format" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="topics" SEQUENCE="false" PREVIOUS="summaryformat" NEXT="showgrades"/>
         <FIELD NAME="showgrades" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="format" NEXT="modinfo"/>
         <FIELD NAME="modinfo" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" PREVIOUS="showgrades" NEXT="newsitems"/>
         <FIELD NAME="newsitems" TYPE="int" LENGTH="5" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="modinfo" NEXT="guest"/>
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="description"/>
-        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="parent"/>
-        <FIELD NAME="parent" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="sortorder"/>
+        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="descriptionformat"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="parent"/>
+        <FIELD NAME="parent" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="descriptionformat" NEXT="sortorder"/>
         <FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="parent" NEXT="coursecount"/>
         <FIELD NAME="coursecount" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="sortorder" NEXT="visible"/>
         <FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" PREVIOUS="coursecount" NEXT="timemodified"/>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="fullname"/>
         <FIELD NAME="fullname" TYPE="char" LENGTH="254" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="shortname"/>
         <FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="fullname" NEXT="summary"/>
-        <FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="shortname" NEXT="reason"/>
-        <FIELD NAME="reason" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="summary" NEXT="requester"/>
+        <FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="shortname" NEXT="summaryformat"/>
+        <FIELD NAME="summaryformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="summary" NEXT="reason"/>
+        <FIELD NAME="reason" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="summaryformat" NEXT="requester"/>
         <FIELD NAME="requester" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="reason" NEXT="password"/>
         <FIELD NAME="password" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" PREVIOUS="requester"/>
       </FIELDS>
         <FIELD NAME="secret" TYPE="char" LENGTH="15" NOTNULL="true" SEQUENCE="false" PREVIOUS="lastip" NEXT="picture"/>
         <FIELD NAME="picture" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="secret" NEXT="url"/>
         <FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="picture" NEXT="description"/>
-        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="url" NEXT="mailformat"/>
-        <FIELD NAME="mailformat" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="description" NEXT="maildigest"/>
+        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="url" NEXT="descriptionformat"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="mailformat"/>
+        <FIELD NAME="mailformat" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="descriptionformat" NEXT="maildigest"/>
         <FIELD NAME="maildigest" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="mailformat" NEXT="maildisplay"/>
         <FIELD NAME="maildisplay" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="2" SEQUENCE="false" PREVIOUS="maildigest" NEXT="htmleditor"/>
         <FIELD NAME="htmleditor" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="maildisplay" NEXT="ajax"/>
         <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="courseid" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="userid" NEXT="scale"/>
         <FIELD NAME="scale" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="name" NEXT="description"/>
-        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="scale" NEXT="timemodified"/>
-        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description"/>
+        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="scale" NEXT="descriptionformat"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="timemodified"/>
+        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="descriptionformat"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
         <FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="shortname" SEQUENCE="false" COMMENT="short name for each field" PREVIOUS="id" NEXT="name"/>
         <FIELD NAME="name" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false" COMMENT="field name" PREVIOUS="shortname" NEXT="datatype"/>
         <FIELD NAME="datatype" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Type of data held in this field" PREVIOUS="name" NEXT="description"/>
-        <FIELD NAME="description" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="Description of field" PREVIOUS="datatype" NEXT="categoryid"/>
-        <FIELD NAME="categoryid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="id from category table" PREVIOUS="description" NEXT="sortorder"/>
+        <FIELD NAME="description" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="Description of field" PREVIOUS="datatype" NEXT="descriptionformat"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="categoryid"/>
+        <FIELD NAME="categoryid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="id from category table" PREVIOUS="descriptionformat" NEXT="sortorder"/>
         <FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="order within the category" PREVIOUS="categoryid" NEXT="required"/>
         <FIELD NAME="required" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Field required" PREVIOUS="sortorder" NEXT="locked"/>
         <FIELD NAME="locked" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Field locked" PREVIOUS="required" NEXT="visible"/>
         <FIELD NAME="visible" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Visibility: private, public, hidden" PREVIOUS="locked" NEXT="forceunique"/>
         <FIELD NAME="forceunique" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="should the field contain unique data" PREVIOUS="visible" NEXT="signup"/>
         <FIELD NAME="signup" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="display field on signup page" PREVIOUS="forceunique" NEXT="defaultdata"/>
-        <FIELD NAME="defaultdata" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="Default value for this field" PREVIOUS="signup" NEXT="param1"/>
-        <FIELD NAME="param1" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="General parameter field" PREVIOUS="defaultdata" NEXT="param2"/>
+        <FIELD NAME="defaultdata" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="Default value for this field" PREVIOUS="signup" NEXT="defaultdataformat"/>
+        <FIELD NAME="defaultdataformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="defaultdata" NEXT="param1"/>
+        <FIELD NAME="param1" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="General parameter field" PREVIOUS="defaultdataformat" NEXT="param2"/>
         <FIELD NAME="param2" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="General parameter field" PREVIOUS="param1" NEXT="param3"/>
         <FIELD NAME="param3" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="General parameter field" PREVIOUS="param2" NEXT="param4"/>
         <FIELD NAME="param4" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="General parameter field" PREVIOUS="param3" NEXT="param5"/>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="userid"/>
         <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="id from the user table" PREVIOUS="id" NEXT="fieldid"/>
         <FIELD NAME="fieldid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="id from the field table" PREVIOUS="userid" NEXT="data"/>
-        <FIELD NAME="data" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false" COMMENT="Field data" PREVIOUS="fieldid"/>
+        <FIELD NAME="data" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false" COMMENT="Field data" PREVIOUS="fieldid" NEXT="dataformat"/>
+        <FIELD NAME="dataformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="data"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
         <FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The short name or code for this outcome statement" PREVIOUS="courseid" NEXT="fullname"/>
         <FIELD NAME="fullname" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" COMMENT="The full description of the outcome (usually 1 sentence)" PREVIOUS="shortname" NEXT="scaleid"/>
         <FIELD NAME="scaleid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="The recommended scale for this outcome." PREVIOUS="fullname" NEXT="description"/>
-        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="outcome description" PREVIOUS="scaleid" NEXT="timecreated"/>
-        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="the time this outcome was first created" PREVIOUS="description" NEXT="timemodified"/>
+        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="outcome description" PREVIOUS="scaleid" NEXT="descriptionformat"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="timecreated"/>
+        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="the time this outcome was first created" PREVIOUS="descriptionformat" NEXT="timemodified"/>
         <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="the time this outcome was last updated" PREVIOUS="timecreated" NEXT="usermodified"/>
         <FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="the userid of the person who last modified this outcome" PREVIOUS="timemodified"/>
       </FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="courseid"/>
         <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="254" NOTNULL="true" SEQUENCE="false" COMMENT="Short human readable unique name for the group." PREVIOUS="courseid" NEXT="description"/>
-        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="enrolmentkey"/>
-        <FIELD NAME="enrolmentkey" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false" PREVIOUS="description" NEXT="picture"/>
+        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="descriptionformat"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="enrolmentkey"/>
+        <FIELD NAME="enrolmentkey" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false" PREVIOUS="descriptionformat" NEXT="picture"/>
         <FIELD NAME="picture" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="enrolmentkey" NEXT="hidepicture"/>
         <FIELD NAME="hidepicture" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="picture" NEXT="timecreated"/>
         <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="hidepicture" NEXT="timemodified"/>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="courseid"/>
         <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Short human readable unique name for group." PREVIOUS="courseid" NEXT="description"/>
-        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="configdata"/>
-        <FIELD NAME="configdata" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="extra configuration data - may be used by group IU tools" PREVIOUS="description" NEXT="timecreated"/>
+        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="descriptionformat"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="configdata"/>
+        <FIELD NAME="configdata" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="extra configuration data - may be used by group IU tools" PREVIOUS="descriptionformat" NEXT="timecreated"/>
         <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="configdata" NEXT="timemodified"/>
         <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated"/>
       </FIELDS>
index 1d50096..1daa312 100644 (file)
@@ -2706,6 +2706,46 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
         upgrade_main_savepoint($result, 2009103000);
     }
 
+    if ($result && $oldversion < 2009110400) {
+
+        // An array used to store the table name and keys of summary and trust fields
+        // to be added
+        $extendtables = array();
+        $extendtables['course'] = array('summaryformat');
+        $extendtables['course_categories'] = array('descriptionformat');
+        $extendtables['course_request'] = array('summaryformat');
+        $extendtables['grade_outcomes'] = array('descriptionformat');
+        $extendtables['groups'] = array('descriptionformat');
+        $extendtables['groupings'] = array('descriptionformat');
+        $extendtables['scale'] = array('descriptionformat');
+        $extendtables['user'] = array('descriptionformat');
+        $extendtables['user_info_field'] = array('descriptionformat', 'defaultdataformat');
+        $extendtables['user_info_data'] = array('dataformat');
+
+        foreach ($extendtables as $tablestr=>$newfields) {
+            $table = new xmldb_table($tablestr);
+            foreach ($newfields as $fieldstr) {
+                $field = new xmldb_field($fieldstr, XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+                // Check that the field doesn't already exists
+                if (!$dbman->field_exists($table, $field)) {
+                    // Add the new field
+                    $dbman->add_field($table, $field);
+                    // Update the field if the text contains the default FORMAT_MOODLE to FORMAT_HTML
+                    if (($pos = strpos($fieldstr, 'format'))>0) {
+                        upgrade_set_timeout(60*20); // this may take a little while
+                        $params = array(FORMAT_HTML, '<p%', '%<br />%', FORMAT_MOODLE);
+                        $textfield = substr($fieldstr, 0, $pos);
+                        $DB->execute('UPDATE '.$tablestr.' SET '.$fieldstr.'=? WHERE ('.$textfield.' LIKE ? OR '.$textfield.' LIKE ?) AND '.$fieldstr.'=?', $params);
+                    }
+                }
+            }
+        }
+
+        unset($extendtables);
+
+        upgrade_main_savepoint($result, 2009110400);
+    }
+
     return $result;
 }
 
index 2cb6a3c..5d9396f 100644 (file)
@@ -40,8 +40,8 @@ class grade_outcome extends grade_object {
      * Array of required table fields, must start with 'id'.
      * @var array $required_fields
      */
-    public $required_fields = array('id', 'courseid', 'shortname', 'fullname', 'scaleid',
-                                 'description', 'timecreated', 'timemodified', 'usermodified');
+    public $required_fields = array('id', 'courseid', 'shortname', 'fullname', 'scaleid','description',
+                                 'descriptionformat', 'timecreated', 'timemodified', 'usermodified');
 
     /**
      * The course this outcome belongs to.
@@ -95,7 +95,16 @@ class grade_outcome extends grade_object {
         if (!empty($this->courseid)) {
             $DB->delete_records('grade_outcomes_courses', array('outcomeid' => $this->id, 'courseid' => $this->courseid));
         }
-        return parent::delete($source);
+        if (parent::delete($source)) {
+            $context = get_context_instace(CONTEXT_SYSTEM);
+            $fs = get_file_storage();
+            $files = $fs->get_area_files($context->id, 'grade_outcome', $this->id);
+            foreach ($files as $file) {
+                $file->delete();
+            }
+            return true;
+        }
+        return false;
     }
 
     /**
@@ -260,6 +269,18 @@ class grade_outcome extends grade_object {
         return $this->shortname;
     }
 
+    /**
+     * Returns the formatted grade description with URL's converted
+     * @return string
+     */
+    public function get_description() {
+        $options = new stdClass;
+        $options->noclean = true;
+        $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+        $description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade_outcome', $this->id);
+        return format_text($description, $this->descriptionformat, $options);
+    }
+
     /**
      * Checks if outcome can be deleted.
      * @return boolean
index 4b317c9..8eb72b0 100644 (file)
@@ -40,7 +40,7 @@ class grade_scale extends grade_object {
      * Array of required table fields, must start with 'id'.
      * @var array $required_fields
      */
-    public $required_fields = array('id', 'courseid', 'userid', 'name', 'scale', 'description', 'timemodified');
+    public $required_fields = array('id', 'courseid', 'userid', 'name', 'scale', 'description', 'descriptionformat', 'timemodified');
 
     /**
      * The course this scale belongs to.
@@ -119,6 +119,25 @@ class grade_scale extends grade_object {
         return parent::update($source);
     }
 
+    /**
+     * Deletes this outcome from the database.
+     * @param string $source from where was the object deleted (mod/forum, manual, etc.)
+     * @return boolean success
+     */
+    public function delete($source=null) {
+        global $DB;
+        if (parent::delete($source)) {
+            $context = get_context_instace(CONTEXT_SYSTEM);
+            $fs = get_file_storage();
+            $files = $fs->get_area_files($context->id, 'grade_scale', $this->id);
+            foreach ($files as $file) {
+                $file->delete();
+            }
+            return true;
+        }
+        return false;
+    }
+
     /**
      * Returns the most descriptive field for this object. This is a standard method used
      * when we do not know the exact type of an object.
@@ -286,4 +305,16 @@ class grade_scale extends grade_object {
 
         return false;
     }
+
+    /**
+     * Returns the formatted grade description with URL's converted
+     * @return string
+     */
+    public function get_description() {
+        $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+        $options = new stdClass;
+        $options->noclean = true;
+        $description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade_scale', $this->id);
+        return format_text($description, $this->descriptionformat, $options);
+    }
 }
index 28f597d..941be9b 100644 (file)
@@ -68,6 +68,8 @@ class message_output_email extends message_output {
             }
         }else{
             //delete what we've processed and check if can move message
+            $messageid = $message->id;
+            unset($message->id);
             if ( $DB->count_records('message_working', array('unreadmessageid' => $messageid)) == 0){
                 if ($DB->insert_record('message_read', $message)) {
                     $DB->delete_records('message', array('id' => $messageid));
index 40dc44e..6e8541c 100644 (file)
@@ -23,6 +23,7 @@
 
 require('../config.php');
 require('lib.php');
+require('send_form.php');
 
 require_login();
 
@@ -40,21 +41,10 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE
     $PAGE->set_title('send');
     $PAGE->requires->js('message/message.js');
 
-    echo $OUTPUT->header();
-
 /// Script parameters
     $userid   = required_param('id', PARAM_INT);
-    $message  = optional_param('message', '', PARAM_CLEANHTML);
-    $format   = optional_param('format', FORMAT_MOODLE, PARAM_INT);
 
-    $url = new moodle_url($CFG->wwwroot.'/message/send.php', array('id'=>$userid));
-    if ($message !== 0) {
-        $url->param('message', $message);
-    }
-    if ($format !== 0) {
-        $url->param('format', $format);
-    }
-    $PAGE->set_url($url);
+    $PAGE->set_url(new moodle_url($CFG->wwwroot.'/message/send.php', array('id'=>$userid)));
 
 /// Check the user we are talking to is valid
     if (! $user = $DB->get_record('user', array('id'=>$userid))) {
@@ -64,6 +54,7 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE
 /// Check that the user is not blocking us!!
     if ($contact = $DB->get_record('message_contacts', array('userid'=>$user->id, 'contactid'=>$USER->id))) {
         if ($contact->blocked and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) {
+            echo $OUTPUT->header();
             echo $OUTPUT->heading(get_string('userisblockingyou', 'message'), 1);
             echo $OUTPUT->footer();
             exit;
@@ -73,22 +64,39 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE
 
     if (!empty($userpreferences['message_blocknoncontacts'])) {  // User is blocking non-contacts
         if (empty($contact)) {   // We are not a contact!
+            echo $OUTPUT->header();
             echo $OUTPUT->heading(get_string('userisblockingyounoncontact', 'message'), 1);
             echo $OUTPUT->footer();
             exit;
         }
     }
 
-    if ($message!='' and confirm_sesskey()) {   /// Current user has just sent a message
+    $mform = new send_form();
+    $defaultmessage = new stdClass;
+    $defaultmessage->id = $userid;
+    $defaultmessage->message = '';
+    if (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0)) {
+        $defaultmessage->messageformat = FORMAT_HTML;
+    } else {
+        $defaultmessage->messageformat = FORMAT_MOODLE;
+    }
+    $mform->set_data($defaultmessage);
+
+    echo $OUTPUT->header();
+    if ($data = $mform->get_data()) {   /// Current user has just sent a message
+
+        if (!confirm_sesskey()) {
+            print_error('invalidsesskey');
+        }
 
         /// Save it to the database...
-        $messageid = message_post_message($USER, $user, $message, $format, 'direct');
+        $messageid = message_post_message($USER, $user, $data->message, $data->messageformat, 'direct');
 
         /// Format the message as HTML
-        $options = NULL;
+        $options = new stdClass;
         $options->para = false;
         $options->newlines = true;
-        $message = format_text($message, $format, $options);
+        $message = format_text($data->message, $data->messageformat, $options);
 
         $time = userdate(time(), get_string('strftimedatetimeshort'));
         $message = '<div class="message me"><span class="author">'.fullname($USER).'</span> '.
@@ -99,33 +107,20 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE
         $PAGE->requires->js_function_call('parent.messages.scroll', Array(1,5000000));
 
         add_to_log(SITEID, 'message', 'write', 'history.php?user1='.$user->id.'&amp;user2='.$USER->id.'#m'.$messageid, $user->id);
+        echo $OUTPUT->notification(get_string('mailsent', 'message'), 'notifysuccess');
+        $mform->reset_message();
     }
 
-    echo '<form id="editing" method="post" action="send.php">';
-    echo '<div class="message-form">';
-    echo '<input type="hidden" name="id" value="'.$user->id.'" />';
-    echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-
-    $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
-    if ($usehtmleditor) {
-        echo '<div class="message-send-box">';
-        print_textarea($usehtmleditor, 5, 34, 0, 0, 'message', '', 0, false, '', 'form-textarea-simple');
-        echo '</div>';
-        echo '<input class="message-send-button" type="submit" value="'.get_string('sendmessage', 'message').'" />';
-        echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
-    } else {
-        print_textarea(false, 5, 34, 0, 0, 'message', '');
-        echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE.'" />';
-        echo '<br /><input class="message-send-button" type="submit" value="'.get_string('sendmessage', 'message').'" />';
-    }
-    echo '</div>';
-    echo '</form>';
-    if (!empty($CFG->messagewasjustemailed)) {
-        $OUTPUT->notifcation(get_string('mailsent', 'message'), 'notifysuccess');
-    }
-    echo '<div class="noframesjslink"><a target="_parent" href="discussion.php?id='.$userid.'&amp;noframesjs=1">'.get_string('noframesjs', 'message').'</a></div>';
+    $mform->display();
+    echo $OUTPUT->box_start('noframesjslink');
+    $accesslink = new html_link();
+    $accesslink->url = new moodle_url($CFG->wwwroot.'/message/discussion.php', array('id'=>$userid, 'noframesjs'=>1));
+    $accesslink->text = get_string('noframesjs', 'message');
+    $accesslink->add_action(new breakout_of_frame_action());
+    echo $OUTPUT->link($accesslink);
+    echo $OUTPUT->box_end();
 
-    $PAGE->requires->js_function_call('set_focus', Array('edit-message'));
+    $PAGE->requires->js_function_call('set_focus', Array('id_message_editor'));
 
     echo $OUTPUT->footer();
 }
\ No newline at end of file
diff --git a/message/send_form.php b/message/send_form.php
new file mode 100644 (file)
index 0000000..e9d12f1
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+require_once($CFG->dirroot.'/lib/formslib.php');
+
+class send_form extends moodleform {
+
+    function definition () {
+
+        $mform =& $this->_form;
+
+        $editoroptions = array('maxfiles'=>0, 'maxbytes'=>0, 'trusttext'=>false);
+
+        $mform->addElement('hidden', 'id');
+        $mform->setType('id', PARAM_INT);
+
+        $systemcontext   = get_context_instance(CONTEXT_SYSTEM);
+
+        $mform->addElement('html', '<div class="message-send-box">');
+        $mform->addElement('editor', 'message_editor', get_string('message', 'message'), null, $editoroptions);
+        $mform->addElement('html', '</div>');
+
+        $this->add_action_buttons(false, get_string('sendmessage', 'message'));
+
+    }
+
+    /**
+     * Used to structure incoming data for the message editor component
+     *
+     * @param <type> $data
+     */
+    function set_data($data) {
+
+        $data->message = array('text'=>$data->message, 'format'=>$data->messageformat);
+
+        parent::set_data($data);
+    }
+
+    /**
+     * Used to reformat the data from the editor component
+     *
+     * @return stdClass
+     */
+    function get_data() {
+        $data = parent::get_data();
+
+        if ($data !== null) {
+            $data->messageformat = $data->message_editor['format'];
+            $data->message = clean_text($data->message_editor['text'], $data->messageformat);
+        }
+
+        return $data;
+    }
+
+    /**
+     * Resets the value of the message
+     *
+     * This is used because after we have acted on the submitted content we want to
+     * re-display the form but with an empty message so the user can type the next
+     * thing into it
+     */
+    function reset_message() {
+        $this->_form->_elements[$this->_form->_elementIndex['message_editor']]->setValue(array('text'=>''));
+    }
+
+}
+
+?>
\ No newline at end of file
index 4869525..d33a23e 100644 (file)
@@ -102,6 +102,36 @@ if ($context->contextlevel == CONTEXT_SYSTEM) {
         }
 
         send_stored_file($file, 10*60, 0, true); // download MUST be forced - security!
+    } else if ($filearea === 'grade_outcome' || $filearea === 'grade_scale') { // CONTEXT_SYSTEM
+        if ($CFG->forcelogin) {
+            require_login();
+        }
+
+        $fullpath = $context->id.$filearea.implode('/', $args);
+
+        if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
+            send_file_not_found();
+        }
+
+        session_get_instance()->write_close(); // unlock session during fileserving
+        send_stored_file($file, 60*60, 0, $forcedownload); // TODO: change timeout?
+
+    } else if ($filearea === 'tag_description') { // CONTEXT_SYSTEM
+
+        // All tag descriptions are going to be public but we still need to respect forcelogin
+        if ($CFG->forcelogin) {
+            require_login();
+        }
+
+        $fullpath = $context->id.$filearea.implode('/', $args);
+
+        if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
+            send_file_not_found();
+        }
+
+        session_get_instance()->write_close(); // unlock session during fileserving
+        send_stored_file($file, 60*60, 0, true); // TODO: change timeout?
+
     } else if ($filearea === 'calendar_event_description') { // CONTEXT_SYSTEM
 
         // All events here are public the one requirement is that we respect forcelogin
@@ -155,6 +185,54 @@ if ($context->contextlevel == CONTEXT_SYSTEM) {
 
         session_get_instance()->write_close(); // unlock session during fileserving
         send_stored_file($file, 60*60, 0, $forcedownload); // TODO: change timeout?
+    } else if ($filearea === 'user_profile') { // CONTEXT_USER
+
+        if ($CFG->forcelogin) {
+            require_login();
+        }
+
+        $userid = array_shift($args);
+        if ((int)$userid <= 0) {
+            send_file_not_found();
+        }
+
+        if (!empty($CFG->forceloginforprofiles)) {
+            require_login();
+            if (isguestuser()) {
+                send_file_not_found();
+            }
+
+            if ($USER->id !== $userid) {
+                $usercontext = get_context_instance(CONTEXT_USER, $userid);
+                // The browsing user is not the current user
+                if (!isteacherinanycourse() && !isteacherinanycourse($userid) && !has_capability('moodle/user:viewdetails', $usercontext)) {
+                    send_file_not_found();
+                }
+
+                $canview = false;
+                if (has_capability('moodle/user:viewdetails', $usercontext)) {
+                    $canview = true;
+                } else {
+                    $courses = get_my_courses($USER->id);
+                }
+
+                while (!$canview && count($courses) > 0) {
+                    $course = array_shift($courses);
+                    if (has_capability('moodle/user:viewdetails', get_context_instance(CONTEXT_COURSE, $course->id))) {
+                        $canview = true;
+                    }
+                }
+            }
+        }
+
+        $fullpath = $context->id.$filearea.$userid.'/'.implode('/', $args);
+
+        if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
+            send_file_not_found();
+        }
+
+        session_get_instance()->write_close(); // unlock session during fileserving
+        send_stored_file($file, 60*60, 0, true);
     }
 
     send_file_not_found();
@@ -215,6 +293,36 @@ if ($context->contextlevel == CONTEXT_SYSTEM) {
         session_get_instance()->write_close(); // unlock session during fileserving
         send_stored_file($file, 60*60, 0, false); // TODO: change timeout?
 
+    } else if ($filearea === 'course_summary') {
+
+        if ($CFG->forcelogin) {
+            require_login();
+        }
+
+        $fullpath = $context->id.$filearea.implode('/', $args);
+        
+        if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
+            send_file_not_found();
+        }
+
+        session_get_instance()->write_close(); // unlock session during fileserving
+        send_stored_file($file, 60*60, 0, $forcedownload); // TODO: change timeout?
+
+    } else if ($filearea === 'course_grade_tree_feedback') {
+
+        if ($CFG->forcelogin || $course->id !== SITEID) {
+            require_login($course);
+        }
+
+        $fullpath = $context->id.$filearea.implode('/', $args);
+
+        if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
+            send_file_not_found();
+        }
+
+        session_get_instance()->write_close(); // unlock session during fileserving
+        send_stored_file($file, 60*60, 0, $forcedownload); // TODO: change timeout?
+
     } else if ($filearea === 'calendar_event_description') { // CONTEXT_COURSE
 
         // This is for content used in course and group events
index 094b1ab..b4f4a20 100644 (file)
@@ -68,7 +68,7 @@ if ($courseid) {
 $PAGE->navbar->add($title);
 $PAGE->set_title($title);
 echo $OUTPUT->header();
-echo $OUTPUT->heading($title, 'centre');
+echo $OUTPUT->heading($title, 2, 'centre');
 
 // Prepare data for tags
 $courselink = '';
index 742e352..64a6e54 100644 (file)
@@ -53,19 +53,21 @@ if (can_use_html_editor()) {
 
 $errorstring = '';
 
-$tagform = new tag_edit_form();
+$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false);
+$tag = file_prepare_standard_editor($tag, 'description', $editoroptions, $systemcontext, 'tag_description', $tag->id);
+
+$tagform = new tag_edit_form(null, compact('editoroptions'));
 if ( $tag->tagtype == 'official' ) {
     $tag->tagtype = '1';
 } else {
     $tag->tagtype = '0';
 }
+
 $tagform->set_data($tag);
 
 // If new data has been sent, update the tag record
 if ($tagnew = $tagform->get_data()) {
 
-    tag_description_set($tag_id, $tagnew->description, $tagnew->descriptionformat);
-
     if (has_capability('moodle/tag:manage', $systemcontext)) {
         if (($tag->tagtype != 'default') && (!isset($tagnew->tagtype) || ($tagnew->tagtype != '1'))) {
             tag_type_set($tag->id, 'default');
@@ -91,6 +93,10 @@ if ($tagnew = $tagform->get_data()) {
 
     if (empty($errorstring)) {    // All is OK, let's save it
 
+        $tagnew = file_postupdate_standard_editor($tagnew, 'description', $editoroptions, $systemcontext, 'tag_description', $tag->id);
+        
+        tag_description_set($tag_id, $tagnew->description, $tagnew->descriptionformat);
+
         $tagnew->timemodified = time();
 
         if (has_capability('moodle/tag:manage', $systemcontext)) {
index 67396f6..7d318a6 100644 (file)
@@ -20,9 +20,7 @@ class tag_edit_form extends moodleform {
                     'maxlength="'.TAG_MAX_LENGTH.'" size="'.TAG_MAX_LENGTH.'"');
         }
 
-        $mform->addElement('htmleditor', 'description', get_string('description', 'tag'), array('rows'=>20));
-
-        $mform->addElement('format', 'descriptionformat', get_string('format'));
+        $mform->addElement('editor', 'description_editor', get_string('description', 'tag'), null, $this->_customdata['editoroptions']);
 
         if (has_capability('moodle/tag:manage', $systemcontext)) {
            $mform->addElement('checkbox', 'tagtype', get_string('officialtag', 'tag'));
index 1ac1628..9f82ea2 100644 (file)
@@ -520,6 +520,7 @@ function tag_delete($tagids) {
     }
 
     $success = true;
+    $context = get_context_instance(CONTEXT_SYSTEM);
     foreach( $tagids as $tagid ) {
         if (is_null($tagid)) { // can happen if tag doesn't exists
             continue;
@@ -529,6 +530,12 @@ function tag_delete($tagids) {
         // is the reason for not using $DB->delete_records_select()
         if ($DB->delete_records('tag_instance', array('tagid'=>$tagid)) ) {
             $success &= (bool) $DB->delete_records('tag', array('id'=>$tagid));
+            // Delete all files associated with this tag
+            $fs = get_file_storage();
+            $files = $fs->get_area_files($context->id, 'tag_description', $tagid);
+            foreach ($files as $file) {
+                $file->delete();
+            }
         }
     }
 
index 36f3017..58e5e0d 100644 (file)
@@ -115,6 +115,7 @@ function tag_print_description_box($tag_object, $return=false) {
     if (!empty($tag_object->description)) {
         $options = new object();
         $options->para = false;
+        $tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', get_context_instance(CONTEXT_SYSTEM)->id, 'tag_description', $tag_object->id);
         $output .= format_text($tag_object->description, $tag_object->descriptionformat, $options);
     }
 
index c539fed..1ca1663 100644 (file)
@@ -129,8 +129,10 @@ useredit_load_preferences($user);
 profile_load_data($user);
 
 
-//create form
-$userform = new user_edit_form();
+// Prepare the editor and create form
+$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'forcehttps'=>false);
+$user = file_prepare_standard_editor($user, 'description', $editoroptions, $personalcontext, 'user_profile', $user->id);
+$userform = new user_edit_form(null, array('editoroptions'=>$editoroptions));
 if (empty($user->country)) {
     // MDL-16308 - we must unset the value here so $CFG->country can be used as default one
     unset($user->country);
@@ -163,6 +165,7 @@ if ($usernew = $userform->get_data()) {
     $authplugin = get_auth_plugin($user->auth);
 
     $usernew->timemodified = time();
+    $usernew = file_postupdate_standard_editor($usernew, 'description', $editoroptions, $personalcontext, 'user_profile', $usernew->id);
 
     $DB->update_record('user', $usernew);
 
@@ -236,14 +239,6 @@ $streditmyprofile = get_string('editmyprofile');
 $strparticipants  = get_string('participants');
 $userfullname     = fullname($user, true);
 
-$link = null;
-if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
-    $link = new moodle_url($CFG->wwwroot."/user/index.php", array('id'=>$course->id));
-}
-$PAGE->navbar->add($strparticipants, $link);
-$link = new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$user->id, 'course'=>$course->id));
-$PAGE->navbar->add($userfullname, $link);
-$PAGE->navbar->add($streditmyprofile);
 $PAGE->set_title("$course->shortname: $streditmyprofile");
 $PAGE->set_heading($course->fullname);
 
index 5e9d9c3..ad7d910 100644 (file)
@@ -1,4 +1,4 @@
-<?php //$Id$
+<?php
 
 require_once($CFG->dirroot.'/lib/formslib.php');
 
@@ -9,6 +9,11 @@ class user_edit_form extends moodleform {
         global $CFG, $COURSE;
 
         $mform =& $this->_form;
+        if (is_array($this->_customdata) && array_key_exists('editoroptions', $this->_customdata)) {
+            $editoroptions = $this->_customdata['editoroptions'];
+        } else {
+            $editoroptions = null;
+        }
         //Accessibility: "Required" is bad legend text.
         $strgeneral  = get_string('general');
         $strrequired = get_string('required');
@@ -23,10 +28,10 @@ class user_edit_form extends moodleform {
         $mform->addElement('header', 'moodle', $strgeneral);
 
         /// shared fields
-        useredit_shared_definition($mform);
+        useredit_shared_definition($mform, $editoroptions);
 
         /// extra settigs
-        $mform->addRule('description', $strrequired, 'required', null, 'client');
+        $mform->addRule('description_editor', $strrequired, 'required', null, 'client');
         if (!empty($CFG->gdversion) and !empty($CFG->disableuserimages)) {
             $mform->removeElement('deletepicture');
             $mform->removeElement('imagefile');
@@ -67,7 +72,7 @@ class user_edit_form extends moodleform {
 
             // remove description
             if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid'=>$userid))) {
-                $mform->removeElement('description');
+                $mform->removeElement('description_editor');
             }
 
             // print picture
index 3a13f9f..2acce58 100644 (file)
@@ -113,8 +113,17 @@ if (!empty($CFG->usetags)) {
     $user->interests = tag_get_tags_array('user', $id);
 }
 
+if ($user->id !== -1) {
+    $user->context = get_context_instance(CONTEXT_USER, $user->id);
+    $editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'forcehttps'=>false);
+    $user = file_prepare_standard_editor($user, 'description', $editoroptions, $user->context, 'user_profile', $user->id);
+} else {
+    // This is a new user, we don't want to add files here
+    $editoroptions = array('maxfiles'=>0, 'maxbytes'=>0, 'trusttext'=>false, 'forcehttps'=>false);
+}
+
 //create form
-$userform = new user_editadvanced_form();
+$userform = new user_editadvanced_form(null, array('editoroptions'=>$editoroptions));
 $userform->set_data($user);
 
 if ($usernew = $userform->get_data()) {
@@ -134,6 +143,7 @@ if ($usernew = $userform->get_data()) {
     if ($usernew->id == -1) {
         //TODO check out if it makes sense to create account with this auth plugin and what to do with the password
         unset($usernew->id);
+        $usernew = file_postupdate_standard_editor($usernew, 'description', $editoroptions, null, 'user_profile', null);
         $usernew->mnethostid = $CFG->mnet_localhost_id; // always local user
         $usernew->confirmed  = 1;
         $usernew->password = hash_internal_user_password($usernew->newpassword);
@@ -141,6 +151,7 @@ if ($usernew = $userform->get_data()) {
         $usercreated = true;
 
     } else {
+        $usernew = file_postupdate_standard_editor($usernew, 'description', $editoroptions, $user->context, 'user_profile', $usernew->id);
         $DB->update_record('user', $usernew);
         // pass a true $userold here
         if (! $authplugin->user_update($user, $userform->get_data())) {
index 69e3954..4ad5d59 100644 (file)
@@ -9,6 +9,13 @@ class user_editadvanced_form extends moodleform {
         global $USER, $CFG, $COURSE;
 
         $mform =& $this->_form;
+
+        if (is_array($this->_customdata) && array_key_exists('editoroptions', $this->_customdata)) {
+            $editoroptions = $this->_customdata['editoroptions'];
+        } else {
+            $editoroptions = null;
+        }
+
         //Accessibility: "Required" is bad legend text.
         $strgeneral  = get_string('general');
         $strrequired = get_string('required');
@@ -42,7 +49,7 @@ class user_editadvanced_form extends moodleform {
         $mform->addElement('advcheckbox', 'preference_auth_forcepasswordchange', get_string('forcepasswordchange'));
         $mform->setHelpButton('preference_auth_forcepasswordchange',array('forcepasswordchange', get_string('forcepasswordchange')));
         /// shared fields
-        useredit_shared_definition($mform);
+        useredit_shared_definition($mform, $editoroptions);
 
         /// Next the customisable profile fields
         profile_definition($mform);
index adb6de2..2d012ee 100644 (file)
@@ -1,4 +1,4 @@
-<?php  //$Id$
+<?php
 
 function cancel_email_update($userid) {
     unset_user_preference('newemail', $userid);
@@ -74,7 +74,7 @@ function useredit_update_interests($user, $interests) {
     tag_set('user', $user->id, $interests);
 }
 
-function useredit_shared_definition(&$mform) {
+function useredit_shared_definition(&$mform, $editoroptions = null) {
     global $CFG, $USER, $DB;
 
     $user = $DB->get_record('user', array('id' => $USER->id));
@@ -228,9 +228,9 @@ function useredit_shared_definition(&$mform) {
         $mform->setAdvanced('theme');
     }
 
-    $mform->addElement('htmleditor', 'description', get_string('userdescription'));
-    $mform->setType('description', PARAM_CLEAN);
-    $mform->setHelpButton('description', array('text2', get_string('helptext')));
+    $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions);
+    $mform->setType('description_editor', PARAM_CLEANHTML);
+    $mform->setHelpButton('description_editor', array('text2', get_string('helptext')));
 
     if (!empty($CFG->gdversion)) {
         $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend
index 8a24aa7..0569fb4 100644 (file)
 
                     $contentheading .= '&nbsp;' . $OUTPUT->action_icon($editgroupaction);
                 }
-                $contentcell->text = $OUTPUT->heading($contentheading, 3) . format_text($group->description);
+
+                $group->description = file_rewrite_pluginfile_urls($group->description, 'pluginfile.php', $context->id, 'course_group_description', $group->id);
+                if (!isset($group->descriptionformat)) {
+                    $group->descriptionformat = FORMAT_MOODLE;
+                }
+                $contentcell->text = $OUTPUT->heading($contentheading, 3) . format_text($group->description, $group->descriptionformat);
                 $groupinfotable->data[] = html_table_row::make(array($picturecell, $contentcell));
                 echo $OUTPUT->table($groupinfotable);
             }
index d34177f..1cbaa51 100644 (file)
@@ -1,4 +1,4 @@
-<?php  //$Id$
+<?php
 
 class profile_define_base {
 
@@ -31,7 +31,7 @@ class profile_define_base {
         $form->addRule('name', $strrequired, 'required', null, 'client');
         $form->setType('name', PARAM_MULTILANG);
 
-        $form->addElement('htmleditor', 'description', get_string('profiledescription', 'admin'));
+        $form->addElement('editor', 'description', get_string('profiledescription', 'admin'), null, null);
         $form->setHelpButton('description', array('text2', get_string('helptext')));
 
         $form->addElement('selectyesno', 'required', get_string('profilerequired', 'admin'));
@@ -174,6 +174,17 @@ class profile_define_base {
         return $data;
     }
 
+    /**
+     * Provides a method by which we can allow the default data in profile_define_*
+     * to use an editor
+     *
+     * This should return an array of editor names (which will need to be formatted/cleaned)
+     *
+     * @return array
+     */
+    function define_editors() {
+        return array();
+    }
 }
 
 
@@ -447,15 +458,35 @@ function profile_edit_category($id, $redirect) {
 }
 
 function profile_edit_field($id, $datatype, $redirect) {
-    global $CFG, $DB, $OUTPUT;
+    global $CFG, $DB, $OUTPUT, $PAGE;
 
     if (!$field = $DB->get_record('user_info_field', array('id'=>$id))) {
         $field = new object();
         $field->datatype = $datatype;
+        $field->description = '';
+        $field->descriptionformat = FORMAT_HTML;
+        $field->defaultdata = '';
+        $field->defaultdataformat = FORMAT_HTML;
     }
 
+
+    // Clean and prepare description for the editor
+    $field->description = clean_text($field->description, $field->descriptionformat);
+    $field->description = array('text'=>$field->description, 'format'=>$field->descriptionformat, 'itemid'=>0);
+
     require_once('index_field_form.php');
     $fieldform = new field_form(null, $field->datatype);
+
+    // Convert the data format for
+    if (is_array($fieldform->editors())) {
+        foreach ($fieldform->editors() as $editor) {
+            if (isset($field->$editor)) {
+                $field->$editor = clean_text($field->$editor, $field->{$editor.'format'});
+                $field->$editor = array('text'=>$field->$editor, 'format'=>$field->{$editor.'format'}, 'itemid'=>0);
+            }
+        }
+    }
+
     $fieldform->set_data($field);
 
     if ($fieldform->is_cancelled()) {
@@ -466,6 +497,30 @@ function profile_edit_field($id, $datatype, $redirect) {
             require_once($CFG->dirroot.'/user/profile/field/'.$datatype.'/define.class.php');
             $newfield = 'profile_define_'.$datatype;
             $formfield = new $newfield();
+
+            // Collect the description and format back into the proper data structure from the editor
+            // Note: This field will ALWAYS be an editor
+            $data->descriptionformat = $data->description['format'];
+            $data->description = $data->description['text'];
+
+            // Check whether the default data is an editor, this is (currently) only the
+            // textarea field type
+            if (is_array($data->defaultdata) && array_key_exists('text', $data->defaultdata)) {
+                // Collect the default data and format back into the proper data structure from the editor
+                $data->defaultdataformat = $data->defaultdata['format'];
+                $data->defaultdata = $data->defaultdata['text'];
+            }
+
+            // Convert the data format for
+            if (is_array($fieldform->editors())) {
+                foreach ($fieldform->editors() as $editor) {
+                    if (isset($field->$editor)) {
+                        $field->{$editor.'format'} = $field->{$editor}['format'];
+                        $field->$editor = $field->{$editor}['text'];
+                    }
+                }
+            }
+
             $formfield->define_save($data);
             profile_reorder_fields();
             profile_reorder_categories();
@@ -481,6 +536,7 @@ function profile_edit_field($id, $datatype, $redirect) {
         }
 
         /// Print the page
+        $PAGE->navbar->add($strheading);
         admin_externalpage_print_header();
         echo $OUTPUT->heading($strheading);
         $fieldform->display();
index f35f6de..44dc79c 100644 (file)
@@ -1,21 +1,15 @@
-<?php  //$Id$
+<?php
 
 class profile_define_textarea extends profile_define_base {
 
     function define_form_specific(&$form) {
         /// Default data
-        $form->addElement('htmleditor', 'defaultdata', get_string('profiledefaultdata', 'admin'));
+        $form->addElement('editor', 'defaultdata', get_string('profiledefaultdata', 'admin'));
         $form->setType('defaultdata', PARAM_CLEAN);
+    }
 
-        /// Param 1 for textarea type is the number of columns
-        $form->addElement('text', 'param1', get_string('profilefieldcolumns', 'admin'), 'size="6"');
-        $form->setDefault('param1', 30);
-        $form->setType('param1', PARAM_INT);
-
-        /// Param 2 for text type is the number of rows
-        $form->addElement('text', 'param2', get_string('profilefieldrows', 'admin'), 'size="6"');
-        $form->setDefault('param2', 10);
-        $form->setType('param2', PARAM_INT);
+    function define_editors() {
+        return array('defaultdata');
     }
 
 }
index 956c092..d4e243b 100644 (file)
@@ -1,4 +1,4 @@
-<?php //$Id$
+<?php
 
 class profile_field_textarea extends profile_field_base {
 
@@ -7,7 +7,7 @@ class profile_field_textarea extends profile_field_base {
         $rows = $this->field->param2;
 
         /// Create the form field
-        $mform->addElement('htmleditor', $this->inputname, format_string($this->field->name), array('cols'=>$cols, 'rows'=>$rows));
+        $mform->addElement('editor', $this->inputname, format_string($this->field->name), null, null);
         $mform->setType($this->inputname, PARAM_CLEAN);
     }
 
@@ -17,6 +17,28 @@ class profile_field_textarea extends profile_field_base {
         return false;
     }
 
+    function edit_save_data_preprocess($data, &$datarecord) {
+        if (is_array($data)) {
+            $datarecord->dataformat = $data['format'];
+            $data = $data['text'];
+        }
+        return $data;
+    }
+
+    function edit_load_user_data(&$user) {
+        if ($this->data !== NULL) {
+            $this->data = clean_text($this->data, $this->dataformat);
+            $user->{$this->inputname} = array('text'=>$this->data, 'format'=>$this->dataformat);
+        }
+    }
+
+    /**
+     * Display the data for this field
+     */
+    function display_data() {
+        return format_text($this->data, $this->dataformat, new stdClass());
+    }
+
 }
 
 ?>
index 1ec39aa..82157a2 100644 (file)
@@ -1,4 +1,4 @@
-<?php //$Id$
+<?php
 
 require('../../config.php');
 require_once($CFG->libdir.'/adminlib.php');
@@ -72,8 +72,10 @@ switch ($action) {
         //ask for confirmation
         $datacount = $DB->count_records('user_info_data', array('fieldid'=>$id));
         $optionsyes = array ('id'=>$id, 'confirm'=>1, 'action'=>'deletefield', 'sesskey'=>sesskey());
+        $strheading = get_string('profiledeletefield', 'admin');
+        $PAGE->navbar->add($strheading);
         admin_externalpage_print_header();
-        echo $OUTPUT->heading('profiledeletefield', 'admin');
+        echo $OUTPUT->heading($strheading);
         $formcontinue = html_form::make_button($redirect, $optionsyes, get_string('yes'), 'post');
         $formcancel = html_form::make_button($redirect, array(), get_string('no'), 'get');
         echo $OUTPUT->confirm(get_string('profileconfirmfielddeletion', 'admin', $datacount), $formcontinue, $formcancel);
index e61848a..f00dd0e 100644 (file)
@@ -45,6 +45,10 @@ class field_form extends moodleform {
     function validation($data, $files) {
         return $this->field->define_validate($data, $files);
     }
+
+    function editors() {
+        return $this->field->define_editors();
+    }
 }
 
 ?>
index ca99fe1..b3cfbb7 100644 (file)
@@ -1,4 +1,4 @@
-<?php //$Id$
+<?php
 
 /// Some constants
 
@@ -21,6 +21,7 @@ class profile_field_base {
     var $field;
     var $inputname;
     var $data;
+    var $dataformat;
 
     /**
      * Constructor method.
@@ -103,10 +104,11 @@ class profile_field_base {
             // field not present in form, probably locked and invisible - skip it
             return;
         }
-        
-        $usernew->{$this->inputname} = $this->edit_save_data_preprocess($usernew->{$this->inputname});
 
         $data = new object();
+        
+        $usernew->{$this->inputname} = $this->edit_save_data_preprocess($usernew->{$this->inputname}, $data);
+
         $data->userid  = $usernew->id;
         $data->fieldid = $this->field->id;
         $data->data    = $usernew->{$this->inputname};
@@ -175,9 +177,10 @@ class profile_field_base {
     /**
      * Hook for child classess to process the data before it gets saved in database
      * @param   mixed
+     * @param   stdClass The object that will be used to save the record
      * @return  mixed
      */
-    function edit_save_data_preprocess($data) {
+    function edit_save_data_preprocess($data, &$datarecord) {
         return $data;
     }
 
@@ -238,10 +241,12 @@ class profile_field_base {
         }
 
         if (!empty($this->field)) {
-            if ($datafield = $DB->get_field('user_info_data', 'data', array('userid'=>$this->userid, 'fieldid'=>$this->fieldid))) {
-                $this->data = $datafield;
+            if ($data = $DB->get_record('user_info_data', array('userid'=>$this->userid, 'fieldid'=>$this->fieldid), 'data, dataformat')) {
+                $this->data = $data->data;
+                $this->dataformat = $data->dataformat;
             } else {
                 $this->data = $this->field->defaultdata;
+                $this->dataformat = FORMAT_HTML;
             }
         } else {
             $this->data = NULL;
index 3b70fb1..580efd4 100644 (file)
@@ -259,7 +259,9 @@ if ($user->description && !isset($hiddenfields['description'])) {
     if (!$has_courseid && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid'=>$id))) {
         echo get_string('profilenotshown', 'moodle').'<hr />';
     } else {
-        echo format_text($user->description, FORMAT_MOODLE)."<hr />";
+        
+        $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user_profile', $id);
+        echo format_text($user->description, $user->descriptionformat)."<hr />";
     }
 }
 
index 4aa5fa4..3033494 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 = 2009103000;  // YYYYMMDD   = date of the last version bump
+    $version = 2009110400;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20091104)';  // Human-friendly version name