moodle-mod_turnitintool /view.php

Language PHP Lines 424
MD5 Hash fda32eca1044ac21c520d61ebb08bbf8
Repository https://github.com/eviweb/moodle-mod_turnitintool.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<?php
/**
 * @package   turnitintool
 * @copyright 2012 Turnitin
 */

require_once("../../config.php");
require_once("lib.php");
require_once("../../lib/formslib.php");
require_once("../../lib/form/text.php");
require_once("../../lib/form/datetimeselector.php");
require_once("../../lib/form/hidden.php");
require_once("../../lib/form/button.php");
require_once("../../lib/form/submit.php");
if (!turnitintool_check_config()) {
    turnitintool_print_error('configureerror','turnitintool',NULL,NULL,__FILE__,__LINE__);
    exit();
}
$viewpage='view.php';
$viewpage .= (isset($_REQUEST['id'])) ? '?id='.$_REQUEST['id'] : '';
$viewpage .= (isset($_REQUEST['do'])) ? '&do='.$_REQUEST['do'] : '';
turnitintool_activitylog($viewpage,"REQUEST");
turnitintool_activitylog("lib.php Loaded","REQUIRE_ONCE");
require_once($CFG->dirroot."/lib/uploadlib.php");
turnitintool_activitylog("uploadlib.php Loaded","REQUIRE_ONCE");

turnitintool_process_api_error();

$id = required_param('id', PARAM_INT); // Course Module ID, or
$a  = optional_param('a', 0, PARAM_INT);  // turnitintool ID

if ($id) {
    if (! $cm = get_coursemodule_from_id('turnitintool', $id)) {
        turnitintool_print_error("Course Module ID was incorrect");
    }

    if (! $course = turnitintool_get_record("course", "id", $cm->course)) {
        turnitintool_print_error("Course is misconfigured");
    }

    if (! $turnitintool = turnitintool_get_record("turnitintool", "id", $cm->instance)) {
        turnitintool_print_error("Course module is incorrect");
    }

} else {
    if (! $turnitintool = turnitintool_get_record("turnitintool", "id", $a)) {
        turnitintool_print_error("Course module is incorrect");
    }
    if (! $course = turnitintool_get_record("course", "id", $turnitintool->course)) {
        turnitintool_print_error("Course is misconfigured");
    }
    if (! $cm = get_coursemodule_from_instance("turnitintool", $turnitintool->id, $course->id)) {
        turnitintool_print_error("Course Module ID was incorrect");
    }
}

require_login($course->id);

if (isset($PAGE) AND is_callable(array($PAGE->requires, 'js'))) { // Are we using new moodle or old?
    $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/jquery-1.7.2.min.js');
    $PAGE->requires->js($jsurl,true);
    $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.min.js');
    $PAGE->requires->js($jsurl);
    $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.plugins.js');
    $PAGE->requires->js($jsurl);
    $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/inboxtable.js');
    $PAGE->requires->js($jsurl);
    $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/turnitintool.js');
    $PAGE->requires->js($jsurl,true);
    $cssurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/styles.css');
    $PAGE->requires->css($cssurl);
} else {
    require_js($CFG->wwwroot.'/mod/turnitintool/scripts/jquery-1.7.2.min.js');
    require_js($CFG->wwwroot.'/mod/turnitintool/scripts/turnitintool.js');
}
turnitintool_activitylog("turnitintool.js Loaded","REQUIRE_JS");

$param_jumppage=optional_param('jumppage',null,PARAM_CLEAN);
$param_userid=optional_param('userid',null,PARAM_CLEAN);
$param_post=optional_param('post',null,PARAM_CLEAN);
$param_delete=optional_param('delete',null,PARAM_CLEAN);
$param_update=optional_param('update',null,PARAM_CLEAN);
$param_do=optional_param('do',null,PARAM_CLEAN);
$param_enroll=optional_param('enroll',null,PARAM_CLEAN);
$param_owner=optional_param('owner',null,PARAM_CLEAN);
$param_anonid=optional_param('anonid',null,PARAM_CLEAN);
$param_updategrade=optional_param('updategrade',null,PARAM_CLEAN);
$param_up=optional_param('up',null,PARAM_CLEAN);
$param_submissiontype=optional_param('submissiontype',null,PARAM_CLEAN);
$param_submitted=optional_param('submitted',null,PARAM_CLEAN);
$param_delpart=optional_param('delpart',null,PARAM_CLEAN);
$param_unenrol=optional_param('unenrol',null,PARAM_CLEAN);
$param_enroltutor=optional_param('enroltutor',null,PARAM_CLEAN);
$param_s=optional_param('s',null,PARAM_CLEAN);
$param_ob=optional_param('ob',null,PARAM_CLEAN);
$param_sh=optional_param('sh',null,PARAM_CLEAN);
$param_fr=optional_param('fr',null,PARAM_CLEAN);
$param_export_data=optional_param('export_data',null,PARAM_CLEAN);
$param_objectid=optional_param('objectid',null,PARAM_CLEAN);
$param_partid=optional_param('partid',null,PARAM_CLEAN);
$param_utp=optional_param('utp',null,PARAM_CLEAN);
$param_enrollstudent=optional_param('enrollstudent',null,PARAM_CLEAN);
$param_reloadrow=optional_param('reloadrow',null,PARAM_CLEAN);

