display.lib.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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. all public functions are stored inside the Display class
  17. CLASS Display
  18. public functions inside
  19. ----------------
  20. Display::display_localised_html_file($full_file_name)
  21. Display::display_table_header()
  22. Display::display_complex_table_header($properties, $column_header)
  23. Display::display_table_row($bgcolor, $table_row, $is_alternating=true)
  24. Display::display_table_footer()
  25. Display::display_normal_message($message)
  26. Display::display_error_message($message)
  27. Display::encrypted_mailto_link($email, $clickable_text, $style_class='')
  28. Display::get_platform_home_link_html($name = '')
  29. */
  30. /**
  31. * Display class
  32. * contains several public functions dealing with the display of
  33. * table data, messages, help topics, ...
  34. *
  35. * @version 1.0.4
  36. * @package dokeos.library
  37. */
  38. require_once 'sortabletable.class.php';
  39. class Display {
  40. private function __construct() {
  41. }
  42. /**
  43. * Displays the tool introduction of a tool.
  44. *
  45. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  46. * @param string $tool These are the constants that are used for indicating the tools.
  47. * @param array $editor_config Optional configuration settings for the online editor.
  48. * @return $tool return a string array list with the "define" in main_api.lib
  49. * @return html code for adding an introduction
  50. */
  51. public static function display_introduction_section ($tool, $editor_config = null) {
  52. $is_allowed_to_edit = api_is_allowed_to_edit();
  53. $moduleId = $tool;
  54. if (api_get_setting('enable_tool_introduction') == 'true' || $tool==TOOL_COURSE_HOMEPAGE)
  55. {
  56. include (api_get_path(INCLUDE_PATH)."introductionSection.inc.php");
  57. }
  58. }
  59. /**
  60. * Displays a localised html file
  61. * tries to show the file "$full_file_name"."_".$language_interface.".html"
  62. * and if this does not exist, shows the file "$full_file_name".".html"
  63. * warning this public function defines a global
  64. * @param $full_file_name, the (path) name of the file, without .html
  65. * @return return a string with the path
  66. */
  67. public static function display_localised_html_file ($full_file_name) {
  68. global $language_interface;
  69. $localised_file_name = $full_file_name."_".$language_interface.".html";
  70. $default_file_name = $full_file_name.".html";
  71. if (file_exists($localised_file_name))
  72. {
  73. include ($localised_file_name);
  74. }
  75. else
  76. {
  77. include ($default_file_name); //default
  78. }
  79. }
  80. /**
  81. * Display simple html header of table.
  82. */
  83. public static function display_table_header () {
  84. $bgcolor = "bgcolor='white'";
  85. echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"85%\"><tbody>";
  86. return $bgcolor;
  87. }
  88. /**
  89. * Display html header of table with several options.
  90. *
  91. * @param $properties, array with elements, all of which have defaults
  92. * "width" - the table width, e.g. "100%", default is 85%
  93. * "class" - the class to use for the table, e.g. "class=\"data_table\""
  94. * "cellpadding" - the extra border in each cell, e.g. "8",default is 4
  95. * "cellspacing" - the extra space between cells, default = 0
  96. * @param column_header, array with the header elements.
  97. * @author Roan Embrechts
  98. * @version 1.01
  99. * @return return type string, bgcolor
  100. */
  101. public static function display_complex_table_header ($properties, $column_header) {
  102. $width = $properties["width"];
  103. if (!isset ($width))
  104. $width = "85%";
  105. $class = $properties["class"];
  106. if (!isset ($class))
  107. $class = "class=\"data_table\"";
  108. $cellpadding = $properties["cellpadding"];
  109. if (!isset ($cellpadding))
  110. $cellpadding = "4";
  111. $cellspacing = $properties["cellspacing"];
  112. if (!isset ($cellspacing))
  113. $cellspacing = "0";
  114. //... add more properties as you see fit
  115. //api_display_debug_info("Dokeos light grey is " . DOKEOSLIGHTGREY);
  116. $bgcolor = "bgcolor='".DOKEOSLIGHTGREY."'";
  117. echo "<table $class border=\"0\" cellspacing=\"$cellspacing\" cellpadding=\"$cellpadding\" width=\"$width\">\n";
  118. echo "<thead><tr $bgcolor>";
  119. foreach ($column_header as $table_element)
  120. {
  121. echo "<th>".$table_element."</th>";
  122. }
  123. echo "</tr></thead>\n";
  124. echo "<tbody>\n";
  125. $bgcolor = "bgcolor='".HTML_WHITE."'";
  126. return $bgcolor;
  127. }
  128. /**
  129. * Displays a table row.
  130. *
  131. * @param $bgcolor the background colour for the table
  132. * @param $table_row an array with the row elements
  133. * @param $is_alternating true: the row colours alternate, false otherwise
  134. */
  135. public static function display_table_row ($bgcolor, $table_row, $is_alternating = true) {
  136. echo "<tr $bgcolor>";
  137. foreach ($table_row as $table_element)
  138. {
  139. echo "<td>".$table_element."</td>";
  140. }
  141. echo "</tr>\n";
  142. if ($is_alternating)
  143. {
  144. if ($bgcolor == "bgcolor='".HTML_WHITE."'")
  145. {
  146. $bgcolor = "bgcolor='".DOKEOSLIGHTGREY."'";
  147. }
  148. else
  149. {
  150. if ($bgcolor == "bgcolor='".DOKEOSLIGHTGREY."'")
  151. {
  152. $bgcolor = "bgcolor='".HTML_WHITE."'";
  153. }
  154. }
  155. }
  156. return $bgcolor;
  157. }
  158. /**
  159. * Displays a table row.
  160. * This public function has more options and is easier to extend than display_table_row()
  161. *
  162. * @param $properties, array with properties:
  163. * ["bgcolor"] - the background colour for the table
  164. * ["is_alternating"] - true: the row colours alternate, false otherwise
  165. * ["align_row"] - an array with, per cell, left|center|right
  166. * @todo add valign property
  167. */
  168. public static function display_complex_table_row ($properties, $table_row) {
  169. $bgcolor = $properties["bgcolor"];
  170. $is_alternating = $properties["is_alternating"];
  171. $align_row = $properties["align_row"];
  172. echo "<tr $bgcolor>";
  173. $number_cells = count($table_row);
  174. for ($i = 0; $i < $number_cells; $i ++)
  175. {
  176. $cell_data = $table_row[$i];
  177. $cell_align = $align_row[$i];
  178. echo "<td align=\"$cell_align\">".$cell_data."</td>";
  179. }
  180. echo "</tr>\n";
  181. if ($is_alternating)
  182. {
  183. if ($bgcolor == "bgcolor='".HTML_WHITE."'")
  184. $bgcolor = "bgcolor='".DOKEOSLIGHTGREY."'";
  185. else
  186. if ($bgcolor == "bgcolor='".DOKEOSLIGHTGREY."'")
  187. $bgcolor = "bgcolor='".HTML_WHITE."'";
  188. }
  189. return $bgcolor;
  190. }
  191. /**
  192. * display html footer of table
  193. */
  194. public static function display_table_footer() {
  195. echo "</tbody></table>";
  196. }
  197. /**
  198. * Display a table
  199. * @param array $header Titles for the table header
  200. * each item in this array can contain 3 values
  201. * - 1st element: the column title
  202. * - 2nd element: true or false (column sortable?)
  203. * - 3th element: additional attributes for
  204. * th-tag (eg for column-width)
  205. * - 4the element: additional attributes for the td-tags
  206. * @param array $content 2D-array with the tables content
  207. * @param array $sorting_options Keys are:
  208. * 'column' = The column to use as sort-key
  209. * 'direction' = SORT_ASC or SORT_DESC
  210. * @param array $paging_options Keys are:
  211. * 'per_page_default' = items per page when switching from
  212. * full- list to per-page-view
  213. * 'per_page' = number of items to show per page
  214. * 'page_nr' = The page to display
  215. * @param array $query_vars Additional variables to add in the query-string
  216. * @param string The style that the table will show. You can set 'table' or 'grid'
  217. * @author bart.mollet@hogent.be
  218. */
  219. public static function display_sortable_table ($header, $content, $sorting_options = array (), $paging_options = array (), $query_vars = null, $form_actions=array(), $style='table') {
  220. global $origin;
  221. $column = isset ($sorting_options['column']) ? $sorting_options['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);
  224. if (is_array($query_vars)) {
  225. $table->set_additional_parameters($query_vars);
  226. }
  227. if ($style=='table') {
  228. if (is_array($header) && count($header)>0 ) {
  229. foreach ($header as $index => $header_item) {
  230. $table->set_header($index, $header_item[0], $header_item[1], $header_item[2], $header_item[3]);
  231. }
  232. }
  233. $table->set_form_actions($form_actions);
  234. $table->display();
  235. } else {
  236. $table->display_grid();
  237. }
  238. }
  239. /**
  240. * Shows a nice grid
  241. * @param string grid name (important to create css)
  242. * @param array header content
  243. * @param array array with the information to show
  244. * @param array $paging_options Keys are:
  245. * 'per_page_default' = items per page when switching from
  246. * full- list to per-page-view
  247. * 'per_page' = number of items to show per page
  248. * 'page_nr' = The page to display
  249. * 'hide_navigation' = true to hide the navigation
  250. * @param array $query_vars Additional variables to add in the query-string
  251. * @param array $form actions Additional variables to add in the query-string
  252. * @param mixed An array with bool values to know which columns show. i.e: $vibility_options= array(true, false) we will only show the first column
  253. * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
  254. */
  255. public static function display_sortable_grid ($name, $header, $content, $paging_options = array (), $query_vars = null, $form_actions=array(), $vibility_options = true) {
  256. global $origin;
  257. $column = 0;
  258. $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  259. $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name);
  260. if (is_array($query_vars)) {
  261. $table->set_additional_parameters($query_vars);
  262. }
  263. echo $table->display_simple_grid($vibility_options, $paging_options['hide_navigation']);
  264. }
  265. /**
  266. * gets a nice grid in html string
  267. * @param string grid name (important to create css)
  268. * @param array header content
  269. * @param array array with the information to show
  270. * @param array $paging_options Keys are:
  271. * 'per_page_default' = items per page when switching from
  272. * full- list to per-page-view
  273. * 'per_page' = number of items to show per page
  274. * 'page_nr' = The page to display
  275. * 'hide_navigation' = true to hide the navigation
  276. * @param array $query_vars Additional variables to add in the query-string
  277. * @param array $form actions Additional variables to add in the query-string
  278. * @param mixed An array with bool values to know which columns show. i.e: $vibility_options= array(true, false) we will only show the first column
  279. * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
  280. * @param bool true for sorting data or false otherwise
  281. * @return string html grid
  282. */
  283. public static function return_sortable_grid ($name, $header, $content, $paging_options = array (), $query_vars = null, $form_actions=array(), $vibility_options = true, $sort_data = true) {
  284. global $origin;
  285. $column = 0;
  286. $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  287. $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name);
  288. if (is_array($query_vars)) {
  289. $table->set_additional_parameters($query_vars);
  290. }
  291. //var_dump($table->get_additional_url_paramstring());
  292. return $table->display_simple_grid($vibility_options, $paging_options['hide_navigation'], $paging_options['per_page'], $sort_data);
  293. }
  294. /**
  295. * Display a table with a special configuration
  296. * @param array $header Titles for the table header
  297. * each item in this array can contain 3 values
  298. * - 1st element: the column title
  299. * - 2nd element: true or false (column sortable?)
  300. * - 3th element: additional attributes for
  301. * th-tag (eg for column-width)
  302. * - 4the element: additional attributes for the td-tags
  303. * @param array $content 2D-array with the tables content
  304. * @param array $sorting_options Keys are:
  305. * 'column' = The column to use as sort-key
  306. * 'direction' = SORT_ASC or SORT_DESC
  307. * @param array $paging_options Keys are:
  308. * 'per_page_default' = items per page when switching from
  309. * full- list to per-page-view
  310. * 'per_page' = number of items to show per page
  311. * 'page_nr' = The page to display
  312. * @param array $query_vars Additional variables to add in the query-string
  313. * @param array $column_show Array of binaries 1= show columns 0. hide a column
  314. * @param array $column_order An array of integers that let us decide how the columns are going to be sort.
  315. * i.e: $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column
  316. * @param array $form_actions Set optional forms actions
  317. *
  318. * @author Julio Montoya
  319. */
  320. public static function display_sortable_config_table ($header, $content, $sorting_options = array (), $paging_options = array (), $query_vars = null, $column_show=array(),$column_order=array(),$form_actions=array()) {
  321. global $origin;
  322. $column = isset ($sorting_options['column']) ? $sorting_options['column'] : 0;
  323. $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  324. $table = new SortableTableFromArrayConfig($content, $column, $default_items_per_page,'tablename',$column_show,$column_order);
  325. if (is_array($query_vars)) {
  326. $table->set_additional_parameters($query_vars);
  327. }
  328. // show or hide the columns header
  329. if (is_array($column_show) )
  330. {
  331. for ($i=0;$i<count($column_show);$i++)
  332. {
  333. if (!empty($column_show[$i]))
  334. {
  335. isset($header[$i][0])?$val0=$header[$i][0]:$val0=null;
  336. isset($header[$i][1])?$val1=$header[$i][1]:$val1=null;
  337. isset($header[$i][2])?$val2=$header[$i][2]:$val2=null;
  338. isset($header[$i][3])?$val3=$header[$i][3]:$val3=null;
  339. $table->set_header($i, $val0, $val1, $val2, $val3);
  340. }
  341. }
  342. }
  343. $table->set_form_actions($form_actions);
  344. $table->display();
  345. }
  346. /**
  347. * Displays a normal message. It is recommended to use this public function
  348. * to display any normal information messages.
  349. *
  350. * @author Roan Embrechts
  351. * @param string $message - include any additional html
  352. * tags if you need them
  353. * @param bool Filter (true) or not (false)
  354. * @return void
  355. */
  356. public static function display_normal_message ($message,$filter=true) {
  357. global $charset;
  358. if($filter) {
  359. //filter message
  360. $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : $charset);
  361. }
  362. if (!headers_sent())
  363. {
  364. echo '
  365. <style type="text/css" media="screen, projection">
  366. /*<![CDATA[*/
  367. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  368. /*]]>*/
  369. </style>';
  370. }
  371. echo '<div class="normal-message">';
  372. //Display :: display_icon('message_normal.gif', get_lang('InfoMessage'), array ('style' => 'float:left; margin-right:10px;'));
  373. /*
  374. get_lang('InfoMessage', array ('style' => 'float:left; margin-right:10px;'));
  375. */
  376. echo $message.'</div>';
  377. }
  378. /**
  379. * Displays an warning message. Use this if you want to draw attention to something
  380. * This can also be used for instance with the hint in the exercises
  381. *
  382. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  383. * @param string $message
  384. * @param bool Filter (true) or not (false)
  385. * @return void
  386. */
  387. public static function display_warning_message ($message,$filter=true) {
  388. global $charset;
  389. if($filter){
  390. //filter message
  391. $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : $charset);
  392. }
  393. if (!headers_sent())
  394. {
  395. echo '
  396. <style type="text/css" media="screen, projection">
  397. /*<![CDATA[*/
  398. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  399. /*]]>*/
  400. </style>';
  401. }
  402. echo '<div class="warning-message">';
  403. //Display :: display_icon('message_warning.png', get_lang('WarningMessage'), array ('style' => 'float:left; margin-right:10px;'));
  404. /*
  405. get_lang('WarningMessage', array ('style' => 'float:left; margin-right:10px;'));
  406. */
  407. echo $message.'</div>';
  408. }
  409. /**
  410. * Displays an confirmation message. Use this if something has been done successfully
  411. *
  412. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  413. * @param string $message
  414. * @param bool Filter (true) or not (false)
  415. * @return void
  416. */
  417. public static function display_confirmation_message ($message,$filter=true) {
  418. global $charset;
  419. if($filter){
  420. //filter message
  421. $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : $charset);
  422. }
  423. if (!headers_sent())
  424. {
  425. echo '
  426. <style type="text/css" media="screen, projection">
  427. /*<![CDATA[*/
  428. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  429. /*]]>*/
  430. </style>';
  431. }
  432. echo '<div class="confirmation-message">';
  433. //Display :: display_icon('message_confirmation.gif', get_lang('ConfirmationMessage'), array ('style' => 'float:left; margin-right:10px;margin-left:5px;'));
  434. /*
  435. get_lang('ConfirmationMessage', array ('style' => 'float:left; margin-right:10px;margin-left:5px;'));
  436. */
  437. echo $message.'</div>';
  438. }
  439. /**
  440. * Displays an error message. It is recommended to use this public function if an error occurs
  441. *
  442. * @author Hugues Peeters
  443. * @author Roan Embrechts
  444. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  445. * @param string $message - include any additional html
  446. * tags if you need them
  447. * @param bool Filter (true) or not (false)
  448. * @return void
  449. */
  450. public static function display_error_message ($message,$filter=true) {
  451. global $charset;
  452. if($filter){
  453. //filter message
  454. $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : $charset);
  455. }
  456. if (!headers_sent())
  457. {
  458. echo '
  459. <style type="text/css" media="screen, projection">
  460. /*<![CDATA[*/
  461. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  462. /*]]>*/
  463. </style>';
  464. }
  465. echo '<div class="error-message">';
  466. //Display :: display_icon('message_error.png', get_lang('ErrorMessage'), array ('style' => 'float:left; margin-right:10px;'));
  467. /*
  468. get_lang('ErrorMessage', array ('style' => 'float:left; margin-right:10px;'));
  469. */
  470. echo $message.'</div>';
  471. }
  472. /**
  473. * Return an encrypted mailto hyperlink
  474. *
  475. * @param - $email (string) - e-mail
  476. * @param - $text (string) - clickable text
  477. * @param - $style_class (string) - optional, class from stylesheet
  478. * @return - encrypted mailto hyperlink
  479. */
  480. public static function encrypted_mailto_link ($email, $clickable_text = null, $style_class = '') {
  481. global $charset;
  482. if (is_null($clickable_text))
  483. {
  484. $clickable_text = $email;
  485. }
  486. //mailto already present?
  487. if (substr($email, 0, 7) != 'mailto:') {
  488. $email = 'mailto:'.$email;
  489. }
  490. //class (stylesheet) defined?
  491. if ($style_class != '') {
  492. $style_class = ' class="'.$style_class.'"';
  493. }
  494. //encrypt email
  495. $hmail = '';
  496. for ($i = 0; $i < strlen($email); $i ++) {
  497. $hmail .= '&#'.ord($email {
  498. $i }).';';
  499. }
  500. //encrypt clickable text if @ is present
  501. if (strpos($clickable_text, '@')) {
  502. for ($i = 0; $i < strlen($clickable_text); $i ++) {
  503. $hclickable_text .= '&#'.ord($clickable_text {
  504. $i }).';';
  505. }
  506. } else {
  507. $hclickable_text = htmlspecialchars($clickable_text,ENT_QUOTES,$charset);
  508. }
  509. //return encrypted mailto hyperlink
  510. return '<a href="'.$hmail.'"'.$style_class.' name="clickable_email_link">'.$hclickable_text.'</a>';
  511. }
  512. /**
  513. * Create a hyperlink to the platform homepage.
  514. * @param string $name, the visible name of the hyperlink, default is sitename
  515. * @return string with html code for hyperlink
  516. */
  517. public static function get_platform_home_link_html ($name = '') {
  518. if ($name == '')
  519. {
  520. $name = api_get_setting('siteName');
  521. }
  522. return "<a href=\"".api_get_path(WEB_PATH)."index.php\">$name</a>";
  523. }
  524. /**
  525. * Display the page header
  526. * @param string The name of the page (will be showed in the page title)
  527. * @param string Optional help file name
  528. */
  529. public static function display_header ($tool_name ='', $help = NULL) {
  530. $nameTools = $tool_name;
  531. global $_plugins,$lp_theme_css,$mycoursetheme,$user_theme,$platform_theme;
  532. global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $clarolineRepositoryWeb, $text_dir, $plugins, $_user, $rootAdminWeb, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF;
  533. global $menu_navigation;
  534. include (api_get_path(INCLUDE_PATH)."header.inc.php");
  535. }
  536. /**
  537. * Display the reduced page header (without banner)
  538. */
  539. public static function display_reduced_header () {
  540. global $_plugins,$lp_theme_css,$mycoursetheme,$user_theme,$platform_theme;
  541. global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $clarolineRepositoryWeb, $text_dir, $plugins, $_user, $rootAdminWeb, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF, $language_interface;
  542. global $menu_navigation;
  543. include (api_get_path(INCLUDE_PATH)."reduced_header.inc.php");
  544. }
  545. /**
  546. * Display the page footer
  547. */
  548. public static function display_footer () {
  549. global $_plugins;
  550. include (api_get_path(INCLUDE_PATH)."footer.inc.php");
  551. }
  552. /**
  553. * Print an <option>-list with all letters (A-Z).
  554. * @param char $selected_letter The letter that should be selected
  555. */
  556. public static function get_alphabet_options ($selected_letter = '') {
  557. $result = '';
  558. for ($i = 65; $i <= 90; $i ++) {
  559. $letter = chr($i);
  560. $result .= '<option value="'.$letter.'"';
  561. if ($selected_letter == $letter) {
  562. $result .= ' selected="selected"';
  563. }
  564. $result .= '>'.$letter.'</option>';
  565. }
  566. return $result;
  567. }
  568. public static function get_numeric_options ($min,$max, $selected_num = 0) {
  569. $result = '';
  570. for ($i = $min; $i <= $max; $i ++) {
  571. $result .= '<option value="'.$i.'"';
  572. if (is_int($selected_num))
  573. if ($selected_num == $i) {
  574. $result .= ' selected="selected"';
  575. }
  576. $result .= '>'.$i.'</option>';
  577. }
  578. return $result;
  579. }
  580. /**
  581. * Show the so-called "left" menu for navigating
  582. */
  583. public static function show_course_navigation_menu ($isHidden = false) {
  584. global $output_string_menu;
  585. global $_setting;
  586. // check if the $_SERVER['REQUEST_URI'] contains already url parameters (thus a questionmark)
  587. if (!strstr($_SERVER['REQUEST_URI'], "?"))
  588. {
  589. $sourceurl = api_get_self()."?";
  590. }
  591. else
  592. {
  593. $sourceurl = $_SERVER['REQUEST_URI'];
  594. }
  595. $output_string_menu = "";
  596. if ($isHidden == "true" and $_SESSION["hideMenu"]) {
  597. $_SESSION["hideMenu"] = "hidden";
  598. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  599. $sourceurl = str_replace("&isHidden=false", "", $sourceurl);
  600. $output_string_menu .= " <a href='".$sourceurl."&isHidden=false'>"."<img src=../../main/img/expand.gif alt='Show menu1' padding:'2px'/>"."</a>";
  601. }
  602. elseif ($isHidden == "false" and $_SESSION["hideMenu"])
  603. {
  604. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  605. $sourceurl = str_replace("&isHidden=false", "", $sourceurl);
  606. $_SESSION["hideMenu"] = "shown";
  607. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src=../../main/img/collapse.gif alt='Hide menu2' padding:'2px'/>"."</a></div>";
  608. }
  609. elseif ($_SESSION["hideMenu"])
  610. {
  611. if ($_SESSION["hideMenu"] == "shown") {
  612. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src='../../main/img/collapse.gif' alt='Hide menu3' padding:'2px'/>"."</a></div>";
  613. }
  614. if ($_SESSION["hideMenu"] == "hidden") {
  615. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  616. $output_string_menu .= "<a href='".$sourceurl."&isHidden=false'>"."<img src='../../main/img/expand.gif' alt='Hide menu4' padding:'2px'/>"."</a>";
  617. }
  618. }
  619. elseif (!$_SESSION["hideMenu"])
  620. {
  621. $_SESSION["hideMenu"] = "shown";
  622. if (isset ($_cid))
  623. {
  624. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src='main/img/collapse.gif' alt='Hide menu5' padding:'2px'/>"."</a></div>";
  625. }
  626. }
  627. }
  628. /**
  629. * This public function displays an icon
  630. * @param string $image the filename of the file (in the main/img/ folder
  631. * @param string $alt_text the alt text (probably a language variable)
  632. * @param array additional attributes (for instance height, width, onclick, ...)
  633. */
  634. public static function display_icon ($image, $alt_text = '', $additional_attributes = array ()) {
  635. echo Display::return_icon($image,$alt_text,$additional_attributes);
  636. }
  637. /**
  638. * This public function returns the htmlcode for an icon
  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. *
  644. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  645. * @version October 2006
  646. */
  647. public static function return_icon ($image,$alt_text='',$additional_attributes=array()) {
  648. $attribute_list = '';
  649. // alt text = the image if there is none provided (for XHTML compliance)
  650. if ($alt_text=='')
  651. {
  652. $alt_text=$image;
  653. }
  654. // managing the additional attributes
  655. if (!empty($additional_attributes) and is_array($additional_attributes))
  656. {
  657. $attribute_list='';
  658. foreach ($additional_attributes as $key=>$value)
  659. {
  660. $attribute_list.=$key.'="'.$value.'" ';
  661. }
  662. }
  663. return '<img src="'.api_get_path(WEB_IMG_PATH).$image.'" alt="'.$alt_text.'" title="'.$alt_text.'" '.$attribute_list.' />';
  664. }
  665. /**
  666. * Ivan, 05-SEP-2009: Deprecated, see api_get_person_name().
  667. *
  668. * Display name and lastname in a specific order
  669. * @param string Firstname
  670. * @param string Lastname
  671. * @param string Title in the destination language (Dr, Mr, Miss, Sr, Sra, etc)
  672. * @param string Optional format string (e.g. '%t. %l, %f')
  673. * @author Carlos Vargas <carlos.vargas@dokeos.com>
  674. */
  675. public static function user_name($fname,$lname,$title='',$format=null) {
  676. if (empty($format)){
  677. if (empty($fname) or empty($lname)) {
  678. $user_name = $fname.$lname;
  679. } else {
  680. $user_name= $fname.' '.$lname;
  681. }
  682. } else {
  683. $find = array('%t','%f','%l');
  684. $repl = array($title,$fname,$lname);
  685. $user_name = str_replace($find,$repl,$format);
  686. }
  687. return $user_name;
  688. }
  689. } //end class Display
  690. ?>