course_home.lib.php 72 KB

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