Issues (2160)

main/notebook/index.php (2 issues)

Labels
Severity
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
use ChamiloSession as Session;
5
6
/**
7
 * @author Christian Fasanando, initial version
8
 * @author Patrick Cool <[email protected]>, Ghent University, Belgium,
9
 * refactoring and tighter integration
10
 */
11
require_once __DIR__.'/../inc/global.inc.php';
12
13
$current_course_tool = TOOL_NOTEBOOK;
14
15
// The section (tabs)
16
$this_section = SECTION_COURSES;
17
18
// Notice for unauthorized people.
19
api_protect_course_script(true);
20
21
// Additional javascript
22
$htmlHeadXtra[] = NotebookManager::javascript_notebook();
23
$htmlHeadXtra[] = '<script>
24
function setFocus(){
25
    $("#note_title").focus();
26
}
27
$(function() {
28
    setFocus();
29
});
30
</script>';
31
32
// Setting the tool constants
33
$tool = TOOL_NOTEBOOK;
34
35
// Tracking
36
Event::event_access_tool(TOOL_NOTEBOOK);
0 ignored issues
show
The method event_access_tool() does not exist on Event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
Event::/** @scrutinizer ignore-call */ 
37
       event_access_tool(TOOL_NOTEBOOK);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
38
$currentUserId = api_get_user_id();
39
$action = $_GET['action'] ?? '';
40
41
$logInfo = [
42
    'tool' => TOOL_NOTEBOOK,
43
    'tool_id' => 0,
44
    'tool_id_detail' => 0,
45
    'action' => $action,
46
    'action_details' => '',
47
];
48
Event::registerLog($logInfo);
0 ignored issues
show
The method registerLog() does not exist on Event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
Event::/** @scrutinizer ignore-call */ 
49
       registerLog($logInfo);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
50
// Tool name
51
if ($action === 'addnote') {
52
    $tool = 'NoteAddNew';
53
    $interbreadcrumb[] = [
54
        'url' => 'index.php?'.api_get_cidreq(),
55
        'name' => get_lang('ToolNotebook'),
56
    ];
57
}
58
if ($action === 'editnote') {
59
    $tool = 'ModifyNote';
60
    $interbreadcrumb[] = [
61
        'url' => 'index.php?'.api_get_cidreq(),
62
        'name' => get_lang('ToolNotebook'),
63
    ];
64
}
65
66
// Displaying the header
67
Display::display_header(get_lang(ucfirst($tool)));
68
69
// Tool introduction
70
Display::display_introduction_section(TOOL_NOTEBOOK);
71
72
// Action handling: Adding a note
73
if ($action === 'addnote') {
74
    if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
75
        api_not_allowed();
76
    }
77
78
    if (!empty($_GET['isStudentView'])) {
79
        NotebookManager::display_notes();
80
        exit;
81
    }
82
83
    Session::write('notebook_view', 'creation_date');
84
85
    $form = new FormValidator(
86
        'note',
87
        'post',
88
        api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&'.api_get_cidreq()
89
    );
90
    // Setting the form elements
91
    $form->addElement('header', '', get_lang('NoteAddNew'));
92
    $form->addElement('text', 'note_title', get_lang('NoteTitle'), ['id' => 'note_title']);
93
    $form->applyFilter('text', 'html_filter');
94
    $form->applyFilter('text', 'attr_on_filter');
95
    $form->addHtmlEditor(
96
        'note_comment',
97
        get_lang('NoteComment'),
98
        false,
99
        false,
100
        api_is_allowed_to_edit() ? ['ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300'] : ['ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student']
101
    );
102
    $form->addButtonCreate(get_lang('AddNote'), 'SubmitNote');
103
104
    // Setting the rules
105
    $form->addRule('note_title', get_lang('ThisFieldIsRequired'), 'required');
106
107
    // The validation or display
108
    if ($form->validate()) {
109
        $check = Security::check_token('post');
110
        if ($check) {
111
            $values = $form->exportValues();
112
            $res = NotebookManager::save_note($values);
113
            if ($res) {
114
                echo Display::return_message(get_lang('NoteAdded'), 'confirmation');
115
            }
116
        }
117
        Security::clear_token();
118
        NotebookManager::display_notes();
119
    } else {
120
        echo Display::toolbarAction(
121
            'add_glossary',
122
            [
123
                Display::url(
124
                    Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
125
                    api_get_self().'?'.api_get_cidreq()
126
                ),
127
            ]
128
        );
129
        $token = Security::get_token();
130
        $form->addElement('hidden', 'sec_token');
131
        $form->setConstants(['sec_token' => $token]);
132
        $form->display();
133
    }
