display.lib.php 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. use Chamilo\CoreBundle\Entity\ExtraField;
  5. use Chamilo\CoreBundle\Framework\Container;
  6. /**
  7. * Class Display
  8. * Contains several public functions dealing with the display of
  9. * table data, messages, help topics, ...
  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. */
  21. class Display
  22. {
  23. /** @var Template */
  24. public static $global_template;
  25. public static $preview_style = null;
  26. /**
  27. * Constructor
  28. */
  29. public function __construct()
  30. {
  31. }
  32. /**
  33. * @return array
  34. */
  35. public static function toolList()
  36. {
  37. return array(
  38. 'group',
  39. 'work',
  40. 'glossary',
  41. 'forum',
  42. 'course_description',
  43. 'gradebook',
  44. 'attendance',
  45. 'course_progress',
  46. 'notebook'
  47. );
  48. }
  49. /**
  50. * Displays the page header
  51. *
  52. * @deprecated See template.lib.php class documentation
  53. *
  54. * @param string The name of the page (will be showed in the page title)
  55. * @param string Optional help file name
  56. * @param string $page_header
  57. */
  58. public static function display_header($tool_name = '', $help = null, $page_header = null)
  59. {
  60. return '';
  61. $origin = api_get_origin();
  62. $showHeader = true;
  63. if (isset($origin) && $origin == 'learnpath') {
  64. $showHeader = false;
  65. }
  66. self::$global_template = new Template($tool_name, $showHeader, $showHeader);
  67. // Fixing tools with any help it takes xxx part of main/xxx/index.php
  68. if (empty($help)) {
  69. $currentURL = api_get_self();
  70. preg_match('/main\/([^*\/]+)/', $currentURL, $matches);
  71. $toolList = self::toolList();
  72. if (!empty($matches)) {
  73. foreach ($matches as $match) {
  74. if (in_array($match, $toolList)) {
  75. $help = explode('_', $match);
  76. $help = array_map('ucfirst', $help);
  77. $help = implode('', $help);
  78. break;
  79. }
  80. }
  81. }
  82. }
  83. self::$global_template->setHelp($help);
  84. if (!empty(self::$preview_style)) {
  85. self::$global_template->preview_theme = self::$preview_style;
  86. self::$global_template->setCssFiles();
  87. self::$global_template->set_js_files();
  88. self::$global_template->setCssCustomFiles();
  89. }
  90. if (!empty($page_header)) {
  91. self::$global_template->assign('header', $page_header);
  92. }
  93. echo self::$global_template->show_header_template();
  94. }
  95. /**
  96. * Displays the reduced page header (without banner)
  97. * @deprecated See template.lib.php class documentation
  98. */
  99. public static function display_reduced_header()
  100. {
  101. return '';
  102. global $show_learnpath, $tool_name;
  103. self::$global_template = new Template($tool_name, false, false, $show_learnpath);
  104. echo self::$global_template->show_header_template();
  105. }
  106. /**
  107. * Display no header
  108. * @deprecated
  109. */
  110. public static function display_no_header()
  111. {
  112. return '';
  113. global $tool_name, $show_learnpath;
  114. $disable_js_and_css_files = true;
  115. self::$global_template = new Template($tool_name, false, false, $show_learnpath);
  116. }
  117. /**
  118. * Displays the reduced page header (without banner)
  119. * @deprecated See template.lib.php class documentation
  120. */
  121. public static function set_header()
  122. {
  123. return '';
  124. global $show_learnpath, $tool_name;
  125. self::$global_template = new Template($tool_name, false, false, $show_learnpath);
  126. }
  127. /**
  128. * Display the page footer
  129. * @deprecated See template.lib.php class documentation
  130. */
  131. public static function display_footer()
  132. {
  133. return '';
  134. echo self::$global_template->show_footer_template();
  135. }
  136. /**
  137. * Display the page footer
  138. * @deprecated See template.lib.php class documentation
  139. */
  140. public static function display_reduced_footer()
  141. {
  142. return '';
  143. echo self::$global_template->show_footer_js_template();
  144. echo '</body></html>';
  145. }
  146. /**
  147. * Displays the tool introduction of a tool.
  148. *
  149. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  150. * @param string $tool These are the constants that are used for indicating the tools.
  151. * @param array $editor_config Optional configuration settings for the online editor.
  152. * return: $tool return a string array list with the "define" in main_api.lib
  153. * @return html code for adding an introduction
  154. */
  155. public static function display_introduction_section($tool, $editor_config = null)
  156. {
  157. echo self::return_introduction_section($tool, $editor_config);
  158. }
  159. /**
  160. * @param string $tool
  161. * @param array $editor_config
  162. * @return null
  163. */
  164. public static function return_introduction_section($tool, $toolList = null)
  165. {
  166. $urlGenerator = Container::getRouter();
  167. $is_allowed_to_edit = api_is_allowed_to_edit();
  168. $courseInfo = api_get_course_info();
  169. $introduction_section = null;
  170. if (api_get_setting('course.enable_tool_introduction') == 'true' ||
  171. $tool == TOOL_COURSE_HOMEPAGE
  172. ) {
  173. $introduction_section = null;
  174. $TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
  175. $session_id = api_get_session_id();
  176. $course_id = api_get_course_int_id();
  177. /* Retrieves the module introduction text, if exist */
  178. $sql = "SELECT iid, intro_text FROM $TBL_INTRODUCTION
  179. WHERE
  180. c_id = $course_id AND
  181. tool ='".Database::escape_string($tool)."' AND
  182. session_id = '".intval($session_id)."'";
  183. $intro_dbQuery = Database::query($sql);
  184. $introContent = null;
  185. $toolId = null;
  186. if (Database::num_rows($intro_dbQuery) > 0) {
  187. $row = Database::fetch_array($intro_dbQuery);
  188. $introContent = $row['intro_text'];
  189. $toolId = $row['iid'];
  190. }
  191. $introContent = CourseHome::replaceTextWithToolUrls($introContent, $toolList);
  192. /* Determines the correct display */
  193. $displayIntro = false;
  194. if ($is_allowed_to_edit) {
  195. $displayIntro = true;
  196. }
  197. $thematicDescription = '';
  198. if ($tool == TOOL_COURSE_HOMEPAGE) {
  199. $thematic = new Thematic($courseInfo);
  200. $thematic->setCourseIntId(api_get_course_int_id());
  201. if (api_get_course_setting('display_info_advance_inside_homecourse') == '1') {
  202. $information_title = get_lang('InfoAboutLastDoneAdvance');
  203. $last_done_advance = $thematic->get_last_done_thematic_advance();
  204. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  205. } else if(api_get_course_setting('display_info_advance_inside_homecourse') == '2') {
  206. $information_title = get_lang('InfoAboutNextAdvanceNotDone');
  207. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  208. $thematic_advance_info = $thematic->get_thematic_advance_list($next_advance_not_done);
  209. } else if(api_get_course_setting('display_info_advance_inside_homecourse') == '3') {
  210. $information_title = get_lang('InfoAboutLastDoneAdvanceAndNextAdvanceNotDone');
  211. $last_done_advance = $thematic->get_last_done_thematic_advance();
  212. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  213. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  214. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  215. }
  216. if (!empty($thematic_advance_info)) {
  217. $thematic_advance = get_lang('CourseThematicAdvance').'&nbsp;'.$thematic->get_total_average_of_thematic_advances().'%';
  218. $thematic_info = $thematic->get_thematic_list($thematic_advance_info['thematic_id']);
  219. $thematic_advance_info['start_date'] = api_get_local_time($thematic_advance_info['start_date']);
  220. $thematic_advance_info['start_date'] = api_format_date($thematic_advance_info['start_date'], DATE_TIME_FORMAT_LONG);
  221. $thematicDescription = '<div class="thematic-postit">
  222. <div class="thematic-postit-top"><h3><a class="thematic-postit-head" style="" href="#"> '.$thematic_advance.'</h3></a></div>
  223. <div class="thematic-postit-center" style="display:none">';
  224. $thematicDescription .= '<div><strong>'.$thematic_info['title'].'</strong></div>';
  225. $thematicDescription .= '<div style="font-size:8pt;"><strong>'.$thematic_advance_info['start_date'].'</strong></div>';
  226. $thematicDescription .= '<div>'.$thematic_advance_info['content'].'</div>';
  227. $thematicDescription .= '<div>'.get_lang('DurationInHours').' : '.$thematic_advance_info['duration'].'</div>';
  228. if (!empty($thematic_advance_info2)){
  229. $thematic_info2 = $thematic->get_thematic_list($thematic_advance_info2['thematic_id']);
  230. $thematic_advance_info2['start_date'] = api_get_local_time($thematic_advance_info2['start_date']);
  231. $thematic_advance_info2['start_date'] = api_format_date($thematic_advance_info2['start_date'], DATE_TIME_FORMAT_LONG);
  232. $thematicDescription .= '<div><strong>'.$thematic_info2['title'].'</strong></div>';
  233. $thematicDescription .= '<div style="font-size:8pt;"><strong>'.$thematic_advance_info2['start_date'].'</strong></div>';
  234. $thematicDescription .= '<div>'.$thematic_advance_info2['content'].'</div>';
  235. $thematicDescription .= '<div>'.get_lang('DurationInHours').' : '.$thematic_advance_info2['duration'].'</div>';
  236. $thematicDescription .= '<br />';
  237. }
  238. $thematicDescription .= '</div>
  239. <div class="thematic-postit-bottom"></div>
  240. </div>';
  241. }
  242. }
  243. $introduction_section .= '<div id="introduction_block" class="row"><div class="col-md-12">';
  244. $introduction_section .= $thematicDescription;
  245. if (!empty($introContent)) {
  246. $introduction_section .= $introContent;
  247. }
  248. $introduction_section .= '</div>';
  249. if ($displayIntro) {
  250. if (empty($introContent)) {
  251. // Displays "Add intro" commands
  252. $introduction_section .= '<div id="introduction_block_action" class="col-md-2 col-md-offset-10">';
  253. $em = Database::getManager();
  254. $criteria = [
  255. 'tool' => $tool,
  256. 'cId' => api_get_course_int_id(),
  257. ];
  258. $toolIntro = $em->getRepository(
  259. 'ChamiloCourseBundle:CToolIntro'
  260. )->findOneBy($criteria);
  261. if ($toolIntro) {
  262. $url = $urlGenerator->generate(
  263. 'chamilo_course_ctoolintro_update',
  264. array(
  265. 'tool' => $toolIntro->getTool(),
  266. 'course' => api_get_course_id(),
  267. 'iid' => $toolIntro->getId(),
  268. )
  269. );
  270. } else {
  271. $url = $urlGenerator->generate(
  272. 'chamilo_course_ctoolintro_create',
  273. array(
  274. 'tool' => $tool,
  275. 'course' => api_get_course_id(),
  276. )
  277. );
  278. }
  279. $introduction_section .= "<a href=\"".$url."?".api_get_cidreq()."\">";
  280. $introduction_section .= Display::return_icon('introduction_add.gif', get_lang('AddIntro')).' ';
  281. $introduction_section .= "</a>";
  282. $introduction_section .= "</div>";
  283. } else {
  284. // Displays "edit intro && delete intro" commands
  285. $introduction_section .= '<div id="introduction_block_action" class="col-md-2 col-md-offset-10">';
  286. $url = $urlGenerator->generate(
  287. 'chamilo_course_ctoolintro_update',
  288. array(
  289. 'tool' => $tool,
  290. 'iid' => $toolId,
  291. 'course' => api_get_course_id(),
  292. )
  293. );
  294. $introduction_section .= "<a href=\"".$url."?".api_get_cidreq()."\">";
  295. $introduction_section .= Display::return_icon('edit.png', get_lang('Modify')).' ';
  296. $introduction_section .= "</a>";
  297. $url = $urlGenerator->generate(
  298. 'chamilo_course_ctoolintro_delete',
  299. array('iid' => $toolId, 'course' => api_get_course_id())
  300. );
  301. $introduction_section .= "<a onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice')))."')) return false;\" href=\"".$url."?".api_get_cidreq()."\">";
  302. $introduction_section .= Display::return_icon('delete.png', get_lang('AddIntro')).' ';
  303. $introduction_section .= "</a>";
  304. $introduction_section .= "</div>";
  305. }
  306. }
  307. $introduction_section .= '</div>';
  308. }
  309. return $introduction_section;
  310. }
  311. /**
  312. * Displays a table
  313. * @param array $header Titles for the table header
  314. * each item in this array can contain 3 values
  315. * - 1st element: the column title
  316. * - 2nd element: true or false (column sortable?)
  317. * - 3th element: additional attributes for
  318. * th-tag (eg for column-width)
  319. * - 4the element: additional attributes for the td-tags
  320. * @param array $content 2D-array with the tables content
  321. * @param array $sorting_options Keys are:
  322. * 'column' = The column to use as sort-key
  323. * 'direction' = SORT_ASC or SORT_DESC
  324. * @param array $paging_options Keys are:
  325. * 'per_page_default' = items per page when switching from
  326. * full- list to per-page-view
  327. * 'per_page' = number of items to show per page
  328. * 'page_nr' = The page to display
  329. * @param array $query_vars Additional variables to add in the query-string
  330. * @param string The style that the table will show. You can set 'table' or 'grid'
  331. * @author bart.mollet@hogent.be
  332. */
  333. public static function display_sortable_table(
  334. $header,
  335. $content,
  336. $sorting_options = array(),
  337. $paging_options = array(),
  338. $query_vars = null,
  339. $form_actions = array(),
  340. $style = 'table'
  341. ) {
  342. global $origin;
  343. $column = isset($sorting_options['column']) ? $sorting_options['column'] : 0;
  344. $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  345. $table = new SortableTableFromArray($content, $column, $default_items_per_page);
  346. if (is_array($query_vars)) {
  347. $table->set_additional_parameters($query_vars);
  348. }
  349. if ($style == 'table') {
  350. if (is_array($header) && count($header) > 0) {
  351. foreach ($header as $index => $header_item) {
  352. $table->set_header(
  353. $index,
  354. isset($header_item[0]) ? $header_item[0] : null,
  355. isset($header_item[1]) ? $header_item[1] : null,
  356. isset($header_item[2]) ? $header_item[2] : null,
  357. isset($header_item[3]) ? $header_item[3] : null
  358. );
  359. }
  360. }
  361. $table->set_form_actions($form_actions);
  362. $table->display();
  363. } else {
  364. $table->display_grid();
  365. }
  366. }
  367. /**
  368. * Returns an HTML table with sortable column (through complete page refresh)
  369. * @param array $header
  370. * @param array $content Array of row arrays
  371. * @param array $sorting_options
  372. * @param array $paging_options
  373. * @param array $query_vars
  374. * @param array $form_actions
  375. * @param string $style
  376. * @return string HTML string for array
  377. */
  378. public static function return_sortable_table(
  379. $header,
  380. $content,
  381. $sorting_options = array(),
  382. $paging_options = array(),
  383. $query_vars = null,
  384. $form_actions = array(),
  385. $style = 'table'
  386. ) {
  387. ob_start();
  388. self::display_sortable_table(
  389. $header,
  390. $content,
  391. $sorting_options,
  392. $paging_options,
  393. $query_vars,
  394. $form_actions,
  395. $style
  396. );
  397. $content = ob_get_contents();
  398. ob_end_clean();
  399. return $content;
  400. }
  401. /**
  402. * Shows a nice grid
  403. * @param string grid name (important to create css)
  404. * @param array header content
  405. * @param array array with the information to show
  406. * @param array $paging_options Keys are:
  407. * 'per_page_default' = items per page when switching from
  408. * full- list to per-page-view
  409. * 'per_page' = number of items to show per page
  410. * 'page_nr' = The page to display
  411. * 'hide_navigation' = true to hide the navigation
  412. * @param array $query_vars Additional variables to add in the query-string
  413. * @param array $form actions Additional variables to add in the query-string
  414. * @param mixed An array with bool values to know which columns show.
  415. * i.e: $visibility_options= array(true, false) we will only show the first column
  416. * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
  417. */
  418. public static function display_sortable_grid(
  419. $name,
  420. $header,
  421. $content,
  422. $paging_options = array(),
  423. $query_vars = null,
  424. $form_actions = array(),
  425. $visibility_options = true,
  426. $sort_data = true,
  427. $grid_class = array()
  428. ) {
  429. echo self::return_sortable_grid(
  430. $name,
  431. $header,
  432. $content,
  433. $paging_options,
  434. $query_vars,
  435. $form_actions,
  436. $visibility_options,
  437. $sort_data,
  438. $grid_class
  439. );
  440. }
  441. /**
  442. * Gets a nice grid in html string
  443. * @param string grid name (important to create css)
  444. * @param array header content
  445. * @param array array with the information to show
  446. * @param array $paging_options Keys are:
  447. * 'per_page_default' = items per page when switching from
  448. * full- list to per-page-view
  449. * 'per_page' = number of items to show per page
  450. * 'page_nr' = The page to display
  451. * 'hide_navigation' = true to hide the navigation
  452. * @param array $query_vars Additional variables to add in the query-string
  453. * @param array $form actions Additional variables to add in the query-string
  454. * @param mixed An array with bool values to know which columns show. i.e:
  455. * $visibility_options= array(true, false) we will only show the first column
  456. * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing
  457. * @param bool true for sorting data or false otherwise
  458. * @param array grid classes
  459. * @return string html grid
  460. */
  461. public static function return_sortable_grid(
  462. $name,
  463. $header,
  464. $content,
  465. $paging_options = array(),
  466. $query_vars = null,
  467. $form_actions = array(),
  468. $visibility_options = true,
  469. $sort_data = true,
  470. $grid_class = array(),
  471. $elementCount = 0
  472. ) {
  473. $column = 0;
  474. $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  475. $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name);
  476. $table->total_number_of_items = intval($elementCount);
  477. if (is_array($query_vars)) {
  478. $table->set_additional_parameters($query_vars);
  479. }
  480. return $table->display_simple_grid(
  481. $visibility_options,
  482. $paging_options['hide_navigation'],
  483. $default_items_per_page,
  484. $sort_data,
  485. $grid_class
  486. );
  487. }
  488. /**
  489. * Displays a table with a special configuration
  490. * @param array $header Titles for the table header
  491. * each item in this array can contain 3 values
  492. * - 1st element: the column title
  493. * - 2nd element: true or false (column sortable?)
  494. * - 3th element: additional attributes for th-tag (eg for column-width)
  495. * - 4the element: additional attributes for the td-tags
  496. * @param array $content 2D-array with the tables content
  497. * @param array $sorting_options Keys are:
  498. * 'column' = The column to use as sort-key
  499. * 'direction' = SORT_ASC or SORT_DESC
  500. * @param array $paging_options Keys are:
  501. * 'per_page_default' = items per page when switching from full list to per-page-view
  502. * 'per_page' = number of items to show per page
  503. * 'page_nr' = The page to display
  504. * @param array $query_vars Additional variables to add in the query-string
  505. * @param array $column_show Array of binaries 1= show columns 0. hide a column
  506. * @param array $column_order An array of integers that let us decide how the columns are going to be sort.
  507. * i.e: $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column
  508. * @param array $form_actions Set optional forms actions
  509. *
  510. * @author Julio Montoya
  511. */
  512. public static function display_sortable_config_table(
  513. $table_name,
  514. $header,
  515. $content,
  516. $sorting_options = array(),
  517. $paging_options = array(),
  518. $query_vars = null,
  519. $column_show = array(),
  520. $column_order = array(),
  521. $form_actions = array()
  522. ) {
  523. $column = isset($sorting_options['column']) ? $sorting_options['column'] : 0;
  524. $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20;
  525. $table = new SortableTableFromArrayConfig(
  526. $content,
  527. $column,
  528. $default_items_per_page,
  529. $table_name,
  530. $column_show,
  531. $column_order
  532. );
  533. if (is_array($query_vars)) {
  534. $table->set_additional_parameters($query_vars);
  535. }
  536. // Show or hide the columns header
  537. if (is_array($column_show)) {
  538. for ($i = 0; $i < count($column_show); $i++) {
  539. if (!empty($column_show[$i])) {
  540. $val0 = isset($header[$i][0]) ? $header[$i][0] : null;
  541. $val1 = isset($header[$i][1]) ? $header[$i][1] : null;
  542. $val2 = isset($header[$i][2]) ? $header[$i][2] : null;
  543. $val3 = isset($header[$i][3]) ? $header[$i][3] : null;
  544. $table->set_header($i, $val0, $val1, $val2, $val3);
  545. }
  546. }
  547. }
  548. $table->set_form_actions($form_actions);
  549. $table->display();
  550. }
  551. /**
  552. * Displays a normal message. It is recommended to use this public function
  553. * to display any normal information messages.
  554. * @param string $message
  555. * @param bool $filter (true) or not (false)
  556. * @param bool $returnValue
  557. *
  558. * @deprecated Use <code>Display::addFlash(Display::return_message($message, 'normal'));</code>
  559. * Or <code>echo Display::return_message($message, 'normal')</code>
  560. *
  561. * @return void
  562. */
  563. public static function display_normal_message(
  564. $message,
  565. $filter = true,
  566. $returnValue = false
  567. ) {
  568. $message = self::return_message($message, 'normal', $filter);
  569. if ($returnValue) {
  570. return $message;
  571. } else {
  572. echo $message;
  573. }
  574. }
  575. /**
  576. * Displays an warning message. Use this if you want to draw attention to something
  577. * This can also be used for instance with the hint in the exercises
  578. *
  579. * @deprecated use Display::addFlash(Display::return_message($message, 'warning'));
  580. */
  581. public static function display_warning_message(
  582. $message,
  583. $filter = true,
  584. $returnValue = false
  585. ) {
  586. $message = self::return_message($message, 'warning', $filter);
  587. if ($returnValue) {
  588. return $message;
  589. } else {
  590. echo $message;
  591. }
  592. }
  593. /**
  594. * Displays an confirmation message. Use this if something has been done successfully
  595. * @param bool Filter (true) or not (false)
  596. * @deprecated use Display::addFlash(Display::return_message($message, 'confirm'));
  597. * @return void
  598. */
  599. public static function display_confirmation_message(
  600. $message,
  601. $filter = true,
  602. $returnValue = false
  603. ) {
  604. $message = self::return_message($message, 'confirm', $filter);
  605. if ($returnValue) {
  606. return $message;
  607. } else {
  608. echo $message;
  609. }
  610. }
  611. /**
  612. * Displays an error message. It is recommended to use this public function if an error occurs
  613. * @param string $message - include any additional html
  614. * tags if you need them
  615. * @param bool Filter (true) or not (false)
  616. * @deprecated use Display::addFlash(Display::return_message($message, 'error'));
  617. *
  618. * @return void
  619. */
  620. public static function display_error_message(
  621. $message,
  622. $filter = true,
  623. $returnValue = false
  624. ) {
  625. $message = self::return_message($message, 'error', $filter);
  626. if ($returnValue) {
  627. return $message;
  628. } else {
  629. echo $message;
  630. }
  631. }
  632. /**
  633. * @param string $message
  634. * @param string $type
  635. * @param bool $filter
  636. */
  637. public static function return_message_and_translate(
  638. $message,
  639. $type = 'normal',
  640. $filter = true
  641. ) {
  642. $message = get_lang($message);
  643. echo self::return_message($message, $type, $filter);
  644. }
  645. /**
  646. * Returns a div html string with
  647. * @param string $message
  648. * @param string $type Example: confirm, normal, warning, error
  649. * @param bool $filter Whether to XSS-filter or not
  650. * @return string Message wrapped into an HTML div
  651. */
  652. public static function return_message(
  653. $message,
  654. $type = 'normal',
  655. $filter = true
  656. ) {
  657. if (empty($message)) {
  658. return '';
  659. }
  660. if ($filter) {
  661. $message = api_htmlentities(
  662. $message,
  663. ENT_QUOTES,
  664. api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding()
  665. );
  666. }
  667. $class = '';
  668. switch ($type) {
  669. case 'warning':
  670. $class .= 'alert alert-warning';
  671. break;
  672. case 'error':
  673. $class .= 'alert alert-danger';
  674. break;
  675. case 'confirmation':
  676. case 'confirm':
  677. case 'success':
  678. $class .= 'alert alert-success';
  679. break;
  680. case 'normal':
  681. default:
  682. $class .= 'alert alert-info';
  683. }
  684. return self::div($message, array('class'=> $class));
  685. }
  686. /**
  687. * Returns an encrypted mailto hyperlink
  688. *
  689. * @param string e-mail
  690. * @param string clickable text
  691. * @param string optional, class from stylesheet
  692. * @return string encrypted mailto hyperlink
  693. */
  694. public static function encrypted_mailto_link(
  695. $email,
  696. $clickable_text = null,
  697. $style_class = ''
  698. ) {
  699. if (is_null($clickable_text)) {
  700. $clickable_text = $email;
  701. }
  702. // "mailto:" already present?
  703. if (substr($email, 0, 7) != 'mailto:') {
  704. $email = 'mailto:'.$email;
  705. }
  706. // Class (stylesheet) defined?
  707. if ($style_class != '') {
  708. $style_class = ' class="'.$style_class.'"';
  709. }
  710. // Encrypt email
  711. $hmail = '';
  712. for ($i = 0; $i < strlen($email); $i++) {
  713. $hmail .= '&#'.ord($email {
  714. $i }).';';
  715. }
  716. $hclickable_text = null;
  717. // Encrypt clickable text if @ is present
  718. if (strpos($clickable_text, '@')) {
  719. for ($i = 0; $i < strlen($clickable_text); $i++) {
  720. $hclickable_text .= '&#'.ord($clickable_text {
  721. $i }).';';
  722. }
  723. } else {
  724. $hclickable_text = @htmlspecialchars(
  725. $clickable_text,
  726. ENT_QUOTES,
  727. api_get_system_encoding()
  728. );
  729. }
  730. // Return encrypted mailto hyperlink
  731. return '<a href="'.$hmail.'"'.$style_class.' class="clickable_email_link">'.$hclickable_text.'</a>';
  732. }
  733. /**
  734. * Returns an mailto icon hyperlink
  735. *
  736. * @param string e-mail
  737. * @param string icon source file from the icon lib
  738. * @param integer icon size from icon lib
  739. * @param string optional, class from stylesheet
  740. * @return string encrypted mailto hyperlink
  741. */
  742. public static function icon_mailto_link(
  743. $email,
  744. $icon_file = "mail.png",
  745. $icon_size = 22,
  746. $style_class = ''
  747. ) {
  748. // "mailto:" already present?
  749. if (substr($email, 0, 7) != 'mailto:') {
  750. $email = 'mailto:'.$email;
  751. }
  752. // Class (stylesheet) defined?
  753. if ($style_class != '') {
  754. $style_class = ' class="'.$style_class.'"';
  755. }
  756. // Encrypt email
  757. $hmail = '';
  758. for ($i = 0; $i < strlen($email); $i++) {
  759. $hmail .= '&#'.ord($email {
  760. $i }).';';
  761. }
  762. // icon html code
  763. $icon_html_source = self::return_icon(
  764. $icon_file,
  765. $hmail,
  766. '',
  767. $icon_size
  768. );
  769. // Return encrypted mailto hyperlink
  770. return '<a href="'.$hmail.'"'.$style_class.' class="clickable_email_link">'.$icon_html_source.'</a>';
  771. }
  772. /**
  773. * Prints an <option>-list with all letters (A-Z).
  774. * @param char $selected_letter The letter that should be selected
  775. * @todo This is English language specific implementation.
  776. * It should be adapted for the other languages.
  777. * @return string
  778. */
  779. public static function get_alphabet_options($selected_letter = '')
  780. {
  781. $result = '';
  782. for ($i = 65; $i <= 90; $i++) {
  783. $letter = chr($i);
  784. $result .= '<option value="'.$letter.'"';
  785. if ($selected_letter == $letter) {
  786. $result .= ' selected="selected"';
  787. }
  788. $result .= '>'.$letter.'</option>';
  789. }
  790. return $result;
  791. }
  792. /**
  793. * Get the options withing a select box within the given values
  794. * @param int Min value
  795. * @param int Max value
  796. * @param int Default value
  797. * @return string HTML select options
  798. */
  799. public static function get_numeric_options($min, $max, $selected_num = 0)
  800. {
  801. $result = '';
  802. for ($i = $min; $i <= $max; $i++) {
  803. $result .= '<option value="'.$i.'"';
  804. if (is_int($selected_num)) {
  805. if ($selected_num == $i) {
  806. $result .= ' selected="selected"';
  807. }
  808. }
  809. $result .= '>'.$i.'</option>';
  810. }
  811. return $result;
  812. }
  813. /**
  814. * This public function displays an icon
  815. * @param string The filename of the file (in the main/img/ folder
  816. * @param string The alt text (probably a language variable)
  817. * @param array additional attributes (for instance height, width, onclick, ...)
  818. * @param integer The wanted width of the icon (to be looked for in the corresponding img/icons/ folder)
  819. * @return void
  820. */
  821. public static function display_icon(
  822. $image,
  823. $alt_text = '',
  824. $additional_attributes = array(),
  825. $size = ICON_SIZE_SMALL
  826. ) {
  827. echo self::return_icon($image, $alt_text, $additional_attributes, $size);
  828. }
  829. /**
  830. * Gets the path of an icon
  831. *
  832. * @param string $icon
  833. * @param int $size
  834. *
  835. * @return string
  836. */
  837. public static function returnIconPath($icon, $size = ICON_SIZE_SMALL)
  838. {
  839. return self::return_icon($icon, null, null, $size, null, true, false);
  840. }
  841. /**
  842. * This public function returns the htmlcode for an icon
  843. *
  844. * @param string The filename of the file (in the main/img/ folder
  845. * @param string The alt text (probably a language variable)
  846. * @param array Additional attributes (for instance height, width, onclick, ...)
  847. * @param integer The wanted width of the icon (to be looked for in the corresponding img/icons/ folder)
  848. * @return string An HTML string of the right <img> tag
  849. *
  850. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University 2006
  851. * @author Julio Montoya 2010 Function improved, adding image constants
  852. * @author Yannick Warnier 2011 Added size handler
  853. * @version Feb 2011
  854. */
  855. public static function return_icon(
  856. $image,
  857. $alt_text = '',
  858. $additional_attributes = array(),
  859. $size = ICON_SIZE_SMALL,
  860. $show_text = true,
  861. $return_only_path = false,
  862. $loadThemeIcon = true
  863. ) {
  864. $image = trim($image);
  865. $size_extra = '';
  866. if (isset($size)) {
  867. $size_extra = $size . '/';
  868. }
  869. $icon = 'img/icons/'.$size_extra.$image;
  870. $icon = Container::getAsset()->getUrl($icon);
  871. if ($return_only_path) {
  872. return $icon;
  873. }
  874. $img = self::img($icon, $alt_text, $additional_attributes);
  875. if (SHOW_TEXT_NEAR_ICONS == true && !empty($alt_text)) {
  876. if ($show_text) {
  877. $img = "$img $alt_text";
  878. }
  879. }
  880. return $img;
  881. }
  882. /**
  883. * Returns the htmlcode for an image
  884. *
  885. * @param string $image_path the filename of the file (in the main/img/ folder
  886. * @param string $alt_text the alt text (probably a language variable)
  887. * @param array $additional_attributes (for instance height, width, onclick, ...)
  888. * @param boolean $filterPath Optional. Whether filter the image path. Default is true
  889. * @return string
  890. * @author Julio Montoya 2010
  891. */
  892. public static function img(
  893. $image_path,
  894. $alt_text = '',
  895. $additional_attributes = null,
  896. $filterPath = true
  897. ) {
  898. if (empty($image_path)) {
  899. // For some reason, the call to img() happened without a proper
  900. // image. Log the error and return an empty string to avoid
  901. // breaking the HTML
  902. $trace = debug_backtrace();
  903. $caller = $trace[1];
  904. error_log('No image provided in Display::img(). Caller info: '.print_r($caller, 1));
  905. return '';
  906. }
  907. // Sanitizing the parameter $image_path
  908. if ($filterPath) {
  909. $image_path = Security::filter_img_path($image_path);
  910. }
  911. // alt text = the image name if there is none provided (for XHTML compliance)
  912. if ($alt_text == '') {
  913. $alt_text = basename($image_path);
  914. }
  915. if (empty($additional_attributes)) {
  916. $additional_attributes = [];
  917. }
  918. $additional_attributes['src'] = $image_path;
  919. if (empty($additional_attributes['alt'])) {
  920. $additional_attributes['alt'] = $alt_text;
  921. }
  922. if (empty($additional_attributes['title'])) {
  923. $additional_attributes['title'] = $alt_text;
  924. }
  925. return self::tag('img', '', $additional_attributes);
  926. }
  927. /**
  928. * Returns the htmlcode for a tag (h3, h1, div, a, button), etc
  929. *
  930. * @param string $tag the tag name
  931. * @param string $content the tag's content
  932. * @param array $additional_attributes (for instance height, width, onclick, ...)
  933. *
  934. * @return string
  935. * @author Julio Montoya 2010
  936. */
  937. public static function tag($tag, $content, $additional_attributes = array())
  938. {
  939. $attribute_list = '';
  940. // Managing the additional attributes
  941. if (!empty($additional_attributes) && is_array($additional_attributes)) {
  942. $attribute_list = '';
  943. foreach ($additional_attributes as $key => & $value) {
  944. $attribute_list .= $key.'="'.$value.'" ';
  945. }
  946. }
  947. //some tags don't have this </XXX>
  948. if (in_array($tag, array('img', 'input', 'br'))) {
  949. $return_value = '<'.$tag.' '.$attribute_list.' />';
  950. } else {
  951. $return_value = '<'.$tag.' '.$attribute_list.' >'.$content.'</'.$tag.'>';
  952. }
  953. return $return_value;
  954. }
  955. /**
  956. * Creates a URL anchor
  957. * @param string $name
  958. * @param string $url
  959. * @param array $attributes
  960. *
  961. * @return string
  962. */
  963. public static function url($name, $url, $attributes = array())
  964. {
  965. if (!empty($url)) {
  966. $url = preg_replace('#&amp;#', '&', $url);
  967. $url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
  968. $attributes['href'] = $url;
  969. }
  970. return self::tag('a', $name, $attributes);
  971. }
  972. /**
  973. * Creates a div tag
  974. *
  975. * @param string $content
  976. * @param array $attributes
  977. * @return string
  978. */
  979. public static function div($content, $attributes = array())
  980. {
  981. return self::tag('div', $content, $attributes);
  982. }
  983. /**
  984. * Creates a span tag
  985. */
  986. public static function span($content, $attributes = array())
  987. {
  988. return self::tag('span', $content, $attributes);
  989. }
  990. /**
  991. * Displays an HTML input tag
  992. */
  993. public static function input($type, $name, $value, $attributes = array())
  994. {
  995. if (isset($type)) {
  996. $attributes['type'] = $type;
  997. }
  998. if (isset($name)) {
  999. $attributes['name'] = $name;
  1000. }
  1001. if (isset($value)) {
  1002. $attributes['value'] = $value;
  1003. }
  1004. return self::tag('input', '', $attributes);
  1005. }
  1006. /**
  1007. * @param $name
  1008. * @param $value
  1009. * @param array $attributes
  1010. * @return string
  1011. */
  1012. public static function button($name, $value, $attributes = array())
  1013. {
  1014. if (!empty($name)) {
  1015. $attributes['name'] = $name;
  1016. }
  1017. return self::tag('button', $value, $attributes);
  1018. }
  1019. /**
  1020. * Displays an HTML select tag
  1021. *
  1022. */
  1023. public static function select(
  1024. $name,
  1025. $values,
  1026. $default = -1,
  1027. $extra_attributes = array(),
  1028. $show_blank_item = true,
  1029. $blank_item_text = null
  1030. ) {
  1031. $html = '';
  1032. $extra = '';
  1033. $default_id = 'id="'.$name.'" ';
  1034. foreach ($extra_attributes as $key => $parameter) {
  1035. if ($key == 'id') {
  1036. $default_id = '';
  1037. }
  1038. $extra .= $key.'="'.$parameter.'" ';
  1039. }
  1040. $html .= '<select name="'.$name.'" '.$default_id.' '.$extra.'>';
  1041. if ($show_blank_item) {
  1042. if (empty($blank_item_text)) {
  1043. $blank_item_text = get_lang('Select');
  1044. } else {
  1045. $blank_item_text = Security::remove_XSS($blank_item_text);
  1046. }
  1047. $html .= self::tag(
  1048. 'option',
  1049. '-- '.$blank_item_text.' --',
  1050. array('value' => '-1')
  1051. );
  1052. }
  1053. if ($values) {
  1054. foreach ($values as $key => $value) {
  1055. if (is_array($value) && isset($value['name'])) {
  1056. $value = $value['name'];
  1057. }
  1058. $html .= '<option value="'.$key.'"';
  1059. if (is_array($default)) {
  1060. foreach ($default as $item) {
  1061. if ($item == $key) {
  1062. $html .= ' selected="selected"';
  1063. break;
  1064. }
  1065. }
  1066. } else {
  1067. if ($default == $key) {
  1068. $html .= ' selected="selected"';
  1069. }
  1070. }
  1071. $html .= '>'.$value.'</option>';
  1072. }
  1073. }
  1074. $html .= '</select>';
  1075. return $html;
  1076. }
  1077. /**
  1078. * Creates a tab menu
  1079. * Requirements: declare the jquery, jquery-ui libraries + the jquery-ui.css
  1080. * in the $htmlHeadXtra variable before the display_header
  1081. * Add this script
  1082. * @example
  1083. * <script>
  1084. $(function() {
  1085. $( "#tabs" ).tabs();
  1086. });
  1087. </script>
  1088. * @param array $headers list of the tab titles
  1089. * @param array $items
  1090. * @param string $id id of the container of the tab in the example "tabs"
  1091. * @param array $attributes for the ul
  1092. * @param array $ul_attributes
  1093. *
  1094. * @return string
  1095. */
  1096. public static function tabs(
  1097. $headers,
  1098. $items,
  1099. $id = 'tabs',
  1100. $attributes = array(),
  1101. $ul_attributes = array()
  1102. ) {
  1103. if (empty($headers) || count($headers) == 0) {
  1104. return '';
  1105. }
  1106. $lis = '';
  1107. $i = 1;
  1108. foreach ($headers as $item) {
  1109. $active = '';
  1110. if ($i == 1) {
  1111. $active = ' active';
  1112. }
  1113. $item = self::tag(
  1114. 'a',
  1115. $item,
  1116. array(
  1117. 'href' => '#'.$id.'-'.$i,
  1118. 'role' => 'tab',
  1119. 'data-toggle' => 'tab',
  1120. 'id' => $id.$i,
  1121. )
  1122. );
  1123. $ul_attributes['role'] = 'presentation';
  1124. $ul_attributes['class'] = $active;
  1125. $lis .= self::tag('li', $item, $ul_attributes);
  1126. $i++;
  1127. }
  1128. $ul = self::tag(
  1129. 'ul',
  1130. $lis,
  1131. [
  1132. 'class' => 'nav nav-tabs tabs-margin',
  1133. 'role' => 'tablist',
  1134. 'id' => 'ul_'.$id
  1135. ]
  1136. );
  1137. $i = 1;
  1138. $divs = '';
  1139. foreach ($items as $content) {
  1140. $active = '';
  1141. if ($i == 1) {
  1142. $active = ' active';
  1143. }
  1144. $divs .= self::tag(
  1145. 'div',
  1146. $content,
  1147. array('id' => $id.'-'.$i, 'class' => 'tab-pane '.$active, 'role' => 'tabpanel')
  1148. );
  1149. $i++;
  1150. }
  1151. $attributes['id'] = $id;
  1152. $attributes['role'] = 'tabpanel';
  1153. $attributes['class'] = 'tab-wrapper';
  1154. $main_div = self::tag(
  1155. 'div',
  1156. $ul.self::tag('div', $divs, ['class' => 'tab-content']),
  1157. $attributes
  1158. );
  1159. return $main_div;
  1160. }
  1161. /**
  1162. * @param $headers
  1163. * @param null $selected
  1164. *
  1165. * @return string
  1166. */
  1167. public static function tabsOnlyLink($headers, $selected = null)
  1168. {
  1169. $id = uniqid();
  1170. $i = 1;
  1171. $lis = null;
  1172. foreach ($headers as $item) {
  1173. $class = null;
  1174. if ($i == $selected) {
  1175. $class = 'active';
  1176. }
  1177. $item = self::tag(
  1178. 'a',
  1179. $item['content'],
  1180. array('id' => $id.'-'.$i, 'href' => $item['url'])
  1181. );
  1182. $lis .= self::tag('li', $item, array('class' => $class));
  1183. $i++;
  1184. }
  1185. return self::tag(
  1186. 'ul',
  1187. $lis,
  1188. array('class' => 'nav nav-tabs tabs-margin')
  1189. );
  1190. }
  1191. /**
  1192. * In order to display a grid using jqgrid you have to:
  1193. * @example
  1194. * After your Display::display_header function you have to add the nex javascript code: *
  1195. * <script>
  1196. * echo Display::grid_js('my_grid_name', $url,$columns, $column_model, $extra_params,array());
  1197. * // for more information of this function check the grid_js() function
  1198. * </script>
  1199. * //Then you have to call the grid_html
  1200. * echo Display::grid_html('my_grid_name');
  1201. * As you can see both function use the same "my_grid_name" this is very important otherwise nothing will work
  1202. *
  1203. * @param string the div id, this value must be the same with the first parameter of Display::grid_js()
  1204. * @return string html
  1205. *
  1206. */
  1207. public static function grid_html($div_id)
  1208. {
  1209. $table = self::tag('table', '', array('id' => $div_id));
  1210. $table .= self::tag('div', '', array('id' => $div_id.'_pager'));
  1211. return $table;
  1212. }
  1213. /**
  1214. * @param string $label
  1215. * @param string $form_item
  1216. * @return string
  1217. */
  1218. public static function form_row($label, $form_item)
  1219. {
  1220. $label = self::span($label, array('class' =>'control-label'));
  1221. $form_item = self::div($form_item, array('class' =>'controls'));
  1222. return self::div($label.$form_item, array('class'=>'control-group'));
  1223. }
  1224. /**
  1225. * This is a wrapper to use the jqgrid in Chamilo.
  1226. * For the other jqgrid options visit http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options
  1227. * This function need to be in the ready jquery function
  1228. * example --> $(function() { <?php echo Display::grid_js('grid' ...); ?> }
  1229. * In order to work this function needs the Display::grid_html function with the same div id
  1230. *
  1231. * @param string $div_id div id
  1232. * @param string $url url where the jqgrid will ask for data (if datatype = json)
  1233. * @param array $column_names Visible columns (you should use get_lang). An array in which we place the names of the columns.
  1234. * This is the text that appears in the head of the grid (Header layer).
  1235. * Example: colname {name:'date', index:'date', width:120, align:'right'},
  1236. * @param array $column_model the column model : Array which describes the parameters of the columns.This is the most important part of the grid.
  1237. * For a full description of all valid values see colModel API. See the url above.
  1238. * @param array $extra_params extra parameters
  1239. * @param array $data data that will be loaded
  1240. * @param string $formatter A string that will be appended to the JSON returned
  1241. * @param bool $fixed_width not implemented yet
  1242. * @return string the js code
  1243. *
  1244. */
  1245. public static function grid_js(
  1246. $div_id,
  1247. $url,
  1248. $column_names,
  1249. $column_model,
  1250. $extra_params,
  1251. $data = array(),
  1252. $formatter = '',
  1253. $fixed_width = false
  1254. ) {
  1255. $obj = new stdClass();
  1256. $obj->first = 'first';
  1257. if (!empty($url)) {
  1258. $obj->url = $url;
  1259. }
  1260. //This line should only be used/modified in case of having characters
  1261. // encoding problems - see #6159
  1262. //$column_names = array_map("utf8_encode", $column_names);
  1263. $obj->colNames = $column_names;
  1264. $obj->colModel = $column_model;
  1265. $obj->pager = '#'.$div_id.'_pager';
  1266. $obj->datatype = 'json';
  1267. $obj->viewrecords = 'true';
  1268. $all_value = 10000000;
  1269. // Default row quantity
  1270. if (!isset($extra_params['rowList'])) {
  1271. $extra_params['rowList'] = array(20, 50, 100, 500, 1000, $all_value);
  1272. }
  1273. $json = '';
  1274. if (!empty($extra_params['datatype'])) {
  1275. $obj->datatype = $extra_params['datatype'];
  1276. }
  1277. // Row even odd style.
  1278. $obj->altRows = true;
  1279. if (!empty($extra_params['altRows'])) {
  1280. $obj->altRows = $extra_params['altRows'];
  1281. }
  1282. if (!empty($extra_params['sortname'])) {
  1283. $obj->sortname = $extra_params['sortname'];
  1284. }
  1285. if (!empty($extra_params['sortorder'])) {
  1286. $obj->sortorder = $extra_params['sortorder'];
  1287. }
  1288. if (!empty($extra_params['rowList'])) {
  1289. $obj->rowList = $extra_params['rowList'];
  1290. }
  1291. //Sets how many records we want to view in the grid
  1292. $obj->rowNum = 20;
  1293. if (!empty($extra_params['rowNum'])) {
  1294. $obj->rowNum = $extra_params['rowNum'];
  1295. }
  1296. if (!empty($extra_params['viewrecords'])) {
  1297. $obj->viewrecords = $extra_params['viewrecords'];
  1298. }
  1299. $beforeSelectRow = null;
  1300. if (isset($extra_params['beforeSelectRow'])) {
  1301. $beforeSelectRow = "beforeSelectRow: ".$extra_params['beforeSelectRow'].", ";
  1302. unset($extra_params['beforeSelectRow']);
  1303. }
  1304. // Adding extra params
  1305. if (!empty($extra_params)) {
  1306. foreach ($extra_params as $key => $element) {
  1307. // the groupHeaders key gets a special treatment
  1308. if ($key != 'groupHeaders') {
  1309. $obj->$key = $element;
  1310. }
  1311. }
  1312. }
  1313. // Adding static data.
  1314. if (!empty($data)) {
  1315. $data_var = $div_id.'_data';
  1316. $json .= ' var '.$data_var.' = '.json_encode($data).';';
  1317. $obj->data = $data_var;
  1318. $obj->datatype = 'local';
  1319. $json .= "\n";
  1320. }
  1321. $obj->end = 'end';
  1322. $json_encode = json_encode($obj);
  1323. if (!empty($data)) {
  1324. //Converts the "data":"js_variable" to "data":js_variable,
  1325. // otherwise it will not work
  1326. $json_encode = str_replace('"data":"'.$data_var.'"', '"data":'.$data_var.'', $json_encode);
  1327. }
  1328. // Fixing true/false js values that doesn't need the ""
  1329. $json_encode = str_replace(':"true"', ':true', $json_encode);
  1330. // wrap_cell is not a valid jqgrid attributes is a hack to wrap a text
  1331. $json_encode = str_replace('"wrap_cell":true', 'cellattr : function(rowId, value, rowObject, colModel, arrData) { return \'class = "jqgrid_whitespace"\'; }', $json_encode);
  1332. $json_encode = str_replace(':"false"', ':false', $json_encode);
  1333. $json_encode = str_replace('"formatter":"action_formatter"', 'formatter:action_formatter', $json_encode);
  1334. $json_encode = str_replace(array('{"first":"first",', '"end":"end"}'), '', $json_encode);
  1335. // Creating the jqgrid element.
  1336. $json .= '$("#'.$div_id.'").jqGrid({';
  1337. //$json .= $beforeSelectRow;
  1338. $json .= $json_encode;
  1339. $json .= '});';
  1340. // Grouping headers option
  1341. if (isset($extra_params['groupHeaders'])) {
  1342. $groups = '';
  1343. foreach ($extra_params['groupHeaders'] as $group) {
  1344. //{ "startColumnName" : "courses", "numberOfColumns" : 1, "titleText" : "Order Info" },
  1345. $groups .= '{ "startColumnName" : "'.$group['startColumnName'].'", "numberOfColumns" : '.$group['numberOfColumns'].', "titleText" : "'.$group['titleText'].'" },';
  1346. }
  1347. $json .= '$("#'.$div_id.'").jqGrid("setGroupHeaders", {
  1348. "useColSpanStyle" : false,
  1349. "groupHeaders" : [
  1350. ' . $groups.'
  1351. ]
  1352. });';
  1353. }
  1354. $all_text = addslashes(get_lang('All'));
  1355. $json .= '$("'.$obj->pager.' option[value='.$all_value.']").text("'.$all_text.'");';
  1356. $json .= "\n";
  1357. // Adding edit/delete icons.
  1358. $json .= $formatter;
  1359. return $json;
  1360. }
  1361. /**
  1362. * @param array $headers
  1363. * @param array $rows
  1364. * @param array $attributes
  1365. * @return string
  1366. */
  1367. public static function table($headers, $rows, $attributes = array())
  1368. {
  1369. if (empty($attributes)) {
  1370. $attributes['class'] = 'data_table';
  1371. }
  1372. $table = new HTML_Table($attributes);
  1373. $row = 0;
  1374. $column = 0;
  1375. // Course headers
  1376. if (!empty($headers)) {
  1377. foreach ($headers as $item) {
  1378. $table->setHeaderContents($row, $column, $item);
  1379. $column++;
  1380. }
  1381. $row = 1;
  1382. $column = 0;
  1383. }
  1384. if (!empty($rows)) {
  1385. foreach ($rows as $content) {
  1386. $table->setCellContents($row, $column, $content);
  1387. $row++;
  1388. }
  1389. }
  1390. return $table->toHtml();
  1391. }
  1392. /**
  1393. * Returns the "what's new" icon notifications
  1394. *
  1395. * The general logic of this function is to track the last time the user
  1396. * entered the course and compare to what has changed inside this course
  1397. * since then, based on the item_property table inside this course. Note that,
  1398. * if the user never entered the course before, he will not see notification
  1399. * icons. This function takes session ID into account (if any) and only shows
  1400. * the corresponding notifications.
  1401. * @param array $course_info Course information array, containing at least elements 'db' and 'k'
  1402. * @param bool $loadAjax
  1403. * @return string The HTML link to be shown next to the course
  1404. */
  1405. public static function show_notification($course_info, $loadAjax = true)
  1406. {
  1407. if (empty($course_info)) {
  1408. return '';
  1409. }
  1410. $t_track_e_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  1411. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  1412. $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1413. $course_code = Database::escape_string($course_info['code']);
  1414. $user_id = api_get_user_id();
  1415. $course_id = (int) $course_info['real_id'];
  1416. $sessionId = (int) $course_info['id_session'];
  1417. $status = (int) $course_info['status'];
  1418. $loadNotificationsByAjax = api_get_configuration_value('user_portal_load_notification_by_ajax');
  1419. if ($loadNotificationsByAjax) {
  1420. if ($loadAjax) {
  1421. $id = 'notification_'.$course_id.'_'.$sessionId.'_'.$status;
  1422. Session::write($id, true);
  1423. return '<span id ="'.$id.'" class="course_notification"></span>';
  1424. }
  1425. }
  1426. // Get the user's last access dates to all tools of this course
  1427. $sql = "SELECT *
  1428. FROM $t_track_e_access
  1429. WHERE
  1430. c_id = $course_id AND
  1431. access_user_id = '$user_id' AND
  1432. access_session_id ='".$sessionId."'";
  1433. $resLastTrackInCourse = Database::query($sql);
  1434. $oldestTrackDate = $oldestTrackDateOrig = '3000-01-01 00:00:00';
  1435. while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
  1436. $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
  1437. if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
  1438. $oldestTrackDate = $lastTrackInCourse['access_date'];
  1439. }
  1440. }
  1441. if ($oldestTrackDate == $oldestTrackDateOrig) {
  1442. //if there was no connexion to the course ever, then take the
  1443. // course creation date as a reference
  1444. $oldestTrackDate = $course_info['creation_date'];
  1445. }
  1446. $sessionCondition = api_get_session_condition(
  1447. $sessionId,
  1448. true,
  1449. false,
  1450. 'session_id'
  1451. );
  1452. $hideTools = [TOOL_NOTEBOOK, TOOL_CHAT];
  1453. // Get current tools in course
  1454. $sql = "SELECT name, link, image
  1455. FROM $course_tool_table
  1456. WHERE
  1457. c_id = $course_id AND
  1458. visibility = '1' AND
  1459. name NOT IN ('".implode("','", $hideTools)."')
  1460. ";
  1461. $result = Database::query($sql);
  1462. $tools = Database::store_result($result);
  1463. $group_ids = GroupManager::get_group_ids($course_info['real_id'], $user_id);
  1464. $group_ids[] = 0; //add group 'everyone'
  1465. $notifications = array();
  1466. if ($tools) {
  1467. foreach ($tools as $tool) {
  1468. $toolName = $tool['name'];
  1469. // Fix to get student publications
  1470. if ($toolName == 'student_publication') {
  1471. $toolName = 'work';
  1472. }
  1473. $toolName = addslashes(Database::escape_string($toolName));
  1474. $sql = "SELECT * FROM $tool_edit_table
  1475. WHERE
  1476. c_id = $course_id AND
  1477. tool = '$toolName' AND
  1478. lastedit_type NOT LIKE '%Deleted%' AND
  1479. lastedit_type NOT LIKE '%deleted%' AND
  1480. lastedit_type NOT LIKE '%DocumentInvisible%' AND
  1481. lastedit_date > '$oldestTrackDate' AND
  1482. lastedit_user_id != $user_id $sessionCondition AND
  1483. visibility != 2 AND
  1484. (to_user_id IN ('$user_id', '0') OR to_user_id IS NULL) AND
  1485. (to_group_id IN ('".implode("','", $group_ids)."') OR to_group_id IS NULL)
  1486. ORDER BY lastedit_date DESC
  1487. LIMIT 1";
  1488. $result = Database::query($sql);
  1489. $latestChange = Database::fetch_array($result);
  1490. if ($latestChange) {
  1491. $latestChange['link'] = $tool['link'];
  1492. $latestChange['image'] = $tool['image'];
  1493. $latestChange['tool'] = $tool['name'];
  1494. $notifications[$toolName] = $latestChange;
  1495. }
  1496. }
  1497. }
  1498. // Show all tool icons where there is something new.
  1499. $return = '';
  1500. foreach ($notifications as $notification) {
  1501. $toolName = $notification['tool'];
  1502. if (!(
  1503. $notification['visibility'] == '1' ||
  1504. ($status == '1' && $notification['visibility'] == '0') ||
  1505. !isset($notification['visibility'])
  1506. )
  1507. ) {
  1508. continue;
  1509. }
  1510. if ($toolName == TOOL_SURVEY) {
  1511. $survey_info = SurveyManager::get_survey($notification['ref'], 0, $course_code);
  1512. if (!empty($survey_info)) {
  1513. $invited_users = SurveyUtil::get_invited_users(
  1514. $survey_info['code'],
  1515. $course_code
  1516. );
  1517. if (!in_array($user_id, $invited_users['course_users'])) {
  1518. continue;
  1519. }
  1520. }
  1521. }
  1522. if ($notification['tool'] == TOOL_LEARNPATH) {
  1523. if (!learnpath::is_lp_visible_for_student($notification['ref'], $user_id, $course_code)) {
  1524. continue;
  1525. }
  1526. }
  1527. if ($notification['tool'] == TOOL_DROPBOX) {
  1528. $notification['link'] = 'dropbox/dropbox_download.php?id='.$notification['ref'];
  1529. }
  1530. if ($notification['tool'] == 'work' &&
  1531. $notification['lastedit_type'] == 'DirectoryCreated'
  1532. ) {
  1533. $notification['lastedit_type'] = 'WorkAdded';
  1534. }
  1535. $lastDate = api_get_local_time($notification['lastedit_date']);
  1536. $type = $notification['lastedit_type'];
  1537. if ($type == 'CalendareventVisible') {
  1538. $type = 'Visible';
  1539. }
  1540. $label = get_lang('TitleNotification').": ".get_lang($type)." ($lastDate)";
  1541. if (strpos($notification['link'], '?') === false) {
  1542. $notification['link'] = $notification['link'].'?notification=1';
  1543. } else {
  1544. $notification['link'] = $notification['link'].'&notification=1';
  1545. }
  1546. $image = substr($notification['image'], 0, -4).'.png';
  1547. $return .= self::url(
  1548. self::return_icon($image, $label),
  1549. api_get_path(WEB_CODE_PATH).
  1550. $notification['link'].'&cidReq='.$course_code.
  1551. '&ref='.$notification['ref'].
  1552. '&gidReq='.$notification['to_group_id'].
  1553. '&id_session='.$sessionId
  1554. ).PHP_EOL;
  1555. }
  1556. return $return;
  1557. }
  1558. /**
  1559. * Get the session box details as an array
  1560. * @param int Session ID
  1561. * @return array Empty array or session array
  1562. * ['title'=>'...','category'=>'','dates'=>'...','coach'=>'...','active'=>true/false,'session_category_id'=>int]
  1563. */
  1564. public static function get_session_title_box($session_id)
  1565. {
  1566. global $nosession;
  1567. if (!$nosession) {
  1568. global $now, $date_start, $date_end;
  1569. }
  1570. $output = array();
  1571. $active = false;
  1572. if (!$nosession) {
  1573. $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
  1574. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  1575. // Request for the name of the general coach
  1576. $sql = 'SELECT tu.lastname, tu.firstname, ts.*
  1577. FROM '.$tbl_session.' ts
  1578. LEFT JOIN '.$main_user_table.' tu
  1579. ON ts.id_coach = tu.user_id
  1580. WHERE ts.id = '.intval($session_id);
  1581. $rs = Database::query($sql);
  1582. $session_info = Database::store_result($rs, 'ASSOC');
  1583. $session_info = $session_info[0];
  1584. $session = array();
  1585. $session['category_id'] = $session_info['session_category_id'];
  1586. $session['title'] = $session_info['name'];
  1587. $session['id_coach'] = $session_info['id_coach'];
  1588. $session['coach'] = '';
  1589. $session['dates'] = '';
  1590. if (api_get_setting('show_session_coach') === 'true') {
  1591. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info['firstname'], $session_info['lastname']);
  1592. }
  1593. if (
  1594. ($session_info['access_end_date'] == '0000-00-00 00:00:00' && $session_info['access_start_date'] == '0000-00-00 00:00:00') ||
  1595. (empty($session_info['access_end_date']) && empty($session_info['access_start_date']))
  1596. ) {
  1597. if (isset($session_info['duration']) && !empty($session_info['duration'])) {
  1598. $daysLeft = SessionManager::getDayLeftInSession($session_info, api_get_user_id());
  1599. $session['duration'] = $daysLeft >= 0
  1600. ? sprintf(get_lang('SessionDurationXDaysLeft'), $daysLeft)
  1601. : get_lang('YourSessionTimeHasExpired');
  1602. }
  1603. $active = true;
  1604. } else {
  1605. $dates = SessionManager::parseSessionDates($session_info, true);
  1606. $session['dates'] = $dates['access'];
  1607. if (api_get_setting('show_session_coach') === 'true') {
  1608. $session['coach'] = api_get_person_name(
  1609. $session_info['firstname'],
  1610. $session_info['lastname']
  1611. );
  1612. }
  1613. $active = $date_start <= $now && $date_end >= $now;
  1614. }
  1615. $session['active'] = $active;
  1616. $session['session_category_id'] = $session_info['session_category_id'];
  1617. $session['visibility'] = $session_info['visibility'];
  1618. $session['num_users'] = $session_info['nbr_users'];
  1619. $session['num_courses'] = $session_info['nbr_courses'];
  1620. $session['description'] = $session_info['description'];
  1621. $session['show_description'] = $session_info['show_description'];
  1622. $entityManager = Database::getManager();
  1623. $fieldValuesRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraFieldValues');
  1624. $extraFieldValues = $fieldValuesRepo->getVisibleValues(
  1625. ExtraField::SESSION_FIELD_TYPE,
  1626. $session_id
  1627. );
  1628. $session['extra_fields'] = [];
  1629. foreach ($extraFieldValues as $value) {
  1630. $session['extra_fields'][] = [
  1631. 'field' => [
  1632. 'variable' => $value->getField()->getVariable(),
  1633. 'display_text' => $value->getField()->getDisplayText()
  1634. ],
  1635. 'value' => $value->getValue()
  1636. ];
  1637. }
  1638. $output = $session;
  1639. }
  1640. return $output;
  1641. }
  1642. /**
  1643. * Return the five star HTML
  1644. *
  1645. * @param string $id of the rating ul element
  1646. * @param string $url that will be added (for jquery see hot_courses.tpl)
  1647. * @param array $point_info point info array see function CourseManager::get_course_ranking()
  1648. * @param bool $add_div_wrapper add a div wrapper
  1649. * @return string
  1650. **/
  1651. public static function return_rating_system(
  1652. $id,
  1653. $url,
  1654. $point_info = [],
  1655. $add_div_wrapper = true
  1656. ) {
  1657. $number_of_users_who_voted = isset($point_info['users_who_voted']) ? $point_info['users_who_voted'] : null;
  1658. $percentage = isset($point_info['point_average']) ? $point_info['point_average'] : 0;
  1659. if (!empty($percentage)) {
  1660. $percentage = $percentage * 125 / 100;
  1661. }
  1662. $accesses = isset($point_info['accesses']) ? $point_info['accesses'] : 0;
  1663. $star_label = sprintf(get_lang('XStarsOutOf5'), $point_info['point_average_star']);
  1664. $html = '<ul id="'.$id.'" class="star-rating">
  1665. <li class="current-rating" style="width:'.$percentage.'px;"></li>
  1666. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=1" title="'.$star_label.'" class="one-star">1</a></li>
  1667. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=2" title="'.$star_label.'" class="two-stars">2</a></li>
  1668. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=3" title="'.$star_label.'" class="three-stars">3</a></li>
  1669. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=4" title="'.$star_label.'" class="four-stars">4</a></li>
  1670. <li><a href="javascript:void(0);" data-link="'.$url.'&amp;star=5" title="'.$star_label.'" class="five-stars">5</a></li>
  1671. </ul>';
  1672. $labels = array();
  1673. $labels[] = $number_of_users_who_voted == 1 ? $number_of_users_who_voted.' '.get_lang('Vote') : $number_of_users_who_voted.' '.get_lang('Votes');
  1674. $labels[] = $accesses == 1 ? $accesses.' '.get_lang('Visit') : $accesses.' '.get_lang('Visits');
  1675. $labels[] = $point_info['user_vote'] ? get_lang('YourVote').' ['.$point_info['user_vote'].']' : get_lang('YourVote').' [?] ';
  1676. if (!$add_div_wrapper && api_is_anonymous()) {
  1677. $labels[] = self::tag('span', get_lang('LoginToVote'), array('class' => 'error'));
  1678. }
  1679. $html .= self::div(implode(' | ', $labels), array('id' => 'vote_label_'.$id, 'class' => 'vote_label_info'));
  1680. $html .= ' '.self::span(' ', array('id' => 'vote_label2_'.$id));
  1681. if ($add_div_wrapper) {
  1682. $html = self::div($html, array('id' => 'rating_wrapper_'.$id));
  1683. }
  1684. return $html;
  1685. }
  1686. /**
  1687. * @param string $title
  1688. * @param string $second_title
  1689. * @param string $size
  1690. * @param bool $filter
  1691. * @return string
  1692. */
  1693. public static function page_header($title, $second_title = null, $size = 'h2', $filter = true)
  1694. {
  1695. if ($filter) {
  1696. $title = Security::remove_XSS($title);
  1697. }
  1698. if (!empty($second_title)) {
  1699. if ($filter) {
  1700. $second_title = Security::remove_XSS($second_title);
  1701. }
  1702. $title .= "<small> $second_title<small>";
  1703. }
  1704. return '<'.$size.' class="page-header">'.$title.'</'.$size.'>';
  1705. }
  1706. public static function page_header_and_translate($title, $second_title = null)
  1707. {
  1708. $title = get_lang($title);
  1709. return self::page_header($title, $second_title);
  1710. }
  1711. public static function page_subheader_and_translate($title, $second_title = null)
  1712. {
  1713. $title = get_lang($title);
  1714. return self::page_subheader($title, $second_title);
  1715. }
  1716. public static function page_subheader($title, $second_title = null, $size = 'h3')
  1717. {
  1718. if (!empty($second_title)) {
  1719. $second_title = Security::remove_XSS($second_title);
  1720. $title .= "<small> $second_title<small>";
  1721. }
  1722. return '<'.$size.'>'.Security::remove_XSS($title).'</'.$size.'>';
  1723. }
  1724. public static function page_subheader2($title, $second_title = null)
  1725. {
  1726. return self::page_header($title, $second_title, 'h4');
  1727. }
  1728. public static function page_subheader3($title, $second_title = null)
  1729. {
  1730. return self::page_header($title, $second_title, 'h5');
  1731. }
  1732. /**
  1733. * @param array $list
  1734. * @return null|string
  1735. */
  1736. public static function description($list)
  1737. {
  1738. $html = null;
  1739. if (!empty($list)) {
  1740. $html = '<dl class="dl-horizontal">';
  1741. foreach ($list as $item) {
  1742. $html .= '<dt>'.$item['title'].'</dt>';
  1743. $html .= '<dd>'.$item['content'].'</dd>';
  1744. }
  1745. $html .= '</dl>';
  1746. }
  1747. return $html;
  1748. }
  1749. /**
  1750. * @param $percentage
  1751. * @param bool $show_percentage
  1752. * @param null $extra_info
  1753. * @return string
  1754. */
  1755. public static function bar_progress($percentage, $show_percentage = true, $extra_info = null)
  1756. {
  1757. $percentage = intval($percentage);
  1758. $div = '<div class="progress">
  1759. <div
  1760. class="progress-bar progress-bar-striped"
  1761. role="progressbar"
  1762. aria-valuenow="'.$percentage.'"
  1763. aria-valuemin="0"
  1764. aria-valuemax="100"
  1765. style="width: '.$percentage.'%;"
  1766. >';
  1767. if ($show_percentage) {
  1768. $div .= $percentage.'%';
  1769. } else {
  1770. if (!empty($extra_info)) {
  1771. $div .= $extra_info;
  1772. }
  1773. }
  1774. $div .= '</div>';
  1775. return $div;
  1776. }
  1777. /**
  1778. * @param string $count
  1779. * @param string $type
  1780. * @return null|string
  1781. */
  1782. public static function badge($count, $type = "warning")
  1783. {
  1784. $class = '';
  1785. switch ($type) {
  1786. case 'success':
  1787. $class = 'badge-success';
  1788. break;
  1789. case 'warning':
  1790. $class = 'badge-warning';
  1791. break;
  1792. case 'important':
  1793. $class = 'badge-important';
  1794. break;
  1795. case 'info':
  1796. $class = 'badge-info';
  1797. break;
  1798. case 'inverse':
  1799. $class = 'badge-inverse';
  1800. break;
  1801. }
  1802. if (!empty($count)) {
  1803. return ' <span class="badge '.$class.'">'.$count.'</span>';
  1804. }
  1805. return null;
  1806. }
  1807. /**
  1808. * @param array $badge_list
  1809. * @return string
  1810. */
  1811. public static function badge_group($badge_list)
  1812. {
  1813. $html = '<div class="badge-group">';
  1814. foreach ($badge_list as $badge) {
  1815. $html .= $badge;
  1816. }
  1817. $html .= '</div>';
  1818. return $html;
  1819. }
  1820. /**
  1821. * @param string $content
  1822. * @param string $type
  1823. * @return string
  1824. */
  1825. public static function label($content, $type = 'default')
  1826. {
  1827. switch ($type) {
  1828. case 'success':
  1829. $class = 'label-success';
  1830. break;
  1831. case 'warning':
  1832. $class = 'label-warning';
  1833. break;
  1834. case 'important':
  1835. //no break
  1836. case 'danger':
  1837. $class = 'label-danger';
  1838. break;
  1839. case 'info':
  1840. $class = 'label-info';
  1841. break;
  1842. case 'primary':
  1843. $class = 'label-primary';
  1844. break;
  1845. default:
  1846. $class = 'label-default';
  1847. break;
  1848. }
  1849. $html = '';
  1850. if (!empty($content)) {
  1851. $html = '<span class="label '.$class.'">';
  1852. $html .= $content;
  1853. $html .= '</span>';
  1854. }
  1855. return $html;
  1856. }
  1857. /**
  1858. * @param array $items
  1859. * @return null|string
  1860. */
  1861. public static function actions($items, $class = 'new_actions')
  1862. {
  1863. $html = null;
  1864. if (!empty($items)) {
  1865. $html = '<div class="'.$class.'"><ul class="nav nav-pills">';
  1866. foreach ($items as $value) {
  1867. $class = null;
  1868. if (isset($value['active']) && $value['active']) {
  1869. $class = 'class ="active"';
  1870. }
  1871. if (basename($_SERVER['REQUEST_URI']) == basename($value['url'])) {
  1872. $class = 'class ="active"';
  1873. }
  1874. $html .= "<li $class >";
  1875. $attributes = isset($value['url_attributes']) ? $value['url_attributes'] : array();
  1876. $html .= self::url($value['content'], $value['url'], $attributes);
  1877. $html .= '</li>';
  1878. }
  1879. $html .= '</ul></div>';
  1880. $html .= '<br />';
  1881. }
  1882. return $html;
  1883. }
  1884. /**
  1885. * Prints a tooltip
  1886. * @param string $text
  1887. * @param string $tip
  1888. *
  1889. * @return string
  1890. */
  1891. public static function tip($text, $tip)
  1892. {
  1893. if (empty($tip)) {
  1894. return $text;
  1895. }
  1896. return self::span(
  1897. $text,
  1898. array('class' => 'boot-tooltip', 'title' => strip_tags($tip))
  1899. );
  1900. }
  1901. /**
  1902. * @param array $items
  1903. * @param string $type
  1904. * @param null $id
  1905. * @return null|string
  1906. */
  1907. public static function generate_accordion($items, $type = 'jquery', $id = null)
  1908. {
  1909. $html = null;
  1910. if (!empty($items)) {
  1911. if (empty($id)) {
  1912. $id = api_get_unique_id();
  1913. }
  1914. if ($type == 'jquery') {
  1915. $html = '<div class="accordion_jquery" id="'.$id.'">'; //using jquery
  1916. } else {
  1917. $html = '<div class="accordion" id="'.$id.'">'; //using bootstrap
  1918. }
  1919. $count = 1;
  1920. foreach ($items as $item) {
  1921. $html .= '<div class="accordion-my-group">';
  1922. $html .= '<div class="accordion-heading">
  1923. <a class="accordion-toggle" data-toggle="collapse" data-parent="#'.$id.'" href="#collapse'.$count.'">
  1924. '.$item['title'].'
  1925. </a>
  1926. </div>';
  1927. $html .= '<div id="collapse'.$count.'" class="accordion-body">';
  1928. $html .= '<div class="accordion-my-inner">
  1929. '.$item['content'].'
  1930. </div>
  1931. </div>';
  1932. }
  1933. $html .= '</div>';
  1934. }
  1935. return $html;
  1936. }
  1937. /**
  1938. * @param array $buttons
  1939. * @return string
  1940. */
  1941. public static function groupButton($buttons)
  1942. {
  1943. $html = '<div class="btn-group" role="group">';
  1944. foreach ($buttons as $button) {
  1945. $html .= $button;
  1946. }
  1947. $html .= '</div>';
  1948. return $html;
  1949. }
  1950. /**
  1951. * @todo use twig
  1952. * @param string $title
  1953. * @param array $elements
  1954. * @param bool $alignToRight
  1955. * @return string
  1956. */
  1957. public static function groupButtonWithDropDown($title, $elements, $alignToRight = false)
  1958. {
  1959. $html = '<div class="btn-group">
  1960. <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
  1961. '.$title.'
  1962. <span class="caret"></span></button>
  1963. <ul class="dropdown-menu ' . ($alignToRight ? 'dropdown-menu-right' : '').'">';
  1964. foreach ($elements as $item) {
  1965. $html .= self::tag('li', self::url($item['title'], $item['href']));
  1966. }
  1967. $html .= '</ul>
  1968. </div>';
  1969. return $html;
  1970. }
  1971. /**
  1972. * @param string $file
  1973. * @param array $params
  1974. * @return null|string
  1975. */
  1976. public static function getMediaPlayer($file, $params = array())
  1977. {
  1978. $fileInfo = pathinfo($file);
  1979. switch ($fileInfo['extension']) {
  1980. case 'mp3':
  1981. case 'webm':
  1982. $autoplay = null;
  1983. if (isset($params['autoplay']) && $params['autoplay'] == 'true') {
  1984. $autoplay = 'autoplay';
  1985. }
  1986. $width = isset($params['width']) ? 'width="'.$params['width'].'"' : null;
  1987. $id = isset($params['id']) ? $params['id'] : $fileInfo['basename'];
  1988. $class = isset($params['class']) ? ' class="'.$params['class'].'"' : null;
  1989. $html = '<audio id="'.$id.'" '.$class.' controls '.$autoplay.' '.$width.' src="'.$params['url'].'" >';
  1990. $html .= '<object width="'.$width.'" height="50" type="application/x-shockwave-flash" data="'.api_get_path(WEB_LIBRARY_PATH).'javascript/mediaelement/flashmediaelement.swf">
  1991. <param name="movie" value="'.api_get_path(WEB_LIBRARY_PATH).'javascript/mediaelement/flashmediaelement.swf" />
  1992. <param name="flashvars" value="controls=true&file='.$params['url'].'" />
  1993. </object>';
  1994. $html .= '</audio>';
  1995. return $html;
  1996. break;
  1997. case 'wav':
  1998. //no break;
  1999. case 'ogg':
  2000. $html = '<audio width="300px" controls src="'.$params['url'].'" >';
  2001. return $html;
  2002. break;
  2003. }
  2004. return null;
  2005. }
  2006. /**
  2007. * @param int $nextValue
  2008. * @param array $list
  2009. * @param int $current
  2010. * @param int $fixedValue
  2011. * @param array $conditions
  2012. * @param string $link
  2013. * @param bool $isMedia
  2014. * @param bool $addHeaders
  2015. * @param array $linkAttributes
  2016. * @return string
  2017. */
  2018. public static function progressPaginationBar(
  2019. $nextValue,
  2020. $list,
  2021. $current,
  2022. $fixedValue = null,
  2023. $conditions = [],
  2024. $link = null,
  2025. $isMedia = false,
  2026. $addHeaders = true,
  2027. $linkAttributes = []
  2028. ) {
  2029. if ($addHeaders) {
  2030. $pagination_size = 'pagination-mini';
  2031. $html = '<div class="exercise_pagination pagination '.$pagination_size.'"><ul>';
  2032. } else {
  2033. $html = null;
  2034. }
  2035. $affectAllItems = false;
  2036. if ($isMedia && isset($fixedValue) && ($nextValue + 1 == $current)) {
  2037. $affectAllItems = true;
  2038. }
  2039. $localCounter = 0;
  2040. foreach ($list as $itemId) {
  2041. $isCurrent = false;
  2042. if ($affectAllItems) {
  2043. $isCurrent = true;
  2044. } else {
  2045. if (!$isMedia) {
  2046. $isCurrent = $current == ($localCounter + $nextValue + 1) ? true : false;
  2047. }
  2048. }
  2049. $html .= self::parsePaginationItem(
  2050. $itemId,
  2051. $isCurrent,
  2052. $conditions,
  2053. $link,
  2054. $nextValue,
  2055. $isMedia,
  2056. $localCounter,
  2057. $fixedValue,
  2058. $linkAttributes
  2059. );
  2060. $localCounter++;
  2061. }
  2062. if ($addHeaders) {
  2063. $html .= '</ul></div>';
  2064. }
  2065. return $html;
  2066. }
  2067. /**
  2068. *
  2069. * @param int $itemId
  2070. * @param bool $isCurrent
  2071. * @param array $conditions
  2072. * @param string $link
  2073. * @param int $nextValue
  2074. * @param bool $isMedia
  2075. * @param int $localCounter
  2076. * @param int $fixedValue
  2077. * @param array $linkAttributes
  2078. *
  2079. * @return string
  2080. */
  2081. public static function parsePaginationItem(
  2082. $itemId,
  2083. $isCurrent,
  2084. $conditions,
  2085. $link,
  2086. $nextValue = 0,
  2087. $isMedia = false,
  2088. $localCounter = null,
  2089. $fixedValue = null,
  2090. $linkAttributes = []
  2091. ) {
  2092. $defaultClass = 'before';
  2093. $class = $defaultClass;
  2094. foreach ($conditions as $condition) {
  2095. $array = isset($condition['items']) ? $condition['items'] : array();
  2096. $class_to_applied = $condition['class'];
  2097. $type = isset($condition['type']) ? $condition['type'] : 'positive';
  2098. $mode = isset($condition['mode']) ? $condition['mode'] : 'add';
  2099. switch ($type) {
  2100. case 'positive':
  2101. if (in_array($itemId, $array)) {
  2102. if ($mode == 'overwrite') {
  2103. $class = " $defaultClass $class_to_applied";
  2104. } else {
  2105. $class .= " $class_to_applied";
  2106. }
  2107. }
  2108. break;
  2109. case 'negative':
  2110. if (!in_array($itemId, $array)) {
  2111. if ($mode == 'overwrite') {
  2112. $class = " $defaultClass $class_to_applied";
  2113. } else {
  2114. $class .= " $class_to_applied";
  2115. }
  2116. }
  2117. break;
  2118. }
  2119. }
  2120. if ($isCurrent) {
  2121. $class = 'before current';
  2122. }
  2123. if ($isMedia && $isCurrent) {
  2124. $class = 'before current';
  2125. }
  2126. if (empty($link)) {
  2127. $link_to_show = '#';
  2128. } else {
  2129. $link_to_show = $link.($nextValue + $localCounter);
  2130. }
  2131. $label = $nextValue + $localCounter + 1;
  2132. if ($isMedia) {
  2133. $label = ($fixedValue + 1).' '.chr(97 + $localCounter);
  2134. $link_to_show = $link.$fixedValue.'#questionanchor'.$itemId;
  2135. }
  2136. $link = self::url($label.' ', $link_to_show, $linkAttributes);
  2137. return '<li class = "'.$class.'">'.$link.'</li>';
  2138. }
  2139. /**
  2140. * @param int $current
  2141. * @param int $total
  2142. * @return string
  2143. */
  2144. public static function paginationIndicator($current, $total)
  2145. {
  2146. $html = null;
  2147. if (!empty($current) && !empty($total)) {
  2148. $label = sprintf(get_lang('PaginationXofY'), $current, $total);
  2149. $html = self::url($label, '#', array('class' => 'btn disabled'));
  2150. }
  2151. return $html;
  2152. }
  2153. /**
  2154. * Adds a message in the queue
  2155. * @param string $message
  2156. */
  2157. public static function addFlash($message, $type = 'no_layout')
  2158. {
  2159. Container::getSession()->getFlashBag()->add($type, $message);
  2160. }
  2161. /**
  2162. * @deprecated
  2163. * @return string
  2164. */
  2165. public static function getFlashToString()
  2166. {
  2167. $messages = Session::read('flash_messages');
  2168. $messageToString = '';
  2169. if (!empty($messages)) {
  2170. foreach ($messages as $message) {
  2171. $messageToString .= $message;
  2172. }
  2173. }
  2174. return $messageToString;
  2175. }
  2176. /**
  2177. * @deprecated
  2178. * Shows the message from the session
  2179. */
  2180. public static function showFlash()
  2181. {
  2182. echo self::getFlashToString();
  2183. }
  2184. /**
  2185. * Destroys the message session
  2186. * @deprecated
  2187. */
  2188. public static function cleanFlashMessages()
  2189. {
  2190. Session::erase('flash_messages');
  2191. }
  2192. /**
  2193. * Get the profile edition link for a user
  2194. * @param int $userId The user id
  2195. * @param boolean $asAdmin Optional. Whether get the URL for the platform admin
  2196. * @return string The link
  2197. */
  2198. public static function getProfileEditionLink($userId, $asAdmin = false)
  2199. {
  2200. $editProfileUrl = api_get_path(WEB_CODE_PATH).'auth/profile.php';
  2201. if ($asAdmin) {
  2202. $editProfileUrl = api_get_path(WEB_CODE_PATH)."admin/user_edit.php?user_id=".intval($userId);
  2203. }
  2204. if (api_get_setting('sso_authentication') === 'true') {
  2205. $subSSOClass = api_get_setting('sso_authentication_subclass');
  2206. $objSSO = null;
  2207. if (!empty($subSSOClass)) {
  2208. $file = api_get_path(SYS_CODE_PATH)."auth/sso/sso.$subSSOClass.class.php";
  2209. if (file_exists($file)) {
  2210. require_once $file;
  2211. $subSSOClass = 'sso'.$subSSOClass;
  2212. $objSSO = new $subSSOClass();
  2213. } else {
  2214. throw new Exception("$subSSOClass file not set");
  2215. }
  2216. } else {
  2217. $objSSO = new sso();
  2218. }
  2219. $editProfileUrl = $objSSO->generateProfileEditingURL(
  2220. $userId,
  2221. $asAdmin
  2222. );
  2223. }
  2224. return $editProfileUrl;
  2225. }
  2226. /**
  2227. * Get the vCard for a user
  2228. * @param int $userId The user id
  2229. * @return string *.*vcf file
  2230. */
  2231. public static function getVCardUserLink($userId)
  2232. {
  2233. $vCardUrl = api_get_path(WEB_PATH).'main/social/vcard_export.php?userId='.intval($userId);
  2234. return $vCardUrl;
  2235. }
  2236. /**
  2237. * @param string $content
  2238. * @param string $title
  2239. * @param string $footer
  2240. * @param string $type primary|success|info|warning|danger
  2241. * @param string $extra
  2242. * @param string $id
  2243. * @param string $customColor
  2244. *
  2245. * @return string
  2246. */
  2247. public static function panel(
  2248. $content,
  2249. $title = '',
  2250. $footer = '',
  2251. $type = 'default',
  2252. $extra = '',
  2253. $id = '',
  2254. $customColor = ''
  2255. ) {
  2256. $headerStyle = '';
  2257. if (!empty($customColor)) {
  2258. $headerStyle = 'style = "color: white; background-color: '.$customColor.'" ';
  2259. }
  2260. $title = !empty($title) ? '<div class="panel-heading" '.$headerStyle.' ><h3 class="panel-title">'.$title.'</h3>'.$extra.'</div>' : '';
  2261. $footer = !empty($footer) ? '<div class="panel-footer">'.$footer.'</div>' : '';
  2262. $typeList = ['primary', 'success', 'info', 'warning', 'danger'];
  2263. $style = !in_array($type, $typeList) ? 'default' : $type;
  2264. if (!empty($id)) {
  2265. $id = " id = $id ";
  2266. }
  2267. return '
  2268. <div '.$id.' class="panel panel-'.$style.'">
  2269. '.$title.'
  2270. '.self::contentPanel($content).'
  2271. '.$footer.'
  2272. </div>'
  2273. ;
  2274. }
  2275. /**
  2276. * @param string $content
  2277. * @return string
  2278. */
  2279. public static function contentPanel($content)
  2280. {
  2281. if (empty($content)) {
  2282. return '';
  2283. }
  2284. return '<div class="panel-body">'.$content.'</div>';
  2285. }
  2286. /**
  2287. * Get the button HTML with an Awesome Font icon
  2288. * @param string $text The button content
  2289. * @param string $url The url to button
  2290. * @param string $icon The Awesome Font class for icon
  2291. * @param string $type Optional. The button Bootstrap class. Default 'default' class
  2292. * @param array $attributes The additional attributes
  2293. * @param bool $includeText
  2294. *
  2295. * @return string The button HTML
  2296. */
  2297. public static function toolbarButton(
  2298. $text,
  2299. $url,
  2300. $icon = 'check',
  2301. $type = 'default',
  2302. array $attributes = [],
  2303. $includeText = true
  2304. ) {
  2305. $buttonClass = "btn btn-$type";
  2306. $icon = self::tag('i', null, ['class' => "fa fa-$icon fa-fw", 'aria-hidden' => 'true']);
  2307. $attributes['class'] = isset($attributes['class']) ? "$buttonClass {$attributes['class']}" : $buttonClass;
  2308. $attributes['title'] = isset($attributes['title']) ? $attributes['title'] : $text;
  2309. if (!$includeText) {
  2310. $text = '<span class="sr-only">'.$text.'</span>';
  2311. }
  2312. return self::url("$icon $text", $url, $attributes);
  2313. }
  2314. /**
  2315. * @param string $id
  2316. * @param array $content
  2317. * @param array $colsWidth Optional. Columns width
  2318. * @return string
  2319. */
  2320. public static function toolbarAction($id, $content, $colsWidth = [])
  2321. {
  2322. $col = count($content);
  2323. if (!$colsWidth) {
  2324. $width = 12 / $col;
  2325. array_walk($content, function() use ($width, &$colsWidth) {
  2326. $colsWidth[] = $width;
  2327. });
  2328. }
  2329. $html = '<div id="'.$id.'" class="actions">';
  2330. $html .= '<div class="row">';
  2331. for ($i = 0; $i < $col; $i++) {
  2332. $class = 'col-sm-'.$colsWidth[$i];
  2333. if ($col > 1) {
  2334. if ($i > 0 && $i < count($content) - 1) {
  2335. $class .= ' text-center';
  2336. } elseif ($i === count($content) - 1) {
  2337. $class .= ' text-right';
  2338. }
  2339. }
  2340. $html .= '<div class="'.$class.'">'.$content[$i].'</div>';
  2341. }
  2342. $html .= '</div>';
  2343. $html .= '</div>';
  2344. return $html;
  2345. }
  2346. /**
  2347. * Get a HTML code for a icon by Font Awesome
  2348. * @param string $name The icon name
  2349. * @param int|string $size Optional. The size for the icon. (Example: lg, 2, 3, 4, 5)
  2350. * @param boolean $fixWidth Optional. Whether add the fw class
  2351. * @param string $additionalClass Optional. Additional class
  2352. *
  2353. * @return string
  2354. */
  2355. public static function returnFontAwesomeIcon(
  2356. $name,
  2357. $size = '',
  2358. $fixWidth = false,
  2359. $additionalClass = ''
  2360. ) {
  2361. $className = "fa fa-$name";
  2362. if ($fixWidth) {
  2363. $className .= ' fa-fw';
  2364. }
  2365. switch ($size) {
  2366. case 'lg':
  2367. $className .= ' fa-lg';
  2368. break;
  2369. case 2:
  2370. //no break
  2371. case 3:
  2372. //no break
  2373. case 4:
  2374. //no break
  2375. case 5:
  2376. $className .= " fa-{$size}x";
  2377. break;
  2378. }
  2379. if (!empty($additionalClass)) {
  2380. $className .= " $additionalClass";
  2381. }
  2382. $icon = self::tag('em', null, ['class' => $className]);
  2383. return "$icon ";
  2384. }
  2385. /**
  2386. * @param string $title
  2387. * @param string $content
  2388. * @param null $id
  2389. * @param array $params
  2390. * @param null $idAccordion
  2391. * @param null $idCollapse
  2392. * @param bool|true $open
  2393. * @param bool|false $fullClickable
  2394. * @return null|string
  2395. * @todo rework function to easy use
  2396. */
  2397. public static function panelCollapse(
  2398. $title,
  2399. $content,
  2400. $id = null,
  2401. $params = array(),
  2402. $idAccordion = null,
  2403. $idCollapse = null,
  2404. $open = true,
  2405. $fullClickable = false
  2406. ) {
  2407. if (!empty($idAccordion)) {
  2408. $headerClass = '';
  2409. $headerClass .= $fullClickable ? 'center-block ' : '';
  2410. $headerClass .= $open ? '' : 'collapsed';
  2411. $contentClass = 'panel-collapse collapse ';
  2412. $contentClass .= $open ? 'in' : '';
  2413. $ariaExpanded = $open ? 'true' : 'false';
  2414. $html = <<<HTML
  2415. <div class="panel-group" id="$idAccordion" role="tablist" aria-multiselectable="true">
  2416. <div class="panel panel-default" id="$id">
  2417. <div class="panel-heading" role="tab">
  2418. <h4 class="panel-title">
  2419. <a class="$headerClass" role="button" data-toggle="collapse" data-parent="#$idAccordion" href="#$idCollapse" aria-expanded="$ariaExpanded" aria-controls="$idCollapse">$title</a>
  2420. </h4>
  2421. </div>
  2422. <div id="$idCollapse" class="$contentClass" role="tabpanel">
  2423. <div class="panel-body">$content</div>
  2424. </div>
  2425. </div>
  2426. </div>
  2427. HTML;
  2428. } else {
  2429. if (!empty($id)) {
  2430. $params['id'] = $id;
  2431. }
  2432. $params['class'] = 'panel panel-default';
  2433. $html = null;
  2434. if (!empty($title)) {
  2435. $html .= '<div class="panel-heading">'.$title.'</div>'.PHP_EOL;
  2436. }
  2437. $html .= '<div class="panel-body">'.$content.'</div>'.PHP_EOL;
  2438. $html = self::div($html, $params);
  2439. }
  2440. return $html;
  2441. }
  2442. /**
  2443. * Returns the string "1 day ago" with a link showing the exact date time.
  2444. * @param string $dateTime in UTC or a DateTime in UTC
  2445. *
  2446. * @return string
  2447. */
  2448. public static function dateToStringAgoAndLongDate($dateTime)
  2449. {
  2450. if (empty($dateTime) || $dateTime === '0000-00-00 00:00:00') {
  2451. return '';
  2452. }
  2453. if ($dateTime instanceof \DateTime) {
  2454. $dateTime = $dateTime->format('Y-m-d H:i:s');
  2455. }
  2456. return self::tip(
  2457. date_to_str_ago($dateTime),
  2458. api_convert_and_format_date($dateTime, DATE_TIME_FORMAT_LONG)
  2459. //api_get_local_time($dateTime)
  2460. );
  2461. }
  2462. /**
  2463. * @param array $userInfo
  2464. * @param string $status
  2465. * @param string $toolbar
  2466. *
  2467. * @return string
  2468. */
  2469. public static function getUserCard($userInfo, $status = '', $toolbar = '')
  2470. {
  2471. if (empty($userInfo)) {
  2472. return '';
  2473. }
  2474. if (!empty($status)) {
  2475. $status = '<div class="items-user-status">'.$status.'</div>';
  2476. }
  2477. if (!empty($toolbar)) {
  2478. $toolbar = '<div class="btn-group pull-right">'.$toolbar.'</div>';
  2479. }
  2480. return '<div id="user_card_'.$userInfo['id'].'" class="col-md-12">
  2481. <div class="row">
  2482. <div class="col-md-2">
  2483. <img src="'.$userInfo['avatar'].'" class="img-responsive img-circle">
  2484. </div>
  2485. <div class="col-md-10">
  2486. <p>'.$userInfo['complete_name'].'</p>
  2487. <div class="row">
  2488. <div class="col-md-2">
  2489. '.$status.'
  2490. </div>
  2491. <div class="col-md-10">
  2492. '.$toolbar.'
  2493. </div>
  2494. </div>
  2495. </div>
  2496. </div>
  2497. <hr />
  2498. </div>';
  2499. }
  2500. }