thematic_advance.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. /*if (!$start_date_error && !$duration_error) {
  17. $token = md5(uniqid(rand(),TRUE));
  18. $_SESSION['thematic_advance_token'] = $token;
  19. }*/
  20. // display form
  21. $form = new FormValidator('thematic_advance','POST','index.php?action=thematic_advance_list&thematic_id='.$thematic_id.'&'.api_get_cidreq());
  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('radio', 'start_date_type', null, get_lang('StartDateFromAnAttendance'),'1',array('onclick' => 'check_per_attendance(this)', 'id'=>'from_attendance'));
  33. $radios[] = $form->createElement('radio', 'start_date_type', null, get_lang('StartDateCustom'),'2',array('onclick' => 'check_per_custom_date(this)', 'id'=>'custom_date'));
  34. $form->addGroup($radios, null, get_lang('StartDateOptions'));
  35. if (isset($thematic_advance_data['attendance_id']) &&
  36. $thematic_advance_data['attendance_id'] == 0) {
  37. $form->addElement('html', '<div id="div_custom_datetime" style="display:block">');
  38. } else {
  39. $form->addElement('html', '<div id="div_custom_datetime" style="display:none">');
  40. }
  41. $form->addElement('DatePicker', 'custom_start_date', get_lang('StartDate'));
  42. $form->addElement('html', '</div>');
  43. if (isset($thematic_advance_data['attendance_id']) &&
  44. $thematic_advance_data['attendance_id'] == 0
  45. ) {
  46. $form->addElement('html', '<div id="div_datetime_by_attendance" style="display:none">');
  47. } else {
  48. $form->addElement('html', '<div id="div_datetime_by_attendance" style="display:block">');
  49. }
  50. if (count($attendance_select) > 1) {
  51. $form->addElement('select', 'attendance_select', get_lang('Attendances'), $attendance_select, array('id' => 'id_attendance_select', 'onchange' => 'datetime_by_attendance(this.value)'));
  52. } else {
  53. $form->addElement('label', get_lang('Attendances'), '<strong><em>'.get_lang('ThereAreNoAttendancesInsideCourse').'</em></strong>');
  54. }
  55. $form->addElement('html', '<div id="div_datetime_attendance">');
  56. if (!empty($calendar_select)) {
  57. $form->addElement('select', 'start_date_by_attendance', get_lang('StartDate'), $calendar_select, array('id'=>'start_date_select_calendar'));
  58. }
  59. $form->addElement('html', '</div>');
  60. $form->addElement('html', '</div>');
  61. $form->addText('duration_in_hours', get_lang('DurationInHours'), false, array('size'=>'3','id'=>'duration_in_hours_element', 'autofocus' => 'autofocus'));
  62. $form->addHtmlEditor('content', get_lang('Content'), false, false, array('ToolbarStartExpanded'=>'false', 'ToolbarSet' => 'TrainingDescription', 'Height' => '150'));
  63. if ($action == 'thematic_advance_add') {
  64. $form->addButtonSave(get_lang('Save'));
  65. } else {
  66. $form->addButtonUpdate(get_lang('Save'));
  67. }
  68. //$form->addElement('html', '<a href="#" id="save_button" onclick="save();">Save</a>');
  69. $attendance_select_item_id = null;
  70. if (count($attendance_select) > 1) {
  71. $i = 1;
  72. foreach ($attendance_select as $key => $attendance_select_item) {
  73. if ($i == 2) {
  74. $attendance_select_item_id = $key;
  75. break;
  76. }
  77. $i++;
  78. }
  79. if (!empty($attendance_select_item_id)) {
  80. $default['attendance_select'] = $attendance_select_item_id;
  81. if ($thematic_advance_id) {
  82. echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", "'.$thematic_advance_id.'"); </script>';
  83. } else {
  84. echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", 0); </script>';
  85. }
  86. }
  87. }
  88. $default['start_date_type'] = 1;
  89. $default['custom_start_date'] = date('Y-m-d', api_strtotime(api_get_local_time()));
  90. $default['duration_in_hours'] = 1;
  91. if (!empty($thematic_advance_data)) {
  92. // set default values
  93. $default['content'] = isset($thematic_advance_data['content']) ? $thematic_advance_data['content'] : null;
  94. $default['duration_in_hours'] = isset($thematic_advance_data['duration']) ? $thematic_advance_data['duration'] : null;
  95. if (empty($thematic_advance_data['attendance_id'])) {
  96. $default['start_date_type'] = 2;
  97. $default['custom_start_date'] = null;
  98. if (isset($thematic_advance_data['start_date'])) {
  99. $default['custom_start_date'] = date(
  100. 'Y-m-d',
  101. api_strtotime(api_get_local_time($thematic_advance_data['start_date']))
  102. );
  103. }
  104. } else {
  105. $default['start_date_type'] = 1;
  106. if (!empty($thematic_advance_data['start_date'])) {
  107. $default['start_date_by_attendance'] = api_get_local_time($thematic_advance_data['start_date']);
  108. }
  109. $default['attendance_select'] = $thematic_advance_data['attendance_id'];
  110. }
  111. }
  112. $form->setDefaults($default);
  113. // error messages
  114. $msg_error = '';
  115. /*if ($start_date_error) {
  116. $msg_error .= get_lang('YouMustSelectAtleastAStartDate').'<br />';
  117. }
  118. if ($duration_error) {
  119. $msg_error .= get_lang('DurationInHoursMustBeNumeric');
  120. }*/
  121. if (!empty($msg_error)) {
  122. Display::display_error_message($msg_error,false);
  123. }
  124. $form->display();
  125. } else if ($action == 'thematic_advance_list') {
  126. // thematic advance list
  127. echo '<div class="actions">';
  128. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_details">'.Display::return_icon('back.png', get_lang("BackTo"),'',ICON_SIZE_MEDIUM).'</a>';
  129. if (api_is_allowed_to_edit(false, true)) {
  130. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_advance_add&amp;thematic_id='.$thematic_id.'"> '.Display::return_icon('add.png', get_lang('NewThematicAdvance'),'',ICON_SIZE_MEDIUM).'</a>';
  131. }
  132. echo '</div>';
  133. $table = new SortableTable('thematic_advance_list', array('Thematic', 'get_number_of_thematic_advances'), array('Thematic', 'get_thematic_advance_data'));
  134. //$table->set_additional_parameters($parameters);
  135. $table->set_header(0, '', false, array('style'=>'width:20px;'));
  136. $table->set_header(1, get_lang('StartDate'), false);
  137. $table->set_header(2, get_lang('DurationInHours'), false, array('style'=>'width:80px;'));
  138. $table->set_header(3, get_lang('Content'), false);
  139. if (api_is_allowed_to_edit(null, true)) {
  140. $table->set_header(4, get_lang('Actions'), false,array('style'=>'text-align:center'));
  141. }
  142. $table->display();
  143. }