Events Manager - Version 3.0.97

Version Description

  • correcting wrong version update
Download this release

Release Info

Developer netweblogic
Plugin Icon 128x128 Events Manager
Version 3.0.97
Comparing to
See all releases

Code changes from version 3.0.96 to 3.0.97

Files changed (72) hide show
  1. admin/bookings/em-cancelled.php +132 -135
  2. admin/bookings/em-confirmed.php +139 -142
  3. admin/bookings/em-events.php +178 -177
  4. admin/bookings/em-pending.php +154 -159
  5. admin/bookings/em-person.php +149 -151
  6. admin/bookings/em-rejected.php +132 -135
  7. admin/em-admin.php +265 -162
  8. admin/em-bookings.php +287 -368
  9. admin/em-categories.php +176 -176
  10. admin/em-docs.php +192 -196
  11. admin/em-event.php +626 -724
  12. admin/em-events.php +241 -243
  13. admin/em-help.php +51 -51
  14. admin/em-locations-search.php +2 -6
  15. admin/em-locations.php +267 -263
  16. admin/em-options.php +443 -492
  17. admin/em-people.php +124 -9
  18. buddypress/bp-em-activity.php +0 -106
  19. buddypress/bp-em-admin.php +0 -65
  20. buddypress/bp-em-core.php +0 -175
  21. buddypress/bp-em-notifications.php +0 -157
  22. buddypress/bp-em-templatetags.php +0 -7
  23. buddypress/screens/attending.php +0 -40
  24. buddypress/screens/my-events.php +0 -65
  25. buddypress/screens/my-locations.php +0 -72
  26. buddypress/screens/profile.php +0 -54
  27. buddypress/screens/settings.php +0 -56
  28. classes/em-booking.php +378 -543
  29. classes/em-bookings.php +487 -595
  30. classes/em-calendar.php +365 -367
  31. classes/em-categories.php +156 -157
  32. classes/em-category.php +151 -175
  33. classes/em-event.php +1005 -1156
  34. classes/em-events.php +253 -300
  35. classes/em-location.php +306 -387
  36. classes/em-locations.php +212 -220
  37. classes/em-mailer.php +79 -79
  38. classes/em-map.php +59 -59
  39. classes/em-notices.php +0 -170
  40. classes/em-object.php +485 -553
  41. classes/em-people.php +128 -66
  42. classes/em-permalinks.php +0 -200
  43. classes/em-person.php +153 -68
  44. classes/em-recurrence.php +89 -0
  45. classes/em-ticket-booking.php +0 -209
  46. classes/em-ticket.php +0 -333
  47. classes/em-tickets-bookings.php +0 -261
  48. classes/em-tickets.php +0 -204
  49. classes/phpmailer/class.phpmailer.php +1506 -1506
  50. classes/phpmailer/class.smtp.php +1045 -1045
  51. classes/phpmailer/language/phpmailer.lang-br.php +21 -21
  52. classes/phpmailer/language/phpmailer.lang-ca.php +21 -21
  53. classes/phpmailer/language/phpmailer.lang-cz.php +23 -23
  54. classes/phpmailer/language/phpmailer.lang-de.php +23 -23
  55. classes/phpmailer/language/phpmailer.lang-dk.php +23 -23
  56. classes/phpmailer/language/phpmailer.lang-en.php +23 -23
  57. classes/phpmailer/language/phpmailer.lang-es.php +22 -22
  58. classes/phpmailer/language/phpmailer.lang-fi.php +22 -22
  59. classes/phpmailer/language/phpmailer.lang-fo.php +25 -25
  60. classes/phpmailer/language/phpmailer.lang-fr.php +24 -24
  61. classes/phpmailer/language/phpmailer.lang-hu.php +22 -22
  62. classes/phpmailer/language/phpmailer.lang-it.php +28 -28
  63. classes/phpmailer/language/phpmailer.lang-nl.php +22 -22
  64. classes/phpmailer/language/phpmailer.lang-no.php +23 -23
  65. classes/phpmailer/language/phpmailer.lang-pl.php +23 -23
  66. classes/phpmailer/language/phpmailer.lang-ro.php +23 -23
  67. classes/phpmailer/language/phpmailer.lang-ru.php +23 -23
  68. classes/phpmailer/language/phpmailer.lang-se.php +23 -23
  69. classes/phpmailer/language/phpmailer.lang-tr.php +24 -24
  70. em-actions.php +0 -241
  71. em-ajax.php +101 -0
  72. em-bookings.php +141 -262
admin/bookings/em-cancelled.php CHANGED
@@ -1,136 +1,133 @@
1
- <?php
2
- /**
3
- * Generates a "widget" table of confirmed bookings for a specific event.
4
- *
5
- * @param int $event_id
6
- */
7
- function em_bookings_cancelled_table(){
8
- global $EM_Event, $EM_Ticket, $wpdb, $current_user;
9
-
10
- $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_cancelled_table' );
11
- $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
12
- $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
13
- $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
14
- $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
15
- $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
16
-
17
- if( is_object($EM_Ticket) ){
18
- $EM_Bookings = $EM_Ticket->get_bookings()->get_cancelled_bookings();
19
- }else{
20
- if( is_object($EM_Event) ){
21
- $EM_Bookings = $EM_Event->get_bookings()->get_cancelled_bookings();
22
- }else{
23
- return false;
24
- }
25
- }
26
- $bookings_count = (is_array($EM_Bookings->bookings)) ? count($EM_Bookings->bookings):0;
27
- ?>
28
- <div class='wrap em_bookings_pending_table em_obj'>
29
- <form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
30
- <input type="hidden" name="em_obj" value="em_bookings_pending_table" />
31
- <!--
32
- <ul class="subsubsub">
33
- <li>
34
- <a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
35
- </li>
36
- </ul>
37
- <p class="search-box">
38
- <label class="screen-reader-text" for="post-search-input"><?php _e('Search'); ?>:</label>
39
- <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? $_GET['em_search']:''; ?>" />
40
- <input type="submit" value="<?php _e('Search'); ?>" class="button" />
41
- </p>
42
- -->
43
- <?php if ( $bookings_count >= $limit ) : ?>
44
- <div class='tablenav'>
45
- <!--
46
- <div class="alignleft actions">
47
- <select name="action">
48
- <option value="-1" selected="selected">
49
- <?php _e('Bulk Actions'); ?>
50
- </option>
51
- <option value="approve">
52
- <?php _e('Approve', 'dbem'); ?>
53
- </option>
54
- <option value="decline">
55
- <?php _e('Decline', 'dbem'); ?>
56
- </option>
57
- </select>
58
- <input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
59
- </div>
60
- -->
61
- <!--
62
- <div class="view-switch">
63
- <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
64
- </div>
65
- -->
66
- <?php
67
- if ( $bookings_count >= $limit ) {
68
- $bookings_nav = em_admin_paginate( $bookings_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
69
- echo $bookings_nav;
70
- }
71
- ?>
72
- <div class="clear"></div>
73
- </div>
74
- <?php endif; ?>
75
- <div class="clear"></div>
76
- <?php if( $bookings_count > 0 ): ?>
77
- <div class='table-wrap'>
78
- <table id='dbem-bookings-table' class='widefat post fixed'>
79
- <thead>
80
- <tr>
81
- <th class='manage-column column-cb check-column' scope='col'>
82
- <input class='select-all' type="checkbox" value='1' />
83
- </th>
84
- <th class='manage-column' scope='col'>Booker</th>
85
- <th class='manage-column' scope='col'>E-mail</th>
86
- <th class='manage-column' scope='col'>Phone number</th>
87
- <th class='manage-column' scope='col'>Spaces</th>
88
- <th class='manage-column' scope='col'>&nbsp;</th>
89
- </tr>
90
- </thead>
91
- <tbody>
92
- <?php
93
- $rowno = 0;
94
- $event_count = 0;
95
- foreach ($EM_Bookings->bookings as $EM_Booking) {
96
- if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
97
- $rowno++;
98
- ?>
99
- <tr>
100
- <th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->id ?>' name='bookings[]'/></th>
101
- <td><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person->ID; ?>"><?php echo $EM_Booking->person->display_name ?></a></td>
102
- <td><?php echo $EM_Booking->person->user_email ?></td>
103
- <td><?php echo $EM_Booking->person->phone ?></td>
104
- <td><?php echo $EM_Booking->get_spaces() ?></td>
105
- <td>
106
- <?php
107
- $approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'booking_id'=>$EM_Booking->id));
108
- $delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->id));
109
- ?>
110
- <a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Restore','dbem'); ?></a> |
111
- <a class="em-bookings-edit" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->id; ?>"><?php _e('Edit/View','dbem'); ?></a> |
112
- <a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a>
113
- </td>
114
- </tr>
115
- <?php
116
- }
117
- $event_count++;
118
- }
119
- ?>
120
- </tbody>
121
- </table>
122
- </div>
123
- <?php else: ?>
124
- <?php _e('No cancelled bookings.', 'dbem'); ?>
125
- <?php endif; ?>
126
- </form>
127
- <?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
128
- <div class='tablenav'>
129
- <?php echo $bookings_nav; ?>
130
- <div class="clear"></div>
131
- </div>
132
- <?php endif; ?>
133
- </div>
134
- <?php
135
- }
136
  ?>
1
+ <?php
2
+ /**
3
+ * Generates a "widget" table of confirmed bookings for a specific event.
4
+ *
5
+ * @param int $event_id
6
+ */
7
+ function em_bookings_cancelled_table(){
8
+ global $EM_Event, $wpdb, $current_user;
9
+
10
+ $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_cancelled_table' );
11
+ $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
12
+ $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
13
+ $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
14
+ $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
15
+ $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
16
+
17
+ if( is_object($EM_Event) ){
18
+ $bookings = $EM_Event->get_bookings()->get_cancelled_bookings();
19
+ }else{
20
+ return false;
21
+ }
22
+ $bookings_count = (is_array($bookings)) ? count($bookings):0;
23
+ ?>
24
+ <div class='wrap em_bookings_pending_table em_obj'>
25
+ <form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
26
+ <input type="hidden" name="em_obj" value="em_bookings_pending_table" />
27
+ <!--
28
+ <ul class="subsubsub">
29
+ <li>
30
+ <a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
31
+ </li>
32
+ </ul>
33
+ <p class="search-box">
34
+ <label class="screen-reader-text" for="post-search-input"><?php _e('Search'); ?>:</label>
35
+ <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? $_GET['em_search']:''; ?>" />
36
+ <input type="submit" value="<?php _e('Search'); ?>" class="button" />
37
+ </p>
38
+ -->
39
+ <?php if ( $bookings_count >= $limit ) : ?>
40
+ <div class='tablenav'>
41
+ <!--
42
+ <div class="alignleft actions">
43
+ <select name="action">
44
+ <option value="-1" selected="selected">
45
+ <?php _e('Bulk Actions'); ?>
46
+ </option>
47
+ <option value="approve">
48
+ <?php _e('Approve', 'dbem'); ?>
49
+ </option>
50
+ <option value="decline">
51
+ <?php _e('Decline', 'dbem'); ?>
52
+ </option>
53
+ </select>
54
+ <input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
55
+ </div>
56
+ -->
57
+ <!--
58
+ <div class="view-switch">
59
+ <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
60
+ </div>
61
+ -->
62
+ <?php
63
+ if ( $bookings_count >= $limit ) {
64
+ $page_link_template = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%', 'em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
65
+ $bookings_nav = em_admin_paginate( $page_link_template, $bookings_count, $limit, $page, 5);
66
+ echo $bookings_nav;
67
+ }
68
+ ?>
69
+ <div class="clear"></div>
70
+ </div>
71
+ <?php endif; ?>
72
+ <div class="clear"></div>
73
+ <?php if( $bookings_count > 0 ): ?>
74
+ <div class='table-wrap'>
75
+ <table id='dbem-bookings-table' class='widefat post fixed'>
76
+ <thead>
77
+ <tr>
78
+ <th class='manage-column column-cb check-column' scope='col'>
79
+ <input class='select-all' type="checkbox" value='1' />
80
+ </th>
81
+ <th class='manage-column' scope='col'>Booker</th>
82
+ <th class='manage-column' scope='col'>E-mail</th>
83
+ <th class='manage-column' scope='col'>Phone number</th>
84
+ <th class='manage-column' scope='col'>Spaces</th>
85
+ <th class='manage-column' scope='col'>&nbsp;</th>
86
+ </tr>
87
+ </thead>
88
+ <tbody>
89
+ <?php
90
+ $rowno = 0;
91
+ $event_count = 0;
92
+ foreach ($bookings as $EM_Booking) {
93
+ if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
94
+ $rowno++;
95
+ ?>
96
+ <tr>
97
+ <th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->id ?>' name='bookings[]'/></th>
98
+ <td><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person->id; ?>"><?php echo $EM_Booking->person->name ?></a></td>
99
+ <td><?php echo $EM_Booking->person->email ?></td>
100
+ <td><?php echo $EM_Booking->person->phone ?></td>
101
+ <td><?php echo $EM_Booking->seats ?></td>
102
+ <td>
103
+ <?php
104
+ $approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'booking_id'=>$EM_Booking->id));
105
+ $delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->id));
106
+ ?>
107
+ <a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Restore','dbem'); ?></a> |
108
+ <a class="em-bookings-edit" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->id; ?>"><?php _e('Edit'); ?></a> |
109
+ <a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a>
110
+ </td>
111
+ </tr>
112
+ <?php
113
+ }
114
+ $event_count++;
115
+ }
116
+ ?>
117
+ </tbody>
118
+ </table>
119
+ </div>
120
+ <?php else: ?>
121
+ <?php _e('No cancelled bookings.', 'dbem'); ?>
122
+ <?php endif; ?>
123
+ </form>
124
+ <?php if( !empty($bookings_nav) ) : ?>
125
+ <div class='tablenav'>
126
+ <?php echo $bookings_nav; ?>
127
+ <div class="clear"></div>
128
+ </div>
129
+ <?php endif; ?>
130
+ </div>
131
+ <?php
132
+ }
 
 
 
133
  ?>
admin/bookings/em-confirmed.php CHANGED
@@ -1,143 +1,140 @@
1
- <?php
2
-
3
- /**
4
- * Generates a "widget" table of confirmed bookings for a specific event.
5
- *
6
- * @param int $event_id
7
- */
8
- function em_bookings_confirmed_table(){
9
- global $EM_Event, $EM_Ticket, $wpdb, $current_user;
10
-
11
- $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_confirmed_table' );
12
- $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
13
- $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
14
- $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
15
- $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
16
- $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
17
-
18
- if( is_object($EM_Ticket) ){
19
- $EM_Bookings = $EM_Ticket->get_bookings()->get_bookings();
20
- }else{
21
- if( is_object($EM_Event) ){
22
- $EM_Bookings = $EM_Event->get_bookings()->get_bookings();
23
- }else{
24
- return false;
25
- }
26
- }
27
- $bookings_count = (is_array($EM_Bookings->bookings)) ? count($EM_Bookings->bookings):0;
28
- ?>
29
- <div class='wrap em_bookings_pending_table em_obj'>
30
- <form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
31
- <input type="hidden" name="em_obj" value="em_bookings_pending_table" />
32
- <!--
33
- <ul class="subsubsub">
34
- <li>
35
- <a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
36
- </li>
37
- </ul>
38
- <p class="search-box">
39
- <label class="screen-reader-text" for="post-search-input"><?php _e('Search'); ?>:</label>
40
- <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? $_GET['em_search']:''; ?>" />
41
- <input type="submit" value="<?php _e('Search'); ?>" class="button" />
42
- </p>
43
- -->
44
- <?php if ( $bookings_count >= $limit ) : ?>
45
- <div class='tablenav'>
46
- <!--
47
- <div class="alignleft actions">
48
- <select name="action">
49
- <option value="-1" selected="selected">
50
- <?php _e('Bulk Actions'); ?>
51
- </option>
52
- <option value="approve">
53
- <?php _e('Approve', 'dbem'); ?>
54
- </option>
55
- <option value="decline">
56
- <?php _e('Decline', 'dbem'); ?>
57
- </option>
58
- </select>
59
- <input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
60
- </div>
61
- -->
62
- <!--
63
- <div class="view-switch">
64
- <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
65
- </div>
66
- -->
67
- <?php
68
- if ( $bookings_count >= $limit ) {
69
- $bookings_nav = em_admin_paginate($bookings_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
70
- echo $bookings_nav;
71
- }
72
- ?>
73
- <div class="clear"></div>
74
- </div>
75
- <?php endif; ?>
76
- <div class="clear"></div>
77
- <?php if( $bookings_count > 0 ): ?>
78
- <div class='table-wrap'>
79
- <table id='dbem-bookings-table' class='widefat post fixed'>
80
- <thead>
81
- <tr>
82
- <th class='manage-column column-cb check-column' scope='col'>
83
- <input class='select-all' type="checkbox" value='1' />
84
- </th>
85
- <th class='manage-column' scope='col'>Booker</th>
86
- <th class='manage-column' scope='col'>E-mail</th>
87
- <th class='manage-column' scope='col'>Phone number</th>
88
- <th class='manage-column' scope='col'>Spaces</th>
89
- <th class='manage-column' scope='col'>&nbsp;</th>
90
- </tr>
91
- </thead>
92
- <tbody>
93
- <?php
94
- $rowno = 0;
95
- $event_count = 0;
96
- foreach ($EM_Bookings->bookings as $EM_Booking) {
97
- if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
98
- $rowno++;
99
- ?>
100
- <tr>
101
- <th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->id ?>' name='bookings[]'/></th>
102
- <td><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person_id; ?>"><?php echo $EM_Booking->person->display_name ?></a></td>
103
- <td><?php echo $EM_Booking->person->user_email ?></td>
104
- <td><?php echo $EM_Booking->person->phone ?></td>
105
- <td><?php echo $EM_Booking->get_spaces() ?></td>
106
- <td>
107
- <?php
108
- $unapprove_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_unapprove', 'booking_id'=>$EM_Booking->id));
109
- $reject_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_reject', 'booking_id'=>$EM_Booking->id));
110
- $delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->id));
111
- ?>
112
- <?php if( current_user_can('manage_bookings') ): ?>
113
- <a class="em-bookings-unapprove" href="<?php echo $unapprove_url ?>"><?php _e('Unapprove','dbem'); ?></a> |
114
- <?php else: ?>
115
- <a class="em-bookings-reject" href="<?php echo $reject_url ?>"><?php _e('Reject','dbem'); ?></a> |
116
- <?php endif; ?>
117
- <span class="trash"><a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a></span> |
118
- <a class="em-bookings-edit" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->id; ?>"><?php _e('Edit/View','dbem'); ?></a>
119
- </td>
120
- </tr>
121
- <?php
122
- }
123
- $event_count++;
124
- }
125
- ?>
126
- </tbody>
127
- </table>
128
- </div>
129
- <?php else: ?>
130
- <?php _e('No confirmed bookings.', 'dbem'); ?>
131
- <?php endif; ?>
132
- </form>
133
- <?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
134
- <div class='tablenav'>
135
- <?php echo $bookings_nav; ?>
136
- <div class="clear"></div>
137
- </div>
138
- <?php endif; ?>
139
- </div>
140
- <?php
141
-
142
- }
143
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Generates a "widget" table of confirmed bookings for a specific event.
5
+ *
6
+ * @param int $event_id
7
+ */
8
+ function em_bookings_confirmed_table(){
9
+ global $EM_Event, $wpdb, $current_user;
10
+
11
+ $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_confirmed_table' );
12
+ $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
13
+ $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
14
+ $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
15
+ $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
16
+ $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
17
+
18
+ if( is_object($EM_Event) ){
19
+ $bookings = $EM_Event->get_bookings()->get_bookings();
20
+ }else{
21
+ return false;
22
+ }
23
+ $bookings_count = (is_array($bookings)) ? count($bookings):0;
24
+ ?>
25
+ <div class='wrap em_bookings_pending_table em_obj'>
26
+ <form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
27
+ <input type="hidden" name="em_obj" value="em_bookings_pending_table" />
28
+ <!--
29
+ <ul class="subsubsub">
30
+ <li>
31
+ <a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
32
+ </li>
33
+ </ul>
34
+ <p class="search-box">
35
+ <label class="screen-reader-text" for="post-search-input"><?php _e('Search'); ?>:</label>
36
+ <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? $_GET['em_search']:''; ?>" />
37
+ <input type="submit" value="<?php _e('Search'); ?>" class="button" />
38
+ </p>
39
+ -->
40
+ <?php if ( $bookings_count >= $limit ) : ?>
41
+ <div class='tablenav'>
42
+ <!--
43
+ <div class="alignleft actions">
44
+ <select name="action">
45
+ <option value="-1" selected="selected">
46
+ <?php _e('Bulk Actions'); ?>
47
+ </option>
48
+ <option value="approve">
49
+ <?php _e('Approve', 'dbem'); ?>
50
+ </option>
51
+ <option value="decline">
52
+ <?php _e('Decline', 'dbem'); ?>
53
+ </option>
54
+ </select>
55
+ <input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
56
+ </div>
57
+ -->
58
+ <!--
59
+ <div class="view-switch">
60
+ <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
61
+ </div>
62
+ -->
63
+ <?php
64
+ if ( $bookings_count >= $limit ) {
65
+ $page_link_template = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%', 'em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
66
+ $bookings_nav = em_admin_paginate( $page_link_template, $bookings_count, $limit, $page, 5);
67
+ echo $bookings_nav;
68
+ }
69
+ ?>
70
+ <div class="clear"></div>
71
+ </div>
72
+ <?php endif; ?>
73
+ <div class="clear"></div>
74
+ <?php if( $bookings_count > 0 ): ?>
75
+ <div class='table-wrap'>
76
+ <table id='dbem-bookings-table' class='widefat post fixed'>
77
+ <thead>
78
+ <tr>
79
+ <th class='manage-column column-cb check-column' scope='col'>
80
+ <input class='select-all' type="checkbox" value='1' />
81
+ </th>
82
+ <th class='manage-column' scope='col'>Booker</th>
83
+ <th class='manage-column' scope='col'>E-mail</th>
84
+ <th class='manage-column' scope='col'>Phone number</th>
85
+ <th class='manage-column' scope='col'>Spaces</th>
86
+ <th class='manage-column' scope='col'>&nbsp;</th>
87
+ </tr>
88
+ </thead>
89
+ <tbody>
90
+ <?php
91
+ $rowno = 0;
92
+ $event_count = 0;
93
+ foreach ($bookings as $EM_Booking) {
94
+ if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
95
+ $rowno++;
96
+ ?>
97
+ <tr>
98
+ <th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->id ?>' name='bookings[]'/></th>
99
+ <td><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person_id; ?>"><?php echo $EM_Booking->person->name ?></a></td>
100
+ <td><?php echo $EM_Booking->person->email ?></td>
101
+ <td><?php echo $EM_Booking->person->phone ?></td>
102
+ <td><?php echo $EM_Booking->seats ?></td>
103
+ <td>
104
+ <?php
105
+ $unapprove_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_unapprove', 'booking_id'=>$EM_Booking->id));
106
+ $reject_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_reject', 'booking_id'=>$EM_Booking->id));
107
+ $delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->id));
108
+ ?>
109
+ <?php if( get_option('dbem_bookings_approval') ): ?>
110
+ <a class="em-bookings-unapprove" href="<?php echo $unapprove_url ?>"><?php _e('Unapprove','dbem'); ?></a> |
111
+ <?php else: ?>
112
+ <a class="em-bookings-reject" href="<?php echo $reject_url ?>"><?php _e('Reject','dbem'); ?></a> |
113
+ <?php endif; ?>
114
+ <a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a> |
115
+ <a class="em-bookings-edit" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->id; ?>"><?php _e('Edit'); ?></a>
116
+ </td>
117
+ </tr>
118
+ <?php
119
+ }
120
+ $event_count++;
121
+ }
122
+ ?>
123
+ </tbody>
124
+ </table>
125
+ </div>
126
+ <?php else: ?>
127
+ <?php _e('No confirmed bookings.', 'dbem'); ?>
128
+ <?php endif; ?>
129
+ </form>
130
+ <?php if( !empty($bookings_nav) ) : ?>
131
+ <div class='tablenav'>
132
+ <?php echo $bookings_nav; ?>
133
+ <div class="clear"></div>
134
+ </div>
135
+ <?php endif; ?>
136
+ </div>
137
+ <?php
138
+
139
+ }
 
 
 
140
  ?>
admin/bookings/em-events.php CHANGED
@@ -1,178 +1,179 @@
1
- <?php
2
-
3
- /**
4
- * Determines whether to show event page or events page, and saves any updates to the event or events
5
- * @return null
6
- */
7
- function em_bookings_events_table() {
8
- //TODO Simplify panel for events, use form flags to detect certain actions (e.g. submitted, etc)
9
- global $wpdb;
10
- global $EM_Event;
11
-
12
- $scope_names = array (
13
- 'past' => __ ( 'Past events', 'dbem' ),
14
- 'all' => __ ( 'All events', 'dbem' ),
15
- 'future' => __ ( 'Future events', 'dbem' )
16
- );
17
-
18
- $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_events_table' );
19
- $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
20
- $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
21
- $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
22
- $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
23
- $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
24
- $scope = ( $action_scope && !empty($_GET ['scope']) && array_key_exists($_GET ['scope'], $scope_names) ) ? $_GET ['scope']:'future';
25
-
26
- // No action, only showing the events list
27
- switch ($scope) {
28
- case "past" :
29
- $title = __ ( 'Past Events', 'dbem' );
30
- break;
31
- case "all" :
32
- $title = __ ( 'All Events', 'dbem' );
33
- break;
34
- default :
35
- $title = __ ( 'Future Events', 'dbem' );
36
- $scope = "future";
37
- }
38
- $events = EM_Events::get( array('scope'=>$scope, 'limit'=>0, 'order'=>$order, 'rsvp'=>true ) );
39
- $events_count = count ( $events );
40
-
41
- $use_events_end = get_option ( 'dbem_use_event_end' );
42
- ?>
43
- <div class="wrap em_bookings_events_table em_obj">
44
- <form id="posts-filter" action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="get">
45
- <input type="hidden" name="em_obj" value="em_bookings_events_table" />
46
- <?php if(!empty($_GET['page'])): ?>
47
- <input type='hidden' name='page' value='events-manager-bookings' />
48
- <?php endif; ?>
49
- <ul class="subsubsub">
50
- <li><a href='#' class="current"><?php _e ( 'Total', 'dbem' ); ?> <span class="count">(<?php echo (count ( $events )); ?>)</span></a></li>
51
- </ul>
52
- <div class="tablenav">
53
- <div class="alignleft actions">
54
- <!--
55
- <select name="action">
56
- <option value="-1" selected="selected"><?php _e ( 'Bulk Actions' ); ?></option>
57
- <option value="deleteEvents"><?php _e ( 'Delete selected','dbem' ); ?></option>
58
- </select>
59
- <input type="submit" value="<?php _e ( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
60
- -->
61
- <select name="scope">
62
- <?php
63
- foreach ( $scope_names as $key => $value ) {
64
- $selected = "";
65
- if ($key == $scope)
66
- $selected = "selected='selected'";
67
- echo "<option value='$key' $selected>$value</option> ";
68
- }
69
- ?>
70
- </select>
71
- <input id="post-query-submit" class="button-secondary" type="submit" value="<?php _e ( 'Filter' )?>" />
72
- </div>
73
- <!--
74
- <div class="view-switch">
75
- <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
76
- </div>
77
- -->
78
- <?php
79
- if ( $events_count >= $limit ) {
80
- $events_nav = em_admin_paginate( $events_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_events_table'));
81
- echo $events_nav;
82
- }
83
- ?>
84
- <br class="clear" />
85
- </div>
86
-
87
- <?php
88
- if (empty ( $events )) {
89
- // TODO localize
90
- _e ( 'no events','dbem' );
91
- } else {
92
- ?>
93
- <div class='table-wrap'>
94
- <table class="widefat">
95
- <thead>
96
- <tr>
97
- <th class='manage-column column-cb check-column' scope='col'>
98
- <input class='select-all' type="checkbox" value='1' />
99
- </th>
100
- <th><?php _e ( 'Event', 'dbem' ); ?></th>
101
- <th><?php _e ( 'Date and time', 'dbem' ); ?></th>
102
- </tr>
103
- </thead>
104
- <tbody>
105
- <?php
106
- $rowno = 0;
107
- $event_count = 0;
108
- foreach ( $events as $event ) {
109
- /* @var $event EM_Event */
110
- if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
111
- $rowno++;
112
- $class = ($rowno % 2) ? ' class="alternate"' : '';
113
- // FIXME set to american
114
- $localised_start_date = date_i18n('D d M Y', $event->start);
115
- $localised_end_date = date_i18n('D d M Y', $event->end);
116
- $style = "";
117
- $today = date ( "Y-m-d" );
118
-
119
- if ($event->start_date < $today && $event->end_date < $today){
120
- $style = "style ='background-color: #FADDB7;'";
121
- }
122
- ?>
123
- <tr <?php echo "$class $style"; ?>>
124
-
125
- <td>
126
- <input type='checkbox' class='row-selector' value='<?php echo $event->id; ?>' name='events[]' />
127
- </td>
128
- <td>
129
- <strong>
130
- <a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php echo $event->id ?>"><?php echo ($event->name); ?></a>
131
- </strong>
132
- &ndash;
133
- <?php _e("Booked Spaces",'dbem') ?>: <?php echo $event->get_bookings()->get_booked_spaces()."/".$event->get_spaces() ?>
134
- <?php if( get_option('dbem_bookings_approval') == 1 ) : ?>
135
- | <?php _e("Pending",'dbem') ?>: <?php echo $event->get_bookings()->get_pending_spaces(); ?>
136
- <?php endif; ?>
137
- </td>
138
-
139
- <td>
140
- <?php echo $localised_start_date; ?>
141
- <?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
142
- &ndash;
143
- <?php
144
- //TODO Should 00:00 - 00:00 be treated as an all day event?
145
- echo substr ( $event->start_time, 0, 5 ) . " - " . substr ( $event->end_time, 0, 5 );
146
- ?>
147
- </td>
148
- </tr>
149
- <?php
150
- }
151
- $event_count++;
152
- }
153
- ?>
154
- </tbody>
155
- </table>
156
- </div>
157
- <?php
158
- } // end of table
159
- ?>
160
- <div class='tablenav'>
161
- <div class="alignleft actions">
162
- <br class='clear' />
163
- </div>
164
- <?php if (!empty($events_nav) && $events_count >= $limit ) : ?>
165
- <div class="tablenav-pages">
166
- <?php
167
- echo $events_nav;
168
- ?>
169
- </div>
170
- <?php endif; ?>
171
- <br class='clear' />
172
- </div>
173
- </form>
174
- </div>
175
- <?php
176
- }
177
-
 
178
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Determines whether to show event page or events page, and saves any updates to the event or events
5
+ * @return null
6
+ */
7
+ function em_bookings_events_table() {
8
+ //TODO Simplify panel for events, use form flags to detect certain actions (e.g. submitted, etc)
9
+ global $wpdb;
10
+ global $EM_Event;
11
+
12
+ $scope_names = array (
13
+ 'past' => __ ( 'Past events', 'dbem' ),
14
+ 'all' => __ ( 'All events', 'dbem' ),
15
+ 'future' => __ ( 'Future events', 'dbem' )
16
+ );
17
+
18
+ $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_events_table' );
19
+ $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
20
+ $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
21
+ $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
22
+ $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
23
+ $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
24
+ $scope = ( $action_scope && !empty($_GET ['scope']) && array_key_exists($_GET ['scope'], $scope_names) ) ? $_GET ['scope']:'future';
25
+
26
+ // No action, only showing the events list
27
+ switch ($scope) {
28
+ case "past" :
29
+ $title = __ ( 'Past Events', 'dbem' );
30
+ break;
31
+ case "all" :
32
+ $title = __ ( 'All Events', 'dbem' );
33
+ break;
34
+ default :
35
+ $title = __ ( 'Future Events', 'dbem' );
36
+ $scope = "future";
37
+ }
38
+ $events = EM_Events::get( array('scope'=>$scope, 'limit'=>0, 'order'=>$order, 'rsvp'=>true ) );
39
+ $events_count = count ( $events );
40
+
41
+ $use_events_end = get_option ( 'dbem_use_event_end' );
42
+ ?>
43
+ <div class="wrap em_bookings_events_table em_obj">
44
+ <form id="posts-filter" action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="get">
45
+ <input type="hidden" name="em_obj" value="em_bookings_events_table" />
46
+ <?php if(!empty($_GET['page'])): ?>
47
+ <input type='hidden' name='page' value='events-manager-bookings' />
48
+ <?php endif; ?>
49
+ <ul class="subsubsub">
50
+ <li><a href='#' class="current"><?php _e ( 'Total', 'dbem' ); ?> <span class="count">(<?php echo (count ( $events )); ?>)</span></a></li>
51
+ </ul>
52
+ <div class="tablenav">
53
+ <div class="alignleft actions">
54
+ <!--
55
+ <select name="action">
56
+ <option value="-1" selected="selected"><?php _e ( 'Bulk Actions' ); ?></option>
57
+ <option value="deleteEvents"><?php _e ( 'Delete selected','dbem' ); ?></option>
58
+ </select>
59
+ <input type="submit" value="<?php _e ( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
60
+ -->
61
+ <select name="scope">
62
+ <?php
63
+ foreach ( $scope_names as $key => $value ) {
64
+ $selected = "";
65
+ if ($key == $scope)
66
+ $selected = "selected='selected'";
67
+ echo "<option value='$key' $selected>$value</option> ";
68
+ }
69
+ ?>
70
+ </select>
71
+ <input id="post-query-submit" class="button-secondary" type="submit" value="<?php _e ( 'Filter' )?>" />
72
+ </div>
73
+ <!--
74
+ <div class="view-switch">
75
+ <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
76
+ </div>
77
+ -->
78
+ <?php
79
+ if ( $events_count >= $limit ) {
80
+ $page_link_template = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%', 'em_ajax'=>0, 'em_obj'=>'em_bookings_events_table'));
81
+ $events_nav = em_admin_paginate( $page_link_template, $events_count, $limit, $page, 5);
82
+ echo $events_nav;
83
+ }
84
+ ?>
85
+ <br class="clear" />
86
+ </div>
87
+
88
+ <?php
89
+ if (empty ( $events )) {
90
+ // TODO localize
91
+ _e ( 'no events','dbem' );
92
+ } else {
93
+ ?>
94
+ <div class='table-wrap'>
95
+ <table class="widefat">
96
+ <thead>
97
+ <tr>
98
+ <th class='manage-column column-cb check-column' scope='col'>
99
+ <input class='select-all' type="checkbox" value='1' />
100
+ </th>
101
+ <th><?php _e ( 'Event', 'dbem' ); ?></th>
102
+ <th><?php _e ( 'Date and time', 'dbem' ); ?></th>
103
+ </tr>
104
+ </thead>
105
+ <tbody>
106
+ <?php
107
+ $rowno = 0;
108
+ $event_count = 0;
109
+ foreach ( $events as $event ) {
110
+ /* @var $event EM_Event */
111
+ if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
112
+ $rowno++;
113
+ $class = ($rowno % 2) ? ' class="alternate"' : '';
114
+ // FIXME set to american
115
+ $localised_start_date = date_i18n('D d M Y', $event->start);
116
+ $localised_end_date = date_i18n('D d M Y', $event->end);
117
+ $style = "";
118
+ $today = date ( "Y-m-d" );
119
+
120
+ if ($event->start_date < $today && $event->end_date < $today){
121
+ $style = "style ='background-color: #FADDB7;'";
122
+ }
123
+ ?>
124
+ <tr <?php echo "$class $style"; ?>>
125
+
126
+ <td>
127
+ <input type='checkbox' class='row-selector' value='<?php echo $event->id; ?>' name='events[]' />
128
+ </td>
129
+ <td>
130
+ <strong>
131
+ <a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php echo $event->id ?>"><?php echo ($event->name); ?></a>
132
+ </strong>
133
+ &ndash;
134
+ <?php _e("Booked Seats",'dbem') ?>: <?php echo $event->get_bookings()->get_booked_seats()."/".$event->seats ?>
135
+ <?php if( get_option('dbem_bookings_approval') == 1 ) : ?>
136
+ | <?php _e("Pending",'dbem') ?>: <?php echo $event->get_bookings()->get_pending_seats(); ?>
137
+ <?php endif; ?>
138
+ </td>
139
+
140
+ <td>
141
+ <?php echo $localised_start_date; ?>
142
+ <?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
143
+ &ndash;
144
+ <?php
145
+ //TODO Should 00:00 - 00:00 be treated as an all day event?
146
+ echo substr ( $event->start_time, 0, 5 ) . " - " . substr ( $event->end_time, 0, 5 );
147
+ ?>
148
+ </td>
149
+ </tr>
150
+ <?php
151
+ }
152
+ $event_count++;
153
+ }
154
+ ?>
155
+ </tbody>
156
+ </table>
157
+ </div>
158
+ <?php
159
+ } // end of table
160
+ ?>
161
+ <div class='tablenav'>
162
+ <div class="alignleft actions">
163
+ <br class='clear' />
164
+ </div>
165
+ <?php if( !empty($events_nav) ) : ?>
166
+ <div class="tablenav-pages">
167
+ <?php
168
+ echo $events_nav;
169
+ ?>
170
+ </div>
171
+ <?php endif; ?>
172
+ <br class='clear' />
173
+ </div>
174
+ </form>
175
+ </div>
176
+ <?php
177
+ }
178
+
179
  ?>
admin/bookings/em-pending.php CHANGED
@@ -1,160 +1,155 @@
1
- <?php
2
-
3
- /**
4
- * Generates a "widget" table of pending bookings with some quick admin operation options.
5
- * If event id supplied then only pending bookings for that event will show.
6
- *
7
- * @param int $event_id
8
- */
9
- function em_bookings_pending_table($event_id = false){
10
- global $EM_Event, $EM_Ticket, $wpdb, $current_user;
11
-
12
- if( get_option('dbem_bookings_approval') == 0 ){
13
- return false;
14
- }
15
-
16
- $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_pending_table' );
17
- $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
18
- $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
19
- $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
20
- $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
21
- $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
22
-
23
- if( is_object($EM_Ticket) ){
24
- $EM_Bookings = $EM_Ticket->get_bookings()->get_pending_bookings();
25
- }else{
26
- if( is_object($EM_Event) ){
27
- $EM_Bookings = $EM_Event->get_bookings()->get_pending_bookings();
28
- }else{
29
- //To optimize performance, we can do one query here for all pending bookings to show.
30
- $EM_Bookings = EM_Bookings::get(array('status'=>0));
31
- $events = array();
32
- //Now let's create events and bookings for this:
33
- foreach($EM_Bookings->bookings as $EM_Booking){
34
- //create event
35
- if( !array_key_exists($EM_Booking->event_id,$events) ){
36
- $events[$EM_Booking->event_id] = new EM_Event($EM_Booking->event_id);
37
- }
38
- }
39
- }
40
- }
41
- $bookings_count = (is_array($EM_Bookings->bookings)) ? count($EM_Bookings->bookings):0;
42
- ?>
43
- <div class='wrap em_bookings_pending_table em_obj'>
44
- <form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
45
- <input type="hidden" name="em_obj" value="em_bookings_pending_table" />
46
- <!--
47
- <ul class="subsubsub">
48
- <li>
49
- <a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
50
- </li>
51
- </ul>
52
- <p class="search-box">
53
- <label class="screen-reader-text" for="post-search-input"><?php _e('Search'); ?>:</label>
54
- <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? $_GET['em_search']:''; ?>" />
55
- <input type="submit" value="<?php _e('Search'); ?>" class="button" />
56
- </p>
57
- -->
58
- <?php if ( $bookings_count >= $limit ) : ?>
59
- <div class='tablenav'>
60
- <!--
61
- <div class="alignleft actions">
62
- <select name="action">
63
- <option value="-1" selected="selected">
64
- <?php _e('Bulk Actions'); ?>
65
- </option>
66
- <option value="approve">
67
- <?php _e('Approve', 'dbem'); ?>
68
- </option>
69
- <option value="decline">
70
- <?php _e('Decline', 'dbem'); ?>
71
- </option>
72
- </select>
73
- <input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
74
- </div>
75
- -->
76
- <!--
77
- <div class="view-switch">
78
- <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
79
- </div>
80
- -->
81
- <?php
82
- if ( $bookings_count >= $limit ) {
83
- $bookings_nav = em_admin_paginate( $bookings_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_pending_table'));
84
- echo $bookings_nav;
85
- }
86
- ?>
87
- <div class="clear"></div>
88
- </div>
89
- <?php endif; ?>
90
- <div class="clear"></div>
91
- <?php if( $bookings_count > 0 ): ?>
92
- <div class='table-wrap'>
93
- <table id='dbem-bookings-table' class='widefat post fixed'>
94
- <thead>
95
- <tr>
96
- <th class='manage-column column-cb check-column' scope='col'>
97
- <input class='select-all' type="checkbox" value='1' />
98
- </th>
99
- <th class='manage-column' scope='col'>Booker</th>
100
- <?php if( !is_object($EM_Event) && !is_object($EM_Ticket) ): ?>
101
- <th class='manage-column' scope="col">Event</th>
102
- <?php endif; ?>
103
- <th class='manage-column' scope='col'>E-mail</th>
104
- <th class='manage-column' scope='col'>Phone number</th>
105
- <th class='manage-column' scope='col'>Spaces</th>
106
- <th class='manage-column' scope='col'>&nbsp;</th>
107
- </tr>
108
- </thead>
109
- <tbody>
110
- <?php
111
- $rowno = 0;
112
- $event_count = 0;
113
- foreach ($EM_Bookings->bookings as $EM_Booking) {
114
- if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
115
- $rowno++;
116
- ?>
117
- <tr>
118
- <th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->id ?>' name='bookings[]'/></th>
119
- <td><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person->ID; ?>"><?php echo $EM_Booking->person->display_name ?></a></td>
120
- <?php if( !is_object($EM_Event) && !is_object($EM_Ticket) ): ?>
121
- <td><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php echo $EM_Booking->event_id; ?>"><?php echo $events[$EM_Booking->event_id]->name ?></a></td>
122
- <?php endif; ?>
123
- <td><?php echo $EM_Booking->person->user_email ?></td>
124
- <td><?php echo $EM_Booking->person->phone ?></td>
125
- <td><?php echo $EM_Booking->get_spaces() ?></td>
126
- <td>
127
- <?php
128
- $approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'booking_id'=>$EM_Booking->id));
129
- $reject_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_reject', 'booking_id'=>$EM_Booking->id));
130
- $delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->id));
131
- ?>
132
- <a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Approve','dbem'); ?></a> |
133
- <a class="em-bookings-reject" href="<?php echo $reject_url ?>"><?php _e('Reject','dbem'); ?></a> |
134
- <span class="trash"><a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a></span> |
135
- <a class="em-bookings-edit" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->id; ?>"><?php _e('Edit/View','dbem'); ?></a>
136
- </td>
137
- </tr>
138
- <?php
139
- }
140
- $event_count++;
141
- }
142
- ?>
143
- </tbody>
144
- </table>
145
- </div>
146
- <?php else: ?>
147
- <?php _e('No pending bookings.', 'dbem'); ?>
148
- <?php endif; ?>
149
- </form>
150
- <?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
151
- <div class='tablenav'>
152
- <?php echo $bookings_nav; ?>
153
- <div class="clear"></div>
154
- </div>
155
- <?php endif; ?>
156
- </div>
157
- <?php
158
-
159
- }
160
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Generates a "widget" table of pending bookings with some quick admin operation options.
5
+ * If event id supplied then only pending bookings for that event will show.
6
+ *
7
+ * @param int $event_id
8
+ */
9
+ function em_bookings_pending_table($event_id = false){
10
+ global $EM_Event, $wpdb, $current_user;
11
+
12
+ if( get_option('dbem_bookings_approval') == 0 ){
13
+ return false;
14
+ }
15
+
16
+ $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_pending_table' );
17
+ $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
18
+ $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
19
+ $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
20
+ $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
21
+ $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
22
+
23
+ if( is_object($EM_Event) ){
24
+ $bookings = $EM_Event->get_bookings()->get_pending();
25
+ }else{
26
+ //To optimize performance, we can do one query here for all pending bookings to show.
27
+ $bookings = EM_Bookings::get(array('status'=>0));
28
+ $events = array();
29
+ //Now let's create events and bookings for this:
30
+ foreach($bookings as $EM_Booking){
31
+ //create event
32
+ if( !array_key_exists($EM_Booking->event_id,$events) ){
33
+ $events[$EM_Booking->event_id] = new EM_Event($EM_Booking->event_id);
34
+ }
35
+ }
36
+ }
37
+ $bookings_count = (is_array($bookings)) ? count($bookings):0;
38
+ ?>
39
+ <div class='wrap em_bookings_pending_table em_obj'>
40
+ <form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
41
+ <input type="hidden" name="em_obj" value="em_bookings_pending_table" />
42
+ <!--
43
+ <ul class="subsubsub">
44
+ <li>
45
+ <a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
46
+ </li>
47
+ </ul>
48
+ <p class="search-box">
49
+ <label class="screen-reader-text" for="post-search-input"><?php _e('Search'); ?>:</label>
50
+ <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? $_GET['em_search']:''; ?>" />
51
+ <input type="submit" value="<?php _e('Search'); ?>" class="button" />
52
+ </p>
53
+ -->
54
+ <?php if ( $bookings_count >= $limit ) : ?>
55
+ <div class='tablenav'>
56
+ <!--
57
+ <div class="alignleft actions">
58
+ <select name="action">
59
+ <option value="-1" selected="selected">
60
+ <?php _e('Bulk Actions'); ?>
61
+ </option>
62
+ <option value="approve">
63
+ <?php _e('Approve', 'dbem'); ?>
64
+ </option>
65
+ <option value="decline">
66
+ <?php _e('Decline', 'dbem'); ?>
67
+ </option>
68
+ </select>
69
+ <input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
70
+ </div>
71
+ -->
72
+ <!--
73
+ <div class="view-switch">
74
+ <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
75
+ </div>
76
+ -->
77
+ <?php
78
+ if ( $bookings_count >= $limit ) {
79
+ $page_link_template = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%', 'em_ajax'=>0, 'em_obj'=>'em_bookings_pending_table'));
80
+ $bookings_nav = em_admin_paginate( $page_link_template, $bookings_count, $limit, $page, 5);
81
+ echo $bookings_nav;
82
+ }
83
+ ?>
84
+ <div class="clear"></div>
85
+ </div>
86
+ <?php endif; ?>
87
+ <div class="clear"></div>
88
+ <?php if( $bookings_count > 0 ): ?>
89
+ <div class='table-wrap'>
90
+ <table id='dbem-bookings-table' class='widefat post fixed'>
91
+ <thead>
92
+ <tr>
93
+ <th class='manage-column column-cb check-column' scope='col'>
94
+ <input class='select-all' type="checkbox" value='1' />
95
+ </th>
96
+ <th class='manage-column' scope='col'>Booker</th>
97
+ <?php if( !is_object($EM_Event) ): ?>
98
+ <th class='manage-column' scope="col">Event</th>
99
+ <?php endif; ?>
100
+ <th class='manage-column' scope='col'>E-mail</th>
101
+ <th class='manage-column' scope='col'>Phone number</th>
102
+ <th class='manage-column' scope='col'>Spaces</th>
103
+ <th class='manage-column' scope='col'>&nbsp;</th>
104
+ </tr>
105
+ </thead>
106
+ <tbody>
107
+ <?php
108
+ $rowno = 0;
109
+ $event_count = 0;
110
+ foreach ($bookings as $EM_Booking) {
111
+ if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
112
+ $rowno++;
113
+ ?>
114
+ <tr>
115
+ <th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->id ?>' name='bookings[]'/></th>
116
+ <td><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person->id; ?>"><?php echo $EM_Booking->person->name ?></a></td>
117
+ <?php if( !is_object($EM_Event) ): ?>
118
+ <td><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php echo $EM_Booking->event_id; ?>"><?php echo $events[$EM_Booking->event_id]->name ?></a></td>
119
+ <?php endif; ?>
120
+ <td><?php echo $EM_Booking->person->email ?></td>
121
+ <td><?php echo $EM_Booking->person->phone ?></td>
122
+ <td><?php echo $EM_Booking->seats ?></td>
123
+ <td>
124
+ <?php
125
+ $approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'booking_id'=>$EM_Booking->id));
126
+ $reject_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_reject', 'booking_id'=>$EM_Booking->id));
127
+ ?>
128
+ <a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Approve','dbem'); ?></a> |
129
+ <a class="em-bookings-reject" href="<?php echo $reject_url ?>"><?php _e('Reject','dbem'); ?></a> |
130
+ <a class="em-bookings-edit" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->id; ?>"><?php _e('Edit'); ?></a>
131
+ </td>
132
+ </tr>
133
+ <?php
134
+ }
135
+ $event_count++;
136
+ }
137
+ ?>
138
+ </tbody>
139
+ </table>
140
+ </div>
141
+ <?php else: ?>
142
+ <?php _e('No pending bookings.', 'dbem'); ?>
143
+ <?php endif; ?>
144
+ </form>
145
+ <?php if( !empty($bookings_nav) ) : ?>
146
+ <div class='tablenav'>
147
+ <?php echo $bookings_nav; ?>
148
+ <div class="clear"></div>
149
+ </div>
150
+ <?php endif; ?>
151
+ </div>
152
+ <?php
153
+
154
+ }
 
 
 
 
 
155
  ?>
admin/bookings/em-person.php CHANGED
@@ -1,152 +1,150 @@
1
- <?php
2
-
3
- /**
4
- * Generates a "widget" table of confirmed bookings for a specific event.
5
- *
6
- * @param int $event_id
7
- */
8
- function em_bookings_person_table(){
9
- global $wpdb, $current_user,$EM_Person;
10
- if(!is_object($EM_Person)){
11
- return false;
12
- }
13
- $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_confirmed_table' );
14
- $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
15
- $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
16
- $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
17
- $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
18
- $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
19
-
20
- $bookings = $EM_Person->get_bookings();
21
- $bookings_count = count($bookings);
22
- if($bookings_count > 0){
23
- //Get events here in one query to speed things up
24
- foreach($bookings as $EM_Booking){
25
- $event_ids[] = $EM_Booking->event_id;
26
- }
27
- $events = EM_Events::get($event_ids);
28
- }
29
- ?>
30
- <div class='wrap em_bookings_pending_table em_obj'>
31
- <form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
32
- <input type="hidden" name="em_obj" value="em_bookings_pending_table" />
33
- <!--
34
- <ul class="subsubsub">
35
- <li>
36
- <a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
37
- </li>
38
- </ul>
39
- <p class="search-box">
40
- <label class="screen-reader-text" for="post-search-input"><?php _e('Search'); ?>:</label>
41
- <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? $_GET['em_search']:''; ?>" />
42
- <input type="submit" value="<?php _e('Search'); ?>" class="button" />
43
- </p>
44
- -->
45
- <?php if ( $bookings_count >= $limit ) : ?>
46
- <div class='tablenav'>
47
- <!--
48
- <div class="alignleft actions">
49
- <select name="action">
50
- <option value="-1" selected="selected">
51
- <?php _e('Bulk Actions'); ?>
52
- </option>
53
- <option value="approve">
54
- <?php _e('Approve', 'dbem'); ?>
55
- </option>
56
- <option value="decline">
57
- <?php _e('Decline', 'dbem'); ?>
58
- </option>
59
- </select>
60
- <input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
61
- </div>
62
- -->
63
- <!--
64
- <div class="view-switch">
65
- <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
66
- </div>
67
- -->
68
- <?php
69
- if ( $bookings_count >= $limit ) {
70
- $bookings_nav = em_admin_paginate( $bookings_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
71
- echo $bookings_nav;
72
- }
73
- ?>
74
- <div class="clear"></div>
75
- </div>
76
- <?php endif; ?>
77
- <div class="clear"></div>
78
- <?php if( $bookings_count > 0 ): ?>
79
- <div class='table-wrap'>
80
- <table id='dbem-bookings-table' class='widefat post fixed'>
81
- <thead>
82
- <tr>
83
- <th class='manage-column column-cb check-column' scope='col'>
84
- <input class='select-all' type="checkbox" value='1' />
85
- </th>
86
- <th class='manage-column' scope='col'>Event</th>
87
- <th class='manage-column' scope='col'>Spaces</th>
88
- <th class='manage-column' scope='col'>Status</th>
89
- <th class='manage-column' scope='col'>&nbsp;</th>
90
- </tr>
91
- </thead>
92
- <tbody>
93
- <?php
94
- $rowno = 0;
95
- $event_count = 0;
96
- foreach ($bookings as $EM_Booking) {
97
- $EM_Event = $events[$EM_Booking->event_id];
98
- if( $EM_Event->can_manage('edit_events','edit_others_events') && ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
99
- $rowno++;
100
- ?>
101
- <tr>
102
- <th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->id ?>' name='bookings[]'/></th>
103
- <td><a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php echo $EM_Event->id ?>"><?php echo ($EM_Event->name); ?></a></td>
104
- <td><?php echo $EM_Booking->get_spaces() ?></td>
105
- <td><?php echo $EM_Booking->status_array[$EM_Booking->status]; ?>
106
- </td>
107
- <td>
108
- <?php
109
- $unapprove_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_unapprove', 'bookings'=>$EM_Booking->id));
110
- $approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'bookings'=>$EM_Booking->id));
111
- $reject_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_reject', 'bookings'=>$EM_Booking->id));
112
- $delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'bookings'=>$EM_Booking->id));
113
- ?>
114
- <?php if( get_option('dbem_bookings_approval') && ($EM_Booking->status == 0 ) ): ?>
115
- <a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Approve','dbem'); ?></a> |
116
- <?php endif; ?>
117
- <?php if( get_option('dbem_bookings_approval') && $EM_Booking->status == 1 ): ?>
118
- <a class="em-bookings-unapprove" href="<?php echo $unapprove_url ?>"><?php _e('Unapprove','dbem'); ?></a> |
119
- <?php endif; ?>
120
- <?php if( $EM_Booking->status == 2 ): ?>
121
- <a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Restore','dbem'); ?></a> |
122
- <?php endif; ?>
123
- <?php if( $EM_Booking->status == 0 || $EM_Booking->status == 1 ): ?>
124
- <a class="em-bookings-reject" href="<?php echo $reject_url ?>"><?php _e('Reject','dbem'); ?></a> |
125
- <?php endif; ?>
126
- <a class="em-bookings-edit" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->id; ?>"><?php _e('Edit/View','dbem'); ?></a> |
127
- <span class="trash"><a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a></span>
128
- </td>
129
- </tr>
130
- <?php
131
- }
132
- $event_count++;
133
- }
134
- ?>
135
- </tbody>
136
- </table>
137
- </div>
138
- <?php else: ?>
139
- <?php _e('No confirmed bookings.', 'dbem'); ?>
140
- <?php endif; ?>
141
- </form>
142
- <?php if( !empty($bookings_nav) && $bookings >= $limit ) : ?>
143
- <div class='tablenav'>
144
- <?php echo $bookings_nav; ?>
145
- <div class="clear"></div>
146
- </div>
147
- <?php endif; ?>
148
- </div>
149
- <?php
150
-
151
- }
152
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Generates a "widget" table of confirmed bookings for a specific event.
5
+ *
6
+ * @param int $event_id
7
+ */
8
+ function em_bookings_person_table(){
9
+ global $wpdb, $current_user,$EM_Person;
10
+ if(!is_object($EM_Person)){
11
+ return false;
12
+ }
13
+ $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_confirmed_table' );
14
+ $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
15
+ $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
16
+ $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
17
+ $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
18
+ $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
19
+
20
+ $bookings = $EM_Person->get_bookings();
21
+ $bookings_count = (is_array($bookings)) ? count($bookings):0;
22
+ if($bookings_count > 0){
23
+ //Get events here in one query to speed things up
24
+ foreach($bookings as $EM_Booking){
25
+ $event_ids[] = $EM_Booking->event_id;
26
+ }
27
+ $events = EM_Events::get($event_ids);
28
+ }
29
+ ?>
30
+ <div class='wrap em_bookings_pending_table em_obj'>
31
+ <form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
32
+ <input type="hidden" name="em_obj" value="em_bookings_pending_table" />
33
+ <!--
34
+ <ul class="subsubsub">
35
+ <li>
36
+ <a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
37
+ </li>
38
+ </ul>
39
+ <p class="search-box">
40
+ <label class="screen-reader-text" for="post-search-input"><?php _e('Search'); ?>:</label>
41
+ <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? $_GET['em_search']:''; ?>" />
42
+ <input type="submit" value="<?php _e('Search'); ?>" class="button" />
43
+ </p>
44
+ -->
45
+ <?php if ( $bookings_count >= $limit ) : ?>
46
+ <div class='tablenav'>
47
+ <!--
48
+ <div class="alignleft actions">
49
+ <select name="action">
50
+ <option value="-1" selected="selected">
51
+ <?php _e('Bulk Actions'); ?>
52
+ </option>
53
+ <option value="approve">
54
+ <?php _e('Approve', 'dbem'); ?>
55
+ </option>
56
+ <option value="decline">
57
+ <?php _e('Decline', 'dbem'); ?>
58
+ </option>
59
+ </select>
60
+ <input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
61
+ </div>
62
+ -->
63
+ <!--
64
+ <div class="view-switch">
65
+ <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
66
+ </div>
67
+ -->
68
+ <?php
69
+ if ( $bookings_count >= $limit ) {
70
+ $page_link_template = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%', 'em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
71
+ $bookings_nav = em_admin_paginate( $page_link_template, $bookings_count, $limit, $page, 5);
72
+ echo $bookings_nav;
73
+ }
74
+ ?>
75
+ <div class="clear"></div>
76
+ </div>
77
+ <?php endif; ?>
78
+ <div class="clear"></div>
79
+ <?php if( $bookings_count > 0 ): ?>
80
+ <div class='table-wrap'>
81
+ <table id='dbem-bookings-table' class='widefat post fixed'>
82
+ <thead>
83
+ <tr>
84
+ <th class='manage-column column-cb check-column' scope='col'>
85
+ <input class='select-all' type="checkbox" value='1' />
86
+ </th>
87
+ <th class='manage-column' scope='col'>Event</th>
88
+ <th class='manage-column' scope='col'>Spaces</th>
89
+ <th class='manage-column' scope='col'>Status</th>
90
+ <th class='manage-column' scope='col'>&nbsp;</th>
91
+ </tr>
92
+ </thead>
93
+ <tbody>
94
+ <?php
95
+ $rowno = 0;
96
+ $event_count = 0;
97
+ foreach ($bookings as $EM_Booking) {
98
+ $EM_Event = $events[$EM_Booking->event_id];
99
+ if( $EM_Event->can_manage() && ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
100
+ $rowno++;
101
+ ?>
102
+ <tr>
103
+ <th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->id ?>' name='bookings[]'/></th>
104
+ <td><a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php echo $EM_Event->id ?>"><?php echo ($EM_Event->name); ?></a></td>
105
+ <td><?php echo $EM_Booking->seats ?></td>
106
+ <td><?php echo $EM_Booking->status_array[$EM_Booking->status]; ?>
107
+ </td>
108
+ <td>
109
+ <?php
110
+ $unapprove_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_unapprove', 'bookings'=>$EM_Booking->id));
111
+ $approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'bookings'=>$EM_Booking->id));
112
+ $reject_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_reject', 'bookings'=>$EM_Booking->id));
113
+ $delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'bookings'=>$EM_Booking->id));
114
+ ?>
115
+ <?php if( $EM_Booking->status == 0 || $EM_Booking->status == 2 ): ?>
116
+ <a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Approve','dbem'); ?></a> |
117
+ <?php endif; ?>
118
+ <?php if( $EM_Booking->status == 2 ): ?>
119
+ <a class="em-bookings-unapprove" href="<?php echo $unapprove_url ?>"><?php _e('Unapprove','dbem'); ?></a> |
120
+ <?php endif; ?>
121
+ <?php if( $EM_Booking->status == 0 || $EM_Booking->status == 1 ): ?>
122
+ <a class="em-bookings-reject" href="<?php echo $reject_url ?>"><?php _e('Reject','dbem'); ?></a> |
123
+ <?php endif; ?>
124
+ <a class="em-bookings-edit" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->id; ?>"><?php _e('Edit'); ?></a> |
125
+ <a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a>
126
+ </td>
127
+ </tr>
128
+ <?php
129
+ }
130
+ $event_count++;
131
+ }
132
+ ?>
133
+ </tbody>
134
+ </table>
135
+ </div>
136
+ <?php else: ?>
137
+ <?php _e('No confirmed bookings.', 'dbem'); ?>
138
+ <?php endif; ?>
139
+ </form>
140
+ <?php if( !empty($bookings_nav) ) : ?>
141
+ <div class='tablenav'>
142
+ <?php echo $bookings_nav; ?>
143
+ <div class="clear"></div>
144
+ </div>
145
+ <?php endif; ?>
146
+ </div>
147
+ <?php
148
+
149
+ }
 
 
150
  ?>
admin/bookings/em-rejected.php CHANGED
@@ -1,136 +1,133 @@
1
- <?php
2
- /**
3
- * Generates a "widget" table of confirmed bookings for a specific event.
4
- *
5
- * @param int $event_id
6
- */
7
- function em_bookings_rejected_table(){
8
- global $EM_Event, $EM_Ticket, $wpdb, $current_user;
9
-
10
- $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_confirmed_table' );
11
- $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
12
- $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
13
- $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
14
- $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
15
- $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
16
-
17
- if( is_object($EM_Ticket) ){
18
- $EM_Bookings = $EM_Ticket->get_bookings()->get_rejected_bookings();
19
- }else{
20
- if( is_object($EM_Event) ){
21
- $EM_Bookings = $EM_Event->get_bookings()->get_rejected_bookings();
22
- }else{
23
- return false;
24
- }
25
- }
26
- $bookings_count = (is_array($EM_Bookings->bookings)) ? count($EM_Bookings->bookings):0;
27
- ?>
28
- <div class='wrap em_bookings_pending_table em_obj'>
29
- <form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
30
- <input type="hidden" name="em_obj" value="em_bookings_pending_table" />
31
- <!--
32
- <ul class="subsubsub">
33
- <li>
34
- <a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
35
- </li>
36
- </ul>
37
- <p class="search-box">
38
- <label class="screen-reader-text" for="post-search-input"><?php _e('Search'); ?>:</label>
39
- <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? $_GET['em_search']:''; ?>" />
40
- <input type="submit" value="<?php _e('Search'); ?>" class="button" />
41
- </p>
42
- -->
43
- <?php if ( $bookings_count >= $limit ) : ?>
44
- <div class='tablenav'>
45
- <!--
46
- <div class="alignleft actions">
47
- <select name="action">
48
- <option value="-1" selected="selected">
49
- <?php _e('Bulk Actions'); ?>
50
- </option>
51
- <option value="approve">
52
- <?php _e('Approve', 'dbem'); ?>
53
- </option>
54
- <option value="decline">
55
- <?php _e('Decline', 'dbem'); ?>
56
- </option>
57
- </select>
58
- <input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
59
- </div>
60
- -->
61
- <!--
62
- <div class="view-switch">
63
- <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
64
- </div>
65
- -->
66
- <?php
67
- if ( $bookings_count >= $limit ) {
68
- $bookings_nav = em_admin_paginate( $bookings_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
69
- echo $bookings_nav;
70
- }
71
- ?>
72
- <div class="clear"></div>
73
- </div>
74
- <?php endif; ?>
75
- <div class="clear"></div>
76
- <?php if( $bookings_count > 0 ): ?>
77
- <div class='table-wrap'>
78
- <table id='dbem-bookings-table' class='widefat post fixed'>
79
- <thead>
80
- <tr>
81
- <th class='manage-column column-cb check-column' scope='col'>
82
- <input class='select-all' type="checkbox" value='1' />
83
- </th>
84
- <th class='manage-column' scope='col'>Booker</th>
85
- <th class='manage-column' scope='col'>E-mail</th>
86
- <th class='manage-column' scope='col'>Phone number</th>
87
- <th class='manage-column' scope='col'>Spaces</th>
88
- <th class='manage-column' scope='col'>&nbsp;</th>
89
- </tr>
90
- </thead>
91
- <tbody>
92
- <?php
93
- $rowno = 0;
94
- $event_count = 0;
95
- foreach ($EM_Bookings->bookings as $EM_Booking) {
96
- if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
97
- $rowno++;
98
- ?>
99
- <tr>
100
- <th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->id ?>' name='bookings[]'/></th>
101
- <td><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person->ID; ?>"><?php echo $EM_Booking->person->display_name ?></a></td>
102
- <td><?php echo $EM_Booking->person->user_email ?></td>
103
- <td><?php echo $EM_Booking->person->phone ?></td>
104
- <td><?php echo $EM_Booking->get_spaces() ?></td>
105
- <td>
106
- <?php
107
- $approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'booking_id'=>$EM_Booking->id));
108
- $delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->id));
109
- ?>
110
- <a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Approve','dbem'); ?></a> |
111
- <a class="em-bookings-edit" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->id; ?>"><?php _e('Edit/View','dbem'); ?></a> |
112
- <span class="trash"><a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a></span> |
113
- </td>
114
- </tr>
115
- <?php
116
- }
117
- $event_count++;
118
- }
119
- ?>
120
- </tbody>
121
- </table>
122
- </div>
123
- <?php else: ?>
124
- <?php _e('No rejected bookings.', 'dbem'); ?>
125
- <?php endif; ?>
126
- </form>
127
- <?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
128
- <div class='tablenav'>
129
- <?php echo $bookings_nav; ?>
130
- <div class="clear"></div>
131
- </div>
132
- <?php endif; ?>
133
- </div>
134
- <?php
135
- }
136
  ?>
1
+ <?php
2
+ /**
3
+ * Generates a "widget" table of confirmed bookings for a specific event.
4
+ *
5
+ * @param int $event_id
6
+ */
7
+ function em_bookings_rejected_table(){
8
+ global $EM_Event, $wpdb, $current_user;
9
+
10
+ $action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_confirmed_table' );
11
+ $action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
12
+ $order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
13
+ $limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
14
+ $page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
15
+ $offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
16
+
17
+ if( is_object($EM_Event) ){
18
+ $bookings = $EM_Event->get_bookings()->get_rejected_bookings();
19
+ }else{
20
+ return false;
21
+ }
22
+ $bookings_count = (is_array($bookings)) ? count($bookings):0;
23
+ ?>
24
+ <div class='wrap em_bookings_pending_table em_obj'>
25
+ <form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
26
+ <input type="hidden" name="em_obj" value="em_bookings_pending_table" />
27
+ <!--
28
+ <ul class="subsubsub">
29
+ <li>
30
+ <a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
31
+ </li>
32
+ </ul>
33
+ <p class="search-box">
34
+ <label class="screen-reader-text" for="post-search-input"><?php _e('Search'); ?>:</label>
35
+ <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? $_GET['em_search']:''; ?>" />
36
+ <input type="submit" value="<?php _e('Search'); ?>" class="button" />
37
+ </p>
38
+ -->
39
+ <?php if ( $bookings_count >= $limit ) : ?>
40
+ <div class='tablenav'>
41
+ <!--
42
+ <div class="alignleft actions">
43
+ <select name="action">
44
+ <option value="-1" selected="selected">
45
+ <?php _e('Bulk Actions'); ?>
46
+ </option>
47
+ <option value="approve">
48
+ <?php _e('Approve', 'dbem'); ?>
49
+ </option>
50
+ <option value="decline">
51
+ <?php _e('Decline', 'dbem'); ?>
52
+ </option>
53
+ </select>
54
+ <input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
55
+ </div>
56
+ -->
57
+ <!--
58
+ <div class="view-switch">
59
+ <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
60
+ </div>
61
+ -->
62
+ <?php
63
+ if ( $bookings_count >= $limit ) {
64
+ $page_link_template = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%', 'em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
65
+ $bookings_nav = em_admin_paginate( $page_link_template, $bookings_count, $limit, $page, 5);
66
+ echo $bookings_nav;
67
+ }
68
+ ?>
69
+ <div class="clear"></div>
70
+ </div>
71
+ <?php endif; ?>
72
+ <div class="clear"></div>
73
+ <?php if( $bookings_count > 0 ): ?>
74
+ <div class='table-wrap'>
75
+ <table id='dbem-bookings-table' class='widefat post fixed'>
76
+ <thead>
77
+ <tr>
78
+ <th class='manage-column column-cb check-column' scope='col'>
79
+ <input class='select-all' type="checkbox" value='1' />
80
+ </th>
81
+ <th class='manage-column' scope='col'>Booker</th>
82
+ <th class='manage-column' scope='col'>E-mail</th>
83
+ <th class='manage-column' scope='col'>Phone number</th>
84
+ <th class='manage-column' scope='col'>Spaces</th>
85
+ <th class='manage-column' scope='col'>&nbsp;</th>
86
+ </tr>
87
+ </thead>
88
+ <tbody>
89
+ <?php
90
+ $rowno = 0;
91
+ $event_count = 0;
92
+ foreach ($bookings as $EM_Booking) {
93
+ if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
94
+ $rowno++;
95
+ ?>
96
+ <tr>
97
+ <th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->id ?>' name='bookings[]'/></th>
98
+ <td><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person->id; ?>"><?php echo $EM_Booking->person->name ?></a></td>
99
+ <td><?php echo $EM_Booking->person->email ?></td>
100
+ <td><?php echo $EM_Booking->person->phone ?></td>
101
+ <td><?php echo $EM_Booking->seats ?></td>
102
+ <td>
103
+ <?php
104
+ $approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'booking_id'=>$EM_Booking->id));
105
+ $delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->id));
106
+ ?>
107
+ <a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Approve','dbem'); ?></a> |
108
+ <a class="em-bookings-edit" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->id; ?>"><?php _e('Edit'); ?></a> |
109
+ <a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a>
110
+ </td>
111
+ </tr>
112
+ <?php
113
+ }
114
+ $event_count++;
115
+ }
116
+ ?>
117
+ </tbody>
118
+ </table>
119
+ </div>
120
+ <?php else: ?>
121
+ <?php _e('No rejected bookings.', 'dbem'); ?>
122
+ <?php endif; ?>
123
+ </form>
124
+ <?php if( !empty($bookings_nav) ) : ?>
125
+ <div class='tablenav'>
126
+ <?php echo $bookings_nav; ?>
127
+ <div class="clear"></div>
128
+ </div>
129
+ <?php endif; ?>
130
+ </div>
131
+ <?php
132
+ }
 
 
 
133
  ?>
admin/em-admin.php CHANGED
@@ -1,163 +1,266 @@
1
- <?php
2
- //Admin functions
3
-
4
- /**
5
- * Generate warnings and notices in the admin area
6
- */
7
- function em_admin_warnings() {
8
- //If we're editing the events page show hello to new user
9
- $events_page_id = get_option ( 'dbem_events_page' );
10
- $dismiss_link_joiner = ( count($_GET) > 0 ) ? '&amp;':'?';
11
-
12
- if( current_user_can('activate_plugins') ){
13
- //New User Intro
14
- if (isset ( $_GET ['disable_hello_to_user'] ) && $_GET ['disable_hello_to_user'] == 'true'){
15
- // Disable Hello to new user if requested
16
- update_option ( 'dbem_hello_to_user', 0 );
17
- }elseif ( get_option ( 'dbem_hello_to_user' ) == 1 && !empty($_GET['page']) && $_GET['page'] == 'events-manager-events' ) {
18
- $current_user = wp_get_current_user ();
19
- //FIXME update welcome msg with good links
20
- $advice = sprintf ( __ ( "<p>Hey, <strong>%s</strong>, welcome to <strong>Events Manager</strong>! We hope you like it around here.</p>
21
- <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>
22
- <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>
23
- <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://wp-events-plugin.com/documentation/template-tags/', 'http://wp-events-plugin.com/documentation/shortcodes/', get_bloginfo ( 'url' ) . '/wp-admin/admin.php?page=events-manager-options', get_bloginfo ( 'url' ) . '/wp-admin/admin.php?page=events-manager&disable_hello_to_user=true' );
24
- ?>
25
- <div id="message" class="updated">
26
- <?php echo $advice; ?>
27
- </div>
28
- <?php
29
- }
30
-
31
- //If events page couldn't be created
32
- if( !empty($_GET['em_dismiss_admin_notice']) ){
33
- delete_option('dbem_admin_notice_'.$_GET['em_dismiss_admin_notice']);
34
- }else{
35
- if ( get_option('dbem_admin_notice_3.0.91') ){
36
- ?>
37
- <div class="updated">
38
- <p><?php echo sprintf ( __( '<strong>Events Manager has some new features!</strong><ul><li>Bookings can now be approved before they count towards your event\'s space allocations.</li><li>Events now have owners, and you can restrict users so they can only manage events/locations/categories they create.<br/><br/>These new permissions are enabled by default, but since you upgraded it has been disabled to maintain the previous plugin behaviour. You can re-enable it from the <a href="%s">settings page</a>. <a href="%s">Dismiss</a>', 'dbem'), get_bloginfo ( 'url' ) . '/wp-admin/admin.php?page=events-manager-options', $_SERVER['REQUEST_URI'].$dismiss_link_joiner.'em_dismiss_admin_notice=3.0.91' ); ?></p>
39
- </div>
40
- <?php
41
- }
42
- }
43
-
44
- //If events page couldn't be created
45
- if( !empty($_GET['em_dismiss_events_page']) ){
46
- update_option('dbem_dismiss_events_page',1);
47
- }else{
48
- if ( !get_page($events_page_id) && !get_option('dbem_dismiss_events_page') ){
49
- ?>
50
- <div id="em_page_error" class="updated">
51
- <p><?php echo sprintf ( __( 'Uh Oh! For some reason wordpress could not create an events page for you (or you just deleted it). Not to worry though, all you have to do is create an empty page, name it whatever you want, and select it as your events page in your <a href="%s">settings page</a>. Sorry for the extra step! If you know what you are doing, you may have done this on purpose, if so <a href="%s">ignore this message</a>', 'dbem'), get_bloginfo ( 'url' ) . '/wp-admin/admin.php?page=events-manager-options', $_SERVER['REQUEST_URI'].$dismiss_link_joiner.'em_dismiss_events_page=1' ); ?></p>
52
- </div>
53
- <?php
54
- }
55
- }
56
- }
57
- //Warn about EM page edit
58
- if ( preg_match( '/(post|page).php/', $_SERVER ['SCRIPT_NAME']) && isset ( $_GET ['action'] ) && $_GET ['action'] == 'edit' && isset ( $_GET ['post'] ) && $_GET ['post'] == "$events_page_id") {
59
- $message = sprintf ( __ ( "This page corresponds to <strong>Events Manager</strong> events page. Its content will be overriden by <strong>Events Manager</strong>. If you want to display your content, you can can assign another page to <strong>Events Manager</strong> in the the <a href='%s'>Settings</a>. ", 'dbem' ), 'admin.php?page=events-manager-options' );
60
- $notice = "<div class='error'><p>$message</p></div>";
61
- echo $notice;
62
- }
63
-
64
- }
65
- add_action ( 'admin_notices', 'em_admin_warnings' );
66
-
67
- /**
68
- * Creates a wp-admin style navigation. All this does is wrap some html around the em_paginate function result to make it style correctly in the admin area.
69
- * @param string $link
70
- * @param int $total
71
- * @param int $limit
72
- * @param int $page
73
- * @param int $pagesToShow
74
- * @return string
75
- * @uses em_paginate()
76
- */
77
- function em_admin_paginate($total, $limit, $page=1, $vars=false){
78
- $return = '<div class="tablenav-pages">';
79
- $events_nav = paginate_links( array(
80
- 'base' => add_query_arg( 'pno', '%#%' ),
81
- 'format' => '',
82
- 'total' => ceil($total / $limit),
83
- 'current' => $page,
84
- 'add_args' => $vars
85
- ));
86
- $return .= sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
87
- number_format_i18n( ( $page - 1 ) * $limit + 1 ),
88
- number_format_i18n( min( $page * $limit, $total ) ),
89
- number_format_i18n( $total ),
90
- $events_nav
91
- );
92
- $return .= '</div>';
93
- return $return;
94
- }
95
-
96
- /**
97
- * Called by admin_print_scripts-(hook|page) action, created when adding menu items in events-manager.php
98
- */
99
- function em_admin_load_scripts(){
100
- //Load the UI items, currently date picker and autocomplete plus dependencies
101
- //wp_enqueue_script('em-ui-js', WP_PLUGIN_URL.'/events-manager/includes/js/jquery-ui-1.8.5.custom.min.js', array('jquery', 'jquery-ui-core'));
102
- wp_enqueue_script('em-ui-js', WP_PLUGIN_URL.'/events-manager/includes/js/em_ui.js', array('jquery', 'jquery-ui-core'));
103
-
104
- //Add maps
105
- if( get_option('dbem_gmap_is_active') ){
106
- wp_enqueue_script('em-google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
107
- }
108
- //Time Entry
109
- wp_enqueue_script('em-timeentry', WP_PLUGIN_URL.'/events-manager/includes/js/timeentry/jquery.timeentry.js', array('jquery'));
110
-
111
- //Date Picker Locale
112
- $locale_code = substr ( get_locale (), 0, 2 );
113
- $locale_file = "/events-manager/includes/js/i18n/jquery.ui.datepicker-$locale_code.js";
114
- if ( file_exists(WP_PLUGIN_DIR.$locale_file) ) {
115
- wp_enqueue_script("em-ui-datepicker-$locale_code", WP_PLUGIN_URL.$locale_file, array('em-ui-js'));
116
- }
117
- wp_enqueue_script('em-script', WP_PLUGIN_URL.'/events-manager/includes/js/em_admin.js', array('em-ui-js'));
118
-
119
- //TinyMCE Editor
120
- remove_filter('the_editor', 'qtrans_modifyRichEditor'); //qtranslate filter
121
- add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
122
- wp_enqueue_script('post');
123
- if ( user_can_richedit() )
124
- wp_enqueue_script('editor');
125
- add_thickbox();
126
- wp_enqueue_script('media-upload');
127
- wp_enqueue_script('word-count');
128
- wp_enqueue_script('quicktags');
129
- }
130
-
131
- /**
132
- * Called by admin_print_styles-(hook|page) action, created when adding menu items in events-manager.php
133
- */
134
- function em_admin_load_styles() {
135
- add_thickbox();
136
- wp_enqueue_style('em-ui-css', WP_PLUGIN_URL.'/events-manager/includes/css/jquery-ui-1.7.3.custom.css');
137
- wp_enqueue_style('events-manager-admin', WP_PLUGIN_URL.'/events-manager/includes/css/events_manager_admin.css');
138
- }
139
-
140
- /**
141
- * Loads script inline due to insertion of php values
142
- */
143
- function em_admin_general_script() {
144
- //TODO clean script up, remove dependency of php so it can be moved to js file.
145
- // Check if the locale is there and loads it
146
- $locale_code = substr ( get_locale (), 0, 2 );
147
- $show24Hours = 'true';
148
- // Setting 12 hours format for those countries using it
149
- if (preg_match ( "/en|sk|zh|us|uk/", $locale_code ))
150
- $show24Hours = 'false';
151
- ?>
152
- <script type="text/javascript">
153
- //<![CDATA[
154
- // TODO: make more general, to support also latitude and longitude (when added)
155
- jQuery(document).ready( function($) {
156
- $("#start-time").timeEntry({spinnerImage: '', show24Hours: <?php echo $show24Hours; ?> });
157
- $("#end-time").timeEntry({spinnerImage: '', show24Hours: <?php echo $show24Hours; ?>});
158
- });
159
- //]]>
160
- </script>
161
- <?php
162
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  ?>
1
+ <?php
2
+ //Admin functions
3
+
4
+ /**
5
+ * Generate warnings and notices in the admin area
6
+ */
7
+ function em_admin_warnings() {
8
+ //If we're editing the events page show hello to new user
9
+ $events_page_id = get_option ( 'dbem_events_page' );
10
+ $dismiss_link_joiner = ( count($_GET) > 0 ) ? '&amp;':'?';
11
+
12
+ if( em_verify_admin() ){
13
+ //New User Intro
14
+ if (isset ( $_GET ['disable_hello_to_user'] ) && $_GET ['disable_hello_to_user'] == 'true'){
15
+ // Disable Hello to new user if requested
16
+ update_option ( 'dbem_hello_to_user', 0 );
17
+ }elseif ( get_option ( 'dbem_hello_to_user' ) == 1 && !empty($_GET['page']) && $_GET['page'] == 'events-manager-events' ) {
18
+ $current_user = wp_get_current_user ();
19
+ //FIXME update welcome msg with good links
20
+ $advice = sprintf ( __ ( "<p>Hey, <strong>%s</strong>, welcome to <strong>Events Manager</strong>! We hope you like it around here.</p>
21
+ <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>
22
+ <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>
23
+ <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://wp-events-plugin.com/documentation/template-tags/', 'http://wp-events-plugin.com/documentation/shortcodes/', get_bloginfo ( 'url' ) . '/wp-admin/admin.php?page=events-manager-options', get_bloginfo ( 'url' ) . '/wp-admin/admin.php?page=events-manager&disable_hello_to_user=true' );
24
+ ?>
25
+ <div id="message" class="updated">
26
+ <?php echo $advice; ?>
27
+ </div>
28
+ <?php
29
+ }
30
+
31
+ //If events page couldn't be created
32
+ if( !empty($_GET['em_dismiss_admin_notice']) ){
33
+ delete_option('dbem_admin_notice_'.$_GET['em_dismiss_admin_notice']);
34
+ }else{
35
+ if ( get_option('dbem_admin_notice_3.0.91') ){
36
+ ?>
37
+ <div class="updated">
38
+ <p><?php echo sprintf ( __( '<strong>Events Manager has some new features!</strong><ul><li>Bookings can now be approved before they count towards your event\'s space allocations.</li><li>Events now have owners, and you can restrict users so they can only manage events/locations/categories they create.<br/><br/>These new permissions are enabled by default, but since you upgraded it has been disabled to maintain the previous plugin behaviour. You can re-enable it from the <a href="%s">settings page</a>. <a href="%s">Dismiss</a>', 'dbem'), get_bloginfo ( 'url' ) . '/wp-admin/admin.php?page=events-manager-options', $_SERVER['REQUEST_URI'].$dismiss_link_joiner.'em_dismiss_admin_notice=3.0.91' ); ?></p>
39
+ </div>
40
+ <?php
41
+ }
42
+ }
43
+
44
+ //If events page couldn't be created
45
+ if( !empty($_GET['em_dismiss_events_page']) ){
46
+ update_option('dbem_dismiss_events_page',1);
47
+ }else{
48
+ if ( !get_page($events_page_id) && !get_option('dbem_dismiss_events_page') ){
49
+ ?>
50
+ <div id="em_page_error" class="updated">
51
+ <p><?php echo sprintf ( __( 'Uh Oh! For some reason wordpress could not create an events page for you (or you just deleted it). Not to worry though, all you have to do is create an empty page, name it whatever you want, and select it as your events page in your <a href="%s">settings page</a>. Sorry for the extra step! If you know what you are doing, you may have done this on purpose, if so <a href="%s">ignore this message</a>', 'dbem'), get_bloginfo ( 'url' ) . '/wp-admin/admin.php?page=events-manager-options', $_SERVER['REQUEST_URI'].$dismiss_link_joiner.'em_dismiss_events_page=1' ); ?></p>
52
+ </div>
53
+ <?php
54
+ }
55
+ }
56
+ }
57
+ //Warn about EM page edit
58
+ if ( preg_match( '/(post|page).php/', $_SERVER ['SCRIPT_NAME']) && isset ( $_GET ['action'] ) && $_GET ['action'] == 'edit' && isset ( $_GET ['post'] ) && $_GET ['post'] == "$events_page_id") {
59
+ $message = sprintf ( __ ( "This page corresponds to <strong>Events Manager</strong> events page. Its content will be overriden by <strong>Events Manager</strong>. If you want to display your content, you can can assign another page to <strong>Events Manager</strong> in the the <a href='%s'>Settings</a>. ", 'dbem' ), 'admin.php?page=events-manager-options' );
60
+ $notice = "<div class='error'><p>$message</p></div>";
61
+ echo $notice;
62
+ }
63
+
64
+ }
65
+ add_action ( 'admin_notices', 'em_admin_warnings' );
66
+
67
+ /**
68
+ * Creates a wp-admin style navigation. All this does is wrap some html around the em_paginate function result to make it style correctly in the admin area.
69
+ * @param string $link
70
+ * @param int $total
71
+ * @param int $limit
72
+ * @param int $page
73
+ * @param int $pagesToShow
74
+ * @return string
75
+ * @uses em_paginate()
76
+ */
77
+ function em_admin_paginate($link, $total, $limit, $page=1, $pagesToShow=5){
78
+ $return = '<div class="tablenav-pages">';
79
+ $return .= sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>',
80
+ number_format_i18n( ( $page - 1 ) * $limit + 1 ),
81
+ number_format_i18n( min( $page * $limit, $total ) ),
82
+ number_format_i18n( $total )
83
+ );
84
+ $return .= em_paginate($link, $total, $limit, $page, $pagesToShow);
85
+ $return .= '</div>';
86
+ return $return;
87
+ }
88
+
89
+ /**
90
+ * Called by admin_print_scripts-(hook|page) action, created when adding menu items in events-manager.php
91
+ */
92
+ function em_admin_load_scripts(){
93
+ //Load the UI items, currently date picker and autocomplete plus dependencies
94
+ //wp_enqueue_script('em-ui-js', WP_PLUGIN_URL.'/events-manager/includes/js/jquery-ui-1.8.5.custom.min.js', array('jquery', 'jquery-ui-core'));
95
+ wp_enqueue_script('em-ui-js', WP_PLUGIN_URL.'/events-manager/includes/js/em_ui.js', array('jquery', 'jquery-ui-core'));
96
+
97
+ //Add maps
98
+ if( get_option('dbem_gmap_is_active') ){
99
+ wp_enqueue_script('em-google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
100
+ }
101
+ //Time Entry
102
+ wp_enqueue_script('em-timeentry', WP_PLUGIN_URL.'/events-manager/includes/js/timeentry/jquery.timeentry.js', array('jquery'));
103
+
104
+ //Date Picker Locale
105
+ $locale_code = substr ( get_locale (), 0, 2 );
106
+ $locale_file = "/events-manager/includes/js/i18n/jquery.ui.datepicker-$locale_code.js";
107
+ if ( file_exists(WP_PLUGIN_DIR.$locale_file) ) {
108
+ wp_enqueue_script("em-ui-datepicker-$locale_code", WP_PLUGIN_URL.$locale_file, array('em-ui-js'));
109
+ }
110
+ wp_enqueue_script('em-script', WP_PLUGIN_URL.'/events-manager/includes/js/em_admin.js', array('em-ui-js'));
111
+
112
+ //TinyMCE Editor
113
+ remove_filter('the_editor', 'qtrans_modifyRichEditor'); //qtranslate filter
114
+ add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
115
+ add_action( 'admin_print_footer_scripts', 'wp_tiny_mce_preload_dialogs', 30 );
116
+ wp_enqueue_script('post');
117
+ if ( user_can_richedit() )
118
+ wp_enqueue_script('editor');
119
+
120
+ add_thickbox();
121
+ wp_enqueue_script('media-upload');
122
+ wp_enqueue_script('word-count');
123
+ wp_enqueue_script('quicktags');
124
+ }
125
+
126
+ /**
127
+ * Called by admin_print_styles-(hook|page) action, created when adding menu items in events-manager.php
128
+ */
129
+ function em_admin_load_styles() {
130
+ add_thickbox();
131
+ wp_enqueue_style('em-ui-css', WP_PLUGIN_URL.'/events-manager/includes/css/jquery-ui-1.7.3.custom.css');
132
+ wp_enqueue_style('events-manager-admin', WP_PLUGIN_URL.'/events-manager/includes/css/events_manager_admin.css');
133
+ }
134
+
135
+ /**
136
+ * Loads script inline due to insertion of php values
137
+ */
138
+ function em_admin_general_script() {
139
+ //TODO clean script up, remove dependency of php so it can be moved to js file.
140
+ // Check if the locale is there and loads it
141
+ $locale_code = substr ( get_locale (), 0, 2 );
142
+ $show24Hours = 'true';
143
+ // Setting 12 hours format for those countries using it
144
+ if (preg_match ( "/en|sk|zh|us|uk/", $locale_code ))
145
+ $show24Hours = 'false';
146
+ ?>
147
+ <script type="text/javascript">
148
+ //<![CDATA[
149
+ // TODO: make more general, to support also latitude and longitude (when added)
150
+
151
+ jQuery(document).ready( function($) {
152
+
153
+ function updateIntervalDescriptor () {
154
+ $(".interval-desc").hide();
155
+ var number = "-plural";
156
+ if ($('input#recurrence-interval').val() == 1 || $('input#recurrence-interval').val() == "")
157
+ number = "-singular"
158
+ var descriptor = "span#interval-"+$("select#recurrence-frequency").val()+number;
159
+ $(descriptor).show();
160
+ }
161
+ function updateIntervalSelectors () {
162
+ $('p.alternate-selector').hide();
163
+ $('p#'+ $('select#recurrence-frequency').val() + "-selector").show();
164
+ }
165
+ function updateShowHideRsvp () {
166
+ if($('input#rsvp-checkbox').attr("checked")) {
167
+ $("div#rsvp-data").fadeIn();
168
+ } else {
169
+ $("div#rsvp-data").hide();
170
+ }
171
+ }
172
+ function updateShowHideRecurrence () {
173
+ if( $('input#event-recurrence').attr("checked")) {
174
+ $("#event_recurrence_pattern").fadeIn();
175
+ $("#event-date-explanation").hide();
176
+ $("#recurrence-dates-explanation").show();
177
+ $("h3#recurrence-dates-title").show();
178
+ $("h3#event-date-title").hide();
179
+ } else {
180
+ $("#event_recurrence_pattern").hide();
181
+ $("#recurrence-dates-explanation").hide();
182
+ $("#event-date-explanation").show();
183
+ $("h3#recurrence-dates-title").hide();
184
+ $("h3#event-date-title").show();
185
+ }
186
+ }
187
+ $("#recurrence-dates-explanation").hide();
188
+ $("#localised-date").show();
189
+ $("#localised-end-date").show();
190
+
191
+ $("#date-to-submit").hide();
192
+ $("#end-date-to-submit").hide();
193
+
194
+ $("#start-time").timeEntry({spinnerImage: '', show24Hours: <?php echo $show24Hours; ?> });
195
+ $("#end-time").timeEntry({spinnerImage: '', show24Hours: <?php echo $show24Hours; ?>});
196
+
197
+ $('input.select-all').change(function(){
198
+ if($(this).is(':checked'))
199
+ $('input.row-selector').attr('checked', true);
200
+ else
201
+ $('input.row-selector').attr('checked', false);
202
+ });
203
+
204
+ updateIntervalDescriptor();
205
+ updateIntervalSelectors();
206
+ updateShowHideRecurrence();
207
+ updateShowHideRsvp();
208
+ $('input#event-recurrence').change(updateShowHideRecurrence);
209
+ $('input#rsvp-checkbox').change(updateShowHideRsvp);
210
+
211
+ // recurrency elements
212
+ $('input#recurrence-interval').keyup(updateIntervalDescriptor);
213
+ $('select#recurrence-frequency').change(updateIntervalDescriptor);
214
+ $('select#recurrence-frequency').change(updateIntervalSelectors);
215
+
216
+ // hiding or showing notes according to their content
217
+ $('.postbox h3').prepend('<a class="togbox">+</a> ');
218
+ $('#event_notes h3').click( function() {
219
+ $(this).parent().first().toggleClass('closed');
220
+ });
221
+
222
+ // users cannot submit the event form unless some fields are filled
223
+ function validateEventForm(){
224
+ errors = "";
225
+ var recurring = $("input[@name=repeated_event]:checked").val();
226
+ requiredFields= new Array('event_name', 'localised_event_date', 'location_name','location_address','location_town');
227
+ var localisedRequiredFields = {
228
+ 'event_name':"<?php _e ( 'Name', 'dbem' )?>",
229
+ 'localised_event_date':"<?php _e ( 'Date', 'dbem' )?>",
230
+ 'location_name':"<?php _e ( 'Location', 'dbem' )?>",
231
+ 'location_address':"<?php _e ( 'Address', 'dbem' )?>",
232
+ 'location_town':"<?php _e ( 'Town', 'dbem' )?>"
233
+ };
234
+ missingFields = new Array;
235
+ for (var i in requiredFields) {
236
+ if ($("input[@name=" + requiredFields[i]+ "]").val() == 0) {
237
+ missingFields.push(localisedRequiredFields[requiredFields[i]]);
238
+ $("input[@name=" + requiredFields[i]+ "]").css('border','2px solid red');
239
+ } else {
240
+ $("input[@name=" + requiredFields[i]+ "]").css('border','1px solid #DFDFDF');
241
+ }
242
+ }
243
+
244
+ // alert('ciao ' + recurring+ " end: " + $("input[@name=localised_event_end_date]").val());
245
+ if (missingFields.length > 0) {
246
+ errors = "<?php _e ( 'Some required fields are missing:', 'dbem' )?> " + missingFields.join(", ") + ".\n";
247
+ }
248
+ if(recurring && $("input[@name=localised_event_end_date]").val() == "") {
249
+ errors = errors + "<?php _e ( 'Since the event is repeated, you must specify an end date', 'dbem' )?>.";
250
+ $("input[@name=localised_event_end_date]").css('border','2px solid red');
251
+ } else {
252
+ $("input[@name=localised_event_end_date]").css('border','1px solid #DFDFDF');
253
+ }
254
+ if(errors != "") {
255
+ alert(errors);
256
+ return false;
257
+ }
258
+ return true;
259
+ }
260
+ $('#event-form').bind("submit", validateEventForm);
261
+ });
262
+ //]]>
263
+ </script>
264
+ <?php
265
+ }
266
  ?>
admin/em-bookings.php CHANGED
@@ -1,369 +1,288 @@
1
- <?php
2
- /**
3
- * Check if there's any admin-related actions to take for bookings. All actions are caught here.
4
- * @return null
5
- */
6
- function em_admin_actions_bookings() {
7
- global $dbem_form_add_message;
8
- global $dbem_form_delete_message;
9
- global $wpdb, $EM_Booking, $EM_Event;
10
-
11
- if( current_user_can(EM_MIN_CAPABILITY) && is_object($EM_Booking) && !empty($_REQUEST['action']) ) {
12
- if( $_REQUEST['action'] == 'bookings_delete' ){
13
- //Delete
14
- if( isset($_POST['booking_id']) ){
15
- $EM_Booking = new EM_Booking($_POST['booking_id']);
16
- $EM_Booking->delete();
17
- }
18
- }elseif( $_REQUEST['action'] == 'bookings_edit' ){
19
- //Edit Booking
20
- $validation = $EM_Booking->get_post();
21
- if ( $validation ) { //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS)
22
- //Save
23
- if( $EM_Booking->save() ) {
24
- function em_booking_save_notification(){ global $EM_Booking; ?><div class="updated"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
25
- }else{
26
- function em_booking_save_notification(){ global $EM_Booking; ?><div class="error"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
27
- }
28
- }else{
29
- //TODO make errors clearer when saving person
30
- function em_booking_save_notification(){ global $EM_Booking; ?><div class="error"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
31
- }
32
- add_action ( 'admin_notices', 'em_booking_save_notification' );
33
- }elseif( $_REQUEST['action'] == 'bookings_approve' || $_REQUEST['action'] == 'bookings_reject' || $_REQUEST['action'] == 'bookings_unapprove' ){
34
- //Booking Approvals
35
- $status_array = array('bookings_unapprove' => 0,'bookings_approve' => 1,'bookings_reject' => 2, 'bookings_cancel' => 3);
36
- if( $EM_Booking->set_status( $status_array[$_REQUEST['action']] ) ) {
37
- function em_booking_save_notification(){ global $EM_Booking; ?><div class="updated"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
38
- }else{
39
- function em_booking_save_notification(){ global $EM_Booking; ?><div class="error"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
40
- }
41
- add_action ( 'admin_notices', 'em_booking_save_notification' );
42
- }elseif( $_REQUEST['action'] == 'bookings_add_note' ){
43
- $EM_Booking->add_note($_REQUEST['booking_note']);
44
- function em_booking_save_notification(){ global $EM_Booking; ?><div class="updated"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
45
- add_action ( 'admin_notices', 'em_booking_save_notification' );
46
- }
47
- }elseif( current_user_can(EM_MIN_CAPABILITY) && is_object($EM_Event) && !empty($_REQUEST['action']) ){
48
- if( $_REQUEST['action'] == 'export_csv' ){
49
- $EM_Event->get_bookings()->export_csv();
50
- exit();
51
- }
52
- }
53
- }
54
- add_action('admin_init','em_admin_actions_bookings',100);
55
-
56
- /**
57
- * Decide what content to show in the bookings section.
58
- */
59
- function em_bookings_page(){
60
- //First any actions take priority
61
- if( !empty($_REQUEST['booking_id']) ){
62
- em_bookings_single();
63
- }elseif( !empty($_REQUEST['person_id']) ){
64
- em_bookings_person();
65
- }elseif( !empty($_REQUEST['event_id']) ){
66
- em_bookings_event();
67
- }elseif( !empty($_REQUEST['ticket_id']) ){
68
- em_bookings_ticket();
69
- }else{
70
- em_bookings_dashboard();
71
- }
72
- }
73
-
74
- /**
75
- * Generates the bookings dashboard, showing information on all events
76
- */
77
- function em_bookings_dashboard(){
78
- ?>
79
- <div class='wrap'>
80
- <div id='icon-users' class='icon32'>
81
- <br/>
82
- </div>
83
- <h2>
84
- <?php _e('Event Bookings Dashboard', 'dbem'); ?>
85
- </h2>
86
- <?php if( get_option('dbem_bookings_approval')): ?>
87
- <h2><?php _e('Pending Bookings','dbem'); ?></h2>
88
- <?php em_bookings_pending_table(); ?>
89
- <?php endif; ?>
90
- <h2><?php _e('Events With Bookings Enabled','dbem'); ?></h2>
91
- <?php em_bookings_events_table(); ?>
92
- <?php do_action('em_bookings_dashboard'); ?>
93
- </div>
94
- <?php
95
- }
96
-
97
- /**
98
- * Shows all booking data for a single event
99
- */
100
- function em_bookings_event(){
101
- global $EM_Event,$EM_Person;
102
- //check that user can access this page
103
- if( is_object($EM_Event) && !$EM_Event->can_manage('manage_bookings','manage_others_bookings') ){
104
- ?>
105
- <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php _e('You do not have the rights to manage this event.','dbem'); ?></p></div>
106
- <?php
107
- return false;
108
- }
109
- $localised_start_date = date_i18n('D d M Y', $EM_Event->start);
110
- $localised_end_date = date_i18n('D d M Y', $EM_Event->end);
111
- ?>
112
- <div class='wrap'>
113
- <div id='icon-users' class='icon32'>
114
- <br/>
115
- </div>
116
- <h2>
117
- <?php echo sprintf(__('Manage %s Bookings', 'dbem'), "'{$EM_Event->name}'"); ?>
118
- <a href="admin.php?page=events-manager-event&event_id=<?php echo $EM_Event->id; ?>" class="button add-new-h2"><?php _e('View/Edit Event','dbem') ?></a>
119
- </h2>
120
- <div><a href='<?php echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&action=export_csv&event_id=".$EM_Event->id ?>'><?php _e('export csv','dbem')?></a></div>
121
- <div>
122
- <p><strong><?php _e('Event Name','dbem'); ?></strong> : <?php echo ($EM_Event->name); ?></p>
123
- <p><strong>Availability :</strong> <?php echo $EM_Event->get_bookings()->get_booked_spaces() . '/'. $EM_Event->get_spaces() ." ". __('Spaces confirmed','dbem'); ?></p>
124
- <p>
125
- <strong><?php _e('Date','dbem'); ?></strong> :
126
- <?php echo $localised_start_date; ?>
127
- <?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
128
- <?php echo substr ( $EM_Event->start_time, 0, 5 ) . " - " . substr ( $EM_Event->end_time, 0, 5 ); ?>
129
- </p>
130
- <p>
131
- <strong><?php _e('Location','dbem'); ?></strong> :
132
- <a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-locations&amp;location_id=<?php echo $EM_Event->location->id ?>"><?php echo ($EM_Event->location->name); ?></a>
133
- </p>
134
- </div>
135
- <?php if( get_option('dbem_bookings_approval')): ?>
136
- <h2><?php _e('Pending Bookings','dbem'); ?></h2>
137
- <?php em_bookings_pending_table(); ?>
138
- <?php endif; ?>
139
- <h2><?php _e('Confirmed Bookings','dbem'); ?></h2>
140
- <?php em_bookings_confirmed_table(); ?>
141
- <h2><?php _e('Rejected Bookings','dbem'); ?></h2>
142
- <?php em_bookings_rejected_table(); ?>
143
- <h2><?php _e('Cancelled Bookings','dbem'); ?></h2>
144
- <?php em_bookings_cancelled_table(); ?>
145
- <?php do_action('em_bookings_event_footer', $EM_Event); ?>
146
- </div>
147
- <?php
148
- }
149
-
150
- /**
151
- * Shows a ticket view
152
- */
153
- function em_bookings_ticket(){
154
- global $EM_Ticket;
155
- $EM_Event = $EM_Ticket->get_event();
156
- //check that user can access this page
157
- if( is_object($EM_Ticket) && !$EM_Ticket->can_manage() ){
158
- ?>
159
- <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php _e('You do not have the rights to manage this ticket.','dbem'); ?></p></div>
160
- <?php
161
- return false;
162
- }
163
- ?>
164
- <div class='wrap'>
165
- <div id='icon-users' class='icon32'>
166
- <br/>
167
- </div>
168
- <h2>
169
- <?php echo sprintf(__('Ticket for %s', 'dbem'), "'{$EM_Event->name}'"); ?>
170
- <a href="admin.php?page=events-manager-event&event_id=<?php echo $EM_Event->id; ?>" class="button add-new-h2"><?php _e('View/Edit Event','dbem') ?></a>
171
- <a href="admin.php?page=events-manager-bookings&event_id=<?php echo $EM_Event->id; ?>" class="button add-new-h2"><?php _e('View Event Bookings','dbem') ?></a>
172
- </h2>
173
- <div>
174
- <table>
175
- <tr><td><?php echo __('Name','dbem'); ?></td><td></td><td><?php echo $EM_Ticket->name; ?></td></tr>
176
- <tr><td><?php echo __('Description','dbem'); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td></td><td><?php echo ($EM_Ticket->description) ? $EM_Ticket->description : '-'; ?></td></tr>
177
- <tr><td><?php echo __('Price','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->price) ? $EM_Ticket->price : '-'; ?></td></tr>
178
- <tr><td><?php echo __('Spaces','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->spaces) ? $EM_Ticket->spaces : '-'; ?></td></tr>
179
- <tr><td><?php echo __('Min','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->min) ? $EM_Ticket->min : '-'; ?></td></tr>
180
- <tr><td><?php echo __('Max','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->max) ? $EM_Ticket->max : '-'; ?></td></tr>
181
- <tr><td><?php echo __('Start','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->start) ? $EM_Ticket->start : '-'; ?></td></tr>
182
- <tr><td><?php echo __('End','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->end) ? $EM_Ticket->end : '-'; ?></td></tr>
183
- </table>
184
- </div>
185
- <?php if( get_option('dbem_bookings_approval')): ?>
186
- <h2><?php _e('Pending Bookings','dbem'); ?></h2>
187
- <?php em_bookings_pending_table(); ?>
188
- <?php endif; ?>
189
- <h2><?php _e('Confirmed Bookings','dbem'); ?></h2>
190
- <?php em_bookings_confirmed_table(); ?>
191
- <h2><?php _e('Rejected Bookings','dbem'); ?></h2>
192
- <?php em_bookings_rejected_table(); ?>
193
- <h2><?php _e('Cancelled Bookings','dbem'); ?></h2>
194
- <?php em_bookings_cancelled_table(); ?>
195
- <?php do_action('em_bookings_ticket_footer', $EM_Ticket); ?>
196
- </div>
197
- <?php
198
- }
199
-
200
- /**
201
- * Shows a single booking for a single person.
202
- */
203
- function em_bookings_single(){
204
- global $EM_Booking;
205
- //check that user can access this page
206
- if( is_object($EM_Booking) && !$EM_Booking->can_manage() ){
207
- ?>
208
- <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php _e('You do not have the rights to manage this event.','dbem'); ?></p></div>
209
- <?php
210
- return false;
211
- }
212
- ?>
213
- <div class='wrap'>
214
- <div id='icon-users' class='icon32'>
215
- <br/>
216
- </div>
217
- <h2>
218
- <?php _e('Edit Booking', 'dbem'); ?>
219
- </h2>
220
- <div id="poststuff" class="metabox-holder">
221
- <div id="post-body">
222
- <div id="post-body-content">
223
- <div id="em-booking-details" class="stuffbox">
224
- <h3>
225
- <?php _e ( 'Event Details', 'dbem' ); ?>
226
- </h3>
227
- <div class="inside">
228
- <?php
229
- $EM_Event = $EM_Booking->get_event();
230
- $localised_start_date = date_i18n('D d M Y', $EM_Event->start);
231
- $localised_end_date = date_i18n('D d M Y', $EM_Event->end);
232
- ?>
233
- <table>
234
- <tr><td><strong><?php _e('Name','dbem'); ?></strong></td><td><a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php echo $EM_Event->id ?>"><?php echo ($EM_Event->name); ?></a></td></tr>
235
- <tr>
236
- <td><strong><?php _e('Date/Time','dbem'); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
237
- <td>
238
- <?php echo $localised_start_date; ?>
239
- <?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
240
- <?php echo substr ( $EM_Event->start_time, 0, 5 ) . " - " . substr ( $EM_Event->end_time, 0, 5 ); ?>
241
- </td>
242
- </tr>
243
- </table>
244
- </div>
245
- </div>
246
- <div id="em-booking-details" class="stuffbox">
247
- <h3>
248
- <?php _e ( 'Personal Details', 'dbem' ); ?>
249
- </h3>
250
- <div class="inside">
251
- <?php echo $EM_Booking->get_person()->display_summary(); ?>
252
- </div>
253
- </div>
254
- <div id="em-booking-details" class="stuffbox">
255
- <h3>
256
- <?php _e ( 'Booking Details', 'dbem' ); ?>
257
- </h3>
258
- <div class="inside">
259
- <?php
260
- $EM_Event = $EM_Booking->get_event();
261
- $localised_start_date = date_i18n('D d M Y', $EM_Event->start);
262
- $localised_end_date = date_i18n('D d M Y', $EM_Event->end);
263
- ?>
264
- <table class="em-tickets-bookings-table" cellspacing="0" cellpadding="0">
265
- <thead>
266
- <tr>
267
- <th><?php _e('Ticket Type','dbem'); ?></th>
268
- <th><?php _e('Spaces','dbem'); ?></th>
269
- <th><?php _e('Price','dbem'); ?></th>
270
- </tr>
271
- </thead>
272
- <tbody>
273
- <?php foreach($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking): ?>
274
- <tr>
275
- <td class="ticket-type"><a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;ticket_id=<?php echo $EM_Ticket_Booking->get_ticket()->id ?>"><?php echo $EM_Ticket_Booking->get_ticket()->name ?></a></td>
276
- <td><?php echo $EM_Ticket_Booking->get_spaces(); ?></td>
277
- <td><?php echo $EM_Ticket_Booking->get_price(); ?></td>
278
- </tr>
279
- <?php endforeach; ?>
280
- </tbody>
281
- <tfoot>
282
- <tr>
283
- <th><?php _e('Totals','dbem'); ?></th>
284
- <th><?php echo $EM_Booking->get_spaces(); ?></th>
285
- <th><?php echo $EM_Booking->get_price(); ?></th>
286
- </tr>
287
- </tfoot>
288
- </table>
289
- <table cellspacing="0" cellpadding="0">
290
- <tr><td><strong><?php _e('Comment','dbem'); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td><td><?php echo $EM_Booking->comment; ?></td></tr>
291
- <?php foreach( $EM_Booking->get_custom() as $custom_option ){
292
- ?><tr><td><strong><?php echo $custom_option['name'] ?></strong></td><td><?php echo $custom_option['value'] ?></td></tr><?php
293
- }
294
- ?>
295
- </table>
296
- </div>
297
- </div>
298
- <div id="event_name" class="stuffbox">
299
- <h3>
300
- <?php _e ( 'Booking Notes', 'dbem' ); ?>
301
- </h3>
302
- <div class="inside">
303
- <p><?php _e('You can add private notes below for internal reference that only event managers will see.','dbem'); ?></p>
304
- <?php foreach( $EM_Booking->notes as $note ):
305
- $user = get_userdata($note['author']);
306
- ?>
307
- <div>
308
- <?php echo date(get_option('date_format'), $note['timestamp']) .' - '. $user->display_name; ?> <?php _e('wrote','dbem'); ?>:
309
- <p style="background:#efefef; padding:5px;"><?php echo nl2br($note['note']); ?></p>
310
- </div>
311
- <?php endforeach; ?>
312
- <form method="post" action="" style="padding:5px;">
313
- <textarea class="widefat" rows="5" name="booking_note"></textarea>
314
- <input type="hidden" name="action" value="bookings_add_note" />
315
- <input type="submit" value="Add Note" />
316
- </form>
317
- </div>
318
- </div>
319
- </div>
320
- </div>
321
- </div>
322
- <br style="clear:both;" />
323
- <?php do_action('em_bookings_single_footer', $EM_Booking); ?>
324
- </div>
325
- <?php
326
-
327
- }
328
-
329
- /**
330
- * Shows all bookings made by one person.
331
- */
332
- function em_bookings_person(){
333
- global $EM_Person;
334
- ?>
335
- <div class='wrap'>
336
- <div id='icon-users' class='icon32'>
337
- <br/>
338
- </div>
339
- <h2>
340
- <?php _e('Manage Person\'s Booking', 'dbem'); ?>
341
- <?php if( current_user_can('edit_users') ) : ?>
342
- <a href="user-edit.php?user_id=<?php echo $EM_Person->ID; ?>" class="button add-new-h2"><?php _e('Edit User','dbem') ?></a>
343
- <?php endif; ?>
344
- </h2>
345
- <?php do_action('em_bookings_person_header'); ?>
346
- <div id="poststuff" class="metabox-holder has-right-sidebar">
347
- <div id="post-body">
348
- <div id="post-body-content">
349
- <div id="event_name" class="stuffbox">
350
- <h3>
351
- <?php _e ( 'Personal Details', 'dbem' ); ?>
352
- </h3>
353
- <div class="inside">
354
- <?php echo $EM_Person->display_summary(); ?>
355
- </div>
356
- </div>
357
- </div>
358
- </div>
359
- </div>
360
- <br style="clear:both;" />
361
- <?php do_action('em_bookings_person_body_1'); ?>
362
- <h3><?php _e('Past And Present Bookings','dbem'); ?></h3>
363
- <?php em_bookings_person_table(); ?>
364
- <?php do_action('em_bookings_person_footer', $EM_Person); ?>
365
- </div>
366
- <?php
367
- }
368
-
369
  ?>
1
+ <?php
2
+ /**
3
+ * Check if there's any admin-related actions to take for bookings. All actions are caught here.
4
+ * @return null
5
+ */
6
+ function em_admin_actions_bookings() {
7
+ global $dbem_form_add_message;
8
+ global $dbem_form_delete_message;
9
+ global $wpdb, $EM_Booking, $EM_Event;
10
+
11
+ if( current_user_can(EM_MIN_CAPABILITY) && is_object($EM_Booking) && !empty($_REQUEST['action']) ) {
12
+ if( $_REQUEST['action'] == 'bookings_delete' ){
13
+ //Delete
14
+ if( isset($_POST['booking_id']) ){
15
+ $EM_Booking = new EM_Booking($_POST['booking_id']);
16
+ $EM_Booking->delete();
17
+ }
18
+ }elseif( $_REQUEST['action'] == 'bookings_edit' ){
19
+ //Edit Booking
20
+ $validation = $EM_Booking->get_post();
21
+ if ( $validation ) { //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS)
22
+ //Save
23
+ if( $EM_Booking->save() ) {
24
+ function em_booking_save_notification(){ global $EM_Booking; ?><div class="updated"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
25
+ }else{
26
+ function em_booking_save_notification(){ global $EM_Booking; ?><div class="error"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
27
+ }
28
+ }else{
29
+ //TODO make errors clearer when saving person
30
+ function em_booking_save_notification(){ global $EM_Booking; ?><div class="error"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
31
+ }
32
+ add_action ( 'admin_notices', 'em_booking_save_notification' );
33
+ }elseif( $_REQUEST['action'] == 'bookings_approve' || $_REQUEST['action'] == 'bookings_reject' || $_REQUEST['action'] == 'bookings_unapprove' ){
34
+ //Booking Approvals
35
+ $status_array = array('bookings_unapprove' => 0,'bookings_approve' => 1,'bookings_reject' => 2, 'bookings_cancel' => 3);
36
+ if( $EM_Booking->set_status( $status_array[$_REQUEST['action']] ) ) {
37
+ function em_booking_save_notification(){ global $EM_Booking; ?><div class="updated"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
38
+ }else{
39
+ function em_booking_save_notification(){ global $EM_Booking; ?><div class="error"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
40
+ }
41
+ add_action ( 'admin_notices', 'em_booking_save_notification' );
42
+ }elseif( $_REQUEST['action'] == 'bookings_add_note' ){
43
+ $EM_Booking->add_note($_REQUEST['booking_note']);
44
+ function em_booking_save_notification(){ global $EM_Booking; ?><div class="updated"><p><strong><?php echo $EM_Booking->feedback_message; ?></strong></p></div><?php }
45
+ add_action ( 'admin_notices', 'em_booking_save_notification' );
46
+ }
47
+ }elseif( current_user_can(EM_MIN_CAPABILITY) && is_object($EM_Event) && !empty($_REQUEST['action']) ){
48
+ if( $_REQUEST['action'] == 'export_csv' ){
49
+ $EM_Event->get_bookings()->export_csv();
50
+ exit();
51
+ }
52
+ }
53
+ }
54
+ add_action('admin_init','em_admin_actions_bookings',100);
55
+
56
+ /**
57
+ * Decide what content to show in the bookings section.
58
+ */
59
+ function em_bookings_page(){
60
+ //First any actions take priority
61
+ if( !empty($_REQUEST['booking_id']) ){
62
+ em_bookings_single();
63
+ }elseif( !empty($_REQUEST['person_id']) ){
64
+ em_bookings_person();
65
+ }elseif( !empty($_REQUEST['event_id']) ){
66
+ em_bookings_event();
67
+ }else{
68
+ em_bookings_dashboard();
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Generates the bookings dashboard, showing information on all events
74
+ */
75
+ function em_bookings_dashboard(){
76
+ ?>
77
+ <div class='wrap'>
78
+ <div id='icon-users' class='icon32'>
79
+ <br/>
80
+ </div>
81
+ <h2>
82
+ <?php _e('Event Bookings Dashboard', 'dbem'); ?>
83
+ </h2>
84
+ <?php if( get_option('dbem_bookings_approval') ): ?>
85
+ <h2><?php _e('Pending Bookings','dbem'); ?></h2>
86
+ <?php em_bookings_pending_table(); ?>
87
+ <?php endif; ?>
88
+ <h2><?php _e('Events With Bookings Enabled','dbem'); ?></h2>
89
+ <?php em_bookings_events_table(); ?>
90
+ </div>
91
+ <?php
92
+ }
93
+
94
+ /**
95
+ * Shows all booking data for a single event
96
+ */
97
+ function em_bookings_event(){
98
+ global $EM_Event,$EM_Person;
99
+ //check that user can access this page
100
+ if( is_object($EM_Event) && !$EM_Event->can_manage() ){
101
+ ?>
102
+ <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php _e('You do not have the rights to manage this event.','dbem'); ?></p></div>
103
+ <?php
104
+ return false;
105
+ }
106
+ $localised_start_date = date_i18n('D d M Y', $EM_Event->start);
107
+ $localised_end_date = date_i18n('D d M Y', $EM_Event->end);
108
+ ?>
109
+ <div class='wrap'>
110
+ <div id='icon-users' class='icon32'>
111
+ <br/>
112
+ </div>
113
+ <h2>
114
+ <?php echo sprintf(__('Manage %s Bookings', 'dbem'), "'{$EM_Event->name}'"); ?>
115
+ <a href="admin.php?page=events-manager-event&event_id=<?php echo $EM_Event->id; ?>" class="button add-new-h2"><?php _e('View/Edit Event','dbem') ?></a>
116
+ </h2>
117
+ <div><a href='<?php echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&action=export_csv&event_id=".$EM_Event->id ?>'><?php _e('export csv','dbem')?></a></div>
118
+ <div>
119
+ <p><strong><?php _e('Event Name','dbem'); ?></strong> : <?php echo ($EM_Event->name); ?></p>
120
+ <p><strong>Availability :</strong> <?php echo $EM_Event->get_bookings()->get_booked_seats() . '/'. $EM_Event->seats ." ". __('Seats confirmed','dbem'); ?></p>
121
+ <p>
122
+ <strong><?php _e('Date','dbem'); ?></strong> :
123
+ <?php echo $localised_start_date; ?>
124
+ <?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
125
+ <?php echo substr ( $EM_Event->start_time, 0, 5 ) . " - " . substr ( $EM_Event->end_time, 0, 5 ); ?>
126
+ </p>
127
+ <p>
128
+ <strong><?php _e('Location','dbem'); ?></strong> :
129
+ <a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-locations&amp;location_id=<?php echo $EM_Event->location->id ?>"><?php echo ($EM_Event->location->name); ?></a>
130
+ </p>
131
+ </div>
132
+ <?php if( get_option('dbem_bookings_approval') ): ?>
133
+ <h2><?php _e('Pending Bookings','dbem'); ?></h2>
134
+ <?php em_bookings_pending_table(); ?>
135
+ <?php endif; ?>
136
+ <h2><?php _e('Confirmed Bookings','dbem'); ?></h2>
137
+ <?php em_bookings_confirmed_table(); ?>
138
+ <h2><?php _e('Rejected Bookings','dbem'); ?></h2>
139
+ <?php em_bookings_rejected_table(); ?>
140
+ <h2><?php _e('Cancelled Bookings','dbem'); ?></h2>
141
+ <?php em_bookings_cancelled_table(); ?>
142
+ </div>
143
+ <?php
144
+ }
145
+
146
+ /**
147
+ * Shows a single booking for a single person.
148
+ */
149
+ function em_bookings_single(){
150
+ global $EM_Booking;
151
+ //check that user can access this page
152
+ if( is_object($EM_Booking) && !$EM_Booking->can_manage() ){
153
+ ?>
154
+ <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php _e('You do not have the rights to manage this event.','dbem'); ?></p></div>
155
+ <?php
156
+ return false;
157
+ }
158
+ ?>
159
+ <div class='wrap'>
160
+ <div id='icon-users' class='icon32'>
161
+ <br/>
162
+ </div>
163
+ <h2>
164
+ <?php _e('Edit Booking', 'dbem'); ?>
165
+ </h2>
166
+ <div id="poststuff" class="metabox-holder has-right-sidebar">
167
+ <div id="post-body">
168
+ <div id="post-body-content">
169
+ <div id="event_name" class="stuffbox">
170
+ <h3>
171
+ <?php _e ( 'Booking Details', 'dbem' ); ?>
172
+ </h3>
173
+ <div class="inside">
174
+ <?php em_bookings_edit_form(); ?>
175
+ </div>
176
+ </div>
177
+ </div>
178
+ </div>
179
+ </div>
180
+ <br style="clear:both;" />
181
+ <div id="poststuff" class="metabox-holder has-right-sidebar">
182
+ <div id="post-body">
183
+ <div id="post-body-content">
184
+ <div id="event_name" class="stuffbox">
185
+ <h3>
186
+ <?php _e ( 'Booking Notes', 'dbem' ); ?>
187
+ </h3>
188
+ <div class="inside">
189
+ <p><?php _e('You can add private notes below for internal reference that only event managers will see.','dbem'); ?></p>
190
+ <?php foreach( $EM_Booking->notes as $note ):
191
+ $user = get_userdata($note['author']);
192
+ ?>
193
+ <div>
194
+ <?php echo date(get_option('date_format'), $note['timestamp']) .' - '. $user->display_name; ?> <?php _e('wrote','dbem'); ?>:
195
+ <p style="background:#efefef; padding:5px;"><?php echo nl2br($note['note']); ?></p>
196
+ </div>
197
+ <?php endforeach; ?>
198
+ <form method="post" action="" style="padding:5px;">
199
+ <textarea class="widefat" rows="5" name="booking_note"></textarea>
200
+ <input type="hidden" name="action" value="bookings_add_note" />
201
+ <input type="submit" value="Add Note" />
202
+ </form>
203
+ </div>
204
+ </div>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ <br style="clear:both;" />
209
+ <?php do_action('em_bookings_single_footer'); ?>
210
+ </div>
211
+ <?php
212
+
213
+ }
214
+
215
+ /**
216
+ * Shows all bookings made by one person.
217
+ */
218
+ function em_bookings_person(){
219
+ global $EM_Person;
220
+ ?>
221
+ <div class='wrap'>
222
+ <div id='icon-users' class='icon32'>
223
+ <br/>
224
+ </div>
225
+ <h2>
226
+ <?php _e('Manage Person\'s Booking', 'dbem'); ?>
227
+ <a href="admin.php?page=events-manager-bookings&action=person_delete&person_id=<?php echo $EM_Person->id; ?>" onclick="if( !confirm('<?php _e('Are you sure you want to delete this person? All bookings corresponding to this person will be deleted and this is not reversible.','dbem') ?>') ){ return false; }" class="button add-new-h2"><?php _e('Delete Person','dbem') ?></a>
228
+ </h2>
229
+ <div id="poststuff" class="metabox-holder has-right-sidebar">
230
+ <div id="post-body">
231
+ <div id="post-body-content">
232
+ <div id="event_name" class="stuffbox">
233
+ <h3>
234
+ <?php _e ( 'Personal Details', 'dbem' ); ?>
235
+ </h3>
236
+ <div class="inside">
237
+ <?php em_person_edit_form(); ?>
238
+ </div>
239
+ </div>
240
+ </div>
241
+ </div>
242
+ </div>
243
+ <br style="clear:both;" />
244
+ <h3><?php _e('Past And Present Bookings','dbem'); ?></h3>
245
+ <?php em_bookings_person_table(); ?>
246
+ </div>
247
+ <?php
248
+ }
249
+
250
+ function em_bookings_edit_form(){
251
+ global $EM_Booking;
252
+ $EM_Event = new EM_Event($EM_Booking->event_id);
253
+ $localised_start_date = date_i18n('D d M Y', $EM_Event->start);
254
+ $localised_end_date = date_i18n('D d M Y', $EM_Event->end);
255
+ ?>
256
+ <form action="" method="post" id="em-person-form">
257
+ <h4>Event Details</h4>
258
+ <table>
259
+ <tr><td><strong><?php _e('Name','dbem'); ?></strong></td><td><a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php echo $EM_Event->id ?>"><?php echo ($EM_Event->name); ?></a></td></tr>
260
+ <tr>
261
+ <td><strong><?php _e('Date/Time','dbem'); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
262
+ <td>
263
+ <?php echo $localised_start_date; ?>
264
+ <?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
265
+ <?php echo substr ( $EM_Event->start_time, 0, 5 ) . " - " . substr ( $EM_Event->end_time, 0, 5 ); ?>
266
+ </td>
267
+ </tr>
268
+ </table>
269
+ <h4>Personal Details</h4>
270
+ <table>
271
+ <tr><td><strong><?php _e('Name','dbem'); ?> </strong></td><td><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person_id; ?>"><?php echo $EM_Booking->person->name ?></a></td></tr>
272
+ <tr><td><strong><?php _e('Phone','dbem'); ?> </strong></td><td><?php echo $EM_Booking->person->phone; ?></td></tr>
273
+ <tr><td><strong><?php _e('E-mail','dbem'); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td><td><?php echo $EM_Booking->person->email; ?></td></tr>
274
+ </table>
275
+ <h4>Booking Details</h4>
276
+ <table>
277
+ <tr><td><strong><?php _e('Spaces','dbem'); ?> </strong></td><td><input type="text" name="booking_seats" value="<?php echo $EM_Booking->seats; ?>" /></td></tr>
278
+ <tr><td><strong><?php _e('Comment','dbem'); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td><td><textarea name="booking_comment"><?php echo $EM_Booking->comment; ?></textarea></td></tr>
279
+ </table>
280
+ <p class="submit">
281
+ <input type="submit" name="events_update" value="<?php _e ( 'Save' ); ?> &raquo;" />
282
+ </p>
283
+ <input type="hidden" name="action" value="bookings_edit" />
284
+ <input type="hidden" name="booking_id" value="<?php echo $EM_Booking->id; ?>" />
285
+ </form>
286
+ <?php
287
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  ?>
admin/em-categories.php CHANGED
@@ -1,177 +1,177 @@
1
- <?php
2
- function em_admin_categories_page() {
3
- global $wpdb, $EM_Category;
4
-
5
- if( !empty($_REQUEST['action']) ){
6
- if( $_REQUEST['action'] == "save") {
7
- // save (add/update) category
8
- if( empty($EM_Category) || !is_object($EM_Category) ){
9
- $EM_Category = new EM_Category(); //blank category
10
- $success_message = __('The category has been added.', 'dbem');
11
- }else{
12
- $success_message = __('The category has been updated.', 'dbem');
13
- }
14
- $EM_Category->get_post();
15
- if ( $EM_Category->validate() ) {
16
- $EM_Category->save(); //FIXME better handling of db write fails when saving category
17
- em_categories_table_layout($success_message);
18
- } else {
19
- ?>
20
- <div id='message' class='error '>
21
- <p>
22
- <strong><?php _e( "Ach, there's a problem here:", "dbem" ) ?></strong><br /><br /><?php echo implode('<br />', $EM_Category->errors); ?>
23
- </p>
24
- </div>
25
- <?php
26
- em_categories_edit_layout();
27
- }
28
- } elseif( $_REQUEST['action'] == "edit" ){
29
- em_categories_edit_layout();
30
- } elseif( $_REQUEST['action'] == "delete" ){
31
- //delelte category
32
- EM_Categories::delete($_REQUEST['categories']);
33
- //FIXME no result verification when deleting various categories
34
- $message = __('Categories Deleted', "dbem" );
35
- em_categories_table_layout($message);
36
- }
37
- }else{
38
- em_categories_table_layout();
39
- }
40
- }
41
-
42
- function em_categories_table_layout($message = "") {
43
- $categories = EM_Categories::get();
44
- $destination = get_bloginfo('url')."/wp-admin/admin.php";
45
- ?>
46
- <div class='wrap nosubsub'>
47
- <div id='icon-edit' class='icon32'>
48
- <br/>
49
- </div>
50
- <h2><?php echo __('Categories', 'dbem') ?></h2>
51
-
52
- <?php if($message != "") : ?>
53
- <div id='message' class='updated fade below-h2' style='background-color: rgb(255, 251, 204);'>
54
- <p><?php echo $message ?></p>
55
- </div>
56
- <?php endif; ?>
57
-
58
- <div id='col-container'>
59
- <!-- begin col-right -->
60
- <div id='col-right'>
61
- <div class='col-wrap'>
62
- <form id='bookings-filter' method='post' action='<?php echo get_bloginfo('wpurl') ?>/wp-admin/admin.php?page=events-manager-categories'>
63
- <input type='hidden' name='action' value='delete'/>
64
- <?php if (count($categories)>0) : ?>
65
- <table class='widefat'>
66
- <thead>
67
- <tr>
68
- <th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1'/></th>
69
- <th><?php echo __('ID', 'dbem') ?></th>
70
- <th><?php echo __('Name', 'dbem') ?></th>
71
- </tr>
72
- </thead>
73
- <tfoot>
74
- <tr>
75
- <th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1'/></th>
76
- <th><?php echo __('ID', 'dbem') ?></th>
77
- <th><?php echo __('Name', 'dbem') ?></th>
78
- </tr>
79
- </tfoot>
80
- <tbody>
81
- <?php foreach ($categories as $EM_Category) : ?>
82
- <tr>
83
- <td><input type='checkbox' class ='row-selector' value='<?php echo $EM_Category->id ?>' name='categories[]'/></td>
84
- <td><a href='<?php echo get_bloginfo('wpurl') ?>/wp-admin/admin.php?page=events-manager-categories&amp;action=edit&amp;category_id=<?php echo $EM_Category->id ?>'><?php echo htmlspecialchars($EM_Category->id, ENT_QUOTES); ?></a></td>
85
- <td><a href='<?php echo get_bloginfo('wpurl') ?>/wp-admin/admin.php?page=events-manager-categories&amp;action=edit&amp;category_id=<?php echo $EM_Category->id ?>'><?php echo htmlspecialchars($EM_Category->name, ENT_QUOTES); ?></a></td>
86
- </tr>
87
- <?php endforeach; ?>
88
- </tbody>
89
-
90
- </table>
91
-
92
- <div class='tablenav'>
93
- <div class='alignleft actions'>
94
- <input class='button-secondary action' type='submit' name='doaction2' value='Delete'/>
95
- <br class='clear'/>
96
- </div>
97
- <br class='clear'/>
98
- </div>
99
- <?php else: ?>
100
- <p><?php echo __('No categories have been inserted yet!', 'dbem'); ?></p>
101
- <?php endif; ?>
102
- </form>
103
- </div>
104
- </div>
105
- <!-- end col-right -->
106
-
107
- <!-- begin col-left -->
108
- <div id='col-left'>
109
- <div class='col-wrap'>
110
- <div class='form-wrap'>
111
- <div id='ajax-response'>
112
- <h3><?php echo __('Add category', 'dbem') ?></h3>
113
- <form name='add' id='add' method='post' action='admin.php?page=events-manager-categories' class='add:the-list: validate'>
114
- <input type='hidden' name='action' value='save' />
115
- <div class='form-field form-required'>
116
- <label for='category_name'><?php echo __('Category name', 'dbem') ?></label>
117
- <input id='category-name' name='category_name' id='category_name' type='text' size='40' />
118
- <p><?php echo __('The name of the category', 'dbem'); ?></p>
119
- </div>
120
- <p class='submit'><input type='submit' class='button' name='submit' value='<?php echo __('Add category', 'dbem') ?>' /></p>
121
- </form>
122
- </div>
123
- </div>
124
- </div>
125
- </div>
126
- <!-- end col-left -->
127
- </div>
128
- </div>
129
- <?php
130
- }
131
-
132
-
133
- function em_categories_edit_layout($message = "") {
134
- global $EM_Category;
135
- if( !is_object($EM_Category) ){
136
- $EM_Category = new EM_Category();
137
- }
138
- //check that user can access this page
139
- if( is_object($EM_Category) && !$EM_Category->can_manage('edit_categories') ){
140
- ?>
141
- <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php implode('<br/>',$EM_Category->get_errors()); ?></p></div>
142
- <?php
143
- return;
144
- }
145
- ?>
146
- <div class='wrap'>
147
- <div id='icon-edit' class='icon32'>
148
- <br/>
149
- </div>
150
-
151
- <h2><?php echo __('Edit category', 'dbem') ?></h2>
152
-
153
- <?php if($message != "") : ?>
154
- <div id='message' class='updated fade below-h2' style='background-color: rgb(255, 251, 204);'>
155
- <p><?php echo $message ?></p>
156
- </div>
157
- <?php endif; ?>
158
-
159
- <div id='ajax-response'></div>
160
-
161
- <form name='editcat' id='editcat' method='post' action='admin.php?page=events-manager-categories' class='validate'>
162
- <input type='hidden' name='action' value='save' />
163
- <input type='hidden' name='category_id' value='<?php echo $EM_Category->id ?>'/>
164
-
165
- <table class='form-table'>
166
- <tr class='form-field form-required'>
167
- <th scope='row' valign='top'><label for='category_name'><?php echo __('Category name', 'dbem') ?></label></th>
168
- <td><input name='category_name' id='category-name' type='text' value='<?php echo $EM_Category->name ?>' size='40' /><br />
169
- <?php echo __('The name of the category', 'dbem') ?></td>
170
- </tr>
171
- </table>
172
- <p class='submit'><input type='submit' class='button-primary' name='submit' value='<?php echo __('Update category', 'dbem') ?>' /></p>
173
- </form>
174
- </div>
175
- <?php
176
- }
177
  ?>
1
+ <?php
2
+ function em_admin_categories_page() {
3
+ global $wpdb, $EM_Category;
4
+
5
+ if( !empty($_REQUEST['action']) ){
6
+ if( $_REQUEST['action'] == "save") {
7
+ // save (add/update) category
8
+ if( empty($EM_Category) || !is_object($EM_Category) ){
9
+ $EM_Category = new EM_Category(); //blank category
10
+ $success_message = __('The category has been added.', 'dbem');
11
+ }else{
12
+ $success_message = __('The category has been updated.', 'dbem');
13
+ }
14
+ $EM_Category->get_post();
15
+ if ( $EM_Category->validate() ) {
16
+ $EM_Category->save(); //FIXME better handling of db write fails when saving category
17
+ em_categories_table_layout($success_message);
18
+ } else {
19
+ ?>
20
+ <div id='message' class='error '>
21
+ <p>
22
+ <strong><?php _e( "Ach, there's a problem here:", "dbem" ) ?></strong><br /><br /><?php echo implode('<br />', $EM_Category->errors); ?>
23
+ </p>
24
+ </div>
25
+ <?php
26
+ em_categories_edit_layout();
27
+ }
28
+ } elseif( $_REQUEST['action'] == "edit" ){
29
+ em_categories_edit_layout();
30
+ } elseif( $_REQUEST['action'] == "delete" ){
31
+ //delelte category
32
+ EM_Categories::delete($_REQUEST['categories']);
33
+ //FIXME no result verification when deleting various categories
34
+ $message = __('Categories Deleted', "dbem" );
35
+ em_categories_table_layout($message);
36
+ }
37
+ }else{
38
+ em_categories_table_layout($message);
39
+ }
40
+ }
41
+
42
+ function em_categories_table_layout($message = "") {
43
+ $categories = EM_Categories::get();
44
+ $destination = get_bloginfo('url')."/wp-admin/admin.php";
45
+ ?>
46
+ <div class='wrap nosubsub'>
47
+ <div id='icon-edit' class='icon32'>
48
+ <br/>
49
+ </div>
50
+ <h2><?php echo __('Categories', 'dbem') ?></h2>
51
+
52
+ <?php if($message != "") : ?>
53
+ <div id='message' class='updated fade below-h2' style='background-color: rgb(255, 251, 204);'>
54
+ <p><?php echo $message ?></p>
55
+ </div>
56
+ <?php endif; ?>
57
+
58
+ <div id='col-container'>
59
+ <!-- begin col-right -->
60
+ <div id='col-right'>
61
+ <div class='col-wrap'>
62
+ <form id='bookings-filter' method='post' action='<?php echo get_bloginfo('wpurl') ?>/wp-admin/admin.php?page=events-manager-categories'>
63
+ <input type='hidden' name='action' value='delete'/>
64
+ <?php if (count($categories)>0) : ?>
65
+ <table class='widefat'>
66
+ <thead>
67
+ <tr>
68
+ <th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1'/></th>
69
+ <th><?php echo __('ID', 'dbem') ?></th>
70
+ <th><?php echo __('Name', 'dbem') ?></th>
71
+ </tr>
72
+ </thead>
73
+ <tfoot>
74
+ <tr>
75
+ <th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1'/></th>
76
+ <th><?php echo __('ID', 'dbem') ?></th>
77
+ <th><?php echo __('Name', 'dbem') ?></th>
78
+ </tr>
79
+ </tfoot>
80
+ <tbody>
81
+ <?php foreach ($categories as $EM_Category) : ?>
82
+ <tr>
83
+ <td><input type='checkbox' class ='row-selector' value='<?php echo $EM_Category->id ?>' name='categories[]'/></td>
84
+ <td><a href='<?php echo get_bloginfo('wpurl') ?>/wp-admin/admin.php?page=events-manager-categories&amp;action=edit&amp;category_id=<?php echo $EM_Category->id ?>'><?php echo htmlspecialchars($EM_Category->id, ENT_QUOTES); ?></a></td>
85
+ <td><a href='<?php echo get_bloginfo('wpurl') ?>/wp-admin/admin.php?page=events-manager-categories&amp;action=edit&amp;category_id=<?php echo $EM_Category->id ?>'><?php echo htmlspecialchars($EM_Category->name, ENT_QUOTES); ?></a></td>
86
+ </tr>
87
+ <?php endforeach; ?>
88
+ </tbody>
89
+
90
+ </table>
91
+
92
+ <div class='tablenav'>
93
+ <div class='alignleft actions'>
94
+ <input class='button-secondary action' type='submit' name='doaction2' value='Delete'/>
95
+ <br class='clear'/>
96
+ </div>
97
+ <br class='clear'/>
98
+ </div>
99
+ <?php else: ?>
100
+ <p><?php echo __('No categories have been inserted yet!', 'dbem'); ?></p>
101
+ <?php endif; ?>
102
+ </form>
103
+ </div>
104
+ </div>
105
+ <!-- end col-right -->
106
+
107
+ <!-- begin col-left -->
108
+ <div id='col-left'>
109
+ <div class='col-wrap'>
110
+ <div class='form-wrap'>
111
+ <div id='ajax-response'>
112
+ <h3><?php echo __('Add category', 'dbem') ?></h3>
113
+ <form name='add' id='add' method='post' action='admin.php?page=events-manager-categories' class='add:the-list: validate'>
114
+ <input type='hidden' name='action' value='save' />
115
+ <div class='form-field form-required'>
116
+ <label for='category_name'><?php echo __('Category name', 'dbem') ?></label>
117
+ <input id='category-name' name='category_name' id='category_name' type='text' size='40' />
118
+ <p><?php echo __('The name of the category', 'dbem'); ?></p>
119
+ </div>
120
+ <p class='submit'><input type='submit' class='button' name='submit' value='<?php echo __('Add category', 'dbem') ?>' /></p>
121
+ </form>
122
+ </div>
123
+ </div>
124
+ </div>
125
+ </div>
126
+ <!-- end col-left -->
127
+ </div>
128
+ </div>
129
+ <?php
130
+ }
131
+
132
+
133
+ function em_categories_edit_layout($message = "") {
134
+ global $EM_Category;
135
+ if( !is_object($EM_Category) ){
136
+ $EM_Category = new EM_Category();
137
+ }
138
+ //check that user can access this page
139
+ if( is_object($EM_Category) && !$EM_Category->can_manage() ){
140
+ ?>
141
+ <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php _e('You do not have the rights to manage this event.','dbem'); ?></p></div>
142
+ <?php
143
+ return;
144
+ }
145
+ ?>
146
+ <div class='wrap'>
147
+ <div id='icon-edit' class='icon32'>
148
+ <br/>
149
+ </div>
150
+
151
+ <h2><?php echo __('Edit category', 'dbem') ?></h2>
152
+
153
+ <?php if($message != "") : ?>
154
+ <div id='message' class='updated fade below-h2' style='background-color: rgb(255, 251, 204);'>
155
+ <p><?php echo $message ?></p>
156
+ </div>
157
+ <?php endif; ?>
158
+
159
+ <div id='ajax-response'></div>
160
+
161
+ <form name='editcat' id='editcat' method='post' action='admin.php?page=events-manager-categories' class='validate'>
162
+ <input type='hidden' name='action' value='save' />
163
+ <input type='hidden' name='category_id' value='<?php echo $EM_Category->id ?>'/>
164
+
165
+ <table class='form-table'>
166
+ <tr class='form-field form-required'>
167
+ <th scope='row' valign='top'><label for='category_name'><?php echo __('Category name', 'dbem') ?></label></th>
168
+ <td><input name='category_name' id='category-name' type='text' value='<?php echo $EM_Category->name ?>' size='40' /><br />
169
+ <?php echo __('The name of the category', 'dbem') ?></td>
170
+ </tr>
171
+ </table>
172
+ <p class='submit'><input type='submit' class='button-primary' name='submit' value='<?php echo __('Update category', 'dbem') ?>' /></p>
173
+ </form>
174
+ </div>
175
+ <?php
176
+ }
177
  ?>
admin/em-docs.php CHANGED
@@ -1,197 +1,193 @@
1
- <?php
2
-
3
- function em_docs_init(){
4
- if( class_exists('EM_Event') ){
5
- add_action('wp_head', 'emd_head');
6
- //Generate the docs
7
- global $EM_Documentation;
8
- $EM_Event = new EM_Event();
9
- $event_fields = $EM_Event->get_fields(true);
10
- $EM_Location = new EM_Location();
11
- $location_fields = $EM_Location->get_fields(true);
12
- $EM_Documentation = array(
13
- 'arguments' => array(
14
- 'events' => array(
15
- 'limit' => array( 'default'=>'See the events lists limit option on the settings page.' ),
16
- 'orderby' => array( 'desc'=>'Choose what fields to order your results by. You can supply a single field or multiple comma-seperated fields (e.g. "start_date,name").', 'default'=>'See the event lists ordering option on the settings page.', 'args'=>'name, start_date, start_time, end_date, end_time'),
17
- 'order' => array( 'default'=>'See the event lists ordering option on the settings page.' )
18
- ),
19
- 'locations' => array(
20
- 'eventful' => array( 'desc'=>'If set to 1 will only show locations that have at least one event occurring during the scope.', 'default' => 0),
21
- 'eventless' => array( 'desc'=>'If set to 1 will only show locations that have no events occurring during the scope.', 'default' => 0),
22
- 'orderby' => array('desc'=>'Choose what fields to order your results by. You can supply a single field or multiple comma-seperated fields (e.g. "start_date,name").', 'default'=>'name', 'args' => 'name, address, town'),
23
- 'scope' => array( 'default' => 'all')
24
- ),
25
- 'calendar' => array(
26
- 'full' => array( 'desc'=>'If set to 1 it will display a full calendar that shows event names.', 'default' => 0),
27
- 'long_events' => array( 'desc'=>'If set to 1, will show events that last longer than a day.', 'default' => 0),
28
- 'order' => array( 'desc'=>'Same as for events.' ),
29
- 'scope' => array( 'default' => 'future')
30
- ),
31
- //The object is commonly shared by all, so entries above overwrite entries here
32
- 'general' => array(
33
- 'limit' => array( 'desc'=>'Limits the amount of values returned to this number.', 'default'=>'0 (no limit)'),
34
- 'scope' => array( 'desc'=>'Choose the time frame of events to show. Accepted values are "future", "past" or "all" events. Additionally you can supply dates (in format of YYYY-MM-DD), either single for events on a specific date or two dates seperated by a comma (e.g. 2010-12-25,2010-12-31) for events ocurring between these dates.', 'default'=>'future'),
35
- 'order' => array( 'desc'=>'Indicates the order of the events. Choose between ASC (ascending) and DESC (descending).', 'default'=>'ASC'),
36
- 'orderby' => array( 'desc'=>'Choose what fields to order your results by. You can supply a single field or multiple comma-seperated fields (e.g. "start_date,name"). See specific instances (e.g. events, locations, etc.) for field names.', 'default'=>0),
37
- 'format' => array( 'desc'=>'If you are displaying some information with the shortcode or function (e.g. listing events), you can supply the html and placeholders here.', 'default'=>'The relevant default format will be taken from the settings page.'),
38
- 'event' => array( 'desc'=>'Supply a single id or comma-seperated ids (e.g. "1,2,3") to limit the search to events with these id(s).', 'default'=>0),
39
- 'category' => array( 'desc'=>'Supply a single id or comma-seperated ids (e.g. "1,2,3") to limit the search to events in these categories.', 'default'=>0),
40
- 'location' => array( 'desc'=>'Supply a single id or comma-seperated ids to limit the search to these locations (or events in these locations).', 'default'=>0),
41
- 'offset' => array( 'desc'=>'For example, if you have ten results, if you set this to 5, only the last 5 results will be returned. Useful for pagination.', 'default'=>0),
42
- 'recurrence' => array( 'desc'=>'If set to 1, will show only events that are recurring (i.e. events that are repeated over different dates).', 'default'=>0),
43
- 'recurring' => array( 'desc'=>'If set to 1, will only show recurring event templates. Only useful if you know what you\'re doing, use recurrence if you want events that are recurrences.', 'default'=>0),
44
- 'month' => array( 'desc'=>'If set to a month (1 to 12) only events that start or end during this month/year will be retured. Must be used in conjunction with year', 'default'=>''),
45
- 'year' => array( 'desc'=>'If set to a year (e.g. 2010) only events that start or end during this year/month will be returned. Must be used in conjunction with year', 'default'=>''),
46
- 'array' => array( 'desc'=>'If you supply this as an argument, the returned data will be in an array, no objects (only useful wen using PHP, not shortcodes)', 'default'=>0),
47
- 'pagination' => array('desc'=>'When using a function or shortcode that outputs items (e.g. [events_list] for events, [locations_list] for locations), if the number of items supercede the limit of items to show, setting this to 1 will show page links under the list.', 'default'=>0)
48
- )
49
- ),
50
- 'placeholders' => array(
51
- 'events' => array(
52
- 'Event Details' => array(
53
- 'placeholders' => array(
54
- '#_NAME' => array( 'desc' => 'Displays the name of the event.' ),
55
- '#_NOTES' => array( 'desc' => 'Shows the description of the event.' ),
56
- '#_EXCERPT' => array( 'desc' => 'If you added a <a href="http://en.support.wordpress.com/splitting-content/more-tag/">more tag</a> to your event description, only the content before this tag will show (currently, no read more link is added).' ),
57
- '#_EVENTID' => array( 'desc' => 'Shows the event\'s corresponding ID number in the database table.' )
58
- )
59
- ),
60
- 'Category Details' => array(
61
- 'placeholders' => array(
62
- '#_CATEGORYNAME' => array( 'desc' => 'Shows the category name of the event.' ),
63
- '#_CATEGORYID' => array( 'desc' => 'Shows the category ID of the event.' )
64
- )
65
- ),
66
- 'Time' => array(
67
- 'desc' => '',
68
- 'placeholders' => array(
69
- '#_24HSTARTTIME' => array( 'desc' => 'Displays the start time in a 24 hours format (e.g. 16:30).' ),
70
- '#_24HENDTIME' => array( 'desc' => 'Displays the end time in a 24 hours format (e.g. 18:30).' ),
71
- '#_12HSTARTTIME' => array( 'desc' => 'Displays the start time in a 12 hours format (e.g. 4:30 PM).' ),
72
- '#_12HENDTIME' => array( 'desc' => 'Displays the end time in a 12 hours format (e.g. 6:30 PM).' )
73
- )
74
- ),
75
- 'Custom Date/Time Formatting' => array(
76
- 'desc' => 'Events Manager allows extremely flexible date formatting by using <a href="http://www.php.net/manual/en/function.date.php">PHP date syntax format characters</a> along with placeholders.',
77
- 'placeholders' => array(
78
- '# or #@' => array( 'desc' => 'Prepend <code>#</code> or <code>#@</code> before a valid PHP date syntax format character to show start and end date/time information respectively (e.g. <code>#F</code> will show the starting month name like "January", #@h shows the end hour).' ),
79
- '#{x} or #@{x}' => array( 'desc' => 'You can also create a date format without prepending # to each character by wrapping a valid php date() format in <code>#{}</code> or <code>#@{}</code> (e.g. <code>#_{d/m/Y}</code>). If there is no end date (or is same as start date), the value is not shown. This is useful if you want to show event end dates only on events that are longer than on day, e.g. <code>#j #M #Y #@_{ \u\n\t\i\l j M Y}</code>.' ),
80
- )
81
- ),
82
- 'Links' => array(
83
- 'placeholders' => array(
84
- '#_EVENTURL' => array( 'desc' => 'Simply prints the event URL. You can use this placeholder to build your own customised links.' ),
85
- '#_EVENTLINK' => array( 'desc' => 'Displays the event name with a link to the event page.' ),
86
- '#_EDITEVENTLINK' => array( 'desc' => 'Inserts a link to the edit event page, only if a user is logged in and is allowed to edit the event.' )
87
- )
88
- ),
89
- 'Custom Attributes' => array(
90
- 'desc' => 'Events Manager allows you to create dynamic attributes to your events, which act as extra information fields for your events (e.g. "Dress Code"). For more information see <a href="http://wp-events-plugin.com/documentation/categories-and-attributes/">our online documentation</a> for more info on attributes.',
91
- 'placeholders' => array(
92
- '#_ATT{key}{alternative text}' => array('desc'=>'This key will appear as an option when adding attributes to your event. The second braces are optional and will appear if the attribute is not defined or left blank for that event.')
93
- )
94
- ),
95
- 'Bookings/RSVP' => array(
96
- 'desc' => 'These placeholders will only show if RSVP is enabled for the given event and in the events manager settings page. Spaces placeholders will default to 0',
97
- 'placeholders' => array(
98
- '#_ADDBOOKINGFORM' => array( 'desc' => 'Adds a form which allows the visitors to register for an event.' ),
99
- '#_REMOVEBOOKINGFORM' => array( 'desc' => 'Adds a form which allows the visitors to remove their booking.' ),
100
- '#_BOOKINGFORM' => array( 'desc' => 'Adds a both booking forms (add and remove).' ),
101
- '#_AVAILABLESPACES' => array( 'desc' => 'Shows available spaces for the event.' ),
102
- '#_BOOKEDSPACES' => array( 'desc' => 'Shows the amount of currently booked spaces for the event.' ),
103
- '#_PENDINGSPACES' => array( 'desc' => 'Shows the amount of pending spaces for the event.' ),
104
- '#_SPACES' => array( 'desc' => 'Shows the total spaces for the event.' ),
105
- '#_ATTENDEES' => array( 'desc' => 'Shows the list of user avatars attending events.' )
106
- )
107
- ),
108
- 'Contact Details' => array(
109
- 'desc' => 'The values here are taken from the chosen contact for the specific event, or the default contact in the settings page.',
110
- 'placeholders' => array(
111
- '#_CONTACTNAME' => array( 'desc' => 'Name of the contact person for this event (as shown in the dropdown when adding an event).' ),
112
- '#_CONTACTUSERNAME' => array( 'desc' => 'Contact person\'s username.' ),
113
- '#_CONTACTEMAIL' => array( 'desc' => 'E-mail of the contact person for this event.' ),
114
- '#_CONTACTPHONE' => array( 'desc' => 'Phone number of the contact person for this event. Can be set in the user profile page.' ),
115
- '#_CONTACTAVATAR' => array( 'desc' => 'Contact person\'s avatar.' ),
116
- '#_CONTACTPROFILELINK' => array( 'desc' => 'Contact person\'s "Profile" link. Only works with BuddyPress enabled.' ),
117
- '#_CONTACTPROFILEURL' => array( 'desc' => 'Contact person\'s profile url. Only works with BuddyPress enabled.' ),
118
- '#_CONTACTID' => array( 'desc' => 'Contact person\'s wordpress user ID.')
119
- )
120
- ),
121
- ),
122
- 'locations' => array(
123
- 'Location Details' => array(
124
- 'desc' => '',
125
- 'placeholders' => array(
126
- '#_LOCATIONNAME' => array( 'desc' => 'Displays the location name.' ),
127
- '#_LOCATIONADDRESS' => array( 'desc' => 'Displays the address.' ),
128
- '#_LOCATIONTOWN' => array( 'desc' => 'Displays the town.' ),
129
- '#_LOCATIONMAP' => array( 'desc' => 'Displays a google map showing where the event is located (Will not show if maps are disabled in the settings page)' ),
130
- '#_LOCATIONNOTES' => array( 'desc' => 'Shows the location description.' ),
131
- '#_LOCATIONEXCERPT' => array( 'desc' => 'If you added a <a href="http://en.support.wordpress.com/splitting-content/more-tag/">more tag</a> to your location description, only the content before this tag will show (currently, no read more link is added).' ),
132
- '#_LOCATIONIMAGE' => array( 'desc' => 'Shows the location image.' ),
133
- '#_LOCATIONID' => array( 'desc' => 'Displays the location ID number.' )
134
- )
135
- ),
136
- 'Links' => array(
137
- 'placeholders' => array(
138
- '#_LOCATIONURL' => array( 'desc' => 'Simply prints the location URL. You can use this placeholder to build your own customised links.' ),
139
- '#_LOCATIONLINK' => array( 'desc' => 'Displays the location name with a link to the location page.' )
140
- )
141
- ),
142
- 'Related Events' => array(
143
- 'desc' => 'You can show lists of other events that are being held at this location. The formatting of the list is the same as a normal events list.',
144
- 'placeholders' => array(
145
- '#_LOCATIONPASTEVENTS' => array( 'desc' => 'Will show a list of all past events at this location.' ),
146
- '#_LOCATIONNEXTEVENTS' => array( 'desc' => 'Will show a list of all future events at this location.' ),
147
- '#_LOCATIONALLEVENTS' => array( 'desc' => 'Will show a list of all events at this location.' )
148
- )
149
- ),
150
- ),
151
- 'bookings' => array(
152
- 'Booking Person Information' => array(
153
- 'desc' => 'When a specific booking is displayed (on screen and on email), you can use these placeholders to show specific information about the booking. For contact details of the contact of this event, see the events placeholders.',
154
- 'placeholders' => array(
155
- '#_BOOKINGNAME' => array( 'desc' => 'Name of person who made the booking.' ),
156
- '#_BOOKINGEMAIL' => array( 'desc' => 'Email of person who made the booking.' ),
157
- '#_BOOKINGPHONE' => array( 'desc' => 'Phone number of person who made the booking.' ),
158
- '#_BOOKINGSPACES' => array( 'desc' => 'Number of spaces the person has booked.' ),
159
- '#_BOOKINGCOMMENT' => array( 'desc' => 'Any specific comments made by the person who made the booking.' )
160
- )
161
- )
162
- ),
163
- ),
164
- //TODO add capabilites explanations
165
- 'capabilities' => array()
166
- );
167
- }
168
- }
169
- add_action('init', 'em_docs_init');
170
-
171
- function em_docs_placeholders($atts){
172
- ob_start();
173
- ?>
174
- <div class="em-docs">
175
- <?php
176
- global $EM_Documentation;
177
- $type = $atts['type'];
178
- $data = $EM_Documentation['placeholders'][$type];
179
- foreach($data as $sectionTitle => $details) : ?>
180
- <div>
181
- <h3><?php echo $sectionTitle; ?></h3>
182
- <?php if( !empty($details['desc']) ): ?>
183
- <p><?php echo $details['desc']; ?></p>
184
- <?php endif; ?>
185
- <dl>
186
- <?php foreach($details['placeholders'] as $placeholder => $desc ): ?>
187
- <dt><b><?php echo $placeholder; ?></b></dt>
188
- <dd><?php echo $desc['desc']; ?></dd>
189
- <?php endforeach; ?>
190
- </dl>
191
- </div>
192
- <?php endforeach; ?>
193
- </div>
194
- <?php
195
- return ob_get_clean();
196
- }
197
  ?>
1
+ <?php
2
+
3
+ function em_docs_init(){
4
+ if( class_exists('EM_Event') ){
5
+ add_action('wp_head', 'emd_head');
6
+ //Generate the docs
7
+ global $EM_Documentation;
8
+ $EM_Event = new EM_Event();
9
+ $event_fields = $EM_Event->get_fields(true);
10
+ $EM_Location = new EM_Location();
11
+ $location_fields = $EM_Location->get_fields(true);
12
+ $EM_Documentation = array(
13
+ 'arguments' => array(
14
+ 'events' => array(
15
+ 'limit' => array( 'default'=>'See the events lists limit option on the settings page.' ),
16
+ 'orderby' => array( 'desc'=>'Choose what fields to order your results by. You can supply a single field or multiple comma-seperated fields (e.g. "start_date,name").', 'default'=>'See the event lists ordering option on the settings page.', 'args'=>'name, start_date, start_time, end_date, end_time'),
17
+ 'order' => array( 'default'=>'See the event lists ordering option on the settings page.' )
18
+ ),
19
+ 'locations' => array(
20
+ 'eventful' => array( 'desc'=>'If set to 1 will only show locations that have at least one event occurring during the scope.', 'default' => 0),
21
+ 'eventless' => array( 'desc'=>'If set to 1 will only show locations that have no events occurring during the scope.', 'default' => 0),
22
+ 'orderby' => array('desc'=>'Choose what fields to order your results by. You can supply a single field or multiple comma-seperated fields (e.g. "start_date,name").', 'default'=>'name', 'args' => 'name, address, town'),
23
+ 'scope' => array( 'default' => 'all')
24
+ ),
25
+ 'calendar' => array(
26
+ 'full' => array( 'desc'=>'If set to 1 it will display a full calendar that shows event names.', 'default' => 0),
27
+ 'long_events' => array( 'desc'=>'If set to 1, will show events that last longer than a day.', 'default' => 0),
28
+ 'order' => array( 'desc'=>'Same as for events.' ),
29
+ 'scope' => array( 'default' => 'future')
30
+ ),
31
+ //The object is commonly shared by all, so entries above overwrite entries here
32
+ 'general' => array(
33
+ 'limit' => array( 'desc'=>'Limits the amount of values returned to this number.', 'default'=>'0 (no limit)'),
34
+ 'scope' => array( 'desc'=>'Choose the time frame of events to show. Accepted values are "future", "past" or "all" events. Additionally you can supply dates (in format of YYYY-MM-DD), either single for events on a specific date or two dates seperated by a comma (e.g. 2010-12-25,2010-12-31) for events ocurring between these dates.', 'default'=>'future'),
35
+ 'order' => array( 'desc'=>'Indicates the order of the events. Choose between ASC (ascending) and DESC (descending).', 'default'=>'ASC'),
36
+ 'orderby' => array( 'desc'=>'Choose what fields to order your results by. You can supply a single field or multiple comma-seperated fields (e.g. "start_date,name"). See specific instances (e.g. events, locations, etc.) for field names.', 'default'=>0),
37
+ 'format' => array( 'desc'=>'If you are displaying some information with the shortcode or function (e.g. listing events), you can supply the html and placeholders here.', 'default'=>'The relevant default format will be taken from the settings page.'),
38
+ 'event' => array( 'desc'=>'Supply a single id or comma-seperated ids (e.g. "1,2,3") to limit the search to events with these id(s).', 'default'=>0),
39
+ 'category' => array( 'desc'=>'Supply a single id or comma-seperated ids (e.g. "1,2,3") to limit the search to events in these categories.', 'default'=>0),
40
+ 'location' => array( 'desc'=>'Supply a single id or comma-seperated ids to limit the search to these locations (or events in these locations).', 'default'=>0),
41
+ 'offset' => array( 'desc'=>'For example, if you have ten results, if you set this to 5, only the last 5 results will be returned. Useful for pagination.', 'default'=>0),
42
+ 'recurrence' => array( 'desc'=>'If set to 1, will show only events that are recurring (i.e. events that are repeated over different dates).', 'default'=>0),
43
+ 'recurring' => array( 'desc'=>'If set to 1, will only show recurring event templates. Only useful if you know what you\'re doing, use recurrence if you want events that are recurrences.', 'default'=>0),
44
+ 'month' => array( 'desc'=>'If set to a month (1 to 12) only events that start or end during this month/year will be retured. Must be used in conjunction with year', 'default'=>''),
45
+ 'year' => array( 'desc'=>'If set to a year (e.g. 2010) only events that start or end during this year/month will be returned. Must be used in conjunction with year', 'default'=>''),
46
+ 'array' => array( 'desc'=>'If you supply this as an argument, the returned data will be in an array, no objects (only useful wen using PHP, not shortcodes)', 'default'=>0),
47
+ 'pagination' => array('desc'=>'When using a function or shortcode that outputs items (e.g. [events_list] for events, [locations_list] for locations), if the number of items supercede the limit of items to show, setting this to 1 will show page links under the list.', 'default'=>0)
48
+ )
49
+ ),
50
+ 'placeholders' => array(
51
+ 'events' => array(
52
+ 'Event Details' => array(
53
+ 'placeholders' => array(
54
+ '#_NAME' => array( 'desc' => 'Displays the name of the event.' ),
55
+ '#_NOTES' => array( 'desc' => 'Shows the description of the event.' ),
56
+ '#_EXCERPT' => array( 'desc' => 'If you added a <a href="http://en.support.wordpress.com/splitting-content/more-tag/">more tag</a> to your event description, only the content before this tag will show (currently, no read more link is added).' ),
57
+ '#_EVENTID' => array( 'desc' => 'Shows the event\'s corresponding ID number in the database table.' )
58
+ )
59
+ ),
60
+ 'Category Details' => array(
61
+ 'placeholders' => array(
62
+ '#_CATEGORYNAME' => array( 'desc' => 'Shows the category name of the event.' ),
63
+ '#_CATEGORYID' => array( 'desc' => 'Shows the category ID of the event.' )
64
+ )
65
+ ),
66
+ 'Time' => array(
67
+ 'desc' => '',
68
+ 'placeholders' => array(
69
+ '#_24HSTARTTIME' => array( 'desc' => 'Displays the start time in a 24 hours format (e.g. 16:30).' ),
70
+ '#_24HENDTIME' => array( 'desc' => 'Displays the end time in a 24 hours format (e.g. 18:30).' ),
71
+ '#_12HSTARTTIME' => array( 'desc' => 'Displays the start time in a 12 hours format (e.g. 4:30 PM).' ),
72
+ '#_12HENDTIME' => array( 'desc' => 'Displays the end time in a 12 hours format (e.g. 6:30 PM).' )
73
+ )
74
+ ),
75
+ 'Custom Date/Time Formatting' => array(
76
+ 'desc' => 'Events Manager allows extremely flexible date formatting by using <a href="http://www.php.net/manual/en/function.date.php">PHP date syntax format characters</a> along with placeholders.',
77
+ 'placeholders' => array(
78
+ '# or #@' => array( 'desc' => 'Prepend <code>#</code> or <code>#@</code> before a valid PHP date syntax format character to show start and end date/time information respectively (e.g. <code>#F</code> will show the starting month name like "January", #@h shows the end hour).' ),
79
+ '#{x} or #@{x}' => array( 'desc' => 'You can also create a date format without prepending # to each character by wrapping a valid php date() format in <code>#{}</code> or <code>#@{}</code> (e.g. <code>#_{d/m/Y}</code>). If there is no end date (or is same as start date), the value is not shown. This is useful if you want to show event end dates only on events that are longer than on day, e.g. <code>#j #M #Y #@_{ \u\n\t\i\l j M Y}</code>.' ),
80
+ )
81
+ ),
82
+ 'Links' => array(
83
+ 'placeholders' => array(
84
+ '#_EVENTURL' => array( 'desc' => 'Simply prints the event URL. You can use this placeholder to build your own customised links.' ),
85
+ '#_EVENTLINK' => array( 'desc' => 'Displays the event name with a link to the event page.' ),
86
+ '#_EDITEVENTLINK' => array( 'desc' => 'Inserts a link to the edit event page, only if a user is logged in and is allowed to edit the event.' )
87
+ )
88
+ ),
89
+ 'Custom Attributes' => array(
90
+ 'desc' => 'Events Manager allows you to create dynamic attributes to your events, which act as extra information fields for your events (e.g. "Dress Code"). For more information see <a href="http://wp-events-plugin.com/documentation/categories-and-attributes/">our online documentation</a> for more info on attributes.',
91
+ 'placeholders' => array(
92
+ '#_ATT{key}{alternative text}' => array('desc'=>'This key will appear as an option when adding attributes to your event. The second braces are optional and will appear if the attribute is not defined or left blank for that event.')
93
+ )
94
+ ),
95
+ 'Bookings/RSVP' => array(
96
+ 'desc' => 'These placeholders will only show if RSVP is enabled for the given event and in the events manager settings page. Spaces placeholders will default to 0',
97
+ 'placeholders' => array(
98
+ '#_ADDBOOKINGFORM' => array( 'desc' => 'Adds a form which allows the visitors to register for an event.' ),
99
+ '#_REMOVEBOOKINGFORM' => array( 'desc' => 'Adds a form which allows the visitors to remove their booking.' ),
100
+ '#_BOOKINGFORM' => array( 'desc' => 'Adds a both booking forms (add and remove).' ),
101
+ '#_AVAILABLESPACES' => array( 'desc' => 'Shows available spaces for the event.' ),
102
+ '#_BOOKEDSPACES' => array( 'desc' => 'Shows the amount of currently booked seats for the event.' ),
103
+ '#_SPACES' => array( 'desc' => 'Shows the total spaces for the event.' )
104
+ )
105
+ ),
106
+ 'Contact Details' => array(
107
+ 'desc' => 'The values here are taken from the chosen contact for the specific event, or the default contact in the settings page.',
108
+ 'placeholders' => array(
109
+ '#_CONTACTNAME' => array( 'desc' => 'Name of the contact person for this event (as shown in the dropdown when adding an event).' ),
110
+ '#_CONTACTUSERNAME' => array( 'desc' => 'Contact person\'s username.' ),
111
+ '#_CONTACTEMAIL' => array( 'desc' => 'E-mail of the contact person for this event.' ),
112
+ '#_CONTACTPHONE' => array( 'desc' => 'Phone number of the contact person for this event. Can be set in the user profile page.' ),
113
+ '#_CONTACTAVATAR' => array( 'desc' => 'Contact person\'s avatar.' ),
114
+ '#_CONTACTPROFILELINK' => array( 'desc' => 'Contact person\'s "Profile" link. Only works with BuddyPress enabled.' ),
115
+ '#_CONTACTPROFILEURL' => array( 'desc' => 'Contact person\'s profile url. Only works with BuddyPress enabled.' ),
116
+ '#_CONTACTID' => array( 'desc' => 'Contact person\'s wordpress user ID.')
117
+ )
118
+ ),
119
+ ),
120
+ 'locations' => array(
121
+ 'Location Details' => array(
122
+ 'desc' => '',
123
+ 'placeholders' => array(
124
+ '#_LOCATIONNAME' => array( 'desc' => 'Displays the location name.' ),
125
+ '#_LOCATIONADDRESS' => array( 'desc' => 'Displays the address.' ),
126
+ '#_LOCATIONTOWN' => array( 'desc' => 'Displays the town.' ),
127
+ '#_LOCATIONMAP' => array( 'desc' => 'Displays a google map showing where the event is located (Will not show if maps are disabled in the settings page)' ),
128
+ '#_LOCATIONNOTES' => array( 'desc' => 'Shows the location description.' ),
129
+ '#_LOCATIONEXCERPT' => array( 'desc' => 'If you added a <a href="http://en.support.wordpress.com/splitting-content/more-tag/">more tag</a> to your location description, only the content before this tag will show (currently, no read more link is added).' ),
130
+ '#_LOCATIONIMAGE' => array( 'desc' => 'Shows the location image.' ),
131
+ '#_LOCATIONID' => array( 'desc' => 'Displays the location ID number.' )
132
+ )
133
+ ),
134
+ 'Links' => array(
135
+ 'placeholders' => array(
136
+ '#_LOCATIONURL' => array( 'desc' => 'Simply prints the location URL. You can use this placeholder to build your own customised links.' ),
137
+ '#_LOCATIONLINK' => array( 'desc' => 'Displays the location name with a link to the location page.' )
138
+ )
139
+ ),
140
+ 'Related Events' => array(
141
+ 'desc' => 'You can show lists of other events that are being held at this location. The formatting of the list is the same as a normal events list.',
142
+ 'placeholders' => array(
143
+ '#_LOCATIONPASTEVENTS' => array( 'desc' => 'Will show a list of all past events at this location.' ),
144
+ '#_LOCATIONNEXTEVENTS' => array( 'desc' => 'Will show a list of all future events at this location.' ),
145
+ '#_LOCATIONALLEVENTS' => array( 'desc' => 'Will show a list of all events at this location.' )
146
+ )
147
+ ),
148
+ ),
149
+ 'bookings' => array(
150
+ 'Booking Person Information' => array(
151
+ 'desc' => 'When a specific booking is displayed (on screen and on email), you can use these placeholders to show specific information about the booking. For contact details of the contact of this event, see the events placeholders.',
152
+ 'placeholders' => array(
153
+ '#_BOOKINGNAME' => array( 'desc' => 'Name of person who made the booking.' ),
154
+ '#_BOOKINGEMAIL' => array( 'desc' => 'Email of person who made the booking.' ),
155
+ '#_BOOKINGPHONE' => array( 'desc' => 'Phone number of person who made the booking.' ),
156
+ '#_BOOKINGSPACES' => array( 'desc' => 'Number of spaces the person has booked.' ),
157
+ '#_BOOKINGCOMMENT' => array( 'desc' => 'Any specific comments made by the person who made the booking.' )
158
+ )
159
+ )
160
+ ),
161
+ )
162
+ );
163
+ }
164
+ }
165
+ add_action('init', 'em_docs_init');
166
+
167
+ function em_docs_placeholders($atts){
168
+ ob_start();
169
+ ?>
170
+ <div class="em-docs">
171
+ <?php
172
+ global $EM_Documentation;
173
+ $type = $atts['type'];
174
+ $data = $EM_Documentation['placeholders'][$type];
175
+ foreach($data as $sectionTitle => $details) : ?>
176
+ <div>
177
+ <h3><?php echo $sectionTitle; ?></h3>
178
+ <?php if($details['desc'] != ''): ?>
179
+ <p><?php echo $details['desc']; ?></p>
180
+ <?php endif; ?>
181
+ <dl>
182
+ <?php foreach($details['placeholders'] as $placeholder => $desc ): ?>
183
+ <dt><b><?php echo $placeholder; ?></b></dt>
184
+ <dd><?php echo $desc['desc']; ?></dd>
185
+ <?php endforeach; ?>
186
+ </dl>
187
+ </div>
188
+ <?php endforeach; ?>
189
+ </div>
190
+ <?php
191
+ return ob_get_clean();
192
+ }
 
 
 
 
193
  ?>
admin/em-event.php CHANGED
@@ -1,725 +1,627 @@
1
- <?php
2
- function em_admin_event_actions(){
3
- if( current_user_can(EM_MIN_CAPABILITY) && !empty($_GET['page']) && $_GET['page'] == 'events-manager-event' && !empty($_REQUEST ['action']) ){
4
- global $wpdb;
5
- global $EM_Event;
6
- //if dealing with new event, we still want an event object
7
- if( !is_object($EM_Event) ){
8
- $EM_Event = new EM_Event();
9
- }
10
- }
11
- }
12
- add_action('admin_init', 'em_admin_event_actions');
13
-
14
- /**
15
- * Generates Event Admin page, for adding and updating a single (or recurring) event.
16
- * @param $title
17
- * @return null
18
- */
19
- function em_admin_event_page() {
20
- global $EM_Event, $current_user, $EM_Notices, $localised_date_formats;
21
- //$EM_Event->get_bookings()->get_tickets()->get_ticket_bookings(); print_r($EM_Event);die();
22
-
23
- //check that user can access this page
24
- if( is_object($EM_Event) && !$EM_Event->can_manage('edit_events','edit_others_events') ){
25
- ?>
26
- <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php echo sprintf(__('You do not have the rights to manage this %s.','dbem'),__('Event','dbem')); ?></p></div>
27
- <?php
28
- return false;
29
- }
30
-
31
- if( is_object($EM_Event) && $EM_Event->id > 0 ){
32
- if($EM_Event->is_recurring()){
33
- $title = __( "Reschedule", 'dbem' )." '{$EM_Event->name}'";
34
- }else{
35
- $title = __ ( "Edit Event", 'dbem' ) . " '" . $EM_Event->name . "'";
36
- }
37
- } else {
38
- $EM_Event = ( is_object($EM_Event) && get_class($EM_Event) == 'EM_Event') ? $EM_Event : new EM_Event();
39
- $title = __ ( "Insert New Event", 'dbem' );
40
- //Give a default location & category
41
- $default_cat = get_option('dbem_default_category');
42
- $default_loc = get_option('dbem_default_location');
43
- if( is_numeric($default_cat) && $default_cat > 0 ){
44
- $EM_Event->category_id = $default_cat;
45
- $EM_Event->category = new EM_Category($default_cat);
46
- }
47
- if( is_numeric($default_loc) && $default_loc > 0 && ( empty($EM_Event->location->id) && empty($EM_Event->location->name) && empty($EM_Event->location->address) && empty($EM_Event->location->town) ) ){
48
- $EM_Event->location_id = $default_loc;
49
- $EM_Event->location = new EM_Location($default_loc);
50
- }
51
- }
52
-
53
- $use_select_for_locations = get_option('dbem_use_select_for_locations');
54
- // change prefix according to event/recurrence
55
- $pref = "event_";
56
-
57
- $locale_code = substr ( get_locale (), 0, 2 );
58
- $localised_date_format = $localised_date_formats[$locale_code];
59
-
60
- //FIXME time useage is very flimsy imho
61
- $hours_locale_regexp = "H:i";
62
- // Setting 12 hours format for those countries using it
63
- if (preg_match ( "/en|sk|zh|us|uk/", $locale_code ))
64
- $hours_locale_regexp = "h:iA";
65
-
66
- $days_names = array (1 => __ ( 'Mon' ), 2 => __ ( 'Tue' ), 3 => __ ( 'Wed' ), 4 => __ ( 'Thu' ), 5 => __ ( 'Fri' ), 6 => __ ( 'Sat' ), 0 => __ ( 'Sun' ) );
67
- ?>
68
- <?php echo $EM_Notices; ?>
69
-
70
- <form id="event-form" method="post" action="">
71
- <div class="wrap">
72
- <div id="icon-events" class="icon32"><br /></div>
73
- <h2><?php echo $title; ?></h2>
74
- <?php if ( count($EM_Event->warnings) > 0 ) : ?>
75
- <?php foreach($EM_Event->warnings as $warning): ?>
76
- <p class="warning"><?php echo $warning; ?></p>
77
- <?php endforeach; ?>
78
- <?php endif; ?>
79
- <div id="poststuff" class="metabox-holder has-right-sidebar">
80
- <!-- SIDEBAR -->
81
- <div id="side-info-column" class='inner-sidebar'>
82
- <div id='side-sortables'>
83
- <?php if(get_option('dbem_recurrence_enabled') && ($EM_Event->is_recurrence() || $EM_Event->is_recurring() || $EM_Event->id == '')) : ?>
84
- <!-- START recurrence postbox -->
85
- <div class="postbox ">
86
- <div class="handlediv" title="Fare clic per cambiare."><br />
87
- </div>
88
- <h3 class='hndle'><span>
89
- <?php _e ( "Recurrence", 'dbem' ); ?>
90
- </span></h3>
91
- <div class="inside">
92
- <?php //TODO add js warning if rescheduling, since all bookings are deleted ?>
93
- <?php if ( !$EM_Event->id || $EM_Event->is_recurring() ) : ?>
94
- <p>
95
- <input id="event-recurrence" type="checkbox" name="repeated_event" value="1" <?php echo ( $EM_Event->is_recurring() ) ? 'checked="checked"':'' ; ?> />
96
- <?php _e ( 'Repeated event', 'dbem' ); ?>
97
- </p>
98
- <div id="event_recurrence_pattern">
99
- <p>
100
- Frequency:
101
- <select id="recurrence-frequency" name="recurrence_freq">
102
- <?php
103
- $freq_options = array ("daily" => __ ( 'Daily', 'dbem' ), "weekly" => __ ( 'Weekly', 'dbem' ), "monthly" => __ ( 'Monthly', 'dbem' ) );
104
- em_option_items ( $freq_options, $EM_Event->freq );
105
- ?>
106
- </select>
107
- </p>
108
- <p>
109
- <?php _e ( 'Every', 'dbem' )?>
110
- <input id="recurrence-interval" name='recurrence_interval' size='2' value='<?php echo $EM_Event->interval ; ?>' />
111
- <span class='interval-desc' id="interval-daily-singular">
112
- <?php _e ( 'day', 'dbem' )?>
113
- </span> <span class='interval-desc' id="interval-daily-plural">
114
- <?php _e ( 'days', 'dbem' ) ?>
115
- </span> <span class='interval-desc' id="interval-weekly-singular">
116
- <?php _e ( 'week', 'dbem' )?>
117
- </span> <span class='interval-desc' id="interval-weekly-plural">
118
- <?php _e ( 'weeks', 'dbem' )?>
119
- </span> <span class='interval-desc' id="interval-monthly-singular">
120
- <?php _e ( 'month', 'dbem' )?>
121
- </span> <span class='interval-desc' id="interval-monthly-plural">
122
- <?php _e ( 'months', 'dbem' )?>
123
- </span>
124
- </p>
125
- <p class="alternate-selector" id="weekly-selector">
126
- <?php
127
- $saved_bydays = ($EM_Event->is_recurring()) ? explode ( ",", $EM_Event->byday ) : array();
128
- em_checkbox_items ( 'recurrence_bydays[]', $days_names, $saved_bydays );
129
- ?>
130
- </p>
131
- <p class="alternate-selector" id="monthly-selector">
132
- <?php _e ( 'Every', 'dbem' )?>
133
- <select id="monthly-modifier" name="recurrence_byweekno">
134
- <?php
135
- $weekno_options = array ("1" => __ ( 'first', 'dbem' ), '2' => __ ( 'second', 'dbem' ), '3' => __ ( 'third', 'dbem' ), '4' => __ ( 'fourth', 'dbem' ), '-1' => __ ( 'last', 'dbem' ) );
136
- em_option_items ( $weekno_options, $EM_Event->byweekno );
137
- ?>
138
- </select>
139
- <select id="recurrence-weekday" name="recurrence_byday">
140
- <?php em_option_items ( $days_names, $EM_Event->byday ); ?>
141
- </select>
142
- &nbsp;
143
- </p>
144
- </div>
145
- <p id="recurrence-tip">
146
- <?php _e ( 'Check if your event happens more than once according to a regular pattern', 'dbem' )?>
147
- </p>
148
- <?php elseif( $EM_Event->is_recurrence() ) : ?>
149
- <p>
150
- <?php echo $EM_Event->get_recurrence_description(); ?>
151
- <br />
152
- <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&amp;event_id=<?php echo $EM_Event->recurrence_id; ?>">
153
- <?php _e ( 'Reschedule', 'dbem' ); ?>
154
- </a>
155
- <input type="hidden" name="recurrence_id" value="<?php echo $EM_Event->recurrence_id; ?>" />
156
- </p>
157
- <?php else : ?>
158
- <p><?php _e ( 'This is\'t a recurrent event', 'dbem' ) ?></p>
159
- <?php endif; ?>
160
- </div>
161
- </div>
162
- <!-- END recurrence postbox -->
163
- <?php endif; ?>
164
- <?php if(get_option('dbem_rsvp_enabled')) : ?>
165
- <!-- START RSVP -->
166
- <?php if ( current_user_can('edit_others_events') ): ?>
167
- <div class="postbox ">
168
- <div class="handlediv" title="Fare clic per cambiare."><br />
169
- </div>
170
- <h3 class='hndle'><span><?php _e ( 'Event Owner/Contact Person', 'dbem' ); ?></span></h3>
171
- <div class="inside">
172
- <?php
173
- wp_dropdown_users ( array ('name' => 'event_owner', 'show_option_none' => __ ( "Select...", 'dbem' ), 'selected' => $EM_Event->owner ) );
174
- ?>
175
- </div>
176
- </div>
177
- <?php else: ?>
178
- <input type="hidden" name="event_owner" value="<?php get_current_user_id() ?>" />
179
- <?php endif; ?>
180
- <div class="postbox " id='rsvp-data'>
181
- <div class="handlediv" title="Fare clic per cambiare."><br />
182
- </div>
183
- <h3 class='hndle'><span><?php _e('Bookings Stats','dbem'); ?></span></h3>
184
- <div class="inside">
185
- <div>
186
- <!-- START RSVP Stats -->
187
- <?php
188
- $available_spaces = $EM_Event->get_bookings()->get_available_spaces();
189
- $booked_spaces = $EM_Event->get_bookings()->get_booked_spaces();
190
-
191
- if ( count($EM_Event->get_bookings()->bookings) > 0 ) {
192
- ?>
193
- <div class='wrap'>
194
- <p><strong><?php echo __('Available Spaces','dbem').': '.$EM_Event->get_bookings()->get_available_spaces(); ?></strong></p>
195
- <p><strong><?php echo __('Confirmed Spaces','dbem').': '.$EM_Event->get_bookings()->get_booked_spaces(); ?></strong></p>
196
- <p><strong><?php echo __('Pending Spaces','dbem').': '.$EM_Event->get_bookings()->get_pending_spaces(); ?></strong></p>
197
- </div>
198
-
199
- <br class='clear'/>
200
-
201
- <div id='major-publishing-actions'>
202
- <div id='publishing-action'>
203
- <a id='printable' href='<?php echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&event_id=".$EM_Event->id ?>'><?php _e('manage bookings','dbem')?></a><br />
204
- <a target='_blank' href='<?php echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&action=bookings_report&event_id=".$EM_Event->id ?>'><?php _e('printable view','dbem')?></a>
205
- <a href='<?php echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&action=export_csv&event_id=".$EM_Event->id ?>'><?php _e('export csv','dbem')?></a>
206
- <br class='clear'/>
207
- </div>
208
- <br class='clear'/>
209
- </div>
210
- <?php
211
- } else {
212
- ?>
213
- <p><em><?php _e('No responses yet!')?></em></p>
214
- <?php
215
- }
216
- ?>
217
- <!-- END RSVP Stats -->
218
- </div>
219
- </div>
220
- </div>
221
- <!-- END RSVP -->
222
- <?php endif; ?>
223
- <?php if(get_option('dbem_categories_enabled')) :?>
224
- <!-- START Categories -->
225
- <div class="postbox ">
226
- <div class="handlediv" title="Fare clic per cambiare."><br />
227
- </div>
228
- <h3 class='hndle'><span>
229
- <?php _e ( 'Category', 'dbem' ); ?>
230
- </span></h3>
231
- <div class="inside">
232
- <?php $categories = EM_Categories::get(array('orderby'=>'category_name')); ?>
233
- <?php if( count($categories) > 0 ): ?>
234
- <p><?php _e ( 'Category:', 'dbem' ); ?>
235
- <select name="event_category_id">
236
- <option value="" <?php echo ($EM_Event->category_id == '') ? "selected='selected'":'' ?>><?php _e('no category','dbem') ?></option>
237
- <?php
238
- foreach ( $categories as $EM_Category ){
239
- $selected = ($EM_Category->id == $EM_Event->category_id) ? "selected='selected'": '';
240
- ?>
241
- <option value="<?php echo $EM_Category->id ?>" <?php echo $selected ?>>
242
- <?php echo $EM_Category->name ?>
243
- </option>
244
- <?php
245
- }
246
- ?>
247
- </select>
248
- </p>
249
- <?php else: ?>
250
- <p><?php sprintf(__('No categories available, <a href="%s">create one here first</a>','dbem'), get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager-categories'); ?></p>
251
- <?php endif; ?>
252
- </div>
253
- </div>
254
- <!-- END Categories -->
255
- <?php endif; ?>
256
- </div>
257
- </div>
258
- <!-- END OF SIDEBAR -->
259
- <div id="post-body">
260
- <div id="post-body-content">
261
- <div id="event_name" class="stuffbox">
262
- <h3>
263
- <?php _e ( 'Name', 'dbem' ); ?>
264
- </h3>
265
- <div class="inside">
266
- <input type="text" name="event_name" id="event-name" value="<?php echo htmlspecialchars($EM_Event->name,ENT_QUOTES); ?>" />
267
- <br />
268
- <?php _e ( 'The event name. Example: Birthday party', 'dbem' )?>
269
- </div>
270
- </div>
271
- <div id="event_start_date" class="stuffbox">
272
- <h3 id='event-date-title'><?php _e ( 'Event date', 'dbem' ); ?></h3>
273
- <h3 id='recurrence-dates-title'><?php _e ( 'Recurrence dates', 'dbem' ); ?></h3>
274
- <div class="inside">
275
- <input id="localised-date" type="text" name="localised_event_date" style="display: none;" />
276
- <input id="date-to-submit" type="text" name="event_start_date" value="<?php echo $EM_Event->start_date ?>" style="background: #FCFFAA" />
277
- <input id="localised-end-date" type="text" name="localised_event_end_date" style="display: none;" />
278
- <input id="end-date-to-submit" type="text" name="event_end_date" value="<?php echo $EM_Event->end_date ?>" style="background: #FCFFAA" />
279
- <br />
280
- <span id='event-date-explanation'>
281
- <?php
282
- _e ( 'The event date.', 'dbem' );
283
- /* Marcus Begin Edit */
284
- echo " ";
285
- _e ( 'When not reoccurring, this event spans between the beginning and end date.', 'dbem' );
286
- /* Marcus End Edit */
287
- ?>
288
- </span>
289
- <span id='recurrence-dates-explanation'>
290
- <?php _e ( 'The recurrence beginning and end date.', 'dbem' ); ?>
291
- </span>
292
- </div>
293
- </div>
294
- <div id="event_end_day" class="stuffbox">
295
- <h3>
296
- <?php _e ( 'Event time', 'dbem' ); ?>
297
- </h3>
298
- <div class="inside">
299
- <input id="start-time" type="text" size="8" maxlength="8" name="event_start_time" value="<?php echo date( $hours_locale_regexp, strtotime($EM_Event->start_time) ); ?>" />
300
- -
301
- <input id="end-time" type="text" size="8" maxlength="8" name="event_end_time" value="<?php echo date( $hours_locale_regexp, strtotime($EM_Event->end_time) ); ?>" />
302
- <br />
303
- <?php _e ( 'The time of the event beginning and end', 'dbem' )?>.
304
- </div>
305
- </div>
306
- <div id="location_coordinates" class="stuffbox" style='display: none;'>
307
- <h3>
308
- <?php _e ( 'Coordinates', 'dbem' ); ?>
309
- </h3>
310
- <div class="inside">
311
- <input id='location-latitude' name='location_latitude' type='text' value='<?php echo $EM_Event->get_location()->latitude; ?>' size='15' />
312
- -
313
- <input id='location-longitude' name='location_longitude' type='text' value='<?php echo $EM_Event->get_location()->longitude; ?>' size='15' />
314
- </div>
315
- </div>
316
- <div id="location_info" class="stuffbox">
317
- <h3>
318
- <?php _e ( 'Location', 'dbem' ); ?>
319
- </h3>
320
- <div class="inside">
321
- <table id="dbem-location-data">
322
- <tr>
323
- <td style="padding-right:20px; width:100%;">
324
- <table>
325
- <?php if($use_select_for_locations) : ?>
326
- <tr>
327
- <th><?php _e('Location:','dbem') ?></th>
328
- <td>
329
- <select name="location-select-id" id='location-select-id' size="1">
330
- <?php
331
- $locations = EM_Locations::get();
332
- foreach($locations as $location) {
333
- $selected = "";
334
- if ($EM_Event->get_location()->id == $location->id){
335
- $selected = "selected='selected' ";
336
- }
337
- ?>
338
- <option value="<?php echo $location->id ?>" title="<?php echo "{$location->latitude},{$location->longitude}" ?>" <?php echo $selected ?>><?php echo $location->name; ?></option>
339
- <?php
340
- }
341
- ?>
342
- </select>
343
- <p><?php _e ( 'The name of the location where the event takes place. You can use the name of a venue, a square, etc', 'dbem' )?></p>
344
- </td>
345
- </tr>
346
- <?php else : ?>
347
- <tr>
348
- <th><?php _e ( 'Name:' )?></th>
349
- <td>
350
- <input id='location-id' name='location_id' type='hidden' value='<?php echo $EM_Event->get_location()->id; ?>' size='15' />
351
- <input id="location-name" type="text" name="location_name" value="<?php echo htmlspecialchars($EM_Event->location->name, ENT_QUOTES); ?>" />
352
- <p><?php _e ( 'Create a location or start typing to search a previously created location.', 'dbem' )?></p>
353
- </td>
354
- </tr>
355
- <tr>
356
- <th><?php _e ( 'Address:' )?>&nbsp;</th>
357
- <td>
358
- <input id="location-address" type="text" name="location_address" value="<?php echo htmlspecialchars($EM_Event->location->address, ENT_QUOTES); ; ?>" /> <?php echo $required; ?>
359
- </td>
360
- </tr>
361
- <tr>
362
- <th><?php _e ( 'City/Town:' )?>&nbsp;</th>
363
- <td>
364
- <input id="location-town" type="text" name="location_town" value="<?php echo htmlspecialchars($EM_Event->location->town, ENT_QUOTES); ?>" /> <?php echo $required; ?>
365
- </td>
366
- </tr>
367
- <tr>
368
- <th><?php _e ( 'State/County:' )?>&nbsp;</th>
369
- <td>
370
- <input id="location-state" type="text" name="location_state" value="<?php echo htmlspecialchars($EM_Event->location->state, ENT_QUOTES); ?>" />
371
- </td>
372
- </tr>
373
- <tr>
374
- <th><?php _e ( 'Postcode:' )?>&nbsp;</th>
375
- <td>
376
- <input id="location-postcode" type="text" name="location_postcode" value="<?php echo htmlspecialchars($EM_Event->location->postcode, ENT_QUOTES); ?>" />
377
- </td>
378
- </tr>
379
- <tr>
380
- <th><?php _e ( 'Country:' )?>&nbsp;</th>
381
- <td>
382
- <select id="location-country" name="location_country">
383
- <?php foreach(em_get_countries(__('none selected','dbem')) as $country_key => $country_name): ?>
384
- <option value="<?php echo $country_key; ?>" <?php echo ( $EM_Event->location->country === $country_key || ($EM_Event->location->country == '' && $EM_Event->location->id == '' && get_option('dbem_location_default_country')==$country_key) ) ? 'selected="selected"':''; ?>><?php echo $country_name; ?></option>
385
- <?php endforeach; ?>
386
- </select> <?php echo $required; ?>
387
- </td>
388
- </tr>
389
- <?php endif; ?>
390
- </table>
391
- </td>
392
- <?php if ( get_option ( 'dbem_gmap_is_active' ) ) : ?>
393
- <td width="400">
394
- <div id='em-map-404' style='width: 400px; vertical-align:middle; text-align: center;'>
395
- <p><em><?php _e ( 'Location not found', 'dbem' ); ?></em></p>
396
- </div>
397
- <div id='em-map' style='width: 400px; height: 300px; display: none;'></div>
398
- </td>
399
- <?php endif; ?>
400
- </tr>
401
- </table>
402
- </div>
403
- </div>
404
- <div id="event_notes" class="stuffbox">
405
- <h3>
406
- <?php _e ( 'Details', 'dbem' ); ?>
407
- </h3>
408
- <div class="inside">
409
- <div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
410
- <?php the_editor($EM_Event->notes ); ?>
411
- </div>
412
- <br />
413
- <?php _e ( 'Details about the event', 'dbem' )?>
414
- </div>
415
- </div>
416
-
417
- <?php if(get_option('dbem_rsvp_enabled')) : ?>
418
- <div id="event-bookings" class="stuffbox">
419
- <h3><span><?php _e('Bookings/Registration','dbem'); ?></span></h3>
420
- <div class="inside">
421
- <div class="wrap">
422
- <p>
423
- <input id="event-rsvp" name='event_rsvp' value='1' type='checkbox' <?php echo ($EM_Event->rsvp) ? 'checked="checked"' : ''; ?> />
424
- <?php _e ( 'Enable registration for this event', 'dbem' )?>
425
- </p>
426
- <br />
427
- <div id="event-tickets" style="<?php echo ($EM_Event->rsvp) ? '':'display:none;' ?>">
428
- <p><strong><?php _e('Tickets','dbem'); ?></strong></p>
429
- <p><em><?php _e('You have single or multiple tickets, where certain tickets become availalble under certain conditions, e.g. early bookings, group discounts, maximum bookings per ticket, etc.', 'dbem'); ?></em></p>
430
- <table class="form-table">
431
- <thead>
432
- <tr valign="top">
433
- <th class="ticket-status">&nbsp;</th>
434
- <th><?php _e('Ticket Name','dbem'); ?></th>
435
- <th><?php _e('Price','dbem'); ?></th>
436
- <th><?php _e('Min/Max','dbem'); ?></th>
437
- <th><?php _e('Start/End','dbem'); ?></th>
438
- <th><?php _e('Avail. Spaces','dbem'); ?></th>
439
- <th><?php _e('Booked Spaces','dbem'); ?></th>
440
- <th>&nbsp;</th>
441
- </tr>
442
- </thead>
443
- <tfoot>
444
- <tr valign="top">
445
- <td colspan="6">
446
- <a href="#" id="em-tickets-add" rel="#em-tickets-form"><?php _e('Add new ticket','dbem'); ?></a>
447
- </td>
448
- </tr>
449
- </tfoot>
450
- <tbody id="em-tickets-body">
451
- <?php
452
- $EM_Tickets = $EM_Event->get_bookings()->get_tickets();
453
- if( count($EM_Tickets->tickets) > 0 ){
454
- $count = 1;
455
- foreach( $EM_Tickets->tickets as $EM_Ticket){
456
- ?>
457
- <tr valign="top" id="em-tickets-row-<?php echo $count ?>" class="em-tickets-row">
458
- <td class="ticket-status"><span class="<?php echo ($EM_Ticket->is_available()) ? 'ticket_on':'ticket_off'; ?>"></span></td>
459
- <td class="ticket-name"><span class="ticket_name"><?php echo $EM_Ticket->name ?></span><br /><span class="ticket_description"></span></td>
460
- <td class="ticket-price">
461
- <span class="ticket_price"><?php echo ($EM_Ticket->price) ? $EM_Ticket->price : __('Free','dbem'); ?></span>
462
- </td>
463
- <td class="ticket-limit">
464
- <span class="ticket_min">
465
- <?php echo ( !empty($EM_Ticket->min) ) ? $EM_Ticket->min:'-'; ?>
466
- </span> /
467
- <span class="ticket_max"><?php echo ( !empty($EM_Ticket->max) ) ? $EM_Ticket->max:'-'; ?></span>
468
- </td>
469
- <td class="ticket-time">
470
- <span class="ticket_start"><?php echo ( !empty($EM_Ticket->start) ) ? date($localised_date_format, $EM_Ticket->start_timestamp):''; ?></span> -
471
- <span class="ticket_end"><?php echo ( !empty($EM_Ticket->end) ) ? date($localised_date_format, $EM_Ticket->end_timestamp):''; ?></span>
472
- </td>
473
- <td class="ticket-qty">
474
- <span class="ticket_available_spaces"><?php echo $EM_Ticket->get_available_spaces(); ?></span>/
475
- <span class="ticket_spaces">
476
- <?php
477
- if( $EM_Ticket->get_spaces() ){
478
- echo $EM_Ticket->get_spaces();
479
- echo ($EM_Ticket->spaces_limit) ? '':'*';
480
- }else{
481
- echo '-';
482
- }
483
- ?>
484
- </span>
485
- </td>
486
- <td class="ticket-booked-spaces">
487
- <span class="ticket_booked_spaces"><?php echo $EM_Ticket->get_booked_spaces(); ?></span>
488
- </td>
489
- <td class="ticket-actions">
490
- <a href="#" class="ticket-actions-edit"><?php _e('Edit','dbem'); ?></a>
491
- <?php if( count($EM_Ticket->get_bookings()->bookings) == 0 ): ?>
492
- | <a href="<?php bloginfo('wpurl'); ?>/wp-load.php" class="ticket-actions-delete"><?php _e('Delete','dbem'); ?></a>
493
- <?php else: ?>
494
- | <a href="<?php bloginfo('wpurl'); ?>/wp-admin/admin.php?page=events-manager-bookings&ticket_id=<?php echo $EM_Ticket->id ?>"><?php _e('View Bookings','dbem'); ?></a>
495
- <?php endif; ?>
496
-
497
- <input type="hidden" class="ticket_id" name="em_tickets[<?php echo $count; ?>][ticket_id]" value="<?php echo $EM_Ticket->id ?>" />
498
- <input type="hidden" class="ticket_name" name="em_tickets[<?php echo $count; ?>][ticket_name]" value="<?php echo $EM_Ticket->name ?>" />
499
- <input type="hidden" class="ticket_description" name="em_tickets[<?php echo $count; ?>][ticket_description]" value="<?php echo $EM_Ticket->description ?>" />
500
- <input type="hidden" class="ticket_price" name="em_tickets[<?php echo $count; ?>][ticket_price]" value="<?php echo $EM_Ticket->price ?>" />
501
- <input type="hidden" class="ticket_spaces" name="em_tickets[<?php echo $count; ?>][ticket_spaces]" value="<?php echo $EM_Ticket->spaces ?>" />
502
- <input type="hidden" class="ticket_start" name="em_tickets[<?php echo $count; ?>][ticket_start]" value="<?php echo ( !empty($EM_Ticket->start) ) ? date("Y-m-d H:i", $EM_Ticket->start_timestamp):''; ?>" />
503
- <input type="hidden" class="ticket_end" name="em_tickets[<?php echo $count; ?>][ticket_end]" value="<?php echo ( !empty($EM_Ticket->end) ) ? date("Y-m-d H:i", $EM_Ticket->end_timestamp):''; ?>" />
504
- <input type="hidden" class="ticket_min" name="em_tickets[<?php echo $count; ?>][ticket_min]" value="<?php echo $EM_Ticket->min ?>" />
505
- <input type="hidden" class="ticket_max" name="em_tickets[<?php echo $count; ?>][ticket_max]" value="<?php echo $EM_Ticket->max ?>" />
506
- </td>
507
- </tr>
508
- <?php
509
- $count++;
510
- }
511
- }else{
512
- ?>
513
- <tr valign="top" id="em-tickets-row-1" class="em-tickets-row">
514
- <td class="ticket-status"><span class="ticket_off"></span></td>
515
- <td class="ticket-name"><span class="ticket_name">Free Ticket</span><br><span class="ticket_description"></span></td>
516
- <td class="ticket-price"><span class="ticket_price">Free</span></td>
517
- <td class="ticket-limit"><span class="ticket_min">-</span> / <span class="ticket_max">-</span></td>
518
- <td class="ticket-time"><span class="ticket_start"></span> - <span class="ticket_end"></span></td>
519
- <td class="ticket-qty"><span class="ticket_available_spaces">10</span>/<span class="ticket_spaces">10</span></td>
520
- <td class="ticket-booked-spaces"><span class="ticket_booked_spaces">0</span></td>
521
- <td class="ticket-actions">
522
- <a href="#" class="ticket-actions-edit">Edit</a>| <a href="http://wordpress.lan/wp-load.php" class="ticket-actions-delete">Delete</a>
523
- <input type="hidden" class="ticket_id" name="em_tickets[1][ticket_id]" value="">
524
- <input type="hidden" class="ticket_name" name="em_tickets[1][ticket_name]" value="Free Ticket">
525
- <input type="hidden" class="ticket_description" name="em_tickets[1][ticket_description]" value="">
526
- <input type="hidden" class="ticket_price" name="em_tickets[1][ticket_price]" value="">
527
- <input type="hidden" class="ticket_spaces" name="em_tickets[1][ticket_spaces]" value="10">
528
- <input type="hidden" class="ticket_start" name="em_tickets[1][ticket_start]" value="">
529
- <input type="hidden" class="ticket_end" name="em_tickets[1][ticket_end]" value="">
530
- <input type="hidden" class="ticket_min" name="em_tickets[1][ticket_min]" value="">
531
- <input type="hidden" class="ticket_max" name="em_tickets[1][ticket_max]" value="">
532
- </td>
533
- </tr>
534
- <?php
535
- }
536
- ?>
537
- </tbody>
538
- </table>
539
- <table style="display:none; visibility:hidden;">
540
- <tr valign="top" id="em-tickets-template">
541
- <td class="ticket-status"><span class="ticket_new"></span></td>
542
- <td class="ticket-name"><span class="ticket_name"></span><br /><span class="ticket_description"></span></td>
543
- <td class="ticket-price"><span class="ticket_price"></span></td>
544
- <td class="ticket-limit"><span class="ticket_min"></span> / <span class="ticket_max"></span></td>
545
- <td class="ticket-time"><span class="ticket_start"></span> - <span class="ticket_end"></span></td>
546
- <td class="ticket-qty"><span class="ticket_available_spaces">0</span>/<span class="ticket_spaces"></span></td>
547
- <td class="ticket-booked-spaces"><span class="ticket_booked_spaces">0</span></td>
548
- <td class="ticket-actions">
549
- <a href="#" class="ticket-actions-edit"><?php _e('Edit','dbem'); ?></a> | <a href="<?php bloginfo('wpurl'); ?>/wp-load.php" class="ticket-actions-delete"><?php _e('Delete','dbem'); ?></a>
550
- <input type="hidden" class="ticket_id" />
551
- <input type="hidden" class="ticket_name" />
552
- <input type="hidden" class="ticket_description" />
553
- <input type="hidden" class="ticket_price" />
554
- <input type="hidden" class="ticket_spaces" />
555
- <input type="hidden" class="ticket_start" />
556
- <input type="hidden" class="ticket_end" />
557
- <input type="hidden" class="ticket_min" />
558
- <input type="hidden" class="ticket_max" />
559
- </td>
560
- </tr>
561
- </table>
562
- </div>
563
- </div>
564
- </div>
565
- </div>
566
- <?php endif; ?>
567
-
568
- <?php if(get_option('dbem_attributes_enabled')) : ?>
569
- <div id="event_attributes" class="stuffbox">
570
- <h3>
571
- <?php _e ( 'Attributes', 'dbem' ); ?>
572
- </h3>
573
- <div class="inside">
574
- <?php
575
- $attributes = em_get_attributes();
576
- $has_depreciated = false;
577
- ?>
578
- <div class="wrap">
579
- <?php if( count( $attributes ) > 0 ) : ?>
580
- <table class="form-table">
581
- <thead>
582
- <tr valign="top">
583
- <td><strong>Attribute Name</strong></td>
584
- <td><strong>Value</strong></td>
585
- </tr>
586
- </thead>
587
- <tbody id="mtm_body">
588
- <?php
589
- $count = 1;
590
- foreach( $attributes as $name){
591
- ?>
592
- <tr valign="top" id="em_attribute_<?php echo $count ?>">
593
- <td scope="row"><?php echo $name ?></td>
594
- <td>
595
- <input type="text" name="em_attributes[<?php echo $name ?>]" value="<?php echo array_key_exists($name, $EM_Event->attributes) ? htmlspecialchars($EM_Event->attributes[$name], ENT_QUOTES):''; ?>" />
596
- </td>
597
- </tr>
598
- <?php
599
- $count++;
600
- }
601
- if($count == 1){
602
- ?>
603
- <tr><td colspan="2"><?php echo sprintf(__("You don't have any custom attributes defined in any of your Events Manager template settings. Please add them the <a href='%s'>settings page</a>",'dbem'),get_bloginfo('wpurl')."/wp-admin/admin.php?page=events-manager-options"); ?></td></tr>
604
- <?php
605
- }
606
- ?>
607
- </tbody>
608
- </table>
609
- <?php if( count(array_diff(array_keys($EM_Event->attributes), $attributes)) > 0 ): ?>
610
- <p><strong><?php _e('Depreciated Attributes')?></strong></p>
611
- <p><em><?php _e("If you see any attributes under here, that means they're not used in Events Manager anymore. To add them, you need to add the custom attribute again to a formatting option in the settings page. To remove any of these depreciated attributes, give it a blank value and save.") ?></em></p>
612
- <table class="form-table">
613
- <thead>
614
- <tr valign="top">
615
- <td><strong>Attribute Name</strong></td>
616
- <td><strong>Value</strong></td>
617
- </tr>
618
- </thead>
619
- <tbody id="mtm_body">
620
- <?php
621
- if( is_array($EM_Event->attributes) and count($EM_Event->attributes) > 0){
622
- foreach( $EM_Event->attributes as $name => $value){
623
- if( !in_array($name, $attributes) ){
624
- ?>
625
- <tr valign="top" id="em_attribute_<?php echo $count ?>">
626
- <td scope="row"><?php echo $name ?></td>
627
- <td>
628
- <input type="text" name="em_attributes[<?php echo $name ?>]" value="<?php echo htmlspecialchars($value, ENT_QUOTES); ?>" />
629
- </td>
630
- </tr>
631
- <?php
632
- $count++;
633
- }
634
- }
635
- }
636
- ?>
637
- </tbody>
638
- </table>
639
- <?php endif; ?>
640
- <?php else : ?>
641
- <p>
642
- <?php _e('In order to use attributes, you must define some in your templates, otherwise they\'ll never show. Go to Events > Settings to add attribute placeholders.', 'dbem'); ?>
643
- </p>
644
- <script>
645
- jQuery(document).ready(function($){ $('#event_attributes').addClass('closed'); });
646
- </script>
647
- <?php endif; ?>
648
- </div>
649
- </div>
650
- </div>
651
- <?php endif; ?>
652
- </div>
653
- <p class="submit">
654
- <input type="submit" name="events_update" value="<?php _e ( 'Submit Event', 'dbem' ); ?> &raquo;" />
655
- </p>
656
- <input type="hidden" name="p" value="<?php echo ( !empty($_REQUEST['pno']) ) ? $_REQUEST['pno']:''; ?>" /><a>
657
- <input type="hidden" name="scope" value="<?php echo ( !empty($_REQUEST['scope']) ) ? $_REQUEST['scope']:'' ?>" /></a>
658
- <input type="hidden" name="event_id" value="<?php echo $EM_Event->id; ?>" />
659
- <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('wpnonce_event_save'); ?>" />
660
- <input type="hidden" name="action" value="event_save" />
661
- </div>
662
- </div>
663
- </div>
664
- </form>
665
- <div id="em-tickets-form">
666
- <h4><?php _e('Create a ticket', 'dbem'); ?></h4>
667
- <form action="" method="post">
668
- <div><label><?php _e('Name','dbem'); ?></label><input type="text" name="ticket_name" /></div>
669
- <div><label><?php _e('Description','dbem') ?></label><br /><textarea name="ticket_description"></textarea></div>
670
- <div><label><?php _e('Price','dbem') ?></label><input type="text" name="ticket_price" /></div>
671
- <div>
672
- <label><?php _e('Available ticket spaces','dbem') ?></label><input type="text" name="ticket_spaces" /><br />
673
- <em><?php _e('If left blank, spaces are determined by event limit.','dbem'); ?></em>
674
- </div><br />
675
- <div><label><?php _e('Start date of ticket availability','dbem') ?></label><input type="hidden" name="ticket_start" /><input type="text" name="ticket_start_pub" /></div>
676
- <div><label><?php _e('End date of ticket availability','dbem') ?></label><input type="hidden" name="ticket_end" /><input type="text" name="ticket_end_pub" /></div>
677
- <div><label><?php _e('Minimum tickets required per booking','dbem') ?></label><input type="text" name="ticket_min" /></div>
678
- <div><label><?php _e('Maximum tickets required per booking','dbem') ?></label><input type="text" name="ticket_max" /></div>
679
- <p class="submit">
680
- <input type="hidden" name="ticket_id" />
681
- <input type="hidden" name="event_id" />
682
- <input type="hidden" name="prev_slot" />
683
- <input type="submit" value="<?php _e('Add Ticket','dbem'); ?>" />
684
- </p>
685
- </form>
686
- </div>
687
- <script type="text/javascript">
688
- jQuery(document).ready( function($) {
689
- <?php if( $EM_Event->is_recurring() ): ?>
690
- //Recurrence Warnings
691
- $('#event_form').submit( function(event){
692
- confirmation = confirm('<?php _e('Are you sure you want to reschedule this recurring event? If you do this, you will lose all booking information and the old recurring events will be deleted.', 'dbem'); ?>');
693
- if( confirmation == false ){
694
- event.preventDefault();
695
- }
696
- });
697
- <?php endif; ?>
698
- <?php if( get_option('dbem_rsvp_enabled') ): ?>
699
- //RSVP Warning
700
- $('#event-rsvp').click( function(event){
701
- if( !this.checked ){
702
- confirmation = confirm('<?php _e('Are you sure you want to disable bookings? If you do this and save, you will lose all previous bookings. If you wish to prevent further bookings, reduce the number of spaces available to the amount of bookings you currently have', 'dbem'); ?>');
703
- if( confirmation == false ){
704
- event.preventDefault();
705
- }else{
706
- $('#event-tickets').hide();
707
- $("div#rsvp-data").hide();
708
- }
709
- }else{
710
- $('#event-tickets').fadeIn();
711
- $("div#rsvp-data").fadeIn();
712
- }
713
- });
714
-
715
- if($('input#event-rsvp').attr("checked")) {
716
- $("div#rsvp-data").fadeIn();
717
- } else {
718
- $("div#rsvp-data").hide();
719
- }
720
- <?php endif; ?>
721
- });
722
- </script>
723
- <?php
724
- }
725
  ?>
1
+ <?php
2
+ function em_admin_event_actions(){
3
+ if( current_user_can(EM_MIN_CAPABILITY) && !empty($_GET['page']) && $_GET['page'] == 'events-manager-event' && !empty($_REQUEST ['action']) ){
4
+ global $wpdb;
5
+ global $EM_Event;
6
+
7
+ //if dealing with new event, we still want an event object
8
+ if( !is_object($EM_Event) ){
9
+ $EM_Event = new EM_Event();
10
+ }
11
+
12
+ // UPDATE or CREATE action
13
+ if ($_REQUEST['action'] == 'save') {
14
+ $validation = $EM_Event->get_post();
15
+ if ( $validation ) { //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS)
16
+ //Save
17
+ if( $EM_Event->save() ) {
18
+ $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno']:'';
19
+ $scope = !empty($_REQUEST['scope']) ? $_REQUEST['scope']:'';
20
+ wp_redirect( get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager&p='.$page.'&scope='.$scope.'&message='.urlencode($EM_Event->feedback_message));
21
+ }
22
+ }//errors added automatically to event global object
23
+ }
24
+
25
+ //Copy the event
26
+ if ($_REQUEST['action'] == 'duplicate') {
27
+ global $EZSQL_ERROR;
28
+ $EM_Event = $EM_Event->duplicate();
29
+ if( $EM_Event === false ){
30
+ $redirect_url = em_add_get_params($_SERVER['HTTP_REFERER'], array('error' => __('There was an error duplicating the event. Try again maybe?', 'dbem'), 'message'=>''), false);
31
+ wp_redirect($redirect_url);
32
+ }else{
33
+ $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno']:'';
34
+ $scope = !empty($_REQUEST['scope']) ? $_REQUEST['scope']:'';
35
+ wp_redirect( get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager-event&event_id='.$EM_Event->id.'&p='.$page.'&scope='.$scope.'&message='.urlencode($EM_Event->feedback_message));
36
+ }
37
+ }
38
+ }
39
+ }
40
+ add_action('admin_init', 'em_admin_event_actions');
41
+
42
+ /**
43
+ * Generates Event Admin page, for adding and updating a single (or recurring) event.
44
+ * @param $title
45
+ * @return null
46
+ */
47
+ function em_admin_event_page() {
48
+ global $EM_Event, $current_user;
49
+ global $localised_date_formats;
50
+
51
+ //check that user can access this page
52
+ if( is_object($EM_Event) && !$EM_Event->can_manage() ){
53
+ ?>
54
+ <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php _e('You do not have the rights to manage this event.','dbem'); ?></p></div>
55
+ <?php
56
+ return false;
57
+ }
58
+
59
+ if( is_object($EM_Event) && $EM_Event->id > 0 ){
60
+ if($EM_Event->is_recurring()){
61
+ $title = __( "Reschedule", 'dbem' )." '{$EM_Event->name}'";
62
+ }else{
63
+ $title = __ ( "Edit Event", 'dbem' ) . " '" . $EM_Event->name . "'";
64
+ }
65
+ } else {
66
+ $EM_Event = ( is_object($EM_Event) && get_class($EM_Event) == 'EM_Event') ? $EM_Event : new EM_Event();
67
+ $title = __ ( "Insert New Event", 'dbem' );
68
+ //Give a default location & category
69
+ $default_cat = get_option('dbem_default_category');
70
+ $default_loc = get_option('dbem_default_location');
71
+ if( is_numeric($default_cat) && $default_cat > 0 ){
72
+ $EM_Event->category_id = $default_cat;
73
+ $EM_Event->category = new EM_Category($default_cat);
74
+ }
75
+ if( is_numeric($default_loc) && $default_loc > 0 && ( empty($EM_Event->location->id) && empty($EM_Event->location->name) && empty($EM_Event->location->address) && empty($EM_Event->location->town) ) ){
76
+ $EM_Event->location_id = $default_loc;
77
+ $EM_Event->location = new EM_Location($default_loc);
78
+ }
79
+ }
80
+
81
+ $use_select_for_locations = get_option('dbem_use_select_for_locations');
82
+ // change prefix according to event/recurrence
83
+ $pref = "event_";
84
+
85
+ $locale_code = substr ( get_locale (), 0, 2 );
86
+ $localised_date_format = $localised_date_formats[$locale_code];
87
+
88
+ //FIXME time useage is very flimsy imho
89
+ $hours_locale_regexp = "H:i";
90
+ // Setting 12 hours format for those countries using it
91
+ if (preg_match ( "/en|sk|zh|us|uk/", $locale_code ))
92
+ $hours_locale_regexp = "h:iA";
93
+
94
+ $days_names = array (1 => __ ( 'Mon' ), 2 => __ ( 'Tue' ), 3 => __ ( 'Wed' ), 4 => __ ( 'Thu' ), 5 => __ ( 'Fri' ), 6 => __ ( 'Sat' ), 0 => __ ( 'Sun' ) );
95
+ ?>
96
+ <?php if ( count($EM_Event->errors) > 0 || !empty($_GET['error']) ) : ?>
97
+ <div id='message' class='error '>
98
+ <p>
99
+ <?php if( count($EM_Event->errors) ){ ?>
100
+ <strong><?php echo __( "Ach, there's a problem here:", "dbem" ) ?></strong><br /><br />
101
+ <?php echo implode('<br />', $EM_Event->errors); ?>
102
+ <?php } else { echo $_GET['error']; } ?>
103
+ </p>
104
+ </div>
105
+ <?php endif; ?>
106
+ <?php if ( !empty($EM_Event->feedback_message) || !empty($_GET['message']) ) : ?>
107
+ <div id='message' class='updated fade'>
108
+ <p><?php echo !empty($EM_Event->feedback_message) ? $EM_Event->feedback_message : $_GET['message']; ?></p>
109
+ </div>
110
+ <?php endif; ?>
111
+ <form id="event-form" method="post" action="">
112
+ <div class="wrap">
113
+ <div id="icon-events" class="icon32"><br /></div>
114
+ <h2><?php echo $title; ?></h2>
115
+ <?php if ( $EM_Event->is_recurrence() || $EM_Event->is_recurring() ) : ?>
116
+ <p id='recurrence_warning'>
117
+ <?php
118
+ //TODO better warning system when changing a recurring event (e.g. when removing recurrences).
119
+ if ( $EM_Event->is_recurring() ) {
120
+ _e ( 'WARNING: This is a recurring event.', 'dbem' );
121
+ echo "<br />";
122
+ _e ( 'Modifying these data all the events linked to this recurrence will be rescheduled', 'dbem' );
123
+ echo " ";
124
+ _e ( 'and all booking information will be deleted!', 'dbem' );
125
+ } elseif ( $EM_Event->is_recurrence() ) {
126
+ //TODO Terminology confusing with methods, maybe worth changing?
127
+ _e ( 'WARNING: This is a recurrence.', 'dbem' );
128
+ echo "<br />";
129
+ _e ( 'If you change these data and save, this will become an independent event.', 'dbem' );
130
+ }
131
+ ?>
132
+ </p>
133
+ <?php endif; ?>
134
+ <div id="poststuff" class="metabox-holder has-right-sidebar">
135
+ <!-- SIDEBAR -->
136
+ <div id="side-info-column" class='inner-sidebar'>
137
+ <div id='side-sortables'>
138
+ <?php if(get_option('dbem_recurrence_enabled')) : ?>
139
+ <!-- START recurrence postbox -->
140
+ <div class="postbox ">
141
+ <div class="handlediv" title="Fare clic per cambiare."><br />
142
+ </div>
143
+ <h3 class='hndle'><span>
144
+ <?php _e ( "Recurrence", 'dbem' ); ?>
145
+ </span></h3>
146
+ <div class="inside">
147
+ <?php //TODO add js warning if rescheduling, since all bookings are deleted ?>
148
+ <?php if ( !$EM_Event->id || $EM_Event->is_recurring() ) : ?>
149
+ <p>
150
+ <input id="event-recurrence" type="checkbox" name="repeated_event" value="1" <?php echo ( $EM_Event->is_recurring() ) ? 'checked="checked"':'' ; ?> />
151
+ <?php _e ( 'Repeated event', 'dbem' ); ?>
152
+ </p>
153
+ <div id="event_recurrence_pattern">
154
+ <p>
155
+ Frequency:
156
+ <select id="recurrence-frequency" name="recurrence_freq">
157
+ <?php
158
+ $freq_options = array ("daily" => __ ( 'Daily', 'dbem' ), "weekly" => __ ( 'Weekly', 'dbem' ), "monthly" => __ ( 'Monthly', 'dbem' ) );
159
+ em_option_items ( $freq_options, $EM_Event->freq );
160
+ ?>
161
+ </select>
162
+ </p>
163
+ <p>
164
+ <?php _e ( 'Every', 'dbem' )?>
165
+ <input id="recurrence-interval" name='recurrence_interval' size='2' value='<?php echo $EM_Event->interval ; ?>' />
166
+ <span class='interval-desc' id="interval-daily-singular">
167
+ <?php _e ( 'day', 'dbem' )?>
168
+ </span> <span class='interval-desc' id="interval-daily-plural">
169
+ <?php _e ( 'days', 'dbem' ) ?>
170
+ </span> <span class='interval-desc' id="interval-weekly-singular">
171
+ <?php _e ( 'week', 'dbem' )?>
172
+ </span> <span class='interval-desc' id="interval-weekly-plural">
173
+ <?php _e ( 'weeks', 'dbem' )?>
174
+ </span> <span class='interval-desc' id="interval-monthly-singular">
175
+ <?php _e ( 'month', 'dbem' )?>
176
+ </span> <span class='interval-desc' id="interval-monthly-plural">
177
+ <?php _e ( 'months', 'dbem' )?>
178
+ </span>
179
+ </p>
180
+ <p class="alternate-selector" id="weekly-selector">
181
+ <?php
182
+ $saved_bydays = ($EM_Event->is_recurring()) ? explode ( ",", $EM_Event->byday ) : array();
183
+ em_checkbox_items ( 'recurrence_bydays[]', $days_names, $saved_bydays );
184
+ ?>
185
+ </p>
186
+ <p class="alternate-selector" id="monthly-selector">
187
+ <?php _e ( 'Every', 'dbem' )?>
188
+ <select id="monthly-modifier" name="recurrence_byweekno">
189
+ <?php
190
+ $weekno_options = array ("1" => __ ( 'first', 'dbem' ), '2' => __ ( 'second', 'dbem' ), '3' => __ ( 'third', 'dbem' ), '4' => __ ( 'fourth', 'dbem' ), '-1' => __ ( 'last', 'dbem' ) );
191
+ em_option_items ( $weekno_options, $EM_Event->byweekno );
192
+ ?>
193
+ </select>
194
+ <select id="recurrence-weekday" name="recurrence_byday">
195
+ <?php em_option_items ( $days_names, $EM_Event->byday ); ?>
196
+ </select>
197
+ &nbsp;
198
+ </p>
199
+ </div>
200
+ <p id="recurrence-tip">
201
+ <?php _e ( 'Check if your event happens more than once according to a regular pattern', 'dbem' )?>
202
+ </p>
203
+ <?php elseif( $EM_Event->is_recurrence() ) : ?>
204
+ <p>
205
+ <?php echo $EM_Event->get_recurrence_description(); ?>
206
+ <br />
207
+ <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&amp;event_id=<?php echo $EM_Event->recurrence_id; ?>">
208
+ <?php _e ( 'Reschedule', 'dbem' ); ?>
209
+ </a>
210
+ <input type="hidden" name="recurrence_id" value="<?php echo $EM_Event->recurrence_id; ?>" />
211
+ </p>
212
+ <?php else : ?>
213
+ <p><?php _e ( 'This is\'t a recurrent event', 'dbem' ) ?></p>
214
+ <?php endif; ?>
215
+ </div>
216
+ </div>
217
+ <!-- END recurrence postbox -->
218
+ <?php endif; ?>
219
+ <?php if(get_option('dbem_rsvp_enabled')) : ?>
220
+ <!-- START RSVP -->
221
+ <?php if ( em_verify_admin() ): ?>
222
+ <div class="postbox ">
223
+ <div class="handlediv" title="Fare clic per cambiare."><br />
224
+ </div>
225
+ <h3 class='hndle'><span>
226
+ <?php _e ( 'Contact Person', 'dbem' ); ?>
227
+ </span></h3>
228
+ <div class="inside">
229
+ <p><?php _e('Contact','dbem'); ?>
230
+ <?php
231
+ wp_dropdown_users ( array ('name' => 'event_contactperson_id', 'show_option_none' => __ ( "Select...", 'dbem' ), 'selected' => $EM_Event->contactperson_id ) );
232
+ ?>
233
+ </p>
234
+ </div>
235
+ </div>
236
+ <?php else: ?>
237
+ <input type="hidden" name="event_contactperson_id" value="<?php get_current_user_id() ?>" />
238
+ <?php endif; ?>
239
+ <div class="postbox ">
240
+ <div class="handlediv" title="Fare clic per cambiare."><br />
241
+ </div>
242
+ <h3 class='hndle'><span><?php _e('RSVP','dbem'); ?></span></h3>
243
+ <div class="inside">
244
+ <p>
245
+ <input id="rsvp-checkbox" name='event_rsvp' value='1' type='checkbox' <?php echo ($EM_Event->rsvp) ? 'checked="checked"' : ''; ?> />
246
+ <?php _e ( 'Enable registration for this event', 'dbem' )?>
247
+ </p>
248
+ <div id='rsvp-data'>
249
+ <?php
250
+ if ($EM_Event->contactperson_id != NULL){
251
+ $selected = $EM_Event->contactperson_id;
252
+ }else{
253
+ $selected = '0';
254
+ }
255
+ ?>
256
+ <p>
257
+ <?php _e ( 'Spaces','dbem' ); ?> :
258
+ <input id="seats-input" type="text" name="event_seats" size='5' value="<?php echo $EM_Event->seats ?>" />
259
+ </p>
260
+ <!-- START RSVP Stats -->
261
+ <?php
262
+ if ($EM_Event->rsvp ) {
263
+ $available_seats = $EM_Event->get_bookings()->get_available_seats();
264
+ $booked_seats = $EM_Event->get_bookings()->get_booked_seats();
265
+
266
+ if ( count($EM_Event->get_bookings()->bookings) > 0 ) {
267
+ ?>
268
+ <div class='wrap'>
269
+ <p><strong><?php echo __('Available Spaces','dbem').': '.$EM_Event->get_bookings()->get_available_seats(); ?></strong></p>
270
+ <p><strong><?php echo __('Confirmed Spaces','dbem').': '.$EM_Event->get_bookings()->get_booked_seats(); ?></strong></p>
271
+ <p><strong><?php echo __('Pending Spaces','dbem').': '.$EM_Event->get_bookings()->get_pending_seats(); ?></strong></p>
272
+ </div>
273
+
274
+ <br class='clear'/>
275
+
276
+ <div id='major-publishing-actions'>
277
+ <div id='publishing-action'>
278
+ <a id='printable' href='<?php echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&event_id=".$EM_Event->id ?>'><?php _e('manage bookings','dbem')?></a><br />
279
+ <a target='_blank' href='<?php echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&action=bookings_report&event_id=".$EM_Event->id ?>'><?php _e('printable view','dbem')?></a>
280
+ <a href='<?php echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&action=export_csv&event_id=".$EM_Event->id ?>'><?php _e('export csv','dbem')?></a>
281
+ <br class='clear'/>
282
+ </div>
283
+ <br class='clear'/>
284
+ </div>
285
+ <?php
286
+ } else {
287
+ ?>
288
+ <p><em><?php _e('No responses yet!')?></em></p>
289
+ <?php
290
+ }
291
+ }
292
+ ?>
293
+ <!-- END RSVP Stats -->
294
+ </div>
295
+ </div>
296
+ </div>
297
+ <!-- END RSVP -->
298
+ <?php endif; ?>
299
+ <?php if(get_option('dbem_categories_enabled')) :?>
300
+ <!-- START Categories -->
301
+ <div class="postbox ">
302
+ <div class="handlediv" title="Fare clic per cambiare."><br />
303
+ </div>
304
+ <h3 class='hndle'><span>
305
+ <?php _e ( 'Category', 'dbem' ); ?>
306
+ </span></h3>
307
+ <div class="inside">
308
+ <?php $categories = EM_Categories::get(array('orderby'=>'category_name')); ?>
309
+ <?php if( count($categories) > 0 ): ?>
310
+ <p><?php _e ( 'Category:', 'dbem' ); ?>
311
+ <select name="event_category_id">
312
+ <option value="" <?php echo ($EM_Event->category_id == '') ? "selected='selected'":'' ?>><?php _e('no category','dbem') ?></option>
313
+ <?php
314
+ foreach ( $categories as $EM_Category ){
315
+ $selected = ($EM_Category->id == $EM_Event->category_id) ? "selected='selected'": '';
316
+ ?>
317
+ <option value="<?php echo $EM_Category->id ?>" <?php echo $selected ?>>
318
+ <?php echo $EM_Category->name ?>
319
+ </option>
320
+ <?php
321
+ }
322
+ ?>
323
+ </select>
324
+ </p>
325
+ <?php else: ?>
326
+ <p><?php sprintf(__('No categories available, <a href="%s">create one here first</a>','dbem'), get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager-categories'); ?></p>
327
+ <?php endif; ?>
328
+ </div>
329
+ </div>
330
+ <!-- END Categories -->
331
+ <?php endif; ?>
332
+ </div>
333
+ </div>
334
+ <!-- END OF SIDEBAR -->
335
+ <div id="post-body">
336
+ <div id="post-body-content">
337
+ <div id="event_name" class="stuffbox">
338
+ <h3>
339
+ <?php _e ( 'Name', 'dbem' ); ?>
340
+ </h3>
341
+ <div class="inside">
342
+ <input type="text" name="event_name" id="event-name" value="<?php echo htmlspecialchars($EM_Event->name,ENT_QUOTES); ?>" />
343
+ <br />
344
+ <?php _e ( 'The event name. Example: Birthday party', 'dbem' )?>
345
+ </div>
346
+ </div>
347
+ <div id="event_start_date" class="stuffbox">
348
+ <h3 id='event-date-title'>
349
+ <?php _e ( 'Event date', 'dbem' ); ?>
350
+ </h3>
351
+ <h3 id='recurrence-dates-title'>
352
+ <?php _e ( 'Recurrence dates', 'dbem' ); ?>
353
+ </h3>
354
+ <div class="inside">
355
+ <input id="localised-date" type="text" name="localised_event_date" style="display: none;" />
356
+ <input id="date-to-submit" type="text" name="event_start_date" value="<?php echo $EM_Event->start_date ?>" style="background: #FCFFAA" />
357
+ <input id="localised-end-date" type="text" name="localised_event_end_date" style="display: none;" />
358
+ <input id="end-date-to-submit" type="text" name="event_end_date" value="<?php echo $EM_Event->end_date ?>" style="background: #FCFFAA" />
359
+ <br />
360
+ <span id='event-date-explanation'>
361
+ <?php
362
+ _e ( 'The event date.', 'dbem' );
363
+ /* Marcus Begin Edit */
364
+ echo " ";
365
+ _e ( 'When not reoccurring, this event spans between the beginning and end date.', 'dbem' );
366
+ /* Marcus End Edit */
367
+ ?>
368
+ </span>
369
+ <span id='recurrence-dates-explanation'>
370
+ <?php _e ( 'The recurrence beginning and end date.', 'dbem' ); ?>
371
+ </span>
372
+ </div>
373
+ </div>
374
+ <div id="event_end_day" class="stuffbox">
375
+ <h3>
376
+ <?php _e ( 'Event time', 'dbem' ); ?>
377
+ </h3>
378
+ <div class="inside">
379
+ <input id="start-time" type="text" size="8" maxlength="8" name="event_start_time" value="<?php echo date( $hours_locale_regexp, strtotime($EM_Event->start_time) ); ?>" />
380
+ -
381
+ <input id="end-time" type="text" size="8" maxlength="8" name="event_end_time" value="<?php echo date( $hours_locale_regexp, strtotime($EM_Event->end_time) ); ?>" />
382
+ <br />
383
+ <?php _e ( 'The time of the event beginning and end', 'dbem' )?>.
384
+ </div>
385
+ </div>
386
+ <div id="location_coordinates" class="stuffbox" style='display: none;'>
387
+ <h3>
388
+ <?php _e ( 'Coordinates', 'dbem' ); ?>
389
+ </h3>
390
+ <div class="inside">
391
+ <input id='location-latitude' name='location_latitude' type='text' value='<?php echo $EM_Event->latitude; ?>' size='15' />
392
+ -
393
+ <input id='location-longitude' name='location_longitude' type='text' value='<?php echo $EM_Event->longitude; ?>' size='15' />
394
+ </div>
395
+ </div>
396
+ <div id="location_info" class="stuffbox">
397
+ <h3>
398
+ <?php _e ( 'Location', 'dbem' ); ?>
399
+ </h3>
400
+ <div class="inside">
401
+ <table id="dbem-location-data">
402
+ <tr>
403
+ <td style="padding-right:20px">
404
+ <table>
405
+ <?php if($use_select_for_locations) : ?>
406
+ <tr>
407
+ <th><?php _e('Location:','dbem') ?></th>
408
+ <td>
409
+ <select name="location-select-id" id='location-select-id' size="1">
410
+ <?php
411
+ $locations = EM_Locations::get();
412
+ foreach($locations as $location) {
413
+ $selected = "";
414
+ if( is_object($EM_Event->location) ) {
415
+ if ($EM_Event->location->id == $location->id)
416
+ $selected = "selected='selected' ";
417
+ }
418
+ ?>
419
+ <option value="<?php echo $location->id ?>" title="<?php echo "{$location->latitude},{$location->longitude}" ?>" <?php echo $selected ?>><?php echo $location->name; ?></option>
420
+ <?php
421
+ }
422
+ ?>
423
+ </select>
424
+ <p><?php _e ( 'The name of the location where the event takes place. You can use the name of a venue, a square, etc', 'dbem' )?></p>
425
+ </td>
426
+ </tr>
427
+ <?php else : ?>
428
+ <tr>
429
+ <th><?php _e ( 'Name:' )?></th>
430
+ <td>
431
+ <input id="location-name" type="text" name="location_name" value="<?php echo htmlspecialchars($EM_Event->location->name, ENT_QUOTES); ?>" />
432
+ <p><?php _e ( 'Select a location for your event', 'dbem' )?></p>
433
+ </td>
434
+ </tr>
435
+ <tr>
436
+ <th><?php _e ( 'Address:' )?>&nbsp;</th>
437
+ <td>
438
+ <input id="location-address" type="text" name="location_address" value="<?php echo htmlspecialchars($EM_Event->location->address, ENT_QUOTES); ; ?>" />
439
+ <p><?php _e ( 'The address of the location where the event takes place. Example: 21, Dominick Street', 'dbem' )?></p>
440
+ </td>
441
+ </tr>
442
+ <tr>
443
+ <th><?php _e ( 'Town:' )?>&nbsp;</th>
444
+ <td>
445
+ <input id="location-town" type="text" name="location_town" value="<?php echo htmlspecialchars($EM_Event->location->town, ENT_QUOTES); ?>" />
446
+ <p><?php _e ( 'The town where the location is located. If you\'re using the Google Map integration and want to avoid geotagging ambiguities include the country in the town field. Example: Verona, Italy.', 'dbem' )?></p>
447
+ </td>
448
+ </tr>
449
+ <?php endif; ?>
450
+ </table>
451
+ </td>
452
+ <?php if ( get_option ( 'dbem_gmap_is_active' ) ) : ?>
453
+ <td width="400">
454
+ <div id='em-map-404' style='width: 400px; vertical-align:middle; text-align: center;'>
455
+ <p><em><?php _e ( 'Location not found', 'dbem' ); ?></em></p>
456
+ </div>
457
+ <div id='em-map' style='width: 400px; height: 300px; display: none;'></div>
458
+ </td>
459
+ <?php endif; ?>
460
+ </tr>
461
+ </table>
462
+ </div>
463
+ </div>
464
+ <div id="event_notes" class="postbox">
465
+ <h3>
466
+ <?php _e ( 'Details', 'dbem' ); ?>
467
+ </h3>
468
+ <div class="inside">
469
+ <div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
470
+ <?php the_editor($EM_Event->notes ); ?>
471
+ </div>
472
+ <br />
473
+ <?php _e ( 'Details about the event', 'dbem' )?>
474
+ </div>
475
+ </div>
476
+
477
+ <?php if(get_option('dbem_attributes_enabled')) : ?>
478
+ <div id="event_attributes" class="postbox">
479
+ <h3>
480
+ <?php _e ( 'Attributes', 'dbem' ); ?>
481
+ </h3>
482
+ <div class="inside">
483
+ <?php
484
+ //We also get a list of attribute names and create a ddm list (since placeholders are fixed)
485
+ $formats =
486
+ get_option ( 'dbem_event_list_item_format' ).
487
+ get_option ( 'dbem_event_page_title_format' ).
488
+ get_option ( 'dbem_full_calendar_event_format' ).
489
+ get_option ( 'dbem_location_baloon_format' ).
490
+ get_option ( 'dbem_location_event_list_item_format' ).
491
+ get_option ( 'dbem_location_page_title_format' ).
492
+ get_option ( 'dbem_map_text_format' ).
493
+ get_option ( 'dbem_rss_description_format' ).
494
+ get_option ( 'dbem_rss_title_format' ).
495
+ get_option ( 'dbem_single_event_format' ).
496
+ get_option ( 'dbem_single_location_format' ).
497
+ get_option ( 'dbem_placeholders_custom' );
498
+ //We now have one long string of formats, get all the attribute placeholders
499
+ preg_match_all('/#_ATT\{.+?\}(\{.+?\})?/', $formats, $placeholders);
500
+ //Now grab all the unique attributes we can use in our event.
501
+ $attributes = array();
502
+ foreach($placeholders[0] as $result) {
503
+ $attribute = substr( substr($result, 0, strpos($result, '}')), 6 );
504
+ if( !in_array($attribute, $attributes) ){
505
+ $attributes[] = $attribute ;
506
+ }
507
+ }
508
+ ?>
509
+ <div class="wrap">
510
+ <?php if( count( $attributes ) > 0 ) : ?>
511
+ <h2>Attributes</h2>
512
+ <p>Add attributes here</p>
513
+ <table class="form-table">
514
+ <thead>
515
+ <tr valign="top">
516
+ <td><strong>Attribute Name</strong></td>
517
+ <td><strong>Value</strong></td>
518
+ </tr>
519
+ </thead>
520
+ <tfoot>
521
+ <tr valign="top">
522
+ <td colspan="3"><a href="#" id="mtm_add_tag">Add new tag</a></td>
523
+ </tr>
524
+ </tfoot>
525
+ <tbody id="mtm_body">
526
+ <?php
527
+ $count = 1;
528
+ if( is_array($EM_Event->attributes) and count($EM_Event->attributes) > 0){
529
+ foreach( $EM_Event->attributes as $name => $value){
530
+ ?>
531
+ <tr valign="top" id="mtm_<?php echo $count ?>">
532
+ <td scope="row">
533
+ <select name="mtm_<?php echo $count ?>_ref">
534
+ <?php
535
+ if( !in_array($name, $attributes) ){
536
+ echo "<option value='$name'>$name (".__('Not defined in templates', 'dbem').")</option>";
537
+ }
538
+ foreach( $attributes as $attribute ){
539
+ if( $attribute == $name ) {
540
+ echo "<option selected='selected'>$attribute</option>";
541
+ }else{
542
+ echo "<option>$attribute</option>";
543
+ }
544
+ }
545
+ ?>
546
+ </select>
547
+ <a href="#" rel="<?php echo $count ?>">Remove</a>
548
+ </td>
549
+ <td>
550
+ <input type="text" name="mtm_<?php echo $count ?>_name" value="<?php echo htmlspecialchars($value, ENT_QUOTES); ?>" />
551
+ </td>
552
+ </tr>
553
+ <?php
554
+ $count++;
555
+ }
556
+ }else{
557
+ ?>
558
+ <tr valign="top" id="mtm_<?php echo $count ?>">
559
+ <td scope="row">
560
+ <select name="mtm_<?php echo $count ?>_ref">
561
+ <?php
562
+ foreach( $attributes as $attribute ){
563
+ echo "<option>$attribute</option>";
564
+ }
565
+ ?>
566
+ </select>
567
+ <a href="#" rel="<?php echo $count ?>">Remove</a>
568
+ </td>
569
+ <td>
570
+ <input type="text" name="mtm_<?php echo $count ?>_name" />
571
+ </td>
572
+ </tr>
573
+ <?php
574
+ }
575
+ ?>
576
+ </tbody>
577
+ </table>
578
+ <?php else : ?>
579
+ <p>
580
+ <?php _e('In order to use attributes, you must define some in your templates, otherwise they\'ll never show. Go to Events > Settings to add attribute placeholders.', 'dbem'); ?>
581
+ </p>
582
+ <script>
583
+ jQuery(document).ready(function($){ $('#event_attributes').addClass('closed'); });
584
+ </script>
585
+ <?php endif; ?>
586
+ </div>
587
+ </div>
588
+ </div>
589
+ <?php endif; ?>
590
+ </div>
591
+ <p class="submit">
592
+ <input type="submit" name="events_update" value="<?php _e ( 'Submit Event', 'dbem' ); ?> &raquo;" />
593
+ </p>
594
+ <input type="hidden" name="p" value="<?php echo ( !empty($_REQUEST['pno']) ) ? $_REQUEST['pno']:''; ?>" /><a>
595
+ <input type="hidden" name="scope" value="<?php echo ( !empty($_REQUEST['scope']) ) ? $_REQUEST['scope']:'' ?>" /></a>
596
+ <input type="hidden" name="action" value="save" />
597
+ </div>
598
+ </div>
599
+ </div>
600
+ </form>
601
+ <script type="text/javascript">
602
+ jQuery(document).ready( function($) {
603
+ <?php if( $EM_Event->is_recurring() ): ?>
604
+ //Recurrence Warnings
605
+ $('#event_form').submit( function(event){
606
+ confirmation = confirm('<?php _e('Are you sure you want to reschedule this recurring event? If you do this, you will lose all booking information and the old recurring events will be deleted.', 'dbem'); ?>');
607
+ if( confirmation == false ){
608
+ event.preventDefault();
609
+ }
610
+ });
611
+ <?php endif; ?>
612
+ <?php if( $EM_Event->rsvp == 1 ): ?>
613
+ //RSVP Warning
614
+ $('#rsvp-checkbox').click( function(event){
615
+ if( !this.checked ){
616
+ confirmation = confirm('<?php _e('Are you sure you want to disable bookings? If you do this and save, you will lose all previous bookings. If you wish to prevent further bookings, reduce the number of seats available to the amount of bookings you currently have', 'dbem'); ?>');
617
+ if( confirmation == false ){
618
+ event.preventDefault();
619
+ }
620
+ }
621
+ });
622
+ <?php endif; ?>
623
+ });
624
+ </script>
625
+ <?php
626
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
627
  ?>
admin/em-events.php CHANGED
@@ -1,244 +1,242 @@
1
- <?php
2
-
3
- /**
4
- * Determines whether to show event page or events page, and saves any updates to the event or events
5
- * @return null
6
- */
7
- function em_admin_events_page() {
8
- //TODO Simplify panel for events, use form flags to detect certain actions (e.g. submitted, etc)
9
- global $wpdb, $EM_Notices, $EM_Event;
10
-
11
- $action = ( !empty($_REQUEST ['action']) ) ? $_REQUEST ['action']:'';
12
- $order = ( !empty($_REQUEST ['order']) ) ? $_REQUEST ['order']:'ASC';
13
- $limit = ( !empty($_REQUEST['limit']) ) ? $_REQUEST['limit'] : 20;//Default limit
14
- $page = ( !empty($_REQUEST['pno']) ) ? $_REQUEST['pno']:1;
15
- $offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
16
- $search = ( !empty($_REQUEST['em_search']) ) ? $_REQUEST['em_search']:'';
17
- $scope_names = array (
18
- 'past' => __ ( 'Past events', 'dbem' ),
19
- 'all' => __ ( 'All events', 'dbem' ),
20
- 'future' => __ ( 'Future events', 'dbem' )
21
- );
22
- $scope = ( !empty($_REQUEST ['scope']) && array_key_exists($_REQUEST ['scope'], $scope_names) ) ? $_REQUEST ['scope']:'future';
23
- $selectedEvents = ( !empty($_REQUEST ['events']) ) ? $_REQUEST ['events']:'';
24
-
25
- $args = array('scope'=>$scope, 'limit'=>0, 'order'=>$order, 'search'=>$search );
26
-
27
- if( !current_user_can('edit_others_events') ){
28
- $args['owner'] = get_current_user_id();
29
- }
30
- //Figure out what status to search for
31
- $args['status'] = ( isset($_REQUEST['status']) && is_numeric($_REQUEST['status']) ) ? $_REQUEST['status'] : false;
32
-
33
- $events = EM_Events::get( $args );
34
- $events_count = count ( $events );
35
- $pending_count = EM_Events::count( array('status'=>0) );
36
- $approved_count = EM_Events::count( array('status'=> 1) );
37
- $total_count = EM_Events::count( array('status'=> false) );
38
-
39
- $use_events_end = get_option('dbem_use_event_end');
40
- echo $EM_Notices;
41
- ?>
42
- <div class="wrap">
43
- <div id="icon-events" class="icon32"><br />
44
- </div>
45
- <h2>
46
- <?php echo $scope_names[$scope]; ?>
47
- <a href="admin.php?page=events-manager-event" class="button add-new-h2"><?php _e('Add New','dbem'); ?></a>
48
- </h2>
49
- <?php
50
- $link = array ();
51
- $link ['past'] = "<a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&amp;scope=past&amp;order=desc'>" . __ ( 'Past events', 'dbem' ) . "</a>";
52
- $link ['all'] = " <a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&amp;scope=all&amp;order=desc'>" . __ ( 'All events', 'dbem' ) . "</a>";
53
- $link ['future'] = " <a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&amp;scope=future'>" . __ ( 'Future events', 'dbem' ) . "</a>";
54
- ?>
55
- <?php if ( !empty($_REQUEST['error']) ) : ?>
56
- <div id='message' class='error'>
57
- <p><?php echo $_REQUEST['error']; ?></p>
58
- </div>
59
- <?php endif; ?>
60
- <?php if ( !empty($_REQUEST['message']) ) : ?>
61
- <div id='message' class='updated fade'>
62
- <p><?php echo $_REQUEST['message']; ?></p>
63
- </div>
64
- <?php endif; ?>
65
- <form id="posts-filter" action="" method="get"><input type='hidden' name='page' value='events-manager' />
66
- <ul class="subsubsub">
67
- <li><a href='<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager' <?php echo ( !isset($_REQUEST['status']) ) ? 'class="current"':''; ?>><?php _e ( 'Total', 'dbem' ); ?> <span class="count">(<?php echo $total_count; ?>)</span></a></li>
68
- <?php if( current_user_can('publish_events') ): ?>
69
- <li>| <a href='<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&amp;status=1' <?php echo ( isset($_REQUEST['status']) && $_REQUEST['status']=='1' ) ? 'class="current"':''; ?>><?php _e ( 'Approved', 'dbem' ); ?> <span class="count">(<?php echo $approved_count; ?>)</span></a></li>
70
- <li>| <a href='<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&amp;status=0' <?php echo ( isset($_REQUEST['status']) && $_REQUEST['status']=='0' ) ? 'class="current"':''; ?>><?php _e ( 'Pending', 'dbem' ); ?> <span class="count">(<?php echo $pending_count; ?>)</span></a></li>
71
- <?php endif; ?>
72
- </ul>
73
- <p class="search-box">
74
- <label class="screen-reader-text" for="post-search-input"><?php _e('Search Events','dbem'); ?>:</label>
75
- <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_REQUEST['em_search'])) ? $_REQUEST['em_search']:''; ?>" />
76
- <input type="submit" value="<?php _e('Search Events','dbem'); ?>" class="button" />
77
- </p>
78
- <div class="tablenav">
79
-
80
- <div class="alignleft actions">
81
- <select name="action">
82
- <option value="-1" selected="selected"><?php _e ( 'Bulk Actions' ); ?></option>
83
- <option value="event_delete"><?php _e ( 'Delete selected','dbem' ); ?></option>
84
- </select>
85
- <input type="submit" value="<?php _e ( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
86
- <select name="scope">
87
- <?php
88
- foreach ( $scope_names as $key => $value ) {
89
- $selected = "";
90
- if ($key == $scope)
91
- $selected = "selected='selected'";
92
- echo "<option value='$key' $selected>$value</option> ";
93
- }
94
- ?>
95
- </select>
96
- <input id="post-query-submit" class="button-secondary" type="submit" value="<?php _e ( 'Filter' )?>" />
97
- </div>
98
- <!--
99
- <div class="view-switch">
100
- <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
101
- </div>
102
- -->
103
- <?php
104
- if ( $events_count >= $limit ) {
105
- $events_nav = em_admin_paginate( $events_count, $limit, $page);
106
- echo $events_nav;
107
- }
108
- ?>
109
- <br class="clear" />
110
- </div>
111
-
112
- <?php
113
- if (empty ( $events )) {
114
- // TODO localize
115
- _e ( 'no events','dbem' );
116
- } else {
117
- ?>
118
-
119
- <table class="widefat events-table">
120
- <thead>
121
- <tr>
122
- <th class='manage-column column-cb check-column' scope='col'>
123
- <input class='select-all' type="checkbox" value='1' />
124
- </th>
125
- <th><?php _e ( 'Name', 'dbem' ); ?></th>
126
- <th>&nbsp;</th>
127
- <th><?php _e ( 'Location', 'dbem' ); ?></th>
128
- <th colspan="2"><?php _e ( 'Date and time', 'dbem' ); ?></th>
129
- </tr>
130
- </thead>
131
- <tbody>
132
- <?php
133
- $rowno = 0;
134
- $event_count = 0;
135
- foreach ( $events as $event ) {
136
- /* @var $event EM_Event */
137
- if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
138
- $rowno++;
139
- $class = ($rowno % 2) ? 'alternate' : '';
140
- // FIXME set to american
141
- $localised_start_date = date_i18n('D d M Y', $event->start);
142
- $localised_end_date = date_i18n('D d M Y', $event->end);
143
- $style = "";
144
- $today = date ( "Y-m-d" );
145
- $location_summary = "<b>" . $event->location->name . "</b><br/>" . $event->location->address . " - " . $event->location->town;
146
- $category = new EM_Category($event->category_id);
147
-
148
- if ($event->start_date < $today && $event->end_date < $today){
149
- $class .= " past";
150
- }
151
- //Check pending approval events
152
- if ( !$event->status ){
153
- $class .= " pending";
154
- }
155
- ?>
156
- <tr class="event <?php echo trim($class); ?>" <?php echo $style; ?> id="event_<?php echo $event->id ?>">
157
- <td>
158
- <input type='checkbox' class='row-selector' value='<?php echo $event->id; ?>' name='events[]' />
159
- </td>
160
- <td>
161
- <strong>
162
- <a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&amp;event_id=<?php echo $event->id ?>&amp;scope=<?php echo $scope ?>&amp;pno=<?php echo $page ?>"><?php echo ($event->name); ?></a>
163
- </strong>
164
- <?php
165
- if( get_option('dbem_rsvp_enabled') == 1 && $event->rsvp == 1 ){
166
- ?>
167
- <br/>
168
- <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php echo $event->id ?>"><?php echo __("Bookings",'dbem'); ?></a> &ndash;
169
- <?php _e("Booked",'dbem'); ?>: <?php echo $event->get_bookings()->get_booked_spaces()."/".$event->get_spaces(); ?>
170
- <?php if( get_option('dbem_bookings_approval') == 1 ): ?>
171
- | <?php _e("Pending",'dbem') ?>: <?php echo $event->get_bookings()->get_pending_spaces(); ?>
172
- <?php endif;
173
- }
174
- ?>
175
- <div class="row-actions">
176
- <span class="trash"><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&amp;action=event_delete&amp;event_id=<?php echo $event->id ?>&amp;scope=<?php echo $scope ?>&amp;pno=<?php echo $page ?>" class="em-event-delete"><?php _e('Delete','dbem'); ?></a></span>
177
- <?php if( !$event->status && $event->can_manage('publish_events','publish_others_events') ): ?>
178
- | <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&amp;action=event_approve&amp;event_id=<?php echo $event->id ?>&amp;scope=<?php echo $scope ?>&amp;pno=<?php echo $page ?>" class="em-event-approve" style="color:green"><?php _e('Approve','dbem'); ?></a>
179
- <?php endif; ?>
180
- </div>
181
- </td>
182
- <td>
183
- <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&amp;action=event_duplicate&amp;event_id=<?php echo $event->id; ?>&amp;scope=<?php echo $scope ?>&amp;pno=<?php echo $page ?>" title="<?php _e ( 'Duplicate this event', 'dbem' ); ?>">
184
- <strong>+</strong>
185
- </a>
186
- </td>
187
- <td>
188
- <?php echo $location_summary; ?>
189
- <?php if( is_object($category) && !empty($category->name) ) : ?>
190
- <br/><span class="category"><strong><?php _e( 'Category', 'dbem' ); ?>: </strong><?php echo $category->name ?></span>
191
- <?php endif; ?>
192
- </td>
193
-
194
- <td>
195
- <?php echo $localised_start_date; ?>
196
- <?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
197
- <br />
198
- <?php
199
- //TODO Should 00:00 - 00:00 be treated as an all day event?
200
- echo substr ( $event->start_time, 0, 5 ) . " - " . substr ( $event->end_time, 0, 5 );
201
- ?>
202
- </td>
203
- <td>
204
- <?php
205
- if ( $event->is_recurrence() ) {
206
- ?>
207
- <strong>
208
- <?php echo $event->get_recurrence_description(); ?> <br />
209
- <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&amp;event_id=<?php echo $event->recurrence_id ?>&amp;scope=<?php echo $scope ?>&amp;pno=<?php echo $page ?>"><?php _e ( 'Reschedule', 'dbem' ); ?></a>
210
- </strong>
211
- <?php
212
- }
213
- ?>
214
- </td>
215
- </tr>
216
- <?php
217
- }
218
- $event_count++;
219
- }
220
- ?>
221
- </tbody>
222
- </table>
223
- <?php
224
- } // end of table
225
- ?>
226
- <div class='tablenav'>
227
- <div class="alignleft actions">
228
- <br class='clear' />
229
- </div>
230
- <?php if ( $events_count >= $limit ) : ?>
231
- <div class="tablenav-pages">
232
- <?php
233
- echo $events_nav;
234
- ?>
235
- </div>
236
- <?php endif; ?>
237
- <br class='clear' />
238
- </div>
239
- </form>
240
- </div>
241
- <?php
242
- }
243
-
244
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Determines whether to show event page or events page, and saves any updates to the event or events
5
+ * @return null
6
+ */
7
+ function em_admin_events_page() {
8
+ //TODO Simplify panel for events, use form flags to detect certain actions (e.g. submitted, etc)
9
+ global $wpdb;
10
+ global $EM_Event;
11
+ $action = ( !empty($_GET ['action']) ) ? $_GET ['action']:'';
12
+ $order = ( !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
13
+ $limit = ( !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
14
+ $page = ( !empty($_GET['pno']) ) ? $_GET['pno']:1;
15
+ $offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
16
+ $scope_names = array (
17
+ 'past' => __ ( 'Past events', 'dbem' ),
18
+ 'all' => __ ( 'All events', 'dbem' ),
19
+ 'future' => __ ( 'Future events', 'dbem' )
20
+ );
21
+ $scope = ( !empty($_GET ['scope']) && array_key_exists($_GET ['scope'], $scope_names) ) ? $_GET ['scope']:'future';
22
+ $selectedEvents = ( !empty($_GET ['events']) ) ? $_GET ['events']:'';
23
+
24
+ // DELETE action
25
+ if ( $action == 'deleteEvents' && EM_Object::array_is_numeric($selectedEvents) ) {
26
+ EM_Events::delete( $selectedEvents );
27
+ }
28
+
29
+ // No action, only showing the events list
30
+ switch ($scope) {
31
+ case "past" :
32
+ $title = __ ( 'Past Events', 'dbem' );
33
+ break;
34
+ case "all" :
35
+ $title = __ ( 'All Events', 'dbem' );
36
+ break;
37
+ default :
38
+ $title = __ ( 'Future Events', 'dbem' );
39
+ $scope = "future";
40
+ }
41
+ $args = array('scope'=>$scope, 'limit'=>0, 'order'=>$order );
42
+
43
+ if( !get_option('dbem_permissions_events') && !em_verify_admin() ){
44
+ $args['owner'] = get_current_user_id();
45
+ }
46
+
47
+ $events = EM_Events::get( $args );
48
+ $events_count = count ( $events );
49
+
50
+ $use_events_end = get_option ( 'dbem_use_event_end' );
51
+ ?>
52
+ <div class="wrap">
53
+ <div id="icon-events" class="icon32"><br />
54
+ </div>
55
+ <h2>
56
+ <?php echo $title; ?>
57
+ <a href="admin.php?page=events-manager-event" class="button add-new-h2"><?php _e('Add New','dbem'); ?></a>
58
+ </h2>
59
+ <?php
60
+ $link = array ();
61
+ $link ['past'] = "<a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&amp;scope=past&amp;order=desc'>" . __ ( 'Past events', 'dbem' ) . "</a>";
62
+ $link ['all'] = " <a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&amp;scope=all&amp;order=desc'>" . __ ( 'All events', 'dbem' ) . "</a>";
63
+ $link ['future'] = " <a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&amp;scope=future'>" . __ ( 'Future events', 'dbem' ) . "</a>";
64
+ ?>
65
+ <?php if ( !empty($_GET['error']) ) : ?>
66
+ <div id='message' class='error'>
67
+ <p><?php echo $_GET['error']; ?></p>
68
+ </div>
69
+ <?php endif; ?>
70
+ <?php if ( !empty($_GET['message']) ) : ?>
71
+ <div id='message' class='updated fade'>
72
+ <p><?php echo $_GET['message']; ?></p>
73
+ </div>
74
+ <?php endif; ?>
75
+ <form id="posts-filter" action="" method="get"><input type='hidden' name='page' value='events-manager' />
76
+ <ul class="subsubsub">
77
+ <li><a href='#' class="current"><?php _e ( 'Total', 'dbem' ); ?> <span class="count">(<?php echo (count ( $events )); ?>)</span></a></li>
78
+ </ul>
79
+ <p class="search-box">
80
+ <label class="screen-reader-text" for="post-search-input"><?php _e('Search Events','dbem'); ?>:</label>
81
+ <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? $_GET['em_search']:''; ?>" />
82
+ <input type="submit" value="<?php _e('Search Events','dbem'); ?>" class="button" />
83
+ </p>
84
+ <div class="tablenav">
85
+
86
+ <div class="alignleft actions">
87
+ <select name="action">
88
+ <option value="-1" selected="selected"><?php _e ( 'Bulk Actions' ); ?></option>
89
+ <option value="deleteEvents"><?php _e ( 'Delete selected','dbem' ); ?></option>
90
+ </select>
91
+ <input type="submit" value="<?php _e ( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
92
+ <select name="scope">
93
+ <?php
94
+ foreach ( $scope_names as $key => $value ) {
95
+ $selected = "";
96
+ if ($key == $scope)
97
+ $selected = "selected='selected'";
98
+ echo "<option value='$key' $selected>$value</option> ";
99
+ }
100
+ ?>
101
+ </select>
102
+ <input id="post-query-submit" class="button-secondary" type="submit" value="<?php _e ( 'Filter' )?>" />
103
+ </div>
104
+ <!--
105
+ <div class="view-switch">
106
+ <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
107
+ </div>
108
+ -->
109
+ <?php
110
+ if ( $events_count >= $limit ) {
111
+ $page_link_template = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%'));
112
+ $events_nav = em_admin_paginate( $page_link_template, $events_count, $limit, $page, 5);
113
+ echo $events_nav;
114
+ }
115
+ ?>
116
+ <br class="clear" />
117
+ </div>
118
+
119
+ <?php
120
+ if (empty ( $events )) {
121
+ // TODO localize
122
+ _e ( 'no events','dbem' );
123
+ } else {
124
+ ?>
125
+
126
+ <table class="widefat">
127
+ <thead>
128
+ <tr>
129
+ <th class='manage-column column-cb check-column' scope='col'>
130
+ <input class='select-all' type="checkbox" value='1' />
131
+ </th>
132
+ <th><?php _e ( 'Name', 'dbem' ); ?></th>
133
+ <th>&nbsp;</th>
134
+ <th><?php _e ( 'Location', 'dbem' ); ?></th>
135
+ <th colspan="2"><?php _e ( 'Date and time', 'dbem' ); ?></th>
136
+ </tr>
137
+ </thead>
138
+ <tbody>
139
+ <?php
140
+ $rowno = 0;
141
+ $event_count = 0;
142
+ foreach ( $events as $event ) {
143
+ /* @var $event EM_Event */
144
+ if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
145
+ $rowno++;
146
+ $class = ($rowno % 2) ? ' class="alternate"' : '';
147
+ // FIXME set to american
148
+ $localised_start_date = date_i18n('D d M Y', $event->start);
149
+ $localised_end_date = date_i18n('D d M Y', $event->end);
150
+ $style = "";
151
+ $today = date ( "Y-m-d" );
152
+ $location_summary = "<b>" . $event->location->name . "</b><br/>" . $event->location->address . " - " . $event->location->town;
153
+ $category = new EM_Category($event->category_id);
154
+
155
+ if ($event->start_date < $today && $event->end_date < $today){
156
+ $style = "style ='background-color: #FADDB7;'";
157
+ }
158
+ ?>
159
+ <tr <?php echo "$class $style"; ?>>
160
+
161
+ <td>
162
+ <input type='checkbox' class='row-selector' value='<?php echo $event->id; ?>' name='events[]' />
163
+ </td>
164
+ <td>
165
+ <strong>
166
+ <a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&amp;event_id=<?php echo $event->id ?>&amp;scope=<?php echo $scope ?>&amp;p=<?php echo $page ?>"><?php echo ($event->name); ?></a>
167
+ </strong>
168
+ <?php if( is_object($category) ) : ?>
169
+ <br/><span title='<?php echo __( 'Category', 'dbem' ).": ".$category->name ?>'><?php echo $category->name ?></span>
170
+ <?php endif; ?>
171
+ <?php
172
+ if( get_option('dbem_rsvp_enabled') == 1 && $event->rsvp == 1 ){
173
+ ?>
174
+ <br/>
175
+ <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php echo $event->id ?>"><?php echo __("Bookings",'dbem'); ?></a> &ndash;
176
+ <?php _e("Booked",'dbem'); ?>: <?php echo $event->get_bookings()->get_booked_seats()."/".$event->seats; ?>
177
+ <?php if( get_option('dbem_bookings_approval') == 1 ): ?>
178
+ | <?php _e("Pending",'dbem') ?>: <?php echo $event->get_bookings()->get_pending_seats(); ?>
179
+ <?php endif;
180
+ }
181
+ ?>
182
+ </td>
183
+ <td>
184
+ <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&amp;action=duplicate&amp;event_id=<?php echo $event->id; ?>&amp;scope=<?php echo $scope ?>&amp;p=<?php echo $page ?>" title="<?php _e ( 'Duplicate this event', 'dbem' ); ?>">
185
+ <strong>+</strong>
186
+ </a>
187
+ </td>
188
+ <td>
189
+ <?php echo $location_summary; ?>
190
+ </td>
191
+
192
+ <td>
193
+ <?php echo $localised_start_date; ?>
194
+ <?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
195
+ <br />
196
+ <?php
197
+ //TODO Should 00:00 - 00:00 be treated as an all day event?
198
+ echo substr ( $event->start_time, 0, 5 ) . " - " . substr ( $event->end_time, 0, 5 );
199
+ ?>
200
+ </td>
201
+ <td>
202
+ <?php
203
+ if ( $event->is_recurrence() ) {
204
+ ?>
205
+ <strong>
206
+ <?php echo $event->get_recurrence_description(); ?> <br />
207
+ <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&amp;event_id=<?php echo $event->recurrence_id ?>&amp;scope=<?php echo $scope ?>&amp;p=<?php echo $page ?>"><?php _e ( 'Reschedule', 'dbem' ); ?></a>
208
+ </strong>
209
+ <?php
210
+ }
211
+ ?>
212
+ </td>
213
+ </tr>
214
+ <?php
215
+ }
216
+ $event_count++;
217
+ }
218
+ ?>
219
+ </tbody>
220
+ </table>
221
+ <?php
222
+ } // end of table
223
+ ?>
224
+ <div class='tablenav'>
225
+ <div class="alignleft actions">
226
+ <br class='clear' />
227
+ </div>
228
+ <?php if ( $events_count >= $limit ) : ?>
229
+ <div class="tablenav-pages">
230
+ <?php
231
+ echo $events_nav;
232
+ ?>
233
+ </div>
234
+ <?php endif; ?>
235
+ <br class='clear' />
236
+ </div>
237
+ </form>
238
+ </div>
239
+ <?php
240
+ }
241
+
 
 
242
  ?>
admin/em-help.php CHANGED
@@ -1,52 +1,52 @@
1
- <?php
2
- /**
3
- * Display function for the support page. here we can give links to forums and special upgrade instructions e.g. migration features
4
- */
5
- function em_admin_help_page(){
6
- global $wpdb;
7
- ?>
8
- <div class="wrap">
9
- <div id="icon-events" class="icon32"><br /></div>
10
- <h2><?php _e('Getting Help for Events Manager','dbem'); ?></h2>
11
- <p>
12
- For further information on using this plugin, please view the <a href="http://wp-events-plugin.com/documentation/">documentation pages</a>. If you can't find what you're looking for in the documentation, you may find help on our <a href="http://wp-events-plugin.com/forums/">support forums</a>.
13
- </p>
14
- <div class="em-docs">
15
- <h2><?php _e('Placeholders for customizing event pages','dbem'); ?></h2>
16
- <p><?php echo sprintf( __("In the <a href='%s'>settings page</a>, you'll find various textboxes where you can edit how event information looks, such as for event and location lists. Using the placeholders below, you can choose what information should be displayed.",'dbem'), 'admin.php?page=events-manager-options'); ?></p>
17
- <h3><a name="event-placeholders"><?php _e('Event Related Placeholders','dbem'); ?></a></h3>
18
- <?php echo em_docs_placeholders( array('type'=>'events') ); ?>
19
- <h3><a name="location-placeholders"><?php _e('Location Related Placeholders','dbem'); ?></a></h3>
20
- <?php echo em_docs_placeholders( array('type'=>'locations') ); ?>
21
- <h3><a name="booking-placeholders"><?php _e('Booking Related Placeholders','dbem'); ?></a></h3>
22
- <?php echo em_docs_placeholders( array('type'=>'bookings') ); ?>
23
- </div>
24
- <?php
25
- //Is this a previously imported installation?
26
- $old_table_name = $wpdb->prefix.'dbem_events';
27
- if( $wpdb->get_var("SHOW TABLES LIKE '$old_table_name'") == $old_table_name ){
28
- ?>
29
- <hr style="margin:30px 10px;" />
30
- <div class="updated">
31
- <h3>Troubleshooting upgrades from version 2.x to 3.x</h3>
32
- <p>We notice that you upgraded from version 2, as we are now using new database tables, and we do not delete the old tables in case something went wrong with this upgrade.</p>
33
- <p>If something went wrong with the update to version 3 read on:</p>
34
- <h4>Scenario 1: the plugin is working, but for some reason the old events weren't imported</h4>
35
- <p>You can safely reimport your old events from the previous tables without any risk of deleting them. However, if you click the link below <b>YOU WILL OVERWRITE ANY NEW EVENTS YOU CREATED IN VERSION 3</b></p>
36
- <p><a onclick="return confirm('Are you sure you want to do this? Any new changes made since updating will be overwritten by your old ones, and this cannot be undone');" href="<?php echo wp_nonce_url( get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager-help&em_reimport=1', 'em_reimport' ) ?>">Reimport Events from version 2</a></p>
37
- <h4>Scenario 2: the plugin is not working, I want to go back to version 2!</h4>
38
- <p>You can safely downgrade and will not lose any information.</p>
39
- <ol>
40
- <li>First of all, <a href='http://downloads.wordpress.org/plugin/events-manager.2.2.2.zip'>dowload a copy of version 2.2</a></li>
41
- <li>Deactivate and delete Events Manager in the plugin page</li>
42
- <li><a href="<?php bloginfo('wpurl'); ?>/wp-admin/plugin-install.php?tab=upload">Upload the zip file you just downloaded here</a></li>
43
- <li>Let the developers know, of any bugs you ran into while upgrading. We'll help you out if there is a simple solution, and will fix reported bugs within days, if not quicker!</li>
44
- </ol>
45
- </div>
46
- <?php
47
- }
48
- ?>
49
- </div>
50
- <?php
51
- }
52
  ?>
1
+ <?php
2
+ /**
3
+ * Display function for the support page. here we can give links to forums and special upgrade instructions e.g. migration features
4
+ */
5
+ function em_admin_help_page(){
6
+ global $wpdb;
7
+ ?>
8
+ <div class="wrap">
9
+ <div id="icon-events" class="icon32"><br /></div>
10
+ <h2><?php _e('Getting Help for Events Manager','dbem'); ?></h2>
11
+ <p>
12
+ For further information on using this plugin, please view the <a href="http://wp-events-plugin.com/documentation/">documentation pages</a>. If you can't find what you're looking for in the documentation, you may find help on our <a href="http://wp-events-plugin.com/forums/">support forums</a>.
13
+ </p>
14
+ <div class="em-docs">
15
+ <h2><?php _e('Placeholders for customizing event pages','dbem'); ?></h2>
16
+ <p><?php echo sprintf( __("In the <a href='%s'>settings page</a>, you'll find various textboxes where you can edit how event information looks, such as for event and location lists. Using the placeholders below, you can choose what information should be displayed.",'dbem'), 'admin.php?page=events-manager-options'); ?></p>
17
+ <h3><a name="event-placeholders"><?php _e('Event Related Placeholders','dbem'); ?></a></h3>
18
+ <?php echo em_docs_placeholders( array('type'=>'events') ); ?>
19
+ <h3><a name="location-placeholders"><?php _e('Location Related Placeholders','dbem'); ?></a></h3>
20
+ <?php echo em_docs_placeholders( array('type'=>'locations') ); ?>
21
+ <h3><a name="booking-placeholders"><?php _e('Booking Related Placeholders','dbem'); ?></a></h3>
22
+ <?php echo em_docs_placeholders( array('type'=>'bookings') ); ?>
23
+ </div>
24
+ <?php
25
+ //Is this a previously imported installation?
26
+ $old_table_name = $wpdb->prefix.'dbem_events';
27
+ if( $wpdb->get_var("SHOW TABLES LIKE '$old_table_name'") == $old_table_name ){
28
+ ?>
29
+ <hr style="margin:30px 10px;" />
30
+ <div class="updated">
31
+ <h3>Troubleshooting upgrades from version 2.x to 3.x</h3>
32
+ <p>We notice that you upgraded from version 2, as we are now using new database tables, and we do not delete the old tables in case something went wrong with this upgrade.</p>
33
+ <p>If something went wrong with the update to version 3 read on:</p>
34
+ <h4>Scenario 1: the plugin is working, but for some reason the old events weren't imported</h4>
35
+ <p>You can safely reimport your old events from the previous tables without any risk of deleting them. However, if you click the link below <b>YOU WILL OVERWRITE ANY NEW EVENTS YOU CREATED IN VERSION 3</b></p>
36
+ <p><a onclick="return confirm('Are you sure you want to do this? Any new changes made since updating will be overwritten by your old ones, and this cannot be undone');" href="<?php echo wp_nonce_url( get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager-help&em_reimport=1', 'em_reimport' ) ?>">Reimport Events from version 2</a></p>
37
+ <h4>Scenario 2: the plugin is not working, I want to go back to version 2!</h4>
38
+ <p>You can safely downgrade and will not lose any information.</p>
39
+ <ol>
40
+ <li>First of all, <a href='http://downloads.wordpress.org/plugin/events-manager.2.2.2.zip'>dowload a copy of version 2.2</a></li>
41
+ <li>Deactivate and delete Events Manager in the plugin page</li>
42
+ <li><a href="<?php bloginfo('wpurl'); ?>/wp-admin/plugin-install.php?tab=upload">Upload the zip file you just downloaded here</a></li>
43
+ <li>Let the developers know, of any bugs you ran into while upgrading. We'll help you out if there is a simple solution, and will fix reported bugs within days, if not quicker!</li>
44
+ </ol>
45
+ </div>
46
+ <?php
47
+ }
48
+ ?>
49
+ </div>
50
+ <?php
51
+ }
52
  ?>
admin/em-locations-search.php CHANGED
@@ -3,24 +3,20 @@
3
  * This page will search for either a specific location via GET "id" variable
4
  * or will search for events by name via the GET "q" variable.
5
  */
6
- //FIXME just plug loc search into ajax catcher
7
  require_once('../../../../wp-load.php');
8
  global $wpdb;
9
 
10
  $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
11
- $location_cond = ( !current_user_can('edit_others_locations') ) ? "AND location_owner=".get_current_user_id() : '';
12
 
13
  $term = (isset($_GET['term'])) ? '%'.$_GET['term'].'%' : '%'.$_GET['q'].'%';
14
  $sql = $wpdb->prepare("
15
  SELECT
16
- location_id AS `id`,
17
  Concat( location_name, ', ', location_address, ', ', location_town) AS `label`,
18
  location_name AS `value`,
19
  location_address AS `address`,
20
  location_town AS `town`,
21
- location_state AS `state`,
22
- location_postcode AS `postcode`,
23
- location_country AS `country`
24
  FROM $locations_table
25
  WHERE ( `location_name` LIKE %s ) $location_cond LIMIT 10
26
  ", $term);
3
  * This page will search for either a specific location via GET "id" variable
4
  * or will search for events by name via the GET "q" variable.
5
  */
 
6
  require_once('../../../../wp-load.php');
7
  global $wpdb;
8
 
9
  $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
10
+ $location_cond = ( get_option('dbem_permissions_locations') < 1 && !em_verify_admin() ) ? "AND location_owner=".get_current_user_id() : '';
11
 
12
  $term = (isset($_GET['term'])) ? '%'.$_GET['term'].'%' : '%'.$_GET['q'].'%';
13
  $sql = $wpdb->prepare("
14
  SELECT
 
15
  Concat( location_name, ', ', location_address, ', ', location_town) AS `label`,
16
  location_name AS `value`,
17
  location_address AS `address`,
18
  location_town AS `town`,
19
+ location_id AS `id`
 
 
20
  FROM $locations_table
21
  WHERE ( `location_name` LIKE %s ) $location_cond LIMIT 10
22
  ", $term);
admin/em-locations.php CHANGED
@@ -1,264 +1,268 @@
1
- <?php
2
- /**
3
- * Looks at the request values, saves/updates and then displays the right menu in the admin
4
- * @return null
5
- */
6
- function em_admin_locations_page() {
7
- //TODO EM_Location is globalized, use it fully here
8
- global $EM_Location;
9
- //Take actions
10
- if( (!empty($_REQUEST['action']) && ( ($_REQUEST['action'] == "edit" && !empty($_REQUEST['location_id'])) || $_REQUEST['action'] == "add")) ) {
11
- em_admin_location();
12
- } elseif( !empty($_REQUEST['action']) && $_REQUEST['action'] == "location_save" ) {
13
- em_admin_location();
14
- } else {
15
- // no action, just a locations list
16
- em_admin_locations();
17
- }
18
- }
19
-
20
- function em_admin_locations($message='', $fill_fields = false) {
21
- global $EM_Notices;
22
- $limit = ( !empty($_REQUEST['limit']) ) ? $_REQUEST['limit'] : 20;//Default limit
23
- $page = ( !empty($_REQUEST['pno']) ) ? $_REQUEST['pno']:1;
24
- $offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
25
- if( !empty($_REQUEST['owner']) && current_user_can('read_others_locations') ){
26
- $locations = EM_Locations::get();
27
- $locations_mine_count = EM_Locations::count( array('owner'=>get_current_user_id()) );
28
- $locations_all_count = count($locations);
29
- }else{
30
- $locations = EM_Locations::get( array('owner'=>get_current_user_id()) );
31
- $locations_mine_count = count($locations);
32
- $locations_all_count = current_user_can('read_others_locations') ? EM_Locations::count():0;
33
- }
34
- $locations_count = count($locations);
35
- ?>
36
- <div class='wrap'>
37
- <div id='icon-edit' class='icon32'>
38
- <br/>
39
- </div>
40
- <h2>
41
- <?php _e('Locations', 'dbem'); ?>
42
- <a href="admin.php?page=events-manager-locations&action=add" class="button add-new-h2"><?php _e('Add New') ?></a>
43
- </h2>
44
-
45
- <?php echo $EM_Notices; ?>
46
-
47
- <form id='locations-filter' method='post' action=''>
48
- <input type='hidden' name='page' value='locations'/>
49
- <input type='hidden' name='limit' value='<?php echo $limit ?>' />
50
- <input type='hidden' name='p' value='<?php echo $page ?>' />
51
- <div class="subsubsub">
52
- <a href='admin.php?page=events-manager-locations' <?php echo (empty($_REQUEST['owner'])) ? 'class="current"':''; ?>><?php echo sprintf( __( 'My %s', 'dbem' ), __('Locations','dbem')); ?> <span class="count">(<?php echo $locations_mine_count; ?>)</span></a>
53
- <?php if( current_user_can('read_others_locations') ): ?>
54
- &nbsp;|&nbsp;
55
- <a href='admin.php?page=events-manager-locations&amp;owner=all' <?php echo (!empty($_REQUEST['owner'])) ? 'class="current"':''; ?>><?php echo sprintf( __( 'All %s', 'dbem' ), __('Locations','dbem')); ?> <span class="count">(<?php echo $locations_all_count; ?>)</span></a>
56
- <?php endif; ?>
57
- </div>
58
- <?php if ( $locations_count > 0 ) : ?>
59
- <div class='tablenav'>
60
- <div class="alignleft actions">
61
- <select name="action">
62
- <option value="" selected="selected"><?php _e ( 'Bulk Actions' ); ?></option>
63
- <option value="location_delete"><?php _e ( 'Delete selected','dbem' ); ?></option>
64
- </select>
65
- <input type="submit" value="<?php _e ( 'Apply' ); ?>" id="doaction2" class="button-secondary action" />
66
- </div>
67
- <?php
68
- if ( $locations_count >= $limit ) {
69
- $locations_nav = em_admin_paginate( $locations_count, $limit, $page );
70
- echo $locations_nav;
71
- }
72
- ?>
73
- </div>
74
- <table class='widefat'>
75
- <thead>
76
- <tr>
77
- <th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1'/></th>
78
- <th><?php _e('Name', 'dbem') ?></th>
79
- <th><?php _e('Address', 'dbem') ?></th>
80
- <th><?php _e('Town', 'dbem') ?></th>
81
- </tr>
82
- </thead>
83
- <tfoot>
84
- <tr>
85
- <th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1'/></th>
86
- <th><?php _e('Name', 'dbem') ?></th>
87
- <th><?php _e('Address', 'dbem') ?></th>
88
- <th><?php _e('Town', 'dbem') ?></th>
89
- </tr>
90
- </tfoot>
91
- <tbody>
92
- <?php $i = 1; ?>
93
- <?php foreach ($locations as $EM_Location) : ?>
94
- <?php if( $i >= $offset && $i <= $offset+$limit ): ?>
95
- <tr>
96
- <td><input type='checkbox' class ='row-selector' value='<?php echo $EM_Location->id ?>' name='locations[]'/></td>
97
- <td><a href='admin.php?page=events-manager-locations&amp;action=edit&amp;location_id=<?php echo $EM_Location->id ?>'><?php echo $EM_Location->name ?></a></td>
98
- <td><?php echo $EM_Location->address ?></td>
99
- <td><?php echo $EM_Location->town ?></td>
100
- </tr>
101
- <?php endif; ?>
102
- <?php $i++; ?>
103
- <?php endforeach; ?>
104
- </tbody>
105
- </table>
106
- <?php else: ?>
107
- <p><?php _e('No venues have been inserted yet!', 'dbem') ?></p>
108
- <?php endif; ?>
109
- </form>
110
- </div>
111
- <?php
112
- }
113
-
114
- function em_admin_location($message = "") {
115
- global $EM_Location, $EM_Notices;
116
- //check that user can access this page
117
- if( is_object($EM_Location) && !$EM_Location->can_manage('edit_locations','edit_others_locations') ){
118
- ?>
119
- <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php _e('You do not have the rights to manage this location.','dbem'); ?></p></div>
120
- <?php
121
- return false;
122
- }
123
- if( empty($EM_Location) || !is_object($EM_Location) ){
124
- $title = __('Add location', 'dbem');
125
- $EM_Location = new EM_Location();
126
- }else{
127
- $title = __('Edit location', 'dbem');
128
- }
129
- $required = "<i>(".__('required','dbem').")</i>";
130
- echo $EM_Notices;
131
- ?>
132
- <form enctype='multipart/form-data' name='editcat' id='location-form' method='post' action='admin.php?page=events-manager-locations' class='validate'>
133
- <input type='hidden' name='action' value='location_save' />
134
- <input type='hidden' name='_wpnonce' value='<?php echo wp_create_nonce('location_save'); ?>' />
135
- <input type='hidden' name='location_id' value='<?php echo $EM_Location->id ?>'/>
136
- <div class='wrap'>
137
- <div id='icon-edit' class='icon32'>
138
- <br/>
139
- </div>
140
- <h2><?php echo $title ?></h2>
141
-
142
- <?php global $EM_Notices; echo $EM_Notices; ?>
143
- <div id='ajax-response'></div>
144
-
145
- <div id="poststuff" class="metabox-holder">
146
- <div id="post-body">
147
- <div id="post-body-content">
148
- <div id="location_name" class="stuffbox">
149
- <h3>
150
- <?php _e ( 'Location Name', 'dbem' ); ?>
151
- </h3>
152
- <div class="inside">
153
- <input name='location_name' id='location-name' type='text' value='<?php echo htmlspecialchars($EM_Location->name, ENT_QUOTES); ?>' size='40' />
154
- <br />
155
- <?php _e('The name of the location', 'dbem') ?>
156
- </div>
157
- </div>
158
- <div id="location_coordinates" class="stuffbox" style='display: none;'>
159
- <h3>
160
- <?php _e ( 'Coordinates', 'dbem' ); ?>
161
- </h3>
162
- <div class="inside">
163
- <input id='location-latitude' name='location_latitude' type='text' value='<?php echo $EM_Location->latitude; ?>' size='15' />
164
- -
165
- <input id='location-longitude' name='location_longitude' type='text' value='<?php echo $EM_Location->longitude; ?>' size='15' />
166
- </div>
167
- </div>
168
- <div id="location_info" class="stuffbox">
169
- <h3>
170
- <?php _e ( 'Location', 'dbem' ); ?>
171
- </h3>
172
- <div class="inside">
173
- <p><?php _e("If you're using the Google Maps, the more detail you provide, the more accurate Google can be at finding your location. If your address isn't being found, please <a='http://maps.google.com'>try it on maps.google.com</a> by adding all the fields below seperated by commas.",'dbem')?></p>
174
- <table id="dbem-location-data">
175
- <tr>
176
- <td style="padding-right:20px; width:100%;">
177
- <table>
178
- <tr>
179
- <th><?php _e ( 'Address:' )?>&nbsp;</th>
180
- <td>
181
- <input id="location-address" type="text" name="location_address" value="<?php echo htmlspecialchars($EM_Location->address, ENT_QUOTES); ; ?>" /> <?php echo $required; ?>
182
- </td>
183
- </tr>
184
- <tr>
185
- <th><?php _e ( 'City/Town:' )?>&nbsp;</th>
186
- <td>
187
- <input id="location-town" type="text" name="location_town" value="<?php echo htmlspecialchars($EM_Location->town, ENT_QUOTES); ?>" /> <?php echo $required; ?>
188
- </td>
189
- </tr>
190
- <tr>
191
- <th><?php _e ( 'State/County:' )?>&nbsp;</th>
192
- <td>
193
- <input id="location-state" type="text" name="location_state" value="<?php echo htmlspecialchars($EM_Location->state, ENT_QUOTES); ?>" />
194
- </td>
195
- </tr>
196
- <tr>
197
- <th><?php _e ( 'Postcode:' )?>&nbsp;</th>
198
- <td>
199
- <input id="location-postcode" type="text" name="location_postcode" value="<?php echo htmlspecialchars($EM_Location->postcode, ENT_QUOTES); ?>" />
200
- </td>
201
- </tr>
202
- <tr>
203
- <th><?php _e ( 'Country:' )?>&nbsp;</th>
204
- <td>
205
- <select id="location-country" name="location_country">
206
- <?php foreach(em_get_countries(__('none selected','dbem')) as $country_key => $country_name): ?>
207
- <option value="<?php echo $country_key; ?>" <?php echo ( $EM_Location->country === $country_key || ($EM_Location->country == '' && $EM_Location->id == '' && get_option('dbem_location_default_country')==$country_key) ) ? 'selected="selected"':''; ?>><?php echo $country_name; ?></option>
208
- <?php endforeach; ?>
209
- </select> <?php echo $required; ?>
210
- </td>
211
- </tr>
212
- </table>
213
- </td>
214
- <?php if ( get_option ( 'dbem_gmap_is_active' ) ) : ?>
215
- <td width="400">
216
- <div id='em-map-404' style='width: 400px; vertical-align:middle; text-align: center;'>
217
- <p><em><?php _e ( 'Location not found', 'dbem' ); ?></em></p>
218
- </div>
219
- <div id='em-map' style='width: 400px; height: 300px; display: none;'></div>
220
- </td>
221
- <?php endif; ?>
222
- </tr>
223
- </table>
224
- </div>
225
- </div>
226
-
227
- <div id="location_description" class="postbox">
228
- <h3>
229
- <?php _e ( 'Details', 'dbem' ); ?>
230
- </h3>
231
- <div class="inside">
232
- <div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
233
- <?php the_editor($EM_Location->description ); ?>
234
- </div>
235
- <br />
236
- <?php _e ( 'Details about the location', 'dbem' )?>
237
- </div>
238
- </div>
239
-
240
- <div id="location_description" class="stuffbox">
241
- <h3>
242
- <?php _e ( 'Location image', 'dbem' ); ?>
243
- </h3>
244
- <div class="inside" style="padding:10px;">
245
- <?php if ($EM_Location->image_url != '') : ?>
246
- <img src='<?php echo $EM_Location->image_url; ?>' alt='<?php echo $EM_Location->name ?>'/>
247
- <?php else : ?>
248
- <?php _e('No image uploaded for this location yet', 'debm') ?>
249
- <?php endif; ?>
250
- <br /><br />
251
- <label for='location_image'><?php _e('Upload/change picture', 'dbem') ?></label> <input id='location-image' name='location_image' id='location_image' type='file' size='40' />
252
- </div>
253
- </div>
254
-
255
- </div>
256
- </div>
257
- </div>
258
- <p class='submit'><input type='submit' class='button-primary' name='submit' value='<?php _e('Update location', 'dbem') ?>' /></p>
259
- </div>
260
- </form>
261
- <?php
262
- }
263
-
 
 
 
 
264
  ?>
1
+ <?php
2
+ /**
3
+ * Looks at the request values, saves/updates and then displays the right menu in the admin
4
+ * @return null
5
+ */
6
+ function em_admin_locations_page() {
7
+ //TODO EM_Location is globalized, use it fully here
8
+ global $EM_Location;
9
+ //Take actions
10
+ if( !empty($_REQUEST['action']) || !empty($_REQUEST['location_id']) ){
11
+ if( $_REQUEST['action'] == "edit" || $_REQUEST['action'] == "add" ) {
12
+ //edit/add location
13
+ em_admin_location();
14
+ } elseif( $_REQUEST['action'] == "delete" ){
15
+ //delelte location
16
+ $locations = $_REQUEST['locations'];
17
+ foreach($locations as $location_id) {
18
+ $EM_Location = new EM_Location($location_id);
19
+ $EM_Location->delete();
20
+ }
21
+ em_admin_locations(__('Locations Deleted', "dbem" ));
22
+ } elseif( $_REQUEST['action'] == "save") {
23
+ // save (add/update) location
24
+ if( empty($EM_Location) || !is_object($EM_Location) ){
25
+ $EM_Location = new EM_Location(); //blank location
26
+ $success_message = __('The location has been added.', 'dbem');
27
+ }else{
28
+ $success_message = __('The location has been updated.', 'dbem');
29
+ }
30
+ $EM_Location->get_post();
31
+ $validation_result = $EM_Location->validate();
32
+ if ( $validation_result ) {
33
+ $EM_Location->save(); //FIXME better handling of db write fails when saving location
34
+ em_admin_locations($success_message);
35
+ } else {
36
+ ?>
37
+ <div id='message' class='error '>
38
+ <p>
39
+ <strong><?php _e( "Ach, there's a problem here:", "dbem" ) ?></strong><br /><br /><?php echo implode('<br />', $EM_Location->errors); ?>
40
+ </p>
41
+ </div>
42
+ <?php
43
+ unset($EM_Location);
44
+ em_admin_location();
45
+ }
46
+ }
47
+ } else {
48
+ // no action, just a locations list
49
+ em_admin_locations();
50
+ }
51
+ }
52
+
53
+ function em_admin_locations($message='', $fill_fields = false) {
54
+ $limit = ( !empty($_REQUEST['limit']) ) ? $_REQUEST['limit'] : 20;//Default limit
55
+ $page = ( !empty($_REQUEST['pno']) ) ? $_REQUEST['pno']:1;
56
+ $offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
57
+ $locations = EM_Locations::get();
58
+ $locations_count = count($locations);
59
+ ?>
60
+ <div class='wrap'>
61
+ <div id='icon-edit' class='icon32'>
62
+ <br/>
63
+ </div>
64
+ <h2>
65
+ <?php _e('Locations', 'dbem'); ?>
66
+ <a href="admin.php?page=events-manager-locations&action=add" class="button add-new-h2"><?php _e('Add New') ?></a>
67
+ </h2>
68
+
69
+ <?php if($message != "") : ?>
70
+ <div id='message' class='updated fade below-h2'>
71
+ <p><?php echo $message ?></p>
72
+ </div>
73
+ <?php endif; ?>
74
+
75
+ <form id='bookings-filter' method='post' action=''>
76
+ <input type='hidden' name='page' value='locations'/>
77
+ <input type='hidden' name='limit' value='<?php echo $limit ?>' />
78
+ <input type='hidden' name='p' value='<?php echo $page ?>' />
79
+ <?php if ( $locations_count > 0 ) : ?>
80
+ <div class='tablenav'>
81
+ <div class="alignleft actions">
82
+ <select name="action">
83
+ <option value="" selected="selected"><?php _e ( 'Bulk Actions' ); ?></option>
84
+ <option value="delete"><?php _e ( 'Delete selected','dbem' ); ?></option>
85
+ </select>
86
+ <input type="submit" value="<?php _e ( 'Apply' ); ?>" id="doaction2" class="button-secondary action" />
87
+ <?php
88
+ //Pagination (if needed/requested)
89
+ if( $locations_count >= $limit ){
90
+ //Show the pagination links (unless there's less than 10 events
91
+ $page_link_template = preg_replace('/(&|\?)p=\d+/i','',$_SERVER['REQUEST_URI']);
92
+ $page_link_template = em_add_get_params($page_link_template, array('pno'=>'%PAGE%'));
93
+ $locations_nav = em_paginate( $page_link_template, $locations_count, $limit, $page);
94
+ echo $locations_nav;
95
+ }
96
+ ?>
97
+ </div>
98
+ </div>
99
+ <table class='widefat'>
100
+ <thead>
101
+ <tr>
102
+ <th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1'/></th>
103
+ <th><?php _e('Name', 'dbem') ?></th>
104
+ <th><?php _e('Address', 'dbem') ?></th>
105
+ <th><?php _e('Town', 'dbem') ?></th>
106
+ </tr>
107
+ </thead>
108
+ <tfoot>
109
+ <tr>
110
+ <th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1'/></th>
111
+ <th><?php _e('Name', 'dbem') ?></th>
112
+ <th><?php _e('Address', 'dbem') ?></th>
113
+ <th><?php _e('Town', 'dbem') ?></th>
114
+ </tr>
115
+ </tfoot>
116
+ <tbody>
117
+ <?php $i = 1; ?>
118
+ <?php foreach ($locations as $EM_Location) : ?>
119
+ <?php if( $i >= $offset && $i <= $offset+$limit ): ?>
120
+ <tr>
121
+ <td><input type='checkbox' class ='row-selector' value='<?php echo $EM_Location->id ?>' name='locations[]'/></td>
122
+ <td><a href='admin.php?page=events-manager-locations&amp;action=edit&amp;location_id=<?php echo $EM_Location->id ?>'><?php echo $EM_Location->name ?></a></td>
123
+ <td><?php echo $EM_Location->address ?></td>
124
+ <td><?php echo $EM_Location->town ?></td>
125
+ </tr>
126
+ <?php endif; ?>
127
+ <?php $i++; ?>
128
+ <?php endforeach; ?>
129
+ </tbody>
130
+ </table>
131
+ <?php else: ?>
132
+ <p><?php _e('No venues have been inserted yet!', 'dbem') ?></p>
133
+ <?php endif; ?>
134
+ </form>
135
+ </div>
136
+ <?php
137
+ }
138
+
139
+ function em_admin_location($message = "") {
140
+ global $EM_Location, $EM_Event;
141
+ //check that user can access this page
142
+ if( is_object($EM_Location) && !$EM_Location->can_manage() ){
143
+ ?>
144
+ <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php _e('You do not have the rights to manage this location.','dbem'); ?></p></div>
145
+ <?php
146
+ return false;
147
+ }
148
+ if( empty($EM_Location) || !is_object($EM_Location) ){
149
+ $title = __('Add location', 'dbem');
150
+ $EM_Location = new EM_Location();
151
+ }else{
152
+ $title = __('Edit location', 'dbem');
153
+ }
154
+ ?>
155
+ <form enctype='multipart/form-data' name='editcat' id='locationForm' method='post' action='admin.php?page=events-manager-locations' class='validate'>
156
+ <input type='hidden' name='action' value='save' />
157
+ <input type='hidden' name='location_id' value='<?php echo $EM_Location->id ?>'/>
158
+ <div class='wrap'>
159
+ <div id='icon-edit' class='icon32'>
160
+ <br/>
161
+ </div>
162
+ <h2><?php echo $title ?></h2>
163
+
164
+ <?php if($message != "") : ?>
165
+ <div id='message' class='updated fade below-h2' style='background-color: rgb(255, 251, 204);'>
166
+ <p><?php echo $message ?></p>
167
+ </div>
168
+ <?php endif; ?>
169
+ <div id='ajax-response'></div>
170
+
171
+ <div id="poststuff" class="metabox-holder">
172
+ <div id="post-body">
173
+ <div id="post-body-content">
174
+ <div id="location_name" class="stuffbox">
175
+ <h3>
176
+ <?php _e ( 'Location Name', 'dbem' ); ?>
177
+ </h3>
178
+ <div class="inside">
179
+ <input name='location_name' id='location-name' type='text' value='<?php echo htmlspecialchars($EM_Location->name, ENT_QUOTES); ?>' size='40' />
180
+ <br />
181
+ <?php _e('The name of the location', 'dbem') ?>
182
+ </div>
183
+ </div>
184
+ <div id="location_coordinates" class="stuffbox" style='display: none;'>
185
+ <h3>
186
+ <?php _e ( 'Coordinates', 'dbem' ); ?>
187
+ </h3>
188
+ <div class="inside">
189
+ <input id='location-latitude' name='location_latitude' type='text' value='<?php echo $EM_Location->latitude; ?>' size='15' />
190
+ -
191
+ <input id='location-longitude' name='location_longitude' type='text' value='<?php echo $EM_Location->longitude; ?>' size='15' />
192
+ </div>
193
+ </div>
194
+ <div id="location_info" class="stuffbox">
195
+ <h3>
196
+ <?php _e ( 'Location', 'dbem' ); ?>
197
+ </h3>
198
+ <div class="inside">
199
+ <table id="dbem-location-data">
200
+ <tr>
201
+ <td style="padding-right:20px">
202
+ <table>
203
+ <tr>
204
+ <th><?php _e ( 'Address:' )?>&nbsp;</th>
205
+ <td>
206
+ <input id="location-address" type="text" name="location_address" value="<?php echo htmlspecialchars($EM_Location->address, ENT_QUOTES); ; ?>" />
207
+ <p><?php _e ( 'The address of the location where the event takes place. Example: 21, Dominick Street', 'dbem' )?></p>
208
+ </td>
209
+ </tr>
210
+ <tr>
211
+ <th><?php _e ( 'Town:' )?>&nbsp;</th>
212
+ <td>
213
+ <input id="location-town" type="text" name="location_town" value="<?php echo htmlspecialchars($EM_Location->town, ENT_QUOTES); ?>" />
214
+ <p><?php _e ( 'The town where the location is located. If you\'re using the Google Map integration and want to avoid geotagging ambiguities include the country in the town field. Example: Verona, Italy.', 'dbem' )?></p>
215
+ </td>
216
+ </tr>
217
+ </table>
218
+ </td>
219
+ <?php if ( get_option ( 'dbem_gmap_is_active' ) ) : ?>
220
+ <td width="400">
221
+ <div id='em-map-404' style='width: 400px; vertical-align:middle; text-align: center;'>
222
+ <p><em><?php _e ( 'Location not found', 'dbem' ); ?></em></p>
223
+ </div>
224
+ <div id='em-map' style='width: 400px; height: 300px; display: none;'></div>
225
+ </td>
226
+ <?php endif; ?>
227
+ </tr>
228
+ </table>
229
+ </div>
230
+ </div>
231
+
232
+ <div id="location_description" class="postbox">
233
+ <h3>
234
+ <?php _e ( 'Details', 'dbem' ); ?>
235
+ </h3>
236
+ <div class="inside">
237
+ <div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
238
+ <?php the_editor($EM_Location->description ); ?>
239
+ </div>
240
+ <br />
241
+ <?php _e ( 'Details about the location', 'dbem' )?>
242
+ </div>
243
+ </div>
244
+
245
+ <div id="location_description" class="stuffbox">
246
+ <h3>
247
+ <?php _e ( 'Location image', 'dbem' ); ?>
248
+ </h3>
249
+ <div class="inside" style="padding:10px;">
250
+ <?php if ($EM_Location->image_url != '') : ?>
251
+ <img src='<?php echo $EM_Location->image_url; ?>' alt='<?php echo $EM_Location->name ?>'/>
252
+ <?php else : ?>
253
+ <?php _e('No image uploaded for this location yet', 'debm') ?>
254
+ <?php endif; ?>
255
+ <br /><br />
256
+ <label for='location_image'><?php _e('Upload/change picture', 'dbem') ?></label> <input id='location-image' name='location_image' id='location_image' type='file' size='40' />
257
+ </div>
258
+ </div>
259
+ </div>
260
+ </div>
261
+ </div>
262
+ <p class='submit'><input type='submit' class='button-primary' name='submit' value='<?php _e('Update location', 'dbem') ?>' /></p>
263
+ </div>
264
+ </form>
265
+ <?php
266
+ }
267
+
268
  ?>
admin/em-options.php CHANGED
@@ -1,493 +1,444 @@
1
- <?php
2
-
3
- //Function composing the options subpanel
4
- function em_options_save(){
5
- if( current_user_can('activate_plugins') && !empty($_POST['em-submitted']) ){
6
- //Build the array of options here
7
- $post = $_POST;
8
- foreach ($_POST as $postKey => $postValue){
9
- if( substr($postKey, 0, 5) == 'dbem_' ){
10
- //TODO some more validation/reporting
11
- $numeric_options = array('dbem_locations_default_limit','dbem_events_default_limit');
12
- if( in_array($postKey,$numeric_options) && !is_numeric($postValue) ){
13
- //Do nothing, keep old setting.
14
- }else{
15
- //TODO slashes being added?
16
- //$postValue = EM_Object::sanitize($postValue)
17
- update_option($postKey, stripslashes($postValue));
18
- }
19
- }
20
- }
21
- //set capabilities
22
- if( !empty($_POST['em_capabilities']) && is_array($_POST['em_capabilities']) ){
23
- global $em_capabilities_array, $wp_roles;
24
- foreach( $wp_roles->role_objects as $role_name => $role ){
25
- foreach( array_keys($em_capabilities_array) as $capability){
26
- if( !empty($_POST['em_capabilities'][$role_name][$capability]) ){
27
- $role->add_cap($capability);
28
- }else{
29
-
30
- $role->remove_cap($capability);
31
- }
32
- }
33
- }
34
- }
35
- do_action('em_options_save');
36
- function em_options_saved_notice(){
37
- ?>
38
- <div class="updated"><p><strong><?php _e('Changes saved.'); ?></strong></p></div>
39
- <?php
40
- }
41
- add_action ( 'admin_notices', 'em_options_saved_notice' );
42
- if( get_option('dbem_debug') ){
43
- include_once( WP_PLUGIN_DIR.'/events-manager/em-debug.php');
44
- }
45
- }
46
- }
47
- add_action('admin_head', 'em_options_save');
48
-
49
-
50
-
51
- function em_admin_options_page() {
52
- //TODO place all options into an array
53
- $events_placeholders = '<a href="admin.php?page=events-manager-help#event-placeholders">'. __('Event Related Placeholders','dbem') .'</a>';
54
- $locations_placeholders = '<a href="admin.php?page=events-manager-help#location-placeholders">'. __('Location Related Placeholders','dbem') .'</a>';
55
- $bookings_placeholders = '<a href="admin.php?page=events-manager-help#booking-placeholders">'. __('Booking Related Placeholders','dbem') .'</a>';
56
- $events_placeholder_tip = " ". sprintf(__('This accepts %s and %s placeholders.','dbem'),$events_placeholders, $locations_placeholders);
57
- $locations_placeholder_tip = " ". sprintf(__('This accepts %s placeholders.','dbem'), $locations_placeholders);
58
- $bookings_placeholder_tip = " ". sprintf(__('This accepts %s, %s and %s placeholders.','dbem'), $bookings_placeholders, $events_placeholders, $locations_placeholders);
59
-
60
- $save_button = '<tr><th>&nbsp;</th><td><p class="submit" style="margin:0px; padding:0px; text-align:right;"><input type="submit" id="dbem_options_submit" name="Submit" value="'. __( 'Save Changes' ) .' ('. __('All','dbem') .')" /></p></ts></td></tr>';
61
- ?>
62
- <script type="text/javascript" charset="utf-8">
63
- jQuery(document).ready(function($){
64
- var close_text = '<?php _e('Collapse All','dbem'); ?>';
65
- var open_text = '<?php _e('Expand All','dbem'); ?>';
66
- var open_close = $('<a href="#" style="display:block; float:right; clear:right; margin:10px;">'+close_text+'</a>');
67
- $('#icon-options-general').after(open_close);
68
- open_close.click( function(e){
69
- e.preventDefault();
70
- if($(this).text() == close_text){
71
- $(".postbox").addClass('closed');
72
- $(this).text(open_text);
73
- }else{
74
- $(".postbox").removeClass('closed');
75
- $(this).text(close_text);
76
- }
77
- });
78
- //For rewrite titles
79
- $('input:radio[name=dbem_disable_title_rewrites]').live('change',function(){
80
- checked_check = $('input:radio[name=dbem_disable_title_rewrites]:checked');
81
- if( checked_check.val() == 1 ){
82
- $('#dbem_title_html_row').show();
83
- }else{
84
- $('#dbem_title_html_row').hide();
85
- }
86
- });
87
- $('input:radio[name=dbem_disable_title_rewrites]').trigger('change');
88
- $(".postbox").addClass('closed'); //Let's start off closing everything for now.
89
- });
90
- </script>
91
- <div class="wrap">
92
- <div id='icon-options-general' class='icon32'><br />
93
- </div>
94
- <h2><?php _e ( 'Event Manager Options', 'dbem' ); ?></h2>
95
-
96
- <form id="dbem_options_form" method="post" action="">
97
-
98
- <div class="metabox-holder">
99
- <!-- // TODO Move style in css -->
100
- <div class='postbox-container' style='width: 99.5%'>
101
- <div id="" class="meta-box-sortables" >
102
-
103
- <div class="postbox " >
104
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'General options', 'dbem' ); ?> </span></h3>
105
- <div class="inside">
106
- <table class="form-table">
107
- <?php
108
- em_options_radio_binary ( __( 'Use dropdown for locations?' ), 'dbem_use_select_for_locations', __( 'Select yes to select location from a drow-down menu; location selection will be faster, but you will lose the ability to insert locations with events','dbem' ) );
109
- em_options_radio_binary ( __( 'Use recurrence?' ), 'dbem_recurrence_enabled', __( 'Select yes to enable the recurrence features feature','dbem' ) );
110
- em_options_radio_binary ( __( 'Use RSVP?' ), 'dbem_rsvp_enabled', __( 'Select yes to enable the RSVP feature','dbem' ) );
111
- em_options_radio_binary ( __( 'Use categories?' ), 'dbem_categories_enabled', __( 'Select yes to enable the category features','dbem' ) );
112
- em_options_radio_binary ( __( 'Use attributes?' ), 'dbem_attributes_enabled', __( 'Select yes to enable the attributes feature','dbem' ) );
113
-
114
- /*default category*/
115
- $category_options = array();
116
- $category_options[0] = __('no default category','dbem');
117
- $EM_Categories = EM_Categories::get();
118
- foreach($EM_Categories as $EM_Category){
119
- $category_options[$EM_Category->id] = $EM_Category->name;
120
- }
121
- em_options_select ( __( 'Default Category' ), 'dbem_default_category', $category_options, __( 'This option allows you to select the default category when adding an event.','dbem' )." ".__('(not applicable with event ownership on presently, coming soon!)','dbem') );
122
-
123
- /*default location*/
124
- $location_options = array();
125
- $location_options[0] = __('no default location','dbem');
126
- $EM_Locations = EM_Locations::get();
127
- foreach($EM_Locations as $EM_Location){
128
- $location_options[$EM_Location->id] = $EM_Location->name;
129
- }
130
- em_options_select ( __( 'Default Location' ), 'dbem_default_location', $location_options, __( 'This option allows you to select the default location when adding an event.','dbem' )." ".__('(not applicable with event ownership on presently, coming soon!)','dbem') );
131
-
132
- /*default location country*/
133
- em_options_select ( __( 'Default Location Country' ), 'dbem_location_default_country', em_get_countries(__('no default country', 'dbem')), __('If you select a default country, that will be pre-selected when creating a new location.','dbem') );
134
-
135
- em_options_textarea ( __( 'Custom Placeholders', 'dbem' ), 'dbem_placeholders_custom', sprintf(__( "You can add custom placeholders here, one per line in this format <code>#_ATT{key}</code>. They will not appear on event pages unless you insert them into another template below, but you may want to store extra information about an event for other uses. <a href='%s'>More information on placeholders.</a>", 'dbem' ), 'wp-events-plugin.com/documentation/the-em-templates-syntax/') );
136
-
137
- echo $save_button;
138
- ?>
139
- </table>
140
-
141
- </div> <!-- . inside -->
142
- </div> <!-- .postbox -->
143
-
144
- <div class="postbox " >
145
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Events page', 'dbem' ); ?> </span></h3>
146
- <div class="inside">
147
- <table class="form-table">
148
- <?php
149
- //Wordpress Pages
150
- global $em_disable_filter; //Using a flag here instead
151
- $em_disable_filter = true;
152
- $get_pages = get_pages();
153
- $events_page_options = array();
154
- $events_page_options[0] = __('[No Events Page]');
155
- //TODO Add the hierarchy style ddm, like when choosing page parents
156
- foreach($get_pages as $page){
157
- $events_page_options[$page->ID] = $page->post_title;
158
- }
159
- em_options_select ( __( 'Events page' ), 'dbem_events_page', $events_page_options, __( 'This option allows you to select which page to use as an events page','dbem' ) );
160
- $em_disable_filter = false;
161
- //Rest
162
- em_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' ) );
163
- em_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.','dbem' ).' '.__('If you would like to show events that span over more than one day, see the Calendar section on this page.','dbem') );
164
- em_options_radio_binary ( __( 'Disable title rewriting?', 'dbem' ), 'dbem_disable_title_rewrites', __( "Some wordpress themes don't follow best practices when generating navigation menus, and so the automatic title rewriting feature may cause problems, if your menus aren't working correctly on the event pages, try setting this to 'Yes', and provide an appropriate HTML title format below.",'dbem' ) );
165
- em_options_input_text ( __( 'Event Manager titles', 'dbem' ), 'dbem_title_html', __( "This only setting only matters if you selected 'Yes' to above. You will notice the events page titles aren't being rewritten, and you have a new title underneath the default page name. This is where you control the HTML of this title. Make sure you keep the #_PAGETITLE placeholder here, as that's what is rewritten by events manager. To control what's rewritten in this title, see settings further down for page titles.", 'dbem' ) );
166
- em_options_input_text ( __( 'Event List Limits', 'dbem' ), 'dbem_events_default_limit', __( "This will control how many events are shown on one list by default.", 'dbem' ) );
167
- ?>
168
- <tr valign="top" id='dbem_events_default_orderby_row'>
169
- <th scope="row"><?php _e('Default event list ordering','dbem'); ?></th>
170
- <td>
171
- <select name="dbem_events_default_orderby" >
172
- <?php
173
- $orderby_options = apply_filters('em_settings_events_default_orderby_ddm', array(
174
- 'start_date,start_time,name' => __('Order by start date, start time, then event name','dbem'),
175
- 'name,start_date,start_time' => __('Order by name, start date, then start time','dbem'),
176
- 'name,end_date,end_time' => __('Order by name, end date, then end time','dbem'),
177
- 'end_date,end_time,name' => __('Order by end date, end time, then event name','dbem'),
178
- ));
179
- ?>
180
- <?php foreach($orderby_options as $key => $value) : ?>
181
- <option value='<?php echo $key ?>' <?php echo ($key == get_option('dbem_events_default_orderby')) ? "selected='selected'" : ''; ?>>
182
- <?php echo $value; ?>
183
- </option>
184
- <?php endforeach; ?>
185
- </select>
186
- <select name="dbem_events_default_order" >
187
- <?php
188
- $ascending = __('Ascending','dbem');
189
- $descending = __('Descending','dbem');
190
- $order_options = apply_filters('em_settings_events_default_order_ddm', array(
191
- 'ASC' => __('All Ascending','dbem'),
192
- 'DESC,ASC,ASC' => __("$descending, $ascending, $ascending",'dbem'),
193
- 'DESC,DESC,ASC' => __("$descending, $descending, $ascending",'dbem'),
194
- 'DESC' => __('All Descending','dbem'),
195
- 'ASC,DESC,ASC' => __("$ascending, $descending, $ascending",'dbem'),
196
- 'ASC,DESC,DESC' => __("$ascending, $descending, $descending",'dbem'),
197
- 'ASC,ASC,DESC' => __("$ascending, $ascending, $descending",'dbem'),
198
- 'DESC,ASC,DESC' => __("$descending, $ascending, $descending",'dbem'),
199
- ));
200
- ?>
201
- <?php foreach( $order_options as $key => $value) : ?>
202
- <option value='<?php echo $key ?>' <?php echo ($key == get_option('dbem_events_default_order')) ? "selected='selected'" : ''; ?>>
203
- <?php echo $value; ?>
204
- </option>
205
- <?php endforeach; ?>
206
- </select>
207
- <br/>
208
- <em><?php _e('When Events Manager displays lists of events the default behaviour is ordering by start date in ascending order. To change this, modify the values above.','dbem'); ?></em>
209
- </td>
210
- </tr>
211
- <tr valign="top" id='dbem_events_display_time_limit'>
212
- <th scope="row"><?php _e('Event list range limit','dbem'); ?></th>
213
- <td>
214
- <select name="dbem_events_page_time_limit" >
215
- <?php
216
- $limit_options = apply_filters('em_settings_events_page_time_limit_ddm', array(
217
- '0' => __('no limit','dbem'),
218
- '1' => __('This month','dbem'),
219
- '2' => __('Next two months','dbem'),
220
- '3' => __('Next three months','dbem'),
221
- '6' => __('Next six months','dbem'),
222
- '12' => __('Next twelve months','dbem')
223
- ));
224
- ?>
225
- <?php foreach( $limit_options as $key => $value) : ?>
226
- <option value='<?php echo $key ?>' <?php echo ($key == get_option('dbem_events_page_time_limit')) ? "selected='selected'" : ''; ?>>
227
- <?php echo $value; ?>
228
- </option>
229
- <?php endforeach; ?>
230
- </select>
231
- <br />
232
- <em><?php _e('Only show events starting within a certain time limit on the events page. Default is no time limit is applied.','dbem'); ?></em>
233
- </td>
234
- </tr>
235
- <?php
236
- echo $save_button;
237
- ?>
238
- </table>
239
- </div> <!-- . inside -->
240
- </div> <!-- .postbox -->
241
-
242
- <div class="postbox " >
243
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Events format', 'dbem' ); ?> </span></h3>
244
- <div class="inside">
245
- <table class="form-table">
246
- <?php
247
- em_options_textarea ( __( 'Default event list format header', 'dbem' ), 'dbem_event_list_item_format_header', __( 'This content will appear just above your code for the default event list format. Default is blank', 'dbem' ) );
248
- em_options_textarea ( __( 'Default event list format', 'dbem' ), 'dbem_event_list_item_format', __( 'The format of any events in a list.', 'dbem' ).$events_placeholder_tip );
249
- em_options_textarea ( __( 'Default event list format footer', 'dbem' ), 'dbem_event_list_item_format_footer', __( 'This content will appear just below your code for the default event list format. Default is blank', 'dbem' ) );
250
- em_options_input_text ( __( 'Single event page title format', 'dbem' ), 'dbem_event_page_title_format', __( 'The format of a single event page title.', 'dbem' ).$events_placeholder_tip );
251
- em_options_textarea ( __( 'Default single event format', 'dbem' ), 'dbem_single_event_format', __( 'The format of a single event page.', 'dbem' ).$events_placeholder_tip );
252
- em_options_input_text ( __( 'Events page title', 'dbem' ), 'dbem_events_page_title', __( 'The title on the multiple events page.', 'dbem' ) );
253
- em_options_input_text ( __( 'No events message', 'dbem' ), 'dbem_no_events_message', __( 'The message displayed when no events are available.', 'dbem' ) );
254
- em_options_input_text ( __( 'List events by date title', 'dbem' ), 'dbem_list_date_title', __( 'If viewing a page for events on a specific date, this is the title that would show up. To insert date 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/>', 'dbem' ) );
255
- echo $save_button;
256
- ?>
257
- </table>
258
- </div> <!-- . inside -->
259
- </div> <!-- .postbox -->
260
-
261
- <div class="postbox " >
262
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Calendar format', 'dbem' ); ?></span></h3>
263
- <div class="inside">
264
- <table class="form-table">
265
- <?php
266
- em_options_input_text ( __( 'Small calendar title', 'dbem' ), 'dbem_small_calendar_event_title_format', __( 'The format of the title, corresponding to the text that appears when hovering on an eventful calendar day.', 'dbem' ).$events_placeholder_tip );
267
- em_options_input_text ( __( 'Small calendar title separator', 'dbem' ), 'dbem_small_calendar_event_title_separator', __( 'The separator appearing on the above title when more than one events are taking place on the same day.', 'dbem' ) );
268
- em_options_input_text ( __( 'Full calendar events format', 'dbem' ), 'dbem_full_calendar_event_format', __( 'The format of each event when displayed in the full calendar. Remember to include <code>li</code> tags before and after the event.', 'dbem' ).$events_placeholder_tip );
269
- em_options_radio_binary ( __( 'Show long events on calendar pages?', 'dbem' ), 'dbem_full_calendar_long_events', __( "If you are showing a calendar on the events page (see Events format section on this page), you have the option of showing events that span over days on each day it occurs.",'dbem' ) );
270
- em_options_radio_binary ( __( 'Show list on day with single event?', 'dbem' ), 'dbem_display_calendar_day_single', __( "By default, if a calendar day only has one event, it display a single event when clicking on the link of that calendar date. If you select Yes here, you will get always see a list of events.",'dbem' ) );
271
- echo $save_button;
272
- ?>
273
- </table>
274
- </div> <!-- . inside -->
275
- </div> <!-- .postbox -->
276
-
277
- <div class="postbox " >
278
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Locations format', 'dbem' ); ?> </span></h3>
279
- <div class="inside">
280
- <table class="form-table">
281
- <?php
282
- em_options_input_text ( __( 'Single location page title format', 'dbem' ), 'dbem_location_page_title_format', __( 'The format of a single location page title.', 'dbem' ).$locations_placeholder_tip );
283
- em_options_textarea ( __( 'Default single location page format', 'dbem' ), 'dbem_single_location_format', __( 'The format of a single location page.', 'dbem' ).$locations_placeholder_tip );
284
- em_options_textarea ( __( 'Default location balloon format', 'dbem' ), 'dbem_location_baloon_format', __( 'The format of of the text appearing in the baloon describing the location in the map.', 'dbem' ).$locations_placeholder_tip );
285
- em_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.', 'dbem' ).$locations_placeholder_tip );
286
- em_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' ) );
287
- echo $save_button;
288
- ?>
289
- </table>
290
- </div> <!-- . inside -->
291
- </div> <!-- .postbox -->
292
-
293
- <div class="postbox " >
294
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'RSS feed format', 'dbem' ); ?> </span></h3>
295
- <div class="inside">
296
- <table class="form-table">
297
- <?php
298
- em_options_input_text ( __( 'RSS main title', 'dbem' ), 'dbem_rss_main_title', __( 'The main title of your RSS events feed.', 'dbem' ).$events_placeholder_tip );
299
- em_options_input_text ( __( 'RSS main description', 'dbem' ), 'dbem_rss_main_description', __( 'The main description of your RSS events feed.', 'dbem' ) );
300
- em_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' ).$events_placeholder_tip );
301
- em_options_input_text ( __( 'RSS description format', 'dbem' ), 'dbem_rss_description_format', __( 'The format of the description of each item in the events RSS feed.', 'dbem' ).$events_placeholder_tip );
302
- echo $save_button;
303
- ?>
304
- </table>
305
- </div> <!-- . inside -->
306
- </div> <!-- .postbox -->
307
-
308
- <div class="postbox " >
309
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Maps and geotagging', 'dbem' ); ?> </span></h3>
310
- <div class="inside">
311
- <table class='form-table'>
312
- <?php $gmap_is_active = get_option ( 'dbem_gmap_is_active' ); ?>
313
- <tr valign="top">
314
- <th scope="row"><?php _e ( 'Enable Google Maps integration?', 'dbem' ); ?></th>
315
- <td>
316
- <?php _e ( 'Yes' ); ?> <input id="dbem_gmap_is_active_yes" name="dbem_gmap_is_active" type="radio" value="1" <?php echo ($gmap_is_active) ? "checked='checked'":''; ?> />
317
- <?php _e ( 'No' ); ?> <input name="dbem_gmap_is_active" type="radio" value="0" <?php echo ($gmap_is_active) ? '':"checked='checked'"; ?> /><br />
318
- <em><?php _e ( 'Check this option to enable Goggle Map integration.', 'dbem' )?></em>
319
- </td>
320
- </tr>
321
- <?php
322
- em_options_textarea ( __( 'Map text format', 'dbem' ), 'dbem_map_text_format', __( 'The text format inside the map balloons.', 'dbem' ).$events_placeholder_tip );
323
- echo $save_button;
324
- ?>
325
- </table>
326
- </div> <!-- . inside -->
327
- </div> <!-- .postbox -->
328
-
329
- <div class="postbox " >
330
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Booking and Ticketing Options', 'dbem' ); ?> </span></h3>
331
- <div class="inside">
332
- <table class='form-table'>
333
- <?php
334
- em_options_radio_binary ( __( 'Approval Required?', 'dbem' ), 'dbem_bookings_approval', __( 'Bookings will not be confirmed until the event administrator approves it.', 'dbem' ) );
335
- em_options_radio_binary ( __( 'Show unavailable tickets?', 'dbem' ), 'dbem_bookings_tickets_show_unavailable', __( 'You can choose whether or not to show unavailable tickets to visitors.', 'dbem' ) );
336
- em_options_radio_binary ( __( 'Reserved unconfirmed spaces?', 'dbem' ), 'dbem_bookings_approval_reserved', __( 'By default, event spaces become unavailable once there are enough CONFIRMED bookings. To reserve spaces even if unnapproved, choose yes.', 'dbem' ) );
337
- em_options_radio_binary ( __( 'Show multiple tickets if logged out?', 'dbem' ), 'dbem_bookings_tickets_show_loggedout', __( 'If logged out, a user will be asked to register in order to book. However, we can show available tickets if you have more than one ticket.', 'dbem' ) );
338
- em_options_radio_binary ( __( 'Allow overbooking when approving?', 'dbem' ), 'dbem_bookings_approval_overbooking', __( 'If you get a lot of pending bookings and you decide to allow more bookings than spaces allow, setting this to yes will allow you to override the event space limit when manually approving.', 'dbem' ) );
339
- echo $save_button;
340
- ?>
341
- </table>
342
- </div> <!-- . inside -->
343
- </div> <!-- .postbox -->
344
-
345
- <div class="postbox " >
346
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Booking Email Templates', 'dbem' ); ?> </span></h3>
347
- <div class="inside">
348
- <table class='form-table'>
349
- <?php
350
- em_options_select ( __( 'Default contact person', 'dbem' ), 'dbem_default_contact_person', em_get_wp_users (), __( 'Select the default contact person. This user will be employed whenever a contact person is not explicitly specified for an event', 'dbem' ) );
351
- em_options_input_text ( __( 'Email events admin?', 'dbem' ), 'dbem_bookings_notify_admin', __( "If you would like every event booking confirmation email sent to an administrator write their email here (leave blank to not send an email).", 'dbem' ) );
352
- em_options_radio_binary ( __( 'Email contact person?', 'dbem' ), 'dbem_bookings_contact_email', __( 'Check this option if you want the event contact to receive an email when someone books places. An email will be sent when a booking is first made (regardless if confirmed or pending)', 'dbem' ) );
353
- ?>
354
- <tr><td colspan='2'><h4><?php _e('Contact person booking confirmed','dbem') ?></h4></td></tr>
355
- <tr><td colspan='2'><?php echo __('An email will be sent to the event contact when a booking is first made.','dbem').$bookings_placeholder_tip ?></td></tr>
356
- <?php
357
- em_options_input_text ( __( 'Contact person email subject', 'dbem' ), 'dbem_bookings_contact_email_subject', '' );
358
- em_options_textarea ( __( 'Contact person email', 'dbem' ), 'dbem_bookings_contact_email_body', '' );
359
- ?>
360
- <tr><td colspan='2'><h4><?php _e('Contact person booking cancelled','dbem') ?></h4></td></tr>
361
- <tr><td colspan='2'><?php echo __('An email will be sent to the event contact if someone cancels their booking.','dbem').$bookings_placeholder_tip ?></td></tr>
362
- <?php
363
- em_options_input_text ( __( 'Contact person cancellation subject', 'dbem' ), 'dbem_contactperson_email_cancelled_subject', '' );
364
- em_options_textarea ( __( 'Contact person cancellation email', 'dbem' ), 'dbem_contactperson_email_cancelled_body', '' );
365
- ?>
366
- <tr><td colspan='2'><h4><?php _e('Confirmed booking email','dbem') ?></h4></td></tr>
367
- <tr><td colspan='2'><?php echo __('This is sent when a person\'s booking is confirmed. This will be sent automatically if approvals are required and the booking is approved. If approvals are disabled, this is sent out when a user first submits their booking.','dbem').$bookings_placeholder_tip ?></td></tr>
368
- <?php
369
- em_options_input_text ( __( 'Booking confirmed email subject', 'dbem' ), 'dbem_bookings_email_confirmed_subject', '' );
370
- em_options_textarea ( __( 'Booking confirmed email', 'dbem' ), 'dbem_bookings_email_confirmed_body', '' );
371
- ?>
372
- <tr><td colspan='2'><h4><?php _e('Pending booking email','dbem') ?></h4></td></tr>
373
- <tr><td colspan='2'><?php echo __( 'This will be sent to the person when they first submit their booking. Not relevant if bookings don\'t require approval.', 'dbem' ).$bookings_placeholder_tip ?></td></tr>
374
- <?php
375
- em_options_input_text ( __( 'Booking pending email subject', 'dbem' ), 'dbem_bookings_email_pending_subject', '');
376
- em_options_textarea ( __( 'Booking pending email', 'dbem' ), 'dbem_bookings_email_pending_body','') ;
377
- ?>
378
- <tr><td colspan='2'><h4><?php _e('Rejected booking email','dbem') ?></h4></td></tr>
379
- <tr><td colspan='2'><?php echo __( 'This will be sent automatically when a booking is rejected. Not relevant if bookings don\'t require approval.', 'dbem' ).$bookings_placeholder_tip ?></td></tr>
380
- <?php
381
- em_options_input_text ( __( 'Booking rejected email subject', 'dbem' ), 'dbem_bookings_email_rejected_subject', __( "The subject of the email sent to the person making a booking that is awaiting administrator approval. Not relevant if bookings don't require approval.", 'dbem' ).$bookings_placeholder_tip );
382
- em_options_textarea ( __( 'Booking rejected email', 'dbem' ), 'dbem_bookings_email_rejected_body', __( 'The body of the email which will be sent to the person if the booking is rejected. Not relevant if bookings don\'t require approval.', 'dbem' ).$bookings_placeholder_tip );
383
- echo $save_button;
384
- ?>
385
- <tr><td colspan='2'><h4><?php _e('Booking cancelled','dbem') ?></h4></td></tr>
386
- <tr><td colspan='2'><?php echo __('This will be sent when a user cancels their booking.','dbem').$bookings_placeholder_tip ?></td></tr>
387
- <?php
388
- em_options_input_text ( __( 'Booking cancelled email subject', 'dbem' ), 'dbem_bookings_email_cancelled_subject', '' );
389
- em_options_textarea ( __( 'Booking cancelled email', 'dbem' ), 'dbem_bookings_email_cancelled_body', '' );
390
- ?>
391
- </table>
392
- </div> <!-- . inside -->
393
- </div> <!-- .postbox -->
394
-
395
- <div class="postbox " >
396
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Email Settings', 'dbem' ); ?> </span></h3>
397
- <div class="inside">
398
- <table class='form-table'>
399
- <?php
400
- em_options_input_text ( __( 'Notification sender name', 'dbem' ), 'dbem_mail_sender_name', __( "Insert the display name of the notification sender.", 'dbem' ) );
401
- em_options_input_text ( __( 'Notification sender address', 'dbem' ), 'dbem_mail_sender_address', __( "Insert the address of the notification sender.", 'dbem' ) );
402
- em_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' ) );
403
- em_options_select ( __( 'Mail sending method', 'dbem' ), 'dbem_rsvp_mail_send_method', array ('smtp' => 'SMTP', 'mail' => __( 'PHP mail function', 'dbem' ), 'sendmail' => 'Sendmail', 'qmail' => 'Qmail', 'wp_mail' => 'WP Mail' ), __( 'Select the method to send email notification.', 'dbem' ) );
404
- em_options_radio_binary ( __( 'Use SMTP authentication?', 'dbem' ), 'dbem_rsvp_mail_SMTPAuth', __( 'SMTP authentication is often needed. If you use GMail, make sure to set this parameter to Yes', 'dbem' ) );
405
- em_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' ) );
406
- em_options_input_text ( __( 'SMTP username', 'dbem' ), 'dbem_smtp_username', __( "Insert the username to be used to access your SMTP server.", 'dbem' ) );
407
- em_options_input_password ( __( 'SMTP password', 'dbem' ), "dbem_smtp_password", __( "Insert the password to be used to access your SMTP server", 'dbem' ) );
408
- echo $save_button;
409
- ?>
410
- </table>
411
- </div> <!-- . inside -->
412
- </div> <!-- .postbox -->
413
-
414
- <div class="postbox " >
415
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Images size', 'dbem' ); ?> </span></h3>
416
- <div class="inside">
417
- <table class='form-table'>
418
- <?php
419
- em_options_input_text ( __( 'Maximum width (px)', 'dbem' ), 'dbem_image_max_width', __( 'The maximum allowed width for images uploades', 'dbem' ) );
420
- em_options_input_text ( __( 'Maximum height (px)', 'dbem' ), 'dbem_image_max_height', __( "The maximum allowed height for images uploaded, in pixels", 'dbem' ) );
421
- em_options_input_text ( __( 'Maximum size (bytes)', 'dbem' ), 'dbem_image_max_size', __( "The maximum allowed size for images uploaded, in pixels", 'dbem' ) );
422
- echo $save_button;
423
- ?>
424
- </table>
425
- </div> <!-- . inside -->
426
- </div> <!-- .postbox -->
427
-
428
- <div class="postbox " >
429
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'User Capabilities', 'dbem' ); ?> (Beta)</span></h3>
430
- <div class="inside">
431
- <table class="form-table">
432
- <tr><td colspan="2">
433
- <strong><?php _e('Warning: Changing these values may result in exposing previously hidden information to all users.')?></strong><br />
434
- </td></tr>
435
- <?php
436
- global $wp_roles;
437
- global $em_capabilities_array;
438
- ?>
439
- <tr><td colspan="2">
440
- <p><em><?php _e('You can now give fine grained control with regards to what your users can do with events. Each user role can have perform different sets of actions.','dbem'); ?></em></p>
441
- <table class="form-table" style="width:auto;">
442
- <?php foreach($wp_roles->role_objects as $role): ?>
443
- <tr>
444
- <th><?php echo $role->name; ?></th>
445
- <td>
446
- <table>
447
- <?php foreach(array_keys($em_capabilities_array) as $capability): ?>
448
- <tr>
449
- <td><?php echo $capability; ?></td>
450
- <td><input type="checkbox" name="em_capabilities[<?php echo $role->name; ?>][<?php echo $capability ?>]" value="1" <?php echo $role->has_cap($capability) ? 'checked="checked"':''; ?> /></td>
451
- </tr>
452
- <?php endforeach; ?>
453
- </table>
454
- </td>
455
- </tr>
456
- <?php endforeach; ?>
457
- </table>
458
- </td></tr>
459
- <?php echo $save_button; ?>
460
- </table>
461
- </div> <!-- . inside -->
462
- </div> <!-- .postbox -->
463
-
464
- <?php /*
465
- <div class="postbox " >
466
- <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Debug Modes', 'dbem' ); ?> </span></h3>
467
- <div class="inside">
468
- <table class='form-table'>
469
- <?php
470
- em_options_radio_binary ( __( 'EM Debug Mode?', 'dbem' ), 'dbem_debug', __( 'Setting this to yes will display different content to admins for event pages and emails so you can see all the available placeholders and their values.', 'dbem' ) );
471
- em_options_radio_binary ( __( 'WP Debug Mode?', 'dbem' ), 'dbem_wp_debug', __( 'This will turn WP_DEBUG mode on. Useful if you want to troubleshoot php errors without looking at your logs.', 'dbem' ) );
472
- ?>
473
- </table>
474
- </div> <!-- . inside -->
475
- </div> <!-- .postbox -->
476
- */ ?>
477
-
478
- <?php do_action('em_options_page_footer'); ?>
479
-
480
- <p class="submit">
481
- <input type="submit" id="dbem_options_submit" name="Submit" value="<?php _e ( 'Save Changes' )?>" />
482
- <input type="hidden" name="em-submitted" value="1" />
483
- </p>
484
-
485
- </div> <!-- .metabox-sortables -->
486
- </div> <!-- .postbox-container -->
487
-
488
- </div> <!-- .metabox-holder -->
489
- </form>
490
- </div>
491
- <?php
492
- }
493
  ?>
1
+ <?php
2
+
3
+ //Function composing the options subpanel
4
+ function em_options_save(){
5
+ if( current_user_can('activate_plugins') && !empty($_POST['em-submitted']) ){
6
+ //Build the array of options here
7
+ $post = $_POST;
8
+ foreach ($_POST as $postKey => $postValue){
9
+ if( substr($postKey, 0, 5) == 'dbem_' ){
10
+ //TODO some more validation/reporting
11
+ $numeric_options = array('dbem_locations_default_limit','dbem_events_default_limit');
12
+ if( in_array($postKey,$numeric_options) && !is_numeric($postValue) ){
13
+ //Do nothing, keep old setting.
14
+ }else{
15
+ //TODO slashes being added?
16
+ //$postValue = EM_Object::sanitize($postValue)
17
+ update_option($postKey, stripslashes($postValue));
18
+ }
19
+ }
20
+ }
21
+ function em_options_saved_notice(){
22
+ ?>
23
+ <div class="updated"><p><strong><?php _e('Changes saved.'); ?></strong></p></div>
24
+ <?php
25
+ }
26
+ add_action ( 'admin_notices', 'em_options_saved_notice' );
27
+ }
28
+ }
29
+ add_action('admin_head', 'em_options_save');
30
+
31
+
32
+
33
+ function em_admin_options_page() {
34
+ //TODO place all options into an array
35
+ $events_placeholders = '<a href="admin.php?page=events-manager-help#event-placeholders">'. __('Event Related Placeholders','dbem') .'</a>';
36
+ $locations_placeholders = '<a href="admin.php?page=events-manager-help#location-placeholders">'. __('Location Related Placeholders','dbem') .'</a>';
37
+ $bookings_placeholders = '<a href="admin.php?page=events-manager-help#booking-placeholders">'. __('Booking Related Placeholders','dbem') .'</a>';
38
+ $events_placeholder_tip = " ". sprintf(__('This accepts %s and %s placeholders.','dbem'),$events_placeholders, $locations_placeholders);
39
+ $locations_placeholder_tip = " ". sprintf(__('This accepts %s placeholders.','dbem'), $locations_placeholders);
40
+ $bookings_placeholder_tip = " ". sprintf(__('This accepts %s, %s and %s placeholders.','dbem'), $bookings_placeholders, $events_placeholders, $locations_placeholders);
41
+
42
+ $save_button = '<tr><th>&nbsp;</th><td><p class="submit" style="margin:0px; padding:0px; text-align:right;"><input type="submit" id="dbem_options_submit" name="Submit" value="'. __( 'Save Changes' ) .' ('. __('All','dbem') .')" /></p></ts></td></tr>';
43
+ ?>
44
+ <script type="text/javascript" charset="utf-8">
45
+ jQuery(document).ready(function($){
46
+ var close_text = '<?php _e('Collapse All','dbem'); ?>';
47
+ var open_text = '<?php _e('Expand All','dbem'); ?>';
48
+ var open_close = $('<a href="#" style="display:block; float:right; clear:right; margin:10px;">'+close_text+'</a>');
49
+ $('#icon-options-general').after(open_close);
50
+ open_close.click( function(e){
51
+ e.preventDefault();
52
+ if($(this).text() == close_text){
53
+ $(".postbox").addClass('closed');
54
+ $(this).text(open_text);
55
+ }else{
56
+ $(".postbox").removeClass('closed');
57
+ $(this).text(close_text);
58
+ }
59
+ });
60
+ //For rewrite titles
61
+ $('input:radio[name=dbem_disable_title_rewrites]').live('change',function(){
62
+ checked_check = $('input:radio[name=dbem_disable_title_rewrites]:checked');
63
+ if( checked_check.val() == 1 ){
64
+ $('#dbem_title_html_row').show();
65
+ }else{
66
+ $('#dbem_title_html_row').hide();
67
+ }
68
+ });
69
+ $('input:radio[name=dbem_disable_title_rewrites]').trigger('change');
70
+
71
+ });
72
+ </script>
73
+ <div class="wrap">
74
+ <div id='icon-options-general' class='icon32'><br />
75
+ </div>
76
+ <h2><?php _e ( 'Event Manager Options', 'dbem' ); ?></h2>
77
+
78
+ <form id="dbem_options_form" method="post" action="">
79
+
80
+ <div class="metabox-holder">
81
+ <!-- // TODO Move style in css -->
82
+ <div class='postbox-container' style='width: 99.5%'>
83
+ <div id="" class="meta-box-sortables" >
84
+
85
+ <div class="postbox " >
86
+ <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'General options', 'dbem' ); ?> </span></h3>
87
+ <div class="inside">
88
+ <table class="form-table">
89
+ <?php
90
+ em_options_radio_binary ( __( 'Use dropdown for locations?' ), 'dbem_use_select_for_locations', __( 'Select yes to select location from a drow-down menu; location selection will be faster, but you will lose the ability to insert locations with events','dbem' ) );
91
+ em_options_radio_binary ( __( 'Use recurrence?' ), 'dbem_recurrence_enabled', __( 'Select yes to enable the recurrence features feature','dbem' ) );
92
+ em_options_radio_binary ( __( 'Use RSVP?' ), 'dbem_rsvp_enabled', __( 'Select yes to enable the RSVP feature','dbem' ) );
93
+ em_options_radio_binary ( __( 'Use categories?' ), 'dbem_categories_enabled', __( 'Select yes to enable the category features','dbem' ) );
94
+ em_options_radio_binary ( __( 'Use attributes?' ), 'dbem_attributes_enabled', __( 'Select yes to enable the attributes feature','dbem' ) );
95
+
96
+ /*default category*/
97
+ $category_options = array();
98
+ $category_options[0] = __('no default category','dbem');
99
+ $EM_Categories = EM_Categories::get();
100
+ foreach($EM_Categories as $EM_Category){
101
+ $category_options[$EM_Category->id] = $EM_Category->name;
102
+ }
103
+ em_options_select ( __( 'Default Category' ), 'dbem_default_category', $category_options, __( 'This option allows you to select the default category when adding an event.','dbem' )." ".__('(not applicable with event ownership on presently, coming soon!)','dbem') );
104
+
105
+ /*default location*/
106
+ $location_options = array();
107
+ $location_options[0] = __('no default location','dbem');
108
+ $EM_Locations = EM_Locations::get();
109
+ foreach($EM_Locations as $EM_Location){
110
+ $location_options[$EM_Location->id] = $EM_Location->name;
111
+ }
112
+ em_options_select ( __( 'Default Location' ), 'dbem_default_location', $location_options, __( 'This option allows you to select the default location when adding an event.','dbem' )." ".__('(not applicable with event ownership on presently, coming soon!)','dbem') );
113
+
114
+ em_options_textarea ( __( 'Custom Placeholders', 'dbem' ), 'dbem_placeholders_custom', sprintf(__( "You can add custom placeholders here, one per line in this format <code>#_ATT{key}</code>. They will not appear on event pages unless you insert them into another template below, but you may want to store extra information about an event for other uses. <a href='%s'>More information on placeholders.</a>", 'dbem' ), 'wp-events-plugin.com/documentation/the-em-templates-syntax/') );
115
+
116
+ echo $save_button;
117
+ ?>
118
+ </table>
119
+
120
+ </div> <!-- . inside -->
121
+ </div> <!-- .postbox -->
122
+
123
+ <div class="postbox " >
124
+ <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Events page', 'dbem' ); ?> </span></h3>
125
+ <div class="inside">
126
+ <table class="form-table">
127
+ <?php
128
+ //Wordpress Pages
129
+ global $em_disable_filter; //Using a flag here instead
130
+ $em_disable_filter = true;
131
+ $get_pages = get_pages();
132
+ $events_page_options = array();
133
+ $events_page_options[0] = __('[No Events Page]');
134
+ //TODO Add the hierarchy style ddm, like when choosing page parents
135
+ foreach($get_pages as $page){
136
+ $events_page_options[$page->ID] = $page->post_title;
137
+ }
138
+ em_options_select ( __( 'Events page' ), 'dbem_events_page', $events_page_options, __( 'This option allows you to select which page to use as an events page','dbem' ) );
139
+ $em_disable_filter = false;
140
+ //Rest
141
+ em_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' ) );
142
+ em_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.','dbem' ).' '.__('If you would like to show events that span over more than one day, see the Calendar section on this page.','dbem') );
143
+ em_options_radio_binary ( __( 'Disable title rewriting?', 'dbem' ), 'dbem_disable_title_rewrites', __( "Some wordpress themes don't follow best practices when generating navigation menus, and so the automatic title rewriting feature may cause problems, if your menus aren't working correctly on the event pages, try setting this to 'Yes', and provide an appropriate HTML title format below.",'dbem' ) );
144
+ em_options_input_text ( __( 'Event Manager titles', 'dbem' ), 'dbem_title_html', __( "This only setting only matters if you selected 'Yes' to above. You will notice the events page titles aren't being rewritten, and you have a new title underneath the default page name. This is where you control the HTML of this title. Make sure you keep the #_PAGETITLE placeholder here, as that's what is rewritten by events manager. To control what's rewritten in this title, see settings further down for page titles.", 'dbem' ) );
145
+ em_options_input_text ( __( 'Event List Limits', 'dbem' ), 'dbem_events_default_limit', __( "This will control how many events are shown on one list by default.", 'dbem' ) );
146
+ ?>
147
+ <tr valign="top" id='dbem_events_default_orderby_row'>
148
+ <th scope="row"><?php _e('Default event list ordering','dbem'); ?></th>
149
+ <td>
150
+ <select name="dbem_events_default_orderby" >
151
+ <?php
152
+ $orderby_options = apply_filters('em_settings_events_default_orderby_ddm', array(
153
+ 'start_date,start_time,name' => __('Order by start date, start time, then event name','dbem'),
154
+ 'name,start_date,start_time' => __('Order by name, start date, then start time','dbem'),
155
+ 'name,end_date,end_time' => __('Order by name, end date, then end time','dbem'),
156
+ 'end_date,end_time,name' => __('Order by end date, end time, then event name','dbem'),
157
+ ));
158
+ ?>
159
+ <?php foreach($orderby_options as $key => $value) : ?>
160
+ <option value='<?php echo $key ?>' <?php echo ($key == get_option('dbem_events_default_orderby')) ? "selected='selected'" : ''; ?>>
161
+ <?php echo $value; ?>
162
+ </option>
163
+ <?php endforeach; ?>
164
+ </select>
165
+ <select name="dbem_events_default_order" >
166
+ <?php
167
+ $ascending = __('Ascending','dbem');
168
+ $descending = __('Descending','dbem');
169
+ $order_options = apply_filters('em_settings_events_default_order_ddm', array(
170
+ 'ASC' => __('All Ascending','dbem'),
171
+ 'DESC,ASC,ASC' => __("$descending, $ascending, $ascending",'dbem'),
172
+ 'DESC,DESC,ASC' => __("$descending, $descending, $ascending",'dbem'),
173
+ 'DESC' => __('All Descending','dbem'),
174
+ 'ASC,DESC,ASC' => __("$ascending, $descending, $ascending",'dbem'),
175
+ 'ASC,DESC,DESC' => __("$ascending, $descending, $descending",'dbem'),
176
+ 'ASC,ASC,DESC' => __("$ascending, $ascending, $descending",'dbem'),
177
+ 'DESC,ASC,DESC' => __("$descending, $ascending, $descending",'dbem'),
178
+ ));
179
+ ?>
180
+ <?php foreach( $order_options as $key => $value) : ?>
181
+ <option value='<?php echo $key ?>' <?php echo ($key == get_option('dbem_events_default_order')) ? "selected='selected'" : ''; ?>>
182
+ <?php echo $value; ?>
183
+ </option>
184
+ <?php endforeach; ?>
185
+ </select>
186
+ <br/>
187
+ <em><?php _e('When Events Manager displays lists of events the default behaviour is ordering by start date in ascending order. To change this, modify the values above.','dbem'); ?></em>
188
+ </td>
189
+ </tr>
190
+ <tr valign="top" id='dbem_events_display_time_limit'>
191
+ <th scope="row"><?php _e('Event list range limit','dbem'); ?></th>
192
+ <td>
193
+ <select name="dbem_events_page_time_limit" >
194
+ <?php
195
+ $limit_options = apply_filters('em_settings_events_page_time_limit_ddm', array(
196
+ '0' => __('no limit','dbem'),
197
+ '1' => __('This month','dbem'),
198
+ '2' => __('Next two months','dbem'),
199
+ '3' => __('Next three months','dbem'),
200
+ '6' => __('Next six months','dbem'),
201
+ '12' => __('Next twelve months','dbem')
202
+ ));
203
+ ?>
204
+ <?php foreach( $limit_options as $key => $value) : ?>
205
+ <option value='<?php echo $key ?>' <?php echo ($key == get_option('dbem_events_page_time_limit')) ? "selected='selected'" : ''; ?>>
206
+ <?php echo $value; ?>
207
+ </option>
208
+ <?php endforeach; ?>
209
+ </select>
210
+ <br />
211
+ <em><?php _e('Only show events starting within a certain time limit on the events page. Default is no time limit is applied.','dbem'); ?></em>
212
+ </td>
213
+ </tr>
214
+ <?php
215
+ echo $save_button;
216
+ ?>
217
+ </table>
218
+ </div> <!-- . inside -->
219
+ </div> <!-- .postbox -->
220
+
221
+ <div class="postbox " >
222
+ <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Events format', 'dbem' ); ?> </span></h3>
223
+ <div class="inside">
224
+ <table class="form-table">
225
+ <?php
226
+ em_options_textarea ( __( 'Default event list format header', 'dbem' ), 'dbem_event_list_item_format_header', __( 'This content will appear just above your code for the default event list format. Default is blank', 'dbem' ) );
227
+ em_options_textarea ( __( 'Default event list format', 'dbem' ), 'dbem_event_list_item_format', __( 'The format of any events in a list.', 'dbem' ).$events_placeholder_tip );
228
+ em_options_textarea ( __( 'Default event list format footer', 'dbem' ), 'dbem_event_list_item_format_footer', __( 'This content will appear just below your code for the default event list format. Default is blank', 'dbem' ) );
229
+ em_options_input_text ( __( 'Single event page title format', 'dbem' ), 'dbem_event_page_title_format', __( 'The format of a single event page title.', 'dbem' ).$events_placeholder_tip );
230
+ em_options_textarea ( __( 'Default single event format', 'dbem' ), 'dbem_single_event_format', __( 'The format of a single event page.', 'dbem' ).$events_placeholder_tip );
231
+ em_options_input_text ( __( 'Events page title', 'dbem' ), 'dbem_events_page_title', __( 'The title on the multiple events page.', 'dbem' ) );
232
+ em_options_input_text ( __( 'No events message', 'dbem' ), 'dbem_no_events_message', __( 'The message displayed when no events are available.', 'dbem' ) );
233
+ em_options_input_text ( __( 'List events by date title', 'dbem' ), 'dbem_list_date_title', __( 'If viewing a page for events on a specific date, this is the title that would show up. To insert date 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/>', 'dbem' ) );
234
+ echo $save_button;
235
+ ?>
236
+ </table>
237
+ </div> <!-- . inside -->
238
+ </div> <!-- .postbox -->
239
+
240
+ <div class="postbox " >
241
+ <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Calendar format', 'dbem' ); ?></span></h3>
242
+ <div class="inside">
243
+ <table class="form-table">
244
+ <?php
245
+ em_options_input_text ( __( 'Small calendar title', 'dbem' ), 'dbem_small_calendar_event_title_format', __( 'The format of the title, corresponding to the text that appears when hovering on an eventful calendar day.', 'dbem' ).$events_placeholder_tip );
246
+ em_options_input_text ( __( 'Small calendar title separator', 'dbem' ), 'dbem_small_calendar_event_title_separator', __( 'The separator appearing on the above title when more than one events are taking place on the same day.', 'dbem' ) );
247
+ em_options_input_text ( __( 'Full calendar events format', 'dbem' ), 'dbem_full_calendar_event_format', __( 'The format of each event when displayed in the full calendar. Remember to include <code>li</code> tags before and after the event.', 'dbem' ).$events_placeholder_tip );
248
+ em_options_radio_binary ( __( 'Show long events on calendar pages?', 'dbem' ), 'dbem_full_calendar_long_events', __( "If you are showing a calendar on the events page (see Events format section on this page), you have the option of showing events that span over days on each day it occurs.",'dbem' ) );
249
+ em_options_radio_binary ( __( 'Show list on day with single event?', 'dbem' ), 'dbem_display_calendar_day_single', __( "By default, if a calendar day only has one event, it display a single event when clicking on the link of that calendar date. If you select Yes here, you will get always see a list of events.",'dbem' ) );
250
+ echo $save_button;
251
+ ?>
252
+ </table>
253
+ </div> <!-- . inside -->
254
+ </div> <!-- .postbox -->
255
+
256
+ <div class="postbox " >
257
+ <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Locations format', 'dbem' ); ?> </span></h3>
258
+ <div class="inside">
259
+ <table class="form-table">
260
+ <?php
261
+ em_options_input_text ( __( 'Single location page title format', 'dbem' ), 'dbem_location_page_title_format', __( 'The format of a single location page title.', 'dbem' ).$locations_placeholder_tip );
262
+ em_options_textarea ( __( 'Default single location page format', 'dbem' ), 'dbem_single_location_format', __( 'The format of a single location page.', 'dbem' ).$locations_placeholder_tip );
263
+ em_options_textarea ( __( 'Default location balloon format', 'dbem' ), 'dbem_location_baloon_format', __( 'The format of of the text appearing in the baloon describing the location in the map.', 'dbem' ).$locations_placeholder_tip );
264
+ em_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.', 'dbem' ).$locations_placeholder_tip );
265
+ em_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' ) );
266
+ echo $save_button;
267
+ ?>
268
+ </table>
269
+ </div> <!-- . inside -->
270
+ </div> <!-- .postbox -->
271
+
272
+ <div class="postbox " >
273
+ <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'RSS feed format', 'dbem' ); ?> </span></h3>
274
+ <div class="inside">
275
+ <table class="form-table">
276
+ <?php
277
+ em_options_input_text ( __( 'RSS main title', 'dbem' ), 'dbem_rss_main_title', __( 'The main title of your RSS events feed.', 'dbem' ).$events_placeholder_tip );
278
+ em_options_input_text ( __( 'RSS main description', 'dbem' ), 'dbem_rss_main_description', __( 'The main description of your RSS events feed.', 'dbem' ) );
279
+ em_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' ).$events_placeholder_tip );
280
+ em_options_input_text ( __( 'RSS description format', 'dbem' ), 'dbem_rss_description_format', __( 'The format of the description of each item in the events RSS feed.', 'dbem' ).$events_placeholder_tip );
281
+ echo $save_button;
282
+ ?>
283
+ </table>
284
+ </div> <!-- . inside -->
285
+ </div> <!-- .postbox -->
286
+
287
+ <div class="postbox " >
288
+ <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Maps and geotagging', 'dbem' ); ?> </span></h3>
289
+ <div class="inside">
290
+ <table class='form-table'>
291
+ <?php $gmap_is_active = get_option ( 'dbem_gmap_is_active' ); ?>
292
+ <tr valign="top">
293
+ <th scope="row"><?php _e ( 'Enable Google Maps integration?', 'dbem' ); ?></th>
294
+ <td>
295
+ <?php _e ( 'Yes' ); ?> <input id="dbem_gmap_is_active_yes" name="dbem_gmap_is_active" type="radio" value="1" <?php echo ($gmap_is_active) ? "checked='checked'":''; ?> />
296
+ <?php _e ( 'No' ); ?> <input name="dbem_gmap_is_active" type="radio" value="0" <?php echo ($gmap_is_active) ? '':"checked='checked'"; ?> /><br />
297
+ <em><?php _e ( 'Check this option to enable Goggle Map integration.', 'dbem' )?></em>
298
+ </td>
299
+ </tr>
300
+ <?php
301
+ em_options_textarea ( __( 'Map text format', 'dbem' ), 'dbem_map_text_format', __( 'The text format inside the map balloons.', 'dbem' ).$events_placeholder_tip );
302
+ echo $save_button;
303
+ ?>
304
+ </table>
305
+ </div> <!-- . inside -->
306
+ </div> <!-- .postbox -->
307
+
308
+ <div class="postbox " >
309
+ <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'RSVP and bookings', 'dbem' ); ?> </span></h3>
310
+ <div class="inside">
311
+ <table class='form-table'>
312
+ <?php
313
+ em_options_select ( __( 'Default contact person', 'dbem' ), 'dbem_default_contact_person', em_get_wp_users (), __( 'Select the default contact person. This user will be employed whenever a contact person is not explicitly specified for an event', 'dbem' ) );
314
+ em_options_radio_binary ( __( 'Approval Required?', 'dbem' ), 'dbem_bookings_approval', __( 'Bookings will not be confirmed until the event administrator approves it.', 'dbem' ) );
315
+ em_options_input_text ( __( 'Email events admin?', 'dbem' ), 'dbem_bookings_notify_admin', __( "If you would like every event booking confirmation email sent to an administrator write their email here (leave blank to not send an email).", 'dbem' ) );
316
+ em_options_radio_binary ( __( 'Email contact person?', 'dbem' ), 'dbem_bookings_contact_email', __( 'Check this option if you want the event contact to receive an email when someone books places. An email will be sent when a booking is first made (regardless if confirmed or pending)', 'dbem' ) );
317
+ ?>
318
+ <tr><td colspan='2'><h4><?php _e('Contact person booking confirmed','dbem') ?></h4></td></tr>
319
+ <tr><td colspan='2'><?php echo __('An email will be sent to the event contact when a booking is first made.','dbem').$bookings_placeholder_tip ?></td></tr>
320
+ <?php
321
+ em_options_input_text ( __( 'Contact person email subject', 'dbem' ), 'dbem_bookings_contact_email_subject', '' );
322
+ em_options_textarea ( __( 'Contact person email', 'dbem' ), 'dbem_bookings_contact_email_body', '' );
323
+ ?>
324
+ <tr><td colspan='2'><h4><?php _e('Contact person booking cancelled','dbem') ?></h4></td></tr>
325
+ <tr><td colspan='2'><?php echo __('An email will be sent to the event contact if someone cancels their booking.','dbem').$bookings_placeholder_tip ?></td></tr>
326
+ <?php
327
+ em_options_input_text ( __( 'Contact person cancellation subject', 'dbem' ), 'dbem_contactperson_email_cancelled_subject', '' );
328
+ em_options_textarea ( __( 'Contact person cancellation email', 'dbem' ), 'dbem_contactperson_email_cancelled_body', '' );
329
+ ?>
330
+ <tr><td colspan='2'><h4><?php _e('Confirmed booking email','dbem') ?></h4></td></tr>
331
+ <tr><td colspan='2'><?php echo __('This is sent when a person\'s booking is confirmed. This will be sent automatically if approvals are required and the booking is approved. If approvals are disabled, this is sent out when a user first submits their booking.','dbem').$bookings_placeholder_tip ?></td></tr>
332
+ <?php
333
+ em_options_input_text ( __( 'Booking confirmed email subject', 'dbem' ), 'dbem_bookings_email_confirmed_subject', '' );
334
+ em_options_textarea ( __( 'Booking confirmed email', 'dbem' ), 'dbem_bookings_email_confirmed_body', '' );
335
+ ?>
336
+ <tr><td colspan='2'><h4><?php _e('Pending booking email','dbem') ?></h4></td></tr>
337
+ <tr><td colspan='2'><?php echo __( 'This will be sent to the person when they first submit their booking. Not relevant if bookings don\'t require approval.', 'dbem' ).$bookings_placeholder_tip ?></td></tr>
338
+ <?php
339
+ em_options_input_text ( __( 'Booking pending email subject', 'dbem' ), 'dbem_bookings_email_pending_subject', '');
340
+ em_options_textarea ( __( 'Booking pending email', 'dbem' ), 'dbem_bookings_email_pending_body','') ;
341
+ ?>
342
+ <tr><td colspan='2'><h4><?php _e('Rejected booking email','dbem') ?></h4></td></tr>
343
+ <tr><td colspan='2'><?php echo __( 'This will be sent automatically when a booking is rejected. Not relevant if bookings don\'t require approval.', 'dbem' ).$bookings_placeholder_tip ?></td></tr>
344
+ <?php
345
+ em_options_input_text ( __( 'Booking rejected email subject', 'dbem' ), 'dbem_bookings_email_rejected_subject', __( "The subject of the email sent to the person making a booking that is awaiting administrator approval. Not relevant if bookings don't require approval.", 'dbem' ).$bookings_placeholder_tip );
346
+ em_options_textarea ( __( 'Booking rejected email', 'dbem' ), 'dbem_bookings_email_rejected_body', __( 'The body of the email which will be sent to the person if the booking is rejected. Not relevant if bookings don\'t require approval.', 'dbem' ).$bookings_placeholder_tip );
347
+ echo $save_button;
348
+ ?>
349
+ <tr><td colspan='2'><h4><?php _e('Booking cancelled','dbem') ?></h4></td></tr>
350
+ <tr><td colspan='2'><?php echo __('This will be sent when a user cancels their booking.','dbem').$bookings_placeholder_tip ?></td></tr>
351
+ <?php
352
+ em_options_input_text ( __( 'Booking cancelled email subject', 'dbem' ), 'dbem_bookings_email_cancelled_subject', '' );
353
+ em_options_textarea ( __( 'Booking cancelled email', 'dbem' ), 'dbem_bookings_email_cancelled_body', '' );
354
+ ?>
355
+ </table>
356
+ </div> <!-- . inside -->
357
+ </div> <!-- .postbox -->
358
+
359
+ <div class="postbox " >
360
+ <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Email Settings', 'dbem' ); ?> </span></h3>
361
+ <div class="inside">
362
+ <table class='form-table'>
363
+ <?php
364
+ em_options_input_text ( __( 'Notification sender name', 'dbem' ), 'dbem_mail_sender_name', __( "Insert the display name of the notification sender.", 'dbem' ) );
365
+ em_options_input_text ( __( 'Notification sender address', 'dbem' ), 'dbem_mail_sender_address', __( "Insert the address of the notification sender.", 'dbem' ) );
366
+ em_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' ) );
367
+ em_options_select ( __( 'Mail sending method', 'dbem' ), 'dbem_rsvp_mail_send_method', array ('smtp' => 'SMTP', 'mail' => __( 'PHP mail function', 'dbem' ), 'sendmail' => 'Sendmail', 'qmail' => 'Qmail', 'wp_mail' => 'WP Mail' ), __( 'Select the method to send email notification.', 'dbem' ) );
368
+ em_options_radio_binary ( __( 'Use SMTP authentication?', 'dbem' ), 'dbem_rsvp_mail_SMTPAuth', __( 'SMTP authentication is often needed. If you use GMail, make sure to set this parameter to Yes', 'dbem' ) );
369
+ em_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' ) );
370
+ em_options_input_text ( __( 'SMTP username', 'dbem' ), 'dbem_smtp_username', __( "Insert the username to be used to access your SMTP server.", 'dbem' ) );
371
+ em_options_input_password ( __( 'SMTP password', 'dbem' ), "dbem_smtp_password", __( "Insert the password to be used to access your SMTP server", 'dbem' ) );
372
+ echo $save_button;
373
+ ?>
374
+ </table>
375
+ </div> <!-- . inside -->
376
+ </div> <!-- .postbox -->
377
+
378
+ <div class="postbox " >
379
+ <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Images size', 'dbem' ); ?> </span></h3>
380
+ <div class="inside">
381
+ <table class='form-table'>
382
+ <?php
383
+ em_options_input_text ( __( 'Maximum width (px)', 'dbem' ), 'dbem_image_max_width', __( 'The maximum allowed width for images uploades', 'dbem' ) );
384
+ em_options_input_text ( __( 'Maximum height (px)', 'dbem' ), 'dbem_image_max_height', __( "The maximum allowed height for images uploaded, in pixels", 'dbem' ) );
385
+ em_options_input_text ( __( 'Maximum size (bytes)', 'dbem' ), 'dbem_image_max_size', __( "The maximum allowed size for images uploaded, in pixels", 'dbem' ) );
386
+ echo $save_button;
387
+ ?>
388
+ </table>
389
+ </div> <!-- . inside -->
390
+ </div> <!-- .postbox -->
391
+
392
+ <div class="postbox " >
393
+ <div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Management Permission Options', 'dbem' ); ?> (Beta)</span></h3>
394
+ <div class="inside">
395
+ <table class="form-table">
396
+ <tr><td colspan="2">
397
+ <strong><?php _e('Warning: Changing these values may result in exposing previously hidden information to all users.')?></strong><br />
398
+ <em><?php _e('Note that currently "users" are considered as wordpress contributor users upwards, as they can create and manage events (we\'re working on that). Wordpress administrators can control all events/locations/categories/etc. on Events Manager.','dbem'); ?></em>
399
+ </td></tr>
400
+ <tr><th colspan="2"><strong><?php _e('Event Permissions','dbem'); ?></strong></th></tr>
401
+ <?php
402
+ $location_privacy_options = array(
403
+ '0' => __('Every user can create and manage their own events. Users can\'t view or modify each others\' events and booking data','dbem'),
404
+ '1' => __('Every user can create/edit/delete any event on this site. (not recommended)','dbem')
405
+ );
406
+ em_options_radio ( 'dbem_permissions_events', $location_privacy_options );
407
+ ?>
408
+ <tr><th colspan="2"><strong><?php _e('Location Permissions','dbem'); ?></strong></th></tr>
409
+ <?php
410
+ $location_privacy_options = array(
411
+ '0' => __('Every user can create and manage their own location.','dbem')." ".__('In future releases of Events Manager, sharing locations with more than one user will be possible in this option, as well as connecting different user defined locations to prevent duplicate listings.','dbem'),
412
+ '1' => __('Only event administrators can create and edit locations. User must choose from these available locations.','dbem'),
413
+ '2' => __('Everyone can create/edit/delete all locations on this site. (not recommended)','dbem')
414
+ );
415
+ em_options_radio ( 'dbem_permissions_locations', $location_privacy_options );
416
+ ?>
417
+ <tr><th colspan="2"><strong><?php _e('Category Permissions','dbem'); ?></strong></th></tr>
418
+ <?php
419
+ $category_privacy_options = array(
420
+ '0' => __('Every user can create and manage their own category.','dbem'),
421
+ '1' => __('Only event administrators can create and edit categories. User must choose from these available categories.','dbem'),
422
+ '2' => __('Everyone can create/edit/delete all categories on the system. (not recommended)','dbem')
423
+ );
424
+ em_options_radio ( 'dbem_permissions_categories', $category_privacy_options );
425
+ ?>
426
+ </table>
427
+
428
+ </div> <!-- . inside -->
429
+ </div> <!-- .postbox -->
430
+
431
+ <p class="submit">
432
+ <input type="submit" id="dbem_options_submit" name="Submit" value="<?php _e ( 'Save Changes' )?>" />
433
+ <input type="hidden" name="em-submitted" value="1" />
434
+ </p>
435
+
436
+ </div> <!-- .metabox-sortables -->
437
+ </div> <!-- .postbox-container -->
438
+
439
+ </div> <!-- .metabox-holder -->
440
+ </form>
441
+ </div>
442
+ <?php
443
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  ?>
admin/em-people.php CHANGED
@@ -1,10 +1,125 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  function em_printable_booking_report() {
4
  global $EM_Event;
5
  //check that user can access this page
6
  if( isset($_GET['page']) && $_GET['page']=='events-manager-bookings' && isset($_GET['action']) && $_GET['action'] == 'bookings_report' && is_object($EM_Event)){
7
- if( is_object($EM_Event) && !$EM_Event->can_manage('edit_events','edit_others_events') ){
8
  ?>
9
  <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php _e('You do not have the rights to manage this event.','dbem'); ?></p></div>
10
  <?php
@@ -30,28 +145,28 @@ function em_printable_booking_report() {
30
  <th scope='col'><?php _e('Name', 'dbem')?></th>
31
  <th scope='col'><?php _e('E-mail', 'dbem')?></th>
32
  <th scope='col'><?php _e('Phone number', 'dbem')?></th>
33
- <th scope='col'><?php _e('Spaces', 'dbem')?></th>
34
  <th scope='col'><?php _e('Comment', 'dbem')?></th>
35
  </tr>
36
  <?php foreach($EM_Event->get_bookings()->bookings as $EM_Booking) { ?>
37
  <tr>
38
 
39
- <td><?php echo $EM_Booking->person->display_name ?></td>
40
- <td><?php echo $EM_Booking->person->user_email ?></td>
41
  <td><?php echo $EM_Booking->person->phone ?></td>
42
- <td class='spaces-number'><?php echo $EM_Booking->get_spaces() ?></td>
43
  <td><?php echo $EM_Booking->comment ?></td>
44
  </tr>
45
  <?php } ?>
46
- <tr id='booked-spaces'>
47
  <td colspan='3'>&nbsp;</td>
48
  <td class='total-label'><?php _e('Booked', 'dbem')?>:</td>
49
- <td class='spaces-number'><?php echo $EM_Event->get_bookings()->get_booked_spaces(); ?></td>
50
  </tr>
51
- <tr id='available-spaces'>
52
  <td colspan='3'>&nbsp;</td>
53
  <td class='total-label'><?php _e('Available', 'dbem')?>:</td>
54
- <td class='spaces-number'><?php echo $EM_Event->get_bookings()->get_available_spaces(); ?></td>
55
  </tr>
56
  </table>
57
  </div>
1
  <?php
2
+ /**
3
+ * Check for flags to save personal data
4
+ */
5
+ function em_person_actions(){
6
+ global $EM_Person;
7
+ if( !empty($_REQUEST['action']) && is_object($EM_Person) ){
8
+ if( $_REQUEST['action'] == 'edit_person' ){
9
+ $validation = $EM_Person->get_post();
10
+ if ( $validation ) { //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS)
11
+ //Save
12
+ if( $EM_Person->save() ) {
13
+ function em_person_save_notification(){
14
+ global $EM_Person;
15
+ ?><div class="updated"><p><strong><?php echo $EM_Person->feedback_message; ?></strong></p></div><?php
16
+ }
17
+ }else{
18
+ function em_person_save_notification(){
19
+ global $EM_Person;
20
+ ?><div class="error"><p><strong><?php echo $EM_Person->feedback_message; ?></strong></p></div><?php
21
+ }
22
+ }
23
+ }else{
24
+ //TODO make errors clearer when saving person
25
+ function em_person_save_notification(){
26
+ global $EM_Person;
27
+ ?><div class="error"><p><strong><?php echo $EM_Person->feedback_message; ?></strong></p></div><?php
28
+ }
29
+ }
30
+ add_action ( 'admin_notices', 'em_person_save_notification' );
31
+ }
32
+ if( $_REQUEST['action'] == 'person_delete' ){
33
+ if( $EM_Person->delete() ){
34
+ //TODO delete person needs confirmation
35
+ wp_redirect( get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager-bookings');
36
+ exit();
37
+ }else{
38
+ function em_person_delete_notification(){
39
+ global $EM_Person;
40
+ ?><div class="error"><p><strong><?php echo $EM_Person->feedback_message; ?></strong></p></div><?php
41
+ }
42
+ }
43
+ add_action ( 'admin_notices', 'em_person_delete_notification' );
44
+ }
45
+ }
46
+ }
47
+ add_action('admin_init','em_person_actions');
48
+
49
+ /**
50
+ * Generate an edit form for person details.
51
+ */
52
+ function em_person_edit_form(){
53
+ global $EM_Person;
54
+ ?>
55
+ <form action="" method="post" id="em-person-form">
56
+ <table>
57
+ <tr><td><strong><?php _e('Name','dbem'); ?></strong></td><td><input type="text" name="person_name" size="60" value="<?php echo $EM_Person->name; ?>" /></td></tr>
58
+ <tr><td><strong><?php _e('Phone','dbem'); ?></strong></td><td><input type="text" name="person_phone" size="60" value="<?php echo $EM_Person->phone; ?>" /></td></tr>
59
+ <tr><td><strong><?php _e('E-mail','dbem'); ?></strong></td><td><input type="text" name="person_email" size="60" value="<?php echo $EM_Person->email; ?>" /></td></tr>
60
+ </table>
61
+ <p class="submit">
62
+ <input type="submit" name="events_update" value="<?php _e ( 'Save' ); ?> &raquo;" />
63
+ </p>
64
+ <input type="hidden" name="action" value="person_edit" />
65
+ <input type="hidden" name="person_id" value="<?php echo $EM_Person->id; ?>" />
66
+ </form>
67
+ <?php
68
+ }
69
+
70
+ /**
71
+ * Depreciated page... for now at least.
72
+ */
73
+ function em_admin_people_page() {
74
+ ?>
75
+ <div class='wrap'>
76
+ <div id="icon-users" class="icon32"><br/></div>
77
+ <h2>People</h2>
78
+ <?php
79
+ $EM_People = EM_People::get();
80
+ if (count($EM_People) < 1 ) {
81
+ _e("No people have responded to your events yet!", 'dbem');
82
+ } else {
83
+ ?>
84
+ <p><?php _e('This table collects the data about the people who responded to your events', 'dbem') ?></p>
85
+ <table id='dbem-people-table' class='widefat post fixed'>
86
+ <thead>
87
+ <tr>
88
+ <th class='manage-column column-cb check-column' scope='col'>&nbsp;</th>
89
+ <th class='manage-column ' scope='col'>Name</th>
90
+ <th scope='col'>E-mail</th>
91
+ <th scope='col'>Phone number</th>
92
+ </tr>
93
+ </thead>
94
+ <tfoot>
95
+ <tr>
96
+ <th class='manage-column column-cb check-column' scope='col'>&nbsp;</th>
97
+ <th class='manage-column ' scope='col'>Name</th>
98
+ <th scope='col'>E-mail</th>
99
+ <th scope='col'>Phone number</th>
100
+ </tr>
101
+ </tfoot>
102
+ <?php foreach ($EM_People as $EM_Person): ?>
103
+ <tr>
104
+ <td>&nbsp;</td>
105
+ <td><?php echo $EM_Person->name ?></td>
106
+ <td><?php echo $EM_Person->email ?></td>
107
+ <td><?php echo $EM_Person->phone ?></td>
108
+ </tr>
109
+ <?php endforeach; ?>
110
+ </table>
111
+ <?php
112
+ }
113
+ ?>
114
+ </div>
115
+ <?php
116
+ }
117
 
118
  function em_printable_booking_report() {
119
  global $EM_Event;
120
  //check that user can access this page
121
  if( isset($_GET['page']) && $_GET['page']=='events-manager-bookings' && isset($_GET['action']) && $_GET['action'] == 'bookings_report' && is_object($EM_Event)){
122
+ if( is_object($EM_Event) && !$EM_Event->can_manage() ){
123
  ?>
124
  <div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php _e('You do not have the rights to manage this event.','dbem'); ?></p></div>
125
  <?php
145
  <th scope='col'><?php _e('Name', 'dbem')?></th>
146
  <th scope='col'><?php _e('E-mail', 'dbem')?></th>
147
  <th scope='col'><?php _e('Phone number', 'dbem')?></th>
148
+ <th scope='col'><?php _e('Seats', 'dbem')?></th>
149
  <th scope='col'><?php _e('Comment', 'dbem')?></th>
150
  </tr>
151
  <?php foreach($EM_Event->get_bookings()->bookings as $EM_Booking) { ?>
152
  <tr>
153
 
154
+ <td><?php echo $EM_Booking->person->name ?></td>
155
+ <td><?php echo $EM_Booking->person->email ?></td>
156
  <td><?php echo $EM_Booking->person->phone ?></td>
157
+ <td class='seats-number'><?php echo $EM_Booking->seats ?></td>
158
  <td><?php echo $EM_Booking->comment ?></td>
159
  </tr>
160
  <?php } ?>
161
+ <tr id='booked-seats'>
162
  <td colspan='3'>&nbsp;</td>
163
  <td class='total-label'><?php _e('Booked', 'dbem')?>:</td>
164
+ <td class='seats-number'><?php echo $EM_Event->get_bookings()->get_booked_seats(); ?></td>
165
  </tr>
166
+ <tr id='available-seats'>
167
  <td colspan='3'>&nbsp;</td>
168
  <td class='total-label'><?php _e('Available', 'dbem')?>:</td>
169
+ <td class='seats-number'><?php echo $EM_Event->get_bookings()->get_available_seats(); ?></td>
170
  </tr>
171
  </table>
172
  </div>
buddypress/bp-em-activity.php DELETED
@@ -1,106 +0,0 @@
1
- <?php
2
- /**
3
- * bp_em_record_activity()
4
- *
5
- * If the activity stream component is installed, this function will record activity items for your
6
- * component.
7
- *
8
- * You must pass the function an associated array of arguments:
9
- *
10
- * $args = array(
11
- * REQUIRED PARAMS
12
- * 'action' => For em: "Andy high-fived John", "Andy posted a new update".
13
- * 'type' => The type of action being carried out, for em 'new_friendship', 'joined_group'. This should be unique within your component.
14
- *
15
- * OPTIONAL PARAMS
16
- * 'id' => The ID of an existing activity item that you want to update.
17
- * 'content' => The content of your activity, if it has any, for em a photo, update content or blog post excerpt.
18
- * 'component' => The slug of the component.
19
- * 'primary_link' => The link for the title of the item when appearing in RSS feeds (defaults to the activity permalink)
20
- * 'item_id' => The ID of the main piece of data being recorded, for em a group_id, user_id, forum_post_id - useful for filtering and deleting later on.
21
- * 'user_id' => The ID of the user that this activity is being recorded for. Pass false if it's not for a user.
22
- * 'recorded_time' => (optional) The time you want to set as when the activity was carried out (defaults to now)
23
- * 'hide_sitewide' => Should this activity item appear on the site wide stream?
24
- * 'secondary_item_id' => (optional) If the activity is more complex you may need a second ID. For em a group forum post may need the group_id AND the forum_post_id.
25
- * )
26
- *
27
- * Events usage would be:
28
- *
29
- * bp_em_record_activity( array( 'type' => 'new_highfive', 'action' => 'Andy high-fived John', 'user_id' => $bp->loggedin_user->id, 'item_id' => $bp->displayed_user->id ) );
30
- *
31
- */
32
- function bp_em_record_activity( $args = '' ) {
33
- if ( !function_exists( 'bp_activity_add' ) )
34
- return false;
35
-
36
- $defaults = array(
37
- 'id' => false,
38
- 'user_id' => '',
39
- 'action' => '',
40
- 'content' => '',
41
- 'primary_link' => '',
42
- 'component' => 'events-manager',
43
- 'type' => false,
44
- 'item_id' => false,
45
- 'secondary_item_id' => false,
46
- 'recorded_time' => gmdate( "Y-m-d H:i:s" ),
47
- 'hide_sitewide' => false
48
- );
49
-
50
- $r = wp_parse_args( $args, $defaults );
51
- extract( $r );
52
-
53
- return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
54
- }
55
-
56
- /**
57
- * Records new events to the activity stream.
58
- * @param unknown_type $result
59
- * @param unknown_type $EM_Event
60
- * @return unknown
61
- */
62
- function bp_em_record_activity_event_save( $result, $EM_Event ){
63
- if( $result && $EM_Event->status == 1 && ($EM_Event->previous_status == 0 || !empty($EM_Event->is_new)) ){
64
- $user = get_userdata($EM_Event->owner);
65
- bp_em_record_activity( array(
66
- 'user_id' => $user->ID,
67
- 'action' => sprintf(__('%s added a the event %s','dbem'), "<a href='".get_bloginfo('wpurl').'/'.BP_MEMBERS_SLUG.'/'.$user->user_login."/'>".$user->display_name."</a>", $EM_Event->output('#_EVENTLINK') ),
68
- 'primary_link' => $EM_Event->output('#_EVENTURL'),
69
- 'type' => 'new_event',
70
- 'item_id' => $EM_Event->id,
71
- ));
72
- }
73
- return $result;
74
- }
75
- add_filter('em_event_save','bp_em_record_activity_event_save', 10, 2);
76
-
77
- /**
78
- * @param boolean $result
79
- * @param EM_Booking $EM_Booking
80
- * @return boolean
81
- */
82
- function bp_em_record_activity_booking_save( $result, $EM_Booking ){
83
- if( $result ){
84
- $user = $EM_Booking->person;
85
- $user_link = "<a href='".get_bloginfo('wpurl').'/'.BP_MEMBERS_SLUG.'/'.$user->user_login."/'>".$user->display_name."</a>";
86
- $event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
87
- $status = $EM_Booking->status;
88
- if( $status == 1 || (!get_option('dbem_bookings_approval') && $status < 2) ){
89
- $action = sprintf(__('%s is attending %s.','dbem'), $user_link, $event_link );
90
- }elseif( ($EM_Booking->previous_status == 1 || (!get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2)) && $status > 1 ){
91
- $action = sprintf(__('%s will not be attending %s anymore.','dbem'), $user_link, $event_link );
92
- }
93
- if( !empty($action) ){
94
- bp_em_record_activity( array(
95
- 'user_id' => $EM_Booking->person->ID,
96
- 'action' => $action,
97
- 'primary_link' => $EM_Booking->get_event()->output('#_EVENTURL'),
98
- 'type' => 'new_booking',
99
- 'item_id' => $EM_Event->id,
100
- 'secondary_item_id' => $EM_Booking->id
101
- ));
102
- }
103
- }
104
- return $result;
105
- }
106
- add_filter('em_booking_save','bp_em_record_activity_booking_save', 10, 2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buddypress/bp-em-admin.php DELETED
@@ -1,65 +0,0 @@
1
- <?php
2
-
3
- /***
4
- * This file is used to add site administration menus to the WordPress backend.
5
- *
6
- * If you need to provide configuration options for your component that can only
7
- * be modified by a site administrator, this is the best place to do it.
8
- *
9
- * However, if your component has settings that need to be configured on a user
10
- * by user basis - it's best to hook into the front end "Settings" menu.
11
- */
12
-
13
- /**
14
- * bp_em_admin()
15
- *
16
- * Checks for form submission, saves component settings and outputs admin screen HTML.
17
- */
18
- function bp_em_admin() {
19
- global $bp;
20
-
21
- /* If the form has been submitted and the admin referrer checks out, save the settings */
22
- if ( isset( $_POST['submit'] ) && check_admin_referer('em-settings') ) {
23
- update_option( 'em-setting-one', $_POST['em-setting-one'] );
24
- update_option( 'em-setting-two', $_POST['em-setting-two'] );
25
-
26
- $updated = true;
27
- }
28
-
29
- $setting_one = get_option( 'em-setting-one' );
30
- $setting_two = get_option( 'em-setting-two' );
31
- ?>
32
- <div class="wrap">
33
- <h2><?php _e( 'Events Admin', 'bp-em' ) ?></h2>
34
- <br />
35
-
36
- <?php if ( isset($updated) ) : ?><?php echo "<div id='message' class='updated fade'><p>" . __( 'Settings Updated.', 'bp-em' ) . "</p></div>" ?><?php endif; ?>
37
-
38
- <form action="<?php echo site_url() . '/wp-admin/admin.php?page=bp-em-settings' ?>" name="em-settings-form" id="em-settings-form" method="post">
39
-
40
- <table class="form-table">
41
- <tr valign="top">
42
- <th scope="row"><label for="target_uri"><?php _e( 'Option One', 'bp-em' ) ?></label></th>
43
- <td>
44
- <input name="em-setting-one" type="text" id="em-setting-one" value="<?php echo attribute_escape( $setting_one ); ?>" size="60" />
45
- </td>
46
- </tr>
47
- <th scope="row"><label for="target_uri"><?php _e( 'Option Two', 'bp-em' ) ?></label></th>
48
- <td>
49
- <input name="em-setting-two" type="text" id="em-setting-two" value="<?php echo attribute_escape( $setting_two ); ?>" size="60" />
50
- </td>
51
- </tr>
52
- </table>
53
- <p class="submit">
54
- <input type="submit" name="submit" value="<?php _e( 'Save Settings', 'bp-em' ) ?>"/>
55
- </p>
56
-
57
- <?php
58
- /* This is very important, don't leave it out. */
59
- wp_nonce_field( 'em-settings' );
60
- ?>
61
- </form>
62
- </div>
63
- <?php
64
- }
65
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buddypress/bp-em-core.php DELETED
@@ -1,175 +0,0 @@
1
- <?php
2
- // Define a slug constant that will be used to view this components pages
3
- if ( !defined( 'BP_EM_SLUG' ) )
4
- define ( 'BP_EM_SLUG', 'events' );
5
-
6
- //Include component files
7
- require ( dirname( __FILE__ ) . '/bp-em-activity.php' ); /* The notifications file should contain functions to send email notifications on specific user actions */
8
- require ( dirname( __FILE__ ) . '/bp-em-templatetags.php' ); /* The templatetags file should contain classes and functions designed for use in template files */
9
- require ( dirname( __FILE__ ) . '/bp-em-notifications.php' ); /* The notifications file should contain functions to send email notifications on specific user actions */
10
- //Screens
11
- include( dirname( __FILE__ ). '/screens/settings.php');
12
- include( dirname( __FILE__ ). '/screens/profile.php');
13
- include( dirname( __FILE__ ). '/screens/my-events.php');
14
- include( dirname( __FILE__ ). '/screens/my-locations.php');
15
- include( dirname( __FILE__ ). '/screens/attending.php');
16
-
17
-
18
- /**
19
- * bp_em_setup_globals()
20
- *
21
- * Sets up global variables for your component.
22
- */
23
- function bp_em_setup_globals() {
24
- global $bp, $wpdb;
25
- $bp->events = new stdClass();
26
- $bp->events->id = 'events';
27
- //$bp->events->table_name = $wpdb->base_prefix . 'bp_em';
28
- $bp->events->format_notification_function = 'bp_em_format_notifications';
29
- $bp->events->slug = BP_EM_SLUG;
30
- /* Register this in the active components array */
31
- $bp->active_components[$bp->events->slug] = $bp->events->id;
32
- //quick link shortcut
33
- $bp->events->link = trailingslashit($bp->loggedin_user->domain).'events/';
34
- }
35
- add_action( 'wp', 'bp_em_setup_globals', 2 );
36
- //add_action( 'admin_menu', 'bp_em_setup_globals', 2 );
37
-
38
- /**
39
- * bp_em_setup_nav()
40
- *
41
- * Sets up the user profile navigation items for the component. This adds the top level nav
42
- * item and all the sub level nav items to the navigation array. This is then
43
- * rendered in the template.
44
- */
45
- function bp_em_setup_nav() {
46
- global $bp;
47
-
48
- /* Add 'Events' to the main user profile navigation */
49
- bp_core_new_nav_item( array(
50
- 'name' => __( 'Events', 'bp-em' ),
51
- 'slug' => $bp->events->slug,
52
- 'position' => 80,
53
- 'screen_function' => bp_is_my_profile() ? 'bp_em_my_events':'bp_em_events',
54
- 'default_subnav_slug' => bp_is_my_profile() ? 'my-events':''
55
- ) );
56
-
57
- $em_link = $bp->loggedin_user->domain . $bp->events->slug . '/';
58
-
59
- if( bp_is_my_profile() ){
60
- /* Create two sub nav items for this component */
61
- bp_core_new_subnav_item( array(
62
- 'name' => __( 'My Profile', 'dbem' ),
63
- 'slug' => 'profile',
64
- 'parent_slug' => $bp->events->slug,
65
- 'parent_url' => $em_link,
66
- 'screen_function' => 'bp_em_events',
67
- 'position' => 10
68
- ) );
69
- }
70
-
71
- bp_core_new_subnav_item( array(
72
- 'name' => __( 'Events I\'m Attending', 'dbem' ),
73
- 'slug' => 'attending',
74
- 'parent_slug' => $bp->events->slug,
75
- 'parent_url' => $em_link,
76
- 'screen_function' => 'bp_em_attending',
77
- 'position' => 20,
78
- 'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
79
- ) );
80
-
81
- bp_core_new_subnav_item( array(
82
- 'name' => __( 'My Events', 'dbem' ),
83
- 'slug' => 'my-events',
84
- 'parent_slug' => $bp->events->slug,
85
- 'parent_url' => $em_link,
86
- 'screen_function' => 'bp_em_my_events',
87
- 'position' => 30,
88
- 'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
89
- ) );
90
-
91
- bp_core_new_subnav_item( array(
92
- 'name' => __( 'My Locations', 'dbem' ),
93
- 'slug' => 'my-locations',
94
- 'parent_slug' => $bp->events->slug,
95
- 'parent_url' => $em_link,
96
- 'screen_function' => 'bp_em_my_locations',
97
- 'position' => 40,
98
- 'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
99
- ) );
100
-
101
- /* Add a nav item for this component under the settings nav item. */
102
- bp_core_new_subnav_item( array(
103
- 'name' => __( 'Events', 'dbem' ),
104
- 'slug' => 'events-settings',
105
- 'parent_slug' => $bp->settings->slug,
106
- 'parent_url' => $bp->loggedin_user->domain . $bp->settings->slug . '/',
107
- 'screen_function' => 'bp_em_screen_settings_menu',
108
- 'position' => 40,
109
- 'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
110
- ) );
111
- }
112
-
113
- /***
114
- * In versions of BuddyPress 1.2.2 and newer you will be able to use:
115
- * add_action( 'bp_setup_nav', 'bp_example_setup_nav' );
116
- */
117
- add_action( 'wp', 'bp_em_setup_nav', 2 );
118
- add_action( 'admin_menu', 'bp_em_setup_nav', 2 );
119
-
120
- /**
121
- * bp_em_load_template_filter()
122
- *
123
- * You can define a custom load template filter for your component. This will allow
124
- * you to store and load template files from your plugin directory.
125
- *
126
- * This will also allow users to override these templates in their active theme and
127
- * replace the ones that are stored in the plugin directory.
128
- *
129
- * If you're not interested in using template files, then you don't need this function.
130
- *
131
- * This will become clearer in the function bp_em_screen_one() when you want to load
132
- * a template file.
133
- */
134
- function bp_em_load_template_filter( $found_template, $templates ) {
135
- global $bp;
136
-
137
- /**
138
- * Only filter the template location when we're on the em component pages.
139
- */
140
- if ( $bp->current_component != $bp->events->slug )
141
- return $found_template;
142
-
143
- foreach ( (array) $templates as $template ) {
144
- if ( file_exists( STYLESHEETPATH . '/' . $template ) )
145
- $filtered_templates[] = STYLESHEETPATH . '/' . $template;
146
- else
147
- $filtered_templates[] = dirname( __FILE__ ) . '/templates/' . $template;
148
- }
149
-
150
- $found_template = $filtered_templates[0];
151
-
152
- return apply_filters( 'bp_em_load_template_filter', $found_template );
153
- }
154
- add_filter( 'bp_located_template', 'bp_em_load_template_filter', 10, 2 );
155
-
156
- /**
157
- * Remove a screen notification for a user.
158
- */
159
- function bp_em_remove_screen_notifications() {
160
- global $bp;
161
- bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->events->slug, 'attending' );
162
- }
163
- add_action( 'bp_em_my_events', 'bp_em_remove_screen_notifications' );
164
- add_action( 'xprofile_screen_display_profile', 'bp_em_remove_screen_notifications' );
165
-
166
- /**
167
- * Delete events when you delete a user.
168
- */
169
- function bp_em_remove_data( $user_id ) {
170
- $EM_Events = EM_Events::get(array('scope'=>'all','owner'=>$user_id, 'status'=>false));
171
- EM_Events::delete($EM_Events);
172
- }
173
- add_action( 'wpmu_delete_user', 'bp_em_remove_data', 1 );
174
- add_action( 'delete_user', 'bp_em_remove_data', 1 );
175
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buddypress/bp-em-notifications.php DELETED
@@ -1,157 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Notification functions are used to send email notifications to users on specific events
5
- * They will check to see the users notification settings first, if the user has the notifications
6
- * turned on, they will be sent a formatted email notification.
7
- *
8
- * You should use your own custom actions to determine when an email notification should be sent.
9
- */
10
-
11
- function bp_em_send_high_five_notification( $to_user_id, $from_user_id ) {
12
- global $bp;
13
-
14
- /* Let's grab both user's names to use in the email. */
15
- $sender_name = bp_core_get_user_displayname( $from_user_id, false );
16
- $reciever_name = bp_core_get_user_displayname( $to_user_id, false );
17
-
18
- /* We need to check to see if the recipient has opted not to recieve high-five emails */
19
- if ( 'no' == get_usermeta( (int)$to_user_id, 'notification_em_new_high_five' ) )
20
- return false;
21
-
22
- /* Get the userdata for the reciever and sender, this will include usernames and emails that we need. */
23
- $reciever_ud = get_userdata( $to_user_id );
24
- $sender_ud = get_userdata( $from_user_id );
25
-
26
- /* Now we need to construct the URL's that we are going to use in the email */
27
- $sender_profile_link = site_url( BP_MEMBERS_SLUG . '/' . $sender_ud->user_login . '/' . $bp->profile->slug );
28
- $sender_highfive_link = site_url( BP_MEMBERS_SLUG . '/' . $sender_ud->user_login . '/' . $bp->events->slug . '/screen-one' );
29
- $reciever_settings_link = site_url( BP_MEMBERS_SLUG . '/' . $reciever_ud->user_login . '/settings/notifications' );
30
-
31
- /* Set up and send the message */
32
- $to = $reciever_ud->user_email;
33
- $subject = '[' . get_blog_option( 1, 'blogname' ) . '] ' . sprintf( __( '%s high-fived you!', 'bp-em' ), stripslashes($sender_name) );
34
-
35
- $message = sprintf( __(
36
- '%s sent you a high-five! Why not send one back?
37
-
38
- To see %s\'s profile: %s
39
-
40
- To send %s a high five: %s
41
-
42
- ---------------------
43
- ', 'bp-em' ), $sender_name, $sender_name, $sender_profile_link, $sender_name, $sender_highfive_link );
44
-
45
- $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'bp-em' ), $reciever_settings_link );
46
-
47
- // Send it!
48
- wp_mail( $to, $subject, $message );
49
- }
50
- add_action( 'bp_em_send_high_five', 'bp_em_send_high_five_notification', 10, 2 );
51
-
52
-
53
- /********************************************************************************
54
- * Activity & Notification Functions
55
- *
56
- * These functions handle the recording, deleting and formatting of activity and
57
- * notifications for the user and for this specific component.
58
- */
59
-
60
-
61
- /**
62
- * bp_em_screen_notification_settings()
63
- *
64
- * Adds notification settings for the component, so that a user can turn off email
65
- * notifications set on specific component actions.
66
- */
67
- function bp_em_screen_notification_settings() {
68
- global $current_user;
69
-
70
- /**
71
- * Under Settings > Notifications within a users profile page they will see
72
- * settings to turn off notifications for each component.
73
- *
74
- * You can plug your custom notification settings into this page, so that when your
75
- * component is active, the user will see options to turn off notifications that are
76
- * specific to your component.
77
- */
78
-
79
- /**
80
- * Each option is stored in a posted array notifications[SETTING_NAME]
81
- * When saved, the SETTING_NAME is stored as usermeta for that user.
82
- *
83
- * For em, notifications[notification_friends_friendship_accepted] could be
84
- * used like this:
85
- *
86
- * if ( 'no' == get_usermeta( $bp['loggedin_userid], 'notification_friends_friendship_accepted' ) )
87
- * // don't send the email notification
88
- * else
89
- * // send the email notification.
90
- */
91
-
92
- ?>
93
- <table class="notification-settings" id="bp-em-notification-settings">
94
- <tr>
95
- <th class="icon"></th>
96
- <th class="title"><?php _e( 'Events', 'bp-em' ) ?></th>
97
- <th class="yes"><?php _e( 'Yes', 'bp-em' ) ?></th>
98
- <th class="no"><?php _e( 'No', 'bp-em' )?></th>
99
- </tr>
100
- <tr>
101
- <td></td>
102
- <td><?php _e( 'Action One', 'bp-em' ) ?></td>
103
- <td class="yes"><input type="radio" name="notifications[notification_em_action_one]" value="yes" <?php if ( !get_usermeta( $current_user->id,'notification_em_action_one') || 'yes' == get_usermeta( $current_user->id,'notification_em_action_one') ) { ?>checked="checked" <?php } ?>/></td>
104
- <td class="no"><input type="radio" name="notifications[notification_em_action_one]" value="no" <?php if ( get_usermeta( $current_user->id,'notification_em_action_one') == 'no' ) { ?>checked="checked" <?php } ?>/></td>
105
- </tr>
106
- <tr>
107
- <td></td>
108
- <td><?php _e( 'Action Two', 'bp-em' ) ?></td>
109
- <td class="yes"><input type="radio" name="notifications[notification_em_action_two]" value="yes" <?php if ( !get_usermeta( $current_user->id,'notification_em_action_two') || 'yes' == get_usermeta( $current_user->id,'notification_em_action_two') ) { ?>checked="checked" <?php } ?>/></td>
110
- <td class="no"><input type="radio" name="notifications[notification_em_action_two]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id,'notification_em_action_two') ) { ?>checked="checked" <?php } ?>/></td>
111
- </tr>
112
-
113
- <?php do_action( 'bp_em_notification_settings' ); ?>
114
- </table>
115
- <?php
116
- }
117
- add_action( 'bp_notification_settings', 'bp_em_screen_notification_settings' );
118
-
119
- /**
120
- * bp_em_format_notifications()
121
- *
122
- * The format notification function will take DB entries for notifications and format them
123
- * so that they can be displayed and read on the screen.
124
- *
125
- * Notifications are "screen" notifications, that is, they appear on the notifications menu
126
- * in the site wide navigation bar. They are not for email notifications.
127
- *
128
- *
129
- * The recording is done by using bp_core_add_notification() which you can search for in this file for
130
- * ems of usage.
131
- */
132
- function bp_em_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
133
- global $bp;
134
-
135
- switch ( $action ) {
136
- case 'new_high_five':
137
- /* In this case, $item_id is the user ID of the user who sent the high five. */
138
-
139
- /***
140
- * We don't want a whole list of similar notifications in a users list, so we group them.
141
- * If the user has more than one action from the same component, they are counted and the
142
- * notification is rendered differently.
143
- */
144
- if ( (int)$total_items > 1 ) {
145
- return apply_filters( 'bp_em_multiple_new_high_five_notification', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/screen-one/" title="' . __( 'Multiple high-fives', 'bp-em' ) . '">' . sprintf( __( '%d new high-fives, multi-five!', 'bp-em' ), (int)$total_items ) . '</a>', $total_items );
146
- } else {
147
- $user_fullname = bp_core_get_user_displayname( $item_id, false );
148
- $user_url = bp_core_get_userurl( $item_id );
149
- return apply_filters( 'bp_em_single_new_high_five_notification', '<a href="' . $user_url . '?new" title="' . $user_fullname .'\'s profile">' . sprintf( __( '%s sent you a high-five!', 'bp-em' ), $user_fullname ) . '</a>', $user_fullname );
150
- }
151
- break;
152
- }
153
-
154
- do_action( 'bp_em_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
155
-
156
- return false;
157
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buddypress/bp-em-templatetags.php DELETED
@@ -1,7 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * In this file you should define template tag functions that end users can add to their template files.
5
- * Each template tag function should echo the final data so that it will output the required information
6
- * just by calling the function name.
7
- */
 
 
 
 
 
 
 
buddypress/screens/attending.php DELETED
@@ -1,40 +0,0 @@
1
- <?php
2
- /**
3
- * bp_em_screen_two()
4
- *
5
- * Sets up and displays the screen output for the sub nav item "em/screen-two"
6
- */
7
- function bp_em_attending() {
8
- global $bp;
9
- /**
10
- * If the user has not Accepted or Rejected anything, then the code above will not run,
11
- * we can continue and load the template.
12
- */
13
- do_action( 'bp_em_attending' );
14
-
15
- add_action( 'bp_template_title', 'bp_em_attending_title' );
16
- add_action( 'bp_template_content', 'bp_em_attending_content' );
17
-
18
- /* Finally load the plugin template file. */
19
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
20
- }
21
-
22
- function bp_em_attending_title() {
23
- _e( 'Attending', 'bp-em' );
24
- }
25
-
26
- function bp_em_attending_content() {
27
- global $bp;
28
- $EM_Person = new EM_Person($bp->displayed_user->id);
29
- $events = $EM_Person->get_events();
30
- $args = array(
31
- 'format_header' => get_option('dbem_bp_events_list_format_header'),
32
- 'format' => get_option('dbem_bp_events_list_format'),
33
- 'format_footer' => get_option('dbem_bp_events_list_format_footer')
34
- );
35
- if( count($events) > 0 ){
36
- echo EM_Events::output($events, $args);
37
- }else{
38
- echo get_option('dbem_bp_events_list_none_format');
39
- }
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buddypress/screens/my-events.php DELETED
@@ -1,65 +0,0 @@
1
- <?php
2
- /**
3
- * Controller for the event views in BP (using mvc terms here)
4
- */
5
- function bp_em_my_events() {
6
- global $bp, $EM_Event;
7
- if( !is_object($EM_Event) && !empty($_REQUEST['event_id']) ){
8
- $EM_Event = new EM_Event($_REQUEST['event_id']);
9
- }
10
-
11
- do_action( 'bp_em_my_events' );
12
-
13
- //plug into EM admin code (at least for now)
14
- include_once(EM_DIR.'/admin/em-admin.php');
15
- em_admin_load_scripts();
16
- add_action('wp_head','em_admin_general_script');
17
-
18
- $template_title = 'bp_em_my_events_title';
19
- $template_content = 'bp_em_my_events_content';
20
-
21
- if( count($bp->action_variables) > 0 ){
22
- if( is_object($EM_Event) && !$EM_Event->can_manage('edit_events','edit_others_events') ) return false;
23
- if( !empty($bp->action_variables[0]) ){
24
- switch($bp->action_variables[0]){
25
- case 'edit':
26
- $template_title = 'bp_em_my_events_editor_title';
27
- $template_content = 'bp_em_my_events_editor';
28
- break;
29
- }
30
- }
31
- }
32
-
33
- add_action( 'bp_template_title', $template_title );
34
- add_action( 'bp_template_content', $template_content );
35
-
36
- /* Finally load the plugin template file. */
37
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
38
- }
39
-
40
- function bp_em_my_events_title() {
41
- _e( 'My Events', 'dbem' );
42
- }
43
-
44
- /**
45
- * Determines whether to show event page or events page, and saves any updates to the event or events
46
- * @return null
47
- */
48
- function bp_em_my_events_content() {
49
- em_locate_template('buddypress/events/my-events.php', true);
50
- }
51
-
52
- function bp_em_my_events_editor_title() {
53
- global $EM_Event;
54
- if( is_object($EM_Event) ){
55
- _e( 'Edit Event', 'dbem' );
56
- }else{
57
- _e( 'Add Event', 'dbem' );
58
- }
59
- }
60
-
61
- function bp_em_my_events_editor(){
62
- em_locate_template('forms/events/editor.php', true);
63
- }
64
-
65
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buddypress/screens/my-locations.php DELETED
@@ -1,72 +0,0 @@
1
- <?php
2
- /**
3
- * Controller for the location views in BP (using mvc terms here)
4
- */
5
- function bp_em_my_locations() {
6
- global $bp, $EM_Location;
7
- if( !is_object($EM_Location) && !empty($_REQUEST['location_id']) ){
8
- $EM_Location = new EM_Location($_REQUEST['location_id']);
9
- }
10
-
11
- do_action( 'bp_em_my_locations' );
12
-
13
- //plug into EM admin code (at least for now)
14
- include_once(EM_DIR.'/admin/em-admin.php');
15
- em_admin_load_scripts();
16
- add_action('wp_head','em_admin_general_script');
17
-
18
- $template_title = 'bp_em_my_locations_title';
19
- $template_content = 'bp_em_my_locations_content';
20
-
21
- if( count($bp->action_variables) > 0 ){
22
- if( is_object($EM_Location) && !$EM_Location->can_manage('edit_locations','edit_others_locations') ) return false;
23
- if( !empty($bp->action_variables[0]) ){
24
- switch($bp->action_variables[0]){
25
- case 'edit':
26
- $template_title = 'bp_em_my_locations_editor_title';
27
- $template_content = 'bp_em_my_locations_editor_content';
28
- break;
29
- default :
30
- $template_title = 'bp_em_my_locations_title';
31
- $template_content = 'bp_em_my_locations_content';
32
- break;
33
- }
34
- }else{
35
- $template_title = 'bp_em_my_locations_title';
36
- $template_content = 'bp_em_my_locations_content';
37
- }
38
- }
39
-
40
- add_action( 'bp_template_title', $template_title );
41
- add_action( 'bp_template_content', $template_content );
42
-
43
- /* Finally load the plugin template file. */
44
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
45
- }
46
-
47
- function bp_em_my_locations_title() {
48
- _e( 'My Locations', 'dbem' );
49
- }
50
-
51
- /**
52
- * Determines whether to show location page or locations page, and saves any updates to the location or locations
53
- * @return null
54
- */
55
- function bp_em_my_locations_content() {
56
- em_locate_template('buddypress/locations/my-locations.php', true);
57
- }
58
-
59
- function bp_em_my_locations_editor_title() {
60
- global $EM_Location;
61
- if( is_object($EM_Location) ){
62
- _e( 'Edit Location', 'dbem' );
63
- }else{
64
- _e( 'Add Location', 'dbem' );
65
- }
66
- }
67
-
68
- function bp_em_my_locations_editor_content(){
69
- em_locate_template('forms/locations/editor.php', true);
70
- }
71
-
72
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buddypress/screens/profile.php DELETED
@@ -1,54 +0,0 @@
1
- <?php
2
- /**
3
- * bp_em_screen_one()
4
- *
5
- * Sets up and displays the screen output for the sub nav item "em/screen-one"
6
- */
7
- function bp_em_events() {
8
- global $bp, $EM_Notices;
9
-
10
- if( bp_is_my_profile() ){
11
- $EM_Notices->add_info( __('You are currently viewing your public page, this is what other users will see.', 'dbem') );
12
- }
13
-
14
- /* Add a do action here, so your component can be extended by others. */
15
- do_action( 'bp_em_events' );
16
-
17
- add_action( 'bp_template_title', 'bp_em_events_title' );
18
- add_action( 'bp_template_content', 'bp_em_events_content' );
19
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
20
- //bp_core_load_template( apply_filters( 'bp_em_template_screen_one', 'em/screen-one' ) );
21
- }
22
- /***
23
- * The second argument of each of the above add_action() calls is a function that will
24
- * display the corresponding information. The functions are presented below:
25
- */
26
- function bp_em_events_title() {
27
- _e( 'Events', 'bp-em' );
28
- }
29
-
30
- function bp_em_events_content() {
31
- global $bp, $EM_Notices;
32
- echo $EM_Notices;
33
- ?>
34
- <h4><?php _e('My Events', 'dbem'); ?></h4>
35
- <?php
36
- $events = EM_Events::get(array('owner'=>$bp->displayed_user->id));
37
- if( count($events) > 0 ){
38
- $args = array(
39
- 'format_header' => get_option('dbem_bp_events_list_format_header'),
40
- 'format' => get_option('dbem_bp_events_list_format'),
41
- 'format_footer' => get_option('dbem_bp_events_list_format_footer'),
42
- 'owner' => $bp->displayed_user->id
43
- );
44
- echo EM_Events::output($events, $args);
45
- }else{
46
- ?>
47
- <p><?php _e('No Events', 'dbem'); ?></p>
48
- <?php
49
- }
50
- ?>
51
- <h4><?php _e("Events I'm Attending", 'dbem'); ?></h4>
52
- <?php
53
- bp_em_attending_content();
54
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buddypress/screens/settings.php DELETED
@@ -1,56 +0,0 @@
1
- <?php
2
- function bp_em_settings() {
3
- global $bp, $current_user, $bp_settings_updated, $pass_error;
4
-
5
- if ( isset( $_POST['submit'] ) ) {
6
- /* Check the nonce */
7
- check_admin_referer('bp-em-admin');
8
-
9
- $bp_settings_updated = true;
10
-
11
- /**
12
- * This is when the user has hit the save button on their settings.
13
- * The best place to store these settings is in wp_usermeta.
14
- */
15
- update_usermeta( $bp->loggedin_user->id, 'bp-em-option-one', attribute_escape( $_POST['bp-em-option-one'] ) );
16
- }
17
-
18
- add_action( 'bp_template_content_header', 'bp_em_screen_settings_menu_header' );
19
- add_action( 'bp_template_title', 'bp_em_screen_settings_menu_title' );
20
- add_action( 'bp_template_content', 'bp_em_screen_settings_menu_content' );
21
-
22
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'plugin-template' ) );
23
- }
24
-
25
- function bp_em_screen_settings_menu_header() {
26
- _e( 'Events Settings Header', 'bp-em' );
27
- }
28
-
29
- function bp_em_screen_settings_menu_title() {
30
- _e( 'Events Settings', 'bp-em' );
31
- }
32
-
33
- function bp_em_screen_settings_menu_content() {
34
- global $bp, $bp_settings_updated; ?>
35
-
36
- <?php if ( $bp_settings_updated ) { ?>
37
- <div id="message" class="updated fade">
38
- <p><?php _e( 'Changes Saved.', 'bp-em' ) ?></p>
39
- </div>
40
- <?php } ?>
41
-
42
- <form action="<?php echo $bp->loggedin_user->domain . 'settings/events'; ?>" name="bp-em-admin-form" id="account-delete-form" class="bp-em-admin-form" method="post">
43
-
44
- <input type="checkbox" name="bp-em-option-one" id="bp-em-option-one" value="1"<?php if ( '1' == get_usermeta( $bp->loggedin_user->id, 'bp-em-option-one' ) ) : ?> checked="checked"<?php endif; ?> /> <?php _e( 'Do you love clicking checkboxes?', 'bp-em' ); ?>
45
- <p class="submit">
46
- <input type="submit" value="<?php _e( 'Save Settings', 'bp-em' ) ?> &raquo;" id="submit" name="submit" />
47
- </p>
48
-
49
- <?php
50
- /* This is very important, don't leave it out. */
51
- wp_nonce_field( 'bp-em-admin' );
52
- ?>
53
-
54
- </form>
55
- <?php
56
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/em-booking.php CHANGED
@@ -1,544 +1,379 @@
1
- <?php
2
- class EM_Booking extends EM_Object{
3
- //DB Fields
4
- var $id;
5
- var $event_id;
6
- var $person_id;
7
- var $price;
8
- var $spaces;
9
- var $comment;
10
- var $status = 0;
11
- var $notes = array();
12
- var $fields = array(
13
- 'booking_id' => array('name'=>'id','type'=>'%d'),
14
- 'event_id' => array('name'=>'event_id','type'=>'%d'),
15
- 'person_id' => array('name'=>'person_id','type'=>'%d'),
16
- 'booking_price' => array('name'=>'price','type'=>'%d'),
17
- 'booking_spaces' => array('name'=>'spaces','type'=>'%d'),
18
- 'booking_comment' => array('name'=>'comment','type'=>'%s'),
19
- 'booking_status' => array('name'=>'status','type'=>'%d')
20
- );
21
- //Other Vars
22
- var $timestamp;
23
- var $person;
24
- var $required_fields = array('booking_id', 'event_id', 'person_id', 'booking_spaces');
25
- var $feedback_message = "";
26
- var $errors = array();
27
- /**
28
- * Contains an array of custom fields for a booking. This is loaded from em_meta, where the booking_custom name contains arrays of data.
29
- * @var array
30
- */
31
- var $custom = array();
32
- /**
33
- * If saved in this instance, you can see what previous approval status was.
34
- * @var int
35
- */
36
- var $previous_status;
37
- /**
38
- * The booking approval status number corresponds to a state in this array.
39
- * @var unknown_type
40
- */
41
- var $status_array = array();
42
- /**
43
- * @var EM_Tickets
44
- */
45
- var $tickets;
46
- /**
47
- * @var EM_Event
48
- */
49
- var $event;
50
- /**
51
- * @var EM_Tickets_Bookings
52
- */
53
- var $tickets_bookings;
54
-
55
- /**
56
- * Creates booking object and retreives booking data (default is a blank booking object). Accepts either array of booking data (from db) or a booking id.
57
- * @param mixed $booking_data
58
- * @return null
59
- */
60
- function EM_Booking( $booking_data = false ){
61
- //Get the person for this booking
62
- if( $booking_data !== false ){
63
- //Load booking data
64
- $booking = array();
65
- if( is_array($booking_data) ){
66
- $booking = $booking_data;
67
- }elseif( is_numeric($booking_data) ){
68
- //Retreiving from the database
69
- global $wpdb;
70
- $sql = "SELECT * FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." LEFT JOIN ". $wpdb->prefix . EM_META_TABLE ." ON object_id=booking_id WHERE booking_id ='$booking_data'";
71
- $booking = $wpdb->get_row($sql, ARRAY_A);
72
- //Custom Fields
73
- $custom = $wpdb->get_row("SELECT meta_key, meta_value FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." LEFT JOIN ". $wpdb->prefix . EM_META_TABLE ." ON object_id=booking_id WHERE booking_id ='$booking_data' AND meta_key='booking_custom'");
74
- //Booking notes
75
- $notes = $wpdb->get_results("SELECT * FROM ". $wpdb->prefix . EM_META_TABLE ." WHERE meta_key='booking-note' AND object_id ='$booking_data'", ARRAY_A);
76
- foreach($notes as $note){
77
- $this->notes[] = unserialize($note['meta_value']);
78
- }
79
- }
80
- //Save into the object
81
- $this->to_object($booking);
82
- $this->get_person();
83
- $this->timestamp = strtotime($booking['booking_date']);
84
- //Add custom booking data
85
- if( !empty($custom['meta_key']) && $custom['meta_key'] == 'booking_custom' && is_serialized($custom['meta_value']) ){
86
- $this->custom = unserialize($custom['meta_value']);
87
- }
88
- }
89
- //Do it here so things appear in the po file.
90
- $this->status_array = array(
91
- 0 => __('Pending','dbem'),
92
- 1 => __('Approved','dbem'),
93
- 2 => __('Rejected','dbem'),
94
- 3 => __('Cacncelled','dbem'),
95
- 4 => __('Awaiting Online Payment','dbem')
96
- );
97
- do_action('em_booking', $this, $booking_data);
98
- }
99
-
100
- /**
101
- * Saves the booking into the database, whether a new or existing booking
102
- * @return boolean
103
- */
104
- function save(){
105
- global $wpdb;
106
- $table = $wpdb->prefix.EM_BOOKINGS_TABLE;
107
- do_action('em_booking_save_pre',$this);
108
- if($this->validate()){
109
- $this->person_id = $this->get_person()->ID;
110
- //Step 1. Save the booking
111
- $data = $this->to_array();
112
- if($this->id != ''){
113
- $update = true;
114
- $where = array( 'booking_id' => $this->id );
115
- $result = $wpdb->update($table, $data, $where, $this->get_types($data));
116
- $this->feedback_message = __('Changes saved','dbem');
117
- }else{
118
- $update = false;
119
- $result = $wpdb->insert($table, $data, $this->get_types($data));
120
- $this->id = $wpdb->insert_id;
121
- $this->feedback_message = __('Your booking has been recorded','dbem');
122
- }
123
- if( $result === false ){
124
- $this->feedback_message = __('There was a problem saving the booking.', 'dbem');
125
- $this->errors[] = __('There was a problem saving the booking.', 'dbem');
126
- }else{
127
- //Step 2. Insert ticket bookings for this booking id
128
- $tickets_bookings_result = $this->get_tickets_bookings()->save();
129
- if( !$tickets_bookings_result ){
130
- if( !$update ){
131
- //delete the booking and tickets, instead of a transaction
132
- $this->delete();
133
- }
134
- $this->errors[] = __('There was a problem saving the booking.', 'dbem');
135
- $this->add_errors( $this->get_tickets_bookings()->get_errors() );
136
- }
137
- }
138
- return apply_filters('em_booking_save', ( count($this->errors) == 0 ), $this);
139
- }else{
140
- $this->feedback_message = __('There was a problem saving the booking.', 'dbem');
141
- }
142
- return apply_filters('em_booking_save', false, $this);
143
- }
144
-
145
- /**
146
- * Load an record into this object by passing an associative array of table criterie to search for.
147
- * Returns boolean depending on whether a record is found or not.
148
- * @param $search
149
- * @return boolean
150
- */
151
- function get($search) {
152
- global $wpdb;
153
- $conds = array();
154
- foreach($search as $key => $value) {
155
- if( array_key_exists($key, $this->fields) ){
156
- $value = $wpdb->escape($value);
157
- $conds[] = "`$key`='$value'";
158
- }
159
- }
160
- $sql = "SELECT * FROM ". $wpdb->EM_BOOKINGS_TABLE ." WHERE " . implode(' AND ', $conds) ;
161
- $result = $wpdb->get_row($sql, ARRAY_A);
162
- if($result){
163
- $this->to_object($result);
164
- $this->person = new EM_Person($this->person_id);
165
- return true;
166
- }else{
167
- return false;
168
- }
169
- }
170
-
171
- /**
172
- * Get posted data and save it into the object (not db)
173
- * @return boolean
174
- */
175
- function get_post(){
176
- $this->tickets_bookings = new EM_Tickets_Bookings($this->id);
177
- $result = array();
178
- $this->event_id = $this->get_event()->id;
179
- if( !empty($_POST['em_tickets']) && is_array($_POST['em_tickets']) ){
180
- foreach( $_POST['em_tickets'] as $ticket_id => $values){
181
- //make sure ticket exists
182
- if( !empty($values['spaces']) ){
183
- $args = array('ticket_id'=>$ticket_id, 'ticket_booking_spaces'=>$values['spaces'], 'booking_id'=>$this->id);
184
- if($this->get_event()->get_bookings()->ticket_exists($ticket_id)){
185
- $EM_Ticket_Booking = new EM_Ticket_Booking($args);
186
- $EM_Ticket_Booking->booking = $this;
187
- $this->tickets_bookings->add( $EM_Ticket_Booking );
188
- }else{
189
- $this->errors[]=__('You are trying to book a non-existent ticket for this event.','dbem');
190
- }
191
- }
192
- }
193
- $this->comment = (!empty($_REQUEST['booking_comment'])) ? $_REQUEST['booking_comment']:'';
194
- $this->get_spaces();
195
- $this->get_price();
196
- $this->get_person();
197
- }
198
- return apply_filters('em_booking_get_post',$this->validate(),$this);
199
- }
200
-
201
- function validate(){
202
- //step 1, basic info
203
- $basic = (
204
- (empty($this->event_id) || is_numeric($this->event_id)) &&
205
- (empty($this->person_id) || is_numeric($this->person_id)) &&
206
- is_numeric($this->spaces) && $this->spaces > 0 &&
207
- is_user_logged_in()
208
- );
209
- //give some errors in step 1
210
- if( $this->spaces == 0 ){
211
- $this->add_error(__('You must request at least one space to book an event.','dbem'));
212
- }
213
- //step 2, tickets bookings info
214
- if( count($this->get_tickets_bookings()) > 0 ){
215
- $ticket_validation = array();
216
- foreach($this->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking){
217
- if ( !$EM_Ticket_Booking->validate() ){
218
- $ticket_validation[] = false;
219
- }
220
- $this->errors = array_merge($this->errors, $EM_Ticket_Booking->get_errors());
221
- }
222
- $result = $basic && !in_array(false,$ticket_validation);
223
- }else{
224
- $result = false;
225
- }
226
-
227
- return apply_filters('em_booking_validate',$result,$this);
228
- }
229
-
230
- /**
231
- * Get the total number of spaces booked in THIS booking. Seting $force_refresh to true will recheck spaces, even if previously done so.
232
- * @param unknown_type $force_refresh
233
- * @return mixed
234
- */
235
- function get_spaces( $force_refresh=false ){
236
- if($this->spaces == 0 || $force_refresh == true ){
237
- $this->spaces = $this->get_tickets_bookings()->get_spaces($force_refresh);
238
- }
239
- return apply_filters('em_booking_get_spaces',$this->spaces,$this);
240
- }
241
-
242
- /**
243
- * Gets the total price for this whole booking. Seting $force_reset to true will recheck spaces, even if previously done so.
244
- * @param boolean $force_refresh
245
- * @return float
246
- */
247
- function get_price( $force_refresh=false ){
248
- if($force_refresh || $this->price == 0){
249
- $this->price = $this->get_tickets_bookings()->get_price($force_refresh);
250
- }
251
- return apply_filters('em_booking_get_prices',$this->price,$this);
252
- }
253
-
254
- /**
255
- * Gets the event this booking belongs to and saves a refernece in the event property
256
- * @return EM_Event
257
- */
258
- function get_event(){
259
- global $EM_Event;
260
- if( is_object($this->event) && get_class($this->event)=='EM_Event' && $this->event->id == $this->event_id ){
261
- return $this->event;
262
- }elseif( is_object($EM_Event) && ( (is_object($this->event) &&$this->event->id == $this->event_id) || empty($this->id)) ){
263
- $this->event = $EM_Event;
264
- }else{
265
- $this->event = new EM_Event($this->event_id);
266
- }
267
- return apply_filters('em_booking_get_event',$this->event);
268
- }
269
-
270
- /**
271
- * Get custom fields for this booking.
272
- * @return array
273
- */
274
- function get_custom(){
275
- global $wpdb;
276
- if( count($this->custom) == 0 ){
277
- $sql = "SELECT * FROM ". $wpdb->prefix . EM_META_TABLE ." WHERE object_id ='{$this->id}' AND (meta_key='booking_custom' OR meta_key IS NULL)";
278
- $booking = $wpdb->get_row($sql, ARRAY_A);
279
- //Add custom booking data
280
- if( !empty($booking['meta_key']) && $booking['meta_key'] == 'booking_custom' && is_serialized($booking['meta_value']) ){
281
- $this->custom = unserialize($booking['meta_value']);
282
- }
283
- }
284
- return $this->custom;
285
- }
286
-
287
- /**
288
- * Gets the ticket object this booking belongs to, saves a reference in ticket property
289
- * @return EM_Ticket
290
- */
291
- function get_tickets(){
292
- global $EM_Ticket;
293
- if( is_object($this->tickets) && get_class($this->tickets)=='EM_Ticket' && $this->tickets->id == $this->ticket_id ){
294
- return apply_filters('em_booking_get_tickets', $this->tickets, $this);
295
- }elseif( is_object($EM_Ticket) && $EM_Ticket->id == $this->ticket_id ){
296
- $this->tickets = $EM_Ticket;
297
- }else{
298
- $this->tickets = new EM_Tickets($this->ticket_id);
299
- }
300
- return apply_filters('em_booking_get_tickets', $this->tickets, $this);
301
- }
302
-
303
- /**
304
- * Gets the ticket object this booking belongs to, saves a reference in ticket property
305
- * @return EM_Tickets_Bookings
306
- */
307
- function get_tickets_bookings(){
308
- global $wpdb;
309
- if( !is_object($this->tickets_bookings) && get_class($this->tickets_bookings)!='EM_Tickets_Bookings'){
310
- $this->tickets_bookings = new EM_Tickets_Bookings($this);
311
- }
312
- return apply_filters('em_booking_get_tickets_bookings', $this->tickets_bookings, $this);
313
- }
314
-
315
- function get_person(){
316
- global $EM_Person;
317
- if( is_object($this->person) && get_class($this->person)=='EM_Person' && ($this->person->ID == $this->person_id || empty($this->person_id) ) ){
318
- return apply_filters('em_booking_get_person', $this->person, $this);
319
- }elseif( is_object($EM_Person) && $EM_Person->ID == $this->person_id ){
320
- $this->person = $EM_Person;
321
- }else{
322
- if( !empty($this->person_id) ){
323
- $this->person = new EM_Person($this->person_id);
324
- }elseif( is_user_logged_in() ){
325
- //get current logged in user
326
- $this->person = new EM_Person(get_current_user_id());
327
- }
328
- }
329
- return apply_filters('em_booking_get_person', $this->person, $this);
330
- }
331
-
332
- /**
333
- * Returns a string representation of the booking's status
334
- * @return string
335
- */
336
- function get_status(){
337
- return $this->status_array[$this->status];
338
- }
339
-
340
- /**
341
- * I wonder what this does....
342
- * @return boolean
343
- */
344
- function delete(){
345
- global $wpdb;
346
- //FIXME ticket logic needed
347
- $sql = $wpdb->prepare("DELETE FROM ". $wpdb->prefix.EM_BOOKINGS_TABLE . " WHERE booking_id=%d", $this->id);
348
- $result = $wpdb->query( $sql );
349
- if( $result !== false ){
350
- //delete the tickets too
351
- $this->get_tickets_bookings()->delete();
352
- $this->previous_status = $this->status;
353
- $this->status = false;
354
- }
355
- return ( $result !== false );
356
- }
357
-
358
- function cancel(){
359
- return $this->set_status(3);
360
- }
361
-
362
- /**
363
- * Approve a booking.
364
- * @return bool
365
- */
366
- function approve(){
367
- return $this->set_status(1);
368
- }
369
- /**
370
- * Reject a booking and save
371
- * @return bool
372
- */
373
- function reject(){
374
- return $this->set_status(2);
375
- }
376
- /**
377
- * Unpprove a booking.
378
- * @return bool
379
- */
380
- function unapprove(){
381
- return $this->set_status(0);
382
- }
383
-
384
- /**
385
- * Change the status of the booking. This will save to the Database too.
386
- * @param unknown_type $status
387
- * @return string
388
- */
389
- function set_status($status){
390
- $action_string = strtolower($this->status_array[$status]);
391
- //if we're approving we can't approve a booking if spaces are full, so check before it's approved.
392
- if($status == 1){
393
- if( $this->get_event()->get_bookings()->get_available_spaces() < $this->get_spaces() && !get_option('dbem_bookings_approval_overbooking') ){
394
- $this->feedback_message = sprintf(__('Not approved, spaces full.','dbem'), $action_string);
395
- return apply_filters('em_booking_set_status', false, $this);
396
- }
397
- }
398
- $this->previous_status = $this->status;
399
- $this->status = $status;
400
- $result = $this->save();
401
- if($result){
402
- $this->feedback_message = sprintf(__('Booking %s.','dbem'), $action_string);
403
- if( !($this->status == 0 && $this->previous_status > 0) ){
404
- if( $this->email() ){
405
- $this->feedback_message .= " ".__('Mail Sent.','dbem');
406
- }elseif( $this->previous_status == 0 ){
407
- //extra errors may be logged by email() in EM_Object
408
- $this->feedback_message .= ' <span style="color:red">'.__('ERROR : Mail Not Sent.','dbem').'</span>';
409
- $result = false;
410
- }
411
- }
412
- }else{
413
- //errors should be logged by save()
414
- $this->feedback_message = sprintf(__('Booking could not be %s.','dbem'), $action_string);
415
- }
416
- return apply_filters('em_booking_set_status', $result, $this);
417
- }
418
-
419
- /**
420
- * Add a booking note to this booking. returns wpdb result or false if use can't manage this event.
421
- * @param string $note
422
- * @return mixed
423
- */
424
- function add_note( $note_text ){
425
- global $wpdb;
426
- if( $this->can_manage() ){
427
- $note = array('author'=>get_current_user_id(),'note'=>$note_text,'timestamp'=>current_time('timestamp'));
428
- $this->notes[] = $note;
429
- $this->feedback_message = __('Booking note successfully added.','dbem');
430
- return $wpdb->insert($wpdb->prefix.EM_META_TABLE, array('object_id'=>$this->id, 'meta_key'=>'booking-note', 'meta_value'=> serialize($note)),array('%d','%s','%s'));
431
- }
432
- return false;
433
- }
434
-
435
- /**
436
- * @param EM_Booking $EM_Booking
437
- * @param EM_Event $event
438
- * @return boolean
439
- */
440
- function email(){
441
- global $EM_Mailer;
442
- //FIXME ticket logic needed
443
- $EM_Event = $this->get_event(); //We NEED event details here.
444
- //Make sure event matches booking, and that booking used to be approved.
445
- if( !($this->status == 0 && $this->previous_status > 0) ){
446
- $contact_id = ( $EM_Event->owner != "") ? $EM_Event->owner : get_option('dbem_default_contact_person');
447
-
448
- $contact_subject = get_option('dbem_bookings_contact_email_subject');
449
- $contact_body = get_option('dbem_bookings_contact_email_body');
450
-
451
- if( get_option('dbem_bookings_approval') == 0 && $this->status < 2 || $this->status == 1 ){
452
- $booker_subject = get_option('dbem_bookings_email_confirmed_subject');
453
- $booker_body = get_option('dbem_bookings_email_confirmed_body');
454
- }elseif( $this->status == 0 ){
455
- $booker_subject = get_option('dbem_bookings_email_pending_subject');
456
- $booker_body = get_option('dbem_bookings_email_pending_body');
457
- }elseif( $this->status == 2 ){
458
- $booker_subject = get_option('dbem_bookings_email_rejected_subject');
459
- $booker_body = get_option('dbem_bookings_email_rejected_body');
460
- }elseif( $this->status == 3 ){
461
- $booker_subject = get_option('dbem_bookings_email_cancelled_subject');
462
- $booker_body = get_option('dbem_bookings_email_cancelled_body');
463
- $contact_subject = get_option('dbem_contactperson_email_cancelled_subject');
464
- $contact_body = get_option('dbem_contactperson_email_cancelled_body');
465
- }
466
-
467
- // email specific placeholders
468
- $placeholders = array(
469
- '#_RESPNAME' => '#_BOOKINGNAME',//Depreciated
470
- '#_RESPEMAIL' => '#_BOOKINGEMAIL',//Depreciated
471
- '#_RESPPHONE' => '#_BOOKINGPHONE',//Depreciated
472
- '#_COMMENT' => '#_BOOKINGCOMMENT',//Depreciated
473
- '#_RESERVEDSPACES' => '#_BOOKEDSPACES',//Depreciated
474
- '#_BOOKINGNAME' => $this->person->display_name,
475
- '#_BOOKINGEMAIL' => $this->person->user_email,
476
- '#_BOOKINGPHONE' => $this->person->phone,
477
- '#_BOOKINGSPACES' => $this->get_spaces(),
478
- '#_BOOKINGCOMMENT' => $this->comment,
479
- );
480
- foreach($placeholders as $key => $value) {
481
- $contact_subject = str_replace($key, $value, $contact_subject);
482
- $contact_body = str_replace($key, $value, $contact_body);
483
- $booker_subject = str_replace($key, $value, $booker_subject);
484
- $booker_body = str_replace($key, $value, $booker_body);
485
- }
486
-
487
- $booker_subject = $EM_Event->output($booker_subject, 'email');
488
- $booker_body = $EM_Event->output($booker_body, 'email');
489
-
490
- //Send to the person booking
491
- if( !$this->email_send( $booker_subject,$booker_body, $this->person->user_email) ){
492
- return false;
493
- }
494
-
495
- //Send admin/contact emails
496
- if( (get_option('dbem_bookings_approval') == 0 || $this->status == 0 || $this->status == 3) && (get_option('dbem_bookings_contact_email') == 1 || get_option('dbem_bookings_notify_admin') != '') ){
497
- //Only gets sent if this is a pending booking, unless approvals are disabled.
498
- $contact_subject = $EM_Event->output($contact_subject, 'email');
499
- $contact_body = $EM_Event->output($contact_body, 'email');
500
-
501
- if( get_option('dbem_bookings_contact_email') == 1 ){
502
- if( !$this->email_send( $contact_subject, $contact_body, $EM_Event->contact->user_email) && current_user_can('activate_plugins')){
503
- $this->errors[] = __('Confirmation email could not be sent to contact person. Registrant should have gotten their email (only admin see this warning).','dbem');
504
- return false;
505
- }
506
- }
507
-
508
- if( get_option('dbem_bookings_notify_admin') != '' && preg_match('/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$/', get_option('dbem_bookings_notify_admin')) ){
509
- if( !$this->email_send( $contact_subject, $contact_body, get_option('dbem_bookings_notify_admin')) ){
510
- $this->errors[] = __('Confirmation email could not be sent to admin. Registrant should have gotten their email (only admin see this warning).','dbem');
511
- return false;
512
- }
513
- }
514
- }
515
- return true;
516
- }
517
- return false;
518
- //TODO need error checking for booking mail send
519
- }
520
-
521
- /**
522
- * Can the user manage this event?
523
- */
524
- function can_manage(){
525
- return $this->get_event()->can_manage('manage_bookings','manage_others_bookings');
526
- }
527
-
528
- /**
529
- * Returns this object in the form of an array
530
- * @return array
531
- */
532
- function to_array($person = false){
533
- $booking = array();
534
- //Core Data
535
- $booking = parent::to_array();
536
- //Person Data
537
- if($person && is_object($this->person)){
538
- $person = $this->person->to_array();
539
- $booking = array_merge($booking, $person);
540
- }
541
- return $booking;
542
- }
543
- }
544
  ?>
1
+ <?php
2
+ class EM_Booking extends EM_Object{
3
+ //DB Fields
4
+ var $id;
5
+ var $event_id;
6
+ var $person_id;
7
+ var $seats;
8
+ var $comment;
9
+ var $status = 0;
10
+ var $notes = array();
11
+ var $fields = array(
12
+ 'booking_id' => array('name'=>'id','type'=>'%d'),
13
+ 'event_id' => array('name'=>'event_id','type'=>'%d'),
14
+ 'person_id' => array('name'=>'person_id','type'=>'%d'),
15
+ 'booking_seats' => array('name'=>'seats','type'=>'%d'),
16
+ 'booking_comment' => array('name'=>'comment','type'=>'%s'),
17
+ 'booking_status' => array('name'=>'status','type'=>'%d')
18
+ );
19
+ //Other Vars
20
+ var $timestamp;
21
+ var $person;
22
+ var $required_fields = array('booking_id', 'event_id', 'person_id', 'booking_seats');
23
+ var $feedback_message = "";
24
+ var $errors = array();
25
+ /**
26
+ * If saved in this instance, you can see what previous approval status was.
27
+ * @var int
28
+ */
29
+ var $previous_status = false;
30
+ /**
31
+ * The booking approval status number corresponds to a state in this array.
32
+ * @var unknown_type
33
+ */
34
+ var $status_array = array();
35
+
36
+ /**
37
+ * Creates booking object and retreives booking data (default is a blank booking object). Accepts either array of booking data (from db) or a booking id.
38
+ * @param mixed $booking_data
39
+ * @return null
40
+ */
41
+ function EM_Booking( $booking_data = false ){
42
+ if( !get_option('dbem_bookings_approval') ){
43
+ $this->status = 1;
44
+ }
45
+ if( $booking_data !== false ){
46
+ //Load booking data
47
+ $booking = array();
48
+ if( is_array($booking_data) ){
49
+ $booking = $booking_data;
50
+ //Also create a person out of this...
51
+ $this->person = new EM_Person($booking_data);
52
+ if( !empty($booking['person_id']) && $booking['person_id'] != $this->person->id){
53
+ $this->person = new EM_Person($booking['booking_id']);
54
+ }
55
+ }elseif( is_numeric($booking_data) ){
56
+ //Retreiving from the database
57
+ global $wpdb;
58
+ $sql = "SELECT * FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." WHERE booking_id ='$booking_data'";
59
+ $booking = $wpdb->get_row($sql, ARRAY_A);
60
+ //Get the person for this booking
61
+ $this->person = new EM_Person($booking['person_id']);
62
+ //Booking notes
63
+ $notes = $wpdb->get_results("SELECT * FROM ". $wpdb->prefix . EM_META_TABLE ." WHERE meta_key='booking-note' AND object_id ='$booking_data'", ARRAY_A);
64
+ foreach($notes as $note){
65
+ $this->notes[] = unserialize($note['meta_value']);
66
+ }
67
+ }
68
+ //Save into the object
69
+ $this->to_object($booking);
70
+ if( !empty($booking['booking_date']) ){
71
+ $this->timestamp = strtotime($booking['booking_date']);
72
+ }
73
+ }
74
+ //Do it here so things appear in the po file.
75
+ $this->status_array = array(
76
+ 0 => __('Pending','dbem'),
77
+ 1 => __('Approved','dbem'),
78
+ 2 => __('Rejected','dbem'),
79
+ 3 => __('Cacncelled','dbem')
80
+ );
81
+ }
82
+
83
+ /**
84
+ * Saves the booking into the database, whether a new or existing booking
85
+ * @return boolean
86
+ */
87
+ function save(){
88
+ global $wpdb;
89
+ $table = $wpdb->prefix.EM_BOOKINGS_TABLE;
90
+ do_action('em_booking_save_pre',$this);
91
+ //First the person
92
+ if($this->validate()){
93
+ //Does this person exist?
94
+ $person_result = $this->person->save();
95
+ if( $person_result === false ){
96
+ $this->errors = array_merge($this->errors, $this->person->errors);
97
+ return false;
98
+ }
99
+ $this->person_id = $this->person->id;
100
+
101
+ //Now we save the booking
102
+ $data = $this->to_array();
103
+ if($this->id != ''){
104
+ $where = array( 'booking_id' => $this->id );
105
+ $result = $wpdb->update($table, $data, $where, $this->get_types($data));
106
+ $this->feedback_message = __('Changes saved');
107
+ }else{
108
+ $result = $wpdb->insert($table, $data, $this->get_types($data));
109
+ $this->id = $wpdb->insert_id;
110
+ $this->feedback_message = __('Your booking has been recorded','dbem');
111
+ }
112
+ if( $result === false ){
113
+ $this->feedback_message = __('There was a problem saving the booking.', 'dbem');
114
+ $this->errors[] = __('There was a problem saving the booking.', 'dbem');
115
+ }
116
+ return apply_filters('em_booking_save', ( count($this->errors) == 0 ), $this);
117
+ }else{
118
+ $this->feedback_message = __('There was a problem saving the booking.', 'dbem');
119
+ $this->errors[] = __('There was a problem saving the booking.', 'dbem');
120
+ return apply_filters('em_booking_save', false, $this);
121
+ }
122
+ return true;
123
+ }
124
+
125
+ /**
126
+ * Load an record into this object by passing an associative array of table criterie to search for.
127
+ * Returns boolean depending on whether a record is found or not.
128
+ * @param $search
129
+ * @return boolean
130
+ */
131
+ function get($search) {
132
+ global $wpdb;
133
+ $conds = array();
134
+ foreach($search as $key => $value) {
135
+ if( array_key_exists($key, $this->fields) ){
136
+ $value = $wpdb->escape($value);
137
+ $conds[] = "`$key`='$value'";
138
+ }
139
+ }
140
+ $sql = "SELECT * FROM ". $wpdb->EM_BOOKINGS_TABLE ." WHERE " . implode(' AND ', $conds) ;
141
+ $result = $wpdb->get_row($sql, ARRAY_A);
142
+ if($result){
143
+ $this->to_object($result);
144
+ return true;
145
+ }else{
146
+ return false;
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Get posted data and save it into the object (not db)
152
+ * @return boolean
153
+ */
154
+ function get_post(){
155
+ //Currently, only editing allowed, so here we are.
156
+ $this->comment = (!empty($_REQUEST['booking_comment'])) ? $_REQUEST['booking_comment']:'';
157
+ $this->seats = (!empty($_REQUEST['booking_seats'])) ? $_REQUEST['booking_seats']:'';
158
+ return apply_filters('em_booking_get_post',$this->validate(),$this);
159
+ }
160
+
161
+ function validate(){
162
+ return (
163
+ (empty($this->event_id) || is_numeric($this->event_id)) &&
164
+ (empty($this->person_id) || is_numeric($this->person_id)) &&
165
+ is_numeric($this->seats)
166
+ );
167
+ }
168
+
169
+ /**
170
+ * Smart event locator, saves a database read if possible.
171
+ */
172
+ function get_event(){
173
+ global $EM_Event;
174
+ if( !empty($this->event) && is_object($this->event) && get_class($this->event)=='EM_Event' && $this->event->id == $this->event_id ){
175
+ return $this->event;
176
+ }elseif( is_object($EM_Event) && $EM_Event->id == $this->event_id ){
177
+ $this->event = $EM_Event;
178
+ }else{
179
+ $this->event = new EM_Event($this->event_id);
180
+ }
181
+ return $this->event;
182
+ }
183
+
184
+ /**
185
+ * Returns a string representation of the booking's status
186
+ * @return string
187
+ */
188
+ function get_status(){
189
+ return $this->status_array[$this->status];
190
+ }
191
+ /**
192
+ * I wonder what this does....
193
+ * @return boolean
194
+ */
195
+ function delete(){
196
+ global $wpdb;
197
+ $sql = $wpdb->prepare("DELETE FROM ". $wpdb->prefix.EM_BOOKINGS_TABLE . " WHERE booking_id=%d", $this->id);
198
+ $result = $wpdb->query( $sql );
199
+ return ( $result !== false );
200
+ }
201
+
202
+ function cancel(){
203
+ return $this->set_status(3);
204
+ }
205
+
206
+ /**
207
+ * Approve a booking.
208
+ * @return bool
209
+ */
210
+ function approve(){
211
+ return $this->set_status(1);
212
+ }
213
+ /**
214
+ * Reject a booking and save
215
+ * @return bool
216
+ */
217
+ function reject(){
218
+ return $this->set_status(2);
219
+ }
220
+ /**
221
+ * Unpprove a booking.
222
+ * @return bool
223
+ */
224
+ function unapprove(){
225
+ return $this->set_status(0);
226
+ }
227
+
228
+ /**
229
+ * Change the status of the booking. This will save to the Database too.
230
+ * @param unknown_type $status
231
+ * @return string|string|string
232
+ */
233
+ function set_status($status){
234
+ $this->previous_status = $this->status;
235
+ $this->status = $status;
236
+ $result = $this->save();
237
+ $action_string = strtolower($this->status_array[$status]);
238
+ if($result){
239
+ $this->feedback_message = sprintf(__('Booking %s.','dbem'), $action_string);
240
+ if( $this->email() ){
241
+ $this->feedback_message .= " ".__('Mail Sent.','dbem');
242
+ }elseif( $this->previous_status == 0 ){
243
+ //extra errors may be logged by email() in EM_Object
244
+ $this->feedback_message .= ' <span style="color:red">'.__('ERROR : Mail Not Sent.','dbem').'</span>';
245
+ return false;
246
+ }
247
+ return true;
248
+ }else{
249
+ //errors should be logged by save()
250
+ $this->feedback_message = sprintf(__('Booking could not be %s.','dbem'), $action_string);
251
+ return false;
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Add a booking note to this booking. returns wpdb result or false if use can't manage this event.
257
+ * @param string $note
258
+ * @return mixed
259
+ */
260
+ function add_note( $note_text ){
261
+ global $wpdb;
262
+ if( $this->can_manage() ){
263
+ $note = array('author'=>get_current_user_id(),'note'=>$note_text,'timestamp'=>current_time('timestamp'));
264
+ $this->notes[] = $note;
265
+ $this->feedback_message = __('Booking note successfully added.','dbem');
266
+ return $wpdb->insert($wpdb->prefix.EM_META_TABLE, array('object_id'=>$this->id, 'meta_key'=>'booking-note', 'meta_value'=> serialize($note)),array('%d','%s','%s'));
267
+ }
268
+ return false;
269
+ }
270
+
271
+ /**
272
+ * @param EM_Booking $EM_Booking
273
+ * @param EM_Event $event
274
+ * @return boolean
275
+ */
276
+ function email(){
277
+ global $EM_Mailer;
278
+ $EM_Event = $this->get_event(); //We NEED event details here.
279
+ //Make sure event matches booking, and that booking used to be approved.
280
+ if( $this->previous_status == 0 || $this->status == 3 ){
281
+ $contact_id = ( $EM_Event->contactperson_id != "") ? $EM_Event->contactperson_id : get_option('dbem_default_contact_person');
282
+
283
+ $contact_subject = get_option('dbem_bookings_contact_email_subject');
284
+ $contact_body = get_option('dbem_bookings_contact_email_body');
285
+
286
+ if( (get_option('dbem_bookings_approval') == 0 && $this->previous_status === false) || $this->status == 1 ){
287
+ $booker_subject = get_option('dbem_bookings_email_confirmed_subject');
288
+ $booker_body = get_option('dbem_bookings_email_confirmed_body');
289
+ }elseif( $this->status == 0 ){
290
+ $booker_subject = get_option('dbem_bookings_email_pending_subject');
291
+ $booker_body = get_option('dbem_bookings_email_pending_body');
292
+ }elseif( $this->status == 2 ){
293
+ $booker_subject = get_option('dbem_bookings_email_rejected_subject');
294
+ $booker_body = get_option('dbem_bookings_email_rejected_body');
295
+ }elseif( $this->status == 3 ){
296
+ $booker_subject = get_option('dbem_bookings_email_cancelled_subject');
297
+ $booker_body = get_option('dbem_bookings_email_cancelled_body');
298
+ $contact_subject = get_option('dbem_contactperson_email_cancelled_subject');
299
+ $contact_body = get_option('dbem_contactperson_email_cancelled_body');
300
+ }
301
+
302
+ // email specific placeholders
303
+ $placeholders = array(
304
+ '#_RESPNAME' => '#_BOOKINGNAME',//Depreciated
305
+ '#_RESPEMAIL' => '#_BOOKINGEMAIL',//Depreciated
306
+ '#_RESPPHONE' => '#_BOOKINGPHONE',//Depreciated
307
+ '#_COMMENT' => '#_BOOKINGCOMMENT',//Depreciated
308
+ '#_RESERVEDSPACES' => '#_BOOKEDSPACES',//Depreciated
309
+ '#_BOOKINGNAME' => $this->person->name,
310
+ '#_BOOKINGEMAIL' => $this->person->email,
311
+ '#_BOOKINGPHONE' => $this->person->phone,
312
+ '#_BOOKINGSPACES' => $this->seats,
313
+ '#_BOOKINGCOMMENT' => $this->comment,
314
+ );
315
+ foreach($placeholders as $key => $value) {
316
+ $contact_subject = str_replace($key, $value, $contact_subject);
317
+ $contact_body = str_replace($key, $value, $contact_body);
318
+ $booker_subject = str_replace($key, $value, $booker_subject);
319
+ $booker_body = str_replace($key, $value, $booker_body);
320
+ }
321
+
322
+ $booker_subject = $EM_Event->output($booker_subject, 'email');
323
+ $booker_body = $EM_Event->output($booker_body, 'email');
324
+
325
+ //Send to the person booking
326
+ if( !$this->email_send( $booker_subject,$booker_body, $this->person->email) ){
327
+ return false;
328
+ }
329
+
330
+ //Send admin emails
331
+ if( (get_option('dbem_bookings_approval') == 0 || $this->status == 0) && (get_option('dbem_bookings_contact_email') == 1 || get_option('dbem_bookings_notify_admin') != '') ){
332
+ //Only gets sent if this is a pending booking, unless approvals are disabled.
333
+ $contact_subject = $EM_Event->output($contact_subject, 'email');
334
+ $contact_body = $EM_Event->output($contact_body, 'email');
335
+
336
+ if( get_option('dbem_bookings_contact_email') == 1 ){
337
+ if( !$this->email_send( $contact_subject, $contact_body, $EM_Event->contact->user_email) && current_user_can('activate_plugins')){
338
+ $this->errors[] = __('Confirmation email could not be sent to contact person. Registrant should have gotten their email (only admin see this warning).','dbem');
339
+ return false;
340
+ }
341
+ }
342
+
343
+ if( get_option('dbem_bookings_notify_admin') != '' && preg_match('/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$/', get_option('dbem_bookings_notify_admin')) ){
344
+ if( !$this->email_send( $contact_subject, $contact_body, get_option('dbem_bookings_notify_admin')) ){
345
+ $this->errors[] = __('Confirmation email could not be sent to admin. Registrant should have gotten their email (only admin see this warning).','dbem');
346
+ return false;
347
+ }
348
+ }
349
+ }
350
+ return true;
351
+ }
352
+ return false;
353
+ //TODO need error checking for booking mail send
354
+ }
355
+
356
+ /**
357
+ * Can the user manage this event?
358
+ */
359
+ function can_manage(){
360
+ return ( get_option('dbem_permissions_events') || $this->get_event()->author == get_current_user_id() || em_verify_admin() );
361
+ }
362
+
363
+ /**
364
+ * Returns this object in the form of an array
365
+ * @return array
366
+ */
367
+ function to_array($person = false){
368
+ $booking = array();
369
+ //Core Data
370
+ $booking = parent::to_array();
371
+ //Person Data
372
+ if($person && is_object($this->person)){
373
+ $person = $this->person->to_array();
374
+ $booking = array_merge($booking, $person);
375
+ }
376
+ return $booking;
377
+ }
378
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  ?>
classes/em-bookings.php CHANGED
@@ -1,596 +1,488 @@
1
- <?php
2
- /**
3
- * Deals with the booking info for an event
4
- * @author marcus
5
- *
6
- */
7
- class EM_Bookings extends EM_Object implements Iterator{
8
-
9
- /**
10
- * Array of EM_Booking objects for a specific event
11
- * @var array
12
- */
13
- var $bookings = array();
14
- /**
15
- * @var EM_Tickets
16
- */
17
- var $tickets;
18
- /**
19
- * @var EM_Event
20
- */
21
- var $event;
22
- /**
23
- * How many spaces this event has
24
- * @var int
25
- */
26
- var $spaces;
27
-
28
- var $feedback_message = "";
29
- var $errors = array();
30
-
31
- /**
32
- * Creates an EM_Bookings instance, currently accepts an EM_Event object (gets all bookings for that event) or array of any EM_Booking objects, which can be manipulated in bulk with helper functions.
33
- * @param EM_Event $event
34
- * @return null
35
- */
36
- function EM_Bookings( $data = false ){
37
- if( is_object($data) && get_class($data) == "EM_Event" ){ //Creates a blank bookings object if needed
38
- global $wpdb;
39
- $this->event = $data;
40
- $sql = "SELECT * FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." WHERE event_id ='{$this->event->id}'";
41
- $bookings = $wpdb->get_results($sql, ARRAY_A);
42
- foreach ($bookings as $booking){
43
- $this->bookings[] = new EM_Booking($booking);
44
- }
45
- $this->spaces = $this->get_spaces();
46
- }elseif( is_array($data) ){
47
- foreach( $data as $EM_Booking ){
48
- if( get_class($EM_Booking) == 'EM_Booking'){
49
- $this->bookings[] = $EM_Booking;
50
- }
51
- }
52
- $this->get_event();
53
- }
54
- }
55
-
56
- /**
57
- * Add a booking into this event (or add spaces if person already booked this), checking that there's enough space for the event
58
- * @param $EM_Booking
59
- * @return boolean
60
- */
61
- function add( $EM_Booking ){
62
- global $wpdb,$EM_Mailer;
63
- $EM_Booking->get_spaces(true);
64
- if ( $this->get_available_spaces() >= $EM_Booking->get_spaces() ) {
65
- //Save the booking
66
- $email = false;
67
- $result = $EM_Booking->save();
68
- if($result){
69
- //Success
70
- $this->bookings[] = $EM_Booking;
71
- $email = $EM_Booking->email();
72
- if( get_option('dbem_bookings_approval') == 1 ){
73
- $this->feedback_message = __('Booking successful, pending confirmation (you will also receive an email once confirmed).', 'dbem');
74
- }else{
75
- $this->feedback_message = __('Booking successful.', 'dbem');
76
- }
77
- if(!$email){
78
- $this->feedback_message .= ' '.__('However, there were some problems whilst sending confirmation emails to you and/or the event contact person. You may want to contact them directly and letting them know of this error.', 'dbem');
79
- if( current_user_can('activate_plugins') ){
80
- if( count($EM_Booking->get_errors()) > 0 ){
81
- $this->feedback_message .= '<br/><strong>Errors:</strong> (only admins see this message)<br/><ul><li>'. implode('</li><li>', $EM_Booking->get_errors()).'</li></ul>';
82
- }else{
83
- $this->feedback_message .= '<br/><strong>No errors returned by mailer</strong> (only admins see this message)';
84
- }
85
- }
86
- }
87
- return true;
88
- }else{
89
- //Failure
90
- $this->errors[] = "<strong>".__('Booking could not be created','dbem').":</strong><br />". implode('<br />', $EM_Booking->errors);
91
- }
92
- } else {
93
- $this->add_error(__('Booking cannot be made, not enough spaces available!', 'dbem'));
94
- return false;
95
- }
96
- }
97
-
98
- /**
99
- * get POST data and create a booking for each ticket requested:
100
- * @return bool
101
- */
102
- function add_from_post(){
103
- $EM_Booking = new EM_booking();
104
- $result = $EM_Booking->get_post();
105
- if($result){
106
- $result = $this->add($EM_Booking);
107
- }else{
108
- $this->errors = array_merge($this->errors, $EM_Booking->errors);
109
- }
110
- return apply_filters('em_bookings_add_from_post',$result,$EM_Booking,$this);
111
- }
112
-
113
- /**
114
- * Smart event locator, saves a database read if possible. Note that if an event doesn't exist, a blank object will be created to prevent duplicates.
115
- */
116
- function get_event(){
117
- if( is_object($this->event) && get_class($this->event) == 'EM_Event' ){
118
- return $this->event;
119
- }elseif( count($this->bookings) > 0 ){
120
- foreach($this->bookings as $EM_Booking){
121
- $this->event = $EM_Booking->get_event();
122
- return $this->event;
123
- }
124
- }else{
125
- $this->event = new EM_Event();
126
- return $this->event;
127
- }
128
- }
129
-
130
- /**
131
- * Retrieve and save the bookings belonging to instance. If called again will return cached version, set $force_reload to true to create a new EM_Tickets object.
132
- * @param boolean $force_reload
133
- * @return EM_Tickets
134
- */
135
- function get_tickets( $force_reload = false ){
136
- if( !is_object($this->tickets) || $force_reload ){
137
- $this->tickets = new EM_Tickets($this->get_event());
138
- }
139
- return apply_filters('em_bookings_get_tickets', $this->tickets, $this);
140
- }
141
-
142
- /**
143
- * Returns EM_Tickets object with available tickets
144
- * @return EM_Tickets
145
- */
146
- function get_available_tickets(){
147
- $tickets = array();
148
- $timesamp = current_time('timestamp');
149
- foreach ($this->get_tickets() as $EM_Ticket){
150
- if( $EM_Ticket->is_available() ){
151
- //within time range
152
- if( $EM_Ticket->get_available_spaces() > 0 ){
153
- $tickets[] = $EM_Ticket;
154
- }
155
- }
156
- }
157
- $EM_Tickets = new EM_Tickets($tickets);
158
- return apply_filters('em_bookings_get_tickets', $EM_Tickets, $this);
159
- }
160
-
161
- function get_user_list(){
162
- $users = array();
163
- foreach( $this->get_bookings()->bookings as $EM_Booking ){
164
- $users[$EM_Booking->person->ID] = $EM_Booking->person;
165
- }
166
- return $users;
167
- }
168
-
169
- /**
170
- * does this ticket exist?
171
- * @return bool
172
- */
173
- function ticket_exists($ticket_id){
174
- $EM_Tickets = $this->get_tickets();
175
- foreach( $EM_Tickets->tickets as $EM_Ticket){
176
- if($EM_Ticket->id == $ticket_id){
177
- return apply_filters('em_bookings_ticket_exists',true, $EM_Ticket, $this);
178
- }
179
- }
180
- return apply_filters('em_bookings_ticket_exists',false, $EM_Ticket,$this);
181
- }
182
-
183
- /**
184
- * Delete bookings on this id
185
- * @return boolean
186
- */
187
- function delete(){
188
- global $wpdb;
189
- $booking_ids = array();
190
- if( is_object($this->event) ){
191
- $result = $wpdb->query("DELETE FROM ".$wpdb->prefix.EM_BOOKINGS_TABLE." WHERE event_id='{$this->event_id}'");
192
- }else{
193
- foreach( $this->bookings as $EM_Booking ){
194
- $booking_ids[] = $EM_Booking->id;
195
- }
196
- $result = $wpdb->query("DELETE FROM ".$wpdb->prefix.EM_BOOKINGS_TABLE." WHERE event_id IN (".implode(',',$booking_ids).")");
197
- }
198
- return ($result !== false);
199
- }
200
-
201
-
202
- /**
203
- * Will approve all supplied booking ids, which must be in the form of a numeric array or a single number.
204
- * @param array|int $booking_ids
205
- * @return boolean
206
- */
207
- function approve( $booking_ids ){
208
- $this->set_status(1, $booking_ids);
209
- return false;
210
- }
211
-
212
- /**
213
- * Will reject all supplied booking ids, which must be in the form of a numeric array or a single number.
214
- * @param array|int $booking_ids
215
- * @return boolean
216
- */
217
- function reject( $booking_ids ){
218
- return $this->set_status(2, $booking_ids);
219
- }
220
-
221
- /**
222
- * Will unapprove all supplied booking ids, which must be in the form of a numeric array or a single number.
223
- * @param array|int $booking_ids
224
- * @return boolean
225
- */
226
- function unapprove( $booking_ids ){
227
- return $this->set_status(0, $booking_ids);
228
- }
229
-
230
- /**
231
- * @param int $status
232
- * @param array|int $booking_ids
233
- * @return bool
234
- */
235
- function set_status($status, $booking_ids){
236
- //FIXME status should work with instantiated object
237
- //FIXME there is a vulnerability where any user can approve/reject bookings if they know the ID
238
- if( $this->array_is_numeric($booking_ids) ){
239
- //Get all the bookings
240
- $results = array();
241
- $mails = array();
242
- foreach( $booking_ids as $booking_id ){
243
- $EM_Booking = new EM_Booking($booking_id);
244
- if( !$EM_Booking->can_manage() ){
245
- $this->feedback_message = __('Bookings %s. Mails Sent.', 'dbem');
246
- return false;
247
- }
248
- $results[] = $EM_Booking->set_status($status);
249
- }
250
- if( !in_array('false',$results) ){
251
- $this->feedback_message = __('Bookings %s. Mails Sent.', 'dbem');
252
- return true;
253
- }else{
254
- //TODO Better error handling needed if some bookings fail approval/failure
255
- $this->feedback_message = __('An error occurred.', 'dbem');
256
- return false;
257
- }
258
- }elseif( is_numeric($booking_ids) || is_object($booking_ids) ){
259
- $EM_Booking = ( is_object($booking_ids) && get_class($booking_ids) == 'EM_Booking') ? $booking_ids : new EM_Booking($booking_ids);
260
- $result = $EM_Booking->set_status($status);
261
- $this->feedback_message = $EM_Booking->feedback_message;
262
- return $result;
263
- }
264
- return false;
265
- }
266
-
267
-
268
- /**
269
- * Get the total number of spaces this event has. This will show the lower value of event global spaces limit or total ticket spaces. Setting $force_refresh to true will recheck spaces, even if previously done so.
270
- * @param boolean $force_refresh
271
- * @return int
272
- */
273
- function get_spaces( $force_refresh=false ){
274
- if($force_refresh || $this->spaces == 0){
275
- $this->spaces = $this->get_tickets()->get_spaces();
276
- }
277
- return apply_filters('em_booking_get_spaces',$this->spaces,$this);
278
- }
279
-
280
- /**
281
- * Returns number of available spaces for this event. If approval of bookings is on, will include pending bookings depending on em option.
282
- * @return int
283
- */
284
- function get_available_spaces(){
285
- $available_spaces = 0;
286
- if( get_option('dbem_bookings_approval_reserved') == 1 ){
287
- $available_spaces = $this->get_spaces() - $this->get_booked_spaces() - $this->get_pending_spaces();
288
- }else{
289
- $available_spaces = $this->get_spaces() - $this->get_booked_spaces();
290
- }
291
- return apply_filters('get_available_spaces', $available_spaces, $this);
292
- }
293
-
294
- /**
295
- * Returns number of booked spaces for this event. If approval of bookings is on, will return number of booked confirmed spaces.
296
- * @return int
297
- */
298
- function get_booked_spaces(){
299
- $booked_spaces = 0;
300
- $EM_Bookings = $this->get_bookings(); //get bookings, automatically filtering approvals etc.
301
- foreach ( $EM_Bookings->bookings as $EM_Booking ){
302
- //never show cancelled status, nor pending if approvals required
303
- $booked_spaces += $EM_Booking->get_spaces();
304
- }
305
- return $booked_spaces;
306
- }
307
-
308
- /**
309
- * Gets number of pending spaces awaiting approval. Will return 0 if booking approval is not enabled.
310
- * @return int
311
- */
312
- function get_pending_spaces(){
313
- if( get_option('dbem_bookings_approval') == 0 ){
314
- return 0;
315
- }
316
- $pending = 0;
317
- foreach ( $this->bookings as $booking ){
318
- if($booking->status == 0){
319
- $pending += $booking->get_spaces();
320
- }
321
- }
322
- return $pending;
323
- }
324
-
325
- /**
326
- * Gets number of bookings (not spaces). If booking approval is enabled, only the number of approved bookings will be shown.
327
- * @return EM_Bookings
328
- */
329
- function get_bookings(){
330
- $confirmed = array();
331
- foreach ( $this->bookings as $booking ){
332
- if( $booking->status == 1 || (get_option('dbem_bookings_approval') == 0 && $booking->status < 2) ){
333
- $confirmed[] = $booking;
334
- }
335
- }
336
- $EM_Bookings = new EM_Bookings($confirmed);
337
- return $EM_Bookings;
338
- }
339
-
340
- /**
341
- * Get pending bookings. If booking approval is disabled, will return no bookings.
342
- * @return EM_Bookings
343
- */
344
- function get_pending_bookings(){
345
- if( get_option('dbem_bookings_approval') == 0 ){
346
- return array();
347
- }
348
- $pending = array();
349
- foreach ( $this->bookings as $booking ){
350
- if($booking->status == 0){
351
- $pending[] = $booking;
352
- }
353
- }
354
- $EM_Bookings = new EM_Bookings($pending);
355
- return $EM_Bookings;
356
- }
357
-
358
- /**
359
- * Get rejected bookings. If booking approval is disabled, will return no bookings.
360
- * @return array EM_Bookings
361
- */
362
- function get_rejected_bookings(){
363
- $rejected = array();
364
- foreach ( $this->bookings as $booking ){
365
- if($booking->status == 2){
366
- $rejected[] = $booking;
367
- }
368
- }
369
- $EM_Bookings = new EM_Bookings($rejected);
370
- return $EM_Bookings;
371
- }
372
-
373
- /**
374
- * Get cancelled bookings.
375
- * @return array EM_Booking
376
- */
377
- function get_cancelled_bookings(){
378
- $cancelled = array();
379
- foreach ( $this->bookings as $booking ){
380
- if($booking->status == 3){
381
- $cancelled[] = $booking;
382
- }
383
- }
384
- $EM_Bookings = new EM_Bookings($cancelled);
385
- return $EM_Bookings;
386
- }
387
-
388
- /**
389
- * Checks if a person with similar details has booked for this before
390
- * @param $person_id
391
- * @return EM_Booking
392
- */
393
- function find_previous_booking($EM_Booking){
394
- //First see if we have a similar person on record that's making this booking
395
- $EM_Booking->person->load_similar();
396
- //If person exists on record, see if they've booked this event before, if so return the booking.
397
- if( is_numeric($EM_Booking->person->ID) && $EM_Booking->person->ID > 0 ){
398
- $EM_Booking->person_id = $EM_Booking->person->ID;
399
- foreach ($this->bookings as $booking){
400
- if( $booking->person_id == $EM_Booking->person->ID ){
401
- return $booking;
402
- }
403
- }
404
- }
405
- return false;
406
- }
407
-
408
- /**
409
- * Get bookings that match the array of arguments passed.
410
- * @return array
411
- * @static
412
- */
413
- function get( $args = array() ){
414
- global $wpdb,$current_user;
415
- $bookings_table = $wpdb->prefix . EM_BOOKINGS_TABLE;
416
- $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
417
- $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
418
-
419
- //Quick version, we can accept an array of IDs, which is easy to retrieve
420
- if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
421
- //We can just get all the events here and return them
422
- $sql = "
423
- SELECT * FROM $bookings_table b
424
- LEFT JOIN $events_table e ON e.event_id=b.event_id
425
- WHERE booking_id".implode(" OR booking_id=", $args);
426
- $results = $wpdb->get_results(apply_filters('em_bookings_get_sql',$sql),ARRAY_A);
427
- $bookings = array();
428
- foreach($results as $result){
429
- $bookings[] = new EM_Booking($result);
430
- }
431
- return $bookings; //We return all the bookings matched as an EM_Booking array.
432
- }
433
-
434
- //We assume it's either an empty array or array of search arguments to merge with defaults
435
- $args = self::get_default_search($args);
436
- $limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
437
- $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
438
-
439
- //Get the default conditions
440
- $conditions = self::build_sql_conditions($args);
441
- //Put it all together
442
- $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
443
-
444
- //Get ordering instructions
445
- $EM_Booking = new EM_Booking();
446
- $accepted_fields = $EM_Booking->get_fields(true);
447
- $orderby = self::build_sql_orderby($args, $accepted_fields);
448
- //Now, build orderby sql
449
- $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
450
-
451
- //Create the SQL statement and execute
452
- $sql = "
453
- SELECT * FROM $bookings_table
454
- LEFT JOIN $events_table ON {$events_table}.event_id={$bookings_table}.event_id
455
- LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
456
- $where
457
- $orderby_sql
458
- $limit $offset
459
- ";
460
-
461
- $results = $wpdb->get_results( apply_filters('em_events_get_sql',$sql, $args), ARRAY_A);
462
-
463
- //If we want results directly in an array, why not have a shortcut here?
464
- if( $args['array'] == true ){
465
- return $results;
466
- }
467
-
468
- //Make returned results EM_Booking objects
469
- $results = (is_array($results)) ? $results:array();
470
- $bookings = array();
471
- foreach ( $results as $booking ){
472
- $bookings[] = new EM_Booking($booking);
473
- }
474
- $EM_Bookings = new EM_Bookings($bookings);
475
- return apply_filters('em_bookings_get', $EM_Bookings);
476
- }
477
-
478
-
479
- //List of patients in the patient database, that a user can choose and go on to edit any previous treatment data, or add a new admission.
480
- function export_csv() {
481
- global $EM_Event;
482
- if($EM_Event->id != $this->event->id ){
483
- $event = new EM_Event($this->event->id);
484
- $event_name = $event->name;
485
- }else{
486
- $event_name = $EM_Event->name;
487
- }
488
- // The name of the file on the user's pc
489
- $file_name = sanitize_title($event_name). "-bookings.csv";
490
-
491
- header("Content-Type: application/octet-stream");
492
- header("Content-Disposition: Attachment; filename=$file_name");
493
-
494
- //Headers
495
- $labels = array(
496
- 'ID',
497
- 'Name',
498
- 'Email',
499
- 'Phone',
500
- 'Date',
501
- 'Status',
502
- 'Spaces',
503
- 'Comment'
504
- );
505
- $file = sprintf(__('Booking details for "%s" as of %s','dbem'),$event_name, date_i18n('D d M Y h:i', current_time('timestamp'))) . "\n";
506
- $file = '"'. implode('","', $labels). '"' . "\n";
507
-
508
- //Rows
509
- foreach( $this->bookings as $EM_Booking ) {
510
- $row = array(
511
- $EM_Booking->id,
512
- $EM_Booking->person->display_name,
513
- $EM_Booking->person->user_email,
514
- $EM_Booking->person->phone,
515
- date('Y-m-d h:i', $EM_Booking->timestamp),
516
- $EM_Booking->get_spaces(),
517
- $EM_Booking->get_status(),
518
- $EM_Booking->comment
519
- );
520
- //Display all values
521
- foreach($row as $value){
522
- $value = str_replace('"', '""', $value);
523
- $value = str_replace("=", "", $value);
524
- $file .= '"' . preg_replace("/\n\r|\r\n|\n|\r/", ". ", $value) . '",';
525
- }
526
- $file .= "\n";
527
- }
528
-
529
- // $file holds the data
530
- echo $file;
531
- $file = "";
532
- }
533
-
534
- /* Overrides EM_Object method to apply a filter to result
535
- * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
536
- */
537
- function build_sql_conditions( $args = array() ){
538
- $conditions = apply_filters( 'em_bookings_build_sql_conditions', parent::build_sql_conditions($args), $args );
539
- if( is_numeric($args['status']) ){
540
- $conditions['status'] = 'booking_status='.$args['status'];
541
- }
542
- return apply_filters('em_bookings_build_sql_conditions', $conditions, $args);
543
- }
544
-
545
- /* Overrides EM_Object method to apply a filter to result
546
- * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
547
- */
548
- function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
549
- return apply_filters( 'em_bookings_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')), $args, $accepted_fields, $default_order );
550
- }
551
-
552
- /*
553
- * Adds custom Events search defaults
554
- * @param array $array
555
- * @return array
556
- * @uses EM_Object#get_default_search()
557
- */
558
- function get_default_search( $array = array() ){
559
- $defaults = array(
560
- 'status' => false,
561
- 'person' => true //to add later, search by person's bookings...
562
- );
563
- if( true || is_admin() ){
564
- //figure out default owning permissions
565
- if( !current_user_can('edit_others_events') ){
566
- $defaults['owner'] = get_current_user_id();
567
- }else{
568
- $defaults['owner'] = false;
569
- }
570
- }
571
- return apply_filters('em_bookings_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
572
- }
573
-
574
- //Iterator Implementation
575
- public function rewind(){
576
- reset($this->bookings);
577
- }
578
- public function current(){
579
- $var = current($this->bookings);
580
- return $var;
581
- }
582
- public function key(){
583
- $var = key($this->bookings);
584
- return $var;
585
- }
586
- public function next(){
587
- $var = next($this->bookings);
588
- return $var;
589
- }
590
- public function valid(){
591
- $key = key($this->bookings);
592
- $var = ($key !== NULL && $key !== FALSE);
593
- return $var;
594
- }
595
- }
596
  ?>
1
+ <?php
2
+ /**
3
+ * Deals with the booking info for an event
4
+ * @author marcus
5
+ *
6
+ */
7
+ class EM_Bookings extends EM_Object{
8
+
9
+ /**
10
+ * Array of EM_Booking objects for a specific event
11
+ * @var array
12
+ */
13
+ var $bookings = array();
14
+ /**
15
+ * Event ID
16
+ * @var int
17
+ */
18
+ var $event_id;
19
+ /**
20
+ * Number of seats for this event
21
+ * @var int
22
+ */
23
+ var $seats;
24
+
25
+ var $feedback_message = "";
26
+ var $errors = array();
27
+
28
+ /**
29
+ * Creates an EM_Bookings instance,
30
+ * @param EM_Event $event
31
+ * @return null
32
+ */
33
+ function EM_Bookings( $event = false ){
34
+ if( is_object($event) && get_class($event) == "EM_Event" ){ //Creates a blank bookings object if needed
35
+ global $wpdb;
36
+ $this->event_id = $event->id;
37
+ $this->seats = $event->seats;
38
+ $sql = "SELECT * FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." b, ". $wpdb->prefix . EM_PEOPLE_TABLE ." p WHERE event_id ='{$this->event_id}' AND p.person_id=b.person_id";
39
+ $bookings = $wpdb->get_results($sql, ARRAY_A);
40
+ foreach ($bookings as $booking){
41
+ $this->bookings[] = new EM_Booking($booking);
42
+ }
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Add a booking into this event (or add seats if person already booked this), checking that there's enough space for the event
48
+ * @param $EM_Booking
49
+ * @return boolean
50
+ */
51
+ function add( $EM_Booking ){
52
+ global $wpdb,$EM_Mailer;
53
+ if ( $this->get_available_seats() >= $EM_Booking->seats ) {
54
+ $EM_Booking->event_id = $this->event_id;
55
+ // checking whether the booker has already booked places
56
+ $previous_booking = $this->find_previous_booking( $EM_Booking );
57
+ $email = false;
58
+ if ( is_object($previous_booking) ) {
59
+ //Previously booked, so we add these seats to the booking
60
+ $new_seats = $EM_Booking->seats;
61
+ $EM_Booking = $previous_booking;
62
+ $EM_Booking->seats += $new_seats;
63
+ $result = $EM_Booking->save();
64
+ if($result){
65
+ //remove old booking
66
+ foreach($this->bookings as $key=>$booking){
67
+ if($booking->id == $EM_Booking->id){ unset($this->bookings[$key]); }
68
+ }
69
+ $this->bookings[] = $EM_Booking;
70
+ $email = $EM_Booking->email();
71
+ }
72
+ } else {
73
+ //New booking, so let's save the booking
74
+ $result = $EM_Booking->save();
75
+ if($result){
76
+ $this->bookings[] = $EM_Booking;
77
+ $email = $EM_Booking->email();
78
+ }
79
+ }
80
+ if($result){
81
+ //Success
82
+ if( get_option('dbem_bookings_approval') == 1 ){
83
+ $this->feedback_message = __('Booking successful, pending confirmation (you will also receive an email once confirmed).', 'dbem');
84
+ }else{
85
+ $this->feedback_message = __('Booking successful.', 'dbem');
86
+ }
87
+ if(!$email){
88
+ $this->feedback_message .= ' '.__('However, there were some problems whilst sending confirmation emails to you and/or the event contact person. You may want to contact them directly and letting them know of this error.', 'dbem');
89
+ if( current_user_can('activate_plugins') ){
90
+ if( is_array($this->errors) && count($this->errors) > 0 ){
91
+ $this->feedback_message .= '<br/><strong>Errors:</strong> (only admins see this message)<br/><ul><li>'. implode('</li><li>', $EM_Mailer->errors).'</li></ul>';
92
+ }else{
93
+ $this->feedback_message .= '<br/><strong>No errors returned by mailer</strong> (only admins see this message)';
94
+ }
95
+ }
96
+ }
97
+ return true;
98
+ }else{
99
+ //Failure
100
+ $this->errors[] = "<strong>".__('Booking could not be created','dbem').":</strong><br />". implode('<br />', $EM_Booking->errors);
101
+ }
102
+ } else {
103
+ $this->errors[] = __('Booking cannot be made, not enough seats available!', 'dbem');
104
+ return false;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Delete bookings on this id
110
+ * @return boolean
111
+ */
112
+ function delete(){
113
+ global $wpdb;
114
+ $result = $wpdb->query("DELETE FROM ".$wpdb->prefix.EM_BOOKINGS_TABLE." WHERE event_id='{$this->event_id}'");
115
+ return ($result);
116
+ }
117
+
118
+
119
+ /**
120
+ * Will approve all supplied booking ids, which must be in the form of a numeric array or a single number.
121
+ * @param array|int $booking_ids
122
+ * @return boolean
123
+ */
124
+ function approve( $booking_ids ){
125
+ $this->set_status(1, $booking_ids);
126
+ return false;
127
+ }
128
+
129
+ /**
130
+ * Will reject all supplied booking ids, which must be in the form of a numeric array or a single number.
131
+ * @param array|int $booking_ids
132
+ * @return boolean
133
+ */
134
+ function reject( $booking_ids ){
135
+ return $this->set_status(2, $booking_ids);
136
+ }
137
+
138
+ /**
139
+ * Will unapprove all supplied booking ids, which must be in the form of a numeric array or a single number.
140
+ * @param array|int $booking_ids
141
+ * @return boolean
142
+ */
143
+ function unapprove( $booking_ids ){
144
+ return $this->set_status(0, $booking_ids);
145
+ }
146
+
147
+ /**
148
+ * @param int $status
149
+ * @param array|int $booking_ids
150
+ * @return bool
151
+ */
152
+ function set_status($status, $booking_ids){
153
+ //FIXME there is a vulnerability where any user can approve/reject bookings if they know the ID
154
+ if( EM_Object::array_is_numeric($booking_ids) ){
155
+ //Get all the bookings
156
+ $results = array();
157
+ $mails = array();
158
+ foreach( $booking_ids as $booking_id ){
159
+ $EM_Booking = new EM_Booking($booking_id);
160
+ $results[] = $EM_Booking->set_status($status);
161
+ }
162
+ if( !in_array('false',$results) ){
163
+ $this->feedback_message = __('Bookings %s. Mails Sent.', 'dbem');
164
+ return true;
165
+ }else{
166
+ //TODO Better error handling needed if some bookings fail approval/failure
167
+ $this->feedback_message = __('An error occurred.', 'dbem');
168
+ return false;
169
+ }
170
+ }elseif( is_numeric($booking_ids) || is_object($booking_ids) ){
171
+ $EM_Booking = ( is_object($booking_ids) && get_class($booking_ids) == 'EM_Booking') ? $booking_ids : new EM_Booking($booking_ids);
172
+ $result = $EM_Booking->set_status($status);
173
+ $this->feedback_message = $EM_Booking->feedback_message;
174
+ return $result;
175
+ }
176
+ return false;
177
+ }
178
+
179
+ /**
180
+ * Returns number of available seats for this event. If approval of bookings is on, will include pending bookings depending on em option.
181
+ * @return int
182
+ */
183
+ function get_available_seats(){
184
+ $booked_seats = 0;
185
+ if( get_option('dbem_bookings_approval_reserved') == 1 ){
186
+ return $this->seats - $this->get_booked_seats() - $this->get_pending_seats();
187
+ }else{
188
+ return $this->seats - $this->get_booked_seats();
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Returns number of booked seats for this event. If approval of bookings is on, will return number of booked confirmed seats.
194
+ * @return int
195
+ */
196
+ function get_booked_seats(){
197
+ $booked_seats = 0;
198
+ foreach ( $this->bookings as $booking ){
199
+ if( $booking->status != 3 && (get_option('dbem_bookings_approval') == 0 || $booking->status == 1) ){
200
+ $booked_seats += $booking->seats;
201
+ }
202
+ }
203
+ return $booked_seats;
204
+ }
205
+
206
+ /**
207
+ * Gets number of pending seats awaiting approval. Will return 0 if booking approval is not enabled.
208
+ * @return int
209
+ */
210
+ function get_pending_seats(){
211
+ if( get_option('dbem_bookings_approval') == 0 ){
212
+ return 0;
213
+ }
214
+ $pending = 0;
215
+ foreach ( $this->bookings as $booking ){
216
+ if($booking->status == 0){
217
+ $pending += $booking->seats;
218
+ }
219
+ }
220
+ return $pending;
221
+ }
222
+
223
+ /**
224
+ * Gets number of bookings (not seats). If booking approval is enabled, only the number of approved bookings will be shown.
225
+ * @return array EM_Booking
226
+ */
227
+ function get_bookings(){
228
+ $confirmed = array();
229
+ foreach ( $this->bookings as $booking ){
230
+ if( $booking->status == 1 || (get_option('dbem_bookings_approval') == 0 && $booking->status < 2) ){
231
+ $confirmed[] = $booking;
232
+ }
233
+ }
234
+ return $confirmed;
235
+ }
236
+
237
+ /**
238
+ * Get pending bookings. If booking approval is disabled, will return no bookings.
239
+ * @return array EM_Booking
240
+ */
241
+ function get_pending_bookings(){
242
+ if( get_option('dbem_bookings_approval') == 0 ){
243
+ return array();
244
+ }
245
+ $pending = array();
246
+ foreach ( $this->bookings as $booking ){
247
+ if($booking->status == 0){
248
+ $pending[] = $booking;
249
+ }
250
+ }
251
+ return $pending;
252
+ }
253
+
254
+ /**
255
+ * Get rejected bookings.
256
+ * @return array EM_Booking
257
+ */
258
+ function get_rejected_bookings(){
259
+ $pending = array();
260
+ foreach ( $this->bookings as $booking ){
261
+ if($booking->status == 2){
262
+ $pending[] = $booking;
263
+ }
264
+ }
265
+ return $pending;
266
+ }
267
+
268
+ /**
269
+ * Get cancelled bookings.
270
+ * @return array EM_Booking
271
+ */
272
+ function get_cancelled_bookings(){
273
+ $pending = array();
274
+ foreach ( $this->bookings as $booking ){
275
+ if($booking->status == 3){
276
+ $pending[] = $booking;
277
+ }
278
+ }
279
+ return $pending;
280
+ }
281
+
282
+ /**
283
+ * Checks if a person with similar details has booked for this before
284
+ * @param $person_id
285
+ * @return EM_Booking
286
+ */
287
+ function find_previous_booking($EM_Booking){
288
+ //First see if we have a similar person on record that's making this booking
289
+ $EM_Booking->person->load_similar();
290
+ //If person exists on record, see if they've booked this event before, if so return the booking.
291
+ if( is_numeric($EM_Booking->person->id) && $EM_Booking->person->id > 0 ){
292
+ $EM_Booking->person_id = $EM_Booking->person->id;
293
+ foreach ($this->bookings as $booking){
294
+ if( $booking->person_id == $EM_Booking->person->id ){
295
+ return $booking;
296
+ }
297
+ }
298
+ }
299
+ return false;
300
+ }
301
+
302
+
303
+ /**
304
+ * Get all pending bookings for this event
305
+ */
306
+ function get_pending(){
307
+ $pending = array();
308
+ foreach($this->bookings as $booking){
309
+ if($booking->status == 0){
310
+ $pending[] = $booking;
311
+ }
312
+ }
313
+ return $pending;
314
+ }
315
+
316
+ /**
317
+ * Gets the pending number of bookings as a raw associative array.
318
+ * @return array
319
+ */
320
+ function get( $args = array() ){
321
+ global $wpdb,$current_user;
322
+ $bookings_table = $wpdb->prefix . EM_BOOKINGS_TABLE;
323
+ $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
324
+ $people_table = $wpdb->prefix . EM_PEOPLE_TABLE;
325
+ $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
326
+
327
+ //Quick version, we can accept an array of IDs, which is easy to retrieve
328
+ if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
329
+ //We can just get all the events here and return them
330
+ $sql = "
331
+ SELECT * FROM $bookings_table b
332
+ LEFT JOIN $events_table e ON e.event_id=b.event_id
333
+ LEFT JOIN $people_table p ON p.person_id=b.person_id
334
+ WHERE booking_id".implode(" OR booking_id=", $args);
335
+ $results = $wpdb->get_results(apply_filters('em_bookings_get_sql',$sql),ARRAY_A);
336
+ $bookings = array();
337
+ foreach($results as $result){
338
+ $bookings[$result['event_id']] = new EM_Event($result);
339
+ }
340
+ return $bookings; //We return all the events matched as an EM_Event array.
341
+ }
342
+
343
+ //We assume it's either an empty array or array of search arguments to merge with defaults
344
+ $args = self::get_default_search($args);
345
+ $limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
346
+ $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
347
+
348
+ //Get the default conditions
349
+ $conditions = self::build_sql_conditions($args);
350
+ //Put it all together
351
+ $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
352
+
353
+ //Get ordering instructions
354
+ $EM_Booking = new EM_Booking();
355
+ $accepted_fields = $EM_Booking->get_fields(true);
356
+ $orderby = self::build_sql_orderby($args, $accepted_fields);
357
+ //Now, build orderby sql
358
+ $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
359
+
360
+ //Create the SQL statement and execute
361
+ $sql = "
362
+ SELECT * FROM $bookings_table
363
+ LEFT JOIN $events_table ON {$events_table}.event_id={$bookings_table}.event_id
364
+ LEFT JOIN $people_table ON {$people_table}.person_id={$bookings_table}.person_id
365
+ LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
366
+ $where
367
+ $orderby_sql
368
+ $limit $offset
369
+ ";
370
+
371
+ $results = $wpdb->get_results( apply_filters('em_events_get_sql',$sql, $args), ARRAY_A);
372
+
373
+ //If we want results directly in an array, why not have a shortcut here?
374
+ if( $args['array'] == true ){
375
+ return $results;
376
+ }
377
+
378
+ //Make returned results EM_Booking objects
379
+ $results = (is_array($results)) ? $results:array();
380
+ $bookings = array();
381
+ foreach ( $results as $booking ){
382
+ $bookings[] = new EM_Booking($booking);
383
+ }
384
+
385
+ return apply_filters('em_bookings_get', $bookings);
386
+ }
387
+
388
+
389
+ //List of patients in the patient database, that a user can choose and go on to edit any previous treatment data, or add a new admission.
390
+ function export_csv() {
391
+ global $EM_Event;
392
+ if($EM_Event->id != $this->event_id ){
393
+ $event = new EM_Event($this->event_id);
394
+ $event_name = $event->name;
395
+ }else{
396
+ $event_name = $EM_Event->name;
397
+ }
398
+ // The name of the file on the user's pc
399
+ $file_name = sanitize_title($event_name). "-bookings.csv";
400
+
401
+ header("Content-Type: application/octet-stream");
402
+ header("Content-Disposition: Attachment; filename=$file_name");
403
+
404
+ //Headers
405
+ $labels = array(
406
+ 'ID',
407
+ 'Name',
408
+ 'Email',
409
+ 'Phone',
410
+ 'Date',
411
+ 'Status',
412
+ 'Spaces',
413
+ 'Comment'
414
+ );
415
+ $file = sprintf(__('Booking details for "%s" as of %s','dbem'),$event_name, date_i18n('D d M Y h:i', current_time('timestamp'))) . "\n";
416
+ $file = '"'. strtolower(implode('","', $labels)). '"' . "\n";
417
+
418
+ //Rows
419
+ foreach( $this->bookings as $EM_Booking ) {
420
+ $row = array(
421
+ $EM_Booking->id,
422
+ $EM_Booking->person->name,
423
+ $EM_Booking->person->email,
424
+ $EM_Booking->person->phone,
425
+ date('Y-m-d h:i', $EM_Booking->timestamp),
426
+ $EM_Booking->seats,
427
+ $EM_Booking->get_status(),
428
+ $EM_Booking->comment
429
+ );
430
+ //Display all values
431
+ foreach($row as $value){
432
+ $value = str_replace('"', '""', $value);
433
+ $value = str_replace("=", "", $value);
434
+ $file .= '"' . preg_replace("/\n\r|\r\n|\n|\r/", ". ", $value) . '",';
435
+ }
436
+ $file .= "\n";
437
+ }
438
+
439
+ // $file holds the data
440
+ echo $file;
441
+ $file = "";
442
+ }
443
+
444
+ /* Overrides EM_Object method to apply a filter to result
445
+ * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
446
+ */
447
+ function build_sql_conditions( $args = array() ){
448
+ $conditions = apply_filters( 'em_bookings_build_sql_conditions', parent::build_sql_conditions($args), $args );
449
+ if( is_numeric($args['status']) ){
450
+ $conditions['status'] = 'booking_status='.$args['status'];
451
+ }
452
+ return apply_filters('em_bookings_build_sql_conditions', $conditions, $args);
453
+ }
454
+
455
+ /* Overrides EM_Object method to apply a filter to result
456
+ * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
457
+ */
458
+ function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
459
+ return apply_filters( 'em_bookings_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')), $args, $accepted_fields, $default_order );
460
+ }
461
+
462
+ /*
463
+ * Adds custom Events search defaults
464
+ * @param array $array
465
+ * @return array
466
+ * @uses EM_Object#get_default_search()
467
+ */
468
+ function get_default_search( $array = array() ){
469
+ $defaults = array(
470
+ 'status' => false,
471
+ 'person' => true //to add later, search by person's bookings...
472
+ );
473
+ if( true || is_admin() ){
474
+ //figure out default owning permissions
475
+ switch( get_option('dbem_permissions_events') ){
476
+ case 0:
477
+ $defaults['owner'] = get_current_user_id();
478
+ break;
479
+ case 1:
480
+ $defaults['owner'] = false;
481
+ break;
482
+ }
483
+ $defaults['owner'] = ( em_verify_admin() ) ? false:$defaults['owner'];
484
+ }
485
+ return apply_filters('em_bookings_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
486
+ }
487
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
  ?>
classes/em-calendar.php CHANGED
@@ -1,368 +1,366 @@
1
- <?php
2
- class EM_Calendar extends EM_Object {
3
-
4
- function init(){
5
- add_action('wp_head', array('EM_Calendar', 'insert_js'));
6
- }
7
-
8
- function output($args = array()) {
9
- global $wpdb;
10
-
11
- $args = self::get_default_search($args);
12
- $full = $args['full']; //For ZDE, don't delete pls
13
- $month = $args['month'];
14
- $year = $args['year'];
15
- $long_events = $args['long_events'];
16
-
17
- $week_starts_on_sunday = get_option('dbem_week_starts_sunday');
18
- $start_of_week = get_option('start_of_week');
19
-
20
- if( !(is_numeric($month) && $month <= 12 && $month > 0) ) {
21
- $month = date('m');
22
- }
23
- if( !( is_numeric($year) ) ){
24
- $year = date('Y');
25
- }
26
-
27
- // Get the first day of the month
28
- $month_start = mktime(0,0,0,$month, 1, $year);
29
- // Get friendly month name
30
- $month_name = date('M',$month_start);
31
- // Figure out which day of the week
32
- // the month starts on.
33
- $month_start_day = date('D', $month_start);
34
-
35
- switch($month_start_day){
36
- case "Sun": $offset = 0; break;
37
- case "Mon": $offset = 1; break;
38
- case "Tue": $offset = 2; break;
39
- case "Wed": $offset = 3; break;
40
- case "Thu": $offset = 4; break;
41
- case "Fri": $offset = 5; break;
42
- case "Sat": $offset = 6; break;
43
- }
44
- //We need to go back to the WP defined day when the week started, in case the event day is near the end
45
- $offset -= $start_of_week;
46
- if($offset<0)
47
- $offset += 7;
48
-
49
- // determine how many days are in the last month.
50
- $month_last = $month-1;
51
- $month_next = $month+1;
52
- $year_last = $year;
53
- $year_next = $year;
54
- if($month == 1) {
55
- $month_last = 12;
56
- $year_last = $year -1;
57
- }
58
- $num_days_last = self::days_in_month($month_last, $year_last);
59
-
60
- // determine how many days are in the current month.
61
- $num_days_current = self::days_in_month($month, $year);
62
- // Build an array for the current days
63
- // in the month
64
- for($i = 1; $i <= $num_days_current; $i++){
65
- $num_days_array[] = mktime(0,0,0,$month, $i, $year);
66
- }
67
- // Build an array for the number of days
68
- // in last month
69
- for($i = 1; $i <= $num_days_last; $i++){
70
- $num_days_last_array[] = mktime(0,0,0,$month_last, $i, $year_last);
71
- }
72
- // If the $offset from the starting day of the
73
- // week happens to be Sunday, $offset would be 0,
74
- // so don't need an offset correction.
75
-
76
- if($offset > 0){
77
- $offset_correction = array_slice($num_days_last_array, -$offset, $offset);
78
- $new_count = array_merge($offset_correction, $num_days_array);
79
- $offset_count = count($offset_correction);
80
- } else { // The else statement is to prevent building the $offset array.
81
- $offset_count = 0;
82
- $new_count = $num_days_array;
83
- }
84
- // count how many days we have with the two
85
- // previous arrays merged together
86
- $current_num = count($new_count);
87
-
88
- // Since we will have 5 HTML table rows (TR)
89
- // with 7 table data entries (TD)
90
- // we need to fill in 35 TDs
91
- // so, we will have to figure out
92
- // how many days to appened to the end
93
- // of the final array to make it 35 days.
94
-
95
-
96
- if($current_num > 35){
97
- $num_weeks = 6;
98
- $outset = (42 - $current_num);
99
- } elseif($current_num < 35){
100
- $num_weeks = 5;
101
- $outset = (35 - $current_num);
102
- }
103
- if($current_num == 35){
104
- $num_weeks = 5;
105
- $outset = 0;
106
- }
107
- // Outset Correction
108
- for($i = 1; $i <= $outset; $i++){
109
- $new_count[] = mktime(0,0,0,$month_next, $i, $year_next);
110
- }
111
- // Now let's "chunk" the $all_days array
112
- // into weeks. Each week has 7 days
113
- // so we will array_chunk it into 7 days.
114
- $weeks = array_chunk($new_count, 7);
115
-
116
-
117
-
118
- // Build Previous and Next Links
119
- $base_link = "?".$_SERVER['QUERY_STRING']."&amp;";
120
-
121
- $full ? $link_extra_class = "full-link" : $link_extra_class = '';
122
- //Get an array of arguments that don't include default valued args
123
- $link_args = self::get_link_args($args);
124
-
125
- //Get the previous link
126
- if($month == 1){
127
- $back_month = 12;
128
- $back_year = $year-1;
129
- } else {
130
- $back_month = $month -1;
131
- $back_year = $year;
132
- }
133
- $previous_link = "<a class='em-calnav $link_extra_class' href='?ajaxCalendar=1&amp;month={$back_month}&amp;year={$back_year}&amp;{$link_args}'>&lt;&lt;</a>";
134
-
135
- //Now the next
136
- if($month == 12){
137
- $next_month = 1;
138
- $next_year = $year+1;
139
- } else {
140
- $next_month = $month + 1;
141
- $next_year = $year;
142
- }
143
- $next_link = "<a class='em-calnav $link_extra_class' href='?ajaxCalendar=1&amp;month={$next_month}&amp;year={$next_year}&amp;{$link_args}'>&gt;&gt;</a>";
144
-
145
-
146
- $class = ($full) ? 'dbem-calendar-full' : 'dbem-calendar';
147
- $calendar="<div class='$class'><div style='display:none' class='month_n'>$month</div><div class='year_n' style='display:none' >$year</div>";
148
-
149
- $weekdays = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
150
- $n = 0 ;
151
- while( $n < $start_of_week ) {
152
- $last_day = array_shift($weekdays);
153
- $weekdays[]= $last_day;
154
- $n++;
155
- }
156
-
157
- $days_initials = "";
158
- foreach($weekdays as $weekday) {
159
- $days_initials .= "<td>".self::translate_and_trim($weekday)."</td>";
160
- }
161
- $full ? $fullclass = 'fullcalendar' : $fullclass='';
162
- // Build the heading portion of the calendar table
163
- $calendar .= "<table class='dbem-calendar-table $fullclass'>\n".
164
- "<thead>\n<tr>\n".
165
- "<td>$previous_link</td><td class='month_name' colspan='5'>". apply_filters('dbem_calendar_output_month', ucfirst(date_i18n('M', $month_start)), $month_start, $args)." $year</td><td>$next_link</td>\n".
166
- "</tr>\n</thead>\n".
167
- "<tr class='days-names'>\n".
168
- $days_initials.
169
- "</tr>\n";
170
-
171
- // Now we break each key of the array
172
- // into a week and create a new table row for each
173
- // week with the days of that week in the table data
174
-
175
- $i = 0;
176
- $current_date = date('Y-m-d', current_time('timestamp'));
177
- foreach ( $weeks as $week ) {
178
- $calendar .= "<tr>\n";
179
- foreach ( $week as $d ) {
180
- if ($i < $offset_count) { //if it is PREVIOUS month
181
- $calendar .= "<td class='eventless-pre'>" . date ( 'j', $d ) . "</td>\n";
182
- }
183
- if (($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)) { // if it is THIS month
184
- $day = date ( 'j', $d );
185
- if ( $current_date == date('Y-m-d', $d) ){
186
- $calendar .= "<td class='eventless-today'>$day</td>\n";
187
- } else {
188
- $calendar .= "<td class='eventless'>$day</td>\n";
189
- }
190
- } elseif (($outset > 0)) { //if it is NEXT month
191
- if (($i >= ($num_weeks * 7) - $outset)) {
192
- $calendar .= "<td class='eventless-post'>" . date ( 'j', $d ) . "</td>\n";
193
- }
194
- }
195
- $i ++;
196
- }
197
- $calendar .= "</tr>\n";
198
- }
199
-
200
- $calendar .= " </table>\n</div>";
201
-
202
- // query the database for events in this time span
203
- if ($month == 1) {
204
- $month_pre=12;
205
- $month_post=2;
206
- $year_pre=$year-1;
207
- $year_post=$year;
208
- } elseif($month == 12) {
209
- $month_pre=11;
210
- $month_post=1;
211
- $year_pre=$year;
212
- $year_post=$year+1;
213
- } else {
214
- $month_pre=$month-1;
215
- $month_post=$month+1;
216
- $year_pre=$year;
217
- $year_post=$year;
218
- }
219
- $args['year'] = array($year_pre, $year_post);
220
- $args['month'] = array($month_pre, $month_post);
221
- $events = EM_Events::get($args);
222
-
223
- $eventful_days= array();
224
- if($events){
225
- //Go through the events and slot them into the right d-m index
226
- foreach($events as $event) {
227
- $event = apply_filters('em_calendar_output_loop_start', $event);
228
- if( $long_events ){
229
- //If $long_events is set then show a date as eventful if there is an multi-day event which runs during that day
230
- $event_start_date = mktime(0,0,0,$month_pre,1,$year_pre);
231
- $event_end_date = mktime(0,0,0,$month_post,date('t', $event_start_date),$year_post );
232
- if( $event_end_date == '' ) $event_end_date = $event_start_date;
233
- while( $event_start_date <= $event->end ){
234
- //Ensure date is within event dates, if so add to eventful days array
235
- if( $event_start_date > $event->start - (86400) ){ //subtract a day since start may be later in day
236
- $event_eventful_date = date('Y-m-d', $event_start_date);
237
- if( array_key_exists($event_eventful_date, $eventful_days) && is_array($eventful_days[$event_eventful_date]) ){
238
- $eventful_days[$event_eventful_date][] = $event;
239
- } else {
240
- $eventful_days[$event_eventful_date] = array($event);
241
- }
242
- }
243
- $event_start_date += (86400); //add a day
244
- }
245
- }else{
246
- //Only show events on the day that they start
247
- if( isset($eventful_days[$event->start_date]) && is_array($eventful_days[$event->start_date]) ){
248
- $eventful_days[$event->start_date][] = $event;
249
- } else {
250
- $eventful_days[$event->start_date] = array($event);
251
- }
252
- }
253
- $event = apply_filters('em_calendar_output_loop_end', $event);
254
- }
255
- }
256
-
257
- $event_format = get_option('dbem_full_calendar_event_format');
258
- $event_title_format = get_option('dbem_small_calendar_event_title_format');
259
- $event_title_separator_format = get_option('dbem_small_calendar_event_title_separator');
260
- $cells = array() ;
261
- foreach($eventful_days as $day_key => $events) {
262
- //Set the date into the key
263
- $event_start_date = explode('-', $day_key);
264
- $cells[$day_key]['day'] = ltrim($event_start_date[2],'0');
265
- $cells[$day_key]['month'] = $event_start_date[1];
266
- $cells[$day_key]['year'] = $event_start_date[0];
267
- $events_titles = array();
268
- foreach($events as $event) {
269
- $events_titles[] = $event->output($event_title_format);
270
- }
271
- $link_title = implode( $event_title_separator_format, $events_titles);
272
-
273
- global $wp_rewrite;
274
- $event_page_link = get_permalink(get_option('dbem_events_page')); //don't use EM_URI here, since ajax calls this before EM_URI is defined.
275
- if( $wp_rewrite->using_permalinks() ){
276
- $cells[$day_key]['cell'] = "<a title='$link_title' href='".$event_page_link."{$day_key}/'>{$cells[$day_key]['day']}</a>";
277
- }else{
278
- if (stristr($event_page_link, "?"))
279
- $joiner = "&amp;";
280
- else
281
- $joiner = "?";
282
- $cells[$day_key]['cell'] = "<a title='$link_title' href='".$event_page_link.$joiner."calendar_day={$day_key}'>{$cells[$day_key]['day']}</a>";
283
- }
284
- if ($full) {
285
- $cells[$day_key]['cell'] .= "<ul>";
286
-
287
- foreach($events as $event) {
288
- $cells[$day_key]['cell'] .= $event->output($event_format);
289
- }
290
- $cells[$day_key]['cell'] .= "</ul>";
291
- }
292
- }
293
-
294
- if($events){
295
- foreach($cells as $cell) {
296
- if ($cell['month'] == $month_pre && $cell['year'] == $year_pre) {
297
- $calendar = str_replace("<td class='eventless-pre'>".$cell['day']."</td>","<td class='eventful-pre'>".$cell['cell']."</td>",$calendar);
298
- } elseif($cell['month'] == $month_post && $cell['year'] == $year_post) {
299
- $calendar = str_replace("<td class='eventless-post'>".$cell['day']."</td>","<td class='eventful-post'>".$cell['cell']."</td>",$calendar);
300
- } elseif( date('Y-m-j', current_time('timestamp')) == $cell['year']."-".$cell['month']."-".$cell['day'] ) {
301
- $calendar = str_replace("<td class='eventless-today'>".$cell['day']."</td>","<td class='eventful-today'>".$cell['cell']."</td>",$calendar);
302
- } elseif( $cell['month'] == $month && $cell['year'] == $year){
303
- $calendar = str_replace("<td class='eventless'>".$cell['day']."</td>","<td class='eventful'>".$cell['cell']."</td>",$calendar);
304
- }
305
- }
306
- }
307
- return apply_filters('em_calendar_output', '<div id="em-calendar-'.rand(100,200).'" class="em-calendar-wrapper">'.$calendar.'</div>');
308
- }
309
-
310
- /**
311
- * Echoes the calendar external JS contents directly into the head of the document
312
- * @return unknown_type
313
- */
314
- function insert_js() {
315
- ?>
316
- <script type='text/javascript'>
317
- <?php include(WP_PLUGIN_DIR.'/events-manager/includes/js/em_calendar_ajax.js'); ?>
318
- </script>
319
- <?php
320
- }
321
-
322
-
323
- function days_in_month($month, $year) {
324
- return date('t', mktime(0,0,0,$month,1,$year));
325
- }
326
-
327
- function translate_and_trim($string, $length = 1) {
328
- return substr(__($string), 0, $length);
329
- }
330
-
331
- /**
332
- * Helper function to create a link querystring from array which contains arguments with only values that aren't defuaults.
333
- */
334
- function get_link_args($args = array(), $html_entities=true){
335
- unset($args['month']); unset($args['year']);
336
- $default_args = self::get_default_search(array());
337
- foreach($default_args as $arg_key => $arg_value){
338
- if( !isset($args[$arg_key]) || $args[$arg_key] == $arg_value ){
339
- unset($args[$arg_key]);
340
- }
341
- }
342
- $qs_array = array();
343
- foreach($args as $key => $value){
344
- if(is_array($value)){
345
- $value = implode(',',$value);
346
- }
347
- $qs_array[] = "$key=".urlencode($value);
348
- }
349
- return ($html_entities) ? implode('&amp;', $qs_array) : implode('&', $qs_array);
350
- }
351
-
352
-
353
- function get_default_search($array=array()){
354
- //These defaults aren't for db queries, but flags for what to display in calendar output
355
- $defaults = array(
356
- 'full' => 0, //Will display a full calendar with event names
357
- 'long_events' => 0, //Events that last longer than a day
358
- 'scope' => 'future',
359
- 'owner' => false
360
- );
361
- $atts = parent::get_default_search($defaults, $array);
362
- $atts['full'] = ($atts['full']==true) ? 1:0;
363
- $atts['long_events'] = ($atts['long_events']==true) ? 1:0;
364
- return apply_filters('em_calendar_get_default_search', $atts, $array, $defaults);
365
- }
366
- }
367
- add_action('init', array('EM_Calendar', 'init'));
368
  ?>
1
+ <?php
2
+ class EM_Calendar extends EM_Object {
3
+
4
+ function init(){
5
+ add_action('wp_head', array('EM_Calendar', 'insert_js'));
6
+ }
7
+
8
+ function output($args = array()) {
9
+ global $wpdb;
10
+
11
+ $args = self::get_default_search($args);
12
+ $full = $args['full']; //For ZDE, don't delete pls
13
+ $month = $args['month'];
14
+ $year = $args['year'];
15
+ $long_events = $args['long_events'];
16
+
17
+ $week_starts_on_sunday = get_option('dbem_week_starts_sunday');
18
+ $start_of_week = get_option('start_of_week');
19
+
20
+ if( !(is_numeric($month) && $month <= 12 && $month > 0) ) {
21
+ $month = date('m');
22
+ }
23
+ if( !( is_numeric($year) ) ){
24
+ $year = date('Y');
25
+ }
26
+
27
+ // Get the first day of the month
28
+ $month_start = mktime(0,0,0,$month, 1, $year);
29
+ // Get friendly month name
30
+ $month_name = date('M',$month_start);
31
+ // Figure out which day of the week
32
+ // the month starts on.
33
+ $month_start_day = date('D', $month_start);
34
+
35
+ switch($month_start_day){
36
+ case "Sun": $offset = 0; break;
37
+ case "Mon": $offset = 1; break;
38
+ case "Tue": $offset = 2; break;
39
+ case "Wed": $offset = 3; break;
40
+ case "Thu": $offset = 4; break;
41
+ case "Fri": $offset = 5; break;
42
+ case "Sat": $offset = 6; break;
43
+ }
44
+ //We need to go back to the WP defined day when the week started, in case the event day is near the end
45
+ $offset -= $start_of_week;
46
+ if($offset<0)
47
+ $offset += 7;
48
+
49
+ // determine how many days are in the last month.
50
+ $month_last = $month-1;
51
+ $month_next = $month+1;
52
+ $year_last = $year;
53
+ $year_next = $year;
54
+ if($month == 1) {
55
+ $month_last = 12;
56
+ $year_last = $year -1;
57
+ }
58
+ $num_days_last = self::days_in_month($month_last, $year_last);
59
+
60
+ // determine how many days are in the current month.
61
+ $num_days_current = self::days_in_month($month, $year);
62
+ // Build an array for the current days
63
+ // in the month
64
+ for($i = 1; $i <= $num_days_current; $i++){
65
+ $num_days_array[] = mktime(0,0,0,$month, $i, $year);
66
+ }
67
+ // Build an array for the number of days
68
+ // in last month
69
+ for($i = 1; $i <= $num_days_last; $i++){
70
+ $num_days_last_array[] = mktime(0,0,0,$month_last, $i, $year_last);
71
+ }
72
+ // If the $offset from the starting day of the
73
+ // week happens to be Sunday, $offset would be 0,
74
+ // so don't need an offset correction.
75
+
76
+ if($offset > 0){
77
+ $offset_correction = array_slice($num_days_last_array, -$offset, $offset);
78
+ $new_count = array_merge($offset_correction, $num_days_array);
79
+ $offset_count = count($offset_correction);
80
+ } else { // The else statement is to prevent building the $offset array.
81
+ $offset_count = 0;
82
+ $new_count = $num_days_array;
83
+ }
84
+ // count how many days we have with the two
85
+ // previous arrays merged together
86
+ $current_num = count($new_count);
87
+
88
+ // Since we will have 5 HTML table rows (TR)
89
+ // with 7 table data entries (TD)
90
+ // we need to fill in 35 TDs
91
+ // so, we will have to figure out
92
+ // how many days to appened to the end
93
+ // of the final array to make it 35 days.
94
+
95
+
96
+ if($current_num > 35){
97
+ $num_weeks = 6;
98
+ $outset = (42 - $current_num);
99
+ } elseif($current_num < 35){
100
+ $num_weeks = 5;
101
+ $outset = (35 - $current_num);
102
+ }
103
+ if($current_num == 35){
104
+ $num_weeks = 5;
105
+ $outset = 0;
106
+ }
107
+ // Outset Correction
108
+ for($i = 1; $i <= $outset; $i++){
109
+ $new_count[] = mktime(0,0,0,$month_next, $i, $year_next);
110
+ }
111
+ // Now let's "chunk" the $all_days array
112
+ // into weeks. Each week has 7 days
113
+ // so we will array_chunk it into 7 days.
114
+ $weeks = array_chunk($new_count, 7);
115
+
116
+
117
+
118
+ // Build Previous and Next Links
119
+ $base_link = "?".$_SERVER['QUERY_STRING']."&amp;";
120
+
121
+ $full ? $link_extra_class = "full-link" : $link_extra_class = '';
122
+ //Get an array of arguments that don't include default valued args
123
+ $link_args = self::get_link_args($args);
124
+
125
+ //Get the previous link
126
+ if($month == 1){
127
+ $back_month = 12;
128
+ $back_year = $year-1;
129
+ } else {
130
+ $back_month = $month -1;
131
+ $back_year = $year;
132
+ }
133
+ $previous_link = "<a class='em-calnav $link_extra_class' href='?ajaxCalendar=1&amp;month={$back_month}&amp;year={$back_year}&amp;{$link_args}'>&lt;&lt;</a>";
134
+
135
+ //Now the next
136
+ if($month == 12){
137
+ $next_month = 1;
138
+ $next_year = $year+1;
139
+ } else {
140
+ $next_month = $month + 1;
141
+ $next_year = $year;
142
+ }
143
+ $next_link = "<a class='em-calnav $link_extra_class' href='?ajaxCalendar=1&amp;month={$next_month}&amp;year={$next_year}&amp;{$link_args}'>&gt;&gt;</a>";
144
+
145
+
146
+ $class = ($full) ? 'dbem-calendar-full' : 'dbem-calendar';
147
+ $calendar="<div class='$class'><div style='display:none' class='month_n'>$month</div><div class='year_n' style='display:none' >$year</div>";
148
+
149
+ $weekdays = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
150
+ $n = 0 ;
151
+ while( $n < $start_of_week ) {
152
+ $last_day = array_shift($weekdays);
153
+ $weekdays[]= $last_day;
154
+ $n++;
155
+ }
156
+
157
+ $days_initials = "";
158
+ foreach($weekdays as $weekday) {
159
+ $days_initials .= "<td>".self::translate_and_trim($weekday)."</td>";
160
+ }
161
+ $full ? $fullclass = 'fullcalendar' : $fullclass='';
162
+ // Build the heading portion of the calendar table
163
+ $calendar .= "<table class='dbem-calendar-table $fullclass'>\n".
164
+ "<thead>\n<tr>\n".
165
+ "<td>$previous_link</td><td class='month_name' colspan='5'>". apply_filters('dbem_calendar_output_month', ucfirst(date_i18n('M', $month_start)), $month_start, $args)." $year</td><td>$next_link</td>\n".
166
+ "</tr>\n</thead>\n".
167
+ "<tr class='days-names'>\n".
168
+ $days_initials.
169
+ "</tr>\n";
170
+
171
+ // Now we break each key of the array
172
+ // into a week and create a new table row for each
173
+ // week with the days of that week in the table data
174
+
175
+ $i = 0;
176
+ $current_date = date('Y-m-d', current_time('timestamp'));
177
+ foreach ( $weeks as $week ) {
178
+ $calendar .= "<tr>\n";
179
+ foreach ( $week as $d ) {
180
+ if ($i < $offset_count) { //if it is PREVIOUS month
181
+ $calendar .= "<td class='eventless-pre'>" . date ( 'j', $d ) . "</td>\n";
182
+ }
183
+ if (($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)) { // if it is THIS month
184
+ $day = date ( 'j', $d );
185
+ if ( $current_date == date('Y-m-d', $d) ){
186
+ $calendar .= "<td class='eventless-today'>$day</td>\n";
187
+ } else {
188
+ $calendar .= "<td class='eventless'>$day</td>\n";
189
+ }
190
+ } elseif (($outset > 0)) { //if it is NEXT month
191
+ if (($i >= ($num_weeks * 7) - $outset)) {
192
+ $calendar .= "<td class='eventless-post'>" . date ( 'j', $d ) . "</td>\n";
193
+ }
194
+ }
195
+ $i ++;
196
+ }
197
+ $calendar .= "</tr>\n";
198
+ }
199
+
200
+ $calendar .= " </table>\n</div>";
201
+
202
+ // query the database for events in this time span
203
+ if ($month == 1) {
204
+ $month_pre=12;
205
+ $month_post=2;
206
+ $year_pre=$year-1;
207
+ $year_post=$year;
208
+ } elseif($month == 12) {
209
+ $month_pre=11;
210
+ $month_post=1;
211
+ $year_pre=$year;
212
+ $year_post=$year+1;
213
+ } else {
214
+ $month_pre=$month-1;
215
+ $month_post=$month+1;
216
+ $year_pre=$year;
217
+ $year_post=$year;
218
+ }
219
+ $args['year'] = array($year_pre, $year_post);
220
+ $args['month'] = array($month_pre, $month_post);
221
+ $events = EM_Events::get($args);
222
+
223
+ $eventful_days= array();
224
+ if($events){
225
+ //Go through the events and slot them into the right d-m index
226
+ foreach($events as $event) {
227
+ $event = apply_filters('em_calendar_output_loop_start', $event);
228
+ if( $long_events ){
229
+ //If $long_events is set then show a date as eventful if there is an multi-day event which runs during that day
230
+ $event_start_date = mktime(0,0,0,$month_pre,1,$year_pre);
231
+ $event_end_date = mktime(0,0,0,$month_post,date('t', $event_start_date),$year_post );
232
+ if( $event_end_date == '' ) $event_end_date = $event_start_date;
233
+ while( $event_start_date <= $event->end ){
234
+ //Ensure date is within event dates, if so add to eventful days array
235
+ if( $event_start_date > $event->start - (86400) ){ //subtract a day since start may be later in day
236
+ $event_eventful_date = date('Y-m-d', $event_start_date);
237
+ if( array_key_exists($event_eventful_date, $eventful_days) && is_array($eventful_days[$event_eventful_date]) ){
238
+ $eventful_days[$event_eventful_date][] = $event;
239
+ } else {
240
+ $eventful_days[$event_eventful_date] = array($event);
241
+ }
242
+ }
243
+ $event_start_date += (86400); //add a day
244
+ }
245
+ }else{
246
+ //Only show events on the day that they start
247
+ if( isset($eventful_days[$event->start_date]) && is_array($eventful_days[$event->start_date]) ){
248
+ $eventful_days[$event->start_date][] = $event;
249
+ } else {
250
+ $eventful_days[$event->start_date] = array($event);
251
+ }
252
+ }
253
+ $event = apply_filters('em_calendar_output_loop_end', $event);
254
+ }
255
+ }
256
+
257
+ $event_format = get_option('dbem_full_calendar_event_format');
258
+ $event_title_format = get_option('dbem_small_calendar_event_title_format');
259
+ $event_title_separator_format = get_option('dbem_small_calendar_event_title_separator');
260
+ $cells = array() ;
261
+ foreach($eventful_days as $day_key => $events) {
262
+ //Set the date into the key
263
+ $event_start_date = explode('-', $day_key);
264
+ $cells[$day_key]['day'] = ltrim($event_start_date[2],'0');
265
+ $cells[$day_key]['month'] = $event_start_date[1];
266
+ $cells[$day_key]['year'] = $event_start_date[0];
267
+ $events_titles = array();
268
+ foreach($events as $event) {
269
+ $events_titles[] = $event->output($event_title_format);
270
+ }
271
+ $link_title = implode( $event_title_separator_format, $events_titles);
272
+
273
+ $events_page_id = get_option('dbem_events_page');
274
+ $event_page_link = get_permalink($events_page_id);
275
+ if (stristr($event_page_link, "?"))
276
+ $joiner = "&amp;";
277
+ else
278
+ $joiner = "?";
279
+
280
+
281
+ $cells[$day_key]['cell'] = "<a title='$link_title' href='".$event_page_link.$joiner."calendar_day={$day_key}'>{$cells[$day_key]['day']}</a>";
282
+ if ($full) {
283
+ $cells[$day_key]['cell'] .= "<ul>";
284
+
285
+ foreach($events as $event) {
286
+ $cells[$day_key]['cell'] .= $event->output($event_format);
287
+ }
288
+ $cells[$day_key]['cell'] .= "</ul>";
289
+ }
290
+ }
291
+
292
+ if($events){
293
+ foreach($cells as $cell) {
294
+ if ($cell['month'] == $month_pre && $cell['year'] == $year_pre) {
295
+ $calendar = str_replace("<td class='eventless-pre'>".$cell['day']."</td>","<td class='eventful-pre'>".$cell['cell']."</td>",$calendar);
296
+ } elseif($cell['month'] == $month_post && $cell['year'] == $year_post) {
297
+ $calendar = str_replace("<td class='eventless-post'>".$cell['day']."</td>","<td class='eventful-post'>".$cell['cell']."</td>",$calendar);
298
+ } elseif( date('Y-m-j', current_time('timestamp')) == $cell['year']."-".$cell['month']."-".$cell['day'] ) {
299
+ $calendar = str_replace("<td class='eventless-today'>".$cell['day']."</td>","<td class='eventful-today'>".$cell['cell']."</td>",$calendar);
300
+ } elseif( $cell['month'] == $month && $cell['year'] == $year){
301
+ $calendar = str_replace("<td class='eventless'>".$cell['day']."</td>","<td class='eventful'>".$cell['cell']."</td>",$calendar);
302
+ }
303
+ }
304
+ }
305
+ return apply_filters('em_calendar_output', '<div id="em-calendar-'.rand(100,200).'" class="em-calendar-wrapper">'.$calendar.'</div>');
306
+ }
307
+
308
+ /**
309
+ * Echoes the calendar external JS contents directly into the head of the document
310
+ * @return unknown_type
311
+ */
312
+ function insert_js() {
313
+ ?>
314
+ <script type='text/javascript'>
315
+ <?php include(WP_PLUGIN_DIR.'/events-manager/includes/js/em_calendar_ajax.js'); ?>
316
+ </script>
317
+ <?php
318
+ }
319
+
320
+
321
+ function days_in_month($month, $year) {
322
+ return date('t', mktime(0,0,0,$month,1,$year));
323
+ }
324
+
325
+ function translate_and_trim($string, $length = 1) {
326
+ return substr(__($string), 0, $length);
327
+ }
328
+
329
+ /**
330
+ * Helper function to create a link querystring from array which contains arguments with only values that aren't defuaults.
331
+ */
332
+ function get_link_args($args = array(), $html_entities=true){
333
+ unset($args['month']); unset($args['year']);
334
+ $default_args = self::get_default_search(array());
335
+ foreach($default_args as $arg_key => $arg_value){
336
+ if( !isset($args[$arg_key]) || $args[$arg_key] == $arg_value ){
337
+ unset($args[$arg_key]);
338
+ }
339
+ }
340
+ $qs_array = array();
341
+ foreach($args as $key => $value){
342
+ if(is_array($value)){
343
+ $value = implode(',',$value);
344
+ }
345
+ $qs_array[] = "$key=".urlencode($value);
346
+ }
347
+ return ($html_entities) ? implode('&amp;', $qs_array) : implode('&', $qs_array);
348
+ }
349
+
350
+
351
+ function get_default_search($array=array()){
352
+ //These defaults aren't for db queries, but flags for what to display in calendar output
353
+ $defaults = array(
354
+ 'full' => 0, //Will display a full calendar with event names
355
+ 'long_events' => 0, //Events that last longer than a day
356
+ 'scope' => 'all',
357
+ 'owner' => false
358
+ );
359
+ $atts = parent::get_default_search($defaults, $array);
360
+ $atts['full'] = ($atts['full']==true) ? 1:0;
361
+ $atts['long_events'] = ($atts['long_events']==true) ? 1:0;
362
+ return apply_filters('em_calendar_get_default_search', $atts, $array, $defaults);
363
+ }
364
+ }
365
+ add_action('init', array('EM_Calendar', 'init'));
 
 
366
  ?>
classes/em-categories.php CHANGED
@@ -1,158 +1,157 @@
1
- <?php
2
- class EM_Categories extends EM_Object {
3
-
4
- function get( $args = array() ) {
5
- global $wpdb;
6
- $categories_table = $wpdb->prefix.EM_CATEGORIES_TABLE;
7
- $events_table = $wpdb->prefix.EM_EVENTS_TABLE;
8
-
9
- //Quick version, we can accept an array of IDs, which is easy to retrieve
10
- if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
11
- //We can just get all the events here and return them
12
- $sql = "SELECT * FROM $categories_table WHERE category_id=".implode(" OR category_id=", $args);
13
- $results = $wpdb->get_results(apply_filters('em_categories_get_sql',$sql),ARRAY_A);
14
- $categories = array();
15
- foreach($results as $result){
16
- $categories[$result['category_id']] = new EM_Category($result);
17
- }
18
- return $categories; //We return all the categories matched as an EM_Event array.
19
- }
20
-
21
- //We assume it's either an empty array or array of search arguments to merge with defaults
22
- $args = self::get_default_search($args);
23
- $limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
24
- $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
25
-
26
- //Get the default conditions
27
- $conditions = self::build_sql_conditions($args);
28
- //Put it all together
29
- $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
30
-
31
- //Get ordering instructions
32
- $EM_Category = new EM_Category();
33
- $accepted_fields = $EM_Category->get_fields(true);
34
- $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_categories_default_order'));
35
- //Now, build orderby sql
36
- $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
37
-
38
- //Create the SQL statement and execute
39
- $sql = "
40
- SELECT * FROM $categories_table
41
- LEFT JOIN $events_table ON {$events_table}.event_category_id={$categories_table}.category_id
42
- $where
43
- GROUP BY category_id
44
- $orderby_sql
45
- $limit $offset
46
- ";
47
- $results = $wpdb->get_results( apply_filters('em_categories_get_sql',$sql, $args), ARRAY_A);
48
- //If we want results directly in an array, why not have a shortcut here?
49
- if( $args['array'] == true ){
50
- return $results;
51
- }
52
-
53
- //Make returned results EM_Event objects
54
- $results = (is_array($results)) ? $results:array();
55
- $categories = array();
56
- foreach ( $results as $category_array ){
57
- $categories[$category_array['category_id']] = new EM_Category($category_array);
58
- }
59
-
60
- return apply_filters('em_categories_get', $categories);
61
- }
62
-
63
- /**
64
- * Will delete given an array of category_ids or EM_Event objects
65
- * @param unknown_type $id_array
66
- */
67
- function delete( $array ){
68
- global $wpdb;
69
- //Detect array type and generate SQL for event IDs
70
- $category_ids = array();
71
- if( @get_class(current($array)) == 'EM_Category' ){
72
- foreach($array as $EM_Category){
73
- $category_ids[] = $EM_Category->id;
74
- }
75
- }else{
76
- $category_ids = $array;
77
- }
78
- if(self::array_is_numeric($category_ids)){
79
- apply_filters('em_categories_delete', $category_ids);
80
- $condition = implode(" OR category_id=", $category_ids);
81
- //Delete all the bookings
82
- $result_bookings = $wpdb->query("DELETE FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." WHERE category_id=$condition;");
83
- //Now delete the categories
84
- $result = $wpdb->query ( "DELETE FROM ". $wpdb->prefix . EM_CATEGORIES_TABLE ." WHERE category_id=$condition;" );
85
- do_action('em_categories_delete', $category_ids);
86
- }
87
- //TODO add error detection on categories delete fails
88
- return apply_filters('em_categories_delete', true, $category_ids);
89
- }
90
-
91
- /* Overrides EM_Object method to apply a filter to result
92
- * @see wp-content/plugins/categories-manager/classes/EM_Object#build_sql_conditions()
93
- */
94
- function build_sql_conditions( $args = array() ){
95
- global $wpdb;
96
- $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
97
- $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
98
-
99
- //FIXME EM_Categories doesn't build sql conditions in EM_Object
100
- $conditions = array();
101
- //eventful locations
102
- if( true == $args['eventful'] ){
103
- $conditions['eventful'] = "{$events_table}.event_id IS NOT NULL";
104
- }elseif( true == $args['eventless'] ){
105
- $conditions['eventless'] = "{$events_table}.event_id IS NULL";
106
- }
107
- //owner lookup
108
- if( is_numeric($args['owner']) ){
109
- $conditions['owner'] = "category_owner=".get_current_user_id();
110
- }elseif( preg_match('/^([0-9],?)+$/', $args['owner']) ){
111
- $conditions['owner'] = "category_owner IN (".explode(',', $args['owner']).")";
112
- }
113
- return apply_filters( 'em_categories_build_sql_conditions', $conditions, $args );
114
- }
115
-
116
- /* Overrides EM_Object method to apply a filter to result
117
- * @see wp-content/plugins/categories-manager/classes/EM_Object#build_sql_orderby()
118
- */
119
- function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
120
- return apply_filters( 'em_categories_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_categories_default_order')), $args, $accepted_fields, $default_order );
121
- }
122
-
123
- /*
124
- * Adds custom categories search defaults
125
- * @param array $array
126
- * @return array
127
- * @uses EM_Object#get_default_search()
128
- */
129
- function get_default_search( $array = array() ){
130
- $defaults = array(
131
- 'scope'=>false,
132
- 'eventful' => false, //cats that have an event (scope will also play a part here
133
- 'eventless' => false, //cats WITHOUT events, eventful takes precedence
134
- );
135
- if( is_admin() ){
136
- //$defaults['owner'] = self::get_default_search_owner();
137
- }
138
- return apply_filters('em_categories_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
139
- }
140
-
141
- /**
142
- * will return the default search parameter to use according to permission settings
143
- * @return string
144
- */
145
- function get_default_search_owner(){
146
- //by default, we only get categories the owner can manage
147
- $defaults = array('owner'=>false);
148
- //by default, we only get categories the owner can manage
149
- if( !current_user_can('edit_categories') ){
150
- $defaults['owner'] = get_current_user_id();
151
- break;
152
- }else{
153
- $defaults['owner'] = false;
154
- break;
155
- }
156
- return $defaults['owner'];
157
- }
158
  }
1
+ <?php
2
+ class EM_Categories extends EM_Object {
3
+
4
+ function get( $args = array() ) {
5
+ global $wpdb;
6
+ $categories_table = $wpdb->prefix.EM_CATEGORIES_TABLE;
7
+ $events_table = $wpdb->prefix.EM_EVENTS_TABLE;
8
+
9
+ //Quick version, we can accept an array of IDs, which is easy to retrieve
10
+ if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
11
+ //We can just get all the events here and return them
12
+ $sql = "SELECT * FROM $categories_table WHERE category_id=".implode(" OR category_id=", $args);
13
+ $results = $wpdb->get_results(apply_filters('em_categories_get_sql',$sql),ARRAY_A);
14
+ $categories = array();
15
+ foreach($results as $result){
16
+ $categories[$result['category_id']] = new EM_Category($result);
17
+ }
18
+ return $categories; //We return all the categories matched as an EM_Event array.
19
+ }
20
+
21
+ //We assume it's either an empty array or array of search arguments to merge with defaults
22
+ $args = self::get_default_search($args);
23
+ $limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
24
+ $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
25
+
26
+ //Get the default conditions
27
+ $conditions = self::build_sql_conditions($args);
28
+ //Put it all together
29
+ $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
30
+
31
+ //Get ordering instructions
32
+ $EM_Category = new EM_Category();
33
+ $accepted_fields = $EM_Category->get_fields(true);
34
+ $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_categories_default_order'));
35
+ //Now, build orderby sql
36
+ $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
37
+
38
+ //Create the SQL statement and execute
39
+ $sql = "
40
+ SELECT * FROM $categories_table
41
+ LEFT JOIN $events_table ON {$events_table}.event_category_id={$categories_table}.category_id
42
+ $where
43
+ GROUP BY category_id
44
+ $orderby_sql
45
+ $limit $offset
46
+ ";
47
+ $results = $wpdb->get_results( apply_filters('em_categories_get_sql',$sql, $args), ARRAY_A);
48
+ //If we want results directly in an array, why not have a shortcut here?
49
+ if( $args['array'] == true ){
50
+ return $results;
51
+ }
52
+
53
+ //Make returned results EM_Event objects
54
+ $results = (is_array($results)) ? $results:array();
55
+ $categories = array();
56
+ foreach ( $results as $category_array ){
57
+ $categories[$category_array['category_id']] = new EM_Category($category_array);
58
+ }
59
+
60
+ return apply_filters('em_categories_get', $categories);
61
+ }
62
+
63
+ /**
64
+ * Will delete given an array of category_ids or EM_Event objects
65
+ * @param unknown_type $id_array
66
+ */
67
+ function delete( $array ){
68
+ global $wpdb;
69
+ //Detect array type and generate SQL for event IDs
70
+ $category_ids = array();
71
+ if( @get_class(current($array)) == 'EM_Category' ){
72
+ foreach($array as $EM_Category){
73
+ $category_ids[] = $EM_Category->id;
74
+ }
75
+ }else{
76
+ $category_ids = $array;
77
+ }
78
+ if(self::array_is_numeric($category_ids)){
79
+ apply_filters('em_categories_delete', $category_ids);
80
+ $condition = implode(" OR category_id=", $category_ids);
81
+ //Delete all the bookings
82
+ $result_bookings = $wpdb->query("DELETE FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." WHERE category_id=$condition;");
83
+ //Now delete the categories
84
+ $result = $wpdb->query ( "DELETE FROM ". $wpdb->prefix . EM_CATEGORIES_TABLE ." WHERE category_id=$condition;" );
85
+ do_action('em_categories_delete', $category_ids);
86
+ }
87
+ //TODO add error detection on categories delete fails
88
+ return apply_filters('em_categories_delete', true, $category_ids);
89
+ }
90
+
91
+ /* Overrides EM_Object method to apply a filter to result
92
+ * @see wp-content/plugins/categories-manager/classes/EM_Object#build_sql_conditions()
93
+ */
94
+ function build_sql_conditions( $args = array() ){
95
+ global $wpdb;
96
+ $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
97
+ $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
98
+
99
+ //FIXME EM_Categories doesn't build sql conditions in EM_Object
100
+ $conditions = array();
101
+ //eventful locations
102
+ if( true == $args['eventful'] ){
103
+ $conditions['eventful'] = "{$events_table}.event_id IS NOT NULL";
104
+ }elseif( true == $args['eventless'] ){
105
+ $conditions['eventless'] = "{$events_table}.event_id IS NULL";
106
+ }
107
+ //owner lookup
108
+ if( is_numeric($args['owner']) ){
109
+ $conditions['owner'] = "category_owner=".get_current_user_id();
110
+ }elseif( preg_match('/^([0-9],?)+$/', $args['owner']) ){
111
+ $conditions['owner'] = "category_owner IN (".explode(',', $args['owner']).")";
112
+ }
113
+ return apply_filters( 'em_categories_build_sql_conditions', $conditions, $args );
114
+ }
115
+
116
+ /* Overrides EM_Object method to apply a filter to result
117
+ * @see wp-content/plugins/categories-manager/classes/EM_Object#build_sql_orderby()
118
+ */
119
+ function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
120
+ return apply_filters( 'em_categories_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_categories_default_order')), $args, $accepted_fields, $default_order );
121
+ }
122
+
123
+ /*
124
+ * Adds custom categories search defaults
125
+ * @param array $array
126
+ * @return array
127
+ * @uses EM_Object#get_default_search()
128
+ */
129
+ function get_default_search( $array = array() ){
130
+ $defaults = array(
131
+ 'scope'=>false,
132
+ 'eventful' => false, //cats that have an event (scope will also play a part here
133
+ 'eventless' => false, //cats WITHOUT events, eventful takes precedence
134
+ );
135
+ if( is_admin() ){
136
+ //by default, we only get categories the owner can manage
137
+ switch( get_option('dbem_permissions_categories') ){
138
+ case 0:
139
+ $defaults['owner'] = get_current_user_id();
140
+ break;
141
+ case 1:
142
+ $wp_user_search = new WP_User_Search(null, null, 'administrator');
143
+ $users = $wp_user_search->get_results();
144
+ $users[] = get_current_user_id();
145
+ $users[] = 0;
146
+ $defaults['owner'] = implode(',', $users);
147
+ break;
148
+ case 2:
149
+ $defaults['owner'] = false;
150
+ break;
151
+ }
152
+ $defaults['owner'] = ( em_verify_admin() ) ? false:$defaults['owner'];
153
+ }
154
+ return apply_filters('em_categories_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
155
+ }
156
+
 
157
  }
classes/em-category.php CHANGED
@@ -1,176 +1,152 @@
1
- <?php
2
- //TODO expand em_category to be like other classes
3
- class EM_Category extends EM_Object {
4
- //DB Fields
5
- var $id = '';
6
- var $slug = '';
7
- var $owner = '';
8
- var $name = '';
9
- //Other Vars
10
- var $fields = array(
11
- 'category_id' => array('name'=>'id','type'=>'%d'),
12
- 'category_slug' => array('name'=>'slug','type'=>'%s'),
13
- 'category_owner' => array('name'=>'owner','type'=>'%d'),
14
- 'category_name' => array('name'=>'name','type'=>'%s')
15
- );
16
- var $required_fields;
17
- var $feedback_message = "";
18
- var $errors = array();
19
-
20
- /**
21
- * Gets data from POST (default), supplied array, or from the database if an ID is supplied
22
- * @param $location_data
23
- * @return null
24
- */
25
- function EM_Category( $category_data = false ) {
26
- global $wpdb;
27
- //Initialize
28
- $this->required_fields = array("category_name" => __('The category name', 'dbem'));
29
- $category = array();
30
- if( !empty($category_data) ){
31
- //Load location data
32
- if( is_array($category_data) && isset($category_data['category_name']) ){
33
- $category = $category_data;
34
- }elseif( is_numeric($category_data) ){
35
- //Retreiving from the database
36
- $sql = "SELECT * FROM ". $wpdb->prefix.EM_CATEGORIES_TABLE ." WHERE category_id ='{$category_data}'";
37
- $category = $wpdb->get_row($sql, ARRAY_A);
38
- }else{
39
- $sql = "SELECT * FROM ". $wpdb->prefix.EM_CATEGORIES_TABLE ." WHERE category_slug ='{$category_data}'";
40
- $category = $wpdb->get_row($sql, ARRAY_A);
41
- }
42
- //Save into the object
43
- $this->to_object($category);
44
- }
45
- do_action('em_category',$this, $category_data);
46
- }
47
-
48
- function get_post(){
49
- //We are getting the values via POST or GET
50
- do_action('em_location_get_post_pre', $this);
51
- $category = array();
52
- $category['category_id'] = ( !empty($_POST['category_id']) ) ? $_POST['category_id']:'';
53
- $category['category_name'] = ( !empty($_POST['category_name']) ) ? stripslashes($_POST['category_name']):'';
54
- $category['category_owner'] = ( !empty($_POST['category_owner']) && is_numeric($_POST['category_owner']) ) ? $_POST['category_owner']:get_current_user_id();
55
- $this->to_object( apply_filters('em_category_get_post', $category, $this) );
56
- }
57
-
58
- function save(){
59
- global $wpdb;
60
- $result = false;
61
- if( $this->can_manage('edit_categories') ){
62
- do_action('em_category_save_pre', $this);
63
- $table = $wpdb->prefix.EM_CATEGORIES_TABLE;
64
- $this->slug = $this->sanitize_title();
65
- $data = $this->to_array();
66
- unset($data['category_id']);
67
- if($this->id != ''){
68
- $where = array( 'category_id' => $this->id );
69
- $result = $wpdb->update($table, $data, $where, $this->get_types($data));
70
- }else{
71
- $wpdb->insert($table, $data, $this->get_types($data));
72
- $result = $this->id = $wpdb->insert_id;
73
- }
74
- }
75
- return apply_filters('em_category_save', ($result !== false), $this);
76
- }
77
-
78
- /**
79
- * Takes the title and gives either a unique slug or returns the currently used slug if this record already has it.
80
- * @param unknown_type $title
81
- */
82
- function sanitize_title($iteration = 1){
83
- global $wpdb;
84
- //Generate the slug. If this is a new event, create the slug automatically, if not, verify it is still unique and if not rewrite
85
- if( empty($this->slug) ){
86
- $this->slug = sanitize_title($this->name);
87
- }
88
- $slug = $this->slug;
89
- $slug_matches = $wpdb->get_results('SELECT category_id FROM '.$wpdb->prefix.EM_LOCATIONS_TABLE." WHERE category_slug='{$slug}'", ARRAY_A);
90
- if( count($slug_matches) > 0 ){ //we will check that the slug is unique
91
- if( $slug_matches[0]['category_id'] != $this->id || count($slug_matches) > 1 ){
92
- //we have a conflict, so try another alternative
93
- $this->slug = preg_replace('/\-[0-9]+$/', '', $slug).'-'.($iteration+1);
94
- $this->sanitize_title($iteration+1);
95
- }
96
- }
97
- return apply_filters('em_location_sanitize_title', $this->slug, $this);
98
- }
99
-
100
- function delete(){
101
- global $wpdb;
102
- $result = false;
103
- if( $this->can_manage('edit_categories') ){
104
- do_action('em_category_delete_pre', $this);
105
- $table_name = $wpdb->prefix.EM_CATEGORIES_TABLE;
106
- $sql = "DELETE FROM $table_name WHERE category_id = '{$this->id}';";
107
- $result = $wpdb->query($sql);
108
- }
109
- return apply_filters('em_category_delete', $result, $this);
110
- }
111
-
112
- /**
113
- * Validates the category. Should be run during any form submission or saving operation.
114
- * @return boolean
115
- */
116
- function validate(){
117
- $missing_fields = Array ();
118
- foreach ( $this->required_fields as $key => $field ) {
119
- $true_field = $this->fields[$key]['name'];
120
- if ( $this->$true_field == "") {
121
- $missing_fields[] = $field;
122
- }
123
- }
124
- if ( count($missing_fields) > 0){
125
- // TODO Create friendly equivelant names for missing fields notice in validation
126
- $this->errors[] = __ ( 'Missing fields: ' ) . implode ( ", ", $missing_fields ) . ". ";
127
- }
128
- return apply_filters('em_category_validate', ( count($this->errors) == 0 ), $this);
129
- }
130
-
131
- function has_events(){
132
- global $wpdb;
133
- $events_table = $wpdb->prefix.EM_EVENTS_TABLE;
134
- $sql = "SELECT count(event_id) as events_no FROM $events_table WHERE category_id = {$this->id}";
135
- $affected_events = $wpdb->get_row($sql);
136
- return apply_filters('em_category_has_events', (count($affected_events) > 0), $this);
137
- }
138
-
139
- function output_single($target = 'html'){
140
- $format = get_option ( 'dbem_single_category_format' );
141
- return apply_filters('em_category_output_single', $this->output($format, $target), $this, $target);
142
- }
143
-
144
- function output($format, $target="html") {
145
- $category_string = $format;
146
- preg_match_all("/#_[A-Za-z]+/", $format, $placeholders);
147
- foreach($placeholders[0] as $result) {
148
- $match = true;
149
- $replace = '';
150
- switch( $result ){
151
- case '#_CATEGORYNAME':
152
- $replace = $this->name;
153
- break;
154
- case '#_CATEGORYID':
155
- $replace = $this->id;
156
- break;
157
- default:
158
- $match = false;
159
- break;
160
- }
161
- if($match){ //if true, we've got a placeholder that needs replacing
162
- //TODO FILTER - placeholder filter
163
- $replace = apply_filters('em_category_output_placeholder', $replace, $this, $result, $target); //USE WITH CAUTION! THIS MIGHT GET RENAMED
164
- $category_string = str_replace($result, $replace , $category_string );
165
- }
166
- }
167
- $name_filter = ($target == "html") ? 'dbem_general':'dbem_general_rss'; //TODO remove dbem_ filters
168
- $category_string = str_replace('#_CATEGORY', apply_filters($name_filter, $this->name) , $category_string ); //Depreciated
169
- return apply_filters('em_category_output', $category_string, $this, $format, $target);
170
- }
171
-
172
- function can_manage( $capability_owner = 'edit_categories', $capability_admin = false ){
173
- return current_user_can($capability_owner);
174
- }
175
- }
176
  ?>
1
+ <?php
2
+ //TODO expand em_category to be like other classes
3
+ class EM_Category extends EM_Object {
4
+ //DB Fields
5
+ var $id = '';
6
+ var $owner = '';
7
+ var $name = '';
8
+ //Other Vars
9
+ var $fields = array(
10
+ 'category_id' => array('name'=>'id','type'=>'%d'),
11
+ 'category_owner' => array('name'=>'owner','type'=>'%d'),
12
+ 'category_name' => array('name'=>'name','type'=>'%s')
13
+ );
14
+ var $required_fields;
15
+ var $feedback_message = "";
16
+ var $errors = array();
17
+
18
+ /**
19
+ * Gets data from POST (default), supplied array, or from the database if an ID is supplied
20
+ * @param $location_data
21
+ * @return null
22
+ */
23
+ function EM_Category( $category_data = false ) {
24
+ //Initialize
25
+ $this->required_fields = array("category_name" => __('The category name', 'dbem'));
26
+ $category = array();
27
+ if( $category_data != false ){
28
+ //Load location data
29
+ if( is_array($category_data) && isset($category_data['category_name']) ){
30
+ $category = $category_data;
31
+ }elseif( is_numeric($category_data) ){
32
+ //Retreiving from the database
33
+ global $wpdb;
34
+ $sql = "SELECT * FROM ". $wpdb->prefix.EM_CATEGORIES_TABLE ." WHERE category_id ='{$category_data}'";
35
+ $category = $wpdb->get_row($sql, ARRAY_A);
36
+ }
37
+ //Save into the object
38
+ $this->to_object($category);
39
+ }
40
+ }
41
+
42
+ function get_post(){
43
+ //We are getting the values via POST or GET
44
+ do_action('em_location_get_post_pre', $this);
45
+ $category = array();
46
+ $category['category_id'] = ( !empty($_POST['category_id']) ) ? $_POST['category_id']:'';
47
+ $category['category_name'] = ( !empty($_POST['category_name']) ) ? stripslashes($_POST['category_name']):'';
48
+ $category['category_owner'] = ( !empty($_POST['category_owner']) && is_numeric($_POST['category_owner']) ) ? $_POST['category_owner']:get_current_user_id();
49
+ $this->to_object( apply_filters('em_category_get_post', $category, $this) );
50
+ }
51
+
52
+ function save(){
53
+ global $wpdb;
54
+ do_action('em_category_save_pre', $this);
55
+ $table = $wpdb->prefix.EM_CATEGORIES_TABLE;
56
+ $data = $this->to_array();
57
+ unset($data['category_id']);
58
+ if($this->id != ''){
59
+ $where = array( 'category_id' => $this->id );
60
+ $wpdb->update($table, $data, $where, $this->get_types($data));
61
+ }else{
62
+ $wpdb->insert($table, $data, $this->get_types($data));
63
+ $this->id = $wpdb->insert_id;
64
+ }
65
+ return apply_filters('em_category_save', ( $this->id > 0 && $image_upload ), $this, $image_upload);
66
+ }
67
+
68
+ function delete(){
69
+ global $wpdb;
70
+ do_action('em_category_delete_pre', $this);
71
+ $table_name = $wpdb->prefix.EM_CATEGORIES_TABLE;
72
+ $sql = "DELETE FROM $table_name WHERE category_id = '{$this->id}';";
73
+ $result = $wpdb->query($sql);
74
+ return apply_filters('em_category_delete', $result, $this);
75
+ }
76
+
77
+ /**
78
+ * Validates the category. Should be run during any form submission or saving operation.
79
+ * @return boolean
80
+ */
81
+ function validate(){
82
+ $missing_fields = Array ();
83
+ foreach ( $this->required_fields as $key => $field ) {
84
+ $true_field = $this->fields[$key]['name'];
85
+ if ( $this->$true_field == "") {
86
+ $missing_fields[] = $field;
87
+ }
88
+ }
89
+ if ( count($missing_fields) > 0){
90
+ // TODO Create friendly equivelant names for missing fields notice in validation
91
+ $this->errors[] = __ ( 'Missing fields: ' ) . implode ( ", ", $missing_fields ) . ". ";
92
+ }
93
+ return apply_filters('em_category_validate', ( count($this->errors) == 0 ), $this);
94
+ }
95
+
96
+ function has_events(){
97
+ global $wpdb;
98
+ $events_table = $wpdb->prefix.EM_EVENTS_TABLE;
99
+ $sql = "SELECT count(event_id) as events_no FROM $events_table WHERE category_id = {$this->id}";
100
+ $affected_events = $wpdb->get_row($sql);
101
+ return apply_filters('em_category_has_events', (count($affected_events) > 0), $this);
102
+ }
103
+
104
+ function output_single($target = 'html'){
105
+ $format = get_option ( 'dbem_single_category_format' );
106
+ return apply_filters('em_category_output_single', $this->output($format, $target), $this, $target);
107
+ }
108
+
109
+ function output($format, $target="html") {
110
+ $category_string = $format;
111
+ preg_match_all("/#_[A-Za-z]+/", $format, $placeholders);
112
+ foreach($placeholders[0] as $result) {
113
+ $match = true;
114
+ $replace = '';
115
+ switch( $result ){
116
+ case '#_CATEGORYNAME':
117
+ $replace = $this->name;
118
+ break;
119
+ case '#_CATEGORYID':
120
+ $replace = $this->id;
121
+ break;
122
+ default:
123
+ $match = false;
124
+ break;
125
+ }
126
+ if($match){ //if true, we've got a placeholder that needs replacing
127
+ //TODO FILTER - placeholder filter
128
+ $replace = apply_filters('em_category_output_placeholder', $replace, $this, $result, $target); //USE WITH CAUTION! THIS MIGHT GET RENAMED
129
+ $category_string = str_replace($result, $replace , $category_string );
130
+ }
131
+ }
132
+ $name_filter = ($target == "html") ? 'dbem_general':'dbem_general_rss'; //TODO remove dbem_ filters
133
+ $category_string = str_replace('#_CATEGORY', apply_filters($name_filter, $this->name) , $category_string ); //Depreciated
134
+ return apply_filters('em_category_output', $category_string, $this, $format, $target);
135
+ }
136
+
137
+ function can_manage(){
138
+ return ( get_option('dbem_permissions_categories') == 2 || $this->owner == get_current_user_id() || empty($this->id) || em_verify_admin() );
139
+ }
140
+
141
+ function can_use(){
142
+ switch( get_option('dbem_permissions_locations') ){
143
+ case 0:
144
+ return $this->owner == get_current_user_id();
145
+ case 1:
146
+ return em_verify_admin($this->owner);
147
+ case 2:
148
+ return true;
149
+ }
150
+ }
151
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  ?>
classes/em-event.php CHANGED
@@ -1,1157 +1,1006 @@
1
- <?php
2
- /**
3
- * Event Object. This holds all the info pertaining to an event, including location and recurrence info.
4
- * An event object can be one of three "types" a recurring event, recurrence of a recurring event, or a single event.
5
- * The single event might be part of a set of recurring events, but if loaded by specific event id then any operations and saves are
6
- * specifically done on this event. However, if you edit the recurring group, any changes made to single events are overwritten.
7
- *
8
- * @author marcus
9
- */
10
- //TODO Can add more recurring functionality such as "also update all future recurring events" or "edit all events" like google calendar does.
11
- //TODO Integrate recurrences into events table
12
- //FIXME If you create a super long recurrence timespan, there could be thousands of events... need an upper limit here.
13
- class EM_Event extends EM_Object{
14
- /**
15
- * Assoc array where keys are names of database fields and values are array corresponding object property name, regex, data types, etc.
16
- * for use when importing/exporting event data between database and object
17
- * @var array
18
- */
19
- var $fields = array(
20
- 'event_id' => array( 'name'=>'id', 'type'=>'%d' ),
21
- 'event_slug' => array( 'name'=>'slug', 'type'=>'%s' ),
22
- 'event_owner' => array( 'name'=>'owner', 'type'=>'%d' ),
23
- 'event_name' => array( 'name'=>'name', 'type'=>'%s' ),
24
- 'event_start_time' => array( 'name'=>'start_time', 'type'=>'%s' ),
25
- 'event_end_time' => array( 'name'=>'end_time', 'type'=>'%s' ),
26
- 'event_start_date' => array( 'name'=>'start_date', 'type'=>'%s' ),
27
- 'event_end_date' => array( 'name'=>'end_date', 'type'=>'%s' ),
28
- 'event_notes' => array( 'name'=>'notes', 'type'=>'%s' ),
29
- 'event_rsvp' => array( 'name'=>'rsvp', 'type'=>'%d' ),
30
- //'event_spaces' => array( 'name'=>'spaces', 'type'=>'%d' ),
31
- 'location_id' => array( 'name'=>'location_id', 'type'=>'%d' ),
32
- 'recurrence_id' => array( 'name'=>'recurrence_id', 'type'=>'%d' ),
33
- 'event_category_id' => array( 'name'=>'category_id', 'type'=>'%d' ),
34
- 'event_attributes' => array( 'name'=>'attributes', 'type'=>'%s' ),
35
- 'recurrence' => array( 'name'=>'recurrence', 'type'=>'%d' ),
36
- 'recurrence_interval' => array( 'name'=>'interval', 'type'=>'%d' ), //every x day(s)/week(s)/month(s)
37
- 'recurrence_freq' => array( 'name'=>'freq', 'type'=>'%s' ), //daily,weekly,monthly?
38
- 'recurrence_byday' => array( 'name'=>'byday', 'type'=>'%s' ), //if weekly or monthly, what days of the week?
39
- 'recurrence_byweekno' => array( 'name'=>'byweekno', 'type'=>'%d' ), //if monthly which week (-1 is last)
40
- 'event_status' => array( 'name'=>'status', 'type'=>'%d' ) //if monthly which week (-1 is last)
41
- );
42
- /* Field Names - see above for matching DB field names and other field meta data */
43
- var $id;
44
- var $slug;
45
- var $owner;
46
- var $name;
47
- var $start_time;
48
- var $end_time;
49
- var $start_date;
50
- var $end_date;
51
- var $notes;
52
- var $rsvp;
53
- //var $spaces;
54
- var $location_id;
55
- var $recurrence_id;
56
- var $category_id;
57
- var $attributes;
58
- var $recurrence;
59
- var $interval;
60
- var $freq;
61
- var $byday;
62
- var $byweekno;
63
- var $status;
64
-
65
- /**
66
- * Timestamp of start date/time
67
- * @var int
68
- */
69
- var $start;
70
- /**
71
- * Timestamp of end date/time
72
- * @var int
73
- */
74
- var $end;
75
- /**
76
- * Created on timestamp, taken from DB, converted to TS
77
- * @var int
78
- */
79
- var $created;
80
- /**
81
- * Created on timestamp, taken from DB, converted to TS
82
- * @var int
83
- */
84
- var $modified;
85
-
86
- /**
87
- * @var EM_Location
88
- */
89
- var $location;
90
- /**
91
- * @var EM_Bookings
92
- */
93
- var $bookings;
94
- /**
95
- * The contact person for this event
96
- * @var WP_User
97
- */
98
- var $contact;
99
- /**
100
- * The category object
101
- * @var EM_Category
102
- */
103
- var $category;
104
- /**
105
- * If there are any errors, they will be added here.
106
- * @var array
107
- */
108
- var $errors = array();
109
- /**
110
- * If something was successful, a feedback message might be supplied here.
111
- * @var string
112
- */
113
- var $feedback_message;
114
- /**
115
- * Any warnings about an event (e.g. bad data, recurring/recurrence, etc.)
116
- * @var string
117
- */
118
- var $warnings;
119
- /**
120
- * Array of dbem_event field names required to create an event
121
- * @var array
122
- */
123
- var $required_fields = array('event_name', 'event_start_date');
124
-
125
- /**
126
- * Initialize an event. You can provide event data in an associative array (using database table field names), an id number, or false (default) to create empty event.
127
- * @param mixed $event_data
128
- * @return null
129
- */
130
- function EM_Event($event_data = false) {
131
- global $wpdb, $EM_Recurrences;
132
- //TODO Change the way we deal with time, maybe revert to timestamps for manipulation, and worry about output in html and db writes?
133
- if( $event_data !== false ){
134
- $event = array();
135
- if( is_array($event_data) ){
136
- //Accepts a raw array that'll just be imported directly into the object with no DB lookups (same for event and recurrence)
137
- $event = $event_data;
138
- if($event['location_name']){
139
- $this->location = new EM_Location( $event );
140
- }
141
- $this->category = new EM_Category( $event );
142
- }elseif( !empty($event_data) ) {
143
- if( is_numeric($event_data) && $event_data > 0 ){
144
- $cond = "event_id = $event_data";
145
- }else{
146
- $cond = "event_slug = '".$wpdb->escape($event_data)."'";
147
- }
148
- //Retreiving from the database
149
- $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
150
- $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
151
- $categories_table = $wpdb->prefix . EM_CATEGORIES_TABLE;
152
- $sql = "
153
- SELECT * FROM $events_table
154
- LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
155
- LEFT JOIN $categories_table ON {$categories_table}.category_id={$events_table}.event_category_id
156
- WHERE $cond
157
- "; //We get event and location data here to avoid extra queries
158
- $event = $wpdb->get_row ( $sql, ARRAY_A );
159
- //Sort Location
160
- $this->location = new EM_Location ( $event );
161
- $this->category = new EM_Category( $event );
162
- }
163
- //Sort out attributes
164
- if( !empty($event['event_attributes']) ){
165
- if( is_serialized($event['event_attributes']) ){
166
- $event['event_attributes'] = @unserialize($event['event_attributes']);
167
- }
168
- $event['event_attributes'] = (!is_array($event['event_attributes'])) ? array() : $event['event_attributes'] ;
169
- }
170
- $event['recurrence_byday'] = ( empty($event['recurrence_byday']) || $event['recurrence_byday'] == 7 ) ? 0:$event['recurrence_byday']; //Backward compatibility (since 3.0.3), using 0 makes more sense due to date() function
171
- $this->to_object($event, true);
172
-
173
- //Start/End times should be available as timestamp
174
- $this->start = strtotime($this->start_date." ".$this->start_time);
175
- $this->end = strtotime($this->end_date." ".$this->end_time);
176
- $this->modified = ( !empty($event['event_date_modified']) ) ? strtotime($event['event_date_modified']):time();
177
- $this->created = ( !empty($event['event_date_created']) ) ? strtotime($event['event_date_created']):time();
178
-
179
- //Add Owner as Contact Person
180
- if($this->owner && $this->owner > 0){
181
- $this->contact = get_userdata($this->owner);
182
- }
183
- if( !is_object($this->contact) ){
184
- $this->owner = get_option('dbem_default_contact_person');
185
- $this->contact = get_userdata($this->owner);
186
- }
187
- if( is_object($this->contact) ){
188
- $this->contact->phone = get_metadata('user', $this->contact->ID, 'dbem_phone', true);
189
- }
190
- //Now, if this is a recurrence, get the recurring for caching to the $EM_Recurrences
191
- if( $this->is_recurrence() && is_array($EM_Recurrences) && !array_key_exists($this->recurrence_id, $EM_Recurrences) ){
192
- $EM_Recurrences[$this->recurrence_id] = new EM_Event($this->recurrence_id);
193
- }
194
- }else{
195
- $this->location = new EM_Location(); //blank location
196
- $this->category = new EM_Category(); //blank category
197
- }
198
- $this->get_location();
199
- //Do it here so things appear in the po file.
200
- $this->status_array = array(
201
- 0 => __('Pending','dbem'),
202
- 1 => __('Approved','dbem')
203
- );
204
-
205
- //Set up some warning meta
206
- if ( $this->is_recurring() ) {
207
- $this->warnings['recurring'] = __( 'WARNING: This is a recurring event.', 'dbem' )."<br />". __( 'Modifications to this event will cause all recurrences of this event to be deleted and recreated and previous bookings will be deleted! You can edit individual recurrences and disassociate them with this recurring event.', 'dbem' );
208
- } elseif ( $this->is_recurrence() ) {
209
- $this->warnings['recurrence'] = __('WARNING: This is a recurrence in a set of recurring events.', 'dbem')."<br />". __('If you update this event data and save, it will become an independent event, and will not be deleted or modified automatically if you reschedule the original recurring event details.', 'dbem' );
210
- }
211
- do_action('em_event', $this, $event_data);
212
- }
213
-
214
- /**
215
- * Retrieve event, location and recurring information via POST
216
- * @return boolean
217
- */
218
- function get_post(){
219
- //Build Event Array
220
- do_action('em_event_get_post_pre', $this);
221
- $this->name = ( !empty($_POST['event_name']) ) ? stripslashes($_POST['event_name']) : '' ;
222
- $this->start_date = ( !empty($_POST['event_start_date']) ) ? $_POST['event_start_date'] : '';
223
- $this->end_date = ( !empty($_POST['event_end_date']) ) ? $_POST['event_end_date'] : $this->start_date;
224
- $this->rsvp = ( !empty($_POST['event_rsvp']) ) ? 1:0;
225
- //$this->spaces = ( !empty($_POST['event_spaces']) && is_numeric($_POST['event_spaces']) ) ? $_POST['event_spaces']:0;
226
- $this->notes = ( !empty($_POST['content']) ) ? stripslashes($_POST['content']) : ''; //WP TinyMCE field
227
- //Sort out time
228
- //TODO make time handling less painful
229
- $match = array();
230
- if( !empty($_POST['event_start_time']) && preg_match ( '/^([01]\d|2[0-3]):([0-5]\d)(AM|PM)?$/', $_POST['event_start_time'], $match ) ){
231
- if( $match[3] == 'PM' && $match[1] != 12 ){
232
- $match[1] = 12+$match[1];
233
- }elseif( $match[3] == 'AM' && $match[1] == 12 ){
234
- $match[1] = '00';
235
- }
236
- $this->start_time = $match[1].":".$match[2].":00";
237
- }else{
238
- $this->start_time = "00:00:00";
239
- }
240
- if( !empty($_POST['event_end_time']) && preg_match ( '/^([01]\d|2[0-3]):([0-5]\d)(AM|PM)?$/', $_POST['event_end_time'], $match ) ){
241
- if( $match[3] == 'PM' && $match[1] != 12 ){
242
- $match[1] = 12+$match[1];
243
- }elseif( $match[3] == 'AM' && $match[1] == 12 ){
244
- $match[1] = '00';
245
- }
246
- $this->end_time = $match[1].":".$match[2].":00";
247
- }else{
248
- $this->end_time = $this->start_time;
249
- }
250
- //Start/End times should be available as timestamp
251
- $this->start = strtotime($this->start_date." ".$this->start_time);
252
- $this->end = strtotime($this->end_date." ".$this->end_time);
253
-
254
- //owner
255
- if( !empty($_REQUEST['event_owner']) && is_numeric($_REQUEST['event_owner']) ){
256
- $this->owner = current_user_can('edit_others_events') ? $_REQUEST['event_owner']:get_current_user_id();
257
- }
258
-
259
- //category
260
- if( !empty($_POST['event_category_id']) && is_numeric($_POST['event_category_id']) ){
261
- $this->category_id = $_POST['event_category_id'];
262
- }
263
- //Attributes
264
- $event_attributes = array();
265
- $post = $_POST;
266
- $event_available_attributes = em_get_attributes();
267
- if( !empty($_POST['em_attributes']) && is_array($_POST['em_attributes']) ){
268
- foreach($_POST['em_attributes'] as $att_key => $att_value ){
269
- if( (in_array($att_key, $event_available_attributes) || array_key_exists($att_key, $this->attributes) ) && trim($att_value) != '' ){
270
- $event_attributes[$att_key] = $att_value;
271
- }
272
- }
273
- }
274
- $this->attributes = $event_attributes;
275
- //Recurrence data
276
- $this->recurrence_id = ( !empty($_POST['recurrence_id']) && is_numeric($_POST['recurrence_id']) ) ? $_POST['recurrence_id'] : 0 ;
277
- if( !empty($_POST['repeated_event']) ){
278
- $this->recurrence = 1;
279
- $this->freq = ( !empty($_POST['recurrence_freq']) && in_array($_POST['recurrence_freq'], array('daily','weekly','monthly')) ) ? $_POST['recurrence_freq']:'daily';
280
- if( !empty($_POST['recurrence_bydays']) && $this->freq == 'weekly' && self::array_is_numeric($_POST['recurrence_bydays']) ){
281
- $this->byday = implode ( ",", $_POST['recurrence_bydays'] );
282
- }elseif( !empty($_POST['recurrence_byday']) && $this->freq == 'monthly' ){
283
- $this->byday = $_POST['recurrence_byday'];
284
- }
285
- $this->interval = ( !empty($_POST['recurrence_interval']) ) ? $_POST['recurrence_interval']:1;
286
- $this->byweekno = ( !empty($_POST['recurrence_byweekno']) ) ? $_POST['recurrence_byweekno']:'';
287
- }
288
-
289
- //Add location information, or just link to previous location, this is a requirement...
290
- if( !empty($_POST['location_id']) && is_numeric($_POST['location_id'])) {
291
- $this->location_id = $_POST['location_id'];
292
- $this->location = new EM_Location($_POST['location_id']);
293
-
294
- } else {
295
- $this->location = new EM_Location($_POST);
296
- $this->location->load_similar($_POST);
297
- }
298
- if( !$this->get_bookings()->get_tickets()->get_post() ){
299
- $EM_Tickets = $this->get_bookings()->get_tickets();
300
- array_merge($this->errors, $this->get_bookings()->get_tickets()->errors);
301
- }
302
- return apply_filters('em_event_get_post', $this->validate(), $this);
303
- }
304
-
305
- /**
306
- * Will save the current instance into the database, along with location information if a new one was created and return true if successful, false if not.
307
- * Will automatically detect what type of event it is (recurrent, recurrence or normal) and whether it's a new or existing event.
308
- * @return boolean
309
- */
310
- function save(){
311
- //FIXME Event doesn't save title when inserting first time
312
- global $wpdb, $current_user;
313
- if( !$this->can_manage('edit_events', 'edit_others_events')){
314
- return apply_filters('em_event_save', false, $this);
315
- }
316
- do_action('em_event_save_pre', $this);
317
- get_currentuserinfo();
318
- $events_table = $wpdb->prefix.EM_EVENTS_TABLE;
319
- $request = $_REQUEST;
320
- //First let's save the location, no location no event!
321
- if ( !$this->get_location()->id && !$this->location->save() ){ //shouldn't try to save if location exists
322
- $this->errors[] = __ ( 'There was a problem saving the location so event was not saved.', 'dbem' );
323
- return apply_filters('em_event_save', false, $this);
324
- }
325
- $this->location_id = $this->location->id;
326
- //owner person can be anyone the admin wants, but the creator if not.
327
- if( current_user_can('edit_others_events') ){
328
- $this->owner = ( $this->owner > 0 ) ? $this->owner:0;
329
- }else{
330
- //force
331
- $this->owner = get_current_user_id();
332
- }
333
- //Set status of this event, depending on user type
334
- if( current_user_can('publish_events') ){
335
- //top level can edit and publish any events
336
- $this->status = 1;
337
- }else{
338
- //any updates or additions put the event into pending status
339
- $this->status = 0;
340
- }
341
- $this->slug = $this->sanitize_title();
342
-
343
- //Now save the event
344
- if ( !$this->id ) {
345
- // Insert New Event
346
- $this->owner = $current_user->ID; //Record creator of event
347
- $event = $this->to_array(true);
348
- $event['event_attributes'] = serialize($this->attributes);
349
- $event['recurrence_id'] = ( is_numeric($this->recurrence_id) ) ? $this->recurrence_id : 0;
350
- $event = apply_filters('em_event_save_pre',$event,$this);
351
- $result = $wpdb->insert ( $events_table, $event, $this->get_types($event) );
352
- if($result !== false){
353
- $this->id = $wpdb->insert_id;
354
- $this->is_new = true;
355
- //Add Tickets
356
- if( !$this->get_bookings()->get_tickets()->save() ){
357
- $this->errors[] = __( 'Something went wrong with creating tickets.', 'dbem' );
358
- return apply_filters('em_event_save', false, $this);
359
- }
360
- //Deal with recurrences
361
- if ( $this->is_recurring() ) {
362
- //Recurrence master event saved, now Save Events & check errors
363
- if( !$this->save_events() ){
364
- $this->errors[] = __ ( 'Something went wrong with the recurrence update...', 'dbem' ).
365
- __ ( 'There was a problem saving the recurring events.', 'dbem' );
366
- $this->delete();
367
- return apply_filters('em_event_save', false, $this);
368
- }
369
- //All good! Event Saved
370
- $this->feedback_message = __ ( 'New recurrent event inserted!', 'dbem' );
371
- return apply_filters('em_event_save', true, $this);
372
- }
373
- //Successful individual save
374
- $this->feedback_message = __ ( 'New event successfully inserted!', 'dbem' );
375
- return apply_filters('em_event_save', true, $this);
376
- }else{
377
- $this->errors[] = __ ( 'Could not save the event details due to a database error.', 'dbem' );
378
- }
379
- } else {
380
- // Update Event
381
- //TODO event privacy protection, only authors and authorized users can edit events
382
- //$this->owner = $current_user->ID; //Record creator of event
383
- //FIXME Saving recurrence and disabling recurrence doesn't work
384
- $this->recurrence_id = 0; // If it's saved here, it becomes individual
385
- $event = $this->to_array();
386
- $event['event_attributes'] = serialize($event['event_attributes']);
387
- $event = apply_filters('em_event_save_pre',$event,$this);
388
- $result = $wpdb->update ( $events_table, $event, array('event_id' => $this->id), $this->get_types($event) );
389
- if($result !== false){ //Can't just do $result since if you don't make an actual record details change, it'll return 0 for no changes made
390
- //Add Tickets
391
- if( !$this->get_bookings()->get_tickets()->save() ){
392
- $this->errors[] = __( 'Something went wrong with creating tickets.', 'dbem' );
393
- return apply_filters('em_event_save', false, $this);
394
- }
395
- //Deal with recurrences
396
- if ( $this->is_recurring() ) {
397
- if( !$this->save_events() ){
398
- $this->errors[] = __ ( 'Something went wrong with the recurrence update...', 'dbem' ).
399
- __ ( 'There was a problem saving the recurring events.', 'dbem' );
400
- return apply_filters('em_event_save', false, $this);
401
- }
402
- $this->feedback_message = __ ( 'Recurrence updated!', 'dbem' );
403
- return apply_filters('em_event_save', true, $this);
404
- }
405
- }else{
406
- $this->errors[] = __('Could not save the event details due to a database error.', 'dbem');
407
- return apply_filters('em_event_save', false, $this);
408
- }
409
- //Successful individual or recurrence save
410
- $this->feedback_message = "{$this->name} " . __ ( 'updated', 'dbem' ) . "!";
411
- if($this->rsvp == 0){
412
- $this->delete_bookings();
413
- }
414
- return apply_filters('em_event_save', true, $this);
415
- }
416
- }
417
-
418
- /**
419
- * Takes the title and gives either a unique slug or returns the currently used slug if this record already has it.
420
- * @param unknown_type $title
421
- */
422
- function sanitize_title($iteration = 1){
423
- global $wpdb;
424
- //Generate the slug. If this is a new event, create the slug automatically, if not, verify it is still unique and if not rewrite
425
- if( empty($this->slug) ){
426
- $this->slug = sanitize_title($this->name);
427
- }
428
- $slug = $this->slug;
429
- $slug_matches = $wpdb->get_results('SELECT event_id FROM '.$wpdb->prefix.EM_EVENTS_TABLE." WHERE event_slug='{$slug}'", ARRAY_A);
430
- if( count($slug_matches) > 0 ){ //we will check that the slug is unique
431
- if( $slug_matches[0]['event_id'] != $this->id || count($slug_matches) > 1 ){
432
- //we have a conflict, so try another alternative
433
- $this->slug = preg_replace('/\-[0-9]+$/', '', $slug).'-'.($iteration+1);
434
- $this->sanitize_title($iteration+1);
435
- }
436
- }
437
- return apply_filters('em_event_sanitize_title', $this->slug, $this);
438
- }
439
-
440
- /**
441
- * Delete whole event, including recurrence and recurring data
442
- * @param $recurrence_id
443
- * @return boolean
444
- */
445
- function delete(){
446
- global $wpdb;
447
- do_action('em_event_delete_pre', $this);
448
- $result = false;
449
- if( $this->can_manage( 'delete_events','delete_others_events' ) ){
450
- if( $this->is_recurring() ){
451
- //Delete the recurrences then this recurrence event
452
- $this->delete_events();
453
- }
454
- $result = $wpdb->query ( $wpdb->prepare("DELETE FROM ". $wpdb->prefix . EM_EVENTS_TABLE ." WHERE event_id=%d", $this->id) );
455
- if($result !== false){
456
- $result = $this->get_bookings()->delete();
457
- }
458
- }
459
- return apply_filters('em_event_delete', $result !== false, $this);
460
- }
461
-
462
- /**
463
- * approve a booking.
464
- * @return bool
465
- */
466
- function approve(){
467
- return $this->set_status(1);
468
- }
469
-
470
- /**
471
- * Change the status of the event. This will save to the Database too.
472
- * @param unknown_type $status
473
- * @return string
474
- */
475
- function set_status($status){
476
- $action_string = strtolower($this->status_array[$status]);
477
- $this->previous_status = $this->status;
478
- $this->status = $status;
479
- $result = $this->save();
480
- if($result){
481
- $this->feedback_message = sprintf(__('Event %s.','dbem'), $action_string);
482
- return true;
483
- }else{
484
- //errors should be logged by save()
485
- $this->feedback_message = sprintf(__('Booking could not be %s.','dbem'), $action_string);
486
- return false;
487
- }
488
- }
489
-
490
- /**
491
- * Duplicates this event and returns the duplicated event. Will return false if there is a problem with duplication.
492
- * @return EM_Event
493
- */
494
- function duplicate(){
495
- global $wpdb, $EZSQL_ERROR;
496
- //First, duplicate.
497
- if( $this->can_manage('edit_events','edit_others_events') ){
498
- $event_table_name = $wpdb->prefix . EM_EVENTS_TABLE;
499
- $eventArray = $this->to_array();
500
- unset($eventArray['event_id']);
501
- $EM_Event = new EM_Event( $eventArray );
502
- if( $EM_Event->save() ){
503
- $EM_Event->feedback_message = sprintf(__("%s successfully duplicated.", 'dbem'), __('Event','dbem'));
504
- return apply_filters('em_event_duplicate', $EM_Event, $this);
505
- }
506
- }else{
507
- $EM_Event->add_error( sprintf(__('You are not allowed to manage this %s.'), __('event','dbem')) );
508
- }
509
- //TODO add error notifications for duplication failures.
510
- return apply_filters('em_event_duplicate', false, $this);;
511
- }
512
-
513
-
514
- /**
515
- * Validates the event. Should be run during any form submission or saving operation.
516
- * @return boolean
517
- */
518
- function validate() {
519
- $missing_fields = Array ();
520
- foreach ( $this->required_fields as $field ) {
521
- $true_field = $this->fields[$field]['name'];
522
- if ( $this->$true_field == "") {
523
- $missing_fields[] = $field;
524
- }
525
- }
526
- if ( count($missing_fields) > 0){
527
- // TODO Create friendly equivelant names for missing fields notice in validation
528
- $this->errors[] = __ ( 'Missing fields: ' ) . implode ( ", ", $missing_fields ) . ". ";
529
- }
530
- if ( !empty($_POST['repeated_event']) && $_POST['repeated_event'] == "1" && $this->end_date == "" ){
531
- $this->errors[] = __ ( 'Since the event is repeated, you must specify an event date.', 'dbem' );
532
- }
533
- if( preg_match('/\d{4}-\d{2}-\d{2}/', $this->start_date) && preg_match('/\d{4}-\d{2}-\d{2}/', $this->end_date) ){
534
- if( strtotime($this->start_date . $this->start_time) > strtotime($this->end_date . $this->end_time) ){
535
- $this->errors[] = __('Events cannot start after they end.','dbem');
536
- }
537
- }else{
538
- $this->errors[] = __('Dates must have correct formatting. Please use the date picker provided.','dbem');
539
- }
540
- if( $this->get_location()->id == '' && !$this->get_location()->validate() ){
541
- $this->errors = array_merge($this->errors, $this->location->errors);
542
- }
543
- //TODO validate recurrence during event validate
544
- return apply_filters('em_event_validate', count($this->errors) == 0, $this );
545
- }
546
-
547
-
548
- /**
549
- * Returns an array with category id and name (in that order) of the EM_Event instance.
550
- * @return array
551
- */
552
- function get_category() {
553
- global $EM_Category;
554
- if( is_object($this->category) && get_class($this->category)=='EM_Category' && $this->category_id == $this->category->id ){
555
- return $this->category;
556
- }elseif( is_object($EM_Category) && $EM_Category->id == $this->category_id ){
557
- $this->category = $EM_Category;
558
- }else{
559
- $this->category = new EM_Category($this->category_id);
560
- }
561
- global $wpdb;
562
- $sql = "SELECT category_id, category_name FROM ".$wpdb->prefix.EM_EVENTS_TABLE." LEFT JOIN ".$wpdb->prefix.EM_CATEGORIES_TABLE." ON category_id=event_category_id WHERE event_id ='".$this->id."'";
563
- $category = $wpdb->get_row($sql, ARRAY_A);
564
- return apply_filters('em_event_get_category', $category, $this);
565
- }
566
-
567
- /**
568
- * Returns the location object this event belongs to.
569
- * @return EM_Location
570
- */
571
- function get_location() {
572
- global $EM_location;
573
- if( is_object($this->location) && get_class($this->location)=='EM_location' && ($this->location_id == $this->location->id || empty($this->id)) ){
574
- return $this->location;
575
- }elseif( is_object($EM_location) && $EM_location->id == $this->location_id ){
576
- $this->location = $EM_location;
577
- }else{
578
- $this->location = new EM_location($this->location_id);
579
- }
580
- return apply_filters('em_event_get_location', $this->location, $this);
581
- }
582
-
583
- /**
584
- * Shortcut function for $this->get_bookings()->delete(), because using the EM_Bookings requires loading previous bookings, which isn't neceesary.
585
- */
586
- function delete_bookings(){
587
- global $wpdb;
588
- do_action('em_event_delete_bookings_pre', $this);
589
- $result = false;
590
- if( $this->can_manage('manage_bookings','manage_others_bookings') ){
591
- $result = $wpdb->query( $wpdb->prepare("DELETE FROM ".$wpdb->prefix.EM_BOOKINGS_TABLE." WHERE event_id=%d", $this->id) );
592
- }
593
- return apply_filters('em_event_delete_bookings', $result, $this);
594
- }
595
-
596
- /**
597
- * Retrieve and save the bookings belonging to instance. If called again will return cached version, set $force_reload to true to create a new EM_Bookings object.
598
- * @param boolean $force_reload
599
- * @return EM_Bookings
600
- */
601
- function get_bookings( $force_reload = false ){
602
- if( get_option('dbem_rsvp_enabled') ){
603
- if( (!$this->bookings || $force_reload) ){
604
- $this->bookings = new EM_Bookings($this);
605
- }
606
- }
607
- return apply_filters('em_event_get_bookings', $this->bookings, $this);
608
- }
609
-
610
- /**
611
- * Gets number of spaces in this event, dependent on ticket spaces or hard limit, whichever is smaller.
612
- * @param boolean $force_refresh
613
- * @return int
614
- */
615
- function get_spaces($force_refresh=false){
616
- return $this->get_bookings()->get_spaces($force_refresh);
617
- }
618
-
619
- /**
620
- * Will output a single event format of this event.
621
- * Equivalent of calling EM_Event::output( get_option ( 'dbem_single_event_format' ) )
622
- * @param string $target
623
- * @return string
624
- */
625
- function output_single($target='html'){
626
- $format = get_option ( 'dbem_single_event_format' );
627
- return apply_filters('em_event_output_single', $this->output($format, $target), $this, $target);
628
- }
629
-
630
- /**
631
- * Will output a event list item format of this event.
632
- * Equivalent of calling EM_Event::output( get_option ( 'dbem_event_list_item_format' ) )
633
- * @param string $target
634
- * @return string
635
- */
636
- function output_list($target='html'){
637
- $format = get_option ( 'dbem_event_list_item_format' );
638
- return apply_filters('em_event_output_list', $this->output($format, $target), $this, $target);
639
- }
640
-
641
- /**
642
- * Will output a event in the format passed in $format by replacing placeholders within the format.
643
- * @param string $format
644
- * @param string $target
645
- * @return string
646
- */
647
- function output($format, $target="html") {
648
- $event_string = $format;
649
- preg_match_all("/#@?_?[A-Za-z0-9]+/", $format, $placeholders);
650
- foreach($placeholders[0] as $result) {
651
- $match = true;
652
- $replace = '';
653
- switch( $result ){
654
- //Event Details
655
- case '#_EVENTID':
656
- $replace = $this->id;
657
- break;
658
- case '#_NAME':
659
- $replace = $this->name;
660
- break;
661
- case '#_NOTES':
662
- case '#_EXCERPT':
663
- //SEE AT BOTTOM OF FILE FOR OLD TARGET FILTERS FROM 2.x
664
- $replace = $this->notes;
665
- if($result == "#_EXCERPT"){
666
- $matches = explode('<!--more', $this->notes);
667
- $replace = $matches[0];
668
- }
669
- break;
670
- //Times
671
- case '#_24HSTARTTIME':
672
- case '#_24HENDTIME':
673
- $time = ($result == '#_24HSTARTTIME') ? $this->start_time:$this->end_time;
674
- $replace = substr($time, 0,5);
675
- break;
676
- case '#_12HSTARTTIME':
677
- case '#_12HENDTIME':
678
- $time = ($result == '#_12HSTARTTIME') ? $this->start_time:$this->end_time;
679
- $replace = date('g:i A', strtotime($time));
680
- break;
681
- //Links
682
- case '#_EVENTPAGEURL': //Depreciated
683
- case '#_LINKEDNAME': //Depreciated
684
- case '#_EVENTURL': //Just the URL
685
- case '#_EVENTLINK': //HTML Link
686
- $joiner = (stristr(EM_URI, "?")) ? "&amp;" : "?";
687
- $event_link = EM_URI.$joiner."event_id=".$this->id;
688
- if($result == '#_LINKEDNAME' || $result == '#_EVENTLINK'){
689
- $replace = "<a href='{$event_link}' title='{$this->name}'>{$this->name}</a>";
690
- }else{
691
- $replace = $event_link;
692
- }
693
- break;
694
- case '#_EDITEVENTLINK':
695
- if( $this->can_manage('edit_event','edit_others_events') ){
696
- //TODO user should have permission to edit the event
697
- $replace = "<a href='".get_bloginfo('wpurl')."/wp-admin/admin.php?page=events-manager-event&amp;event_id={$this->id}'>".__('Edit').' '.__('Event', 'dbem')."</a>";
698
- }
699
- break;
700
- //Bookings
701
- case '#_ADDBOOKINGFORM':
702
- case '#_REMOVEBOOKINGFORM':
703
- case '#_BOOKINGFORM':
704
- if ($this->rsvp && get_option('dbem_rsvp_enabled')){
705
- if($result == '#_BOOKINGFORM'){
706
- $replace = EM_Bookings_Form::create().EM_Bookings_Form::cancel();
707
- }else{
708
- $replace = ($result == '#_ADDBOOKINGFORM') ? EM_Bookings_Form::create():EM_Bookings_Form::cancel();
709
- }
710
- }
711
- break;
712
- case '#_AVAILABLESEATS': //Depreciated
713
- case '#_AVAILABLESPACES':
714
- if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
715
- $replace = $this->get_bookings()->get_available_spaces();
716
- } else {
717
- $replace = "0";
718
- }
719
- break;
720
- case '#_BOOKEDSEATS': //Depreciated
721
- case '#_BOOKEDSPACES':
722
- if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
723
- $replace = $this->get_bookings()->get_booked_spaces();
724
- } else {
725
- $replace = "0";
726
- }
727
- break;
728
- case '#_PENDINGSPACES':
729
- if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
730
- $replace = $this->get_bookings()->get_pending_spaces();
731
- } else {
732
- $replace = "0";
733
- }
734
- break;
735
- case '#_SEATS': //Depreciated
736
- case '#_SPACES':
737
- $replace = $this->get_spaces();
738
- break;
739
- //Contact Person
740
- case '#_CONTACTNAME':
741
- case '#_CONTACTPERSON': //Depreciated (your call, I think name is better)
742
- $replace = $this->contact->display_name;
743
- break;
744
- case '#_CONTACTUSERNAME':
745
- $replace = $this->contact->user_login;
746
- break;
747
- case '#_CONTACTEMAIL':
748
- case '#_CONTACTMAIL': //Depreciated
749
- $replace = $this->contact->user_email;
750
- break;
751
- case '#_CONTACTID':
752
- $replace = $this->contact->ID;
753
- break;
754
- case '#_CONTACTPHONE':
755
- $replace = ( $this->contact->phone != '') ? $this->contact->phone : __('N/A', 'dbem');
756
- break;
757
- case '#_CONTACTAVATAR':
758
- $replace = get_avatar( $this->contact->ID, $size = '50' );
759
- break;
760
- case '#_CONTACTPROFILELINK':
761
- case '#_CONTACTPROFILEURL':
762
- if( function_exists('bp_core_get_user_domain') ){
763
- $replace = bp_core_get_user_domain($this->contact->ID);
764
- if( $result == '#_CONTACTPROFILELINK' ){
765
- $replace = '<a href="'.$replace.'">'.__('Profile').'</a>';
766
- }
767
- }
768
- break;
769
- case '#_CONTACTPROFILELINK':
770
- case '#_CONTACTPROFILEURL':
771
- if( function_exists('bp_core_get_user_domain') ){
772
- $replace = bp_core_get_user_domain($this->contact->ID);
773
- if( $result == '#_CONTACTPROFILELINK' ){
774
- $replace = '<a href="'.$replace.'">'.__('Profile').'</a>';
775
- }
776
- }
777
- break;
778
- case '#_ATTENDEES':
779
- $template = em_locate_template('placeholders/attendees.php');
780
- if( $template ){
781
- ob_start();
782
- include($template);
783
- $replace = ob_get_clean();
784
- }
785
- break;
786
- default:
787
- $replace = $result;
788
- break;
789
- }
790
- $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
791
- $event_string = str_replace($result, $replace , $event_string );
792
- }
793
- //Time placeholders
794
- foreach($placeholders[0] as $result) {
795
- // matches all PHP START date and time placeholders
796
- if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) {
797
- $replace = date_i18n(ltrim($result, "#"), $this->start);
798
- $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
799
- $event_string = str_replace($result, $replace, $event_string );
800
- }
801
- // matches all PHP END time placeholders for endtime
802
- if (preg_match('/^#@[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) {
803
- $replace = date_i18n(ltrim($result, "#@"), $this->end);
804
- $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
805
- $event_string = str_replace($result, $replace, $event_string );
806
- }
807
- }
808
- //Time place holder that doesn't show if empty.
809
- //TODO add filter here too
810
- preg_match_all('/#@?_\{[A-Za-z0-9 -\/,\.\\\]+\}/', $format, $results);
811
- foreach($results[0] as $result) {
812
- if(substr($result, 0, 3 ) == "#@_"){
813
- $date = 'end_date';
814
- $offset = 4;
815
- }else{
816
- $date = 'start_date';
817
- $offset = 3;
818
- }
819
- if( $date == 'end_date' && $this->end_date == $this->start_date ){
820
- $replace = __( apply_filters('em_event_output_placeholder', '', $this, $result, $target) );
821
- }else{
822
- $replace = __( apply_filters('em_event_output_placeholder', mysql2date(substr($result, $offset, (strlen($result)-($offset+1)) ), $this->$date), $this, $result, $target) );
823
- }
824
- $event_string = str_replace($result,$replace,$event_string );
825
- }
826
- //This is for the custom attributes
827
- preg_match_all('/#_ATT\{.+?\}(\{.+?\})?/', $format, $results);
828
- foreach($results[0] as $resultKey => $result) {
829
- //Strip string of placeholder and just leave the reference
830
- $attRef = substr( substr($result, 0, strpos($result, '}')), 6 );
831
- $attString = '';
832
- if( is_array($this->attributes) && array_key_exists($attRef, $this->attributes) ){
833
- $attString = $this->attributes[$attRef];
834
- }elseif( !empty($results[2][$resultKey]) ){
835
- //Check to see if we have a second set of braces;
836
- $attString = $results[2][$resultKey];
837
- }
838
- $attString = apply_filters('em_event_output_placeholder', $attString, $this, $result, $target);
839
- $event_string = str_replace($result, $attString ,$event_string );
840
- }
841
-
842
- //Now do dependent objects
843
- $event_string = $this->location->output($event_string, $target);
844
- $event_string = $this->category->output($event_string, $target);
845
- return apply_filters('em_event_output', $event_string, $this, $target);
846
- }
847
-
848
- /**********************************************************
849
- * RECURRENCE METHODS
850
- ***********************************************************/
851
-
852
- /**
853
- * Saves events and replaces old ones. Returns true if sucecssful or false if not.
854
- * @return boolean
855
- */
856
- function save_events() {
857
- if( $this->is_recurring() && $this->can_manage('edit_events','edit_others_events') ){
858
- do_action('em_event_save_events_pre', $this); //actions/filters only run if event is recurring
859
- global $wpdb;
860
- $event_saves = array();
861
- $matching_days = $this->get_recurrence_days(); //Get days where events recur
862
- $this->delete_events(); //Delete old events beforehand
863
- //Make template event (and we just change dates)
864
- $event = $this->to_array();
865
- unset($event['event_id']); //remove id and we have a event template to feed to wpdb insert
866
- $event['event_attributes'] = serialize($event['event_attributes']);
867
- foreach($event as $key => $value ){ //remove recurrence information
868
- if( substr($key, 0, 10) == 'recurrence' ){
869
- unset($event[$key]);
870
- }
871
- }
872
- $event['recurrence_id'] = $this->id;
873
- //Save event template with different dates
874
- foreach( $matching_days as $day ) {
875
- $event['event_start_date'] = date("Y-m-d", $day);
876
- $event['event_end_date'] = $event['event_start_date'];
877
- $event_saves[] = $wpdb->insert($wpdb->prefix.EM_EVENTS_TABLE, $event, $this->get_types($event));
878
- if( EM_DEBUG ){ echo "Entering recurrence " . date("D d M Y", $day)."<br/>"; }
879
- }
880
- return apply_filters('em_event_save_events', !in_array(false, $event_saves), $this);
881
- }
882
- return apply_filters('em_event_save_events', false, $this);;
883
- }
884
-
885
- /**
886
- * Removes all reoccurring events.
887
- * @param $recurrence_id
888
- * @return null
889
- */
890
- function delete_events(){
891
- global $wpdb;
892
- do_action('em_event_delete_events_pre', $this);
893
- //So we don't do something we'll regret later, we could just supply the get directly into the delete, but this is safer
894
- $result = false;
895
- if( $this->can_manage('delete_events', 'delete_others_events') ){
896
- $EM_Events = EM_Events::get( array('recurrence_id'=>$this->id) );
897
- $event_ids = array();
898
- foreach($EM_Events as $EM_Event){
899
- if($EM_Event->recurrence_id == $this->id){
900
- $event_ids[] = $EM_Event->id; //ONLY ADD if id's match - hard coded
901
- }
902
- }
903
- $result = EM_Events::delete( $event_ids );
904
- }
905
- return apply_filters('delete_events', $result, $this);
906
- }
907
-
908
- /**
909
- * Returns true if this event is a recurring event, meaning that it's not an individual event,
910
- * but an event that defines many events that recur over a span of time.
911
- * For checking if a specific event is part of a greater set of recurring events, use is_recurrence()
912
- * @return boolean
913
- */
914
- function is_recurring(){
915
- return ( $this->recurrence );
916
- }
917
- /**
918
- * Will return true if this individual event is part of a set of events that recur
919
- * For checking if this is the "master recurring event", see is_recurring()
920
- * @return boolean
921
- */
922
- function is_recurrence(){
923
- return ( $this->id > 0 && $this->recurrence_id > 0 );
924
- }
925
- /**
926
- * Returns if this is an individual event and is not recurring or a recurrence
927
- * @return boolean
928
- */
929
- function is_individual(){
930
- return ( !$this->is_recurring() && !$this->is_recurrence() );
931
- }
932
-
933
- /**
934
- * Can the user manage this?
935
- */
936
- function can_manage( $owner_capability = false, $admin_capability = false ){
937
- return apply_filters('em_event_can_manage', parent::can_manage($owner_capability, $admin_capability), $this);
938
- }
939
-
940
- /**
941
- * Returns the days that match the recurrance array passed (unix timestamps)
942
- * @param array $recurrence
943
- * @return array
944
- */
945
- function get_recurrence_days(){
946
- if( $this->is_recurring() ){
947
-
948
- $start_date = strtotime($this->start_date);
949
- $end_date = strtotime($this->end_date);
950
-
951
- $weekdays = explode(",", $this->byday); //what days of the week (or if monthly, one value at index 0)
952
-
953
- $matching_days = array();
954
- $aDay = 86400; // a day in seconds
955
- $aWeek = $aDay * 7;
956
-
957
- //TODO can this be optimized?
958
- switch ( $this->freq ){
959
- case 'daily':
960
- //If daily, it's simple. Get start date, add interval timestamps to that and create matching day for each interval until end date.
961
- $current_date = $start_date;
962
- while( $current_date <= $end_date ){
963
- $matching_days[] = $current_date;
964
- $current_date = $current_date + ($aDay * $this->interval);
965
- }
966
- break;
967
- case 'weekly':
968
- //sort out week one, get starting days and then days that match time span of event (i.e. remove past events in week 1)
969
- $start_of_week = get_option('start_of_week'); //Start of week depends on wordpress
970
- //first, get the start of this week as timestamp
971
- $event_start_day = date('w', $start_date);
972
- $offset = 0;
973
- if( $event_start_day > $start_of_week ){
974
- $offset = $event_start_day - $start_of_week; //x days backwards
975
- }elseif( $event_start_day < $start_of_week ){
976
- $offset = $start_of_week;
977
- }
978
- $start_week_date = $start_date - ( ($event_start_day - $start_of_week) * $aDay );
979
- //then get the timestamps of weekdays during this first week, regardless if within event range
980
- $start_weekday_dates = array(); //Days in week 1 where there would events, regardless of event date range
981
- for($i = 0; $i < 7; $i++){
982
- $weekday_date = $start_week_date+($aDay*$i); //the date of the weekday we're currently checking
983
- $weekday_day = date('w',$weekday_date); //the day of the week we're checking, taking into account wp start of week setting
984
- if( in_array( $weekday_day, $weekdays) ){
985
- $start_weekday_dates[] = $weekday_date; //it's in our starting week day, so add it
986
- }
987
- }
988
- //for each day of eventful days in week 1, add 7 days * weekly intervals
989
- foreach ($start_weekday_dates as $weekday_date){
990
- //Loop weeks by interval until we reach or surpass end date
991
- while($weekday_date <= $end_date){
992
- if( $weekday_date >= $start_date && $weekday_date <= $end_date ){
993
- $matching_days[] = $weekday_date;
994
- }
995
- $weekday_date = $weekday_date + ($aWeek * $this->interval);
996
- }
997
- }//done!
998
- break;
999
- case 'monthly':
1000
- //loop months starting this month by intervals
1001
- $current_arr = getdate($start_date);
1002
- $end_arr = getdate($end_date);
1003
- $end_month_date = strtotime( date('Y-m-t', $end_date) ); //End date on last day of month
1004
- $current_date = strtotime( date('Y-m-1', $start_date) ); //Start date on first day of month
1005
- while( $current_date <= $end_month_date ){
1006
- $last_day_of_month = date('t', $current_date);
1007
- //Now find which day we're talking about
1008
- $current_week_day = date('w',$current_date);
1009
- $matching_month_days = array();
1010
- //Loop through days of this years month and save matching days to temp array
1011
- for($day = 1; $day <= $last_day_of_month; $day++){
1012
- if($current_week_day == $this->byday){
1013
- $matching_month_days[] = $day;
1014
- }
1015
- $current_week_day = ($current_week_day < 6) ? $current_week_day+1 : 0;
1016
- }
1017
- //Now grab from the array the x day of the month
1018
- $matching_day = ($this->byweekno > 0) ? $matching_month_days[$this->byweekno-1] : array_pop($matching_month_days);
1019
- $matching_date = strtotime(date('Y-m',$current_date).'-'.$matching_day);
1020
- if($matching_date >= $start_date && $matching_date <= $end_date){
1021
- $matching_days[] = $matching_date;
1022
- }
1023
- //add the number of days in this month to make start of next month
1024
- $current_arr['mon'] += $this->interval;
1025
- if($current_arr['mon'] > 12){
1026
- //FIXME this won't work if interval is more than 12
1027
- $current_arr['mon'] = $current_arr['mon'] - 12;
1028
- $current_arr['year']++;
1029
- }
1030
- $current_date = strtotime("{$current_arr['year']}-{$current_arr['mon']}-1");
1031
- }
1032
- break;
1033
- }
1034
- sort($matching_days);
1035
- //TODO delete this after testing
1036
- /*Delete*/
1037
- $test_dates = array();
1038
- foreach($matching_days as $matching_day){
1039
- $test_dates[] = date('d/m/Y', $matching_day);
1040
- }
1041
- /*end delete*/
1042
- return $matching_days;
1043
- }
1044
- }
1045
-
1046
- function get_recurrence(){
1047
- global $EM_Recurrences;
1048
- if( is_array($EM_Recurrences) && array_key_exists($this->recurrence_id, $EM_Recurrences) && is_object($EM_Recurrences[$this->recurrence_id]) && get_class($EM_Recurrences[$this->recurrence_id]) == 'EM_Event' ){
1049
- $recurrence = $EM_Recurrences[$this->recurrence_id];
1050
- }else{
1051
- //get this recurrence
1052
- $recurrence = new EM_Event($this->recurrence_id);
1053
- $EM_Recurrences[$this->recurrence_id] = $recurrence;
1054
- }
1055
- return $recurrence;
1056
- }
1057
-
1058
- /**
1059
- * Returns a string representation of this recurrence. Will return false if not a recurrence
1060
- * @return string
1061
- */
1062
- function get_recurrence_description() {
1063
- if( $this->is_individual() ) return false;
1064
- $recurrence = $this->get_recurrence()->to_array();
1065
- $weekdays_name = array(__('Sunday'),__('Monday'),__('Tuesday'),__('Wednesday'),__('Thursday'),__('Friday'),__('Saturday'));
1066
- $monthweek_name = array('1' => __('the first %s of the month', 'dbem'),'2' => __('the second %s of the month', 'dbem'), '3' => __('the third %s of the month', 'dbem'), '4' => __('the fourth %s of the month', 'dbem'), '-1' => __('the last %s of the month', 'dbem'));
1067
- $output = sprintf (__('From %1$s to %2$s', 'dbem'), $recurrence['event_start_date'], $recurrence['event_end_date']).", ";
1068
- if ($recurrence['recurrence_freq'] == 'daily') {
1069
- $freq_desc =__('everyday', 'dbem');
1070
- if ($recurrence['recurrence_interval'] > 1 ) {
1071
- $freq_desc = sprintf (__("every %s days", 'dbem'), $recurrence['recurrence_interval']);
1072
- }
1073
- }elseif ($recurrence['recurrence_freq'] == 'weekly') {
1074
- $weekday_array = explode(",", $recurrence['recurrence_byday']);
1075
- $natural_days = array();
1076
- foreach($weekday_array as $day){
1077
- array_push($natural_days, $weekdays_name[$day]);
1078
- }
1079
- $output .= implode(" and ", $natural_days);
1080
- $freq_desc = ", " . __("every week", 'dbem');
1081
- if ($recurrence['recurrence_interval'] > 1 ) {
1082
- $freq_desc = ", ".sprintf (__("every %s weeks", 'dbem'), $recurrence['recurrence_interval']);
1083
- }
1084
-
1085
- }elseif ($recurrence['recurrence_freq'] == 'monthly') {
1086
- $weekday_array = explode(",", $recurrence['recurrence_byday']);
1087
- $natural_days = array();
1088
- foreach($weekday_array as $day){
1089
- array_push($natural_days, $weekdays_name[$day]);
1090
- }
1091
- $freq_desc = sprintf (($monthweek_name[$recurrence['recurrence_byweekno']]), implode(" and ", $natural_days));
1092
- if ($recurrence['recurrence_interval'] > 1 ) {
1093
- $freq_desc .= ", ".sprintf (__("every %s months",'dbem'), $recurrence['recurrence_interval']);
1094
- }
1095
- }else{
1096
- $freq_desc = "[ERROR: corrupted database record]";
1097
- }
1098
- $output .= $freq_desc;
1099
- return $output;
1100
- }
1101
-
1102
- /**********************************************************
1103
- * UTILITIES
1104
- ***********************************************************/
1105
-
1106
- /**
1107
- * Returns this object in the form of an array, useful for saving directly into the wp_dbem_events table.
1108
- * @param boolean $for_database
1109
- * @return array
1110
- */
1111
- function to_array($for_database = false){
1112
- $event = array();
1113
- //Core Event Data
1114
- foreach ( $this->fields as $key => $val ) {
1115
- //TODO does it matter if it's for db or not... shouldn't it just not include blanks?
1116
- if( !$for_database || $for_database && $this->$val['name'] != '' ){
1117
- $event[$key] = $this->$val['name'];
1118
- }
1119
- }
1120
- return $event;
1121
- }
1122
- }
1123
-
1124
- //TODO placeholder targets filtering could be streamlined better
1125
- /**
1126
- * This is a temporary filter function which mimicks the old filters in the old 2.x placeholders function
1127
- * @param string $result
1128
- * @param EM_Event $event
1129
- * @param string $placeholder
1130
- * @param string $target
1131
- * @return mixed
1132
- */
1133
- function em_event_output_placeholder($result,$event,$placeholder,$target='html'){
1134
- if( ($placeholder == "#_EXCERPT" || $placeholder == "#_LOCATIONEXCERPT") && $target == 'html' ){
1135
- $result = apply_filters('dbem_notes_excerpt', $result);
1136
- }elseif( $placeholder == '#_CONTACTEMAIL' && $target == 'html' ){
1137
- $result = em_ascii_encode($event->contact->user_email);
1138
- }elseif( $placeholder == "#_NOTES" || $placeholder == "#_EXCERPT" || $placeholder == "#_LOCATIONEXCERPT" ){
1139
- if($target == 'html'){
1140
- $result = apply_filters('dbem_notes', $result);
1141
- }elseif($target == 'map'){
1142
- $result = apply_filters('dbem_notes_map', $result);
1143
- }else{
1144
- $result = apply_filters('dbem_notes_rss', $result);
1145
- $result = apply_filters('the_content_rss', $result);
1146
- }
1147
- }elseif( in_array($placeholder, array("#_NAME",'#_ADDRESS','#_LOCATION','#_TOWN')) ){
1148
- if ($target == "html"){
1149
- $result = apply_filters('dbem_general', $result);
1150
- }else{
1151
- $result = apply_filters('dbem_general_rss', $result);
1152
- }
1153
- }
1154
- return $result;
1155
- }
1156
- add_filter('em_event_output_placeholder','em_event_output_placeholder',1,4);
1157
  ?>
1
+ <?php
2
+ /**
3
+ * Event Object. This holds all the info pertaining to an event, including location and recurrence info.
4
+ * An event object can be one of three "types" a recurring event, recurrence of a recurring event, or a single event.
5
+ * The single event might be part of a set of recurring events, but if loaded by specific event id then any operations and saves are
6
+ * specifically done on this event. However, if you edit the recurring group, any changes made to single events are overwritten.
7
+ *
8
+ * @author marcus
9
+ */
10
+ //TODO Can add more recurring functionality such as "also update all future recurring events" or "edit all events" like google calendar does.
11
+ //TODO Integrate recurrences into events table
12
+ //FIXME If you create a super long recurrence timespan, there could be thousands of events... need an upper limit here.
13
+ class EM_Event extends EM_Object{
14
+ /**
15
+ * Assoc array where keys are names of database fields and values are array corresponding object property name, regex, data types, etc.
16
+ * for use when importing/exporting event data between database and object
17
+ * @var array
18
+ */
19
+ var $fields = array(
20
+ 'event_id' => array( 'name'=>'id', 'type'=>'%d' ),
21
+ 'event_author' => array( 'name'=>'author', 'type'=>'%d' ),
22
+ 'event_name' => array( 'name'=>'name', 'type'=>'%s' ),
23
+ 'event_start_time' => array( 'name'=>'start_time', 'type'=>'%s' ),
24
+ 'event_end_time' => array( 'name'=>'end_time', 'type'=>'%s' ),
25
+ 'event_start_date' => array( 'name'=>'start_date', 'type'=>'%s' ),
26
+ 'event_end_date' => array( 'name'=>'end_date', 'type'=>'%s' ),
27
+ 'event_notes' => array( 'name'=>'notes', 'type'=>'%s' ),
28
+ 'event_rsvp' => array( 'name'=>'rsvp', 'type'=>'%d' ),
29
+ 'event_seats' => array( 'name'=>'seats', 'type'=>'%d' ),
30
+ 'event_contactperson_id' => array( 'name'=>'contactperson_id', 'type'=>'%d' ),
31
+ 'location_id' => array( 'name'=>'location_id', 'type'=>'%d' ),
32
+ 'recurrence_id' => array( 'name'=>'recurrence_id', 'type'=>'%d' ),
33
+ 'event_category_id' => array( 'name'=>'category_id', 'type'=>'%d' ),
34
+ 'event_attributes' => array( 'name'=>'attributes', 'type'=>'%s' ),
35
+ 'recurrence' => array( 'name'=>'recurrence', 'type'=>'%d' ),
36
+ 'recurrence_interval' => array( 'name'=>'interval', 'type'=>'%d' ), //every x day(s)/week(s)/month(s)
37
+ 'recurrence_freq' => array( 'name'=>'freq', 'type'=>'%s' ), //daily,weekly,monthly?
38
+ 'recurrence_byday' => array( 'name'=>'byday', 'type'=>'%s' ), //if weekly or monthly, what days of the week?
39
+ 'recurrence_byweekno' => array( 'name'=>'byweekno', 'type'=>'%d' ), //if monthly which week (-1 is last)
40
+ 'event_date_created' => array( 'name'=>'date_created', 'type'=>'%s' ),
41
+ 'event_date_modified' => array( 'name'=>'date_modified', 'type'=>'%s' )
42
+ );
43
+ /* Field Names - see above for matching DB field names and other field meta data */
44
+ var $id;
45
+ var $author;
46
+ var $name;
47
+ var $start_time;
48
+ var $end_time;
49
+ var $start_date;
50
+ var $end_date;
51
+ var $notes;
52
+ var $rsvp;
53
+ var $seats;
54
+ var $contactperson_id;
55
+ var $location_id;
56
+ var $recurrence_id;
57
+ var $category_id;
58
+ var $attributes;
59
+ var $recurrence;
60
+ var $interval;
61
+ var $freq;
62
+ var $byday;
63
+ var $byweekno;
64
+ var $date_created;
65
+ var $date_modified;
66
+
67
+ /**
68
+ * Timestamp of start date/time
69
+ * @var int
70
+ */
71
+ var $start;
72
+ /**
73
+ * Timestamp of end date/time
74
+ * @var int
75
+ */
76
+ var $end;
77
+ /**
78
+ * Created on timestamp, taken from DB, converted to TS
79
+ * @var int
80
+ */
81
+ var $created;
82
+ /**
83
+ * Created on timestamp, taken from DB, converted to TS
84
+ * @var int
85
+ */
86
+ var $modified;
87
+
88
+ /**
89
+ * @var EM_Location
90
+ */
91
+ var $location;
92
+ /**
93
+ * @var EM_Bookings
94
+ */
95
+ var $bookings;
96
+ /**
97
+ * The contact person for this event
98
+ * @var WP_User
99
+ */
100
+ var $contact;
101
+ /**
102
+ * The category object
103
+ * @var EM_Category
104
+ */
105
+ var $category;
106
+ /**
107
+ * If there are any errors, they will be added here.
108
+ * @var array
109
+ */
110
+ var $errors = array();
111
+ /**
112
+ * If something was successful, a feedback message might be supplied here.
113
+ * @var string
114
+ */
115
+ var $feedback_message;
116
+ /**
117
+ * Array of dbem_event field names required to create an event
118
+ * @var array
119
+ */
120
+ var $required_fields = array('event_name', 'event_start_date');
121
+
122
+ /**
123
+ * Initialize an event. You can provide event data in an associative array (using database table field names), an id number, or false (default) to create empty event.
124
+ * @param mixed $event_data
125
+ * @param boolean $recurrent
126
+ * @return null
127
+ */
128
+ function EM_Event($event_data = false, $recurrent = false) {
129
+ global $wpdb, $EM_Recurrences;
130
+ //TODO Change the way we deal with time, maybe revert to timestamps for manipulation, and worry about output in html and db writes?
131
+ if( $event_data !== false ){
132
+ $event = array();
133
+ if( is_array($event_data) ){
134
+ //Accepts a raw array that'll just be imported directly into the object with no DB lookups (same for event and recurrence)
135
+ $event = $event_data;
136
+ $this->location = new EM_Location( $event );
137
+ $this->category = new EM_Category( $event );
138
+ }elseif( is_numeric($event_data) && $event_data > 0 ){
139
+ //Retreiving from the database
140
+ $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
141
+ $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
142
+ $categories_table = $wpdb->prefix . EM_CATEGORIES_TABLE;
143
+ $sql = "
144
+ SELECT * FROM $events_table
145
+ LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
146
+ LEFT JOIN $categories_table ON {$categories_table}.category_id={$events_table}.event_category_id
147
+ WHERE event_id = $event_data
148
+ "; //We get event and location data here to avoid extra queries
149
+ $event = $wpdb->get_row ( $sql, ARRAY_A );
150
+ //Sort Location
151
+ $this->location = new EM_Location ( $event );
152
+ $this->category = new EM_Category( $event );
153
+ }
154
+ //Sort out attributes
155
+ if( !empty($event['event_attributes']) ){
156
+ if( is_serialized($event['event_attributes']) ){
157
+ $event['event_attributes'] = @unserialize($event['event_attributes']);
158
+ }
159
+ $event['event_attributes'] = (!is_array($event['event_attributes'])) ? array() : $event['event_attributes'] ;
160
+ }
161
+ $event['recurrence_byday'] = ( $event['recurrence_byday'] == 7 ) ? 0:$event['recurrence_byday']; //Backward compatibility (since 3.0.3), using 0 makes more sense due to date() function
162
+ $this->to_object($event, true);
163
+
164
+ //Start/End times should be available as timestamp
165
+ $this->start = strtotime($this->start_date." ".$this->start_time);
166
+ $this->end = strtotime($this->end_date." ".$this->end_time);
167
+ $this->modified = strtotime($event['event_date_modified']);
168
+ $this->created = strtotime($event['event_date_created']);
169
+
170
+ //Add Contact Person
171
+ if($this->contactperson_id){
172
+ if($this->contactperson_id > 0){
173
+ $this->contact = get_userdata($this->contactperson_id);
174
+ }
175
+ }
176
+ if( !is_object($this->contact) ){
177
+ $this->contactperson_id = get_option('dbem_default_contact_person');
178
+ $this->contact = get_userdata($this->contactperson_id);
179
+ }
180
+ if( is_object($this->contact) ){
181
+ $this->contact->phone = get_metadata('user', $this->contact->ID, 'dbem_phone', true);
182
+ }
183
+ //Now, if this is a recurrence, get the recurring for caching to the $EM_Recurrences
184
+ if( $this->is_recurrence() && !array_key_exists($this->recurrence_id, $EM_Recurrences) ){
185
+ $EM_Recurrences[$this->recurrence_id] = new EM_Event($this->recurrence_id);
186
+ }
187
+ }else{
188
+ $this->location = new EM_Location(); //blank location
189
+ $this->category = new EM_Category(); //blank category
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Retrieve event, location and recurring information via POST
195
+ * @return boolean
196
+ */
197
+ function get_post(){
198
+ //Build Event Array
199
+ do_action('em_event_get_post_pre', $this);
200
+ $this->name = ( !empty($_POST['event_name']) ) ? stripslashes($_POST['event_name']) : '' ;
201
+ $this->start_date = ( !empty($_POST['event_start_date']) ) ? $_POST['event_start_date'] : '';
202
+ $this->end_date = ( !empty($_POST['event_end_date']) ) ? $_POST['event_end_date'] : $this->start_date;
203
+ $this->rsvp = ( !empty($_POST['event_rsvp']) ) ? 1:0;
204
+ $this->seats = ( !empty($_POST['event_seats']) && is_numeric($_POST['event_seats']) ) ? $_POST['event_seats']:0;
205
+ $this->notes = ( !empty($_POST['content']) ) ? stripslashes($_POST['content']) : ''; //WP TinyMCE field
206
+ //Sort out time
207
+ //TODO make time handling less painful
208
+ $match = array();
209
+ if( !empty($_POST['event_start_time']) && preg_match ( '/^([01]\d|2[0-3]):([0-5]\d)(AM|PM)?$/', $_POST['event_start_time'], $match ) ){
210
+ if( $match[3] == 'PM' && $match[1] != 12 ){
211
+ $match[1] = 12+$match[1];
212
+ }elseif( $match[3] == 'AM' && $match[1] == 12 ){
213
+ $match[1] = '00';
214
+ }
215
+ $this->start_time = $match[1].":".$match[2].":00";
216
+ }else{
217
+ $this->start_time = "00:00:00";
218
+ }
219
+ if( !empty($_POST['event_end_time']) && preg_match ( '/^([01]\d|2[0-3]):([0-5]\d)(AM|PM)?$/', $_POST['event_end_time'], $match ) ){
220
+ if( $match[3] == 'PM' && $match[1] != 12 ){
221
+ $match[1] = 12+$match[1];
222
+ }elseif( $match[3] == 'AM' && $match[1] == 12 ){
223
+ $match[1] = '00';
224
+ }
225
+ $this->end_time = $match[1].":".$match[2].":00";
226
+ }else{
227
+ $this->end_time = $this->start_time;
228
+ }
229
+ //Start/End times should be available as timestamp
230
+ $this->start = strtotime($this->start_date." ".$this->start_time);
231
+ $this->end = strtotime($this->end_date." ".$this->end_time);
232
+ //Contact Person
233
+ if ( !empty($_POST['event_contactperson_id']) && is_numeric($_POST['event_contactperson_id']) ) {
234
+ //TODO contactperson choices needs limiting depending on role
235
+ $this->contactperson_id = $_POST['event_contactperson_id'];
236
+ }
237
+ //category
238
+ if( !empty($_POST['event_category_id']) && is_numeric($_POST['event_category_id']) ){
239
+ $this->category_id = $_POST['event_category_id'];
240
+ }
241
+ //Attributes
242
+ $event_attributes = array();
243
+ for($i=1 ; !empty($_POST["mtm_{$i}_ref"]) && trim($_POST["mtm_{$i}_ref"]) != '' ; $i++ ){
244
+ if( !empty($_POST["mtm_{$i}_name"]) && trim($_POST["mtm_{$i}_name"]) != '' ){
245
+ $event_attributes[$_POST["mtm_{$i}_ref"]] = stripslashes($_POST["mtm_{$i}_name"]);
246
+ }
247
+ }
248
+ $this->attributes = $event_attributes;
249
+ //Recurrence data
250
+ $this->recurrence_id = ( !empty($_POST['recurrence_id']) && is_numeric($_POST['recurrence_id']) ) ? $_POST['recurrence_id'] : 0 ;
251
+ if( !empty($_POST['repeated_event']) ){
252
+ $this->recurrence = 1;
253
+ $this->freq = ( !empty($_POST['recurrence_freq']) && in_array($_POST['recurrence_freq'], array('daily','weekly','monthly')) ) ? $_POST['recurrence_freq']:'daily';
254
+ if( !empty($_POST['recurrence_bydays']) && $this->freq == 'weekly' && self::array_is_numeric($_POST['recurrence_bydays']) ){
255
+ $this->byday = implode ( ",", $_POST['recurrence_bydays'] );
256
+ }elseif( !empty($_POST['recurrence_byday']) && $this->freq == 'monthly' ){
257
+ $this->byday = $_POST['recurrence_byday'];
258
+ }
259
+ $this->interval = ( !empty($_POST['recurrence_interval']) ) ? $_POST['recurrence_interval']:1;
260
+ $this->byweekno = ( !empty($_POST['recurrence_byweekno']) ) ? $_POST['recurrence_byweekno']:'';
261
+ }
262
+
263
+ //Add location information, or just link to previous location, this is a requirement...
264
+ if( !empty($_POST['location-select-id']) ) {
265
+ $this->location = new EM_Location($_POST['location-select-id']);
266
+ } else {
267
+ $this->location = new EM_Location($_POST);
268
+ $this->location->load_similar($_POST);
269
+ }
270
+ return apply_filters('em_event_get_post', $this->validate(), $this);
271
+ }
272
+
273
+ /**
274
+ * Will save the current instance into the database, along with location information if a new one was created and return true if successful, false if not.
275
+ * Will automatically detect what type of event it is (recurrent, recurrence or normal) and whether it's a new or existing event.
276
+ * @return boolean
277
+ */
278
+ function save(){
279
+ //FIXME Event doesn't save title when inserting first time
280
+ global $wpdb, $current_user;
281
+ if( !$this->can_manage(true) ){
282
+ return apply_filters('em_event_save', false, $this);
283
+ }
284
+ do_action('em_event_save_pre', $this);
285
+ get_currentuserinfo();
286
+ $events_table = $wpdb->prefix.EM_EVENTS_TABLE;
287
+ //First let's save the location, no location no event!
288
+ if ( !$this->location->id && !$this->location->save() ){ //shouldn't try to save if location exists
289
+ $this->errors[] = __ ( 'There was a problem saving the location so event was not saved.', 'dbem' );
290
+ return apply_filters('em_event_save', false, $this);
291
+ }
292
+ $this->location_id = $this->location->id;
293
+ //Contact person can be anyone the admin wants, but the creator if not.
294
+ if( em_verify_admin() ){
295
+ $this->contactperson_id = ( $this->contactperson_id > 0 ) ? $this->contactperson_id:0;
296
+ }else{
297
+ //force
298
+ $this->contactperson_id = get_current_user_id();
299
+ }
300
+ //Now save the event
301
+ if ( !$this->id ) {
302
+ // Insert New Event
303
+ $this->author = $current_user->ID; //Record creator of event
304
+ $event = $this->to_array(false, true);
305
+ $event['event_attributes'] = serialize($this->attributes);
306
+ $event['recurrence_id'] = ( is_numeric($this->recurrence_id) ) ? $this->recurrence_id : 0;
307
+ $event = apply_filters('em_event_save_pre',$event,$this);
308
+ $result = $wpdb->insert ( $events_table, $event, $this->get_types($event) );
309
+ if($result !== false){
310
+ $this->id = $wpdb->insert_id;
311
+ //Deal with recurrences
312
+ if ( $this->is_recurring() ) {
313
+ //Recurrence master event saved, now Save Events & check errors
314
+ if( !$this->save_events() ){
315
+ $this->errors[] = __ ( 'Something went wrong with the recurrence update...', 'dbem' ).
316
+ __ ( 'There was a problem saving the recurring events.', 'dbem' );
317
+ $this->delete();
318
+ return apply_filters('em_event_save', false, $this);
319
+ }
320
+ //All good! Event Saved
321
+ $this->feedback_message = __ ( 'New recurrent event inserted!', 'dbem' );
322
+ return apply_filters('em_event_save', true, $this);
323
+ }
324
+ //Successful individual save
325
+ $this->feedback_message = __ ( 'New event successfully inserted!', 'dbem' );
326
+ return apply_filters('em_event_save', true, $this);
327
+ }else{
328
+ $this->errors[] = __ ( 'Could not save the event details due to a database error.', 'dbem' );
329
+ }
330
+ } else {
331
+ // Update Event
332
+ //TODO event privacy protection, only authors and authorized users can edit events
333
+ //$this->author = $current_user->ID; //Record creator of event
334
+ //FIXME Saving recurrence and disabling recurrence doesn't work
335
+ $this->recurrence_id = 0; // If it's saved here, it becomes individual
336
+ $event = $this->to_array();
337
+ $event['event_attributes'] = serialize($event['event_attributes']);
338
+ $event['event_date_modified'] = current_time('mysql');
339
+ $event = apply_filters('em_event_save_pre',$event,$this);
340
+ $result = $wpdb->update ( $events_table, $event, array('event_id' => $this->id), $this->get_types($event) );
341
+ if($result !== false){ //Can't just do $result since if you don't make an actual record details change, it'll return 0 for no changes made
342
+ //Deal with recurrences
343
+ if ( $this->is_recurring() ) {
344
+ if( !$this->save_events() ){
345
+ $this->errors[] = __ ( 'Something went wrong with the recurrence update...', 'dbem' ).
346
+ __ ( 'There was a problem saving the recurring events.', 'dbem' );
347
+ return apply_filters('em_event_save', false, $this);
348
+ }
349
+ $this->feedback_message = __ ( 'Recurrence updated!', 'dbem' );
350
+ return apply_filters('em_event_save', true, $this);
351
+ }
352
+ }else{
353
+ $this->errors[] = __('Could not save the event details due to a database error.', 'dbem');
354
+ return apply_filters('em_event_save', false, $this);
355
+ }
356
+ //Successful individual or recurrence save
357
+ $this->feedback_message = "{$this->name} " . __ ( 'updated', 'dbem' ) . "!";
358
+ if($this->rsvp == 0){
359
+ $this->delete_bookings();
360
+ }
361
+ return apply_filters('em_event_save', true, $this);
362
+ }
363
+ }
364
+
365
+ /**
366
+ * Delete whole event, including recurrence and recurring data
367
+ * @param $recurrence_id
368
+ * @return boolean
369
+ */
370
+ function delete(){
371
+ global $wpdb;
372
+ do_action('em_event_delete_pre', $this);
373
+ $result = false;
374
+ if( $this->can_manage(true) ){
375
+ if( $this->is_recurring() ){
376
+ //Delete the recurrences then this recurrence event
377
+ $this->delete_events();
378
+ }
379
+ $result = $wpdb->query ( $wpdb->prepare("DELETE FROM ". $wpdb->prefix . EM_EVENTS_TABLE ." WHERE event_id=%d", $this->id) );
380
+ if($result !== false){
381
+ $result = $this->get_bookings()->delete();
382
+ }
383
+ }
384
+ return apply_filters('em_event_delete', $result, $this);
385
+ }
386
+
387
+ /**
388
+ * Duplicates this event and returns the duplicated event. Will return false if there is a problem with duplication.
389
+ * @return EM_Event
390
+ */
391
+ function duplicate(){
392
+ global $wpdb, $EZSQL_ERROR;
393
+ //First, duplicate.
394
+ if( $this->can_manage(true) ){
395
+ $event_table_name = $wpdb->prefix . EM_EVENTS_TABLE;
396
+ $eventArray = $this->to_array(true);
397
+ unset($eventArray['event_id']);
398
+ $EM_Event = new EM_Event( $eventArray );
399
+ if( $EM_Event->save() ){
400
+ $EM_Event->feedback_message = __("You are now viewing the duplicated event", 'dbem');
401
+ return apply_filters('em_event_duplicate', $EM_Event, $this);
402
+ }
403
+ }
404
+ //TODO add error notifications for duplication failures.
405
+ return apply_filters('em_event_duplicate', false, $this);;
406
+ }
407
+
408
+
409
+ /**
410
+ * Validates the event. Should be run during any form submission or saving operation.
411
+ * @return boolean
412
+ */
413
+ function validate() {
414
+ $missing_fields = Array ();
415
+ foreach ( $this->required_fields as $field ) {
416
+ $true_field = $this->fields[$field]['name'];
417
+ if ( $this->$true_field == "") {
418
+ $missing_fields[] = $field;
419
+ }
420
+ }
421
+ if ( count($missing_fields) > 0){
422
+ // TODO Create friendly equivelant names for missing fields notice in validation
423
+ $this->errors[] = __ ( 'Missing fields: ' ) . implode ( ", ", $missing_fields ) . ". ";
424
+ }
425
+ if ( !empty($_POST['repeated_event']) && $_POST['repeated_event'] == "1" && $this->end_date == "" ){
426
+ $this->errors[] = __ ( 'Since the event is repeated, you must specify an event date.', 'dbem' );
427
+ }
428
+ if( preg_match('/\d{4}-\d{2}-\d{2}/', $this->start_date) && preg_match('/\d{4}-\d{2}-\d{2}/', $this->end_date) ){
429
+ if( strtotime($this->start_date . $this->start_time) > strtotime($this->end_date . $this->end_time) ){
430
+ $this->errors[] = __('Events cannot start after they end.','dbem');
431
+ }
432
+ }else{
433
+ $this->errors[] = __('Dates must have correct formatting. Please use the date picker provided.','dbem');
434
+ }
435
+ if( !$this->location->validate() ){
436
+ $this->errors = array_merge($this->errors, $this->location->errors);
437
+ }
438
+ //TODO validate recurrence during event validate
439
+ return apply_filters('em_event_validate', count($this->errors) == 0, $this );
440
+ }
441
+
442
+
443
+ /**
444
+ * Returns an array with category id and name (in that order) of the EM_Event instance.
445
+ * @return array
446
+ */
447
+ function get_category() {
448
+ global $EM_Category;
449
+ if( is_object($this->category) && get_class($this->category)=='EM_Category' && $this->category_id == $this->category->id ){
450
+ return $this->category;
451
+ }elseif( is_object($EM_Category) && $EM_Category->id == $this->category_id ){
452
+ $this->category = $EM_Category;
453
+ }else{
454
+ $this->category = new EM_Category($this->category_id);
455
+ }
456
+ return $this->event;
457
+ global $wpdb;
458
+ $sql = "SELECT category_id, category_name FROM ".$wpdb->prefix.EM_EVENTS_TABLE." LEFT JOIN ".$wpdb->prefix.EM_CATEGORIES_TABLE." ON category_id=event_category_id WHERE event_id ='".$this->id."'";
459
+ $category = $wpdb->get_row($sql, ARRAY_A);
460
+ return apply_filters('em_event_get_category', $category, $this);
461
+ }
462
+
463
+ /**
464
+ * Shortcut function for $this->get_bookings()->delete(), because using the EM_Bookings requires loading previous bookings, which isn't neceesary.
465
+ */
466
+ function delete_bookings(){
467
+ global $wpdb;
468
+ do_action('em_event_delete_bookings_pre', $this);
469
+ $result = false;
470
+ if( $this->can_manage(true) ){
471
+ $result = $wpdb->query( $wpdb->prepare("DELETE FROM ".$wpdb->prefix.EM_BOOKINGS_TABLE." WHERE event_id=%d", $this->id) );
472
+ }
473
+ return apply_filters('em_event_delete_bookings', $result, $this);
474
+ }
475
+
476
+ /**
477
+ * Retrieve and save the bookings belonging to instance. If called again will return cached version, set $force_reload to true to create a new EM_Bookings object.
478
+ * @param boolean $force_reload
479
+ * @return EM_Bookings
480
+ */
481
+ function get_bookings( $force_reload = false ){
482
+ if( get_option('dbem_rsvp_enabled') ){
483
+ if( (!$this->bookings || $force_reload) ){
484
+ $this->bookings = new EM_Bookings($this);
485
+ }
486
+ }
487
+ return apply_filters('em_event_get_bookings', $this->bookings, $this);
488
+ }
489
+
490
+ /**
491
+ * Will output a single event format of this event.
492
+ * Equivalent of calling EM_Event::output( get_option ( 'dbem_single_event_format' ) )
493
+ * @param string $target
494
+ * @return string
495
+ */
496
+ function output_single($target='html'){
497
+ $format = get_option ( 'dbem_single_event_format' );
498
+ return apply_filters('em_event_output_single', $this->output($format, $target), $this, $target);
499
+ }
500
+
501
+ /**
502
+ * Will output a event list item format of this event.
503
+ * Equivalent of calling EM_Event::output( get_option ( 'dbem_event_list_item_format' ) )
504
+ * @param string $target
505
+ * @return string
506
+ */
507
+ function output_list($target='html'){
508
+ $format = get_option ( 'dbem_event_list_item_format' );
509
+ return apply_filters('em_event_output_list', $this->output($format, $target), $this, $target);
510
+ }
511
+
512
+ /**
513
+ * Will output a event in the format passed in $format by replacing placeholders within the format.
514
+ * @param string $format
515
+ * @param string $target
516
+ * @return string
517
+ */
518
+ function output($format, $target="html") {
519
+ $event_string = $format;
520
+ preg_match_all("/#@?_?[A-Za-z0-9]+/", $format, $placeholders);
521
+ foreach($placeholders[0] as $result) {
522
+ $match = true;
523
+ $replace = '';
524
+ switch( $result ){
525
+ //Event Details
526
+ case '#_EVENTID':
527
+ $replace = $this->id;
528
+ break;
529
+ case '#_NAME':
530
+ $replace = $this->name;
531
+ break;
532
+ case '#_NOTES':
533
+ case '#_EXCERPT':
534
+ //SEE AT BOTTOM OF FILE FOR OLD TARGET FILTERS FROM 2.x
535
+ $replace = $this->notes;
536
+ if($result == "#_EXCERPT"){
537
+ $matches = explode('<!--more', $this->notes);
538
+ $replace = $matches[0];
539
+ }
540
+ break;
541
+ //Times
542
+ case '#_24HSTARTTIME':
543
+ case '#_24HENDTIME':
544
+ $time = ($result == '#_24HSTARTTIME') ? $this->start_time:$this->end_time;
545
+ $replace = substr($time, 0,5);
546
+ break;
547
+ case '#_12HSTARTTIME':
548
+ case '#_12HENDTIME':
549
+ $time = ($result == '#_12HSTARTTIME') ? $this->start_time:$this->end_time;
550
+ $replace = date('g:i A', strtotime($time));
551
+ break;
552
+ //Links
553
+ case '#_EVENTPAGEURL': //Depreciated
554
+ case '#_LINKEDNAME': //Depreciated
555
+ case '#_EVENTURL': //Just the URL
556
+ case '#_EVENTLINK': //HTML Link
557
+ $joiner = (stristr(EM_URI, "?")) ? "&amp;" : "?";
558
+ $event_link = EM_URI.$joiner."event_id=".$this->id;
559
+ if($result == '#_LINKEDNAME' || $result == '#_EVENTLINK'){
560
+ $replace = "<a href='{$event_link}' title='{$this->name}'>{$this->name}</a>";
561
+ }else{
562
+ $replace = $event_link;
563
+ }
564
+ break;
565
+ case '#_EDITEVENTLINK':
566
+ if( $this->can_manage() ){
567
+ //TODO user should have permission to edit the event
568
+ $replace = "<a href='".get_bloginfo('wpurl')."/wp-admin/admin.php?page=events-manager-event&amp;event_id={$this->id}'>".__('Edit').' '.__('Event', 'dbem')."</a>";
569
+ }
570
+ break;
571
+ //Bookings
572
+ case '#_ADDBOOKINGFORM':
573
+ case '#_REMOVEBOOKINGFORM':
574
+ case '#_BOOKINGFORM':
575
+ if ($this->rsvp && get_option('dbem_rsvp_enabled')){
576
+ if($result == '#_BOOKINGFORM'){
577
+ $replace = em_add_booking_form().em_delete_booking_form();
578
+ }else{
579
+ $replace = ($result == '#_ADDBOOKINGFORM') ? em_add_booking_form():em_delete_booking_form();
580
+ }
581
+ }
582
+ break;
583
+ case '#_AVAILABLESEATS': //Depreciated
584
+ case '#_AVAILABLESPACES':
585
+ if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
586
+ $replace = $this->get_bookings()->get_available_seats();
587
+ } else {
588
+ $replace = "0";
589
+ }
590
+ break;
591
+ case '#_BOOKEDSEATS': //Depreciated
592
+ case '#_BOOKEDSPACES':
593
+ if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
594
+ $replace = $this->get_bookings()->get_booked_seats();
595
+ } else {
596
+ $replace = "0";
597
+ }
598
+ break;
599
+ case '#_SEATS': //Depreciated
600
+ case '#_SPACES':
601
+ $replace = $this->seats;
602
+ break;
603
+ //Contact Person
604
+ case '#_CONTACTNAME':
605
+ case '#_CONTACTPERSON': //Depreciated (your call, I think name is better)
606
+ $replace = $this->contact->display_name;
607
+ break;
608
+ case '#_CONTACTUSERNAME':
609
+ $replace = $this->contact->user_login;
610
+ break;
611
+ case '#_CONTACTEMAIL':
612
+ case '#_CONTACTMAIL': //Depreciated
613
+ $replace = $this->contact->user_email;
614
+ break;
615
+ case '#_CONTACTID':
616
+ $replace = $this->contact->ID;
617
+ break;
618
+ case '#_CONTACTPHONE':
619
+ $replace = ( $this->contact->phone != '') ? $this->contact->phone : __('N/A', 'dbem');
620
+ break;
621
+ case '#_CONTACTAVATAR':
622
+ $replace = get_avatar( $this->contact->ID, $size = '50' );
623
+ break;
624
+ case '#_CONTACTPROFILELINK':
625
+ case '#_CONTACTPROFILEURL':
626
+ if( function_exists('bp_core_get_user_domain') ){
627
+ $replace = bp_core_get_user_domain($this->contact->ID);
628
+ if( $result == '#_CONTACTPROFILELINK' ){
629
+ $replace = '<a href="'.$replace.'">'.__('Profile').'</a>';
630
+ }
631
+ }
632
+ break;
633
+ default:
634
+ $replace = $result;
635
+ break;
636
+ }
637
+ $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
638
+ $event_string = str_replace($result, $replace , $event_string );
639
+ }
640
+ //Time placeholders
641
+ foreach($placeholders[0] as $result) {
642
+ // matches all PHP START date and time placeholders
643
+ if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) {
644
+ $replace = date_i18n(ltrim($result, "#"), $this->start);
645
+ $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
646
+ $event_string = str_replace($result, $replace, $event_string );
647
+ }
648
+ // matches all PHP END time placeholders for endtime
649
+ if (preg_match('/^#@[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) {
650
+ $replace = date_i18n(ltrim($result, "#@"), $this->end);
651
+ $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
652
+ $event_string = str_replace($result, $replace, $event_string );
653
+ }
654
+ }
655
+ //Time place holder that doesn't show if empty.
656
+ //TODO add filter here too
657
+ preg_match_all('/#@?_\{[A-Za-z0-9 -\/,\.\\\]+\}/', $format, $results);
658
+ foreach($results[0] as $result) {
659
+ if(substr($result, 0, 3 ) == "#@_"){
660
+ $date = 'end_date';
661
+ $offset = 4;
662
+ }else{
663
+ $date = 'start_date';
664
+ $offset = 3;
665
+ }
666
+ if( $date == 'end_date' && $this->end_date == $this->start_date ){
667
+ $replace = __( apply_filters('em_event_output_placeholder', '', $this, $result, $target) );
668
+ }else{
669
+ $replace = __( apply_filters('em_event_output_placeholder', mysql2date(substr($result, $offset, (strlen($result)-($offset+1)) ), $this->$date), $this, $result, $target) );
670
+ }
671
+ $event_string = str_replace($result,$replace,$event_string );
672
+ }
673
+ //This is for the custom attributes
674
+ preg_match_all('/#_ATT\{.+?\}(\{(.+)\})?/', $format, $results);
675
+ foreach($results[0] as $resultKey => $result) {
676
+ //Strip string of placeholder and just leave the reference
677
+ $attRef = substr( substr($result, 0, strpos($result, '}')), 6 );
678
+ $attString = '';
679
+ if( is_array($this->attributes) && array_key_exists($attRef, $this->attributes) ){
680
+ $attString = $this->attributes[$attRef];
681
+ }elseif( !empty($results[2][$resultKey]) ){
682
+ //Check to see if we have a second set of braces;
683
+ $attString = $results[2][$resultKey];
684
+ }
685
+ $attString = apply_filters('em_event_output_placeholder', $attString, $this, $result, $target);
686
+ $event_string = str_replace($result, $attString ,$event_string );
687
+ }
688
+
689
+ //Now do dependent objects
690
+ $event_string = $this->location->output($event_string, $target);
691
+ $event_string = $this->category->output($event_string, $target);
692
+ return apply_filters('em_event_output', $event_string, $this, $target);
693
+ }
694
+
695
+ /**********************************************************
696
+ * RECURRENCE METHODS
697
+ ***********************************************************/
698
+
699
+ /**
700
+ * Saves events and replaces old ones. Returns true if sucecssful or false if not.
701
+ * @return boolean
702
+ */
703
+ function save_events() {
704
+ if( $this->is_recurring() && $this->can_manage() ){
705
+ do_action('em_event_save_events_pre', $this); //actions/filters only run if event is recurring
706
+ global $wpdb;
707
+ $event_saves = array();
708
+ $matching_days = $this->get_recurrence_days(); //Get days where events recur
709
+ $this->delete_events(); //Delete old events beforehand
710
+ //Make template event (and we just change dates)
711
+ $event = $this->to_array();
712
+ unset($event['event_id']); //remove id and we have a event template to feed to wpdb insert
713
+ $event['event_attributes'] = serialize($event['event_attributes']);
714
+ foreach($event as $key => $value ){ //remove recurrence information
715
+ if( substr($key, 0, 10) == 'recurrence' ){
716
+ unset($event[$key]);
717
+ }
718
+ }
719
+ $event['recurrence_id'] = $this->id;
720
+ //Save event template with different dates
721
+ foreach( $matching_days as $day ) {
722
+ $event['event_start_date'] = date("Y-m-d", $day);
723
+ $event['event_end_date'] = $event['event_start_date'];
724
+ $event_saves[] = $wpdb->insert($wpdb->prefix.EM_EVENTS_TABLE, $event, $this->get_types($event));
725
+ //TODO should be EM_DEBUG, and do we really need it?
726
+ if( DEBUG ){ echo "Entering recurrence " . date("D d M Y", $day)."<br/>"; }
727
+ }
728
+ return apply_filters('em_event_save_events', !in_array(false, $event_saves), $this);
729
+ }
730
+ return apply_filters('em_event_save_events', false, $this);;
731
+ }
732
+
733
+ /**
734
+ * Removes all reoccurring events.
735
+ * @param $recurrence_id
736
+ * @return null
737
+ */
738
+ function delete_events(){
739
+ global $wpdb;
740
+ do_action('em_event_delete_events_pre', $this);
741
+ //So we don't do something we'll regret later, we could just supply the get directly into the delete, but this is safer
742
+ $result = false;
743
+ if( $this->can_manage(true) ){
744
+ $EM_Events = EM_Events::get( array('recurrence_id'=>$this->id) );
745
+ $event_ids = array();
746
+ foreach($EM_Events as $EM_Event){
747
+ if($EM_Event->recurrence_id == $this->id){
748
+ $event_ids[] = $EM_Event->id; //ONLY ADD if id's match - hard coded
749
+ }
750
+ }
751
+ $result = EM_Events::delete( $event_ids );
752
+ }
753
+ return apply_filters('delete_events', $result, $this);
754
+ }
755
+
756
+ /**
757
+ * Returns true if this event is a recurring event, meaning that it's not an individual event,
758
+ * but an event that defines many events that recur over a span of time.
759
+ * For checking if a specific event is part of a greater set of recurring events, use is_recurrence()
760
+ * @return boolean
761
+ */
762
+ function is_recurring(){
763
+ return ( $this->recurrence );
764
+ }
765
+ /**
766
+ * Will return true if this individual event is part of a set of events that recur
767
+ * For checking if this is the "master recurring event", see is_recurring()
768
+ * @return boolean
769
+ */
770
+ function is_recurrence(){
771
+ return ( $this->id > 0 && $this->recurrence_id > 0 );
772
+ }
773
+ /**
774
+ * Returns if this is an individual event and is not recurring or a recurrence
775
+ * @return boolean
776
+ */
777
+ function is_individual(){
778
+ return ( !$this->is_recurring() && !$this->is_recurrence() );
779
+ }
780
+
781
+ /**
782
+ * Can the user manage this event?
783
+ */
784
+ function can_manage( $error_msg = false ){
785
+ $can_manage = ( get_option('dbem_permissions_events') || $this->author == get_current_user_id() || empty($this->id) || em_verify_admin() );
786
+ if($error_msg && !$can_manage){
787
+ $this->errors[] = __('You do not have permission to manage this event.','dbem');
788
+ }
789
+ return apply_filters('em_event_can_manage', $can_manage, $this);
790
+ }
791
+
792
+ /**
793
+ * Returns the days that match the recurrance array passed (unix timestamps)
794
+ * @param array $recurrence
795
+ * @return array
796
+ */
797
+ function get_recurrence_days(){
798
+ if( $this->is_recurring() ){
799
+
800
+ $start_date = strtotime($this->start_date);
801
+ $end_date = strtotime($this->end_date);
802
+
803
+ $weekdays = explode(",", $this->byday); //what days of the week (or if monthly, one value at index 0)
804
+
805
+ $matching_days = array();
806
+ $aDay = 86400; // a day in seconds
807
+ $aWeek = $aDay * 7;
808
+
809
+ //TODO can this be optimized?
810
+ switch ( $this->freq ){
811
+ case 'daily':
812
+ //If daily, it's simple. Get start date, add interval timestamps to that and create matching day for each interval until end date.
813
+ $current_date = $start_date;
814
+ while( $current_date <= $end_date ){
815
+ $matching_days[] = $current_date;
816
+ $current_date = $current_date + ($aDay * $this->interval);
817
+ }
818
+ break;
819
+ case 'weekly':
820
+ //sort out week one, get starting days and then days that match time span of event (i.e. remove past events in week 1)
821
+ $start_of_week = get_option('start_of_week'); //Start of week depends on wordpress
822
+ //first, get the start of this week as timestamp
823
+ $event_start_day = date('w', $start_date);
824
+ $offset = 0;
825
+ if( $event_start_day > $start_of_week ){
826
+ $offset = $event_start_day - $start_of_week; //x days backwards
827
+ }elseif( $event_start_day < $start_of_week ){
828
+ $offset = $start_of_week;
829
+ }
830
+ $start_week_date = $start_date - ( ($event_start_day - $start_of_week) * $aDay );
831
+ //then get the timestamps of weekdays during this first week, regardless if within event range
832
+ $start_weekday_dates = array(); //Days in week 1 where there would events, regardless of event date range
833
+ for($i = 0; $i < 7; $i++){
834
+ $weekday_date = $start_week_date+($aDay*$i); //the date of the weekday we're currently checking
835
+ $weekday_day = date('w',$weekday_date); //the day of the week we're checking, taking into account wp start of week setting
836
+ if( in_array( $weekday_day, $weekdays) ){
837
+ $start_weekday_dates[] = $weekday_date; //it's in our starting week day, so add it
838
+ }
839
+ }
840
+ //for each day of eventful days in week 1, add 7 days * weekly intervals
841
+ foreach ($start_weekday_dates as $weekday_date){
842
+ //Loop weeks by interval until we reach or surpass end date
843
+ while($weekday_date <= $end_date){
844
+ if( $weekday_date >= $start_date && $weekday_date <= $end_date ){
845
+ $matching_days[] = $weekday_date;
846
+ }
847
+ $weekday_date = $weekday_date + ($aWeek * $this->interval);
848
+ }
849
+ }//done!
850
+ break;
851
+ case 'monthly':
852
+ //loop months starting this month by intervals
853
+ $current_arr = getdate($start_date);
854
+ $end_arr = getdate($end_date);
855
+ $end_month_date = strtotime( date('Y-m-t', $end_date) ); //End date on last day of month
856
+ $current_date = strtotime( date('Y-m-1', $start_date) ); //Start date on first day of month
857
+ while( $current_date <= $end_month_date ){
858
+ $last_day_of_month = date('t', $current_date);
859
+ //Now find which day we're talking about
860
+ $current_week_day = date('w',$current_date);
861
+ $matching_month_days = array();
862
+ //Loop through days of this years month and save matching days to temp array
863
+ for($day = 1; $day <= $last_day_of_month; $day++){
864
+ if($current_week_day == $this->byday){
865
+ $matching_month_days[] = $day;
866
+ }
867
+ $current_week_day = ($current_week_day < 6) ? $current_week_day+1 : 0;
868
+ }
869
+ //Now grab from the array the x day of the month
870
+ $matching_day = ($this->byweekno > 0) ? $matching_month_days[$this->byweekno-1] : array_pop($matching_month_days);
871
+ $matching_date = strtotime(date('Y-m',$current_date).'-'.$matching_day);
872
+ if($matching_date >= $start_date && $matching_date <= $end_date){
873
+ $matching_days[] = $matching_date;
874
+ }
875
+ //add the number of days in this month to make start of next month
876
+ $current_arr['mon'] += $this->interval;
877
+ if($current_arr['mon'] > 12){
878
+ //FIXME this won't work if interval is more than 12
879
+ $current_arr['mon'] = $current_arr['mon'] - 12;
880
+ $current_arr['year']++;
881
+ }
882
+ $current_date = strtotime("{$current_arr['year']}-{$current_arr['mon']}-1");
883
+ }
884
+ break;
885
+ }
886
+ sort($matching_days);
887
+ //TODO delete this after testing
888
+ /*Delete*/
889
+ $test_dates = array();
890
+ foreach($matching_days as $matching_day){
891
+ $test_dates[] = date('d/m/Y', $matching_day);
892
+ }
893
+ /*end delete*/
894
+ return $matching_days;
895
+ }
896
+ }
897
+
898
+ /**
899
+ * Returns a string representation of this recurrence. Will return false if not a recurrence
900
+ * @return string
901
+ */
902
+ function get_recurrence_description() {
903
+ //FIXME Recurrence description not working for recurrence
904
+ global $EM_Recurrences;
905
+ if( $this->is_individual() ) return false;
906
+ $recurrence = $EM_Recurrences[$this->recurrence_id]->to_array();
907
+ $weekdays_name = array(__('Sunday'),__('Monday'),__('Tuesday'),__('Wednesday'),__('Thursday'),__('Friday'),__('Saturday'));
908
+ $monthweek_name = array('1' => __('the first %s of the month', 'dbem'),'2' => __('the second %s of the month', 'dbem'), '3' => __('the third %s of the month', 'dbem'), '4' => __('the fourth %s of the month', 'dbem'), '-1' => __('the last %s of the month', 'dbem'));
909
+ $output = sprintf (__('From %1$s to %2$s', 'dbem'), $recurrence['event_start_date'], $recurrence['event_end_date']).", ";
910
+ if ($recurrence['recurrence_freq'] == 'daily') {
911
+ $freq_desc =__('everyday', 'dbem');
912
+ if ($recurrence['recurrence_interval'] > 1 ) {
913
+ $freq_desc = sprintf (__("every %s days", 'dbem'), $recurrence['recurrence_interval']);
914
+ }
915
+ }
916
+ if ($recurrence['recurrence_freq'] == 'weekly') {
917
+ $weekday_array = explode(",", $recurrence['recurrence_byday']);
918
+ $natural_days = array();
919
+ foreach($weekday_array as $day){
920
+ array_push($natural_days, $weekdays_name[$day]);
921
+ }
922
+ $output .= implode(" and ", $natural_days);
923
+ $freq_desc = ", " . __("every week", 'dbem');
924
+ if ($recurrence['recurrence_interval'] > 1 ) {
925
+ $freq_desc = ", ".sprintf (__("every %s weeks", 'dbem'), $recurrence['recurrence_interval']);
926
+ }
927
+
928
+ }
929
+ if ($recurrence['recurrence_freq'] == 'monthly') {
930
+ $weekday_array = explode(",", $recurrence['recurrence_byday']);
931
+ $natural_days = array();
932
+ foreach($weekday_array as $day){
933
+ array_push($natural_days, $weekdays_name[$day]);
934
+ }
935
+ $freq_desc = sprintf (($monthweek_name[$recurrence['recurrence_byweekno']]), implode(" and ", $natural_days));
936
+ if ($recurrence['recurrence_interval'] > 1 ) {
937
+ $freq_desc .= ", ".sprintf (__("every %s months",'dbem'), $recurrence['recurrence_interval']);
938
+ }
939
+
940
+ }
941
+ $output .= $freq_desc;
942
+ return $output;
943
+ }
944
+
945
+ /**********************************************************
946
+ * UTILITIES
947
+ ***********************************************************/
948
+
949
+ /**
950
+ * Returns this object in the form of an array, useful for saving directly into the wp_dbem_events table.
951
+ * @param boolean $location
952
+ * @param boolean $for_database
953
+ * @return array
954
+ */
955
+ function to_array($location = false, $for_database = false){
956
+ $event = array();
957
+ //Core Event Data
958
+ foreach ( $this->fields as $key => $val ) {
959
+ //TODO does it matter if it's for db or not... shouldn't it just not include blanks?
960
+ if( !$for_database || $for_database && $this->$val['name'] ){
961
+ $event[$key] = $this->$val['name'];
962
+ }
963
+ }
964
+ //Location Data
965
+ if($location && is_object($this->location)){
966
+ $location = $this->location->to_array();
967
+ $event = array_merge($event, $location);
968
+ }
969
+ return $event;
970
+ }
971
+ }
972
+
973
+ //TODO placeholder targets filtering could be streamlined better
974
+ /**
975
+ * This is a temporary filter function which mimicks the old filters in the old 2.x placeholders function
976
+ * @param string $result
977
+ * @param EM_Event $event
978
+ * @param string $placeholder
979
+ * @param string $target
980
+ * @return mixed
981
+ */
982
+ function em_event_output_placeholder($result,$event,$placeholder,$target='html'){
983
+ if( ($placeholder == "#_EXCERPT" || $placeholder == "#_LOCATIONEXCERPT") && $target == 'html' ){
984
+ $result = apply_filters('dbem_notes_excerpt', $result);
985
+ }elseif( $placeholder == '#_CONTACTEMAIL' && $target == 'html' ){
986
+ $result = em_ascii_encode($event->contact->user_email);
987
+ }elseif( $placeholder == "#_NOTES" || $placeholder == "#_EXCERPT" || $placeholder == "#_LOCATIONEXCERPT" ){
988
+ if($target == 'html'){
989
+ $result = apply_filters('dbem_notes', $result);
990
+ }elseif($target == 'map'){
991
+ $result = apply_filters('dbem_notes_map', $result);
992
+ }else{
993
+ $result = apply_filters('dbem_notes_rss', $result);
994
+ $result = apply_filters('the_content_rss', $result);
995
+ }
996
+ }elseif( in_array($placeholder, array("#_NAME",'#_ADDRESS','#_LOCATION','#_TOWN')) ){
997
+ if ($target == "html"){
998
+ $result = apply_filters('dbem_general', $result);
999
+ }else{
1000
+ $result = apply_filters('dbem_general_rss', $result);
1001
+ }
1002
+ }
1003
+ return $result;
1004
+ }
1005
+ add_filter('em_event_output_placeholder','em_event_output_placeholder',1,4);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1006
  ?>
classes/em-events.php CHANGED
@@ -1,301 +1,254 @@
1
- <?php
2
- //TODO EM_Events is currently static, better we make this non-static so we can loop sets of events, and standardize with other objects.
3
- /**
4
- * Use this class to query and manipulate sets of events. If dealing with more than one event, you probably want to use this class in some way.
5
- *
6
- */
7
- class EM_Events extends EM_Object implements Iterator {
8
- /**
9
- * Array of EM_Event objects
10
- * @var array EM_Event
11
- */
12
- var $events = array();
13
- /**
14
- * Returns an array of EM_Events that match the given specs in the argument, or returns a list of future evetnts in future
15
- * (see EM_Events::get_default_search() ) for explanation of possible search array values. You can also supply a numeric array
16
- * containing the ids of the events you'd like to obtain
17
- *
18
- * @param array $args
19
- * @return EM_Event array()
20
- */
21
- function get( $args = array(), $count=false ) {
22
- global $wpdb;
23
- $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
24
- $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
25
- $categories_table = $wpdb->prefix . EM_CATEGORIES_TABLE;
26
-
27
- //Quick version, we can accept an array of IDs, which is easy to retrieve
28
- if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
29
- //We can just get all the events here and return them
30
- $sql = "
31
- SELECT * FROM $events_table
32
- LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
33
- LEFT JOIN $categories_table ON {$categories_table}.category_id={$events_table}.event_category_id
34
- WHERE event_id=".implode(" OR event_id=", $args)."
35
- ";
36
- $results = $wpdb->get_results(apply_filters('em_events_get_sql',$sql),ARRAY_A);
37
- $events = array();
38
- foreach($results as $result){
39
- $events[$result['event_id']] = new EM_Event($result);
40
- }
41
- return $events; //We return all the events matched as an EM_Event array.
42
- }
43
-
44
- //We assume it's either an empty array or array of search arguments to merge with defaults
45
- $args = self::get_default_search($args);
46
- $limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
47
- $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
48
-
49
- //Get the default conditions
50
- $conditions = self::build_sql_conditions($args);
51
- //Put it all together
52
- $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
53
-
54
- //Get ordering instructions
55
- $EM_Event = new EM_Event();
56
- $accepted_fields = $EM_Event->get_fields(true);
57
- $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order'));
58
- //Now, build orderby sql
59
- $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
60
-
61
- //Create the SQL statement and execute
62
- $selectors = ( $count ) ? 'COUNT(*)':'*';
63
- $sql = "
64
- SELECT $selectors FROM $events_table
65
- LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
66
- LEFT JOIN $categories_table ON {$categories_table}.category_id={$events_table}.event_category_id
67
- $where
68
- $orderby_sql
69
- $limit $offset
70
- ";
71
- //If we're only counting results, return the number of results
72
- if( $count ){
73
- return $wpdb->get_var($sql);
74
- }
75
- $results = $wpdb->get_results( apply_filters('em_events_get_sql',$sql, $args), ARRAY_A);
76
-
77
- //If we want results directly in an array, why not have a shortcut here?
78
- if( $args['array'] == true ){
79
- return $results;
80
- }
81
-
82
- //Make returned results EM_Event objects
83
- $results = (is_array($results)) ? $results:array();
84
- $events = array();
85
- foreach ( $results as $event ){
86
- $events[] = new EM_Event($event);
87
- }
88
-
89
- return apply_filters('em_events_get', $events);
90
- }
91
-
92
- /**
93
- * Returns the number of events on a given date
94
- * @param $date
95
- * @return int
96
- */
97
- function count_date($date){
98
- global $wpdb;
99
- $table_name = $wpdb->prefix . EM_EVENTS_TABLE;
100
- $sql = "SELECT COUNT(*) FROM $table_name WHERE (event_start_date like '$date') OR (event_start_date <= '$date' AND event_end_date >= '$date');";
101
- return apply_filters('em_events_count_date', $wpdb->get_var($sql));
102
- }
103
-
104
- function count( $args = array() ){
105
- return apply_filters('em_events_count', self::get($args, true), $args);
106
- }
107
-
108
- /**
109
- * Will delete given an array of event_ids or EM_Event objects
110
- * @param unknown_type $id_array
111
- */
112
- function delete( $array ){
113
- //TODO add better cap checks in bulk actions
114
- global $wpdb;
115
- //Detect array type and generate SQL for event IDs
116
- $event_ids = array();
117
- if( @get_class(current($array)) == 'EM_Event' ){
118
- foreach($array as $EM_Event){
119
- $event_ids[] = $EM_Event->id;
120
- }
121
- }else{
122
- $event_ids = $array;
123
- }
124
- if(self::array_is_numeric($event_ids)){
125
- //First we have to check that they're all deletable by this user.
126
- if ( self::can_manage($event_ids) ) {
127
- apply_filters('em_events_delete_pre', $event_ids);
128
- $condition = implode(" OR event_id=", $event_ids);
129
- //Delete all the bookings
130
- $result_bookings = $wpdb->query("DELETE FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." WHERE event_id=$condition;");
131
- //Now delete the events
132
- $result = $wpdb->query ( "DELETE FROM ". $wpdb->prefix . EM_EVENTS_TABLE ." WHERE event_id=$condition;" );
133
- return apply_filters('em_events_delete', true, $event_ids);
134
- }else{
135
- return apply_filters('em_events_delete', true, $event_ids);
136
- }
137
- }
138
- //TODO add better error feedback on events delete fails
139
- return apply_filters('em_events_delete', true, $event_ids);
140
- }
141
-
142
-
143
- /**
144
- * Output a set of matched of events. You can pass on an array of EM_Events as well, in this event you can pass args in second param.
145
- * Note that you can pass a 'pagination' boolean attribute to enable pagination, default is enabled (true).
146
- * @param array $args
147
- * @param array $secondary_args
148
- * @return string
149
- */
150
- function output( $args ){
151
- global $EM_Event;
152
- $EM_Event_old = $EM_Event; //When looping, we can replace EM_Event global with the current event in the loop
153
- //Can be either an array for the get search or an array of EM_Event objects
154
- if( is_object(current($args)) && get_class((current($args))) == 'EM_Event' ){
155
- $func_args = func_get_args();
156
- $events = $func_args[0];
157
- $args = apply_filters('em_events_output_args', self::get_default_search($func_args[1]), $events);
158
- $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
159
- $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
160
- $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
161
- }else{
162
- //Firstly, let's check for a limit/offset here, because if there is we need to remove it and manually do this
163
- $args = apply_filters('em_events_output_args', self::get_default_search($args) );
164
- $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
165
- $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
166
- $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
167
- $args['limit'] = false;
168
- $args['offset'] = false;
169
- $args['page'] = false;
170
- $events = self::get( $args );
171
- }
172
- //What format shall we output this to, or use default
173
- $format = ( empty($args['format']) ) ? get_option( 'dbem_event_list_item_format' ) : $args['format'] ;
174
-
175
- $output = "";
176
- $events_count = count($events);
177
- $events = apply_filters('em_events_output_events', $events);
178
-
179
- if ( $events_count > 0 ) {
180
- $event_count = 0;
181
- $events_shown = 0;
182
- foreach ( $events as $EM_Event ) {
183
- if( ($events_shown < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ){
184
- $output .= $EM_Event->output($format);
185
- $events_shown++;
186
- }
187
- $event_count++;
188
- }
189
- //Add headers and footers to output
190
- if( $format == get_option ( 'dbem_event_list_item_format' ) ){
191
- $format_header = ( get_option( 'dbem_event_list_item_format_header') == '' ) ? '':get_option ( 'dbem_event_list_item_format_header' );
192
- $format_footer = ( get_option ( 'dbem_event_list_item_format_footer' ) == '' ) ? '':get_option ( 'dbem_event_list_item_format_footer' );
193
- }else{
194
- $format_header = ( !empty($args['format_header']) ) ? $args['format_header']:'';
195
- $format_footer = ( !empty($args['format_footer']) ) ? $args['format_footer']:'';
196
- }
197
- $output = $format_header . $output . $format_footer;
198
- //Pagination (if needed/requested)
199
- if( !empty($args['pagination']) && !empty($limit) && $events_count > $limit ){
200
- //Show the pagination links (unless there's less than $limit events)
201
- $page_link_template = preg_replace('/(&|\?)page=\d+/i','',$_SERVER['REQUEST_URI']);
202
- $page_link_template = em_add_get_params($page_link_template, array('page'=>'%PAGE%'));
203
- $output .= apply_filters('em_events_output_pagination', em_paginate( $page_link_template, $events_count, $limit, $page), $page_link_template, $events_count, $limit, $page);
204
- }
205
- } else {
206
- $output = get_option ( 'dbem_no_events_message' );
207
- }
208
- //TODO check if reference is ok when restoring object, due to changes in php5 v 4
209
- $EM_Event = $EM_Event_old;
210
- $output = apply_filters('em_events_output', $output, $events, $args);
211
- return $output;
212
- }
213
-
214
- function can_manage($event_ids){
215
- global $wpdb;
216
- if( current_user_can('edit_others_events') ){
217
- return apply_filters('em_events_can_manage', true, $event_ids);
218
- }
219
- if( EM_Object::array_is_numeric($event_ids) ){
220
- $condition = implode(" OR event_id=", $event_ids);
221
- //Delete all the bookings
222
- $results = $wpdb->query("SELECT event_owner FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." WHERE author_id != '". get_current_user_id() ."' event_id=$condition;");
223
- return apply_filters('em_events_can_manage', (count($results) > 0), $event_ids);
224
- }
225
- return apply_filters('em_events_can_manage', false, $event_ids);
226
- }
227
-
228
- /* Overrides EM_Object method to apply a filter to result
229
- * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
230
- */
231
- function build_sql_conditions( $args = array() ){
232
- $conditions = parent::build_sql_conditions($args);
233
- if( !empty($args['search']) ){
234
- $like_search = array('event_name','event_notes');
235
- $conditions['search'] = "(".implode(" LIKE '%{$args['search']}%' OR ", $like_search). " LIKE '%{$args['search']}%')";
236
- }
237
- if( array_key_exists('status',$args) && is_numeric($args['status']) ){
238
- $conditions['status'] = "(`event_status`={$args['status']})";
239
- }
240
- return apply_filters( 'em_events_build_sql_conditions', $conditions, $args );
241
- }
242
-
243
- /* Overrides EM_Object method to apply a filter to result
244
- * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
245
- */
246
- function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
247
- return apply_filters( 'em_events_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')), $args, $accepted_fields, $default_order );
248
- }
249
-
250
- /*
251
- * Adds custom Events search defaults
252
- * @param array $array
253
- * @return array
254
- * @uses EM_Object#get_default_search()
255
- */
256
- function get_default_search( $array = array() ){
257
- $defaults = array(
258
- 'orderby' => get_option('dbem_events_default_orderby'),
259
- 'order' => get_option('dbem_events_default_order'),
260
- 'rsvp' => false, //if set to true, only events with bookings enabled are returned
261
- 'status' => 1, //approved events only
262
- 'format_header' => '', //events can have custom html above the list
263
- 'format_footer' => '', //events can have custom html below the list
264
- );
265
- if( is_admin() ){
266
- //figure out default owning permissions
267
- $defaults['owner'] = !current_user_can('edit_others_events') ? get_current_user_id() : false;
268
- if( !array_key_exists('status', $array) && current_user_can('edit_others_events') ){
269
- $defaults['status'] = false; //by default, admins see pending and live events
270
- }
271
- }
272
- return apply_filters('em_events_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
273
- }
274
-
275
- //TODO Implement object and interators for handling groups of events.
276
- public function rewind(){
277
- reset($this->events);
278
- }
279
-
280
- public function current(){
281
- $var = current($this->events);
282
- return $var;
283
- }
284
-
285
- public function key(){
286
- $var = key($this->events);
287
- return $var;
288
- }
289
-
290
- public function next(){
291
- $var = next($this->events);
292
- return $var;
293
- }
294
-
295
- public function valid(){
296
- $key = key($this->events);
297
- $var = ($key !== NULL && $key !== FALSE);
298
- return $var;
299
- }
300
- }
301
  ?>
1
+ <?php
2
+ /**
3
+ * Use this class to query and manipulate sets of events. If dealing with more than one event, you probably want to use this class in some way.
4
+ *
5
+ */
6
+ class EM_Events extends EM_Object {
7
+
8
+ /**
9
+ * Returns an array of EM_Events that match the given specs in the argument, or returns a list of future evetnts in future
10
+ * (see EM_Events::get_default_search() ) for explanation of possible search array values. You can also supply a numeric array
11
+ * containing the ids of the events you'd like to obtain
12
+ *
13
+ * @param array $args
14
+ * @return EM_Event array()
15
+ */
16
+ function get( $args = array() ) {
17
+ global $wpdb;
18
+ $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
19
+ $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
20
+ $categories_table = $wpdb->prefix . EM_CATEGORIES_TABLE;
21
+
22
+ //Quick version, we can accept an array of IDs, which is easy to retrieve
23
+ if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
24
+ //We can just get all the events here and return them
25
+ $sql = "
26
+ SELECT * FROM $events_table
27
+ LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
28
+ LEFT JOIN $categories_table ON {$categories_table}.category_id={$events_table}.event_category_id
29
+ WHERE event_id=".implode(" OR event_id=", $args)."
30
+ ";
31
+ $results = $wpdb->get_results(apply_filters('em_events_get_sql',$sql),ARRAY_A);
32
+ $events = array();
33
+ foreach($results as $result){
34
+ $events[$result['event_id']] = new EM_Event($result);
35
+ }
36
+ return $events; //We return all the events matched as an EM_Event array.
37
+ }
38
+
39
+ //We assume it's either an empty array or array of search arguments to merge with defaults
40
+ $args = self::get_default_search($args);
41
+ $limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
42
+ $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
43
+
44
+ //Get the default conditions
45
+ $conditions = self::build_sql_conditions($args);
46
+ //Put it all together
47
+ $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
48
+
49
+ //Get ordering instructions
50
+ $EM_Event = new EM_Event();
51
+ $accepted_fields = $EM_Event->get_fields(true);
52
+ $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order'));
53
+ //Now, build orderby sql
54
+ $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
55
+
56
+ //Create the SQL statement and execute
57
+ $sql = "
58
+ SELECT * FROM $events_table
59
+ LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
60
+ LEFT JOIN $categories_table ON {$categories_table}.category_id={$events_table}.event_category_id
61
+ $where
62
+ $orderby_sql
63
+ $limit $offset
64
+ ";
65
+
66
+ $results = $wpdb->get_results( apply_filters('em_events_get_sql',$sql, $args), ARRAY_A);
67
+
68
+ //If we want results directly in an array, why not have a shortcut here?
69
+ if( $args['array'] == true ){
70
+ return $results;
71
+ }
72
+
73
+ //Make returned results EM_Event objects
74
+ $results = (is_array($results)) ? $results:array();
75
+ $events = array();
76
+ foreach ( $results as $event ){
77
+ $events[] = new EM_Event($event);
78
+ }
79
+
80
+ return apply_filters('em_events_get', $events);
81
+ }
82
+
83
+ /**
84
+ * Returns the number of events on a given date
85
+ * @param $date
86
+ * @return int
87
+ */
88
+ function count_date($date){
89
+ global $wpdb;
90
+ $table_name = $wpdb->prefix . EM_EVENTS_TABLE;
91
+ $sql = "SELECT COUNT(*) FROM $table_name WHERE (event_start_date like '$date') OR (event_start_date <= '$date' AND event_end_date >= '$date');";
92
+ return apply_filters('em_events_count_date', $wpdb->get_var($sql));
93
+ }
94
+
95
+ /**
96
+ * Will delete given an array of event_ids or EM_Event objects
97
+ * @param unknown_type $id_array
98
+ */
99
+ function delete( $array ){
100
+ global $wpdb;
101
+ //Detect array type and generate SQL for event IDs
102
+ $event_ids = array();
103
+ if( @get_class(current($array)) == 'EM_Event' ){
104
+ foreach($array as $EM_Event){
105
+ $event_ids[] = $EM_Event->id;
106
+ }
107
+ }else{
108
+ $event_ids = $array;
109
+ }
110
+ if(self::array_is_numeric($event_ids)){
111
+ //First we have to check that they're all deletable by this user.
112
+ if ( self::can_manage($event_ids) ) {
113
+ apply_filters('em_events_delete_pre', $event_ids);
114
+ $condition = implode(" OR event_id=", $event_ids);
115
+ //Delete all the bookings
116
+ $result_bookings = $wpdb->query("DELETE FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." WHERE event_id=$condition;");
117
+ //Now delete the events
118
+ $result = $wpdb->query ( "DELETE FROM ". $wpdb->prefix . EM_EVENTS_TABLE ." WHERE event_id=$condition;" );
119
+ return apply_filters('em_events_delete', true, $event_ids);
120
+ }else{
121
+ return apply_filters('em_events_delete', true, $event_ids);
122
+ }
123
+ }
124
+ //TODO add better error feedback on events delete fails
125
+ return apply_filters('em_events_delete', true, $event_ids);
126
+ }
127
+
128
+
129
+ /**
130
+ * Output a set of matched of events. You can pass on an array of EM_Events as well, in this event you can pass args in second param.
131
+ * Note that you can pass a 'pagination' boolean attribute to enable pagination, default is enabled (true).
132
+ * @param array $args
133
+ * @param array $secondary_args
134
+ * @return string
135
+ */
136
+ function output( $args ){
137
+ global $EM_Event;
138
+ $EM_Event_old = $EM_Event; //When looping, we can replace EM_Event global with the current event in the loop
139
+ //Can be either an array for the get search or an array of EM_Event objects
140
+ if( is_object(current($args)) && get_class((current($args))) == 'EM_Event' ){
141
+ $func_args = func_get_args();
142
+ $events = $func_args[0];
143
+ $args = apply_filters('em_events_output_args', self::get_default_search($func_args[1]), $events);
144
+ $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
145
+ $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
146
+ $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
147
+ }else{
148
+ //Firstly, let's check for a limit/offset here, because if there is we need to remove it and manually do this
149
+ $args = apply_filters('em_events_output_args', self::get_default_search($args) );
150
+ $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
151
+ $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
152
+ $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
153
+ $args['limit'] = false;
154
+ $args['offset'] = false;
155
+ $args['page'] = false;
156
+ $events = self::get( $args );
157
+ }
158
+ //What format shall we output this to, or use default
159
+ $format = ( empty($args['format']) ) ? get_option( 'dbem_event_list_item_format' ) : $args['format'] ;
160
+
161
+ $output = "";
162
+ $events_count = count($events);
163
+ $events = apply_filters('em_events_output_events', $events);
164
+
165
+ if ( $events_count > 0 ) {
166
+ $event_count = 0;
167
+ $events_shown = 0;
168
+ foreach ( $events as $EM_Event ) {
169
+ if( ($events_shown < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ){
170
+ $output .= $EM_Event->output($format);
171
+ $events_shown++;
172
+ }
173
+ $event_count++;
174
+ }
175
+ //Add headers and footers to output
176
+ if( $format == get_option ( 'dbem_event_list_item_format' ) ){
177
+ $single_event_format_header = get_option ( 'dbem_event_list_item_format_header' );
178
+ $single_event_format_header = ( $single_event_format_header != '' ) ? $single_event_format_header : "<ul class='dbem_events_list'>";
179
+ $single_event_format_footer = get_option ( 'dbem_event_list_item_format_footer' );
180
+ $single_event_format_footer = ( $single_event_format_footer != '' ) ? $single_event_format_footer : "</ul>";
181
+ $output = $single_event_format_header . $output . $single_event_format_footer;
182
+ }
183
+ //Pagination (if needed/requested)
184
+ if( !empty($args['pagination']) && !empty($limit) && $events_count > $limit ){
185
+ //Show the pagination links (unless there's less than $limit events)
186
+ $page_link_template = preg_replace('/(&|\?)page=\d+/i','',$_SERVER['REQUEST_URI']);
187
+ $page_link_template = em_add_get_params($page_link_template, array('page'=>'%PAGE%'));
188
+ $output .= apply_filters('em_events_output_pagination', em_paginate( $page_link_template, $events_count, $limit, $page), $page_link_template, $events_count, $limit, $page);
189
+ }
190
+ } else {
191
+ $output = get_option ( 'dbem_no_events_message' );
192
+ }
193
+ //TODO check if reference is ok when restoring object, due to changes in php5 v 4
194
+ $EM_Event = $EM_Event_old;
195
+ $output = apply_filters('em_events_output', $output, $events, $args);
196
+ return $output;
197
+ }
198
+
199
+ function can_manage($event_ids){
200
+ global $wpdb;
201
+ if( em_verify_admin() ){
202
+ return apply_filters('em_events_can_manage', true, $event_ids);
203
+ }
204
+ if( EM_Object::array_is_numeric($event_ids) ){
205
+ $condition = implode(" OR event_id=", $event_ids);
206
+ //Delete all the bookings
207
+ $results = $wpdb->query("SELECT event_author FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." WHERE author_id != '". get_current_user_id() ."' event_id=$condition;");
208
+ return apply_filters('em_events_can_manage', (count($results) > 0), $event_ids);
209
+ }
210
+ return apply_filters('em_events_can_manage', false, $event_ids);
211
+ }
212
+
213
+ /* Overrides EM_Object method to apply a filter to result
214
+ * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
215
+ */
216
+ function build_sql_conditions( $args = array() ){
217
+ return apply_filters( 'em_events_build_sql_conditions', parent::build_sql_conditions($args), $args );
218
+ }
219
+
220
+ /* Overrides EM_Object method to apply a filter to result
221
+ * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
222
+ */
223
+ function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
224
+ return apply_filters( 'em_events_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')), $args, $accepted_fields, $default_order );
225
+ }
226
+
227
+ /*
228
+ * Adds custom Events search defaults
229
+ * @param array $array
230
+ * @return array
231
+ * @uses EM_Object#get_default_search()
232
+ */
233
+ function get_default_search( $array = array() ){
234
+ $defaults = array(
235
+ 'orderby' => get_option('dbem_events_default_orderby'),
236
+ 'order' => get_option('dbem_events_default_order'),
237
+ 'rsvp' => false //if set to true, only events with bookings enabled are returned
238
+ );
239
+ if( is_admin() ){
240
+ //figure out default owning permissions
241
+ switch( get_option('dbem_permissions_events') ){
242
+ case 0:
243
+ $defaults['owner'] = get_current_user_id();
244
+ break;
245
+ case 1:
246
+ $defaults['owner'] = false;
247
+ break;
248
+ }
249
+ $defaults['owner'] = ( em_verify_admin() ) ? false:$defaults['owner'];
250
+ }
251
+ return apply_filters('em_events_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
252
+ }
253
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  ?>
classes/em-location.php CHANGED
@@ -1,388 +1,307 @@
1
- <?php
2
- /**
3
- * Object that holds location info and related functions
4
- * @author marcus
5
- */
6
- class EM_Location extends EM_Object {
7
- //DB Fields
8
- var $id = '';
9
- var $slug = '';
10
- var $name = '';
11
- var $address = '';
12
- var $town = '';
13
- var $state = '';
14
- var $postcode = '';
15
- var $country = '';
16
- var $latitude = '';
17
- var $longitude = '';
18
- var $description = '';
19
- var $image_url = '';
20
- var $owner = '';
21
- //Other Vars
22
- var $fields = array(
23
- 'location_id' => array('name'=>'id','type'=>'%d'),
24
- 'location_slug' => array('name'=>'slug','type'=>'%s'),
25
- 'location_name' => array('name'=>'name','type'=>'%s'),
26
- 'location_address' => array('name'=>'address','type'=>'%s'),
27
- 'location_town' => array('name'=>'town','type'=>'%s'),
28
- 'location_state' => array('name'=>'state','type'=>'%s'),
29
- 'location_postcode' => array('name'=>'postcode','type'=>'%s'),
30
- 'location_country' => array('name'=>'country','type'=>'%s'),
31
- 'location_latitude' => array('name'=>'latitude','type'=>'%f'),
32
- 'location_longitude' => array('name'=>'longitude','type'=>'%f'),
33
- 'location_description' => array('name'=>'description','type'=>'%s'),
34
- 'location_owner' => array('name'=>'owner','type'=>'%d')
35
- );
36
- var $required_fields = array();
37
- var $feedback_message = "";
38
- var $mime_types = array(1 => 'gif', 2 => 'jpg', 3 => 'png');
39
- var $errors = array();
40
-
41
- /**
42
- * Gets data from POST (default), supplied array, or from the database if an ID is supplied
43
- * @param $location_data
44
- * @return null
45
- */
46
- function EM_Location( $location_data = 0 ) {
47
- //Initialize
48
- $this->required_fields = array("name" => __('The location name', 'dbem'), "address" => __('The location address', 'dbem'), "town" => __('The location town', 'dbem'), "country" => __('The country', 'dbem'),);
49
- if( !empty($location_data) ){
50
- //Load location data
51
- if( is_array($location_data) && isset($location_data['location_name']) ){
52
- $location = $location_data;
53
- }elseif( !empty($location_data) ){
54
- //Retreiving from the database
55
- global $wpdb;
56
- if( is_numeric($location_data) ){
57
- $sql = "SELECT * FROM ". $wpdb->prefix.EM_LOCATIONS_TABLE ." WHERE location_id ='{$location_data}'";
58
- $location = $wpdb->get_row($sql, ARRAY_A);
59
- }else{
60
- $sql = "SELECT * FROM ". $wpdb->prefix.EM_LOCATIONS_TABLE ." WHERE location_slug ='{$location_data}'";
61
- $location = $wpdb->get_row($sql, ARRAY_A);
62
- }
63
- }
64
- //If gmap is turned off, values may not be returned and set, so we set it here
65
- if(empty($location['location_latitude'])) {
66
- $location['location_latitude'] = 0;
67
- $location['location_longitude'] = 0;
68
- }
69
- //Save into the object
70
- $this->to_object($location, true);
71
- $this->get_image_url();
72
- }
73
- do_action('em_location', $this, $location_data);
74
- }
75
-
76
- function get_post(){
77
- //We are getting the values via POST or GET
78
- do_action('em_location_get_post_pre', $this);
79
- $location = array();
80
- $location['location_id'] = ( !empty($_POST['location_id']) ) ? $_POST['location_id']:'';
81
- $location['location_name'] = ( !empty($_POST['location_name']) ) ? stripslashes($_POST['location_name']):'';
82
- $location['location_address'] = ( !empty($_POST['location_address']) ) ? stripslashes($_POST['location_address']):'';
83
- $location['location_town'] = ( !empty($_POST['location_town']) ) ? stripslashes($_POST['location_town']):'';
84
- $location['location_state'] = ( !empty($_POST['location_state']) ) ? stripslashes($_POST['location_state']):'';
85
- $location['location_postcode'] = ( !empty($_POST['location_postcode']) ) ? stripslashes($_POST['location_postcode']):'';
86
- $location['location_country'] = ( !empty($_POST['location_country']) ) ? stripslashes($_POST['location_country']):'';
87
- $location['location_latitude'] = ( !empty($_POST['location_latitude']) ) ? $_POST['location_latitude']:'';
88
- $location['location_longitude'] = ( !empty($_POST['location_longitude']) ) ? $_POST['location_longitude']:'';
89
- $location['location_description'] = ( !empty($_POST['content']) ) ? stripslashes($_POST['content']):'';
90
- $this->to_object( apply_filters('em_location_get_post', $location, $this) );
91
- }
92
-
93
- function save(){
94
- global $wpdb, $current_user;
95
- if( $this->validate() ){
96
- if( current_user_can('edit_locations') ){
97
- get_currentuserinfo();
98
- do_action('em_location_save_pre', $this);
99
- $table = $wpdb->prefix.EM_LOCATIONS_TABLE;
100
- $this->slug = $this->sanitize_title();
101
- $data = $this->to_array();
102
- unset($data['location_id']);
103
- unset($data['location_image_url']);
104
- if($this->id != ''){
105
- $where = array( 'location_id' => $this->id );
106
- $result = $wpdb->update($table, $data, $where, $this->get_types($data));
107
- if( $result ){
108
- $this->feedback_message = sprintf(__('%s successfully updated.', 'dbem'), __('Location','dbem'));
109
- }
110
- }else{
111
- $this->owner = $current_user->ID; //Record creator of event
112
- $data['location_owner'] = $this->owner;
113
- $result = $wpdb->insert($table, $data, $this->get_types($data));
114
- $this->id = $wpdb->insert_id;
115
- if( $result ){
116
- $this->feedback_message = sprintf(__('%s successfully added.', 'dbem'), __('Location','dbem'));
117
- }
118
- }
119
- $image_upload = $this->image_upload();
120
- return apply_filters('em_location_save', ( $this->id > 0 && $image_upload ), $this, $image_upload);
121
- }else{
122
- $this->add_error( sprintf(__('You do not have permission to create/edit %s.','dbem'), __('locations','dbem')) );
123
- }
124
- }
125
- return apply_filters('em_location_save', false, $this, false);
126
- }
127
-
128
- /**
129
- * Takes the title and gives either a unique slug or returns the currently used slug if this record already has it.
130
- * @param unknown_type $title
131
- */
132
- function sanitize_title($iteration = 1){
133
- global $wpdb;
134
- //Generate the slug. If this is a new event, create the slug automatically, if not, verify it is still unique and if not rewrite
135
- if( empty($this->slug) ){
136
- $this->slug = sanitize_title($this->name);
137
- }
138
- $slug = $this->slug;
139
- $slug_matches = $wpdb->get_results('SELECT location_id FROM '.$wpdb->prefix.EM_LOCATIONS_TABLE." WHERE location_slug='{$slug}'", ARRAY_A);
140
- if( count($slug_matches) > 0 ){ //we will check that the slug is unique
141
- if( $slug_matches[0]['location_id'] != $this->id || count($slug_matches) > 1 ){
142
- //we have a conflict, so try another alternative
143
- $this->slug = preg_replace('/\-[0-9]+$/', '', $slug).'-'.($iteration+1);
144
- $this->sanitize_title($iteration+1);
145
- }
146
- }
147
- return apply_filters('em_location_sanitize_title', $this->slug, $this);
148
- }
149
-
150
- function delete(){
151
- global $wpdb;
152
- if( current_user_can('delete_locations') ){
153
- do_action('em_location_delete_pre', $this);
154
- $table_name = $wpdb->prefix.EM_LOCATIONS_TABLE;
155
- $sql = "DELETE FROM $table_name WHERE location_id = '{$this->id}';";
156
- $result = $wpdb->query($sql);
157
- $result = $this->image_delete() && $result;
158
- if( $result ){
159
- $this->feedback_message = sprintf(__('%s successfully deleted.', 'dbem'), __('Location','dbem')) ;
160
- }else{
161
- $this->add_error( sprintf(__('%s could not be deleted.', 'dbem'), __('Location','dbem')) );
162
- }
163
- }else{
164
- $this->add_error( sprintf(__('You do not have permission to delete %s.','dbem'), __('locations','dbem')) );
165
- $result = false;
166
- }
167
- return apply_filters('em_location_delete', $result, $this);
168
- }
169
-
170
- function get_image_url(){
171
- if($this->image_url == ''){
172
- foreach($this->mime_types as $type) {
173
- $file_path = "/".EM_IMAGE_UPLOAD_DIR."/location-{$this->id}.$type";
174
- if( file_exists( ABSPATH . $file_path) ) {
175
- $result = get_bloginfo('wpurl').$file_path;
176
- $this->image_url = $result;
177
- }
178
- }
179
- }
180
- return apply_filters('em_location_get_image_url', $this->image_url, $this);
181
- }
182
-
183
- function image_delete() {
184
- if( $this->image_url == '' ){
185
- $result = true;
186
- }else{
187
- $file_name= ABSPATH.EM_IMAGE_UPLOAD_DIR."/location-".$this->id;
188
- $result = false;
189
- foreach($this->mime_types as $type) {
190
- if (file_exists($file_name.".".$type))
191
- $result = unlink($file_name.".".$type);
192
- }
193
- }
194
- return apply_filters('em_location_image_delete', $result, $this);
195
- }
196
-
197
- function image_upload(){
198
- //TODO better image upload error handling
199
- do_action('em_location_image_upload_pre', $this);
200
- $result = true;
201
- if ( !empty($_FILES['location_image']['size']) ) {
202
- if( !file_exists(ABSPATH.EM_IMAGE_UPLOAD_DIR) ){
203
- mkdir(ABSPATH.EM_IMAGE_UPLOAD_DIR, 0777);
204
- }
205
- $this->image_delete();
206
- list($width, $height, $type, $attr) = getimagesize($_FILES['location_image']['tmp_name']);
207
- $image_path = ABSPATH.EM_IMAGE_UPLOAD_DIR."/location-".$this->id.".".$this->mime_types[$type];
208
- if (!move_uploaded_file($_FILES['location_image']['tmp_name'], $image_path)){
209
- $this->errors = __('The image could not be loaded','dbem');
210
- $result = false;
211
- }else{
212
- $result = true;
213
- }
214
- }
215
- return apply_filters('em_location_image_upload', $result, $this);
216
- }
217
-
218
- function load_similar($criteria){
219
- global $wpdb;
220
- if( !empty($criteria['location_name']) && !empty($criteria['location_name']) && !empty($criteria['location_name']) ){
221
- $locations_table = $wpdb->prefix.EM_LOCATIONS_TABLE;
222
- $prepared_sql = $wpdb->prepare("SELECT * FROM $locations_table WHERE location_name = %s AND location_address = %s AND location_town = %s AND location_state = %s AND location_postcode = %s AND location_country = %s", stripcslashes($criteria['location_name']), stripcslashes($criteria['location_address']), stripcslashes($criteria['location_town']), stripcslashes($criteria['location_state']), stripcslashes($criteria['location_postcode']), stripcslashes($criteria['location_country']) );
223
- //$wpdb->show_errors(true);
224
- $location = $wpdb->get_row($prepared_sql, ARRAY_A);
225
- if( is_array($location) ){
226
- $this->to_object($location);
227
- }
228
- return apply_filters('em_location_load_similar', $location, $this);
229
- }
230
- return apply_filters('em_location_load_similar', false, $this);
231
- }
232
-
233
- /**
234
- * Validates the location. Should be run during any form submission or saving operation.
235
- * @return boolean
236
- */
237
- function validate(){
238
- //check required fields
239
- foreach ( $this->required_fields as $field => $description) {
240
- if( $field == 'country' && !array_key_exists($this->country, em_get_countries()) ){
241
- //country specific checking
242
- $this->errors[] = $this->required_fields['country'].__(" is required.", "dbem");
243
- }elseif ( $this->$field == "" ) {
244
- $this->errors[] = $description.__(" is required.", "dbem");
245
- }
246
- }
247
- //Srt out the image
248
- if ( !empty($_FILES['location_image']) && $_FILES['location_image']['size'] > 0 ) {
249
- if (is_uploaded_file($_FILES['location_image']['tmp_name'])) {
250
- $mime_types = array(1 => 'gif', 2 => 'jpg', 3 => 'png');
251
- $maximum_size = get_option('dbem_image_max_size');
252
- if ($_FILES['location_image']['size'] > $maximum_size){
253
- $this->errors[] = __('The image file is too big! Maximum size:', 'dbem')." $maximum_size";
254
- }
255
- list($width, $height, $type, $attr) = getimagesize($_FILES['location_image']['tmp_name']);
256
- $maximum_width = get_option('dbem_image_max_width');
257
- $maximum_height = get_option('dbem_image_max_height');
258
- if (($width > $maximum_width) || ($height > $maximum_height)) {
259
- $this->errors[] = __('The image is too big! Maximum size allowed:')." $maximum_width x $maximum_height";
260
- }
261
- if (($type!=1) && ($type!=2) && ($type!=3)){
262
- $this->errors[] = __('The image is in a wrong format!');
263
- }
264
- }
265
- }
266
- return apply_filters('em_location_validate', ( count($this->errors) == 0 ), $this);
267
- }
268
-
269
- function has_events(){
270
- global $wpdb;
271
- $events_table = $wpdb->prefix.EM_EVENTS_TABLE;
272
- $sql = "SELECT count(event_id) as events_no FROM $events_table WHERE location_id = {$this->id}";
273
- $affected_events = $wpdb->get_row($sql);
274
- return apply_filters('em_location_has_events', (count($affected_events) > 0), $this);
275
- }
276
-
277
- /**
278
- * Can the user manage this location?
279
- */
280
- function can_manage( $owner_capability = false, $admin_capability = false ){
281
- return apply_filters('em_location_can_manage', parent::can_manage($owner_capability, $admin_capability), $this);
282
- }
283
-
284
- function output_single($target = 'html'){
285
- $format = get_option ( 'dbem_single_location_format' );
286
- return apply_filters('em_location_output_single', $this->output($format, $target), $this, $target);
287
- }
288
-
289
- function output($format, $target="html") {
290
- $location_string = $format;
291
- preg_match_all("/#_[A-Za-z]+/", $format, $placeholders);
292
- foreach($placeholders[0] as $result) {
293
- $match = true;
294
- $replace = '';
295
- switch( $result ){
296
- case '#_LOCATIONID':
297
- $replace = $this->id;
298
- break;
299
- case '#_NAME': //Depreciated
300
- case '#_LOCATIONNAME':
301
- $replace = $this->name;
302
- break;
303
- case '#_ADDRESS': //Depreciated
304
- case '#_LOCATIONADDRESS':
305
- $replace = $this->address;
306
- break;
307
- case '#_TOWN': //Depreciated
308
- case '#_LOCATIONTOWN':
309
- $replace = $this->town;
310
- break;
311
- case '#_LOCATIONSTATE':
312
- $replace = $this->id;
313
- break;
314
- case '#_LOCATIONPOSTCODE':
315
- $replace = $this->id;
316
- break;
317
- case '#_LOCATIONCOUNTRY':
318
- $replace = $this->id;
319
- break;
320
- case '#_MAP': //Depreciated
321
- case '#_LOCATIONMAP':
322
- $replace = EM_Map::get_single( array('location' => $this) );
323
- break;
324
- case '#_DESCRIPTION': //Depreciated
325
- case '#_EXCERPT': //Depreciated
326
- case '#_LOCATIONNOTES':
327
- case '#_LOCATIONEXCERPT':
328
- $replace = $this->description;
329
- if($result == "#_EXCERPT" || $result == "#_LOCATIONEXCERPT"){
330
- $matches = explode('<!--more', $this->description);
331
- $replace = $matches[0];
332
- }
333
- break;
334
- case '#_IMAGE': //Depreciated
335
- case '#_LOCATIONIMAGE':
336
- if($this->image_url != ''){
337
- $replace = "<img src='".$this->image_url."' alt='".$this->name."'/>";
338
- }
339
- break;
340
- case '#_LOCATIONURL':
341
- case '#_LOCATIONLINK':
342
- case '#_LOCATIONPAGEURL': //Depreciated
343
- $joiner = (stristr(EM_URI, "?")) ? "&amp;" : "?";
344
- $link = EM_URI.$joiner."location_id=".$this->id;
345
- $replace = ($result == '#_LOCATIONURL' || $result == '#_LOCATIONPAGEURL') ? $link : '<a href="'.$link.'">'.$this->name.'</a>';
346
- break;
347
- case '#_PASTEVENTS': //Depreciated
348
- case '#_LOCATIONPASTEVENTS':
349
- case '#_NEXTEVENTS': //Depreciated
350
- case '#_LOCATIONNEXTEVENTS':
351
- case '#_ALLEVENTS': //Depreciated
352
- case '#_LOCATIONALLEVENTS':
353
- if ($result == '#_PASTEVENTS' || $result == '#_LOCATIONPASTEVENTS'){ $scope = 'past'; }
354
- elseif ( $result == '#_NEXTEVENTS' || $result == '#_LOCATIONNEXTEVENTS' ){ $scope = 'future'; }
355
- else{ $scope = 'all'; }
356
- $events = EM_Events::get( array('location'=>$this->id, 'scope'=>$scope) );
357
- if ( count($events) > 0 ){
358
- foreach($events as $event){
359
- $replace .= $event->output(get_option('dbem_location_event_list_item_format'));
360
- }
361
- } else {
362
- $replace = get_option('dbem_location_no_events_message');
363
- }
364
- break;
365
- default:
366
- $match = false;
367
- break;
368
- }
369
- if($match){ //if true, we've got a placeholder that needs replacing
370
- //TODO FILTER - placeholder filter
371
- $replace = apply_filters('em_location_output_placeholder', $replace, $this, $result, $target); //USE WITH CAUTION! THIS MIGHT GET RENAMED
372
- $location_string = str_replace($result, $replace , $location_string );
373
- }
374
- }
375
- $name_filter = ($target == "html") ? 'dbem_general':'dbem_general_rss'; //TODO remove dbem_ filters
376
- $location_string = str_replace('#_LOCATION', apply_filters($name_filter, $this->name) , $location_string ); //Depreciated
377
- return apply_filters('em_location_output', $location_string, $this, $format, $target);
378
- }
379
-
380
- function get_country(){
381
- $countries = em_get_countries();
382
- if( !empty($countries[$this->country]) ){
383
- return apply_filters('em_location_get_country', $countries[$this->country], $this);
384
- }
385
- return apply_filters('em_location_get_country', false, $this);
386
-
387
- }
388
  }
1
+ <?php
2
+ /**
3
+ * Object that holds location info and related functions
4
+ * @author marcus
5
+ */
6
+ class EM_Location extends EM_Object {
7
+ //DB Fields
8
+ var $id = '';
9
+ var $name = '';
10
+ var $address = '';
11
+ var $town = '';
12
+ var $latitude = '';
13
+ var $longitude = '';
14
+ var $description = '';
15
+ var $image_url = '';
16
+ var $owner = '';
17
+ //Other Vars
18
+ var $fields = array(
19
+ 'location_id' => array('name'=>'id','type'=>'%d'),
20
+ 'location_name' => array('name'=>'name','type'=>'%s'),
21
+ 'location_address' => array('name'=>'address','type'=>'%s'),
22
+ 'location_town' => array('name'=>'town','type'=>'%s'),
23
+ //Not Used - 'location_province' => array('name'=>'province','type'=>'%s'),
24
+ 'location_latitude' => array('name'=>'latitude','type'=>'%f'),
25
+ 'location_longitude' => array('name'=>'longitude','type'=>'%f'),
26
+ 'location_description' => array('name'=>'description','type'=>'%s'),
27
+ 'location_owner' => array('name'=>'owner','type'=>'%d')
28
+ );
29
+ var $required_fields;
30
+ var $feedback_message = "";
31
+ var $mime_types = array(1 => 'gif', 2 => 'jpg', 3 => 'png');
32
+ var $errors = array();
33
+
34
+ /**
35
+ * Gets data from POST (default), supplied array, or from the database if an ID is supplied
36
+ * @param $location_data
37
+ * @return null
38
+ */
39
+ function EM_Location( $location_data = 0 ) {
40
+ //Initialize
41
+ $this->required_fields = array("name" => __('The location name', 'dbem'), "address" => __('The location address', 'dbem'), "town" => __('The location town', 'dbem'));
42
+ if( $location_data != 0 ){
43
+ //Load location data
44
+ if( is_array($location_data) && isset($location_data['location_name']) ){
45
+ $location = $location_data;
46
+ }elseif( $location_data > 0 ){
47
+ //Retreiving from the database
48
+ global $wpdb;
49
+ $sql = "SELECT * FROM ". $wpdb->prefix.EM_LOCATIONS_TABLE ." WHERE location_id ='{$location_data}'";
50
+ $location = $wpdb->get_row($sql, ARRAY_A);
51
+ }
52
+ //If gmap is turned off, values may not be returned and set, so we set it here
53
+ if(empty($location['location_latitude'])) {
54
+ $location['location_latitude'] = 0;
55
+ $location['location_longitude'] = 0;
56
+ }
57
+ //Save into the object
58
+ $this->to_object($location, true);
59
+ $this->get_image_url();
60
+ }
61
+ }
62
+
63
+ function get_post(){
64
+ //We are getting the values via POST or GET
65
+ do_action('em_location_get_post_pre', $this);
66
+ $location = array();
67
+ $location['location_id'] = ( !empty($_POST['location_id']) ) ? $_POST['location_id']:'';
68
+ $location['location_name'] = ( !empty($_POST['location_name']) ) ? stripslashes($_POST['location_name']):'';
69
+ $location['location_address'] = ( !empty($_POST['location_address']) ) ? stripslashes($_POST['location_address']):'';
70
+ $location['location_town'] = ( !empty($_POST['location_town']) ) ? stripslashes($_POST['location_town']):'';
71
+ $location['location_latitude'] = ( !empty($_POST['location_latitude']) ) ? $_POST['location_latitude']:'';
72
+ $location['location_longitude'] = ( !empty($_POST['location_longitude']) ) ? $_POST['location_longitude']:'';
73
+ $location['location_description'] = ( !empty($_POST['content']) ) ? stripslashes($_POST['content']):'';
74
+ $this->to_object( apply_filters('em_location_get_post', $location, $this) );
75
+ }
76
+
77
+ function save(){
78
+ global $wpdb, $current_user;
79
+ get_currentuserinfo();
80
+ do_action('em_location_save_pre', $this);
81
+ $table = $wpdb->prefix.EM_LOCATIONS_TABLE;
82
+ $data = $this->to_array();
83
+ unset($data['location_id']);
84
+ unset($data['location_image_url']);
85
+ if($this->id != ''){
86
+ $where = array( 'location_id' => $this->id );
87
+ $wpdb->update($table, $data, $where, $this->get_types($data));
88
+ }else{
89
+ $this->owner = $current_user->ID; //Record creator of event
90
+ $data['location_owner'] = $this->owner;
91
+ $wpdb->insert($table, $data, $this->get_types($data));
92
+ $this->id = $wpdb->insert_id;
93
+ }
94
+ $image_upload = $this->image_upload();
95
+ return apply_filters('em_location_save', ( $this->id > 0 && $image_upload ), $this, $image_upload);
96
+ }
97
+
98
+ function delete(){
99
+ global $wpdb;
100
+ do_action('em_location_delete_pre', $this);
101
+ $table_name = $wpdb->prefix.EM_LOCATIONS_TABLE;
102
+ $sql = "DELETE FROM $table_name WHERE location_id = '{$this->id}';";
103
+ $result = $wpdb->query($sql);
104
+ $result = $this->image_delete() && $result;
105
+ return apply_filters('em_location_delete', $result, $this);
106
+ }
107
+
108
+ function get_image_url(){
109
+ if($this->image_url == ''){
110
+ foreach($this->mime_types as $type) {
111
+ $file_path = "/".EM_IMAGE_UPLOAD_DIR."/location-{$this->id}.$type";
112
+ if( file_exists( ABSPATH . $file_path) ) {
113
+ $result = get_bloginfo('wpurl').$file_path;
114
+ $this->image_url = $result;
115
+ }
116
+ }
117
+ }
118
+ return apply_filters('em_location_get_image_url', $this->image_url, $this);
119
+ }
120
+
121
+ function image_delete() {
122
+ $file_name= ABSPATH.EM_IMAGE_UPLOAD_DIR."/location-".$this->id;
123
+ $result = false;
124
+ foreach($this->mime_types as $type) {
125
+ if (file_exists($file_name.".".$type))
126
+ $result = unlink($file_name.".".$type);
127
+ }
128
+ return apply_filters('em_location_image_delete', $result, $this);
129
+ }
130
+
131
+ function image_upload(){
132
+ //TODO better image upload error handling
133
+ do_action('em_location_image_upload_pre', $this);
134
+ $result = true;
135
+ if ( !empty($_FILES['location_image']['size']) ) {
136
+ if( !file_exists(ABSPATH.EM_IMAGE_UPLOAD_DIR) ){
137
+ mkdir(ABSPATH.EM_IMAGE_UPLOAD_DIR, 0777);
138
+ }
139
+ $this->image_delete();
140
+ list($width, $height, $type, $attr) = getimagesize($_FILES['location_image']['tmp_name']);
141
+ $image_path = ABSPATH.EM_IMAGE_UPLOAD_DIR."/location-".$this->id.".".$this->mime_types[$type];
142
+ if (!move_uploaded_file($_FILES['location_image']['tmp_name'], $image_path)){
143
+ $this->errors = __('The image could not be loaded','dbem');
144
+ $result = false;
145
+ }else{
146
+ $result = true;
147
+ }
148
+ }
149
+ return apply_filters('em_location_image_upload', $result, $this);
150
+ }
151
+
152
+ function load_similar($criteria){
153
+ global $wpdb;
154
+ if( !empty($criteria['location_name']) && !empty($criteria['location_name']) && !empty($criteria['location_name']) ){
155
+ $locations_table = $wpdb->prefix.EM_LOCATIONS_TABLE;
156
+ $prepared_sql = $wpdb->prepare("SELECT * FROM $locations_table WHERE location_name = %s AND location_address = %s AND location_town = %s", stripcslashes($criteria['location_name']), stripcslashes($criteria['location_address']), stripcslashes($criteria['location_town']) );
157
+ //$wpdb->show_errors(true);
158
+ $location = $wpdb->get_row($prepared_sql, ARRAY_A);
159
+ if( is_array($location) ){
160
+ $this->to_object($location);
161
+ }
162
+ return apply_filters('em_location_load_similar', $location, $this);
163
+ }
164
+ return apply_filters('em_location_load_similar', false, $this);
165
+ }
166
+
167
+ /**
168
+ * Validates the location. Should be run during any form submission or saving operation.
169
+ * @return boolean
170
+ */
171
+ function validate(){
172
+ foreach ( $this->required_fields as $field => $description) {
173
+ if ( $this->$field == "" ) {
174
+ $this->errors[] = $description.__(" is missing!", "dbem");
175
+ }
176
+ }
177
+ if ( !empty($_FILES['location_image']) && $_FILES['location_image']['size'] > 0 ) {
178
+ if (is_uploaded_file($_FILES['location_image']['tmp_name'])) {
179
+ $mime_types = array(1 => 'gif', 2 => 'jpg', 3 => 'png');
180
+ $maximum_size = get_option('dbem_image_max_size');
181
+ if ($_FILES['location_image']['size'] > $maximum_size){
182
+ $this->errors[] = __('The image file is too big! Maximum size:', 'dbem')." $maximum_size";
183
+ }
184
+ list($width, $height, $type, $attr) = getimagesize($_FILES['location_image']['tmp_name']);
185
+ $maximum_width = get_option('dbem_image_max_width');
186
+ $maximum_height = get_option('dbem_image_max_height');
187
+ if (($width > $maximum_width) || ($height > $maximum_height)) {
188
+ $this->errors[] = __('The image is too big! Maximum size allowed:')." $maximum_width x $maximum_height";
189
+ }
190
+ if (($type!=1) && ($type!=2) && ($type!=3)){
191
+ $this->errors[] = __('The image is in a wrong format!');
192
+ }
193
+ }
194
+ }
195
+ return apply_filters('em_location_validate', ( count($this->errors) == 0 ), $this);
196
+ }
197
+
198
+ function has_events(){
199
+ global $wpdb;
200
+ $events_table = $wpdb->prefix.EM_EVENTS_TABLE;
201
+ $sql = "SELECT count(event_id) as events_no FROM $events_table WHERE location_id = {$this->id}";
202
+ $affected_events = $wpdb->get_row($sql);
203
+ return apply_filters('em_location_has_events', (count($affected_events) > 0), $this);
204
+ }
205
+
206
+ function can_manage(){
207
+ return ( get_option('dbem_permissions_locations') == 2 || $this->owner == get_current_user_id() || empty($this->id) || em_verify_admin() );
208
+ }
209
+
210
+ function can_use(){
211
+ switch( get_option('dbem_permissions_locations') ){
212
+ case 0:
213
+ return $this->owner == get_current_user_id();
214
+ case 1:
215
+ return em_verify_admin($this->owner);
216
+ case 2:
217
+ return true;
218
+ }
219
+ }
220
+
221
+ function output_single($target = 'html'){
222
+ $format = get_option ( 'dbem_single_location_format' );
223
+ return apply_filters('em_location_output_single', $this->output($format, $target), $this, $target);
224
+ }
225
+
226
+ function output($format, $target="html") {
227
+ $location_string = $format;
228
+ preg_match_all("/#_[A-Za-z]+/", $format, $placeholders);
229
+ foreach($placeholders[0] as $result) {
230
+ $match = true;
231
+ $replace = '';
232
+ switch( $result ){
233
+ case '#_MAP': //Depreciated
234
+ case '#_LOCATIONMAP':
235
+ $replace = EM_Map::get_single( array('location' => $this) );
236
+ break;
237
+ case '#_DESCRIPTION': //Depreciated
238
+ case '#_EXCERPT': //Depreciated
239
+ case '#_LOCATIONNOTES':
240
+ case '#_LOCATIONEXCERPT':
241
+ $replace = $this->description;
242
+ if($result == "#_EXCERPT" || $result == "#_LOCATIONEXCERPT"){
243
+ $matches = explode('<!--more', $this->description);
244
+ $replace = $matches[0];
245
+ }
246
+ break;
247
+ case '#_LOCATIONURL':
248
+ case '#_LOCATIONLINK':
249
+ case '#_LOCATIONPAGEURL': //Depreciated
250
+ $joiner = (stristr(EM_URI, "?")) ? "&amp;" : "?";
251
+ $link = EM_URI.$joiner."location_id=".$this->id;
252
+ $replace = ($result == '#_LOCATIONURL' || $result == '#_LOCATIONPAGEURL') ? $link : '<a href="'.$link.'">'.$this->name.'</a>';
253
+ break;
254
+ case '#_PASTEVENTS': //Depreciated
255
+ case '#_LOCATIONPASTEVENTS':
256
+ case '#_NEXTEVENTS': //Depreciated
257
+ case '#_LOCATIONNEXTEVENTS':
258
+ case '#_ALLEVENTS': //Depreciated
259
+ case '#_LOCATIONALLEVENTS':
260
+ if ($result == '#_PASTEVENTS' || $result == '#_LOCATIONPASTEVENTS'){ $scope = 'past'; }
261
+ elseif ( $result == '#_NEXTEVENTS' || $result == '#_LOCATIONNEXTEVENTS' ){ $scope = 'future'; }
262
+ else{ $scope = 'all'; }
263
+ $events = EM_Events::get( array('location'=>$this->id, 'scope'=>$scope) );
264
+ if ( count($events) > 0 ){
265
+ foreach($events as $event){
266
+ $replace .= $event->output(get_option('dbem_location_event_list_item_format'));
267
+ }
268
+ } else {
269
+ $replace = get_option('dbem_location_no_events_message');
270
+ }
271
+ break;
272
+ case '#_IMAGE': //Depreciated
273
+ case '#_LOCATIONIMAGE':
274
+ if($this->image_url != ''){
275
+ $replace = "<img src='".$this->image_url."' alt='".$this->name."'/>";
276
+ }
277
+ break;
278
+ case '#_NAME': //Depreciated
279
+ case '#_LOCATIONNAME':
280
+ $replace = $this->name;
281
+ break;
282
+ case '#_ADDRESS': //Depreciated
283
+ case '#_LOCATIONADDRESS':
284
+ $replace = $this->address;
285
+ break;
286
+ case '#_TOWN': //Depreciated
287
+ case '#_LOCATIONTOWN':
288
+ $replace = $this->town;
289
+ break;
290
+ case '#_LOCATIONID':
291
+ $replace = $this->id;
292
+ break;
293
+ default:
294
+ $match = false;
295
+ break;
296
+ }
297
+ if($match){ //if true, we've got a placeholder that needs replacing
298
+ //TODO FILTER - placeholder filter
299
+ $replace = apply_filters('em_location_output_placeholder', $replace, $this, $result, $target); //USE WITH CAUTION! THIS MIGHT GET RENAMED
300
+ $location_string = str_replace($result, $replace , $location_string );
301
+ }
302
+ }
303
+ $name_filter = ($target == "html") ? 'dbem_general':'dbem_general_rss'; //TODO remove dbem_ filters
304
+ $location_string = str_replace('#_LOCATION', apply_filters($name_filter, $this->name) , $location_string ); //Depreciated
305
+ return apply_filters('em_location_output', $location_string, $this, $format, $target);
306
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  }
classes/em-locations.php CHANGED
@@ -1,221 +1,213 @@
1
- <?php
2
- /**
3
- * Static class which will help bulk add/edit/retrieve/manipulate arrays of EM_Location objects.
4
- * Optimized for specifically retreiving locations (whether eventful or not). If you want event data AND location information for each event, use EM_Events
5
- *
6
- */
7
- class EM_Locations extends EM_Object {
8
- /**
9
- * Returns an array of EM_Location objects
10
- * @param boolean $eventful
11
- * @param boolean $return_objects
12
- * @return array
13
- */
14
- function get( $args = array(), $count=false ){
15
- global $wpdb;
16
- $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
17
- $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
18
-
19
- //Quick version, we can accept an array of IDs, which is easy to retrieve
20
- if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
21
- //We can just get all the events here and return them
22
- $sql = "SELECT * FROM $locations_table WHERE location_id=".implode(" OR location_id=", $args);
23
- $results = $wpdb->get_results($sql,ARRAY_A);
24
- $events = array();
25
- foreach($results as $result){
26
- $locations[$result['location_id']] = new EM_Location($result);
27
- }
28
- return $locations; //We return all the events matched as an EM_Event array.
29
- }elseif( is_numeric($args) ){
30
- //return an event in the usual array format
31
- return apply_filters('em_locations_get', array(new EM_Event($args)), $args);
32
- }elseif( is_array($args) && is_object(current($args)) && get_class((current($args))) == 'EM_Location' ){
33
- return apply_filters('em_locations_get', $args, $args);
34
- }
35
-
36
- //We assume it's either an empty array or array of search arguments to merge with defaults
37
- $args = self::get_default_search($args);
38
- $limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
39
- $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
40
-
41
- //Get the default conditions
42
- $conditions = self::build_sql_conditions($args);
43
-
44
- //Put it all together
45
- $EM_Location = new EM_Location(0); //Empty class for strict message avoidance
46
- $fields = $locations_table .".". implode(", {$locations_table}.", array_keys($EM_Location->fields));
47
- $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
48
-
49
- //Get ordering instructions
50
- $EM_Event = new EM_Event(); //blank event for below
51
- $accepted_fields = $EM_Location->get_fields(true);
52
- $accepted_fields = array_merge($EM_Event->get_fields(true),$accepted_fields);
53
- $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order'));
54
- //Now, build orderby sql
55
- $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
56
-
57
- if( $count ){
58
- $fields = $locations_table.'.location_id';
59
- }
60
- //Create the SQL statement and execute
61
- $sql = "
62
- SELECT $fields FROM $locations_table
63
- LEFT JOIN $events_table ON {$locations_table}.location_id={$events_table}.location_id
64
- $where
65
- GROUP BY {$locations_table}.location_id
66
- $orderby_sql
67
- $limit $offset
68
- ";
69
-
70
- //If we're only counting results, return the number of results
71
- if( $count ){
72
- return count($wpdb->get_results($sql));
73
- }
74
- $results = $wpdb->get_results($sql, ARRAY_A);
75
-
76
- //If we want results directly in an array, why not have a shortcut here?
77
- if( $args['array'] == true ){
78
- return $results;
79
- }
80
-
81
- $locations = array();
82
- foreach ($results as $location){
83
- $locations[] = new EM_Location($location);
84
- }
85
- return apply_filters('em_locations_get', $locations, $args);
86
- }
87
-
88
- function count( $args = array() ){
89
- return apply_filters('em_locations_count', self::get($args, true), $args);
90
- }
91
-
92
- /**
93
- * Output a set of matched of events
94
- * @param array $args
95
- * @return string
96
- */
97
- function output( $args ){
98
- global $EM_Location;
99
- $EM_Location_old = $EM_Location; //When looping, we can replace EM_Location global with the current event in the loop
100
- //Can be either an array for the get search or an array of EM_Location objects
101
- if( is_object(current($args)) && get_class((current($args))) == 'EM_Location' ){
102
- $func_args = func_get_args();
103
- $locations = $func_args[0];
104
- $args = apply_filters('em_locations_output_args', self::get_default_search($func_args[1]), $locations);
105
- $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
106
- $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
107
- $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
108
- }else{
109
- $args = apply_filters('em_locations_output_args', self::get_default_search($args) );
110
- $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
111
- $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
112
- $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
113
- $args['limit'] = false;
114
- $args['offset'] = false;
115
- $args['page'] = false;
116
- $locations = self::get( $args );
117
- }
118
- //What format shall we output this to, or use default
119
- $format = ( $args['format'] == '' ) ? get_option( 'dbem_location_list_item_format' ) : $args['format'] ;
120
-
121
- $output = "";
122
- $locations_count = count($locations);
123
- $locations = apply_filters('em_locations_output_locations', $locations);
124
-
125
- if ( count($locations) > 0 ) {
126
- $location_count = 0;
127
- $locations_shown = 0;
128
- foreach ( $locations as $EM_Location ) {
129
- if( ($locations_shown < $limit || empty($limit)) && ($location_count >= $offset || $offset === 0) ){
130
- $output .= $EM_Location->output($format);
131
- $locations_shown++;
132
- }
133
- $location_count++;
134
- }
135
- //Add headers and footers to output
136
- if( $format == get_option ( 'dbem_location_list_item_format' ) ){
137
- $single_event_format_header = get_option ( 'dbem_location_list_item_format_header' );
138
- $single_event_format_header = ( $single_event_format_header != '' ) ? $single_event_format_header : "<ul class='dbem_events_list'>";
139
- $single_event_format_footer = get_option ( 'dbem_location_list_item_format_footer' );
140
- $single_event_format_footer = ( $single_event_format_footer != '' ) ? $single_event_format_footer : "</ul>";
141
- $output = $single_event_format_header . $output . $single_event_format_footer;
142
- }
143
- //Pagination (if needed/requested)
144
- if( !empty($args['pagination']) && !empty($limit) && $locations_count >= $limit ){
145
- //Show the pagination links (unless there's less than 10 events
146
- $page_link_template = preg_replace('/(&|\?)page=\d+/i','',$_SERVER['REQUEST_URI']);
147
- $page_link_template = em_add_get_params($page_link_template, array('page'=>'%PAGE%'));
148
- $output .= apply_filters('em_events_output_pagination', em_paginate( $page_link_template, $locations_count, $limit, $page), $page_link_template, $locations_count, $limit, $page);
149
- }
150
- } else {
151
- $output = get_option ( 'dbem_no_events_message' );
152
- }
153
- //FIXME check if reference is ok when restoring object, due to changes in php5 v 4
154
- $EM_Location_old= $EM_Location;
155
- return apply_filters('em_locations_output', $output, $locations, $args);
156
- }
157
-
158
- function delete( $args = array() ){
159
- if( !is_object(current($args)) && get_class((current($args))) != 'EM_Location' ){
160
- $locations = self::get($args);
161
- }else{
162
- $locations = $args;
163
- }
164
- $results = array();
165
- foreach ( $locations as $EM_Location ){
166
- $results[] = $EM_Location->delete();
167
- }
168
- return apply_filters('em_locations_delete', in_array(false, $results), $locations);
169
- }
170
-
171
- /**
172
- * Builds an array of SQL query conditions based on regularly used arguments
173
- * @param array $args
174
- * @return array
175
- */
176
- function build_sql_conditions( $args = array() ){
177
- global $wpdb;
178
- $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
179
- $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
180
-
181
- $conditions = parent::build_sql_conditions($args);
182
- //eventful locations
183
- if( true == $args['eventful'] ){
184
- $conditions['eventful'] = "{$events_table}.event_id IS NOT NULL";
185
- }elseif( true == $args['eventless'] ){
186
- $conditions['eventless'] = "{$events_table}.event_id IS NULL";
187
- }
188
- //owner lookup
189
- if( !empty($args['owner']) ){
190
- $conditions['owner'] = "location_owner=".$args['owner'];
191
- }
192
- return apply_filters('em_locations_build_sql_conditions', $conditions, $args);
193
- }
194
-
195
- /* Overrides EM_Object method to apply a filter to result
196
- * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
197
- */
198
- function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
199
- return apply_filters( 'em_locations_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')), $args, $accepted_fields, $default_order );
200
- }
201
-
202
- /*
203
- * Generate a search arguments array from defalut and user-defined.
204
- * @see wp-content/plugins/events-manager/classes/EM_Object::get_default_search()
205
- */
206
- function get_default_search($array = array()){
207
- $defaults = array(
208
- 'eventful' => false, //Locations that have an event (scope will also play a part here
209
- 'eventless' => false, //Locations WITHOUT events, eventful takes precedence
210
- 'orderby' => 'name',
211
- 'scope' => 'all' //we probably want to search all locations by default, not like events
212
- );
213
- $array['eventful'] = ( !empty($array['eventful']) && $array['eventful'] == true );
214
- $array['eventless'] = ( !empty($array['eventless']) && $array['eventless'] == true );
215
- if( is_admin() ){
216
- $defaults['owner'] = !current_user_can('read_others_locations') ? get_current_user_id():false;
217
- }
218
- return apply_filters('em_locations_get_default_search', parent::get_default_search($defaults, $array), $array, $defaults);
219
- }
220
- }
221
  ?>
1
+ <?php
2
+ /**
3
+ * Static class which will help bulk add/edit/retrieve/manipulate arrays of EM_Location objects.
4
+ * Optimized for specifically retreiving locations (whether eventful or not). If you want event data AND location information for each event, use EM_Events
5
+ *
6
+ */
7
+ class EM_Locations extends EM_Object {
8
+ /**
9
+ * Returns an array of EM_Location objects
10
+ * @param boolean $eventful
11
+ * @param boolean $return_objects
12
+ * @return array
13
+ */
14
+ function get( $args = array() ){
15
+ global $wpdb;
16
+ $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
17
+ $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
18
+
19
+ //Quick version, we can accept an array of IDs, which is easy to retrieve
20
+ if( self::array_is_numeric($args) && count() ){ //Array of numbers, assume they are event IDs to retreive
21
+ //We can just get all the events here and return them
22
+ $sql = "SELECT * FROM $locations_table WHERE location_id=".implode(" OR location_id=", $args);
23
+ $results = $wpdb->get_results($sql,ARRAY_A);
24
+ $events = array();
25
+ foreach($results as $result){
26
+ $locations[$result['location_id']] = new EM_Location($result);
27
+ }
28
+ return $locations; //We return all the events matched as an EM_Event array.
29
+ }
30
+
31
+
32
+ //We assume it's either an empty array or array of search arguments to merge with defaults
33
+ $args = self::get_default_search($args);
34
+ $limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
35
+ $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
36
+
37
+ //Get the default conditions
38
+ $conditions = self::build_sql_conditions($args);
39
+
40
+ //Put it all together
41
+ $EM_Location = new EM_Location(0); //Empty class for strict message avoidance
42
+ $fields = $locations_table .".". implode(", {$locations_table}.", array_keys($EM_Location->fields));
43
+ $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
44
+
45
+ //Get ordering instructions
46
+ $EM_Event = new EM_Event(); //blank event for below
47
+ $accepted_fields = $EM_Location->get_fields(true);
48
+ $accepted_fields = array_merge($EM_Event->get_fields(true),$accepted_fields);
49
+ $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order'));
50
+ //Now, build orderby sql
51
+ $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
52
+
53
+
54
+ //Create the SQL statement and execute
55
+ $sql = "
56
+ SELECT $fields FROM $locations_table
57
+ LEFT JOIN $events_table ON {$locations_table}.location_id={$events_table}.location_id
58
+ $where
59
+ GROUP BY location_id
60
+ $orderby_sql
61
+ $limit $offset
62
+ ";
63
+
64
+ $results = $wpdb->get_results($sql, ARRAY_A);
65
+
66
+ //If we want results directly in an array, why not have a shortcut here?
67
+ if( $args['array'] == true ){
68
+ return $results;
69
+ }
70
+
71
+ $locations = array();
72
+ foreach ($results as $location){
73
+ $locations[] = new EM_Location($location);
74
+ }
75
+ return apply_filters('em_locations_get', $locations, $args);
76
+ }
77
+
78
+ /**
79
+ * Output a set of matched of events
80
+ * @param array $args
81
+ * @return string
82
+ */
83
+ function output( $args ){
84
+ global $EM_Location;
85
+ $EM_Location_old = $EM_Location; //When looping, we can replace EM_Location global with the current event in the loop
86
+ //Can be either an array for the get search or an array of EM_Location objects
87
+ if( is_object(current($args)) && get_class((current($args))) == 'EM_Location' ){
88
+ $func_args = func_get_args();
89
+ $locations = $func_args[0];
90
+ $args = apply_filters('em_locations_output_args', self::get_default_search($func_args[1]), $locations);
91
+ $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
92
+ $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
93
+ $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
94
+ }else{
95
+ $args = apply_filters('em_locations_output_args', self::get_default_search($args) );
96
+ $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
97
+ $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
98
+ $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
99
+ $args['limit'] = false;
100
+ $args['offset'] = false;
101
+ $args['page'] = false;
102
+ $locations = self::get( $args );
103
+ }
104
+ //What format shall we output this to, or use default
105
+ $format = ( $args['format'] == '' ) ? get_option( 'dbem_location_list_item_format' ) : $args['format'] ;
106
+
107
+ $output = "";
108
+ $locations_count = count($locations);
109
+ $locations = apply_filters('em_locations_output_locations', $locations);
110
+
111
+ if ( count($locations) > 0 ) {
112
+ $location_count = 0;
113
+ $locations_shown = 0;
114
+ foreach ( $locations as $EM_Location ) {
115
+ if( ($locations_shown < $limit || empty($limit)) && ($location_count >= $offset || $offset === 0) ){
116
+ $output .= $EM_Location->output($format);
117
+ $locations_shown++;
118
+ }
119
+ $location_count++;
120
+ }
121
+ //Add headers and footers to output
122
+ if( $format == get_option ( 'dbem_location_list_item_format' ) ){
123
+ $single_event_format_header = get_option ( 'dbem_location_list_item_format_header' );
124
+ $single_event_format_header = ( $single_event_format_header != '' ) ? $single_event_format_header : "<ul class='dbem_events_list'>";
125
+ $single_event_format_footer = get_option ( 'dbem_location_list_item_format_footer' );
126
+ $single_event_format_footer = ( $single_event_format_footer != '' ) ? $single_event_format_footer : "</ul>";
127
+ $output = $single_event_format_header . $output . $single_event_format_footer;
128
+ }
129
+ //Pagination (if needed/requested)
130
+ if( !empty($args['pagination']) && !empty($limit) && $locations_count >= $limit ){
131
+ //Show the pagination links (unless there's less than 10 events
132
+ $page_link_template = preg_replace('/(&|\?)page=\d+/i','',$_SERVER['REQUEST_URI']);
133
+ $page_link_template = em_add_get_params($page_link_template, array('page'=>'%PAGE%'));
134
+ $output .= apply_filters('em_events_output_pagination', em_paginate( $page_link_template, $locations_count, $limit, $page), $page_link_template, $locations_count, $limit, $page);
135
+ }
136
+ } else {
137
+ $output = get_option ( 'dbem_no_events_message' );
138
+ }
139
+ //FIXME check if reference is ok when restoring object, due to changes in php5 v 4
140
+ $EM_Location_old= $EM_Location;
141
+ return apply_filters('em_locations_output', $output, $locations, $args);
142
+ }
143
+
144
+ /**
145
+ * Builds an array of SQL query conditions based on regularly used arguments
146
+ * @param array $args
147
+ * @return array
148
+ */
149
+ function build_sql_conditions( $args = array() ){
150
+ global $wpdb;
151
+ $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
152
+ $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
153
+
154
+ $conditions = parent::build_sql_conditions($args);
155
+ //eventful locations
156
+ if( true == $args['eventful'] ){
157
+ $conditions['eventful'] = "{$events_table}.event_id IS NOT NULL";
158
+ }elseif( true == $args['eventless'] ){
159
+ $conditions['eventless'] = "{$events_table}.event_id IS NULL";
160
+ }
161
+ //owner lookup
162
+ if( !empty($args['owner']) ){
163
+ if ( get_option('dbem_permissions_locations') < 1 && !em_verify_admin() ){
164
+ $conditions['owner'] = "location_owner=".get_current_user_id();
165
+ }
166
+ }
167
+ return apply_filters('em_locations_build_sql_conditions', $conditions, $args);
168
+ }
169
+
170
+ /* Overrides EM_Object method to apply a filter to result
171
+ * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
172
+ */
173
+ function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
174
+ return apply_filters( 'em_locations_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')), $args, $accepted_fields, $default_order );
175
+ }
176
+
177
+ /*
178
+ * Generate a search arguments array from defalut and user-defined.
179
+ * @see wp-content/plugins/events-manager/classes/EM_Object::get_default_search()
180
+ */
181
+ function get_default_search($array = array()){
182
+ $defaults = array(
183
+ 'eventful' => false, //Locations that have an event (scope will also play a part here
184
+ 'eventless' => false, //Locations WITHOUT events, eventful takes precedence
185
+ 'orderby' => 'name',
186
+ 'scope' => 'all' //we probably want to search all locations by default, not like events
187
+ );
188
+ $array['eventful'] = ( !empty($array['eventful']) && $array['eventful'] == true );
189
+ $array['eventless'] = ( !empty($array['eventless']) && $array['eventless'] == true );
190
+ if( is_admin() ){
191
+ //by default, we only get categories the owner can manage
192
+ switch( get_option('dbem_permissions_locations') ){
193
+ case 0:
194
+ $defaults['owner'] = get_current_user_id();
195
+ break;
196
+ case 1:
197
+ $wp_user_search = new WP_User_Search(null, null, 'administrator');
198
+ $users = $wp_user_search->get_results();
199
+ $users[] = get_current_user_id();
200
+ $users[] = 0;
201
+ $defaults['owner'] = implode(',', $users);
202
+ break;
203
+ case 2:
204
+ $defaults['owner'] = false;
205
+ break;
206
+ }
207
+ $defaults['owner'] = ( em_verify_admin() ) ? false:$defaults['owner'];
208
+ }
209
+ return apply_filters('em_locations_get_default_search', parent::get_default_search($defaults, $array), $array, $defaults);
210
+ }
211
+ //TODO for all the static plural classes like this one, we might benefit from bulk actions like delete/add/save etc.... just a random thought.
212
+ }
 
 
 
 
 
 
 
 
213
  ?>
classes/em-mailer.php CHANGED
@@ -1,80 +1,80 @@
1
- <?php
2
- /**
3
- * phpmailer support
4
- *
5
- */
6
- class EM_Mailer {
7
-
8
- /**
9
- * if any errors crop up, here they are
10
- * @var array
11
- */
12
- var $errors = array();
13
-
14
- /**
15
- * @param $subject
16
- * @param $body
17
- * @param $receiver
18
- */
19
- function send($subject="no title",$body="No message specified", $receiver='') {
20
- //TODO add an EM_Error global object, for this sort of error reporting. (@marcus like StatusNotice)
21
- global $smtpsettings, $phpmailer, $cformsSettings;
22
-
23
- if( preg_match('/^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$/i', $receiver) ){
24
- $this->load_phpmailer();
25
- $mail = new EM_PHPMailer();
26
- //$mail->SMTPDebug = true;
27
- $mail->ClearAllRecipients();
28
- $mail->ClearAddresses();
29
- $mail->ClearAttachments();
30
- $mail->CharSet = 'utf-8';
31
- $mail->SetLanguage('en', dirname(__FILE__).'/');
32
- $mail->PluginDir = dirname(__FILE__).'/phpmailer/';
33
- $mail->Host = get_option('dbem_smtp_host');
34
- $mail->port = get_option('dbem_rsvp_mail_port');
35
- $mail->Username = get_option('dbem_smtp_username');
36
- $mail->Password = get_option('dbem_smtp_password');
37
- $mail->From = get_option('dbem_mail_sender_address');
38
- $mail->FromName = get_option('dbem_mail_sender_name'); // This is the from name in the email, you can put anything you like here
39
- $mail->Body = $body;
40
- $mail->Subject = $subject;
41
- $mail->AddAddress($receiver);
42
-
43
- //Protocols
44
- if ( get_option('dbem_rsvp_mail_send_method') == 'wp_mail' ){
45
- $mail->Mailer = 'wp_mail';
46
- $send = wp_mail($receiver, $subject, $body);
47
- if(!$send){
48
- global $phpmailer;
49
- $this->errors[] = $phpmailer->ErrorInfo;
50
- }
51
- }else{
52
- if( get_option('dbem_rsvp_mail_send_method') == 'qmail' ){
53
- $mail->IsQmail();
54
- }else {
55
- $mail->Mailer = get_option('dbem_rsvp_mail_send_method');
56
- }
57
- if(get_option('dbem_rsvp_mail_SMTPAuth') == '1'){
58
- $mail->SMTPAuth = TRUE;
59
- }
60
- $send = $mail->Send();
61
- if(!$send){
62
- $this->errors[] = $mail->ErrorInfo;
63
- }
64
- }
65
- return $send;
66
- }else{
67
- $this->errors = __('Please supply a valid email format.', 'dbem');
68
- return false;
69
- }
70
- }
71
-
72
- /**
73
- * load phpmailer classes
74
- */
75
- function load_phpmailer(){
76
- require_once(dirname(__FILE__) . '/phpmailer/class.phpmailer.php');
77
- require_once(dirname(__FILE__) . '/phpmailer/class.smtp.php');
78
- }
79
- }
80
  ?>
1
+ <?php
2
+ /**
3
+ * phpmailer support
4
+ *
5
+ */
6
+ class EM_Mailer {
7
+
8
+ /**
9
+ * if any errors crop up, here they are
10
+ * @var array
11
+ */
12
+ var $errors = array();
13
+
14
+ /**
15
+ * @param $subject
16
+ * @param $body
17
+ * @param $receiver
18
+ */
19
+ function send($subject="no title",$body="No message specified", $receiver='') {
20
+ //TODO add an EM_Error global object, for this sort of error reporting. (@marcus like StatusNotice)
21
+ global $smtpsettings, $phpmailer, $cformsSettings;
22
+
23
+ if( preg_match('/^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$/i', $receiver) ){
24
+ $this->load_phpmailer();
25
+ $mail = new EM_PHPMailer();
26
+ //$mail->SMTPDebug = true;
27
+ $mail->ClearAllRecipients();
28
+ $mail->ClearAddresses();
29
+ $mail->ClearAttachments();
30
+ $mail->CharSet = 'utf-8';
31
+ $mail->SetLanguage('en', dirname(__FILE__).'/');
32
+ $mail->PluginDir = dirname(__FILE__).'/phpmailer/';
33
+ $mail->Host = get_option('dbem_smtp_host');
34
+ $mail->port = get_option('dbem_rsvp_mail_port');
35
+ $mail->Username = get_option('dbem_smtp_username');
36
+ $mail->Password = get_option('dbem_smtp_password');
37
+ $mail->From = get_option('dbem_mail_sender_address');
38
+ $mail->FromName = get_option('dbem_mail_sender_name'); // This is the from name in the email, you can put anything you like here
39
+ $mail->Body = $body;
40
+ $mail->Subject = $subject;
41
+ $mail->AddAddress($receiver);
42
+
43
+ //Protocols
44
+ if ( get_option('dbem_rsvp_mail_send_method') == 'wp_mail' ){
45
+ $mail->Mailer = 'wp_mail';
46
+ $send = wp_mail($receiver, $subject, $body);
47
+ if(!$send){
48
+ global $phpmailer;
49
+ $this->errors[] = $phpmailer->ErrorInfo;
50
+ }
51
+ }else{
52
+ if( get_option('dbem_rsvp_mail_send_method') == 'qmail' ){
53
+ $mail->IsQmail();
54
+ }else {
55
+ $mail->Mailer = get_option('dbem_rsvp_mail_send_method');
56
+ }
57
+ if(get_option('dbem_rsvp_mail_SMTPAuth') == '1'){
58
+ $mail->SMTPAuth = TRUE;
59
+ }
60
+ $send = $mail->Send();
61
+ if(!$send){
62
+ $this->errors[] = $mail->ErrorInfo;
63
+ }
64
+ }
65
+ return $send;
66
+ }else{
67
+ $this->errors = __('Please supply a valid email format.', 'dbem');
68
+ return false;
69
+ }
70
+ }
71
+
72
+ /**
73
+ * load phpmailer classes
74
+ */
75
+ function load_phpmailer(){
76
+ require_once(dirname(__FILE__) . '/phpmailer/class.phpmailer.php');
77
+ require_once(dirname(__FILE__) . '/phpmailer/class.smtp.php');
78
+ }
79
+ }
80
  ?>
classes/em-map.php CHANGED
@@ -1,60 +1,60 @@
1
- <?php
2
- /**
3
- * Obtains the html required to display a google map for given location(s)
4
- *
5
- */
6
- class EM_Map extends EM_Object {
7
- /**
8
- * Shortcode for producing a google map with all the locations. Unfinished and undocumented.
9
- * @param array $atts
10
- * @return string
11
- */
12
- function get_global($atts) {
13
- //TODO Finish and document this feature, need to add balloons here
14
- if (get_option('dbem_gmap_is_active') == '1') {
15
- ob_start();
16
- $atts['em_ajax'] = true;
17
- $atts['query'] = 'GlobalMapData';
18
- $rand = substr(md5(rand().rand()),0,5);
19
- //build js array of arguments to send to event query
20
- ?>
21
- <div class='em-locations-map' id='em-locations-map-<?php echo $rand; ?>' style='width:<?php echo $atts['width']; ?>px; height:<?php echo $atts['height']; ?>px'><em><?php _e('Loading Map....', 'dbem'); ?></em></div>
22
- <div class='em-locations-map-coords' id='em-locations-map-coords-<?php echo $rand; ?>' style="display:none; visibility:hidden;"><?php echo EM_Object::json_encode($atts); ?></div>
23
- <?php
24
- return apply_filters('em_map_get_global', ob_get_clean());
25
- }else{
26
- return '';
27
- }
28
- }
29
-
30
-
31
- /**
32
- * Returns th HTML and JS required to produce a google map in for this location.
33
- * @param EM_Location $location
34
- * @return string
35
- */
36
- function get_single($args) {
37
- //TODO do some validation here of defaults
38
- //FIXME change baloon to balloon for consistent spelling
39
- $location = $args['location'];
40
- if ( get_option('dbem_gmap_is_active') && ( is_object($location) && $location->latitude != 0 && $location->longitude != 0 ) ) {
41
- $width = (isset($args['width'])) ? $args['width']:'400';
42
- $height = (isset($args['height'])) ? $args['height']:'300';
43
- ob_start();
44
- $rand = substr(md5(rand().rand()),0,5);
45
- ?>
46
- <div class='em-location-map' id='em-location-map-<?php echo $rand ?>' style='background: #CDCDCD; width: <?php echo $width ?>px; height: <?php echo $height ?>px'><?php _e('Loading Map....', 'dbem'); ?></div>
47
- <div class='em-location-map-info' id='em-location-map-info-<?php echo $rand ?>' style="display:none; visibility:hidden;"><div class="em-map-balloon" style="font-size:12px;"><div class="em-map-balloon-content" ><?php echo $location->output(get_option('dbem_location_baloon_format')); ?></div></div></div>
48
- <div class='em-location-map-coords' id='em-location-map-coords-<?php echo $rand ?>' style="display:none; visibility:hidden;">
49
- <span class="lat"><?php echo $location->latitude; ?></span>
50
- <span class="lng"><?php echo $location->longitude; ?></span>
51
- </div>
52
- <?php
53
- return ob_get_clean();
54
- }elseif( is_object($location) && $location->latitude == 0 && $location->longitude == 0 ){
55
- return '<i>'. __('Map Unavailable', 'dbem') .'</i>';
56
- }else{
57
- return '';
58
- }
59
- }
60
  }
1
+ <?php
2
+ /**
3
+ * Obtains the html required to display a google map for given location(s)
4
+ *
5
+ */
6
+ class EM_Map extends EM_Object {
7
+ /**
8
+ * Shortcode for producing a google map with all the locations. Unfinished and undocumented.
9
+ * @param array $atts
10
+ * @return string
11
+ */
12
+ function get_global($atts) {
13
+ //TODO Finish and document this feature, need to add balloons here
14
+ if (get_option('dbem_gmap_is_active') == '1') {
15
+ ob_start();
16
+ $atts['em_ajax'] = true;
17
+ $atts['query'] = 'GlobalMapData';
18
+ $rand = substr(md5(rand().rand()),0,5);
19
+ //build js array of arguments to send to event query
20
+ ?>
21
+ <div class='em-locations-map' id='em-locations-map-<?php echo $rand; ?>' style='width:<?php echo $atts['width']; ?>px; height:<?php echo $atts['height']; ?>px'><em><?php _e('Loading Map....', 'dbem'); ?></em></div>
22
+ <div class='em-locations-map-coords' id='em-locations-map-coords-<?php echo $rand; ?>' style="display:none; visibility:hidden;"><?php echo EM_Object::json_encode($atts); ?></div>
23
+ <?php
24
+ return apply_filters('em_map_get_global', ob_get_clean());
25
+ }else{
26
+ return '';
27
+ }
28
+ }
29
+
30
+
31
+ /**
32
+ * Returns th HTML and JS required to produce a google map in for this location.
33
+ * @param EM_Location $location
34
+ * @return string
35
+ */
36
+ function get_single($args) {
37
+ //TODO do some validation here of defaults
38
+ //FIXME change baloon to balloon for consistent spelling
39
+ $location = $args['location'];
40
+ if ( get_option('dbem_gmap_is_active') && ( is_object($location) && $location->latitude != 0 && $location->longitude != 0 ) ) {
41
+ $width = (isset($args['width'])) ? $args['width']:'400';
42
+ $height = (isset($args['height'])) ? $args['height']:'300';
43
+ ob_start();
44
+ $rand = substr(md5(rand().rand()),0,5);
45
+ ?>
46
+ <div class='em-location-map' id='em-location-map-<?php echo $rand ?>' style='background: #CDCDCD; width: <?php echo $width ?>px; height: <?php echo $height ?>px'><?php _e('Loading Map....', 'dbem'); ?></div>
47
+ <div class='em-location-map-info' id='em-location-map-info-<?php echo $rand ?>' style="display:none; visibility:hidden;"><div class="em-map-balloon" style="font-size:12px;"><div class="em-map-balloon-content" ><?php echo $location->output(get_option('dbem_location_baloon_format')); ?></div></div></div>
48
+ <div class='em-location-map-coords' id='em-location-map-coords-<?php echo $rand ?>' style="display:none; visibility:hidden;">
49
+ <span class="lat"><?php echo $location->latitude; ?></span>
50
+ <span class="lng"><?php echo $location->longitude; ?></span>
51
+ </div>
52
+ <?php
53
+ return ob_get_clean();
54
+ }elseif( is_object($location) && $location->latitude == 0 && $location->longitude == 0 ){
55
+ return '<i>'. __('Map Unavailable', 'dbem') .'</i>';
56
+ }else{
57
+ return '';
58
+ }
59
+ }
60
  }
classes/em-notices.php DELETED
@@ -1,170 +0,0 @@
1
- <?php
2
- /**
3
- *
4
- * @author marcus
5
- *
6
- */
7
- class EM_Notices implements Iterator {
8
- var $notices = array('errors'=>array(), 'infos'=>array(), 'alerts'=>array(), 'confirms'=>array());
9
-
10
- function __construct(){
11
- //Grab from session
12
- if( !empty($_SESSION['events']['notices']) && is_serialized($_SESSION['events']['notices']) ){
13
- $this->notices = unserialize($_SESSION['events']['notices']);
14
- }
15
- //Flush notices that weren't made to stay cross-requests, we can do this if initialized immediately.
16
- foreach($this->notices as $notice_type => $notices){
17
- foreach ($notices as $key => $notice){
18
- if( empty($notice['static']) ){
19
- unset($this->notices[$notice_type][$key]);
20
- }else{
21
- unset($this->notices[$notice_type][$key]['static']); //so it gets removed next request
22
- }
23
- }
24
- }
25
- add_action('shutdown', array(&$this,'flush_notices'));
26
- }
27
-
28
- function flush_notices(){
29
- $_SESSION['events']['notices'] = serialize($this->notices);
30
- }
31
-
32
- function __toString(){
33
- $string = false;
34
- if(count($this->notices['errors']) > 0){
35
- $string .= "<div class='em-warning em-warning-errors error'>{$this->get_errors()}</div>";
36
- }
37
- if(count($this->notices['alerts']) > 0){
38
- $string .= "<div class='em-warning em-warning-alerts updated'>{$this->get_alerts()}</div>";
39
- }
40
- if(count($this->notices['infos']) > 0){
41
- $string .= "<div class='em-warning em-warning-infos updated'>{$this->get_infos()}</div>";
42
- }
43
- if(count($this->notices['confirms']) > 0){
44
- $string .= "<div class='em-warning em-warning-confirms updated'>{$this->get_confirms()}</div>";
45
- }
46
- return ($string !== false) ? "<div class='statusnotice'>".$string."</div>" : '';
47
- }
48
-
49
- /* General */
50
- function add($string, $type, $static = false){
51
- if( is_array($string) ){
52
- $result = true;
53
- foreach($string as $string_item){
54
- if( $this->add($string_item, $type, $static) === false ){ $result = false; }
55
- }
56
- return $result;
57
- }
58
- if($string != ''){
59
- if( isset($this->notices[$type]) ){
60
- foreach( $this->notices[$type] as $notice_key => $notice ){
61
- if($string == $notice['string']){
62
- return $notice_key;
63
- }
64
- }
65
- $i = key($this->notices[$type])+1;
66
- $this->notices[$type][$i]['string'] = $string;
67
- if( $static ){
68
- $this->notices[$type][$i]['static'] = true;
69
- }
70
- return $i;
71
- }else{
72
- return false;
73
- }
74
- }else{
75
- return false;
76
- }
77
- }
78
- function remove($key, $type){
79
- if( isset($this->notices[$type]) ){
80
- unset($this->notices[$type][$key]);
81
- return true;
82
- }else{
83
- return false;
84
- }
85
- }
86
- function get($type){
87
- if( isset($this->notices[$type]) ){
88
- foreach ($this->notices[$type] as $key => $error){
89
- $class = substr($type, 0, (strlen($type)-1));
90
- $string .= "<p>{$error['string']}</p>";
91
- if($error['static'] !== true){
92
- $this->remove($key, $type);
93
- }
94
- }
95
- return $string;
96
- }else{
97
- return false;
98
- }
99
- }
100
-
101
- /* Errors */
102
- function add_error($string, $static=false){
103
- return $this->add($string, 'errors', $static);
104
- }
105
- function remove_error($key){
106
- return $this->remove($key, 'errors');
107
- }
108
- function get_errors(){
109
- return $this->get('errors');
110
- }
111
-
112
- /* Alerts */
113
- function add_alert($string, $static=false){
114
- return $this->add($string, 'alerts', $static);
115
- }
116
- function remove_alert($key){
117
- return $this->remove($key, 'alerts');
118
- }
119
- function get_alerts(){
120
- return $this->get('alerts');
121
- }
122
-
123
- /* Info */
124
- function add_info($string, $static=false){
125
- return $this->add($string, 'infos', $static);
126
- }
127
- function remove_info($key){
128
- return $this->remove($key, 'infos');
129
- }
130
- function get_infos(){
131
- return $this->get('infos');
132
- }
133
-
134
- /* Confirms */
135
- function add_confirm($string, $static=false){
136
- return $this->add($string, 'confirms', $static);
137
- }
138
- function remove_confirm($key){
139
- return $this->remove($key, 'confirms');
140
- }
141
- function get_confirms(){
142
- return $this->get('confirms');
143
- }
144
-
145
- //Iterator Implementation
146
- function rewind(){
147
- reset($this->bookings);
148
- }
149
- function current(){
150
- $var = current($this->bookings);
151
- return $var;
152
- }
153
- function key(){
154
- $var = key($this->bookings);
155
- return $var;
156
- }
157
- function next(){
158
- $var = next($this->bookings);
159
- return $var;
160
- }
161
- function valid(){
162
- $key = key($this->bookings);
163
- $var = ($key !== NULL && $key !== FALSE);
164
- return $var;
165
- }
166
-
167
- }
168
- global $EM_Notices;
169
- $EM_Notices = new EM_Notices();
170
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/em-object.php CHANGED
@@ -1,554 +1,486 @@
1
- <?php
2
- /**
3
- * Base class which others extend on. Contains functions shared across all EM objects.
4
- *
5
- */
6
- class EM_Object {
7
- var $fields = array();
8
- var $required_fields = array();
9
- var $feedback_message = "";
10
- var $errors = array();
11
-
12
- /**
13
- * Takes the array and provides a clean array of search parameters, along with details
14
- * @param array $defaults
15
- * @param array $array
16
- * @return array
17
- */
18
- function get_default_search($defaults=array(), $array = array()){
19
- global $wpdb;
20
- //TODO accept all objects as search options as well as ids (e.g. location vs. location_id, person vs. person_id)
21
- //Create minimal defaults array, merge it with supplied defaults array
22
- $super_defaults = array(
23
- 'limit' => false,
24
- 'scope' => 'future',
25
- 'order' => 'ASC', //hard-coded at end of this function
26
- 'orderby' => false,
27
- 'format' => '',
28
- 'category' => 0,
29
- 'location' => 0,
30
- 'event' => 0,
31
- 'offset'=>0,
32
- 'page'=>1,//basically, if greater than 0, calculates offset at end
33
- 'recurrence'=>0,
34
- 'recurring'=>false,
35
- 'month'=>'',
36
- 'year'=>'',
37
- 'pagination'=>false,
38
- 'array'=>false,
39
- 'owner'=>false,
40
- 'rsvp'=>false,
41
- 'search'=>false
42
- );
43
- //Return default if nothing passed
44
- if( empty($defaults) && empty($array) ){
45
- return $super_defaults;
46
- }
47
- //TODO decide on search defaults shared across all objects and then validate here
48
- $defaults = array_merge($super_defaults, $defaults);
49
-
50
- //We are still dealing with recurrence_id, location_id, category_id in some place, so we do a quick replace here just in case
51
- if( array_key_exists('recurrence_id', $array) && !array_key_exists('recurrence', $array) ) { $array['recurrence'] = $array['recurrence_id']; }
52
- if( array_key_exists('location_id', $array) && !array_key_exists('location', $array) ) { $array['location'] = $array['location_id']; }
53
- if( array_key_exists('category_id', $array) && !array_key_exists('category', $array) ) { $array['category'] = $array['category_id']; }
54
-
55
- if(is_array($array)){
56
- //Clean all id lists
57
- $array = self::clean_id_atts($array, array('location', 'event', 'category'));
58
-
59
- //OrderBy - can be a comma-seperated array of field names to order by (field names of object, not db)
60
- if( array_key_exists('orderby', $array)){
61
- if( !is_array($array['orderby']) && preg_match('/,/', $array['orderby']) ) {
62
- $array['orderby'] = explode(',', $array['orderby']);
63
- }
64
- }
65
- //TODO validate search query array
66
- //Clean the supplied array, so we only have allowed keys
67
- foreach( array_keys($array) as $key){
68
- if( !array_key_exists($key, $defaults) ) unset($array[$key]);
69
- }
70
- //return clean array
71
- $defaults = array_merge ( $defaults, $array ); //No point using WP's cleaning function, we're doing it already.
72
- }
73
- //Do some spring cleaning for known values
74
- //Month & Year - may be array or single number
75
- $month_regex = '/^[0-9]{1,2}$/';
76
- $year_regex = '/^[0-9]{4}$/';
77
- if( is_array($defaults['month']) ){
78
- $defaults['month'] = ( preg_match($month_regex, $defaults['month'][0]) && preg_match($month_regex, $defaults['month'][1]) ) ? $defaults['month']:'';
79
- }else{
80
- $defaults['month'] = preg_match($month_regex, $defaults['month']) ? $defaults['month']:'';
81
- }
82
- if( is_array($defaults['year']) ){
83
- $defaults['year'] = ( preg_match($year_regex, $defaults['year'][0]) && preg_match($year_regex, $defaults['year'][1]) ) ? $defaults['year']:'';
84
- }else{
85
- $defaults['year'] = preg_match($year_regex, $defaults['year']) ? $defaults['year']:'';
86
- }
87
- //Order - it's either ASC or DESC, so let's just validate
88
- if( !is_array($defaults['order']) && preg_match('/,/', $defaults['order']) ) {
89
- $defaults['order'] = explode(',', $defaults['order']);
90
- }elseif( !in_array($defaults['order'], array('ASC','DESC')) ){
91
- $defaults['order'] = $super_defaults['order'];
92
- }
93
- //ORDER BY, split if an array
94
- if( !is_array($defaults['orderby']) && preg_match('/,/', $defaults['orderby']) ) {
95
- $defaults['orderby'] = explode(',', $defaults['orderby']);
96
- }
97
- //TODO should we clean format of malicious code over here and run everything thorugh this?
98
- $defaults['array'] = ($defaults['array'] == true);
99
- $defaults['pagination'] = ($defaults['pagination'] == true);
100
- $defaults['limit'] = (is_numeric($defaults['limit'])) ? $defaults['limit']:$super_defaults['limit'];
101
- $defaults['offset'] = (is_numeric($defaults['offset'])) ? $defaults['offset']:$super_defaults['offset'];
102
- $defaults['recurring'] = ($defaults['recurring'] == true);
103
- $defaults['owner'] = (is_numeric($defaults['owner'])) ? $defaults['owner']:$super_defaults['owner'];
104
- $defaults['search'] = ($defaults['search']) ? $wpdb->escape(like_escape($defaults['search'])):false;
105
- //Calculate offset in event page is set
106
- if($defaults['page'] > 1){
107
- $defaults['offset'] = $defaults['limit'] * ($defaults['page']-1);
108
- }else{
109
- $defaults['page'] = ($defaults['limit'] > 0 ) ? floor($defaults['offset']/$defaults['limit']) + 1 : 1;
110
- }
111
- return apply_filters('em_object_get_default_search', $defaults, $array, $super_defaults);
112
- }
113
-
114
- /**
115
- * Builds an array of SQL query conditions based on regularly used arguments
116
- * @param array $args
117
- * @return array
118
- */
119
- function build_sql_conditions( $args = array() ){
120
- global $wpdb;
121
- $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
122
- $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
123
-
124
- $args = apply_filters('em_object_build_sql_conditions_args',$args);
125
-
126
- //Format the arguments passed on
127
- $scope = $args['scope'];//undefined variable warnings in ZDE, could just delete this (but dont pls!)
128
- $recurring = $args['recurring'];
129
- $recurrence = $args['recurrence'];
130
- $category = $args['category'];
131
- $location = $args['location'];
132
- $rsvp = $args['rsvp'];
133
- $owner = $args['owner'];
134
- $event = $args['event'];
135
- $month = $args['month'];
136
- $year = $args['year'];
137
- $today = date('Y-m-d', current_time('timestamp'));
138
- //Create the WHERE statement
139
-
140
- //Recurrences
141
- $conditions = array();
142
- if( $recurring ){
143
- $conditions['recurring'] = "`recurrence`=1";
144
- }elseif( $recurrence > 0 ){
145
- $conditions['recurrence'] = "`recurrence_id`=$recurrence";
146
- }else{
147
- $conditions['recurring'] = "(`recurrence`!=1 OR `recurrence` IS NULL)";
148
- }
149
- //Dates - first check 'month', and 'year', and adjust scope if needed
150
- if( !($month=='' && $year=='') ){
151
- //Sort out month range, if supplied an array of array(month,month), it'll check between these two months
152
- if( self::array_is_numeric($month) ){
153
- $date_month_start = $month[0];
154
- $date_month_end = $month[1];
155
- }else{
156
- $date_month_start = $date_month_end = $month;
157
- }
158
- //Sort out year range, if supplied an array of array(year,year), it'll check between these two years
159
- if( self::array_is_numeric($year) ){
160
- $date_year_start = $year[0];
161
- $date_year_end = $year[1];
162
- }else{
163
- $date_year_start = $date_year_end = $year;
164
- }
165
- $date_start = $date_year_start."-".$date_month_start."-01";
166
- $date_end = date('Y-m-t', mktime(0,0,0,$date_month_end,1,$date_year_end));
167
- $scope = "$date_start,$date_end"; //just modify the scope here
168
- }
169
- //No date requested, so let's look at scope
170
- if ( preg_match ( "/^[0-9]{4}-[0-9]{2}-[0-9]{2},[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $scope ) ) {
171
- //This is an array, let's split it up
172
- $dates = explode(',', $scope);
173
- $date_start = $dates[0];
174
- $date_end = $dates[1];
175
- $conditions['scope'] = " ( ( event_start_date <= CAST('$date_end' AS DATE) AND event_end_date >= CAST('$date_start' AS DATE) ) OR (event_start_date BETWEEN CAST('$date_start' AS DATE) AND CAST('$date_end' AS DATE)) OR (event_end_date BETWEEN CAST('$date_start' AS DATE) AND CAST('$date_end' AS DATE)) )";
176
- } elseif ( preg_match ( "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $scope ) ) {
177
- //Scope can also be a specific date. However, if 'day', 'month', or 'year' are set, that will take precedence
178
- $conditions['scope'] = " ( event_start_date = CAST('$scope' AS DATE) OR ( event_start_date <= CAST('$scope' AS DATE) AND event_end_date >= CAST('$scope' AS DATE) ) )";
179
- } else {
180
- if ($scope == "past"){
181
- $conditions['scope'] = " event_start_date < '$today'";
182
- }elseif ($scope == "today"){
183
- $conditions['scope'] = " ( (event_start_date = CAST('$today' AS DATE)) OR (event_start_date <= CAST('$today' AS DATE) AND event_end_date >= CAST('$today' AS DATE)) )";
184
- }elseif ($scope == "future"){
185
- $conditions['scope'] = " (event_start_date >= CAST('$today' AS DATE) OR (event_end_date >= CAST('$today' AS DATE) AND event_end_date != '0000-00-00' AND event_end_date IS NOT NULL))";
186
- }
187
- }
188
-
189
- //Filter by Location - can be object, array, or id
190
- if ( is_numeric($location) && $location > 0 ) { //Location ID takes precedence
191
- $conditions['location'] = " {$locations_table}.location_id = $location";
192
- }elseif ( self::array_is_numeric($location) ){
193
- $conditions['location'] = "( {$locations_table}.location_id = " . implode(" OR {$locations_table}.location_id = ", $location) .' )';
194
- }elseif ( is_object($location) && get_class($location)=='EM_Location' ){ //Now we deal with objects
195
- $conditions['location'] = " {$locations_table}.location_id = $location->id";
196
- }elseif ( is_array($location) && @get_class(current($location)=='EM_Location') ){ //we can accept array of ids or EM_Location objects
197
- foreach($location as $EM_Location){
198
- $location_ids[] = $EM_Location->id;
199
- }
200
- $conditions['location'] = "( {$locations_table}.location_id=". implode(" {$locations_table}.location_id=", $location_ids) ." )";
201
- }
202
-
203
- //Filter by Event - can be object, array, or id
204
- if ( is_numeric($event) && $event > 0 ) { //event ID takes precedence
205
- $conditions['event'] = " {$events_table}.event_id = $event";
206
- }elseif ( self::array_is_numeric($event) ){ //array of ids
207
- $conditions['event'] = "( {$events_table}.event_id = " . implode(" OR {$events_table}.event_id = ", $event) .' )';
208
- }elseif ( is_object($event) && get_class($event)=='EM_Event' ){ //Now we deal with objects
209
- $conditions['event'] = " {$events_table}.event_id = $event->id";
210
- }elseif ( is_array($event) && @get_class(current($event)=='EM_Event') ){ //we can accept array of ids or EM_event objects
211
- foreach($event as $EM_Event){
212
- $event_ids[] = $EM_Event->id;
213
- }
214
- $conditions['event'] = "( {$events_table}.event_id=". implode(" {$events_table}.event_id=", $event_ids) ." )";
215
- }
216
-
217
- //Add conditions for category selection
218
- //Filter by category, can be id or comma seperated ids
219
- //TODO create an exclude category option
220
- if ( is_numeric($category) && $category > 0 ){
221
- $conditions['category'] = " event_category_id = $category";
222
- }elseif( self::array_is_numeric($category) ){
223
- $conditions['category'] = "( event_category_id = ". implode(' OR event_category_id = ', $category).")";
224
- }
225
-
226
- //If we want rsvped items, we usually check the event
227
- if( $rsvp == 1 ){
228
- $conditions['rsvp'] = 'event_rsvp=1';
229
- }
230
- //Default ownership belongs to an event, child objects can just overwrite this if needed.
231
- if( is_numeric($owner) ){
232
- $conditions['owner'] = 'event_owner='.$owner;
233
- }
234
- return apply_filters('em_object_build_sql_conditions', $conditions);
235
- }
236
-
237
- function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
238
- //First, ORDER BY
239
- $args = apply_filters('em_object_build_sql_orderby_args', $args);
240
- $orderby = array();
241
- if(is_array($args['orderby'])){
242
- //Clean orderby array so we only have accepted values
243
- foreach( $args['orderby'] as $key => $field ){
244
- if( array_key_exists($field, $accepted_fields) ){
245
- $orderby[] = $accepted_fields[$field];
246
- }elseif( in_array($field,$accepted_fields) ){
247
- $orderby[] = $field;
248
- }else{
249
- unset($args['orderby'][$key]);
250
- }
251
- }
252
- }elseif( $args['orderby'] != '' && array_key_exists($args['orderby'], $accepted_fields) ){
253
- $orderby[] = $accepted_fields[$args['orderby']];
254
- }elseif( $args['orderby'] != '' && in_array($args['orderby'], $accepted_fields) ){
255
- $orderby[] = $args['orderby'];
256
- }
257
- //ORDER
258
- //If order is an array, we'll go through the orderby array and match the order values (in order of array) with orderby values
259
- //If orders don't match up, or it's not ASC/DESC, the default events search in EM settings/options page will be used.
260
- foreach($orderby as $i => $field){
261
- $orderby[$i] .= ' ';
262
- if(is_array($args['order'])){
263
- if( in_array($args['order'][$i], array('ASC','DESC')) ){
264
- $orderby[$i] .= $args['order'][$i];
265
- }else{
266
- $orderby[$i] .= $default_order;
267
- }
268
- }else{
269
- $orderby[$i] .= ( in_array($args['order'], array('ASC','DESC')) ) ? $args['order'] : $default_order;
270
- }
271
- }
272
- return apply_filters('em_object_build_sql_orderby', $orderby);
273
- }
274
-
275
- /**
276
- * Used by "single" objects, e.g. bookings, events, locations to verify if they have the capability to edit this or someone else's object. Relies on the fact that the object has an owner property with id of user (or admin capability must pass).
277
- * @param string $owner_capability If the object has an owner property and the user id matches that, this capability will be checked for.
278
- * @param string $admin_capability If the user isn't the owner of the object, this capability will be checked for.
279
- * @return boolean
280
- */
281
- function can_manage( $owner_capability = false, $admin_capability = false ){
282
- global $em_capabilities_array;
283
- //do they own this?
284
- $is_owner = ( $this->owner == get_current_user_id() || empty($this->id) );
285
- //now check capability
286
- $can_manage = false;
287
- if( $is_owner && current_user_can($owner_capability) ){
288
- $can_manage = true;
289
- }elseif( $is_owner && array_key_exists($owner_capability, $em_capabilities_array) ){
290
- $error_msg = $em_capabilities_array[$owner_capability];
291
- }
292
- if( !$is_owner && current_user_can($admin_capability) ){
293
- $can_manage = true;
294
- }elseif( !$is_owner && array_key_exists($admin_capability, $em_capabilities_array) ){
295
- $error_msg = $em_capabilities_array[$admin_capability];
296
- }
297
- if( !$can_manage ){
298
- $this->add_error($error_msg);
299
- }
300
- return $can_manage;
301
- }
302
-
303
- /**
304
- * Save an array into this class.
305
- * If you provide a record from the database table corresponding to this class type it will add the data to this object.
306
- * @param array $array
307
- * @return null
308
- */
309
- function to_object( $array = array(), $addslashes = false ){
310
- //Save core data
311
- if( is_array($array) ){
312
- $array = apply_filters('em_to_object', $array);
313
- foreach ( $this->fields as $key => $val ) {
314
- if(array_key_exists($key, $array)){
315
- if( !is_object($array[$key]) && !is_array($array[$key]) ){
316
- $array[$key] = ($addslashes) ? stripslashes($array[$key]):$array[$key];
317
- }
318
- $this->$val['name'] = $array[$key];
319
- }
320
- }
321
- }
322
- }
323
-
324
- /**
325
- * Returns this object in the form of an array, useful for saving directly into a database table.
326
- * @return array
327
- */
328
- function to_array($db = false){
329
- $array = array();
330
- foreach ( $this->fields as $key => $val ) {
331
- if($db){
332
- if( !empty($this->$val['name']) || empty($val['null']) ){
333
- $array[$key] = $this->$val['name'];
334
- }
335
- }else{
336
- $array[$key] = $this->$val['name'];
337
- }
338
- }
339
- return apply_filters('em_to_array', $array);
340
- }
341
-
342
-
343
- /**
344
- * Function to retreive wpdb types for all fields, or if you supply an assoc array with field names as keys it'll return an equivalent array of wpdb types
345
- * @param array $array
346
- * @return array:
347
- */
348
- function get_types($array = array()){
349
- $types = array();
350
- if( count($array)>0 ){
351
- //So we look at assoc array and find equivalents
352
- foreach ($array as $key => $val){
353
- $types[] = $this->fields[$key]['type'];
354
- }
355
- }else{
356
- //Blank array, let's assume we're getting a standard list of types
357
- foreach ($this->fields as $field){
358
- $types[] = $field['type'];
359
- }
360
- }
361
- return apply_filters('em_object_get_types', $types, $this, $array);
362
- }
363
-
364
- function get_fields( $inverted_array=false ){
365
- if( is_array($this->fields) ){
366
- $return = array();
367
- foreach($this->fields as $fieldName => $fieldArray){
368
- if($inverted_array){
369
- $return[$fieldArray['name']] = $fieldName;
370
- }else{
371
- $return[$fieldName] = $fieldArray['name'];
372
- }
373
- }
374
- return apply_filters('em_object_get_fields', $return, $this, $inverted_array);
375
- }
376
- return apply_filters('em_object_get_fields', array(), $this, $inverted_array);
377
- }
378
-
379
- /**
380
- * Sanitize text before inserting into database
381
- * @param string $value
382
- * @return string
383
- */
384
- function sanitize( $value ) {
385
- if( get_magic_quotes_gpc() )
386
- $value = stripslashes( $value );
387
-
388
- //check if this function exists
389
- if( function_exists( "mysql_real_escape_string" ) ) {
390
- $value = mysql_real_escape_string( $value );
391
- //for PHP version < 4.3.0 use addslashes
392
- } else {
393
- $value = addslashes( $value );
394
- }
395
- return apply_filters('em_object_sanitize', $value);
396
- }
397
-
398
- /**
399
- * Cleans arrays that contain id lists. Takes an array of items and will clean the keys passed in second argument so that if they keep numbers, explode comma-seperated numbers, and unsets the key if there's any other value
400
- * @param array $array
401
- * @param array $id_atts
402
- */
403
- function clean_id_atts( $array = array(), $id_atts = array() ){
404
- if( is_array($array) && is_array($id_atts) ){
405
- foreach( $array as $key => $string ){
406
- if( in_array($key, $id_atts) ){
407
- //This is in the list of atts we want cleaned
408
- if( is_numeric($string) ){
409
- $array[$key] = (int) $string;
410
- }elseif( self::array_is_numeric($string) ){
411
- $array[$key] = $string;
412
- }elseif( preg_match('/^([0-9],?)+$/', $string) ){
413
- $array[$key] = explode(',', $string);
414
- }else{
415
- //No format we accept
416
- unset($array[$key]);
417
- }
418
- }
419
- }
420
- }
421
- return $array;
422
- }
423
-
424
- /**
425
- * Send an email and log errors in this object
426
- * @param string $subject
427
- * @param string $body
428
- * @param string $email
429
- * @return string
430
- */
431
- function email_send($subject, $body, $email){
432
- global $EM_Mailer;
433
- if( !$EM_Mailer->send($subject,$body,$email) ){
434
- if( is_array($EM_Mailer->errors) ){
435
- foreach($EM_Mailer->errors as $error){
436
- $this->errors[] = $error;
437
- }
438
- }else{
439
- $this->errors[] = $EM_Mailer->errors;
440
- }
441
- return false;
442
- }
443
- return true;
444
- }
445
-
446
- /**
447
- * Will return true if this is a simple (non-assoc) numeric array, meaning it has at one or more numeric entries and nothing else
448
- * @param mixed $array
449
- * @return boolean
450
- */
451
- function array_is_numeric($array){
452
- $results = array();
453
- if(is_array($array)){
454
- foreach($array as $key => $item){
455
- $results[] = (is_numeric($item)&&is_numeric($key));
456
- }
457
- }
458
- return (!in_array(false, $results) && count($results) > 0);
459
- }
460
-
461
- /**
462
- * Returns an array of errors in this object
463
- * @return array
464
- */
465
- function get_errors(){
466
- if(is_array($this->errors)){
467
- return $this->errors;
468
- }else{
469
- return array();
470
- }
471
- }
472
-
473
- /**
474
- * Adds an error to the object
475
- */
476
- function add_error($error){
477
- if(is_array($this->errors)){
478
- if( !in_array($error, $this->errors) ){
479
- $this->errors[] = $error;
480
- }
481
- }else{
482
- $this->errors = array($error);
483
- }
484
- }
485
-
486
- /**
487
- * Converts an array to JSON format, useful for outputting data for AJAX calls. Uses a PHP4 fallback function, given it doesn't support json_encode().
488
- * @param array $array
489
- * @return string
490
- */
491
- function json_encode($array){
492
- if( function_exists("json_encode") ){
493
- $return = json_encode($array);
494
- }else{
495
- $return = self::array_to_json($array);
496
- }
497
- if( isset($_REQUEST['callback']) ){
498
- $return = $_REQUEST['callback']."($return)";
499
- }
500
- return apply_filters('em_object_json_encode', $return, $array);
501
- }
502
-
503
- /**
504
- * Compatible json encoder function for PHP4
505
- * @param array $array
506
- * @return string
507
- */
508
- function array_to_json($array){
509
- //PHP4 Comapatability - This encodes the array into JSON. Thanks go to Andy - http://www.php.net/manual/en/function.json-encode.php#89908
510
- if( !is_array( $array ) ){
511
- $array = array();
512
- }
513
- $associative = count( array_diff( array_keys($array), array_keys( array_keys( $array )) ));
514
- if( $associative ){
515
- $construct = array();
516
- foreach( $array as $key => $value ){
517
- // We first copy each key/value pair into a staging array,
518
- // formatting each key and value properly as we go.
519
- // Format the key:
520
- if( is_numeric($key) ){
521
- $key = "key_$key";
522
- }
523
- $key = "'".addslashes($key)."'";
524
- // Format the value:
525
- if( is_array( $value )){
526
- $value = $this->array_to_json( $value );
527
- }else if( is_bool($value) ) {
528
- $value = ($value) ? "true" : "false";
529
- }else if( !is_numeric( $value ) || is_string( $value ) ){
530
- $value = "'".addslashes($value)."'";
531
- }
532
- // Add to staging array:
533
- $construct[] = "$key: $value";
534
- }
535
- // Then we collapse the staging array into the JSON form:
536
- $result = "{ " . implode( ", ", $construct ) . " }";
537
- } else { // If the array is a vector (not associative):
538
- $construct = array();
539
- foreach( $array as $value ){
540
- // Format the value:
541
- if( is_array( $value )){
542
- $value = $this->array_to_json( $value );
543
- } else if( !is_numeric( $value ) || is_string( $value ) ){
544
- $value = "'".addslashes($value)."'";
545
- }
546
- // Add to staging array:
547
- $construct[] = $value;
548
- }
549
- // Then we collapse the staging array into the JSON form:
550
- $result = "[ " . implode( ", ", $construct ) . " ]";
551
- }
552
- return $result;
553
- }
554
  }
1
+ <?php
2
+ /**
3
+ * Base class which others extend on. Contains functions shared across all EM objects.
4
+ *
5
+ */
6
+ class EM_Object {
7
+
8
+ var $fields = array();
9
+
10
+ /**
11
+ * Takes the array and provides a clean array of search parameters, along with details
12
+ * @param array $defaults
13
+ * @param array $array
14
+ * @return array
15
+ */
16
+ function get_default_search($defaults=array(), $array = array()){
17
+ //TODO accept all objects as search options as well as ids (e.g. location vs. location_id, person vs. person_id)
18
+ //Create minimal defaults array, merge it with supplied defaults array
19
+ $super_defaults = array(
20
+ 'limit' => false,
21
+ 'scope' => 'future',
22
+ 'order' => 'ASC', //hard-coded at end of this function
23
+ 'orderby' => false,
24
+ 'format' => '',
25
+ 'category' => 0,
26
+ 'location' => 0,
27
+ 'event' => 0,
28
+ 'offset'=>0,
29
+ 'page'=>1,//basically, if greater than 0, calculates offset at end
30
+ 'recurrence'=>0,
31
+ 'recurring'=>false,
32
+ 'month'=>'',
33
+ 'year'=>'',
34
+ 'pagination'=>false,
35
+ 'array'=>false,
36
+ 'owner'=>false,
37
+ 'rsvp'=>false
38
+ );
39
+ //Return default if nothing passed
40
+ if( empty($defaults) && empty($array) ){
41
+ return $super_defaults;
42
+ }
43
+ //TODO decide on search defaults shared across all objects and then validate here
44
+ $defaults = array_merge($super_defaults, $defaults);
45
+
46
+ //We are still dealing with recurrence_id, location_id, category_id in some place, so we do a quick replace here just in case
47
+ if( array_key_exists('recurrence_id', $array) && !array_key_exists('recurrence', $array) ) { $array['recurrence'] = $array['recurrence_id']; }
48
+ if( array_key_exists('location_id', $array) && !array_key_exists('location', $array) ) { $array['location'] = $array['location_id']; }
49
+ if( array_key_exists('category_id', $array) && !array_key_exists('category', $array) ) { $array['category'] = $array['category_id']; }
50
+
51
+ if(is_array($array)){
52
+ //Clean all id lists
53
+ $array = self::clean_id_atts($array, array('location', 'event', 'category'));
54
+
55
+ //OrderBy - can be a comma-seperated array of field names to order by (field names of object, not db)
56
+ if( array_key_exists('orderby', $array)){
57
+ if( !is_array($array['orderby']) && preg_match('/,/', $array['orderby']) ) {
58
+ $array['orderby'] = explode(',', $array['orderby']);
59
+ }
60
+ }
61
+ //TODO validate search query array
62
+ //Clean the supplied array, so we only have allowed keys
63
+ foreach( array_keys($array) as $key){
64
+ if( !array_key_exists($key, $defaults) ) unset($array[$key]);
65
+ }
66
+ //return clean array
67
+ $defaults = array_merge ( $defaults, $array ); //No point using WP's cleaning function, we're doing it already.
68
+ }
69
+ //Do some spring cleaning for known values
70
+ //Month & Year - may be array or single number
71
+ $month_regex = '/^[0-9]{1,2}$/';
72
+ $year_regex = '/^[0-9]{4}$/';
73
+ if( is_array($defaults['month']) ){
74
+ $defaults['month'] = ( preg_match($month_regex, $defaults['month'][0]) && preg_match($month_regex, $defaults['month'][1]) ) ? $defaults['month']:'';
75
+ }else{
76
+ $defaults['month'] = preg_match($month_regex, $defaults['month']) ? $defaults['month']:'';
77
+ }
78
+ if( is_array($defaults['year']) ){
79
+ $defaults['year'] = ( preg_match($year_regex, $defaults['year'][0]) && preg_match($year_regex, $defaults['year'][1]) ) ? $defaults['year']:'';
80
+ }else{
81
+ $defaults['year'] = preg_match($year_regex, $defaults['year']) ? $defaults['year']:'';
82
+ }
83
+ //Order - it's either ASC or DESC, so let's just validate
84
+ if( !is_array($defaults['order']) && preg_match('/,/', $defaults['order']) ) {
85
+ $defaults['order'] = explode(',', $defaults['order']);
86
+ }elseif( !in_array($defaults['order'], array('ASC','DESC')) ){
87
+ $defaults['order'] = $super_defaults['order'];
88
+ }
89
+ //ORDER BY, split if an array
90
+ if( !is_array($defaults['orderby']) && preg_match('/,/', $defaults['orderby']) ) {
91
+ $defaults['orderby'] = explode(',', $defaults['orderby']);
92
+ }
93
+ //TODO should we clean format of malicious code over here and run everything thorugh this?
94
+ $defaults['array'] = ($defaults['array'] == true);
95
+ $defaults['pagination'] = ($defaults['pagination'] == true);
96
+ $defaults['limit'] = (is_numeric($defaults['limit'])) ? $defaults['limit']:$super_defaults['limit'];
97
+ $defaults['offset'] = (is_numeric($defaults['offset'])) ? $defaults['offset']:$super_defaults['offset'];
98
+ $defaults['recurring'] = ($defaults['recurring'] == true);
99
+ $defaults['owner'] = (is_numeric($defaults['owner'])) ? $defaults['owner']:$super_defaults['owner'];
100
+ //Calculate offset in event page is set
101
+ if($defaults['page'] > 1){
102
+ $defaults['offset'] = $defaults['limit'] * ($defaults['page']-1);
103
+ }else{
104
+ $defaults['page'] = ($defaults['limit'] > 0 ) ? floor($defaults['offset']/$defaults['limit']) + 1 : 1;
105
+ }
106
+ return apply_filters('em_object_get_default_search', $defaults, $array, $super_defaults);
107
+ }
108
+
109
+ /**
110
+ * Builds an array of SQL query conditions based on regularly used arguments
111
+ * @param array $args
112
+ * @return array
113
+ */
114
+ function build_sql_conditions( $args = array() ){
115
+ global $wpdb;
116
+ $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
117
+ $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE;
118
+
119
+ $args = apply_filters('em_object_build_sql_conditions_args',$args);
120
+
121
+ //Format the arguments passed on
122
+ $scope = $args['scope'];//undefined variable warnings in ZDE, could just delete this (but dont pls!)
123
+ $recurring = $args['recurring'];
124
+ $recurrence = $args['recurrence'];
125
+ $category = $args['category'];
126
+ $location = $args['location'];
127
+ $rsvp = $args['rsvp'];
128
+ $owner = $args['owner'];
129
+ $event = $args['event'];
130
+ $month = $args['month'];
131
+ $year = $args['year'];
132
+ $today = date('Y-m-d', current_time('timestamp'));
133
+ //Create the WHERE statement
134
+
135
+ //Recurrences
136
+ $conditions = array();
137
+ if( $recurring ){
138
+ $conditions['recurring'] = "`recurrence`=1";
139
+ }elseif( $recurrence > 0 ){
140
+ $conditions['recurrence'] = "`recurrence_id`=$recurrence";
141
+ }else{
142
+ $conditions['recurring'] = "(`recurrence`!=1 OR `recurrence` IS NULL)";
143
+ }
144
+ //Dates - first check 'month', and 'year', and adjust scope if needed
145
+ if( !($month=='' && $year=='') ){
146
+ //Sort out month range, if supplied an array of array(month,month), it'll check between these two months
147
+ if( self::array_is_numeric($month) ){
148
+ $date_month_start = $month[0];
149
+ $date_month_end = $month[1];
150
+ }else{
151
+ $date_month_start = $date_month_end = $month;
152
+ }
153
+ //Sort out year range, if supplied an array of array(year,year), it'll check between these two years
154
+ if( self::array_is_numeric($year) ){
155
+ $date_year_start = $year[0];
156
+ $date_year_end = $year[1];
157
+ }else{
158
+ $date_year_start = $date_year_end = $year;
159
+ }
160
+ $date_start = $date_year_start."-".$date_month_start."-01";
161
+ $date_end = date('Y-m-t', mktime(0,0,0,$date_month_end,1,$date_year_end));
162
+ $scope = $date_start.",".$date_end; //just modify the scope here
163
+ }
164
+ //No date requested, so let's look at scope
165
+ if ( preg_match ( "/^[0-9]{4}-[0-9]{2}-[0-9]{2},[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $scope ) ) {
166
+ //This is an array, let's split it up
167
+ $dates = explode(',', $scope);
168
+ $date_start = $dates[0];
169
+ $date_end = $dates[1];
170
+ $conditions['scope'] = " ( ( event_start_date <= CAST('$date_end' AS DATE) AND event_end_date >= CAST('$date_start' AS DATE) ) OR (event_start_date BETWEEN CAST('$date_start' AS DATE) AND CAST('$date_end' AS DATE)) OR (event_end_date BETWEEN CAST('$date_start' AS DATE) AND CAST('$date_end' AS DATE)) )";
171
+ } elseif ( preg_match ( "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $scope ) ) {
172
+ //Scope can also be a specific date. However, if 'day', 'month', or 'year' are set, that will take precedence
173
+ $conditions['scope'] = " ( event_start_date = CAST('$scope' AS DATE) OR ( event_start_date <= CAST('$scope' AS DATE) AND event_end_date >= CAST('$scope' AS DATE) ) )";
174
+ } else {
175
+ if ($scope == "past"){
176
+ $conditions['scope'] = " event_start_date < '$today'";
177
+ }elseif ($scope == "today"){
178
+ $conditions['scope'] = " ( (event_start_date = CAST('$today' AS DATE)) OR (event_start_date <= CAST('$today' AS DATE) AND event_end_date >= CAST('$today' AS DATE)) )";
179
+ }elseif ($scope == "future"){
180
+ $conditions['scope'] = " (event_start_date >= CAST('$today' AS DATE) OR (event_end_date >= CAST('$today' AS DATE) AND event_end_date != '0000-00-00' AND event_end_date IS NOT NULL))";
181
+ }
182
+ }
183
+
184
+ //Filter by Location - can be object, array, or id
185
+ if ( is_numeric($location) && $location > 0 ) { //Location ID takes precedence
186
+ $conditions['location'] = " {$locations_table}.location_id = $location";
187
+ }elseif ( self::array_is_numeric($location) ){
188
+ $conditions['location'] = "( {$locations_table}.location_id = " . implode(" OR {$locations_table}.location_id = ", $location) .' )';
189
+ }elseif ( is_object($location) && get_class($location)=='EM_Location' ){ //Now we deal with objects
190
+ $conditions['location'] = " {$locations_table}.location_id = $location->id";
191
+ }elseif ( is_array($location) && @get_class(current($location)=='EM_Location') ){ //we can accept array of ids or EM_Location objects
192
+ foreach($location as $EM_Location){
193
+ $location_ids[] = $EM_Location->id;
194
+ }
195
+ $conditions['location'] = "( {$locations_table}.location_id=". implode(" {$locations_table}.location_id=", $location_ids) ." )";
196
+ }
197
+
198
+ //Filter by Event - can be object, array, or id
199
+ if ( is_numeric($event) && $event > 0 ) { //event ID takes precedence
200
+ $conditions['event'] = " {$events_table}.event_id = $event";
201
+ }elseif ( self::array_is_numeric($event) ){ //array of ids
202
+ $conditions['event'] = "( {$events_table}.event_id = " . implode(" OR {$events_table}.event_id = ", $event) .' )';
203
+ }elseif ( is_object($event) && get_class($event)=='EM_Event' ){ //Now we deal with objects
204
+ $conditions['event'] = " {$events_table}.event_id = $event->id";
205
+ }elseif ( is_array($event) && @get_class(current($event)=='EM_Event') ){ //we can accept array of ids or EM_event objects
206
+ foreach($event as $EM_Event){
207
+ $event_ids[] = $EM_Event->id;
208
+ }
209
+ $conditions['event'] = "( {$events_table}.event_id=". implode(" {$events_table}.event_id=", $event_ids) ." )";
210
+ }
211
+
212
+ //Add conditions for category selection
213
+ //Filter by category, can be id or comma seperated ids
214
+ //TODO create an exclude category option
215
+ if ( is_numeric($category) && $category > 0 ){
216
+ $conditions['category'] = " event_category_id = $category";
217
+ }elseif( self::array_is_numeric($category) ){
218
+ $conditions['category'] = "( event_category_id = ". implode(' OR event_category_id = ', $category).")";
219
+ }
220
+
221
+ //If we want rsvped items, we usually check the event
222
+ if( $rsvp == 1 ){
223
+ $conditions['rsvp'] = 'event_rsvp=1';
224
+ }
225
+ //Default ownership belongs to an event, child objects can just overwrite this if needed.
226
+ if( is_numeric($owner) ){
227
+ $conditions['owner'] = 'event_author='.$owner;
228
+ }
229
+ return apply_filters('em_object_build_sql_conditions', $conditions);
230
+ }
231
+
232
+ function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
233
+ //First, ORDER BY
234
+ $args = apply_filters('em_object_build_sql_orderby_args', $args);
235
+ $orderby = array();
236
+ if(is_array($args['orderby'])){
237
+ //Clean orderby array so we only have accepted values
238
+ foreach( $args['orderby'] as $key => $field ){
239
+ if( array_key_exists($field, $accepted_fields) ){
240
+ $orderby[] = $accepted_fields[$field];
241
+ }elseif( in_array($field,$accepted_fields) ){
242
+ $orderby[] = $field;
243
+ }else{
244
+ unset($args['orderby'][$key]);
245
+ }
246
+ }
247
+ }elseif( $args['orderby'] != '' && array_key_exists($args['orderby'], $accepted_fields) ){
248
+ $orderby[] = $accepted_fields[$args['orderby']];
249
+ }elseif( $args['orderby'] != '' && in_array($args['orderby'], $accepted_fields) ){
250
+ $orderby[] = $args['orderby'];
251
+ }
252
+ //ORDER
253
+ //If order is an array, we'll go through the orderby array and match the order values (in order of array) with orderby values
254
+ //If orders don't match up, or it's not ASC/DESC, the default events search in EM settings/options page will be used.
255
+ foreach($orderby as $i => $field){
256
+ $orderby[$i] .= ' ';
257
+ if(is_array($args['order'])){
258
+ if( in_array($args['order'][$i], array('ASC','DESC')) ){
259
+ $orderby[$i] .= $args['order'][$i];
260
+ }else{
261
+ $orderby[$i] .= $default_order;
262
+ }
263
+ }else{
264
+ $orderby[$i] .= ( in_array($args['order'], array('ASC','DESC')) ) ? $args['order'] : $default_order;
265
+ }
266
+ }
267
+ return apply_filters('em_object_build_sql_orderby', $orderby);
268
+ }
269
+
270
+ /**
271
+ * Save an array into this class.
272
+ * If you provide a record from the database table corresponding to this class type it will add the data to this object.
273
+ * @param array $array
274
+ * @return null
275
+ */
276
+ function to_object( $array = array(), $addslashes = false ){
277
+ //Save core data
278
+ if( is_array($array) ){
279
+ $array = apply_filters('em_to_object', $array);
280
+ foreach ( $this->fields as $key => $val ) {
281
+ if(array_key_exists($key, $array)){
282
+ if( !is_object($array[$key]) && !is_array($array[$key]) ){
283
+ $array[$key] = ($addslashes) ? stripslashes($array[$key]):$array[$key];
284
+ }
285
+ $this->$val['name'] = $array[$key];
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Returns this object in the form of an array, useful for saving directly into a database table.
293
+ * @return array
294
+ */
295
+ function to_array(){
296
+ $array = array();
297
+ foreach ( $this->fields as $key => $val ) {
298
+ $array[$key] = $this->$val['name'];
299
+ }
300
+ return apply_filters('em_to_array', $array);
301
+ }
302
+
303
+
304
+ /**
305
+ * Function to retreive wpdb types for all fields, or if you supply an assoc array with field names as keys it'll return an equivalent array of wpdb types
306
+ * @param array $array
307
+ * @return array:
308
+ */
309
+ function get_types($array = array()){
310
+ $types = array();
311
+ if( count($array)>0 ){
312
+ //So we look at assoc array and find equivalents
313
+ foreach ($array as $key => $val){
314
+ $types[] = $this->fields[$key]['type'];
315
+ }
316
+ }else{
317
+ //Blank array, let's assume we're getting a standard list of types
318
+ foreach ($this->fields as $field){
319
+ $types[] = $field['type'];
320
+ }
321
+ }
322
+ return apply_filters('em_object_get_types', $types, $this, $array);
323
+ }
324
+
325
+ function get_fields( $inverted_array=false ){
326
+ if( is_array($this->fields) ){
327
+ $return = array();
328
+ foreach($this->fields as $fieldName => $fieldArray){
329
+ if($inverted_array){
330
+ $return[$fieldArray['name']] = $fieldName;
331
+ }else{
332
+ $return[$fieldName] = $fieldArray['name'];
333
+ }
334
+ }
335
+ return apply_filters('em_object_get_fields', $return, $this, $inverted_array);
336
+ }
337
+ return apply_filters('em_object_get_fields', array(), $this, $inverted_array);
338
+ }
339
+
340
+ /**
341
+ * Sanitize text before inserting into database
342
+ * @param string $value
343
+ * @return string
344
+ */
345
+ function sanitize( $value ) {
346
+ if( get_magic_quotes_gpc() )
347
+ $value = stripslashes( $value );
348
+
349
+ //check if this function exists
350
+ if( function_exists( "mysql_real_escape_string" ) ) {
351
+ $value = mysql_real_escape_string( $value );
352
+ //for PHP version < 4.3.0 use addslashes
353
+ } else {
354
+ $value = addslashes( $value );
355
+ }
356
+ return apply_filters('em_object_sanitize', $value);
357
+ }
358
+
359
+ /**
360
+ * Cleans arrays that contain id lists. Takes an array of items and will clean the keys passed in second argument so that if they keep numbers, explode comma-seperated numbers, and unsets the key if there's any other value
361
+ * @param array $array
362
+ * @param array $id_atts
363
+ */
364
+ function clean_id_atts( $array = array(), $id_atts = array() ){
365
+ if( is_array($array) && is_array($id_atts) ){
366
+ foreach( $array as $key => $string ){
367
+ if( in_array($key, $id_atts) ){
368
+ //This is in the list of atts we want cleaned
369
+ if( is_numeric($string) ){
370
+ $array[$key] = (int) $string;
371
+ }elseif( self::array_is_numeric($string) ){
372
+ $array[$key] = $string;
373
+ }elseif( preg_match('/^([0-9],?)+$/', $string) ){
374
+ $array[$key] = explode(',', $string);
375
+ }else{
376
+ //No format we accept
377
+ unset($array[$key]);
378
+ }
379
+ }
380
+ }
381
+ }
382
+ return $array;
383
+ }
384
+
385
+ /**
386
+ * Send an email and log errors in this object
387
+ * @param string $subject
388
+ * @param string $body
389
+ * @param string $email
390
+ * @return string
391
+ */
392
+ function email_send($subject, $body, $email){
393
+ global $EM_Mailer;
394
+ if( !$EM_Mailer->send($subject,$body,$email) ){
395
+ foreach($EM_Mailer->errors as $error){
396
+ $this->errors[] = $error;
397
+ }
398
+ return false;
399
+ }
400
+ return true;
401
+ }
402
+
403
+ /**
404
+ * Will return true if this is a simple (non-assoc) numeric array, meaning it has at one or more numeric entries and nothing else
405
+ * @param mixed $array
406
+ * @return boolean
407
+ */
408
+ function array_is_numeric($array){
409
+ $results = array();
410
+ if(is_array($array)){
411
+ foreach($array as $key => $item){
412
+ $results[] = (is_numeric($item)&&is_numeric($key));
413
+ }
414
+ }
415
+ return (!in_array(false, $results) && count($results) > 0);
416
+ }
417
+
418
+ /**
419
+ * Converts an array to JSON format, useful for outputting data for AJAX calls. Uses a PHP4 fallback function, given it doesn't support json_encode().
420
+ * @param array $array
421
+ * @return string
422
+ */
423
+ function json_encode($array){
424
+ if( function_exists("json_encode") ){
425
+ $return = json_encode($array);
426
+ }else{
427
+ $return = self::array_to_json($array);
428
+ }
429
+ if( isset($_GET['callback']) ){
430
+ $return = $_GET['callback']."($return)";
431
+ }
432
+ return apply_filters('em_object_json_encode', $return, $array);
433
+ }
434
+
435
+ /**
436
+ * Compatible json encoder function for PHP4
437
+ * @param array $array
438
+ * @return string
439
+ */
440
+ function array_to_json($array){
441
+ //PHP4 Comapatability - This encodes the array into JSON. Thanks go to Andy - http://www.php.net/manual/en/function.json-encode.php#89908
442
+ if( !is_array( $array ) ){
443
+ $array = array();
444
+ }
445
+ $associative = count( array_diff( array_keys($array), array_keys( array_keys( $array )) ));
446
+ if( $associative ){
447
+ $construct = array();
448
+ foreach( $array as $key => $value ){
449
+ // We first copy each key/value pair into a staging array,
450
+ // formatting each key and value properly as we go.
451
+ // Format the key:
452
+ if( is_numeric($key) ){
453
+ $key = "key_$key";
454
+ }
455
+ $key = "'".addslashes($key)."'";
456
+ // Format the value:
457
+ if( is_array( $value )){
458
+ $value = $this->array_to_json( $value );
459
+ }else if( is_bool($value) ) {
460
+ $value = ($value) ? "true" : "false";
461
+ }else if( !is_numeric( $value ) || is_string( $value ) ){
462
+ $value = "'".addslashes($value)."'";
463
+ }
464
+ // Add to staging array:
465
+ $construct[] = "$key: $value";
466
+ }
467
+ // Then we collapse the staging array into the JSON form:
468
+ $result = "{ " . implode( ", ", $construct ) . " }";
469
+ } else { // If the array is a vector (not associative):
470
+ $construct = array();
471
+ foreach( $array as $value ){
472
+ // Format the value:
473
+ if( is_array( $value )){
474
+ $value = $this->array_to_json( $value );
475
+ } else if( !is_numeric( $value ) || is_string( $value ) ){
476
+ $value = "'".addslashes($value)."'";
477
+ }
478
+ // Add to staging array:
479
+ $construct[] = $value;
480
+ }
481
+ // Then we collapse the staging array into the JSON form:
482
+ $result = "[ " . implode( ", ", $construct ) . " ]";
483
+ }
484
+ return $result;
485
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
  }
classes/em-people.php CHANGED
@@ -1,67 +1,129 @@
1
- <?php
2
- class EM_People extends EM_Object {
3
-
4
- /**
5
- * Gets all users, if $return_people false an array associative arrays will be returned. If $return_people is true this will return an array of EM_Person objects
6
- * @param $return_people
7
- * @return array
8
- */
9
- function get( $return_people = true ) {
10
- global $wpdb;
11
- $sql = "SELECT * FROM ". $wpdb->prefix.EM_PEOPLE_TABLE ;
12
- $result = $wpdb->get_results($sql, ARRAY_A);
13
- if( $return_people ){
14
- //Return people as EM_Person objects
15
- $people = array();
16
- foreach ($result as $person){
17
- $people[] = new EM_Person($person);
18
- }
19
- return $people;
20
- }
21
- return $result;
22
- }
23
-
24
- /* Overrides EM_Object method to apply a filter to result
25
- * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
26
- */
27
- function build_sql_conditions( $args = array() ){
28
- global $wpdb;
29
- //FIXME EM_People doesn't build sql conditions in EM_Object
30
- $conditions = array();
31
-
32
- //owner lookup
33
- //FIXME permissions need tweaking for people, not owned by event owner, but site.
34
- /*
35
- if( is_numeric($args['owner']) ){
36
- $conditions['owner'] = "person_owner=".get_current_user_id();
37
- }elseif( preg_match('/^([0-9],?)+$/', $args['owner']) ){
38
- $conditions['owner'] = "person_owner IN (".explode(',', $args['owner']).")";
39
- }
40
- */
41
- return apply_filters( 'em_people_build_sql_conditions', $conditions, $args );
42
- }
43
-
44
- /* Overrides EM_Object method to apply a filter to result
45
- * @see wp-content/plugins/people-manager/classes/EM_Object#build_sql_orderby()
46
- */
47
- function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
48
- return apply_filters( 'em_people_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_people_default_order')), $args, $accepted_fields, $default_order );
49
- }
50
-
51
- /*
52
- * Adds custom people search defaults
53
- * @param array $array
54
- * @return array
55
- * @uses EM_Object#get_default_search()
56
- */
57
- function get_default_search( $array = array() ){
58
- $defaults = array(
59
- 'scope'=>false,
60
- 'eventful' => false, //cats that have an event (scope will also play a part here
61
- 'eventless' => false, //cats WITHOUT events, eventful takes precedence
62
- );
63
- return apply_filters('em_people_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
64
- }
65
-
66
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  ?>
1
+ <?php
2
+ class EM_People extends EM_Object {
3
+
4
+ /**
5
+ * Gets all users, if $return_people false an array associative arrays will be returned. If $return_people is true this will return an array of EM_Person objects
6
+ * @param $return_people
7
+ * @return array
8
+ */
9
+ function get( $return_people = true ) {
10
+ global $wpdb;
11
+ $sql = "SELECT * FROM ". $wpdb->prefix.EM_PEOPLE_TABLE ;
12
+ $result = $wpdb->get_results($sql, ARRAY_A);
13
+ if( $return_people ){
14
+ //Return people as EM_Person objects
15
+ $people = array();
16
+ foreach ($result as $person){
17
+ $people[] = new EM_Person($person);
18
+ }
19
+ return $people;
20
+ }
21
+ return $result;
22
+ }
23
+
24
+ function get_new( $args = array() ) {
25
+ global $wpdb;
26
+ $people_table = $wpdb->prefix.EM_PEOPLE_TABLE;
27
+ $bookings_table = $wpdb->prefix.EM_BOOKINGS_TABLE;
28
+
29
+ //Quick version, we can accept an array of IDs, which is easy to retrieve
30
+ if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
31
+ //We can just get all the events here and return them
32
+ $sql = "SELECT * FROM $people_table WHERE person_id=".implode(" OR person_id=", $args);
33
+ $results = $wpdb->get_results(apply_filters('em_people_get_sql',$sql),ARRAY_A);
34
+ $people = array();
35
+ foreach($results as $result){
36
+ $people[$result['person_id']] = new EM_Person($result);
37
+ }
38
+ return $people; //We return all the people matched as an EM_Event array.
39
+ }
40
+
41
+ //We assume it's either an empty array or array of search arguments to merge with defaults
42
+ $args = self::get_default_search($args);
43
+ $limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
44
+ $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
45
+
46
+ //Get the default conditions
47
+ $conditions = self::build_sql_conditions($args);
48
+ //Put it all together
49
+ $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
50
+
51
+ //Get ordering instructions
52
+ $EM_Person = new EM_Person();
53
+ $accepted_fields = $EM_Person->get_fields(true);
54
+ $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_people_default_order'));
55
+ //Now, build orderby sql
56
+ $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
57
+
58
+ //Create the SQL statement and execute
59
+ $sql = "
60
+ SELECT * FROM $people_table
61
+ LEFT JOIN $bookings_table ON {$bookings_table}.person_id={$people_table}.person_id
62
+ $where
63
+ GROUP BY person_id
64
+ $orderby_sql
65
+ $limit $offset
66
+ ";
67
+ $results = $wpdb->get_results( apply_filters('em_people_get_sql',$sql, $args), ARRAY_A);
68
+ //If we want results directly in an array, why not have a shortcut here?
69
+ if( $args['array'] == true ){
70
+ return $results;
71
+ }
72
+
73
+ //Make returned results EM_Event objects
74
+ $results = (is_array($results)) ? $results:array();
75
+ $people = array();
76
+ foreach ( $results as $person_array ){
77
+ $people[$person_array['person_id']] = new EM_Person($person_array);
78
+ }
79
+
80
+ return apply_filters('em_people_get', $people);
81
+ }
82
+
83
+ /* Overrides EM_Object method to apply a filter to result
84
+ * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
85
+ */
86
+ function build_sql_conditions( $args = array() ){
87
+ global $wpdb;
88
+ //FIXME EM_People doesn't build sql conditions in EM_Object
89
+ $conditions = array();
90
+
91
+ return apply_filters( 'em_people_build_sql_conditions', $conditions, $args );
92
+ }
93
+
94
+ /* Overrides EM_Object method to apply a filter to result
95
+ * @see wp-content/plugins/people-manager/classes/EM_Object#build_sql_orderby()
96
+ */
97
+ function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
98
+ return apply_filters( 'em_people_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_people_default_order')), $args, $accepted_fields, $default_order );
99
+ }
100
+
101
+ /*
102
+ * Adds custom people search defaults
103
+ * @param array $array
104
+ * @return array
105
+ * @uses EM_Object#get_default_search()
106
+ */
107
+ function get_default_search( $array = array() ){
108
+ $defaults = array(
109
+ 'scope'=>false,
110
+ 'eventful' => false, //cats that have an event (scope will also play a part here
111
+ 'eventless' => false, //cats WITHOUT events, eventful takes precedence
112
+ );
113
+ //figure out default owning permissions, but since public is for viewing events, only impose limitations in admin area
114
+ if( is_admin() ){
115
+ switch( get_option('dbem_permissions_events') ){
116
+ case 0:
117
+ $defaults['owner'] = get_current_user_id();
118
+ break;
119
+ case 1:
120
+ $defaults['owner'] = false;
121
+ break;
122
+ }
123
+ $defaults['owner'] = ( em_verify_admin() ) ? false:$defaults['owner'];
124
+ }
125
+ return apply_filters('em_people_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
126
+ }
127
+
128
+ }
129
  ?>
classes/em-permalinks.php DELETED
@@ -1,200 +0,0 @@
1
- <?php
2
-
3
- if( !class_exists('EM_Permalinks') ){
4
- class EM_Permalinks {
5
-
6
- static $em_queryvars = array(
7
- 'event_id', 'event_slug',
8
- 'location_id', 'location_slug',
9
- 'person_id',
10
- 'booking_id',
11
- 'category_id', 'category_slug',
12
- 'ticket_id',
13
- 'calendar_day',
14
- 'book',
15
- 'rss','ical', 'scope', 'page'
16
- );
17
- static $scopes = 'today|tomorrow|this\-month|next\-month|past|all|future';
18
-
19
- function init(){
20
- add_filter('pre_update_option_dbem_events_page', array('EM_Permalinks','option_update'));
21
- add_filter('init', array('EM_Permalinks','flush'));
22
- add_filter('rewrite_rules_array',array('EM_Permalinks','rewrite_rules_array'));
23
- add_filter('query_vars',array('EM_Permalinks','query_vars'));
24
- add_action('template_redirect',array('EM_Permalinks','init_objects'));
25
- add_action('template_redirect',array('EM_Permalinks','redirection'));
26
- //Add filters to rewrite the URLs
27
- add_filter('em_event_output_placeholder',array('EM_Permalinks','rewrite_urls'),1,3);
28
- add_filter('em_location_output_placeholder',array('EM_Permalinks','rewrite_urls'),1,3);
29
- }
30
-
31
- function flush(){
32
- global $wp_rewrite;
33
- if( get_option('dbem_flush_needed') ){
34
- $wp_rewrite->flush_rules();
35
- delete_option('dbem_flush_needed');
36
- }
37
- }
38
-
39
- function rewrite_urls($replace, $object, $result){
40
- global $wp_query, $wp_rewrite;
41
- if( $wp_rewrite->using_permalinks() ){
42
- switch( $result ){
43
- case '#_EVENTPAGEURL': //Depreciated
44
- case '#_LINKEDNAME': //Depreciated
45
- case '#_EVENTURL': //Just the URL
46
- case '#_EVENTLINK': //HTML Link
47
- if( is_object($object) && get_class($object)=='EM_Event' ){
48
- $event_link = trailingslashit(trailingslashit(EM_URI).'event/'.$object->slug);
49
- if($result == '#_LINKEDNAME' || $result == '#_EVENTLINK'){
50
- $replace = "<a href='{$event_link}' title='{$object->name}'>{$object->name}</a>";
51
- }else{
52
- $replace = $event_link;
53
- }
54
- }
55
- break;
56
- case '#_LOCATIONURL':
57
- case '#_LOCATIONLINK':
58
- case '#_LOCATIONPAGEURL': //Depreciated
59
- if( is_object($object) && get_class($object)=='EM_Location' ){
60
- $link = trailingslashit(trailingslashit(EM_URI).'location/'.$object->slug);
61
- $replace = ($result == '#_LOCATIONURL' || $result == '#_LOCATIONPAGEURL') ? $link : '<a href="'.$link.'">'.$object->name.'</a>';
62
- }
63
- break;
64
- }
65
- }
66
- return $replace;
67
- }
68
-
69
- /**
70
- * will redirect old links to new link structures.
71
- * @return mixed
72
- */
73
- function redirection(){
74
- global $wp_rewrite, $post, $wp_query;
75
- if( $wp_rewrite->using_permalinks() && !is_admin() ){
76
- //is this a querystring url?
77
- $events_page_id = get_option ( 'dbem_events_page' );
78
- if ( is_object($post) && $post->ID == $events_page_id && $events_page_id != 0 ) {
79
- $page = ( !empty($_GET['page']) && is_numeric($_GET['page']) )? $_GET['page'] : '';
80
- if ( !empty($_GET['calendar_day']) ) {
81
- //Events for a specific day
82
- wp_redirect( self::url($_GET['calendar_day'],$page), 301);
83
- exit();
84
- } elseif ( !empty($_GET['location_id']) && is_numeric($_GET['location_id']) ) {
85
- //Just a single location
86
- wp_redirect( self::url('location', $_GET['location_id'],$page), 301);
87
- exit();
88
- } elseif ( !empty($_GET['location_slug']) ) {
89
- //Just a single location with slug
90
- wp_redirect( self::url('location', $_GET['location_slug'],$page), 301);
91
- exit();
92
- } elseif ( !empty($_GET['book']) && !empty($_GET['event_id']) ) {
93
- //bookings page
94
- wp_redirect( self::url('book', $_GET['event_id']), 301);
95
- exit();
96
- } elseif ( !empty($_GET['event_id']) && is_numeric($_GET['event_id']) ) {
97
- //single event page
98
- wp_redirect( self::url('event', $_GET['event_id']), 301);
99
- exit();
100
- } elseif ( !empty($_GET['event_slug']) ) {
101
- //single event page with slug
102
- wp_redirect( self::url('event', $_GET['event_slug']), 301);
103
- exit();
104
- } elseif ( !empty($_GET['category_id']) && is_numeric($_GET['category_id']) ){
105
- //category page
106
- wp_redirect( self::url('category', $_GET['category_id'], $page), 301);
107
- exit();
108
- } elseif ( !empty($_GET['category_slug']) ){
109
- //category page with slug
110
- wp_redirect( self::url('category', $_GET['category_slug'], $page), 301);
111
- exit();
112
- } elseif( !empty($_GET['scope']) ) {
113
- // Multiple events page
114
- wp_redirect( self::url($_GET['scope'], $page), 301);
115
- exit();
116
- }
117
- }elseif( !empty($_GET['dbem_rss']) ){
118
- //RSS page
119
- wp_redirect( self::url('rss'), 301);
120
- exit();
121
- }
122
- }
123
- }
124
- // Adding a new rule
125
- function rewrite_rules_array($rules){
126
- //get the slug of the event page
127
- $events_page_id = get_option ( 'dbem_events_page' );
128
- $events_page = get_post($events_page_id);
129
- $em_rules = array();
130
- if( is_object($events_page) ){
131
- $events_slug = $events_page->post_name;
132
- $em_rules[$events_slug.'/('.self::$scopes.')$'] = 'index.php?pagename='.$events_slug.'&scope=$matches[1]'; //events with scope
133
- $em_rules[$events_slug.'/(\d{4}-\d{2}-\d{2})$'] = 'index.php?pagename='.$events_slug.'&calendar_day=$matches[1]'; //event calendar date search
134
- $em_rules[$events_slug.'/event/(\d*)$'] = 'index.php?pagename='.$events_slug.'&event_id=$matches[1]'; //single event page with id
135
- $em_rules[$events_slug.'/event/book/(\d*)$'] = 'index.php?pagename='.$events_slug.'&event_id=$matches[1]&book=1'; //single event booking form with id
136
- $em_rules[$events_slug.'/event/book/(.+)$'] = 'index.php?pagename='.$events_slug.'&event_slug=$matches[1]&book=1'; //single event booking form with slug
137
- $em_rules[$events_slug.'/event/(.+)$'] = 'index.php?pagename='.$events_slug.'&event_slug=$matches[1]'; //single event page with slug
138
- $em_rules[$events_slug.'/location/(\d*)$'] = 'index.php?pagename='.$events_slug.'&location_id=$matches[1]'; //location page with id
139
- $em_rules[$events_slug.'/location/(.+)$'] = 'index.php?pagename='.$events_slug.'&location_slug=$matches[1]'; //location page with slug
140
- $em_rules[$events_slug.'/category/(.+)$'] = 'index.php?pagename='.$events_slug.'&category_id=$matches[1]'; //category page with id
141
- $em_rules[$events_slug.'/category/(.+)$'] = 'index.php?pagename='.$events_slug.'&category_slug=$matches[1]'; //category page with slug
142
- $em_rules[$events_slug.'/rss$'] = 'index.php?pagename='.$events_slug.'&rss=1'; //rss page
143
- $em_rules[$events_slug.'/ical$'] = 'index.php?pagename='.$events_slug.'&ical=1'; //ical page
144
- $em_rules[$events_slug.'/(\d+)$'] = 'index.php?pagename='.$events_slug.'&page=$matches[1]'; //event pageno
145
- }
146
- return $em_rules + $rules;
147
- }
148
-
149
- /**
150
- * Generate a URL. Pass each section of a link as a parameter, e.g. EM_Permalinks::url('event',$event_id); will create an event link.
151
- * @param mixed
152
- */
153
- function url(){
154
- $args = func_get_args();
155
- $em_uri = ( !defined('EM_URI') ) ? get_permalink(get_option("dbem_events_page")):EM_URI; //PAGE URI OF EM
156
- $event_link = trailingslashit(trailingslashit($em_uri). implode('/',$args));
157
- return $event_link;
158
- }
159
-
160
- /**
161
- * checks if the events page has changed, and sets a flag to flush wp_rewrite.
162
- * @param mixed $val
163
- * @return mixed
164
- */
165
- function option_update( $val ){
166
- if( get_option('dbem_events_page') != $val ){
167
- update_option('dbem_flush_needed',1);
168
- }
169
- return $val;
170
- }
171
-
172
- // Adding the id var so that WP recognizes it
173
- function query_vars($vars){
174
- foreach(self::$em_queryvars as $em_queryvar){
175
- array_push($vars, $em_queryvar);
176
- }
177
- return $vars;
178
- }
179
-
180
- /**
181
- * Not the "WP way" but for now this'll do!
182
- */
183
- function init_objects(){
184
- //Build permalinks here
185
- global $wp_query, $wp_rewrite;
186
- if ( $wp_rewrite->using_permalinks() ) {
187
- foreach(self::$em_queryvars as $em_queryvar){
188
- if( $wp_query->get($em_queryvar) ) {
189
- $_REQUEST[$em_queryvar] = $wp_query->get($em_queryvar);
190
- }
191
- }
192
- }
193
- //dirty rss condition
194
- if( !empty($_REQUEST['rss']) ){
195
- $_REQUEST['rss_main'] = 'main';
196
- }
197
- }
198
- }
199
- EM_Permalinks::init();
200
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/em-person.php CHANGED
@@ -1,69 +1,154 @@
1
- <?php
2
- // TODO make person details more secure and integrate with WP user data
3
- class EM_Person extends WP_User{
4
-
5
- function EM_Person( $person_id = false, $username = false ){
6
- if( is_array($person_id) ){
7
- if( array_key_exists('person_id',$person_id) ){
8
- $person_id = $person_id['person_id'];
9
- }elseif ( array_key_exists('user_id',$person_id) ){
10
- $person_id = $person_id['user_id'];
11
- }else{
12
- $person_id = $person_id['ID'];
13
- }
14
- }elseif( is_object($person_id) && get_class($person_id) == 'WP_User'){
15
- $person_id = $person_id->ID; //create new object if passed a wp_user
16
- }
17
- if($username){
18
- parent::WP_User($person_id, $username);
19
- }elseif($person_id === 0){
20
- $this->ID = 0;
21
- $this->display_name = 'Unregistered Booking';
22
- $this->user_email = 'n/a';
23
- }else{
24
- parent::WP_User($person_id);
25
- }
26
- $this->phone = get_metadata('user', $this->ID, 'dbem_phone', true); //extra field for EM
27
- do_action('em_person',$this, $person_id, $username);
28
- }
29
-
30
- function get_bookings(){
31
- global $wpdb;
32
- $results = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix.EM_BOOKINGS_TABLE." WHERE person_id={$this->id}",ARRAY_A);
33
- $bookings = array();
34
- foreach($results as $booking_data){
35
- $bookings[] = new EM_Booking($booking_data);
36
- }
37
- return new EM_Bookings($bookings);
38
- }
39
-
40
- /**
41
- * @return EM_Events
42
- */
43
- function get_events(){
44
- global $wpdb;
45
- $events = array();
46
- foreach( $this->get_bookings()->get_bookings() as $EM_Booking ){
47
- $events[$EM_Booking->event_id] = $EM_Booking->get_event();
48
- }
49
- return $events;
50
- }
51
-
52
- function display_summary(){
53
- ob_start();
54
- ?>
55
- <table>
56
- <tr>
57
- <td><?php echo get_avatar($this->ID); ?></td>
58
- <td style="padding-left:10px; vertical-align: top;">
59
- <strong>Name</strong> : <?php echo $this->display_name; ?><br /><br />
60
- <strong>Email</strong> : <?php echo $this->user_email; ?><br /><br />
61
- <strong>Phone</strong> : <?php echo $this->phone; ?>
62
- </td>
63
- </tr>
64
- </table>
65
- <?php
66
- return ob_get_clean();
67
- }
68
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  ?>
1
+ <?php
2
+ // TODO make person details more secure and integrate with WP user data
3
+ class EM_Person extends EM_Object{
4
+ //DB Fields
5
+ var $id = '';
6
+ var $owner = '';
7
+ var $name = '';
8
+ var $email = '';
9
+ var $phone = '';
10
+ //Other Vars
11
+ var $fields = array(
12
+ 'person_id' => array('name'=>'id','type'=>'%d'),
13
+ 'person_name' => array('name'=>'name','type'=>'%s'),
14
+ 'person_email' => array('name'=>'email','type'=>'%s'),
15
+ 'person_phone' => array('name'=>'phone','type'=>'%s')
16
+ );
17
+ var $required_fields = array('person_id', 'person_name', 'person_email', 'person_phone');
18
+ var $feedback_message = "";
19
+ var $errors = array();
20
+
21
+ function EM_Person( $person_data = false ){
22
+ if( $person_data != 0 ){
23
+ //Load person data
24
+ $person = array();
25
+ if( is_array($person_data) ){
26
+ $person = $person_data;
27
+ }elseif( is_numeric($person_data) ){
28
+ //Retreiving from the database
29
+ global $wpdb;
30
+ $sql = "SELECT * FROM ". $wpdb->prefix . EM_PEOPLE_TABLE ." WHERE person_id ='$person_data'";
31
+ $person = $wpdb->get_row($sql, ARRAY_A);
32
+ }
33
+ //Save into the object
34
+ $this->to_object($person);
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Load an record into this object by passing an associative array of table criterie to search for.
40
+ * Returns boolean depending on whether a record is found or not.
41
+ * @param $search
42
+ * @return boolean
43
+ */
44
+ function get($search) {
45
+ global $wpdb;
46
+ $conds = array();
47
+ foreach($search as $key => $value) {
48
+ if( array_key_exists($key, $this->fields) ){
49
+ $conds[] = "`$key`='$value'";
50
+ }
51
+ }
52
+ $sql = "SELECT * FROM ". $wpdb->prefix.EM_PEOPLE_TABLE ." WHERE " . implode(' AND ', $conds) ;
53
+ $result = $wpdb->get_row($sql, ARRAY_A);
54
+ if($result){
55
+ $this->to_object($result);
56
+ return true;
57
+ }else{
58
+ return false;
59
+ }
60
+ }
61
+
62
+ function get_post(){
63
+ $this->name = ( !empty($_REQUEST['person_name']) ) ? stripslashes($_REQUEST['person_name']) : '' ;
64
+ $this->email = ( !empty($_REQUEST['person_email']) ) ? $_REQUEST['person_email'] : '';
65
+ $this->phone = ( !empty($_REQUEST['person_phone']) ) ? $_REQUEST['person_phone'] : '';
66
+ return apply_filters('em_person_get_post', $this->validate(), $this);
67
+ }
68
+
69
+ function save(){
70
+ global $wpdb;
71
+ do_action('em_person_save_pre',$this);
72
+ if($this->validate()){
73
+ //Does this person already exist?
74
+ $this->load_similar();
75
+ $table = $wpdb->prefix.EM_PEOPLE_TABLE;
76
+ $data = $this->to_array();
77
+ unset($data['person_id']);
78
+ if($this->id != ''){
79
+ $where = array( 'person_id' => $this->id );
80
+ $result = $wpdb->update($table, $data, $where);
81
+ }else{
82
+ $result = $wpdb->insert($table, $data);
83
+ $this->id = $wpdb->insert_id;
84
+ }
85
+ $this->feedback_message = ($result) ? __('Changes saved.'): __('Could not edit person details.','dbem');
86
+ return apply_filters('em_save_delete', $result, $this);
87
+ }else{
88
+ $this->feedback_message = __('Could not edit person details.','dbem');
89
+ return apply_filters('em_save_delete', false, $this);
90
+ }
91
+ }
92
+
93
+ function delete(){
94
+ global $wpdb;
95
+ do_action('em_person_delete_pre', $this);
96
+ $results = array();
97
+ $results[] = $wpdb->query ( $wpdb->prepare("DELETE FROM ". $wpdb->prefix . EM_PEOPLE_TABLE ." WHERE person_id=%d", $this->id) );
98
+ $results[] = $wpdb->query ( $wpdb->prepare("DELETE FROM ". $wpdb->prefix . EM_BOOKINGS_TABLE ." WHERE person_id=%d", $this->id) );
99
+ return apply_filters('em_event_delete', !in_array(false,$results), $this);
100
+ }
101
+
102
+ function validate(){
103
+ if( !preg_match('/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/', $this->email) ){
104
+ $this->errors[] = __('Please provide a valid email address.', 'dbem');
105
+ return false;
106
+ }
107
+ return true;
108
+ }
109
+
110
+ function get_bookings(){
111
+ global $wpdb;
112
+ $results = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix.EM_BOOKINGS_TABLE." WHERE person_id={$this->id}",ARRAY_A);
113
+ $bookings = array();
114
+ foreach($results as $booking_data){
115
+ $bookings[] = new EM_Booking($booking_data);
116
+ }
117
+ return $bookings;
118
+ }
119
+
120
+ /**
121
+ * Checks agains the database to see if this user exists already
122
+ * @return boolean|int
123
+ */
124
+ function find_similar(){
125
+ global $wpdb;
126
+ $sql = "SELECT * FROM ". $wpdb->prefix.EM_PEOPLE_TABLE ." WHERE person_name='%s' AND person_email='%s' AND person_phone='%s'";
127
+ $row = $wpdb->get_row( $wpdb->prepare($sql, array($this->name, $this->email, $this->phone)), ARRAY_A );
128
+ if( is_array($row) ){
129
+ return $row['person_id'];
130
+ }
131
+ return false;
132
+ }
133
+
134
+ /**
135
+ * Checks if a similar record exists (same name, email and phone) and if so it loads
136
+ * @return boolean
137
+ */
138
+ function load_similar(){
139
+ $return = $this->find_similar();
140
+ if( is_numeric($return) ){
141
+ $this->id = $return;
142
+ return true;
143
+ }
144
+ return false;
145
+ }
146
+
147
+ /**
148
+ * Can the user manage this event?
149
+ */
150
+ function can_manage(){
151
+ return ( get_option('dbem_permissions_events') || $this->owner == get_current_user_id() || em_verify_admin() );
152
+ }
153
+ }
154
  ?>
classes/em-recurrence.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Object that holds event recurrence info
4
+ * The EM_Event objects will handle adding / editing / deleting recurrences, this just holds the recurring info
5
+ * and provides extra functions to obtain related events.
6
+ * @author marcus
7
+ */
8
+ class EM_Recurrence extends EM_Object{
9
+ //TODO We NEED to add an author and rsvp to this recurrence.....
10
+ var $fields = array(
11
+ 'recurrence_id' => 'id',
12
+ 'recurrence_author' => 'author',
13
+ 'recurrence_name' => 'name',
14
+ 'recurrence_start_time' => 'start_time',
15
+ 'recurrence_end_time' => 'end_time',
16
+ 'recurrence_start_date' => 'start_date',
17
+ 'recurrence_end_date' => 'end_date',
18
+ 'recurrence_notes' => 'notes',
19
+ 'recurrence_rsvp' => 'rsvp',
20
+ 'recurrence_seats' => 'seats',
21
+ 'recurrence_contactperson_id' => 'contactperson_id',
22
+ 'location_id' => 'location_id',
23
+ 'recurrence_id' => 'recurrence_id',
24
+ 'recurrence_category_id' => 'category_id',
25
+ 'recurrence_attributes' => 'attributes',
26
+ 'recurrence_interval' => 'interval',
27
+ 'recurrence_freq' => 'freq',
28
+ 'recurrence_byday' => 'byday',
29
+ 'recurrence_byweekno' => 'byweekno',
30
+ );
31
+ /**
32
+ * Array of EM_Event objects
33
+ * @var array
34
+ */
35
+ var $events = array();
36
+
37
+ /**
38
+ * Initialize object. You can provide event data in an associative array (using database table field names), an id number, or false (default) to create empty event.
39
+ * If you provide an event array or object, it will convert it into a recurrence (useful if you want to change event data into recurrence).
40
+ * @param mixed $event_data
41
+ * @return null
42
+ */
43
+ function EM_Recurrence($event_data = false) {
44
+ global $wpdb;
45
+ if( $event_data !== false ){
46
+ $recurrence = array();
47
+ if( is_array($event_data) && isset($event_data['recurrence_name']) ){
48
+ //Directly inserting array of recurrence data
49
+ $recurrence = $event_data;
50
+ }elseif( is_numeric($event_data) || isset($event_data['recurrence_id']) ){
51
+ //$event_data is recurrence_id - Retreiving from the database
52
+ $recurrence_id = (is_array($event_data)) ? $event_data['recurrence_id']:$event_data;
53
+ $sql = "SELECT * FROM ". $wpdb->prefix . EM_RECURRENCE_TABLE ." WHERE recurrence_id = $recurrence_id";
54
+ $result = $wpdb->get_row( $sql, ARRAY_A );
55
+ if($result){
56
+ $this->location = new EM_Location ( $recurrence ['location_id'] );
57
+ $recurrence = $result;
58
+ }
59
+ }
60
+ $this->to_object($recurrence);
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Removes recurrence record.
66
+ * @param $recurrence_id
67
+ * @return null
68
+ */
69
+ function delete() {
70
+ global $wpdb;
71
+ $sql = "DELETE FROM ".$wpdb->prefix.EM_RECURRENCE_TABLE." WHERE recurrence_id = '{$this->id}';";
72
+ $wpdb->query($sql);
73
+ }
74
+
75
+ /**
76
+ * Save an array into this class
77
+ * @param $array
78
+ * @return null
79
+ */
80
+ function to_object( $array = array() ){
81
+ //Save event core data
82
+ parent::to_object($array);
83
+ //Save location info
84
+ $this->location = new EM_Location($array['location_id']);
85
+ //Save contact person info
86
+ }
87
+
88
+ }
89
+ ?>
classes/em-ticket-booking.php DELETED
@@ -1,209 +0,0 @@
1
- <?php
2
- class EM_Ticket_Booking extends EM_Object{
3
- //DB Fields
4
- var $id;
5
- var $booking_id;
6
- var $ticket_id;
7
- var $price;
8
- var $spaces;
9
- var $fields = array(
10
- 'ticket_booking_id' => array('name'=>'id','type'=>'%d'),
11
- 'ticket_id' => array('name'=>'ticket_id','type'=>'%d'),
12
- 'booking_id' => array('name'=>'booking_id','type'=>'%d'),
13
- 'ticket_booking_price' => array('name'=>'price','type'=>'%f'),
14
- 'ticket_booking_spaces' => array('name'=>'spaces','type'=>'%d')
15
- );
16
- //Other Vars
17
- /**
18
- * Contains ticket object
19
- * @var EM_Ticket
20
- */
21
- var $ticket;
22
- /**
23
- * Contains the booking object of this
24
- * @var EM_Booking
25
- */
26
- var $booking;
27
- var $required_fields = array( 'ticket_id', 'ticket_booking_spaces');
28
-
29
- /**
30
- * Creates ticket object and retreives ticket data (default is a blank ticket object). Accepts either array of ticket data (from db) or a ticket id.
31
- * @param mixed $ticket_data
32
- * @return null
33
- */
34
- function EM_Ticket_Booking( $ticket_data = false ){
35
- if( $ticket_data !== false ){
36
- //Load ticket data
37
- $ticket = array();
38
- if( is_array($ticket_data) ){
39
- $ticket = $ticket_data;
40
- }elseif( is_numeric($ticket_data) ){
41
- //Retreiving from the database
42
- global $wpdb;
43
- $sql = "SELECT * FROM ". $wpdb->prefix . EM_TICKETS_BOOKINGS_TABLE ." WHERE ticket_booking_id ='$ticket_data'";
44
- $ticket = $wpdb->get_row($sql, ARRAY_A);
45
- }
46
- //Save into the object
47
- $this->to_object($ticket);
48
- }
49
- }
50
-
51
- /**
52
- * Saves the ticket into the database, whether a new or existing ticket
53
- * @return boolean
54
- */
55
- function save(){
56
- global $wpdb;
57
- $table = $wpdb->prefix. EM_TICKETS_BOOKINGS_TABLE;
58
- do_action('em_ticket_booking_save_pre',$this);
59
- //First the person
60
- if($this->validate()){
61
- //Now we save the ticket
62
- $this->booking_id = $this->get_booking()->id; //event wouldn't exist before save, so refresh id
63
- $data = $this->to_array(true); //add the true to remove the nulls
64
- if($this->id != ''){
65
- $where = array( 'ticket_booking_id' => $this->id );
66
- $result = $wpdb->update($table, $data, $where, $this->get_types($data));
67
- $this->feedback_message = __('Changes saved','dbem');
68
- }else{
69
- //TODO better error handling
70
- $result = $wpdb->insert($table, $data, $this->get_types($data));
71
- $this->id = $wpdb->insert_id;
72
- $this->feedback_message = __('Ticket booking created','dbem');
73
- }
74
- if( $result === false ){
75
- $this->feedback_message = __('There was a problem saving the ticket booking.', 'dbem');
76
- $this->errors[] = __('There was a problem saving the ticket booking.', 'dbem');
77
- }
78
- return apply_filters('em_ticket_booking_save', ( count($this->errors) == 0 ), $this);
79
- }else{
80
- $this->feedback_message = __('There was a problem saving the ticket booking.', 'dbem');
81
- $this->errors[] = __('There was a problem saving the ticket booking.', 'dbem');
82
- return apply_filters('em_ticket_booking_save', false, $this);
83
- }
84
- return true;
85
- }
86
-
87
-
88
- /**
89
- * Validates the ticket for saving. Should be run during any form submission or saving operation.
90
- * @return boolean
91
- */
92
- function validate(){
93
- $missing_fields = Array ();
94
- foreach ( $this->required_fields as $field ) {
95
- $true_field = $this->fields[$field]['name'];
96
- if ( $this->$true_field == "") {
97
- $missing_fields[] = $field;
98
- }
99
- }
100
- if ( count($missing_fields) > 0){
101
- // TODO Create friendly equivelant names for missing fields notice in validation
102
- $this->errors[] = __ ( 'Missing fields: ' ) . implode ( ", ", $missing_fields ) . ". ";
103
- }
104
- return apply_filters('em_event_validate', count($this->errors) == 0, $this );
105
- }
106
-
107
- /**
108
- * Get the total number of spaces booked for this ticket within this booking.
109
- * @return int
110
- */
111
- function get_spaces(){
112
- return apply_filters('em_booking_get_spaces',$this->spaces,$this);
113
- }
114
-
115
- /**
116
- * Gets the total price for this whole booking. Seting $force_reset to true will recheck spaces, even if previously done so.
117
- * @param boolean $force_refresh
118
- * @return float
119
- */
120
- function get_price( $force_refresh=false ){
121
- if( $force_refresh || $this->price == 0 ){
122
- //get the ticket, clculate price on spaces
123
- $this->price = $this->get_ticket()->get_price() * $this->spaces;
124
- }
125
- return apply_filters('em_booking_get_prices',$this->price,$this);
126
- }
127
-
128
- /**
129
- * Smart event locator, saves a database read if possible.
130
- */
131
- function get_booking(){
132
- global $EM_Booking;
133
- if( is_object($this->booking) && get_class($this->booking)=='EM_Booking' && ($this->booking->id == $this->booking_id || (empty($this->id) && empty($this->booking_id))) ){
134
- return $this->booking;
135
- }elseif( is_object($EM_Booking) && $EM_Booking->id == $this->booking_id ){
136
- $this->booking = $EM_Booking;
137
- }else{
138
- if(is_numeric($this->booking_id)){
139
- $this->booking = new EM_Booking($this->booking_id);
140
- }else{
141
- $this->booking = new EM_Booking();
142
- }
143
- }
144
- return apply_filters('em_ticket_booking_get_booking', $this->booking, $this);;
145
- }
146
-
147
- /**
148
- * Gets the ticket object this booking belongs to, saves a reference in ticket property
149
- * @return EM_Ticket
150
- */
151
- function get_ticket(){
152
- global $EM_Ticket;
153
- if( is_object($this->ticket) && get_class($this->ticket)=='EM_Ticket' && $this->ticket->id == $this->ticket_id ){
154
- return $this->ticket;
155
- }elseif( is_object($EM_Ticket) && $EM_Ticket->id == $this->ticket_id ){
156
- $this->ticket = $EM_Ticket;
157
- }else{
158
- $this->ticket = new EM_Ticket($this->ticket_id);
159
- }
160
- return $this->ticket;
161
- }
162
-
163
- /**
164
- * I wonder what this does....
165
- * @return boolean
166
- */
167
- function delete(){
168
- global $wpdb;
169
- $sql = $wpdb->prepare("DELETE FROM ". $wpdb->prefix.EM_TICKETS_BOOKINGS_TABLE . " WHERE ticket_booking_id=%d", $this->id);
170
- $result = $wpdb->query( $sql );
171
- return apply_filters('em_ticket_booking_delete', ($result !== false ), $this);
172
- }
173
-
174
-
175
- /**
176
- * Get the html options for quantities to go within a <select> container
177
- * @return string
178
- */
179
- function get_spaces_options($zero_value = true){
180
- $available_spaces = $this->get_available_spaces();
181
- if( $available_spaces >= $this->min || ( empty($this->min) && $available_spaces > 0) ) {
182
- ob_start();
183
- ?>
184
- <select name="em_tickets[<?php echo $this->id ?>][spaces]">
185
- <?php
186
- $min = ($this->min > 0) ? $this->min:1;
187
- $max = ($this->max > 0) ? $this->max:get_option('dbem_bookings_form_max');
188
- ?>
189
- <?php if($zero_value) : ?><option>0</option><?php endif; ?>
190
- <?php for( $i=$min; $i<=$max; $i++ ): ?>
191
- <option><?php echo $i ?></option>
192
- <?php endfor; ?>
193
- </select>
194
- <?php
195
- return ob_get_clean();
196
- }else{
197
- return false;
198
- }
199
-
200
- }
201
-
202
- /**
203
- * Can the user manage this event?
204
- */
205
- function can_manage(){
206
- return ( $this->get_booking()->can_manage() );
207
- }
208
- }
209
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/em-ticket.php DELETED
@@ -1,333 +0,0 @@
1
- <?php
2
- class EM_Ticket extends EM_Object{
3
- //DB Fields
4
- var $id;
5
- var $event_id;
6
- var $name;
7
- var $description;
8
- var $price;
9
- var $start;
10
- var $end;
11
- var $min;
12
- var $max;
13
- var $spaces;
14
- var $fields = array(
15
- 'ticket_id' => array('name'=>'id','type'=>'%d'),
16
- 'event_id' => array('name'=>'event_id','type'=>'%d'),
17
- 'ticket_name' => array('name'=>'name','type'=>'%s'),
18
- 'ticket_description' => array('name'=>'description','type'=>'%s','null'=>1),
19
- 'ticket_price' => array('name'=>'price','type'=>'%f','null'=>1),
20
- 'ticket_start' => array('name'=>'start','type'=>'%s','null'=>1),
21
- 'ticket_end' => array('name'=>'end','type'=>'%s','null'=>1),
22
- 'ticket_min' => array('name'=>'min','type'=>'%s','null'=>1),
23
- 'ticket_max' => array('name'=>'max','type'=>'%s','null'=>1),
24
- 'ticket_spaces' => array('name'=>'spaces','type'=>'%s','null'=>1)
25
- );
26
- //Other Vars
27
- /**
28
- * @var EM_Event
29
- */
30
- var $event;
31
- /**
32
- * Contains only bookings belonging to this ticket.
33
- * @var EM_Booking
34
- */
35
- var $bookings = array();
36
- var $required_fields = array('ticket_name');
37
- var $start_timestamp;
38
- var $end_timestamp;
39
- /**
40
- * is this ticket limited by spaces allotted to this ticket? false if no limit (i.e. the events general limit of seats)
41
- * @var unknown_type
42
- */
43
- var $spaces_limit = true;
44
-
45
- /**
46
- * Creates ticket object and retreives ticket data (default is a blank ticket object). Accepts either array of ticket data (from db) or a ticket id.
47
- * @param mixed $ticket_data
48
- * @return null
49
- */
50
- function EM_Ticket( $ticket_data = false ){
51
- if( $ticket_data !== false ){
52
- //Load ticket data
53
- $ticket = array();
54
- if( is_array($ticket_data) ){
55
- $ticket = $ticket_data;
56
- }elseif( is_numeric($ticket_data) ){
57
- //Retreiving from the database
58
- global $wpdb;
59
- $sql = "SELECT * FROM ". $wpdb->prefix . EM_TICKETS_TABLE ." WHERE ticket_id ='$ticket_data'";
60
- $ticket = $wpdb->get_row($sql, ARRAY_A);
61
- //Ticket notes
62
- $notes = $wpdb->get_results("SELECT * FROM ". $wpdb->prefix . EM_META_TABLE ." WHERE meta_key='ticket-note' AND object_id ='$ticket_data'", ARRAY_A);
63
- foreach($notes as $note){
64
- $this->notes[] = unserialize($note['meta_value']);
65
- }
66
- }
67
- //Save into the object
68
- $this->to_object($ticket);
69
- $this->start_timestamp = (!empty($ticket['ticket_start'])) ? strtotime($ticket['ticket_start']):false;
70
- $this->end_timestamp = (!empty($ticket['ticket_end'])) ? strtotime($ticket['ticket_end']):false;
71
- }
72
- do_action('em_ticket',$this, $ticket_data);
73
- }
74
-
75
- /**
76
- * Saves the ticket into the database, whether a new or existing ticket
77
- * @return boolean
78
- */
79
- function save(){
80
- global $wpdb;
81
- $table = $wpdb->prefix.EM_TICKETS_TABLE;
82
- do_action('em_ticket_save_pre',$this);
83
- //First the person
84
- if($this->validate() && $this->can_manage() ){
85
- //Now we save the ticket
86
- $this->event_id = $this->get_event()->id; //event wouldn't exist before save, so refresh id
87
- $data = $this->to_array(true); //add the true to remove the nulls
88
- if($this->id != ''){
89
- //since currently wpdb calls don't accept null, let's build the sql ourselves.
90
- $set_array = array();
91
- foreach( $this->fields as $field_name => $field ){
92
- if( empty($this->$field['name']) && $field['null'] ){
93
- $set_array[] = "{$field_name}=NULL";
94
- }else{
95
- $set_array[] = "{$field_name}='".$wpdb->escape($this->$field['name'])."'";
96
- }
97
- }
98
- $sql = "UPDATE $table SET ".implode(', ', $set_array)." WHERE ticket_id={$this->id}";
99
- $result = $wpdb->query($sql);
100
- $this->feedback_message = __('Changes saved','dbem');
101
- }else{
102
- //TODO better error handling
103
- $result = $wpdb->insert($table, $data, $this->get_types($data));
104
- $this->id = $wpdb->insert_id;
105
- $this->feedback_message = __('Ticket created','dbem');
106
- }
107
- if( $result === false ){
108
- $this->feedback_message = __('There was a problem saving the ticket.', 'dbem');
109
- $this->errors[] = __('There was a problem saving the ticket.', 'dbem');
110
- }
111
- return apply_filters('em_ticket_save', ( count($this->errors) == 0 ), $this);
112
- }else{
113
- $this->feedback_message = __('There was a problem saving the ticket.', 'dbem');
114
- $this->errors[] = __('There was a problem saving the ticket.', 'dbem');
115
- return apply_filters('em_ticket_save', false, $this);
116
- }
117
- return true;
118
- }
119
-
120
- /**
121
- * Get posted data and save it into the object (not db)
122
- * @return boolean
123
- */
124
- function get_post(){
125
- //We are getting the values via POST or GET
126
- do_action('em_location_get_post_pre', $this);
127
- $location = array();
128
- $location['ticket_id'] = ( !empty($_POST['ticket_id']) ) ? $_POST['ticket_id']:'';
129
- $location['event_id'] = ( !empty($_POST['event_id']) ) ? $_POST['event_id']:'';
130
- $location['ticket_name'] = ( !empty($_POST['ticket_name']) ) ? stripslashes($_POST['ticket_name']):'';
131
- $location['ticket_description'] = ( !empty($_POST['ticket_description']) ) ? stripslashes($_POST['ticket_description']):'';
132
- $location['ticket_price'] = ( !empty($_POST['ticket_price']) ) ? $_POST['ticket_price']:'';
133
- $location['ticket_start'] = ( !empty($_POST['ticket_start']) ) ? $_POST['ticket_start']:'';
134
- $location['ticket_end'] = ( !empty($_POST['ticket_end']) ) ? $_POST['ticket_end']:'';
135
- $this->start_timestamp = ( !empty($_POST['ticket_start']) ) ? strtotime($_POST['ticket_start']):'';
136
- $this->end_timestamp = ( !empty($_POST['ticket_end']) ) ? strtotime($_POST['ticket_end']):'';
137
- $location['ticket_min'] = ( !empty($_POST['ticket_min']) ) ? $_POST['ticket_min']:'';
138
- $location['ticket_max'] = ( !empty($_POST['ticket_max']) ) ? $_POST['ticket_max']:'';
139
- $location['ticket_spaces'] = ( !empty($_POST['ticket_spaces']) ) ? $_POST['ticket_spaces']:'';
140
- $this->to_object( apply_filters('em_location_get_post', $location, $this) );
141
- }
142
-
143
-
144
- /**
145
- * Validates the ticket for saving. Should be run during any form submission or saving operation.
146
- * @return boolean
147
- */
148
- function validate(){
149
- $missing_fields = Array ();
150
- foreach ( $this->required_fields as $field ) {
151
- $true_field = $this->fields[$field]['name'];
152
- if ( $this->$true_field == "") {
153
- $missing_fields[] = $field;
154
- }
155
- }
156
- if ( count($missing_fields) > 0){
157
- // TODO Create friendly equivelant names for missing fields notice in validation
158
- $this->errors[] = __ ( 'Missing fields: ' ) . implode ( ", ", $missing_fields ) . ". ";
159
- }
160
- return apply_filters('em_event_validate', count($this->errors) == 0, $this );
161
- }
162
-
163
- function is_available(){
164
- $timestamp = current_time('timestamp');
165
- $available_spaces = $this->get_available_spaces();
166
- $val = (empty($this->start) || $this->start_timestamp <= $timestamp);
167
- $val2 = ($this->end_timestamp >= $timestamp || empty($this->end));
168
- $val3 = $this->get_event()->end > current_time('timestamp');
169
-
170
- if( (empty($this->start) || $this->start_timestamp <= $timestamp) && ($this->end_timestamp >= $timestamp || empty($this->end)) && $this->get_event()->end > current_time('timestamp') ){
171
- //Time Constraints met, now quantities
172
- if( $available_spaces > 0 && ($available_spaces >= $this->min || empty($this->min)) ){
173
- return apply_filters('em_ticket_is_available',true,$this);
174
- }
175
- }
176
- return apply_filters('em_ticket_is_available',false,$this);
177
- }
178
-
179
- /**
180
- * Gets the total price for this ticket.
181
- * @return float
182
- */
183
- function get_price(){
184
- return apply_filters('em_ticket_get_prices',$this->price,$this);
185
- }
186
-
187
- /**
188
- * Get the total number of tickets (spaces) available, bearing in mind event-wide maxiumums and ticket priority settings.
189
- * @return int
190
- */
191
- function get_spaces(){
192
- return apply_filters('em_ticket_get_spaces',$this->spaces,$this);
193
- }
194
-
195
- /**
196
- * Returns the number of available spaces left in this ticket, bearing in mind event-wide restrictions, previous bookings, approvals and other tickets.
197
- * @return int
198
- */
199
- function get_available_spaces(){
200
- $event_available_spaces = $this->get_event()->get_bookings()->get_available_spaces();
201
- $ticket_available_spaces = $this->get_spaces() - $this->get_booked_spaces();
202
- $return = ($ticket_available_spaces <= $event_available_spaces) ? $ticket_available_spaces:$event_available_spaces;
203
- return apply_filters('em_ticket_get_available_spaces', $return, $this);
204
- }
205
-
206
- /**
207
- * Returns the number of available spaces left in this ticket, bearing in mind event-wide restrictions, previous bookings, approvals and other tickets.
208
- * @return int
209
- */
210
- function get_booked_spaces($force_reload=false){
211
- //get all bookings for this event
212
- $spaces = 0;
213
- if( is_object($this->bookings) && $force_reload ){
214
- return $this->bookings;
215
- }
216
- foreach( $this->get_bookings()->get_bookings()->bookings as $EM_Booking ){ //get_bookings() is used twice so we get the confirmed (or all if confirmation disabled) bookings of this ticket's total bookings.
217
- //foreach booking, get this ticket booking info if found
218
- foreach($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking){
219
- if( $EM_Ticket_Booking->ticket_id == $this->id ){
220
- $spaces += $EM_Ticket_Booking->get_spaces();
221
- }
222
- }
223
- }
224
- return apply_filters('em_ticket_get_available_spaces', $spaces, $this);
225
- }
226
-
227
- /**
228
- * Smart event locator, saves a database read if possible.
229
- * @return EM_Event
230
- */
231
- function get_event(){
232
- global $EM_Event;
233
- if( is_object($this->event) && get_class($this->event)=='EM_Event' && ($this->event->id == $this->event_id || empty($this->event_id)) ){
234
- return $this->event;
235
- }elseif( is_object($EM_Event) && $EM_Event->id == $this->event_id ){
236
- $this->event = $EM_Event;
237
- }else{
238
- $this->event = new EM_Event($this->event_id);
239
- }
240
- return $this->event;
241
- }
242
-
243
- /**
244
- * returns array of EM_Booking objects that have this ticket
245
- * @return EM_Bookings
246
- */
247
- function get_bookings(){
248
- $bookings = array();
249
- foreach( $this->get_event()->get_bookings()->bookings as $EM_Booking ){
250
- foreach($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking){
251
- if( $EM_Ticket_Booking->ticket_id == $this->id ){
252
- $bookings[$EM_Booking->id] = $EM_Booking;
253
- }
254
- }
255
- }
256
- $this->bookings = new EM_Bookings($bookings);
257
- return $this->bookings;
258
- }
259
-
260
- /**
261
- * I wonder what this does....
262
- * @return boolean
263
- */
264
- function delete(){
265
- global $wpdb;
266
- $result = false;
267
- if( $this->can_manage() ){
268
- if( count($this->get_bookings()->bookings) == 0 ){
269
- $sql = $wpdb->prepare("DELETE FROM ". $wpdb->prefix.EM_TICKETS_TABLE . " WHERE ticket_id=%d", $this->id);
270
- $result = $wpdb->query( $sql );
271
- }else{
272
- $this->feedback_message = __('You cannot delete a ticket that has a booking on it.','dbem');
273
- return false;
274
- }
275
- }
276
- return ( $result !== false );
277
- }
278
-
279
- /**
280
- * Get the html options for quantities to go within a <select> container
281
- * @return string
282
- */
283
- function get_spaces_options($zero_value = true){
284
- $available_spaces = $this->get_available_spaces();
285
- if( $this->is_available() ) {
286
- ob_start();
287
- ?>
288
- <select name="em_tickets[<?php echo $this->id ?>][spaces]">
289
- <?php
290
- $min = ($this->min > 0) ? $this->min:1;
291
- $max = ($this->max > 0) ? $this->max:get_option('dbem_bookings_form_max');
292
- ?>
293
- <?php if($zero_value) : ?><option>0</option><?php endif; ?>
294
- <?php for( $i=$min; $i<=$available_spaces && $i<=$max; $i++ ): ?>
295
- <option><?php echo $i ?></option>
296
- <?php endfor; ?>
297
- </select>
298
- <?php
299
- return ob_get_clean();
300
- }else{
301
- return false;
302
- }
303
-
304
- }
305
-
306
- /**
307
- * Can the user manage this event?
308
- */
309
- function can_manage(){
310
- return $this->get_event()->can_manage('manage_bookings','manage_others_bookings');
311
- }
312
-
313
- /**
314
- * Outputs properties with formatting
315
- * @param string $property
316
- * @return string
317
- */
318
- function output_property($property){
319
- switch($property){
320
- case 'start':
321
- $value = date_i18n( get_option('date_format'), $this->start_timestamp );
322
- break;
323
- case 'end':
324
- $value = date_i18n( get_option('date_format'), $this->end_timestamp );
325
- break;
326
- default:
327
- $value = $this->$property;
328
- break;
329
- }
330
- return apply_filters('em_ticket_output_property',$value,$this);
331
- }
332
- }
333
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/em-tickets-bookings.php DELETED
@@ -1,261 +0,0 @@
1
- <?php
2
- /**
3
- * Deals with the each ticket booked in a single booking
4
- * @author marcus
5
- *
6
- */
7
- class EM_Tickets_Bookings extends EM_Object{
8
-
9
- /**
10
- * Array of EM_Ticket_Booking objects for a specific event
11
- * @var array
12
- */
13
- var $tickets_bookings = array();
14
- /**
15
- * This object belongs to this booking object
16
- * @var EM_Booking
17
- */
18
- var $booking;
19
- /**
20
- * This object belongs to this booking object
21
- * @var EM_Ticket
22
- */
23
- var $ticket;
24
- var $spaces;
25
- var $price;
26
-
27
- /**
28
- * Creates an EM_Tickets instance,
29
- * @param EM_Event $event
30
- * @return null
31
- */
32
- function EM_Tickets_Bookings( $object = false ){
33
- global $wpdb;
34
- if($object){
35
- if( is_object($object) && get_class($object) == "EM_Booking"){
36
- $this->booking = $object;
37
- $sql = "SELECT * FROM ". $wpdb->prefix . EM_TICKETS_BOOKINGS_TABLE ." bt LEFT JOIN ". $wpdb->prefix . EM_BOOKINGS_TABLE ." b ON bt.booking_id=b.booking_id WHERE b.booking_id ='{$this->booking->id}'";
38
- }elseif( is_object($object) && get_class($object) == "EM_Ticket"){
39
- $this->ticket = $object;
40
- $sql = "SELECT * FROM ". $wpdb->prefix . EM_TICKETS_BOOKINGS_TABLE ." bt LEFT JOIN ". $wpdb->prefix . EM_TICKETS_TABLE ." t ON bt.ticket_id=t.ticket_id WHERE t.ticket_id ='{$this->ticket->id}'";
41
- }elseif( is_numeric($object) ){
42
- $sql = "SELECT * FROM ". $wpdb->prefix . EM_TICKETS_BOOKINGS_TABLE ." bt LEFT JOIN ". $wpdb->prefix . EM_BOOKINGS_TABLE ." t ON bt.booking_id=b.booking_id WHERE b.booking_id ='{$object}'";
43
- }
44
- $tickets_bookings = $wpdb->get_results($sql, ARRAY_A);
45
- //Get tickets belonging to this tickets booking.
46
- foreach ($tickets_bookings as $ticket_booking){
47
- $EM_Ticket_Booking = new EM_Ticket_Booking($ticket_booking);
48
- $EM_Ticket_Booking->booking = $this->booking; //save some calls
49
- $this->tickets_bookings[] = $EM_Ticket_Booking;
50
- }
51
- }
52
- do_action('em_tickets_bookings',$this, $object);
53
- }
54
-
55
- /**
56
- * Saves the ticket bookings for this booking into the database, whether a new or existing booking
57
- * @return boolean
58
- */
59
- function save(){
60
- global $wpdb;
61
- do_action('em_tickets_bookings_save_pre',$this);
62
- foreach( $this->tickets_bookings as $EM_Ticket_Booking ){
63
- $result = $EM_Ticket_Booking->save();
64
- if(!$result){
65
- $this->errors = array_merge($this->errors, $EM_Ticket_Booking->get_errors());
66
- }
67
- }
68
- if( count($this->errors) > 0 ){
69
- $this->feedback_message = __('There was a problem saving the booking.', 'dbem');
70
- $this->errors[] = __('There was a problem saving the booking.', 'dbem');
71
- return apply_filters('em_tickets_bookings_save', false, $this);
72
- }
73
- return apply_filters('em_tickets_bookings_save', true, $this);
74
- }
75
-
76
- /**
77
- * Add a booking into this event object, checking that there's enough space for the event
78
- * @param EM_Ticket_Booking $EM_Ticket_Booking
79
- * @return boolean
80
- */
81
- function add( $EM_Ticket_Booking ){
82
- global $wpdb,$EM_Mailer;
83
- //Does the ticket we want to book have enough spaeces?
84
- if( $EM_Ticket_Booking->get_spaces() > 0 ){
85
- if ( $EM_Ticket_Booking->get_ticket()->get_available_spaces() >= $EM_Ticket_Booking->get_spaces() ) {
86
- $this->tickets_bookings[] = $EM_Ticket_Booking;
87
- $this->get_spaces(true);
88
- $this->get_price(true);
89
- return apply_filters('em_tickets_bookings_add',true,$this);
90
- } else {
91
- $this->errors[] = __('Booking cannot be made, not enough spaces available!', 'dbem');
92
- return apply_filters('em_tickets_bookings_add',false,$this);
93
- }
94
- }
95
- return apply_filters('em_tickets_bookings_add',false,$this);
96
- }
97
-
98
- /**
99
- * Smart event locator, saves a database read if possible.
100
- */
101
- function get_booking(){
102
- global $EM_Booking;
103
- $booking_id = $this->get_booking_id();
104
- if( is_object($this->booking) && get_class($this->booking)=='EM_Booking' && $this->booking->id == $booking_id ){
105
- return $this->booking;
106
- }elseif( is_object($EM_Booking) && $EM_Booking->id == $booking_id ){
107
- $this->booking = $EM_Booking;
108
- }else{
109
- if(is_numeric($booking_id)){
110
- $this->booking = new EM_Booking($booking_id);
111
- }else{
112
- $this->booking = new EM_Booking();
113
- }
114
- }
115
- return apply_filters('em_tickets_bookings_get_booking', $this->booking, $this);;
116
- }
117
-
118
- function get_booking_id(){
119
- if( count($this->tickets_bookings) > 0 ){
120
- foreach($this->tickets_bookings as $EM_Booking_Ticket){ break; } //get first array item
121
- return apply_filters('em_tickets_bookings_get_booking_id', $EM_Booking_Ticket->id, $this);
122
- }
123
- return apply_filters('em_tickets_bookings_get_booking_id', false, $this);
124
- }
125
-
126
- /**
127
- * Delete all ticket bookings
128
- * @return boolean
129
- */
130
- function delete(){
131
- global $wpdb;
132
- if( is_object($this->get_booking()) && $this->get_booking()->can_manage() ){
133
- $result = $wpdb->query("DELETE FROM ".$wpdb->prefix.EM_TICKETS_BOOKINGS_TABLE." WHERE booking_id='{$this->booking->id}'");
134
- }else{
135
- //FIXME ticket bookings
136
- $ticket_ids = array();
137
- foreach( $this->tickets_bookings as $EM_Ticket_Booking ){
138
- if( $EM_Ticket_Booking->can_manage() ){
139
- $tickets_bookings_ids[] = $EM_Ticket_Booking->id;
140
- }else{
141
- $this->errors[] = sprintf(__('You do not have the rights to manage this %s.','dbem'),__('Booking','dbem'));
142
- }
143
- }
144
- if(count($ticket_ids) > 0){
145
- $result = $wpdb->query("DELETE FROM ".$wpdb->prefix.EM_TICKETS_BOOKINGS_TABLE." WHERE ticket_booking_id IN (".implode(',',$ticket_ids).")");
146
- }
147
- }
148
- return apply_filters('em_tickets_bookings_get_booking_id', ($result == true), $this);
149
- }
150
-
151
- /**
152
- * Retrieve multiple ticket info via POST
153
- * @return boolean
154
- */
155
- function get_post(){
156
- //Build Event Array
157
- do_action('em_tickets_get_post_pre', $this);
158
- $this->tickets = array(); //clean current tickets out
159
- if( !empty($_POST['em_tickets']) && is_array($_POST['em_tickets']) ){
160
- //get all ticket data and create objects
161
- foreach($_POST['em_tickets'] as $ticket_data){
162
- $EM_Ticket = new EM_Ticket($ticket_data);
163
- $this->tickets[] = $EM_Ticket;
164
- }
165
- }elseif( is_object($this->booking) ){
166
- //we create a blank standard ticket
167
- $EM_Ticket = new EM_Ticket(array(
168
- 'event_id' => $this->booking->id,
169
- 'ticket_name' => __('Standard','dbem')
170
- ));
171
- $this->tickets[] = $EM_Ticket;
172
- }
173
- return apply_filters('em_tickets_bookings_get_post', $this->validate(), $this);
174
- }
175
-
176
- /**
177
- * Go through the tickets in this object and validate them
178
- */
179
- function validate(){
180
- $errors = array();
181
- foreach($this->tickets_bookings as $EM_Ticket_Booking){
182
- $errors[] = $EM_Ticket_Booking->validate();
183
- }
184
- return apply_filters('em_tickets_bookings_validate', !in_array(false, $errors), $this);
185
- }
186
-
187
- /**
188
- * Get the total number of spaces booked in this booking. Seting $force_reset to true will recheck spaces, even if previously done so.
189
- * @param unknown_type $force_refresh
190
- * @return mixed
191
- */
192
- function get_spaces( $force_refresh=false ){
193
- if($force_refresh || $this->spaces == 0){
194
- $spaces = 0;
195
- foreach($this->tickets_bookings as $EM_Ticket_Booking){
196
- $spaces += $EM_Ticket_Booking->get_spaces();
197
- }
198
- $this->spaces = $spaces;
199
- }
200
- return apply_filters('em_booking_get_spaces',$this->spaces,$this);
201
- }
202
-
203
- /**
204
- * Gets the total price for this whole booking by adding up subtotals of booked tickets. Seting $force_reset to true will recheck spaces, even if previously done so.
205
- * @param boolean $force_refresh
206
- * @return float
207
- */
208
- function get_price( $force_refresh=false ){
209
- $price = 0;
210
- if($force_refresh || $this->price == 0){
211
- foreach($this->tickets_bookings as $EM_Ticket_Booking){
212
- $price += $EM_Ticket_Booking->get_price();
213
- }
214
- $this->price = $price;
215
- }
216
- return apply_filters('em_booking_get_prices',$this->price,$this);
217
- }
218
-
219
- /**
220
- * Goes through each ticket and populates it with the bookings made
221
- */
222
- function get_ticket_bookings(){
223
- foreach( $this->tickets as $EM_Ticket ){
224
- $EM_Ticket->get_bookings();
225
- }
226
- }
227
-
228
- /* Overrides EM_Object method to apply a filter to result
229
- * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
230
- */
231
- function build_sql_conditions( $args = array() ){
232
- $conditions = apply_filters( 'em_tickets_build_sql_conditions', parent::build_sql_conditions($args), $args );
233
- if( is_numeric($args['status']) ){
234
- $conditions['status'] = 'ticket_status='.$args['status'];
235
- }
236
- return apply_filters('em_tickets_bookings_build_sql_conditions', $conditions, $args);
237
- }
238
-
239
- /* Overrides EM_Object method to apply a filter to result
240
- * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
241
- */
242
- function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
243
- return apply_filters( 'em_tickets_bookings_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')), $args, $accepted_fields, $default_order );
244
- }
245
-
246
- /*
247
- * Adds custom Events search defaults
248
- * @param array $array
249
- * @return array
250
- * @uses EM_Object#get_default_search()
251
- */
252
- function get_default_search( $array = array() ){
253
- $defaults = array(
254
- 'status' => false,
255
- 'person' => true //to add later, search by person's tickets...
256
- );
257
- $defaults['owner'] = !current_user_can('manage_others_bookings') ? get_current_user_id():false;
258
- return apply_filters('em_tickets_bookings_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
259
- }
260
- }
261
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/em-tickets.php DELETED
@@ -1,204 +0,0 @@
1
- <?php
2
- /**
3
- * Deals with the ticket info for an event
4
- * @author marcus
5
- *
6
- */
7
- class EM_Tickets extends EM_Object{
8
-
9
- /**
10
- * Array of EM_Ticket objects for a specific event
11
- * @var array
12
- */
13
- var $tickets = array();
14
- /**
15
- * Event ID
16
- * @var EM_Event
17
- */
18
- var $event;
19
- /**
20
- * @var EM_Booking
21
- */
22
- var $booking;
23
- var $spaces;
24
-
25
-
26
- /**
27
- * Creates an EM_Tickets instance,
28
- * @param EM_Event $event
29
- * @return null
30
- */
31
- function EM_Tickets( $object = false ){
32
- global $wpdb;
33
- if( is_object($object) && get_class($object) == "EM_Event" ){ //Creates a blank tickets object if needed
34
- $this->event = $object;
35
- $sql = "SELECT * FROM ". $wpdb->prefix . EM_TICKETS_TABLE ." WHERE event_id ='{$this->event->id}'";
36
- $tickets = $wpdb->get_results($sql, ARRAY_A);
37
- foreach ($tickets as $ticket){
38
- $EM_Ticket = new EM_Ticket($ticket);
39
- $EM_Ticket->event = $this->event;
40
- $this->tickets[] = $EM_Ticket;
41
- }
42
- }elseif( is_object($object) && get_class($object) == "EM_Booking"){
43
- $this->booking = $object;
44
- $this->event = $this->booking->get_event();
45
- $sql = "SELECT * FROM ". $wpdb->prefix . EM_TICKETS_TABLE ." t LEFT JOIN ". $wpdb->prefix . EM_BOOKINGS_TICKETS_TABLE ." bt ON bt.ticket_id=t.ticket_id WHERE booking_id ='{$EM_Booking->id}'";
46
- $tickets = $wpdb->get_results($sql, ARRAY_A);
47
- foreach ($tickets as $ticket){
48
- $EM_Ticket = new EM_Ticket($ticket);
49
- $EM_Ticket->event = $this->event;
50
- $this->tickets[] = $EM_Ticket;
51
- }
52
- }
53
- do_action('em_tickets', $this, $object);
54
- }
55
-
56
- /**
57
- * @return EM_Event
58
- */
59
- function get_event(){
60
- return $this->event;
61
- }
62
-
63
- /**
64
- * Get the first EM_Ticket object in this instance. Returns false if no tickets available.
65
- * @return EM_Ticket
66
- */
67
- function get_first(){
68
- if( count($this->tickets) > 0 ){
69
- foreach($this->tickets as $EM_Ticket){
70
- return $EM_Ticket;
71
- }
72
- }else{
73
- return false;
74
- }
75
- }
76
-
77
- /**
78
- * Delete tickets on this id
79
- * @return boolean
80
- */
81
- function delete(){
82
- global $wpdb;
83
- if( is_object($this->event) ){
84
- $result = $wpdb->query("DELETE FROM ".$wpdb->prefix.EM_TICKETS_TABLE." WHERE event_id='{$this->event->id}'");
85
- }else{
86
- foreach( $this->tickets as $EM_Ticket ){
87
- $ticket_ids[] = $EM_Ticket->id;
88
- }
89
- $result = $wpdb->query("DELETE FROM ".$wpdb->prefix.EM_TICKETS_TABLE." WHERE event_id IN (".implode(',',$ticket_ids).")");
90
- }
91
- return ($result == true);
92
- }
93
-
94
- /**
95
- * Retrieve multiple ticket info via POST
96
- * @return boolean
97
- */
98
- function get_post(){
99
- //Build Event Array
100
- do_action('em_tickets_get_post_pre', $this);
101
- $this->tickets = array(); //clean current tickets out
102
- if( !empty($_POST['em_tickets']) && is_array($_POST['em_tickets']) ){
103
- //get all ticket data and create objects
104
- foreach($_POST['em_tickets'] as $ticket_data){
105
- $EM_Ticket = new EM_Ticket($ticket_data);
106
- $this->tickets[] = $EM_Ticket;
107
- }
108
- }elseif( is_object($this->event) ){
109
- //we create a blank standard ticket
110
- $EM_Ticket = new EM_Ticket(array(
111
- 'event_id' => $this->event->id,
112
- 'ticket_name' => __('Standard','dbem')
113
- ));
114
- $this->tickets[] = $EM_Ticket;
115
- }
116
- return apply_filters('em_tickets_get_post', $this->validate(), $this);
117
- }
118
-
119
- /**
120
- * Go through the tickets in this object and validate them
121
- */
122
- function validate(){
123
- $errors = array();
124
- foreach($this->tickets as $EM_Ticket){
125
- $errors[] = $EM_Ticket->validate();
126
- }
127
- return apply_filters('em_tickets_validate', !in_array(false, $errors), $this);
128
- }
129
-
130
- /**
131
- * Save tickets into DB
132
- */
133
- function save(){
134
- $errors = array();
135
- foreach( $this->tickets as $EM_Ticket ){
136
- $EM_Ticket->event = $this->event; //pass on saved event_data
137
- $errors[] = $EM_Ticket->save();
138
- }
139
- return apply_filters('em_tickets_save', !in_array(false, $errors), $this);
140
- }
141
-
142
- /**
143
- * Goes through each ticket and populates it with the bookings made
144
- */
145
- function get_ticket_bookings(){
146
- foreach( $this->tickets as $EM_Ticket ){
147
- $EM_Ticket->get_bookings();
148
- }
149
- }
150
-
151
- /**
152
- * Get the total number of spaces this event has. This will show the lower value of event global spaces limit or total ticket spaces. Setting $force_refresh to true will recheck spaces, even if previously done so.
153
- * @param boolean $force_refresh
154
- * @return int
155
- */
156
- function get_spaces( $force_refresh=false ){
157
- $spaces = 0;
158
- if($force_refresh || $this->spaces == 0){
159
- foreach( $this->tickets as $EM_Ticket ){
160
- /* @var $EM_Ticket EM_Ticket */
161
- $spaces += $EM_Ticket->get_spaces();
162
- }
163
- $this->spaces = $spaces;
164
- }
165
- return apply_filters('em_booking_get_spaces',$this->spaces,$this);
166
- }
167
-
168
- /* Overrides EM_Object method to apply a filter to result
169
- * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
170
- */
171
- function build_sql_conditions( $args = array() ){
172
- $conditions = apply_filters( 'em_tickets_build_sql_conditions', parent::build_sql_conditions($args), $args );
173
- if( is_numeric($args['status']) ){
174
- $conditions['status'] = 'ticket_status='.$args['status'];
175
- }
176
- return apply_filters('em_tickets_build_sql_conditions', $conditions, $args);
177
- }
178
-
179
- /* Overrides EM_Object method to apply a filter to result
180
- * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
181
- */
182
- function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
183
- return apply_filters( 'em_tickets_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')), $args, $accepted_fields, $default_order );
184
- }
185
-
186
- /*
187
- * Adds custom Events search defaults
188
- * @param array $array
189
- * @return array
190
- * @uses EM_Object#get_default_search()
191
- */
192
- function get_default_search( $array = array() ){
193
- $defaults = array(
194
- 'status' => false,
195
- 'person' => true //to add later, search by person's tickets...
196
- );
197
- if( is_admin() ){
198
- //figure out default owning permissions
199
- $defaults['owner'] = !current_user_can('manage_others_bookings') ? get_current_user_id():false;
200
- }
201
- return apply_filters('em_tickets_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
202
- }
203
- }
204
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/phpmailer/class.phpmailer.php CHANGED
@@ -1,1506 +1,1506 @@
1
- <?php
2
- ////////////////////////////////////////////////////
3
- // PHPMailer - PHP email class
4
- //
5
- // Class for sending email using either
6
- // sendmail, PHP mail(), or SMTP. Methods are
7
- // based upon the standard AspEmail(tm) classes.
8
- //
9
- // Copyright (C) 2001 - 2003 Brent R. Matzelle
10
- //
11
- // License: LGPL, see LICENSE
12
- ////////////////////////////////////////////////////
13
-
14
- /**
15
- * PHPMailer - PHP email transport class
16
- * @package PHPMailer
17
- * @author Brent R. Matzelle
18
- * @copyright 2001 - 2003 Brent R. Matzelle
19
- */
20
- class EM_PHPMailer
21
- {
22
- /////////////////////////////////////////////////
23
- // PUBLIC VARIABLES
24
- /////////////////////////////////////////////////
25
-
26
- /**
27
- * Email priority (1 = High, 3 = Normal, 5 = low).
28
- * @var int
29
- */
30
- var $Priority = 3;
31
-
32
- /**
33
- * Sets the CharSet of the message.
34
- * @var string
35
- */
36
- var $CharSet = "iso-8859-1";
37
-
38
- /**
39
- * Sets the Content-type of the message.
40
- * @var string
41
- */
42
- var $ContentType = "text/plain";
43
-
44
- /**
45
- * Sets the Encoding of the message. Options for this are "8bit",
46
- * "7bit", "binary", "base64", and "quoted-printable".
47
- * @var string
48
- */
49
- var $Encoding = "8bit";
50
-
51
- /**
52
- * Holds the most recent mailer error message.
53
- * @var string
54
- */
55
- var $ErrorInfo = "";
56
-
57
- /**
58
- * Sets the From email address for the message.
59
- * @var string
60
- */
61
- var $From = "root@localhost";
62
-
63
- /**
64
- * Sets the From name of the message.
65
- * @var string
66
- */
67
- var $FromName = "Root User";
68
-
69
- /**
70
- * Sets the Sender email (Return-Path) of the message. If not empty,
71
- * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
72
- * @var string
73
- */
74
- var $Sender = "";
75
-
76
- /**
77
- * Sets the Subject of the message.
78
- * @var string
79
- */
80
- var $Subject = "";
81
-
82
- /**
83
- * Sets the Body of the message. This can be either an HTML or text body.
84
- * If HTML then run IsHTML(true).
85
- * @var string
86
- */
87
- var $Body = "";
88
-
89
- /**
90
- * Sets the text-only body of the message. This automatically sets the
91
- * email to multipart/alternative. This body can be read by mail
92
- * clients that do not have HTML email capability such as mutt. Clients
93
- * that can read HTML will view the normal Body.
94
- * @var string
95
- */
96
- var $AltBody = "";
97
-
98
- /**
99
- * Sets word wrapping on the body of the message to a given number of
100
- * characters.
101
- * @var int
102
- */
103
- var $WordWrap = 0;
104
-
105
- /**
106
- * Method to send mail: ("mail", "sendmail", or "smtp").
107
- * @var string
108
- */
109
- var $Mailer = "mail";
110
-
111
- /**
112
- * Sets the path of the sendmail program.
113
- * @var string
114
- */
115
- var $Sendmail = "/usr/sbin/sendmail";
116
-
117
- /**
118
- * Path to PHPMailer plugins. This is now only useful if the SMTP class
119
- * is in a different directory than the PHP include path.
120
- * @var string
121
- */
122
- var $PluginDir = "";
123
-
124
- /**
125
- * Holds PHPMailer version.
126
- * @var string
127
- */
128
- var $Version = "1.73";
129
-
130
- /**
131
- * Sets the email address that a reading confirmation will be sent.
132
- * @var string
133
- */
134
- var $ConfirmReadingTo = "";
135
-
136
- /**
137
- * Sets the hostname to use in Message-Id and Received headers
138
- * and as default HELO string. If empty, the value returned
139
- * by SERVER_NAME is used or 'localhost.localdomain'.
140
- * @var string
141
- */
142
- var $Hostname = "";
143
-
144
- /////////////////////////////////////////////////
145
- // SMTP VARIABLES
146
- /////////////////////////////////////////////////
147
-
148
- /**
149
- * Sets the SMTP hosts. All hosts must be separated by a
150
- * semicolon. You can also specify a different port
151
- * for each host by using this format: [hostname:port]
152
- * (e.g. "smtp1.example.com:25;smtp2.example.com").
153
- * Hosts will be tried in order.
154
- * @var string
155
- */
156
- var $Host = "localhost";
157
-
158
- /**
159
- * Sets the default SMTP server port.
160
- * @var int
161
- */
162
- var $Port = 25;
163
-
164
- /**
165
- * Sets the SMTP HELO of the message (Default is $Hostname).
166
- * @var string
167
- */
168
- var $Helo = "";
169
-
170
- /**
171
- * Sets SMTP authentication. Utilizes the Username and Password variables.
172
- * @var bool
173
- */
174
- var $SMTPAuth = false;
175
-
176
- /**
177
- * Sets SMTP username.
178
- * @var string
179
- */
180
- var $Username = "";
181
-
182
- /**
183
- * Sets SMTP password.
184
- * @var string
185
- */
186
- var $Password = "";
187
-
188
- /**
189
- * Sets the SMTP server timeout in seconds. This function will not
190
- * work with the win32 version.
191
- * @var int
192
- */
193
- var $Timeout = 10;
194
-
195
- /**
196
- * Sets SMTP class debugging on or off.
197
- * @var bool
198
- */
199
- var $SMTPDebug = false;
200
-
201
- /**
202
- * Prevents the SMTP connection from being closed after each mail
203
- * sending. If this is set to true then to close the connection
204
- * requires an explicit call to SmtpClose().
205
- * @var bool
206
- */
207
- var $SMTPKeepAlive = false;
208
-
209
- /**#@+
210
- * @access private
211
- */
212
- var $smtp = NULL;
213
- var $to = array();
214
- var $cc = array();
215
- var $bcc = array();
216
- var $ReplyTo = array();
217
- var $attachment = array();
218
- var $CustomHeader = array();
219
- var $message_type = "";
220
- var $boundary = array();
221
- var $language = array();
222
- var $error_count = 0;
223
- var $LE = "\n";
224
- /**#@-*/
225
-
226
- /////////////////////////////////////////////////
227
- // VARIABLE METHODS
228
- /////////////////////////////////////////////////
229
-
230
- /**
231
- * Sets message type to HTML.
232
- * @param bool $bool
233
- * @return void
234
- */
235
- function IsHTML($bool) {
236
- if($bool == true)
237
- $this->ContentType = "text/html";
238
- else
239
- $this->ContentType = "text/plain";
240
- }
241
-
242
- /**
243
- * Sets Mailer to send message using SMTP.
244
- * @return void
245
- */
246
- function IsSMTP() {
247
- $this->Mailer = "smtp";
248
- }
249
-
250
- /**
251
- * Sets Mailer to send message using PHP mail() function.
252
- * @return void
253
- */
254
- function IsMail() {
255
- $this->Mailer = "mail";
256
- }
257
-
258
- /**
259
- * Sets Mailer to send message using the $Sendmail program.
260
- * @return void
261
- */
262
- function IsSendmail() {
263
- $this->Mailer = "sendmail";
264
- }
265
-
266
- /**
267
- * Sets Mailer to send message using the qmail MTA.
268
- * @return void
269
- */
270
- function IsQmail() {
271
- $this->Sendmail = "/var/qmail/bin/sendmail";
272
- $this->Mailer = "sendmail";
273
- }
274
-
275
-
276
- /////////////////////////////////////////////////
277
- // RECIPIENT METHODS
278
- /////////////////////////////////////////////////
279
-
280
- /**
281
- * Adds a "To" address.
282
- * @param string $address
283
- * @param string $name
284
- * @return void
285
- */
286
- function AddAddress($address, $name = "") {
287
- $cur = count($this->to);
288
- $this->to[$cur][0] = trim($address);
289
- $this->to[$cur][1] = $name;
290
- }
291
-
292
- /**
293
- * Adds a "Cc" address. Note: this function works
294
- * with the SMTP mailer on win32, not with the "mail"
295
- * mailer.
296
- * @param string $address
297
- * @param string $name
298
- * @return void
299
- */
300
- function AddCC($address, $name = "") {
301
- $cur = count($this->cc);
302
- $this->cc[$cur][0] = trim($address);
303
- $this->cc[$cur][1] = $name;
304
- }
305
-
306
- /**
307
- * Adds a "Bcc" address. Note: this function works
308
- * with the SMTP mailer on win32, not with the "mail"
309
- * mailer.
310
- * @param string $address
311
- * @param string $name
312
- * @return void
313
- */
314
- function AddBCC($address, $name = "") {
315
- $cur = count($this->bcc);
316
- $this->bcc[$cur][0] = trim($address);
317
- $this->bcc[$cur][1] = $name;
318
- }
319
-
320
- /**
321
- * Adds a "Reply-to" address.
322
- * @param string $address
323
- * @param string $name
324
- * @return void
325
- */
326
- function AddReplyTo($address, $name = "") {
327
- $cur = count($this->ReplyTo);
328
- $this->ReplyTo[$cur][0] = trim($address);
329
- $this->ReplyTo[$cur][1] = $name;
330
- }
331
-
332
-
333
- /////////////////////////////////////////////////
334
- // MAIL SENDING METHODS
335
- /////////////////////////////////////////////////
336
-
337
- /**
338
- * Creates message and assigns Mailer. If the message is
339
- * not sent successfully then it returns false. Use the ErrorInfo
340
- * variable to view description of the error.
341
- * @return bool
342
- */
343
- function Send() {
344
- $header = "";
345
- $body = "";
346
- $result = true;
347
-
348
- if((count($this->to) + count($this->cc) + count($this->bcc)) < 1)
349
- {
350
- $this->SetError($this->Lang("provide_address"));
351
- return false;
352
- }
353
-
354
- // Set whether the message is multipart/alternative
355
- if(!empty($this->AltBody))
356
- $this->ContentType = "multipart/alternative";
357
-
358
- $this->error_count = 0; // reset errors
359
- $this->SetMessageType();
360
- $header .= $this->CreateHeader();
361
- $body = $this->CreateBody();
362
-
363
- if($body == "") { return false; }
364
-
365
- // Choose the mailer
366
- switch($this->Mailer)
367
- {
368
- case "sendmail":
369
- $result = $this->SendmailSend($header, $body);
370
- break;
371
- case "mail":
372
- $result = $this->MailSend($header, $body);
373
- break;
374
- case "smtp":
375
- $result = $this->SmtpSend($header, $body);
376
- break;
377
- default:
378
- $this->SetError($this->Mailer . $this->Lang("mailer_not_supported"));
379
- $result = false;
380
- break;
381
- }
382
-
383
- return $result;
384
- }
385
-
386
- /**
387
- * Sends mail using the $Sendmail program.
388
- * @access private
389
- * @return bool
390
- */
391
- function SendmailSend($header, $body) {
392
- if ($this->Sender != "")
393
- $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender);
394
- else
395
- $sendmail = sprintf("%s -oi -t", $this->Sendmail);
396
-
397
- if(!@$mail = popen($sendmail, "w"))
398
- {
399
- $this->SetError($this->Lang("execute") . $this->Sendmail);
400
- return false;
401
- }
402
-
403
- fputs($mail, $header);
404
- fputs($mail, $body);
405
-
406
- $result = pclose($mail) >> 8 & 0xFF;
407
- if($result != 0)
408
- {
409
- $this->SetError($this->Lang("execute") . $this->Sendmail);
410
- return false;
411
- }
412
-
413
- return true;
414
- }
415
-
416
- /**
417
- * Sends mail using the PHP mail() function.
418
- * @access private
419
- * @return bool
420
- */
421
- function MailSend($header, $body) {
422
- $to = "";
423
- for($i = 0; $i < count($this->to); $i++)
424
- {
425
- if($i != 0) { $to .= ", "; }
426
- $to .= $this->to[$i][0];
427
- }
428
-
429
- if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
430
- {
431
- $old_from = ini_get("sendmail_from");
432
- ini_set("sendmail_from", $this->Sender);
433
- $params = sprintf("-oi -f %s", $this->Sender);
434
- $rt = @mail($to, $this->EncodeHeader($this->Subject), $body,
435
- $header, $params);
436
- }
437
- else
438
- $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header);
439
-
440
- if (isset($old_from))
441
- ini_set("sendmail_from", $old_from);
442
-
443
- if(!$rt)
444
- {
445
- $this->SetError($this->Lang("instantiate"));
446
- return false;
447
- }
448
-
449
- return true;
450
- }
451
-
452
- /**
453
- * Sends mail via SMTP using PhpSMTP (Author:
454
- * Chris Ryan). Returns bool. Returns false if there is a
455
- * bad MAIL FROM, RCPT, or DATA input.
456
- * @access private
457
- * @return bool
458
- */
459
- function SmtpSend($header, $body) {
460
- include_once($this->PluginDir . "class.smtp.php");
461
- $error = "";
462
- $bad_rcpt = array();
463
-
464
- if(!$this->SmtpConnect())
465
- return false;
466
-
467
- $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
468
- if(!$this->smtp->Mail($smtp_from))
469
- {
470
- $error = $this->Lang("from_failed") . $smtp_from;
471
- $this->SetError($error);
472
- $this->smtp->Reset();
473
- return false;
474
- }
475
-
476
- // Attempt to send attach all recipients
477
- for($i = 0; $i < count($this->to); $i++)
478
- {
479
- if(!$this->smtp->Recipient($this->to[$i][0]))
480
- $bad_rcpt[] = $this->to[$i][0];
481
- }
482
- for($i = 0; $i < count($this->cc); $i++)
483
- {
484
- if(!$this->smtp->Recipient($this->cc[$i][0]))
485
- $bad_rcpt[] = $this->cc[$i][0];
486
- }
487
- for($i = 0; $i < count($this->bcc); $i++)
488
- {
489
- if(!$this->smtp->Recipient($this->bcc[$i][0]))
490
- $bad_rcpt[] = $this->bcc[$i][0];
491
- }
492
-
493
- if(count($bad_rcpt) > 0) // Create error message
494
- {
495
- for($i = 0; $i < count($bad_rcpt); $i++)
496
- {
497
- if($i != 0) { $error .= ", "; }
498
- $error .= $bad_rcpt[$i];
499
- }
500
- $error = $this->Lang("recipients_failed") . $error;
501
- $this->SetError($error);
502
- $this->smtp->Reset();
503
- return false;
504
- }
505
-
506
- if(!$this->smtp->Data($header . $body))
507
- {
508
- $this->SetError($this->Lang("data_not_accepted"));
509
- $this->smtp->Reset();
510
- return false;
511
- }
512
- if($this->SMTPKeepAlive == true)
513
- $this->smtp->Reset();
514
- else
515
- $this->SmtpClose();
516
-
517
- return true;
518
- }
519
-
520
- /**
521
- * Initiates a connection to an SMTP server. Returns false if the
522
- * operation failed.
523
- * @access private
524
- * @return bool
525
- */
526
- function SmtpConnect() {
527
- if($this->smtp == NULL) { $this->smtp = new EM_SMTP(); }
528
-
529
- $this->smtp->do_debug = $this->SMTPDebug;
530
- $hosts = explode(";", $this->Host);
531
- $index = 0;
532
- $connection = ($this->smtp->Connected());
533
-
534
- // Retry while there is no connection
535
- while($index < count($hosts) && $connection == false)
536
- {
537
- if(strstr($hosts[$index], ":"))
538
- {
539
- $hostA = explode(':', $hosts[$index]);
540
- if (is_numeric(end($hostA)))
541
- $port = array_pop($hostA);
542
- else
543
- $port = $this->Port;
544
- $host = implode(':', $hostA);
545
- }
546
- else
547
- {
548
- $host = $hosts[$index];
549
- $port = $this->Port;
550
- }
551
-
552
- if($this->smtp->Connect($host, $port, $this->Timeout))
553
- {
554
- if ($this->Helo != '')
555
- $this->smtp->Hello($this->Helo);
556
- else
557
- $this->smtp->Hello($this->ServerHostname());
558
-
559
- if($this->SMTPAuth)
560
- {
561
- if(!$this->smtp->Authenticate($this->Username,
562
- $this->Password))
563
- {
564
- $this->SetError($this->Lang("authenticate"));
565
- $this->smtp->Reset();
566
- $connection = false;
567
- }
568
- }
569
- $connection = true;
570
- }
571
- $index++;
572
- }
573
- if(!$connection)
574
- $this->SetError($this->Lang("connect_host"));
575
-
576
- return $connection;
577
- }
578
-
579
- /**
580
- * Closes the active SMTP session if one exists.
581
- * @return void
582
- */
583
- function SmtpClose() {
584
- if($this->smtp != NULL)
585
- {
586
- if($this->smtp->Connected())
587
- {
588
- $this->smtp->Quit();
589
- $this->smtp->Close();
590
- }
591
- }
592
- }
593
-
594
- /**
595
- * Sets the language for all class error messages. Returns false
596
- * if it cannot load the language file. The default language type
597
- * is English.
598
- * @param string $lang_type Type of language (e.g. Portuguese: "br")
599
- * @param string $lang_path Path to the language file directory
600
- * @access public
601
- * @return bool
602
- */
603
- function SetLanguage($lang_type, $lang_path = "language/") {
604
- if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php'))
605
- include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
606
- else if(file_exists($lang_path.'phpmailer.lang-en.php'))
607
- include($lang_path.'phpmailer.lang-en.php');
608
- else
609
- {
610
- $this->SetError("Could not load language file");
611
- return false;
612
- }
613
- $this->language = $PHPMAILER_LANG;
614
-
615
- return true;
616
- }
617
-
618
- /////////////////////////////////////////////////
619
- // MESSAGE CREATION METHODS
620
- /////////////////////////////////////////////////
621
-
622
- /**
623
- * Creates recipient headers.
624
- * @access private
625
- * @return string
626
- */
627
- function AddrAppend($type, $addr) {
628
- $addr_str = $type . ": ";
629
- $addr_str .= $this->AddrFormat($addr[0]);
630
- if(count($addr) > 1)
631
- {
632
- for($i = 1; $i < count($addr); $i++)
633
- $addr_str .= ", " . $this->AddrFormat($addr[$i]);
634
- }
635
- $addr_str .= $this->LE;
636
-
637
- return $addr_str;
638
- }
639
-
640
- /**
641
- * Formats an address correctly.
642
- * @access private
643
- * @return string
644
- */
645
- function AddrFormat($addr) {
646
- if(empty($addr[1]))
647
- $formatted = $addr[0];
648
- else
649
- {
650
- $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" .
651
- $addr[0] . ">";
652
- }
653
-
654
- return $formatted;
655
- }
656
-
657
- /**
658
- * Wraps message for use with mailers that do not
659
- * automatically perform wrapping and for quoted-printable.
660
- * Original written by philippe.
661
- * @access private
662
- * @return string
663
- */
664
- function WrapText($message, $length, $qp_mode = false) {
665
- $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
666
-
667
- $message = $this->FixEOL($message);
668
- if (substr($message, -1) == $this->LE)
669
- $message = substr($message, 0, -1);
670
-
671
- $line = explode($this->LE, $message);
672
- $message = "";
673
- for ($i=0 ;$i < count($line); $i++)
674
- {
675
- $line_part = explode(" ", $line[$i]);
676
- $buf = "";
677
- for ($e = 0; $e<count($line_part); $e++)
678
- {
679
- $word = $line_part[$e];
680
- if ($qp_mode and (strlen($word) > $length))
681
- {
682
- $space_left = $length - strlen($buf) - 1;
683
- if ($e != 0)
684
- {
685
- if ($space_left > 20)
686
- {
687
- $len = $space_left;
688
- if (substr($word, $len - 1, 1) == "=")
689
- $len--;
690
- elseif (substr($word, $len - 2, 1) == "=")
691
- $len -= 2;
692
- $part = substr($word, 0, $len);
693
- $word = substr($word, $len);
694
- $buf .= " " . $part;
695
- $message .= $buf . sprintf("=%s", $this->LE);
696
- }
697
- else
698
- {
699
- $message .= $buf . $soft_break;
700
- }
701
- $buf = "";
702
- }
703
- while (strlen($word) > 0)
704
- {
705
- $len = $length;
706
- if (substr($word, $len - 1, 1) == "=")
707
- $len--;
708
- elseif (substr($word, $len - 2, 1) == "=")
709
- $len -= 2;
710
- $part = substr($word, 0, $len);
711
- $word = substr($word, $len);
712
-
713
- if (strlen($word) > 0)
714
- $message .= $part . sprintf("=%s", $this->LE);
715
- else
716
- $buf = $part;
717
- }
718
- }
719
- else
720
- {
721
- $buf_o = $buf;
722
- $buf .= ($e == 0) ? $word : (" " . $word);
723
-
724
- if (strlen($buf) > $length and $buf_o != "")
725
- {
726
- $message .= $buf_o . $soft_break;
727
- $buf = $word;
728
- }
729
- }
730
- }
731
- $message .= $buf . $this->LE;
732
- }
733
-
734
- return $message;
735
- }
736
-
737
- /**
738
- * Set the body wrapping.
739
- * @access private
740
- * @return void
741
- */
742
- function SetWordWrap() {
743
- if($this->WordWrap < 1)
744
- return;
745
-
746
- switch($this->message_type)
747
- {
748
- case "alt":
749
- // fall through
750
- case "alt_attachments":
751
- $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
752
- break;
753
- default:
754
- $this->Body = $this->WrapText($this->Body, $this->WordWrap);
755
- break;
756
- }
757
- }
758
-
759
- /**
760
- * Assembles message header.
761
- * @access private
762
- * @return string
763
- */
764
- function CreateHeader() {
765
- $result = "";
766
-
767
- // Set the boundaries
768
- $uniq_id = md5(uniqid(time()));
769
- $this->boundary[1] = "b1_" . $uniq_id;
770
- $this->boundary[2] = "b2_" . $uniq_id;
771
-
772
- $result .= $this->HeaderLine("Date", $this->RFCDate());
773
- if($this->Sender == "")
774
- $result .= $this->HeaderLine("Return-Path", trim($this->From));
775
- else
776
- $result .= $this->HeaderLine("Return-Path", trim($this->Sender));
777
-
778
- // To be created automatically by mail()
779
- if($this->Mailer != "mail")
780
- {
781
- if(count($this->to) > 0)
782
- $result .= $this->AddrAppend("To", $this->to);
783
- else if (count($this->cc) == 0)
784
- $result .= $this->HeaderLine("To", "undisclosed-recipients:;");
785
- if(count($this->cc) > 0)
786
- $result .= $this->AddrAppend("Cc", $this->cc);
787
- }
788
-
789
- $from = array();
790
- $from[0][0] = trim($this->From);
791
- $from[0][1] = $this->FromName;
792
- $result .= $this->AddrAppend("From", $from);
793
-
794
- // sendmail and mail() extract Bcc from the header before sending
795
- if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))
796
- $result .= $this->AddrAppend("Bcc", $this->bcc);
797
-
798
- if(count($this->ReplyTo) > 0)
799
- $result .= $this->AddrAppend("Reply-to", $this->ReplyTo);
800
-
801
- // mail() sets the subject itself
802
- if($this->Mailer != "mail")
803
- $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject)));
804
-
805
- $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
806
- $result .= $this->HeaderLine("X-Priority", $this->Priority);
807
- $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]");
808
-
809
- if($this->ConfirmReadingTo != "")
810
- {
811
- $result .= $this->HeaderLine("Disposition-Notification-To",
812
- "<" . trim($this->ConfirmReadingTo) . ">");
813
- }
814
-
815
- // Add custom headers
816
- for($index = 0; $index < count($this->CustomHeader); $index++)
817
- {
818
- $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]),
819
- $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
820
- }
821
- $result .= $this->HeaderLine("MIME-Version", "1.0");
822
-
823
- switch($this->message_type)
824
- {
825
- case "plain":
826
- $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
827
- $result .= sprintf("Content-Type: %s; charset=\"%s\"",
828
- $this->ContentType, $this->CharSet);
829
- break;
830
- case "attachments":
831
- // fall through
832
- case "alt_attachments":
833
- if($this->InlineImageExists())
834
- {
835
- $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
836
- "multipart/related", $this->LE, $this->LE,
837
- $this->boundary[1], $this->LE);
838
- }
839
- else
840
- {
841
- $result .= $this->HeaderLine("Content-Type", "multipart/mixed;");
842
- $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
843
- }
844
- break;
845
- case "alt":
846
- $result .= $this->HeaderLine("Content-Type", "multipart/alternative;");
847
- $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
848
- break;
849
- }
850
-
851
- if($this->Mailer != "mail")
852
- $result .= $this->LE.$this->LE;
853
-
854
- return $result;
855
- }
856
-
857
- /**
858
- * Assembles the message body. Returns an empty string on failure.
859
- * @access private
860
- * @return string
861
- */
862
- function CreateBody() {
863
- $result = "";
864
-
865
- $this->SetWordWrap();
866
-
867
- switch($this->message_type)
868
- {
869
- case "alt":
870
- $result .= $this->GetBoundary($this->boundary[1], "",
871
- "text/plain", "");
872
- $result .= $this->EncodeString($this->AltBody, $this->Encoding);
873
- $result .= $this->LE.$this->LE;
874
- $result .= $this->GetBoundary($this->boundary[1], "",
875
- "text/html", "");
876
-
877
- $result .= $this->EncodeString($this->Body, $this->Encoding);
878
- $result .= $this->LE.$this->LE;
879
-
880
- $result .= $this->EndBoundary($this->boundary[1]);
881
- break;
882
- case "plain":
883
- $result .= $this->EncodeString($this->Body, $this->Encoding);
884
- break;
885
- case "attachments":
886
- $result .= $this->GetBoundary($this->boundary[1], "", "", "");
887
- $result .= $this->EncodeString($this->Body, $this->Encoding);
888
- $result .= $this->LE;
889
-
890
- $result .= $this->AttachAll();
891
- break;
892
- case "alt_attachments":
893
- $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
894
- $result .= sprintf("Content-Type: %s;%s" .
895
- "\tboundary=\"%s\"%s",
896
- "multipart/alternative", $this->LE,
897
- $this->boundary[2], $this->LE.$this->LE);
898
-
899
- // Create text body
900
- $result .= $this->GetBoundary($this->boundary[2], "",
901
- "text/plain", "") . $this->LE;
902
-
903
- $result .= $this->EncodeString($this->AltBody, $this->Encoding);
904
- $result .= $this->LE.$this->LE;
905
-
906
- // Create the HTML body
907
- $result .= $this->GetBoundary($this->boundary[2], "",
908
- "text/html", "") . $this->LE;
909
-
910
- $result .= $this->EncodeString($this->Body, $this->Encoding);
911
- $result .= $this->LE.$this->LE;
912
-
913
- $result .= $this->EndBoundary($this->boundary[2]);
914
-
915
- $result .= $this->AttachAll();
916
- break;
917
- }
918
- if($this->IsError())
919
- $result = "";
920
-
921
- return $result;
922
- }
923
-
924
- /**
925
- * Returns the start of a message boundary.
926
- * @access private
927
- */
928
- function GetBoundary($boundary, $charSet, $contentType, $encoding) {
929
- $result = "";
930
- if($charSet == "") { $charSet = $this->CharSet; }
931
- if($contentType == "") { $contentType = $this->ContentType; }
932
- if($encoding == "") { $encoding = $this->Encoding; }
933
-
934
- $result .= $this->TextLine("--" . $boundary);
935
- $result .= sprintf("Content-Type: %s; charset = \"%s\"",
936
- $contentType, $charSet);
937
- $result .= $this->LE;
938
- $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding);
939
- $result .= $this->LE;
940
-
941
- return $result;
942
- }
943
-
944
- /**
945
- * Returns the end of a message boundary.
946
- * @access private
947
- */
948
- function EndBoundary($boundary) {
949
- return $this->LE . "--" . $boundary . "--" . $this->LE;
950
- }
951
-
952
- /**
953
- * Sets the message type.
954
- * @access private
955
- * @return void
956
- */
957
- function SetMessageType() {
958
- if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
959
- $this->message_type = "plain";
960
- else
961
- {
962
- if(count($this->attachment) > 0)
963
- $this->message_type = "attachments";
964
- if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)
965
- $this->message_type = "alt";
966
- if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)
967
- $this->message_type = "alt_attachments";
968
- }
969
- }
970
-
971
- /**
972
- * Returns a formatted header line.
973
- * @access private
974
- * @return string
975
- */
976
- function HeaderLine($name, $value) {
977
- return $name . ": " . $value . $this->LE;
978
- }
979
-
980
- /**
981
- * Returns a formatted mail line.
982
- * @access private
983
- * @return string
984
- */
985
- function TextLine($value) {
986
- return $value . $this->LE;
987
- }
988
-
989
- /////////////////////////////////////////////////
990
- // ATTACHMENT METHODS
991
- /////////////////////////////////////////////////
992
-
993
- /**
994
- * Adds an attachment from a path on the filesystem.
995
- * Returns false if the file could not be found
996
- * or accessed.
997
- * @param string $path Path to the attachment.
998
- * @param string $name Overrides the attachment name.
999
- * @param string $encoding File encoding (see $Encoding).
1000
- * @param string $type File extension (MIME) type.
1001
- * @return bool
1002
- */
1003
- function AddAttachment($path, $name = "", $encoding = "base64",
1004
- $type = "application/octet-stream") {
1005
- if(!@is_file($path))
1006
- {
1007
- $this->SetError($this->Lang("file_access") . $path);
1008
- return false;
1009
- }
1010
-
1011
- $filename = basename($path);
1012
- if($name == "")
1013
- $name = $filename;
1014
-
1015
- $cur = count($this->attachment);
1016
- $this->attachment[$cur][0] = $path;
1017
- $this->attachment[$cur][1] = $filename;
1018
- $this->attachment[$cur][2] = $name;
1019
- $this->attachment[$cur][3] = $encoding;
1020
- $this->attachment[$cur][4] = $type;
1021
- $this->attachment[$cur][5] = false; // isStringAttachment
1022
- $this->attachment[$cur][6] = "attachment";
1023
- $this->attachment[$cur][7] = 0;
1024
-
1025
- return true;
1026
- }
1027
-
1028
- /**
1029
- * Attaches all fs, string, and binary attachments to the message.
1030
- * Returns an empty string on failure.
1031
- * @access private
1032
- * @return string
1033
- */
1034
- function AttachAll() {
1035
- // Return text of body
1036
- $mime = array();
1037
-
1038
- // Add all attachments
1039
- for($i = 0; $i < count($this->attachment); $i++)
1040
- {
1041
- // Check for string attachment
1042
- $bString = $this->attachment[$i][5];
1043
- if ($bString)
1044
- $string = $this->attachment[$i][0];
1045
- else
1046
- $path = $this->attachment[$i][0];
1047
-
1048
- $filename = $this->attachment[$i][1];
1049
- $name = $this->attachment[$i][2];
1050
- $encoding = $this->attachment[$i][3];
1051
- $type = $this->attachment[$i][4];
1052
- $disposition = $this->attachment[$i][6];
1053
- $cid = $this->attachment[$i][7];
1054
-
1055
- $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
1056
- $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
1057
- $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1058
-
1059
- if($disposition == "inline")
1060
- $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
1061
-
1062
- $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s",
1063
- $disposition, $name, $this->LE.$this->LE);
1064
-
1065
- // Encode as string attachment
1066
- if($bString)
1067
- {
1068
- $mime[] = $this->EncodeString($string, $encoding);
1069
- if($this->IsError()) { return ""; }
1070
- $mime[] = $this->LE.$this->LE;
1071
- }
1072
- else
1073
- {
1074
- $mime[] = $this->EncodeFile($path, $encoding);
1075
- if($this->IsError()) { return ""; }
1076
- $mime[] = $this->LE.$this->LE;
1077
- }
1078
- }
1079
-
1080
- $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
1081
-
1082
- return join("", $mime);
1083
- }
1084
-
1085
- /**
1086
- * Encodes attachment in requested format. Returns an
1087
- * empty string on failure.
1088
- * @access private
1089
- * @return string
1090
- */
1091
- function EncodeFile ($path, $encoding = "base64") {
1092
- if(!@$fd = fopen($path, "rb"))
1093
- {
1094
- $this->SetError($this->Lang("file_open") . $path);
1095
- return "";
1096
- }
1097
- $magic_quotes = get_magic_quotes_runtime();
1098
- set_magic_quotes_runtime(0);
1099
- $file_buffer = fread($fd, filesize($path));
1100
- $file_buffer = $this->EncodeString($file_buffer, $encoding);
1101
- fclose($fd);
1102
- set_magic_quotes_runtime($magic_quotes);
1103
-
1104
- return $file_buffer;
1105
- }
1106
-
1107
- /**
1108
- * Encodes string to requested format. Returns an
1109
- * empty string on failure.
1110
- * @access private
1111
- * @return string
1112
- */
1113
- function EncodeString ($str, $encoding = "base64") {
1114
- $encoded = "";
1115
- switch(strtolower($encoding)) {
1116
- case "base64":
1117
- // chunk_split is found in PHP >= 3.0.6
1118
- $encoded = chunk_split(base64_encode($str), 76, $this->LE);
1119
- break;
1120
- case "7bit":
1121
- case "8bit":
1122
- $encoded = $this->FixEOL($str);
1123
- if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1124
- $encoded .= $this->LE;
1125
- break;
1126
- case "binary":
1127
- $encoded = $str;
1128
- break;
1129
- case "quoted-printable":
1130
- $encoded = $this->EncodeQP($str);
1131
- break;
1132
- default:
1133
- $this->SetError($this->Lang("encoding") . $encoding);
1134
- break;
1135
- }
1136
- return $encoded;
1137
- }
1138
-
1139
- /**
1140
- * Encode a header string to best of Q, B, quoted or none.
1141
- * @access private
1142
- * @return string
1143
- */
1144
- function EncodeHeader ($str, $position = 'text') {
1145
- $x = 0;
1146
-
1147
- switch (strtolower($position)) {
1148
- case 'phrase':
1149
- if (!preg_match('/[\200-\377]/', $str)) {
1150
- // Can't use addslashes as we don't know what value has magic_quotes_sybase.
1151
- $encoded = addcslashes($str, "\0..\37\177\\\"");
1152
-
1153
- if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
1154
- return ($encoded);
1155
- else
1156
- return ("\"$encoded\"");
1157
- }
1158
- $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
1159
- break;
1160
- case 'comment':
1161
- $x = preg_match_all('/[()"]/', $str, $matches);
1162
- // Fall-through
1163
- case 'text':
1164
- default:
1165
- $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1166
- break;
1167
- }
1168
-
1169
- if ($x == 0)
1170
- return ($str);
1171
-
1172
- $maxlen = 75 - 7 - strlen($this->CharSet);
1173
- // Try to select the encoding which should produce the shortest output
1174
- if (strlen($str)/3 < $x) {
1175
- $encoding = 'B';
1176
- $encoded = base64_encode($str);
1177
- $maxlen -= $maxlen % 4;
1178
- $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
1179
- } else {
1180
- $encoding = 'Q';
1181
- $encoded = $this->EncodeQ($str, $position);
1182
- $encoded = $this->WrapText($encoded, $maxlen, true);
1183
- $encoded = str_replace("=".$this->LE, "\n", trim($encoded));
1184
- }
1185
-
1186
- $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
1187
- $encoded = trim(str_replace("\n", $this->LE, $encoded));
1188
-
1189
- return $encoded;
1190
- }
1191
-
1192
- /**
1193
- * Encode string to quoted-printable.
1194
- * @access private
1195
- * @return string
1196
- */
1197
- function EncodeQP ($str) {
1198
- $encoded = $this->FixEOL($str);
1199
- if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1200
- $encoded .= $this->LE;
1201
-
1202
- // Replace every high ascii, control and = characters
1203
- $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
1204
- "'='.sprintf('%02X', ord('\\1'))", $encoded);
1205
- // Replace every spaces and tabs when it's the last character on a line
1206
- $encoded = preg_replace("/([\011\040])".$this->LE."/e",
1207
- "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
1208
-
1209
- // Maximum line length of 76 characters before CRLF (74 + space + '=')
1210
- $encoded = $this->WrapText($encoded, 74, true);
1211
-
1212
- return $encoded;
1213
- }
1214
-
1215
- /**
1216
- * Encode string to q encoding.
1217
- * @access private
1218
- * @return string
1219
- */
1220
- function EncodeQ ($str, $position = "text") {
1221
- // There should not be any EOL in the string
1222
- $encoded = preg_replace("[\r\n]", "", $str);
1223
-
1224
- switch (strtolower($position)) {
1225
- case "phrase":
1226
- $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1227
- break;
1228
- case "comment":
1229
- $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1230
- case "text":
1231
- default:
1232
- // Replace every high ascii, control =, ? and _ characters
1233
- $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1234
- "'='.sprintf('%02X', ord('\\1'))", $encoded);
1235
- break;
1236
- }
1237
-
1238
- // Replace every spaces to _ (more readable than =20)
1239
- $encoded = str_replace(" ", "_", $encoded);
1240
-
1241
- return $encoded;
1242
- }
1243
-
1244
- /**
1245
- * Adds a string or binary attachment (non-filesystem) to the list.
1246
- * This method can be used to attach ascii or binary data,
1247
- * such as a BLOB record from a database.
1248
- * @param string $string String attachment data.
1249
- * @param string $filename Name of the attachment.
1250
- * @param string $encoding File encoding (see $Encoding).
1251
- * @param string $type File extension (MIME) type.
1252
- * @return void
1253
- */
1254
- function AddStringAttachment($string, $filename, $encoding = "base64",
1255
- $type = "application/octet-stream") {
1256
- // Append to $attachment array
1257
- $cur = count($this->attachment);
1258
- $this->attachment[$cur][0] = $string;
1259
- $this->attachment[$cur][1] = $filename;
1260
- $this->attachment[$cur][2] = $filename;
1261
- $this->attachment[$cur][3] = $encoding;
1262
- $this->attachment[$cur][4] = $type;
1263
- $this->attachment[$cur][5] = true; // isString
1264
- $this->attachment[$cur][6] = "attachment";
1265
- $this->attachment[$cur][7] = 0;
1266
- }
1267
-
1268
- /**
1269
- * Adds an embedded attachment. This can include images, sounds, and
1270
- * just about any other document. Make sure to set the $type to an
1271
- * image type. For JPEG images use "image/jpeg" and for GIF images
1272
- * use "image/gif".
1273
- * @param string $path Path to the attachment.
1274
- * @param string $cid Content ID of the attachment. Use this to identify
1275
- * the Id for accessing the image in an HTML form.
1276
- * @param string $name Overrides the attachment name.
1277
- * @param string $encoding File encoding (see $Encoding).
1278
- * @param string $type File extension (MIME) type.
1279
- * @return bool
1280
- */
1281
- function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64",
1282
- $type = "application/octet-stream") {
1283
-
1284
- if(!@is_file($path))
1285
- {
1286
- $this->SetError($this->Lang("file_access") . $path);
1287
- return false;
1288
- }
1289
-
1290
- $filename = basename($path);
1291
- if($name == "")
1292
- $name = $filename;
1293
-
1294
- // Append to $attachment array
1295
- $cur = count($this->attachment);
1296
- $this->attachment[$cur][0] = $path;
1297
- $this->attachment[$cur][1] = $filename;
1298
- $this->attachment[$cur][2] = $name;
1299
- $this->attachment[$cur][3] = $encoding;
1300
- $this->attachment[$cur][4] = $type;
1301
- $this->attachment[$cur][5] = false; // isStringAttachment
1302
- $this->attachment[$cur][6] = "inline";
1303
- $this->attachment[$cur][7] = $cid;
1304
-
1305
- return true;
1306
- }
1307
-
1308
- /**
1309
- * Returns true if an inline attachment is present.
1310
- * @access private
1311
- * @return bool
1312
- */
1313
- function InlineImageExists() {
1314
- $result = false;
1315
- for($i = 0; $i < count($this->attachment); $i++)
1316
- {
1317
- if($this->attachment[$i][6] == "inline")
1318
- {
1319
- $result = true;
1320
- break;
1321
- }
1322
- }
1323
-
1324
- return $result;
1325
- }
1326
-
1327
- /////////////////////////////////////////////////
1328
- // MESSAGE RESET METHODS
1329
- /////////////////////////////////////////////////
1330
-
1331
- /**
1332
- * Clears all recipients assigned in the TO array. Returns void.
1333
- * @return void
1334
- */
1335
- function ClearAddresses() {
1336
- $this->to = array();
1337
- }
1338
-
1339
- /**
1340
- * Clears all recipients assigned in the CC array. Returns void.
1341
- * @return void
1342
- */
1343
- function ClearCCs() {
1344
- $this->cc = array();
1345
- }
1346
-
1347
- /**
1348
- * Clears all recipients assigned in the BCC array. Returns void.
1349
- * @return void
1350
- */
1351
- function ClearBCCs() {
1352
- $this->bcc = array();
1353
- }
1354
-
1355
- /**
1356
- * Clears all recipients assigned in the ReplyTo array. Returns void.
1357
- * @return void
1358
- */
1359
- function ClearReplyTos() {
1360
- $this->ReplyTo = array();
1361
- }
1362
-
1363
- /**
1364
- * Clears all recipients assigned in the TO, CC and BCC
1365
- * array. Returns void.
1366
- * @return void
1367
- */
1368
- function ClearAllRecipients() {
1369
- $this->to = array();
1370
- $this->cc = array();
1371
- $this->bcc = array();
1372
- }
1373
-
1374
- /**
1375
- * Clears all previously set filesystem, string, and binary
1376
- * attachments. Returns void.
1377
- * @return void
1378
- */
1379
- function ClearAttachments() {
1380
- $this->attachment = array();
1381
- }
1382
-
1383
- /**
1384
- * Clears all custom headers. Returns void.
1385
- * @return void
1386
- */
1387
- function ClearCustomHeaders() {
1388
- $this->CustomHeader = array();
1389
- }
1390
-
1391
-
1392
- /////////////////////////////////////////////////
1393
- // MISCELLANEOUS METHODS
1394
- /////////////////////////////////////////////////
1395
-
1396
- /**
1397
- * Adds the error message to the error container.
1398
- * Returns void.
1399
- * @access private
1400
- * @return void
1401
- */
1402
- function SetError($msg) {
1403
- $this->error_count++;
1404
- $this->ErrorInfo = $msg;
1405
- }
1406
-
1407
- /**
1408
- * Returns the proper RFC 822 formatted date.
1409
- * @access private
1410
- * @return string
1411
- */
1412
- function RFCDate() {
1413
- $tz = date("Z");
1414
- $tzs = ($tz < 0) ? "-" : "+";
1415
- $tz = abs($tz);
1416
- $tz = ($tz/3600)*100 + ($tz%3600)/60;
1417
- $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
1418
-
1419
- return $result;
1420
- }
1421
-
1422
- /**
1423
- * Returns the appropriate server variable. Should work with both
1424
- * PHP 4.1.0+ as well as older versions. Returns an empty string
1425
- * if nothing is found.
1426
- * @access private
1427
- * @return mixed
1428
- */
1429
- function ServerVar($varName) {
1430
- global $HTTP_SERVER_VARS;
1431
- global $HTTP_ENV_VARS;
1432
-
1433
- if(!isset($_SERVER))
1434
- {
1435
- $_SERVER = $HTTP_SERVER_VARS;
1436
- if(!isset($_SERVER["REMOTE_ADDR"]))
1437
- $_SERVER = $HTTP_ENV_VARS; // must be Apache
1438
- }
1439
-
1440
- if(isset($_SERVER[$varName]))
1441
- return $_SERVER[$varName];
1442
- else
1443
- return "";
1444
- }
1445
-
1446
- /**
1447
- * Returns the server hostname or 'localhost.localdomain' if unknown.
1448
- * @access private
1449
- * @return string
1450
- */
1451
- function ServerHostname() {
1452
- if ($this->Hostname != "")
1453
- $result = $this->Hostname;
1454
- elseif ($this->ServerVar('SERVER_NAME') != "")
1455
- $result = $this->ServerVar('SERVER_NAME');
1456
- else
1457
- $result = "localhost.localdomain";
1458
-
1459
- return $result;
1460
- }
1461
-
1462
- /**
1463
- * Returns a message in the appropriate language.
1464
- * @access private
1465
- * @return string
1466
- */
1467
- function Lang($key) {
1468
- if(count($this->language) < 1)
1469
- $this->SetLanguage("en"); // set the default language
1470
-
1471
- if(isset($this->language[$key]))
1472
- return $this->language[$key];
1473
- else
1474
- return "Language string failed to load: " . $key;
1475
- }
1476
-
1477
- /**
1478
- * Returns true if an error occurred.
1479
- * @return bool
1480
- */
1481
- function IsError() {
1482
- return ($this->error_count > 0);
1483
- }
1484
-
1485
- /**
1486
- * Changes every end of line from CR or LF to CRLF.
1487
- * @access private
1488
- * @return string
1489
- */
1490
- function FixEOL($str) {
1491
- $str = str_replace("\r\n", "\n", $str);
1492
- $str = str_replace("\r", "\n", $str);
1493
- $str = str_replace("\n", $this->LE, $str);
1494
- return $str;
1495
- }
1496
-
1497
- /**
1498
- * Adds a custom header.
1499
- * @return void
1500
- */
1501
- function AddCustomHeader($custom_header) {
1502
- $this->CustomHeader[] = explode(":", $custom_header, 2);
1503
- }
1504
- }
1505
-
1506
- ?>
1
+ <?php
2
+ ////////////////////////////////////////////////////
3
+ // PHPMailer - PHP email class
4
+ //
5
+ // Class for sending email using either
6
+ // sendmail, PHP mail(), or SMTP. Methods are
7
+ // based upon the standard AspEmail(tm) classes.
8
+ //
9
+ // Copyright (C) 2001 - 2003 Brent R. Matzelle
10
+ //
11
+ // License: LGPL, see LICENSE
12
+ ////////////////////////////////////////////////////
13
+
14
+ /**
15
+ * PHPMailer - PHP email transport class
16
+ * @package PHPMailer
17
+ * @author Brent R. Matzelle
18
+ * @copyright 2001 - 2003 Brent R. Matzelle
19
+ */
20
+ class EM_PHPMailer
21
+ {
22
+ /////////////////////////////////////////////////
23
+ // PUBLIC VARIABLES
24
+ /////////////////////////////////////////////////
25
+
26
+ /**
27
+ * Email priority (1 = High, 3 = Normal, 5 = low).
28
+ * @var int
29
+ */
30
+ var $Priority = 3;
31
+
32
+ /**
33
+ * Sets the CharSet of the message.
34
+ * @var string
35
+ */
36
+ var $CharSet = "iso-8859-1";
37
+
38
+ /**
39
+ * Sets the Content-type of the message.
40
+ * @var string
41
+ */
42
+ var $ContentType = "text/plain";
43
+
44
+ /**
45
+ * Sets the Encoding of the message. Options for this are "8bit",
46
+ * "7bit", "binary", "base64", and "quoted-printable".
47
+ * @var string
48
+ */
49
+ var $Encoding = "8bit";
50
+
51
+ /**
52
+ * Holds the most recent mailer error message.
53
+ * @var string
54
+ */
55
+ var $ErrorInfo = "";
56
+
57
+ /**
58
+ * Sets the From email address for the message.
59
+ * @var string
60
+ */
61
+ var $From = "root@localhost";
62
+
63
+ /**
64
+ * Sets the From name of the message.
65
+ * @var string
66
+ */
67
+ var $FromName = "Root User";
68
+
69
+ /**
70
+ * Sets the Sender email (Return-Path) of the message. If not empty,
71
+ * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
72
+ * @var string
73
+ */
74
+ var $Sender = "";
75
+
76
+ /**
77
+ * Sets the Subject of the message.
78
+ * @var string
79
+ */
80
+ var $Subject = "";
81
+
82
+ /**
83
+ * Sets the Body of the message. This can be either an HTML or text body.
84
+ * If HTML then run IsHTML(true).
85
+ * @var string
86
+ */
87
+ var $Body = "";
88
+
89
+ /**
90
+ * Sets the text-only body of the message. This automatically sets the
91
+ * email to multipart/alternative. This body can be read by mail
92
+ * clients that do not have HTML email capability such as mutt. Clients
93
+ * that can read HTML will view the normal Body.
94
+ * @var string
95
+ */
96
+ var $AltBody = "";
97
+
98
+ /**
99
+ * Sets word wrapping on the body of the message to a given number of
100
+ * characters.
101
+ * @var int
102
+ */
103
+ var $WordWrap = 0;
104
+
105
+ /**
106
+ * Method to send mail: ("mail", "sendmail", or "smtp").
107
+ * @var string
108
+ */
109
+ var $Mailer = "mail";
110
+
111
+ /**
112
+ * Sets the path of the sendmail program.
113
+ * @var string
114
+ */
115
+ var $Sendmail = "/usr/sbin/sendmail";
116
+
117
+ /**
118
+ * Path to PHPMailer plugins. This is now only useful if the SMTP class
119
+ * is in a different directory than the PHP include path.
120
+ * @var string
121
+ */
122
+ var $PluginDir = "";
123
+
124
+ /**
125
+ * Holds PHPMailer version.
126
+ * @var string
127
+ */
128
+ var $Version = "1.73";
129
+
130
+ /**
131
+ * Sets the email address that a reading confirmation will be sent.
132
+ * @var string
133
+ */
134
+ var $ConfirmReadingTo = "";
135
+
136
+ /**
137
+ * Sets the hostname to use in Message-Id and Received headers
138
+ * and as default HELO string. If empty, the value returned
139
+ * by SERVER_NAME is used or 'localhost.localdomain'.
140
+ * @var string
141
+ */
142
+ var $Hostname = "";
143
+
144
+ /////////////////////////////////////////////////
145
+ // SMTP VARIABLES
146
+ /////////////////////////////////////////////////
147
+
148
+ /**
149
+ * Sets the SMTP hosts. All hosts must be separated by a
150
+ * semicolon. You can also specify a different port
151
+ * for each host by using this format: [hostname:port]
152
+ * (e.g. "smtp1.example.com:25;smtp2.example.com").
153
+ * Hosts will be tried in order.
154
+ * @var string
155
+ */
156
+ var $Host = "localhost";
157
+
158
+ /**
159
+ * Sets the default SMTP server port.
160
+ * @var int
161
+ */
162
+ var $Port = 25;
163
+
164
+ /**
165
+ * Sets the SMTP HELO of the message (Default is $Hostname).
166
+ * @var string
167
+ */
168
+ var $Helo = "";
169
+
170
+ /**
171
+ * Sets SMTP authentication. Utilizes the Username and Password variables.
172
+ * @var bool
173
+ */
174
+ var $SMTPAuth = false;
175
+
176
+ /**
177
+ * Sets SMTP username.
178
+ * @var string
179
+ */
180
+ var $Username = "";
181
+
182
+ /**
183
+ * Sets SMTP password.
184
+ * @var string
185
+ */
186
+ var $Password = "";
187
+
188
+ /**
189
+ * Sets the SMTP server timeout in seconds. This function will not
190
+ * work with the win32 version.
191
+ * @var int
192
+ */
193
+ var $Timeout = 10;
194
+
195
+ /**
196
+ * Sets SMTP class debugging on or off.
197
+ * @var bool
198
+ */
199
+ var $SMTPDebug = false;
200
+
201
+ /**
202
+ * Prevents the SMTP connection from being closed after each mail
203
+ * sending. If this is set to true then to close the connection
204
+ * requires an explicit call to SmtpClose().
205
+ * @var bool
206
+ */
207
+ var $SMTPKeepAlive = false;
208
+
209
+ /**#@+
210
+ * @access private
211
+ */
212
+ var $smtp = NULL;
213
+ var $to = array();
214
+ var $cc = array();
215
+ var $bcc = array();
216
+ var $ReplyTo = array();
217
+ var $attachment = array();
218
+ var $CustomHeader = array();
219
+ var $message_type = "";
220
+ var $boundary = array();
221
+ var $language = array();
222
+ var $error_count = 0;
223
+ var $LE = "\n";
224
+ /**#@-*/
225
+
226
+ /////////////////////////////////////////////////
227
+ // VARIABLE METHODS
228
+ /////////////////////////////////////////////////
229
+
230
+ /**
231
+ * Sets message type to HTML.
232
+ * @param bool $bool
233
+ * @return void
234
+ */
235
+ function IsHTML($bool) {
236
+ if($bool == true)
237
+ $this->ContentType = "text/html";
238
+ else
239
+ $this->ContentType = "text/plain";
240
+ }
241
+
242
+ /**
243
+ * Sets Mailer to send message using SMTP.
244
+ * @return void
245
+ */
246
+ function IsSMTP() {
247
+ $this->Mailer = "smtp";
248
+ }
249
+
250
+ /**
251
+ * Sets Mailer to send message using PHP mail() function.
252
+ * @return void
253
+ */
254
+ function IsMail() {
255
+ $this->Mailer = "mail";
256
+ }
257
+
258
+ /**
259
+ * Sets Mailer to send message using the $Sendmail program.
260
+ * @return void
261
+ */
262
+ function IsSendmail() {
263
+ $this->Mailer = "sendmail";
264
+ }
265
+
266
+ /**
267
+ * Sets Mailer to send message using the qmail MTA.
268
+ * @return void
269
+ */
270
+ function IsQmail() {
271
+ $this->Sendmail = "/var/qmail/bin/sendmail";
272
+ $this->Mailer = "sendmail";
273
+ }
274
+
275
+
276
+ /////////////////////////////////////////////////
277
+ // RECIPIENT METHODS
278
+ /////////////////////////////////////////////////
279
+
280
+ /**
281
+ * Adds a "To" address.
282
+ * @param string $address
283
+ * @param string $name
284
+ * @return void
285
+ */
286
+ function AddAddress($address, $name = "") {
287
+ $cur = count($this->to);
288
+ $this->to[$cur][0] = trim($address);
289
+ $this->to[$cur][1] = $name;
290
+ }
291
+
292
+ /**
293
+ * Adds a "Cc" address. Note: this function works
294
+ * with the SMTP mailer on win32, not with the "mail"
295
+ * mailer.
296
+ * @param string $address
297
+ * @param string $name
298
+ * @return void
299
+ */
300
+ function AddCC($address, $name = "") {
301
+ $cur = count($this->cc);
302
+ $this->cc[$cur][0] = trim($address);
303
+ $this->cc[$cur][1] = $name;
304
+ }
305
+
306
+ /**
307
+ * Adds a "Bcc" address. Note: this function works
308
+ * with the SMTP mailer on win32, not with the "mail"
309
+ * mailer.
310
+ * @param string $address
311
+ * @param string $name
312
+ * @return void
313
+ */
314
+ function AddBCC($address, $name = "") {
315
+ $cur = count($this->bcc);
316
+ $this->bcc[$cur][0] = trim($address);
317
+ $this->bcc[$cur][1] = $name;
318
+ }
319
+
320
+ /**
321
+ * Adds a "Reply-to" address.
322
+ * @param string $address
323
+ * @param string $name
324
+ * @return void
325
+ */
326
+ function AddReplyTo($address, $name = "") {
327
+ $cur = count($this->ReplyTo);
328
+ $this->ReplyTo[$cur][0] = trim($address);
329
+ $this->ReplyTo[$cur][1] = $name;
330
+ }
331
+
332
+
333
+ /////////////////////////////////////////////////
334
+ // MAIL SENDING METHODS
335
+ /////////////////////////////////////////////////
336
+
337
+ /**
338
+ * Creates message and assigns Mailer. If the message is
339
+ * not sent successfully then it returns false. Use the ErrorInfo
340
+ * variable to view description of the error.
341
+ * @return bool
342
+ */
343
+ function Send() {
344
+ $header = "";
345
+ $body = "";
346
+ $result = true;
347
+
348
+ if((count($this->to) + count($this->cc) + count($this->bcc)) < 1)
349
+ {
350
+ $this->SetError($this->Lang("provide_address"));
351
+ return false;
352
+ }
353
+
354
+ // Set whether the message is multipart/alternative
355
+ if(!empty($this->AltBody))
356
+ $this->ContentType = "multipart/alternative";
357
+
358
+ $this->error_count = 0; // reset errors
359
+ $this->SetMessageType();
360
+ $header .= $this->CreateHeader();
361
+ $body = $this->CreateBody();
362
+
363
+ if($body == "") { return false; }
364
+
365
+ // Choose the mailer
366
+ switch($this->Mailer)
367
+ {
368
+ case "sendmail":
369
+ $result = $this->SendmailSend($header, $body);
370
+ break;
371
+ case "mail":
372
+ $result = $this->MailSend($header, $body);
373
+ break;
374
+ case "smtp":
375
+ $result = $this->SmtpSend($header, $body);
376
+ break;
377
+ default:
378
+ $this->SetError($this->Mailer . $this->Lang("mailer_not_supported"));
379
+ $result = false;
380
+ break;
381
+ }
382
+
383
+ return $result;
384
+ }
385
+
386
+ /**
387
+ * Sends mail using the $Sendmail program.
388
+ * @access private
389
+ * @return bool
390
+ */
391
+ function SendmailSend($header, $body) {
392
+ if ($this->Sender != "")
393
+ $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender);
394
+ else
395
+ $sendmail = sprintf("%s -oi -t", $this->Sendmail);
396
+
397
+ if(!@$mail = popen($sendmail, "w"))
398
+ {
399
+ $this->SetError($this->Lang("execute") . $this->Sendmail);
400
+ return false;
401
+ }
402
+
403
+ fputs($mail, $header);
404
+ fputs($mail, $body);
405
+
406
+ $result = pclose($mail) >> 8 & 0xFF;
407
+ if($result != 0)
408
+ {
409
+ $this->SetError($this->Lang("execute") . $this->Sendmail);
410
+ return false;
411
+ }
412
+
413
+ return true;
414
+ }
415
+
416
+ /**
417
+ * Sends mail using the PHP mail() function.
418
+ * @access private
419
+ * @return bool
420
+ */
421
+ function MailSend($header, $body) {
422
+ $to = "";
423
+ for($i = 0; $i < count($this->to); $i++)
424
+ {
425
+ if($i != 0) { $to .= ", "; }
426
+ $to .= $this->to[$i][0];
427
+ }
428
+
429
+ if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
430
+ {
431
+ $old_from = ini_get("sendmail_from");
432
+ ini_set("sendmail_from", $this->Sender);
433
+ $params = sprintf("-oi -f %s", $this->Sender);
434
+ $rt = @mail($to, $this->EncodeHeader($this->Subject), $body,
435
+ $header, $params);
436
+ }
437
+ else
438
+ $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header);
439
+
440
+ if (isset($old_from))
441
+ ini_set("sendmail_from", $old_from);
442
+
443
+ if(!$rt)
444
+ {
445
+ $this->SetError($this->Lang("instantiate"));
446
+ return false;
447
+ }
448
+
449
+ return true;
450
+ }
451
+
452
+ /**
453
+ * Sends mail via SMTP using PhpSMTP (Author:
454
+ * Chris Ryan). Returns bool. Returns false if there is a
455
+ * bad MAIL FROM, RCPT, or DATA input.
456
+ * @access private
457
+ * @return bool
458
+ */
459
+ function SmtpSend($header, $body) {
460
+ include_once($this->PluginDir . "class.smtp.php");
461
+ $error = "";
462
+ $bad_rcpt = array();
463
+
464
+ if(!$this->SmtpConnect())
465
+ return false;
466
+
467
+ $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
468
+ if(!$this->smtp->Mail($smtp_from))
469
+ {
470
+ $error = $this->Lang("from_failed") . $smtp_from;
471
+ $this->SetError($error);
472
+ $this->smtp->Reset();
473
+ return false;
474
+ }
475
+
476
+ // Attempt to send attach all recipients
477
+ for($i = 0; $i < count($this->to); $i++)
478
+ {
479
+ if(!$this->smtp->Recipient($this->to[$i][0]))
480
+ $bad_rcpt[] = $this->to[$i][0];
481
+ }
482
+ for($i = 0; $i < count($this->cc); $i++)
483
+ {
484
+ if(!$this->smtp->Recipient($this->cc[$i][0]))
485
+ $bad_rcpt[] = $this->cc[$i][0];
486
+ }
487
+ for($i = 0; $i < count($this->bcc); $i++)
488
+ {
489
+ if(!$this->smtp->Recipient($this->bcc[$i][0]))
490
+ $bad_rcpt[] = $this->bcc[$i][0];
491
+ }
492
+
493
+ if(count($bad_rcpt) > 0) // Create error message
494
+ {
495
+ for($i = 0; $i < count($bad_rcpt); $i++)
496
+ {
497
+ if($i != 0) { $error .= ", "; }
498
+ $error .= $bad_rcpt[$i];
499
+ }
500
+ $error = $this->Lang("recipients_failed") . $error;
501
+ $this->SetError($error);
502
+ $this->smtp->Reset();
503
+ return false;
504
+ }
505
+
506
+ if(!$this->smtp->Data($header . $body))
507
+ {
508
+ $this->SetError($this->Lang("data_not_accepted"));
509
+ $this->smtp->Reset();
510
+ return false;
511
+ }
512
+ if($this->SMTPKeepAlive == true)
513
+ $this->smtp->Reset();
514
+ else
515
+ $this->SmtpClose();
516
+
517
+ return true;
518
+ }
519
+
520
+ /**
521
+ * Initiates a connection to an SMTP server. Returns false if the
522
+ * operation failed.
523
+ * @access private
524
+ * @return bool
525
+ */
526
+ function SmtpConnect() {
527
+ if($this->smtp == NULL) { $this->smtp = new EM_SMTP(); }
528
+
529
+ $this->smtp->do_debug = $this->SMTPDebug;
530
+ $hosts = explode(";", $this->Host);
531
+ $index = 0;
532
+ $connection = ($this->smtp->Connected());
533
+
534
+ // Retry while there is no connection
535
+ while($index < count($hosts) && $connection == false)
536
+ {
537
+ if(strstr($hosts[$index], ":"))
538
+ {
539
+ $hostA = explode(':', $hosts[$index]);
540
+ if (is_numeric(end($hostA)))
541
+ $port = array_pop($hostA);
542
+ else
543
+ $port = $this->Port;
544
+ $host = implode(':', $hostA);
545
+ }
546
+ else
547
+ {
548
+ $host = $hosts[$index];
549
+ $port = $this->Port;
550
+ }
551
+
552
+ if($this->smtp->Connect($host, $port, $this->Timeout))
553
+ {
554
+ if ($this->Helo != '')
555
+ $this->smtp->Hello($this->Helo);
556
+ else
557
+ $this->smtp->Hello($this->ServerHostname());
558
+
559
+ if($this->SMTPAuth)
560
+ {
561
+ if(!$this->smtp->Authenticate($this->Username,
562
+ $this->Password))
563
+ {
564
+ $this->SetError($this->Lang("authenticate"));
565
+ $this->smtp->Reset();
566
+ $connection = false;
567
+ }
568
+ }
569
+ $connection = true;
570
+ }
571
+ $index++;
572
+ }
573
+ if(!$connection)
574
+ $this->SetError($this->Lang("connect_host"));
575
+
576
+ return $connection;
577
+ }
578
+
579
+ /**
580
+ * Closes the active SMTP session if one exists.
581
+ * @return void
582
+ */
583
+ function SmtpClose() {
584
+ if($this->smtp != NULL)
585
+ {
586
+ if($this->smtp->Connected())
587
+ {
588
+ $this->smtp->Quit();
589
+ $this->smtp->Close();
590
+ }
591
+ }
592
+ }
593
+
594
+ /**
595
+ * Sets the language for all class error messages. Returns false
596
+ * if it cannot load the language file. The default language type
597
+ * is English.
598
+ * @param string $lang_type Type of language (e.g. Portuguese: "br")
599
+ * @param string $lang_path Path to the language file directory
600
+ * @access public
601
+ * @return bool
602
+ */
603
+ function SetLanguage($lang_type, $lang_path = "language/") {
604
+ if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php'))
605
+ include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
606
+ else if(file_exists($lang_path.'phpmailer.lang-en.php'))
607
+ include($lang_path.'phpmailer.lang-en.php');
608
+ else
609
+ {
610
+ $this->SetError("Could not load language file");
611
+ return false;
612
+ }
613
+ $this->language = $PHPMAILER_LANG;
614
+
615
+ return true;
616
+ }
617
+
618
+ /////////////////////////////////////////////////
619
+ // MESSAGE CREATION METHODS
620
+ /////////////////////////////////////////////////
621
+
622
+ /**
623
+ * Creates recipient headers.
624
+ * @access private
625
+ * @return string
626
+ */
627
+ function AddrAppend($type, $addr) {
628
+ $addr_str = $type . ": ";
629
+ $addr_str .= $this->AddrFormat($addr[0]);
630
+ if(count($addr) > 1)
631
+ {
632
+ for($i = 1; $i < count($addr); $i++)
633
+ $addr_str .= ", " . $this->AddrFormat($addr[$i]);
634
+ }
635
+ $addr_str .= $this->LE;
636
+
637
+ return $addr_str;
638
+ }
639
+
640
+ /**
641
+ * Formats an address correctly.
642
+ * @access private
643
+ * @return string
644
+ */
645
+ function AddrFormat($addr) {
646
+ if(empty($addr[1]))
647
+ $formatted = $addr[0];
648
+ else
649
+ {
650
+ $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" .
651
+ $addr[0] . ">";
652
+ }
653
+
654
+ return $formatted;
655
+ }
656
+
657
+ /**
658
+ * Wraps message for use with mailers that do not
659
+ * automatically perform wrapping and for quoted-printable.
660
+ * Original written by philippe.
661
+ * @access private
662
+ * @return string
663
+ */
664
+ function WrapText($message, $length, $qp_mode = false) {
665
+ $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
666
+
667
+ $message = $this->FixEOL($message);
668
+ if (substr($message, -1) == $this->LE)
669
+ $message = substr($message, 0, -1);
670
+
671
+ $line = explode($this->LE, $message);
672
+ $message = "";
673
+ for ($i=0 ;$i < count($line); $i++)
674
+ {
675
+ $line_part = explode(" ", $line[$i]);
676
+ $buf = "";
677
+ for ($e = 0; $e<count($line_part); $e++)
678
+ {
679
+ $word = $line_part[$e];
680
+ if ($qp_mode and (strlen($word) > $length))
681
+ {
682
+ $space_left = $length - strlen($buf) - 1;
683
+ if ($e != 0)
684
+ {
685
+ if ($space_left > 20)
686
+ {
687
+ $len = $space_left;
688
+ if (substr($word, $len - 1, 1) == "=")
689
+ $len--;
690
+ elseif (substr($word, $len - 2, 1) == "=")
691
+ $len -= 2;
692
+ $part = substr($word, 0, $len);
693
+ $word = substr($word, $len);
694
+ $buf .= " " . $part;
695
+ $message .= $buf . sprintf("=%s", $this->LE);
696
+ }
697
+ else
698
+ {
699
+ $message .= $buf . $soft_break;
700
+ }
701
+ $buf = "";
702
+ }
703
+ while (strlen($word) > 0)
704
+ {
705
+ $len = $length;
706
+ if (substr($word, $len - 1, 1) == "=")
707
+ $len--;
708
+ elseif (substr($word, $len - 2, 1) == "=")
709
+ $len -= 2;
710
+ $part = substr($word, 0, $len);
711
+ $word = substr($word, $len);
712
+
713
+ if (strlen($word) > 0)
714
+ $message .= $part . sprintf("=%s", $this->LE);
715
+ else
716
+ $buf = $part;
717
+ }
718
+ }
719
+ else
720
+ {
721
+ $buf_o = $buf;
722
+ $buf .= ($e == 0) ? $word : (" " . $word);
723
+
724
+ if (strlen($buf) > $length and $buf_o != "")
725
+ {
726
+ $message .= $buf_o . $soft_break;
727
+ $buf = $word;
728
+ }
729
+ }
730
+ }
731
+ $message .= $buf . $this->LE;
732
+ }
733
+
734
+ return $message;
735
+ }
736
+
737
+ /**
738
+ * Set the body wrapping.
739
+ * @access private
740
+ * @return void
741
+ */
742
+ function SetWordWrap() {
743
+ if($this->WordWrap < 1)
744
+ return;
745
+
746
+ switch($this->message_type)
747
+ {
748
+ case "alt":
749
+ // fall through
750
+ case "alt_attachments":
751
+ $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
752
+ break;
753
+ default:
754
+ $this->Body = $this->WrapText($this->Body, $this->WordWrap);
755
+ break;
756
+ }
757
+ }
758
+
759
+ /**
760
+ * Assembles message header.
761
+ * @access private
762
+ * @return string
763
+ */
764
+ function CreateHeader() {
765
+ $result = "";
766
+
767
+ // Set the boundaries
768
+ $uniq_id = md5(uniqid(time()));
769
+ $this->boundary[1] = "b1_" . $uniq_id;
770
+ $this->boundary[2] = "b2_" . $uniq_id;
771
+
772
+ $result .= $this->HeaderLine("Date", $this->RFCDate());
773
+ if($this->Sender == "")
774
+ $result .= $this->HeaderLine("Return-Path", trim($this->From));
775
+ else
776
+ $result .= $this->HeaderLine("Return-Path", trim($this->Sender));
777
+
778
+ // To be created automatically by mail()
779
+ if($this->Mailer != "mail")
780
+ {
781
+ if(count($this->to) > 0)
782
+ $result .= $this->AddrAppend("To", $this->to);
783
+ else if (count($this->cc) == 0)
784
+ $result .= $this->HeaderLine("To", "undisclosed-recipients:;");
785
+ if(count($this->cc) > 0)
786
+ $result .= $this->AddrAppend("Cc", $this->cc);
787
+ }
788
+
789
+ $from = array();
790
+ $from[0][0] = trim($this->From);
791
+ $from[0][1] = $this->FromName;
792
+ $result .= $this->AddrAppend("From", $from);
793
+
794
+ // sendmail and mail() extract Bcc from the header before sending
795
+ if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))
796
+ $result .= $this->AddrAppend("Bcc", $this->bcc);
797
+
798
+ if(count($this->ReplyTo) > 0)
799
+ $result .= $this->AddrAppend("Reply-to", $this->ReplyTo);
800
+
801
+ // mail() sets the subject itself
802
+ if($this->Mailer != "mail")
803
+ $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject)));
804
+
805
+ $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
806
+ $result .= $this->HeaderLine("X-Priority", $this->Priority);
807
+ $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]");
808
+
809
+ if($this->ConfirmReadingTo != "")
810
+ {
811
+ $result .= $this->HeaderLine("Disposition-Notification-To",
812
+ "<" . trim($this->ConfirmReadingTo) . ">");
813
+ }
814
+
815
+ // Add custom headers
816
+ for($index = 0; $index < count($this->CustomHeader); $index++)
817
+ {
818
+ $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]),
819
+ $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
820
+ }
821
+ $result .= $this->HeaderLine("MIME-Version", "1.0");
822
+
823
+ switch($this->message_type)
824
+ {
825
+ case "plain":
826
+ $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
827
+ $result .= sprintf("Content-Type: %s; charset=\"%s\"",
828
+ $this->ContentType, $this->CharSet);
829
+ break;
830
+ case "attachments":
831
+ // fall through
832
+ case "alt_attachments":
833
+ if($this->InlineImageExists())
834
+ {
835
+ $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
836
+ "multipart/related", $this->LE, $this->LE,
837
+ $this->boundary[1], $this->LE);
838
+ }
839
+ else
840
+ {
841
+ $result .= $this->HeaderLine("Content-Type", "multipart/mixed;");
842
+ $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
843
+ }
844
+ break;
845
+ case "alt":
846
+ $result .= $this->HeaderLine("Content-Type", "multipart/alternative;");
847
+ $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
848
+ break;
849
+ }
850
+
851
+ if($this->Mailer != "mail")
852
+ $result .= $this->LE.$this->LE;
853
+
854
+ return $result;
855
+ }
856
+
857
+ /**
858
+ * Assembles the message body. Returns an empty string on failure.
859
+ * @access private
860
+ * @return string
861
+ */
862
+ function CreateBody() {
863
+ $result = "";
864
+
865
+ $this->SetWordWrap();
866
+
867
+ switch($this->message_type)
868
+ {
869
+ case "alt":
870
+ $result .= $this->GetBoundary($this->boundary[1], "",
871
+ "text/plain", "");
872
+ $result .= $this->EncodeString($this->AltBody, $this->Encoding);
873
+ $result .= $this->LE.$this->LE;
874
+ $result .= $this->GetBoundary($this->boundary[1], "",
875
+ "text/html", "");
876
+
877
+ $result .= $this->EncodeString($this->Body, $this->Encoding);
878
+ $result .= $this->LE.$this->LE;
879
+
880
+ $result .= $this->EndBoundary($this->boundary[1]);
881
+ break;
882
+ case "plain":
883
+ $result .= $this->EncodeString($this->Body, $this->Encoding);
884
+ break;
885
+ case "attachments":
886
+ $result .= $this->GetBoundary($this->boundary[1], "", "", "");
887
+ $result .= $this->EncodeString($this->Body, $this->Encoding);
888
+ $result .= $this->LE;
889
+
890
+ $result .= $this->AttachAll();
891
+ break;
892
+ case "alt_attachments":
893
+ $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
894
+ $result .= sprintf("Content-Type: %s;%s" .
895
+ "\tboundary=\"%s\"%s",
896
+ "multipart/alternative", $this->LE,
897
+ $this->boundary[2], $this->LE.$this->LE);
898
+
899
+ // Create text body
900
+ $result .= $this->GetBoundary($this->boundary[2], "",
901
+ "text/plain", "") . $this->LE;
902
+
903
+ $result .= $this->EncodeString($this->AltBody, $this->Encoding);
904
+ $result .= $this->LE.$this->LE;
905
+
906
+ // Create the HTML body
907
+ $result .= $this->GetBoundary($this->boundary[2], "",
908
+ "text/html", "") . $this->LE;
909
+
910
+ $result .= $this->EncodeString($this->Body, $this->Encoding);
911
+ $result .= $this->LE.$this->LE;
912
+
913
+ $result .= $this->EndBoundary($this->boundary[2]);
914
+
915
+ $result .= $this->AttachAll();
916
+ break;
917
+ }
918
+ if($this->IsError())
919
+ $result = "";
920
+
921
+ return $result;
922
+ }
923
+
924
+ /**
925
+ * Returns the start of a message boundary.
926
+ * @access private
927
+ */
928
+ function GetBoundary($boundary, $charSet, $contentType, $encoding) {
929
+ $result = "";
930
+ if($charSet == "") { $charSet = $this->CharSet; }
931
+ if($contentType == "") { $contentType = $this->ContentType; }
932
+ if($encoding == "") { $encoding = $this->Encoding; }
933
+
934
+ $result .= $this->TextLine("--" . $boundary);
935
+ $result .= sprintf("Content-Type: %s; charset = \"%s\"",
936
+ $contentType, $charSet);
937
+ $result .= $this->LE;
938
+ $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding);
939
+ $result .= $this->LE;
940
+
941
+ return $result;
942
+ }
943
+
944
+ /**
945
+ * Returns the end of a message boundary.
946
+ * @access private
947
+ */
948
+ function EndBoundary($boundary) {
949
+ return $this->LE . "--" . $boundary . "--" . $this->LE;
950
+ }
951
+
952
+ /**
953
+ * Sets the message type.
954
+ * @access private
955
+ * @return void
956
+ */
957
+ function SetMessageType() {
958
+ if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
959
+ $this->message_type = "plain";
960
+ else
961
+ {
962
+ if(count($this->attachment) > 0)
963
+ $this->message_type = "attachments";
964
+ if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)
965
+ $this->message_type = "alt";
966
+ if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)
967
+ $this->message_type = "alt_attachments";
968
+ }
969
+ }
970
+
971
+ /**
972
+ * Returns a formatted header line.
973
+ * @access private
974
+ * @return string
975
+ */
976
+ function HeaderLine($name, $value) {
977
+ return $name . ": " . $value . $this->LE;
978
+ }
979
+
980
+ /**
981
+ * Returns a formatted mail line.
982
+ * @access private
983
+ * @return string
984
+ */
985
+ function TextLine($value) {
986
+ return $value . $this->LE;
987
+ }
988
+
989
+ /////////////////////////////////////////////////
990
+ // ATTACHMENT METHODS
991
+ /////////////////////////////////////////////////
992
+
993
+ /**
994
+ * Adds an attachment from a path on the filesystem.
995
+ * Returns false if the file could not be found
996
+ * or accessed.
997
+ * @param string $path Path to the attachment.
998
+ * @param string $name Overrides the attachment name.
999
+ * @param string $encoding File encoding (see $Encoding).
1000
+ * @param string $type File extension (MIME) type.
1001
+ * @return bool
1002
+ */
1003
+ function AddAttachment($path, $name = "", $encoding = "base64",
1004
+ $type = "application/octet-stream") {
1005
+ if(!@is_file($path))
1006
+ {
1007
+ $this->SetError($this->Lang("file_access") . $path);
1008
+ return false;
1009
+ }
1010
+
1011
+ $filename = basename($path);
1012
+ if($name == "")
1013
+ $name = $filename;
1014
+
1015
+ $cur = count($this->attachment);
1016
+ $this->attachment[$cur][0] = $path;
1017
+ $this->attachment[$cur][1] = $filename;
1018
+ $this->attachment[$cur][2] = $name;
1019
+ $this->attachment[$cur][3] = $encoding;
1020
+ $this->attachment[$cur][4] = $type;
1021
+ $this->attachment[$cur][5] = false; // isStringAttachment
1022
+ $this->attachment[$cur][6] = "attachment";
1023
+ $this->attachment[$cur][7] = 0;
1024
+
1025
+ return true;
1026
+ }
1027
+
1028
+ /**
1029
+ * Attaches all fs, string, and binary attachments to the message.
1030
+ * Returns an empty string on failure.
1031
+ * @access private
1032
+ * @return string
1033
+ */
1034
+ function AttachAll() {
1035
+ // Return text of body
1036
+ $mime = array();
1037
+
1038
+ // Add all attachments
1039
+ for($i = 0; $i < count($this->attachment); $i++)
1040
+ {
1041
+ // Check for string attachment
1042
+ $bString = $this->attachment[$i][5];
1043
+ if ($bString)
1044
+ $string = $this->attachment[$i][0];
1045
+ else
1046
+ $path = $this->attachment[$i][0];
1047
+
1048
+ $filename = $this->attachment[$i][1];
1049
+ $name = $this->attachment[$i][2];
1050
+ $encoding = $this->attachment[$i][3];
1051
+ $type = $this->attachment[$i][4];
1052
+ $disposition = $this->attachment[$i][6];
1053
+ $cid = $this->attachment[$i][7];
1054
+
1055
+ $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
1056
+ $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
1057
+ $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1058
+
1059
+ if($disposition == "inline")
1060
+ $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
1061
+
1062
+ $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s",
1063
+ $disposition, $name, $this->LE.$this->LE);
1064
+
1065
+ // Encode as string attachment
1066
+ if($bString)
1067
+ {
1068
+ $mime[] = $this->EncodeString($string, $encoding);
1069
+ if($this->IsError()) { return ""; }
1070
+ $mime[] = $this->LE.$this->LE;
1071
+ }
1072
+ else
1073
+ {
1074
+ $mime[] = $this->EncodeFile($path, $encoding);
1075
+ if($this->IsError()) { return ""; }
1076
+ $mime[] = $this->LE.$this->LE;
1077
+ }
1078
+ }
1079
+
1080
+ $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
1081
+
1082
+ return join("", $mime);
1083
+ }
1084
+
1085
+ /**
1086
+ * Encodes attachment in requested format. Returns an
1087
+ * empty string on failure.
1088
+ * @access private
1089
+ * @return string
1090
+ */
1091
+ function EncodeFile ($path, $encoding = "base64") {
1092
+ if(!@$fd = fopen($path, "rb"))
1093
+ {
1094
+ $this->SetError($this->Lang("file_open") . $path);
1095
+ return "";
1096
+ }
1097
+ $magic_quotes = get_magic_quotes_runtime();
1098
+ set_magic_quotes_runtime(0);
1099
+ $file_buffer = fread($fd, filesize($path));
1100
+ $file_buffer = $this->EncodeString($file_buffer, $encoding);
1101
+ fclose($fd);
1102
+ set_magic_quotes_runtime($magic_quotes);
1103
+
1104
+ return $file_buffer;
1105
+ }
1106
+
1107
+ /**
1108
+ * Encodes string to requested format. Returns an
1109
+ * empty string on failure.
1110
+ * @access private
1111
+ * @return string
1112
+ */
1113
+ function EncodeString ($str, $encoding = "base64") {
1114
+ $encoded = "";
1115
+ switch(strtolower($encoding)) {
1116
+ case "base64":
1117
+ // chunk_split is found in PHP >= 3.0.6
1118
+ $encoded = chunk_split(base64_encode($str), 76, $this->LE);
1119
+ break;
1120
+ case "7bit":
1121
+ case "8bit":
1122
+ $encoded = $this->FixEOL($str);
1123
+ if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1124
+ $encoded .= $this->LE;
1125
+ break;
1126
+ case "binary":
1127
+ $encoded = $str;
1128
+ break;
1129
+ case "quoted-printable":
1130
+ $encoded = $this->EncodeQP($str);
1131
+ break;
1132
+ default:
1133
+ $this->SetError($this->Lang("encoding") . $encoding);
1134
+ break;
1135
+ }
1136
+ return $encoded;
1137
+ }
1138
+
1139
+ /**
1140
+ * Encode a header string to best of Q, B, quoted or none.
1141
+ * @access private
1142
+ * @return string
1143
+ */
1144
+ function EncodeHeader ($str, $position = 'text') {
1145
+ $x = 0;
1146
+
1147
+ switch (strtolower($position)) {
1148
+ case 'phrase':
1149
+ if (!preg_match('/[\200-\377]/', $str)) {
1150
+ // Can't use addslashes as we don't know what value has magic_quotes_sybase.
1151
+ $encoded = addcslashes($str, "\0..\37\177\\\"");
1152
+
1153
+ if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
1154
+ return ($encoded);
1155
+ else
1156
+ return ("\"$encoded\"");
1157
+ }
1158
+ $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
1159
+ break;
1160
+ case 'comment':
1161
+ $x = preg_match_all('/[()"]/', $str, $matches);
1162
+ // Fall-through
1163
+ case 'text':
1164
+ default:
1165
+ $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1166
+ break;
1167
+ }
1168
+
1169
+ if ($x == 0)
1170
+ return ($str);
1171
+
1172
+ $maxlen = 75 - 7 - strlen($this->CharSet);
1173
+ // Try to select the encoding which should produce the shortest output
1174
+ if (strlen($str)/3 < $x) {
1175
+ $encoding = 'B';
1176
+ $encoded = base64_encode($str);
1177
+ $maxlen -= $maxlen % 4;
1178
+ $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
1179
+ } else {
1180
+ $encoding = 'Q';
1181
+ $encoded = $this->EncodeQ($str, $position);
1182
+ $encoded = $this->WrapText($encoded, $maxlen, true);
1183
+ $encoded = str_replace("=".$this->LE, "\n", trim($encoded));
1184
+ }
1185
+
1186
+ $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
1187
+ $encoded = trim(str_replace("\n", $this->LE, $encoded));
1188
+
1189
+ return $encoded;
1190
+ }
1191
+
1192
+ /**
1193
+ * Encode string to quoted-printable.
1194
+ * @access private
1195
+ * @return string
1196
+ */
1197
+ function EncodeQP ($str) {
1198
+ $encoded = $this->FixEOL($str);
1199
+ if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1200
+ $encoded .= $this->LE;
1201
+
1202
+ // Replace every high ascii, control and = characters
1203
+ $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
1204
+ "'='.sprintf('%02X', ord('\\1'))", $encoded);
1205
+ // Replace every spaces and tabs when it's the last character on a line
1206
+ $encoded = preg_replace("/([\011\040])".$this->LE."/e",
1207
+ "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
1208
+
1209
+ // Maximum line length of 76 characters before CRLF (74 + space + '=')
1210
+ $encoded = $this->WrapText($encoded, 74, true);
1211
+
1212
+ return $encoded;
1213
+ }
1214
+
1215
+ /**
1216
+ * Encode string to q encoding.
1217
+ * @access private
1218
+ * @return string
1219
+ */
1220
+ function EncodeQ ($str, $position = "text") {
1221
+ // There should not be any EOL in the string
1222
+ $encoded = preg_replace("[\r\n]", "", $str);
1223
+
1224
+ switch (strtolower($position)) {
1225
+ case "phrase":
1226
+ $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1227
+ break;
1228
+ case "comment":
1229
+ $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1230
+ case "text":
1231
+ default:
1232
+ // Replace every high ascii, control =, ? and _ characters
1233
+ $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1234
+ "'='.sprintf('%02X', ord('\\1'))", $encoded);
1235
+ break;
1236
+ }
1237
+
1238
+ // Replace every spaces to _ (more readable than =20)
1239
+ $encoded = str_replace(" ", "_", $encoded);
1240
+
1241
+ return $encoded;
1242
+ }
1243
+
1244
+ /**
1245
+ * Adds a string or binary attachment (non-filesystem) to the list.
1246
+ * This method can be used to attach ascii or binary data,
1247
+ * such as a BLOB record from a database.
1248
+ * @param string $string String attachment data.
1249
+ * @param string $filename Name of the attachment.
1250
+ * @param string $encoding File encoding (see $Encoding).
1251
+ * @param string $type File extension (MIME) type.
1252
+ * @return void
1253
+ */
1254
+ function AddStringAttachment($string, $filename, $encoding = "base64",
1255
+ $type = "application/octet-stream") {
1256
+ // Append to $attachment array
1257
+ $cur = count($this->attachment);
1258
+ $this->attachment[$cur][0] = $string;
1259
+ $this->attachment[$cur][1] = $filename;
1260
+ $this->attachment[$cur][2] = $filename;
1261
+ $this->attachment[$cur][3] = $encoding;
1262
+ $this->attachment[$cur][4] = $type;
1263
+ $this->attachment[$cur][5] = true; // isString
1264
+ $this->attachment[$cur][6] = "attachment";
1265
+ $this->attachment[$cur][7] = 0;
1266
+ }
1267
+
1268
+ /**
1269
+ * Adds an embedded attachment. This can include images, sounds, and
1270
+ * just about any other document. Make sure to set the $type to an
1271
+ * image type. For JPEG images use "image/jpeg" and for GIF images
1272
+ * use "image/gif".
1273
+ * @param string $path Path to the attachment.
1274
+ * @param string $cid Content ID of the attachment. Use this to identify
1275
+ * the Id for accessing the image in an HTML form.
1276
+ * @param string $name Overrides the attachment name.
1277
+ * @param string $encoding File encoding (see $Encoding).
1278
+ * @param string $type File extension (MIME) type.
1279
+ * @return bool
1280
+ */
1281
+ function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64",
1282
+ $type = "application/octet-stream") {
1283
+
1284
+ if(!@is_file($path))
1285
+ {
1286
+ $this->SetError($this->Lang("file_access") . $path);
1287
+ return false;
1288
+ }
1289
+
1290
+ $filename = basename($path);
1291
+ if($name == "")
1292
+ $name = $filename;
1293
+
1294
+ // Append to $attachment array
1295
+ $cur = count($this->attachment);
1296
+ $this->attachment[$cur][0] = $path;
1297
+ $this->attachment[$cur][1] = $filename;
1298
+ $this->attachment[$cur][2] = $name;
1299
+ $this->attachment[$cur][3] = $encoding;
1300
+ $this->attachment[$cur][4] = $type;
1301
+ $this->attachment[$cur][5] = false; // isStringAttachment
1302
+ $this->attachment[$cur][6] = "inline";
1303
+ $this->attachment[$cur][7] = $cid;
1304
+
1305
+ return true;
1306
+ }
1307
+
1308
+ /**
1309
+ * Returns true if an inline attachment is present.
1310
+ * @access private
1311
+ * @return bool
1312
+ */
1313
+ function InlineImageExists() {
1314
+ $result = false;
1315
+ for($i = 0; $i < count($this->attachment); $i++)
1316
+ {
1317
+ if($this->attachment[$i][6] == "inline")
1318
+ {
1319
+ $result = true;
1320
+ break;
1321
+ }
1322
+ }
1323
+
1324
+ return $result;
1325
+ }
1326
+
1327
+ /////////////////////////////////////////////////
1328
+ // MESSAGE RESET METHODS
1329
+ /////////////////////////////////////////////////
1330
+
1331
+ /**
1332
+ * Clears all recipients assigned in the TO array. Returns void.
1333
+ * @return void
1334
+ */
1335
+ function ClearAddresses() {
1336
+ $this->to = array();
1337
+ }
1338
+
1339
+ /**
1340
+ * Clears all recipients assigned in the CC array. Returns void.
1341
+ * @return void
1342
+ */
1343
+ function ClearCCs() {
1344
+ $this->cc = array();
1345
+ }
1346
+
1347
+ /**
1348
+ * Clears all recipients assigned in the BCC array. Returns void.
1349
+ * @return void
1350
+ */
1351
+ function ClearBCCs() {
1352
+ $this->bcc = array();
1353
+ }
1354
+
1355
+ /**
1356
+ * Clears all recipients assigned in the ReplyTo array. Returns void.
1357
+ * @return void
1358
+ */
1359
+ function ClearReplyTos() {
1360
+ $this->ReplyTo = array();
1361
+ }
1362
+
1363
+ /**
1364
+ * Clears all recipients assigned in the TO, CC and BCC
1365
+ * array. Returns void.
1366
+ * @return void
1367
+ */
1368
+ function ClearAllRecipients() {
1369
+ $this->to = array();
1370
+ $this->cc = array();
1371
+ $this->bcc = array();
1372
+ }
1373
+
1374
+ /**
1375
+ * Clears all previously set filesystem, string, and binary
1376
+ * attachments. Returns void.
1377
+ * @return void
1378
+ */
1379
+ function ClearAttachments() {
1380
+ $this->attachment = array();
1381
+ }
1382
+
1383
+ /**
1384
+ * Clears all custom headers. Returns void.
1385
+ * @return void
1386
+ */
1387
+ function ClearCustomHeaders() {
1388
+ $this->CustomHeader = array();
1389
+ }
1390
+
1391
+
1392
+ /////////////////////////////////////////////////
1393
+ // MISCELLANEOUS METHODS
1394
+ /////////////////////////////////////////////////
1395
+
1396
+ /**
1397
+ * Adds the error message to the error container.
1398
+ * Returns void.
1399
+ * @access private
1400
+ * @return void
1401
+ */
1402
+ function SetError($msg) {
1403
+ $this->error_count++;
1404
+ $this->ErrorInfo = $msg;
1405
+ }
1406
+
1407
+ /**
1408
+ * Returns the proper RFC 822 formatted date.
1409
+ * @access private
1410
+ * @return string
1411
+ */
1412
+ function RFCDate() {
1413
+ $tz = date("Z");
1414
+ $tzs = ($tz < 0) ? "-" : "+";
1415
+ $tz = abs($tz);
1416
+ $tz = ($tz/3600)*100 + ($tz%3600)/60;
1417
+ $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
1418
+
1419
+ return $result;
1420
+ }
1421
+
1422
+ /**
1423
+ * Returns the appropriate server variable. Should work with both
1424
+ * PHP 4.1.0+ as well as older versions. Returns an empty string
1425
+ * if nothing is found.
1426
+ * @access private
1427
+ * @return mixed
1428
+ */
1429
+ function ServerVar($varName) {
1430
+ global $HTTP_SERVER_VARS;
1431
+ global $HTTP_ENV_VARS;
1432
+
1433
+ if(!isset($_SERVER))
1434
+ {
1435
+ $_SERVER = $HTTP_SERVER_VARS;
1436
+ if(!isset($_SERVER["REMOTE_ADDR"]))
1437
+ $_SERVER = $HTTP_ENV_VARS; // must be Apache
1438
+ }
1439
+
1440
+ if(isset($_SERVER[$varName]))
1441
+ return $_SERVER[$varName];
1442
+ else
1443
+ return "";
1444
+ }
1445
+
1446
+ /**
1447
+ * Returns the server hostname or 'localhost.localdomain' if unknown.
1448
+ * @access private
1449
+ * @return string
1450
+ */
1451
+ function ServerHostname() {
1452
+ if ($this->Hostname != "")
1453
+ $result = $this->Hostname;
1454
+ elseif ($this->ServerVar('SERVER_NAME') != "")
1455
+ $result = $this->ServerVar('SERVER_NAME');
1456
+ else
1457
+ $result = "localhost.localdomain";
1458
+
1459
+ return $result;
1460
+ }
1461
+
1462
+ /**
1463
+ * Returns a message in the appropriate language.
1464
+ * @access private
1465
+ * @return string
1466
+ */
1467
+ function Lang($key) {
1468
+ if(count($this->language) < 1)
1469
+ $this->SetLanguage("en"); // set the default language
1470
+
1471
+ if(isset($this->language[$key]))
1472
+ return $this->language[$key];
1473
+ else
1474
+ return "Language string failed to load: " . $key;
1475
+ }
1476
+
1477
+ /**
1478
+ * Returns true if an error occurred.
1479
+ * @return bool
1480
+ */
1481
+ function IsError() {
1482
+ return ($this->error_count > 0);
1483
+ }
1484
+
1485
+ /**
1486
+ * Changes every end of line from CR or LF to CRLF.
1487
+ * @access private
1488
+ * @return string
1489
+ */
1490
+ function FixEOL($str) {
1491
+ $str = str_replace("\r\n", "\n", $str);
1492
+ $str = str_replace("\r", "\n", $str);
1493
+ $str = str_replace("\n", $this->LE, $str);
1494
+ return $str;
1495
+ }
1496
+
1497
+ /**
1498
+ * Adds a custom header.
1499
+ * @return void
1500
+ */
1501
+ function AddCustomHeader($custom_header) {
1502
+ $this->CustomHeader[] = explode(":", $custom_header, 2);
1503
+ }
1504
+ }
1505
+
1506
+ ?>
classes/phpmailer/class.smtp.php CHANGED
@@ -1,1045 +1,1045 @@
1
- <?php
2
- ////////////////////////////////////////////////////
3
- // SMTP - PHP SMTP class
4
- //
5
- // Version 1.02
6
- //
7
- // Define an SMTP class that can be used to connect
8
- // and communicate with any SMTP server. It implements
9
- // all the SMTP functions defined in RFC821 except TURN.
10
- //
11
- // Author: Chris Ryan
12
- //
13
- // License: LGPL, see LICENSE
14
- ////////////////////////////////////////////////////
15
-
16
- /**
17
- * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
18
- * commands except TURN which will always return a not implemented
19
- * error. SMTP also provides some utility methods for sending mail
20
- * to an SMTP server.
21
- * @package PHPMailer
22
- * @author Chris Ryan
23
- */
24
- class EM_SMTP
25
- {
26
- /**
27
- * SMTP server port
28
- * @var int
29
- */
30
- var $SMTP_PORT = 25;
31
-
32
- /**
33
- * SMTP reply line ending
34
- * @var string
35
- */
36
- var $CRLF = "\r\n";
37
-
38
- /**
39
- * Sets whether debugging is turned on
40
- * @var bool
41
- */
42
- var $do_debug; # the level of debug to perform
43
-
44
- /**#@+
45
- * @access private
46
- */
47
- var $smtp_conn; # the socket to the server
48
- var $error; # error if any on the last call
49
- var $helo_rply; # the reply the server sent to us for HELO
50
- /**#@-*/
51
-
52
- /**
53
- * Initialize the class so that the data is in a known state.
54
- * @access public
55
- * @return void
56
- */
57
- function EM_SMTP() {
58
- $this->smtp_conn = 0;
59
- $this->error = null;
60
- $this->helo_rply = null;
61
-
62
- $this->do_debug = 0;
63
- }
64
-
65
- /*************************************************************
66
- * CONNECTION FUNCTIONS *
67
- ***********************************************************/
68
-
69
- /**
70
- * Connect to the server specified on the port specified.
71
- * If the port is not specified use the default SMTP_PORT.
72
- * If tval is specified then a connection will try and be
73
- * established with the server for that number of seconds.
74
- * If tval is not specified the default is 30 seconds to
75
- * try on the connection.
76
- *
77
- * SMTP CODE SUCCESS: 220
78
- * SMTP CODE FAILURE: 421
79
- * @access public
80
- * @return bool
81
- */
82
- function Connect($host,$port=0,$tval=30) {
83
- # set the error val to null so there is no confusion
84
- $this->error = null;
85
-
86
- # make sure we are __not__ connected
87
- if($this->connected()) {
88
- # ok we are connected! what should we do?
89
- # for now we will just give an error saying we
90
- # are already connected
91
- $this->error =
92
- array("error" => "Already connected to a server");
93
- return false;
94
- }
95
-
96
- if(empty($port)) {
97
- $port = $this->SMTP_PORT;
98
- }
99
-
100
- #connect to the smtp server
101
- $this->smtp_conn = fsockopen($host, # the host of the server
102
- $port, # the port to use
103
- $errno, # error number if any
104
- $errstr, # error message if any
105
- $tval); # give up after ? secs
106
- # verify we connected properly
107
- if(empty($this->smtp_conn)) {
108
- $this->error = array("error" => "Failed to connect to server",
109
- "errno" => $errno,
110
- "errstr" => $errstr);
111
- if($this->do_debug >= 1) {
112
- echo "SMTP -> ERROR: " . $this->error["error"] .
113
- ": $errstr ($errno)" . $this->CRLF;
114
- }
115
- return false;
116
- }
117
-
118
- # sometimes the SMTP server takes a little longer to respond
119
- # so we will give it a longer timeout for the first read
120
- // Windows still does not have support for this timeout function
121
- if(substr(PHP_OS, 0, 3) != "WIN")
122
- socket_set_timeout($this->smtp_conn, $tval, 0);
123
-
124
- # get any announcement stuff
125
- $announce = $this->get_lines();
126
-
127
- # set the timeout of any socket functions at 1/10 of a second
128
- //if(function_exists("socket_set_timeout"))
129
- // socket_set_timeout($this->smtp_conn, 0, 100000);
130
-
131
- if($this->do_debug >= 2) {
132
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
133
- }
134
-
135
- return true;
136
- }
137
-
138
- /**
139
- * Performs SMTP authentication. Must be run after running the
140
- * Hello() method. Returns true if successfully authenticated.
141
- * @access public
142
- * @return bool
143
- */
144
- function Authenticate($username, $password) {
145
- // Start authentication
146
- fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
147
-
148
- $rply = $this->get_lines();
149
- $code = substr($rply,0,3);
150
-
151
- if($code != 334) {
152
- $this->error =
153
- array("error" => "AUTH not accepted from server",
154
- "smtp_code" => $code,
155
- "smtp_msg" => substr($rply,4));
156
- if($this->do_debug >= 1) {
157
- echo "SMTP -> ERROR: " . $this->error["error"] .
158
- ": " . $rply . $this->CRLF;
159
- }
160
- return false;
161
- }
162
-
163
- // Send encoded username
164
- fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
165
-
166
- $rply = $this->get_lines();
167
- $code = substr($rply,0,3);
168
-
169
- if($code != 334) {
170
- $this->error =
171
- array("error" => "Username not accepted from server",
172
- "smtp_code" => $code,
173
- "smtp_msg" => substr($rply,4));
174
- if($this->do_debug >= 1) {
175
- echo "SMTP -> ERROR: " . $this->error["error"] .
176
- ": " . $rply . $this->CRLF;
177
- }
178
- return false;
179
- }
180
-
181
- // Send encoded password
182
- fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
183
-
184
- $rply = $this->get_lines();
185
- $code = substr($rply,0,3);
186
-
187
- if($code != 235) {
188
- $this->error =
189
- array("error" => "Password not accepted from server",
190
- "smtp_code" => $code,
191
- "smtp_msg" => substr($rply,4));
192
- if($this->do_debug >= 1) {
193
- echo "SMTP -> ERROR: " . $this->error["error"] .
194
- ": " . $rply . $this->CRLF;
195
- }
196
- return false;
197
- }
198
-
199
- return true;
200
- }
201
-
202
- /**
203
- * Returns true if connected to a server otherwise false
204
- * @access private
205
- * @return bool
206
- */
207
- function Connected() {
208
- if(!empty($this->smtp_conn)) {
209
- $sock_status = socket_get_status($this->smtp_conn);
210
- if($sock_status["eof"]) {
211
- # hmm this is an odd situation... the socket is
212
- # valid but we aren't connected anymore
213
- if($this->do_debug >= 1) {
214
- echo "SMTP -> NOTICE:" . $this->CRLF .
215
- "EOF caught while checking if connected";
216
- }
217
- $this->Close();
218
- return false;
219
- }
220
- return true; # everything looks good
221
- }
222
- return false;
223
- }
224
-
225
- /**
226
- * Closes the socket and cleans up the state of the class.
227
- * It is not considered good to use this function without
228
- * first trying to use QUIT.
229
- * @access public
230
- * @return void
231
- */
232
- function Close() {
233
- $this->error = null; # so there is no confusion
234
- $this->helo_rply = null;
235
- if(!empty($this->smtp_conn)) {
236
- # close the connection and cleanup
237
- fclose($this->smtp_conn);
238
- $this->smtp_conn = 0;
239
- }
240
- }
241
-
242
-
243
- /***************************************************************
244
- * SMTP COMMANDS *
245
- *************************************************************/
246
-
247
- /**
248
- * Issues a data command and sends the msg_data to the server
249
- * finializing the mail transaction. $msg_data is the message
250
- * that is to be send with the headers. Each header needs to be
251
- * on a single line followed by a <CRLF> with the message headers
252
- * and the message body being seperated by and additional <CRLF>.
253
- *
254
- * Implements rfc 821: DATA <CRLF>
255
- *
256
- * SMTP CODE INTERMEDIATE: 354
257
- * [data]
258
- * <CRLF>.<CRLF>
259
- * SMTP CODE SUCCESS: 250
260
- * SMTP CODE FAILURE: 552,554,451,452
261
- * SMTP CODE FAILURE: 451,554
262
- * SMTP CODE ERROR : 500,501,503,421
263
- * @access public
264
- * @return bool
265
- */
266
- function Data($msg_data) {
267
- $this->error = null; # so no confusion is caused
268
-
269
- if(!$this->connected()) {
270
- $this->error = array(
271
- "error" => "Called Data() without being connected");
272
- return false;
273
- }
274
-
275
- fputs($this->smtp_conn,"DATA" . $this->CRLF);
276
-
277
- $rply = $this->get_lines();
278
- $code = substr($rply,0,3);
279
-
280
- if($this->do_debug >= 2) {
281
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
282
- }
283
-
284
- if($code != 354) {
285
- $this->error =
286
- array("error" => "DATA command not accepted from server",
287
- "smtp_code" => $code,
288
- "smtp_msg" => substr($rply,4));
289
- if($this->do_debug >= 1) {
290
- echo "SMTP -> ERROR: " . $this->error["error"] .
291
- ": " . $rply . $this->CRLF;
292
- }
293
- return false;
294
- }
295
-
296
- # the server is ready to accept data!
297
- # according to rfc 821 we should not send more than 1000
298
- # including the CRLF
299
- # characters on a single line so we will break the data up
300
- # into lines by \r and/or \n then if needed we will break
301
- # each of those into smaller lines to fit within the limit.
302
- # in addition we will be looking for lines that start with
303
- # a period '.' and append and additional period '.' to that
304
- # line. NOTE: this does not count towards are limit.
305
-
306
- # normalize the line breaks so we know the explode works
307
- $msg_data = str_replace("\r\n","\n",$msg_data);
308
- $msg_data = str_replace("\r","\n",$msg_data);
309
- $lines = explode("\n",$msg_data);
310
-
311
- # we need to find a good way to determine is headers are
312
- # in the msg_data or if it is a straight msg body
313
- # currently I'm assuming rfc 822 definitions of msg headers
314
- # and if the first field of the first line (':' sperated)
315
- # does not contain a space then it _should_ be a header
316
- # and we can process all lines before a blank "" line as
317
- # headers.
318
- $field = substr($lines[0],0,strpos($lines[0],":"));
319
- $in_headers = false;
320
- if(!empty($field) && !strstr($field," ")) {
321
- $in_headers = true;
322
- }
323
-
324
- $max_line_length = 998; # used below; set here for ease in change
325
-
326
- while(list(,$line) = @each($lines)) {
327
- $lines_out = null;
328
- if($line == "" && $in_headers) {
329
- $in_headers = false;
330
- }
331
- # ok we need to break this line up into several
332
- # smaller lines
333
- while(strlen($line) > $max_line_length) {
334
- $pos = strrpos(substr($line,0,$max_line_length)," ");
335
-
336
- # Patch to fix DOS attack
337
- if(!$pos) {
338
- $pos = $max_line_length - 1;
339
- }
340
-
341
- $lines_out[] = substr($line,0,$pos);
342
- $line = substr($line,$pos + 1);
343
- # if we are processing headers we need to
344
- # add a LWSP-char to the front of the new line
345
- # rfc 822 on long msg headers
346
- if($in_headers) {
347
- $line = "\t" . $line;
348
- }
349
- }
350
- $lines_out[] = $line;
351
-
352
- # now send the lines to the server
353
- while(list(,$line_out) = @each($lines_out)) {
354
- if(strlen($line_out) > 0)
355
- {
356
- if(substr($line_out, 0, 1) == ".") {
357
- $line_out = "." . $line_out;
358
- }
359
- }
360
- fputs($this->smtp_conn,$line_out . $this->CRLF);
361
- }
362
- }
363
-
364
- # ok all the message data has been sent so lets get this
365
- # over with aleady
366
- fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
367
-
368
- $rply = $this->get_lines();
369
- $code = substr($rply,0,3);
370
-
371
- if($this->do_debug >= 2) {
372
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
373
- }
374
-
375
- if($code != 250) {
376
- $this->error =
377
- array("error" => "DATA not accepted from server",
378
- "smtp_code" => $code,
379
- "smtp_msg" => substr($rply,4));
380
- if($this->do_debug >= 1) {
381
- echo "SMTP -> ERROR: " . $this->error["error"] .
382
- ": " . $rply . $this->CRLF;
383
- }
384
- return false;
385
- }
386
- return true;
387
- }
388
-
389
- /**
390
- * Expand takes the name and asks the server to list all the
391
- * people who are members of the _list_. Expand will return
392
- * back and array of the result or false if an error occurs.
393
- * Each value in the array returned has the format of:
394
- * [ <full-name> <sp> ] <path>
395
- * The definition of <path> is defined in rfc 821
396
- *
397
- * Implements rfc 821: EXPN <SP> <string> <CRLF>
398
- *
399
- * SMTP CODE SUCCESS: 250
400
- * SMTP CODE FAILURE: 550
401
- * SMTP CODE ERROR : 500,501,502,504,421
402
- * @access public
403
- * @return string array
404
- */
405
- function Expand($name) {
406
- $this->error = null; # so no confusion is caused
407
-
408
- if(!$this->connected()) {
409
- $this->error = array(
410
- "error" => "Called Expand() without being connected");
411
- return false;
412
- }
413
-
414
- fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
415
-
416
- $rply = $this->get_lines();
417
- $code = substr($rply,0,3);
418
-
419
- if($this->do_debug >= 2) {
420
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
421
- }
422
-
423
- if($code != 250) {
424
- $this->error =
425
- array("error" => "EXPN not accepted from server",
426
- "smtp_code" => $code,
427
- "smtp_msg" => substr($rply,4));
428
- if($this->do_debug >= 1) {
429
- echo "SMTP -> ERROR: " . $this->error["error"] .
430
- ": " . $rply . $this->CRLF;
431
- }
432
- return false;
433
- }
434
-
435
- # parse the reply and place in our array to return to user
436
- $entries = explode($this->CRLF,$rply);
437
- while(list(,$l) = @each($entries)) {
438
- $list[] = substr($l,4);
439
- }
440
-
441
- return $list;
442
- }
443
-
444
- /**
445
- * Sends the HELO command to the smtp server.
446
- * This makes sure that we and the server are in
447
- * the same known state.
448
- *
449
- * Implements from rfc 821: HELO <SP> <domain> <CRLF>
450
- *
451
- * SMTP CODE SUCCESS: 250
452
- * SMTP CODE ERROR : 500, 501, 504, 421
453
- * @access public
454
- * @return bool
455
- */
456
- function Hello($host="") {
457
- $this->error = null; # so no confusion is caused
458
-
459
- if(!$this->connected()) {
460
- $this->error = array(
461
- "error" => "Called Hello() without being connected");
462
- return false;
463
- }
464
-
465
- # if a hostname for the HELO wasn't specified determine
466
- # a suitable one to send
467
- if(empty($host)) {
468
- # we need to determine some sort of appopiate default
469
- # to send to the server
470
- $host = "localhost";
471
- }
472
-
473
- // Send extended hello first (RFC 2821)
474
- if(!$this->SendHello("EHLO", $host))
475
- {
476
- if(!$this->SendHello("HELO", $host))
477
- return false;
478
- }
479
-
480
- return true;
481
- }
482
-
483
- /**
484
- * Sends a HELO/EHLO command.
485
- * @access private
486
- * @return bool
487
- */
488
- function SendHello($hello, $host) {
489
- fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
490
-
491
- $rply = $this->get_lines();
492
- $code = substr($rply,0,3);
493
-
494
- if($this->do_debug >= 2) {
495
- echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
496
- }
497
-
498
- if($code != 250) {
499
- $this->error =
500
- array("error" => $hello . " not accepted from server",
501
- "smtp_code" => $code,
502
- "smtp_msg" => substr($rply,4));
503
- if($this->do_debug >= 1) {
504
- echo "SMTP -> ERROR: " . $this->error["error"] .
505
- ": " . $rply . $this->CRLF;
506
- }
507
- return false;
508
- }
509
-
510
- $this->helo_rply = $rply;
511
-
512
- return true;
513
- }
514
-
515
- /**
516
- * Gets help information on the keyword specified. If the keyword
517
- * is not specified then returns generic help, ussually contianing
518
- * A list of keywords that help is available on. This function
519
- * returns the results back to the user. It is up to the user to
520
- * handle the returned data. If an error occurs then false is
521
- * returned with $this->error set appropiately.
522
- *
523
- * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
524
- *
525
- * SMTP CODE SUCCESS: 211,214
526
- * SMTP CODE ERROR : 500,501,502,504,421
527
- * @access public
528
- * @return string
529
- */
530
- function Help($keyword="") {
531
- $this->error = null; # to avoid confusion
532
-
533
- if(!$this->connected()) {
534
- $this->error = array(
535
- "error" => "Called Help() without being connected");
536
- return false;
537
- }
538
-
539
- $extra = "";
540
- if(!empty($keyword)) {
541
- $extra = " " . $keyword;
542
- }
543
-
544
- fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
545
-
546
- $rply = $this->get_lines();
547
- $code = substr($rply,0,3);
548
-
549
- if($this->do_debug >= 2) {
550
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
551
- }
552
-
553
- if($code != 211 && $code != 214) {
554
- $this->error =
555
- array("error" => "HELP not accepted from server",
556
- "smtp_code" => $code,
557
- "smtp_msg" => substr($rply,4));
558
- if($this->do_debug >= 1) {
559
- echo "SMTP -> ERROR: " . $this->error["error"] .
560
- ": " . $rply . $this->CRLF;
561
- }
562
- return false;
563
- }
564
-
565
- return $rply;
566
- }
567
-
568
- /**
569
- * Starts a mail transaction from the email address specified in
570
- * $from. Returns true if successful or false otherwise. If True
571
- * the mail transaction is started and then one or more Recipient
572
- * commands may be called followed by a Data command.
573
- *
574
- * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
575
- *
576
- * SMTP CODE SUCCESS: 250
577
- * SMTP CODE SUCCESS: 552,451,452
578
- * SMTP CODE SUCCESS: 500,501,421
579
- * @access public
580
- * @return bool
581
- */
582
- function Mail($from) {
583
- $this->error = null; # so no confusion is caused
584
-
585
- if(!$this->connected()) {
586
- $this->error = array(
587
- "error" => "Called Mail() without being connected");
588
- return false;
589
- }
590
-
591
- fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $this->CRLF);
592
-
593
- $rply = $this->get_lines();
594
- $code = substr($rply,0,3);
595
-
596
- if($this->do_debug >= 2) {
597
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
598
- }
599
-
600
- if($code != 250) {
601
- $this->error =
602
- array("error" => "MAIL not accepted from server",
603
- "smtp_code" => $code,
604
- "smtp_msg" => substr($rply,4));
605
- if($this->do_debug >= 1) {
606
- echo "SMTP -> ERROR: " . $this->error["error"] .
607
- ": " . $rply . $this->CRLF;
608
- }
609
- return false;
610
- }
611
- return true;
612
- }
613
-
614
- /**
615
- * Sends the command NOOP to the SMTP server.
616
- *
617
- * Implements from rfc 821: NOOP <CRLF>
618
- *
619
- * SMTP CODE SUCCESS: 250
620
- * SMTP CODE ERROR : 500, 421
621
- * @access public
622
- * @return bool
623
- */
624
- function Noop() {
625
- $this->error = null; # so no confusion is caused
626
-
627
- if(!$this->connected()) {
628
- $this->error = array(
629
- "error" => "Called Noop() without being connected");
630
- return false;
631
- }
632
-
633
- fputs($this->smtp_conn,"NOOP" . $this->CRLF);
634
-
635
- $rply = $this->get_lines();
636
- $code = substr($rply,0,3);
637
-
638
- if($this->do_debug >= 2) {
639
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
640
- }
641
-
642
- if($code != 250) {
643
- $this->error =
644
- array("error" => "NOOP not accepted from server",
645
- "smtp_code" => $code,
646
- "smtp_msg" => substr($rply,4));
647
- if($this->do_debug >= 1) {
648
- echo "SMTP -> ERROR: " . $this->error["error"] .
649
- ": " . $rply . $this->CRLF;
650
- }
651
- return false;
652
- }
653
- return true;
654
- }
655
-
656
- /**
657
- * Sends the quit command to the server and then closes the socket
658
- * if there is no error or the $close_on_error argument is true.
659
- *
660
- * Implements from rfc 821: QUIT <CRLF>
661
- *
662
- * SMTP CODE SUCCESS: 221
663
- * SMTP CODE ERROR : 500
664
- * @access public
665
- * @return bool
666
- */
667
- function Quit($close_on_error=true) {
668
- $this->error = null; # so there is no confusion
669
-
670
- if(!$this->connected()) {
671
- $this->error = array(
672
- "error" => "Called Quit() without being connected");
673
- return false;
674
- }
675
-
676
- # send the quit command to the server
677
- fputs($this->smtp_conn,"quit" . $this->CRLF);
678
-
679
- # get any good-bye messages
680
- $byemsg = $this->get_lines();
681
-
682
- if($this->do_debug >= 2) {
683
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
684
- }
685
-
686
- $rval = true;
687
- $e = null;
688
-
689
- $code = substr($byemsg,0,3);
690
- if($code != 221) {
691
- # use e as a tmp var cause Close will overwrite $this->error
692
- $e = array("error" => "SMTP server rejected quit command",
693
- "smtp_code" => $code,
694
- "smtp_rply" => substr($byemsg,4));
695
- $rval = false;
696
- if($this->do_debug >= 1) {
697
- echo "SMTP -> ERROR: " . $e["error"] . ": " .
698
- $byemsg . $this->CRLF;
699
- }
700
- }
701
-
702
- if(empty($e) || $close_on_error) {
703
- $this->Close();
704
- }
705
-
706
- return $rval;
707
- }
708
-
709
- /**
710
- * Sends the command RCPT to the SMTP server with the TO: argument of $to.
711
- * Returns true if the recipient was accepted false if it was rejected.
712
- *
713
- * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
714
- *
715
- * SMTP CODE SUCCESS: 250,251
716
- * SMTP CODE FAILURE: 550,551,552,553,450,451,452
717
- * SMTP CODE ERROR : 500,501,503,421
718
- * @access public
719
- * @return bool
720
- */
721
- function Recipient($to) {
722
- $this->error = null; # so no confusion is caused
723
-
724
- if(!$this->connected()) {
725
- $this->error = array(
726
- "error" => "Called Recipient() without being connected");
727
- return false;
728
- }
729
-
730
- fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
731
-
732
- $rply = $this->get_lines();
733
- $code = substr($rply,0,3);
734
-
735
- if($this->do_debug >= 2) {
736
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
737
- }
738
-
739
- if($code != 250 && $code != 251) {
740
- $this->error =
741
- array("error" => "RCPT not accepted from server",
742
- "smtp_code" => $code,
743
- "smtp_msg" => substr($rply,4));
744
- if($this->do_debug >= 1) {
745
- echo "SMTP -> ERROR: " . $this->error["error"] .
746
- ": " . $rply . $this->CRLF;
747
- }
748
- return false;
749
- }
750
- return true;
751
- }
752
-
753
- /**
754
- * Sends the RSET command to abort and transaction that is
755
- * currently in progress. Returns true if successful false
756
- * otherwise.
757
- *
758
- * Implements rfc 821: RSET <CRLF>
759
- *
760
- * SMTP CODE SUCCESS: 250
761
- * SMTP CODE ERROR : 500,501,504,421
762
- * @access public
763
- * @return bool
764
- */
765
- function Reset() {
766
- $this->error = null; # so no confusion is caused
767
-
768
- if(!$this->connected()) {
769
- $this->error = array(
770
- "error" => "Called Reset() without being connected");
771
- return false;
772
- }
773
-
774
- fputs($this->smtp_conn,"RSET" . $this->CRLF);
775
-
776
- $rply = $this->get_lines();
777
- $code = substr($rply,0,3);
778
-
779
- if($this->do_debug >= 2) {
780
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
781
- }
782
-
783
- if($code != 250) {
784
- $this->error =
785
- array("error" => "RSET failed",
786
- "smtp_code" => $code,
787
- "smtp_msg" => substr($rply,4));
788
- if($this->do_debug >= 1) {
789
- echo "SMTP -> ERROR: " . $this->error["error"] .
790
- ": " . $rply . $this->CRLF;
791
- }
792
- return false;
793
- }
794
-
795
- return true;
796
- }
797
-
798
- /**
799
- * Starts a mail transaction from the email address specified in
800
- * $from. Returns true if successful or false otherwise. If True
801
- * the mail transaction is started and then one or more Recipient
802
- * commands may be called followed by a Data command. This command
803
- * will send the message to the users terminal if they are logged
804
- * in.
805
- *
806
- * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
807
- *
808
- * SMTP CODE SUCCESS: 250
809
- * SMTP CODE SUCCESS: 552,451,452
810
- * SMTP CODE SUCCESS: 500,501,502,421
811
- * @access public
812
- * @return bool
813
- */
814
- function Send($from) {
815
- $this->error = null; # so no confusion is caused
816
-
817
- if(!$this->connected()) {
818
- $this->error = array(
819
- "error" => "Called Send() without being connected");
820
- return false;
821
- }
822
-
823
- fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
824
-
825
- $rply = $this->get_lines();
826
- $code = substr($rply,0,3);
827
-
828
- if($this->do_debug >= 2) {
829
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
830
- }
831
-
832
- if($code != 250) {
833
- $this->error =
834
- array("error" => "SEND not accepted from server",
835
- "smtp_code" => $code,
836
- "smtp_msg" => substr($rply,4));
837
- if($this->do_debug >= 1) {
838
- echo "SMTP -> ERROR: " . $this->error["error"] .
839
- ": " . $rply . $this->CRLF;
840
- }
841
- return false;
842
- }
843
- return true;
844
- }
845
-
846
- /**
847
- * Starts a mail transaction from the email address specified in
848
- * $from. Returns true if successful or false otherwise. If True
849
- * the mail transaction is started and then one or more Recipient
850
- * commands may be called followed by a Data command. This command
851
- * will send the message to the users terminal if they are logged
852
- * in and send them an email.
853
- *
854
- * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
855
- *
856
- * SMTP CODE SUCCESS: 250
857
- * SMTP CODE SUCCESS: 552,451,452
858
- * SMTP CODE SUCCESS: 500,501,502,421
859
- * @access public
860
- * @return bool
861
- */
862
- function SendAndMail($from) {
863
- $this->error = null; # so no confusion is caused
864
-
865
- if(!$this->connected()) {
866
- $this->error = array(
867
- "error" => "Called SendAndMail() without being connected");
868
- return false;
869
- }
870
-
871
- fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
872
-
873
- $rply = $this->get_lines();
874
- $code = substr($rply,0,3);
875
-
876
- if($this->do_debug >= 2) {
877
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
878
- }
879
-
880
- if($code != 250) {
881
- $this->error =
882
- array("error" => "SAML not accepted from server",
883
- "smtp_code" => $code,
884
- "smtp_msg" => substr($rply,4));
885
- if($this->do_debug >= 1) {
886
- echo "SMTP -> ERROR: " . $this->error["error"] .
887
- ": " . $rply . $this->CRLF;
888
- }
889
- return false;
890
- }
891
- return true;
892
- }
893
-
894
- /**
895
- * Starts a mail transaction from the email address specified in
896
- * $from. Returns true if successful or false otherwise. If True
897
- * the mail transaction is started and then one or more Recipient
898
- * commands may be called followed by a Data command. This command
899
- * will send the message to the users terminal if they are logged
900
- * in or mail it to them if they are not.
901
- *
902
- * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
903
- *
904
- * SMTP CODE SUCCESS: 250
905
- * SMTP CODE SUCCESS: 552,451,452
906
- * SMTP CODE SUCCESS: 500,501,502,421
907
- * @access public
908
- * @return bool
909
- */
910
- function SendOrMail($from) {
911
- $this->error = null; # so no confusion is caused
912
-
913
- if(!$this->connected()) {
914
- $this->error = array(
915
- "error" => "Called SendOrMail() without being connected");
916
- return false;
917
- }
918
-
919
- fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
920
-
921
- $rply = $this->get_lines();
922
- $code = substr($rply,0,3);
923
-
924
- if($this->do_debug >= 2) {
925
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
926
- }
927
-
928
- if($code != 250) {
929
- $this->error =
930
- array("error" => "SOML not accepted from server",
931
- "smtp_code" => $code,
932
- "smtp_msg" => substr($rply,4));
933
- if($this->do_debug >= 1) {
934
- echo "SMTP -> ERROR: " . $this->error["error"] .
935
- ": " . $rply . $this->CRLF;
936
- }
937
- return false;
938
- }
939
- return true;
940
- }
941
-
942
- /**
943
- * This is an optional command for SMTP that this class does not
944
- * support. This method is here to make the RFC821 Definition
945
- * complete for this class and __may__ be implimented in the future
946
- *
947
- * Implements from rfc 821: TURN <CRLF>
948
- *
949
- * SMTP CODE SUCCESS: 250
950
- * SMTP CODE FAILURE: 502
951
- * SMTP CODE ERROR : 500, 503
952
- * @access public
953
- * @return bool
954
- */
955
- function Turn() {
956
- $this->error = array("error" => "This method, TURN, of the SMTP ".
957
- "is not implemented");
958
- if($this->do_debug >= 1) {
959
- echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
960
- }
961
- return false;
962
- }
963
-
964
- /**
965
- * Verifies that the name is recognized by the server.
966
- * Returns false if the name could not be verified otherwise
967
- * the response from the server is returned.
968
- *
969
- * Implements rfc 821: VRFY <SP> <string> <CRLF>
970
- *
971
- * SMTP CODE SUCCESS: 250,251
972
- * SMTP CODE FAILURE: 550,551,553
973
- * SMTP CODE ERROR : 500,501,502,421
974
- * @access public
975
- * @return int
976
- */
977
- function Verify($name) {
978
- $this->error = null; # so no confusion is caused
979
-
980
- if(!$this->connected()) {
981
- $this->error = array(
982
- "error" => "Called Verify() without being connected");
983
- return false;
984
- }
985
-
986
- fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
987
-
988
- $rply = $this->get_lines();
989
- $code = substr($rply,0,3);
990
-
991
- if($this->do_debug >= 2) {
992
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
993
- }
994
-
995
- if($code != 250 && $code != 251) {
996
- $this->error =
997
- array("error" => "VRFY failed on name '$name'",
998
- "smtp_code" => $code,
999
- "smtp_msg" => substr($rply,4));
1000
- if($this->do_debug >= 1) {
1001
- echo "SMTP -> ERROR: " . $this->error["error"] .
1002
- ": " . $rply . $this->CRLF;
1003
- }
1004
- return false;
1005
- }
1006
- return $rply;
1007
- }
1008
-
1009
- /*******************************************************************
1010
- * INTERNAL FUNCTIONS *
1011
- ******************************************************************/
1012
-
1013
- /**
1014
- * Read in as many lines as possible
1015
- * either before eof or socket timeout occurs on the operation.
1016
- * With SMTP we can tell if we have more lines to read if the
1017
- * 4th character is '-' symbol. If it is a space then we don't
1018
- * need to read anything else.
1019
- * @access private
1020
- * @return string
1021
- */
1022
- function get_lines() {
1023
- $data = "";
1024
- while($str = fgets($this->smtp_conn,515)) {
1025
- if($this->do_debug >= 4) {
1026
- echo "SMTP -> get_lines(): \$data was \"$data\"" .
1027
- $this->CRLF;
1028
- echo "SMTP -> get_lines(): \$str is \"$str\"" .
1029
- $this->CRLF;
1030
- }
1031
- $data .= $str;
1032
- if($this->do_debug >= 4) {
1033
- echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
1034
- }
1035
- # if the 4th character is a space then we are done reading
1036
- # so just break the loop
1037
- if(substr($str,3,1) == " ") { break; }
1038
- }
1039
- return $data;
1040
- }
1041
-
1042
- }
1043
-
1044
-
1045
- ?>
1
+ <?php
2
+ ////////////////////////////////////////////////////
3
+ // SMTP - PHP SMTP class
4
+ //
5
+ // Version 1.02
6
+ //
7
+ // Define an SMTP class that can be used to connect
8
+ // and communicate with any SMTP server. It implements
9
+ // all the SMTP functions defined in RFC821 except TURN.
10
+ //
11
+ // Author: Chris Ryan
12
+ //
13
+ // License: LGPL, see LICENSE
14
+ ////////////////////////////////////////////////////
15
+
16
+ /**
17
+ * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
18
+ * commands except TURN which will always return a not implemented
19
+ * error. SMTP also provides some utility methods for sending mail
20
+ * to an SMTP server.
21
+ * @package PHPMailer
22
+ * @author Chris Ryan
23
+ */
24
+ class EM_SMTP
25
+ {
26
+ /**
27
+ * SMTP server port
28
+ * @var int
29
+ */
30
+ var $SMTP_PORT = 25;
31
+
32
+ /**
33
+ * SMTP reply line ending
34
+ * @var string
35
+ */
36
+ var $CRLF = "\r\n";
37
+
38
+ /**
39
+ * Sets whether debugging is turned on
40
+ * @var bool
41
+ */
42
+ var $do_debug; # the level of debug to perform
43
+
44
+ /**#@+
45
+ * @access private
46
+ */
47
+ var $smtp_conn; # the socket to the server
48
+ var $error; # error if any on the last call
49
+ var $helo_rply; # the reply the server sent to us for HELO
50
+ /**#@-*/
51
+
52
+ /**
53
+ * Initialize the class so that the data is in a known state.
54
+ * @access public
55
+ * @return void
56
+ */
57
+ function EM_SMTP() {
58
+ $this->smtp_conn = 0;
59
+ $this->error = null;
60
+ $this->helo_rply = null;
61
+
62
+ $this->do_debug = 0;
63
+ }
64
+
65
+ /*************************************************************
66
+ * CONNECTION FUNCTIONS *
67
+ ***********************************************************/
68
+
69
+ /**
70
+ * Connect to the server specified on the port specified.
71
+ * If the port is not specified use the default SMTP_PORT.
72
+ * If tval is specified then a connection will try and be
73
+ * established with the server for that number of seconds.
74
+ * If tval is not specified the default is 30 seconds to
75
+ * try on the connection.
76
+ *
77
+ * SMTP CODE SUCCESS: 220
78
+ * SMTP CODE FAILURE: 421
79
+ * @access public
80
+ * @return bool
81
+ */
82
+ function Connect($host,$port=0,$tval=30) {
83
+ # set the error val to null so there is no confusion
84
+ $this->error = null;
85
+
86
+ # make sure we are __not__ connected
87
+ if($this->connected()) {
88
+ # ok we are connected! what should we do?
89
+ # for now we will just give an error saying we
90
+ # are already connected
91
+ $this->error =
92
+ array("error" => "Already connected to a server");
93
+ return false;
94
+ }
95
+
96
+ if(empty($port)) {
97
+ $port = $this->SMTP_PORT;
98
+ }
99
+
100
+ #connect to the smtp server
101
+ $this->smtp_conn = fsockopen($host, # the host of the server
102
+ $port, # the port to use
103
+ $errno, # error number if any
104
+ $errstr, # error message if any
105
+ $tval); # give up after ? secs
106
+ # verify we connected properly
107
+ if(empty($this->smtp_conn)) {
108
+ $this->error = array("error" => "Failed to connect to server",
109
+ "errno" => $errno,
110
+ "errstr" => $errstr);
111
+ if($this->do_debug >= 1) {
112
+ echo "SMTP -> ERROR: " . $this->error["error"] .
113
+ ": $errstr ($errno)" . $this->CRLF;
114
+ }
115
+ return false;
116
+ }
117
+
118
+ # sometimes the SMTP server takes a little longer to respond
119
+ # so we will give it a longer timeout for the first read
120
+ // Windows still does not have support for this timeout function
121
+ if(substr(PHP_OS, 0, 3) != "WIN")
122
+ socket_set_timeout($this->smtp_conn, $tval, 0);
123
+
124
+ # get any announcement stuff
125
+ $announce = $this->get_lines();
126
+
127
+ # set the timeout of any socket functions at 1/10 of a second
128
+ //if(function_exists("socket_set_timeout"))
129
+ // socket_set_timeout($this->smtp_conn, 0, 100000);
130
+
131
+ if($this->do_debug >= 2) {
132
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
133
+ }
134
+
135
+ return true;
136
+ }
137
+
138
+ /**
139
+ * Performs SMTP authentication. Must be run after running the
140
+ * Hello() method. Returns true if successfully authenticated.
141
+ * @access public
142
+ * @return bool
143
+ */
144
+ function Authenticate($username, $password) {
145
+ // Start authentication
146
+ fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
147
+
148
+ $rply = $this->get_lines();
149
+ $code = substr($rply,0,3);
150
+
151
+ if($code != 334) {
152
+ $this->error =
153
+ array("error" => "AUTH not accepted from server",
154
+ "smtp_code" => $code,
155
+ "smtp_msg" => substr($rply,4));
156
+ if($this->do_debug >= 1) {
157
+ echo "SMTP -> ERROR: " . $this->error["error"] .
158
+ ": " . $rply . $this->CRLF;
159
+ }
160
+ return false;
161
+ }
162
+
163
+ // Send encoded username
164
+ fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
165
+
166
+ $rply = $this->get_lines();
167
+ $code = substr($rply,0,3);
168
+
169
+ if($code != 334) {
170
+ $this->error =
171
+ array("error" => "Username not accepted from server",
172
+ "smtp_code" => $code,
173
+ "smtp_msg" => substr($rply,4));
174
+ if($this->do_debug >= 1) {
175
+ echo "SMTP -> ERROR: " . $this->error["error"] .
176
+ ": " . $rply . $this->CRLF;
177
+ }
178
+ return false;
179
+ }
180
+
181
+ // Send encoded password
182
+ fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
183
+
184
+ $rply = $this->get_lines();
185
+ $code = substr($rply,0,3);
186
+
187
+ if($code != 235) {
188
+ $this->error =
189
+ array("error" => "Password not accepted from server",
190
+ "smtp_code" => $code,
191
+ "smtp_msg" => substr($rply,4));
192
+ if($this->do_debug >= 1) {
193
+ echo "SMTP -> ERROR: " . $this->error["error"] .
194
+ ": " . $rply . $this->CRLF;
195
+ }
196
+ return false;
197
+ }
198
+
199
+ return true;
200
+ }
201
+
202
+ /**
203
+ * Returns true if connected to a server otherwise false
204
+ * @access private
205
+ * @return bool
206
+ */
207
+ function Connected() {
208
+ if(!empty($this->smtp_conn)) {
209
+ $sock_status = socket_get_status($this->smtp_conn);
210
+ if($sock_status["eof"]) {
211
+ # hmm this is an odd situation... the socket is
212
+ # valid but we aren't connected anymore
213
+ if($this->do_debug >= 1) {
214
+ echo "SMTP -> NOTICE:" . $this->CRLF .
215
+ "EOF caught while checking if connected";
216
+ }
217
+ $this->Close();
218
+ return false;
219
+ }
220
+ return true; # everything looks good
221
+ }
222
+ return false;
223
+ }
224
+
225
+ /**
226
+ * Closes the socket and cleans up the state of the class.
227
+ * It is not considered good to use this function without
228
+ * first trying to use QUIT.
229
+ * @access public
230
+ * @return void
231
+ */
232
+ function Close() {
233
+ $this->error = null; # so there is no confusion
234
+ $this->helo_rply = null;
235
+ if(!empty($this->smtp_conn)) {
236
+ # close the connection and cleanup
237
+ fclose($this->smtp_conn);
238
+ $this->smtp_conn = 0;
239
+ }
240
+ }
241
+
242
+
243
+ /***************************************************************
244
+ * SMTP COMMANDS *
245
+ *************************************************************/
246
+
247
+ /**
248
+ * Issues a data command and sends the msg_data to the server
249
+ * finializing the mail transaction. $msg_data is the message
250
+ * that is to be send with the headers. Each header needs to be
251
+ * on a single line followed by a <CRLF> with the message headers
252
+ * and the message body being seperated by and additional <CRLF>.
253
+ *
254
+ * Implements rfc 821: DATA <CRLF>
255
+ *
256
+ * SMTP CODE INTERMEDIATE: 354
257
+ * [data]
258
+ * <CRLF>.<CRLF>
259
+ * SMTP CODE SUCCESS: 250
260
+ * SMTP CODE FAILURE: 552,554,451,452
261
+ * SMTP CODE FAILURE: 451,554
262
+ * SMTP CODE ERROR : 500,501,503,421
263
+ * @access public
264
+ * @return bool
265
+ */
266
+ function Data($msg_data) {
267
+ $this->error = null; # so no confusion is caused
268
+
269
+ if(!$this->connected()) {
270
+ $this->error = array(
271
+ "error" => "Called Data() without being connected");
272
+ return false;
273
+ }
274
+
275
+ fputs($this->smtp_conn,"DATA" . $this->CRLF);
276
+
277
+ $rply = $this->get_lines();
278
+ $code = substr($rply,0,3);
279
+
280
+ if($this->do_debug >= 2) {
281
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
282
+ }
283
+
284
+ if($code != 354) {
285
+ $this->error =
286
+ array("error" => "DATA command not accepted from server",
287
+ "smtp_code" => $code,
288
+ "smtp_msg" => substr($rply,4));
289
+ if($this->do_debug >= 1) {
290
+ echo "SMTP -> ERROR: " . $this->error["error"] .
291
+ ": " . $rply . $this->CRLF;
292
+ }
293
+ return false;
294
+ }
295
+
296
+ # the server is ready to accept data!
297
+ # according to rfc 821 we should not send more than 1000
298
+ # including the CRLF
299
+ # characters on a single line so we will break the data up
300
+ # into lines by \r and/or \n then if needed we will break
301
+ # each of those into smaller lines to fit within the limit.
302
+ # in addition we will be looking for lines that start with
303
+ # a period '.' and append and additional period '.' to that
304
+ # line. NOTE: this does not count towards are limit.
305
+
306
+ # normalize the line breaks so we know the explode works
307
+ $msg_data = str_replace("\r\n","\n",$msg_data);
308
+ $msg_data = str_replace("\r","\n",$msg_data);
309
+ $lines = explode("\n",$msg_data);
310
+
311
+ # we need to find a good way to determine is headers are
312
+ # in the msg_data or if it is a straight msg body
313
+ # currently I'm assuming rfc 822 definitions of msg headers
314
+ # and if the first field of the first line (':' sperated)
315
+ # does not contain a space then it _should_ be a header
316
+ # and we can process all lines before a blank "" line as
317
+ # headers.
318
+ $field = substr($lines[0],0,strpos($lines[0],":"));
319
+ $in_headers = false;
320
+ if(!empty($field) && !strstr($field," ")) {
321
+ $in_headers = true;
322
+ }
323
+
324
+ $max_line_length = 998; # used below; set here for ease in change
325
+
326
+ while(list(,$line) = @each($lines)) {
327
+ $lines_out = null;
328
+ if($line == "" && $in_headers) {
329
+ $in_headers = false;
330
+ }
331
+ # ok we need to break this line up into several
332
+ # smaller lines
333
+ while(strlen($line) > $max_line_length) {
334
+ $pos = strrpos(substr($line,0,$max_line_length)," ");
335
+
336
+ # Patch to fix DOS attack
337
+ if(!$pos) {
338
+ $pos = $max_line_length - 1;
339
+ }
340
+
341
+ $lines_out[] = substr($line,0,$pos);
342
+ $line = substr($line,$pos + 1);
343
+ # if we are processing headers we need to
344
+ # add a LWSP-char to the front of the new line
345
+ # rfc 822 on long msg headers
346
+ if($in_headers) {
347
+ $line = "\t" . $line;
348
+ }
349
+ }
350
+ $lines_out[] = $line;
351
+
352
+ # now send the lines to the server
353
+ while(list(,$line_out) = @each($lines_out)) {
354
+ if(strlen($line_out) > 0)
355
+ {
356
+ if(substr($line_out, 0, 1) == ".") {
357
+ $line_out = "." . $line_out;
358
+ }
359
+ }
360
+ fputs($this->smtp_conn,$line_out . $this->CRLF);
361
+ }
362
+ }
363
+
364
+ # ok all the message data has been sent so lets get this
365
+ # over with aleady
366
+ fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
367
+
368
+ $rply = $this->get_lines();
369
+ $code = substr($rply,0,3);
370
+
371
+ if($this->do_debug >= 2) {
372
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
373
+ }
374
+
375
+ if($code != 250) {
376
+ $this->error =
377
+ array("error" => "DATA not accepted from server",
378
+ "smtp_code" => $code,
379
+ "smtp_msg" => substr($rply,4));
380
+ if($this->do_debug >= 1) {
381
+ echo "SMTP -> ERROR: " . $this->error["error"] .
382
+ ": " . $rply . $this->CRLF;
383
+ }
384
+ return false;
385
+ }
386
+ return true;
387
+ }
388
+
389
+ /**
390
+ * Expand takes the name and asks the server to list all the
391
+ * people who are members of the _list_. Expand will return
392
+ * back and array of the result or false if an error occurs.
393
+ * Each value in the array returned has the format of:
394
+ * [ <full-name> <sp> ] <path>
395
+ * The definition of <path> is defined in rfc 821
396
+ *
397
+ * Implements rfc 821: EXPN <SP> <string> <CRLF>
398
+ *
399
+ * SMTP CODE SUCCESS: 250
400
+ * SMTP CODE FAILURE: 550
401
+ * SMTP CODE ERROR : 500,501,502,504,421
402
+ * @access public
403
+ * @return string array
404
+ */
405
+ function Expand($name) {
406
+ $this->error = null; # so no confusion is caused
407
+
408
+ if(!$this->connected()) {
409
+ $this->error = array(
410
+ "error" => "Called Expand() without being connected");
411
+ return false;
412
+ }
413
+
414
+ fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
415
+
416
+ $rply = $this->get_lines();
417
+ $code = substr($rply,0,3);
418
+
419
+ if($this->do_debug >= 2) {
420
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
421
+ }
422
+
423
+ if($code != 250) {
424
+ $this->error =
425
+ array("error" => "EXPN not accepted from server",
426
+ "smtp_code" => $code,
427
+ "smtp_msg" => substr($rply,4));
428
+ if($this->do_debug >= 1) {
429
+ echo "SMTP -> ERROR: " . $this->error["error"] .
430
+ ": " . $rply . $this->CRLF;
431
+ }
432
+ return false;
433
+ }
434
+
435
+ # parse the reply and place in our array to return to user
436
+ $entries = explode($this->CRLF,$rply);
437
+ while(list(,$l) = @each($entries)) {
438
+ $list[] = substr($l,4);
439
+ }
440
+
441
+ return $list;
442
+ }
443
+
444
+ /**
445
+ * Sends the HELO command to the smtp server.
446
+ * This makes sure that we and the server are in
447
+ * the same known state.
448
+ *
449
+ * Implements from rfc 821: HELO <SP> <domain> <CRLF>
450
+ *
451
+ * SMTP CODE SUCCESS: 250
452
+ * SMTP CODE ERROR : 500, 501, 504, 421
453
+ * @access public
454
+ * @return bool
455
+ */
456
+ function Hello($host="") {
457
+ $this->error = null; # so no confusion is caused
458
+
459
+ if(!$this->connected()) {
460
+ $this->error = array(
461
+ "error" => "Called Hello() without being connected");
462
+ return false;
463
+ }
464
+
465
+ # if a hostname for the HELO wasn't specified determine
466
+ # a suitable one to send
467
+ if(empty($host)) {
468
+ # we need to determine some sort of appopiate default
469
+ # to send to the server
470
+ $host = "localhost";
471
+ }
472
+
473
+ // Send extended hello first (RFC 2821)
474
+ if(!$this->SendHello("EHLO", $host))
475
+ {
476
+ if(!$this->SendHello("HELO", $host))
477
+ return false;
478
+ }
479
+
480
+ return true;
481
+ }
482
+
483
+ /**
484
+ * Sends a HELO/EHLO command.
485
+ * @access private
486
+ * @return bool
487
+ */
488
+ function SendHello($hello, $host) {
489
+ fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
490
+
491
+ $rply = $this->get_lines();
492
+ $code = substr($rply,0,3);
493
+
494
+ if($this->do_debug >= 2) {
495
+ echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
496
+ }
497
+
498
+ if($code != 250) {
499
+ $this->error =
500
+ array("error" => $hello . " not accepted from server",
501
+ "smtp_code" => $code,
502
+ "smtp_msg" => substr($rply,4));
503
+ if($this->do_debug >= 1) {
504
+ echo "SMTP -> ERROR: " . $this->error["error"] .
505
+ ": " . $rply . $this->CRLF;
506
+ }
507
+ return false;
508
+ }
509
+
510
+ $this->helo_rply = $rply;
511
+
512
+ return true;
513
+ }
514
+
515
+ /**
516
+ * Gets help information on the keyword specified. If the keyword
517
+ * is not specified then returns generic help, ussually contianing
518
+ * A list of keywords that help is available on. This function
519
+ * returns the results back to the user. It is up to the user to
520
+ * handle the returned data. If an error occurs then false is
521
+ * returned with $this->error set appropiately.
522
+ *
523
+ * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
524
+ *
525
+ * SMTP CODE SUCCESS: 211,214
526
+ * SMTP CODE ERROR : 500,501,502,504,421
527
+ * @access public
528
+ * @return string
529
+ */
530
+ function Help($keyword="") {
531
+ $this->error = null; # to avoid confusion
532
+
533
+ if(!$this->connected()) {
534
+ $this->error = array(
535
+ "error" => "Called Help() without being connected");
536
+ return false;
537
+ }
538
+
539
+ $extra = "";
540
+ if(!empty($keyword)) {
541
+ $extra = " " . $keyword;
542
+ }
543
+
544
+ fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
545
+
546
+ $rply = $this->get_lines();
547
+ $code = substr($rply,0,3);
548
+
549
+ if($this->do_debug >= 2) {
550
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
551
+ }
552
+
553
+ if($code != 211 && $code != 214) {
554
+ $this->error =
555
+ array("error" => "HELP not accepted from server",
556
+ "smtp_code" => $code,
557
+ "smtp_msg" => substr($rply,4));
558
+ if($this->do_debug >= 1) {
559
+ echo "SMTP -> ERROR: " . $this->error["error"] .
560
+ ": " . $rply . $this->CRLF;
561
+ }
562
+ return false;
563
+ }
564
+
565
+ return $rply;
566
+ }
567
+
568
+ /**
569
+ * Starts a mail transaction from the email address specified in
570
+ * $from. Returns true if successful or false otherwise. If True
571
+ * the mail transaction is started and then one or more Recipient
572
+ * commands may be called followed by a Data command.
573
+ *
574
+ * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
575
+ *
576
+ * SMTP CODE SUCCESS: 250
577
+ * SMTP CODE SUCCESS: 552,451,452
578
+ * SMTP CODE SUCCESS: 500,501,421
579
+ * @access public
580
+ * @return bool
581
+ */
582
+ function Mail($from) {
583
+ $this->error = null; # so no confusion is caused
584
+
585
+ if(!$this->connected()) {
586
+ $this->error = array(
587
+ "error" => "Called Mail() without being connected");
588
+ return false;
589
+ }
590
+
591
+ fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $this->CRLF);
592
+
593
+ $rply = $this->get_lines();
594
+ $code = substr($rply,0,3);
595
+
596
+ if($this->do_debug >= 2) {
597
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
598
+ }
599
+
600
+ if($code != 250) {
601
+ $this->error =
602
+ array("error" => "MAIL not accepted from server",
603
+ "smtp_code" => $code,
604
+ "smtp_msg" => substr($rply,4));
605
+ if($this->do_debug >= 1) {
606
+ echo "SMTP -> ERROR: " . $this->error["error"] .
607
+ ": " . $rply . $this->CRLF;
608
+ }
609
+ return false;
610
+ }
611
+ return true;
612
+ }
613
+
614
+ /**
615
+ * Sends the command NOOP to the SMTP server.
616
+ *
617
+ * Implements from rfc 821: NOOP <CRLF>
618
+ *
619
+ * SMTP CODE SUCCESS: 250
620
+ * SMTP CODE ERROR : 500, 421
621
+ * @access public
622
+ * @return bool
623
+ */
624
+ function Noop() {
625
+ $this->error = null; # so no confusion is caused
626
+
627
+ if(!$this->connected()) {
628
+ $this->error = array(
629
+ "error" => "Called Noop() without being connected");
630
+ return false;
631
+ }
632
+
633
+ fputs($this->smtp_conn,"NOOP" . $this->CRLF);
634
+
635
+ $rply = $this->get_lines();
636
+ $code = substr($rply,0,3);
637
+
638
+ if($this->do_debug >= 2) {
639
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
640
+ }
641
+
642
+ if($code != 250) {
643
+ $this->error =
644
+ array("error" => "NOOP not accepted from server",
645
+ "smtp_code" => $code,
646
+ "smtp_msg" => substr($rply,4));
647
+ if($this->do_debug >= 1) {
648
+ echo "SMTP -> ERROR: " . $this->error["error"] .
649
+ ": " . $rply . $this->CRLF;
650
+ }
651
+ return false;
652
+ }
653
+ return true;
654
+ }
655
+
656
+ /**
657
+ * Sends the quit command to the server and then closes the socket
658
+ * if there is no error or the $close_on_error argument is true.
659
+ *
660
+ * Implements from rfc 821: QUIT <CRLF>
661
+ *
662
+ * SMTP CODE SUCCESS: 221
663
+ * SMTP CODE ERROR : 500
664
+ * @access public
665
+ * @return bool
666
+ */
667
+ function Quit($close_on_error=true) {
668
+ $this->error = null; # so there is no confusion
669
+
670
+ if(!$this->connected()) {
671
+ $this->error = array(
672
+ "error" => "Called Quit() without being connected");
673
+ return false;
674
+ }
675
+
676
+ # send the quit command to the server
677
+ fputs($this->smtp_conn,"quit" . $this->CRLF);
678
+
679
+ # get any good-bye messages
680
+ $byemsg = $this->get_lines();
681
+
682
+ if($this->do_debug >= 2) {
683
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
684
+ }
685
+
686
+ $rval = true;
687
+ $e = null;
688
+
689
+ $code = substr($byemsg,0,3);
690
+ if($code != 221) {
691
+ # use e as a tmp var cause Close will overwrite $this->error
692
+ $e = array("error" => "SMTP server rejected quit command",
693
+ "smtp_code" => $code,
694
+ "smtp_rply" => substr($byemsg,4));
695
+ $rval = false;
696
+ if($this->do_debug >= 1) {
697
+ echo "SMTP -> ERROR: " . $e["error"] . ": " .
698
+ $byemsg . $this->CRLF;
699
+ }
700
+ }
701
+
702
+ if(empty($e) || $close_on_error) {
703
+ $this->Close();
704
+ }
705
+
706
+ return $rval;
707
+ }
708
+
709
+ /**
710
+ * Sends the command RCPT to the SMTP server with the TO: argument of $to.
711
+ * Returns true if the recipient was accepted false if it was rejected.
712
+ *
713
+ * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
714
+ *
715
+ * SMTP CODE SUCCESS: 250,251
716
+ * SMTP CODE FAILURE: 550,551,552,553,450,451,452
717
+ * SMTP CODE ERROR : 500,501,503,421
718
+ * @access public
719
+ * @return bool
720
+ */
721
+ function Recipient($to) {
722
+ $this->error = null; # so no confusion is caused
723
+
724
+ if(!$this->connected()) {
725
+ $this->error = array(
726
+ "error" => "Called Recipient() without being connected");
727
+ return false;
728
+ }
729
+
730
+ fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
731
+
732
+ $rply = $this->get_lines();
733
+ $code = substr($rply,0,3);
734
+
735
+ if($this->do_debug >= 2) {
736
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
737
+ }
738
+
739
+ if($code != 250 && $code != 251) {
740
+ $this->error =
741
+ array("error" => "RCPT not accepted from server",
742
+ "smtp_code" => $code,
743
+ "smtp_msg" => substr($rply,4));
744
+ if($this->do_debug >= 1) {
745
+ echo "SMTP -> ERROR: " . $this->error["error"] .
746
+ ": " . $rply . $this->CRLF;
747
+ }
748
+ return false;
749
+ }
750
+ return true;
751
+ }
752
+
753
+ /**
754
+ * Sends the RSET command to abort and transaction that is
755
+ * currently in progress. Returns true if successful false
756
+ * otherwise.
757
+ *
758
+ * Implements rfc 821: RSET <CRLF>
759
+ *
760
+ * SMTP CODE SUCCESS: 250
761
+ * SMTP CODE ERROR : 500,501,504,421
762
+ * @access public
763
+ * @return bool
764
+ */
765
+ function Reset() {
766
+ $this->error = null; # so no confusion is caused
767
+
768
+ if(!$this->connected()) {
769
+ $this->error = array(
770
+ "error" => "Called Reset() without being connected");
771
+ return false;
772
+ }
773
+
774
+ fputs($this->smtp_conn,"RSET" . $this->CRLF);
775
+
776
+ $rply = $this->get_lines();
777
+ $code = substr($rply,0,3);
778
+
779
+ if($this->do_debug >= 2) {
780
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
781
+ }
782
+
783
+ if($code != 250) {
784
+ $this->error =
785
+ array("error" => "RSET failed",
786
+ "smtp_code" => $code,
787
+ "smtp_msg" => substr($rply,4));
788
+ if($this->do_debug >= 1) {
789
+ echo "SMTP -> ERROR: " . $this->error["error"] .
790
+ ": " . $rply . $this->CRLF;
791
+ }
792
+ return false;
793
+ }
794
+
795
+ return true;
796
+ }
797
+
798
+ /**
799
+ * Starts a mail transaction from the email address specified in
800
+ * $from. Returns true if successful or false otherwise. If True
801
+ * the mail transaction is started and then one or more Recipient
802
+ * commands may be called followed by a Data command. This command
803
+ * will send the message to the users terminal if they are logged
804
+ * in.
805
+ *
806
+ * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
807
+ *
808
+ * SMTP CODE SUCCESS: 250
809
+ * SMTP CODE SUCCESS: 552,451,452
810
+ * SMTP CODE SUCCESS: 500,501,502,421
811
+ * @access public
812
+ * @return bool
813
+ */
814
+ function Send($from) {
815
+ $this->error = null; # so no confusion is caused
816
+
817
+ if(!$this->connected()) {
818
+ $this->error = array(
819
+ "error" => "Called Send() without being connected");
820
+ return false;
821
+ }
822
+
823
+ fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
824
+
825
+ $rply = $this->get_lines();
826
+ $code = substr($rply,0,3);
827
+
828
+ if($this->do_debug >= 2) {
829
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
830
+ }
831
+
832
+ if($code != 250) {
833
+ $this->error =
834
+ array("error" => "SEND not accepted from server",
835
+ "smtp_code" => $code,
836
+ "smtp_msg" => substr($rply,4));
837
+ if($this->do_debug >= 1) {
838
+ echo "SMTP -> ERROR: " . $this->error["error"] .
839
+ ": " . $rply . $this->CRLF;
840
+ }
841
+ return false;
842
+ }
843
+ return true;
844
+ }
845
+
846
+ /**
847
+ * Starts a mail transaction from the email address specified in
848
+ * $from. Returns true if successful or false otherwise. If True
849
+ * the mail transaction is started and then one or more Recipient
850
+ * commands may be called followed by a Data command. This command
851
+ * will send the message to the users terminal if they are logged
852
+ * in and send them an email.
853
+ *
854
+ * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
855
+ *
856
+ * SMTP CODE SUCCESS: 250
857
+ * SMTP CODE SUCCESS: 552,451,452
858
+ * SMTP CODE SUCCESS: 500,501,502,421
859
+ * @access public
860
+ * @return bool
861
+ */
862
+ function SendAndMail($from) {
863
+ $this->error = null; # so no confusion is caused
864
+
865
+ if(!$this->connected()) {
866
+ $this->error = array(
867
+ "error" => "Called SendAndMail() without being connected");
868
+ return false;
869
+ }
870
+
871
+ fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
872
+
873
+ $rply = $this->get_lines();
874
+ $code = substr($rply,0,3);
875
+
876
+ if($this->do_debug >= 2) {
877
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
878
+ }
879
+
880
+ if($code != 250) {
881
+ $this->error =
882
+ array("error" => "SAML not accepted from server",
883
+ "smtp_code" => $code,
884
+ "smtp_msg" => substr($rply,4));
885
+ if($this->do_debug >= 1) {
886
+ echo "SMTP -> ERROR: " . $this->error["error"] .
887
+ ": " . $rply . $this->CRLF;
888
+ }
889
+ return false;
890
+ }
891
+ return true;
892
+ }
893
+
894
+ /**
895
+ * Starts a mail transaction from the email address specified in
896
+ * $from. Returns true if successful or false otherwise. If True
897
+ * the mail transaction is started and then one or more Recipient
898
+ * commands may be called followed by a Data command. This command
899
+ * will send the message to the users terminal if they are logged
900
+ * in or mail it to them if they are not.
901
+ *
902
+ * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
903
+ *
904
+ * SMTP CODE SUCCESS: 250
905
+ * SMTP CODE SUCCESS: 552,451,452
906
+ * SMTP CODE SUCCESS: 500,501,502,421
907
+ * @access public
908
+ * @return bool
909
+ */
910
+ function SendOrMail($from) {
911
+ $this->error = null; # so no confusion is caused
912
+
913
+ if(!$this->connected()) {
914
+ $this->error = array(
915
+ "error" => "Called SendOrMail() without being connected");
916
+ return false;
917
+ }
918
+
919
+ fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
920
+
921
+ $rply = $this->get_lines();
922
+ $code = substr($rply,0,3);
923
+
924
+ if($this->do_debug >= 2) {
925
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
926
+ }
927
+
928
+ if($code != 250) {
929
+ $this->error =
930
+ array("error" => "SOML not accepted from server",
931
+ "smtp_code" => $code,
932
+ "smtp_msg" => substr($rply,4));
933
+ if($this->do_debug >= 1) {
934
+ echo "SMTP -> ERROR: " . $this->error["error"] .
935
+ ": " . $rply . $this->CRLF;
936
+ }
937
+ return false;
938
+ }
939
+ return true;
940
+ }
941
+
942
+ /**
943
+ * This is an optional command for SMTP that this class does not
944
+ * support. This method is here to make the RFC821 Definition
945
+ * complete for this class and __may__ be implimented in the future
946
+ *
947
+ * Implements from rfc 821: TURN <CRLF>
948
+ *
949
+ * SMTP CODE SUCCESS: 250
950
+ * SMTP CODE FAILURE: 502
951
+ * SMTP CODE ERROR : 500, 503
952
+ * @access public
953
+ * @return bool
954
+ */
955
+ function Turn() {
956
+ $this->error = array("error" => "This method, TURN, of the SMTP ".
957
+ "is not implemented");
958
+ if($this->do_debug >= 1) {
959
+ echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
960
+ }
961
+ return false;
962
+ }
963
+
964
+ /**
965
+ * Verifies that the name is recognized by the server.
966
+ * Returns false if the name could not be verified otherwise
967
+ * the response from the server is returned.
968
+ *
969
+ * Implements rfc 821: VRFY <SP> <string> <CRLF>
970
+ *
971
+ * SMTP CODE SUCCESS: 250,251
972
+ * SMTP CODE FAILURE: 550,551,553
973
+ * SMTP CODE ERROR : 500,501,502,421
974
+ * @access public
975
+ * @return int
976
+ */
977
+ function Verify($name) {
978
+ $this->error = null; # so no confusion is caused
979
+
980
+ if(!$this->connected()) {
981
+ $this->error = array(
982
+ "error" => "Called Verify() without being connected");
983
+ return false;
984
+ }
985
+
986
+ fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
987
+
988
+ $rply = $this->get_lines();
989
+ $code = substr($rply,0,3);
990
+
991
+ if($this->do_debug >= 2) {
992
+ echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
993
+ }
994
+
995
+ if($code != 250 && $code != 251) {
996
+ $this->error =
997
+ array("error" => "VRFY failed on name '$name'",
998
+ "smtp_code" => $code,
999
+ "smtp_msg" => substr($rply,4));
1000
+ if($this->do_debug >= 1) {
1001
+ echo "SMTP -> ERROR: " . $this->error["error"] .
1002
+ ": " . $rply . $this->CRLF;
1003
+ }
1004
+ return false;
1005
+ }
1006
+ return $rply;
1007
+ }
1008
+
1009
+ /*******************************************************************
1010
+ * INTERNAL FUNCTIONS *
1011
+ ******************************************************************/
1012
+
1013
+ /**
1014
+ * Read in as many lines as possible
1015
+ * either before eof or socket timeout occurs on the operation.
1016
+ * With SMTP we can tell if we have more lines to read if the
1017
+ * 4th character is '-' symbol. If it is a space then we don't
1018
+ * need to read anything else.
1019
+ * @access private
1020
+ * @return string
1021
+ */
1022
+ function get_lines() {
1023
+ $data = "";
1024
+ while($str = fgets($this->smtp_conn,515)) {
1025
+ if($this->do_debug >= 4) {
1026
+ echo "SMTP -> get_lines(): \$data was \"$data\"" .
1027
+ $this->CRLF;
1028
+ echo "SMTP -> get_lines(): \$str is \"$str\"" .
1029
+ $this->CRLF;
1030
+ }
1031
+ $data .= $str;
1032
+ if($this->do_debug >= 4) {
1033
+ echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
1034
+ }
1035
+ # if the 4th character is a space then we are done reading
1036
+ # so just break the loop
1037
+ if(substr($str,3,1) == " ") { break; }
1038
+ }
1039
+ return $data;
1040
+ }
1041
+
1042
+ }
1043
+
1044
+
1045
+ ?>
classes/phpmailer/language/phpmailer.lang-br.php CHANGED
@@ -1,21 +1,21 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Portuguese Version
5
- * By Paulo Henrique Garcia - paulo@controllerweb.com.br
6
- */
7
-
8
- $PHPMAILER_LANG = array();
9
- $PHPMAILER_LANG["provide_address"] = 'Voc� deve fornecer pelo menos um endere�o de destinat�rio de email.';
10
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer n�o suportado.';
11
- $PHPMAILER_LANG["execute"] = 'N�o foi poss�vel executar: ';
12
- $PHPMAILER_LANG["instantiate"] = 'N�o foi poss�vel instanciar a fun��o mail.';
13
- $PHPMAILER_LANG["authenticate"] = 'Erro de SMTP: N�o foi poss�vel autenticar.';
14
- $PHPMAILER_LANG["from_failed"] = 'Os endere�os de rementente a seguir falharam: ';
15
- $PHPMAILER_LANG["recipients_failed"] = 'Erro de SMTP: Os endere�os de destinat�rio a seguir falharam: ';
16
- $PHPMAILER_LANG["data_not_accepted"] = 'Erro de SMTP: Dados n�o aceitos.';
17
- $PHPMAILER_LANG["connect_host"] = 'Erro de SMTP: N�o foi poss�vel conectar com o servidor SMTP.';
18
- $PHPMAILER_LANG["file_access"] = 'N�o foi poss�vel acessar o arquivo: ';
19
- $PHPMAILER_LANG["file_open"] = 'Erro de Arquivo: N�o foi poss�vel abrir o arquivo: ';
20
- $PHPMAILER_LANG["encoding"] = 'Codifica��o desconhecida: ';
21
- ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Portuguese Version
5
+ * By Paulo Henrique Garcia - paulo@controllerweb.com.br
6
+ */
7
+
8
+ $PHPMAILER_LANG = array();
9
+ $PHPMAILER_LANG["provide_address"] = 'Voc� deve fornecer pelo menos um endere�o de destinat�rio de email.';
10
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer n�o suportado.';
11
+ $PHPMAILER_LANG["execute"] = 'N�o foi poss�vel executar: ';
12
+ $PHPMAILER_LANG["instantiate"] = 'N�o foi poss�vel instanciar a fun��o mail.';
13
+ $PHPMAILER_LANG["authenticate"] = 'Erro de SMTP: N�o foi poss�vel autenticar.';
14
+ $PHPMAILER_LANG["from_failed"] = 'Os endere�os de rementente a seguir falharam: ';
15
+ $PHPMAILER_LANG["recipients_failed"] = 'Erro de SMTP: Os endere�os de destinat�rio a seguir falharam: ';
16
+ $PHPMAILER_LANG["data_not_accepted"] = 'Erro de SMTP: Dados n�o aceitos.';
17
+ $PHPMAILER_LANG["connect_host"] = 'Erro de SMTP: N�o foi poss�vel conectar com o servidor SMTP.';
18
+ $PHPMAILER_LANG["file_access"] = 'N�o foi poss�vel acessar o arquivo: ';
19
+ $PHPMAILER_LANG["file_open"] = 'Erro de Arquivo: N�o foi poss�vel abrir o arquivo: ';
20
+ $PHPMAILER_LANG["encoding"] = 'Codifica��o desconhecida: ';
21
+ ?>
classes/phpmailer/language/phpmailer.lang-ca.php CHANGED
@@ -1,22 +1,22 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Catalan Version
5
- * By Ivan: web AT microstudi DOT com
6
- */
7
-
8
- $PHPMAILER_LANG = array();
9
-
10
- $PHPMAILER_LANG["provide_address"] = 'S\'ha de proveir almenys una adre�a d\'email com a destinatari.';
11
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer no est� suportat';
12
- $PHPMAILER_LANG["execute"] = 'No es pot executar: ';
13
- $PHPMAILER_LANG["instantiate"] = 'No s\'ha pogut crear una inst�ncia de la funci� Mail.';
14
- $PHPMAILER_LANG["authenticate"] = 'Error SMTP: No s\'hapogut autenticar.';
15
- $PHPMAILER_LANG["from_failed"] = 'La(s) seg�ent(s) adreces de remitent han fallat: ';
16
- $PHPMAILER_LANG["recipients_failed"] = 'Error SMTP: Els seg�ents destinataris han fallat: ';
17
- $PHPMAILER_LANG["data_not_accepted"] = 'Error SMTP: Dades no acceptades.';
18
- $PHPMAILER_LANG["connect_host"] = 'Error SMTP: No es pot connectar al servidor SMTP.';
19
- $PHPMAILER_LANG["file_access"] = 'No es pot accedir a l\'arxiu: ';
20
- $PHPMAILER_LANG["file_open"] = 'Error d\'Arxiu: No es pot obrir l\'arxiu: ';
21
- $PHPMAILER_LANG["encoding"] = 'Codificaci� desconeguda: ';
22
  ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Catalan Version
5
+ * By Ivan: web AT microstudi DOT com
6
+ */
7
+
8
+ $PHPMAILER_LANG = array();
9
+
10
+ $PHPMAILER_LANG["provide_address"] = 'S\'ha de proveir almenys una adre�a d\'email com a destinatari.';
11
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer no est� suportat';
12
+ $PHPMAILER_LANG["execute"] = 'No es pot executar: ';
13
+ $PHPMAILER_LANG["instantiate"] = 'No s\'ha pogut crear una inst�ncia de la funci� Mail.';
14
+ $PHPMAILER_LANG["authenticate"] = 'Error SMTP: No s\'hapogut autenticar.';
15
+ $PHPMAILER_LANG["from_failed"] = 'La(s) seg�ent(s) adreces de remitent han fallat: ';
16
+ $PHPMAILER_LANG["recipients_failed"] = 'Error SMTP: Els seg�ents destinataris han fallat: ';
17
+ $PHPMAILER_LANG["data_not_accepted"] = 'Error SMTP: Dades no acceptades.';
18
+ $PHPMAILER_LANG["connect_host"] = 'Error SMTP: No es pot connectar al servidor SMTP.';
19
+ $PHPMAILER_LANG["file_access"] = 'No es pot accedir a l\'arxiu: ';
20
+ $PHPMAILER_LANG["file_open"] = 'Error d\'Arxiu: No es pot obrir l\'arxiu: ';
21
+ $PHPMAILER_LANG["encoding"] = 'Codificaci� desconeguda: ';
22
  ?>
classes/phpmailer/language/phpmailer.lang-cz.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Czech Version
5
- */
6
-
7
- $PHPMAILER_LANG = array();
8
-
9
- $PHPMAILER_LANG["provide_address"] = 'Mus�te zadat alespo� jednu ' .
10
- 'emailovou adresu p��jemce.';
11
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailov� klient nen� podporov�n.';
12
- $PHPMAILER_LANG["execute"] = 'Nelze prov�st: ';
13
- $PHPMAILER_LANG["instantiate"] = 'Nelze vytvo�it instanci emailov� funkce.';
14
- $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Chyba autentikace.';
15
- $PHPMAILER_LANG["from_failed"] = 'N�sleduj�c� adresa From je nespr�vn�: ';
16
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: Adresy p��jemc� ' .
17
- 'nejsou spr�vn� ' .
18
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data nebyla p�ijata';
19
- $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Nelze nav�zat spojen� se ' .
20
- ' SMTP serverem.';
21
- $PHPMAILER_LANG["file_access"] = 'Soubor nenalezen: ';
22
- $PHPMAILER_LANG["file_open"] = 'File Error: Nelze otev��t soubor pro �ten�: ';
23
- $PHPMAILER_LANG["encoding"] = 'Nezn�m� k�dov�n�: ';
24
  ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Czech Version
5
+ */
6
+
7
+ $PHPMAILER_LANG = array();
8
+
9
+ $PHPMAILER_LANG["provide_address"] = 'Mus�te zadat alespo� jednu ' .
10
+ 'emailovou adresu p��jemce.';
11
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailov� klient nen� podporov�n.';
12
+ $PHPMAILER_LANG["execute"] = 'Nelze prov�st: ';
13
+ $PHPMAILER_LANG["instantiate"] = 'Nelze vytvo�it instanci emailov� funkce.';
14
+ $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Chyba autentikace.';
15
+ $PHPMAILER_LANG["from_failed"] = 'N�sleduj�c� adresa From je nespr�vn�: ';
16
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: Adresy p��jemc� ' .
17
+ 'nejsou spr�vn� ' .
18
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data nebyla p�ijata';
19
+ $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Nelze nav�zat spojen� se ' .
20
+ ' SMTP serverem.';
21
+ $PHPMAILER_LANG["file_access"] = 'Soubor nenalezen: ';
22
+ $PHPMAILER_LANG["file_open"] = 'File Error: Nelze otev��t soubor pro �ten�: ';
23
+ $PHPMAILER_LANG["encoding"] = 'Nezn�m� k�dov�n�: ';
24
  ?>
classes/phpmailer/language/phpmailer.lang-de.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * German Version
5
- */
6
-
7
- $PHPMAILER_LANG = array();
8
-
9
- $PHPMAILER_LANG["provide_address"] = 'Bitte geben Sie mindestens eine ' .
10
- 'Empf&auml;nger Emailadresse an.';
11
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer wird nicht unterst&uuml;tzt.';
12
- $PHPMAILER_LANG["execute"] = 'Konnte folgenden Befehl nicht ausf&uuml;hren: ';
13
- $PHPMAILER_LANG["instantiate"] = 'Mail Funktion konnte nicht initialisiert werden.';
14
- $PHPMAILER_LANG["authenticate"] = 'SMTP Fehler: Authentifizierung fehlgeschlagen.';
15
- $PHPMAILER_LANG["from_failed"] = 'Die folgende Absenderadresse ist nicht korrekt: ';
16
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Fehler: Die folgenden ' .
17
- 'Empf&auml;nger sind nicht korrekt: ';
18
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Fehler: Daten werden nicht akzeptiert.';
19
- $PHPMAILER_LANG["connect_host"] = 'SMTP Fehler: Konnte keine Verbindung zum SMTP-Host herstellen.';
20
- $PHPMAILER_LANG["file_access"] = 'Zugriff auf folgende Datei fehlgeschlagen: ';
21
- $PHPMAILER_LANG["file_open"] = 'Datei Fehler: konnte folgende Datei nicht &ouml;ffnen: ';
22
- $PHPMAILER_LANG["encoding"] = 'Unbekanntes Encoding-Format: ';
23
- ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * German Version
5
+ */
6
+
7
+ $PHPMAILER_LANG = array();
8
+
9
+ $PHPMAILER_LANG["provide_address"] = 'Bitte geben Sie mindestens eine ' .
10
+ 'Empf&auml;nger Emailadresse an.';
11
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer wird nicht unterst&uuml;tzt.';
12
+ $PHPMAILER_LANG["execute"] = 'Konnte folgenden Befehl nicht ausf&uuml;hren: ';
13
+ $PHPMAILER_LANG["instantiate"] = 'Mail Funktion konnte nicht initialisiert werden.';
14
+ $PHPMAILER_LANG["authenticate"] = 'SMTP Fehler: Authentifizierung fehlgeschlagen.';
15
+ $PHPMAILER_LANG["from_failed"] = 'Die folgende Absenderadresse ist nicht korrekt: ';
16
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP Fehler: Die folgenden ' .
17
+ 'Empf&auml;nger sind nicht korrekt: ';
18
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Fehler: Daten werden nicht akzeptiert.';
19
+ $PHPMAILER_LANG["connect_host"] = 'SMTP Fehler: Konnte keine Verbindung zum SMTP-Host herstellen.';
20
+ $PHPMAILER_LANG["file_access"] = 'Zugriff auf folgende Datei fehlgeschlagen: ';
21
+ $PHPMAILER_LANG["file_open"] = 'Datei Fehler: konnte folgende Datei nicht &ouml;ffnen: ';
22
+ $PHPMAILER_LANG["encoding"] = 'Unbekanntes Encoding-Format: ';
23
+ ?>
classes/phpmailer/language/phpmailer.lang-dk.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Danish Version
5
- * Author: Mikael Stokkebro <info@stokkebro.dk>
6
- */
7
-
8
- $PHPMAILER_LANG = array();
9
-
10
- $PHPMAILER_LANG["provide_address"] = 'Du skal indtaste mindst en ' .
11
- 'modtagers emailadresse.';
12
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer underst�ttes ikke.';
13
- $PHPMAILER_LANG["execute"] = 'Kunne ikke k�re: ';
14
- $PHPMAILER_LANG["instantiate"] = 'Kunne ikke initialisere email funktionen.';
15
- $PHPMAILER_LANG["authenticate"] = 'SMTP fejl: Kunne ikke logge p�.';
16
- $PHPMAILER_LANG["from_failed"] = 'F�lgende afsenderadresse er forkert: ';
17
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP fejl: F�lgende' .
18
- 'modtagere er forkerte: ';
19
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP fejl: Data kunne ikke accepteres.';
20
- $PHPMAILER_LANG["connect_host"] = 'SMTP fejl: Kunne ikke tilslutte SMTP serveren.';
21
- $PHPMAILER_LANG["file_access"] = 'Ingen adgang til fil: ';
22
- $PHPMAILER_LANG["file_open"] = 'Fil fejl: Kunne ikke �bne filen: ';
23
- $PHPMAILER_LANG["encoding"] = 'Ukendt encode-format: ';
24
  ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Danish Version
5
+ * Author: Mikael Stokkebro <info@stokkebro.dk>
6
+ */
7
+
8
+ $PHPMAILER_LANG = array();
9
+
10
+ $PHPMAILER_LANG["provide_address"] = 'Du skal indtaste mindst en ' .
11
+ 'modtagers emailadresse.';
12
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer underst�ttes ikke.';
13
+ $PHPMAILER_LANG["execute"] = 'Kunne ikke k�re: ';
14
+ $PHPMAILER_LANG["instantiate"] = 'Kunne ikke initialisere email funktionen.';
15
+ $PHPMAILER_LANG["authenticate"] = 'SMTP fejl: Kunne ikke logge p�.';
16
+ $PHPMAILER_LANG["from_failed"] = 'F�lgende afsenderadresse er forkert: ';
17
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP fejl: F�lgende' .
18
+ 'modtagere er forkerte: ';
19
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP fejl: Data kunne ikke accepteres.';
20
+ $PHPMAILER_LANG["connect_host"] = 'SMTP fejl: Kunne ikke tilslutte SMTP serveren.';
21
+ $PHPMAILER_LANG["file_access"] = 'Ingen adgang til fil: ';
22
+ $PHPMAILER_LANG["file_open"] = 'Fil fejl: Kunne ikke �bne filen: ';
23
+ $PHPMAILER_LANG["encoding"] = 'Ukendt encode-format: ';
24
  ?>
classes/phpmailer/language/phpmailer.lang-en.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * English Version
5
- */
6
-
7
- $PHPMAILER_LANG = array();
8
-
9
- $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
10
- 'recipient email address.';
11
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
12
- $PHPMAILER_LANG["execute"] = 'Could not execute: ';
13
- $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
14
- $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
15
- $PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
16
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' .
17
- 'recipients failed: ';
18
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
19
- $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
20
- $PHPMAILER_LANG["file_access"] = 'Could not access file: ';
21
- $PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: ';
22
- $PHPMAILER_LANG["encoding"] = 'Unknown encoding: ';
23
- ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * English Version
5
+ */
6
+
7
+ $PHPMAILER_LANG = array();
8
+
9
+ $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
10
+ 'recipient email address.';
11
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
12
+ $PHPMAILER_LANG["execute"] = 'Could not execute: ';
13
+ $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
14
+ $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
15
+ $PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
16
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' .
17
+ 'recipients failed: ';
18
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
19
+ $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
20
+ $PHPMAILER_LANG["file_access"] = 'Could not access file: ';
21
+ $PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: ';
22
+ $PHPMAILER_LANG["encoding"] = 'Unknown encoding: ';
23
+ ?>
classes/phpmailer/language/phpmailer.lang-es.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Versi�n en espa�ol
5
- */
6
-
7
- $PHPMAILER_LANG = array();
8
-
9
- $PHPMAILER_LANG["provide_address"] = 'Debe proveer al menos una ' .
10
- 'direcci�n de email como destinatario.';
11
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer no est� soportado.';
12
- $PHPMAILER_LANG["execute"] = 'No puedo ejecutar: ';
13
- $PHPMAILER_LANG["instantiate"] = 'No pude crear una instancia de la funci�n Mail.';
14
- $PHPMAILER_LANG["authenticate"] = 'Error SMTP: No se pudo autentificar.';
15
- $PHPMAILER_LANG["from_failed"] = 'La(s) siguiente(s) direcciones de remitente fallaron: ';
16
- $PHPMAILER_LANG["recipients_failed"] = 'Error SMTP: Los siguientes ' .
17
- 'destinatarios fallaron: ';
18
- $PHPMAILER_LANG["data_not_accepted"] = 'Error SMTP: Datos no aceptados.';
19
- $PHPMAILER_LANG["connect_host"] = 'Error SMTP: No puedo conectar al servidor SMTP.';
20
- $PHPMAILER_LANG["file_access"] = 'No puedo acceder al archivo: ';
21
- $PHPMAILER_LANG["file_open"] = 'Error de Archivo: No puede abrir el archivo: ';
22
- $PHPMAILER_LANG["encoding"] = 'Codificaci�n desconocida: ';
23
  ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Versi�n en espa�ol
5
+ */
6
+
7
+ $PHPMAILER_LANG = array();
8
+
9
+ $PHPMAILER_LANG["provide_address"] = 'Debe proveer al menos una ' .
10
+ 'direcci�n de email como destinatario.';
11
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer no est� soportado.';
12
+ $PHPMAILER_LANG["execute"] = 'No puedo ejecutar: ';
13
+ $PHPMAILER_LANG["instantiate"] = 'No pude crear una instancia de la funci�n Mail.';
14
+ $PHPMAILER_LANG["authenticate"] = 'Error SMTP: No se pudo autentificar.';
15
+ $PHPMAILER_LANG["from_failed"] = 'La(s) siguiente(s) direcciones de remitente fallaron: ';
16
+ $PHPMAILER_LANG["recipients_failed"] = 'Error SMTP: Los siguientes ' .
17
+ 'destinatarios fallaron: ';
18
+ $PHPMAILER_LANG["data_not_accepted"] = 'Error SMTP: Datos no aceptados.';
19
+ $PHPMAILER_LANG["connect_host"] = 'Error SMTP: No puedo conectar al servidor SMTP.';
20
+ $PHPMAILER_LANG["file_access"] = 'No puedo acceder al archivo: ';
21
+ $PHPMAILER_LANG["file_open"] = 'Error de Archivo: No puede abrir el archivo: ';
22
+ $PHPMAILER_LANG["encoding"] = 'Codificaci�n desconocida: ';
23
  ?>
classes/phpmailer/language/phpmailer.lang-fi.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Finnish Version
5
- * By Jyry Kuukanen
6
- */
7
-
8
- $PHPMAILER_LANG = array();
9
-
10
- $PHPMAILER_LANG["provide_address"] = 'Aseta v&auml;hint&auml;&auml;n yksi vastaanottajan ' .
11
- 's&auml;hk&ouml;postiosoite.';
12
- $PHPMAILER_LANG["mailer_not_supported"] = 'postiv&auml;litintyyppi&auml; ei tueta.';
13
- $PHPMAILER_LANG["execute"] = 'Suoritus ep&auml;onnistui: ';
14
- $PHPMAILER_LANG["instantiate"] = 'mail-funktion luonti ep&auml;onnistui.';
15
- $PHPMAILER_LANG["authenticate"] = 'SMTP-virhe: k&auml;ytt&auml;j&auml;tunnistus ep&auml;onnistui.';
16
- $PHPMAILER_LANG["from_failed"] = 'Seuraava l&auml;hett&auml;j&auml;n osoite on virheellinen: ';
17
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP-virhe: seuraava vastaanottaja osoite on virheellinen.';
18
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP-virhe: data on virheellinen.';
19
- $PHPMAILER_LANG["connect_host"] = 'SMTP-virhe: yhteys palvelimeen ei onnistu.';
20
- $PHPMAILER_LANG["file_access"] = 'Seuraavaan tiedostoon ei ole oikeuksia: ';
21
- $PHPMAILER_LANG["file_open"] = 'Tiedostovirhe: Ei voida avata tiedostoa: ';
22
- $PHPMAILER_LANG["encoding"] = 'Tuntematon koodaustyyppi: ';
23
  ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Finnish Version
5
+ * By Jyry Kuukanen
6
+ */
7
+
8
+ $PHPMAILER_LANG = array();
9
+
10
+ $PHPMAILER_LANG["provide_address"] = 'Aseta v&auml;hint&auml;&auml;n yksi vastaanottajan ' .
11
+ 's&auml;hk&ouml;postiosoite.';
12
+ $PHPMAILER_LANG["mailer_not_supported"] = 'postiv&auml;litintyyppi&auml; ei tueta.';
13
+ $PHPMAILER_LANG["execute"] = 'Suoritus ep&auml;onnistui: ';
14
+ $PHPMAILER_LANG["instantiate"] = 'mail-funktion luonti ep&auml;onnistui.';
15
+ $PHPMAILER_LANG["authenticate"] = 'SMTP-virhe: k&auml;ytt&auml;j&auml;tunnistus ep&auml;onnistui.';
16
+ $PHPMAILER_LANG["from_failed"] = 'Seuraava l&auml;hett&auml;j&auml;n osoite on virheellinen: ';
17
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP-virhe: seuraava vastaanottaja osoite on virheellinen.';
18
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP-virhe: data on virheellinen.';
19
+ $PHPMAILER_LANG["connect_host"] = 'SMTP-virhe: yhteys palvelimeen ei onnistu.';
20
+ $PHPMAILER_LANG["file_access"] = 'Seuraavaan tiedostoon ei ole oikeuksia: ';
21
+ $PHPMAILER_LANG["file_open"] = 'Tiedostovirhe: Ei voida avata tiedostoa: ';
22
+ $PHPMAILER_LANG["encoding"] = 'Tuntematon koodaustyyppi: ';
23
  ?>
classes/phpmailer/language/phpmailer.lang-fo.php CHANGED
@@ -1,25 +1,25 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Faroese Version [language of the Faroe Islands, a Danish dominion]
5
- * This file created: 11-06-2004
6
- * Supplied by D�vur S�rensen [www.profo-webdesign.dk]
7
- */
8
-
9
- $PHPMAILER_LANG = array();
10
-
11
- $PHPMAILER_LANG["provide_address"] = 'T� skal uppgeva minst ' .
12
- 'm�ttakara-emailadressu(r).';
13
- $PHPMAILER_LANG["mailer_not_supported"] = ' er ikki supportera�.';
14
- $PHPMAILER_LANG["execute"] = 'Kundi ikki �tf�ra: ';
15
- $PHPMAILER_LANG["instantiate"] = 'Kuni ikki instantiera mail funkti�n.';
16
- $PHPMAILER_LANG["authenticate"] = 'SMTP feilur: Kundi ikki g��kenna.';
17
- $PHPMAILER_LANG["from_failed"] = 'fylgjandi Fr�/From adressa miseydna�ist: ';
18
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Feilur: Fylgjandi ' .
19
- 'm�ttakarar miseydna�ust: ';
20
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP feilur: Data ikki g��kent.';
21
- $PHPMAILER_LANG["connect_host"] = 'SMTP feilur: Kundi ikki kn�ta samband vi� SMTP vert.';
22
- $PHPMAILER_LANG["file_access"] = 'Kundi ikki tilganga f�lu: ';
23
- $PHPMAILER_LANG["file_open"] = 'F�lu feilur: Kundi ikki opna f�lu: ';
24
- $PHPMAILER_LANG["encoding"] = '�kend encoding: ';
25
- ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Faroese Version [language of the Faroe Islands, a Danish dominion]
5
+ * This file created: 11-06-2004
6
+ * Supplied by D�vur S�rensen [www.profo-webdesign.dk]
7
+ */
8
+
9
+ $PHPMAILER_LANG = array();
10
+
11
+ $PHPMAILER_LANG["provide_address"] = 'T� skal uppgeva minst ' .
12
+ 'm�ttakara-emailadressu(r).';
13
+ $PHPMAILER_LANG["mailer_not_supported"] = ' er ikki supportera�.';
14
+ $PHPMAILER_LANG["execute"] = 'Kundi ikki �tf�ra: ';
15
+ $PHPMAILER_LANG["instantiate"] = 'Kuni ikki instantiera mail funkti�n.';
16
+ $PHPMAILER_LANG["authenticate"] = 'SMTP feilur: Kundi ikki g��kenna.';
17
+ $PHPMAILER_LANG["from_failed"] = 'fylgjandi Fr�/From adressa miseydna�ist: ';
18
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP Feilur: Fylgjandi ' .
19
+ 'm�ttakarar miseydna�ust: ';
20
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP feilur: Data ikki g��kent.';
21
+ $PHPMAILER_LANG["connect_host"] = 'SMTP feilur: Kundi ikki kn�ta samband vi� SMTP vert.';
22
+ $PHPMAILER_LANG["file_access"] = 'Kundi ikki tilganga f�lu: ';
23
+ $PHPMAILER_LANG["file_open"] = 'F�lu feilur: Kundi ikki opna f�lu: ';
24
+ $PHPMAILER_LANG["encoding"] = '�kend encoding: ';
25
+ ?>
classes/phpmailer/language/phpmailer.lang-fr.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * French Version
5
- * bruno@ioda-net.ch 09.08.2003
6
- */
7
-
8
- $PHPMAILER_LANG = array();
9
-
10
- $PHPMAILER_LANG["provide_address"] = 'Vous devez fournir au moins ' .
11
- 'une adresse de destinataire.';
12
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer non support�.';
13
- $PHPMAILER_LANG["execute"] = 'Ne peut pas lancer l\'ex�cution: ';
14
- $PHPMAILER_LANG["instantiate"] = 'Impossible d\'instancier la fonction mail.';
15
- $PHPMAILER_LANG["authenticate"] = 'SMTP Erreur: Echec de l\'authentification.';
16
- $PHPMAILER_LANG["from_failed"] = 'L\'adresse From suivante a �chou� : ';
17
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Erreur: Les destinataires ' .
18
- 'suivants sont en erreur : ';
19
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Erreur: Data non accept�e.';
20
- $PHPMAILER_LANG["connect_host"] = 'SMTP Erreur: Impossible de connecter le serveur SMTP .';
21
- $PHPMAILER_LANG["file_access"] = 'N\'arrive pas � acc�der au fichier: ';
22
- $PHPMAILER_LANG["file_open"] = 'Erreur Fichier: ouverture impossible: ';
23
- $PHPMAILER_LANG["encoding"] = 'Encodage inconnu: ';
24
- ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * French Version
5
+ * bruno@ioda-net.ch 09.08.2003
6
+ */
7
+
8
+ $PHPMAILER_LANG = array();
9
+
10
+ $PHPMAILER_LANG["provide_address"] = 'Vous devez fournir au moins ' .
11
+ 'une adresse de destinataire.';
12
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer non support�.';
13
+ $PHPMAILER_LANG["execute"] = 'Ne peut pas lancer l\'ex�cution: ';
14
+ $PHPMAILER_LANG["instantiate"] = 'Impossible d\'instancier la fonction mail.';
15
+ $PHPMAILER_LANG["authenticate"] = 'SMTP Erreur: Echec de l\'authentification.';
16
+ $PHPMAILER_LANG["from_failed"] = 'L\'adresse From suivante a �chou� : ';
17
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP Erreur: Les destinataires ' .
18
+ 'suivants sont en erreur : ';
19
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Erreur: Data non accept�e.';
20
+ $PHPMAILER_LANG["connect_host"] = 'SMTP Erreur: Impossible de connecter le serveur SMTP .';
21
+ $PHPMAILER_LANG["file_access"] = 'N\'arrive pas � acc�der au fichier: ';
22
+ $PHPMAILER_LANG["file_open"] = 'Erreur Fichier: ouverture impossible: ';
23
+ $PHPMAILER_LANG["encoding"] = 'Encodage inconnu: ';
24
+ ?>
classes/phpmailer/language/phpmailer.lang-hu.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Hungarian Version
5
- */
6
-
7
- $PHPMAILER_LANG = array();
8
-
9
- $PHPMAILER_LANG["provide_address"] = 'Meg kell adnod legal�bb egy ' .
10
- 'c�mzett email c�met.';
11
- $PHPMAILER_LANG["mailer_not_supported"] = ' levelez� nem t�mogatott.';
12
- $PHPMAILER_LANG["execute"] = 'Nem tudtam v�grehajtani: ';
13
- $PHPMAILER_LANG["instantiate"] = 'Nem siker�lt p�ld�nyos�tani a mail funkci�t.';
14
- $PHPMAILER_LANG["authenticate"] = 'SMTP Hiba: Sikertelen autentik�ci�.';
15
- $PHPMAILER_LANG["from_failed"] = 'Az al�bbi Felad� c�m hib�s: ';
16
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Hiba: Az al�bbi ' .
17
- 'c�mzettek hib�sak: ';
18
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Hiba: Nem elfogadhat� adat.';
19
- $PHPMAILER_LANG["connect_host"] = 'SMTP Hiba: Nem tudtam csatlakozni az SMTP host-hoz.';
20
- $PHPMAILER_LANG["file_access"] = 'Nem siker�lt el�rni a k�vetkez� f�jlt: ';
21
- $PHPMAILER_LANG["file_open"] = 'F�jl Hiba: Nem siker�lt megnyitni a k�vetkez� f�jlt: ';
22
- $PHPMAILER_LANG["encoding"] = 'Ismeretlen k�dol�s: ';
23
  ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Hungarian Version
5
+ */
6
+
7
+ $PHPMAILER_LANG = array();
8
+
9
+ $PHPMAILER_LANG["provide_address"] = 'Meg kell adnod legal�bb egy ' .
10
+ 'c�mzett email c�met.';
11
+ $PHPMAILER_LANG["mailer_not_supported"] = ' levelez� nem t�mogatott.';
12
+ $PHPMAILER_LANG["execute"] = 'Nem tudtam v�grehajtani: ';
13
+ $PHPMAILER_LANG["instantiate"] = 'Nem siker�lt p�ld�nyos�tani a mail funkci�t.';
14
+ $PHPMAILER_LANG["authenticate"] = 'SMTP Hiba: Sikertelen autentik�ci�.';
15
+ $PHPMAILER_LANG["from_failed"] = 'Az al�bbi Felad� c�m hib�s: ';
16
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP Hiba: Az al�bbi ' .
17
+ 'c�mzettek hib�sak: ';
18
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Hiba: Nem elfogadhat� adat.';
19
+ $PHPMAILER_LANG["connect_host"] = 'SMTP Hiba: Nem tudtam csatlakozni az SMTP host-hoz.';
20
+ $PHPMAILER_LANG["file_access"] = 'Nem siker�lt el�rni a k�vetkez� f�jlt: ';
21
+ $PHPMAILER_LANG["file_open"] = 'F�jl Hiba: Nem siker�lt megnyitni a k�vetkez� f�jlt: ';
22
+ $PHPMAILER_LANG["encoding"] = 'Ismeretlen k�dol�s: ';
23
  ?>
classes/phpmailer/language/phpmailer.lang-it.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Italian version
5
- * @package PHPMailer
6
- * @author Ilias Bartolini <brain79@inwind.it>
7
- */
8
-
9
- $PHPMAILER_LANG = array();
10
-
11
- $PHPMAILER_LANG["provide_address"] = 'Deve essere fornito almeno un'.
12
- ' indirizzo ricevente';
13
- $PHPMAILER_LANG["mailer_not_supported"] = 'Mailer non supportato';
14
- $PHPMAILER_LANG["execute"] = "Impossibile eseguire l'operazione: ";
15
- $PHPMAILER_LANG["instantiate"] = 'Impossibile istanziare la funzione mail';
16
- $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Impossibile autenticarsi.';
17
- $PHPMAILER_LANG["from_failed"] = 'I seguenti indirizzi mittenti hanno'.
18
- ' generato errore: ';
19
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: I seguenti indirizzi'.
20
- 'destinatari hanno generato errore: ';
21
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data non accettati dal'.
22
- 'server.';
23
- $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Impossibile connettersi'.
24
- ' all\'host SMTP.';
25
- $PHPMAILER_LANG["file_access"] = 'Impossibile accedere al file: ';
26
- $PHPMAILER_LANG["file_open"] = 'File Error: Impossibile aprire il file: ';
27
- $PHPMAILER_LANG["encoding"] = 'Encoding set dei caratteri sconosciuto: ';
28
- ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Italian version
5
+ * @package PHPMailer
6
+ * @author Ilias Bartolini <brain79@inwind.it>
7
+ */
8
+
9
+ $PHPMAILER_LANG = array();
10
+
11
+ $PHPMAILER_LANG["provide_address"] = 'Deve essere fornito almeno un'.
12
+ ' indirizzo ricevente';
13
+ $PHPMAILER_LANG["mailer_not_supported"] = 'Mailer non supportato';
14
+ $PHPMAILER_LANG["execute"] = "Impossibile eseguire l'operazione: ";
15
+ $PHPMAILER_LANG["instantiate"] = 'Impossibile istanziare la funzione mail';
16
+ $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Impossibile autenticarsi.';
17
+ $PHPMAILER_LANG["from_failed"] = 'I seguenti indirizzi mittenti hanno'.
18
+ ' generato errore: ';
19
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: I seguenti indirizzi'.
20
+ 'destinatari hanno generato errore: ';
21
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data non accettati dal'.
22
+ 'server.';
23
+ $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Impossibile connettersi'.
24
+ ' all\'host SMTP.';
25
+ $PHPMAILER_LANG["file_access"] = 'Impossibile accedere al file: ';
26
+ $PHPMAILER_LANG["file_open"] = 'File Error: Impossibile aprire il file: ';
27
+ $PHPMAILER_LANG["encoding"] = 'Encoding set dei caratteri sconosciuto: ';
28
+ ?>
classes/phpmailer/language/phpmailer.lang-nl.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Dutch Version
5
- */
6
-
7
- $PHPMAILER_LANG = array();
8
-
9
- $PHPMAILER_LANG["provide_address"] = 'Er moet tenmiste &eacute;&eacute;n ' .
10
- 'ontvanger emailadres opgegeven worden.';
11
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer wordt niet ondersteund.';
12
- $PHPMAILER_LANG["execute"] = 'Kon niet uitvoeren: ';
13
- $PHPMAILER_LANG["instantiate"] = 'Kon mail functie niet initialiseren.';
14
- $PHPMAILER_LANG["authenticate"] = 'SMTP Fout: authenticatie mislukt.';
15
- $PHPMAILER_LANG["from_failed"] = 'De volgende afzender adressen zijn mislukt: ';
16
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Fout: De volgende ' .
17
- 'ontvangers zijn mislukt: ';
18
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Fout: Data niet geaccepteerd.';
19
- $PHPMAILER_LANG["connect_host"] = 'SMTP Fout: Kon niet verbinden met SMTP host.';
20
- $PHPMAILER_LANG["file_access"] = 'Kreeg geen toegang tot bestand: ';
21
- $PHPMAILER_LANG["file_open"] = 'Bestandsfout: Kon bestand niet openen: ';
22
- $PHPMAILER_LANG["encoding"] = 'Onbekende codering: ';
23
  ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Dutch Version
5
+ */
6
+
7
+ $PHPMAILER_LANG = array();
8
+
9
+ $PHPMAILER_LANG["provide_address"] = 'Er moet tenmiste &eacute;&eacute;n ' .
10
+ 'ontvanger emailadres opgegeven worden.';
11
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer wordt niet ondersteund.';
12
+ $PHPMAILER_LANG["execute"] = 'Kon niet uitvoeren: ';
13
+ $PHPMAILER_LANG["instantiate"] = 'Kon mail functie niet initialiseren.';
14
+ $PHPMAILER_LANG["authenticate"] = 'SMTP Fout: authenticatie mislukt.';
15
+ $PHPMAILER_LANG["from_failed"] = 'De volgende afzender adressen zijn mislukt: ';
16
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP Fout: De volgende ' .
17
+ 'ontvangers zijn mislukt: ';
18
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Fout: Data niet geaccepteerd.';
19
+ $PHPMAILER_LANG["connect_host"] = 'SMTP Fout: Kon niet verbinden met SMTP host.';
20
+ $PHPMAILER_LANG["file_access"] = 'Kreeg geen toegang tot bestand: ';
21
+ $PHPMAILER_LANG["file_open"] = 'Bestandsfout: Kon bestand niet openen: ';
22
+ $PHPMAILER_LANG["encoding"] = 'Onbekende codering: ';
23
  ?>
classes/phpmailer/language/phpmailer.lang-no.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Norwegian Version
5
- */
6
-
7
- $PHPMAILER_LANG = array();
8
-
9
- $PHPMAILER_LANG["provide_address"] = 'Du m� ha med minst en' .
10
- 'mottager adresse.';
11
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer er ikke supportert.';
12
- $PHPMAILER_LANG["execute"] = 'Kunne ikke utf�re: ';
13
- $PHPMAILER_LANG["instantiate"] = 'Kunne ikke instantiate mail funksjonen.';
14
- $PHPMAILER_LANG["authenticate"] = 'SMTP Feil: Kunne ikke authentisere.';
15
- $PHPMAILER_LANG["from_failed"] = 'F�lgende Fra feilet: ';
16
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Feil: F�lgende' .
17
- 'mottagere feilet: ';
18
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Feil: Data ble ikke akseptert.';
19
- $PHPMAILER_LANG["connect_host"] = 'SMTP Feil: Kunne ikke koble til SMTP host.';
20
- $PHPMAILER_LANG["file_access"] = 'Kunne ikke f� tilgang til filen: ';
21
- $PHPMAILER_LANG["file_open"] = 'Fil feil: Kunne ikke �pne filen: ';
22
- $PHPMAILER_LANG["encoding"] = 'Ukjent encoding: ';
23
- ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Norwegian Version
5
+ */
6
+
7
+ $PHPMAILER_LANG = array();
8
+
9
+ $PHPMAILER_LANG["provide_address"] = 'Du m� ha med minst en' .
10
+ 'mottager adresse.';
11
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer er ikke supportert.';
12
+ $PHPMAILER_LANG["execute"] = 'Kunne ikke utf�re: ';
13
+ $PHPMAILER_LANG["instantiate"] = 'Kunne ikke instantiate mail funksjonen.';
14
+ $PHPMAILER_LANG["authenticate"] = 'SMTP Feil: Kunne ikke authentisere.';
15
+ $PHPMAILER_LANG["from_failed"] = 'F�lgende Fra feilet: ';
16
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP Feil: F�lgende' .
17
+ 'mottagere feilet: ';
18
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Feil: Data ble ikke akseptert.';
19
+ $PHPMAILER_LANG["connect_host"] = 'SMTP Feil: Kunne ikke koble til SMTP host.';
20
+ $PHPMAILER_LANG["file_access"] = 'Kunne ikke f� tilgang til filen: ';
21
+ $PHPMAILER_LANG["file_open"] = 'Fil feil: Kunne ikke �pne filen: ';
22
+ $PHPMAILER_LANG["encoding"] = 'Ukjent encoding: ';
23
+ ?>
classes/phpmailer/language/phpmailer.lang-pl.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Polish Version, encoding: windows-1250
5
- * translated from english lang file ver. 1.72
6
- */
7
-
8
- $PHPMAILER_LANG = array();
9
-
10
- $PHPMAILER_LANG["provide_address"] = 'Nale�y poda� prawid�owy adres email Odbiorcy.';
11
- $PHPMAILER_LANG["mailer_not_supported"] = 'Wybrana metoda wysy�ki wiadomo�ci nie jest obs�ugiwana.';
12
- $PHPMAILER_LANG["execute"] = 'Nie mo�na uruchomi�: ';
13
- $PHPMAILER_LANG["instantiate"] = 'Nie mo�na wywo�a� funkcji mail(). Sprawd� konfiguracj� serwera.';
14
- $PHPMAILER_LANG["authenticate"] = 'B��d SMTP: Nie mo�na przeprowadzi� autentykacji.';
15
- $PHPMAILER_LANG["from_failed"] = 'Nast�puj�cy adres Nadawcy jest jest nieprawid�owy: ';
16
- $PHPMAILER_LANG["recipients_failed"] = 'B��d SMTP: Nast�puj�cy ' .
17
- 'odbiorcy s� nieprawid�owi: ';
18
- $PHPMAILER_LANG["data_not_accepted"] = 'B��d SMTP: Dane nie zosta�y przyj�te.';
19
- $PHPMAILER_LANG["connect_host"] = 'B��d SMTP: Nie mo�na po��czy� si� z wybranym hostem.';
20
- $PHPMAILER_LANG["file_access"] = 'Brak dost�pu do pliku: ';
21
- $PHPMAILER_LANG["file_open"] = 'Nie mo�na otworzy� pliku: ';
22
- $PHPMAILER_LANG["encoding"] = 'Nieznany spos�b kodowania znak�w: ';
23
-
24
  ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Polish Version, encoding: windows-1250
5
+ * translated from english lang file ver. 1.72
6
+ */
7
+
8
+ $PHPMAILER_LANG = array();
9
+
10
+ $PHPMAILER_LANG["provide_address"] = 'Nale�y poda� prawid�owy adres email Odbiorcy.';
11
+ $PHPMAILER_LANG["mailer_not_supported"] = 'Wybrana metoda wysy�ki wiadomo�ci nie jest obs�ugiwana.';
12
+ $PHPMAILER_LANG["execute"] = 'Nie mo�na uruchomi�: ';
13
+ $PHPMAILER_LANG["instantiate"] = 'Nie mo�na wywo�a� funkcji mail(). Sprawd� konfiguracj� serwera.';
14
+ $PHPMAILER_LANG["authenticate"] = 'B��d SMTP: Nie mo�na przeprowadzi� autentykacji.';
15
+ $PHPMAILER_LANG["from_failed"] = 'Nast�puj�cy adres Nadawcy jest jest nieprawid�owy: ';
16
+ $PHPMAILER_LANG["recipients_failed"] = 'B��d SMTP: Nast�puj�cy ' .
17
+ 'odbiorcy s� nieprawid�owi: ';
18
+ $PHPMAILER_LANG["data_not_accepted"] = 'B��d SMTP: Dane nie zosta�y przyj�te.';
19
+ $PHPMAILER_LANG["connect_host"] = 'B��d SMTP: Nie mo�na po��czy� si� z wybranym hostem.';
20
+ $PHPMAILER_LANG["file_access"] = 'Brak dost�pu do pliku: ';
21
+ $PHPMAILER_LANG["file_open"] = 'Nie mo�na otworzy� pliku: ';
22
+ $PHPMAILER_LANG["encoding"] = 'Nieznany spos�b kodowania znak�w: ';
23
+
24
  ?>
classes/phpmailer/language/phpmailer.lang-ro.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Romanian Version
5
- * @package PHPMailer
6
- * @author Catalin Constantin <catalin@dazoot.ro>
7
- */
8
-
9
- $PHPMAILER_LANG = array();
10
-
11
- $PHPMAILER_LANG["provide_address"] = 'Trebuie sa adaugati cel putin un recipient (adresa de mail).';
12
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer nu este suportat.';
13
- $PHPMAILER_LANG["execute"] = 'Nu pot executa: ';
14
- $PHPMAILER_LANG["instantiate"] = 'Nu am putut instantia functia mail.';
15
- $PHPMAILER_LANG["authenticate"] = 'Eroare SMTP: Nu a functionat autentificarea.';
16
- $PHPMAILER_LANG["from_failed"] = 'Urmatoarele adrese From au dat eroare: ';
17
- $PHPMAILER_LANG["recipients_failed"] = 'Eroare SMTP: Urmatoarele adrese de mail au dat eroare: ';
18
- $PHPMAILER_LANG["data_not_accepted"] = 'Eroare SMTP: Continutul mailului nu a fost acceptat.';
19
- $PHPMAILER_LANG["connect_host"] = 'Eroare SMTP: Nu m-am putut conecta la adresa SMTP.';
20
- $PHPMAILER_LANG["file_access"] = 'Nu pot accesa fisierul: ';
21
- $PHPMAILER_LANG["file_open"] = 'Eroare de fisier: Nu pot deschide fisierul: ';
22
- $PHPMAILER_LANG["encoding"] = 'Encodare necunoscuta: ';
23
- ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Romanian Version
5
+ * @package PHPMailer
6
+ * @author Catalin Constantin <catalin@dazoot.ro>
7
+ */
8
+
9
+ $PHPMAILER_LANG = array();
10
+
11
+ $PHPMAILER_LANG["provide_address"] = 'Trebuie sa adaugati cel putin un recipient (adresa de mail).';
12
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer nu este suportat.';
13
+ $PHPMAILER_LANG["execute"] = 'Nu pot executa: ';
14
+ $PHPMAILER_LANG["instantiate"] = 'Nu am putut instantia functia mail.';
15
+ $PHPMAILER_LANG["authenticate"] = 'Eroare SMTP: Nu a functionat autentificarea.';
16
+ $PHPMAILER_LANG["from_failed"] = 'Urmatoarele adrese From au dat eroare: ';
17
+ $PHPMAILER_LANG["recipients_failed"] = 'Eroare SMTP: Urmatoarele adrese de mail au dat eroare: ';
18
+ $PHPMAILER_LANG["data_not_accepted"] = 'Eroare SMTP: Continutul mailului nu a fost acceptat.';
19
+ $PHPMAILER_LANG["connect_host"] = 'Eroare SMTP: Nu m-am putut conecta la adresa SMTP.';
20
+ $PHPMAILER_LANG["file_access"] = 'Nu pot accesa fisierul: ';
21
+ $PHPMAILER_LANG["file_open"] = 'Eroare de fisier: Nu pot deschide fisierul: ';
22
+ $PHPMAILER_LANG["encoding"] = 'Encodare necunoscuta: ';
23
+ ?>
classes/phpmailer/language/phpmailer.lang-ru.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Russian Version
5
- */
6
-
7
- $PHPMAILER_LANG = array();
8
-
9
- $PHPMAILER_LANG["provide_address"] = '���������� ������� ������� ���� Email' .
10
- '����������.';
11
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer �� ��������������.';
12
- $PHPMAILER_LANG["execute"] = '���������� ��������� ��� �������: ';
13
- $PHPMAILER_LANG["instantiate"] = '��������� ������ ��� ������������� Mail �������.';
14
- $PHPMAILER_LANG["authenticate"] = 'SMTP ������: ������ �����������.';
15
- $PHPMAILER_LANG["from_failed"] = '�������� ����� �����������: ';
16
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP ������: ��������� ' .
17
- '������ ����������� �������: ';
18
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP ������: ������ �� ���� �������.';
19
- $PHPMAILER_LANG["connect_host"] = 'SMTP ������: SMTP-Host ����������.';
20
- $PHPMAILER_LANG["file_access"] = '� ������� � ���������� ����� ���� ��������: ';
21
- $PHPMAILER_LANG["file_open"] = '�� ���� ������� ����: ';
22
- $PHPMAILER_LANG["encoding"] = '����������� ������ ���������: ';
23
- ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Russian Version
5
+ */
6
+
7
+ $PHPMAILER_LANG = array();
8
+
9
+ $PHPMAILER_LANG["provide_address"] = '���������� ������� ������� ���� Email' .
10
+ '����������.';
11
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer �� ��������������.';
12
+ $PHPMAILER_LANG["execute"] = '���������� ��������� ��� �������: ';
13
+ $PHPMAILER_LANG["instantiate"] = '��������� ������ ��� ������������� Mail �������.';
14
+ $PHPMAILER_LANG["authenticate"] = 'SMTP ������: ������ �����������.';
15
+ $PHPMAILER_LANG["from_failed"] = '�������� ����� �����������: ';
16
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP ������: ��������� ' .
17
+ '������ ����������� �������: ';
18
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP ������: ������ �� ���� �������.';
19
+ $PHPMAILER_LANG["connect_host"] = 'SMTP ������: SMTP-Host ����������.';
20
+ $PHPMAILER_LANG["file_access"] = '� ������� � ���������� ����� ���� ��������: ';
21
+ $PHPMAILER_LANG["file_open"] = '�� ���� ������� ����: ';
22
+ $PHPMAILER_LANG["encoding"] = '����������� ������ ���������: ';
23
+ ?>
classes/phpmailer/language/phpmailer.lang-se.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
- /**
3
- * PHPMailer language file.
4
- * Swedish Version
5
- * Author: Johan Linn�r <johan@linner.biz>
6
- */
7
-
8
- $PHPMAILER_LANG = array();
9
-
10
- $PHPMAILER_LANG["provide_address"] = 'Du m�ste ange minst en ' .
11
- 'mottagares e-postadress.';
12
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer st�ds inte.';
13
- $PHPMAILER_LANG["execute"] = 'Kunde inte k�ra: ';
14
- $PHPMAILER_LANG["instantiate"] = 'Kunde inte initiera e-postfunktion.';
15
- $PHPMAILER_LANG["authenticate"] = 'SMTP fel: Kunde inte autentisera.';
16
- $PHPMAILER_LANG["from_failed"] = 'F�ljande avs�ndaradress �r felaktig: ';
17
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP fel: F�ljande ' .
18
- 'mottagare �r felaktig: ';
19
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP fel: Data accepterades inte.';
20
- $PHPMAILER_LANG["connect_host"] = 'SMTP fel: Kunde inte ansluta till SMTP-server.';
21
- $PHPMAILER_LANG["file_access"] = 'Ingen �tkomst till fil: ';
22
- $PHPMAILER_LANG["file_open"] = 'Fil fel: Kunde inte �ppna fil: ';
23
- $PHPMAILER_LANG["encoding"] = 'Ok�nt encode-format: ';
24
  ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer language file.
4
+ * Swedish Version
5
+ * Author: Johan Linn�r <johan@linner.biz>
6
+ */
7
+
8
+ $PHPMAILER_LANG = array();
9
+
10
+ $PHPMAILER_LANG["provide_address"] = 'Du m�ste ange minst en ' .
11
+ 'mottagares e-postadress.';
12
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer st�ds inte.';
13
+ $PHPMAILER_LANG["execute"] = 'Kunde inte k�ra: ';
14
+ $PHPMAILER_LANG["instantiate"] = 'Kunde inte initiera e-postfunktion.';
15
+ $PHPMAILER_LANG["authenticate"] = 'SMTP fel: Kunde inte autentisera.';
16
+ $PHPMAILER_LANG["from_failed"] = 'F�ljande avs�ndaradress �r felaktig: ';
17
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP fel: F�ljande ' .
18
+ 'mottagare �r felaktig: ';
19
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP fel: Data accepterades inte.';
20
+ $PHPMAILER_LANG["connect_host"] = 'SMTP fel: Kunde inte ansluta till SMTP-server.';
21
+ $PHPMAILER_LANG["file_access"] = 'Ingen �tkomst till fil: ';
22
+ $PHPMAILER_LANG["file_open"] = 'Fil fel: Kunde inte �ppna fil: ';
23
+ $PHPMAILER_LANG["encoding"] = 'Ok�nt encode-format: ';
24
  ?>
classes/phpmailer/language/phpmailer.lang-tr.php CHANGED
@@ -1,25 +1,25 @@
1
- <?php
2
- /**
3
- * PHPMailer dil dosyas�.
4
- * T�rk�e Versiyonu
5
- * �ZYAZILIM - El�in �zel - Can Y�lmaz - Mehmet Benlio�lu
6
- */
7
-
8
- $PHPMAILER_LANG = array();
9
-
10
- $PHPMAILER_LANG["provide_address"] = 'En az bir tane mail adresi belirtmek zorundas�n�z ' .
11
- 'al�c�n�n email adresi.';
12
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailler desteklenmemektedir.';
13
- $PHPMAILER_LANG["execute"] = '�al��t�r�lam�yor: ';
14
- $PHPMAILER_LANG["instantiate"] = '�rnek mail fonksiyonu yarat�lamad�.';
15
- $PHPMAILER_LANG["authenticate"] = 'SMTP Hatas�: Do�rulanam�yor.';
16
- $PHPMAILER_LANG["from_failed"] = 'Ba�ar�s�z olan g�nderici adresi: ';
17
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Hatas�: ' .
18
- 'al�c�lara ula�mad�: ';
19
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Hatas�: Veri kabul edilmedi.';
20
- $PHPMAILER_LANG["connect_host"] = 'SMTP Hatas�: SMTP hosta ba�lan�lam�yor.';
21
- $PHPMAILER_LANG["file_access"] = 'Dosyaya eri�ilemiyor: ';
22
- $PHPMAILER_LANG["file_open"] = 'Dosya Hatas�: Dosya a��lam�yor: ';
23
- $PHPMAILER_LANG["encoding"] = 'Bilinmeyen �ifreleme: ';
24
-
25
  ?>
1
+ <?php
2
+ /**
3
+ * PHPMailer dil dosyas�.
4
+ * T�rk�e Versiyonu
5
+ * �ZYAZILIM - El�in �zel - Can Y�lmaz - Mehmet Benlio�lu
6
+ */
7
+
8
+ $PHPMAILER_LANG = array();
9
+
10
+ $PHPMAILER_LANG["provide_address"] = 'En az bir tane mail adresi belirtmek zorundas�n�z ' .
11
+ 'al�c�n�n email adresi.';
12
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailler desteklenmemektedir.';
13
+ $PHPMAILER_LANG["execute"] = '�al��t�r�lam�yor: ';
14
+ $PHPMAILER_LANG["instantiate"] = '�rnek mail fonksiyonu yarat�lamad�.';
15
+ $PHPMAILER_LANG["authenticate"] = 'SMTP Hatas�: Do�rulanam�yor.';
16
+ $PHPMAILER_LANG["from_failed"] = 'Ba�ar�s�z olan g�nderici adresi: ';
17
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP Hatas�: ' .
18
+ 'al�c�lara ula�mad�: ';
19
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Hatas�: Veri kabul edilmedi.';
20
+ $PHPMAILER_LANG["connect_host"] = 'SMTP Hatas�: SMTP hosta ba�lan�lam�yor.';
21
+ $PHPMAILER_LANG["file_access"] = 'Dosyaya eri�ilemiyor: ';
22
+ $PHPMAILER_LANG["file_open"] = 'Dosya Hatas�: Dosya a��lam�yor: ';
23
+ $PHPMAILER_LANG["encoding"] = 'Bilinmeyen �ifreleme: ';
24
+
25
  ?>
em-actions.php DELETED
@@ -1,241 +0,0 @@
1
- <?php
2
- /**
3
- * Performs actions on init. This works for both ajax and normal requests, the return results depends if an em_ajax flag is passed via POST or GET.
4
- */
5
- function em_init_actions() {
6
- //NOTE - No EM objects are globalized at this point, as we're hitting early init mode.
7
- //TODO Clean this up.... use a uniformed way of calling EM Ajax actions
8
- if( !empty($_REQUEST['em_ajax']) || !empty($_REQUEST['em_ajax_action']) ){
9
- if(isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'get_location') {
10
- if(isset($_REQUEST['id'])){
11
- $EM_Location = new EM_Location($_REQUEST['id']);
12
- $location_array = $EM_Location->to_array();
13
- $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_location_baloon_format'));
14
- echo EM_Object::json_encode($location_array);
15
- }
16
- die();
17
- }
18
- if(isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'delete_ticket') {
19
- if(isset($_REQUEST['id'])){
20
- $EM_Ticket = new EM_Ticket($_REQUEST['id']);
21
- $result = $EM_Ticket->delete();
22
- if($result){
23
- $result = array('result'=>true);
24
- }else{
25
- $result = array('result'=>false, 'error'=>$EM_Ticket->feedback_message);
26
- }
27
- }else{
28
- $result = array('result'=>false, 'error'=>__('No ticket id provided','dbem'));
29
- }
30
- echo EM_Object::json_encode($result);
31
- die();
32
- }
33
- if(isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalMapData') {
34
- $EM_Locations = EM_Locations::get( $_REQUEST );
35
- $json_locations = array();
36
- foreach($EM_Locations as $location_key => $EM_Location) {
37
- $json_locations[$location_key] = $EM_Location->to_array();
38
- $json_locations[$location_key]['location_balloon'] = $EM_Location->output(get_option('dbem_map_text_format'));
39
- }
40
- echo EM_Object::json_encode($json_locations);
41
- die();
42
- }
43
-
44
- if(isset($_REQUEST['ajaxCalendar']) && $_REQUEST['ajaxCalendar']) {
45
- //FIXME if long events enabled originally, this won't show up on ajax call
46
- echo EM_Calendar::output($_REQUEST);
47
- die();
48
- }
49
-
50
- //EM Ajax requests require this flag.
51
- if( is_admin() && is_user_logged_in() ){
52
- //Admin operations
53
- global $EM_Booking;
54
- //TODO multiple deletion won't work in ajax
55
- if( !empty($_REQUEST['action']) && (!empty($_REQUEST['bookings']) || !empty($_REQUEST['booking_id'])) ){
56
- $allowed_actions = array('bookings_approve'=>'approve','bookings_reject'=>'reject','bookings_unapprove'=>'unapprove', 'bookings_delete'=>'delete');
57
- if( array_key_exists($_REQUEST['action'], $allowed_actions) ){
58
- $action = $allowed_actions[$_REQUEST['action']];
59
- //Just do it here, since we may be deleting bookings of different events.
60
- if( !empty($_REQUEST['bookings']) && EM_Object::array_is_numeric($_REQUEST['bookings'])){
61
- $results = array();
62
- foreach($_REQUEST['bookings'] as $booking_id){
63
- $EM_Booking = new EM_Booking($booking_id);
64
- $result = $EM_Booking->$action();
65
- $results[] = $result;
66
- if( !in_array(false, $results) || !$result ){
67
- $feedback = $EM_Booking->feedback_message;
68
- }
69
- }
70
- $result = !in_array(false,$results);
71
- }elseif( !empty($_REQUEST['bookings']) && is_numeric($_REQUEST['bookings'])){
72
- $EM_Booking = new EM_Booking($_REQUEST['bookings']);
73
- $result = $EM_Booking->$action();
74
- $feedback = $EM_Booking->feedback_message;
75
- }elseif( is_object($EM_Booking) ){
76
- $result = $EM_Booking->$action();
77
- $feedback = $EM_Booking->feedback_message;
78
- }
79
- if( $result ){
80
- echo $feedback;
81
- }else{
82
- echo '<span style="color:red">'.$feedback.'</span>';
83
- }
84
- die();
85
- }
86
- }
87
- //Specific Oject Ajax
88
- if( !empty($_REQUEST['em_obj']) ){
89
- switch( $_REQUEST['em_obj'] ){
90
- case 'em_bookings_events_table':
91
- case 'em_bookings_pending_table':
92
- case 'em_bookings_confirmed_table':
93
- call_user_func($_REQUEST['em_obj']);
94
- break;
95
- }
96
- die();
97
- }
98
- }
99
- }
100
- //Event Actions
101
- if( !empty($_REQUEST['action']) && substr($_REQUEST['action'],0,5) == 'event' ){
102
- global $EM_Event, $EM_Notices;
103
- //Load the event object, with saved event if requested
104
- if( !empty($_REQUEST['event_id']) ){
105
- $EM_Event = new EM_Event($_REQUEST['event_id']);
106
- }else{
107
- $EM_Event = new EM_Event();
108
- }
109
- if( $_REQUEST['action'] == 'event_save' && current_user_can('edit_events') ){
110
- //Check Nonces
111
- if( is_admin() ){
112
- if( !wp_verify_nonce($_REQUEST['_wpnonce'] && 'event_save') ) check_admin_referer('trigger_error');
113
- }else{
114
- if( !wp_verify_nonce($_REQUEST['_wpnonce'] && 'event_save') ) exit('Trying to perform an illegal action.');
115
- }
116
- //Grab and validate submitted data
117
- if ( $EM_Event->get_post() && $EM_Event->save() ) { //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS)
118
- $EM_Notices->add_confirm($EM_Event->feedback_message);
119
- if( is_admin() ){
120
- $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno']:'';
121
- $scope = !empty($_REQUEST['scope']) ? $_REQUEST['scope']:'';
122
- //wp_redirect( get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager&pno='.$page.'&scope='.$scope.'&message='.urlencode($EM_Event->feedback_message));
123
- }else{
124
- $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer();
125
- wp_redirect( $redirect );
126
- }
127
- $events_result = true;
128
- }else{
129
- foreach($EM_Event->get_errors() as $error){
130
- $EM_Notices->add_error( $error );
131
- }
132
- $events_result = false;
133
- }
134
- }
135
- if ( $_REQUEST['action'] == 'event_duplicate' ) {
136
- global $EZSQL_ERROR;
137
- $EM_Event = $EM_Event->duplicate();
138
- if( $EM_Event === false ){
139
- $EM_Notices->add_error($EM_Event->errors, true);
140
- }else{
141
- if( $EM_Event->id == $_REQUEST['event_id'] ){
142
- $EM_Notices->add_confirm($EM_Event->feedback_message ." ". sprintf(__('You are now viewing the duplicated %s.', 'dbem'),__('event','dbem')), true);
143
- }else{
144
- $EM_Notices->add_confirm($EM_Event->feedback_message, true);
145
- }
146
- }
147
- }
148
- if ( $_REQUEST['action'] == 'event_delete' ) {
149
- //DELETE action
150
- $selectedEvents = !empty($_REQUEST['events']) ? $_REQUEST['events']:'';
151
- if( EM_Object::array_is_numeric($selectedEvents) ){
152
- $events_result = EM_Events::delete( $selectedEvents );
153
- }elseif( is_object($EM_Event) ){
154
- $events_result = $EM_Event->delete();
155
- }
156
- $plural = (count($selectedEvents) > 1) ? __('Events','dbem'):__('Event','dbem');
157
- if($events_result){
158
- $message = ( is_object($EM_Event) ) ? $EM_Event->feedback_message : sprintf(__('%s successfully deleted.','dbem'),$plural);
159
- $EM_Notices->add_confirm( $message );
160
- }else{
161
- $message = ( is_object($EM_Event) ) ? $EM_Event->errors : sprintf(__('%s could not be deleted.','dbem'),$plural);
162
- $EM_Notices->add_confirm( $message );
163
- }
164
- }elseif( $_REQUEST['action'] == 'event_approve' ){
165
- //Approve Action
166
- $events_result = $EM_Event->approve();
167
- if($events_result){
168
- $EM_Notices->add_confirm( $EM_Event->feedback_message );
169
- }else{
170
- $EM_Notices->add_error( $EM_Event->errors );
171
- }
172
- }
173
-
174
- //AJAX Exit
175
- if( isset($events_result) && !empty($_REQUEST['em_ajax']) ){
176
- if( $events_result ){
177
- $return = array('result'=>true, 'message'=>$EM_Event->feedback_message);
178
- }else{
179
- $return = array('result'=>false, 'message'=>$EM_Event->feedback_message, 'errors'=>$EM_Event->errors);
180
- }
181
- }
182
- }
183
-
184
- //Location Actions
185
- if( !empty($_REQUEST['action']) && substr($_REQUEST['action'],0,8) == 'location' ){
186
- global $EM_Location, $EM_Notices;
187
- //Load the location object, with saved event if requested
188
- if( !empty($_REQUEST['location_id']) ){
189
- $EM_Location = new EM_Location($_REQUEST['location_id']);
190
- }else{
191
- $EM_Location = new EM_Location();
192
- }
193
- if( $_REQUEST['action'] == 'location_save' && current_user_can('edit_locations') ){
194
- //Check Nonces
195
- em_verify_nonce('location_save');
196
- //Grab and validate submitted data
197
- $EM_Location->get_post();
198
- if ( $EM_Location->save() ) { //EM_location gets the location if submitted via POST and validates it (safer than to depend on JS)
199
- $EM_Notices->add_confirm($EM_Location->feedback_message);
200
- $result = true;
201
- }else{
202
- foreach($EM_Location->get_errors() as $error){
203
- $EM_Notices->add_error( $error );
204
- }
205
- $result = false;
206
- }
207
- }elseif( !empty($_REQUEST['action']) && $_REQUEST['action'] == "location_delete" ){
208
- //delete location
209
- //get object or objects
210
- if( !empty($_REQUEST['locations']) || !empty($_REQUEST['location_id']) ){
211
- $args = !empty($_REQUEST['locations']) ? $_REQUEST['locations']:$_REQUEST['location_id'];
212
- $locations = EM_Locations::get($args);
213
- foreach($locations as $location) {
214
- if( !$location->delete() ){
215
- $EM_Notices->add_error($location->get_errors());
216
- $errors = true;
217
- }
218
- }
219
- if( empty($errors) ){
220
- $result = true;
221
- $location_term = ( count($locations) > 1 ) ?__('Locations', 'dbem') : __('Location', 'dbem');
222
- $EM_Notices->add_confirm( sprintf(__('%s successfully deleted', 'dbem'), $location_term) );
223
- }else{
224
- $result = false;
225
- }
226
- }
227
- }
228
- if( isset($result) && $result && !empty($_REQUEST['em_ajax']) ){
229
- $return = array('result'=>true, 'message'=>$EM_Location->feedback_message);
230
- echo EM_Object::json_encode($return);
231
- die();
232
- }elseif( isset($result) && !$result && !empty($_REQUEST['em_ajax']) ){
233
- $return = array('result'=>false, 'message'=>$EM_Location->feedback_message, 'errors'=>$EM_Notices->get_errors());
234
- echo EM_Object::json_encode($return);
235
- die();
236
- }
237
- }
238
- }
239
- add_action('init','em_init_actions');
240
-
241
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
em-ajax.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //AJAX function
3
+ function em_ajax_actions() {
4
+ //TODO Clean this up.... use a uniformed way of calling EM Ajax actions
5
+ if( !empty($_REQUEST['em_ajax']) || !empty($_REQUEST['em_ajax_action']) ){
6
+ if(isset($_REQUEST['dbem_ajax_action']) && $_REQUEST['dbem_ajax_action'] == 'booking_data') {
7
+ if(isset($_REQUEST['id'])){
8
+ $EM_Event = new EM_Event($_REQUEST['id']);
9
+ echo "[{bookedSeats:".$EM_Event->get_bookings()->get_booked_seats().", availableSeats:".$EM_Event->get_bookings()->get_available_seats()."}]";
10
+ }
11
+ die();
12
+ }
13
+ if(isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'get_location') {
14
+ if(isset($_REQUEST['id'])){
15
+ $EM_Location = new EM_Location($_REQUEST['id']);
16
+ $location_array = $EM_Location->to_array();
17
+ $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_location_baloon_format'));
18
+ echo EM_Object::json_encode($location_array);
19
+ }
20
+ die();
21
+ }
22
+ if(isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalMapData') {
23
+ $locations = EM_Locations::get( $_REQUEST );
24
+ $json_locations = array();
25
+ foreach($locations as $location_key => $location) {
26
+ $json_locations[$location_key] = $location->to_array();
27
+ $json_locations[$location_key]['location_balloon'] = $location->output(get_option('dbem_map_text_format'));
28
+ }
29
+ echo EM_Object::json_encode($json_locations);
30
+ die();
31
+ }
32
+
33
+ if(isset($_REQUEST['ajaxCalendar']) && $_REQUEST['ajaxCalendar']) {
34
+ //FIXME if long events enabled originally, this won't show up on ajax call
35
+ echo EM_Calendar::output($_REQUEST);
36
+ die();
37
+ }
38
+
39
+ //EM Ajax requests require this flag.
40
+ if( is_admin() ){
41
+ //Admin operations
42
+ //Booking Actions
43
+ global $EM_Booking;
44
+ if( !empty($_REQUEST['bookings']) || is_object($EM_Booking) ){
45
+ if( is_object($EM_Booking) ){
46
+ $_REQUEST['bookings'] = $EM_Booking; //small hack to prevent unecessary db reads
47
+ }
48
+ $EM_Bookings = new EM_Bookings(); //Empty, not bound to event.
49
+ if( $_REQUEST['action'] == 'bookings_approve' ){
50
+ $EM_Bookings->approve($_REQUEST['bookings']);
51
+ echo $EM_Bookings->feedback_message;
52
+ die();
53
+ }elseif($_REQUEST['action'] == 'bookings_reject'){
54
+ $EM_Bookings->reject($_REQUEST['bookings']);
55
+ echo $EM_Bookings->feedback_message;
56
+ die();
57
+ }elseif($_REQUEST['action'] == 'bookings_unapprove'){
58
+ $EM_Bookings->unapprove($_REQUEST['bookings']);
59
+ echo $EM_Bookings->feedback_message;
60
+ die();
61
+ }elseif($_REQUEST['action'] == 'bookings_delete'){
62
+ //Just do it here, since we may be deleting bookings of different events.
63
+ $result = false;
64
+ if(EM_Object::array_is_numeric($_REQUEST['bookings'])){
65
+ $results = array();
66
+ foreach($_REQUEST['bookings'] as $booking_id){
67
+ $EM_Booking = new EM_Booking($booking_id);
68
+ $results[] = $EM_Booking->delete();
69
+ }
70
+ $result = !in_array(false,$results);
71
+ }elseif( is_numeric($_REQUEST['bookings']) ){
72
+ $EM_Booking = new EM_Booking($_REQUEST['bookings']);
73
+ $result = $EM_Booking->delete();
74
+ }elseif( is_object($EM_Booking) ){
75
+ $result = $EM_Booking->delete();
76
+ }
77
+ if( $result ){
78
+ echo __('Booking Deleted','dbem');
79
+ }else{
80
+ echo '<span style="color:red">'.__('Booking deletion unsuccessful','dbem').'</span>';
81
+ }
82
+ die();
83
+ }
84
+ }
85
+ //Specific Oject Ajax
86
+ if( !empty($_REQUEST['em_obj']) ){
87
+ switch( $_REQUEST['em_obj'] ){
88
+ case 'em_bookings_events_table':
89
+ case 'em_bookings_pending_table':
90
+ case 'em_bookings_confirmed_table':
91
+ call_user_func($_REQUEST['em_obj']);
92
+ break;
93
+ }
94
+ die();
95
+ }
96
+ }
97
+ }
98
+ }
99
+ add_action('init','em_ajax_actions');
100
+
101
+ ?>
em-bookings.php CHANGED
@@ -1,263 +1,163 @@
1
- <?php
2
- /**
3
- * This object is a parent of EM_Bookings_Form, which is extendable by creating a bookings form object and placing the
4
- * php file in the wp-content/mu-plugins folder (see http://wpmututorials.com/plugins/basics/what-is-the-mu-plugins-folder/ for more info).
5
- * Since mu-plugin files are executed before this, the EM_Bookings_Form will already be defined and won't be definied here.
6
- * @author marcus
7
- *
8
- */
9
- class EM_Bookings_Form_Core extends EM_Object {
10
- /* Contains functions to handle save and delete requests on the front-end for bookings */
11
- static $em_form_messages_booking_cancel = array();
12
- static $em_form_messages_booking_add = array();
13
-
14
- function init(){
15
- add_action('template_redirect', array('EM_Bookings_Form','actions'),100);
16
- //catch the ajax call
17
- add_action( 'wp_ajax_add_booking', array('EM_Bookings_Form','ajax_add_booking') );
18
- }
19
-
20
- function ajax_add_booking(){
21
- /* Check the nonce */
22
- check_admin_referer( 'add_booking', '_wpnonce_add_booking' );
23
- if( !empty($_REQUEST['event_id']) && is_numeric($_REQUEST['event_id']) ){
24
- $EM_Event = new EM_Event($_REQUEST['event_id']);
25
- $result = $EM_Event->get_bookings()->add_from_post();
26
- if($result){
27
- $return = array('result'=>true, 'message'=>$EM_Event->get_bookings()->feedback_message);
28
- }else{
29
- $return = array('result'=>false, 'message'=>implode('<br />', $EM_Event->get_bookings()->errors));
30
- }
31
- echo EM_Object::json_encode($return);
32
- exit();
33
- }else{
34
- $return = array('result'=>false, 'message'=>'');
35
- echo EM_Object::json_encode($return);
36
- exit();
37
- }
38
- }
39
-
40
- /**
41
- * Check if there's any actions to take for bookings
42
- * @return null
43
- */
44
- function actions() {
45
- global $wpdb;
46
- global $EM_Event, $EM_Person;
47
- if( @get_class($EM_Event) == 'EM_Event' ){
48
- //ADD/EDIT Booking
49
- if (isset($_POST['action']) && $_POST['action'] == 'add_booking') {
50
- check_admin_referer( 'em_add_booking', '_wpnonce_em_add_booking' );
51
- $EM_Event->get_bookings()->add_from_post();
52
- }
53
- //CANCEL Booking
54
- if (isset($_POST['action']) && $_POST['action'] == 'cancel_booking') {
55
- self::cancel_booking();
56
- }
57
- }
58
- }
59
-
60
- /**
61
- * Handles booking cancellations on the front end. makes a few extra checks.
62
- */
63
- function cancel_booking(){
64
- global $EM_Event;
65
- if( is_user_logged_in() ){
66
- $canceled = 0;
67
- foreach($EM_Event->get_bookings()->bookings as $EM_Booking){
68
- if($EM_Booking->person->ID == $EM_Person->ID ){
69
- $EM_Booking->cancel();
70
- $canceled++;
71
- }
72
- }
73
- if($canceled > 0){
74
- self::$em_form_messages_booking_cancel['success'] = __('Booking cancelled', 'dbem');
75
- }
76
- }else{
77
- self::$em_form_messages_booking_cancel['error'] = __('You must log in to cancel your booking.', 'dbem');
78
- }
79
- }
80
-
81
- /**
82
- * Returns the booking form for the front-end, displayed when using placeholder #_ADDBOOKINGFORM
83
- * @return string
84
- */
85
- function create() {
86
- global $em_form_messages_booking_add, $EM_Event;
87
-
88
- $booked_places_options = array();
89
- for ( $i = 1; $i <= 10; $i++ ) {
90
- $booking_spaces = (!empty($_POST['booking_spaces']) && $_POST['booking_spaces'] == $i) ? 'selected="selected"':'';
91
- array_push($booked_places_options, "<option value='$i' $booking_spaces>$i</option>");
92
- }
93
- ob_start();
94
- ?>
95
- <div id="em-booking">
96
- <a name="em-booking"></a>
97
- <h3><?php _e('Book now!','dbem') ?></h3>
98
-
99
- <?php if( !empty($EM_Event->get_bookings()->feedback_message) && count($EM_Event->get_bookings()->errors) == 0 ) : ?>
100
- <div class='em-booking-message-success'><?php echo $EM_Event->get_bookings()->feedback_message; ?></div>
101
- <?php elseif( count($EM_Event->get_bookings()->errors) > 1 ) : ?>
102
- <div class='em-booking-message-error'><?php echo implode('<br />', $EM_Event->get_bookings()->errors); ?></div>
103
- <?php elseif( !empty($EM_Event->get_bookings()->feedback_message) ) : ?>
104
- <div class='em-booking-message'><?php echo $EM_Event->get_bookings()->feedback_message; ?></div>
105
- <?php endif; ?>
106
-
107
- <form id='em-booking-form' name='booking-form' method='post' action=''>
108
- <?php do_action('em_booking_form_before_tickets'); ?>
109
- <?php
110
- $EM_Tickets = ( get_option('dbem_bookings_tickets_show_unavailable') ) ? $EM_Event->get_bookings()->get_tickets():$EM_Event->get_bookings()->get_tickets();
111
- if( (count($EM_Tickets->tickets) > 1 || !empty($EM_Tickets->get_first()->price)) && (get_option('dbem_bookings_tickets_show_loggedout') || is_user_logged_in()) ): ?>
112
- <table class="em-tickets" cellspacing="0" cellpadding="0">
113
- <tr>
114
- <td><?php _e('Ticket Type','dbem') ?></td>
115
- <td><?php _e('Price','dbem') ?></td>
116
- <td><?php _e('Spaces','dbem') ?></td>
117
- </tr>
118
- <?php foreach( $EM_Tickets->tickets as $EM_Ticket ): ?>
119
- <?php if( $EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable') ): ?>
120
- <tr>
121
- <td><?php echo $EM_Ticket->output_property('name'); ?></td>
122
- <td><?php echo $EM_Ticket->output_property('price'); ?></td>
123
- <td>
124
- <?php
125
- $spaces_options = $EM_Ticket->get_spaces_options();
126
- if( $spaces_options ){
127
- echo $spaces_options;
128
- }else{
129
- echo "<strong>".__('N/A','dbem')."</strong>";
130
- }
131
- ?>
132
- </td>
133
- </tr>
134
- <?php endif; ?>
135
- <?php endforeach; ?>
136
- </table>
137
- <?php endif; ?>
138
- <?php do_action('em_booking_form_after_tickets'); ?>
139
- <?php if( is_user_logged_in() && count($EM_Tickets->tickets) > 0 ) : ?>
140
- <?php $EM_Ticket = $EM_Tickets->get_first(); ?>
141
- <table class='em-booking-form-details'>
142
- <?php if( is_object($EM_Ticket) && (count($EM_Tickets->tickets) == 1 && empty($EM_Tickets->get_first()->price)) ): ?>
143
- <tr>
144
- <th scope='row'><?php _e('Spaces', 'dbem') ?>:</th>
145
- <td>
146
- <?php
147
- $spaces_options = $EM_Ticket->get_spaces_options(false);
148
- if( $spaces_options ){
149
- echo $spaces_options;
150
- }else{
151
- echo "<strong>".__('N/A','dbem')."</strong>";
152
- }
153
- ?>
154
- </td>
155
- </tr>
156
- <?php endif; ?>
157
- <?php do_action('em_booking_form_before_user_details'); ?>
158
- <tr><th scope='row'><?php _e('Comment', 'dbem') ?>:</th><td><textarea name='booking_comment'><?php echo !empty($_POST['booking_comment']) ? $_POST['booking_comment']:'' ?></textarea></td></tr>
159
- <?php do_action('em_booking_form_footer'); ?>
160
- </table>
161
- <div class="em-booking-buttons">
162
- <?php echo apply_filters('em_booking_form_buttons', '<input type="submit" class="em-booking-submit" value="'.__('Send your booking', 'dbem').'" />'); ?>
163
- <input type='hidden' name='action' value='add_booking'/>
164
- <input type='hidden' name='callback' value='em'/>
165
- <input type='hidden' name='event_id' value='<?php echo $EM_Event->id; ?>'/>
166
- <?php echo wp_nonce_field('add_booking','_wpnonce_add_booking'); ?>
167
- </div>
168
- <?php elseif( count($EM_Tickets->tickets) == 0 ): ?>
169
- <div><?php _e('No more tickets available at this time.','dbem'); ?></div>
170
- <?php else: ?>
171
- <div><?php echo sprintf(__('You must <a href="%s">register</a> or <a href="%s">log in</a> in order to create and manage your bookings.','dbem'), site_url('wp-login.php?action=register', 'login_post'), site_url('wp-login.php', 'login_post')); ?></div>
172
- <?php endif; ?>
173
- </form>
174
- </div>
175
- <?php echo self::get_js(); ?>
176
- <?php
177
- return apply_filters('em_bookings_form_create', ob_get_clean());
178
- }
179
-
180
- function get_js(){
181
- ob_start();
182
- ?>
183
- <script type="text/javascript">
184
- jQuery(document).ready( function($){
185
- $('#em-booking-form').ajaxForm({
186
- url: EM.ajaxurl,
187
- dataType: 'jsonp',
188
- beforeSubmit: function(formData, jqForm, options) {
189
- $('.em-booking-message').remove();
190
- $('#em-booking-form').append('<div id="em-loading"></div>');
191
- },
192
- success : function(response, statusText, xhr, $form) {
193
- $('#em-loading').remove();
194
- if(response.result){
195
- $('<div class="em-booking-message-success em-booking-message">'+response.message+'</div>').insertBefore('#em-booking-form');
196
- }else{
197
- $('<div class="em-booking-message-error em-booking-message">'+response.message+'</div>').insertBefore('#em-booking-form');
198
-
199
- }
200
- }
201
- });
202
- });
203
- </script>
204
- <?php
205
- return apply_filters('em_bookings_form_get_js', ob_get_clean());
206
- }
207
-
208
- /**
209
- * Booking removal in front end, called by placeholder #_REMOVEBOOKINGFORM
210
- * @return string
211
- */
212
- function cancel() {
213
- global $em_form_messages_booking_cancel, $EM_Event;
214
- $destination = "?".$_SERVER['QUERY_STRING'];
215
- ob_start();
216
- ?>
217
- <div id="em-booking-delete">
218
- <a name="em-booking-delete"></a>
219
- <h3><?php _e('Cancel your booking', 'dbem') ?></h3>
220
-
221
- <?php if( is_user_logged_in() ): ?>
222
- <?php if( !empty(self::$em_form_messages_booking_cancel['success']) ) : ?>
223
- <div class='em-booking-message-success'><?php echo self::$em_form_messages_booking_cancel['success'] ?></div>
224
- <?php elseif( !empty(self::$em_form_messages_booking_cancel['error']) ) : ?>
225
- <div class='em-booking-message-error'><?php echo self::$em_form_messages_booking_cancel['error'] ?></div>
226
- <?php elseif( !empty(self::$em_form_messages_booking_cancel['message']) ) : ?>
227
- <div class='em-booking-message'><?php echo self::$em_form_messages_booking_add['message'] ?></div>
228
- <?php endif; ?>
229
-
230
- <form name='booking-delete-form' method='post' action='<?php echo $destination ?>#em-booking-delete'>
231
- <input type='hidden' name='em_action' value='delete_booking'/>
232
- <input type='hidden' name='event_id' value='<?php echo $EM_Event->id; ?>'/>
233
- <input type='submit' value='<?php _e('Cancel your booking', 'dbem') ?>'/>
234
- </form>
235
- <?php else: ?>
236
- <p>Please <a href="<?php echo site_url('wp-login.php', 'login_post'); ?>">log in</a> to manage your bookings.</p>
237
- <?php endif; ?>
238
- </div>
239
- <?php
240
- return ob_get_clean();
241
- }
242
-
243
- /* AJAX update posting */
244
- function bp_dtheme_post_update() {
245
- global $bp;
246
-
247
- /* Check the nonce */
248
- check_admin_referer( 'post_update', '_wpnonce_post_update' );
249
-
250
- if ( !is_user_logged_in() ) {
251
- echo '-1';
252
- return false;
253
- }
254
- add_action( 'wp_ajax_post_update', 'bp_dtheme_post_update' );
255
- }
256
- }
257
- if( !class_exists('EM_Bookings_Form') ){
258
- class EM_Bookings_Form extends EM_Bookings_Form_Core {
259
-
260
- }
261
- }
262
- EM_Bookings_Form::init();
1
+ <?php
2
+ /* Contains functions to handle save and delete requests on the front-end for bookings */
3
+ global $dbem_form_messages_booking_delete;
4
+ $dbem_form_messages_booking_delete = array();
5
+ global $dbem_form_messages_booking_add;
6
+ $dbem_form_messages_booking_add = array();
7
+
8
+ /**
9
+ * Check if there's any actions to take for bookings
10
+ * @return null
11
+ */
12
+ function em_actions_bookings() {
13
+ global $dbem_form_messages_booking_delete, $dbem_form_messages_booking_add;
14
+ global $wpdb;
15
+ global $EM_Event;
16
+
17
+ if( @get_class($EM_Event) == 'EM_Event' ){
18
+ //ADD/EDIT Booking
19
+ if (isset($_POST['eventAction']) && $_POST['eventAction'] == 'add_booking') {
20
+ //$EM_Event->get_bookings();
21
+ if( $EM_Event->get_bookings()->add( new EM_Booking($_POST) ) ){
22
+ $dbem_form_messages_booking_add['success'] = $EM_Event->get_bookings()->feedback_message;
23
+ }else{
24
+ $dbem_form_messages_booking_add['error'] = implode('<br />', $EM_Event->get_bookings()->errors);
25
+ }
26
+ }
27
+ //DELETE Booking
28
+ if (isset($_POST['eventAction']) && $_POST['eventAction'] == 'delete_booking') {
29
+ $EM_Person = new EM_Person();
30
+ if( $EM_Person->get(array('person_name' => $_POST['person_name'], 'person_email' => $_POST['person_email'])) ){
31
+ $deleted = 0;
32
+ foreach($EM_Event->get_bookings()->bookings as $EM_Booking){
33
+ if($EM_Booking->person->id == $EM_Person->id ){
34
+ $EM_Booking->cancel();
35
+ $deleted++;
36
+ }
37
+ }
38
+ }
39
+ if($deleted > 0){
40
+ $dbem_form_messages_booking_delete['success'] = __('Booking deleted', 'dbem');
41
+ }else{
42
+ $dbem_form_messages_booking_delete['error'] = __('There are no bookings associated to this name and e-mail', 'dbem');
43
+ }
44
+ }
45
+ }
46
+ }
47
+ add_action('init','em_actions_bookings');
48
+
49
+ /**
50
+ * Returns the booking form for the front-end, displayed when using placeholder #_ADDBOOKINGFORM
51
+ * @return string
52
+ */
53
+ function em_add_booking_form() {
54
+ global $dbem_form_messages_booking_add, $EM_Event;
55
+
56
+ $destination = "?".$_SERVER['QUERY_STRING']."#dbem-rsvp";
57
+ $booked_places_options = array();
58
+ for ( $i = 1; $i <= 10; $i++ ) {
59
+ $booking_seats = (!empty($_POST['booking_seats']) && $_POST['booking_seats'] == $i) ? 'selected="selected"':'';
60
+ array_push($booked_places_options, "<option value='$i' $booking_seats>$i</option>");
61
+ }
62
+ ob_start();
63
+ ?>
64
+ <div id="dbem-rsvp">
65
+ <a name="dbem-rsvp"></a>
66
+ <h3><?php _e('Book now!','dbem') ?></h3>
67
+
68
+ <?php if( !empty($dbem_form_messages_booking_add['success']) ) : ?>
69
+ <div class='dbem-rsvp-message-success'><?php echo $dbem_form_messages_booking_add['success'] ?></div>
70
+ <?php elseif( !empty($dbem_form_messages_booking_add['error']) ) : ?>
71
+ <div class='dbem-rsvp-message-error'><?php echo $dbem_form_messages_booking_add['error'] ?></div>
72
+ <?php elseif( !empty($dbem_form_messages_booking_add['message']) ) : ?>
73
+ <div class='dbem-rsvp-message'><?php echo $dbem_form_messages_booking_add['message'] ?></div>
74
+ <?php endif; ?>
75
+
76
+ <form id='dbem-rsvp-form' name='booking-form' method='post' action='<?php echo $destination ?>'>
77
+ <table class='dbem-rsvp-form'>
78
+ <tr><th scope='row'><?php _e('Name', 'dbem') ?>:</th><td><input type='text' name='person_name' value='<?php echo !empty($_POST['person_name']) ? $_POST['person_name'] : ''; ?>'/></td></tr>
79
+ <tr><th scope='row'><?php _e('E-Mail', 'dbem') ?>:</th><td><input type='text' name='person_email' value='<?php echo !empty($_POST['person_email']) ? $_POST['person_email'] : ''; ?>'/></td></tr>
80
+ <tr><th scope='row'><?php _e('Phone number', 'dbem') ?>:</th><td><input type='text' name='person_phone' value='<?php echo !empty($_POST['person_phone']) ? $_POST['person_phone'] : ''; ?>'/></td></tr>
81
+ <tr>
82
+ <th scope='row'><?php _e('Seats', 'dbem') ?>:</th>
83
+ <td>
84
+ <select name='booking_seats' >
85
+ <?php
86
+ foreach($booked_places_options as $option) {
87
+ echo $option ."\n";
88
+ }
89
+ ?>
90
+ </select>
91
+ </td>
92
+ </tr>
93
+ <tr><th scope='row'><?php _e('Comment', 'dbem') ?>:</th><td><textarea name='booking_comment'><?php echo !empty($_POST['booking_comment']) ? $_POST['booking_comment']:'' ?></textarea></td></tr>
94
+ </table>
95
+ <p>
96
+ <input type='submit' value='<?php _e('Send your booking', 'dbem') ?>'/>&nbsp;&nbsp;&nbsp;&nbsp;
97
+ <input type='hidden' name='eventAction' value='add_booking'/>
98
+ <input type='hidden' name='event_id' value='<?php echo $EM_Event->id; ?>'/>
99
+ </p>
100
+ </form>
101
+ </div>
102
+ <script type="text/javascript">
103
+ jQuery(document).ready( function($){
104
+ if( $('#dbem-booking-delete').size() > 0 ){
105
+ var triggerText = '<?php ( !empty($_POST['eventAction']) && $_POST['eventAction'] == 'delete_booking') ? _e('Hide cancellation form', 'dbem') : _e('Cancel a booking', 'dbem'); ?>';
106
+ $('#dbem-rsvp input[type=submit]').after(' <a href="#" id="dbem-booking-cancel">'+triggerText+'</a>');
107
+ if( $('#dbem-booking-cancel').html() == '<?php _e('Cancel a booking', 'dbem'); ?>' ) { $('#dbem-booking-delete').hide(); }
108
+ $('#dbem-booking-cancel').click( function(event){
109
+ event.preventDefault();
110
+ if( $('#dbem-booking-cancel').html() == '<?php _e('Cancel a booking', 'dbem'); ?>' ){
111
+ $('#dbem-booking-cancel').html('<?php _e('Hide cancellation form', 'dbem'); ?>');
112
+ $('#dbem-booking-delete').slideDown();
113
+ }else{
114
+ $('#dbem-booking-cancel').html('<?php _e('Cancel a booking', 'dbem'); ?>');
115
+ $('#dbem-booking-delete').slideUp();
116
+ }
117
+ });
118
+ }
119
+ });
120
+ </script>
121
+ <?php
122
+ return ob_get_clean();
123
+ }
124
+
125
+ /**
126
+ * Booking removal in front end, called by placeholder #_REMOVEBOOKINGFORM
127
+ * @return string
128
+ */
129
+ function em_delete_booking_form() {
130
+ global $dbem_form_messages_booking_delete, $EM_Event;
131
+ $destination = "?".$_SERVER['QUERY_STRING'];
132
+ ob_start();
133
+ ?>
134
+ <div id="dbem-booking-delete">
135
+ <a name="dbem-booking-delete"></a>
136
+ <h3><?php _e('Cancel your booking', 'dbem') ?></h3>
137
+
138
+ <?php if( !empty($dbem_form_messages_booking_delete['success']) ) : ?>
139
+ <div class='dbem-rsvp-message-success'><?php echo $dbem_form_messages_booking_delete['success'] ?></div>
140
+ <?php elseif( !empty($dbem_form_messages_booking_delete['error']) ) : ?>
141
+ <div class='dbem-rsvp-message-erro