Version Description
- fixed events not editing due to new location js
- fixed pro notification
- fixed calendar ajax year switching issue
Download this release
Release Info
Developer | netweblogic |
Plugin | Events Manager |
Version | 4.0.81 |
Comparing to | |
See all releases |
Code changes from version 3.0.98 to 4.0.81
- admin/bookings/em-cancelled.php +136 -132
- admin/bookings/em-confirmed.php +143 -139
- admin/bookings/em-events.php +178 -178
- admin/bookings/em-pending.php +158 -154
- admin/bookings/em-person.php +151 -149
- admin/bookings/em-rejected.php +136 -132
- admin/em-admin.php +218 -284
- admin/em-bookings.php +390 -287
- admin/em-categories.php +210 -176
- admin/em-docs.php +226 -192
- admin/em-event.php +765 -626
- admin/em-events.php +237 -241
- admin/em-help.php +53 -51
- admin/em-locations-search.php +7 -3
- admin/em-locations.php +309 -267
- admin/em-options.php +617 -443
- admin/em-people.php +9 -124
- buddypress/bp-em-activity.php +107 -0
- buddypress/bp-em-admin.php +65 -0
- buddypress/bp-em-core.php +254 -0
- buddypress/bp-em-groups.php +57 -0
- buddypress/bp-em-notifications.php +135 -0
- buddypress/bp-em-templatetags.php +7 -0
- buddypress/screens/attending.php +29 -0
- buddypress/screens/group-events.php +27 -0
- buddypress/screens/my-bookings.php +37 -0
- buddypress/screens/my-events.php +64 -0
- buddypress/screens/my-group-events.php +24 -0
- buddypress/screens/my-locations.php +71 -0
- buddypress/screens/profile.php +54 -0
- buddypress/screens/settings.php +56 -0
- classes/em-booking.php +578 -378
- classes/em-bookings.php +626 -487
- classes/em-calendar.php +316 -366
- classes/em-categories.php +314 -156
- classes/em-category.php +231 -151
- classes/em-event.php +1325 -1005
- classes/em-events.php +360 -253
- classes/em-location.php +367 -306
- classes/em-locations.php +277 -212
- classes/em-mailer.php +79 -79
- classes/em-map.php +0 -60
- classes/em-notices.php +174 -0
- classes/em-object.php +771 -485
- classes/em-people.php +84 -128
- classes/em-permalinks.php +222 -0
- classes/em-person.php +69 -153
- classes/em-recurrence.php +0 -89
- classes/em-ticket-booking.php +209 -0
- classes/em-ticket.php +338 -0
- classes/em-tickets-bookings.php +286 -0
- classes/em-tickets.php +240 -0
- classes/phpmailer/class.phpmailer.php +1506 -1506
- classes/phpmailer/class.smtp.php +1045 -1045
- classes/phpmailer/language/phpmailer.lang-br.php +21 -21
- classes/phpmailer/language/phpmailer.lang-ca.php +21 -21
- classes/phpmailer/language/phpmailer.lang-cz.php +4 -23
admin/bookings/em-cancelled.php
CHANGED
@@ -1,133 +1,137 @@
|
|
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($
|
18 |
-
$
|
19 |
-
}else{
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
<
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
<th class='manage-column' scope='col'>
|
82 |
-
|
83 |
-
|
84 |
-
<th class='manage-column' scope='col'>
|
85 |
-
<th class='manage-column' scope='col'
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
<
|
101 |
-
<td><?php echo $EM_Booking->
|
102 |
-
<td>
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
<?php
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
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 '>
|
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'> </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&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 |
+
$edit_url = em_add_get_params($_SERVER['REQUEST_URI'], array('booking_id'=>$EM_Booking->id));
|
110 |
+
?>
|
111 |
+
<a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Restore','dbem'); ?></a> |
|
112 |
+
<a class="em-bookings-edit" href="<?php echo $edit_url; ?>"><?php _e('Edit/View','dbem'); ?></a> |
|
113 |
+
<a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a>
|
114 |
+
</td>
|
115 |
+
</tr>
|
116 |
+
<?php
|
117 |
+
}
|
118 |
+
$event_count++;
|
119 |
+
}
|
120 |
+
?>
|
121 |
+
</tbody>
|
122 |
+
</table>
|
123 |
+
</div>
|
124 |
+
<?php else: ?>
|
125 |
+
<?php _e('No cancelled bookings.', 'dbem'); ?>
|
126 |
+
<?php endif; ?>
|
127 |
+
</form>
|
128 |
+
<?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
|
129 |
+
<div class='tablenav'>
|
130 |
+
<?php echo $bookings_nav; ?>
|
131 |
+
<div class="clear"></div>
|
132 |
+
</div>
|
133 |
+
<?php endif; ?>
|
134 |
+
</div>
|
135 |
+
<?php
|
136 |
+
}
|
137 |
?>
|
admin/bookings/em-confirmed.php
CHANGED
@@ -1,140 +1,144 @@
|
|
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($
|
19 |
-
$
|
20 |
-
}else{
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
<
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
<th class='manage-column' scope='col'>
|
83 |
-
|
84 |
-
|
85 |
-
<th class='manage-column' scope='col'>
|
86 |
-
<th class='manage-column' scope='col'
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
<
|
102 |
-
<td><?php echo $EM_Booking->
|
103 |
-
<td>
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
<?php
|
114 |
-
<a class="em-bookings-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
<?php
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
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 '>
|
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'> </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&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 |
+
$edit_url = em_add_get_params($_SERVER['REQUEST_URI'], array('booking_id'=>$EM_Booking->id));
|
112 |
+
?>
|
113 |
+
<?php if( current_user_can('manage_bookings') && get_option('dbem_bookings_approval') ): ?>
|
114 |
+
<a class="em-bookings-unapprove" href="<?php echo $unapprove_url ?>"><?php _e('Unapprove','dbem'); ?></a> |
|
115 |
+
<?php else: ?>
|
116 |
+
<a class="em-bookings-reject" href="<?php echo $reject_url ?>"><?php _e('Reject','dbem'); ?></a> |
|
117 |
+
<?php endif; ?>
|
118 |
+
<span class="trash"><a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a></span> |
|
119 |
+
<a class="em-bookings-edit" href="<?php echo $edit_url; ?>"><?php _e('Edit/View','dbem'); ?></a>
|
120 |
+
</td>
|
121 |
+
</tr>
|
122 |
+
<?php
|
123 |
+
}
|
124 |
+
$event_count++;
|
125 |
+
}
|
126 |
+
?>
|
127 |
+
</tbody>
|
128 |
+
</table>
|
129 |
+
</div>
|
130 |
+
<?php else: ?>
|
131 |
+
<?php _e('No confirmed bookings.', 'dbem'); ?>
|
132 |
+
<?php endif; ?>
|
133 |
+
</form>
|
134 |
+
<?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
|
135 |
+
<div class='tablenav'>
|
136 |
+
<?php echo $bookings_nav; ?>
|
137 |
+
<div class="clear"></div>
|
138 |
+
</div>
|
139 |
+
<?php endif; ?>
|
140 |
+
</div>
|
141 |
+
<?php
|
142 |
+
|
143 |
+
}
|
144 |
?>
|
admin/bookings/em-events.php
CHANGED
@@ -1,179 +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 |
-
$
|
39 |
-
$
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
<option value="
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
$events_nav = em_admin_paginate( $
|
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 |
-
|
132 |
-
</strong>
|
133 |
-
–
|
134 |
-
<?php _e("Booked
|
135 |
-
<?php if( get_option('dbem_bookings_approval') == 1 ) : ?>
|
136 |
-
| <?php _e("Pending",'dbem') ?>: <?php echo $event->get_bookings()->
|
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 |
-
–
|
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 |
-
|
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 |
?>
|
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 |
+
$owner = !current_user_can('edit_others_events') ? get_current_user_id() : false;
|
39 |
+
$events = EM_Events::get( array('scope'=>$scope, 'limit'=>0, 'order'=>$order, 'rsvp'=>true, 'owner' => $owner ) );
|
40 |
+
$events_count = count ( $events );
|
41 |
+
|
42 |
+
$use_events_end = get_option ( 'dbem_use_event_end' );
|
43 |
+
?>
|
44 |
+
<div class="wrap em_bookings_events_table em_obj">
|
45 |
+
<form id="posts-filter" action="" method="get">
|
46 |
+
<input type="hidden" name="em_obj" value="em_bookings_events_table" />
|
47 |
+
<?php if(!empty($_GET['page'])): ?>
|
48 |
+
<input type='hidden' name='page' value='events-manager-bookings' />
|
49 |
+
<?php endif; ?>
|
50 |
+
<ul class="subsubsub">
|
51 |
+
<li><a href='#' class="current"><?php _e ( 'Total', 'dbem' ); ?> <span class="count">(<?php echo (count ( $events )); ?>)</span></a></li>
|
52 |
+
</ul>
|
53 |
+
<div class="tablenav">
|
54 |
+
<div class="alignleft actions">
|
55 |
+
<!--
|
56 |
+
<select name="action">
|
57 |
+
<option value="-1" selected="selected"><?php _e ( 'Bulk Actions' ); ?></option>
|
58 |
+
<option value="deleteEvents"><?php _e ( 'Delete selected','dbem' ); ?></option>
|
59 |
+
</select>
|
60 |
+
<input type="submit" value="<?php _e ( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
|
61 |
+
-->
|
62 |
+
<select name="scope">
|
63 |
+
<?php
|
64 |
+
foreach ( $scope_names as $key => $value ) {
|
65 |
+
$selected = "";
|
66 |
+
if ($key == $scope)
|
67 |
+
$selected = "selected='selected'";
|
68 |
+
echo "<option value='$key' $selected>$value</option> ";
|
69 |
+
}
|
70 |
+
?>
|
71 |
+
</select>
|
72 |
+
<input id="post-query-submit" class="button-secondary" type="submit" value="<?php _e ( 'Filter' )?>" />
|
73 |
+
</div>
|
74 |
+
<!--
|
75 |
+
<div class="view-switch">
|
76 |
+
<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>
|
77 |
+
</div>
|
78 |
+
-->
|
79 |
+
<?php
|
80 |
+
if ( $events_count >= $limit ) {
|
81 |
+
$events_nav = em_admin_paginate( $events_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_events_table'));
|
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 |
+
<?php echo $event->output('#_BOOKINGSLINK'); ?>
|
132 |
+
</strong>
|
133 |
+
–
|
134 |
+
<?php _e("Booked Spaces",'dbem') ?>: <?php echo $event->get_bookings()->get_booked_spaces()."/".$event->get_spaces() ?>
|
135 |
+
<?php if( get_option('dbem_bookings_approval') == 1 ) : ?>
|
136 |
+
| <?php _e("Pending",'dbem') ?>: <?php echo $event->get_bookings()->get_pending_spaces(); ?>
|
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 |
+
–
|
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) && $events_count >= $limit ) : ?>
|
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,155 +1,159 @@
|
|
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($
|
24 |
-
$
|
25 |
-
}else{
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
<
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
<th class='manage-column' scope='col'>
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
<th class='manage-column' scope=
|
102 |
-
|
103 |
-
<th class='manage-column' scope='col'
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
<
|
119 |
-
<?php
|
120 |
-
|
121 |
-
<td><?php echo $EM_Booking->
|
122 |
-
|
123 |
-
<td>
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
</
|
150 |
-
<?php
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
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 '>
|
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'> </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&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&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&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 |
?>
|
admin/bookings/em-person.php
CHANGED
@@ -1,150 +1,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 =
|
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 |
-
$
|
71 |
-
$bookings_nav
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
<
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
</th>
|
87 |
-
<th class='manage-column' scope='col'>
|
88 |
-
<th class='manage-column' scope='col'>
|
89 |
-
<th class='manage-column' scope='col'
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
$
|
96 |
-
$
|
97 |
-
|
98 |
-
$EM_Event
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
<
|
104 |
-
<td
|
105 |
-
<td><?php echo $EM_Booking->
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
$
|
111 |
-
$
|
112 |
-
$
|
113 |
-
|
114 |
-
?>
|
115 |
-
<?php
|
116 |
-
|
117 |
-
<?php
|
118 |
-
<?php
|
119 |
-
|
120 |
-
<?php
|
121 |
-
<?php
|
122 |
-
|
123 |
-
<?php
|
124 |
-
<a class="em-bookings-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
<?php
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
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 '>
|
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'> </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&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', 'booking_id'=>$EM_Booking->id));
|
110 |
+
$approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'booking_id'=>$EM_Booking->id));
|
111 |
+
$reject_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_reject', 'booking_id'=>$EM_Booking->id));
|
112 |
+
$delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$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&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 |
?>
|
admin/bookings/em-rejected.php
CHANGED
@@ -1,133 +1,137 @@
|
|
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($
|
18 |
-
$
|
19 |
-
}else{
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
<
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
<th class='manage-column' scope='col'>
|
82 |
-
|
83 |
-
|
84 |
-
<th class='manage-column' scope='col'>
|
85 |
-
<th class='manage-column' scope='col'
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
<
|
101 |
-
<td><?php echo $EM_Booking->
|
102 |
-
<td>
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
<?php
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
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 '>
|
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'> </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&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 |
+
$edit_url = em_add_get_params($_SERVER['REQUEST_URI'], array('booking_id'=>$EM_Booking->id));
|
110 |
+
?>
|
111 |
+
<a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Approve','dbem'); ?></a> |
|
112 |
+
<a class="em-bookings-edit" href="<?php echo $edit_url ?>"><?php _e('Edit/View','dbem'); ?></a> |
|
113 |
+
<span class="trash"><a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','dbem'); ?></a></span>
|
114 |
+
</td>
|
115 |
+
</tr>
|
116 |
+
<?php
|
117 |
+
}
|
118 |
+
$event_count++;
|
119 |
+
}
|
120 |
+
?>
|
121 |
+
</tbody>
|
122 |
+
</table>
|
123 |
+
</div>
|
124 |
+
<?php else: ?>
|
125 |
+
<?php _e('No rejected bookings.', 'dbem'); ?>
|
126 |
+
<?php endif; ?>
|
127 |
+
</form>
|
128 |
+
<?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
|
129 |
+
<div class='tablenav'>
|
130 |
+
<?php echo $bookings_nav; ?>
|
131 |
+
<div class="clear"></div>
|
132 |
+
</div>
|
133 |
+
<?php endif; ?>
|
134 |
+
</div>
|
135 |
+
<?php
|
136 |
+
}
|
137 |
?>
|
admin/em-admin.php
CHANGED
@@ -1,285 +1,219 @@
|
|
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 ) ? '&':'?';
|
11 |
-
|
12 |
-
if(
|
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 |
-
//
|
32 |
-
if(
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
<
|
58 |
-
</
|
59 |
-
|
60 |
-
|
61 |
-
}
|
62 |
-
|
63 |
-
//If events page couldn't be created
|
64 |
-
if( !empty($_GET['em_dismiss_events_page']) ){
|
65 |
-
update_option('dbem_dismiss_events_page',1);
|
66 |
-
}else{
|
67 |
-
if ( !get_page($events_page_id) && !get_option('dbem_dismiss_events_page') ){
|
68 |
-
?>
|
69 |
-
<div id="em_page_error" class="updated">
|
70 |
-
<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>
|
71 |
-
</div>
|
72 |
-
<?php
|
73 |
-
}
|
74 |
-
}
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
//
|
117 |
-
if(
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
//
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
else
|
220 |
-
$('input.row-selector').attr('checked', false);
|
221 |
-
});
|
222 |
-
|
223 |
-
updateIntervalDescriptor();
|
224 |
-
updateIntervalSelectors();
|
225 |
-
updateShowHideRecurrence();
|
226 |
-
updateShowHideRsvp();
|
227 |
-
$('input#event-recurrence').change(updateShowHideRecurrence);
|
228 |
-
$('input#rsvp-checkbox').change(updateShowHideRsvp);
|
229 |
-
|
230 |
-
// recurrency elements
|
231 |
-
$('input#recurrence-interval').keyup(updateIntervalDescriptor);
|
232 |
-
$('select#recurrence-frequency').change(updateIntervalDescriptor);
|
233 |
-
$('select#recurrence-frequency').change(updateIntervalSelectors);
|
234 |
-
|
235 |
-
// hiding or showing notes according to their content
|
236 |
-
$('.postbox h3').prepend('<a class="togbox">+</a> ');
|
237 |
-
$('#event_notes h3').click( function() {
|
238 |
-
$(this).parent().first().toggleClass('closed');
|
239 |
-
});
|
240 |
-
|
241 |
-
// users cannot submit the event form unless some fields are filled
|
242 |
-
function validateEventForm(){
|
243 |
-
errors = "";
|
244 |
-
var recurring = $("input[@name=repeated_event]:checked").val();
|
245 |
-
requiredFields= new Array('event_name', 'localised_event_date', 'location_name','location_address','location_town');
|
246 |
-
var localisedRequiredFields = {
|
247 |
-
'event_name':"<?php _e ( 'Name', 'dbem' )?>",
|
248 |
-
'localised_event_date':"<?php _e ( 'Date', 'dbem' )?>",
|
249 |
-
'location_name':"<?php _e ( 'Location', 'dbem' )?>",
|
250 |
-
'location_address':"<?php _e ( 'Address', 'dbem' )?>",
|
251 |
-
'location_town':"<?php _e ( 'Town', 'dbem' )?>"
|
252 |
-
};
|
253 |
-
missingFields = new Array;
|
254 |
-
for (var i in requiredFields) {
|
255 |
-
if ($("input[@name=" + requiredFields[i]+ "]").val() == 0) {
|
256 |
-
missingFields.push(localisedRequiredFields[requiredFields[i]]);
|
257 |
-
$("input[@name=" + requiredFields[i]+ "]").css('border','2px solid red');
|
258 |
-
} else {
|
259 |
-
$("input[@name=" + requiredFields[i]+ "]").css('border','1px solid #DFDFDF');
|
260 |
-
}
|
261 |
-
}
|
262 |
-
|
263 |
-
// alert('ciao ' + recurring+ " end: " + $("input[@name=localised_event_end_date]").val());
|
264 |
-
if (missingFields.length > 0) {
|
265 |
-
errors = "<?php _e ( 'Some required fields are missing:', 'dbem' )?> " + missingFields.join(", ") + ".\n";
|
266 |
-
}
|
267 |
-
if(recurring && $("input[@name=localised_event_end_date]").val() == "") {
|
268 |
-
errors = errors + "<?php _e ( 'Since the event is repeated, you must specify an end date', 'dbem' )?>.";
|
269 |
-
$("input[@name=localised_event_end_date]").css('border','2px solid red');
|
270 |
-
} else {
|
271 |
-
$("input[@name=localised_event_end_date]").css('border','1px solid #DFDFDF');
|
272 |
-
}
|
273 |
-
if(errors != "") {
|
274 |
-
alert(errors);
|
275 |
-
return false;
|
276 |
-
}
|
277 |
-
return true;
|
278 |
-
}
|
279 |
-
$('#event-form').bind("submit", validateEventForm);
|
280 |
-
});
|
281 |
-
//]]>
|
282 |
-
</script>
|
283 |
-
<?php
|
284 |
-
}
|
285 |
?>
|
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 ) ? '&':'?';
|
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 |
+
//Image upload folders
|
32 |
+
if( is_admin() && EM_IMAGE_DS == '/' ){
|
33 |
+
$errs = array();
|
34 |
+
if( is_writable(EM_IMAGE_UPLOAD_DIR) || @mkdir(EM_IMAGE_UPLOAD_DIR, 0777)){
|
35 |
+
if( !is_writable(EM_IMAGE_UPLOAD_DIR.'/events/') && !@mkdir(EM_IMAGE_UPLOAD_DIR."events/", 0777) ){ $errs[] = 'events'; }
|
36 |
+
if( !is_writable(EM_IMAGE_UPLOAD_DIR.'/locations/') && !@mkdir(EM_IMAGE_UPLOAD_DIR."locations/", 0777) ){ $errs[] = 'locations'; }
|
37 |
+
if( !is_writable(EM_IMAGE_UPLOAD_DIR.'/categories/') && !@mkdir(EM_IMAGE_UPLOAD_DIR."categories/", 0777) ){ $errs[] = 'categories'; }
|
38 |
+
}elseif( !is_writable(EM_IMAGE_UPLOAD_DIR) ){
|
39 |
+
$errs = array('events','categories','locations');
|
40 |
+
}
|
41 |
+
if( count($errs) > 0 ){
|
42 |
+
?>
|
43 |
+
<div class="updated">
|
44 |
+
<p><?php echo sprintf(__('The upload directory '.EM_IMAGE_UPLOAD_DIR.' is must be present with these writeable folders: %s. Please create these folders with the same write permissions you use for your normal wordpress image upload folders.','dbem'),implode(', ',$errs)); ?></p>
|
45 |
+
</div>
|
46 |
+
<?php
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
//If events page couldn't be created
|
51 |
+
if( !empty($_GET['em_dismiss_admin_notice']) ){
|
52 |
+
delete_option('dbem_admin_notice_'.$_GET['em_dismiss_admin_notice']);
|
53 |
+
}else{
|
54 |
+
if ( get_option('dbem_admin_notice_3.0.91') ){
|
55 |
+
?>
|
56 |
+
<div class="updated">
|
57 |
+
<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>
|
58 |
+
</div>
|
59 |
+
<?php
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
//If events page couldn't be created
|
64 |
+
if( !empty($_GET['em_dismiss_events_page']) ){
|
65 |
+
update_option('dbem_dismiss_events_page',1);
|
66 |
+
}else{
|
67 |
+
if ( !get_page($events_page_id) && !get_option('dbem_dismiss_events_page') ){
|
68 |
+
?>
|
69 |
+
<div id="em_page_error" class="updated">
|
70 |
+
<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>
|
71 |
+
</div>
|
72 |
+
<?php
|
73 |
+
}
|
74 |
+
}
|
75 |
+
//If events page couldn't be created
|
76 |
+
if( !empty($_GET['em_dismiss_notice_migrate_v3']) ){
|
77 |
+
delete_option('em_notice_migrate_v3');
|
78 |
+
}else{
|
79 |
+
if( get_option('em_notice_migrate_v3') ){
|
80 |
+
?>
|
81 |
+
<div id="em_page_error" class="updated">
|
82 |
+
<p><?php echo sprintf ( __( 'A <strong>LOT</strong> has changed since Events Manager 3. We recommend you take a look at the <a href="%s">settings page</a> for new features and upgrade instructions, and you may particualarly be interested in modifying permissions. <a href="%s">Dismiss</a>' ), 'admin.php?page=events-manager-options', em_add_get_params($_SERVER['REQUEST_URI'], array('em_dismiss_notice_migrate_v3'=>1))); ?></p>
|
83 |
+
</div>
|
84 |
+
<?php
|
85 |
+
}
|
86 |
+
}
|
87 |
+
//Fixing the RC2 fiasco
|
88 |
+
if( !empty($_GET['em_dismiss_notice_rc_reimport']) ){
|
89 |
+
delete_option('dbem_notice_rc_reimport');
|
90 |
+
}else{
|
91 |
+
if( get_option('dbem_notice_rc_reimport') ){
|
92 |
+
?>
|
93 |
+
<div id="em_page_error" class="updated">
|
94 |
+
<p><?php echo sprintf ( __( 'If you upgraded from 3.x to the RC2 and the update did not go so well, <a href="%s">try reimporting old settings</a>. Warning! Re-importing will rename all event slugs, re-import your old category settings from events, and recreate all tickets, so changes to these areas will be lost. <a href="%s">Dismiss</a>' ), 'admin.php?page=events-manager-options&action=em_rc_reimport&_wpnonce='.wp_create_nonce('em_rc_reimport'), em_add_get_params($_SERVER['REQUEST_URI'], array('em_dismiss_notice_rc_reimport'=>1))); ?></p>
|
95 |
+
</div>
|
96 |
+
<?php
|
97 |
+
}
|
98 |
+
}
|
99 |
+
if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'em_rc_reimport' && wp_verify_nonce($_REQUEST['_wpnonce'], 'em_rc_reimport') ){
|
100 |
+
require_once( dirname(__FILE__).'/../em-install.php');
|
101 |
+
em_migrate_v3();
|
102 |
+
?>
|
103 |
+
<div id="em_page_error" class="updated">
|
104 |
+
<p>Reimporting old settings was successful. Click the dismiss button on the other notification if after checking things are now working.</p>
|
105 |
+
</div>
|
106 |
+
<?php
|
107 |
+
}
|
108 |
+
|
109 |
+
if( defined('EMP_VERSION') && EMP_VERSION < EM_PRO_MIN_VERSION ){?>
|
110 |
+
<div id="em_page_error" class="updated">
|
111 |
+
<p>There is a newer version of Events Manager Pro which is required for this current version of Events Manager. Please go to the plugin website and download the latest update.</p>
|
112 |
+
</div>
|
113 |
+
<?php
|
114 |
+
}
|
115 |
+
}
|
116 |
+
//Warn about EM page edit
|
117 |
+
if ( preg_match( '/(post|page).php/', $_SERVER ['SCRIPT_NAME']) && isset ( $_GET ['action'] ) && $_GET ['action'] == 'edit' && isset ( $_GET ['post'] ) && $_GET ['post'] == "$events_page_id") {
|
118 |
+
$message = sprintf ( __ ( "This page corresponds to <strong>Events Manager</strong> events page. Its content will be overriden by Events Manager, although if you include the word CONTENTS (exactly in capitals) and surround it with other text, only CONTENTS will be overwritten. If you want to change the way your events look, go to the <a href='%s'>settings</a> page. ", 'dbem' ), 'admin.php?page=events-manager-options' );
|
119 |
+
$notice = "<div class='error'><p>$message</p></div>";
|
120 |
+
echo $notice;
|
121 |
+
}
|
122 |
+
|
123 |
+
}
|
124 |
+
add_action ( 'admin_notices', 'em_admin_warnings' );
|
125 |
+
|
126 |
+
/**
|
127 |
+
* 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.
|
128 |
+
* @param string $link
|
129 |
+
* @param int $total
|
130 |
+
* @param int $limit
|
131 |
+
* @param int $page
|
132 |
+
* @param int $pagesToShow
|
133 |
+
* @return string
|
134 |
+
* @uses em_paginate()
|
135 |
+
*/
|
136 |
+
function em_admin_paginate($total, $limit, $page=1, $vars=false){
|
137 |
+
$return = '<div class="tablenav-pages">';
|
138 |
+
$events_nav = paginate_links( array(
|
139 |
+
'base' => add_query_arg( 'pno', '%#%' ),
|
140 |
+
'format' => '',
|
141 |
+
'total' => ceil($total / $limit),
|
142 |
+
'current' => $page,
|
143 |
+
'add_args' => $vars
|
144 |
+
));
|
145 |
+
$return .= sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s',
|
146 |
+
number_format_i18n( ( $page - 1 ) * $limit + 1 ),
|
147 |
+
number_format_i18n( min( $page * $limit, $total ) ),
|
148 |
+
number_format_i18n( $total ),
|
149 |
+
$events_nav
|
150 |
+
);
|
151 |
+
$return .= '</div>';
|
152 |
+
return $return;
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Called by admin_print_scripts-(hook|page) action, created when adding menu items in events-manager.php
|
157 |
+
*/
|
158 |
+
function em_admin_load_scripts(){
|
159 |
+
//Load the UI items, currently date picker and autocomplete plus dependencies
|
160 |
+
//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'));
|
161 |
+
wp_enqueue_script('events-manager', WP_PLUGIN_URL.'/events-manager/includes/js/events-manager.js', array('jquery', 'jquery-ui-core','jquery-ui-widget','jquery-ui-position'));
|
162 |
+
|
163 |
+
//Add maps
|
164 |
+
if( get_option('dbem_gmap_is_active') ){
|
165 |
+
wp_enqueue_script('em-google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
|
166 |
+
}
|
167 |
+
//Time Entry
|
168 |
+
wp_enqueue_script('em-timeentry', WP_PLUGIN_URL.'/events-manager/includes/js/timeentry/jquery.timeentry.js', array('jquery'));
|
169 |
+
|
170 |
+
if( is_admin() ){
|
171 |
+
//TinyMCE Editor
|
172 |
+
remove_filter('the_editor', 'qtrans_modifyRichEditor'); //qtranslate filter
|
173 |
+
if( function_exists('wp_tiny_mce')) add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
|
174 |
+
if( function_exists('wp_tiny_mce_preload_dialogs')) add_action( 'admin_print_footer_scripts', 'wp_tiny_mce_preload_dialogs', 30 );
|
175 |
+
wp_enqueue_script('post');
|
176 |
+
if ( user_can_richedit() )
|
177 |
+
wp_enqueue_script('editor');
|
178 |
+
|
179 |
+
add_thickbox();
|
180 |
+
wp_enqueue_script('media-upload');
|
181 |
+
wp_enqueue_script('word-count');
|
182 |
+
wp_enqueue_script('quicktags');
|
183 |
+
}
|
184 |
+
em_js_localize_vars();
|
185 |
+
}
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Called by admin_print_styles-(hook|page) action, created when adding menu items in events-manager.php
|
189 |
+
*/
|
190 |
+
function em_admin_load_styles() {
|
191 |
+
add_thickbox();
|
192 |
+
wp_enqueue_style('em-ui-css', WP_PLUGIN_URL.'/events-manager/includes/css/jquery-ui-1.8.13.custom.css');
|
193 |
+
wp_enqueue_style('events-manager-admin', WP_PLUGIN_URL.'/events-manager/includes/css/events_manager_admin.css');
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Loads script inline due to insertion of php values
|
198 |
+
*/
|
199 |
+
function em_admin_general_script() {
|
200 |
+
//TODO clean script up, remove dependency of php so it can be moved to js file.
|
201 |
+
// Check if the locale is there and loads it
|
202 |
+
$locale_code = substr ( get_locale (), 0, 2 );
|
203 |
+
$show24Hours = 'true';
|
204 |
+
// Setting 12 hours format for those countries using it
|
205 |
+
if (preg_match ( "/en|sk|zh|us|uk/", $locale_code ))
|
206 |
+
$show24Hours = 'false';
|
207 |
+
?>
|
208 |
+
<script type="text/javascript">
|
209 |
+
//<![CDATA[
|
210 |
+
// TODO: make more general, to support also latitude and longitude (when added)
|
211 |
+
jQuery(document).ready( function($) {
|
212 |
+
$("#start-time").timeEntry({spinnerImage: '', show24Hours: <?php echo $show24Hours; ?> });
|
213 |
+
$("#end-time").timeEntry({spinnerImage: '', show24Hours: <?php echo $show24Hours; ?>});
|
214 |
+
});
|
215 |
+
//]]>
|
216 |
+
</script>
|
217 |
+
<?php
|
218 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
?>
|
admin/em-bookings.php
CHANGED
@@ -1,288 +1,391 @@
|
|
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 |
-
|
25 |
-
}else{
|
26 |
-
|
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(
|
48 |
-
if( $_REQUEST['action'] == '
|
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 |
-
}
|
68 |
-
|
69 |
-
}
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
<p>
|
128 |
-
|
129 |
-
<
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
<h2><?php _e('
|
141 |
-
<?php
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
<
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
<
|
234 |
-
<?php
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
?>
|
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, $EM_Notices;
|
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 |
+
$EM_Notices->add_confirm($EM_Booking->feedback_message);
|
25 |
+
}else{
|
26 |
+
$EM_Notices->add_error($EM_Booking->feedback_message);
|
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( is_object($EM_Event) && !empty($_REQUEST['action']) ){
|
48 |
+
if( $_REQUEST['action'] == 'bookings_export_csv' && wp_verify_nonce($_REQUEST['_wpnonce'],'bookings_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 |
+
global $EM_Notices;
|
79 |
+
?>
|
80 |
+
<div class='wrap'>
|
81 |
+
<div id='icon-users' class='icon32'>
|
82 |
+
<br/>
|
83 |
+
</div>
|
84 |
+
<h2>
|
85 |
+
<?php _e('Event Bookings Dashboard', 'dbem'); ?>
|
86 |
+
</h2>
|
87 |
+
<?php echo $EM_Notices; ?>
|
88 |
+
<?php if( get_option('dbem_bookings_approval')): ?>
|
89 |
+
<h2><?php _e('Pending Bookings','dbem'); ?></h2>
|
90 |
+
<?php em_bookings_pending_table(); ?>
|
91 |
+
<?php endif; ?>
|
92 |
+
<h2><?php _e('Events With Bookings Enabled','dbem'); ?></h2>
|
93 |
+
<?php em_bookings_events_table(); ?>
|
94 |
+
<?php do_action('em_bookings_dashboard'); ?>
|
95 |
+
</div>
|
96 |
+
<?php
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Shows all booking data for a single event
|
101 |
+
*/
|
102 |
+
function em_bookings_event(){
|
103 |
+
global $EM_Event,$EM_Person,$EM_Notices;
|
104 |
+
//check that user can access this page
|
105 |
+
if( is_object($EM_Event) && !$EM_Event->can_manage('manage_bookings','manage_others_bookings') ){
|
106 |
+
?>
|
107 |
+
<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>
|
108 |
+
<?php
|
109 |
+
return false;
|
110 |
+
}
|
111 |
+
$localised_start_date = date_i18n('D d M Y', $EM_Event->start);
|
112 |
+
$localised_end_date = date_i18n('D d M Y', $EM_Event->end);
|
113 |
+
?>
|
114 |
+
<div class='wrap'>
|
115 |
+
<div id='icon-users' class='icon32'>
|
116 |
+
<br/>
|
117 |
+
</div>
|
118 |
+
<h2>
|
119 |
+
<?php echo sprintf(__('Manage %s Bookings', 'dbem'), "'{$EM_Event->name}'"); ?>
|
120 |
+
<a href="<?php echo $EM_Event->output('#_EDITEVENTURL'); ?>" class="button add-new-h2"><?php _e('View/Edit Event','dbem') ?></a>
|
121 |
+
<?php do_action('em_admin_event_booking_options_buttons'); ?>
|
122 |
+
</h2>
|
123 |
+
<?php echo $EM_Notices; ?>
|
124 |
+
<div><a href='<?php echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&action=bookings_export_csv&_wpnonce=".wp_create_nonce('bookings_export_csv')."&event_id=".$EM_Event->id ?>'><?php _e('export csv','dbem')?></a></div>
|
125 |
+
<div>
|
126 |
+
<p><strong><?php _e('Event Name','dbem'); ?></strong> : <?php echo ($EM_Event->name); ?></p>
|
127 |
+
<p><strong>Availability :</strong> <?php echo $EM_Event->get_bookings()->get_booked_spaces() . '/'. $EM_Event->get_spaces() ." ". __('Spaces confirmed','dbem'); ?></p>
|
128 |
+
<p>
|
129 |
+
<strong><?php _e('Date','dbem'); ?></strong> :
|
130 |
+
<?php echo $localised_start_date; ?>
|
131 |
+
<?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
|
132 |
+
<?php echo substr ( $EM_Event->start_time, 0, 5 ) . " - " . substr ( $EM_Event->end_time, 0, 5 ); ?>
|
133 |
+
</p>
|
134 |
+
<p>
|
135 |
+
<strong><?php _e('Location','dbem'); ?></strong> :
|
136 |
+
<a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-locations&location_id=<?php echo $EM_Event->location->id ?>"><?php echo ($EM_Event->location->name); ?></a>
|
137 |
+
</p>
|
138 |
+
</div>
|
139 |
+
<?php if( get_option('dbem_bookings_approval')): ?>
|
140 |
+
<h2><?php _e('Pending Bookings','dbem'); ?></h2>
|
141 |
+
<?php em_bookings_pending_table(); ?>
|
142 |
+
<?php endif; ?>
|
143 |
+
<h2><?php _e('Confirmed Bookings','dbem'); ?></h2>
|
144 |
+
<?php em_bookings_confirmed_table(); ?>
|
145 |
+
<h2><?php _e('Rejected Bookings','dbem'); ?></h2>
|
146 |
+
<?php em_bookings_rejected_table(); ?>
|
147 |
+
<h2><?php _e('Cancelled Bookings','dbem'); ?></h2>
|
148 |
+
<?php em_bookings_cancelled_table(); ?>
|
149 |
+
<?php do_action('em_bookings_event_footer', $EM_Event); ?>
|
150 |
+
</div>
|
151 |
+
<?php
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Shows a ticket view
|
156 |
+
*/
|
157 |
+
function em_bookings_ticket(){
|
158 |
+
global $EM_Ticket,$EM_Notices;
|
159 |
+
$EM_Event = $EM_Ticket->get_event();
|
160 |
+
//check that user can access this page
|
161 |
+
if( is_object($EM_Ticket) && !$EM_Ticket->can_manage() ){
|
162 |
+
?>
|
163 |
+
<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>
|
164 |
+
<?php
|
165 |
+
return false;
|
166 |
+
}
|
167 |
+
?>
|
168 |
+
<div class='wrap'>
|
169 |
+
<div id='icon-users' class='icon32'>
|
170 |
+
<br/>
|
171 |
+
</div>
|
172 |
+
<h2>
|
173 |
+
<?php echo sprintf(__('Ticket for %s', 'dbem'), "'{$EM_Event->name}'"); ?>
|
174 |
+
<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>
|
175 |
+
<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>
|
176 |
+
</h2>
|
177 |
+
<?php echo $EM_Notices; ?>
|
178 |
+
<div>
|
179 |
+
<table>
|
180 |
+
<tr><td><?php echo __('Name','dbem'); ?></td><td></td><td><?php echo $EM_Ticket->name; ?></td></tr>
|
181 |
+
<tr><td><?php echo __('Description','dbem'); ?> </td><td></td><td><?php echo ($EM_Ticket->description) ? $EM_Ticket->description : '-'; ?></td></tr>
|
182 |
+
<tr><td><?php echo __('Price','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->price) ? $EM_Ticket->price : '-'; ?></td></tr>
|
183 |
+
<tr><td><?php echo __('Spaces','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->spaces) ? $EM_Ticket->spaces : '-'; ?></td></tr>
|
184 |
+
<tr><td><?php echo __('Min','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->min) ? $EM_Ticket->min : '-'; ?></td></tr>
|
185 |
+
<tr><td><?php echo __('Max','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->max) ? $EM_Ticket->max : '-'; ?></td></tr>
|
186 |
+
<tr><td><?php echo __('Start','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->start) ? $EM_Ticket->start : '-'; ?></td></tr>
|
187 |
+
<tr><td><?php echo __('End','dbem'); ?></td><td></td><td><?php echo ($EM_Ticket->end) ? $EM_Ticket->end : '-'; ?></td></tr>
|
188 |
+
</table>
|
189 |
+
</div>
|
190 |
+
<?php if( get_option('dbem_bookings_approval')): ?>
|
191 |
+
<h2><?php _e('Pending Bookings','dbem'); ?></h2>
|
192 |
+
<?php em_bookings_pending_table(); ?>
|
193 |
+
<?php endif; ?>
|
194 |
+
<h2><?php _e('Confirmed Bookings','dbem'); ?></h2>
|
195 |
+
<?php em_bookings_confirmed_table(); ?>
|
196 |
+
<h2><?php _e('Rejected Bookings','dbem'); ?></h2>
|
197 |
+
<?php em_bookings_rejected_table(); ?>
|
198 |
+
<h2><?php _e('Cancelled Bookings','dbem'); ?></h2>
|
199 |
+
<?php em_bookings_cancelled_table(); ?>
|
200 |
+
<?php do_action('em_bookings_ticket_footer', $EM_Ticket); ?>
|
201 |
+
</div>
|
202 |
+
<?php
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Shows a single booking for a single person.
|
207 |
+
*/
|
208 |
+
function em_bookings_single(){
|
209 |
+
global $EM_Booking, $EM_Notices;
|
210 |
+
//check that user can access this page
|
211 |
+
if( is_object($EM_Booking) && !$EM_Booking->can_manage() ){
|
212 |
+
?>
|
213 |
+
<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>
|
214 |
+
<?php
|
215 |
+
return false;
|
216 |
+
}
|
217 |
+
?>
|
218 |
+
<div class='wrap'>
|
219 |
+
<div id='icon-users' class='icon32'>
|
220 |
+
<br/>
|
221 |
+
</div>
|
222 |
+
<h2>
|
223 |
+
<?php _e('Edit Booking', 'dbem'); ?>
|
224 |
+
</h2>
|
225 |
+
<?php echo $EM_Notices; ?>
|
226 |
+
<div id="poststuff" class="metabox-holder">
|
227 |
+
<div id="post-body">
|
228 |
+
<div id="post-body-content">
|
229 |
+
<div id="em-booking-details" class="stuffbox">
|
230 |
+
<h3>
|
231 |
+
<?php _e ( 'Event Details', 'dbem' ); ?>
|
232 |
+
</h3>
|
233 |
+
<div class="inside">
|
234 |
+
<?php
|
235 |
+
$EM_Event = $EM_Booking->get_event();
|
236 |
+
$localised_start_date = date_i18n('D d M Y', $EM_Event->start);
|
237 |
+
$localised_end_date = date_i18n('D d M Y', $EM_Event->end);
|
238 |
+
?>
|
239 |
+
<table>
|
240 |
+
<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&event_id=<?php echo $EM_Event->id ?>"><?php echo ($EM_Event->name); ?></a></td></tr>
|
241 |
+
<tr>
|
242 |
+
<td><strong><?php _e('Date/Time','dbem'); ?> </strong></td>
|
243 |
+
<td>
|
244 |
+
<?php echo $localised_start_date; ?>
|
245 |
+
<?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
|
246 |
+
<?php echo substr ( $EM_Event->start_time, 0, 5 ) . " - " . substr ( $EM_Event->end_time, 0, 5 ); ?>
|
247 |
+
</td>
|
248 |
+
</tr>
|
249 |
+
</table>
|
250 |
+
</div>
|
251 |
+
</div>
|
252 |
+
<div id="em-booking-details" class="stuffbox">
|
253 |
+
<h3>
|
254 |
+
<?php _e ( 'Personal Details', 'dbem' ); ?>
|
255 |
+
</h3>
|
256 |
+
<div class="inside">
|
257 |
+
<?php echo $EM_Booking->get_person()->display_summary(); ?>
|
258 |
+
</div>
|
259 |
+
</div>
|
260 |
+
<div id="em-booking-details" class="stuffbox">
|
261 |
+
<h3>
|
262 |
+
<?php _e ( 'Booking Details', 'dbem' ); ?>
|
263 |
+
</h3>
|
264 |
+
<div class="inside">
|
265 |
+
<?php
|
266 |
+
$EM_Event = $EM_Booking->get_event();
|
267 |
+
$localised_start_date = date_i18n('D d M Y', $EM_Event->start);
|
268 |
+
$localised_end_date = date_i18n('D d M Y', $EM_Event->end);
|
269 |
+
?>
|
270 |
+
<p><strong><?php _e('Status','dbem'); ?> : </strong><?php echo $EM_Booking->get_status(); ?></p>
|
271 |
+
<table class="em-tickets-bookings-table" cellspacing="0" cellpadding="0">
|
272 |
+
<thead>
|
273 |
+
<tr>
|
274 |
+
<th><?php _e('Ticket Type','dbem'); ?></th>
|
275 |
+
<th><?php _e('Spaces','dbem'); ?></th>
|
276 |
+
<th><?php _e('Price','dbem'); ?></th>
|
277 |
+
</tr>
|
278 |
+
</thead>
|
279 |
+
<tbody>
|
280 |
+
<?php foreach($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking): ?>
|
281 |
+
<tr>
|
282 |
+
<td class="ticket-type"><a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&ticket_id=<?php echo $EM_Ticket_Booking->get_ticket()->id ?>"><?php echo $EM_Ticket_Booking->get_ticket()->name ?></a></td>
|
283 |
+
<td><?php echo $EM_Ticket_Booking->get_spaces(); ?></td>
|
284 |
+
<td><?php echo $EM_Ticket_Booking->get_price(); ?></td>
|
285 |
+
</tr>
|
286 |
+
<?php endforeach; ?>
|
287 |
+
</tbody>
|
288 |
+
<tfoot>
|
289 |
+
<tr>
|
290 |
+
<th><?php _e('Totals','dbem'); ?></th>
|
291 |
+
<th><?php echo $EM_Booking->get_spaces(); ?></th>
|
292 |
+
<th><?php echo $EM_Booking->get_price(); ?></th>
|
293 |
+
</tr>
|
294 |
+
</tfoot>
|
295 |
+
</table>
|
296 |
+
<table cellspacing="0" cellpadding="0">
|
297 |
+
<tr><td><strong><?php _e('Comment','dbem'); ?> </strong></td><td><?php echo $EM_Booking->comment; ?></td></tr>
|
298 |
+
<?php foreach( $EM_Booking->get_custom() as $custom_option ){
|
299 |
+
?><tr><td><strong><?php echo $custom_option['name'] ?></strong></td><td><?php echo $custom_option['value'] ?></td></tr><?php
|
300 |
+
}
|
301 |
+
?>
|
302 |
+
</table>
|
303 |
+
</div>
|
304 |
+
</div>
|
305 |
+
<div id="em-booking-notes" class="stuffbox">
|
306 |
+
<h3>
|
307 |
+
<?php _e ( 'Booking Notes', 'dbem' ); ?>
|
308 |
+
</h3>
|
309 |
+
<div class="inside">
|
310 |
+
<p><?php _e('You can add private notes below for internal reference that only event managers will see.','dbem'); ?></p>
|
311 |
+
<?php foreach( $EM_Booking->notes as $note ):
|
312 |
+
$user = get_userdata($note['author']);
|
313 |
+
?>
|
314 |
+
<div>
|
315 |
+
<?php echo date(get_option('date_format'), $note['timestamp']) .' - '. $user->display_name; ?> <?php _e('wrote','dbem'); ?>:
|
316 |
+
<p style="background:#efefef; padding:5px;"><?php echo nl2br($note['note']); ?></p>
|
317 |
+
</div>
|
318 |
+
<?php endforeach; ?>
|
319 |
+
<form method="post" action="" style="padding:5px;">
|
320 |
+
<textarea class="widefat" rows="5" name="booking_note"></textarea>
|
321 |
+
<input type="hidden" name="action" value="bookings_add_note" />
|
322 |
+
<input type="submit" value="Add Note" />
|
323 |
+
</form>
|
324 |
+
</div>
|
325 |
+
</div>
|
326 |
+
<?php do_action('em_bookings_single_metabox_footer', $EM_Booking); ?>
|
327 |
+
</div>
|
328 |
+
</div>
|
329 |
+
</div>
|
330 |
+
<br style="clear:both;" />
|
331 |
+
<?php do_action('em_bookings_single_footer', $EM_Booking); ?>
|
332 |
+
</div>
|
333 |
+
<?php
|
334 |
+
|
335 |
+
}
|
336 |
+
|
337 |
+
/**
|
338 |
+
* Shows all bookings made by one person.
|
339 |
+
*/
|
340 |
+
function em_bookings_person(){
|
341 |
+
global $EM_Person, $EM_Notices;
|
342 |
+
$EM_Person->get_bookings();
|
343 |
+
$has_booking = false;
|
344 |
+
foreach($EM_Person->get_bookings() as $EM_Booking){
|
345 |
+
if($EM_Booking->can_manage('manage_bookings','manage_others_bookings')){
|
346 |
+
$has_booking = true;
|
347 |
+
}
|
348 |
+
}
|
349 |
+
if( !$has_booking ){
|
350 |
+
?>
|
351 |
+
<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>
|
352 |
+
<?php
|
353 |
+
return false;
|
354 |
+
}
|
355 |
+
?>
|
356 |
+
<div class='wrap'>
|
357 |
+
<div id='icon-users' class='icon32'>
|
358 |
+
<br/>
|
359 |
+
</div>
|
360 |
+
<h2>
|
361 |
+
<?php _e('Manage Person\'s Booking', 'dbem'); ?>
|
362 |
+
<?php if( current_user_can('edit_users') ) : ?>
|
363 |
+
<a href="user-edit.php?user_id=<?php echo $EM_Person->ID; ?>" class="button add-new-h2"><?php _e('Edit User','dbem') ?></a>
|
364 |
+
<?php endif; ?>
|
365 |
+
</h2>
|
366 |
+
<?php echo $EM_Notices; ?>
|
367 |
+
<?php do_action('em_bookings_person_header'); ?>
|
368 |
+
<div id="poststuff" class="metabox-holder has-right-sidebar">
|
369 |
+
<div id="post-body">
|
370 |
+
<div id="post-body-content">
|
371 |
+
<div id="event_name" class="stuffbox">
|
372 |
+
<h3>
|
373 |
+
<?php _e ( 'Personal Details', 'dbem' ); ?>
|
374 |
+
</h3>
|
375 |
+
<div class="inside">
|
376 |
+
<?php echo $EM_Person->display_summary(); ?>
|
377 |
+
</div>
|
378 |
+
</div>
|
379 |
+
</div>
|
380 |
+
</div>
|
381 |
+
</div>
|
382 |
+
<br style="clear:both;" />
|
383 |
+
<?php do_action('em_bookings_person_body_1'); ?>
|
384 |
+
<h3><?php _e('Past And Present Bookings','dbem'); ?></h3>
|
385 |
+
<?php em_bookings_person_table(); ?>
|
386 |
+
<?php do_action('em_bookings_person_footer', $EM_Person); ?>
|
387 |
+
</div>
|
388 |
+
<?php
|
389 |
+
}
|
390 |
+
|
391 |
?>
|
admin/em-categories.php
CHANGED
@@ -1,177 +1,211 @@
|
|
1 |
-
<?php
|
2 |
-
function em_admin_categories_page() {
|
3 |
-
global $wpdb, $EM_Category;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
?>
|
1 |
+
<?php
|
2 |
+
function em_admin_categories_page() {
|
3 |
+
global $wpdb, $EM_Category, $EM_Notices;
|
4 |
+
|
5 |
+
//Take actions
|
6 |
+
if( (!empty($_REQUEST['action']) && ( ($_REQUEST['action'] == "edit" && !empty($_REQUEST['category_id'])) || $_REQUEST['action'] == "add")) ) {
|
7 |
+
em_categories_edit_layout();
|
8 |
+
} elseif( !empty($_REQUEST['action']) && $_REQUEST['action'] == "category_save" ) {
|
9 |
+
em_categories_edit_layout();
|
10 |
+
} else {
|
11 |
+
// no action, just a locations list
|
12 |
+
em_categories_table_layout();
|
13 |
+
}
|
14 |
+
return;
|
15 |
+
//TODO move categories action logic to em-actions.php
|
16 |
+
if( !empty($_REQUEST['action']) ){
|
17 |
+
if( $_REQUEST['action'] == "save") {
|
18 |
+
// save (add/update) category
|
19 |
+
if( empty($EM_Category) || !is_object($EM_Category) ){
|
20 |
+
$EM_Category = new EM_Category(); //blank category
|
21 |
+
$success_message = __('The category has been added.', 'dbem');
|
22 |
+
}else{
|
23 |
+
$success_message = __('The category has been updated.', 'dbem');
|
24 |
+
}
|
25 |
+
|
26 |
+
if ( $EM_Category->get_post() && $EM_Category->save() ) {
|
27 |
+
$EM_Notices->add_confirm($EM_Category->feedback_message);
|
28 |
+
em_categories_table_layout();
|
29 |
+
} else {
|
30 |
+
$EM_Notices->add_error($EM_Category->errors);
|
31 |
+
em_categories_edit_layout();
|
32 |
+
}
|
33 |
+
} elseif( $_REQUEST['action'] == "edit" ){
|
34 |
+
em_categories_edit_layout();
|
35 |
+
} elseif( $_REQUEST['action'] == "delete" ){
|
36 |
+
//delelte category
|
37 |
+
EM_Categories::delete($_REQUEST['categories']);
|
38 |
+
//FIXME no result verification when deleting various categories
|
39 |
+
$message = __('Categories Deleted', "dbem" );
|
40 |
+
em_categories_table_layout($message);
|
41 |
+
}
|
42 |
+
}else{
|
43 |
+
em_categories_table_layout();
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
function em_categories_table_layout($message = "") {
|
48 |
+
global $EM_Notices;
|
49 |
+
$categories = EM_Categories::get();
|
50 |
+
$destination = get_bloginfo('url')."/wp-admin/admin.php";
|
51 |
+
?>
|
52 |
+
<div class='wrap'>
|
53 |
+
<div id='icon-edit' class='icon32'>
|
54 |
+
<br/>
|
55 |
+
</div>
|
56 |
+
<h2>
|
57 |
+
<?php echo __('Categories', 'dbem') ?>
|
58 |
+
<a href="admin.php?page=events-manager-categories&action=add" class="button add-new-h2"><?php _e('Add New') ?></a>
|
59 |
+
</h2>
|
60 |
+
|
61 |
+
<?php echo $EM_Notices; ?>
|
62 |
+
|
63 |
+
<form id='bookings-filter' method='post' action='<?php echo get_bloginfo('wpurl') ?>/wp-admin/admin.php?page=events-manager-categories'>
|
64 |
+
<input type='hidden' name='action' value='category_delete'/>
|
65 |
+
<input type='hidden' name='_wpnonce' value='<?php echo wp_create_nonce('category_delete'); ?>'/>
|
66 |
+
<?php if (count($categories)>0) : ?>
|
67 |
+
<table class='widefat'>
|
68 |
+
<thead>
|
69 |
+
<tr>
|
70 |
+
<th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1'/></th>
|
71 |
+
<th><?php echo __('ID', 'dbem') ?></th>
|
72 |
+
<th><?php echo __('Name', 'dbem') ?></th>
|
73 |
+
</tr>
|
74 |
+
</thead>
|
75 |
+
<tfoot>
|
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 echo __('ID', 'dbem') ?></th>
|
79 |
+
<th><?php echo __('Name', 'dbem') ?></th>
|
80 |
+
</tr>
|
81 |
+
</tfoot>
|
82 |
+
<tbody>
|
83 |
+
<?php foreach ($categories as $EM_Category) : ?>
|
84 |
+
<tr>
|
85 |
+
<td><input type='checkbox' class ='row-selector' value='<?php echo $EM_Category->id ?>' name='categories[]'/></td>
|
86 |
+
<td><a href='<?php echo get_bloginfo('wpurl') ?>/wp-admin/admin.php?page=events-manager-categories&action=edit&category_id=<?php echo $EM_Category->id ?>'><?php echo htmlspecialchars($EM_Category->id, ENT_QUOTES); ?></a></td>
|
87 |
+
<td><a href='<?php echo get_bloginfo('wpurl') ?>/wp-admin/admin.php?page=events-manager-categories&action=edit&category_id=<?php echo $EM_Category->id ?>'><?php echo htmlspecialchars($EM_Category->name, ENT_QUOTES); ?></a></td>
|
88 |
+
</tr>
|
89 |
+
<?php endforeach; ?>
|
90 |
+
</tbody>
|
91 |
+
|
92 |
+
</table>
|
93 |
+
|
94 |
+
<div class='tablenav'>
|
95 |
+
<div class='alignleft actions'>
|
96 |
+
<input class='button-secondary action' type='submit' name='doaction2' value='Delete'/>
|
97 |
+
<br class='clear'/>
|
98 |
+
</div>
|
99 |
+
<br class='clear'/>
|
100 |
+
</div>
|
101 |
+
<?php else: ?>
|
102 |
+
<p><?php echo __('No categories have been inserted yet!', 'dbem'); ?></p>
|
103 |
+
<?php endif; ?>
|
104 |
+
</form>
|
105 |
+
</div>
|
106 |
+
<?php
|
107 |
+
}
|
108 |
+
|
109 |
+
|
110 |
+
function em_categories_edit_layout($message = "") {
|
111 |
+
global $EM_Category, $EM_Notices;
|
112 |
+
if( !is_object($EM_Category) ){
|
113 |
+
$EM_Category = new EM_Category();
|
114 |
+
}
|
115 |
+
//check that user can access this page
|
116 |
+
if( is_object($EM_Category) && !$EM_Category->can_manage('edit_categories') ){
|
117 |
+
?>
|
118 |
+
<div class="wrap"><h2><?php _e('Unauthorized Access','dbem'); ?></h2><p><?php implode('<br/>',$EM_Category->get_errors()); ?></p></div>
|
119 |
+
<?php
|
120 |
+
return;
|
121 |
+
}
|
122 |
+
?>
|
123 |
+
<div class='wrap'>
|
124 |
+
<div id='icon-edit' class='icon32'>
|
125 |
+
<br/>
|
126 |
+
</div>
|
127 |
+
|
128 |
+
<h2><?php echo __('Edit category', 'dbem') ?></h2>
|
129 |
+
|
130 |
+
<?php echo $EM_Notices ?>
|
131 |
+
|
132 |
+
<div id='ajax-response'></div>
|
133 |
+
|
134 |
+
<div id="poststuff" class="metabox-holder">
|
135 |
+
<div id="post-body">
|
136 |
+
<div id="post-body-content">
|
137 |
+
<form enctype='multipart/form-data' name='editcat' id='editcat' method='post' action='admin.php?page=events-manager-categories' class='validate'>
|
138 |
+
<input type='hidden' name='action' value='category_save' />
|
139 |
+
<input type='hidden' name='category_id' value='<?php echo $EM_Category->id ?>'/>
|
140 |
+
<input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('category_save'); ?>" />
|
141 |
+
|
142 |
+
<?php do_action('em_admin_category_form_header'); ?>
|
143 |
+
|
144 |
+
<div id="category_description" class="postbox">
|
145 |
+
<h3><?php echo __('Category name', 'dbem') ?></h3>
|
146 |
+
<div class="inside">
|
147 |
+
<input name='category_name' id='category-name' type='text' value='<?php echo htmlspecialchars($EM_Category->name,ENT_QUOTES); ?>' size='40' />
|
148 |
+
<br />
|
149 |
+
<em><?php echo __('The name of the category', 'dbem') ?></em>
|
150 |
+
<?php $slug_link = __('View Slug','dbem'); ?>
|
151 |
+
<a href="#" id="category-slug-trigger"><?php echo $slug_link; ?></a>
|
152 |
+
<script type="text/javascript">
|
153 |
+
jQuery(document).ready(function($){
|
154 |
+
$('#category-slug-trigger').click(function(){
|
155 |
+
if( $(this).text() == '<?php echo $slug_link; ?>'){
|
156 |
+
$('.category-slug').show();
|
157 |
+
$(this).text('<?php _e('Hide Slug','dbem'); ?>');
|
158 |
+
}else{
|
159 |
+
$('.category-slug').hide();
|
160 |
+
$(this).text('<?php echo $slug_link; ?>');
|
161 |
+
}
|
162 |
+
});
|
163 |
+
});
|
164 |
+
</script>
|
165 |
+
<p class='category-slug' style="display:none">
|
166 |
+
<?php echo sprintf(__('%s Slug','dbem'),__('Category','dbem')); ?>: <input type="text" name="category_slug" id="category-slug" value="<?php echo $EM_Category->slug; ?>" />
|
167 |
+
<br />
|
168 |
+
<?php _e ( 'The event slug. If the event slug already exists, a random number will be appended to the end.', 'dbem' )?>
|
169 |
+
</p>
|
170 |
+
</div>
|
171 |
+
</div>
|
172 |
+
|
173 |
+
<div id="category_description" class="postbox">
|
174 |
+
<h3>
|
175 |
+
<?php _e ( 'Details', 'dbem' ); ?>
|
176 |
+
</h3>
|
177 |
+
<div class="inside">
|
178 |
+
<div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
|
179 |
+
<?php the_editor($EM_Category->description ); ?>
|
180 |
+
</div>
|
181 |
+
<br />
|
182 |
+
<em><?php _e ( 'Details about the category', 'dbem' )?></em>
|
183 |
+
</div>
|
184 |
+
</div>
|
185 |
+
|
186 |
+
<div id="category_description" class="stuffbox">
|
187 |
+
<h3>
|
188 |
+
<?php _e ( 'Category image', 'dbem' ); ?>
|
189 |
+
</h3>
|
190 |
+
<div class="inside" style="padding:10px;">
|
191 |
+
<?php if ($EM_Category->get_image_url() != '') : ?>
|
192 |
+
<img src='<?php echo $EM_Category->image_url; ?>' alt='<?php echo $EM_Category->name ?>'/>
|
193 |
+
<?php else : ?>
|
194 |
+
<em><?php _e('No image uploaded for this category yet', 'dbem') ?></em>
|
195 |
+
<?php endif; ?>
|
196 |
+
<br /><br />
|
197 |
+
<label for='category_image'><?php _e('Upload/change picture', 'dbem') ?></label> <input id='locacategoryge' name='category_image' id='category_image' type='file' size='40' />
|
198 |
+
</div>
|
199 |
+
</div>
|
200 |
+
</div>
|
201 |
+
<?php do_action('em_admin_category_form_footer'); ?>
|
202 |
+
<p class='submit'><input type='submit' class='button-primary' name='submit' value='<?php echo __('Update category', 'dbem') ?>' /></p>
|
203 |
+
</form>
|
204 |
+
</div>
|
205 |
+
</div>
|
206 |
+
</div>
|
207 |
+
|
208 |
+
</div>
|
209 |
+
<?php
|
210 |
+
}
|
211 |
?>
|
admin/em-docs.php
CHANGED
@@ -1,193 +1,227 @@
|
|
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 |
-
|
26 |
-
'
|
27 |
-
'
|
28 |
-
'
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
'
|
34 |
-
'scope' => array( '
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
'
|
39 |
-
'
|
40 |
-
'
|
41 |
-
'
|
42 |
-
'
|
43 |
-
'
|
44 |
-
'
|
45 |
-
'
|
46 |
-
'
|
47 |
-
'
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
'
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
'#
|
63 |
-
'#
|
64 |
-
)
|
65 |
-
),
|
66 |
-
'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 |
-
'#
|
86 |
-
'#
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
'#
|
103 |
-
'#
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
'#
|
110 |
-
'#
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
'#
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
'#
|
131 |
-
'#
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
'
|
142 |
-
|
143 |
-
'#
|
144 |
-
'#
|
145 |
-
'#
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
'#
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
?>
|
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.', 'dbem') ),
|
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").', 'dbem'), 'default'=> __('See the event lists ordering option on the settings page.', 'dbem'), 'args'=>'name, start_date, start_time, end_date, end_time'),
|
17 |
+
'order' => array( 'default'=> __('See the event lists ordering option on the settings page.', 'dbem') )
|
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.', 'dbem'), 'default' => 0),
|
21 |
+
'eventless' => array( 'desc'=> __('If set to 1 will only show locations that have no events occurring during the scope.', 'dbem'), '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").', 'dbem'), 'default'=>'name', 'args' => 'name, address, town'),
|
23 |
+
'scope' => array( 'default' => 'all'),
|
24 |
+
'town' => array( 'desc'=> __('Search for locations in this town (no partial matches, case sensitive).', 'dbem'), 'default' => __('none','dbem')),
|
25 |
+
'state' => array( 'desc'=> __('Search for locations in this state (no partial matches, case sensitive).', 'dbem'), 'default' => __('none','dbem')),
|
26 |
+
'region' => array( 'desc'=> __('Search for locations in this region (no partial matches, case sensitive).', 'dbem'), 'default' => __('none','dbem')),
|
27 |
+
'country' => array( 'desc'=> __('Search for locations in this country (no partial matches, case sensitive).', 'dbem'), 'default' => __('none','dbem')),
|
28 |
+
'postcode' => array( 'desc'=> __('Search for locations in this postcode (no partial matches, case sensitive).', 'dbem'), 'default' => __('none','dbem'))
|
29 |
+
),
|
30 |
+
'calendar' => array(
|
31 |
+
'full' => array( 'desc'=> __('If set to 1 it will display a full calendar that shows event names.', 'dbem'), 'default' => 0),
|
32 |
+
'long_events' => array( 'desc'=> __('If set to 1, will show events that last longer than a day.', 'dbem'), 'default' => 0),
|
33 |
+
'order' => array( 'desc'=> __('Same as for events.', 'dbem') ),
|
34 |
+
'scope' => array( 'default' => 'future')
|
35 |
+
),
|
36 |
+
//The object is commonly shared by all, so entries above overwrite entries here
|
37 |
+
'general' => array(
|
38 |
+
'limit' => array( 'desc'=> __('Limits the amount of values returned to this number.', 'dbem'), 'default'=>'0 (no limit)'),
|
39 |
+
'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.', 'dbem'), 'default'=>'future'),
|
40 |
+
'order' => array( 'desc'=> __('Indicates the order of the events. Choose between ASC (ascending) and DESC (descending).', 'dbem'), 'default'=>'ASC'),
|
41 |
+
'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.', 'dbem'), 'default'=>0),
|
42 |
+
'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.', 'dbem'), 'default'=> __('The relevant default format will be taken from the settings page.', 'dbem')),
|
43 |
+
'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).', 'dbem'), 'default'=>0),
|
44 |
+
'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.', 'dbem'), 'default'=>0),
|
45 |
+
'location' => array( 'desc'=> __('Supply a single id or comma-seperated ids to limit the search to these locations (or events in these locations).', 'dbem'), 'default'=>0),
|
46 |
+
'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.', 'dbem'), 'default'=>0),
|
47 |
+
'recurrence' => array( 'desc'=> __('If set to 1, will show only events that are recurring (i.e. events that are repeated over different dates).', 'dbem'), 'default'=>0),
|
48 |
+
'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.', 'dbem'), 'default'=>0),
|
49 |
+
'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 and does not work as intended if used with scope.', 'dbem'), 'default'=>''),
|
50 |
+
'year' => array( 'desc'=> __('If set to a year (e.g. 2010) only events that start or end during this year/month will be returned. Does not work as intended if used with scope.', 'dbem'), 'default'=>''),
|
51 |
+
'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)', 'dbem'), 'default'=>0),
|
52 |
+
'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.', 'dbem'), 'default'=>0)
|
53 |
+
)
|
54 |
+
),
|
55 |
+
'placeholders' => array(
|
56 |
+
'events' => array(
|
57 |
+
'Event Details' => array(
|
58 |
+
'placeholders' => array(
|
59 |
+
'#_NAME' => array( 'desc' => __('Displays the name of the event.', 'dbem') ),
|
60 |
+
'#_NOTES' => array( 'desc' => __('Shows the description of the event.', 'dbem') ),
|
61 |
+
'#_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).', 'dbem') ),
|
62 |
+
'#_EVENTID' => array( 'desc' => __('Shows the event corresponding ID number in the database table.', 'dbem') ),
|
63 |
+
'#_EVENTIMAGE' => array( 'desc' => __('Shows the event image, if available.', 'dbem') )
|
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).', 'dbem') ),
|
70 |
+
'#_24HENDTIME' => array( 'desc' => __('Displays the end time in a 24 hours format (e.g. 18:30).', 'dbem') ),
|
71 |
+
'#_12HSTARTTIME' => array( 'desc' => __('Displays the start time in a 12 hours format (e.g. 4:30 PM).', 'dbem') ),
|
72 |
+
'#_12HENDTIME' => array( 'desc' => __('Displays the end time in a 12 hours format (e.g. 6:30 PM).', 'dbem') )
|
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.', 'dbem'),
|
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).', 'dbem') ),
|
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>.', 'dbem') ),
|
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.', 'dbem') ),
|
85 |
+
'#_EVENTIMAGEURL' => array( 'desc' => __('Shows the event image url, if available.', 'dbem') ),
|
86 |
+
'#_EVENTLINK' => array( 'desc' => __('Displays the event name with a link to the event page.', 'dbem') ),
|
87 |
+
'#_EDITEVENTLINK' => array( 'desc' => __('Inserts a link to the admin or buddypress (if activated) edit event page, only if a user is logged in and is allowed to edit the event.', 'dbem') ),
|
88 |
+
'#_EDITEVENTURL' => array( 'desc' => __('Inserts a url to the admin or buddypress (if activated) edit event page, only if a user is logged in and is allowed to edit the event.', 'dbem') )
|
89 |
+
)
|
90 |
+
),
|
91 |
+
'Custom Attributes' => array(
|
92 |
+
'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.', 'dbem'),
|
93 |
+
'placeholders' => array(
|
94 |
+
'#_ATT{key}' => array('desc'=> __('This key will appear as an option when adding attributes to your event.', 'dbem')),
|
95 |
+
'#_ATT{key}{alternative text}' => array('desc'=> __('This key will appear as an option when adding attributes to your event. The text in the second braces will appear if the attribute is not defined or left blank for that event.', 'dbem')),
|
96 |
+
'#_ATT{key}{option 1|option 2|option 3|etc.}' => array('desc'=> __('This key will appear as an option when adding attributes to your event. The second braces are optional and will use a select box with these values as input. If no valid value is defined, the first option is used.', 'dbem')),
|
97 |
+
)
|
98 |
+
),
|
99 |
+
'Bookings/RSVP' => array(
|
100 |
+
'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', 'dbem'),
|
101 |
+
'placeholders' => array(
|
102 |
+
'#_BOOKINGFORM' => array( 'desc' => __('Adds a booking forms for this event.', 'dbem') ),
|
103 |
+
'#_AVAILABLESPACES' => array( 'desc' => __('Shows available spaces for the event.', 'dbem') ),
|
104 |
+
'#_BOOKEDSPACES' => array( 'desc' => __('Shows the amount of currently booked spaces for the event.', 'dbem') ),
|
105 |
+
'#_PENDINGSPACES' => array( 'desc' => __('Shows the amount of pending spaces for the event.', 'dbem') ),
|
106 |
+
'#_SPACES' => array( 'desc' => __('Shows the total spaces for the event.', 'dbem') ),
|
107 |
+
'#_ATTENDEES' => array( 'desc' => __('Shows the list of user avatars attending events.', 'dbem') ),
|
108 |
+
'#_BOOKINGBUTTON' => array( 'desc' => __('A single button that will appear to logged in users, if they click on it, they apply for a booking. This button will only display if there is one ticket.', 'dbem') ),
|
109 |
+
'#_BOOKINGSURL' => array( 'desc' => __('Shows the url to the admin or buddypress (if activated) bookings management page for this event. Only shown if user is logged in and able to manage bookings.', 'dbem') ),
|
110 |
+
'#_BOOKINGSLINK' => array( 'desc' => __('Shows a link to the admin or buddypress (if activated) bookings management page for this event. Only shown if user is logged in and able to manage bookings.', 'dbem') )
|
111 |
+
)
|
112 |
+
),
|
113 |
+
'Contact Details' => array(
|
114 |
+
'desc' => __('The values here are taken from the chosen contact for the specific event, or the default contact in the settings page.', 'dbem'),
|
115 |
+
'placeholders' => array(
|
116 |
+
'#_CONTACTNAME' => array( 'desc' => __('Name of the contact person for this event (as shown in the dropdown when adding an event).', 'dbem') ),
|
117 |
+
'#_CONTACTUSERNAME' => array( 'desc' => __('Contact person\'s username.', 'dbem') ),
|
118 |
+
'#_CONTACTEMAIL' => array( 'desc' => __('E-mail of the contact person for this event.', 'dbem') ),
|
119 |
+
'#_CONTACTPHONE' => array( 'desc' => __('Phone number of the contact person for this event. Can be set in the user profile page.', 'dbem') ),
|
120 |
+
'#_CONTACTAVATAR' => array( 'desc' => __('Contact person\'s avatar.', 'dbem') ),
|
121 |
+
'#_CONTACTPROFILELINK' => array( 'desc' => __('Contact person\'s "Profile" link. Only works with BuddyPress enabled.', 'dbem') ),
|
122 |
+
'#_CONTACTPROFILEURL' => array( 'desc' => __('Contact person\'s profile url. Only works with BuddyPress enabled.', 'dbem') ),
|
123 |
+
'#_CONTACTID' => array( 'desc' => __('Contact person\'s wordpress user ID.', 'dbem'))
|
124 |
+
)
|
125 |
+
),
|
126 |
+
),
|
127 |
+
'categories' => array(
|
128 |
+
'Category Details' => array(
|
129 |
+
'placeholders' => array(
|
130 |
+
'#_CATEGORYNAME' => array( 'desc' => __('Shows the category name of the event.', 'dbem') ),
|
131 |
+
'#_CATEGORYID' => array( 'desc' => __('Shows the category ID of the event.', 'dbem') ),
|
132 |
+
'#_CATEGORYIMAGE' => array( 'desc' => __('Shows the event image, if available.', 'dbem') ),
|
133 |
+
'#_CATEGORYIMAGEURL' => array( 'desc' => __('Shows the event image url, if available.', 'dbem') ),
|
134 |
+
'#_CATEGORYNOTES' => array( 'desc' => __('Shows the location description.', 'dbem') )
|
135 |
+
)
|
136 |
+
)
|
137 |
+
),
|
138 |
+
'locations' => array(
|
139 |
+
'Location Details' => array(
|
140 |
+
'desc' => '',
|
141 |
+
'placeholders' => array(
|
142 |
+
'#_LOCATIONNAME' => array( 'desc' => __('Displays the location name.', 'dbem') ),
|
143 |
+
'#_LOCATIONADDRESS' => array( 'desc' => __('Displays the address.', 'dbem') ),
|
144 |
+
'#_LOCATIONTOWN' => array( 'desc' => __('Displays the town.', 'dbem') ),
|
145 |
+
'#_LOCATIONSTATE' => array( 'desc' => __('Displays the state/county.', 'dbem') ),
|
146 |
+
'#_LOCATIONPOSTCODE' => array( 'desc' => __('Displays the postcode.', 'dbem') ),
|
147 |
+
'#_LOCATIONREGION' => array( 'desc' => __('Displays the region.', 'dbem') ),
|
148 |
+
'#_LOCATIONCOUNTRY' => array( 'desc' => __('Displays the country.', 'dbem') ),
|
149 |
+
'#_LOCATIONMAP' => array( 'desc' => __('Displays a google map showing where the event is located (Will not show if maps are disabled in the settings page)', 'dbem') ),
|
150 |
+
'#_LOCATIONNOTES' => array( 'desc' => __('Shows the location description.', 'dbem') ),
|
151 |
+
'#_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).', 'dbem') ),
|
152 |
+
'#_LOCATIONIMAGE' => array( 'desc' => __('Shows the location image.', 'dbem') ),
|
153 |
+
'#_LOCATIONID' => array( 'desc' => __('Displays the location ID number.', 'dbem') )
|
154 |
+
)
|
155 |
+
),
|
156 |
+
'Links' => array(
|
157 |
+
'placeholders' => array(
|
158 |
+
'#_LOCATIONURL' => array( 'desc' => __('Simply prints the location URL. You can use this placeholder to build your own customised links.', 'dbem') ),
|
159 |
+
'#_LOCATIONLINK' => array( 'desc' => __('Displays the location name with a link to the location page.', 'dbem') )
|
160 |
+
)
|
161 |
+
),
|
162 |
+
'Related Events' => array(
|
163 |
+
'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.', 'dbem'),
|
164 |
+
'placeholders' => array(
|
165 |
+
'#_LOCATIONPASTEVENTS' => array( 'desc' => __('Will show a list of all past events at this location.', 'dbem') ),
|
166 |
+
'#_LOCATIONNEXTEVENTS' => array( 'desc' => __('Will show a list of all future events at this location.', 'dbem') ),
|
167 |
+
'#_LOCATIONALLEVENTS' => array( 'desc' => __('Will show a list of all events at this location.', 'dbem') )
|
168 |
+
)
|
169 |
+
),
|
170 |
+
),
|
171 |
+
'bookings' => array(
|
172 |
+
'Booking Person Information' => array(
|
173 |
+
'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.', 'dbem'),
|
174 |
+
'placeholders' => array(
|
175 |
+
'#_BOOKINGNAME' => array( 'desc' => __('Name of person who made the booking.', 'dbem') ),
|
176 |
+
'#_BOOKINGEMAIL' => array( 'desc' => __('Email of person who made the booking.', 'dbem') ),
|
177 |
+
'#_BOOKINGPHONE' => array( 'desc' => __('Phone number of person who made the booking.', 'dbem') ),
|
178 |
+
'#_BOOKINGSPACES' => array( 'desc' => __('Number of spaces the person has booked.', 'dbem') ),
|
179 |
+
'#_BOOKINGCOMMENT' => array( 'desc' => __('Any specific comments made by the person who made the booking.', 'dbem') ),
|
180 |
+
'#_BOOKINGTICKETNAME' => array( 'desc' => __('Name of the ticket booked. Useful in single ticket mode, if multiple tickets are booked a random ticket is used.', 'dbem') ),
|
181 |
+
'#_BOOKINGTICKETDESCRIPTION' => array( 'desc' => __('Description of the ticket booked. Useful in single ticket mode, if multiple tickets are booked a random ticket is used.', 'dbem') ),
|
182 |
+
'#_BOOKINGTICKETPRICE' => array( 'desc' => __('Booked ticket price with currency symbol (e.g. $ 10.00). Useful in single ticket mode, if multiple tickets are booked a random ticket is used.', 'dbem') ),
|
183 |
+
'#_BOOKINGTICKETS' => array( 'desc' => __('A list of booked tickets. You can modify this by using template files and modifying templates/emails/bookingtickets.php', 'dbem') ),
|
184 |
+
)
|
185 |
+
),
|
186 |
+
'Links' => array(
|
187 |
+
'desc' => __('People are able to manage their bookings. Below are some placeholder which automatically provides correctly formatted urls', 'dbem'),
|
188 |
+
'placeholders' => array(
|
189 |
+
'#_BOOKINGLISTURL' => array( 'desc' => __('URL to page showing that users booked events.', 'dbem') )
|
190 |
+
)
|
191 |
+
)
|
192 |
+
),
|
193 |
+
),
|
194 |
+
//TODO add capabilites explanations
|
195 |
+
'capabilities' => array()
|
196 |
+
);
|
197 |
+
}
|
198 |
+
}
|
199 |
+
add_action('init', 'em_docs_init');
|
200 |
+
|
201 |
+
function em_docs_placeholders($atts){
|
202 |
+
ob_start();
|
203 |
+
?>
|
204 |
+
<div class="em-docs">
|
205 |
+
<?php
|
206 |
+
global $EM_Documentation;
|
207 |
+
$type = $atts['type'];
|
208 |
+
$data = $EM_Documentation['placeholders'][$type];
|
209 |
+
foreach($data as $sectionTitle => $details) : ?>
|
210 |
+
<div>
|
211 |
+
<h3><?php echo $sectionTitle; ?></h3>
|
212 |
+
<?php if( !empty($details['desc']) ): ?>
|
213 |
+
<p><?php echo $details['desc']; ?></p>
|
214 |
+
<?php endif; ?>
|
215 |
+
<dl>
|
216 |
+
<?php foreach($details['placeholders'] as $placeholder => $desc ): ?>
|
217 |
+
<dt><b><?php echo $placeholder; ?></b></dt>
|
218 |
+
<dd><?php echo $desc['desc']; ?></dd>
|
219 |
+
<?php endforeach; ?>
|
220 |
+
</dl>
|
221 |
+
</div>
|
222 |
+
<?php endforeach; ?>
|
223 |
+
</div>
|
224 |
+
<?php
|
225 |
+
return ob_get_clean();
|
226 |
+
}
|
227 |
?>
|
admin/em-event.php
CHANGED
@@ -1,627 +1,766 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
<?php
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
</
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
<?php _e ( '
|
345 |
-
</
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
<?php
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
<
|
360 |
-
|
361 |
-
<?php
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
<
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
<
|
405 |
-
<?php
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
<?php
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
$
|
504 |
-
if(
|
505 |
-
$
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
<
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
<
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
<
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
<
|
548 |
-
|
549 |
-
|
550 |
-
<
|
551 |
-
</td>
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
627 |
?>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Generates Event Admin page, for adding and updating a single (or recurring) event.
|
4 |
+
* @param $title
|
5 |
+
* @return null
|
6 |
+
*/
|
7 |
+
function em_admin_event_page() {
|
8 |
+
global $EM_Event, $current_user, $EM_Notices, $localised_date_formats;
|
9 |
+
//$EM_Event->get_bookings()->get_tickets()->get_ticket_bookings(); print_r($EM_Event);die();
|
10 |
+
|
11 |
+
//check that user can access this page
|
12 |
+
if( is_object($EM_Event) && !$EM_Event->can_manage('edit_events','edit_others_events') ){
|
13 |
+
?>
|
14 |
+
<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>
|
15 |
+
<?php
|
16 |
+
return false;
|
17 |
+
}elseif( !is_object($EM_Event) ){
|
18 |
+
$EM_Event = new EM_Event();
|
19 |
+
}
|
20 |
+
|
21 |
+
if( is_object($EM_Event) && $EM_Event->id > 0 ){
|
22 |
+
if($EM_Event->is_recurring()){
|
23 |
+
$title = __( "Reschedule", 'dbem' )." '{$EM_Event->name}'";
|
24 |
+
}else{
|
25 |
+
$title = __ ( "Edit Event", 'dbem' ) . " '" . $EM_Event->name . "'";
|
26 |
+
}
|
27 |
+
} else {
|
28 |
+
$EM_Event = ( is_object($EM_Event) && get_class($EM_Event) == 'EM_Event') ? $EM_Event : new EM_Event();
|
29 |
+
$title = __ ( "Insert New Event", 'dbem' );
|
30 |
+
//Give a default location & category
|
31 |
+
$default_cat = get_option('dbem_default_category');
|
32 |
+
$default_loc = get_option('dbem_default_location');
|
33 |
+
if( is_numeric($default_cat) && $default_cat > 0 ){
|
34 |
+
$EM_Category = new EM_Category($default_cat);
|
35 |
+
$EM_Event->get_categories()->categories[] = $EM_Category;
|
36 |
+
}
|
37 |
+
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) ) ){
|
38 |
+
$EM_Event->location_id = $default_loc;
|
39 |
+
$EM_Event->location = new EM_Location($default_loc);
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
$use_select_for_locations = get_option('dbem_use_select_for_locations');
|
44 |
+
// change prefix according to event/recurrence
|
45 |
+
$pref = "event_";
|
46 |
+
|
47 |
+
$locale_code = substr ( get_locale (), 0, 2 );
|
48 |
+
$localised_date_format = $localised_date_formats[$locale_code];
|
49 |
+
|
50 |
+
//FIXME time useage is very flimsy imho
|
51 |
+
$hours_locale_regexp = "H:i";
|
52 |
+
// Setting 12 hours format for those countries using it
|
53 |
+
if (preg_match ( "/en|sk|zh|us|uk/", $locale_code ))
|
54 |
+
$hours_locale_regexp = "h:iA";
|
55 |
+
|
56 |
+
$days_names = array (1 => __ ( 'Mon' ), 2 => __ ( 'Tue' ), 3 => __ ( 'Wed' ), 4 => __ ( 'Thu' ), 5 => __ ( 'Fri' ), 6 => __ ( 'Sat' ), 0 => __ ( 'Sun' ) );
|
57 |
+
$required = "<i>*</i>";
|
58 |
+
?>
|
59 |
+
<?php echo $EM_Notices; ?>
|
60 |
+
|
61 |
+
<form id="event-form" method="post" action="" enctype='multipart/form-data'>
|
62 |
+
<div class="wrap">
|
63 |
+
<div id="icon-events" class="icon32"><br /></div>
|
64 |
+
<h2><?php echo $title; ?></h2>
|
65 |
+
<?php if ( count($EM_Event->warnings) > 0 ) : ?>
|
66 |
+
<?php foreach($EM_Event->warnings as $warning): ?>
|
67 |
+
<p class="warning"><?php echo $warning; ?></p>
|
68 |
+
<?php endforeach; ?>
|
69 |
+
<?php endif; ?>
|
70 |
+
<div id="poststuff" class="metabox-holder has-right-sidebar">
|
71 |
+
<!-- SIDEBAR -->
|
72 |
+
<div id="side-info-column" class='inner-sidebar'>
|
73 |
+
<div id='side-sortables'>
|
74 |
+
<?php do_action('em_admin_event_form_side_header'); ?>
|
75 |
+
<?php if(get_option('dbem_recurrence_enabled') && ($EM_Event->is_recurrence() || $EM_Event->is_recurring() || $EM_Event->id == '')) : ?>
|
76 |
+
<!-- START recurrence postbox -->
|
77 |
+
<div class="postbox ">
|
78 |
+
<div class="handlediv" title="Fare clic per cambiare."><br />
|
79 |
+
</div>
|
80 |
+
<h3 class='hndle'><span>
|
81 |
+
<?php _e ( "Recurrence", 'dbem' ); ?>
|
82 |
+
</span></h3>
|
83 |
+
<div class="inside">
|
84 |
+
<?php //TODO add js warning if rescheduling, since all bookings are deleted ?>
|
85 |
+
<?php if ( !$EM_Event->id || $EM_Event->is_recurring() ) : ?>
|
86 |
+
<p>
|
87 |
+
<input id="event-recurrence" type="checkbox" name="repeated_event" value="1" <?php echo ( $EM_Event->is_recurring() ) ? 'checked="checked"':'' ; ?> />
|
88 |
+
<?php _e ( 'Repeated event', 'dbem' ); ?>
|
89 |
+
</p>
|
90 |
+
<div id="event_recurrence_pattern">
|
91 |
+
<p>
|
92 |
+
Frequency:
|
93 |
+
<select id="recurrence-frequency" name="recurrence_freq">
|
94 |
+
<?php
|
95 |
+
$freq_options = array ("daily" => __ ( 'Daily', 'dbem' ), "weekly" => __ ( 'Weekly', 'dbem' ), "monthly" => __ ( 'Monthly', 'dbem' ) );
|
96 |
+
em_option_items ( $freq_options, $EM_Event->freq );
|
97 |
+
?>
|
98 |
+
</select>
|
99 |
+
</p>
|
100 |
+
<p>
|
101 |
+
<?php _e ( 'Every', 'dbem' )?>
|
102 |
+
<input id="recurrence-interval" name='recurrence_interval' size='2' value='<?php echo $EM_Event->interval ; ?>' />
|
103 |
+
<span class='interval-desc' id="interval-daily-singular">
|
104 |
+
<?php _e ( 'day', 'dbem' )?>
|
105 |
+
</span> <span class='interval-desc' id="interval-daily-plural">
|
106 |
+
<?php _e ( 'days', 'dbem' ) ?>
|
107 |
+
</span> <span class='interval-desc' id="interval-weekly-singular">
|
108 |
+
<?php _e ( 'week', 'dbem' )?>
|
109 |
+
</span> <span class='interval-desc' id="interval-weekly-plural">
|
110 |
+
<?php _e ( 'weeks', 'dbem' )?>
|
111 |
+
</span> <span class='interval-desc' id="interval-monthly-singular">
|
112 |
+
<?php _e ( 'month', 'dbem' )?>
|
113 |
+
</span> <span class='interval-desc' id="interval-monthly-plural">
|
114 |
+
<?php _e ( 'months', 'dbem' )?>
|
115 |
+
</span>
|
116 |
+
</p>
|
117 |
+
<p class="alternate-selector" id="weekly-selector">
|
118 |
+
<?php
|
119 |
+
$saved_bydays = ($EM_Event->is_recurring()) ? explode ( ",", $EM_Event->byday ) : array();
|
120 |
+
em_checkbox_items ( 'recurrence_bydays[]', $days_names, $saved_bydays );
|
121 |
+
?>
|
122 |
+
</p>
|
123 |
+
<p class="alternate-selector" id="monthly-selector">
|
124 |
+
<?php _e ( 'Every', 'dbem' )?>
|
125 |
+
<select id="monthly-modifier" name="recurrence_byweekno">
|
126 |
+
<?php
|
127 |
+
$weekno_options = array ("1" => __ ( 'first', 'dbem' ), '2' => __ ( 'second', 'dbem' ), '3' => __ ( 'third', 'dbem' ), '4' => __ ( 'fourth', 'dbem' ), '-1' => __ ( 'last', 'dbem' ) );
|
128 |
+
em_option_items ( $weekno_options, $EM_Event->byweekno );
|
129 |
+
?>
|
130 |
+
</select>
|
131 |
+
<select id="recurrence-weekday" name="recurrence_byday">
|
132 |
+
<?php em_option_items ( $days_names, $EM_Event->byday ); ?>
|
133 |
+
</select>
|
134 |
+
|
135 |
+
</p>
|
136 |
+
</div>
|
137 |
+
<p id="recurrence-tip">
|
138 |
+
<?php _e ( 'Check if your event happens more than once according to a regular pattern', 'dbem' )?>
|
139 |
+
</p>
|
140 |
+
<?php elseif( $EM_Event->is_recurrence() ) : ?>
|
141 |
+
<p>
|
142 |
+
<?php echo $EM_Event->get_recurrence_description(); ?>
|
143 |
+
<br />
|
144 |
+
<a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&event_id=<?php echo $EM_Event->recurrence_id; ?>">
|
145 |
+
<?php _e ( 'Reschedule', 'dbem' ); ?>
|
146 |
+
</a>
|
147 |
+
<input type="hidden" name="recurrence_id" value="<?php echo $EM_Event->recurrence_id; ?>" />
|
148 |
+
</p>
|
149 |
+
<?php else : ?>
|
150 |
+
<p><?php _e ( 'This is\'t a recurrent event', 'dbem' ) ?></p>
|
151 |
+
<?php endif; ?>
|
152 |
+
</div>
|
153 |
+
</div>
|
154 |
+
<!-- END recurrence postbox -->
|
155 |
+
<?php endif; ?>
|
156 |
+
|
157 |
+
<?php if ( current_user_can('edit_others_events') ): ?>
|
158 |
+
<div class="postbox ">
|
159 |
+
<div class="handlediv" title="Fare clic per cambiare."><br />
|
160 |
+
</div>
|
161 |
+
<h3 class='hndle'><span><?php _e ( 'Event Owner/Contact Person', 'dbem' ); ?></span></h3>
|
162 |
+
<div class="inside">
|
163 |
+
<?php
|
164 |
+
$event_owner = (empty($EM_Event->id)) ? $EM_Event->owner:get_current_user_id();
|
165 |
+
$user_args = array ('name' => 'event_owner', 'show_option_none' => __ ( "Select...", 'dbem' ), 'selected' => $EM_Event->owner );
|
166 |
+
if( is_super_admin() || is_main_site() ){ $user_args['blog_id'] = false; }
|
167 |
+
wp_dropdown_users ( $user_args );
|
168 |
+
?>
|
169 |
+
</div>
|
170 |
+
</div>
|
171 |
+
<?php else: ?>
|
172 |
+
<input type="hidden" name="event_owner" value="<?php get_current_user_id() ?>" />
|
173 |
+
<?php endif; ?>
|
174 |
+
|
175 |
+
<?php if( empty($EM_Event->id) ): ?>
|
176 |
+
<?php
|
177 |
+
$user_groups = array();
|
178 |
+
if( function_exists('groups_get_user_groups') ){
|
179 |
+
$group_data = groups_get_user_groups(get_current_user_id());
|
180 |
+
foreach( $group_data['groups'] as $group_id ){
|
181 |
+
if( groups_is_user_admin(get_current_user_id(), $group_id) ){
|
182 |
+
$user_groups[] = groups_get_group( array('group_id'=>$group_id));
|
183 |
+
}
|
184 |
+
}
|
185 |
+
}
|
186 |
+
?>
|
187 |
+
<?php if( count($user_groups) > 0 ): ?>
|
188 |
+
<!-- START RSVP -->
|
189 |
+
<div class="postbox " id='group-data'>
|
190 |
+
<div class="handlediv" title="Fare clic per cambiare."><br />
|
191 |
+
</div>
|
192 |
+
<h3 class='hndle'><span><?php _e('Group Ownership','dbem'); ?></span></h3>
|
193 |
+
<div class="inside">
|
194 |
+
<p>
|
195 |
+
<select name="group_id">
|
196 |
+
<option value="<?php echo $BP_Group->id; ?>">Not a Group Event</option>
|
197 |
+
<?php
|
198 |
+
foreach($user_groups as $BP_Group){
|
199 |
+
?>
|
200 |
+
<option value="<?php echo $BP_Group->id; ?>"><?php echo $BP_Group->name; ?></option>
|
201 |
+
<?php
|
202 |
+
}
|
203 |
+
?>
|
204 |
+
</select>
|
205 |
+
<br />
|
206 |
+
<em><?php _e ( 'Select a group you admin to attach this event to it. Note that all other admins of that group can modify the booking, and you will not be able to unattach the event without deleting it.', 'dbem' )?></em>
|
207 |
+
</p>
|
208 |
+
</div>
|
209 |
+
</div>
|
210 |
+
<?php endif; ?>
|
211 |
+
<?php endif; ?>
|
212 |
+
|
213 |
+
<?php if(get_option('dbem_rsvp_enabled')) : ?>
|
214 |
+
<!-- START RSVP -->
|
215 |
+
<div class="postbox " id='rsvp-data'>
|
216 |
+
<div class="handlediv" title="Fare clic per cambiare."><br />
|
217 |
+
</div>
|
218 |
+
<h3 class='hndle'><span><?php _e('Bookings Stats','dbem'); ?></span></h3>
|
219 |
+
<div class="inside">
|
220 |
+
<div>
|
221 |
+
<!-- START RSVP Stats -->
|
222 |
+
<?php
|
223 |
+
$available_spaces = $EM_Event->get_bookings()->get_available_spaces();
|
224 |
+
$booked_spaces = $EM_Event->get_bookings()->get_booked_spaces();
|
225 |
+
|
226 |
+
if ( count($EM_Event->get_bookings()->bookings) > 0 ) {
|
227 |
+
?>
|
228 |
+
<div class='wrap'>
|
229 |
+
<p><strong><?php echo __('Available Spaces','dbem').': '.$EM_Event->get_bookings()->get_available_spaces(); ?></strong></p>
|
230 |
+
<p><strong><?php echo __('Confirmed Spaces','dbem').': '.$EM_Event->get_bookings()->get_booked_spaces(); ?></strong></p>
|
231 |
+
<p><strong><?php echo __('Pending Spaces','dbem').': '.$EM_Event->get_bookings()->get_pending_spaces(); ?></strong></p>
|
232 |
+
</div>
|
233 |
+
|
234 |
+
<br class='clear'/>
|
235 |
+
|
236 |
+
<div id='major-publishing-actions'>
|
237 |
+
<div id='publishing-action'>
|
238 |
+
<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 />
|
239 |
+
<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>
|
240 |
+
<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>
|
241 |
+
<?php do_action('em_admin_event_booking_options'); ?>
|
242 |
+
<br class='clear'/>
|
243 |
+
</div>
|
244 |
+
<br class='clear'/>
|
245 |
+
</div>
|
246 |
+
<?php
|
247 |
+
} else {
|
248 |
+
?>
|
249 |
+
<p><em><?php _e('No responses yet!')?></em></p>
|
250 |
+
<?php
|
251 |
+
}
|
252 |
+
?>
|
253 |
+
<!-- END RSVP Stats -->
|
254 |
+
</div>
|
255 |
+
</div>
|
256 |
+
</div>
|
257 |
+
<!-- END RSVP -->
|
258 |
+
<?php endif; ?>
|
259 |
+
<?php if(get_option('dbem_categories_enabled')) :?>
|
260 |
+
<!-- START Categories -->
|
261 |
+
<div class="postbox ">
|
262 |
+
<div class="handlediv" title="Fare clic per cambiare."><br />
|
263 |
+
</div>
|
264 |
+
<h3 class='hndle'><span>
|
265 |
+
<?php _e ( 'Category', 'dbem' ); ?>
|
266 |
+
</span></h3>
|
267 |
+
<div class="inside">
|
268 |
+
<?php $categories = EM_Categories::get(array('orderby'=>'category_name')); ?>
|
269 |
+
<?php if( count($categories) > 0 ): ?>
|
270 |
+
<p>
|
271 |
+
<?php foreach( $categories as $EM_Category ):?>
|
272 |
+
<label><input type="checkbox" name="event_categories[]" value="<?php echo $EM_Category->id; ?>" <?php if($EM_Event->get_categories()->has($EM_Category->id)) echo 'checked="checked"'; ?> /> <?php echo $EM_Category->name ?></label><br />
|
273 |
+
<?php endforeach; ?>
|
274 |
+
</p>
|
275 |
+
<?php else: ?>
|
276 |
+
<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>
|
277 |
+
<?php endif; ?>
|
278 |
+
</div>
|
279 |
+
</div>
|
280 |
+
<!-- END Categories -->
|
281 |
+
<?php endif; ?>
|
282 |
+
<?php do_action('em_admin_event_form_side_footer'); ?>
|
283 |
+
</div>
|
284 |
+
</div>
|
285 |
+
<!-- END OF SIDEBAR -->
|
286 |
+
<div id="post-body">
|
287 |
+
<div id="post-body-content">
|
288 |
+
<?php do_action('em_admin_event_form_header'); ?>
|
289 |
+
<div id="event_name" class="stuffbox">
|
290 |
+
<h3>
|
291 |
+
<?php _e ( 'Name', 'dbem' ); ?>
|
292 |
+
</h3>
|
293 |
+
<div class="inside">
|
294 |
+
<input type="text" name="event_name" id="event-name" value="<?php echo htmlspecialchars($EM_Event->name,ENT_QUOTES); ?>" /><?php echo $required; ?>
|
295 |
+
<br />
|
296 |
+
<?php _e ( 'The event name. Example: Birthday party', 'dbem' )?>
|
297 |
+
<?php $slug_link = __('View Slug','dbem'); ?>
|
298 |
+
<a href="#" id="event-slug-trigger"><?php echo $slug_link; ?></a>
|
299 |
+
<script type="text/javascript">
|
300 |
+
jQuery(document).ready(function($){
|
301 |
+
$('#event-slug-trigger').click(function(){
|
302 |
+
if( $(this).text() == '<?php echo $slug_link; ?>'){
|
303 |
+
$('.event-slug').show();
|
304 |
+
$(this).text('<?php _e('Hide Slug','dbem'); ?>');
|
305 |
+
}else{
|
306 |
+
$('.event-slug').hide();
|
307 |
+
$(this).text('<?php echo $slug_link; ?>');
|
308 |
+
}
|
309 |
+
});
|
310 |
+
});
|
311 |
+
</script>
|
312 |
+
<p class='event-slug' style="display:none">
|
313 |
+
<?php _e('Event Slug','dbem'); ?>: <input type="text" name="event_slug" id="event-slug" value="<?php echo $EM_Event->slug; ?>" />
|
314 |
+
<br />
|
315 |
+
<?php _e ( 'The event slug. If the event slug already exists, a random number will be appended to the end.', 'dbem' )?>
|
316 |
+
</p>
|
317 |
+
</div>
|
318 |
+
</div>
|
319 |
+
<div id="event_start_date" class="stuffbox">
|
320 |
+
<h3 id='event-date-title'><?php _e ( 'Event date', 'dbem' ); ?></h3>
|
321 |
+
<h3 id='recurrence-dates-title'><?php _e ( 'Recurrence dates', 'dbem' ); ?></h3>
|
322 |
+
<div class="inside">
|
323 |
+
<input id="em-date-start-loc" type="text" />
|
324 |
+
<input id="em-date-start" type="hidden" name="event_start_date" value="<?php echo $EM_Event->start_date ?>" />
|
325 |
+
<input id="em-date-end-loc" type="text" />
|
326 |
+
<input id="em-date-end" type="hidden" name="event_end_date" value="<?php echo $EM_Event->end_date ?>" />
|
327 |
+
<br />
|
328 |
+
<span id='event-date-explanation'>
|
329 |
+
<?php
|
330 |
+
_e ( 'The event date.', 'dbem' );
|
331 |
+
/* Marcus Begin Edit */
|
332 |
+
echo " ";
|
333 |
+
_e ( 'When not reoccurring, this event spans between the beginning and end date.', 'dbem' );
|
334 |
+
/* Marcus End Edit */
|
335 |
+
?>
|
336 |
+
</span>
|
337 |
+
<span id='recurrence-dates-explanation'>
|
338 |
+
<?php _e ( 'The recurrence beginning and end date.', 'dbem' ); ?>
|
339 |
+
</span>
|
340 |
+
</div>
|
341 |
+
</div>
|
342 |
+
<div id="event_end_day" class="stuffbox">
|
343 |
+
<h3>
|
344 |
+
<?php _e ( 'Event time', 'dbem' ); ?>
|
345 |
+
</h3>
|
346 |
+
<div class="inside">
|
347 |
+
<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) ); ?>" />
|
348 |
+
-
|
349 |
+
<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) ); ?>" />
|
350 |
+
<br />
|
351 |
+
<?php _e ( 'The time of the event beginning and end', 'dbem' )?>.
|
352 |
+
</div>
|
353 |
+
</div>
|
354 |
+
<div id="location_coordinates" class="stuffbox" style='display: none;'>
|
355 |
+
<h3>
|
356 |
+
<?php _e ( 'Coordinates', 'dbem' ); ?>
|
357 |
+
</h3>
|
358 |
+
<div class="inside">
|
359 |
+
<input id='location-latitude' name='location_latitude' type='text' value='<?php echo $EM_Event->get_location()->latitude; ?>' size='15' />
|
360 |
+
-
|
361 |
+
<input id='location-longitude' name='location_longitude' type='text' value='<?php echo $EM_Event->get_location()->longitude; ?>' size='15' />
|
362 |
+
</div>
|
363 |
+
</div>
|
364 |
+
<div id="location_info" class="stuffbox">
|
365 |
+
<h3>
|
366 |
+
<?php _e ( 'Location', 'dbem' ); ?>
|
367 |
+
</h3>
|
368 |
+
<div class="inside">
|
369 |
+
<div id="em-location-data">
|
370 |
+
<table>
|
371 |
+
<?php if($use_select_for_locations) : ?>
|
372 |
+
<tr>
|
373 |
+
<th><?php _e('Location:','dbem') ?></th>
|
374 |
+
<td>
|
375 |
+
<select name="location_id" id='location-select-id' size="1">
|
376 |
+
<?php
|
377 |
+
$locations = EM_Locations::get();
|
378 |
+
foreach($locations as $location) {
|
379 |
+
$selected = "";
|
380 |
+
if ($EM_Event->get_location()->id == $location->id){
|
381 |
+
$selected = "selected='selected' ";
|
382 |
+
}
|
383 |
+
?>
|
384 |
+
<option value="<?php echo $location->id ?>" title="<?php echo "{$location->latitude},{$location->longitude}" ?>" <?php echo $selected ?>><?php echo $location->name; ?></option>
|
385 |
+
<?php
|
386 |
+
}
|
387 |
+
?>
|
388 |
+
</select>
|
389 |
+
<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>
|
390 |
+
</td>
|
391 |
+
</tr>
|
392 |
+
<?php else : ?>
|
393 |
+
<tr>
|
394 |
+
<th><?php _e ( 'Name:' )?></th>
|
395 |
+
<td>
|
396 |
+
<input id='location-id' name='location_id' type='hidden' value='<?php echo $EM_Event->get_location()->id; ?>' size='15' />
|
397 |
+
<input id="location-name" type="text" name="location_name" value="<?php echo htmlspecialchars($EM_Event->location->name, ENT_QUOTES); ?>" /><?php echo $required; ?>
|
398 |
+
<p><em><?php _e ( 'Create a location or start typing to search a previously created location.', 'dbem' )?></em></p>
|
399 |
+
<p id="em-location-reset" style="display:none;"><em><?php _e('You cannot edit saved locations here.', 'dbem'); ?> <a href="#"><?php _e('Reset this form to create a location.', 'dbem')?></a></em></p>
|
400 |
+
</td>
|
401 |
+
</tr>
|
402 |
+
<tr>
|
403 |
+
<th><?php _e ( 'Address:' )?> </th>
|
404 |
+
<td>
|
405 |
+
<input id="location-address" type="text" name="location_address" value="<?php echo htmlspecialchars($EM_Event->location->address, ENT_QUOTES); ; ?>" /><?php echo $required; ?>
|
406 |
+
</td>
|
407 |
+
</tr>
|
408 |
+
<tr>
|
409 |
+
<th><?php _e ( 'City/Town:' )?> </th>
|
410 |
+
<td>
|
411 |
+
<input id="location-town" type="text" name="location_town" value="<?php echo htmlspecialchars($EM_Event->location->town, ENT_QUOTES); ?>" /><?php echo $required; ?>
|
412 |
+
<input id="location-town-wpnonce" type="hidden" value="<?php echo wp_create_nonce('search_town'); ?>" />
|
413 |
+
</td>
|
414 |
+
</tr>
|
415 |
+
<tr>
|
416 |
+
<th><?php _e ( 'State/County:' )?> </th>
|
417 |
+
<td>
|
418 |
+
<input id="location-state" type="text" name="location_state" value="<?php echo htmlspecialchars($EM_Event->location->state, ENT_QUOTES); ?>" />
|
419 |
+
<input id="location-state-wpnonce" type="hidden" value="<?php echo wp_create_nonce('search_states'); ?>" />
|
420 |
+
</td>
|
421 |
+
</tr>
|
422 |
+
<tr>
|
423 |
+
<th><?php _e ( 'Postcode:' )?> </th>
|
424 |
+
<td>
|
425 |
+
<input id="location-postcode" type="text" name="location_postcode" value="<?php echo htmlspecialchars($EM_Event->location->postcode, ENT_QUOTES); ?>" />
|
426 |
+
</td>
|
427 |
+
</tr>
|
428 |
+
<tr>
|
429 |
+
<th><?php _e ( 'Region:' )?> </th>
|
430 |
+
<td>
|
431 |
+
<input id="location-region" type="text" name="location_region" value="<?php echo htmlspecialchars($EM_Event->location->region, ENT_QUOTES); ?>" />
|
432 |
+
<input id="location-region-wpnonce" type="hidden" value="<?php echo wp_create_nonce('search_regions'); ?>" />
|
433 |
+
</td>
|
434 |
+
</tr>
|
435 |
+
<tr>
|
436 |
+
<th><?php _e ( 'Country:' )?> </th>
|
437 |
+
<td>
|
438 |
+
<select id="location-country" name="location_country">
|
439 |
+
<option value="0" <?php echo ( $EM_Event->location->country == '' && $EM_Event->location->id == '' && get_option('dbem_location_default_country') == '' ) ? 'selected="selected"':''; ?>><?php _e('none selected','dbem'); ?></option>
|
440 |
+
<?php foreach(em_get_countries() as $country_key => $country_name): ?>
|
441 |
+
<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>
|
442 |
+
<?php endforeach; ?>
|
443 |
+
</select><?php echo $required; ?>
|
444 |
+
<!-- <p><em><?php _e('Filling this in first will allow you to quickly find previously filled states and regions for the country.','dbem'); ?></em></p> -->
|
445 |
+
</td>
|
446 |
+
</tr>
|
447 |
+
<?php endif; ?>
|
448 |
+
</table>
|
449 |
+
|
450 |
+
<?php if ( get_option( 'dbem_gmap_is_active' ) ) : ?>
|
451 |
+
<div style="width: 400px; height: 300px; float:left; ">
|
452 |
+
<div id='em-map-404' style='width: 400px; height:300px; vertical-align:middle; text-align: center;'>
|
453 |
+
<p><em><?php _e ( 'Location not found', 'dbem' ); ?></em></p>
|
454 |
+
</div>
|
455 |
+
<div id='em-map' style='width: 400px; height: 300px; display: none;'></div>
|
456 |
+
</div>
|
457 |
+
<?php endif; ?>
|
458 |
+
<br style="clear:both;" />
|
459 |
+
</div>
|
460 |
+
</div>
|
461 |
+
</div>
|
462 |
+
<div id="event_notes" class="stuffbox">
|
463 |
+
<h3>
|
464 |
+
<?php _e ( 'Details', 'dbem' ); ?>
|
465 |
+
</h3>
|
466 |
+
<div class="inside">
|
467 |
+
<div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
|
468 |
+
<?php the_editor($EM_Event->notes ); ?>
|
469 |
+
</div>
|
470 |
+
<br />
|
471 |
+
<?php _e ( 'Details about the event', 'dbem' )?>
|
472 |
+
</div>
|
473 |
+
</div>
|
474 |
+
|
475 |
+
<div id="event-image" class="stuffbox">
|
476 |
+
<h3>
|
477 |
+
<?php _e ( 'Event image', 'dbem' ); ?>
|
478 |
+
</h3>
|
479 |
+
<div class="inside" style="padding:10px;">
|
480 |
+
<?php if ($EM_Event->get_image_url() != '') : ?>
|
481 |
+
<img src='<?php echo $EM_Event->image_url; ?>' alt='<?php echo $EM_Event->name ?>'/>
|
482 |
+
<?php else : ?>
|
483 |
+
<?php _e('No image uploaded for this event yet', 'dbem') ?>
|
484 |
+
<?php endif; ?>
|
485 |
+
<br /><br />
|
486 |
+
<label for='event_image'><?php _e('Upload/change picture', 'dbem') ?></label> <input id='event-image' name='event_image' id='event_image' type='file' size='40' />
|
487 |
+
</div>
|
488 |
+
</div>
|
489 |
+
|
490 |
+
<?php if(get_option('dbem_rsvp_enabled')) : ?>
|
491 |
+
<div id="event-bookings" class="stuffbox">
|
492 |
+
<h3><span><?php _e('Bookings/Registration','dbem'); ?></span></h3>
|
493 |
+
<div class="inside">
|
494 |
+
<div class="wrap">
|
495 |
+
<div id="event-rsvp-box">
|
496 |
+
<input id="event-rsvp" name='event_rsvp' value='1' type='checkbox' <?php echo ($EM_Event->rsvp) ? 'checked="checked"' : ''; ?> />
|
497 |
+
|
498 |
+
<?php _e ( 'Enable registration for this event', 'dbem' )?>
|
499 |
+
</div>
|
500 |
+
<div id="event-tickets" style="<?php echo ($EM_Event->rsvp) ? '':'display:none;' ?>">
|
501 |
+
<?php
|
502 |
+
//get tickets here and if there are none, create a blank ticket
|
503 |
+
$EM_Tickets = $EM_Event->get_bookings()->get_tickets();
|
504 |
+
if( count($EM_Tickets->tickets) == 0 ){
|
505 |
+
$EM_Tickets->tickets[] = new EM_Ticket();
|
506 |
+
$delete_temp_ticket = true;
|
507 |
+
}
|
508 |
+
if( get_option('dbem_bookings_tickets_single') ){
|
509 |
+
$EM_Ticket = $EM_Tickets->get_first();
|
510 |
+
include( em_locate_template('forms/ticket-form.php') );
|
511 |
+
}else{
|
512 |
+
?>
|
513 |
+
<p><strong><?php _e('Tickets','dbem'); ?></strong></p>
|
514 |
+
<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>
|
515 |
+
<table class="form-table">
|
516 |
+
<thead>
|
517 |
+
<tr valign="top">
|
518 |
+
<th class="ticket-status"> </th>
|
519 |
+
<th><?php _e('Ticket Name','dbem'); ?></th>
|
520 |
+
<th><?php _e('Price','dbem'); ?></th>
|
521 |
+
<th><?php _e('Min/Max','dbem'); ?></th>
|
522 |
+
<th><?php _e('Start/End','dbem'); ?></th>
|
523 |
+
<th><?php _e('Avail. Spaces','dbem'); ?></th>
|
524 |
+
<th><?php _e('Booked Spaces','dbem'); ?></th>
|
525 |
+
<th> </th>
|
526 |
+
</tr>
|
527 |
+
</thead>
|
528 |
+
<tfoot>
|
529 |
+
<tr valign="top">
|
530 |
+
<td colspan="6">
|
531 |
+
<a href="#" id="em-tickets-add" rel="#em-tickets-form"><?php _e('Add new ticket','dbem'); ?></a>
|
532 |
+
</td>
|
533 |
+
</tr>
|
534 |
+
</tfoot>
|
535 |
+
<tbody id="em-tickets-body">
|
536 |
+
<?php
|
537 |
+
$count = 1;
|
538 |
+
foreach( $EM_Tickets->tickets as $EM_Ticket){
|
539 |
+
?>
|
540 |
+
<tr valign="top" id="em-tickets-row-<?php echo $count ?>" class="em-tickets-row">
|
541 |
+
<td class="ticket-status"><span class="<?php echo ($EM_Ticket->is_available()) ? 'ticket_on':'ticket_off'; ?>"></span></td>
|
542 |
+
<td class="ticket-name"><span class="ticket_name"><?php echo $EM_Ticket->name ?></span><br /><span class="ticket_description"><?php echo $EM_Ticket->description; ?></span></td>
|
543 |
+
<td class="ticket-price">
|
544 |
+
<span class="ticket_price"><?php echo ($EM_Ticket->price) ? $EM_Ticket->price : __('Free','dbem'); ?></span>
|
545 |
+
</td>
|
546 |
+
<td class="ticket-limit">
|
547 |
+
<span class="ticket_min">
|
548 |
+
<?php echo ( !empty($EM_Ticket->min) ) ? $EM_Ticket->min:'-'; ?>
|
549 |
+
</span> /
|
550 |
+
<span class="ticket_max"><?php echo ( !empty($EM_Ticket->max) ) ? $EM_Ticket->max:'-'; ?></span>
|
551 |
+
</td>
|
552 |
+
<td class="ticket-time">
|
553 |
+
<span class="ticket_start"><?php echo ( !empty($EM_Ticket->start) ) ? date($localised_date_format, $EM_Ticket->start_timestamp):''; ?></span> -
|
554 |
+
<span class="ticket_end"><?php echo ( !empty($EM_Ticket->end) ) ? date($localised_date_format, $EM_Ticket->end_timestamp):''; ?></span>
|
555 |
+
</td>
|
556 |
+
<td class="ticket-qty">
|
557 |
+
<span class="ticket_available_spaces"><?php echo $EM_Ticket->get_available_spaces(); ?></span>/
|
558 |
+
<span class="ticket_spaces">
|
559 |
+
<?php
|
560 |
+
if( $EM_Ticket->get_spaces() ){
|
561 |
+
echo $EM_Ticket->get_spaces();
|
562 |
+
echo ($EM_Ticket->spaces_limit) ? '':'*';
|
563 |
+
}else{
|
564 |
+
echo '-';
|
565 |
+
}
|
566 |
+
?>
|
567 |
+
</span>
|
568 |
+
</td>
|
569 |
+
<td class="ticket-booked-spaces">
|
570 |
+
<span class="ticket_booked_spaces"><?php echo $EM_Ticket->get_booked_spaces(); ?></span>
|
571 |
+
</td>
|
572 |
+
<td class="ticket-actions">
|
573 |
+
<a href="#" class="ticket-actions-edit"><?php _e('Edit','dbem'); ?></a>
|
574 |
+
<?php if( count($EM_Ticket->get_bookings()->bookings) == 0 ): ?>
|
575 |
+
| <a href="<?php bloginfo('wpurl'); ?>/wp-load.php" class="ticket-actions-delete"><?php _e('Delete','dbem'); ?></a>
|
576 |
+
<?php else: ?>
|
577 |
+
| <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>
|
578 |
+
<?php endif; ?>
|
579 |
+
<input type="hidden" class="ticket_id" name="em_tickets[<?php echo $count; ?>][ticket_id]" value="<?php echo $EM_Ticket->id ?>" />
|
580 |
+
<input type="hidden" class="ticket_name" name="em_tickets[<?php echo $count; ?>][ticket_name]" value="<?php echo $EM_Ticket->name ?>" />
|
581 |
+
<input type="hidden" class="ticket_description" name="em_tickets[<?php echo $count; ?>][ticket_description]" value="<?php echo $EM_Ticket->description ?>" />
|
582 |
+
<input type="hidden" class="ticket_price" name="em_tickets[<?php echo $count; ?>][ticket_price]" value="<?php echo $EM_Ticket->price ?>" />
|
583 |
+
<input type="hidden" class="ticket_spaces" name="em_tickets[<?php echo $count; ?>][ticket_spaces]" value="<?php echo $EM_Ticket->spaces ?>" />
|
584 |
+
<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):''; ?>" />
|
585 |
+
<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):''; ?>" />
|
586 |
+
<input type="hidden" class="ticket_min" name="em_tickets[<?php echo $count; ?>][ticket_min]" value="<?php echo $EM_Ticket->min ?>" />
|
587 |
+
<input type="hidden" class="ticket_max" name="em_tickets[<?php echo $count; ?>][ticket_max]" value="<?php echo $EM_Ticket->max ?>" />
|
588 |
+
</td>
|
589 |
+
</tr>
|
590 |
+
<?php
|
591 |
+
$count++;
|
592 |
+
}
|
593 |
+
if( !empty($delete_temp_ticket) ){
|
594 |
+
array_pop($EM_Tickets->tickets);
|
595 |
+
}
|
596 |
+
?>
|
597 |
+
</tbody>
|
598 |
+
</table>
|
599 |
+
<?php } ?>
|
600 |
+
</div>
|
601 |
+
</div>
|
602 |
+
</div>
|
603 |
+
</div>
|
604 |
+
<?php endif; ?>
|
605 |
+
|
606 |
+
<?php if(get_option('dbem_attributes_enabled')) : ?>
|
607 |
+
<div id="event-attributes" class="stuffbox">
|
608 |
+
<h3>
|
609 |
+
<?php _e ( 'Attributes', 'dbem' ); ?>
|
610 |
+
</h3>
|
611 |
+
<div class="inside">
|
612 |
+
<?php
|
613 |
+
$attributes = em_get_attributes();
|
614 |
+
$has_depreciated = false;
|
615 |
+
?>
|
616 |
+
<div class="wrap">
|
617 |
+
<?php if( !empty($attributes['names']) && count( $attributes['names'] ) > 0 ) : ?>
|
618 |
+
<table class="form-table">
|
619 |
+
<thead>
|
620 |
+
<tr valign="top">
|
621 |
+
<td><strong>Attribute Name</strong></td>
|
622 |
+
<td><strong>Value</strong></td>
|
623 |
+
</tr>
|
624 |
+
</thead>
|
625 |
+
<tbody id="mtm_body">
|
626 |
+
<?php
|
627 |
+
$count = 1;
|
628 |
+
foreach( $attributes['names'] as $name){
|
629 |
+
?>
|
630 |
+
<tr valign="top" id="em_attribute_<?php echo $count ?>">
|
631 |
+
<td scope="row"><?php echo $name ?></td>
|
632 |
+
<td>
|
633 |
+
<?php if( count($attributes['values'][$name]) > 0 ): ?>
|
634 |
+
<select name="em_attributes[<?php echo $name ?>]">
|
635 |
+
<option><?php echo __('No Value','dbem'); ?></option>
|
636 |
+
<?php foreach($attributes['values'][$name] as $attribute_val): ?>
|
637 |
+
<?php if( array_key_exists($name, $EM_Event->attributes) && $EM_Event->attributes[$name]==$attribute_val ): ?>
|
638 |
+
<option selected="selected"><?php echo $attribute_val; ?></option>
|
639 |
+
<?php else: ?>
|
640 |
+
<option><?php echo $attribute_val; ?></option>
|
641 |
+
<?php endif; ?>
|
642 |
+
<?php endforeach; ?>
|
643 |
+
</select>
|
644 |
+
<?php else: ?>
|
645 |
+
<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):''; ?>" />
|
646 |
+
<?php endif; ?>
|
647 |
+
</td>
|
648 |
+
</tr>
|
649 |
+
<?php
|
650 |
+
$count++;
|
651 |
+
}
|
652 |
+
if($count == 1){
|
653 |
+
?>
|
654 |
+
<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>
|
655 |
+
<?php
|
656 |
+
}
|
657 |
+
?>
|
658 |
+
</tbody>
|
659 |
+
</table>
|
660 |
+
<?php if( count(array_diff(array_keys($EM_Event->attributes), $attributes['names'])) > 0 ): ?>
|
661 |
+
<p><strong><?php _e('Depreciated Attributes')?></strong></p>
|
662 |
+
<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>
|
663 |
+
<table class="form-table">
|
664 |
+
<thead>
|
665 |
+
<tr valign="top">
|
666 |
+
<td><strong>Attribute Name</strong></td>
|
667 |
+
<td><strong>Value</strong></td>
|
668 |
+
</tr>
|
669 |
+
</thead>
|
670 |
+
<tbody id="mtm_body">
|
671 |
+
<?php
|
672 |
+
if( is_array($EM_Event->attributes) and count($EM_Event->attributes) > 0){
|
673 |
+
foreach( $EM_Event->attributes as $name => $value){
|
674 |
+
if( !in_array($name, $attributes['names']) ){
|
675 |
+
?>
|
676 |
+
<tr valign="top" id="em_attribute_<?php echo $count ?>">
|
677 |
+
<td scope="row"><?php echo $name ?></td>
|
678 |
+
<td>
|
679 |
+
<input type="text" name="em_attributes[<?php echo $name ?>]" value="<?php echo htmlspecialchars($value, ENT_QUOTES); ?>" />
|
680 |
+
</td>
|
681 |
+
</tr>
|
682 |
+
<?php
|
683 |
+
$count++;
|
684 |
+
}
|
685 |
+
}
|
686 |
+
}
|
687 |
+
?>
|
688 |
+
</tbody>
|
689 |
+
</table>
|
690 |
+
<?php endif; ?>
|
691 |
+
<?php else : ?>
|
692 |
+
<p>
|
693 |
+
<?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'); ?>
|
694 |
+
</p>
|
695 |
+
<script>
|
696 |
+
jQuery(document).ready(function($){ $('#event_attributes').addClass('closed'); });
|
697 |
+
</script>
|
698 |
+
<?php endif; ?>
|
699 |
+
</div>
|
700 |
+
</div>
|
701 |
+
</div>
|
702 |
+
<?php endif; ?>
|
703 |
+
<?php do_action('em_admin_event_form_footer'); ?>
|
704 |
+
</div>
|
705 |
+
<p class="submit">
|
706 |
+
<?php
|
707 |
+
if ( $EM_Event->is_recurring() ) {
|
708 |
+
$recurrence_delete_confirm = __('WARNING! You are about to re-create all your recurrent events including erasing your old booking data! Are you sure you want to do this?','dbem');
|
709 |
+
$js = 'onclick = "if( !confirm(\''. $recurrence_delete_confirm.'\') ){ return false; }"';
|
710 |
+
}
|
711 |
+
?>
|
712 |
+
<input type="submit" name="events_update" value="<?php _e ( 'Submit Event', 'dbem' ); ?> »" <?php if(!empty($js)) echo $js; ?> />
|
713 |
+
</p>
|
714 |
+
<input type="hidden" name="p" value="<?php echo ( !empty($_REQUEST['pno']) ) ? $_REQUEST['pno']:''; ?>" /><a>
|
715 |
+
<input type="hidden" name="scope" value="<?php echo ( !empty($_REQUEST['scope']) ) ? $_REQUEST['scope']:'' ?>" /></a>
|
716 |
+
<input type="hidden" name="event_id" value="<?php echo $EM_Event->id; ?>" />
|
717 |
+
<input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('wpnonce_event_save'); ?>" />
|
718 |
+
<input type="hidden" name="action" value="event_save" />
|
719 |
+
</div>
|
720 |
+
</div>
|
721 |
+
</div>
|
722 |
+
</form>
|
723 |
+
<?php
|
724 |
+
if( !get_option('dbem_bookings_tickets_single') ){
|
725 |
+
em_locate_template('forms/tickets-form.php', true); //put here as it can't be in the add event form
|
726 |
+
}
|
727 |
+
?>
|
728 |
+
<script type="text/javascript">
|
729 |
+
jQuery(document).ready( function($) {
|
730 |
+
<?php if( $EM_Event->is_recurring() ): ?>
|
731 |
+
//Recurrence Warnings
|
732 |
+
$('#event_form').submit( function(event){
|
733 |
+
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'); ?>');
|
734 |
+
if( confirmation == false ){
|
735 |
+
event.preventDefault();
|
736 |
+
}
|
737 |
+
});
|
738 |
+
<?php endif; ?>
|
739 |
+
<?php if( get_option('dbem_rsvp_enabled') ): ?>
|
740 |
+
//RSVP Warning
|
741 |
+
$('#event-rsvp').click( function(event){
|
742 |
+
if( !this.checked ){
|
743 |
+
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'); ?>');
|
744 |
+
if( confirmation == false ){
|
745 |
+
event.preventDefault();
|
746 |
+
}else{
|
747 |
+
$('#event-tickets').hide();
|
748 |
+
$("div#rsvp-data").hide();
|
749 |
+
}
|
750 |
+
}else{
|
751 |
+
$('#event-tickets').fadeIn();
|
752 |
+
$("div#rsvp-data").fadeIn();
|
753 |
+
}
|
754 |
+
});
|
755 |
+
|
756 |
+
if($('input#event-rsvp').attr("checked")) {
|
757 |
+
$("div#rsvp-data").fadeIn();
|
758 |
+
} else {
|
759 |
+
$("div#rsvp-data").hide();
|
760 |
+
}
|
761 |
+
<?php endif; ?>
|
762 |
+
});
|
763 |
+
</script>
|
764 |
+
<?php
|
765 |
+
}
|
766 |
?>
|
admin/em-events.php
CHANGED
@@ -1,242 +1,238 @@
|
|
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 |
-
|
11 |
-
$action = ( !empty($
|
12 |
-
$order = ( !empty($
|
13 |
-
$limit = ( !empty($
|
14 |
-
$page = ( !empty($
|
15 |
-
$offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
|
16 |
-
$
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
$
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
</div>
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
<
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
<
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
<
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
<
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
<
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
?>
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
<?php
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
<div class="
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
</div>
|
239 |
-
<?php
|
240 |
-
}
|
241 |
-
|
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 = em_get_scopes();
|
18 |
+
$scope = ( !empty($_REQUEST ['scope']) && array_key_exists($_REQUEST ['scope'], $scope_names) ) ? $_REQUEST ['scope']:'future';
|
19 |
+
$selectedEvents = ( !empty($_REQUEST ['events']) ) ? $_REQUEST ['events']:'';
|
20 |
+
|
21 |
+
$args = array('scope'=>$scope, 'limit'=>0, 'order'=>$order, 'search'=>$search );
|
22 |
+
|
23 |
+
if( !current_user_can('edit_others_events') ){
|
24 |
+
$args['owner'] = get_current_user_id();
|
25 |
+
}
|
26 |
+
//Figure out what status to search for
|
27 |
+
$args['status'] = ( isset($_REQUEST['status']) && is_numeric($_REQUEST['status']) ) ? $_REQUEST['status'] : false;
|
28 |
+
|
29 |
+
$events = EM_Events::get( $args );
|
30 |
+
$events_count = count ( $events );
|
31 |
+
$pending_count = EM_Events::count( array('status'=>0, 'scope'=>$scope) );
|
32 |
+
$approved_count = EM_Events::count( array('status'=> 1, 'scope'=>$scope) );
|
33 |
+
$total_count = EM_Events::count( array('status'=> false, 'scope'=>$scope) );
|
34 |
+
|
35 |
+
$use_events_end = get_option('dbem_use_event_end');
|
36 |
+
echo $EM_Notices;
|
37 |
+
?>
|
38 |
+
<div class="wrap">
|
39 |
+
<div id="icon-events" class="icon32"><br />
|
40 |
+
</div>
|
41 |
+
<h2>
|
42 |
+
<?php echo $scope_names[$scope]; ?>
|
43 |
+
<a href="admin.php?page=events-manager-event" class="button add-new-h2"><?php _e('Add New','dbem'); ?></a>
|
44 |
+
</h2>
|
45 |
+
<?php
|
46 |
+
$link = array ();
|
47 |
+
$link ['past'] = "<a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&scope=past&order=desc'>" . __ ( 'Past events', 'dbem' ) . "</a>";
|
48 |
+
$link ['all'] = " <a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&scope=all&order=desc'>" . __ ( 'All events', 'dbem' ) . "</a>";
|
49 |
+
$link ['future'] = " <a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&scope=future'>" . __ ( 'Future events', 'dbem' ) . "</a>";
|
50 |
+
?>
|
51 |
+
<?php if ( !empty($_REQUEST['error']) ) : ?>
|
52 |
+
<div id='message' class='error'>
|
53 |
+
<p><?php echo $_REQUEST['error']; ?></p>
|
54 |
+
</div>
|
55 |
+
<?php endif; ?>
|
56 |
+
<?php if ( !empty($_REQUEST['message']) ) : ?>
|
57 |
+
<div id='message' class='updated fade'>
|
58 |
+
<p><?php echo $_REQUEST['message']; ?></p>
|
59 |
+
</div>
|
60 |
+
<?php endif; ?>
|
61 |
+
<form id="posts-filter" action="" method="get"><input type='hidden' name='page' value='events-manager' />
|
62 |
+
<ul class="subsubsub">
|
63 |
+
<li><a href='<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&scope=<?php echo $scope; ?>' <?php echo ( !isset($_REQUEST['status']) ) ? 'class="current"':''; ?>><?php _e ( 'Total', 'dbem' ); ?> <span class="count">(<?php echo $total_count; ?>)</span></a></li>
|
64 |
+
<?php if( current_user_can('publish_events') ): ?>
|
65 |
+
<li>| <a href='<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&scope=<?php echo $scope; ?>&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>
|
66 |
+
<li>| <a href='<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&scope=<?php echo $scope; ?>&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>
|
67 |
+
<?php endif; ?>
|
68 |
+
</ul>
|
69 |
+
<p class="search-box">
|
70 |
+
<label class="screen-reader-text" for="post-search-input"><?php _e('Search Events','dbem'); ?>:</label>
|
71 |
+
<input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_REQUEST['em_search'])) ? $_REQUEST['em_search']:''; ?>" />
|
72 |
+
<input type="submit" value="<?php _e('Search Events','dbem'); ?>" class="button" />
|
73 |
+
</p>
|
74 |
+
<div class="tablenav">
|
75 |
+
|
76 |
+
<div class="alignleft actions">
|
77 |
+
<select name="action">
|
78 |
+
<option value="-1" selected="selected"><?php _e ( 'Bulk Actions' ); ?></option>
|
79 |
+
<option value="event_delete"><?php _e ( 'Delete selected','dbem' ); ?></option>
|
80 |
+
</select>
|
81 |
+
<input type="submit" value="<?php _e ( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
|
82 |
+
<select name="scope">
|
83 |
+
<?php
|
84 |
+
foreach ( $scope_names as $key => $value ) {
|
85 |
+
$selected = "";
|
86 |
+
if ($key == $scope)
|
87 |
+
$selected = "selected='selected'";
|
88 |
+
echo "<option value='$key' $selected>$value</option> ";
|
89 |
+
}
|
90 |
+
?>
|
91 |
+
</select>
|
92 |
+
<input id="post-query-submit" class="button-secondary" type="submit" value="<?php _e ( 'Filter' )?>" />
|
93 |
+
</div>
|
94 |
+
<!--
|
95 |
+
<div class="view-switch">
|
96 |
+
<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>
|
97 |
+
</div>
|
98 |
+
-->
|
99 |
+
<?php
|
100 |
+
if ( $events_count >= $limit ) {
|
101 |
+
$events_nav = em_admin_paginate( $events_count, $limit, $page);
|
102 |
+
echo $events_nav;
|
103 |
+
}
|
104 |
+
?>
|
105 |
+
<br class="clear" />
|
106 |
+
</div>
|
107 |
+
|
108 |
+
<?php
|
109 |
+
if (empty ( $events )) {
|
110 |
+
// TODO localize
|
111 |
+
_e ( 'no events','dbem' );
|
112 |
+
} else {
|
113 |
+
?>
|
114 |
+
|
115 |
+
<table class="widefat events-table">
|
116 |
+
<thead>
|
117 |
+
<tr>
|
118 |
+
<th class='manage-column column-cb check-column' scope='col'>
|
119 |
+
<input class='select-all' type="checkbox" value='1' />
|
120 |
+
</th>
|
121 |
+
<th><?php _e ( 'Name', 'dbem' ); ?></th>
|
122 |
+
<th> </th>
|
123 |
+
<th><?php _e ( 'Location', 'dbem' ); ?></th>
|
124 |
+
<th colspan="2"><?php _e ( 'Date and time', 'dbem' ); ?></th>
|
125 |
+
</tr>
|
126 |
+
</thead>
|
127 |
+
<tbody>
|
128 |
+
<?php
|
129 |
+
$rowno = 0;
|
130 |
+
$event_count = 0;
|
131 |
+
foreach ( $events as $event ) {
|
132 |
+
/* @var $event EM_Event */
|
133 |
+
if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
|
134 |
+
$rowno++;
|
135 |
+
$class = ($rowno % 2) ? 'alternate' : '';
|
136 |
+
// FIXME set to american
|
137 |
+
$localised_start_date = date_i18n('D d M Y', $event->start);
|
138 |
+
$localised_end_date = date_i18n('D d M Y', $event->end);
|
139 |
+
$style = "";
|
140 |
+
$today = date ( "Y-m-d" );
|
141 |
+
$location_summary = "<b>" . $event->location->name . "</b><br/>" . $event->location->address . " - " . $event->location->town;
|
142 |
+
|
143 |
+
if ($event->start_date < $today && $event->end_date < $today){
|
144 |
+
$class .= " past";
|
145 |
+
}
|
146 |
+
//Check pending approval events
|
147 |
+
if ( !$event->status ){
|
148 |
+
$class .= " pending";
|
149 |
+
}
|
150 |
+
?>
|
151 |
+
<tr class="event <?php echo trim($class); ?>" <?php echo $style; ?> id="event_<?php echo $event->id ?>">
|
152 |
+
<td>
|
153 |
+
<input type='checkbox' class='row-selector' value='<?php echo $event->id; ?>' name='events[]' />
|
154 |
+
</td>
|
155 |
+
<td>
|
156 |
+
<strong>
|
157 |
+
<a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&event_id=<?php echo $event->id ?>&scope=<?php echo $scope ?>&pno=<?php echo $page ?>"><?php echo ($event->name); ?></a>
|
158 |
+
</strong>
|
159 |
+
<?php
|
160 |
+
if( get_option('dbem_rsvp_enabled') == 1 && $event->rsvp == 1 ){
|
161 |
+
?>
|
162 |
+
<br/>
|
163 |
+
<a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&event_id=<?php echo $event->id ?>"><?php echo __("Bookings",'dbem'); ?></a> –
|
164 |
+
<?php _e("Booked",'dbem'); ?>: <?php echo $event->get_bookings()->get_booked_spaces()."/".$event->get_spaces(); ?>
|
165 |
+
<?php if( get_option('dbem_bookings_approval') == 1 ): ?>
|
166 |
+
| <?php _e("Pending",'dbem') ?>: <?php echo $event->get_bookings()->get_pending_spaces(); ?>
|
167 |
+
<?php endif;
|
168 |
+
}
|
169 |
+
?>
|
170 |
+
<div class="row-actions">
|
171 |
+
<span class="trash"><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&action=event_delete&event_id=<?php echo $event->id ?>&scope=<?php echo $scope ?>&pno=<?php echo $page ?>" class="em-event-delete"><?php _e('Delete','dbem'); ?></a></span>
|
172 |
+
<?php if( !$event->status && current_user_can('publish_others_events') ): ?>
|
173 |
+
| <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&action=event_approve&event_id=<?php echo $event->id ?>&scope=<?php echo $scope ?>&pno=<?php echo $page ?>" class="em-event-approve" style="color:green"><?php _e('Approve','dbem'); ?></a>
|
174 |
+
<?php endif; ?>
|
175 |
+
</div>
|
176 |
+
</td>
|
177 |
+
<td>
|
178 |
+
<a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&action=event_duplicate&event_id=<?php echo $event->id; ?>&scope=<?php echo $scope ?>&pno=<?php echo $page ?>" title="<?php _e ( 'Duplicate this event', 'dbem' ); ?>">
|
179 |
+
<strong>+</strong>
|
180 |
+
</a>
|
181 |
+
</td>
|
182 |
+
<td>
|
183 |
+
<?php echo $location_summary; ?>
|
184 |
+
</td>
|
185 |
+
|
186 |
+
<td>
|
187 |
+
<?php echo $localised_start_date; ?>
|
188 |
+
<?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
|
189 |
+
<br />
|
190 |
+
<?php
|
191 |
+
//TODO Should 00:00 - 00:00 be treated as an all day event?
|
192 |
+
echo substr ( $event->start_time, 0, 5 ) . " - " . substr ( $event->end_time, 0, 5 );
|
193 |
+
?>
|
194 |
+
</td>
|
195 |
+
<td>
|
196 |
+
<?php
|
197 |
+
if ( $event->is_recurrence() ) {
|
198 |
+
$recurrence_delete_confirm = __('WARNING! You will delete ALL recurrences of this event, including booking history associated with any event in this recurrence. To keep booking information, go to the relevant single event and save it to detach it from this recurrence series.','dbem');
|
199 |
+
?>
|
200 |
+
<strong>
|
201 |
+
<?php echo $event->get_recurrence_description(); ?> <br />
|
202 |
+
<a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&event_id=<?php echo $event->recurrence_id ?>&scope=<?php echo $scope ?>&pno=<?php echo $page ?>"><?php _e ( 'Reschedule', 'dbem' ); ?></a> |
|
203 |
+
<span class="trash"><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&action=event_delete&event_id=<?php echo $event->recurrence_id ?>&scope=<?php echo $scope ?>&pno=<?php echo $page ?>" class="em-event-rec-delete" onclick ="if( !confirm('<?php echo $recurrence_delete_confirm; ?>') ){ return false; }"><?php _e('Delete','dbem'); ?></a></span>
|
204 |
+
</strong>
|
205 |
+
<?php
|
206 |
+
}
|
207 |
+
?>
|
208 |
+
</td>
|
209 |
+
</tr>
|
210 |
+
<?php
|
211 |
+
}
|
212 |
+
$event_count++;
|
213 |
+
}
|
214 |
+
?>
|
215 |
+
</tbody>
|
216 |
+
</table>
|
217 |
+
<?php
|
218 |
+
} // end of table
|
219 |
+
?>
|
220 |
+
<div class='tablenav'>
|
221 |
+
<div class="alignleft actions">
|
222 |
+
<br class='clear' />
|
223 |
+
</div>
|
224 |
+
<?php if ( $events_count >= $limit ) : ?>
|
225 |
+
<div class="tablenav-pages">
|
226 |
+
<?php
|
227 |
+
echo $events_nav;
|
228 |
+
?>
|
229 |
+
</div>
|
230 |
+
<?php endif; ?>
|
231 |
+
<br class='clear' />
|
232 |
+
</div>
|
233 |
+
</form>
|
234 |
+
</div>
|
235 |
+
<?php
|
236 |
+
}
|
237 |
+
|
|
|
|
|
|
|
|
|
238 |
?>
|
admin/em-help.php
CHANGED
@@ -1,52 +1,54 @@
|
|
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="
|
20 |
-
<?php echo em_docs_placeholders( array('type'=>'
|
21 |
-
<h3><a name="
|
22 |
-
<?php echo em_docs_placeholders( array('type'=>'
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
<p>
|
36 |
-
|
37 |
-
|
38 |
-
<p
|
39 |
-
<
|
40 |
-
|
41 |
-
|
42 |
-
<li
|
43 |
-
<li>
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
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="category-placeholders"><?php _e('Category Related Placeholders','dbem'); ?></a></h3>
|
20 |
+
<?php echo em_docs_placeholders( array('type'=>'categories') ); ?>
|
21 |
+
<h3><a name="location-placeholders"><?php _e('Location Related Placeholders','dbem'); ?></a></h3>
|
22 |
+
<?php echo em_docs_placeholders( array('type'=>'locations') ); ?>
|
23 |
+
<h3><a name="booking-placeholders"><?php _e('Booking Related Placeholders','dbem'); ?></a></h3>
|
24 |
+
<?php echo em_docs_placeholders( array('type'=>'bookings') ); ?>
|
25 |
+
</div>
|
26 |
+
<?php
|
27 |
+
//Is this a previously imported installation?
|
28 |
+
$old_table_name = $wpdb->prefix.'dbem_events';
|
29 |
+
if( $wpdb->get_var("SHOW TABLES LIKE '$old_table_name'") == $old_table_name ){
|
30 |
+
?>
|
31 |
+
<hr style="margin:30px 10px;" />
|
32 |
+
<div class="updated">
|
33 |
+
<h3>Troubleshooting upgrades from version 2.x to 3.x</h3>
|
34 |
+
<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>
|
35 |
+
<p>If something went wrong with the update to version 3 read on:</p>
|
36 |
+
<h4>Scenario 1: the plugin is working, but for some reason the old events weren't imported</h4>
|
37 |
+
<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>
|
38 |
+
<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>
|
39 |
+
<h4>Scenario 2: the plugin is not working, I want to go back to version 2!</h4>
|
40 |
+
<p>You can safely downgrade and will not lose any information.</p>
|
41 |
+
<ol>
|
42 |
+
<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>
|
43 |
+
<li>Deactivate and delete Events Manager in the plugin page</li>
|
44 |
+
<li><a href="<?php bloginfo('wpurl'); ?>/wp-admin/plugin-install.php?tab=upload">Upload the zip file you just downloaded here</a></li>
|
45 |
+
<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>
|
46 |
+
</ol>
|
47 |
+
</div>
|
48 |
+
<?php
|
49 |
+
}
|
50 |
+
?>
|
51 |
+
</div>
|
52 |
+
<?php
|
53 |
+
}
|
54 |
?>
|
admin/em-locations-search.php
CHANGED
@@ -3,20 +3,24 @@
|
|
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 =
|
10 |
-
$location_cond = (
|
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 |
-
|
|
|
|
|
20 |
FROM $locations_table
|
21 |
WHERE ( `location_name` LIKE %s ) $location_cond LIMIT 10
|
22 |
", $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 |
+
//FIXME just plug loc search into ajax catcher
|
7 |
require_once('../../../../wp-load.php');
|
8 |
global $wpdb;
|
9 |
|
10 |
+
$locations_table = 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);
|
admin/em-locations.php
CHANGED
@@ -1,268 +1,310 @@
|
|
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'])
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
<
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
?>
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
</div>
|
183 |
-
</div>
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
<
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
?>
|
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(array('blog'=>false));
|
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(), 'blog'=>false) );
|
31 |
+
$locations_mine_count = count($locations);
|
32 |
+
$locations_all_count = current_user_can('read_others_locations') ? EM_Locations::count(array('blog'=>false)):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 |
+
|
|
55 |
+
<a href='admin.php?page=events-manager-locations&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 |
+
<th><?php _e('State', 'dbem') ?></th>
|
82 |
+
<th><?php _e('Country', 'dbem') ?></th>
|
83 |
+
</tr>
|
84 |
+
</thead>
|
85 |
+
<tfoot>
|
86 |
+
<tr>
|
87 |
+
<th class='manage-column column-cb check-column' scope='col'><input type='checkbox' class='select-all' value='1'/></th>
|
88 |
+
<th><?php _e('Name', 'dbem') ?></th>
|
89 |
+
<th><?php _e('Address', 'dbem') ?></th>
|
90 |
+
<th><?php _e('Town', 'dbem') ?></th>
|
91 |
+
<th><?php _e('State', 'dbem') ?></th>
|
92 |
+
<th><?php _e('Country', 'dbem') ?></th>
|
93 |
+
</tr>
|
94 |
+
</tfoot>
|
95 |
+
<tbody>
|
96 |
+
<?php $i = 1; ?>
|
97 |
+
<?php foreach ($locations as $EM_Location) : ?>
|
98 |
+
<?php if( $i >= $offset && $i <= $offset+$limit ): ?>
|
99 |
+
<tr>
|
100 |
+
<td><input type='checkbox' class ='row-selector' value='<?php echo $EM_Location->id ?>' name='locations[]'/></td>
|
101 |
+
<td><a href='admin.php?page=events-manager-locations&action=edit&location_id=<?php echo $EM_Location->id ?>'><?php echo $EM_Location->name ?></a></td>
|
102 |
+
<td><?php echo $EM_Location->address ?></td>
|
103 |
+
<td><?php echo $EM_Location->town ?></td>
|
104 |
+
<td><?php echo $EM_Location->state ?></td>
|
105 |
+
<td><?php echo $EM_Location->get_country() ?></td>
|
106 |
+
</tr>
|
107 |
+
<?php endif; ?>
|
108 |
+
<?php $i++; ?>
|
109 |
+
<?php endforeach; ?>
|
110 |
+
</tbody>
|
111 |
+
</table>
|
112 |
+
<?php else: ?>
|
113 |
+
<p><?php _e('No venues have been inserted yet!', 'dbem') ?></p>
|
114 |
+
<?php endif; ?>
|
115 |
+
</form>
|
116 |
+
</div>
|
117 |
+
<?php
|
118 |
+
}
|
119 |
+
|
120 |
+
function em_admin_location($message = "") {
|
121 |
+
global $EM_Location, $EM_Notices;
|
122 |
+
//check that user can access this page
|
123 |
+
if( is_object($EM_Location) && !$EM_Location->can_manage('edit_locations','edit_others_locations') ){
|
124 |
+
?>
|
125 |
+
<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>
|
126 |
+
<?php
|
127 |
+
return false;
|
128 |
+
}
|
129 |
+
if( empty($EM_Location) || !is_object($EM_Location) ){
|
130 |
+
$title = __('Add location', 'dbem');
|
131 |
+
$EM_Location = new EM_Location();
|
132 |
+
}else{
|
133 |
+
$title = __('Edit location', 'dbem');
|
134 |
+
}
|
135 |
+
$required = "<i>(".__('required','dbem').")</i>";
|
136 |
+
echo $EM_Notices;
|
137 |
+
?>
|
138 |
+
<form enctype='multipart/form-data' name='editcat' id='location-form' method='post' action='admin.php?page=events-manager-locations' class='validate'>
|
139 |
+
<input type='hidden' name='action' value='location_save' />
|
140 |
+
<input type='hidden' name='_wpnonce' value='<?php echo wp_create_nonce('location_save'); ?>' />
|
141 |
+
<input type='hidden' name='location_id' value='<?php echo $EM_Location->id ?>'/>
|
142 |
+
<div class='wrap'>
|
143 |
+
<div id='icon-edit' class='icon32'>
|
144 |
+
<br/>
|
145 |
+
</div>
|
146 |
+
<h2><?php echo $title ?></h2>
|
147 |
+
|
148 |
+
<?php global $EM_Notices; echo $EM_Notices; ?>
|
149 |
+
<div id='ajax-response'></div>
|
150 |
+
|
151 |
+
<div id="poststuff" class="metabox-holder">
|
152 |
+
<div id="post-body">
|
153 |
+
<div id="post-body-content">
|
154 |
+
<div id="location_name" class="stuffbox">
|
155 |
+
<h3>
|
156 |
+
<?php _e ( 'Location Name', 'dbem' ); ?>
|
157 |
+
</h3>
|
158 |
+
<div class="inside">
|
159 |
+
<input name='location_name' id='location-name' type='text' value='<?php echo htmlspecialchars($EM_Location->name, ENT_QUOTES); ?>' size='40' />
|
160 |
+
<br />
|
161 |
+
<?php _e('The name of the location', 'dbem') ?>
|
162 |
+
<?php $slug_link = __('View Slug','dbem'); ?>
|
163 |
+
<a href="#" id="location-slug-trigger"><?php echo $slug_link; ?></a>
|
164 |
+
<script type="text/javascript">
|
165 |
+
jQuery(document).ready(function($){
|
166 |
+
$('#location-slug-trigger').click(function(){
|
167 |
+
if( $(this).text() == '<?php echo $slug_link; ?>'){
|
168 |
+
$('.location-slug').show();
|
169 |
+
$(this).text('<?php _e('Hide Slug','dbem'); ?>');
|
170 |
+
}else{
|
171 |
+
$('.location-slug').hide();
|
172 |
+
$(this).text('<?php echo $slug_link; ?>');
|
173 |
+
}
|
174 |
+
});
|
175 |
+
});
|
176 |
+
</script>
|
177 |
+
<p class='location-slug' style="display:none">
|
178 |
+
<?php echo sprintf(__('%s Slug','dbem'),__('Location','dbem')); ?>: <input type="text" name="location_slug" id="location-slug" value="<?php echo $EM_Location->slug; ?>" />
|
179 |
+
<br />
|
180 |
+
<?php _e ( 'The event slug. If the event slug already exists, a random number will be appended to the end.', 'dbem' )?>
|
181 |
+
</p>
|
182 |
+
</div>
|
183 |
+
</div>
|
184 |
+
<?php if( current_user_can('edit_others_locations') ): ?>
|
185 |
+
<div id="location_owner" class="stuffbox">
|
186 |
+
<h3>
|
187 |
+
<?php _e ( 'Location Owner', 'dbem' ); ?>
|
188 |
+
</h3>
|
189 |
+
<div class="inside">
|
190 |
+
<?php
|
191 |
+
$location_owner = (empty($EM_Location->id)) ? $EM_Location->owner:get_current_user_id();
|
192 |
+
$user_args = array ('name' => 'location_owner', 'show_option_none' => __ ( "Select...", 'dbem' ), 'selected' => get_current_user_id() );
|
193 |
+
if( is_super_admin() || is_main_site() ){ $user_args['blog_id'] = false; }
|
194 |
+
wp_dropdown_users ( $user_args );
|
195 |
+
?>
|
196 |
+
</div>
|
197 |
+
</div>
|
198 |
+
<?php endif; ?>
|
199 |
+
<div id="location_coordinates" class="stuffbox" style='display: none;'>
|
200 |
+
<h3>
|
201 |
+
<?php _e ( 'Coordinates', 'dbem' ); ?>
|
202 |
+
</h3>
|
203 |
+
<div class="inside">
|
204 |
+
<input id='location-latitude' name='location_latitude' type='text' value='<?php echo $EM_Location->latitude; ?>' size='15' />
|
205 |
+
-
|
206 |
+
<input id='location-longitude' name='location_longitude' type='text' value='<?php echo $EM_Location->longitude; ?>' size='15' />
|
207 |
+
</div>
|
208 |
+
</div>
|
209 |
+
<div id="location_info" class="stuffbox">
|
210 |
+
<h3>
|
211 |
+
<?php _e ( 'Location', 'dbem' ); ?>
|
212 |
+
</h3>
|
213 |
+
<div class="inside">
|
214 |
+
<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>
|
215 |
+
<div id="em-location-data">
|
216 |
+
<table>
|
217 |
+
<tr>
|
218 |
+
<th><?php _e ( 'Address:' )?> </th>
|
219 |
+
<td>
|
220 |
+
<input id="location-address" type="text" name="location_address" value="<?php echo htmlspecialchars($EM_Location->address, ENT_QUOTES); ; ?>" /> <?php echo $required; ?>
|
221 |
+
</td>
|
222 |
+
</tr>
|
223 |
+
<tr>
|
224 |
+
<th><?php _e ( 'City/Town:' )?> </th>
|
225 |
+
<td>
|
226 |
+
<input id="location-town" type="text" name="location_town" value="<?php echo htmlspecialchars($EM_Location->town, ENT_QUOTES); ?>" /> <?php echo $required; ?>
|
227 |
+
</td>
|
228 |
+
</tr>
|
229 |
+
<tr>
|
230 |
+
<th><?php _e ( 'State/County:' )?> </th>
|
231 |
+
<td>
|
232 |
+
<input id="location-state" type="text" name="location_state" value="<?php echo htmlspecialchars($EM_Location->state, ENT_QUOTES); ?>" />
|
233 |
+
</td>
|
234 |
+
</tr>
|
235 |
+
<tr>
|
236 |
+
<th><?php _e ( 'Postcode:' )?> </th>
|
237 |
+
<td>
|
238 |
+
<input id="location-postcode" type="text" name="location_postcode" value="<?php echo htmlspecialchars($EM_Location->postcode, ENT_QUOTES); ?>" />
|
239 |
+
</td>
|
240 |
+
</tr>
|
241 |
+
<tr>
|
242 |
+
<th><?php _e ( 'Region:' )?> </th>
|
243 |
+
<td>
|
244 |
+
<input id="location-region" type="text" name="location_region" value="<?php echo htmlspecialchars($EM_Location->region, ENT_QUOTES); ?>" />
|
245 |
+
<input id="location-region-wpnonce" type="hidden" value="<?php echo wp_create_nonce('search_regions'); ?>" />
|
246 |
+
</td>
|
247 |
+
</tr>
|
248 |
+
<tr>
|
249 |
+
<th><?php _e ( 'Country:' )?> </th>
|
250 |
+
<td>
|
251 |
+
<select id="location-country" name="location_country">
|
252 |
+
<?php foreach(em_get_countries(__('none selected','dbem')) as $country_key => $country_name): ?>
|
253 |
+
<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>
|
254 |
+
<?php endforeach; ?>
|
255 |
+
</select> <?php echo $required; ?>
|
256 |
+
</td>
|
257 |
+
</tr>
|
258 |
+
</table>
|
259 |
+
<?php if ( get_option ( 'dbem_gmap_is_active' ) ) : ?>
|
260 |
+
<div style="width: 400px; height: 300px; float:left;">
|
261 |
+
<div id='em-map-404' style='width: 400px; height:300px; vertical-align:middle; text-align: center;'>
|
262 |
+
<p><em><?php _e ( 'Location not found', 'dbem' ); ?></em></p>
|
263 |
+
</div>
|
264 |
+
<div id='em-map' style='width: 400px; height: 300px; display: none;'></div>
|
265 |
+
</div>
|
266 |
+
<?php endif; ?>
|
267 |
+
<br style="clear:both; " />
|
268 |
+
</div>
|
269 |
+
</div>
|
270 |
+
</div>
|
271 |
+
|
272 |
+
<div id="location_description" class="postbox">
|
273 |
+
<h3>
|
274 |
+
<?php _e ( 'Details', 'dbem' ); ?>
|
275 |
+
</h3>
|
276 |
+
<div class="inside">
|
277 |
+
<div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
|
278 |
+
<?php the_editor($EM_Location->description ); ?>
|
279 |
+
</div>
|
280 |
+
<br />
|
281 |
+
<?php _e ( 'Details about the location', 'dbem' )?>
|
282 |
+
</div>
|
283 |
+
</div>
|
284 |
+
|
285 |
+
<div id="location_description" class="stuffbox">
|
286 |
+
<h3>
|
287 |
+
<?php _e ( 'Location image', 'dbem' ); ?>
|
288 |
+
</h3>
|
289 |
+
<div class="inside" style="padding:10px;">
|
290 |
+
<?php if ($EM_Location->get_image_url() != '') : ?>
|
291 |
+
<img src='<?php echo $EM_Location->image_url; ?>' alt='<?php echo $EM_Location->name ?>'/>
|
292 |
+
<?php else : ?>
|
293 |
+
<?php _e('No image uploaded for this location yet', 'dbem') ?>
|
294 |
+
<?php endif; ?>
|
295 |
+
<br /><br />
|
296 |
+
<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' />
|
297 |
+
</div>
|
298 |
+
</div>
|
299 |
+
<?php do_action('em_admin_location_form_footer'); ?>
|
300 |
+
|
301 |
+
</div>
|
302 |
+
</div>
|
303 |
+
</div>
|
304 |
+
<p class='submit'><input type='submit' class='button-primary' name='submit' value='<?php _e('Update location', 'dbem') ?>' /></p>
|
305 |
+
</div>
|
306 |
+
</form>
|
307 |
+
<?php
|
308 |
+
}
|
309 |
+
|
310 |
?>
|
admin/em-options.php
CHANGED
@@ -1,444 +1,618 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
//Function composing the options subpanel
|
4 |
-
function em_options_save(){
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
}
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
em_options_input_text ( __( '
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
?>
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
<?php
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
em_options_input_text ( __( '
|
353 |
-
em_options_textarea ( __(
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
em_options_input_text ( '
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
);
|
415 |
-
|
416 |
-
?>
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
</div> <!-- .
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//Function composing the options subpanel
|
4 |
+
function em_options_save(){
|
5 |
+
/*
|
6 |
+
* Here's the idea, we have an array of all options that need super admin approval if in multi-site mode
|
7 |
+
* since options are only updated here, its one place fit all
|
8 |
+
*/
|
9 |
+
if( current_user_can('activate_plugins') && !empty($_POST['em-submitted']) ){
|
10 |
+
//Build the array of options here
|
11 |
+
$post = $_POST;
|
12 |
+
foreach ($_POST as $postKey => $postValue){
|
13 |
+
if( substr($postKey, 0, 5) == 'dbem_' ){
|
14 |
+
//TODO some more validation/reporting
|
15 |
+
$numeric_options = array('dbem_locations_default_limit','dbem_events_default_limit');
|
16 |
+
if( in_array($postKey,$numeric_options) && !is_numeric($postValue) ){
|
17 |
+
//Do nothing, keep old setting.
|
18 |
+
}else{
|
19 |
+
//TODO slashes being added?
|
20 |
+
//$postValue = EM_Object::sanitize($postValue)
|
21 |
+
update_option($postKey, stripslashes($postValue));
|
22 |
+
}
|
23 |
+
}
|
24 |
+
}
|
25 |
+
|
26 |
+
//set capabilities
|
27 |
+
if( !empty($_POST['em_capabilities']) && is_array($_POST['em_capabilities']) && (!is_multisite() || is_multisite() && is_super_admin()) ){
|
28 |
+
global $em_capabilities_array, $wp_roles;
|
29 |
+
foreach( $wp_roles->role_objects as $role_name => $role ){
|
30 |
+
foreach( array_keys($em_capabilities_array) as $capability){
|
31 |
+
if( !empty($_POST['em_capabilities'][$role_name][$capability]) ){
|
32 |
+
$role->add_cap($capability);
|
33 |
+
}else{
|
34 |
+
$role->remove_cap($capability);
|
35 |
+
}
|
36 |
+
}
|
37 |
+
}
|
38 |
+
}
|
39 |
+
do_action('em_options_save');
|
40 |
+
function em_options_saved_notice(){
|
41 |
+
?>
|
42 |
+
<div class="updated"><p><strong><?php _e('Changes saved.'); ?></strong></p></div>
|
43 |
+
<?php
|
44 |
+
}
|
45 |
+
add_action ( 'admin_notices', 'em_options_saved_notice' );
|
46 |
+
if( get_option('dbem_debug') ){
|
47 |
+
include_once( WP_PLUGIN_DIR.'/events-manager/em-debug.php');
|
48 |
+
}
|
49 |
+
}
|
50 |
+
}
|
51 |
+
add_action('admin_head', 'em_options_save');
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
function em_admin_options_page() {
|
56 |
+
global $wpdb;
|
57 |
+
//TODO place all options into an array
|
58 |
+
$events_placeholders = '<a href="admin.php?page=events-manager-help#event-placeholders">'. __('Event Related Placeholders','dbem') .'</a>';
|
59 |
+
$locations_placeholders = '<a href="admin.php?page=events-manager-help#location-placeholders">'. __('Location Related Placeholders','dbem') .'</a>';
|
60 |
+
$bookings_placeholders = '<a href="admin.php?page=events-manager-help#booking-placeholders">'. __('Booking Related Placeholders','dbem') .'</a>';
|
61 |
+
$categories_placeholders = '<a href="admin.php?page=events-manager-help#category-placeholders">'. __('Category Related Placeholders','dbem') .'</a>';
|
62 |
+
$events_placeholder_tip = " ". sprintf(__('This accepts %s and %s placeholders.','dbem'),$events_placeholders, $locations_placeholders);
|
63 |
+
$locations_placeholder_tip = " ". sprintf(__('This accepts %s placeholders.','dbem'), $locations_placeholders);
|
64 |
+
$categories_placeholder_tip = " ". sprintf(__('This accepts %s placeholders.','dbem'), $categories_placeholders);
|
65 |
+
$bookings_placeholder_tip = " ". sprintf(__('This accepts %s, %s and %s placeholders.','dbem'), $bookings_placeholders, $events_placeholders, $locations_placeholders);
|
66 |
+
|
67 |
+
$save_button = '<tr><th> </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>';
|
68 |
+
//Do some multisite checking here for reuse
|
69 |
+
$multisite_view = (is_multisite() && is_super_admin()) ? ' - ('.__('Only Network Admins see this','dbem').')':'';
|
70 |
+
?>
|
71 |
+
<script type="text/javascript" charset="utf-8">
|
72 |
+
jQuery(document).ready(function($){
|
73 |
+
var close_text = '<?php _e('Collapse All','dbem'); ?>';
|
74 |
+
var open_text = '<?php _e('Expand All','dbem'); ?>';
|
75 |
+
var open_close = $('<a href="#" style="display:block; float:right; clear:right; margin:10px;">'+close_text+'</a>');
|
76 |
+
$('#icon-options-general').after(open_close);
|
77 |
+
open_close.click( function(e){
|
78 |
+
e.preventDefault();
|
79 |
+
if($(this).text() == close_text){
|
80 |
+
$(".postbox").addClass('closed');
|
81 |
+
$(this).text(open_text);
|
82 |
+
}else{
|
83 |
+
$(".postbox").removeClass('closed');
|
84 |
+
$(this).text(close_text);
|
85 |
+
}
|
86 |
+
});
|
87 |
+
//For rewrite titles
|
88 |
+
$('input:radio[name=dbem_disable_title_rewrites]').live('change',function(){
|
89 |
+
checked_check = $('input:radio[name=dbem_disable_title_rewrites]:checked');
|
90 |
+
if( checked_check.val() == 1 ){
|
91 |
+
$('#dbem_title_html_row').show();
|
92 |
+
}else{
|
93 |
+
$('#dbem_title_html_row').hide();
|
94 |
+
}
|
95 |
+
});
|
96 |
+
$('input:radio[name=dbem_disable_title_rewrites]').trigger('change');
|
97 |
+
});
|
98 |
+
</script>
|
99 |
+
<div class="wrap">
|
100 |
+
<div id='icon-options-general' class='icon32'><br />
|
101 |
+
</div>
|
102 |
+
<h2><?php _e ( 'Event Manager Options', 'dbem' ); ?></h2>
|
103 |
+
<?php
|
104 |
+
/*
|
105 |
+
* START MIGRATION BIT
|
106 |
+
*/
|
107 |
+
if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'bookings_migrate' ){
|
108 |
+
require_once(dirname(__FILE__).'/../em-install.php');
|
109 |
+
em_migrate_bookings();
|
110 |
+
}elseif( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'bookings_migrate_delete'){
|
111 |
+
require_once( dirname(__FILE__).'/../em-install.php');
|
112 |
+
em_migrate_bookings_delete();
|
113 |
+
}
|
114 |
+
?>
|
115 |
+
<?php if( $wpdb->get_var("SHOW TABLES LIKE '".EM_PEOPLE_TABLE."'") == EM_PEOPLE_TABLE ): ?>
|
116 |
+
<?php if( $wpdb->get_var('SELECT COUNT(*) FROM '.EM_TICKETS_BOOKINGS_TABLE) > 0 ): ?>
|
117 |
+
<div class='updated'>
|
118 |
+
<p>
|
119 |
+
It looks like you've already tried reimporting some bookings into the new version (or new bookings have been made since you installed).
|
120 |
+
If everything looks correct, you can
|
121 |
+
<a href="admin.php?page=events-manager-options&_wpnonce=<?php echo wp_create_nonce('bookings_migrate_delete'); ?>&action=bookings_migrate_delete">delete the unused tables</a>,
|
122 |
+
or you can also safely try
|
123 |
+
<a href="admin.php?page=events-manager-options&_wpnonce=<?php echo wp_create_nonce('bookings_migrate'); ?>&action=bookings_migrate">re-importing again</a>.
|
124 |
+
</p>
|
125 |
+
</div>
|
126 |
+
<?php else: ?>
|
127 |
+
<div class='updated'>
|
128 |
+
<p>It looks like you've upgraded from Events Manager version 3.0, meaning your old bookings won't work until you re-import them.
|
129 |
+
Events Manager 3.0 kept booking user info in a simple database table, whereas now people that make bookings get a subscriber account so
|
130 |
+
they can access private booking information. You have to choice to
|
131 |
+
<a href="admin.php?page=events-manager-options&_wpnonce=<?php echo wp_create_nonce('bookings_migrate'); ?>&action=bookings_migrate">import all your old bookings</a>
|
132 |
+
and create wordpress accounts for bookers, or you can also start afresh and
|
133 |
+
<a href="admin.php?page=events-manager-options&_wpnonce=<?php echo wp_create_nonce('bookings_migrate_delete'); ?>&action=bookings_migrate_delete">delete the old bookings</a>.
|
134 |
+
</p>
|
135 |
+
</div>
|
136 |
+
<?php endif; ?>
|
137 |
+
<?php endif; ?>
|
138 |
+
<?php
|
139 |
+
/*
|
140 |
+
* END MIGRATION BIT
|
141 |
+
*/
|
142 |
+
?>
|
143 |
+
<form id="dbem_options_form" method="post" action="">
|
144 |
+
|
145 |
+
<div class="metabox-holder">
|
146 |
+
<!-- // TODO Move style in css -->
|
147 |
+
<div class='postbox-container' style='width: 99.5%'>
|
148 |
+
<div id="">
|
149 |
+
|
150 |
+
<?php if ( is_multisite() && is_super_admin() ) : ?>
|
151 |
+
<div class="postbox " >
|
152 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Multi Site Options', 'dbem' ); ?> <?php echo $multisite_view; ?></span></h3>
|
153 |
+
<div class="inside">
|
154 |
+
<table class="form-table">
|
155 |
+
<?php
|
156 |
+
em_options_radio_binary ( __( 'Enable global tables mode?' ), 'dbem_ms_global_table', __( 'Setting this to yes will make all events save in the main site event tables (EM must also be activated). This allows you to share events across different blogs, such as showing events in your network whilst allowing users to display and manage their events within their own blog. Bear in mind that activating this will mean old events created on the sub-blogs will not be accessible anymore, and if you switch back they will be but new events created during global events mode will only remain on the main site.','dbem' ) );
|
157 |
+
em_options_radio_binary ( __( 'Display global events on main blog?' ), 'dbem_ms_global_events', __( 'Displays events from all sites on the network by default. You can still restrict events by blog using shortcodes and template tags coupled with the <code>blog</code> attribute. Requires global tables to be turned on.','dbem' ) );
|
158 |
+
em_options_radio_binary ( __( 'Link sub-site events directly to sub-site?' ), 'dbem_ms_global_events_links', __( 'When displaying global events on the main site you have the option of users viewing the event details on the main site or being directed to the sub-site.','dbem' ) );
|
159 |
+
echo $save_button;
|
160 |
+
?>
|
161 |
+
</table>
|
162 |
+
|
163 |
+
</div> <!-- . inside -->
|
164 |
+
</div> <!-- .postbox -->
|
165 |
+
<?php endif; ?>
|
166 |
+
|
167 |
+
<div class="postbox " >
|
168 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'General options', 'dbem' ); ?> </span></h3>
|
169 |
+
<div class="inside">
|
170 |
+
<table class="form-table">
|
171 |
+
<?php
|
172 |
+
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' ) );
|
173 |
+
em_options_radio_binary ( __( 'Use recurrence?' ), 'dbem_recurrence_enabled', __( 'Select yes to enable the recurrence features feature','dbem' ) );
|
174 |
+
em_options_radio_binary ( __( 'Enable bookings?' ), 'dbem_rsvp_enabled', __( 'Select yes to allow bookings and tickets for events.','dbem' ) );
|
175 |
+
em_options_radio_binary ( __( 'Use categories?' ), 'dbem_categories_enabled', __( 'Select yes to enable the category features','dbem' ) );
|
176 |
+
em_options_radio_binary ( __( 'Use event attributes?' ), 'dbem_attributes_enabled', __( 'Select yes to enable the attributes feature','dbem' ) );
|
177 |
+
|
178 |
+
/*default category*/
|
179 |
+
$category_options = array();
|
180 |
+
$category_options[0] = __('no default category','dbem');
|
181 |
+
$EM_Categories = EM_Categories::get();
|
182 |
+
foreach($EM_Categories as $EM_Category){
|
183 |
+
$category_options[$EM_Category->id] = $EM_Category->name;
|
184 |
+
}
|
185 |
+
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') );
|
186 |
+
|
187 |
+
/*default location*/
|
188 |
+
$location_options = array();
|
189 |
+
$location_options[0] = __('no default location','dbem');
|
190 |
+
$EM_Locations = EM_Locations::get();
|
191 |
+
foreach($EM_Locations as $EM_Location){
|
192 |
+
$location_options[$EM_Location->id] = $EM_Location->name;
|
193 |
+
}
|
194 |
+
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') );
|
195 |
+
|
196 |
+
/*default location country*/
|
197 |
+
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') );
|
198 |
+
|
199 |
+
em_options_textarea ( __( 'Event Attributes', 'dbem' ), 'dbem_placeholders_custom', sprintf(__( "You can also add event attributes 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/event-attributes/') );
|
200 |
+
|
201 |
+
em_options_radio_binary ( __( 'Show some love?' ), 'dbem_credits', __( 'Hundreds of free hours have gone into making this free plugin, show your support and add a small link to the plugin website at the bottom of your event pages.','dbem' ) );
|
202 |
+
echo $save_button;
|
203 |
+
?>
|
204 |
+
</table>
|
205 |
+
|
206 |
+
</div> <!-- . inside -->
|
207 |
+
</div> <!-- .postbox -->
|
208 |
+
|
209 |
+
<div class="postbox " >
|
210 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Events page', 'dbem' ); ?> </span></h3>
|
211 |
+
<div class="inside">
|
212 |
+
<table class="form-table">
|
213 |
+
<?php
|
214 |
+
//Wordpress Pages
|
215 |
+
global $em_disable_filter; //Using a flag here instead
|
216 |
+
$em_disable_filter = true;
|
217 |
+
$get_pages = get_pages();
|
218 |
+
$events_page_options = array();
|
219 |
+
$events_page_options[0] = __('[No Events Page]');
|
220 |
+
//TODO Add the hierarchy style ddm, like when choosing page parents
|
221 |
+
foreach($get_pages as $page){
|
222 |
+
$events_page_options[$page->ID] = $page->post_title;
|
223 |
+
}
|
224 |
+
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' ) );
|
225 |
+
$em_disable_filter = false;
|
226 |
+
//Rest
|
227 |
+
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' ) );
|
228 |
+
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') );
|
229 |
+
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' ) );
|
230 |
+
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' ) );
|
231 |
+
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' ) );
|
232 |
+
em_options_radio_binary ( __( 'Are current events past events?', 'dbem' ), 'dbem_events_current_are_past', __( "By default, events that are have an end date later than today will be included in searches, set this to yes to consider events that started 'yesterday' as past.", 'dbem' ) );
|
233 |
+
em_options_radio_binary ( __( 'Show events search?', 'dbem' ), 'dbem_events_page_search', __( "If set to yes, a search form will appear just above your list of events.", 'dbem' ) );
|
234 |
+
?>
|
235 |
+
<tr valign="top" id='dbem_events_default_orderby_row'>
|
236 |
+
<th scope="row"><?php _e('Default event list ordering','dbem'); ?></th>
|
237 |
+
<td>
|
238 |
+
<select name="dbem_events_default_orderby" >
|
239 |
+
<?php
|
240 |
+
$orderby_options = apply_filters('em_settings_events_default_orderby_ddm', array(
|
241 |
+
'start_date,start_time,name' => __('Order by start date, start time, then event name','dbem'),
|
242 |
+
'name,start_date,start_time' => __('Order by name, start date, then start time','dbem'),
|
243 |
+
'name,end_date,end_time' => __('Order by name, end date, then end time','dbem'),
|
244 |
+
'end_date,end_time,name' => __('Order by end date, end time, then event name','dbem'),
|
245 |
+
));
|
246 |
+
?>
|
247 |
+
<?php foreach($orderby_options as $key => $value) : ?>
|
248 |
+
<option value='<?php echo $key ?>' <?php echo ($key == get_option('dbem_events_default_orderby')) ? "selected='selected'" : ''; ?>>
|
249 |
+
<?php echo $value; ?>
|
250 |
+
</option>
|
251 |
+
<?php endforeach; ?>
|
252 |
+
</select>
|
253 |
+
<select name="dbem_events_default_order" >
|
254 |
+
<?php
|
255 |
+
$ascending = __('Ascending','dbem');
|
256 |
+
$descending = __('Descending','dbem');
|
257 |
+
$order_options = apply_filters('em_settings_events_default_order_ddm', array(
|
258 |
+
'ASC' => __('All Ascending','dbem'),
|
259 |
+
'DESC,ASC,ASC' => __("$descending, $ascending, $ascending",'dbem'),
|
260 |
+
'DESC,DESC,ASC' => __("$descending, $descending, $ascending",'dbem'),
|
261 |
+
'DESC' => __('All Descending','dbem'),
|
262 |
+
'ASC,DESC,ASC' => __("$ascending, $descending, $ascending",'dbem'),
|
263 |
+
'ASC,DESC,DESC' => __("$ascending, $descending, $descending",'dbem'),
|
264 |
+
'ASC,ASC,DESC' => __("$ascending, $ascending, $descending",'dbem'),
|
265 |
+
'DESC,ASC,DESC' => __("$descending, $ascending, $descending",'dbem'),
|
266 |
+
));
|
267 |
+
?>
|
268 |
+
<?php foreach( $order_options as $key => $value) : ?>
|
269 |
+
<option value='<?php echo $key ?>' <?php echo ($key == get_option('dbem_events_default_order')) ? "selected='selected'" : ''; ?>>
|
270 |
+
<?php echo $value; ?>
|
271 |
+
</option>
|
272 |
+
<?php endforeach; ?>
|
273 |
+
</select>
|
274 |
+
<br/>
|
275 |
+
<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>
|
276 |
+
</td>
|
277 |
+
</tr>
|
278 |
+
<tr valign="top" id='dbem_events_display_time_limit'>
|
279 |
+
<th scope="row"><?php _e('Event list scope','dbem'); ?></th>
|
280 |
+
<td>
|
281 |
+
<select name="dbem_events_page_scope" >
|
282 |
+
<?php foreach( em_get_scopes() as $key => $value) : ?>
|
283 |
+
<option value='<?php echo $key ?>' <?php echo ($key == get_option('dbem_events_page_scope')) ? "selected='selected'" : ''; ?>>
|
284 |
+
<?php echo $value; ?>
|
285 |
+
</option>
|
286 |
+
<?php endforeach; ?>
|
287 |
+
</select>
|
288 |
+
<br />
|
289 |
+
<em><?php _e('Only show events starting within a certain time limit on the events page. Default is future events with no end time limit.','dbem'); ?></em>
|
290 |
+
</td>
|
291 |
+
</tr>
|
292 |
+
<?php
|
293 |
+
echo $save_button;
|
294 |
+
?>
|
295 |
+
</table>
|
296 |
+
</div> <!-- . inside -->
|
297 |
+
</div> <!-- .postbox -->
|
298 |
+
|
299 |
+
<div class="postbox " >
|
300 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Events format', 'dbem' ); ?> </span></h3>
|
301 |
+
<div class="inside">
|
302 |
+
<table class="form-table">
|
303 |
+
<tr><td><strong><?php echo sprintf(__('%s Page','dbem'),__('Events','dbem')); ?></strong></td></tr>
|
304 |
+
<?php
|
305 |
+
em_options_input_text ( __( 'Events page title', 'dbem' ), 'dbem_events_page_title', __( 'The title on the multiple events page.', 'dbem' ) );
|
306 |
+
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' ) );
|
307 |
+
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 );
|
308 |
+
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' ) );
|
309 |
+
em_options_input_text ( __( 'No events message', 'dbem' ), 'dbem_no_events_message', __( 'The message displayed when no events are available.', 'dbem' ) );
|
310 |
+
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' ) );
|
311 |
+
?>
|
312 |
+
<tr><td><strong><?php echo sprintf(__('Single %s Page','dbem'),__('Event','dbem')); ?></strong></td></tr>
|
313 |
+
<?php
|
314 |
+
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 );
|
315 |
+
em_options_textarea ( __( 'Default single event format', 'dbem' ), 'dbem_single_event_format', __( 'The format of a single event page.', 'dbem' ).$events_placeholder_tip );
|
316 |
+
echo $save_button;
|
317 |
+
?>
|
318 |
+
</table>
|
319 |
+
</div> <!-- . inside -->
|
320 |
+
</div> <!-- .postbox -->
|
321 |
+
|
322 |
+
<div class="postbox " >
|
323 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Calendar format', 'dbem' ); ?></span></h3>
|
324 |
+
<div class="inside">
|
325 |
+
<table class="form-table">
|
326 |
+
<?php
|
327 |
+
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 );
|
328 |
+
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' ) );
|
329 |
+
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 );
|
330 |
+
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' ) );
|
331 |
+
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' ) );
|
332 |
+
echo $save_button;
|
333 |
+
?>
|
334 |
+
</table>
|
335 |
+
</div> <!-- . inside -->
|
336 |
+
</div> <!-- .postbox -->
|
337 |
+
|
338 |
+
<div class="postbox " >
|
339 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Locations format', 'dbem' ); ?> </span></h3>
|
340 |
+
<div class="inside">
|
341 |
+
<table class="form-table">
|
342 |
+
<tr><td><strong><?php echo sprintf(__('%s Page','dbem'),__('Locations','dbem')); ?></strong></td></tr>
|
343 |
+
<?php
|
344 |
+
em_options_input_text ( sprintf(__('%s page title','dbem'),__('Locations','dbem')), 'dbem_locations_page_title', sprintf(__( 'The title on the multiple %s page.', 'dbem' ), __('locations','dbem')) );
|
345 |
+
em_options_textarea ( sprintf(__('%s list header format','dbem'),__('Locations','dbem')), 'dbem_location_list_item_format_header', sprintf(__( 'This content will appear just above your code for the %s list format below. Default is blank', 'dbem' ), __('locations','dbem')) );
|
346 |
+
em_options_textarea ( sprintf(__('%s list item format','dbem'),__('Locations','dbem')), 'dbem_location_list_item_format', sprintf(__( 'The format of a single %s in a list.', 'dbem' ), __('locations','dbem')).$locations_placeholder_tip );
|
347 |
+
em_options_textarea ( sprintf(__('%s list footer format','dbem'),__('Locations','dbem')), 'dbem_location_list_item_format_footer', sprintf(__( 'This content will appear just below your code for the %s list format above. Default is blank', 'dbem' ), __('locations','dbem')) );
|
348 |
+
em_options_input_text ( sprintf(__( 'No %s message', 'dbem' ),__('Locations','dbem')), 'dbem_no_locations_message', sprintf( __( 'The message displayed when no %s are available.', 'dbem' ), __('locations','dbem')) );
|
349 |
+
?>
|
350 |
+
<tr><td><strong><?php echo sprintf(__('Single %s Page','dbem'),__('Location','dbem')); ?></strong></td></tr>
|
351 |
+
<?php
|
352 |
+
em_options_input_text (sprintf( __( 'Single %s title format', 'dbem' ),__('location','dbem')), 'dbem_location_page_title_format', __( 'The format of a single location page title.', 'dbem' ).$locations_placeholder_tip );
|
353 |
+
em_options_textarea ( sprintf(__('Single %s page format', 'dbem' ),__('location','dbem')), 'dbem_single_location_format', __( 'The format of a single location page.', 'dbem' ).$locations_placeholder_tip );
|
354 |
+
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 a single location map.', 'dbem' ).$locations_placeholder_tip );
|
355 |
+
em_options_textarea ( sprintf(__( 'Default %s list format', 'dbem' ),__('events','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 );
|
356 |
+
em_options_textarea ( sprintf(__( 'No %s message', 'dbem' ),__('events','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' ) );
|
357 |
+
echo $save_button;
|
358 |
+
?>
|
359 |
+
</table>
|
360 |
+
</div> <!-- . inside -->
|
361 |
+
</div> <!-- .postbox -->
|
362 |
+
|
363 |
+
<div class="postbox " >
|
364 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Categories format', 'dbem' ); ?> </span></h3>
|
365 |
+
<div class="inside">
|
366 |
+
<table class="form-table">
|
367 |
+
<tr><td><strong><?php echo sprintf(__('%s Page','dbem'),__('Categories','dbem')); ?></strong></td></tr>
|
368 |
+
<?php
|
369 |
+
em_options_input_text ( sprintf(__('%s page title','dbem'),__('Categories','dbem')), 'dbem_categories_page_title', sprintf(__( 'The title on the multiple %s page.', 'dbem' ), __('categories','dbem')) );
|
370 |
+
em_options_textarea ( sprintf(__('%s list header format','dbem'),__('Categories','dbem')), 'dbem_categories_list_item_format_header', sprintf(__( 'This content will appear just above your code for the %s list format below. Default is blank', 'dbem' ), __('categories','dbem')) );
|
371 |
+
em_options_textarea ( sprintf(__('%s list item format','dbem'),__('Categories','dbem')), 'dbem_categories_list_item_format', sprintf(__( 'The format of a single %s in a list.', 'dbem' ), __('categories','dbem')).$categories_placeholder_tip );
|
372 |
+
em_options_textarea ( sprintf(__('%s list footer format','dbem'),__('Categories','dbem')), 'dbem_categories_list_item_format_footer', sprintf(__( 'This content will appear just below your code for the %s list format above. Default is blank', 'dbem' ), __('categories','dbem')) );
|
373 |
+
em_options_input_text ( sprintf(__( 'No %s message', 'dbem' ),__('Categories','dbem')), 'dbem_no_categories_message', sprintf( __( 'The message displayed when no %s are available.', 'dbem' ), __('categories','dbem')) );
|
374 |
+
?>
|
375 |
+
<tr><td><strong><?php echo sprintf(__('Single %s Page','dbem'),__('Category','dbem')); ?></strong></td></tr>
|
376 |
+
<?php
|
377 |
+
em_options_input_text ( sprintf(__( 'Single %s title format', 'dbem' ),__('category','dbem')), 'dbem_category_page_title_format', __( 'The format of a single category page title.', 'dbem' ).$categories_placeholder_tip );
|
378 |
+
em_options_textarea ( sprintf(__('Single %s page format', 'dbem' ),__('category','dbem')), 'dbem_category_page_format', __( 'The format of a single category page.', 'dbem' ).$categories_placeholder_tip );
|
379 |
+
echo $save_button;
|
380 |
+
?>
|
381 |
+
</table>
|
382 |
+
</div> <!-- . inside -->
|
383 |
+
</div> <!-- .postbox -->
|
384 |
+
|
385 |
+
<div class="postbox " >
|
386 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'RSS feed format', 'dbem' ); ?> </span></h3>
|
387 |
+
<div class="inside">
|
388 |
+
<table class="form-table">
|
389 |
+
<?php
|
390 |
+
em_options_input_text ( __( 'RSS main title', 'dbem' ), 'dbem_rss_main_title', __( 'The main title of your RSS events feed.', 'dbem' ).$events_placeholder_tip );
|
391 |
+
em_options_input_text ( __( 'RSS main description', 'dbem' ), 'dbem_rss_main_description', __( 'The main description of your RSS events feed.', 'dbem' ) );
|
392 |
+
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 );
|
393 |
+
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 );
|
394 |
+
echo $save_button;
|
395 |
+
?>
|
396 |
+
</table>
|
397 |
+
</div> <!-- . inside -->
|
398 |
+
</div> <!-- .postbox -->
|
399 |
+
|
400 |
+
<div class="postbox " >
|
401 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Maps and geotagging', 'dbem' ); ?> </span></h3>
|
402 |
+
<div class="inside">
|
403 |
+
<table class='form-table'>
|
404 |
+
<?php $gmap_is_active = get_option ( 'dbem_gmap_is_active' ); ?>
|
405 |
+
<tr valign="top">
|
406 |
+
<th scope="row"><?php _e ( 'Enable Google Maps integration?', 'dbem' ); ?></th>
|
407 |
+
<td>
|
408 |
+
<?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'":''; ?> />
|
409 |
+
<?php _e ( 'No' ); ?> <input name="dbem_gmap_is_active" type="radio" value="0" <?php echo ($gmap_is_active) ? '':"checked='checked'"; ?> /><br />
|
410 |
+
<em><?php _e ( 'Check this option to enable Goggle Map integration.', 'dbem' )?></em>
|
411 |
+
</td>
|
412 |
+
</tr>
|
413 |
+
<?php
|
414 |
+
em_options_textarea ( __( 'Map text format', 'dbem' ), 'dbem_map_text_format', __( 'The text format inside the map balloons.', 'dbem' ).$events_placeholder_tip );
|
415 |
+
echo $save_button;
|
416 |
+
?>
|
417 |
+
</table>
|
418 |
+
</div> <!-- . inside -->
|
419 |
+
</div> <!-- .postbox -->
|
420 |
+
|
421 |
+
<div class="postbox " >
|
422 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Booking and Ticketing Options', 'dbem' ); ?> </span></h3>
|
423 |
+
<div class="inside">
|
424 |
+
<table class='form-table'>
|
425 |
+
<?php
|
426 |
+
em_options_radio_binary ( __( 'Approval Required?', 'dbem' ), 'dbem_bookings_approval', __( 'Bookings will not be confirmed until the event administrator approves it.', 'dbem' ) );
|
427 |
+
em_options_select ( __( 'Currency', 'dbem' ), 'dbem_bookings_currency', em_get_currencies()->names, __( 'Choose your currency for displaying event pricing.', 'dbem' ) );
|
428 |
+
em_options_radio_binary ( __( 'Single ticket mode?', 'dbem' ), 'dbem_bookings_tickets_single', __( 'In single ticket mode, users can only create one ticket per booking (and will not see options to add more tickets).', 'dbem' ) );
|
429 |
+
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' ) );
|
430 |
+
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' ) );
|
431 |
+
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' ) );
|
432 |
+
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' ) );
|
433 |
+
em_options_radio_binary ( __( 'Allow guest bookings?', 'dbem' ), 'dbem_bookings_anonymous', __( 'If enabled, guest visitors can supply an email address and a user account will automatically be created for them along with their booking. They will be also be able to log back in with that newly created account.', 'dbem' ) );
|
434 |
+
echo $save_button;
|
435 |
+
?>
|
436 |
+
</table>
|
437 |
+
</div> <!-- . inside -->
|
438 |
+
</div> <!-- .postbox -->
|
439 |
+
|
440 |
+
<div class="postbox " >
|
441 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Booking Email Templates', 'dbem' ); ?> </span></h3>
|
442 |
+
<div class="inside">
|
443 |
+
<table class='form-table'>
|
444 |
+
<?php
|
445 |
+
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' ) );
|
446 |
+
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' ) );
|
447 |
+
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' ) );
|
448 |
+
em_options_radio_binary ( __( 'Disable new registration email?', 'dbem' ), 'dbem_email_disable_registration', __( 'Check this option if you want to prevent the wordpress registration email from going out when a user anonymously books an event.', 'dbem' ) );
|
449 |
+
?>
|
450 |
+
<tr><td colspan='2'><h4><?php _e('Contact person booking confirmed','dbem') ?></h4></td></tr>
|
451 |
+
<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>
|
452 |
+
<?php
|
453 |
+
em_options_input_text ( __( 'Contact person email subject', 'dbem' ), 'dbem_bookings_contact_email_subject', '' );
|
454 |
+
em_options_textarea ( __( 'Contact person email', 'dbem' ), 'dbem_bookings_contact_email_body', '' );
|
455 |
+
?>
|
456 |
+
<tr><td colspan='2'><h4><?php _e('Contact person booking cancelled','dbem') ?></h4></td></tr>
|
457 |
+
<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>
|
458 |
+
<?php
|
459 |
+
em_options_input_text ( __( 'Contact person cancellation subject', 'dbem' ), 'dbem_contactperson_email_cancelled_subject', '' );
|
460 |
+
em_options_textarea ( __( 'Contact person cancellation email', 'dbem' ), 'dbem_contactperson_email_cancelled_body', '' );
|
461 |
+
?>
|
462 |
+
<tr><td colspan='2'><h4><?php _e('Confirmed booking email','dbem') ?></h4></td></tr>
|
463 |
+
<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>
|
464 |
+
<?php
|
465 |
+
em_options_input_text ( __( 'Booking confirmed email subject', 'dbem' ), 'dbem_bookings_email_confirmed_subject', '' );
|
466 |
+
em_options_textarea ( __( 'Booking confirmed email', 'dbem' ), 'dbem_bookings_email_confirmed_body', '' );
|
467 |
+
?>
|
468 |
+
<tr><td colspan='2'><h4><?php _e('Pending booking email','dbem') ?></h4></td></tr>
|
469 |
+
<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>
|
470 |
+
<?php
|
471 |
+
em_options_input_text ( __( 'Booking pending email subject', 'dbem' ), 'dbem_bookings_email_pending_subject', '');
|
472 |
+
em_options_textarea ( __( 'Booking pending email', 'dbem' ), 'dbem_bookings_email_pending_body','') ;
|
473 |
+
?>
|
474 |
+
<tr><td colspan='2'><h4><?php _e('Rejected booking email','dbem') ?></h4></td></tr>
|
475 |
+
<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>
|
476 |
+
<?php
|
477 |
+
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 );
|
478 |
+
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 );
|
479 |
+
echo $save_button;
|
480 |
+
?>
|
481 |
+
<tr><td colspan='2'><h4><?php _e('Booking cancelled','dbem') ?></h4></td></tr>
|
482 |
+
<tr><td colspan='2'><?php echo __('This will be sent when a user cancels their booking.','dbem').$bookings_placeholder_tip ?></td></tr>
|
483 |
+
<?php
|
484 |
+
em_options_input_text ( __( 'Booking cancelled email subject', 'dbem' ), 'dbem_bookings_email_cancelled_subject', '' );
|
485 |
+
em_options_textarea ( __( 'Booking cancelled email', 'dbem' ), 'dbem_bookings_email_cancelled_body', '' );
|
486 |
+
?>
|
487 |
+
</table>
|
488 |
+
</div> <!-- . inside -->
|
489 |
+
</div> <!-- .postbox -->
|
490 |
+
|
491 |
+
<?php if ( !is_multisite() || (is_multisite() && is_super_admin()) ) : ?>
|
492 |
+
<div class="postbox " >
|
493 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Email Settings', 'dbem' ); ?> <?php echo $multisite_view; ?></span></h3>
|
494 |
+
<div class="inside">
|
495 |
+
<table class='form-table'>
|
496 |
+
<?php
|
497 |
+
em_options_input_text ( __( 'Notification sender name', 'dbem' ), 'dbem_mail_sender_name', __( "Insert the display name of the notification sender.", 'dbem' ) );
|
498 |
+
em_options_input_text ( __( 'Notification sender address', 'dbem' ), 'dbem_mail_sender_address', __( "Insert the address of the notification sender.", 'dbem' ) );
|
499 |
+
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' ) );
|
500 |
+
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' ) );
|
501 |
+
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' ) );
|
502 |
+
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' ) );
|
503 |
+
em_options_input_text ( __( 'SMTP username', 'dbem' ), 'dbem_smtp_username', __( "Insert the username to be used to access your SMTP server.", 'dbem' ) );
|
504 |
+
em_options_input_password ( __( 'SMTP password', 'dbem' ), "dbem_smtp_password", __( "Insert the password to be used to access your SMTP server", 'dbem' ) );
|
505 |
+
echo $save_button;
|
506 |
+
?>
|
507 |
+
</table>
|
508 |
+
</div> <!-- . inside -->
|
509 |
+
</div> <!-- .postbox -->
|
510 |
+
|
511 |
+
<div class="postbox " >
|
512 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Images size', 'dbem' ); ?> <?php echo $multisite_view; ?> </span></h3>
|
513 |
+
<div class="inside">
|
514 |
+
<table class='form-table'>
|
515 |
+
<?php
|
516 |
+
em_options_input_text ( __( 'Maximum width (px)', 'dbem' ), 'dbem_image_max_width', __( 'The maximum allowed width for images uploades', 'dbem' ) );
|
517 |
+
em_options_input_text ( __( 'Maximum height (px)', 'dbem' ), 'dbem_image_max_height', __( "The maximum allowed height for images uploaded, in pixels", 'dbem' ) );
|
518 |
+
em_options_input_text ( __( 'Maximum size (bytes)', 'dbem' ), 'dbem_image_max_size', __( "The maximum allowed size for images uploaded, in pixels", 'dbem' ) );
|
519 |
+
echo $save_button;
|
520 |
+
?>
|
521 |
+
</table>
|
522 |
+
</div> <!-- . inside -->
|
523 |
+
</div> <!-- .postbox -->
|
524 |
+
|
525 |
+
<div class="postbox" >
|
526 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'User Capabilities', 'dbem' ); ?> <?php echo $multisite_view; ?></span></h3>
|
527 |
+
<div class="inside">
|
528 |
+
<table class="form-table">
|
529 |
+
<tr><td colspan="2">
|
530 |
+
<strong><?php _e('Warning: Changing these values may result in exposing previously hidden information to all users.')?></strong><br />
|
531 |
+
</td></tr>
|
532 |
+
<?php
|
533 |
+
global $wp_roles;
|
534 |
+
global $em_capabilities_array;
|
535 |
+
?>
|
536 |
+
<tr><td colspan="2">
|
537 |
+
<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>
|
538 |
+
<table class="em-caps-table" style="width:auto;" cellspacing="0" cellpadding="0">
|
539 |
+
<thead>
|
540 |
+
<tr>
|
541 |
+
<td> </td>
|
542 |
+
<?php
|
543 |
+
$odd = 0;
|
544 |
+
$cap_docs = array(
|
545 |
+
'publish_events' => __('Users can publish events and skip any admin approval.','dbem'),
|
546 |
+
'edit_categories' => __('User can edit the global categories.','dbem'),
|
547 |
+
'delete_others_events' => __('User can delete other users events.','dbem'),
|
548 |
+
'delete_others_locations' => __('User can delete other users locations.','dbem'),
|
549 |
+
'edit_others_locations' => __('User can edit other users locations.','dbem'),
|
550 |
+
'manage_others_bookings' => __('User can manage other users individual bookings and event booking settings.','dbem'),
|
551 |
+
'edit_others_events' => __('User can edit other users events.','dbem'),
|
552 |
+
'delete_locations' => __('User can delete their own locations.','dbem'),
|
553 |
+
'delete_events' => __('User can delete their events.','dbem'),
|
554 |
+
'edit_locations' => __('User can edit their locations.','dbem'),
|
555 |
+
'manage_bookings' => __('User can use and manage bookings with their events.','dbem'),
|
556 |
+
'read_others_locations' => __('User can view other users locations, to make locations shared by all users allow all event user roles to view all locations.','dbem'),
|
557 |
+
'edit_recurrences' => __('User can create recurrent events.','dbem'),
|
558 |
+
'edit_events' => __('User can create and edit their events.','dbem')
|
559 |
+
);
|
560 |
+
foreach(array_keys($em_capabilities_array) as $capability){
|
561 |
+
?><th class="<?php echo $capability ?> <?php echo ( !is_int($odd/2) ) ? 'odd':''; ?>"> <a href="#" title="<?php echo $cap_docs[$capability]; ?>">?</a></th><?php
|
562 |
+
$odd++;
|
563 |
+
}
|
564 |
+
?>
|
565 |
+
</tr>
|
566 |
+
</thead>
|
567 |
+
<tbody>
|
568 |
+
<?php foreach($wp_roles->role_objects as $role): ?>
|
569 |
+
<tr>
|
570 |
+
<td class="cap"><strong><?php echo $role->name; ?></strong></td>
|
571 |
+
<?php
|
572 |
+
$odd = 0;
|
573 |
+
foreach(array_keys($em_capabilities_array) as $capability){
|
574 |
+
?><td class="<?php echo ( !is_int($odd/2) ) ? 'odd':''; ?>"><input type="checkbox" name="em_capabilities[<?php echo $role->name; ?>][<?php echo $capability ?>]" value="1" <?php echo $role->has_cap($capability) ? 'checked="checked"':''; ?> /></td><?php
|
575 |
+
$odd++;
|
576 |
+
}
|
577 |
+
?>
|
578 |
+
</tr>
|
579 |
+
<?php endforeach; ?>
|
580 |
+
</tbody>
|
581 |
+
</table>
|
582 |
+
</td></tr>
|
583 |
+
<?php echo $save_button; ?>
|
584 |
+
</table>
|
585 |
+
</div> <!-- . inside -->
|
586 |
+
</div> <!-- .postbox -->
|
587 |
+
<?php endif; ?>
|
588 |
+
|
589 |
+
<?php /*
|
590 |
+
<div class="postbox " >
|
591 |
+
<div class="handlediv" title="<?php __('Click to toggle'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Debug Modes', 'dbem' ); ?> </span></h3>
|
592 |
+
<div class="inside">
|
593 |
+
<table class='form-table'>
|
594 |
+
<?php
|
595 |
+
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' ) );
|
596 |
+
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' ) );
|
597 |
+
?>
|
598 |
+
</table>
|
599 |
+
</div> <!-- . inside -->
|
600 |
+
</div> <!-- .postbox -->
|
601 |
+
*/ ?>
|
602 |
+
|
603 |
+
<?php do_action('em_options_page_footer'); ?>
|
604 |
+
|
605 |
+
<p class="submit">
|
606 |
+
<input type="submit" id="dbem_options_submit" name="Submit" value="<?php _e ( 'Save Changes' )?>" />
|
607 |
+
<input type="hidden" name="em-submitted" value="1" />
|
608 |
+
</p>
|
609 |
+
|
610 |
+
</div> <!-- .metabox-sortables -->
|
611 |
+
</div> <!-- .postbox-container -->
|
612 |
+
|
613 |
+
</div> <!-- .metabox-holder -->
|
614 |
+
</form>
|
615 |
+
</div>
|
616 |
+
<?php
|
617 |
+
}
|
618 |
?>
|
admin/em-people.php
CHANGED
@@ -1,125 +1,10 @@
|
|
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' ); ?> »" />
|
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'> </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'> </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> </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,28 +30,28 @@ function em_printable_booking_report() {
|
|
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('
|
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->
|
155 |
-
<td><?php echo $EM_Booking->person->
|
156 |
<td><?php echo $EM_Booking->person->phone ?></td>
|
157 |
-
<td class='
|
158 |
<td><?php echo $EM_Booking->comment ?></td>
|
159 |
</tr>
|
160 |
<?php } ?>
|
161 |
-
<tr id='booked-
|
162 |
<td colspan='3'> </td>
|
163 |
<td class='total-label'><?php _e('Booked', 'dbem')?>:</td>
|
164 |
-
<td class='
|
165 |
</tr>
|
166 |
-
<tr id='available-
|
167 |
<td colspan='3'> </td>
|
168 |
<td class='total-label'><?php _e('Available', 'dbem')?>:</td>
|
169 |
-
<td class='
|
170 |
</tr>
|
171 |
</table>
|
172 |
</div>
|
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 |
<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'> </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'> </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>
|
buddypress/bp-em-activity.php
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 || empty($status) || (!get_option('dbem_bookings_approval') && $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);
|
107 |
+
add_filter('em_booking_delete','bp_em_record_activity_booking_save', 10, 2);
|
buddypress/bp-em-admin.php
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
require ( dirname( __FILE__ ) . '/bp-em-groups.php' ); /* The notifications file should contain functions to send email notifications on specific user actions */
|
11 |
+
//Screens
|
12 |
+
include( dirname( __FILE__ ). '/screens/settings.php');
|
13 |
+
include( dirname( __FILE__ ). '/screens/profile.php');
|
14 |
+
include( dirname( __FILE__ ). '/screens/my-events.php');
|
15 |
+
include( dirname( __FILE__ ). '/screens/my-locations.php');
|
16 |
+
include( dirname( __FILE__ ). '/screens/attending.php');
|
17 |
+
include( dirname( __FILE__ ). '/screens/my-bookings.php');
|
18 |
+
include( dirname( __FILE__ ). '/screens/my-group-events.php');
|
19 |
+
include( dirname( __FILE__ ). '/screens/group-events.php');
|
20 |
+
|
21 |
+
|
22 |
+
/**
|
23 |
+
* bp_em_setup_globals()
|
24 |
+
*
|
25 |
+
* Sets up global variables for your component.
|
26 |
+
*/
|
27 |
+
function bp_em_setup_globals() {
|
28 |
+
global $bp, $wpdb;
|
29 |
+
$bp->events = new stdClass();
|
30 |
+
$bp->events->id = 'events';
|
31 |
+
//$bp->events->table_name = $wpdb->base_prefix . 'bp_em';
|
32 |
+
$bp->events->format_notification_function = 'bp_em_format_notifications';
|
33 |
+
$bp->events->slug = BP_EM_SLUG;
|
34 |
+
/* Register this in the active components array */
|
35 |
+
$bp->active_components[$bp->events->slug] = $bp->events->id;
|
36 |
+
//quick link shortcut
|
37 |
+
$bp->events->link = trailingslashit($bp->loggedin_user->domain).'events/';
|
38 |
+
}
|
39 |
+
add_action( 'wp', 'bp_em_setup_globals', 2 );
|
40 |
+
//add_action( 'admin_menu', 'bp_em_setup_globals', 2 );
|
41 |
+
|
42 |
+
/**
|
43 |
+
* bp_em_setup_nav()
|
44 |
+
*
|
45 |
+
* Sets up the user profile navigation items for the component. This adds the top level nav
|
46 |
+
* item and all the sub level nav items to the navigation array. This is then
|
47 |
+
* rendered in the template.
|
48 |
+
*/
|
49 |
+
function bp_em_setup_nav() {
|
50 |
+
global $bp;
|
51 |
+
$count = 0;
|
52 |
+
if( empty($bp->events) ) bp_em_setup_globals();
|
53 |
+
/* Add 'Events' to the main user profile navigation */
|
54 |
+
bp_core_new_nav_item( array(
|
55 |
+
'name' => __( 'Events', 'bp-em' ),
|
56 |
+
'slug' => $bp->events->slug,
|
57 |
+
'position' => 80,
|
58 |
+
'screen_function' => bp_is_my_profile() ? 'bp_em_my_events':'bp_em_events',
|
59 |
+
'default_subnav_slug' => bp_is_my_profile() ? 'my-events':''
|
60 |
+
) );
|
61 |
+
|
62 |
+
$em_link = $bp->loggedin_user->domain . $bp->events->slug . '/';
|
63 |
+
|
64 |
+
/* Create two sub nav items for this component */
|
65 |
+
bp_core_new_subnav_item( array(
|
66 |
+
'name' => __( 'My Profile', 'dbem' ),
|
67 |
+
'slug' => 'profile',
|
68 |
+
'parent_slug' => $bp->events->slug,
|
69 |
+
'parent_url' => $em_link,
|
70 |
+
'screen_function' => 'bp_em_events',
|
71 |
+
'position' => 10,
|
72 |
+
'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
|
73 |
+
) );
|
74 |
+
|
75 |
+
bp_core_new_subnav_item( array(
|
76 |
+
'name' => __( 'Events I\'m Attending', 'dbem' ),
|
77 |
+
'slug' => 'attending',
|
78 |
+
'parent_slug' => $bp->events->slug,
|
79 |
+
'parent_url' => $em_link,
|
80 |
+
'screen_function' => 'bp_em_attending',
|
81 |
+
'position' => 20,
|
82 |
+
'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
|
83 |
+
) );
|
84 |
+
|
85 |
+
bp_core_new_subnav_item( array(
|
86 |
+
'name' => __( 'My Events', 'dbem' ),
|
87 |
+
'slug' => 'my-events',
|
88 |
+
'parent_slug' => $bp->events->slug,
|
89 |
+
'parent_url' => $em_link,
|
90 |
+
'screen_function' => 'bp_em_my_events',
|
91 |
+
'position' => 30,
|
92 |
+
'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
|
93 |
+
) );
|
94 |
+
|
95 |
+
bp_core_new_subnav_item( array(
|
96 |
+
'name' => __( 'My Locations', 'dbem' ),
|
97 |
+
'slug' => 'my-locations',
|
98 |
+
'parent_slug' => $bp->events->slug,
|
99 |
+
'parent_url' => $em_link,
|
100 |
+
'screen_function' => 'bp_em_my_locations',
|
101 |
+
'position' => 40,
|
102 |
+
'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
|
103 |
+
) );
|
104 |
+
|
105 |
+
bp_core_new_subnav_item( array(
|
106 |
+
'name' => __( 'My Event Bookings', 'dbem' ),
|
107 |
+
'slug' => 'my-bookings',
|
108 |
+
'parent_slug' => $bp->events->slug,
|
109 |
+
'parent_url' => $em_link,
|
110 |
+
'screen_function' => 'bp_em_my_bookings',
|
111 |
+
'position' => 50,
|
112 |
+
'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
|
113 |
+
) );
|
114 |
+
|
115 |
+
/* Add a nav item for this component under the settings nav item. */
|
116 |
+
bp_core_new_subnav_item( array(
|
117 |
+
'name' => __( 'Events', 'dbem' ),
|
118 |
+
'slug' => 'group-events',
|
119 |
+
'parent_slug' => $bp->groups->slug,
|
120 |
+
'parent_url' => $bp->loggedin_user->domain . $bp->groups->slug . '/',
|
121 |
+
'screen_function' => 'bp_em_my_group_events',
|
122 |
+
'position' => 60,
|
123 |
+
'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
|
124 |
+
) );
|
125 |
+
|
126 |
+
/* Add a nav item for this component under the settings nav item. */
|
127 |
+
bp_core_new_subnav_item( array(
|
128 |
+
'name' => __( 'Events', 'dbem' ),
|
129 |
+
'slug' => 'events-settings',
|
130 |
+
'parent_slug' => $bp->settings->slug,
|
131 |
+
'parent_url' => $bp->loggedin_user->domain . $bp->settings->slug . '/',
|
132 |
+
'screen_function' => 'bp_em_screen_settings_menu',
|
133 |
+
'position' => 40,
|
134 |
+
'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
|
135 |
+
) );
|
136 |
+
|
137 |
+
|
138 |
+
/* Create two sub nav items for this component */
|
139 |
+
$user_access = false;
|
140 |
+
$group_link = '';
|
141 |
+
if( !empty($bp->groups->current_group) ){
|
142 |
+
$group_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $bp->groups->current_group->slug . '/';
|
143 |
+
$user_access = $bp->groups->current_group->user_has_access;
|
144 |
+
if( !empty($bp->current_component) && $bp->current_component == 'groups' ){
|
145 |
+
$count = EM_Events::count(array('group'=>$bp->groups->current_group->id));
|
146 |
+
if( empty($count) ) $count = 0;
|
147 |
+
}
|
148 |
+
bp_core_new_subnav_item( array(
|
149 |
+
'name' => sprintf(__( 'Events (%s)', 'dbem' ), $count),
|
150 |
+
'slug' => 'events',
|
151 |
+
'parent_url' => $group_link,
|
152 |
+
'parent_slug' => $bp->groups->slug,
|
153 |
+
'screen_function' => 'bp_em_group_events',
|
154 |
+
'position' => 50,
|
155 |
+
'user_has_access' => $user_access,
|
156 |
+
'item_css_id' => 'forums'
|
157 |
+
));
|
158 |
+
}
|
159 |
+
|
160 |
+
}
|
161 |
+
|
162 |
+
/***
|
163 |
+
* In versions of BuddyPress 1.2.2 and newer you will be able to use:
|
164 |
+
* add_action( 'bp_setup_nav', 'bp_example_setup_nav' );
|
165 |
+
*/
|
166 |
+
add_action( 'wp', 'bp_em_setup_nav', 2 );
|
167 |
+
add_action( 'admin_menu', 'bp_em_setup_nav', 2 );
|
168 |
+
|
169 |
+
|
170 |
+
function em_bp_rewrite_links($replace, $object, $result){
|
171 |
+
global $bp;
|
172 |
+
if( is_object($object) && get_class($object)=='EM_Event' ){
|
173 |
+
switch( $result ){
|
174 |
+
case '#_EDITEVENTURL':
|
175 |
+
case '#_EDITEVENTLINK':
|
176 |
+
if( $object->can_manage('edit_events','edit_others_events') && !is_admin() ){
|
177 |
+
$replace = $bp->events->link.'my-events/edit/?event_id='.$object->id;
|
178 |
+
if($result == '#_EDITEVENTLINK'){
|
179 |
+
$replace = "<a href='".$replace."'>".__('Edit').' '.__('Event', 'dbem')."</a>";
|
180 |
+
}
|
181 |
+
}
|
182 |
+
break;
|
183 |
+
case '#_BOOKINGSLINK':
|
184 |
+
case '#_BOOKINGSURL':
|
185 |
+
if( $object->can_manage('manage_bookings','manage_others_bookings') && !is_admin() ){
|
186 |
+
$replace = $bp->events->link.'my-bookings/?event_id='.$object->id;
|
187 |
+
if($result == '#_BOOKINGSLINK'){
|
188 |
+
$replace = "<a href='{$replace}' title='{$object->name}'>{$object->name}</a>";
|
189 |
+
}
|
190 |
+
}
|
191 |
+
break;
|
192 |
+
}
|
193 |
+
}
|
194 |
+
return $replace;
|
195 |
+
}
|
196 |
+
add_filter('em_event_output_placeholder','em_bp_rewrite_links',10,3);
|
197 |
+
|
198 |
+
/**
|
199 |
+
* bp_em_load_template_filter()
|
200 |
+
*
|
201 |
+
* You can define a custom load template filter for your component. This will allow
|
202 |
+
* you to store and load template files from your plugin directory.
|
203 |
+
*
|
204 |
+
* This will also allow users to override these templates in their active theme and
|
205 |
+
* replace the ones that are stored in the plugin directory.
|
206 |
+
*
|
207 |
+
* If you're not interested in using template files, then you don't need this function.
|
208 |
+
*
|
209 |
+
* This will become clearer in the function bp_em_screen_one() when you want to load
|
210 |
+
* a template file.
|
211 |
+
*/
|
212 |
+
function bp_em_load_template_filter( $found_template, $templates ) {
|
213 |
+
global $bp;
|
214 |
+
|
215 |
+
/**
|
216 |
+
* Only filter the template location when we're on the em component pages.
|
217 |
+
*/
|
218 |
+
if ( $bp->current_component != $bp->events->slug )
|
219 |
+
return $found_template;
|
220 |
+
|
221 |
+
foreach ( (array) $templates as $template ) {
|
222 |
+
if ( file_exists( STYLESHEETPATH . '/' . $template ) )
|
223 |
+
$filtered_templates[] = STYLESHEETPATH . '/' . $template;
|
224 |
+
else
|
225 |
+
$filtered_templates[] = dirname( __FILE__ ) . '/templates/' . $template;
|
226 |
+
}
|
227 |
+
|
228 |
+
$found_template = $filtered_templates[0];
|
229 |
+
|
230 |
+
return apply_filters( 'bp_em_load_template_filter', $found_template );
|
231 |
+
}
|
232 |
+
add_filter( 'bp_located_template', 'bp_em_load_template_filter', 10, 2 );
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Remove a screen notification for a user.
|
236 |
+
*/
|
237 |
+
function bp_em_remove_screen_notifications() {
|
238 |
+
global $bp;
|
239 |
+
bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->events->slug, 'attending' );
|
240 |
+
}
|
241 |
+
add_action( 'bp_em_my_events', 'bp_em_remove_screen_notifications' );
|
242 |
+
add_action( 'xprofile_screen_display_profile', 'bp_em_remove_screen_notifications' );
|
243 |
+
|
244 |
+
/**
|
245 |
+
* Delete events when you delete a user.
|
246 |
+
*/
|
247 |
+
function bp_em_remove_data( $user_id ) {
|
248 |
+
$EM_Events = EM_Events::get(array('scope'=>'all','owner'=>$user_id, 'status'=>false));
|
249 |
+
EM_Events::delete($EM_Events);
|
250 |
+
}
|
251 |
+
add_action( 'wpmu_delete_user', 'bp_em_remove_data', 1 );
|
252 |
+
add_action( 'delete_user', 'bp_em_remove_data', 1 );
|
253 |
+
|
254 |
+
?>
|
buddypress/bp-em-groups.php
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @param EM_Event $EM_Event
|
4 |
+
*/
|
5 |
+
function bp_em_group_event_save($EM_Event){
|
6 |
+
if( is_object($EM_Event) && empty($EM_Event->group_id) && !empty($_REQUEST['group_id']) && is_numeric($_REQUEST['group_id']) ){
|
7 |
+
//we have been requested an event creation tied to a group, so does this group exist, and does this person have admin rights to it?
|
8 |
+
if( groups_is_user_admin(get_current_user_id(), $_REQUEST['group_id']) ){
|
9 |
+
$EM_Event->group_id = $_REQUEST['group_id'];
|
10 |
+
}
|
11 |
+
}
|
12 |
+
return $EM_Event;
|
13 |
+
}
|
14 |
+
add_action('em_event_save_pre','bp_em_group_event_save',1,1);
|
15 |
+
|
16 |
+
/**
|
17 |
+
* @param boolean $result
|
18 |
+
* @param EM_Event $EM_Event
|
19 |
+
*/
|
20 |
+
function bp_em_group_event_can_manage( $result, $EM_Event){
|
21 |
+
if( !$result && !empty($EM_Event->group_id) ){ //only override if already false, incase it's true
|
22 |
+
if( groups_is_user_admin(get_current_user_id(),$EM_Event->group_id) && current_user_can('edit_events') ){
|
23 |
+
//This user is an admin of the owner's group, so they can edit this event.
|
24 |
+
return true;
|
25 |
+
}
|
26 |
+
}
|
27 |
+
return $result;
|
28 |
+
}
|
29 |
+
add_action('em_event_can_manage','bp_em_group_event_can_manage',1,2);
|
30 |
+
|
31 |
+
|
32 |
+
function bp_em_group_events_accepted_searches($searches){
|
33 |
+
$searches[] = 'group';
|
34 |
+
return $searches;
|
35 |
+
}
|
36 |
+
add_filter('em_accepted_searches','bp_em_group_events_accepted_searches',1,1);
|
37 |
+
|
38 |
+
function bp_em_group_events_get_default_search($searches, $array){
|
39 |
+
if( !empty($array['group']) && (is_numeric($array['group']) || $array['group'] == 'my') ){
|
40 |
+
$searches['group'] = $array['group'];
|
41 |
+
}
|
42 |
+
return $searches;
|
43 |
+
}
|
44 |
+
add_filter('em_events_get_default_search','bp_em_group_events_get_default_search',1,2);
|
45 |
+
|
46 |
+
function bp_em_group_events_build_sql_conditions( $conditions, $args ){
|
47 |
+
if( !empty($args['group']) && is_numeric($args['group']) ){
|
48 |
+
$conditions['group'] = "( `group_id`={$args['group']} )";
|
49 |
+
}elseif( !empty($args['group']) && $args['group'] == 'my' ){
|
50 |
+
$groups = groups_get_user_groups(get_current_user_id());
|
51 |
+
if( count($groups) > 0 ){
|
52 |
+
$conditions['group'] = "( `group_id` IN (".implode(',',$groups['groups']).") )";
|
53 |
+
}
|
54 |
+
}
|
55 |
+
return $conditions;
|
56 |
+
}
|
57 |
+
add_filter('em_events_build_sql_conditions','bp_em_group_events_build_sql_conditions',1,2);
|
buddypress/bp-em-notifications.php
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/********************************************************************************
|
4 |
+
* Activity & Notification Functions
|
5 |
+
*
|
6 |
+
* These functions handle the recording, deleting and formatting of activity and
|
7 |
+
* notifications for the user and for this specific component.
|
8 |
+
*/
|
9 |
+
/**
|
10 |
+
* bp_em_screen_notification_settings()
|
11 |
+
*
|
12 |
+
* Adds notification settings for the component, so that a user can turn off email
|
13 |
+
* notifications set on specific component actions.
|
14 |
+
*/
|
15 |
+
function bp_em_screen_notification_settings() {
|
16 |
+
global $current_user;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Under Settings > Notifications within a users profile page they will see
|
20 |
+
* settings to turn off notifications for each component.
|
21 |
+
*
|
22 |
+
* You can plug your custom notification settings into this page, so that when your
|
23 |
+
* component is active, the user will see options to turn off notifications that are
|
24 |
+
* specific to your component.
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Each option is stored in a posted array notifications[SETTING_NAME]
|
29 |
+
* When saved, the SETTING_NAME is stored as usermeta for that user.
|
30 |
+
*
|
31 |
+
* For em, notifications[notification_friends_friendship_accepted] could be
|
32 |
+
* used like this:
|
33 |
+
*
|
34 |
+
* if ( 'no' == get_usermeta( $bp['loggedin_userid'], 'notification_friends_friendship_accepted' ) )
|
35 |
+
* // don't send the email notification
|
36 |
+
* else
|
37 |
+
* // send the email notification.
|
38 |
+
*/
|
39 |
+
|
40 |
+
?>
|
41 |
+
<table class="notification-settings" id="bp-em-notification-settings">
|
42 |
+
<tr>
|
43 |
+
<th class="icon"></th>
|
44 |
+
<th class="title"><?php _e( 'Events', 'bp-em' ) ?></th>
|
45 |
+
<th class="yes"><?php _e( 'Yes', 'bp-em' ) ?></th>
|
46 |
+
<th class="no"><?php _e( 'No', 'bp-em' )?></th>
|
47 |
+
</tr>
|
48 |
+
<tr>
|
49 |
+
<td></td>
|
50 |
+
<td><?php _e( 'Action One', 'bp-em' ) ?></td>
|
51 |
+
<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>
|
52 |
+
<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>
|
53 |
+
</tr>
|
54 |
+
<tr>
|
55 |
+
<td></td>
|
56 |
+
<td><?php _e( 'Action Two', 'bp-em' ) ?></td>
|
57 |
+
<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>
|
58 |
+
<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>
|
59 |
+
</tr>
|
60 |
+
|
61 |
+
<?php do_action( 'bp_em_notification_settings' ); ?>
|
62 |
+
</table>
|
63 |
+
<?php
|
64 |
+
}
|
65 |
+
//add_action( 'bp_notification_settings', 'bp_em_screen_notification_settings' );
|
66 |
+
|
67 |
+
/**
|
68 |
+
* bp_em_format_notifications()
|
69 |
+
*
|
70 |
+
* The format notification function will take DB entries for notifications and format them
|
71 |
+
* so that they can be displayed and read on the screen.
|
72 |
+
*
|
73 |
+
* Notifications are "screen" notifications, that is, they appear on the notifications menu
|
74 |
+
* in the site wide navigation bar. They are not for email notifications.
|
75 |
+
*
|
76 |
+
*
|
77 |
+
* The recording is done by using bp_core_add_notification() which you can search for in this file for
|
78 |
+
* ems of usage.
|
79 |
+
*/
|
80 |
+
function bp_em_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
|
81 |
+
global $bp;
|
82 |
+
switch ( $action ) {
|
83 |
+
case 'pending_booking':
|
84 |
+
//Count pending bookings
|
85 |
+
if( get_option('dbem_bookings_approval')){
|
86 |
+
if ( $total_items > 1 ) {
|
87 |
+
return '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'bp-em' ) . '">' . __('You have a pending booking','dbem'). '</a>';
|
88 |
+
} else {
|
89 |
+
return apply_filters( 'bp_em_format_new_booking_notification', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'bp-em' ) . '">' . sprintf(__('You have %s pending bookings','dbem'), $total_items). '</a>' );
|
90 |
+
}
|
91 |
+
}
|
92 |
+
break;
|
93 |
+
case 'confirmed_booking':
|
94 |
+
//Count pending bookings
|
95 |
+
if ( $total_items > 1 ) {
|
96 |
+
return apply_filters( 'bp_em_format_confirmed_booking_notifications', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'bp-em' ) . '">' . __('You have a confirmed booking','dbem'). '</a>' );
|
97 |
+
} else {
|
98 |
+
return apply_filters( 'bp_em_format_confirmed_booking_notification', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'bp-em' ) . '">' . sprintf(__('You have %s confirmed bookings','dbem'), $total_items). '</a>' );
|
99 |
+
}
|
100 |
+
break;
|
101 |
+
case 'cancelled_booking':
|
102 |
+
//Count pending bookings
|
103 |
+
if ( $total_items > 1 ) {
|
104 |
+
return apply_filters( 'bp_em_format_cancelled_booking_notifications', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'bp-em' ) . '">' . __('A user cancelled a booking','dbem'). '</a>' );
|
105 |
+
} else {
|
106 |
+
return apply_filters( 'bp_em_format_cancelled_booking_notification', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'bp-em' ) . '">' . sprintf(__('%s users cancelled bookings.','dbem'), $total_items). '</a>' );
|
107 |
+
}
|
108 |
+
break;
|
109 |
+
}
|
110 |
+
do_action( 'bp_em_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
|
111 |
+
|
112 |
+
return false;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Catch booking saves and add a BP notification.
|
117 |
+
* @param boolean $result
|
118 |
+
* @param EM_Booking $EM_Booking
|
119 |
+
* @return boolean
|
120 |
+
*/
|
121 |
+
function bp_em_add_booking_notification($result, $EM_Booking){
|
122 |
+
global $bp;
|
123 |
+
if( get_option('dbem_bookings_approval') && $EM_Booking->status == 0 ){
|
124 |
+
$action = 'pending_booking';
|
125 |
+
}elseif( $EM_Booking->status == 1 || (get_option('dbem_bookings_approval') && $EM_Booking->status == 0) ){
|
126 |
+
$action = 'confirmed_booking';
|
127 |
+
}elseif( $EM_Booking->status == 3 ){
|
128 |
+
$action = 'cancelled_booking';
|
129 |
+
}
|
130 |
+
if( !empty($action) ){
|
131 |
+
bp_core_add_notification( $EM_Booking->id, $EM_Booking->get_event()->owner, 'events', $action );
|
132 |
+
}
|
133 |
+
return $result;
|
134 |
+
}
|
135 |
+
add_filter('em_booking_save','bp_em_add_booking_notification',1,2);
|
buddypress/bp-em-templatetags.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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( 'Events I\'m Attending', 'bp-em' );
|
24 |
+
}
|
25 |
+
|
26 |
+
function bp_em_attending_content() {
|
27 |
+
//We can use the same template as the public user interface for non bp sites
|
28 |
+
em_locate_template('templates/my-bookings.php',true);
|
29 |
+
}
|
buddypress/screens/group-events.php
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Controller for the event views in BP (using mvc terms here)
|
4 |
+
*/
|
5 |
+
function bp_em_group_events() {
|
6 |
+
global $bp;
|
7 |
+
do_action( 'bp_em_group_events' );
|
8 |
+
|
9 |
+
add_action( 'bp_template_title', 'bp_em_group_events_title' );
|
10 |
+
add_action( 'bp_template_content', 'bp_em_group_events_content' );
|
11 |
+
|
12 |
+
/* Finally load the plugin template file. */
|
13 |
+
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'groups/single/plugins' ) );
|
14 |
+
}
|
15 |
+
|
16 |
+
function bp_em_group_events_title() {
|
17 |
+
_e( 'Group Events', 'dbem' );
|
18 |
+
}
|
19 |
+
/**
|
20 |
+
* Determines whether to show event page or events page, and saves any updates to the event or events
|
21 |
+
* @return null
|
22 |
+
*/
|
23 |
+
function bp_em_group_events_content() {
|
24 |
+
em_locate_template('buddypress/group-events.php', true);
|
25 |
+
}
|
26 |
+
|
27 |
+
?>
|
buddypress/screens/my-bookings.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_my_bookings() {
|
8 |
+
global $bp, $EM_Event;
|
9 |
+
|
10 |
+
//assume any notifications here are considered viewed via this page
|
11 |
+
bp_core_delete_notifications_for_user_by_type(get_current_user_id(), 'events','pending_booking');
|
12 |
+
bp_core_delete_notifications_for_user_by_type(get_current_user_id(), 'events','confirmed_booking');
|
13 |
+
bp_core_delete_notifications_for_user_by_type(get_current_user_id(), 'events','cancelled_booking');
|
14 |
+
|
15 |
+
if( !is_object($EM_Event) && !empty($_REQUEST['event_id']) ){
|
16 |
+
$EM_Event = new EM_Event($_REQUEST['event_id']);
|
17 |
+
}
|
18 |
+
/**
|
19 |
+
* If the user has not Accepted or Rejected anything, then the code above will not run,
|
20 |
+
* we can continue and load the template.
|
21 |
+
*/
|
22 |
+
do_action( 'bp_em_my_bookings' );
|
23 |
+
|
24 |
+
add_action( 'bp_template_title', 'bp_em_my_bookings_title' );
|
25 |
+
add_action( 'bp_template_content', 'bp_em_my_bookings_content' );
|
26 |
+
|
27 |
+
/* Finally load the plugin template file. */
|
28 |
+
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
|
29 |
+
}
|
30 |
+
|
31 |
+
function bp_em_my_bookings_title() {
|
32 |
+
_e( 'My Event Bookings', 'dbem' );
|
33 |
+
}
|
34 |
+
|
35 |
+
function bp_em_my_bookings_content() {
|
36 |
+
em_locate_template('buddypress/my-bookings.php',true);
|
37 |
+
}
|
buddypress/screens/my-events.php
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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( !empty($bp->action_variables[0]) ){
|
23 |
+
switch($bp->action_variables[0]){
|
24 |
+
case 'edit':
|
25 |
+
$template_title = 'bp_em_my_events_editor_title';
|
26 |
+
$template_content = 'bp_em_my_events_editor';
|
27 |
+
break;
|
28 |
+
}
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
add_action( 'bp_template_title', $template_title );
|
33 |
+
add_action( 'bp_template_content', $template_content );
|
34 |
+
|
35 |
+
/* Finally load the plugin template file. */
|
36 |
+
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
|
37 |
+
}
|
38 |
+
|
39 |
+
function bp_em_my_events_title() {
|
40 |
+
_e( 'My Events', 'dbem' );
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Determines whether to show event page or events page, and saves any updates to the event or events
|
45 |
+
* @return null
|
46 |
+
*/
|
47 |
+
function bp_em_my_events_content() {
|
48 |
+
em_locate_template('buddypress/my-events.php', true);
|
49 |
+
}
|
50 |
+
|
51 |
+
function bp_em_my_events_editor_title() {
|
52 |
+
global $EM_Event;
|
53 |
+
if( is_object($EM_Event) ){
|
54 |
+
_e( 'Edit Event', 'dbem' );
|
55 |
+
}else{
|
56 |
+
_e( 'Add Event', 'dbem' );
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
function bp_em_my_events_editor(){
|
61 |
+
em_locate_template('forms/event-editor.php', true);
|
62 |
+
}
|
63 |
+
|
64 |
+
?>
|
buddypress/screens/my-group-events.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Controller for the event views in BP (using mvc terms here)
|
4 |
+
*/
|
5 |
+
function bp_em_my_group_events() {
|
6 |
+
global $bp;
|
7 |
+
do_action( 'bp_em_my_group_events' );
|
8 |
+
|
9 |
+
add_action( 'bp_template_title', 'bp_em_my_group_events_title' );
|
10 |
+
add_action( 'bp_template_content', 'bp_em_my_group_events_content' );
|
11 |
+
|
12 |
+
/* Finally load the plugin template file. */
|
13 |
+
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
|
14 |
+
}
|
15 |
+
|
16 |
+
function bp_em_my_group_events_title() {
|
17 |
+
_e( 'Group Events', 'dbem' );
|
18 |
+
}
|
19 |
+
|
20 |
+
function bp_em_my_group_events_content(){
|
21 |
+
em_locate_template('buddypress/my-group-events.php', true);
|
22 |
+
}
|
23 |
+
|
24 |
+
?>
|
buddypress/screens/my-locations.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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( !empty($bp->action_variables[0]) ){
|
23 |
+
switch($bp->action_variables[0]){
|
24 |
+
case 'edit':
|
25 |
+
$template_title = 'bp_em_my_locations_editor_title';
|
26 |
+
$template_content = 'bp_em_my_locations_editor_content';
|
27 |
+
break;
|
28 |
+
default :
|
29 |
+
$template_title = 'bp_em_my_locations_title';
|
30 |
+
$template_content = 'bp_em_my_locations_content';
|
31 |
+
break;
|
32 |
+
}
|
33 |
+
}else{
|
34 |
+
$template_title = 'bp_em_my_locations_title';
|
35 |
+
$template_content = 'bp_em_my_locations_content';
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
add_action( 'bp_template_title', $template_title );
|
40 |
+
add_action( 'bp_template_content', $template_content );
|
41 |
+
|
42 |
+
/* Finally load the plugin template file. */
|
43 |
+
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
|
44 |
+
}
|
45 |
+
|
46 |
+
function bp_em_my_locations_title() {
|
47 |
+
_e( 'My Locations', 'dbem' );
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Determines whether to show location page or locations page, and saves any updates to the location or locations
|
52 |
+
* @return null
|
53 |
+
*/
|
54 |
+
function bp_em_my_locations_content() {
|
55 |
+
em_locate_template('buddypress/my-locations.php', true);
|
56 |
+
}
|
57 |
+
|
58 |
+
function bp_em_my_locations_editor_title() {
|
59 |
+
global $EM_Location;
|
60 |
+
if( is_object($EM_Location) ){
|
61 |
+
_e( 'Edit Location', 'dbem' );
|
62 |
+
}else{
|
63 |
+
_e( 'Add Location', 'dbem' );
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
function bp_em_my_locations_editor_content(){
|
68 |
+
em_locate_template('forms/location-editor.php', true);
|
69 |
+
}
|
70 |
+
|
71 |
+
?>
|
buddypress/screens/profile.php
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
function bp_em_screen_settings_menu() {
|
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', 'members/single/plugins' ) );
|
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-settings/'; ?>" 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' ) ?> »" 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,379 +1,579 @@
|
|
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 $
|
8 |
-
var $
|
9 |
-
var $
|
10 |
-
var $
|
11 |
-
var $
|
12 |
-
|
13 |
-
'
|
14 |
-
'
|
15 |
-
'
|
16 |
-
'
|
17 |
-
'
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
var $
|
23 |
-
var $
|
24 |
-
var $
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
*
|
39 |
-
* @
|
40 |
-
*/
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
//
|
69 |
-
$
|
70 |
-
if(
|
71 |
-
$
|
72 |
-
}
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
*
|
171 |
-
*/
|
172 |
-
function
|
173 |
-
global $
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
}
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
}
|
191 |
-
|
192 |
-
|
193 |
-
*
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
$
|
198 |
-
$result =
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
$this->
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
$this->
|
242 |
-
}
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
}
|
355 |
-
|
356 |
-
/**
|
357 |
-
*
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
?>
|
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 |
+
* If set to true, this booking can be managed by any logged in user.
|
56 |
+
* @var EM_Tickets_Bookings
|
57 |
+
*/
|
58 |
+
var $manage_override;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* 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.
|
62 |
+
* @param mixed $booking_data
|
63 |
+
* @return null
|
64 |
+
*/
|
65 |
+
function EM_Booking( $booking_data = false ){
|
66 |
+
//Get the person for this booking
|
67 |
+
if( $booking_data !== false ){
|
68 |
+
//Load booking data
|
69 |
+
$booking = array();
|
70 |
+
if( is_array($booking_data) ){
|
71 |
+
$booking = $booking_data;
|
72 |
+
}elseif( is_numeric($booking_data) ){
|
73 |
+
//Retreiving from the database
|
74 |
+
global $wpdb;
|
75 |
+
$sql = "SELECT * FROM ". EM_BOOKINGS_TABLE ." LEFT JOIN ". EM_META_TABLE ." ON object_id=booking_id WHERE booking_id ='$booking_data'";
|
76 |
+
$booking = $wpdb->get_row($sql, ARRAY_A);
|
77 |
+
//Custom Fields
|
78 |
+
$custom = $wpdb->get_row("SELECT meta_key, meta_value FROM ". EM_BOOKINGS_TABLE ." LEFT JOIN ". EM_META_TABLE ." ON object_id=booking_id WHERE booking_id ='$booking_data' AND meta_key='booking_custom'");
|
79 |
+
//Booking notes
|
80 |
+
$notes = $wpdb->get_results("SELECT * FROM ". EM_META_TABLE ." WHERE meta_key='booking-note' AND object_id ='$booking_data'", ARRAY_A);
|
81 |
+
foreach($notes as $note){
|
82 |
+
$this->notes[] = unserialize($note['meta_value']);
|
83 |
+
}
|
84 |
+
}
|
85 |
+
//Save into the object
|
86 |
+
$this->to_object($booking);
|
87 |
+
$this->get_person();
|
88 |
+
$this->timestamp = strtotime($booking['booking_date']);
|
89 |
+
//Add custom booking data
|
90 |
+
if( !empty($custom['meta_key']) && $custom['meta_key'] == 'booking_custom' && is_serialized($custom['meta_value']) ){
|
91 |
+
$this->custom = unserialize($custom['meta_value']);
|
92 |
+
}
|
93 |
+
}
|
94 |
+
//Do it here so things appear in the po file.
|
95 |
+
$this->status_array = array(
|
96 |
+
0 => __('Pending','dbem'),
|
97 |
+
1 => __('Approved','dbem'),
|
98 |
+
2 => __('Rejected','dbem'),
|
99 |
+
3 => __('Cancelled','dbem'),
|
100 |
+
4 => __('Awaiting Online Payment','dbem'),
|
101 |
+
5 => __('Awaiting Payment','dbem')
|
102 |
+
);
|
103 |
+
do_action('em_booking', $this, $booking_data);
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Saves the booking into the database, whether a new or existing booking
|
108 |
+
* @param $mail whether or not to email the user and contact people
|
109 |
+
* @return boolean
|
110 |
+
*/
|
111 |
+
function save($mail = true){
|
112 |
+
global $wpdb;
|
113 |
+
$table = EM_BOOKINGS_TABLE;
|
114 |
+
do_action('em_booking_save_pre',$this);
|
115 |
+
if( $this->validate() ){
|
116 |
+
if( $this->can_manage() ){
|
117 |
+
$this->person_id = $this->get_person()->ID;
|
118 |
+
//Step 1. Save the booking
|
119 |
+
$data = $this->to_array();
|
120 |
+
if($this->id != ''){
|
121 |
+
$update = true;
|
122 |
+
$where = array( 'booking_id' => $this->id );
|
123 |
+
$result = $wpdb->update($table, $data, $where, $this->get_types($data));
|
124 |
+
$result = ($result !== false);
|
125 |
+
$this->feedback_message = __('Changes saved','dbem');
|
126 |
+
}else{
|
127 |
+
$update = false;
|
128 |
+
$result = $wpdb->insert($table, $data, $this->get_types($data));
|
129 |
+
$this->id = $wpdb->insert_id;
|
130 |
+
$this->feedback_message = __('Your booking has been recorded','dbem');
|
131 |
+
}
|
132 |
+
if( $result === false ){
|
133 |
+
$this->feedback_message = __('There was a problem saving the booking.', 'dbem');
|
134 |
+
$this->errors[] = __('There was a problem saving the booking.', 'dbem');
|
135 |
+
}else{
|
136 |
+
//Step 2. Insert ticket bookings for this booking id
|
137 |
+
$tickets_bookings_result = $this->get_tickets_bookings()->save();
|
138 |
+
if( !$tickets_bookings_result ){
|
139 |
+
if( !$update ){
|
140 |
+
//delete the booking and tickets, instead of a transaction
|
141 |
+
$this->delete();
|
142 |
+
}
|
143 |
+
$this->errors[] = __('There was a problem saving the booking.', 'dbem');
|
144 |
+
$this->add_errors( $this->get_tickets_bookings()->get_errors() );
|
145 |
+
}
|
146 |
+
}
|
147 |
+
if ( count($this->errors) == 0 && $mail ) {
|
148 |
+
$this->email();
|
149 |
+
}
|
150 |
+
return apply_filters('em_booking_save', ( count($this->errors) == 0 ), $this);
|
151 |
+
}else{
|
152 |
+
$this->feedback_message = __('There was a problem saving the booking.', 'dbem');
|
153 |
+
if( !$this->can_manage() ){
|
154 |
+
$this->feedback_message = sprintf(__('You cannot manage this %s.', 'dbem'),__('Booking','dbem'));
|
155 |
+
}
|
156 |
+
}
|
157 |
+
}else{
|
158 |
+
$this->feedback_message = __('There was a problem saving the booking.', 'dbem');
|
159 |
+
if( !$this->can_manage() ){
|
160 |
+
$this->feedback_message = sprintf(__('You cannot manage this %s.', 'dbem'),__('Booking','dbem'));
|
161 |
+
}
|
162 |
+
}
|
163 |
+
return apply_filters('em_booking_save', false, $this);
|
164 |
+
}
|
165 |
+
|
166 |
+
/**
|
167 |
+
* Load an record into this object by passing an associative array of table criterie to search for.
|
168 |
+
* Returns boolean depending on whether a record is found or not.
|
169 |
+
* @param $search
|
170 |
+
* @return boolean
|
171 |
+
*/
|
172 |
+
function get($search) {
|
173 |
+
global $wpdb;
|
174 |
+
$conds = array();
|
175 |
+
foreach($search as $key => $value) {
|
176 |
+
if( array_key_exists($key, $this->fields) ){
|
177 |
+
$value = $wpdb->escape($value);
|
178 |
+
$conds[] = "`$key`='$value'";
|
179 |
+
}
|
180 |
+
}
|
181 |
+
$sql = "SELECT * FROM ". $wpdb->EM_BOOKINGS_TABLE ." WHERE " . implode(' AND ', $conds) ;
|
182 |
+
$result = $wpdb->get_row($sql, ARRAY_A);
|
183 |
+
if($result){
|
184 |
+
$this->to_object($result);
|
185 |
+
$this->person = new EM_Person($this->person_id);
|
186 |
+
return true;
|
187 |
+
}else{
|
188 |
+
return false;
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Get posted data and save it into the object (not db)
|
194 |
+
* @return boolean
|
195 |
+
*/
|
196 |
+
function get_post(){
|
197 |
+
$this->tickets_bookings = new EM_Tickets_Bookings($this->id);
|
198 |
+
$result = array();
|
199 |
+
$this->event_id = $this->get_event()->id;
|
200 |
+
if( !empty($_REQUEST['em_tickets']) && is_array($_REQUEST['em_tickets']) ){
|
201 |
+
foreach( $_REQUEST['em_tickets'] as $ticket_id => $values){
|
202 |
+
//make sure ticket exists
|
203 |
+
if( !empty($values['spaces']) ){
|
204 |
+
$args = array('ticket_id'=>$ticket_id, 'ticket_booking_spaces'=>$values['spaces'], 'booking_id'=>$this->id);
|
205 |
+
if($this->get_event()->get_bookings()->ticket_exists($ticket_id)){
|
206 |
+
$EM_Ticket_Booking = new EM_Ticket_Booking($args);
|
207 |
+
$EM_Ticket_Booking->booking = $this;
|
208 |
+
$this->tickets_bookings->add( $EM_Ticket_Booking );
|
209 |
+
}else{
|
210 |
+
$this->errors[]=__('You are trying to book a non-existent ticket for this event.','dbem');
|
211 |
+
}
|
212 |
+
}
|
213 |
+
}
|
214 |
+
$this->comment = (!empty($_REQUEST['booking_comment'])) ? $_REQUEST['booking_comment']:'';
|
215 |
+
$this->get_spaces();
|
216 |
+
$this->get_price();
|
217 |
+
$this->get_person();
|
218 |
+
}
|
219 |
+
return apply_filters('em_booking_get_post',$this->validate(),$this);
|
220 |
+
}
|
221 |
+
|
222 |
+
function validate(){
|
223 |
+
//step 1, basic info
|
224 |
+
$basic = (
|
225 |
+
(empty($this->event_id) || is_numeric($this->event_id)) &&
|
226 |
+
(empty($this->person_id) || is_numeric($this->person_id)) &&
|
227 |
+
is_numeric($this->spaces) && $this->spaces > 0
|
228 |
+
);
|
229 |
+
//give some errors in step 1
|
230 |
+
if( $this->spaces == 0 ){
|
231 |
+
$this->add_error(__('You must request at least one space to book an event.','dbem'));
|
232 |
+
}
|
233 |
+
//step 2, tickets bookings info
|
234 |
+
if( count($this->get_tickets_bookings()) > 0 ){
|
235 |
+
$ticket_validation = array();
|
236 |
+
foreach($this->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking){
|
237 |
+
if ( !$EM_Ticket_Booking->validate() ){
|
238 |
+
$ticket_validation[] = false;
|
239 |
+
$result = $basic && !in_array(false,$ticket_validation);
|
240 |
+
}
|
241 |
+
$this->errors = array_merge($this->errors, $EM_Ticket_Booking->get_errors());
|
242 |
+
}
|
243 |
+
$result = $basic && !in_array(false,$ticket_validation);
|
244 |
+
}else{
|
245 |
+
$result = false;
|
246 |
+
}
|
247 |
+
|
248 |
+
return apply_filters('em_booking_validate',$result,$this);
|
249 |
+
}
|
250 |
+
|
251 |
+
/**
|
252 |
+
* Get the total number of spaces booked in THIS booking. Seting $force_refresh to true will recheck spaces, even if previously done so.
|
253 |
+
* @param unknown_type $force_refresh
|
254 |
+
* @return mixed
|
255 |
+
*/
|
256 |
+
function get_spaces( $force_refresh=false ){
|
257 |
+
if($this->spaces == 0 || $force_refresh == true ){
|
258 |
+
$this->spaces = $this->get_tickets_bookings()->get_spaces($force_refresh);
|
259 |
+
}
|
260 |
+
return apply_filters('em_booking_get_spaces',$this->spaces,$this);
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Gets the total price for this whole booking. Seting $force_reset to true will recheck spaces, even if previously done so.
|
265 |
+
* @param boolean $force_refresh
|
266 |
+
* @return float
|
267 |
+
*/
|
268 |
+
function get_price( $force_refresh=false, $format=false ){
|
269 |
+
if($force_refresh || $this->price == 0){
|
270 |
+
$this->price = $this->get_tickets_bookings()->get_price($force_refresh);
|
271 |
+
}
|
272 |
+
if($format){
|
273 |
+
return apply_filters('em_booking_get_prices', em_get_currency_symbol().number_format($this->price,2),$this);
|
274 |
+
}
|
275 |
+
return apply_filters('em_booking_get_prices',$this->price,$this);
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Gets the event this booking belongs to and saves a refernece in the event property
|
280 |
+
* @return EM_Event
|
281 |
+
*/
|
282 |
+
function get_event(){
|
283 |
+
global $EM_Event;
|
284 |
+
if( is_object($this->event) && get_class($this->event)=='EM_Event' && $this->event->id == $this->event_id ){
|
285 |
+
return $this->event;
|
286 |
+
}elseif( is_object($EM_Event) && ( (is_object($this->event) &&$this->event->id == $this->event_id) || empty($this->id)) ){
|
287 |
+
$this->event = $EM_Event;
|
288 |
+
}else{
|
289 |
+
$this->event = new EM_Event($this->event_id);
|
290 |
+
}
|
291 |
+
return apply_filters('em_booking_get_event',$this->event);
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* Get custom fields for this booking.
|
296 |
+
* @return array
|
297 |
+
*/
|
298 |
+
function get_custom(){
|
299 |
+
global $wpdb;
|
300 |
+
if( count($this->custom) == 0 ){
|
301 |
+
$sql = "SELECT * FROM ". EM_META_TABLE ." WHERE object_id ='{$this->id}' AND (meta_key='booking_custom' OR meta_key IS NULL)";
|
302 |
+
$booking = $wpdb->get_row($sql, ARRAY_A);
|
303 |
+
//Add custom booking data
|
304 |
+
if( !empty($booking['meta_key']) && $booking['meta_key'] == 'booking_custom' && is_serialized($booking['meta_value']) ){
|
305 |
+
$this->custom = unserialize($booking['meta_value']);
|
306 |
+
}
|
307 |
+
}
|
308 |
+
return $this->custom;
|
309 |
+
}
|
310 |
+
|
311 |
+
/**
|
312 |
+
* Gets the ticket object this booking belongs to, saves a reference in ticket property
|
313 |
+
* @return EM_Tickets
|
314 |
+
*/
|
315 |
+
function get_tickets(){
|
316 |
+
if( is_object($this->tickets) && get_class($this->tickets)=='EM_Tickets' ){
|
317 |
+
return apply_filters('em_booking_get_tickets', $this->tickets, $this);
|
318 |
+
}else{
|
319 |
+
$this->tickets = new EM_Tickets($this);
|
320 |
+
}
|
321 |
+
return apply_filters('em_booking_get_tickets', $this->tickets, $this);
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* Gets the ticket object this booking belongs to, saves a reference in ticket property
|
326 |
+
* @return EM_Tickets_Bookings
|
327 |
+
*/
|
328 |
+
function get_tickets_bookings(){
|
329 |
+
global $wpdb;
|
330 |
+
if( !is_object($this->tickets_bookings) && get_class($this->tickets_bookings)!='EM_Tickets_Bookings'){
|
331 |
+
$this->tickets_bookings = new EM_Tickets_Bookings($this);
|
332 |
+
}
|
333 |
+
return apply_filters('em_booking_get_tickets_bookings', $this->tickets_bookings, $this);
|
334 |
+
}
|
335 |
+
|
336 |
+
function get_person(){
|
337 |
+
global $EM_Person;
|
338 |
+
if( is_object($this->person) && get_class($this->person)=='EM_Person' && ($this->person->ID == $this->person_id || empty($this->person_id) ) ){
|
339 |
+
return apply_filters('em_booking_get_person', $this->person, $this);
|
340 |
+
}elseif( is_object($EM_Person) && ($EM_Person->ID === $this->person_id || $this->id == '') ){
|
341 |
+
$this->person = $EM_Person;
|
342 |
+
}elseif( is_numeric($this->person_id) ){
|
343 |
+
$this->person = new EM_Person($this->person_id);
|
344 |
+
}
|
345 |
+
return apply_filters('em_booking_get_person', $this->person, $this);
|
346 |
+
}
|
347 |
+
|
348 |
+
/**
|
349 |
+
* Returns a string representation of the booking's status
|
350 |
+
* @return string
|
351 |
+
*/
|
352 |
+
function get_status(){
|
353 |
+
return $this->status_array[$this->status];
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* I wonder what this does....
|
358 |
+
* @return boolean
|
359 |
+
*/
|
360 |
+
function delete(){
|
361 |
+
global $wpdb;
|
362 |
+
//FIXME ticket logic needed
|
363 |
+
$sql = $wpdb->prepare("DELETE FROM ". EM_BOOKINGS_TABLE . " WHERE booking_id=%d", $this->id);
|
364 |
+
$result = $wpdb->query( $sql );
|
365 |
+
if( $result !== false ){
|
366 |
+
//delete the tickets too
|
367 |
+
$this->get_tickets_bookings()->delete();
|
368 |
+
$this->previous_status = $this->status;
|
369 |
+
$this->status = false;
|
370 |
+
$this->feedback_message = sprintf(__('%s deleted', 'dbem'), __('Booking','dbem'));
|
371 |
+
}else{
|
372 |
+
$this->add_error(sprintf(__('%s could not be deleted', 'dbem'), __('Booking','dbem')));
|
373 |
+
}
|
374 |
+
return apply_filters('em_booking_delete',( $result !== false ), $this);
|
375 |
+
}
|
376 |
+
|
377 |
+
function cancel(){
|
378 |
+
if( $this->person->ID == get_current_user_id() ){
|
379 |
+
$this->manage_override = true; //normally, users can't manage a bookiing, only event owners, so we allow them to mod their booking status in this case only.
|
380 |
+
}
|
381 |
+
return $this->set_status(3);
|
382 |
+
}
|
383 |
+
|
384 |
+
/**
|
385 |
+
* Approve a booking.
|
386 |
+
* @return bool
|
387 |
+
*/
|
388 |
+
function approve(){
|
389 |
+
return $this->set_status(1);
|
390 |
+
}
|
391 |
+
/**
|
392 |
+
* Reject a booking and save
|
393 |
+
* @return bool
|
394 |
+
*/
|
395 |
+
function reject(){
|
396 |
+
return $this->set_status(2);
|
397 |
+
}
|
398 |
+
/**
|
399 |
+
* Unpprove a booking.
|
400 |
+
* @return bool
|
401 |
+
*/
|
402 |
+
function unapprove(){
|
403 |
+
return $this->set_status(0);
|
404 |
+
}
|
405 |
+
|
406 |
+
/**
|
407 |
+
* Change the status of the booking. This will save to the Database too.
|
408 |
+
* @param int $status
|
409 |
+
* @return boolean
|
410 |
+
*/
|
411 |
+
function set_status($status){
|
412 |
+
$action_string = strtolower($this->status_array[$status]);
|
413 |
+
//if we're approving we can't approve a booking if spaces are full, so check before it's approved.
|
414 |
+
if($status == 1){
|
415 |
+
if( $this->get_event()->get_bookings()->get_available_spaces() < $this->get_spaces() && !get_option('dbem_bookings_approval_overbooking') ){
|
416 |
+
$this->feedback_message = sprintf(__('Not approved, spaces full.','dbem'), $action_string);
|
417 |
+
return apply_filters('em_booking_set_status', false, $this);
|
418 |
+
}
|
419 |
+
}
|
420 |
+
$this->previous_status = $this->status;
|
421 |
+
$this->status = $status;
|
422 |
+
$result = $this->save(false);
|
423 |
+
if($result){
|
424 |
+
$this->feedback_message = sprintf(__('Booking %s.','dbem'), $action_string);
|
425 |
+
if( !($this->status == 0 && $this->previous_status > 0) || $this->previous_status == 4 ){
|
426 |
+
if( $this->email() ){
|
427 |
+
$this->feedback_message .= " ".__('Mail Sent.','dbem');
|
428 |
+
}elseif( $this->previous_status == 0 ){
|
429 |
+
//extra errors may be logged by email() in EM_Object
|
430 |
+
$this->feedback_message .= ' <span style="color:red">'.__('ERROR : Mail Not Sent.','dbem').'</span>';
|
431 |
+
$this->add_error(__('ERROR : Mail Not Sent.','dbem'));
|
432 |
+
$result = false;
|
433 |
+
}
|
434 |
+
}
|
435 |
+
}else{
|
436 |
+
//errors should be logged by save()
|
437 |
+
$this->feedback_message = sprintf(__('Booking could not be %s.','dbem'), $action_string);
|
438 |
+
$this->add_error(sprintf(__('Booking could not be %s.','dbem'), $action_string));
|
439 |
+
}
|
440 |
+
return apply_filters('em_booking_set_status', $result, $this);
|
441 |
+
}
|
442 |
+
|
443 |
+
/**
|
444 |
+
* Add a booking note to this booking. returns wpdb result or false if use can't manage this event.
|
445 |
+
* @param string $note
|
446 |
+
* @return mixed
|
447 |
+
*/
|
448 |
+
function add_note( $note_text ){
|
449 |
+
global $wpdb;
|
450 |
+
if( $this->can_manage() ){
|
451 |
+
$note = array('author'=>get_current_user_id(),'note'=>$note_text,'timestamp'=>current_time('timestamp'));
|
452 |
+
$this->notes[] = $note;
|
453 |
+
$this->feedback_message = __('Booking note successfully added.','dbem');
|
454 |
+
return $wpdb->insert(EM_META_TABLE, array('object_id'=>$this->id, 'meta_key'=>'booking-note', 'meta_value'=> serialize($note)),array('%d','%s','%s'));
|
455 |
+
}
|
456 |
+
return false;
|
457 |
+
}
|
458 |
+
|
459 |
+
/**
|
460 |
+
* @param EM_Booking $EM_Booking
|
461 |
+
* @param EM_Event $event
|
462 |
+
* @return boolean
|
463 |
+
*/
|
464 |
+
function email(){
|
465 |
+
global $EM_Mailer;
|
466 |
+
//FIXME ticket logic needed
|
467 |
+
$EM_Event = $this->get_event(); //We NEED event details here.
|
468 |
+
//Make sure event matches booking, and that booking used to be approved.
|
469 |
+
if( !($this->status == 0 && $this->previous_status > 0) || $this->previous_status == 4 ){
|
470 |
+
$contact_id = ( $EM_Event->owner != "") ? $EM_Event->owner : get_option('dbem_default_contact_person');
|
471 |
+
|
472 |
+
$contact_subject = get_option('dbem_bookings_contact_email_subject');
|
473 |
+
$contact_body = get_option('dbem_bookings_contact_email_body');
|
474 |
+
|
475 |
+
if( get_option('dbem_bookings_approval') == 0 && $this->status < 2 || $this->status == 1 ){
|
476 |
+
$booker_subject = get_option('dbem_bookings_email_confirmed_subject');
|
477 |
+
$booker_body = get_option('dbem_bookings_email_confirmed_body');
|
478 |
+
}elseif( $this->status == 0 || $this->status == 5 || ( $this->status == 0 && ($this->previous_status == 4 || $this->previous_status == 5) ) ){
|
479 |
+
$booker_subject = get_option('dbem_bookings_email_pending_subject');
|
480 |
+
$booker_body = get_option('dbem_bookings_email_pending_body');
|
481 |
+
}elseif( $this->status == 2 ){
|
482 |
+
$booker_subject = get_option('dbem_bookings_email_rejected_subject');
|
483 |
+
$booker_body = get_option('dbem_bookings_email_rejected_body');
|
484 |
+
}elseif( $this->status == 3 ){
|
485 |
+
$booker_subject = get_option('dbem_bookings_email_cancelled_subject');
|
486 |
+
$booker_body = get_option('dbem_bookings_email_cancelled_body');
|
487 |
+
$contact_subject = get_option('dbem_contactperson_email_cancelled_subject');
|
488 |
+
$contact_body = get_option('dbem_contactperson_email_cancelled_body');
|
489 |
+
}else{
|
490 |
+
return true;
|
491 |
+
}
|
492 |
+
|
493 |
+
// email specific placeholders
|
494 |
+
foreach( $this->get_tickets() as $EM_Ticket){ break; }
|
495 |
+
ob_start();
|
496 |
+
em_locate_template('emails/bookingtickets.php', true, array('EM_Booking'=>$this));
|
497 |
+
$tickets = ob_get_clean();
|
498 |
+
$placeholders = array(
|
499 |
+
'#_RESPNAME' => '#_BOOKINGNAME',//Depreciated
|
500 |
+
'#_RESPEMAIL' => '#_BOOKINGEMAIL',//Depreciated
|
501 |
+
'#_RESPPHONE' => '#_BOOKINGPHONE',//Depreciated
|
502 |
+
'#_COMMENT' => '#_BOOKINGCOMMENT',//Depreciated
|
503 |
+
'#_RESERVEDSPACES' => '#_BOOKEDSPACES',//Depreciated
|
504 |
+
'#_BOOKINGNAME' => $this->person->display_name,
|
505 |
+
'#_BOOKINGEMAIL' => $this->person->user_email,
|
506 |
+
'#_BOOKINGPHONE' => $this->person->phone,
|
507 |
+
'#_BOOKINGSPACES' => $this->get_spaces(),
|
508 |
+
'#_BOOKINGLISTURL' => em_get_my_bookings_url(),
|
509 |
+
'#_BOOKINGCOMMENT' => $this->comment,
|
510 |
+
'#_BOOKINGTICKETNAME' => $EM_Ticket->name,
|
511 |
+
'#_BOOKINGTICKETDESCRIPTION' => $EM_Ticket->description,
|
512 |
+
'#_BOOKINGTICKETPRICE' => em_get_currency_symbol(true)." ". number_format($EM_Ticket->get_price(true),2),
|
513 |
+
'#_BOOKINGTICKETS' => $tickets
|
514 |
+
);
|
515 |
+
foreach($placeholders as $key => $value) {
|
516 |
+
$contact_subject = str_replace($key, $value, $contact_subject);
|
517 |
+
$contact_body = str_replace($key, $value, $contact_body);
|
518 |
+
$booker_subject = str_replace($key, $value, $booker_subject);
|
519 |
+
$booker_body = str_replace($key, $value, $booker_body);
|
520 |
+
}
|
521 |
+
|
522 |
+
$booker_subject = $EM_Event->output($booker_subject, 'email');
|
523 |
+
$booker_body = $EM_Event->output($booker_body, 'email');
|
524 |
+
|
525 |
+
//Send to the person booking
|
526 |
+
if( !$this->email_send( $booker_subject,$booker_body, $this->person->user_email) ){
|
527 |
+
return false;
|
528 |
+
}
|
529 |
+
|
530 |
+
//Send admin/contact emails
|
531 |
+
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') != '') ){
|
532 |
+
//Only gets sent if this is a pending booking, unless approvals are disabled.
|
533 |
+
$contact_subject = $EM_Event->output($contact_subject, 'email');
|
534 |
+
$contact_body = $EM_Event->output($contact_body, 'email');
|
535 |
+
|
536 |
+
if( get_option('dbem_bookings_contact_email') == 1 ){
|
537 |
+
if( !$this->email_send( $contact_subject, $contact_body, $EM_Event->contact->user_email) && current_user_can('activate_plugins')){
|
538 |
+
$this->errors[] = __('Confirmation email could not be sent to contact person. Registrant should have gotten their email (only admin see this warning).','dbem');
|
539 |
+
return false;
|
540 |
+
}
|
541 |
+
}
|
542 |
+
|
543 |
+
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')) ){
|
544 |
+
if( !$this->email_send( $contact_subject, $contact_body, get_option('dbem_bookings_notify_admin')) ){
|
545 |
+
$this->errors[] = __('Confirmation email could not be sent to admin. Registrant should have gotten their email (only admin see this warning).','dbem');
|
546 |
+
return false;
|
547 |
+
}
|
548 |
+
}
|
549 |
+
}
|
550 |
+
return true;
|
551 |
+
}
|
552 |
+
return false;
|
553 |
+
//TODO need error checking for booking mail send
|
554 |
+
}
|
555 |
+
|
556 |
+
/**
|
557 |
+
* Can the user manage this event?
|
558 |
+
*/
|
559 |
+
function can_manage(){
|
560 |
+
return $this->get_event()->can_manage('manage_bookings','manage_others_bookings') || empty($this->id) || !empty($this->manage_override);
|
561 |
+
}
|
562 |
+
|
563 |
+
/**
|
564 |
+
* Returns this object in the form of an array
|
565 |
+
* @return array
|
566 |
+
*/
|
567 |
+
function to_array($person = false){
|
568 |
+
$booking = array();
|
569 |
+
//Core Data
|
570 |
+
$booking = parent::to_array();
|
571 |
+
//Person Data
|
572 |
+
if($person && is_object($this->person)){
|
573 |
+
$person = $this->person->to_array();
|
574 |
+
$booking = array_merge($booking, $person);
|
575 |
+
}
|
576 |
+
return $booking;
|
577 |
+
}
|
578 |
+
}
|
579 |
?>
|
classes/em-bookings.php
CHANGED
@@ -1,488 +1,627 @@
|
|
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 |
-
*
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
var $
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Creates an EM_Bookings instance,
|
30 |
-
* @param EM_Event $event
|
31 |
-
* @return null
|
32 |
-
*/
|
33 |
-
function EM_Bookings( $
|
34 |
-
if( is_object($
|
35 |
-
global $wpdb;
|
36 |
-
$this->
|
37 |
-
$
|
38 |
-
$
|
39 |
-
$bookings
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
}
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
$this->
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
*
|
132 |
-
* @
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
$
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
/**
|
207 |
-
*
|
208 |
-
* @
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
if(
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
*
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
$
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
$
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
$
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
//
|
399 |
-
$
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
$EM_Booking->person->
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
$
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
$
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
?>
|
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 |
+
/**
|
29 |
+
* 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.
|
30 |
+
* @param EM_Event $event
|
31 |
+
* @return null
|
32 |
+
*/
|
33 |
+
function EM_Bookings( $data = false ){
|
34 |
+
if( is_object($data) && get_class($data) == "EM_Event" ){ //Creates a blank bookings object if needed
|
35 |
+
global $wpdb;
|
36 |
+
$this->event = $data;
|
37 |
+
$sql = "SELECT * FROM ". EM_BOOKINGS_TABLE ." WHERE event_id ='{$this->event->id}'";
|
38 |
+
$bookings = $wpdb->get_results($sql, ARRAY_A);
|
39 |
+
foreach ($bookings as $booking){
|
40 |
+
$this->bookings[] = new EM_Booking($booking);
|
41 |
+
}
|
42 |
+
$this->spaces = $this->get_spaces();
|
43 |
+
}elseif( is_array($data) ){
|
44 |
+
foreach( $data as $EM_Booking ){
|
45 |
+
if( get_class($EM_Booking) == 'EM_Booking'){
|
46 |
+
$this->bookings[] = $EM_Booking;
|
47 |
+
}
|
48 |
+
}
|
49 |
+
$this->get_event();
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Add a booking into this event (or add spaces if person already booked this), checking that there's enough space for the event
|
55 |
+
* @param EM_Booking $EM_Booking
|
56 |
+
* @return boolean
|
57 |
+
*/
|
58 |
+
function add( $EM_Booking ){
|
59 |
+
global $wpdb,$EM_Mailer;
|
60 |
+
if ( $this->get_available_spaces() >= $EM_Booking->get_spaces(true) ) {
|
61 |
+
//Save the booking
|
62 |
+
$email = false;
|
63 |
+
$result = $EM_Booking->save(false);
|
64 |
+
if($result){
|
65 |
+
//Success
|
66 |
+
$this->bookings[] = $EM_Booking;
|
67 |
+
$email = $EM_Booking->email();
|
68 |
+
if( get_option('dbem_bookings_approval') == 1 && $EM_Booking->status == 0){
|
69 |
+
$this->feedback_message = __('Booking successful, pending confirmation (you will also receive an email once confirmed).', 'dbem');
|
70 |
+
}else{
|
71 |
+
$this->feedback_message = __('Booking successful.', 'dbem');
|
72 |
+
}
|
73 |
+
if(!$email){
|
74 |
+
$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');
|
75 |
+
if( current_user_can('activate_plugins') ){
|
76 |
+
if( count($EM_Booking->get_errors()) > 0 ){
|
77 |
+
$this->feedback_message .= '<br/><strong>Errors:</strong> (only admins see this message)<br/><ul><li>'. implode('</li><li>', $EM_Booking->get_errors()).'</li></ul>';
|
78 |
+
}else{
|
79 |
+
$this->feedback_message .= '<br/><strong>No errors returned by mailer</strong> (only admins see this message)';
|
80 |
+
}
|
81 |
+
}
|
82 |
+
}
|
83 |
+
return true;
|
84 |
+
}else{
|
85 |
+
//Failure
|
86 |
+
$this->errors[] = "<strong>".__('Booking could not be created','dbem').":</strong><br />". implode('<br />', $EM_Booking->errors);
|
87 |
+
}
|
88 |
+
} else {
|
89 |
+
$this->add_error(__('Booking cannot be made, not enough spaces available!', 'dbem'));
|
90 |
+
}
|
91 |
+
return false;
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Get POST data and create a booking for each ticket requested. If successful, a booking object is returned, false if not.
|
96 |
+
* @return false|object
|
97 |
+
*/
|
98 |
+
function add_from_post(){
|
99 |
+
$EM_Booking = new EM_booking();
|
100 |
+
$result = $EM_Booking->get_post();
|
101 |
+
if($result){
|
102 |
+
$result = $this->add($EM_Booking);
|
103 |
+
if($result){
|
104 |
+
$result = $EM_Booking;
|
105 |
+
}
|
106 |
+
$this->feedback_message = sprintf(__('%s created.','dbem'),__('Booking','dbem'));
|
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 |
+
/* @var EM_Ticket $EM_Ticket */
|
151 |
+
if( $EM_Ticket->is_available() ){
|
152 |
+
//within time range
|
153 |
+
if( $EM_Ticket->get_available_spaces() > 0 ){
|
154 |
+
$tickets[] = $EM_Ticket;
|
155 |
+
}
|
156 |
+
}
|
157 |
+
}
|
158 |
+
$EM_Tickets = new EM_Tickets($tickets);
|
159 |
+
return apply_filters('em_bookings_get_tickets', $EM_Tickets, $this);
|
160 |
+
}
|
161 |
+
|
162 |
+
function get_user_list(){
|
163 |
+
$users = array();
|
164 |
+
foreach( $this->get_bookings()->bookings as $EM_Booking ){
|
165 |
+
$users[$EM_Booking->person->ID] = $EM_Booking->person;
|
166 |
+
}
|
167 |
+
return $users;
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* does this ticket exist?
|
172 |
+
* @return bool
|
173 |
+
*/
|
174 |
+
function ticket_exists($ticket_id){
|
175 |
+
$EM_Tickets = $this->get_tickets();
|
176 |
+
foreach( $EM_Tickets->tickets as $EM_Ticket){
|
177 |
+
if($EM_Ticket->id == $ticket_id){
|
178 |
+
return apply_filters('em_bookings_ticket_exists',true, $EM_Ticket, $this);
|
179 |
+
}
|
180 |
+
}
|
181 |
+
return apply_filters('em_bookings_ticket_exists',false, $EM_Ticket,$this);
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Delete bookings on this id
|
186 |
+
* @return boolean
|
187 |
+
*/
|
188 |
+
function delete(){
|
189 |
+
global $wpdb;
|
190 |
+
$booking_ids = array();
|
191 |
+
//get the booking ids tied to this event
|
192 |
+
foreach( $this->bookings as $EM_Booking ){
|
193 |
+
$booking_ids[] = $EM_Booking->id;
|
194 |
+
}
|
195 |
+
$result_tickets = true;
|
196 |
+
$result = true;
|
197 |
+
if( count($booking_ids) > 0 ){
|
198 |
+
//Delete bookings and ticket bookings
|
199 |
+
$result_tickets = $wpdb->query("DELETE FROM ". EM_TICKETS_BOOKINGS_TABLE ." WHERE booing_id IN (".implode(',',$booking_ids).");");
|
200 |
+
$result = $wpdb->query("DELETE FROM ".EM_BOOKINGS_TABLE." WHERE event_id IN (".implode(',',$booking_ids).")");
|
201 |
+
}
|
202 |
+
return ($result !== false && $result_tickets !== false);
|
203 |
+
}
|
204 |
+
|
205 |
+
|
206 |
+
/**
|
207 |
+
* Will approve all supplied booking ids, which must be in the form of a numeric array or a single number.
|
208 |
+
* @param array|int $booking_ids
|
209 |
+
* @return boolean
|
210 |
+
*/
|
211 |
+
function approve( $booking_ids ){
|
212 |
+
$this->set_status(1, $booking_ids);
|
213 |
+
return false;
|
214 |
+
}
|
215 |
+
|
216 |
+
/**
|
217 |
+
* Will reject all supplied booking ids, which must be in the form of a numeric array or a single number.
|
218 |
+
* @param array|int $booking_ids
|
219 |
+
* @return boolean
|
220 |
+
*/
|
221 |
+
function reject( $booking_ids ){
|
222 |
+
return $this->set_status(2, $booking_ids);
|
223 |
+
}
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Will unapprove all supplied booking ids, which must be in the form of a numeric array or a single number.
|
227 |
+
* @param array|int $booking_ids
|
228 |
+
* @return boolean
|
229 |
+
*/
|
230 |
+
function unapprove( $booking_ids ){
|
231 |
+
return $this->set_status(0, $booking_ids);
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* @param int $status
|
236 |
+
* @param array|int $booking_ids
|
237 |
+
* @return bool
|
238 |
+
*/
|
239 |
+
function set_status($status, $booking_ids){
|
240 |
+
//FIXME status should work with instantiated object
|
241 |
+
//FIXME there is a vulnerability where any user can approve/reject bookings if they know the ID
|
242 |
+
if( $this->array_is_numeric($booking_ids) ){
|
243 |
+
//Get all the bookings
|
244 |
+
$results = array();
|
245 |
+
$mails = array();
|
246 |
+
foreach( $booking_ids as $booking_id ){
|
247 |
+
$EM_Booking = new EM_Booking($booking_id);
|
248 |
+
if( !$EM_Booking->can_manage() ){
|
249 |
+
$this->feedback_message = __('Bookings %s. Mails Sent.', 'dbem');
|
250 |
+
return false;
|
251 |
+
}
|
252 |
+
$results[] = $EM_Booking->set_status($status);
|
253 |
+
}
|
254 |
+
if( !in_array('false',$results) ){
|
255 |
+
$this->feedback_message = __('Bookings %s. Mails Sent.', 'dbem');
|
256 |
+
return true;
|
257 |
+
}else{
|
258 |
+
//TODO Better error handling needed if some bookings fail approval/failure
|
259 |
+
$this->feedback_message = __('An error occurred.', 'dbem');
|
260 |
+
return false;
|
261 |
+
}
|
262 |
+
}elseif( is_numeric($booking_ids) || is_object($booking_ids) ){
|
263 |
+
$EM_Booking = ( is_object($booking_ids) && get_class($booking_ids) == 'EM_Booking') ? $booking_ids : new EM_Booking($booking_ids);
|
264 |
+
$result = $EM_Booking->set_status($status);
|
265 |
+
$this->feedback_message = $EM_Booking->feedback_message;
|
266 |
+
return $result;
|
267 |
+
}
|
268 |
+
return false;
|
269 |
+
}
|
270 |
+
|
271 |
+
|
272 |
+
/**
|
273 |
+
* 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.
|
274 |
+
* @param boolean $force_refresh
|
275 |
+
* @return int
|
276 |
+
*/
|
277 |
+
function get_spaces( $force_refresh=false ){
|
278 |
+
if($force_refresh || $this->spaces == 0){
|
279 |
+
$this->spaces = $this->get_tickets()->get_spaces();
|
280 |
+
}
|
281 |
+
return apply_filters('em_booking_get_spaces',$this->spaces,$this);
|
282 |
+
}
|
283 |
+
|
284 |
+
/**
|
285 |
+
* Returns number of available spaces for this event. If approval of bookings is on, will include pending bookings depending on em option.
|
286 |
+
* @return int
|
287 |
+
*/
|
288 |
+
function get_available_spaces(){
|
289 |
+
$available_spaces = 0;
|
290 |
+
if( get_option('dbem_bookings_approval_reserved') == 1 ){
|
291 |
+
$available_spaces = $this->get_spaces() - $this->get_booked_spaces() - $this->get_pending_spaces();
|
292 |
+
}else{
|
293 |
+
$available_spaces = $this->get_spaces() - $this->get_booked_spaces();
|
294 |
+
}
|
295 |
+
return apply_filters('get_available_spaces', $available_spaces, $this);
|
296 |
+
}
|
297 |
+
|
298 |
+
/**
|
299 |
+
* Returns number of booked spaces for this event. If approval of bookings is on, will return number of booked confirmed spaces.
|
300 |
+
* @return int
|
301 |
+
*/
|
302 |
+
function get_booked_spaces(){
|
303 |
+
$booked_spaces = 0;
|
304 |
+
$EM_Bookings = $this->get_bookings(); //get bookings, automatically filtering approvals etc.
|
305 |
+
foreach ( $EM_Bookings->bookings as $EM_Booking ){
|
306 |
+
//never show cancelled status, nor pending if approvals required
|
307 |
+
$booked_spaces += $EM_Booking->get_spaces();
|
308 |
+
}
|
309 |
+
return $booked_spaces;
|
310 |
+
}
|
311 |
+
|
312 |
+
/**
|
313 |
+
* Gets number of pending spaces awaiting approval. Will return 0 if booking approval is not enabled.
|
314 |
+
* @return int
|
315 |
+
*/
|
316 |
+
function get_pending_spaces(){
|
317 |
+
if( get_option('dbem_bookings_approval') == 0 ){
|
318 |
+
return 0;
|
319 |
+
}
|
320 |
+
$pending = 0;
|
321 |
+
foreach ( $this->bookings as $booking ){
|
322 |
+
if($booking->status == 0){
|
323 |
+
$pending += $booking->get_spaces();
|
324 |
+
}
|
325 |
+
}
|
326 |
+
return $pending;
|
327 |
+
}
|
328 |
+
|
329 |
+
/**
|
330 |
+
* Gets number of bookings (not spaces). If booking approval is enabled, only the number of approved bookings will be shown.
|
331 |
+
* @return EM_Bookings
|
332 |
+
*/
|
333 |
+
function get_bookings(){
|
334 |
+
$confirmed = array();
|
335 |
+
foreach ( $this->bookings as $booking ){
|
336 |
+
if( $booking->status == 1 || (get_option('dbem_bookings_approval') == 0 && in_array($booking->status, array(1,2,5))) ){
|
337 |
+
$confirmed[] = $booking;
|
338 |
+
}
|
339 |
+
}
|
340 |
+
$EM_Bookings = new EM_Bookings($confirmed);
|
341 |
+
return $EM_Bookings;
|
342 |
+
}
|
343 |
+
|
344 |
+
/**
|
345 |
+
* Get pending bookings. If booking approval is disabled, will return no bookings.
|
346 |
+
* @return EM_Bookings
|
347 |
+
*/
|
348 |
+
function get_pending_bookings(){
|
349 |
+
if( get_option('dbem_bookings_approval') == 0 ){
|
350 |
+
return array();
|
351 |
+
}
|
352 |
+
$pending = array();
|
353 |
+
foreach ( $this->bookings as $booking ){
|
354 |
+
if($booking->status == 0){
|
355 |
+
$pending[] = $booking;
|
356 |
+
}
|
357 |
+
}
|
358 |
+
$EM_Bookings = new EM_Bookings($pending);
|
359 |
+
return $EM_Bookings;
|
360 |
+
}
|
361 |
+
|
362 |
+
/**
|
363 |
+
* Get rejected bookings. If booking approval is disabled, will return no bookings.
|
364 |
+
* @return array EM_Bookings
|
365 |
+
*/
|
366 |
+
function get_rejected_bookings(){
|
367 |
+
$rejected = array();
|
368 |
+
foreach ( $this->bookings as $booking ){
|
369 |
+
if($booking->status == 2){
|
370 |
+
$rejected[] = $booking;
|
371 |
+
}
|
372 |
+
}
|
373 |
+
$EM_Bookings = new EM_Bookings($rejected);
|
374 |
+
return $EM_Bookings;
|
375 |
+
}
|
376 |
+
|
377 |
+
/**
|
378 |
+
* Get cancelled bookings.
|
379 |
+
* @return array EM_Booking
|
380 |
+
*/
|
381 |
+
function get_cancelled_bookings(){
|
382 |
+
$cancelled = array();
|
383 |
+
foreach ( $this->bookings as $booking ){
|
384 |
+
if($booking->status == 3){
|
385 |
+
$cancelled[] = $booking;
|
386 |
+
}
|
387 |
+
}
|
388 |
+
$EM_Bookings = new EM_Bookings($cancelled);
|
389 |
+
return $EM_Bookings;
|
390 |
+
}
|
391 |
+
|
392 |
+
/**
|
393 |
+
* Checks if a person with similar details has booked for this before
|
394 |
+
* @param $person_id
|
395 |
+
* @return EM_Booking
|
396 |
+
*/
|
397 |
+
function find_previous_booking($EM_Booking){
|
398 |
+
//First see if we have a similar person on record that's making this booking
|
399 |
+
$EM_Booking->person->load_similar();
|
400 |
+
//If person exists on record, see if they've booked this event before, if so return the booking.
|
401 |
+
if( is_numeric($EM_Booking->person->ID) && $EM_Booking->person->ID > 0 ){
|
402 |
+
$EM_Booking->person_id = $EM_Booking->person->ID;
|
403 |
+
foreach ($this->bookings as $booking){
|
404 |
+
if( $booking->person_id == $EM_Booking->person->ID ){
|
405 |
+
return $booking;
|
406 |
+
}
|
407 |
+
}
|
408 |
+
}
|
409 |
+
return false;
|
410 |
+
}
|
411 |
+
|
412 |
+
/**
|
413 |
+
* Checks to see if user has a booking for this event
|
414 |
+
* @param unknown_type $user_id
|
415 |
+
*/
|
416 |
+
function has_booking( $user_id = false ){
|
417 |
+
if( $user_id === false ){
|
418 |
+
$user_id = get_current_user_id();
|
419 |
+
}
|
420 |
+
if( is_numeric($user_id) && $user_id > 0 ){
|
421 |
+
foreach ($this->bookings as $EM_Booking){
|
422 |
+
if( $EM_Booking->person->ID == $user_id && $EM_Booking->status != 3 ){
|
423 |
+
return apply_filters('em_bookings_has_booking', true, $this);
|
424 |
+
}
|
425 |
+
}
|
426 |
+
}
|
427 |
+
return apply_filters('em_bookings_has_booking', false, $this);
|
428 |
+
}
|
429 |
+
|
430 |
+
/**
|
431 |
+
* Get bookings that match the array of arguments passed.
|
432 |
+
* @return array
|
433 |
+
* @static
|
434 |
+
*/
|
435 |
+
function get( $args = array() ){
|
436 |
+
global $wpdb,$current_user;
|
437 |
+
$bookings_table = EM_BOOKINGS_TABLE;
|
438 |
+
$events_table = EM_EVENTS_TABLE;
|
439 |
+
$locations_table = EM_LOCATIONS_TABLE;
|
440 |
+
|
441 |
+
//Quick version, we can accept an array of IDs, which is easy to retrieve
|
442 |
+
if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
|
443 |
+
//We can just get all the events here and return them
|
444 |
+
$sql = "
|
445 |
+
SELECT * FROM $bookings_table b
|
446 |
+
LEFT JOIN $events_table e ON e.event_id=b.event_id
|
447 |
+
WHERE booking_id".implode(" OR booking_id=", $args);
|
448 |
+
$results = $wpdb->get_results(apply_filters('em_bookings_get_sql',$sql),ARRAY_A);
|
449 |
+
$bookings = array();
|
450 |
+
foreach($results as $result){
|
451 |
+
$bookings[] = new EM_Booking($result);
|
452 |
+
}
|
453 |
+
return $bookings; //We return all the bookings matched as an EM_Booking array.
|
454 |
+
}
|
455 |
+
|
456 |
+
//We assume it's either an empty array or array of search arguments to merge with defaults
|
457 |
+
$args = self::get_default_search($args);
|
458 |
+
$limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
|
459 |
+
$offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
|
460 |
+
|
461 |
+
//Get the default conditions
|
462 |
+
$conditions = self::build_sql_conditions($args);
|
463 |
+
//Put it all together
|
464 |
+
$where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
|
465 |
+
|
466 |
+
//Get ordering instructions
|
467 |
+
$EM_Booking = new EM_Booking();
|
468 |
+
$accepted_fields = $EM_Booking->get_fields(true);
|
469 |
+
$orderby = self::build_sql_orderby($args, $accepted_fields);
|
470 |
+
//Now, build orderby sql
|
471 |
+
$orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
|
472 |
+
|
473 |
+
//Create the SQL statement and execute
|
474 |
+
$sql = "
|
475 |
+
SELECT * FROM $bookings_table
|
476 |
+
LEFT JOIN $events_table ON {$events_table}.event_id={$bookings_table}.event_id
|
477 |
+
LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
|
478 |
+
$where
|
479 |
+
$orderby_sql
|
480 |
+
$limit $offset
|
481 |
+
";
|
482 |
+
$results = $wpdb->get_results( apply_filters('em_events_get_sql',$sql, $args), ARRAY_A);
|
483 |
+
|
484 |
+
//If we want results directly in an array, why not have a shortcut here?
|
485 |
+
if( $args['array'] == true ){
|
486 |
+
return $results;
|
487 |
+
}
|
488 |
+
|
489 |
+
//Make returned results EM_Booking objects
|
490 |
+
$results = (is_array($results)) ? $results:array();
|
491 |
+
$bookings = array();
|
492 |
+
foreach ( $results as $booking ){
|
493 |
+
$bookings[] = new EM_Booking($booking);
|
494 |
+
}
|
495 |
+
$EM_Bookings = new EM_Bookings($bookings);
|
496 |
+
return apply_filters('em_bookings_get', $EM_Bookings);
|
497 |
+
}
|
498 |
+
|
499 |
+
|
500 |
+
//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.
|
501 |
+
function export_csv() {
|
502 |
+
global $EM_Event;
|
503 |
+
if($EM_Event->id != $this->event->id ){
|
504 |
+
$event = new EM_Event($this->event->id);
|
505 |
+
$event_name = $event->name;
|
506 |
+
}else{
|
507 |
+
$event_name = $EM_Event->name;
|
508 |
+
}
|
509 |
+
// The name of the file on the user's pc
|
510 |
+
$file_name = sanitize_title($event_name). "-bookings.csv";
|
511 |
+
|
512 |
+
header("Content-Type: application/octet-stream");
|
513 |
+
header("Content-Disposition: Attachment; filename=$file_name");
|
514 |
+
|
515 |
+
//Headers
|
516 |
+
$labels = array(
|
517 |
+
'Booking ID',
|
518 |
+
'Name',
|
519 |
+
'Email',
|
520 |
+
'Phone',
|
521 |
+
'Date',
|
522 |
+
'Status',
|
523 |
+
'Ticket Name',
|
524 |
+
'Spaces',
|
525 |
+
'Price',
|
526 |
+
'Comment'
|
527 |
+
);
|
528 |
+
$file = sprintf(__('Booking details for "%s" as of %s','dbem'),$event_name, date_i18n('D d M Y h:i', current_time('timestamp'))) . "\n";
|
529 |
+
$file = '"'. implode('","', $labels). '"' . "\n";
|
530 |
+
|
531 |
+
//Rows
|
532 |
+
foreach( $this->bookings as $EM_Booking ) {
|
533 |
+
/* @var $EM_Booking EM_Booking */
|
534 |
+
foreach( $EM_Booking->get_tickets_bookings() as $EM_Ticket_Booking){
|
535 |
+
/* @var $EM_Ticket EM_Ticket */
|
536 |
+
/* @var $EM_Ticket_Booking EM_Ticket_Booking */
|
537 |
+
$EM_Ticket = $EM_Ticket_Booking->get_ticket();
|
538 |
+
$row = array(
|
539 |
+
$EM_Booking->id,
|
540 |
+
$EM_Booking->person->display_name,
|
541 |
+
$EM_Booking->person->user_email,
|
542 |
+
$EM_Booking->person->phone,
|
543 |
+
date('Y-m-d h:i', $EM_Booking->timestamp),
|
544 |
+
$EM_Booking->get_status(),
|
545 |
+
$EM_Ticket->name,
|
546 |
+
$EM_Ticket_Booking->get_spaces(),
|
547 |
+
$EM_Ticket_Booking->get_price(),
|
548 |
+
$EM_Booking->comment
|
549 |
+
);
|
550 |
+
//Display all values
|
551 |
+
foreach($row as $value){
|
552 |
+
$value = str_replace('"', '""', $value);
|
553 |
+
$value = str_replace("=", "", $value);
|
554 |
+
$file .= '"' . preg_replace("/\n\r|\r\n|\n|\r/", ". ", $value) . '",';
|
555 |
+
}
|
556 |
+
$file .= "\n";
|
557 |
+
}
|
558 |
+
}
|
559 |
+
|
560 |
+
// $file holds the data
|
561 |
+
echo $file;
|
562 |
+
$file = "";
|
563 |
+
}
|
564 |
+
|
565 |
+
/* Overrides EM_Object method to apply a filter to result
|
566 |
+
* @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
|
567 |
+
*/
|
568 |
+
function build_sql_conditions( $args = array() ){
|
569 |
+
$conditions = apply_filters( 'em_bookings_build_sql_conditions', parent::build_sql_conditions($args), $args );
|
570 |
+
if( is_numeric($args['status']) ){
|
571 |
+
$conditions['status'] = 'booking_status='.$args['status'];
|
572 |
+
}
|
573 |
+
return apply_filters('em_bookings_build_sql_conditions', $conditions, $args);
|
574 |
+
}
|
575 |
+
|
576 |
+
/* Overrides EM_Object method to apply a filter to result
|
577 |
+
* @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
|
578 |
+
*/
|
579 |
+
function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
|
580 |
+
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 );
|
581 |
+
}
|
582 |
+
|
583 |
+
/*
|
584 |
+
* Adds custom Events search defaults
|
585 |
+
* @param array $array
|
586 |
+
* @return array
|
587 |
+
* @uses EM_Object#get_default_search()
|
588 |
+
*/
|
589 |
+
function get_default_search( $array = array() ){
|
590 |
+
$defaults = array(
|
591 |
+
'status' => false,
|
592 |
+
'person' => true //to add later, search by person's bookings...
|
593 |
+
);
|
594 |
+
if( true || is_admin() ){
|
595 |
+
//figure out default owning permissions
|
596 |
+
if( !current_user_can('edit_others_events') ){
|
597 |
+
$defaults['owner'] = get_current_user_id();
|
598 |
+
}else{
|
599 |
+
$defaults['owner'] = false;
|
600 |
+
}
|
601 |
+
}
|
602 |
+
return apply_filters('em_bookings_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
|
603 |
+
}
|
604 |
+
|
605 |
+
//Iterator Implementation
|
606 |
+
public function rewind(){
|
607 |
+
reset($this->bookings);
|
608 |
+
}
|
609 |
+
public function current(){
|
610 |
+
$var = current($this->bookings);
|
611 |
+
return $var;
|
612 |
+
}
|
613 |
+
public function key(){
|
614 |
+
$var = key($this->bookings);
|
615 |
+
return $var;
|
616 |
+
}
|
617 |
+
public function next(){
|
618 |
+
$var = next($this->bookings);
|
619 |
+
return $var;
|
620 |
+
}
|
621 |
+
public function valid(){
|
622 |
+
$key = key($this->bookings);
|
623 |
+
$var = ($key !== NULL && $key !== FALSE);
|
624 |
+
return $var;
|
625 |
+
}
|
626 |
+
}
|
627 |
?>
|
classes/em-calendar.php
CHANGED
@@ -1,366 +1,316 @@
|
|
1 |
-
<?php
|
2 |
-
class EM_Calendar extends EM_Object {
|
3 |
-
|
4 |
-
function init(){
|
5 |
-
|
6 |
-
}
|
7 |
-
|
8 |
-
function
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
$
|
13 |
-
$
|
14 |
-
|
15 |
-
$
|
16 |
-
|
17 |
-
$
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
//
|
32 |
-
|
33 |
-
$
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
case "
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
$offset
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
$
|
52 |
-
$
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
$
|
59 |
-
|
60 |
-
|
61 |
-
$
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
$
|
66 |
-
}
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
//
|
89 |
-
//
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
//
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
$
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
//
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
}
|
133 |
-
$
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
$
|
139 |
-
|
140 |
-
$
|
141 |
-
|
142 |
-
|
143 |
-
$
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
$
|
158 |
-
foreach($
|
159 |
-
$
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
$
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
$
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
$
|
289 |
-
|
290 |
-
}
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
<?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('&', $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 |
-
?>
|
1 |
+
<?php
|
2 |
+
class EM_Calendar extends EM_Object {
|
3 |
+
|
4 |
+
function init(){
|
5 |
+
//nothing to init anymore
|
6 |
+
}
|
7 |
+
|
8 |
+
function get( $args ){
|
9 |
+
|
10 |
+
global $wpdb;
|
11 |
+
|
12 |
+
$calendar_array = array();
|
13 |
+
$calendar_array['cells'] = array();
|
14 |
+
|
15 |
+
$args = self::get_default_search($args);
|
16 |
+
$full = $args['full']; //For ZDE, don't delete pls
|
17 |
+
$month = $args['month'];
|
18 |
+
$year = $args['year'];
|
19 |
+
$long_events = $args['long_events'];
|
20 |
+
|
21 |
+
$week_starts_on_sunday = get_option('dbem_week_starts_sunday');
|
22 |
+
$start_of_week = get_option('start_of_week');
|
23 |
+
|
24 |
+
if( !(is_numeric($month) && $month <= 12 && $month > 0) ) {
|
25 |
+
$month = date('m');
|
26 |
+
}
|
27 |
+
if( !( is_numeric($year) ) ){
|
28 |
+
$year = date('Y');
|
29 |
+
}
|
30 |
+
|
31 |
+
// Get the first day of the month
|
32 |
+
$month_start = mktime(0,0,0,$month, 1, $year);
|
33 |
+
$calendar_array['month_start'] = $month_start;
|
34 |
+
|
35 |
+
// Get friendly month name
|
36 |
+
$month_name = date('M',$month_start);
|
37 |
+
// Figure out which day of the week
|
38 |
+
// the month starts on.
|
39 |
+
$month_start_day = date('D', $month_start);
|
40 |
+
|
41 |
+
switch($month_start_day){
|
42 |
+
case "Sun": $offset = 0; break;
|
43 |
+
case "Mon": $offset = 1; break;
|
44 |
+
case "Tue": $offset = 2; break;
|
45 |
+
case "Wed": $offset = 3; break;
|
46 |
+
case "Thu": $offset = 4; break;
|
47 |
+
case "Fri": $offset = 5; break;
|
48 |
+
case "Sat": $offset = 6; break;
|
49 |
+
}
|
50 |
+
//We need to go back to the WP defined day when the week started, in case the event day is near the end
|
51 |
+
$offset -= $start_of_week;
|
52 |
+
if($offset<0)
|
53 |
+
$offset += 7;
|
54 |
+
|
55 |
+
// determine how many days are in the last month.
|
56 |
+
$month_last = $month-1;
|
57 |
+
$month_next = $month+1;
|
58 |
+
$calendar_array['month_next'] = $month_next;
|
59 |
+
$year_last = $year;
|
60 |
+
$year_next = $year;
|
61 |
+
$calendar_array['year_next'] = $year_next;
|
62 |
+
|
63 |
+
if($month == 1) {
|
64 |
+
$month_last = 12;
|
65 |
+
$year_last = $year -1;
|
66 |
+
}elseif($month == 12){
|
67 |
+
$month_next = 1;
|
68 |
+
$year_next = $year + 1;
|
69 |
+
}
|
70 |
+
$calendar_array['month_last'] = $month_last;
|
71 |
+
$calendar_array['year_last'] = $year_last;
|
72 |
+
|
73 |
+
$num_days_last = self::days_in_month($month_last, $year_last);
|
74 |
+
|
75 |
+
// determine how many days are in the current month.
|
76 |
+
$num_days_current = self::days_in_month($month, $year);
|
77 |
+
// Build an array for the current days
|
78 |
+
// in the month
|
79 |
+
for($i = 1; $i <= $num_days_current; $i++){
|
80 |
+
$num_days_array[] = mktime(0,0,0,$month, $i, $year);
|
81 |
+
}
|
82 |
+
// Build an array for the number of days
|
83 |
+
// in last month
|
84 |
+
for($i = 1; $i <= $num_days_last; $i++){
|
85 |
+
$num_days_last_array[] = mktime(0,0,0,$month_last, $i, $year_last);
|
86 |
+
}
|
87 |
+
// If the $offset from the starting day of the
|
88 |
+
// week happens to be Sunday, $offset would be 0,
|
89 |
+
// so don't need an offset correction.
|
90 |
+
|
91 |
+
if($offset > 0){
|
92 |
+
$offset_correction = array_slice($num_days_last_array, -$offset, $offset);
|
93 |
+
$new_count = array_merge($offset_correction, $num_days_array);
|
94 |
+
$offset_count = count($offset_correction);
|
95 |
+
} else { // The else statement is to prevent building the $offset array.
|
96 |
+
$offset_count = 0;
|
97 |
+
$new_count = $num_days_array;
|
98 |
+
}
|
99 |
+
// count how many days we have with the two
|
100 |
+
// previous arrays merged together
|
101 |
+
$current_num = count($new_count);
|
102 |
+
|
103 |
+
// Since we will have 5 HTML table rows (TR)
|
104 |
+
// with 7 table data entries (TD)
|
105 |
+
// we need to fill in 35 TDs
|
106 |
+
// so, we will have to figure out
|
107 |
+
// how many days to appened to the end
|
108 |
+
// of the final array to make it 35 days.
|
109 |
+
if($current_num > 35){
|
110 |
+
$num_weeks = 6;
|
111 |
+
$outset = (42 - $current_num);
|
112 |
+
} elseif($current_num < 35){
|
113 |
+
$num_weeks = 5;
|
114 |
+
$outset = (35 - $current_num);
|
115 |
+
}
|
116 |
+
if($current_num == 35){
|
117 |
+
$num_weeks = 5;
|
118 |
+
$outset = 0;
|
119 |
+
}
|
120 |
+
// Outset Correction
|
121 |
+
for($i = 1; $i <= $outset; $i++){
|
122 |
+
$new_count[] = mktime(0,0,0,$month_next, $i, $year_next);
|
123 |
+
}
|
124 |
+
// Now let's "chunk" the $all_days array
|
125 |
+
// into weeks. Each week has 7 days
|
126 |
+
// so we will array_chunk it into 7 days.
|
127 |
+
$weeks = array_chunk($new_count, 7);
|
128 |
+
|
129 |
+
//Get an array of arguments that don't include default valued args
|
130 |
+
$link_args = self::get_link_args($args);
|
131 |
+
|
132 |
+
$previous_url = "?ajaxCalendar=1&month={$month_last}&year={$year_last}&{$link_args}";
|
133 |
+
$next_url = "?ajaxCalendar=1&month={$month_next}&year={$year_next}&{$link_args}";
|
134 |
+
|
135 |
+
$weekdays = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
|
136 |
+
$n = 0 ;
|
137 |
+
while( $n < $start_of_week ) {
|
138 |
+
$last_day = array_shift($weekdays);
|
139 |
+
$weekdays[]= $last_day;
|
140 |
+
$n++;
|
141 |
+
}
|
142 |
+
|
143 |
+
$days_initials_array = array();
|
144 |
+
foreach($weekdays as $weekday) {
|
145 |
+
$days_initials_array[] = self::translate_and_trim($weekday);
|
146 |
+
}
|
147 |
+
|
148 |
+
$calendar_array['links'] = array( 'previous_url'=>$previous_url, 'next_url'=>$next_url);
|
149 |
+
$calendar_array['row_headers'] = $days_initials_array;
|
150 |
+
|
151 |
+
// Now we break each key of the array
|
152 |
+
// into a week and create a new table row for each
|
153 |
+
// week with the days of that week in the table data
|
154 |
+
|
155 |
+
$i = 0;
|
156 |
+
$current_date = date('Y-m-d', current_time('timestamp'));
|
157 |
+
$week_count = 0;
|
158 |
+
foreach ( $weeks as $week ) {
|
159 |
+
foreach ( $week as $d ) {
|
160 |
+
$date = date('Y-m-d', $d);
|
161 |
+
$calendar_array['cells'][$date] = array('date'=>$d); //set it up so we have the exact array of dates to be filled
|
162 |
+
if ($i < $offset_count) { //if it is PREVIOUS month
|
163 |
+
$calendar_array['cells'][$date]['type'] = 'pre';
|
164 |
+
}
|
165 |
+
if (($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)) { // if it is THIS month
|
166 |
+
if ( $current_date == $date ){
|
167 |
+
$calendar_array['cells'][$date]['type'] = 'today';
|
168 |
+
}
|
169 |
+
} elseif (($outset > 0)) { //if it is NEXT month
|
170 |
+
if (($i >= ($num_weeks * 7) - $outset)) {
|
171 |
+
$calendar_array['cells'][$date]['type'] = 'post';
|
172 |
+
}
|
173 |
+
}
|
174 |
+
$i ++;
|
175 |
+
}
|
176 |
+
$week_count++;
|
177 |
+
}
|
178 |
+
|
179 |
+
// query the database for events in this time span
|
180 |
+
if ($month == 1) {
|
181 |
+
$month_pre=12;
|
182 |
+
$month_post=2;
|
183 |
+
$year_pre=$year-1;
|
184 |
+
$year_post=$year;
|
185 |
+
} elseif($month == 12) {
|
186 |
+
$month_pre=11;
|
187 |
+
$month_post=1;
|
188 |
+
$year_pre=$year;
|
189 |
+
$year_post=$year+1;
|
190 |
+
} else {
|
191 |
+
$month_pre=$month-1;
|
192 |
+
$month_post=$month+1;
|
193 |
+
$year_pre=$year;
|
194 |
+
$year_post=$year;
|
195 |
+
}
|
196 |
+
$args['year'] = array($year_pre, $year_post);
|
197 |
+
$args['month'] = array($month_pre, $month_post);
|
198 |
+
$events = EM_Events::get($args);
|
199 |
+
|
200 |
+
$event_format = get_option('dbem_full_calendar_event_format');
|
201 |
+
$event_title_format = get_option('dbem_small_calendar_event_title_format');
|
202 |
+
$event_title_separator_format = get_option('dbem_small_calendar_event_title_separator');
|
203 |
+
|
204 |
+
$eventful_days= array();
|
205 |
+
if($events){
|
206 |
+
//Go through the events and slot them into the right d-m index
|
207 |
+
foreach($events as $event) {
|
208 |
+
$event = apply_filters('em_calendar_output_loop_start', $event);
|
209 |
+
if( $long_events ){
|
210 |
+
//If $long_events is set then show a date as eventful if there is an multi-day event which runs during that day
|
211 |
+
$event_start_date = mktime(0,0,0,$month_pre,1,$year_pre);
|
212 |
+
$event_end_date = mktime(0,0,0,$month_post,date('t', $event_start_date),$year_post );
|
213 |
+
if( $event_end_date == '' ) $event_end_date = $event_start_date;
|
214 |
+
while( $event_start_date <= $event->end ){
|
215 |
+
//Ensure date is within event dates, if so add to eventful days array
|
216 |
+
if( $event_start_date > $event->start - (86400) ){ //subtract a day since start may be later in day
|
217 |
+
$event_eventful_date = date('Y-m-d', $event_start_date);
|
218 |
+
if( array_key_exists($event_eventful_date, $eventful_days) && is_array($eventful_days[$event_eventful_date]) ){
|
219 |
+
$eventful_days[$event_eventful_date][] = $event;
|
220 |
+
} else {
|
221 |
+
$eventful_days[$event_eventful_date] = array($event);
|
222 |
+
}
|
223 |
+
}
|
224 |
+
$event_start_date += (86400); //add a day
|
225 |
+
}
|
226 |
+
}else{
|
227 |
+
//Only show events on the day that they start
|
228 |
+
if( isset($eventful_days[$event->start_date]) && is_array($eventful_days[$event->start_date]) ){
|
229 |
+
$eventful_days[$event->start_date][] = $event;
|
230 |
+
} else {
|
231 |
+
$eventful_days[$event->start_date] = array($event);
|
232 |
+
}
|
233 |
+
}
|
234 |
+
$event = apply_filters('em_calendar_output_loop_end', $event);
|
235 |
+
}
|
236 |
+
}
|
237 |
+
foreach($eventful_days as $day_key => $events) {
|
238 |
+
if( array_key_exists($day_key, $calendar_array['cells']) ){
|
239 |
+
//Get link title for this date
|
240 |
+
$events_titles = array();
|
241 |
+
foreach($events as $event) {
|
242 |
+
$events_titles[] = $event->output($event_title_format);
|
243 |
+
}
|
244 |
+
$calendar_array['cells'][$day_key]['link_title'] = implode( $event_title_separator_format, $events_titles);
|
245 |
+
|
246 |
+
//Get the link to this calendar day
|
247 |
+
global $wp_rewrite;
|
248 |
+
$event_page_link = trailingslashit(get_permalink(get_option('dbem_events_page'))); //don't use EM_URI here, since ajax calls this before EM_URI is defined.
|
249 |
+
if( $wp_rewrite->using_permalinks() && !defined('EM_DISABLE_PERMALINKS') ){
|
250 |
+
$calendar_array['cells'][$day_key]['link'] = $event_page_link.$day_key."/";
|
251 |
+
}else{
|
252 |
+
$joiner = (stristr($event_page_link, "?")) ? "&" : "?";
|
253 |
+
$calendar_array['cells'][$day_key]['link'] = $event_page_link.$joiner."calendar_day=".$day_key;
|
254 |
+
}
|
255 |
+
//Add events to array
|
256 |
+
$calendar_array['cells'][$day_key]['events'] = $events;
|
257 |
+
}
|
258 |
+
}
|
259 |
+
return apply_filters('em_calendar_get',$calendar_array, $args);
|
260 |
+
}
|
261 |
+
|
262 |
+
function output($args = array()) {
|
263 |
+
$calendar_array = self::get($args);
|
264 |
+
$template = ($args['full']) ? 'templates/calendar-full.php':'templates/calendar-small.php';
|
265 |
+
ob_start();
|
266 |
+
em_locate_template($template, true, array('calendar'=>$calendar_array,'args'=>$args));
|
267 |
+
$calendar = '<div id="em-calendar-'.rand(100,200).'" class="em-calendar-wrapper">'.ob_get_clean().'</div>';
|
268 |
+
return apply_filters('em_calendar_output', $calendar, $args);
|
269 |
+
}
|
270 |
+
|
271 |
+
|
272 |
+
function days_in_month($month, $year) {
|
273 |
+
return date('t', mktime(0,0,0,$month,1,$year));
|
274 |
+
}
|
275 |
+
|
276 |
+
function translate_and_trim($string, $length = 1) {
|
277 |
+
return substr(__($string), 0, $length);
|
278 |
+
}
|
279 |
+
|
280 |
+
/**
|
281 |
+
* Helper function to create a link querystring from array which contains arguments with only values that aren't defuaults.
|
282 |
+
*/
|
283 |
+
function get_link_args($args = array(), $html_entities=true){
|
284 |
+
unset($args['month']); unset($args['year']);
|
285 |
+
$default_args = self::get_default_search(array());
|
286 |
+
foreach($default_args as $arg_key => $arg_value){
|
287 |
+
if( !isset($args[$arg_key]) || $args[$arg_key] == $arg_value ){
|
288 |
+
unset($args[$arg_key]);
|
289 |
+
}
|
290 |
+
}
|
291 |
+
$qs_array = array();
|
292 |
+
foreach($args as $key => $value){
|
293 |
+
if(is_array($value)){
|
294 |
+
$value = implode(',',$value);
|
295 |
+
}
|
296 |
+
$qs_array[] = "$key=".urlencode($value);
|
297 |
+
}
|
298 |
+
return ($html_entities) ? implode('&', $qs_array) : implode('&', $qs_array);
|
299 |
+
}
|
300 |
+
|
301 |
+
|
302 |
+
function get_default_search($array=array()){
|
303 |
+
//These defaults aren't for db queries, but flags for what to display in calendar output
|
304 |
+
$defaults = array(
|
305 |
+
'full' => 0, //Will display a full calendar with event names
|
306 |
+
'long_events' => 0, //Events that last longer than a day
|
307 |
+
'scope' => 'future',
|
308 |
+
'owner' => false
|
309 |
+
);
|
310 |
+
$atts = parent::get_default_search($defaults, $array);
|
311 |
+
$atts['full'] = ($atts['full']==true) ? 1:0;
|
312 |
+
$atts['long_events'] = ($atts['long_events']==true) ? 1:0;
|
313 |
+
return apply_filters('em_calendar_get_default_search', $atts, $array, $defaults);
|
314 |
+
}
|
315 |
+
}
|
316 |
+
add_action('init', array('EM_Calendar', 'init'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/em-categories.php
CHANGED
@@ -1,157 +1,315 @@
|
|
1 |
-
<?php
|
2 |
-
class EM_Categories extends EM_Object {
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
//
|
70 |
-
$
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
$
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
if(
|
109 |
-
$
|
110 |
-
|
111 |
-
|
112 |
-
}
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
$
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
}
|
1 |
+
<?php
|
2 |
+
class EM_Categories extends EM_Object implements Iterator{
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Array of EM_Category objects for a specific event
|
6 |
+
* @var array
|
7 |
+
*/
|
8 |
+
var $categories = array();
|
9 |
+
/**
|
10 |
+
* @var EM_Event
|
11 |
+
*/
|
12 |
+
var $event;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Creates an EM_Categories instance, currently accepts an EM_Event object (gets all Categories for that event) or array of any EM_Category objects, which can be manipulated in bulk with helper functions.
|
16 |
+
* @param EM_Event $event
|
17 |
+
* @return null
|
18 |
+
*/
|
19 |
+
function EM_Categories( $data = false ){
|
20 |
+
if( is_object($data) && get_class($data) == "EM_Event" ){ //Creates a blank categories object if needed
|
21 |
+
global $wpdb;
|
22 |
+
$this->event = $data;
|
23 |
+
$sql = "SELECT meta_value FROM ". EM_META_TABLE ." WHERE meta_key='event-category' AND object_id ='{$this->event->id}'";
|
24 |
+
$categories = $wpdb->get_results($sql, ARRAY_A);
|
25 |
+
foreach ($categories as $category_data){
|
26 |
+
$this->categories[] = new EM_Category($category_data['meta_value']);
|
27 |
+
}
|
28 |
+
}elseif( is_array($data) && $this->array_is_numeric($data) ){
|
29 |
+
foreach($data as $category_id){
|
30 |
+
$this->categories[] = new EM_Category($category_id);
|
31 |
+
}
|
32 |
+
}elseif( is_array($data) ){
|
33 |
+
foreach( $data as $EM_Category ){
|
34 |
+
if( get_class($EM_Category) == 'EM_Category'){
|
35 |
+
$this->categories[] = $EM_Category;
|
36 |
+
}
|
37 |
+
}
|
38 |
+
$this->get_event();
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
function get( $args = array() ) {
|
43 |
+
global $wpdb;
|
44 |
+
$categories_table = EM_CATEGORIES_TABLE;
|
45 |
+
$events_table = EM_EVENTS_TABLE;
|
46 |
+
|
47 |
+
//Quick version, we can accept an array of IDs, which is easy to retrieve
|
48 |
+
if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
|
49 |
+
//We can just get all the events here and return them
|
50 |
+
$sql = "SELECT * FROM $categories_table WHERE category_id=".implode(" OR category_id=", $args);
|
51 |
+
$results = $wpdb->get_results(apply_filters('em_categories_get_sql',$sql),ARRAY_A);
|
52 |
+
$categories = array();
|
53 |
+
foreach($results as $result){
|
54 |
+
$categories[$result['category_id']] = new EM_Category($result);
|
55 |
+
}
|
56 |
+
return $categories; //We return all the categories matched as an EM_Event array.
|
57 |
+
}
|
58 |
+
|
59 |
+
//We assume it's either an empty array or array of search arguments to merge with defaults
|
60 |
+
$args = self::get_default_search($args);
|
61 |
+
$limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
|
62 |
+
$offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
|
63 |
+
|
64 |
+
//Get the default conditions
|
65 |
+
$conditions = self::build_sql_conditions($args);
|
66 |
+
//Put it all together
|
67 |
+
$where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
|
68 |
+
|
69 |
+
//Get ordering instructions
|
70 |
+
$EM_Category = new EM_Category();
|
71 |
+
$accepted_fields = $EM_Category->get_fields(true);
|
72 |
+
$orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_categories_default_order'));
|
73 |
+
//Now, build orderby sql
|
74 |
+
$orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
|
75 |
+
|
76 |
+
//Create the SQL statement and execute
|
77 |
+
$sql = "
|
78 |
+
SELECT * FROM $categories_table
|
79 |
+
$where
|
80 |
+
GROUP BY category_id
|
81 |
+
$orderby_sql
|
82 |
+
$limit $offset
|
83 |
+
";
|
84 |
+
$results = $wpdb->get_results( apply_filters('em_categories_get_sql',$sql, $args), ARRAY_A);
|
85 |
+
//If we want results directly in an array, why not have a shortcut here?
|
86 |
+
if( $args['array'] == true ){
|
87 |
+
return $results;
|
88 |
+
}
|
89 |
+
|
90 |
+
//Make returned results EM_Event objects
|
91 |
+
$results = (is_array($results)) ? $results:array();
|
92 |
+
$categories = array();
|
93 |
+
foreach ( $results as $category_array ){
|
94 |
+
$categories[$category_array['category_id']] = new EM_Category($category_array);
|
95 |
+
}
|
96 |
+
|
97 |
+
return apply_filters('em_categories_get', $categories, $args);
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Will delete given an array of category_ids or EM_Event objects
|
102 |
+
* @param unknown_type $id_array
|
103 |
+
*/
|
104 |
+
function delete( $array ){
|
105 |
+
global $wpdb;
|
106 |
+
//Detect array type and generate SQL for event IDs
|
107 |
+
$category_ids = array();
|
108 |
+
if( @get_class(current($array)) == 'EM_Category' ){
|
109 |
+
foreach($array as $EM_Category){
|
110 |
+
$category_ids[] = $EM_Category->id;
|
111 |
+
}
|
112 |
+
}else{
|
113 |
+
$category_ids = $array;
|
114 |
+
}
|
115 |
+
if(self::array_is_numeric($category_ids)){
|
116 |
+
apply_filters('em_categories_delete', $category_ids);
|
117 |
+
$condition = implode(" OR category_id=", $category_ids);
|
118 |
+
//Delete all the categories
|
119 |
+
$result_categories = $wpdb->query("DELETE FROM ". EM_CATEGORIES_TABLE ." WHERE category_id=$condition;");
|
120 |
+
//Now delete the categories
|
121 |
+
$result = $wpdb->query ( "DELETE FROM ". EM_CATEGORIES_TABLE ." WHERE category_id=$condition;" );
|
122 |
+
do_action('em_categories_delete', $category_ids);
|
123 |
+
}
|
124 |
+
//TODO add error detection on categories delete fails
|
125 |
+
return apply_filters('em_categories_delete', true, $category_ids);
|
126 |
+
}
|
127 |
+
|
128 |
+
function output( $args ){
|
129 |
+
global $EM_Category;
|
130 |
+
$EM_Category_old = $EM_Category; //When looping, we can replace EM_Category global with the current event in the loop
|
131 |
+
//Can be either an array for the get search or an array of EM_Category objects
|
132 |
+
if( is_object(current($args)) && get_class((current($args))) == 'EM_Category' ){
|
133 |
+
$func_args = func_get_args();
|
134 |
+
$categories = $func_args[0];
|
135 |
+
$args = (!empty($func_args[1])) ? $func_args[1] : array();
|
136 |
+
$args = apply_filters('em_categories_output_args', self::get_default_search($args), $categories);
|
137 |
+
$limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
|
138 |
+
$offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
|
139 |
+
$page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
|
140 |
+
}else{
|
141 |
+
$args = apply_filters('em_categories_output_args', self::get_default_search($args) );
|
142 |
+
$limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
|
143 |
+
$offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
|
144 |
+
$page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
|
145 |
+
$args['limit'] = false;
|
146 |
+
$args['offset'] = false;
|
147 |
+
$args['page'] = false;
|
148 |
+
$categories = self::get( $args );
|
149 |
+
}
|
150 |
+
//What format shall we output this to, or use default
|
151 |
+
$format = ( $args['format'] == '' ) ? get_option( 'dbem_categories_list_item_format' ) : $args['format'] ;
|
152 |
+
|
153 |
+
$output = "";
|
154 |
+
$categories_count = count($categories);
|
155 |
+
$categories = apply_filters('em_categories_output_categories', $categories);
|
156 |
+
if ( count($categories) > 0 ) {
|
157 |
+
$category_count = 0;
|
158 |
+
$categories_shown = 0;
|
159 |
+
foreach ( $categories as $EM_Category ) {
|
160 |
+
if( ($categories_shown < $limit || empty($limit)) && ($category_count >= $offset || $offset === 0) ){
|
161 |
+
$output .= $EM_Category->output($format);
|
162 |
+
$categories_shown++;
|
163 |
+
}
|
164 |
+
$category_count++;
|
165 |
+
}
|
166 |
+
//Add headers and footers to output
|
167 |
+
if( $format == get_option ( 'dbem_categories_list_item_format' ) ){
|
168 |
+
$single_event_format_header = get_option ( 'dbem_categories_list_item_format_header' );
|
169 |
+
$single_event_format_header = ( $single_event_format_header != '' ) ? $single_event_format_header : "<ul class='em-categories-list'>";
|
170 |
+
$single_event_format_footer = get_option ( 'dbem_categories_list_item_format_footer' );
|
171 |
+
$single_event_format_footer = ( $single_event_format_footer != '' ) ? $single_event_format_footer : "</ul>";
|
172 |
+
$output = $single_event_format_header . $output . $single_event_format_footer;
|
173 |
+
}
|
174 |
+
//Pagination (if needed/requested)
|
175 |
+
if( !empty($args['pagination']) && !empty($limit) && $categories_count >= $limit ){
|
176 |
+
//Show the pagination links (unless there's less than 10 events, or the custom limit)
|
177 |
+
$page_link_template = preg_replace('/(&|\?)page=\d+/i','',$_SERVER['REQUEST_URI']);
|
178 |
+
$page_link_template = em_add_get_params($page_link_template, array('page'=>'%PAGE%'));
|
179 |
+
$output .= apply_filters('em_events_output_pagination', em_paginate( $page_link_template, $categories_count, $limit, $page), $page_link_template, $categories_count, $limit, $page);
|
180 |
+
}
|
181 |
+
} else {
|
182 |
+
$output = get_option ( 'dbem_no_categories_message' );
|
183 |
+
}
|
184 |
+
//FIXME check if reference is ok when restoring object, due to changes in php5 v 4
|
185 |
+
$EM_Category_old= $EM_Category;
|
186 |
+
return apply_filters('em_categories_output', $output, $categories, $args);
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* If these categories collection are connected with an existing EM_Event object, then we can add categories to this event.
|
191 |
+
*/
|
192 |
+
function save(){
|
193 |
+
if( !empty($this->get_event()->id) ){
|
194 |
+
global $wpdb;
|
195 |
+
$event_id = $this->event->id;
|
196 |
+
//remove old cats
|
197 |
+
$wpdb->query('DELETE FROM '.EM_META_TABLE." WHERE object_id='$event_id' AND meta_key='event-category'");
|
198 |
+
//Now add new ones
|
199 |
+
$inserts = array();
|
200 |
+
foreach($this->get_ids() as $id){
|
201 |
+
$inserts[] = "($event_id,'event-category',$id)";
|
202 |
+
}
|
203 |
+
if( count($inserts) > 0 ){
|
204 |
+
$result = $wpdb->query("INSERT INTO ".EM_META_TABLE." (`object_id`,`meta_key`,`meta_value`) VALUES ".implode(',',$inserts));
|
205 |
+
if( $result === false ){
|
206 |
+
$this->add_error( sprintf(__('Could not save the %s details due to a database error.', 'dbem'),__('category','dbem') ));
|
207 |
+
}
|
208 |
+
}
|
209 |
+
}
|
210 |
+
return apply_filters('em_categories_save', count($this->errors) == 0, $this);
|
211 |
+
}
|
212 |
+
|
213 |
+
function has( $search ){
|
214 |
+
if( is_numeric($search) ){
|
215 |
+
foreach($this->categories as $EM_Category){
|
216 |
+
if($EM_Category->id == $search) return apply_filters('em_categories_has', true, $search, $this);
|
217 |
+
}
|
218 |
+
}
|
219 |
+
return apply_filters('em_categories_has', false, $search, $this);
|
220 |
+
}
|
221 |
+
|
222 |
+
function get_ids(){
|
223 |
+
$ids = array();
|
224 |
+
foreach($this->categories as $EM_Category){
|
225 |
+
if( !empty($EM_Category->id) ){
|
226 |
+
$ids[] = $EM_Category->id;
|
227 |
+
}
|
228 |
+
}
|
229 |
+
return $ids;
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Gets the event for this object, or a blank event if none exists
|
234 |
+
* @return EM_Event
|
235 |
+
*/
|
236 |
+
function get_event(){
|
237 |
+
if( !( is_object($this->event) && get_class($this->event) == 'EM_Event' ) ){
|
238 |
+
$this->event = new EM_Event();
|
239 |
+
}
|
240 |
+
return apply_filters('em_categories_get_event', $this->event, $this);
|
241 |
+
}
|
242 |
+
|
243 |
+
/* Overrides EM_Object method to apply a filter to result. Categories won't accept many arguments as you tend to search with events for much else.
|
244 |
+
* @see wp-content/plugins/categories-manager/classes/EM_Object#build_sql_conditions()
|
245 |
+
*/
|
246 |
+
function build_sql_conditions( $args = array() ){
|
247 |
+
global $wpdb;
|
248 |
+
$events_table = EM_EVENTS_TABLE;
|
249 |
+
$locations_table = EM_LOCATIONS_TABLE;
|
250 |
+
|
251 |
+
$temp_conditions = parent::build_sql_conditions($args);
|
252 |
+
$conditions = array();
|
253 |
+
if( !empty($temp_conditions['category']) ){
|
254 |
+
$conditions['category'] = $temp_conditions['category'];
|
255 |
+
}
|
256 |
+
return apply_filters( 'em_categories_build_sql_conditions', $conditions, $args );
|
257 |
+
}
|
258 |
+
|
259 |
+
/* Overrides EM_Object method to apply a filter to result
|
260 |
+
* @see wp-content/plugins/categories-manager/classes/EM_Object#build_sql_orderby()
|
261 |
+
*/
|
262 |
+
function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
|
263 |
+
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 );
|
264 |
+
}
|
265 |
+
|
266 |
+
/*
|
267 |
+
* Adds custom categories search defaults
|
268 |
+
* @param array $array
|
269 |
+
* @return array
|
270 |
+
* @uses EM_Object#get_default_search()
|
271 |
+
*/
|
272 |
+
function get_default_search( $array = array() ){
|
273 |
+
return apply_filters('em_categories_get_default_search', parent::get_default_search(array(),$array), $array, array());
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* will return the default search parameter to use according to permission settings
|
278 |
+
* @return string
|
279 |
+
*/
|
280 |
+
function get_default_search_owner(){
|
281 |
+
//by default, we only get categories the owner can manage
|
282 |
+
$defaults = array('owner'=>false);
|
283 |
+
//by default, we only get categories the owner can manage
|
284 |
+
if( !current_user_can('edit_categories') ){
|
285 |
+
$defaults['owner'] = get_current_user_id();
|
286 |
+
break;
|
287 |
+
}else{
|
288 |
+
$defaults['owner'] = false;
|
289 |
+
break;
|
290 |
+
}
|
291 |
+
return $defaults['owner'];
|
292 |
+
}
|
293 |
+
|
294 |
+
//Iterator Implementation
|
295 |
+
public function rewind(){
|
296 |
+
reset($this->categories);
|
297 |
+
}
|
298 |
+
public function current(){
|
299 |
+
$var = current($this->categories);
|
300 |
+
return $var;
|
301 |
+
}
|
302 |
+
public function key(){
|
303 |
+
$var = key($this->categories);
|
304 |
+
return $var;
|
305 |
+
}
|
306 |
+
public function next(){
|
307 |
+
$var = next($this->categories);
|
308 |
+
return $var;
|
309 |
+
}
|
310 |
+
public function valid(){
|
311 |
+
$key = key($this->categories);
|
312 |
+
$var = ($key !== NULL && $key !== FALSE);
|
313 |
+
return $var;
|
314 |
+
}
|
315 |
}
|
classes/em-category.php
CHANGED
@@ -1,152 +1,232 @@
|
|
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 $
|
7 |
-
var $
|
8 |
-
|
9 |
-
var $
|
10 |
-
|
11 |
-
|
12 |
-
'
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
$
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
$
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
$
|
74 |
-
return apply_filters('
|
75 |
-
}
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
$
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
function
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
$
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
}
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
?>
|
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 |
+
var $description = '';
|
10 |
+
//Other Vars
|
11 |
+
var $fields = array(
|
12 |
+
'category_id' => array('name'=>'id','type'=>'%d'),
|
13 |
+
'category_slug' => array('name'=>'slug','type'=>'%s'),
|
14 |
+
'category_owner' => array('name'=>'owner','type'=>'%d'),
|
15 |
+
'category_name' => array('name'=>'name','type'=>'%s'),
|
16 |
+
'category_description' => array('name'=>'description','type'=>'%s')
|
17 |
+
);
|
18 |
+
var $required_fields;
|
19 |
+
var $feedback_message = "";
|
20 |
+
var $errors = array();
|
21 |
+
var $image_url = '';
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Gets data from POST (default), supplied array, or from the database if an ID is supplied
|
25 |
+
* @param $category_data
|
26 |
+
* @return null
|
27 |
+
*/
|
28 |
+
function EM_Category( $category_data = false ) {
|
29 |
+
global $wpdb;
|
30 |
+
//Initialize
|
31 |
+
$this->required_fields = array("name" => __('The category name', 'dbem'));
|
32 |
+
$category = array();
|
33 |
+
if( !empty($category_data) ){
|
34 |
+
//Load category data
|
35 |
+
if( is_array($category_data) && isset($category_data['category_name']) ){
|
36 |
+
$category = $category_data;
|
37 |
+
}elseif( is_numeric($category_data) ){
|
38 |
+
//Retreiving from the database
|
39 |
+
$sql = "SELECT * FROM ". EM_CATEGORIES_TABLE ." WHERE category_id ='{$category_data}'";
|
40 |
+
$category = $wpdb->get_row($sql, ARRAY_A);
|
41 |
+
}else{
|
42 |
+
$sql = "SELECT * FROM ". EM_CATEGORIES_TABLE ." WHERE category_slug ='{$category_data}'";
|
43 |
+
$category = $wpdb->get_row($sql, ARRAY_A);
|
44 |
+
}
|
45 |
+
//Save into the object
|
46 |
+
$this->to_object($category);
|
47 |
+
}
|
48 |
+
$this->get_image_url();
|
49 |
+
add_action('em_category_save',array(&$this, 'image_upload'), 1, 2);
|
50 |
+
do_action('em_category',$this, $category_data);
|
51 |
+
}
|
52 |
+
|
53 |
+
function get_post(){
|
54 |
+
//We are getting the values via POST or GET
|
55 |
+
do_action('em_category_get_post_pre', $this);
|
56 |
+
$category = array();
|
57 |
+
$category['category_id'] = ( !empty($_POST['category_id']) ) ? $_POST['category_id']:'';
|
58 |
+
$category['category_name'] = ( !empty($_POST['category_name']) ) ? stripslashes($_POST['category_name']):'';
|
59 |
+
$category['category_slug'] = ( !empty($_POST['category_slug']) ) ? sanitize_title($_POST['category_slug']) : '' ;
|
60 |
+
$category['category_description'] = ( !empty($_POST['content']) ) ? stripslashes($_POST['content']) : ''; //WP TinyMCE field
|
61 |
+
$category['category_owner'] = ( !empty($_POST['category_owner']) && is_numeric($_POST['category_owner']) ) ? $_POST['category_owner']:get_current_user_id();
|
62 |
+
$this->to_object( apply_filters('em_category_get_post', $category, $this) );
|
63 |
+
return apply_filters('em_category_get_post',$this->validate(), $this);
|
64 |
+
}
|
65 |
+
|
66 |
+
function validate(){
|
67 |
+
//check required fields
|
68 |
+
foreach ( $this->required_fields as $field => $description) {
|
69 |
+
if ( $this->$field == "" ) {
|
70 |
+
$this->add_error($description.__(" is required.", "dbem"));
|
71 |
+
}
|
72 |
+
}
|
73 |
+
$this->image_validate();
|
74 |
+
return apply_filters('em_location_validate', ( count($this->errors) == 0 ), $this);
|
75 |
+
}
|
76 |
+
|
77 |
+
function save(){
|
78 |
+
global $wpdb;
|
79 |
+
$result = false;
|
80 |
+
if( $this->can_manage('edit_categories') ){
|
81 |
+
do_action('em_category_save_pre', $this);
|
82 |
+
$table = EM_CATEGORIES_TABLE;
|
83 |
+
$this->slug = $this->sanitize_title();
|
84 |
+
$data = $this->to_array();
|
85 |
+
unset($data['category_id']);
|
86 |
+
if($this->id != ''){
|
87 |
+
$where = array( 'category_id' => $this->id );
|
88 |
+
$result = $wpdb->update($table, $data, $where, $this->get_types($data));
|
89 |
+
if( $result !== false ){
|
90 |
+
$this->feedback_message = sprintf(__('%s successfully updated.', 'dbem'), __('Category','dbem'));
|
91 |
+
}
|
92 |
+
}else{
|
93 |
+
$wpdb->insert($table, $data, $this->get_types($data));
|
94 |
+
$result = $this->id = $wpdb->insert_id;
|
95 |
+
if( $result !== false ){
|
96 |
+
$this->feedback_message = sprintf(__('%s successfully added.', 'dbem'), __('Category','dbem'));
|
97 |
+
}
|
98 |
+
}
|
99 |
+
}else{
|
100 |
+
$this->add_error( sprintf(__('You do not have permission to create/edit %s.','dbem'), __('categories','dbem')) );
|
101 |
+
}
|
102 |
+
return apply_filters('em_category_save', ($result !== false), $this);
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Takes the title and gives either a unique slug or returns the currently used slug if this record already has it.
|
107 |
+
* @param unknown_type $title
|
108 |
+
*/
|
109 |
+
function sanitize_title($iteration = 1){
|
110 |
+
global $wpdb;
|
111 |
+
//Generate the slug. If this is a new event, create the slug automatically, if not, verify it is still unique and if not rewrite
|
112 |
+
if( empty($this->slug) ){
|
113 |
+
$this->slug = sanitize_title($this->name);
|
114 |
+
}
|
115 |
+
$slug = $this->slug;
|
116 |
+
$slug_matches = $wpdb->get_results('SELECT category_id FROM '.EM_CATEGORIES_TABLE." WHERE category_slug='{$slug}'", ARRAY_A);
|
117 |
+
if( count($slug_matches) > 0 ){ //we will check that the slug is unique
|
118 |
+
if( $slug_matches[0]['category_id'] != $this->id || count($slug_matches) > 1 ){
|
119 |
+
//we have a conflict, so try another alternative
|
120 |
+
$this->slug = preg_replace('/\-[0-9]+$/', '', $slug).'-'.($iteration+1);
|
121 |
+
$this->sanitize_title($iteration+1);
|
122 |
+
}
|
123 |
+
}
|
124 |
+
return apply_filters('em_category_title', $this->slug, $this);
|
125 |
+
}
|
126 |
+
|
127 |
+
function delete(){
|
128 |
+
global $wpdb;
|
129 |
+
$result = false;
|
130 |
+
if( $this->can_manage('edit_categories') ){
|
131 |
+
do_action('em_category_delete_pre', $this);
|
132 |
+
$table_name = EM_CATEGORIES_TABLE;
|
133 |
+
$sql = "DELETE FROM $table_name WHERE category_id = '{$this->id}';";
|
134 |
+
$result = $wpdb->query($sql);
|
135 |
+
}
|
136 |
+
return apply_filters('em_category_delete', $result, $this);
|
137 |
+
}
|
138 |
+
|
139 |
+
function has_events(){
|
140 |
+
global $wpdb;
|
141 |
+
$events_table = EM_EVENTS_TABLE;
|
142 |
+
$sql = "SELECT count(event_id) as events_no FROM $events_table WHERE category_id = {$this->id}";
|
143 |
+
$affected_events = $wpdb->get_row($sql);
|
144 |
+
return apply_filters('em_category_has_events', (count($affected_events) > 0), $this);
|
145 |
+
}
|
146 |
+
|
147 |
+
function output_single($target = 'html'){
|
148 |
+
$format = get_option ( 'dbem_category_page_format' );
|
149 |
+
return apply_filters('em_category_output_single', $this->output($format, $target), $this, $target);
|
150 |
+
}
|
151 |
+
|
152 |
+
function output($format, $target="html") {
|
153 |
+
preg_match_all('/\{([a-zA-Z0-9_]+)\}([^{]+)\{\/[a-zA-Z0-9_]+\}/', $format, $conditionals);
|
154 |
+
if( count($conditionals[0]) > 0 ){
|
155 |
+
//Check if the language we want exists, if not we take the first language there
|
156 |
+
foreach($conditionals[1] as $key => $condition){
|
157 |
+
$format = str_replace($conditionals[0][$key], apply_filters('em_category_output_condition', '', $condition, $conditionals[0][$key], $this), $format);
|
158 |
+
}
|
159 |
+
}
|
160 |
+
$category_string = $format;
|
161 |
+
preg_match_all("/#_[A-Za-z]+/", $format, $placeholders);
|
162 |
+
foreach($placeholders[0] as $result) {
|
163 |
+
$match = true;
|
164 |
+
$replace = '';
|
165 |
+
switch( $result ){
|
166 |
+
case '#_CATEGORYNAME':
|
167 |
+
$replace = $this->name;
|
168 |
+
break;
|
169 |
+
case '#_CATEGORYID':
|
170 |
+
$replace = $this->id;
|
171 |
+
break;
|
172 |
+
case '#_CATEGORYNOTES':
|
173 |
+
case '#_CATEGORYDESCRIPTION':
|
174 |
+
$replace = $this->description;
|
175 |
+
break;
|
176 |
+
case '#_CATEGORYIMAGE':
|
177 |
+
case '#_CATEGORYIMAGEURL':
|
178 |
+
if( $this->image_url != ''){
|
179 |
+
$replace = ($result == '#_CATEGORYIMAGEURL') ? $this->image_url : "<img src='".$this->image_url."' alt='".$this->name."'/>";
|
180 |
+
}
|
181 |
+
break;
|
182 |
+
case '#_CATEGORYLINK':
|
183 |
+
case '#_CATEGORYURL':
|
184 |
+
$joiner = (stristr(EM_URI, "?")) ? "&" : "?";
|
185 |
+
$link = EM_URI.$joiner."category_id=".$this->id;
|
186 |
+
$replace = ($result == '#_CATEGORYURL') ? $link : '<a href="'.$link.'">'.$this->name.'</a>';
|
187 |
+
break;
|
188 |
+
case '#_CATEGORYEVENTSPAST':
|
189 |
+
case '#_CATEGORYEVENTSNEXT':
|
190 |
+
case '#_CATEGORYEVENTSALL':
|
191 |
+
if ($result == '#_CATEGORYEVENTSPAST'){ $scope = 'past'; }
|
192 |
+
elseif ( $result == '#_CATEGORYEVENTSNEXT' ){ $scope = 'future'; }
|
193 |
+
else{ $scope = 'all'; }
|
194 |
+
$events = EM_Events::get( array('category'=>$this->id, 'scope'=>$scope) );
|
195 |
+
if ( count($events) > 0 ){
|
196 |
+
foreach($events as $EM_Event){
|
197 |
+
$replace .= $EM_Event->output(get_option('dbem_location_event_list_item_format'));
|
198 |
+
}
|
199 |
+
} else {
|
200 |
+
$replace = get_option('dbem_location_no_events_message');
|
201 |
+
}
|
202 |
+
break;
|
203 |
+
default:
|
204 |
+
$replace = $result;
|
205 |
+
break;
|
206 |
+
}
|
207 |
+
$replace = apply_filters('em_category_output_placeholder', $replace, $this, $result, $target); //USE WITH CAUTION! THIS MIGHT GET RENAMED
|
208 |
+
$category_string = str_replace($result, $replace , $category_string );
|
209 |
+
}
|
210 |
+
$name_filter = ($target == "html") ? 'dbem_general':'dbem_general_rss'; //TODO remove dbem_ filters
|
211 |
+
$category_string = str_replace('#_CATEGORY', apply_filters($name_filter, $this->name) , $category_string ); //Depreciated
|
212 |
+
return apply_filters('em_category_output', $category_string, $this, $format, $target);
|
213 |
+
}
|
214 |
+
|
215 |
+
function can_manage( $capability_owner = 'edit_categories', $capability_admin = false ){
|
216 |
+
global $em_capabilities_array;
|
217 |
+
//Figure out if this is multisite and require an extra bit of validation
|
218 |
+
$multisite_check = true;
|
219 |
+
$can_manage = current_user_can($capability_owner);
|
220 |
+
//if multisite and supoer admin, just return true
|
221 |
+
if( is_multisite() && is_super_admin() ){ return true; }
|
222 |
+
if( is_multisite() && get_site_option('dbem_ms_global_table') && !is_main_site() ){
|
223 |
+
//User can't admin this bit, as they're on a sub-blog
|
224 |
+
$can_manage = false;
|
225 |
+
if(array_key_exists($capability_owner, $em_capabilities_array) ){
|
226 |
+
$this->add_error( $em_capabilities_array[$capability_owner]);
|
227 |
+
}
|
228 |
+
}
|
229 |
+
return $can_manage;
|
230 |
+
}
|
231 |
+
}
|
232 |
?>
|
classes/em-event.php
CHANGED
@@ -1,1006 +1,1326 @@
|
|
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 |
-
'
|
22 |
-
'
|
23 |
-
'
|
24 |
-
'
|
25 |
-
'
|
26 |
-
'
|
27 |
-
'
|
28 |
-
'
|
29 |
-
'
|
30 |
-
'
|
31 |
-
'location_id' => array( 'name'=>'location_id', 'type'=>'%d' ),
|
32 |
-
'recurrence_id' => array( 'name'=>'recurrence_id', 'type'=>'%d' ),
|
33 |
-
'
|
34 |
-
'
|
35 |
-
'
|
36 |
-
'
|
37 |
-
'
|
38 |
-
'
|
39 |
-
'
|
40 |
-
'event_date_created' => array( 'name'=>'date_created', 'type'=>'%s' ),
|
41 |
-
'event_date_modified' => array( 'name'=>'date_modified', 'type'=>'%s' )
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
var $
|
47 |
-
var $
|
48 |
-
var $
|
49 |
-
var $
|
50 |
-
var $
|
51 |
-
var $
|
52 |
-
var $
|
53 |
-
var $
|
54 |
-
var $
|
55 |
-
var $
|
56 |
-
var $
|
57 |
-
var $
|
58 |
-
var $
|
59 |
-
var $
|
60 |
-
var $
|
61 |
-
var $
|
62 |
-
var $
|
63 |
-
var $
|
64 |
-
var $
|
65 |
-
var $
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
*
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
*
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
*
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
/**
|
89 |
-
*
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
*
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
*
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
*
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
*
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
/**
|
123 |
-
*
|
124 |
-
* @
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
$
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
$
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
}
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
$this->
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
$this->
|
216 |
-
}
|
217 |
-
$
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
$
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
$this->
|
261 |
-
}
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
$this->
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
if(
|
295 |
-
$this->
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
$this->
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
$
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
$
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
//
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
$
|
401 |
-
return apply_filters('
|
402 |
-
}
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
$
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
$this->
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
$
|
653 |
-
|
654 |
-
}
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
$
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
$
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
$
|
924 |
-
|
925 |
-
$
|
926 |
-
}
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
$
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
}
|
935 |
-
$
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
$
|
992 |
-
|
993 |
-
$
|
994 |
-
$
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_attributes' => array( 'name'=>'attributes', 'type'=>'%s' ),
|
34 |
+
'recurrence' => array( 'name'=>'recurrence', 'type'=>'%d' ),
|
35 |
+
'recurrence_interval' => array( 'name'=>'interval', 'type'=>'%d' ), //every x day(s)/week(s)/month(s)
|
36 |
+
'recurrence_freq' => array( 'name'=>'freq', 'type'=>'%s' ), //daily,weekly,monthly?
|
37 |
+
'recurrence_byday' => array( 'name'=>'byday', 'type'=>'%s' ), //if weekly or monthly, what days of the week?
|
38 |
+
'recurrence_byweekno' => array( 'name'=>'byweekno', 'type'=>'%d' ), //if monthly which week (-1 is last)
|
39 |
+
'event_status' => array( 'name'=>'status', '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 |
+
'blog_id' => array( 'name'=>'blog_id', 'type'=>'%d' ),
|
43 |
+
'group_id' => array( 'name'=>'group_id', 'type'=>'%d' )
|
44 |
+
);
|
45 |
+
/* Field Names - see above for matching DB field names and other field meta data */
|
46 |
+
var $id;
|
47 |
+
var $slug;
|
48 |
+
var $owner;
|
49 |
+
var $name;
|
50 |
+
var $start_time;
|
51 |
+
var $end_time;
|
52 |
+
var $start_date;
|
53 |
+
var $end_date;
|
54 |
+
var $notes;
|
55 |
+
var $rsvp;
|
56 |
+
//var $spaces;
|
57 |
+
var $location_id;
|
58 |
+
var $recurrence_id;
|
59 |
+
var $category_id;
|
60 |
+
var $attributes = array();
|
61 |
+
var $recurrence;
|
62 |
+
var $interval;
|
63 |
+
var $freq;
|
64 |
+
var $byday;
|
65 |
+
var $byweekno;
|
66 |
+
var $status;
|
67 |
+
var $date_created;
|
68 |
+
var $date_modified;
|
69 |
+
var $blog_id;
|
70 |
+
var $group_id;
|
71 |
+
|
72 |
+
var $image_url = '';
|
73 |
+
/**
|
74 |
+
* Timestamp of start date/time
|
75 |
+
* @var int
|
76 |
+
*/
|
77 |
+
var $start;
|
78 |
+
/**
|
79 |
+
* Timestamp of end date/time
|
80 |
+
* @var int
|
81 |
+
*/
|
82 |
+
var $end;
|
83 |
+
/**
|
84 |
+
* Created on timestamp, taken from DB, converted to TS
|
85 |
+
* @var int
|
86 |
+
*/
|
87 |
+
var $created;
|
88 |
+
/**
|
89 |
+
* Created on timestamp, taken from DB, converted to TS
|
90 |
+
* @var int
|
91 |
+
*/
|
92 |
+
var $modified;
|
93 |
+
|
94 |
+
/**
|
95 |
+
* @var EM_Location
|
96 |
+
*/
|
97 |
+
var $location;
|
98 |
+
/**
|
99 |
+
* @var EM_Bookings
|
100 |
+
*/
|
101 |
+
var $bookings;
|
102 |
+
/**
|
103 |
+
* The contact person for this event
|
104 |
+
* @var WP_User
|
105 |
+
*/
|
106 |
+
var $contact;
|
107 |
+
/**
|
108 |
+
* The category object
|
109 |
+
* @var EM_Category
|
110 |
+
*/
|
111 |
+
var $category;
|
112 |
+
/**
|
113 |
+
* If there are any errors, they will be added here.
|
114 |
+
* @var array
|
115 |
+
*/
|
116 |
+
var $errors = array();
|
117 |
+
/**
|
118 |
+
* If something was successful, a feedback message might be supplied here.
|
119 |
+
* @var string
|
120 |
+
*/
|
121 |
+
var $feedback_message;
|
122 |
+
/**
|
123 |
+
* Any warnings about an event (e.g. bad data, recurring/recurrence, etc.)
|
124 |
+
* @var string
|
125 |
+
*/
|
126 |
+
var $warnings;
|
127 |
+
/**
|
128 |
+
* Array of dbem_event field names required to create an event
|
129 |
+
* @var array
|
130 |
+
*/
|
131 |
+
var $required_fields = array('event_name', 'event_start_date');
|
132 |
+
var $mime_types = array(1 => 'gif', 2 => 'jpg', 3 => 'png');
|
133 |
+
|
134 |
+
/**
|
135 |
+
* 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.
|
136 |
+
* @param mixed $event_data
|
137 |
+
* @return null
|
138 |
+
*/
|
139 |
+
function EM_Event($event_data = false) {
|
140 |
+
global $wpdb, $EM_Recurrences;
|
141 |
+
//TODO Change the way we deal with time, maybe revert to timestamps for manipulation, and worry about output in html and db writes?
|
142 |
+
if( $event_data !== false ){
|
143 |
+
$event = array();
|
144 |
+
if( is_array($event_data) ){
|
145 |
+
//Accepts a raw array that'll just be imported directly into the object with no DB lookups (same for event and recurrence)
|
146 |
+
$event = $event_data;
|
147 |
+
if($event['location_name']){
|
148 |
+
$this->location = new EM_Location( $event );
|
149 |
+
}
|
150 |
+
}elseif( !empty($event_data) ) {
|
151 |
+
if( is_numeric($event_data) && $event_data > 0 ){
|
152 |
+
$cond = "event_id = $event_data";
|
153 |
+
}else{
|
154 |
+
$cond = "event_slug = '".$wpdb->escape($event_data)."'";
|
155 |
+
}
|
156 |
+
//Retreiving from the database
|
157 |
+
$events_table = EM_EVENTS_TABLE;
|
158 |
+
$locations_table = EM_LOCATIONS_TABLE;
|
159 |
+
$categories_table = EM_CATEGORIES_TABLE;
|
160 |
+
$sql = "
|
161 |
+
SELECT * FROM $events_table
|
162 |
+
LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
|
163 |
+
WHERE $cond
|
164 |
+
"; //We get event and location data here to avoid extra queries
|
165 |
+
$event = $wpdb->get_row ( $sql, ARRAY_A );
|
166 |
+
//Sort Location
|
167 |
+
$this->location = new EM_Location ( $event );
|
168 |
+
}
|
169 |
+
//Sort out attributes
|
170 |
+
if( !empty($event['event_attributes']) ){
|
171 |
+
if( is_serialized($event['event_attributes']) ){
|
172 |
+
$event['event_attributes'] = @unserialize($event['event_attributes']);
|
173 |
+
}
|
174 |
+
$event['event_attributes'] = (!is_array($event['event_attributes'])) ? array() : $event['event_attributes'] ;
|
175 |
+
}
|
176 |
+
$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
|
177 |
+
$this->to_object($event, true);
|
178 |
+
$this->blog_id = (!empty($event['blog_id'])) ? $event['blog_id']:0;
|
179 |
+
|
180 |
+
//Start/End times should be available as timestamp
|
181 |
+
$this->start = strtotime($this->start_date." ".$this->start_time);
|
182 |
+
$this->end = strtotime($this->end_date." ".$this->end_time);
|
183 |
+
$this->modified = ( !empty($event['event_date_modified']) ) ? strtotime($event['event_date_modified']):time();
|
184 |
+
$this->created = ( !empty($event['event_date_created']) ) ? strtotime($event['event_date_created']):time();
|
185 |
+
|
186 |
+
//Add Owner as Contact Person
|
187 |
+
if($this->owner && $this->owner > 0){
|
188 |
+
$this->contact = get_userdata($this->owner);
|
189 |
+
}
|
190 |
+
if( !is_object($this->contact) ){
|
191 |
+
$this->owner = get_option('dbem_default_contact_person');
|
192 |
+
$this->contact = get_userdata($this->owner);
|
193 |
+
}
|
194 |
+
if( is_object($this->contact) ){
|
195 |
+
$this->contact->phone = get_metadata('user', $this->contact->ID, 'dbem_phone', true);
|
196 |
+
}
|
197 |
+
//Now, if this is a recurrence, get the recurring for caching to the $EM_Recurrences
|
198 |
+
if( $this->is_recurrence() && is_array($EM_Recurrences) && !array_key_exists($this->recurrence_id, $EM_Recurrences) ){
|
199 |
+
$EM_Recurrences[$this->recurrence_id] = new EM_Event($this->recurrence_id);
|
200 |
+
}
|
201 |
+
}else{
|
202 |
+
$this->location = new EM_Location(); //blank location
|
203 |
+
}
|
204 |
+
$this->get_location();
|
205 |
+
//Do it here so things appear in the po file.
|
206 |
+
$this->status_array = array(
|
207 |
+
0 => __('Pending','dbem'),
|
208 |
+
1 => __('Approved','dbem')
|
209 |
+
);
|
210 |
+
|
211 |
+
//Set up some warning meta
|
212 |
+
if ( $this->is_recurring() ) {
|
213 |
+
$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' );
|
214 |
+
} elseif ( $this->is_recurrence() ) {
|
215 |
+
$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' );
|
216 |
+
}elseif( !empty($this->group_id) && function_exists('groups_get_group') ){
|
217 |
+
$group = groups_get_group(array('group_id'=>$this->group_id));
|
218 |
+
$this->warnings['group'] = sprintf(__('WARNING: This is a event belonging to the group "%s". Other group admins can also modify this event.', 'dbem'), $group->name);
|
219 |
+
}
|
220 |
+
$this->get_image_url();
|
221 |
+
add_filter('em_event_save',array(&$this, 'image_upload'), 1, 2);
|
222 |
+
do_action('em_event', $this, $event_data);
|
223 |
+
}
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Retrieve event, location and recurring information via POST
|
227 |
+
* @return boolean
|
228 |
+
*/
|
229 |
+
function get_post(){
|
230 |
+
//Build Event Array
|
231 |
+
do_action('em_event_get_post_pre', $this);
|
232 |
+
$this->name = ( !empty($_POST['event_name']) ) ? stripslashes($_POST['event_name']) : '' ;
|
233 |
+
$this->slug = ( !empty($_POST['event_slug']) ) ? sanitize_title($_POST['event_slug']) : '' ;
|
234 |
+
$this->start_date = ( !empty($_POST['event_start_date']) ) ? $_POST['event_start_date'] : '';
|
235 |
+
$this->end_date = ( !empty($_POST['event_end_date']) ) ? $_POST['event_end_date'] : $this->start_date;
|
236 |
+
$this->rsvp = ( !empty($_POST['event_rsvp']) ) ? 1:0;
|
237 |
+
//$this->spaces = ( !empty($_POST['event_spaces']) && is_numeric($_POST['event_spaces']) ) ? $_POST['event_spaces']:0;
|
238 |
+
$this->notes = ( !empty($_POST['content']) ) ? stripslashes($_POST['content']) : ''; //WP TinyMCE field
|
239 |
+
//Sort out time
|
240 |
+
//TODO make time handling less painful
|
241 |
+
$match = array();
|
242 |
+
if( !empty($_POST['event_start_time']) && preg_match ( '/^([01]\d|2[0-3]):([0-5]\d)(AM|PM)?$/', $_POST['event_start_time'], $match ) ){
|
243 |
+
if( !empty($match[3]) && $match[3] == 'PM' && $match[1] != 12 ){
|
244 |
+
$match[1] = 12+$match[1];
|
245 |
+
}elseif( !empty($match[3]) && $match[3] == 'AM' && $match[1] == 12 ){
|
246 |
+
$match[1] = '00';
|
247 |
+
}
|
248 |
+
$this->start_time = $match[1].":".$match[2].":00";
|
249 |
+
}else{
|
250 |
+
$this->start_time = "00:00:00";
|
251 |
+
}
|
252 |
+
if( !empty($_POST['event_end_time']) && preg_match ( '/^([01]\d|2[0-3]):([0-5]\d)(AM|PM)?$/', $_POST['event_end_time'], $match ) ){
|
253 |
+
if( !empty($match[3]) && $match[3] == 'PM' && $match[1] != 12 ){
|
254 |
+
$match[1] = 12+$match[1];
|
255 |
+
}elseif( !empty($match[3]) && $match[3] == 'AM' && $match[1] == 12 ){
|
256 |
+
$match[1] = '00';
|
257 |
+
}
|
258 |
+
$this->end_time = $match[1].":".$match[2].":00";
|
259 |
+
}else{
|
260 |
+
$this->end_time = $this->start_time;
|
261 |
+
}
|
262 |
+
//Start/End times should be available as timestamp
|
263 |
+
$this->start = strtotime($this->start_date." ".$this->start_time);
|
264 |
+
$this->end = strtotime($this->end_date." ".$this->end_time);
|
265 |
+
//owner
|
266 |
+
if( !empty($_REQUEST['event_owner']) && is_numeric($_REQUEST['event_owner']) ){
|
267 |
+
$this->owner = current_user_can('edit_others_events') ? $_REQUEST['event_owner']:get_current_user_id();
|
268 |
+
}
|
269 |
+
//categories
|
270 |
+
if( !empty($_POST['event_categories']) && is_array($_POST['event_categories']) ){
|
271 |
+
$this->categories = new EM_Categories($_POST['event_categories']);
|
272 |
+
}else{
|
273 |
+
$this->categories = new EM_Categories();
|
274 |
+
}
|
275 |
+
//Attributes
|
276 |
+
$event_attributes = array();
|
277 |
+
$post = $_POST;
|
278 |
+
$event_available_attributes = em_get_attributes();
|
279 |
+
if( !empty($_POST['em_attributes']) && is_array($_POST['em_attributes']) ){
|
280 |
+
foreach($_POST['em_attributes'] as $att_key => $att_value ){
|
281 |
+
if( (in_array($att_key, $event_available_attributes['names']) || array_key_exists($att_key, $this->attributes) ) && trim($att_value) != '' ){
|
282 |
+
$att_vals = count($event_available_attributes['values'][$att_key]);
|
283 |
+
if( $att_vals == 0 || ($att_vals > 0 && in_array($att_value, $event_available_attributes['values'][$att_key])) ){
|
284 |
+
$event_attributes[$att_key] = $att_value;
|
285 |
+
}elseif($att_vals > 0){
|
286 |
+
$event_attributes[$att_key] = $event_available_attributes['values'][$att_key][0];
|
287 |
+
}
|
288 |
+
}
|
289 |
+
}
|
290 |
+
}
|
291 |
+
$this->attributes = stripslashes_deep($event_attributes);
|
292 |
+
//Recurrence data
|
293 |
+
$this->recurrence_id = ( !empty($_POST['recurrence_id']) && is_numeric($_POST['recurrence_id']) ) ? $_POST['recurrence_id'] : 0 ;
|
294 |
+
if( !empty($_POST['repeated_event']) ){
|
295 |
+
$this->recurrence = 1;
|
296 |
+
$this->freq = ( !empty($_POST['recurrence_freq']) && in_array($_POST['recurrence_freq'], array('daily','weekly','monthly')) ) ? $_POST['recurrence_freq']:'daily';
|
297 |
+
if( !empty($_POST['recurrence_bydays']) && $this->freq == 'weekly' && self::array_is_numeric($_POST['recurrence_bydays']) ){
|
298 |
+
$this->byday = implode ( ",", $_POST['recurrence_bydays'] );
|
299 |
+
}elseif( !empty($_POST['recurrence_byday']) && $this->freq == 'monthly' ){
|
300 |
+
$this->byday = $_POST['recurrence_byday'];
|
301 |
+
}
|
302 |
+
$this->interval = ( !empty($_POST['recurrence_interval']) ) ? $_POST['recurrence_interval']:1;
|
303 |
+
$this->byweekno = ( !empty($_POST['recurrence_byweekno']) ) ? $_POST['recurrence_byweekno']:'';
|
304 |
+
}
|
305 |
+
|
306 |
+
//Add location information, or just link to previous location, this is a requirement...
|
307 |
+
if( !empty($_POST['location_id']) && is_numeric($_POST['location_id'])) {
|
308 |
+
$this->location_id = $_POST['location_id'];
|
309 |
+
$this->location = new EM_Location($_POST['location_id']);
|
310 |
+
} else {
|
311 |
+
$this->location = new EM_Location();
|
312 |
+
$this->location->get_post();
|
313 |
+
}
|
314 |
+
if( !$this->get_bookings()->get_tickets()->get_post() ){
|
315 |
+
$EM_Tickets = $this->get_bookings()->get_tickets();
|
316 |
+
array_merge($this->errors, $this->get_bookings()->get_tickets()->errors);
|
317 |
+
}
|
318 |
+
return apply_filters('em_event_get_post', $this->validate(), $this);
|
319 |
+
}
|
320 |
+
|
321 |
+
/**
|
322 |
+
* 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.
|
323 |
+
* Will automatically detect what type of event it is (recurrent, recurrence or normal) and whether it's a new or existing event.
|
324 |
+
* @return boolean
|
325 |
+
*/
|
326 |
+
function save(){
|
327 |
+
//FIXME Event doesn't save title when inserting first time
|
328 |
+
global $wpdb, $current_user;
|
329 |
+
if( !$this->can_manage('edit_events', 'edit_others_events')){
|
330 |
+
return apply_filters('em_event_save', false, $this);
|
331 |
+
}
|
332 |
+
do_action('em_event_save_pre', $this);
|
333 |
+
get_currentuserinfo();
|
334 |
+
$events_table = EM_EVENTS_TABLE;
|
335 |
+
$request = $_REQUEST;
|
336 |
+
//First let's save the location, no location no event!
|
337 |
+
if ( !$this->get_location()->id && !$this->location->save() ){ //shouldn't try to save if location exists
|
338 |
+
$this->errors[] = __('There was a problem saving the location so event was not saved.', 'dbem');
|
339 |
+
return apply_filters('em_event_save', false, $this);
|
340 |
+
}
|
341 |
+
$this->location_id = $this->location->id;
|
342 |
+
//owner person can be anyone the admin wants, but the creator if not.
|
343 |
+
if( current_user_can('edit_others_events') ){
|
344 |
+
$this->owner = ( $this->owner > 0 ) ? $this->owner:0;
|
345 |
+
}else{
|
346 |
+
//force
|
347 |
+
$this->owner = get_current_user_id();
|
348 |
+
}
|
349 |
+
//Set status of this event, depending on user type
|
350 |
+
if( current_user_can('publish_events') ){
|
351 |
+
//top level can edit and publish any events
|
352 |
+
$this->status = 1;
|
353 |
+
}else{
|
354 |
+
//any updates or additions put the event into pending status
|
355 |
+
$this->status = 0;
|
356 |
+
}
|
357 |
+
$this->slug = $this->sanitize_title();
|
358 |
+
|
359 |
+
//Now save the event
|
360 |
+
if ( !$this->id ) {
|
361 |
+
// Insert New Event
|
362 |
+
if( is_multisite() ){
|
363 |
+
$this->blog_id = get_current_blog_id();
|
364 |
+
}
|
365 |
+
$this->owner = $current_user->ID; //Record creator of event
|
366 |
+
$this->date_created = current_time('mysql');
|
367 |
+
$event = $this->to_array(true);
|
368 |
+
$event['event_attributes'] = serialize($this->attributes);
|
369 |
+
$event['recurrence_id'] = ( is_numeric($this->recurrence_id) ) ? $this->recurrence_id : 0;
|
370 |
+
$event = apply_filters('em_event_save_pre',$event,$this);
|
371 |
+
$result = $wpdb->insert ( $events_table, $event, $this->get_types($event) );
|
372 |
+
if($result !== false){
|
373 |
+
//$event['event_date_created'] = current_time('mysql');
|
374 |
+
$this->id = $wpdb->insert_id;
|
375 |
+
$this->is_new = true;
|
376 |
+
//Add Tickets
|
377 |
+
if( !$this->get_bookings()->get_tickets()->save() ){
|
378 |
+
$this->errors[] = __( 'Something went wrong with creating tickets.', 'dbem' );
|
379 |
+
return apply_filters('em_event_save', false, $this);
|
380 |
+
}
|
381 |
+
//Save Categories
|
382 |
+
if( !$this->get_categories()->save() ){
|
383 |
+
$this->add_error( $this->get_categories()->get_errors() );
|
384 |
+
return apply_filters('em_event_save', false, $this);
|
385 |
+
}
|
386 |
+
//Deal with recurrences
|
387 |
+
if ( $this->is_recurring() ) {
|
388 |
+
//Recurrence master event saved, now Save Events & check errors
|
389 |
+
if( !$this->save_events() ){
|
390 |
+
$this->add_error(__ ( 'Something went wrong with the recurrence update...', 'dbem' ).
|
391 |
+
__ ( 'There was a problem saving the recurring events.', 'dbem' ));
|
392 |
+
$this->delete();
|
393 |
+
return apply_filters('em_event_save', false, $this);
|
394 |
+
}
|
395 |
+
//All good! Event Saved
|
396 |
+
$this->feedback_message = __ ( 'New recurrent event inserted!', 'dbem' );
|
397 |
+
return apply_filters('em_event_save', true, $this);
|
398 |
+
}
|
399 |
+
//Successful individual save
|
400 |
+
$this->feedback_message = __ ( 'New event successfully inserted!', 'dbem' );
|
401 |
+
return apply_filters('em_event_save', true, $this);
|
402 |
+
}else{
|
403 |
+
$this->errors[] = __ ( 'Could not save the event details due to a database error.', 'dbem' );
|
404 |
+
}
|
405 |
+
} else {
|
406 |
+
// Update Event
|
407 |
+
if($this->is_recurrence()){
|
408 |
+
//duplicate the original recurrence image
|
409 |
+
$dir = (EM_IMAGE_DS == '/') ? 'events/event':'event';
|
410 |
+
foreach($this->mime_types as $mime_type) {
|
411 |
+
$file_name = $dir."-{$this->recurrence_id}.$mime_type";
|
412 |
+
if( file_exists( EM_IMAGE_UPLOAD_DIR . $file_name) ) {
|
413 |
+
$replacement = $dir."-{$this->id}.$mime_type";
|
414 |
+
copy(EM_IMAGE_UPLOAD_DIR . $file_name, EM_IMAGE_UPLOAD_DIR . $replacement);
|
415 |
+
}
|
416 |
+
}
|
417 |
+
}
|
418 |
+
$this->recurrence_id = 0; // If it's saved here, it becomes individual
|
419 |
+
$event = $this->to_array();
|
420 |
+
$event['event_attributes'] = serialize($event['event_attributes']);
|
421 |
+
unset($event['event_date_created']);
|
422 |
+
$event['event_date_modified'] = current_time('mysql');
|
423 |
+
$event = apply_filters('em_event_save_pre',$event,$this);
|
424 |
+
$result = $wpdb->update ( $events_table, $event, array('event_id' => $this->id), $this->get_types($event) );
|
425 |
+
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
|
426 |
+
//Add Tickets
|
427 |
+
$this->feedback_message = "{$this->name} " . __ ( 'updated', 'dbem' ) . "!";
|
428 |
+
if( !$this->get_bookings()->get_tickets()->save() ){
|
429 |
+
$this->errors[] = __( 'Something went wrong with creating tickets.', 'dbem' );
|
430 |
+
return apply_filters('em_event_save', false, $this);
|
431 |
+
}
|
432 |
+
//Save Categories
|
433 |
+
if( !$this->get_categories()->save() ){
|
434 |
+
$this->add_error( $this->get_categories()->get_errors() );
|
435 |
+
return apply_filters('em_event_save', false, $this);
|
436 |
+
}
|
437 |
+
//Deal with recurrences
|
438 |
+
if ( $this->is_recurring() ) {
|
439 |
+
if( !$this->save_events() ){
|
440 |
+
$this->errors[] = __ ( 'Something went wrong with the recurrence update...', 'dbem' ).
|
441 |
+
__ ( 'There was a problem saving the recurring events.', 'dbem' );
|
442 |
+
return apply_filters('em_event_save', false, $this);
|
443 |
+
}
|
444 |
+
$this->feedback_message = __ ( 'Recurrence updated!', 'dbem' );
|
445 |
+
return apply_filters('em_event_save', true, $this);
|
446 |
+
}
|
447 |
+
}else{
|
448 |
+
$this->errors[] = __('Could not save the event details due to a database error.', 'dbem');
|
449 |
+
return apply_filters('em_event_save', false, $this);
|
450 |
+
}
|
451 |
+
//Successful individual or recurrence save
|
452 |
+
$this->feedback_message = "{$this->name} " . __ ( 'updated', 'dbem' ) . "!";
|
453 |
+
if($this->rsvp == 0){
|
454 |
+
$this->delete_bookings();
|
455 |
+
}
|
456 |
+
return apply_filters('em_event_save', true, $this);
|
457 |
+
}
|
458 |
+
}
|
459 |
+
|
460 |
+
/**
|
461 |
+
* Takes the title and gives either a unique slug or returns the currently used slug if this record already has it.
|
462 |
+
* @param unknown_type $title
|
463 |
+
*/
|
464 |
+
function sanitize_title($iteration = 1){
|
465 |
+
global $wpdb;
|
466 |
+
//Generate the slug. If this is a new event, create the slug automatically, if not, verify it is still unique and if not rewrite
|
467 |
+
if( empty($this->slug) ){
|
468 |
+
$this->slug = sanitize_title($this->name);
|
469 |
+
}
|
470 |
+
$slug = $this->slug;
|
471 |
+
$slug_matches = $wpdb->get_results('SELECT event_id FROM '.EM_EVENTS_TABLE." WHERE event_slug='{$slug}'", ARRAY_A);
|
472 |
+
if( count($slug_matches) > 0 ){ //we will check that the slug is unique
|
473 |
+
if( $slug_matches[0]['event_id'] != $this->id || count($slug_matches) > 1 ){
|
474 |
+
//we have a conflict, so try another alternative
|
475 |
+
$this->slug = preg_replace('/\-[0-9]+$/', '', $slug).'-'.($iteration+1);
|
476 |
+
$this->sanitize_title($iteration+1);
|
477 |
+
}
|
478 |
+
}
|
479 |
+
return apply_filters('em_event_sanitize_title', $this->slug, $this);
|
480 |
+
}
|
481 |
+
|
482 |
+
/**
|
483 |
+
* Delete whole event, including recurrence and recurring data
|
484 |
+
* @param $recurrence_id
|
485 |
+
* @return boolean
|
486 |
+
*/
|
487 |
+
function delete(){
|
488 |
+
global $wpdb;
|
489 |
+
do_action('em_event_delete_pre', $this);
|
490 |
+
$result = false;
|
491 |
+
if( $this->can_manage( 'delete_events','delete_others_events' ) ){
|
492 |
+
if( $this->is_recurring() ){
|
493 |
+
//Delete the recurrences then this recurrence event
|
494 |
+
$this->delete_events();
|
495 |
+
}
|
496 |
+
$result = $wpdb->query ( $wpdb->prepare("DELETE FROM ". EM_EVENTS_TABLE ." WHERE event_id=%d", $this->id) );
|
497 |
+
if($result !== false){
|
498 |
+
//delete bookings
|
499 |
+
$result_bookings = $this->get_bookings()->delete();
|
500 |
+
//delete tickets
|
501 |
+
$result_tickets = $this->get_bookings()->get_tickets()->delete();
|
502 |
+
//delete categories
|
503 |
+
$result = $wpdb->query ( $wpdb->prepare("DELETE FROM ". EM_META_TABLE ." WHERE meta_key='event-category' AND object_id=%d", $this->id) );
|
504 |
+
$this->id = false;
|
505 |
+
}
|
506 |
+
}
|
507 |
+
return apply_filters('em_event_delete', $result !== false, $this);
|
508 |
+
}
|
509 |
+
|
510 |
+
/**
|
511 |
+
* approve a booking.
|
512 |
+
* @return bool
|
513 |
+
*/
|
514 |
+
function approve(){
|
515 |
+
return $this->set_status(1);
|
516 |
+
}
|
517 |
+
|
518 |
+
/**
|
519 |
+
* Change the status of the event. This will save to the Database too.
|
520 |
+
* @param unknown_type $status
|
521 |
+
* @return string
|
522 |
+
*/
|
523 |
+
function set_status($status){
|
524 |
+
$action_string = strtolower($this->status_array[$status]);
|
525 |
+
$this->previous_status = $this->status;
|
526 |
+
$this->status = $status;
|
527 |
+
$result = $this->save();
|
528 |
+
if($result){
|
529 |
+
$this->feedback_message = sprintf(__('Event %s.','dbem'), $action_string);
|
530 |
+
return true;
|
531 |
+
}else{
|
532 |
+
//errors should be logged by save()
|
533 |
+
$this->feedback_message = sprintf(__('Booking could not be %s.','dbem'), $action_string);
|
534 |
+
return false;
|
535 |
+
}
|
536 |
+
}
|
537 |
+
|
538 |
+
/**
|
539 |
+
* Duplicates this event and returns the duplicated event. Will return false if there is a problem with duplication.
|
540 |
+
* @return EM_Event
|
541 |
+
*/
|
542 |
+
function duplicate(){
|
543 |
+
global $wpdb, $EZSQL_ERROR;
|
544 |
+
//First, duplicate.
|
545 |
+
if( $this->can_manage('edit_events','edit_others_events') ){
|
546 |
+
$event_table_name = EM_EVENTS_TABLE;
|
547 |
+
$eventArray = $this->to_array();
|
548 |
+
unset($eventArray['event_id']);
|
549 |
+
$EM_Event = new EM_Event( $eventArray );
|
550 |
+
if( $EM_Event->save() ){
|
551 |
+
$EM_Event->feedback_message = sprintf(__("%s successfully duplicated.", 'dbem'), __('Event','dbem'));
|
552 |
+
return apply_filters('em_event_duplicate', $EM_Event, $this);
|
553 |
+
}
|
554 |
+
}else{
|
555 |
+
$this->add_error( sprintf(__('You are not allowed to manage this %s.'), __('event','dbem')) );
|
556 |
+
}
|
557 |
+
//TODO add error notifications for duplication failures.
|
558 |
+
return apply_filters('em_event_duplicate', false, $this);;
|
559 |
+
}
|
560 |
+
|
561 |
+
|
562 |
+
/**
|
563 |
+
* Validates the event. Should be run during any form submission or saving operation.
|
564 |
+
* @return boolean
|
565 |
+
*/
|
566 |
+
function validate() {
|
567 |
+
$missing_fields = Array ();
|
568 |
+
foreach ( $this->required_fields as $field ) {
|
569 |
+
$true_field = $this->fields[$field]['name'];
|
570 |
+
if ( $this->$true_field == "") {
|
571 |
+
$missing_fields[] = $field;
|
572 |
+
}
|
573 |
+
}
|
574 |
+
if ( count($missing_fields) > 0){
|
575 |
+
// TODO Create friendly equivelant names for missing fields notice in validation
|
576 |
+
$this->add_error( __( 'Missing fields: ' ) . implode ( ", ", $missing_fields ) . ". " );
|
577 |
+
}
|
578 |
+
if ( !empty($_POST['repeated_event']) && $_POST['repeated_event'] == "1" && $this->end_date == "" ){
|
579 |
+
$this->add_error( __( 'Since the event is repeated, you must specify an event date.', 'dbem' ));
|
580 |
+
}
|
581 |
+
if( preg_match('/\d{4}-\d{2}-\d{2}/', $this->start_date) && preg_match('/\d{4}-\d{2}-\d{2}/', $this->end_date) ){
|
582 |
+
if( strtotime($this->start_date . $this->start_time) > strtotime($this->end_date . $this->end_time) ){
|
583 |
+
$this->add_error(__('Events cannot start after they end.','dbem'));
|
584 |
+
}
|
585 |
+
}else{
|
586 |
+
$this->add_error(__('Dates must have correct formatting. Please use the date picker provided.','dbem'));
|
587 |
+
}
|
588 |
+
if( $this->get_location()->id == '' && !$this->location->validate() ){
|
589 |
+
$this->errors = array_merge($this->errors, $this->location->errors);
|
590 |
+
}
|
591 |
+
$this->image_validate();
|
592 |
+
|
593 |
+
//TODO validate recurrence during event validate
|
594 |
+
$count = count($this->errors);
|
595 |
+
return apply_filters('em_event_validate', count($this->errors) == 0, $this );
|
596 |
+
}
|
597 |
+
|
598 |
+
/**
|
599 |
+
* Returns an EM_Categories object of the EM_Event instance.
|
600 |
+
* @return EM_Categories
|
601 |
+
*/
|
602 |
+
function get_categories() {
|
603 |
+
global $EM_Categories;
|
604 |
+
if( !empty($this->categories) && is_object($this->categories) && get_class($this->categories)=='EM_Categories' && ( empty($this->categories->event->id) || $this->categories->event->id == $this->id ) ){
|
605 |
+
$this->categories = $this->categories;
|
606 |
+
}elseif( is_object($EM_Categories) && $EM_Categories->get_event()->id == $this->id ){
|
607 |
+
$this->categories = $EM_Categories;
|
608 |
+
}else{
|
609 |
+
$this->categories = new EM_Categories($this);
|
610 |
+
}
|
611 |
+
$this->categories->event = $this;
|
612 |
+
return apply_filters('em_event_get_categories', $this->categories, $this);
|
613 |
+
}
|
614 |
+
|
615 |
+
/**
|
616 |
+
* Returns the location object this event belongs to.
|
617 |
+
* @return EM_Location
|
618 |
+
*/
|
619 |
+
function get_location() {
|
620 |
+
global $EM_location;
|
621 |
+
if( is_object($this->location) && get_class($this->location)=='EM_Location' && ($this->location_id == $this->location->id || empty($this->id)) ){
|
622 |
+
return $this->location;
|
623 |
+
}elseif( is_object($EM_location) && $EM_location->id == $this->location_id ){
|
624 |
+
$this->location = $EM_location;
|
625 |
+
}else{
|
626 |
+
$this->location = new EM_location($this->location_id);
|
627 |
+
}
|
628 |
+
return apply_filters('em_event_get_location', $this->location, $this);
|
629 |
+
}
|
630 |
+
|
631 |
+
/**
|
632 |
+
* Shortcut function for $this->get_bookings()->delete(), because using the EM_Bookings requires loading previous bookings, which isn't neceesary.
|
633 |
+
*/
|
634 |
+
function delete_bookings(){
|
635 |
+
global $wpdb;
|
636 |
+
do_action('em_event_delete_bookings_pre', $this);
|
637 |
+
$result = false;
|
638 |
+
if( $this->can_manage('manage_bookings','manage_others_bookings') ){
|
639 |
+
$result = $wpdb->query( $wpdb->prepare("DELETE FROM ".EM_BOOKINGS_TABLE." WHERE event_id=%d", $this->id) );
|
640 |
+
}
|
641 |
+
return apply_filters('em_event_delete_bookings', $result, $this);
|
642 |
+
}
|
643 |
+
|
644 |
+
/**
|
645 |
+
* 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.
|
646 |
+
* @param boolean $force_reload
|
647 |
+
* @return EM_Bookings
|
648 |
+
*/
|
649 |
+
function get_bookings( $force_reload = false ){
|
650 |
+
if( get_option('dbem_rsvp_enabled') ){
|
651 |
+
if( (!$this->bookings || $force_reload) ){
|
652 |
+
$this->bookings = new EM_Bookings($this);
|
653 |
+
}
|
654 |
+
}else{
|
655 |
+
return new EM_Bookings();
|
656 |
+
}
|
657 |
+
return apply_filters('em_event_get_bookings', $this->bookings, $this);
|
658 |
+
}
|
659 |
+
|
660 |
+
function is_free(){
|
661 |
+
$free = true;
|
662 |
+
if( isset($this->free) ) return $this->free;
|
663 |
+
foreach($this->get_bookings()->get_tickets() as $EM_Ticket){
|
664 |
+
if( $EM_Ticket->price > 0 ){
|
665 |
+
$free = false;
|
666 |
+
}
|
667 |
+
}
|
668 |
+
return apply_filters('em_event_is_free',$free,$this);
|
669 |
+
}
|
670 |
+
|
671 |
+
/**
|
672 |
+
* Gets number of spaces in this event, dependent on ticket spaces or hard limit, whichever is smaller.
|
673 |
+
* @param boolean $force_refresh
|
674 |
+
* @return int
|
675 |
+
*/
|
676 |
+
function get_spaces($force_refresh=false){
|
677 |
+
return $this->get_bookings()->get_spaces($force_refresh);
|
678 |
+
}
|
679 |
+
|
680 |
+
/**
|
681 |
+
* Will output a single event format of this event.
|
682 |
+
* Equivalent of calling EM_Event::output( get_option ( 'dbem_single_event_format' ) )
|
683 |
+
* @param string $target
|
684 |
+
* @return string
|
685 |
+
*/
|
686 |
+
function output_single($target='html'){
|
687 |
+
$format = get_option ( 'dbem_single_event_format' );
|
688 |
+
return apply_filters('em_event_output_single', $this->output($format, $target), $this, $target);
|
689 |
+
}
|
690 |
+
|
691 |
+
/**
|
692 |
+
* Will output a event in the format passed in $format by replacing placeholders within the format.
|
693 |
+
* @param string $format
|
694 |
+
* @param string $target
|
695 |
+
* @return string
|
696 |
+
*/
|
697 |
+
function output($format, $target="html") {
|
698 |
+
//First let's do some conditional placeholder removals
|
699 |
+
preg_match_all('/\{([a-zA-Z0-9_]+)\}([^{]+)\{\/[a-zA-Z0-9_]+\}/', $format, $conditionals);
|
700 |
+
if( count($conditionals[0]) > 0 ){
|
701 |
+
//Check if the language we want exists, if not we take the first language there
|
702 |
+
foreach($conditionals[1] as $key => $condition){
|
703 |
+
$replacement = $conditionals[0][$key];
|
704 |
+
if ($condition == 'has_bookings') {
|
705 |
+
//check if there's a booking, if not, remove this section of code.
|
706 |
+
if($this->rsvp && get_option('dbem_rsvp_enabled')){
|
707 |
+
$replacement = substr($conditionals[0][$key], 14, strlen($conditionals[0][$key])-29); //29 = (15+14)
|
708 |
+
}else{
|
709 |
+
$replacement = '';
|
710 |
+
}
|
711 |
+
}
|
712 |
+
if ($condition == 'no_bookings') {
|
713 |
+
//check if there's a booking, if not, remove this section of code.
|
714 |
+
if(!$this->rsvp && get_option('dbem_rsvp_enabled')){
|
715 |
+
$replacement = substr($conditionals[0][$key], 13, strlen($conditionals[0][$key])-28); //28 = (13+14)
|
716 |
+
}else{
|
717 |
+
$replacement = '';
|
718 |
+
}
|
719 |
+
str_replace($conditionals[0][$key], $replacement, $format);
|
720 |
+
}
|
721 |
+
$format = str_replace($conditionals[0][$key], apply_filters('em_event_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $format);
|
722 |
+
}
|
723 |
+
}
|
724 |
+
$event_string = $format;
|
725 |
+
//Now let's check out the placeholders.
|
726 |
+
preg_match_all("/#@?_?[A-Za-z0-9]+/", $format, $placeholders);
|
727 |
+
foreach($placeholders[0] as $result) {
|
728 |
+
$match = true;
|
729 |
+
$replace = '';
|
730 |
+
switch( $result ){
|
731 |
+
//Event Details
|
732 |
+
case '#_EVENTID':
|
733 |
+
$replace = $this->id;
|
734 |
+
break;
|
735 |
+
case '#_NAME':
|
736 |
+
$replace = $this->name;
|
737 |
+
break;
|
738 |
+
case '#_NOTES':
|
739 |
+
case '#_EXCERPT':
|
740 |
+
//SEE AT BOTTOM OF FILE FOR OLD TARGET FILTERS FROM 2.x
|
741 |
+
$replace = $this->notes;
|
742 |
+
if($result == "#_EXCERPT"){
|
743 |
+
$matches = explode('<!--more', $this->notes);
|
744 |
+
$replace = $matches[0];
|
745 |
+
}
|
746 |
+
break;
|
747 |
+
case '#_EVENTIMAGEURL':
|
748 |
+
case '#_EVENTIMAGE':
|
749 |
+
if($this->image_url != ''){
|
750 |
+
$replace = ($result == '#_EVENTIMAGEURL') ? $this->image_url : "<img src='".$this->image_url."' alt='".$this->name."'/>";
|
751 |
+
}
|
752 |
+
break;
|
753 |
+
//Times
|
754 |
+
case '#_24HSTARTTIME':
|
755 |
+
case '#_24HENDTIME':
|
756 |
+
$time = ($result == '#_24HSTARTTIME') ? $this->start_time:$this->end_time;
|
757 |
+
$replace = substr($time, 0,5);
|
758 |
+
break;
|
759 |
+
case '#_12HSTARTTIME':
|
760 |
+
case '#_12HENDTIME':
|
761 |
+
$time = ($result == '#_12HSTARTTIME') ? $this->start_time:$this->end_time;
|
762 |
+
$replace = date('g:i A', strtotime($time));
|
763 |
+
break;
|
764 |
+
//Links
|
765 |
+
case '#_EVENTPAGEURL': //Depreciated
|
766 |
+
case '#_LINKEDNAME': //Depreciated
|
767 |
+
case '#_EVENTURL': //Just the URL
|
768 |
+
case '#_EVENTLINK': //HTML Link
|
769 |
+
//If this event is not of this blog, we need a new URL
|
770 |
+
$EM_URI = EM_URI;
|
771 |
+
if( is_multisite() && get_site_option('dbem_ms_global_events') && get_site_option('dbem_ms_global_events_links') && !empty($this->blog_id) && is_main_site() && $this->blog_id != get_current_blog_id() ){
|
772 |
+
$EM_URI = get_blog_permalink($this->blog_id, get_blog_option($this->blog_id, 'dbem_events_page'));
|
773 |
+
}
|
774 |
+
$joiner = (stristr($EM_URI, "?")) ? "&" : "?";
|
775 |
+
$event_link = $EM_URI.$joiner."event_id=".$this->id;
|
776 |
+
if($result == '#_LINKEDNAME' || $result == '#_EVENTLINK'){
|
777 |
+
$replace = "<a href='{$event_link}' title='{$this->name}'>{$this->name}</a>";
|
778 |
+
}else{
|
779 |
+
$replace = $event_link;
|
780 |
+
}
|
781 |
+
break;
|
782 |
+
case '#_EDITEVENTURL':
|
783 |
+
case '#_EDITEVENTLINK':
|
784 |
+
if( $this->can_manage('edit_events','edit_others_events') ){
|
785 |
+
if( is_multisite() && get_site_option('dbem_ms_global_events') && get_site_option('dbem_ms_global_events_links') && !empty($this->blog_id) && is_main_site() && $this->blog_id != get_current_blog_id() ){
|
786 |
+
$replace = get_site_url($this->blog_id, "/wp-admin/admin.php?page=events-manager-event&event_id={$this->id}");
|
787 |
+
}else{
|
788 |
+
$replace = get_bloginfo('wpurl')."/wp-admin/admin.php?page=events-manager-event&event_id={$this->id}";
|
789 |
+
}
|
790 |
+
if( $result == '#_EDITEVENTLINK'){
|
791 |
+
$replace = "<a href='{$replace}'>".__('Edit').' '.__('Event', 'dbem')."</a>";
|
792 |
+
}
|
793 |
+
}
|
794 |
+
break;
|
795 |
+
//Bookings
|
796 |
+
case '#_ADDBOOKINGFORM': //Depreciated
|
797 |
+
case '#_REMOVEBOOKINGFORM': //Depreciated
|
798 |
+
case '#_BOOKINGFORM':
|
799 |
+
if( get_option('dbem_rsvp_enabled')){
|
800 |
+
ob_start();
|
801 |
+
$template = em_locate_template('placeholders/bookingform.php', true, array('EM_Event'=>$this));
|
802 |
+
$replace = ob_get_clean();
|
803 |
+
}
|
804 |
+
break;
|
805 |
+
case '#_BOOKINGBUTTON':
|
806 |
+
if( get_option('dbem_rsvp_enabled')){
|
807 |
+
ob_start();
|
808 |
+
$template = em_locate_template('placeholders/bookingbutton.php', true, array('EM_Event'=>$this));
|
809 |
+
$replace = ob_get_clean();
|
810 |
+
}
|
811 |
+
break;
|
812 |
+
case '#_AVAILABLESEATS': //Depreciated
|
813 |
+
case '#_AVAILABLESPACES':
|
814 |
+
if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
|
815 |
+
$replace = $this->get_bookings()->get_available_spaces();
|
816 |
+
} else {
|
817 |
+
$replace = "0";
|
818 |
+
}
|
819 |
+
break;
|
820 |
+
case '#_BOOKEDSEATS': //Depreciated
|
821 |
+
case '#_BOOKEDSPACES':
|
822 |
+
if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
|
823 |
+
$replace = $this->get_bookings()->get_booked_spaces();
|
824 |
+
} else {
|
825 |
+
$replace = "0";
|
826 |
+
}
|
827 |
+
break;
|
828 |
+
case '#_PENDINGSPACES':
|
829 |
+
if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
|
830 |
+
$replace = $this->get_bookings()->get_pending_spaces();
|
831 |
+
} else {
|
832 |
+
$replace = "0";
|
833 |
+
}
|
834 |
+
break;
|
835 |
+
case '#_SEATS': //Depreciated
|
836 |
+
case '#_SPACES':
|
837 |
+
$replace = $this->get_spaces();
|
838 |
+
break;
|
839 |
+
case '#_BOOKINGSURL':
|
840 |
+
case '#_BOOKINGSLINK':
|
841 |
+
$bookings_link = get_bloginfo ( 'wpurl' )."/wp-admin/admin.php?page=events-manager-bookings&event_id=".$this->id;
|
842 |
+
if($result == '#_BOOKINGSLINK'){
|
843 |
+
$replace = "<a href='{$bookings_link}' title='{$this->name}'>{$this->name}</a>";
|
844 |
+
}else{
|
845 |
+
$replace = $bookings_link;
|
846 |
+
}
|
847 |
+
break;
|
848 |
+
//Contact Person
|
849 |
+
case '#_CONTACTNAME':
|
850 |
+
case '#_CONTACTPERSON': //Depreciated (your call, I think name is better)
|
851 |
+
$replace = $this->contact->display_name;
|
852 |
+
break;
|
853 |
+
case '#_CONTACTUSERNAME':
|
854 |
+
$replace = $this->contact->user_login;
|
855 |
+
break;
|
856 |
+
case '#_CONTACTEMAIL':
|
857 |
+
case '#_CONTACTMAIL': //Depreciated
|
858 |
+
$replace = $this->contact->user_email;
|
859 |
+
break;
|
860 |
+
case '#_CONTACTID':
|
861 |
+
$replace = $this->contact->ID;
|
862 |
+
break;
|
863 |
+
case '#_CONTACTPHONE':
|
864 |
+
$replace = ( $this->contact->phone != '') ? $this->contact->phone : __('N/A', 'dbem');
|
865 |
+
break;
|
866 |
+
case '#_CONTACTAVATAR':
|
867 |
+
$replace = get_avatar( $this->contact->ID, $size = '50' );
|
868 |
+
break;
|
869 |
+
case '#_CONTACTPROFILELINK':
|
870 |
+
case '#_CONTACTPROFILEURL':
|
871 |
+
if( function_exists('bp_core_get_user_domain') ){
|
872 |
+
$replace = bp_core_get_user_domain($this->contact->ID);
|
873 |
+
if( $result == '#_CONTACTPROFILELINK' ){
|
874 |
+
$replace = '<a href="'.$replace.'">'.__('Profile').'</a>';
|
875 |
+
}
|
876 |
+
}
|
877 |
+
break;
|
878 |
+
case '#_CONTACTPROFILELINK':
|
879 |
+
case '#_CONTACTPROFILEURL':
|
880 |
+
if( function_exists('bp_core_get_user_domain') ){
|
881 |
+
$replace = bp_core_get_user_domain($this->contact->ID);
|
882 |
+
if( $result == '#_CONTACTPROFILELINK' ){
|
883 |
+
$replace = '<a href="'.$replace.'">'.__('Profile').'</a>';
|
884 |
+
}
|
885 |
+
}
|
886 |
+
break;
|
887 |
+
case '#_ATTENDEES':
|
888 |
+
ob_start();
|
889 |
+
$template = em_locate_template('placeholders/attendees.php', true, array('EM_Event'=>$this));
|
890 |
+
$replace = ob_get_clean();
|
891 |
+
break;
|
892 |
+
case '#_CATEGORIES':
|
893 |
+
ob_start();
|
894 |
+
$template = em_locate_template('placeholders/categories.php', true, array('EM_Event'=>$this));
|
895 |
+
$replace = ob_get_clean();
|
896 |
+
break;
|
897 |
+
default:
|
898 |
+
$replace = $result;
|
899 |
+
break;
|
900 |
+
}
|
901 |
+
$replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
|
902 |
+
$event_string = str_replace($result, $replace , $event_string );
|
903 |
+
}
|
904 |
+
//Time placeholders
|
905 |
+
foreach($placeholders[0] as $result) {
|
906 |
+
// matches all PHP START date and time placeholders
|
907 |
+
if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) {
|
908 |
+
$replace = date_i18n(ltrim($result, "#"), $this->start);
|
909 |
+
$replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
|
910 |
+
$event_string = str_replace($result, $replace, $event_string );
|
911 |
+
}
|
912 |
+
// matches all PHP END time placeholders for endtime
|
913 |
+
if (preg_match('/^#@[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) {
|
914 |
+
$replace = date_i18n(ltrim($result, "#@"), $this->end);
|
915 |
+
$replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
|
916 |
+
$event_string = str_replace($result, $replace, $event_string );
|
917 |
+
}
|
918 |
+
}
|
919 |
+
//Time place holder that doesn't show if empty.
|
920 |
+
//TODO add filter here too
|
921 |
+
preg_match_all('/#@?_\{[A-Za-z0-9 -\/,\.\\\]+\}/', $format, $results);
|
922 |
+
foreach($results[0] as $result) {
|
923 |
+
if(substr($result, 0, 3 ) == "#@_"){
|
924 |
+
$date = 'end_date';
|
925 |
+
$offset = 4;
|
926 |
+
}else{
|
927 |
+
$date = 'start_date';
|
928 |
+
$offset = 3;
|
929 |
+
}
|
930 |
+
if( $date == 'end_date' && $this->end_date == $this->start_date ){
|
931 |
+
$replace = __( apply_filters('em_event_output_placeholder', '', $this, $result, $target) );
|
932 |
+
}else{
|
933 |
+
$replace = __( apply_filters('em_event_output_placeholder', mysql2date(substr($result, $offset, (strlen($result)-($offset+1)) ), $this->$date), $this, $result, $target) );
|
934 |
+
}
|
935 |
+
$event_string = str_replace($result,$replace,$event_string );
|
936 |
+
}
|
937 |
+
//This is for the custom attributes
|
938 |
+
preg_match_all('/#_ATT\{([^}]+)\}(\{([^}]+)\})?/', $format, $results);
|
939 |
+
foreach($results[0] as $resultKey => $result) {
|
940 |
+
//Strip string of placeholder and just leave the reference
|
941 |
+
$attRef = substr( substr($result, 0, strpos($result, '}')), 6 );
|
942 |
+
$attString = '';
|
943 |
+
if( is_array($this->attributes) && array_key_exists($attRef, $this->attributes) ){
|
944 |
+
$attString = $this->attributes[$attRef];
|
945 |
+
}elseif( !empty($results[3][$resultKey]) ){
|
946 |
+
//Check to see if we have a second set of braces;
|
947 |
+
$attString = $results[3][$resultKey];
|
948 |
+
}
|
949 |
+
$attString = apply_filters('em_event_output_placeholder', $attString, $this, $result, $target);
|
950 |
+
$event_string = str_replace($result, $attString ,$event_string );
|
951 |
+
}
|
952 |
+
|
953 |
+
//Now do dependent objects
|
954 |
+
$event_string = $this->location->output($event_string, $target);
|
955 |
+
|
956 |
+
//for backwards compat and easy use, take over the individual category placeholders with the frirst cat in th elist.
|
957 |
+
$EM_Categories = $this->get_categories();
|
958 |
+
if( count($EM_Categories->categories) > 0 ){
|
959 |
+
$EM_Category = $EM_Categories->categories[0];
|
960 |
+
}
|
961 |
+
if( empty($EM_Category) ) $EM_Category = new EM_Category();
|
962 |
+
$event_string = $EM_Category->output($event_string, $target);
|
963 |
+
|
964 |
+
return apply_filters('em_event_output', $event_string, $this, $target);
|
965 |
+
}
|
966 |
+
|
967 |
+
/**********************************************************
|
968 |
+
* RECURRENCE METHODS
|
969 |
+
***********************************************************/
|
970 |
+
|
971 |
+
/**
|
972 |
+
* Saves events and replaces old ones. Returns true if sucecssful or false if not.
|
973 |
+
* @return boolean
|
974 |
+
*/
|
975 |
+
function save_events() {
|
976 |
+
if( $this->is_recurring() && $this->can_manage('edit_events','edit_others_events') ){
|
977 |
+
do_action('em_event_save_events_pre', $this); //actions/filters only run if event is recurring
|
978 |
+
global $wpdb;
|
979 |
+
$matching_days = $this->get_recurrence_days(); //Get days where events recur
|
980 |
+
$this->delete_events(); //Delete old events beforehand
|
981 |
+
//Make template event (and we just change dates)
|
982 |
+
$event = $this->to_array();
|
983 |
+
unset($event['event_id']); //remove id and we have a event template to feed to wpdb insert
|
984 |
+
unset($event['event_date_modified']);
|
985 |
+
$event['event_attributes'] = serialize($event['event_attributes']);
|
986 |
+
foreach($event as $key => $value ){ //remove recurrence information
|
987 |
+
if( substr($key, 0, 10) == 'recurrence' ){
|
988 |
+
unset($event[$key]);
|
989 |
+
}
|
990 |
+
}
|
991 |
+
$event['recurrence_id'] = $this->id;
|
992 |
+
//Save event template with different dates
|
993 |
+
$event_saves = array();
|
994 |
+
$event_ids = array();
|
995 |
+
if( count($matching_days) > 0 ){
|
996 |
+
foreach( $matching_days as $day ) {
|
997 |
+
$event['event_start_date'] = date("Y-m-d", $day);
|
998 |
+
$event['event_slug'] = $this->slug.'-'.$event['event_start_date'];
|
999 |
+
$event['event_end_date'] = $event['event_start_date'];
|
1000 |
+
$event_saves[] = $wpdb->insert(EM_EVENTS_TABLE, $event, $this->get_types($event));
|
1001 |
+
$event_ids[] = $wpdb->insert_id;
|
1002 |
+
//if( EM_DEBUG ){ echo "Entering recurrence " . date("D d M Y", $day)."<br/>"; }
|
1003 |
+
}
|
1004 |
+
//save bookings
|
1005 |
+
if( $this->rsvp ){
|
1006 |
+
$inserts = array();
|
1007 |
+
foreach($this->get_bookings()->get_tickets() as $EM_Ticket){
|
1008 |
+
/* @var $EM_Ticket EM_Ticket */
|
1009 |
+
//get array, modify event id and insert
|
1010 |
+
$ticket = $EM_Ticket->to_array();
|
1011 |
+
unset($ticket['ticket_id']);
|
1012 |
+
//clean up ticket values
|
1013 |
+
foreach($ticket as $k => $v){
|
1014 |
+
if( empty($v) && $k != 'ticket_name' ){
|
1015 |
+
$ticket[$k] = 'NULL';
|
1016 |
+
}else{
|
1017 |
+
$ticket[$k] = "'$v'";
|
1018 |
+
}
|
1019 |
+
}
|
1020 |
+
foreach($event_ids as $event_id){
|
1021 |
+
$ticket['event_id'] = $event_id;
|
1022 |
+
$inserts[] = "(".implode(",",$ticket).")";
|
1023 |
+
}
|
1024 |
+
}
|
1025 |
+
$keys = "(".implode(",",array_keys($ticket)).")";
|
1026 |
+
$values = implode(',',$inserts);
|
1027 |
+
$sql = "INSERT INTO ".EM_TICKETS_TABLE." $keys VALUES $values";
|
1028 |
+
$result = $wpdb->query($sql);
|
1029 |
+
}
|
1030 |
+
//save categories
|
1031 |
+
$category_ids = $this->get_categories()->get_ids();
|
1032 |
+
$inserts = array();
|
1033 |
+
foreach($event_ids as $event_id){
|
1034 |
+
//create the meta inserts for each event
|
1035 |
+
foreach($category_ids as $category_id){
|
1036 |
+
$inserts[] = "($event_id,'event-category', $category_id)";
|
1037 |
+
}
|
1038 |
+
}
|
1039 |
+
if( count($inserts) > 0 ){
|
1040 |
+
$result = $wpdb->query("INSERT INTO ".EM_META_TABLE." (object_id,meta_key,meta_value) VALUES ".implode(',',$inserts));
|
1041 |
+
if($result === false){
|
1042 |
+
$this->add_error('There was a problem adding categories to your recurring events.','dbem');
|
1043 |
+
}
|
1044 |
+
}
|
1045 |
+
}else{
|
1046 |
+
$this->add_error('You have not defined a date range long enough to create a recurrence.','dbem');
|
1047 |
+
$result = false;
|
1048 |
+
}
|
1049 |
+
return apply_filters('em_event_save_events', !in_array(false, $event_saves) && $result !== false, $this);
|
1050 |
+
}
|
1051 |
+
return apply_filters('em_event_save_events', false, $this);;
|
1052 |
+
}
|
1053 |
+
|
1054 |
+
/**
|
1055 |
+
* Removes all reoccurring events.
|
1056 |
+
* @param $recurrence_id
|
1057 |
+
* @return null
|
1058 |
+
*/
|
1059 |
+
function delete_events(){
|
1060 |
+
global $wpdb;
|
1061 |
+
do_action('em_event_delete_events_pre', $this);
|
1062 |
+
//So we don't do something we'll regret later, we could just supply the get directly into the delete, but this is safer
|
1063 |
+
$result = false;
|
1064 |
+
if( $this->can_manage('delete_events', 'delete_others_events') ){
|
1065 |
+
$EM_Events = EM_Events::get( array('recurrence_id'=>$this->id) );
|
1066 |
+
$event_ids = array();
|
1067 |
+
foreach($EM_Events as $EM_Event){
|
1068 |
+
if($EM_Event->recurrence_id == $this->id){
|
1069 |
+
$event_ids[] = $EM_Event->id; //ONLY ADD if id's match - hard coded
|
1070 |
+
}
|
1071 |
+
}
|
1072 |
+
$result = EM_Events::delete( $event_ids );
|
1073 |
+
}
|
1074 |
+
return apply_filters('delete_events', $result, $this);
|
1075 |
+
}
|
1076 |
+
|
1077 |
+
/**
|
1078 |
+
* Returns true if this event is a recurring event, meaning that it's not an individual event,
|
1079 |
+
* but an event that defines many events that recur over a span of time.
|
1080 |
+
* For checking if a specific event is part of a greater set of recurring events, use is_recurrence()
|
1081 |
+
* @return boolean
|
1082 |
+
*/
|
1083 |
+
function is_recurring(){
|
1084 |
+
return ( $this->recurrence );
|
1085 |
+
}
|
1086 |
+
/**
|
1087 |
+
* Will return true if this individual event is part of a set of events that recur
|
1088 |
+
* For checking if this is the "master recurring event", see is_recurring()
|
1089 |
+
* @return boolean
|
1090 |
+
*/
|
1091 |
+
function is_recurrence(){
|
1092 |
+
return ( $this->id > 0 && $this->recurrence_id > 0 );
|
1093 |
+
}
|
1094 |
+
/**
|
1095 |
+
* Returns if this is an individual event and is not recurring or a recurrence
|
1096 |
+
* @return boolean
|
1097 |
+
*/
|
1098 |
+
function is_individual(){
|
1099 |
+
return ( !$this->is_recurring() && !$this->is_recurrence() );
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
/**
|
1103 |
+
* Can the user manage this?
|
1104 |
+
*/
|
1105 |
+
function can_manage( $owner_capability = false, $admin_capability = false ){
|
1106 |
+
return apply_filters('em_event_can_manage', parent::can_manage($owner_capability, $admin_capability), $this);
|
1107 |
+
}
|
1108 |
+
|
1109 |
+
/**
|
1110 |
+
* Returns the days that match the recurrance array passed (unix timestamps)
|
1111 |
+
* @param array $recurrence
|
1112 |
+
* @return array
|
1113 |
+
*/
|
1114 |
+
function get_recurrence_days(){
|
1115 |
+
if( $this->is_recurring() ){
|
1116 |
+
|
1117 |
+
$start_date = strtotime($this->start_date);
|
1118 |
+
$end_date = strtotime($this->end_date);
|
1119 |
+
|
1120 |
+
$weekdays = explode(",", $this->byday); //what days of the week (or if monthly, one value at index 0)
|
1121 |
+
|
1122 |
+
$matching_days = array();
|
1123 |
+
$aDay = 86400; // a day in seconds
|
1124 |
+
$aWeek = $aDay * 7;
|
1125 |
+
|
1126 |
+
//TODO can this be optimized?
|
1127 |
+
switch ( $this->freq ){
|
1128 |
+
case 'daily':
|
1129 |
+
//If daily, it's simple. Get start date, add interval timestamps to that and create matching day for each interval until end date.
|
1130 |
+
$current_date = $start_date;
|
1131 |
+
while( $current_date <= $end_date ){
|
1132 |
+
$matching_days[] = $current_date;
|
1133 |
+
$current_date = $current_date + ($aDay * $this->interval);
|
1134 |
+
}
|
1135 |
+
break;
|
1136 |
+
case 'weekly':
|
1137 |
+
//sort out week one, get starting days and then days that match time span of event (i.e. remove past events in week 1)
|
1138 |
+
$start_of_week = get_option('start_of_week'); //Start of week depends on wordpress
|
1139 |
+
//first, get the start of this week as timestamp
|
1140 |
+
$event_start_day = date('w', $start_date);
|
1141 |
+
$offset = 0;
|
1142 |
+
if( $event_start_day > $start_of_week ){
|
1143 |
+
$offset = $event_start_day - $start_of_week; //x days backwards
|
1144 |
+
}elseif( $event_start_day < $start_of_week ){
|
1145 |
+
$offset = $start_of_week;
|
1146 |
+
}
|
1147 |
+
$start_week_date = $start_date - ( ($event_start_day - $start_of_week) * $aDay );
|
1148 |
+
//then get the timestamps of weekdays during this first week, regardless if within event range
|
1149 |
+
$start_weekday_dates = array(); //Days in week 1 where there would events, regardless of event date range
|
1150 |
+
for($i = 0; $i < 7; $i++){
|
1151 |
+
$weekday_date = $start_week_date+($aDay*$i); //the date of the weekday we're currently checking
|
1152 |
+
$weekday_day = date('w',$weekday_date); //the day of the week we're checking, taking into account wp start of week setting
|
1153 |
+
if( in_array( $weekday_day, $weekdays) ){
|
1154 |
+
$start_weekday_dates[] = $weekday_date; //it's in our starting week day, so add it
|
1155 |
+
}
|
1156 |
+
}
|
1157 |
+
//for each day of eventful days in week 1, add 7 days * weekly intervals
|
1158 |
+
foreach ($start_weekday_dates as $weekday_date){
|
1159 |
+
//Loop weeks by interval until we reach or surpass end date
|
1160 |
+
while($weekday_date <= $end_date){
|
1161 |
+
if( $weekday_date >= $start_date && $weekday_date <= $end_date ){
|
1162 |
+
$matching_days[] = $weekday_date;
|
1163 |
+
}
|
1164 |
+
$weekday_date = $weekday_date + ($aWeek * $this->interval);
|
1165 |
+
}
|
1166 |
+
}//done!
|
1167 |
+
break;
|
1168 |
+
case 'monthly':
|
1169 |
+
//loop months starting this month by intervals
|
1170 |
+
$current_arr = getdate($start_date);
|
1171 |
+
$end_arr = getdate($end_date);
|
1172 |
+
$end_month_date = strtotime( date('Y-m-t', $end_date) ); //End date on last day of month
|
1173 |
+
$current_date = strtotime( date('Y-m-1', $start_date) ); //Start date on first day of month
|
1174 |
+
while( $current_date <= $end_month_date ){
|
1175 |
+
$last_day_of_month = date('t', $current_date);
|
1176 |
+
//Now find which day we're talking about
|
1177 |
+
$current_week_day = date('w',$current_date);
|
1178 |
+
$matching_month_days = array();
|
1179 |
+
//Loop through days of this years month and save matching days to temp array
|
1180 |
+
for($day = 1; $day <= $last_day_of_month; $day++){
|
1181 |
+
if($current_week_day == $this->byday){
|
1182 |
+
$matching_month_days[] = $day;
|
1183 |
+
}
|
1184 |
+
$current_week_day = ($current_week_day < 6) ? $current_week_day+1 : 0;
|
1185 |
+
}
|
1186 |
+
//Now grab from the array the x day of the month
|
1187 |
+
$matching_day = ($this->byweekno > 0) ? $matching_month_days[$this->byweekno-1] : array_pop($matching_month_days);
|
1188 |
+
$matching_date = strtotime(date('Y-m',$current_date).'-'.$matching_day);
|
1189 |
+
if($matching_date >= $start_date && $matching_date <= $end_date){
|
1190 |
+
$matching_days[] = $matching_date;
|
1191 |
+
}
|
1192 |
+
//add the number of days in this month to make start of next month
|
1193 |
+
$current_arr['mon'] += $this->interval;
|
1194 |
+
if($current_arr['mon'] > 12){
|
1195 |
+
//FIXME this won't work if interval is more than 12
|
1196 |
+
$current_arr['mon'] = $current_arr['mon'] - 12;
|
1197 |
+
$current_arr['year']++;
|
1198 |
+
}
|
1199 |
+
$current_date = strtotime("{$current_arr['year']}-{$current_arr['mon']}-1");
|
1200 |
+
}
|
1201 |
+
break;
|
1202 |
+
}
|
1203 |
+
sort($matching_days);
|
1204 |
+
//TODO delete this after testing
|
1205 |
+
/*Delete*/
|
1206 |
+
$test_dates = array();
|
1207 |
+
foreach($matching_days as $matching_day){
|
1208 |
+
$test_dates[] = date('d/m/Y', $matching_day);
|
1209 |
+
}
|
1210 |
+
/*end delete*/
|
1211 |
+
return $matching_days;
|
1212 |
+
}
|
1213 |
+
}
|
1214 |
+
|
1215 |
+
function get_recurrence(){
|
1216 |
+
global $EM_Recurrences;
|
1217 |
+
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' ){
|
1218 |
+
$recurrence = $EM_Recurrences[$this->recurrence_id];
|
1219 |
+
}else{
|
1220 |
+
//get this recurrence
|
1221 |
+
$recurrence = new EM_Event($this->recurrence_id);
|
1222 |
+
$EM_Recurrences[$this->recurrence_id] = $recurrence;
|
1223 |
+
}
|
1224 |
+
return $recurrence;
|
1225 |
+
}
|
1226 |
+
|
1227 |
+
/**
|
1228 |
+
* Returns a string representation of this recurrence. Will return false if not a recurrence
|
1229 |
+
* @return string
|
1230 |
+
*/
|
1231 |
+
function get_recurrence_description() {
|
1232 |
+
if( $this->is_individual() ) return false;
|
1233 |
+
$recurrence = $this->get_recurrence()->to_array();
|
1234 |
+
$weekdays_name = array(__('Sunday'),__('Monday'),__('Tuesday'),__('Wednesday'),__('Thursday'),__('Friday'),__('Saturday'));
|
1235 |
+
$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'));
|
1236 |
+
$output = sprintf (__('From %1$s to %2$s', 'dbem'), $recurrence['event_start_date'], $recurrence['event_end_date']).", ";
|
1237 |
+
if ($recurrence['recurrence_freq'] == 'daily') {
|
1238 |
+
$freq_desc =__('everyday', 'dbem');
|
1239 |
+
if ($recurrence['recurrence_interval'] > 1 ) {
|
1240 |
+
$freq_desc = sprintf (__("every %s days", 'dbem'), $recurrence['recurrence_interval']);
|
1241 |
+
}
|
1242 |
+
}elseif ($recurrence['recurrence_freq'] == 'weekly') {
|
1243 |
+
$weekday_array = explode(",", $recurrence['recurrence_byday']);
|
1244 |
+
$natural_days = array();
|
1245 |
+
foreach($weekday_array as $day){
|
1246 |
+
array_push($natural_days, $weekdays_name[$day]);
|
1247 |
+
}
|
1248 |
+
$output .= implode(" and ", $natural_days);
|
1249 |
+
$freq_desc = ", " . __("every week", 'dbem');
|
1250 |
+
if ($recurrence['recurrence_interval'] > 1 ) {
|
1251 |
+
$freq_desc = ", ".sprintf (__("every %s weeks", 'dbem'), $recurrence['recurrence_interval']);
|
1252 |
+
}
|
1253 |
+
|
1254 |
+
}elseif ($recurrence['recurrence_freq'] == 'monthly') {
|
1255 |
+
$weekday_array = explode(",", $recurrence['recurrence_byday']);
|
1256 |
+
$natural_days = array();
|
1257 |
+
foreach($weekday_array as $day){
|
1258 |
+
array_push($natural_days, $weekdays_name[$day]);
|
1259 |
+
}
|
1260 |
+
$freq_desc = sprintf (($monthweek_name[$recurrence['recurrence_byweekno']]), implode(" and ", $natural_days));
|
1261 |
+
if ($recurrence['recurrence_interval'] > 1 ) {
|
1262 |
+
$freq_desc .= ", ".sprintf (__("every %s months",'dbem'), $recurrence['recurrence_interval']);
|
1263 |
+
}
|
1264 |
+
}else{
|
1265 |
+
$freq_desc = "[ERROR: corrupted database record]";
|
1266 |
+
}
|
1267 |
+
$output .= $freq_desc;
|
1268 |
+
return $output;
|
1269 |
+
}
|
1270 |
+
|
1271 |
+
/**********************************************************
|
1272 |
+
* UTILITIES
|
1273 |
+
***********************************************************/
|
1274 |
+
|
1275 |
+
/**
|
1276 |
+
* Returns this object in the form of an array, useful for saving directly into the wp_dbem_events table.
|
1277 |
+
* @param boolean $for_database
|
1278 |
+
* @return array
|
1279 |
+
*/
|
1280 |
+
function to_array($for_database = false){
|
1281 |
+
$event = array();
|
1282 |
+
//Core Event Data
|
1283 |
+
foreach ( $this->fields as $key => $val ) {
|
1284 |
+
//TODO does it matter if it's for db or not... shouldn't it just not include blanks?
|
1285 |
+
if( !$for_database || $for_database && $this->$val['name'] != '' ){
|
1286 |
+
$event[$key] = $this->$val['name'];
|
1287 |
+
}
|
1288 |
+
}
|
1289 |
+
return $event;
|
1290 |
+
}
|
1291 |
+
}
|
1292 |
+
|
1293 |
+
//TODO placeholder targets filtering could be streamlined better
|
1294 |
+
/**
|
1295 |
+
* This is a temporary filter function which mimicks the old filters in the old 2.x placeholders function
|
1296 |
+
* @param string $result
|
1297 |
+
* @param EM_Event $event
|
1298 |
+
* @param string $placeholder
|
1299 |
+
* @param string $target
|
1300 |
+
* @return mixed
|
1301 |
+
*/
|
1302 |
+
function em_event_output_placeholder($result,$event,$placeholder,$target='html'){
|
1303 |
+
if( ($placeholder == "#_EXCERPT" || $placeholder == "#_LOCATIONEXCERPT") && $target == 'html' ){
|
1304 |
+
$result = apply_filters('dbem_notes_excerpt', $result);
|
1305 |
+
}elseif( $placeholder == '#_CONTACTEMAIL' && $target == 'html' ){
|
1306 |
+
$result = em_ascii_encode($event->contact->user_email);
|
1307 |
+
}elseif( $placeholder == "#_NOTES" || $placeholder == "#_EXCERPT" || $placeholder == "#_LOCATIONEXCERPT" ){
|
1308 |
+
if($target == 'html'){
|
1309 |
+
$result = apply_filters('dbem_notes', $result);
|
1310 |
+
}elseif($target == 'map'){
|
1311 |
+
$result = apply_filters('dbem_notes_map', $result);
|
1312 |
+
}else{
|
1313 |
+
$result = apply_filters('dbem_notes_rss', $result);
|
1314 |
+
$result = apply_filters('the_content_rss', $result);
|
1315 |
+
}
|
1316 |
+
}elseif( in_array($placeholder, array("#_NAME",'#_ADDRESS','#_LOCATION','#_TOWN')) ){
|
1317 |
+
if ($target == "html"){
|
1318 |
+
$result = apply_filters('dbem_general', $result);
|
1319 |
+
}else{
|
1320 |
+
$result = apply_filters('dbem_general_rss', $result);
|
1321 |
+
}
|
1322 |
+
}
|
1323 |
+
return $result;
|
1324 |
+
}
|
1325 |
+
add_filter('em_event_output_placeholder','em_event_output_placeholder',1,4);
|
1326 |
?>
|
classes/em-events.php
CHANGED
@@ -1,254 +1,361 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
/**
|
9 |
-
*
|
10 |
-
*
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
//
|
57 |
-
$
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
";
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
//
|
74 |
-
$
|
75 |
-
$
|
76 |
-
|
77 |
-
$
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
$
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
$output =
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
'
|
238 |
-
|
239 |
-
if(
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
function EM_Events( $args = array() ){
|
15 |
+
if( is_array($args) ){
|
16 |
+
if( is_object(current($args)) && get_class(current($args)) == 'EM_Event' ){
|
17 |
+
$this->events = $args;
|
18 |
+
}else{
|
19 |
+
$this->events = EM_Events::get($args);
|
20 |
+
}
|
21 |
+
}else{
|
22 |
+
$this->events = EM_Events::get();
|
23 |
+
}
|
24 |
+
do_action('em_events',$this);
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Returns an array of EM_Events that match the given specs in the argument, or returns a list of future evetnts in future
|
29 |
+
* (see EM_Events::get_default_search() ) for explanation of possible search array values. You can also supply a numeric array
|
30 |
+
* containing the ids of the events you'd like to obtain
|
31 |
+
*
|
32 |
+
* @param array $args
|
33 |
+
* @return EM_Event array()
|
34 |
+
*/
|
35 |
+
function get( $args = array(), $count=false ) {
|
36 |
+
global $wpdb;
|
37 |
+
$events_table = EM_EVENTS_TABLE;
|
38 |
+
$locations_table = EM_LOCATIONS_TABLE;
|
39 |
+
|
40 |
+
//Quick version, we can accept an array of IDs, which is easy to retrieve
|
41 |
+
if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
|
42 |
+
//We can just get all the events here and return them
|
43 |
+
$sql = "
|
44 |
+
SELECT * FROM $events_table
|
45 |
+
LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
|
46 |
+
WHERE event_id=".implode(" OR event_id=", $args)."
|
47 |
+
";
|
48 |
+
$results = $wpdb->get_results(apply_filters('em_events_get_sql',$sql),ARRAY_A);
|
49 |
+
$events = array();
|
50 |
+
foreach($results as $result){
|
51 |
+
$events[$result['event_id']] = new EM_Event($result);
|
52 |
+
}
|
53 |
+
return $events; //We return all the events matched as an EM_Event array.
|
54 |
+
}
|
55 |
+
|
56 |
+
//We assume it's either an empty array or array of search arguments to merge with defaults
|
57 |
+
$args = self::get_default_search($args);
|
58 |
+
$limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
|
59 |
+
$offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
|
60 |
+
|
61 |
+
//Get the default conditions
|
62 |
+
$conditions = self::build_sql_conditions($args);
|
63 |
+
//Put it all together
|
64 |
+
$where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
|
65 |
+
|
66 |
+
//Get ordering instructions
|
67 |
+
$EM_Event = new EM_Event();
|
68 |
+
$accepted_fields = $EM_Event->get_fields(true);
|
69 |
+
$orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order'));
|
70 |
+
//Now, build orderby sql
|
71 |
+
$orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
|
72 |
+
|
73 |
+
//Create the SQL statement and execute
|
74 |
+
$selectors = ( $count ) ? 'COUNT(*)':'*';
|
75 |
+
$sql = "
|
76 |
+
SELECT $selectors FROM $events_table
|
77 |
+
LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id
|
78 |
+
$where
|
79 |
+
$orderby_sql
|
80 |
+
$limit $offset
|
81 |
+
";
|
82 |
+
|
83 |
+
//If we're only counting results, return the number of results
|
84 |
+
if( $count ){
|
85 |
+
return $wpdb->get_var($sql);
|
86 |
+
}
|
87 |
+
$results = $wpdb->get_results( apply_filters('em_events_get_sql',$sql, $args), ARRAY_A);
|
88 |
+
|
89 |
+
//If we want results directly in an array, why not have a shortcut here?
|
90 |
+
if( $args['array'] == true ){
|
91 |
+
return $results;
|
92 |
+
}
|
93 |
+
|
94 |
+
//Make returned results EM_Event objects
|
95 |
+
$results = (is_array($results)) ? $results:array();
|
96 |
+
$events = array();
|
97 |
+
foreach ( $results as $event ){
|
98 |
+
$events[] = new EM_Event($event);
|
99 |
+
}
|
100 |
+
|
101 |
+
return apply_filters('em_events_get', $events, $args);
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Returns the number of events on a given date
|
106 |
+
* @param $date
|
107 |
+
* @return int
|
108 |
+
*/
|
109 |
+
function count_date($date){
|
110 |
+
global $wpdb;
|
111 |
+
$table_name = EM_EVENTS_TABLE;
|
112 |
+
$sql = "SELECT COUNT(*) FROM $table_name WHERE (event_start_date like '$date') OR (event_start_date <= '$date' AND event_end_date >= '$date');";
|
113 |
+
return apply_filters('em_events_count_date', $wpdb->get_var($sql));
|
114 |
+
}
|
115 |
+
|
116 |
+
function count( $args = array() ){
|
117 |
+
return apply_filters('em_events_count', self::get($args, true), $args);
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Will delete given an array of event_ids or EM_Event objects
|
122 |
+
* @param unknown_type $id_array
|
123 |
+
*/
|
124 |
+
function delete( $array ){
|
125 |
+
//TODO add better cap checks in bulk actions
|
126 |
+
global $wpdb;
|
127 |
+
//Detect array type and generate SQL for event IDs
|
128 |
+
$event_ids = array();
|
129 |
+
if( @get_class(current($array)) == 'EM_Event' ){
|
130 |
+
foreach($array as $EM_Event){
|
131 |
+
$event_ids[] = $EM_Event->id;
|
132 |
+
}
|
133 |
+
}else{
|
134 |
+
$event_ids = $array;
|
135 |
+
}
|
136 |
+
if(self::array_is_numeric($event_ids)){
|
137 |
+
//First we have to check that they're all deletable by this user.
|
138 |
+
if ( self::can_manage($event_ids) ) {
|
139 |
+
apply_filters('em_events_delete_pre', $event_ids);
|
140 |
+
$condition = "event_id IN (". implode(',',$event_ids).")";
|
141 |
+
//Delete all tickets bookings
|
142 |
+
$result_tickets_bookings = $wpdb->query("DELETE FROM ".EM_TICKETS_BOOKINGS_TABLE." WHERE booking_id IN (SELECT booking_id FROM ". EM_BOOKINGS_TABLE ." WHERE $condition)");
|
143 |
+
//Delete all tickets
|
144 |
+
$result_tickets = $wpdb->query("DELETE FROM ". EM_TICKETS_TABLE ." WHERE $condition;");
|
145 |
+
//Delete all the bookings
|
146 |
+
$result_bookings = $wpdb->query("DELETE FROM ". EM_BOOKINGS_TABLE ." WHERE $condition;");
|
147 |
+
//Now delete the events
|
148 |
+
$result_events = $wpdb->query ( "DELETE FROM ". EM_EVENTS_TABLE ." WHERE $condition;" );
|
149 |
+
//delete category links
|
150 |
+
$result_categories = $wpdb->query('DELETE FROM '.EM_META_TABLE." WHERE meta_key='event-category' AND object_id IN (".implode(',', $event_ids).")");
|
151 |
+
return apply_filters('em_events_delete', true, $event_ids);
|
152 |
+
}else{
|
153 |
+
return apply_filters('em_events_delete', true, $event_ids);
|
154 |
+
}
|
155 |
+
}
|
156 |
+
//TODO add better error feedback on events delete fails
|
157 |
+
return apply_filters('em_events_delete', true, $event_ids);
|
158 |
+
}
|
159 |
+
|
160 |
+
|
161 |
+
/**
|
162 |
+
* 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.
|
163 |
+
* Note that you can pass a 'pagination' boolean attribute to enable pagination, default is enabled (true).
|
164 |
+
* @param array $args
|
165 |
+
* @param array $secondary_args
|
166 |
+
* @return string
|
167 |
+
*/
|
168 |
+
function output( $args ){
|
169 |
+
global $EM_Event;
|
170 |
+
$EM_Event_old = $EM_Event; //When looping, we can replace EM_Event global with the current event in the loop
|
171 |
+
//Can be either an array for the get search or an array of EM_Event objects
|
172 |
+
$func_args = func_get_args();
|
173 |
+
if( is_object(current($args)) && get_class((current($args))) == 'EM_Event' ){
|
174 |
+
$func_args = func_get_args();
|
175 |
+
$events = $func_args[0];
|
176 |
+
$args = (!empty($func_args[1]) && is_array($func_args[1])) ? $func_args[1] : array();
|
177 |
+
$args = apply_filters('em_events_output_args', self::get_default_search($args), $events);
|
178 |
+
$limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
|
179 |
+
$offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
|
180 |
+
$page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
|
181 |
+
}else{
|
182 |
+
//Firstly, let's check for a limit/offset here, because if there is we need to remove it and manually do this
|
183 |
+
$args = apply_filters('em_events_output_args', self::get_default_search($args) );
|
184 |
+
$limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
|
185 |
+
$offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
|
186 |
+
$page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
|
187 |
+
$args['limit'] = false;
|
188 |
+
$args['offset'] = false;
|
189 |
+
$args['page'] = false;
|
190 |
+
$events = self::get( $args );
|
191 |
+
}
|
192 |
+
//What format shall we output this to, or use default
|
193 |
+
$format = ( empty($args['format']) ) ? get_option( 'dbem_event_list_item_format' ) : $args['format'] ;
|
194 |
+
|
195 |
+
$output = "";
|
196 |
+
$events = apply_filters('em_events_output_events', $events);
|
197 |
+
$events_count = count($events);
|
198 |
+
if ( $events_count > 0 ) {
|
199 |
+
$event_count = 0;
|
200 |
+
$events_shown = 0;
|
201 |
+
foreach ( $events as $EM_Event ) {
|
202 |
+
if( ($events_shown < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ){
|
203 |
+
$output .= $EM_Event->output($format);
|
204 |
+
$events_shown++;
|
205 |
+
}
|
206 |
+
$event_count++;
|
207 |
+
}
|
208 |
+
//Add headers and footers to output
|
209 |
+
if( $format == get_option ( 'dbem_event_list_item_format' ) ){
|
210 |
+
$format_header = ( get_option( 'dbem_event_list_item_format_header') == '' ) ? '':get_option ( 'dbem_event_list_item_format_header' );
|
211 |
+
$format_footer = ( get_option ( 'dbem_event_list_item_format_footer' ) == '' ) ? '':get_option ( 'dbem_event_list_item_format_footer' );
|
212 |
+
}else{
|
213 |
+
$format_header = ( !empty($args['format_header']) ) ? $args['format_header']:'';
|
214 |
+
$format_footer = ( !empty($args['format_footer']) ) ? $args['format_footer']:'';
|
215 |
+
}
|
216 |
+
$output = $format_header . $output . $format_footer;
|
217 |
+
//Pagination (if needed/requested)
|
218 |
+
if( !empty($args['pagination']) && !empty($limit) && $events_count > $limit ){
|
219 |
+
//Show the pagination links (unless there's less than $limit events)
|
220 |
+
$page_link_template = preg_replace('/(&|\?)page=\d+/i','',$_SERVER['REQUEST_URI']);
|
221 |
+
$page_link_template = em_add_get_params($page_link_template, array('page'=>'%PAGE%'));
|
222 |
+
$output .= apply_filters('em_events_output_pagination', em_paginate( $page_link_template, $events_count, $limit, $page), $page_link_template, $events_count, $limit, $page);
|
223 |
+
}
|
224 |
+
} else {
|
225 |
+
$output = get_option ( 'dbem_no_events_message' );
|
226 |
+
}
|
227 |
+
|
228 |
+
//TODO check if reference is ok when restoring object, due to changes in php5 v 4
|
229 |
+
$EM_Event = $EM_Event_old;
|
230 |
+
$output = apply_filters('em_events_output', $output, $events, $args);
|
231 |
+
return $output;
|
232 |
+
}
|
233 |
+
|
234 |
+
function can_manage($event_ids){
|
235 |
+
global $wpdb;
|
236 |
+
if( current_user_can('edit_others_events') ){
|
237 |
+
return apply_filters('em_events_can_manage', true, $event_ids);
|
238 |
+
}
|
239 |
+
if( EM_Object::array_is_numeric($event_ids) ){
|
240 |
+
$condition = implode(" OR event_id=", $event_ids);
|
241 |
+
//we try to find any of these events that don't belong to this user
|
242 |
+
$results = $wpdb->get_var("SELECT COUNT(*) FROM ". EM_BOOKINGS_TABLE ." WHERE event_owner != '". get_current_user_id() ."' event_id=$condition;");
|
243 |
+
return apply_filters('em_events_can_manage', ($results == 0), $event_ids);
|
244 |
+
}
|
245 |
+
return apply_filters('em_events_can_manage', false, $event_ids);
|
246 |
+
}
|
247 |
+
|
248 |
+
function get_post_search($args = array()){
|
249 |
+
$accepted_searches = apply_filters('em_accepted_searches', array('scope','search','category','country','state','region','town'), $args);
|
250 |
+
foreach($_REQUEST as $post_key => $post_value){
|
251 |
+
if( in_array($post_key, $accepted_searches) && !empty($post_value) ){
|
252 |
+
if(is_array($post_value)){
|
253 |
+
$post_value = implode(',',$post_value);
|
254 |
+
}
|
255 |
+
if($post_value != ',' ){
|
256 |
+
$args[$post_key] = $post_value;
|
257 |
+
}
|
258 |
+
}
|
259 |
+
}
|
260 |
+
return $args;
|
261 |
+
}
|
262 |
+
|
263 |
+
/* Overrides EM_Object method to apply a filter to result
|
264 |
+
* @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
|
265 |
+
*/
|
266 |
+
function build_sql_conditions( $args = array() ){
|
267 |
+
$conditions = parent::build_sql_conditions($args);
|
268 |
+
if( !empty($args['search']) ){
|
269 |
+
$like_search = array('event_name','event_notes','location_name','location_address','location_town','location_postcode','location_state','location_country');
|
270 |
+
$conditions['search'] = "(".implode(" LIKE '%{$args['search']}%' OR ", $like_search). " LIKE '%{$args['search']}%')";
|
271 |
+
}
|
272 |
+
if( array_key_exists('status',$args) && is_numeric($args['status']) ){
|
273 |
+
$null = ($args['status'] == 0) ? ' OR `event_status` IS NULL':'';
|
274 |
+
$conditions['status'] = "(`event_status`={$args['status']}{$null} )";
|
275 |
+
}
|
276 |
+
if( is_multisite() && array_key_exists('blog',$args) && is_numeric($args['blog']) ){
|
277 |
+
if( is_main_site($args['blog']) ){
|
278 |
+
$conditions['blog'] = "(`blog_id`={$args['blog']} OR blog_id IS NULL)";
|
279 |
+
}else{
|
280 |
+
$conditions['blog'] = "(`blog_id`={$args['blog']})";
|
281 |
+
}
|
282 |
+
}
|
283 |
+
return apply_filters( 'em_events_build_sql_conditions', $conditions, $args );
|
284 |
+
}
|
285 |
+
|
286 |
+
/* Overrides EM_Object method to apply a filter to result
|
287 |
+
* @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
|
288 |
+
*/
|
289 |
+
function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
|
290 |
+
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 );
|
291 |
+
}
|
292 |
+
|
293 |
+
/*
|
294 |
+
* Adds custom Events search defaults
|
295 |
+
* @param array $array
|
296 |
+
* @return array
|
297 |
+
* @uses EM_Object#get_default_search()
|
298 |
+
*/
|
299 |
+
function get_default_search( $array = array() ){
|
300 |
+
$defaults = array(
|
301 |
+
'orderby' => get_option('dbem_events_default_orderby'),
|
302 |
+
'order' => get_option('dbem_events_default_order'),
|
303 |
+
'rsvp' => false, //if set to true, only events with bookings enabled are returned
|
304 |
+
'status' => 1, //approved events only
|
305 |
+
'format_header' => '', //events can have custom html above the list
|
306 |
+
'format_footer' => '', //events can have custom html below the list
|
307 |
+
'town' => false,
|
308 |
+
'state' => false,
|
309 |
+
'country' => false,
|
310 |
+
'region' => false,
|
311 |
+
'blog' => get_current_blog_id(),
|
312 |
+
);
|
313 |
+
if(is_multisite()){
|
314 |
+
global $bp;
|
315 |
+
//echo "<pre>"; print_r($bp); echo "</pre>";
|
316 |
+
if( !empty($bp->current_component) && $bp->current_component == 'events' && !empty($bp->current_action)){
|
317 |
+
$array['blog'] = false; //This is the buddypress root blog so we also show all event data
|
318 |
+
}elseif( !is_main_site() ){
|
319 |
+
//not the main blog, force single blog search
|
320 |
+
$array['blog'] = get_current_blog_id();
|
321 |
+
}elseif( empty($array['blog']) && get_site_option('dbem_ms_global_events') ) {
|
322 |
+
$array['blog'] = false;
|
323 |
+
}
|
324 |
+
}
|
325 |
+
if( is_admin() ){
|
326 |
+
//figure out default owning permissions
|
327 |
+
$defaults['owner'] = !current_user_can('edit_others_events') ? get_current_user_id() : false;
|
328 |
+
if( !array_key_exists('status', $array) && current_user_can('edit_others_events') ){
|
329 |
+
$defaults['status'] = false; //by default, admins see pending and live events
|
330 |
+
}
|
331 |
+
}
|
332 |
+
return apply_filters('em_events_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
|
333 |
+
}
|
334 |
+
|
335 |
+
//TODO Implement object and interators for handling groups of events.
|
336 |
+
public function rewind(){
|
337 |
+
reset($this->events);
|
338 |
+
}
|
339 |
+
|
340 |
+
public function current(){
|
341 |
+
$var = current($this->events);
|
342 |
+
return $var;
|
343 |
+
}
|
344 |
+
|
345 |
+
public function key(){
|
346 |
+
$var = key($this->events);
|
347 |
+
return $var;
|
348 |
+
}
|
349 |
+
|
350 |
+
public function next(){
|
351 |
+
$var = next($this->events);
|
352 |
+
return $var;
|
353 |
+
}
|
354 |
+
|
355 |
+
public function valid(){
|
356 |
+
$key = key($this->events);
|
357 |
+
$var = ($key !== NULL && $key !== FALSE);
|
358 |
+
return $var;
|
359 |
+
}
|
360 |
+
}
|
361 |
?>
|
classes/em-location.php
CHANGED
@@ -1,307 +1,368 @@
|
|
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 $
|
10 |
-
var $
|
11 |
-
var $
|
12 |
-
var $
|
13 |
-
var $
|
14 |
-
var $
|
15 |
-
var $
|
16 |
-
var $
|
17 |
-
|
18 |
-
var $
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
'
|
25 |
-
'
|
26 |
-
'
|
27 |
-
'
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
//
|
53 |
-
if(
|
54 |
-
$location
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
$
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
$
|
88 |
-
}
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
$
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
$
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
$
|
123 |
-
$
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
$
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
case '#
|
255 |
-
|
256 |
-
|
257 |
-
case '#
|
258 |
-
case '#
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
$
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
break;
|
272 |
-
case '#
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
break;
|
278 |
-
case '#
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
$replace = $this->
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
$replace = $this->
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 $region = '';
|
16 |
+
var $country = '';
|
17 |
+
var $latitude = '';
|
18 |
+
var $longitude = '';
|
19 |
+
var $description = '';
|
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_region' => array('name'=>'region','type'=>'%s'),
|
31 |
+
'location_country' => array('name'=>'country','type'=>'%s'),
|
32 |
+
'location_latitude' => array('name'=>'latitude','type'=>'%f'),
|
33 |
+
'location_longitude' => array('name'=>'longitude','type'=>'%f'),
|
34 |
+
'location_description' => array('name'=>'description','type'=>'%s'),
|
35 |
+
'location_owner' => array('name'=>'owner','type'=>'%d')
|
36 |
+
);
|
37 |
+
var $image_url = '';
|
38 |
+
var $required_fields = array();
|
39 |
+
var $feedback_message = "";
|
40 |
+
var $mime_types = array(1 => 'gif', 2 => 'jpg', 3 => 'png');
|
41 |
+
var $errors = array();
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Gets data from POST (default), supplied array, or from the database if an ID is supplied
|
45 |
+
* @param $location_data
|
46 |
+
* @return null
|
47 |
+
*/
|
48 |
+
function EM_Location( $location_data = 0 ) {
|
49 |
+
//Initialize
|
50 |
+
$this->required_fields = array("name" => __('The location name', 'dbem'), "address" => __('The location address', 'dbem'), "town" => __('The location town', 'dbem'), "country" => __('The country', 'dbem'),);
|
51 |
+
if( !empty($location_data) ){
|
52 |
+
//Load location data
|
53 |
+
if( is_array($location_data) && isset($location_data['location_name']) ){
|
54 |
+
$location = $location_data;
|
55 |
+
}elseif( !empty($location_data) ){
|
56 |
+
//Retreiving from the database
|
57 |
+
global $wpdb;
|
58 |
+
if( is_numeric($location_data) ){
|
59 |
+
$sql = "SELECT * FROM ". EM_LOCATIONS_TABLE ." WHERE location_id ='{$location_data}'";
|
60 |
+
$location = $wpdb->get_row($sql, ARRAY_A);
|
61 |
+
}else{
|
62 |
+
$sql = "SELECT * FROM ". EM_LOCATIONS_TABLE ." WHERE location_slug ='{$location_data}'";
|
63 |
+
$location = $wpdb->get_row($sql, ARRAY_A);
|
64 |
+
}
|
65 |
+
}
|
66 |
+
//If gmap is turned off, values may not be returned and set, so we set it here
|
67 |
+
if(empty($location['location_latitude'])) {
|
68 |
+
$location['location_latitude'] = 0;
|
69 |
+
$location['location_longitude'] = 0;
|
70 |
+
}
|
71 |
+
//Save into the object
|
72 |
+
$this->to_object($location, true);
|
73 |
+
$this->get_image_url();
|
74 |
+
add_filter('em_location_save',array(&$this,'image_upload'),1,2);
|
75 |
+
}
|
76 |
+
do_action('em_location', $this, $location_data);
|
77 |
+
}
|
78 |
+
|
79 |
+
function get_post(){
|
80 |
+
//We are getting the values via POST or GET
|
81 |
+
do_action('em_location_get_post_pre', $this);
|
82 |
+
$location = array();
|
83 |
+
$location['location_id'] = ( !empty($_POST['location_id']) ) ? $_POST['location_id']:'';
|
84 |
+
$location['location_name'] = ( !empty($_POST['location_name']) ) ? stripslashes($_POST['location_name']):'';
|
85 |
+
$location['location_slug'] = ( !empty($_POST['location_slug']) ) ? sanitize_title($_POST['location_slug']) : '' ;
|
86 |
+
if( current_user_can('edit_others_events') ){
|
87 |
+
$location['location_owner'] = ( !empty($_POST['location_owner']) && is_numeric($_POST['location_owner']) ) ? $_POST['location_owner']:'';
|
88 |
+
}
|
89 |
+
$location['location_address'] = ( !empty($_POST['location_address']) ) ? stripslashes($_POST['location_address']):'';
|
90 |
+
$location['location_town'] = ( !empty($_POST['location_town']) ) ? stripslashes($_POST['location_town']):'';
|
91 |
+
$location['location_state'] = ( !empty($_POST['location_state']) ) ? stripslashes($_POST['location_state']):'';
|
92 |
+
$location['location_postcode'] = ( !empty($_POST['location_postcode']) ) ? stripslashes($_POST['location_postcode']):'';
|
93 |
+
$location['location_region'] = ( !empty($_POST['location_region']) ) ? stripslashes($_POST['location_region']):'';
|
94 |
+
$location['location_country'] = ( !empty($_POST['location_country']) ) ? stripslashes($_POST['location_country']):'';
|
95 |
+
$location['location_latitude'] = ( !empty($_POST['location_latitude']) ) ? $_POST['location_latitude']:'';
|
96 |
+
$location['location_longitude'] = ( !empty($_POST['location_longitude']) ) ? $_POST['location_longitude']:'';
|
97 |
+
$location['location_description'] = ( !empty($_POST['content']) ) ? stripslashes($_POST['content']):'';
|
98 |
+
$this->to_object( apply_filters('em_location_get_post', $location, $this) );
|
99 |
+
return apply_filters('em_location_get_post',$this->validate(),$this);
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Validates the location. Should be run during any form submission or saving operation.
|
104 |
+
* @return boolean
|
105 |
+
*/
|
106 |
+
function validate(){
|
107 |
+
//check required fields
|
108 |
+
foreach ( $this->required_fields as $field => $description) {
|
109 |
+
if( $field == 'country' && !array_key_exists($this->country, em_get_countries()) ){
|
110 |
+
//country specific checking
|
111 |
+
$this->add_error( $this->required_fields['country'].__(" is required.", "dbem") );
|
112 |
+
}elseif ( $this->$field == "" ) {
|
113 |
+
$this->add_error( $description.__(" is required.", "dbem") );
|
114 |
+
}
|
115 |
+
}
|
116 |
+
$this->image_validate();
|
117 |
+
return apply_filters('em_location_validate', ( count($this->errors) == 0 ), $this);
|
118 |
+
}
|
119 |
+
|
120 |
+
function save(){
|
121 |
+
global $wpdb, $current_user;
|
122 |
+
$table = EM_LOCATIONS_TABLE;
|
123 |
+
if( $this->validate() ){
|
124 |
+
if( $this->can_manage('edit_locations','edit_others_locations') ){
|
125 |
+
//owner person can be anyone the admin wants, but the creator if not.
|
126 |
+
if( current_user_can('edit_others_events') ){
|
127 |
+
$this->owner = ( $this->owner > 0 ) ? $this->owner:0;
|
128 |
+
}else{
|
129 |
+
//force user id - user is either editing a location or making a new one, as can_manage checks ownership too.
|
130 |
+
$this->owner = get_current_user_id();
|
131 |
+
}
|
132 |
+
get_currentuserinfo();
|
133 |
+
do_action('em_location_save_pre', $this);
|
134 |
+
$this->slug = $this->sanitize_title();
|
135 |
+
$data = $this->to_array();
|
136 |
+
unset($data['location_id']);
|
137 |
+
unset($data['location_image_url']);
|
138 |
+
if($this->id != ''){
|
139 |
+
$where = array( 'location_id' => $this->id );
|
140 |
+
$result = $wpdb->update($table, $data, $where, $this->get_types($data));
|
141 |
+
if( $result !== false ){
|
142 |
+
$this->feedback_message = sprintf(__('%s successfully updated.', 'dbem'), __('Location','dbem'));
|
143 |
+
}else{
|
144 |
+
$this->add_error( sprintf(__('Could not save the %s details due to a database error.', 'dbem'),__('location','dbem') ));
|
145 |
+
}
|
146 |
+
}else{
|
147 |
+
$result = $wpdb->insert($table, $data, $this->get_types($data));
|
148 |
+
$this->id = $wpdb->insert_id;
|
149 |
+
if( $result !== false ){
|
150 |
+
$this->feedback_message = sprintf(__('%s successfully added.', 'dbem'), __('Location','dbem'));
|
151 |
+
}else{
|
152 |
+
$this->add_error( sprintf(__('Could not save the %s details due to a database error.', 'dbem'),__('location','dbem') ));
|
153 |
+
}
|
154 |
+
}
|
155 |
+
return apply_filters('em_location_save', ( $this->id > 0 && count($this->errors) == 0 ), $this);
|
156 |
+
}else{
|
157 |
+
$this->add_error( sprintf(__('You do not have permission to create/edit %s.','dbem'), __('locations','dbem')) );
|
158 |
+
}
|
159 |
+
}
|
160 |
+
return apply_filters('em_location_save', false, $this, false);
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Takes the title and gives either a unique slug or returns the currently used slug if this record already has it.
|
165 |
+
* @param unknown_type $title
|
166 |
+
*/
|
167 |
+
function sanitize_title($iteration = 1){
|
168 |
+
global $wpdb;
|
169 |
+
//Generate the slug. If this is a new event, create the slug automatically, if not, verify it is still unique and if not rewrite
|
170 |
+
if( empty($this->slug) ){
|
171 |
+
$this->slug = sanitize_title($this->name);
|
172 |
+
}
|
173 |
+
$slug = $this->slug;
|
174 |
+
$slug_matches = $wpdb->get_results('SELECT location_id FROM '.EM_LOCATIONS_TABLE." WHERE location_slug='{$slug}'", ARRAY_A);
|
175 |
+
if( count($slug_matches) > 0 ){ //we will check that the slug is unique
|
176 |
+
if( $slug_matches[0]['location_id'] != $this->id || count($slug_matches) > 1 ){
|
177 |
+
//we have a conflict, so try another alternative
|
178 |
+
$this->slug = preg_replace('/\-[0-9]+$/', '', $slug).'-'.($iteration+1);
|
179 |
+
$this->sanitize_title($iteration+1);
|
180 |
+
}
|
181 |
+
}
|
182 |
+
return apply_filters('em_location_sanitize_title', $this->slug, $this);
|
183 |
+
}
|
184 |
+
|
185 |
+
function delete(){
|
186 |
+
global $wpdb;
|
187 |
+
if( current_user_can('delete_locations') ){
|
188 |
+
do_action('em_location_delete_pre', $this);
|
189 |
+
$table_name = EM_LOCATIONS_TABLE;
|
190 |
+
$sql = "DELETE FROM $table_name WHERE location_id = '{$this->id}';";
|
191 |
+
$result = $wpdb->query($sql);
|
192 |
+
$result = $this->image_delete() && $result;
|
193 |
+
if( $result ){
|
194 |
+
$this->feedback_message = sprintf(__('%s successfully deleted.', 'dbem'), __('Location','dbem')) ;
|
195 |
+
}else{
|
196 |
+
$this->add_error( sprintf(__('%s could not be deleted.', 'dbem'), __('Location','dbem')) );
|
197 |
+
}
|
198 |
+
}else{
|
199 |
+
$this->add_error( sprintf(__('You do not have permission to delete %s.','dbem'), __('locations','dbem')) );
|
200 |
+
$result = false;
|
201 |
+
}
|
202 |
+
return apply_filters('em_location_delete', $result, $this);
|
203 |
+
}
|
204 |
+
|
205 |
+
function load_similar($criteria){
|
206 |
+
global $wpdb;
|
207 |
+
if( !empty($criteria['location_name']) && !empty($criteria['location_name']) && !empty($criteria['location_name']) ){
|
208 |
+
$locations_table = EM_LOCATIONS_TABLE;
|
209 |
+
$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']) );
|
210 |
+
//$wpdb->show_errors(true);
|
211 |
+
$location = $wpdb->get_row($prepared_sql, ARRAY_A);
|
212 |
+
if( is_array($location) ){
|
213 |
+
$this->to_object($location);
|
214 |
+
}
|
215 |
+
return apply_filters('em_location_load_similar', $location, $this);
|
216 |
+
}
|
217 |
+
return apply_filters('em_location_load_similar', false, $this);
|
218 |
+
}
|
219 |
+
|
220 |
+
function has_events(){
|
221 |
+
global $wpdb;
|
222 |
+
$events_table = EM_EVENTS_TABLE;
|
223 |
+
$sql = "SELECT count(event_id) as events_no FROM $events_table WHERE location_id = {$this->id}";
|
224 |
+
$affected_events = $wpdb->get_row($sql);
|
225 |
+
return apply_filters('em_location_has_events', (count($affected_events) > 0), $this);
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Can the user manage this location?
|
230 |
+
*/
|
231 |
+
function can_manage( $owner_capability = false, $admin_capability = false ){
|
232 |
+
return apply_filters('em_location_can_manage', parent::can_manage($owner_capability, $admin_capability), $this);
|
233 |
+
}
|
234 |
+
|
235 |
+
function output_single($target = 'html'){
|
236 |
+
$format = get_option ( 'dbem_single_location_format' );
|
237 |
+
return apply_filters('em_location_output_single', $this->output($format, $target), $this, $target);
|
238 |
+
}
|
239 |
+
|
240 |
+
function output($format, $target="html") {
|
241 |
+
preg_match_all('/\{([a-zA-Z0-9_]+)\}([^{]+)\{\/[a-zA-Z0-9_]+\}/', $format, $conditionals);
|
242 |
+
if( count($conditionals[0]) > 0 ){
|
243 |
+
//Check if the language we want exists, if not we take the first language there
|
244 |
+
foreach($conditionals[1] as $key => $condition){
|
245 |
+
$format = str_replace($conditionals[0][$key], apply_filters('em_location_output_condition', '', $conditionals[0][$key], $condition, $this), $format);
|
246 |
+
}
|
247 |
+
}
|
248 |
+
$location_string = $format;
|
249 |
+
preg_match_all("/#_[A-Za-z]+/", $format, $placeholders);
|
250 |
+
foreach($placeholders[0] as $result) {
|
251 |
+
$match = true;
|
252 |
+
$replace = '';
|
253 |
+
switch( $result ){
|
254 |
+
case '#_LOCATIONID':
|
255 |
+
$replace = $this->id;
|
256 |
+
break;
|
257 |
+
case '#_NAME': //Depreciated
|
258 |
+
case '#_LOCATIONNAME':
|
259 |
+
$replace = $this->name;
|
260 |
+
break;
|
261 |
+
case '#_ADDRESS': //Depreciated
|
262 |
+
case '#_LOCATIONADDRESS':
|
263 |
+
$replace = $this->address;
|
264 |
+
break;
|
265 |
+
case '#_TOWN': //Depreciated
|
266 |
+
case '#_LOCATIONTOWN':
|
267 |
+
$replace = $this->town;
|
268 |
+
break;
|
269 |
+
case '#_LOCATIONSTATE':
|
270 |
+
$replace = $this->state;
|
271 |
+
break;
|
272 |
+
case '#_LOCATIONPOSTCODE':
|
273 |
+
$replace = $this->postcode;
|
274 |
+
break;
|
275 |
+
case '#_LOCATIONREGION':
|
276 |
+
$replace = $this->region;
|
277 |
+
break;
|
278 |
+
case '#_LOCATIONCOUNTRY':
|
279 |
+
$replace = $this->get_country();
|
280 |
+
break;
|
281 |
+
case '#_LOCATIONFULLLINE':
|
282 |
+
$replace = $this->address.', ';
|
283 |
+
$replace = empty($this->town) ? '':', '.$this->town;
|
284 |
+
$replace = empty($this->state) ? '':', '.$this->state;
|
285 |
+
$replace = empty($this->postcode) ? '':', '.$this->postcode;
|
286 |
+
$replace = empty($this->region) ? '':', '.$this->region;
|
287 |
+
break;
|
288 |
+
case '#_LOCATIONFULLBR':
|
289 |
+
$replace = $this->address.'<br /> ';
|
290 |
+
$replace = empty($this->town) ? '':'<br /> '.$this->town;
|
291 |
+
$replace = empty($this->state) ? '':'<br /> '.$this->state;
|
292 |
+
$replace = empty($this->postcode) ? '':'<br /> '.$this->postcode;
|
293 |
+
$replace = empty($this->region) ? '':'<br /> '.$this->region;
|
294 |
+
break;
|
295 |
+
case '#_MAP': //Depreciated
|
296 |
+
case '#_LOCATIONMAP':
|
297 |
+
ob_start();
|
298 |
+
$template = em_locate_template('placeholders/locationmap.php', true, array('EM_Location'=>$this));
|
299 |
+
$replace = ob_get_clean();
|
300 |
+
break;
|
301 |
+
case '#_DESCRIPTION': //Depreciated
|
302 |
+
case '#_EXCERPT': //Depreciated
|
303 |
+
case '#_LOCATIONNOTES':
|
304 |
+
case '#_LOCATIONEXCERPT':
|
305 |
+
$replace = $this->description;
|
306 |
+
if($result == "#_EXCERPT" || $result == "#_LOCATIONEXCERPT"){
|
307 |
+
$matches = explode('<!--more', $this->description);
|
308 |
+
$replace = $matches[0];
|
309 |
+
}
|
310 |
+
break;
|
311 |
+
case '#_LOCATIONIMAGE':
|
312 |
+
if($this->image_url != ''){
|
313 |
+
$replace = "<img src='".$this->image_url."' alt='".$this->name."'/>";
|
314 |
+
}
|
315 |
+
break;
|
316 |
+
case '#_LOCATIONURL':
|
317 |
+
case '#_LOCATIONLINK':
|
318 |
+
case '#_LOCATIONPAGEURL': //Depreciated
|
319 |
+
$joiner = (stristr(EM_URI, "?")) ? "&" : "?";
|
320 |
+
$link = EM_URI.$joiner."location_id=".$this->id;
|
321 |
+
$replace = ($result == '#_LOCATIONURL' || $result == '#_LOCATIONPAGEURL') ? $link : '<a href="'.$link.'">'.$this->name.'</a>';
|
322 |
+
break;
|
323 |
+
case '#_PASTEVENTS': //Depreciated
|
324 |
+
case '#_LOCATIONPASTEVENTS':
|
325 |
+
case '#_NEXTEVENTS': //Depreciated
|
326 |
+
case '#_LOCATIONNEXTEVENTS':
|
327 |
+
case '#_ALLEVENTS': //Depreciated
|
328 |
+
case '#_LOCATIONALLEVENTS':
|
329 |
+
if ($result == '#_PASTEVENTS' || $result == '#_LOCATIONPASTEVENTS'){ $scope = 'past'; }
|
330 |
+
elseif ( $result == '#_NEXTEVENTS' || $result == '#_LOCATIONNEXTEVENTS' ){ $scope = 'future'; }
|
331 |
+
else{ $scope = 'all'; }
|
332 |
+
$events = EM_Events::get( array('location'=>$this->id, 'scope'=>$scope) );
|
333 |
+
if ( count($events) > 0 ){
|
334 |
+
foreach($events as $event){
|
335 |
+
$replace .= $event->output(get_option('dbem_location_event_list_item_format'));
|
336 |
+
}
|
337 |
+
} else {
|
338 |
+
$replace = get_option('dbem_location_no_events_message');
|
339 |
+
}
|
340 |
+
break;
|
341 |
+
default:
|
342 |
+
$match = false;
|
343 |
+
break;
|
344 |
+
}
|
345 |
+
if($match){ //if true, we've got a placeholder that needs replacing
|
346 |
+
$replace = apply_filters('em_location_output_placeholder', $replace, $this, $result, $target); //USE WITH CAUTION! THIS MIGHT GET RENAMED
|
347 |
+
$location_string = str_replace($result, $replace , $location_string );
|
348 |
+
}else{
|
349 |
+
$custom_replace = apply_filters('em_location_output_placeholder', $replace, $this, $result, $target); //USE WITH CAUTION! THIS MIGHT GET RENAMED
|
350 |
+
if($custom_replace != $replace){
|
351 |
+
$location_string = str_replace($result, $custom_replace , $location_string );
|
352 |
+
}
|
353 |
+
}
|
354 |
+
}
|
355 |
+
$name_filter = ($target == "html") ? 'dbem_general':'dbem_general_rss'; //TODO remove dbem_ filters
|
356 |
+
$location_string = str_replace('#_LOCATION', apply_filters($name_filter, $this->name) , $location_string ); //Depreciated
|
357 |
+
return apply_filters('em_location_output', $location_string, $this, $format, $target);
|
358 |
+
}
|
359 |
+
|
360 |
+
function get_country(){
|
361 |
+
$countries = em_get_countries();
|
362 |
+
if( !empty($countries[$this->country]) ){
|
363 |
+
return apply_filters('em_location_get_country', $countries[$this->country], $this);
|
364 |
+
}
|
365 |
+
return apply_filters('em_location_get_country', false, $this);
|
366 |
+
|
367 |
+
}
|
368 |
}
|
classes/em-locations.php
CHANGED
@@ -1,213 +1,278 @@
|
|
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 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
function
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
$
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
$
|
35 |
-
$
|
36 |
-
|
37 |
-
//
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
//
|
55 |
-
$
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
$
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
$
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
$
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
$
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
}
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
$
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
$
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
$
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
?>
|
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 implements Iterator {
|
8 |
+
/**
|
9 |
+
* Array of EM_Location objects
|
10 |
+
* @var array EM_Location
|
11 |
+
*/
|
12 |
+
var $locations = array();
|
13 |
+
|
14 |
+
function EM_Events( $args = array() ){
|
15 |
+
if( is_array($args) ){
|
16 |
+
if( is_object(current($args)) && get_class(current($args)) == 'EM_Event' ){
|
17 |
+
$this->locations = $args;
|
18 |
+
}else{
|
19 |
+
$this->locations = EM_Events::get($args);
|
20 |
+
}
|
21 |
+
}else{
|
22 |
+
$this->locations = EM_Events::get();
|
23 |
+
}
|
24 |
+
do_action('em_events',$this);
|
25 |
+
}
|
26 |
+
/**
|
27 |
+
* Returns an array of EM_Location objects
|
28 |
+
* @param boolean $eventful
|
29 |
+
* @param boolean $return_objects
|
30 |
+
* @return array
|
31 |
+
*/
|
32 |
+
function get( $args = array(), $count=false ){
|
33 |
+
global $wpdb;
|
34 |
+
$events_table = EM_EVENTS_TABLE;
|
35 |
+
$locations_table = EM_LOCATIONS_TABLE;
|
36 |
+
|
37 |
+
//Quick version, we can accept an array of IDs, which is easy to retrieve
|
38 |
+
if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive
|
39 |
+
//We can just get all the events here and return them
|
40 |
+
$sql = "SELECT * FROM $locations_table WHERE location_id=".implode(" OR location_id=", $args);
|
41 |
+
$results = $wpdb->get_results($sql,ARRAY_A);
|
42 |
+
$events = array();
|
43 |
+
foreach($results as $result){
|
44 |
+
$locations[$result['location_id']] = new EM_Location($result);
|
45 |
+
}
|
46 |
+
return $locations; //We return all the events matched as an EM_Event array.
|
47 |
+
}elseif( is_numeric($args) ){
|
48 |
+
//return an event in the usual array format
|
49 |
+
return apply_filters('em_locations_get', array(new EM_Event($args)), $args);
|
50 |
+
}elseif( is_array($args) && is_object(current($args)) && get_class((current($args))) == 'EM_Location' ){
|
51 |
+
return apply_filters('em_locations_get', $args, $args);
|
52 |
+
}
|
53 |
+
|
54 |
+
//We assume it's either an empty array or array of search arguments to merge with defaults
|
55 |
+
$args = self::get_default_search($args);
|
56 |
+
$limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : '';
|
57 |
+
$offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : '';
|
58 |
+
|
59 |
+
//Get the default conditions
|
60 |
+
$conditions = self::build_sql_conditions($args);
|
61 |
+
|
62 |
+
//Put it all together
|
63 |
+
$EM_Location = new EM_Location(0); //Empty class for strict message avoidance
|
64 |
+
$fields = $locations_table .".". implode(", {$locations_table}.", array_keys($EM_Location->fields));
|
65 |
+
$where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):'';
|
66 |
+
|
67 |
+
//Get ordering instructions
|
68 |
+
$EM_Event = new EM_Event(); //blank event for below
|
69 |
+
$accepted_fields = $EM_Location->get_fields(true);
|
70 |
+
$accepted_fields = array_merge($EM_Event->get_fields(true),$accepted_fields);
|
71 |
+
$orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order'));
|
72 |
+
//Now, build orderby sql
|
73 |
+
$orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : '';
|
74 |
+
|
75 |
+
if( $count ){
|
76 |
+
$fields = $locations_table.'.location_id';
|
77 |
+
}
|
78 |
+
//Create the SQL statement and execute
|
79 |
+
$sql = "
|
80 |
+
SELECT $fields FROM $locations_table
|
81 |
+
LEFT JOIN $events_table ON {$locations_table}.location_id={$events_table}.location_id
|
82 |
+
$where
|
83 |
+
GROUP BY {$locations_table}.location_id
|
84 |
+
$orderby_sql
|
85 |
+
$limit $offset
|
86 |
+
";
|
87 |
+
|
88 |
+
//If we're only counting results, return the number of results
|
89 |
+
if( $count ){
|
90 |
+
return count($wpdb->get_results($sql));
|
91 |
+
}
|
92 |
+
$results = $wpdb->get_results($sql, ARRAY_A);
|
93 |
+
|
94 |
+
//If we want results directly in an array, why not have a shortcut here?
|
95 |
+
if( $args['array'] == true ){
|
96 |
+
return $results;
|
97 |
+
}
|
98 |
+
|
99 |
+
$locations = array();
|
100 |
+
foreach ($results as $location){
|
101 |
+
$locations[] = new EM_Location($location);
|
102 |
+
}
|
103 |
+
return apply_filters('em_locations_get', $locations, $args);
|
104 |
+
}
|
105 |
+
|
106 |
+
function count( $args = array() ){
|
107 |
+
return apply_filters('em_locations_count', self::get($args, true), $args);
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Output a set of matched of events
|
112 |
+
* @param array $args
|
113 |
+
* @return string
|
114 |
+
*/
|
115 |
+
function output( $args ){
|
116 |
+
global $EM_Location;
|
117 |
+
$EM_Location_old = $EM_Location; //When looping, we can replace EM_Location global with the current event in the loop
|
118 |
+
//Can be either an array for the get search or an array of EM_Location objects
|
119 |
+
if( is_object(current($args)) && get_class((current($args))) == 'EM_Location' ){
|
120 |
+
$func_args = func_get_args();
|
121 |
+
$locations = $func_args[0];
|
122 |
+
$args = (!empty($func_args[1])) ? $func_args[1] : array();
|
123 |
+
$args = apply_filters('em_locations_output_args', self::get_default_search($args), $locations);
|
124 |
+
$limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
|
125 |
+
$offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
|
126 |
+
$page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
|
127 |
+
}else{
|
128 |
+
$args = apply_filters('em_locations_output_args', self::get_default_search($args) );
|
129 |
+
$limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false;
|
130 |
+
$offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0;
|
131 |
+
$page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1;
|
132 |
+
$args['limit'] = false;
|
133 |
+
$args['offset'] = false;
|
134 |
+
$args['page'] = false;
|
135 |
+
$locations = self::get( $args );
|
136 |
+
}
|
137 |
+
//What format shall we output this to, or use default
|
138 |
+
$format = ( $args['format'] == '' ) ? get_option( 'dbem_location_list_item_format' ) : $args['format'] ;
|
139 |
+
|
140 |
+
$output = "";
|
141 |
+
$locations_count = count($locations);
|
142 |
+
$locations = apply_filters('em_locations_output_locations', $locations);
|
143 |
+
if ( count($locations) > 0 ) {
|
144 |
+
$location_count = 0;
|
145 |
+
$locations_shown = 0;
|
146 |
+
foreach ( $locations as $EM_Location ) {
|
147 |
+
if( ($locations_shown < $limit || empty($limit)) && ($location_count >= $offset || $offset === 0) ){
|
148 |
+
$output .= $EM_Location->output($format);
|
149 |
+
$locations_shown++;
|
150 |
+
}
|
151 |
+
$location_count++;
|
152 |
+
}
|
153 |
+
//Add headers and footers to output
|
154 |
+
if( $format == get_option ( 'dbem_location_list_item_format' ) ){
|
155 |
+
$single_event_format_header = get_option ( 'dbem_location_list_item_format_header' );
|
156 |
+
$single_event_format_header = ( $single_event_format_header != '' ) ? $single_event_format_header : "<ul class='em-locations-list'>";
|
157 |
+
$single_event_format_footer = get_option ( 'dbem_location_list_item_format_footer' );
|
158 |
+
$single_event_format_footer = ( $single_event_format_footer != '' ) ? $single_event_format_footer : "</ul>";
|
159 |
+
$output = $single_event_format_header . $output . $single_event_format_footer;
|
160 |
+
}
|
161 |
+
//Pagination (if needed/requested)
|
162 |
+
if( !empty($args['pagination']) && !empty($limit) && $locations_count >= $limit ){
|
163 |
+
//Show the pagination links (unless there's less than 10 events
|
164 |
+
$page_link_template = preg_replace('/(&|\?)page=\d+/i','',$_SERVER['REQUEST_URI']);
|
165 |
+
$page_link_template = em_add_get_params($page_link_template, array('page'=>'%PAGE%'));
|
166 |
+
$output .= apply_filters('em_events_output_pagination', em_paginate( $page_link_template, $locations_count, $limit, $page), $page_link_template, $locations_count, $limit, $page);
|
167 |
+
}
|
168 |
+
} else {
|
169 |
+
$output = get_option ( 'dbem_no_locations_message' );
|
170 |
+
}
|
171 |
+
//FIXME check if reference is ok when restoring object, due to changes in php5 v 4
|
172 |
+
$EM_Location_old= $EM_Location;
|
173 |
+
return apply_filters('em_locations_output', $output, $locations, $args);
|
174 |
+
}
|
175 |
+
|
176 |
+
function delete( $args = array() ){
|
177 |
+
if( !is_object(current($args)) && get_class((current($args))) != 'EM_Location' ){
|
178 |
+
$locations = self::get($args);
|
179 |
+
}else{
|
180 |
+
$locations = $args;
|
181 |
+
}
|
182 |
+
$results = array();
|
183 |
+
foreach ( $locations as $EM_Location ){
|
184 |
+
$results[] = $EM_Location->delete();
|
185 |
+
}
|
186 |
+
return apply_filters('em_locations_delete', in_array(false, $results), $locations);
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Builds an array of SQL query conditions based on regularly used arguments
|
191 |
+
* @param array $args
|
192 |
+
* @return array
|
193 |
+
*/
|
194 |
+
function build_sql_conditions( $args = array() ){
|
195 |
+
global $wpdb;
|
196 |
+
$events_table = EM_EVENTS_TABLE;
|
197 |
+
$locations_table = EM_LOCATIONS_TABLE;
|
198 |
+
|
199 |
+
$conditions = parent::build_sql_conditions($args);
|
200 |
+
//eventful locations
|
201 |
+
if( true == $args['eventful'] ){
|
202 |
+
$conditions['eventful'] = "{$events_table}.event_id IS NOT NULL";
|
203 |
+
}elseif( true == $args['eventless'] ){
|
204 |
+
$conditions['eventless'] = "{$events_table}.event_id IS NULL";
|
205 |
+
}
|
206 |
+
//owner lookup
|
207 |
+
if( !empty($args['owner']) ){
|
208 |
+
$conditions['owner'] = "location_owner=".$args['owner'];
|
209 |
+
}
|
210 |
+
//blog id in events table
|
211 |
+
if( is_multisite() && array_key_exists('blog',$args) && is_numeric($args['blog']) ){
|
212 |
+
if( is_main_site($args['blog']) ){
|
213 |
+
$conditions['blog'] = "(`blog_id`={$args['blog']} OR blog_id IS NULL)";
|
214 |
+
}else{
|
215 |
+
$conditions['blog'] = "(`blog_id`={$args['blog']})";
|
216 |
+
}
|
217 |
+
}
|
218 |
+
return apply_filters('em_locations_build_sql_conditions', $conditions, $args);
|
219 |
+
}
|
220 |
+
|
221 |
+
/* Overrides EM_Object method to apply a filter to result
|
222 |
+
* @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
|
223 |
+
*/
|
224 |
+
function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
|
225 |
+
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 );
|
226 |
+
}
|
227 |
+
|
228 |
+
/*
|
229 |
+
* Generate a search arguments array from defalut and user-defined.
|
230 |
+
* @see wp-content/plugins/events-manager/classes/EM_Object::get_default_search()
|
231 |
+
*/
|
232 |
+
function get_default_search($array = array()){
|
233 |
+
$defaults = array(
|
234 |
+
'eventful' => false, //Locations that have an event (scope will also play a part here
|
235 |
+
'eventless' => false, //Locations WITHOUT events, eventful takes precedence
|
236 |
+
'orderby' => 'name',
|
237 |
+
'town' => false,
|
238 |
+
'state' => false,
|
239 |
+
'country' => false,
|
240 |
+
'region' => false,
|
241 |
+
'scope' => 'all', //we probably want to search all locations by default, not like events
|
242 |
+
'blog' => get_current_blog_id()
|
243 |
+
);
|
244 |
+
$array['eventful'] = ( !empty($array['eventful']) && $array['eventful'] == true );
|
245 |
+
$array['eventless'] = ( !empty($array['eventless']) && $array['eventless'] == true );
|
246 |
+
if( is_admin() ){
|
247 |
+
$defaults['owner'] = !current_user_can('read_others_locations') ? get_current_user_id():false;
|
248 |
+
}
|
249 |
+
return apply_filters('em_locations_get_default_search', parent::get_default_search($defaults, $array), $array, $defaults);
|
250 |
+
}
|
251 |
+
|
252 |
+
//Iteratior methods
|
253 |
+
public function rewind(){
|
254 |
+
reset($this->locations);
|
255 |
+
}
|
256 |
+
|
257 |
+
public function current(){
|
258 |
+
$var = current($this->locations);
|
259 |
+
return $var;
|
260 |
+
}
|
261 |
+
|
262 |
+
public function key(){
|
263 |
+
$var = key($this->locations);
|
264 |
+
return $var;
|
265 |
+
}
|
266 |
+
|
267 |
+
public function next(){
|
268 |
+
$var = next($this->locations);
|
269 |
+
return $var;
|
270 |
+
}
|
271 |
+
|
272 |
+
public function valid(){
|
273 |
+
$key = key($this->locations);
|
274 |
+
$var = ($key !== NULL && $key !== FALSE);
|
275 |
+
return $var;
|
276 |
+
}
|
277 |
+
}
|
278 |
?>
|
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
DELETED
@@ -1,60 +0,0 @@
|
|
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
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
session_start();
|
12 |
+
//Grab from session
|
13 |
+
if( !empty($_SESSION['events-manager']['notices']) && is_serialized($_SESSION['events-manager']['notices']) ){
|
14 |
+
$this->notices = unserialize($_SESSION['events-manager']['notices']);
|
15 |
+
}
|
16 |
+
//Flush notices that weren't made to stay cross-requests, we can do this if initialized immediately.
|
17 |
+
foreach($this->notices as $notice_type => $notices){
|
18 |
+
foreach ($notices as $key => $notice){
|
19 |
+
if( empty($notice['static']) ){
|
20 |
+
unset($this->notices[$notice_type][$key]);
|
21 |
+
}else{
|
22 |
+
unset($this->notices[$notice_type][$key]['static']); //so it gets removed next request
|
23 |
+
}
|
24 |
+
}
|
25 |
+
}
|
26 |
+
add_action('shutdown', array(&$this,'destruct'));
|
27 |
+
add_filter('wp_redirect', array(&$this,'destruct'), 1,1);
|
28 |
+
}
|
29 |
+
|
30 |
+
function destruct($redirect = false){
|
31 |
+
$_SESSION['events-manager']['notices'] = serialize($this->notices);
|
32 |
+
return $redirect;
|
33 |
+
}
|
34 |
+
|
35 |
+
function __toString(){
|
36 |
+
$string = false;
|
37 |
+
if(count($this->notices['errors']) > 0){
|
38 |
+
$string .= "<div class='em-warning em-warning-errors error'>{$this->get_errors()}</div>";
|
39 |
+
}
|
40 |
+
if(count($this->notices['alerts']) > 0){
|
41 |
+
$string .= "<div class='em-warning em-warning-alerts updated'>{$this->get_alerts()}</div>";
|
42 |
+
}
|
43 |
+
if(count($this->notices['infos']) > 0){
|
44 |
+
$string .= "<div class='em-warning em-warning-infos updated'>{$this->get_infos()}</div>";
|
45 |
+
}
|
46 |
+
if(count($this->notices['confirms']) > 0){
|
47 |
+
$string .= "<div class='em-warning em-warning-confirms updated'>{$this->get_confirms()}</div>";
|
48 |
+
}
|
49 |
+
return ($string !== false) ? "<div class='statusnotice'>".$string."</div>" : '';
|
50 |
+
}
|
51 |
+
|
52 |
+
/* General */
|
53 |
+
function add($string, $type, $static = false){
|
54 |
+
if( is_array($string) ){
|
55 |
+
$result = true;
|
56 |
+
foreach($string as $string_item){
|
57 |
+
if( $this->add($string_item, $type, $static) === false ){ $result = false; }
|
58 |
+
}
|
59 |
+
return $result;
|
60 |
+
}
|
61 |
+
if($string != ''){
|
62 |
+
if( isset($this->notices[$type]) ){
|
63 |
+
$notice_key = 0;
|
64 |
+
foreach( $this->notices[$type] as $notice_key => $notice ){
|
65 |
+
if($string == $notice['string']){
|
66 |
+
return $notice_key;
|
67 |
+
}
|
68 |
+
}
|
69 |
+
$i = $notice_key+1;
|
70 |
+
$this->notices[$type][$i]['string'] = $string;
|
71 |
+
if( $static ){
|
72 |
+
$this->notices[$type][$i]['static'] = true;
|
73 |
+
}
|
74 |
+
return $i;
|
75 |
+
}else{
|
76 |
+
return false;
|
77 |
+
}
|
78 |
+
}else{
|
79 |
+
return false;
|
80 |
+
}
|
81 |
+
}
|
82 |
+
function remove($key, $type){
|
83 |
+
if( isset($this->notices[$type]) ){
|
84 |
+
unset($this->notices[$type][$key]);
|
85 |
+
return true;
|
86 |
+
}else{
|
87 |
+
return false;
|
88 |
+
}
|
89 |
+
}
|
90 |
+
function get($type){
|
91 |
+
if( isset($this->notices[$type]) ){
|
92 |
+
$string = '';
|
93 |
+
foreach ($this->notices[$type] as $key => $error){
|
94 |
+
$class = substr($type, 0, (strlen($type)-1));
|
95 |
+
$string .= "<p>{$error['string']}</p>";
|
96 |
+
if( empty($error['static']) || $error['static'] !== true){
|
97 |
+
$this->remove($key, $type);
|
98 |
+
}
|
99 |
+
}
|
100 |
+
return $string;
|
101 |
+
}
|
102 |
+
return false;
|
103 |
+
}
|
104 |
+
|
105 |
+
/* Errors */
|
106 |
+
function add_error($string, $static=false){
|
107 |
+
return $this->add($string, 'errors', $static);
|
108 |
+
}
|
109 |
+
function remove_error($key){
|
110 |
+
return $this->remove($key, 'errors');
|
111 |
+
}
|
112 |
+
function get_errors(){
|
113 |
+
return $this->get('errors');
|
114 |
+
}
|
115 |
+
|
116 |
+
/* Alerts */
|
117 |
+
function add_alert($string, $static=false){
|
118 |
+
return $this->add($string, 'alerts', $static);
|
119 |
+
}
|
120 |
+
function remove_alert($key){
|
121 |
+
return $this->remove($key, 'alerts');
|
122 |
+
}
|
123 |
+
function get_alerts(){
|
124 |
+
return $this->get('alerts');
|
125 |
+
}
|
126 |
+
|
127 |
+
/* Info */
|
128 |
+
function add_info($string, $static=false){
|
129 |
+
return $this->add($string, 'infos', $static);
|
130 |
+
}
|
131 |
+
function remove_info($key){
|
132 |
+
return $this->remove($key, 'infos');
|
133 |
+
}
|
134 |
+
function get_infos(){
|
135 |
+
return $this->get('infos');
|
136 |
+
}
|
137 |
+
|
138 |
+
/* Confirms */
|
139 |
+
function add_confirm($string, $static=false){
|
140 |
+
return $this->add($string, 'confirms', $static);
|
141 |
+
}
|
142 |
+
function remove_confirm($key){
|
143 |
+
return $this->remove($key, 'confirms');
|
144 |
+
}
|
145 |
+
function get_confirms(){
|
146 |
+
return $this->get('confirms');
|
147 |
+
}
|
148 |
+
|
149 |
+
//Iterator Implementation
|
150 |
+
function rewind(){
|
151 |
+
reset($this->bookings);
|
152 |
+
}
|
153 |
+
function current(){
|
154 |
+
$var = current($this->bookings);
|
155 |
+
return $var;
|
156 |
+
}
|
157 |
+
function key(){
|
158 |
+
$var = key($this->bookings);
|
159 |
+
return $var;
|
160 |
+
}
|
161 |
+
function next(){
|
162 |
+
$var = next($this->bookings);
|
163 |
+
return $var;
|
164 |
+
}
|
165 |
+
function valid(){
|
166 |
+
$key = key($this->bookings);
|
167 |
+
$var = ($key !== NULL && $key !== FALSE);
|
168 |
+
return $var;
|
169 |
+
}
|
170 |
+
|
171 |
+
}
|
172 |
+
global $EM_Notices;
|
173 |
+
$EM_Notices = new EM_Notices();
|
174 |
+
?>
|
classes/em-object.php
CHANGED
@@ -1,486 +1,772 @@
|
|
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 $
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
*
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
'
|
25 |
-
'
|
26 |
-
'
|
27 |
-
'
|
28 |
-
'
|
29 |
-
'
|
30 |
-
'
|
31 |
-
'
|
32 |
-
'
|
33 |
-
'
|
34 |
-
'
|
35 |
-
'
|
36 |
-
'
|
37 |
-
'
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
if(is_array($array)){
|
52 |
-
//
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
}
|
66 |
-
//
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
$defaults['
|
82 |
-
}
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
$
|
117 |
-
$
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
$
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
$
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
$
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
//
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
}
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
$
|
187 |
-
|
188 |
-
$conditions['
|
189 |
-
}elseif (
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
$
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
}
|
247 |
-
}elseif(
|
248 |
-
$
|
249 |
-
}elseif( $
|
250 |
-
$
|
251 |
-
}
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
if(
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
}
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
}
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
*
|
421 |
-
* @return
|
422 |
-
*/
|
423 |
-
function
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
486 |
}
|
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 |
+
var $mime_types = array(1 => 'gif', 2 => 'jpg', 3 => 'png');
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Takes the array and provides a clean array of search parameters, along with details
|
15 |
+
* @param array $defaults
|
16 |
+
* @param array $array
|
17 |
+
* @return array
|
18 |
+
*/
|
19 |
+
function get_default_search($defaults=array(), $array = array()){
|
20 |
+
global $wpdb;
|
21 |
+
//TODO accept all objects as search options as well as ids (e.g. location vs. location_id, person vs. person_id)
|
22 |
+
//Create minimal defaults array, merge it with supplied defaults array
|
23 |
+
$super_defaults = array(
|
24 |
+
'limit' => false,
|
25 |
+
'scope' => 'future',
|
26 |
+
'order' => 'ASC', //hard-coded at end of this function
|
27 |
+
'orderby' => false,
|
28 |
+
'format' => '',
|
29 |
+
'category' => 0,
|
30 |
+
'location' => 0,
|
31 |
+
'event' => 0,
|
32 |
+
'offset'=>0,
|
33 |
+
'page'=>1,//basically, if greater than 0, calculates offset at end
|
34 |
+
'recurrence'=>0,
|
35 |
+
'recurring'=>false,
|
36 |
+
'month'=>'',
|
37 |
+
'year'=>'',
|
38 |
+
'pagination'=>false,
|
39 |
+
'array'=>false,
|
40 |
+
'owner'=>false,
|
41 |
+
'rsvp'=>false,
|
42 |
+
'search'=>false
|
43 |
+
);
|
44 |
+
//Return default if nothing passed
|
45 |
+
if( empty($defaults) && empty($array) ){
|
46 |
+
return $super_defaults;
|
47 |
+
}
|
48 |
+
//TODO decide on search defaults shared across all objects and then validate here
|
49 |
+
$defaults = array_merge($super_defaults, $defaults);
|
50 |
+
|
51 |
+
if(is_array($array)){
|
52 |
+
//We are still dealing with recurrence_id, location_id, category_id in some place, so we do a quick replace here just in case
|
53 |
+
if( array_key_exists('recurrence_id', $array) && !array_key_exists('recurrence', $array) ) { $array['recurrence'] = $array['recurrence_id']; }
|
54 |
+
if( array_key_exists('location_id', $array) && !array_key_exists('location', $array) ) { $array['location'] = $array['location_id']; }
|
55 |
+
if( array_key_exists('category_id', $array) && !array_key_exists('category', $array) ) { $array['category'] = $array['category_id']; }
|
56 |
+
|
57 |
+
//Clean all id lists
|
58 |
+
$array = self::clean_id_atts($array, array('location', 'event', 'category'));
|
59 |
+
|
60 |
+
//OrderBy - can be a comma-seperated array of field names to order by (field names of object, not db)
|
61 |
+
if( array_key_exists('orderby', $array)){
|
62 |
+
if( !is_array($array['orderby']) && preg_match('/,/', $array['orderby']) ) {
|
63 |
+
$array['orderby'] = explode(',', $array['orderby']);
|
64 |
+
}
|
65 |
+
}
|
66 |
+
//TODO validate search query array
|
67 |
+
//Clean the supplied array, so we only have allowed keys
|
68 |
+
foreach( array_keys($array) as $key){
|
69 |
+
if( !array_key_exists($key, $defaults) ) unset($array[$key]);
|
70 |
+
}
|
71 |
+
//return clean array
|
72 |
+
$defaults = array_merge ( $defaults, $array ); //No point using WP's cleaning function, we're doing it already.
|
73 |
+
|
74 |
+
}
|
75 |
+
|
76 |
+
//Do some spring cleaning for known values
|
77 |
+
//Month & Year - may be array or single number
|
78 |
+
$month_regex = '/^[0-9]{1,2}$/';
|
79 |
+
$year_regex = '/^[0-9]{4}$/';
|
80 |
+
if( is_array($defaults['month']) ){
|
81 |
+
$defaults['month'] = ( preg_match($month_regex, $defaults['month'][0]) && preg_match($month_regex, $defaults['month'][1]) ) ? $defaults['month']:'';
|
82 |
+
}else{
|
83 |
+
$defaults['month'] = preg_match($month_regex, $defaults['month']) ? $defaults['month']:'';
|
84 |
+
}
|
85 |
+
if( is_array($defaults['year']) ){
|
86 |
+
$defaults['year'] = ( preg_match($year_regex, $defaults['year'][0]) && preg_match($year_regex, $defaults['year'][1]) ) ? $defaults['year']:'';
|
87 |
+
}else{
|
88 |
+
$defaults['year'] = preg_match($year_regex, $defaults['year']) ? $defaults['year']:'';
|
89 |
+
}
|
90 |
+
//Deal with scope and date searches
|
91 |
+
if ( !is_array($defaults['scope']) && preg_match ( "/^[0-9]{4}-[0-9]{2}-[0-9]{2},[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $defaults['scope'] ) ) {
|
92 |
+
//This is to become an array, so let's split it up
|
93 |
+
$defaults['scope'] = explode(',', $defaults['scope']);
|
94 |
+
}
|
95 |
+
if( is_array($defaults['scope']) ){
|
96 |
+
//looking for a date range here, so we'll verify the dates validate, if not get the default.
|
97 |
+
if ( !preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $defaults['scope'][0]) || !preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $defaults['scope'][1]) ) {
|
98 |
+
$defaults['scope'] = $super_defaults['scope'];
|
99 |
+
}
|
100 |
+
}
|
101 |
+
//Order - it's either ASC or DESC, so let's just validate
|
102 |
+
if( !is_array($defaults['order']) && preg_match('/,/', $defaults['order']) ) {
|
103 |
+
$defaults['order'] = explode(',', $defaults['order']);
|
104 |
+
}elseif( !in_array($defaults['order'], array('ASC','DESC')) ){
|
105 |
+
$defaults['order'] = $super_defaults['order'];
|
106 |
+
}
|
107 |
+
//ORDER BY, split if an array
|
108 |
+
if( !is_array($defaults['orderby']) && preg_match('/,/', $defaults['orderby']) ) {
|
109 |
+
$defaults['orderby'] = explode(',', $defaults['orderby']);
|
110 |
+
}
|
111 |
+
//TODO should we clean format of malicious code over here and run everything thorugh this?
|
112 |
+
$defaults['array'] = ($defaults['array'] == true);
|
113 |
+
$defaults['pagination'] = ($defaults['pagination'] == true);
|
114 |
+
$defaults['limit'] = (is_numeric($defaults['limit'])) ? $defaults['limit']:$super_defaults['limit'];
|
115 |
+
$defaults['offset'] = (is_numeric($defaults['offset'])) ? $defaults['offset']:$super_defaults['offset'];
|
116 |
+
$defaults['recurring'] = ($defaults['recurring'] == true);
|
117 |
+
$defaults['owner'] = (is_numeric($defaults['owner'])) ? $defaults['owner']:$super_defaults['owner'];
|
118 |
+
$defaults['search'] = ($defaults['search']) ? trim($wpdb->escape(like_escape($defaults['search']))):false;
|
119 |
+
//Calculate offset if event page is set
|
120 |
+
if($defaults['page'] > 1){
|
121 |
+
$defaults['offset'] = $defaults['limit'] * ($defaults['page']-1);
|
122 |
+
}else{
|
123 |
+
$defaults['page'] = ($defaults['limit'] > 0 ) ? floor($defaults['offset']/$defaults['limit']) + 1 : 1;
|
124 |
+
}
|
125 |
+
return apply_filters('em_object_get_default_search', $defaults, $array, $super_defaults);
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Builds an array of SQL query conditions based on regularly used arguments
|
130 |
+
* @param array $args
|
131 |
+
* @return array
|
132 |
+
*/
|
133 |
+
function build_sql_conditions( $args = array() ){
|
134 |
+
global $wpdb;
|
135 |
+
$events_table = EM_EVENTS_TABLE;
|
136 |
+
$locations_table = EM_LOCATIONS_TABLE;
|
137 |
+
|
138 |
+
$args = apply_filters('em_object_build_sql_conditions_args',$args);
|
139 |
+
|
140 |
+
//Format the arguments passed on
|
141 |
+
$scope = $args['scope'];//undefined variable warnings in ZDE, could just delete this (but dont pls!)
|
142 |
+
$recurring = $args['recurring'];
|
143 |
+
$recurrence = $args['recurrence'];
|
144 |
+
$category = $args['category'];
|
145 |
+
$location = $args['location'];
|
146 |
+
$rsvp = $args['rsvp'];
|
147 |
+
$owner = $args['owner'];
|
148 |
+
$event = $args['event'];
|
149 |
+
$month = $args['month'];
|
150 |
+
$year = $args['year'];
|
151 |
+
$today = date('Y-m-d', current_time('timestamp'));
|
152 |
+
//Create the WHERE statement
|
153 |
+
|
154 |
+
//Recurrences
|
155 |
+
$conditions = array();
|
156 |
+
if( $recurring ){
|
157 |
+
$conditions['recurring'] = "`recurrence`=1";
|
158 |
+
}elseif( $recurrence > 0 ){
|
159 |
+
$conditions['recurrence'] = "`recurrence_id`=$recurrence";
|
160 |
+
}else{
|
161 |
+
$conditions['recurring'] = "(`recurrence`!=1 OR `recurrence` IS NULL)";
|
162 |
+
}
|
163 |
+
//Dates - first check 'month', and 'year', and adjust scope if needed
|
164 |
+
if( !($month=='' && $year=='') ){
|
165 |
+
//Sort out month range, if supplied an array of array(month,month), it'll check between these two months
|
166 |
+
if( self::array_is_numeric($month) ){
|
167 |
+
$date_month_start = $month[0];
|
168 |
+
$date_month_end = $month[1];
|
169 |
+
}else{
|
170 |
+
$date_month_start = $date_month_end = $month;
|
171 |
+
}
|
172 |
+
//Sort out year range, if supplied an array of array(year,year), it'll check between these two years
|
173 |
+
if( self::array_is_numeric($year) ){
|
174 |
+
$date_year_start = $year[0];
|
175 |
+
$date_year_end = $year[1];
|
176 |
+
}else{
|
177 |
+
$date_year_start = $date_year_end = $year;
|
178 |
+
}
|
179 |
+
$date_start = $date_year_start."-".$date_month_start."-01";
|
180 |
+
$date_end = date('Y-m-t', mktime(0,0,0,$date_month_end,1,$date_year_end));
|
181 |
+
$scope = array($date_start,$date_end); //just modify the scope here
|
182 |
+
}
|
183 |
+
//No date requested, so let's look at scope
|
184 |
+
if ( is_array($scope) ) {
|
185 |
+
//This is an array, let's split it up
|
186 |
+
$date_start = $scope[0];
|
187 |
+
$date_end = $scope[1];
|
188 |
+
$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)) )";
|
189 |
+
} elseif ( preg_match ( "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $scope ) ) {
|
190 |
+
//Scope can also be a specific date. However, if 'day', 'month', or 'year' are set, that will take precedence
|
191 |
+
$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) ) )";
|
192 |
+
} else {
|
193 |
+
if ($scope == "past"){
|
194 |
+
if( get_option('dbem_events_current_are_past') ){
|
195 |
+
$conditions['scope'] = " event_start_date < '$today'";
|
196 |
+
}else{
|
197 |
+
$conditions['scope'] = " event_end_date < '$today'";
|
198 |
+
}
|
199 |
+
}elseif ($scope == "today"){
|
200 |
+
$conditions['scope'] = " (event_start_date = CAST('$today' AS DATE))";
|
201 |
+
if( !get_option('dbem_events_current_are_past') ){
|
202 |
+
$conditions['scope'] .= " OR (event_start_date <= CAST('$today' AS DATE) AND event_end_date >= CAST('$today' AS DATE))";
|
203 |
+
}
|
204 |
+
}elseif ($scope == "tomorrow"){
|
205 |
+
$tomorrow = date('Y-m-d',current_time('timestamp')+60*60*24);
|
206 |
+
$conditions['scope'] = "(event_start_date = CAST('$tomorrow' AS DATE))";
|
207 |
+
if( !get_option('dbem_events_current_are_past') ){
|
208 |
+
$conditions['scope'] .= " OR (event_start_date <= CAST('$tomorrow' AS DATE) AND event_end_date >= CAST('$tomorrow' AS DATE))";
|
209 |
+
}
|
210 |
+
}elseif ($scope == "month"){
|
211 |
+
$start_month = date('Y-m-d',current_time('timestamp'));
|
212 |
+
$end_month = date('Y-m-t',current_time('timestamp'));
|
213 |
+
$conditions['scope'] = " (event_start_date BETWEEN CAST('$start_month' AS DATE) AND CAST('$end_month' AS DATE))";
|
214 |
+
if( !get_option('dbem_events_current_are_past') ){
|
215 |
+
$conditions['scope'] .= " OR (event_start_date < CAST('$start_month' AS DATE) AND event_end_date >= CAST('$start_month' AS DATE))";
|
216 |
+
}
|
217 |
+
}elseif ($scope == "next-month"){
|
218 |
+
$start_month_timestamp = strtotime('+1 month', current_time('timestamp')); //get the end of this month + 1 day
|
219 |
+
$start_month = date('Y-m-1',$start_month_timestamp);
|
220 |
+
$end_month = date('Y-m-t',$start_month_timestamp);
|
221 |
+
$conditions['scope'] = " (event_start_date BETWEEN CAST('$start_month' AS DATE) AND CAST('$end_month' AS DATE))";
|
222 |
+
if( !get_option('dbem_events_current_are_past') ){
|
223 |
+
$conditions['scope'] .= " OR (event_start_date < CAST('$start_month' AS DATE) AND event_end_date >= CAST('$start_month' AS DATE))";
|
224 |
+
}
|
225 |
+
}elseif( preg_match('/(\d\d?)\-months/',$scope,$matches) ){ // next x months means this month (what's left of it), plus the following x-1 months until the end of that month.
|
226 |
+
$months_to_add = $matches[1];
|
227 |
+
$start_month = date('Y-m-d',current_time('timestamp'));
|
228 |
+
$end_month = date('Y-m-t',strtotime("+$months_to_add month", current_time('timestamp')));
|
229 |
+
$conditions['scope'] = " (event_start_date BETWEEN CAST('$start_month' AS DATE) AND CAST('$end_month' AS DATE))";
|
230 |
+
if( !get_option('dbem_events_current_are_past') ){
|
231 |
+
$conditions['scope'] .= " OR (event_start_date < CAST('$start_month' AS DATE) AND event_end_date >= CAST('$start_month' AS DATE))";
|
232 |
+
}
|
233 |
+
}elseif ($scope == "future"){
|
234 |
+
$conditions['scope'] = " event_start_date >= CAST('$today' AS DATE)";
|
235 |
+
if( !get_option('dbem_events_current_are_past') ){
|
236 |
+
$conditions['scope'] .= " OR (event_end_date >= CAST('$today' AS DATE) AND event_end_date != '0000-00-00' AND event_end_date IS NOT NULL)";
|
237 |
+
}
|
238 |
+
}
|
239 |
+
if( !empty($conditions['scope']) ){
|
240 |
+
$conditions['scope'] = '('.$conditions['scope'].')';
|
241 |
+
}
|
242 |
+
}
|
243 |
+
|
244 |
+
//Filter by Location - can be object, array, or id
|
245 |
+
if ( is_numeric($location) && $location > 0 ) { //Location ID takes precedence
|
246 |
+
$conditions['location'] = " {$locations_table}.location_id = $location";
|
247 |
+
}elseif ( self::array_is_numeric($location) ){
|
248 |
+
$conditions['location'] = "( {$locations_table}.location_id = " . implode(" OR {$locations_table}.location_id = ", $location) .' )';
|
249 |
+
}elseif ( is_object($location) && get_class($location)=='EM_Location' ){ //Now we deal with objects
|
250 |
+
$conditions['location'] = " {$locations_table}.location_id = $location->id";
|
251 |
+
}elseif ( is_array($location) && @get_class(current($location)=='EM_Location') ){ //we can accept array of ids or EM_Location objects
|
252 |
+
foreach($location as $EM_Location){
|
253 |
+
$location_ids[] = $EM_Location->id;
|
254 |
+
}
|
255 |
+
$conditions['location'] = "( {$locations_table}.location_id=". implode(" {$locations_table}.location_id=", $location_ids) ." )";
|
256 |
+
}
|
257 |
+
|
258 |
+
//Filter by Event - can be object, array, or id
|
259 |
+
if ( is_numeric($event) && $event > 0 ) { //event ID takes precedence
|
260 |
+
$conditions['event'] = " {$events_table}.event_id = $event";
|
261 |
+
}elseif ( self::array_is_numeric($event) ){ //array of ids
|
262 |
+
$conditions['event'] = "( {$events_table}.event_id = " . implode(" OR {$events_table}.event_id = ", $event) .' )';
|
263 |
+
}elseif ( is_object($event) && get_class($event)=='EM_Event' ){ //Now we deal with objects
|
264 |
+
$conditions['event'] = " {$events_table}.event_id = $event->id";
|
265 |
+
}elseif ( is_array($event) && @get_class(current($event)=='EM_Event') ){ //we can accept array of ids or EM_event objects
|
266 |
+
foreach($event as $EM_Event){
|
267 |
+
$event_ids[] = $EM_Event->id;
|
268 |
+
}
|
269 |
+
$conditions['event'] = "( {$events_table}.event_id=". implode(" {$events_table}.event_id=", $event_ids) ." )";
|
270 |
+
}
|
271 |
+
//Location specific filters
|
272 |
+
//country lookup
|
273 |
+
if( !empty($args['country']) ){
|
274 |
+
$countries = em_get_countries();
|
275 |
+
//we can accept country codes or names
|
276 |
+
if( in_array($args['country'], $countries) ){
|
277 |
+
//we have a country name,
|
278 |
+
$conditions['country'] = "location_country='".array_search($args['country'])."'";
|
279 |
+
}elseif( array_key_exists($args['country'], $countries) ){
|
280 |
+
//we have a country code
|
281 |
+
$conditions['country'] = "location_country='".$args['country']."'";
|
282 |
+
}
|
283 |
+
}
|
284 |
+
//state lookup
|
285 |
+
if( !empty($args['state']) ){
|
286 |
+
$conditions['state'] = $wpdb->prepare('location_state=%s', $args['state']);
|
287 |
+
}
|
288 |
+
//state lookup
|
289 |
+
if( !empty($args['town']) ){
|
290 |
+
$conditions['town'] = $wpdb->prepare('location_town=%s', $args['town']);
|
291 |
+
}
|
292 |
+
//region lookup
|
293 |
+
if( !empty($args['region']) ){
|
294 |
+
$conditions['region'] = $wpdb->prepare('location_region=%s', $args['region']);
|
295 |
+
}
|
296 |
+
|
297 |
+
//Add conditions for category selection
|
298 |
+
//Filter by category, can be id or comma seperated ids
|
299 |
+
//TODO create an exclude category option
|
300 |
+
if ( is_numeric($category) && $category > 0 ){
|
301 |
+
$conditions['category'] = " event_id IN ( SELECT object_id FROM ".EM_META_TABLE." WHERE meta_key='event-category' AND meta_value='$category' ) ";
|
302 |
+
}elseif( self::array_is_numeric($category) ){
|
303 |
+
$conditions['category'] = " event_id IN ( SELECT object_id FROM ".EM_META_TABLE." WHERE meta_key='event-category' AND meta_value IN (".implode(',',$category).") ) ";
|
304 |
+
}
|
305 |
+
|
306 |
+
//If we want rsvped items, we usually check the event
|
307 |
+
if( $rsvp == 1 ){
|
308 |
+
$conditions['rsvp'] = 'event_rsvp=1';
|
309 |
+
}
|
310 |
+
//Default ownership belongs to an event, child objects can just overwrite this if needed.
|
311 |
+
if( is_numeric($owner) ){
|
312 |
+
$conditions['owner'] = 'event_owner='.$owner;
|
313 |
+
}
|
314 |
+
return apply_filters('em_object_build_sql_conditions', $conditions);
|
315 |
+
}
|
316 |
+
|
317 |
+
function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
|
318 |
+
//First, ORDER BY
|
319 |
+
$args = apply_filters('em_object_build_sql_orderby_args', $args);
|
320 |
+
$orderby = array();
|
321 |
+
if(is_array($args['orderby'])){
|
322 |
+
//Clean orderby array so we only have accepted values
|
323 |
+
foreach( $args['orderby'] as $key => $field ){
|
324 |
+
if( array_key_exists($field, $accepted_fields) ){
|
325 |
+
$orderby[] = $accepted_fields[$field];
|
326 |
+
}elseif( in_array($field,$accepted_fields) ){
|
327 |
+
$orderby[] = $field;
|
328 |
+
}else{
|
329 |
+
unset($args['orderby'][$key]);
|
330 |
+
}
|
331 |
+
}
|
332 |
+
}elseif( $args['orderby'] != '' && array_key_exists($args['orderby'], $accepted_fields) ){
|
333 |
+
$orderby[] = $accepted_fields[$args['orderby']];
|
334 |
+
}elseif( $args['orderby'] != '' && in_array($args['orderby'], $accepted_fields) ){
|
335 |
+
$orderby[] = $args['orderby'];
|
336 |
+
}
|
337 |
+
//ORDER
|
338 |
+
//If order is an array, we'll go through the orderby array and match the order values (in order of array) with orderby values
|
339 |
+
//If orders don't match up, or it's not ASC/DESC, the default events search in EM settings/options page will be used.
|
340 |
+
foreach($orderby as $i => $field){
|
341 |
+
$orderby[$i] .= ' ';
|
342 |
+
if(is_array($args['order'])){
|
343 |
+
if( in_array($args['order'][$i], array('ASC','DESC')) ){
|
344 |
+
$orderby[$i] .= $args['order'][$i];
|
345 |
+
}else{
|
346 |
+
$orderby[$i] .= $default_order;
|
347 |
+
}
|
348 |
+
}else{
|
349 |
+
$orderby[$i] .= ( in_array($args['order'], array('ASC','DESC')) ) ? $args['order'] : $default_order;
|
350 |
+
}
|
351 |
+
}
|
352 |
+
return apply_filters('em_object_build_sql_orderby', $orderby);
|
353 |
+
}
|
354 |
+
|
355 |
+
/**
|
356 |
+
* 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).
|
357 |
+
* @param string $owner_capability If the object has an owner property and the user id matches that, this capability will be checked for.
|
358 |
+
* @param string $admin_capability If the user isn't the owner of the object, this capability will be checked for.
|
359 |
+
* @return boolean
|
360 |
+
*/
|
361 |
+
function can_manage( $owner_capability = false, $admin_capability = false ){
|
362 |
+
global $em_capabilities_array;
|
363 |
+
//if multisite and supoer admin, just return true
|
364 |
+
if( is_multisite() && is_super_admin() ){ return true; }
|
365 |
+
//do they own this?
|
366 |
+
$is_owner = ( $this->owner == get_current_user_id() || empty($this->id) );
|
367 |
+
//now check capability
|
368 |
+
$can_manage = false;
|
369 |
+
if( $is_owner && current_user_can($owner_capability) ){
|
370 |
+
//user owns the object and can therefore manage it
|
371 |
+
$can_manage = true;
|
372 |
+
}elseif( array_key_exists($owner_capability, $em_capabilities_array) ){
|
373 |
+
//currently user is not able to manage as they aren't the owner
|
374 |
+
$error_msg = $em_capabilities_array[$owner_capability];
|
375 |
+
}
|
376 |
+
//admins have special rights
|
377 |
+
if( current_user_can($admin_capability) ){
|
378 |
+
$can_manage = true;
|
379 |
+
}elseif( array_key_exists($admin_capability, $em_capabilities_array) ){
|
380 |
+
$error_msg = $em_capabilities_array[$admin_capability];
|
381 |
+
}
|
382 |
+
//Figure out if this is multisite in global mode and require an extra bit of validation
|
383 |
+
if( !empty($this->id) && is_multisite() && get_site_option('dbem_ms_global_table') ){
|
384 |
+
if( get_class($this) == "EM_Event" ){
|
385 |
+
//Other user-owned events can be modified by admins if it's on the same blog, otherwise it must be an admin on the main site.
|
386 |
+
$can_manage = $this->blog_id == get_current_blog_id() || is_main_site() || (defined('BP_ROOT_BLOG') && get_current_blog_id() == BP_ROOT_BLOG);
|
387 |
+
}
|
388 |
+
}
|
389 |
+
|
390 |
+
if( !$can_manage && !empty($error_msg) ){
|
391 |
+
$this->add_error($error_msg);
|
392 |
+
}
|
393 |
+
return $can_manage;
|
394 |
+
}
|
395 |
+
|
396 |
+
/**
|
397 |
+
* Save an array into this class.
|
398 |
+
* If you provide a record from the database table corresponding to this class type it will add the data to this object.
|
399 |
+
* @param array $array
|
400 |
+
* @return null
|
401 |
+
*/
|
402 |
+
function to_object( $array = array(), $addslashes = false ){
|
403 |
+
//Save core data
|
404 |
+
if( is_array($array) ){
|
405 |
+
$array = apply_filters('em_to_object', $array);
|
406 |
+
foreach ( $this->fields as $key => $val ) {
|
407 |
+
if(array_key_exists($key, $array)){
|
408 |
+
if( !is_object($array[$key]) && !is_array($array[$key]) ){
|
409 |
+
$array[$key] = ($addslashes) ? stripslashes($array[$key]):$array[$key];
|
410 |
+
}elseif( is_array($array[$key]) ){
|
411 |
+
$array[$key] = ($addslashes) ? stripslashes_deep($array[$key]):$array[$key];
|
412 |
+
}
|
413 |
+
$this->$val['name'] = $array[$key];
|
414 |
+
}
|
415 |
+
}
|
416 |
+
}
|
417 |
+
}
|
418 |
+
|
419 |
+
/**
|
420 |
+
* Returns this object in the form of an array, useful for saving directly into a database table.
|
421 |
+
* @return array
|
422 |
+
*/
|
423 |
+
function to_array($db = false){
|
424 |
+
$array = array();
|
425 |
+
foreach ( $this->fields as $key => $val ) {
|
426 |
+
if($db){
|
427 |
+
if( !empty($this->$val['name']) || empty($val['null']) ){
|
428 |
+
$array[$key] = $this->$val['name'];
|
429 |
+
}
|
430 |
+
}else{
|
431 |
+
$array[$key] = $this->$val['name'];
|
432 |
+
}
|
433 |
+
}
|
434 |
+
return apply_filters('em_to_array', $array);
|
435 |
+
}
|
436 |
+
|
437 |
+
|
438 |
+
/**
|
439 |
+
* 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
|
440 |
+
* @param array $array
|
441 |
+
* @return array:
|
442 |
+
*/
|
443 |
+
function get_types($array = array()){
|
444 |
+
$types = array();
|
445 |
+
if( count($array)>0 ){
|
446 |
+
//So we look at assoc array and find equivalents
|
447 |
+
foreach ($array as $key => $val){
|
448 |
+
$types[] = $this->fields[$key]['type'];
|
449 |
+
}
|
450 |
+
}else{
|
451 |
+
//Blank array, let's assume we're getting a standard list of types
|
452 |
+
foreach ($this->fields as $field){
|
453 |
+
$types[] = $field['type'];
|
454 |
+
}
|
455 |
+
}
|
456 |
+
return apply_filters('em_object_get_types', $types, $this, $array);
|
457 |
+
}
|
458 |
+
|
459 |
+
function get_fields( $inverted_array=false ){
|
460 |
+
if( is_array($this->fields) ){
|
461 |
+
$return = array();
|
462 |
+
foreach($this->fields as $fieldName => $fieldArray){
|
463 |
+
if($inverted_array){
|
464 |
+
$return[$fieldArray['name']] = $fieldName;
|
465 |
+
}else{
|
466 |
+
$return[$fieldName] = $fieldArray['name'];
|
467 |
+
}
|
468 |
+
}
|
469 |
+
return apply_filters('em_object_get_fields', $return, $this, $inverted_array);
|
470 |
+
}
|
471 |
+
return apply_filters('em_object_get_fields', array(), $this, $inverted_array);
|
472 |
+
}
|
473 |
+
|
474 |
+
/**
|
475 |
+
* Sanitize text before inserting into database
|
476 |
+
* @param string $value
|
477 |
+
* @return string
|
478 |
+
*/
|
479 |
+
function sanitize( $value ) {
|
480 |
+
if( get_magic_quotes_gpc() )
|
481 |
+
$value = stripslashes( $value );
|
482 |
+
|
483 |
+
//check if this function exists
|
484 |
+
if( function_exists( "mysql_real_escape_string" ) ) {
|
485 |
+
$value = mysql_real_escape_string( $value );
|
486 |
+
//for PHP version < 4.3.0 use addslashes
|
487 |
+
} else {
|
488 |
+
$value = addslashes( $value );
|
489 |
+
}
|
490 |
+
return apply_filters('em_object_sanitize', $value);
|
491 |
+
}
|
492 |
+
|
493 |
+
/**
|
494 |
+
* 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
|
495 |
+
* @param array $array
|
496 |
+
* @param array $id_atts
|
497 |
+
*/
|
498 |
+
function clean_id_atts( $array = array(), $id_atts = array() ){
|
499 |
+
if( is_array($array) && is_array($id_atts) ){
|
500 |
+
foreach( $array as $key => $string ){
|
501 |
+
if( in_array($key, $id_atts) ){
|
502 |
+
//This is in the list of atts we want cleaned
|
503 |
+
if( is_numeric($string) ){
|
504 |
+
$array[$key] = (int) $string;
|
505 |
+
}elseif( self::array_is_numeric($string) ){
|
506 |
+
$array[$key] = $string;
|
507 |
+
}elseif( preg_match('/^([0-9],?)+$/', $string) ){
|
508 |
+
$array[$key] = explode(',', $string);
|
509 |
+
}else{
|
510 |
+
//No format we accept
|
511 |
+
unset($array[$key]);
|
512 |
+
}
|
513 |
+
}
|
514 |
+
}
|
515 |
+
}
|
516 |
+
return $array;
|
517 |
+
}
|
518 |
+
|
519 |
+
/**
|
520 |
+
* Send an email and log errors in this object
|
521 |
+
* @param string $subject
|
522 |
+
* @param string $body
|
523 |
+
* @param string $email
|
524 |
+
* @return string
|
525 |
+
*/
|
526 |
+
function email_send($subject, $body, $email){
|
527 |
+
global $EM_Mailer;
|
528 |
+
if( !$EM_Mailer->send($subject,$body,$email) ){
|
529 |
+
if( is_array($EM_Mailer->errors) ){
|
530 |
+
foreach($EM_Mailer->errors as $error){
|
531 |
+
$this->errors[] = $error;
|
532 |
+
}
|
533 |
+
}else{
|
534 |
+
$this->errors[] = $EM_Mailer->errors;
|
535 |
+
}
|
536 |
+
return false;
|
537 |
+
}
|
538 |
+
return true;
|
539 |
+
}
|
540 |
+
|
541 |
+
/**
|
542 |
+
* Will return true if this is a simple (non-assoc) numeric array, meaning it has at one or more numeric entries and nothing else
|
543 |
+
* @param mixed $array
|
544 |
+
* @return boolean
|
545 |
+
*/
|
546 |
+
function array_is_numeric($array){
|
547 |
+
$results = array();
|
548 |
+
if(is_array($array)){
|
549 |
+
foreach($array as $key => $item){
|
550 |
+
$results[] = (is_numeric($item)&&is_numeric($key));
|
551 |
+
}
|
552 |
+
}
|
553 |
+
return (!in_array(false, $results) && count($results) > 0);
|
554 |
+
}
|
555 |
+
|
556 |
+
/**
|
557 |
+
* Returns an array of errors in this object
|
558 |
+
* @return array
|
559 |
+
*/
|
560 |
+
function get_errors(){
|
561 |
+
if(is_array($this->errors)){
|
562 |
+
return $this->errors;
|
563 |
+
}else{
|
564 |
+
return array();
|
565 |
+
}
|
566 |
+
}
|
567 |
+
|
568 |
+
/**
|
569 |
+
* Adds an error to the object
|
570 |
+
*/
|
571 |
+
function add_error($error){
|
572 |
+
if(is_array($this->errors)){
|
573 |
+
if( !in_array($error, $this->errors) ){
|
574 |
+
$this->errors[] = $error;
|
575 |
+
}
|
576 |
+
}else{
|
577 |
+
$this->errors = array($error);
|
578 |
+
}
|
579 |
+
}
|
580 |
+
|
581 |
+
/**
|
582 |
+
* 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().
|
583 |
+
* @param array $array
|
584 |
+
* @return string
|
585 |
+
*/
|
586 |
+
function json_encode($array){
|
587 |
+
if( function_exists("json_encode") ){
|
588 |
+
$return = json_encode($array);
|
589 |
+
}else{
|
590 |
+
$return = self::array_to_json($array);
|
591 |
+
}
|
592 |
+
if( isset($_REQUEST['callback']) ){
|
593 |
+
$return = $_REQUEST['callback']."($return)";
|
594 |
+
}
|
595 |
+
return apply_filters('em_object_json_encode', $return, $array);
|
596 |
+
}
|
597 |
+
|
598 |
+
/**
|
599 |
+
* Compatible json encoder function for PHP4
|
600 |
+
* @param array $array
|
601 |
+
* @return string
|
602 |
+
*/
|
603 |
+
function array_to_json($array){
|
604 |
+
//PHP4 Comapatability - This encodes the array into JSON. Thanks go to Andy - http://www.php.net/manual/en/function.json-encode.php#89908
|
605 |
+
if( !is_array( $array ) ){
|
606 |
+
$array = array();
|
607 |
+
}
|
608 |
+
$associative = count( array_diff( array_keys($array), array_keys( array_keys( $array )) ));
|
609 |
+
if( $associative ){
|
610 |
+
$construct = array();
|
611 |
+
foreach( $array as $key => $value ){
|
612 |
+
// We first copy each key/value pair into a staging array,
|
613 |
+
// formatting each key and value properly as we go.
|
614 |
+
// Format the key:
|
615 |
+
if( is_numeric($key) ){
|
616 |
+
$key = "key_$key";
|
617 |
+
}
|
618 |
+
$key = "'".addslashes($key)."'";
|
619 |
+
// Format the value:
|
620 |
+
if( is_array( $value )){
|
621 |
+
$value = $this->array_to_json( $value );
|
622 |
+
}else if( is_bool($value) ) {
|
623 |
+
$value = ($value) ? "true" : "false";
|
624 |
+
}else if( !is_numeric( $value ) || is_string( $value ) ){
|
625 |
+
$value = "'".addslashes($value)."'";
|
626 |
+
}
|
627 |
+
// Add to staging array:
|
628 |
+
$construct[] = "$key: $value";
|
629 |
+
}
|
630 |
+
// Then we collapse the staging array into the JSON form:
|
631 |
+
$result = "{ " . implode( ", ", $construct ) . " }";
|
632 |
+
} else { // If the array is a vector (not associative):
|
633 |
+
$construct = array();
|
634 |
+
foreach( $array as $value ){
|
635 |
+
// Format the value:
|
636 |
+
if( is_array( $value )){
|
637 |
+
$value = $this->array_to_json( $value );
|
638 |
+
} else if( !is_numeric( $value ) || is_string( $value ) ){
|
639 |
+
$value = "'".addslashes($value)."'";
|
640 |
+
}
|
641 |
+
// Add to staging array:
|
642 |
+
$construct[] = $value;
|
643 |
+
}
|
644 |
+
// Then we collapse the staging array into the JSON form:
|
645 |
+
$result = "[ " . implode( ", ", $construct ) . " ]";
|
646 |
+
}
|
647 |
+
return $result;
|
648 |
+
}
|
649 |
+
|
650 |
+
/*
|
651 |
+
* START IMAGE UPlOAD FUNCTIONS
|
652 |
+
* Used for various objects, so shared in one place
|
653 |
+
*/
|
654 |
+
/**
|
655 |
+
* Returns the type of image in lowercase, if $path is true, a base filename is returned which indicates where to store the file from the root upload folder.
|
656 |
+
* @param unknown_type $path
|
657 |
+
* @return mixed|mixed
|
658 |
+
*/
|
659 |
+
function get_image_type($path = false){
|
660 |
+
$type = false;
|
661 |
+
switch( get_class($this) ){
|
662 |
+
case 'EM_Event':
|
663 |
+
$dir = (EM_IMAGE_DS == '/') ? 'events/':'';
|
664 |
+
$type = 'event';
|
665 |
+
break;
|
666 |
+
case 'EM_Location':
|
667 |
+
$dir = (EM_IMAGE_DS == '/') ? 'locations/':'';
|
668 |
+
$type = 'location';
|
669 |
+
break;
|
670 |
+
case 'EM_Category':
|
671 |
+
$dir = (EM_IMAGE_DS == '/') ? 'categories/':'';
|
672 |
+
$type = 'category';
|
673 |
+
break;
|
674 |
+
}
|
675 |
+
if($path){
|
676 |
+
return apply_filters('em_object_get_image_type',$dir.$type, $path, $this);
|
677 |
+
}
|
678 |
+
return apply_filters('em_object_get_image_type',$type, $path, $this);
|
679 |
+
}
|
680 |
+
|
681 |
+
function get_image_url(){
|
682 |
+
if( !empty($this->id) ){
|
683 |
+
$type = $this->get_image_type();
|
684 |
+
$id = ( get_class($this) == "EM_Event" && $this->is_recurrence() ) ? $this->recurrence_id:$this->id; //quick fix for recurrences
|
685 |
+
if( $type ){
|
686 |
+
if($this->image_url == ''){
|
687 |
+
foreach($this->mime_types as $mime_type) {
|
688 |
+
$file_name = $this->get_image_type(true)."-{$id}.$mime_type";
|
689 |
+
if( file_exists( EM_IMAGE_UPLOAD_DIR . $file_name) ) {
|
690 |
+
$this->image_url = EM_IMAGE_UPLOAD_URI.$file_name;
|
691 |
+
}
|
692 |
+
}
|
693 |
+
}
|
694 |
+
}
|
695 |
+
}
|
696 |
+
return apply_filters('em_object_get_image_url', $this->image_url, $this);
|
697 |
+
}
|
698 |
+
|
699 |
+
function image_delete() {
|
700 |
+
$type = $this->get_image_type();
|
701 |
+
if( $type ){
|
702 |
+
if( $this->image_url == '' ){
|
703 |
+
$result = true;
|
704 |
+
}else{
|
705 |
+
$file_name= EM_IMAGE_UPLOAD_DIR.$this->get_image_type(true)."-".$this->id;
|
706 |
+
$result = false;
|
707 |
+
foreach($this->mime_types as $mime_type) {
|
708 |
+
if (file_exists($file_name.".".$mime_type)){
|
709 |
+
$result = unlink($file_name.".".$mime_type);
|
710 |
+
}
|
711 |
+
}
|
712 |
+
}
|
713 |
+
}
|
714 |
+
return apply_filters('em_object_get_image_url', $result, $this);
|
715 |
+
}
|
716 |
+
|
717 |
+
function image_upload($result, $object){
|
718 |
+
//due to php versions and handling of refernece we'll just reference the $object instead of $this, essentially making this a static function
|
719 |
+
$type = $object->get_image_type();
|
720 |
+
if( $result && $type ){
|
721 |
+
do_action('em_object_image_upload_pre', $type, $object);
|
722 |
+
if ( !empty($_FILES[$type.'_image']['size']) && file_exists($_FILES[$type.'_image']['tmp_name'])) {
|
723 |
+
$object->image_delete();
|
724 |
+
list($width, $height, $mime_type, $attr) = getimagesize($_FILES[$type.'_image']['tmp_name']);
|
725 |
+
$image_path = $object->get_image_type(true)."-".$object->id.".".$object->mime_types[$mime_type];
|
726 |
+
if( $object->image_validate()){
|
727 |
+
if ( move_uploaded_file($_FILES[$type.'_image']['tmp_name'], EM_IMAGE_UPLOAD_DIR.$image_path) ){
|
728 |
+
$object->image_url = EM_IMAGE_UPLOAD_URI.$image_path;
|
729 |
+
}else{
|
730 |
+
if($result){
|
731 |
+
$object->feedback_message .= ' '. __('However, the image could not be saved.','dbem');
|
732 |
+
}
|
733 |
+
$object->add_error(__('The image could not be saved','dbem'));
|
734 |
+
}
|
735 |
+
}else{
|
736 |
+
if($result){
|
737 |
+
$object->feedback_message .= ' '. __('However, the image could not be saved:','dbem');
|
738 |
+
$object->feedback_message .= '<p>'.implode('<br />',$object->errors).'</p>';
|
739 |
+
}
|
740 |
+
}
|
741 |
+
}
|
742 |
+
}
|
743 |
+
return apply_filters('em_object_image_upload', $result, $object);
|
744 |
+
}
|
745 |
+
|
746 |
+
function image_validate(){
|
747 |
+
$type = $this->get_image_type();
|
748 |
+
if( $type ){
|
749 |
+
if ( !empty($_FILES[$type.'_image']) && $_FILES[$type.'_image']['size'] > 0 ) {
|
750 |
+
if (is_uploaded_file($_FILES[$type.'_image']['tmp_name'])) {
|
751 |
+
list($width, $height, $mime_type, $attr) = getimagesize($_FILES[$type.'_image']['tmp_name']);
|
752 |
+
$maximum_size = get_option('dbem_image_max_size');
|
753 |
+
if ($_FILES[$type.'_image']['size'] > $maximum_size){
|
754 |
+
$this->add_error( __('The image file is too big! Maximum size:', 'dbem')." $maximum_size");
|
755 |
+
}
|
756 |
+
$maximum_width = get_option('dbem_image_max_width');
|
757 |
+
$maximum_height = get_option('dbem_image_max_height');
|
758 |
+
if (($width > $maximum_width) || ($height > $maximum_height)) {
|
759 |
+
$this->add_error( __('The image is too big! Maximum size allowed:','dbem')." $maximum_width x $maximum_height");
|
760 |
+
}
|
761 |
+
if ( empty($mime_type) || !array_key_exists($mime_type, $this->mime_types) ){
|
762 |
+
$this->add_error(__('The image is in a wrong format!','dbem'));
|
763 |
+
}
|
764 |
+
}
|
765 |
+
}
|
766 |
+
}
|
767 |
+
return apply_filters('em_object_image_validate', count($this->errors) == 0, $this);
|
768 |
+
}
|
769 |
+
/*
|
770 |
+
* END IMAGE UPlOAD FUNCTIONS
|
771 |
+
*/
|
772 |
}
|
classes/em-people.php
CHANGED
@@ -1,129 +1,85 @@
|
|
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 ".
|
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 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
//
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
}
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
*/
|
86 |
-
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 |
?>
|
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 ". 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 |
+
* Handles the action of someone being deleted on wordpress
|
68 |
+
* @param int $id
|
69 |
+
*/
|
70 |
+
function user_deleted( $id ){
|
71 |
+
global $wpdb;
|
72 |
+
if( current_user_can('delete_users') ){
|
73 |
+
if( $_REQUEST['delete_option'] == 'reassign' && is_numeric($_REQUEST['reassign_user']) ){
|
74 |
+
$wpdb->update(EM_EVENTS_TABLE, array('event_owner'=>$_REQUEST['reassign_user']), array('event_owner'=>$id));
|
75 |
+
}else{
|
76 |
+
//User is being deleted, so we delete their events and cancel their bookings.
|
77 |
+
$wpdb->query("DELETE FROM ".EM_EVENTS_TABLE." WHERE event_owner=$id");
|
78 |
+
}
|
79 |
+
}
|
80 |
+
//set bookings to cancelled
|
81 |
+
$wpdb->update(EM_BOOKINGS_TABLE, array('booking_status'=>3, 'person_id'=>0, 'booking_comment'=>__('User deleted by administrators','dbem')), array('person_id'=>$id));
|
82 |
+
}
|
83 |
+
}
|
84 |
+
add_action('delete_user', array('EM_People','user_deleted'), 1,10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
?>
|
classes/em-permalinks.php
ADDED
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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', 'bookings_page', 'payment_gateway','event_categories','event_locations'
|
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'), 1);
|
25 |
+
add_action('template_redirect',array('EM_Permalinks','redirection'), 1);
|
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 |
+
add_filter('em_category_output_placeholder',array('EM_Permalinks','rewrite_urls'),1,3);
|
30 |
+
}
|
31 |
+
|
32 |
+
function flush(){
|
33 |
+
global $wp_rewrite;
|
34 |
+
if( get_option('dbem_flush_needed') ){
|
35 |
+
$wp_rewrite->flush_rules();
|
36 |
+
delete_option('dbem_flush_needed');
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
function rewrite_urls($replace, $object, $result){
|
41 |
+
global $wp_query, $wp_rewrite;
|
42 |
+
if( $wp_rewrite->using_permalinks() && !defined('EM_DISABLE_PERMALINKS')){
|
43 |
+
switch( $result ){
|
44 |
+
case '#_EVENTPAGEURL': //Depreciated
|
45 |
+
case '#_LINKEDNAME': //Depreciated
|
46 |
+
case '#_EVENTURL': //Just the URL
|
47 |
+
case '#_EVENTLINK': //HTML Link
|
48 |
+
if( is_object($object) && get_class($object)=='EM_Event' ){
|
49 |
+
$EM_URI = EM_URI;
|
50 |
+
if( is_multisite() && get_site_option('dbem_ms_global_events') && get_site_option('dbem_ms_global_events_links') && !empty($object->blog_id) && is_main_site() && $object->blog_id != get_current_blog_id() ){
|
51 |
+
$EM_URI = get_blog_permalink($object->blog_id, get_blog_option($object->blog_id, 'dbem_events_page'));
|
52 |
+
}
|
53 |
+
$event_link = trailingslashit(trailingslashit($EM_URI).'event/'.$object->slug);
|
54 |
+
if($result == '#_LINKEDNAME' || $result == '#_EVENTLINK'){
|
55 |
+
$replace = "<a href='{$event_link}' title='{$object->name}'>{$object->name}</a>";
|
56 |
+
}else{
|
57 |
+
$replace = $event_link;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
break;
|
61 |
+
case '#_LOCATIONURL':
|
62 |
+
case '#_LOCATIONLINK':
|
63 |
+
case '#_LOCATIONPAGEURL': //Depreciated
|
64 |
+
if( is_object($object) && get_class($object)=='EM_Location' ){
|
65 |
+
$link = trailingslashit(trailingslashit(EM_URI).'location/'.$object->slug);
|
66 |
+
$replace = ($result == '#_LOCATIONURL' || $result == '#_LOCATIONPAGEURL') ? $link : '<a href="'.$link.'">'.$object->name.'</a>';
|
67 |
+
}
|
68 |
+
break;
|
69 |
+
case '#_CATEGORYLINK':
|
70 |
+
case '#_CATEGORYURL':
|
71 |
+
if( is_object($object) && get_class($object)=='EM_Category' ){
|
72 |
+
$link = trailingslashit(trailingslashit(EM_URI).'category/'.$object->slug);
|
73 |
+
$replace = ($result == '#_CATEGORYURL') ? $link : '<a href="'.$link.'">'.$object->name.'</a>';
|
74 |
+
}
|
75 |
+
break;
|
76 |
+
}
|
77 |
+
}
|
78 |
+
return $replace;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* will redirect old links to new link structures.
|
83 |
+
* @return mixed
|
84 |
+
*/
|
85 |
+
function redirection(){
|
86 |
+
global $wp_rewrite, $post, $wp_query;
|
87 |
+
if( $wp_rewrite->using_permalinks() && !is_admin() && !defined('EM_DISABLE_PERMALINKS') ){
|
88 |
+
//is this a querystring url?
|
89 |
+
$events_page_id = get_option ( 'dbem_events_page' );
|
90 |
+
if ( is_object($post) && $post->ID == $events_page_id && $events_page_id != 0 ) {
|
91 |
+
$page = ( !empty($_GET['page']) && is_numeric($_GET['page']) )? $_GET['page'] : '';
|
92 |
+
if ( !empty($_GET['calendar_day']) ) {
|
93 |
+
//Events for a specific day
|
94 |
+
wp_redirect( self::url($_GET['calendar_day'],$page), 301);
|
95 |
+
exit();
|
96 |
+
} elseif ( !empty($_GET['location_id']) && is_numeric($_GET['location_id']) ) {
|
97 |
+
//Just a single location
|
98 |
+
$EM_Location = new EM_Location($_GET['location_id']);
|
99 |
+
wp_redirect( self::url('location', $EM_Location->slug,$page), 301);
|
100 |
+
exit();
|
101 |
+
} elseif ( !empty($_GET['event_id']) && is_numeric($_GET['event_id']) ) {
|
102 |
+
//single event page
|
103 |
+
$EM_Event = new EM_Event($_GET['event_id']);
|
104 |
+
wp_redirect( self::url('event', $EM_Event->slug), 301);
|
105 |
+
exit();
|
106 |
+
}
|
107 |
+
}
|
108 |
+
if( !empty($_GET['dbem_rss']) ){
|
109 |
+
//RSS page
|
110 |
+
wp_redirect( self::url('rss'), 301);
|
111 |
+
exit();
|
112 |
+
}
|
113 |
+
}
|
114 |
+
}
|
115 |
+
// Adding a new rule
|
116 |
+
function rewrite_rules_array($rules){
|
117 |
+
//get the slug of the event page
|
118 |
+
$events_page_id = get_option ( 'dbem_events_page' );
|
119 |
+
$events_page = get_post($events_page_id);
|
120 |
+
$em_rules = array();
|
121 |
+
if( is_object($events_page) ){
|
122 |
+
$events_slug = str_replace(trailingslashit(get_bloginfo('wpurl')),'', get_permalink($events_page->ID));
|
123 |
+
$events_slug = str_replace(trailingslashit(get_bloginfo('url')),'', get_permalink($events_page->ID));
|
124 |
+
$events_slug = preg_replace('/\/$/','',$events_slug);
|
125 |
+
$em_rules[$events_slug.'/('.self::$scopes.')$'] = 'index.php?pagename='.$events_slug.'&scope=$matches[1]'; //events with scope
|
126 |
+
$em_rules[$events_slug.'/(\d{4}-\d{2}-\d{2})$'] = 'index.php?pagename='.$events_slug.'&calendar_day=$matches[1]'; //event calendar date search
|
127 |
+
$em_rules[$events_slug.'/event/(\d*)$'] = 'index.php?pagename='.$events_slug.'&event_id=$matches[1]'; //single event page with id
|
128 |
+
$em_rules[$events_slug.'/my\-bookings$'] = 'index.php?pagename='.$events_slug.'&bookings_page=1'; //page for users to manage bookings
|
129 |
+
$em_rules[$events_slug.'/my\-bookings/(\d+)$'] = 'index.php?pagename='.$events_slug.'&booking_id=$matches[1]'; //page for users to manage bookings
|
130 |
+
$em_rules[$events_slug.'/bookings/(\d+)$'] = 'index.php?pagename='.$events_slug.'&event_id=$matches[1]&book=1'; //single event booking form with id
|
131 |
+
$em_rules[$events_slug.'/bookings/(.+)$'] = 'index.php?pagename='.$events_slug.'&event_slug=$matches[1]&book=1'; //single event booking form with slug
|
132 |
+
$em_rules[$events_slug.'/event/(.+)$'] = 'index.php?pagename='.$events_slug.'&event_slug=$matches[1]'; //single event page with slug
|
133 |
+
$em_rules[$events_slug.'/locations$'] = 'index.php?pagename='.$events_slug.'&event_locations=1'; //category list with slug
|
134 |
+
$em_rules[$events_slug.'/location/(\d+)$'] = 'index.php?pagename='.$events_slug.'&location_id=$matches[1]'; //location page with id
|
135 |
+
$em_rules[$events_slug.'/location/(.+)$'] = 'index.php?pagename='.$events_slug.'&location_slug=$matches[1]'; //location page with slug
|
136 |
+
$em_rules[$events_slug.'/categories$'] = 'index.php?pagename='.$events_slug.'&event_categories=1'; //category list with slug
|
137 |
+
$em_rules[$events_slug.'/category/(.+)$'] = 'index.php?pagename='.$events_slug.'&category_slug=$matches[1]'; //category page with slug
|
138 |
+
$em_rules[$events_slug.'/rss$'] = 'index.php?pagename='.$events_slug.'&rss=1'; //rss page
|
139 |
+
$em_rules[$events_slug.'/ical$'] = 'index.php?pagename='.$events_slug.'&ical=1'; //ical page
|
140 |
+
$em_rules[$events_slug.'/payments/(.+)$'] = 'index.php?pagename='.$events_slug.'&payment_gateway=$matches[1]'; //single event booking form with slug
|
141 |
+
$em_rules[$events_slug.'/(\d+)$'] = 'index.php?pagename='.$events_slug.'&page=$matches[1]'; //event pageno
|
142 |
+
}
|
143 |
+
return $em_rules + $rules;
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
* 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.
|
148 |
+
* @param mixed
|
149 |
+
*/
|
150 |
+
function url(){
|
151 |
+
global $wp_rewrite;
|
152 |
+
$args = func_get_args();
|
153 |
+
$em_uri = get_permalink(get_option("dbem_events_page")); //PAGE URI OF EM
|
154 |
+
if ( $wp_rewrite->using_permalinks() && !defined('EM_DISABLE_PERMALINKS') ) {
|
155 |
+
$event_link = trailingslashit(trailingslashit($em_uri). implode('/',$args));
|
156 |
+
}
|
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() && !defined('EM_DISABLE_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 |
+
}
|
201 |
+
|
202 |
+
//Specific links that aren't generated by objects
|
203 |
+
|
204 |
+
/**
|
205 |
+
* returns the url of the my bookings page, depending on the settings page and if BP is installed.
|
206 |
+
* @return string
|
207 |
+
*/
|
208 |
+
function em_get_my_bookings_url(){
|
209 |
+
global $bp, $wp_rewrite;
|
210 |
+
if( is_object($bp) ){
|
211 |
+
//get member url
|
212 |
+
return $bp->events->link.'attending/';
|
213 |
+
}elseif( get_option('dbem_bookings_my_page') ){
|
214 |
+
return get_permalink(get_option('dbem_bookings_my_page'));
|
215 |
+
}else{
|
216 |
+
if( $wp_rewrite->using_permalinks() && !defined('EM_DISABLE_PERMALINKS') ){
|
217 |
+
return trailingslashit(EM_URI)."my-bookings/";
|
218 |
+
}else{
|
219 |
+
return preg_match('/\?/',EM_URI) ? EM_URI.'&bookings_page=1':EM_URI.'?bookings_page=1';
|
220 |
+
}
|
221 |
+
}
|
222 |
+
}
|
classes/em-person.php
CHANGED
@@ -1,154 +1,70 @@
|
|
1 |
-
<?php
|
2 |
-
// TODO make person details more secure and integrate with WP user data
|
3 |
-
class EM_Person extends
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
$
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
* @return
|
43 |
-
*/
|
44 |
-
function
|
45 |
-
global $wpdb;
|
46 |
-
$
|
47 |
-
foreach($
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
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 |
?>
|
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::__construct($person_id, $username);
|
19 |
+
}elseif( is_numeric($person_id) && $person_id == 0 ){
|
20 |
+
$this->ID = 0;
|
21 |
+
$this->display_name = 'Non-Registered User';
|
22 |
+
$this->user_email = 'n/a';
|
23 |
+
}else{
|
24 |
+
parent::__construct($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 |
+
$EM_Booking = new EM_Booking(); //empty booking for fields
|
33 |
+
$results = $wpdb->get_results("SELECT b.".implode(', b.', array_keys($EM_Booking->fields))." FROM ".EM_BOOKINGS_TABLE." b, ".EM_EVENTS_TABLE." e WHERE e.event_id=b.event_id AND person_id={$this->id} ORDER BY event_start_date DESC",ARRAY_A);
|
34 |
+
$bookings = array();
|
35 |
+
foreach($results as $booking_data){
|
36 |
+
$bookings[] = new EM_Booking($booking_data);
|
37 |
+
}
|
38 |
+
return new EM_Bookings($bookings);
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @return EM_Events
|
43 |
+
*/
|
44 |
+
function get_events(){
|
45 |
+
global $wpdb;
|
46 |
+
$events = array();
|
47 |
+
foreach( $this->get_bookings()->get_bookings() as $EM_Booking ){
|
48 |
+
$events[$EM_Booking->event_id] = $EM_Booking->get_event();
|
49 |
+
}
|
50 |
+
return $events;
|
51 |
+
}
|
52 |
+
|
53 |
+
function display_summary(){
|
54 |
+
ob_start();
|
55 |
+
?>
|
56 |
+
<table>
|
57 |
+
<tr>
|
58 |
+
<td><?php echo get_avatar($this->ID); ?></td>
|
59 |
+
<td style="padding-left:10px; vertical-align: top;">
|
60 |
+
<strong><?php _e('Name','dbem'); ?></strong> : <?php echo $this->display_name; ?><br /><br />
|
61 |
+
<strong><?php _e('Email','dbem'); ?></strong> : <?php echo $this->user_email; ?><br /><br />
|
62 |
+
<strong><?php _e('Phone','dbem'); ?></strong> : <?php echo $this->phone; ?>
|
63 |
+
</td>
|
64 |
+
</tr>
|
65 |
+
</table>
|
66 |
+
<?php
|
67 |
+
return ob_get_clean();
|
68 |
+
}
|
69 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
?>
|
classes/em-recurrence.php
DELETED
@@ -1,89 +0,0 @@
|
|
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
ADDED
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 ". 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 = 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 ". 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
ADDED
@@ -0,0 +1,338 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = 10;
|
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 |
+
$this->name = __('Standard Ticket','dbem');
|
52 |
+
if( $ticket_data !== false ){
|
53 |
+
//Load ticket data
|
54 |
+
$ticket = array();
|
55 |
+
if( is_array($ticket_data) ){
|
56 |
+
$ticket = $ticket_data;
|
57 |
+
}elseif( is_numeric($ticket_data) ){
|
58 |
+
//Retreiving from the database
|
59 |
+
global $wpdb;
|
60 |
+
$sql = "SELECT * FROM ". EM_TICKETS_TABLE ." WHERE ticket_id ='$ticket_data'";
|
61 |
+
$ticket = $wpdb->get_row($sql, ARRAY_A);
|
62 |
+
//Ticket notes
|
63 |
+
$notes = $wpdb->get_results("SELECT * FROM ". EM_META_TABLE ." WHERE meta_key='ticket-note' AND object_id ='$ticket_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($ticket);
|
70 |
+
$this->start_timestamp = (!empty($ticket['ticket_start'])) ? strtotime($ticket['ticket_start']):false;
|
71 |
+
$this->end_timestamp = (!empty($ticket['ticket_end'])) ? strtotime($ticket['ticket_end']):false;
|
72 |
+
}
|
73 |
+
do_action('em_ticket',$this, $ticket_data);
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Saves the ticket into the database, whether a new or existing ticket
|
78 |
+
* @return boolean
|
79 |
+
*/
|
80 |
+
function save(){
|
81 |
+
global $wpdb;
|
82 |
+
$table = EM_TICKETS_TABLE;
|
83 |
+
do_action('em_ticket_save_pre',$this);
|
84 |
+
//First the person
|
85 |
+
if($this->validate() && $this->can_manage() ){
|
86 |
+
//Now we save the ticket
|
87 |
+
$this->event_id = $this->get_event()->id; //event wouldn't exist before save, so refresh id
|
88 |
+
$data = $this->to_array(true); //add the true to remove the nulls
|
89 |
+
if($this->id != ''){
|
90 |
+
//since currently wpdb calls don't accept null, let's build the sql ourselves.
|
91 |
+
$set_array = array();
|
92 |
+
foreach( $this->fields as $field_name => $field ){
|
93 |
+
if( empty($this->$field['name']) && $field['null'] ){
|
94 |
+
$set_array[] = "{$field_name}=NULL";
|
95 |
+
}else{
|
96 |
+
$set_array[] = "{$field_name}='".$wpdb->escape($this->$field['name'])."'";
|
97 |
+
}
|
98 |
+
}
|
99 |
+
$sql = "UPDATE $table SET ".implode(', ', $set_array)." WHERE ticket_id={$this->id}";
|
100 |
+
$result = $wpdb->query($sql);
|
101 |
+
$this->feedback_message = __('Changes saved','dbem');
|
102 |
+
}else{
|
103 |
+
//TODO better error handling
|
104 |
+
$result = $wpdb->insert($table, $data, $this->get_types($data));
|
105 |
+
$this->id = $wpdb->insert_id;
|
106 |
+
$this->feedback_message = __('Ticket created','dbem');
|
107 |
+
}
|
108 |
+
if( $result === false ){
|
109 |
+
$this->feedback_message = __('There was a problem saving the ticket.', 'dbem');
|
110 |
+
$this->errors[] = __('There was a problem saving the ticket.', 'dbem');
|
111 |
+
}
|
112 |
+
return apply_filters('em_ticket_save', ( count($this->errors) == 0 ), $this);
|
113 |
+
}else{
|
114 |
+
$this->feedback_message = __('There was a problem saving the ticket.', 'dbem');
|
115 |
+
$this->errors[] = __('There was a problem saving the ticket.', 'dbem');
|
116 |
+
return apply_filters('em_ticket_save', false, $this);
|
117 |
+
}
|
118 |
+
return true;
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Get posted data and save it into the object (not db)
|
123 |
+
* @return boolean
|
124 |
+
*/
|
125 |
+
function get_post(){
|
126 |
+
//We are getting the values via POST or GET
|
127 |
+
do_action('em_location_get_post_pre', $this);
|
128 |
+
$location = array();
|
129 |
+
$location['ticket_id'] = ( !empty($_POST['ticket_id']) ) ? $_POST['ticket_id']:'';
|
130 |
+
$location['event_id'] = ( !empty($_POST['event_id']) ) ? $_POST['event_id']:'';
|
131 |
+
$location['ticket_name'] = ( !empty($_POST['ticket_name']) ) ? stripslashes($_POST['ticket_name']):'';
|
132 |
+
$location['ticket_description'] = ( !empty($_POST['ticket_description']) ) ? stripslashes($_POST['ticket_description']):'';
|
133 |
+
$location['ticket_price'] = ( !empty($_POST['ticket_price']) ) ? $_POST['ticket_price']:'';
|
134 |
+
$location['ticket_start'] = ( !empty($_POST['ticket_start']) ) ? $_POST['ticket_start']:'';
|
135 |
+
$location['ticket_end'] = ( !empty($_POST['ticket_end']) ) ? $_POST['ticket_end']:'';
|
136 |
+
$this->start_timestamp = ( !empty($_POST['ticket_start']) ) ? strtotime($_POST['ticket_start']):'';
|
137 |
+
$this->end_timestamp = ( !empty($_POST['ticket_end']) ) ? strtotime($_POST['ticket_end']):'';
|
138 |
+
$location['ticket_min'] = ( !empty($_POST['ticket_min']) ) ? $_POST['ticket_min']:'';
|
139 |
+
$location['ticket_max'] = ( !empty($_POST['ticket_max']) ) ? $_POST['ticket_max']:'';
|
140 |
+
$location['ticket_spaces'] = ( !empty($_POST['ticket_spaces']) ) ? $_POST['ticket_spaces']:'';
|
141 |
+
$this->to_object( apply_filters('em_location_get_post', $location, $this) );
|
142 |
+
}
|
143 |
+
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Validates the ticket for saving. Should be run during any form submission or saving operation.
|
147 |
+
* @return boolean
|
148 |
+
*/
|
149 |
+
function validate(){
|
150 |
+
$missing_fields = Array ();
|
151 |
+
foreach ( $this->required_fields as $field ) {
|
152 |
+
$true_field = $this->fields[$field]['name'];
|
153 |
+
if ( $this->$true_field == "") {
|
154 |
+
$missing_fields[] = $field;
|
155 |
+
}
|
156 |
+
}
|
157 |
+
if ( count($missing_fields) > 0){
|
158 |
+
// TODO Create friendly equivelant names for missing fields notice in validation
|
159 |
+
$this->errors[] = __ ( 'Missing fields: ' ) . implode ( ", ", $missing_fields ) . ". ";
|
160 |
+
}
|
161 |
+
return apply_filters('em_event_validate', count($this->errors) == 0, $this );
|
162 |
+
}
|
163 |
+
|
164 |
+
function is_available(){
|
165 |
+
$timestamp = current_time('timestamp');
|
166 |
+
$available_spaces = $this->get_available_spaces();
|
167 |
+
$val = (empty($this->start) || $this->start_timestamp <= $timestamp);
|
168 |
+
$val2 = ($this->end_timestamp >= $timestamp || empty($this->end));
|
169 |
+
$val3 = $this->get_event()->end > current_time('timestamp');
|
170 |
+
|
171 |
+
if( (empty($this->start) || $this->start_timestamp <= $timestamp) && ($this->end_timestamp >= $timestamp || empty($this->end)) && $this->get_event()->end > current_time('timestamp') ){
|
172 |
+
//Time Constraints met, now quantities
|
173 |
+
if( $available_spaces > 0 && ($available_spaces >= $this->min || empty($this->min)) ){
|
174 |
+
return apply_filters('em_ticket_is_available',true,$this);
|
175 |
+
}
|
176 |
+
}
|
177 |
+
return apply_filters('em_ticket_is_available',false,$this);
|
178 |
+
}
|
179 |
+
|
180 |
+
/**
|
181 |
+
* Gets the total price for this ticket.
|
182 |
+
* @return float
|
183 |
+
*/
|
184 |
+
function get_price($format = false){
|
185 |
+
if($format){
|
186 |
+
return apply_filters('em_ticket_get_price', em_get_currency_symbol().number_format($this->price,2),$this);
|
187 |
+
}
|
188 |
+
return apply_filters('em_ticket_get_price',$this->price,$this);
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Get the total number of tickets (spaces) available, bearing in mind event-wide maxiumums and ticket priority settings.
|
193 |
+
* @return int
|
194 |
+
*/
|
195 |
+
function get_spaces(){
|
196 |
+
return apply_filters('em_ticket_get_spaces',$this->spaces,$this);
|
197 |
+
}
|
198 |
+
|
199 |
+
/**
|
200 |
+
* Returns the number of available spaces left in this ticket, bearing in mind event-wide restrictions, previous bookings, approvals and other tickets.
|
201 |
+
* @return int
|
202 |
+
*/
|
203 |
+
function get_available_spaces(){
|
204 |
+
$event_available_spaces = $this->get_event()->get_bookings()->get_available_spaces();
|
205 |
+
$ticket_available_spaces = $this->get_spaces() - $this->get_booked_spaces();
|
206 |
+
$return = ($ticket_available_spaces <= $event_available_spaces) ? $ticket_available_spaces:$event_available_spaces;
|
207 |
+
return apply_filters('em_ticket_get_available_spaces', $return, $this);
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Returns the number of available spaces left in this ticket, bearing in mind event-wide restrictions, previous bookings, approvals and other tickets.
|
212 |
+
* @return int
|
213 |
+
*/
|
214 |
+
function get_booked_spaces($force_reload=false){
|
215 |
+
//get all bookings for this event
|
216 |
+
$spaces = 0;
|
217 |
+
if( is_object($this->bookings) && $force_reload ){
|
218 |
+
return $this->bookings;
|
219 |
+
}
|
220 |
+
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.
|
221 |
+
//foreach booking, get this ticket booking info if found
|
222 |
+
foreach($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking){
|
223 |
+
if( $EM_Ticket_Booking->ticket_id == $this->id ){
|
224 |
+
$spaces += $EM_Ticket_Booking->get_spaces();
|
225 |
+
}
|
226 |
+
}
|
227 |
+
}
|
228 |
+
return apply_filters('em_ticket_get_available_spaces', $spaces, $this);
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Smart event locator, saves a database read if possible.
|
233 |
+
* @return EM_Event
|
234 |
+
*/
|
235 |
+
function get_event(){
|
236 |
+
global $EM_Event;
|
237 |
+
if( is_object($this->event) && get_class($this->event)=='EM_Event' && ($this->event->id == $this->event_id || empty($this->event_id)) ){
|
238 |
+
return $this->event;
|
239 |
+
}elseif( is_object($EM_Event) && $EM_Event->id == $this->event_id ){
|
240 |
+
$this->event = $EM_Event;
|
241 |
+
}else{
|
242 |
+
$this->event = new EM_Event($this->event_id);
|
243 |
+
}
|
244 |
+
return $this->event;
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* returns array of EM_Booking objects that have this ticket
|
249 |
+
* @return EM_Bookings
|
250 |
+
*/
|
251 |
+
function get_bookings(){
|
252 |
+
$bookings = array();
|
253 |
+
foreach( $this->get_event()->get_bookings()->bookings as $EM_Booking ){
|
254 |
+
foreach($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking){
|
255 |
+
if( $EM_Ticket_Booking->ticket_id == $this->id ){
|
256 |
+
$bookings[$EM_Booking->id] = $EM_Booking;
|
257 |
+
}
|
258 |
+
}
|
259 |
+
}
|
260 |
+
$this->bookings = new EM_Bookings($bookings);
|
261 |
+
return $this->bookings;
|
262 |
+
}
|
263 |
+
|
264 |
+
/**
|
265 |
+
* I wonder what this does....
|
266 |
+
* @return boolean
|
267 |
+
*/
|
268 |
+
function delete(){
|
269 |
+
global $wpdb;
|
270 |
+
$result = false;
|
271 |
+
if( $this->can_manage() ){
|
272 |
+
if( count($this->get_bookings()->bookings) == 0 ){
|
273 |
+
$sql = $wpdb->prepare("DELETE FROM ". EM_TICKETS_TABLE . " WHERE ticket_id=%d", $this->id);
|
274 |
+
$result = $wpdb->query( $sql );
|
275 |
+
}else{
|
276 |
+
$this->feedback_message = __('You cannot delete a ticket that has a booking on it.','dbem');
|
277 |
+
return false;
|
278 |
+
}
|
279 |
+
}
|
280 |
+
return ( $result !== false );
|
281 |
+
}
|
282 |
+
|
283 |
+
/**
|
284 |
+
* Get the html options for quantities to go within a <select> container
|
285 |
+
* @return string
|
286 |
+
*/
|
287 |
+
function get_spaces_options($zero_value = true){
|
288 |
+
$available_spaces = $this->get_available_spaces();
|
289 |
+
if( $this->is_available() ) {
|
290 |
+
ob_start();
|
291 |
+
?>
|
292 |
+
<select name="em_tickets[<?php echo $this->id ?>][spaces]">
|
293 |
+
<?php
|
294 |
+
$min = ($this->min > 0) ? $this->min:1;
|
295 |
+
$max = ($this->max > 0) ? $this->max:get_option('dbem_bookings_form_max');
|
296 |
+
?>
|
297 |
+
<?php if($zero_value) : ?><option>0</option><?php endif; ?>
|
298 |
+
<?php for( $i=$min; $i<=$available_spaces && $i<=$max; $i++ ): ?>
|
299 |
+
<option><?php echo $i ?></option>
|
300 |
+
<?php endfor; ?>
|
301 |
+
</select>
|
302 |
+
<?php
|
303 |
+
return ob_get_clean();
|
304 |
+
}else{
|
305 |
+
return false;
|
306 |
+
}
|
307 |
+
|
308 |
+
}
|
309 |
+
|
310 |
+
/**
|
311 |
+
* Can the user manage this event?
|
312 |
+
*/
|
313 |
+
function can_manage(){
|
314 |
+
return $this->get_event()->can_manage('manage_bookings','manage_others_bookings');
|
315 |
+
}
|
316 |
+
|
317 |
+
/**
|
318 |
+
* Outputs properties with formatting
|
319 |
+
* @param string $property
|
320 |
+
* @return string
|
321 |
+
*/
|
322 |
+
function output_property($property){
|
323 |
+
switch($property){
|
324 |
+
case 'start':
|
325 |
+
$value = date_i18n( get_option('date_format'), $this->start_timestamp );
|
326 |
+
break;
|
327 |
+
case 'end':
|
328 |
+
$value = date_i18n( get_option('date_format'), $this->end_timestamp );
|
329 |
+
break;
|
330 |
+
break;
|
331 |
+
default:
|
332 |
+
$value = $this->$property;
|
333 |
+
break;
|
334 |
+
}
|
335 |
+
return apply_filters('em_ticket_output_property',$value,$this);
|
336 |
+
}
|
337 |
+
}
|
338 |
+
?>
|
classes/em-tickets-bookings.php
ADDED
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 implements Iterator{
|
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 ". EM_TICKETS_BOOKINGS_TABLE ." bt LEFT JOIN ". 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 ". EM_TICKETS_BOOKINGS_TABLE ." bt LEFT JOIN ". 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 ". EM_TICKETS_BOOKINGS_TABLE ." bt LEFT JOIN ". 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 ".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 ".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, $format = 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 |
+
if($format){
|
217 |
+
return apply_filters('em_tickets_bookings_get_prices', em_get_currency_symbol().number_format($this->price,2),$this);
|
218 |
+
}
|
219 |
+
return apply_filters('em_tickets_bookings_get_prices',$this->price,$this);
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Goes through each ticket and populates it with the bookings made
|
224 |
+
*/
|
225 |
+
function get_ticket_bookings(){
|
226 |
+
foreach( $this->tickets as $EM_Ticket ){
|
227 |
+
$EM_Ticket->get_bookings();
|
228 |
+
}
|
229 |
+
}
|
230 |
+
|
231 |
+
/* Overrides EM_Object method to apply a filter to result
|
232 |
+
* @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
|
233 |
+
*/
|
234 |
+
function build_sql_conditions( $args = array() ){
|
235 |
+
$conditions = apply_filters( 'em_tickets_build_sql_conditions', parent::build_sql_conditions($args), $args );
|
236 |
+
if( is_numeric($args['status']) ){
|
237 |
+
$conditions['status'] = 'ticket_status='.$args['status'];
|
238 |
+
}
|
239 |
+
return apply_filters('em_tickets_bookings_build_sql_conditions', $conditions, $args);
|
240 |
+
}
|
241 |
+
|
242 |
+
/* Overrides EM_Object method to apply a filter to result
|
243 |
+
* @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
|
244 |
+
*/
|
245 |
+
function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
|
246 |
+
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 );
|
247 |
+
}
|
248 |
+
|
249 |
+
/*
|
250 |
+
* Adds custom Events search defaults
|
251 |
+
* @param array $array
|
252 |
+
* @return array
|
253 |
+
* @uses EM_Object#get_default_search()
|
254 |
+
*/
|
255 |
+
function get_default_search( $array = array() ){
|
256 |
+
$defaults = array(
|
257 |
+
'status' => false,
|
258 |
+
'person' => true //to add later, search by person's tickets...
|
259 |
+
);
|
260 |
+
$defaults['owner'] = !current_user_can('manage_others_bookings') ? get_current_user_id():false;
|
261 |
+
return apply_filters('em_tickets_bookings_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
|
262 |
+
}
|
263 |
+
|
264 |
+
//Iterator Implementation
|
265 |
+
public function rewind(){
|
266 |
+
reset($this->tickets_bookings);
|
267 |
+
}
|
268 |
+
public function current(){
|
269 |
+
$var = current($this->tickets_bookings);
|
270 |
+
return $var;
|
271 |
+
}
|
272 |
+
public function key(){
|
273 |
+
$var = key($this->tickets_bookings);
|
274 |
+
return $var;
|
275 |
+
}
|
276 |
+
public function next(){
|
277 |
+
$var = next($this->tickets_bookings);
|
278 |
+
return $var;
|
279 |
+
}
|
280 |
+
public function valid(){
|
281 |
+
$key = key($this->tickets_bookings);
|
282 |
+
$var = ($key !== NULL && $key !== FALSE);
|
283 |
+
return $var;
|
284 |
+
}
|
285 |
+
}
|
286 |
+
?>
|
classes/em-tickets.php
ADDED
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Deals with the ticket info for an event
|
4 |
+
* @author marcus
|
5 |
+
*
|
6 |
+
*/
|
7 |
+
class EM_Tickets extends EM_Object implements Iterator{
|
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 ". 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 ". EM_TICKETS_TABLE ." t LEFT JOIN ". EM_TICKETS_BOOKINGS_TABLE ." bt ON bt.ticket_id=t.ticket_id WHERE booking_id ='{$this->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 |
+
}elseif( is_array($object) ){
|
53 |
+
if( is_object(current($object)) && get_class(current($object)) == 'EM_Ticket' ){
|
54 |
+
$this->tickets = $object;
|
55 |
+
}else{
|
56 |
+
foreach($object as $ticket){
|
57 |
+
$EM_Ticket = new EM_Ticket($ticket);
|
58 |
+
$EM_Ticket->event = $this->event;
|
59 |
+
$this->tickets[] = $EM_Ticket;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
}
|
63 |
+
do_action('em_tickets', $this, $object);
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* @return EM_Event
|
68 |
+
*/
|
69 |
+
function get_event(){
|
70 |
+
return $this->event;
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Get the first EM_Ticket object in this instance. Returns false if no tickets available.
|
75 |
+
* @return EM_Ticket
|
76 |
+
*/
|
77 |
+
function get_first(){
|
78 |
+
if( count($this->tickets) > 0 ){
|
79 |
+
foreach($this->tickets as $EM_Ticket){
|
80 |
+
return $EM_Ticket;
|
81 |
+
}
|
82 |
+
}else{
|
83 |
+
return false;
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Delete tickets in thie object
|
89 |
+
* @return boolean
|
90 |
+
*/
|
91 |
+
function delete(){
|
92 |
+
global $wpdb;
|
93 |
+
//get all the ticket ids
|
94 |
+
foreach( $this->tickets as $EM_Ticket ){
|
95 |
+
$ticket_ids[] = $EM_Ticket->id;
|
96 |
+
}
|
97 |
+
//check that tickets don't have bookings
|
98 |
+
$bookings = $wpdb->get_var("SELECT COUNT(*) FROM ". EM_TICKETS_BOOKINGS_TABLE." WHERE ticket_id IN (".implode(',',$ticket_ids).")");
|
99 |
+
if( $bookings > 0 ){
|
100 |
+
$result = false;
|
101 |
+
$this->add_error(__('You cannot delete tickets if there are any bookings associated with them. Please delete these bookings first.','dbem'));
|
102 |
+
}else{
|
103 |
+
$result = $wpdb->query("DELETE FROM ".EM_TICKETS_TABLE." WHERE event_id IN (".implode(',',$ticket_ids).")");
|
104 |
+
}
|
105 |
+
return ($result !== false);
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Retrieve multiple ticket info via POST
|
110 |
+
* @return boolean
|
111 |
+
*/
|
112 |
+
function get_post(){
|
113 |
+
//Build Event Array
|
114 |
+
do_action('em_tickets_get_post_pre', $this);
|
115 |
+
$this->tickets = array(); //clean current tickets out
|
116 |
+
if( !empty($_POST['em_tickets']) && is_array($_POST['em_tickets']) ){
|
117 |
+
//get all ticket data and create objects
|
118 |
+
foreach($_POST['em_tickets'] as $ticket_data){
|
119 |
+
$EM_Ticket = new EM_Ticket($ticket_data);
|
120 |
+
$this->tickets[] = $EM_Ticket;
|
121 |
+
}
|
122 |
+
}elseif( is_object($this->event) ){
|
123 |
+
//we create a blank standard ticket
|
124 |
+
$EM_Ticket = new EM_Ticket(array(
|
125 |
+
'event_id' => $this->event->id,
|
126 |
+
'ticket_name' => __('Standard','dbem')
|
127 |
+
));
|
128 |
+
$this->tickets[] = $EM_Ticket;
|
129 |
+
}
|
130 |
+
return apply_filters('em_tickets_get_post', $this->validate(), $this);
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Go through the tickets in this object and validate them
|
135 |
+
*/
|
136 |
+
function validate(){
|
137 |
+
$errors = array();
|
138 |
+
foreach($this->tickets as $EM_Ticket){
|
139 |
+
$errors[] = $EM_Ticket->validate();
|
140 |
+
}
|
141 |
+
return apply_filters('em_tickets_validate', !in_array(false, $errors), $this);
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Save tickets into DB
|
146 |
+
*/
|
147 |
+
function save(){
|
148 |
+
$errors = array();
|
149 |
+
foreach( $this->tickets as $EM_Ticket ){
|
150 |
+
$EM_Ticket->event = $this->event; //pass on saved event_data
|
151 |
+
$errors[] = $EM_Ticket->save();
|
152 |
+
}
|
153 |
+
return apply_filters('em_tickets_save', !in_array(false, $errors), $this);
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Goes through each ticket and populates it with the bookings made
|
158 |
+
*/
|
159 |
+
function get_ticket_bookings(){
|
160 |
+
foreach( $this->tickets as $EM_Ticket ){
|
161 |
+
$EM_Ticket->get_bookings();
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* 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.
|
167 |
+
* @param boolean $force_refresh
|
168 |
+
* @return int
|
169 |
+
*/
|
170 |
+
function get_spaces( $force_refresh=false ){
|
171 |
+
$spaces = 0;
|
172 |
+
if($force_refresh || $this->spaces == 0){
|
173 |
+
foreach( $this->tickets as $EM_Ticket ){
|
174 |
+
/* @var $EM_Ticket EM_Ticket */
|
175 |
+
$spaces += $EM_Ticket->get_spaces();
|
176 |
+
}
|
177 |
+
$this->spaces = $spaces;
|
178 |
+
}
|
179 |
+
return apply_filters('em_booking_get_spaces',$this->spaces,$this);
|
180 |
+
}
|
181 |
+
|
182 |
+
/* Overrides EM_Object method to apply a filter to result
|
183 |
+
* @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_conditions()
|
184 |
+
*/
|
185 |
+
function build_sql_conditions( $args = array() ){
|
186 |
+
$conditions = apply_filters( 'em_tickets_build_sql_conditions', parent::build_sql_conditions($args), $args );
|
187 |
+
if( is_numeric($args['status']) ){
|
188 |
+
$conditions['status'] = 'ticket_status='.$args['status'];
|
189 |
+
}
|
190 |
+
return apply_filters('em_tickets_build_sql_conditions', $conditions, $args);
|
191 |
+
}
|
192 |
+
|
193 |
+
/* Overrides EM_Object method to apply a filter to result
|
194 |
+
* @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby()
|
195 |
+
*/
|
196 |
+
function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){
|
197 |
+
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 );
|
198 |
+
}
|
199 |
+
|
200 |
+
/*
|
201 |
+
* Adds custom Events search defaults
|
202 |
+
* @param array $array
|
203 |
+
* @return array
|
204 |
+
* @uses EM_Object#get_default_search()
|
205 |
+
*/
|
206 |
+
function get_default_search( $array = array() ){
|
207 |
+
$defaults = array(
|
208 |
+
'status' => false,
|
209 |
+
'person' => true //to add later, search by person's tickets...
|
210 |
+
);
|
211 |
+
if( is_admin() ){
|
212 |
+
//figure out default owning permissions
|
213 |
+
$defaults['owner'] = !current_user_can('manage_others_bookings') ? get_current_user_id():false;
|
214 |
+
}
|
215 |
+
return apply_filters('em_tickets_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults);
|
216 |
+
}
|
217 |
+
|
218 |
+
//Iterator Implementation
|
219 |
+
public function rewind(){
|
220 |
+
reset($this->tickets);
|
221 |
+
}
|
222 |
+
public function current(){
|
223 |
+
$var = current($this->tickets);
|
224 |
+
return $var;
|
225 |
+
}
|
226 |
+
public function key(){
|
227 |
+
$var = key($this->tickets);
|
228 |
+
return $var;
|
229 |
+
}
|
230 |
+
public function next(){
|
231 |
+
$var = next($this->tickets);
|
232 |
+
return $var;
|
233 |
+
}
|
234 |
+
public function valid(){
|
235 |
+
$key = key($this->tickets);
|
236 |
+
$var = ($key !== NULL && $key !== FALSE);
|
237 |
+
return $var;
|
238 |
+
}
|
239 |
+
}
|
240 |
+
?>
|
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 |
-
*
|
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�: ';
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* PHPMailer language file.
|
4 |
+
* Cz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|