display.lib.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 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. $is_allowed_to_edit = api_is_allowed_to_edit();
  91. $moduleId = $tool;
  92. if (api_get_setting('enable_tool_introduction') == 'true' || $tool==TOOL_COURSE_HOMEPAGE) {
  93. include (api_get_path(INCLUDE_PATH)."introductionSection.inc.php");
  94. }
  95. }
  96. /*
  97. * Displays a localised html file
  98. *
  99. * tries to show the file "$full_file_name"."_".$language_interface.".html"
  100. * and if this does not exist, shows the file "$full_file_name".".html"
  101. *
  102. * warning this function defines a global
  103. *
  104. * @param $full_file_name, the (path) name of the file, without .html
  105. */
  106. function display_localised_html_file($full_file_name) {
  107. global $language_interface;
  108. $localised_file_name = $full_file_name."_".$language_interface.".html";
  109. $default_file_name = $full_file_name.".html";
  110. if (file_exists($localised_file_name))
  111. {
  112. include ($localised_file_name);
  113. }
  114. else
  115. {
  116. include ($default_file_name); //default
  117. }
  118. }
  119. /**
  120. * Display simple html header of table.
  121. */
  122. function display_table_header()
  123. {
  124. $bgcolor = "bgcolor='white'";
  125. echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"85%\"><tbody>";
  126. return $bgcolor;
  127. }
  128. /**
  129. * Display html header of table with several options.
  130. *
  131. * @param $properties, array with elements, all of which have defaults
  132. * "width" - the table width, e.g. "100%", default is 85%
  133. * "class" - the class to use for the table, e.g. "class=\"data_table\""
  134. * "cellpadding" - the extra border in each cell, e.g. "8",default is 4
  135. * "cellspacing" - the extra space between cells, default = 0
  136. *
  137. * @param column_header, array with the header elements.
  138. * @author Roan Embrechts
  139. * @version 1.01
  140. */
  141. function display_complex_table_header($properties, $column_header)
  142. {
  143. $width = $properties["width"];
  144. if (!isset ($width))
  145. $width = "85%";
  146. $class = $properties["class"];
  147. if (!isset ($class))
  148. $class = "class=\"data_table\"";
  149. $cellpadding = $properties["cellpadding"];
  150. if (!isset ($cellpadding))
  151. $cellpadding = "4";
  152. $cellspacing = $properties["cellspacing"];
  153. if (!isset ($cellspacing))
  154. $cellspacing = "0";
  155. //... add more properties as you see fit
  156. //api_display_debug_info("Dokeos light grey is " . DOKEOSLIGHTGREY);
  157. $bgcolor = "bgcolor='".DOKEOSLIGHTGREY."'";
  158. echo "<table $class border=\"0\" cellspacing=\"$cellspacing\" cellpadding=\"$cellpadding\" width=\"$width\">\n";
  159. echo "<thead><tr $bgcolor>";
  160. foreach ($column_header as $table_element)
  161. {
  162. echo "<th>".$table_element."</th>";
  163. }
  164. echo "</tr></thead>\n";
  165. echo "<tbody>\n";
  166. $bgcolor = "bgcolor='".HTML_WHITE."'";
  167. return $bgcolor;
  168. }
  169. /**
  170. * Displays a table row.
  171. *
  172. * @param $bgcolor the background colour for the table
  173. * @param $table_row an array with the row elements
  174. * @param $is_alternating true: the row colours alternate, false otherwise
  175. */
  176. function display_table_row($bgcolor, $table_row, $is_alternating = true)
  177. {
  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. $bgcolor = "bgcolor='".DOKEOSLIGHTGREY."'";
  188. else
  189. if ($bgcolor == "bgcolor='".DOKEOSLIGHTGREY."'")
  190. $bgcolor = "bgcolor='".HTML_WHITE."'";
  191. }
  192. return $bgcolor;
  193. }
  194. /**
  195. * Displays a table row.
  196. * This function has more options and is easier to extend than display_table_row()
  197. *
  198. * @param $properties, array with properties:
  199. * ["bgcolor"] - the background colour for the table
  200. * ["is_alternating"] - true: the row colours alternate, false otherwise
  201. * ["align_row"] - an array with, per cell, left|center|right
  202. * @todo add valign property
  203. */
  204. function display_complex_table_row($properties, $table_row)
  205. {
  206. $bgcolor = $properties["bgcolor"];
  207. $is_alternating = $properties["is_alternating"];
  208. $align_row = $properties["align_row"];
  209. echo "<tr $bgcolor>";
  210. $number_cells = count($table_row);
  211. for ($i = 0; $i < $number_cells; $i ++)
  212. {
  213. $cell_data = $table_row[$i];
  214. $cell_align = $align_row[$i];
  215. echo "<td align=\"$cell_align\">".$cell_data."</td>";
  216. }
  217. echo "</tr>\n";
  218. if ($is_alternating)
  219. {
  220. if ($bgcolor == "bgcolor='".HTML_WHITE."'")
  221. $bgcolor = "bgcolor='".DOKEOSLIGHTGREY."'";
  222. else
  223. if ($bgcolor == "bgcolor='".DOKEOSLIGHTGREY."'")
  224. $bgcolor = "bgcolor='".HTML_WHITE."'";
  225. }
  226. return $bgcolor;
  227. }
  228. /**
  229. * display html footer of table
  230. */
  231. function display_table_footer()
  232. {
  233. echo "</tbody></table>";
  234. }
  235. /**
  236. * Display a table
  237. * @param array $header Titles for the table header
  238. * each item in this array can contain 3 values
  239. * - 1st element: the column title
  240. * - 2nd element: true or false (column sortable?)
  241. * - 3th element: additional attributes for
  242. * th-tag (eg for column-width)
  243. * - 4the element: additional attributes for the td-tags
  244. * @param array $content 2D-array with the tables content
  245. * @param array $sorting_options Keys are:
  246. * 'column' = The column to use as sort-key
  247. * 'direction' = SORT_ASC or SORT_DESC
  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. * @param array $query_vars Additional variables to add in the query-string
  254. * @author bart.mollet@hogent.be
  255. */
  256. function display_sortable_table($header, $content, $sorting_options = array (), $paging_options = array (), $query_vars = null)
  257. {
  258. global $origin;
  259. $column = isset ($sorting_options['column']) ? $sorting_options['column'] : 0;
  260. $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  261. $table = new SortableTableFromArray($content, $column, $default_items_per_page);
  262. if (is_array($query_vars)) {
  263. $table->set_additional_parameters($query_vars);
  264. }
  265. foreach ($header as $index => $header_item)
  266. {
  267. $table->set_header($index, $header_item[0], $header_item[1], $header_item[2], $header_item[3]);
  268. }
  269. $table->display();
  270. }
  271. /**
  272. * Displays a normal message. It is recommended to use this function
  273. * to display any normal information messages.
  274. *
  275. * @author Roan Embrechts
  276. * @param string $message - include any additional html
  277. * tags if you need them
  278. * @return void
  279. */
  280. function display_normal_message($message)
  281. {
  282. if (!headers_sent())
  283. {
  284. echo '
  285. <style type="text/css" media="screen, projection">
  286. /*<![CDATA[*/
  287. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  288. /*]]>*/
  289. </style>';
  290. }
  291. echo '<div class="normal-message">';
  292. Display :: display_icon('message_normal.png', '', array ('style' => 'float:left; margin-right:10px;'));
  293. echo $message.'</div>';
  294. }
  295. /**
  296. * Displays an warning message. Use this if you want to draw attention to something
  297. * This can also be used for instance with the hint in the exercises
  298. *
  299. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  300. * @param string $message
  301. * @return void
  302. */
  303. function display_warning_message($message)
  304. {
  305. if (!headers_sent())
  306. {
  307. echo '
  308. <style type="text/css" media="screen, projection">
  309. /*<![CDATA[*/
  310. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  311. /*]]>*/
  312. </style>';
  313. }
  314. echo '<div class="warning-message">';
  315. Display :: display_icon('message_warning.png', '', array ('style' => 'float:left; margin-right:10px;'));
  316. echo $message.'</div>';
  317. }
  318. /**
  319. * Displays an confirmation message. Use this if something has been done successfully
  320. *
  321. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  322. * @param string $message
  323. * @return void
  324. */
  325. function display_confirmation_message($message)
  326. {
  327. if (!headers_sent())
  328. {
  329. echo '
  330. <style type="text/css" media="screen, projection">
  331. /*<![CDATA[*/
  332. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  333. /*]]>*/
  334. </style>';
  335. }
  336. echo '<div class="confirmation-message">';
  337. Display :: display_icon('message_confirmation.png', '', array ('style' => 'float:left; margin-right:10px;'));
  338. echo $message.'</div>';
  339. }
  340. /**
  341. * Displays an error message. It is recommended to use this function if an error occurs
  342. *
  343. * @author Hugues Peeters
  344. * @author Roan Embrechts
  345. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  346. * @param string $message - include any additional html
  347. * tags if you need them
  348. * @return void
  349. */
  350. function display_error_message($message)
  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="error-message">';
  362. Display :: display_icon('message_error.png', '', array ('style' => 'float:left; margin-right:10px;'));
  363. echo $message.'</div>';
  364. }
  365. /**
  366. * Return an encrypted mailto hyperlink
  367. *
  368. * @param - $email (string) - e-mail
  369. * @param - $text (string) - clickable text
  370. * @param - $style_class (string) - optional, class from stylesheet
  371. * @return - encrypted mailto hyperlink
  372. */
  373. function encrypted_mailto_link($email, $clickable_text = null, $style_class = '')
  374. {
  375. if (is_null($clickable_text))
  376. {
  377. $clickable_text = $email;
  378. }
  379. //mailto already present?
  380. if (substr($email, 0, 7) != 'mailto:')
  381. $email = 'mailto:'.$email;
  382. //class (stylesheet) defined?
  383. if ($style_class != '')
  384. $style_class = ' class="'.$style_class.'"';
  385. //encrypt email
  386. $hmail = '';
  387. for ($i = 0; $i < strlen($email); $i ++)
  388. $hmail .= '&#'.ord($email {
  389. $i }).';';
  390. //encrypt clickable text if @ is present
  391. if (strpos($clickable_text, '@'))
  392. {
  393. for ($i = 0; $i < strlen($clickable_text); $i ++)
  394. $hclickable_text .= '&#'.ord($clickable_text {
  395. $i }).';';
  396. }
  397. else
  398. {
  399. $hclickable_text = htmlspecialchars($clickable_text);
  400. }
  401. //return encrypted mailto hyperlink
  402. return '<a href="'.$hmail.'"'.$style_class.' name="clickable_email_link">'.$hclickable_text.'</a>';
  403. }
  404. /**
  405. * Create a hyperlink to the platform homepage.
  406. * @param string $name, the visible name of the hyperlink, default is sitename
  407. * @return string with html code for hyperlink
  408. */
  409. function get_platform_home_link_html($name = '')
  410. {
  411. if ($name == '')
  412. {
  413. $name = api_get_setting('siteName');
  414. }
  415. return "<a href=\"".api_get_path(WEB_PATH)."index.php\">$name</a>";
  416. }
  417. /**
  418. * Display the page header
  419. * @param string $tool_name The name of the page (will be showed in the
  420. * page title)
  421. * @param string $help
  422. */
  423. function display_header($tool_name, $help = NULL)
  424. {
  425. $nameTools = $tool_name;
  426. global $_plugins;
  427. global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $clarolineRepositoryWeb, $text_dir, $plugins, $_uid, $rootAdminWeb, $_cid, $interbreadcrumb, $charset, $langFile, $noPHP_SELF;
  428. include (api_get_path(INCLUDE_PATH)."header.inc.php");
  429. }
  430. /**
  431. * Display the page footer
  432. */
  433. function display_footer()
  434. {
  435. global $dokeos_version; //necessary to have the value accessible in the footer
  436. global $_plugins;
  437. include (api_get_path(INCLUDE_PATH)."footer.inc.php");
  438. }
  439. /**
  440. * Print an <option>-list with all letters (A-Z).
  441. * @param char $selected_letter The letter that should be selected
  442. */
  443. function get_alphabet_options($selected_letter = '')
  444. {
  445. $result = '';
  446. for ($i = 65; $i <= 90; $i ++) {
  447. $letter = chr($i);
  448. $result .= '<option value="'.$letter.'"';
  449. if ($selected_letter == $letter) {
  450. $result .= ' selected="selected"';
  451. }
  452. $result .= '>'.$letter.'</option>';
  453. }
  454. return $result;
  455. }
  456. /**
  457. * Show the so-called "left" menu for navigating
  458. */
  459. function show_course_navigation_menu($isHidden = false)
  460. {
  461. global $output_string_menu;
  462. global $_setting;
  463. // check if the $_SERVER['REQUEST_URI'] contains already url parameters (thus a questionmark)
  464. if (!strstr($_SERVER['REQUEST_URI'], "?"))
  465. {
  466. $sourceurl = $_SERVER['PHP_SELF']."?";
  467. }
  468. else
  469. {
  470. $sourceurl = $_SERVER['REQUEST_URI'];
  471. }
  472. $output_string_menu = "";
  473. if ($isHidden == "true" and $_SESSION["hideMenu"]) {
  474. $_SESSION["hideMenu"] = "hidden";
  475. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  476. $sourceurl = str_replace("&isHidden=false", "", $sourceurl);
  477. $output_string_menu .= " <a href='".$sourceurl."&isHidden=false'>"."<img src=../../main/img/expand.gif alt='Show menu1' padding:'2px'/>"."</a>";
  478. }
  479. elseif ($isHidden == "false" and $_SESSION["hideMenu"])
  480. {
  481. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  482. $sourceurl = str_replace("&isHidden=false", "", $sourceurl);
  483. $_SESSION["hideMenu"] = "shown";
  484. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src=../../main/img/collapse.gif alt='Hide menu2' padding:'2px'/>"."</a></div>";
  485. }
  486. elseif ($_SESSION["hideMenu"])
  487. {
  488. if ($_SESSION["hideMenu"] == "shown") {
  489. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src='../../main/img/collapse.gif' alt='Hide menu3' padding:'2px'/>"."</a></div>";
  490. }
  491. if ($_SESSION["hideMenu"] == "hidden") {
  492. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  493. $output_string_menu .= "<a href='".$sourceurl."&isHidden=false'>"."<img src='../../main/img/expand.gif' alt='Hide menu4' padding:'2px'/>"."</a>";
  494. }
  495. }
  496. elseif (!$_SESSION["hideMenu"])
  497. {
  498. $_SESSION["hideMenu"] = "shown";
  499. if (isset ($_cid))
  500. {
  501. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src='main/img/collapse.gif' alt='Hide menu5' padding:'2px'/>"."</a></div>";
  502. }
  503. }
  504. }
  505. /**
  506. * This function displays an icon
  507. * @param string $image the filename of the file (in the main/img/ folder
  508. * @param string $alt_text the alt text (probably a language variable)
  509. * @param array additional attributes (for instance height, width, onclick, ...)
  510. */
  511. function display_icon($image, $alt_text = '', $additional_attributes = array ()) {
  512. echo Display::return_icon($image,$alt_text,$additional_attributes);
  513. }
  514. /**
  515. * This function returns the htmlcode for an icon
  516. *
  517. * @param string $image the filename of the file (in the main/img/ folder
  518. * @param string $alt_text the alt text (probably a language variable)
  519. * @param array additional attributes (for instance height, width, onclick, ...)
  520. *
  521. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  522. * @version October 2006
  523. */
  524. function return_icon($image,$alt_text='',$additional_attributes=array())
  525. {
  526. // alt text = the image if there is none provided (for XHTML compliance)
  527. if ($alt_text=='')
  528. {
  529. $alt_text=$image;
  530. }
  531. // managing the additional attributes
  532. if (!empty($additional_attributes) and is_array($additional_attributes))
  533. {
  534. $attribute_list='';
  535. foreach ($additional_attributes as $key=>$value)
  536. {
  537. $attribute_list.=$key.'="'.$value.'" ';
  538. }
  539. }
  540. return '<img src="'.api_get_path(WEB_IMG_PATH).$image.'" alt="'.$alt_text.'" '.$attribute_list.' />';
  541. }
  542. } //end class Display
  543. ?>