display.lib.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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 functionality.
  30. * There are also several display functions in the main api library.
  31. *
  32. * All functions static 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. FUNCTIONS
  53. ==============================================================================
  54. */
  55. //all functions are stored inside the Display class
  56. /*
  57. ==============================================================================
  58. CLASS Display
  59. 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 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. 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 function defines a global
  105. *
  106. * @param $full_file_name, the (path) name of the file, without .html
  107. */
  108. 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. 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. 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. 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 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. 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. 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. 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. 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 ($column_show[$i])
  322. {
  323. $table->set_header($i, $header[$i][0], $header[$i][1], $header[$i][2], $header[$i][3]);
  324. }
  325. }
  326. }
  327. $table->set_form_actions($form_actions);
  328. $table->display();
  329. }
  330. /**
  331. * Displays a normal message. It is recommended to use this function
  332. * to display any normal information messages.
  333. *
  334. * @author Roan Embrechts
  335. * @param string $message - include any additional html
  336. * tags if you need them
  337. * @param bool Filter (true) or not (false)
  338. * @return void
  339. */
  340. function display_normal_message($message,$filter=true)
  341. {
  342. global $charset;
  343. if($filter)
  344. {
  345. //filter message
  346. $message = htmlentities($message,ENT_QUOTES,$charset);
  347. }
  348. if (!headers_sent())
  349. {
  350. echo '
  351. <style type="text/css" media="screen, projection">
  352. /*<![CDATA[*/
  353. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  354. /*]]>*/
  355. </style>';
  356. }
  357. echo '<div class="normal-message">';
  358. Display :: display_icon('message_normal.gif', '', array ('style' => 'float:left; margin-right:10px;'));
  359. echo "<div style='margin-left: 43px'>".$message.'</div></div>';
  360. }
  361. /**
  362. * Displays an warning message. Use this if you want to draw attention to something
  363. * This can also be used for instance with the hint in the exercises
  364. *
  365. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  366. * @param string $message
  367. * @param bool Filter (true) or not (false)
  368. * @return void
  369. */
  370. function display_warning_message($message,$filter=true)
  371. {
  372. global $charset;
  373. if($filter){
  374. //filter message
  375. $message = htmlentities($message,ENT_QUOTES,$charset);
  376. }
  377. if (!headers_sent())
  378. {
  379. echo '
  380. <style type="text/css" media="screen, projection">
  381. /*<![CDATA[*/
  382. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  383. /*]]>*/
  384. </style>';
  385. }
  386. echo '<div class="warning-message">';
  387. Display :: display_icon('message_warning.png', '', array ('style' => 'float:left; margin-right:10px;'));
  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. function display_confirmation_message($message,$filter=true)
  399. {
  400. global $charset;
  401. if($filter){
  402. //filter message
  403. $message = htmlentities($message,ENT_QUOTES,$charset);
  404. }
  405. if (!headers_sent())
  406. {
  407. echo '
  408. <style type="text/css" media="screen, projection">
  409. /*<![CDATA[*/
  410. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  411. /*]]>*/
  412. </style>';
  413. }
  414. echo '<div class="confirmation-message">';
  415. Display :: display_icon('message_confirmation.gif', '', array ('style' => 'float:left; margin-right:10px;'));
  416. echo $message.'</div>';
  417. }
  418. /**
  419. * Displays an error message. It is recommended to use this function if an error occurs
  420. *
  421. * @author Hugues Peeters
  422. * @author Roan Embrechts
  423. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  424. * @param string $message - include any additional html
  425. * tags if you need them
  426. * @param bool Filter (true) or not (false)
  427. * @return void
  428. */
  429. function display_error_message($message,$filter=true)
  430. {
  431. global $charset;
  432. if($filter){
  433. //filter message
  434. $message = htmlentities($message,ENT_QUOTES,$charset);
  435. }
  436. if (!headers_sent())
  437. {
  438. echo '
  439. <style type="text/css" media="screen, projection">
  440. /*<![CDATA[*/
  441. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  442. /*]]>*/
  443. </style>';
  444. }
  445. echo '<div class="error-message">';
  446. Display :: display_icon('message_error.png', '', array ('style' => 'float:left; margin-right:10px;'));
  447. echo $message.'</div>';
  448. }
  449. /**
  450. * Return an encrypted mailto hyperlink
  451. *
  452. * @param - $email (string) - e-mail
  453. * @param - $text (string) - clickable text
  454. * @param - $style_class (string) - optional, class from stylesheet
  455. * @return - encrypted mailto hyperlink
  456. */
  457. function encrypted_mailto_link($email, $clickable_text = null, $style_class = '')
  458. {
  459. global $charset;
  460. if (is_null($clickable_text))
  461. {
  462. $clickable_text = $email;
  463. }
  464. //mailto already present?
  465. if (substr($email, 0, 7) != 'mailto:')
  466. $email = 'mailto:'.$email;
  467. //class (stylesheet) defined?
  468. if ($style_class != '')
  469. $style_class = ' class="'.$style_class.'"';
  470. //encrypt email
  471. $hmail = '';
  472. for ($i = 0; $i < strlen($email); $i ++)
  473. $hmail .= '&#'.ord($email {
  474. $i }).';';
  475. //encrypt clickable text if @ is present
  476. if (strpos($clickable_text, '@'))
  477. {
  478. for ($i = 0; $i < strlen($clickable_text); $i ++)
  479. $hclickable_text .= '&#'.ord($clickable_text {
  480. $i }).';';
  481. }
  482. else
  483. {
  484. $hclickable_text = htmlspecialchars($clickable_text,ENT_QUOTES,$charset);
  485. }
  486. //return encrypted mailto hyperlink
  487. return '<a href="'.$hmail.'"'.$style_class.' name="clickable_email_link">'.$hclickable_text.'</a>';
  488. }
  489. /**
  490. * Create a hyperlink to the platform homepage.
  491. * @param string $name, the visible name of the hyperlink, default is sitename
  492. * @return string with html code for hyperlink
  493. */
  494. function get_platform_home_link_html($name = '')
  495. {
  496. if ($name == '')
  497. {
  498. $name = api_get_setting('siteName');
  499. }
  500. return "<a href=\"".api_get_path(WEB_PATH)."index.php\">$name</a>";
  501. }
  502. /**
  503. * Display the page header
  504. * @param string The name of the page (will be showed in the page title)
  505. * @param string Optional help file name
  506. */
  507. function display_header($tool_name, $help = NULL)
  508. {
  509. $nameTools = $tool_name;
  510. global $_plugins,$lp_theme_css,$mycoursetheme,$user_theme,$platform_theme;
  511. global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $clarolineRepositoryWeb, $text_dir, $plugins, $_user, $rootAdminWeb, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF;
  512. global $menu_navigation;
  513. include (api_get_path(INCLUDE_PATH)."header.inc.php");
  514. }
  515. /**
  516. * Display the page footer
  517. */
  518. function display_footer()
  519. {
  520. global $dokeos_version; //necessary to have the value accessible in the footer
  521. global $_plugins;
  522. include (api_get_path(INCLUDE_PATH)."footer.inc.php");
  523. }
  524. /**
  525. * Print an <option>-list with all letters (A-Z).
  526. * @param char $selected_letter The letter that should be selected
  527. */
  528. function get_alphabet_options($selected_letter = '')
  529. {
  530. $result = '';
  531. for ($i = 65; $i <= 90; $i ++) {
  532. $letter = chr($i);
  533. $result .= '<option value="'.$letter.'"';
  534. if ($selected_letter == $letter) {
  535. $result .= ' selected="selected"';
  536. }
  537. $result .= '>'.$letter.'</option>';
  538. }
  539. return $result;
  540. }
  541. /**
  542. * Show the so-called "left" menu for navigating
  543. */
  544. function show_course_navigation_menu($isHidden = false)
  545. {
  546. global $output_string_menu;
  547. global $_setting;
  548. // check if the $_SERVER['REQUEST_URI'] contains already url parameters (thus a questionmark)
  549. if (!strstr($_SERVER['REQUEST_URI'], "?"))
  550. {
  551. $sourceurl = api_get_self()."?";
  552. }
  553. else
  554. {
  555. $sourceurl = $_SERVER['REQUEST_URI'];
  556. }
  557. $output_string_menu = "";
  558. if ($isHidden == "true" and $_SESSION["hideMenu"]) {
  559. $_SESSION["hideMenu"] = "hidden";
  560. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  561. $sourceurl = str_replace("&isHidden=false", "", $sourceurl);
  562. $output_string_menu .= " <a href='".$sourceurl."&isHidden=false'>"."<img src=../../main/img/expand.gif alt='Show menu1' padding:'2px'/>"."</a>";
  563. }
  564. elseif ($isHidden == "false" and $_SESSION["hideMenu"])
  565. {
  566. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  567. $sourceurl = str_replace("&isHidden=false", "", $sourceurl);
  568. $_SESSION["hideMenu"] = "shown";
  569. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src=../../main/img/collapse.gif alt='Hide menu2' padding:'2px'/>"."</a></div>";
  570. }
  571. elseif ($_SESSION["hideMenu"])
  572. {
  573. if ($_SESSION["hideMenu"] == "shown") {
  574. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src='../../main/img/collapse.gif' alt='Hide menu3' padding:'2px'/>"."</a></div>";
  575. }
  576. if ($_SESSION["hideMenu"] == "hidden") {
  577. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  578. $output_string_menu .= "<a href='".$sourceurl."&isHidden=false'>"."<img src='../../main/img/expand.gif' alt='Hide menu4' padding:'2px'/>"."</a>";
  579. }
  580. }
  581. elseif (!$_SESSION["hideMenu"])
  582. {
  583. $_SESSION["hideMenu"] = "shown";
  584. if (isset ($_cid))
  585. {
  586. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src='main/img/collapse.gif' alt='Hide menu5' padding:'2px'/>"."</a></div>";
  587. }
  588. }
  589. }
  590. /**
  591. * This function displays an icon
  592. * @param string $image the filename of the file (in the main/img/ folder
  593. * @param string $alt_text the alt text (probably a language variable)
  594. * @param array additional attributes (for instance height, width, onclick, ...)
  595. */
  596. function display_icon($image, $alt_text = '', $additional_attributes = array ()) {
  597. echo Display::return_icon($image,$alt_text,$additional_attributes);
  598. }
  599. /**
  600. * This function returns the htmlcode for an icon
  601. *
  602. * @param string $image the filename of the file (in the main/img/ folder
  603. * @param string $alt_text the alt text (probably a language variable)
  604. * @param array additional attributes (for instance height, width, onclick, ...)
  605. *
  606. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  607. * @version October 2006
  608. */
  609. function return_icon($image,$alt_text='',$additional_attributes=array())
  610. {
  611. // alt text = the image if there is none provided (for XHTML compliance)
  612. if ($alt_text=='')
  613. {
  614. $alt_text=$image;
  615. }
  616. // managing the additional attributes
  617. if (!empty($additional_attributes) and is_array($additional_attributes))
  618. {
  619. $attribute_list='';
  620. foreach ($additional_attributes as $key=>$value)
  621. {
  622. $attribute_list.=$key.'="'.$value.'" ';
  623. }
  624. }
  625. return '<img src="'.api_get_path(WEB_IMG_PATH).$image.'" alt="'.$alt_text.'" title="'.$alt_text.'" '.$attribute_list.' />';
  626. }
  627. } //end class Display
  628. ?>