display.lib.php 72 KB

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