thematic_advance.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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'));
  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. if (!empty($thematic_advance_data)) {
  89. // set default values
  90. $default['content'] = $thematic_advance_data['content'];
  91. $default['duration_in_hours'] = $thematic_advance_data['duration'];
  92. if (empty($thematic_advance_data['attendance_id'])) {
  93. $default['start_date_type'] = 2;
  94. $default['custom_start_date'] = date('d-F-Y H:i', api_strtotime(api_get_local_time($thematic_advance_data['start_date'])));
  95. } else {
  96. $default['start_date_type'] = 1;
  97. if (!empty($thematic_advance_data['start_date'])) {
  98. $default['start_date_by_attendance'] = api_get_local_time($thematic_advance_data['start_date']);
  99. }
  100. $default['attendance_select'] = $thematic_advance_data['attendance_id'];
  101. }
  102. }
  103. $form->setDefaults($default);
  104. // error messages
  105. $msg_error = '';
  106. if ($start_date_error) {
  107. $msg_error .= get_lang('YouMustSelectAtleastAStartDate').'<br />';
  108. }
  109. if ($duration_error) {
  110. $msg_error .= get_lang('DurationInHoursMustBeNumeric');
  111. }
  112. if (!empty($msg_error)) {
  113. Display::display_error_message($msg_error,false);
  114. }
  115. $form->display();
  116. } else if ($action == 'thematic_advance_list') {
  117. // thematic advance list
  118. $table = new SortableTable('thematic_advance_list', array('Thematic', 'get_number_of_thematic_advances'), array('Thematic', 'get_thematic_advance_data'));
  119. $table->set_additional_parameters($parameters);
  120. $table->set_header(0, '', false, array('style'=>'width:20px;'));
  121. $table->set_header(1, get_lang('StartDate'), false );
  122. $table->set_header(2, get_lang('DurationInHours'), false, array('style'=>'width:80px;'));
  123. $table->set_header(3, get_lang('Content'), false);
  124. if (api_is_allowed_to_edit(null, true)) {
  125. $table->set_header(4, get_lang('Actions'), false,array('style'=>'text-align:center'));
  126. }
  127. $table->display();
  128. }