Test Setup Failed
Push — master ( 4e700f...c7183e )
by Julito
63:12
created

CourseHome::show_navigation_menu()   C

Complexity

Conditions 11
Paths 20

Size

Total Lines 80
Code Lines 52

Duplication

Lines 4
Ratio 5 %

Importance

Changes 0
Metric Value
cc 11
eloc 52
nc 20
nop 0
dl 4
loc 80
rs 5.2653
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
use Chamilo\CourseBundle\Entity\CTool;
5
use Chamilo\CourseBundle\Entity\CLpCategory;
6
7
/**
8
 * Class CourseHome
9
 */
10
class CourseHome
11
{
12
    /**
13
     * Gets the html content to show in the 3 column view
14
     * @param string $cat
15
     * @param int $userId
16
     * @return string
17
     */
18
    public static function show_tool_3column($cat, $userId = null)
19
    {
20
        $_user = api_get_user_info($userId);
21
22
        $TBL_ACCUEIL = Database::get_course_table(TABLE_TOOL_LIST);
23
        $TABLE_TOOLS = Database::get_main_table(TABLE_MAIN_COURSE_MODULE);
24
25
        $numcols = 3;
26
        $table = new HTML_Table('width="100%"');
27
        $all_tools = array();
28
29
        $course_id = api_get_course_int_id();
30
31
        switch ($cat) {
32 View Code Duplication
            case 'Basic':
33
                $condition_display_tools = ' WHERE a.c_id = '.$course_id.' AND  a.link=t.link AND t.position="basic" ';
34
                if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
35
                    $condition_display_tools = ' WHERE a.c_id = '.$course_id.' AND a.link=t.link AND (t.position="basic" OR a.name = "'.TOOL_TRACKING.'") ';
36
                }
37
38
                $sql = "SELECT a.*, t.image img, t.row, t.column  FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
39
                        $condition_display_tools ORDER BY t.row, t.column";
40
                break;
41
            case 'External':
42
                if (api_is_allowed_to_edit()) {
43
                    $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
44
                            WHERE a.c_id = $course_id AND ((a.link=t.link AND t.position='external')
45
                            OR (a.visibility <= 1 AND (a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image))
46
                            ORDER BY a.id";
47
                } else {
48
                    $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
49
                            WHERE a.c_id = $course_id AND (a.visibility = 1 AND ((a.link=t.link AND t.position='external')
50
                            OR ((a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image)))
51
                            ORDER BY a.id";
52
                }
53
                break;
54
            case 'courseAdmin':
55
                $sql = "SELECT a.*, t.image img, t.row, t.column  FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
56
                        WHERE a.c_id = $course_id AND admin=1 AND a.link=t.link ORDER BY t.row, t.column";
57
                break;
58
59
            case 'platformAdmin':
60
                $sql = "SELECT *, image img FROM $TBL_ACCUEIL WHERE c_id = $course_id AND visibility = 2 ORDER BY id";
61
        }
62
        $result = Database::query($sql);
63
64
        // Grabbing all the tools from $course_tool_table
65
        while ($tool = Database::fetch_array($result)) {
66
            $all_tools[] = $tool;
67
        }
68
69
        $course_id = api_get_course_int_id();
70
71
        // Grabbing all the links that have the property on_homepage set to 1
72
        if ($cat == 'External') {
73
            $tbl_link = Database::get_course_table(TABLE_LINK);
74
            $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
75
            if (api_is_allowed_to_edit(null, true)) {
76
                $sql_links = "SELECT tl.*, tip.visibility
77
                              FROM $tbl_link tl
78
                              LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
79
                              WHERE 	
80
                                tl.c_id = $course_id AND
81
                                tip.c_id = $course_id AND
82
                                tl.on_homepage='1' AND
83
                				tip.visibility != 2";
84
            } else {
85
                $sql_links = "SELECT tl.*, tip.visibility
86
                                FROM $tbl_link tl
87
                                LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
88
                                WHERE 	
89
                                    tl.c_id = $course_id AND
90
                                    tip.c_id = $course_id AND
91
                                    tl.on_homepage='1' AND
92
                                    tip.visibility = 1";
93
            }
94
            $result_links = Database::query($sql_links);
95 View Code Duplication
            while ($links_row = Database::fetch_array($result_links)) {
96
                $properties = array();
97
                $properties['name'] = $links_row['title'];
98
                $properties['link'] = $links_row['url'];
99
                $properties['visibility'] = $links_row['visibility'];
100
                $properties['img'] = 'external.gif';
101
                $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&amp;id='.$links_row['id'];
102
                $all_tools[] = $properties;
103
            }
104
        }
105
106
        $cell_number = 0;
107
        // Draw line between basic and external, only if there are entries in External
108
        if ($cat == 'External' && count($all_tools)) {
109
            $table->setCellContents(0, 0, '<hr noshade="noshade" size="1"/>');
110
            $table->updateCellAttributes(0, 0, 'colspan="3"');
111
            $cell_number += $numcols;
112
        }
113
114
        foreach ($all_tools as & $tool) {
115 View Code Duplication
            if ($tool['image'] == 'scormbuilder.gif') {
116
                // check if the published learnpath is visible for student
117
                $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
118
                if (!api_is_allowed_to_edit(null, true) &&
119
                    !learnpath::is_lp_visible_for_student(
120
                        $published_lp_id,
121
                        api_get_user_id(),
122
                        api_get_course_id(),
123
                        api_get_session_id()
124
                    )
125
                ) {
126
                    continue;
127
                }
128
            }
129
130 View Code Duplication
            if (api_get_session_id() != 0 &&
131
                in_array($tool['name'], array('course_maintenance', 'course_setting'))
132
            ) {
133
                continue;
134
            }
135
136
            $cell_content = '';
137
            // The name of the tool
138
            $tool_name = self::translate_tool_name($tool);
139
140
            $link_annex = '';
141
            // The url of the tool
142
            if ($tool['img'] != 'external.gif') {
143
                $tool['link'] = api_get_path(WEB_CODE_PATH).$tool['link'];
144
                $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
145
                $link_annex = $qm_or_amp.api_get_cidreq();
146
            } else {
147
                // If an external link ends with 'login=', add the actual login...
148
                $pos = strpos($tool['link'], '?login=');
149
                $pos2 = strpos($tool['link'], '&amp;login=');
150
                if ($pos !== false or $pos2 !== false) {
151
                    $link_annex = $_user['username'];
152
                }
153
            }
154
155
            // Setting the actual image url
156
            $tool['img'] = Display::returnIconPath($tool['img']);
157
158
            // VISIBLE
159
            if (($tool['visibility'] ||
160
                ((api_is_coach() || api_is_course_tutor()) && $tool['name'] == TOOL_TRACKING)) ||
161
                $cat == 'courseAdmin' || $cat == 'platformAdmin'
162
            ) {
163
                if (strpos($tool['name'], 'visio_') !== false) {
164
                    $cell_content .= '<a  href="javascript: void(0);" onclick="javascript: window.open(\''.$tool['link'].$link_annex.'\',\'window_visio'.api_get_course_id().'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'"><img src="'.$tool['img'].'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
165 View Code Duplication
                } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
166
                    $cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$tool['link'].$link_annex.'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'"><img src="'.$tool['img'].'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
167
                    // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
168
                } else {
169
                    $cell_content .= '<a href="'.$tool['link'].$link_annex.'" target="'.$tool['target'].'"><img src="'.$tool['img'].'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
170
                    // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
171
                }
172
            } else {
173
                // INVISIBLE
174
                if (api_is_allowed_to_edit(null, true)) {
175
                    if (strpos($tool['name'], 'visio_') !== false) {
176
                        $cell_content .= '<a  href="javascript: void(0);" onclick="window.open(\''.$tool['link'].$link_annex.'\',\'window_visio'.api_get_course_id().'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'"><img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
177 View Code Duplication
                    } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
178
                        $cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$tool['link'].$link_annex.'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'" class="text-muted"><img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
179
                        // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
180
                    } else {
181
                        $cell_content .= '<a href="'.$tool['link'].$link_annex.'" target="'.$tool['target'].'" class="text-muted">
182
                                            <img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
183
                        // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
184
                    }
185
                } else {
186
                    $cell_content .= '<img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">';
187
                    // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
188
                    $cell_content .= '<span class="text-muted">'.$tool_name.'</span>';
189
                }
190
            }
191
192
            $lnk = array();
193
            if (api_is_allowed_to_edit(null, true) &&
194
                $cat != "courseAdmin" &&
195
                !strpos($tool['link'], 'learnpath_handler.php?learnpath_id') &&
196
                !api_is_coach()
197
            ) {
198
                if ($tool['visibility']) {
199
                    $link['name'] = Display::return_icon(
200
                        'remove.gif',
201
                        get_lang('Deactivate'),
202
                        array('style' => 'vertical-align: middle;')
203
                    );
204
                    $link['cmd'] = "hide=yes";
205
                    $lnk[] = $link;
206
                } else {
207
                    $link['name'] = Display::return_icon(
208
                        'add.gif',
209
                        get_lang('Activate'),
210
                        array('style' => 'vertical-align: middle;')
211
                    );
212
                    $link['cmd'] = "restore=yes";
213
                    $lnk[] = $link;
214
                }
215
                if (is_array($lnk)) {
216
                    foreach ($lnk as & $this_lnk) {
217
                        if ($tool['adminlink']) {
218
                            $cell_content .= '<a href="'.$properties['adminlink'].'">'.
219
                                Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
220
                        } else {
221
                            $cell_content .= '<a href="'.api_get_self().'?id='.$tool['id'].'&amp;'.$this_lnk['cmd'].'">'.$this_lnk['name'].'</a>';
222
                        }
223
                    }
224
                }
225
            }
226
            $table->setCellContents($cell_number / $numcols, ($cell_number) % $numcols, $cell_content);
227
            $table->updateCellAttributes($cell_number / $numcols, ($cell_number) % $numcols, 'width="32%" height="42"');
228
            $cell_number++;
229
        }
230
231
        return $table->toHtml();
232
    }
