display.lib.php 52 KB

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