introductionSection.inc.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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 Id
  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. /* Constants and variables */
  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->setElementTemplate('<div style="width: 80%; margin: 0px auto; padding-bottom: 10px; ">{element}</div>');
  47. $toolbar_set = 'Introduction';
  48. $width = '100%';
  49. $height = '300';
  50. // The global variable $fck_attribute has been deprecated. It stays here for supporting old external code.
  51. global $fck_attribute;
  52. if (is_array($fck_attribute)) {
  53. if (isset($fck_attribute['ToolbarSet'])) {
  54. $toolbar_set = $fck_attribute['ToolbarSet'];
  55. }
  56. if (isset($fck_attribute['Width'])) {
  57. $toolbar_set = $fck_attribute['Width'];
  58. }
  59. if (isset($fck_attribute['Height'])) {
  60. $toolbar_set = $fck_attribute['Height'];
  61. }
  62. }
  63. if (is_array($editor_config)) {
  64. if (!isset($editor_config['ToolbarSet'])) {
  65. $editor_config['ToolbarSet'] = $toolbar_set;
  66. }
  67. if (!isset($editor_config['Width'])) {
  68. $editor_config['Width'] = $width;
  69. }
  70. if (!isset($editor_config['Height'])) {
  71. $editor_config['Height'] = $height;
  72. }
  73. } else {
  74. $editor_config = array('ToolbarSet' => $toolbar_set, 'Width' => $width, 'Height' => $height);
  75. }
  76. $form->add_html_editor('intro_content', null, null, false, $editor_config);
  77. $form->addElement('style_submit_button', 'intro_cmdUpdate', get_lang('SaveIntroText'), 'class="save"');
  78. /* INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED) */
  79. $course_id = api_get_course_int_id();
  80. if ($intro_editAllowed) {
  81. $moduleId = Database::escape_string($moduleId);
  82. /* Replace command */
  83. if ($intro_cmdUpdate) {
  84. if ($form->validate()) {
  85. $form_values = $form->exportValues();
  86. $intro_content = Security::remove_XSS(stripslashes(api_html_entity_decode($form_values['intro_content'])), COURSEMANAGERLOWSECURITY);
  87. if (!empty($intro_content)) {
  88. $sql = "REPLACE $TBL_INTRODUCTION SET c_id = $course_id, id='$moduleId',intro_text='".Database::escape_string($intro_content)."', session_id='".intval($session_id)."'";
  89. Database::query($sql);
  90. $introduction_section .= Display::return_message(get_lang('IntroductionTextUpdated'),'confirmation', false);
  91. } else {
  92. $intro_cmdDel = true; // got to the delete command
  93. }
  94. } else {
  95. $intro_cmdEdit = true;
  96. }
  97. }
  98. /* Delete Command */
  99. if ($intro_cmdDel) {
  100. Database::query("DELETE FROM $TBL_INTRODUCTION WHERE c_id = $course_id AND id='".$moduleId."' AND session_id='".intval($session_id)."'");
  101. $introduction_section .= Display::return_message(get_lang('IntroductionTextDeleted'), 'confirmation');
  102. }
  103. }
  104. /* INTRODUCTION MICRO MODULE - DISPLAY SECTION */
  105. /* Retrieves the module introduction text, if exist */
  106. /* @todo use a lib to query the $TBL_INTRODUCTION table */
  107. // Getting course intro
  108. $intro_content = null;
  109. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION
  110. WHERE c_id = $course_id AND id='".Database::escape_string($moduleId)."' AND session_id = 0";
  111. $intro_dbQuery = Database::query($sql);
  112. if (Database::num_rows($intro_dbQuery) > 0) {
  113. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  114. $intro_content = $intro_dbResult['intro_text'];
  115. }
  116. // Getting session intro
  117. if (!empty($session_id)) {
  118. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION
  119. WHERE c_id = $course_id AND id='".Database::escape_string($moduleId)."' AND session_id = '".intval($session_id)."'";
  120. $intro_dbQuery = Database::query($sql);
  121. $introSessionContent = null;
  122. if (Database::num_rows($intro_dbQuery) > 0) {
  123. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  124. $introSessionContent = $intro_dbResult['intro_text'];
  125. }
  126. // If the course session intro exists replace it.
  127. if (!empty($introSessionContent)) {
  128. $intro_content = $introSessionContent;
  129. }
  130. }
  131. /* Determines the correct display */
  132. if ($intro_cmdEdit || $intro_cmdAdd) {
  133. $intro_dispDefault = false;
  134. $intro_dispForm = true;
  135. $intro_dispCommand = false;
  136. } else {
  137. $intro_dispDefault = true;
  138. $intro_dispForm = false;
  139. if ($intro_editAllowed) {
  140. $intro_dispCommand = true;
  141. } else {
  142. $intro_dispCommand = false;
  143. }
  144. }
  145. /* Executes the display */
  146. // display thematic advance inside a postit
  147. if ($intro_dispForm) {
  148. $default['intro_content'] = $intro_content;
  149. $form->setDefaults($default);
  150. $introduction_section .= '<div id="courseintro" style="width: 98%">';
  151. $introduction_section .= $form->return_form();
  152. $introduction_section .= '</div>';
  153. }
  154. $thematic_description_html = '';
  155. if ($tool == TOOL_COURSE_HOMEPAGE && !isset($_GET['intro_cmdEdit'])) {
  156. // Only show this if we're on the course homepage and we're not currently editing
  157. $thematic = new Thematic();
  158. $displayMode = api_get_course_setting('display_info_advance_inside_homecourse');
  159. $class1 = '';
  160. if ($displayMode == '1') {
  161. // Show only the current course progress step
  162. // $information_title = get_lang('InfoAboutLastDoneAdvance');
  163. $last_done_advance = $thematic->get_last_done_thematic_advance();
  164. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  165. $subTitle1 = get_lang('CurrentTopic');
  166. $class1 = ' current';
  167. } else if($displayMode == '2') {
  168. // Show only the two next course progress steps
  169. // $information_title = get_lang('InfoAboutNextAdvanceNotDone');
  170. $last_done_advance = $thematic->get_next_thematic_advance_not_done();
  171. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done(2);
  172. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  173. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  174. $subTitle1 = $subTitle2 = get_lang('NextTopic');
  175. } else if($displayMode == '3') {
  176. // Show the current and next course progress steps
  177. // $information_title = get_lang('InfoAboutLastDoneAdvanceAndNextAdvanceNotDone');
  178. $last_done_advance = $thematic->get_last_done_thematic_advance();
  179. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  180. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  181. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  182. $subTitle1 = get_lang('CurrentTopic');
  183. $subTitle2 = get_lang('NextTopic');
  184. $class1 = ' current';
  185. }
  186. if (!empty($thematic_advance_info)) {
  187. /*$thematic_advance = get_lang('CourseThematicAdvance').'&nbsp;'.
  188. $thematic->get_total_average_of_thematic_advances().'%';*/
  189. $thematic_advance = get_lang('CourseThematicAdvance');
  190. $thematicScore = $thematic->get_total_average_of_thematic_advances() . '%';
  191. $thematicUrl = api_get_path(WEB_CODE_PATH) .
  192. 'course_progress/index.php?action=thematic_details&'.api_get_cidreq();
  193. $thematic_info = $thematic->get_thematic_list(
  194. $thematic_advance_info['thematic_id']
  195. );
  196. $thematic_advance_info['start_date'] = api_get_local_time(
  197. $thematic_advance_info['start_date']
  198. );
  199. $thematic_advance_info['start_date'] = api_format_date(
  200. $thematic_advance_info['start_date'],
  201. DATE_TIME_FORMAT_LONG
  202. );
  203. $userInfo = $_SESSION['_user'];
  204. $courseInfo = api_get_course_info();
  205. //die('<pre>'.print_r($courseInfo,1).'</pre>');
  206. $thematic_description_html =
  207. '<div class="thematic-postit">
  208. <div class="row-fluid"><div class="span12">
  209. <div class="accordion" id="progress-bar-course">
  210. <div class="accordion-group">
  211. <div class="accordion-heading">
  212. <div class="title-accordion">
  213. <div class="row-fluid score-thematic">
  214. <div class="span8">';
  215. $thematic_description_html .=
  216. '<div class="span6 name-student">
  217. <h2>' . $userInfo['firstName'] . '</h2>
  218. <h3>' . $userInfo['lastName'] . '</h3>
  219. </div>
  220. <div class="span2 score">
  221. <h1>' . $thematicScore . '</h1>
  222. </div>
  223. <div class="span4">
  224. <h3>' . $thematic_advance . '</h3>
  225. <p>' . $courseInfo['name'] . '</p>
  226. </div>
  227. </div>';
  228. $thematic_description_html .=
  229. '<div class="span4">
  230. <a id="thematic-show" class="btn btn-small btn-primary accordion-toggle btn-hide-thematic" href="#pross" data-toggle="collapse" data-parent="#progress-bar-course">
  231. ' . get_lang('SeeDetail') . '
  232. </a>
  233. <a id="thematic-hide" class="btn btn-small accordion-toggle btn-show-thematic" href="#pross" data-toggle="collapse" data-parent="#progress-bar-course" style="display:none;">
  234. ' . get_lang('Hide') . '
  235. </a>
  236. </div>
  237. </div>
  238. </div>
  239. </div>';
  240. $thematic_description_html .=
  241. '<div class="accordion-body collapse in" id="pross" style="height: auto !important;">
  242. <div class="accordion-inner">
  243. <div class="row-fluid">
  244. <div class="span4">
  245. <div class="row-fluid">
  246. <div class="span4">
  247. <div class="thumbnail">
  248. <img src="' . $userInfo['avatar'] . '" class="img-polaroid">
  249. </div>
  250. </div>
  251. <div class="span8">
  252. <div class="info-progress">
  253. <div class="tittle-score">' . $thematic_advance . '&nbsp;' . $thematicScore .'
  254. </div>
  255. <div class="progress progress-striped">
  256. <div class="bar" style="width: ' . $thematicScore . ';"></div>
  257. </div>
  258. <a href="' . $thematicUrl . '" class="btn btn-info">' . get_lang('ShowFullCourseAdvance') . '</a>
  259. </div>
  260. </div>
  261. </div>
  262. </div>';
  263. $thematic_description_html .=
  264. '<div class="span8">
  265. <div class="row-fluid">';
  266. $thematic_description_html .=
  267. '<div class="span6 items-progress'.$class1.'">
  268. <div class="topics">' . $subTitle1 . '</div>
  269. <p class="title_topics">' . $thematic_info['title'] . '</p>
  270. <p class="date">' . $thematic_advance_info['start_date'] . '</p>
  271. <h3 class="title">' . $thematic_advance_info['content'] . '</h3>
  272. <p class="time">' . get_lang('DurationInHours') . ' : ' . $thematic_advance_info['duration'] . ' - <a href="' . $thematicUrl . '">' . get_lang('SeeDetail') . '</a></p>
  273. </div>';
  274. if (!empty($thematic_advance_info2)) {
  275. $thematic_info2 = $thematic->get_thematic_list($thematic_advance_info2['thematic_id']);
  276. $thematic_advance_info2['start_date'] = api_get_local_time($thematic_advance_info2['start_date']);
  277. $thematic_advance_info2['start_date'] = api_format_date($thematic_advance_info2['start_date'], DATE_TIME_FORMAT_LONG);
  278. $thematic_description_html .=
  279. '<div class="span6 items-progress">
  280. <div class="topics">'.$subTitle2.'</div>
  281. <p class="title_topics">'.$thematic_info['title'].'</p>
  282. <p class="date">'.$thematic_advance_info2['start_date'].'</p>
  283. <h3 class="title">'.$thematic_advance_info2['content'].'</h3>
  284. <p class="time">'.get_lang('DurationInHours').' : '.$thematic_advance_info2['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('SeeDetail').'</a></p>
  285. </div>';
  286. }
  287. $thematic_description_html.=
  288. '</div>
  289. </div>
  290. </div>
  291. </div>
  292. </div>
  293. </div>
  294. </div>
  295. </div>
  296. </div>
  297. </div>';
  298. }
  299. }
  300. $introduction_section .= '<div class="row course-tools-intro"><div class="span12">';
  301. $introduction_section .= $thematic_description_html;
  302. $introduction_section .= '</div>';
  303. $introduction_section .= '<div class="home-course-intro span12"><div class="page-course">';
  304. if ($intro_dispDefault) {
  305. $intro_content = $intro_content;
  306. if (!empty($intro_content)) {
  307. $introduction_section.='<div class="page-course-intro">';
  308. $introduction_section .= $intro_content;
  309. $introduction_section.='</div>';
  310. }
  311. }
  312. $introduction_section .= '</div></div>';
  313. if ($intro_dispCommand) {
  314. if (empty($intro_content)) {
  315. // Displays "Add intro" commands
  316. $introduction_section .= '<div id="courseintro_empty">';
  317. if (!empty ($GLOBALS['_cid'])) {
  318. $introduction_section .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdAdd=1\">";
  319. $introduction_section .= Display::return_icon('introduction_add.gif', get_lang('AddIntro')).' ';
  320. $introduction_section .= "</a>";
  321. } else {
  322. $introduction_section .= "<a href=\"".api_get_self()."?intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>";
  323. }
  324. $introduction_section .= "</div>";
  325. } else {
  326. // Displays "edit intro && delete intro" commands
  327. $introduction_section .= '<div id="courseintro_empty">';
  328. if (!empty ($GLOBALS['_cid'])) {
  329. $introduction_section .=
  330. "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdEdit=1\">".
  331. Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL).
  332. "</a>";
  333. $introduction_section .=
  334. "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdDel=1\" onclick=\"javascript:
  335. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  336. "')) return false;\">".
  337. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
  338. "</a>";
  339. } else {
  340. $introduction_section .=
  341. "<a href=\"".api_get_self()."?intro_cmdEdit=1\">".
  342. Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL).
  343. "</a>";
  344. $introduction_section .=
  345. "<a href=\"".api_get_self()."?intro_cmdDel=1\" onclick=\"javascript:
  346. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  347. "')) return false;\">".
  348. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
  349. "</a>";
  350. }
  351. $introduction_section .= "</div>";
  352. // Fix for chrome XSS filter for videos in iframes - BT#7930
  353. $browser = api_get_navigator();
  354. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  355. header('X-XSS-Protection: 0');
  356. }
  357. }
  358. }
  359. $introduction_section .= '</div>';
  360. $browser = api_get_navigator();
  361. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  362. header("X-XSS-Protection: 0");
  363. }