PluginProbe
Church Admin / 5.0.8
Church Admin v5.0.8
5.1.2 5.1.1 trunk 5.0.10 5.0.12 5.0.13 5.0.14 5.0.15 5.0.16 5.0.17 5.0.18 5.0.20 5.0.21 5.0.22 5.0.23 5.0.24 5.0.26 5.0.27 5.0.28 5.0.29 5.0.3 5.0.30 5.0.31 5.0.32 5.0.4 All 30 releases
church-admin / church-admin.php

church-admin.php in Church Admin 5.0.8, at church-admin.php

6,715 lines 313.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3
4 Plugin Name: Church Admin
5 Plugin URI: http://www.churchadminplugin.com/
6 Description: Manage church life with address book, schedule, classes, small groups, and advanced communication tools - bulk email and sms.
7 Version: 5.0.8
8 Tags: sermons, sermons, prayer, membership, SMS, Bible, events, calendar, email, small groups, contact form, giving, administration, management, child protection, safeguarding
9 Author: Andy Moyle
10 Text Domain: church-admin
11 Elementor tested up to: 3.21.4
12
13 Author URI: http://www.themoyles.co.uk
14 License:
15 ----------------------------------------
16
17
18 Copyright (C) 2010-2022 Andy Moyle
19
20
21
22 This program is free software: you can redistribute it and/or modify
23
24 it under the terms of the GNU General Public License as published by
25
26 the Free Software Foundation, either version 3 of the License, or
27
28 (at your option) any later version.
29
30
31
32 This program is distributed in the hope that it will be useful,
33
34 but WITHOUT ANY WARRANTY; without even the implied warranty of
35
36 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37
38 GNU General Public License for more details.
39
40
41
42 http://www.gnu.org/licenses/
43
44 ----------------------------------------
45 ___ _ _ _ _ _ _ _
46 |_ _| |_( )___ __ _| | | __ _| |__ ___ _ _| |_ | | ___ ___ _ _ ___
47 | || __|// __| / _` | | | / _` | '_ \ / _ \| | | | __| _ | |/ _ \/ __| | | / __|
48 | || |_ \__ \ | (_| | | | | (_| | |_) | (_) | |_| | |_ | |_| | __/\__ \ |_| \__ \
49 |___|\__| |___/ \__,_|_|_| \__,_|_.__/ \___/ \__,_|\__| \___/ \___||___/\__,_|___/
50
51
52 */
53 if(!defined('CHURCH_ADMIN_VERSION')){define('CHURCH_ADMIN_VERSION','5.0.7');}
54
55 define('CA_PAYPAL',"https://www.paypal.com/cgi-bin/webscr");
56 require_once( plugin_dir_path( __FILE__ ) .'includes/functions.php');
57 require_once( plugin_dir_path( __FILE__ ) .'elementor/elementor.php');
58 require_once( plugin_dir_path( __FILE__ ).'includes/enqueue.php');
59
60 if ( ! defined( 'ABSPATH' ) ) exit('You need Jesus!'); // Exit if accessed directly
61 if(is_admin() && !empty($_GET['page']) && $_GET['page']=='church_admin/index.php'){
62
63
64 require_once( plugin_dir_path( __FILE__ ).'includes/new-style-callbacks.php');
65 require_once( plugin_dir_path( __FILE__ ).'includes/custom_fields.php');
66 }
67
68 $church_admin_url='admin.php?page=church_admin/index.php';
69 $people_type=get_option('church_admin_people_type');
70
71 $level=get_option('church_admin_levels');
72 if(!defined('CA_ICON')){
73 define('CA_ICON','data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+Cjxzdmcgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDM2IDM2IiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiIHhtbG5zOnNlcmlmPSJodHRwOi8vd3d3LnNlcmlmLmNvbS8iIHN0eWxlPSJmaWxsLXJ1bGU6ZXZlbm9kZDtjbGlwLXJ1bGU6ZXZlbm9kZDtzdHJva2UtbGluZWpvaW46cm91bmQ7c3Ryb2tlLW1pdGVybGltaXQ6MjsiPgogICAgPGcgdHJhbnNmb3JtPSJtYXRyaXgoMC4wNzEwMTc4LDAsMCwwLjA2NjYyMzcsLTAuMjI4NzM4LDAuOTkyMTg4KSI+CiAgICAgICAgPHBhdGggZD0iTTI1NiwwTDIzOC4zLDIyTDE0Ny43LDEzNS4zTDE0Mi43LDE0MS43TDE0Mi43LDI4NEwxNy4zLDM2Mi42TDQxLjQsNDAwLjhMNTIsMzk0LjRMNTIsNTEyTDIzMy4zLDUxMkwyMzMuMyw0MjEuNEMyMzMuMyw0MDguNiAyNDMuMSwzOTguNyAyNTYsMzk4LjdDMjY4LjgsMzk4LjcgMjc4LjcsNDA4LjUgMjc4LjcsNDIxLjRMMjc4LjcsNTEyTDQ2MCw1MTJMNDYwLDM5NC40TDQ3MC42LDQwMC44TDQ5NC43LDM2Mi42TDM2OS4zLDI4NEwzNjkuMywxNDEuNkwzNjQuMywxMzUuMkwyNzMuNywyMkwyNTYsMFpNMjU2LDcyLjJMMzI0LDE1Ny4yTDMyNCwyNTUuNkwyNjgsMjIwLjlMMjU2LDIxMy4xTDI0NCwyMjAuOUwxODgsMjU1LjZMMTg4LDE1Ny4yTDI1Niw3Mi4yWk0yNTYsMTQ5LjRDMjQzLjUsMTQ5LjQgMjMzLjMsMTU5LjYgMjMzLjMsMTcyLjFDMjMzLjMsMTg0LjYgMjQzLjUsMTk0LjggMjU2LDE5NC44QzI2OC41LDE5NC44IDI3OC43LDE4NC42IDI3OC43LDE3Mi4xQzI3OC43LDE1OS42IDI2OC41LDE0OS40IDI1NiwxNDkuNFpNMjU2LDI2N0w0MTQuNiwzNjYuMUw0MTQuNiw0NjYuN0wzMjQsNDY2LjdMMzI0LDQyMS40QzMyNCwzODQuMSAyOTMuMywzNTMuNCAyNTYsMzUzLjRDMjE4LjcsMzUzLjQgMTg4LDM4NC4xIDE4OCw0MjEuNEwxODgsNDY2LjdMOTcuNCw0NjYuN0w5Ny40LDM2Ni4xTDI1NiwyNjdaIiBzdHlsZT0iZmlsbDpyZ2IoMTU2LDE2MiwxNjcpO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpyZ2IoMTU2LDE2MiwxNjcpO3N0cm9rZS13aWR0aDoxNC41MnB4OyIvPgogICAgPC9nPgo8L3N2Zz4K');
74
75 }
76 /***************************
77 *
78 * Export ical
79 *
80 ****************************/
81 add_action('wp_loaded','church_admin_ical_download');
82 function church_admin_ical_download()
83 {
84 if(empty($_GET['page']) || $_GET['page']!='church_admin/index.php'){return;}
85 if(!empty( $_GET['action'] )&&$_GET['action']=='export-ics')
86 {
87 if(!church_admin_level_check('Calendar') )exit('No download permission');
88 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
89 church_admin_export_ical();
90 exit();
91 }
92
93 }
94
95
96
97
98 add_action('wp_loaded','church_admin_debug_mode_switch');
99 function church_admin_debug_mode_switch()
100 {
101
102 /***************************
103 *
104 * Debug Mode
105 *
106 ****************************/
107 if(!empty( $_GET['action'] )&& $_GET['action']=='toggle-debug-mode' )
108 {
109 if (empty($_GET['_wpnonce']) || ! wp_verify_nonce($_GET['_wpnonce'], 'toggle-debug-mode' ) ) {
110 die( __( 'Failed security check', 'church-admin' ) );
111 }
112 $debug=get_option('church_admin_debug_mode');
113 if ( empty( $debug ) )
114 {
115 update_option('church_admin_debug_mode',TRUE);
116
117 setcookie('ca_debug_mode', 'DEBUG MODE ON', time()+31556926);
118 if(!defined('CA_DEBUG')){define('CA_DEBUG',TRUE);}
119 }
120 else
121 {
122
123 unset( $_COOKIE['ca_debug_mode'] );
124 setcookie('ca_debug_mode', "", time() - 3600);
125 delete_option('church_admin_debug_mode',FALSE);
126 }
127 }
128
129
130 global $church_admin_url;
131
132 if(!empty( $_COOKIE['ca_debug_mode'] ) )
133 {
134 if(!(defined('CA_DEBUG') ))define('CA_DEBUG',TRUE);
135 }
136 /*
137 $debug_mode=get_option('church_admin_debug_mode');
138 if(!empty( $debug_mode) )
139 {
140 if(!(defined('CA_DEBUG') ))define('CA_DEBUG',TRUE);
141 }
142 */
143 }
144
145
146
147
148
149 add_action('admin_init','church_admin_admin_init');
150 function church_admin_admin_init() {
151
152
153
154 if(empty($_GET['page']) || $_GET['page']!='church_admin/index.php'){return;}
155
156 global $wpdb, $church_admin_url,$church_admin_menu;
157
158
159
160
161 $church_admin_menu=array(
162
163 'people'=>array(
164
165 'module'=>'People',
166 'parent'=>'people',
167 'level'=>'Directory',
168 'section'=>'people',
169 'title'=>esc_html( __('People','church-admin' ) ),
170 'link'=>wp_nonce_url($church_admin_url.'&amp;action=people&section=people','people'),
171 "dashicon"=>'dashicons-id',
172 "font-awesome"=>'<span class="ca-dashicons dashicons dashicons-admin-users ca-dashicons"></span>',
173 "background"=>"ca-yellow",
174 "callback"=>'church_admin_people_callback'
175 ),
176 'check-directory-issues'=>array(
177 'module'=>'People',
178 'parent'=>'people',
179 'level'=>'Directory',
180 'section'=>'people',
181 'title'=>esc_html( __('Check for Directory issues','church-admin' ) ),
182 'link'=>wp_nonce_url($church_admin_url.'&action=check-directory-issues&amp;section=people','check-directory-issues')
183 ),
184 'import-from-users'=>array(
185 'module'=>'People',
186 'parent'=>'people',
187 'level'=>'Directory',
188 'section'=>'people',
189 'title'=>esc_html( __('Import users into directory','church-admin' ) ),
190 'link'=>wp_nonce_url($church_admin_url.'&action=import-from-users&amp;section=people','import-from-users')
191 ),
192
193 'view-address-list'=>array(
194 'module'=>'People',
195 'parent'=>'people',
196 'level'=>'Directory',
197 'section'=>'people',
198 'title'=>esc_html( __('View address list','church-admin' ) ),
199 'link'=>wp_nonce_url($church_admin_url.'&action=view-address-list&amp;section=people','view-address-list')
200 ),
201 'add-household'=>array(
202 'module'=>'People',
203 'parent'=>'people',
204 'level'=>'Directory',
205 'section'=>'people',
206 'title'=>esc_html( __('Add household','church-admin' ) ),
207 'link'=>wp_nonce_url($church_admin_url.'&action=add-household&amp;section=people', 'add-household')
208 ),
209 'import-csv'=>array(
210 'module'=>'People',
211 'parent'=>'people',
212 'level'=>'Directory',
213 'section'=>'people',
214 'title'=>esc_html( __('Import CSV','church-admin' ) ),
215 'link'=>wp_nonce_url($church_admin_url.'&action=import-csv&amp;section=people','import-csv')
216 ),
217 'directory-pdf'=>array(
218 'module'=>'People',
219 'parent'=>'people',
220 'level'=>'Directory',
221 'section'=>'people',
222 'title'=>esc_html( __('Directory PDF','church-admin' ) ),
223 'link'=>wp_nonce_url($church_admin_url.'&action=export-pdf&amp;section=people','address-list')
224 ),
225 'member-types'=>array(
226 'module'=>'People',
227 'parent'=>'people',
228 'level'=>'Directory',
229 'section'=>'people',
230 'title'=>esc_html( __('Member types','church-admin' ) ),
231 'link'=>wp_nonce_url($church_admin_url.'&action=member-types&amp;section=people','member-types')
232 ),
233 'edit-member-type'=>array(
234 'module'=>'People',
235 'parent'=>'people',
236 'level'=>'Directory',
237 'section'=>'people',
238 'title'=>esc_html( __('Add member type','church-admin' ) ),
239 'link'=>wp_nonce_url($church_admin_url.'&action=edit-member-type&amp;section=people','edit-member-type')
240 ),
241
242
243 'bulk-geocode'=>array(
244 'module'=>'People',
245 'parent'=>'people',
246 'level'=>'Directory',
247 'section'=>'people',
248 'title'=>esc_html( __('Bulk geocode ','church-admin' ) ),
249 'link'=>wp_nonce_url($church_admin_url.'&action=bulk-geocode&amp;section=people','bulk-geocode')
250 ),
251 'bulk-edit-anniversary'=>array(
252 'module'=>'People',
253 'parent'=>'people',
254 'level'=>'Directory',
255 'section'=>'people',
256 'confirm'=>TRUE,
257 'title'=>esc_html( __('Bulk edit anniversaries','church-admin' ) ),
258 'link'=>wp_nonce_url($church_admin_url.'&action=bulk-edit-anniversary&amp;section=people','bulk-edit-anniversary')
259 ),
260 'bulk-edit-comms-permissions'=>array(
261 'module'=>'People',
262 'parent'=>'people',
263 'level'=>'Directory',
264 'section'=>'people',
265 'confirm'=>TRUE,
266 'title'=>esc_html( __('Bulk edit email permissions','church-admin' ) ),
267 'link'=>wp_nonce_url($church_admin_url.'&action=bulk-edit-comms-permissions&amp;section=people','bulk-edit-comms-permissions')
268 ),
269 'bulk-edit-custom'=>array(
270 'module'=>'People',
271 'parent'=>'people',
272 'level'=>'Directory',
273 'section'=>'people',
274 'confirm'=>TRUE,
275 'title'=>esc_html( __('Bulk edit custom field entries','church-admin' ) ),
276 'link'=>wp_nonce_url($church_admin_url.'&action=bulk-edit-custom&amp;section=people', 'bulk-edit-custom')
277 ),
278 'bulk-edit-dob'=>array(
279 'module'=>'People',
280 'parent'=>'people',
281 'level'=>'Directory',
282 'section'=>'people',
283 'confirm'=>TRUE,
284 'title'=>esc_html( __('Bulk edit dates of birth','church-admin' ) ),
285 'link'=>wp_nonce_url($church_admin_url.'&action=bulk-edit-dob&amp;section=people','bulk-edit-dob')
286 ),
287 'create-users'=>array(
288 'module'=>'People',
289 'parent'=>'people',
290 'level'=>'Directory',
291 'section'=>'people',
292 'title'=>esc_html( __('Create users ','church-admin' ) ).' &raquo;',
293 'link'=>wp_nonce_url($church_admin_url.'&action=create-users&amp;section=people','create-users')
294 ),
295 'custom-fields'=>array(
296 'module'=>'People',
297 'parent'=>'people',
298 'level'=>'Directory',
299 'section'=>'people',
300 'title'=>esc_html( __('Custom fields','church-admin' ) ),
301 'link'=>wp_nonce_url($church_admin_url.'&action=custom-fields&amp;section=people','custom-fields')
302 ),
303 'download-csv'=>array(
304 'module'=>'People',
305 'parent'=>'people',
306 'level'=>'Directory',
307 'section'=>'people',
308 'title'=>esc_html( __('Download CSV/labels ','church-admin' ) ).' &raquo;',
309 'link'=>wp_nonce_url($church_admin_url.'&action=download-csv&amp;section=people','download-csv')
310 ),
311 'recent-activity'=>array(
312 'module'=>'People',
313 'parent'=>'people',
314 'level'=>'Directory',
315 'section'=>'people',
316 'title'=>esc_html( __('Recent people activity ','church-admin' ) ),
317 'link'=>wp_nonce_url($church_admin_url.'&action=recent-activity&amp;section=people','recent-activity')
318 ),
319 'check-duplicates'=>array(
320 'module'=>'People',
321 'parent'=>'people',
322 'level'=>'Directory',
323 'section'=>'people',
324 'title'=>esc_html( __('Check duplicates','church-admin' ) ),
325 'link'=>wp_nonce_url($church_admin_url.'&action=check-duplicates&amp;section=people','check-duplicates')
326 ),
327
328 'photo-permissions'=>array(
329 'module'=>'People',
330 'parent'=>'people',
331 'level'=>'Directory',
332 'section'=>'people',
333 'title'=>esc_html( __('Photo Permissions','church-admin' ) ),
334 'link'=>wp_nonce_url($church_admin_url.'&action=photo-permissions&amp;section=people','photo-permissions')
335 ),
336 'photo-permissions-pdf'=>array(
337 'module'=>'People',
338 'parent'=>'people',
339 'level'=>'Directory',
340 'section'=>'people',
341 'title'=>esc_html( __('Photo Permissions PDF','church-admin' ) ),
342 'link'=>wp_nonce_url($church_admin_url.'&action=photo-permissions-pdf&amp;section=people','photo-permissions-pdf')
343 ),
344 'everyone-visible'=>array(
345 'module'=>'People',
346 'parent'=>'people',
347 'level'=>'Directory',
348 'section'=>'people',
349 'title'=>esc_html( __('Everyone visible','church-admin' ) ),
350 'link'=>wp_nonce_url($church_admin_url.'&action=everyone-visible&amp;section=people','everyone-visible')
351 ),
352 'delete-all'=>array(
353 'module'=>'People',
354 'parent'=>'people',
355 'level'=>'Directory',
356 'section'=>'people',
357 'confirm'=>TRUE,
358 'title'=>esc_html( __('Delete all','church-admin' ) ),
359 'link'=>wp_nonce_url($church_admin_url.'&action=delete-all&amp;section=people','delete-all')
360 ),
361
362
363
364
365 'email-list'=>array(
366 'module'=>'Comms',
367 'parent'=>'comms',
368 'level'=>'Bulk_Email',
369 'section'=>'comms',
370 'title'=>esc_html( __('Sent Emails','church-admin' ) ),
371 'link'=>wp_nonce_url($church_admin_url.'&action=email-list&amp;section=comms','email-list')
372 ),
373 'send-email'=>array(
374 'module'=>'Comms',
375 'parent'=>'comms',
376 'level'=>'Bulk_Email',
377 'section'=>'comms',
378 'title'=>esc_html( __('Send email','church-admin' ) ),
379 'link'=>wp_nonce_url($church_admin_url.'&action=send-email&amp;section=comms','send-email')
380 ),
381
382 'email-settings'=>array(
383 'module'=>'Comms',
384 'parent'=>'comms',
385 'level'=>'Bulk_Email',
386 'section'=>'comms',
387 'title'=>esc_html( __('Email settings','church-admin' ) ),
388 'link'=>wp_nonce_url($church_admin_url.'&action=email-settings&amp;section=comms','email-settings')
389 ),
390
391
392 'calendar'=>array(
393 'licence_level'=>array('standard','basic','premium'),
394 'module'=>'Calendar',
395 'parent'=>'calendar',
396 'level'=>'Calendar',
397 'section'=>'calender',
398 'title'=>esc_html( __('Calendar','church-admin' ) ),
399 'link'=>wp_nonce_url($church_admin_url.'&action=calendar&amp;section=calendar','calendar'),
400 "dashicon"=>'dashicons-calendar-alt',
401 "font-awesome"=>'<span class="ca-dashicons dashicons dashicons-calendar-alt ca-dashicons"></span>',
402 "background"=>"ca-lime",
403 "callback"=>'church_admin_calendar_callback'
404 ),
405 'calendar-list'=>array(
406 'module'=>'Calendar',
407 'parent'=>'calendar',
408 'level'=>'Calendar',
409 'section'=>'calender',
410 'title'=>esc_html( __('Calendar List','church-admin' ) ),
411 'link'=>wp_nonce_url($church_admin_url.'&action=calendar-list&amp;section=calendar','calendar-list')
412 ),
413 'add-calendar'=>array(
414 'module'=>'Calendar',
415 'parent'=>'calendar',
416 'level'=>'Calendar',
417 'section'=>'calender',
418 'title'=>esc_html( __('Add to calendar','church-admin' ) ),
419 'link'=>wp_nonce_url($church_admin_url.'&action=add-calendar&amp;section=calendar','edit-calendar')
420 ),
421 'delete-calendar'=>array(
422 'module'=>'Calendar',
423 'parent'=>'calendar',
424 'level'=>'Calendar',
425 'section'=>'calender',
426 'title'=>esc_html( __('Delete all calendar events','church-admin' ) ),
427 'link'=>wp_nonce_url($church_admin_url.'&action=delete-calendar&amp;section=calendar','delete-calendar')
428 ),
429 'view-categories'=>array(
430 'module'=>'Calendar',
431 'parent'=>'calendar',
432 'level'=>'Calendar',
433 'section'=>'calender',
434 'title'=>esc_html( __('View categories','church-admin' ) ),
435 'link'=>wp_nonce_url($church_admin_url.'&action=categories&amp;section=calendar','view-categories')
436 ),
437 'edit-category'=>array(
438 'module'=>'Calendar',
439 'parent'=>'calendar',
440 'level'=>'Calendar',
441 'section'=>'calender',
442 'title'=>esc_html( __('Edit category','church-admin' ) ),
443 'link'=>wp_nonce_url($church_admin_url.'&action=edit-category&amp;section=calendar','edit-category')
444 ),
445 'import-ics'=>array(
446 'module'=>'Calendar',
447 'parent'=>'calendar',
448 'level'=>'Calendar',
449 'section'=>'calender',
450 'title'=>esc_html( __('Import ICS calendar','church-admin' ) ),
451 'link'=>wp_nonce_url($church_admin_url.'&action=import-ics&amp;section=calendar','import-ics')
452 ),
453 'export-ics'=>array(
454 'module'=>'Calendar',
455 'parent'=>'calendar',
456 'level'=>'Calendar',
457 'section'=>'calender',
458 'title'=>esc_html( __('Export ICS calendar','church-admin' ) ),
459 'link'=>wp_nonce_url($church_admin_url.'&action=export-ics&amp;section=calendar','export-ics')
460 ),
461
462 'media'=>array(
463
464 'module'=>'Media',
465 'parent'=>'media',
466 'level'=>'Sermons',
467 'section'=>'media',
468 'title'=>esc_html( __('Media','church-admin' ) ),
469 'link'=>wp_nonce_url($church_admin_url.'&action=media&amp;section=media','media'),
470 "dashicon"=>'dashicons-controls-volumeon',
471 "font-awesome"=>'<span class="ca-dashicons dashicons dashicons-media-audio ca-dashicons"></span>',
472 "background"=>"ca-blue",
473 "callback"=>'church_admin_media_callback'
474 ),
475 'upload-mp3'=>array(
476 'module'=>'Media',
477 'parent'=>'media',
478 'level'=>'Sermons',
479 'section'=>'media',
480 'title'=>esc_html( __('Upload/Add media','church-admin' ) ),
481 'link'=>wp_nonce_url($church_admin_url.'&action=upload-mp3&amp;section=media','upload-mp3')
482 ),
483 'check-media-files'=>array(
484 'module'=>'Media',
485 'parent'=>'media',
486 'level'=>'Sermons',
487 'section'=>'media',
488 'title'=>esc_html( __('Add uploaded file','church-admin' ) ),
489 'link'=>wp_nonce_url($church_admin_url.'&action=check-media-files&amp;section=media','check-media-files')
490 ),
491 'sermon-series'=>array(
492 'module'=>'Media',
493 'parent'=>'media',
494 'level'=>'Sermons',
495 'section'=>'media',
496 'title'=>esc_html( __('Sermon series','church-admin' ) ),
497 'link'=>wp_nonce_url($church_admin_url.'&action=sermon-series&amp;section=media','sermon-series')
498 ),
499 'set-sermon-page'=>array(
500 'module'=>'Media',
501 'parent'=>'media',
502 'level'=>'Sermons',
503 'section'=>'media',
504 'title'=>esc_html( __('Set sermon page','church-admin' ) ),
505 'link'=>wp_nonce_url($church_admin_url.'&action=set-sermon-page&amp;section=media','set-sermon-page')
506 ),
507 'edit-sermon-series'=>array(
508 'module'=>'Media',
509 'parent'=>'media',
510 'level'=>'Sermons',
511 'section'=>'media',
512 'title'=>esc_html( __('Edit series','church-admin' ) ),
513 'link'=>wp_nonce_url($church_admin_url.'&action=edit-sermon-series&amp;section=media','edit-sermon-series')
514 ),
515 'podcast-settings'=>array(
516 'module'=>'Media',
517 'parent'=>'media',
518 'level'=>'Sermons',
519 'section'=>'media',
520 'title'=>esc_html( __('Podcast settings','church-admin' ) ),
521 'link'=>wp_nonce_url($church_admin_url.'&action=podcast-settings&amp;section=media','podcast-settings')
522 ),
523 'refresh-podcast'=>array(
524 'module'=>'Media',
525 'parent'=>'media',
526 'level'=>'Sermons',
527 'section'=>'media',
528 'title'=>esc_html( __('Refresh podcast','church-admin' ) ),
529 'link'=>wp_nonce_url($church_admin_url.'&action=refresh-podcast&amp;section=media','refresh-podcast')
530 ),
531
532
533 'settings'=>array(
534
535 'module'=>'Settings',
536 'parent'=>'settings',
537 'level'=>'Directory',
538 'section'=>'settings',
539 'title'=>esc_html( __('Settings','church-admin' ) ),
540 'link'=>wp_nonce_url($church_admin_url.'&action=settings&amp;section=settings','settings'),
541 "dashicon"=>'dashicons-admin-generic',
542 "font-awesome"=>'<span class="ca-dashicons dashicons dashicons-admin-settings ca-dashicons"></span>',
543 "background"=>"ca-gray",
544 "callback"=>'church_admin_settings_callback'
545 ),
546
547 'email-settings'=>array(
548 'module'=>'Settings',
549 'parent'=>'settings',
550 'level'=>'Bulk_Email',
551 'section'=>'comms',
552 'title'=>esc_html( __('Email settings','church-admin' ) ),
553 'link'=>wp_nonce_url($church_admin_url.'&action=email-settings&amp;section=comms','email-settings')
554 ),
555 'email-templates'=>array(
556 'module'=>'Settings',
557 'parent'=>'Settings',
558 'level'=>'Bulk_Email',
559 'section'=>'comms',
560 'title'=>esc_html( __('Email Templates','church-admin' ) ),
561 'link'=>wp_nonce_url($church_admin_url.'&action=email-templates&amp;section=comms','email-templates')
562 ),
563 'restrict-access'=>array(
564 'module'=>'Settings',
565 'parent'=>'settings',
566 'level'=>'Directory',
567 'section'=>'settings',
568 'title'=>esc_html( __('Restrict access','church-admin' ) ),
569 'link'=>wp_nonce_url($church_admin_url.'&action=restrict-access&amp;section=settings','restrict-access')
570 ),
571 'people-types'=>array(
572 'module'=>'Settings',
573 'parent'=>'settings',
574 'level'=>'Directory',
575 'section'=>'settings',
576 'title'=>esc_html( __('People types','church-admin' ) ),
577 'link'=>wp_nonce_url($church_admin_url.'&action=people-types&amp;section=settings','people-types')
578 ),
579 'marital-status'=>array(
580 'module'=>'Settings',
581 'parent'=>'settings',
582 'level'=>'Directory',
583 'section'=>'settings',
584 'title'=>esc_html( __('Marital status','church-admin' ) ),
585 'link'=>wp_nonce_url($church_admin_url.'&action=marital-status&amp;section=settings','marital-status')
586 ),
587 'debug-log'=>array(
588 'module'=>'Settings',
589 'parent'=>'settings',
590 'level'=>'Directory',
591 'section'=>'settings',
592 'title'=>esc_html( __('Debug Log','church-admin' ) ),
593 'link'=>wp_nonce_url($church_admin_url.'&action=debug-log&amp;section=settings','debug-log')
594 ),
595 'installation-errors'=>array(
596 'module'=>'Settings',
597 'parent'=>'settings',
598 'level'=>'Directory',
599 'section'=>'settings',
600 'title'=>esc_html( __('Installation errors','church-admin' ) ),
601 'link'=>wp_nonce_url($church_admin_url.'&action=installation-errors&amp;section=settings','installation-errors')
602 ),
603 'email-templates'=>array(
604 'module'=>'Settings',
605 'parent'=>'settings',
606 'level'=>'Directory',
607 'section'=>'settings',
608 'title'=>esc_html( __('Email templates','church-admin' ) ),
609 'link'=>wp_nonce_url($church_admin_url.'&action=email-templates&amp;section=comms','email-templates')
610 ),
611 'permissions'=>array(
612 'module'=>'Settings',
613 'parent'=>'settings',
614 'level'=>'Directory',
615 'section'=>'settings',
616 'title'=>esc_html( __('Permissions','church-admin' ) ),
617 'link'=>wp_nonce_url($church_admin_url.'&action=permissions&amp;section=settings', 'permissions')
618 ),
619
620 'roles'=>array(
621 'module'=>'Settings',
622 'parent'=>'settings',
623 'level'=>'Directory',
624 'section'=>'settings',
625 'title'=>esc_html( __('Roles','church-admin' ) ),
626 'link'=>wp_nonce_url($church_admin_url.'&action=roles&amp;section=settings','roles')
627 ),
628 'replicate-roles'=>array(
629 'module'=>'Settings',
630 'parent'=>'settings',
631 'level'=>'Directory',
632 'section'=>'settings',
633 'title'=>esc_html( __('Replicate roles','church-admin' ) ),
634 'link'=>wp_nonce_url($church_admin_url.'&action=replicate-roles&amp;section=settings','replicate-roles')
635 ),
636 'reset-version'=>array(
637 'module'=>'Settings',
638 'parent'=>'settings',
639 'level'=>'Directory',
640 'section'=>'settings',
641 'title'=>esc_html( __('Reset version','church-admin' ) ),
642 'link'=>wp_nonce_url($church_admin_url.'&action=reset-version&amp;section=settings','reset-version')
643 ),
644 'shortcode-generator'=>array(
645 'module'=>'Settings',
646 'parent'=>'settings',
647 'level'=>'Directory',
648 'section'=>'settings',
649 'title'=>esc_html( __('Shortcode generator','church-admin' ) ),
650 'link'=>wp_nonce_url($church_admin_url.'&action=shortcode-generator&amp;section=settings','shortcode-generator')
651 )
652
653 );
654
655
656 }
657 /* initialise plugin */
658
659 //add_action( 'plugins_loaded', 'church_admin_initialise' );
660 add_action( 'init', 'church_admin_initialise' );
661 function church_admin_initialise() {
662 global $church_admin_url,$level,$wpdb,$current_user,$church_admin_prayer_request_success,$member_types,$ministries;
663 church_admin_constants();//setup constants first
664 if(defined('CA_DEBUG') )$wpdb->show_errors();
665 define('CA_PATH',plugin_dir_path( __FILE__) );
666
667 //user email settings
668 if(!empty( $_GET['action'] ) && $_GET['action']=='user-email-settings')
669 {
670 //church_admin_debug('User email settings');
671 require_once( plugin_dir_path( __FILE__ ).'includes/user-profile.php');
672 church_admin_profile();
673 exit();
674 }
675 /****************************************************************************
676 * When licence payment made, this site_url/licence-change=reset is visited
677 ***************************************************************************/
678 if(!empty($_GET['licence-change'])&&$_GET['licence-change']=='reset'){
679 church_admin_debug('***** LICENCE CHANGE ********');
680 //this will be pinged when a payment ipn received at www.churchadminplugin.com, to force a licence check.
681 update_option('church_admin_licence_checked',1);//low value to force a check
682 delete_option('church_admin_trial');
683 $licence=church_admin_app_licence_check();
684 church_admin_debug('LICENCE VAR '.$licence);
685 echo'<!doctype html><html><head><title>Licence change check</title><style>body { text-align: center; padding:150px; }h1 { font-size: 50px; }body { font: 20px Helvetica, sans-serif; color: #333; }article { display: block; text-align:center; width: 650px; margin: 0 auto; }a { color: #dc8100; text-decoration: none; }a:hover { color: #333; text-decoration: none; }</style></head><body><article><p style="text-align:center"><img src="'.plugins_url('/', __FILE__ ) .'images/church-admin-logo.png"></p><h2>Licence change check</h2><p>';
686 echo'<h3>'.esc_html($licence).'</h3>';
687 echo'<p>Church Admin version: '.CHURCH_ADMIN_VERSION.'</p>';
688
689 $trial = get_option('church_admin_trial');
690 church_admin_debug('Trial: '.$trial);
691 if(!empty($trial) && time() > ($trial + $one_month)){
692 echo'<p>Trial period, ending:'.date('d M Y',$trial).'</p>';
693 }
694 echo'<p><a href="'.site_url().'">Back to main site</a></p>';
695 echo'</article></body></html>';
696 church_admin_debug('***** END LICENCE CHANGE ********');
697 exit();
698 }
699
700 wp_get_current_user();
701
702
703 //front end actions
704 /**************************************
705 * handle unsubscribe link from email
706 * ************************************/
707 if(!empty( $_GET['ca_unsub'] ) )
708 {
709 //update sanitize, validate,escape v 3.7.25 2023-05-08
710 //sanitize
711
712 $unsub = !empty($_GET['ca_unsub'])?sanitize_text_field(stripslashes($_GET['ca_unsub'])):null;
713 //validate
714 $validMD5 = FALSE;
715 if(!empty($unsub)){
716 $validMD5 = preg_match('/^[a-f0-9]{32}$/', $unsub);
717 }
718
719 if(!empty($validMD5)){
720 $details=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE md5(people_id)="'.esc_sql( $unsub ).'"');
721 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET email_send=0 WHERE md5(people_id)="'.esc_sql( $unsub ).'"');
722 require_once( plugin_dir_path( __FILE__ ).'includes/unsubscribe.php');
723 exit();
724 }
725 }
726 /***************************
727 * handle re-subscribe
728 ***************************/
729 if(!empty( $_GET['ca_sub'] ) )
730 {
731 //update sanitize, validate,escape v 3.7.25 2023-05-08
732 //sanitize
733
734 $resub = !empty($_GET['ca_unsub'])?sanitize_text_field(stripslashes($_GET['ca_sub'])):null;
735 //validate
736 $validMD5 = FALSE;
737 if(!empty($resub)){
738 $validMD5 = preg_match('/^[a-f0-9]{32}$/', $resub);
739 }
740
741 if(!empty($validMD5)){
742 $details=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE md5(people_id)="'.esc_sql( $resub ).'"');
743 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET email_send=1 WHERE md5(people_id)="'.esc_sql( $resub ).'"');
744 require_once( plugin_dir_path( __FILE__ ).'includes/resubscribe.php');
745 exit();
746 }
747 }
748
749 /**************************************
750 * handle confirm email
751 *************************************/
752 if(!empty( $_GET['confirm_email'] )&&!empty( $_GET['people_id'] ) )
753 {
754 church_admin_debug("**********************\r\n CONFIRM EMAIL");
755 //update sanitize, validate,escape v 3.7.25 2023-05-08
756 //sanitize
757 $md5email = !empty($_GET['confirm_email'])? sanitize_text_field(stripslashes($_GET['confirm_email'])):null;
758 $md5peopleID = !empty($_GET['people_id'])? sanitize_text_field(stripslashes($_GET['people_id'])) :null;
759 //validate
760 $validated = FALSE;
761 if(!empty($md5email)){$validMD5email = preg_match('/^[a-f0-9]{32}$/', $md5email);}
762 if(!empty($md5peopleID)){$validMD5peopleID = preg_match('/^[a-f0-9]{32}$/', $md5peopleID);}
763 if(!empty($validMD5email ) && !empty($validMD5peopleID)){$validated = TRUE;}
764
765 if(!empty($validated))
766 {
767 $person=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE md5(email)="'.esc_sql($md5email).'" AND md5(people_id)="'.esc_sql($md5peopleID ).'"');
768 //church_admin_debug($wpdb->last_query);
769 //church_admin_debug(print_r( $person,TRUE) );
770
771 if(!empty( $person) )
772 {
773 $household_id = (int)$person->household_id;
774 $bulk_email_method = get_option('church_admin_bulk_email_method');
775
776 //update GDPR reason
777 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET gdpr_reason="'.esc_sql(__('User confirmed from confirmation email','church-admin')).'" WHERE people_id="'.(int)$person->people_id.'"');
778 if(defined('CA_DEBUG') ) {
779 //church_admin_debug $wpdb->last_query);
780 }
781 $adminApproval=get_option('church_admin_admin_approval_required');
782 if ( empty( $adminApproval) )
783 {
784 //no admin approval required!
785 require_once( plugin_dir_path( __FILE__ ).'includes/directory.php');
786 if ( empty( $person->user_id) )church_admin_create_user( $person->people_id,$person->household_id,null,null);
787 $CAUSER=TRUE;
788 }else
789 {
790
791 $admin_message = get_option('church_admin_new_entry_admin_email');
792 $admin_message = str_replace('[HOUSEHOLD_ID]','[HOUSEHOLD_ID]&token=[NONCE]',$admin_message);
793 $admin_message=str_replace('[HOUSEHOLD_ID]',(int)$household_id,$admin_message);
794 $household_details= church_admin_household_details_table($person->household_id);
795 $admin_message=str_replace('[HOUSEHOLD_DETAILS]',$household_details,$admin_message);
796
797 church_admin_debug($admin_message);
798 //translators: email subject where %1$s is the URL of the website
799 church_admin_email_send(get_option('church_admin_default_from_email'),esc_html(sprintf(__('New household registration on %1$s','church-admin' ),site_url())),$admin_message,null,null,null,null,null,TRUE);
800
801 }
802 require_once( plugin_dir_path( __FILE__ ).'includes/confirmed.php');
803 exit();
804 }
805 else{
806 echo'<p>Person not found</p>';
807 }
808 }
809 exit();
810 }
811
812 //church admin app initialisation
813
814 if(!empty( $_GET['ca-app'] ) )
815 {
816 require_once( plugin_dir_path( __FILE__ ).'app/app-admin.php');
817 switch( $_GET['ca-app'] )
818 {
819 case'latest_media':
820 header("Content-Type: application/json");
821 echo church_admin_json_latest_media();
822 exit();
823 break;
824
825 }
826 }
827 //reset version
828 if(!empty( $_GET['page'] )&&( $_GET['page']=='church_admin/index.php')&&!empty( $_GET['action'] )&& $_GET['action']=='reset-version')
829 {
830 //check_admin_referer('reset-version');
831 update_option('church_admin_licence_checked',1);
832 //delete_option('church_admin_trial');
833 update_option("church_admin_version",0);
834 require_once(plugin_dir_path( __FILE__) .'/includes/install.php');
835 church_admin_install();
836 $url=admin_url().'admin.php?page=church_admin%2Findex.php&message=Church+Admin+Version+Reset';
837 wp_redirect( $url );
838 exit;
839 }
840 //reset version
841 define('OLD_CHURCH_ADMIN_VERSION',get_option('church_admin_version') );
842 if(version_compare(OLD_CHURCH_ADMIN_VERSION,CHURCH_ADMIN_VERSION)<0)
843 {
844 //church_admin_debug('Firing install');
845
846 require_once(plugin_dir_path( __FILE__) .'/includes/install.php');
847 church_admin_install();
848 }
849
850
851
852 /***********************************************
853 * only proceed if in church admin menu land
854 ***********************************************/
855 if(!is_admin() || empty($_GET['page']) || $_GET['page']!='church_admin/index.php'){return;}
856 //Version Number
857
858
859
860
861 /******************************************
862 * initialise variables
863 ******************************************/
864
865
866 $member_types=church_admin_member_types_array();
867
868
869
870 if(!empty( $_GET['ca_refresh'] ) )
871 {
872 delete_option('church-admin-directory-output');
873
874 }
875
876 /************************************
877 * handle move household to site
878 ************************************/
879 if(!empty( $_POST['move_site_id'] ) )
880 {
881 //update sanitize, validate,escape v 3.7.25 2023-05-08
882 //sanitize
883 $move_site_id = !empty($_POST['move_site_id'])?(int)sanitize_text_field(stripslashes($_POST['move_site_id']) ) :null;
884 $site_id = !empty($_POST['site_id'])?(int)sanitize_text_field(stripslashes($_POST['site_id'] ) ):null;
885 //validate
886 $validated = TRUE;
887 if(empty($move_site_id) || !church_admin_int_check($site_id) || empty($sites[$move_site_id])){$validated = FALSE;}
888 if(empty($site_id) || !church_admin_int_check($site_id) || empty($sites[$site_id])){$validated = FALSE;}
889
890 if(!empty($validated) )
891 {
892 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET site_id="'.(int)$site_id.'" WHERE household_id="'.(int)$move_site_id.'"');
893
894 }
895 }
896 /*****************************
897 * handle unit save
898 *****************************/
899 if(!empty( $_POST['save-unit'] ) )
900 {
901 //update sanitize, validate,escape v 3.7.25 2023-05-08
902 //sanitize
903 $unit_id = !empty( $_REQUEST['unit_id'] )? sanitize_text_field(stripslashes($_REQUEST['unit_id'])) :null;
904 $name = !empty($_POST['unit_name']) ? sanitize_text_field( stripslashes($_POST['unit_name']) ) :null;
905 $description = !empty($_POST['unit_description']) ? sanitize_textarea_field(stripslashes( $_POST['unit_description']) ) :null;
906
907 //validate
908 $validated = TRUE;
909 if(!empty($unit_id)){
910 //check it exists
911 if(empty($units[$unit_id])){
912 $unit_id = FALSE; //non existent unit_id, so needs to be an insery
913 }
914 }
915 if(empty($name)){$validated = FALSE;}
916 if(empty($description)){$validated = FALSE;}
917 if(!empty($validated)){
918 if ( empty( $unit_id) ) {
919 $wpdb->query('INSERT INTO '.$wpdb->prefix.'church_admin_units (name,description)VALUES("'.esc_sql($name).'","'.esc_sql($description).'")');
920 }
921 else{
922 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_units SET name="'.esc_sql($name).'",description="'.esc_sql($description).'" WHERE unit_id="'.(int)$unit_id.'"');
923 }
924 }
925 }
926 if(!empty( $_POST['save-subunit'] ) )
927 {
928 //update sanitize, validate,escape v 3.7.25 2023-05-08
929 //sanitize
930 $unit_id = !empty( $_REQUEST['unit_id'] )? sanitize_text_field(stripslashes($_REQUEST['unit_id'] )) :null;
931 $subunit_id = !empty( $_REQUEST['subunit_id'] )? sanitize_text_field(stripslashes($_REQUEST['subunit_id'])) :null;
932 $name = !empty($_POST['unit_name']) ? sanitize_text_field(stripslashes( $_POST['unit_name']) ) :null;
933 $description = !empty($_POST['unit_description']) ? sanitize_textarea_field( stripslashes($_POST['unit_description']) ) :null;
934 $people = !empty($_POST['people']) ? sanitize_text_field(stripslashes( $_POST['people'] )) :null;
935
936 //validate
937 $validated = TRUE;
938 if(!empty($unit_id)){
939 //check it exists
940 if(empty($units[$unit_id])){
941 $unit_id = FALSE; //non existent unit_id, so needs to be an insery
942 }
943 }
944 if(!empty($subunit_id)||!church_admin_int_check($subunit_id)){$validated = FALSE;}
945 if(empty($name)){$validated = FALSE;}
946 if(empty($description)){$validated = FALSE;}
947
948 if(!empty($validated))
949 {
950
951 if ( empty( $subunit_id) )$subunit_id=$wpdb->get_var('SELECT subunit_id FROM '.$wpdb->prefix.'church_admin_unit_meta WHERE name="'.esc_sql($name).'" AND description="'.esc_sql($description).'"');
952
953
954
955 if ( empty( $subunit_id) ){
956 $wpdb->query('INSERT INTO '.$wpdb->prefix.'church_admin_unit_meta (name,description,unit_id,active)VALUES("'.esc_sql($name).'","'.esc_sql($description).'","'.(int)$unit_id.'",1)');
957 $subunit_id=(int)$wpdb->insert_id;
958 //church_admin_debug $wpdb->last_query);
959 }
960 else{
961 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_unit_meta SET name="'.esc_sql($name).'",description="'.esc_sql($description).'" WHERE subunit_id="'.(int)$subunit_id.'"');
962 }
963 //handle people
964 $wpdb->query('DELETE FROM '.$wpdb->prefix.'church_admin_people_meta WHERE meta_type="unit" AND ID="'.(int)$subunit_id.'"');
965 $autocompleted= maybe_unserialize(church_admin_get_people_id(trim($people )) );
966 foreach( $autocompleted AS $x=>$name)
967 {
968 $p_id=church_admin_get_one_id(trim( $name) );//get the people_id
969 if(!empty( $p_id) )
970 {
971 church_admin_update_people_meta( $subunit_id,$p_id,'unit');//update person
972 }
973 }
974 }
975
976 }
977
978 //handle unconfirm GDPR
979 if(!empty( $_GET['action'] )&&$_GET['action']=='ca_unconfirm_GDPR')
980 {
981 if(!is_user_logged_in() )return;
982 if(current_user_can('manage_options') )
983 {
984 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET gdpr_reason=NULL');
985
986 }
987 }
988
989
990
991 if(!empty( $_POST['ind_att_csv'] ) ) {
992 require_once( plugin_dir_path( __FILE__ ).'includes/individual_attendance.php');
993 $out = church_admin_output_ind_att_csv();
994 echo $out;
995 exit();
996 }
997 //load_plugin_textdomain( 'church-admin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
998 load_plugin_textdomain( 'church-admin');
999 $level=get_option('church_admin_levels');
1000 if(empty($level))
1001 {
1002 if ( empty( $level['Units'] ) )$level['Units']='administrator';
1003 if ( empty( $level['Ministries'] ) )$level['Ministries']='administrator';
1004 if ( empty( $level['Giving'] ) )$level['Giving']='administrator';
1005 if ( empty( $level['Directory'] ) )$level['Directory']='administrator';
1006 if ( empty( $level['Kidswork'] ) )$level['Kidswork']='administrator';
1007 if ( empty( $level['Small Groups'] ) )$level['Small Groups']='administrator';
1008
1009 if ( empty( $level['Funnel'] ) ) $level['Funnel']='administrator';
1010 if ( empty( $level['Bulk Email'] ) )$level['Bulk Email']='administrator';
1011 if ( empty( $level['Sermons'] ) )$level['Sermons']='administrator';
1012 if ( empty( $level['Bulk SMS'] ) )$level['Bulk SMS']='administrator';
1013 if ( empty( $level['Calendar'] ) )$level['Calendar']='administrator';
1014 if ( empty( $level['Attendance'] ) )$level['Attendance']='administrator';
1015 if ( empty( $level['Member Type'] ) )$level['Member Type']='administrator';
1016 if ( empty( $level['Service'] ) )$level['Service']='administrator';
1017 if ( empty( $level['Sessions'] ) )$level['Sessions']='administrator';
1018 if(empty($level['Pastoral']))$level['Pastoral']='administrator';
1019 if ( empty( $level['Sessions'] ) )$level['Sessions']='administrator';
1020 if ( empty( $level['App'] ) )$level['App']='administrator';
1021 if ( empty( $level['Prayer Requests'] ) )$level['Prayer Requests']='administrator';
1022 if ( empty( $level['Events'] ) )$level['Events']='administrator';
1023 if ( empty( $level['Ministries'] ) )$level['Ministries']='administrator';
1024 if ( empty( $level['Classes'] ) )$level['Classes']='administrator';
1025 if ( empty( $level['Contact form'] ) )$level['Contact form']='administrator';
1026 update_option('church_admin_levels',$level);
1027 }
1028 if(!empty( $_POST['one_site'] ) ){
1029 //update sanitize, validate,escape v 3.7.25 2023-05-08
1030 //sanitize
1031 $site_id=!empty($_POST['site_id'])?sanitize_text_field( stripslashes( $_POST['site_id'] ) ) :null;
1032 //validate
1033 $sites = church_admin_sites_array();
1034 if(!empty($sites[$site_id]))
1035 {
1036 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET site_id="'.(int)$site_id.'"');
1037 }
1038 }
1039
1040
1041
1042
1043 //save the church admin note before any display happens
1044
1045 if(!empty( $_POST['save-ca-comment'] ) )
1046 {
1047 //church_admin_debug('******************************'."\r\n Save Comment ".date('Y-m-d H:i:s')."\r\n");
1048 //update sanitize, validate,escape v 3.7.25 2023-05-08
1049 //sanitize
1050 $parent_id = !empty( $_POST['parent_id'] )?sanitize_text_field( $_POST['parent_id'] ) : null;
1051 $comment_id = !empty( $_POST['comment_id'] )?sanitize_text_field( $_POST['comment_id'] ) : null;
1052 $comment = !empty($_POST['comment'])?sanitize_textarea_field($_POST['comment']):null;
1053 $comment_type = !empty( $_POST['comment_type'] )?sanitize_text_field( $_POST['comment_type'] ) : null;
1054 $ID = !empty( $_POST['ID'] )?sanitize_text_field( $_POST['ID'] ) : null;
1055
1056 foreach( $_POST AS $key=>$value)$sqlsafe[$key]=esc_sql(sanitize_text_field( $value) );
1057 if(!empty( $_POST['comment_id'] ) )
1058 {
1059 $sql='UPDATE '.$wpdb->prefix.'church_admin_comments SET comment="'.esc_sql($comment).'",comment_type="'.esc_sql($comment_type).'",parent_id="'.(int)$parent_id.'",author_id="'.(int)$current_user->ID.'",timestamp="'.date('Y-m-d h:i:s').'" comment_id="'.(int)$comment_id.'"';
1060 }
1061 else
1062 {
1063
1064 $sql='INSERT INTO '.$wpdb->prefix.'church_admin_comments (comment,comment_type,parent_id,author_id,timestamp,ID)VALUES("'.esc_sql($comment).'","'.esc_sql($comment_type).'","'.(int)$parent_id.'","'.(int)$current_user->ID.'","'.date('Y-m-d h:i:s').'","'.(int)$ID.'")';
1065 }
1066 //church_admin_debug('******************************'."\r\n $sql \r\n");
1067 $wpdb->query( $sql);
1068 if ( empty( $comment_id ) )$comment_id=$wpdb->insert_id;
1069
1070 $comment=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_comments WHERE comment_id="'.(int)$comment_id.'"');
1071
1072 }
1073
1074 }
1075
1076
1077
1078 if(function_exists('register_block_type') )require_once( plugin_dir_path( __FILE__ ) .'gutenberg/php-blocks.php');
1079 add_action( 'delete_user', 'church_admin_delete_user' );//make sure user account disconnected from directory
1080
1081
1082 function church_admin_delete_user( $user_id)
1083 {
1084 global $wpdb;
1085 //sanitize
1086 $sanitizedUserID = (!empty($user_id) && church_admin_int_check($user_id) ) ? (int)$user_id: null;
1087 //validate - check actual user with that ID
1088 if(!empty($sanitizedUserID)){
1089 $user = get_user_by('ID',$sanitizedUserID);
1090 }
1091 if(!empty($user)){
1092 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET user_id="NULL" WHERE user_id="'.(int)$user->ID.'"');
1093 }
1094
1095 }
1096
1097 add_action('activated_plugin','church_admin_save_error');
1098 function church_admin_save_error() {
1099 update_option('church_admin_plugin_error', ob_get_contents() );
1100 }
1101 add_action('load-church-admin', 'church_admin_add_screen_meta_boxes');
1102
1103
1104
1105
1106 /**
1107 *
1108 * Sets up constants for plugin
1109 *
1110 * @author Andy Moyle
1111 * @param null
1112 * @return
1113 * @version 0.1
1114 *
1115 */
1116 function church_admin_constants()
1117 {
1118
1119 //define DB
1120 define('OLD_CHURCH_ADMIN_EMAIL_CACHE',WP_PLUGIN_DIR.'/church-admin-cache/');
1121 define('OLD_CHURCH_ADMIN_EMAIL_CACHE_URL',WP_PLUGIN_URL.'/church-admin-cache/');
1122
1123 church_admin_create_directories();
1124
1125 }//end constants
1126
1127
1128 /**
1129 *
1130 * Add new household to admin toolbar
1131 *
1132 * @author Andy Moyle
1133 * @param null
1134 * @return Array, key is order
1135 * @version 0.1
1136 *
1137 */
1138 function church_admin_menu_item ( $wp_admin_bar) {
1139
1140 $args = array (
1141 'id' => 'household',
1142 'title' =>esc_html( __('Household','church-admin' ) ),
1143 'href' => wp_nonce_url(admin_url().'admin.php?page=church_admin/index.php&amp;section=people&action=add-household','add-household'),
1144 'parent' => 'new-content'
1145 );
1146
1147 if(church_admin_level_check('Directory') ) $wp_admin_bar->add_node( $args );
1148
1149 $args = array (
1150 'id' => 'quickhousehold',
1151 'title' =>esc_html( __('Quick Household','church-admin' ) ),
1152 'href' => wp_nonce_url(admin_url().'admin.php?page=church_admin/index.php&amp;section=people&action=quick-household','quick-household'),
1153 'parent' => 'new-content'
1154 );
1155
1156 if(church_admin_level_check('Directory') ) $wp_admin_bar->add_node( $args );
1157
1158
1159 $args = array (
1160 'id' => 'sermon',
1161 'title' =>esc_html( __('Sermon','church-admin' ) ),
1162 'href' => wp_nonce_url(admin_url().'admin.php?page=church_admin/index.php&action=upload-mp3','upload-mp3'),
1163 'parent' => 'new-content'
1164 );
1165 if(church_admin_level_check('Media') ) $wp_admin_bar->add_node( $args );
1166
1167
1168
1169
1170
1171
1172 }
1173
1174 add_action('admin_bar_menu', 'church_admin_menu_item',71);
1175
1176
1177
1178
1179 /******************************************************************************************************************************
1180 *
1181 * For prayer request, if made private in settings we want to show the login form at the template_redirect hook
1182 *
1183 ******************************************************************************************************************************/
1184 function church_admin_private_prayer_template( $archive_template ) {
1185 global $post;
1186 $private=get_option('church-admin-private-prayer-requests');
1187 //church_admin_debugget_post_type());
1188 if ( (is_post_type_archive ( 'prayer-requests' ) || 'prayer-requests'==get_post_type()) && !is_user_logged_in() && !empty($private) ) {
1189 //church_admin_debug('Prayer request not logged in');
1190 $located = locate_template( 'private-prayer.php' );
1191 //church_admin_debug($located);
1192 if(!empty($located)){
1193
1194 $archive_template = $located;
1195 }
1196 else
1197 {
1198 $archive_template = dirname( __FILE__ ) . '/display/private-prayer.php';
1199 }
1200 }
1201 return $archive_template;
1202 }
1203 add_filter( 'archive_template', 'church_admin_private_prayer_template' ) ;
1204 add_filter( 'single_template', 'church_admin_private_prayer_template' ) ;
1205
1206
1207 /******************************************************************************************************************************
1208 *
1209 * Show a submit prayer requests form at the top of the archive
1210 *
1211 ******************************************************************************************************************************/
1212 $theme = wp_get_theme(); // gets the current theme
1213
1214 if ( 'Avada' == $theme->name || 'Avada' == $theme->parent_theme ) {
1215 add_action('avada_before_main_container', 'church_admin_draft_prayer_request');
1216 define('CA_PRY_STYLE','style="min-width:80vw;"');
1217 }
1218 elseif ( 'The7' == $theme->name || 'The7' == $theme->parent_theme ) {
1219 add_action('presscore_before_loop', 'church_admin_draft_prayer_request');
1220 }
1221 elseif( 'Omega' == $theme->name || 'Omega' == $theme->parent_theme ) {
1222
1223 add_action('omega_before_content', 'church_admin_draft_prayer_request');
1224 }
1225 elseif(has_action('church_admin_theme_before_loop') )
1226 {
1227 add_action('church_admin_theme_before_loop', 'church_admin_draft_prayer_request');
1228 }
1229 elseif(has_action('fusion_blog_shortcode_before_loop') )
1230 {
1231 add_action('fusion_blog_shortcode_before_loop', 'church_admin_draft_prayer_request');
1232 }
1233 else{
1234 add_action('loop_start', 'church_admin_draft_prayer_request');
1235 }
1236
1237 function church_admin_draft_prayer_request( $content)
1238 {
1239 global $wpdb,$church_admin_prayer_request_success;
1240
1241 if(is_post_type_archive('prayer-requests')&& is_archive() )
1242 {
1243 $private=get_option('church-admin-private-prayer-requests');
1244 //only show form if not private or logged in
1245 if (!$private ||(is_user_logged_in() && $private) )
1246 {
1247 $out='';
1248
1249 if ( empty( $_POST['save_prayer_request'] )&&empty( $_POST['non_spammer'] )||!wp_verify_nonce( $_POST['non_spammer'],'prayer-request') )
1250 {
1251 $out.='<div class="church-admin-prayer-request alignwide" ';
1252 if(defined('CA_PRY_STYLE') ) $out.= CA_PRY_STYLE;
1253 $out.='><h3>'.esc_html( __('Submit a prayer request','church-admin' ) ).'</h3>';
1254 $message=get_option('church_admin_prayer_request_message');
1255 if(!empty( $message) )$out.='<p>'. wp_kses_post( $message).'</p>';
1256 $out.='<form action="" method="POST">';
1257
1258 $out.='<div class="church-admin-form-group"><label>'.esc_html( __('Title','church-admin' ) ).'</label><input type="text" name="request_title" class="church-admin-form-control"></div>';
1259 $out.='<div class="church-admin-form-group"><label>'.esc_html( __('Prayer request','church-admin' ) ).'</label><textarea name="request_content" class="church-admin-form-control" style="height:100px"></textarea></div>';
1260 $out.='<div id="spam-proof">&nbsp;</div>';
1261 $out.='<div class="church-admin-form-group"><input type="hidden" value="TRUE" name="save_prayer_request" /><input type="submit" value="'.esc_html( __('Save','church-admin' ) ).'" /></div>';
1262
1263 $out.='</form></div>';
1264 $nonce=wp_create_nonce('prayer-request');
1265 $out.='<script>jQuery(document).ready(function( $) {var content="<div class=\"form-check\"><label>'.esc_html( __('Check box if not a spammer','church-admin' ) ).'<input type=\"checkbox\" name=\"non_spammer\" value=\"'.esc_attr($nonce).'\" /></label></div>"; $("#spam-proof").html(content);});</script>';
1266 }
1267 else{
1268 $out=$church_admin_prayer_request_success;
1269 }
1270 echo $out;
1271 }
1272 }
1273
1274 }
1275 add_action('loop_start', 'church_admin_draft_act_of_courage');
1276
1277 function church_admin_draft_act_of_courage( $content)
1278 {
1279 global $wpdb,$church_admin_acts_success;
1280
1281 if(is_post_type_archive('acts-of-courage') )
1282 {
1283 $private=get_option('church-admin-private-acts-of-courage');
1284 //only show form if not private or logged in
1285 if (!$private ||(is_user_logged_in() && $private) )
1286 {
1287 $out='';
1288
1289 if ( empty( $_POST['save_acts_request'] )&&empty( $_POST['non_spammer'] )||!wp_verify_nonce( $_POST['non_spammer'],'acts-of-courage') )
1290 {
1291 $out.='<h3>'.esc_html( __('Submit an act of courage','church-admin' ) ).'</h3>';
1292 $message=get_option('church-admin-acts-of-courage-message');
1293 if(!empty( $message) )$out.='<p>'. wp_kses_post( $message).'</p>';
1294 $out.='<form action="" method="POST">';
1295 $out.='<table class="form-table"><tbody>';
1296 $out.='<tr><th scope="row">'.esc_html( __('Title','church-admin' ) ).'</th><td><input type="text" name="request_title"></td></tr>';
1297 $out.='<tr><th scope="row">'.esc_html( __('Your act of courage','church-admin' ) ).'</th><td><textarea name="request_content"></textarea></td></tr>';
1298 $out.='<tr id="spam-proof">&nbsp;</td></tr>';
1299 $out.='<tr><td cellspacing=2><input type="hidden" value="TRUE" name="save_act_of_courage_request" /><input type="submit" value="'.esc_html( __('Save','church-admin' ) ).'" /></td></tr></table>';
1300
1301 $out.='</form>';
1302 $nonce=wp_create_nonce('acts-of-courage');
1303 $out.='<script>jQuery(document).ready(function( $) {var content="<th scope=\"row\">'.esc_html( __('Check box if not a spammer','church-admin' ) ).'</th><td><input type=\"checkbox\" name=\"non_spammer\" value=\"'.esc_attr($nonce).'\" /></td></tr>"; $("#spam-proof").html(content);});</script>';
1304 }
1305 else{
1306 $out = $church_admin_acts_success;
1307 }
1308 echo $out;
1309 }
1310 }
1311
1312 }
1313 /****************************************************************************
1314 *
1315 * From 1.2800 register front end scripts early then enqueue on shortcode process
1316 *
1317 *****************************************************************************/
1318 add_action( 'wp_enqueue_scripts', 'church_admin_register_frontend_scripts' );
1319 add_action( 'admin_enqueue_scripts', 'church_admin_register_frontend_scripts' );
1320 function church_admin_register_frontend_scripts() {
1321 global $post;
1322
1323
1324
1325 wp_register_script('ca-draganddrop', plugins_url( '/', __FILE__ ) . 'includes/draganddrop.js', array( 'jquery' ) , filemtime(plugin_dir_path(__FILE__ ).'includes/draganddrop.js'),TRUE);
1326 wp_register_script('church-admin-form-case-enforcer',plugins_url( '/', __FILE__ ) . 'includes/jQuery.caseEnforcer.min.js',array( 'jquery' ),FALSE, TRUE);
1327
1328
1329 wp_register_script('church-admin-calendar-script',plugins_url( '/', __FILE__ ) . 'includes/calendar.js',array( 'jquery' ),FALSE, TRUE);
1330 wp_register_script('church-admin-calendar',plugins_url( '/', __FILE__ ) . 'includes/jQueryCalendar.js',array( 'jquery' ),FALSE, TRUE);
1331
1332 /****************
1333 * Podcast
1334 ***************/
1335 wp_register_script('ca_podcast_audio_use',plugins_url('/', __FILE__ ) . 'includes/audio.use.js' , array( 'jquery' ) ,filemtime(plugin_dir_path(__FILE__ ).'includes/audio.use.js'), TRUE);
1336 wp_register_script( 'jquery-ui-datepicker','','',NULL );
1337 wp_register_script('church_admin_form_clone',plugins_url('/', __FILE__ ) . 'includes/jquery-formfields.js', array( 'jquery' ) ,FALSE, TRUE);
1338 //fix issue caused by some "premium" themes, which call google maps w/o key on every admin page. D'uh!
1339 wp_dequeue_script('avia-google-maps-api');
1340 //now enqueue google map api with the key
1341 $src = 'https://maps.googleapis.com/maps/api/js';
1342 $key='?key='.get_option('church_admin_google_api_key').'&callback=Function.prototype';
1343 wp_register_script( 'church_admin_google_maps_api',$src.$key, array() ,FALSE);
1344 wp_register_script('church_admin_map', plugins_url('/', __FILE__ ) . 'includes/google_maps.js', array( 'jquery' ) ,filemtime(plugin_dir_path(__FILE__ ).'includes/google_maps.js'),FALSE);
1345 wp_register_script('church_admin_map_script', plugins_url('/', __FILE__ ) . 'includes/maps.js', array( 'jquery' ) ,filemtime(plugin_dir_path(__FILE__ ).'includes/maps.js'),FALSE);
1346 wp_register_script('jquery-ui-sortable','','',NULL );
1347 //google graph needs to be called early and in header, didn't like being registered and then enqueued later
1348 wp_register_script('church_admin_google_graph_api','https://www.google.com/jsapi', array( 'jquery' ) ,FALSE, FALSE);
1349
1350
1351 }
1352
1353 add_action('wp_head','church_admin_ajaxurl');
1354 function church_admin_ajaxurl()
1355 {
1356 $ajax_nonce = wp_create_nonce("church_admin_mp3_play");
1357 ?>
1358 <script type="text/javascript">
1359 var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
1360 var security= '<?php echo $ajax_nonce; ?>';
1361 </script>
1362 <?php
1363 }
1364 add_action('wp_enqueue_scripts', 'church_admin_init');
1365 add_action('admin_enqueue_scripts', 'church_admin_init',9999);//adding withlow priority to be last to call google maps api
1366 /**
1367 *
1368 * Initialises js scripts and css
1369 *
1370 * @author Andy Moyle
1371 * @param null
1372 * @return
1373 * @version 0.1
1374 *
1375 */
1376 function church_admin_init()
1377 {
1378 if(!empty( $_COOKIE['churchAdminBlur'] ) )wp_enqueue_style( 'church-admin-blur', plugins_url('includes/blur.css',__FILE__ ) ,'',NULL);
1379
1380 //This function add scripts as needed
1381
1382 //wp_enqueue_script('common','','',NULL);
1383 //wp_enqueue_script('wp-lists','','',NULL);
1384 //wp_enqueue_script('postbox','','',NULL);
1385 wp_register_script('church_admin_google_graph_api','https://www.google.com/jsapi', array( 'jquery' ) ,FALSE, FALSE);
1386 //wp_enqueue_style( 'dashicons' ); - added to style.new.css for less calls.
1387
1388
1389 if(!empty( $_POST['church_admin_search'] ) )church_admin_editable_script();
1390
1391
1392 if(isset( $_GET['action'] ) )
1393 {
1394 switch( $_GET['action'] )
1395 {
1396
1397 case 'send-email':
1398 church_admin_autocomplete_script();
1399 church_admin_date_picker_script();
1400 break;
1401 case 'edit-ministry':
1402 case 'edit-subunit':
1403 case 'settings':
1404 case'people':
1405 case 'edit_ministry':
1406 case'view_ministry':
1407 case'church_admin_member_type':
1408 case 'send-sms':
1409 case'twilio-replies':
1410 case 'app-settings':
1411 case 'edit-custom-field-automation':
1412 case 'pastoral-visit-list':
1413 case 'pastoral-settings':
1414
1415 case 'edit-child-protection-incident':
1416 church_admin_autocomplete_script();
1417 break;
1418 case 'edit-calendar':
1419 case 'add-calendar':
1420 case 'podcast-settings':
1421 case 'edit-child-protection-incident':
1422
1423 church_admin_media_uploader_enqueue();
1424 church_admin_date_picker_script();
1425 break;
1426
1427 case'church_admin_add_calendar':
1428 case 'add-calendar':
1429
1430 case'church_admin_series_event_edit':
1431 case'church_admin_single_event_edit':
1432 case 'show-attendance':
1433 case'edit-attendance':
1434 case'church_admin_new_edit_calendar':
1435 case 'edit-calendar':
1436 case'edit_kidswork':
1437 case 'add-attendance':
1438 case 'weeks-attendance':
1439 case 'individual-attendance':
1440 case 'individual-attendance-csv':
1441 case 'individual_attendance':
1442 case 'individual-attendance-list':
1443 case 'edit-individual-attendance':
1444
1445 case 'import-ics':
1446 case'giving-csv':
1447 case'edit-service':
1448 case'add-event':
1449 case'edit_safeguarding':
1450
1451 case 'add-three-months':
1452 case 'edit_event':
1453 case 'edit_ticket_type':
1454 case 'bulk-bible-readings':
1455 case 'series-event-edit':
1456 case 'single-event-edit':
1457 case 'bulk-edit-anniversary':
1458 case 'bulk-edit-dob':
1459 case 'bulk-edit-custom':
1460 case 'edit-pastoral-visit-note':
1461 case 'schedule-pastoral-visit':
1462 case 'whole-series-edit':
1463 case 'future-series-edit':
1464 church_admin_date_picker_script();
1465 break;
1466 case 'bulk_geocode':
1467 case 'bulk-geocode':
1468 church_admin_google_map_api();
1469 wp_enqueue_script('ca_batch_geocode', plugins_url('/', __FILE__ ) . 'includes/batch_geocode.js', array( 'jquery' ) ,FALSE, TRUE);
1470 break;
1471 case 'services':
1472 case'individual-attendance':
1473 case'attendance':
1474 church_admin_date_picker_script();
1475 church_admin_frontend_graph_script();
1476 break;
1477 case'church_admin_cron_email':
1478 //church_admin_debug('Cron fired:'.date('Y-m-d h:i:s')."/r/n");
1479 church_admin_bulk_email();exit();
1480 break;
1481 case 'remove-queue':check_admin_referer('remove-queue');church_admin_remove_queue();break;
1482 case'send-email':case'church_admin_send_email':church_admin_email_script();church_admin_autocomplete_script();church_admin_date_picker_script();break;
1483 case'edit-resend':church_admin_email_script();church_admin_autocomplete_script();church_admin_date_picker_script();break;
1484 case'resend-new':
1485
1486 church_admin_email_script();
1487 church_admin_autocomplete_script();
1488 break;
1489 case'resend_email':church_admin_email_script();church_admin_autocomplete_script();break;
1490 case'church_admin_send_sms':church_admin_email_script();church_admin_autocomplete_script();break;
1491 case'delete-group':
1492 church_admin_sg_map_script();
1493 church_admin_autocomplete_script();
1494 break;
1495 case'church_admin_search';church_admin_editable_script();break;
1496 //calendar
1497 case'church_admin_add_category':
1498 case'church_admin_edit_category':
1499 case 'edit-category':
1500 church_admin_farbtastic_script();
1501 break;
1502
1503 case 'edit_bubble_booking':case 'add_bubble_booking':
1504 wp_enqueue_script('church-admin-form-case-enforcer',plugins_url( '/', __FILE__ ) . 'includes/jQuery.caseEnforcer.min.js',array( 'jquery' ),FALSE, TRUE);
1505 break;
1506 case 'test':
1507 church_admin_sortable_script();
1508 break;
1509 case 'small_groups':
1510 case 'smallgroups-cleanup':
1511 case 'groups-cleanup':
1512 church_admin_sortable_script();
1513 church_admin_form_script();
1514 church_admin_autocomplete_script();
1515 $key=get_option('church_admin_google_api_key');
1516 if(!empty( $key) )church_admin_sg_map_script();
1517 break;
1518 case 'add-service':
1519 case 'edit-service':
1520 church_admin_form_script();church_admin_date_picker_script();
1521 break;
1522 case 'edit-site':
1523 case 'edit_site':
1524 church_admin_form_script();
1525 church_admin_media_uploader_enqueue();
1526
1527 $key=get_option('church_admin_google_api_key');
1528 if(!empty( $key) )
1529 {
1530 church_admin_map_script();
1531 }
1532 break;
1533
1534 case 'edit-small-group':
1535 case 'edit-group':
1536 case 'add-group':
1537 //church_admin_form_script();
1538 church_admin_autocomplete_script();
1539 church_admin_media_uploader_enqueue();
1540 wp_enqueue_script('ca-draganddrop');
1541 $key=get_option('church_admin_google_api_key');
1542 if(!empty( $key) )
1543 {
1544 church_admin_map_script();
1545 church_admin_sg_map_script();
1546 }
1547 break;
1548 case 'small_groups':
1549 $key=get_option('church_admin_google_api_key');
1550 if(!empty( $key) )
1551 {
1552 church_admin_map_script();
1553 church_admin_sg_map_script();
1554 }
1555 break;
1556 case'classes':church_admin_date_picker_script();church_admin_frontend_graph_script();break;
1557 case'view_class':
1558 church_admin_date_picker_script();
1559 church_admin_autocomplete_script();
1560 church_admin_frontend_graph_script();
1561 break;
1562
1563 case'edit-class':
1564 case'edit_class':
1565 case 'edit-gift':
1566
1567 case 'upload-mp3':
1568 case 'permissions':
1569 case'add-media-file':
1570 case'church_admin_permissions':
1571 church_admin_date_picker_script();church_admin_autocomplete_script();
1572 break;
1573 case 'app-visits':
1574 church_admin_date_picker_script();
1575 break;
1576
1577 case'list';church_admin_editable_script();break;
1578
1579 case 'app':
1580 case'custom-fields':
1581 case 'edit-custom-field':
1582
1583 church_admin_sortable_script();break;
1584
1585 //directory
1586 case 'people-map':
1587 church_admin_map_script();
1588 break;
1589 case 'smallgroups-map':church_admin_sg_map_script();break;
1590 case'new_household':
1591 case 'add-household':
1592 case'church_admin_new_household':
1593 church_admin_form_script();
1594 church_admin_map_script();
1595
1596 church_admin_media_uploader_enqueue();
1597 church_admin_date_picker_script();
1598 break;
1599
1600
1601
1602 case'edit_household':
1603 case'view_household':
1604 case 'display-household':
1605 case 'display_household':
1606 case 'upload-mp3':
1607 church_admin_map_script();
1608 church_admin_date_picker_script();
1609 wp_enqueue_script('ca-draganddrop');
1610
1611 break;
1612 case 'edit_people':
1613 church_admin_form_script();
1614 church_admin_date_picker_script();
1615 church_admin_media_uploader_enqueue();
1616 church_admin_map_script();
1617 wp_enqueue_script('ca-draganddrop');
1618 break;
1619 case'app':
1620 case'edit_sermon_series':
1621 case 'edit-sermon-series':
1622 church_admin_media_uploader_enqueue();
1623 wp_enqueue_script('ca-draganddrop');
1624 break;
1625
1626
1627 case'church_admin_update_order':
1628 church_admin_update_order( $_GET['which'] );exit();
1629 break;
1630 case'get_people':church_admin_ajax_people(TRUE);break;
1631 case'people':case'edit_funnel':case'delete_funnel':church_admin_sortable_script();break;
1632 case 'upload-mp3':church_admin_date_picker_script();church_admin_autocomplete_script();break;
1633
1634 }
1635 }
1636 elseif(isset( $_GET['page'] )&& $_GET['page']=='church_admin/index.php')
1637 {
1638 church_admin_date_picker_script();//needed on main menu page too
1639 }
1640
1641 }
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653 /* Thumbnails */
1654 add_action( 'after_setup_theme', 'ca_thumbnails' );
1655 function ca_thumbnails()
1656 {
1657 /**
1658 *
1659 * Add thumbnails for plugin use
1660 *
1661 * @author Andy Moyle
1662 * @param null
1663 * @return
1664 * @version 0.1
1665 *
1666 */
1667 add_theme_support( 'post-thumbnails' );
1668 if ( function_exists( 'add_image_size' ) )
1669 {
1670 add_image_size('ca-people-thumb',75,75);
1671 add_image_size('ca-address-thumb',150,150);
1672 //add_image_size( 'ca-email-thumb', 300, 200 ); //300 pixels wide (and unlimited height)
1673 //add_image_size('ca-series-thumbnail',480,360);
1674
1675 }
1676
1677 }
1678 /* Thumbnails */
1679 add_action( 'admin_enqueue_scripts','church_admin_public_css');
1680 add_action('wp_enqueue_scripts','church_admin_public_css');
1681 function church_admin_public_css() {
1682
1683 wp_enqueue_style('Church-Admin',plugins_url('/', __FILE__ ) . 'includes/style.new.css',NULL,filemtime(plugin_dir_path( __FILE__ ).'includes/style.new.css' ),'all');
1684 }
1685 add_action('admin_head',"church_admin_colorscheme");
1686 function church_admin_colorscheme()
1687 {
1688 //add the users selected admin colors
1689 global $_wp_admin_css_colors;
1690
1691 $current_color = get_user_option( 'admin_color' );
1692
1693 if ( empty( $current_color) ) {$current_color='fresh';}
1694 $church_admin_colors = $_wp_admin_css_colors[$current_color];
1695 $styles='#church-admin-menu{background:'.esc_attr($church_admin_colors->colors[1]).';}'."\r\n";
1696 $styles.='.church-admin-top-menu.active .church-admin-top-menu-item{background:'.esc_attr($church_admin_colors->colors[2]).'}'."\r\n";
1697 $styles.='.church-admin-top-menu.inactive .church-admin-submenu{background:'.esc_attr($church_admin_colors->colors[0]).';}'."\r\n";
1698 $styles.='.church-admin-submenu.active{background:'.esc_attr($church_admin_colors->colors[0]).';}'."\r\n";
1699 wp_add_inline_style( 'Church-Admin', $styles );
1700
1701 }
1702 add_action('wp_head', 'church_admin_public_header');
1703 function church_admin_public_header()
1704 {
1705
1706 $licence = get_option('church_admin_app_new_licence');
1707 echo"<!--
1708
1709 ____ _ _ _ _ _ ____ _ _
1710 / ___| |__ _ _ _ __ ___| |__ / \ __| |_ __ ___ (_)_ __ | _ \| |_ _ __ _(_)_ __
1711 | | | '_ \| | | | '__/ __| '_ \ / _ \ / _` | '_ ` _ \| | '_ \ | |_) | | | | |/ _` | | '_ \
1712 | |___| | | | |_| | | | (__| | | | / ___ \ (_| | | | | | | | | | | | __/| | |_| | (_| | | | | |
1713 \____|_| |_|\__,_|_| \___|_| |_| /_/ \_\__,_|_| |_| |_|_|_| |_| |_| |_|\__,_|\__, |_|_| |_|
1714 |___/
1715 \r\n";
1716 echo' FREE Version: '.CHURCH_ADMIN_VERSION.' -->
1717 <style>table.church_admin_calendar{width:';
1718 if(get_option('church_admin_calendar_width') ) {
1719 echo (int)get_option('church_admin_calendar_width').'px}';
1720 }else {echo'700px}';}
1721 echo'</style>';
1722 }
1723
1724 //Build Admin Menus
1725 add_action('admin_menu', 'church_admin_menus');
1726 /**
1727 *
1728 * Admin menu
1729 *
1730 * @author Andy Moyle
1731 * @param null
1732 * @return
1733 * @version 0.1
1734 *
1735 */
1736 function church_admin_menus()
1737
1738 {
1739
1740 global $level;
1741
1742 add_menu_page('church_admin:Administration', esc_html(__('Church Admin','church-admin' ) ), 'read', 'church_admin/index.php', 'church_admin_main',CA_ICON,98);
1743 }
1744
1745 // Admin Bar Customisation
1746 /**
1747 *
1748 * Admin Bar Menu
1749 *
1750 * @author Andy Moyle
1751 * @param null
1752 * @return
1753 * @version 0.1
1754 *
1755 */
1756 function church_admin_admin_bar_render() {
1757
1758 global $wp_admin_bar;
1759 // Add a new top level menu link
1760 // Here we add a customer support URL link
1761 if(current_user_can('publish_posts') )
1762 {
1763 $wp_admin_bar->add_menu( array('parent' => false,
1764 'id' => 'church_admin',
1765 'title' => esc_html(__('Church Admin','church-admin' ) ),
1766 'href' => admin_url().'admin.php?page=church_admin/index.php' ) );
1767 if(church_admin_level_check('Directory') ){
1768 $wp_admin_bar->add_menu(array ('parent' => 'church_admin',
1769 'id'=> 'household1',
1770 'title'=>esc_html( __('New Household','church-admin' ) ),
1771 'href'=>wp_nonce_url(admin_url().'admin.php?page=church_admin/index.php&amp;section=people&action=add-household','add-household')
1772 )
1773 );
1774 $wp_admin_bar->add_menu(array ('parent' => 'church_admin',
1775 'id'=> 'household2',
1776 'title'=>esc_html( __('Quick Household','church-admin' ) ),
1777 'href'=>wp_nonce_url(admin_url().'admin.php?page=church_admin/index.php&amp;section=people&action=quick-household','quick-household')
1778 )
1779 );
1780 }
1781 if(church_admin_level_check('Calendar') ){
1782 $wp_admin_bar->add_menu(array ('parent' => 'church_admin',
1783 'id'=> 'calendar1',
1784 'title'=>esc_html( __('New Calendar Item','church-admin' ) ),
1785 'href'=>wp_nonce_url(admin_url().'admin.php?page=church_admin/index.php&action=edit-calendar','edit-calendar')
1786 )
1787 );
1788 }
1789 if(church_admin_level_check('Media') ){
1790 $wp_admin_bar->add_menu(array ('parent' => 'church_admin',
1791 'id'=> 'sermon1',
1792 'title'=>esc_html( __('New Sermon','church-admin' ) ),
1793 'href'=>wp_nonce_url(admin_url().'admin.php?page=church_admin/index.php&action=upload-mp3','upload-mp3')
1794 )
1795 );
1796 }
1797 if(current_user_can('manage_options') ){
1798 $wp_admin_bar->add_menu(array('parent' => 'church_admin','id' => 'church_admin_settings', 'title' => esc_html(__('Settings','church-admin' ) ), 'href' => wp_nonce_url(admin_url().'admin.php?page=church_admin/index.php&action=settings','settings') ) );
1799 }
1800 $wp_admin_bar->add_menu(array('parent' => 'church_admin','id' => 'plugin_support', 'title' => esc_html(__('Plugin Support','church-admin' ) ), 'href' => 'https://www.churchadminplugin.com/support/' ) );
1801 }
1802 }
1803
1804 // Finally we add our hook function
1805 add_action( 'wp_before_admin_bar_render', 'church_admin_admin_bar_render' );
1806
1807
1808
1809
1810 //main admin page function
1811
1812
1813 function church_admin_main()
1814 {
1815 global $wpdb;
1816 $user=wp_get_current_user();
1817
1818 //check if premium is installed
1819 $installed_plugins = get_plugins();
1820
1821 if(!empty($installed_plugins['church-admin-premium/index.php']) && !is_plugin_active('church-admin-premium/index.php')){
1822 echo'<div class="notice notice-danger"><h2>Church Admin Premium</h2>';
1823 echo'<p>'.esc_html(__('You have already installed the premium version. Please activate "Church Admin Premium Version" and then deactivate "Church Admin".','church-admin') ).'</p>';
1824 echo'<p><a class="button-primary" href="'.esc_url(wp_nonce_url(admin_url().'plugins.php?action=deactivate&plugin=church-admin/church-admin.php','deactivate-plugin_church-admin/church-admin.php')).'">'.esc_html(__('Deactivate now','church-admin')).'</a></p>';
1825 wp_die();
1826 }
1827
1828 if(is_plugin_active('church-admin-premium/index.php')){
1829 echo'<div class="notice notice-danger"><h2>Church Admin Premium</h2>';
1830 echo'<p>'.esc_html(__('You have already installed and activated the premium version. Please deactivate the free version of "Church Admin", using the button below.','church-admin')).'</p>';
1831 echo'<p><a class="button-primary" href="'.esc_url(wp_nonce_url(admin_url().'plugins.php?action=deactivate&plugin=church-admin/church-admin.php','deactivate-plugin_church-admin/church-admin.php')).'">'.esc_html(__('Deactivate now','church-admin')).'</a></p>';
1832 echo'</div>';
1833 wp_die();
1834 }
1835
1836 //only using modern style now.
1837 echo'<div class="church-admin-wrap-new"><!--church_admin_main-->'."\r\n";
1838 if ( empty( $_GET['action'] ) )
1839 {
1840 church_admin_boxes_look();
1841 }else
1842 {
1843 echo'<div class="church-admin-content">'."\r\n";
1844 echo'<div id="church-admin-header">'."\r\n";
1845 echo '<h1 class="church-admin-title"><a title="'.esc_html( __('Back to menu','church-admin')).'" href="'.esc_url(admin_url().'admin.php?page=church_admin/index.php').'"><span class="ca-dashicons dashicons dashicons-menu-alt3" style="text-decoration:none;"></span></a> Church Admin Plugin v'.CHURCH_ADMIN_VERSION.'</h1>';
1846
1847 //church_admin_modules_dropdown();
1848 echo '</div><!-- END church-admin-header-->'."\r\n";
1849 church_admin_actions();
1850 echo'</div><!-- END church-admin-content-->'."\r\n";
1851 }
1852 echo'</div><!-- .church-admin-wrap-new -->'."\r\n";
1853
1854 echo'<script>// shorthand no-conflict safe document-ready function
1855 jQuery(function( $) {
1856
1857 $( document ).on( "click", ".notice-church-admin .notice-dismiss", function () {
1858
1859 var type = $( this ).closest( ".notice-church-admin" ).data( "notice" );
1860
1861 $.ajax( ajaxurl,
1862 {
1863 type: "POST",
1864 data: {
1865 action:"church-admin",
1866 method: "dismissed_notice_handler",
1867 type: type,
1868 }
1869 } );
1870 } );
1871 });</script>'."\r\n";
1872
1873
1874 }
1875 /**************************************************
1876 *
1877 * MAIN SHORTCODE FUNCTION
1878 *
1879 *********************************************************/
1880 function church_admin_shortcode( $atts, $content = null)
1881 {
1882
1883 $current_user=wp_get_current_user();
1884 if(!empty($atts) && is_array($atts)){
1885 //sort out true false issue where it gets evaluated as a string
1886 foreach( $atts AS $key=>$value)
1887 {
1888 if( $value==='FALSE'||$value==='false')$atts[$key]=0;
1889 if( $value==='TRUE'||$value==='true')$atts[$key]=1;
1890 }
1891 }
1892 extract(shortcode_atts(array('series_id'=>null,'login_form'=>1,'allow_registrations'=>1,'vcf'=>1,'address_style'=>'one','loginform'=>1,'cache'=>3600,'upcoming'=>true,'playlist_id'=>NULL,'nowhite'=>FALSE,'start_date'=>NULL,'target'=>0,'fund'=>NULL,'monthly'=>TRUE,'cache'=>1,'pdf'=>1,'zoom'=>13,'class_id'=>NULL,'day_calendar'=>TRUE,'style'=>'new','kids'=>TRUE,'height'=>500,'width'=>900,"pdf_font_resize"=>TRUE,"updateable"=>1,"restricted"=>0,"loggedin"=>1,"type" => 'address-list','people_types'=>'all','site_id'=>0,'days'=>30,'year'=>date('Y'),'service_id'=>NULL,'photo'=>0,'category'=>NULL,'weeks'=>4,'ministry_id'=>NULL,'people_type_id'=>NULL,'member_type_id'=>NULL,'kids'=>1,'map'=>0,'series_id'=>NULL,'speaker_id'=>NULL,'file_id'=>NULL,'api_key'=>NULL,'facilities_id'=>NULL,'exclude'=>NULL,'today'=>FALSE,'first_initial'=>0,'show_age'=>FALSE,'show_years'=>FALSE,'most_popular'=>TRUE,'order'=>'DESC','people_types'=>NULL,'title'=>"",'event_id'=>NULL,'unit_id'=>NULL,'url'=>NULL,'comments_title'=>NULL,'url'=>NULL,'hide_views'=>FALSE,'mode'=>"households","max_fields"=>10,'admin_email'=>NULL,'no_address'=>NULL,'cols'=>3,'sermon_page'=>NULL,'initials'=>0,'allow_registration'=>TRUE,"email_text"=>'','background'=>FALSE,'colorscheme'=>'','custom_id'=>NULL,'links'=>TRUE,'name_style'=>'Full','how_many'=>9,'playnoshow'=>0,'show_email'=>0,'show_phone'=>0,'rolling'=>null,'custom_fields'=>0,'onboarding'=>0,'category'=>null,'cat_id'=>null,'full_privacy_show'=>1), $atts) );
1893 church_admin_posts_logout();
1894
1895 //sanitize
1896 $allow_registrations = !empty($allow_registrations)?1:0;
1897 $vcf = !empty($vcf)?1:0;
1898 $show_email = !empty($show_email)?1:0;
1899 $show_phone = !empty($show_phone)?1:0;
1900 $full_privacy_show =!empty($full_privacy_show) ? 1 :0;
1901 $file_id = !empty($file_id) ? (int)$file_id: null;
1902 //validate
1903 if(!empty($zoom) && !church_admin_int_check($zoom)){
1904 $zoom = 13;
1905 }
1906
1907
1908
1909 // TO DO further sanitization required...
1910
1911 $out='<div class="church-admin-shortcode-output ';
1912 if(!empty( $colorscheme) )
1913 {
1914 switch( $colorscheme)
1915 {
1916 case 'white':
1917 $out.='ca-background ';
1918 break;
1919 case 'bluegrey':
1920 default:
1921 $out.=' ca-dark-mode-blue-grey ';
1922 break;
1923 case 'warmgrey':
1924 $out.=' ca-dark-mode-warm-grey ';
1925 break;
1926 case 'coolgrey':
1927 $out.=' ca-dark-mode-cool-grey ';
1928 break;
1929 }
1930 }
1931 if(!empty( $background) )$out.=' ca-background ';
1932 $out.='">';
1933 global $wpdb,$wp_query;
1934
1935 $upload_dir = wp_upload_dir();
1936 $path=$upload_dir['basedir'].'/church-admin-cache/';
1937 //look to see if church directory is o/p on a password protected page
1938 if(!empty( $wp_query->post->ID) )$pageinfo=get_page( $wp_query->post->ID);
1939 //grab page info
1940 //check to see if on a password protected page
1941 if(!empty( $pageinfo)&& $pageinfo->post_password!=''&&isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
1942 {
1943 $text = __('Log out of password protected posts','church-admin');
1944 //text for link
1945 $link = site_url().'?church_admin_logout=posts_logout';
1946 $out.= '<p><a href="' . esc_url( wp_nonce_url( $link, 'posts logout') ).'">' . esc_html( $text ). '</a></p>';
1947 //output logoutlink
1948 }
1949
1950 //grab content
1951 switch( $type)
1952 {
1953 case 'mailing-list':
1954 require_once( plugin_dir_path( __FILE__ ).'display/mailing-list.php');
1955 $out.=church_admin_mailing_list($member_type_id);
1956 break;
1957
1958 case 'not-logged-in':
1959 case 'not-logged-in':
1960 if(!is_user_logged_in() ){
1961 if(!empty($login_form)){
1962 $content.= '<div class="login"><h2>'.esc_html( __('Please login','church-admin') ).'</h2>'.wp_login_form(array('echo'=>FALSE,'redirect'=>get_permalink()) ).'</div>'.'<p><a href="'.wp_lostpassword_url(get_permalink() ).'" title="Lost Password">'.esc_html( __('Help! I don\'t know my password','church-admin') ).'</a></p>';
1963
1964 }
1965 return $content;
1966 }
1967 break;
1968 case 'logged-in':
1969 case 'logged-in':
1970 if(is_user_logged_in() )return $content;
1971 break;
1972 case 'spiritual-gifts':
1973 require_once( plugin_dir_path( __FILE__ ).'display/spiritual-gifts.php');
1974 $out.=church_admin_spiritual_gifts( $admin_email);
1975 break;
1976 case'unit':
1977 require_once( plugin_dir_path( __FILE__ ).'display/units.php');
1978 $out.=church_admin_display_unit( $unit_id);
1979 break;
1980 case 'attendance':
1981 if(is_user_logged_in()&&church_admin_level_check('Directory') )
1982 {
1983 require_once( plugin_dir_path( __FILE__ ).'includes/individual_attendance.php');
1984 $out.=church_admin_individual_attendance();
1985 }
1986 else
1987 {
1988 $out.='<h3>'.esc_html( __('Only logged in users with permission can use this feature','church-admin' ) ).'</h3>';
1989 $out.=wp_login_form(array('echo' => false) );
1990 }
1991 break;
1992
1993 case 'volunteer':
1994 require_once( plugin_dir_path( __FILE__ ).'display/volunteer.php');
1995 $out.=church_admin_display_volunteer();
1996 break;
1997 case 'sessions':
1998 require_once( plugin_dir_path( __FILE__ ).'includes/sessions.php');
1999 $out.=church_admin_sessions(NULL,NULL);
2000 break;
2001 case 'video':
2002 if(!empty( $url) )
2003 {
2004
2005 $embed=church_admin_generateVideoEmbedUrl( $url);
2006 $out.="\r\n<!-- CHURCH ADMIN VIDEO EMBED -->\r\n";
2007 $out.='<div class="container-fluid no-padding">'."\r\n";
2008 $out.='<div style="position:relative;padding-top:56.25%">'."\r\n";
2009 $out.='<iframe class="ca-video" loading="lazy" style="position:absolute;top:0;left:0;width:100%;height:100%;" src="'.esc_url($embed['embed']).'" '."\r\n";
2010 if(!empty( $embed['image'] ) )$out.='srcdoc="<style>*{padding:0;margin:0;overflow:hidden}html,body{height:100%}img,span{position:absolute;width:100%;top:0;bottom:0;margin:auto}span{height:1.5em;text-align:center;font:48px/1.5 sans-serif;color:white;text-shadow:0 0 0.5em black}</style><a href='.esc_url($embed['embed']).'?autoplay=1&mute=1><img src='.esc_url( $embed['image'] ) .' alt=Youtube><span class=ca-play>â–¶</span></a>" '."\r\n";
2011 $out.='frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'."\r\n";
2012 $out.="</div>\r\n</div>\r\n";
2013 $views=church_admin_youtube_views_api( $embed['id'] );
2014 //translators: video views with count
2015 if(!empty( $views)&& empty( $hide_views) )$out.='<p>'.esc_html( sprintf(__('%1$s views','church-admin' ) ,$views) ).'</p>';
2016 }
2017 break;
2018 case 'podcast':
2019 wp_enqueue_script('church-admin-datepicker');
2020 church_admin_podcast_script();
2021 require_once( plugin_dir_path( __FILE__ ).'display/sermon-podcast.php');
2022
2023 $out.=church_admin_podcast_display( $series_id,$file_id,$exclude,$most_popular,$order,$nowhite);
2024
2025 break;
2026
2027 case 'sermons':
2028 wp_enqueue_script('church-admin-datepicker');
2029 require_once( plugin_dir_path( __FILE__ ).'display/new-sermon-podcast.php');
2030 //validate variables
2031 $how_many = (!empty($how_many) && church_admin_int_check($how_many)) ? (int)$how_many : 9;
2032 $nowhite = !empty( $nowhite ) ? 1 : 0;
2033 $playnoshow = !empty( $playnoshow ) ? 1 : 0;
2034 $start_date = (!empty($start_date) && church_admin_checkdate($start_date)) ? $start_date : null;
2035 $rolling = (!empty($rolling) && church_admin_int_check($rolling)) ? (int)$rolling : null;
2036
2037
2038 $out.= church_admin_new_sermons_display($how_many,$nowhite,$playnoshow,$start_date,$rolling);
2039 break;
2040 case 'sermon-series':
2041
2042 require_once( plugin_dir_path( __FILE__ ).'display/sermon-series.php');
2043 $out.=church_admin_all_the_series_display( $sermon_page);
2044
2045 break;
2046 case 'single-sermon':
2047 wp_enqueue_script('ca_podcast_audio_use');
2048 require_once( plugin_dir_path( __FILE__ ).'display/sermon-podcast.php');
2049 //$file_id=(int)church_admin_sanitize($_REQUEST['id']);
2050 $out.=church_admin_podcast_file_detail( $file_id , $exclude);
2051
2052 break;
2053 case 'latest-sermon':
2054 wp_enqueue_script('ca_podcast_audio_use');
2055 require_once( plugin_dir_path( __FILE__ ).'display/sermon-podcast.php');
2056
2057 $out.=church_admin_podcast_file_detail( NULL,NULL);
2058
2059 break;
2060 case 'watch-latest-sermon':
2061 require_once( plugin_dir_path( __FILE__ ).'display/recent-message.php');
2062 $out.=church_admin_latest_sermon();
2063 break;
2064 case 'player':
2065 wp_enqueue_script('ca_podcast_audio_use');
2066 require_once( plugin_dir_path( __FILE__ ).'display/sermon-podcast.php');
2067 if(!empty( $file_id) ) {$out.=church_admin_player( $file_id);}else{$out.=esc_html( __('No file specified','church-admin'));}
2068 break;
2069
2070 case 'calendar':
2071 wp_enqueue_script('church-admin-calendar');//Jan 2020 version
2072 wp_enqueue_script('church_admin_calendar');
2073 $out.='<div class="church-admin-calendar">';
2074 if ( empty( $facilities_id)&& !empty( $pdf) )
2075 {
2076 $out.='<table><tr><td>'.esc_html( __('Yearly Planner PDFs','church-admin' ) ).' </td><td> <form name="guideform" action="'.esc_url($_SERVER['PHP_SELF']).'" method="get"><select name="guidelinks" onchange="window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value"> <option selected="selected" value="">-- '.esc_html( __('Choose a PDF','church-admin' ) ).' --</option>';
2077 for ( $x=0; $x<5; $x++ )
2078 {
2079 $y=date('Y')+$x;
2080 $out.='<option value="'.home_url().'/?ca_download=yearplanner&amp;yearplanner='.wp_create_nonce('yearplanner').'&amp;year='.(int)$y.'">'.(int)$y.esc_html( __('Year Planner','church-admin' ) ).'</option>';
2081 }
2082 $out.='</select></form></td></tr></table>';
2083 }
2084 if( $style=='old'||!empty( $facilities_id) )
2085 {
2086 require_once( plugin_dir_path( __FILE__ ).'display/calendar.php');
2087 $out.=church_admin_display_calendar( $facilities_id);
2088 }
2089 else
2090 {
2091 require_once( plugin_dir_path( __FILE__ ).'display/calendar.new.php');
2092 //$out.=church_admin_new_calendar_display('day',$day_calendar);
2093 $out.=church_admin_display_new_calendar($cat_id,$facilities_id);
2094 }
2095 $out.='</div>';
2096 break;
2097 case 'calendar-table':
2098 wp_enqueue_script('church-admin-calendar');//Jan 2020 version
2099 wp_enqueue_script('church_admin_calendar');
2100 $out.='<div class="church-admin-calendar">';
2101 if ( empty( $facilities_id)&& !empty( $pdf) )
2102 {
2103 $out.='<table><tr><td>'.esc_html( __('Yearly Planner PDFs','church-admin' ) ).' </td><td> <form name="guideform" action="'.esc_url($_SERVER['PHP_SELF']).'" method="get"><select name="guidelinks" onchange="window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value"> <option selected="selected" value="">-- '.esc_html( __('Choose a PDF','church-admin' ) ).' --</option>';
2104 for ( $x=0; $x<5; $x++ )
2105 {
2106 $y=date('Y')+$x;
2107 $out.='<option value="'.home_url().'/?ca_download=yearplanner&amp;yearplanner='.wp_create_nonce('yearplanner').'&amp;year='.(int)$y.'">'.(int)$y.esc_html( __('Year Planner','church-admin' ) ).'</option>';
2108 }
2109 $out.='</select></form></td></tr></table>';
2110 }
2111
2112 require_once( plugin_dir_path( __FILE__ ).'display/calendar.php');
2113 $out.=church_admin_display_calendar( $facilities_id,$category);
2114
2115 $out.='</div>';
2116 break;
2117 case 'classes':
2118 wp_enqueue_script('jquery-ui-datepicker');
2119 require_once( plugin_dir_path( __FILE__ ).'display/classes.php');
2120 $out.=church_admin_display_classes( $today,$allow_registration);
2121 $out.='<script type="text/javascript">jQuery(function( $) {
2122
2123 $(".ca-class-toggle").click(function() {
2124 var id=this.id;
2125 console.log(id);
2126 $("."+id).toggle();
2127 });
2128
2129 });</script>';
2130 break;
2131 case 'class':
2132 wp_enqueue_script('jquery-ui-datepicker');
2133 require_once( plugin_dir_path( __FILE__ ).'display/classes.php');
2134 $out.=church_admin_display_class( $class_id,TRUE,$allow_registration);
2135
2136 break;
2137 case 'facilities':
2138 require_once( plugin_dir_path( __FILE__ ).'display/calendar.php');
2139 $out.=church_admin_display_calendar( $facilities_id);
2140 break;
2141 case 'facility-booking':
2142 //require_once( plugin_dir_path( __FILE__ ).'display/facility-bookings.php');
2143
2144 //$out.=church_admin_facility_booking( $facilities_id);
2145 break;
2146 case 'names':
2147 if ( empty( $loggedin)||is_user_logged_in() )
2148 {
2149 require_once( plugin_dir_path( __FILE__ ).'/display/names.php'); $out.=church_admin_names( $member_type_id,$people_types);
2150 }
2151 else //login required
2152 {
2153 $out.='<div class="login"><h2>'.esc_html( __('Please login','church-admin') ).'</h2>'.wp_login_form(array('echo'=>FALSE,'redirect'=>get_permalink()) ).'</div>'.'<p><a href="'.esc_url( wp_lostpassword_url( get_permalink() ) ).'" title="Lost Password">'.esc_html( __('Help! I don\'t know my password','church-admin') ).'</a></p>';
2154 }
2155 break;
2156
2157 case 'calendar-list':
2158 require_once( plugin_dir_path( __FILE__ ).'/display/calendar-list.php');
2159 $out.=church_admin_calendar_list( $days,$category);
2160 break;
2161 case 'event_booking':
2162 case 'event':
2163 case 'events':
2164 wp_enqueue_script('church-admin-event-booking'); require_once( plugin_dir_path( __FILE__ ).'/display/events.php');
2165 $out.=church_admin_event_bookings_output( $event_id);
2166 break;
2167
2168 case 'recent':
2169 $access=TRUE;
2170 if(is_user_logged_in() )
2171 {
2172
2173 $current_user=wp_get_current_user();
2174 $people_id=$wpdb->get_var('SELECT people_id FROM '.$wpdb->prefix.'church_admin_people WHERE user_id="'.(int)$current_user->ID.'"');
2175 $restrictedList=get_option('church-admin-restricted-access');
2176 if(is_array( $restrictedList)&&in_array( $people_id,$restrictedList) )$access=FALSE;
2177 }
2178 if ( empty( $loggedin)||is_user_logged_in() && $access)
2179 {
2180 require_once( plugin_dir_path( __FILE__ ).'includes/recent.php');
2181 $out.=church_admin_recent_display( $weeks,$member_type_id);
2182 }
2183 else //login required
2184 {
2185 if(!$access && is_user_logged_in() )$out.='<div class="notice notice-warning inline">'.esc_html( __("You haven't been granted access to this infromation",'church-admin' ) ) .'</div>';
2186 $out.='<div class="login"><h2>'.esc_html( __('Please login','church-admin' ) ).'</h2>'.wp_login_form(array('echo'=>FALSE,'redirect'=>get_permalink()) ).'</div>'.'<p><a href="'.esc_url( wp_lostpassword_url( get_permalink() ) ).'" title="Lost Password">'.esc_html(__('Help! I don\'t know my password','church-admin')).'</a></p>';
2187 }
2188 break;
2189 case 'phone-list':
2190 $access=TRUE;
2191 if(is_user_logged_in() )
2192 {
2193
2194 $current_user=wp_get_current_user();
2195 $people_id=$wpdb->get_var('SELECT people_id FROM '.$wpdb->prefix.'church_admin_people WHERE user_id="'.(int)$current_user->ID.'"');
2196 $restrictedList=get_option('church-admin-restricted-access');
2197 if(is_array( $restrictedList)&&in_array( $people_id,$restrictedList) )$access=FALSE;
2198 }
2199 if ( empty( $loggedin)||is_user_logged_in() && $access)
2200 {
2201 require_once( plugin_dir_path( __FILE__ ).'display/phone-list.php');
2202 $out.=church_admin_frontend_phone_list( $people_type_id,$member_type_id);
2203 }
2204 else //login required
2205 {
2206 if ( empty( $access) ) $out.='<h2>'.esc_html(__('You have not been granted access to the address list','church-admin')).'</h2>';
2207 else $out.='<div class="login"><h2>'.esc_html(__('Please login','church-admin')).'</h2>'.wp_login_form(array('echo'=>FALSE,'redirect'=>get_permalink()) ).'</div>'.'<p><a href="'.esc_url(wp_lostpassword_url(get_permalink() )).'" title="Lost Password">'.esc_html( __('Help! I don\'t know my password','church-admin') ).'</a></p>';
2208 }
2209 break;
2210 case 'custom-field':
2211 case 'custom-fields':
2212 $out.='<div class="church-admin-custom-field">';
2213 require_once( plugin_dir_path( __FILE__ ).'display/custom-fields.php');
2214 $out.=church_admin_display_custom_field( $days,$show_years,$custom_id);
2215 $out.='</div>';
2216 break;
2217 case 'address-list':
2218 case'addresslist':
2219 case 'directory':
2220 //assumed no access allowed
2221 $out.='<div class="church-admin-directory">';
2222 $access=FALSE;
2223 if( $loggedin)
2224 {
2225 if(!is_user_logged_in() )
2226 {
2227 $out.='<div class="login"><h2>'.esc_html( __( 'Please login', 'church-admin' ) ).'</h2>'.wp_login_form(array('echo'=>FALSE,'redirect'=>get_permalink()) ).'</div>'.'<p><a href="'.wp_lostpassword_url(get_permalink() ).'" title="Lost Password">'.esc_html( __('Help! I don\'t know my password','church-admin' ) ).'</a></p>';
2228 $out.='</div>';
2229 return $out;
2230 }
2231 if(!empty( $member_type_id) )
2232 {
2233 if( $member_type_id=='All'||$member_type_id=='all'||$member_type_id=='#')
2234 {
2235 $access=true;
2236 }
2237 else
2238 {
2239 $current_user=wp_get_current_user();
2240 $mtArray=explode(",",$member_type_id);
2241 //church_admin_debug("mtArray");
2242 //church_admin_debugprint_r( $mtArray,TRUE) );
2243 $mt_id=$wpdb->get_var('SELECT member_type_id FROM '.$wpdb->prefix.'church_admin_people WHERE user_id="'.(int)$current_user->ID.'"');
2244 //church_admin_debug('User mt '.$mt_id);
2245 if ( empty( $mt_id) )return'<p>'.esc_html( __('Your login does not permit viewing the address list','church-admin' ) ).'</p>';
2246
2247 if(!church_admin_level_check('Directory')&&!empty( $mt_id)&&!in_array( $mt_id,$mtArray) ) {
2248 $out.='<p>'.esc_html( __('Your login does not permit viewing the address list','church-admin' ) ).'</p>';
2249 $out.='</div>';
2250 return $out;
2251 }
2252 $access=TRUE;
2253 }
2254 }
2255 if ( empty( $member_type_id) )$access=true;
2256
2257
2258 if(!church_admin_level_check('Directory')&& !empty($restrictedList) && is_array( $restrictedList)&&in_array( $people_id,$restrictedList) ){
2259 return'<p>'.esc_html( __('Your login does not permit viewing the address list', 'church-admin' ) ).'</p>';
2260 }
2261 if(church_admin_level_check('Directory') )$access=TRUE;
2262 }
2263 else
2264 {
2265 //open access
2266 $access=TRUE;
2267 }
2268
2269 if(!empty( $access) )
2270 {
2271 if(!empty( $pdf) )
2272 {
2273 $out.='<div class="church-admin-address-pdf-links">';
2274 switch( $pdf)
2275 {
2276 case '2':
2277 $out.='<p><a rel="nofollow" href="'.home_url().'/?ca_download=addresslist&amp;addresslist='.wp_create_nonce('address-list','address-list').'&amp;title='.urlencode( $title).'&amp;loggedin='.$loggedin.'&amp;pdfversion=2&amp;member_type_id='.$member_type_id.'" target="_blank"> '.esc_html( __('PDF version','church-admin' ) ).'</a></p>';
2278 break;
2279 case 'multi':
2280
2281 $out.='<p><a rel="nofollow" target="_blank" href="'.wp_nonce_url(home_url().'/?ca_download=addresslist-family-photos&amp;address_style=multi&amp;loggedin='.$loggedin.'&amp;title='.urlencode( $title).'&amp;kids='.$kids.'&amp;member_type_id='.$member_type_id,'address-list').'">'.esc_html( __('PDF version','church-admin' ) ).'</a></p>';
2282 break;
2283 default:
2284 case 1:
2285 $out.='<p><a rel="nofollow" target="_blank" href="'.wp_nonce_url(home_url().'/?ca_download=addresslist-family-photos&amp;loggedin='.$loggedin.'&amp;title='.urlencode( $title).'&amp;kids='.$kids.'&amp;member_type_id='.$member_type_id,'address-list' ).'">'.esc_html( __('PDF version','church-admin' ) ).'</a></p>';
2286 break;
2287
2288 }
2289 $out.='</div>';
2290 }
2291 if( $style=='old')
2292 {
2293 require_once( plugin_dir_path( __FILE__ ).'display/address-list.old.php');
2294 $out.=church_admin_frontend_directory( $member_type_id,$map,$photo,$api_key,$kids,$site_id,$updateable,$address_style);
2295 }
2296 else
2297 {
2298 require_once( plugin_dir_path( __FILE__ ).'display/address-list.php');
2299 $out.=church_admin_frontend_directory( $member_type_id,$map,$photo,$api_key,$kids,$site_id,$updateable,$first_initial,0,$vcf,$address_style);
2300 //$out.=church_admin_frontend_directory( $member_type_id,$map,$photo,$api_key,$kids,$site_id,$updateable,$first_initial,$cache,$address_style);
2301 //$out.=' <p><a href="'.get_permalink().'?ca_refresh=TRUE">'.esc_html( __("Refresh",'church-admin' ) ).'</a></p>';
2302 }
2303 $out.='</div>';
2304 }
2305 else{ $out.='<h2>'.esc_html( __('You have not been granted access to the address list','church-admin' ) ).'</h2>';}
2306
2307 break;
2308 case 'bible-readings':
2309 case 'bible-reading':
2310 require_once( plugin_dir_path( __FILE__ ).'display/bible-readings.php' );
2311 $out.=church_admin_bible_reading_shortcode();
2312 break;
2313
2314 case 'hello':
2315 if(is_user_logged_in() )
2316 {
2317 $user=wp_get_current_user();
2318 $name=$wpdb->get_var('SELECT first_name FROM '.$wpdb->prefix.'church_admin_people WHERE user_id="'.(int)$user->ID.'"');
2319 if( !empty( $name) ){
2320 //translators: %1$s is users name
2321 $out.=esc_html( sprintf(__('Welcome back %1$s', 'church-admin' ), $name ) );
2322 }
2323 }
2324 break;
2325 case 'small-groups-list':
2326 wp_enqueue_script('church_admin_google_maps_api');
2327 wp_enqueue_script('church_admin_sg_map_script');
2328
2329 require_once( plugin_dir_path( __FILE__ ).'/display/small-group-list.php');
2330 $out.= church_admin_small_group_list( $map,$zoom,$photo,$loggedin,$title,$pdf,$no_address);
2331 break;
2332 case 'my-group':
2333 require_once( plugin_dir_path( __FILE__ ).'/display/my-group.php');
2334 $out.=church_admin_my_group();
2335 break;
2336 case 'small-group-signup':
2337 require_once( plugin_dir_path( __FILE__ ).'/display/small-group-signup.php');
2338 $out.=church_admin_smallgroup_signup( $title,$people_types);
2339 break;
2340 case 'small-groups':
2341 wp_enqueue_script('church_admin_google_maps_api');
2342 wp_enqueue_script('church_admin_sg_map_script');
2343 require_once( plugin_dir_path( __FILE__ ).'/display/small-groups.php' );
2344 $out.= church_admin_frontend_small_groups( $member_type_id,$restricted);
2345 break;
2346 case 'map':
2347 $out.=church_admin_map_shortcode( $atts, $content);
2348 break;
2349 case 'shortcode-generator':
2350
2351 require_once( plugin_dir_path( __FILE__ ).'includes/shortcode-generator.php' );
2352 $out.=church_admin_shortcode_generator();
2353 break;
2354 case 'register':
2355 case 'basic-register':
2356 wp_enqueue_script('ca-draganddrop');
2357 wp_enqueue_script('jquery-ui-datepicker');
2358 wp_enqueue_script('church_admin_map_script');
2359 $out.=church_admin_register( $atts, $content);
2360 break;
2361 case 'ministries':
2362 require_once( plugin_dir_path( __FILE__ ).'/display/ministries.php');
2363 $out.=church_admin_frontend_ministries( $ministry_id,$member_type_id);
2364 break;
2365
2366 case 'rolling-average':
2367 case 'weekly-attendance':
2368 case 'monthly-attendance':
2369 case 'rolling-average-attendance':
2370 case 'graph':
2371 wp_enqueue_script('jquery-ui-datepicker');
2372 wp_enqueue_script('church_admin_google_graph_api');
2373 if ( empty( $width) )$width=900;
2374 if ( empty( $height) )$height=500;
2375 if(!empty( $_POST['type'] ) )
2376 {
2377 switch( $_POST['type'] )
2378 {
2379 case'weekly':$graphtype='weekly';break;
2380 case'rolling':$graphtype='rolling';break;
2381 default:$graphtype='weekly';break;
2382 }
2383 }else{$graphtype='weekly';}
2384 if(!empty( $_POST['start'] ) ) {
2385 $start = sanitize_text_field(stripslashes($_POST['start']));
2386 //validate
2387 if(!church_admin_checkdate($start))
2388 {
2389 $start=date('Y-m-d',strtotime('-1 year') );
2390 }
2391 }
2392 else
2393 {
2394 $start=date('Y-m-d',strtotime('-1 year') );
2395 }
2396 if(!empty( $_POST['end'] ) ) {
2397 $end=sanitize_text_field(stripslashes($_POST['end']));
2398 //validate
2399 if(!church_admin_checkdate($end))
2400 {
2401 $end=date('Y-m-d',strtotime('-1 year') );
2402 }
2403 }else{
2404 $end=date('Y-m-d');
2405 }
2406 if(!empty( $_POST['service_id'] ) ) {
2407 $service_id=sanitize_text_field(stripslashes($_POST['service_id']));
2408 }else{
2409 $service_id='S/1';
2410 }
2411
2412 require_once( plugin_dir_path( __FILE__ ).'display/graph.php');
2413 $out.=church_admin_graph( $graphtype,$service_id,$start,$end,$width,$height,FALSE);
2414 break;
2415 case 'anniversaries':
2416 if ( empty( $loggedin)||is_user_logged_in() )
2417 {
2418 require_once( plugin_dir_path( __FILE__ ).'includes/birthdays.php');
2419 $out.=church_admin_frontend_anniversaries( $member_type_id,$people_type_id, $days,$show_age,$show_email,$show_phone);
2420 }
2421 else //login required
2422 {
2423 $out.='<div class="login"><h2>'.esc_html( __('Please login','church-admin' ) ).'</h2>'.wp_login_form(array('echo'=>FALSE,'redirect'=>get_permalink()) ).'</div>'.'<p><a href="'.esc_url( wp_lostpassword_url(get_permalink() ) ).'" title="Lost Password">'.esc_html( __('Help! I don\'t know my password','church-admin') ).'</a></p>';
2424 }
2425
2426 break;
2427 case 'birthdays':
2428 if ( empty( $loggedin)||is_user_logged_in() )
2429 {
2430 require_once( plugin_dir_path( __FILE__ ).'includes/birthdays.php');
2431 $out.=church_admin_frontend_birthdays( $member_type_id,$people_type_id, $days,$show_age,$show_email,$show_phone);
2432 }
2433 else //login required
2434 {
2435 $out.='<div class="login"><h2>'.esc_html( __('Please login','church-admin' ) ).'</h2>'.wp_login_form(array('echo'=>FALSE,'redirect'=>get_permalink()) ).'</div>'.'<p><a href="'.esc_url( wp_lostpassword_url(get_permalink() ) ).'" title="Lost Password">'.esc_html( __('Help! I don\'t know my password','church-admin') ).'</a></p>';
2436 }
2437
2438 break;
2439 case 'restricted':
2440 //restricts content to certain member_type_ids
2441 if(!is_user_logged_in() )
2442 {
2443 if(!empty( $loginform) ) {
2444 $out.='<div class="login"><h2>'.esc_html( __('Please login','church-admin') ).'</h2>'.wp_login_form(array('echo'=>FALSE,'redirect'=>get_permalink()) ).'</div>'.'<p><a href="'.wp_lostpassword_url(get_permalink() ).'" title="Lost Password">'.esc_html( __('Help! I don\'t know my password','church-admin') ).'</a></p>';
2445 }
2446 else{
2447 $out.='<p>'.esc_html( __('Restricted content','church-admin') ).'</p>';
2448 }
2449 }
2450 elseif(church_admin_user_member_level( $member_type_id) ) {
2451 $out.=do_shortcode( $content);
2452 }
2453 else{
2454 $out.=esc_html( __('You are not permitted to view this content','church-admin') );
2455 }
2456 break;
2457 case 'follow-up':
2458 if(is_user_logged_in()&& church_admin_level_check('Directory') )
2459 {
2460 require_once( plugin_dir_path( __FILE__ ).'includes/people_activity.php');
2461 return church_admin_recent_people_activity();
2462 }
2463 else{
2464 $out.=esc_html( __( 'You are not permitted to view this content', 'church-admin' ) );
2465 }
2466 break;
2467 default:
2468 if ( empty( $loggedin)||is_user_logged_in() )
2469 {
2470
2471 //$out.='<p><a rel="nofollow" href="'.home_url().'/?ca_download=addresslist&amp;addresslist='.wp_create_nonce('member'.$member_type_id ).'&amp;member_type_id='.$member_type_id.'">'.esc_html( __('PDF version','church-admin' ) ).'</a></p>';
2472 require_once( plugin_dir_path( __FILE__ ).'display/address-list.php');
2473 $out.=church_admin_frontend_directory( $member_type_id,$map,$photo,$api_key,$kids,$site_id,$updateable);
2474 }
2475 else //login required
2476 {
2477 $out.='<div class="login"><h2>'.esc_html( __('Please login','church-admin') ).'</h2>'.wp_login_form(array('echo'=>FALSE,'redirect'=>get_permalink()) ).'</div>'.'<p><a href="'.esc_url( wp_lostpassword_url(get_permalink() ) ).'" title="Lost Password">'.esc_html( __('Help! I don\'t know my password','church-admin') ).'</a></p>';
2478 }
2479 break;
2480 case 'covid-prebooking':
2481 case'service-prebooking':
2482
2483 if ( empty( $loggedin)||is_user_logged_in() )
2484 {
2485 wp_enqueue_script('church-admin-form-case-enforcer');
2486 require_once( plugin_dir_path( __FILE__ ).'display/covid-prebooking.php');
2487 $out.=church_admin_covid_attendance( $service_id,$mode,$max_fields,$days,$admin_email,$email_text);
2488 }
2489 else
2490 {
2491 $out.='<div class="login"><h2>'.esc_html( __('Please login','church-admin') ).'</h2>'.wp_login_form(array('echo'=>FALSE,'redirect'=>get_permalink()) ).'</div>'.'<p><a href="'.esc_url( wp_lostpassword_url(get_permalink() ) ).'" title="Lost Password">'.esc_html( __('Help! I don\'t know my password','church-admin') ).'</a></p>';
2492
2493 }
2494 break;
2495
2496 case 'how-much':
2497
2498 require_once( plugin_dir_path( __FILE__ ).'display/giving.php');
2499 $out.=church_admin_fund_so_far( $fund,$start_date,$target);
2500 break;
2501 case 'giving':
2502 wp_enqueue_script('church-admin-giving-form');
2503 require_once( plugin_dir_path( __FILE__ ).'display/giving.php');
2504 $out.=church_admin_giving_form( $fund,$monthly);
2505 break;
2506 case 'giving-totals':
2507 wp_enqueue_script('church-admin-giving-form');
2508 require_once( plugin_dir_path( __FILE__ ).'includes/pledges.php');
2509 $out .= church_admin_pledge_totals(FALSE);
2510 require_once( plugin_dir_path( __FILE__ ).'display/pledge.php');
2511 $out .='<p><button id="show-pledge" class="button">'.__('Pledge now','church-admin').'</button>&nbsp; <button id="show-giving" class="button">'.__('Give now','church-admin').'</button></p>';
2512 $out.='<script>
2513 jQuery(document).ready(function($){
2514 $("#show-pledge").click(function(){
2515 $(".giving-toggle").hide();
2516 $(".pledge-toggle").show();
2517 });
2518 $("#show-giving").click(function(){
2519 $(".pledge-toggle").hide();
2520 $(".giving-toggle").show();
2521 });
2522 });</script>';
2523 $out.='<div class="pledge-toggle" style="display:none">'.church_admin_pledge_form().'</div>';
2524 require_once( plugin_dir_path( __FILE__ ).'display/giving.php');
2525 $out.='<div class="giving-toggle" style="display:none">'.church_admin_giving_form( $fund,$monthly).'</div>';
2526 break;
2527 case 'pledge':
2528
2529 require_once( plugin_dir_path( __FILE__ ).'display/pledge.php');
2530 $out.=church_admin_pledge_form();
2531 break;
2532 case 'contact-form':
2533 require_once( plugin_dir_path( __FILE__ ).'display/contact.php');
2534 $out.=church_admin_contact_public();
2535 break;
2536 case 'not-available':
2537 require_once( plugin_dir_path( __FILE__ ).'display/not-available.php');
2538 $out.= church_admin_not_available();
2539 break;
2540 case 'latest-youtube':
2541 case 'latest_youtube':
2542 require_once( plugin_dir_path( __FILE__ ).'display/latest-youtube.php');
2543 $out.= church_admin_latest_youtube( $playlist_id,$cache);
2544 break;
2545 case 'toilet-message':
2546 require_once( plugin_dir_path( __FILE__ ).'display/kidswork-message.php');
2547 $out.= church_admin_toilet_message($ministry_id);
2548 break;
2549
2550 }
2551
2552 //output content instead of shortcode!
2553 $out.='</div>';
2554 return $out;
2555 }
2556
2557 add_shortcode('church_admin_unsubscribe','church_admin_unsubscribe');
2558 function church_admin_unsubscribe()
2559 {
2560 $out='<p>'.esc_html( __('This shortcode is deprecated','church-admin' ) ).'</p>';
2561 return $out;
2562 }
2563 add_shortcode('church_admin_recent','church_admin_recent');
2564 function church_admin_recent( $atts, $content = null)
2565 {
2566 extract(shortcode_atts(array('month'=>1), $atts) );
2567 require_once( plugin_dir_path( __FILE__ ).'includes/recent.php');
2568 $out = church_admin_recent_display( $month);
2569 return $out;
2570 }
2571 add_shortcode("church_admin", "church_admin_shortcode");
2572
2573 add_shortcode("church_admin_map","church_admin_map_shortcode");
2574 function church_admin_map_shortcode( $atts, $content = null)
2575 {
2576 $out='';
2577 extract(shortcode_atts(array('zoom'=>13,'member_type_id'=>1,'small_group'=>1,'unattached'=>0,'loggedin'=>1,'width'=>"100%",'height'=>"1000px",'colorscheme'=>''), $atts) );
2578 global $wpdb;
2579
2580 //sanitize
2581 $zoom = !empty($zoom) ? church_admin_sanitize($zoom): 13;
2582 $width = !empty($width) ? church_admin_sanitize($width): '100%';
2583 $height = !empty($height) ? church_admin_sanitize($height): '100%';
2584 $member_type_id = !empty($member_type_id) ? (int)church_admin_sanitize($member_type_id): null;
2585 $small_group = !empty($small_group) ? 1 : 0;
2586 $logged_in = !empty($logged_in) ? 1 : 0;
2587
2588 //validate
2589 if(!empty($zoom) && !church_admin_int_check($zoom)){
2590 $zoom = 13;
2591 }
2592 $out.='<div class="alignwide church-admin-shortcode-output ';
2593 if(!empty( $colorscheme) ) {
2594
2595 switch( $colorscheme)
2596 {
2597 case 'white':
2598 $out.='ca-background ';
2599 break;
2600 case 'bluegrey':
2601 default:
2602 $out.=' ca-dark-mode-blue-grey ';
2603 break;
2604 }
2605 }
2606 $out.='">';
2607 $out.= church_admin_map( $zoom,$member_type_id,$small_group,$unattached,$loggedin,$width,$height);
2608 $out.='</div>';
2609 return $out;
2610 }
2611 function church_admin_map( $zoom=13,$member_type_id=NULL,$small_group=1,$unattached=1,$loggedin=1,$width="100%",$height="500px")
2612 {
2613
2614
2615 //sanitize
2616 $zoom = !empty($zoom) ? church_admin_sanitize($zoom): 13;
2617 $width = !empty($width) ? church_admin_sanitize($width): null;
2618 $height = !empty($height) ? church_admin_sanitize($height): null;
2619 $member_type_id = !empty($member_type_id) ? (int)church_admin_sanitize($member_type_id): null;
2620 $small_group = !empty($small_group) ? 1 : 0;
2621 $logged_in = !empty($logged_in) ? 1 : 0;
2622
2623 //validate
2624 if(!empty($zoom) && !church_admin_int_check($zoom)){
2625 $zoom = 13;
2626 }
2627
2628
2629 global $wpdb;
2630 $out='';
2631 //if(defined("CA_DEBUG") )//church_admin_debug("****************\r\n church_admin_map function");
2632 if ( empty( $loggedin)||is_user_logged_in() )
2633 {
2634 wp_enqueue_script('church_admin_google_maps_api');
2635 wp_enqueue_script('church_admin_map');
2636
2637
2638 $coords=church_admin_center_coordinates($wpdb->prefix.'church_admin_household');
2639 //if(defined("CA_DEBUG") )//church_admin_debug('Center coordinates'."\r\n".print_r( $coords,TRUE) );
2640 $out.='<div class="church-admin-member-map"><script type="text/javascript">var xml_url="'.site_url().'/?ca_download=address-xml&member_type_id='.esc_html( $member_type_id).'&small_group='.esc_html( $small_group).'&unattached='.esc_html( $unattached).'&address-xml='.wp_create_nonce('address-xml').'";';
2641 $out.=' var lat='.esc_html( $coords->lat).';';
2642 $out.=' var lng='.esc_html( $coords->lng).';';
2643
2644 $out.=' var zoom='.(int) $zoom.';';
2645 $out.=' var translation=["'.esc_html( __('Small Groups','church-admin' ) ).'","'.esc_html( __('Unattached','church-admin' ) ).'","'.esc_html( __('In a group','church-admin' ) ).'","'.esc_html( __('Group','church-admin' ) ).'"];';
2646 $out.='jQuery(document).ready(function() {console.log("Ready to lead");
2647 load(lat,lng,xml_url,zoom,translation);});</script><div id="church-admin-member-map" style="width:'.esc_attr( $width ).';height:'.esc_attr( $height ).'"></div>';
2648 $out.='<div id="groups" ><p><img src="https://maps.google.com/mapfiles/kml/paddle/blu-circle.png" />'.esc_html( __('Small Group','church-admin' ) ).'<br><img src="https://maps.google.com/mapfiles/kml/paddle/red-circle.png" />'.esc_html( __('Not in a small group','church-admin' ) ).'<br><img src="https://maps.google.com/mapfiles/kml/paddle/grn-circle.png" />'.esc_html( __('In a small Group','church-admin') ).'</p></div>';
2649
2650 }
2651 else {
2652 $out.='<h3>'.esc_html( __('You need to be logged in to view the map','church-admin') ).'</h3>'.wp_login_form(array('echo'=>false) );
2653 }
2654 return $out;
2655
2656 }
2657 add_shortcode("church_admin_register","church_admin_register");
2658 function church_admin_register( $atts, $content = null)
2659 {
2660
2661 extract(shortcode_atts(array('allow_registrations'=>1,'member_type_id'=>1,'allow'=>NULL,'background'=>FALSE,'exclude'=>NULL,'custom_fields'=>0,'onboarding'=>0,'admin_email'=>1,'full_privacy_show'=>1), $atts) );
2662 $full_privacy_show =!empty($full_privacy_show) ? 1 :0;
2663
2664 $noshow=$allowArray=array();
2665 if(!empty( $exclude) )
2666 {
2667 $noshow=explode(",",$exclude);
2668 }
2669 if(!empty( $allow) )
2670 {
2671 $allowArray=explode(",",$allow);
2672 }
2673
2674 //allow for custom_fields shortcode value to override old style exclude array
2675 if(!empty($custom)){
2676
2677 if (($key = array_search('custom_fields', $noshow)) !== false) {
2678 unset($noshow[$key]);
2679 }
2680
2681 }
2682 //church_admin_debug $allowArray,TRUE);
2683 require_once( plugin_dir_path( __FILE__ ).'includes/front_end_register.php');
2684 wp_enqueue_script('church_admin_google_maps_api');
2685 wp_enqueue_script('church_admin_map_script');
2686 wp_enqueue_script('ca-draganddrop');
2687 wp_enqueue_script('jquery-ui-datepicker');
2688 wp_enqueue_style('church-admin-ui',plugins_url('/',dirname(__FILE__) ). 'css/jquery-ui-1.13.2.css',false,"1.13.2",false);
2689 $out=church_admin_front_end_register( $member_type_id, $noshow, $admin_email, $allowArray, $allow_registrations,$onboarding,$full_privacy_show);
2690 return $out;
2691 }
2692
2693 function church_admin_posts_logout()
2694 {
2695 if ( isset( $_GET['church_admin_logout'] ) && ( 'posts_logout' == $_GET['church_admin_logout'] ) &&check_admin_referer( 'posts logout' ) )
2696 {
2697 setcookie( 'wp-postpass_' . COOKIEHASH, ' ', time() - 31536000, COOKIEPATH );
2698 wp_redirect( wp_get_referer() );
2699 die();
2700 }
2701 }
2702
2703
2704 add_action( 'init', 'church_admin_posts_logout' );
2705
2706 //end of logout functions
2707
2708
2709
2710 add_action('init','church_admin_download');
2711 function church_admin_download()
2712 {
2713 global $wpdb;
2714
2715 /*********************************
2716 * Handle delete me from app
2717 *
2718 ******************************/
2719
2720 if(!empty($_GET['church_admin_delete'])){
2721
2722 //translators %1$s is the name of the website
2723 echo'<!doctype html><html><head><title>'.esc_html(__('User delete','church-admin')).'</title><style>body { text-align: center; padding:150px; }h1 { font-size: 50px; }body { font: 20px Helvetica, sans-serif; color: #333; }article { display: block; text-align:center; width: 650px; margin: 0 auto; }a { color: #dc8100; text-decoration: none; }a:hover { color: #333; text-decoration: none; }</style></head><body><article><p style="text-align:center"><img src="'.plugins_url('/', __FILE__ ) .'images/church-admin-logo.png"></p><h2>'.esc_html(sprintf(__('User deletion for %1$s','church-admin'),get_bloginfo('name'))).'</h2><p>';
2724
2725 $people_id = !empty($_GET['church_admin_delete'])? church_admin_sanitize($_GET['church_admin_delete']): null;
2726 $token = !empty($_GET['token'])? church_admin_sanitize($_GET['token']): null;
2727 if(!empty($people_id) && !empty($token)){
2728 $loginStatus = $wpdb->get_row('SELECT b.UUID AS token,a.member_type_id,a.people_id,a.user_id,a.household_id FROM '.$wpdb->prefix.'church_admin_people a, '.$wpdb->prefix.'church_admin_app b WHERE a.user_id=b.user_id AND b.UUID="'.esc_sql($token).'"');
2729
2730 if(!empty($loginStatus) && $people_id == $loginStatus->people_id){
2731 $household_numbers = $wpdb->get_var('SELECT COUNT(*) FROM '.$wpdb->prefix.'church_admin_people WHERE household_id="'.(int)$loginStatus->household_id.'"');
2732 if(!empty($household_numbers) && $household_numbers==1){$wpdb->query('DELETE FROM '.$wpdb->prefix.'church_admin_household WHERE household_id="'.(int)$loginStatus->household_id.'"');}
2733 $wpdb->query('DELETE FROM '.$wpdb->prefix.'church_admin_app WHERE people_id="'.(int)$loginStatus->people_id.'"');
2734 $wpdb->query('DELETE FROM '.$wpdb->prefix.'church_admin_people_meta WHERE people_id="'.(int)$loginStatus->people_id.'"');
2735 $wpdb->query('DELETE FROM '.$wpdb->prefix.'church_admin_people WHERE people_id="'.(int)$loginStatus->people_id.'"');
2736 require_once(ABSPATH.'wp-admin/includes/user.php');
2737 if(!user_can($loginStatus->user_id,'manage_options') ){
2738
2739 if(empty(count_user_posts($loginStatus->user_id))){
2740 //only delete account if no posts
2741 echo '<h2>'.__('Success','church-admin').'</h2><p>'.__('You have been deleted from the directory and your user account has been deleted. Sorry to see you go.','church-admin').'</p>';
2742 wp_delete_user($loginStatus->user_id,null);
2743
2744 }
2745 else
2746 {
2747 echo '<h2>'.__('Success','church-admin').'</h2><p>'.__('You have been deleted from the directory BUT your user account has not been deleted because you have publisehed posts on the site. A site admin will remove you.','church-admin').'</p>';
2748
2749 }
2750 }
2751 else{
2752
2753 echo '<h2>'.__('Success','church-admin').'</h2><p>'.__('You have been deleted from the directory BUT your user account has not been deleted because you are a site admin.','church-admin').'</p>';
2754
2755 }
2756
2757
2758 exit();
2759
2760 }else
2761 {
2762
2763 echo '<p>'.__('User not found, so nothing deleted.','church-admin').'</p>';
2764 }
2765
2766
2767 }
2768 echo'<div><p><a href="'.site_url().'">'.esc_html( __('Back to main site','church-admin')).'</a></p></div></article></body></html>';
2769 exit();
2770
2771 }
2772
2773
2774
2775
2776 if(!empty( $_REQUEST['ca_download'] ) )
2777 {
2778 header("X-Robots-Tag: noindex, nofollow", true);
2779 $member_type_id=NULL;
2780 if ( empty( $_REQUEST['addressType'] ) ) {$addressType='street';}
2781 else
2782 {
2783 switch( $_REQUEST['addressType'] )
2784 {
2785 default:
2786 case 'street':
2787 $addressType='street';
2788 break;
2789 case 'mailing':
2790 $addressType='mailing';
2791 break;
2792
2793 }
2794 }
2795 $loggedin=!empty( $_REQUEST['loggedin'] )?1:0;
2796
2797
2798 $member_type_id = !empty($_REQUEST['member_type_id']) ?church_admin_sanitize($_REQUEST['member_type_id']) : null;
2799 $people_type_id = !empty($_REQUEST['people_type_id']) ?church_admin_sanitize($_REQUEST['people_type_id']) : null;
2800 if(!empty( $_REQUEST['date'] ) ) {
2801 $date=sanitize_text_field(stripslashes($_REQUEST['date']));
2802 if(!church_admin_checkdate($date)){
2803 $date=date('Y-m-d');
2804 }
2805 }else{$date=date('Y-m-d');}
2806 if(!empty( $_REQUEST['pdf_font_resize'] ) ) {
2807 $resize=sanitize_text_field(stripslashes($_REQUEST['pdf_font_resize']));
2808 }else{$resize=FALSE;}
2809 if(!empty( $_REQUEST['pdfversion'] ) ) {
2810 $pdfversion=sanitize_text_field(stripslashes($_REQUEST['pdfversion']));
2811 }else{$pdfversion=1;}
2812 if(!empty( $_REQUEST['service_id'] ) ) {
2813 $service_id=sanitize_text_field(stripslashes($_REQUEST['service_id']));
2814 //validate
2815 if(!church_admin_int_check($service_id)){$service_id=1;}
2816 }else
2817 {
2818 $service_id=1;
2819 }
2820 $facilities_id = !empty($_REQUEST['facilities_id'])? church_admin_sanitize($_REQUEST['facilities_id']) : null;
2821 $cat_id = !empty($_REQUEST['cat_id'])? church_admin_sanitize($_REQUEST['cat_id']) : null;
2822
2823
2824 $kids=!empty($_REQUEST['kids'])?1:0;
2825 $id = !empty($_REQUEST['id'])?church_admin_sanitize($_REQUEST['id']):0;
2826
2827 if(!empty( $_REQUEST['start_date'] ) ) {
2828 $start_date=sanitize_text_field(stripslashes($_REQUEST['start_date']));
2829 //validate
2830 if(!church_admin_checkdate($start_date)){
2831 $start_date = date('Y-m-d');
2832 }
2833 }else{$start_date=date('Y-m-d');}
2834 if(!empty( $_REQUEST['end_date'] ) ) {
2835 $end_date= sanitize_text_field(stripslashes( $_REQUEST['end_date'] ) ) ;
2836 //validate
2837 if(!church_admin_checkdate($end_date)){
2838 $end_date=date('Y-m-d',strtotime("+3 years") );
2839 }
2840 }else{$end_date=date('Y-m-d',strtotime("+3 years") );}
2841 $showDOB = !empty( $_REQUEST['showDOB'] ) ?1:0;
2842
2843 if(!empty( $_REQUEST['service_id'] ) ) {
2844 $service_id= sanitize_text_field(stripslashes($_REQUEST['service_id']));
2845 //validate
2846 if(!church_admin_int_check($service_id)){$service_id=FALSE;}
2847 }else{$service_id=FALSE;}
2848 if(!empty( $_REQUEST['people_id'] ) ) {
2849 $people_id= sanitize_text_field(stripslashes($_REQUEST['people_id']));
2850 //validate
2851 if(!church_admin_int_check($people_id)){
2852 $people_id = FALSE;
2853 }
2854
2855 }else{$people_id=FALSE;}
2856 if(!empty( $_REQUEST['file_id'] ) ) {
2857 $file_id= sanitize_text_field( stripslashes( $_REQUEST['file_id'] ) );
2858 //validate
2859 if(!church_admin_int_check($file_id)){
2860 $file_id= FALSE;
2861 }
2862 }else{$file_id=FALSE;}
2863 if(!empty( $_REQUEST['event_id'] ) ) {
2864 $event_id=$_REQUEST['event_id'];
2865 //validate
2866 if(!church_admin_int_check($event_id)){
2867 $event_id= FALSE;
2868 }
2869 }else{$event_id=FALSE;}
2870 if(!empty( $_REQUEST['unit_id'] ) ) {
2871 $unit_id=$_REQUEST['unit_id'];
2872 //validate
2873 if(!church_admin_int_check($unit_id)){
2874 $unit_id= FALSE;
2875 }
2876 }else{$unit_id=FALSE;}
2877 $booking_ref = !empty($_REQUEST['booking_ref'])?sanitize_text_field(stripslashes($_REQUEST['booking_ref'])):NULL;
2878 if(!empty( $_REQUEST['date_id'] ) ) {
2879 $date_id= sanitize_text_field( stripslashes( $_REQUEST['date_id'] ) ) ;
2880 }else{$date_id=FALSE;}
2881 if(!empty( $_REQUEST['fund'] ) ) {
2882 $fund=urldecode( sanitize_text_field(stripslashes($_REQUEST['fund'] ) ) );
2883 }else{$fund='All';}
2884 if(!empty( $_REQUEST['title'] ) ) {
2885 $title = sanitize_text_field(stripslashes($_REQUEST['title'] ) ) ;
2886 }else{$title=NULL;}
2887 if(!empty( $_REQUEST['initials'] ) ) {$initials=1;}else{$initials=0;}
2888
2889 switch( $_REQUEST['ca_download'] )
2890 {
2891 case 'monthly-calendar-pdf':
2892 require_once(plugin_dir_path(__FILE__ ).'includes/pdf_creator.php');
2893 church_admin_monthly_calendar_pdf($start_date, $facilities_id,$cat_id );
2894 break;
2895 case 'weekly-calendar-pdf':
2896 require_once(plugin_dir_path(__FILE__ ).'includes/pdf_creator.php');
2897 church_admin_weekly_calendar_pdf($facilities_id,$cat_id,$start_date);
2898 break;
2899 case 'visitation-pdf':
2900 if(church_admin_level_check('Directory') )
2901 {
2902 require_once(plugin_dir_path(__FILE__ ).'includes/visitation.php');
2903 church_admin_visitation_pdf($people_id,FALSE);
2904 }else{
2905 echo'<div class="error"><p>'.esc_html( __("You don't have permissions",'church-admin' ) ).'</p></div>';
2906 }
2907 break;
2908 case 'photo-permissions-pdf':
2909 //church_admin_debug('photo-permissions-pdf');
2910 if(church_admin_level_check('Directory') )
2911 {
2912 require_once(plugin_dir_path(__FILE__ ).'includes/pdf_creator.php');
2913 $peopleIDs= !empty($_GET['people_type_id'])?church_admin_sanitize($_GET['people_type_id']):null;
2914 //church_admin_debug($peopleIDs);
2915 church_admin_photo_permissions_pdf( $peopleIDs);
2916 }else{
2917 echo'<div class="error"><p>'.esc_html( __("You don't have permissions",'church-admin' ) ).'</p></div>';
2918 }
2919 break;
2920 case 'smallgroup-signup':
2921 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
2922 church_admin_smallgroup_signup_pdf( $title);
2923 break;
2924 case 'sermon-notes':
2925 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
2926 church_admin_sermon_notes_pdf( $file_id);
2927 break;
2928 case 'giving-csv':
2929 require_once( plugin_dir_path( __FILE__ ).'includes/csv.php');
2930 church_admin_giving_csv( $start_date,$end_date,$people_id);
2931
2932 break;
2933 case 'gift-aid-csv':
2934 require_once( plugin_dir_path( __FILE__ ).'includes/csv.php');
2935 church_admin_gift_aid_csv( $start_date,$end_date,$fund);
2936
2937 break;
2938 case 'service_booking_bubble_pdf':
2939 if(church_admin_level_check('Directory') )
2940 {
2941 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
2942 church_admin_service_bubble_pdf( $date_id,$service_id,FALSE);
2943 }
2944 break;
2945 case 'service_booking_pdf':
2946
2947 if(church_admin_level_check('Directory') )
2948 {
2949 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
2950 church_admin_service_booking_pdf( $date_id,$service_id,FALSE);
2951 }
2952 break;
2953 case 'service_booking_csv':
2954
2955 if(church_admin_level_check('Directory') )
2956 {
2957 require_once( plugin_dir_path( __FILE__ ).'includes/csv.php');
2958 church_admin_service_booking_csv( $date_id,$service_id,FALSE);
2959 }
2960 break;
2961 case 'service_booking_alphabetical_pdf':
2962
2963 if(church_admin_level_check('Directory') )
2964 {
2965 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
2966 church_admin_service_booking_pdf( $date_id,$service_id,TRUE);
2967 }
2968 break;
2969 case 'unit-pdf':
2970 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
2971 church_admin_unit_pdf( $unit_id);
2972 break;
2973 case 'ical':
2974 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
2975 church_admin_ical( $date_id);
2976 exit();
2977 break;
2978
2979 case 'bookings_csv':
2980 if(wp_verify_nonce( $_REQUEST['_wpnonce'],'bookings_csv') )
2981 {
2982 require_once( plugin_dir_path( __FILE__ ).'includes/events.php');
2983 church_admin_bookings_csv( $event_id );
2984 }
2985 break;
2986 case 'bookings_pdf':
2987 if(wp_verify_nonce( $_REQUEST['_wpnonce'],'bookings_pdf') )
2988 {
2989 require_once( plugin_dir_path( __FILE__ ).'includes/events.php');
2990 church_admin_bookings_pdf( $event_id );
2991 }
2992 break;
2993 case 'tickets':
2994
2995 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
2996 if ( empty( $_REQUEST['booking_ref'] ) ) return __('Oops no booking reference','church-admin');
2997 church_admin_tickets_pdf( $booking_ref );
2998 break;
2999 case 'pdf-filter':
3000 if(church_admin_level_check('Directory') )
3001 {
3002 //church_admin_debug("PDF filter");
3003 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3004 church_admin_filter_pdf();
3005 }else{
3006 echo esc_html( __("You don't have permissions to do that",'church-admin') );
3007 }
3008 break;
3009 case'kidswork-checkin':
3010 if(church_admin_level_check('Kidswork') )
3011 {
3012 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3013 church_admin_kidswork_checkin_pdf( $id,$service_id,$date);
3014 }else{
3015 echo esc_html( __("You don't have permissions to do that",'church-admin') );
3016 }
3017 break;
3018 case'gdpr-pdf':
3019 if(church_admin_level_check('Directory') ){
3020 require_once( plugin_dir_path( __FILE__ ).'includes/directory.php');church_admin_gdpr_pdf();
3021 }
3022 break;
3023 case'address-list':
3024 case'addresslist':
3025
3026 church_admin_debug('Doing address list PDF ');
3027 church_admin_debug($_REQUEST);
3028 $pdf_version =!empty($_REQUEST['pdf_version'])? (int)church_admin_sanitize($_REQUEST['pdf_version']):2;
3029 $showDOB = FALSE;
3030 $title =!empty($_REQUEST['title'])? (int)church_admin_sanitize($_REQUEST['title']) : __('Address List','church-admin');
3031 $loggedin=TRUE;
3032
3033
3034 if(wp_verify_nonce( $_GET['_wpnonce'],'address-list') )
3035 {
3036 if ( !empty( $_REQUEST['address_style'] ) ){
3037 switch( $_REQUEST['address_style'] )
3038 {
3039 default:
3040 case 'multi':
3041 $address_style="multi";
3042 break;
3043 case'single':
3044 $address_style='single';
3045 break;
3046 }
3047 }
3048
3049 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3050
3051 switch( $pdf_version)
3052 {
3053 case 1:default:
3054 church_admin_address_pdf_v1( $member_type_id,$loggedin,$showDOB,$title ,$address_style,1);
3055 break;
3056 case 2:
3057 //church_admin_debug('about to do pdf directory');
3058 church_admin_address_pdf_v2( $member_type_id,$loggedin);
3059 break;
3060 case 3:
3061 church_admin_address_pdf_v1( $member_type_id,$loggedin,$showDOB,$title ,$address_style,0);
3062 break;
3063 }
3064
3065 }
3066 break;
3067 case'addresslist-family-photos':
3068 church_admin_debug('Doing family photos PDF ');
3069 if(!empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'],'address-list') )
3070 {
3071 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3072 $member_type_id=!empty( $_REQUEST['member_type_id'] )?$_REQUEST['member_type_id']:0;
3073 $title = !empty( $_REQUEST['title'] )?$_REQUEST['title']:__('Address List','church-admin');
3074 church_admin_debug($title);
3075 church_admin_address_pdf_v1( $member_type_id,$loggedin,FALSE,$title);
3076 }else{
3077 echo'<p>'.esc_html(__('You can only download if coming from a valid link',' church-admin') ).'</p>';
3078 }
3079 break;
3080 case'kidswork_pdf':
3081 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3082 church_admin_kidswork_pdf( $member_type_id,$loggedin);
3083 break;
3084
3085 case'ministries_pdf':
3086 if(wp_verify_nonce( $_REQUEST['_wpnonce'],'ministries_pdf') ) {
3087 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3088 church_admin_ministry_pdf();
3089 }else{
3090 echo'<p>'.esc_html(__('You can only download if coming from a valid link',' church-admin') ).'</p>';
3091 }
3092 break;
3093 case 'csv-filter':
3094 if(church_admin_level_check('Directory') )
3095 {
3096 require_once( plugin_dir_path( __FILE__ ).'includes/csv.php');
3097 church_admin_people_csv();
3098 }
3099 else{
3100 echo esc_html( __("You don't have permissions to do that", 'church-admin' ) );
3101 }
3102 break;
3103
3104 case 'people-csv':
3105 if(wp_verify_nonce( $_REQUEST['people-csv'],'people-csv') )
3106 {
3107 require_once( plugin_dir_path( __FILE__ ).'includes/csv.php');
3108 church_admin_people_csv();
3109 }
3110 else
3111 {
3112 echo'<p>'.esc_html(__('You can only download if coming from a valid link',' church-admin') ).'</p>';
3113 }
3114 break;
3115 case 'small-group-xml':
3116 if(wp_verify_nonce( $_REQUEST['small-group-xml'],'small-group-xml') )
3117 {
3118
3119 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3120 church_admin_small_group_xml();
3121 }else{
3122 echo'<p>'.esc_html(__('You can only download if coming from a valid link',' church-admin') ).'</p>';
3123 }
3124 break;
3125 case 'address-xml':
3126 $member_type_id=!empty( $_REQUEST['member_type_id'] )?$_REQUEST['member_type_id']:'#';
3127 $small_group=!empty( $_REQUEST['small_group'] )?1:0;
3128 require_once( plugin_dir_path(__FILE__).'includes/pdf_creator.php' );
3129
3130 church_admin_address_xml( $member_type_id,$small_group);
3131 exit();
3132 break;
3133 case'cron-instructions':
3134 if ( wp_verify_nonce( $_GET['cron-instructions'], 'cron-instructions') ) {
3135 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3136 church_admin_cron_pdf();
3137 }
3138 else {
3139 echo'<p>'.esc_html(__('You can only download if coming from a valid link',' church-admin') ).'</p>';
3140 exit();
3141 }
3142 break;
3143
3144 case'yearplanner':
3145 if ( wp_verify_nonce( $_REQUEST['yearplanner'], 'yearplanner' ) ) {
3146 require_once ( plugin_dir_path(__FILE__).'includes/pdf_creator.php' );
3147 church_admin_year_planner_pdf( sanitize_text_field(stripslashes($_REQUEST['year'] )));
3148 } else {
3149 echo'<p>'.esc_html(__('You can only download if coming from a valid link',' church-admin') ).'</p>';
3150 exit();
3151 }
3152 break;
3153 case'smallgroup':
3154 if(wp_verify_nonce( $_REQUEST['_wpnonce'], 'smallgroup') )
3155 {
3156 require_once( plugin_dir_path(__FILE__).'includes/pdf_creator.php' );
3157 church_admin_smallgroup_pdf( $member_type_id, $people_type_id, $loggedin, urldecode( $title) );
3158 }
3159 else{
3160 echo'<p>'.esc_html(__('You can only download if coming from a valid link',' church-admin') ).'</p>';
3161 }
3162 exit();
3163 break;
3164 case 'smallgroups':
3165 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3166 church_admin_smallgroups_pdf( $loggedin , urldecode( $title) );
3167 exit();
3168 break;
3169 case 'vcf-person':
3170 $okay=FALSE;
3171 if(!empty( $_GET['token'] ) )
3172 {
3173 //church_admin_debug("Coming from app");
3174 //coming from app so no nonce, but login can be checked
3175 $sql='SELECT user_id FROM '.$wpdb->prefix.'church_admin_app WHERE UUID="'.esc_sql(sanitize_text_field( stripslashes($_GET['token']) ) ).'"';
3176 //church_admin_debug($sql);
3177 $result=$wpdb->get_var( $sql);
3178 //church_admin_debug("Result: ".$result);
3179 if( !empty( $result) ) {
3180
3181 $okay = TRUE;
3182 }
3183 }
3184 //only allow login if from logged in app user or correct nonce
3185 if( !empty($okay) || wp_verify_nonce( $_REQUEST['_wpnonce'],$_GET['id'] ) )
3186 {
3187 //church_admin_debug('passed checks');
3188
3189 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3190 $people_id=!empty($_GET['id'])?(int)$_GET['id']:null;
3191 if(empty($people_id)){
3192 //app sends $_GET['people_id']
3193 $people_id=!empty($_GET['people_id'])?(int)$_GET['people_id']:null;
3194 }
3195 ca_person_vcard( $people_id );
3196 } else {
3197 echo'<p>'.esc_html( __('You can only download if coming from a valid link','church-admin' ) ).'</p>';
3198 }
3199 exit();
3200 break;
3201 case 'vcf':
3202 $okay=FALSE;
3203 if(!empty( $_GET['token'] ) )
3204 {
3205 $sql='SELECT user_id FROM '.$wpdb->prefix.'church_admin_app WHERE UUID="'.esc_sql(sanitize_text_field( $_GET['token'] ) ).'"';
3206 $result=$wpdb->get_var( $sql);
3207 if(!empty( $result) )$okay=TRUE;
3208 }
3209 if( $okay||wp_verify_nonce( $_REQUEST['_wpnonce'],$_REQUEST['id'] ) )
3210 {
3211 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3212 ca_vcard( $id );
3213 }else{
3214 echo'<p>'.esc_html(__('You can only download if coming from a valid link',' church-admin') ).'</p>';
3215 }
3216 exit();
3217 break;
3218 case'mailinglabel':
3219 if(church_admin_level_check('Directory') )
3220 {
3221 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3222 church_admin_label_pdf( $member_type_id,$loggedin,$addressType);
3223
3224 }
3225 exit();
3226
3227 break;
3228 case'householdlabel':
3229 if(church_admin_level_check('Directory') )
3230 {
3231 require_once( plugin_dir_path( __FILE__ ).'includes/pdf_creator.php');
3232 church_admin_household_label_pdf( $member_type_id,$loggedin,$addressType);
3233 }
3234 exit();
3235 break;
3236
3237 }
3238 exit();
3239 }
3240
3241 }
3242 function church_admin_delete_backup()
3243 {
3244 $upload_dir = wp_upload_dir();
3245 $path=$upload_dir['basedir'].'/church-admin-cache/*';
3246 $files = glob( $path); // get all file names
3247 foreach( $files as $file)
3248 { // iterate files
3249 if(is_file( $file) )unlink( $file); // delete file
3250 }
3251 $text="<?php exit('----------------------------------------
3252 ___ _ _ _ _ _ _ _
3253 |_ _| |_( )___ __ _| | | __ _| |__ ___ _ _| |_ | | ___ ___ _ _ ___
3254 | || __|// __| / _` | | | / _` | '_ \ / _ \| | | | __| _ | |/ _ \/ __| | | / __|
3255 | || |_ \__ \ | (_| | | | | (_| | |_) | (_) | |_| | |_ | |_| | __/\__ \ |_| \__ \
3256 |___|\__| |___/ \__,_|_|_| \__,_|_.__/ \___/ \__,_|\__| \___/ \___||___/\__,_|___/
3257 '); \r\n // Nothing is good! ";
3258 $church_admin_fp = fopen( $upload_dir['basedir'].'/church-admin-cache/debug_log.php', 'w');
3259 if($church_admin_fp){
3260 fwrite( $church_admin_fp, $text."\r\n");
3261 fclose($church_admin_fp);
3262 }
3263 $church_admin_fp = fopen( $upload_dir['basedir'].'/church-admin-cache/index.php', 'w');
3264 if($church_admin_fp){
3265 fwrite( $church_admin_fp, $text."\r\n");
3266 fclose($church_admin_fp);
3267 }
3268
3269 }
3270
3271
3272
3273
3274
3275 function church_admin_activation_log_clear()
3276 {
3277 delete_option('church_admin_plugin_error');
3278
3279 echo'<div class="notice notice-success"><h2>'. esc_html( __( 'Installation errors cleared', 'church-admin' ) ).'</h2></div>';
3280 }
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290 function church_admin_from_name( $from ) {
3291 if(!empty( $_POST['from_name'] ) ) {
3292 return esc_html(sanitize_text_field( stripslashes($_POST['from_name'] ) ) );
3293 }
3294 else {
3295 return get_option('blogname');
3296 }
3297 }
3298 function church_admin_from_email( $email ) {
3299 if(!empty( $_POST['from_email'] ) ) {
3300 return esc_html(sanitize_text_field( stripslashes( $_POST['from_email'] ) ) );
3301 }else {
3302 return get_option('church_admin_default_from_email');
3303 }
3304
3305 }
3306 function church_admin_debug($message)
3307 {
3308 $debug=get_option('church_admin_debug_mode');
3309 if(!defined('CA_DEBUG') && empty($debug) )return;
3310 if(is_array( $message)||is_object( $message) )$message=print_r( $message,TRUE);
3311 $text="<?php exit('Nothing is good!') ;?>";
3312 $upload_dir = wp_upload_dir();
3313 $debug_path=$upload_dir['basedir'].'/church-admin-cache/';
3314 if(file_exists( $debug_path.'debug.log') )unlink( $debug_path.'debug.log');
3315 if(!file_exists( $debug_path.'debug_log.php') )
3316 {
3317
3318 $church_admin_fp = fopen( $debug_path.'debug_log.php', 'w');
3319 if($church_admin_fp){
3320 fwrite( $church_admin_fp, $text."\r\n");
3321
3322 }
3323 }
3324 if ( empty( $church_admin_fp) )$church_admin_fp = fopen( $debug_path.'debug_log.php', 'a');
3325 if(!empty($church_admin_fp)){
3326 fwrite( $church_admin_fp, $message."\r\n");
3327 fclose( $church_admin_fp);
3328 }
3329 if(!file_exists( $debug_path.'index.php') )
3330 {
3331 $church_admin_fp = fopen( $debug_path.'index.php', 'w');
3332 if(!empty($church_admin_fp)){
3333 fwrite( $church_admin_fp, $text."\r\n");
3334 fclose( $church_admin_fp);
3335 }
3336 }
3337 }
3338
3339 register_deactivation_hook(__FILE__, 'church_admin_deactivation');
3340
3341 function church_admin_deactivation() {
3342
3343 $args = get_option('church_admin_happy_birthday_arguments');
3344 wp_clear_scheduled_hook( 'church_admin_happy_birthday_email',$args );
3345
3346
3347
3348 $cron=get_option('cron');
3349 foreach($cron AS $id=>$cronArray)
3350 {
3351 if(!empty($cron[$id]['church_admin_bulk_email'])){
3352 unset($cron[$id]['church_admin_bulk_email']);
3353 }
3354
3355 }
3356
3357 update_option('cron',$cron);
3358 }
3359
3360 /**************************************
3361 * CHURCH ADMIN BULK EMAIL
3362 **************************************/
3363
3364 add_action('church_admin_bulk_email','church_admin_bulk_email');
3365 function church_admin_bulk_email()
3366 {
3367 church_admin_debug('****** BULK EMAIL CRON ********');
3368 global $wpdb;
3369
3370 $max_email=get_option('church_admin_bulk_email');
3371
3372 if ( empty( $max_email) )$max_email=100;
3373 $sql='SELECT * FROM '.$wpdb->prefix.'church_admin_email WHERE schedule <=NOW() OR schedule is NULL LIMIT 0,'.$max_email;
3374 //church_admin_debug $sql);
3375 $result=$wpdb->get_results( $sql);
3376
3377 if(!empty( $result) )
3378 {
3379 foreach( $result AS $row)
3380 {
3381 if(!is_email($row->recipient)){
3382 //delete from queue and skip
3383 $wpdb->query('DELETE FROM '.$wpdb->prefix.'church_admin_email WHERE email_id="'.(int)$row->email_id.'"');
3384 continue;
3385 }
3386 $from_name = !empty($row->from_name) ? $row->from_name : get_option('church_admin_default_from_name');
3387 $from_email = !empty($row->from_email) ? $row->from_email : get_option('church_admin_default_from_email');
3388 $reply_email = !empty($row->reply_email) ? $row->reply_email : get_option('church_admin_default_from_email');
3389 $reply_name = !empty($row->reply_name) ? $row->reply_name : get_option('church_admin_default_from_name');
3390
3391 church_admin_email_send($row->recipient,$row->subject,$row->message,$from_name,$from_email,unserialize( $row->attachment),$reply_name,$reply_email,TRUE);
3392 $wpdb->query('DELETE FROM '.$wpdb->prefix.'church_admin_email WHERE email_id="'.(int) $row->email_id.'"');
3393
3394 }
3395 }
3396 echo 'Done';
3397 exit;
3398 }
3399
3400 //add donate link on config page
3401 add_filter( 'plugin_row_meta', 'church_admin_plugin_meta_links', 10, 2 );
3402 function church_admin_plugin_meta_links( $links, $file ) {
3403 $plugin = plugin_basename(__FILE__);
3404 // create link
3405 if ( $file == $plugin ) {
3406 return array_merge(
3407 $links,
3408 array( '<a href="http://www.churchadminplugin.com/support">Support</a>','<a href="https://pay.sumup.io/b2c/QEEPP89C">Donate</a>' )
3409 );
3410 }
3411 return $links;
3412 }
3413
3414
3415 add_action( 'wp_trash_post', 'church_admin_delete_from_app_menu');
3416
3417 function church_admin_delete_from_app_menu($postID)
3418 {
3419 global $wpdb;
3420 $post=$wpdb->get_row('SELECT * FROM '.$wpdb->posts.' WHERE ID="'.(int)$postID.'"');
3421 church_admin_debug('******* POST delete'.$postID.' *******');
3422 if(!empty($post->post_type) && $post->post_type == 'app-content'){
3423 church_admin_debug('App menu upated on deleting '.$postID);
3424 require_once(plugin_dir_path( __FILE__) .'/app/app-setup.php');
3425 ca_update_app_menu('remove',$post->post_title);
3426 }
3427
3428 }
3429
3430
3431 add_action( 'transition_post_status', 'church_admin_post_message', 10, 3 );
3432
3433 function church_admin_post_message( $new_status, $old_status, $post )
3434 {
3435 //update app cache time
3436
3437 //if(!defined('CA_DEBUG') )define('CA_DEBUG',TRUE);
3438 //church_admin_debug("**********************************\r\nPublish firing\r\n".date('Y-m-d H:i:s') );
3439 //church_admin_debug("Post title {$post->post_title}");
3440 //church_admin_debug("Post type {$post->post_type}");
3441 //church_admin_debug("New Status {$new_status}");
3442 //church_admin_debug("Old Status {$old_status}");
3443 //app content modified check
3444 $continue=FALSE;
3445 switch($post->post_type){
3446
3447 case 'post':
3448 case 'bible-readings':
3449 case 'prayer-requests':
3450 case 'app-content':
3451 $continue = TRUE;
3452 break;
3453 }
3454 if( $new_status!='publish')
3455 {
3456 $continue = FALSE;
3457 }
3458 if(empty($continue)) {return;}
3459
3460
3461
3462 if( $post->post_type=='app-content' && ( $new_status=='update'||$new_status=='publish') )
3463 {
3464 church_admin_debug('App menu updated on publishing '.$post->post_title);
3465 require_once(plugin_dir_path( __FILE__) .'/app/app-setup.php');
3466 ca_update_app_menu('add',$post->post_title);
3467 }
3468
3469 global $wpdb,$videoURL;
3470 //$debug=FALSE;//stop push notifications while testing
3471 $user=wp_get_current_user();
3472 $sender=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE user_id="'.(int)$user->ID.'"');
3473 if(!empty( $sender) )$username=implode(" ",array_filter(array( $sender->first_name,$sender->prefix,$sender->last_name) ));
3474
3475 $no_push=get_option('church_admin_no_push');
3476 if( $no_push)
3477 {
3478 //church_admin_debug("No push");
3479 return;
3480 }
3481
3482
3483 $title='';
3484 $type=get_post_type( $post );
3485 $sent=get_post_meta( $post->ID,'Email Sent',TRUE);
3486 $pushOK=TRUE;
3487 if(!empty( $_POST['church_admin_no_push'] ) )return;
3488 if( $new_status == 'publish' && $old_status != 'publish' && !empty( $type) && ( $type=='prayer-requests'||$type=='post'||$type=='bible-readings') && $pushOK)
3489 {
3490 //church_admin_debug("Post status changed to PUBLISH");
3491
3492
3493 switch( $type)
3494 {
3495 case 'acts-of-courage':
3496 $title=__('New Act of Courage','church-admin');
3497 $contactType='acts-of-courage';
3498 $ministry=__('Prayer requests send','church-admin');
3499 break;
3500 case 'prayer-requests':
3501 $title=__('New Prayer Request','church-admin');
3502 $contactType='prayer';
3503 $ministry=__('Prayer requests send','church-admin');
3504 break;
3505 case 'bible-readings':
3506 $title=__('New Bible Reading','church-admin');
3507 $contactType='bible';
3508 $ministry=__('Bible readings send','church-admin');
3509 break;
3510 case 'post':
3511 $title=__('New Blog Post','church-admin');
3512 $contactType='posts';
3513 $ministry=__('News send','church-admin');
3514 break;
3515
3516 }
3517 if( $type=='post')$type='posts';
3518 //church_admin_debug("ContactType = $contactType Ministry = $ministry");
3519 /****************************************
3520 *
3521 * Push Notification
3522 *
3523 ****************************************/
3524 if( $_SERVER['SERVER_NAME']!="localhost")
3525 {
3526
3527
3528 $private=get_option('church-admin-private-prayer-requests');
3529 if( $type=='bible-readings')
3530 {
3531 //only send bible readings to logged in app users who accept bible readings
3532 $myTokens=$wpdb->get_results('SELECT a.*,a.pushToken,b.meta_date FROM '.$wpdb->prefix.'church_admin_people a, '.$wpdb->prefix.'church_admin_people_meta b WHERE a.active=1 AND a.pushToken!="" AND a.people_id=b.people_id AND b.meta_type="bible-readings-notifications"');
3533 //church_admin_debug $wpdb->last_query);
3534 $pushTokens=array();
3535 if(!empty( $myTokens) )
3536 {
3537 foreach( $myTokens AS $myToken)
3538 {
3539 if(!in_array( $myToken->pushToken,$pushTokens) ) {
3540 $pushTokens[]=$myToken->pushToken;
3541 }
3542 //church_admin_debug("Push token for ".church_admin_formatted_name( $myTokens).' is '.$myToken->pushToken);
3543 }
3544 }
3545
3546 }elseif( $private && $type=='prayer-requests')
3547 {
3548 //only send prayer requestes to logged in app users who accept prayer requests
3549 $myTokens=$wpdb->get_results('SELECT a.pushToken,b.meta_date FROM '.$wpdb->prefix.'church_admin_people a, '.$wpdb->prefix.'church_admin_people_meta b WHERE a.active=1 AND a.pushToken!="" AND a.people_id=b.people_id AND b.meta_type="prayer-requests-notifications"');
3550 //church_admin_debug $wpdb->last_query);
3551 $pushTokens=array();
3552 if(!empty( $myTokens) )
3553 {
3554 foreach( $myTokens AS $myToken)if(!in_array( $myToken->pushToken,$pushTokens) ) {$pushTokens[]=$myToken->pushToken;}
3555 }
3556
3557 }elseif( $type=='post')
3558 {
3559 $myTokens=$wpdb->get_results('SELECT pushToken FROM '.$wpdb->prefix.'church_admin_people WHERE active=1 AND pushToken!="" AND news_send=1');
3560 //church_admin_debug $wpdb->last_query);
3561 $pushTokens=array();
3562 if(!empty( $myTokens) )
3563 {
3564 foreach( $myTokens AS $myToken)if(!in_array( $myToken->pushToken,$pushTokens) ) {$pushTokens[]=$myToken->pushToken;}
3565 }
3566
3567 }else
3568 {
3569 //send to all app subscribers
3570 //$data["to"]="/topics/church".$appID;
3571 $myTokens=$wpdb->get_results('SELECT a.pushToken,b.meta_date FROM '.$wpdb->prefix.'church_admin_people a, '.$wpdb->prefix.'church_admin_people_meta b WHERE a.active=1 AND a.pushToken!="" AND a.people_id=b.people_id AND b.meta_type="news-notifications"');
3572 //church_admin_debug $wpdb->last_query);
3573 $pushTokens=array();
3574 if(!empty( $myTokens) )
3575 {
3576 foreach( $myTokens AS $myToken)if(!in_array( $myToken->pushToken,$pushTokens) ) {$pushTokens[]=$myToken->pushToken;}
3577 }
3578
3579 }
3580 church_admin_send_push('tokens',$type,$pushTokens,'Our Church App',$title,get_option('blogname'));
3581
3582 }//only send push if not localhost
3583
3584 /***************************************
3585 *
3586 * Email send
3587 *
3588 ****************************************/
3589 if ( empty( $sent) )
3590 {
3591
3592 church_admin_debug("Preparing to send ".$contactType);
3593
3594 $post_title = get_the_title( $post->ID );
3595 $post_url = get_permalink( $post->ID );
3596
3597 $email_title=$title.' - '.$post->post_title;
3598 $content_post = get_post( $post->ID);
3599 //church_admin_debug("Post contents************\r\n".print_r( $post,TRUE) );
3600 $content=church_admin_prepare_post_for_email( $post->post_content,$type,NULL);
3601
3602 //church_admin_debug("***** CONTENT *****");
3603 //church_admin_debug $content);
3604 //church_admin_debug("***** END CONTENT *****");
3605
3606
3607
3608
3609 $sql='SELECT DISTINCT a.first_name,a.last_name,a.people_id,a.email FROM '.$wpdb->prefix.'church_admin_people a, '.$wpdb->prefix.'church_admin_people_meta b WHERE a.people_id=b.people_id AND b.meta_type="'.esc_sql( $type).'" AND a.email!="" AND email_send!=0 AND gdpr_reason!=""';
3610 //church_admin_debug $sql);
3611 $results=$wpdb->get_results( $sql);
3612 if(empty($results)){return;}
3613
3614 $mailersend_api = get_option('church_admin_mailersend_api_key');
3615 if(!empty($mailersend_api)){
3616
3617 //use mailersend bulk method.
3618 $recipients = array();
3619 foreach( $results AS $row)
3620 {
3621 $recipients[]=array('name'=>church_admin_formatted_name($row),'first_name'=>$row->first_name,'email'=>$row->email,'people_id'=>$row->people_id);
3622 }
3623 church_admin_mailersend_bulk($recipients,$title,'<h2>'.$email_title.'</h2>'.$content,$user->email,$user->name,$user->email,$user->name,null,FALSE);
3624 }
3625 else
3626 {
3627 foreach( $results AS $row)
3628 {
3629 church_admin_email_send($row->email,$title,'<h2>'.$email_title.'</h2>'.$content,$user->name,$user->email,null,null,null);
3630
3631 }
3632
3633 }
3634
3635
3636
3637 //set sent field in post meta
3638 update_post_meta( $post->ID, 'Email Sent', 1);
3639 }
3640 } //just published
3641 //church_admin_debug("************ End of church admin publish post function **************");
3642 }
3643
3644 function ca_prayer_create_posttype() {
3645 $labels = array(
3646 'name' => _x( 'Prayer Requests', 'Post Type General Name', 'church-admin' ),
3647 'singular_name' => _x( 'Prayer Request', 'Post Type Singular Name', 'church-admin' ),
3648 'menu_name' => __( 'Prayer Requests', 'church-admin' ),
3649 'parent_item_colon' => __( 'Parent Prayer Request', 'church-admin' ),
3650 'all_items' => __( 'All Prayer Requests', 'church-admin' ),
3651 'view_item' => __( 'View Prayer Request', 'church-admin' ),
3652 'add_new_item' => __( 'Add New Prayer Request', 'church-admin' ),
3653 'add_new' => __( 'Add New', 'church-admin' ),
3654 'edit_item' => __( 'Edit Prayer Request', 'church-admin' ),
3655 'update_item' => __( 'Update Prayer Request', 'church-admin' ),
3656 'search_items' => __( 'Search Prayer Requests', 'church-admin' ),
3657 'not_found' => __( 'Not Found', 'church-admin' ),
3658 'not_found_in_trash' => __( 'Not found in Trash', 'church-admin' ),
3659 );
3660 $noPrayer=get_option('church-admin-no-prayer');
3661 if ( empty( $noPrayer) )
3662 {
3663 register_post_type( 'prayer-requests',
3664 // CPT Options
3665 array(
3666 'labels' => $labels,
3667 'public' => true,
3668 'exclude_from_search'=>true,
3669 'has_archive' => true,
3670 'publicly_queryable'=>true,
3671 'show_ui'=>true,
3672 'supports' => array( 'thumbnail','title','editor','comments' ),
3673 'show_in_menu' => TRUE,
3674 'show_in_nav_menus' => TRUE
3675 )
3676 );
3677 }
3678 }
3679 add_action( 'init', 'ca_prayer_create_posttype' );
3680
3681 /****************************************************************************************
3682 *
3683 * From v2.2520 app content has it's own post type app-content, so create app-content and move content over
3684 *
3685 ****************************************************************************************/
3686 add_action( 'init', 'ca_app_content_create_posttype' );
3687 function ca_app_content_create_posttype() {
3688 $licence = get_option('church_admin_app_new_licence');
3689 if(!empty( $licence) && $licence == "premium")
3690 {
3691
3692 $labels = array(
3693 'name' => _x( 'App Content', 'Post Type General Name', 'church-admin' ),
3694 'singular_name' => _x( 'App Content', 'Post Type Singular Name', 'church-admin' ),
3695 'menu_name' => __( 'App Content', 'church-admin' ),
3696 'parent_item_colon' => __( 'Parent App Content', 'church-admin' ),
3697 'all_items' => __( 'All App Content', 'church-admin' ),
3698 'view_item' => __( 'View App Content', 'church-admin' ),
3699 'add_new_item' => __( 'Add New App Content', 'church-admin' ),
3700 'add_new' => __( 'Add New', 'church-admin' ),
3701 'edit_item' => __( 'Edit App Content', 'church-admin' ),
3702 'update_item' => __( 'Update App Content', 'church-admin' ),
3703 'search_items' => __( 'Search App Content', 'church-admin' ),
3704 'not_found' => __( 'Not Found', 'church-admin' ),
3705 'not_found_in_trash' => __( 'Not found in Trash', 'church-admin' ),
3706
3707 );
3708 $args=array(
3709 'labels' => $labels,
3710 'public' => true,
3711 'exclude_from_search'=>true,
3712 'has_archive' => true,
3713 'publicly_queryable'=>true,
3714 'show_ui'=>true,
3715 'supports' => array( 'thumbnail','title','editor'),
3716 'show_in_menu' => true,
3717 'show_in_nav_menus' => true,
3718
3719 );
3720 $gutenbergapp=get_option('church_admin_app_gutenberg');
3721 if(!empty($gutenbergapp))$args['show_in_rest']=true;
3722 register_post_type( 'app-content',$args);
3723
3724
3725 //church_admin_fix_app_default_content();
3726 }
3727 }
3728 /****************************
3729 *
3730 *
3731 * Bible Reading Plan
3732 *
3733 *
3734 *****************************/
3735
3736 function ca_bible_reading_create_posttype() {
3737 $noBible=get_option('church-admin-no-bible-readings');
3738 if ( empty( $noBible) )
3739 {
3740 $labels = array(
3741 'name' => _x( 'Bible Readings', 'Post Type General Name', 'church-admin' ),
3742 'singular_name' => _x( 'Bible Reading', 'Post Type Singular Name', 'church-admin' ),
3743 'menu_name' => __( 'Bible Readings', 'church-admin' ),
3744 'parent_item_colon' => __( 'Parent Bible Reading', 'church-admin' ),
3745 'all_items' => __( 'All Bible Readings', 'church-admin' ),
3746 'view_item' => __( 'View Bible Reading', 'church-admin' ),
3747 'add_new_item' => __( 'Add New Bible Reading', 'church-admin' ),
3748 'add_new' => __( 'Add New', 'church-admin' ),
3749 'edit_item' => __( 'Edit Bible Reading', 'church-admin' ),
3750 'update_item' => __( 'Update Bible Reading', 'church-admin' ),
3751 'search_items' => __( 'Search Bible Readings', 'church-admin' ),
3752 'not_found' => __( 'Not Found', 'church-admin' ),
3753 'not_found_in_trash' => __( 'Not found in Trash', 'church-admin' ),
3754
3755 );
3756
3757 register_post_type( 'bible-readings',
3758 // CPT Options
3759 array(
3760
3761 'hierarchical' => false,
3762 'labels' => $labels,
3763 'public' => true,
3764 'exclude_from_search'=>false,
3765 'has_archive' => true,
3766 'publicly_queryable'=>true,
3767 'show_ui'=>true,
3768 'supports' => array( 'thumbnail','title','editor','comments' ),
3769 'show_in_menu' => TRUE,
3770 'show_in_nav_menus' => TRUE,
3771 'show_in_rest' => true,
3772 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail','custom-fields', 'comments', 'revisions', 'permalinks', 'featured_image' )
3773 )
3774 );
3775 }
3776 }
3777
3778 add_action( 'init', 'ca_bible_reading_create_posttype' );
3779 /****************************
3780 *
3781 *
3782 * Acts of courage
3783 *
3784 *
3785 *****************************/
3786
3787 function ca_acts_of_courage_create_posttype() {
3788
3789 $acts=get_option('church-admin-acts-of-courage');
3790 if( $acts)
3791 {
3792 $labels = array(
3793 'name' => _x( 'Acts of Courage', 'Post Type General Name', 'church-admin' ),
3794 'singular_name' => _x( 'Act of Courage', 'Post Type Singular Name', 'church-admin' ),
3795 'menu_name' => __( 'Acts of Courage', 'church-admin' ),
3796 'parent_item_colon' => __( 'Parent Act of Courage', 'church-admin' ),
3797 'all_items' => __( 'All Acts of Courage', 'church-admin' ),
3798 'view_item' => __( 'View Act of Courage', 'church-admin' ),
3799 'add_new_item' => __( 'Add New Acts of Courage', 'church-admin' ),
3800 'add_new' => __( 'Add New', 'church-admin' ),
3801 'edit_item' => __( 'Edit Acts of Courage', 'church-admin' ),
3802 'update_item' => __( 'Update Act of Courage', 'church-admin' ),
3803 'search_items' => __( 'Search Acts of Courage', 'church-admin' ),
3804 'not_found' => __( 'Not Found', 'church-admin' ),
3805 'not_found_in_trash' => __( 'Not found in Trash', 'church-admin' ),
3806
3807 );
3808
3809 register_post_type( 'acts-of-courage',
3810 // CPT Options
3811 array(
3812 'labels' => $labels,
3813 'public' => true,
3814 'exclude_from_search'=>false,
3815 'has_archive' => true,
3816 'publicly_queryable'=>true,
3817 'show_ui'=>true,
3818 'supports' => array( 'thumbnail','title','editor','comments' ),
3819 'show_in_menu' => TRUE,
3820 'show_in_nav_menus' => TRUE
3821 )
3822 );
3823 }
3824 }
3825
3826 add_action( 'init', 'ca_acts_of_courage_create_posttype' );
3827
3828 /****************************
3829 *
3830 *
3831 * Service Planner
3832 * Working behind teh scenes as of v3.8.3
3833 *
3834 *****************************/
3835 /*
3836 function ca_service_create_posttype() {
3837 $noServicePlanner=get_option('church-admin-no-service-planner');
3838 if ( empty( $noServicePlanner) )
3839 {
3840 $labels = array(
3841 'name' => _x( 'Service Planner', 'Post Type General Name', 'church-admin' ),
3842 'singular_name' => _x( 'Service plan', 'Post Type Singular Name', 'church-admin' ),
3843 'menu_name' => __( 'Service plans', 'church-admin' ),
3844 'parent_item_colon' => __( 'Parent Service Plan', 'church-admin' ),
3845 'all_items' => __( 'All Service Plans', 'church-admin' ),
3846 'view_item' => __( 'View Service Plan', 'church-admin' ),
3847 'add_new_item' => __( 'Add New Service Plan', 'church-admin' ),
3848 'add_new' => __( 'Add New', 'church-admin' ),
3849 'edit_item' => __( 'Edit Service Plan', 'church-admin' ),
3850 'update_item' => __( 'Update Service Plan', 'church-admin' ),
3851 'search_items' => __( 'Search Service Plans', 'church-admin' ),
3852 'not_found' => __( 'Not Found', 'church-admin' ),
3853 'not_found_in_trash' => __( 'Not found in Trash', 'church-admin' ),
3854
3855 );
3856
3857 register_post_type( 'service-plans',
3858 // CPT Options
3859 array(
3860 'labels' => $labels,
3861 'public' => true,
3862 'exclude_from_search'=>false,
3863 'has_archive' => true,
3864 'publicly_queryable'=>true,
3865 'show_ui'=>true,
3866 'supports' => array( 'thumbnail','title','editor','comments' ),
3867 'show_in_menu' => TRUE,
3868 'show_in_nav_menus' => TRUE,
3869 'show_in_rest' => true,
3870 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail','custom-fields', 'comments', 'revisions', 'permalinks', 'featured_image' )
3871 )
3872 );
3873 }
3874 }
3875
3876
3877 */
3878
3879
3880
3881 /**
3882
3883 * Adds a meta box to the post editing screen
3884
3885 */
3886
3887 function ca_brp_custom_meta() {
3888
3889 add_meta_box( 'ca_brp_meta', __( 'Scripture', 'church-admin' ), 'ca_brp_meta_callback', 'bible-readings','normal','high' );
3890
3891 }
3892
3893 add_action( 'add_meta_boxes', 'ca_brp_custom_meta' );
3894
3895 add_action('edit_form_after_title', 'ca_move_metabox_after_title' );
3896
3897
3898
3899 function ca_move_metabox_after_title () {
3900
3901 global $post, $wp_meta_boxes;
3902
3903 do_meta_boxes( get_current_screen(), 'after_title', $post );
3904
3905 unset( $wp_meta_boxes[get_post_type( $post )]['after_title'] );
3906
3907 }
3908 /**
3909 * Outputs the content of the meta box
3910 */
3911 function ca_brp_meta_callback( $post )
3912 {
3913 wp_nonce_field( basename( __FILE__ ), 'ca_brp__nonce' );
3914 $stored_meta = get_post_meta( $post->ID ,'bible-passage',TRUE);
3915 ?>
3916
3917 <p>
3918 <label for="meta-text" class="ca_brp_-row-title"><?php _e( 'Bible Passage', 'church-admin' )?></label>
3919 <input type="text" name="meta-text" class="large-text" id="meta-text" value="<?php if ( isset ( $stored_meta ) ) echo esc_attr($stored_meta); ?>" />
3920 </p>
3921
3922 <?php
3923 }
3924
3925 /**
3926 * Saves the custom meta input
3927 */
3928 function ca_brp__meta_save( $post_id ) {
3929
3930 // Checks save status
3931 $is_autosave = wp_is_post_autosave( $post_id );
3932 $is_revision = wp_is_post_revision( $post_id );
3933 $is_valid_nonce = ( isset( $_POST[ 'ca_brp__nonce' ] ) && wp_verify_nonce( $_POST[ 'ca_brp__nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
3934
3935 // Exits script depending on save status
3936 if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
3937 return;
3938 }
3939
3940
3941 $passage = !empty($_POST['meta-text']) ? church_admin_sanitize($_POST['meta-text']) : null;
3942 if (empty($passage)) return;
3943
3944 update_post_meta( $post_id, 'bible-passage', esc_attr($passage) );
3945
3946
3947 }
3948 add_action( 'save_post', 'ca_brp__meta_save' );
3949
3950 // Add the custom columns to the bible-readings post type:
3951 add_filter( 'manage_bible-readings_posts_columns', 'church_admin_set_custom_bible_readings_columns' );
3952 function church_admin_set_custom_bible_readings_columns( $columns)
3953 {
3954
3955
3956 $newcolumns=array() ;
3957 foreach( $columns as $key=>$value) {
3958 if( $key=='date')
3959 { // when we find the date column
3960
3961 $newcolumns['passage'] = __( 'Bible passage', 'church-admin' );
3962 $newcolumns['thumbnail'] = __( 'Featured Image', 'church-admin' );
3963
3964
3965
3966 }
3967 $newcolumns[$key]=$value;
3968 }
3969
3970 return $newcolumns;
3971 }
3972
3973 // Add the data to the custom columns for the book post type:
3974 add_action( 'manage_bible-readings_posts_custom_column' , 'church_admin_custom_bible_readings_column', 10, 2 );
3975 function church_admin_custom_bible_readings_column( $column, $post_id ) {
3976 switch ( $column ) {
3977
3978 case 'passage' :
3979 $passages=get_post_meta( $post_id,'bible-passage',true);
3980 if ( is_string( $passages ) )
3981 echo esc_html( $passages);
3982 else
3983 _e( 'Unable to get passage(s)', 'church-admin' );
3984 break;
3985 case'thumbnail':
3986 if(has_post_thumbnail( $post_id) )
3987 {
3988 echo get_the_post_thumbnail( $post_id, 'ca-address-thumb' );
3989 }
3990 else
3991 {
3992 _e('No featured image','church-admin');
3993 }
3994 break;
3995 case 'resend':
3996 echo '<a href="'.wp_nonce_url('admin.php?page=church_admin/index.php&action=resend-bible-reading&ID='.(int)$post_id,'resend-bible-reading').'">'.esc_html( __('Resend','church-admin' ) ).'</a>';
3997
3998 break;
3999 }
4000 }
4001
4002 function ca_bible_reading_passage( $content ) {
4003
4004 //this function prepends the passage to content for bible readings
4005 global $post;
4006 if ( is_single() && 'bible-readings' == get_post_type() ) {
4007 $custom_content='';
4008 $version=get_option('church_admin_bible_version');
4009 if(empty($version)){
4010 $version='ESV';
4011 }
4012 $passages=explode(",",get_post_meta( $post->ID ,'bible-passage',TRUE) );
4013 if(!empty( $passages) )
4014 {
4015 // //church_admin_debugprint_r( $passages,true) );
4016 foreach( $passages AS $key=>$passage)
4017 {
4018 $sanitizedPassage = church_admin_bible_audio_link( $passage, $version );
4019 $dayNo=get_the_date('z')+1;
4020 $custom_content.='<div class="ca-bible-date">'.get_the_date().' '.esc_html( __('Day','church-admin' ) ).' '.$dayNo.'</div>';
4021 if(!empty( $passage) )
4022 {
4023 $custom_content .= '<p class="ca-bible-reading"><a href="https://www.biblegateway.com/passage/?search='.urlencode( $sanitizedPassage['passage']).'&version='.urlencode( $version).'&interface=print" target="_blank" >'.esc_html( $sanitizedPassage['passage']).'</a></p>';
4024 $headphonesSVG='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M6 23v-11c-4.036 0-6 2.715-6 5.5 0 2.807 1.995 5.5 6 5.5zm18-5.5c0-2.785-1.964-5.5-6-5.5v11c4.005 0 6-2.693 6-5.5zm-12-13.522c-3.879-.008-6.861 2.349-7.743 6.195-.751.145-1.479.385-2.161.716.629-5.501 4.319-9.889 9.904-9.889 5.589 0 9.29 4.389 9.916 9.896-.684-.334-1.415-.575-2.169-.721-.881-3.85-3.867-6.205-7.747-6.197z" /></svg>';
4025
4026 //church_admin_debugprint_r( $bibleCV,true) );
4027 if(!empty( $bibleCV['url'] ) )$custom_content.='<p><a href="'.$sanitizedPassage['url'].'">'.$headphonesSVG.' '.$sanitizedPassage['linkText'].'</a></p>';
4028 }
4029 }
4030 $custom_content .= $content;
4031 }
4032 return $custom_content;
4033 } else {
4034 return $content;
4035 }
4036 }
4037 add_filter( 'the_content', 'ca_bible_reading_passage' );
4038 /****************************
4039 *
4040 *
4041 * Ajax operations
4042 *
4043 *
4044 *****************************/
4045
4046 //Bulk email
4047 add_action('wp_ajax_nopriv_church_admin_cronemail', 'church_admin_bulk_email');
4048 add_action('wp_ajax_church_admin_cronemail', 'church_admin_bulk_email');
4049
4050
4051
4052
4053
4054
4055 add_action('wp_ajax_church_admin_calendar_date_display','church_admin_date');
4056 add_action('wp_ajax_nopriv_church_admin_calendar_date_display', '');
4057
4058 /**
4059 *
4060 * Ajax image upload
4061 *
4062 * @author Andy Moyle
4063 * @param null
4064 * @return html
4065 * @version 0.1
4066 *
4067 */
4068 add_action('wp_ajax_church_admin_image_upload','church_admin_image_upload');
4069 add_action('wp_ajax_nopriv_church_admin_image_upload', 'church_admin_image_upload');
4070 function church_admin_image_upload()
4071 {
4072 //church_admin_debug("********************\r\nAJAX Image upload");
4073 // These files need to be included as dependencies when on the front end.
4074 require_once( ABSPATH . 'wp-admin/includes/image.php' );
4075 require_once( ABSPATH . 'wp-admin/includes/file.php' );
4076 require_once( ABSPATH . 'wp-admin/includes/media.php' );
4077 // Let WordPress handle the upload.
4078 // Remember, 'my_image_upload' is the name of our file input in our form above.
4079 $attachment_id = media_handle_upload( 'file-0', 0 );
4080 //church_admin_debug("attachment_id: ".$attachment_id);
4081 if ( is_wp_error( $attachment_id ) ) {
4082 exit();
4083 } else {
4084 // The image was uploaded successfully!
4085 $image=wp_get_attachment_image_src( $attachment_id, "thumbnail", false );
4086 //church_admin_debugprint_r( $image,TRUE) );
4087 echo json_encode(array('src' => esc_url( $image[0] ), 'attachment_id' => (int)$attachment_id ) );
4088 exit();
4089 }
4090
4091
4092
4093 }
4094
4095 /**
4096 *
4097 * Popup of calendar events
4098 *
4099 * @author Andy Moyle
4100 * @param null
4101 * @return html
4102 * @version 0.1
4103 *
4104 */
4105 add_action('wp_ajax_church_admin_calendar_event_display','church_admin_calendar_event_display');
4106 add_action('wp_ajax_nopriv_church_admin_calendar_event_display', 'church_admin_calendar_event_display');
4107 function church_admin_calendar_event_display()
4108 {
4109 //church_admin_debug('Calendar Event' .date('Y-m-d h:i:s') );
4110 global $wpdb;
4111 $date_sql=1;
4112 $out='';
4113 $dates=explode(',',$_POST['date'] );
4114 foreach( $dates AS $key=>$value) { $datesql[]='a.start_date="'.esc_sql( $value).'"';}
4115 if(!empty( $datesql) ) {
4116 $date_sql=' ('.implode(' || ',$datesql).')';
4117 }else{
4118 echo esc_html( __( 'No event to show', 'church-admin' ) );
4119 exit();
4120 }
4121
4122 $sql='SELECT a.*, b.* FROM '.$wpdb->prefix.'church_admin_calendar_date a LEFT JOIN '.$wpdb->prefix.'church_admin_calendar_category b ON b.cat_id = a.cat_id WHERE '.esc_sql( $date_sql );
4123
4124
4125 $result=$wpdb->get_results( $sql);
4126
4127 if(!empty( $result) )
4128 {
4129 foreach( $result AS $row)
4130 {
4131 $out.='<div class="ca-event ">';
4132 $out.='<span class="ca-close">x</span>';
4133 $out.='<h2 style="color:'.esc_html( $row->bgcolor).'">'.esc_html( $row->title).'</h2>';
4134 $out.='<p>'.esc_html( mysql2date( get_option('date_format'), $row->start_date) ).' '.esc_html( mysql2date(get_option('time_format'),$row->start_time) ).' - '.esc_html( mysql2date(get_option('time_format'),$row->end_time) ).'</p>';
4135 if(!empty( $row->description) )$out.='<p>'.esc_html( $row->description ).'</p>';
4136 if(!empty( $row->page_id) )$out.='<p><a href="'.get_permalink( $row->page_id ).'">'.esc_html( __('More information','church-admin' ) ).'</p>';
4137 if(!empty( $row->booking_id) )$out.='<p><a class="button-primary" href="'.esc_url( get_permalink( $row->booking_id) ).'">'.esc_html( __('Book Now', 'church-admin' ) ).'</p>';
4138 $out.='</div>';
4139 }
4140 }
4141 else
4142 {
4143 $out= esc_html( __('No event to show','church-admin') );
4144 }
4145 echo json_encode(array('id'=>esc_html( sanitize_text_field(stripslashes($_POST['date'] ) ) ),'output'=>$out) );
4146 exit();
4147 }
4148
4149
4150
4151 /****************************************
4152 * MAIN AJAX HANDLER
4153 *****************************************/
4154
4155 add_action('wp_ajax_church_admin','church_admin_ajax_handler');
4156 add_action('wp_ajax_nopriv_church_admin', 'church_admin_ajax_handler');
4157
4158 function church_admin_ajax_handler()
4159 {
4160
4161 global $wpdb;
4162 $current_user = wp_get_current_user();
4163 switch ( $_REQUEST['method'] )
4164 {
4165
4166
4167
4168 case 'kiosk-app-delete':
4169 church_admin_debug('**** kiosk-app-delete ****');
4170 check_ajax_referer('kiosk-app-ajax','nonce');
4171 church_admin_debug($_POST);
4172 $ID=church_admin_sanitize($_POST['id']);
4173 if(empty($ID)){return; exit();}
4174 $display_fields = get_option('church_admin_kiosk_app_form');
4175 church_admin_debug($display_fields);
4176 if(!empty($display_fields[$ID])){
4177 unset($display_fields[$ID]);
4178
4179 update_option('church_admin_kiosk_app_form',$display_fields);
4180 }
4181 echo (int)$ID;
4182 exit();
4183 break;
4184 case 'kiosk_form_order':
4185 check_ajax_referer('kiosk-app-ajax','nonce');
4186 if(!empty( $_POST['order'] ) )
4187 {
4188 $order=explode(",",church_admin_sanitize($_POST['order']) );
4189 $saved_fields=get_option('church_admin_kiosk_app_form');
4190 foreach( $order AS $key=>$name)
4191 {
4192 //church_admin_debug("Handling $name and giving it order of $key");
4193 if(!empty( $saved_fields[$name] ) )$saved_fields[$name]['order']=(int)$key;
4194 }
4195
4196 update_option('church_admin_kiosk_app_form',$saved_fields);
4197 }
4198
4199 break;
4200 case'pastoral-list-remove':
4201 check_ajax_referer('pastoral-list-remove','nonce');
4202 $people_id=!empty($_POST['people_id'])?church_admin_sanitize($_POST['people_id'] ) :exit();
4203 $wpdb->query('DELETE FROM '.$wpdb->prefix.'church_admin_people_meta WHERE people_id="'.(int)$people_id.'" AND meta_type="pastoral-visit-required"');
4204 echo (int)$people_id;
4205 exit();
4206 break;
4207 case 'add-to-group':
4208 check_ajax_referer('add-to-group','nonce');
4209 //church_admin_debug('*** Add to group AJAX ****');
4210 //sanitize
4211 $people_id=!empty($_POST['people_id'])?sanitize_text_field(stripslashes($_POST['people_id'] ) ):exit();
4212 $group_id = !empty($_POST['group_id'])?sanitize_text_field(stripslashes($_POST['group_id'] ) ):exit();
4213 //validate
4214 if(!church_admin_int_check($people_id)){
4215 //church_admin_debug('Invalid people_id');
4216 exit();
4217 }
4218 if(!church_admin_int_check($group_id)){
4219 //church_admin_debug('Invalid group_id');
4220 exit();
4221 }
4222 //check
4223 $checked_people_id=$wpdb->get_var('SELECT people_id FROM '.$wpdb->prefix.'church_admin_people WHERE people_id="'.(int)$people_id.'"');
4224 if(empty($checked_people_id)){
4225 //church_admin_debug('People_id not in DB');
4226 exit();
4227 }
4228 $groups=church_admin_groups_array();
4229 if(empty($groups[$group_id])){
4230 //church_admin_debug('Group not recognised');
4231 exit();
4232 }
4233
4234 //safe to proceed
4235 //delete persons current group
4236 $wpdb->query('DELETE FROM '.$wpdb->prefix.'church_admin_people_meta WHERE people_id="'.(int)$people_id.'" AND meta_type="smallgroup"');
4237 $wpdb->query('INSERT INTO '.$wpdb->prefix.'church_admin_people_meta (meta_type,people_id,ID,meta_date) VALUES("smallgroup","'.(int)$people_id.'","'.(int)$group_id.'","'.wp_date('Y-m-d').'")');
4238 //send out put back
4239
4240 $output=array('people_id'=>$people_id);
4241 header('Access-Control-Max-Age: 1728000');
4242 header('Access-Control-Allow-Origin: *');
4243 header('Access-Control-Allow-Methods: *');
4244 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4245 header('Access-Control-Allow-Credentials: true');
4246 echo json_encode( $output);
4247 die();
4248
4249 break;
4250 case 'sermon_length':
4251 //church_admin_debug('Sermon length AJAX');
4252 check_ajax_referer('sermon_length','nonce');
4253 $file_id=(int)$_REQUEST['id'];
4254 $length=sanitize_text_field(stripslashes($_REQUEST['length'] ) );
4255 $regex='/(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9]/';
4256 $match=preg_match($regex,$length);
4257 //church_admin_debug("match - ".$match);
4258 if(!empty($match)){
4259 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_sermon_files SET length="'.esc_sql($length).'" WHERE file_id="'.(int)$file_id.'"');
4260 //church_admin_debug($wpdb->last_query);
4261 }
4262 header('Access-Control-Max-Age: 1728000');
4263 header('Access-Control-Allow-Origin: *');
4264 header('Access-Control-Allow-Methods: *');
4265 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4266 header('Access-Control-Allow-Credentials: true');
4267 if($wpdb->rows_affected==1){
4268 //translators: %1$s is a time of the recording
4269 echo esc_html(sprintf(__('%1$s updated','church-admin' ) , $length));
4270 }
4271 exit();
4272 break;
4273
4274
4275 case 'facility-booking':
4276 check_ajax_referer('facility-booking','nonce');
4277 //church_admin_debugprint_r( $_POST,TRUE) );
4278
4279 //sanitize
4280 $facilities_id=!empty($_POST['facilities_id'])?sanitize_text_field(stripslashes($_POST['facilities_id'])):null;
4281 $startDate=!empty($_POST['facilities_id'])?sanitize_text_field(stripslashes( $_POST['start_date'] )):null;
4282 $startTime=!empty( $_POST['start_time'] )?sanitize_text_field(stripslashes( $_POST['start_time'] )):null;
4283 $endTime=!empty( $_POST['end_time'] )?sanitize_text_field(stripslashes( $_POST['start_time'] )):null;
4284
4285 //validate
4286 if(empty($facilities_id)||!church_admin_int_check($facilities_id)){exit();}
4287 if(empty($start_date)||!church_admin_checkdate($start_date)){exit();}
4288 if(empty($startTime) || !preg_match('#^([01]?[0-9]|2[0-3]):[0-5][0-9]?$#', $startTime)){exit();}
4289 if(empty($endTime) || !preg_match('#^([01]?[0-9]|2[0-3]):[0-5][0-9]?$#', $endTime)){exit();}
4290
4291 $check=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_calendar_date WHERE facilities_id="'.(int)$facilities_id.'" AND
4292 (startTime BETWEEN "'.esc_sql($startTime).'" AND "'.esc_sql($endTime).'") OR
4293 (endTime BETWEEN "'.esc_sql($startTime).'" AND "'.esc_sql($endTime).'") OR
4294 (startTime BETWEEN "'.esc_sql($startTime).'" AND "'.esc_sql($endTime).'" AND endTime BETWEEN "'.esc_sql($startTime).'" AND "'.esc_sql($endTime).'") OR
4295 (startTime<="'.esc_sql($startTime).'" AND endTime>="'.esc_sql($endTime).'")');
4296
4297 if ( empty( $check) ) {
4298 $out=array('message'=> '<span style="color:green;">'. esc_html(__('Date and time are available','church-admin')).'</span>','available'=>1);
4299 }else{$out=array('message'=>'<span style="color:red;">'. esc_html( __('Date and time are NOT available','church-admin') ).'</span>','available'=>0);}
4300 header('Access-Control-Max-Age: 1728000');
4301 header('Access-Control-Allow-Origin: *');
4302 header('Access-Control-Allow-Methods: *');
4303 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4304 header('Access-Control-Allow-Credentials: true');
4305 echo json_encode( $out);
4306 die();
4307 break;
4308 case 'update-site':
4309 check_ajax_referer('update-site','nonce');
4310 //sanitize
4311 $ID=!empty($_POST['id'])?sanitize_text_field(stripslashes($_POST['id'])):null;
4312 $div=!empty($_POST['div'])?sanitize_text_field( stripslashes( $_POST['div'] ) ):null;
4313 $lat = !empty($_POST['lat'])?sanitize_text_field( stripslashes( $_POST['lat'] ) ):null;
4314 $lng = !empty($_POST['lng'])?sanitize_text_field( stripslashes( $_POST['lng'] ) ):null;
4315
4316 //validate
4317 $errors = array();
4318 if(empty($ID) || !church_admin_int_check($ID)){
4319 $errors[] = __('Invalid site ID','church-admin');
4320 }
4321 if(empty($lat) || !church_admin_validate_latitude($lat)){
4322 $errors[] = __('Invalid latitude','church-admin');
4323 }
4324 if(empty($lat) || !church_admin_validate_longitude($lng)){
4325 $errors[] = __('Invalid longitude','church-admin');
4326 }
4327
4328 if(!empty($errors) )
4329 {
4330 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_sites SET lat="'.esc_sql( $lat ).'",lng="'.esc_sql( $lng ).'" WHERE site_id="'.(int)$ID.'"');
4331 //church_admin_debug $wpdb->last_query);
4332 }
4333 else
4334 {
4335 $output = array('errors' => esc_html(implode(", ",$errors)) );
4336 }
4337 break;
4338
4339 case 'update-directory':
4340 //church_admin_debugprint_r( $_POST,TRUE) );
4341
4342 check_ajax_referer('update-directory','nonce');
4343 $ID=!empty($_POST['id'])?sanitize_text_field(stripslashes($_POST['id'])):null;
4344 if(empty($ID)||!church_admin_int_check($ID)){exit("Invalid ID");}
4345 $div=!empty($_POST['div'])?sanitize_text_field( stripslashes( $_POST['div'] ) ):null;
4346 $what=!empty($_POST['what'])?sanitize_text_field( stripslashes( $_POST['what'] ) ):null;
4347 $custom_id=!empty($_POST['custom-id'])?sanitize_text_field(stripslashes($_POST['custom-id'])):null;
4348 $lat=!empty($_POST['lat'])?sanitize_text_field(stripslashes($_POST['lat'])):null;
4349 $lng=!empty($_POST['lng'])?sanitize_text_field(stripslashes($_POST['lng'])):null;
4350 if(!empty( $_POST['value'] ) )$value=church_admin_sanitize($_POST['value'] ) ;
4351 if(!empty($value) && is_array($value)){$value=maybe_serialize($value);}
4352 //validate
4353
4354 $errors = array();
4355 if(empty($ID) || !church_admin_int_check($ID)){
4356 $errors[] = __('Invalid site ID','church-admin');
4357 }
4358 if(!empty($lat) && !church_admin_validate_latitude($lat)){
4359 $errors[] = __('Invalid latitude','church-admin');
4360 }
4361 if(!empty($lat) && !church_admin_validate_longitude($lng)){
4362 $errors[] = __('Invalid longitude','church-admin');
4363 }
4364
4365 if(!empty($errors))
4366 {
4367 exit();
4368 }
4369 switch( $what)
4370 {
4371 case 'wedding_anniversary':
4372 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_household SET wedding_anniversary="'.esc_sql( $value).'" WHERE household_id="'.(int)$ID.'"');
4373 break;
4374 case 'member_type_id':
4375 if(!empty( $ID) && !empty( $value) ) $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET member_type_id="'.(int)$value.'" WHERE people_id="'.(int)$ID.'"');
4376 //church_admin_debug $wpdb->last_query);
4377 $mtOut=church_admin_member_type_option( $value);
4378 break;
4379 case 'people_type_id':
4380 if(!empty( $ID) && !empty( $value) ) $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET people_type_id="'.(int)$value.'" WHERE people_id="'.(int)$ID.'"');
4381 //church_admin_debug $wpdb->last_query);
4382 break;
4383 case 'household-custom':
4384
4385 $metaData=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_custom_fields_meta WHERE section="household" AND custom_id="'.(int)$custom_id.'" AND household_id="'.(int)$ID.'"');
4386 //church_admin_debug($wpdb->last_query);
4387 if( !empty($metaData->ID))
4388 {
4389 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_custom_fields_meta SET section="household", data="'.esc_sql($value).'" , household_id="'.(int)$ID.'" WHERE ID="'.(int)$metaData->ID.'"' );
4390 }
4391 else
4392 {
4393 $wpdb->query('INSERT INTO '.$wpdb->prefix.'church_admin_custom_fields_meta (custom_id,household_id,data,section) VALUES("'.esc_sql($custom_id).'","'.(int)$ID.'","'.esc_sql($value).'","household")');
4394 }
4395 //church_admin_debug($wpdb->last_query);
4396 break;
4397
4398 case 'phone':$wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_household SET phone="'.esc_sql( $value).'" WHERE household_id="'.(int)$ID.'"');break;
4399 case 'address':$wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_household SET address="'.esc_sql( $value).'" WHERE household_id="'.(int)$ID.'"');break;
4400 case 'mailing-address':$wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_household SET mailing_address="'.esc_sql( $value).'" WHERE household_id="'.(int)$ID.'"');break;
4401 case 'email':$wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET email="'.esc_sql( $value).'" WHERE people_id="'.(int)$ID.'"');break;
4402 case 'mobile':case 'cell':
4403
4404 $e164cell=!empty( $value)?church_admin_e164( $value):'';
4405 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET mobile="'.esc_sql( $value).'", e164cell="'.esc_sql( $e614cell).'" WHERE people_id="'.(int)$ID.'"');
4406
4407 break;
4408
4409
4410 case 'geocode':
4411 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_household SET geocoded=1, lat="'.esc_sql($lat ).'",lng="'.esc_sql($lng ).'" WHERE household_id="'.(int)$ID.'"');
4412
4413 break;
4414 }
4415 //church_admin_debug($wpdb->last_query);
4416 //reset app address list cache
4417 delete_option('church_admin_app_address_cache');
4418 delete_option('church_admin_app_admin_address_cache');
4419
4420 header('Access-Control-Max-Age: 1728000');
4421 header('Access-Control-Allow-Origin: *');
4422 header('Access-Control-Allow-Methods: *');
4423 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4424 header('Access-Control-Allow-Credentials: true');
4425 $outputArray=array();
4426 if(!empty( $div) ) $outputArray['div']=esc_html( $div);
4427 if(!empty( $mtOut) )$outputArray['mtout']=$mtOut;
4428 echo json_encode( $outputArray);
4429
4430 exit();
4431 break;
4432 case 'smallgroup-map-geocode':
4433 //church_admin_debug('Small group map geocode');
4434 check_ajax_referer('smallgroup-map-geocode','nonce');
4435 //church_admin_debugprint_r( $_POST,TRUE) );
4436 //sanitize
4437 $lat = !empty($_POST['lat'])?sanitize_text_field( stripslashes( $_POST['lat'] ) ):null;
4438 $lng = !empty($_POST['lng'])?sanitize_text_field( stripslashes( $_POST['lng'] ) ):null;
4439 $id=!empty($_POST['id'])?sanitize_text_field(stripslashes($_POST['id'])):null;
4440
4441 //validate
4442 $errors=array();
4443 if(empty($id) || !church_admin_int_check($id)){
4444 $errors[] = __('Invalid small group','church-admin');
4445 }
4446 if(empty($lat) || !church_admin_validate_latitude($lat)){
4447 $errors[] = __('Invalid latitude','church-admin');
4448 }
4449 if(empty($lat) || !church_admin_validate_longitude($lng)){
4450 $errors[] = __('Invalid longitude','church-admin');
4451 }
4452 if(empty( $errors ))
4453 {
4454 $sql='UPDATE '.$wpdb->prefix.'church_admin_smallgroup SET lat="'.esc_sql($lat ).'",lng="'.esc_sql($lng).'" WHERE id="'.(int)$id.'"';
4455 //church_admin_debug $sql);
4456 $wpdb->query( $sql);
4457 $output = array('lat'=>esc_attr($lng),'lng'=>esc_attr( $lng ));
4458 }
4459 else
4460 {
4461 $output = array('errors' => esc_html(implode(", ",$errors)) );
4462 }
4463 header('Access-Control-Max-Age: 1728000');
4464 header('Access-Control-Allow-Origin: *');
4465 header('Access-Control-Allow-Methods: *');
4466 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4467 header('Access-Control-Allow-Credentials: true');
4468 echo json_encode($output);
4469 exit();
4470 break;
4471 case 'ignore-last-name':
4472 check_ajax_referer('ignore-last-name','nonce');
4473 if(!empty( $_POST['household_id'] ) )
4474 {
4475 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET ignore_last_name_check=1 WHERE household_id="'.(int)$_POST['household_id'].'"');
4476 header('Access-Control-Max-Age: 1728000');
4477 header('Access-Control-Allow-Origin: *');
4478 header('Access-Control-Allow-Methods: *');
4479 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4480 header('Access-Control-Allow-Credentials: true');
4481 echo (int)$_POST['household_id'];
4482 die();
4483 }
4484 break;
4485
4486
4487 case 'show-help':
4488 //church_admin_debug $_REQUEST["which"] );
4489 require_once( plugin_dir_path( __FILE__ ).'includes/helper.php');
4490 $out=church_admin_helper( $_REQUEST["which"] );
4491 if ( empty( $out) )$out='';
4492 header('Access-Control-Max-Age: 1728000');
4493 header('Access-Control-Allow-Origin: *');
4494 header('Access-Control-Allow-Methods: *');
4495 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4496 header('Access-Control-Allow-Credentials: true');
4497 echo $out;
4498 die();
4499 break;
4500 case'dismissed-notice-handler':
4501 church_admin_debug('**** dismissed-notice-handler ******');
4502 church_admin_debug($_REQUEST);
4503
4504 check_ajax_referer('dismissed-notice-handler','nonce');
4505 //church_admin_debug('Dismiss notice');
4506 switch( $_REQUEST['type'] )
4507 {
4508 case 'church-admin-free-version': update_option('dismissed-church-admin-free-version',TRUE);break;
4509 case 'church-admin-roles-permissions': update_option('dismissed-church-admin-roles-permissions',TRUE);break;
4510 case 'dismissed-church-admin-please-review':update_option('dismissed-church-admin-please-review',TRUE);break;
4511 case "church-admin-email-settings":update_option('dismissed-church-admin-email-settings',TRUE);break;
4512 case "church-admin-set-sermon-page":update_option('dismissed-church-admin-set-sermon-page',TRUE);break;
4513 case "church-admin-bible-version":update_option('dismissed-church-admin-bible-version',TRUE);break;
4514 case "church-admin-app":update_option( 'dismissed-church-admin-app', TRUE );break;
4515 case "church-admin-gdpr":update_option( 'dismissed-church-admin-gdpr', TRUE );break;
4516 case "church-admin-cron"://church_admin_debug('cron dismissed');update_option( 'dismissed-church-admin-cron', TRUE );echo'Dismissed';break;
4517 }
4518 exit();
4519 break;
4520
4521 case 'refresh-sms':
4522 check_ajax_referer('refresh-sms','nonce');
4523 $out='';
4524 $sql='SELECT * FROM '.$wpdb->prefix.'church_admin_twilio_messages WHERE mobile="'.esc_sql( $_POST['e164cell'] ).'" AND direction=0 AND message_id>"'.(int)$_POST['lastID'].'" ORDER BY message_date ASC';
4525
4526 $results=$wpdb->get_results( $sql);
4527 if(!empty( $results) )
4528 {
4529 foreach( $results AS $row)
4530 {
4531 //church_admin_debugprint_r( $row,TRUE) );
4532 $out.='<div class="ca-message-blue"><div class="ca-message-content">';
4533 $out.= '<div class="ca-message-content">'.esc_html( $row->message).'</div>';
4534 $out.='<div class="ca-message-timestamp-left">'.mysql2date(get_option('date_format').' '.get_option('time_format'),$row->message_date).'</div></div>';
4535
4536 }
4537 $id=$row->message_id;
4538 }
4539 $output=array('messages'=>$out,'id'=>$id);
4540 //church_admin_debugprint_r( $output,TRUE) );
4541 header('Access-Control-Max-Age: 1728000');
4542 header('Access-Control-Allow-Origin: *');
4543 header('Access-Control-Allow-Methods: *');
4544 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4545 header('Access-Control-Allow-Credentials: true');
4546 echo json_encode( $output);
4547 die();
4548 break;
4549 case 'refresh-sms-replies':
4550 check_ajax_referer('refresh-sms-replies','nonce');
4551 require_once(plugin_dir_path( __FILE__) .'/includes/twilio.php');
4552 $out=church_admin_sms_replies_list();
4553
4554 header('Access-Control-Max-Age: 1728000');
4555 header('Access-Control-Allow-Origin: *');
4556 header('Access-Control-Allow-Methods: *');
4557 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4558 header('Access-Control-Allow-Credentials: true');
4559 echo json_encode( $out);
4560 die();
4561 break;
4562 case 'remove-from-favourites':
4563 //church_admin_debugprint_r( $_POST,TRUE) );
4564 check_ajax_referer('remove-from-favourites','nonce');
4565 $user_id=(int)$_POST['user_id'];
4566 $what=$_POST['what'];
4567 $favourites=get_option('church-admin-favourites');
4568 $userFavourites=$favourites[$user_id];
4569 $key = array_search( $what, $userFavourites);
4570 if ( $key !== false)
4571 {
4572 //church_admin_debug $key);
4573 unset( $favourites[$user_id][$key] );
4574 }
4575 update_option('church-admin-favourites',$favourites);
4576 church_admin_favourites_menu( $user_id);
4577 exit();
4578 break;
4579 case 'add-to-favourites':
4580 check_ajax_referer('add-to-favourites','nonce');
4581 $user_id=(int)$_POST['user_id'];
4582 $what=$_POST['what'];
4583 if( $what=='favourites')exit();
4584 $favourites=array();
4585 $favourites=get_option('church-admin-favourites');
4586 if(in_array( $what,$favourites[$user_id] ) )exit();
4587 $favourites[$user_id][]=$what;
4588 update_option('church-admin-favourites-v2',$favourites);
4589 church_admin_favourites_menu( $user_id);
4590 exit();
4591 break;
4592 case 'email-checker':
4593 check_ajax_referer('email-checker','nonce');
4594 $email=!empty($_POST['email'] )?sanitize_text_field( stripslashes($_POST['email'] )):null;
4595 $id=!empty($_REQUEST['id'])?sanitize_text_field(stripslashes($_REQUEST['id'])):null;
4596 //church_admin_debug('Email checker :'.$email);
4597 if(!empty($email) && is_email( $email) && email_exists( $email) )
4598 {
4599 $response=array('found'=>TRUE,'email'=>$email);
4600 if(!empty( $id ) )$response['id']=(int)$id;
4601
4602 }else {
4603 $response=array('found'=>FALSE,'nonce'=>wp_create_nonce('second-step'),'email'=>$email);
4604 if(!empty( $id ) )$response['id']=(int)$id;
4605 }
4606 echo json_encode( $response);
4607 exit();
4608 break;
4609 case 'remove-series-image':
4610 check_ajax_referer('remove-series-image');
4611 //sanitize
4612 $series_id=!empty($_REQUEST['series_id'])?sanitize_text_field(stripslashes($_REQUEST['series_id'])):null;
4613 //validate
4614 if(!church_admin_int_check($series_id)){exit();}
4615 $wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_services SET attachment_id="" WHERE series_id="'.(int)$series_id.'"');
4616 wp_delete_attachment( $series_id );
4617 exit();
4618 break;
4619 case 'calendar-render':
4620 check_ajax_referer('calendar','nonce');
4621 require_once(plugin_dir_path( __FILE__) .'/display/calendar.new.php');
4622 $date = !empty($_REQUEST['date'] )?sanitize_text_field(stripslashes($_REQUEST['date'] )):wp_date('Y-m-d');
4623 if(!church_admin_checkdate($date)){$date=wp_date('Y-m-d');}
4624
4625 $d=explode("-",$date);
4626 $facilities_id=!empty($_REQUEST['fac_ids'])?sanitize_text_field(stripslashes($_REQUEST['fac_ids'])):null;
4627 $cat_id=!empty($_REQUEST['cat_id'])?sanitize_text_field(stripslashes($_REQUEST['cat_id'])):null;
4628 church_admin_render_month( $d[1],$d[0],$d[2],$cat_id,$facilities_id);
4629 exit();
4630 break;
4631 case 'calendar-day-render':
4632 check_ajax_referer('calendar','nonce');
4633 require_once(plugin_dir_path( __FILE__) .'/display/calendar.new.php');
4634 $date = !empty($_REQUEST['date'] )?sanitize_text_field(stripslashes($_REQUEST['date'] )):wp_date('Y-m-d');
4635 if(!church_admin_checkdate($date)){$date=wp_date('Y-m-d');}
4636 $facilities_id=!empty($_REQUEST['facilities_id'])?sanitize_text_field(stripslashes($_REQUEST['facilities_id'])):null;
4637 $cat_id=!empty($_REQUEST['cat_id'])?sanitize_text_field(stripslashes($_REQUEST['cat_id'])):null;
4638 church_admin_render_day( $date,$cat_id,$facilities_id );
4639
4640 exit();
4641 break;
4642
4643 case 'edit-app-menu':
4644 check_ajax_referer('edit-app-menu','nonce');
4645 $chosenMenu=get_option('church_admin_app_new_menu');
4646 $menuItem=sanitize_text_field( stripslashes($_POST['menuItem'] ) );
4647 $menuTitle=sanitize_text_field(stripslashes( $_POST['menuTitle'] ));
4648 if(!empty( $chosenMenu[$menuItem] ) )
4649 {
4650 $chosenMenu[$menuItem]['item']=$menuTitle;
4651 }
4652 update_option('church_admin_app_new_menu',$chosenMenu);
4653 echo '<span class="ca-editable" data-item="'.$menuItem.'">'.$menuTitle.'</span>';
4654 exit();
4655 break;
4656 case 'app-menu-show':
4657 check_ajax_referer('edit-app-menu','nonce');
4658 $chosenMenu=get_option('church_admin_app_new_menu');
4659 //church_admin_debugprint_r( $chosenMenu,TRUE) );
4660 $menuItem=sanitize_text_field( stripslashes($_POST['menuItem'] ));
4661 $status=$_POST['status'];
4662 if( $status=="ON")
4663 {
4664 $chosenMenu[$menuItem]['show']=1;
4665 }else $chosenMenu[$menuItem]['show']=0;
4666 update_option('church_admin_app_new_menu',$chosenMenu);
4667 //church_admin_debugprint_r( $chosenMenu,TRUE) );
4668 echo'DONE';
4669 exit();
4670 break;
4671 case 'app-menu-login':
4672 check_ajax_referer('edit-app-menu','nonce');
4673 $chosenMenu=get_option('church_admin_app_new_menu');
4674 //church_admin_debugprint_r( $chosenMenu,TRUE) );
4675 $menuItem=sanitize_text_field( stripslashes($_POST['menuItem'] ) );
4676 $status=sanitize_text_field( stripslashes($_POST['status']));
4677 if( $status=="ON")
4678 {
4679 $chosenMenu[$menuItem]['loggedinOnly']=1;
4680 }else $chosenMenu[$menuItem]['loggedinOnly']=0;
4681 update_option('church_admin_app_new_menu',$chosenMenu);
4682 //church_admin_debugprint_r( $chosenMenu,TRUE) );
4683 echo'DONE';
4684 exit();
4685 break;
4686 case 'add-ticket':
4687 check_ajax_referer('add-ticket','nonce');
4688 require_once(plugin_dir_path( __FILE__) .'/includes/events.php');
4689 $x=sanitize_text_field( stripslashes($_REQUEST['id']));
4690
4691 echo church_admin_event_ticket_form(NULL,$x,FALSE);
4692
4693 exit();
4694 break;
4695 case 'event-ticket':
4696 check_ajax_referer('event-ticket','nonce');
4697 require_once(plugin_dir_path( __FILE__) .'/display/events.php');
4698 $x=sanitize_text_field( stripslashes($_REQUEST['id']));
4699 $event_id=!empty($_REQUEST['event_id'])?sanitize_text_field(stripslashes($_REQUEST['event_id'])):null;
4700 if(empty($event_id)||!church_admin_int_check($event_id)){exit();}
4701 $ticket=church_admin_front_end_ticket( (int)$event_id,$x,TRUE);
4702 echo wp_kses_post($ticket['output']);
4703 exit();
4704 break;
4705 case 'event-booking':
4706 check_ajax_referer('event-booking','nonce');
4707 require_once(plugin_dir_path( __FILE__) .'/display/events.php');
4708
4709 $booking_ref = church_admin_save_event_booking();
4710 //church_admin_debug $booking_ref);
4711 //get cost
4712 $cost=$wpdb->get_var('SELECT SUM(a.ticket_price) FROM '.$wpdb->prefix.'church_admin_tickets a, '.$wpdb->prefix.'church_admin_bookings b WHERE a.ticket_id=b.ticket_type AND b.booking_ref="'.esc_sql( $booking_ref).'"');
4713 //church_admin_debug $wpdb->last_query);
4714 //church_admin_debug $cost);
4715 header('Access-Control-Max-Age: 1728000');
4716 header('Access-Control-Allow-Origin: *');
4717 header('Access-Control-Allow-Methods: *');
4718 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4719 header('Access-Control-Allow-Credentials: true');
4720 $output=json_encode(array('booking_ref'=>$booking_ref,'cost'=>$cost) );
4721 //church_admin_debug $output);
4722 echo $output;
4723 exit();
4724 exit();
4725 break;
4726
4727 case 'assign_funnel':
4728 check_admin_referer('assign_funnel','nonce');
4729 //sanitize
4730 $funnel_id=!empty($_REQUEST['funnel_id']) ? sanitize_text_field( stripslashes( $_REQUEST['funnel_id'] ) ):null;
4731 $people_id=!empty($_REQUEST['people_id']) ? sanitize_text_field( stripslashes( $_REQUEST['people_id'] ) ):null;
4732 $assign_id=!empty($_REQUEST['assign_id']) ? sanitize_text_field( stripslashes( $_REQUEST['assign_id'] ) ):null;
4733 $member_type_id=!empty($_REQUEST['member_type_id']) ? sanitize_text_field( stripslashes( $_REQUEST['member_type_id'] ) ):null;
4734 //validate
4735 if(empty($funnel_id) || !church_admin_int_check($funnel_id)){exit();}
4736 if(empty($people_id) || !church_admin_int_check($people_id)){exit();}
4737 if(empty($assign_id) || !church_admin_int_check($assign_id)){exit();}
4738 if(empty($member_type_id) || !church_admin_int_check($member_type_id)){exit();}
4739
4740 $check=$wpdb->get_var('SELECT id FROM '.$wpdb->prefix.'church_admin_follow_up WHERE funnel_id="'.(int)$funnel_id.'" AND people_id="'.(int)$people_id.'" AND member_type_id="'.(int)$member_type_id.'" AND assign_id="'.(int)$assign_id.'" AND assigned_date="'.esc_sql(date("Y-m-d")).'"');
4741 if(!$check)
4742 {
4743 $sql='INSERT INTO '.$wpdb->prefix.'church_admin_follow_up' .'(funnel_id,people_id,member_type_id,assign_id,assigned_date,completion_date)VALUES("'.(int)$funnel_id.'","'.(int)$people_id.'","'.(int)$member_type_id.'","'.(int)$assign_id.'","'.esc_sql(date("Y-m-d")).'","0000-00-00")';
4744 //church_admin_debug $sql);
4745 $wpdb->query( $sql);
4746 }
4747 //find name of funnel
4748 $funnel=$wpdb->get_var('SELECT action FROM '.$wpdb->prefix.'church_admin_funnels WHERE funnel_id="'.(int)$funnel_id.'"');
4749 //church_admin_debug $wpdb->last_query);
4750 $response=array('people_id'=>(int)$people_id );
4751 if(!empty( $funnel) ) {
4752 //translators: %1$s is a name
4753 $response['message']= esc_html(sprintf(__('Assigned to %1$s','church-admin' ) ,$funnel));
4754 }else{
4755 $response['message']=__('Oopsie','church-admin');
4756 }
4757 header('Access-Control-Max-Age: 1728000');
4758 header('Access-Control-Allow-Origin: *');
4759 header('Access-Control-Allow-Methods: *');
4760 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4761 header('Access-Control-Allow-Credentials: true');
4762 echo json_encode( $response);
4763 exit();
4764
4765 break;
4766 case 'app_menu_order':
4767 check_admin_referer('church_admin_app_menu_order','nonce');
4768 //church_admin_debug("Posted".print_r( $_REQUEST,TRUE) );
4769 if(!empty( $_POST['order'] ) )
4770 {
4771 $order=explode(",",church_admin_sanitize($_POST['order']) );
4772 $appMenu=get_option('church_admin_app_new_menu');
4773 foreach( $order AS $key=>$name)
4774 {
4775 //church_admin_debug("Handling $name and giving it order of $key");
4776 if(!empty( $appMenu[$name] ) )$appMenu[$name]['order']=(int)$key;
4777 }
4778 //church_admin_debugprint_r( $appMenu,TRUE) );
4779 update_option('church_admin_app_new_menu',$appMenu);
4780 }
4781 break;
4782 case 'update-oversight':
4783 check_admin_referer('update-oversight','nonce');
4784 //church_admin_debugprint_r( $_POST,TRUE) );
4785 //sanitize
4786 $name=!empty( $_POST['name'])?sanitize_text_field(stripslashes( $_POST['name'])):null;
4787 $people=!empty( $_POST['people'])?sanitize_text_field(stripslashes( $_POST['people'])):null;
4788 $cell_id = !empty( $_POST['cell_id'])?sanitize_text_field(stripslashes( $_POST['cell_id'])):null;
4789 //validate
4790 if(empty($name)){exit();}
4791 if(empty($cell_id)|| ! church_admin_int_check($cell_id)){exit();}
4792
4793
4794 if(!empty( $name ) ) {$wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_cell_structure SET name="'.esc_sql($name ).'" WHERE ID="'.(int)$cell_id.'"');}
4795 if(!empty( $people ) )
4796 {
4797 $wpdb->query('DELETE FROM '.$wpdb->prefix.'church_admin_people_meta WHERE meta_type="oversight" AND ID="'.(int)$cell_id.'"');
4798 $autocompleted=explode(',',$people );//string with entered names
4799
4800 foreach( $autocompleted AS $x=>$name)
4801 {
4802 $p_id=church_admin_get_one_id(trim( $name) );//get the people_id
4803
4804 if(!empty( $p_id) )
4805 {
4806 church_admin_update_people_meta((int)$cell_id,$p_id,'oversight');//update person as leader at that level
4807 }
4808 }
4809 }
4810
4811 break;
4812
4813 case 'remove-image':
4814 check_ajax_referer( 'remove-image', 'nonce' );
4815 $ID=!empty($_POST['id'])?sanitize_text_field(stripslashes($_POST['id'])):null;
4816 if(empty($ID))exit();
4817 switch( $_POST['type'] )
4818 {
4819 case'people':$wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET attachment_id=NULL WHERE people_id="'.(int)$ID.'"');break;
4820 case'household':$wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_household SET attachment_id=NULL WHERE household_id="'.(int)$ID.'"');break;
4821 }
4822 if(is_attachment($ID)){wp_delete_attachment($ID);}
4823 echo (int)$ID;
4824 exit();
4825 break;
4826 case 'show-person':
4827 check_ajax_referer( 'show-person', 'security' );
4828 require_once(plugin_dir_path( __FILE__) .'/display/address-list.php');
4829 $data= church_admin_people_data((int)$_POST['id'] );
4830 //church_admin_debugprint_r( $data,TRUE) );
4831
4832 //sanitize
4833 $map= !empty($_POST['map'])?sanitize_text_field(stripslashes($_POST['map'])):null;
4834 $updateable= !empty($_POST['updateable'])?sanitize_text_field(stripslashes($_POST['updateable'])):null;
4835 $photo = !empty($_POST['photo'])?sanitize_text_field(stripslashes($_POST['photo'])):null;
4836 $vcf = !empty($_POST['vcf'])?sanitize_text_field(stripslashes($_POST['vcf'])):null;
4837 $address_style= !empty($_POST['address_style'])?sanitize_text_field(stripslashes($_POST['address_style'])):null;
4838
4839 echo church_admin_formatted_household( $data,$map,$updateable,$photo,$vcf,$address_style );
4840 exit();
4841 break;
4842 case 'show-personv2':
4843 check_ajax_referer( 'show-person', 'security' );
4844 require_once(plugin_dir_path( __FILE__) .'/display/address-list.php');
4845 $data= church_admin_people_data((int)$_POST['id'] );
4846 //church_admin_debugprint_r( $data,TRUE) );
4847 header('Access-Control-Max-Age: 1728000');
4848 header('Access-Control-Allow-Origin: *');
4849 header('Access-Control-Allow-Methods: *');
4850 header('Access-Control-Allow-Headers: Content-MD5, X-Alt-Referer');
4851 header('Access-Control-Allow-Credentials: true');
4852 //sanitize
4853 $map= !empty($_POST['map'])?sanitize_text_field(stripslashes($_POST['map'])):null;
4854 $updateable= !empty($_POST['updateable'])?sanitize_text_field(stripslashes($_POST['updateable'])):null;
4855 $photo = !empty($_POST['photo'])?sanitize_text_field(stripslashes($_POST['photo'])):null;
4856 $vcf = !empty($_POST['vcf'])?sanitize_text_field(stripslashes($_POST['vcf'])):null;
4857
4858 $outputData=church_admin_formatted_household( data,$map,$updateable,$photo,$vcf,$address_style );
4859 echo json_encode(array('householdIndex'=>wp_kses_post($data['household_index']),'id'=>(int)$data['household_id'],'entry'=>wp_kses_post($outputData)) );
4860 exit();
4861 break;
4862 //podcast
4863 case "podcast-file"://checked
4864 check_ajax_referer( 'sermon-display', 'nonce' );
4865 require_once(plugin_dir_path( __FILE__) .'/display/sermon-podcast.php');
4866 //church_admin_debug('podcast file');
4867 $ID=!empty($_POST['id'])?sanitize_text_field(stripslashes($_POST['id'])):null;
4868 echo church_admin_podcast_file_detail((int)$ID,FALSE);
4869 exit();
4870 break;
4871 case 'dropdown'://checked
4872 check_ajax_referer( 'sermon-display', 'nonce' );
4873 if(defined('CA_DEBUG') )
4874 {
4875 //church_admin_debug('FUNCTION church_admin_podcast_files_list');
4876 //church_admin_debugprint_r( $_REQUEST,TRUE) );
4877 }
4878 require_once(plugin_dir_path( __FILE__) .'/display/sermon-podcast.php');
4879 $response=array();
4880 if(defined('CA_DEBUG') ) {
4881 //church_admin_debug('Calling church_admin_podcast_file_list');
4882 }
4883 //sanitize
4884 $series_id=!empty($_REQUEST['series_id']) ? sanitize_text_field( stripslashes( $_REQUEST['series_id'] ) ):null;
4885 $page=!empty($_REQUEST['page']) ? sanitize_text_field( stripslashes( $_REQUEST['page'] ) ):null;
4886 $limit=!empty($_REQUEST['limit']) ? sanitize_text_field( stripslashes( $_REQUEST['limit'] ) ):null;
4887 $speaker=!empty($_REQUEST['speaker']) ? sanitize_text_field( stripslashes( $_REQUEST['speaker'] ) ):null;
4888 $order =!empty($_REQUEST['order']) ? sanitize_text_field( stripslashes( $_REQUEST['order'] ) ):null;
4889
4890 $file_list=church_admin_podcast_files_list((int)$series_id,(int)$page,(int)$limit,esc_html( $speaker ),NULL,esc_html( $order ) );
4891 $series_detail='';
4892 if(!empty( $_REQUEST['series_id'] ) )$series_detail=church_admin_podcast_series_detail((int)$series_id,NULL);
4893
4894 $SQL=array();
4895 if(!empty( $series_id ) )
4896 {
4897 $SQL[]=' AND series_id="'.(int)$series_id.'"';
4898 }
4899 if(!empty( $_REQUEST['speaker'] ) )
4900 {
4901 $SQL[]=' AND speaker LIKE "%'.esc_sql( $speaker).'%"';
4902 }
4903 $first_sermon_id=$wpdb->get_var('SELECT file_id FROM '.$wpdb->prefix.'church_admin_sermon_files WHERE 2=2 '.implode(" ",$SQL).' ORDER BY pub_date '.esc_sql( $order ).' LIMIT 1');
4904 $first_sermon=church_admin_podcast_file_detail( $first_sermon_id,$exclude=NULL);
4905
4906 $outputArray=array('series_detail'=>$series_detail,'file_list'=>$file_list,'first_sermon'=>$first_sermon,'file_id'=>$first_sermon_id);
4907 if(defined('CA_DEBUG') )
4908 {
4909 //church_admin_debugprint_r( $outputArray,TRUE) );
4910
4911 }
4912 echo json_encode( $outputArray);
4913 exit();
4914 break;
4915 case 'series-dropdown':
4916 check_ajax_referer( 'sermon-display', 'nonce' );
4917 //checked
4918 require_once(plugin_dir_path( __FILE__) .'/display/sermon-podcast.php');
4919
4920 //sanitize
4921 $id =!empty($_REQUEST['id']) ? sanitize_text_field( stripslashes( $_REQUEST['id'] ) ):null;
4922 $page=!empty($_REQUEST['page']) ? sanitize_text_field( stripslashes( $_REQUEST['page'] ) ):null;
4923 $limit=!empty($_REQUEST['limit']) ? sanitize_text_field( stripslashes( $_REQUEST['limit'] ) ):null;
4924
4925 $response=array();
4926 $file_list=church_admin_podcast_files_list((int)$id,(int)$page,(int)$limit );
4927 $series_detail=church_admin_podcast_series_detail((int)$id,NULL);
4928 $first_sermon_id=$wpdb->get_var('SELECT file_id FROM '.$wpdb->prefix.'church_admin_sermon_files WHERE series_id="'.(int)$id.'" ORDER BY pub_date DESC LIMIT 1');
4929 $first_sermon=church_admin_podcast_file_detail( $first_sermon_id,$exclude=NULL);
4930 echo json_encode(array('series_detail'=>$series_detail,'file_list'=>$file_list,'first_sermon'=>$first_sermon,'file_id'=>$first_sermon_id) );
4931 exit();
4932 break;
4933 case 'speaker-dropdown'://checked
4934 check_ajax_referer( 'sermon-display', 'nonce' );
4935 $id =!empty($_REQUEST['id']) ? sanitize_text_field( stripslashes( $_REQUEST['id'] ) ):null;
4936 $page=!empty($_REQUEST['page']) ? sanitize_text_field( stripslashes( $_REQUEST['page'] ) ):null;
4937 $limit=!empty($_REQUEST['limit']) ? sanitize_text_field( stripslashes( $_REQUEST['limit'] ) ):null;
4938
4939 require_once(plugin_dir_path( __FILE__) .'/display/sermon-podcast.php');
4940 $response=array();
4941 $file_list=church_admin_podcast_files_list(NULL,(int)$page,(int)$limit,esc_html( $speaker ) );
4942 $series_detail=church_admin_podcast_series_detail(NULL,NULL);
4943 $first_sermon_id=$wpdb->get_var('SELECT file_id FROM '.$wpdb->prefix.'church_admin_sermon_files WHERE speaker LIKE"%'.esc_sql( $speaker ).'%" ORDER BY pub_date DESC LIMIT 1');
4944 $first_sermon=church_admin_podcast_file_detail( $first_sermon_id,$exclude=NULL);
4945 echo json_encode(array('series_detail'=>$series_detail,'file_list'=>$file_list,'first_sermon'=>$first_sermon,'file_id'=>$first_sermon_id) );
4946 exit();
4947 break;
4948 case 'latest-series-sermon':
4949 check_ajax_referer( 'sermon-display', 'nonce' );
4950 require_once(plugin_dir_path( __FILE__) .'/display/sermon-podcast.php');
4951
4952 echo church_admin_podcast_latest_sermon((int)$_REQUEST['id'] );
4953 exit();
4954 break;
4955 case 'more-sermons'://checked
4956 check_ajax_referer( 'sermon-display', 'nonce' );
4957 require_once(plugin_dir_path( __FILE__) .'/display/sermon-podcast.php');
4958 $series_id =!empty($_REQUEST['series_id']) ? sanitize_text_field( stripslashes( $_REQUEST['series_id'] ) ):null;
4959 $page=!empty($_REQUEST['page']) ? sanitize_text_field( stripslashes( $_REQUEST['page'] ) ):null;
4960 $limit=!empty($_REQUEST['limit']) ? sanitize_text_field( stripslashes( $_REQUEST['limit'] ) ):null;
4961 $sermon_search = !empty($_REQUEST['sermon-search']) ? sanitize_text_field( stripslashes( $_REQUEST['sermon-search'] ) ):null;
4962 $speaker = !empty($_REQUEST['speaker'])? church_admin_sanitize($_REQUEST['speaker']):null;
4963 echo church_admin_podcast_files_list(esc_attr($series_id),(int)$page,(int)$limit,esc_attr( $speaker ),$sermon_search );
4964 exit();
4965 break;
4966 case 'sermon-search'://checked
4967 check_ajax_referer( 'sermon-display', 'nonce' );
4968 $page=!empty($_REQUEST['page']) ? sanitize_text_field( stripslashes( $_REQUEST['page'] ) ):null;
4969 $limit=!empty($_REQUEST['limit']) ? sanitize_text_field( stripslashes( $_REQUEST['limit'] ) ):null;
4970 $sermon_search = !empty($_REQUEST['sermon-search']) ? sanitize_text_field( stripslashes( $_REQUEST['sermon-search'] ) ):null;
4971 require_once(plugin_dir_path( __FILE__) .'/display/sermon-podcast.php');
4972 echo church_admin_podcast_files_list((int)$series_id,(int)$page,(int)$limit,esc_html( $speaker ),$sermon_search );
4973 exit();
4974 break;
4975 case 'unattach_user'://checked
4976 check_ajax_referer( 'church_admin_unattach_user', 'nonce' );
4977 church_admin_unattach_user();
4978 break;
4979 case 'autocomplete'://checked
4980 check_ajax_referer( 'church-admin-autocomplete', 'security' );
4981 church_admin_ajax_people(TRUE);
4982 break;
4983 case 'mp3_plays'://checked
4984 church_admin_debug('Logging a play');
4985 church_admin_debug($_POST);
4986 //check_ajax_referer( 'church_admin_mp3_play', 'security' );
4987 church_admin_mp3_plays();
4988 break;
4989 case 'username_check'://checked
4990 check_ajax_referer( 'church_admin_username_check', 'nonce' );
4991 church_admin_username_check();
4992 break;
4993
4994 case 'filter'://checked
4995 require_once(plugin_dir_path( __FILE__) .'/includes/filter.php');
4996
4997 church_admin_filter_callback();
4998 break;
4999 case 'filter_email'://checked
5000 church_admin_debug('filter_email ajax fired');
5001 require_once(plugin_dir_path( __FILE__) .'/includes/filter.php');
5002
5003 church_admin_filter_email_callback();
5004 break;
5005 case 'people_activate'://checked
5006 check_ajax_referer( 'activate', 'nonce' );
5007 church_admin_people_activate_callback();
5008 break;
5009 case'note_delete':
5010 check_ajax_referer( 'note_delete', 'nonce' );
5011 church_admin_note_delete_callback();
5012 break;
5013 case 'calendar_date_display':
5014 church_admin_date();
5015 break;
5016
5017 case'connect_user':
5018 check_ajax_referer('connect_user','nonce',TRUE);
5019 if(church_admin_level_check('Directory') )
5020 {
5021 //church_admin_debugprint_r( $_POST,TRUE) );
5022 //sanitize
5023 $userID=!empty($_POST['user_id'])?sanitize_text_field(stripslashes($_POST['user_id'])):null;
5024 $people_id=!empty($_POST['people_id'])?sanitize_text_field(stripslashes($_POST['people_id'])):null;
5025 //validate
5026 if(empty($userID)){exit();}
5027 if(!church_admin_int_check($userID)){exit();}
5028 if(empty($people_id)){exit();}
5029 if(!church_admin_int_check($people_id)){exit();}
5030
5031
5032
5033 $ID=church_admin_user_id_exists( $userID );
5034 if( !empty( $ID) )
5035 {
5036 $sql='UPDATE '.$wpdb->prefix.'church_admin_people SET user_id="'.(int)$userID.'" WHERE people_id="'.(int)$people_id.'"';
5037 //church_admin_debug $sql);
5038 $wpdb->query( $sql);
5039 $user=get_userdata($userID );
5040 $response= json_encode(array('login'=>$user->user_login,'people_id'=>(int)$people_id ) );
5041 //church_admin_debug $response);
5042 echo $response;
5043 }
5044 }
5045 exit();
5046 break;
5047 case'create_user':
5048 check_ajax_referer('create_user','nonce',TRUE);
5049 //sanitize
5050
5051 $people_id=!empty($_POST['people_id'])?sanitize_text_field(stripslashes($_POST['people_id'])):null;
5052 //validate
5053 if(empty($people_id)){exit();}
5054 if(!church_admin_int_check($people_id)){exit();}
5055
5056
5057 if(church_admin_level_check('Directory') )
5058 {
5059
5060
5061
5062 $person=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE people_id="'.(int)$people_id.'"');
5063
5064 church_admin_create_user( $person->people_id,$person->household_id,null,null);
5065 $userID=$wpdb->get_var('SELECT user_id FROM '.$wpdb->prefix.'church_admin_people WHERE people_id="'.(int)$people_id.'"');
5066 $user= get_userdata( $userID);
5067 $response= json_encode(array('login'=>$user->user_login.' '.$out,'people_id'=>(int)$people_id ) );
5068 //church_admin_debug $response);
5069 echo $response;
5070
5071
5072
5073 }
5074 exit();
5075 break;
5076 case 'individual_attendance':
5077 //church_admin_debug('Individual attendance');
5078 check_ajax_referer('individual_attendance','nonce',TRUE);
5079 //sanitize
5080 $meeting_type=!empty($_REQUEST['meeting_type'])?sanitize_text_field(stripslashes($_REQUEST['meeting_type'])):null;
5081 $meeting_id = !empty($_REQUEST['meeting_id'])?sanitize_text_field(stripslashes($_REQUEST['meeting_id'])):null;
5082 $date = !empty($_REQUEST['date'])?sanitize_text_field(stripslashes($_REQUEST['date'])):null;
5083 //validate
5084 if(empty($meeting_type)){exit();}
5085 if(empty($meeting_id)||!church_admin_int_check($meeting_id)){exit();}
5086 if(empty($date)||!church_admin_checkdate($date)){exit();}
5087
5088 $sql='SELECT * FROM '.$wpdb->prefix.'church_admin_individual_attendance WHERE meeting_type="'.esc_sql( $meeting_type ).'" AND meeting_id="'.(int)$meeting_id.'" AND `date`="'.esc_sql( $date).'"';
5089 //church_admin_debug $sql);
5090 $results=$wpdb->get_results( $sql);
5091 //church_admin_debugprint_r( $results,TRUE) );
5092 $out=array();
5093 if(!empty( $results) )
5094 {
5095 foreach( $results AS $row)
5096 {
5097 $out[]='person-'.$row->people_id;
5098
5099 }
5100 //church_admin_debugprint_r( $out,TRUE) );
5101 echo json_encode( $out);
5102 }
5103 exit();
5104 break;
5105 case 'image_upload':
5106 check_ajax_referer('church_admin_image_upload','nonce',TRUE);
5107 // These files need to be included as dependencies when on the front end.
5108 require_once( ABSPATH . 'wp-admin/includes/image.php' );
5109 require_once( ABSPATH . 'wp-admin/includes/file.php' );
5110 require_once( ABSPATH . 'wp-admin/includes/media.php' );
5111 // Let WordPress handle the upload.
5112 // Remember, 'my_image_upload' is the name of our file input in our form above.
5113 $attachment_id = media_handle_upload( 'file-0', 0 );
5114 //church_admin_debug $attachment_id);
5115 if ( is_wp_error( $attachment_id ) ) {
5116 // There was an error uploading the image.
5117 } else {
5118 // The image was uploaded successfully!
5119 $image=wp_get_attachment_image_src( $attachment_id, "medium", false );
5120 //church_admin_debugprint_r( $image,TRUE) );
5121 echo json_encode(array('src'=>$image[0],'attachment_id'=>$attachment_id) );
5122 exit();
5123 }
5124 break;
5125 case 'household-upload':
5126 //church_admin_debug("*********************\r\n Household image upload");
5127 //church_admin_debugprint_r( $_POST,TRUE) );
5128 //church_admin_debugprint_r( $_FILES,TRUE) );
5129 check_ajax_referer('household-image-upload','nonce',TRUE);
5130 // These files need to be included as dependencies when on the front end.
5131 require_once( ABSPATH . 'wp-admin/includes/image.php' );
5132 require_once( ABSPATH . 'wp-admin/includes/file.php' );
5133 require_once( ABSPATH . 'wp-admin/includes/media.php' );
5134 // Let WordPress handle the upload.
5135 $attachment_id = media_handle_upload( 'userImage', 0 );
5136 //church_admin_debug("attachment id $attachment_id");
5137
5138 if ( is_wp_error( $attachment_id ) ) {
5139 // There was an error uploading the image.
5140 } else {
5141
5142 $id=!empty($_POST['id'])?sanitize_text_field(stripslashes($_POST['id'])):null;
5143 // The image was uploaded successfully!
5144 $image=wp_get_attachment_image_src( $attachment_id, "medium", false );
5145 //church_admin_debugprint_r( $image,TRUE) );
5146 if(!empty( $id ) )$wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_household SET attachment_id="'.(int)$attachment_id.'" WHERE household_id="'.(int)$id.'"');
5147 echo json_encode(array('src'=>$image[0],'attachment_id'=>$attachment_id,'div'=>'household-image','id'=>'attachment_id') );
5148 exit();
5149 }
5150 break;
5151 case 'smallgroup-upload':
5152 //church_admin_debug("*********************\r\n People image upload");
5153 //church_admin_debugprint_r( $_POST,TRUE) );
5154 //church_admin_debugprint_r( $_FILES,TRUE) );
5155
5156 check_ajax_referer('smallgroup-image-upload','nonce',TRUE);
5157 // These files need to be included as dependencies when on the front end.
5158 require_once( ABSPATH . 'wp-admin/includes/image.php' );
5159 require_once( ABSPATH . 'wp-admin/includes/file.php' );
5160 require_once( ABSPATH . 'wp-admin/includes/media.php' );
5161 // Let WordPress handle the upload.
5162 $attachment_id = media_handle_upload( 'userImage', 0 );
5163 //church_admin_debug("attachment id $attachment_id");
5164 if ( is_wp_error( $attachment_id ) ) {
5165 // There was an error uploading the image.
5166
5167 } else {
5168 $id=!empty($_POST['id'])?sanitize_text_field(stripslashes($_POST['id'])):null;
5169 // The image was uploaded successfully!
5170 $image=wp_get_attachment_image_src( $attachment_id, "medium", false );
5171 //church_admin_debugprint_r( $image,TRUE) );
5172 if(!empty( $id ) )$wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_smallgroup SET attachment_id="'.(int)$attachment_id.'" WHERE id="'.(int)$id.'"');
5173 echo json_encode(array('src'=>$image[0],'attachment_id'=>$attachment_id,'div'=>'smallgroup-image'.(int)$id,'id'=>'attachment_id') );
5174 exit();
5175 }
5176 break;
5177 case 'people-upload':
5178 //church_admin_debug("*********************\r\n People image upload");
5179 //church_admin_debugprint_r( $_POST,TRUE) );
5180 //church_admin_debugprint_r( $_FILES,TRUE) );
5181
5182 check_ajax_referer('people-image-upload','nonce',TRUE);
5183 // These files need to be included as dependencies when on the front end.
5184 require_once( ABSPATH . 'wp-admin/includes/image.php' );
5185 require_once( ABSPATH . 'wp-admin/includes/file.php' );
5186 require_once( ABSPATH . 'wp-admin/includes/media.php' );
5187 // Let WordPress handle the upload.
5188 $attachment_id = media_handle_upload( 'userImage', 0 );
5189 //church_admin_debug("attachment id $attachment_id");
5190 if ( is_wp_error( $attachment_id ) ) {
5191 // There was an error uploading the image.
5192
5193 } else {
5194 $id=!empty($_POST['id'])?sanitize_text_field(stripslashes($_POST['id'])):null;
5195 // The image was uploaded successfully!
5196 $image=wp_get_attachment_image_src( $attachment_id, "medium", false );
5197 //church_admin_debugprint_r( $image,TRUE) );
5198 if(!empty( $id ) )$wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_people SET attachment_id="'.(int)$attachment_id.'" WHERE people_id="'.(int)$id.'"');
5199 echo json_encode(array('src'=>$image[0],'attachment_id'=>$attachment_id,'div'=>'people-image'.(int)$id,'id'=>'attachment_id','people_id'=>(int)$id ) );
5200 exit();
5201 }
5202 break;
5203
5204 case 'series-upload':
5205 //church_admin_debug("*********************\r\n People image upload");
5206 //church_admin_debugprint_r( $_POST,TRUE) );
5207 //church_admin_debugprint_r( $_FILES,TRUE) );
5208
5209 check_ajax_referer('series-image-upload','nonce',TRUE);
5210 // These files need to be included as dependencies when on the front end.
5211 require_once( ABSPATH . 'wp-admin/includes/image.php' );
5212 require_once( ABSPATH . 'wp-admin/includes/file.php' );
5213 require_once( ABSPATH . 'wp-admin/includes/media.php' );
5214 // Let WordPress handle the upload.
5215 $attachment_id = media_handle_upload( 'userImage', 0 );
5216 //church_admin_debug("attachment id $attachment_id");
5217 if ( is_wp_error( $attachment_id ) ) {
5218 // There was an error uploading the image.
5219
5220 } else {
5221 // The image was uploaded successfully!
5222 $id=!empty($_POST['id'])?sanitize_text_field(stripslashes($_POST['id'])):null;
5223 $image=wp_get_attachment_image_src( $attachment_id, "medium", false );
5224 //church_admin_debugprint_r( $image,TRUE) );
5225 if(!empty( $id) )$wpdb->query('UPDATE '.$wpdb->prefix.'church_admin_sermon_series SET series_image="'.(int)$attachment_id.'" WHERE series_id="'.(int)$id.'"');
5226 echo json_encode(array('src'=>$image[0],'attachment_id'=>$attachment_id,'div'=>'series-image','id'=>'attachment_id') );
5227 exit();
5228 }
5229 break;
5230 case 'remove-app-logo':
5231 check_ajax_referer('remove-app-logo','nonce',TRUE);
5232 delete_option('church_admin_app_logo');
5233 echo TRUE;
5234 exit();
5235 break;
5236 case 'update-app-logo':
5237 check_ajax_referer('update-app-logo','nonce',TRUE);
5238 $logo= !empty($_POST['logo'])?sanitize_text_field(stripslashes($_POST['logo'])):null;
5239 if(!empty($logo)){update_option('church_admin_app_logo',$logo ) ;}
5240 echo TRUE;
5241 exit();
5242 break;
5243 case 'category_list':
5244 //filter count
5245 check_ajax_referer('church_admin_filter','nonce',TRUE);
5246 require_once(plugin_dir_path( __FILE__) .'/includes/filter.php');
5247 echo church_admin_filter_count(null);
5248 exit();
5249 break;
5250
5251
5252 }
5253
5254
5255
5256 }
5257
5258 add_action('init','church_admin_receive_prayer');
5259
5260 function church_admin_receive_prayer()
5261 {
5262 //handle front end prayer request which needs to happen later than plugins_loaded action
5263 global $church_admin_prayer_request_success;
5264 if(!empty( $_POST['save_prayer_request'] )&&!empty( $_POST['non_spammer'] )&&wp_verify_nonce( $_POST['non_spammer'],'prayer-request') )
5265 {
5266 if(is_user_logged_in()){
5267 $user=wp_get_current_user();
5268 $ID=$user->ID;
5269 }
5270 if(empty($ID))$ID=1;
5271 //church_admin_debug("**** church_admin_receive_prayer ****");
5272 //church_admin_debug('$_POST ');
5273 //church_admin_debug($_POST);
5274 $post_content=sanitize_textarea_field( stripslashes($_POST['request_content'] ));
5275 $post_title=wp_strip_all_tags( stripslashes($_POST['request_title'] ));
5276 $post_type='prayer-requests';
5277 $args=array(
5278 'post_author'=>(int)$ID,
5279 'post_content'=>$post_content,
5280 'post_title'=>$post_title,
5281 'post_status'=>'draft',
5282 'post_type'=>$post_type
5283 );
5284
5285 if(church_admin_level_check('Prayer') ) {$args['post_status']='publish';}
5286 //post_exists not available in front end, so check and require post.php if needed
5287 if ( ! function_exists( 'post_exists' ) ) {
5288 require_once( ABSPATH . 'wp-admin/includes/post.php' );
5289 }
5290 //church_admin_debug('Args for insert_post');
5291 //church_admin_debug($args);
5292 if(post_exists( $post_title, $post_content, '', $post_type, '' ) )return;
5293 $postid = wp_insert_post( $args);
5294
5295 if( $postid)
5296 {
5297 //church_admin_debug('Post inserted');
5298 //the post is valid
5299 $church_admin_prayer_request_success='<div class="notice notice-success">';
5300 if( $args['post_status']=='publish') {
5301 $church_admin_prayer_request_success.=__('Your prayer-request has been published','church-admin');
5302 //church_admin_debug('Post status - publish');
5303 }
5304 else
5305 {
5306 //church_admin_debug('Post status - draft');
5307 $church_admin_prayer_request_success.=__('Your prayer-request has been put in the moderation queue','church-admin');
5308 $message='<p>'.esc_html( __('New prayer request draft for moderation','church-admin' ) ).'</p><p><a href="'.admin_url().'?edit.php?post_type=prayer-requests">'.esc_html( __('View prayer requests','church-admin' ) ).'</a>';
5309 $prm= get_option('prayer-request-moderation');
5310
5311 if(empty( $prm) )$prm=get_option('church_admin_default_from_email');
5312
5313
5314 church_admin_email_send($prm,esc_html(__('Prayer Request Draft','church-admin' ) ),esc_html(__('A draft prayer request has been posted. Please moderate','church-admin') ),null,null,null,null,null,TRUE);
5315 /*
5316 //church_admin_debug('Email to be sent to :'.$prm);
5317 add_filter( 'wp_mail_from_name','church_admin_from_name' );
5318 add_filter( 'wp_mail_from', 'church_admin_from_email');
5319 add_filter('wp_mail_content_type','church_admin_email_type');
5320
5321 if(wp_mail( $prm,esc_html(__('Prayer Request Draft','church-admin' ) ),esc_html(__('A draft prayer request has been posted. Please moderate','church-admin') )))
5322 {
5323 //church_admin_debug('Email sent');
5324 }
5325
5326 //church_admin_debug print_r( $GLOBALS['phpmailer'] ,TRUE));
5327 remove_filter('wp_mail_content_type','church_admin_email_type');
5328 remove_filter( 'wp_mail_from_name','church_admin_from_name' );
5329 remove_filter( 'wp_mail_from', 'church_admin_from_email');
5330 */
5331
5332 /*****************************************
5333 * push to admins if required!
5334 *
5335 * ***************************************/
5336 $prayer_request_people_ids=get_option('church_admin_prayer_request_receive_push_to_admin');
5337 //church_admin_debug('Attempting to push prayer request moderation');
5338 //church_admin_debugprint_r( $prayer_request_people_ids,TRUE) );
5339 $licence = get_option('church_admin_app_new_licence');;
5340 if(!empty( $prayer_request_people_ids)&&!empty( $licence) )
5341 {
5342 $pushTokens=church_admin_get_push_tokens_from_ids( $prayer_request_people_ids);
5343 //church_admin_debug('Push tokens');
5344 //church_admin_debugprint_r( $pushTokens,TRUE) );
5345 if(!empty( $pushTokens) )
5346 {
5347 require_once( plugin_dir_path( __FILE__ ).'includes/push.php');
5348
5349 $dataMessage=$message= esc_html( __('Please moderate a new prayer request','church-admin') );
5350 //$dataMessage=$message.'<p><a href="'.admin_url().'edit.php?post_type=prayer-requests">'.esc_html( __('View prayer requests','church-admin' ) ).'</a>';
5351
5352 //church_admin_debug('Data Message variable: ' . $dataMessage);
5353 church_admin_filtered_push( $message,$pushTokens,esc_html( __('Prayer Request Moderation','church-admin') ),$dataMessage,'prayer',NULL);
5354
5355 }
5356
5357
5358 }
5359
5360 }
5361 $church_admin_prayer_request_success.='</div>';
5362 }
5363 }
5364 }
5365
5366
5367
5368
5369
5370 add_action('init','church_admin_acts_courage');
5371
5372 function church_admin_acts_courage()
5373 {
5374 //handle front end prayer request which needs to happen later than plugins_loaded action
5375 global $church_admin_acts_success;
5376 if(!empty( $_POST['save_act_of_courage_request'] )&&!empty( $_POST['non_spammer'] )&&wp_verify_nonce( $_POST['non_spammer'],'acts-of-courage') )
5377 {
5378
5379 $args=array(
5380 'post_content'=>sanitize_textarea_field( stripslashes($_POST['request_content'] ) ),
5381 'post_title'=>wp_strip_all_tags( stripslashes($_POST['request_title'] ) ),
5382 'post_status'=>'draft',
5383 'post_type'=>'acts-of-courage'
5384 );
5385 if(church_admin_level_check('Prayer') ) {$args['post_status']='publish';}
5386
5387
5388 $postid = wp_insert_post( $args);
5389
5390 if( $postid)
5391 {
5392
5393 //the post is valid
5394 $church_admin_acts_success='<div class="notice notice-success">';
5395 if( $args['post_status']=='publish') {
5396 $church_admin_acts_success.=esc_html( __('Your act of courage has been published','church-admin') );
5397 }
5398 else
5399 {
5400 $church_admin_acts_success.=esc_html( __('Your act of courage has been put in the moderation queue','church-admin') );
5401 $message='<p>'.esc_html( __('New act of courage draft for moderation','church-admin') ).'</p>';
5402 //wp_mail(get_option('church_admin_default_from_email'),esc_html( __('New act of courage draft for moderation','church-admin') ) ,$message);
5403 church_admin_email_send(get_option('church_admin_default_from_email'),esc_html( __('New act of courage draft for moderation','church-admin') ),$message,null,null,null,null,null,TRUE);
5404 }
5405 $church_admin_acts_success.='</div>';
5406 }
5407 }
5408 }
5409
5410 /**
5411 * Redirect user after successful login.
5412 *
5413 * @param string $redirect_to URL to redirect to.
5414 * @param string $request URL the user is coming from.
5415 * @param object $user Logged user's data.
5416 * @return string
5417 */
5418
5419 function church_admin_login_redirect( $redirect_to, $request, $user ) {
5420 $check=get_option('church_admin_login_redirect');
5421 if( $check && isset( $user->roles) && is_array( $user->roles) ) {
5422 //check for subscribers
5423 if (in_array('subscriber', $user->roles) ) {
5424 // redirect them to another URL, in this case, the homepage
5425 $redirect_to = $check;
5426 }
5427 }
5428
5429 return $redirect_to;
5430 }
5431
5432 add_filter( 'login_redirect', 'church_admin_login_redirect', 10, 3 );
5433
5434
5435
5436 add_action( 'save_post', 'church_admin_sermon_check', 10,3 );
5437 function church_admin_sermon_check( $post_id, $post, $update)
5438 {
5439 if(strpos( $post->post_content,'[church_admin') !== false && strpos( $post->post_content,'podcast') !== false)
5440 {
5441
5442 update_option('church_admin_sermon_page',$post_id);
5443
5444 }
5445 }
5446
5447 function church_admin_find_sermon_page()
5448 {
5449 /*
5450 global $wpdb;
5451 $result=$wpdb->get_var('SELECT ID FROM '.$wpdb->posts.' WHERE post_content LIKE "%[church_admin%" AND post_content LIKE"%podcast%" AND post_status="publish" LIMIT 1');
5452 if( $result)
5453 {
5454 $link=get_permalink( $result);
5455
5456 return $link;
5457 }
5458 */
5459 $sermonPageID=get_option('church-admin-sermon-page');
5460 if(!empty( $sermonPageID) ) {return get_permalink( $sermonPageID);}
5461 else return get_permalink();
5462
5463 }
5464
5465 function church_admin_cpanel_fix()
5466 {
5467 //church_admin_debug("Cpanel fix");
5468 //look in CA_PATH
5469 function church_admin_remover( $path)
5470 {
5471 if (is_dir( $path) )
5472 {
5473 if ( $dh = opendir( $path) )
5474 {
5475 while (( $file = readdir( $dh) ) !== false)
5476 {
5477 if( $file==".ea-php-cli.cache")
5478 {
5479 unlink( $path.$file);
5480 //church_admin_debug(" .ea-php-cli.cache deleted from ".$path);
5481 }
5482 }
5483 closedir( $dh);
5484 }
5485 }
5486 }
5487 church_admin_remover(CA_PATH);
5488 church_admin_remover(CA_PATH.'/display/');
5489 church_admin_remover(CA_PATH.'/includes/');
5490 church_admin_remover(CA_PATH.'/app/');
5491 church_admin_remover(CA_PATH.'/gutenberg/');
5492 church_admin_remover(CA_PATH.'/css/');
5493
5494
5495 }
5496
5497 /*************************************************************
5498 *
5499 * Add column for custom button to the app-content post type
5500 *
5501 *************************************************************/
5502 // Add the custom columns to the book post type:
5503 add_filter( 'manage_app-content_posts_columns', 'church_admin_custom_app_content_columns' );
5504 function church_admin_custom_app_content_columns( $columns) {
5505 unset( $columns['date'] );
5506 $columns['mybutton'] = __( 'App button code', 'church-admin' );
5507 $columns['date'] =__('Date','church-admin');
5508 return $columns;
5509 }
5510
5511 // Add the data to the custom columns for the book post type:
5512 add_action( 'manage_app-content_posts_custom_column' , 'church_admin_custom_app_content_column', 10, 2 );
5513 function church_admin_custom_app_content_column( $column, $post_id ) {
5514
5515 switch ( $column ) {
5516
5517 case 'mybutton' :
5518 echo esc_html('<button id="myButton" class="button red" data-page="'.sanitize_title(get_the_title( $post_id) ).'">'.get_the_title( $post_id).'</button>');
5519 break;
5520 }
5521 }
5522
5523 /*************************************************************
5524 *
5525 * Add don't send push notification for this post meta box
5526 *
5527 *************************************************************/
5528
5529 function church_admin_add_custom_box()
5530 {
5531 $screens = ['post'];
5532 foreach ( $screens as $screen) {
5533 add_meta_box(
5534 'church_admin_no_push', // Unique ID
5535 'Church Admin Post Settings', // Box title
5536 'church_admin_custom_box_html', // Content callback, must be of type callable
5537 $screen // Post type
5538 );
5539 }
5540 }
5541 add_action('add_meta_boxes', 'church_admin_add_custom_box');
5542
5543 function church_admin_custom_box_html( $post)
5544 {
5545 ?>
5546 <label for="church_admin_field">Don't send a push notification when this post is published</label>
5547 <input type="checkbox" name="church_admin_no_push" id="church_admin_field" value=1/>
5548
5549 <?php
5550 }
5551
5552
5553
5554 function church_admin_create_directories()
5555 {
5556 //use native WordPress functions to check and create directories 2020-09-30
5557
5558 $upload_dir = wp_upload_dir();
5559 $church_admin_sermon_dir=$upload_dir['basedir'].'/sermons/';
5560 wp_mkdir_p( $church_admin_sermon_dir);
5561 $index="<?php\r\n//nothing is good;\r\n?>";
5562 if(is_dir( $church_admin_sermon_dir) )
5563 {
5564 $church_admin_fp = fopen( $church_admin_sermon_dir.'index.php', 'w');
5565 if($church_admin_fp){
5566 fwrite( $church_admin_fp, $index);
5567 fclose( $church_admin_fp);
5568 }
5569
5570 }
5571 $church_admin_cache_dir=$upload_dir['basedir'].'/church-admin-cache/';
5572 wp_mkdir_p( $church_admin_cache_dir);
5573 if(is_dir( $church_admin_sermon_dir) )
5574 {
5575 $church_admin_fp = fopen( $church_admin_cache_dir.'index.php', 'w');
5576 if($church_admin_fp){
5577 fwrite( $church_admin_fp, $index);
5578 fclose( $church_admin_fp);
5579 }
5580
5581 }
5582 }
5583
5584
5585 /**
5586 * Adds a privacy policy statement.
5587 */
5588 function church_admin_add_privacy_policy_content() {
5589 if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
5590 return;
5591 }
5592 $content = '<p class="privacy-policy-tutorial">' . __( 'The Church Admin plugin handles a fair of amount personal data within the website in a secure way. ', 'church-admin' ) . '</p>'
5593
5594 . '<h3>'.esc_html( __('Registration','church-admin' ) ).'</h3>'
5595 .'<p>'.esc_html( __('When you register on this website, your information is stored in our database and viewable by the church admin team. You can set your own privacy settings to restrict who can see what and if and how you are communicated with.','church-admin'))
5596 .'<h3>'.esc_html( __('Address list','church-admin' ) ).'</h3>'
5597 .'<p>'.esc_html( __('The church has an address list which is visible to logged in users of the website. You can opt whether or not your personal data appears on the address list.','church-admin' ) ).'</p>'
5598 .'<h3>'.esc_html( __('Schedules','church-admin' ) ).'</h3>'
5599 .'<p>'.esc_html( __('The church organises who is doing what and when for our services in schedules. You can opt to recieve email, SMS and push notifications of your involvement. The schedule is also visible to other logged in users of the site, showing only names and what jobs and when.','church-admin'))
5600 .'<h3>'.esc_html( __('Communications','church-admin' ) ).'</h3>'
5601 .'<p>'.esc_html( __('Logged in users can set the communications settings for their household. You can opt to receive or not receive phone calls, SMS, email and mail letters.','church-admin'))
5602 .'<h3>'.esc_html( __('Donations','church-admin' ) ).'</h3>'
5603 .'<p>'.esc_html( __('If you make a donation using PayPal on the website, the donation details are stored in the database and viewable by the admin team','church-admin. UK churches will use your name, address and donation amount to make a Gift Aid claim if you have opted for Gift Aid claims.','church-admin'))
5604 .'<h3>'.esc_html( __('Classes and events','church-admin' ) ).'</h3>'
5605 .'<p>'.esc_html( __('If you book a place for a class or event your personal data will be stored for that booking to allow event checkin and attendance records.','church-admin'))
5606 .'<h3>'.esc_html( __('MailChimp (if used)','church-admin' ) ).'</h3>'
5607 .'<p>'.esc_html( __('This site uses MailChimp as its email sending partner. To send email, first name, last name, email and which member level, gender, small groups and classes is stored on their database to allow the correct emails to be sent.','church-admin'))
5608 .'<h3>'.esc_html( __('Google (if api key is set','church-admin'))
5609 .'<p>'.esc_html( __('To allow map pins on mapping on the website, latitude and longitude of addresses are used by mapping on site'))
5610 .'<h3>'.esc_html( __('Right to be forgotten','church-admin'))
5611 .'<p>'.esc_html( __('If you are logged in user, you can completely delete all your household information','church-admin'));
5612
5613
5614 wp_add_privacy_policy_content( 'Church Admin Plugin', wp_kses_post( wpautop( $content, false ) ) );
5615 }
5616
5617 add_action( 'admin_init', 'church_admin_add_privacy_policy_content' );
5618
5619
5620 /********************
5621 * AUTOMATIONS
5622 *********************/
5623 add_action('church_admin_followup_email','church_admin_followup_email',1,2);
5624 function church_admin_followup_email()
5625 {
5626 church_admin_debug('*** church_admin_followup_email ****');
5627 global $wpdb;
5628 $followup_template = get_option('church_admin_followup_email_template');
5629 $from_name = !empty($followup_template['from_name'])? $followup_template['from_name']:get_option('church_admin_default_from_name');;
5630 $from_email = !empty($followup_template['from_email'])? $followup_template['from_email']:get_option('church_admin_default_from_email');
5631 $days_ago = wp_date('Y-m-d',strtotime($followup_template['days'].' days ago'));
5632 //church_admin_debug('Looking for first registered '.$days_ago);
5633 $households = $wpdb->get_results('SELECT a.*,b.* FROM '.$wpdb->prefix.'church_admin_household a, '.$wpdb->prefix.'church_admin_people b WHERE a.household_id=b.household_id AND b.head_of_household=1 AND b.email_send=1 AND b.first_registered="'.esc_sql($days_ago).'" AND b.gdpr_reason IS NULL AND b.user_id IS NULL');
5634 church_admin_debug($wpdb->last_query);
5635 if(empty($households)){return;}
5636 church_admin_debug('New households found');
5637 foreach($households AS $household){
5638 $check=$wpdb->get_var('SELECT meta_date FROM '.$wpdb->prefix.'church_admin_people_meta WHERE people_id="'.(int)$household->people_id.'" AND meta_type="confirmation_reminder"');
5639 if(!empty($check)){
5640 //translators: %1$s is a name, %2$s is a date
5641 church_admin_debug(sprintf('Reminder sent to %1$s on %2$s',church_admin_formatted_name($household),$check));
5642 continue;
5643 }
5644 $name = church_admin_formatted_name($household);
5645 $email = $household->email;
5646 if(empty($email)){continue;}
5647
5648 $message = $followup_template['message'];
5649 $message = str_replace('[NOT_CONFIRMED]',' <a href="'.home_url().'?confirm_email='.md5( $household->email).'&amp;people_id='.md5( $household->people_id).'">'.esc_html( __( 'Please click to confirm your email','church-admin') ).'</a>',$message);
5650
5651 $message = str_replace('[CHURCH_URL]',make_clickable(site_url()),$message);
5652 $send_message = str_replace('[NAME]',$name,$message);
5653 church_admin_email_send($email,$followup_template['subject'],$send_message,$from_name,$from_email,null,null,null,FALSE);
5654 }
5655
5656 }
5657 /***********************************
5658 * TEST BIRTHDAY/ANNIVERSARY EMAIL
5659 ***********************************/
5660 function church_admin_send_test_automation_email()
5661 {
5662 global $wpdb,$church_admin_url;
5663 $people_types=get_option('church_admin_people_type');
5664 if(!empty($_POST['save']))
5665 {
5666
5667
5668 $email=!empty($_POST['test-email'])? church_admin_sanitize($_POST['test-email']):null;
5669 if(empty($email)){
5670 echo'<div class="notice notice-succes"><h2>'.esc_html(__('No test email ','church-admin')).'</h2></div>';
5671 return;
5672 }
5673 $which =!empty($_POST['which-automation'])? church_admin_sanitize($_POST['which-automation']):null;
5674 if(empty($which)){
5675 echo'<div class="notice notice-succes"><h2>'.esc_html(__('No automation specified','church-admin')).'</h2></div>';
5676 return;
5677
5678 }
5679 $tableStyle='style="font-family: Arial;font-size:1em; border-collapse: collapse;margin-bottom:10px"';
5680 $thStyle = 'style="border: 1px solid #ddd;padding: 12px; text-align: left; background-color: #CCC;color: white;" ';
5681 $tdStyle = 'style="border: 1px solid #ddd;padding: 8px;"';
5682 switch($which){
5683
5684 case 'happy-birthday':
5685 $stored_message = get_option('church_admin_happy_birthday_template');
5686 //church_admin_debug($stored_message);
5687 if(empty($stored_message)){
5688 echo'<div class="notice notice-succes"><h2>'.esc_html(__('No template setup ','church-admin')).'</h2></div>';
5689 return;
5690
5691 }
5692 $message = $stored_message['message'];
5693 $subject = $stored_message['subject'];
5694 $from_name = !empty($stored_message['from_name'])?$stored_message['from_name']:get_option('church_admin_default_from_name');;
5695 $from_email = !empty($stored_message['from_email'])?$stored_message['from_email']:get_option('church_admin_default_from_email');
5696 $reply_name = !empty($stored_message['reply_name'])?$stored_message['reply_name']:get_option('church_admin_default_from_name');;
5697 $reply_email = !empty($stored_message['reply_email'])?$stored_message['reply_email']:get_option('church_admin_default_from_email');
5698 $subject = str_replace('[first_name]','John',$subject);
5699 $subject = str_replace('[last_name]','Doe',$subject);
5700
5701
5702 $send_message = str_replace('[date]',wp_date(get_option('date_format')),$message);
5703 $send_message = str_replace('[first_name]','John',$send_message);
5704 $send_message = str_replace('[last_name]','Doe',$send_message);
5705 $send_message = str_replace('[email]','john@doe.com',$send_message);
5706 $send_message = str_replace('[cell]','<a href="'.esc_url('tel:0123456789').'">0123456789</a>',$send_message);
5707
5708 $birthyear = '1970';
5709 $currentyear = date("Y");
5710 $age = $currentyear - $birthyear;
5711 $send_message = str_replace('[age]',$age,$send_message);
5712 break;
5713
5714 case 'global-birthday':
5715 $message = get_option('church_admin_global_birthday_template');
5716 //church_admin_debug($message);
5717 if(empty($message)){
5718 echo'<div class="notice notice-succes"><h2>'.esc_html(__('No template setup ','church-admin')).'</h2></div>';
5719 return;
5720
5721 }
5722 $subject = $message['subject'];
5723 $from_name = !empty( $message['from_name'] )? $message['from_name'] : get_option('church_admin_default_from_name');
5724 $from_email = !empty( $message['from_email'] )? $message['from_email'] : get_option('church_admin_default_from_email');
5725
5726 $reply_name = !empty( $message['reply_name'] )? $message['reply_name'] : get_option('church_admin_default_from_name');
5727 $reply_email = !empty( $message['reply_email'] )? $message['reply_email'] : get_option('church_admin_default_from_email');
5728
5729
5730
5731
5732 $birthdaysTable='<table '.$tableStyle.'><thead><tr><th '.$thStyle.'>'.esc_html(__('Name','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Adult/Child','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Email','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Cell','church-admin')).'</th></tr></thead><tbody>';
5733 $birthdaysTable.='<tr><td '.$tdStyle.'>John Doe</td><td '.$tdStyle.'>'.esc_html($people_types[1]).'</td><td '.$tdStyle.'>'.make_clickable('john@doe.com').'</td><td '.$tdStyle.'><a href="'.esc_url('tel:0123456789').'">0123456789</a></td></tr>';
5734 $birthdaysTable.='<tr><td '.$tdStyle.'>Jane Doe</td><td '.$tdStyle.'>'.esc_html($people_types[2]).'</td><td '.$tdStyle.'>'.make_clickable('jane@doe.com').'</td><td '.$tdStyle.'><a href="'.esc_url('tel:0987654321').'">0123456789</a></td></tr>';
5735
5736 $birthdaysTable.='</tbody></table>';
5737 $send_message = str_replace('[birthdays]',$birthdaysTable,wpautop($message['message']));
5738 $send_message = str_replace('[date]',wp_date(get_option('date_format')),$send_message);
5739 break;
5740
5741 case 'happy-anniversary':
5742
5743 $message = get_option('church_admin_happy_anniversary_template');
5744 //church_admin_debug($message);
5745 if(empty($message)){
5746 echo'<div class="notice notice-succes"><h2>'.esc_html(__('No template setup ','church-admin')).'</h2></div>';
5747 return;
5748
5749 }
5750 $subject = $message['subject'];
5751 $send_message = $message['message'];
5752 $from_name = !empty($message['from_name'])?$message['from_name'] : get_option('church_admin_default_from_name');
5753 $from_email = !empty($message['from_email'])?$message['from_email'] : get_option('church_admin_default_from_email');
5754 $reply_name = !empty($message['reply_name'])?$message['reply_name'] : get_option('church_admin_default_from_name');
5755 $reply_email = !empty($message['reply_email'])?$message['reply_email']:get_option('church_admin_default_from_email');
5756
5757
5758 $subject = str_replace('[couple_name]','John & Jane Doe',$subject);
5759 $subject = str_replace('[couple_names]','John & Jane Doe',$subject);
5760 //sort message shortcode
5761 $send_message = str_replace('[date]',wp_date(get_option('date_format')),$send_message);
5762 $send_message = str_replace('[couple_names]','John & Jane Doe',$send_message);
5763 $send_message = str_replace('[couple_name]','John & Jane Doe',$send_message);
5764 $send_message = str_replace('[email]','john@doe.com',$send_message);
5765 $send_message = str_replace('[cell]','<a href="'.esc_url('tel:0123456789').'">0123456789</a>',$send_message);
5766 $send_message = str_replace('[years]',20,$send_message);
5767 break;
5768
5769 case 'global-anniversary':
5770 $message = get_option('church_admin_global_anniversary_template');
5771 //church_admin_debug($message);
5772 if(empty($message)){
5773 echo'<div class="notice notice-succes"><h2>'.esc_html(__('No template setup ','church-admin')).'</h2></div>';
5774 return;
5775
5776 }
5777 $subject = $message['subject'];
5778 $send_message = wpautop($message['message']);
5779 $from_name = !empty($message['from_name'])?$message['from_name'] : get_option('church_admin_default_from_name');
5780 $from_email = !empty($message['from_email'])?$message['from_email'] : get_option('church_admin_default_from_email');
5781 $reply_name = !empty( $message['reply_name'] )? $message['reply_name'] : get_option('church_admin_default_from_name');
5782 $reply_email = !empty( $message['reply_email'] )? $message['reply_email'] : get_option('church_admin_default_from_email');
5783
5784
5785 $anniversaryTable='<table '.$tableStyle.'><thead><tr><th '.$thStyle.'>'.esc_html(__('Name','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Email','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Cell','church-admin')).'</th></tr></thead><tbody>'."\r\n";
5786 $anniversaryTable.='<tr><td '.$tdStyle.'>John & Jane Doe</td><<td '.$tdStyle.'>'.make_clickable('john@doe.com').'</td><td '.$tdStyle.'><a href="'.esc_url('tel:0987654321').'">0123456789</a></td></tr>'."\r\n";
5787 $anniversaryTable.='<tr><td '.$tdStyle.'>Fred & Sally Smith</td><td '.$tdStyle.'>'.make_clickable('fred@smith.com').'</td><td '.$tdStyle.'><a href="'.esc_url('tel:01357924680').'">01357924680</a></td></tr>'."\r\n";
5788 $anniversaryTable.='</tbody></table>'."\r\n";
5789 $send_message = str_replace('[anniversaries]',$anniversaryTable,$send_message);
5790 break;
5791 case 'global-both':
5792 $message = get_option('church_admin_global_both_template');
5793 //church_admin_debug($message);
5794 if(empty($message)){
5795 echo'<div class="notice notice-succes"><h2>'.esc_html(__('No template setup ','church-admin')).'</h2></div>';
5796 return;
5797
5798 }
5799 $subject = $message['subject'];
5800 $from_name = !empty($message['from_name'])?$message['from_name'] : get_option('church_admin_default_from_name');
5801 $from_email = !empty($message['from_email'])?$message['from_email'] : get_option('church_admin_default_from_email');
5802
5803 $reply_name = !empty( $message['reply_name'] )? $message['reply_name'] : get_option('church_admin_default_from_name');
5804 $reply_email = !empty( $message['reply_email'] )? $message['reply_email'] : get_option('church_admin_default_from_email');
5805
5806
5807 $send_message = wpautop($message['message']);
5808
5809 $birthdaysTable='<table '.$tableStyle.'><thead><tr><th '.$thStyle.'>'.esc_html(__('Name','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Adult/Child','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Email','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Cell','church-admin')).'</th></tr></thead><tbody>';
5810 $birthdaysTable.='<tr><td '.$tdStyle.'>John Doe</td><td '.$tdStyle.'>'.esc_html(__('Adult','church-admin')).'</td><td '.$tdStyle.'>'.make_clickable('john@doe.com').'</td><td '.$tdStyle.'><a href="'.esc_url('tel:0123456789').'">0123456789</a></td></tr>';
5811 $birthdaysTable.='<tr><td '.$tdStyle.'>Jane Doe</td><td '.$tdStyle.'>'.esc_html(__('Adult','church-admin')).'</td><td '.$tdStyle.'>'.make_clickable('jane@doe.com').'</td><td '.$tdStyle.'><a href="'.esc_url('tel:0987654321').'">0123456789</a></td></tr>';
5812 $birthdaysTable.='</tbody></table>';
5813 $anniversaryTable='<table '.$tableStyle.'><thead><tr><th '.$thStyle.'>'.esc_html(__('Name','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Email','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Cell','church-admin')).'</th></tr></thead><tbody>'."\r\n";
5814 $anniversaryTable.='<tr><td '.$tdStyle.'>John & Jane Doe</td><td '.$tdStyle.'>'.make_clickable('john@doe.com').'</td><td '.$tdStyle.'><a href="'.esc_url('tel:0987654321').'">0123456789</a></td></tr>'."\r\n";
5815 $anniversaryTable.='<tr><td '.$tdStyle.'>Fred & Sally Smith</td><td '.$tdStyle.'>'.make_clickable('fred@smith.com').'</td><td '.$tdStyle.'><a href="'.esc_url('tel:01357924680').'">01357924680</a></td></tr>'."\r\n";
5816 $anniversaryTable.='</tbody></table>'."\r\n";
5817
5818 /**********************************
5819 * Build message
5820 ***********************************/
5821 $send_message = $message['message'];
5822
5823
5824 //birthday_text
5825 $tag = 'birthday_text';
5826 $regex = '\\[' // Opening bracket.
5827 . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]].
5828 . "($tag)" // 2: Shortcode name.
5829 . '(?![\\w-])' // Not followed by word character or hyphen.
5830 . '(' // 3: Unroll the loop: Inside the opening shortcode tag.
5831 . '[^\\]\\/]*' // Not a closing bracket or forward slash.
5832 . '(?:'
5833 . '\\/(?!\\])' // A forward slash not followed by a closing bracket.
5834 . '[^\\]\\/]*' // Not a closing bracket or forward slash.
5835 . ')*?'
5836 . ')'
5837 . '(?:'
5838 . '(\\/)' // 4: Self closing tag...
5839 . '\\]' // ...and closing bracket.
5840 . '|'
5841 . '\\]' // Closing bracket.
5842 . '(?:'
5843 . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags.
5844 . '[^\\[]*+' // Not an opening bracket.
5845 . '(?:'
5846 . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag.
5847 . '[^\\[]*+' // Not an opening bracket.
5848 . ')*+'
5849 . ')'
5850 . '\\[\\/\\2\\]' // Closing shortcode tag.
5851 . ')?'
5852 . ')'
5853 . '(\\]?)';
5854
5855
5856 preg_match_all( '/'. $regex .'/s',$send_message, $matches );
5857
5858
5859 if(!empty($birthdaysTable)){
5860 // replace [birthday_text] and [birthdays]
5861 $send_message = str_replace($matches[0],$matches[5][0],$send_message);
5862 $send_message = str_replace('[birthdays]',$birthdaysTable,$send_message);
5863
5864 }else
5865 {
5866 //no birthdays so strip out [birthday_text] and [birthdays]
5867 $send_message = str_replace($matches[0],'',$send_message);
5868 $send_message = str_replace('[birthdays]','',$send_message);
5869 }
5870 //anniversaries
5871 $tag = 'anniversary_text';
5872 $regex = '\\[' // Opening bracket.
5873 . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]].
5874 . "($tag)" // 2: Shortcode name.
5875 . '(?![\\w-])' // Not followed by word character or hyphen.
5876 . '(' // 3: Unroll the loop: Inside the opening shortcode tag.
5877 . '[^\\]\\/]*' // Not a closing bracket or forward slash.
5878 . '(?:'
5879 . '\\/(?!\\])' // A forward slash not followed by a closing bracket.
5880 . '[^\\]\\/]*' // Not a closing bracket or forward slash.
5881 . ')*?'
5882 . ')'
5883 . '(?:'
5884 . '(\\/)' // 4: Self closing tag...
5885 . '\\]' // ...and closing bracket.
5886 . '|'
5887 . '\\]' // Closing bracket.
5888 . '(?:'
5889 . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags.
5890 . '[^\\[]*+' // Not an opening bracket.
5891 . '(?:'
5892 . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag.
5893 . '[^\\[]*+' // Not an opening bracket.
5894 . ')*+'
5895 . ')'
5896 . '\\[\\/\\2\\]' // Closing shortcode tag.
5897 . ')?'
5898 . ')'
5899 . '(\\]?)';
5900
5901
5902 preg_match_all( '/'. $regex .'/s', $send_message, $matches );
5903
5904
5905 if(!empty($anniversaryTable)){
5906 // replace [birthday_text] and [birthdays]
5907 $send_message = str_replace($matches[0],$matches[5][0],$send_message);
5908 $send_message = str_replace('[anniversaries]',$anniversaryTable,$send_message);
5909
5910 }else
5911 {
5912 //no birthdays so strip out [birthday_text] and [birthdays]
5913 $send_message = str_replace($matches[0],'',$send_message);
5914 $send_message = str_replace('[anniversaries]','',$send_message);
5915 }
5916
5917 $send_message = str_replace('[date]',wp_date(get_option('date_format')),$send_message);
5918
5919
5920
5921
5922 //church_admin_debug('*** Finished message ***');
5923 break;
5924 }
5925
5926 if(!empty($send_message)){
5927
5928 church_admin_email_send($email,$subject,$send_message,$from_name,$from_email,null,$reply_name,$reply_email,TRUE);
5929 echo'<div class="notice notice-succes"><h2>'.esc_html(__('Test message sent','church-admin')).'</h2></div>';
5930 }
5931 }
5932 echo'<h2>'.esc_html(__('Send test email','church-admin')).'</h2>';
5933 echo'<p>'.__('Send a test email with some random birthday and anniversary names inserted','church-admin').'</p>';
5934 echo'<form action="'.wp_nonce_url($church_admin_url.'&action=send-test-automation-emails&amp;section=key-dates','send-test-automation-emails').'" method="POST">';
5935 echo'<div class="church-admin-form-group"><label>'.esc_html( __( 'Send test email to', 'church-admin' ) ) .'</label><input class="church-admin-form-control" type="email" name="test-email"></div>';
5936 echo'<div class="church-admin-form-group"><label>'.__('Which automation','church-admin').'</label>';
5937 echo'<select name="which-automation">';
5938 echo '<option value="happy-birthday">'.esc_html( __( 'Individual Happy Birthday', 'church-admin' ) ) .'</option>';
5939 echo '<option value="global-birthday">'.esc_html( __( 'Global Happy Birthday', 'church-admin' ) ) .'</option>';
5940 echo '<option value="happy-anniversary">'.esc_html( __( 'Individual Happy Anniversary', 'church-admin' ) ) .'</option>';
5941 echo '<option value="global-anniversary">'.esc_html( __( 'Global Happy Anniversaries', 'church-admin' ) ) .'</option>';
5942 echo '<option value="global-both">'.esc_html( __( 'Global Anniversaries & birthdays', 'church-admin' ) ) .'</option>';
5943 echo'</select></div>';
5944 echo'<p><input type="hidden" name="save" value=1><input type="submit" class="button-primary" value="'.esc_html(__('Send Test email')).'"></p></form>';
5945 }
5946
5947
5948 /**************************
5949 * HAPPY BIRTHDAY EMAIL
5950 ***************************/
5951
5952 add_action('church_admin_happy_birthday_email','church_admin_happy_birthday_email',1,2);
5953 function church_admin_happy_birthday_email($args)
5954 {
5955 //church_admin_debug('*** church_admin_happy_birthday_email ****');
5956 //church_admin_debugwp_date('y-m-d h:i:s'));
5957 global $wpdb;
5958 //church_admin_debug($args);
5959 $memb_sql='';
5960
5961 if(!empty($args)){
5962 $membsql=array();
5963 foreach($args AS $key=>$id){
5964 $membsql[]=' (member_type_id="'.(int)$id.'") ';
5965 }
5966 if(!empty($memb_sql)){$memb_sql = 'AND ('.implode(' OR ',$membsql).')';}
5967 }
5968
5969 $this_month = date('m');
5970 $this_day = date('d');
5971 $people=$wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE MONTH(date_of_birth)="'.(int)$this_month.'" AND DAY(date_of_birth)="'.(int)$this_day.'" '.$memb_sql);
5972 //church_admin_debug($wpdb->last_query);
5973 //church_admin_debug($people);
5974 if(!empty($people)){
5975 //church_admin_debug('Got people');
5976 $stored_message = get_option('church_admin_happy_birthday_template');
5977 //church_admin_debug($stored_message);
5978 $message = $stored_message['message'];
5979 $subject = $stored_message['subject'];
5980 $from_name = !empty($stored_message['from_name'])?$stored_message['from_name']:get_option('church_admin_default_from_name');
5981 $from_email = !empty($stored_message['from_email'])?$stored_message['from_email']:get_option('church_admin_default_from_email');
5982 $reply_name = !empty($stored_message['reply_name'])?$stored_message['reply_name']:get_option('church_admin_default_from_name');
5983 $reply_email = !empty($stored_message['reply_email'])?$stored_message['reply_email']:get_option('church_admin_default_from_email');
5984 if(empty($message)){return;}
5985 foreach($people AS $person){
5986 $email = $person->email;
5987 $email_send = $person->email_send;
5988 $send_message = $message;
5989 //if a child change to head of household
5990 if(!empty($person->people_type_id) && $person->people_type_id==2)
5991 {
5992 //church_admin_debug('Handle child birthday');
5993 //birthday person is a child so do it differently
5994 $parent=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE head_of_household=1 AND household_id="'.(int)$person->household_id.'"');
5995 $email = $parent->email;
5996 $email_send = $parent->email_send;
5997 $send_message = $stored_message['parent_message'];
5998 $send_message = str_replace('[PARENT_NAME]',$parent->first_name, $send_message);
5999 $send_message = str_replace('[parent_name]',$parent->first_name, $send_message);
6000 $send_message = str_replace('[child_name]',$person->first_name, $send_message);
6001 }
6002
6003 if(empty($email)){continue;}
6004 if(empty($email_send)){continue;}//don't send if no permission
6005
6006
6007 $privacy = maybe_unserialize($person->privacy);
6008 //prepare subject
6009 $person_subject = $subject;
6010 $person_subject = str_replace('[first_name]',$person->first_name,$person_subject);
6011 $person_subject = str_replace('[last_name]',$person->last_name,$person_subject);
6012
6013
6014 $send_message = str_replace('[date]',wp_date(get_option('date_format')),$send_message);
6015 $send_message = str_replace('[first_name]',$person->first_name,$send_message);
6016 $send_message = str_replace('[last_name]',$person->last_name,$send_message);
6017 if(empty($privacy['show-email'])){
6018 $send_message = str_replace('[email]','',$send_message);
6019 }
6020 else{
6021 $send_message = str_replace('[email]',make_clickable($person->email),$send_message);
6022 }
6023 if(empty($privacy['show-cell'])){
6024 $send_message = str_replace('[cell]','<a href="'.esc_url('tel:'.$person->cell).'">'.$person->cell.'</a>',$send_message);
6025 }
6026 else{
6027 $send_message = str_replace('[cell]','',$send_message);
6028 }
6029 $birthyear = mysql2date("Y",$person->date_of_birth);
6030 $currentyear = date("Y");
6031 $age = $currentyear - $birthyear;
6032 $send_message = str_replace('[age]',$age,$send_message);
6033 //church_admin_debug($send_message);
6034 church_admin_email_send($email,$person_subject,wp_kses_post( wpautop( $send_message ) ),$from_name,$from_email ,null);
6035
6036
6037
6038
6039
6040 }
6041
6042 }
6043 }
6044 /**************************
6045 * GLOBAL BIRTHDAY EMAIL
6046 ***************************/
6047 add_action('church_admin_global_birthday_email','church_admin_global_birthday_email',1,2);
6048 function church_admin_global_birthday_email($args)
6049 {
6050 //church_admin_debug('*** church_admin_global_birthday_email ****');
6051 //church_admin_debugwp_date('y-m-d h:i:s'));
6052 $message = get_option('church_admin_global_birthday_template');
6053 $subject = $message['subject'];
6054 $from_name = !empty( $message['from_name'] ) ? $message['from_name'] : get_option('church_admin_default_from_name');
6055 $from_email = !empty( $message['from_email'] ) ? $message['from_email'] : get_option('church_admin_default_from_email');
6056 $reply_name = !empty($message['reply_name']) ? $message['reply_name'] : get_option('church_admin_default_from_name');
6057 $reply_email = !empty($message['reply_email']) ? $message['reply_email'] : get_option('church_admin_default_from_email');
6058
6059
6060
6061 if(empty($message)){
6062 //church_admin_debug('No template setup');
6063 return;
6064 }
6065 global $wpdb;
6066 //church_admin_debug($args);
6067
6068 //get today's birthdays
6069
6070 //sort out member types stuff
6071 $people_types=get_option('church_admin_people_type');
6072 $member_types=church_admin_member_types_array();
6073 //church_admin_debug('member types array');
6074 //church_admin_debug($member_types);
6075 $tags = array();//for use if MailChimp
6076 $memb_sql='';
6077
6078 if(!empty($args)){
6079 $membsql=array();
6080 foreach($args AS $key=>$id){
6081 $membsql[]=' (member_type_id="'.(int)$id.'") ';
6082 $tags[]=$member_types[$id];
6083 }
6084 if(!empty($memb_sql)){$memb_sql = 'AND ('.implode(' OR ',$membsql).')';}
6085 }else{
6086 $tags = $member_types;
6087 }
6088 //church_admin_debug('tags');
6089 //church_admin_debug($tags);
6090 $this_month = wp_date('m');
6091 $this_day = wp_date('d');
6092 $people = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE show_me=1 AND email_send=1 AND MONTH(date_of_birth)="'.(int)$this_month.'" AND DAY(date_of_birth)="'.(int)$this_day.'" '.$memb_sql);
6093 //church_admin_debug($wpdb->last_query);
6094 $tableStyle='style="font-family: Arial;font-size:1em; border-collapse: collapse;margin-bottom:10px"';
6095 $thStyle = 'style="border: 1px solid #ddd;padding: 12px; text-align: left; background-color: #CCC;color: white;" ';
6096 $tdStyle = 'style="border: 1px solid #ddd;padding: 8px;"';
6097
6098 if(!empty($people)){
6099 //church_admin_debug('Processing people');
6100 $birthdaysTable='<table '.$tableStyle.'><thead><tr><th '.$thStyle.'>'.esc_html(__('Name','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Adult/Child','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Email','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Cell','church-admin')).'</th></tr></thead><tbody>';
6101 foreach($people AS $person){
6102 $privacy = maybe_unserialize($person->privacy);
6103 $name=church_admin_formatted_name($person);
6104 /*
6105 $birthyear = mysql2date("Y",$person->date_of_birth);
6106 $currentyear = wp_date("Y");
6107 $age = $currentyear - $birthyear;
6108 */
6109 $adult_child = $people_types[$person->people_type_id];
6110 if(!empty($person->people_type_id) && $person->people_type_id==2 || $person->people_type_id==3 ){
6111 $parents_names = church_admin_parents($person->people_id);
6112 //translators: %1$s is a name of the parent
6113 if(!empty($parents_names)){$adult_child = sprintf(__('Child of %1$s','church-admin'),$parents_names);}
6114 $head_of_household_details=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE head_of_household=1 AND household_id="'.(int)$person->household_id.'"');
6115 if(!empty($head_of_household_details)){
6116 $person->email = !empty($head_of_household_details->email) ? $head_of_household_details->email : null;
6117 $person->mobile = !empty($head_of_household_details->mobile) ? $head_of_household_details->mobile : null;
6118 }
6119 }
6120 $email = (!empty($person->email) &&!empty($person->email_send) &&!empty($privacy['show-email']) ) ? '<a href="'.esc_url('mailto:'.$person->email).'">'.esc_html($person->email).'</a>':'&nbsp;';
6121 $mobile = (!empty($person->mobile) &&!empty($person->sms_send) &&!empty($privacy['show-mobile']) ) ? '<a href="'.esc_url('tel:'.$person->e164cell).'">'.esc_html($person->mobile).'</a>':'&nbsp;';
6122 $birthdaysTable.='<tr><td '.$tdStyle.'>'.esc_html($name).'</td><td '.$tdStyle.'>'.esc_html($adult_child).'</td><td '.$tdStyle.'>'.$email.'</td><td '.$tdStyle.'>'.$mobile.'</td></tr>';
6123 }
6124 $birthdaysTable.='</tbody></table>';
6125
6126 $send_message = str_replace('[birthdays]',$birthdaysTable,wpautop($message['message']));
6127 $send_message = str_replace('[date]',wp_date(get_option('date_format')),$send_message);
6128 }
6129 else{
6130 return;
6131 }
6132 //church_admin_debug($send_message);
6133 //send to all
6134
6135 //use native wp_mail/queued email
6136 $send_people = $wpdb->get_results('SELECT email FROM '.$wpdb->prefix.'church_admin_people WHERE email_send=1 '.$memb_sql.' GROUP BY email');
6137 if(!empty($send_people)){
6138 foreach($send_people AS $person){
6139 if(!empty($person->email)){
6140 //church_admin_debug('Sent to '.$person->email);
6141 church_admin_email_send($person->email,$subject,$send_message,$from_name,$from_email,null,$reply_name,$reply_email);
6142 }
6143 }
6144 }
6145
6146
6147
6148 }
6149 /**************************
6150 * HAPPY ANNIVERSARY EMAIL
6151 ***************************/
6152 add_action('church_admin_happy_anniversary_email','church_admin_happy_anniversary_email',1,2);
6153 function church_admin_happy_anniversary_email($args)
6154 {
6155 $member_types = church_admin_member_types_array();
6156 $people_type_id=1;
6157 //church_admin_debug('*** church_admin_happy_anniversary_email ****');
6158 //church_admin_debugwp_date('y-m-d h:i:s'));
6159 global $wpdb;
6160 //church_admin_debug($args);
6161 $message = get_option('church_admin_happy_anniversary_template');
6162
6163 if(empty($message)){
6164 //church_admin_debug('No template yet');
6165 return;
6166 }
6167 $subject = $message['subject'];
6168 $send_message = $message['message'];
6169 $from_name = !empty($message['from_name'])?$message['from_name'] : get_option('church_admin_default_from_name');
6170 $from_email = !empty($message['from_email'])?$message['from_email'] : get_option('church_admin_default_from_email');
6171 $reply_name = !empty($message['reply_name'])?$message['reply_name'] : get_option('church_admin_default_from_name');
6172 $reply_email = !empty($message['reply_email'])?$message['reply_email'] : get_option('church_admin_default_from_email');
6173 $this_month = wp_date('m');
6174 $this_day = wp_date('d');
6175 $memb_sql='';
6176
6177 if(!empty($args)){
6178 $membsql=array();
6179 foreach($args AS $key=>$id){
6180 $membsql[]=' (member_type_id="'.(int)$id.'") ';
6181 $tags[]=$member_types[$id];
6182 }
6183 if(!empty($memb_sql)){$memb_sql = 'AND ('.implode(' OR ',$membsql).')';}
6184 }
6185 //get Households
6186 $households = $wpdb->get_results('SELECT a.household_id FROM '.$wpdb->prefix.'church_admin_people a, '.$wpdb->prefix.'church_admin_household b WHERE a.household_id=b.household_id AND a.show_me=1 AND a.email_send=1 AND MONTH(b.wedding_anniversary)="'.(int)$this_month.'" AND DAY(b.wedding_anniversary)="'.(int)$this_day.'" '.$memb_sql.' GROUP BY a.household_id');
6187 //church_admin_debug($wpdb->last_query);
6188
6189 if(empty($households)){ return;}
6190
6191 foreach($households AS $household)
6192 {
6193 //church_admin_debug('Processing households');
6194 $adults = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE household_id = "'.(int)$household->household_id.'" AND people_type_id="'.(int)$people_type_id.'"');
6195 //church_admin_debug($wpdb->last_query);
6196 if(empty($adults)){continue;}
6197 //church_admin_debug('Adults found');
6198 $names = $first_names = $last_names=$emails = array();
6199
6200 foreach($adults AS $adult)
6201 {
6202 $first_names[] = $adult->first_name;
6203 if(!in_array($adult->last_name,$last_names)){$last_names[] = $adult->last_name;}
6204 $names[]=church_admin_formatted_name($adult);
6205 if(!empty($adult->email)){$emails[]=$adult->email;}
6206 }
6207 //handle the fact that some couples have different last names (cultural not ethical BTW)
6208 if(count($last_names)==1){
6209 $name = implode (' & ',$first_names).' '.$last_names[0];
6210 }
6211 else
6212 {
6213 $name = implode (' & ',$names);
6214 }
6215
6216 $weddingyear = $wpdb->get_var('SELECT YEAR(wedding_anniversary) FROM '.$wpdb->prefix.'church_admin_household WHERE household_id="'.(int)$household->household_id.'"');
6217 $currentyear = wp_date("Y");
6218 $no_of_years = $currentyear - $weddingyear;
6219
6220
6221 //sort subject shortcode
6222 $subject = str_replace('[couple_name]',$name,$subject);
6223 $subject = str_replace('[couple_names]',$name,$subject);
6224 //sort message shortcode
6225 $send_message = str_replace('[date]',$name,$send_message);
6226 $send_message = str_replace('[couple_name]',$name,$send_message);
6227 $send_message = str_replace('[couple_names]',$name,$send_message);
6228 $send_message = str_replace('[years]',$no_of_years,$send_message);
6229
6230 //church_admin_debug($send_message);
6231 foreach($emails AS $key=>$to){
6232 church_admin_email_send( $to, $subject, wpautop( $send_message ),$from_name,$from_email,null ,$reply_name,$reply_email);
6233 }
6234
6235 }
6236
6237
6238
6239 }
6240 /**************************
6241 * GLOBAL ANNIVERSARY EMAIL
6242 ***************************/
6243 add_action('church_admin_global_anniversary_email','church_admin_global_anniversary_email',1,2);
6244 function church_admin_global_anniversary_email($args)
6245 {
6246 $member_types = church_admin_member_types_array();
6247 //church_admin_debug('*** church_admin_global_anniversary_email ****');
6248 //church_admin_debugwp_date('y-m-d h:i:s'));
6249 global $wpdb;
6250 //church_admin_debug($args);
6251 $message = get_option('church_admin_global_anniversary_template');
6252
6253 if(empty($message)){
6254 //church_admin_debug('No template yet');
6255 return;
6256 }
6257 $people_type_id = 1;
6258 $subject = $message['subject'];
6259 $send_message = wpautop($message['message']);
6260 $from_name = !empty($message['from_name'])?$message['from_name'] : get_option('church_admin_default_from_name');
6261 $from_email = !empty($message['from_email'])?$message['from_email'] : get_option('church_admin_default_from_email');
6262 $reply_name = !empty($message['reply_name'])?$message['reply_name'] : get_option('church_admin_default_from_name');
6263 $reply_email = !empty($message['reply_email'])?$message['reply_email'] : get_option('church_admin_default_from_email');
6264 //sort out member types stuff
6265 $member_types=church_admin_member_types_array();
6266 //church_admin_debug('member types array');
6267 //church_admin_debug($member_types);
6268 $tags = array();//for use if MailChimp
6269 $memb_sql='';
6270
6271 if(!empty($args)){
6272 $membsql=array();
6273 foreach($args AS $key=>$id){
6274 $membsql[]=' (member_type_id="'.(int)$id.'") ';
6275 $tags[]=$member_types[$id];
6276 }
6277 if(!empty($memb_sql)){$memb_sql = 'AND ('.implode(' OR ',$membsql).')';}
6278 }else{
6279 $tags = $member_types;
6280 }
6281 //church_admin_debug('tags');
6282 //church_admin_debug($tags);
6283
6284
6285 //get anniversaries
6286
6287 $this_month = wp_date('m');
6288 $this_day = wp_date('d');
6289 $households = $wpdb->get_results('SELECT a.household_id FROM '.$wpdb->prefix.'church_admin_people a, '.$wpdb->prefix.'church_admin_household b WHERE a.household_id=b.household_id AND a.show_me=1 AND a.email_send=1 AND MONTH(b.wedding_anniversary)="'.(int)$this_month.'" AND DAY(b.wedding_anniversary)="'.(int)$this_day.'" '.$memb_sql.' GROUP BY a.household_id');
6290 //church_admin_debug($wpdb->last_query);
6291
6292 if(empty($households)){ return;}
6293 $tableStyle='style="font-family: Arial; font-size:12px; border-collapse: collapse;"';
6294 $thStyle = 'style="border: 1px solid #ddd;padding: 12px; text-align: left; background-color: #CCC;color: white;" ';
6295 $tdStyle = 'style="border: 1px solid #ddd;padding: 8px;"';
6296
6297 //church_admin_debug('Build anniversary table');
6298 $anniversaryTable='<table '.$tableStyle.'><thead><tr><th '.$thStyle.'>'.esc_html(__('Name','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Email','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Cell','church-admin')).'</th></tr></thead><tbody>'."\r\n";
6299 foreach($households AS $household)
6300 {
6301 //church_admin_debug('Processing households');
6302 $adults = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE household_id = "'.(int)$household->household_id.'" AND people_type_id="'.(int)$people_type_id.'"');
6303 //church_admin_debug($wpdb->last_query);
6304 if(empty($adults)){continue;}
6305 //church_admin_debug($adults);
6306 $names = $first_names = $last_names=$emails = $mobiles = array();
6307
6308 foreach($adults AS $adult)
6309 {
6310 $privacy = maybe_unserialize($adult->privacy);
6311 $first_names[] = $adult->first_name;
6312 if(!in_array($adult->last_name,$last_names)){$last_names[] = $adult->last_name;}
6313 $names[]=church_admin_formatted_name($adult);
6314 if(!empty($adult->email) && !empty($privacy['show-email'])){
6315 $emails[]=make_clickable($adult->email);
6316 }
6317 if(!empty($adult->mobile) && !empty($privacy['show-mobile'])){
6318 $mobiles[]='<a href="'.esc_url('tel:'.$adult->e164).'>'.esc_html($adult->mobile).'</a>';;
6319 }
6320 }
6321 //handle the fact that some couples have different last names (cultural not ethical BTW)
6322 if(count($last_names)==1){
6323 $name = implode (' & ',$first_names).' '.$last_names[0];
6324 }
6325 else
6326 {
6327 $name = implode (' & ',$names);
6328 }
6329 /*
6330 $weddingyear = $wpdb->get_var('SELECT YEAR(wedding_anniversary) FROM '.$wpdb->prefix.'church_admin_household WHERE household_id="'.(int)$household->household_id.'"');
6331 $currentyear = wp_date("Y");
6332 $age = $currentyear - $weddingyear;
6333 */
6334
6335 $anniversaryTable.='<tr><td '.$tdStyle.'>'.esc_html($name).'</td><td '.$tdStyle.'>'.implode('<br/>',$emails).'</td><td '.$tdStyle.'>'.implode('<br/>',$mobiles).'</td></tr>'."\r\n";
6336
6337
6338 }
6339 $anniversaryTable.='</tbody></table>'."\r\n";
6340 //church_admin_debug($anniversaryTable);
6341
6342 //build message
6343 $send_message = str_replace('[anniversaries]',$anniversaryTable,$send_message);
6344 $send_message = str_replace('[date]',wp_date(get_option('date_format')),$send_message);
6345
6346 //use native wp_mail/queued email
6347 $send_people = $wpdb->get_results('SELECT first_name,email FROM '.$wpdb->prefix.'church_admin_people WHERE email_send=1 '.$memb_sql.' GROUP BY email');
6348 if(!empty($send_people)){
6349 foreach($send_people AS $person){
6350 if(!empty($person->email)){
6351
6352 $subject = str_replace('[first_name]',$person->first_name,$subject);
6353
6354
6355 //church_admin_debug('Sent to '.$person->email);
6356 church_admin_email_send($person->email,$subject,$send_message,$from_name,$from_email,null ,$reply_name,$reply_email);
6357
6358 }
6359 }
6360 }
6361
6362
6363 }
6364
6365 add_action('church_admin_global_birthday_and_anniversary_email','church_admin_global_birthday_and_anniversary_email',1,2);
6366 function church_admin_global_birthday_and_anniversary_email($args)
6367 {
6368
6369 $people_type_id=1;
6370 $people_types=get_option('church_admin_people_type');
6371 //church_admin_debug('*** church_admin_global_birthday_and_anniversary_email ****');
6372 //church_admin_debugwp_date('y-m-d h:i:s'));
6373 $message = get_option('church_admin_global_both_template');
6374 $subject = $message['subject'];
6375 if(empty($message)){
6376 //church_admin_debug('No template yet');
6377 return;
6378 }
6379 $from_name = !empty($message['from_name'])?$message['from_name'] : get_option('church_admin_default_from_name');
6380 $from_email = !empty($message['from_email'])?$message['from_email'] : get_option('church_admin_default_from_email');
6381 $reply_name = !empty($message['reply_name'])?$message['reply_name'] : get_option('church_admin_default_from_name');
6382 $reply_email = !empty($message['reply_email'])?$message['reply_email'] : get_option('church_admin_default_from_email');
6383 global $wpdb;
6384 //church_admin_debug($args);
6385
6386 //sort out member types stuff
6387 $member_types=church_admin_member_types_array();
6388 $tags = array();//for use if MailChimp
6389 $memb_sql='';
6390
6391 if(!empty($args)){
6392 $membsql=array();
6393 foreach($args AS $key=>$id){
6394 $membsql[]=' (member_type_id="'.(int)$id.'") ';
6395 $tags[]=$member_types[$id];
6396 }
6397 if(!empty($memb_sql)){$memb_sql = 'AND ('.implode(' OR ',$membsql).')';}
6398 }
6399
6400 //get birthdays
6401 $this_month = wp_date('m');
6402 $this_day = wp_date('d');
6403 /*
6404 $people=$wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE MONTH(date_of_birth)="'.(int)$this_month.'" AND DAY(date_of_birth)="'.(int)$this_day.'" '.$memb_sql);
6405 */
6406
6407 //do queries
6408 $people = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE show_me=1 AND email_send=1 AND MONTH(date_of_birth)="'.(int)$this_month.'" AND DAY(date_of_birth)="'.(int)$this_day.'" '.$memb_sql);
6409 //church_admin_debug($wpdb->last_query);
6410 //church_admin_debug('Number of rows '.$wpdb->num_rows);
6411 $households = $wpdb->get_results('SELECT a.household_id FROM '.$wpdb->prefix.'church_admin_people a, '.$wpdb->prefix.'church_admin_household b WHERE a.household_id=b.household_id AND a.show_me=1 AND a.email_send=1 AND MONTH(b.wedding_anniversary)="'.(int)$this_month.'" AND DAY(b.wedding_anniversary)="'.(int)$this_day.'" '.$memb_sql.' GROUP BY a.household_id');
6412 //church_admin_debug($wpdb->last_query);
6413 //church_admin_debug('Number of rows '.$wpdb->num_rows);
6414 if(empty($people) && empty($households)){
6415 //empty
6416 //church_admin_debug('No birthdays or anniversaries today');
6417 return;
6418 }
6419
6420
6421 //church_admin_debug($wpdb->last_query);
6422 $tableStyle='style="font-family: Arial;font-size:1em; border-collapse: collapse;margin-bottom:10px"';
6423 $thStyle = 'style="border: 1px solid #ddd;padding: 12px; text-align: left; background-color: #CCC;color: white;" ';
6424 $tdStyle = 'style="border: 1px solid #ddd;padding: 8px;"';
6425 $birthdaysTable = null;
6426 if(!empty($people)){
6427
6428
6429 //church_admin_debug('Build birthday table');
6430 $birthdaysTable='<table '.$tableStyle.'><thead><tr><th '.$thStyle.'>'.esc_html(__('Name','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Adult/Child','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Email','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Cell','church-admin')).'</th></tr></thead><tbody>';
6431 foreach($people AS $person){
6432 $name=church_admin_formatted_name($person);
6433
6434 $adult_child = $people_types[$person->people_type_id];
6435 if(!empty($person->people_type_id) && ($person->people_type_id==2 || $person->people_type_id==3 )){
6436 $parents_names = church_admin_parents($person->people_id);
6437 //translators: %1$s is a name of the parent
6438 if(!empty($parents_names)){$adult_child = sprintf(__('Child of %1$s','church-admin'),$parents_names);}
6439 $head_of_household_details=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE head_of_household=1 AND household_id="'.(int)$person->household_id.'"');
6440 if(!empty($head_of_household_details)){
6441 $person->email = !empty($head_of_household_details->email) ? $head_of_household_details->email : null;
6442 $person->mobile = !empty($head_of_household_details->mobile) ? $head_of_household_details->mobile : null;
6443 }
6444 }
6445 $email = (!empty($person->email) &&!empty($person->email_send) ) ? '<a href="'.esc_url('mailto:'.$person->email).'">'.esc_html($person->email).'</a>':'&nbsp;';
6446 $mobile = (!empty($person->mobile) &&!empty($person->sms_send) ) ? '<a href="'.esc_url('tel:'.$person->e164cell).'">'.esc_html($person->mobile).'</a>':'&nbsp;';
6447 $birthdaysTable.='<tr><td '.$tdStyle.'>'.esc_html($name).'</td><td '.$tdStyle.'>'.esc_html($adult_child).'</td><td '.$tdStyle.'>'.$email.'</td><td '.$tdStyle.'>'.$mobile.'</td></tr>';
6448 }
6449 $birthdaysTable.='</tbody></table>';
6450 //church_admin_debug($birthdaysTable);
6451 }
6452
6453 //get anniversaries
6454
6455 $anniversaryTable = null;
6456 if(!empty($households)){
6457 //church_admin_debug('Build anniversary table');
6458 $anniversaryTable='<table '.$tableStyle.'><thead><tr><th '.$thStyle.'>'.esc_html(__('Name','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Email','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Cell','church-admin')).'</th></tr></thead><tbody>'."\r\n";
6459 //church_admin_debug('Processing households');
6460 foreach($households AS $household)
6461 {
6462
6463 $adults = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE household_id = "'.(int)$household->household_id.'" AND people_type_id="'.(int)$people_type_id.'"');
6464 //church_admin_debug($wpdb->last_query);
6465 //church_admin_debug('Number of rows '.$wpdb->num_rows);
6466 if(empty($adults)){
6467 //church_admin_debug('No adults found');
6468 continue;
6469 }
6470 $names = $first_names = $last_names=$emails =$mobiles = array();
6471
6472 foreach($adults AS $adult)
6473 {
6474 $first_names[] = $adult->first_name;
6475 if(!in_array($adult->last_name,$last_names)){$last_names[] = $adult->last_name;}
6476 $names[]=church_admin_formatted_name($adult);
6477
6478 $privacy=maybe_unserialize($adult->privacy);
6479 if(!empty($adult->email) && !empty($privacy['show-email'])){$emails[]=make_clickable($adult->email);}
6480 if(!empty($adult->mobile) && !empty($privacy['show-cell'])){$mobiles[]='<a href="'.esc_url('tel:'.$adult->e164cell).'">'.esc_html($adult->mobile).'</a>';}
6481 }
6482 //handle the fact that some couples have different last names (cultural not ethical BTW)
6483 if(count($last_names)==1){
6484 $name = implode (' & ',$first_names).' '.$last_names[0];
6485 }
6486 else
6487 {
6488 $name = implode (' & ',$names);
6489 }
6490 //church_admin_debug('Names for this household '.$name);
6491
6492
6493
6494 $anniversaryTable.='<tr><td '.$tdStyle.'>'.esc_html($name).'</td><td '.$tdStyle.'>'.implode('<br/>',$emails).'</td><td '.$tdStyle.'>'.implode('<br/>',$mobiles).'</td></tr>'."\r\n";
6495
6496
6497 }
6498 $anniversaryTable.='</tbody></table>'."\r\n";
6499 //church_admin_debug($anniversaryTable);
6500 //church_admin_debug('Finished processing anniversary table');
6501 }
6502
6503 /**********************************
6504 * Build message
6505 ***********************************/
6506 $send_message = $message['message'];
6507
6508
6509 //birthday_text
6510 $tag = 'birthday_text';
6511 $regex = '\\[' // Opening bracket.
6512 . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]].
6513 . "($tag)" // 2: Shortcode name.
6514 . '(?![\\w-])' // Not followed by word character or hyphen.
6515 . '(' // 3: Unroll the loop: Inside the opening shortcode tag.
6516 . '[^\\]\\/]*' // Not a closing bracket or forward slash.
6517 . '(?:'
6518 . '\\/(?!\\])' // A forward slash not followed by a closing bracket.
6519 . '[^\\]\\/]*' // Not a closing bracket or forward slash.
6520 . ')*?'
6521 . ')'
6522 . '(?:'
6523 . '(\\/)' // 4: Self closing tag...
6524 . '\\]' // ...and closing bracket.
6525 . '|'
6526 . '\\]' // Closing bracket.
6527 . '(?:'
6528 . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags.
6529 . '[^\\[]*+' // Not an opening bracket.
6530 . '(?:'
6531 . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag.
6532 . '[^\\[]*+' // Not an opening bracket.
6533 . ')*+'
6534 . ')'
6535 . '\\[\\/\\2\\]' // Closing shortcode tag.
6536 . ')?'
6537 . ')'
6538 . '(\\]?)';
6539
6540
6541 preg_match_all( '/'. $regex .'/s', $send_message, $matches );
6542
6543
6544 if(!empty($birthdaysTable)){
6545 // replace [birthday_text] and [birthdays]
6546 $send_message = str_replace($matches[0],$matches[5][0],$send_message);
6547 $send_message = str_replace('[birthdays]',$birthdaysTable,$send_message);
6548
6549 }else
6550 {
6551 //no birthdays so strip out [birthday_text] and [birthdays]
6552 $send_message = str_replace($matches[0],'',$send_message);
6553 $send_message = str_replace('[birthdays]','',$send_message);
6554 }
6555 //anniversaries
6556 $tag = 'anniversary_text';
6557 $regex = '\\[' // Opening bracket.
6558 . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]].
6559 . "($tag)" // 2: Shortcode name.
6560 . '(?![\\w-])' // Not followed by word character or hyphen.
6561 . '(' // 3: Unroll the loop: Inside the opening shortcode tag.
6562 . '[^\\]\\/]*' // Not a closing bracket or forward slash.
6563 . '(?:'
6564 . '\\/(?!\\])' // A forward slash not followed by a closing bracket.
6565 . '[^\\]\\/]*' // Not a closing bracket or forward slash.
6566 . ')*?'
6567 . ')'
6568 . '(?:'
6569 . '(\\/)' // 4: Self closing tag...
6570 . '\\]' // ...and closing bracket.
6571 . '|'
6572 . '\\]' // Closing bracket.
6573 . '(?:'
6574 . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags.
6575 . '[^\\[]*+' // Not an opening bracket.
6576 . '(?:'
6577 . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag.
6578 . '[^\\[]*+' // Not an opening bracket.
6579 . ')*+'
6580 . ')'
6581 . '\\[\\/\\2\\]' // Closing shortcode tag.
6582 . ')?'
6583 . ')'
6584 . '(\\]?)';
6585
6586
6587 preg_match_all( '/'. $regex .'/s', $send_message, $matches );
6588
6589
6590 if(!empty($anniversaryTable)){
6591 // replace [birthday_text] and [birthdays]
6592 $send_message = str_replace($matches[0],$matches[5][0],$send_message);
6593 $send_message = str_replace('[anniversaries]',$anniversaryTable,$send_message);
6594
6595 }else
6596 {
6597 //no birthdays so strip out [birthday_text] and [birthdays]
6598 $send_message = str_replace($matches[0],'',$send_message);
6599 $send_message = str_replace('[anniversaries]','',$send_message);
6600 }
6601
6602 $send_message = str_replace('[date]',wp_date(get_option('date_format')),$send_message);
6603
6604 //church_admin_debug('*** Finished message ***');
6605 //church_admin_debug($send_message);
6606
6607 //send to all
6608
6609 //use native wp_mail/queued email
6610 $send_people = $wpdb->get_results('SELECT email FROM '.$wpdb->prefix.'church_admin_people WHERE email_send=1 '.$memb_sql.' GROUP BY email');
6611 if(!empty($send_people)){
6612 foreach($send_people AS $person){
6613 if(!empty($person->email)){
6614 //church_admin_debug('Sent to '.$person->email);
6615 church_admin_email_send($person->email,$subject,$send_message,$from_name,$from_email,null,$reply_name,$reply_email);
6616 }
6617 }
6618 }
6619
6620
6621
6622
6623
6624 }
6625
6626 add_action('church_admin_custom_fields_automations','church_admin_custom_fields_automations',1,2);
6627 function church_admin_custom_fields_automations()
6628 {
6629 global $wpdb;
6630 //church_admin_debug('*** church_admin_custom_fields_automations ****');
6631 $automations = get_option('church_admin_custom_fields_automations');
6632 if(empty($automations)){
6633 //church_admin_debug('No custom field automations');
6634 return;
6635 }
6636 $custom_fields = church_admin_custom_fields_array();
6637
6638 foreach($automations AS $key=>$auto){
6639 /*
6640 //here is the structure of each $auto...
6641 $args=array('name'=>$name,
6642 'custom_id'=>$custom_id,
6643 'contacts' =>$people_ids,
6644 'email_type' =>$email_type
6645 );
6646 */
6647 $people_ids=maybe_unserialize($auto['contacts']);
6648 $emails=array();
6649 foreach($people_ids AS $x=>$people_id){
6650 $emails[]=$wpdb->get_var('SELECT email FROM '.$wpdb->prefix.'church_admin_people WHERE people_id="'.(int)$people_id.'"');
6651 }
6652 $emails = array_filter($emails);
6653 $custom_field_details = $custom_fields[$auto['custom_id']];
6654 $transients = get_option('church_admin_transient_custom_id'.$auto['custom_id']);
6655 if(empty($transients)){continue;}
6656 /*
6657 * Here is the structure of each $transient...
6658 * array('from_name'=>$from_name, 'from_email'=>$from_email,people_id'=>$people_id,'household'=>$household_id,'old_value'=>$old_value,'new_value'=>$new_value)
6659 */
6660 $from_name = !empty($transients['from_name'])?$transients['from_name'] : get_option('church_admin_default_from_name');
6661 $from_email = !empty($transients['from_email'])?$transients['from_email'] : get_option('church_admin_default_from_email');
6662 $tableStyle='style="font-family: Arial;font-size:1em; border-collapse: collapse;margin-bottom:10px"';
6663 $thStyle = 'style="border: 1px solid #ddd;padding: 12px; text-align: left; background-color: #CCC;color: white;" ';
6664 $tdStyle = 'style="border: 1px solid #ddd;padding: 8px;"';
6665 $table='<table '.$tableStyle.'><thead><tr><th '.$thStyle.'>'.esc_html(__('Person','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Email','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Cell','church-admin')).'</th><th '.$thStyle.'>'.esc_html(__('Old value')).'</th><th '.$thStyle.'>'.esc_html(__('New value','church-admin')).'</th></tr></thead><tbody>';
6666
6667 foreach($transients AS $y=>$tr){
6668 $person=$wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'church_admin_people WHERE people_id="'.(int)$tr['people_id'].'"');
6669 if(empty($person)){continue;}
6670 $name = church_admin_formatted_name($person);
6671 $email = !empty($person->email)?make_clickable($person->email):'';
6672 $cell = !empty($person->mobile)?'<a href="tel:'.$person->e164cell.'">'.$person->mobile.'</a>':'';
6673 $table.='<tr><td '.$tdStyle.'>'.esc_html($name).'</a></td><td '.$tdStyle.'>'.$email.'</td><td '.$tdStyle.'>'.$cell.'</td><td '.$tdStyle.'>'.esc_html($tr['old_value']).'</td><td '.$tdStyle.'>'.esc_html($tr['new_value']).'</td></tr>';
6674 }
6675 $table.='</tbody></table>';
6676 //translators: %1$s is a name of the custom field
6677 $subject = esc_html(sprintf(__('Changes to custom field %1$s','church-admin'),$custom_field_details['name']));
6678 $message='<p>'.$subject.'</p>';
6679 $message.=$table;
6680 //church_admin_debug($message);
6681 foreach($emails AS $z=>$to){
6682 //church_admin_debug('Sent to '.$to);
6683 church_admin_email_send($to,$subject,$message,$from_name,$from_email,null);
6684 }
6685 delete_option('church_admin_transient_custom_id'.$auto['custom_id']);
6686 }
6687 }
6688
6689
6690 if(is_multisite()){
6691 add_filter('upload_dir', 'church_admin_fix_upload_paths');
6692 }
6693
6694 function church_admin_fix_upload_paths($data)
6695 {
6696 $add = '/sites/'.get_current_blog_id();
6697 //check whether this has already been done
6698 $pos = strpos($data['basedir'], $add);
6699 if ($pos === false) {
6700 $data['basedir'] = $data['basedir'].'/sites/'.get_current_blog_id();
6701 $data['path'] = $data['basedir'].$data['subdir'];
6702 $data['baseurl'] = $data['baseurl'].'/sites/'.get_current_blog_id();
6703 $data['url'] = $data['baseurl'].$data['subdir'];
6704 } else {
6705 // do nothing because it has already been done
6706 }
6707 return $data;
6708 }
6709
6710
6711
6712
6713 function church_admin_test_function(){
6714 echo'Nothing';
6715 }