display.lib.php 24 KB

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