course_home.lib.php 68 KB

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