// Clean the post array so we can pass it into the functions below
$post = array();
foreach ( $_POST as $key => $value ) {
    // If 1.9 use clean_param to clean an array  / if 2.0 use clean_param_array
    if ( is_array( $value ) AND is_callable( 'clean_param_array' ) ) {
        $post[$key] = clean_param_array( $value, PARAM_CLEAN );
    } else {
        $post[$key] = clean_param( $value, PARAM_CLEAN );
    }
}

if (!is_null($param_jumppage)) {
    turnitintool_url_jumpto($param_userid,$param_jumppage,$turnitintool,$param_utp,$param_objectid,$param_partid,$param_export_data);
    exit();
}

if (!is_null($param_delete)) {
    if (!$submission = turnitintool_get_record('turnitintool_submissions','id',$param_delete)) {
        print_error('submissiongeterror','turnitintool');
        exit();
    }
    turnitintool_delete_submission($cm,$turnitintool,$USER->id,$submission);
    exit();
}

$redirectlink=$CFG->wwwroot.'/mod/turnitintool/view.php?id='.$cm->id;
$redirectlink.=(!is_null($param_do)) ? '&do='.$param_do : '&do=intro';
$redirectlink.=(!is_null($param_fr)) ? '&fr='.$param_fr : '';
$redirectlink.=(!is_null($param_sh)) ? '&sh='.$param_sh : '';
$redirectlink.=(!is_null($param_ob)) ? '&ob='.$param_ob : '';

if (!is_null($param_reloadrow)) {
    turnitintool_reloadinbox_row($cm,$turnitintool,$param_reloadrow);
    exit();
}

if (!is_null($param_update)) {
    $loaderbar = new turnitintool_loaderbarclass(2);
    turnitintool_update_all_report_scores($cm,$turnitintool,$param_update,$loaderbar);
    turnitintool_redirect($redirectlink);
    exit();
}

if (!is_null($param_enrollstudent)) {
    turnitintool_enroll_student($cm,$turnitintool,$param_enrollstudent);
}

if (!is_null($param_enroll)) {
    turnitintool_enroll_all_students($cm,$turnitintool);
    turnitintool_redirect($redirectlink);
    exit();
}

if (!is_null($param_do) AND $param_do=="tutors" AND !is_null($param_unenrol)) {
    $tutors=turnitintool_remove_tiitutor($cm,$turnitintool,$param_unenrol);
    if (!is_null($tutors->error)) {
        $notice=$tutors->error;
    } else {
        turnitintool_redirect($CFG->wwwroot.'/mod/turnitintool/view.php?id='.$cm->id.'&do=tutors');
        exit();
    }
}

if (!is_null($param_do) AND $param_do=="tutors" AND !is_null($param_enroltutor)) {
    $tutors=turnitintool_add_tiitutor($cm,$turnitintool,$param_enroltutor);
    if (!is_null($tutors->error)) {
        $notice=$tutors->error;
    } else {
        turnitintool_redirect($CFG->wwwroot.'/mod/turnitintool/view.php?id='.$cm->id.'&do=tutors');
        exit();
    }
}

if (!is_null($param_do) AND $param_do=="tutors" AND is_null($param_unenrol) AND is_null($param_enroltutor)) {
    $tutors=turnitintool_get_tiitutors($cm,$turnitintool);
    if (!is_null($tutors->error)) {
        $notice=$tutors->error;
    } else {
        $notice=null;
    }
}

if (!is_null($param_do) AND $param_do=="changeowner") {
    turnitintool_ownerprocess($cm,$turnitintool,$param_owner);
    turnitintool_redirect($CFG->wwwroot.'/mod/turnitintool/view.php?id='.$cm->id.'&do=tutors');
    exit();
}

