PageRenderTime 21ms CodeModel.GetById 1ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/view.php

https://github.com/eviweb/moodle-mod_turnitintool
PHP | 424 lines | 349 code | 53 blank | 22 comment | 77 complexity | fda32eca1044ac21c520d61ebb08bbf8 MD5 | raw file
  1<?php
  2/**
  3 * @package   turnitintool
  4 * @copyright 2012 Turnitin
  5 */
  6
  7require_once("../../config.php");
  8require_once("lib.php");
  9require_once("../../lib/formslib.php");
 10require_once("../../lib/form/text.php");
 11require_once("../../lib/form/datetimeselector.php");
 12require_once("../../lib/form/hidden.php");
 13require_once("../../lib/form/button.php");
 14require_once("../../lib/form/submit.php");
 15if (!turnitintool_check_config()) {
 16    turnitintool_print_error('configureerror','turnitintool',NULL,NULL,__FILE__,__LINE__);
 17    exit();
 18}
 19$viewpage='view.php';
 20$viewpage .= (isset($_REQUEST['id'])) ? '?id='.$_REQUEST['id'] : '';
 21$viewpage .= (isset($_REQUEST['do'])) ? '&do='.$_REQUEST['do'] : '';
 22turnitintool_activitylog($viewpage,"REQUEST");
 23turnitintool_activitylog("lib.php Loaded","REQUIRE_ONCE");
 24require_once($CFG->dirroot."/lib/uploadlib.php");
 25turnitintool_activitylog("uploadlib.php Loaded","REQUIRE_ONCE");
 26
 27turnitintool_process_api_error();
 28
 29$id = required_param('id', PARAM_INT); // Course Module ID, or
 30$a  = optional_param('a', 0, PARAM_INT);  // turnitintool ID
 31
 32if ($id) {
 33    if (! $cm = get_coursemodule_from_id('turnitintool', $id)) {
 34        turnitintool_print_error("Course Module ID was incorrect");
 35    }
 36
 37    if (! $course = turnitintool_get_record("course", "id", $cm->course)) {
 38        turnitintool_print_error("Course is misconfigured");
 39    }
 40
 41    if (! $turnitintool = turnitintool_get_record("turnitintool", "id", $cm->instance)) {
 42        turnitintool_print_error("Course module is incorrect");
 43    }
 44
 45} else {
 46    if (! $turnitintool = turnitintool_get_record("turnitintool", "id", $a)) {
 47        turnitintool_print_error("Course module is incorrect");
 48    }
 49    if (! $course = turnitintool_get_record("course", "id", $turnitintool->course)) {
 50        turnitintool_print_error("Course is misconfigured");
 51    }
 52    if (! $cm = get_coursemodule_from_instance("turnitintool", $turnitintool->id, $course->id)) {
 53        turnitintool_print_error("Course Module ID was incorrect");
 54    }
 55}
 56
 57require_login($course->id);
 58
 59if (isset($PAGE) AND is_callable(array($PAGE->requires, 'js'))) { // Are we using new moodle or old?
 60    $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/jquery-1.7.2.min.js');
 61    $PAGE->requires->js($jsurl,true);
 62    $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.min.js');
 63    $PAGE->requires->js($jsurl);
 64    $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.plugins.js');
 65    $PAGE->requires->js($jsurl);
 66    $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/inboxtable.js');
 67    $PAGE->requires->js($jsurl);
 68    $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/turnitintool.js');
 69    $PAGE->requires->js($jsurl,true);
 70    $cssurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/styles.css');
 71    $PAGE->requires->css($cssurl);
 72} else {
 73    require_js($CFG->wwwroot.'/mod/turnitintool/scripts/jquery-1.7.2.min.js');
 74    require_js($CFG->wwwroot.'/mod/turnitintool/scripts/turnitintool.js');
 75}
 76turnitintool_activitylog("turnitintool.js Loaded","REQUIRE_JS");
 77
 78$param_jumppage=optional_param('jumppage',null,PARAM_CLEAN);
 79$param_userid=optional_param('userid',null,PARAM_CLEAN);
 80$param_post=optional_param('post',null,PARAM_CLEAN);
 81$param_delete=optional_param('delete',null,PARAM_CLEAN);
 82$param_update=optional_param('update',null,PARAM_CLEAN);
 83$param_do=optional_param('do',null,PARAM_CLEAN);
 84$param_enroll=optional_param('enroll',null,PARAM_CLEAN);
 85$param_owner=optional_param('owner',null,PARAM_CLEAN);
 86$param_anonid=optional_param('anonid',null,PARAM_CLEAN);
 87$param_updategrade=optional_param('updategrade',null,PARAM_CLEAN);
 88$param_up=optional_param('up',null,PARAM_CLEAN);
 89$param_submissiontype=optional_param('submissiontype',null,PARAM_CLEAN);
 90$param_submitted=optional_param('submitted',null,PARAM_CLEAN);
 91$param_delpart=optional_param('delpart',null,PARAM_CLEAN);
 92$param_unenrol=optional_param('unenrol',null,PARAM_CLEAN);
 93$param_enroltutor=optional_param('enroltutor',null,PARAM_CLEAN);
 94$param_s=optional_param('s',null,PARAM_CLEAN);
 95$param_ob=optional_param('ob',null,PARAM_CLEAN);
 96$param_sh=optional_param('sh',null,PARAM_CLEAN);
 97$param_fr=optional_param('fr',null,PARAM_CLEAN);
 98$param_export_data=optional_param('export_data',null,PARAM_CLEAN);
 99$param_objectid=optional_param('objectid',null,PARAM_CLEAN);
