From 8bdc9cacad8192dafc9787b55130dc98717fd815 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Wed, 4 Nov 2009 06:14:06 +0000 Subject: [PATCH] files MDL-20601 Conversion of many of the uses of print_textarea, and the mforms htmleditor to the new editor 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. --- admin/report/spamcleaner/index.php | 6 +- admin/uploaduser.php | 2 +- admin/uploaduser_form.php | 21 +- .../course_summary/block_course_summary.php | 4 +- calendar/lib.php | 6 +- course/category.php | 8 +- course/edit.php | 33 +- course/edit_form.php | 35 +- course/editcategory.php | 25 +- course/editcategory_form.php | 9 +- course/format/topics/format.php | 377 ++++++++-------- course/info.php | 3 +- course/lib.php | 417 +++++++++++++++++- course/pending.php | 282 +++++------- course/request.php | 57 +-- course/request_form.php | 10 +- course/scales.php | 8 + course/search.php | 7 + grade/edit/outcome/edit.php | 21 +- grade/edit/outcome/edit_form.php | 2 +- grade/edit/outcome/export.php | 4 +- grade/edit/scale/edit.php | 16 +- grade/edit/scale/edit_form.php | 3 +- grade/edit/tree/grade.php | 10 +- grade/edit/tree/grade_form.php | 7 +- group/group.php | 11 +- group/group_form.php | 19 +- group/grouping.php | 19 +- group/grouping_form.php | 14 +- group/lib.php | 74 +++- group/overview.php | 10 +- lib/db/install.xml | 55 ++- lib/db/upgrade.php | 40 ++ lib/grade/grade_outcome.php | 27 +- lib/grade/grade_scale.php | 33 +- message/output/email/message_output_email.php | 2 + message/send.php | 75 ++-- message/send_form.php | 67 +++ pluginfile.php | 108 +++++ tag/coursetags_more.php | 2 +- tag/edit.php | 12 +- tag/edit_form.php | 4 +- tag/lib.php | 7 + tag/locallib.php | 1 + user/edit.php | 15 +- user/edit_form.php | 13 +- user/editadvanced.php | 13 +- user/editadvanced_form.php | 9 +- user/editlib.php | 10 +- user/index.php | 7 +- user/profile/definelib.php | 62 ++- user/profile/field/textarea/define.class.php | 16 +- user/profile/field/textarea/field.class.php | 26 +- user/profile/index.php | 6 +- user/profile/index_field_form.php | 4 + user/profile/lib.php | 17 +- user/view.php | 4 +- version.php | 2 +- 58 files changed, 1532 insertions(+), 625 deletions(-) create mode 100644 message/send_form.php diff --git a/admin/report/spamcleaner/index.php b/admin/report/spamcleaner/index.php index 724bfe3e67..478a56d139 100755 --- a/admin/report/spamcleaner/index.php +++ b/admin/report/spamcleaner/index.php @@ -265,7 +265,11 @@ function print_user_entry($user, $keywords, $count) { $user->description = highlight($keyword, $user->description); } - $html .= ''.format_text($user->description, FORMAT_MOODLE).''; + if (!isset($user->descriptionformat)) { + $user->descriptionformat = FORMAT_MOODLE; + } + + $html .= ''.format_text($user->description, $user->descriptionformat).''; $html .= ''; $html .= '
'; $html .= ''; diff --git a/admin/uploaduser.php b/admin/uploaduser.php index 944e1fdb84..1b4ad9a75f 100755 --- a/admin/uploaduser.php +++ b/admin/uploaduser.php @@ -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(); diff --git a/admin/uploaduser_form.php b/admin/uploaduser_form.php index ecb2d974a4..19da95500a 100644 --- a/admin/uploaduser_form.php +++ b/admin/uploaduser_form.php @@ -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; + } } diff --git a/blocks/course_summary/block_course_summary.php b/blocks/course_summary/block_course_summary.php index e99914215f..5605632e49 100644 --- a/blocks/course_summary/block_course_summary.php +++ b/blocks/course_summary/block_course_summary.php @@ -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'; diff --git a/calendar/lib.php b/calendar/lib.php index 281b019fe9..1102ada551 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -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 ''; echo '
'; if (!empty($event->icon)) { @@ -571,7 +574,8 @@ function calendar_print_event($event, $showactions=true) { } else { echo ''; } - echo format_text($event->description, FORMAT_HTML); + + echo $event->description; if (calendar_edit_event_allowed($event) && $showactions) { echo '
'; $calendarcourseid = ''; diff --git a/course/category.php b/course/category.php index b34e98784e..50034cdcb4 100644 --- a/course/category.php +++ b/course/category.php @@ -191,7 +191,13 @@ /// 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(); } diff --git a/course/edit.php b/course/edit.php index 70c1ef9014..ffe46964b3 100644 --- a/course/edit.php +++ b/course/edit.php @@ -1,4 +1,4 @@ -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)) { @@ -60,12 +61,15 @@ } $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); } @@ -84,13 +88,22 @@ //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); @@ -109,6 +122,8 @@ } } 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'); } @@ -126,7 +141,7 @@ $stradministration = get_string("administration"); $strcategories = get_string("categories"); - if (!empty($course)) { + if (!empty($course->id)) { $PAGE->navbar->add($streditcoursesettings); $title = $streditcoursesettings; $fullname = $course->fullname; @@ -148,4 +163,4 @@ echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/course/edit_form.php b/course/edit_form.php index fc4a3ab595..859178188c 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -1,4 +1,4 @@ -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 diff --git a/course/editcategory.php b/course/editcategory.php index cf2a48e15c..522cc28350 100644 --- a/course/editcategory.php +++ b/course/editcategory.php @@ -1,4 +1,4 @@ -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'); } diff --git a/course/editcategory_form.php b/course/editcategory_form.php index 2973e92773..8da5a95803 100644 --- a/course/editcategory_form.php +++ b/course/editcategory_form.php @@ -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); diff --git a/course/format/topics/format.php b/course/format/topics/format.php index 09f59b900b..a3b20eb2de 100644 --- a/course/format/topics/format.php +++ b/course/format/topics/format.php @@ -1,6 +1,7 @@ -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 "
    \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 '
  • '; + echo $stractivityclipboard.'  ('.$strcancel.')'; + echo "
  • \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 '
  • '; + echo '
     
    '; + echo '
     
    '; + echo '
    '; + echo '
    '; + + $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 ''.$streditsummary.''; + } + echo '
    '; - // Note, an ordered list would confuse - "1" could be the clipboard or summary. - echo "
      \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 '
    • '; - echo $stractivityclipboard.'  ('.$strcancel.')'; - echo "
    • \n"; + if ($PAGE->user_is_editing()) { + print_section_add_menus($course, $section, $modnames); } -/// Print Section 0 with general activities + echo '
    '; + echo "
  • \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 '
  • '; - echo '
     
    '; - echo '
     
    '; - echo '
    '; - echo '
    '; - - $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 ''.$streditsummary.''; - } - echo '
    '; - - 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 '
    '; - echo "
  • \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 '
  • '; //'
     
    '; + + echo '
    '.$currenttext.$section.'
    '; + // Note, 'right side' is BEFORE content. + echo '
    '; + + if ($displaysection == $section) { // Show the zoom boxes + echo ''. + ''.$strshowalltopics.'
    '; + } else { + $strshowonlytopic = get_string("showonlytopic", "", $section); + echo ''. + ''.$strshowonlytopic.'
    '; } - 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 ''.''.$strmarkedthistopic.'
    '; + } else { + echo ''.''.$strmarkthistopic.'
    '; + } - $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 ''. + ''.$strtopichide.'
    '; } else { - $sectionstyle = ''; + echo ''. + ''.$strtopicshow.'
    '; + } + if ($section > 1) { // Add a arrow to move section up + echo ''. + ''.$strmoveup.'
    '; } - echo '
  • '; //'
     
    '; + if ($section < $course->numsections) { // Add a arrow to move section down + echo ''. + ''.$strmovedown.'
    '; + } + } + echo '
'; - echo '
'.$currenttext.$section.'
'; - // Note, 'right side' is BEFORE content. - echo '
'; - - if ($displaysection == $section) { // Show the zoom boxes - echo ''. - ''.$strshowalltopics.'
'; + echo '
'; + if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students + echo get_string('notavailable').'
'; + } else { + echo '
'; + $summaryformatoptions->noclean = true; + if ($thissection->summary) { + echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions); } else { - $strshowonlytopic = get_string("showonlytopic", "", $section); - echo ''. - ''.$strshowonlytopic.'
'; + echo ' '; } 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 ''.''.$strmarkedthistopic.'
'; - } else { - echo ''.''.$strmarkthistopic.'
'; - } - - if ($thissection->visible) { // Show the hide/show eye - echo ''. - ''.$strtopichide.'
'; - } else { - echo ''. - ''.$strtopicshow.'
'; - } - if ($section > 1) { // Add a arrow to move section up - echo ''. - ''.$strmoveup.'
'; - } - - if ($section < $course->numsections) { // Add a arrow to move section down - echo ''. - ''.$strmovedown.'
'; - } + echo ' '. + ''.$streditsummary.'

'; } echo '
'; - echo '
'; - if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students - echo get_string('notavailable').'
'; - } else { - echo '
'; - $summaryformatoptions->noclean = true; - if ($thissection->summary) { - echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions); - } else { - echo ' '; - } - - if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) { - echo ' '. - ''.$streditsummary.'

'; - } - echo '
'; - - print_section($course, $thissection, $mods, $modnamesused); - echo '
'; - if ($PAGE->user_is_editing()) { - print_section_add_menus($course, $section, $modnames); - } + print_section($course, $thissection, $mods, $modnamesused); + echo '
'; + if ($PAGE->user_is_editing()) { + print_section_add_menus($course, $section, $modnames); } - - echo '
'; - echo "\n"; } - $section++; - } - echo "\n"; - - if (!empty($sectionmenu)) { - echo '
'; - $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 '
'; + echo "\n"; } + + $section++; +} +echo "\n"; + +if (!empty($sectionmenu)) { + echo '
'; + $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 '
'; +} diff --git a/course/info.php b/course/info.php index 51fe0346e9..2570956c3c 100644 --- a/course/info.php +++ b/course/info.php @@ -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); diff --git a/course/lib.php b/course/lib.php index 3e2beca1e8..44eaf7f3bb 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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 '
'; @@ -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 '
'; echo ''; } @@ -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 diff --git a/course/pending.php b/course/pending.php index d9dfefa401..f931f4e71b 100644 --- a/course/pending.php +++ b/course/pending.php @@ -1,4 +1,4 @@ -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(' ', 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[] = ''.$strrequireskey.''; - } 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(' ', 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 diff --git a/course/request.php b/course/request.php index d7b52c002f..518b7d6b16 100644 --- a/course/request.php +++ b/course/request.php @@ -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 diff --git a/course/request_form.php b/course/request_form.php index d084fffd02..5fc5da7cb9 100644 --- a/course/request_form.php +++ b/course/request_form.php @@ -1,4 +1,4 @@ -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); diff --git a/course/scales.php b/course/scales.php index d93415c57a..38139bd6ff 100644 --- a/course/scales.php +++ b/course/scales.php @@ -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(); diff --git a/course/search.php b/course/search.php index 738f1119dc..763fed0e31 100644 --- a/course/search.php +++ b/course/search.php @@ -227,6 +227,13 @@ if (!$adminediting) { foreach ($courses as $course) { + + if (isset($course->context)) { + $coursecontext = $course->context; + } else { + $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + } + $course->summary .= "

"; $course->summary .= "$strcategory: category\">"; $course->summary .= $displaylist[$course->category]; diff --git a/grade/edit/outcome/edit.php b/grade/edit/outcome/edit.php index d5a3e1102e..a56abd6a44 100644 --- a/grade/edit/outcome/edit.php +++ b/grade/edit/outcome/edit.php @@ -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 { diff --git a/grade/edit/outcome/edit_form.php b/grade/edit/outcome/edit_form.php index 3983b87f04..71e93bb9a6 100644 --- a/grade/edit/outcome/edit_form.php +++ b/grade/edit/outcome/edit_form.php @@ -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 diff --git a/grade/edit/outcome/export.php b/grade/edit/outcome/export.php index 5d226c1490..e1ce6b0fa7 100644 --- a/grade/edit/outcome/export.php +++ b/grade/edit/outcome/export.php @@ -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, ';', '"'); } diff --git a/grade/edit/scale/edit.php b/grade/edit/scale/edit.php index f958760041..e8d3b6f1b4 100644 --- a/grade/edit/scale/edit.php +++ b/grade/edit/scale/edit.php @@ -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 { diff --git a/grade/edit/scale/edit_form.php b/grade/edit/scale/edit_form.php index be72751482..7879856f04 100644 --- a/grade/edit/scale/edit_form.php +++ b/grade/edit/scale/edit_form.php @@ -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); diff --git a/grade/edit/tree/grade.php b/grade/edit/tree/grade.php index c5333354ea..299ebe5c81 100644 --- a/grade/edit/tree/grade.php +++ b/grade/edit/tree/grade.php @@ -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 diff --git a/grade/edit/tree/grade_form.php b/grade/edit/tree/grade_form.php index c2f7c3408f..63cdd01480 100755 --- a/grade/edit/tree/grade_form.php +++ b/grade/edit/tree/grade_form.php @@ -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'); diff --git a/group/group.php b/group/group.php index ed5d4c920d..4e35548246 100644 --- a/group/group.php +++ b/group/group.php @@ -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()) { diff --git a/group/group_form.php b/group/group_form.php index e99511df3b..3d038030a2 100644 --- a/group/group_form.php +++ b/group/group_form.php @@ -1,5 +1,15 @@ 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']; + } } diff --git a/group/grouping.php b/group/grouping.php index d7ffbce74b..dbea9fcc01 100644 --- a/group/grouping.php +++ b/group/grouping.php @@ -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 diff --git a/group/grouping_form.php b/group/grouping_form.php index 2d986f8f82..98d7a947f0 100644 --- a/group/grouping_form.php +++ b/group/grouping_form.php @@ -1,4 +1,13 @@ 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); diff --git a/group/lib.php b/group/lib.php index 0dc59a461f..ddf2242367 100644 --- a/group/lib.php +++ b/group/lib.php @@ -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); diff --git a/group/overview.php b/group/overview.php index c6a5ae6934..9e407690a1 100644 --- a/group/overview.php +++ b/group/overview.php @@ -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); diff --git a/lib/db/install.xml b/lib/db/install.xml index 4b8ae9da58..53cb9b029d 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -75,8 +75,9 @@ - - + + + @@ -124,8 +125,9 @@ - - + + + @@ -258,8 +260,9 @@ - - + + + @@ -589,8 +592,9 @@ - - + + + @@ -656,8 +660,9 @@ - - + + + @@ -1044,16 +1049,18 @@ - - + + + - - + + + @@ -1078,7 +1085,8 @@ - + + @@ -1440,8 +1448,9 @@ - - + + + @@ -1797,8 +1806,9 @@ - - + + + @@ -1814,8 +1824,9 @@ - - + + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 1d500961dd..1daa312761 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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, '%', 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; } diff --git a/lib/grade/grade_outcome.php b/lib/grade/grade_outcome.php index 2cb6a3cf45..5d9396f8c3 100644 --- a/lib/grade/grade_outcome.php +++ b/lib/grade/grade_outcome.php @@ -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 diff --git a/lib/grade/grade_scale.php b/lib/grade/grade_scale.php index 4b317c97bf..8eb72b068b 100644 --- a/lib/grade/grade_scale.php +++ b/lib/grade/grade_scale.php @@ -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); + } } diff --git a/message/output/email/message_output_email.php b/message/output/email/message_output_email.php index 28f597d249..941be9b6f5 100644 --- a/message/output/email/message_output_email.php +++ b/message/output/email/message_output_email.php @@ -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)); diff --git a/message/send.php b/message/send.php index 40dc44ea90..6e8541c107 100644 --- a/message/send.php +++ b/message/send.php @@ -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 = '

