course_home.lib.php 65 KB

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