233
234
    /**
235
     * Displays the tools of a certain category.
236
     *
237
     * @return void
238
     * @param string $course_tool_category	contains the category of tools to display:
239
     * "Public", "PublicButHide", "courseAdmin", "claroAdmin"
240
     */
241
    public static function show_tool_2column($course_tool_category)
242
    {
243
        $html = '';
244
        $web_code_path = api_get_path(WEB_CODE_PATH);
245
        $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
246
247
        $course_id = api_get_course_int_id();
248
249
        switch ($course_tool_category) {
250 View Code Duplication
            case TOOL_PUBLIC:
251
                $condition_display_tools = ' WHERE c_id = '.$course_id.' AND visibility = 1 ';
252
                if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
253
                    $condition_display_tools = ' WHERE c_id = '.$course_id.' AND (visibility = 1 OR (visibility = 0 AND name = "'.TOOL_TRACKING.'")) ';
254
                }
255
                $result = Database::query("SELECT * FROM $course_tool_table $condition_display_tools ORDER BY id");
256
                $col_link = "##003399";
257
                break;
258
            case TOOL_PUBLIC_BUT_HIDDEN:
259
                $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility=0 AND admin=0 ORDER BY id");
260
                $col_link = "##808080";
261
                break;
262
            case TOOL_COURSE_ADMIN:
263
                $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND admin=1 AND visibility != 2 ORDER BY id");
264
                $col_link = "##003399";
265
                break;
266
            case TOOL_PLATFORM_ADMIN:
267
                $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility = 2  ORDER BY id");
268
                $col_link = "##003399";
269
        }
270
        $i = 0;
271
272
        // Grabbing all the tools from $course_tool_table
273
        while ($temp_row = Database::fetch_array($result)) {
274
            if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN && $temp_row['image'] != 'scormbuilder.gif') {
275
                $temp_row['image'] = str_replace('.gif', '_na.gif', $temp_row['image']);
276
            }
277
            $all_tools_list[] = $temp_row;
278
        }
279
280
        // Grabbing all the links that have the property on_homepage set to 1
281
        $course_link_table = Database::get_course_table(TABLE_LINK);
282
        $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
283
284
        switch ($course_tool_category) {
285
            case TOOL_PUBLIC:
286
                $sql_links = "SELECT tl.*, tip.visibility
287
                        FROM $course_link_table tl
288
                        LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tl.c_id = tip.c_id AND tl.c_id = $course_id AND tip.ref=tl.id
289
                        WHERE tl.on_homepage='1' AND tip.visibility = 1";
290
                break;
291
            case TOOL_PUBLIC_BUT_HIDDEN:
292
                $sql_links = "SELECT tl.*, tip.visibility
293
                    FROM $course_link_table tl
294
                    LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tl.c_id = tip.c_id AND tl.c_id = $course_id AND tip.ref=tl.id
295
                    WHERE tl.on_homepage='1' AND tip.visibility = 0";
296
297
                break;
298
            default:
299
                $sql_links = null;
300
                break;
301
        }
302
        if ($sql_links != null) {
303
            $properties = array();
304
            $result_links = Database::query($sql_links);
305 View Code Duplication
            while ($links_row = Database::fetch_array($result_links)) {
306
                unset($properties);
307
                $properties['name'] = $links_row['title'];
308
                $properties['link'] = $links_row['url'];
309
                $properties['visibility'] = $links_row['visibility'];
310
                $properties['image'] = $course_tool_category == TOOL_PUBLIC_BUT_HIDDEN ? 'external_na.gif' : 'external.gif';
311
                $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
312
                $all_tools_list[] = $properties;
313
            }
314
        }
315
        if (isset($all_tools_list)) {
316
            $lnk = array();
317
            foreach ($all_tools_list as & $tool) {
318 View Code Duplication
                if ($tool['image'] == 'scormbuilder.gif') {
319
                    // check if the published learnpath is visible for student
320
                    $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
321
322
                    if (!api_is_allowed_to_edit(null, true) &&
323
                        !learnpath::is_lp_visible_for_student(
324
                            $published_lp_id,
325
                            api_get_user_id(),
326
                            api_get_course_id(),
327
                            api_get_session_id()
328
                        )
329
                    ) {
330
                        continue;
331
                    }
332
                }
333
334 View Code Duplication
                if (api_get_session_id() != 0 &&
335
                    in_array($tool['name'], array('course_maintenance', 'course_setting'))
336
                ) {
337
                    continue;
338
                }
339
340
                if (!($i % 2)) {
341
                    $html .= "<tr valign=\"top\">";
342
                }
343
344
                // NOTE : Table contains only the image file name, not full path
345 View Code Duplication
                if (stripos($tool['link'], 'http://') === false &&
346
                    stripos($tool['link'], 'https://') === false &&
347
                    stripos($tool['link'], 'ftp://') === false
348
                ) {
349
                    $tool['link'] = $web_code_path.$tool['link'];
350
                }
351
                $class = '';
352
                if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) {
353
                    $class = 'class="text-muted"';
354
                }
355
                $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
356
357
                $tool['link'] = $tool['link'];
358
                $html .= '<td width="50%" height="30">';
359
360
                if (strpos($tool['name'], 'visio_') !== false) {
361
                    $html .= '<a  '.$class.' href="javascript: void(0);" onclick="javascript: window.open(\''.htmlspecialchars($tool['link']).(($tool['image'] == 'external.gif' || $tool['image'] == 'external_na.gif') ? '' : $qm_or_amp.api_get_cidreq()).'\',\'window_visio'.api_get_course_id().'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'">';
362
                } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
363
                    $html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.htmlspecialchars($tool['link']).$qm_or_amp.api_get_cidreq().'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'" '.$class.'>';
364
                } else {
365
                    $html .= '<a href="'.htmlspecialchars($tool['link']).(($tool['image'] == 'external.gif' || $tool['image'] == 'external_na.gif') ? '' : $qm_or_amp.api_get_cidreq()).'" target="'.$tool['target'].'" '.$class.'>';
366
                }
367
368
                $tool_name = self::translate_tool_name($tool);
