display.lib.php 64 KB

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