display.lib.php 57 KB

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