-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathunplag_form.php
231 lines (198 loc) · 8.71 KB
/
unplag_form.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
<?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/>.
/**
* unplag_form.php
*
* @package plagiarism_unplag
* @subpackage plagiarism
* @author Vadim Titov <v.titov@p1k.co.uk>
* @copyright UKU Group, LTD, https://www.unicheck.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use plagiarism_unplag\classes\entities\unplag_archive;
use plagiarism_unplag\classes\unplag_settings;
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
global $CFG;
require_once($CFG->libdir . '/formslib.php');
/**
* Class unplag_setup_form
*
* @copyright UKU Group, LTD, https://www.unicheck.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class unplag_setup_form extends moodleform {
/**
* Define the form
*
* @throws coding_exception
*/
public function definition() {
$mform = &$this->_form;
$mform->addElement('checkbox', 'unplag_use', plagiarism_unplag::trans('use_unplag'));
$settingstext = '<div id="fitem_id_unplag_settings_link" class="fitem fitem_ftext ">
<div class="felement ftext">
<a href="' . UNPLAG_DOMAIN . 'profile/apisettings" target="_blank"> ' .
plagiarism_unplag::trans('unplag_settings_url_text') . '</a>
</div>
</div>';
$mform->addElement('html', $settingstext);
$mform->addElement('text', 'unplag_client_id', plagiarism_unplag::trans('unplag_client_id'));
$mform->addHelpButton('unplag_client_id', 'unplag_client_id', 'plagiarism_unplag');
$mform->addRule('unplag_client_id', null, 'required', null, 'client');
$mform->setType('unplag_client_id', PARAM_TEXT);
$mform->addElement('text', 'unplag_api_secret', plagiarism_unplag::trans('unplag_api_secret'));
$mform->addHelpButton('unplag_api_secret', 'unplag_api_secret', 'plagiarism_unplag');
$mform->addRule('unplag_api_secret', null, 'required', null, 'client');
$mform->setType('unplag_api_secret', PARAM_TEXT);
$mform->addElement('textarea', 'unplag_student_disclosure', plagiarism_unplag::trans('studentdisclosure'),
'wrap="virtual" rows="6" cols="100"');
$mform->addHelpButton('unplag_student_disclosure', 'studentdisclosure', 'plagiarism_unplag');
$mform->setDefault('unplag_student_disclosure', plagiarism_unplag::trans('studentdisclosuredefault'));
$mform->setType('unplag_student_disclosure', PARAM_TEXT);
$mods = core_component::get_plugin_list('mod');
foreach (array_keys($mods) as $mod) {
if (plugin_supports('mod', $mod, FEATURE_PLAGIARISM) && plagiarism_unplag::is_support_mod($mod)) {
$modstring = 'unplag_enable_mod_' . $mod;
$mform->addElement('checkbox', $modstring, plagiarism_unplag::trans('unplag_enableplugin', ucfirst($mod)));
}
}
$this->add_action_buttons(true);
}
}
/**
* Class unplag_defaults_form
*
* @copyright UKU Group, LTD, https://www.unicheck.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class unplag_defaults_form extends moodleform {
/** @var bool */
private $internalusage = false;
/** @var string */
private $modname = '';
/**
* unplag_defaults_form constructor.
*
* @param object|null $mform - Moodle form
* @param string|null $modname
*/
public function __construct($mform = null, $modname = null) {
parent::__construct();
if (!is_null($mform)) {
$this->_form = $mform;
$this->internalusage = true;
}
if (!is_null($modname) && is_string($modname) && plagiarism_plugin_unplag::is_enabled_module($modname)) {
$modname = str_replace('mod_', '', $modname);
if (plagiarism_unplag::is_support_mod($modname)) {
$this->modname = $modname;
};
}
}
/**
* Define the form
*
* @throws coding_exception
*/
public function definition() {
$defaultsforfield = function(MoodleQuickForm $mform, $setting, $defaultvalue) {
if (!isset($mform->exportValues()[$setting]) || is_null($mform->exportValues()[$setting])) {
$mform->setDefault($setting, $defaultvalue);
}
};
$addyesnoelem = function(MoodleQuickForm $mform, $setting, $showhelpballoon = false) {
$ynoptions = [get_string('no'), get_string('yes')];
$mform->addElement('select', $setting, plagiarism_unplag::trans($setting), $ynoptions);
if ($showhelpballoon) {
$mform->addHelpButton($setting, $setting, 'plagiarism_unplag');
}
};
/** @var MoodleQuickForm $mform */
$mform = &$this->_form;
$mform::registerRule('range', null, new unplag_form_rule_range());
$mform->addElement('header', 'plagiarismdesc', plagiarism_unplag::trans('unplag'));
if ($this->modname === UNPLAG_MODNAME_ASSIGN) {
$mform->addElement('static', 'use_unplag_static_description', plagiarism_unplag::trans('useunplag_assign_desc_param'),
plagiarism_unplag::trans('useunplag_assign_desc_value'));
}
$setting = unplag_settings::USE_UNPLAG;
$addyesnoelem($mform, $setting);
if ($this->modname === UNPLAG_MODNAME_ASSIGN) {
$mform->addHelpButton($setting, $setting, 'plagiarism_unplag');
}
if (!in_array($this->modname, [UNPLAG_MODNAME_FORUM, UNPLAG_MODNAME_WORKSHOP])) {
$addyesnoelem($mform, unplag_settings::CHECK_ALL_SUBMITTED_ASSIGNMENTS);
$addyesnoelem($mform, unplag_settings::NO_INDEX_FILES);
}
$setting = unplag_settings::CHECK_TYPE;
$mform->addElement('select', $setting, plagiarism_unplag::trans($setting), [
UNPLAG_CHECK_TYPE_WEB__LIBRARY => plagiarism_unplag::trans(UNPLAG_CHECK_TYPE_WEB__LIBRARY),
UNPLAG_CHECK_TYPE_WEB => plagiarism_unplag::trans(UNPLAG_CHECK_TYPE_WEB),
UNPLAG_CHECK_TYPE_MY_LIBRARY => plagiarism_unplag::trans(UNPLAG_CHECK_TYPE_MY_LIBRARY),
]);
$addyesnoelem($mform, unplag_settings::SHOW_STUDENT_SCORE, true);
$addyesnoelem($mform, unplag_settings::SHOW_STUDENT_REPORT, true);
$setting = unplag_settings::SENSITIVITY_SETTING_NAME;
$mform->addElement('text', $setting, plagiarism_unplag::trans($setting));
$mform->setType($setting, PARAM_TEXT);
$defaultsforfield($mform, $setting, 0);
$setting = unplag_settings::EXCLUDE_CITATIONS;
$addyesnoelem($mform, $setting);
$defaultsforfield($mform, $setting, 1);
$setting = unplag_settings::MAX_SUPPORTED_ARCHIVE_FILES_COUNT;
$mform->addElement('text', $setting, plagiarism_unplag::trans($setting));
$mform->setType($setting, PARAM_TEXT);
$defaultsforfield($mform, $setting, 10);
$min = unplag_archive::MIN_SUPPORTED_FILES_COUNT;
$max = unplag_archive::MAX_SUPPORTED_FILES_COUNT;
$mform->addRule(
unplag_settings::MAX_SUPPORTED_ARCHIVE_FILES_COUNT,
"Invalid value range. Allowed $min-$max",
'range',
['min' => $min, 'max' => $max],
'server',
true
);
$mform->addHelpButton($setting, $setting, 'plagiarism_unplag');
if (!$this->internalusage) {
$this->add_action_buttons(true);
}
}
}
/**
* Class unplag_form_rule_range
*
* @copyright UKU Group, LTD, https://www.unicheck.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class unplag_form_rule_range extends HTML_QuickForm_Rule {
/**
* validate
*
* @param int $value Value to check
* @param array|null $options
*
* @return bool true if value in valid range
*/
public function validate($value, $options = null) {
if ($value < $options['min'] || $value > $options['max']) {
return false;
}
return true;
}
}