course_home.lib.php 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class CourseHome
  5. */
  6. class CourseHome
  7. {
  8. /**
  9. * Gets the html content to show in the 3 column view
  10. */
  11. public static function show_tool_3column($cat, $userId = null)
  12. {
  13. $_user = api_get_user_info($userId);
  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. $course_id = api_get_course_int_id();
  20. switch ($cat) {
  21. case 'Basic' :
  22. $condition_display_tools = ' WHERE a.c_id = '.$course_id.' AND a.link=t.link AND t.position="basic" ';
  23. if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
  24. $condition_display_tools = ' WHERE a.c_id = '.$course_id.' AND a.link=t.link AND (t.position="basic" OR a.name = "'.TOOL_TRACKING.'") ';
  25. }
  26. $sql = "SELECT a.*, t.image img, t.row, t.column FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  27. $condition_display_tools ORDER BY t.row, t.column";
  28. break;
  29. case 'External' :
  30. if (api_is_allowed_to_edit()) {
  31. $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  32. WHERE a.c_id = $course_id AND ((a.link=t.link AND t.position='external')
  33. OR (a.visibility <= 1 AND (a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image))
  34. ORDER BY a.id";
  35. } else {
  36. $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  37. WHERE a.c_id = $course_id AND (a.visibility = 1 AND ((a.link=t.link AND t.position='external')
  38. OR ((a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image)))
  39. ORDER BY a.id";
  40. }
  41. break;
  42. case 'courseAdmin' :
  43. $sql = "SELECT a.*, t.image img, t.row, t.column FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  44. WHERE a.c_id = $course_id AND admin=1 AND a.link=t.link ORDER BY t.row, t.column";
  45. break;
  46. case 'platformAdmin' :
  47. $sql = "SELECT *, image img FROM $TBL_ACCUEIL WHERE c_id = $course_id AND visibility = 2 ORDER BY id";
  48. }
  49. $result = Database::query($sql);
  50. // Grabbing all the tools from $course_tool_table
  51. while ($tool = Database::fetch_array($result)) {
  52. $all_tools[] = $tool;
  53. }
  54. $course_id = api_get_course_int_id();
  55. // Grabbing all the links that have the property on_homepage set to 1
  56. if ($cat == 'External') {
  57. $tbl_link = Database :: get_course_table(TABLE_LINK);
  58. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  59. if (api_is_allowed_to_edit(null, true)) {
  60. $sql_links = "SELECT tl.*, tip.visibility
  61. FROM $tbl_link tl
  62. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  63. WHERE tl.c_id = $course_id AND
  64. tip.c_id = $course_id AND
  65. tl.on_homepage='1' AND
  66. tip.visibility != 2";
  67. } else {
  68. $sql_links = "SELECT tl.*, tip.visibility
  69. FROM $tbl_link tl
  70. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  71. WHERE tl.c_id = $course_id AND
  72. tip.c_id = $course_id AND
  73. tl.on_homepage='1' AND
  74. tip.visibility = 1";
  75. }
  76. $result_links = Database::query($sql_links);
  77. while ($links_row = Database::fetch_array($result_links)) {
  78. $properties = array();
  79. $properties['name'] = $links_row['title'];
  80. $properties['link'] = $links_row['url'];
  81. $properties['visibility'] = $links_row['visibility'];
  82. $properties['img'] = 'external.gif';
  83. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&amp;id='.$links_row['id'];
  84. $all_tools[] = $properties;
  85. }
  86. }
  87. $cell_number = 0;
  88. // Draw line between basic and external, only if there are entries in External
  89. if ($cat == 'External' && count($all_tools)) {
  90. $table->setCellContents(0, 0, '<hr noshade="noshade" size="1"/>');
  91. $table->updateCellAttributes(0, 0, 'colspan="3"');
  92. $cell_number += $numcols;
  93. }
  94. foreach ($all_tools as & $tool) {
  95. if ($tool['image'] == 'scormbuilder.gif') {
  96. // check if the published learnpath is visible for student
  97. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  98. if (!api_is_allowed_to_edit(null, true) &&
  99. !learnpath::is_lp_visible_for_student(
  100. $published_lp_id,
  101. api_get_user_id(),
  102. api_get_course_id(),
  103. api_get_session_id()
  104. )
  105. ) {
  106. continue;
  107. }
  108. }
  109. if (api_get_session_id() != 0 &&
  110. in_array($tool['name'], array('course_maintenance', 'course_setting'))
  111. ) {
  112. continue;
  113. }
  114. $cell_content = '';
  115. // The name of the tool
  116. $tool_name = self::translate_tool_name($tool);
  117. $link_annex = '';
  118. // The url of the tool
  119. if ($tool['img'] != 'external.gif') {
  120. $tool['link'] = api_get_path(WEB_CODE_PATH).$tool['link'];
  121. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
  122. $link_annex = $qm_or_amp.api_get_cidreq();
  123. } else {
  124. // If an external link ends with 'login=', add the actual login...
  125. $pos = strpos($tool['link'], '?login=');
  126. $pos2 = strpos($tool['link'], '&amp;login=');
  127. if ($pos !== false or $pos2 !== false) {
  128. $link_annex = $_user['username'];
  129. }
  130. }
  131. // Setting the actual image url
  132. $tool['img'] = Display::returnIconPath($tool['img']);
  133. // VISIBLE
  134. if (($tool['visibility'] ||
  135. ((api_is_coach() || api_is_course_tutor()) && $tool['name'] == TOOL_TRACKING)) ||
  136. $cat == 'courseAdmin' || $cat == 'platformAdmin'
  137. ) {
  138. if (strpos($tool['name'], 'visio_') !== false) {
  139. $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>';
  140. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  141. $cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$tool['link'].$link_annex.'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', 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>';
  142. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  143. } else {
  144. $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>';
  145. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  146. }
  147. } else {
  148. // INVISIBLE
  149. if (api_is_allowed_to_edit(null, true)) {
  150. if (strpos($tool['name'], 'visio_') !== false) {
  151. $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>';
  152. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  153. $cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$tool['link'].$link_annex.'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', 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>';
  154. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  155. } else {
  156. $cell_content .= '<a href="'.$tool['link'].$link_annex.'" target="'.$tool['target'].'" class="invisible">
  157. <img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  158. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  159. }
  160. } else {
  161. $cell_content .= '<img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">';
  162. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  163. $cell_content .= '<span class="invisible">'.$tool_name.'</span>';
  164. }
  165. }
  166. $lnk = array();
  167. if (api_is_allowed_to_edit(null, true) &&
  168. $cat != "courseAdmin" &&
  169. !strpos($tool['link'], 'learnpath_handler.php?learnpath_id') &&
  170. !api_is_coach()
  171. ) {
  172. if ($tool['visibility']) {
  173. $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'), array('style' => 'vertical-align: middle;'));
  174. $link['cmd'] = "hide=yes";
  175. $lnk[] = $link;
  176. } else {
  177. $link['name'] = Display::return_icon('add.gif', get_lang('Activate'), array('style' => 'vertical-align: middle;'));
  178. $link['cmd'] = "restore=yes";
  179. $lnk[] = $link;
  180. }
  181. if (is_array($lnk)) {
  182. foreach ($lnk as & $this_lnk) {
  183. if ($tool['adminlink']) {
  184. $cell_content .= '<a href="'.$properties['adminlink'].'">'.
  185. Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  186. } else {
  187. $cell_content .= '<a href="'.api_get_self().'?id='.$tool['id'].'&amp;'.$this_lnk['cmd'].'">'.$this_lnk['name'].'</a>';
  188. }
  189. }
  190. }
  191. }
  192. $table->setCellContents($cell_number / $numcols, ($cell_number) % $numcols, $cell_content);
  193. $table->updateCellAttributes($cell_number / $numcols, ($cell_number) % $numcols, 'width="32%" height="42"');
  194. $cell_number++;
  195. }
  196. return $table->toHtml();
  197. }
  198. /**
  199. * Displays the tools of a certain category.
  200. *
  201. * @return void
  202. * @param string $course_tool_category contains the category of tools to display:
  203. * "Public", "PublicButHide", "courseAdmin", "claroAdmin"
  204. */
  205. public static function show_tool_2column($course_tool_category)
  206. {
  207. $html = '';
  208. $web_code_path = api_get_path(WEB_CODE_PATH);
  209. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  210. $course_id = api_get_course_int_id();
  211. switch ($course_tool_category) {
  212. case TOOL_PUBLIC:
  213. $condition_display_tools = ' WHERE c_id = '.$course_id.' AND visibility = 1 ';
  214. if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
  215. $condition_display_tools = ' WHERE c_id = '.$course_id.' AND (visibility = 1 OR (visibility = 0 AND name = "'.TOOL_TRACKING.'")) ';
  216. }
  217. $result = Database::query("SELECT * FROM $course_tool_table $condition_display_tools ORDER BY id");
  218. $col_link = "##003399";
  219. break;
  220. case TOOL_PUBLIC_BUT_HIDDEN:
  221. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility=0 AND admin=0 ORDER BY id");
  222. $col_link = "##808080";
  223. break;
  224. case TOOL_COURSE_ADMIN:
  225. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND admin=1 AND visibility != 2 ORDER BY id");
  226. $col_link = "##003399";
  227. break;
  228. case TOOL_PLATFORM_ADMIN:
  229. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility = 2 ORDER BY id");
  230. $col_link = "##003399";
  231. }
  232. $i = 0;
  233. // Grabbing all the tools from $course_tool_table
  234. while ($temp_row = Database::fetch_array($result)) {
  235. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN && $temp_row['image'] != 'scormbuilder.gif') {
  236. $temp_row['image'] = str_replace('.gif', '_na.gif', $temp_row['image']);
  237. }
  238. $all_tools_list[] = $temp_row;
  239. }
  240. // Grabbing all the links that have the property on_homepage set to 1
  241. $course_link_table = Database::get_course_table(TABLE_LINK);
  242. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  243. switch ($course_tool_category) {
  244. case TOOL_PUBLIC:
  245. $sql_links = "SELECT tl.*, tip.visibility
  246. FROM $course_link_table tl
  247. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tl.c_id = tip.c_id AND tl.c_id = $course_id AND tip.ref=tl.id
  248. WHERE tl.on_homepage='1' AND tip.visibility = 1";
  249. break;
  250. case TOOL_PUBLIC_BUT_HIDDEN:
  251. $sql_links = "SELECT tl.*, tip.visibility
  252. FROM $course_link_table tl
  253. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tl.c_id = tip.c_id AND tl.c_id = $course_id AND tip.ref=tl.id
  254. WHERE tl.on_homepage='1' AND tip.visibility = 0";
  255. break;
  256. default:
  257. $sql_links = null;
  258. break;
  259. }
  260. if ($sql_links != null) {
  261. $properties = array();
  262. $result_links = Database::query($sql_links);
  263. while ($links_row = Database::fetch_array($result_links)) {
  264. unset($properties);
  265. $properties['name'] = $links_row['title'];
  266. $properties['link'] = $links_row['url'];
  267. $properties['visibility'] = $links_row['visibility'];
  268. $properties['image'] = $course_tool_category == TOOL_PUBLIC_BUT_HIDDEN ? 'external_na.gif' : 'external.gif';
  269. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  270. $all_tools_list[] = $properties;
  271. }
  272. }
  273. if (isset($all_tools_list)) {
  274. $lnk = array();
  275. foreach ($all_tools_list as & $tool) {
  276. if ($tool['image'] == 'scormbuilder.gif') {
  277. // check if the published learnpath is visible for student
  278. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  279. if (!api_is_allowed_to_edit(null, true) &&
  280. !learnpath::is_lp_visible_for_student(
  281. $published_lp_id,
  282. api_get_user_id(),
  283. api_get_course_id(),
  284. api_get_session_id()
  285. )
  286. ) {
  287. continue;
  288. }
  289. }
  290. if (api_get_session_id() != 0 &&
  291. in_array($tool['name'], array('course_maintenance', 'course_setting'))
  292. ) {
  293. continue;
  294. }
  295. if (!($i % 2)) {
  296. $html .= "<tr valign=\"top\">";
  297. }
  298. // NOTE : Table contains only the image file name, not full path
  299. if (stripos($tool['link'], 'http://') === false &&
  300. stripos($tool['link'], 'https://') === false &&
  301. stripos($tool['link'], 'ftp://') === false
  302. ) {
  303. $tool['link'] = $web_code_path.$tool['link'];
  304. }
  305. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) {
  306. $class = 'class="invisible"';
  307. }
  308. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
  309. $tool['link'] = $tool['link'];
  310. $html .= '<td width="50%" height="30">';
  311. if (strpos($tool['name'], 'visio_') !== false) {
  312. $html .= '<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'].'">';
  313. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  314. $html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.htmlspecialchars($tool['link']).$qm_or_amp.api_get_cidreq().'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'"'.$class.'>';
  315. } else {
  316. $html .= '<a href="'.htmlspecialchars($tool['link']).(($tool['image'] == 'external.gif' || $tool['image'] == 'external_na.gif') ? '' : $qm_or_amp.api_get_cidreq()).'" target="'.$tool['target'].'" '.$class.'>';
  317. }
  318. $tool_name = self::translate_tool_name($tool);
  319. $html .= Display::return_icon(
  320. $tool['image'],
  321. $tool_name,
  322. array(),
  323. null,
  324. ICON_SIZE_MEDIUM
  325. ) . '&nbsp;' . $tool_name . '</a>';
  326. // This part displays the links to hide or remove a tool.
  327. // These links are only visible by the course manager.
  328. unset($lnk);
  329. if (api_is_allowed_to_edit(null, true) && !api_is_coach()) {
  330. if ($tool['visibility'] == '1' || $tool['name'] == TOOL_TRACKING) {
  331. $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'));
  332. $link['cmd'] = 'hide=yes';
  333. $lnk[] = $link;
  334. }
  335. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) {
  336. $link['name'] = Display::return_icon('add.gif', get_lang('Activate'));
  337. $link['cmd'] = 'restore=yes';
  338. $lnk[] = $link;
  339. if ($tool['added_tool'] == 1) {
  340. $link['name'] = Display::return_icon('delete.gif', get_lang('Remove'));
  341. $link['cmd'] = 'remove=yes';
  342. $lnk[] = $link;
  343. }
  344. }
  345. if ($tool['adminlink']) {
  346. $html .= '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  347. }
  348. }
  349. if (api_is_platform_admin() && !api_is_coach()) {
  350. if ($tool['visibility'] == 2) {
  351. $link['name'] = Display::return_icon('undelete.gif', get_lang('Activate'));
  352. $link['cmd'] = 'hide=yes';
  353. $lnk[] = $link;
  354. if ($tool['added_tool'] == 1) {
  355. $link['name'] = get_lang('Delete');
  356. $link['cmd'] = 'askDelete=yes';
  357. $lnk[] = $link;
  358. }
  359. }
  360. if ($tool['visibility'] == 0 && $tool['added_tool'] == 0) {
  361. $link['name'] = Display::return_icon('delete.gif', get_lang('Remove'));
  362. $link['cmd'] = 'remove=yes';
  363. $lnk[] = $link;
  364. }
  365. }
  366. if (is_array($lnk)) {
  367. foreach ($lnk as & $this_link) {
  368. if (!$tool['adminlink']) {
  369. $html .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$tool['id'].'&amp;'.$this_link['cmd'].'">'.$this_link['name'].'</a>';
  370. }
  371. }
  372. }
  373. $html .= "</td>";
  374. if ($i % 2) {
  375. $html .= "</tr>";
  376. }
  377. $i++;
  378. }
  379. }
  380. if ($i % 2) {
  381. $html .= "<td width=\"50%\">&nbsp;</td></tr>";
  382. }
  383. return $html;
  384. }
  385. /**
  386. * Gets the tools of a certain category. Returns an array expected
  387. * by show_tools_category()
  388. * @param string $course_tool_category contains the category of tools to
  389. * display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform", "toolplugin"
  390. * @return array
  391. */
  392. public static function get_tools_category($course_tool_category)
  393. {
  394. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  395. $is_platform_admin = api_is_platform_admin();
  396. $all_tools_list = array();
  397. // Condition for the session
  398. $session_id = api_get_session_id();
  399. $course_id = api_get_course_int_id();
  400. $condition_session = api_get_session_condition($session_id, true, true, 't.session_id');
  401. switch ($course_tool_category) {
  402. case TOOL_STUDENT_VIEW:
  403. $conditions = ' WHERE visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") ';
  404. if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
  405. $conditions = ' WHERE (visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") OR (name = "'.TOOL_TRACKING.'") ) ';
  406. }
  407. $sql = "SELECT *
  408. FROM $course_tool_table t
  409. $conditions AND
  410. c_id = $course_id $condition_session
  411. ORDER BY id";
  412. $result = Database::query($sql);
  413. break;
  414. case TOOL_AUTHORING:
  415. $sql = "SELECT * FROM $course_tool_table t
  416. WHERE category = 'authoring' AND c_id = $course_id $condition_session
  417. ORDER BY id";
  418. $result = Database::query($sql);
  419. break;
  420. case TOOL_INTERACTION:
  421. $sql = "SELECT * FROM $course_tool_table t
  422. WHERE category = 'interaction' AND c_id = $course_id $condition_session
  423. ORDER BY id";
  424. $result = Database::query($sql);
  425. break;
  426. case TOOL_ADMIN_VISIBLE:
  427. $sql = "SELECT * FROM $course_tool_table t
  428. WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session
  429. ORDER BY id";
  430. $result = Database::query($sql);
  431. break;
  432. case TOOL_ADMIN_PLATFORM:
  433. $sql = "SELECT * FROM $course_tool_table t
  434. WHERE category = 'admin' AND c_id = $course_id $condition_session
  435. ORDER BY id";
  436. $result = Database::query($sql);
  437. break;
  438. case TOOL_DRH:
  439. $sql = "SELECT * FROM $course_tool_table t
  440. WHERE name IN ('tracking') AND c_id = $course_id $condition_session
  441. ORDER BY id";
  442. $result = Database::query($sql);
  443. break;
  444. case TOOL_COURSE_PLUGIN:
  445. //Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id
  446. // but plugins are not present in the tool table, only globally and inside the course_settings table once configured
  447. $sql = "SELECT * FROM $course_tool_table t
  448. WHERE category = 'plugin' AND c_id = $course_id $condition_session
  449. ORDER BY id";
  450. $result = Database::query($sql);
  451. break;
  452. }
  453. //Get the list of hidden tools - this might imply performance slowdowns
  454. // if the course homepage is loaded many times, so the list of hidden
  455. // tools might benefit from a shared memory storage later on
  456. $list = api_get_settings('Tools', 'list', api_get_current_access_url_id());
  457. $hide_list = array();
  458. $check = false;
  459. foreach ($list as $line) {
  460. // Admin can see all tools even if the course_hide_tools configuration is set
  461. if ($is_platform_admin) {
  462. continue;
  463. }
  464. if ($line['variable'] == 'course_hide_tools' and $line['selected_value'] == 'true') {
  465. $hide_list[] = $line['subkey'];
  466. $check = true;
  467. }
  468. }
  469. while ($temp_row = Database::fetch_assoc($result)) {
  470. $add = false;
  471. if ($check) {
  472. if (!in_array($temp_row['name'], $hide_list)) {
  473. $add = true;
  474. }
  475. } else {
  476. $add = true;
  477. }
  478. if ($temp_row['image'] == 'scormbuilder.gif') {
  479. $lp_id = self::get_published_lp_id_from_link($temp_row['link']);
  480. $lp = new learnpath(
  481. api_get_course_id(),
  482. $lp_id,
  483. api_get_user_id()
  484. );
  485. $path = $lp->get_preview_image_path(ICON_SIZE_BIG);
  486. $add = $lp->is_lp_visible_for_student(
  487. $lp_id,
  488. api_get_user_id(),
  489. api_get_course_id(),
  490. api_get_session_id()
  491. );
  492. if ($path) {
  493. $temp_row['custom_image'] = $path;
  494. }
  495. }
  496. if ($add) {
  497. $all_tools_list[] = $temp_row;
  498. }
  499. }
  500. // Grabbing all the links that have the property on_homepage set to 1
  501. $course_link_table = Database::get_course_table(TABLE_LINK);
  502. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  503. $condition_session = api_get_session_condition($session_id, true, true, 'tip.session_id');
  504. switch ($course_tool_category) {
  505. case TOOL_AUTHORING:
  506. $sql_links = "SELECT tl.*, tip.visibility
  507. FROM $course_link_table tl
  508. LEFT JOIN $course_item_property_table tip
  509. ON tip.tool='link' AND tip.ref=tl.id
  510. WHERE
  511. tl.c_id = $course_id AND
  512. tip.c_id = $course_id AND
  513. tl.on_homepage='1' $condition_session";
  514. break;
  515. case TOOL_INTERACTION:
  516. $sql_links = null;
  517. /*
  518. $sql_links = "SELECT tl.*, tip.visibility
  519. FROM $course_link_table tl
  520. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  521. WHERE tl.on_homepage='1' ";
  522. */
  523. break;
  524. case TOOL_STUDENT_VIEW:
  525. $sql_links = "SELECT tl.*, tip.visibility
  526. FROM $course_link_table tl
  527. LEFT JOIN $course_item_property_table tip
  528. ON tip.tool='link' AND tip.ref=tl.id
  529. WHERE
  530. tl.c_id = $course_id AND
  531. tip.c_id = $course_id AND
  532. tl.on_homepage ='1' $condition_session";
  533. break;
  534. case TOOL_ADMIN:
  535. $sql_links = "SELECT tl.*, tip.visibility
  536. FROM $course_link_table tl
  537. LEFT JOIN $course_item_property_table tip
  538. ON tip.tool='link' AND tip.ref=tl.id
  539. WHERE
  540. tl.c_id = $course_id AND
  541. tip.c_id = $course_id AND
  542. tl.on_homepage='1' $condition_session";
  543. break;
  544. default:
  545. $sql_links = null;
  546. break;
  547. }
  548. // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
  549. if ($sql_links != null) {
  550. $result_links = Database::query($sql_links);
  551. if (Database::num_rows($result_links) > 0) {
  552. while ($links_row = Database::fetch_array($result_links, 'ASSOC')) {
  553. $properties = array();
  554. $properties['name'] = $links_row['title'];
  555. $properties['session_id'] = $links_row['session_id'];
  556. $properties['link'] = $links_row['url'];
  557. $properties['visibility'] = $links_row['visibility'];
  558. $properties['image'] = $links_row['visibility'] == '0' ? 'file_html.png' : 'file_html.png';
  559. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  560. $properties['target'] = $links_row['target'];
  561. $tmp_all_tools_list[] = $properties;
  562. }
  563. }
  564. }
  565. if (isset($tmp_all_tools_list)) {
  566. foreach ($tmp_all_tools_list as $tool) {
  567. if ($tool['image'] == 'blog.gif') {
  568. // Init
  569. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  570. // Get blog id
  571. $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
  572. // Get blog members
  573. if ($is_platform_admin) {
  574. $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
  575. WHERE blog_id =".$blog_id;
  576. } else {
  577. $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
  578. WHERE blog_id =".$blog_id." AND user_id = ".api_get_user_id();
  579. }
  580. $result_blogs = Database::query($sql_blogs);
  581. if (Database::num_rows($result_blogs) > 0) {
  582. $all_tools_list[] = $tool;
  583. }
  584. } else {
  585. $all_tools_list[] = $tool;
  586. }
  587. }
  588. }
  589. return $all_tools_list;
  590. }
  591. /**
  592. * Displays the tools of a certain category.
  593. * @param array $all_tools_list List of tools as returned by get_tools_category()
  594. * @param bool $rows
  595. *
  596. * @return void
  597. */
  598. public static function show_tools_category($all_tools_list, $rows = false)
  599. {
  600. $_user = api_get_user_info();
  601. $theme = api_get_setting('homepage_view');
  602. if ($theme == 'vertical_activity') {
  603. //ordering by get_lang name
  604. $order_tool_list = array();
  605. if (is_array($all_tools_list) && count($all_tools_list) > 0) {
  606. foreach ($all_tools_list as $key => $new_tool) {
  607. $tool_name = self::translate_tool_name($new_tool);
  608. $order_tool_list [$key] = $tool_name;
  609. }
  610. natsort($order_tool_list);
  611. $my_temp_tool_array = array();
  612. foreach ($order_tool_list as $key => $new_tool) {
  613. $my_temp_tool_array[] = $all_tools_list[$key];
  614. }
  615. $all_tools_list = $my_temp_tool_array;
  616. } else {
  617. $all_tools_list = array();
  618. }
  619. }
  620. $web_code_path = api_get_path(WEB_CODE_PATH);
  621. $session_id = api_get_session_id();
  622. $is_platform_admin = api_is_platform_admin();
  623. if ($session_id == 0 ) {
  624. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin();
  625. } else {
  626. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach();
  627. }
  628. $i = 0;
  629. $items = array();
  630. $app_plugin = new AppPlugin();
  631. if (isset($all_tools_list)) {
  632. $lnk = '';
  633. foreach ($all_tools_list as & $tool) {
  634. $item = array();
  635. $studentview = false;
  636. $tool['original_link'] = $tool['link'];
  637. if ($tool['image'] == 'scormbuilder.gif') {
  638. // check if the published learnpath is visible for student
  639. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  640. if (api_is_allowed_to_edit(null, true)) {
  641. $studentview = true;
  642. }
  643. if (!api_is_allowed_to_edit(null, true) &&
  644. !learnpath::is_lp_visible_for_student(
  645. $published_lp_id,
  646. api_get_user_id(),
  647. api_get_course_id(),
  648. api_get_session_id()
  649. )
  650. ) {
  651. continue;
  652. }
  653. }
  654. if ($session_id != 0 && in_array($tool['name'], array('course_setting'))) {
  655. continue;
  656. }
  657. // This part displays the links to hide or remove a tool.
  658. // These links are only visible by the course manager.
  659. unset($lnk);
  660. $item['extra'] = null;
  661. $toolAdmin = isset($tool['admin']) ? $tool['admin'] : '';
  662. if ($is_allowed_to_edit) {
  663. if (empty($session_id)) {
  664. if (isset($tool['id'])) {
  665. if ($tool['visibility'] == '1' && $toolAdmin != '1') {
  666. $link['name'] = Display::return_icon(
  667. 'visible.png',
  668. get_lang('Deactivate'),
  669. array('id' => 'linktool_'.$tool['id']),
  670. ICON_SIZE_SMALL,
  671. false
  672. );
  673. $link['cmd'] = 'hide=yes';
  674. $lnk[] = $link;
  675. }
  676. if ($tool['visibility'] == '0' && $toolAdmin != '1') {
  677. $link['name'] = Display::return_icon(
  678. 'invisible.png',
  679. get_lang('Activate'),
  680. array('id' => 'linktool_'.$tool['id']),
  681. ICON_SIZE_SMALL,
  682. false
  683. );
  684. $link['cmd'] = 'restore=yes';
  685. $lnk[] = $link;
  686. }
  687. }
  688. }
  689. if (!empty($tool['adminlink'])) {
  690. $item['extra'] = '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  691. }
  692. }
  693. // Both checks are necessary as is_platform_admin doesn't take student view into account
  694. if ($is_platform_admin && $is_allowed_to_edit) {
  695. if ($toolAdmin != '1') {
  696. $link['cmd'] = 'hide=yes';
  697. }
  698. }
  699. $item['visibility'] = null;
  700. if (isset($lnk) && is_array($lnk)) {
  701. foreach ($lnk as $this_link) {
  702. if (empty($tool['adminlink'])) {
  703. $item['visibility'] .= '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$tool['id'].'&amp;'.$this_link['cmd'].'">'.
  704. $this_link['name'].'</a>';
  705. }
  706. }
  707. } else {
  708. $item['visibility'] .= '';
  709. }
  710. // NOTE : Table contains only the image file name, not full path
  711. if (stripos($tool['link'], 'http://') === false &&
  712. stripos($tool['link'], 'https://') === false &&
  713. stripos($tool['link'], 'ftp://') === false
  714. ) {
  715. $tool['link'] = $web_code_path.$tool['link'];
  716. }
  717. if ($tool['visibility'] == '0' && $toolAdmin != '1') {
  718. $class = 'invisible';
  719. $info = pathinfo($tool['image']);
  720. $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
  721. $tool['image'] = $basename.'_na.'.$info['extension'];
  722. } else {
  723. $class = '';
  724. }
  725. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
  726. // If it's a link, we don't add the cidReq
  727. if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') {
  728. $tool['link'] = $tool['link'].$qm_or_amp;
  729. } else {
  730. $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
  731. }
  732. $tool_link_params = array();
  733. $toolId = isset($tool["id"]) ? $tool["id"] : null;
  734. //@todo this visio stuff should be removed
  735. if (strpos($tool['name'], 'visio_') !== false) {
  736. $tool_link_params = array(
  737. 'id' => 'tooldesc_'.$toolId,
  738. 'href' => '"javascript: void(0);"',
  739. 'class' => $class,
  740. 'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_visio'.$_SESSION['_cid'].'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')',
  741. 'target' => $tool['target']
  742. );
  743. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  744. $tool_link_params = array(
  745. 'id' => 'tooldesc_'.$toolId,
  746. 'class' => $class,
  747. 'href' => 'javascript: void(0);',
  748. 'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', //Chat Open Windows
  749. 'target' => $tool['target']
  750. );
  751. } else {
  752. if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) {
  753. $tool_link_params = array(
  754. 'id' => 'tooldesc_'.$toolId,
  755. 'href' => $tool['link'],
  756. 'class' => $class,
  757. 'target' => '_blank'
  758. );
  759. } else {
  760. $tool_link_params = array(
  761. 'id' => 'tooldesc_'.$toolId,
  762. 'href' => $tool['link'],
  763. 'class' => $class,
  764. 'target' => $tool['target']
  765. );
  766. }
  767. }
  768. $tool_name = self::translate_tool_name($tool);
  769. // Including Courses Plugins
  770. // Creating title and the link
  771. if (isset($tool['category']) && $tool['category'] == 'plugin') {
  772. $plugin_info = $app_plugin->getPluginInfo($tool['name']);
  773. if (isset($plugin_info) && isset($plugin_info['title'])) {
  774. $tool_name = $plugin_info['title'];
  775. }
  776. if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) &&
  777. !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/64/'.$tool['image'])) {
  778. $tool['image'] = 'plugins.png';
  779. }
  780. $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH).$tool['original_link'].'?'.api_get_cidreq();
  781. }
  782. $icon = Display::return_icon(
  783. $tool['image'],
  784. $tool_name,
  785. array('class' => 'tool-icon', 'id' => 'toolimage_'.$toolId),
  786. ICON_SIZE_BIG,
  787. false
  788. );
  789. /*if (!empty($tool['custom_icon'])) {
  790. $image = self::getCustomWebIconPath().$tool['custom_icon'];
  791. $icon = Display::img(
  792. $image,
  793. $tool['description'],
  794. array(
  795. 'class' => 'tool-icon',
  796. 'id' => 'toolimage_'.$tool['id']
  797. )
  798. );
  799. }*/
  800. // Validation when belongs to a session
  801. $session_img = api_get_session_image($tool['session_id'], (!empty($_user['status']) ? $_user['status'] : ''));
  802. if ($studentview) {
  803. $tool_link_params['href'] .= '&isStudentView=true';
  804. }
  805. $item['url_params'] = $tool_link_params;
  806. $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params);
  807. $item['tool'] = $tool;
  808. $item['name'] = $tool_name;
  809. $tool_link_params['id'] = 'is'.$tool_link_params['id'];
  810. $item['link'] = Display::url(
  811. $tool_name.$session_img,
  812. $tool_link_params['href'],
  813. $tool_link_params
  814. );
  815. $items[] = $item;
  816. $i++;
  817. } // end of foreach
  818. }
  819. $i = 0;
  820. $html = '';
  821. if (!empty($items)) {
  822. foreach ($items as $item) {
  823. switch ($theme) {
  824. case 'activity_big':
  825. $data = '';
  826. $html .= '<div class="col-xs-6 col-md-3 course-tool">';
  827. $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png';
  828. $toolId = isset($item['tool']['id']) ? $item['tool']['id'] : null;
  829. if (isset($item['tool']['custom_image'])) {
  830. $original_image = Display::img(
  831. $item['tool']['custom_image'],
  832. $item['name'],
  833. array('id' => 'toolimage_'.$toolId)
  834. );
  835. } elseif (isset($item['tool']['custom_icon']) &&
  836. !empty($item['tool']['custom_icon'])
  837. ) {
  838. $customIcon = $item['tool']['custom_icon'];
  839. if ($item['tool']['visibility'] == '0') {
  840. $fileInfo = pathinfo($item['tool']['custom_icon']);
  841. $customIcon = self::getDisableIcon($item['tool']['custom_icon']);
  842. }
  843. $original_image = Display::img(
  844. self::getCustomWebIconPath().$customIcon,
  845. $item['name'],
  846. array('id' => 'toolimage_'.$toolId)
  847. );
  848. } else {
  849. $original_image = Display::return_icon(
  850. $image,
  851. $item['name'],
  852. array('id' => 'toolimage_'.$toolId),
  853. ICON_SIZE_BIG,
  854. false
  855. );
  856. }
  857. $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']);
  858. $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection
  859. $html .= Display::div('<h4>'.$item['visibility'].$item['extra'].$item['link'].'</h4>', array('class' => 'content'));
  860. $html .= '</div>';
  861. break;
  862. case 'activity':
  863. $html .= '<div class="offset2 col-md-4 course-tool">';
  864. $html .= $item['extra'];
  865. $html .= $item['visibility'];
  866. $html .= $item['icon'];
  867. $html .= $item['link'];
  868. $html .= '</div>';
  869. break;
  870. case 'vertical_activity':
  871. if ($i == 0) {
  872. $html .= '<ul>';
  873. }
  874. $html .= '<li class="course-tool">';
  875. $html .= $item['extra'];
  876. $html .= $item['visibility'];
  877. $html .= $item['icon'];
  878. $html .= $item['link'];
  879. $html .= '</li>';
  880. if ($i == count($items) - 1) {
  881. $html .= '</ul>';
  882. }
  883. break;
  884. }
  885. $i++;
  886. }
  887. }
  888. return $html;
  889. }
  890. /**
  891. * Shows the general data for a particular meeting
  892. *
  893. * @param id session id
  894. * @return string session data
  895. */
  896. public static function show_session_data($id_session)
  897. {
  898. $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  899. $sessionInfo = api_get_session_info($id_session);
  900. if (empty($sessionInfo)) {
  901. return '';
  902. }
  903. $sql = 'SELECT name FROM '.$session_category_table.'
  904. WHERE id = "'.intval($sessionInfo['session_category_id']).'"';
  905. $rs_category = Database::query($sql);
  906. $session_category = '';
  907. if (Database::num_rows($rs_category) > 0) {
  908. $rows_session_category = Database::store_result($rs_category);
  909. $rows_session_category = $rows_session_category[0];
  910. $session_category = $rows_session_category['name'];
  911. }
  912. $coachInfo = api_get_user_info($sessionInfo['id_coach']);
  913. $output = '';
  914. if (!empty($session_category)) {
  915. $output .= '<tr><td>'.get_lang('SessionCategory').': '.'<b>'.$session_category.'</b></td></tr>';
  916. }
  917. $dateInfo = SessionManager::parseSessionDates($sessionInfo);
  918. $msgDate = $dateInfo['access'];
  919. $output .= '<tr>
  920. <td style="width:50%">'.get_lang('SessionName').': '.'<b>'.$sessionInfo['name'].'</b></td>
  921. <td>'.get_lang('GeneralCoach').': '.'<b>'.$coachInfo['complete_name'].'</b></td></tr>';
  922. $output .= '<tr>
  923. <td>'.get_lang('SessionIdentifier').': '.
  924. Display::return_icon('star.png', ' ', array('align' => 'absmiddle')).'
  925. </td>
  926. <td>'.get_lang('Date').': '.'<b>'.$msgDate.'</b>
  927. </td>
  928. </tr>';
  929. return $output;
  930. }
  931. /**
  932. * Retrieves the name-field within a tool-record and translates it on necessity.
  933. * @param array $tool The input record.
  934. * @return string Returns the name of the corresponding tool.
  935. */
  936. public static function translate_tool_name(& $tool)
  937. {
  938. static $already_translated_icons = array(
  939. 'file_html.gif',
  940. 'file_html_na.gif',
  941. 'file_html.png',
  942. 'file_html_na.png',
  943. 'scormbuilder.gif',
  944. 'scormbuilder_na.gif',
  945. 'blog.gif',
  946. 'blog_na.gif',
  947. 'external.gif',
  948. 'external_na.gif'
  949. );
  950. $toolName = Security::remove_XSS(stripslashes($tool['name']));
  951. if (in_array($tool['image'], $already_translated_icons)) {
  952. return $toolName;
  953. }
  954. $toolName = api_underscore_to_camel_case($toolName);
  955. if (isset($GLOBALS['Tool' . $toolName])) {
  956. return get_lang('Tool' . $toolName);
  957. }
  958. return $toolName;
  959. }
  960. /**
  961. * Get published learning path id from link inside course home
  962. * @param string Link to published lp
  963. * @return int Learning path id
  964. */
  965. public static function get_published_lp_id_from_link($published_lp_link)
  966. {
  967. $lp_id = 0;
  968. $param_lp_id = strstr($published_lp_link, 'lp_id=');
  969. if (!empty($param_lp_id)) {
  970. $a_param_lp_id = explode('=', $param_lp_id);
  971. if (isset($a_param_lp_id[1])) {
  972. $lp_id = intval($a_param_lp_id[1]);
  973. }
  974. }
  975. return $lp_id;
  976. }
  977. /**
  978. * @param bool $include_admin_tools
  979. * @return array
  980. */
  981. public static function get_navigation_items($include_admin_tools = false)
  982. {
  983. $navigation_items = array();
  984. $course_id = api_get_course_int_id();
  985. $courseInfo = api_get_course_info();
  986. $sessionId = api_get_session_id();
  987. if (!empty($course_id)) {
  988. $course_tools_table = Database :: get_course_table(TABLE_TOOL_LIST);
  989. /* Link to the Course homepage */
  990. $navigation_items['home']['image'] = 'home.gif';
  991. $navigation_items['home']['link'] = $courseInfo['course_public_url'];
  992. $navigation_items['home']['name'] = get_lang('CourseHomepageLink');
  993. $sql_menu_query = "SELECT * FROM $course_tools_table
  994. WHERE c_id = $course_id AND visibility='1' and admin='0'
  995. ORDER BY id ASC";
  996. $sql_result = Database::query($sql_menu_query);
  997. while ($row = Database::fetch_array($sql_result)) {
  998. $navigation_items[$row['id']] = $row;
  999. if (stripos($row['link'], 'http://') === false && stripos($row['link'], 'https://') === false) {
  1000. $navigation_items[$row['id']]['link'] = api_get_path(WEB_CODE_PATH).$row['link'];
  1001. $navigation_items[$row['id']]['name'] = CourseHome::translate_tool_name($row);
  1002. }
  1003. }
  1004. /* Admin (edit rights) only links
  1005. - Course settings (course admin only)
  1006. - Course rights (roles & rights overview) */
  1007. if ($include_admin_tools) {
  1008. $sql = "SELECT name,image FROM $course_tools_table
  1009. WHERE c_id = $course_id AND link='course_info/infocours.php'";
  1010. $sql_result = Database::query($sql);
  1011. $course_setting_info = Database::fetch_array($sql_result);
  1012. $course_setting_visual_name = CourseHome::translate_tool_name($course_setting_info);
  1013. if ($sessionId == 0) {
  1014. // course settings item
  1015. $navigation_items['course_settings']['image'] = $course_setting_info['image'];
  1016. $navigation_items['course_settings']['link'] = api_get_path(WEB_CODE_PATH).'course_info/infocours.php';
  1017. $navigation_items['course_settings']['name'] = $course_setting_visual_name;
  1018. }
  1019. }
  1020. }
  1021. foreach ($navigation_items as $key => $navigation_item) {
  1022. if (strstr($navigation_item['link'], '?')) {
  1023. //link already contains a parameter, add course id parameter with &
  1024. $parameter_separator = '&amp;';
  1025. } else {
  1026. //link doesn't contain a parameter yet, add course id parameter with ?
  1027. $parameter_separator = '?';
  1028. }
  1029. //$navigation_items[$key]['link'] .= $parameter_separator.api_get_cidreq();
  1030. $navigation_items[$key]['link'] .= $parameter_separator.'cidReq='.api_get_course_id().'&gidReq=0&id_session='.$sessionId;
  1031. }
  1032. return $navigation_items;
  1033. }
  1034. /**
  1035. * Show a navigation menu
  1036. */
  1037. public static function show_navigation_menu()
  1038. {
  1039. $navigation_items = self::get_navigation_items(true);
  1040. $course_id = api_get_course_id();
  1041. $html = '<div id="toolnav"> <!-- start of #toolnav -->';
  1042. if (api_get_setting('show_navigation_menu') == 'icons') {
  1043. $html .= self::show_navigation_tool_shortcuts($orientation = SHORTCUTS_VERTICAL);
  1044. } else {
  1045. $html .= '<div id="toolnavbox">';
  1046. $html .= '<div id="toolnavlist"><dl>';
  1047. foreach ($navigation_items as $key => $navigation_item) {
  1048. //students can't see the course settings option
  1049. if (!api_is_allowed_to_edit() && $key == 'course_settings') {
  1050. continue;
  1051. }
  1052. $html .= '<dd>';
  1053. $url_item = parse_url($navigation_item['link']);
  1054. $url_current = parse_url($_SERVER['REQUEST_URI']);
  1055. if (strpos($navigation_item['link'], 'chat') !== false &&
  1056. api_get_course_setting('allow_open_chat_window', $course_id)
  1057. ) {
  1058. $html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$navigation_item['target'].'"';
  1059. } else {
  1060. $html .= '<a href="'.$navigation_item['link'].'" target="_top" ';
  1061. }
  1062. if (stristr($url_item['path'], $url_current['path'])) {
  1063. if (!isset($_GET['learnpath_id']) || strpos($url_item['query'], 'learnpath_id='.intval($_GET['learnpath_id'])) === 0) {
  1064. $html .= ' id="here"';
  1065. }
  1066. }
  1067. $html .= ' title="'.$navigation_item['name'].'">';
  1068. if (api_get_setting('show_navigation_menu') != 'text') {
  1069. $html .= '<div align="left"><img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/></div>';
  1070. }
  1071. if (api_get_setting('show_navigation_menu') != 'icons') {
  1072. $html .= $navigation_item['name'];
  1073. }
  1074. $html .= '</a>';
  1075. $html .= '</dd>';
  1076. }
  1077. $html .= '</dl></div></div>';
  1078. }
  1079. $html .= '</div><!-- end "#toolnav" -->';
  1080. return $html;
  1081. }
  1082. /**
  1083. * Show a toolbar with shortcuts to the course tool
  1084. */
  1085. public static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL)
  1086. {
  1087. $navigation_items = self::get_navigation_items(false);
  1088. $html = '';
  1089. if (!empty($navigation_items)) {
  1090. if ($orientation == SHORTCUTS_HORIZONTAL) {
  1091. $style_id = "toolshortcuts_horizontal";
  1092. } else {
  1093. $style_id = "toolshortcuts_vertical";
  1094. }
  1095. $html .= '<div id="'.$style_id.'">';
  1096. foreach ($navigation_items as $key => $navigation_item) {
  1097. if (strpos($navigation_item['link'], 'chat') !== false &&
  1098. api_get_course_setting('allow_open_chat_window')
  1099. ) {
  1100. $html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$navigation_item['target'].'"';
  1101. } else {
  1102. $html .= '<a href="'.$navigation_item['link'].'"';
  1103. }
  1104. if (strpos(api_get_self(), $navigation_item['link']) !== false) {
  1105. $html .= ' id="here"';
  1106. }
  1107. $html .= ' target="_top" title="'.$navigation_item['name'].'">';
  1108. $html .= '<img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/>';
  1109. $html .= '</a> ';
  1110. if ($orientation == SHORTCUTS_VERTICAL) {
  1111. $html .= '<br />';
  1112. }
  1113. }
  1114. $html .= '</div>';
  1115. }
  1116. return $html;
  1117. }
  1118. /**
  1119. * List course homepage tools from authoring and interaction sections
  1120. * @param int $courseId The course ID (guessed from context if not provided)
  1121. * @param int $sessionId The session ID (guessed from context if not provided)
  1122. * @return array List of all tools data from the c_tools table
  1123. */
  1124. public static function toolsIconsAction($courseId = null, $sessionId = null)
  1125. {
  1126. if (empty($courseId)) {
  1127. $courseId = api_get_course_int_id();
  1128. } else {
  1129. $courseId = intval($courseId);
  1130. }
  1131. if (empty($sessionId)) {
  1132. $sessionId = api_get_session_id();
  1133. } else {
  1134. $sessionId = intval($sessionId);
  1135. }
  1136. if (empty($courseId)) {
  1137. // We shouldn't get here, but for some reason api_get_course_int_id()
  1138. // doesn't seem to get the course from the context, sometimes
  1139. return array();
  1140. }
  1141. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1142. $sql = "SELECT * FROM $table
  1143. WHERE category in ('authoring','interaction')
  1144. AND c_id = $courseId
  1145. AND session_id = $sessionId
  1146. ORDER BY id";
  1147. $result = Database::query($sql);
  1148. $data = Database::store_result($result, 'ASSOC');
  1149. return $data;
  1150. }
  1151. /**
  1152. * @param int $editIcon
  1153. * @return array
  1154. */
  1155. public static function getTool($editIcon)
  1156. {
  1157. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  1158. $editIcon = intval($editIcon);
  1159. $sql = "SELECT * FROM $course_tool_table
  1160. WHERE iid = $editIcon";
  1161. $result = Database::query($sql);
  1162. $tool = Database::fetch_assoc($result, 'ASSOC');
  1163. return $tool;
  1164. }
  1165. /**
  1166. * @return string
  1167. */
  1168. public static function getCustomSysIconPath()
  1169. {
  1170. // Check if directory exists or create it if it doesn't
  1171. $dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
  1172. if (!is_dir($dir)) {
  1173. mkdir($dir, api_get_permissions_for_new_directories(), true);
  1174. }
  1175. return $dir;
  1176. }
  1177. /**
  1178. * @return string
  1179. */
  1180. public static function getCustomWebIconPath()
  1181. {
  1182. // Check if directory exists or create it if it doesn't
  1183. $dir = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
  1184. return $dir;
  1185. }
  1186. /**
  1187. * @param string $icon
  1188. * @return string
  1189. */
  1190. public static function getDisableIcon($icon)
  1191. {
  1192. $fileInfo = pathinfo($icon);
  1193. return $fileInfo['filename'].'_na.'.$fileInfo['extension'];
  1194. }
  1195. /**
  1196. * @param int $id
  1197. * @param array $values
  1198. */
  1199. public static function updateTool($id, $values)
  1200. {
  1201. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1202. $params = [
  1203. 'name' => $values['name'],
  1204. 'link' => $values['link'],
  1205. 'target' => $values['target'],
  1206. 'visibility' => $values['visibility'],
  1207. 'description' => $values['description'],
  1208. ];
  1209. if (isset($_FILES['icon']['size']) && $_FILES['icon']['size'] !== 0) {
  1210. $dir = self::getCustomSysIconPath();
  1211. // Resize image if it is larger than 64px
  1212. $temp = new Image($_FILES['icon']['tmp_name']);
  1213. $picture_infos = $temp->get_image_info();
  1214. if ($picture_infos['width'] > 64) {
  1215. $thumbwidth = 64;
  1216. } else {
  1217. $thumbwidth = $picture_infos['width'];
  1218. }
  1219. if ($picture_infos['height'] > 64) {
  1220. $new_height = 64;
  1221. } else {
  1222. $new_height = $picture_infos['height'];
  1223. }
  1224. $temp->resize($thumbwidth, $new_height, 0);
  1225. //copy the image to the course upload folder
  1226. $path = $dir.$_FILES['icon']['name'];
  1227. $result = $temp->send_image($path);
  1228. $temp = new Image($path);
  1229. $r = $temp->convert2bw();
  1230. $ext = pathinfo($path, PATHINFO_EXTENSION);
  1231. $bwPath = substr($path,0,-(strlen($ext)+1)) . '_na.' . $ext;
  1232. if ($r === false) {
  1233. error_log('Conversion to B&W of '.$path.' failed in '.__FILE__.' at line '.__LINE__);
  1234. } else {
  1235. $temp->send_image($bwPath);
  1236. $iconName = $_FILES['icon']['name'];
  1237. $params['custom_icon'] = $iconName;
  1238. }
  1239. }
  1240. Database::update(
  1241. $table,
  1242. $params,
  1243. [' iid = ?' => [$id]]
  1244. );
  1245. }
  1246. /**
  1247. * @param int $id
  1248. */
  1249. public static function deleteIcon($id)
  1250. {
  1251. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1252. $tool = self::getTool($id);
  1253. if ($tool && !empty($tool['custom_icon'])) {
  1254. $file = self::getCustomSysIconPath().$tool['custom_icon'];
  1255. $fileInfo = pathinfo($file);
  1256. $fileGray = $fileInfo['filename'].'_na.'.$fileInfo['extension'];
  1257. $fileGray = self::getCustomSysIconPath().$fileGray;
  1258. if (file_exists($file) && is_file($file)) {
  1259. if (Security::check_abs_path($file, self::getCustomSysIconPath())) {
  1260. unlink($file);
  1261. }
  1262. }
  1263. if (file_exists($fileGray) && is_file($fileGray)) {
  1264. if (Security::check_abs_path($fileGray, self::getCustomSysIconPath())) {
  1265. unlink($fileGray);
  1266. }
  1267. }
  1268. $params = [
  1269. 'custom_icon' => '',
  1270. ];
  1271. Database::update(
  1272. $table,
  1273. $params,
  1274. [' iid = ?' => [$id]]
  1275. );
  1276. }
  1277. }
  1278. }