369
                $html .= Display::return_icon(
370
                        $tool['image'],
371
                        $tool_name,
372
                        array(),
373
                        null,
374
                        ICON_SIZE_MEDIUM
375
                    ).'&nbsp;'.$tool_name.'</a>';
376
377
                // This part displays the links to hide or remove a tool.
378
                // These links are only visible by the course manager.
379
                unset($lnk);
380
                if (api_is_allowed_to_edit(null, true) && !api_is_coach()) {
381 View Code Duplication
                    if ($tool['visibility'] == '1' || $tool['name'] == TOOL_TRACKING) {
382
                        $link['name'] = Display::returnFontAwesomeIcon('minus');
383
                        $link['title'] = get_lang('Deactivate');
384
                        $link['cmd'] = 'hide=yes';
385
                        $lnk[] = $link;
386
                    }
387
388 View Code Duplication
                    if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) {
389
                        //$link['name'] = Display::return_icon('add.gif', get_lang('Activate'));
390
                        $link['name'] = Display::returnFontAwesomeIcon('plus');
391
                        $link['title'] = get_lang('Activate');
392
                        $link['cmd'] = 'restore=yes';
393
                        $lnk[] = $link;
394
395
                        if ($tool['added_tool'] == 1) {
396
                            //$link['name'] = Display::return_icon('delete.gif', get_lang('Remove'));
397
                            $link['name'] = Display::returnFontAwesomeIcon('trash');
398
                            $link['title'] = get_lang('Remove');
399
                            $link['cmd'] = 'remove=yes';
400
                            $lnk[] = $link;
401
                        }
402
                    }
403
                    if (isset($tool['adminlink'])) {
404
                        $html .= '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
405
                    }
406
                }
407
                if (api_is_platform_admin() && !api_is_coach()) {
408 View Code Duplication
                    if ($tool['visibility'] == 2) {
409
                        $link['name'] = Display::returnFontAwesomeIcon('undo');
410
                        $link['title'] = get_lang('Activate');
411
                        $link['cmd'] = 'hide=yes';
412
                        $lnk[] = $link;
413
414
                        if ($tool['added_tool'] == 1) {
415
                            $link['name'] = get_lang('Delete');
416
                            $link['cmd'] = 'askDelete=yes';
417
                            $lnk[] = $link;
418
                        }
419
                    }
420 View Code Duplication
                    if ($tool['visibility'] == 0 && $tool['added_tool'] == 0) {
421
                        $link['name'] = Display::returnFontAwesomeIcon('trash');
422
                        $link['title'] = get_lang('Remove');
423
                        $link['cmd'] = 'remove=yes';
424
                        $lnk[] = $link;
425
                    }
426
                }
427
                if (is_array($lnk)) {
428
                    $html .= '<div class="pull-right">';
429
                    $html .= '<div class="btn-options">';
430
                    $html .= '<div class="btn-group btn-group-sm" role="group">';
431 View Code Duplication
                    foreach ($lnk as & $this_link) {
432
                        if (!isset($tool['adminlink'])) {
433
                            $html .= '<a class="btn btn-default" title='.$this_link['title'].' href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$tool['id'].'&amp;'.$this_link['cmd'].'">'.$this_link['name'].'</a>';
434
                        }
435
                    }
436
                    $html .= '</div>';
437
                    $html .= '</div>';
438
                    $html .= '</div>';
439
                }
440
                $html .= "</td>";
441
442
                if ($i % 2) {
443
                    $html .= "</tr>";
444
                }
445
446
                $i++;
447
            }
448
        }
449
450
        if ($i % 2) {
451
            $html .= "<td width=\"50%\">&nbsp;</td></tr>";
452
        }
453
454
        return $html;
455
    }
456
457
    /**
458
     * Gets the tools of a certain category. Returns an array expected
459
     * by show_tools_category()
460
     * @param string $course_tool_category contains the category of tools to
461
     * display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform", "toolplugin"
462
     * @param int $courseId Optional
463
     * @param int $sessionId Optional
464
     * @return array
465
     */
466
    public static function get_tools_category($course_tool_category, $courseId = 0, $sessionId = 0)
467
    {
468
        $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
469
        $is_platform_admin = api_is_platform_admin();
470
        $all_tools_list = array();
471
472
        // Condition for the session
473
        $session_id = $sessionId ?: api_get_session_id();
474
        $course_id = $courseId ?: api_get_course_int_id();
475
        $userId = api_get_user_id();
476
        $user = api_get_user_entity($userId);
477
        $condition_session = api_get_session_condition(
478
            $session_id,
479
            true,
480
            true,
481
            't.session_id'
482
        );
483
484
        switch ($course_tool_category) {
485
            case TOOL_STUDENT_VIEW:
486
                $conditions = ' WHERE visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") ';
487
                if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
488
                    $conditions = ' WHERE (visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") OR (name = "'.TOOL_TRACKING.'") )   ';
489
                }
490
                $sql = "SELECT *
491
                        FROM $course_tool_table t
492
                        $conditions AND
493
                        c_id = $course_id $condition_session
494
                        ORDER BY id";
495
                $result = Database::query($sql);
496
                break;
497
            case TOOL_AUTHORING:
498
                $sql = "SELECT * FROM $course_tool_table t
499
                        WHERE category = 'authoring' AND c_id = $course_id $condition_session
500
                        ORDER BY id";
501
                $result = Database::query($sql);
502
                break;
503
            case TOOL_INTERACTION:
504
                $sql = "SELECT * FROM $course_tool_table t
505
                        WHERE category = 'interaction' AND c_id = $course_id $condition_session
506
                        ORDER BY id";
507
                $result = Database::query($sql);
508
                break;
509
            case TOOL_ADMIN_VISIBLE:
510
                $sql = "SELECT * FROM $course_tool_table t
511
                        WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session
512
                        ORDER BY id";
513
                $result = Database::query($sql);
514
                break;
515
            case TOOL_ADMIN_PLATFORM:
516
                $sql = "SELECT * FROM $course_tool_table t
517
                        WHERE category = 'admin' AND c_id = $course_id $condition_session
518
                        ORDER BY id";
519
                $result = Database::query($sql);
520
                break;
521
            case TOOL_DRH:
522
                $sql = "SELECT * FROM $course_tool_table t
523
                        WHERE name IN ('tracking') AND c_id = $course_id $condition_session
524
                        ORDER BY id";
525
                $result = Database::query($sql);
526
                break;
527
            case TOOL_COURSE_PLUGIN:
528
                //Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id
529
                // but plugins are not present in the tool table, only globally and inside the course_settings table once configured
530
                $sql = "SELECT * FROM $course_tool_table t
531
                        WHERE category = 'plugin' AND name <> 'courseblock' AND c_id = $course_id $condition_session
532
                        ORDER BY id";
533
                $result = Database::query($sql);
534
                break;
535
        }
536
537
        //Get the list of hidden tools - this might imply performance slowdowns
538
        // if the course homepage is loaded many times, so the list of hidden
539
        // tools might benefit from a shared memory storage later on
540
        $list = api_get_settings('Tools', 'list', api_get_current_access_url_id());
541
        $hide_list = array();
542
        $check = false;
543
544
        foreach ($list as $line) {
545
            // Admin can see all tools even if the course_hide_tools configuration is set
546
            if ($is_platform_admin) {
547
                continue;
548
            }
549
            if ($line['variable'] == 'course_hide_tools' and $line['selected_value'] == 'true') {
550
                $hide_list[] = $line['subkey'];
551
                $check = true;
552
            }
553
        }
554
555
        $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session');
556
        while ($temp_row = Database::fetch_assoc($result)) {
557
            $add = false;
558
            if ($check) {
559
                if (!in_array($temp_row['name'], $hide_list)) {
560
                    $add = true;
561
                }
562
            } else {
563
                $add = true;
564
            }
565
566
            if ($allowEditionInSession && !empty($session_id)) {
567
                // Checking if exist row in session
568
                $criteria = [
569
                    'cId' => $course_id,
570
                    'name' => $temp_row['name'],
571
                    'sessionId' => $session_id,
572
                ];
573
                /** @var CTool $tool */
574
                $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria);
575
                if ($toolObj) {
576
                    if ($toolObj->getVisibility() == 0) {
577
                        continue;
578
                    }
579
                }
580
            }
