thematic.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for thematic control
  5. * @author Christian Fasanando <christian1827@gmail.com>
  6. * @author Julio Montoya <gugli100@gmail.com> Bug fixing
  7. * @package chamilo.course_progress
  8. */
  9. // protect a course script
  10. api_protect_course_script(true);
  11. $token = Security::get_token();
  12. $url_token = "&sec_token=".$token;
  13. $user_info = api_get_user_info();
  14. $param_gradebook = '&'.api_get_cidreq();
  15. if (api_is_allowed_to_edit(null, true)) {
  16. echo '<div class="actions">';
  17. switch ($action) {
  18. case 'thematic_add' :
  19. case 'thematic_import_select' :
  20. echo '<a href="index.php?'.api_get_cidreq().'">'.
  21. Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('ThematicDetails'),'',ICON_SIZE_MEDIUM).'</a>';
  22. break;
  23. case 'thematic_list' :
  24. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
  25. Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'</a>';
  26. break;
  27. case 'thematic_details' :
  28. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
  29. Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'</a>';
  30. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_import_select'.$url_token.'">'.
  31. Display::return_icon('import_csv.png',get_lang('ImportThematic'),'',ICON_SIZE_MEDIUM).'</a>';
  32. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_export'.$url_token.'">'.
  33. Display::return_icon('export_csv.png',get_lang('ExportThematic'),'', ICON_SIZE_MEDIUM).'</a>';
  34. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_export_pdf'.$url_token.'">'.
  35. Display::return_icon('pdf.png',get_lang('ExportToPDF'),'', ICON_SIZE_MEDIUM).'</a>';
  36. break;
  37. default :
  38. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
  39. Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'</a>';
  40. }
  41. echo '</div>';
  42. }
  43. if ($action == 'thematic_list') {
  44. $table = new SortableTable(
  45. 'thematic_list',
  46. array('Thematic', 'get_number_of_thematics'),
  47. array('Thematic', 'get_thematic_data')
  48. );
  49. $parameters['action'] = $action;
  50. $table->set_additional_parameters($parameters);
  51. $table->set_header(0, '', false, array('style'=>'width:20px;'));
  52. $table->set_header(1, get_lang('Title'), false );
  53. if (api_is_allowed_to_edit(null, true)) {
  54. $table->set_header(2, get_lang('Actions'), false,array('style'=>'text-align:center;width:40%;'));
  55. $table->set_form_actions(array ('thematic_delete_select' => get_lang('DeleteAllThematics')));
  56. }
  57. $table->display();
  58. } elseif ($action == 'thematic_details') {
  59. if (isset($_GET['thematic_plan_save_message']) && $_GET['thematic_plan_save_message'] == 'ok') {
  60. Display::display_confirmation_message(get_lang('ThematicSectionHasBeenCreatedSuccessfull'));
  61. }
  62. if (isset($last_id) && $last_id) {
  63. $link_to_thematic_plan = '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$last_id.'">'.
  64. Display::return_icon('lesson_plan.png', get_lang('ThematicPlan'), array('style'=>'vertical-align:middle;float:none;'),ICON_SIZE_SMALL).'</a>';
  65. $link_to_thematic_advance = '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$last_id.'">'.
  66. Display::return_icon('lesson_plan_calendar.png', get_lang('ThematicAdvance'), array('style'=>'vertical-align:middle;float:none;'),ICON_SIZE_SMALL).'</a>';
  67. Display::display_confirmation_message(
  68. get_lang('ThematicSectionHasBeenCreatedSuccessfull').'<br />'.sprintf(get_lang('NowYouShouldAddThematicPlanXAndThematicAdvanceX'),$link_to_thematic_plan, $link_to_thematic_advance),
  69. false
  70. );
  71. }
  72. // display title
  73. if (!empty($thematic_id)) {
  74. } else {
  75. // display information
  76. $message = '<strong>'.get_lang('Information').'</strong><br />';
  77. $message .= get_lang('ThematicDetailsDescription');
  78. Display::display_normal_message($message, false);
  79. echo '<br />';
  80. }
  81. // Display thematic data
  82. if (!empty($thematic_data)) {
  83. // display progress
  84. echo '<div style="text-align:right;"><h2>'.get_lang('Progress').': <span id="div_result">'.$total_average_of_advances.'</span> %</h2></div>';
  85. echo '<table width="100%" class="data_table">';
  86. echo '<tr><th width="33%">'.get_lang('Thematic').'</th><th>'.get_lang('ThematicPlan').'</th><th width="33%">'.get_lang('ThematicAdvance').'</th></tr>';
  87. foreach ($thematic_data as $thematic) {
  88. $my_thematic_id = $thematic['id'];
  89. $session_star = '';
  90. if (api_is_allowed_to_edit(null, true)) {
  91. if (api_get_session_id() == $thematic['session_id']) {
  92. $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
  93. }
  94. }
  95. //@todo add a validation in order to load or not course thematics in the session thematic
  96. echo '<tr>';
  97. $actions_first_col = '';
  98. if (api_is_allowed_to_edit(null, true)) {
  99. // Thematic title
  100. $actions_first_col = Display::url(
  101. Display::return_icon('cd.gif', get_lang('Copy')),
  102. 'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$my_thematic_id.$param_gradebook.$url_token
  103. );
  104. if (api_get_session_id() == 0 ) {
  105. if ($thematic['display_order'] > 1) {
  106. $actions_first_col .= ' <a href="'.api_get_self().'?action=moveup&'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('up.png', get_lang('Up'),'',ICON_SIZE_SMALL).'</a>';
  107. } else {
  108. $actions_first_col .= ' '.Display::return_icon('up_na.png','&nbsp;','',ICON_SIZE_SMALL);
  109. }
  110. if (isset($thematic['max_thematic_item']) && $thematic['display_order'] < $thematic['max_thematic_item']) {
  111. $actions_first_col .= ' <a href="'.api_get_self().'?action=movedown&a'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('down.png',get_lang('Down'),'',ICON_SIZE_SMALL).'</a>';
  112. } else {
  113. $actions_first_col .= ' '.Display::return_icon('down_na.png','&nbsp;','',ICON_SIZE_SMALL);
  114. }
  115. }
  116. if (api_get_session_id() == $thematic['session_id']) {
  117. $actions_first_col .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>';
  118. $actions_first_col .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  119. }
  120. $actions_first_col = Display::div($actions_first_col, array('id'=>'thematic_id_content_'.$thematic['id'], 'class'=>'thematic_tools'));
  121. $actions_first_col = Display::div($actions_first_col, array('style'=>'height:20px'));
  122. }
  123. echo Display::tag('td', Display::tag('h3', Security::remove_XSS($thematic['title'], STUDENT).$session_star).Security::remove_XSS($thematic['content'], STUDENT).$actions_first_col, array('id'=>'thematic_td_content_'.$thematic['id'], 'class'=>'thematic_content'));
  124. // Display 2nd column - thematic plan data
  125. echo '<td>';
  126. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  127. if (api_is_allowed_to_edit(null, true)) {
  128. echo '<div style="text-align:right"><a href="index.php?'.api_get_cidreq().'&origin=thematic_details&action=thematic_plan_list&thematic_id='.$thematic['id'].'&width=700&height=500">'.
  129. Display::return_icon('edit.png', get_lang('EditThematicPlan'), array('style'=>'vertical-align:middle'),ICON_SIZE_MEDIUM).'</a></div><br />';
  130. }
  131. if (empty($thematic_plan_div[$thematic['id']])) {
  132. echo Display::div('', array('id' => "thematic_plan_".$thematic['id']));
  133. } else {
  134. echo $thematic_plan_div[$thematic['id']];
  135. }
  136. echo '</td>';
  137. // Display 3rd column - thematic advance data
  138. echo '<td style="vertical-align:top">';
  139. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  140. if (api_is_allowed_to_edit(null, true)) {
  141. echo '<div style="text-align:right"><a href="index.php?'.api_get_cidreq().'&action=thematic_advance_add&thematic_id='.$thematic['id'].'">'.
  142. Display::return_icon('add.png',get_lang('NewThematicAdvance'),'',ICON_SIZE_MEDIUM).'</a></div>';
  143. }
  144. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  145. if (!empty($thematic_advance_data[$thematic['id']])) {
  146. echo '<table width="100%">';
  147. foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
  148. $thematic_advance['start_date'] = api_get_local_time($thematic_advance['start_date']);
  149. $thematic_advance['start_date'] = api_format_date($thematic_advance['start_date'], DATE_TIME_FORMAT_LONG);
  150. echo '<tr>';
  151. echo '<td width="90%" class="thematic_advance_content" id="thematic_advance_content_id_'.$thematic_advance['id'].'">';
  152. $edit_link = '';
  153. if (api_is_allowed_to_edit(null, true)) {
  154. $edit_link = Display::url(
  155. Display::return_icon(
  156. 'edit.png',
  157. get_lang('EditThematicAdvance'),
  158. [],
  159. ICON_SIZE_SMALL
  160. ),
  161. 'index.php?' . api_get_cidreq() . '&' . http_build_query([
  162. 'action' => 'thematic_advance_edit',
  163. 'thematic_id' => $thematic['id'],
  164. 'thematic_advance_id' => $thematic_advance['id'],
  165. 'display' => 'no_header'
  166. ]),
  167. [
  168. 'class' => 'ajax',
  169. 'data-title' => get_lang('EditThematicAdvance')
  170. ]
  171. );
  172. $edit_link .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_advance_delete&thematic_id='.$thematic['id'].'&thematic_advance_id='.$thematic_advance['id'].'">'.
  173. Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a></center>';
  174. //Links
  175. $edit_link = Display::div(
  176. Display::div($edit_link , array('id'=>'thematic_advance_tools_'.$thematic_advance['id'], 'class'=>'thematic_advance_actions')),
  177. array('style'=>'height:20px;')
  178. );
  179. }
  180. $thematic_advance_item = isset($thematic_advance_div[$thematic['id']][$thematic_advance['id']]) ? $thematic_advance_div[$thematic['id']][$thematic_advance['id']] : null;
  181. echo Display::div($thematic_advance_item, array('id'=>'thematic_advance_'.$thematic_advance['id']));
  182. echo $edit_link;
  183. echo '</td>';
  184. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  185. if (api_is_allowed_to_edit(null, true)) {
  186. if (empty($thematic_id)) {
  187. $checked = '';
  188. if ($last_done_thematic_advance == $thematic_advance['id']) {
  189. $checked = 'checked';
  190. }
  191. $style = '';
  192. if ($thematic_advance['done_advance'] == 1) {
  193. $style = ' style="background-color:#E5EDF9" ';
  194. } else {
  195. $style = ' style="background-color:#fff" ';
  196. }
  197. echo '<td id="td_done_thematic_'.$thematic_advance['id'].'" '.$style.'><center>';
  198. echo '<input type="radio" class="done_thematic" id="done_thematic_'.$thematic_advance['id'].'" name="done_thematic" value="'.$thematic_advance['id'].'" '.$checked.' onclick="update_done_thematic_advance(this.value)">';
  199. echo '</center></td>';
  200. } else {
  201. if ($thematic_advance['done_advance'] == 1) {
  202. echo '<td><center>'.get_lang('Done').'</center></td>';
  203. } else {
  204. echo '<td><center>-</center></td>';
  205. }
  206. }
  207. }
  208. echo '</tr>';
  209. }
  210. echo '</table>';
  211. } else {
  212. echo '<div><em>'.get_lang('ThereIsNoAThematicAdvance').'</em></div>';
  213. }
  214. echo '</td>';
  215. echo '</tr>';
  216. } //End for
  217. echo '</table>';
  218. } else {
  219. echo '<div><em>'.get_lang('ThereIsNoAThematicSection').'</em></div>';
  220. }
  221. } elseif ($action == 'thematic_add' || $action == 'thematic_edit') {
  222. // Display form
  223. $form = new FormValidator('thematic_add','POST','index.php?action=thematic_add&'.api_get_cidreq());
  224. if ($action == 'thematic_edit') {
  225. $form->addElement('header', '', get_lang('EditThematicSection'));
  226. }
  227. $form->addElement('hidden', 'sec_token', $token);
  228. $form->addElement('hidden', 'action', $action);
  229. if (!empty($thematic_id)) {
  230. $form->addElement('hidden', 'thematic_id',$thematic_id);
  231. }
  232. $form->addText('title', get_lang('Title'), true, array('size'=>'50'));
  233. $form->addHtmlEditor('content', get_lang('Content'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Height' => '150'));
  234. $form->addButtonSave(get_lang('Save'));
  235. $show_form = true;
  236. if (!empty($thematic_data)) {
  237. if (api_get_session_id()) {
  238. if ($thematic_data['session_id'] != api_get_session_id()) {
  239. $show_form = false;
  240. Display::display_error_message(get_lang('NotAllowedClickBack'),false);
  241. }
  242. }
  243. // set default values
  244. $default['title'] = $thematic_data['title'];
  245. $default['content'] = $thematic_data['content'];
  246. $form->setDefaults($default);
  247. }
  248. // error messages
  249. if (isset($error)) {
  250. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false);
  251. }
  252. if ($show_form) {
  253. $form->display();
  254. }
  255. } elseif ($action == 'thematic_import_select') {
  256. // Create form to upload csv file.
  257. $form = new FormValidator('thematic_import','POST','index.php?action=thematic_import&'.api_get_cidreq().$url_token);
  258. $form->addElement('header', get_lang('ImportThematic'));
  259. $form->addElement('file', 'file');
  260. $form->addElement('checkbox', 'replace', null, get_lang('DeleteAllThematic'));
  261. $form->addButtonImport(get_lang('Import'), 'SubmitImport');
  262. $form->display();
  263. }