course_home.lib.php 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826
  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_info(),
  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_info(),
  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. $tblLpCategory = Database::get_course_table(TABLE_LP_CATEGORY);
  481. $orderBy = ' ORDER BY id ';
  482. switch ($course_tool_category) {
  483. case TOOL_STUDENT_VIEW:
  484. $conditions = ' WHERE visibility = 1 AND
  485. (category = "authoring" OR category = "interaction" OR category = "plugin") AND
  486. t.name <> "notebookteacher" ';
  487. if ((api_is_coach() || api_is_course_tutor() || api_is_platform_admin()) &&
  488. $_SESSION['studentview'] != 'studentview'
  489. ) {
  490. $conditions = ' WHERE (
  491. visibility = 1 AND (
  492. category = "authoring" OR
  493. category = "interaction" OR
  494. category = "plugin"
  495. ) OR (t.name = "'.TOOL_TRACKING.'")
  496. )';
  497. }
  498. // Add order if there are LPs
  499. $sql = "SELECT t.* FROM $course_tool_table t
  500. LEFT JOIN $lpTable l
  501. ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%'))
  502. LEFT JOIN $tblLpCategory lc
  503. ON (t.c_id = lc.c_id AND l.category_id = lc.iid)
  504. $conditions AND
  505. t.c_id = $course_id $condition_session
  506. ORDER BY
  507. CASE WHEN l.category_id IS NULL THEN 0 ELSE 1 END,
  508. CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END,
  509. lc.position,
  510. l.display_order,
  511. t.id";
  512. $orderBy = '';
  513. break;
  514. case TOOL_AUTHORING:
  515. $sql = "SELECT t.* FROM $course_tool_table t
  516. LEFT JOIN $lpTable l
  517. ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%'))
  518. LEFT JOIN $tblLpCategory lc
  519. ON (t.c_id = lc.c_id AND l.category_id = lc.iid)
  520. WHERE
  521. category = 'authoring' AND t.c_id = $course_id $condition_session
  522. ORDER BY
  523. CASE WHEN l.category_id IS NULL THEN 0 ELSE 1 END,
  524. CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END,
  525. lc.position,
  526. l.display_order,
  527. t.id";
  528. $orderBy = '';
  529. break;
  530. case TOOL_INTERACTION:
  531. $sql = "SELECT * FROM $course_tool_table t
  532. WHERE category = 'interaction' AND c_id = $course_id $condition_session
  533. ";
  534. break;
  535. case TOOL_ADMIN_VISIBLE:
  536. $sql = "SELECT * FROM $course_tool_table t
  537. WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session
  538. ";
  539. break;
  540. case TOOL_ADMIN_PLATFORM:
  541. $sql = "SELECT * FROM $course_tool_table t
  542. WHERE category = 'admin' AND c_id = $course_id $condition_session
  543. ";
  544. break;
  545. case TOOL_DRH:
  546. $sql = "SELECT * FROM $course_tool_table t
  547. WHERE t.name IN ('tracking') AND c_id = $course_id $condition_session
  548. ";
  549. break;
  550. case TOOL_COURSE_PLUGIN:
  551. //Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id
  552. // but plugins are not present in the tool table, only globally and inside the course_settings table once configured
  553. $sql = "SELECT * FROM $course_tool_table t
  554. WHERE category = 'plugin' AND name <> 'courseblock' AND c_id = $course_id $condition_session
  555. ";
  556. break;
  557. }
  558. $sql .= $orderBy;
  559. $result = Database::query($sql);
  560. $tools = [];
  561. while ($row = Database::fetch_assoc($result)) {
  562. $tools[] = $row;
  563. }
  564. // Get the list of hidden tools - this might imply performance slowdowns
  565. // if the course homepage is loaded many times, so the list of hidden
  566. // tools might benefit from a shared memory storage later on
  567. $list = api_get_settings('Tools', 'list', api_get_current_access_url_id());
  568. $hide_list = [];
  569. $check = false;
  570. foreach ($list as $line) {
  571. // Admin can see all tools even if the course_hide_tools configuration is set
  572. if ($is_platform_admin) {
  573. continue;
  574. }
  575. if ($line['variable'] == 'course_hide_tools' && $line['selected_value'] == 'true') {
  576. $hide_list[] = $line['subkey'];
  577. $check = true;
  578. }
  579. }
  580. $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session');
  581. // If exists same tool (by name) from session in base course then avoid it. Allow them pass in other cases
  582. $tools = array_filter($tools, function (array $toolToFilter) use ($sessionId, $tools) {
  583. if (!empty($toolToFilter['session_id'])) {
  584. foreach ($tools as $originalTool) {
  585. if ($toolToFilter['name'] == $originalTool['name'] && empty($originalTool['session_id'])) {
  586. return false;
  587. }
  588. }
  589. }
  590. return true;
  591. });
  592. foreach ($tools as $temp_row) {
  593. $add = false;
  594. if ($check) {
  595. if (!in_array($temp_row['name'], $hide_list)) {
  596. $add = true;
  597. }
  598. } else {
  599. $add = true;
  600. }
  601. if ($allowEditionInSession && !empty($sessionId)) {
  602. // Checking if exist row in session
  603. $criteria = [
  604. 'cId' => $course_id,
  605. 'name' => $temp_row['name'],
  606. 'sessionId' => $sessionId,
  607. ];
  608. /** @var CTool $toolObj */
  609. $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria);
  610. if ($toolObj) {
  611. if (api_is_allowed_to_edit() == false && $toolObj->getVisibility() == false) {
  612. continue;
  613. }
  614. }
  615. }
  616. switch ($temp_row['image']) {
  617. case 'scormbuilder.gif':
  618. $lpId = self::getPublishedLpIdFromLink($temp_row['link']);
  619. $lp = new learnpath(
  620. $courseInfo['code'],
  621. $lpId,
  622. $userId
  623. );
  624. $path = $lp->get_preview_image_path(ICON_SIZE_BIG);
  625. if (api_is_allowed_to_edit(null, true)) {
  626. $add = true;
  627. } else {
  628. $add = learnpath::is_lp_visible_for_student(
  629. $lpId,
  630. $userId,
  631. $courseInfo,
  632. $sessionId
  633. );
  634. }
  635. if ($path) {
  636. $temp_row['custom_image'] = $path;
  637. }
  638. break;
  639. case 'lp_category.gif':
  640. $lpCategory = self::getPublishedLpCategoryFromLink(
  641. $temp_row['link']
  642. );
  643. $add = learnpath::categoryIsVisibleForStudent(
  644. $lpCategory,
  645. $user
  646. );
  647. break;
  648. }
  649. if ($add) {
  650. $all_tools_list[] = $temp_row;
  651. }
  652. }
  653. // Grabbing all the links that have the property on_homepage set to 1
  654. $course_link_table = Database::get_course_table(TABLE_LINK);
  655. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  656. $condition_session = api_get_session_condition(
  657. $sessionId,
  658. true,
  659. true,
  660. 'tip.session_id'
  661. );
  662. switch ($course_tool_category) {
  663. case TOOL_AUTHORING:
  664. $sql_links = "SELECT tl.*, tip.visibility
  665. FROM $course_link_table tl
  666. LEFT JOIN $course_item_property_table tip
  667. ON tip.tool='link' AND tip.ref=tl.id
  668. WHERE
  669. tl.c_id = $course_id AND
  670. tip.c_id = $course_id AND
  671. tl.on_homepage='1' $condition_session";
  672. break;
  673. case TOOL_INTERACTION:
  674. $sql_links = null;
  675. /*
  676. $sql_links = "SELECT tl.*, tip.visibility
  677. FROM $course_link_table tl
  678. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  679. WHERE tl.on_homepage='1' ";
  680. */
  681. break;
  682. case TOOL_STUDENT_VIEW:
  683. $sql_links = "SELECT tl.*, tip.visibility
  684. FROM $course_link_table tl
  685. LEFT JOIN $course_item_property_table tip
  686. ON tip.tool='link' AND tip.ref=tl.id
  687. WHERE
  688. tl.c_id = $course_id AND
  689. tip.c_id = $course_id AND
  690. tl.on_homepage ='1' $condition_session";
  691. break;
  692. case TOOL_ADMIN:
  693. $sql_links = "SELECT tl.*, tip.visibility
  694. FROM $course_link_table tl
  695. LEFT JOIN $course_item_property_table tip
  696. ON tip.tool='link' AND tip.ref=tl.id
  697. WHERE
  698. tl.c_id = $course_id AND
  699. tip.c_id = $course_id AND
  700. tl.on_homepage='1' $condition_session";
  701. break;
  702. default:
  703. $sql_links = null;
  704. break;
  705. }
  706. // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
  707. if ($sql_links != null) {
  708. $result_links = Database::query($sql_links);
  709. if (Database::num_rows($result_links) > 0) {
  710. while ($links_row = Database::fetch_array($result_links, 'ASSOC')) {
  711. $properties = [];
  712. $properties['name'] = $links_row['title'];
  713. $properties['session_id'] = $links_row['session_id'];
  714. $properties['link'] = $links_row['url'];
  715. $properties['visibility'] = $links_row['visibility'];
  716. $properties['image'] = $links_row['visibility'] == '0' ? 'file_html.png' : 'file_html.png';
  717. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  718. $properties['target'] = $links_row['target'];
  719. $tmp_all_tools_list[] = $properties;
  720. }
  721. }
  722. }
  723. if (isset($tmp_all_tools_list)) {
  724. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  725. foreach ($tmp_all_tools_list as $tool) {
  726. if ($tool['image'] == 'blog.gif') {
  727. // Get blog id
  728. $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
  729. // Get blog members
  730. if ($is_platform_admin) {
  731. $sql = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
  732. WHERE blog_id = ".$blog_id;
  733. } else {
  734. $sql = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
  735. WHERE blog_id = ".$blog_id." AND user_id = ".$userId;
  736. }
  737. $result = Database::query($sql);
  738. if (Database::num_rows($result) > 0) {
  739. $all_tools_list[] = $tool;
  740. }
  741. } else {
  742. $all_tools_list[] = $tool;
  743. }
  744. }
  745. }
  746. $list = self::filterPluginTools($all_tools_list, $course_tool_category);
  747. return $list;
  748. }
  749. /**
  750. * Displays the tools of a certain category.
  751. *
  752. * @param array $all_tools_list List of tools as returned by get_tools_category()
  753. *
  754. * @return array
  755. */
  756. public static function show_tools_category($all_tools_list)
  757. {
  758. $_user = api_get_user_info();
  759. $theme = api_get_setting('homepage_view');
  760. if ($theme === 'vertical_activity') {
  761. //ordering by get_lang name
  762. $order_tool_list = [];
  763. if (is_array($all_tools_list) && count($all_tools_list) > 0) {
  764. foreach ($all_tools_list as $key => $new_tool) {
  765. $tool_name = self::translate_tool_name($new_tool);
  766. $order_tool_list[$key] = $tool_name;
  767. }
  768. natsort($order_tool_list);
  769. $my_temp_tool_array = [];
  770. foreach ($order_tool_list as $key => $new_tool) {
  771. $my_temp_tool_array[] = $all_tools_list[$key];
  772. }
  773. $all_tools_list = $my_temp_tool_array;
  774. } else {
  775. $all_tools_list = [];
  776. }
  777. }
  778. $web_code_path = api_get_path(WEB_CODE_PATH);
  779. $session_id = api_get_session_id();
  780. $is_platform_admin = api_is_platform_admin();
  781. $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session');
  782. if ($session_id == 0) {
  783. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin();
  784. } else {
  785. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach();
  786. if ($allowEditionInSession) {
  787. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_coach($session_id, api_get_course_int_id());
  788. }
  789. }
  790. $items = [];
  791. $app_plugin = new AppPlugin();
  792. if (isset($all_tools_list)) {
  793. $lnk = '';
  794. foreach ($all_tools_list as &$tool) {
  795. $item = [];
  796. $studentview = false;
  797. $tool['original_link'] = $tool['link'];
  798. if ($tool['image'] == 'scormbuilder.gif') {
  799. // Check if the published learnpath is visible for student
  800. $lpId = self::getPublishedLpIdFromLink($tool['link']);
  801. if (api_is_allowed_to_edit(null, true)) {
  802. $studentview = true;
  803. }
  804. if (!api_is_allowed_to_edit(null, true) &&
  805. !learnpath::is_lp_visible_for_student(
  806. $lpId,
  807. api_get_user_id(),
  808. api_get_course_info(),
  809. api_get_session_id()
  810. )
  811. ) {
  812. continue;
  813. }
  814. }
  815. if ($session_id != 0 && in_array($tool['name'], ['course_setting'])) {
  816. continue;
  817. }
  818. // This part displays the links to hide or remove a tool.
  819. // These links are only visible by the course manager.
  820. unset($lnk);
  821. $item['extra'] = null;
  822. $toolAdmin = isset($tool['admin']) ? $tool['admin'] : '';
  823. if ($is_allowed_to_edit) {
  824. if (empty($session_id)) {
  825. if (isset($tool['id'])) {
  826. if ($tool['visibility'] == '1' && $toolAdmin != '1') {
  827. $link['name'] = Display::return_icon(
  828. 'visible.png',
  829. get_lang('Deactivate'),
  830. ['id' => 'linktool_'.$tool['iid']],
  831. ICON_SIZE_SMALL,
  832. false
  833. );
  834. $link['cmd'] = 'hide=yes';
  835. $lnk[] = $link;
  836. }
  837. if ($tool['visibility'] == '0' && $toolAdmin != '1') {
  838. $link['name'] = Display::return_icon(
  839. 'invisible.png',
  840. get_lang('Activate'),
  841. ['id' => 'linktool_'.$tool['iid']],
  842. ICON_SIZE_SMALL,
  843. false
  844. );
  845. $link['cmd'] = 'restore=yes';
  846. $lnk[] = $link;
  847. }
  848. }
  849. } elseif ($allowEditionInSession) {
  850. $criteria = [
  851. 'cId' => api_get_course_int_id(),
  852. 'name' => $tool['name'],
  853. 'sessionId' => $session_id,
  854. ];
  855. /** @var CTool $tool */
  856. $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria);
  857. if ($toolObj) {
  858. $visibility = (int) $toolObj->getVisibility();
  859. switch ($visibility) {
  860. case '0':
  861. $info = pathinfo($tool['image']);
  862. $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
  863. $tool['image'] = $basename.'_na.'.$info['extension'];
  864. $link['name'] = Display::return_icon(
  865. 'invisible.png',
  866. get_lang('Activate'),
  867. ['id' => 'linktool_'.$tool['iid']],
  868. ICON_SIZE_SMALL,
  869. false
  870. );
  871. $link['cmd'] = 'restore=yes';
  872. $lnk[] = $link;
  873. break;
  874. case '1':
  875. $link['name'] = Display::return_icon(
  876. 'visible.png',
  877. get_lang('Deactivate'),
  878. ['id' => 'linktool_'.$tool['iid']],
  879. ICON_SIZE_SMALL,
  880. false
  881. );
  882. $link['cmd'] = 'hide=yes';
  883. $lnk[] = $link;
  884. break;
  885. }
  886. } else {
  887. $link['name'] = Display::return_icon(
  888. 'visible.png',
  889. get_lang('Deactivate'),
  890. ['id' => 'linktool_'.$tool['iid']],
  891. ICON_SIZE_SMALL,
  892. false
  893. );
  894. $link['cmd'] = 'hide=yes';
  895. $lnk[] = $link;
  896. }
  897. }
  898. if (!empty($tool['adminlink'])) {
  899. $item['extra'] = '<a href="'.$tool['adminlink'].'">'.
  900. Display::return_icon('edit.gif', get_lang('Edit')).
  901. '</a>';
  902. }
  903. }
  904. // Both checks are necessary as is_platform_admin doesn't take student view into account
  905. if ($is_platform_admin && $is_allowed_to_edit) {
  906. if ($toolAdmin != '1') {
  907. $link['cmd'] = 'hide=yes';
  908. }
  909. }
  910. $item['visibility'] = null;
  911. if (isset($lnk) && is_array($lnk)) {
  912. foreach ($lnk as $this_link) {
  913. if (empty($tool['adminlink'])) {
  914. $item['visibility'] .=
  915. '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&id='.$tool['iid'].'&'.$this_link['cmd'].'">'.
  916. $this_link['name'].'</a>';
  917. }
  918. }
  919. } else {
  920. $item['visibility'] .= '';
  921. }
  922. // NOTE : Table contains only the image file name, not full path
  923. if (stripos($tool['link'], 'http://') === false &&
  924. stripos($tool['link'], 'https://') === false &&
  925. stripos($tool['link'], 'ftp://') === false
  926. ) {
  927. $tool['link'] = $web_code_path.$tool['link'];
  928. }
  929. $class = '';
  930. if ($tool['visibility'] == '0' && $toolAdmin != '1') {
  931. $class = 'text-muted';
  932. $info = pathinfo($tool['image']);
  933. $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
  934. $tool['image'] = $basename.'_na.'.$info['extension'];
  935. }
  936. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
  937. // If it's a link, we don't add the cidReq
  938. if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') {
  939. $tool['link'] = $tool['link'];
  940. } else {
  941. $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
  942. }
  943. $toolIid = isset($tool['iid']) ? $tool['iid'] : null;
  944. //@todo this visio stuff should be removed
  945. if (strpos($tool['name'], 'visio_') !== false) {
  946. $tool_link_params = [
  947. 'id' => 'tooldesc_'.$toolIid,
  948. 'href' => '"javascript: void(0);"',
  949. 'class' => $class,
  950. '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\')',
  951. 'target' => $tool['target'],
  952. ];
  953. } elseif (strpos($tool['name'], 'chat') !== false &&
  954. api_get_course_setting('allow_open_chat_window')
  955. ) {
  956. $tool_link_params = [
  957. 'id' => 'tooldesc_'.$toolIid,
  958. 'class' => $class,
  959. 'href' => 'javascript: void(0);',
  960. '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
  961. 'target' => $tool['target'],
  962. ];
  963. } else {
  964. $tool_link_params = [
  965. 'id' => 'tooldesc_'.$toolIid,
  966. 'href' => $tool['link'],
  967. 'class' => $class,
  968. 'target' => $tool['target'],
  969. ];
  970. }
  971. $tool_name = self::translate_tool_name($tool);
  972. // Including Courses Plugins
  973. // Creating title and the link
  974. if (isset($tool['category']) && $tool['category'] == 'plugin') {
  975. $plugin_info = $app_plugin->getPluginInfo($tool['name']);
  976. if (isset($plugin_info) && isset($plugin_info['title'])) {
  977. $tool_name = $plugin_info['title'];
  978. }
  979. if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) &&
  980. !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/64/'.$tool['image'])) {
  981. $tool['image'] = 'plugins.png';
  982. }
  983. $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH)
  984. .$tool['original_link'].$qm_or_amp.api_get_cidreq();
  985. }
  986. // Use in the course home
  987. $icon = Display::return_icon(
  988. $tool['image'],
  989. $tool_name,
  990. ['class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid],
  991. ICON_SIZE_BIG,
  992. false
  993. );
  994. // Used in the top bar
  995. $iconMedium = Display::return_icon(
  996. $tool['image'],
  997. $tool_name,
  998. ['class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid],
  999. ICON_SIZE_MEDIUM,
  1000. false
  1001. );
  1002. // Used for vertical navigation
  1003. $iconSmall = Display::return_icon(
  1004. $tool['image'],
  1005. $tool_name,
  1006. ['class' => 'tool-img', 'id' => 'toolimage_'.$toolIid],
  1007. ICON_SIZE_SMALL,
  1008. false
  1009. );
  1010. /*if (!empty($tool['custom_icon'])) {
  1011. $image = self::getCustomWebIconPath().$tool['custom_icon'];
  1012. $icon = Display::img(
  1013. $image,
  1014. $tool['description'],
  1015. array(
  1016. 'class' => 'tool-icon',
  1017. 'id' => 'toolimage_'.$tool['id']
  1018. )
  1019. );
  1020. }*/
  1021. // Validation when belongs to a session
  1022. $session_img = api_get_session_image(
  1023. $tool['session_id'],
  1024. !empty($_user['status']) ? $_user['status'] : ''
  1025. );
  1026. if ($studentview) {
  1027. $tool_link_params['href'] .= '&isStudentView=true';
  1028. }
  1029. $item['url_params'] = $tool_link_params;
  1030. $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params);
  1031. $item['only_icon'] = $icon;
  1032. $item['only_icon_medium'] = $iconMedium;
  1033. $item['only_icon_small'] = $iconSmall;
  1034. $item['only_href'] = $tool_link_params['href'];
  1035. $item['tool'] = $tool;
  1036. $item['name'] = $tool_name;
  1037. $tool_link_params['id'] = 'is'.$tool_link_params['id'];
  1038. $item['link'] = Display::url(
  1039. $tool_name.$session_img,
  1040. $tool_link_params['href'],
  1041. $tool_link_params
  1042. );
  1043. $items[] = $item;
  1044. }
  1045. }
  1046. foreach ($items as &$item) {
  1047. $originalImage = self::getToolIcon($item, ICON_SIZE_BIG);
  1048. $item['tool']['only_icon_medium'] = self::getToolIcon($item, ICON_SIZE_MEDIUM, false);
  1049. $item['tool']['only_icon_small'] = self::getToolIcon($item, ICON_SIZE_SMALL, false);
  1050. if ($theme === 'activity_big') {
  1051. $item['tool']['image'] = Display::url(
  1052. $originalImage,
  1053. $item['url_params']['href'],
  1054. $item['url_params']
  1055. );
  1056. }
  1057. }
  1058. return $items;
  1059. }
  1060. /**
  1061. * Shows the general data for a particular meeting.
  1062. *
  1063. * @param int $id_session
  1064. *
  1065. * @return string session data
  1066. */
  1067. public static function show_session_data($id_session)
  1068. {
  1069. $sessionInfo = api_get_session_info($id_session);
  1070. if (empty($sessionInfo)) {
  1071. return '';
  1072. }
  1073. $table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  1074. $sql = 'SELECT name FROM '.$table.'
  1075. WHERE id = "'.intval($sessionInfo['session_category_id']).'"';
  1076. $rs_category = Database::query($sql);
  1077. $session_category = '';
  1078. if (Database::num_rows($rs_category) > 0) {
  1079. $rows_session_category = Database::store_result($rs_category);
  1080. $rows_session_category = $rows_session_category[0];
  1081. $session_category = $rows_session_category['name'];
  1082. }
  1083. $coachInfo = api_get_user_info($sessionInfo['id_coach']);
  1084. $output = '';
  1085. if (!empty($session_category)) {
  1086. $output .= '<tr><td>'.get_lang('SessionCategory').': '.'<b>'.$session_category.'</b></td></tr>';
  1087. }
  1088. $dateInfo = SessionManager::parseSessionDates($sessionInfo);
  1089. $msgDate = $dateInfo['access'];
  1090. $output .= '<tr>
  1091. <td style="width:50%">'.get_lang('SessionName').': '.'<b>'.$sessionInfo['name'].'</b></td>
  1092. <td>'.get_lang('GeneralCoach').': '.'<b>'.$coachInfo['complete_name'].'</b></td></tr>';
  1093. $output .= '<tr>
  1094. <td>'.get_lang('SessionIdentifier').': '.
  1095. Display::return_icon('star.png', ' ', ['align' => 'absmiddle']).'
  1096. </td>
  1097. <td>'.get_lang('Date').': '.'<b>'.$msgDate.'</b>
  1098. </td>
  1099. </tr>';
  1100. return $output;
  1101. }
  1102. /**
  1103. * Retrieves the name-field within a tool-record and translates it on necessity.
  1104. *
  1105. * @param array $tool the input record
  1106. *
  1107. * @return string returns the name of the corresponding tool
  1108. */
  1109. public static function translate_tool_name(&$tool)
  1110. {
  1111. static $already_translated_icons = [
  1112. 'file_html.gif',
  1113. 'file_html_na.gif',
  1114. 'file_html.png',
  1115. 'file_html_na.png',
  1116. 'scormbuilder.gif',
  1117. 'scormbuilder_na.gif',
  1118. 'blog.gif',
  1119. 'blog_na.gif',
  1120. 'external.gif',
  1121. 'external_na.gif',
  1122. ];
  1123. $toolName = Security::remove_XSS(stripslashes($tool['name']));
  1124. if (isset($tool['image']) && in_array($tool['image'], $already_translated_icons)) {
  1125. return $toolName;
  1126. }
  1127. $toolName = api_underscore_to_camel_case($toolName);
  1128. if (isset($tool['category']) && 'plugin' !== $tool['category'] &&
  1129. isset($GLOBALS['Tool'.$toolName])
  1130. ) {
  1131. return get_lang('Tool'.$toolName);
  1132. }
  1133. return $toolName;
  1134. }
  1135. /**
  1136. * Get published learning path id from link inside course home.
  1137. *
  1138. * @param string Link to published lp
  1139. *
  1140. * @return int Learning path id
  1141. */
  1142. public static function getPublishedLpIdFromLink($link)
  1143. {
  1144. $lpId = 0;
  1145. $param = strstr($link, 'lp_id=');
  1146. if (!empty($param)) {
  1147. $paramList = explode('=', $param);
  1148. if (isset($paramList[1])) {
  1149. $lpId = (int) $paramList[1];
  1150. }
  1151. }
  1152. return $lpId;
  1153. }
  1154. /**
  1155. * Get published learning path category from link inside course home.
  1156. *
  1157. * @param string $link
  1158. *
  1159. * @return CLpCategory
  1160. */
  1161. public static function getPublishedLpCategoryFromLink($link)
  1162. {
  1163. $query = parse_url($link, PHP_URL_QUERY);
  1164. parse_str($query, $params);
  1165. $id = isset($params['id']) ? (int) $params['id'] : 0;
  1166. $em = Database::getManager();
  1167. /** @var CLpCategory $category */
  1168. $category = $em->find('ChamiloCourseBundle:CLpCategory', $id);
  1169. return $category;
  1170. }
  1171. /**
  1172. * Show a navigation menu.
  1173. */
  1174. public static function show_navigation_menu()
  1175. {
  1176. $blocks = self::getUserBlocks();
  1177. $class = null;
  1178. $idLearn = null;
  1179. $item = null;
  1180. $marginLeft = 160;
  1181. $html = '<div id="toolnav">';
  1182. $html .= '<ul id="toolnavbox">';
  1183. $showOnlyText = api_get_setting('show_navigation_menu') === 'text';
  1184. $showOnlyIcons = api_get_setting('show_navigation_menu') === 'icons';
  1185. foreach ($blocks as $block) {
  1186. $blockItems = $block['content'];
  1187. foreach ($blockItems as $item) {
  1188. $html .= '<li>';
  1189. if ($showOnlyText) {
  1190. $class = 'text';
  1191. $marginLeft = 170;
  1192. $show = $item['name'];
  1193. } elseif ($showOnlyIcons) {
  1194. $class = 'icons';
  1195. $marginLeft = 25;
  1196. $show = $item['tool']['only_icon_small'];
  1197. } else {
  1198. $class = 'icons-text';
  1199. $show = $item['name'].$item['tool']['only_icon_small'];
  1200. }
  1201. $item['url_params']['class'] = 'btn btn-default text-left '.$class;
  1202. $html .= Display::url(
  1203. $show,
  1204. $item['only_href'],
  1205. $item['url_params']
  1206. );
  1207. $html .= '</li>';
  1208. }
  1209. }
  1210. $html .= '</ul>';
  1211. $html .= '<script>$(function() {
  1212. $("#toolnavbox a").stop().animate({"margin-left":"-'.$marginLeft.'px"},1000);
  1213. $("#toolnavbox > li").hover(
  1214. function () {
  1215. $("a",$(this)).stop().animate({"margin-left":"-2px"},200);
  1216. $("span",$(this)).css("display","block");
  1217. },
  1218. function () {
  1219. $("a",$(this)).stop().animate({"margin-left":"-'.$marginLeft.'px"},200);
  1220. $("span",$(this)).css("display","initial");
  1221. }
  1222. );
  1223. });</script>';
  1224. $html .= '</div>';
  1225. return $html;
  1226. }
  1227. /**
  1228. * Show a toolbar with shortcuts to the course tool.
  1229. *
  1230. * @param int $orientation
  1231. *
  1232. * @return string
  1233. */
  1234. public static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL)
  1235. {
  1236. $origin = api_get_origin();
  1237. $courseInfo = api_get_course_info();
  1238. if ($origin === 'learnpath') {
  1239. return '';
  1240. }
  1241. $blocks = self::getUserBlocks();
  1242. $html = '';
  1243. if (!empty($blocks)) {
  1244. $styleId = 'toolshortcuts_vertical';
  1245. if ($orientation == SHORTCUTS_HORIZONTAL) {
  1246. $styleId = 'toolshortcuts_horizontal';
  1247. }
  1248. $html .= '<div id="'.$styleId.'">';
  1249. $html .= Display::url(
  1250. Display::return_icon('home.png', get_lang('CourseHomepageLink'), '', ICON_SIZE_MEDIUM),
  1251. $courseInfo['course_public_url'],
  1252. ['class' => 'items-icon']
  1253. );
  1254. foreach ($blocks as $block) {
  1255. $blockItems = $block['content'];
  1256. foreach ($blockItems as $item) {
  1257. $item['url_params']['id'] = '';
  1258. $item['url_params']['class'] = 'items-icon';
  1259. $html .= Display::url(
  1260. $item['tool']['only_icon_medium'],
  1261. $item['only_href'],
  1262. $item['url_params']
  1263. );
  1264. if ($orientation == SHORTCUTS_VERTICAL) {
  1265. $html .= '<br />';
  1266. }
  1267. }
  1268. }
  1269. $html .= '</div>';
  1270. }
  1271. return $html;
  1272. }
  1273. /**
  1274. * List course homepage tools from authoring and interaction sections.
  1275. *
  1276. * @param int $courseId The course ID (guessed from context if not provided)
  1277. * @param int $sessionId The session ID (guessed from context if not provided)
  1278. *
  1279. * @return array List of all tools data from the c_tools table
  1280. */
  1281. public static function toolsIconsAction($courseId = null, $sessionId = null)
  1282. {
  1283. if (empty($courseId)) {
  1284. $courseId = api_get_course_int_id();
  1285. } else {
  1286. $courseId = intval($courseId);
  1287. }
  1288. if (empty($sessionId)) {
  1289. $sessionId = api_get_session_id();
  1290. } else {
  1291. $sessionId = intval($sessionId);
  1292. }
  1293. if (empty($courseId)) {
  1294. // We shouldn't get here, but for some reason api_get_course_int_id()
  1295. // doesn't seem to get the course from the context, sometimes
  1296. return [];
  1297. }
  1298. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1299. $sql = "SELECT * FROM $table
  1300. WHERE category in ('authoring','interaction')
  1301. AND c_id = $courseId
  1302. AND session_id = $sessionId
  1303. ORDER BY id";
  1304. $result = Database::query($sql);
  1305. $data = Database::store_result($result, 'ASSOC');
  1306. return $data;
  1307. }
  1308. /**
  1309. * @param int $editIcon
  1310. *
  1311. * @return array
  1312. */
  1313. public static function getTool($editIcon)
  1314. {
  1315. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  1316. $editIcon = intval($editIcon);
  1317. $sql = "SELECT * FROM $course_tool_table
  1318. WHERE iid = $editIcon";
  1319. $result = Database::query($sql);
  1320. $tool = Database::fetch_assoc($result, 'ASSOC');
  1321. return $tool;
  1322. }
  1323. /**
  1324. * @return string
  1325. */
  1326. public static function getCustomSysIconPath()
  1327. {
  1328. // Check if directory exists or create it if it doesn't
  1329. $dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
  1330. if (!is_dir($dir)) {
  1331. mkdir($dir, api_get_permissions_for_new_directories(), true);
  1332. }
  1333. return $dir;
  1334. }
  1335. /**
  1336. * @return string
  1337. */
  1338. public static function getCustomWebIconPath()
  1339. {
  1340. // Check if directory exists or create it if it doesn't
  1341. $dir = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
  1342. return $dir;
  1343. }
  1344. /**
  1345. * @param string $icon
  1346. *
  1347. * @return string
  1348. */
  1349. public static function getDisableIcon($icon)
  1350. {
  1351. $fileInfo = pathinfo($icon);
  1352. return $fileInfo['filename'].'_na.'.$fileInfo['extension'];
  1353. }
  1354. /**
  1355. * @param int $id
  1356. * @param array $values
  1357. */
  1358. public static function updateTool($id, $values)
  1359. {
  1360. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1361. $params = [
  1362. 'name' => $values['name'],
  1363. 'link' => $values['link'],
  1364. 'target' => $values['target'],
  1365. 'visibility' => $values['visibility'],
  1366. 'description' => $values['description'],
  1367. ];
  1368. if (isset($_FILES['icon']['size']) && $_FILES['icon']['size'] !== 0) {
  1369. $dir = self::getCustomSysIconPath();
  1370. // Resize image if it is larger than 64px
  1371. $temp = new Image($_FILES['icon']['tmp_name']);
  1372. $picture_infos = $temp->get_image_info();
  1373. if ($picture_infos['width'] > 64) {
  1374. $thumbwidth = 64;
  1375. } else {
  1376. $thumbwidth = $picture_infos['width'];
  1377. }
  1378. if ($picture_infos['height'] > 64) {
  1379. $new_height = 64;
  1380. } else {
  1381. $new_height = $picture_infos['height'];
  1382. }
  1383. $temp->resize($thumbwidth, $new_height, 0);
  1384. //copy the image to the course upload folder
  1385. $path = $dir.$_FILES['icon']['name'];
  1386. $result = $temp->send_image($path);
  1387. $temp = new Image($path);
  1388. $r = $temp->convert2bw();
  1389. $ext = pathinfo($path, PATHINFO_EXTENSION);
  1390. $bwPath = substr($path, 0, -(strlen($ext) + 1)).'_na.'.$ext;
  1391. if ($r === false) {
  1392. error_log('Conversion to B&W of '.$path.' failed in '.__FILE__.' at line '.__LINE__);
  1393. } else {
  1394. $temp->send_image($bwPath);
  1395. $iconName = $_FILES['icon']['name'];
  1396. $params['custom_icon'] = $iconName;
  1397. }
  1398. }
  1399. Database::update(
  1400. $table,
  1401. $params,
  1402. [' iid = ?' => [$id]]
  1403. );
  1404. }
  1405. /**
  1406. * @param int $id
  1407. */
  1408. public static function deleteIcon($id)
  1409. {
  1410. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1411. $tool = self::getTool($id);
  1412. if ($tool && !empty($tool['custom_icon'])) {
  1413. $file = self::getCustomSysIconPath().$tool['custom_icon'];
  1414. $fileInfo = pathinfo($file);
  1415. $fileGray = $fileInfo['filename'].'_na.'.$fileInfo['extension'];
  1416. $fileGray = self::getCustomSysIconPath().$fileGray;
  1417. if (file_exists($file) && is_file($file)) {
  1418. if (Security::check_abs_path($file, self::getCustomSysIconPath())) {
  1419. unlink($file);
  1420. }
  1421. }
  1422. if (file_exists($fileGray) && is_file($fileGray)) {
  1423. if (Security::check_abs_path($fileGray, self::getCustomSysIconPath())) {
  1424. unlink($fileGray);
  1425. }
  1426. }
  1427. $params = [
  1428. 'custom_icon' => '',
  1429. ];
  1430. Database::update(
  1431. $table,
  1432. $params,
  1433. [' iid = ?' => [$id]]
  1434. );
  1435. }
  1436. }
  1437. /**
  1438. * @return array
  1439. */
  1440. public static function getCourseAdminBlocks()
  1441. {
  1442. $blocks = [];
  1443. $my_list = self::get_tools_category(TOOL_AUTHORING);
  1444. $blocks[] = [
  1445. 'title' => get_lang('Authoring'),
  1446. 'class' => 'course-tools-author',
  1447. 'content' => self::show_tools_category($my_list),
  1448. ];
  1449. $list1 = self::get_tools_category(TOOL_INTERACTION);
  1450. $list2 = self::get_tools_category(TOOL_COURSE_PLUGIN);
  1451. $my_list = array_merge($list1, $list2);
  1452. $blocks[] = [
  1453. 'title' => get_lang('Interaction'),
  1454. 'class' => 'course-tools-interaction',
  1455. 'content' => self::show_tools_category($my_list),
  1456. ];
  1457. $my_list = self::get_tools_category(TOOL_ADMIN_PLATFORM);
  1458. $blocks[] = [
  1459. 'title' => get_lang('Administration'),
  1460. 'class' => 'course-tools-administration',
  1461. 'content' => self::show_tools_category($my_list),
  1462. ];
  1463. return $blocks;
  1464. }
  1465. /**
  1466. * @return array
  1467. */
  1468. public static function getCoachBlocks()
  1469. {
  1470. $blocks = [];
  1471. $my_list = self::get_tools_category(TOOL_STUDENT_VIEW);
  1472. $blocks[] = [
  1473. 'content' => self::show_tools_category($my_list),
  1474. ];
  1475. $sessionsCopy = api_get_setting('allow_session_course_copy_for_teachers');
  1476. if ($sessionsCopy === 'true') {
  1477. // Adding only maintenance for coaches.
  1478. $myList = self::get_tools_category(TOOL_ADMIN_PLATFORM);
  1479. $onlyMaintenanceList = [];
  1480. foreach ($myList as $item) {
  1481. if ($item['name'] === 'course_maintenance') {
  1482. $item['link'] = 'course_info/maintenance_coach.php';
  1483. $onlyMaintenanceList[] = $item;
  1484. }
  1485. }
  1486. $blocks[] = [
  1487. 'title' => get_lang('Administration'),
  1488. 'content' => self::show_tools_category($onlyMaintenanceList),
  1489. ];
  1490. }
  1491. return $blocks;
  1492. }
  1493. /**
  1494. * @return array
  1495. */
  1496. public static function getStudentBlocks()
  1497. {
  1498. $blocks = [];
  1499. $tools = self::get_tools_category(TOOL_STUDENT_VIEW);
  1500. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  1501. api_get_user_id(),
  1502. api_get_course_info()
  1503. );
  1504. // Force user icon for DRH
  1505. if ($isDrhOfCourse) {
  1506. $addUserTool = true;
  1507. foreach ($tools as $tool) {
  1508. if ($tool['name'] === 'user') {
  1509. $addUserTool = false;
  1510. break;
  1511. }
  1512. }
  1513. if ($addUserTool) {
  1514. $tools[] = [
  1515. 'c_id' => api_get_course_int_id(),
  1516. 'name' => 'user',
  1517. 'link' => 'user/user.php',
  1518. 'image' => 'members.gif',
  1519. 'visibility' => '1',
  1520. 'admin' => '0',
  1521. 'address' => 'squaregrey.gif',
  1522. 'added_tool' => '0',
  1523. 'target' => '_self',
  1524. 'category' => 'interaction',
  1525. 'session_id' => api_get_session_id(),
  1526. ];
  1527. }
  1528. }
  1529. if (count($tools) > 0) {
  1530. $blocks[] = ['content' => self::show_tools_category($tools)];
  1531. }
  1532. if ($isDrhOfCourse) {
  1533. $drhTool = self::get_tools_category(TOOL_DRH);
  1534. $blocks[] = ['content' => self::show_tools_category($drhTool)];
  1535. }
  1536. return $blocks;
  1537. }
  1538. /**
  1539. * @return array
  1540. */
  1541. public static function getUserBlocks()
  1542. {
  1543. $sessionId = api_get_session_id();
  1544. // Start of tools for CourseAdmins (teachers/tutors)
  1545. if ($sessionId === 0 && api_is_course_admin() && api_is_allowed_to_edit(null, true)) {
  1546. $blocks = self::getCourseAdminBlocks();
  1547. } elseif (api_is_coach()) {
  1548. $blocks = self::getCoachBlocks();
  1549. } else {
  1550. $blocks = self::getStudentBlocks();
  1551. }
  1552. return $blocks;
  1553. }
  1554. /**
  1555. * Filter tool icons. Only show if $patronKey is = :teacher
  1556. * Example dataIcons[i]['name']: parameter titleIcons1:teacher || titleIcons2 || titleIcons3:teacher.
  1557. *
  1558. * @param array $dataIcons array Reference to icons
  1559. * @param string $courseToolCategory Current tools category
  1560. *
  1561. * @return array
  1562. */
  1563. private static function filterPluginTools($dataIcons, $courseToolCategory)
  1564. {
  1565. $patronKey = ':teacher';
  1566. if ($courseToolCategory == TOOL_STUDENT_VIEW) {
  1567. //Fix only coach can see external pages - see #8236 - icpna
  1568. if (api_is_coach()) {
  1569. foreach ($dataIcons as $index => $array) {
  1570. if (isset($array['name'])) {
  1571. $dataIcons[$index]['name'] = str_replace($patronKey, '', $array['name']);
  1572. }
  1573. }
  1574. return $dataIcons;
  1575. }
  1576. $flagOrder = false;
  1577. foreach ($dataIcons as $index => $array) {
  1578. if (!isset($array['name'])) {
  1579. continue;
  1580. }
  1581. $pos = strpos($array['name'], $patronKey);
  1582. if ($pos !== false) {
  1583. unset($dataIcons[$index]);
  1584. $flagOrder = true;
  1585. }
  1586. }
  1587. if ($flagOrder) {
  1588. return array_values($dataIcons);
  1589. }
  1590. return $dataIcons;
  1591. }
  1592. // clean patronKey of name icons
  1593. foreach ($dataIcons as $index => $array) {
  1594. if (isset($array['name'])) {
  1595. $dataIcons[$index]['name'] = str_replace($patronKey, '', $array['name']);
  1596. }
  1597. }
  1598. return $dataIcons;
  1599. }
  1600. /**
  1601. * Find the tool icon when homepage_view is activity_big.
  1602. *
  1603. * @param array $item
  1604. * @param int $iconSize
  1605. * @param bool $generateId
  1606. *
  1607. * @return string
  1608. */
  1609. private static function getToolIcon(array $item, $iconSize, $generateId = true)
  1610. {
  1611. $image = str_replace('.gif', '.png', $item['tool']['image']);
  1612. $toolIid = isset($item['tool']['iid']) ? $item['tool']['iid'] : null;
  1613. if (isset($item['tool']['custom_image'])) {
  1614. return Display::img(
  1615. $item['tool']['custom_image'],
  1616. $item['name'],
  1617. ['id' => 'toolimage_'.$toolIid]
  1618. );
  1619. }
  1620. if (isset($item['tool']['custom_icon']) && !empty($item['tool']['custom_icon'])) {
  1621. $customIcon = $item['tool']['custom_icon'];
  1622. if ($item['tool']['visibility'] == '0') {
  1623. $customIcon = self::getDisableIcon($item['tool']['custom_icon']);
  1624. }
  1625. return Display::img(
  1626. self::getCustomWebIconPath().$customIcon,
  1627. $item['name'],
  1628. ['id' => 'toolimage_'.$toolIid]
  1629. );
  1630. }
  1631. $id = '';
  1632. if ($generateId) {
  1633. $id = 'toolimage_'.$toolIid;
  1634. }
  1635. return Display::return_icon(
  1636. $image,
  1637. $item['name'],
  1638. ['id' => $id],
  1639. $iconSize,
  1640. false
  1641. );
  1642. }
  1643. }