134
} elseif ($action === 'editnote' && is_numeric($_GET['notebook_id'])) {
135
    // Action handling: Editing a note
136
137
    if (!empty($_GET['isStudentView'])) {
138
        NotebookManager::display_notes();
139
        exit;
140
    }
141
142
    // Setting the defaults
143
    $defaults = NotebookManager::get_note_information((int) $_GET['notebook_id']);
144
145
    if ($currentUserId !== (int) $defaults['user_id']) {
146
        echo Display::return_message(get_lang('NotAllowed'), 'error');
147
        Display::display_footer();
148
        exit();
149
    }
150
151
    // Initialize the object
152
    $form = new FormValidator(
153
        'note',
154
        'post',
155
        api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&notebook_id='.intval($_GET['notebook_id']).'&'.api_get_cidreq()
156
    );
157
    // Setting the form elements
158
    $form->addElement('header', '', get_lang('ModifyNote'));
159
    $form->addElement('hidden', 'notebook_id');
160
    $form->addElement('text', 'note_title', get_lang('NoteTitle'), ['size' => '100']);
161
    $form->applyFilter('text', 'html_filter');
162
    $form->applyFilter('text', 'attr_on_filter');
163
    $form->addHtmlEditor(
164
        'note_comment',
165
        get_lang('NoteComment'),
166
        false,
167
        false,
168
        api_is_allowed_to_edit()
169
            ? ['ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300']
170
            : ['ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student']
171
    );
172
    $form->addButtonUpdate(get_lang('ModifyNote'), 'SubmitNote');
173
174
    $form->setDefaults($defaults);
175
176
    // Setting the rules
177
    $form->addRule('note_title', get_lang('ThisFieldIsRequired'), 'required');
178
179
    // The validation or display
180
    if ($form->validate()) {
181
        $check = Security::check_token('post');
182
        if ($check) {
183
            $values = $form->exportValues();
184
            $res = NotebookManager::update_note($values);
185
            if ($res) {
186
                echo Display::return_message(get_lang('NoteUpdated'), 'confirmation');
187
            }
188
        }
189
        Security::clear_token();
190
        NotebookManager::display_notes();
191
    } else {
192
        echo Display::toolbarAction(
193
            'add_glossary',
194
            [
195
                Display::url(
196
                    Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
197
                    api_get_self().'?'.api_get_cidreq()
198
                ),
199
            ]
200
        );
201
        $token = Security::get_token();
202
        $form->addElement('hidden', 'sec_token');
203
        $form->setConstants(['sec_token' => $token]);
204
        $form->display();
205
    }
206
} elseif ($action === 'deletenote' && is_numeric($_GET['notebook_id'])) {
207
    // Action handling: deleting a note
208
    $res = NotebookManager::delete_note($_GET['notebook_id']);
209
    if ($res) {
210
        echo Display::return_message(get_lang('NoteDeleted'), 'confirmation');
211
    }
212
213
    NotebookManager::display_notes();
214
} elseif ($action === 'changeview' &&
215
    in_array($_GET['view'], ['creation_date', 'update_date', 'title'])
216
) {
217
    // Action handling: changing the view (sorting order)
218
    switch ($_GET['view']) {
219
        case 'creation_date':
220
            if (!$_GET['direction'] || $_GET['direction'] == 'ASC') {
221
                echo Display::return_message(
222
                    get_lang('NotesSortedByCreationDateAsc'),
223
                    'confirmation'
224
                );
225
            } else {
226
                echo Display::return_message(
227
                    get_lang('NotesSortedByCreationDateDESC'),
228
                    'confirmation'
229
                );
230
            }
231
            break;
232
        case 'update_date':
233
            if (!$_GET['direction'] || $_GET['direction'] == 'ASC') {
234
                echo Display::return_message(
235
                    get_lang('NotesSortedByUpdateDateAsc'),
236
                    'confirmation'
237
                );
238
            } else {
239
                echo Display::return_message(
240
                    get_lang('NotesSortedByUpdateDateDESC'),
241
                    'confirmation'
242
                );
243
            }
244
            break;
245
        case 'title':
246
            if (!$_GET['direction'] || $_GET['direction'] == 'ASC') {
247
                echo Display::return_message(
248
                    get_lang('NotesSortedByTitleAsc'),
249
                    'confirmation'
250
                );
251
            } else {
252
                echo Display::return_message(
253
                    get_lang('NotesSortedByTitleDESC'),
254
                    'confirmation'
255
                );
256
            }
257
            break;
258
    }
259
    Session::write('notebook_view', $_GET['view']);
260
    NotebookManager::display_notes();
261
} else {
262
    NotebookManager::display_notes();
263
}
264
265
Display::display_footer();
266