'.fullname($USER).' '. @@ -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.'&user2='.$USER->id.'#m'.$messageid, $user->id); + echo $OUTPUT->notification(get_string('mailsent', 'message'), 'notifysuccess'); + $mform->reset_message(); } - echo '
'; - echo '
'; - echo ''; - echo ''; - - $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0)); - if ($usehtmleditor) { - echo '
'; - print_textarea($usehtmleditor, 5, 34, 0, 0, 'message', '', 0, false, '', 'form-textarea-simple'); - echo '
'; - echo ''; - echo ''; - } else { - print_textarea(false, 5, 34, 0, 0, 'message', ''); - echo ''; - echo '
'; - } - echo '
'; - echo '
'; - if (!empty($CFG->messagewasjustemailed)) { - $OUTPUT->notifcation(get_string('mailsent', 'message'), 'notifysuccess'); - } - echo '
'; + $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 index 0000000000..e9d12f14f0 --- /dev/null +++ b/message/send_form.php @@ -0,0 +1,67 @@ +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', '
'); + $mform->addElement('editor', 'message_editor', get_string('message', 'message'), null, $editoroptions); + $mform->addElement('html', '
'); + + $this->add_action_buttons(false, get_string('sendmessage', 'message')); + + } + + /** + * Used to structure incoming data for the message editor component + * + * @param $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 diff --git a/pluginfile.php b/pluginfile.php index 4869525c55..d33a23ebc6 100644 --- a/pluginfile.php +++ b/pluginfile.php @@ -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 diff --git a/tag/coursetags_more.php b/tag/coursetags_more.php index 094b1ab10c..b4f4a204e6 100644 --- a/tag/coursetags_more.php +++ b/tag/coursetags_more.php @@ -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 = ''; diff --git a/tag/edit.php b/tag/edit.php index 742e352009..64a6e549cb 100644 --- a/tag/edit.php +++ b/tag/edit.php @@ -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)) { diff --git a/tag/edit_form.php b/tag/edit_form.php index 67396f6071..7d318a66e3 100644 --- a/tag/edit_form.php +++ b/tag/edit_form.php @@ -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')); diff --git a/tag/lib.php b/tag/lib.php index 1ac16289fc..9f82ea2fc0 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -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(); + } } } diff --git a/tag/locallib.php b/tag/locallib.php index 36f30178fc..58e5e0d534 100644 --- a/tag/locallib.php +++ b/tag/locallib.php @@ -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); } diff --git a/user/edit.php b/user/edit.php index c539fed742..1ca1663725 100644 --- a/user/edit.php +++ b/user/edit.php @@ -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); diff --git a/user/edit_form.php b/user/edit_form.php index 5e9d9c370d..ad7d910699 100644 --- a/user/edit_form.php +++ b/user/edit_form.php @@ -1,4 +1,4 @@ -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 diff --git a/user/editadvanced.php b/user/editadvanced.php index 3a13f9f591..2acce585aa 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -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())) { diff --git a/user/editadvanced_form.php b/user/editadvanced_form.php index 69e39549ff..4ad5d59139 100644 --- a/user/editadvanced_form.php +++ b/user/editadvanced_form.php @@ -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); diff --git a/user/editlib.php b/user/editlib.php index adb6de252c..2d012ee3c3 100644 --- a/user/editlib.php +++ b/user/editlib.php @@ -1,4 +1,4 @@ -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 diff --git a/user/index.php b/user/index.php index 8a24aa7abe..0569fb46de 100644 --- a/user/index.php +++ b/user/index.php @@ -348,7 +348,12 @@ $contentheading .= ' ' . $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); } diff --git a/user/profile/definelib.php b/user/profile/definelib.php index d34177fed8..1cbaa51f26 100644 --- a/user/profile/definelib.php +++ b/user/profile/definelib.php @@ -1,4 +1,4 @@ -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(); diff --git a/user/profile/field/textarea/define.class.php b/user/profile/field/textarea/define.class.php index f35f6dedc9..44dc79c39d 100644 --- a/user/profile/field/textarea/define.class.php +++ b/user/profile/field/textarea/define.class.php @@ -1,21 +1,15 @@ -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'); } } diff --git a/user/profile/field/textarea/field.class.php b/user/profile/field/textarea/field.class.php index 956c092cbe..d4e243b4ca 100644 --- a/user/profile/field/textarea/field.class.php +++ b/user/profile/field/textarea/field.class.php @@ -1,4 +1,4 @@ -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()); + } + } ?> diff --git a/user/profile/index.php b/user/profile/index.php index 1ec39aa8d0..82157a2078 100644 --- a/user/profile/index.php +++ b/user/profile/index.php @@ -1,4 +1,4 @@ -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); diff --git a/user/profile/index_field_form.php b/user/profile/index_field_form.php index e61848a09e..f00dd0e406 100644 --- a/user/profile/index_field_form.php +++ b/user/profile/index_field_form.php @@ -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(); + } } ?> diff --git a/user/profile/lib.php b/user/profile/lib.php index ca99fe1ac9..b3cfbb7132 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -1,4 +1,4 @@ -{$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; diff --git a/user/view.php b/user/view.php index 3b70fb19bf..580efd4846 100644 --- a/user/view.php +++ b/user/view.php @@ -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').'
'; } else { - echo format_text($user->description, FORMAT_MOODLE)."
"; + + $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user_profile', $id); + echo format_text($user->description, $user->descriptionformat)."
"; } } diff --git a/version.php b/version.php index 4aa5fa4e1c..3033494984 100644 --- a/version.php +++ b/version.php @@ -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 -- 2.39.5