forked from jl2035/moodle_mod_mootyper
/
eins.php
executable file
·174 lines (157 loc) · 6.27 KB
/
eins.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
<?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/>.
/**
* This is a one-line short description of the file
*
*
* @package mod
* @subpackage mootyper
* @copyright 2011 Jaka Luthar (jaka.luthar@gmail.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
global $USER, $DB;
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
require_once(dirname(__FILE__).'/locallib.php');
$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
if ($id){
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
}
else
error('You must specify a course_module ID or an instance ID');
require_login($course, true);
$lessonPO = optional_param('lesson', -1, PARAM_INT);
if(isset($_POST['button']))
$param1 = $_POST['button'];
if(isset($param1) && get_string('fconfirm', 'mootyper') == $param1 )
//DB insert
{
//$lessonPO = optional_param('lesson', -1, PARAM_INT);
$texttotypeePO = $_POST['texttotype'];
//$enamePO = $_POST['exercisename'];
if($lessonPO == -1)
{
$lsnnamePO = $_POST['lessonname'];
$lsnrecord = new stdClass();
$lsnrecord->lessonname = $lsnnamePO;
$lsnrecord->visible = $_POST['visible'];
$lsnrecord->editable = $_POST['editable'];
$lsnrecord->authorid = $USER->id;
$lsnrecord->courseid = $course->id;
$lesson_id = $DB->insert_record('mootyper_lessons', $lsnrecord, true);
}
else
$lesson_id = $lessonPO;
$snum = get_new_snumber($lesson_id);
$erecord = new stdClass();
$erecord->exercisename = "".$snum;
$erecord->snumber = $snum;
$erecord->lesson = $lesson_id;
$erecord->texttotype = str_replace("\r\n", '\n', $texttotypeePO);
$DB->insert_record('mootyper_exercises', $erecord, false);
$webDir = $CFG->wwwroot . '/mod/mootyper/exercises.php?id='.$id;
//header('Location: '.$webDir);
echo '<script type="text/javascript">window.location="'.$webDir.'";</script>';
}
//$context = get_context_instance(CONTEXT_MODULE, $cm->id);
//add_to_log($course->id, 'mootyper', 'view', "view.php?id={$cm->id}", $mootyper->name, $cm->id);
/// Print the page header
$PAGE->set_url('/mod/mootyper/eins.php', array('id' => $course->id));
$PAGE->set_title(get_string('etitle', 'mootyper'));
$PAGE->set_heading(get_string('eheading', 'mootyper'));
//$PAGE->set_context($context);
// other things you may want to set - remove if not needed
$PAGE->set_cacheable(false);
//$PAGE->set_focuscontrol('tb1');
//$PAGE->add_body_class('mootyper-'.$somevar);
// Output starts here
echo $OUTPUT->header();
// action="?id='.$id.'&ins=true"
$lessonsG = get_typerlessons();
if(has_capability('mod/mootyper:editall', context_course::instance($course->id)))
$lessons = $lessonsG;
else
{
$lessons = array();
foreach($lessonsG as $lsnG)
if(is_editable_by_me($USER->id, $lsnG['id']))
$lessons[] = $lsnG;
}
echo '<form method="POST">';
echo get_string('fnewexercise', 'mootyper').' ';
echo '<select onchange="this.form.submit()" name="lesson">';
echo '<option value="-1">'.get_string('fnewlesson', 'mootyper').'</option>';
for($ij=0; $ij<count($lessons); $ij++)
{
if($lessons[$ij]['id'] == $lessonPO)
echo '<option selected="true" value="'.$lessons[$ij]['id'].'">'.$lessons[$ij]['lessonname'].'</option>';
else
echo '<option value="'.$lessons[$ij]['id'].'">'.$lessons[$ij]['lessonname'].'</option>';
}
echo '</select>';
if($lessonPO == -1){
echo '<br><br>...'.get_string('lsnname', 'mootyper').': <input type="text" name="lessonname" id="lessonname"><span style="color:red;" id="namemsg"></span>';
echo '<br><br>'.get_string('visibility', 'mootyper').': <select name="visible">';
echo '<option value="2">'.get_string('vaccess2', 'mootyper').'</option>';
echo '<option value="1">'.get_string('vaccess1', 'mootyper').'</option>';
echo '<option value="0">'.get_string('vaccess0', 'mootyper').'</option>';
echo '</select><br><br>'.get_string('editable', 'mootyper').': <select name="editable">';
echo '<option value="2">'.get_string('eaccess2', 'mootyper').'</option>';
echo '<option value="1">'.get_string('eaccess1', 'mootyper').'</option>';
echo '<option value="0">'.get_string('eaccess0', 'mootyper').'</option>';
echo '</select>';
}
?>
<script type="text/javascript">
function isLetter(str) {
var pattern = /[a-zčšžđćüöäèéàçâêîôº¡çñáéíóú]/i;
return str.length === 1 && str.match(pattern);
}
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
var ok = true;
function clClick()
{
var exercise_text = document.getElementById("texttotype").value;
var allowed_chars = ['!','@','#','$','%','^','&','(',')','*','_','+',':',';','"','{','}','>','<','?','\'','-','/','=','.',',',' ','|','¡','`','º','¿','ª','·','\n','\r','\r\n', '\n\r', ']', '[', '¬', '´', '`'];
var shown_text = "";
ok = true;
for(var i=0; i<exercise_text.length; i++) {
if(!isLetter(exercise_text[i]) && !isNumber(exercise_text[i]) && allowed_chars.indexOf(exercise_text[i]) == -1) {
shown_text += '<span style="color: red;">'+exercise_text[i]+'</span>';
ok = false;
}
else
shown_text += exercise_text[i];
}
if(!ok) {
document.getElementById('text_holder_span').innerHTML = shown_text;
return false;
}
if(document.getElementById("lessonname").value == "") {
document.getElementById("namemsg").innerHTML = '<?php echo get_string('reqfield', 'mootyper'); ?>';
return false;
}
else
return true;
}
</script>
<?php echo '<br><span id="text_holder_span" class=""></span><br>'.get_string('fexercise', 'mootyper').':<br>'.
'<textarea rows="4" cols="40" name="texttotype" id="texttotype"></textarea><br>'.
'<br><input name="button" onClick="return clClick()" type="submit" value="'.get_string('fconfirm', 'mootyper').'">'.
'</form>';
echo $OUTPUT->footer();