display.lib.php 82 KB

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