course_home.lib.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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_module, t.column_module FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  22. $condition_display_tools ORDER BY t.row_module, t.column_module";
  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_module, t.column_module 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_module, t.column_module";
  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. public static function show_tool_2column($course_tool_category) {
  188. $html = '';
  189. $web_code_path = api_get_path(WEB_CODE_PATH);
  190. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  191. $course_id = api_get_course_int_id();
  192. switch ($course_tool_category) {
  193. case TOOL_PUBLIC:
  194. $condition_display_tools = ' WHERE c_id = '.$course_id.' AND visibility = 1 ';
  195. if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
  196. $condition_display_tools = ' WHERE c_id = '.$course_id.' AND (visibility = 1 OR (visibility = 0 AND name = "'.TOOL_TRACKING.'")) ';
  197. }
  198. $result = Database::query("SELECT * FROM $course_tool_table $condition_display_tools ORDER BY id");
  199. $col_link ="##003399";
  200. break;
  201. case TOOL_PUBLIC_BUT_HIDDEN:
  202. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility=0 AND admin=0 ORDER BY id");
  203. $col_link ="##808080";
  204. break;
  205. case TOOL_COURSE_ADMIN:
  206. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND admin=1 AND visibility != 2 ORDER BY id");
  207. $col_link ="##003399";
  208. break;
  209. case TOOL_PLATFORM_ADMIN:
  210. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility = 2 ORDER BY id");
  211. $col_link ="##003399";
  212. }
  213. $i = 0;
  214. // Grabbing all the tools from $course_tool_table
  215. while ($temp_row = Database::fetch_array($result)) {
  216. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN && $temp_row['image'] != 'scormbuilder.gif') {
  217. $temp_row['image'] = str_replace('.gif', '_na.gif', $temp_row['image']);
  218. }
  219. $all_tools_list[] = $temp_row;
  220. }
  221. // Grabbing all the links that have the property on_homepage set to 1
  222. $course_link_table = Database::get_course_table(TABLE_LINK);
  223. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  224. switch ($course_tool_category) {
  225. case TOOL_PUBLIC:
  226. $sql_links="SELECT tl.*, tip.visibility
  227. FROM $course_link_table tl
  228. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tl.c_id = tip.c_id AND tl.c_id = $course_id AND tip.ref=tl.id
  229. WHERE tl.on_homepage='1' AND tip.visibility = 1";
  230. break;
  231. case TOOL_PUBLIC_BUT_HIDDEN:
  232. $sql_links="SELECT tl.*, tip.visibility
  233. FROM $course_link_table tl
  234. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tl.c_id = tip.c_id AND tl.c_id = $course_id AND tip.ref=tl.id
  235. WHERE tl.on_homepage='1' AND tip.visibility = 0";
  236. break;
  237. default:
  238. $sql_links = null;
  239. break;
  240. }
  241. if ($sql_links != null) {
  242. $properties = array();
  243. $result_links = Database::query($sql_links);
  244. while ($links_row = Database::fetch_array($result_links)) {
  245. unset($properties);
  246. $properties['name'] = $links_row['title'];
  247. $properties['link'] = $links_row['url'];
  248. $properties['visibility'] = $links_row['visibility'];
  249. $properties['image'] = $course_tool_category == TOOL_PUBLIC_BUT_HIDDEN ? 'external_na.gif' : 'external.gif';
  250. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  251. $all_tools_list[] = $properties;
  252. }
  253. }
  254. if (isset($all_tools_list)) {
  255. $lnk = array();
  256. foreach ($all_tools_list as & $tool) {
  257. if ($tool['image'] == 'scormbuilder.gif') {
  258. // display links to lp only for current session
  259. /*if (api_get_session_id() != $tool['session_id']) {
  260. continue;
  261. }*/
  262. // check if the published learnpath is visible for student
  263. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  264. if (!api_is_allowed_to_edit(null, true) && !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. // Grabbing all the links that have the property on_homepage set to 1
  430. $course_link_table = Database::get_course_table(TABLE_LINK);
  431. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  432. switch ($course_tool_category) {
  433. case TOOL_AUTHORING:
  434. $sql_links = "SELECT tl.*, tip.visibility
  435. FROM $course_link_table tl
  436. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  437. WHERE tl.c_id = $course_id AND
  438. tip.c_id = $course_id AND
  439. tl.on_homepage='1' $condition_session";
  440. break;
  441. case TOOL_INTERACTION:
  442. $sql_links = null;
  443. /*
  444. $sql_links = "SELECT tl.*, tip.visibility
  445. FROM $course_link_table tl
  446. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  447. WHERE tl.on_homepage='1' ";
  448. */
  449. break;
  450. case TOOL_STUDENT_VIEW:
  451. $sql_links = "SELECT tl.*, tip.visibility
  452. FROM $course_link_table tl
  453. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  454. WHERE tl.c_id = $course_id AND
  455. tip.c_id = $course_id AND
  456. tl.on_homepage ='1' $condition_session";
  457. break;
  458. case TOOL_ADMIN:
  459. $sql_links = "SELECT tl.*, tip.visibility
  460. FROM $course_link_table tl
  461. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  462. WHERE tl.c_id = $course_id AND
  463. tip.c_id = $course_id AND
  464. tl.on_homepage='1' $condition_session";
  465. break;
  466. default:
  467. $sql_links = null;
  468. break;
  469. }
  470. // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
  471. if ($sql_links != null) {
  472. $result_links = Database::query($sql_links);
  473. if (Database::num_rows($result_links) > 0) {
  474. while ($links_row = Database::fetch_array($result_links, 'ASSOC')) {
  475. $properties = array();
  476. $properties['name'] = $links_row['title'];
  477. $properties['session_id'] = $links_row['session_id'];
  478. $properties['link'] = $links_row['url'];
  479. $properties['visibility'] = $links_row['visibility'];
  480. $properties['image'] = ($links_row['visibility'] == '0') ? 'file_html.gif' : 'file_html.gif';
  481. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  482. $properties['target'] = $links_row['target'];
  483. $tmp_all_tools_list[] = $properties;
  484. }
  485. }
  486. }
  487. if (isset($tmp_all_tools_list)) {
  488. foreach ($tmp_all_tools_list as $tool) {
  489. if ($tool['image'] == 'blog.gif') {
  490. // Init
  491. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  492. // Get blog id
  493. $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
  494. // Get blog members
  495. if ($is_platform_admin) {
  496. $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user WHERE blog_id =" . $blog_id;
  497. } else {
  498. $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user WHERE blog_id =" . $blog_id . " AND user_id = " . api_get_user_id();
  499. }
  500. $result_blogs = Database::query($sql_blogs);
  501. if (Database::num_rows($result_blogs) > 0) {
  502. $all_tools_list[] = $tool;
  503. }
  504. } else {
  505. $all_tools_list[] = $tool;
  506. }
  507. }
  508. }
  509. return $all_tools_list;
  510. }
  511. /**
  512. * Displays the tools of a certain category.
  513. * @param array List of tools as returned by get_tools_category()
  514. * @param int rows
  515. * @return void
  516. */
  517. public static function show_tools_category($all_tools_list, $rows = false) {
  518. $rowDiv = '<div class="row-fluid">';
  519. $theme = api_get_setting('homepage_view');
  520. if ($theme == 'vertical_activity') {
  521. //ordering by get_lang name
  522. $order_tool_list = array();
  523. if (is_array($all_tools_list) && count($all_tools_list)>0) {
  524. foreach($all_tools_list as $key=>$new_tool) {
  525. $tool_name = self::translate_tool_name($new_tool);
  526. $order_tool_list [$key]= $tool_name;
  527. }
  528. natsort($order_tool_list);
  529. $my_temp_tool_array = array();
  530. foreach($order_tool_list as $key=>$new_tool) {
  531. $my_temp_tool_array[] = $all_tools_list[$key];
  532. }
  533. $all_tools_list = $my_temp_tool_array;
  534. } else {
  535. $all_tools_list = array();
  536. }
  537. }
  538. $web_code_path = api_get_path(WEB_CODE_PATH);
  539. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  540. $is_platform_admin = api_is_platform_admin();
  541. $session_id = api_get_session_id();
  542. $i = 0;
  543. $items = array();
  544. $app_plugin = new AppPlugin();
  545. if (isset($all_tools_list)) {
  546. $lnk = '';
  547. foreach ($all_tools_list as & $tool) {
  548. $item = array();
  549. $tool['original_link'] = $tool['link'];
  550. if ($tool['image'] == 'scormbuilder.gif') {
  551. // display links to lp only for current session
  552. /*if ($session_id != $tool['session_id']) {
  553. continue;
  554. }*/
  555. // check if the published learnpath is visible for student
  556. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  557. if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id,api_get_user_id())) {
  558. continue;
  559. }
  560. }
  561. if ($session_id != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
  562. continue;
  563. }
  564. // This part displays the links to hide or remove a tool.
  565. // These links are only visible by the course manager.
  566. unset($lnk);
  567. $item['extra'] = null;
  568. if ($is_allowed_to_edit && !api_is_coach()) {
  569. if (empty($session_id)) {
  570. if ($tool['visibility'] == '1' && $tool['admin'] != '1') {
  571. $link['name'] = Display::return_icon('visible.gif', get_lang('Deactivate'), array('id' => 'linktool_'.$tool['id']), ICON_SIZE_MEDIUM, false);
  572. $link['cmd'] = 'hide=yes';
  573. $lnk[] = $link;
  574. }
  575. if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
  576. $link['name'] = Display::return_icon('invisible.gif', get_lang('Activate'), array('id' => 'linktool_'.$tool['id']), ICON_SIZE_MEDIUM, false);
  577. $link['cmd'] = 'restore=yes';
  578. $lnk[] = $link;
  579. }
  580. }
  581. if (!empty($tool['adminlink'])) {
  582. $item['extra'] = '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  583. }
  584. }
  585. // Both checks are necessary as is_platform_admin doesn't take student view into account
  586. if ($is_platform_admin && $is_allowed_to_edit) {
  587. if ($tool['admin'] != '1') {
  588. $link['cmd'] = 'hide=yes';
  589. }
  590. }
  591. $item['visibility'] = null;
  592. if (isset($lnk) && is_array($lnk)) {
  593. foreach ($lnk as $this_link) {
  594. if (empty($tool['adminlink'])) {
  595. $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>';
  596. }
  597. }
  598. } else {
  599. $item['visibility'] .= '&nbsp;&nbsp;&nbsp;&nbsp;';
  600. }
  601. // NOTE : Table contains only the image file name, not full path
  602. if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) {
  603. $tool['link'] = $web_code_path.$tool['link'];
  604. }
  605. if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
  606. $class = 'invisible';
  607. $info = pathinfo($tool['image']);
  608. $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
  609. $tool['image'] = $basename.'_na.'.$info['extension'];
  610. } else {
  611. $class = '';
  612. }
  613. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
  614. // If it's a link, we don't add the cidReq
  615. if ($tool['image'] == 'file_html.gif' || $tool['image'] == 'file_html_na.gif') {
  616. $tool['link'] = $tool['link'].$qm_or_amp;
  617. } else {
  618. $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
  619. }
  620. $tool_link_params = array();
  621. //$tool['link'] = htmlspecialchars($tool['link']) ;
  622. //@todo this visio stuff should be removed
  623. if (strpos($tool['name'],'visio_') !== false) {
  624. $tool_link_params = array(
  625. '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(
  632. 'id' => 'tooldesc_'.$tool["id"],
  633. 'class' => $class,
  634. 'href' => 'javascript: void(0);',
  635. '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\')',
  636. 'target' => $tool['target']);
  637. } else {
  638. if (count(explode('type=classroom',$tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) {
  639. $tool_link_params = array(
  640. 'id' => 'tooldesc_'.$tool["id"],
  641. 'href' => $tool['link'],
  642. 'class' => $class,
  643. 'target' => '_blank');
  644. } else {
  645. $tool_link_params = array(
  646. 'id' => 'tooldesc_'.$tool["id"],
  647. 'href' => $tool['link'],
  648. 'class' => $class,
  649. 'target' => $tool['target']);
  650. }
  651. }
  652. $tool_name = self::translate_tool_name($tool);
  653. // Including Courses Plugins
  654. // Creating title and the link
  655. if (isset($tool['category']) && $tool['category'] == 'plugin') {
  656. $plugin_info = $app_plugin->get_plugin_info($tool['name']);
  657. if (isset($plugin_info) && isset($plugin_info['title'])) {
  658. $tool_name = $plugin_info['title'];
  659. }
  660. $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH).$tool['original_link'].'?'.api_get_cidreq();
  661. }
  662. $icon = Display::return_icon($tool['image'], $tool_name, array('class' => 'tool-icon', 'id' => 'toolimage_'.$tool['id']), ICON_SIZE_BIG, false);
  663. $userInfo = api_get_user_info();
  664. $userStatus = isset($userInfo['status']) ? $userInfo['status'] : null;
  665. // Validation when belongs to a session
  666. $session_img = api_get_session_image($tool['session_id'], $userStatus);
  667. $item['url_params'] = $tool_link_params;
  668. $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params);
  669. $item['tool'] = $tool;
  670. $item['name'] = $tool_name;
  671. $tool_link_params['id'] = 'is'.$tool_link_params['id'];
  672. $item['link'] = Display::url($tool_name.$session_img, $tool_link_params['href'], $tool_link_params);
  673. $items[] = $item;
  674. $i++;
  675. } // end of foreach
  676. }
  677. $i = 0;
  678. $html = '';
  679. $counter = 0;
  680. if (!empty($items)) {
  681. foreach ($items as $item) {
  682. switch ($theme) {
  683. case 'activity_big':
  684. $data = '';
  685. if ($counter == 0) {
  686. $html .= $rowDiv;
  687. }
  688. $html .= '<div class="span4 course-tool">';
  689. $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png';
  690. $original_image = Display::return_icon($image, $item['name'], array('id'=>'toolimage_'.$item['tool']['id']), ICON_SIZE_BIG, false);
  691. switch ($image) {
  692. case 'scormbuilder.png':
  693. if (api_is_allowed_to_edit(null, true)) {
  694. $item['url_params']['href'] .= '&isStudentView=true';
  695. }
  696. $image = $original_image;
  697. $lp_id = self::get_published_lp_id_from_link($item['link']);
  698. if ($lp_id) {
  699. $lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id());
  700. $path = $lp->get_preview_image_path(64);
  701. if ($path) {
  702. $image = '<img src="'.$path.'">';
  703. }
  704. }
  705. break;
  706. default:
  707. $image = $original_image;
  708. }
  709. $data .= Display::url($image , $item['url_params']['href'], $item['url_params']);
  710. $html .= Display::div($data, array('class'=>'big_icon')); //box-image reflection
  711. $html .= Display::div('<h4>'.$item['visibility'].$item['extra'].$item['link'].'</h4>', array('class'=>'content'));
  712. $html .= '</div>';
  713. if ($counter == 2) {
  714. $html .= '</div>';
  715. $counter = -1;
  716. }
  717. $counter++;
  718. break;
  719. case 'activity':
  720. if ($counter == 0) {
  721. $html .= $rowDiv;
  722. }
  723. $html .= '<div class="span6 course-tool">';
  724. $content = $item['extra'];
  725. $content .= $item['visibility'];
  726. $content .= $item['icon'];
  727. $content .= $item['link'];
  728. $html .= Display::div($content, array('class'=>'activity_content'));
  729. $html .= '</div>';
  730. if ($counter == 1) {
  731. $html .= '</div>';
  732. $counter = -1;
  733. }
  734. $counter++;
  735. break;
  736. case 'vertical_activity':
  737. if ($i == 0) {
  738. $html .= '<ul>';
  739. }
  740. $html .= '<li class="course-tool">';
  741. $html .= $item['extra'];
  742. $html .= $item['visibility'];
  743. $html .= $item['icon'];
  744. $html .= $item['link'];
  745. $html .= '</li>';
  746. if ($i == count($items) -1) {
  747. $html .= '</ul>';
  748. }
  749. break;
  750. }
  751. $i++;
  752. }
  753. }
  754. return $html;
  755. }
  756. /**
  757. * Shows the general data for a particular meeting
  758. *
  759. * @param id session id
  760. * @return string session data
  761. */
  762. public static function show_session_data($id_session) {
  763. if ($id_session != strval(intval($id_session))) {
  764. return '';
  765. } else {
  766. $id_session = intval($id_session);
  767. }
  768. $session_info = api_get_session_info($id_session);
  769. $session_category = SessionManager::get_session_category($session_info['session_category_id']);
  770. $session_category_name = null;
  771. if (!empty($session_category)) {
  772. $session_category_name = $session_category['name'];
  773. }
  774. $user_info = api_get_user_info($session_info['id_coach']);
  775. $general_coach = null;
  776. if (!empty($user_info)) {
  777. $general_coach = $user_info['complete_name'].' ('.$user_info['username'].')';
  778. }
  779. $msg_date = SessionManager::parse_session_dates($session_info);
  780. $output = '';
  781. if (!empty($session_category)) {
  782. $output .= '<tr><td>'. get_lang('SessionCategory') . ': ' . '<b>' . $session_category_name .'</b></td></tr>';
  783. }
  784. $output .= '<tr>
  785. <td style="width:50%">'. get_lang('SessionName') . ': ' . '<b>' . $session_info['name'] .'</b></td>
  786. <td>'. get_lang('GeneralCoach') . ': ' . '<b>' .$general_coach.'</b></td></tr>';
  787. $output .= '<tr><td>'. get_lang('SessionIdentifier') . ': '. Display::return_icon('star.png', ' ', array('align' => 'absmiddle')) .'</td>
  788. <td>'. get_lang('Date') . ': ' . '<b>' . $msg_date .'</b></td></tr>';
  789. return $output;
  790. }
  791. /**
  792. * Retrieves the name-field within a tool-record and translates it on necessity.
  793. * @param array $tool The input record.
  794. * @return string Returns the name of the corresponding tool.
  795. */
  796. public static function translate_tool_name(& $tool) {
  797. static $already_translated_icons = array(
  798. 'file_html.gif',
  799. 'file_html_na.gif',
  800. 'scormbuilder.gif',
  801. 'scormbuilder_na.gif',
  802. 'blog.gif',
  803. 'blog_na.gif',
  804. 'external.gif',
  805. 'external_na.gif'
  806. );
  807. if (in_array($tool['image'], $already_translated_icons)) {
  808. $tool_name = Security::remove_XSS(stripslashes($tool['name']));
  809. } else {
  810. /*
  811. // The following (slow) code was made in the past for transitional purposes.
  812. // We assume that the new language variables Tool* have been already translated.
  813. $variable = 'Tool'.api_underscore_to_camel_case($tool['name']); // The newly opened language variables.
  814. $variable_old = ucfirst($tool['name']); // The old language variables as a second chance.
  815. if (api_is_translated($variable)) {
  816. $tool_name = get_lang($variable);
  817. } elseif (api_is_translated($variable_old)) {
  818. $tool_name = get_lang($variable_old);
  819. } else {
  820. $tool_name = get_lang($variable);
  821. }
  822. */
  823. $tool_name = get_lang('Tool'.Text::api_underscore_to_camel_case($tool['name']));
  824. }
  825. return $tool_name;
  826. }
  827. /**
  828. * Get published learning path id from link inside course home
  829. * @param string Link to published lp
  830. * @return int Learning path id
  831. */
  832. public static function get_published_lp_id_from_link($published_lp_link) {
  833. $lp_id = 0;
  834. $param_lp_id = strstr($published_lp_link, 'lp_id=');
  835. if (!empty($param_lp_id)) {
  836. $a_param_lp_id = explode('=',$param_lp_id);
  837. if (isset($a_param_lp_id[1])) {
  838. $lp_id = intval($a_param_lp_id[1]);
  839. }
  840. }
  841. return $lp_id;
  842. }
  843. static function get_navigation_items($include_admin_tools = false) {
  844. $navigation_items = array();
  845. $course_id = api_get_course_int_id();
  846. if (!empty($course_id)) {
  847. $course_tools_table = Database :: get_course_table(TABLE_TOOL_LIST);
  848. /* Link to the Course homepage */
  849. $navigation_items['home']['image'] = 'home.gif';
  850. $navigation_items['home']['link'] = api_get_path(REL_COURSE_PATH).Security::remove_XSS($_SESSION['_course']['path']).'/index.php';
  851. $navigation_items['home']['name'] = get_lang('CourseHomepageLink');
  852. $sql_menu_query = "SELECT * FROM $course_tools_table WHERE c_id = $course_id AND visibility='1' and admin='0' ORDER BY id ASC";
  853. $sql_result = Database::query($sql_menu_query);
  854. while ($row = Database::fetch_array($sql_result)) {
  855. $navigation_items[$row['id']] = $row;
  856. if (stripos($row['link'], 'http://') === false && stripos($row['link'], 'https://') === false) {
  857. $navigation_items[$row['id']]['link'] = api_get_path(REL_CODE_PATH).$row['link'];
  858. $navigation_items[$row['id']]['name'] = CourseHome::translate_tool_name($row);
  859. }
  860. }
  861. /* Admin (edit rights) only links
  862. - Course settings (course admin only)
  863. - Course rights (roles & rights overview) */
  864. if ($include_admin_tools) {
  865. $course_settings_sql = "SELECT name,image FROM $course_tools_table
  866. WHERE c_id = $course_id AND link='course_info/infocours.php'";
  867. $sql_result = Database::query($course_settings_sql);
  868. $course_setting_info = Database::fetch_array($sql_result);
  869. $course_setting_visual_name = CourseHome::translate_tool_name($course_setting_info);
  870. if (api_get_session_id() == 0) {
  871. // course settings item
  872. $navigation_items['course_settings']['image'] = $course_setting_info['image'];
  873. $navigation_items['course_settings']['link'] = api_get_path(REL_CODE_PATH).'course_info/infocours.php';
  874. $navigation_items['course_settings']['name'] = $course_setting_visual_name;
  875. }
  876. }
  877. }
  878. foreach ($navigation_items as $key => $navigation_item) {
  879. if (strstr($navigation_item['link'], '?')) {
  880. //link already contains a parameter, add course id parameter with &
  881. $parameter_separator = '&amp;';
  882. } else {
  883. //link doesn't contain a parameter yet, add course id parameter with ?
  884. $parameter_separator = '?';
  885. }
  886. //$navigation_items[$key]['link'] .= $parameter_separator.api_get_cidreq();
  887. $navigation_items[$key]['link'] .= $parameter_separator.'cidReq='.api_get_course_id().'&gidReq=0&id_session='.api_get_session_id();
  888. }
  889. return $navigation_items;
  890. }
  891. /**
  892. * Show a navigation menu
  893. */
  894. static function show_navigation_menu() {
  895. $navigation_items = self::get_navigation_items(true);
  896. $course_id = api_get_course_id();
  897. $html = '<div id="toolnav"> <!-- start of #toolnav -->';
  898. if (api_get_setting('show_navigation_menu') == 'icons') {
  899. $html .= self::show_navigation_tool_shortcuts($orientation = SHORTCUTS_VERTICAL);
  900. } else {
  901. $html .= '<div id="toolnavbox">';
  902. $html .= '<div id="toolnavlist"><dl>';
  903. foreach ($navigation_items as $key => $navigation_item) {
  904. //students can't see the course settings option
  905. if (!api_is_allowed_to_edit() && $key == 'course_settings') {
  906. continue;
  907. }
  908. $html .= '<dd>';
  909. $url_item = parse_url($navigation_item['link']);
  910. $url_current = parse_url($_SERVER['REQUEST_URI']);
  911. if (strpos($navigation_item['link'], 'chat') !== false && api_get_course_setting('allow_open_chat_window', $course_id)) {
  912. $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'] . '"';
  913. } else {
  914. $html .= '<a href="'.$navigation_item['link'].'" target="_top" ';
  915. }
  916. if (stristr($url_item['path'], $url_current['path'])) {
  917. if (!isset($_GET['learnpath_id']) || strpos($url_item['query'],'learnpath_id='.$_GET['learnpath_id']) === 0) {
  918. $html .= ' id="here"';
  919. }
  920. }
  921. $html .= ' title="'.$navigation_item['name'].'">';
  922. if (api_get_setting('show_navigation_menu') != 'text') {
  923. $html .= '<div align="left"><img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/></div>';
  924. }
  925. if (api_get_setting('show_navigation_menu') != 'icons') {
  926. $html .= $navigation_item['name'];
  927. }
  928. $html .= '</a>';
  929. $html .= '</dd>';
  930. }
  931. $html .= '</dl></div></div>';
  932. }
  933. $html .= '</div><!-- end "#toolnav" -->';
  934. return $html;
  935. }
  936. /**
  937. * Show a toolbar with shortcuts to the course tool
  938. */
  939. static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL) {
  940. $navigation_items = self::get_navigation_items(false);
  941. $html = '';
  942. if (!empty($navigation_items)) {
  943. if ($orientation == SHORTCUTS_HORIZONTAL)
  944. $style_id = "toolshortcuts_horizontal";
  945. else {
  946. $style_id = "toolshortcuts_vertical";
  947. }
  948. $html .= '<div id="'.$style_id.'">';
  949. foreach ($navigation_items as $key => $navigation_item) {
  950. if (strpos($navigation_item['link'],'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  951. $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'] . '"';
  952. } else {
  953. $html .= '<a href="'.$navigation_item['link'].'"';
  954. }
  955. if (strpos(api_get_self(), $navigation_item['link']) !== false) {
  956. $html .= ' id="here"';
  957. }
  958. $html .= ' target="_top" title="'.$navigation_item['name'].'">';
  959. $html .= '<img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/>';
  960. $html .= '</a> ';
  961. if ($orientation == SHORTCUTS_VERTICAL) {
  962. $html .= '<br />';
  963. }
  964. }
  965. $html .= '</div>';
  966. }
  967. return $html;
  968. }
  969. }