display.lib.php 55 KB

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