thematic_advance.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. 'index.php?action=thematic_advance_list&thematic_id='.$thematic_id.'&'.api_get_cidreq(
  21. )
  22. );
  23. $form->addElement('header', $header_form);
  24. //$form->addElement('hidden', 'thematic_advance_token',$token);
  25. $form->addElement('hidden', 'action', $action);
  26. if (!empty($thematic_advance_id)) {
  27. $form->addElement('hidden', 'thematic_advance_id',$thematic_advance_id);
  28. }
  29. if (!empty($thematic_id)) {
  30. $form->addElement('hidden', 'thematic_id',$thematic_id);
  31. }
  32. $radios = array();
  33. $radios[] = $form->createElement(
  34. 'radio',
  35. 'start_date_type',
  36. null,
  37. get_lang('StartDateFromAnAttendance'),
  38. '1',
  39. array(
  40. 'onclick' => 'check_per_attendance(this)',
  41. 'id' => 'from_attendance',
  42. )
  43. );
  44. $radios[] = $form->createElement(
  45. 'radio',
  46. 'start_date_type',
  47. null,
  48. get_lang('StartDateCustom'),
  49. '2',
  50. array('onclick' => 'check_per_custom_date(this)', 'id' => 'custom_date')
  51. );
  52. $form->addGroup($radios, null, get_lang('StartDateOptions'));
  53. if (isset($thematic_advance_data['attendance_id']) &&
  54. $thematic_advance_data['attendance_id'] == 0) {
  55. $form->addElement('html', '<div id="div_custom_datetime" style="display:block">');
  56. } else {
  57. $form->addElement('html', '<div id="div_custom_datetime" style="display:none">');
  58. }
  59. $form->addElement('DateTimePicker', 'custom_start_date', get_lang('StartDate'));
  60. $form->addElement('html', '</div>');
  61. if (isset($thematic_advance_data['attendance_id']) &&
  62. $thematic_advance_data['attendance_id'] == 0
  63. ) {
  64. $form->addElement('html', '<div id="div_datetime_by_attendance" style="display:none">');
  65. } else {
  66. $form->addElement('html', '<div id="div_datetime_by_attendance" style="display:block">');
  67. }
  68. if (count($attendance_select) > 1) {
  69. $form->addElement('select', 'attendance_select', get_lang('Attendances'), $attendance_select, array('id' => 'id_attendance_select', 'onchange' => 'datetime_by_attendance(this.value)'));
  70. } else {
  71. $form->addElement('label', get_lang('Attendances'), '<strong><em>'.get_lang('ThereAreNoAttendancesInsideCourse').'</em></strong>');
  72. }
  73. $form->addElement('html', '<div id="div_datetime_attendance">');
  74. if (!empty($calendar_select)) {
  75. $form->addElement('select', 'start_date_by_attendance', get_lang('StartDate'), $calendar_select, array('id'=>'start_date_select_calendar'));
  76. }
  77. $form->addElement('html', '</div>');
  78. $form->addElement('html', '</div>');
  79. $form->addText(
  80. 'duration_in_hours',
  81. get_lang('DurationInHours'),
  82. false,
  83. array(
  84. 'size' => '3',
  85. 'id' => 'duration_in_hours_element',
  86. 'autofocus' => 'autofocus',
  87. )
  88. );
  89. $form->addHtmlEditor(
  90. 'content',
  91. get_lang('Content'),
  92. false,
  93. false,
  94. array(
  95. 'ToolbarStartExpanded' => 'false',
  96. 'ToolbarSet' => 'TrainingDescription',
  97. 'Height' => '150',
  98. )
  99. );
  100. if ($action == 'thematic_advance_add') {
  101. $form->addButtonSave(get_lang('Save'));
  102. } else {
  103. $form->addButtonUpdate(get_lang('Save'));
  104. }
  105. $attendance_select_item_id = null;
  106. if (count($attendance_select) > 1) {
  107. $i = 1;
  108. foreach ($attendance_select as $key => $attendance_select_item) {
  109. if ($i == 2) {
  110. $attendance_select_item_id = $key;
  111. break;
  112. }
  113. $i++;
  114. }
  115. if (!empty($attendance_select_item_id)) {
  116. $default['attendance_select'] = $attendance_select_item_id;
  117. if ($thematic_advance_id) {
  118. echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", "'.$thematic_advance_id.'"); </script>';
  119. } else {
  120. echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", 0); </script>';
  121. }
  122. }
  123. }
  124. $default['start_date_type'] = 1;
  125. $default['custom_start_date'] = date('Y-m-d H:i:s', api_strtotime(api_get_local_time()));
  126. $default['duration_in_hours'] = 1;
  127. if (!empty($thematic_advance_data)) {
  128. // set default values
  129. $default['content'] = isset($thematic_advance_data['content']) ? $thematic_advance_data['content'] : null;
  130. $default['duration_in_hours'] = isset($thematic_advance_data['duration']) ? $thematic_advance_data['duration'] : null;
  131. if (empty($thematic_advance_data['attendance_id'])) {
  132. $default['start_date_type'] = 2;
  133. $default['custom_start_date'] = null;
  134. if (isset($thematic_advance_data['start_date'])) {
  135. $default['custom_start_date'] = date(
  136. 'Y-m-d H:i:s',
  137. api_strtotime(api_get_local_time($thematic_advance_data['start_date']))
  138. );
  139. }
  140. } else {
  141. $default['start_date_type'] = 1;
  142. if (!empty($thematic_advance_data['start_date'])) {
  143. $default['start_date_by_attendance'] = api_get_local_time($thematic_advance_data['start_date']);
  144. }
  145. $default['attendance_select'] = $thematic_advance_data['attendance_id'];
  146. }
  147. }
  148. $form->setDefaults($default);
  149. $form->display();
  150. } else if ($action == 'thematic_advance_list') {
  151. // thematic advance list
  152. echo '<div class="actions">';
  153. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_details">'.
  154. Display::return_icon('back.png', get_lang("BackTo"),'',ICON_SIZE_MEDIUM).'</a>';
  155. if (api_is_allowed_to_edit(false, true)) {
  156. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_advance_add&amp;thematic_id='.$thematic_id.'"> '.
  157. Display::return_icon('add.png', get_lang('NewThematicAdvance'),'',ICON_SIZE_MEDIUM).'</a>';
  158. }
  159. echo '</div>';
  160. $table = new SortableTable(
  161. 'thematic_advance_list',
  162. array('Thematic', 'get_number_of_thematic_advances'),
  163. array('Thematic', 'get_thematic_advance_data')
  164. );
  165. //$table->set_additional_parameters($parameters);
  166. $table->set_header(0, '', false, array('style'=>'width:20px;'));
  167. $table->set_header(1, get_lang('StartDate'), false);
  168. $table->set_header(2, get_lang('DurationInHours'), false, array('style'=>'width:80px;'));
  169. $table->set_header(3, get_lang('Content'), false);
  170. if (api_is_allowed_to_edit(null, true)) {
  171. $table->set_header(
  172. 4,
  173. get_lang('Actions'),
  174. false,
  175. array('style' => 'text-align:center')
  176. );
  177. }
  178. $table->display();
  179. }