thematic_advance.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. * @package chamilo.course_progress
  7. */
  8. // protect a course script
  9. api_protect_course_script(true);
  10. if ($action == 'thematic_advance_add' || $action == 'thematic_advance_edit') {
  11. $header_form = get_lang('NewThematicAdvance');
  12. if ($action == 'thematic_advance_edit') {
  13. $header_form = get_lang('EditThematicAdvance');
  14. }
  15. if (!$start_date_error && !$duration_error) {
  16. $token = md5(uniqid(rand(),TRUE));
  17. $_SESSION['thematic_advance_token'] = $token;
  18. }
  19. // display form
  20. $form = new FormValidator('thematic_advance','POST','index.php?action=thematic_advance_list&thematic_id='.$thematic_id.'&'.api_get_cidreq(),'','style="width: 100%;"');
  21. $form->addElement('header', '', $header_form);
  22. $form->addElement('hidden', 'thematic_advance_token',$token);
  23. $form->addElement('hidden', 'action', $action);
  24. if (!empty($thematic_advance_id)) {
  25. $form->addElement('hidden', 'thematic_advance_id',$thematic_advance_id);
  26. }
  27. if (!empty($thematic_id)) {
  28. $form->addElement('hidden', 'thematic_id',$thematic_id);
  29. }
  30. $radios = array();
  31. $radios[] = FormValidator::createElement('radio', 'start_date_type', null, get_lang('StartDateFromAnAttendance'),'1',array('onclick' => 'check_per_attendance(this)', 'id'=>'from_attendance'));
  32. $radios[] = FormValidator::createElement('radio', 'start_date_type', null, get_lang('StartDateCustom'),'2',array('onclick' => 'check_per_custom_date(this)', 'id'=>'custom_date'));
  33. $form->addGroup($radios, null, get_lang('StartDateOptions'));
  34. if (isset($thematic_advance_data['attendance_id']) && $thematic_advance_data['attendance_id'] == 0) {
  35. $form->addElement('html', '<div id="div_custom_datetime" style="display:block">');
  36. } else {
  37. $form->addElement('html', '<div id="div_custom_datetime" style="display:none">');
  38. }
  39. $form->addElement('datepicker', 'custom_start_date', get_lang('StartDate'), array('form_name'=>'thematic_advance'));
  40. $form->addElement('html', '</div>');
  41. if (isset($thematic_advance_data['attendance_id']) && $thematic_advance_data['attendance_id'] == 0) {
  42. $form->addElement('html', '<div id="div_datetime_by_attendance" style="display:none">');
  43. } else {
  44. $form->addElement('html', '<div id="div_datetime_by_attendance" style="display:block">');
  45. }
  46. if (count($attendance_select) > 1) {
  47. $form->addElement('select', 'attendance_select', get_lang('Attendances'), $attendance_select, array('id' => 'id_attendance_select', 'onchange' => 'datetime_by_attendance(this.value)'));
  48. } else {
  49. $form->addElement('html', '<div class="row"><div class="label">'.get_lang('Attendances').'</div><div class="formw"><strong><em>'.get_lang('ThereAreNoAttendancesInsideCourse').'</em></strong></div></div>');
  50. }
  51. $form->addElement('html', '<div id="div_datetime_attendance">');
  52. if (!empty($calendar_select)) {
  53. $form->addElement('select', 'start_date_by_attendance', get_lang('StartDate'), $calendar_select);
  54. }
  55. $form->addElement('html', '</div>');
  56. $form->addElement('html', '</div>');
  57. $form->add_textfield('duration_in_hours', get_lang('DurationInHours'), false, array('size'=>'3'));
  58. $form->add_html_editor('content', get_lang('Content'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '150'));
  59. $form->addElement('html','<div class="clear" style="margin-top:50px;"></div>');
  60. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  61. $default['start_date_type'] = 1;
  62. $default['custom_start_date'] = date('d-F-Y H:i',api_strtotime(api_get_local_time()));
  63. if (!empty($thematic_advance_data)) {
  64. // set default values
  65. $default['content'] = $thematic_advance_data['content'];
  66. $default['duration_in_hours'] = $thematic_advance_data['duration'];
  67. if (empty($thematic_advance_data['attendance_id'])) {
  68. $default['start_date_type'] = 2;
  69. $default['custom_start_date'] = date('d-F-Y H:i', api_strtotime(api_get_local_time($thematic_advance_data['start_date'])));
  70. } else {
  71. $default['start_date_type'] = 1;
  72. if (!empty($thematic_advance_data['start_date'])) {
  73. $default['start_date_by_attendance'] = api_get_local_time($thematic_advance_data['start_date']);
  74. }
  75. $default['attendance_select'] = $thematic_advance_data['attendance_id'];
  76. }
  77. }
  78. $form->setDefaults($default);
  79. // error messages
  80. $msg_error = '';
  81. if ($start_date_error) {
  82. $msg_error .= get_lang('YouMustSelectAtleastAStartDate').'<br />';
  83. }
  84. if ($duration_error) {
  85. $msg_error .= get_lang('DurationInHoursMustBeNumeric');
  86. }
  87. if (!empty($msg_error)) {
  88. Display::display_error_message($msg_error,false);
  89. }
  90. $form->display();
  91. } else if ($action == 'thematic_advance_list') {
  92. if (api_is_allowed_to_edit(null, true)) {
  93. echo '<div class="actions" style="margin-bottom:30px">';
  94. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_add&thematic_id='.$thematic_id.'">'.Display::return_icon('add_calendar_event.png',get_lang('NewThematicAdvance'),'','32').'</a>';
  95. echo '</div>';
  96. }
  97. // thematic advance list
  98. $table = new SortableTable('thematic_advance_list', array('Thematic', 'get_number_of_thematic_advances'), array('Thematic', 'get_thematic_advance_data'));
  99. $table->set_additional_parameters($parameters);
  100. $table->set_header(0, '', false, array('style'=>'width:20px;'));
  101. $table->set_header(1, get_lang('StartDate'), false );
  102. $table->set_header(2, get_lang('DurationInHours'), false, array('style'=>'width:80px;'));
  103. $table->set_header(3, get_lang('Content'), false);
  104. if (api_is_allowed_to_edit(null, true)) {
  105. $table->set_header(4, get_lang('Actions'), false,array('style'=>'text-align:center'));
  106. }
  107. $table->display();
  108. }
  109. ?>