attendance_calendar.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. 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('AttendanceCalendar'), '', 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('AttendanceSheet'), '', 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('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.'">'.
  22. Display::return_icon('clean.png', get_lang('CleanCalendar'), '', ICON_SIZE_MEDIUM).'</a>';
  23. }
  24. }
  25. echo '</div>';
  26. }
  27. $message_information = get_lang('AttendanceCalendarDescription');
  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('EndDateMustBeMoreThanStartDate');
  35. echo Display::return_message($message, 'error', false);
  36. }
  37. if (isset($error_checkdate) && $error_checkdate) {
  38. $message = get_lang('InvalidDate');
  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 = array('--');
  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('AddADateTime'));
  55. $form->addDateTimePicker(
  56. 'date_time',
  57. array(get_lang('StartDate')),
  58. array('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('RepeatDate'),
  66. array(
  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 = array(
  77. 'daily' => get_lang('RepeatDaily'),
  78. 'weekly' => get_lang('RepeatWeekly'),
  79. 'monthlyByDate' => get_lang('RepeatMonthlyByDate')
  80. );
  81. $form->addElement('select', 'repeat_type', get_lang('RepeatType'), $a_repeat_type);
  82. $form->addElement(
  83. 'date_picker',
  84. 'end_date_time',
  85. get_lang('RepeatEnd'),
  86. array('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 = array('--');
  99. foreach ($groupList as $group) {
  100. $groupIdList[$group['id']] = $group['name'];
  101. }
  102. echo Display::page_subheader(get_lang('CalendarList'));
  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. array(get_lang('Date')),
  121. array('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('DateTime'),
  134. null,
  135. ICON_SIZE_MEDIUM
  136. ).' '.substr($calendar['date_time'], 0, strlen($calendar['date_time']) - 3).'&nbsp;';
  137. if (isset($calendar['groups']) && !empty($calendar['groups'])) {
  138. foreach ($calendar['groups'] as $group) {
  139. echo '&nbsp;'.Display::label($groupIdList[$group['group_id']]);
  140. }
  141. }
  142. if (!$is_locked_attendance || api_is_platform_admin()) {
  143. if (api_is_allowed_to_edit()) {
  144. echo '<div class="pull-right">';
  145. echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_edit&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.'">'.
  146. Display::return_icon('edit.png', get_lang('Edit'), array('style'=>'vertical-align:middle'), ICON_SIZE_SMALL).'</a>&nbsp;';
  147. 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.'">'.
  148. Display::return_icon('delete.png', get_lang('Delete'), array('style'=>'vertical-align:middle'), ICON_SIZE_SMALL).'</a>';
  149. echo '</div>';
  150. }
  151. }
  152. }
  153. echo '</li>';
  154. }
  155. } else {
  156. echo Display::return_message(get_lang('ThereAreNoRegisteredDatetimeYet'), 'warning');
  157. }
  158. echo '</ul>';
  159. }