|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); 00028 require_once(dirname(__FILE__).'/locallib.php'); 00029 00030 $cmid = required_param('cmid', PARAM_INT); // course module id 00031 $id = required_param('id', PARAM_INT); // example submission id, 0 for the new one 00032 $edit = optional_param('edit', false, PARAM_BOOL); // open for editing? 00033 $delete = optional_param('delete', false, PARAM_BOOL); // example removal requested 00034 $confirm = optional_param('confirm', false, PARAM_BOOL); // example removal request confirmed 00035 $assess = optional_param('assess', false, PARAM_BOOL); // assessment required 00036 00037 $cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST); 00038 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); 00039 00040 require_login($course, false, $cm); 00041 if (isguestuser()) { 00042 print_error('guestsarenotallowed'); 00043 } 00044 00045 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST); 00046 $workshop = new workshop($workshop, $cm, $course); 00047 00048 $PAGE->set_url($workshop->exsubmission_url($id), array('edit' => $edit)); 00049 $PAGE->set_title($workshop->name); 00050 $PAGE->set_heading($course->fullname); 00051 if ($edit) { 00052 $PAGE->navbar->add(get_string('exampleediting', 'workshop')); 00053 } else { 00054 $PAGE->navbar->add(get_string('example', 'workshop')); 00055 } 00056 $output = $PAGE->get_renderer('mod_workshop'); 00057 00058 if ($id) { // example is specified 00059 $example = $workshop->get_example_by_id($id); 00060 $workshop->log('view example', $workshop->exsubmission_url($example->id), $example->id); 00061 00062 } else { // no example specified - create new one 00063 require_capability('mod/workshop:manageexamples', $workshop->context); 00064 $example = new stdclass(); 00065 $example->id = null; 00066 $example->authorid = $USER->id; 00067 $example->example = 1; 00068 } 00069 00070 $canmanage = has_capability('mod/workshop:manageexamples', $workshop->context); 00071 $canassess = has_capability('mod/workshop:peerassess', $workshop->context); 00072 $refasid = $DB->get_field('workshop_assessments', 'id', array('submissionid' => $example->id, 'weight' => 1)); 00073 00074 if ($example->id and ($canmanage or ($workshop->assessing_examples_allowed() and $canassess))) { 00075 // ok you can go 00076 } elseif (is_null($example->id) and $canmanage) { 00077 // ok you can go 00078 } else { 00079 print_error('nopermissions', 'error', $workshop->view_url(), 'view or manage example submission'); 00080 } 00081 00082 if ($id and $delete and $confirm and $canmanage) { 00083 require_sesskey(); 00084 $workshop->delete_submission($example); 00085 redirect($workshop->view_url()); 00086 } 00087 00088 if ($id and $assess and $canmanage) { 00089 // reference assessment of an example is the assessment with the weight = 1. There should be just one 00090 // such assessment 00091 require_sesskey(); 00092 if (!$refasid) { 00093 $refasid = $workshop->add_allocation($example, $USER->id, 1); 00094 } 00095 redirect($workshop->exassess_url($refasid)); 00096 } 00097 00098 if ($id and $assess and $canassess) { 00099 // training assessment of an example is the assessment with the weight = 0 00100 require_sesskey(); 00101 $asid = $DB->get_field('workshop_assessments', 'id', 00102 array('submissionid' => $example->id, 'weight' => 0, 'reviewerid' => $USER->id)); 00103 if (!$asid) { 00104 $asid = $workshop->add_allocation($example, $USER->id, 0); 00105 } 00106 if ($asid == workshop::ALLOCATION_EXISTS) { 00107 // the training assessment of the example was not found but the allocation already 00108 // exists. this probably means that the user is the author of the reference assessment. 00109 echo $output->header(); 00110 echo $output->box(get_string('assessmentreferenceconflict', 'workshop')); 00111 echo $output->continue_button($workshop->view_url()); 00112 echo $output->footer(); 00113 die(); 00114 } 00115 redirect($workshop->exassess_url($asid)); 00116 } 00117 00118 if ($edit and $canmanage) { 00119 require_once(dirname(__FILE__).'/submission_form.php'); 00120 00121 $maxfiles = $workshop->nattachments; 00122 $maxbytes = $workshop->maxbytes; 00123 $contentopts = array( 00124 'trusttext' => true, 00125 'subdirs' => false, 00126 'maxfiles' => $maxfiles, 00127 'maxbytes' => $maxbytes, 00128 'context' => $workshop->context 00129 ); 00130 00131 $attachmentopts = array('subdirs' => true, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes); 00132 $example = file_prepare_standard_editor($example, 'content', $contentopts, $workshop->context, 00133 'mod_workshop', 'submission_content', $example->id); 00134 $example = file_prepare_standard_filemanager($example, 'attachment', $attachmentopts, $workshop->context, 00135 'mod_workshop', 'submission_attachment', $example->id); 00136 00137 $mform = new workshop_submission_form($PAGE->url, array('current' => $example, 'workshop' => $workshop, 00138 'contentopts' => $contentopts, 'attachmentopts' => $attachmentopts)); 00139 00140 if ($mform->is_cancelled()) { 00141 redirect($workshop->view_url()); 00142 00143 } elseif ($canmanage and $formdata = $mform->get_data()) { 00144 if ($formdata->example == 1) { 00145 // this was used just for validation, it must be set to one when dealing with example submissions 00146 unset($formdata->example); 00147 } else { 00148 throw new coding_exception('Invalid submission form data value: example'); 00149 } 00150 $timenow = time(); 00151 if (is_null($example->id)) { 00152 $formdata->workshopid = $workshop->id; 00153 $formdata->example = 1; 00154 $formdata->authorid = $USER->id; 00155 $formdata->timecreated = $timenow; 00156 $formdata->feedbackauthorformat = editors_get_preferred_format(); 00157 } 00158 $formdata->timemodified = $timenow; 00159 $formdata->title = trim($formdata->title); 00160 $formdata->content = ''; // updated later 00161 $formdata->contentformat = FORMAT_HTML; // updated later 00162 $formdata->contenttrust = 0; // updated later 00163 if (is_null($example->id)) { 00164 $example->id = $formdata->id = $DB->insert_record('workshop_submissions', $formdata); 00165 $workshop->log('add example', $workshop->exsubmission_url($example->id), $example->id); 00166 } else { 00167 $workshop->log('update example', $workshop->exsubmission_url($example->id), $example->id); 00168 if (empty($formdata->id) or empty($example->id) or ($formdata->id != $example->id)) { 00169 throw new moodle_exception('err_examplesubmissionid', 'workshop'); 00170 } 00171 } 00172 // save and relink embedded images and save attachments 00173 $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $workshop->context, 00174 'mod_workshop', 'submission_content', $example->id); 00175 $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $workshop->context, 00176 'mod_workshop', 'submission_attachment', $example->id); 00177 if (empty($formdata->attachment)) { 00178 // explicit cast to zero integer 00179 $formdata->attachment = 0; 00180 } 00181 // store the updated values or re-save the new example (re-saving needed because URLs are now rewritten) 00182 $DB->update_record('workshop_submissions', $formdata); 00183 redirect($workshop->exsubmission_url($formdata->id)); 00184 } 00185 } 00186 00187 // Output starts here 00188 echo $output->header(); 00189 echo $output->heading(format_string($workshop->name), 2); 00190 00191 // show instructions for submitting as they may contain some list of questions and we need to know them 00192 // while reading the submitted answer 00193 if (trim($workshop->instructauthors)) { 00194 $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id, 00195 'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($PAGE->context)); 00196 print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop')); 00197 echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv'=>true)), array('generalbox', 'instructions')); 00198 print_collapsible_region_end(); 00199 } 00200 00201 // if in edit mode, display the form to edit the example 00202 if ($edit and $canmanage) { 00203 $mform->display(); 00204 echo $output->footer(); 00205 die(); 00206 } 00207 00208 // else display the example... 00209 if ($example->id) { 00210 if ($canmanage and $delete) { 00211 echo $output->confirm(get_string('exampledeleteconfirm', 'workshop'), 00212 new moodle_url($PAGE->url, array('delete' => 1, 'confirm' => 1)), $workshop->view_url()); 00213 } 00214 if ($canmanage and !$delete and !$DB->record_exists_select('workshop_assessments', 00215 'grade IS NOT NULL AND weight=1 AND submissionid = ?', array($example->id))) { 00216 echo $output->confirm(get_string('assessmentreferenceneeded', 'workshop'), 00217 new moodle_url($PAGE->url, array('assess' => 1)), $workshop->view_url()); 00218 } 00219 echo $output->render($workshop->prepare_example_submission($example)); 00220 } 00221 // ...with an option to edit or remove it 00222 echo $output->container_start('buttonsbar'); 00223 if ($canmanage) { 00224 if (empty($edit) and empty($delete)) { 00225 $aurl = new moodle_url($workshop->exsubmission_url($example->id), array('edit' => 'on')); 00226 echo $output->single_button($aurl, get_string('exampleedit', 'workshop'), 'get'); 00227 00228 $aurl = new moodle_url($workshop->exsubmission_url($example->id), array('delete' => 'on')); 00229 echo $output->single_button($aurl, get_string('exampledelete', 'workshop'), 'get'); 00230 } 00231 } 00232 // ...and optionally assess it 00233 if ($canassess or ($canmanage and empty($edit) and empty($delete))) { 00234 $aurl = new moodle_url($workshop->exsubmission_url($example->id), array('assess' => 'on', 'sesskey' => sesskey())); 00235 echo $output->single_button($aurl, get_string('exampleassess', 'workshop'), 'get'); 00236 } 00237 echo $output->container_end(); // buttonsbar 00238 // and possibly display the example's review(s) - todo 00239 echo $output->footer();