attendance_calendar.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. if (api_is_allowed_to_edit()) {
  21. 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>';
  22. 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.'">'.
  23. Display::return_icon('clean.png',get_lang('CleanCalendar'),'',ICON_SIZE_MEDIUM).'</a>';
  24. }
  25. }
  26. echo '</div>';
  27. }
  28. $message_information = get_lang('AttendanceCalendarDescription');
  29. if (!empty($message_information)) {
  30. $message = '<strong>'.get_lang('Information').'</strong><br />';
  31. $message .= $message_information;
  32. Display::display_normal_message($message, false);
  33. }
  34. if (isset($error_repeat_date) && $error_repeat_date) {
  35. $message = get_lang('EndDateMustBeMoreThanStartDate');
  36. Display::display_error_message($message, false);
  37. }
  38. if (isset($error_checkdate) && $error_checkdate) {
  39. $message = get_lang('InvalidDate');
  40. Display::display_error_message($message, false);
  41. }
  42. if (isset($action) && $action == 'calendar_add') {
  43. $groupList = GroupManager::get_group_list(null, null, 1);
  44. $groupIdList = array('--');
  45. foreach ($groupList as $group) {
  46. $groupIdList[$group['id']] = $group['name'];
  47. }
  48. // calendar add form
  49. $form = new FormValidator(
  50. 'attendance_calendar_add',
  51. 'POST',
  52. 'index.php?action=calendar_add&attendance_id=' . $attendance_id . $param_gradebook . '&' . api_get_cidreq(),
  53. ''
  54. );
  55. $form->addElement('header', get_lang('AddADateTime'));
  56. $form->addElement('date_time_picker', 'date_time');
  57. $defaults['date_time'] = date('Y-m-d H:i', api_strtotime(api_get_local_time()));
  58. $form->addElement(
  59. 'checkbox',
  60. 'repeat',
  61. null,
  62. get_lang('RepeatDate'),
  63. array(
  64. 'onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}",
  65. )
  66. );
  67. $defaults['repeat'] = isset($repeat) ? $repeat : null;
  68. if ($defaults['repeat']) {
  69. $form->addElement('html', '<div id="repeat-date-attendance" style="display:block">');
  70. } else {
  71. $form->addElement('html', '<div id="repeat-date-attendance" style="display:none">');
  72. }
  73. $a_repeat_type = array(
  74. 'daily' => get_lang('RepeatDaily'),
  75. 'weekly' => get_lang('RepeatWeekly'),
  76. 'monthlyByDate' => get_lang('RepeatMonthlyByDate')
  77. );
  78. $form->addElement('select', 'repeat_type', get_lang('RepeatType') , $a_repeat_type);
  79. $form->addElement('date_picker', 'end_date_time', get_lang('RepeatEnd'), array('form_name'=>'attendance_calendar_add'));
  80. $defaults['end_date_time'] = date('Y-m-d');
  81. $form->addElement('html', '</div>');
  82. $defaults['repeat_type'] = 'weekly';
  83. $form->addSelect('groups', get_lang('Group'), $groupIdList);
  84. $form->addButtonCreate(get_lang('Save'));
  85. $form->setDefaults($defaults);
  86. $form->display();
  87. } else {
  88. // Calendar list
  89. $groupList = GroupManager::get_group_list();
  90. $groupIdList = array('--');
  91. foreach ($groupList as $group) {
  92. $groupIdList[$group['id']] = $group['name'];
  93. }
  94. echo Display::page_subheader(get_lang('CalendarList'));
  95. echo '<div class="attendance-calendar-list">';
  96. if (!empty($attendance_calendar)) {
  97. foreach ($attendance_calendar as $calendar) {
  98. echo '<div class="attendance-calendar-row">';
  99. if ((isset($action) && $action == 'calendar_edit') &&
  100. (isset($calendar_id) && $calendar_id == $calendar['id'])
  101. ) {
  102. // calendar edit form
  103. echo '<div class="attendance-calendar-edit">';
  104. $form = new FormValidator(
  105. 'attendance_calendar_edit',
  106. 'POST',
  107. 'index.php?action=calendar_edit&attendance_id=' . $attendance_id . '&calendar_id=' . $calendar_id . '&' . api_get_cidreq() . $param_gradebook,
  108. ''
  109. );
  110. $form->addElement('date_time_picker', 'date_time', '', array('form_name'=>'attendance_calendar_edit'), 5);
  111. $defaults['date_time'] = $calendar['date_time'];
  112. $form->addButtonSave(get_lang('Save'));
  113. $form->addButtonCancel(get_lang('Cancel'), 'cancel');
  114. $form->setDefaults($defaults);
  115. $form->display();
  116. echo '</div>';
  117. } else {
  118. echo Display::return_icon(
  119. 'lp_calendar_event.png',
  120. get_lang('DateTime')
  121. ).' '.substr($calendar['date_time'], 0, strlen($calendar['date_time'])- 3) .'&nbsp;';
  122. if (isset($calendar['groups']) && !empty($calendar['groups'])) {
  123. foreach ($calendar['groups'] as $group) {
  124. echo '&nbsp;'.Display::label($groupIdList[$group['group_id']]);
  125. }
  126. }
  127. if (!$is_locked_attendance || api_is_platform_admin()) {
  128. if (api_is_allowed_to_edit()) {
  129. echo '<span style="margin-left:20px;">';
  130. echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_edit&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.$param_gradebook.'">'.
  131. Display::return_icon('edit.png', get_lang('Edit'), array('style'=>'vertical-align:middle'), ICON_SIZE_SMALL).'</a>&nbsp;';
  132. 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.'">'.
  133. Display::return_icon('delete.png', get_lang('Delete'), array('style'=>'vertical-align:middle'), ICON_SIZE_SMALL).'</a>';
  134. echo '</span>';
  135. }
  136. }
  137. }
  138. echo '</div>';
  139. }
  140. } else {
  141. echo Display::return_message(get_lang('ThereAreNoRegisteredDatetimeYet'), 'warning');
  142. }
  143. echo '</div>';
  144. }