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