course_home.lib.php 49 KB

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