attendance_calendar.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for attendance calendar (list, edit, add)
  5. * @author Christian Fasanando <christian1827@gmail.com>
  6. * @package chamilo.attendance
  7. */
  8. // protect a course script
  9. api_protect_course_script(true);
  10. $param_gradebook = '';
  11. if (isset($_SESSION['gradebook'])) {
  12. $param_gradebook = '&gradebook='.Security::remove_XSS($_SESSION['gradebook']);
  13. }
  14. if (!$is_locked_attendance || api_is_platform_admin()) {
  15. echo '<div class="actions">';
  16. if ($action == 'calendar_add') {
  17. echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('back.png',get_lang('AttendanceCalendar'),'',ICON_SIZE_MEDIUM).'</a>';
  18. } else {
  19. echo '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('back.png',get_lang('AttendanceSheet'),'',ICON_SIZE_MEDIUM).'</a>';
  20. echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_add&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('add.png',get_lang('AddDateAndTime'),'',ICON_SIZE_MEDIUM).'</a>';
  21. echo '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDeleteAllDates').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=calendar_all_delete&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('clean.png',get_lang('CleanCalendar'),'',ICON_SIZE_MEDIUM).'</a>';
  22. }
  23. echo '</div>';
  24. }
  25. $message_information = get_lang('AttendanceCalendarDescription');
  26. if (!empty($message_information)) {
  27. $message = '<strong>'.get_lang('Information').'</strong><br />';
  28. $message .= $message_information;
  29. Display::display_normal_message($message, false);
  30. }
  31. if ($error_repeat_date) {
  32. $message = get_lang('EndDateMustBeMoreThanStartDate');
  33. Display::display_error_message($message, false);
  34. }
  35. if ($error_checkdate) {
  36. $message = get_lang('InvalidDate');
  37. Display::display_error_message($message, false);
  38. }
  39. if (isset($action) && $action == 'calendar_add') {
  40. // calendar add form
  41. $form = new FormValidator('attendance_calendar_add','POST','index.php?action=calendar_add&attendance_id='.$attendance_id.$param_gradebook.'&'.api_get_cidreq(),'');
  42. $form->addElement('header', get_lang('AddADateTime'));
  43. $form->addElement('datepicker', 'date_time', '', array('form_name'=>'attendance_calendar_add'), 5);
  44. $defaults['date_time'] = date('Y-m-d H:i', api_strtotime(api_get_local_time()));
  45. $form->addElement('checkbox', 'repeat', null, get_lang('RepeatDate'), array('onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}",
  46. ));
  47. $defaults['repeat'] = $repeat;
  48. if ($repeat) {
  49. $form->addElement('html', '<div id="repeat-date-attendance" style="display:block">');
  50. } else {
  51. $form->addElement('html', '<div id="repeat-date-attendance" style="display:none">');
  52. }
  53. $a_repeat_type = array('daily'=>get_lang('RepeatDaily'), 'weekly'=>get_lang('RepeatWeekly'), 'monthlyByDate'=>get_lang('RepeatMonthlyByDate'));
  54. $form->addElement('select', 'repeat_type', get_lang('RepeatType') , $a_repeat_type);
  55. $form->addElement('datepickerdate', 'end_date_time', get_lang('RepeatEnd'), array('form_name'=>'attendance_calendar_add'));
  56. $defaults['end_date_time'] = date('Y-m-d 12:00:00');
  57. $form->addElement('html', '</div>');
  58. $defaults['repeat_type'] = 'weekly';
  59. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  60. $form->setDefaults($defaults);
  61. $form->display();
  62. } else {
  63. // calendar list
  64. echo Display::page_subheader(get_lang('CalendarList'));
  65. echo '<div class="attendance-calendar-list">';
  66. if (!empty($attendance_calendar)) {
  67. foreach ($attendance_calendar as $calendar) {
  68. echo '<div class="attendance-calendar-row">';
  69. if ((isset($action) && $action == 'calendar_edit') && (isset($calendar_id) && $calendar_id == $calendar['id'])) {
  70. // calendar edit form
  71. echo '<div class="attendance-calendar-edit">';
  72. $form = new FormValidator('attendance_calendar_edit','POST','index.php?action=calendar_edit&attendance_id='.$attendance_id.'&calendar_id='.$calendar_id.'&'.api_get_cidreq().$param_gradebook,'');
  73. $form->addElement('datepicker', 'date_time', '', array('form_name'=>'attendance_calendar_edit'), 5);
  74. $defaults['date_time'] = $calendar['date_time'];
  75. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  76. $form->addElement('style_submit_button', 'cancel', get_lang('Cancel'), 'class="cancel"');
  77. $form->setDefaults($defaults);
  78. $form->display();
  79. echo '</div>';
  80. } else {
  81. echo Display::return_icon('lp_calendar_event.png', get_lang('DateTime')).' '.substr($calendar['date_time'], 0, strlen($calendar['date_time'])- 3) .'&nbsp;';
  82. if (!$is_locked_attendance || api_is_platform_admin()) {
  83. echo '<span style="margin-left:20px;">';
  84. echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_edit&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('edit.png', get_lang('Edit'), array('style'=>'vertical-align:middle'), ICON_SIZE_SMALL).'</a>&nbsp;';
  85. echo '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().$param_gradebook.'&action=calendar_delete&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.'">'.Display::return_icon('delete.png', get_lang('Delete'), array('style'=>'vertical-align:middle'), ICON_SIZE_SMALL).'</a>';
  86. echo '</span>';
  87. }
  88. }
  89. echo '</div>';
  90. }
  91. } else {
  92. echo Display::return_message(get_lang('ThereAreNoRegisteredDatetimeYet'), 'warning');
  93. }
  94. echo '</div>';
  95. }