course_home.lib.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. class CourseHome {
  4. /**
  5. * Gets the html content to show in the 3 column view
  6. */
  7. public static function show_tool_3column($cat) {
  8. if (!class_exists('HTML_Table')) {
  9. require_once 'pear/HTML/Table.php';
  10. }
  11. global $_user;
  12. $charset = api_get_system_encoding();
  13. $TBL_ACCUEIL = Database :: get_course_table(TABLE_TOOL_LIST);
  14. $TABLE_TOOLS = Database :: get_main_table(TABLE_MAIN_COURSE_MODULE);
  15. $numcols = 3;
  16. $table = new HTML_Table('width="100%"');
  17. $all_tools = array();
  18. switch ($cat) {
  19. case 'Basic' :
  20. $condition_display_tools = ' WHERE a.link=t.link AND t.position="basic" ';
  21. if (api_is_coach()) {
  22. $condition_display_tools = ' WHERE a.link=t.link AND (t.position="basic" OR a.name = "'.TOOL_TRACKING.'") ';
  23. }
  24. $sql = "SELECT a.*, t.image img, t.row, t.column FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  25. $condition_display_tools ORDER BY t.row, t.column";
  26. break;
  27. case 'External' :
  28. if (api_is_allowed_to_edit()) {
  29. $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  30. WHERE (a.link=t.link AND t.position='external')
  31. OR (a.visibility <= 1 AND (a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image)
  32. ORDER BY a.id";
  33. } else {
  34. $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  35. WHERE a.visibility = 1 AND ((a.link=t.link AND t.position='external')
  36. OR ((a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image))
  37. ORDER BY a.id";
  38. }
  39. break;
  40. case 'courseAdmin' :
  41. $sql = "SELECT a.*, t.image img, t.row, t.column FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  42. WHERE admin=1 AND a.link=t.link ORDER BY t.row, t.column";
  43. break;
  44. case 'platformAdmin' :
  45. $sql = "SELECT *, image img FROM $TBL_ACCUEIL WHERE visibility = 2 ORDER BY id";
  46. }
  47. $result = Database::query($sql);
  48. // Grabbing all the tools from $course_tool_table
  49. while ($tool = Database::fetch_array($result)) {
  50. $all_tools[] = $tool;
  51. }
  52. // Grabbing all the links that have the property on_homepage set to 1
  53. if ($cat == 'External') {
  54. $tbl_link = Database :: get_course_table(TABLE_LINK);
  55. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  56. if (api_is_allowed_to_edit(null, true)) {
  57. $sql_links = "SELECT tl.*, tip.visibility
  58. FROM $tbl_link tl
  59. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  60. WHERE tl.on_homepage='1' AND tip.visibility != 2";
  61. } else {
  62. $sql_links = "SELECT tl.*, tip.visibility
  63. FROM $tbl_link tl
  64. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  65. WHERE tl.on_homepage='1' AND tip.visibility = 1";
  66. }
  67. $result_links = Database::query($sql_links);
  68. while ($links_row = Database::fetch_array($result_links)) {
  69. $properties = array();
  70. $properties['name'] = $links_row['title'];
  71. $properties['link'] = $links_row['url'];
  72. $properties['visibility'] = $links_row['visibility'];
  73. $properties['img'] = 'external.gif';
  74. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&amp;id='.$links_row['id'];
  75. $all_tools[] = $properties;
  76. }
  77. }
  78. $cell_number = 0;
  79. // Draw line between basic and external, only if there are entries in External
  80. if ($cat == 'External' && count($all_tools)) {
  81. $table->setCellContents(0, 0, '<hr noshade="noshade" size="1"/>');
  82. $table->updateCellAttributes(0, 0, 'colspan="3"');
  83. $cell_number += $numcols;
  84. }
  85. foreach ($all_tools as & $tool) {
  86. if (api_get_session_id() != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
  87. continue;
  88. }
  89. $cell_content = '';
  90. // The name of the tool
  91. $tool_name = self::translate_tool_name($tool);
  92. $link_annex = '';
  93. // The url of the tool
  94. if ($tool['img'] != 'external.gif') {
  95. $tool['link'] = api_get_path(WEB_CODE_PATH).$tool['link'];
  96. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
  97. $link_annex = $qm_or_amp.api_get_cidreq();
  98. } else {
  99. // If an external link ends with 'login=', add the actual login...
  100. $pos = strpos($tool['link'], '?login=');
  101. $pos2 = strpos($tool['link'], '&amp;login=');
  102. if ($pos !== false or $pos2 !== false) {
  103. $link_annex = $_user['username'];
  104. }
  105. }
  106. // Setting the actual image url
  107. $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img'];
  108. // VISIBLE
  109. if (($tool['visibility'] || (api_is_coach() && $tool['name'] == TOOL_TRACKING)) || $cat == 'courseAdmin' || $cat == 'platformAdmin') {
  110. if (strpos($tool['name'], 'visio_') !== false) {
  111. $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>';
  112. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  113. $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']
  114. } else {
  115. $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']
  116. }
  117. }
  118. // INVISIBLE
  119. else {
  120. if (api_is_allowed_to_edit(null, true)) {
  121. if (strpos($tool['name'], 'visio_') !== false) {
  122. $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";
  123. } elseif (strpos($tool['name'],'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  124. $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']
  125. } else {
  126. $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']
  127. }
  128. } else {
  129. $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']
  130. $cell_content .= '<span class="invisible">'.$tool_name.'</span>';
  131. }
  132. }
  133. $lnk = array();
  134. if (api_is_allowed_to_edit(null, true) && $cat != "courseAdmin" && !strpos($tool['link'], 'learnpath_handler.php?learnpath_id') && !api_is_coach()) {
  135. if ($tool['visibility']) {
  136. $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'), array('style' => 'vertical-align: middle;'));
  137. $link['cmd'] = "hide=yes";
  138. $lnk[] = $link;
  139. } else {
  140. $link['name'] = Display::return_icon('add.gif', get_lang('Activate'), array('style' => 'vertical-align: middle;'));
  141. $link['cmd'] = "restore=yes";
  142. $lnk[] = $link;
  143. /*if ($tool['img'] == api_get_path(WEB_IMG_PATH).'external.gif') {
  144. $link['name'] = get_lang('Remove');
  145. $link['cmd'] = 'remove=yes';
  146. if ($tool['visibility'] == 2 && $cat == 'platformAdmin') {
  147. $link['name'] = get_lang('Delete');
  148. $link['cmd'] = 'askDelete=yes';
  149. $lnk[] = $link;
  150. }
  151. }*/
  152. }
  153. //echo "<div class=courseadmin>";
  154. if (is_array($lnk)) {
  155. foreach ($lnk as & $this_lnk) {
  156. if ($tool['adminlink']) {
  157. $cell_content .= '<a href="'.$properties['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  158. } else {
  159. $cell_content .= '<a href="'.api_get_self().'?id='.$tool['id'].'&amp;'.$this_lnk['cmd'].'">'.$this_lnk['name'].'</a>';
  160. }
  161. }
  162. }
  163. // RH: Allow editing of invisible homepage links (modified external_module)
  164. if ($tool['added_tool'] == 1 && api_is_allowed_to_edit() && !$tool['visibility']
  165. && $tool['image'] != 'scormbuilder.gif' && $tool['image'] != 'scormbuilder_na.gif') {
  166. $cell_content .= '<a class="nobold" href="'.api_get_path(WEB_CODE_PATH).'external_module/external_module.php?id='.$tool['id'].'">'.get_lang('Edit').'</a>';
  167. }
  168. }
  169. $table->setCellContents($cell_number / $numcols, ($cell_number) % $numcols, $cell_content);
  170. $table->updateCellAttributes($cell_number / $numcols, ($cell_number) % $numcols, 'width="32%" height="42"');
  171. $cell_number ++;
  172. }
  173. $table->display();
  174. } // end function showtools2($cat)
  175. /**
  176. * Displays the tools of a certain category.
  177. *
  178. * @return void
  179. * @param string $course_tool_category contains the category of tools to display:
  180. * "Public", "PublicButHide", "courseAdmin", "claroAdmin"
  181. */
  182. function show_tool_2column($course_tool_category) {
  183. $charset = api_get_system_encoding();
  184. $web_code_path = api_get_path(WEB_CODE_PATH);
  185. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  186. switch ($course_tool_category) {
  187. case TOOL_PUBLIC:
  188. $condition_display_tools = ' WHERE visibility = 1 ';
  189. if (api_is_coach()) {
  190. $condition_display_tools = ' WHERE visibility = 1 OR (visibility = 0 AND name = "'.TOOL_TRACKING.'") ';
  191. }
  192. $result = Database::query("SELECT * FROM $course_tool_table $condition_display_tools ORDER BY id");
  193. $col_link ="##003399";
  194. break;
  195. case TOOL_PUBLIC_BUT_HIDDEN:
  196. $result = Database::query("SELECT * FROM $course_tool_table WHERE visibility=0 AND admin=0 ORDER BY id");
  197. $col_link ="##808080";
  198. break;
  199. case TOOL_COURSE_ADMIN:
  200. $result = Database::query("SELECT * FROM $course_tool_table WHERE admin=1 AND visibility != 2 ORDER BY id");
  201. $col_link ="##003399";
  202. break;
  203. case TOOL_PLATFORM_ADMIN:
  204. $result = Database::query("SELECT * FROM $course_tool_table WHERE visibility = 2 ORDER BY id");
  205. $col_link ="##003399";
  206. }
  207. $i = 0;
  208. // Grabbing all the tools from $course_tool_table
  209. while ($temp_row = Database::fetch_array($result)) {
  210. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN && $temp_row['image'] != 'scormbuilder.gif') {
  211. $temp_row['image'] = str_replace('.gif', '_na.gif', $temp_row['image']);
  212. }
  213. $all_tools_list[] = $temp_row;
  214. }
  215. // Grabbing all the links that have the property on_homepage set to 1
  216. $course_link_table = Database::get_course_table(TABLE_LINK);
  217. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  218. switch ($course_tool_category) {
  219. case TOOL_PUBLIC:
  220. $sql_links="SELECT tl.*, tip.visibility
  221. FROM $course_link_table tl
  222. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  223. WHERE tl.on_homepage='1' AND tip.visibility = 1";
  224. break;
  225. case TOOL_PUBLIC_BUT_HIDDEN:
  226. $sql_links="SELECT tl.*, tip.visibility
  227. FROM $course_link_table tl
  228. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  229. WHERE tl.on_homepage='1' AND tip.visibility = 0";
  230. break;
  231. default:
  232. $sql_links = null;
  233. break;
  234. }
  235. if ($sql_links != null) {
  236. $properties = array();
  237. $result_links = Database::query($sql_links);
  238. while ($links_row = Database::fetch_array($result_links)) {
  239. unset($properties);
  240. $properties['name'] = $links_row['title'];
  241. $properties['link'] = $links_row['url'];
  242. $properties['visibility'] = $links_row['visibility'];
  243. $properties['image'] = $course_tool_category == TOOL_PUBLIC_BUT_HIDDEN ? 'external_na.gif' : 'external.gif';
  244. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  245. $all_tools_list[] = $properties;
  246. }
  247. }
  248. if (isset($all_tools_list)) {
  249. $lnk = array();
  250. foreach ($all_tools_list as & $tool) {
  251. if (api_get_session_id() != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
  252. continue;
  253. }
  254. if (!($i % 2)) {
  255. echo "<tr valign=\"top\">\n";
  256. }
  257. // NOTE : Table contains only the image file name, not full path
  258. if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) {
  259. $tool['link'] = $web_code_path.$tool['link'];
  260. }
  261. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) {
  262. $class = 'class="invisible"';
  263. }
  264. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
  265. $tool['link'] = $tool['link'];
  266. echo '<td width="50%" height="30">';
  267. if (strpos($tool['name'], 'visio_') !== false) {
  268. 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'] . '">';
  269. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  270. 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.'>';
  271. } else {
  272. 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.'>';
  273. }
  274. $tool_name = self::translate_tool_name($tool);
  275. echo Display::return_icon($tool['image'], $tool_name),'&nbsp;', $tool_name,'</a>';
  276. // This part displays the links to hide or remove a tool.
  277. // These links are only visible by the course manager.
  278. unset($lnk);
  279. if (api_is_allowed_to_edit(null, true) && !api_is_coach()) {
  280. if ($tool['visibility'] == '1' || $tool['name'] == TOOL_TRACKING) {
  281. $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'));
  282. $link['cmd'] = 'hide=yes';
  283. $lnk[] = $link;
  284. }
  285. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) {
  286. $link['name'] = Display::return_icon('add.gif', get_lang('Activate'));
  287. $link['cmd'] = 'restore=yes';
  288. $lnk[] = $link;
  289. if ($tool['added_tool'] == 1) {
  290. $link['name'] = Display::return_icon('delete.gif', get_lang('Remove'));
  291. $link['cmd'] = 'remove=yes';
  292. $lnk[] = $link;
  293. }
  294. }
  295. if ($tool['adminlink']) {
  296. echo '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  297. }
  298. }
  299. if (api_is_platform_admin() && !api_is_coach()) {
  300. if ($tool['visibility'] == 2) {
  301. $link['name'] = Display::return_icon('undelete.gif', get_lang('Activate'));
  302. $link['cmd'] = 'hide=yes';
  303. $lnk[] = $link;
  304. if ($tool['added_tool'] == 1) {
  305. $link['name'] = get_lang('Delete');
  306. $link['cmd'] = 'askDelete=yes';
  307. $lnk[] = $link;
  308. }
  309. }
  310. if ($tool['visibility'] == 0 && $tool['added_tool'] == 0) {
  311. $link['name'] = Display::return_icon('delete.gif', get_lang('Remove'));
  312. $link['cmd'] = 'remove=yes';
  313. $lnk[] = $link;
  314. }
  315. }
  316. if (is_array($lnk)) {
  317. foreach ($lnk as & $this_link) {
  318. if (!$tool['adminlink']) {
  319. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$tool['id'].'&amp;'.$this_link['cmd'].'">'.$this_link['name'].'</a>';
  320. }
  321. }
  322. }
  323. // Allow editing of invisible homepage links (modified external_module)
  324. if ($tool['added_tool'] == 1 && api_is_allowed_to_edit(null, true) && !$tool['visibility']
  325. && $tool['image'] != 'scormbuilder.gif' && $tool['image'] != 'scormbuilder_na.gif') {
  326. 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>';
  327. }
  328. echo "</td>\n";
  329. if ($i % 2) {
  330. echo "</tr>\n";
  331. }
  332. $i++;
  333. }
  334. }
  335. if ($i % 2) {
  336. echo "<td width=\"50%\">&nbsp;</td>\n", "</tr>\n";
  337. }
  338. }
  339. /**
  340. * Gets the tools of a certain category. Returns an array expected
  341. * by show_tools_category()
  342. * @param string $course_tool_category contains the category of tools to
  343. * display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform"
  344. * @return array
  345. */
  346. public static function get_tools_category($course_tool_category) {
  347. global $_user;
  348. $web_code_path = api_get_path(WEB_CODE_PATH);
  349. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  350. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  351. $is_platform_admin = api_is_platform_admin();
  352. $all_tools_list = array();
  353. // Condition for the session
  354. $session_id = api_get_session_id();
  355. $condition_session = api_get_session_condition($session_id, true, true);
  356. switch ($course_tool_category) {
  357. case TOOL_STUDENT_VIEW:
  358. $condition_display_tools = ' WHERE visibility = 1 AND (category = "authoring" OR category = "interaction") ';
  359. if (api_is_coach()) {
  360. $condition_display_tools = ' WHERE (visibility = 1 AND (category = "authoring" OR category = "interaction")) OR (name = "'.TOOL_TRACKING.'") ';
  361. }
  362. $sql = "SELECT * FROM $course_tool_table $condition_display_tools $condition_session ORDER BY id";
  363. $result = Database::query($sql);
  364. $col_link ="##003399";
  365. break;
  366. case TOOL_AUTHORING:
  367. $sql = "SELECT * FROM $course_tool_table WHERE category = 'authoring' $condition_session ORDER BY id";
  368. $result = Database::query($sql);
  369. $col_link ="##003399";
  370. break;
  371. case TOOL_INTERACTION:
  372. $sql = "SELECT * FROM $course_tool_table WHERE category = 'interaction' $condition_session ORDER BY id";
  373. $result = Database::query($sql);
  374. $col_link ="##003399";
  375. break;
  376. case TOOL_ADMIN_VISIBLE:
  377. $sql = "SELECT * FROM $course_tool_table WHERE category = 'admin' AND visibility ='1' $condition_session ORDER BY id";
  378. $result = Database::query($sql);
  379. $col_link ="##003399";
  380. break;
  381. case TOOL_ADMIN_PLATEFORM:
  382. $sql = "SELECT * FROM $course_tool_table WHERE category = 'admin' $condition_session ORDER BY id";
  383. $result = Database::query($sql);
  384. $col_link ="##003399";
  385. break;
  386. }
  387. while ($temp_row = Database::fetch_array($result)) {
  388. $all_tools_list[] = $temp_row;
  389. }
  390. /*if(api_is_course_coach()) {
  391. $result = Database::query("SELECT * FROM $course_tool_table WHERE name='tracking'");
  392. $all_tools_list[]=Database :: fetch_array($result);
  393. }*/
  394. $i = 0;
  395. // Grabbing all the links that have the property on_homepage set to 1
  396. $course_link_table = Database::get_course_table(TABLE_LINK);
  397. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  398. switch ($course_tool_category) {
  399. case TOOL_AUTHORING:
  400. $sql_links = "SELECT tl.*, tip.visibility
  401. FROM $course_link_table tl
  402. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  403. WHERE tl.on_homepage='1' $condition_session";
  404. break;
  405. case TOOL_INTERACTION:
  406. $sql_links = null;
  407. /*
  408. $sql_links = "SELECT tl.*, tip.visibility
  409. FROM $course_link_table tl
  410. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  411. WHERE tl.on_homepage='1' ";
  412. */
  413. break;
  414. case TOOL_STUDENT_VIEW:
  415. $sql_links = "SELECT tl.*, tip.visibility
  416. FROM $course_link_table tl
  417. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  418. WHERE tl.on_homepage='1' $condition_session";
  419. break;
  420. case TOOL_ADMIN:
  421. $sql_links = "SELECT tl.*, tip.visibility
  422. FROM $course_link_table tl
  423. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  424. WHERE tl.on_homepage='1' $condition_session";
  425. break;
  426. default:
  427. $sql_links = null;
  428. break;
  429. }
  430. // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
  431. if ($sql_links != null) {
  432. $result_links = Database::query($sql_links);
  433. $properties = array();
  434. if (Database::num_rows($result_links) > 0) {
  435. while ($links_row = Database::fetch_array($result_links)) {
  436. unset($properties);
  437. $properties['name'] = $links_row['title'];
  438. $properties['session_id'] = $links_row['session_id'];
  439. $properties['link'] = $links_row['url'];
  440. $properties['visibility'] = $links_row['visibility'];
  441. $properties['image'] = ($links_row['visibility'] == '0') ? 'file_html.gif' : 'file_html.gif';
  442. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  443. $properties['target'] = $links_row['target'];
  444. $tmp_all_tools_list[] = $properties;
  445. }
  446. }
  447. }
  448. if (isset($tmp_all_tools_list)) {
  449. foreach ($tmp_all_tools_list as $tool) {
  450. if ($tool['image'] == 'blog.gif') {
  451. // Init
  452. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  453. // Get blog id
  454. $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
  455. // Get blog members
  456. if ($is_platform_admin) {
  457. $sql_blogs = "
  458. SELECT *
  459. FROM " . $tbl_blogs_rel_user . " blogs_rel_user
  460. WHERE blog_id = " . $blog_id;
  461. } else {
  462. $sql_blogs = "
  463. SELECT *
  464. FROM " . $tbl_blogs_rel_user . " blogs_rel_user
  465. WHERE
  466. blog_id = " . $blog_id . " AND
  467. user_id = " . api_get_user_id();
  468. }
  469. $result_blogs = Database::query($sql_blogs);
  470. if (Database::num_rows($result_blogs) > 0) {
  471. $all_tools_list[] = $tool;
  472. }
  473. } else {
  474. $all_tools_list[] = $tool;
  475. }
  476. }
  477. }
  478. return $all_tools_list;
  479. }
  480. /**
  481. * Displays the tools of a certain category.
  482. * @param array List of tools as returned by get_tools_category()
  483. * @return void
  484. */
  485. public static function show_tools_category($all_tools_list) {
  486. global $_user;
  487. $web_code_path = api_get_path(WEB_CODE_PATH);
  488. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  489. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  490. $is_platform_admin = api_is_platform_admin();
  491. $i = 0;
  492. if (isset($all_tools_list)) {
  493. $lnk = '';
  494. foreach ($all_tools_list as & $tool) {
  495. if (api_get_session_id() != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
  496. continue;
  497. }
  498. if (!($i % 2)) {
  499. echo "<tr valign=\"top\">\n";
  500. }
  501. // This part displays the links to hide or remove a tool.
  502. // These links are only visible by the course manager.
  503. unset($lnk);
  504. echo '<td width="50%">'."\n";
  505. if ($is_allowed_to_edit && !api_is_coach()) {
  506. if ($tool['visibility'] == '1' && $tool['admin'] != '1') {
  507. $link['name'] = Display::return_icon('visible.gif', get_lang('Deactivate'), array('id' => 'linktool_'.$tool['id']));
  508. $link['cmd'] = 'hide=yes';
  509. $lnk[] = $link;
  510. }
  511. if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
  512. $link['name'] = Display::return_icon('invisible.gif', get_lang('Activate'), array('id' => 'linktool_'.$tool['id']));
  513. $link['cmd'] = 'restore=yes';
  514. $lnk[] = $link;
  515. }
  516. if (!empty($tool['adminlink'])) {
  517. echo '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  518. }
  519. }
  520. // Both checks are necessary as is_platform_admin doesn't take student view into account
  521. if ($is_platform_admin && $is_allowed_to_edit) {
  522. if ($tool['admin'] != '1') {
  523. $link['cmd'] = 'hide=yes';
  524. }
  525. }
  526. if (isset($lnk) && is_array($lnk)) {
  527. foreach ($lnk as $this_link) {
  528. if (empty($tool['adminlink'])) {
  529. 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>';
  530. }
  531. }
  532. } else {
  533. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  534. }
  535. // NOTE : Table contains only the image file name, not full path
  536. if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) {
  537. $tool['link'] = $web_code_path.$tool['link'];
  538. }
  539. if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
  540. $class = 'class="invisible"';
  541. $info = pathinfo($tool['image']);
  542. $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
  543. $tool['image'] = $basename.'_na.'.$info['extension'];
  544. } else {
  545. $class = '';
  546. }
  547. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
  548. // If it's a link, we don't add the cidReq
  549. if ($tool['image'] == 'file_html.gif' || $tool['image'] == 'file_html_na.gif') {
  550. $tool['link'] = $tool['link'].$qm_or_amp;
  551. } else {
  552. $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
  553. }
  554. if (strpos($tool['name'],'visio_') !== false) {
  555. $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'] . '">';
  556. $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'] . '">';
  557. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  558. $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'] . '">';
  559. $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'] . '">';
  560. } else {
  561. if (count(explode('type=classroom',$tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) {
  562. $toollink = "\t" . '<a id="tooldesc_'.$tool["id"].'" ' . $class . ' href="' . $tool['link'] . '" target="_blank">';
  563. $my_tool_link = "\t" . '<a id="istooldesc_'.$tool["id"].'" ' . $class . ' href="' . $tool['link'] . '" target="_blank">';
  564. } else {
  565. $toollink = "\t" . '<a id="tooldesc_'.$tool["id"].'" ' . $class . ' href="' . htmlspecialchars($tool['link']) . '" target="' . $tool['target'] . '">';
  566. $my_tool_link = "\t" . '<a id="istooldesc_'.$tool["id"].'" ' . $class . ' href="' . htmlspecialchars($tool['link']) . '" target="' . $tool['target'] . '">';
  567. }
  568. }
  569. echo $toollink;
  570. $tool_name = self::translate_tool_name($tool);
  571. Display::display_icon($tool['image'], $tool_name, array('class' => 'tool-icon', 'id' => 'toolimage_'.$tool['id']));
  572. // Validacion when belongs to a session
  573. $session_img = api_get_session_image($tool['session_id'], $_user['status']);
  574. echo '</a> ';
  575. echo $my_tool_link;
  576. echo "{$tool_name}$session_img";
  577. echo "\t".'</a></td>';
  578. if ($i % 2) {
  579. echo '</tr>';
  580. }
  581. $i++;
  582. }
  583. }
  584. if ($i % 2) {
  585. echo "<td width=\"50%\">&nbsp;</td>\n", "</tr>\n";
  586. }
  587. }
  588. /**
  589. * Shows the general data for a particular meeting
  590. *
  591. * @param id session id
  592. * @return string session data
  593. */
  594. public static function show_session_data($id_session) {
  595. $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
  596. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  597. $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  598. if ($id_session != strval(intval($id_session))) {
  599. return '';
  600. } else {
  601. $id_session = intval($id_session);
  602. }
  603. $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
  604. FROM '.$session_table.'
  605. LEFT JOIN '.$user_table.'
  606. ON id_coach = user_id
  607. WHERE '.$session_table.'.id='.$id_session;
  608. $rs = Database::query($sql);
  609. $session = Database::store_result($rs);
  610. $session = $session[0];
  611. $sql_category = 'SELECT name FROM '.$session_category_table.' WHERE id = "'.intval($session['session_category_id']).'"';
  612. $rs_category = Database::query($sql_category);
  613. $session_category = '';
  614. if (Database::num_rows($rs_category) > 0) {
  615. $rows_session_category = Database::store_result($rs_category);
  616. $rows_session_category = $rows_session_category[0];
  617. $session_category = $rows_session_category['name'];
  618. }
  619. if ($session['date_start'] == '00-00-0000') {
  620. $msg_date = get_lang('NoTimeLimits');
  621. } else {
  622. $msg_date = get_lang('From').' '.$session['date_start'].' '.get_lang('To').' '.$session['date_end'];
  623. }
  624. $output = '';
  625. if (!empty($session_category)) {
  626. $output .= '<tr><td>'. get_lang('SessionCategory') . ': ' . '<b>' . $session_category .'</b></td></tr>';
  627. }
  628. $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>';
  629. $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>';
  630. return $output;
  631. }
  632. /**
  633. * Retrieves the name-field within a tool-record and translates it on necessity.
  634. * @param array $tool The input record.
  635. * @return string Returns the name of the corresponding tool.
  636. */
  637. public static function translate_tool_name(& $tool) {
  638. static $already_translated_icons = array(
  639. 'file_html.gif', 'file_html_na.gif',
  640. 'scormbuilder.gif', 'scormbuilder_na.gif',
  641. 'blog.gif', 'blog_na.gif',
  642. 'external.gif', 'external_na.gif'
  643. );
  644. if (in_array($tool['image'], $already_translated_icons)) {
  645. $tool_name = Security::remove_XSS(stripslashes($tool['name']));
  646. } else {
  647. $variable = 'Tool'.api_underscore_to_camel_case($tool['name']); // The newly opened language variables.
  648. $variable_old = ucfirst($tool['name']); // The old language variables as a second chance exist.
  649. if (api_is_translated($variable)) {
  650. $tool_name = get_lang($variable);
  651. } elseif (api_is_translated($variable_old)) {
  652. $tool_name = get_lang($variable_old);
  653. } else {
  654. $tool_name = get_lang($variable);
  655. }
  656. }
  657. return $tool_name;
  658. }
  659. }