course_home.lib.php 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  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. */
  11. public static function show_tool_3column($cat)
  12. {
  13. global $_user;
  14. $TBL_ACCUEIL = Database :: get_course_table(TABLE_TOOL_LIST);
  15. $TABLE_TOOLS = Database :: get_main_table(TABLE_MAIN_COURSE_MODULE);
  16. $numcols = 3;
  17. $table = new HTML_Table('width="100%"');
  18. $all_tools = array();
  19. $course_id = api_get_course_int_id();
  20. switch ($cat) {
  21. case 'Basic':
  22. $condition_display_tools = ' WHERE a.c_id = '.$course_id.' AND a.link=t.link AND t.position="basic" ';
  23. if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
  24. $condition_display_tools = ' WHERE a.c_id = '.$course_id.' AND a.link=t.link AND (t.position="basic" OR a.name = "'.TOOL_TRACKING.'") ';
  25. }
  26. $sql = "SELECT a.*, t.image img, t.row_module, t.column_module FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  27. $condition_display_tools ORDER BY t.row_module, t.column_module";
  28. break;
  29. case 'External':
  30. if (api_is_allowed_to_edit()) {
  31. $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  32. WHERE a.c_id = $course_id AND ((a.link=t.link AND t.position='external')
  33. OR (a.visibility <= 1 AND (a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image))
  34. ORDER BY a.id";
  35. } else {
  36. $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  37. WHERE a.c_id = $course_id AND (a.visibility = 1 AND ((a.link=t.link AND t.position='external')
  38. OR ((a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image)))
  39. ORDER BY a.id";
  40. }
  41. break;
  42. case 'courseAdmin':
  43. $sql = "SELECT a.*, t.image img, t.row_module, t.column_module FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  44. WHERE a.c_id = $course_id AND admin=1 AND a.link=t.link ORDER BY t.row_module, t.column_module";
  45. break;
  46. case 'platformAdmin':
  47. $sql = "SELECT *, image img FROM $TBL_ACCUEIL WHERE c_id = $course_id AND visibility = 2 ORDER BY id";
  48. }
  49. $result = Database::query($sql);
  50. // Grabbing all the tools from $course_tool_table
  51. while ($tool = Database::fetch_array($result)) {
  52. $all_tools[] = $tool;
  53. }
  54. $course_id = api_get_course_int_id();
  55. // Grabbing all the links that have the property on_homepage set to 1
  56. if ($cat == 'External') {
  57. $tbl_link = Database :: get_course_table(TABLE_LINK);
  58. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  59. if (api_is_allowed_to_edit(null, true)) {
  60. $sql_links = "SELECT tl.*, tip.visibility
  61. FROM $tbl_link tl
  62. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  63. WHERE tl.c_id = $course_id AND
  64. tip.c_id = $course_id AND
  65. tl.on_homepage='1' AND
  66. tip.visibility != 2";
  67. } else {
  68. $sql_links = "SELECT tl.*, tip.visibility
  69. FROM $tbl_link tl
  70. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  71. WHERE tl.c_id = $course_id AND
  72. tip.c_id = $course_id AND
  73. tl.on_homepage='1' AND
  74. tip.visibility = 1";
  75. }
  76. $result_links = Database::query($sql_links);
  77. while ($links_row = Database::fetch_array($result_links)) {
  78. $properties = array();
  79. $properties['name'] = $links_row['title'];
  80. $properties['link'] = $links_row['url'];
  81. $properties['visibility'] = $links_row['visibility'];
  82. $properties['img'] = 'external.gif';
  83. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&amp;id='.$links_row['id'];
  84. $all_tools[] = $properties;
  85. }
  86. }
  87. $cell_number = 0;
  88. // Draw line between basic and external, only if there are entries in External
  89. if ($cat == 'External' && count($all_tools)) {
  90. $table->setCellContents(0, 0, '<hr noshade="noshade" size="1"/>');
  91. $table->updateCellAttributes(0, 0, 'colspan="3"');
  92. $cell_number += $numcols;
  93. }
  94. foreach ($all_tools as & $tool) {
  95. if ($tool['image'] == 'scormbuilder.gif') {
  96. // display links to lp only for current session
  97. /*if (api_get_session_id() != $tool['session_id']) {
  98. continue;
  99. }*/
  100. // check if the published learnpath is visible for student
  101. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  102. if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id())) {
  103. continue;
  104. }
  105. }
  106. if (api_get_session_id() != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
  107. continue;
  108. }
  109. $cell_content = '';
  110. // The name of the tool
  111. $tool_name = self::translate_tool_name($tool);
  112. $link_annex = '';
  113. // The url of the tool
  114. if ($tool['img'] != 'external.gif') {
  115. $tool['link'] = api_get_path(WEB_CODE_PATH).$tool['link'];
  116. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
  117. $link_annex = $qm_or_amp.api_get_cidreq();
  118. } else {
  119. // If an external link ends with 'login=', add the actual login...
  120. $pos = strpos($tool['link'], '?login=');
  121. $pos2 = strpos($tool['link'], '&amp;login=');
  122. if ($pos !== false or $pos2 !== false) {
  123. $link_annex = $_user['username'];
  124. }
  125. }
  126. // Setting the actual image url
  127. $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img'];
  128. // VISIBLE
  129. if (($tool['visibility'] || ((api_is_coach() || api_is_course_tutor()) && $tool['name'] == TOOL_TRACKING)) || $cat == 'courseAdmin' || $cat == 'platformAdmin') {
  130. if (strpos($tool['name'], 'visio_') !== false) {
  131. $cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\'' . $tool['link'].$link_annex . '\',\'window_visio'.$_SESSION['_cid'].'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $tool['target'] . '"><img src="'.$tool['img'].'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  132. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  133. $cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\'' .$tool['link'].$link_annex. '\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', 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>';
  134. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  135. } else {
  136. $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>';
  137. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  138. }
  139. } else {
  140. // INVISIBLE
  141. if (api_is_allowed_to_edit(null, true)) {
  142. if (strpos($tool['name'], 'visio_') !== false) {
  143. $cell_content .= '<a href="javascript: void(0);" onclick="window.open(\'' . $tool['link'].$link_annex . '\',\'window_visio'.$_SESSION['_cid'].'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $tool['target'] . '"><img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  144. } elseif (strpos($tool['name'],'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  145. $cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\'' .$tool['link'].$link_annex. '\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $tool['target'] . '" class="invisible"><img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  146. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  147. } else {
  148. $cell_content .= '<a href="'.$tool['link'].$link_annex.'" target="'.$tool['target'].'" class="invisible">
  149. <img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  150. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  151. }
  152. } else {
  153. $cell_content .= '<img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">';
  154. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  155. $cell_content .= '<span class="invisible">'.$tool_name.'</span>';
  156. }
  157. }
  158. $lnk = array();
  159. if (api_is_allowed_to_edit(null, true) && $cat != "courseAdmin" && !strpos($tool['link'], 'learnpath_handler.php?learnpath_id') && !api_is_coach()) {
  160. if ($tool['visibility']) {
  161. $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'), array('style' => 'vertical-align: middle;'));
  162. $link['cmd'] = "hide=yes";
  163. $lnk[] = $link;
  164. } else {
  165. $link['name'] = Display::return_icon('add.gif', get_lang('Activate'), array('style' => 'vertical-align: middle;'));
  166. $link['cmd'] = "restore=yes";
  167. $lnk[] = $link;
  168. }
  169. if (is_array($lnk)) {
  170. foreach ($lnk as & $this_lnk) {
  171. if ($tool['adminlink']) {
  172. $cell_content .= '<a href="'.$properties['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  173. } else {
  174. $cell_content .= '<a href="'.api_get_self().'?id='.$tool['id'].'&amp;'.$this_lnk['cmd'].'">'.$this_lnk['name'].'</a>';
  175. }
  176. }
  177. }
  178. }
  179. $table->setCellContents($cell_number / $numcols, ($cell_number) % $numcols, $cell_content);
  180. $table->updateCellAttributes($cell_number / $numcols, ($cell_number) % $numcols, 'width="32%" height="42"');
  181. $cell_number ++;
  182. }
  183. return $table->toHtml();
  184. }
  185. /**
  186. * Displays the tools of a certain category.
  187. *
  188. * @return void
  189. * @param string $course_tool_category contains the category of tools to display:
  190. * "Public", "PublicButHide", "courseAdmin", "claroAdmin"
  191. */
  192. public static function show_tool_2column($course_tool_category)
  193. {
  194. $html = '';
  195. $web_code_path = api_get_path(WEB_CODE_PATH);
  196. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  197. $course_id = api_get_course_int_id();
  198. switch ($course_tool_category) {
  199. case TOOL_PUBLIC:
  200. $condition_display_tools = ' WHERE c_id = '.$course_id.' AND visibility = 1 ';
  201. if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
  202. $condition_display_tools = ' WHERE c_id = '.$course_id.' AND (visibility = 1 OR (visibility = 0 AND name = "'.TOOL_TRACKING.'")) ';
  203. }
  204. $result = Database::query("SELECT * FROM $course_tool_table $condition_display_tools ORDER BY id");
  205. $col_link ="##003399";
  206. break;
  207. case TOOL_PUBLIC_BUT_HIDDEN:
  208. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility=0 AND admin=0 ORDER BY id");
  209. $col_link ="##808080";
  210. break;
  211. case TOOL_COURSE_ADMIN:
  212. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND admin=1 AND visibility != 2 ORDER BY id");
  213. $col_link ="##003399";
  214. break;
  215. case TOOL_PLATFORM_ADMIN:
  216. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility = 2 ORDER BY id");
  217. $col_link ="##003399";
  218. }
  219. $i = 0;
  220. // Grabbing all the tools from $course_tool_table
  221. while ($temp_row = Database::fetch_array($result)) {
  222. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN && $temp_row['image'] != 'scormbuilder.gif') {
  223. $temp_row['image'] = str_replace('.gif', '_na.gif', $temp_row['image']);
  224. }
  225. $all_tools_list[] = $temp_row;
  226. }
  227. // Grabbing all the links that have the property on_homepage set to 1
  228. $course_link_table = Database::get_course_table(TABLE_LINK);
  229. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  230. switch ($course_tool_category) {
  231. case TOOL_PUBLIC:
  232. $sql_links = "SELECT tl.*, tip.visibility
  233. FROM $course_link_table tl
  234. 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
  235. WHERE tl.on_homepage='1' AND tip.visibility = 1";
  236. break;
  237. case TOOL_PUBLIC_BUT_HIDDEN:
  238. $sql_links = "SELECT tl.*, tip.visibility
  239. FROM $course_link_table tl
  240. 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
  241. WHERE tl.on_homepage='1' AND tip.visibility = 0";
  242. break;
  243. default:
  244. $sql_links = null;
  245. break;
  246. }
  247. if ($sql_links != null) {
  248. $properties = array();
  249. $result_links = Database::query($sql_links);
  250. while ($links_row = Database::fetch_array($result_links)) {
  251. unset($properties);
  252. $properties['name'] = $links_row['title'];
  253. $properties['link'] = $links_row['url'];
  254. $properties['visibility'] = $links_row['visibility'];
  255. $properties['image'] = $course_tool_category == TOOL_PUBLIC_BUT_HIDDEN ? 'external_na.gif' : 'external.gif';
  256. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  257. $all_tools_list[] = $properties;
  258. }
  259. }
  260. if (isset($all_tools_list)) {
  261. $lnk = array();
  262. foreach ($all_tools_list as & $tool) {
  263. if ($tool['image'] == 'scormbuilder.gif') {
  264. // display links to lp only for current session
  265. /*if (api_get_session_id() != $tool['session_id']) {
  266. continue;
  267. }*/
  268. // check if the published learnpath is visible for student
  269. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  270. if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id,api_get_user_id())) {
  271. continue;
  272. }
  273. }
  274. if (api_get_session_id() != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
  275. continue;
  276. }
  277. if (!($i % 2)) {
  278. $html .= "<tr valign=\"top\">";
  279. }
  280. // NOTE : Table contains only the image file name, not full path
  281. if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) {
  282. $tool['link'] = $web_code_path.$tool['link'];
  283. }
  284. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) {
  285. $class = 'class="invisible"';
  286. }
  287. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
  288. $tool['link'] = $tool['link'];
  289. $html .= '<td width="50%" height="30">';
  290. if (strpos($tool['name'], 'visio_') !== false) {
  291. $html .= '<a '.$class.' href="javascript: void(0);" onclick="javascript: window.open(\'' . htmlspecialchars($tool['link']).(($tool['image'] == 'external.gif' || $tool['image'] == 'external_na.gif') ? '' : $qm_or_amp.api_get_cidreq()) . '\',\'window_visio'.$_SESSION['_cid'].'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $tool['target'] . '">';
  292. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  293. $html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\'' . htmlspecialchars($tool['link']).$qm_or_amp.api_get_cidreq() . '\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $tool['target'] . '"'.$class.'>';
  294. } else {
  295. $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.'>';
  296. }
  297. $tool_name = self::translate_tool_name($tool);
  298. $html .= Display::return_icon($tool['image'], $tool_name, array(), null, ICON_SIZE_MEDIUM).'&nbsp;'.$tool_name.'</a>';
  299. // This part displays the links to hide or remove a tool.
  300. // These links are only visible by the course manager.
  301. unset($lnk);
  302. if (api_is_allowed_to_edit(null, true) && !api_is_coach()) {
  303. if ($tool['visibility'] == '1' || $tool['name'] == TOOL_TRACKING) {
  304. $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'));
  305. $link['cmd'] = 'hide=yes';
  306. $lnk[] = $link;
  307. }
  308. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) {
  309. $link['name'] = Display::return_icon('add.gif', get_lang('Activate'));
  310. $link['cmd'] = 'restore=yes';
  311. $lnk[] = $link;
  312. if ($tool['added_tool'] == 1) {
  313. $link['name'] = Display::return_icon('delete.gif', get_lang('Remove'));
  314. $link['cmd'] = 'remove=yes';
  315. $lnk[] = $link;
  316. }
  317. }
  318. if ($tool['adminlink']) {
  319. $html .= '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  320. }
  321. }
  322. if (api_is_platform_admin() && !api_is_coach()) {
  323. if ($tool['visibility'] == 2) {
  324. $link['name'] = Display::return_icon('undelete.gif', get_lang('Activate'));
  325. $link['cmd'] = 'hide=yes';
  326. $lnk[] = $link;
  327. if ($tool['added_tool'] == 1) {
  328. $link['name'] = get_lang('Delete');
  329. $link['cmd'] = 'askDelete=yes';
  330. $lnk[] = $link;
  331. }
  332. }
  333. if ($tool['visibility'] == 0 && $tool['added_tool'] == 0) {
  334. $link['name'] = Display::return_icon('delete.gif', get_lang('Remove'));
  335. $link['cmd'] = 'remove=yes';
  336. $lnk[] = $link;
  337. }
  338. }
  339. if (is_array($lnk)) {
  340. foreach ($lnk as & $this_link) {
  341. if (!$tool['adminlink']) {
  342. $html .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$tool['id'].'&amp;'.$this_link['cmd'].'">'.$this_link['name'].'</a>';
  343. }
  344. }
  345. }
  346. $html .= "</td>";
  347. if ($i % 2) {
  348. $html .= "</tr>";
  349. }
  350. $i++;
  351. }
  352. }
  353. if ($i % 2) {
  354. $html .= "<td width=\"50%\">&nbsp;</td></tr>";
  355. }
  356. return $html;
  357. }
  358. /**
  359. * Gets the tools of a certain category. Returns an array expected
  360. * by show_tools_category()
  361. * @param string $course_tool_category contains the category of tools to
  362. * display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform", "toolplugin"
  363. * @return array
  364. */
  365. public static function get_tools_category($course_tool_category)
  366. {
  367. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  368. $is_platform_admin = api_is_platform_admin();
  369. $all_tools_list = array();
  370. // Condition for the session
  371. $session_id = api_get_session_id();
  372. $course_id = api_get_course_int_id();
  373. $condition_session = api_get_session_condition($session_id, true, true);
  374. $studentView = isset($_SESSION['studentview']) ? $_SESSION['studentview'] : null;
  375. switch ($course_tool_category) {
  376. case TOOL_STUDENT_VIEW:
  377. $condition_display_tools = ' WHERE visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") ';
  378. if ((api_is_coach() || api_is_course_tutor()) && $studentView != 'studentview') {
  379. $condition_display_tools = ' WHERE (visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") OR (name = "'.TOOL_TRACKING.'") ) ';
  380. }
  381. $sql = "SELECT * FROM $course_tool_table $condition_display_tools AND c_id = $course_id $condition_session ORDER BY id";
  382. $result = Database::query($sql);
  383. $col_link ="##003399";
  384. break;
  385. case TOOL_AUTHORING:
  386. $sql = "SELECT * FROM $course_tool_table WHERE category = 'authoring' AND c_id = $course_id $condition_session ORDER BY id";
  387. $result = Database::query($sql);
  388. $col_link ="##003399";
  389. break;
  390. case TOOL_INTERACTION:
  391. $sql = "SELECT * FROM $course_tool_table WHERE category = 'interaction' AND c_id = $course_id $condition_session ORDER BY id";
  392. $result = Database::query($sql);
  393. $col_link ="##003399";
  394. break;
  395. case TOOL_ADMIN_VISIBLE:
  396. $sql = "SELECT * FROM $course_tool_table WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session ORDER BY id";
  397. $result = Database::query($sql);
  398. $col_link ="##003399";
  399. break;
  400. case TOOL_ADMIN_PLATFORM:
  401. $sql = "SELECT * FROM $course_tool_table WHERE category = 'admin' AND c_id = $course_id $condition_session ORDER BY id";
  402. $result = Database::query($sql);
  403. $col_link ="##003399";
  404. break;
  405. case TOOL_COURSE_PLUGIN:
  406. //Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id
  407. // but plugins are not present in the tool table, only globally and inside the course_settings table once configured
  408. $sql = "SELECT * FROM $course_tool_table WHERE category = 'plugin' AND c_id = $course_id $condition_session ORDER BY id";
  409. $result = Database::query($sql);
  410. break;
  411. }
  412. //Get the list of hidden tools - this might imply performance slowdowns
  413. // if the course homepage is loaded many times, so the list of hidden
  414. // tools might benefit from a shared memory storage later on
  415. $list = api_get_settings('Tools', 'list', api_get_current_access_url_id());
  416. $hide_list = array();
  417. $check = false;
  418. foreach ($list as $line) {
  419. // Admin can see all tools even if the course_hide_tools configuration is set
  420. if ($is_platform_admin) {
  421. continue;
  422. }
  423. if ($line['variable'] == 'course_hide_tools' and $line['selected_value'] == 'true') {
  424. $hide_list[] = $line['subkey'];
  425. $check = true;
  426. }
  427. }
  428. while ($temp_row = Database::fetch_assoc($result)) {
  429. if ($check) {
  430. if (!in_array($temp_row['name'], $hide_list)) {
  431. $all_tools_list[$temp_row['name']] = $temp_row;
  432. }
  433. } else {
  434. $all_tools_list[$temp_row['name']] = $temp_row;
  435. }
  436. }
  437. // Grabbing all the links that have the property on_homepage set to 1
  438. $course_link_table = Database::get_course_table(TABLE_LINK);
  439. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  440. switch ($course_tool_category) {
  441. case TOOL_AUTHORING:
  442. $sql_links = "SELECT tl.*, tip.visibility, tl.id link_id
  443. FROM $course_link_table tl
  444. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  445. WHERE tl.c_id = $course_id AND
  446. tip.c_id = $course_id AND
  447. tl.on_homepage='1' $condition_session";
  448. break;
  449. case TOOL_INTERACTION:
  450. $sql_links = null;
  451. /*
  452. $sql_links = "SELECT tl.*, tip.visibility
  453. FROM $course_link_table tl
  454. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  455. WHERE tl.on_homepage='1' ";
  456. */
  457. break;
  458. case TOOL_STUDENT_VIEW:
  459. $sql_links = "SELECT tl.*, tip.visibility, tl.id link_id
  460. FROM $course_link_table tl
  461. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  462. WHERE tl.c_id = $course_id AND
  463. tip.c_id = $course_id AND
  464. tl.on_homepage ='1' $condition_session";
  465. break;
  466. case TOOL_ADMIN:
  467. $sql_links = "SELECT tl.*, tip.visibility, tl.id link_id
  468. FROM $course_link_table tl
  469. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  470. WHERE tl.c_id = $course_id AND
  471. tip.c_id = $course_id AND
  472. tl.on_homepage='1' $condition_session";
  473. break;
  474. default:
  475. $sql_links = null;
  476. break;
  477. }
  478. // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
  479. if ($sql_links != null) {
  480. $result_links = Database::query($sql_links);
  481. if (Database::num_rows($result_links) > 0) {
  482. while ($links_row = Database::fetch_array($result_links, 'ASSOC')) {
  483. $properties = array();
  484. $properties['name'] = $links_row['title'];
  485. $properties['session_id'] = $links_row['session_id'];
  486. $properties['link'] = $links_row['url'];
  487. $properties['visibility'] = $links_row['visibility'];
  488. $properties['image'] = ($links_row['visibility'] == '0') ? 'file_html.gif' : 'file_html.gif';
  489. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  490. $properties['target'] = $links_row['target'];
  491. $properties['link_id'] = !empty($links_row['link_id']) ? $links_row['link_id'] : null;
  492. $tmp_all_tools_list[] = $properties;
  493. }
  494. }
  495. }
  496. if (isset($tmp_all_tools_list)) {
  497. foreach ($tmp_all_tools_list as $tool) {
  498. if ($tool['image'] == 'blog.gif') {
  499. // Init
  500. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  501. // Get blog id
  502. $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
  503. // Get blog members
  504. if ($is_platform_admin) {
  505. $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user WHERE blog_id =" . $blog_id;
  506. } else {
  507. $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user WHERE blog_id =" . $blog_id . " AND user_id = " . api_get_user_id();
  508. }
  509. $result_blogs = Database::query($sql_blogs);
  510. if (Database::num_rows($result_blogs) > 0) {
  511. $all_tools_list[] = $tool;
  512. }
  513. } else {
  514. $all_tools_list[] = $tool;
  515. }
  516. }
  517. }
  518. return $all_tools_list;
  519. }
  520. /**
  521. * Displays the tools of a certain category.
  522. * @param Symfony\Component\Routing\RouterInterface $urlGenerator
  523. * @param array List of tools as returned by get_tools_category()
  524. * @param bool rows
  525. * @return string
  526. */
  527. public static function show_tools_category($urlGenerator, $toolList, $rows = false)
  528. {
  529. $rowDiv = '<div class="row">';
  530. $theme = api_get_setting('homepage_view');
  531. if ($theme == 'vertical_activity') {
  532. //ordering by get_lang name
  533. $order_tool_list = array();
  534. if (is_array($toolList) && count($toolList)>0) {
  535. foreach ($toolList as $key => $new_tool) {
  536. $tool_name = self::translate_tool_name($new_tool);
  537. $order_tool_list [$key]= $tool_name;
  538. }
  539. natsort($order_tool_list);
  540. $my_temp_tool_array = array();
  541. foreach ($order_tool_list as $key => $new_tool) {
  542. $my_temp_tool_array[] = $toolList[$key];
  543. }
  544. $toolList = $my_temp_tool_array;
  545. } else {
  546. $toolList = array();
  547. }
  548. }
  549. $courseInfo = api_get_course_info();
  550. $web_code_path = api_get_path(WEB_CODE_PATH);
  551. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  552. $is_platform_admin = api_is_platform_admin();
  553. $session_id = api_get_session_id();
  554. $items = array();
  555. $app_plugin = new AppPlugin();
  556. if (isset($toolList)) {
  557. $lnk = '';
  558. foreach ($toolList as & $tool) {
  559. $item = array();
  560. $tool['admin'] = isset($tool['admin']) ? $tool['admin'] : null;
  561. $tool['id'] = isset($tool['id']) ? $tool['id'] : null;
  562. $tool['target'] = isset($tool['target']) ? $tool['target'] : null;
  563. if (isset($tool['link_id'])) {
  564. $tool['original_link'] = api_get_path(WEB_CODE_PATH).'link/link_goto.php?link_id='.$tool['link_id'].'&'.api_get_cidreq();
  565. $tool['link'] = $tool['original_link'];
  566. } else {
  567. $tool['original_link'] = $tool['link'];
  568. }
  569. // Re-writing URL for new tools
  570. $newTools = array(TOOL_CURRICULUM);
  571. $toolName = isset($tool['name']) ? $tool['name'] : null;
  572. if (in_array($toolName, $newTools)) {
  573. $tool['link'] = $courseInfo['course_web_public_url'].$tool['name'].'/';
  574. }
  575. if ($tool['image'] == 'scormbuilder.gif') {
  576. // Check if the published learnpath is visible for student
  577. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  578. if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id())) {
  579. continue;
  580. }
  581. }
  582. if ($session_id != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
  583. continue;
  584. }
  585. if ($tool['name'] == 'course_description') {
  586. $tool['link'] = 'course_description/index.php';
  587. }
  588. // This part displays the links to hide or remove a tool.
  589. // These links are only visible by the course manager.
  590. unset($lnk);
  591. $item['extra'] = null;
  592. if ($is_allowed_to_edit && !api_is_coach()) {
  593. if (empty($session_id)) {
  594. if ($tool['visibility'] == '1' && $tool['admin'] != '1') {
  595. $link['name'] = Display::return_icon(
  596. 'visible.gif',
  597. get_lang('Deactivate'),
  598. array('id' => 'linktool_'.$tool['id']),
  599. ICON_SIZE_MEDIUM,
  600. false
  601. );
  602. if (!empty($tool['id'])) {
  603. $link['cmd'] = $urlGenerator->generate(
  604. 'course_home.controller:hideIconAction',
  605. array('course' => api_get_course_id(), 'iconId' => $tool['id'])
  606. );
  607. }
  608. $lnk[] = $link;
  609. }
  610. if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
  611. $link['name'] = Display::return_icon('invisible.gif', get_lang('Activate'), array('id' => 'linktool_'.$tool['id']), ICON_SIZE_MEDIUM, false);
  612. if (!empty($tool['id'])) {
  613. $link['cmd'] = $urlGenerator->generate(
  614. 'course_home.controller:showIconAction',
  615. array('course' => api_get_course_id(), 'iconId' => $tool['id'])
  616. );
  617. }
  618. $lnk[] = $link;
  619. }
  620. }
  621. if (!empty($tool['adminlink'])) {
  622. $item['extra'] = '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  623. }
  624. }
  625. // Both checks are necessary as is_platform_admin doesn't take student view into account
  626. if ($is_platform_admin && $is_allowed_to_edit) {
  627. if ($tool['admin'] != '1') {
  628. $link['cmd'] = 'hide=yes';
  629. }
  630. }
  631. $item['visibility'] = null;
  632. if (isset($lnk) && is_array($lnk)) {
  633. foreach ($lnk as $this_link) {
  634. if (empty($tool['adminlink'])) {
  635. $item['visibility'] .= '<a class="make_visible_and_invisible" href="'.$this_link['cmd'].'">'.$this_link['name'].'</a>';
  636. }
  637. }
  638. } else {
  639. $item['visibility'] .= null;
  640. }
  641. // NOTE : Table contains only the image file name, not full path
  642. if (stripos($tool['link'], 'http://') === false &&
  643. stripos($tool['link'], 'https://') === false &&
  644. stripos($tool['link'], 'ftp://') === false
  645. ) {
  646. $tool['link'] = $web_code_path.$tool['link'];
  647. }
  648. if (!empty($tool['custom_icon'])) {
  649. $tool['image'] = self::getCustomIconPath($courseInfo).$tool['custom_icon'];
  650. }
  651. if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
  652. $class = 'invisible';
  653. $info = pathinfo($tool['image']);
  654. $dirName = null;
  655. if ($info['dirname'] != '.') {
  656. $dirName = $info['dirname'].'/';
  657. }
  658. $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
  659. $tool['image'] = $dirName.$basename.'_na.'.$info['extension'];
  660. } else {
  661. $class = '';
  662. }
  663. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
  664. // If it's a link, we don't add the cidReq
  665. if ($tool['image'] == 'file_html.gif' || $tool['image'] == 'file_html_na.gif') {
  666. $tool['link'] = $tool['link'].$qm_or_amp;
  667. } else {
  668. $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
  669. }
  670. $tool_link_params = array();
  671. //@todo this visio stuff should be removed
  672. if (strpos($tool['name'], 'visio_') !== false) {
  673. $tool_link_params = array(
  674. 'id' => 'tooldesc_'.$tool["id"],
  675. 'href' => '"javascript: void(0);"',
  676. 'class' => $class,
  677. 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_visio'.$_SESSION['_cid'].'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')',
  678. 'target' => $tool['target']
  679. );
  680. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  681. $tool_link_params = array(
  682. 'id' => 'tooldesc_'.$tool["id"],
  683. 'class' => $class,
  684. 'href' => 'javascript: void(0);',
  685. 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')',
  686. 'target' => $tool['target']
  687. );
  688. } else {
  689. if (count(explode('type=classroom',$tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) {
  690. $tool_link_params = array(
  691. 'id' => 'tooldesc_'.$tool["id"],
  692. 'href' => $tool['link'],
  693. 'class' => $class,
  694. 'target' => '_blank'
  695. );
  696. } else {
  697. $tool_link_params = array(
  698. 'id' => 'tooldesc_'.$tool["id"],
  699. 'href' => $tool['link'],
  700. 'class' => $class,
  701. 'target' => $tool['target']
  702. );
  703. }
  704. }
  705. $tool_name = self::translate_tool_name($tool);
  706. $toolTip = $tool_name;
  707. if (!empty($tool['description'])) {
  708. $toolTip = $tool['description'];
  709. }
  710. $tool_link_params['data-original-title'] = $toolTip;
  711. $tool_link_params['data-toggle'] = 'tooltip';
  712. //$tool_link_params['title'] = $toolTip;
  713. // Including Courses Plugins
  714. // Creating title and the link
  715. if (isset($tool['category']) && $tool['category'] == 'plugin') {
  716. $plugin_info = $app_plugin->get_plugin_info($tool['name']);
  717. if (isset($plugin_info) && isset($plugin_info['title'])) {
  718. $tool_name = $plugin_info['title'];
  719. }
  720. $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH).$tool['original_link'].'?'.api_get_cidreq();
  721. }
  722. if (!empty($tool['custom_icon'])) {
  723. //self::getCustomIconPath($courseInfo)
  724. $icon = Display::img(
  725. $tool['image'],
  726. null,
  727. array('class' => 'tool-icon', 'id' => 'toolimage_'.$tool['id'])
  728. );
  729. } else {
  730. $image = (substr($tool['image'], 0, strpos($tool['image'], '.'))).'.png';
  731. $icon = Display::return_icon(
  732. $image,
  733. null,
  734. array('class' => 'tool-icon', 'id' => 'toolimage_'.$tool['id']),
  735. ICON_SIZE_BIG,
  736. false
  737. );
  738. }
  739. $userInfo = api_get_user_info();
  740. $userStatus = isset($userInfo['status']) ? $userInfo['status'] : null;
  741. // Validation when belongs to a session
  742. $session_img = api_get_session_image($tool['session_id'], $userStatus);
  743. $item['url_params'] = $tool_link_params;
  744. $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params);
  745. $item['tool'] = $tool;
  746. $item['name'] = $tool_name;
  747. $tool_link_params['id'] = 'is'.$tool_link_params['id'];
  748. $item['link'] = Display::url($tool_name.$session_img, $tool_link_params['href'], $tool_link_params);
  749. $items[] = $item;
  750. } // end of foreach
  751. }
  752. $i = 0;
  753. $html = '';
  754. $counter = 0;
  755. if (!empty($items)) {
  756. foreach ($items as $item) {
  757. switch ($theme) {
  758. case 'activity_big':
  759. $data = '';
  760. if ($counter == 0) {
  761. $html .= $rowDiv;
  762. }
  763. $html .= '<div class="col-xs-4 col-md-4 course-tool">';
  764. $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png';
  765. if (!empty($item['tool']['custom_icon'])) {
  766. $original_image = Display::img(
  767. $item['tool']['image'],
  768. null,
  769. array('id'=>'toolimage_'.$item['tool']['id'])
  770. );
  771. } else {
  772. $original_image = Display::return_icon(
  773. $image,
  774. null,
  775. array('id'=>'toolimage_'.$item['tool']['id']),
  776. ICON_SIZE_BIG,
  777. false
  778. );
  779. }
  780. switch ($image) {
  781. case 'scormbuilder.png':
  782. if (api_is_allowed_to_edit(null, true)) {
  783. $item['url_params']['href'] .= '&isStudentView=true';
  784. }
  785. $image = $original_image;
  786. $lp_id = self::get_published_lp_id_from_link($item['link']);
  787. if ($lp_id) {
  788. $lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id());
  789. $path = $lp->get_preview_image_path(64);
  790. if ($path) {
  791. $image = '<img src="'.$path.'">';
  792. }
  793. }
  794. break;
  795. default:
  796. $image = $original_image;
  797. }
  798. $data .= Display::url($image, $item['url_params']['href'], $item['url_params']);
  799. $html .= Display::div($data, array('class'=>'big_icon')); //box-image reflection
  800. $html .= Display::div('<h4>'.$item['visibility'].$item['extra'].$item['link'].'</h4>', array('class'=>'content'));
  801. $html .= '</div>';
  802. if ($counter == 2) {
  803. $html .= '</div>';
  804. $counter = -1;
  805. }
  806. $counter++;
  807. break;
  808. case 'activity':
  809. if ($counter == 0) {
  810. $html .= $rowDiv;
  811. }
  812. $html .= '<div class="col-md-6 course-tool">';
  813. $content = $item['extra'];
  814. $content .= $item['visibility'];
  815. $content .= $item['icon'];
  816. $content .= $item['link'];
  817. $html .= Display::div($content, array('class'=>'activity_content'));
  818. $html .= '</div>';
  819. if ($counter == 1) {
  820. $html .= '</div>';
  821. $counter = -1;
  822. }
  823. $counter++;
  824. break;
  825. case 'vertical_activity':
  826. if ($i == 0) {
  827. $html .= '<ul>';
  828. }
  829. $html .= '<li class="course-tool">';
  830. $html .= $item['extra'];
  831. $html .= $item['visibility'];
  832. $html .= $item['icon'];
  833. $html .= $item['link'];
  834. $html .= '</li>';
  835. if ($i == count($items) -1) {
  836. $html .= '</ul>';
  837. }
  838. break;
  839. }
  840. $i++;
  841. }
  842. }
  843. return array(
  844. 'content' => $html,
  845. 'tool_list' => $items
  846. );
  847. }
  848. /**
  849. * Shows the general data for a particular meeting
  850. *
  851. * @param id session id
  852. * @return string session data
  853. */
  854. public static function show_session_data($id_session)
  855. {
  856. if ($id_session != strval(intval($id_session))) {
  857. return '';
  858. } else {
  859. $id_session = intval($id_session);
  860. }
  861. $session_info = api_get_session_info($id_session);
  862. $session_category = SessionManager::get_session_category($session_info['session_category_id']);
  863. $session_category_name = null;
  864. if (!empty($session_category)) {
  865. $session_category_name = $session_category['name'];
  866. }
  867. $user_info = api_get_user_info($session_info['id_coach']);
  868. $general_coach = null;
  869. if (!empty($user_info)) {
  870. $general_coach = $user_info['complete_name'].' ('.$user_info['username'].')';
  871. }
  872. $msg_date = SessionManager::parse_session_dates($session_info);
  873. $output = '';
  874. if (!empty($session_category)) {
  875. $output .= '<tr><td>'. get_lang('SessionCategory').': '.'<b>'.$session_category_name.'</b></td></tr>';
  876. }
  877. $output .= '<tr>
  878. <td style="width:50%">'. get_lang('SessionName') . ': ' . '<b>' . $session_info['name'] .'</b></td>
  879. <td>'. get_lang('GeneralCoach') . ': ' . '<b>' .$general_coach.'</b></td></tr>';
  880. $output .= '<tr><td>'. get_lang('SessionIdentifier') . ': '. Display::return_icon('star.png', ' ', array('align' => 'absmiddle')) .'</td>
  881. <td>'. get_lang('Date') . ': ' . '<b>' . $msg_date .'</b></td></tr>';
  882. return $output;
  883. }
  884. /**
  885. * Retrieves the name-field within a tool-record and translates it on necessity.
  886. * @param array $tool The input record.
  887. * @return string Returns the name of the corresponding tool.
  888. */
  889. public static function translate_tool_name(& $tool)
  890. {
  891. static $already_translated_icons = array(
  892. 'file_html.gif',
  893. 'file_html_na.gif',
  894. 'scormbuilder.gif',
  895. 'scormbuilder_na.gif',
  896. 'blog.gif',
  897. 'blog_na.gif',
  898. 'external.gif',
  899. 'external_na.gif'
  900. );
  901. if (in_array($tool['image'], $already_translated_icons)) {
  902. $tool_name = Security::remove_XSS(stripslashes($tool['name']));
  903. } else {
  904. /*
  905. // The following (slow) code was made in the past for transitional purposes.
  906. // We assume that the new language variables Tool* have been already translated.
  907. $variable = 'Tool'.api_underscore_to_camel_case($tool['name']); // The newly opened language variables.
  908. $variable_old = ucfirst($tool['name']); // The old language variables as a second chance.
  909. if (api_is_translated($variable)) {
  910. $tool_name = get_lang($variable);
  911. } elseif (api_is_translated($variable_old)) {
  912. $tool_name = get_lang($variable_old);
  913. } else {
  914. $tool_name = get_lang($variable);
  915. }
  916. */
  917. $tool_name = get_lang('Tool'.Text::api_underscore_to_camel_case($tool['name']));
  918. }
  919. return $tool_name;
  920. }
  921. /**
  922. * Get published learning path id from link inside course home
  923. * @param string Link to published lp
  924. * @return int Learning path id
  925. */
  926. public static function get_published_lp_id_from_link($published_lp_link) {
  927. $lp_id = 0;
  928. $param_lp_id = strstr($published_lp_link, 'lp_id=');
  929. if (!empty($param_lp_id)) {
  930. $a_param_lp_id = explode('=',$param_lp_id);
  931. if (isset($a_param_lp_id[1])) {
  932. $lp_id = intval($a_param_lp_id[1]);
  933. }
  934. }
  935. return $lp_id;
  936. }
  937. static function get_navigation_items($include_admin_tools = false) {
  938. $navigation_items = array();
  939. $course_id = api_get_course_int_id();
  940. if (!empty($course_id)) {
  941. $course_tools_table = Database :: get_course_table(TABLE_TOOL_LIST);
  942. /* Link to the Course homepage */
  943. $navigation_items['home']['image'] = 'home.gif';
  944. $navigation_items['home']['link'] = api_get_path(REL_COURSE_PATH).Security::remove_XSS($_SESSION['_course']['path']).'/index.php';
  945. $navigation_items['home']['name'] = get_lang('CourseHomepageLink');
  946. $sql_menu_query = "SELECT * FROM $course_tools_table WHERE c_id = $course_id AND visibility='1' and admin='0' ORDER BY id ASC";
  947. $sql_result = Database::query($sql_menu_query);
  948. while ($row = Database::fetch_array($sql_result)) {
  949. $navigation_items[$row['id']] = $row;
  950. if (stripos($row['link'], 'http://') === false && stripos($row['link'], 'https://') === false) {
  951. $navigation_items[$row['id']]['link'] = api_get_path(REL_CODE_PATH).$row['link'];
  952. $navigation_items[$row['id']]['name'] = CourseHome::translate_tool_name($row);
  953. }
  954. }
  955. /* Admin (edit rights) only links
  956. - Course settings (course admin only)
  957. - Course rights (roles & rights overview) */
  958. if ($include_admin_tools) {
  959. $course_settings_sql = "SELECT name,image FROM $course_tools_table
  960. WHERE c_id = $course_id AND link='course_info/infocours.php'";
  961. $sql_result = Database::query($course_settings_sql);
  962. $course_setting_info = Database::fetch_array($sql_result);
  963. $course_setting_visual_name = CourseHome::translate_tool_name($course_setting_info);
  964. if (api_get_session_id() == 0) {
  965. // course settings item
  966. $navigation_items['course_settings']['image'] = $course_setting_info['image'];
  967. $navigation_items['course_settings']['link'] = api_get_path(REL_CODE_PATH).'course_info/infocours.php';
  968. $navigation_items['course_settings']['name'] = $course_setting_visual_name;
  969. }
  970. }
  971. }
  972. foreach ($navigation_items as $key => $navigation_item) {
  973. if (strstr($navigation_item['link'], '?')) {
  974. //link already contains a parameter, add course id parameter with &
  975. $parameter_separator = '&amp;';
  976. } else {
  977. //link doesn't contain a parameter yet, add course id parameter with ?
  978. $parameter_separator = '?';
  979. }
  980. //$navigation_items[$key]['link'] .= $parameter_separator.api_get_cidreq();
  981. $navigation_items[$key]['link'] .= $parameter_separator.'cidReq='.api_get_course_id().'&gidReq=0&id_session='.api_get_session_id();
  982. }
  983. return $navigation_items;
  984. }
  985. /**
  986. * Show a navigation menu
  987. */
  988. static function show_navigation_menu() {
  989. $navigation_items = self::get_navigation_items(true);
  990. $course_id = api_get_course_id();
  991. $html = '<div id="toolnav"> <!-- start of #toolnav -->';
  992. if (api_get_setting('show_navigation_menu') == 'icons') {
  993. $html .= self::show_navigation_tool_shortcuts($orientation = SHORTCUTS_VERTICAL);
  994. } else {
  995. $html .= '<div id="toolnavbox">';
  996. $html .= '<div id="toolnavlist"><dl>';
  997. foreach ($navigation_items as $key => $navigation_item) {
  998. //students can't see the course settings option
  999. if (!api_is_allowed_to_edit() && $key == 'course_settings') {
  1000. continue;
  1001. }
  1002. $html .= '<dd>';
  1003. $url_item = parse_url($navigation_item['link']);
  1004. $url_current = parse_url($_SERVER['REQUEST_URI']);
  1005. if (strpos($navigation_item['link'], 'chat') !== false && api_get_course_setting('allow_open_chat_window', $course_id)) {
  1006. $html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $navigation_item['target'] . '"';
  1007. } else {
  1008. $html .= '<a href="'.$navigation_item['link'].'" target="_top" ';
  1009. }
  1010. if (stristr($url_item['path'], $url_current['path'])) {
  1011. if (!isset($_GET['learnpath_id']) || strpos($url_item['query'],'learnpath_id='.$_GET['learnpath_id']) === 0) {
  1012. $html .= ' id="here"';
  1013. }
  1014. }
  1015. $html .= ' title="'.$navigation_item['name'].'">';
  1016. if (api_get_setting('show_navigation_menu') != 'text') {
  1017. $html .= '<div align="left"><img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/></div>';
  1018. }
  1019. if (api_get_setting('show_navigation_menu') != 'icons') {
  1020. $html .= $navigation_item['name'];
  1021. }
  1022. $html .= '</a>';
  1023. $html .= '</dd>';
  1024. }
  1025. $html .= '</dl></div></div>';
  1026. }
  1027. $html .= '</div><!-- end "#toolnav" -->';
  1028. return $html;
  1029. }
  1030. /**
  1031. * Show a toolbar with shortcuts to the course tool
  1032. */
  1033. static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL)
  1034. {
  1035. $navigation_items = self::get_navigation_items(false);
  1036. $html = '';
  1037. if (!empty($navigation_items)) {
  1038. if ($orientation == SHORTCUTS_HORIZONTAL)
  1039. $style_id = "toolshortcuts_horizontal";
  1040. else {
  1041. $style_id = "toolshortcuts_vertical";
  1042. }
  1043. $html .= '<div id="'.$style_id.'">';
  1044. foreach ($navigation_items as $navigation_item) {
  1045. if (strpos($navigation_item['link'],'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  1046. $html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $navigation_item['target'] . '"';
  1047. } else {
  1048. $html .= '<a href="'.$navigation_item['link'].'"';
  1049. }
  1050. if (strpos(api_get_self(), $navigation_item['link']) !== false) {
  1051. $html .= ' id="here"';
  1052. }
  1053. $html .= ' target="_top" title="'.$navigation_item['name'].'">';
  1054. $html .= '<img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/>';
  1055. $html .= '</a> ';
  1056. if ($orientation == SHORTCUTS_VERTICAL) {
  1057. $html .= '<br />';
  1058. }
  1059. }
  1060. $html .= '</div>';
  1061. }
  1062. return $html;
  1063. }
  1064. /**
  1065. * @param array $courseInfo
  1066. * @return string
  1067. */
  1068. public static function getCustomIconPath($courseInfo)
  1069. {
  1070. return api_get_path(WEB_DATA_COURSE_PATH).$courseInfo['directory'].'/upload/course_home_icons/';
  1071. }
  1072. /**
  1073. * @param string $text
  1074. * @param array $toolList
  1075. * @return string
  1076. */
  1077. public static function replaceTextWithToolUrls($text, $toolList)
  1078. {
  1079. if (empty($toolList)) {
  1080. return $text;
  1081. }
  1082. foreach ($toolList as $tool) {
  1083. if (!isset($tool['icon'])) {
  1084. continue;
  1085. }
  1086. $toolName = $tool['tool']['name'];
  1087. $search = array("{{ ".$toolName." }}", "{{".$toolName."}}", "((".$toolName."))", "(( ".$toolName." ))");
  1088. $text = str_replace($search, $tool['icon'], $text);
  1089. }
  1090. // Cleaning tags that are not used.
  1091. $tools = self::availableTools();
  1092. foreach ($tools as $toolName) {
  1093. $search = array("{{ ".$toolName." }}", "{{".$toolName."}}", "((".$toolName."))", "(( ".$toolName." ))");
  1094. $text = str_replace($search, null, $text);
  1095. }
  1096. return $text;
  1097. }
  1098. /**
  1099. * Available tools
  1100. * @return array
  1101. */
  1102. public static function availableTools()
  1103. {
  1104. return array(
  1105. 'course_description',
  1106. 'quiz',
  1107. 'announcement',
  1108. 'forum',
  1109. 'dropbox',
  1110. 'user',
  1111. 'group',
  1112. 'chat',
  1113. 'student_publication',
  1114. 'survey',
  1115. 'wiki',
  1116. 'gradebook',
  1117. 'glossary',
  1118. 'notebook',
  1119. 'attendance',
  1120. 'course_progress',
  1121. 'curriculum',
  1122. 'blog_management',
  1123. 'tracking',
  1124. 'course_setting',
  1125. 'course_maintenance'
  1126. );
  1127. }
  1128. }