course_home.lib.php 58 KB

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