This repository has been archived by the owner on Jul 28, 2022. It is now read-only.
forked from segeybutakov/moodle-plagiarism_crot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.php
153 lines (137 loc) · 5.84 KB
/
settings.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
<?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/>.
/**
* plagiarism.php - allows the admin to configure plagiarism stuff
*
* @package plagiarism_crot
* @author Dan Marsden <[email protected]>, Sergey Butakov, Svetlana Kim
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(__FILE__)) . '/../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/plagiarismlib.php');
require_once($CFG->dirroot.'/plagiarism/crot/lib.php');
require_once($CFG->dirroot.'/plagiarism/crot/plagiarism_form.php');
require_login();
admin_externalpage_setup('plagiarismcrot');
$context = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
require_once('plagiarism_form.php');
$mform = new plagiarism_setup_form();
$plagiarismplugin = new plagiarism_plugin_crot();
if ($mform->is_cancelled()) {
redirect('');
}
echo $OUTPUT->header();
if (($data = $mform->get_data()) && confirm_sesskey()) {
if (!isset($data->crot_use)) {
$data->crot_use = 0;
}
foreach ($data as $field=>$value) {
if (strpos($field, 'crot')===0) {
if ($tiiconfigfield = $DB->get_record('config_plugins', array('name'=>$field, 'plugin'=>'plagiarism'))) {
$tiiconfigfield->value = $value;
if (! $DB->update_record('config_plugins', $tiiconfigfield)) {
error("errorupdating");
}
} else {
$tiiconfigfield = new stdClass();
$tiiconfigfield->value = $value;
$tiiconfigfield->plugin = 'plagiarism';
$tiiconfigfield->name = $field;
if (! $DB->insert_record('config_plugins', $tiiconfigfield)) {
error("errorinserting");
}
}
}
if($field == 'delall' && $value == true) {
clean_data();
}
if($field == 'testglobal' && $value == true) {
test_global_search();
}
if($field == 'registration' && $value == true) {
echo $OUTPUT->box("<b><a href=\"https://spreadsheets.google.com/viewform?formkey=dFRPVTRiSkNzSzI1cTVManUwNWVKZXc6MQ\" target=\"_new\">Please follow this link to register!</a></b>");
}
}
notify(get_string('savedconfigsuccess', 'plagiarism_crot'), 'notifysuccess');
}
$plagiarismsettings = (array)get_config('plagiarism');
$mform->set_data($plagiarismsettings);
function clean_data(){
global $DB;
// cleaning up all the tables for Crot plugin except teachers' settings: delete_records("plagiarism_crot_config")
$DB->delete_records("plagiarism_crot_files");
$DB->delete_records("plagiarism_crot_documents");
$DB->delete_records("plagiarism_crot_fingerprint");
$DB->delete_records("plagiarism_crot_spair");
$DB->delete_records("plagiarism_crot_webdoc");
notify(get_string('tables_cleaned_up','plagiarism_crot'), 'notifysuccess');
}
function test_global_search(){
// method sends a few queries to test search
global $CFG;
require_once($CFG->dirroot.'/plagiarism/crot/locallib.php');
// testing global connectivity
echo "Testing global connectivity...<br>";
// read file from global bing web site
$infile = @file_get_contents("http://www.bing.com/siteowner/s/siteowner/Logo_63x23_Dark.png", FILE_BINARY);
if (strlen($infile)>0 && substr($infile,1,3)=='PNG'){
// print the file size
echo "<i>Bing.com is accessible from your server - <font color=\"green\"><b>OK</b></font></i><br><hr>";
} else {
echo "can not reach bing.com<br>";
}
// testing Bing search
$plagiarismsettings = (array)get_config('plagiarism');
$msnkey = $plagiarismsettings['crot_live_key'];
$culture_info = $plagiarismsettings['crot_culture_info'];
$todown = $plagiarismsettings['crot_number_of_web_documents'];
$query = ("Crot for Moodle");
$query = "'".trim($query)."'";
echo "Testing global search settings for Bing...<br>";
try {
$request = 'http://api.bing.net/xml.aspx?Appid=' . $msnkey .
'&sources=web&Query=' . urlencode( $query) .
'&culture='.$culture_info.
'&Web.Options=DisableHostCollapsing+DisableQueryAlterations'.
'&Options=DisableLocationDetection';
echo "Sending query:".$request;
$searches = fetchBingResults($query, $todown, $msnkey, $culture_info);
}
catch (Exception $e) {
print_error("exception in querying Bing!\n");
}
$i=1;
if ($searches){
echo "<i>- <font color=\"green\"><b>OK</b></font></i><hr>";
echo "<b>Search results:</b><br>";
echo "Top links for <i>".$query."</i> query:<br>";
foreach($searches as $hit){
echo "link $i:".substr($hit,0,60)."<br>";
$i++;
}
}else{
echo "<i> - <font color=\"red\"><b>ERROR!!!</b></font></i><hr>";
}
echo "<script type=\"text/javascript\">alert(\"Test is over\");</script>";
flush();
}
echo $OUTPUT->box_start('generalbox boxaligncenter', 'intro');
$mform->display();
echo $OUTPUT->box_end();
echo $OUTPUT->footer();