581
582
            if ($temp_row['image'] == 'scormbuilder.gif') {
583
                $lp_id = self::get_published_lp_id_from_link($temp_row['link']);
584
                $lp = new learnpath(
585
                    api_get_course_id(),
586
                    $lp_id,
587
                    $userId
588
                );
589
                $path = $lp->get_preview_image_path(ICON_SIZE_BIG);
590
                $add = learnpath::is_lp_visible_for_student(
591
                    $lp_id,
592
                    $userId,
593
                    api_get_course_id(),
594
                    api_get_session_id()
595
                );
596
                if ($path) {
597
                    $temp_row['custom_image'] = $path;
598
                }
599
            }
600
601
            if ($temp_row['image'] === 'lp_category.gif') {
602
                $lpCategory = self::getPublishedLpCategoryFromLink(
603
                    $temp_row['link']
604
                );
605
                $add = learnpath::categoryIsVisibleForStudent(
606
                    $lpCategory,
607
                    $user
608
                );
609
            }
610
611
            if ($add) {
612
                $all_tools_list[] = $temp_row;
613
            }
614
        }
615
616
        // Grabbing all the links that have the property on_homepage set to 1
617
        $course_link_table = Database::get_course_table(TABLE_LINK);
618
        $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
619
        $condition_session = api_get_session_condition(
620
            $session_id,
621
            true,
622
            true,
623
            'tip.session_id'
624
        );
625
626
        switch ($course_tool_category) {
627
            case TOOL_AUTHORING:
628
                $sql_links = "SELECT tl.*, tip.visibility
629
                    FROM $course_link_table tl
630
                    LEFT JOIN $course_item_property_table tip
631
                    ON tip.tool='link' AND tip.ref=tl.id
632
                    WHERE
633
                        tl.c_id = $course_id AND
634
                        tip.c_id = $course_id AND
635
                        tl.on_homepage='1' $condition_session";
636
                break;
637
            case TOOL_INTERACTION:
638
                $sql_links = null;
639
                /*
640
                  $sql_links = "SELECT tl.*, tip.visibility
641
                  FROM $course_link_table tl
642
                  LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
643
                  WHERE tl.on_homepage='1' ";
644
                 */
645
                break;
646
            case TOOL_STUDENT_VIEW:
647
                $sql_links = "SELECT tl.*, tip.visibility
648
                    FROM $course_link_table tl
649
                    LEFT JOIN $course_item_property_table tip
650
                    ON tip.tool='link' AND tip.ref=tl.id
651
                    WHERE
652
                        tl.c_id 		= $course_id AND
653
                        tip.c_id 		= $course_id AND
654
                        tl.on_homepage	='1' $condition_session";
655
                break;
656
            case TOOL_ADMIN:
657
                $sql_links = "SELECT tl.*, tip.visibility
658
                    FROM $course_link_table tl
659
                    LEFT JOIN $course_item_property_table tip
660
                    ON tip.tool='link' AND tip.ref=tl.id
661
                    WHERE
662
                        tl.c_id = $course_id AND
663
                        tip.c_id = $course_id AND
664
                        tl.on_homepage='1' $condition_session";
665
                break;
666
            default:
667
                $sql_links = null;
668
                break;
669
        }
670
671
        // Edited by Kevin Van Den Haute ([email protected]) for integrating Smartblogs
672
        if ($sql_links != null) {
673
            $result_links = Database::query($sql_links);
674
675
            if (Database::num_rows($result_links) > 0) {
676
                while ($links_row = Database::fetch_array($result_links, 'ASSOC')) {
677
                    $properties = array();
678
                    $properties['name'] = $links_row['title'];
679
                    $properties['session_id'] = $links_row['session_id'];
680
                    $properties['link'] = $links_row['url'];
681
                    $properties['visibility'] = $links_row['visibility'];
682
                    $properties['image'] = $links_row['visibility'] == '0' ? 'file_html.png' : 'file_html.png';
683
                    $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
684
                    $properties['target'] = $links_row['target'];
685
                    $tmp_all_tools_list[] = $properties;
686
                }
687
            }
688
        }
689
690
        if (isset($tmp_all_tools_list)) {
691
            foreach ($tmp_all_tools_list as $tool) {
692
                if ($tool['image'] == 'blog.gif') {
693
                    // Init
694
                    $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
695
696
                    // Get blog id
697
                    $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
698
699
                    // Get blog members
700
                    if ($is_platform_admin) {
701
                        $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
702
                                      WHERE blog_id =".$blog_id;
703
                    } else {
704
                        $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
705
                                      WHERE blog_id =".$blog_id." AND user_id = ".$userId;
706
                    }
707
                    $result_blogs = Database::query($sql_blogs);
708
709
                    if (Database::num_rows($result_blogs) > 0) {
710
                        $all_tools_list[] = $tool;
711
                    }
712
                } else {
713
                    $all_tools_list[] = $tool;
714
                }
715
            }
716
        }
717
718
        return $all_tools_list;
719
    }
720
721
    /**
722
     * Displays the tools of a certain category.
723
     * @param array $all_tools_list List of tools as returned by get_tools_category()
724
     * @param bool  $rows
725
     *
726
     * @return string
727
     */
728
    public static function show_tools_category($all_tools_list, $rows = false)
