| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | if (!defined('DEBUG_MODE')) { die(); } |
| 10: | |
| 11: | require_once APP_PATH.'modules/calendar/hm-calendar.php'; |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | class Hm_Handler_vcalendar_check extends Hm_Handler_Module { |
| 17: | public function process() { |
| 18: | $struct = $this->get('msg_struct', array()); |
| 19: | if (count($struct) > 0 && class_exists('Hm_IMAP')) { |
| 20: | $imap = new Hm_IMAP(); |
| 21: | $imap->struct_object = new Hm_IMAP_Struct(array(), $imap); |
| 22: | $cal_struct = $imap->search_bodystructure($struct, array('subtype' => 'calendar')); |
| 23: | if (is_array($cal_struct) && count($cal_struct) > 0) { |
| 24: | $this->out('imap_calendar_struct', $cal_struct); |
| 25: | } |
| 26: | } |
| 27: | } |
| 28: | } |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | class Hm_Handler_process_delete_event extends Hm_Handler_Module { |
| 34: | public function process() { |
| 35: | list($success, $form) = $this->process_form(array('delete_id')); |
| 36: | if ($success) { |
| 37: | $cal_events = $this->get('cal_events'); |
| 38: | if (is_object($cal_events)) { |
| 39: | if ($cal_events->delete($form['delete_id'])) { |
| 40: | Hm_Msgs::add('Event Deleted'); |
| 41: | $this->session->record_unsaved('Calendar updated'); |
| 42: | $this->user_config->set('calendar_events', $cal_events->dump()); |
| 43: | } |
| 44: | } |
| 45: | } |
| 46: | } |
| 47: | } |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | class Hm_Handler_process_add_event extends Hm_Handler_Module { |
| 53: | public function process() { |
| 54: | list($success, $form) = $this->process_form(array('event_title', |
| 55: | 'event_date', 'event_time', 'event_repeat')); |
| 56: | if ($success) { |
| 57: | $ts = strtotime(sprintf('%s %s', $form['event_date'], $form['event_time'])); |
| 58: | if ($ts) { |
| 59: | $repeat = ''; |
| 60: | if (in_array($form['event_repeat'], array('day', 'week', 'month', 'year'), true)) { |
| 61: | $repeat = $form['event_repeat']; |
| 62: | } |
| 63: | $detail = ''; |
| 64: | if (array_key_exists('event_detail', $this->request->post)) { |
| 65: | $detail = $this->request->post['event_detail']; |
| 66: | } |
| 67: | $cal_events = $this->get('cal_events'); |
| 68: | if (is_object($cal_events)) { |
| 69: | if ($cal_events->add(array( |
| 70: | 'title' => html_entity_decode($form['event_title'], ENT_QUOTES), |
| 71: | 'description' => html_entity_decode($detail, ENT_QUOTES), |
| 72: | 'date' => $ts, |
| 73: | 'repeat_interval' => $repeat |
| 74: | ))) { |
| 75: | Hm_Msgs::add('Event Created'); |
| 76: | $this->session->record_unsaved('Calendar updated'); |
| 77: | $this->user_config->set('calendar_events', $cal_events->dump()); |
| 78: | } |
| 79: | } |
| 80: | } |
| 81: | } |
| 82: | } |
| 83: | } |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | class Hm_Handler_get_calendar_date extends Hm_Handler_Module { |
| 89: | public function process() { |
| 90: | $date = date('r'); |
| 91: | if (array_key_exists('date', $this->request->get)) { |
| 92: | if (strtotime($this->request->get['date']) !== false) { |
| 93: | $date = $this->request->get['date']; |
| 94: | } |
| 95: | } |
| 96: | if (array_key_exists('view', $this->request->get)) { |
| 97: | if (in_array($this->request->get['view'], array('month', 'year', 'week'), true)) { |
| 98: | $this->out('calendar_view', $this->request->get['view']); |
| 99: | } |
| 100: | } |
| 101: | if (array_key_exists('action', $this->request->get)) { |
| 102: | if ($this->request->get['action'] == 'add') { |
| 103: | $this->out('cal_action', 'add'); |
| 104: | } |
| 105: | } |
| 106: | $cal_events = new Hm_Cal_Event_Store(); |
| 107: | $events = $this->user_config->get('calendar_events', array()); |
| 108: | if (count($events) > 0) { |
| 109: | $cal_events->load($events); |
| 110: | } |
| 111: | $this->out('cal_events', $cal_events); |
| 112: | $this->out('calendar_date', $date); |
| 113: | } |
| 114: | } |
| 115: | |
| 116: | |
| 117: | |
| 118: | |
| 119: | class Hm_Output_vcalendar_add_output extends Hm_Output_Module { |
| 120: | protected function output() { |
| 121: | if ($this->get('imap_calendar_struct')) { |
| 122: | $link = '<a class="add_vcal float-end mt-2 pe-4" href="">Add to calendar</a>'; |
| 123: | $this->concat('msg_headers', $link); |
| 124: | } |
| 125: | } |
| 126: | } |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: | class Hm_Output_calendar_page_link extends Hm_Output_Module { |
| 132: | protected function output() { |
| 133: | $res = '<li class="menu_calendar"><a class="unread_link" href="?page=calendar">'; |
| 134: | if (!$this->get('hide_folder_icons')) { |
| 135: | $res .= '<i class="bi bi-calendar-week-fill menu-icon"></i>'; |
| 136: | } |
| 137: | $res .= '<span class="nav-label">'. $this->trans('Calendar').'</span></a></li>'; |
| 138: | if ($this->format == 'HTML5') { |
| 139: | return $res; |
| 140: | } |
| 141: | $this->concat('formatted_folder_list', $res); |
| 142: | } |
| 143: | } |
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: | class Hm_Output_add_cal_event_form extends Hm_Output_Module { |
| 149: | protected function output() { |
| 150: | $repeat_opts = array( |
| 151: | 'none' => $this->trans('None'), |
| 152: | 'day' => $this->trans('Daily'), |
| 153: | 'week' => $this->trans('Weekly'), |
| 154: | 'month' => $this->trans('Monthly'), |
| 155: | 'year' => $this->trans('Yearly') |
| 156: | ); |
| 157: | if ($this->get('cal_action') == 'add') { |
| 158: | $res = '<div class="calendar p-0"> |
| 159: | <div class="content_title px-3">'.$this->trans('Add an Event').'</div> |
| 160: | <div class="px-4 mt-5"> |
| 161: | <form method="post"> |
| 162: | <input type="hidden" name="hm_page_key" value="'.$this->html_safe(Hm_Request_Key::generate()).'" /> |
| 163: | |
| 164: | <div class="mb-3 row"> |
| 165: | <label for="event_title" class="col-md-2 col-form-label">'.$this->trans('Title').'</label> |
| 166: | <div class="col-md-10"> |
| 167: | <input required type="text" class="form-control" id="event_title" name="event_title"> |
| 168: | </div> |
| 169: | </div> |
| 170: | |
| 171: | <div class="mb-3 row"> |
| 172: | <label for="event_detail" class="col-md-2 col-form-label">'.$this->trans('Detail').'</label> |
| 173: | <div class="col-md-10"> |
| 174: | <textarea class="form-control" id="event_detail" name="event_detail"></textarea> |
| 175: | </div> |
| 176: | </div> |
| 177: | |
| 178: | <div class="mb-3 row"> |
| 179: | <label for="event_date" class="col-md-2 col-form-label">'.$this->trans('Date').'</label> |
| 180: | <div class="col-md-5"> |
| 181: | <input required type="date" class="form-control" id="event_date" name="event_date" placeholder="MM/DD/YYYY"> |
| 182: | </div> |
| 183: | </div> |
| 184: | |
| 185: | <div class="mb-3 row"> |
| 186: | <label for="event_time" class="col-md-2 col-form-label">'.$this->trans('Time').'</label> |
| 187: | <div class="col-md-5"> |
| 188: | <input required type="time" class="form-control" id="event_time" name="event_time" placeholder="HH:MM"> |
| 189: | </div> |
| 190: | </div> |
| 191: | |
| 192: | <div class="mb-3 row"> |
| 193: | <label for="event_repeat" class="col-md-2 col-form-label">'.$this->trans('Repeat').'</label> |
| 194: | <div class="col-md-5"> |
| 195: | <select class="form-select" id="event_repeat" name="event_repeat">'; |
| 196: | foreach ($repeat_opts as $val => $name) { |
| 197: | $res .= '<option value="'.$val.'">'.$name.'</option>'; |
| 198: | } |
| 199: | $res .= '</select> |
| 200: | </div> |
| 201: | </div> |
| 202: | |
| 203: | <div class="mb-3 row"> |
| 204: | <div class="col-md-2"></div> |
| 205: | <div class="col-md-10"> |
| 206: | <button type="submit" class="btn btn-primary">'.$this->trans('Create').'</button> |
| 207: | </div> |
| 208: | </div> |
| 209: | </form> |
| 210: | </div> |
| 211: | </div>'; |
| 212: | |
| 213: | return $res; |
| 214: | |
| 215: | } |
| 216: | } |
| 217: | } |
| 218: | |
| 219: | |
| 220: | |
| 221: | |
| 222: | class Hm_Output_calendar_content extends Hm_Output_Module { |
| 223: | protected function output() { |
| 224: | if (!$this->get('cal_action')) { |
| 225: | $cal_events = $this->get('cal_events'); |
| 226: | $date = $this->get('calendar_date', date('r')); |
| 227: | $view = $this->get('calendar_view', 'month'); |
| 228: | $cal = new Hm_Cal_Data(); |
| 229: | $data = $cal->output($date, $view); |
| 230: | $bounds = get_date_bounds($data, $view); |
| 231: | $events = $cal_events->in_date_range($bounds[0], $bounds[1]); |
| 232: | $out = new Hm_Cal_Output($this, $events); |
| 233: | $out = $out->output($data, $date, $view); |
| 234: | return '<div class="calendar p-0"><div class="content_title d-flex justify-content-between px-3"><span class="calendar_content_title">'.$this->trans('Calendar').'</span>'. |
| 235: | '<a href="?page=calendar&action=add" title="'.$this->trans('Add Event').'" class="btn btn-light btn-sm">'. |
| 236: | '<i class="bi bi-plus-circle me-2"></i> '.$this->trans('Add Event').'</a></div>'. |
| 237: | $out.'</div>'; |
| 238: | } |
| 239: | } |
| 240: | } |
| 241: | |
| 242: | if (!hm_exists('get_date_bounds')) { |
| 243: | function get_date_bounds($data, $view) { |
| 244: | if ($view == 'week') { |
| 245: | $start = $data[0]; |
| 246: | $end = array_pop($data); |
| 247: | } |
| 248: | elseif ($view == 'month') { |
| 249: | $start = $data[0][0]; |
| 250: | $last_week = array_pop($data); |
| 251: | $end = array_pop($last_week); |
| 252: | } |
| 253: | elseif ($view == 'year') { |
| 254: | $start = $data[1][0][0]; |
| 255: | $last_month = array_pop($data); |
| 256: | $last_week = array_pop($last_month); |
| 257: | $end = array_pop($last_week); |
| 258: | } |
| 259: | return array($start, $end); |
| 260: | }} |
| 261: | |