display.lib.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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) René 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. * @param string The style that the table will show. You can set 'table' or 'grid'
  259. * @author bart.mollet@hogent.be
  260. */
  261. public static function display_sortable_table ($header, $content, $sorting_options = array (), $paging_options = array (), $query_vars = null, $form_actions=array(), $style='table') {
  262. global $origin;
  263. $column = isset ($sorting_options['column']) ? $sorting_options['column'] : 0;
  264. $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  265. $table = new SortableTableFromArray($content, $column, $default_items_per_page);
  266. if (is_array($query_vars)) {
  267. $table->set_additional_parameters($query_vars);
  268. }
  269. if ($style=='table') {
  270. if (is_array($header) && count($header)>0 ) {
  271. foreach ($header as $index => $header_item) {
  272. $table->set_header($index, $header_item[0], $header_item[1], $header_item[2], $header_item[3]);
  273. }
  274. }
  275. $table->set_form_actions($form_actions);
  276. $table->display();
  277. } else {
  278. $table->display_grid();
  279. }
  280. }
  281. /**
  282. * Shows a nice grid
  283. * @param string grid name (important to create css)
  284. * @param array header content
  285. * @param array array with the information to show
  286. * @param array $paging_options Keys are:
  287. * 'per_page_default' = items per page when switching from
  288. * full- list to per-page-view
  289. * 'per_page' = number of items to show per page
  290. * 'page_nr' = The page to display
  291. * 'hide_navigation' = true to hide the navigation
  292. * @param array $query_vars Additional variables to add in the query-string
  293. * @param array $form actions Additional variables to add in the query-string
  294. * @param mixed An array with bool values to know which columns show. i.e: $vibility_options= array(true, false) we will only show the first column
  295. * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
  296. */
  297. public static function display_sortable_grid ($name, $header, $content, $paging_options = array (), $query_vars = null, $form_actions=array(), $vibility_options = true) {
  298. global $origin;
  299. $column = 0;
  300. $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  301. $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name);
  302. if (is_array($query_vars)) {
  303. $table->set_additional_parameters($query_vars);
  304. }
  305. echo $table->display_simple_grid($vibility_options, $paging_options['hide_navigation']);
  306. }
  307. /**
  308. * gets a nice grid in html string
  309. * @param string grid name (important to create css)
  310. * @param array header content
  311. * @param array array with the information to show
  312. * @param array $paging_options Keys are:
  313. * 'per_page_default' = items per page when switching from
  314. * full- list to per-page-view
  315. * 'per_page' = number of items to show per page
  316. * 'page_nr' = The page to display
  317. * 'hide_navigation' = true to hide the navigation
  318. * @param array $query_vars Additional variables to add in the query-string
  319. * @param array $form actions Additional variables to add in the query-string
  320. * @param mixed An array with bool values to know which columns show. i.e: $vibility_options= array(true, false) we will only show the first column
  321. * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
  322. * @param bool true for sorting data or false otherwise
  323. * @return string html grid
  324. */
  325. public static function return_sortable_grid ($name, $header, $content, $paging_options = array (), $query_vars = null, $form_actions=array(), $vibility_options = true, $sort_data = true) {
  326. global $origin;
  327. $column = 0;
  328. $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  329. $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name);
  330. if (is_array($query_vars)) {
  331. $table->set_additional_parameters($query_vars);
  332. }
  333. //var_dump($table->get_additional_url_paramstring());
  334. return $table->display_simple_grid($vibility_options, $paging_options['hide_navigation'], $paging_options['per_page'], $sort_data);
  335. }
  336. /**
  337. * Display a table with a special configuration
  338. * @param array $header Titles for the table header
  339. * each item in this array can contain 3 values
  340. * - 1st element: the column title
  341. * - 2nd element: true or false (column sortable?)
  342. * - 3th element: additional attributes for
  343. * th-tag (eg for column-width)
  344. * - 4the element: additional attributes for the td-tags
  345. * @param array $content 2D-array with the tables content
  346. * @param array $sorting_options Keys are:
  347. * 'column' = The column to use as sort-key
  348. * 'direction' = SORT_ASC or SORT_DESC
  349. * @param array $paging_options Keys are:
  350. * 'per_page_default' = items per page when switching from
  351. * full- list to per-page-view
  352. * 'per_page' = number of items to show per page
  353. * 'page_nr' = The page to display
  354. * @param array $query_vars Additional variables to add in the query-string
  355. * @param array $column_show Array of binaries 1= show columns 0. hide a column
  356. * @param array $column_order An array of integers that let us decide how the columns are going to be sort.
  357. * i.e: $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column
  358. * @param array $form_actions Set optional forms actions
  359. *
  360. * @author Julio Montoya
  361. */
  362. 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()) {
  363. global $origin;
  364. $column = isset ($sorting_options['column']) ? $sorting_options['column'] : 0;
  365. $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  366. $table = new SortableTableFromArrayConfig($content, $column, $default_items_per_page,'tablename',$column_show,$column_order);
  367. if (is_array($query_vars)) {
  368. $table->set_additional_parameters($query_vars);
  369. }
  370. // show or hide the columns header
  371. if (is_array($column_show) )
  372. {
  373. for ($i=0;$i<count($column_show);$i++)
  374. {
  375. if (!empty($column_show[$i]))
  376. {
  377. isset($header[$i][0])?$val0=$header[$i][0]:$val0=null;
  378. isset($header[$i][1])?$val1=$header[$i][1]:$val1=null;
  379. isset($header[$i][2])?$val2=$header[$i][2]:$val2=null;
  380. isset($header[$i][3])?$val3=$header[$i][3]:$val3=null;
  381. $table->set_header($i, $val0, $val1, $val2, $val3);
  382. }
  383. }
  384. }
  385. $table->set_form_actions($form_actions);
  386. $table->display();
  387. }
  388. /**
  389. * Displays a normal message. It is recommended to use this public function
  390. * to display any normal information messages.
  391. *
  392. * @author Roan Embrechts
  393. * @param string $message - include any additional html
  394. * tags if you need them
  395. * @param bool Filter (true) or not (false)
  396. * @return void
  397. */
  398. public static function display_normal_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="normal-message">';
  414. //Display :: display_icon('message_normal.gif', get_lang('InfoMessage'), array ('style' => 'float:left; margin-right:10px;'));
  415. /*
  416. get_lang('InfoMessage', array ('style' => 'float:left; margin-right:10px;'));
  417. */
  418. echo $message.'</div>';
  419. }
  420. /**
  421. * Displays an warning message. Use this if you want to draw attention to something
  422. * This can also be used for instance with the hint in the exercises
  423. *
  424. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  425. * @param string $message
  426. * @param bool Filter (true) or not (false)
  427. * @return void
  428. */
  429. public static function display_warning_message ($message,$filter=true) {
  430. global $charset;
  431. if($filter){
  432. //filter message
  433. $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : $charset);
  434. }
  435. if (!headers_sent())
  436. {
  437. echo '
  438. <style type="text/css" media="screen, projection">
  439. /*<![CDATA[*/
  440. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  441. /*]]>*/
  442. </style>';
  443. }
  444. echo '<div class="warning-message">';
  445. //Display :: display_icon('message_warning.png', get_lang('WarningMessage'), array ('style' => 'float:left; margin-right:10px;'));
  446. /*
  447. get_lang('WarningMessage', array ('style' => 'float:left; margin-right:10px;'));
  448. */
  449. echo $message.'</div>';
  450. }
  451. /**
  452. * Displays an confirmation message. Use this if something has been done successfully
  453. *
  454. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  455. * @param string $message
  456. * @param bool Filter (true) or not (false)
  457. * @return void
  458. */
  459. public static function display_confirmation_message ($message,$filter=true) {
  460. global $charset;
  461. if($filter){
  462. //filter message
  463. $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : $charset);
  464. }
  465. if (!headers_sent())
  466. {
  467. echo '
  468. <style type="text/css" media="screen, projection">
  469. /*<![CDATA[*/
  470. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  471. /*]]>*/
  472. </style>';
  473. }
  474. echo '<div class="confirmation-message">';
  475. //Display :: display_icon('message_confirmation.gif', get_lang('ConfirmationMessage'), array ('style' => 'float:left; margin-right:10px;margin-left:5px;'));
  476. /*
  477. get_lang('ConfirmationMessage', array ('style' => 'float:left; margin-right:10px;margin-left:5px;'));
  478. */
  479. echo $message.'</div>';
  480. }
  481. /**
  482. * Displays an error message. It is recommended to use this public function if an error occurs
  483. *
  484. * @author Hugues Peeters
  485. * @author Roan Embrechts
  486. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  487. * @param string $message - include any additional html
  488. * tags if you need them
  489. * @param bool Filter (true) or not (false)
  490. * @return void
  491. */
  492. public static function display_error_message ($message,$filter=true) {
  493. global $charset;
  494. if($filter){
  495. //filter message
  496. $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : $charset);
  497. }
  498. if (!headers_sent())
  499. {
  500. echo '
  501. <style type="text/css" media="screen, projection">
  502. /*<![CDATA[*/
  503. @import "'.api_get_path(WEB_CODE_PATH).'css/default.css";
  504. /*]]>*/
  505. </style>';
  506. }
  507. echo '<div class="error-message">';
  508. //Display :: display_icon('message_error.png', get_lang('ErrorMessage'), array ('style' => 'float:left; margin-right:10px;'));
  509. /*
  510. get_lang('ErrorMessage', array ('style' => 'float:left; margin-right:10px;'));
  511. */
  512. echo $message.'</div>';
  513. }
  514. /**
  515. * Return an encrypted mailto hyperlink
  516. *
  517. * @param - $email (string) - e-mail
  518. * @param - $text (string) - clickable text
  519. * @param - $style_class (string) - optional, class from stylesheet
  520. * @return - encrypted mailto hyperlink
  521. */
  522. public static function encrypted_mailto_link ($email, $clickable_text = null, $style_class = '') {
  523. global $charset;
  524. if (is_null($clickable_text))
  525. {
  526. $clickable_text = $email;
  527. }
  528. //mailto already present?
  529. if (substr($email, 0, 7) != 'mailto:') {
  530. $email = 'mailto:'.$email;
  531. }
  532. //class (stylesheet) defined?
  533. if ($style_class != '') {
  534. $style_class = ' class="'.$style_class.'"';
  535. }
  536. //encrypt email
  537. $hmail = '';
  538. for ($i = 0; $i < strlen($email); $i ++) {
  539. $hmail .= '&#'.ord($email {
  540. $i }).';';
  541. }
  542. //encrypt clickable text if @ is present
  543. if (strpos($clickable_text, '@')) {
  544. for ($i = 0; $i < strlen($clickable_text); $i ++) {
  545. $hclickable_text .= '&#'.ord($clickable_text {
  546. $i }).';';
  547. }
  548. } else {
  549. $hclickable_text = htmlspecialchars($clickable_text,ENT_QUOTES,$charset);
  550. }
  551. //return encrypted mailto hyperlink
  552. return '<a href="'.$hmail.'"'.$style_class.' name="clickable_email_link">'.$hclickable_text.'</a>';
  553. }
  554. /**
  555. * Create a hyperlink to the platform homepage.
  556. * @param string $name, the visible name of the hyperlink, default is sitename
  557. * @return string with html code for hyperlink
  558. */
  559. public static function get_platform_home_link_html ($name = '') {
  560. if ($name == '')
  561. {
  562. $name = api_get_setting('siteName');
  563. }
  564. return "<a href=\"".api_get_path(WEB_PATH)."index.php\">$name</a>";
  565. }
  566. /**
  567. * Display the page header
  568. * @param string The name of the page (will be showed in the page title)
  569. * @param string Optional help file name
  570. */
  571. public static function display_header ($tool_name ='', $help = NULL) {
  572. $nameTools = $tool_name;
  573. global $_plugins,$lp_theme_css,$mycoursetheme,$user_theme,$platform_theme;
  574. global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $clarolineRepositoryWeb, $text_dir, $plugins, $_user, $rootAdminWeb, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF;
  575. global $menu_navigation;
  576. include (api_get_path(INCLUDE_PATH)."header.inc.php");
  577. }
  578. /**
  579. * Display the reduced page header (without banner)
  580. */
  581. public static function display_reduced_header () {
  582. global $_plugins,$lp_theme_css,$mycoursetheme,$user_theme,$platform_theme;
  583. global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $clarolineRepositoryWeb, $text_dir, $plugins, $_user, $rootAdminWeb, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF, $language_interface;
  584. global $menu_navigation;
  585. include (api_get_path(INCLUDE_PATH)."reduced_header.inc.php");
  586. }
  587. /**
  588. * Display the page footer
  589. */
  590. public static function display_footer () {
  591. global $dokeos_version; //necessary to have the value accessible in the footer
  592. global $_plugins;
  593. include (api_get_path(INCLUDE_PATH)."footer.inc.php");
  594. }
  595. /**
  596. * Print an <option>-list with all letters (A-Z).
  597. * @param char $selected_letter The letter that should be selected
  598. */
  599. public static function get_alphabet_options ($selected_letter = '') {
  600. $result = '';
  601. for ($i = 65; $i <= 90; $i ++) {
  602. $letter = chr($i);
  603. $result .= '<option value="'.$letter.'"';
  604. if ($selected_letter == $letter) {
  605. $result .= ' selected="selected"';
  606. }
  607. $result .= '>'.$letter.'</option>';
  608. }
  609. return $result;
  610. }
  611. public static function get_numeric_options ($min,$max, $selected_num = 0) {
  612. $result = '';
  613. for ($i = $min; $i <= $max; $i ++) {
  614. $result .= '<option value="'.$i.'"';
  615. if (is_int($selected_num))
  616. if ($selected_num == $i) {
  617. $result .= ' selected="selected"';
  618. }
  619. $result .= '>'.$i.'</option>';
  620. }
  621. return $result;
  622. }
  623. /**
  624. * Show the so-called "left" menu for navigating
  625. */
  626. public static function show_course_navigation_menu ($isHidden = false) {
  627. global $output_string_menu;
  628. global $_setting;
  629. // check if the $_SERVER['REQUEST_URI'] contains already url parameters (thus a questionmark)
  630. if (!strstr($_SERVER['REQUEST_URI'], "?"))
  631. {
  632. $sourceurl = api_get_self()."?";
  633. }
  634. else
  635. {
  636. $sourceurl = $_SERVER['REQUEST_URI'];
  637. }
  638. $output_string_menu = "";
  639. if ($isHidden == "true" and $_SESSION["hideMenu"]) {
  640. $_SESSION["hideMenu"] = "hidden";
  641. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  642. $sourceurl = str_replace("&isHidden=false", "", $sourceurl);
  643. $output_string_menu .= " <a href='".$sourceurl."&isHidden=false'>"."<img src=../../main/img/expand.gif alt='Show menu1' padding:'2px'/>"."</a>";
  644. }
  645. elseif ($isHidden == "false" and $_SESSION["hideMenu"])
  646. {
  647. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  648. $sourceurl = str_replace("&isHidden=false", "", $sourceurl);
  649. $_SESSION["hideMenu"] = "shown";
  650. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src=../../main/img/collapse.gif alt='Hide menu2' padding:'2px'/>"."</a></div>";
  651. }
  652. elseif ($_SESSION["hideMenu"])
  653. {
  654. if ($_SESSION["hideMenu"] == "shown") {
  655. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src='../../main/img/collapse.gif' alt='Hide menu3' padding:'2px'/>"."</a></div>";
  656. }
  657. if ($_SESSION["hideMenu"] == "hidden") {
  658. $sourceurl = str_replace("&isHidden=true", "", $sourceurl);
  659. $output_string_menu .= "<a href='".$sourceurl."&isHidden=false'>"."<img src='../../main/img/expand.gif' alt='Hide menu4' padding:'2px'/>"."</a>";
  660. }
  661. }
  662. elseif (!$_SESSION["hideMenu"])
  663. {
  664. $_SESSION["hideMenu"] = "shown";
  665. if (isset ($_cid))
  666. {
  667. $output_string_menu .= "<div id='leftimg'><a href='".$sourceurl."&isHidden=true'>"."<img src='main/img/collapse.gif' alt='Hide menu5' padding:'2px'/>"."</a></div>";
  668. }
  669. }
  670. }
  671. /**
  672. * This public function displays an icon
  673. * @param string $image the filename of the file (in the main/img/ folder
  674. * @param string $alt_text the alt text (probably a language variable)
  675. * @param array additional attributes (for instance height, width, onclick, ...)
  676. */
  677. public static function display_icon ($image, $alt_text = '', $additional_attributes = array ()) {
  678. echo Display::return_icon($image,$alt_text,$additional_attributes);
  679. }
  680. /**
  681. * This public function returns the htmlcode for an icon
  682. *
  683. * @param string $image the filename of the file (in the main/img/ folder
  684. * @param string $alt_text the alt text (probably a language variable)
  685. * @param array additional attributes (for instance height, width, onclick, ...)
  686. *
  687. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  688. * @version October 2006
  689. */
  690. public static function return_icon ($image,$alt_text='',$additional_attributes=array()) {
  691. $attribute_list = '';
  692. // alt text = the image if there is none provided (for XHTML compliance)
  693. if ($alt_text=='')
  694. {
  695. $alt_text=$image;
  696. }
  697. // managing the additional attributes
  698. if (!empty($additional_attributes) and is_array($additional_attributes))
  699. {
  700. $attribute_list='';
  701. foreach ($additional_attributes as $key=>$value)
  702. {
  703. $attribute_list.=$key.'="'.$value.'" ';
  704. }
  705. }
  706. return '<img src="'.api_get_path(WEB_IMG_PATH).$image.'" alt="'.$alt_text.'" title="'.$alt_text.'" '.$attribute_list.' />';
  707. }
  708. /**
  709. * Ivan, 05-SEP-2009: Deprecated, see api_get_person_name().
  710. *
  711. * Display name and lastname in a specific order
  712. * @param string Firstname
  713. * @param string Lastname
  714. * @param string Title in the destination language (Dr, Mr, Miss, Sr, Sra, etc)
  715. * @param string Optional format string (e.g. '%t. %l, %f')
  716. * @author Carlos Vargas <carlos.vargas@dokeos.com>
  717. */
  718. public static function user_name($fname,$lname,$title='',$format=null) {
  719. if (empty($format)){
  720. if (empty($fname) or empty($lname)) {
  721. $user_name = $fname.$lname;
  722. } else {
  723. $user_name= $fname.' '.$lname;
  724. }
  725. } else {
  726. $find = array('%t','%f','%l');
  727. $repl = array($title,$fname,$lname);
  728. $user_name = str_replace($find,$repl,$format);
  729. }
  730. return $user_name;
  731. }
  732. } //end class Display
  733. ?>