1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class CourseHome |
6
|
|
|
*/ |
7
|
|
|
class CourseHome |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Gets the html content to show in the 3 column view |
11
|
|
|
*/ |
12
|
|
|
public static function show_tool_3column($cat, $userId = null) |
13
|
|
|
{ |
14
|
|
|
$_user = api_get_user_info($userId); |
15
|
|
|
|
16
|
|
|
$TBL_ACCUEIL = Database :: get_course_table(TABLE_TOOL_LIST); |
17
|
|
|
$TABLE_TOOLS = Database :: get_main_table(TABLE_MAIN_COURSE_MODULE); |
18
|
|
|
|
19
|
|
|
$numcols = 3; |
20
|
|
|
$table = new HTML_Table('width="100%"'); |
21
|
|
|
$all_tools = array(); |
22
|
|
|
|
23
|
|
|
$course_id = api_get_course_int_id(); |
24
|
|
|
|
25
|
|
|
switch ($cat) { |
26
|
|
View Code Duplication |
case 'Basic' : |
27
|
|
|
$condition_display_tools = ' WHERE a.c_id = '.$course_id.' AND a.link=t.link AND t.position="basic" '; |
28
|
|
|
if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') { |
29
|
|
|
$condition_display_tools = ' WHERE a.c_id = '.$course_id.' AND a.link=t.link AND (t.position="basic" OR a.name = "'.TOOL_TRACKING.'") '; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$sql = "SELECT a.*, t.image img, t.row, t.column FROM $TBL_ACCUEIL a, $TABLE_TOOLS t |
33
|
|
|
$condition_display_tools ORDER BY t.row, t.column"; |
34
|
|
|
break; |
35
|
|
|
case 'External' : |
36
|
|
|
if (api_is_allowed_to_edit()) { |
37
|
|
|
$sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t |
38
|
|
|
WHERE a.c_id = $course_id AND ((a.link=t.link AND t.position='external') |
39
|
|
|
OR (a.visibility <= 1 AND (a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image)) |
40
|
|
|
ORDER BY a.id"; |
41
|
|
|
} else { |
42
|
|
|
$sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t |
43
|
|
|
WHERE a.c_id = $course_id AND (a.visibility = 1 AND ((a.link=t.link AND t.position='external') |
44
|
|
|
OR ((a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image))) |
45
|
|
|
ORDER BY a.id"; |
46
|
|
|
} |
47
|
|
|
break; |
48
|
|
|
case 'courseAdmin' : |
49
|
|
|
$sql = "SELECT a.*, t.image img, t.row, t.column FROM $TBL_ACCUEIL a, $TABLE_TOOLS t |
50
|
|
|
WHERE a.c_id = $course_id AND admin=1 AND a.link=t.link ORDER BY t.row, t.column"; |
51
|
|
|
break; |
52
|
|
|
|
53
|
|
|
case 'platformAdmin' : |
54
|
|
|
$sql = "SELECT *, image img FROM $TBL_ACCUEIL WHERE c_id = $course_id AND visibility = 2 ORDER BY id"; |
55
|
|
|
} |
56
|
|
|
$result = Database::query($sql); |
57
|
|
|
|
58
|
|
|
// Grabbing all the tools from $course_tool_table |
59
|
|
|
while ($tool = Database::fetch_array($result)) { |
60
|
|
|
$all_tools[] = $tool; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$course_id = api_get_course_int_id(); |
64
|
|
|
|
65
|
|
|
// Grabbing all the links that have the property on_homepage set to 1 |
66
|
|
|
if ($cat == 'External') { |
67
|
|
|
$tbl_link = Database :: get_course_table(TABLE_LINK); |
68
|
|
|
$tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
69
|
|
|
if (api_is_allowed_to_edit(null, true)) { |
70
|
|
|
$sql_links = "SELECT tl.*, tip.visibility |
71
|
|
|
FROM $tbl_link tl |
72
|
|
|
LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id |
73
|
|
|
WHERE tl.c_id = $course_id AND |
74
|
|
|
tip.c_id = $course_id AND |
75
|
|
|
tl.on_homepage='1' AND |
76
|
|
|
tip.visibility != 2"; |
77
|
|
|
} else { |
78
|
|
|
$sql_links = "SELECT tl.*, tip.visibility |
79
|
|
|
FROM $tbl_link tl |
80
|
|
|
LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id |
81
|
|
|
WHERE tl.c_id = $course_id AND |
82
|
|
|
tip.c_id = $course_id AND |
83
|
|
|
tl.on_homepage='1' AND |
84
|
|
|
tip.visibility = 1"; |
85
|
|
|
} |
86
|
|
|
$result_links = Database::query($sql_links); |
87
|
|
View Code Duplication |
while ($links_row = Database::fetch_array($result_links)) { |
88
|
|
|
$properties = array(); |
89
|
|
|
$properties['name'] = $links_row['title']; |
90
|
|
|
$properties['link'] = $links_row['url']; |
91
|
|
|
$properties['visibility'] = $links_row['visibility']; |
92
|
|
|
$properties['img'] = 'external.gif'; |
93
|
|
|
$properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id']; |
94
|
|
|
$all_tools[] = $properties; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$cell_number = 0; |
99
|
|
|
// Draw line between basic and external, only if there are entries in External |
100
|
|
|
if ($cat == 'External' && count($all_tools)) { |
101
|
|
|
$table->setCellContents(0, 0, '<hr noshade="noshade" size="1"/>'); |
102
|
|
|
$table->updateCellAttributes(0, 0, 'colspan="3"'); |
103
|
|
|
$cell_number += $numcols; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
foreach ($all_tools as & $tool) { |
107
|
|
View Code Duplication |
if ($tool['image'] == 'scormbuilder.gif') { |
108
|
|
|
// check if the published learnpath is visible for student |
109
|
|
|
$published_lp_id = self::get_published_lp_id_from_link($tool['link']); |
110
|
|
|
if (!api_is_allowed_to_edit(null, true) && |
111
|
|
|
!learnpath::is_lp_visible_for_student( |
112
|
|
|
$published_lp_id, |
113
|
|
|
api_get_user_id(), |
114
|
|
|
api_get_course_id(), |
115
|
|
|
api_get_session_id() |
116
|
|
|
) |
117
|
|
|
) { |
118
|
|
|
continue; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
View Code Duplication |
if (api_get_session_id() != 0 && |
123
|
|
|
in_array($tool['name'], array('course_maintenance', 'course_setting')) |
124
|
|
|
) { |
125
|
|
|
continue; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$cell_content = ''; |
129
|
|
|
// The name of the tool |
130
|
|
|
$tool_name = self::translate_tool_name($tool); |
131
|
|
|
|
132
|
|
|
$link_annex = ''; |
133
|
|
|
// The url of the tool |
134
|
|
|
if ($tool['img'] != 'external.gif') { |
135
|
|
|
$tool['link'] = api_get_path(WEB_CODE_PATH).$tool['link']; |
136
|
|
|
$qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; |
137
|
|
|
$link_annex = $qm_or_amp.api_get_cidreq(); |
138
|
|
|
} else { |
139
|
|
|
// If an external link ends with 'login=', add the actual login... |
140
|
|
|
$pos = strpos($tool['link'], '?login='); |
141
|
|
|
$pos2 = strpos($tool['link'], '&login='); |
142
|
|
|
if ($pos !== false or $pos2 !== false) { |
143
|
|
|
$link_annex = $_user['username']; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
// Setting the actual image url |
148
|
|
|
$tool['img'] = Display::returnIconPath($tool['img']); |
149
|
|
|
|
150
|
|
|
// VISIBLE |
151
|
|
|
if (($tool['visibility'] || |
152
|
|
|
((api_is_coach() || api_is_course_tutor()) && $tool['name'] == TOOL_TRACKING)) || |
153
|
|
|
$cat == 'courseAdmin' || $cat == 'platformAdmin' |
154
|
|
|
) { |
155
|
|
|
if (strpos($tool['name'], 'visio_') !== false) { |
156
|
|
|
$cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$tool['link'].$link_annex.'\',\'window_visio'.$_SESSION['_cid'].'\',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>'; |
157
|
|
View Code Duplication |
} elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { |
158
|
|
|
$cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$tool['link'].$link_annex.'\',\'window_chat'.$_SESSION['_cid'].'\',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>'; |
159
|
|
|
// don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img'] |
160
|
|
|
} else { |
161
|
|
|
$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>'; |
162
|
|
|
// don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img'] |
163
|
|
|
} |
164
|
|
|
} else { |
165
|
|
|
// INVISIBLE |
166
|
|
|
if (api_is_allowed_to_edit(null, true)) { |
167
|
|
|
if (strpos($tool['name'], 'visio_') !== false) { |
168
|
|
|
$cell_content .= '<a href="javascript: void(0);" onclick="window.open(\''.$tool['link'].$link_annex.'\',\'window_visio'.$_SESSION['_cid'].'\',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>'; |
169
|
|
View Code Duplication |
} elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { |
170
|
|
|
$cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$tool['link'].$link_annex.'\',\'window_chat'.$_SESSION['_cid'].'\',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="invisible"><img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>'; |
171
|
|
|
// don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img'] |
172
|
|
|
} else { |
173
|
|
|
$cell_content .= '<a href="'.$tool['link'].$link_annex.'" target="'.$tool['target'].'" class="invisible"> |
174
|
|
|
<img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>'; |
175
|
|
|
// don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img'] |
176
|
|
|
} |
177
|
|
|
} else { |
178
|
|
|
$cell_content .= '<img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'; |
179
|
|
|
// don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img'] |
180
|
|
|
$cell_content .= '<span class="invisible">'.$tool_name.'</span>'; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
$lnk = array(); |
185
|
|
|
if (api_is_allowed_to_edit(null, true) && |
186
|
|
|
$cat != "courseAdmin" && |
187
|
|
|
!strpos($tool['link'], 'learnpath_handler.php?learnpath_id') && |
188
|
|
|
!api_is_coach() |
189
|
|
|
) { |
190
|
|
|
if ($tool['visibility']) { |
191
|
|
|
$link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'), array('style' => 'vertical-align: middle;')); |
192
|
|
|
$link['cmd'] = "hide=yes"; |
193
|
|
|
$lnk[] = $link; |
194
|
|
|
} else { |
195
|
|
|
$link['name'] = Display::return_icon('add.gif', get_lang('Activate'), array('style' => 'vertical-align: middle;')); |
196
|
|
|
$link['cmd'] = "restore=yes"; |
197
|
|
|
$lnk[] = $link; |
198
|
|
|
} |
199
|
|
|
if (is_array($lnk)) { |
200
|
|
|
foreach ($lnk as & $this_lnk) { |
201
|
|
|
if ($tool['adminlink']) { |
202
|
|
|
$cell_content .= '<a href="'.$properties['adminlink'].'">'. |
203
|
|
|
Display::return_icon('edit.gif', get_lang('Edit')).'</a>'; |
204
|
|
|
} else { |
205
|
|
|
$cell_content .= '<a href="'.api_get_self().'?id='.$tool['id'].'&'.$this_lnk['cmd'].'">'.$this_lnk['name'].'</a>'; |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
$table->setCellContents($cell_number / $numcols, ($cell_number) % $numcols, $cell_content); |
211
|
|
|
$table->updateCellAttributes($cell_number / $numcols, ($cell_number) % $numcols, 'width="32%" height="42"'); |
212
|
|
|
$cell_number++; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
return $table->toHtml(); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Displays the tools of a certain category. |
220
|
|
|
* |
221
|
|
|
* @return void |
222
|
|
|
* @param string $course_tool_category contains the category of tools to display: |
223
|
|
|
* "Public", "PublicButHide", "courseAdmin", "claroAdmin" |
224
|
|
|
*/ |
225
|
|
|
public static function show_tool_2column($course_tool_category) |
226
|
|
|
{ |
227
|
|
|
$html = ''; |
228
|
|
|
$web_code_path = api_get_path(WEB_CODE_PATH); |
229
|
|
|
$course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); |
230
|
|
|
|
231
|
|
|
$course_id = api_get_course_int_id(); |
232
|
|
|
|
233
|
|
|
switch ($course_tool_category) { |
234
|
|
View Code Duplication |
case TOOL_PUBLIC: |
235
|
|
|
$condition_display_tools = ' WHERE c_id = '.$course_id.' AND visibility = 1 '; |
236
|
|
|
if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') { |
237
|
|
|
$condition_display_tools = ' WHERE c_id = '.$course_id.' AND (visibility = 1 OR (visibility = 0 AND name = "'.TOOL_TRACKING.'")) '; |
238
|
|
|
} |
239
|
|
|
$result = Database::query("SELECT * FROM $course_tool_table $condition_display_tools ORDER BY id"); |
240
|
|
|
$col_link = "##003399"; |
241
|
|
|
break; |
242
|
|
|
case TOOL_PUBLIC_BUT_HIDDEN: |
243
|
|
|
$result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility=0 AND admin=0 ORDER BY id"); |
244
|
|
|
$col_link = "##808080"; |
245
|
|
|
break; |
246
|
|
|
case TOOL_COURSE_ADMIN: |
247
|
|
|
$result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND admin=1 AND visibility != 2 ORDER BY id"); |
248
|
|
|
$col_link = "##003399"; |
249
|
|
|
break; |
250
|
|
|
case TOOL_PLATFORM_ADMIN: |
251
|
|
|
$result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility = 2 ORDER BY id"); |
252
|
|
|
$col_link = "##003399"; |
253
|
|
|
} |
254
|
|
|
$i = 0; |
255
|
|
|
|
256
|
|
|
// Grabbing all the tools from $course_tool_table |
257
|
|
|
while ($temp_row = Database::fetch_array($result)) { |
|
|
|
|
258
|
|
|
if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN && $temp_row['image'] != 'scormbuilder.gif') { |
259
|
|
|
$temp_row['image'] = str_replace('.gif', '_na.gif', $temp_row['image']); |
260
|
|
|
} |
261
|
|
|
$all_tools_list[] = $temp_row; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
// Grabbing all the links that have the property on_homepage set to 1 |
265
|
|
|
$course_link_table = Database::get_course_table(TABLE_LINK); |
266
|
|
|
$course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); |
267
|
|
|
|
268
|
|
|
switch ($course_tool_category) { |
269
|
|
|
case TOOL_PUBLIC: |
270
|
|
|
$sql_links = "SELECT tl.*, tip.visibility |
271
|
|
|
FROM $course_link_table tl |
272
|
|
|
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 |
273
|
|
|
WHERE tl.on_homepage='1' AND tip.visibility = 1"; |
274
|
|
|
break; |
275
|
|
|
case TOOL_PUBLIC_BUT_HIDDEN: |
276
|
|
|
$sql_links = "SELECT tl.*, tip.visibility |
277
|
|
|
FROM $course_link_table tl |
278
|
|
|
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 |
279
|
|
|
WHERE tl.on_homepage='1' AND tip.visibility = 0"; |
280
|
|
|
|
281
|
|
|
break; |
282
|
|
|
default: |
283
|
|
|
$sql_links = null; |
284
|
|
|
break; |
285
|
|
|
} |
286
|
|
|
if ($sql_links != null) { |
287
|
|
|
$properties = array(); |
288
|
|
|
$result_links = Database::query($sql_links); |
289
|
|
View Code Duplication |
while ($links_row = Database::fetch_array($result_links)) { |
290
|
|
|
unset($properties); |
291
|
|
|
$properties['name'] = $links_row['title']; |
292
|
|
|
$properties['link'] = $links_row['url']; |
293
|
|
|
$properties['visibility'] = $links_row['visibility']; |
294
|
|
|
$properties['image'] = $course_tool_category == TOOL_PUBLIC_BUT_HIDDEN ? 'external_na.gif' : 'external.gif'; |
295
|
|
|
$properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id']; |
296
|
|
|
$all_tools_list[] = $properties; |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
if (isset($all_tools_list)) { |
300
|
|
|
$lnk = array(); |
301
|
|
|
foreach ($all_tools_list as & $tool) { |
302
|
|
|
|
303
|
|
View Code Duplication |
if ($tool['image'] == 'scormbuilder.gif') { |
304
|
|
|
// check if the published learnpath is visible for student |
305
|
|
|
$published_lp_id = self::get_published_lp_id_from_link($tool['link']); |
306
|
|
|
|
307
|
|
|
if (!api_is_allowed_to_edit(null, true) && |
308
|
|
|
!learnpath::is_lp_visible_for_student( |
309
|
|
|
$published_lp_id, |
310
|
|
|
api_get_user_id(), |
311
|
|
|
api_get_course_id(), |
312
|
|
|
api_get_session_id() |
313
|
|
|
) |
314
|
|
|
) { |
315
|
|
|
continue; |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|
319
|
|
View Code Duplication |
if (api_get_session_id() != 0 && |
320
|
|
|
in_array($tool['name'], array('course_maintenance', 'course_setting')) |
321
|
|
|
) { |
322
|
|
|
continue; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
if (!($i % 2)) { |
326
|
|
|
$html .= "<tr valign=\"top\">"; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
// NOTE : Table contains only the image file name, not full path |
330
|
|
View Code Duplication |
if (stripos($tool['link'], 'http://') === false && |
331
|
|
|
stripos($tool['link'], 'https://') === false && |
332
|
|
|
stripos($tool['link'], 'ftp://') === false |
333
|
|
|
) { |
334
|
|
|
$tool['link'] = $web_code_path.$tool['link']; |
335
|
|
|
} |
336
|
|
|
if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) { |
337
|
|
|
$class = 'class="invisible"'; |
338
|
|
|
} |
339
|
|
|
$qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; |
340
|
|
|
|
341
|
|
|
$tool['link'] = $tool['link']; |
342
|
|
|
$html .= '<td width="50%" height="30">'; |
343
|
|
|
|
344
|
|
|
if (strpos($tool['name'], 'visio_') !== false) { |
345
|
|
|
$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'.$_SESSION['_cid'].'\',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'].'">'; |
346
|
|
|
} elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { |
347
|
|
|
$html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.htmlspecialchars($tool['link']).$qm_or_amp.api_get_cidreq().'\',\'window_chat'.$_SESSION['_cid'].'\',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.'>'; |
348
|
|
|
} else { |
349
|
|
|
$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.'>'; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
$tool_name = self::translate_tool_name($tool); |
353
|
|
|
$html .= Display::return_icon( |
354
|
|
|
$tool['image'], |
355
|
|
|
$tool_name, |
356
|
|
|
array(), |
357
|
|
|
null, |
358
|
|
|
ICON_SIZE_MEDIUM |
359
|
|
|
) . ' ' . $tool_name . '</a>'; |
360
|
|
|
|
361
|
|
|
// This part displays the links to hide or remove a tool. |
362
|
|
|
// These links are only visible by the course manager. |
363
|
|
|
unset($lnk); |
364
|
|
|
if (api_is_allowed_to_edit(null, true) && !api_is_coach()) { |
365
|
|
View Code Duplication |
if ($tool['visibility'] == '1' || $tool['name'] == TOOL_TRACKING) { |
366
|
|
|
$link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate')); |
367
|
|
|
$link['cmd'] = 'hide=yes'; |
368
|
|
|
$lnk[] = $link; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
View Code Duplication |
if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) { |
372
|
|
|
$link['name'] = Display::return_icon('add.gif', get_lang('Activate')); |
373
|
|
|
$link['cmd'] = 'restore=yes'; |
374
|
|
|
$lnk[] = $link; |
375
|
|
|
|
376
|
|
|
if ($tool['added_tool'] == 1) { |
377
|
|
|
$link['name'] = Display::return_icon('delete.gif', get_lang('Remove')); |
378
|
|
|
$link['cmd'] = 'remove=yes'; |
379
|
|
|
$lnk[] = $link; |
380
|
|
|
} |
381
|
|
|
} |
382
|
|
View Code Duplication |
if ($tool['adminlink']) { |
383
|
|
|
$html .= '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>'; |
384
|
|
|
} |
385
|
|
|
} |
386
|
|
|
if (api_is_platform_admin() && !api_is_coach()) { |
387
|
|
View Code Duplication |
if ($tool['visibility'] == 2) { |
388
|
|
|
$link['name'] = Display::return_icon('undelete.gif', get_lang('Activate')); |
389
|
|
|
|
390
|
|
|
$link['cmd'] = 'hide=yes'; |
391
|
|
|
$lnk[] = $link; |
392
|
|
|
|
393
|
|
|
if ($tool['added_tool'] == 1) { |
394
|
|
|
$link['name'] = get_lang('Delete'); |
395
|
|
|
$link['cmd'] = 'askDelete=yes'; |
396
|
|
|
$lnk[] = $link; |
397
|
|
|
} |
398
|
|
|
} |
399
|
|
View Code Duplication |
if ($tool['visibility'] == 0 && $tool['added_tool'] == 0) { |
400
|
|
|
$link['name'] = Display::return_icon('delete.gif', get_lang('Remove')); |
401
|
|
|
$link['cmd'] = 'remove=yes'; |
402
|
|
|
$lnk[] = $link; |
403
|
|
|
} |
404
|
|
|
} |
405
|
|
|
if (is_array($lnk)) { |
406
|
|
View Code Duplication |
foreach ($lnk as & $this_link) { |
407
|
|
|
if (!$tool['adminlink']) { |
408
|
|
|
$html .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$tool['id'].'&'.$this_link['cmd'].'">'.$this_link['name'].'</a>'; |
409
|
|
|
} |
410
|
|
|
} |
411
|
|
|
} |
412
|
|
|
$html .= "</td>"; |
413
|
|
|
|
414
|
|
|
if ($i % 2) { |
415
|
|
|
$html .= "</tr>"; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
$i++; |
419
|
|
|
} |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
if ($i % 2) { |
423
|
|
|
$html .= "<td width=\"50%\"> </td></tr>"; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
return $html; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* Gets the tools of a certain category. Returns an array expected |
431
|
|
|
* by show_tools_category() |
432
|
|
|
* @param string $course_tool_category contains the category of tools to |
433
|
|
|
* display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform", "toolplugin" |
434
|
|
|
* @return array |
435
|
|
|
*/ |
436
|
|
|
public static function get_tools_category($course_tool_category) |
437
|
|
|
{ |
438
|
|
|
$course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); |
439
|
|
|
$is_platform_admin = api_is_platform_admin(); |
440
|
|
|
$all_tools_list = array(); |
441
|
|
|
|
442
|
|
|
// Condition for the session |
443
|
|
|
$session_id = api_get_session_id(); |
444
|
|
|
$course_id = api_get_course_int_id(); |
445
|
|
|
$condition_session = api_get_session_condition($session_id, true, true, 't.session_id'); |
446
|
|
|
|
447
|
|
|
switch ($course_tool_category) { |
448
|
|
|
case TOOL_STUDENT_VIEW: |
449
|
|
|
$conditions = ' WHERE visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") '; |
450
|
|
|
if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') { |
451
|
|
|
$conditions = ' WHERE (visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") OR (name = "'.TOOL_TRACKING.'") ) '; |
452
|
|
|
} |
453
|
|
|
$sql = "SELECT * |
454
|
|
|
FROM $course_tool_table t |
455
|
|
|
$conditions AND |
456
|
|
|
c_id = $course_id $condition_session |
457
|
|
|
ORDER BY id"; |
458
|
|
|
$result = Database::query($sql); |
459
|
|
|
break; |
460
|
|
|
case TOOL_AUTHORING: |
461
|
|
|
$sql = "SELECT * FROM $course_tool_table t |
462
|
|
|
WHERE category = 'authoring' AND c_id = $course_id $condition_session |
463
|
|
|
ORDER BY id"; |
464
|
|
|
$result = Database::query($sql); |
465
|
|
|
break; |
466
|
|
|
case TOOL_INTERACTION: |
467
|
|
|
$sql = "SELECT * FROM $course_tool_table t |
468
|
|
|
WHERE category = 'interaction' AND c_id = $course_id $condition_session |
469
|
|
|
ORDER BY id"; |
470
|
|
|
$result = Database::query($sql); |
471
|
|
|
break; |
472
|
|
|
case TOOL_ADMIN_VISIBLE: |
473
|
|
|
$sql = "SELECT * FROM $course_tool_table t |
474
|
|
|
WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session |
475
|
|
|
ORDER BY id"; |
476
|
|
|
$result = Database::query($sql); |
477
|
|
|
break; |
478
|
|
|
case TOOL_ADMIN_PLATFORM: |
479
|
|
|
$sql = "SELECT * FROM $course_tool_table t |
480
|
|
|
WHERE category = 'admin' AND c_id = $course_id $condition_session |
481
|
|
|
ORDER BY id"; |
482
|
|
|
$result = Database::query($sql); |
483
|
|
|
break; |
484
|
|
|
case TOOL_DRH: |
485
|
|
|
$sql = "SELECT * FROM $course_tool_table t |
486
|
|
|
WHERE name IN ('tracking') AND c_id = $course_id $condition_session |
487
|
|
|
ORDER BY id"; |
488
|
|
|
$result = Database::query($sql); |
489
|
|
|
break; |
490
|
|
|
case TOOL_COURSE_PLUGIN: |
491
|
|
|
//Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id |
492
|
|
|
// but plugins are not present in the tool table, only globally and inside the course_settings table once configured |
493
|
|
|
$sql = "SELECT * FROM $course_tool_table t |
494
|
|
|
WHERE category = 'plugin' AND c_id = $course_id $condition_session |
495
|
|
|
ORDER BY id"; |
496
|
|
|
$result = Database::query($sql); |
497
|
|
|
break; |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
//Get the list of hidden tools - this might imply performance slowdowns |
501
|
|
|
// if the course homepage is loaded many times, so the list of hidden |
502
|
|
|
// tools might benefit from a shared memory storage later on |
503
|
|
|
$list = api_get_settings('Tools', 'list', api_get_current_access_url_id()); |
504
|
|
|
$hide_list = array(); |
505
|
|
|
$check = false; |
506
|
|
|
|
507
|
|
|
foreach ($list as $line) { |
508
|
|
|
// Admin can see all tools even if the course_hide_tools configuration is set |
509
|
|
|
if ($is_platform_admin) { |
510
|
|
|
continue; |
511
|
|
|
} |
512
|
|
|
if ($line['variable'] == 'course_hide_tools' and $line['selected_value'] == 'true') { |
513
|
|
|
$hide_list[] = $line['subkey']; |
514
|
|
|
$check = true; |
515
|
|
|
} |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
while ($temp_row = Database::fetch_assoc($result)) { |
|
|
|
|
519
|
|
|
$add = false; |
520
|
|
|
if ($check) { |
521
|
|
|
if (!in_array($temp_row['name'], $hide_list)) { |
522
|
|
|
$add = true; |
523
|
|
|
} |
524
|
|
|
} else { |
525
|
|
|
$add = true; |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
if ($temp_row['image'] == 'scormbuilder.gif') { |
529
|
|
|
$lp_id = self::get_published_lp_id_from_link($temp_row['link']); |
530
|
|
|
$lp = new learnpath( |
531
|
|
|
api_get_course_id(), |
532
|
|
|
$lp_id, |
533
|
|
|
api_get_user_id() |
534
|
|
|
); |
535
|
|
|
$path = $lp->get_preview_image_path(ICON_SIZE_BIG); |
536
|
|
|
$add = $lp->is_lp_visible_for_student( |
537
|
|
|
$lp_id, |
538
|
|
|
api_get_user_id(), |
539
|
|
|
api_get_course_id(), |
540
|
|
|
api_get_session_id() |
541
|
|
|
); |
542
|
|
|
if ($path) { |
543
|
|
|
$temp_row['custom_image'] = $path; |
544
|
|
|
} |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
if ($add) { |
548
|
|
|
$all_tools_list[] = $temp_row; |
549
|
|
|
} |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
// Grabbing all the links that have the property on_homepage set to 1 |
553
|
|
|
$course_link_table = Database::get_course_table(TABLE_LINK); |
554
|
|
|
$course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); |
555
|
|
|
|
556
|
|
|
$condition_session = api_get_session_condition($session_id, true, true, 'tip.session_id'); |
557
|
|
|
|
558
|
|
|
switch ($course_tool_category) { |
559
|
|
|
case TOOL_AUTHORING: |
560
|
|
|
$sql_links = "SELECT tl.*, tip.visibility |
561
|
|
|
FROM $course_link_table tl |
562
|
|
|
LEFT JOIN $course_item_property_table tip |
563
|
|
|
ON tip.tool='link' AND tip.ref=tl.id |
564
|
|
|
WHERE |
565
|
|
|
tl.c_id = $course_id AND |
566
|
|
|
tip.c_id = $course_id AND |
567
|
|
|
tl.on_homepage='1' $condition_session"; |
568
|
|
|
break; |
569
|
|
|
case TOOL_INTERACTION: |
570
|
|
|
$sql_links = null; |
571
|
|
|
/* |
572
|
|
|
$sql_links = "SELECT tl.*, tip.visibility |
573
|
|
|
FROM $course_link_table tl |
574
|
|
|
LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id |
575
|
|
|
WHERE tl.on_homepage='1' "; |
576
|
|
|
*/ |
577
|
|
|
break; |
578
|
|
|
case TOOL_STUDENT_VIEW: |
579
|
|
|
$sql_links = "SELECT tl.*, tip.visibility |
580
|
|
|
FROM $course_link_table tl |
581
|
|
|
LEFT JOIN $course_item_property_table tip |
582
|
|
|
ON tip.tool='link' AND tip.ref=tl.id |
583
|
|
|
WHERE |
584
|
|
|
tl.c_id = $course_id AND |
585
|
|
|
tip.c_id = $course_id AND |
586
|
|
|
tl.on_homepage ='1' $condition_session"; |
587
|
|
|
break; |
588
|
|
|
case TOOL_ADMIN: |
589
|
|
|
$sql_links = "SELECT tl.*, tip.visibility |
590
|
|
|
FROM $course_link_table tl |
591
|
|
|
LEFT JOIN $course_item_property_table tip |
592
|
|
|
ON tip.tool='link' AND tip.ref=tl.id |
593
|
|
|
WHERE |
594
|
|
|
tl.c_id = $course_id AND |
595
|
|
|
tip.c_id = $course_id AND |
596
|
|
|
tl.on_homepage='1' $condition_session"; |
597
|
|
|
break; |
598
|
|
|
default: |
599
|
|
|
$sql_links = null; |
600
|
|
|
break; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
// Edited by Kevin Van Den Haute ([email protected]) for integrating Smartblogs |
604
|
|
|
if ($sql_links != null) { |
605
|
|
|
$result_links = Database::query($sql_links); |
606
|
|
|
|
607
|
|
|
if (Database::num_rows($result_links) > 0) { |
608
|
|
|
while ($links_row = Database::fetch_array($result_links, 'ASSOC')) { |
609
|
|
|
$properties = array(); |
610
|
|
|
$properties['name'] = $links_row['title']; |
611
|
|
|
$properties['session_id'] = $links_row['session_id']; |
612
|
|
|
$properties['link'] = $links_row['url']; |
613
|
|
|
$properties['visibility'] = $links_row['visibility']; |
614
|
|
|
$properties['image'] = $links_row['visibility'] == '0' ? 'file_html.png' : 'file_html.png'; |
615
|
|
|
$properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id']; |
616
|
|
|
$properties['target'] = $links_row['target']; |
617
|
|
|
$tmp_all_tools_list[] = $properties; |
618
|
|
|
} |
619
|
|
|
} |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
if (isset($tmp_all_tools_list)) { |
623
|
|
|
foreach ($tmp_all_tools_list as $tool) { |
624
|
|
|
if ($tool['image'] == 'blog.gif') { |
625
|
|
|
// Init |
626
|
|
|
$tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); |
627
|
|
|
|
628
|
|
|
// Get blog id |
629
|
|
|
$blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link'])); |
630
|
|
|
|
631
|
|
|
// Get blog members |
632
|
|
|
if ($is_platform_admin) { |
633
|
|
|
$sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user |
634
|
|
|
WHERE blog_id =".$blog_id; |
635
|
|
|
} else { |
636
|
|
|
$sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user |
637
|
|
|
WHERE blog_id =".$blog_id." AND user_id = ".api_get_user_id(); |
638
|
|
|
} |
639
|
|
|
$result_blogs = Database::query($sql_blogs); |
640
|
|
|
|
641
|
|
|
if (Database::num_rows($result_blogs) > 0) { |
642
|
|
|
$all_tools_list[] = $tool; |
643
|
|
|
} |
644
|
|
|
} else { |
645
|
|
|
$all_tools_list[] = $tool; |
646
|
|
|
} |
647
|
|
|
} |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
return $all_tools_list; |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
/** |
654
|
|
|
* Displays the tools of a certain category. |
655
|
|
|
* @param array $all_tools_list List of tools as returned by get_tools_category() |
656
|
|
|
* @param bool $rows |
657
|
|
|
* |
658
|
|
|
* @return void |
659
|
|
|
*/ |
660
|
|
|
public static function show_tools_category($all_tools_list, $rows = false) |
661
|
|
|
{ |
662
|
|
|
$_user = api_get_user_info(); |
663
|
|
|
$theme = api_get_setting('homepage_view'); |
664
|
|
|
if ($theme == 'vertical_activity') { |
665
|
|
|
//ordering by get_lang name |
666
|
|
|
$order_tool_list = array(); |
667
|
|
|
if (is_array($all_tools_list) && count($all_tools_list) > 0) { |
668
|
|
|
foreach ($all_tools_list as $key => $new_tool) { |
669
|
|
|
$tool_name = self::translate_tool_name($new_tool); |
670
|
|
|
$order_tool_list [$key] = $tool_name; |
671
|
|
|
} |
672
|
|
|
natsort($order_tool_list); |
673
|
|
|
$my_temp_tool_array = array(); |
674
|
|
|
foreach ($order_tool_list as $key => $new_tool) { |
675
|
|
|
$my_temp_tool_array[] = $all_tools_list[$key]; |
676
|
|
|
} |
677
|
|
|
$all_tools_list = $my_temp_tool_array; |
678
|
|
|
} else { |
679
|
|
|
$all_tools_list = array(); |
680
|
|
|
} |
681
|
|
|
} |
682
|
|
|
$web_code_path = api_get_path(WEB_CODE_PATH); |
683
|
|
|
$session_id = api_get_session_id(); |
684
|
|
|
$is_platform_admin = api_is_platform_admin(); |
685
|
|
|
|
686
|
|
|
if ($session_id == 0 ) { |
687
|
|
|
$is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin(); |
688
|
|
|
} else { |
689
|
|
|
$is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach(); |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
$i = 0; |
693
|
|
|
$items = array(); |
694
|
|
|
$app_plugin = new AppPlugin(); |
695
|
|
|
|
696
|
|
|
if (isset($all_tools_list)) { |
697
|
|
|
$lnk = ''; |
698
|
|
|
|
699
|
|
|
foreach ($all_tools_list as & $tool) { |
700
|
|
|
$item = array(); |
701
|
|
|
$studentview = false; |
702
|
|
|
|
703
|
|
|
$tool['original_link'] = $tool['link']; |
704
|
|
|
|
705
|
|
|
if ($tool['image'] == 'scormbuilder.gif') { |
706
|
|
|
// check if the published learnpath is visible for student |
707
|
|
|
$published_lp_id = self::get_published_lp_id_from_link($tool['link']); |
708
|
|
|
if (api_is_allowed_to_edit(null, true)) { |
709
|
|
|
$studentview = true; |
710
|
|
|
} |
711
|
|
|
if (!api_is_allowed_to_edit(null, true) && |
712
|
|
|
!learnpath::is_lp_visible_for_student( |
713
|
|
|
$published_lp_id, |
714
|
|
|
api_get_user_id(), |
715
|
|
|
api_get_course_id(), |
716
|
|
|
api_get_session_id() |
717
|
|
|
) |
718
|
|
|
) { |
719
|
|
|
continue; |
720
|
|
|
} |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
if ($session_id != 0 && in_array($tool['name'], array('course_setting'))) { |
724
|
|
|
continue; |
725
|
|
|
} |
726
|
|
|
|
727
|
|
|
// This part displays the links to hide or remove a tool. |
728
|
|
|
// These links are only visible by the course manager. |
729
|
|
|
unset($lnk); |
730
|
|
|
|
731
|
|
|
$item['extra'] = null; |
732
|
|
|
$toolAdmin = isset($tool['admin']) ? $tool['admin'] : ''; |
733
|
|
|
|
734
|
|
|
if ($is_allowed_to_edit) { |
735
|
|
|
if (empty($session_id)) { |
736
|
|
|
if (isset($tool['id'])) { |
737
|
|
View Code Duplication |
if ($tool['visibility'] == '1' && $toolAdmin != '1') { |
738
|
|
|
$link['name'] = Display::return_icon( |
739
|
|
|
'visible.png', |
740
|
|
|
get_lang('Deactivate'), |
741
|
|
|
array('id' => 'linktool_'.$tool['id']), |
742
|
|
|
ICON_SIZE_SMALL, |
743
|
|
|
false |
744
|
|
|
); |
745
|
|
|
$link['cmd'] = 'hide=yes'; |
746
|
|
|
$lnk[] = $link; |
747
|
|
|
} |
748
|
|
View Code Duplication |
if ($tool['visibility'] == '0' && $toolAdmin != '1') { |
749
|
|
|
$link['name'] = Display::return_icon( |
750
|
|
|
'invisible.png', |
751
|
|
|
get_lang('Activate'), |
752
|
|
|
array('id' => 'linktool_'.$tool['id']), |
753
|
|
|
ICON_SIZE_SMALL, |
754
|
|
|
false |
755
|
|
|
); |
756
|
|
|
$link['cmd'] = 'restore=yes'; |
757
|
|
|
$lnk[] = $link; |
758
|
|
|
} |
759
|
|
|
} |
760
|
|
|
} |
761
|
|
View Code Duplication |
if (!empty($tool['adminlink'])) { |
762
|
|
|
$item['extra'] = '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>'; |
763
|
|
|
} |
764
|
|
|
} |
765
|
|
|
|
766
|
|
|
// Both checks are necessary as is_platform_admin doesn't take student view into account |
767
|
|
|
if ($is_platform_admin && $is_allowed_to_edit) { |
768
|
|
|
if ($toolAdmin != '1') { |
769
|
|
|
$link['cmd'] = 'hide=yes'; |
770
|
|
|
} |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
$item['visibility'] = null; |
774
|
|
|
|
775
|
|
|
if (isset($lnk) && is_array($lnk)) { |
776
|
|
View Code Duplication |
foreach ($lnk as $this_link) { |
777
|
|
|
if (empty($tool['adminlink'])) { |
778
|
|
|
$item['visibility'] .= '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&id='.$tool['id'].'&'.$this_link['cmd'].'">'. |
779
|
|
|
$this_link['name'].'</a>'; |
780
|
|
|
} |
781
|
|
|
} |
782
|
|
|
} else { |
783
|
|
|
$item['visibility'] .= ''; |
784
|
|
|
} |
785
|
|
|
|
786
|
|
|
// NOTE : Table contains only the image file name, not full path |
787
|
|
View Code Duplication |
if (stripos($tool['link'], 'http://') === false && |
788
|
|
|
stripos($tool['link'], 'https://') === false && |
789
|
|
|
stripos($tool['link'], 'ftp://') === false |
790
|
|
|
) { |
791
|
|
|
$tool['link'] = $web_code_path.$tool['link']; |
792
|
|
|
} |
793
|
|
|
|
794
|
|
|
if ($tool['visibility'] == '0' && $toolAdmin != '1') { |
795
|
|
|
$class = 'invisible'; |
796
|
|
|
$info = pathinfo($tool['image']); |
797
|
|
|
$basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index" |
798
|
|
|
$tool['image'] = $basename.'_na.'.$info['extension']; |
799
|
|
|
} else { |
800
|
|
|
$class = ''; |
801
|
|
|
} |
802
|
|
|
|
803
|
|
|
$qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; |
804
|
|
|
// If it's a link, we don't add the cidReq |
805
|
|
|
|
806
|
|
|
if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') { |
807
|
|
|
$tool['link'] = $tool['link'].$qm_or_amp; |
808
|
|
|
} else { |
809
|
|
|
$tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq(); |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
$tool_link_params = array(); |
813
|
|
|
$toolId = isset($tool["id"]) ? $tool["id"] : null; |
814
|
|
|
|
815
|
|
|
//@todo this visio stuff should be removed |
816
|
|
|
if (strpos($tool['name'], 'visio_') !== false) { |
817
|
|
|
$tool_link_params = array( |
818
|
|
|
'id' => 'tooldesc_'.$toolId, |
819
|
|
|
'href' => '"javascript: void(0);"', |
820
|
|
|
'class' => $class, |
821
|
|
|
'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_visio'.$_SESSION['_cid'].'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', |
822
|
|
|
'target' => $tool['target'] |
823
|
|
|
); |
824
|
|
|
} elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { |
825
|
|
|
$tool_link_params = array( |
826
|
|
|
'id' => 'tooldesc_'.$toolId, |
827
|
|
|
'class' => $class, |
828
|
|
|
'href' => 'javascript: void(0);', |
829
|
|
|
'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',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 |
830
|
|
|
'target' => $tool['target'] |
831
|
|
|
); |
832
|
|
|
} else { |
833
|
|
|
if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) { |
834
|
|
|
$tool_link_params = array( |
835
|
|
|
'id' => 'tooldesc_'.$toolId, |
836
|
|
|
'href' => $tool['link'], |
837
|
|
|
'class' => $class, |
838
|
|
|
'target' => '_blank' |
839
|
|
|
); |
840
|
|
|
} else { |
841
|
|
|
$tool_link_params = array( |
842
|
|
|
'id' => 'tooldesc_'.$toolId, |
843
|
|
|
'href' => $tool['link'], |
844
|
|
|
'class' => $class, |
845
|
|
|
'target' => $tool['target'] |
846
|
|
|
); |
847
|
|
|
} |
848
|
|
|
} |
849
|
|
|
|
850
|
|
|
$tool_name = self::translate_tool_name($tool); |
851
|
|
|
|
852
|
|
|
// Including Courses Plugins |
853
|
|
|
// Creating title and the link |
854
|
|
|
if (isset($tool['category']) && $tool['category'] == 'plugin') { |
855
|
|
|
$plugin_info = $app_plugin->getPluginInfo($tool['name']); |
856
|
|
|
if (isset($plugin_info) && isset($plugin_info['title'])) { |
857
|
|
|
$tool_name = $plugin_info['title']; |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) && |
861
|
|
|
!file_exists(api_get_path(SYS_CODE_PATH).'img/icons/64/'.$tool['image'])) { |
862
|
|
|
$tool['image'] = 'plugins.png'; |
863
|
|
|
} |
864
|
|
|
$tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH).$tool['original_link'].'?'.api_get_cidreq(); |
865
|
|
|
} |
866
|
|
|
|
867
|
|
|
$icon = Display::return_icon( |
868
|
|
|
$tool['image'], |
869
|
|
|
$tool_name, |
870
|
|
|
array('class' => 'tool-icon', 'id' => 'toolimage_'.$toolId), |
871
|
|
|
ICON_SIZE_BIG, |
872
|
|
|
false |
873
|
|
|
); |
874
|
|
|
|
875
|
|
|
/*if (!empty($tool['custom_icon'])) { |
876
|
|
|
$image = self::getCustomWebIconPath().$tool['custom_icon']; |
877
|
|
|
$icon = Display::img( |
878
|
|
|
$image, |
879
|
|
|
$tool['description'], |
880
|
|
|
array( |
881
|
|
|
'class' => 'tool-icon', |
882
|
|
|
'id' => 'toolimage_'.$tool['id'] |
883
|
|
|
) |
884
|
|
|
); |
885
|
|
|
}*/ |
886
|
|
|
|
887
|
|
|
// Validation when belongs to a session |
888
|
|
|
$session_img = api_get_session_image($tool['session_id'], (!empty($_user['status']) ? $_user['status'] : '')); |
889
|
|
|
if ($studentview) { |
890
|
|
|
$tool_link_params['href'] .= '&isStudentView=true'; |
891
|
|
|
} |
892
|
|
|
$item['url_params'] = $tool_link_params; |
893
|
|
|
$item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params); |
894
|
|
|
$item['tool'] = $tool; |
895
|
|
|
$item['name'] = $tool_name; |
896
|
|
|
$tool_link_params['id'] = 'is'.$tool_link_params['id']; |
897
|
|
|
$item['link'] = Display::url( |
898
|
|
|
$tool_name.$session_img, |
899
|
|
|
$tool_link_params['href'], |
900
|
|
|
$tool_link_params |
901
|
|
|
); |
902
|
|
|
|
903
|
|
|
$items[] = $item; |
904
|
|
|
|
905
|
|
|
$i++; |
906
|
|
|
} // end of foreach |
907
|
|
|
} |
908
|
|
|
|
909
|
|
|
$i = 0; |
910
|
|
|
$html = ''; |
911
|
|
|
|
912
|
|
|
if (!empty($items)) { |
913
|
|
|
foreach ($items as $item) { |
914
|
|
|
switch ($theme) { |
915
|
|
|
case 'activity_big': |
916
|
|
|
$data = ''; |
917
|
|
|
$html .= '<div class="col-xs-6 col-md-3 course-tool">'; |
918
|
|
|
$image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png'; |
919
|
|
|
$toolId = isset($item['tool']['id']) ? $item['tool']['id'] : null; |
920
|
|
|
|
921
|
|
|
if (isset($item['tool']['custom_image'])) { |
922
|
|
|
$original_image = Display::img( |
923
|
|
|
$item['tool']['custom_image'], |
924
|
|
|
$item['name'], |
925
|
|
|
array('id' => 'toolimage_'.$toolId) |
926
|
|
|
); |
927
|
|
|
} elseif (isset($item['tool']['custom_icon']) && |
928
|
|
|
!empty($item['tool']['custom_icon']) |
929
|
|
|
) { |
930
|
|
|
$customIcon = $item['tool']['custom_icon']; |
931
|
|
|
if ($item['tool']['visibility'] == '0') { |
932
|
|
|
$fileInfo = pathinfo($item['tool']['custom_icon']); |
933
|
|
|
$customIcon = self::getDisableIcon($item['tool']['custom_icon']); |
934
|
|
|
} |
935
|
|
|
$original_image = Display::img( |
936
|
|
|
self::getCustomWebIconPath().$customIcon, |
937
|
|
|
$item['name'], |
938
|
|
|
array('id' => 'toolimage_'.$toolId) |
939
|
|
|
); |
940
|
|
|
} else { |
941
|
|
|
$original_image = Display::return_icon( |
942
|
|
|
$image, |
943
|
|
|
$item['name'], |
944
|
|
|
array('id' => 'toolimage_'.$toolId), |
945
|
|
|
ICON_SIZE_BIG, |
946
|
|
|
false |
947
|
|
|
); |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
$data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']); |
951
|
|
|
$html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection |
952
|
|
|
$html .= Display::div('<h4>'.$item['visibility'].$item['extra'].$item['link'].'</h4>', array('class' => 'content')); |
953
|
|
|
$html .= '</div>'; |
954
|
|
|
|
955
|
|
|
break; |
956
|
|
|
case 'activity': |
957
|
|
|
$html .= '<div class="offset2 col-md-4 course-tool">'; |
958
|
|
|
$html .= $item['extra']; |
959
|
|
|
$html .= $item['visibility']; |
960
|
|
|
$html .= $item['icon']; |
961
|
|
|
$html .= $item['link']; |
962
|
|
|
$html .= '</div>'; |
963
|
|
|
break; |
964
|
|
|
case 'vertical_activity': |
965
|
|
|
if ($i == 0) { |
966
|
|
|
$html .= '<ul>'; |
967
|
|
|
} |
968
|
|
|
$html .= '<li class="course-tool">'; |
969
|
|
|
$html .= $item['extra']; |
970
|
|
|
$html .= $item['visibility']; |
971
|
|
|
$html .= $item['icon']; |
972
|
|
|
$html .= $item['link']; |
973
|
|
|
$html .= '</li>'; |
974
|
|
|
|
975
|
|
|
if ($i == count($items) - 1) { |
976
|
|
|
$html .= '</ul>'; |
977
|
|
|
} |
978
|
|
|
break; |
979
|
|
|
} |
980
|
|
|
$i++; |
981
|
|
|
} |
982
|
|
|
} |
983
|
|
|
|
984
|
|
|
return $html; |
985
|
|
|
} |
986
|
|
|
|
987
|
|
|
/** |
988
|
|
|
* Shows the general data for a particular meeting |
989
|
|
|
* |
990
|
|
|
* @param id session id |
991
|
|
|
* @return string session data |
992
|
|
|
*/ |
993
|
|
|
public static function show_session_data($id_session) |
994
|
|
|
{ |
995
|
|
|
$session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); |
996
|
|
|
|
997
|
|
|
$sessionInfo = api_get_session_info($id_session); |
998
|
|
|
|
999
|
|
|
if (empty($sessionInfo)) { |
1000
|
|
|
return ''; |
1001
|
|
|
} |
1002
|
|
|
|
1003
|
|
|
$sql = 'SELECT name FROM '.$session_category_table.' |
1004
|
|
|
WHERE id = "'.intval($sessionInfo['session_category_id']).'"'; |
1005
|
|
|
$rs_category = Database::query($sql); |
1006
|
|
|
$session_category = ''; |
1007
|
|
View Code Duplication |
if (Database::num_rows($rs_category) > 0) { |
1008
|
|
|
$rows_session_category = Database::store_result($rs_category); |
1009
|
|
|
$rows_session_category = $rows_session_category[0]; |
1010
|
|
|
$session_category = $rows_session_category['name']; |
1011
|
|
|
} |
1012
|
|
|
|
1013
|
|
|
$coachInfo = api_get_user_info($sessionInfo['id_coach']); |
1014
|
|
|
|
1015
|
|
|
$output = ''; |
1016
|
|
|
if (!empty($session_category)) { |
1017
|
|
|
$output .= '<tr><td>'.get_lang('SessionCategory').': '.'<b>'.$session_category.'</b></td></tr>'; |
1018
|
|
|
} |
1019
|
|
|
$dateInfo = SessionManager::parseSessionDates($sessionInfo); |
1020
|
|
|
|
1021
|
|
|
$msgDate = $dateInfo['access']; |
1022
|
|
|
$output .= '<tr> |
1023
|
|
|
<td style="width:50%">'.get_lang('SessionName').': '.'<b>'.$sessionInfo['name'].'</b></td> |
1024
|
|
|
<td>'.get_lang('GeneralCoach').': '.'<b>'.$coachInfo['complete_name'].'</b></td></tr>'; |
1025
|
|
|
$output .= '<tr> |
1026
|
|
|
<td>'.get_lang('SessionIdentifier').': '. |
1027
|
|
|
Display::return_icon('star.png', ' ', array('align' => 'absmiddle')).' |
1028
|
|
|
</td> |
1029
|
|
|
<td>'.get_lang('Date').': '.'<b>'.$msgDate.'</b> |
1030
|
|
|
</td> |
1031
|
|
|
</tr>'; |
1032
|
|
|
|
1033
|
|
|
return $output; |
1034
|
|
|
} |
1035
|
|
|
|
1036
|
|
|
/** |
1037
|
|
|
* Retrieves the name-field within a tool-record and translates it on necessity. |
1038
|
|
|
* @param array $tool The input record. |
1039
|
|
|
* @return string Returns the name of the corresponding tool. |
1040
|
|
|
*/ |
1041
|
|
|
public static function translate_tool_name(& $tool) |
1042
|
|
|
{ |
1043
|
|
|
static $already_translated_icons = array( |
1044
|
|
|
'file_html.gif', |
1045
|
|
|
'file_html_na.gif', |
1046
|
|
|
'file_html.png', |
1047
|
|
|
'file_html_na.png', |
1048
|
|
|
'scormbuilder.gif', |
1049
|
|
|
'scormbuilder_na.gif', |
1050
|
|
|
'blog.gif', |
1051
|
|
|
'blog_na.gif', |
1052
|
|
|
'external.gif', |
1053
|
|
|
'external_na.gif' |
1054
|
|
|
); |
1055
|
|
|
|
1056
|
|
|
$toolName = Security::remove_XSS(stripslashes($tool['name'])); |
1057
|
|
|
|
1058
|
|
|
if (in_array($tool['image'], $already_translated_icons)) { |
1059
|
|
|
return $toolName; |
1060
|
|
|
} |
1061
|
|
|
|
1062
|
|
|
$toolName = api_underscore_to_camel_case($toolName); |
1063
|
|
|
|
1064
|
|
|
if (isset($GLOBALS['Tool' . $toolName])) { |
1065
|
|
|
return get_lang('Tool' . $toolName); |
1066
|
|
|
} |
1067
|
|
|
|
1068
|
|
|
return $toolName; |
1069
|
|
|
} |
1070
|
|
|
|
1071
|
|
|
/** |
1072
|
|
|
* Get published learning path id from link inside course home |
1073
|
|
|
* @param string Link to published lp |
1074
|
|
|
* @return int Learning path id |
1075
|
|
|
*/ |
1076
|
|
|
public static function get_published_lp_id_from_link($published_lp_link) |
1077
|
|
|
{ |
1078
|
|
|
$lp_id = 0; |
1079
|
|
|
$param_lp_id = strstr($published_lp_link, 'lp_id='); |
1080
|
|
|
if (!empty($param_lp_id)) { |
1081
|
|
|
$a_param_lp_id = explode('=', $param_lp_id); |
1082
|
|
|
if (isset($a_param_lp_id[1])) { |
1083
|
|
|
$lp_id = intval($a_param_lp_id[1]); |
1084
|
|
|
} |
1085
|
|
|
} |
1086
|
|
|
return $lp_id; |
1087
|
|
|
} |
1088
|
|
|
|
1089
|
|
|
/** |
1090
|
|
|
* @param bool $include_admin_tools |
1091
|
|
|
* @return array |
1092
|
|
|
*/ |
1093
|
|
|
static function get_navigation_items($include_admin_tools = false) |
1094
|
|
|
{ |
1095
|
|
|
$navigation_items = array(); |
1096
|
|
|
$course_id = api_get_course_int_id(); |
1097
|
|
|
|
1098
|
|
|
if (!empty($course_id)) { |
1099
|
|
|
|
1100
|
|
|
$course_tools_table = Database :: get_course_table(TABLE_TOOL_LIST); |
1101
|
|
|
|
1102
|
|
|
/* Link to the Course homepage */ |
1103
|
|
|
|
1104
|
|
|
$navigation_items['home']['image'] = 'home.gif'; |
1105
|
|
|
$navigation_items['home']['link'] = api_get_path(WEB_CODE_PATH).Security::remove_XSS($_SESSION['_course']['path']).'/index.php'; |
1106
|
|
|
$navigation_items['home']['name'] = get_lang('CourseHomepageLink'); |
1107
|
|
|
|
1108
|
|
|
$sql_menu_query = "SELECT * FROM $course_tools_table |
1109
|
|
|
WHERE c_id = $course_id AND visibility='1' and admin='0' |
1110
|
|
|
ORDER BY id ASC"; |
1111
|
|
|
$sql_result = Database::query($sql_menu_query); |
1112
|
|
|
while ($row = Database::fetch_array($sql_result)) { |
1113
|
|
|
$navigation_items[$row['id']] = $row; |
1114
|
|
|
if (stripos($row['link'], 'http://') === false && stripos($row['link'], 'https://') === false) { |
1115
|
|
|
$navigation_items[$row['id']]['link'] = api_get_path(WEB_CODE_PATH).$row['link']; |
1116
|
|
|
$navigation_items[$row['id']]['name'] = CourseHome::translate_tool_name($row); |
1117
|
|
|
} |
1118
|
|
|
} |
1119
|
|
|
|
1120
|
|
|
/* Admin (edit rights) only links |
1121
|
|
|
- Course settings (course admin only) |
1122
|
|
|
- Course rights (roles & rights overview) */ |
1123
|
|
|
|
1124
|
|
|
if ($include_admin_tools) { |
1125
|
|
|
$course_settings_sql = "SELECT name,image FROM $course_tools_table |
1126
|
|
|
WHERE c_id = $course_id AND link='course_info/infocours.php'"; |
1127
|
|
|
$sql_result = Database::query($course_settings_sql); |
1128
|
|
|
$course_setting_info = Database::fetch_array($sql_result); |
1129
|
|
|
$course_setting_visual_name = CourseHome::translate_tool_name($course_setting_info); |
1130
|
|
|
if (api_get_session_id() == 0) { |
1131
|
|
|
// course settings item |
1132
|
|
|
$navigation_items['course_settings']['image'] = $course_setting_info['image']; |
1133
|
|
|
$navigation_items['course_settings']['link'] = api_get_path(WEB_CODE_PATH).'course_info/infocours.php'; |
1134
|
|
|
$navigation_items['course_settings']['name'] = $course_setting_visual_name; |
1135
|
|
|
} |
1136
|
|
|
} |
1137
|
|
|
} |
1138
|
|
|
|
1139
|
|
|
foreach ($navigation_items as $key => $navigation_item) { |
1140
|
|
|
if (strstr($navigation_item['link'], '?')) { |
1141
|
|
|
//link already contains a parameter, add course id parameter with & |
1142
|
|
|
$parameter_separator = '&'; |
1143
|
|
|
} else { |
1144
|
|
|
//link doesn't contain a parameter yet, add course id parameter with ? |
1145
|
|
|
$parameter_separator = '?'; |
1146
|
|
|
} |
1147
|
|
|
//$navigation_items[$key]['link'] .= $parameter_separator.api_get_cidreq(); |
1148
|
|
|
$navigation_items[$key]['link'] .= $parameter_separator.'cidReq='.api_get_course_id().'&gidReq=0&id_session='.api_get_session_id(); |
1149
|
|
|
} |
1150
|
|
|
|
1151
|
|
|
return $navigation_items; |
1152
|
|
|
} |
1153
|
|
|
|
1154
|
|
|
/** |
1155
|
|
|
* Show a navigation menu |
1156
|
|
|
*/ |
1157
|
|
|
public static function show_navigation_menu() |
1158
|
|
|
{ |
1159
|
|
|
$navigation_items = self::get_navigation_items(true); |
1160
|
|
|
$course_id = api_get_course_id(); |
1161
|
|
|
|
1162
|
|
|
$html = '<div id="toolnav"> <!-- start of #toolnav -->'; |
1163
|
|
|
if (api_get_setting('show_navigation_menu') == 'icons') { |
1164
|
|
|
$html .= self::show_navigation_tool_shortcuts($orientation = SHORTCUTS_VERTICAL); |
1165
|
|
|
} else { |
1166
|
|
|
$html .= '<div id="toolnavbox">'; |
1167
|
|
|
$html .= '<div id="toolnavlist"><dl>'; |
1168
|
|
|
foreach ($navigation_items as $key => $navigation_item) { |
1169
|
|
|
//students can't see the course settings option |
1170
|
|
|
if (!api_is_allowed_to_edit() && $key == 'course_settings') { |
1171
|
|
|
continue; |
1172
|
|
|
} |
1173
|
|
|
$html .= '<dd>'; |
1174
|
|
|
$url_item = parse_url($navigation_item['link']); |
1175
|
|
|
$url_current = parse_url($_SERVER['REQUEST_URI']); |
1176
|
|
|
|
1177
|
|
View Code Duplication |
if (strpos($navigation_item['link'], 'chat') !== false && |
1178
|
|
|
api_get_course_setting('allow_open_chat_window', $course_id) |
1179
|
|
|
) { |
1180
|
|
|
$html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',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'].'"'; |
1181
|
|
|
} else { |
1182
|
|
|
$html .= '<a href="'.$navigation_item['link'].'" target="_top" '; |
1183
|
|
|
} |
1184
|
|
|
|
1185
|
|
|
if (stristr($url_item['path'], $url_current['path'])) { |
1186
|
|
|
if (!isset($_GET['learnpath_id']) || strpos($url_item['query'], 'learnpath_id='.$_GET['learnpath_id']) === 0) { |
1187
|
|
|
$html .= ' id="here"'; |
1188
|
|
|
} |
1189
|
|
|
} |
1190
|
|
|
$html .= ' title="'.$navigation_item['name'].'">'; |
1191
|
|
|
if (api_get_setting('show_navigation_menu') != 'text') { |
1192
|
|
|
$html .= '<div align="left"><img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/></div>'; |
1193
|
|
|
} |
1194
|
|
|
if (api_get_setting('show_navigation_menu') != 'icons') { |
1195
|
|
|
$html .= $navigation_item['name']; |
1196
|
|
|
} |
1197
|
|
|
$html .= '</a>'; |
1198
|
|
|
$html .= '</dd>'; |
1199
|
|
|
} |
1200
|
|
|
$html .= '</dl></div></div>'; |
1201
|
|
|
} |
1202
|
|
|
$html .= '</div><!-- end "#toolnav" -->'; |
1203
|
|
|
return $html; |
1204
|
|
|
} |
1205
|
|
|
|
1206
|
|
|
/** |
1207
|
|
|
* Show a toolbar with shortcuts to the course tool |
1208
|
|
|
*/ |
1209
|
|
|
public static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL) |
1210
|
|
|
{ |
1211
|
|
|
$navigation_items = self::get_navigation_items(false); |
1212
|
|
|
$html = ''; |
1213
|
|
|
if (!empty($navigation_items)) { |
1214
|
|
|
if ($orientation == SHORTCUTS_HORIZONTAL) |
1215
|
|
|
$style_id = "toolshortcuts_horizontal"; |
1216
|
|
|
else { |
1217
|
|
|
$style_id = "toolshortcuts_vertical"; |
1218
|
|
|
} |
1219
|
|
|
$html .= '<div id="'.$style_id.'">'; |
1220
|
|
|
|
1221
|
|
|
foreach ($navigation_items as $key => $navigation_item) { |
1222
|
|
View Code Duplication |
if (strpos($navigation_item['link'], 'chat') !== false && |
1223
|
|
|
api_get_course_setting('allow_open_chat_window') |
1224
|
|
|
) { |
1225
|
|
|
$html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',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'].'"'; |
1226
|
|
|
} else { |
1227
|
|
|
$html .= '<a href="'.$navigation_item['link'].'"'; |
1228
|
|
|
} |
1229
|
|
|
if (strpos(api_get_self(), $navigation_item['link']) !== false) { |
1230
|
|
|
$html .= ' id="here"'; |
1231
|
|
|
} |
1232
|
|
|
$html .= ' target="_top" title="'.$navigation_item['name'].'">'; |
1233
|
|
|
$html .= '<img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/>'; |
1234
|
|
|
$html .= '</a> '; |
1235
|
|
|
if ($orientation == SHORTCUTS_VERTICAL) { |
1236
|
|
|
$html .= '<br />'; |
1237
|
|
|
} |
1238
|
|
|
} |
1239
|
|
|
$html .= '</div>'; |
1240
|
|
|
} |
1241
|
|
|
return $html; |
1242
|
|
|
} |
1243
|
|
|
|
1244
|
|
|
/** |
1245
|
|
|
* List course homepage tools from authoring and interaction sections |
1246
|
|
|
* @param int $courseId The course ID (guessed from context if not provided) |
1247
|
|
|
* @param int $sessionId The session ID (guessed from context if not provided) |
1248
|
|
|
* @return array List of all tools data from the c_tools table |
1249
|
|
|
*/ |
1250
|
|
|
public static function toolsIconsAction($courseId = null, $sessionId = null) |
1251
|
|
|
{ |
1252
|
|
|
if (empty($courseId)) { |
1253
|
|
|
$courseId = api_get_course_int_id(); |
1254
|
|
|
} else { |
1255
|
|
|
$courseId = intval($courseId); |
1256
|
|
|
} |
1257
|
|
|
if (empty($sessionId)) { |
1258
|
|
|
$sessionId = api_get_session_id(); |
1259
|
|
|
} else { |
1260
|
|
|
$sessionId = intval($sessionId); |
1261
|
|
|
} |
1262
|
|
|
|
1263
|
|
|
if (empty($courseId)) { |
1264
|
|
|
// We shouldn't get here, but for some reason api_get_course_int_id() |
1265
|
|
|
// doesn't seem to get the course from the context, sometimes |
1266
|
|
|
return array(); |
1267
|
|
|
} |
1268
|
|
|
|
1269
|
|
|
$table = Database::get_course_table(TABLE_TOOL_LIST); |
1270
|
|
|
$sql = "SELECT * FROM $table |
1271
|
|
|
WHERE category in ('authoring','interaction') |
1272
|
|
|
AND c_id = $courseId |
1273
|
|
|
AND session_id = $sessionId |
1274
|
|
|
ORDER BY id"; |
1275
|
|
|
|
1276
|
|
|
$result = Database::query($sql); |
1277
|
|
|
$data = Database::store_result($result, 'ASSOC'); |
1278
|
|
|
|
1279
|
|
|
return $data; |
1280
|
|
|
} |
1281
|
|
|
|
1282
|
|
|
/** |
1283
|
|
|
* @param int $editIcon |
1284
|
|
|
* @return array |
1285
|
|
|
*/ |
1286
|
|
|
public static function getTool($editIcon) |
1287
|
|
|
{ |
1288
|
|
|
$course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); |
1289
|
|
|
$editIcon = intval($editIcon); |
1290
|
|
|
|
1291
|
|
|
$sql = "SELECT * FROM $course_tool_table |
1292
|
|
|
WHERE iid = $editIcon"; |
1293
|
|
|
$result = Database::query($sql); |
1294
|
|
|
$tool = Database::fetch_assoc($result, 'ASSOC'); |
1295
|
|
|
|
1296
|
|
|
return $tool; |
1297
|
|
|
} |
1298
|
|
|
|
1299
|
|
|
/** |
1300
|
|
|
* @return string |
1301
|
|
|
*/ |
1302
|
|
|
public static function getCustomSysIconPath() |
1303
|
|
|
{ |
1304
|
|
|
// Check if directory exists or create it if it doesn't |
1305
|
|
|
$dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/'; |
1306
|
|
|
if (!is_dir($dir)) { |
1307
|
|
|
mkdir($dir, api_get_permissions_for_new_directories(), true); |
1308
|
|
|
} |
1309
|
|
|
|
1310
|
|
|
return $dir; |
1311
|
|
|
} |
1312
|
|
|
|
1313
|
|
|
/** |
1314
|
|
|
* @return string |
1315
|
|
|
*/ |
1316
|
|
|
public static function getCustomWebIconPath() |
1317
|
|
|
{ |
1318
|
|
|
// Check if directory exists or create it if it doesn't |
1319
|
|
|
$dir = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/'; |
1320
|
|
|
|
1321
|
|
|
return $dir; |
1322
|
|
|
} |
1323
|
|
|
|
1324
|
|
|
/** |
1325
|
|
|
* @param string $icon |
1326
|
|
|
* @return string |
1327
|
|
|
*/ |
1328
|
|
|
public static function getDisableIcon($icon) |
1329
|
|
|
{ |
1330
|
|
|
$fileInfo = pathinfo($icon); |
1331
|
|
|
|
1332
|
|
|
return $fileInfo['filename'].'_na.'.$fileInfo['extension']; |
1333
|
|
|
} |
1334
|
|
|
|
1335
|
|
|
/** |
1336
|
|
|
* @param int $id |
1337
|
|
|
* @param array $values |
1338
|
|
|
*/ |
1339
|
|
|
public static function updateTool($id, $values) |
1340
|
|
|
{ |
1341
|
|
|
$table = Database::get_course_table(TABLE_TOOL_LIST); |
1342
|
|
|
$params = [ |
1343
|
|
|
'name' => $values['name'], |
1344
|
|
|
'link' => $values['link'], |
1345
|
|
|
'target' => $values['target'], |
1346
|
|
|
'visibility' => $values['visibility'], |
1347
|
|
|
'description' => $values['description'], |
1348
|
|
|
]; |
1349
|
|
|
|
1350
|
|
|
if (isset($_FILES['icon']['size']) && $_FILES['icon']['size'] !== 0) { |
1351
|
|
|
$dir = self::getCustomSysIconPath(); |
1352
|
|
|
|
1353
|
|
|
// Resize image if it is larger than 64px |
1354
|
|
|
$temp = new Image($_FILES['icon']['tmp_name']); |
1355
|
|
|
$picture_infos = $temp->get_image_info(); |
1356
|
|
|
if ($picture_infos['width'] > 64) { |
1357
|
|
|
$thumbwidth = 64; |
1358
|
|
|
} else { |
1359
|
|
|
$thumbwidth = $picture_infos['width']; |
1360
|
|
|
} |
1361
|
|
|
if ($picture_infos['height'] > 64) { |
1362
|
|
|
$new_height = 64; |
1363
|
|
|
} else { |
1364
|
|
|
$new_height = $picture_infos['height']; |
1365
|
|
|
} |
1366
|
|
|
$temp->resize($thumbwidth, $new_height, 0); |
1367
|
|
|
|
1368
|
|
|
//copy the image to the course upload folder |
1369
|
|
|
$path = $dir.$_FILES['icon']['name']; |
1370
|
|
|
$result = $temp->send_image($path); |
1371
|
|
|
|
1372
|
|
|
$temp = new Image($path); |
1373
|
|
|
$r = $temp->convert2bw(); |
|
|
|
|
1374
|
|
|
$ext = pathinfo($path, PATHINFO_EXTENSION); |
1375
|
|
|
$bwPath = substr($path,0,-(strlen($ext)+1)) . '_na.' . $ext; |
1376
|
|
|
|
1377
|
|
|
if ($r === false) { |
1378
|
|
|
error_log('Conversion to B&W of '.$path.' failed in '.__FILE__.' at line '.__LINE__); |
1379
|
|
|
} else { |
1380
|
|
|
$temp->send_image($bwPath); |
1381
|
|
|
$iconName = $_FILES['icon']['name']; |
1382
|
|
|
$params['custom_icon'] = $iconName; |
1383
|
|
|
} |
1384
|
|
|
} |
1385
|
|
|
|
1386
|
|
|
Database::update( |
1387
|
|
|
$table, |
1388
|
|
|
$params, |
1389
|
|
|
[' iid = ?' => [$id]] |
1390
|
|
|
); |
1391
|
|
|
} |
1392
|
|
|
|
1393
|
|
|
/** |
1394
|
|
|
* @param int $id |
1395
|
|
|
*/ |
1396
|
|
|
public static function deleteIcon($id) |
1397
|
|
|
{ |
1398
|
|
|
$table = Database::get_course_table(TABLE_TOOL_LIST); |
1399
|
|
|
$tool = self::getTool($id); |
1400
|
|
|
|
1401
|
|
|
if ($tool && !empty($tool['custom_icon'])) { |
1402
|
|
|
$file = self::getCustomSysIconPath().$tool['custom_icon']; |
1403
|
|
|
$fileInfo = pathinfo($file); |
1404
|
|
|
$fileGray = $fileInfo['filename'].'_na.'.$fileInfo['extension']; |
1405
|
|
|
$fileGray = self::getCustomSysIconPath().$fileGray; |
1406
|
|
|
|
1407
|
|
View Code Duplication |
if (file_exists($file) && is_file($file)) { |
1408
|
|
|
if (Security::check_abs_path($file, self::getCustomSysIconPath())) { |
1409
|
|
|
unlink($file); |
1410
|
|
|
} |
1411
|
|
|
} |
1412
|
|
|
|
1413
|
|
View Code Duplication |
if (file_exists($fileGray) && is_file($fileGray)) { |
1414
|
|
|
if (Security::check_abs_path($fileGray, self::getCustomSysIconPath())) { |
1415
|
|
|
unlink($fileGray); |
1416
|
|
|
} |
1417
|
|
|
} |
1418
|
|
|
|
1419
|
|
|
$params = [ |
1420
|
|
|
'custom_icon' => '', |
1421
|
|
|
]; |
1422
|
|
|
|
1423
|
|
|
Database::update( |
1424
|
|
|
$table, |
1425
|
|
|
$params, |
1426
|
|
|
[' iid = ?' => [$id]] |
1427
|
|
|
); |
1428
|
|
|
} |
1429
|
|
|
} |
1430
|
|
|
} |
1431
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: