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