course_home.lib.php 55 KB

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