if (!is_null($param_do) AND $turnitintool->autoupdates==1 AND $param_do=="allsubmissions" AND !is_null($param_anonid)) {
    $loaderbar = new turnitintool_loaderbarclass(3);
    turnitintool_revealuser($cm,$turnitintool,$post,$loaderbar);
    turnitintool_redirect($CFG->wwwroot.'/mod/turnitintool/view.php?id='.$cm->id.'&do=allsubmissions&update=1');
    exit();
}

if (!is_null($param_updategrade) OR isset($post['updategrade']) OR isset($post["updategrade_x"])) {
    turnitintool_update_form_grades($cm,$turnitintool,$post);
}

if (!is_null($param_up)) { // Manual Submission to Turnitin
    if (!$submission = turnitintool_get_record('turnitintool_submissions','id',$param_up)) {
        print_error('submissiongeterror','turnitintool');
        exit();
    }
    turnitintool_upload_submission($cm,$turnitintool,$submission);
    exit();
}

if (!is_null($param_submissiontype) AND $param_do=='submissions') {
    if (isset($param_userid)) {
        $thisuserid=$param_userid;
    } else {
        $thisuserid=$USER->id;
    }

    if ($param_submissiontype==1) {
        $notice=turnitintool_dofileupload($cm,$turnitintool,$thisuserid,$post);
    } else if ($param_submissiontype==2) {
        $notice=turnitintool_dotextsubmission($cm,$turnitintool,$thisuserid,$post);
    }
    if ($turnitintool->autosubmission AND !empty($notice["subid"])) {
        if (!$submission = turnitintool_get_record('turnitintool_submissions','id',$notice["subid"])) {
            print_error('submissiongeterror','turnitintool');
            exit();
        }
        turnitintool_upload_submission($cm,$turnitintool,$submission);
        exit();
    }
}

if (!is_null($param_submitted) AND $param_do=='intro') {
    $notice=turnitintool_update_partnames($cm,$turnitintool,$post);
}

if (!is_null($param_delpart) AND $param_do=='intro') {
    $notice=turnitintool_delete_part($cm,$turnitintool,$param_delpart);
}

if (!is_null($param_submitted) AND $param_do=='notes') {
    $notice=turnitintool_process_notes($cm,$turnitintool,$param_s,$post);
}

if (!is_null($param_submitted) AND $param_do=='options') {
    $notice=turnitintool_process_options($cm,$turnitintool,$post);
}

add_to_log($course->id, "turnitintool", "view", "view.php?id=$cm->id", "User viewed assignment '$turnitintool->name'", "$cm->id");

/// Print the page header
$strturnitintools = get_string("modulenameplural", "turnitintool");
$strturnitintool  = get_string("modulename", "turnitintool");

if (!is_callable('build_navigation')) {
    $navigation = array(
            array('title' => $course->shortname, 'url' => $CFG->wwwroot."/course/view.php?id=$course->id", 'type' => 'course'),
            array('title' => $strturnitintools, 'url' => $CFG->wwwroot."/mod/turnitintool/index.php?id=$course->id", 'type' => 'activity'),
            array('title' => format_string($turnitintool->name), 'url' => '', 'type' => 'activityinstance')
    );
} else {
    $navigation = build_navigation('',$cm);
}

turnitintool_header($cm,
        $course,
        $_SERVER["REQUEST_URI"],
        $turnitintool->name,
        $SITE->fullname,
        $navigation,
        "",
        "",
        true,
        update_module_button($cm->id, $course->id, $strturnitintool),
        navmenu($course)
);

/// Check to see if groups are being used and abstract for 1.8 if neccessary
if (!is_callable('groups_get_activity_group')) {
    $changegroup = optional_param('group', -1, PARAM_INT);
    $cm->currentgroup=get_and_set_current_group($course, $cm->groupmode, $changegroup);
    setup_and_print_groups($course, $cm->groupmode, $redirectlink);
} else {
    $groupmode = groups_get_activity_groupmode($cm);
    if ($groupmode) {
        groups_get_activity_group($cm, true);
        groups_print_activity_menu($cm, $redirectlink);
    }
}

// Print the main part of the page
echo '<div id="turnitintool_style">';

if (!is_null($param_do)) {
    $do=$param_do;
} else {
    $do='intro';
}

// $do=ACTION
// $do=submissions >>> Student Submission Page
// $do=intro >>> Turnitin Assignment Intro Page
// $do=allsubmissions >>> Tutor View All Submissions
// $do=bulkupload >>> Tutor Bulk Upload Student Submissions
// $do=viewtext >>> View Student Text Submission
// $do=submissiondetails >>> View Submission Details

