display.lib.php 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a display library for Chamilo.
  5. *
  6. * Include/require it in your code to use its public functionality.
  7. * There are also several display public functions in the main api library.
  8. *
  9. * All public functions static public functions inside a class called Display,
  10. * so you use them like this: e.g.
  11. * Display::display_normal_message($message)
  12. *
  13. * @package chamilo.library
  14. */
  15. /**
  16. * Code
  17. */
  18. class Display {
  19. /* The main template*/
  20. static $global_template;
  21. static $preview_style = null;
  22. private function __construct() {
  23. }
  24. /**
  25. * Displays the page header
  26. * @param string The name of the page (will be showed in the page title)
  27. * @param string Optional help file name
  28. */
  29. public static function display_header($tool_name ='', $help = null, $page_header = null) {
  30. self::$global_template = new Template($tool_name);
  31. self::$global_template->set_help($help);
  32. if (!empty(self::$preview_style)) {
  33. self::$global_template->preview_theme = self::$preview_style;
  34. self::$global_template->set_css_files();
  35. self::$global_template->set_js_files();
  36. }
  37. if (!empty($page_header)) {
  38. self::$global_template->assign('header', $page_header);
  39. }
  40. echo self::$global_template->show_header_template();
  41. }
  42. /**
  43. * Displays the reduced page header (without banner)
  44. */
  45. public static function display_reduced_header() {
  46. global $show_learnpath, $tool_name;
  47. self::$global_template = new Template($tool_name, false, false, $show_learnpath);
  48. echo self::$global_template ->show_header_template();
  49. }
  50. public static function display_no_header() {
  51. global $tool_name;
  52. $disable_js_and_css_files = true;
  53. self::$global_template = new Template($tool_name, false, false, $show_learnpath);
  54. //echo self::$global_template->show_header_template();
  55. }
  56. /**
  57. * Displays the reduced page header (without banner)
  58. */
  59. public static function set_header() {
  60. global $show_learnpath;
  61. self::$global_template = new Template($tool_name, false, false, $show_learnpath);
  62. }
  63. /**
  64. * Display the page footer
  65. */
  66. public static function display_footer() {
  67. echo self::$global_template ->show_footer_template();
  68. }
  69. public static function page()
  70. {
  71. return new Page();
  72. }
  73. /**
  74. * Displays the tool introduction of a tool.
  75. *
  76. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  77. * @param string $tool These are the constants that are used for indicating the tools.
  78. * @param array $editor_config Optional configuration settings for the online editor.
  79. * return: $tool return a string array list with the "define" in main_api.lib
  80. * @return html code for adding an introduction
  81. */
  82. public static function display_introduction_section($tool, $editor_config = null) {
  83. echo self::return_introduction_section($tool, $editor_config);
  84. }
  85. public static function return_introduction_section($tool, $editor_config = null) {
  86. $is_allowed_to_edit = api_is_allowed_to_edit();
  87. $moduleId = $tool;
  88. if (api_get_setting('enable_tool_introduction') == 'true' || $tool == TOOL_COURSE_HOMEPAGE) {
  89. $introduction_section = null;
  90. require api_get_path(INCLUDE_PATH).'introductionSection.inc.php';
  91. return $introduction_section;
  92. }
  93. }
  94. /**
  95. * Displays a localised html file
  96. * tries to show the file "$full_file_name"."_".$language_interface.".html"
  97. * and if this does not exist, shows the file "$full_file_name".".html"
  98. * warning this public function defines a global
  99. * @param $full_file_name, the (path) name of the file, without .html
  100. * @return return a string with the path
  101. */
  102. public static function display_localised_html_file($full_file_name) {
  103. global $language_interface;
  104. $localised_file_name = $full_file_name.'_'.$language_interface.'.html';
  105. $default_file_name = $full_file_name.'.html';
  106. if (file_exists($localised_file_name)) {
  107. include $localised_file_name;
  108. } else {
  109. include ($default_file_name);
  110. }
  111. }
  112. /**
  113. * Displays a table
  114. * @param array $header Titles for the table header
  115. * each item in this array can contain 3 values
  116. * - 1st element: the column title
  117. * - 2nd element: true or false (column sortable?)
  118. * - 3th element: additional attributes for
  119. * th-tag (eg for column-width)
  120. * - 4the element: additional attributes for the td-tags
  121. * @param array $content 2D-array with the tables content
  122. * @param array $sorting_options Keys are:
  123. * 'column' = The column to use as sort-key
  124. * 'direction' = SORT_ASC or SORT_DESC
  125. * @param array $paging_options Keys are:
  126. * 'per_page_default' = items per page when switching from
  127. * full- list to per-page-view
  128. * 'per_page' = number of items to show per page
  129. * 'page_nr' = The page to display
  130. * @param array $query_vars Additional variables to add in the query-string
  131. * @param string The style that the table will show. You can set 'table' or 'grid'
  132. * @author bart.mollet@hogent.be
  133. */
  134. public static function display_sortable_table($header, $content, $sorting_options = array(), $paging_options = array(), $query_vars = null, $form_actions = array(), $style = 'table') {
  135. global $origin;
  136. $column = isset($sorting_options['column']) ? $sorting_options['column'] : 0;
  137. $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  138. $table = new SortableTableFromArray($content, $column, $default_items_per_page);
  139. if (is_array($query_vars)) {
  140. $table->set_additional_parameters($query_vars);
  141. }
  142. if ($style == 'table') {
  143. if (is_array($header) && count($header) > 0) {
  144. foreach ($header as $index => $header_item) {
  145. $table->set_header($index, $header_item[0], $header_item[1], $header_item[2], $header_item[3]);
  146. }
  147. }
  148. $table->set_form_actions($form_actions);
  149. $table->display();
  150. } else {
  151. $table->display_grid();
  152. }
  153. }
  154. /**
  155. * Shows a nice grid
  156. * @param string grid name (important to create css)
  157. * @param array header content
  158. * @param array array with the information to show
  159. * @param array $paging_options Keys are:
  160. * 'per_page_default' = items per page when switching from
  161. * full- list to per-page-view
  162. * 'per_page' = number of items to show per page
  163. * 'page_nr' = The page to display
  164. * 'hide_navigation' = true to hide the navigation
  165. * @param array $query_vars Additional variables to add in the query-string
  166. * @param array $form actions Additional variables to add in the query-string
  167. * @param mixed An array with bool values to know which columns show. i.e: $visibility_options= array(true, false) we will only show the first column
  168. * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
  169. */
  170. public static function display_sortable_grid($name, $header, $content, $paging_options = array(), $query_vars = null, $form_actions = array(), $visibility_options = true, $sort_data = true, $grid_class = array()) {
  171. echo self::return_sortable_grid($name, $header, $content, $paging_options, $query_vars, $form_actions, $visibility_options, $sort_data, $grid_class);
  172. }
  173. /**
  174. * Gets a nice grid in html string
  175. * @param string grid name (important to create css)
  176. * @param array header content
  177. * @param array array with the information to show
  178. * @param array $paging_options Keys are:
  179. * 'per_page_default' = items per page when switching from
  180. * full- list to per-page-view
  181. * 'per_page' = number of items to show per page
  182. * 'page_nr' = The page to display
  183. * 'hide_navigation' = true to hide the navigation
  184. * @param array $query_vars Additional variables to add in the query-string
  185. * @param array $form actions Additional variables to add in the query-string
  186. * @param mixed An array with bool values to know which columns show. i.e: $visibility_options= array(true, false) we will only show the first column
  187. * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
  188. * @param bool true for sorting data or false otherwise
  189. * @param array grid classes
  190. * @return string html grid
  191. */
  192. public static function return_sortable_grid($name, $header, $content, $paging_options = array(), $query_vars = null, $form_actions = array(), $visibility_options = true, $sort_data = true, $grid_class = array()) {
  193. global $origin;
  194. $column = 0;
  195. $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  196. $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name);
  197. if (is_array($query_vars)) {
  198. $table->set_additional_parameters($query_vars);
  199. }
  200. return $table->display_simple_grid($visibility_options, $paging_options['hide_navigation'], $default_items_per_page, $sort_data, $grid_class);
  201. }
  202. /**
  203. * Displays a table with a special configuration
  204. * @param array $header Titles for the table header
  205. * each item in this array can contain 3 values
  206. * - 1st element: the column title
  207. * - 2nd element: true or false (column sortable?)
  208. * - 3th element: additional attributes for
  209. * th-tag (eg for column-width)
  210. * - 4the element: additional attributes for the td-tags
  211. * @param array $content 2D-array with the tables content
  212. * @param array $sorting_options Keys are:
  213. * 'column' = The column to use as sort-key
  214. * 'direction' = SORT_ASC or SORT_DESC
  215. * @param array $paging_options Keys are:
  216. * 'per_page_default' = items per page when switching from
  217. * full- list to per-page-view
  218. * 'per_page' = number of items to show per page
  219. * 'page_nr' = The page to display
  220. * @param array $query_vars Additional variables to add in the query-string
  221. * @param array $column_show Array of binaries 1= show columns 0. hide a column
  222. * @param array $column_order An array of integers that let us decide how the columns are going to be sort.
  223. * i.e: $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column
  224. * @param array $form_actions Set optional forms actions
  225. *
  226. * @author Julio Montoya
  227. */
  228. public static function display_sortable_config_table($table_name, $header, $content, $sorting_options = array(), $paging_options = array(), $query_vars = null, $column_show = array(), $column_order = array(), $form_actions = array()) {
  229. global $origin;
  230. $column = isset($sorting_options['column']) ? $sorting_options['column'] : 0;
  231. $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  232. $table = new SortableTableFromArrayConfig($content, $column, $default_items_per_page, $table_name, $column_show, $column_order);
  233. if (is_array($query_vars)) {
  234. $table->set_additional_parameters($query_vars);
  235. }
  236. // Show or hide the columns header
  237. if (is_array($column_show)) {
  238. for ($i = 0; $i < count($column_show); $i++) {
  239. if (!empty($column_show[$i])) {
  240. $val0 = isset($header[$i][0]) ? $header[$i][0] : null;
  241. $val1 = isset($header[$i][1]) ? $header[$i][1] : null;
  242. $val2 = isset($header[$i][2]) ? $header[$i][2] : null;
  243. $val3 = isset($header[$i][3]) ? $header[$i][3] : null;
  244. $table->set_header($i, $val0, $val1, $val2, $val3);
  245. }
  246. }
  247. }
  248. $table->set_form_actions($form_actions);
  249. $table->display();
  250. }
  251. /**
  252. * Displays a normal message. It is recommended to use this public function
  253. * to display any normal information messages.
  254. *
  255. * @param bool Filter (true) or not (false)
  256. * @return void
  257. */
  258. public static function display_normal_message($message, $filter = true) {
  259. echo self::return_message($message, 'normal', $filter);
  260. }
  261. /**
  262. * Displays an warning message. Use this if you want to draw attention to something
  263. * This can also be used for instance with the hint in the exercises
  264. *
  265. */
  266. public static function display_warning_message($message, $filter = true) {
  267. echo self::return_message($message, 'warning', $filter);
  268. }
  269. /**
  270. * Displays an confirmation message. Use this if something has been done successfully
  271. * @param bool Filter (true) or not (false)
  272. * @return void
  273. */
  274. public static function display_confirmation_message ($message, $filter = true) {
  275. echo self::return_message($message, 'confirm', $filter);
  276. }
  277. /**
  278. * Displays an error message. It is recommended to use this public function if an error occurs
  279. * @param string $message - include any additional html
  280. * tags if you need them
  281. * @param bool Filter (true) or not (false)
  282. * @return void
  283. */
  284. public static function display_error_message ($message, $filter = true) {
  285. echo self::return_message($message, 'error', $filter);
  286. }
  287. public static function return_message_and_translate($message, $type='normal', $filter = true) {
  288. $message = get_lang($message);
  289. echo self::return_message($message, $type, $filter);
  290. }
  291. /**
  292. * Returns a div html string with
  293. * @param string The message
  294. * @param string The message type (confirm,normal,warning,error)
  295. * @param bool Whether to XSS-filter or not
  296. * @return string Message wrapped into an HTML div
  297. */
  298. public static function return_message($message, $type='normal', $filter = true) {
  299. if ($filter) {
  300. $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding());
  301. //$message = Security::remove_XSS($message);
  302. }
  303. $class = "";
  304. switch($type) {
  305. case 'warning':
  306. $class .= 'warning-message';
  307. break;
  308. case 'error':
  309. $class .= 'error-message';
  310. break;
  311. case 'confirmation':
  312. case 'confirm':
  313. case 'success':
  314. $class .= 'confirmation-message';
  315. break;
  316. case 'normal':
  317. default:
  318. $class .= 'normal-message';
  319. }
  320. return self::div($message, array('class'=> $class));
  321. }
  322. /**
  323. * Returns an encrypted mailto hyperlink
  324. *
  325. * @param string e-mail
  326. * @param string clickable text
  327. * @param string optional, class from stylesheet
  328. * @return string encrypted mailto hyperlink
  329. */
  330. public static function encrypted_mailto_link ($email, $clickable_text = null, $style_class = '') {
  331. if (is_null($clickable_text)) {
  332. $clickable_text = $email;
  333. }
  334. // "mailto:" already present?
  335. if (substr($email, 0, 7) != 'mailto:') {
  336. $email = 'mailto:'.$email;
  337. }
  338. // Class (stylesheet) defined?
  339. if ($style_class != '') {
  340. $style_class = ' class="'.$style_class.'"';
  341. }
  342. // Encrypt email
  343. $hmail = '';
  344. for ($i = 0; $i < strlen($email); $i ++) {
  345. $hmail .= '&#'.ord($email {
  346. $i }).';';
  347. }
  348. $hclickable_text = null;
  349. // Encrypt clickable text if @ is present
  350. if (strpos($clickable_text, '@')) {
  351. for ($i = 0; $i < strlen($clickable_text); $i ++) {
  352. $hclickable_text .= '&#'.ord($clickable_text {
  353. $i }).';';
  354. }
  355. } else {
  356. $hclickable_text = @htmlspecialchars($clickable_text, ENT_QUOTES, api_get_system_encoding());
  357. }
  358. // Return encrypted mailto hyperlink
  359. return '<a href="'.$hmail.'"'.$style_class.' class="clickable_email_link">'.$hclickable_text.'</a>';
  360. }
  361. /**
  362. * Returns an mailto icon hyperlink
  363. *
  364. * @param string e-mail
  365. * @param string icon source file from the icon lib
  366. * @param integer icon size from icon lib
  367. * @param string optional, class from stylesheet
  368. * @return string encrypted mailto hyperlink
  369. */
  370. public static function icon_mailto_link ($email, $icon_file = "mail.png", $icon_size = 22, $style_class = '') {
  371. // "mailto:" already present?
  372. if (substr($email, 0, 7) != 'mailto:') {
  373. $email = 'mailto:'.$email;
  374. }
  375. // Class (stylesheet) defined?
  376. if ($style_class != '') {
  377. $style_class = ' class="'.$style_class.'"';
  378. }
  379. // Encrypt email
  380. $hmail = '';
  381. for ($i = 0; $i < strlen($email); $i ++) {
  382. $hmail .= '&#'.ord($email {
  383. $i }).';';
  384. }
  385. // icon html code
  386. $icon_html_source = self::return_icon($icon_file, $hmail, '', $icon_size);
  387. // Return encrypted mailto hyperlink
  388. return '<a href="'.$hmail.'"'.$style_class.' class="clickable_email_link">'.$icon_html_source.'</a>';
  389. }
  390. /**
  391. * Creates a hyperlink to the platform homepage.
  392. * @param string $name, the visible name of the hyperlink, default is sitename
  393. * @return string with html code for hyperlink
  394. */
  395. public static function get_platform_home_link_html($name = '') {
  396. if ($name == '') {
  397. $name = api_get_setting('siteName');
  398. }
  399. return '<a href="'.api_get_path(WEB_PATH).'index.php">'.$name.'</a>';
  400. }
  401. /**
  402. * Prints an <option>-list with all letters (A-Z).
  403. * @param char $selected_letter The letter that should be selected
  404. * @todo This is English language specific implementation. It should be adapted for the other languages.
  405. */
  406. public static function get_alphabet_options($selected_letter = '') {
  407. $result = '';
  408. for ($i = 65; $i <= 90; $i ++) {
  409. $letter = chr($i);
  410. $result .= '<option value="'.$letter.'"';
  411. if ($selected_letter == $letter) {
  412. $result .= ' selected="selected"';
  413. }
  414. $result .= '>'.$letter.'</option>';
  415. }
  416. return $result;
  417. }
  418. /**
  419. * Get the options withing a select box within the given values
  420. * @param int Min value
  421. * @param int Max value
  422. * @param int Default value
  423. * @return string HTML select options
  424. */
  425. public static function get_numeric_options($min, $max, $selected_num = 0) {
  426. $result = '';
  427. for ($i = $min; $i <= $max; $i ++) {
  428. $result .= '<option value="'.$i.'"';
  429. if (is_int($selected_num))
  430. if ($selected_num == $i) {
  431. $result .= ' selected="selected"';
  432. }
  433. $result .= '>'.$i.'</option>';
  434. }
  435. return $result;
  436. }
  437. /**
  438. * Shows the so-called "left" menu for navigating
  439. */
  440. public static function show_course_navigation_menu($isHidden = false) {
  441. global $output_string_menu;
  442. global $_setting;
  443. // Check if the $_SERVER['REQUEST_URI'] contains already url parameters (thus a questionmark)
  444. if (strpos($_SERVER['REQUEST_URI'], '?') === false) {
  445. $sourceurl = api_get_self().'?';
  446. } else {
  447. $sourceurl = $_SERVER['REQUEST_URI'];
  448. }
  449. $output_string_menu = '';
  450. if ($isHidden == 'true' and $_SESSION['hideMenu']) {
  451. $_SESSION['hideMenu'] = 'hidden';
  452. $sourceurl = str_replace('&isHidden=true', '', $sourceurl);
  453. $sourceurl = str_replace('&isHidden=false', '', $sourceurl);
  454. $output_string_menu .= ' <a href="'.$sourceurl.'&isHidden=false"><img src="../../main/img/expand.gif" alt="'.'Show menu1'.'" padding:"2px"/></a>';
  455. } elseif ($isHidden == 'false' && $_SESSION['hideMenu']) {
  456. $sourceurl = str_replace('&isHidden=true', '', $sourceurl);
  457. $sourceurl = str_replace('&isHidden=false', '', $sourceurl);
  458. $_SESSION['hideMenu'] = 'shown';
  459. $output_string_menu .= '<div id="leftimg"><a href="'.$sourceurl.'&isHidden=true"><img src="../../main/img/collapse.gif" alt="'.'Hide menu2'.'" padding:"2px"/></a></div>';
  460. } elseif ($_SESSION['hideMenu']) {
  461. if ($_SESSION['hideMenu'] == 'shown') {
  462. $output_string_menu .= '<div id="leftimg"><a href="'.$sourceurl.'&isHidden=true"><img src="../../main/img/collapse.gif" alt="'.'Hide menu3'.' padding:"2px"/></a></div>';
  463. }
  464. if ($_SESSION['hideMenu'] == 'hidden') {
  465. $sourceurl = str_replace('&isHidden=true', '', $sourceurl);
  466. $output_string_menu .= '<a href="'.$sourceurl.'&isHidden=false"><img src="../../main/img/expand.gif" alt="'.'Hide menu4'.' padding:"2px"/></a>';
  467. }
  468. } elseif (!$_SESSION['hideMenu']) {
  469. $_SESSION['hideMenu'] = 'shown';
  470. if (isset($_cid)) {
  471. $output_string_menu .= '<div id="leftimg"><a href="'.$sourceurl.'&isHidden=true"><img src="main/img/collapse.gif" alt="'.'Hide menu5'.' padding:"2px"/></a></div>';
  472. }
  473. }
  474. }
  475. /**
  476. * This public function displays an icon
  477. * @param string The filename of the file (in the main/img/ folder
  478. * @param string The alt text (probably a language variable)
  479. * @param array additional attributes (for instance height, width, onclick, ...)
  480. * @param integer The wanted width of the icon (to be looked for in the corresponding img/icons/ folder)
  481. * @return void
  482. */
  483. public static function display_icon($image, $alt_text = '', $additional_attributes = array(), $size=null) {
  484. echo self::return_icon($image, $alt_text, $additional_attributes, $size);
  485. }
  486. /**
  487. * This public function returns the htmlcode for an icon
  488. *
  489. * @param string The filename of the file (in the main/img/ folder
  490. * @param string The alt text (probably a language variable)
  491. * @param array Additional attributes (for instance height, width, onclick, ...)
  492. * @param integer The wanted width of the icon (to be looked for in the corresponding img/icons/ folder)
  493. * @return string An HTML string of the right <img> tag
  494. *
  495. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University 2006
  496. * @author Julio Montoya 2010 Function improved, adding image constants
  497. * @author Yannick Warnier 2011 Added size handler
  498. * @version Feb 2011
  499. */
  500. public static function return_icon($image, $alt_text = '', $additional_attributes = array(), $size = ICON_SIZE_SMALL, $show_text = true, $return_only_path = false) {
  501. $code_path = api_get_path(SYS_CODE_PATH);
  502. $w_code_path = api_get_path(WEB_CODE_PATH);
  503. $image = trim($image);
  504. $theme = 'css/'.api_get_visual_theme().'/icons/';
  505. $icon = '';
  506. $size_extra = '';
  507. if (isset($size)) {
  508. $size = intval($size);
  509. $size_extra = $size.'/';
  510. } else {
  511. $size = ICON_SIZE_SMALL;
  512. }
  513. //Checking the theme icons folder example: main/css/chamilo/icons/XXX
  514. if (is_file($code_path.$theme.$size_extra.$image)) {
  515. $icon = $w_code_path.$theme.$size_extra.$image;
  516. } elseif (is_file($code_path.'img/icons/'.$size_extra.$image)) {
  517. //Checking the main/img/icons/XXX/ folder
  518. $icon = $w_code_path.'img/icons/'.$size_extra.$image;
  519. } else {
  520. //Checking the img/ folder
  521. $icon = $w_code_path.'img/'.$image;
  522. }
  523. $icon = api_get_cdn_path($icon);
  524. if ($return_only_path) {
  525. return $icon;
  526. }
  527. $img = self::img($icon, $alt_text, $additional_attributes);
  528. if (SHOW_TEXT_NEAR_ICONS == true and !empty($alt_text)) {
  529. if ($show_text) {
  530. $img = "$img $alt_text";
  531. }
  532. }
  533. return $img;
  534. }
  535. /**
  536. * Returns the htmlcode for an image
  537. *
  538. * @param string $image the filename of the file (in the main/img/ folder
  539. * @param string $alt_text the alt text (probably a language variable)
  540. * @param array additional attributes (for instance height, width, onclick, ...)
  541. * @author Julio Montoya 2010
  542. */
  543. public static function img($image_path, $alt_text = '', $additional_attributes = array()) {
  544. // Sanitizing the parameter $image_path
  545. $image_path = Security::filter_img_path($image_path);
  546. // alt text = the image name if there is none provided (for XHTML compliance)
  547. if ($alt_text == '') {
  548. $alt_text = basename($image_path);
  549. }
  550. $additional_attributes['src'] = $image_path;
  551. if (empty($additional_attributes['alt'])) {
  552. $additional_attributes['alt'] = $alt_text;
  553. }
  554. if (empty($additional_attributes['title'])) {
  555. $additional_attributes['title'] = $alt_text;
  556. }
  557. //return '<img src="'.$image_path.'" alt="'.$alt_text.'" title="'.$alt_text.'" '.$attribute_list.' />';
  558. return self::tag('img', '', $additional_attributes);
  559. }
  560. /**
  561. * Returns the htmlcode for a tag (h3, h1, div, a, button), etc
  562. *
  563. * @param string $image the filename of the file (in the main/img/ folder
  564. * @param string $alt_text the alt text (probably a language variable)
  565. * @param array additional attributes (for instance height, width, onclick, ...)
  566. * @author Julio Montoya 2010
  567. */
  568. public static function tag($tag, $content, $additional_attributes = array()) {
  569. $attribute_list = '';
  570. // Managing the additional attributes
  571. if (!empty($additional_attributes) && is_array($additional_attributes)) {
  572. $attribute_list = '';
  573. foreach ($additional_attributes as $key => & $value) {
  574. $attribute_list .= $key.'="'.$value.'" ';
  575. }
  576. }
  577. //some tags don't have this </XXX>
  578. if (in_array($tag, array('img', 'input', 'br'))) {
  579. $return_value = '<'.$tag.' '.$attribute_list.' />';
  580. } else {
  581. $return_value = '<'.$tag.' '.$attribute_list.' > '.$content.'</'.$tag.'>';
  582. }
  583. return $return_value;
  584. }
  585. /**
  586. * Creates a URL anchor
  587. */
  588. public static function url($name, $url, $extra_attributes = array()) {
  589. if (!empty($url)) {
  590. $extra_attributes['href']= $url;
  591. }
  592. return self::tag('a', $name, $extra_attributes);
  593. }
  594. /**
  595. * Creates a div tag
  596. */
  597. public static function div($content, $extra_attributes = array()) {
  598. return self::tag('div', $content, $extra_attributes);
  599. }
  600. /**
  601. * Creates a span tag
  602. */
  603. public static function span($content, $extra_attributes = array()) {
  604. return self::tag('span', $content, $extra_attributes);
  605. }
  606. /**
  607. * Displays an HTML input tag
  608. *
  609. */
  610. public static function input($type, $name, $value, $extra_attributes = array()) {
  611. if (isset($type)) {
  612. $extra_attributes['type']= $type;
  613. }
  614. if (isset($name)) {
  615. $extra_attributes['name']= $name;
  616. }
  617. if (isset($value)) {
  618. $extra_attributes['value']= $value;
  619. }
  620. return self::tag('input', '', $extra_attributes);
  621. }
  622. public static function button($name, $value, $extra_attributes = array()) {
  623. if (!empty($name)) {
  624. $extra_attributes['name']= $name;
  625. }
  626. return self::tag('button', $value, $extra_attributes);
  627. }
  628. /**
  629. * Displays an HTML select tag
  630. *
  631. */
  632. public static function select($name, $values, $default = -1, $extra_attributes = array(), $show_blank_item = true, $blank_item_text = null) {
  633. $html = '';
  634. $extra = '';
  635. $default_id = 'id="'.$name.'" ';
  636. foreach($extra_attributes as $key=>$parameter) {
  637. if ($key == 'id') {
  638. $default_id = '';
  639. }
  640. $extra .= $key.'="'.$parameter.'"';
  641. }
  642. $html .= '<select name="'.$name.'" '.$default_id.' '.$extra.'>';
  643. if ($show_blank_item) {
  644. if (empty($blank_item_text)) {
  645. $blank_item_text = get_lang('Select');
  646. } else {
  647. $blank_item_text = Security::remove_XSS($blank_item_text);
  648. }
  649. $html .= self::tag('option', '-- '.$blank_item_text.' --', array('value'=>'-1'));
  650. }
  651. if ($values) {
  652. foreach ($values as $key => $value) {
  653. if(is_array($value) && isset($value['name'])) {
  654. $value = $value['name'];
  655. }
  656. $html .= '<option value="'.$key.'"';
  657. if (is_array($default)) {
  658. foreach($default as $item) {
  659. if ($item == $key) {
  660. $html .= 'selected="selected"';
  661. break;
  662. }
  663. }
  664. } else {
  665. if ($default == $key) {
  666. $html .= 'selected="selected"';
  667. }
  668. }
  669. $html .= '>'.$value.'</option>';
  670. }
  671. }
  672. $html .= '</select>';
  673. return $html;
  674. }
  675. /**
  676. * Creates a tab menu
  677. * Requirements: declare the jquery, jquery-ui libraries + the jquery-ui.css in the $htmlHeadXtra variable before the display_header
  678. * Add this script
  679. * @example
  680. * <script>
  681. $(function() {
  682. $( "#tabs" ).tabs();
  683. });
  684. </script>
  685. * @param array list of the tab titles
  686. * @param array content that will be showed
  687. * @param string the id of the container of the tab in the example "tabs"
  688. * @param array attributes for the ul
  689. *
  690. */
  691. public static function tabs($header_list, $content_list, $id = 'tabs', $attributes = array(), $ul_attributes = array()) {
  692. if (empty($header_list) || count($header_list) == 0 ) {
  693. return '';
  694. }
  695. $lis = '';
  696. $i = 1;
  697. foreach ($header_list as $item) {
  698. $item =self::tag('a', $item, array('href'=>'#'.$id.'-'.$i));
  699. $lis .=self::tag('li', $item, $ul_attributes);
  700. $i++;
  701. }
  702. $ul = self::tag('ul',$lis);
  703. $i = 1;
  704. $divs = '';
  705. foreach ($content_list as $content) {
  706. $content = self::tag('p',$content);
  707. $divs .=self::tag('div', $content, array('id'=>$id.'-'.$i));
  708. $i++;
  709. }
  710. $attributes['id'] = $id;
  711. $main_div = self::tag('div',$ul.$divs, $attributes);
  712. return $main_div ;
  713. }
  714. public static function tabs_only_link($header_list, $selected = null) {
  715. $id = uniqid();
  716. $i = 1;
  717. $lis = null;
  718. foreach ($header_list as $item) {
  719. $class = null;
  720. if ($i == $selected) {
  721. $class = 'active';
  722. }
  723. $item =self::tag('a', $item['content'], array('id'=>$id.'-'.$i, 'href' => $item['url']));
  724. $lis .=self::tag('li', $item, array('class' => $class));
  725. $i++;
  726. }
  727. return self::tag('ul',$lis, array('class' => 'nav nav-tabs'));
  728. }
  729. /**
  730. * In order to display a grid using jqgrid you have to:
  731. * @example
  732. * After your Display::display_header function you have to add the nex javascript code: *
  733. * <script>
  734. * echo Display::grid_js('my_grid_name', $url,$columns, $column_model, $extra_params,array()); // for more information of this function check the grid_js() function
  735. * </script>
  736. * //Then you have to call the grid_html
  737. * echo Display::grid_html('my_grid_name');
  738. * As you can see both function use the same "my_grid_name" this is very important otherwise nothing will work
  739. *
  740. * @param string the div id, this value must be the same with the first parameter of Display::grid_js()
  741. * @return string html
  742. *
  743. */
  744. public static function grid_html($div_id){
  745. $table = self::tag('table','',array('id'=>$div_id));
  746. $table .= self::tag('div','',array('id'=>$div_id.'_pager'));
  747. return $table;
  748. }
  749. public static function form_row($label, $form_item) {
  750. $label = self::span($label, array('class' =>'control-label'));
  751. $form_item = self::div($form_item, array('class' =>'controls'));
  752. return self::div($label.$form_item, array('class'=>'control-group'));
  753. }
  754. /**
  755. * This is a wrapper to use the jqgrid in Chamilo. For the other jqgrid options visit http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options
  756. * This function need to be in the ready jquery function example --> $(function() { <?php echo Display::grid_js('grid' ...); ?> }
  757. * In order to work this function needs the Display::grid_html function with the same div id
  758. *
  759. * @param string div id
  760. * @param string url where the jqgrid will ask for data (if datatype = json)
  761. * @param array Visible columns (you should use get_lang). An array in which we place the names of the columns.
  762. * This is the text that appears in the head of the grid (Header layer).
  763. * Example: colname {name:'date', index:'date', width:120, align:'right'},
  764. * @param array the column model : Array which describes the parameters of the columns.This is the most important part of the grid.
  765. * For a full description of all valid values see colModel API. See the url above.
  766. * @param array extra parameters
  767. * @param array data that will be loaded
  768. * @return string the js code
  769. *
  770. */
  771. public static function grid_js($div_id, $url, $column_names, $column_model, $extra_params, $data = array(), $formatter = '', $width_fix = false) {
  772. $obj = new stdClass();
  773. if (!empty($url)) {
  774. $obj->url = $url;
  775. $obj->datatype = 'json';
  776. } else {
  777. $obj->datatype = 'local';
  778. }
  779. $obj->colNames = $column_names;
  780. $obj->colModel = $column_model;
  781. $obj->pager = '#'.$div_id.'_pager';
  782. //Default row quantity
  783. if (!isset($extra_params['rowList'])) {
  784. $extra_params['rowList'] = array(20, 50, 100, 500, 1000);
  785. //$extra_params['rowList'] = array(20, 50, 100, 500, 1000, 2000, 5000, 10000);
  786. }
  787. $json = '';
  788. if (!empty($extra_params['datatype'])) {
  789. $obj->datatype = $extra_params['datatype'];
  790. }
  791. //Row even odd style
  792. $obj->altRows = true;
  793. if (!empty($extra_params['altRows'])) {
  794. $obj->altRows = $extra_params['altRows'];
  795. }
  796. if (!empty($extra_params['sortname'])) {
  797. $obj->sortname = $extra_params['sortname'];
  798. }
  799. //$obj->sortorder = 'desc';
  800. if (!empty($extra_params['sortorder'])) {
  801. $obj->sortorder = $extra_params['sortorder'];
  802. }
  803. if (!empty($extra_params['rowList'])) {
  804. $obj->rowList = $extra_params['rowList'];
  805. }
  806. //Sets how many records we want to view in the grid
  807. $obj->rowNum = 20;
  808. if (!empty($extra_params['rowNum'])) {
  809. $obj->rowNum = $extra_params['rowNum'];
  810. }
  811. $obj->viewrecords = 'true';
  812. if (!empty($extra_params['viewrecords']))
  813. $obj->viewrecords = $extra_params['viewrecords'];
  814. if (!empty($extra_params)) {
  815. foreach ($extra_params as $key=>$element){
  816. $obj->$key = $element;
  817. }
  818. }
  819. //Adding static data
  820. if (!empty($data)) {
  821. $data_var = $div_id.'_data';
  822. $json.=' var '.$data_var.' = '.json_encode($data).';';
  823. /* $json.='for(var i=0;i<='.$data_var.'.length;i++)
  824. jQuery("#'.$div_id.'").jqGrid(\'addRowData\',i+1,'.$data_var.'[i]);';*/
  825. $obj->data = $data_var;
  826. $obj->datatype = 'local';
  827. $json.="\n";
  828. }
  829. $json_encode = json_encode($obj);
  830. if (!empty($data)) {
  831. //Converts the "data":"js_variable" to "data":js_variable othersiwe it will not work
  832. $json_encode = str_replace('"data":"'.$data_var.'"','"data":'.$data_var.'',$json_encode);
  833. }
  834. //Fixes datainit datepick
  835. $json_encode = str_replace('"dataInit"','dataInit', $json_encode);
  836. /*$json_encode = str_replace('"dataEvents"','dataEvents', $json_encode);
  837. $json_encode = str_replace('"type"','type', $json_encode);
  838. $json_encode = str_replace('"fn"','fn', $json_encode);
  839. $json_encode = str_replace('"data"','data', $json_encode);
  840. $json_encode = str_replace('"attr"','attr', $json_encode);
  841. $json_encode = str_replace('"rel"','rel', $json_encode);
  842. $json_encode = str_replace('"title"','title', $json_encode);
  843. */
  844. $json_encode = str_replace('"register_second_select"','register_second_select', $json_encode);
  845. $json_encode = str_replace('"fill_second_select"','fill_second_select', $json_encode);
  846. $json_encode = str_replace('"date_pick"','date_pick', $json_encode);
  847. $json_encode = str_replace('"date_pick_today"','date_pick_today', $json_encode);
  848. $json_encode = str_replace('"date_pick_one_month"','date_pick_one_month', $json_encode);
  849. //Fixing true/false js values that doesn't need the ""
  850. $json_encode = str_replace(':"true"',':true',$json_encode);
  851. //wrap_cell is not a valid jqgrid attributes is a hack to wrap a text
  852. $json_encode = str_replace('"wrap_cell":true','cellattr:function(rowId, tv, rawObject, cm, rdata) { return \'style ="white-space: normal;"\'}',$json_encode);
  853. $json_encode = str_replace(':"false"',':false',$json_encode);
  854. $json_encode = str_replace('"formatter":"action_formatter"','formatter:action_formatter',$json_encode);
  855. if ($width_fix) {
  856. if (is_numeric($width_fix)) {
  857. $width_fix = intval($width_fix);
  858. } else {
  859. $width_fix = '150';
  860. }
  861. //see BT#2020
  862. /*$json .= "$(window).bind('resize', function() {
  863. $('#".$div_id."').setGridWidth($(window).width() - ".$width_fix.");
  864. }).trigger('resize');";*/
  865. }
  866. //Creating the jqgrid element
  867. $json .= '$("#'.$div_id.'").jqGrid(';
  868. $json .= $json_encode;
  869. $json .= ');';
  870. $json.="\n";
  871. //Adding edit/delete icons
  872. $json.=$formatter;
  873. return $json;
  874. /*
  875. Real Example
  876. $("#list_week").jqGrid({
  877. url:'<?php echo api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_week&session_id='.$session_id; ?>',
  878. datatype: 'json',
  879. colNames:['Week','Date','Course', 'LP'],
  880. colModel :[
  881. {name:'week', index:'week', width:120, align:'right'},
  882. {name:'date', index:'date', width:120, align:'right'},
  883. {name:'course', index:'course', width:150},
  884. {name:'lp', index:'lp', width:250}
  885. ],
  886. pager: '#pager3',
  887. rowNum:100,
  888. rowList:[10,20,30],
  889. sortname: 'date',
  890. sortorder: 'desc',
  891. viewrecords: true,
  892. grouping:true,
  893. groupingView : {
  894. groupField : ['week'],
  895. groupColumnShow : [false],
  896. groupText : ['<b>Week {0} - {1} Item(s)</b>']
  897. }
  898. }); */
  899. }
  900. public static function table($headers, $rows, $attributes = array()) {
  901. if (empty($attributes)) {
  902. $attributes['class'] = 'data_table';
  903. }
  904. //require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.php';
  905. $table = new HTML_Table($attributes);
  906. $row = 0;
  907. $column = 0;
  908. //Course headers
  909. if (!empty($headers)) {
  910. foreach ($headers as $item) {
  911. $table->setHeaderContents($row, $column, $item);
  912. $column++;
  913. }
  914. $row = 1;
  915. $column = 0;
  916. }
  917. if (!empty($rows)) {
  918. foreach($rows as $content) {
  919. $table->setCellContents($row, $column, $content);
  920. $row++;
  921. //$column++;
  922. }
  923. }
  924. return $table->toHtml();
  925. }
  926. /**
  927. * Returns the "what's new" icon notifications
  928. *
  929. * The general logic of this function is to track the last time the user
  930. * entered the course and compare to what has changed inside this course
  931. * since then, based on the item_property table inside this course. Note that,
  932. * if the user never entered the course before, he will not see notification
  933. * icons. This function takes session ID into account (if any) and only shows
  934. * the corresponding notifications.
  935. * @param array Course information array, containing at least elements 'db' and 'k'
  936. * @return string The HTML link to be shown next to the course
  937. */
  938. public static function show_notification($course_info) {
  939. $t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  940. $user_id = api_get_user_id();
  941. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  942. $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  943. $course_code = Database::escape_string($course_info['code']);
  944. $course_id = $course_info['real_id'];
  945. $course_info['id_session'] = intval($course_info['id_session']);
  946. // Get the user's last access dates to all tools of this course
  947. $sqlLastTrackInCourse = "SELECT * FROM $t_track_e_access USE INDEX (access_cours_code, access_user_id)
  948. WHERE access_cours_code = '".$course_code."' AND
  949. access_user_id = '$user_id' AND
  950. access_session_id ='".$course_info['id_session']."'";
  951. $resLastTrackInCourse = Database::query($sqlLastTrackInCourse);
  952. $oldestTrackDate = $oldestTrackDateOrig = '3000-01-01 00:00:00';
  953. while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
  954. $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
  955. if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
  956. $oldestTrackDate = $lastTrackInCourse['access_date'];
  957. }
  958. }
  959. if ($oldestTrackDate == $oldestTrackDateOrig) {
  960. //if there was no connexion to the course ever, then take the
  961. // course creation date as a reference
  962. $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  963. $sql = "SELECT course.creation_date ".
  964. "FROM $course_table course ".
  965. "WHERE course.code = '".$course_code."'";
  966. $res = Database::query($sql);
  967. if ($res && Database::num_rows($res)>0) {
  968. $row = Database::fetch_array($res);
  969. }
  970. $oldestTrackDate = $row['creation_date'];
  971. }
  972. // Get the last edits of all tools of this course.
  973. $sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref, ".
  974. " tet.lastedit_type type, tet.to_group_id group_id, ".
  975. " ctt.image image, ctt.link link ".
  976. " FROM $tool_edit_table tet, $course_tool_table ctt ".
  977. " WHERE tet.c_id = $course_id AND
  978. ctt.c_id = $course_id AND
  979. tet.lastedit_date > '$oldestTrackDate' ".
  980. " AND ctt.name = tet.tool ".
  981. " AND ctt.visibility = '1' ".
  982. " AND tet.lastedit_user_id != $user_id AND tet.id_session = '".$course_info['id_session']."' ".
  983. " ORDER BY tet.lastedit_date";
  984. $res = Database::query($sql);
  985. // Get the group_id's with user membership.
  986. $group_ids = GroupManager :: get_group_ids($course_info['real_id'], $user_id);
  987. $group_ids[] = 0; //add group 'everyone'
  988. $notifications = array();
  989. // Filter all last edits of all tools of the course
  990. while ($res && ($item_property = Database::fetch_array($res))) {
  991. // First thing to check is if the user never entered the tool
  992. // or if his last visit was earlier than the last modification.
  993. if ((!isset ($lastTrackInCourseDate[$item_property['tool']])
  994. || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date'])
  995. // Drop the tool elements that are part of a group that the
  996. // user is not part of.
  997. && ((in_array($item_property['to_group_id'], $group_ids)
  998. // Drop the dropbox, notebook and chat tools (we don't care)
  999. && ($item_property['tool'] != TOOL_DROPBOX
  1000. && $item_property['tool'] != TOOL_NOTEBOOK
  1001. && $item_property['tool'] != TOOL_CHAT)
  1002. )
  1003. )
  1004. // Take only what's visible or invisible but where the user is a teacher or where the visibility is unset.
  1005. && ($item_property['visibility'] == '1'
  1006. || ($course_info['status'] == '1' && $item_property['visibility'] == '0')
  1007. || !isset($item_property['visibility'])))
  1008. {
  1009. // Also drop announcements and events that are not for the user or his group.
  1010. if (($item_property['tool'] == TOOL_ANNOUNCEMENT
  1011. || $item_property['tool'] == TOOL_CALENDAR_EVENT)
  1012. && (($item_property['to_user_id'] != $user_id )
  1013. && (!isset($item_property['to_group_id'])
  1014. || !in_array($item_property['to_group_id'], $group_ids)))) {
  1015. continue;
  1016. }
  1017. // If it's a survey, make sure the user's invited. Otherwise drop it.
  1018. if ($item_property['tool'] == TOOL_SURVEY) {
  1019. $survey_info = survey_manager::get_survey($item_property['ref'], 0, $course_code);
  1020. $invited_users = SurveyUtil::get_invited_users($survey_info['code'], $course_code);
  1021. if (!in_array($user_id, $invited_users['course_users'])) continue;
  1022. }
  1023. // If it's a learning path, ensure it is currently visible to the user
  1024. if ($item_property['tool'] == TOOL_LEARNPATH) {
  1025. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  1026. if (!learnpath::is_lp_visible_for_student($item_property['ref'],$user_id, $course_code)) {
  1027. continue;
  1028. }
  1029. }
  1030. $notifications[$item_property['tool']] = $item_property;
  1031. }
  1032. }
  1033. // Show all tool icons where there is something new.
  1034. $retvalue = '&nbsp;';
  1035. while (list($key, $notification) = each($notifications)) {
  1036. $lastDate = date('d/m/Y H:i', convert_sql_date($notification['lastedit_date']));
  1037. $type = $notification['lastedit_type'];
  1038. if (empty($course_info['id_session'])) {
  1039. $my_course['id_session'] = 0;
  1040. } else {
  1041. $my_course['id_session'] = $course_info['id_session'];
  1042. }
  1043. $label = get_lang('TitleNotification').": ".get_lang($type)." ($lastDate)";
  1044. $retvalue .= '<a href="'.api_get_path(WEB_CODE_PATH).$notification['link'].'?cidReq='.$course_code.'&amp;ref='.$notification['ref'].'&amp;gidReq='.$notification['to_group_id'].'&amp;id_session='.$my_course['id_session'].'">'.
  1045. Display::return_icon($notification['image'], $label).'</a>&nbsp;';
  1046. }
  1047. return $retvalue;
  1048. }
  1049. /**
  1050. * Displays a digest e.g. short summary of new agenda and announcements items.
  1051. * This used to be displayed in the right hand menu, but is now
  1052. * disabled by default (see config settings in this file) because most people like
  1053. * the what's new icons better.
  1054. *
  1055. * @version 1.0
  1056. */
  1057. public static function display_digest($toolsList, $digest, $orderKey, $courses) {
  1058. $html = '';
  1059. if (is_array($digest) && (CONFVAL_showExtractInfo == SCRIPTVAL_UnderCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both)) {
  1060. // // // LEVEL 1 // // //
  1061. reset($digest);
  1062. $html .= "<br /><br />\n";
  1063. while (list($key1) = each($digest)) {
  1064. if (is_array($digest[$key1])) {
  1065. // // // Title of LEVEL 1 // // //
  1066. $html .= "<strong>\n";
  1067. if ($orderKey[0] == 'keyTools') {
  1068. $tools = $key1;
  1069. $html .= $toolsList[$key1]['name'];
  1070. } elseif ($orderKey[0] == 'keyCourse') {
  1071. $courseSysCode = $key1;
  1072. $html .= "<a href=\"".api_get_path(WEB_COURSE_PATH). $courses[$key1]['coursePath']. "\">".$courses[$key1]['courseCode']. "</a>\n";
  1073. } elseif ($orderKey[0] == 'keyTime') {
  1074. $html .= api_convert_and_format_date($digest[$key1], DATE_FORMAT_LONG, date_default_timezone_get());
  1075. }
  1076. $html .= "</strong>\n";
  1077. // // // End Of Title of LEVEL 1 // // //
  1078. // // // LEVEL 2 // // //
  1079. reset($digest[$key1]);
  1080. while (list ($key2) = each($digest[$key1])) {
  1081. // // // Title of LEVEL 2 // // //
  1082. $html .= "<p>\n". "\n";
  1083. if ($orderKey[1] == 'keyTools') {
  1084. $tools = $key2;
  1085. $html .= $toolsList[$key2][name];
  1086. } elseif ($orderKey[1] == 'keyCourse') {
  1087. $courseSysCode = $key2;
  1088. $html .= "<a href=\"". api_get_path(WEB_COURSE_PATH). $courses[$key2]['coursePath']. "\">". $courses[$key2]['courseCode']. "</a>\n";
  1089. } elseif ($orderKey[1] == 'keyTime') {
  1090. $html .= api_convert_and_format_date($key2, DATE_FORMAT_LONG, date_default_timezone_get());
  1091. }
  1092. $html .= "\n";
  1093. $html .= "</p>";
  1094. // // // End Of Title of LEVEL 2 // // //
  1095. // // // LEVEL 3 // // //
  1096. reset($digest[$key1][$key2]);
  1097. while (list ($key3, $dataFromCourse) = each($digest[$key1][$key2])) {
  1098. // // // Title of LEVEL 3 // // //
  1099. if ($orderKey[2] == 'keyTools') {
  1100. $level3title = "<a href=\"".$toolsList[$key3]["path"].$courseSysCode."\">".$toolsList[$key3]['name']."</a>";
  1101. } elseif ($orderKey[2] == 'keyCourse') {
  1102. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$key3."\">".$courses[$key3]['courseCode']."</a>\n";
  1103. } elseif ($orderKey[2] == 'keyTime') {
  1104. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$courseSysCode."\">".api_convert_and_format_date($key3, DATE_FORMAT_LONG, date_default_timezone_get())."</a>";
  1105. }
  1106. // // // End Of Title of LEVEL 3 // // //
  1107. // // // LEVEL 4 (data) // // //
  1108. reset($digest[$key1][$key2][$key3]);
  1109. while (list ($key4, $dataFromCourse) = each($digest[$key1][$key2][$key3])) {
  1110. $html .= $level3title. ' &ndash; '. api_substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT);
  1111. //adding ... (three dots) if the texts are too large and they are shortened
  1112. if (api_strlen($dataFromCourse) >= CONFVAL_NB_CHAR_FROM_CONTENT) {
  1113. $html .= '...';
  1114. }
  1115. }
  1116. $html .= "<br />\n";
  1117. }
  1118. }
  1119. }
  1120. }
  1121. return $html;
  1122. }
  1123. } // End function display_digest
  1124. /**
  1125. * Return the five star HTML
  1126. *
  1127. * @param string id of the rating ul element
  1128. * @param string url that will be added (for jquery see hot_courses.tpl)
  1129. * @param string point info array see function CourseManager::get_course_ranking()
  1130. * @param bool add a div wrapper
  1131. * @todo use templates
  1132. **/
  1133. public static function return_rating_system($id, $url, $point_info = array(), $add_div_wrapper = true) {
  1134. $number_of_users_who_voted = isset($point_info['users_who_voted']) ? $point_info['users_who_voted'] : null;
  1135. $percentage = isset($point_info['point_average']) ? $point_info['point_average'] : 0;
  1136. if (!empty($percentage)) {
  1137. $percentage = $percentage*125/100;
  1138. }
  1139. $accesses = isset($point_info['accesses']) ? $point_info['accesses'] : 0;
  1140. $star_label = sprintf(get_lang('XStarsOutOf5'), $point_info['point_average_star']);
  1141. $html = '<ul id="'.$id.'" class="star-rating">
  1142. <li class="current-rating" style="width:'.$percentage.'px;"></li>
  1143. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=1" title="'.$star_label.'" class="one-star">1</a></li>
  1144. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=2" title="'.$star_label.'" class="two-stars">2</a></li>
  1145. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=3" title="'.$star_label.'" class="three-stars">3</a></li>
  1146. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=4" title="'.$star_label.'" class="four-stars">4</a></li>
  1147. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=5" title="'.$star_label.'" class="five-stars">5</a></li>
  1148. </ul>';
  1149. $labels = array();
  1150. $labels[]= $number_of_users_who_voted == 1 ? $number_of_users_who_voted.' '.get_lang('Vote') : $number_of_users_who_voted.' '.get_lang('Votes');
  1151. $labels[]= $accesses == 1 ? $accesses.' '.get_lang('Visit') : $accesses.' '.get_lang('Visits');
  1152. if (!empty($number_of_users_who_voted)) {
  1153. $labels[]= get_lang('Average').' '.$point_info['point_average_star'].'/5';
  1154. }
  1155. $labels[]= $point_info['user_vote'] ? get_lang('YourVote').' ['.$point_info['user_vote'].']' : get_lang('YourVote'). ' [?] ';
  1156. if (!$add_div_wrapper && api_is_anonymous()) {
  1157. $labels[]= Display::tag('span', get_lang('LoginToVote'), array('class' => 'error'));
  1158. }
  1159. $html .= Display::span(implode(' | ', $labels) , array('id' => 'vote_label_'.$id, 'class' => 'vote_label_info'));
  1160. $html .= ' '.Display::span(' ', array('id' => 'vote_label2_'.$id));
  1161. if ($add_div_wrapper) {
  1162. $html = Display::div($html, array('id' => 'rating_wrapper_'.$id));
  1163. }
  1164. return $html;
  1165. }
  1166. public static function return_default_table_class() {
  1167. return 'data_table';
  1168. }
  1169. public static function page_header($title, $second_title = null, $size = 'h1') {
  1170. $title = Security::remove_XSS($title);
  1171. if (!empty($second_title)) {
  1172. $second_title = Security::remove_XSS($second_title);
  1173. $title .= "<small> $second_title<small>";
  1174. }
  1175. return '<div class="page-header"><'.$size.'>'.$title.'</'.$size.'></div>';
  1176. }
  1177. public static function page_header_and_translate($title, $second_title = null) {
  1178. $title = get_lang($title);
  1179. return self::page_header($title, $second_title);
  1180. }
  1181. public static function page_subheader_and_translate($title, $second_title = null) {
  1182. $title = get_lang($title);
  1183. return self::page_subheader($title, $second_title);
  1184. }
  1185. public static function page_subheader($title, $second_title = null) {
  1186. return self::page_header($title, $second_title, 'h2');
  1187. }
  1188. public static function page_subheader2($title, $second_title = null) {
  1189. return self::page_header($title, $second_title, 'h3');
  1190. }
  1191. public static function page_subheader3($title, $second_title = null) {
  1192. return self::page_header($title, $second_title, 'h4');
  1193. }
  1194. public static function page_subheader2($title, $second_title = null) {
  1195. return self::page_header($title, $second_title, 'h3');
  1196. }
  1197. public static function page_subheader3($title, $second_title = null) {
  1198. return self::page_header($title, $second_title, 'h4');
  1199. }
  1200. public static function description($list) {
  1201. $html = null;
  1202. if (!empty($list)) {
  1203. $html = '<dl class="dl-horizontal">';
  1204. foreach ($list as $item) {
  1205. $html .= '<dt>'.$item['title'].'</dd>';
  1206. $html .= '<dd>'.$item['content'].'</dt>';
  1207. }
  1208. $html .= '</dl>';
  1209. }
  1210. return $html;
  1211. }
  1212. public static function bar_progress($percentage, $show_percentage = true, $extra_info = null) {
  1213. $percentage = intval($percentage);
  1214. $div = '<div class="progress progress-striped">
  1215. <div class="bar" style="width: '.$percentage.'%;"></div>
  1216. </div>';
  1217. if ($show_percentage) {
  1218. $div .= '<div class="progresstext">'.$percentage.'%</div>';
  1219. } else {
  1220. if (!empty($extra_info)) {
  1221. $div .= '<div class="progresstext">'.$extra_info.'</div>';
  1222. }
  1223. }
  1224. return $div;
  1225. }
  1226. public static function badge($count, $type ="warning") {
  1227. $class = '';
  1228. switch ($type) {
  1229. case 'success':
  1230. $class = 'badge-success';
  1231. break;
  1232. case 'warning':
  1233. $class = 'badge-warning';
  1234. break;
  1235. case 'important':
  1236. $class = 'badge-important';
  1237. break;
  1238. case 'info':
  1239. $class = 'badge-info';
  1240. break;
  1241. case 'inverse':
  1242. $class = 'badge-inverse';
  1243. break;
  1244. }
  1245. if (!empty($count)) {
  1246. return ' <span class="badge '.$class.'">'.$count.'</span>';
  1247. }
  1248. return null;
  1249. }
  1250. public static function badge_group($badge_list) {
  1251. $html = '<div class="badge-group">';
  1252. foreach ($badge_list as $badge) {
  1253. $html .= $badge;
  1254. }
  1255. $html .= '</div>';
  1256. return $html;
  1257. }
  1258. public static function label($content, $type = null, $full_content = null) {
  1259. $class = '';
  1260. switch ($type) {
  1261. case 'success':
  1262. $class = 'label-success';
  1263. break;
  1264. case 'warning':
  1265. $class = 'label-warning';
  1266. break;
  1267. case 'important':
  1268. $class = 'label-important';
  1269. break;
  1270. case 'info':
  1271. $class = 'label-info';
  1272. break;
  1273. case 'inverse':
  1274. $class = 'label-inverse';
  1275. break;
  1276. }
  1277. $html = '';
  1278. if (!empty($content)) {
  1279. $html = '<span title="'.$full_content.'" class="label '.$class.'">';
  1280. $html .= $content;
  1281. $html .='</span>';
  1282. }
  1283. return $html;
  1284. }
  1285. /**
  1286. * Return a list of actions in a div
  1287. * @param array array(array('content' => 'Hello', 'url' => 'chamilo.org'));
  1288. * @return string
  1289. */
  1290. public static function actions($items) {
  1291. $html = null;
  1292. if (!empty($items)) {
  1293. $html = '<div class="new_actions"><ul class="nav nav-pills">';
  1294. foreach ($items as $value) {
  1295. $class = null;
  1296. if (isset($value['active']) && $value['active']) {
  1297. $class = 'class ="active"';
  1298. }
  1299. $html .= "<li $class >";
  1300. $html .= self::url($value['content'], $value['url']);
  1301. $html .= '</li>';
  1302. }
  1303. $html .= '</ul></div>';
  1304. }
  1305. return $html;
  1306. }
  1307. /**
  1308. * Prints a tooltip
  1309. */
  1310. public static function tip($text, $tip) {
  1311. if (empty($tip)) {
  1312. return $text;
  1313. }
  1314. return self::span($text, array('class' => 'boot-tooltip', 'title' => strip_tags($tip)));
  1315. }
  1316. public static function generate_accordion($items) {
  1317. $html = null;
  1318. if (!empty($items)) {
  1319. $id = api_get_unique_id();
  1320. //$html = '<div class="accordion" id="'.$id.'">'; //using bootstrap
  1321. $html = '<div class="accordion_jquery" id="'.$id.'">'; //using jquery
  1322. $count = 1;
  1323. foreach ($items as $item) {
  1324. $html .= '<div class="accordion-my-group">';
  1325. $html .= '<div class="accordion-heading">
  1326. <a class="accordion-toggle" data-toggle="collapse" data-parent="#'.$id.'" href="#collapse'.$count.'">
  1327. '.$item['title'].'
  1328. </a>
  1329. </div>';
  1330. //$html .= '<div id="collapse'.$count.'" class="accordion-body collapse in">
  1331. $html .= '<div id="collapse'.$count.'" class="accordion-body">';
  1332. //$html .= '<div class="accordion-inner">
  1333. $html .= '<div class="accordion-my-inner">
  1334. '.$item['content'].'
  1335. </div>
  1336. </div>';
  1337. }
  1338. $html .= '</div>';
  1339. }
  1340. return $html;
  1341. }
  1342. } //end class Display