introductionSection.inc.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * The INTRODUCTION MICRO MODULE is used to insert and edit
  5. * an introduction section on a Chamilo module or on the course homepage.
  6. * It can be inserted on any Chamilo module, provided the corresponding setting
  7. * is enabled in the administration section.
  8. *
  9. * The introduction content are stored in a table called "tool_intro"
  10. * in the course Database. Each module introduction has an Id stored in
  11. * the table, which matches a specific module.
  12. *
  13. * '(c_)tool_intro' table description
  14. * c_id: int
  15. * id : int
  16. * intro_text :text
  17. * session_id: int
  18. *
  19. * usage :
  20. *
  21. * $moduleId = 'XX'; // specifying the module tool (string value)
  22. * include(introductionSection.inc.php);
  23. *
  24. * This script is also used since Chamilo 1.9 to show course progress (from the
  25. * course_progress module)
  26. *
  27. * @package chamilo.include
  28. */
  29. use Chamilo\CourseBundle\Entity\CToolIntro;
  30. $TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
  31. $intro_editAllowed = $is_allowed_to_edit;
  32. $session_id = api_get_session_id();
  33. $introduction_section = '';
  34. global $charset;
  35. $intro_cmdEdit = empty($_GET['intro_cmdEdit']) ? '' : $_GET['intro_cmdEdit'];
  36. $intro_cmdUpdate = isset($_POST['intro_cmdUpdate']);
  37. $intro_cmdDel = empty($_GET['intro_cmdDel']) ? '' : $_GET['intro_cmdDel'];
  38. $intro_cmdAdd = empty($_GET['intro_cmdAdd']) ? '' : $_GET['intro_cmdAdd'];
  39. $courseId = api_get_course_id();
  40. if (!empty($courseId)) {
  41. $form = new FormValidator('introduction_text', 'post', api_get_self().'?'.api_get_cidreq());
  42. } else {
  43. $form = new FormValidator('introduction_text');
  44. }
  45. $renderer =& $form->defaultRenderer();
  46. $renderer->setCustomElementTemplate('<div style="width: 80%; margin: 0px auto; padding-bottom: 10px; ">{element}</div>');
  47. $config = array(
  48. 'ToolbarSet' => 'IntroductionTool',
  49. 'Width' => '100%',
  50. 'Height' => '300'
  51. );
  52. $form->addHtmlEditor('intro_content', null, null, false, $config);
  53. $form->addButtonSave(get_lang('SaveIntroText'), 'intro_cmdUpdate');
  54. /* INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED) */
  55. $course_id = api_get_course_int_id();
  56. if ($intro_editAllowed) {
  57. /* Replace command */
  58. if ($intro_cmdUpdate) {
  59. if ($form->validate()) {
  60. $form_values = $form->exportValues();
  61. $intro_content = Security::remove_XSS(
  62. stripslashes(
  63. api_html_entity_decode($form_values['intro_content'])
  64. ),
  65. COURSEMANAGERLOWSECURITY
  66. );
  67. $criteria = [
  68. 'cId' => $course_id,
  69. 'id' => $moduleId,
  70. 'sessionId' => $session_id,
  71. ];
  72. if (!empty($intro_content)) {
  73. /** @var CToolIntro $toolIntro */
  74. $toolIntro = Database::getManager()
  75. ->getRepository('ChamiloCourseBundle:CToolIntro')
  76. ->findOneBy($criteria);
  77. if ($toolIntro) {
  78. $toolIntro
  79. ->setIntroText($intro_content);
  80. } else {
  81. $toolIntro = new CToolIntro();
  82. $toolIntro
  83. ->setSessionId($session_id)
  84. ->setCId($course_id)
  85. ->setIntroText($intro_content)
  86. ->setId($moduleId);
  87. }
  88. Database::getManager()->persist($toolIntro);
  89. Database::getManager()->flush();
  90. $introduction_section .= Display::return_message(
  91. get_lang('IntroductionTextUpdated'),
  92. 'confirmation',
  93. false
  94. );
  95. } else {
  96. // got to the delete command
  97. $intro_cmdDel = true;
  98. }
  99. } else {
  100. $intro_cmdEdit = true;
  101. }
  102. }
  103. /* Delete Command */
  104. if ($intro_cmdDel) {
  105. $sql = "DELETE FROM $TBL_INTRODUCTION
  106. WHERE
  107. c_id = $course_id AND
  108. id='".Database::escape_string($moduleId)."' AND
  109. session_id='".intval($session_id)."'";
  110. Database::query($sql);
  111. $introduction_section .= Display::return_message(get_lang('IntroductionTextDeleted'), 'confirmation');
  112. }
  113. }
  114. /* INTRODUCTION MICRO MODULE - DISPLAY SECTION */
  115. /* Retrieves the module introduction text, if exist */
  116. /* @todo use a lib to query the $TBL_INTRODUCTION table */
  117. // Getting course intro
  118. $intro_content = null;
  119. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION
  120. WHERE
  121. c_id = $course_id AND
  122. id = '".Database::escape_string($moduleId)."' AND
  123. session_id = 0";
  124. $intro_dbQuery = Database::query($sql);
  125. if (Database::num_rows($intro_dbQuery) > 0) {
  126. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  127. $intro_content = $intro_dbResult['intro_text'];
  128. }
  129. // Getting session intro
  130. if (!empty($session_id)) {
  131. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION
  132. WHERE
  133. c_id = $course_id AND
  134. id = '".Database::escape_string($moduleId)."' AND
  135. session_id = '".intval($session_id)."'";
  136. $intro_dbQuery = Database::query($sql);
  137. $introSessionContent = null;
  138. if (Database::num_rows($intro_dbQuery) > 0) {
  139. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  140. $introSessionContent = $intro_dbResult['intro_text'];
  141. }
  142. // If the course session intro exists replace it.
  143. if (!empty($introSessionContent)) {
  144. $intro_content = $introSessionContent;
  145. }
  146. }
  147. /* Determines the correct display */
  148. if ($intro_cmdEdit || $intro_cmdAdd) {
  149. $intro_dispDefault = false;
  150. $intro_dispForm = true;
  151. $intro_dispCommand = false;
  152. } else {
  153. $intro_dispDefault = true;
  154. $intro_dispForm = false;
  155. if ($intro_editAllowed) {
  156. $intro_dispCommand = true;
  157. } else {
  158. $intro_dispCommand = false;
  159. }
  160. }
  161. /* Executes the display */
  162. // display thematic advance inside a postit
  163. if ($intro_dispForm) {
  164. $default['intro_content'] = $intro_content;
  165. $form->setDefaults($default);
  166. $introduction_section .= '<div id="courseintro" style="width: 98%">';
  167. $introduction_section .= $form->return_form();
  168. $introduction_section .= '</div>';
  169. }
  170. $thematic_description_html = '';
  171. if ($tool == TOOL_COURSE_HOMEPAGE && !isset($_GET['intro_cmdEdit'])) {
  172. // Only show this if we're on the course homepage and we're not currently editing
  173. $thematic = new Thematic();
  174. $displayMode = api_get_course_setting('display_info_advance_inside_homecourse');
  175. $class1 = '';
  176. if ($displayMode == '1') {
  177. // Show only the current course progress step
  178. // $information_title = get_lang('InfoAboutLastDoneAdvance');
  179. $last_done_advance = $thematic->get_last_done_thematic_advance();
  180. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  181. $subTitle1 = get_lang('CurrentTopic');
  182. $class1 = ' current';
  183. } else if($displayMode == '2') {
  184. // Show only the two next course progress steps
  185. // $information_title = get_lang('InfoAboutNextAdvanceNotDone');
  186. $last_done_advance = $thematic->get_next_thematic_advance_not_done();
  187. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done(2);
  188. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  189. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  190. $subTitle1 = $subTitle2 = get_lang('NextTopic');
  191. } else if($displayMode == '3') {
  192. // Show the current and next course progress steps
  193. // $information_title = get_lang('InfoAboutLastDoneAdvanceAndNextAdvanceNotDone');
  194. $last_done_advance = $thematic->get_last_done_thematic_advance();
  195. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  196. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  197. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  198. $subTitle1 = get_lang('CurrentTopic');
  199. $subTitle2 = get_lang('NextTopic');
  200. $class1 = ' current';
  201. }
  202. if (!empty($thematic_advance_info)) {
  203. $thematic_advance = get_lang('CourseThematicAdvance');
  204. $thematicScore = $thematic->get_total_average_of_thematic_advances() . '%';
  205. $thematicUrl = api_get_path(WEB_CODE_PATH) .
  206. 'course_progress/index.php?action=thematic_details&'.api_get_cidreq();
  207. $thematic_info = $thematic->get_thematic_list(
  208. $thematic_advance_info['thematic_id']
  209. );
  210. $thematic_advance_info['start_date'] = api_get_local_time(
  211. $thematic_advance_info['start_date']
  212. );
  213. $thematic_advance_info['start_date'] = api_format_date(
  214. $thematic_advance_info['start_date'],
  215. DATE_TIME_FORMAT_LONG
  216. );
  217. $userInfo = $_SESSION['_user'];
  218. $courseInfo = api_get_course_info();
  219. $thematic_description_html = '
  220. <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
  221. <div id="panel-thematic" class="panel panel-default">
  222. <div class="panel-heading">
  223. <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
  224. <h4>
  225. '. $thematic_advance .' : '. $courseInfo['name'] . ' <b>( '. $thematicScore .' )</b>
  226. </h4>
  227. </a>
  228. </div>
  229. <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
  230. <div class="panel-body">
  231. <div class="row">
  232. <div class="col-md-3">
  233. <div class="thumbnail">
  234. <img src="' . $userInfo['avatar'] . '" class="img-responsive">
  235. </div>
  236. <div class="progress">
  237. <div class="progress-bar progress-bar-success progress-bar-striped" role="progressbar" style="width: ' . $thematicScore . ';">
  238. '.$thematicScore.'
  239. </div>
  240. </div>
  241. <div class="separate">
  242. <a href="' . $thematicUrl . '" class="btn btn-block btn-info">' . get_lang('ShowFullCourseAdvance') . '</a>
  243. </div>
  244. </div>';
  245. $thematic_description_html .= '<div class="col-md-9">';
  246. $thematic_description_html .= '<div class="row">';
  247. $thematic_description_html .= '<div class="col-md-6 items-progress'.$class1.'">
  248. <div class="topics">' . $subTitle1 . '</div>
  249. <h4 class="title-topics">' . $thematic_info['title'] . '</h4>
  250. <p class="date">' . $thematic_advance_info['start_date'] . '</p>
  251. <div class="views">' . $thematic_advance_info['content'] . '</div>
  252. <p class="time">' . get_lang('DurationInHours') . ' : ' . $thematic_advance_info['duration'] . ' - <a href="' . $thematicUrl . '">' . get_lang('SeeDetail') . '</a></p>
  253. </div>';
  254. if (!empty($thematic_advance_info2)) {
  255. $thematic_info2 = $thematic->get_thematic_list($thematic_advance_info2['thematic_id']);
  256. $thematic_advance_info2['start_date'] = api_get_local_time($thematic_advance_info2['start_date']);
  257. $thematic_advance_info2['start_date'] = api_format_date($thematic_advance_info2['start_date'], DATE_TIME_FORMAT_LONG);
  258. $thematic_description_html .= '
  259. <div class="col-md-6 items-progress">
  260. <div class="topics">'.$subTitle2.'</div>
  261. <h4 class="title-topics">'.$thematic_info2['title'].'</h4>
  262. <p class="date">'.$thematic_advance_info2['start_date'].'</p>
  263. <div class="views">'.$thematic_advance_info2['content'].'</div>
  264. <p class="time">'.get_lang('DurationInHours').' : '.$thematic_advance_info2['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('SeeDetail').'</a></p>
  265. </div>';
  266. }
  267. $thematic_description_html.='</div>';
  268. $thematic_description_html.='</div></div></div></div></div></div>';
  269. }
  270. }
  271. $introduction_section .= '<div class="row">';
  272. if (!empty($thematic_advance_info)) {
  273. $introduction_section .= '<div class="col-md-12">';
  274. $introduction_section .= $thematic_description_html;
  275. $introduction_section .= '</div>';
  276. }
  277. $editIconButton = '';
  278. if (api_is_allowed_to_edit() && empty($session_id)) {
  279. $editIconButton = Display::url(
  280. '<i class="fa fa-wrench"></i> ',
  281. api_get_path(WEB_CODE_PATH).'course_info/tools.php?'.api_get_cidreq(),
  282. ['class' => 'btn btn-default', 'title' => get_lang('CustomizeIcons') ]
  283. );
  284. }
  285. $toolbar = '';
  286. $textIntro = '';
  287. if ($intro_dispCommand) {
  288. if (empty($intro_content)) {
  289. // Displays "Add intro" commands
  290. $toolbar = '<div class="btn-group pull-right" rol="group">';
  291. if (!empty ($GLOBALS['_cid'])) {
  292. $textIntro = '<a class="btn btn-default" title="' . get_lang('AddIntro') . '" href="'.api_get_self().'?' . api_get_cidreq().'&intro_cmdAdd=1">';
  293. $textIntro .= '<i class="fa fa-file-text"></i> ';
  294. $textIntro .= "</a>";
  295. $toolbar .= $textIntro . $editIconButton;
  296. } else {
  297. $toolbar .= '<a class="btn btn-default" href="' . api_get_self() . '?intro_cmdAdd=1">"' . get_lang('AddIntro') . '</a>';
  298. $toolbar .= $editIconButton;
  299. }
  300. $toolbar .= '</div>';
  301. } else {
  302. // Displays "edit intro && delete intro" commands
  303. $toolbar .= '<div class="btn-group pull-right" rol="group">';
  304. if (!empty ($GLOBALS['_cid'])) {
  305. $toolbar .=
  306. '<a class="btn btn-default" href="'.api_get_self().'?'.api_get_cidreq().'&intro_cmdEdit=1" title="'.get_lang('Modify').'">
  307. <i class="fa fa-pencil"></i></a>';
  308. $toolbar .= $editIconButton;
  309. $toolbar .="<a class=\"btn btn-default\" href=\"".api_get_self()."?".api_get_cidreq()."&intro_cmdDel=1\" onclick=\"javascript:
  310. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  311. "')) return false;\"><i class=\"fa fa-trash-o\"></i></a>";
  312. } else {
  313. $toolbar .=
  314. '<a class="btn btn-default" href="'.api_get_self().'?intro_cmdEdit=1" title="'.get_lang('Modify').'">
  315. <i class="fa fa-pencil"></i>
  316. </a>"';
  317. $toolbar .= $editIconButton;
  318. $toolbar .= "<a class=\"btn btn-default\" href=\"".api_get_self()."?".api_get_cidreq()."&intro_cmdDel=1\" onclick=\"javascript:
  319. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  320. "')) return false;\"><i class=\"fa fa-trash-o\"></i></a>";
  321. }
  322. $toolbar .= "</div>";
  323. // Fix for chrome XSS filter for videos in iframes - BT#7930
  324. $browser = api_get_navigator();
  325. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  326. header('X-XSS-Protection: 0');
  327. }
  328. }
  329. }
  330. $introduction_section .= '<div class="col-md-12">';
  331. if ($intro_dispDefault) {
  332. if (!empty($intro_content)) {
  333. $introduction_section .= '<div class="page-course">';
  334. $introduction_section .= $intro_content;
  335. $introduction_section .= '</div>';
  336. } else {
  337. if (api_is_allowed_to_edit()) {
  338. $introduction_section .= '<div class="help-course">';
  339. $introduction_section .= get_lang('AddCustomCourseIntro') . ' ' . $textIntro;
  340. $introduction_section .= '</div>';
  341. }
  342. }
  343. }
  344. $introduction_section .= $toolbar;
  345. $introduction_section .= '</div>';
  346. $introduction_section .= '</div>';
  347. $browser = api_get_navigator();
  348. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  349. header("X-XSS-Protection: 0");
  350. }