course_home.lib.php 55 KB

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