thematic_advance.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for thematic advance
  5. * @author Christian Fasanando <christian1827@gmail.com>
  6. * @author Julio Montoya <gugli100@gmail.com> BeezNest 2011 Bug fixing
  7. * @package chamilo.course_progress
  8. */
  9. // protect a course script
  10. api_protect_course_script(true);
  11. if ($action === 'thematic_advance_add' || $action === 'thematic_advance_edit') {
  12. $header_form = get_lang('NewThematicAdvance');
  13. if ($action === 'thematic_advance_edit') {
  14. $header_form = get_lang('EditThematicAdvance');
  15. }
  16. // display form
  17. $form = new FormValidator(
  18. 'thematic_advance',
  19. 'POST',
  20. api_get_self().'?'.api_get_cidreq()
  21. );
  22. $form->addElement('header', $header_form);
  23. //$form->addElement('hidden', 'thematic_advance_token',$token);
  24. $form->addElement('hidden', 'action', $action);
  25. if (!empty($thematic_advance_id)) {
  26. $form->addElement('hidden', 'thematic_advance_id', $thematic_advance_id);
  27. }
  28. if (!empty($thematic_id)) {
  29. $form->addElement('hidden', 'thematic_id', $thematic_id);
  30. }
  31. $radios = array();
  32. $radios[] = $form->createElement(
  33. 'radio',
  34. 'start_date_type',
  35. null,
  36. get_lang('StartDateFromAnAttendance'),
  37. '1',
  38. array(
  39. 'onclick' => 'check_per_attendance(this)',
  40. 'id' => 'from_attendance',
  41. )
  42. );
  43. $radios[] = $form->createElement(
  44. 'radio',
  45. 'start_date_type',
  46. null,
  47. get_lang('StartDateCustom'),
  48. '2',
  49. array(
  50. 'onclick' => 'check_per_custom_date(this)',
  51. 'id' => 'custom_date'
  52. )
  53. );
  54. $form->addGroup($radios, null, get_lang('StartDateOptions'));
  55. if (isset($thematic_advance_data['attendance_id']) &&
  56. $thematic_advance_data['attendance_id'] == 0) {
  57. $form->addElement('html', '<div id="div_custom_datetime" style="display:block">');
  58. } else {
  59. $form->addElement('html', '<div id="div_custom_datetime" style="display:none">');
  60. }
  61. $form->addElement('DateTimePicker', 'custom_start_date', get_lang('StartDate'));
  62. $form->addElement('html', '</div>');
  63. if (isset($thematic_advance_data['attendance_id']) &&
  64. $thematic_advance_data['attendance_id'] == 0
  65. ) {
  66. $form->addElement('html', '<div id="div_datetime_by_attendance" style="display:none">');
  67. } else {
  68. $form->addElement('html', '<div id="div_datetime_by_attendance" style="display:block">');
  69. }
  70. if (count($attendance_select) > 1) {
  71. $form->addElement(
  72. 'select',
  73. 'attendance_select',
  74. get_lang('Attendances'),
  75. $attendance_select,
  76. array('id' => 'id_attendance_select', 'onchange' => 'datetime_by_attendance(this.value)')
  77. );
  78. } else {
  79. $form->addElement(
  80. 'label',
  81. get_lang('Attendances'),
  82. '<strong><em>'.get_lang('ThereAreNoAttendancesInsideCourse').'</em></strong>'
  83. );
  84. }
  85. $form->addElement('html', '<div id="div_datetime_attendance">');
  86. if (!empty($calendar_select)) {
  87. $form->addElement(
  88. 'select',
  89. 'start_date_by_attendance',
  90. get_lang('StartDate'),
  91. $calendar_select,
  92. array('id' => 'start_date_select_calendar')
  93. );
  94. }
  95. $form->addElement('html', '</div>');
  96. $form->addElement('html', '</div>');
  97. $form->addText(
  98. 'duration_in_hours',
  99. get_lang('DurationInHours'),
  100. false,
  101. array(
  102. 'size' => '3',
  103. 'id' => 'duration_in_hours_element',
  104. 'autofocus' => 'autofocus',
  105. )
  106. );
  107. $form->addHtmlEditor(
  108. 'content',
  109. get_lang('Content'),
  110. false,
  111. false,
  112. array(
  113. 'ToolbarStartExpanded' => 'false',
  114. 'ToolbarSet' => 'TrainingDescription',
  115. 'Height' => '150',
  116. )
  117. );
  118. if ($action == 'thematic_advance_add') {
  119. $form->addButtonSave(get_lang('Save'));
  120. } else {
  121. $form->addButtonUpdate(get_lang('Save'));
  122. }
  123. $attendance_select_item_id = null;
  124. if (count($attendance_select) > 1) {
  125. $i = 1;
  126. foreach ($attendance_select as $key => $attendance_select_item) {
  127. if ($i == 2) {
  128. $attendance_select_item_id = $key;
  129. break;
  130. }
  131. $i++;
  132. }
  133. if (!empty($attendance_select_item_id)) {
  134. $default['attendance_select'] = $attendance_select_item_id;
  135. if ($thematic_advance_id) {
  136. echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", "'.$thematic_advance_id.'"); </script>';
  137. } else {
  138. echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", 0); </script>';
  139. }
  140. }
  141. }
  142. $default['start_date_type'] = 1;
  143. $default['custom_start_date'] = date('Y-m-d H:i:s', api_strtotime(api_get_local_time()));
  144. $default['duration_in_hours'] = 1;
  145. if (!empty($thematic_advance_data)) {
  146. // set default values
  147. $default['content'] = isset($thematic_advance_data['content']) ? $thematic_advance_data['content'] : null;
  148. $default['duration_in_hours'] = isset($thematic_advance_data['duration']) ? $thematic_advance_data['duration'] : 1;
  149. if (empty($thematic_advance_data['attendance_id'])) {
  150. $default['start_date_type'] = 1;
  151. $default['custom_start_date'] = null;
  152. if (isset($thematic_advance_data['start_date'])) {
  153. $default['custom_start_date'] = date(
  154. 'Y-m-d H:i:s',
  155. api_strtotime(api_get_local_time($thematic_advance_data['start_date']))
  156. );
  157. }
  158. } else {
  159. $default['start_date_type'] = 1;
  160. if (!empty($thematic_advance_data['start_date'])) {
  161. $default['start_date_by_attendance'] = api_get_local_time($thematic_advance_data['start_date']);
  162. }
  163. $default['attendance_select'] = $thematic_advance_data['attendance_id'];
  164. }
  165. }
  166. $form->setDefaults($default);
  167. if ($form->validate()) {
  168. $values = $form->exportValues();
  169. if (isset($_POST['start_date_by_attendance'])) {
  170. $values['start_date_by_attendance'] = $_POST['start_date_by_attendance'];
  171. }
  172. $thematic = new Thematic();
  173. $thematic->set_thematic_advance_attributes(
  174. isset($values['thematic_advance_id']) ? $values['thematic_advance_id'] : null,
  175. $values['thematic_id'],
  176. $values['start_date_type'] == 1 && isset($values['attendance_select']) ? $values['attendance_select'] : 0,
  177. $values['content'],
  178. $values['start_date_type'] == 2 ? $values['custom_start_date'] : $values['start_date_by_attendance'],
  179. $values['duration_in_hours']
  180. );
  181. $affected_rows = $thematic->thematic_advance_save();
  182. if ($affected_rows) {
  183. // get last done thematic advance before move thematic list
  184. $last_done_thematic_advance = $thematic->get_last_done_thematic_advance();
  185. // update done advances with de current thematic list
  186. if (!empty($last_done_thematic_advance)) {
  187. $thematic->update_done_thematic_advances($last_done_thematic_advance);
  188. }
  189. }
  190. $redirectUrlParams = 'course_progress/index.php?'.api_get_cidreq().'&'.
  191. http_build_query([
  192. 'action' => 'thematic_advance_list',
  193. 'thematic_id' => $values['thematic_id']
  194. ]);
  195. header('Location: '.api_get_path(WEB_CODE_PATH).$redirectUrlParams);
  196. exit;
  197. }
  198. $form->display();
  199. } else if ($action == 'thematic_advance_list') {
  200. // thematic advance list
  201. echo '<div class="actions">';
  202. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_details">'.
  203. Display::return_icon('back.png', get_lang("BackTo"), '', ICON_SIZE_MEDIUM).'</a>';
  204. if (api_is_allowed_to_edit(false, true)) {
  205. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_advance_add&amp;thematic_id='.$thematic_id.'"> '.
  206. Display::return_icon('add.png', get_lang('NewThematicAdvance'), '', ICON_SIZE_MEDIUM).'</a>';
  207. }
  208. echo '</div>';
  209. $table = new SortableTable(
  210. 'thematic_advance_list',
  211. array('Thematic', 'get_number_of_thematic_advances'),
  212. array('Thematic', 'get_thematic_advance_data')
  213. );
  214. //$table->set_additional_parameters($parameters);
  215. $table->set_header(0, '', false, array('style'=>'width:20px;'));
  216. $table->set_header(1, get_lang('StartDate'), false);
  217. $table->set_header(2, get_lang('DurationInHours'), false, array('style'=>'width:80px;'));
  218. $table->set_header(3, get_lang('Content'), false);
  219. if (api_is_allowed_to_edit(null, true)) {
  220. $table->set_header(
  221. 4,
  222. get_lang('Actions'),
  223. false,
  224. array('style' => 'text-align:center')
  225. );
  226. }
  227. $table->display();
  228. }