/
dbem_events.php
1932 lines (1712 loc) · 68.5 KB
/
dbem_events.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
// Moved to Admin Class
function dbem_new_event_page() {
$title = __ ( "Insert New Event", 'dbem' );
dbem_event_form ( '', $title,'' );
}
// Moved to Admin Class
function dbem_events_subpanel() {
global $wpdb;
$action = $_GET ['action'];
$action2 = $_GET ['action2'];
$event_ID = $_GET ['event_id'];
$recurrence_ID = $_GET ['recurrence_id'];
$scope = $_GET ['scope'];
$offset = $_GET ['offset'];
$order = $_GET ['order'];
$selectedEvents = $_GET ['events'];
$dbem_opts = get_option('dbem');
// Disable Hello to new user if requested
if (isset ( $_GET ['disable_hello_to_user'] ) && $_GET ['disable_hello_to_user'] == 'true') {
update_option ( 'dbem_hello_to_user', 0 );
$dbem_opts->dbem_hello_to_user = 0;
}
if ($order == "")
$order = "ASC";
if ($offset == "")
$offset = "0";
$event_table_name = $wpdb->prefix . EVENTS_TBNAME;
// Debug code, to make sure I get the correct page
// DELETE action
if ($action == 'deleteEvents') {
// $sql="DELETE FROM ".$event_table_name." WHERE event_id='"."$event_ID"."'";
// TODO eventual error if ID in non-existant
//$wpdb->query($sql);
foreach ( $selectedEvents as $event_ID ) {
dbem_delete_event ( $event_ID );
}
$events = dbem_get_events ( "", "future" );
dbem_events_table ( $events, 10, "Future events" );
}
// UPDATE or CREATE action
if ($action == 'update_event' || $action == 'update_recurrence') {
$event = array ();
$location = array ();
$event ['event_name'] = stripslashes ( $_POST [event_name] );
// Set event end time to event time if not valid
// if (!_dbem_is_date_valid($event['event_end_date']))
// $event['event_end_date'] = $event['event-date'];
$event ['event_start_date'] = $_POST [event_date];
$event ['event_end_date'] = $_POST [event_end_date];
//$event['event_start_time'] = $_POST[event_hh].":".$_POST[event_mm].":00";
//$event['event_end_time'] = $_POST[event_end_hh].":".$_POST[event_end_mm].":00";
$event ['event_start_time'] = date ( "G:i:00", strtotime ( $_POST ['event_start_time'] ) );
$event ['event_end_time'] = date ( "G:i:00", strtotime ( $_POST ['event_end_time'] ) );
$recurrence ['recurrence_name'] = $event ['event_name'];
$recurrence ['recurrence_start_date'] = $event ['event_start_date'];
$recurrence ['recurrence_end_date'] = $event ['event_end_date'];
$recurrence ['recurrence_start_time'] = $event ['event_start_time'];
$recurrence ['recurrence_end_time'] = $event ['event_end_time'];
$recurrence ['recurrence_id'] = $_POST [recurrence_id];
$recurrence ['recurrence_freq'] = $_POST [recurrence_freq];
$recurrence ['recurrence_freq'] == 'weekly' ? $recurrence [recurrence_byday] = implode ( ",", $_POST ['recurrence_bydays'] ) : $recurrence ['recurrence_byday'] = $_POST [recurrence_byday];
$_POST ['recurrence_interval'] == "" ? $recurrence ['recurrence_interval'] = 1 : $recurrence ['recurrence_interval'] = $_POST ['recurrence_interval'];
$recurrence ['recurrence_byweekno'] = $_POST [recurrence_byweekno];
$event ['event_rsvp'] = $_POST ['event_rsvp'];
$event ['event_seats'] = $_POST ['event_seats'];
if (isset ( $_POST ['event_contactperson_id'] ) && $_POST ['event_contactperson_id'] != '' && $_POST ['event_contactperson_id'] != '-1') {
$event ['event_contactperson_id'] = $_POST ['event_contactperson_id'];
$recurrence ['event_contactperson_id'] = $_POST ['event_contactperson_id'];
}
if (! _dbem_is_time_valid ( $event_end_time ))
$event_end_time = $event_time;
$location ['location_name'] = $_POST [location_name];
$location ['location_address'] = $_POST [location_address];
$location ['location_town'] = $_POST [location_town];
$location ['location_latitude'] = $_POST [location_latitude];
$location ['location_longitude'] = $_POST [location_longitude];
$location ['location_description'] = "";
/* Marcus Begin Edit */
//switched to WP TinyMCE field
//$event ['event_notes'] = stripslashes ( $_POST [event_notes] );
$event ['event_notes'] = stripslashes ( $_POST ['content'] );
/* Marcus End Edit */
$recurrence ['recurrence_notes'] = $event ['event_notes'];
$validation_result = dbem_validate_event ( $event );
if ($validation_result == "OK") {
// validation successful
$related_location = dbem_get_identical_location ( $location );
// print_r($related_location);
if ($related_location) {
$event ['location_id'] = $related_location ['location_id'];
$recurrence ['location_id'] = $related_location ['location_id'];
} else {
$new_location = dbem_insert_location ( $location );
$event ['location_id'] = $new_location ['location_id'];
$recurrence ['location_id'] = $new_location ['location_id'];
//print_r($new_location);
}
if (! $event_ID && ! $recurrence_ID) {
// there isn't anything
if ($_POST ['repeated_event']) {
//insert new recurrence
dbem_insert_recurrent_event ( $event, $recurrence );
$feedback_message = __ ( 'New recurrent event inserted!', 'dbem' );
} else {
// INSERT new event
$wpdb->insert ( $event_table_name, $event );
$feedback_message = __ ( 'New event successfully inserted!', 'dbem' );
}
} else {
// something exists
if ($recurrence_ID) {
// UPDATE old recurrence
$recurrence ['recurrence_id'] = $recurrence_ID;
//print_r($recurrence);
if (dbem_update_recurrence ( $recurrence ))
$feedback_message = __ ( 'Recurrence updated!', 'dbem' );
else
$feedback_message = __ ( 'Something went wrong with the recurrence update...', 'dbem' );
} else {
// UPDATE old event
// unlink from recurrence in case it was generated by one
$event ['recurrence_id'] = null;
$where ['event_id'] = $event_ID;
$wpdb->update ( $event_table_name, $event, $where );
$feedback_message = "'" . $event ['event_name'] . "' " . __ ( 'updated', 'dbem' ) . "!";
}
}
/* Marcus Begin Edit */
//Save the category if selected
if( is_numeric($_POST['event_category_id']) ){
$insert_id = (! $event_ID && ! $recurrence_ID) ? $wpdb->insert_id : $event_ID;
$wpdb->update ( $event_table_name, array("event_category_id" => $_POST['event_category_id']), array('event_id' => $insert_id) );
}
/* Marcus End Edit */
//$wpdb->query($sql);
echo "<div id='message' class='updated fade'>
<p>$feedback_message</p>
</div>";
$events = dbem_get_events ( "", "future" );
dbem_events_table ( $events, 10, "Future events" );
} else {
// validation unsuccessful
echo "<div id='message' class='error '>
<p>" . __ ( "Ach, there's a problem here:", "dbem" ) . " $validation_result</p>
</div>";
dbem_event_form ( $event, "Edit event $event_ID", $event_ID );
}
}
if ($action == 'edit_event') {
if (! $event_ID) {
$title = __ ( "Insert New Event", 'dbem' );
} else {
$event = dbem_get_event ( $event_ID );
$title = __ ( "Edit Event", 'dbem' ) . " '" . $event ['event_name'] . "'";
}
//$event=$wpdb->get_row($sql, ARRAY_A);
// Enter new events and updates old ones
// DEBUG: echo"Nome: $event->event_name";
dbem_event_form ( $event, $title, $event_ID );
}
/* Marcus Begin Edit */
//Add duplicate event if requested
if ($action == 'duplicate_event') {
dbem_duplicate_event ( $event_ID );
}
/* Marcus End Edit */
if ($action == 'edit_recurrence') {
$event_ID = $_GET ['recurrence_id'];
$recurrence = dbem_get_recurrence ( $event_ID );
$title = __ ( "Reschedule", 'dbem' ) . " '" . $recurrence ['recurrence_name'] . "'";
dbem_event_form ( $recurrence, $title, $event_ID );
}
if ($action == 'update_recurrence') {
//print_r($recurrence);
//die('update recurrence!');
}
if ($action == "-1" || $action == "") {
// No action, only showing the events list
switch ($scope) {
case "past" :
$title = __ ( 'Past Events', 'dbem' );
break;
case "all" :
$title = __ ( 'All Events', 'dbem' );
break;
default :
$title = __ ( 'Future Events', 'dbem' );
$scope = "future";
}
$limit = 20;
$events = dbem_get_events ( $limit, $scope, $order, $offset );
dbem_events_table ( $events, $limit, $title );
}
update_option('dbem', $dbem_opts);
}
// array of all pages, bypasses the filter I set up :)
function dbem_get_all_pages() {
global $wpdb;
$query = "SELECT id, post_title FROM " . $wpdb->prefix . "posts WHERE post_type = 'page';";
$pages = $wpdb->get_results ( $query, ARRAY_A );
$output = array ();
foreach ( $pages as $page ) {
$output [$page ['id']] = $page ['post_title'];
}
return $output;
}
// Moved to admin
// Function composing the options subpanel
function dbem_options_subpanel() {
// dbem_options_register();
?>
<div class="wrap">
<div id='icon-options-general' class='icon32'><br />
</div>
<h2><?php
_e ( 'Event Manager Options', 'dbem' );
?></h2>
<form id="dbem_options_form" method="post" action="options.php">
<h3><?php
_e ( 'Events page', 'dbem' );
?></h3>
<table class="form-table">
<?php
dbem_options_select ( __ ( 'Events page' ), 'dbem_events_page', dbem_get_all_pages (), __ ( 'This option allows you to select which page to use as an events page' ) );
dbem_options_radio_binary ( __ ( 'Display calendar in events page?', 'dbem' ), 'dbem_display_calendar_in_events_page', __ ( 'This options allows to display the calendar in the events page, instead of the default list. It is recommended not to display both the calendar widget and a calendar page.' ) )?>
</table>
<h3><?php
_e ( 'Events format', 'dbem' );
?></h3>
<table class="form-table">
<?php
/* Marcus Begin Edit */
dbem_options_textarea ( __ ( 'Default event list format', 'dbem' ), 'dbem_event_list_item_format', __ ( 'The format of any events in a list.<br/>Insert one or more of the following placeholders: <code>#_NAME</code>, <code>#_LOCATION</code>, <code>#_ADDRESS</code>, <code>#_TOWN</code>, <code>#_NOTES</code>.<br/> Use <code>#_LINKEDNAME</code> for the event name with a link to the given event page.<br/> Use <code>#_EVENTPAGEURL</code> to print the event page URL and make your own customised links.<br/> Use <code>#_LOCATIONPAGEURL</code> to print the location page URL and make your own customised links.<br/>To insert date and time values, use <a href="http://www.php.net/manual/en/function.date.php">PHP time format characters</a> with a <code>#</code> symbol before them, i.e. <code>#m</code>, <code>#M</code>, <code>#j</code>, etc.<br/> For the end time, put <code>#@</code> in front of the character, ie. <code>#@h</code>, <code>#@i</code>, etc.<br/> You can also create a date format without prepending <code>#</code> by wrapping it in #_{} or #@_{} (e.g. <code>#_{d/m/Y}</code>). If there is no end date, the value is not shown.<br/> Feel free to use HTML tags as <code>li</code>, <code>br</code> and so on.', 'dbem' ) );
/* Marcus End Edit */
dbem_options_input_text ( __ ( 'Single event page title format', 'dbem' ), 'dbem_event_page_title_format', __ ( 'The format of a single event page title. Follow the previous formatting instructions.', 'dbem' ) );
dbem_options_textarea ( __ ( 'Default single event format', 'dbem' ), 'dbem_single_event_format', __ ( 'The format of a single event page.<br/>Follow the previous formatting instructions. <br/>Use <code>#_MAP</code> to insert a map.<br/>Use <code>#_CONTACTNAME</code>, <code>#_CONTACTEMAIL</code>, <code>#_CONTACTPHONE</code> to insert respectively the name, e-mail address and phone number of the designated contact person. <br/>Use <code>#_ADDBOOKINGFORM</code> to insert a form to allow the user to respond to your events reserving one or more places (RSVP).<br/> Use <code>#_REMOVEBOOKINGFORM</code> to insert a form where users, inserting their name and e-mail address, can remove their bookings.', 'dbem' ) );
dbem_options_radio_binary ( __ ( 'Show events page in lists?', 'dbem' ), 'dbem_list_events_page', __ ( 'Check this option if you want the events page to appear together with other pages in pages lists.', 'dbem' ) );
dbem_options_input_text ( __ ( 'Events page title', 'dbem' ), 'dbem_events_page_title', __ ( 'The title on the multiple events page.', 'dbem' ) );
dbem_options_input_text ( __ ( 'No events message', 'dbem' ), 'dbem_no_events_message', __ ( 'The message displayed when no events are available.', 'dbem' ) );
dbem_options_textarea ( __ ( 'Map text format', 'dbem' ), 'dbem_map_text_format', __ ( 'The format the text appearing in the event page map cloud.<br/>Follow the previous formatting instructions.', 'dbem' ) );
?>
</table>
<h3><?php
_e ( 'Locations format', 'dbem' );
?></h3>
<table class="form-table"><?php
dbem_options_input_text ( __ ( 'Single location page title format', 'dbem' ), 'dbem_location_page_title_format', __ ( 'The format of a single location page title.<br/>Follow the previous formatting instructions.', 'dbem' ) );
dbem_options_textarea ( __ ( 'Default single location page format', 'dbem' ), 'dbem_single_location_format', __ ( 'The format of a single location page.<br/>Insert one or more of the following placeholders: <code>#_NAME</code>, <code>#_ADDRESS</code>, <code>#_TOWN</code>, <code>#_DESCRIPTION</code>.<br/> Use <code>#_MAP</code> to display a map of the event location, and <code>#_IMAGE</code> to display an image of the location.<br/> Use <code>#_NEXTEVENTS</code> to insert a list of the upcoming events, <code>#_PASTEVENTS</code> for a list of past events, <code>#_ALLEVENTS</code> for a list of all events taking place in this location.', 'dbem' ) );
dbem_options_textarea ( __ ( 'Default location baloon format', 'dbem' ), 'dbem_location_baloon_format', __ ( 'The format of of the text appearing in the baloon describing the location in the map.<br/>Insert one or more of the following placeholders: <code>#_NAME</code>, <code>#_ADDRESS</code>, <code>#_TOWN</code>, <code>#_DESCRIPTION</code> or <code>#_IMAGE</code>.', 'dbem' ) );
dbem_options_textarea ( __ ( 'Default location event list format', 'dbem' ), 'dbem_location_event_list_item_format', __ ( 'The format of the events the list inserted in the location page through the <code>#_NEXTEVENTS</code>, <code>#_PASTEVENTS</code> and <code>#_ALLEVENTS</code> element. <br/> Follow the events formatting instructions', 'dbem' ) );
dbem_options_textarea ( __ ( 'Default no events message', 'dbem' ), 'dbem_location_no_events_message', __ ( 'The message to be displayed in the list generated by <code>#_NEXTEVENTS</code>, <code>#_PASTEVENTS</code> and <code>#_ALLEVENTS</code> when no events are available.', 'dbem' ) );
?>
</table>
<h3><?php
_e ( 'RSS feed format', 'dbem' );
?></h3>
<table class="form-table"><?php
dbem_options_input_text ( __ ( 'RSS main title', 'dbem' ), 'dbem_rss_main_title', __ ( 'The main title of your RSS events feed.', 'dbem' ) );
dbem_options_input_text ( __ ( 'RSS main description', 'dbem' ), 'dbem_rss_main_description', __ ( 'The main description of your RSS events feed.', 'dbem' ) );
dbem_options_input_text ( __ ( 'RSS title format', 'dbem' ), 'dbem_rss_title_format', __ ( 'The format of the title of each item in the events RSS feed.', 'dbem' ) );
dbem_options_input_text ( __ ( 'RSS description format', 'dbem' ), 'dbem_rss_description_format', __ ( 'The format of the description of each item in the events RSS feed. Follow the previous formatting instructions.', 'dbem' ) );
?>
</table>
<h3><?php
_e ( 'Maps and geotagging', 'dbem' );
?></h3>
<table class='form-table'>
<?php
$gmap_is_active = get_option ( 'dbem_gmap_is_active' );
?>
<tr valign="top">
<th scope="row"><?php
_e ( 'Enable Google Maps integration?', 'dbem' );
?></th>
<td><input id="dbem_gmap_is_active_yes" name="dbem_gmap_is_active"
type="radio" value="1"
<?php
if ($gmap_is_active)
echo "checked='checked'";
?> /><?php
_e ( 'Yes' );
?> <br />
<input name="dbem_gmap_is_active" type="radio" value="0"
<?php
if (! $gmap_is_active)
echo "checked='checked'";
?> /> <?php
_e ( 'No' );
?> <br />
<?php
_e ( 'Check this option to enable Goggle Map integration.', 'dbem' )?>
</td>
</tr>
<?php
dbem_options_input_text ( __ ( 'Google Maps API Key', 'dbem' ), 'dbem_gmap_key', sprintf ( __ ( "To display Google Maps you need a Google Maps API key. Don't worry, it's free, you can get one <a href='%s'>here</a>.", 'dbem' ), 'http://code.google.com/apis/maps/signup.html' ) );
?>
</table>
<h3><?php
_e ( 'RSVP and bookings', 'dbem' );
?></h3>
<table class='form-table'>
<?php
dbem_options_select ( __ ( 'Default contact person', 'dbem' ), 'dbem_default_contact_person', dbem_get_indexed_users (), __ ( 'Select the default contact person. This user will be employed whenever a contact person is not explicitly specified for an event', 'dbem' ) );
dbem_options_radio_binary ( __ ( 'Enable the RSVP e-mail notifications?', 'dbem' ), 'dbem_rsvp_mail_notify_is_active', __ ( 'Check this option if you want to receive an email when someone books places for your events.', 'dbem' ) );
dbem_options_textarea ( __ ( 'Contact person email format', 'dbem' ), 'dbem_contactperson_email_body', __ ( 'The format or the email which will be sent to the contact person. Follow the events formatting instructions. <br/>Use <code>#_RESPNAME</code>, <code>#_RESPEMAIL</code> and <code>#_RESPPHONE</code> to display respectively the name, e-mail, address and phone of the respondent.<br/>Use <code>#_SPACES</code> to display the number of spaces reserved by the respondent.<br/> Use <code>#_BOOKEDSEATS</code> and <code>#_AVAILABLESEATS</code> to display respectively the number of booked and available seats.', 'dbem' ) );
dbem_options_textarea ( __ ( 'Contact person email format', 'dbem' ), 'dbem_respondent_email_body', __ ( 'The format or the email which will be sent to reposdent. Follow the events formatting instructions. <br/>Use <code>#_RESPNAME</code> to display the name of the respondent.<br/>Use <code>#_CONTACTNAME</code> and <code>#_CONTACTMAIL</code> a to display respectively the name and e-mail of the contact person.<br/>Use <code>#_SPACES</code> to display the number of spaces reserved by the respondent.', 'dbem' ) );
dbem_options_input_text ( __ ( 'Notification sender name', 'dbem' ), 'dbem_mail_sender_name', __ ( "Insert the display name of the notification sender.", 'dbem' ) );
dbem_options_input_text ( __ ( 'Notification sender address', 'dbem' ), 'dbem_mail_sender_address', __ ( "Insert the address of the notification sender. It must corresponds with your gmail account user", 'dbem' ) );
dbem_options_input_text ( __ ( 'Default notification receiver address', 'dbem' ), 'dbem_mail_receiver_address', __ ( "Insert the address of the receiver of your notifications", 'dbem' ) );
dbem_options_input_text ( 'Mail sending port', 'dbem_rsvp_mail_port', __ ( "The port through which you e-mail notifications will be sent. Make sure the firewall doesn't block this port", 'dbem' ) );
dbem_options_select ( __ ( 'Mail sending method', 'dbem' ), 'dbem_rsvp_mail_send_method', array ('smtp' => 'SMTP', 'mail' => __ ( 'PHP mail function', 'dbem' ), 'sendmail' => 'Sendmail', 'qmail' => 'Qmail' ), __ ( 'Select the method to send email notification.', 'dbem' ) );
dbem_options_radio_binary ( __ ( 'Use SMTP authentication?', 'dbem' ), 'dbem_rsvp_mail_SMTPAuth', __ ( 'SMTP authenticatio is often needed. If you use GMail, make sure to set this parameter to Yes', 'dbem' ) );
dbem_options_input_text ( 'SMTP host', 'dbem_smtp_host', __ ( "The SMTP host. Usually it corresponds to 'localhost'. If you use GMail, set this value to 'ssl://smtp.gmail.com:465'.", 'dbem' ) );
dbem_options_input_text ( __ ( 'SMTP username', 'dbem' ), 'dbem_smtp_username', __ ( "Insert the username to be used to access your SMTP server.", 'dbem' ) );
dbem_options_input_password ( __ ( 'SMTP password', 'dbem' ), "dbem_smtp_password", __ ( "Insert the password to be used to access your SMTP server", 'dbem' ) );
?>
</table>
<h3><?php
_e ( 'Images size', 'dbem' );
?></h3>
<table class='form-table'> <?php
dbem_options_input_text ( __ ( 'Maximum width (px)', 'dbem' ), 'dbem_image_max_width', __ ( 'The maximum allowed width for images uploades', 'dbem' ) );
dbem_options_input_text ( __ ( 'Maximum height (px)', 'dbem' ), 'dbem_image_max_height', __ ( "The maximum allowed width for images uploaded, in pixels", 'dbem' ) );
dbem_options_input_text ( __ ( 'Maximum size (bytes)', 'dbem' ), 'dbem_image_max_size', __ ( "The maximum allowed size for images uploaded, in pixels", 'dbem' ) );
?>
</table>
<p class="submit"><input type="submit" id="dbem_options_submit"
name="Submit" value="<?php
_e ( 'Save Changes' )?>" /></p>
<?php
settings_fields ( 'dbem-options' );
?>
</form>
</div>
<?php
}
// Front
//This is the content of the event page
function dbem_events_page_content() {
global $wpdb;
if (isset ( $_REQUEST ['location_id'] ) && $_REQUEST ['location_id'] |= '') {
$location = dbem_get_location ( $_REQUEST ['location_id'] );
$single_location_format = get_option ( 'dbem_single_location_format' );
$page_body = dbem_replace_locations_placeholders ( $single_location_format, $location );
return $page_body;
}
if (isset ( $_REQUEST ['event_id'] ) && $_REQUEST ['event_id'] != '') {
// single event page
$event_ID = $_REQUEST ['event_id'];
$event = dbem_get_event ( $event_ID );
$single_event_format = get_option ( 'dbem_single_event_format' );
$page_body = dbem_replace_placeholders ( $single_event_format, $event );
return $page_body;
} elseif (isset ( $_REQUEST ['calendar_day'] ) && $_REQUEST ['calendar_day'] != '') {
$date = $_REQUEST ['calendar_day'];
$events_N = dbem_events_count_for ( $date );
// $_GET['scope'] ? $scope = $_GET['scope']: $scope = "future";
// $stored_format = get_option('dbem_event_list_item_format');
// $events_body = dbem_get_events_list(10, $scope, "ASC", $stored_format, $false);
if ($events_N > 1) {
$_GET ['calendar_day'] ? $scope = $_GET ['calendar_day'] : $scope = "future";
$stored_format = get_option ( 'dbem_event_list_item_format' );
$events_body = "<ul class='dbem_events_list'>" . dbem_get_events_list ( 10, $scope, "ASC", $stored_format, $false ) . "</ul>";
return $events_body;
} else {
$events = dbem_get_events ( "", $_REQUEST ['calendar_day'] );
$event = $events [0];
$single_event_format = get_option ( 'dbem_single_event_format' );
$page_body = dbem_replace_placeholders ( $single_event_format, $event );
return $page_body;
}
return $events_body;
} else {
// Multiple events page
$_GET ['scope'] ? $scope = $_GET ['scope'] : $scope = "future";
$stored_format = get_option ( 'dbem_event_list_item_format' );
if (get_option ( 'dbem_display_calendar_in_events_page' ))
$events_body = dbem_get_calendar ();
else
$events_body = $events_body = "<ul class='dbem_events_list'>" . dbem_get_events_list ( 10, $scope, "ASC", $stored_format, $false ) . "</ul>";
return $events_body;
}
}
// Count events
function dbem_events_count_for($date) {
global $wpdb;
$table_name = $wpdb->prefix . EVENTS_TBNAME;
$sql = "SELECT COUNT(*) FROM $table_name WHERE event_start_date like '$date';";
return $wpdb->get_var ( $sql );
}
// Front
// filter function to call the event page when appropriate
function dbem_filter_events_page($data) {
// $table_name = $wpdb->prefix .EVENTS_TBNAME;
// $start = strpos($data, DBEM_PAGE);
//echo "uh oh";
$is_events_post = (get_the_ID () == get_option ( 'dbem_events_page' ));
$events_page_id = get_option ( 'dbem_events_page' );
if (is_page ( $events_page_id ) && $is_events_post) {
return dbem_events_page_content ();
} else {
return $data;
}
}
//add_filter ( 'the_content', 'dbem_filter_events_page' );
// TODO ?
function dbem_events_page_title($data) {
$events_page_id = get_option ( 'dbem_events_page' );
$events_page = get_page ( $events_page_id );
$events_page_title = $events_page->post_title;
if (($data == $events_page_title) && (is_page ( $events_page_id ))) {
if (isset ( $_REQUEST ['calendar_day'] ) && $_REQUEST ['calendar_day'] != '') {
$date = $_REQUEST ['calendar_day'];
$events_N = dbem_events_count_for ( $date );
if ($events_N == 1) {
$events = dbem_get_events ( "", $_REQUEST ['calendar_day'] );
$event = $events [0];
$stored_page_title_format = get_option ( 'dbem_event_page_title_format' );
$page_title = dbem_replace_placeholders ( $stored_page_title_format, $event );
return $page_title;
}
}
if (isset ( $_REQUEST ['location_id'] ) && $_REQUEST ['location_id'] |= '') {
$location = dbem_get_location ( $_REQUEST ['location_id'] );
$stored_page_title_format = get_option ( 'dbem_location_page_title_format' );
$page_title = dbem_replace_locations_placeholders ( $stored_page_title_format, $location );
return $page_title;
}
if (isset ( $_REQUEST ['event_id'] ) && $_REQUEST ['event_id'] != '') {
// single event page
$event_ID = $_REQUEST ['event_id'];
$event = dbem_get_event ( $event_ID );
$stored_page_title_format = get_option ( 'dbem_event_page_title_format' );
$page_title = dbem_replace_placeholders ( $stored_page_title_format, $event );
return $page_title;
} else {
// Multiple events page
$page_title = get_option ( 'dbem_events_page_title' );
return $page_title;
}
} else {
return $data;
}
}
// to make sure that in pages lists the title is dbem_events_page_title, and not overwritten by the previous filter
//add_filter ( 'the_title', 'dbem_events_page_title' );
//add_filter ( 'single_post_title', 'dbem_events_page_title' );
// TODO ? Get Pages
function dbem_filter_get_pages($data) {
$output = array ();
$events_page_id = get_option ( 'dbem_events_page' );
for($i = 0; $i < count ( $data ); ++ $i) {
if ($data [$i]->ID == $events_page_id) {
$list_events_page = get_option ( 'dbem_list_events_page' );
if ($list_events_page) {
$data [$i]->post_title = get_option ( 'dbem_events_page_title' ) . " ";
$output [] = $data [$i];
}
} else {
$output [] = $data [$i];
}
}
return $output;
}
//add_filter ( 'get_pages', 'dbem_filter_get_pages' );
//
// TODO: ROBA NUOVA DA RIORDINARE
// ADMIN CSS for debug
function dbem_admin_css() {
$css = '<link rel="stylesheet" href="'
. DBEM_URI . 'css/admin.css" type="text/css" />';
echo $css;
}
//add_action ( 'admin_print_scripts', 'dbem_admin_css' );
// TEMPLATE TAGS
// exposed function, for theme makers
/* Marcus Begin Edit */
//Added a category option to the get events list method and shortcode
function dbem_get_events_list($limit = "3", $scope = "future", $order = "ASC", $format = '', $echo = 1, $category = '') {
if (strpos ( $limit, "=" )) {
// allows the use of arguments without breaking the legacy code
$defaults = array ('limit' => 3, 'scope' => 'future', 'order' => 'ASC', 'format' => '', 'echo' => 1 , 'category' => '');
$r = wp_parse_args ( $limit, $defaults );
extract ( $r, EXTR_SKIP );
$limit = $r ['limit'];
$scope = $r ['scope'];
$order = $r ['order'];
$format = $r ['format'];
$echo = $r ['echo'];
$category = (is_numeric($r ['category'])) ? $r ['category'] : '' ;
}
if ($scope == "")
$scope = "future";
if ($order != "DESC")
$order = "ASC";
if ($format == '')
$format = get_option ( 'dbem_event_list_item_format' );
$events = dbem_get_events ( $limit, $scope, $order, '', '', $category );
$output = "";
if (! empty ( $events )) {
foreach ( $events as $event ) {
// $localised_date = mysql2date("j M Y", $event->event_time);
$output .= dbem_replace_placeholders ( $format, $event );
}
} else {
$output = "<li class='dbem-no-events'>" . get_option ( 'dbem_no_events_message' ) . "</li>";
}
if ($echo)
echo $output;
else
return $output;
}
function dbem_get_events_list_shortcode($atts) {
extract ( shortcode_atts ( array ('limit' => 3, 'scope' => 'future', 'order' => 'ASC', 'format' => '', 'category' => '' ), $atts ) );
$result = dbem_get_events_list ( "limit=$limit&scope=$scope&order=$order&format=$format&echo=0&category=$category" );
return $result;
}
//add_shortcode ( 'events_list', 'dbem_get_events_list_shortcode' );
/* Marcus End Edit*/
function dbem_get_events_page($justurl = 0, $echo = 1, $text = '') {
if (strpos ( $justurl, "=" )) {
// allows the use of arguments without breaking the legacy code
$defaults = array ('justurl' => 0, 'text' => '', 'echo' => 1 );
$r = wp_parse_args ( $justurl, $defaults );
extract ( $r, EXTR_SKIP );
$justurl = $r ['justurl'];
$text = $r ['text'];
$echo = $r ['echo'];
}
$page_link = get_permalink ( get_option ( "dbem_events_page" ) );
if ($justurl) {
$result = $page_link;
} else {
if ($text == '')
$text = get_option ( "dbem_events_page_title" );
$result = "<a href='$page_link' title='$text'>$text</a>";
}
if ($echo)
echo $result;
else
return $result;
}
function dbem_get_events_page_shortcode($atts) {
extract ( shortcode_atts ( array ('justurl' => 0, 'text' => '' ), $atts ) );
$result = dbem_get_events_page ( "justurl=$justurl&text=$text&echo=0" );
return $result;
}
//add_shortcode ( 'events_page', 'dbem_get_events_page_shortcode' );
function dbem_are_events_available($scope = "future") {
if ($scope == "")
$scope = "future";
$events = dbem_get_events ( 1, $scope );
if (empty ( $events ))
return FALSE;
else
return TRUE;
}
// Returns true if the page in question is the events page
function dbem_is_events_page() {
$events_page_id = get_option ( 'dbem_events_page' );
return is_page ( $events_page_id );
}
function dbem_is_single_event_page() {
return (dbem_is_events_page () && (isset ( $_REQUEST ['event_id'] ) && $_REQUEST ['event_id'] != ''));
}
function dbem_is_multiple_events_page() {
return (dbem_is_events_page () && ! (isset ( $_REQUEST ['event_id'] ) && $_REQUEST ['event_id'] != ''));
}
// Moved to Events Class
// main function querying the database event table
/* Marcus Begin Edit */
//Added extra method option for cateogry
function dbem_get_events($limit = "", $scope = "future", $order = "ASC", $offset = "", $location_id = "", $category = '') {
/* Marcus End Edit */
global $wpdb;
$events_table = $wpdb->prefix . EVENTS_TBNAME;
if ($limit != "")
$limit = "LIMIT $limit";
if ($offset != "")
$offset = "OFFSET $offset";
if ($order == "")
$order = "ASC";
$timestamp = time ();
$date_time_array = getdate ( $timestamp );
$hours = $date_time_array ['hours'];
$minutes = $date_time_array ['minutes'];
$seconds = $date_time_array ['seconds'];
$month = $date_time_array ['mon'];
$day = $date_time_array ['mday'];
$year = $date_time_array ['year'];
$today = strftime ( '%Y-%m-%d', mktime ( $hours, $minutes, $seconds, $month, $day, $year ) );
$conditions = array ();
if (preg_match ( "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $scope )) {
$conditions [] = " start_date like '$scope'";
} else {
if (($scope != "past") && ($scope != "all"))
$scope = "future";
if ($scope == "future")
/* Marcus Begin Edit */
//This is so events with future dates are counted too
$conditions [] = "(start_date >= '$today' )"; //OR (event_end_date >= '$today' AND event_end_date != '0000-00-00' AND event_end_date IS NOT NULL))";
/* Marcus End Edit */
if ($scope == "past")
$conditions [] = " start_date < '$today'";
}
if ($location_id != "")
$conditions [] = " location_id = $location_id";
/* Marcus Begin Edit */
if ($category != '' && is_numeric($category)){
$conditions [] = " category_id = $category";
}
/* Marcus End Edit */
$where = implode ( " AND ", $conditions );
if ($where != "")
$where = " WHERE " . $where;
$sql = "SELECT event_id,
name,
DATE_FORMAT(start_time, '%e') AS 'event_day',
DATE_FORMAT(start_time, '%Y') AS 'event_year',
DATE_FORMAT(start_time, '%k') AS 'event_hh',
DATE_FORMAT(start_time, '%i') AS 'event_mm',
DATE_FORMAT(end_time, '%e') AS 'event_end_day',
DATE_FORMAT(end_time, '%Y') AS 'event_end_year',
DATE_FORMAT(end_time, '%k') AS 'event_end_hh',
DATE_FORMAT(end_time, '%i') AS 'event_end_mm',
start_date,
start_time,
end_time,
notes,
rsvp,
location_id,
contactperson_id
FROM $events_table
$where
ORDER BY start_date $order, start_time $order
$limit
$offset";
$wpdb->show_errors = true;
$events = $wpdb->get_results ( $sql, ARRAY_A );
if (! empty ( $events )) {
//$wpdb->print_error();
$inflated_events = array ();
foreach ( $events as $this_event ) {
$this_location = dbem_get_location ( $this_event ['location_id'] );
$this_event ['location_name'] = $this_location ['location_name'];
$this_event ['location_address'] = $this_location ['location_address'];
$this_event ['location_town'] = $this_location ['location_town'];
array_push ( $inflated_events, $this_event );
}
return $inflated_events;
} else {
return null;
}
}
// Moved to events class
function dbem_get_event($event_id) {
global $wpdb;
$events_table = $wpdb->prefix . EVENTS_TBNAME;
$sql = "SELECT event_id,
event_name,
DATE_FORMAT(event_start_date, '%Y-%m-%e') AS 'event_date',
DATE_FORMAT(event_start_date, '%e') AS 'event_day',
DATE_FORMAT(event_start_date, '%m') AS 'event_month',
DATE_FORMAT(event_start_date, '%Y') AS 'event_year',
DATE_FORMAT(event_start_time, '%k') AS 'event_hh',
DATE_FORMAT(event_start_time, '%i') AS 'event_mm',
DATE_FORMAT(event_start_time, '%h:%i%p') AS 'event_start_12h_time',
DATE_FORMAT(event_start_time, '%H:%i') AS 'event_start_24h_time',
DATE_FORMAT(event_end_time, '%Y-%m-%e') AS 'event_end_date',
DATE_FORMAT(event_end_time, '%e') AS 'event_end_day',
DATE_FORMAT(event_end_time, '%m') AS 'event_end_month',
DATE_FORMAT(event_end_time, '%Y') AS 'event_end_year',
DATE_FORMAT(event_end_time, '%k') AS 'event_end_hh',
DATE_FORMAT(event_end_time, '%i') AS 'event_end_mm',
DATE_FORMAT(event_end_time, '%h:%i%p') AS 'event_end_12h_time',
DATE_FORMAT(event_end_time, '%H:%i') AS 'event_end_24h_time',
event_start_date,
event_end_date,
event_start_time,
event_end_time,
event_notes,
event_rsvp,
event_seats,
recurrence_id,
location_id,
event_contactperson_id
FROM $events_table
WHERE event_id = $event_id";
//$wpdb->show_errors(true);
$event = $wpdb->get_row ( $sql, ARRAY_A );
//$wpdb->print_error();
$location = dbem_get_location ( $event ['location_id'] );
$event ['location_name'] = $location ['location_name'];
$event ['location_address'] = $location ['location_address'];
$event ['location_town'] = $location ['location_town'];
$event ['location_latitude'] = $location ['location_latitude'];
$event ['location_longitude'] = $location ['location_longitude'];
$event ['location_image_url'] = $location ['location_image_url'];
return $event;
}
// Moved kinda'
function dbem_hello_to_new_user() {
$current_user = wp_get_current_user ();
$advice = sprintf ( __ ( "<p>Hey, <strong>%s</strong>, welcome to <strong>Events Manager</strong>! We hope you like it around here.</p>
<p>Now it's time to insert events lists through <a href='%s' title='Widgets page'>widgets</a>, <a href='%s' title='Template tags documentation'>template tags</a> or <a href='%s' title='Shortcodes documentation'>shortcodes</a>.</p>
<p>By the way, have you taken a look at the <a href='%s' title='Change settings'>Settings page</a>? That's where you customize the way events and locations are displayed.</p>
<p>What? Tired of seeing this advice? I hear you, <a href='%s' title='Don't show this advice again'>click here</a> and you won't see this again!</p>", 'dbem' ), $current_user->display_name, get_bloginfo ( 'url' ) . '/wp-admin/widgets.php', 'http://davidebenini.it/wordpress-plugins/events-manager#template-tags', 'http://davidebenini.it/wordpress-plugins/events-manager#shortcodes', get_bloginfo ( 'url' ) . '/wp-admin/admin.php?page=events-manager-options', get_bloginfo ( 'url' ) . '/wp-admin/admin.php?page=events-manager2/events-manager2.php&disable_hello_to_user=true' );
?>
<div id="message" class="updated">
<?php
echo $advice;
?>
</div>
<?php
}
// Moved to admin
function dbem_events_table($events, $limit, $title) {
if (isset ( $_GET ['scope'] ))
$scope = $_GET ['scope'];
else
$scope = "future";
if (($scope != "past") && ($scope != "all"))
$scope = "future";
$events_count = count ( dbem_get_events ( "", $scope ) );
if (isset ( $_GET ['offset'] ))
$offset = $_GET ['offset'];
$use_events_end = get_option ( 'dbem_use_event_end' );
?>
<div class="wrap">
<div id="icon-events" class="icon32"><br />
</div>
<h2><?php
echo $title;
?></h2>
<?php
$say_hello = get_option ( 'dbem_hello_to_user' );
if ($say_hello == 1)
dbem_hello_to_new_user ();
?>
<!--<div id='new-event' class='switch-tab'><a href="<?php
bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager2/events-manager2.php&action=edit_event"><?php
_e ( 'New Event ...', 'dbem' );
?></a></div>-->
<?php
$link = array ();
$link ['past'] = "<a href='" . get_bloginfo ( 'url' ) . "/wp-admin/admin.php?page=events-manager2/events-manager2.php&scope=past&order=desc'>" . __ ( 'Past events', 'dbem' ) . "</a>";
$link ['all'] = " <a href='" . get_bloginfo ( 'url' ) . "/wp-admin/admin.php?page=events-manager2/events-manager2.php&scope=all&order=desc'>" . __ ( 'All events', 'dbem' ) . "</a>";
$link ['future'] = " <a href='" . get_bloginfo ( 'url' ) . "/wp-admin/admin.php?page=events-manager2/events-manager2.php&scope=future'>" . __ ( 'Future events', 'dbem' ) . "</a>";
$scope_names = array ();
$scope_names ['past'] = __ ( 'Past events', 'dbem' );
$scope_names ['all'] = __ ( 'All events', 'dbem' );
$scope_names ['future'] = __ ( 'Future events', 'dbem' );
?>
<form id="posts-filter" action="" method="get"><input type='hidden'
name='page' value='events-manager2/events-manager2.php' />
<ul class="subsubsub">
<li><a href='admin.php' class="current"><?php
_e ( 'Total', 'dbem' );
?> <span
class="count">(<?php
echo (count ( $events ));
?>)</span></a></li>
</ul>
<div class="tablenav">
<div class="alignleft actions"><select name="action">
<option value="-1" selected="selected"><?php
_e ( 'Bulk Actions' );
?></option>
<option value="deleteEvents"><?php
_e ( 'Delete selected' );
?></option>
</select> <input type="submit" value="<?php
_e ( 'Apply' );
?>"
name="doaction2" id="doaction2" class="button-secondary action" /> <select
name="scope">
<?php
foreach ( $scope_names as $key => $value ) {
$selected = "";
if ($key == $scope)
$selected = "selected='selected'";
echo "<option value='$key' $selected>$value</option> ";
}
?>
</select> <input id="post-query-submit" class="button-secondary"
type="submit" value="<?php
_e ( 'Filter' )?>" /></div>
<div class="clear"></div>
<?php
if (empty ( $events )) {
// TODO localize
echo "no events";
} else {
?>
<table class="widefat">
<thead>
<tr>
<th class='manage-column column-cb check-column' scope='col'><input
class='select-all' type="checkbox" value='1' /></th>
<th><?php
_e ( 'Name', 'dbem' );
?></th>
<?php /* Marcus Begin Edit */ ?>
<th></th>
<?php /* Marcus End Edit */ ?>
<th><?php
_e ( 'Location', 'dbem' );
?></th>
<th colspan="2"><?php
_e ( 'Date and time', 'dbem' );
?></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
foreach ( $events as $event ) {
$class = ($i % 2) ? ' class="alternate"' : '';
// FIXME set to american
$localised_date = mysql2date ( __ ( 'D d M Y' ), $event ['event_start_date'] );
$style = "";
$today = date ( "Y-m-d" );
$location_summary = "<b>" . $event ['location_name'] . "</b><br/>" . $event ['location_address'] . " - " . $event ['location_town'];
if ($event ['event_start_date'] < $today)
$style = "style ='background-color: #FADDB7;'";
?>
<tr <?php
echo "$class $style";
?>>
<td><input type='checkbox' class='row-selector'
value='<?php
echo $event ['event_id'];
?>' name='events[]' /></td>
<td><strong><a class="row-title"
href="<?php
bloginfo ( 'url' )?>/wp-admin/admin.php?page=events-manager2/events-manager2.php&action=edit_event&event_id=<?php
echo $event ['event_id'];
?>"><?php
echo ($event ['event_name']);
?></a></strong>
</td>
<td>
<?php /* Marcus Begin Edit */ ?>
<a
href="<?php
bloginfo ( 'url' )?>/wp-admin/admin.php?page=events-manager2/events-manager2.php&action=duplicate_event&event_id=<?php
echo $event ['event_id'];
?>"
title="<?php
_e ( 'Duplicate this event', 'dbem' );
?>"><strong>+</strong></a>
<?php /* Marcus End Edit */ ?>
</td>
<td>
<?php
echo $location_summary;
?>
</td>
<td>
<?php