729
    {
730
        $_user = api_get_user_info();
731
        $theme = api_get_setting('homepage_view');
732
        if ($theme === 'vertical_activity') {
733
            //ordering by get_lang name
734
            $order_tool_list = array();
735
            if (is_array($all_tools_list) && count($all_tools_list) > 0) {
736
                foreach ($all_tools_list as $key => $new_tool) {
737
                    $tool_name = self::translate_tool_name($new_tool);
738
                    $order_tool_list [$key] = $tool_name;
739
                }
740
                natsort($order_tool_list);
741
                $my_temp_tool_array = array();
742
                foreach ($order_tool_list as $key => $new_tool) {
743
                    $my_temp_tool_array[] = $all_tools_list[$key];
744
                }
745
                $all_tools_list = $my_temp_tool_array;
746
            } else {
747
                $all_tools_list = array();
748
            }
749
        }
750
        $web_code_path = api_get_path(WEB_CODE_PATH);
751
        $session_id = api_get_session_id();
752
        $is_platform_admin = api_is_platform_admin();
753
        $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session');
754
755
        if ($session_id == 0) {
756
            $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin();
757
        } else {
758
            $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach();
759
            if ($allowEditionInSession) {
760
                $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_coach($session_id, api_get_course_int_id());
761
            }
762
        }
763
764
        $i = 0;
765
        $items = array();
766
        $app_plugin = new AppPlugin();
767
768
        if (isset($all_tools_list)) {
769
            $lnk = '';
770
            foreach ($all_tools_list as & $tool) {
771
                $item = array();
772
                $studentview = false;
773
                $tool['original_link'] = $tool['link'];
774
                if ($tool['image'] == 'scormbuilder.gif') {
775
                    // check if the published learnpath is visible for student
776
                    $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
777
                    if (api_is_allowed_to_edit(null, true)) {
778
                        $studentview = true;
779
                    }
780
                    if (!api_is_allowed_to_edit(null, true) &&
781
                        !learnpath::is_lp_visible_for_student(
782
                            $published_lp_id,
783
                            api_get_user_id(),
784
                            api_get_course_id(),
785
                            api_get_session_id()
786
                        )
787
                    ) {
788
                        continue;
789
                    }
790
                }
791
792
                if ($session_id != 0 && in_array($tool['name'], array('course_setting'))) {
793
                    continue;
794
                }
795
796
                // This part displays the links to hide or remove a tool.
797
                // These links are only visible by the course manager.
798
                unset($lnk);
799
800
                $item['extra'] = null;
801
                $toolAdmin = isset($tool['admin']) ? $tool['admin'] : '';
802
803
                if ($is_allowed_to_edit) {
804
                    if (empty($session_id)) {
805
                        if (isset($tool['id'])) {
806 View Code Duplication
                            if ($tool['visibility'] == '1' && $toolAdmin != '1') {
807
                                $link['name'] = Display::return_icon(
808
                                    'visible.png',
809
                                    get_lang('Deactivate'),
810
                                    array('id' => 'linktool_'.$tool['iid']),
811
                                    ICON_SIZE_SMALL,
812
                                    false
813
                                );
814
                                $link['cmd'] = 'hide=yes';
815
                                $lnk[] = $link;
816
                            }
817 View Code Duplication
                            if ($tool['visibility'] == '0' && $toolAdmin != '1') {
818
                                $link['name'] = Display::return_icon(
819
                                    'invisible.png',
820
                                    get_lang('Activate'),
821
                                    array('id' => 'linktool_'.$tool['iid']),
822
                                    ICON_SIZE_SMALL,
823
                                    false
824
                                );
825
                                $link['cmd'] = 'restore=yes';
826
                                $lnk[] = $link;
827
                            }
828
                        }
829
                    } elseif ($allowEditionInSession) {
830
                        $criteria = [
831
                            'cId' => api_get_course_int_id(),
832
                            'name' => $tool['name'],
833
                            'sessionId' => $session_id
834
                        ];
835
                        /** @var CTool $tool */
836
                        $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria);
837
                        if ($toolObj) {
838
                            $visibility = $toolObj->getVisibility();
839
                            switch ($visibility) {
840 View Code Duplication
                                case '0':
841
                                    $link['name'] = Display::return_icon(
842
                                        'invisible.png',
843
                                        get_lang('Activate'),
844
                                        array('id' => 'linktool_'.$tool['iid']),
845
                                        ICON_SIZE_SMALL,
846
                                        false
847
                                    );
848
                                    $link['cmd'] = 'restore=yes';
849
                                    $lnk[] = $link;
850
                                    break;
851 View Code Duplication
                                case '1':
852
                                    $link['name'] = Display::return_icon(
853
                                        'visible.png',
854
                                        get_lang('Deactivate'),
855
                                        array('id' => 'linktool_'.$tool['iid']),
856
                                        ICON_SIZE_SMALL,
857
                                        false
858
                                    );
859
                                    $link['cmd'] = 'hide=yes';
860
                                    $lnk[] = $link;
861
                                    break;
862
                            }
863 View Code Duplication
                        } else {
864
                            $link['name'] = Display::return_icon(
865
                                'visible.png',
866
                                get_lang('Deactivate'),
867
                                array('id' => 'linktool_'.$tool['iid']),
868
                                ICON_SIZE_SMALL,
869
                                false
870
                            );
871
                            $link['cmd'] = 'hide=yes';
872
                            $lnk[] = $link;
873
                        }
874
                    }
875
                    if (!empty($tool['adminlink'])) {
876
                        $item['extra'] = '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
877
                    }
878
                }
879
880
                // Both checks are necessary as is_platform_admin doesn't take student view into account
881
                if ($is_platform_admin && $is_allowed_to_edit) {
882
                    if ($toolAdmin != '1') {
883
                        $link['cmd'] = 'hide=yes';
884
                    }
885
                }
886
887
                $item['visibility'] = null;
888
                if (isset($lnk) && is_array($lnk)) {
889 View Code Duplication
                    foreach ($lnk as $this_link) {
890
                        if (empty($tool['adminlink'])) {
891
                            $item['visibility'] .= '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&id='.$tool['iid'].'&'.$this_link['cmd'].'">'.
892
                                $this_link['name'].'</a>';
893
                        }
894
                    }
895
                } else {
896
                    $item['visibility'] .= '';
897
                }
898
899
                // NOTE : Table contains only the image file name, not full path
900 View Code Duplication
                if (stripos($tool['link'], 'http://') === false &&
901
                    stripos($tool['link'], 'https://') === false &&
902
                    stripos($tool['link'], 'ftp://') === false
903
                ) {
904
                    $tool['link'] = $web_code_path.$tool['link'];
905
                }
906
907
                if ($tool['visibility'] == '0' && $toolAdmin != '1') {
908
                    $class = 'text-muted';
909
                    $info = pathinfo($tool['image']);
910
                    $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
911
                    $tool['image'] = $basename.'_na.'.$info['extension'];
912
                } else {
913
                    $class = '';
914
                }
915
916
                $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
917
                // If it's a link, we don't add the cidReq
918
919
                if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') {
920
                    $tool['link'] = $tool['link'].$qm_or_amp;
921
                } else {
922
                    $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
923
                }
924
925
                $tool_link_params = array();
926
                $toolIid = isset($tool["iid"]) ? $tool["iid"] : null;
927
928
                //@todo this visio stuff should be removed
929
                if (strpos($tool['name'], 'visio_') !== false) {
930
                    $tool_link_params = array(
931
                        'id' => 'tooldesc_'.$toolIid,
932
                        'href' => '"javascript: void(0);"',
933
                        'class' => $class,
934
                        'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_visio'.api_get_course_id().'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')',
935
                        'target' => $tool['target']
936
                    );
937
                } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
938
                    $tool_link_params = array(
939
                        'id' => 'tooldesc_'.$toolIid,
940
                        'class' => $class,
941
                        'href' => 'javascript: void(0);',
942
                        'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', //Chat Open Windows
943
                        'target' => $tool['target']
944
                    );
945
                } else {
946
                    $tool_link_params = array(
947
                        'id' => 'tooldesc_'.$toolIid,
948
                        'href' => $tool['link'],
949
                        'class' => $class,
950
                        'target' => $tool['target']
951
                    );
952
                }
953
954
                $tool_name = self::translate_tool_name($tool);
0 ignored issues
show
Bug introduced by
It seems like $tool can also be of type object<Chamilo\CourseBundle\Entity\CTool>; however, CourseHome::translate_tool_name() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
955
956
                // Including Courses Plugins
957
                // Creating title and the link
958
                if (isset($tool['category']) && $tool['category'] == 'plugin') {
959
                    $plugin_info = $app_plugin->getPluginInfo($tool['name']);
960
                    if (isset($plugin_info) && isset($plugin_info['title'])) {
961
                        $tool_name = $plugin_info['title'];
962
                    }
963
964 View Code Duplication
                    if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) &&
965
                        !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/64/'.$tool['image'])) {
966
                        $tool['image'] = 'plugins.png';
967
                    }
968
                    $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH)
969
                        .$tool['original_link'].$qm_or_amp.api_get_cidreq();
970
                }
971
972
                $icon = Display::return_icon(
973
                    $tool['image'],
974
                    $tool_name,
975
                    array('class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid),
976
                    ICON_SIZE_BIG,
977
                    false
978
                );
979
980
                /*if (!empty($tool['custom_icon'])) {
981
                    $image = self::getCustomWebIconPath().$tool['custom_icon'];
982
                    $icon = Display::img(
983
                        $image,
984
                        $tool['description'],
985
                        array(
986
                            'class' => 'tool-icon',
987
                            'id' => 'toolimage_'.$tool['id']
988
                        )
989
                    );
990
                }*/
991
992
                // Validation when belongs to a session
993
                $session_img = api_get_session_image($tool['session_id'], (!empty($_user['status']) ? $_user['status'] : ''));
994
                if ($studentview) {
995
                    $tool_link_params['href'] .= '&isStudentView=true';
996
                }
997
                $item['url_params'] = $tool_link_params;
998
                $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params);
999
                $item['tool'] = $tool;
1000
                $item['name'] = $tool_name;
1001
                $tool_link_params['id'] = 'is'.$tool_link_params['id'];
1002
                $item['link'] = Display::url(
1003
                    $tool_name.$session_img,
1004
                    $tool_link_params['href'],
1005
                    $tool_link_params
1006
                );
1007
1008
                $items[] = $item;
1009
1010
                $i++;
1011
            } // end of foreach
1012
        }
1013
1014
        $i = 0;
1015
        $html = '';
