display.lib.php 25 KB

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