-
Notifications
You must be signed in to change notification settings - Fork 1
/
page.php
executable file
·196 lines (151 loc) · 6.88 KB
/
page.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
<?PHP // $Id: edit.php,v 1.15 2005/07/14 20:58:07 skodak Exp $
require_once('../../config.php');
require_once('lib.php');
$pagenum = optional_param('pagenum', 1, PARAM_INT); //-> pagenum virou chapternum
$delete = optional_param('delete', 0, PARAM_INT); //-> para apagar
$addprev = optional_param('addprev', 0, PARAM_INT); //-> para apagar
$addnext = optional_param('addnext', 0, PARAM_INT); //-> para apagar
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid',0,PARAM_INT);
$target_navigation_chapter = required_param('target_navigation_chapter', PARAM_INT); // navegação padrao pelos
// =========================================================================
// security checks START - only teachers edit
// =========================================================================
require_login();
if ($CFG->forcelogin) {
require_login();
}
if (!$cm = get_record('course_modules', 'id', $id)) {
error('Course Module ID is incorrect');
}
if (!$course = get_record('course', 'id', $cm->course)) {
error('Course is misconfigured');
}
if ($course->category) {
require_login($course->id);
}
if (!$book = get_record('hiperbook', 'id', $cm->instance)) {
error('Course module is incorrect');
}
$navchapter = get_record('hiperbook_navigation_chapters', 'id',$target_navigation_chapter);
if (!$chapter = get_record('hiperbook_chapters', 'id', $navchapter->chapterid)) {
error('Chapter is misconfigured');
}
if (!isteacheredit($course->id)&($chapter->opentostudents==0)) {
error('Only editing teachers can edit hiperbooks!', $_SERVER['HTTP_REFERER']);
}
if (($addprev==0)&($addnext==0)){
$page = get_record('hiperbook_chapters_pages', 'chapterid', $navchapter->chapterid, 'pagenum', $pagenum);
}
// =========================================================================
// security checks END
// =========================================================================
$usehtmleditor = can_use_html_editor();
if($delete == 1){
//echo 'apaga';
// apaga a pagina com pagenum do parametro, subtraindo 1 de pagenum das paginas com pagenum > pagenum apagada
delete_records('hiperbook_chapters_pages','chapterid', $chapter->id,'pagenum',$pagenum);
$err = execute_sql("update ". $CFG->prefix."hiperbook_chapters_pages set pagenum = (pagenum -1) where chapterid = '$chapter->id' and pagenum > '$pagenum'");
$npnum = $page->pagenum-1;
redirect("view.php?id=$cm->id&target_navigation_chapter=$navchapter->id&pagenum=$npnum&groupid=$groupid");
}
/// If data submitted, then process and store.
if (($form = data_submitted()) && (confirm_sesskey())) {
//TODO: skip it for now
//prepare data - security checks
//$form->title = clean_text($form->title, FORMAT_HTML);
//$form->content = clean_text($form->content, FORMAT_HTML);
//var_dump($form);
//var_dump(data_submitted());
//$db->debug=true;
//die();
if (!isset($form->parentchapterid) ) {
$form->parentchapterid = 0;
}
if ($page) {
/// editing existing page
$page->pagenum = $form->pagenum;
$page->timemodified = time();
$page->content = $form->content;
//var_dump($page);
if (!update_record('hiperbook_chapters_pages', $page,'pageid')) {
error('Could not update your hiperbook!');
}
add_to_log($course->id, 'course', 'update mod', '../mod/hiperbook/view.php?id='.$cm->id, 'hiperbook '.$book->id);
add_to_log($course->id, 'hiperbook', 'update', '../mod/hiperbook/view.php?id='.$cm->id.'&chapterid='.$chapter->id, $book->name.' page update', $cm->id);
} else {
// creating new page
$db->debug = true;
if($form->addnext==1){
// move as paginas posteriores p frente e adiciona uma apos a atual
execute_sql("update ". $CFG->prefix."hiperbook_chapters_pages set pagenum = (pagenum + 1) where chapterid = '$chapter->id' and pagenum > '$pagenum'");
$page->pagenum = $form->pagenum + 1; //place after given pagenum, lets hope it is a number
}
if($form->addprev==1){
// move as paginas posteriores e a atual p frente e adiciona no lugar da atual
execute_sql("update ". $CFG->prefix."hiperbook_chapters_pages set pagenum = (pagenum + 1) where chapterid = '$chapter->id' and pagenum >= '$pagenum'");
$page->pagenum = $form->pagenum; //place after given pagenum, lets hope it is a number
}
if(($form->addprev==0)&($form->addnext==0)){
$page->pagenum = $form->pagenum;
}else{
}
//var_dump($form);
/// adding new page (the first one)
$page->content = $form->content;
$page->chapterid = $form->chapterid;
$page->groupid = $form->groupid;
$page->opentostudents = $form->opentostudents;
$page->userid = $USER->id;
$page->idhiperbook = $cm->instance;
$page->hidden = 0;
$page->timecreated = time();
$page->timemodified = $page->timecreated;
// $db->debug = true;
if (!$page->id = insert_record('hiperbook_chapters_pages', $page)) {
error('Could not insert a new page!');
}
add_to_log($course->id, 'course', 'update mod', '../mod/hiperbook/view.php?id='.$cm->id, 'hiperbook '.$book->id);
add_to_log($course->id, 'hiperbook', 'update', '../mod/hiperbook/view.php?id='.$cm->id.'&chapterid='.$chapter->id, $book->id, $cm->id);
}
// var_dump($page); die();
// /view.php?id=391&chapterid=5924&navigationnum=1&parentnavchapterid=20&groupid=0
redirect("view.php?id=$cm->id&target_navigation_chapter=$navchapter->id&pagenum=$page->pagenum&groupid=$groupid");
}
/// Otherwise fill and print the form.
$strbook = get_string('modulename', 'hiperbook');
$strbooks = get_string('modulenameplural', 'hiperbook');
$stredit = get_string('edit');
$pageheading = get_string('editingpage', 'hiperbook');
$usehtmleditor = can_use_html_editor();
if (!$page) {
$page->chapterid = $chapterid;
$page->pagenum = $pagenum;
$page->content = $book->template_main;
$page->opentostudents = $chapter->opentostudents;
}
///prepare the page header
if ($course->category) {
$navigation = '<a href="../../course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->';
} else {
$navigation = '';
}
print_header( "$course->shortname: $book->name",
$course->fullname,
"$navigation <a href=\"index.php?id=$course->id\">$strbooks</A> -> <a href=\"view.php?id=$cm->id\">$book->name</A> -> $stredit",
'',
'',
true,
'',
''
);
$icon = '<img align="absmiddle" height="16" width="16" src="icon_chapter.gif" /> ';
print_heading_with_help($pageheading, 'edit', 'hiperbook', $icon);
print_simple_box_start('center', '');
include('page.html');
print_simple_box_end();
if ($usehtmleditor ) {
use_html_editor();
}
print_footer($course);
?>