thematic_advance.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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('select', 'attendance_select', get_lang('Attendances'), $attendance_select, array('id' => 'id_attendance_select', 'onchange' => 'datetime_by_attendance(this.value)'));
  72. } else {
  73. $form->addElement('label', get_lang('Attendances'), '<strong><em>'.get_lang('ThereAreNoAttendancesInsideCourse').'</em></strong>');
  74. }
  75. $form->addElement('html', '<div id="div_datetime_attendance">');
  76. if (!empty($calendar_select)) {
  77. $form->addElement('select', 'start_date_by_attendance', get_lang('StartDate'), $calendar_select, array('id'=>'start_date_select_calendar'));
  78. }
  79. $form->addElement('html', '</div>');
  80. $form->addElement('html', '</div>');
  81. $form->addText(
  82. 'duration_in_hours',
  83. get_lang('DurationInHours'),
  84. false,
  85. array(
  86. 'size' => '3',
  87. 'id' => 'duration_in_hours_element',
  88. 'autofocus' => 'autofocus',
  89. )
  90. );
  91. $form->addHtmlEditor(
  92. 'content',
  93. get_lang('Content'),
  94. false,
  95. false,
  96. array(
  97. 'ToolbarStartExpanded' => 'false',
  98. 'ToolbarSet' => 'TrainingDescription',
  99. 'Height' => '150',
  100. )
  101. );
  102. if ($action == 'thematic_advance_add') {
  103. $form->addButtonSave(get_lang('Save'));
  104. } else {
  105. $form->addButtonUpdate(get_lang('Save'));
  106. }
  107. $attendance_select_item_id = null;
  108. if (count($attendance_select) > 1) {
  109. $i = 1;
  110. foreach ($attendance_select as $key => $attendance_select_item) {
  111. if ($i == 2) {
  112. $attendance_select_item_id = $key;
  113. break;
  114. }
  115. $i++;
  116. }
  117. if (!empty($attendance_select_item_id)) {
  118. $default['attendance_select'] = $attendance_select_item_id;
  119. if ($thematic_advance_id) {
  120. echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", "'.$thematic_advance_id.'"); </script>';
  121. } else {
  122. echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", 0); </script>';
  123. }
  124. }
  125. }
  126. $default['start_date_type'] = 1;
  127. $default['custom_start_date'] = date('Y-m-d H:i:s', api_strtotime(api_get_local_time()));
  128. $default['duration_in_hours'] = 1;
  129. if (!empty($thematic_advance_data)) {
  130. // set default values
  131. $default['content'] = isset($thematic_advance_data['content']) ? $thematic_advance_data['content'] : null;
  132. $default['duration_in_hours'] = isset($thematic_advance_data['duration']) ? $thematic_advance_data['duration'] : null;
  133. if (empty($thematic_advance_data['attendance_id'])) {
  134. $default['start_date_type'] = 1;
  135. $default['custom_start_date'] = null;
  136. if (isset($thematic_advance_data['start_date'])) {
  137. $default['custom_start_date'] = date(
  138. 'Y-m-d H:i:s',
  139. api_strtotime(api_get_local_time($thematic_advance_data['start_date']))
  140. );
  141. }
  142. } else {
  143. $default['start_date_type'] = 1;
  144. if (!empty($thematic_advance_data['start_date'])) {
  145. $default['start_date_by_attendance'] = api_get_local_time($thematic_advance_data['start_date']);
  146. }
  147. $default['attendance_select'] = $thematic_advance_data['attendance_id'];
  148. }
  149. }
  150. $form->setDefaults($default);
  151. if ($form->validate()) {
  152. $values = $form->exportValues();
  153. $thematic = new Thematic();
  154. $thematic->set_thematic_advance_attributes(
  155. isset($values['thematic_advance_id']) ? $values['thematic_advance_id']: null,
  156. $values['thematic_id'],
  157. $values['start_date_type'] == 1 && isset($values['attendance_select']) ? $values['attendance_select'] : 0,
  158. $values['content'],
  159. $values['start_date_type'] == 2 ? $values['custom_start_date'] : $values['start_date_by_attendance'],
  160. $values['duration_in_hours']
  161. );
  162. $affected_rows = $thematic->thematic_advance_save();
  163. if ($affected_rows) {
  164. // get last done thematic advance before move thematic list
  165. $last_done_thematic_advance = $thematic->get_last_done_thematic_advance();
  166. // update done advances with de current thematic list
  167. if (!empty($last_done_thematic_advance)) {
  168. $thematic->update_done_thematic_advances($last_done_thematic_advance);
  169. }
  170. }
  171. $redirectUrlParams = 'course_progress/index.php?' . api_get_cidreq() . '&' .
  172. http_build_query([
  173. 'action' => 'thematic_advance_list',
  174. 'thematic_id' => $values['thematic_id']
  175. ]);
  176. header('Location: ' . api_get_path(WEB_CODE_PATH) . $redirectUrlParams);
  177. exit;
  178. }
  179. $form->display();
  180. } else if ($action == 'thematic_advance_list') {
  181. // thematic advance list
  182. echo '<div class="actions">';
  183. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_details">'.
  184. Display::return_icon('back.png', get_lang("BackTo"),'',ICON_SIZE_MEDIUM).'</a>';
  185. if (api_is_allowed_to_edit(false, true)) {
  186. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_advance_add&amp;thematic_id='.$thematic_id.'"> '.
  187. Display::return_icon('add.png', get_lang('NewThematicAdvance'),'',ICON_SIZE_MEDIUM).'</a>';
  188. }
  189. echo '</div>';
  190. $table = new SortableTable(
  191. 'thematic_advance_list',
  192. array('Thematic', 'get_number_of_thematic_advances'),
  193. array('Thematic', 'get_thematic_advance_data')
  194. );
  195. //$table->set_additional_parameters($parameters);
  196. $table->set_header(0, '', false, array('style'=>'width:20px;'));
  197. $table->set_header(1, get_lang('StartDate'), false);
  198. $table->set_header(2, get_lang('DurationInHours'), false, array('style'=>'width:80px;'));
  199. $table->set_header(3, get_lang('Content'), false);
  200. if (api_is_allowed_to_edit(null, true)) {
  201. $table->set_header(
  202. 4,
  203. get_lang('Actions'),
  204. false,
  205. array('style' => 'text-align:center')
  206. );
  207. }
  208. $table->display();
  209. }