$studentdos=array('submissions','intro','viewtext','submissiondetails','notes');
$graderdos=array('allsubmissions','options','changeowner','tutors');

// If an unrecognised DO request produce error
if (!in_array($do,$studentdos) AND !in_array($do,$graderdos)) {
    turnitintool_print_error('dorequesterror','turnitintool');
    exit();
} else if (!has_capability('mod/turnitintool:grade', get_context_instance(CONTEXT_MODULE, $cm->id)) AND in_array($do,$graderdos)) {
    turnitintool_print_error('permissiondeniederror','turnitintool');
    exit();
}

echo '<br />';
turnitintool_draw_menu($cm,$do);

if ($do=='intro') {
    if (isset($notice['error'])) {
        turnitintool_box_start('generalbox boxwidthwide boxaligncenter error', 'errorbox');
        echo $notice['message'];
        turnitintool_box_end();
    } else {
        $notice=NULL;
    }
    // Update the GradeBook to make sure the grade stays 'hidden' until and wasn't revealed by modedit
    turnitintool_grade_item_update( $turnitintool );
    echo turnitintool_duplicatewarning($cm,$turnitintool);
    echo turnitintool_introduction($cm,$turnitintool,$notice);
}

if ($do=='submissions') {
    if ( !has_capability('mod/turnitintool:grade', get_context_instance(CONTEXT_MODULE, $cm->id)) 
         AND !has_capability('mod/turnitintool:submit', get_context_instance(CONTEXT_MODULE, $cm->id))) {
        turnitintool_print_error('permissiondeniederror','turnitintool');
        exit();
    } else {
        echo turnitintool_view_student_submissions($cm,$turnitintool);
        if (isset($notice["error"])) {
            turnitintool_box_start('generalbox boxwidthwide boxaligncenter error', 'errorbox');
            echo $notice["error"];
            turnitintool_box_end();
        }
        echo turnitintool_view_submission_form($cm,$turnitintool);
    }
}

if ($do=='allsubmissions') {
    if (!empty($notice)) {
        turnitintool_box_start('generalbox boxwidthwide boxaligncenter error', 'errorbox');
        echo $notice;
        turnitintool_box_end();
    }
    if (isset($param_ob)) {
        $ob=$param_ob;
    } else {
        $ob=1;
    }
    echo turnitintool_view_all_submissions($cm,$turnitintool,$ob);
}

if ($do=='notes') {
    echo turnitintool_view_notes($cm,$turnitintool,$param_s,$post);
    if (isset($notice['error'])) {
        turnitintool_box_start('generalbox boxwidthwide boxaligncenter error', 'errorbox');
        echo $notice['message'];
        turnitintool_box_end();
    } else {
        $notice=NULL;
    }
    echo turnitintool_addedit_notes($cm,$turnitintool,$param_s,$post,$notice);

}

if ($do=='options') {
    if (!empty($notice)) {
        turnitintool_box_start('generalbox boxwidthwide boxaligncenter', 'general');
        echo $notice;
        turnitintool_box_end();
    }
    echo turnitintool_view_options($cm,$turnitintool);
}

if ($do=='tutors') {
    if (!is_null($notice)) {
        turnitintool_box_start('generalbox boxwidthwide boxaligncenter error', 'errorbox');
        echo $notice;
        turnitintool_box_end();
    } else {
        echo turnitintool_view_tiitutors($cm,$turnitintool,$tutors);
    }
}

// Finish the page
echo '</div>';

if (isset($PAGE) AND @is_callable(array($PAGE->requires, 'js'))) { // Are we using new moodle or old?
    // We already added the Moodle 2.0+ stuff
} else {
    // These need to go to the botton here to avoid conflicts
    require_js($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.min.js');
    require_js($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.plugins.js');
    require_js($CFG->wwwroot.'/mod/turnitintool/scripts/inboxtable.js');
}

turnitintool_footer($course);
$module=turnitintool_get_record('modules','name','turnitintool');
$parts=turnitintool_get_records('turnitintool_parts','turnitintoolid',$turnitintool->id);
$parts_string="(";
foreach ($parts as $part) {
    $parts_string.=($parts_string!="(") ? " | " : "";
    $parts_string.= $part->partname.': '.$part->tiiassignid;
}
$parts_string.=")";
echo '<!-- Turnitin Moodle Direct Version: '.$module->version.' - '.$parts_string.' -->';

/* ?> */
Back to Top