forked from thanhtri/plagiarism_programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
675 lines (587 loc) · 30 KB
/
lib.php
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The main entry file of the plugin.
*
* Provide the site-wide setting and specific configuration for each assignment.
*
* @package plagiarism_programming
* @copyright 2015 thanhtri, 2019 Benedikt Schneider (@Nullmann)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
// Get global class.
global $CFG;
require_once($CFG->dirroot.'/plagiarism/lib.php');
require_once(__DIR__.'/detection_tools.php');
require_once(__DIR__.'/reportlib.php');
require_once(__DIR__.'/scan_assignment.php');
/**
* Class to integrate the plugin in the moodle submission workflow.
*
* See https://docs.moodle.org/dev/Plagiarism_plugins#Interfacing_to_APIs
*
* @copyright 2015 thanhtri, 2019 Benedikt Schneider (@Nullmann)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plagiarism_plugin_programming extends plagiarism_plugin {
/**
* @var Object $filemanageroption Moodle filemanager to upload and delete files.
*/
private $filemanageroption;
/**
* Constructor which initializes the options.
*/
public function __construct() {
$this->filemanageroption = array('subdir' => 0, 'maxbytes' => 20 * 1024 * 1024, 'maxfiles' => 50,
'accepted_type' => array('*.zip', '*.rar'));
}
/**
* Define the configuration block of plagiarism detection in assignment setting form.
* This method will be called by mod_assign_mod_form class, in its definition method
* @see mod_assign_mod_form
*
* @param object $mform - Moodle form
* @param object $context - current context
* @param string $modulename - Name of the module
*/
public function get_form_elements_module($mform, $context, $modulename = '') {
global $DB, $PAGE;
// When updating an assignment, cmid of the assignment is passed by "update" param.
$cmid = optional_param('update', 0, PARAM_INT);
// When creating an assignment, cmid does not exist, but course id is provided via "course" param.
$courseid = optional_param('course', 0, PARAM_INT);
if (!$this->is_plugin_enabled($cmid, $courseid)) {
return;
}
$plagiarismconfig = null;
$assignmentcontext = null;
if ($cmid) {
$plagiarismconfig = $DB->get_record('plagiarism_programming', array('cmid' => $cmid));
$assignmentcontext = context_module::instance($cmid);
}
$mform->addElement('header', 'programming_header', get_string('plagiarism_header', 'plagiarism_programming'));
// Do not show the settings if the user is not allowed to.
if ($cmid == 0) {
$context = context_course::instance($courseid); // Newly created assign module.
} else {
$context = context_module::instance($cmid); // Already existing assign module.
}
if (!has_capability('plagiarism/programming:changesettings', $context)) {
$mform->addElement('html', html_writer::tag('div', get_string('caperror_changesettings', 'plagiarism_programming')));
return $mform;
}
// Enable or disable plagiarism checking.
$enablechecking = array();
$enablechecking[] = &$mform->createElement('radio', 'programmingYN', '', get_string('disable'), 0);
$enablechecking[] = &$mform->createElement('radio', 'programmingYN', '', get_string('enable'), 1);
$mform->addGroup($enablechecking, 'similarity_checking',
get_string('programmingYN', 'plagiarism_programming'), array(' '), false);
// Select the used programming language.
$programminglanguages = array(
'java' => 'Java',
'c' => 'C/C++',
'c#' => 'C#',
'scheme' => 'Scheme',
'text' => 'Plain text',
'python' => 'Python',
'vb' => 'Visual Basic',
'js' => 'Javascript',
'pascal' => 'Pascal',
'lisp' => 'Lisp',
'perl' => 'Perl',
'prolog' => 'Prolog',
'plsql' => 'Pl-SQL',
'mathlab' => 'MathLab',
'mips' => 'MPIS Assembly',
'a8086' => '8086 Assembly',
'fortran' => 'Fortran'
);
$mform->addElement('select', 'programming_language',
get_string('programming_language', 'plagiarism_programming'), $programminglanguages);
// Disable the tools when no credentials are provided.
$settings = get_config('plagiarism');
$jplagdisabled = null;
if (empty($settings->jplag_user) || empty($settings->jplag_pass)) {
$jplagdisabled = array('disabled' => true);
}
$mossdisabled = null;
if (empty($settings->programming_moss_user_id)) {
$mossdisabled = array('disabled' => true);
}
// Check box for selecting the tools.
$selectedtools = array();
$selectedtools[] = &$mform->createElement('checkbox', 'jplag', '',
get_string('jplag', 'plagiarism_programming'), $jplagdisabled);
$selectedtools[] = &$mform->createElement('checkbox', 'moss', '',
get_string('moss', 'plagiarism_programming'), $mossdisabled);
$mform->addGroup($selectedtools, 'detection_tools', get_string('detection_tools', 'plagiarism_programming'));
// Display scan dates.
$this->setup_multiple_scandate($mform, $plagiarismconfig);
// Additional settings.
$mform->addElement('checkbox', 'auto_publish', get_string('auto_publish', 'plagiarism_programming'));
$mform->addElement('checkbox', 'see_mark', get_string('see_mark', 'plagiarism_programming'));
$mform->addElement('checkbox', 'notification', get_string('notification', 'plagiarism_programming'));
$mform->addElement('textarea', 'notification_text', get_string('notification_text', 'plagiarism_programming'),
'wrap="virtual" rows="4" cols="50"');
$this->setup_code_seeding_filemanager($mform, $plagiarismconfig, $assignmentcontext);
$mform->disabledIf('programming_language', 'programmingYN', 'eq', 0);
$mform->disabledIf('auto_publish', 'programmingYN', 'eq', 0);
$mform->disabledIf('see_mark', 'programmingYN', 'eq', 0);
$mform->disabledIf('see_mark', 'auto_publish', 'notchecked');
$mform->disabledIf('notification', 'programmingYN', 'eq', 0);
$mform->disabledIf('notification_text', 'programmingYN', 'eq', 0);
$mform->disabledIf('notification_text', 'notification', 'notchecked');
/* jplag and moss checkbox is enabled and disabled by custom javascript */
$mform->addHelpButton('similarity_checking', 'programmingYN_hlp', 'plagiarism_programming');
$mform->addHelpButton('programming_language', 'programmingLanguage_hlp', 'plagiarism_programming');
$mform->addHelpButton('detection_tools', 'detection_tools_hlp', 'plagiarism_programming');
$mform->addHelpButton('auto_publish', 'auto_publish_hlp', 'plagiarism_programming');
$mform->addHelpButton('see_mark', 'see_mark_hlp', 'plagiarism_programming');
$mform->addHelpButton('notification', 'notification_hlp', 'plagiarism_programming');
$mform->addHelpButton('notification_text', 'notification_text_hlp', 'plagiarism_programming');
if ($plagiarismconfig) { // Update mode, populate the form with current values.
$mform->setDefault('programmingYN', 1);
$mform->setDefault('programming_language', $plagiarismconfig->language);
$mform->setDefault('detection_tools[jplag]', $plagiarismconfig->jplag);
$mform->setDefault('detection_tools[moss]', $plagiarismconfig->moss);
$mform->setDefault('auto_publish', $plagiarismconfig->auto_publish);
$mform->setDefault('see_mark', $plagiarismconfig->see_mark);
$mform->setDefault('notification', $plagiarismconfig->notification);
$mform->setDefault('notification_text', $plagiarismconfig->notification_text);
}
if (empty($plagiarismconfig->notification_text)) {
$mform->setDefault('notification_text', get_string('notification_text_default', 'plagiarism_programming'));
}
// Disable tool if it doesn't support the selected language.
include_once(__DIR__.'/jplag_tool.php');
include_once(__DIR__.'/moss_tool.php');
$jplagsupport = $jplagdisabled ? false : jplag_tool::get_supported_language();
$mosssupport = $mossdisabled ? false : moss_tool::get_supported_language();
// Include the javascript for doing some minor interface adjustment to improve user experience.
$jsmodule = array(
'name' => 'plagiarism_programming',
'fullpath' => '/plagiarism/programming/assignment_setting.js',
'requires' => array('base', 'node'),
'strings' => array(
array('no_tool_selected_error', 'plagiarism_programming'),
array('invalid_submit_date_error', 'plagiarism_programming')
)
);
$PAGE->requires->js_init_call('M.plagiarism_programming.assignment_setting.init',
array($jplagsupport, $mosssupport), true, $jsmodule);
}
/**
* Save the form into database
* @param stdClass $data the data object retrieved from the form
* @return void
*/
public function save_form_elements($data) {
global $DB, $detectiontools;
$cmid = $data->coursemodule;
$context = context_module::instance($cmid);
if (!$this->is_plugin_enabled($cmid)) {
return;
}
if (!empty($data->programmingYN)) { // The plugin is enabled for this assignment.
$setting = $DB->get_record('plagiarism_programming', array('cmid' => $cmid));
$new = false;
if (!$setting) {
$new = true;
$setting = new stdClass();
$setting->cmid = $cmid;
}
$setting->language = $data->programming_language;
$setting->jplag = isset($data->detection_tools['jplag']) ? 1 : 0;
$setting->moss = isset($data->detection_tools['moss']) ? 1 : 0;
$setting->auto_publish = isset($data->auto_publish) ? 1 : 0;
$setting->see_mark = isset($data->see_mark) ? 1 : 0;
if (isset($data->notification)) {
$setting->notification = 1;
$setting->notification_text = $data->notification_text;
} else {
$setting->notification = 0;
$setting->notification_text = '';
}
if ($new) {
$setting->id = $DB->insert_record('plagiarism_programming', $setting);
} else {
$DB->update_record('plagiarism_programming', $setting);
}
file_postupdate_standard_filemanager($data, 'code', $this->filemanageroption,
$context, 'plagiarism_programming', 'codeseeding', $setting->id);
$datenum = $data->submit_date_num;
// Delete all unfinished scan dates.
$DB->delete_records('plagiarism_programming_date', array('settingid' => $setting->id, 'finished' => 0));
// Save scan dates again.
for ($i = 0; $i < $datenum; $i++) {
if (isset($data->scan_date[$i]) && $data->scan_date[$i] > 0) {
$scandateobj = new stdClass();
$scandateobj->scan_date = $data->scan_date[$i];
$scandateobj->finished = 0;
$scandateobj->settingid = $setting->id;
$DB->insert_record('plagiarism_programming_date', $scandateobj);
}
}
// Either save in *_jplag or *_moss table.
foreach ($detectiontools as $toolname => $info) {
if ($setting->$toolname && !$DB->get_record('plagiarism_programming_'.$toolname,
array('settingid' => $setting->id))) {
$jplagrec = new stdClass();
$jplagrec->settingid = $setting->id;
$jplagrec->status = 'pending';
$DB->insert_record('plagiarism_programming_'.$toolname, $jplagrec);
}
}
} else { // Plugin not enabled, delete the records if there are.
plagiarism_programming_delete_config($cmid);
}
}
/**
* Display similarity information beside each submission
* @param array $linkarray contain relevant information
*/
public function get_links($linkarray) {
global $DB;
// These static variables are for caching, since this function will be called a lot in grade listing.
static $students = null, $context = null, $canshow = null;
$cmid = $linkarray['cmid'];
$studentid = $linkarray['userid'];
if ($canshow == null) { // Those computed values are cached in static variables and reused.
if ($this->is_plugin_enabled($cmid)) { // If the plugin is activated globally.
$settings = $DB->get_record('plagiarism_programming', array('cmid' => $cmid));
if ($settings != null) { // If the plugin is activated for this assignment.
if ($settings->moss) {
$mossparam = $DB->get_record('plagiarism_programming_moss', array('settingid' => $settings->id));
}
if ($settings->jplag) {
$jplagparam = $DB->get_record('plagiarism_programming_jplag', array('settingid' => $settings->id));
}
$canshow = (isset($mossparam) && $mossparam->status == 'finished') ||
(isset($jplagparam) && $jplagparam->status == 'finished');
$context = context_module::instance($cmid);
$isteacher = has_capability('mod/assignment:grade', $context);
$canshow = $isteacher || ($settings->auto_publish && has_capability('mod/assignment:view', $context));
if ($isteacher) {
$students = plagiarism_programming_get_students_similarity_info($cmid);
} else {
$students = plagiarism_programming_get_students_similarity_info($cmid, $studentid);
}
}
}
}
$output = '';
if ($canshow) {
if (isset($students[$studentid])) {
$link = plagiarism_programming_get_report_link($cmid, $studentid, $students[$studentid]['detector'], 0);
$maxrate = round($students[$studentid]['max'], 2);
$output = get_string('max_similarity', 'plagiarism_programming').': '.html_writer::link($link, "$maxrate%");
// Mark as suspicious next to percentage rating.
if ($students[$studentid]['mark'] == 'Y') {
$output .= ' '.html_writer::tag('span', get_string('suspicious', 'plagiarism_programming'),
array('class' => 'programming_result_warning'));
}
} else {
$output .= get_string('no_similarity', 'plagiarism_programming');
}
}
return $output;
}
/**
* Print the disclosure on the assignment page
* @param int $cmid - course module id
* @return string
*/
public function print_disclosure($cmid) {
global $OUTPUT, $DB, $USER;
$setting = $DB->get_record('plagiarism_programming', array('cmid' => $cmid));
// Is the plugin enabled for this course?
if (!$this->is_plugin_enabled($cmid)) {
return '';
}
if (!$setting) { // Plagiarism scanning turned off.
return '';
}
$context = context_module::instance($cmid);
// The user must be a student (or teacher).
if (!has_capability('mod/assignment:submit', $context, $USER->id)) {
return '';
}
$content = '';
if ($setting->notification) {
$content = format_text($setting->notification_text, FORMAT_MOODLE);
$scandates = $DB->get_records('plagiarism_programming_date', array('settingid' => $setting->id, 'finished' => 0),
'scan_date ASC');
if (count($scandates) > 0) {
// Get the first scan date.
$scandate = array_shift($scandates);
$content .= html_writer::tag('div', get_string('scheduled_scanning', 'plagiarism_programming').' '.
date('D j M', $scandate->scan_date));
}
}
if ($setting->auto_publish && count(plagiarism_programming_get_suspicious_works($USER->id, $cmid)) > 0) {
$warning = get_string('high_similarity_warning', 'plagiarism_programming');
$content .= html_writer::tag('span', $warning, array('class' => 'programming_result_warning'));
}
if ($content) {
return $OUTPUT->box_start('generalbox boxaligncenter', 'plagiarism_info')
.$content
.$OUTPUT->box_end();
} else {
return '';
}
}
/**
* Integrates the similarity check into the grading-page of moodle (overview of all users submissions).
*
* @param object $course - full course object
* @param object $cm - full context module object
*/
public function update_status($course, $cm) {
global $OUTPUT, $DB, $USER, $CFG, $PAGE, $detectiontools;
$cmid = $cm->id;
$setting = $DB->get_record('plagiarism_programming', array('cmid' => $cmid));
// Is the plugin enabled for this course?
if (!$this->is_plugin_enabled($cmid)) {
return '';
}
if (!$setting) { // Plagiarism scanning turned off for this assignment.
return '';
}
$context = context_module::instance($cmid);
// Not a teacher.
if (!has_capability('mod/assignment:grade', $context, $USER->id)) {
return '';
}
$content = '';
$alreadyscanned = false;
$buttondisabled = false;
// Check if at least one detector is selected.
if (!$setting->moss && !$setting->jplag) {
$content .= $OUTPUT->notification(get_string('no_tool_selected', 'plagiarism_programming'), 'notifyproblem');
$buttondisabled = true;
}
$check = array();
foreach ($detectiontools as $tool => $toolinfo) {
// If the tool is selected.
if (!$setting->$tool) {
continue;
}
$toolname = $toolinfo['name'];
$scanninginfo = $DB->get_record('plagiarism_programming_'.$tool, array('settingid' => $setting->id));
$info = $scanninginfo->status;
include_once($toolinfo['code_file']);
$classname = $toolinfo['class_name']; // Either jplag_tool or moss_tool.
$toolclass = new $classname();
switch ($scanninginfo->status) {
case null:
case 'pending':
$info = get_string('pending', 'plagiarism_programming');
break;
case 'finished':
$info = $toolclass->display_link($setting);
break;
case 'error':
$info = $scanninginfo->message;
$info .= "<br>".get_string('working_scan', 'plagiarism_programming').": ".$toolclass->display_link($setting);
break;
}
$infotag = html_writer::tag('span', $info, array('id' => $tool.'_status'));
$content .= html_writer::tag('div', "<span style='font-weight: bold'>$toolname</span>: $infotag",
array('class' => 'text_to_html'));
$content .= html_writer::tag('div', '', array('id' => $tool.'_tool', 'class' => 'yui-skin-sam'));
$needchecking = (
$scanninginfo->status != 'pending' &&
$scanninginfo->status != 'finished' &&
$scanninginfo->status != 'error');
$check[$tool] = $needchecking;
$alreadyscanned |= $scanninginfo->status == 'finished'||$scanninginfo->status == 'error';
}
// Add link to MOSS / stanford.
if ($scanninginfo->resultlink !== null) {
$content .= '<a target="_blank" href='.$scanninginfo->resultlink.'>'
.get_string('stanford_link', 'plagiarism_programming').'</a> <br>';
}
// Get user's preferred language to transform time string.
setlocale(LC_TIME, current_language());
if ($setting->latestscan) {
$content .= get_string('latestscan', 'plagiarism_programming').' '.strftime("%c", $setting->latestscan);
}
$scandates = $DB->get_records('plagiarism_programming_date', array('settingid' => $setting->id, 'finished' => 0),
'scan_date ASC');
if (count($scandates) > 0) {
// Get the first scan date.
$scandate = array_shift($scandates);
$content .= html_writer::tag('div', get_string('scheduled_scanning', 'plagiarism_programming').' '.
strftime("%c", $scandate->scan_date));
} else {
$content .= html_writer::tag('div', get_string('no_scheduled_scanning', 'plagiarism_programming'));
}
// Only display help for the rescan button if the user is allowed to.
$context = context_module::instance($cmid);
if (has_capability('plagiarism/programming:manualscan', $context)) {
$content .= html_writer::tag('div', get_string('manual_scheduling_help', 'plagiarism_programming'),
array('style' => 'margin-top:5px'));
} else {
$content .= html_writer::tag('div', get_string('caperror_manualscan', 'plagiarism_programming'));
}
// Check that at least two assignments are submitted.
$filerecords = plagiarism_programming_get_submitted_files($context);
if (count($filerecords) < 2) {
$content .= html_writer::tag('div', get_string('not_enough_submission', 'plagiarism_programming'));
$buttondisabled = true;
}
if (has_capability('plagiarism/programming:manualscan', $context)) {
// Write the rescan button if the user has the capability to do so.
$buttonlabel = ($alreadyscanned) ?
get_string('rescanning', 'plagiarism_programming') :
get_string('start_scanning', 'plagiarism_programming');
$buttonattr = array('type' => 'submit',
'id' => 'plagiarism_programming_scan',
'value' => $buttonlabel);
if ($buttondisabled) {
$buttonattr['disabled'] = 'disabled';
}
$scanbutton = html_writer::empty_tag('input', $buttonattr);
$content .= html_writer::tag('form', $scanbutton, array('method' => 'post',
'action' => "$CFG->wwwroot/plagiarism/programming/start_scanning.php?task=scan&cmid=$cmid"));
$content .= html_writer::tag('span', get_string('scanning_in_progress', 'plagiarism_programming'),
array('style' => 'display:none', 'id' => 'scan_message'));
}
// Include the javascript.
$PAGE->requires->js('/plagiarism/programming/progressbar.js');
$jsmodule = array(
'name' => 'plagiarism_programming',
'fullpath' => '/plagiarism/programming/scanning.js',
'requires' => array('progressbar', 'json', 'io'),
'strings' => array(
array('pending_start', 'plagiarism_programming'),
array('uploading', 'plagiarism_programming'),
array('scanning', 'plagiarism_programming'),
array('downloading', 'plagiarism_programming')
)
);
$PAGE->requires->js_init_call('M.plagiarism_programming.initialise',
array('cmid' => $setting->cmid, 'checkprogress' => $check), false, $jsmodule);
return $OUTPUT->box_start('generalbox boxaligncenter', 'plagiarism_info')
.$content
.$OUTPUT->box_end();
}
/**
* If the plugin is enabled or not (at Moodle level or at course level)
* @param Number $cmid The course module id (can provide the course id instead)
* @param Number $courseid The course id. If course_id is passed, cmid is ignored
* @return boolean
*/
public function is_plugin_enabled($cmid, $courseid=null) {
return get_config('plagiarism')->programming_use;
/* Course-specific activation is not supported anymore.
*
$programmingsettings = (array) get_config('plagiarism_programming');
if ($programmingsettings['level_enabled'] == 'global') { // Globally enabled.
return true;
}
// Specifically enabled for some courses.
if (!$courseid) {
$coursemodule = get_coursemodule_from_id('', $cmid);
$courseid = ($coursemodule) ? $coursemodule->course : 0;
}
global $DB;
return $DB->get_record('plagiarism_programming_cours', array('course' => $courseid)) != false;
*/
}
/**
*/
/**
* This function will setup multiple scan dates for the form.
* This will be similar to the repeat group of moodle form.
* However, since just an instance of $mform is passed in,
* it is not possible to call the protected function repeat_elements
*
* @param object $mform
* @param object $plagiarismconfig
*/
private function setup_multiple_scandate($mform, $plagiarismconfig) {
global $DB;
$scandates = array();
$constantvars = array();
if ($plagiarismconfig) {
$scandates = $DB->get_records('plagiarism_programming_date',
array('settingid' => $plagiarismconfig->id), 'scan_date ASC');
}
$dbscandate = count($scandates);
$datenum = optional_param('submit_date_num', max($dbscandate, 1), PARAM_INT); // Amount of dates to be displayed and saved.
$isadddate = optional_param('add_new_date', '', PARAM_TEXT); // Add another form element if new date button was pushed.
if (!empty($isadddate)) { // The hidden element, combined with javascript, makes the form jump to the date position.
// Add another date picker.
$datenum++;
$mform->addElement('hidden', 'is_add_date', 1);
$constantvars['is_add_date'] = 1;
} else {
// Add first date picker if this is the first time the settings page is called.
$mform->addElement('hidden', 'is_add_date', 0);
$constantvars['is_add_date'] = 0;
}
$mform->setType('is_add_date', PARAM_BOOL);
$i = 0;
foreach ($scandates as $scandate) {
if ($scandate->finished) {
$name = "scan_date_finished[$i]";
$mform->addElement('date_time_selector', $name, get_string('scan_date_finished', 'plagiarism_programming'),
null, array('disabled' => 'disabled'));
$constantvars[$name] = $scandate->scan_date;
$mform->addHelpButton($name, 'date_selector_finished_hlp', 'plagiarism_programming');
} else {
$name = "scan_date[$i]";
$mform->addElement('date_time_selector', "scan_date[$i]", get_string('scan_date', 'plagiarism_programming'),
array('optional' => true, 'step' => 5));
$mform->disabledIf($name, 'programmingYN', 'eq', 0);
$mform->addHelpButton($name, 'date_selector_hlp', 'plagiarism_programming');
}
$mform->setDefault($name, $scandate->scan_date);
$i++;
}
for ($i = $dbscandate; $i < $datenum; $i++) {
$mform->addElement('date_time_selector', "scan_date[$i]", get_string('scan_date', 'plagiarism_programming'),
array('optional' => true, 'step' => 5));
$mform->addHelpButton("scan_date[$i]", 'date_selector_hlp', 'plagiarism_programming');
}
$mform->addElement('hidden', 'submit_date_num', $datenum);
$mform->setType('submit_date_num', PARAM_INT);
$mform->setConstants(array('submit_date_num' => $datenum));
$mform->addElement('submit', 'add_new_date', get_string('new_scan_date', 'plagiarism_programming'));
$mform->disabledIf('add_new_date', 'programmingYN', 'eq', 0);
$mform->registerNoSubmitButton('add_new_date');
$mform->setConstants($constantvars);
}
/**
* Sets up the filemanager for uploading additional libraries to compare against.
*
* @param object $mform
* @param object $plagiarismconfig contents of the table plagiarism_programming
* @param object $assignmentcontext context_module
*/
private function setup_code_seeding_filemanager($mform, $plagiarismconfig, $assignmentcontext) {
$mform->addElement('filemanager', 'code_filemanager', get_string('additional_code', 'plagiarism_programming'),
null, $this->filemanageroption);
$mform->addHelpButton('code_filemanager', 'additional_code_hlp', 'plagiarism_programming');
$data = new stdClass();
file_prepare_standard_filemanager($data, 'code', $this->filemanageroption,
$assignmentcontext, 'plagiarism_programming', 'codeseeding',
($plagiarismconfig) ? $plagiarismconfig->id : null);
$mform->setDefault('code_filemanager', $data->code_filemanager);
}
}