thematic_advance.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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(),'','style="width: 100%;"');
  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']) && $thematic_advance_data['attendance_id'] == 0) {
  36. $form->addElement('html', '<div id="div_custom_datetime" style="display:block">');
  37. } else {
  38. $form->addElement('html', '<div id="div_custom_datetime" style="display:none">');
  39. }
  40. $form->addElement('datepicker', 'custom_start_date', get_lang('StartDate'), array('form_name'=>'thematic_advance'));
  41. $form->addElement('html', '</div>');
  42. if (isset($thematic_advance_data['attendance_id']) && $thematic_advance_data['attendance_id'] == 0) {
  43. $form->addElement('html', '<div id="div_datetime_by_attendance" style="display:none">');
  44. } else {
  45. $form->addElement('html', '<div id="div_datetime_by_attendance" style="display:block">');
  46. }
  47. if (count($attendance_select) > 1) {
  48. $form->addElement('select', 'attendance_select', get_lang('Attendances'), $attendance_select, array('id' => 'id_attendance_select', 'onchange' => 'datetime_by_attendance(this.value)'));
  49. } else {
  50. $form->addElement('label', get_lang('Attendances'), '<strong><em>'.get_lang('ThereAreNoAttendancesInsideCourse').'</em></strong>');
  51. }
  52. $form->addElement('html', '<div id="div_datetime_attendance">');
  53. if (!empty($calendar_select)) {
  54. $form->addElement('select', 'start_date_by_attendance', get_lang('StartDate'), $calendar_select, array('id'=>'start_date_select_calendar'));
  55. }
  56. $form->addElement('html', '</div>');
  57. $form->addElement('html', '</div>');
  58. $form->add_textfield('duration_in_hours', get_lang('DurationInHours'), false, array('size'=>'3','id'=>'duration_in_hours_element', 'autofocus' => 'autofocus'));
  59. $form->add_html_editor('content', get_lang('Content'), false, false, array('ToolbarStartExpanded'=>'false', 'ToolbarSet' => 'TrainingDescription', 'Width' => '80%', 'Height' => '150'));
  60. //$form->addElement('textarea', 'content', get_lang('Content'));
  61. if ($action == 'thematic_advance_add') {
  62. $form->addElement('style_submit_button', null, get_lang('Save'), 'id="add_button" class="save"');
  63. } else {
  64. $form->addElement('style_submit_button', null, get_lang('Save'), 'id="update_button" class="save"');
  65. }
  66. //$form->addElement('html', '<a href="#" id="save_button" onclick="save();">Save</a>');
  67. $attendance_select_item_id = null;
  68. if (count($attendance_select) > 1) {
  69. $i = 1;
  70. foreach ($attendance_select as $key => $attendance_select_item) {
  71. if ($i == 2) {
  72. $attendance_select_item_id = $key;
  73. break;
  74. }
  75. $i++;
  76. }
  77. if (!empty($attendance_select_item_id)) {
  78. $default['attendance_select'] = $attendance_select_item_id;
  79. if ($thematic_advance_id) {
  80. echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", "'.$thematic_advance_id.'"); </script>';
  81. } else {
  82. echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", 0); </script>';
  83. }
  84. }
  85. }
  86. $default['start_date_type'] = 1;
  87. $default['custom_start_date'] = date('d-F-Y H:i', api_strtotime(api_get_local_time()));
  88. $default['duration_in_hours'] = 1;
  89. if (!empty($thematic_advance_data)) {
  90. // set default values
  91. $default['content'] = $thematic_advance_data['content'];
  92. $default['duration_in_hours'] = $thematic_advance_data['duration'];
  93. if (empty($thematic_advance_data['attendance_id'])) {
  94. $default['start_date_type'] = 2;
  95. $default['custom_start_date'] = date('d-F-Y H:i', api_strtotime(api_get_local_time($thematic_advance_data['start_date'])));
  96. } else {
  97. $default['start_date_type'] = 1;
  98. if (!empty($thematic_advance_data['start_date'])) {
  99. $default['start_date_by_attendance'] = api_get_local_time($thematic_advance_data['start_date']);
  100. }
  101. $default['attendance_select'] = $thematic_advance_data['attendance_id'];
  102. }
  103. }
  104. $form->setDefaults($default);
  105. // error messages
  106. $msg_error = '';
  107. if ($start_date_error) {
  108. $msg_error .= get_lang('YouMustSelectAtleastAStartDate').'<br />';
  109. }
  110. if ($duration_error) {
  111. $msg_error .= get_lang('DurationInHoursMustBeNumeric');
  112. }
  113. if (!empty($msg_error)) {
  114. Display::display_error_message($msg_error,false);
  115. }
  116. $form->display();
  117. } else if ($action == 'thematic_advance_list') {
  118. // thematic advance list
  119. echo '<div class="actions">';
  120. 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>';
  121. if (api_is_allowed_to_edit(false, true)) {
  122. 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>';
  123. }
  124. echo '</div>';
  125. $table = new SortableTable('thematic_advance_list', array('Thematic', 'get_number_of_thematic_advances'), array('Thematic', 'get_thematic_advance_data'));
  126. $table->set_additional_parameters($parameters);
  127. $table->set_header(0, '', false, array('style'=>'width:20px;'));
  128. $table->set_header(1, get_lang('StartDate'), false );
  129. $table->set_header(2, get_lang('DurationInHours'), false, array('style'=>'width:80px;'));
  130. $table->set_header(3, get_lang('Content'), false);
  131. if (api_is_allowed_to_edit(null, true)) {
  132. $table->set_header(4, get_lang('Actions'), false,array('style'=>'text-align:center'));
  133. }
  134. $table->display();
  135. }