display.lib.php 55 KB

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