display.lib.php 61 KB

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