attendance_calendar.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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('date_time_picker', 'date_time');
  44. $defaults['date_time'] = date('Y-m-d H:i', api_strtotime(api_get_local_time()));
  45. $form->addElement(
  46. 'checkbox',
  47. 'repeat',
  48. null,
  49. get_lang('RepeatDate'),
  50. array(
  51. 'onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}",
  52. )
  53. );
  54. $defaults['repeat'] = $repeat;
  55. if ($repeat) {
  56. $form->addElement('html', '<div id="repeat-date-attendance" style="display:block">');
  57. } else {
  58. $form->addElement('html', '<div id="repeat-date-attendance" style="display:none">');
  59. }
  60. $a_repeat_type = array(
  61. 'daily' => get_lang('RepeatDaily'),
  62. 'weekly' => get_lang('RepeatWeekly'),
  63. 'monthlyByDate' => get_lang('RepeatMonthlyByDate')
  64. );
  65. $form->addElement('select', 'repeat_type', get_lang('RepeatType') , $a_repeat_type);
  66. $form->addElement('date_picker', 'end_date_time', get_lang('RepeatEnd'), array('form_name'=>'attendance_calendar_add'));
  67. $defaults['end_date_time'] = date('Y-m-d');
  68. $form->addElement('html', '</div>');
  69. $defaults['repeat_type'] = 'weekly';
  70. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  71. $form->setDefaults($defaults);
  72. $form->display();
  73. } else {
  74. // calendar list
  75. echo Display::page_subheader(get_lang('CalendarList'));
  76. echo '<div class="attendance-calendar-list">';
  77. if (!empty($attendance_calendar)) {
  78. foreach ($attendance_calendar as $calendar) {
  79. echo '<div class="attendance-calendar-row">';
  80. if ((isset($action) && $action == 'calendar_edit') && (isset($calendar_id) && $calendar_id == $calendar['id'])) {
  81. // calendar edit form
  82. echo '<div class="attendance-calendar-edit">';
  83. $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,'');
  84. $form->addElement('date_time_picker', 'date_time', '', array('form_name'=>'attendance_calendar_edit'), 5);
  85. $defaults['date_time'] = $calendar['date_time'];
  86. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  87. $form->addElement('style_submit_button', 'cancel', get_lang('Cancel'), 'class="cancel"');
  88. $form->setDefaults($defaults);
  89. $form->display();
  90. echo '</div>';
  91. } else {
  92. echo Display::return_icon('lp_calendar_event.png', get_lang('DateTime')).' '.substr($calendar['date_time'], 0, strlen($calendar['date_time'])- 3) .'&nbsp;';
  93. if (!$is_locked_attendance || api_is_platform_admin()) {
  94. echo '<span style="margin-left:20px;">';
  95. 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;';
  96. 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>';
  97. echo '</span>';
  98. }
  99. }
  100. echo '</div>';
  101. }
  102. } else {
  103. echo Display::return_message(get_lang('ThereAreNoRegisteredDatetimeYet'), 'warning');
  104. }
  105. echo '</div>';
  106. }