forked from wp-plugins/participants-database
/
participants-database.php
3462 lines (2855 loc) · 114 KB
/
participants-database.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Plugin Name: Participants Database
* Plugin URI: http://xnau.com/wordpress-plugins/participants-database
* Description: Plugin for managing a database of participants, members or volunteers
* Author: Roland Barker
* Version: 1.6.3
* Author URI: http://xnau.com
* License: GPL2
* Text Domain: participants-database
* Domain Path: /languages
*/
/*
* Copyright 2011, 2012, 2013, 2014, 2015 Roland Barker xnau webdesign (email : webdesign@xnau.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
if (!defined( 'ABSPATH' ) ) exit;
// register the class autoloading
spl_autoload_register('PDb_class_loader');
/**
* main static class for running the plugin
*
* @category WordPress Plugins
* @package wordPress
* @author Roland Barker <webdesign@xnau.com>
* @copyright 2011 - 2015 7th Veil, LLC
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL2
* @version Release: 1.6
*
*/
class Participants_Db extends PDb_Base {
/**
*
* unique slug for the plugin; this is same as the plugin directory name
*
* @var string unique slug for the plugin
*/
const PLUGIN_NAME = 'participants-database';
/**
* display title
* @var string
*/
public static $plugin_title;
/**
* basename of the main participants index table
* @var string
*/
public static $participants_table;
/**
* base name of the table for all associated values
* @var string
*/
public static $fields_table;
/**
* name of the table for groups defninitions
* @var string
*/
public static $groups_table;
/**
* to create a new database version, change this value to the new version number.
* This will trigger a database update in the PDb_Init class
*
* @var string current Db version
*/
public static $db_version = '1.0';
/**
* name of the WP option where the current db version is stored
* @var string
*/
public static $db_version_option = 'PDb_Db_version';
/**
* current version of plugin
* @var string
*/
public static $plugin_version;
/**
* name of the WP plugin options
* @var string
*/
public static $participants_db_options;
/**
* name of the default settings option
* @var string
*/
public static $default_options;
/**
* plugin option values $name => $value
* @var array
*/
public static $plugin_options;
/**
* plugin settings object
* @var object
*/
public static $Settings;
/**
* name of the plugin admin page
* @var string
*/
public static $plugin_page;
/**
* path to the plugin root ditectory
* @var string
*/
public static $plugin_path;
/**
* absolute path to the uploads directory
* @var string
*/
public static $uploads_path;
/**
* a general-use prefix to set a namespace
*
* @var string
*/
public static $prefix = 'pdb-';
/**
* duplicate of $prefix for backwards compatibility
* @var string
*/
public static $css_prefix;
/**
* the PDb_FormValidation object
* @var object
*/
public static $validation_errors;
/**
* an admin status or error message
* @var string
*/
static $admin_message = '';
/**
* the type of admin message
* @var string
*/
static $admin_message_type;
/**
* name of the transient record used to hold the last recor
* @var string
*/
public static $last_record;
/**
* status code for the last record processed
* @var string
*/
public static $insert_status;
/**
* header to include with plugin email
* @var strings
*/
public static $email_headers;
/**
* enclosure character to use
* @var string
*/
public static $CSV_enclosure = '"';
/**
* list of reserved field names
* @var array
*/
public static $reserved_names = array('source', 'subsource', 'id', 'private_id', 'record_link', 'action', 'submit', 'submit-button', 'name', 'day', 'month', 'year', 'hour', 'date', 'minute', 'email-regex');
/**
* true while sending an email
* @var bool
*/
public static $sending_email = false;
/**
* set of internationalized words
* @var array
*/
public static $i18n = array();
/**
* the date format; defaults to the WP global setting, but can be changed within the plugin
*
* @var string
*/
public static $date_format;
/**
* the last method used to parse a date
*
* @var string
*/
public static $date_mode;
/**
* index for tracking multiple instances of a shortcode
* @var int
*/
public static $instance_index = 1;
/**
* @var string name of the list pagination variable
*/
public static $list_page = 'listpage';
/**
* set when a list search form is shown to prevent more than one form appearing on a page
* @var bool
*/
public static $search_set = false;
/**
* holds the WP session object
*
* @var object
*/
public static $session;
/**
* this is set once per plugin instantiation, then all instances are expected to use this instead of running their own queries
*
*
*
* @var array of all field objects, indexed by field name
*/
public static $fields;
/**
* @var string context string for the main submission nonce
*/
public static $main_submission_nonce_key = 'main_submission';
/**
* @var int the number of characters to use in the private ID
*/
public static $private_id_length = 5;
/**
* initializes the static class
*
* sets up the class autoloading, configuration values, hooks, filters and shortcodes
*
* @global object $wpdb
*/
public static function initialize() {
// set the plugin version
self::$plugin_version = self::_get_plugin_data('Version');
// define some locations
self::$default_options = self::$prefix . 'default_options';
self::$plugin_page = self::PLUGIN_NAME;
self::$plugin_path = plugin_dir_path(__FILE__);
// this is relative to the WP install
self::$uploads_path = 'wp-content/uploads/' . self::PLUGIN_NAME . '/';
self::$last_record = self::$prefix . 'last_record';
self::$css_prefix = self::$prefix;
self::$session = new PDb_Session();
/*
* set up data source names
*
* these can be modified later with a filter hook
*/
global $wpdb;
$table_basename = $wpdb->prefix . str_replace('-', '_', self::PLUGIN_NAME);
self::$participants_table = $table_basename;
self::$fields_table = $table_basename . '_fields';
self::$groups_table = $table_basename . '_groups';
self::$participants_db_options = self::PLUGIN_NAME . '_options';
// install/deactivate and uninstall methods are handled by the PDB_Init class
register_activation_hook(__FILE__, array('PDb_Init', 'on_activate'));
register_deactivation_hook(__FILE__, array('PDb_Init', 'on_deactivate'));
register_uninstall_hook(__FILE__, array('PDb_Init', 'on_uninstall'));
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array(__CLASS__, 'add_plugin_action_links') );
add_filter( 'plugin_row_meta', array(__CLASS__, 'add_plugin_meta_links'), 10, 2 );
// set the WP hooks to finish setting up the plugin
add_action('init', array(__CLASS__, 'init'));
add_action('wp', array(__CLASS__, 'remove_rel_link'));
add_action('wp', array(__CLASS__, 'reset_shortcode_session'));
add_filter('admin_body_class', array(__CLASS__, 'add_admin_body_class'));
add_filter('body_class', array(__CLASS__, 'add_body_class'));
add_action('admin_menu', array(__CLASS__, 'plugin_menu'));
add_action('admin_init', array(__CLASS__, 'admin_init'));
add_action('wp_enqueue_scripts', array(__CLASS__, 'include_scripts'));
add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_includes'));
add_filter('wp_headers', array(__CLASS__, 'control_caching'));
add_filter(self::$prefix . 'translate_string', array(__CLASS__, 'string_static_translation'), 20);
// handles ajax request from list filter
add_action('wp_ajax_pdb_list_filter', array(__CLASS__, 'pdb_list_filter'));
add_action('wp_ajax_nopriv_pdb_list_filter', array(__CLASS__, 'pdb_list_filter'));
// define our shortcodes
add_shortcode('pdb_record', array(__CLASS__, 'print_shortcode'));
add_shortcode('pdb_signup', array(__CLASS__, 'print_shortcode'));
add_shortcode('pdb_signup_thanks', array(__CLASS__, 'print_shortcode'));
add_shortcode('pdb_request_link', array(__CLASS__, 'print_shortcode'));
add_shortcode('pdb_list', array(__CLASS__, 'print_shortcode'));
add_shortcode('pdb_single', array(__CLASS__, 'print_shortcode'));
add_shortcode('pdb_search', array(__CLASS__, 'print_shortcode'));
add_shortcode('pdb_total', array(__CLASS__, 'print_shortcode'));
/*
* sets up the update notification
*
*/
new PDb_Update_Notices(__FILE__);
}
/**
* performs a fix for some older versions of the plugin; does nothing with current plugins
*/
public static function admin_init() {
// if the setting was made in previous versions and is a slug, convert it to a post ID
$regpage = isset(self::$plugin_options['registration_page']) ? self::$plugin_options['registration_page'] : '';
if (!empty($regpage) && !is_numeric($regpage)) {
self::$plugin_options['registration_page'] = self::get_id_by_slug($regpage);
update_option(self::$participants_db_options, self::$plugin_options);
}
}
/**
* initializes the plugin in the WP environment, fired on the 'init' hook
*
* @return null
*/
public static function init() {
// set the table names
global $wpdb;
/*
* this filter allows a plugin to determine which db tables to use
*
* this allows things like multilingual field definitions or possibly even multiple databases
*/
self::$participants_table = self::set_filter('select_database_table', self::$participants_table);
self::$fields_table = self::set_filter('select_database_table', self::$fields_table);
self::$groups_table = self::set_filter('select_database_table', self::$groups_table);
// also filter the name of the settings to use
self::$participants_db_options = self::set_filter('select_database_table', self::$participants_db_options);
/*
* set up the base reference object arrays
*
* this is to reduce the number of db queries
*/
self::_setup_columns();
self::load_plugin_textdomain(__FILE__);
self::$plugin_title = __('Participants Database', 'participants-database');
self::_set_i18n();
/**
* @version 1.6 filter pdb-private_id_length
*/
self::$private_id_length = self::set_filter('private_id_length', self::$private_id_length);
/*
* checks for the need to update the DB
*
* this is to allow for updates to occur in many different ways
*/
if ( false === get_option( self::$db_version_option ) || get_option( self::$db_version_option ) != self::$db_version )
PDb_Init::on_update();
/*
* instantiate the settings class; this only sets up the settings definitions,
* the WP Settings API may not be available at this point, so we register the
* settings on the 'admin_menu' hook
*/
self::$Settings = new PDb_Settings();
// get the plugin options array
if (!is_array(self::$plugin_options)) {
$default_options = get_option(self::$default_options);
if (!is_array($default_options)) {
$default_options = self::$Settings->get_default_options();
add_option(self::$default_options, $default_options, '', false);
}
self::$plugin_options = array_merge($default_options, (array) get_option(self::$participants_db_options));
}
/*
* normally, the custom CSS is written to a static css file, but on some systems,
* that doesn't work, so the fallback is to load the dynamic CSS file
*/
if (self::_set_custom_css()) {
$custom_css_file = 'PDb-custom.css';
} else {
$custom_css_file = 'custom_css.php';
}
/*
* set the plugin date display format; uses the blog setting, which is localized
*
* since version 1.5.5 we have not used the "strict date format" becuase that
* is for input purposes only. This format is used to display dates.
*
* this property can be changed in a template if desired
*/
self::$date_format = get_option('date_format');
if (self::plugin_setting_is_true('html_email')) {
$type = 'text/html; charset="' . get_option('blog_charset') . '"';
} else {
$type = 'text/plain; charset=us-ascii';
}
$email_headers =
"From: " . self::$plugin_options['receipt_from_name'] . " <" . self::$plugin_options['receipt_from_address'] . ">\n" .
"Content-Type: " . $type . "\n";
self::$email_headers = self::set_filter('email_headers', $email_headers);
// this processes form submits before any output so that redirects can be used
self::process_page_request();
// if (!is_object(self::$Settings)) {
// self::$Settings = new PDb_Settings();
// }
// self::$Settings->initialize();
$option_version = self::$Settings->option_version();
/*
* register frontend scripts and stylesheets
*/
wp_register_style('pdb-frontend', plugins_url('/css/participants-database.css', __FILE__), array('dashicons'));
wp_register_style('custom_plugin_css', plugins_url('/css/' . $custom_css_file, __FILE__), null, $option_version);
wp_register_script(self::$prefix.'shortcode', plugins_url('js/shortcodes.js', __FILE__), array('jquery'));
wp_register_script(self::$prefix.'list-filter', plugins_url('js/list-filter.js', __FILE__), array('jquery'));
wp_register_script(self::$prefix.'jq-placeholder', plugins_url('js/jquery.placeholder.min.js', __FILE__), array('jquery'));
wp_register_script(self::$prefix.'otherselect', plugins_url('js/otherselect.js', __FILE__), array('jquery'));
/*
* register admin scripts and stylesheets
*/
wp_register_script(self::$prefix.'cookie', plugins_url('js/jquery_cookie.js', __FILE__));
wp_register_script(self::$prefix.'manage_fields', plugins_url('js/manage_fields.js', __FILE__), array('jquery','jquery-ui-core','jquery-ui-tabs','jquery-ui-sortable','jquery-ui-dialog',self::$prefix.'cookie'), false, true);
wp_register_script(self::$prefix.'settings_script', plugins_url('js/settings.js', __FILE__), array('jquery','jquery-ui-core','jquery-ui-tabs',self::$prefix.'cookie'), false, true);
wp_register_script(self::$prefix.'record_edit_script', plugins_url('js/record_edit.js', __FILE__), array('jquery','jquery-ui-core','jquery-ui-tabs',self::$prefix.'cookie'), false, true);
wp_register_script(self::$prefix.'jq-placeholder', plugins_url('js/jquery.placeholder.min.js', __FILE__), array('jquery'));
wp_register_script('jq-doublescroll', plugins_url('js/jquery.doubleScroll.js', __FILE__), array('jquery', 'jquery-ui-widget'));
wp_register_script(self::$prefix.'admin', plugins_url('js/admin.js', __FILE__), array('jquery','jq-doublescroll'));
wp_register_script(self::$prefix.'otherselect', plugins_url('js/otherselect.js', __FILE__), array('jquery'));
wp_register_script(self::$prefix.'list-admin', plugins_url('js/list_admin.js', __FILE__), array('jquery'));
wp_register_script(self::$prefix.'debounce', plugins_url('js/jq_debounce.js', __FILE__), array('jquery'));
//wp_register_script( 'datepicker', plugins_url( 'js/jquery.datepicker.js', __FILE__ ) );
//wp_register_script( 'edit_record', plugins_url( 'js/edit.js', __FILE__ ) );
wp_register_style('pdb-utility', plugins_url('/css/xnau-utility.css', __FILE__));
wp_register_style('pdb-global-admin', plugins_url('/css/PDb-admin-global.css', __FILE__), false, false);
wp_register_style('pdb-frontend', plugins_url('/css/participants-database.css', __FILE__));
wp_register_style('pdb-admin', plugins_url('/css/PDb-admin.css', __FILE__));
}
/**
* sets up the plugin admin menus
*
* @return null
*/
public static function plugin_menu() {
global $pagenow;
if (($pagenow == 'admin.php' && filter_input(INPUT_GET, 'page') === 'participants-database_settings_page') || $pagenow == 'options.php') {
/*
* intialize the plugin settings for the plugin settings pages
*/
self::$Settings->initialize();
}
/*
* this allows the possibility of a child class handling the admin list display
*/
$list_admin_classname = self::set_filter('admin_list_classname', 'PDb_List_Admin');
// define the plugin admin menu pages
add_menu_page(
self::$plugin_title,
self::$plugin_title,
self::plugin_capability('record_edit_capability', 'main admin menu'),
self::PLUGIN_NAME,
null
);
add_submenu_page(
self::PLUGIN_NAME,
__('List Participants', 'participants-database'),
__('List Participants', 'participants-database'),
self::plugin_capability('record_edit_capability', 'list participants'),
self::PLUGIN_NAME,//self::$plugin_page . '-list_participants',
array($list_admin_classname, 'initialize')
);
/**
* this registers the edit participant page without adding it as a menu item
*/
add_submenu_page(
null,
null,
null,
self::plugin_capability('record_edit_capability', 'edit participant'),
self::$plugin_page . '-edit_participant',
array(__CLASS__, 'include_admin_file')
);
add_submenu_page(
self::PLUGIN_NAME,
__('Add Participant', 'participants-database'),
__('Add Participant', 'participants-database'),
self::plugin_capability('record_edit_capability', 'add participant'),
self::$plugin_page . '-add_participant',
array(__CLASS__, 'include_admin_file')
);
add_submenu_page(
self::PLUGIN_NAME,
__('Manage Database Fields', 'participants-database'),
__('Manage Database Fields', 'participants-database'),
self::plugin_capability('plugin_admin_capability', 'manage fields'),
self::$plugin_page . '-manage_fields',
array(__CLASS__, 'include_admin_file')
);
add_submenu_page(
self::PLUGIN_NAME,
__('Import CSV File', 'participants-database'),
__('Import CSV File', 'participants-database'),
self::plugin_capability('plugin_admin_capability', 'upload csv'),
self::$plugin_page . '-upload_csv',
array(__CLASS__, 'include_admin_file')
);
add_submenu_page(
self::PLUGIN_NAME,
__('Settings', 'participants-database'),
__('Settings', 'participants-database'),
self::plugin_capability('plugin_admin_capability', 'plugin settings'),
self::$plugin_page . '_settings_page',
array(self::$Settings, 'show_settings_form')
);
add_submenu_page(
self::PLUGIN_NAME,
__('Setup Guide', 'participants-database'),
__('Setup Guide', 'participants-database'),
self::plugin_capability('plugin_admin_capability', 'setup guide'),
self::$plugin_page . '-setup_guide',
array(__CLASS__, 'include_admin_file')
);
}
/**
* processes the admin includes
*
* uses WP hook 'admin_enqueue_scripts''
*
* @param string $hook the admin menu hook as provided by the WP filter
* @return null
*/
public static function admin_includes($hook) {
if (false !== stripos($hook, 'participants-database')) {
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_script('jquery-ui-sortable');
wp_enqueue_script('jquery-ui-dialog');
wp_enqueue_script(self::$prefix.'cookie');
wp_enqueue_script(self::$prefix.'jq-placeholder');
wp_enqueue_script(self::$prefix.'admin');
wp_enqueue_script(self::$prefix.'otherselect');
wp_enqueue_script('jq-doublescroll');
}
if (false !== stripos($hook, 'participants-database-list_participants')) {
// wp_localize_script(self::$prefix.'list-admin', 'list_adminL10n', array(
// 'delete' => PDb_List_Admin::$i18n['delete_checked'],
// 'cancel' => PDb_List_Admin::$i18n['change'],
// "record" => __("Do you really want to delete the selected record?", 'participants-database' ),
// "records" => __("Do you really want to delete the selected records?", 'participants-database' ),
// ));
// wp_enqueue_script(self::$prefix.'list-admin');
}
if (false !== stripos($hook, 'participants-database_settings_page')) {
wp_enqueue_script(self::$prefix.'settings_script');
}
if (false !== stripos($hook, 'participants-database-edit_participant')) {
//wp_enqueue_script(self::$prefix.'record_edit_script');
}
if (false !== stripos($hook, 'participants-database-manage_fields')) {
wp_localize_script(self::$prefix . 'manage_fields', 'manageFields', array('uri' => $_SERVER['REQUEST_URI']));
wp_localize_script(self::$prefix . 'manage_fields', 'PDb_L10n', array(
/* translators: don't translate the words in brackets {} */
'must_remove' => '<h4>' . __('You must remove all fields from the {name} group before deleting it.', 'participants-database') . '</h4>',
'delete_confirm' => '<h4>' . __('Delete the "{name}" {thing}?', 'participants-database') . '</h4>',
'unsaved_changes' => __("The changes you made will be lost if you navigate away from this page.")
));
wp_enqueue_script(self::$prefix . 'manage_fields');
}
wp_enqueue_style('pdb-global-admin');
wp_enqueue_style('pdb-utility');
// only incude these stylesheets on the plugin admin pages
if (false !== stripos($hook, 'participants-database')) {
wp_enqueue_style('pdb-frontend');
wp_enqueue_style('pdb-admin');
}
}
/**
* register all frontend JS and CSS
*
* fired on WP hook 'wp_enqueue_scripts' the actual enqueueing happens in the PDb_Shortcode class
*
* @return null
*/
public static function include_scripts() {
}
/**
* enqueues the frontend CSS
*
* @return null
*/
public static function include_stylesheets() {
if (self::plugin_setting_is_true('use_plugin_css')) {
wp_enqueue_style('pdb-frontend');
}
wp_enqueue_style('custom_plugin_css');
}
/**
* enqueues the general plugin frontend scripts
*
* @return null
*/
public static function add_scripts() {
wp_enqueue_script(self::$prefix.'shortcode');
wp_enqueue_script(self::$prefix.'jq-placeholder');
wp_enqueue_script(self::$prefix.'otherselect');
}
/**
* includes files for generating plugin admin pages
*
* grabs the name from the request and includes the file to display the page;
* this is the admin submenu callback
*
* @static
* @return null
*/
public static function include_admin_file()
{
$file = str_replace(self::$plugin_page . '-', '', filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING)) . '.php';
if (is_file(plugin_dir_path(__FILE__) . $file)) {
// we'll need this in the included file
global $wpdb;
include $file;
}
}
/**
* shows the frontend edit screen called by the [pdb_record] shortcode
*
*
* the ID of the record to show for editing can be provided one of three ways:
* $_GET['pid'] (private link) or in the POST array (actively editing a record)
* $atts['id'](deprecated) or $atts['record_id'] (in the sortcode), or
* self::$session->get('pdbid') (directly from the signup form)
*
*
* @param array $atts array of attributes drawn from the shortcode
* @return string the HTML of the record edit form
*/
public static function print_record_edit_form($atts)
{
$record_id = false;
// get the pid from the get string if given (for backwards compatibility)
$get_pid = filter_input(INPUT_GET, 'pid', FILTER_SANITIZE_STRING);
if (empty($get_pid)) {
$get_pid = filter_input(INPUT_POST, 'pid', FILTER_SANITIZE_STRING);
}
if (!empty($get_pid)) {
$record_id = self::get_participant_id($get_pid);
}
// get the id from the SESSION array
if ($record_id === false && self::$session->get('pdbid')) {
$record_id = self::get_record_id_by_term('id', self::$session->get('pdbid'));
}
if ($record_id === false && (isset($atts['id']) || isset($atts['record_id']))) {
if (isset($atts['id']) & !isset($atts['record_id'])) {
$atts['record_id'] = $atts['id'];
unset($atts['id']);
}
$record_id = self::get_record_id_by_term('id', $atts['record_id']);
}
$atts['record_id'] = $record_id;
return PDb_Record::print_form($atts);
}
/**
* updates the "last_accessed" field in the database
*
* @ver 1.5 added $wpdb->prepare()
*
* @param int $id the record to update
* @global $wpdb
*/
private static function _record_access($id) {
global $wpdb;
$sql = 'UPDATE ' . self::$participants_table . ' SET `last_accessed` = NOW() WHERE `id` = %s';
return $wpdb->query($wpdb->prepare($sql, $id));
}
/**
* sets the last_accessed timestamp
*
* @param int $id id of the record to update
*/
public static function set_record_access($id) {
self::_record_access($id);
}
/**
* common function for printing all shortcodes
*
* @param array $params array of paramters passed in from the shortcode
* @param string $content the content of the enclosure (empty string; we don't use enclosure tags)
* @param string $tag the shortcode identification string
* @return null
*/
public static function print_shortcode($params, $content, $tag) {
/**
* @version 1.6
*
* 'pdb-shortcode_call_{$tag}' filter allows the shortcode atrributes to be
* altered before instantiating the shortcode object
*/
$shortcode_parameters = self::set_filter('shortcode_call_' . $tag, $params);
switch ($tag) {
case 'pdb_record':
return self::print_record_edit_form($shortcode_parameters);
break;
case 'pdb_signup':
return self::print_signup_form($shortcode_parameters);
break;
case 'pdb_signup_thanks':
return self::print_signup_thanks_form($shortcode_parameters);
break;
case 'pdb_request_link':
return self::print_retrieval_form($shortcode_parameters);
break;
case 'pdb_list':
return self::print_list($shortcode_parameters);
break;
case 'pdb_single':
return self::print_single_record($shortcode_parameters);
break;
case 'pdb_search':
return self::print_search_form($shortcode_parameters);
break;
case 'pdb_total':
return self::print_total($shortcode_parameters);
break;
}
}
/**
* prints a "total" value
*
* called by the "pdb_total" shortcode. this is to print a total number of records,
* the number of records passing a filter, or an arithmetic sum of all the data
* passing a filter.
*
* @param array $params the parameters passed in by the shortcode
* @return string the output HTML
*/
public static function print_total($params) {
$params['module'] = 'total';
$params['list_limit'] = -1;
return PDb_List::get_list($params);
}
/**
* prints a single record called by [pdb_list] shortcode
*
* @param array $params the parameters passed in by the shortcode
* @return string the output HTML
*/
public static function print_list($params) {
$params['module'] = 'list';
return PDb_List::get_list($params);
}
/**
* prints a list search form
*
* @param array $params the parameters passed in by the shortcode
* @return string the output HTML
*/
public static function print_search_form($params) {
$params = (array) $params + array('module' => 'search', 'search' => true);
return PDb_List::get_list($params);
}
/**
* prints a single record called by [pdb_single] shortcode
*
* @param array $params the parameters passed in by the shortcode
* @return string the output HTML
*/
public static function print_single_record($params) {
// alias the 'id' attribute for backwards compatibility
if (isset($params['id']) & !isset($params['record_id'])) {
$params['record_id'] = $params['id'];
unset($params['id']);
}
if (isset($params['record_id'])) {
$params['record_id'] = self::get_record_id_by_term('id', $params['record_id']);
}
return PDb_Single::print_record($params);
}
/**
* prints a form from the Signup class
*
* @param array $params the parameters from the shortcode
* @return string the output HTML
*/
public static function print_signup_class_form($params) {
$params['post_id'] = get_the_ID();
return PDb_Signup::print_form($params);
}
/**
* prints a signup form
*
* @param array $params the parameters passed in by the shortcode
* @return string the output HTML
*/
public static function print_signup_form($params) {
$params['module'] = 'signup';
return self::print_signup_class_form($params);
}
/**
* prints the signup thanks form
*
* @param array $params the parameters passed in by the shortcode
* @return string the output HTML
*/
public static function print_signup_thanks_form($params) {
$params['module'] = 'thanks';
return self::print_signup_class_form($params);
}
/**
* prints the private ID retrieval form
*
* @param array $params the parameters passed in by the shortcode
* @return string the output HTML
*/
public static function print_retrieval_form($params)
{
$params['module'] = 'retrieve';
return self::print_signup_class_form($params);
}
/**
* sets up the $fields array
*
* global $wpdb
*/
private static function _setup_columns() {
global $wpdb;
self::$fields = array();
$sql = 'SELECT v.*
FROM ' . self::$fields_table . ' v
ORDER BY v.order';
$result = $wpdb->get_results($sql);
foreach ($result as $column) {
self::$fields[$column->name] = $column;
}
}
/**
* get all the attributes of a field by it's name
*
* an attribute or comma-separated list of attributes can be specified if not,
* a default list of attributes is retrieved
*
* @global object $wpdb
* @param string $field the name of the field to get
* @param string $atts depricated
* @return stdClass
*/
public static function get_field_atts($field = false, $atts = '*') {
return self::get_column($field);
}
/**
* get an array of groups
*
* @param string $column comma-separated list of columns to get, defaults to all (*)
* @param mixed $exclude single group to exclude or array of groups to exclude
* @return array returns an associative array column => value or indexed array
* if only one column is specified in the $column argument
*/
public static function get_groups($column = '*', $exclude = false) {
global $wpdb;
$where = '';
if ($exclude) {
$where = ' WHERE `name` ';
if (is_array($exclude)) {
$where .= 'NOT IN ("' . implode('","', $exclude) . '") ';
} else {
$where .= '!= "' . $exclude . '" ';
}
}
$sql = 'SELECT ' . $column . ' FROM ' . self::$groups_table . $where . ' ORDER BY `order`,`name` ASC';
// are we looking for only one column?
// if so, flatten the array
if ($column !== '*' and false === strpos($column, ',')) {
$output = array();
foreach ($wpdb->get_results($sql, ARRAY_A) as $row)
$output[] = $row[$column];
return $output;
} else {
$group_index = array();
$groups = $wpdb->get_results($sql, ARRAY_A);