display.lib.php 55 KB

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