1016
1017
        if (!empty($items)) {
1018
            foreach ($items as $item) {
1019
                switch ($theme) {
1020
                    case 'activity_big':
1021
                        $data = '';
1022
                        $html .= '<div class="col-xs-6 col-md-3 course-tool">';
1023
                        $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png';
1024
                        $toolId = isset($item['tool']['id']) ? $item['tool']['id'] : null;
1025
1026
                        if (isset($item['tool']['custom_image'])) {
1027
                            $original_image = Display::img(
1028
                                $item['tool']['custom_image'],
1029
                                $item['name'],
1030
                                array('id' => 'toolimage_'.$toolId)
1031
                            );
1032
                        } elseif (isset($item['tool']['custom_icon']) &&
1033
                            !empty($item['tool']['custom_icon'])
1034
                        ) {
1035
                            $customIcon = $item['tool']['custom_icon'];
1036
                            if ($item['tool']['visibility'] == '0') {
1037
                                $fileInfo = pathinfo($item['tool']['custom_icon']);
1038
                                $customIcon = self::getDisableIcon($item['tool']['custom_icon']);
1039
                            }
1040
                            $original_image = Display::img(
1041
                                self::getCustomWebIconPath().$customIcon,
1042
                                $item['name'],
1043
                                array('id' => 'toolimage_'.$toolId)
1044
                            );
1045
                        } else {
1046
                            $original_image = Display::return_icon(
1047
                                $image,
1048
                                $item['name'],
1049
                                array('id' => 'toolimage_'.$toolId),
1050
                                ICON_SIZE_BIG,
1051
                                false
1052
                            );
1053
                        }
1054
1055
                        $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']);
1056
                        $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection
1057
                        $html .= Display::div('<h4>'.$item['visibility'].$item['extra'].$item['link'].'</h4>', array('class' => 'content'));
1058
                        $html .= '</div>';
1059
1060
                        break;
1061
                    case 'activity':
1062
                        $html .= '<div class="offset2 col-md-4 course-tool">';
1063
                        $html .= $item['extra'];
1064
                        $html .= $item['visibility'];
1065
                        $html .= $item['icon'];
1066
                        $html .= $item['link'];
1067
                        $html .= '</div>';
1068
                        break;
1069
                    case 'vertical_activity':
1070
                        if ($i == 0) {
1071
                            $html .= '<ul>';
1072
                        }
1073
                        $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png';
1074
                        $original_image = Display::return_icon(
1075
                                $image,
1076
                                $item['name'],
1077
                                array('id' => 'toolimage_'.$item['tool']['id']),
1078
                                ICON_SIZE_SMALL,
1079
                                false
1080
                            );
1081
                        $html .= '<li class="course-tool">';
1082
                        $html .= $item['extra'];
1083
                        $html .= $item['visibility'];
1084
                        $url = Display::url($original_image, $item['url_params']['href'], $item['url_params']);
1085
                        $html .= $url;
1086
                        $html .= $item['link'];
1087
                        $html .= '</li>';
1088
1089
                        if ($i == count($items) - 1) {
1090
                            $html .= '</ul>';
1091
                        }
1092
                        break;
1093
                }
1094
                $i++;
1095
            }
1096
        }
1097
1098
        return $html;
1099
    }
1100
1101
    /**
1102
     * Shows the general data for a particular meeting
1103
     *
1104
     * @param id	session id
1105
     * @return string	session data
1106
     */
1107
    public static function show_session_data($id_session)
1108
    {
1109
        $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
1110
1111
        $sessionInfo = api_get_session_info($id_session);
1112
1113
        if (empty($sessionInfo)) {
1114
            return '';
1115
        }
1116
1117
        $sql = 'SELECT name FROM '.$session_category_table.'
1118
                WHERE id = "'.intval($sessionInfo['session_category_id']).'"';
1119
        $rs_category = Database::query($sql);
1120
        $session_category = '';
1121 View Code Duplication
        if (Database::num_rows($rs_category) > 0) {
1122
            $rows_session_category = Database::store_result($rs_category);
1123
            $rows_session_category = $rows_session_category[0];
1124
            $session_category = $rows_session_category['name'];
1125
        }
1126
1127
        $coachInfo = api_get_user_info($sessionInfo['id_coach']);
1128
1129
        $output = '';
1130
        if (!empty($session_category)) {
1131
            $output .= '<tr><td>'.get_lang('SessionCategory').': '.'<b>'.$session_category.'</b></td></tr>';
1132
        }
1133
        $dateInfo = SessionManager::parseSessionDates($sessionInfo);
1134
1135
        $msgDate = $dateInfo['access'];
1136
        $output .= '<tr>
1137
                    <td style="width:50%">'.get_lang('SessionName').': '.'<b>'.$sessionInfo['name'].'</b></td>
1138
                    <td>'.get_lang('GeneralCoach').': '.'<b>'.$coachInfo['complete_name'].'</b></td></tr>';
1139
        $output .= '<tr>
1140
                        <td>'.get_lang('SessionIdentifier').': '.
1141
                            Display::return_icon('star.png', ' ', array('align' => 'absmiddle')).'
1142
                        </td>
1143
                        <td>'.get_lang('Date').': '.'<b>'.$msgDate.'</b>
1144
                        </td>
1145
                    </tr>';
1146
1147
        return $output;
1148
    }
1149
1150
    /**
1151
     * Retrieves the name-field within a tool-record and translates it on necessity.
1152
     * @param array $tool		The input record.
1153
     * @return string			Returns the name of the corresponding tool.
1154
     */
1155
    public static function translate_tool_name(& $tool)
1156
    {
1157
        static $already_translated_icons = array(
1158
            'file_html.gif',
1159
            'file_html_na.gif',
1160
            'file_html.png',
1161
            'file_html_na.png',
1162
            'scormbuilder.gif',
1163
            'scormbuilder_na.gif',
1164
            'blog.gif',
1165
            'blog_na.gif',
1166
            'external.gif',
1167
            'external_na.gif'
1168
        );
1169
1170
        $toolName = Security::remove_XSS(stripslashes($tool['name']));
1171
1172
        if (in_array($tool['image'], $already_translated_icons)) {
1173
            return $toolName;
1174
        }
1175
1176
        $toolName = api_underscore_to_camel_case($toolName);
1177
1178
        if (isset($GLOBALS['Tool'.$toolName])) {
1179
            return get_lang('Tool'.$toolName);
1180
        }
1181
1182
        return $toolName;
1183
    }
1184
1185
    /**
1186
     * Get published learning path id from link inside course home
1187
     * @param 	string	Link to published lp
1188
     * @return	int		Learning path id
1189
     */
1190
    public static function get_published_lp_id_from_link($published_lp_link)
1191
    {
1192
        $lp_id = 0;
1193
        $param_lp_id = strstr($published_lp_link, 'lp_id=');
1194
        if (!empty($param_lp_id)) {
1195
            $a_param_lp_id = explode('=', $param_lp_id);
1196
            if (isset($a_param_lp_id[1])) {
1197
                $lp_id = intval($a_param_lp_id[1]);
1198
            }
1199
        }
1200
1201
        return $lp_id;
1202
    }
1203
1204
    /**
1205
     * Get published learning path category from link inside course home
1206
     * @param string $link
1207
     * @return CLpCategory
1208
     */
1209
    public static function getPublishedLpCategoryFromLink($link)
1210
    {
1211
        $query = parse_url($link, PHP_URL_QUERY);
1212
        parse_str($query, $params);
1213
1214
        $id = isset($params['id']) ? (int) $params['id'] : 0;
1215
1216
        $em = Database::getManager();
1217
        /** @var CLpCategory $category */
1218
        $category = $em->find('ChamiloCourseBundle:CLpCategory', $id);
1219
1220
        return $category;
1221
    }
1222
1223
    /**
1224
     * @param bool $include_admin_tools
1225
     * @return array
1226
     */
1227
    public static function get_navigation_items($include_admin_tools = false)
