display.lib.php 62 KB

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