course_home.lib.php 56 KB

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