1228
    {
1229
        $navigation_items = array();
1230
        $course_id = api_get_course_int_id();
1231
        $courseInfo = api_get_course_info();
1232
        $sessionId = api_get_session_id();
1233
1234
        if (!empty($course_id)) {
1235
1236
            $course_tools_table = Database::get_course_table(TABLE_TOOL_LIST);
1237
1238
            /* 	Link to the Course homepage */
1239
            $navigation_items['home']['image'] = 'home.gif';
1240
            $navigation_items['home']['link'] = $courseInfo['course_public_url'];
1241
            $navigation_items['home']['name'] = get_lang('CourseHomepageLink');
1242
1243
            $sql = "SELECT * FROM $course_tools_table
1244
                    WHERE c_id = $course_id AND visibility='1' and admin='0'
1245
                    ORDER BY id ASC";
1246
            $sql_result = Database::query($sql);
1247
            while ($row = Database::fetch_array($sql_result)) {
1248
                $navigation_items[$row['id']] = $row;
1249
                if (stripos($row['link'], 'http://') === false && stripos($row['link'], 'https://') === false) {
1250
                    $navigation_items[$row['id']]['link'] = api_get_path(WEB_CODE_PATH);
1251
1252
                    if ($row['category'] == 'plugin') {
1253
                        $plugin = new AppPlugin();
1254
                        $pluginInfo = $plugin->getPluginInfo($row['name']);
1255
                        $navigation_items[$row['id']]['link'] = api_get_path(WEB_PLUGIN_PATH);
1256
                        $navigation_items[$row['id']]['name'] = $pluginInfo['title'];
1257
                    } else {
1258
                        $navigation_items[$row['id']]['name'] = self::translate_tool_name($row);
1259
                    }
1260
1261
                    $navigation_items[$row['id']]['link'] .= $row['link'];
1262
                }
1263
            }
1264
1265
            /* 	Admin (edit rights) only links
1266
              - Course settings (course admin only)
1267
              - Course rights (roles & rights overview) */
1268
            if ($include_admin_tools) {
1269
                $sql = "SELECT name, image FROM $course_tools_table
1270
                        WHERE c_id = $course_id  AND link='course_info/infocours.php'";
1271
                $sql_result = Database::query($sql);
1272
                $course_setting_info = Database::fetch_array($sql_result);
1273
                $course_setting_visual_name = self::translate_tool_name($course_setting_info);
1274
                if ($sessionId == 0) {
1275
                    // course settings item
1276
                    $navigation_items['course_settings']['image'] = $course_setting_info['image'];
1277
                    $navigation_items['course_settings']['link'] = api_get_path(WEB_CODE_PATH).'course_info/infocours.php';
1278
                    $navigation_items['course_settings']['name'] = $course_setting_visual_name;
1279
                }
1280
            }
1281
        }
1282
1283
        foreach ($navigation_items as $key => $navigation_item) {
1284
            if (strstr($navigation_item['link'], '?')) {
1285
                //link already contains a parameter, add course id parameter with &
1286
                $parameter_separator = '&amp;';
1287
            } else {
1288
                //link doesn't contain a parameter yet, add course id parameter with ?
1289
                $parameter_separator = '?';
1290
            }
1291
            //$navigation_items[$key]['link'] .= $parameter_separator.api_get_cidreq();
1292
            $navigation_items[$key]['link'] .= $parameter_separator.'cidReq='.api_get_course_id().'&gidReq=0&id_session='.$sessionId;
1293
        }
1294
1295
        return $navigation_items;
1296
    }
1297
1298
    /**
1299
     * Show a navigation menu
1300
     */
1301
    public static function show_navigation_menu()
1302
    {
1303
        $navigation_items = self::get_navigation_items(true);
1304
        $course_id = api_get_course_id();
1305
1306
        $class = null;
1307
        $idLearn = null;
1308
        $item = null;
1309
        $marginLeft = 160;
1310
1311
        $html = '<div id="toolnav">';
1312
        $html .= '<ul id="toolnavbox">';
1313
        $count = 0;
1314
        foreach ($navigation_items as $key => $navigation_item) {
1315
            //students can't see the course settings option
1316
            $count++;
1317
            if (!api_is_allowed_to_edit() && $key == 'course_settings') {
1318
                continue;
1319
            }
1320
            $html .= '<li>';
1321
            $url_item = parse_url($navigation_item['link']);
1322
            $url_current = parse_url($_SERVER['REQUEST_URI']);
1323
1324
            if (api_get_setting('show_navigation_menu') == 'text') {
1325
                $class = 'text';
1326
                $marginLeft = 170;
1327
                $item = $navigation_item['name'];
1328
            } else if (api_get_setting('show_navigation_menu') == 'icons') {
1329
                $class = 'icons';
1330
                $marginLeft = 25;
1331
                $item = Display::return_icon(
1332
                    substr($navigation_item['image'], 0, -3)."png",
1333
                    $navigation_item['name'],
1334
                    array('class' => 'tool-img'),
1335
                    ICON_SIZE_SMALL
1336
                );
1337 View Code Duplication
            } else {
1338
                $class = 'icons-text';
1339
                $item = $navigation_item['name'].Display::return_icon(substr($navigation_item['image'], 0, -3)."png", $navigation_item['name'], array('class'=>'tool-img'), ICON_SIZE_SMALL);
1340
            }
1341
1342
            if (stristr($url_item['path'], $url_current['path'])) {
1343
                if (!isset($_GET['learnpath_id']) || strpos($url_item['query'], 'learnpath_id='.intval($_GET['learnpath_id'])) === 0) {
1344
                    $idLearn = ' id="here"';
1345
                }
1346
            }
1347
1348
            if (strpos($navigation_item['link'], 'chat') !== false &&
1349
                api_get_course_setting('allow_open_chat_window', $course_id)
1350
            ) {
1351
                $html .= '<a '.$idLearn.' class="btn btn-default text-left '.$class.' " href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$navigation_item['target'].'"';
1352
                $html .= ' title="'.$navigation_item['name'].'">';
1353
                $html .= $item;
1354
                $html .= '</a>';
1355
            } else {
1356
                $html .= '<a '.$idLearn.' class="btn btn-default text-left '.$class.'" href="'.$navigation_item['link'].'" target="_top" title="'.$navigation_item['name'].'">';
1357
                $html .= $item;
1358
                $html .= '</a>';
1359
            }
1360
1361
            $html .= '</li>';
1362
        }
1363
        $html .= '</ul>';
1364
        $html .= '<script>$(function() {
1365
                $("#toolnavbox a").stop().animate({"margin-left":"-' . $marginLeft.'px"},1000);
1366
                $("#toolnavbox > li").hover(
1367
                    function () {
1368
                        $("a",$(this)).stop().animate({"margin-left":"-2px"},200);
1369
                        $("span",$(this)).css("display","block");
1370
                    },
1371
                    function () {
1372
                        $("a",$(this)).stop().animate({"margin-left":"-' . $marginLeft.'px"},200);
1373
                        $("span",$(this)).css("display","initial");
1374
                    }
1375
                );
1376
            });</script>';
1377
        $html .= '</div>';
1378
1379
        return $html;
1380
    }
1381
1382
    /**
1383
     * Show a toolbar with shortcuts to the course tool
1384
     * @param int $orientation
1385
     *
1386
     * @return string
1387
     */
1388
    public static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL)
