Issues (2115)

public/main/notebook/index.php (2 issues)

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

37
Event::/** @scrutinizer ignore-call */ 
38
       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...
38
39
$action = isset($_GET['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 ('addnote' === $action) {
52
    $tool = 'Add new note in my personal notebook';
53
    $interbreadcrumb[] = [
54
        'url' => 'index.php?'.api_get_cidreq(),
55
        'name' => get_lang('Notebook'),
56
    ];
57
}
58
if ('editnote' === $action) {
59
    $tool = 'Edit my personal note';
60
    $interbreadcrumb[] = [
61
        'url' => 'index.php?'.api_get_cidreq(),
62
        'name' => get_lang('Notebook'),
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 ('addnote' === $action) {
74
    if (0 != api_get_session_id() && !api_is_allowed_to_session_edit(false, true)) {
75
        api_not_allowed();
76
    }
77
78
    if (!empty($_GET['isStudentView'])) {
79
        NotebookManager::display_notes();
80
        Display::display_footer();
81
82
        exit;
83
    }
84
85
    Session::write('notebook_view', 'creation_date');
86
87
    $form = new FormValidator(
88
        'note',
89
        'post',
90
        api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&'.api_get_cidreq()
91
    );
92
    // Setting the form elements
93
    $form->addElement('header', '', get_lang('Add new note in my personal notebook'));
94
    $form->addElement('text', 'note_title', get_lang('Note title'), ['id' => 'note_title']);
95
    $form->applyFilter('note_title', 'html_filter');
96
    $form->addElement(
97
        'html_editor',
98
        'note_comment',
99
        get_lang('Note details'),
100
        null,
101
        api_is_allowed_to_edit()
102
            ? ['ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300']
103
            : ['ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student']
104
    );
105
    $form->addButtonCreate(get_lang('Create note'), 'SubmitNote');
106
107
    // Setting the rules
108
    $form->addRule('note_title', get_lang('Required field'), 'required');
109
110
    // The validation or display
111
    if ($form->validate()) {
112
        $check = Security::check_token('post');
113
        if ($check) {
114
            $values = $form->exportValues();
115
            $res = NotebookManager::saveNote($values);
116
            if ($res) {
117
                echo Display::return_message(get_lang('Note added'), 'confirmation');
118
            }
119
        }
120
        Security::clear_token();
121
        NotebookManager::display_notes();
122
    } else {
123
        echo Display::toolbarAction(
124
            'add_glossary',
125
            [
126
                Display::url(
127
                    Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Back')),
128
                    api_get_self().'?'.api_get_cidreq()
129
                ),
130
            ]
131
        );
132
        $token = Security::get_token();
133
        $form->addElement('hidden', 'sec_token');
134
        $form->setConstants(['sec_token' => $token]);
135
        $form->display();
136
    }
137
} elseif ('editnote' === $action && is_numeric($_GET['notebook_id'])) {
138
    // Action handling: Editing a note
139
140
    if (!empty($_GET['isStudentView'])) {
141
        NotebookManager::display_notes();
142
        Display::display_footer();
143
144
        exit;
145
    }
146
147
    // Initialize the object
148
    $form = new FormValidator(
149
        'note',
150
        'post',
151
        api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&notebook_id='.intval($_GET['notebook_id']).'&'.api_get_cidreq()
152
    );
153
    // Setting the form elements
154
    $form->addElement('header', '', get_lang('Edit my personal note'));
155
    $form->addElement('hidden', 'notebook_id');
156
    $form->addElement('text', 'note_title', get_lang('Note title'), ['size' => '100']);
157
    $form->applyFilter('note_title', 'html_filter');
158
    $form->addElement(
159
        'html_editor',
160
        'note_comment',
161
        get_lang('Note details'),
162
        null,
163
        api_is_allowed_to_edit()
164
            ? ['ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300']
165
            : ['ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student']
166
    );
167
    $form->addButtonUpdate(get_lang('Edit my personal note'), 'SubmitNote');
168
169
    // Setting the defaults
170
    $defaults = NotebookManager::get_note_information(Security::remove_XSS($_GET['notebook_id']));
171
    $form->setDefaults($defaults);
172
173
    // Setting the rules
174
    $form->addRule('note_title', get_lang('Required field'), 'required');
175
176
    // The validation or display
177
    if ($form->validate()) {
178
        $check = Security::check_token('post');
179
        if ($check) {
180
            $values = $form->exportValues();
181
            $res = NotebookManager::updateNote($values);
182
            if ($res) {
183
                echo Display::return_message(get_lang('Note updated'), 'confirmation');
184
            }
185
        }
186
        Security::clear_token();
187
        NotebookManager::display_notes();
188
    } else {
189
        echo Display::toolbarAction(
190
            'add_glossary',
191
            [
192
                Display::url(
193
                    Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Back')),
194
                    api_get_self().'?'.api_get_cidreq()
195
                ),
196
            ]
197
        );
198
        $token = Security::get_token();
199
        $form->addElement('hidden', 'sec_token');
200
        $form->setConstants(['sec_token' => $token]);
201
        $form->display();
202
    }
203
} elseif ('deletenote' === $action && is_numeric($_GET['notebook_id'])) {
204
    // Action handling: deleting a note
205
    $res = NotebookManager::delete_note($_GET['notebook_id']);
206
    if ($res) {
207
        echo Display::return_message(get_lang('Note deleted'), 'confirmation');
208
    }
209
210
    NotebookManager::display_notes();
211
} elseif ('changeview' === $action &&
212
    in_array($_GET['view'], ['creation_date', 'update_date', 'title'])
213
) {
214
    // Action handling: changing the view (sorting order)
215
    switch ($_GET['view']) {
216
        case 'creation_date':
217
            if (!$_GET['direction'] || 'ASC' == $_GET['direction']) {
218
                echo Display::return_message(
219
                    get_lang('Notes sorted by creation date ascendant'),
220
                    'confirmation'
221
                );
222
            } else {
223
                echo Display::return_message(
224
                    get_lang('Notes sorted by creation date downward'),
225
                    'confirmation'
226
                );
227
            }
228
            break;
229
        case 'update_date':
230
            if (!$_GET['direction'] || 'ASC' == $_GET['direction']) {
231
                echo Display::return_message(
232
                    get_lang('Notes sorted by update date ascendant'),
233
                    'confirmation'
234
                );
235
            } else {
236
                echo Display::return_message(
237
                    get_lang('Notes sorted by update date downward'),
238
                    'confirmation'
239
                );
240
            }
241
            break;
242
        case 'title':
243
            if (!$_GET['direction'] || 'ASC' == $_GET['direction']) {
244
                echo Display::return_message(
245
                    get_lang('Notes sorted by title ascendant'),
246
                    'confirmation'
247
                );
248
            } else {
249
                echo Display::return_message(
250
                    get_lang('Notes sorted by title downward'),
251
                    'confirmation'
252
                );
253
            }
254
            break;
255
    }
256
    Session::write('notebook_view', $_GET['view']);
257
    NotebookManager::display_notes();
258
} else {
259
    NotebookManager::display_notes();
260
}
261
262
Display::display_footer();
263