course_home.lib.php 55 KB

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