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