attendance_calendar.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for attendance calendar (list, edit, add).
  5. *
  6. * @author Christian Fasanando <christian1827@gmail.com>
  7. *
  8. * @package chamilo.attendance
  9. */
  10. // protect a course script
  11. api_protect_course_script(true);
  12. if (!$is_locked_attendance || api_is_platform_admin()) {
  13. echo '<div class="actions">';
  14. if ($action == 'calendar_add') {
  15. echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.'">'.
  16. Display::return_icon('back.png', get_lang('AttendanceCalendar'), '', ICON_SIZE_MEDIUM).'</a>';
  17. } else {
  18. echo '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.'">'.
  19. 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.'">'.
  22. Display::return_icon('add.png', get_lang('AddDateAndTime'), '', ICON_SIZE_MEDIUM).'</a>';
  23. 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.'">'.
  24. Display::return_icon('clean.png', get_lang('CleanCalendar'), '', ICON_SIZE_MEDIUM).'</a>';
  25. }
  26. }
  27. echo '</div>';
  28. }
  29. $message_information = get_lang('AttendanceCalendarDescription');
  30. if (!empty($message_information)) {
  31. $message = '<strong>'.get_lang('Information').'</strong><br />';
  32. $message .= $message_information;
  33. echo Display::return_message($message, 'normal', false);
  34. }
  35. if (isset($error_repeat_date) && $error_repeat_date) {
  36. $message = get_lang('EndDateMustBeMoreThanStartDate');
  37. echo Display::return_message($message, 'error', false);
  38. }
  39. if (isset($error_checkdate) && $error_checkdate) {
  40. $message = get_lang('InvalidDate');
  41. echo Display::return_message($message, 'error', false);
  42. }
  43. if (isset($action) && $action == 'calendar_add') {
  44. $groupList = GroupManager::get_group_list(null, null, 1);
  45. $groupIdList = ['--'];
  46. foreach ($groupList as $group) {
  47. $groupIdList[$group['id']] = $group['name'];
  48. }
  49. // calendar add form
  50. $form = new FormValidator(
  51. 'attendance_calendar_add',
  52. 'POST',
  53. 'index.php?action=calendar_add&attendance_id='.$attendance_id.'&'.api_get_cidreq(),
  54. ''
  55. );
  56. $form->addElement('header', get_lang('AddADateTime'));
  57. $form->addDateTimePicker(
  58. 'date_time',
  59. [get_lang('StartDate')],
  60. ['id' => 'date_time']
  61. );
  62. $defaults['date_time'] = date('Y-m-d H:i', api_strtotime(api_get_local_time()));
  63. $form->addElement(
  64. 'checkbox',
  65. 'repeat',
  66. null,
  67. get_lang('RepeatDate'),
  68. [
  69. 'onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}",
  70. ]
  71. );
  72. $defaults['repeat'] = isset($repeat) ? $repeat : null;
  73. if ($defaults['repeat']) {
  74. $form->addElement('html', '<div id="repeat-date-attendance" style="display:block">');
  75. } else {
  76. $form->addElement('html', '<div id="repeat-date-attendance" style="display:none">');
  77. }
  78. $a_repeat_type = [
  79. 'daily' => get_lang('RepeatDaily'),
  80. 'weekly' => get_lang('RepeatWeekly'),
  81. 'monthlyByDate' => get_lang('RepeatMonthlyByDate'),
  82. ];
  83. $form->addElement('select', 'repeat_type', get_lang('RepeatType'), $a_repeat_type);
  84. $form->addElement(
  85. 'date_picker',
  86. 'end_date_time',
  87. get_lang('RepeatEnd'),
  88. ['form_name' => 'attendance_calendar_add']
  89. );
  90. $defaults['end_date_time'] = date('Y-m-d');
  91. $form->addElement('html', '</div>');
  92. $defaults['repeat_type'] = 'weekly';
  93. $form->addSelect('groups', get_lang('Group'), $groupIdList);
  94. $form->addButtonCreate(get_lang('Save'));
  95. $form->setDefaults($defaults);
  96. $form->display();
  97. } else {
  98. // Calendar list
  99. $groupList = GroupManager::get_group_list();
  100. $groupIdList = ['--'];
  101. foreach ($groupList as $group) {
  102. $groupIdList[$group['id']] = $group['name'];
  103. }
  104. echo Display::page_subheader(get_lang('CalendarList'));
  105. echo '<ul class="list-group">';
  106. if (!empty($attendance_calendar)) {
  107. foreach ($attendance_calendar as $calendar) {
  108. echo '<li class="list-group-item">';
  109. if ((isset($action) && $action === 'calendar_edit') &&
  110. (isset($calendar_id) && $calendar_id == $calendar['id'])
  111. ) {
  112. // calendar edit form
  113. echo '<div class="attendance-calendar-edit">';
  114. $form = new FormValidator(
  115. 'attendance_calendar_edit',
  116. 'POST',
  117. 'index.php?action=calendar_edit&attendance_id='.$attendance_id.'&calendar_id='.$calendar_id.'&'.api_get_cidreq(),
  118. ''
  119. );
  120. $form->addDateTimePicker(
  121. 'date_time',
  122. [get_lang('Date')],
  123. ['form_name' => 'attendance_calendar_edit'],
  124. 5
  125. );
  126. $defaults['date_time'] = $calendar['date_time'];
  127. $form->addButtonSave(get_lang('Save'));
  128. $form->addButtonCancel(get_lang('Cancel'), 'cancel');
  129. $form->setDefaults($defaults);
  130. $form->display();
  131. echo '</div>';
  132. } else {
  133. echo Display::return_icon(
  134. 'lp_calendar_event.png',
  135. get_lang('DateTime'),
  136. null,
  137. ICON_SIZE_MEDIUM
  138. ).' '.
  139. substr(
  140. $calendar['date_time'],
  141. 0,
  142. strlen($calendar['date_time']) - 3
  143. ).
  144. '&nbsp;';
  145. if (isset($calendar['groups']) && !empty($calendar['groups'])) {
  146. foreach ($calendar['groups'] as $group) {
  147. echo '&nbsp;'.Display::label($groupIdList[$group['group_id']]);
  148. }
  149. }
  150. if (!$is_locked_attendance || api_is_platform_admin()) {
  151. if (api_is_allowed_to_edit()) {
  152. echo '<div class="pull-right">';
  153. echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_edit&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.'">'.
  154. Display::return_icon('edit.png', get_lang('Edit'), ['style' => 'vertical-align:middle'], ICON_SIZE_SMALL).'</a>&nbsp;';
  155. echo '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=calendar_delete&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.'">'.
  156. Display::return_icon('delete.png', get_lang('Delete'), ['style' => 'vertical-align:middle'], ICON_SIZE_SMALL).'</a>';
  157. echo '</div>';
  158. }
  159. }
  160. }
  161. echo '</li>';
  162. }
  163. } else {
  164. echo Display::return_message(get_lang('ThereAreNoRegisteredDatetimeYet'), 'warning');
  165. }
  166. echo '</ul>';
  167. }