display.lib.php 82 KB

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