course_home.lib.php 74 KB

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