course_home.lib.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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>'."\n"; // 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>'."\n"; // 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>'."\n";
  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>'."\n"; // 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>'."\n";// 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\">\n";
  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>\n";
  352. if ($i % 2) {
  353. echo "</tr>\n";
  354. }
  355. $i++;
  356. }
  357. }
  358. if ($i % 2) {
  359. echo "<td width=\"50%\">&nbsp;</td>\n", "</tr>\n";
  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"
  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") ';
  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 (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. }
  410. while ($temp_row = Database::fetch_array($result)) {
  411. $all_tools_list[] = $temp_row;
  412. }
  413. /*if(api_is_course_coach()) {
  414. $result = Database::query("SELECT * FROM $course_tool_table WHERE name='tracking'");
  415. $all_tools_list[]=Database :: fetch_array($result);
  416. }*/
  417. $i = 0;
  418. // Grabbing all the links that have the property on_homepage set to 1
  419. $course_link_table = Database::get_course_table(TABLE_LINK);
  420. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  421. switch ($course_tool_category) {
  422. case TOOL_AUTHORING:
  423. $sql_links = "SELECT tl.*, tip.visibility
  424. FROM $course_link_table tl
  425. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  426. WHERE tl.on_homepage='1' $condition_session";
  427. break;
  428. case TOOL_INTERACTION:
  429. $sql_links = null;
  430. /*
  431. $sql_links = "SELECT tl.*, tip.visibility
  432. FROM $course_link_table tl
  433. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  434. WHERE tl.on_homepage='1' ";
  435. */
  436. break;
  437. case TOOL_STUDENT_VIEW:
  438. $sql_links = "SELECT tl.*, tip.visibility
  439. FROM $course_link_table tl
  440. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  441. WHERE tl.on_homepage='1' $condition_session";
  442. break;
  443. case TOOL_ADMIN:
  444. $sql_links = "SELECT tl.*, tip.visibility
  445. FROM $course_link_table tl
  446. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  447. WHERE tl.on_homepage='1' $condition_session";
  448. break;
  449. default:
  450. $sql_links = null;
  451. break;
  452. }
  453. // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
  454. if ($sql_links != null) {
  455. $result_links = Database::query($sql_links);
  456. $properties = array();
  457. if (Database::num_rows($result_links) > 0) {
  458. while ($links_row = Database::fetch_array($result_links)) {
  459. unset($properties);
  460. $properties['name'] = $links_row['title'];
  461. $properties['session_id'] = $links_row['session_id'];
  462. $properties['link'] = $links_row['url'];
  463. $properties['visibility'] = $links_row['visibility'];
  464. $properties['image'] = ($links_row['visibility'] == '0') ? 'file_html.gif' : 'file_html.gif';
  465. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  466. $properties['target'] = $links_row['target'];
  467. $tmp_all_tools_list[] = $properties;
  468. }
  469. }
  470. }
  471. if (isset($tmp_all_tools_list)) {
  472. foreach ($tmp_all_tools_list as $tool) {
  473. if ($tool['image'] == 'blog.gif') {
  474. // Init
  475. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  476. // Get blog id
  477. $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
  478. // Get blog members
  479. if ($is_platform_admin) {
  480. $sql_blogs = "
  481. SELECT *
  482. FROM " . $tbl_blogs_rel_user . " blogs_rel_user
  483. WHERE blog_id = " . $blog_id;
  484. } else {
  485. $sql_blogs = "
  486. SELECT *
  487. FROM " . $tbl_blogs_rel_user . " blogs_rel_user
  488. WHERE
  489. blog_id = " . $blog_id . " AND
  490. user_id = " . api_get_user_id();
  491. }
  492. $result_blogs = Database::query($sql_blogs);
  493. if (Database::num_rows($result_blogs) > 0) {
  494. $all_tools_list[] = $tool;
  495. }
  496. } else {
  497. $all_tools_list[] = $tool;
  498. }
  499. }
  500. }
  501. return $all_tools_list;
  502. }
  503. /**
  504. * Displays the tools of a certain category.
  505. * @param array List of tools as returned by get_tools_category()
  506. * @return void
  507. */
  508. public static function show_tools_category($all_tools_list, $theme = 'activity') {
  509. if ($theme == 'vertical_activity') {
  510. //ordering by get_lang name
  511. $order_tool_list = array();
  512. foreach($all_tools_list as $key=>$new_tool) {
  513. $tool_name = self::translate_tool_name($new_tool);
  514. $order_tool_list [$key]= $tool_name;
  515. }
  516. natsort($order_tool_list);
  517. $my_temp_tool_array = array();
  518. foreach($order_tool_list as $key=>$new_tool) {
  519. $my_temp_tool_array[] = $all_tools_list[$key];
  520. }
  521. $all_tools_list = $my_temp_tool_array;
  522. }
  523. global $_user;
  524. $web_code_path = api_get_path(WEB_CODE_PATH);
  525. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  526. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  527. $is_platform_admin = api_is_platform_admin();
  528. //var_dump($all_tools_list);
  529. $i = 0;
  530. if (isset($all_tools_list)) {
  531. $lnk = '';
  532. if ($theme == 'vertical_activity') echo '<ul>';
  533. foreach ($all_tools_list as & $tool) {
  534. if ($tool['image'] == 'scormbuilder.gif') {
  535. // display links to lp only for current session
  536. if (api_get_session_id() != $tool['session_id']) {
  537. continue;
  538. }
  539. // check if the published learnpath is visible for student
  540. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  541. if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id,api_get_user_id())) {
  542. continue;
  543. }
  544. }
  545. if (api_get_session_id() != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
  546. continue;
  547. }
  548. if ($theme == 'activity') {
  549. if (!($i % 2)) {
  550. echo "<tr valign=\"top\">\n";
  551. }
  552. } elseif ($theme == 'vertical_activity') {
  553. echo '<li>';
  554. }
  555. // This part displays the links to hide or remove a tool.
  556. // These links are only visible by the course manager.
  557. unset($lnk);
  558. if ($theme == 'activity') {
  559. echo '<td width="50%">'."\n";
  560. }
  561. if ($is_allowed_to_edit && !api_is_coach()) {
  562. if ($tool['visibility'] == '1' && $tool['admin'] != '1') {
  563. $link['name'] = Display::return_icon('visible.gif', get_lang('Deactivate'), array('id' => 'linktool_'.$tool['id']));
  564. $link['cmd'] = 'hide=yes';
  565. $lnk[] = $link;
  566. }
  567. if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
  568. $link['name'] = Display::return_icon('invisible.gif', get_lang('Activate'), array('id' => 'linktool_'.$tool['id']));
  569. $link['cmd'] = 'restore=yes';
  570. $lnk[] = $link;
  571. }
  572. if (!empty($tool['adminlink'])) {
  573. echo '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  574. }
  575. }
  576. // Both checks are necessary as is_platform_admin doesn't take student view into account
  577. if ($is_platform_admin && $is_allowed_to_edit) {
  578. if ($tool['admin'] != '1') {
  579. $link['cmd'] = 'hide=yes';
  580. }
  581. }
  582. if (isset($lnk) && is_array($lnk)) {
  583. foreach ($lnk as $this_link) {
  584. if (empty($tool['adminlink'])) {
  585. echo '<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>';
  586. }
  587. }
  588. } else {
  589. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  590. }
  591. // NOTE : Table contains only the image file name, not full path
  592. if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) {
  593. $tool['link'] = $web_code_path.$tool['link'];
  594. }
  595. if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
  596. $class = 'class="invisible"';
  597. $info = pathinfo($tool['image']);
  598. $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
  599. $tool['image'] = $basename.'_na.'.$info['extension'];
  600. } else {
  601. $class = '';
  602. }
  603. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
  604. // If it's a link, we don't add the cidReq
  605. if ($tool['image'] == 'file_html.gif' || $tool['image'] == 'file_html_na.gif') {
  606. $tool['link'] = $tool['link'].$qm_or_amp;
  607. } else {
  608. $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
  609. }
  610. if (strpos($tool['name'],'visio_') !== false) {
  611. $toollink = "\t" . '<a id="tooldesc_'.$tool["id"].'" ' . $class . ' href="javascript: void(0);" 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\')" target="' . $tool['target'] . '">';
  612. $my_tool_link = "\t" . '<a id="istooldesc_'.$tool["id"].'" ' . $class . ' href="javascript: void(0);" 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\')" target="' . $tool['target'] . '">';
  613. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  614. $toollink = "\t" . '<a id="tooldesc_'.$tool["id"].'" ' . $class . ' href="javascript: void(0);" 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\')" target="' . $tool['target'] . '">';
  615. $my_tool_link="\t" . '<a id="istooldesc_'.$tool["id"].'" ' . $class . ' href="javascript: void(0);" 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\')" target="' . $tool['target'] . '">';
  616. } else {
  617. if (count(explode('type=classroom',$tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) {
  618. $toollink = "\t" . '<a id="tooldesc_'.$tool["id"].'" ' . $class . ' href="' . $tool['link'] . '" target="_blank">';
  619. $my_tool_link = "\t" . '<a id="istooldesc_'.$tool["id"].'" ' . $class . ' href="' . $tool['link'] . '" target="_blank">';
  620. } else {
  621. $toollink = "\t" . '<a id="tooldesc_'.$tool["id"].'" ' . $class . ' href="' . htmlspecialchars($tool['link']) . '" target="' . $tool['target'] . '">';
  622. $my_tool_link = "\t" . '<a id="istooldesc_'.$tool["id"].'" ' . $class . ' href="' . htmlspecialchars($tool['link']) . '" target="' . $tool['target'] . '">';
  623. }
  624. }
  625. echo $toollink;
  626. $tool_name = self::translate_tool_name($tool);
  627. Display::display_icon($tool['image'], $tool_name, array('class' => 'tool-icon', 'id' => 'toolimage_'.$tool['id']));
  628. // Validacion when belongs to a session
  629. $session_img = api_get_session_image($tool['session_id'], $_user['status']);
  630. echo '</a> ';
  631. echo $my_tool_link;
  632. echo "{$tool_name}$session_img";
  633. echo '</a>';
  634. if ($theme == 'activity') {
  635. echo '</td>';
  636. if ($i % 2) {
  637. echo '</tr>';
  638. }
  639. } elseif($theme == 'vertical_activity') {
  640. echo '</li>';
  641. }
  642. $i++;
  643. }
  644. }
  645. if ($theme == 'activity') {
  646. if ($i % 2) {
  647. echo "<td width=\"50%\">&nbsp;</td>\n", "</tr>\n";
  648. }
  649. } elseif($theme == 'vertical_activity') {
  650. echo '</ul>';
  651. }
  652. }
  653. /**
  654. * Shows the general data for a particular meeting
  655. *
  656. * @param id session id
  657. * @return string session data
  658. */
  659. public static function show_session_data($id_session) {
  660. $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
  661. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  662. $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  663. if ($id_session != strval(intval($id_session))) {
  664. return '';
  665. } else {
  666. $id_session = intval($id_session);
  667. }
  668. $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
  669. FROM '.$session_table.'
  670. LEFT JOIN '.$user_table.'
  671. ON id_coach = user_id
  672. WHERE '.$session_table.'.id='.$id_session;
  673. $rs = Database::query($sql);
  674. $session = Database::store_result($rs);
  675. $session = $session[0];
  676. $sql_category = 'SELECT name FROM '.$session_category_table.' WHERE id = "'.intval($session['session_category_id']).'"';
  677. $rs_category = Database::query($sql_category);
  678. $session_category = '';
  679. if (Database::num_rows($rs_category) > 0) {
  680. $rows_session_category = Database::store_result($rs_category);
  681. $rows_session_category = $rows_session_category[0];
  682. $session_category = $rows_session_category['name'];
  683. }
  684. if ($session['date_start'] == '00-00-0000') {
  685. $msg_date = get_lang('NoTimeLimits');
  686. } else {
  687. $msg_date = get_lang('From').' '.$session['date_start'].' '.get_lang('To').' '.$session['date_end'];
  688. }
  689. $output = '';
  690. if (!empty($session_category)) {
  691. $output .= '<tr><td>'. get_lang('SessionCategory') . ': ' . '<b>' . $session_category .'</b></td></tr>';
  692. }
  693. $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>';
  694. $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>';
  695. return $output;
  696. }
  697. /**
  698. * Retrieves the name-field within a tool-record and translates it on necessity.
  699. * @param array $tool The input record.
  700. * @return string Returns the name of the corresponding tool.
  701. */
  702. public static function translate_tool_name(& $tool) {
  703. static $already_translated_icons = array(
  704. 'file_html.gif', 'file_html_na.gif',
  705. 'scormbuilder.gif', 'scormbuilder_na.gif',
  706. 'blog.gif', 'blog_na.gif',
  707. 'external.gif', 'external_na.gif'
  708. );
  709. if (in_array($tool['image'], $already_translated_icons)) {
  710. $tool_name = Security::remove_XSS(stripslashes($tool['name']));
  711. } else {
  712. $variable = 'Tool'.api_underscore_to_camel_case($tool['name']); // The newly opened language variables.
  713. $variable_old = ucfirst($tool['name']); // The old language variables as a second chance exist.
  714. if (api_is_translated($variable)) {
  715. $tool_name = get_lang($variable);
  716. } elseif (api_is_translated($variable_old)) {
  717. $tool_name = get_lang($variable_old);
  718. } else {
  719. $tool_name = get_lang($variable);
  720. }
  721. }
  722. return $tool_name;
  723. }
  724. /**
  725. * Get published learning path id from link inside course home
  726. * @param string Link to published lp
  727. * @return int Learning path id
  728. */
  729. public static function get_published_lp_id_from_link($published_lp_link) {
  730. $lp_id = 0;
  731. $param_lp_id = strstr($published_lp_link, 'lp_id=');
  732. if (!empty($param_lp_id)) {
  733. $a_param_lp_id = explode('=',$param_lp_id);
  734. if (isset($a_param_lp_id[1])) {
  735. $lp_id = intval($a_param_lp_id[1]);
  736. }
  737. }
  738. return $lp_id;
  739. }
  740. }