attendance_calendar.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. Display::display_normal_message($message, false);
  32. }
  33. if (isset($error_repeat_date) && $error_repeat_date) {
  34. $message = get_lang('EndDateMustBeMoreThanStartDate');
  35. Display::display_error_message($message, false);
  36. }
  37. if (isset($error_checkdate) && $error_checkdate) {
  38. $message = get_lang('InvalidDate');
  39. Display::display_error_message($message, 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->addElement('date_time_picker', 'date_time');
  56. $form->addDateTimePicker(
  57. 'date_time',
  58. array(get_lang('StartDate')),
  59. array('id' => 'date_time')
  60. );
  61. $defaults['date_time'] = date('Y-m-d H:i', api_strtotime(api_get_local_time()));
  62. $form->addElement(
  63. 'checkbox',
  64. 'repeat',
  65. null,
  66. get_lang('RepeatDate'),
  67. array(
  68. 'onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}",
  69. )
  70. );
  71. $defaults['repeat'] = isset($repeat) ? $repeat : null;
  72. if ($defaults['repeat']) {
  73. $form->addElement('html', '<div id="repeat-date-attendance" style="display:block">');
  74. } else {
  75. $form->addElement('html', '<div id="repeat-date-attendance" style="display:none">');
  76. }
  77. $a_repeat_type = array(
  78. 'daily' => get_lang('RepeatDaily'),
  79. 'weekly' => get_lang('RepeatWeekly'),
  80. 'monthlyByDate' => get_lang('RepeatMonthlyByDate')
  81. );
  82. $form->addElement('select', 'repeat_type', get_lang('RepeatType') , $a_repeat_type);
  83. $form->addElement(
  84. 'date_picker',
  85. 'end_date_time',
  86. get_lang('RepeatEnd'),
  87. array('form_name'=>'attendance_calendar_add')
  88. );
  89. $defaults['end_date_time'] = date('Y-m-d');
  90. $form->addElement('html', '</div>');
  91. $defaults['repeat_type'] = 'weekly';
  92. $form->addSelect('groups', get_lang('Group'), $groupIdList);
  93. $form->addButtonCreate(get_lang('Save'));
  94. $form->setDefaults($defaults);
  95. $form->display();
  96. } else {
  97. // Calendar list
  98. $groupList = GroupManager::get_group_list();
  99. $groupIdList = array('--');
  100. foreach ($groupList as $group) {
  101. $groupIdList[$group['id']] = $group['name'];
  102. }
  103. echo Display::page_subheader(get_lang('CalendarList'));
  104. echo '<ul class="list-group">';
  105. if (!empty($attendance_calendar)) {
  106. foreach ($attendance_calendar as $calendar) {
  107. echo '<li class="list-group-item">';
  108. if ((isset($action) && $action === 'calendar_edit') &&
  109. (isset($calendar_id) && $calendar_id == $calendar['id'])
  110. ) {
  111. // calendar edit form
  112. echo '<div class="attendance-calendar-edit">';
  113. $form = new FormValidator(
  114. 'attendance_calendar_edit',
  115. 'POST',
  116. 'index.php?action=calendar_edit&attendance_id=' . $attendance_id . '&calendar_id=' . $calendar_id . '&' . api_get_cidreq(),
  117. ''
  118. );
  119. $form->addDateTimePicker(
  120. 'date_time',
  121. array(get_lang('Date')),
  122. array('form_name'=>'attendance_calendar_edit'),
  123. 5
  124. );
  125. $defaults['date_time'] = $calendar['date_time'];
  126. $form->addButtonSave(get_lang('Save'));
  127. $form->addButtonCancel(get_lang('Cancel'), 'cancel');
  128. $form->setDefaults($defaults);
  129. $form->display();
  130. echo '</div>';
  131. } else {
  132. echo Display::return_icon(
  133. 'lp_calendar_event.png',
  134. get_lang('DateTime'),
  135. null,
  136. ICON_SIZE_MEDIUM
  137. ).' '.substr($calendar['date_time'], 0, strlen($calendar['date_time'])- 3) .'&nbsp;';
  138. if (isset($calendar['groups']) && !empty($calendar['groups'])) {
  139. foreach ($calendar['groups'] as $group) {
  140. echo '&nbsp;'.Display::label($groupIdList[$group['group_id']]);
  141. }
  142. }
  143. if (!$is_locked_attendance || api_is_platform_admin()) {
  144. if (api_is_allowed_to_edit()) {
  145. echo '<div class="pull-right">';
  146. echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_edit&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.'">'.
  147. Display::return_icon('edit.png', get_lang('Edit'), array('style'=>'vertical-align:middle'), ICON_SIZE_SMALL).'</a>&nbsp;';
  148. 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.'">'.
  149. Display::return_icon('delete.png', get_lang('Delete'), array('style'=>'vertical-align:middle'), ICON_SIZE_SMALL).'</a>';
  150. echo '</div>';
  151. }
  152. }
  153. }
  154. echo '</li>';
  155. }
  156. } else {
  157. echo Display::return_message(get_lang('ThereAreNoRegisteredDatetimeYet'), 'warning');
  158. }
  159. echo '</ul>';
  160. }