display.lib.php 75 KB

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