course_home.lib.php 55 KB

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