display.lib.php 79 KB

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