attendance_calendar.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. // protect a course script
  9. api_protect_course_script(true);
  10. if (!$is_locked_attendance || api_is_platform_admin()) {
  11. echo '<div class="actions">';
  12. if ($action == 'calendar_add') {
  13. echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.'">'.
  14. Display::return_icon('back.png', get_lang('Attendance calendar'), '', ICON_SIZE_MEDIUM).'</a>';
  15. } else {
  16. echo '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.'">'.
  17. Display::return_icon('back.png', get_lang('Attendance sheet'), '', ICON_SIZE_MEDIUM).'</a>';
  18. if (api_is_allowed_to_edit()) {
  19. echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_add&attendance_id='.$attendance_id.'">'.
  20. Display::return_icon('add.png', get_lang('Add a date and time'), '', ICON_SIZE_MEDIUM).'</a>';
  21. echo '<a onclick="javascript:if(!confirm(\''.get_lang('Are you sure you want to delete all dates?').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=calendar_all_delete&attendance_id='.$attendance_id.'">'.
  22. Display::return_icon('clean.png', get_lang('Clean the calendar of all lists'), '', ICON_SIZE_MEDIUM).'</a>';
  23. }
  24. }
  25. echo '</div>';
  26. }
  27. $message_information = get_lang('Attendance calendarDescription');
  28. if (!empty($message_information)) {
  29. $message = '<strong>'.get_lang('Information').'</strong><br />';
  30. $message .= $message_information;
  31. echo Display::return_message($message, 'normal', false);
  32. }
  33. if (isset($error_repeat_date) && $error_repeat_date) {
  34. $message = get_lang('End date must be more than the start date');
  35. echo Display::return_message($message, 'error', false);
  36. }
  37. if (isset($error_checkdate) && $error_checkdate) {
  38. $message = get_lang('Invalid date');
  39. echo Display::return_message($message, 'error', false);
  40. }
  41. if (isset($action) && $action == 'calendar_add') {
  42. $groupList = GroupManager::get_group_list(null, null, 1);
  43. $groupIdList = ['--'];
  44. foreach ($groupList as $group) {
  45. $groupIdList[$group['id']] = $group['name'];
  46. }
  47. // calendar add form
  48. $form = new FormValidator(
  49. 'attendance_calendar_add',
  50. 'POST',
  51. 'index.php?action=calendar_add&attendance_id='.$attendance_id.'&'.api_get_cidreq(),
  52. ''
  53. );
  54. $form->addElement('header', get_lang('Add a date time'));
  55. $form->addDateTimePicker(
  56. 'date_time',
  57. [get_lang('Start Date')],
  58. ['id' => 'date_time']
  59. );
  60. $defaults['date_time'] = date('Y-m-d H:i', api_strtotime(api_get_local_time()));
  61. $form->addElement(
  62. 'checkbox',
  63. 'repeat',
  64. null,
  65. get_lang('Repeat date'),
  66. [
  67. 'onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}",
  68. ]
  69. );
  70. $defaults['repeat'] = isset($repeat) ? $repeat : null;
  71. if ($defaults['repeat']) {
  72. $form->addElement('html', '<div id="repeat-date-attendance" style="display:block">');
  73. } else {
  74. $form->addElement('html', '<div id="repeat-date-attendance" style="display:none">');
  75. }
  76. $a_repeat_type = [
  77. 'daily' => get_lang('Daily'),
  78. 'weekly' => get_lang('Weekly'),
  79. 'monthlyByDate' => get_lang('Monthly, by date'),
  80. ];
  81. $form->addElement('select', 'repeat_type', get_lang('Repeat type'), $a_repeat_type);
  82. $form->addElement(
  83. 'date_picker',
  84. 'end_date_time',
  85. get_lang('Repeat end date'),
  86. ['form_name' => 'attendance_calendar_add']
  87. );
  88. $defaults['end_date_time'] = date('Y-m-d');
  89. $form->addElement('html', '</div>');
  90. $defaults['repeat_type'] = 'weekly';
  91. $form->addSelect('groups', get_lang('Group'), $groupIdList);
  92. $form->addButtonCreate(get_lang('Save'));
  93. $form->setDefaults($defaults);
  94. $form->display();
  95. } else {
  96. // Calendar list
  97. $groupList = GroupManager::get_group_list();
  98. $groupIdList = ['--'];
  99. foreach ($groupList as $group) {
  100. $groupIdList[$group['id']] = $group['name'];
  101. }
  102. echo Display::page_subheader(get_lang('Calendar list of attendances'));
  103. echo '<ul class="list-group">';
  104. if (!empty($attendance_calendar)) {
  105. foreach ($attendance_calendar as $calendar) {
  106. echo '<li class="list-group-item">';
  107. if ((isset($action) && $action === 'calendar_edit') &&
  108. (isset($calendar_id) && $calendar_id == $calendar['id'])
  109. ) {
  110. // calendar edit form
  111. echo '<div class="attendance-calendar-edit">';
  112. $form = new FormValidator(
  113. 'attendance_calendar_edit',
  114. 'POST',
  115. 'index.php?action=calendar_edit&attendance_id='.$attendance_id.'&calendar_id='.$calendar_id.'&'.api_get_cidreq(),
  116. ''
  117. );
  118. $form->addDateTimePicker(
  119. 'date_time',
  120. [get_lang('Date')],
  121. ['form_name' => 'attendance_calendar_edit'],
  122. 5
  123. );
  124. $defaults['date_time'] = $calendar['date_time'];
  125. $form->addButtonSave(get_lang('Save'));
  126. $form->addButtonCancel(get_lang('Cancel'), 'cancel');
  127. $form->setDefaults($defaults);
  128. $form->display();
  129. echo '</div>';
  130. } else {
  131. echo Display::return_icon(
  132. 'lp_calendar_event.png',
  133. get_lang('Date DateTime time'),
  134. null,
  135. ICON_SIZE_MEDIUM
  136. ).' '.
  137. substr(
  138. $calendar['date_time'],
  139. 0,
  140. strlen($calendar['date_time']) - 3
  141. ).
  142. '&nbsp;';
  143. if (isset($calendar['groups']) && !empty($calendar['groups'])) {
  144. foreach ($calendar['groups'] as $group) {
  145. echo '&nbsp;'.Display::label($groupIdList[$group['group_id']]);
  146. }
  147. }
  148. if (!$is_locked_attendance || api_is_platform_admin()) {
  149. if (api_is_allowed_to_edit()) {
  150. echo '<div class="pull-right">';
  151. echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_edit&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.'">'.
  152. Display::return_icon('edit.png', get_lang('Edit'), ['style' => 'vertical-align:middle'], ICON_SIZE_SMALL).'</a>&nbsp;';
  153. echo '<a onclick="javascript:if(!confirm(\''.get_lang('Are you sure you want to delete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=calendar_delete&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.'">'.
  154. Display::return_icon('delete.png', get_lang('Delete'), ['style' => 'vertical-align:middle'], ICON_SIZE_SMALL).'</a>';
  155. echo '</div>';
  156. }
  157. }
  158. }
  159. echo '</li>';
  160. }
  161. } else {
  162. echo Display::return_message(get_lang('There is no date/time registered yet'), 'warning');
  163. }
  164. echo '</ul>';
  165. }