display.lib.php 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a display library for Chamilo.
  5. *
  6. * Include/require it in your code to use its public functionality.
  7. * There are also several display public functions in the main api library.
  8. *
  9. * All public functions static public functions inside a class called Display,
  10. * so you use them like this: e.g.
  11. * Display::display_normal_message($message)
  12. *
  13. * @package chamilo.library
  14. */
  15. /**
  16. * Code
  17. */
  18. class Display
  19. {
  20. /* The main template*/
  21. static $global_template;
  22. static $preview_style = null;
  23. public function __construct()
  24. {
  25. }
  26. /**
  27. * Displays the page header
  28. * @param string The name of the page (will be showed in the page title)
  29. * @param string Optional help file name
  30. */
  31. public static function display_header($tool_name = '', $help = null, $page_header = null)
  32. {
  33. global $app;
  34. $app['classic_layout'] = true;
  35. if ($app['allowed'] == true) {
  36. ob_start(array($app['template'], 'manage_display'));
  37. } else {
  38. $app->run();
  39. exit;
  40. }
  41. }
  42. /**
  43. * Displays the reduced page header (without banner)
  44. */
  45. public static function display_reduced_header()
  46. {
  47. global $app;
  48. $app['classic_layout'] = true;
  49. global $show_learnpath, $tool_name;
  50. $app['template.show_header'] = false;
  51. $app['template.show_footer'] = false;
  52. $app['template.show_learnpath'] = $show_learnpath;
  53. self::display_header();
  54. }
  55. public static function display_no_header()
  56. {
  57. global $app;
  58. global $tool_name, $show_learnpath;
  59. $disable_js_and_css_files = true;
  60. $app['template.show_header'] = false;
  61. $app['template.show_footer'] = false;
  62. $app['template.show_learnpath'] = $show_learnpath;
  63. self::display_header();
  64. }
  65. /**
  66. * Displays the reduced page header (without banner)
  67. */
  68. public static function set_header()
  69. {
  70. global $app, $tool_name, $show_learnpath;
  71. $app['template.show_header'] = false;
  72. $app['template.show_footer'] = false;
  73. $app['template.show_learnpath'] = $show_learnpath;
  74. self::$global_template = new Template($tool_name);
  75. }
  76. /**
  77. * Display the page footer
  78. */
  79. public static function display_footer()
  80. {
  81. global $app;
  82. $out = ob_get_contents();
  83. ob_end_clean();
  84. $app['template']->assign('content', $out);
  85. $app->run();
  86. }
  87. public static function page()
  88. {
  89. return new Page();
  90. }
  91. /**
  92. * Displays the tool introduction of a tool.
  93. *
  94. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  95. * @param string $tool These are the constants that are used for indicating the tools.
  96. * @param array $editor_config Optional configuration settings for the online editor.
  97. * return: $tool return a string array list with the "define" in main_api.lib
  98. * @return html code for adding an introduction
  99. */
  100. public static function display_introduction_section($tool, $editor_config = null)
  101. {
  102. echo self::return_introduction_section($tool, $editor_config);
  103. }
  104. public static function return_introduction_section($tool, $editor_config = null)
  105. {
  106. $is_allowed_to_edit = api_is_allowed_to_edit();
  107. $moduleId = $tool;
  108. if (api_get_setting('enable_tool_introduction') == 'true' || $tool == TOOL_COURSE_HOMEPAGE) {
  109. $introduction_section = null;
  110. require api_get_path(LIBRARY_PATH).'introductionSection.inc.php';
  111. return $introduction_section;
  112. }
  113. }
  114. /**
  115. * Displays a localised html file
  116. * tries to show the file "$full_file_name"."_".$language_interface.".html"
  117. * and if this does not exist, shows the file "$full_file_name".".html"
  118. * warning this public function defines a global
  119. * @param $full_file_name, the (path) name of the file, without .html
  120. * @return return a string with the path
  121. */
  122. public static function display_localised_html_file($full_file_name)
  123. {
  124. global $language_interface;
  125. $localised_file_name = $full_file_name.'_'.$language_interface.'.html';
  126. $default_file_name = $full_file_name.'.html';
  127. if (file_exists($localised_file_name)) {
  128. include $localised_file_name;
  129. } else {
  130. include ($default_file_name);
  131. }
  132. }
  133. /**
  134. * Displays a table
  135. * @param array $header Titles for the table header
  136. * each item in this array can contain 3 values
  137. * - 1st element: the column title
  138. * - 2nd element: true or false (column sortable?)
  139. * - 3th element: additional attributes for
  140. * th-tag (eg for column-width)
  141. * - 4the element: additional attributes for the td-tags
  142. * @param array $content 2D-array with the tables content
  143. * @param array $sorting_options Keys are:
  144. * 'column' = The column to use as sort-key
  145. * 'direction' = SORT_ASC or SORT_DESC
  146. * @param array $paging_options Keys are:
  147. * 'per_page_default' = items per page when switching from
  148. * full- list to per-page-view
  149. * 'per_page' = number of items to show per page
  150. * 'page_nr' = The page to display
  151. * @param array $query_vars Additional variables to add in the query-string
  152. * @param string The style that the table will show. You can set 'table' or 'grid'
  153. * @author bart.mollet@hogent.be
  154. */
  155. public static function display_sortable_table(
  156. $header,
  157. $content,
  158. $sorting_options = array(),
  159. $paging_options = array(),
  160. $query_vars = null,
  161. $form_actions = array(),
  162. $style = 'table'
  163. ) {
  164. $column = isset($sorting_options['column']) ? $sorting_options['column'] : 0;
  165. $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  166. $table = new SortableTableFromArray($content, $column, $default_items_per_page);
  167. if (is_array($query_vars)) {
  168. $table->set_additional_parameters($query_vars);
  169. }
  170. if ($style == 'table') {
  171. if (is_array($header) && count($header) > 0) {
  172. foreach ($header as $index => $header_item) {
  173. $label = $header_item[0];
  174. $sortable = isset($header_item[1]) ? $header_item[1] : false;
  175. $th_attributes = isset($header_item[2]) ? $header_item[2] : false;
  176. $td_attributes = isset($header_item[3]) ? $header_item[3] : false;
  177. $table->set_header($index, $label, $sortable, $th_attributes, $td_attributes);
  178. }
  179. }
  180. $table->set_form_actions($form_actions);
  181. $table->display();
  182. } else {
  183. $table->display_grid();
  184. }
  185. }
  186. /**
  187. * Shows a nice grid
  188. * @param string grid name (important to create css)
  189. * @param array header content
  190. * @param array array with the information to show
  191. * @param array $paging_options Keys are:
  192. * 'per_page_default' = items per page when switching from
  193. * full- list to per-page-view
  194. * 'per_page' = number of items to show per page
  195. * 'page_nr' = The page to display
  196. * 'hide_navigation' = true to hide the navigation
  197. * @param array $query_vars Additional variables to add in the query-string
  198. * @param array $form actions Additional variables to add in the query-string
  199. * @param mixed An array with bool values to know which columns show. i.e: $visibility_options= array(true, false) we will only show the first column
  200. * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
  201. */
  202. public static function display_sortable_grid(
  203. $name,
  204. $header,
  205. $content,
  206. $paging_options = array(),
  207. $query_vars = null,
  208. $form_actions = array(),
  209. $visibility_options = true,
  210. $sort_data = true,
  211. $grid_class = array()
  212. ) {
  213. echo self::return_sortable_grid(
  214. $name,
  215. $header,
  216. $content,
  217. $paging_options,
  218. $query_vars,
  219. $form_actions,
  220. $visibility_options,
  221. $sort_data,
  222. $grid_class
  223. );
  224. }
  225. /**
  226. * Gets a nice grid in html string
  227. * @param string grid name (important to create css)
  228. * @param array header content
  229. * @param array array with the information to show
  230. * @param array $paging_options Keys are:
  231. * 'per_page_default' = items per page when switching from
  232. * full- list to per-page-view
  233. * 'per_page' = number of items to show per page
  234. * 'page_nr' = The page to display
  235. * 'hide_navigation' = true to hide the navigation
  236. * @param array $query_vars Additional variables to add in the query-string
  237. * @param array $form actions Additional variables to add in the query-string
  238. * @param mixed An array with bool values to know which columns show. i.e: $visibility_options= array(true, false) we will only show the first column
  239. * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
  240. * @param bool true for sorting data or false otherwise
  241. * @param array grid classes
  242. * @return string html grid
  243. */
  244. public static function return_sortable_grid(
  245. $name,
  246. $header,
  247. $content,
  248. $paging_options = array(),
  249. $query_vars = null,
  250. $form_actions = array(),
  251. $visibility_options = true,
  252. $sort_data = true,
  253. $grid_class = array()
  254. ) {
  255. global $origin;
  256. $column = 0;
  257. $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  258. $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name);
  259. if (is_array($query_vars)) {
  260. $table->set_additional_parameters($query_vars);
  261. }
  262. return $table->display_simple_grid(
  263. $visibility_options,
  264. $paging_options['hide_navigation'],
  265. $default_items_per_page,
  266. $sort_data,
  267. $grid_class
  268. );
  269. }
  270. /**
  271. * Displays a table with a special configuration
  272. * @param array $header Titles for the table header
  273. * each item in this array can contain 3 values
  274. * - 1st element: the column title
  275. * - 2nd element: true or false (column sortable?)
  276. * - 3th element: additional attributes for
  277. * th-tag (eg for column-width)
  278. * - 4the element: additional attributes for the td-tags
  279. * @param array $content 2D-array with the tables content
  280. * @param array $sorting_options Keys are:
  281. * 'column' = The column to use as sort-key
  282. * 'direction' = SORT_ASC or SORT_DESC
  283. * @param array $paging_options Keys are:
  284. * 'per_page_default' = items per page when switching from
  285. * full- list to per-page-view
  286. * 'per_page' = number of items to show per page
  287. * 'page_nr' = The page to display
  288. * @param array $query_vars Additional variables to add in the query-string
  289. * @param array $column_show Array of binaries 1= show columns 0. hide a column
  290. * @param array $column_order An array of integers that let us decide how the columns are going to be sort.
  291. * i.e: $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column
  292. * @param array $form_actions Set optional forms actions
  293. *
  294. * @author Julio Montoya
  295. */
  296. public static function display_sortable_config_table(
  297. $table_name,
  298. $header,
  299. $content,
  300. $sorting_options = array(),
  301. $paging_options = array(),
  302. $query_vars = null,
  303. $column_show = array(),
  304. $column_order = array(),
  305. $form_actions = array()
  306. ) {
  307. global $origin;
  308. $column = isset($sorting_options['column']) ? $sorting_options['column'] : 0;
  309. $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  310. $table = new SortableTableFromArrayConfig($content, $column, $default_items_per_page, $table_name, $column_show, $column_order);
  311. if (is_array($query_vars)) {
  312. $table->set_additional_parameters($query_vars);
  313. }
  314. // Show or hide the columns header
  315. if (is_array($column_show)) {
  316. for ($i = 0; $i < count($column_show); $i++) {
  317. if (!empty($column_show[$i])) {
  318. $val0 = isset($header[$i][0]) ? $header[$i][0] : null;
  319. $val1 = isset($header[$i][1]) ? $header[$i][1] : null;
  320. $val2 = isset($header[$i][2]) ? $header[$i][2] : null;
  321. $val3 = isset($header[$i][3]) ? $header[$i][3] : null;
  322. $table->set_header($i, $val0, $val1, $val2, $val3);
  323. }
  324. }
  325. }
  326. $table->set_form_actions($form_actions);
  327. $table->display();
  328. }
  329. /**
  330. * Displays a normal message. It is recommended to use this public function
  331. * to display any normal information messages.
  332. *
  333. * @param bool Filter (true) or not (false)
  334. * @return void
  335. */
  336. public static function display_normal_message($message, $filter = true)
  337. {
  338. echo self::return_message($message, 'normal', $filter);
  339. }
  340. /**
  341. * Displays an warning message. Use this if you want to draw attention to something
  342. * This can also be used for instance with the hint in the exercises
  343. *
  344. */
  345. public static function display_warning_message($message, $filter = true)
  346. {
  347. echo self::return_message($message, 'warning', $filter);
  348. }
  349. /**
  350. * Displays an confirmation message. Use this if something has been done successfully
  351. * @param bool Filter (true) or not (false)
  352. * @return void
  353. */
  354. public static function display_confirmation_message($message, $filter = true)
  355. {
  356. echo self::return_message($message, 'confirm', $filter);
  357. }
  358. /**
  359. * Displays an error message. It is recommended to use this public function if an error occurs
  360. * @param string $message - include any additional html
  361. * tags if you need them
  362. * @param bool Filter (true) or not (false)
  363. * @return void
  364. */
  365. public static function display_error_message($message, $filter = true)
  366. {
  367. echo self::return_message($message, 'error', $filter);
  368. }
  369. public static function return_message_and_translate($message, $type = 'normal', $filter = true)
  370. {
  371. $message = get_lang($message);
  372. echo self::return_message($message, $type, $filter);
  373. }
  374. /**
  375. * Returns a div html string with
  376. * @param string The message
  377. * @param string The message type (confirm,normal,warning,error)
  378. * @param bool Whether to XSS-filter or not
  379. * @return string Message wrapped into an HTML div
  380. */
  381. public static function return_message($message, $type = 'normal', $filter = true)
  382. {
  383. if ($filter) {
  384. $message = api_htmlentities(
  385. $message,
  386. ENT_QUOTES,
  387. api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding()
  388. );
  389. //$message = Security::remove_XSS($message);
  390. }
  391. $class = "";
  392. switch ($type) {
  393. case 'warning':
  394. $class .= 'warning-message';
  395. break;
  396. case 'error':
  397. $class .= 'error-message';
  398. break;
  399. case 'confirmation':
  400. case 'confirm':
  401. case 'success':
  402. $class .= 'confirmation-message';
  403. break;
  404. case 'normal':
  405. default:
  406. $class .= 'normal-message';
  407. }
  408. return self::div($message, array('class' => $class));
  409. }
  410. /**
  411. * Returns an encrypted mailto hyperlink
  412. *
  413. * @param string e-mail
  414. * @param string clickable text
  415. * @param string optional, class from stylesheet
  416. * @return string encrypted mailto hyperlink
  417. */
  418. public static function encrypted_mailto_link($email, $clickable_text = null, $style_class = '')
  419. {
  420. if (is_null($clickable_text)) {
  421. $clickable_text = $email;
  422. }
  423. // "mailto:" already present?
  424. if (substr($email, 0, 7) != 'mailto:') {
  425. $email = 'mailto:'.$email;
  426. }
  427. // Class (stylesheet) defined?
  428. if ($style_class != '') {
  429. $style_class = ' class="'.$style_class.'"';
  430. }
  431. // Encrypt email
  432. $hmail = '';
  433. for ($i = 0; $i < strlen($email); $i++) {
  434. $hmail .= '&#'.ord(
  435. $email{
  436. $i}
  437. ).';';
  438. }
  439. $hclickable_text = null;
  440. // Encrypt clickable text if @ is present
  441. if (strpos($clickable_text, '@')) {
  442. for ($i = 0; $i < strlen($clickable_text); $i++) {
  443. $hclickable_text .= '&#'.ord(
  444. $clickable_text{
  445. $i}
  446. ).';';
  447. }
  448. } else {
  449. $hclickable_text = @htmlspecialchars($clickable_text, ENT_QUOTES, api_get_system_encoding());
  450. }
  451. // Return encrypted mailto hyperlink
  452. return '<a href="'.$hmail.'"'.$style_class.' class="clickable_email_link">'.$hclickable_text.'</a>';
  453. }
  454. /**
  455. * Returns an mailto icon hyperlink
  456. *
  457. * @param string e-mail
  458. * @param string icon source file from the icon lib
  459. * @param integer icon size from icon lib
  460. * @param string optional, class from stylesheet
  461. * @return string encrypted mailto hyperlink
  462. */
  463. public static function icon_mailto_link($email, $icon_file = "mail.png", $icon_size = 22, $style_class = '')
  464. {
  465. // "mailto:" already present?
  466. if (substr($email, 0, 7) != 'mailto:') {
  467. $email = 'mailto:'.$email;
  468. }
  469. // Class (stylesheet) defined?
  470. if ($style_class != '') {
  471. $style_class = ' class="'.$style_class.'"';
  472. }
  473. // Encrypt email
  474. $hmail = '';
  475. for ($i = 0; $i < strlen($email); $i++) {
  476. $hmail .= '&#'.ord(
  477. $email{
  478. $i}
  479. ).';';
  480. }
  481. // icon html code
  482. $icon_html_source = self::return_icon($icon_file, $hmail, '', $icon_size);
  483. // Return encrypted mailto hyperlink
  484. return '<a href="'.$hmail.'"'.$style_class.' class="clickable_email_link">'.$icon_html_source.'</a>';
  485. }
  486. /**
  487. * Creates a hyperlink to the platform homepage.
  488. * @param string $name, the visible name of the hyperlink, default is sitename
  489. * @return string with html code for hyperlink
  490. */
  491. public static function get_platform_home_link_html($name = '')
  492. {
  493. if ($name == '') {
  494. $name = api_get_setting('siteName');
  495. }
  496. return '<a href="'.api_get_path(WEB_PATH).'index.php">'.$name.'</a>';
  497. }
  498. /**
  499. * Prints an <option>-list with all letters (A-Z).
  500. * @param char $selected_letter The letter that should be selected
  501. * @todo This is English language specific implementation. It should be adapted for the other languages.
  502. */
  503. public static function get_alphabet_options($selected_letter = '')
  504. {
  505. $result = '';
  506. for ($i = 65; $i <= 90; $i++) {
  507. $letter = chr($i);
  508. $result .= '<option value="'.$letter.'"';
  509. if ($selected_letter == $letter) {
  510. $result .= ' selected="selected"';
  511. }
  512. $result .= '>'.$letter.'</option>';
  513. }
  514. return $result;
  515. }
  516. /**
  517. * Get the options withing a select box within the given values
  518. * @param int Min value
  519. * @param int Max value
  520. * @param int Default value
  521. * @return string HTML select options
  522. */
  523. public static function get_numeric_options($min, $max, $selected_num = 0)
  524. {
  525. $result = '';
  526. for ($i = $min; $i <= $max; $i++) {
  527. $result .= '<option value="'.$i.'"';
  528. if (is_int($selected_num)) {
  529. if ($selected_num == $i) {
  530. $result .= ' selected="selected"';
  531. }
  532. }
  533. $result .= '>'.$i.'</option>';
  534. }
  535. return $result;
  536. }
  537. /**
  538. * Shows the so-called "left" menu for navigating
  539. */
  540. public static function show_course_navigation_menu($isHidden = false)
  541. {
  542. global $output_string_menu;
  543. global $_setting;
  544. // Check if the $_SERVER['REQUEST_URI'] contains already url parameters (thus a questionmark)
  545. if (strpos($_SERVER['REQUEST_URI'], '?') === false) {
  546. $sourceurl = api_get_self().'?';
  547. } else {
  548. $sourceurl = $_SERVER['REQUEST_URI'];
  549. }
  550. $output_string_menu = '';
  551. if ($isHidden == 'true' and $_SESSION['hideMenu']) {
  552. $_SESSION['hideMenu'] = 'hidden';
  553. $sourceurl = str_replace('&isHidden=true', '', $sourceurl);
  554. $sourceurl = str_replace('&isHidden=false', '', $sourceurl);
  555. $output_string_menu .= ' <a href="'.$sourceurl.'&isHidden=false"><img src="../../main/img/expand.gif" alt="'.'Show menu1'.'" padding:"2px"/></a>';
  556. } elseif ($isHidden == 'false' && $_SESSION['hideMenu']) {
  557. $sourceurl = str_replace('&isHidden=true', '', $sourceurl);
  558. $sourceurl = str_replace('&isHidden=false', '', $sourceurl);
  559. $_SESSION['hideMenu'] = 'shown';
  560. $output_string_menu .= '<div id="leftimg"><a href="'.$sourceurl.'&isHidden=true"><img src="../../main/img/collapse.gif" alt="'.'Hide menu2'.'" padding:"2px"/></a></div>';
  561. } elseif ($_SESSION['hideMenu']) {
  562. if ($_SESSION['hideMenu'] == 'shown') {
  563. $output_string_menu .= '<div id="leftimg"><a href="'.$sourceurl.'&isHidden=true"><img src="../../main/img/collapse.gif" alt="'.'Hide menu3'.' padding:"2px"/></a></div>';
  564. }
  565. if ($_SESSION['hideMenu'] == 'hidden') {
  566. $sourceurl = str_replace('&isHidden=true', '', $sourceurl);
  567. $output_string_menu .= '<a href="'.$sourceurl.'&isHidden=false"><img src="../../main/img/expand.gif" alt="'.'Hide menu4'.' padding:"2px"/></a>';
  568. }
  569. } elseif (!$_SESSION['hideMenu']) {
  570. $_SESSION['hideMenu'] = 'shown';
  571. if (isset($_cid)) {
  572. $output_string_menu .= '<div id="leftimg"><a href="'.$sourceurl.'&isHidden=true"><img src="main/img/collapse.gif" alt="'.'Hide menu5'.' padding:"2px"/></a></div>';
  573. }
  574. }
  575. }
  576. /**
  577. * This public function displays an icon
  578. * @param string The filename of the file (in the main/img/ folder
  579. * @param string The alt text (probably a language variable)
  580. * @param array additional attributes (for instance height, width, onclick, ...)
  581. * @param integer The wanted width of the icon (to be looked for in the corresponding img/icons/ folder)
  582. * @return void
  583. */
  584. public static function display_icon($image, $alt_text = '', $additional_attributes = array(), $size = null)
  585. {
  586. echo self::return_icon($image, $alt_text, $additional_attributes, $size);
  587. }
  588. /**
  589. * This public function returns the htmlcode for an icon
  590. *
  591. * @param string The filename of the file (in the main/img/ folder
  592. * @param string The alt text (probably a language variable)
  593. * @param array Additional attributes (for instance height, width, onclick, ...)
  594. * @param integer The wanted width of the icon (to be looked for in the corresponding img/icons/ folder)
  595. * @return string An HTML string of the right <img> tag
  596. *
  597. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University 2006
  598. * @author Julio Montoya 2010 Function improved, adding image constants
  599. * @author Yannick Warnier 2011 Added size handler
  600. * @version Feb 2011
  601. */
  602. public static function return_icon(
  603. $image,
  604. $alt_text = '',
  605. $additional_attributes = array(),
  606. $size = ICON_SIZE_SMALL,
  607. $show_text = true,
  608. $return_only_path = false
  609. ) {
  610. $code_path = api_get_path(SYS_CODE_PATH);
  611. $w_code_path = api_get_path(WEB_CODE_PATH);
  612. $image = trim($image);
  613. $theme = 'css/'.api_get_visual_theme().'/icons/';
  614. $icon = '';
  615. $size_extra = '';
  616. if (isset($size)) {
  617. $size = intval($size);
  618. $size_extra = $size.'/';
  619. } else {
  620. $size = ICON_SIZE_SMALL;
  621. }
  622. //Checking the theme icons folder example: main/css/chamilo/icons/XXX
  623. if (is_file($code_path.$theme.$size_extra.$image)) {
  624. $icon = $w_code_path.$theme.$size_extra.$image;
  625. } elseif (is_file($code_path.'img/icons/'.$size_extra.$image)) {
  626. //Checking the main/img/icons/XXX/ folder
  627. $icon = $w_code_path.'img/icons/'.$size_extra.$image;
  628. } else {
  629. //Checking the img/ folder
  630. $icon = $w_code_path.'img/'.$image;
  631. }
  632. $icon = api_get_cdn_path($icon);
  633. if ($return_only_path) {
  634. return $icon;
  635. }
  636. $img = self::img($icon, $alt_text, $additional_attributes);
  637. if (SHOW_TEXT_NEAR_ICONS == true and !empty($alt_text)) {
  638. if ($show_text) {
  639. $img = "$img $alt_text";
  640. }
  641. }
  642. return $img;
  643. }
  644. /**
  645. * Returns the htmlcode for an image
  646. *
  647. * @param string $image the filename of the file (in the main/img/ folder
  648. * @param string $alt_text the alt text (probably a language variable)
  649. * @param array additional attributes (for instance height, width, onclick, ...)
  650. * @author Julio Montoya 2010
  651. */
  652. public static function img($image_path, $alt_text = '', $additional_attributes = array())
  653. {
  654. // Sanitizing the parameter $image_path
  655. $image_path = Security::filter_img_path($image_path);
  656. // alt text = the image name if there is none provided (for XHTML compliance)
  657. if ($alt_text == '') {
  658. $alt_text = basename($image_path);
  659. }
  660. $additional_attributes['src'] = $image_path;
  661. if (empty($additional_attributes['alt'])) {
  662. $additional_attributes['alt'] = $alt_text;
  663. }
  664. if (empty($additional_attributes['title'])) {
  665. $additional_attributes['title'] = $alt_text;
  666. }
  667. //return '<img src="'.$image_path.'" alt="'.$alt_text.'" title="'.$alt_text.'" '.$attribute_list.' />';
  668. return self::tag('img', '', $additional_attributes);
  669. }
  670. /**
  671. * Returns the htmlcode for a tag (h3, h1, div, a, button), etc
  672. *
  673. * @param string $image the filename of the file (in the main/img/ folder
  674. * @param string $alt_text the alt text (probably a language variable)
  675. * @param array additional attributes (for instance height, width, onclick, ...)
  676. * @author Julio Montoya 2010
  677. */
  678. public static function tag($tag, $content, $additional_attributes = array())
  679. {
  680. $attribute_list = '';
  681. // Managing the additional attributes
  682. if (!empty($additional_attributes) && is_array($additional_attributes)) {
  683. $attribute_list = '';
  684. foreach ($additional_attributes as $key => & $value) {
  685. $attribute_list .= $key.'="'.$value.'" ';
  686. }
  687. }
  688. //some tags don't have this </XXX>
  689. if (in_array($tag, array('img', 'input', 'br'))) {
  690. $return_value = '<'.$tag.' '.$attribute_list.' />';
  691. } else {
  692. $return_value = '<'.$tag.' '.$attribute_list.' > '.$content.'</'.$tag.'>';
  693. }
  694. return $return_value;
  695. }
  696. /**
  697. * Creates a URL anchor
  698. */
  699. public static function url($name, $url, $extra_attributes = array())
  700. {
  701. if (!empty($url)) {
  702. $extra_attributes['href'] = $url;
  703. }
  704. return self::tag('a', $name, $extra_attributes);
  705. }
  706. /**
  707. * Creates a div tag
  708. */
  709. public static function div($content, $extra_attributes = array())
  710. {
  711. return self::tag('div', $content, $extra_attributes);
  712. }
  713. /**
  714. * Creates a span tag
  715. */
  716. public static function span($content, $extra_attributes = array())
  717. {
  718. return self::tag('span', $content, $extra_attributes);
  719. }
  720. /**
  721. * Displays an HTML input tag
  722. *
  723. */
  724. public static function input($type, $name, $value, $extra_attributes = array())
  725. {
  726. if (isset($type)) {
  727. $extra_attributes['type'] = $type;
  728. }
  729. if (isset($name)) {
  730. $extra_attributes['name'] = $name;
  731. }
  732. if (isset($value)) {
  733. $extra_attributes['value'] = $value;
  734. }
  735. return self::tag('input', '', $extra_attributes);
  736. }
  737. public static function button($name, $value, $extra_attributes = array())
  738. {
  739. if (!empty($name)) {
  740. $extra_attributes['name'] = $name;
  741. }
  742. return self::tag('button', $value, $extra_attributes);
  743. }
  744. /**
  745. * Displays an HTML select tag
  746. *
  747. */
  748. public static function select(
  749. $name,
  750. $values,
  751. $default = -1,
  752. $extra_attributes = array(),
  753. $show_blank_item = true,
  754. $blank_item_text = null
  755. ) {
  756. $html = '';
  757. $extra = '';
  758. $default_id = 'id="'.$name.'" ';
  759. foreach ($extra_attributes as $key => $parameter) {
  760. if ($key == 'id') {
  761. $default_id = '';
  762. }
  763. $extra .= $key.'="'.$parameter.'"';
  764. }
  765. $html .= '<select name="'.$name.'" '.$default_id.' '.$extra.'>';
  766. if ($show_blank_item) {
  767. if (empty($blank_item_text)) {
  768. $blank_item_text = get_lang('Select');
  769. } else {
  770. $blank_item_text = Security::remove_XSS($blank_item_text);
  771. }
  772. $html .= self::tag('option', '-- '.$blank_item_text.' --', array('value' => '-1'));
  773. }
  774. if ($values) {
  775. foreach ($values as $key => $value) {
  776. if (is_array($value) && isset($value['name'])) {
  777. $value = $value['name'];
  778. }
  779. $html .= '<option value="'.$key.'"';
  780. if (is_array($default)) {
  781. foreach ($default as $item) {
  782. if ($item == $key) {
  783. $html .= 'selected="selected"';
  784. break;
  785. }
  786. }
  787. } else {
  788. if ($default == $key) {
  789. $html .= 'selected="selected"';
  790. }
  791. }
  792. $html .= '>'.$value.'</option>';
  793. }
  794. }
  795. $html .= '</select>';
  796. return $html;
  797. }
  798. /**
  799. * Creates a tab menu
  800. * Requirements: declare the jquery, jquery-ui libraries + the jquery-ui.css in the $htmlHeadXtra variable before the display_header
  801. * Add this script
  802. * @example
  803. * <script>
  804. $(function() {
  805. $( "#tabs" ).tabs();
  806. });
  807. </script>
  808. * @param array list of the tab titles
  809. * @param array content that will be showed
  810. * @param string the id of the container of the tab in the example "tabs"
  811. * @param array attributes for the ul
  812. *
  813. */
  814. public static function tabs(
  815. $header_list,
  816. $content_list,
  817. $id = 'tabs',
  818. $attributes = array(),
  819. $ul_attributes = array()
  820. ) {
  821. if (empty($header_list) || count($header_list) == 0) {
  822. return '';
  823. }
  824. $lis = '';
  825. $i = 1;
  826. foreach ($header_list as $item) {
  827. $item = self::tag('a', $item, array('href' => '#'.$id.'-'.$i));
  828. $lis .= self::tag('li', $item, $ul_attributes);
  829. $i++;
  830. }
  831. $ul = self::tag('ul', $lis);
  832. $i = 1;
  833. $divs = '';
  834. foreach ($content_list as $content) {
  835. $content = self::tag('p', $content);
  836. $divs .= self::tag('div', $content, array('id' => $id.'-'.$i));
  837. $i++;
  838. }
  839. $attributes['id'] = $id;
  840. $main_div = self::tag('div', $ul.$divs, $attributes);
  841. return $main_div;
  842. }
  843. public static function tabs_only_link($header_list, $selected = null)
  844. {
  845. $id = uniqid();
  846. $i = 1;
  847. $lis = null;
  848. foreach ($header_list as $item) {
  849. $class = null;
  850. if ($i == $selected) {
  851. $class = 'active';
  852. }
  853. $item = self::tag('a', $item['content'], array('id' => $id.'-'.$i, 'href' => $item['url']));
  854. $lis .= self::tag('li', $item, array('class' => $class));
  855. $i++;
  856. }
  857. return self::tag('ul', $lis, array('class' => 'nav nav-tabs'));
  858. }
  859. /**
  860. * In order to display a grid using jqgrid you have to:
  861. * @example
  862. * After your Display::display_header function you have to add the nex javascript code: *
  863. * <script>
  864. * echo Display::grid_js('my_grid_name', $url,$columns, $column_model, $extra_params,array()); // for more information of this function check the grid_js() function
  865. * </script>
  866. * //Then you have to call the grid_html
  867. * echo Display::grid_html('my_grid_name');
  868. * As you can see both function use the same "my_grid_name" this is very important otherwise nothing will work
  869. *
  870. * @param string the div id, this value must be the same with the first parameter of Display::grid_js()
  871. * @return string html
  872. *
  873. */
  874. public static function grid_html($div_id)
  875. {
  876. $table = self::tag('table', '', array('id' => $div_id));
  877. $table .= self::tag('div', '', array('id' => $div_id.'_pager'));
  878. return $table;
  879. }
  880. public static function form_row($label, $form_item)
  881. {
  882. $label = self::span($label, array('class' => 'control-label'));
  883. $form_item = self::div($form_item, array('class' => 'controls'));
  884. return self::div($label.$form_item, array('class' => 'control-group'));
  885. }
  886. /**
  887. * This is a wrapper to use the jqgrid in Chamilo. For the other jqgrid options visit http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options
  888. * This function need to be in the ready jquery function example --> $(function() { <?php echo Display::grid_js('grid' ...); ?> }
  889. * In order to work this function needs the Display::grid_html function with the same div id
  890. *
  891. * @param string div id
  892. * @param string url where the jqgrid will ask for data (if datatype = json)
  893. * @param array Visible columns (you should use get_lang). An array in which we place the names of the columns.
  894. * This is the text that appears in the head of the grid (Header layer).
  895. * Example: colname {name:'date', index:'date', width:120, align:'right'},
  896. * @param array the column model : Array which describes the parameters of the columns.This is the most important part of the grid.
  897. * For a full description of all valid values see colModel API. See the url above.
  898. * @param array extra parameters
  899. * @param array data that will be loaded
  900. * @return string the js code
  901. *
  902. */
  903. public static function grid_js(
  904. $div_id,
  905. $url,
  906. $column_names,
  907. $column_model,
  908. $extra_params,
  909. $data = array(),
  910. $formatter = '',
  911. $width_fix = false
  912. ) {
  913. $obj = new stdClass();
  914. if (!empty($url)) {
  915. $obj->url = $url;
  916. $obj->datatype = 'json';
  917. } else {
  918. $obj->datatype = 'local';
  919. }
  920. $column_names = array_map("utf8_encode", $column_names);
  921. $obj->colNames = $column_names;
  922. $obj->colModel = $column_model;
  923. $obj->pager = '#'.$div_id.'_pager';
  924. $all_value = 10000000;
  925. //Default row quantity
  926. if (!isset($extra_params['rowList'])) {
  927. $extra_params['rowList'] = array(20, 50, 100, 500, 1000, $all_value);
  928. //$extra_params['rowList'] = array(20, 50, 100, 500, 1000, 2000, 5000, 10000);
  929. }
  930. $json = '';
  931. if (!empty($extra_params['datatype'])) {
  932. $obj->datatype = $extra_params['datatype'];
  933. }
  934. //Row even odd style
  935. $obj->altRows = true;
  936. if (!empty($extra_params['altRows'])) {
  937. $obj->altRows = $extra_params['altRows'];
  938. }
  939. if (!empty($extra_params['sortname'])) {
  940. $obj->sortname = $extra_params['sortname'];
  941. }
  942. //$obj->sortorder = 'desc';
  943. if (!empty($extra_params['sortorder'])) {
  944. $obj->sortorder = $extra_params['sortorder'];
  945. }
  946. if (!empty($extra_params['rowList'])) {
  947. $obj->rowList = $extra_params['rowList'];
  948. }
  949. //Sets how many records we want to view in the grid
  950. $obj->rowNum = 20;
  951. if (!empty($extra_params['rowNum'])) {
  952. $obj->rowNum = $extra_params['rowNum'];
  953. }
  954. $obj->viewrecords = 'true';
  955. if (!empty($extra_params['viewrecords'])) {
  956. $obj->viewrecords = $extra_params['viewrecords'];
  957. }
  958. if (!empty($extra_params)) {
  959. foreach ($extra_params as $key => $element) {
  960. $obj->$key = $element;
  961. }
  962. }
  963. //Adding static data
  964. if (!empty($data)) {
  965. $data_var = $div_id.'_data';
  966. $json .= ' var '.$data_var.' = '.json_encode($data).';';
  967. $obj->data = $data_var;
  968. $obj->datatype = 'local';
  969. $json .= "\n";
  970. }
  971. $json_encode = json_encode($obj);
  972. if (!empty($data)) {
  973. //Converts the "data":"js_variable" to "data":js_variable othersiwe it will not work
  974. $json_encode = str_replace('"data":"'.$data_var.'"', '"data":'.$data_var.'', $json_encode);
  975. }
  976. //Fixes datainit datepick
  977. $json_encode = str_replace('"dataInit"', 'dataInit', $json_encode);
  978. /*$json_encode = str_replace('"dataEvents"','dataEvents', $json_encode);
  979. $json_encode = str_replace('"type"','type', $json_encode);
  980. $json_encode = str_replace('"fn"','fn', $json_encode);
  981. $json_encode = str_replace('"data"','data', $json_encode);
  982. $json_encode = str_replace('"attr"','attr', $json_encode);
  983. $json_encode = str_replace('"rel"','rel', $json_encode);
  984. $json_encode = str_replace('"title"','title', $json_encode);
  985. */
  986. $json_encode = str_replace('"register_second_select"', 'register_second_select', $json_encode);
  987. $json_encode = str_replace('"fill_second_select"', 'fill_second_select', $json_encode);
  988. $json_encode = str_replace('"date_pick"', 'date_pick', $json_encode);
  989. $json_encode = str_replace('"date_pick_today"', 'date_pick_today', $json_encode);
  990. $json_encode = str_replace('"date_pick_one_month"', 'date_pick_one_month', $json_encode);
  991. //Fixing true/false js values that doesn't need the ""
  992. $json_encode = str_replace(':"true"', ':true', $json_encode);
  993. //wrap_cell is not a valid jqgrid attributes is a hack to wrap a text
  994. $json_encode = str_replace(
  995. '"wrap_cell":true',
  996. 'cellattr:function(rowId, tv, rawObject, cm, rdata) { return \'style ="white-space: normal;"\'}',
  997. $json_encode
  998. );
  999. $json_encode = str_replace(':"false"', ':false', $json_encode);
  1000. $json_encode = str_replace('"formatter":"action_formatter"', 'formatter:action_formatter', $json_encode);
  1001. if ($width_fix) {
  1002. if (is_numeric($width_fix)) {
  1003. $width_fix = intval($width_fix);
  1004. } else {
  1005. $width_fix = '150';
  1006. }
  1007. //see BT#2020
  1008. /*$json .= "$(window).bind('resize', function() {
  1009. $('#".$div_id."').setGridWidth($(window).width() - ".$width_fix.");
  1010. }).trigger('resize');";*/
  1011. }
  1012. //Creating the jqgrid element
  1013. $json .= '$("#'.$div_id.'").jqGrid(';
  1014. $json .= $json_encode;
  1015. $json .= ');';
  1016. $all_text = addslashes(get_lang('All'));
  1017. $json .= '$("'.$obj->pager.' option[value='.$all_value.']").text("'.$all_text.'");';
  1018. $json .= "\n";
  1019. //Adding edit/delete icons
  1020. $json .= $formatter;
  1021. return $json;
  1022. /*
  1023. Real Example
  1024. $("#list_week").jqGrid({
  1025. url:'<?php echo api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_week&session_id='.$session_id; ?>',
  1026. datatype: 'json',
  1027. colNames:['Week','Date','Course', 'LP'],
  1028. colModel :[
  1029. {name:'week', index:'week', width:120, align:'right'},
  1030. {name:'date', index:'date', width:120, align:'right'},
  1031. {name:'course', index:'course', width:150},
  1032. {name:'lp', index:'lp', width:250}
  1033. ],
  1034. pager: '#pager3',
  1035. rowNum:100,
  1036. rowList:[10,20,30],
  1037. sortname: 'date',
  1038. sortorder: 'desc',
  1039. viewrecords: true,
  1040. grouping:true,
  1041. groupingView : {
  1042. groupField : ['week'],
  1043. groupColumnShow : [false],
  1044. groupText : ['<b>Week {0} - {1} Item(s)</b>']
  1045. }
  1046. }); */
  1047. }
  1048. public static function table($headers, $rows, $attributes = array())
  1049. {
  1050. if (empty($attributes)) {
  1051. $attributes['class'] = 'data_table';
  1052. }
  1053. //require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.php';
  1054. $table = new HTML_Table($attributes);
  1055. $row = 0;
  1056. $column = 0;
  1057. //Course headers
  1058. if (!empty($headers)) {
  1059. foreach ($headers as $item) {
  1060. $table->setHeaderContents($row, $column, $item);
  1061. $column++;
  1062. }
  1063. $row = 1;
  1064. $column = 0;
  1065. }
  1066. if (!empty($rows)) {
  1067. foreach ($rows as $content) {
  1068. $table->setCellContents($row, $column, $content);
  1069. $row++;
  1070. //$column++;
  1071. }
  1072. }
  1073. return $table->toHtml();
  1074. }
  1075. /**
  1076. * Returns the "what's new" icon notifications
  1077. *
  1078. * The general logic of this function is to track the last time the user
  1079. * entered the course and compare to what has changed inside this course
  1080. * since then, based on the item_property table inside this course. Note that,
  1081. * if the user never entered the course before, he will not see notification
  1082. * icons. This function takes session ID into account (if any) and only shows
  1083. * the corresponding notifications.
  1084. * @param array Course information array, containing at least elements 'db' and 'k'
  1085. * @return string The HTML link to be shown next to the course
  1086. */
  1087. public static function show_notification($course_info)
  1088. {
  1089. $t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  1090. $user_id = api_get_user_id();
  1091. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  1092. $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1093. $course_code = Database::escape_string($course_info['code']);
  1094. $course_id = $course_info['real_id'];
  1095. $course_info['id_session'] = intval($course_info['id_session']);
  1096. // Get the user's last access dates to all tools of this course
  1097. $sqlLastTrackInCourse = "SELECT * FROM $t_track_e_access USE INDEX (access_cours_code, access_user_id)
  1098. WHERE access_cours_code = '".$course_code."' AND
  1099. access_user_id = '$user_id' AND
  1100. access_session_id ='".$course_info['id_session']."'";
  1101. $resLastTrackInCourse = Database::query($sqlLastTrackInCourse);
  1102. $oldestTrackDate = $oldestTrackDateOrig = '3000-01-01 00:00:00';
  1103. while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
  1104. $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
  1105. if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
  1106. $oldestTrackDate = $lastTrackInCourse['access_date'];
  1107. }
  1108. }
  1109. if ($oldestTrackDate == $oldestTrackDateOrig) {
  1110. //if there was no connexion to the course ever, then take the
  1111. // course creation date as a reference
  1112. $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  1113. $sql = "SELECT course.creation_date ".
  1114. "FROM $course_table course ".
  1115. "WHERE course.code = '".$course_code."'";
  1116. $res = Database::query($sql);
  1117. if ($res && Database::num_rows($res) > 0) {
  1118. $row = Database::fetch_array($res);
  1119. }
  1120. $oldestTrackDate = $row['creation_date'];
  1121. }
  1122. // Get the last edits of all tools of this course.
  1123. $sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref, ".
  1124. " tet.lastedit_type type, tet.to_group_id group_id, ".
  1125. " ctt.image image, ctt.link link ".
  1126. " FROM $tool_edit_table tet, $course_tool_table ctt ".
  1127. " WHERE tet.c_id = $course_id AND
  1128. ctt.c_id = $course_id AND
  1129. tet.lastedit_date > '$oldestTrackDate' ".
  1130. " AND ctt.name = tet.tool ".
  1131. " AND ctt.visibility = '1' ".
  1132. " AND tet.lastedit_user_id != $user_id AND tet.id_session = '".$course_info['id_session']."' ".
  1133. " ORDER BY tet.lastedit_date";
  1134. $res = Database::query($sql);
  1135. // Get the group_id's with user membership.
  1136. $group_ids = GroupManager :: get_group_ids($course_info['real_id'], $user_id);
  1137. $group_ids[] = 0; //add group 'everyone'
  1138. $notifications = array();
  1139. // Filter all last edits of all tools of the course
  1140. while ($res && ($item_property = Database::fetch_array($res))) {
  1141. // First thing to check is if the user never entered the tool
  1142. // or if his last visit was earlier than the last modification.
  1143. if ((!isset ($lastTrackInCourseDate[$item_property['tool']])
  1144. || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date'])
  1145. // Drop the tool elements that are part of a group that the
  1146. // user is not part of.
  1147. && ((in_array($item_property['to_group_id'], $group_ids)
  1148. // Drop the dropbox, notebook and chat tools (we don't care)
  1149. && ($item_property['tool'] != TOOL_DROPBOX
  1150. && $item_property['tool'] != TOOL_NOTEBOOK
  1151. && $item_property['tool'] != TOOL_CHAT)
  1152. )
  1153. )
  1154. // Take only what's visible or invisible but where the user is a teacher or where the visibility is unset.
  1155. && ($item_property['visibility'] == '1'
  1156. || ($course_info['status'] == '1' && $item_property['visibility'] == '0')
  1157. || !isset($item_property['visibility']))
  1158. ) {
  1159. // Also drop announcements and events that are not for the user or his group.
  1160. if (($item_property['tool'] == TOOL_ANNOUNCEMENT
  1161. || $item_property['tool'] == TOOL_CALENDAR_EVENT)
  1162. && (($item_property['to_user_id'] != $user_id)
  1163. && (!isset($item_property['to_group_id'])
  1164. || !in_array($item_property['to_group_id'], $group_ids)))
  1165. ) {
  1166. continue;
  1167. }
  1168. // If it's a survey, make sure the user's invited. Otherwise drop it.
  1169. if ($item_property['tool'] == TOOL_SURVEY) {
  1170. $survey_info = survey_manager::get_survey($item_property['ref'], 0, $course_code);
  1171. if ($survey_info) {
  1172. $invited_users = SurveyUtil::get_invited_users($survey_info['code'], $course_code);
  1173. if (!in_array($user_id, $invited_users['course_users'])) {
  1174. continue;
  1175. }
  1176. }
  1177. }
  1178. // If it's a learning path, ensure it is currently visible to the user
  1179. if ($item_property['tool'] == TOOL_LEARNPATH) {
  1180. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  1181. if (!learnpath::is_lp_visible_for_student($item_property['ref'], $user_id, $course_code)) {
  1182. continue;
  1183. }
  1184. }
  1185. $notifications[$item_property['tool']] = $item_property;
  1186. }
  1187. }
  1188. // Show all tool icons where there is something new.
  1189. $retvalue = '&nbsp;';
  1190. while (list($key, $notification) = each($notifications)) {
  1191. $lastDate = date('d/m/Y H:i', convert_sql_date($notification['lastedit_date']));
  1192. $type = $notification['lastedit_type'];
  1193. if (empty($course_info['id_session'])) {
  1194. $my_course['id_session'] = 0;
  1195. } else {
  1196. $my_course['id_session'] = $course_info['id_session'];
  1197. }
  1198. $label = get_lang('TitleNotification').": ".get_lang($type)." ($lastDate)";
  1199. $retvalue .= '<a href="'.api_get_path(
  1200. WEB_CODE_PATH
  1201. ).$notification['link'].'?cidReq='.$course_code.'&amp;ref='.$notification['ref'].'&amp;gidReq='.$notification['to_group_id'].'&amp;id_session='.$my_course['id_session'].'">'.
  1202. Display::return_icon($notification['image'], $label).'</a>&nbsp;';
  1203. }
  1204. return $retvalue;
  1205. }
  1206. /**
  1207. * Displays a digest e.g. short summary of new agenda and announcements items.
  1208. * This used to be displayed in the right hand menu, but is now
  1209. * disabled by default (see config settings in this file) because most people like
  1210. * the what's new icons better.
  1211. *
  1212. * @version 1.0
  1213. */
  1214. public static function display_digest($toolsList, $digest, $orderKey, $courses)
  1215. {
  1216. $html = '';
  1217. if (is_array(
  1218. $digest
  1219. ) && (CONFVAL_showExtractInfo == SCRIPTVAL_UnderCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both)
  1220. ) {
  1221. // // // LEVEL 1 // // //
  1222. reset($digest);
  1223. $html .= "<br /><br />\n";
  1224. while (list($key1) = each($digest)) {
  1225. if (is_array($digest[$key1])) {
  1226. // // // Title of LEVEL 1 // // //
  1227. $html .= "<strong>\n";
  1228. if ($orderKey[0] == 'keyTools') {
  1229. $tools = $key1;
  1230. $html .= $toolsList[$key1]['name'];
  1231. } elseif ($orderKey[0] == 'keyCourse') {
  1232. $courseSysCode = $key1;
  1233. $html .= "<a href=\"".api_get_path(
  1234. WEB_COURSE_PATH
  1235. ).$courses[$key1]['coursePath']."\">".$courses[$key1]['courseCode']."</a>\n";
  1236. } elseif ($orderKey[0] == 'keyTime') {
  1237. $html .= api_convert_and_format_date(
  1238. $digest[$key1],
  1239. DATE_FORMAT_LONG,
  1240. date_default_timezone_get()
  1241. );
  1242. }
  1243. $html .= "</strong>\n";
  1244. // // // End Of Title of LEVEL 1 // // //
  1245. // // // LEVEL 2 // // //
  1246. reset($digest[$key1]);
  1247. while (list ($key2) = each($digest[$key1])) {
  1248. // // // Title of LEVEL 2 // // //
  1249. $html .= "<p>\n"."\n";
  1250. if ($orderKey[1] == 'keyTools') {
  1251. $tools = $key2;
  1252. $html .= $toolsList[$key2][name];
  1253. } elseif ($orderKey[1] == 'keyCourse') {
  1254. $courseSysCode = $key2;
  1255. $html .= "<a href=\"".api_get_path(
  1256. WEB_COURSE_PATH
  1257. ).$courses[$key2]['coursePath']."\">".$courses[$key2]['courseCode']."</a>\n";
  1258. } elseif ($orderKey[1] == 'keyTime') {
  1259. $html .= api_convert_and_format_date($key2, DATE_FORMAT_LONG, date_default_timezone_get());
  1260. }
  1261. $html .= "\n";
  1262. $html .= "</p>";
  1263. // // // End Of Title of LEVEL 2 // // //
  1264. // // // LEVEL 3 // // //
  1265. reset($digest[$key1][$key2]);
  1266. while (list ($key3, $dataFromCourse) = each($digest[$key1][$key2])) {
  1267. // // // Title of LEVEL 3 // // //
  1268. if ($orderKey[2] == 'keyTools') {
  1269. $level3title = "<a href=\"".$toolsList[$key3]["path"].$courseSysCode."\">".$toolsList[$key3]['name']."</a>";
  1270. } elseif ($orderKey[2] == 'keyCourse') {
  1271. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$key3."\">".$courses[$key3]['courseCode']."</a>\n";
  1272. } elseif ($orderKey[2] == 'keyTime') {
  1273. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$courseSysCode."\">".api_convert_and_format_date(
  1274. $key3,
  1275. DATE_FORMAT_LONG,
  1276. date_default_timezone_get()
  1277. )."</a>";
  1278. }
  1279. // // // End Of Title of LEVEL 3 // // //
  1280. // // // LEVEL 4 (data) // // //
  1281. reset($digest[$key1][$key2][$key3]);
  1282. while (list ($key4, $dataFromCourse) = each($digest[$key1][$key2][$key3])) {
  1283. $html .= $level3title.' &ndash; '.api_substr(
  1284. strip_tags($dataFromCourse),
  1285. 0,
  1286. CONFVAL_NB_CHAR_FROM_CONTENT
  1287. );
  1288. //adding ... (three dots) if the texts are too large and they are shortened
  1289. if (api_strlen($dataFromCourse) >= CONFVAL_NB_CHAR_FROM_CONTENT) {
  1290. $html .= '...';
  1291. }
  1292. }
  1293. $html .= "<br />\n";
  1294. }
  1295. }
  1296. }
  1297. }
  1298. return $html;
  1299. }
  1300. } // End function display_digest
  1301. /**
  1302. * Return the five star HTML
  1303. *
  1304. * @param string id of the rating ul element
  1305. * @param string url that will be added (for jquery see hot_courses.tpl)
  1306. * @param string point info array see function CourseManager::get_course_ranking()
  1307. * @param bool add a div wrapper
  1308. * @todo use templates
  1309. **/
  1310. public static function return_rating_system($id, $url, $point_info = array(), $add_div_wrapper = true)
  1311. {
  1312. $number_of_users_who_voted = isset($point_info['users_who_voted']) ? $point_info['users_who_voted'] : null;
  1313. $percentage = isset($point_info['point_average']) ? $point_info['point_average'] : 0;
  1314. if (!empty($percentage)) {
  1315. $percentage = $percentage * 125 / 100;
  1316. }
  1317. $accesses = isset($point_info['accesses']) ? $point_info['accesses'] : 0;
  1318. $star_label = sprintf(get_lang('XStarsOutOf5'), $point_info['point_average_star']);
  1319. $html = '<ul id="'.$id.'" class="star-rating">
  1320. <li class="current-rating" style="width:'.$percentage.'px;"></li>
  1321. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=1" title="'.$star_label.'" class="one-star">1</a></li>
  1322. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=2" title="'.$star_label.'" class="two-stars">2</a></li>
  1323. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=3" title="'.$star_label.'" class="three-stars">3</a></li>
  1324. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=4" title="'.$star_label.'" class="four-stars">4</a></li>
  1325. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=5" title="'.$star_label.'" class="five-stars">5</a></li>
  1326. </ul>';
  1327. $labels = array();
  1328. $labels[] = $number_of_users_who_voted == 1 ? $number_of_users_who_voted.' '.get_lang(
  1329. 'Vote'
  1330. ) : $number_of_users_who_voted.' '.get_lang('Votes');
  1331. $labels[] = $accesses == 1 ? $accesses.' '.get_lang('Visit') : $accesses.' '.get_lang('Visits');
  1332. if (!empty($number_of_users_who_voted)) {
  1333. $labels[] = get_lang('Average').' '.$point_info['point_average_star'].'/5';
  1334. }
  1335. $labels[] = $point_info['user_vote'] ? get_lang('YourVote').' ['.$point_info['user_vote'].']' : get_lang(
  1336. 'YourVote'
  1337. ).' [?] ';
  1338. if (!$add_div_wrapper && api_is_anonymous()) {
  1339. $labels[] = Display::tag('span', get_lang('LoginToVote'), array('class' => 'error'));
  1340. }
  1341. $html .= Display::span(implode(' | ', $labels), array('id' => 'vote_label_'.$id, 'class' => 'vote_label_info'));
  1342. $html .= ' '.Display::span(' ', array('id' => 'vote_label2_'.$id));
  1343. if ($add_div_wrapper) {
  1344. $html = Display::div($html, array('id' => 'rating_wrapper_'.$id));
  1345. }
  1346. return $html;
  1347. }
  1348. public static function return_default_table_class()
  1349. {
  1350. return 'data_table';
  1351. }
  1352. public static function page_header($title, $second_title = null, $size = 'h1')
  1353. {
  1354. $title = Security::remove_XSS($title);
  1355. if (!empty($second_title)) {
  1356. $second_title = Security::remove_XSS($second_title);
  1357. $title .= "<small> $second_title<small>";
  1358. }
  1359. return '<div class="page-header"><'.$size.'>'.$title.'</'.$size.'></div>';
  1360. }
  1361. public static function page_header_and_translate($title, $second_title = null)
  1362. {
  1363. $title = get_lang($title);
  1364. return self::page_header($title, $second_title);
  1365. }
  1366. public static function page_subheader_and_translate($title, $second_title = null)
  1367. {
  1368. $title = get_lang($title);
  1369. return self::page_subheader($title, $second_title);
  1370. }
  1371. public static function page_subheader($title, $second_title = null)
  1372. {
  1373. return self::page_header($title, $second_title, 'h2');
  1374. }
  1375. public static function page_subheader2($title, $second_title = null)
  1376. {
  1377. return self::page_header($title, $second_title, 'h3');
  1378. }
  1379. public static function page_subheader3($title, $second_title = null)
  1380. {
  1381. return self::page_header($title, $second_title, 'h4');
  1382. }
  1383. public static function description($list)
  1384. {
  1385. $html = null;
  1386. if (!empty($list)) {
  1387. $html = '<dl class="dl-horizontal">';
  1388. foreach ($list as $item) {
  1389. $html .= '<dt>'.$item['title'].'</dd>';
  1390. $html .= '<dd>'.$item['content'].'</dt>';
  1391. }
  1392. $html .= '</dl>';
  1393. }
  1394. return $html;
  1395. }
  1396. /**
  1397. * Returns a styled HTML progress bar corresponding to the given progress.
  1398. * Defaults to a blue bar (options allow you to change that)
  1399. * @param int Percentage of progress
  1400. * @param bool Whether to show the textual percentage or not
  1401. * @param string Extra information to show (in case we do not show the percentage)
  1402. * @param bool Whether to play with other colors
  1403. * @param int Percentage below which to show a red bar
  1404. * @param int Percentage below which to show an orange bar
  1405. * @param int Percentage below which to show a blue bar (normal)
  1406. * @assert (null) === false
  1407. */
  1408. public static function bar_progress(
  1409. $percentage,
  1410. $show_percentage = true,
  1411. $extra_info = null,
  1412. $colors = false,
  1413. $fail = 50,
  1414. $warn = 60,
  1415. $normal = 80
  1416. ) {
  1417. $percentage = intval($percentage);
  1418. $type = '';
  1419. if ($colors) {
  1420. $type = 'progress-success';
  1421. if ($percentage < $fail) {
  1422. $type = 'progress-danger';
  1423. } elseif ($percentage < $warn) {
  1424. $type = 'progress-warning';
  1425. } elseif ($percentage < $normal) {
  1426. $type = '';
  1427. }
  1428. }
  1429. $div = '<div class="progress progress-striped '.$type.'">
  1430. <div class="bar" style="width: '.$percentage.'%;"></div>
  1431. </div>';
  1432. if ($show_percentage) {
  1433. $div .= '<div class="progresstext">'.$percentage.'%</div>';
  1434. } else {
  1435. if (!empty($extra_info)) {
  1436. $div .= '<div class="progresstext">'.$extra_info.'</div>';
  1437. }
  1438. }
  1439. return $div;
  1440. }
  1441. public static function badge($count, $type = "warning")
  1442. {
  1443. $class = '';
  1444. switch ($type) {
  1445. case 'success':
  1446. $class = 'badge-success';
  1447. break;
  1448. case 'warning':
  1449. $class = 'badge-warning';
  1450. break;
  1451. case 'important':
  1452. $class = 'badge-important';
  1453. break;
  1454. case 'info':
  1455. $class = 'badge-info';
  1456. break;
  1457. case 'inverse':
  1458. $class = 'badge-inverse';
  1459. break;
  1460. }
  1461. if (!empty($count)) {
  1462. return ' <span class="badge '.$class.'">'.$count.'</span>';
  1463. }
  1464. return null;
  1465. }
  1466. public static function badge_group($badge_list)
  1467. {
  1468. $html = '<div class="badge-group">';
  1469. foreach ($badge_list as $badge) {
  1470. $html .= $badge;
  1471. }
  1472. $html .= '</div>';
  1473. return $html;
  1474. }
  1475. public static function label($content, $type = null, $full_content = null)
  1476. {
  1477. $class = '';
  1478. switch ($type) {
  1479. case 'success':
  1480. $class = 'label-success';
  1481. break;
  1482. case 'warning':
  1483. $class = 'label-warning';
  1484. break;
  1485. case 'important':
  1486. $class = 'label-important';
  1487. break;
  1488. case 'info':
  1489. $class = 'label-info';
  1490. break;
  1491. case 'inverse':
  1492. $class = 'label-inverse';
  1493. break;
  1494. }
  1495. $html = '';
  1496. if (!empty($content)) {
  1497. $html = '<span title="'.$full_content.'" class="label '.$class.'">';
  1498. $html .= $content;
  1499. $html .= '</span>';
  1500. }
  1501. return $html;
  1502. }
  1503. /**
  1504. * Return a list of actions in a div
  1505. * @param array array(array('content' => 'Hello', 'url' => 'chamilo.org'));
  1506. * @return string
  1507. */
  1508. public static function actions($items)
  1509. {
  1510. $html = null;
  1511. if (!empty($items)) {
  1512. $html = '<div class="new_actions"><ul class="nav nav-pills">';
  1513. foreach ($items as $value) {
  1514. $class = null;
  1515. if (isset($value['active']) && $value['active']) {
  1516. $class = 'class ="active"';
  1517. }
  1518. $html .= "<li $class >";
  1519. $html .= self::url($value['content'], $value['url']);
  1520. $html .= '</li>';
  1521. }
  1522. $html .= '</ul></div>';
  1523. }
  1524. return $html;
  1525. }
  1526. /**
  1527. * Prints a tooltip
  1528. */
  1529. public static function tip($text, $tip)
  1530. {
  1531. if (empty($tip)) {
  1532. return $text;
  1533. }
  1534. return self::span($text, array('class' => 'boot-tooltip', 'title' => strip_tags($tip)));
  1535. }
  1536. public static function generate_accordion($items, $type = 'jquery', $id = null)
  1537. {
  1538. $html = null;
  1539. if (!empty($items)) {
  1540. if (empty($id)) {
  1541. $id = api_get_unique_id();
  1542. }
  1543. if ($type == 'jquery') {
  1544. $html = '<div class="accordion_jquery" id="'.$id.'">'; //using jquery
  1545. } else {
  1546. $html = '<div class="accordion" id="'.$id.'">'; //using bootstrap
  1547. }
  1548. $count = 1;
  1549. foreach ($items as $item) {
  1550. $html .= '<div class="accordion-my-group">';
  1551. $html .= '<div class="accordion-heading">
  1552. <a class="accordion-toggle" data-toggle="collapse" data-parent="#'.$id.'" href="#collapse'.$count.'">
  1553. '.$item['title'].'
  1554. </a>
  1555. </div>';
  1556. //$html .= '<div id="collapse'.$count.'" class="accordion-body collapse in">
  1557. $html .= '<div id="collapse'.$count.'" class="accordion-body">';
  1558. //$html .= '<div class="accordion-inner">
  1559. $html .= '<div class="accordion-my-inner">
  1560. '.$item['content'].'
  1561. </div>
  1562. </div>';
  1563. }
  1564. $html .= '</div>';
  1565. }
  1566. return $html;
  1567. }
  1568. /**
  1569. * @todo use twig
  1570. */
  1571. static function group_button($title, $elements)
  1572. {
  1573. $html = '<div class="btn-toolbar">
  1574. <div class="btn-group">
  1575. <button class="btn dropdown-toggle" data-toggle="dropdown">'.$title.' <span class="caret"></span></button>
  1576. <ul class="dropdown-menu">';
  1577. foreach ($elements as $item) {
  1578. $html .= Display::tag('li', Display::url($item['title'], $item['href']));
  1579. }
  1580. $html .= '</ul>
  1581. </div> </div>';
  1582. return $html;
  1583. }
  1584. } //end class Display