course_home.lib.php 73 KB

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