course_home.lib.php 71 KB

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