100$param_partid=optional_param('partid',null,PARAM_CLEAN);
101$param_utp=optional_param('utp',null,PARAM_CLEAN);
102$param_enrollstudent=optional_param('enrollstudent',null,PARAM_CLEAN);
103$param_reloadrow=optional_param('reloadrow',null,PARAM_CLEAN);
104
105// Clean the post array so we can pass it into the functions below
106$post = array();
107foreach ( $_POST as $key => $value ) {
108    // If 1.9 use clean_param to clean an array  / if 2.0 use clean_param_array
109    if ( is_array( $value ) AND is_callable( 'clean_param_array' ) ) {
110        $post[$key] = clean_param_array( $value, PARAM_CLEAN );
111    } else {
112        $post[$key] = clean_param( $value, PARAM_CLEAN );
113    }
114}
115
116if (!is_null($param_jumppage)) {
117    turnitintool_url_jumpto($param_userid,$param_jumppage,$turnitintool,$param_utp,$param_objectid,$param_partid,$param_export_data);
118    exit();
119}
120
121if (!is_null($param_delete)) {
122    if (!$submission = turnitintool_get_record('turnitintool_submissions','id',$param_delete)) {
123        print_error('submissiongeterror','turnitintool');
124        exit();
125    }
126    turnitintool_delete_submission($cm,$turnitintool,$USER->id,$submission);
127    exit();
128}
129
130$redirectlink=$CFG->wwwroot.'/mod/turnitintool/view.php?id='.$cm->id;
131$redirectlink.=(!is_null($param_do)) ? '&do='.$param_do : '&do=intro';
132$redirectlink.=(!is_null($param_fr)) ? '&fr='.$param_fr : '';
133$redirectlink.=(!is_null($param_sh)) ? '&sh='.$param_sh : '';
134$redirectlink.=(!is_null($param_ob)) ? '&ob='.$param_ob : '';
135
136if (!is_null($param_reloadrow)) {
137    turnitintool_reloadinbox_row($cm,$turnitintool,$param_reloadrow);
138    exit();
139}
140
141if (!is_null($param_update)) {
142    $loaderbar = new turnitintool_loaderbarclass(2);
143    turnitintool_update_all_report_scores($cm,$turnitintool,$param_update,$loaderbar);
144    turnitintool_redirect($redirectlink);
145    exit();
146}
147
148if (!is_null($param_enrollstudent)) {
149    turnitintool_enroll_student($cm,$turnitintool,$param_enrollstudent);
150}
151
152if (!is_null($param_enroll)) {
153    turnitintool_enroll_all_students($cm,$turnitintool);
154    turnitintool_redirect($redirectlink);
155    exit();
156}
157
158if (!is_null($param_do) AND $param_do=="tutors" AND !is_null($param_unenrol)) {
159    $tutors=turnitintool_remove_tiitutor($cm,$turnitintool,$param_unenrol);
160    if (!is_null($tutors->error)) {
161        $notice=$tutors->error;
162    } else {
163        turnitintool_redirect($CFG->wwwroot.'/mod/turnitintool/view.php?id='.$cm->id.'&do=tutors');
164        exit();
165    }
166}
167
168if (!is_null($param_do) AND $param_do=="tutors" AND !is_null($param_enroltutor)) {
169    $tutors=turnitintool_add_tiitutor($cm,$turnitintool,$param_enroltutor);
170    if (!is_null($tutors->error)) {
171        $notice=$tutors->error;
172    } else {
173        turnitintool_redirect($CFG->wwwroot.'/mod/turnitintool/view.php?id='.$cm->id.'&do=tutors');
174        exit();
175    }
176}
177
178if (!is_null($param_do) AND $param_do=="tutors" AND is_null($param_unenrol) AND is_null($param_enroltutor)) {
179    $tutors=turnitintool_get_tiitutors($cm,$turnitintool);
180    if (!is_null($tutors->error)) {
181        $notice=$tutors->error;
182    } else {
183        $notice=null;
184    }
185}
186
187if (!is_null($param_do) AND $param_do=="changeowner") {
188    turnitintool_ownerprocess($cm,$turnitintool,$param_owner);
189    turnitintool_redirect($CFG->wwwroot.'/mod/turnitintool/view.php?id='.$cm->id.'&do=tutors');
190    exit();
191}
192
193if (!is_null($param_do) AND $turnitintool->autoupdates==1 AND $param_do=="allsubmissions" AND !is_null($param_anonid)) {
194    $loaderbar = new turnitintool_loaderbarclass(3);
195    turnitintool_revealuser($cm,$turnitintool,$post,$loaderbar);
196    turnitintool_redirect($CFG->wwwroot.'/mod/turnitintool/view.php?id='.$cm->id.'&do=allsubmissions&update=1');
197    exit();
198}
199
200if (!is_null($param_updategrade) OR isset($post['updategrade']) OR isset($post["updategrade_x"])) {
201    turnitintool_update_form_grades($cm,$turnitintool,$post);
202}
203
204if (!is_null($param_up)) { // Manual Submission to Turnitin
205    if (!$submission = turnitintool_get_record('turnitintool_submissions','id',$param_up)) {
206        print_error('submissiongeterror','turnitintool');
207        exit();
208    }
209    turnitintool_upload_submission($cm,$turnitintool,$submission);
210    exit();
211}
212
213if (!is_null($param_submissiontype) AND $param_do=='submissions') {
214    if (isset($param_userid)) {
215        $thisuserid=$param_userid;
216    } else {
217        $thisuserid=$USER->id;
218    }
219
220    if ($param_submissiontype==1) {
221        $notice=turnitintool_dofileupload($cm,$turnitintool,$thisuserid,$post);
222    } else if ($param_submissiontype==2) {
223        $notice=turnitintool_dotextsubmission($cm,$turnitintool,$thisuserid,$post);
224    }
225    if ($turnitintool->autosubmission AND !empty($notice["subid"])) {
226        if (!$submission = turnitintool_get_record('turnitintool_submissions','id',$notice["subid"])) {
227            print_error('submissiongeterror','turnitintool');
228            exit();
229        }
230        turnitintool_upload_submission($cm,$turnitintool,$submission);
231        exit();
232    }
233}
234
235if (!is_null($param_submitted) AND $param_do=='intro') {
236    $notice=turnitintool_update_partnames($cm,$turnitintool,$post);
237}
238
239if (!is_null($param_delpart) AND $param_do=='intro') {
240    $notice=turnitintool_delete_part($cm,$turnitintool,$param_delpart);
241}
242
243if (!is_null($param_submitted) AND $param_do=='notes') {
244    $notice=turnitintool_process_notes($cm,$turnitintool,$param_s,$post);
245}
246
247if (!is_null($param_submitted) AND $param_do=='options') {
248    $notice=turnitintool_process_options($cm,$turnitintool,$post);
249}
250
251add_to_log($course->id, "turnitintool", "view", "view.php?id=$cm->id", "User viewed assignment '$turnitintool->name'", "$cm->id");
252
253/// Print the page header
254$strturnitintools = get_string("modulenameplural", "turnitintool");
255$strturnitintool  = get_string("modulename", "turnitintool");
256
257if (!is_callable('build_navigation')) {
258    $navigation = array(
259            array('title' => $course->shortname, 'url' => $CFG->wwwroot."/course/view.php?id=$course->id", 'type' => 'course'),
260            array('title' => $strturnitintools, 'url' => $CFG->wwwroot."/mod/turnitintool/index.php?id=$course->id", 'type' => 'activity'),
261            array('title' => format_string($turnitintool->name), 'url' => '', 'type' => 'activityinstance')
262    );
263} else {
264    $navigation = build_navigation('',$cm);
265}
266
267turnitintool_header($cm,
268        $course,
269        $_SERVER["REQUEST_URI"],
270        $turnitintool->name,
271        $SITE->fullname,
272        $navigation,
273        "",
274        "",
275        true,
276        update_module_button($cm->id, $course->id, $strturnitintool),
277        navmenu($course)
278);
279
280/// Check to see if groups are being used and abstract for 1.8 if neccessary
281if (!is_callable('groups_get_activity_group')) {
282    $changegroup = optional_param('group', -1, PARAM_INT);
283    $cm->currentgroup=get_and_set_current_group($course, $cm->groupmode, $changegroup);
284    setup_and_print_groups($course, $cm->groupmode, $redirectlink);
285} else {
286    $groupmode = groups_get_activity_groupmode($cm);
287    if ($groupmode) {
288        groups_get_activity_group($cm, true);
289        groups_print_activity_menu($cm, $redirectlink);
290    }
291}
292
293// Print the main part of the page
294echo '<div id="turnitintool_style">';
295
296if (!is_null($param_do)) {
297    $do=$param_do;
298} else {
299    $do='intro';
300}
301
302// $do=ACTION
303// $do=submissions >>> Student Submission Page
304// $do=intro >>> Turnitin Assignment Intro Page
305// $do=allsubmissions >>> Tutor View All Submissions
306// $do=bulkupload >>> Tutor Bulk Upload Student Submissions
307// $do=viewtext >>> View Student Text Submission
308// $do=submissiondetails >>> View Submission Details
309
310$studentdos=array('submissions','intro','viewtext','submissiondetails','notes');
311$graderdos=array('allsubmissions','options','changeowner','tutors');
312
313// If an unrecognised DO request produce error
314if (!in_array($do,$studentdos) AND !in_array($do,$graderdos)) {
315    turnitintool_print_error('dorequesterror','turnitintool');
316    exit();
317} else if (!has_capability('mod/turnitintool:grade', get_context_instance(CONTEXT_MODULE, $cm->id)) AND in_array($do,$graderdos)) {
318    turnitintool_print_error('permissiondeniederror','turnitintool');
319    exit();
320}
321
322echo '<br />';
323turnitintool_draw_menu($cm,$do);
324
325if ($do=='intro') {
326    if (isset($notice['error'])) {
327        turnitintool_box_start('generalbox boxwidthwide boxaligncenter error', 'errorbox');
328        echo $notice['message'];
329        turnitintool_box_end();
330    } else {
331        $notice=NULL;
332    }
333    // Update the GradeBook to make sure the grade stays 'hidden' until and wasn't revealed by modedit
334    turnitintool_grade_item_update( $turnitintool );
335    echo turnitintool_duplicatewarning($cm,$turnitintool);
336    echo turnitintool_introduction($cm,$turnitintool,$notice);
337}
338
339if ($do=='submissions') {
340    if ( !has_capability('mod/turnitintool:grade', get_context_instance(CONTEXT_MODULE, $cm->id)) 
341         AND !has_capability('mod/turnitintool:submit', get_context_instance(CONTEXT_MODULE, $cm->id))) {
342        turnitintool_print_error('permissiondeniederror','turnitintool');
343        exit();
344    } else {
345        echo turnitintool_view_student_submissions($cm,$turnitintool);
346        if (isset($notice["error"])) {
347            turnitintool_box_start('generalbox boxwidthwide boxaligncenter error', 'errorbox');
348            echo $notice["error"];
349            turnitintool_box_end();
350        }
351        echo turnitintool_view_submission_form($cm,$turnitintool);
352    }
353}
354
355if ($do=='allsubmissions') {
356    if (!empty($notice)) {
357        turnitintool_box_start('generalbox boxwidthwide boxaligncenter error', 'errorbox');
358        echo $notice;
359        turnitintool_box_end();
360    }
361    if (isset($param_ob)) {
362        $ob=$param_ob;
363    } else {
364        $ob=1;
365    }
366    echo turnitintool_view_all_submissions($cm,$turnitintool,$ob);
367}
368
369if ($do=='notes') {
370    echo turnitintool_view_notes($cm,$turnitintool,$param_s,$post);
371    if (isset($notice['error'])) {
372        turnitintool_box_start('generalbox boxwidthwide boxaligncenter error', 'errorbox');
373        echo $notice['message'];
374        turnitintool_box_end();
375    } else {
376        $notice=NULL;
377    }
378    echo turnitintool_addedit_notes($cm,$turnitintool,$param_s,$post,$notice);
379
380}
381
382if ($do=='options') {
383    if (!empty($notice)) {
384        turnitintool_box_start('generalbox boxwidthwide boxaligncenter', 'general');
385        echo $notice;
386        turnitintool_box_end();
387    }
388    echo turnitintool_view_options($cm,$turnitintool);
389}
390
391if ($do=='tutors') {
392    if (!is_null($notice)) {
393        turnitintool_box_start('generalbox boxwidthwide boxaligncenter error', 'errorbox');
394        echo $notice;
395        turnitintool_box_end();
396    } else {
397        echo turnitintool_view_tiitutors($cm,$turnitintool,$tutors);
398    }
399}
400
401// Finish the page
402echo '</div>';
403
404if (isset($PAGE) AND @is_callable(array($PAGE->requires, 'js'))) { // Are we using new moodle or old?
405    // We already added the Moodle 2.0+ stuff
406} else {
407    // These need to go to the botton here to avoid conflicts
408    require_js($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.min.js');
409    require_js($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.plugins.js');
410    require_js($CFG->wwwroot.'/mod/turnitintool/scripts/inboxtable.js');
411}
412
413turnitintool_footer($course);
414$module=turnitintool_get_record('modules','name','turnitintool');
415$parts=turnitintool_get_records('turnitintool_parts','turnitintoolid',$turnitintool->id);
416$parts_string="(";
417foreach ($parts as $part) {
418    $parts_string.=($parts_string!="(") ? " | " : "";
419    $parts_string.= $part->partname.': '.$part->tiiassignid;
420}
421$parts_string.=")";
422echo '<!-- Turnitin Moodle Direct Version: '.$module->version.' - '.$parts_string.' -->';
423
424/* ?> */