1389
    {
1390
        $origin = api_get_origin();
1391
        if ($origin === 'learnpath') {
1392
            return '';
1393
        }
1394
1395
        $navigation_items = self::get_navigation_items(false);
1396
        $html = '';
1397
        if (!empty($navigation_items)) {
1398
            if ($orientation == SHORTCUTS_HORIZONTAL) {
1399
                $style_id = "toolshortcuts_horizontal";
1400
            } else {
1401
                $style_id = "toolshortcuts_vertical";
1402
            }
1403
            $html .= '<div id="'.$style_id.'">';
1404
            foreach ($navigation_items as $key => $navigation_item) {
1405
                if (strpos($navigation_item['link'], 'chat') !== false &&
1406
                    api_get_course_setting('allow_open_chat_window')
1407
                ) {
1408
                    $html .= '<a class="items-icon" href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$navigation_item['target'].'"';
1409
                } else {
1410
                    $html .= '<a class="items-icon" href="'.$navigation_item['link'].'"';
1411
                }
1412
                if (strpos(api_get_self(), $navigation_item['link']) !== false) {
1413
                    $html .= ' id="here"';
1414
                }
1415
                $html .= ' target="_top" title="'.$navigation_item['name'].'">';
1416
1417
                if (isset($navigation_item['category']) && $navigation_item['category'] == 'plugin') {
1418
                    /*$plugin_info = $app_plugin->getPluginInfo($navigation_item['name']);
1419
                    if (isset($plugin_info) && isset($plugin_info['title'])) {
1420
                        $tool_name = $plugin_info['title'];
1421
                    }*/
1422
1423 View Code Duplication
                    if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$navigation_item['image']) &&
1424
                        !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/'.ICON_SIZE_MEDIUM.'/'.$navigation_item['image'])
1425
                    ) {
1426
                        $navigation_item['image'] = 'plugins.png';
1427
                    }
1428
                    //$tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH).$navigation_item['link'].'?'.api_get_cidreq();
1429
                }
1430
1431
                $html .= Display::return_icon(
1432
                    substr($navigation_item['image'], 0, -3).'png',
1433
                    $navigation_item['name'],
1434
                    [],
1435
                    ICON_SIZE_MEDIUM
1436
                );
1437
                $html .= '</a> ';
1438
                if ($orientation == SHORTCUTS_VERTICAL) {
1439
                    $html .= '<br />';
1440
                }
1441
            }
1442
            $html .= '</div>';
1443
        }
1444
1445
        return $html;
1446
    }
1447
1448
    /**
1449
     * List course homepage tools from authoring and interaction sections
1450
     * @param   int $courseId The course ID (guessed from context if not provided)
1451
     * @param   int $sessionId The session ID (guessed from context if not provided)
1452
     * @return  array List of all tools data from the c_tools table
1453
     */
1454
    public static function toolsIconsAction($courseId = null, $sessionId = null)
1455
    {
1456
        if (empty($courseId)) {
1457
            $courseId = api_get_course_int_id();
1458
        } else {
1459
            $courseId = intval($courseId);
1460
        }
1461
        if (empty($sessionId)) {
1462
            $sessionId = api_get_session_id();
1463
        } else {
1464
            $sessionId = intval($sessionId);
1465
        }
1466
1467
        if (empty($courseId)) {
1468
            // We shouldn't get here, but for some reason api_get_course_int_id()
1469
            // doesn't seem to get the course from the context, sometimes
1470
            return array();
1471
        }
1472
1473
        $table = Database::get_course_table(TABLE_TOOL_LIST);
1474
        $sql = "SELECT * FROM $table
1475
                WHERE category in ('authoring','interaction')
1476
                AND c_id = $courseId
1477
                AND session_id = $sessionId
1478
                ORDER BY id";
1479
1480
        $result = Database::query($sql);
1481
        $data = Database::store_result($result, 'ASSOC');
1482
1483
        return $data;
1484
    }
1485
1486
    /**
1487
     * @param int $editIcon
1488
     * @return array
1489
     */
1490 View Code Duplication
    public static function getTool($editIcon)
1491
    {
1492
        $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
1493
        $editIcon = intval($editIcon);
1494
1495
        $sql = "SELECT * FROM $course_tool_table
1496
                WHERE iid = $editIcon";
1497
        $result = Database::query($sql);
1498
        $tool = Database::fetch_assoc($result, 'ASSOC');
1499
1500
        return $tool;
1501
    }
1502
1503
    /**
1504
     * @return string
1505
     */
1506
    public static function getCustomSysIconPath()
1507
    {
1508
        // Check if directory exists or create it if it doesn't
1509
        $dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
1510
        if (!is_dir($dir)) {
1511
            mkdir($dir, api_get_permissions_for_new_directories(), true);
1512
        }
1513
1514
        return $dir;
1515
    }
1516
1517
    /**
1518
     * @return string
1519
     */
1520
    public static function getCustomWebIconPath()
1521
    {
1522
        // Check if directory exists or create it if it doesn't
1523
        $dir = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
1524
1525
        return $dir;
1526
    }
1527
1528
    /**
1529
     * @param string $icon
1530
     * @return string
1531
     */
1532
    public static function getDisableIcon($icon)
1533
    {
1534
        $fileInfo = pathinfo($icon);
1535
1536
        return $fileInfo['filename'].'_na.'.$fileInfo['extension'];
1537
    }
1538
1539
    /**
1540
     * @param int $id
1541
     * @param array $values
1542
     */
1543
    public static function updateTool($id, $values)
1544
    {
1545
        $table = Database::get_course_table(TABLE_TOOL_LIST);
1546
        $params = [
1547
            'name' => $values['name'],
1548
            'link' => $values['link'],
1549
            'target' => $values['target'],
1550
            'visibility' => $values['visibility'],
1551
            'description' => $values['description'],
1552
        ];
1553
1554
        if (isset($_FILES['icon']['size']) && $_FILES['icon']['size'] !== 0) {
1555
            $dir = self::getCustomSysIconPath();
1556
1557
            // Resize image if it is larger than 64px
1558
            $temp = new Image($_FILES['icon']['tmp_name']);
1559
            $picture_infos = $temp->get_image_info();
1560
            if ($picture_infos['width'] > 64) {
1561
                $thumbwidth = 64;
1562
            } else {
1563
                $thumbwidth = $picture_infos['width'];
1564
            }
1565
            if ($picture_infos['height'] > 64) {
1566
                $new_height = 64;
1567
            } else {
1568
                $new_height = $picture_infos['height'];
1569
            }
1570
            $temp->resize($thumbwidth, $new_height, 0);
1571
1572
            //copy the image to the course upload folder
1573
            $path = $dir.$_FILES['icon']['name'];
1574
            $result = $temp->send_image($path);
1575
1576
            $temp = new Image($path);
1577
            $r = $temp->convert2bw();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $r is correct as $temp->convert2bw() (which targets Image::convert2bw()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1578
            $ext = pathinfo($path, PATHINFO_EXTENSION);
1579
            $bwPath = substr($path, 0, -(strlen($ext) + 1)).'_na.'.$ext;
1580
1581
            if ($r === false) {
1582
                error_log('Conversion to B&W of '.$path.' failed in '.__FILE__.' at line '.__LINE__);
1583
            } else {
1584
                $temp->send_image($bwPath);
1585
                $iconName = $_FILES['icon']['name'];
1586
                $params['custom_icon'] = $iconName;
1587
            }
1588
        }
1589
1590
        Database::update(
1591
            $table,
1592
            $params,
1593
            [' iid = ?' => [$id]]
1594
        );
1595
    }
1596
1597
    /**
1598
     * @param int $id
1599
     */
1600
    public static function deleteIcon($id)
1601
    {
1602
        $table = Database::get_course_table(TABLE_TOOL_LIST);
1603
        $tool = self::getTool($id);
1604
1605
        if ($tool && !empty($tool['custom_icon'])) {
1606
            $file = self::getCustomSysIconPath().$tool['custom_icon'];
1607
            $fileInfo = pathinfo($file);
1608
            $fileGray = $fileInfo['filename'].'_na.'.$fileInfo['extension'];
1609
            $fileGray = self::getCustomSysIconPath().$fileGray;
1610
1611 View Code Duplication
            if (file_exists($file) && is_file($file)) {
1612
                if (Security::check_abs_path($file, self::getCustomSysIconPath())) {
1613
                    unlink($file);
1614
                }
1615
            }
1616
1617 View Code Duplication
            if (file_exists($fileGray) && is_file($fileGray)) {
1618
                if (Security::check_abs_path($fileGray, self::getCustomSysIconPath())) {
1619
                    unlink($fileGray);
1620
                }
1621
            }
1622
1623
            $params = [
1624
                'custom_icon' => ''
1625
            ];
1626
1627
            Database::update(
1628
                $table,
1629
                $params,
1630
                [' iid = ?' => [$id]]
1631
            );
1632
        }
1633
    }
1634
}
1635