-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.php
1939 lines (1681 loc) · 56.7 KB
/
calendar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @package hubzero-cms
* @copyright Copyright (c) 2005-2020 The Regents of the University of California.
* @license http://opensource.org/licenses/MIT MIT
*/
// No direct access
defined('_HZEXEC_') or die();
$pluginDirectory = __DIR__;
require_once "$pluginDirectory/helpers/userLocalizer.php";
/**
* Groups Plugin class for calendar
*/
class plgGroupsCalendar extends \Hubzero\Plugin\Plugin
{
/**
* Affects constructor behavior. If true, language files will be loaded automatically.
*
* @var boolean
*/
protected $_autoloadLanguage = true;
/**
* Loads the plugin language file
*
* @param string $extension The extension for which a language file should be loaded
* @param string $basePath The basepath to use
* @return boolean True, if the file has successfully loaded.
*/
public function loadLanguage($extension = '', $basePath = PATH_APP)
{
if (empty($extension))
{
$extension = 'plg_' . $this->_type . '_' . $this->_name;
}
$group = \Hubzero\User\Group::getInstance(Request::getCmd('cn'));
if ($group && $group->isSuperGroup())
{
$basePath = PATH_APP . DS . 'site' . DS . 'groups' . DS . $group->get('gidNumber');
}
$lang = \App::get('language');
return $lang->load(strtolower($extension), $basePath, null, false, true)
|| $lang->load(strtolower($extension), PATH_APP . DS . 'plugins' . DS . $this->_type . DS . $this->_name, null, false, true)
|| $lang->load(strtolower($extension), PATH_CORE . DS . 'plugins' . DS . $this->_type . DS . $this->_name, null, false, true);
}
/**
* Return the alias and name for this category of content
*
* @return array
*/
public function &onGroupAreas()
{
$area = array(
'name' => 'calendar',
'title' => Lang::txt('PLG_GROUPS_CALENDAR'),
'default_access' => $this->params->get('plugin_access', 'members'),
'display_menu_tab' => $this->params->get('display_tab', 1),
'icon' => 'f073'
);
return $area;
}
/**
* Return data on a group view (this will be some form of HTML)
*
* @param object $group Current group
* @param string $option Name of the component
* @param string $authorized User's authorization level
* @param integer $limit Number of records to pull
* @param integer $limitstart Start of records to pull
* @param string $action Action to perform
* @param array $access What can be accessed
* @param array $areas Active area(s)
* @return array
*/
public function onGroup($group, $option, $authorized, $limit=0, $limitstart=0, $action='', $access, $areas=null)
{
$returnhtml = true;
$active = 'calendar';
// The output array we're returning
$arr = array(
'html' => '',
'metadata' => array()
);
//get this area details
$this_area = $this->onGroupAreas();
// Check if our area is in the array of areas we want to return results for
if (is_array($areas) && $limit)
{
if (!in_array($this_area['name'], $areas))
{
$returnhtml = false;
}
}
//Create user object
$user = User::getInstance();
//get the group members
$members = $group->get('members');
// Set some variables so other functions have access
$this->user = $user;
$this->authorized = $authorized;
$this->members = $members;
$this->group = $group;
$this->option = $option;
$this->action = $action;
$this->access = $access;
$this->event = null;
//if we want to return content
if ($returnhtml)
{
//set group members plugin access level
$group_plugin_acl = $access[$active];
//if were not trying to subscribe
if ($this->action != 'subscribe')
{
//if set to nobody make sure cant access
if ($group_plugin_acl == 'nobody')
{
$arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_OFF', ucfirst($active)) . '</p>';
return $arr;
}
//check if guest and force login if plugin access is registered or members
if (User::isGuest()
&& ($group_plugin_acl == 'registered' || $group_plugin_acl == 'members'))
{
$url = Route::url('index.php?option=com_groups&cn='.$group->get('cn').'&active='.$active, false, true);
App::redirect(
Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url)),
Lang::txt('GROUPS_PLUGIN_REGISTERED', ucfirst($active)),
'warning'
);
return;
}
//check to see if user is member and plugin access requires members
if (!in_array($user->get('id'), $members) && $group_plugin_acl == 'members')
{
$arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_REQUIRES_MEMBER', ucfirst($active)) . '</p>';
return $arr;
}
}
// load events lang file
Lang::load('com_events') ||
Lang::load('com_events', Component::path('com_events') . DS . 'site');
//push styles to the view
$this->css('calendar');
$this->js('calendar');
//get the request vars
$this->month = Request::getInt('month', Date::of()->format("m"), 'get');
$this->month = (strlen($this->month) == 1) ? '0' . $this->month : $this->month;
$this->year = Request::getInt('year', Date::of()->format("Y"), 'get');
$this->calendar = Request::getInt('calendar', 0, 'get');
// make sure month is always two digets
if (strlen($this->month) == 1)
{
$this->month = 0 . $this->month;
}
//set vars for reuse purposes
$this->database = App::get('db');
//include needed event libs
require_once __DIR__ . '/helper.php';
require_once Component::path('com_events') . DS . 'models' . DS . 'event.php';
require_once Component::path('com_events') . DS . 'models' . DS . 'calendar' . DS . 'archive.php';
require_once Component::path('com_events') . DS . 'tables' . DS . 'respondent.php';
require_once Component::path('com_events') . DS . 'helpers' . DS . 'html.php';
//run task based on action
switch ($this->action)
{
//managing events
case 'add':
$arr['html'] = $this->add();
break;
case 'edit':
$arr['html'] = $this->edit();
break;
case 'save':
$arr['html'] = $this->save();
break;
case 'delete':
$arr['html'] = $this->delete();
break;
case 'details':
$arr['html'] = $this->details();
break;
case 'export':
$arr['html'] = $this->export();
break;
case 'subscribe':
$arr['html'] = $this->subscribe();
break;
case 'import':
$arr['html'] = $this->import();
break;
//event registration
case 'register':
$arr['html'] = $this->register();
break;
case 'doregister':
$arr['html'] = $this->doRegister();
break;
case 'registrants':
$arr['html'] = $this->registrants();
break;
case 'download':
$arr['html'] = $this->download();
break;
//event calendars
case 'calendars':
$arr['html'] = $this->calendars();
break;
case 'addcalendar':
$arr['html'] = $this->addCalendar();
break;
case 'editcalendar':
$arr['html'] = $this->editCalendar();
break;
case 'savecalendar':
$arr['html'] = $this->saveCalendar();
break;
case 'deletecalendar':
$arr['html'] = $this->deleteCalendar();
break;
case 'refreshcalendar':
$arr['html'] = $this->refreshCalendar();
break;
case 'refreshcalendars':
$this->refreshCalendars();
break;
case 'eventsources':
$this->eventSources();
break;
case 'events':
$this->events();
break;
default:
$arr['html'] = $this->display();
break;
}
}
//get count of all future group events
$arr['metadata']['count'] = $this->_getAllFutureEvents();
//get the upcoming events
$upcoming_events = $this->_getFutureEventsThisMonth();
if ($upcoming_events > 0)
{
$title = $this->group->get('description')." has {$upcoming_events} events this month.";
$link = Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=calendar');
$arr['metadata']['alert'] = "<a class=\"alrt\" href=\"{$link}\"><span><h5>Calendar Alert</h5>{$title}</span></a>";
}
// Return the output
return $arr;
}
/**
* Display a calendar
*
* @return string
*/
private function display()
{
$view = $this->view('display', 'calendar');
//push the calendar content to view
$view->month = $this->month;
$view->year = $this->year;
$view->calendar = $this->calendar;
$view->user = $this->user;
$view->authorized = $this->authorized;
$view->members = $this->members;
$view->option = $this->option;
$view->group = $this->group;
$view->params = $this->params;
//get calendars
$eventsCalendarArchive = \Components\Events\Models\Calendar\Archive::getInstance();
$view->calendars = $eventsCalendarArchive->calendars('list', array(
'scope' => 'group',
'scope_id' => $this->group->get('gidNumber')
));
// event calendar model
$eventsCalendar = \Components\Events\Models\Calendar::getInstance();
//define our filters
$view->filters = array(
'scope' => 'group',
'scope_id' => $this->group->get('gidNumber'),
'orderby' => 'publish_up DESC'
);
// get events count
$view->eventsCount = $eventsCalendar->events('count', $view->filters);
// get events for no js
$view->filters['limit'] = Request::getInt('limit', Config::get('list_limit'));
$view->filters['start'] = Request::getInt('limitstart', 0);
$view->events = $eventsCalendar->events('list', $view->filters);
// add hub fancyselect lib
$this->js('jquery.fancyselect.min', 'system');
$this->css('jquery.fancyselect.css', 'system');
// add full calendar lib
$this->js('moment.min', 'system');
$this->js('jquery.fullcalendar.min', 'system');
$this->css('jquery.fullcalendar.css', 'system');
$this->css('jquery.fullcalendar.print.css', 'system', array('media' => 'print'));
foreach ($this->getErrors() as $error)
{
$view->setError($error);
}
return $view->loadTemplate();
}
/**
* Output event sources. For caledar
*
* @return string
*/
private function eventSources()
{
// array to hold sources
$sources = array();
// get calendars
$eventsCalendarArchive = \Components\Events\Models\Calendar\Archive::getInstance();
$calendars = $eventsCalendarArchive->calendars('list', array(
'scope' => 'group',
'scope_id' => $this->group->get('gidNumber')
));
// add each calendar to the sources
foreach ($calendars as $calendar)
{
$source = new stdClass;
$source->title = $calendar->get('title');
$source->url = Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=calendar&action=events&calendar_id=' . $calendar->get('id'));
$source->className = ($calendar->get('color')) ? 'fc-event-' . $calendar->get('color') : 'fc-event-default';
array_push($sources, $source);
}
// add uncategorized source
$source = new stdClass;
$source->title = 'Uncategorized';
$source->url = Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=calendar&action=events&calendar_id=0');
$source->className = 'fc-event-default';
array_push($sources, $source);
// output sources
echo json_encode($sources);
exit();
}
/**
* Returns events for a source.
* Ajax only and returns json.
*
* @return string
*/
public function events()
{
// array to hold events
$events = array();
// get request params
$start = Request::getString('start');
$end = Request::getString('end');
$calendarId = Request::getInt('calendar_id', 0);
if ($start && !preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/', $start))
{
$start = '';
}
if ($end && !preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/', $end))
{
$end = '';
}
// format date/times
$start = Date::of($start . ' 00:00:00');
$end = Date::of($end . ' 00:00:00');
$end->modify('-1 second');
$userLocalizer = new UserLocalizer();
// get calendar events
$eventsCalendar = \Components\Events\Models\Calendar::getInstance();
$rawEvents = $eventsCalendar->events('list', array(
'scope' => 'group',
'scope_id' => $this->group->get('gidNumber'),
'calendar_id' => $calendarId,
'state' => array(1),
'publish_up' => $start->format('Y-m-d H:i:s'),
'publish_down' => $end->format('Y-m-d H:i:s'),
'non_repeating' => true
));
// get repeating events
$rawEventsRepeating = $eventsCalendar->events('repeating', array(
'scope' => 'group',
'scope_id' => $this->group->get('gidNumber'),
'calendar_id' => $calendarId,
'state' => array(1),
'publish_up' => $start->format('Y-m-d H:i:s'),
'publish_down' => $end->format('Y-m-d H:i:s')
));
// merge events with repeating events
$rawEvents = $rawEvents->merge($rawEventsRepeating);
$timezone = $userLocalizer->getTimezone();
// loop through each event to return it
foreach ($rawEvents as $rawEvent)
{
$up = Date::of($rawEvent->get('publish_up'));
$down = Date::of($rawEvent->get('publish_down'));
$params = new \Hubzero\Config\Registry($rawEvent->get('params'));
$ignoreDst = false;
$ignoreDst = $params->get('ignore_dst') == 1 ? true : false;
$timeFormat = 'Y-m-d\TH:i:sO';
$event = new stdClass;
$event->id = $rawEvent->get('id');
$event->title = $rawEvent->get('title');
$event->allDay = $rawEvent->get('allday') == 1;
$event->url = $rawEvent->link();
$event->start = ($event->allDay == 1) ? $up->setTimezone('UTC')->format($timeFormat, true) : $up->toTimezone($timezone, $timeFormat, $ignoreDst);
$event->className = ($rawEvent->get('calendar_id')) ? 'calendar-' . $rawEvent->get('calendar_id') : 'calendar-0';
if ($rawEvent->get('publish_down') && $rawEvent->get('publish_down') != '0000-00-00 00:00:00')
{
$event->end = ($event->allDay == 1) ? $down->setTimezone('UTC')->format($timeFormat, true) : $down->toLocal($timeFormat, $ignoreDst);
}
// add start & end for displaying dates user clicked on
// instead of actual event start & end
if ($rawEvent->get('repeating_rule') != '')
{
$event->url .= '?start=' . $up->toUnix();
if ($rawEvent->get('publish_down') && $rawEvent->get('publish_down') != '0000-00-00 00:00:00')
{
$event->url .= '&end=' . $down->toUnix();
}
}
// accounts for how humans keep time.
if ($event->allDay)
{
//google events don't put a time.
if (!isset($event->end))
{
$event->end = '0000-00-00 00:00:00';
}
// Kevin: Don't change this value. Everyone else is wrong.
// Seriously this is the correct way to do all-day events.
// Previous entries may need to be corrected, but future events will be correct.
$endDay = Date::of($event->end)->subtract('24 hours');
if ($endDay < $up)
{
$event->end = Date::of($event->start)->add('24 hours')->format($timeFormat);
}
}
array_push($events, $event);
}
// output events
echo json_encode($events);
exit();
}
/**
* Show a form for adding an entry
*
* @return string
*/
private function add()
{
return $this->edit();
}
/**
* Show a form for editing en entry
*
* @return string
*/
private function edit()
{
//if we are not a member we cant create events
if (!in_array($this->user->get('id'), $this->group->get('members')))
{
App::redirect(
Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&year=' . $this->year . '&month=' . $this->month),
Lang::txt('Only group members are allowed to create & edit events.'),
'warning'
);
return;
}
//create the view
$view = $this->view('edit', 'calendar');
//get the passed in event id
$eventId = Request::getInt('event_id', 0, 'get');
//load event data
$view->event = new \Components\Events\Models\Event($eventId);
//get calendars
$eventsCalendarArchive = \Components\Events\Models\Calendar\Archive::getInstance();
$view->calendars = $eventsCalendarArchive->calendars('list', array(
'scope' => 'group',
'scope_id' => $this->group->get('gidNumber'),
'readonly' => 0
));
// do we have access to edit
if ($view->event->get('id'))
{
//check to see if user has the correct permissions to edit
if ($this->user->get('id') != $view->event->get('created_by') && $this->authorized != 'manager')
{
//do not have permission to edit the event
App::redirect(
Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&year=' . $this->year . '&month=' . $this->month),
Lang::txt('You do not have the correct permissions to edit this event.'),
'error'
);
return;
}
// make sure this event is editable
$eventCalendar = $view->event->calendar();
if ($eventCalendar->isSubscription())
{
App::redirect(
Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&action=details&event_id='.$view->event->get('id')),
Lang::txt('You cannot edit imported events from remote calendar subscriptions.'),
'error'
);
return;
}
else
{
$allDay = $view->event->get('allday');
$endDate = $view->event->get('publish_down');
if ($allDay == '1' && !empty($endDate))
{
$newEndDate = Date::of($endDate)->subtract('24 hours')->toSql();
$view->event->set('publish_down', $newEndDate);
}
}
}
//are we passing an events array back from save
if (isset($this->event))
{
$view->event = $this->event;
}
$timezone = $view->event->get('time_zone');
if ($view->event->get('allday') == "1")
{
$timezone = 'UTC';
}
$view->timezone = isset($timezone) ? $timezone : -5;
//push some vars to the view
$view->month = $this->month;
$view->year = $this->year;
$view->calendar = $this->calendar;
$view->group = $this->group;
$view->option = $this->option;
$view->authorized = $this->authorized;
$view->params = $this->params;
//load com_events params file for registration fields
$view->registrationFields = new \Hubzero\Html\Parameter(
$view->event->get('params'),
Component::path('com_events') . DS . 'events.xml'
);
//added need scripts and stylesheets
$this->js('fileupload/jquery.fileupload', 'system');
$this->js('fileupload/jquery.iframe-transport', 'system');
$this->js('jquery.fancyselect.min', 'system');
$this->js('jquery.timepicker', 'system');
$this->js('toolbox', 'system');
$this->css('jquery.datepicker.css', 'system');
$this->css('jquery.timepicker.css', 'system');
$this->css('jquery.fancyselect.css', 'system');
$this->css('toolbox.css', 'system');
//get any errors if there are any
foreach ($this->getErrors() as $error)
{
$view->setError($error);
}
//load the view
return $view->loadTemplate();
}
/**
* Save an entry
*
* @return string
*/
private function save()
{
Request::checkToken();
//get request vars
$event = Request::getArray('event', array(), 'post');
$event['time_zone'] = Request::getString('time_zone', null);
$event['params'] = Request::getArray('params', array());
$event['content'] = Request::getString('content', '', 'post');
$registration = Request::getInt('include-registration', 0);
//set vars for saving
$event['catid'] = '-1';
$event['state'] = 1;
$event['scope'] = 'group';
$event['scope_id'] = $this->group->get('gidNumber');
$event['modified'] = Date::of()->toSql();
$event['modified_by'] = $this->user->get('id');
// repeating rule
$event['repeating_rule'] = $this->_buildRepeatingRule();
//stringify params
if (isset($event['params']) && count($event['params']) > 0)
{
$params = new \Hubzero\Config\Registry($event['params']);
$event['params'] = $params->toString();
}
$ignoreDst = false;
if (isset($params))
{
$ignoreDst = $params->get('ignore_dst') == 1 ? true : false;
}
//if we are updating set modified time and actor
if (!isset($event['id']) || $event['id'] == 0)
{
$event['created'] = Date::toSql();
$event['created_by'] = $this->user->get('id');
}
// Handle all-day events, iCal is literal
// Since Google adopts the behavior of adding 24 hours to whatever the end date is, I've done the same here.
// If no end date set, it assumes the allday event was scheduled for just the publish_up day selected.
$allday = (isset($event['allday']) && $event['allday'] == 1) ? true : false;
if ($allday)
{
$event['publish_up'] = Date::of($event['publish_up'])->toSql();
$event['publish_down'] = !empty($event['publish_down']) ? $event['publish_down'] : $event['publish_up'];
$event['publish_down'] = Date::of($event['publish_down'])->add('24 hours')->toSql();
}
//parse publish up date/time
if (isset($event['publish_up']) && $event['publish_up'] != '' && !$allday)
{
// combine date & time
if (isset($event['publish_up_time']) && !$allday)
{
$event['publish_up'] = $event['publish_up'] . ' ' . $event['publish_up_time'];
}
$event['publish_up'] = Date::of($event['publish_up'], $event['time_zone'], $ignoreDst)->toSql();
unset($event['publish_up_time']);
}
//parse publish down date/time
if (isset($event['publish_down']) && $event['publish_down'] != '' && !$allday)
{
// combine date & time
if (isset($event['publish_down_time']))
{
$event['publish_down'] = $event['publish_down'] . ' ' . $event['publish_down_time'];
}
$event['publish_down'] = Date::of($event['publish_down'], $event['time_zone'], $ignoreDst)->toSql();
unset($event['publish_down_time']);
}
//parse register by date/time
if (isset($event['registerby']) && $event['registerby'] != '')
{
//remove @ symbol
$event['registerby'] = str_replace("@", "", $event['registerby']);
$event['registerby'] = Date::of($event['registerby'], $event['time_zone'])->toSql();
}
//did we want to turn off registration?
if (!$registration)
{
$event['registerby'] = null;
}
//instantiate new event object
$eventsModelEvent = new \Components\Events\Models\Event();
// attempt to bind
if (!$eventsModelEvent->bind($event))
{
$this->setError($eventsModelEvent->getError());
$this->event = $eventsModelEvent;
return $this->edit();
}
if (isset($event['content']) && $event['content'])
{
$event['content'] = \Hubzero\Utility\Sanitize::clean($event['content']);
}
if (isset($event['extra_info']) && $event['extra_info'] && ! \Hubzero\Utility\Validate::url($event['extra_info']))
{
$this->setError('Website entered does not appear to be a valid URL.');
$this->event = $eventsModelEvent;
return $this->edit();
}
//make sure we have both start and end time
if ($event['publish_up'] == '')
{
$this->setError('You must enter an event start, an end date is optional.');
$this->event = $eventsModelEvent;
return $this->edit();
}
//check to make sure end time is greater than start time
if (isset($event['publish_down']) && $event['publish_down'] && $event['publish_down'] != '0000-00-00 00:00:00')
{
$up = strtotime($event['publish_up']);
$down = strtotime($event['publish_down']);
// make sure up greater than down when not all day
// when all day event up can equal down
if (($up >= $down && !$allday) || ($allday && $up > $down))
{
$this->setError('You must an event end date greater than the start date.');
$this->event = $eventsModelEvent;
return $this->edit();
}
}
//make sure registration email is valid
if ($registration && isset($event['email']) && $event['email'] != '' && !filter_var($event['email'], FILTER_VALIDATE_EMAIL))
{
$this->setError('You must enter a valid email address for the events registration admin email.');
$this->event = $eventsModelEvent;
return $this->edit();
}
//make sure registration email is valid
if ($registration && (!isset($event['registerby']) || $event['registerby'] == ''))
{
$this->setError('You must enter a valid event registration deadline to require registration.');
Request::setVar('includeRegistration', 1);
$this->event = $eventsModelEvent;
return $this->edit();
}
//check to make sure we have valid info
if (!$eventsModelEvent->store(true))
{
$this->setError('An error occurred when trying to edit the event. Please try again.');
$this->event = $eventsModelEvent;
return $this->edit();
}
//get the year and month for this event
//so we can jump to that spot
$year = Date::of(strtotime($event['publish_up']))->format("Y");
$month = Date::of(strtotime($event['publish_up']))->format("m");
//build message
$message = Lang::txt('You have successfully created a new group event.');
if (isset($event['id']) && $event['id'] != 0)
{
$message = Lang::txt('You have successfully edited the group event.');
}
//inform user and redirect
App::redirect(
Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&action=details&event_id=' . $eventsModelEvent->get('id')),
$message,
'passed'
);
}
/**
* Delete an event
*
* @return string
*/
private function delete()
{
//get the passed in event id
$eventId = Request::getInt('event_id', 0, 'get');
//load event data
$eventsModelEvent = new \Components\Events\Models\Event($eventId);
//for rediction purposes
$publish_up = strtotime($eventsModelEvent->get('publish_up'));
$year = date('Y', $publish_up);
$month = date('m', $publish_up);
// check to see if user has the right permissions to delete
if ($this->user->get('id') != $eventsModelEvent->get('created_by') && $this->authorized != 'manager')
{
// do not have permission to delete the event
App::redirect(
Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&year=' . $year . '&month=' . $month),
Lang::txt('You do not have the correct permissions to delete this event.'),
'error'
);
return;
}
// make sure this event is editable
$eventCalendar = $eventsModelEvent->calendar();
if ($eventCalendar->isSubscription())
{
App::redirect(
Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&action=details&event_id='.$eventsModelEvent->get('id')),
Lang::txt('You cannot delete imported events from remote calendar subscriptions.'),
'error'
);
return;
}
//make as disabled
$eventsModelEvent->set('state', 0);
//save changes
if (!$eventsModelEvent->store(true))
{
App::redirect(
Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&year=' . $year . '&month=' . $month),
Lang::txt('An error occurred while trying to delete the event. Please try again.'),
'error'
);
return;
}
//inform user and return
App::redirect(
Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&year=' . $year . '&month=' . $month),
Lang::txt('You have successfully deleted the event.'),
'passed'
);
}
/**
* Details View for Event
*
* @return string
*/
private function details()
{
//create the view
$view = $this->view('details', 'calendar');
//get request varse
$eventId = Request::getInt('event_id', 0, 'get');
//load event data
$view->event = new \Components\Events\Models\Event($eventId);
// make sure we have event
if (!$view->event->get('id'))
{
App::redirect(
Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&year=' . $this->year . '&month=' . $this->month),
Lang::txt('Event not found.'),
'error'
);
return;
}
//get registrants count
$eventsRespondent = new \Components\Events\Tables\Respondent(array('id' => $eventId));
$view->registrants = $eventsRespondent->getCount();
//get calendar
$view->calendar = \Components\Events\Models\Calendar::getInstance($view->event->get('calendar_id'));
//push some vars to the view
$view->month = $this->month;
$view->year = $this->year;
$view->group = $this->group;
$view->option = $this->option;
$view->authorized = $this->authorized;
$view->user = $this->user;
//get any errors if there are any
foreach ($this->getErrors() as $error)
{
$view->setError($error);
}
//load the view
return $view->loadTemplate();
}
/**
* Export Event Details
*
* @return void
*/
private function export()
{
// get request varse
$eventId = Request::getInt('event_id', 0, 'get');
// load & export event
$eventsModelEvent = new \Components\Events\Models\Event($eventId);
$eventsModelEvent->export();
}
/**
* Subscribe to a calendar
*
* @return void
*/
private function subscribe()
{
//check to see if subscriptions are on
if (!$this->params->get('allow_subscriptions', 1))
{
header('HTTP/1.1 404 Not Found');
die(Lang::txt('Calendar subsciptions are currently turned off.'));
}
//force https protocol
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off')
{
App::redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
die(Lang::txt('Calendar subscriptions only support the HTTPS (port 443) protocol.'));
}
//get the calendar plugin access
$plugin_access = $this->access['calendar'];
//is the plugin off
if ($plugin_access == 'nobody')
{
header('HTTP/1.1 404 Not Found');
die(Lang::txt('GROUPS_PLUGIN_OFF', 'Calendar'));
}
//is the plugin for registered or members only?
if ($plugin_access == 'registered' || $plugin_access == 'members')
{
//authenticate user
$auth = $this->authenticateSubscriptionRequest();
//is it registered users only?
if ($plugin_access == 'registered' && !is_object($auth))
{
header('HTTP/1.1 403 Not Authorized');
die(Lang::txt('GROUPS_PLUGIN_REGISTERED', 'Calendar'));
}
//make sure we are a member