course_home.lib.php 54 KB

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