course_home.lib.php 50 KB

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