Formidable Forms – Form Builder for WordPress - Version 1.0

Version Description

Download this release

Release Info

Developer sswells
Plugin Icon 128x128 Formidable Forms – Form Builder for WordPress
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (85) hide show
  1. classes/controllers/FrmApiController.php +88 -0
  2. classes/controllers/FrmAppController.php +308 -0
  3. classes/controllers/FrmEntriesController.php +113 -0
  4. classes/controllers/FrmFieldsController.php +149 -0
  5. classes/controllers/FrmFormsController.php +313 -0
  6. classes/controllers/FrmSettingsController.php +104 -0
  7. classes/controllers/FrmStatisticsController.php +21 -0
  8. classes/helpers/FrmAppHelper.php +142 -0
  9. classes/helpers/FrmEntriesHelper.php +50 -0
  10. classes/helpers/FrmFieldsHelper.php +60 -0
  11. classes/helpers/FrmFormsHelper.php +59 -0
  12. classes/helpers/FrmSettingsHelper.php +19 -0
  13. classes/models/FrmEntry.php +200 -0
  14. classes/models/FrmEntryMeta.php +171 -0
  15. classes/models/FrmField.php +147 -0
  16. classes/models/FrmForm.php +211 -0
  17. classes/models/FrmNotification.php +88 -0
  18. classes/models/FrmSettings.php +43 -0
  19. classes/models/FrmUtils.php +64 -0
  20. classes/views/frm-entries/direct.php +9 -0
  21. classes/views/frm-entries/form.php +31 -0
  22. classes/views/frm-entries/frm-entry.php +37 -0
  23. classes/views/frm-entries/list.php +11 -0
  24. classes/views/frm-entries/new.php +17 -0
  25. classes/views/frm-fields/radio.php +8 -0
  26. classes/views/frm-fields/show.php +40 -0
  27. classes/views/frm-fields/single-option.php +9 -0
  28. classes/views/frm-forms/add_field.php +116 -0
  29. classes/views/frm-forms/add_field_links.php +60 -0
  30. classes/views/frm-forms/default-templates.php +40 -0
  31. classes/views/frm-forms/edit.php +26 -0
  32. classes/views/frm-forms/footer.php +37 -0
  33. classes/views/frm-forms/form.php +36 -0
  34. classes/views/frm-forms/list.php +101 -0
  35. classes/views/frm-forms/new-field-js.php +109 -0
  36. classes/views/frm-forms/new-option-js.php +40 -0
  37. classes/views/frm-forms/new-selection.php +14 -0
  38. classes/views/frm-forms/new.php +27 -0
  39. classes/views/frm-settings/form.php +28 -0
  40. classes/views/frm-settings/pro-settings.php +51 -0
  41. classes/views/frm-statistics/list.php +11 -0
  42. classes/views/shared/errors.php +11 -0
  43. classes/views/shared/head.php +13 -0
  44. classes/views/shared/item-table-nav.php +83 -0
  45. classes/views/shared/nav.php +8 -0
  46. css/frm_admin.css +81 -0
  47. css/frm_display.css +6 -0
  48. css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  49. css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  50. css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  51. css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  52. css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  53. css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  54. css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  55. css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  56. css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  57. css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  58. css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  59. css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  60. css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  61. css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  62. css/ui-lightness/jquery-ui-1.7.2.custom.css +406 -0
  63. formidable.php +166 -0
  64. images/arrow_down.png +0 -0
  65. images/arrow_up.png +0 -0
  66. images/blackglass-captcha.png +0 -0
  67. images/clean-captcha.png +0 -0
  68. images/error.png +0 -0
  69. images/icon.png +0 -0
  70. images/icon_128.png +0 -0
  71. images/icon_16.png +0 -0
  72. images/icon_32.png +0 -0
  73. images/icon_48.png +0 -0
  74. images/red-captcha.png +0 -0
  75. images/white-captcha.png +0 -0
  76. js/jquery/jquery-ui-1.7.1.custom.min.js +273 -0
  77. js/jquery/jquery-ui-datepicker.js +12 -0
  78. js/jquery/jquery.editinplace.js +281 -0
  79. js/jquery/jquery.editinplace.packed.js +24 -0
  80. js/list-items.js +66 -0
  81. readme.txt +30 -0
  82. screenshot-1.png +0 -0
  83. screenshot-2.png +0 -0
  84. screenshot-3.png +0 -0
  85. todo.txt +60 -0
classes/controllers/FrmApiController.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmApiController{
4
+ function FrmApiController(){
5
+ }
6
+
7
+ /********* DISPLAY DATA *************/
8
+ function frm_filter_content($args){
9
+ global $frm_entry;
10
+ $args = explode(",",$args[1]);
11
+
12
+ $form_key = sanitize_title($args[0]);
13
+
14
+ $where = '';//" gr.form_key = '$form_key'";
15
+ $items = $frm_entry->getAll($where);
16
+
17
+ $list = $form_key;
18
+ foreach ($items as $item){
19
+ $list .= $item->name;
20
+ }
21
+
22
+ return $list;
23
+ }
24
+
25
+ function get_frm_items($args = null){
26
+ global $frm_entry, $frm_form, $frm_entry_meta;
27
+
28
+ $defaults = array(
29
+ 'form_key' => '', 'parent_id' => '',
30
+ 'order' => '', 'limit' => '',
31
+ 'search' =>'', 'search_type' => '',
32
+ 'search_field' => '', 'search_operator' => 'LIKE'
33
+ );
34
+
35
+ $r = wp_parse_args( $args, $defaults );
36
+
37
+ $form = $frm_form->getOneByKey($r['form_key']);
38
+
39
+ $where = " (it.form_id='". $form->id ."' or gr.form_id='". $form->id ."')";
40
+ if (!($r['parent_id'] == ''))
41
+ $where .= " and it.parent_item_id='". $r['parent_id'] ."'";
42
+
43
+ if (!($r['order'] == ''))
44
+ $r['order'] = " ORDER BY {$r['order']}";
45
+
46
+ if (!($r['limit'] == ''))
47
+ $r['limit'] = " LIMIT {$r['limit']}";
48
+
49
+ if (!($r['search'] == '') and $r['search_type'] == '')
50
+ $where .= " and (it.item_key LIKE '%{$r['search']}%' or it.description LIKE '%{$r['search']}%' or it.name LIKE '%{$r['search']}%')";
51
+
52
+ $items = $frm_entry->getAll($where, $r['order'], $r['limit']);
53
+
54
+ if (!($r['search'] == '') and $r['search_type'] == 'meta'){ //search meta values
55
+ $item_ids = $frm_entry_meta->search_entry_metas($r['search'], $r['search_field'], $r['search_operator']);
56
+ $item_list = array();
57
+ foreach ($items as $item){
58
+ if (in_array($item->id, $item_ids))
59
+ $item_list[] = $item;
60
+ }
61
+ return $item_list;
62
+ }else
63
+ return $items;
64
+ }
65
+
66
+ function get_frm_item($item_key){
67
+ global $frm_entry;
68
+ return $frm_entry->getOneByKey( $item_key );
69
+ }
70
+
71
+ function get_frm_item_by_id($id){
72
+ global $frm_entry;
73
+ return $frm_entry->getOne( $id );
74
+ }
75
+
76
+ function get_frm_edit_link($id){
77
+ global $current_user, $frm_siteurl;
78
+
79
+ $output = '';
80
+ if($current_user->wp_capabilities['administrator'] == 1) {
81
+ $output = "<span class='frm_edit'>[<a href='{$frm_siteurl}/wp-admin/admin.php?page=". FRM_PLUGIN_NAME ."-entries&action=edit&id={$id}'>Edit</a>]</span>";
82
+ }
83
+ return $output;
84
+ }
85
+
86
+ }
87
+
88
+ ?>
classes/controllers/FrmAppController.php ADDED
@@ -0,0 +1,308 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmAppController{
4
+ function FrmAppController(){
5
+ add_action('admin_menu', array( $this, 'menu' ));
6
+ add_filter('the_content', array( $this, 'page_route' ), 1);
7
+ add_action('init', array($this, 'front_head'));
8
+ add_action('admin_init', array( $this, 'admin_js'));
9
+ register_activation_hook(FRM_PATH."/formidable.php", array( $this, 'install' ));
10
+
11
+ // Used to process standalone requests
12
+ add_action('init', array($this,'parse_standalone_request'));
13
+
14
+ //Shortcodes
15
+ add_shortcode('formidable', array($this,'get_form_shortcode'));
16
+ add_filter( 'widget_text', array($this,'widget_text_filter'), 9 );
17
+ }
18
+
19
+ function menu(){
20
+ global $frmpro_is_installed, $frm_forms_controller;
21
+
22
+ add_menu_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE, 8, FRM_PLUGIN_NAME, array($frm_forms_controller,'route'), FRM_URL . '/images/icon_16.png');
23
+
24
+ if(!$frmpro_is_installed){
25
+ add_submenu_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE .' | Pro Statistics', 'Pro Statistics', 8, FRM_PLUGIN_TITLE.'-statistics',array($this,''));
26
+ }
27
+ }
28
+
29
+ function head(){
30
+ $css_file = 'frm_admin.css';
31
+ $js_file = 'list-items.js';
32
+ require_once(FRM_VIEWS_PATH . '/shared/head.php');
33
+ }
34
+
35
+ function admin_js(){
36
+ wp_enqueue_script('jQuery');
37
+ wp_enqueue_script('jQuery-custom', FRM_URL.'/js/jquery/jquery-ui-1.7.1.custom.min.js');
38
+ wp_enqueue_script('jQuery-in-place-edit-patched', FRM_URL.'/js/jquery/jquery.editinplace.packed.js');
39
+
40
+ add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
41
+ if ( user_can_richedit() )
42
+ wp_enqueue_script('editor');
43
+ add_thickbox();
44
+ }
45
+
46
+ function front_head(){
47
+ wp_enqueue_style('frm-forms', FRM_URL.'/css/frm_display.css');
48
+ }
49
+
50
+ function install(){
51
+ global $wpdb, $frm_utils, $frm_form, $frm_field;
52
+ $db_version = 1.0; // this is the version of the database we're moving to
53
+ $old_db_version = get_option('frm_db_version');
54
+
55
+ $fields_table = $wpdb->prefix . "frm_fields";
56
+ $forms_table = $wpdb->prefix . "frm_forms";
57
+ $items_table = $wpdb->prefix . "frm_items";
58
+ $item_metas_table = $wpdb->prefix . "frm_item_metas";
59
+
60
+ $charset_collate = '';
61
+ if( $wpdb->has_cap( 'collation' ) ){
62
+ if( !empty($wpdb->charset) )
63
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
64
+ if( !empty($wpdb->collate) )
65
+ $charset_collate .= " COLLATE $wpdb->collate";
66
+ }
67
+
68
+ if ($db_version != $old_db_version){
69
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
70
+
71
+ /* Create/Upgrade Fields Table */
72
+ $sql = "CREATE TABLE {$fields_table} (
73
+ id int(11) NOT NULL auto_increment,
74
+ field_key varchar(255) default NULL,
75
+ name varchar(255) default NULL,
76
+ description text default NULL,
77
+ type text default NULL,
78
+ default_value longtext default NULL,
79
+ options longtext default NULL,
80
+ field_order int(11) default 0,
81
+ required int(1) default NULL,
82
+ field_options longtext default NULL,
83
+ form_id int(11) default NULL,
84
+ created_at datetime NOT NULL,
85
+ PRIMARY KEY (id),
86
+ KEY form_id (form_id)
87
+ );";
88
+
89
+ dbDelta($sql);
90
+
91
+ /* Create/Upgrade Forms Table */
92
+ $sql = "CREATE TABLE {$forms_table} (
93
+ id int(11) NOT NULL auto_increment,
94
+ form_key varchar(255) default NULL,
95
+ name varchar(255) default NULL,
96
+ description text default NULL,
97
+ logged_in boolean default NULL,
98
+ editable boolean default NULL,
99
+ is_template boolean default 0,
100
+ default_template boolean default 0,
101
+ status varchar(255) default NULL,
102
+ prli_link_id int(11) default NULL,
103
+ options longtext default NULL,
104
+ created_at datetime NOT NULL,
105
+ PRIMARY KEY (id)
106
+ );";
107
+
108
+ dbDelta($sql);
109
+
110
+ /* Create/Upgrade Items Table */
111
+ $sql = "CREATE TABLE {$items_table} (
112
+ id int(11) NOT NULL auto_increment,
113
+ item_key varchar(255) default NULL,
114
+ name varchar(255) default NULL,
115
+ description text default NULL,
116
+ form_id int(11) default NULL,
117
+ parent_item_id int(11) default NULL,
118
+ created_at datetime NOT NULL,
119
+ PRIMARY KEY (id),
120
+ KEY form_id (form_id),
121
+ KEY parent_item_id (parent_item_id)
122
+ );";
123
+
124
+ dbDelta($sql);
125
+
126
+ /* Create/Upgrade Meta Table */
127
+ $sql = "CREATE TABLE {$item_metas_table} (
128
+ id int(11) NOT NULL auto_increment,
129
+ meta_key varchar(255) default NULL,
130
+ meta_value longtext default NULL,
131
+ field_id int(11) NOT NULL,
132
+ item_id int(11) NOT NULL,
133
+ created_at datetime NOT NULL,
134
+ PRIMARY KEY (id),
135
+ KEY field_id (field_id),
136
+ KEY item_id (item_id)
137
+ );";
138
+
139
+ dbDelta($sql);
140
+
141
+ /**** ADD DEFAULT FORMS ****/
142
+ if ($frm_form->getRecordCount("form_key='contact' and is_template='1'") <= 0){
143
+ $values = FrmFormsHelper::setup_new_vars();
144
+ $values['name'] = 'Contact Us';
145
+ $values['form_key'] = 'contact';
146
+ $values['description'] = 'We would like to hear from you. Please send us a message by filling out the form below and we will get back with you shortly.';
147
+ $values['is_template'] = 1;
148
+ $values['default_template'] = 1;
149
+ $form_id = $frm_form->create( $values );
150
+
151
+ $field_options = array();
152
+ $field_options['label'] = 'top';
153
+ $field_options['size'] = '75';
154
+ $field_options['max'] = '';
155
+ $field_options['required_indicator'] = '*';
156
+
157
+
158
+ $field_options['blank'] = 'Name cannot be blank';
159
+ $field_options['invalid'] = '';
160
+ $frm_field->create( array(
161
+ 'field_key' => 'name',
162
+ 'name' => 'Name',
163
+ 'description' => '',
164
+ 'type' => 'text',
165
+ 'default_value' => '',
166
+ 'options' => '',
167
+ 'form_id' => $form_id,
168
+ 'field_order' => 1,
169
+ 'required' => true,
170
+ 'field_options' => $field_options ));
171
+
172
+ $field_options['blank'] = 'Email cannot be blank';
173
+ $field_options['invalid'] = 'Please enter a valid email address';
174
+ $frm_field->create( array(
175
+ 'field_key' => 'email',
176
+ 'name' => 'Email',
177
+ 'description' => '',
178
+ 'type' => 'email',
179
+ 'default_value' => '',
180
+ 'options' => '',
181
+ 'form_id' => $form_id,
182
+ 'field_order' => 2,
183
+ 'required' => true,
184
+ 'field_options' => $field_options ));
185
+
186
+ $field_options['blank'] = 'Website cannot be blank';
187
+ $field_options['invalid'] = 'Website is an invalid format';
188
+ $frm_field->create( array(
189
+ 'field_key' => 'website',
190
+ 'name' => 'Website',
191
+ 'description' => '',
192
+ 'type' => 'website',
193
+ 'default_value' => '',
194
+ 'options' => '',
195
+ 'form_id' => $form_id,
196
+ 'field_order' => 3,
197
+ 'required' => false,
198
+ 'field_options' => $field_options ));
199
+
200
+ $field_options['blank'] = 'Subject cannot be blank';
201
+ $field_options['invalid'] = '';
202
+ $frm_field->create( array(
203
+ 'field_key' => 'subject',
204
+ 'name' => 'Subject',
205
+ 'description' => '',
206
+ 'type' => 'text',
207
+ 'default_value' => '',
208
+ 'options' => '',
209
+ 'form_id' => $form_id,
210
+ 'field_order' => 4,
211
+ 'required' => true,
212
+ 'field_options' => $field_options ));
213
+
214
+ $field_options['size'] = '65';
215
+ $field_options['max'] = '5';
216
+ $field_options['blank'] = 'Message cannot be blank';
217
+ $frm_field->create( array(
218
+ 'field_key' => 'message',
219
+ 'name' => 'Message',
220
+ 'description' => '',
221
+ 'type' => 'textarea',
222
+ 'default_value' => '',
223
+ 'options' => '',
224
+ 'form_id' => $form_id,
225
+ 'field_order' => 5,
226
+ 'required' => true,
227
+ 'field_options' => $field_options ));
228
+
229
+ $field_options['label'] = 'none';
230
+ $field_options['size'] = '';
231
+ $field_options['max'] = '';
232
+ $frm_field->create( array(
233
+ 'field_key' => 'captcha',
234
+ 'name' => 'Captcha',
235
+ 'description' => '',
236
+ 'type' => 'captcha',
237
+ 'default_value' => '',
238
+ 'options' => '',
239
+ 'form_id' => $form_id,
240
+ 'field_order' => 6,
241
+ 'required' => false,
242
+ 'field_options' => $field_options ));
243
+ }
244
+
245
+ /***** SAVE DB VERSION *****/
246
+ update_option('frm_db_version',$db_version);
247
+ }
248
+ }
249
+
250
+
251
+ // Routes for wordpress pages -- we're just replacing content here folks.
252
+ function page_route($content){
253
+ global $post, $frm_settings, $frm_forms_controller;
254
+
255
+ if( $post->ID == $frm_settings->preview_page_id){
256
+ $frm_forms_controller->page_preview();
257
+ return '';
258
+ }
259
+
260
+ return $content;
261
+ }
262
+
263
+ // The tight way to process standalone requests dogg...
264
+ function parse_standalone_request(){
265
+ $plugin = $this->get_param('plugin');
266
+ $action = $this->get_param('action');
267
+ $controller = $this->get_param('controller');
268
+
269
+ if( !empty($plugin) and $plugin == FRM_PLUGIN_NAME and !empty($controller) and !empty($action) ){
270
+ $this->standalone_route($controller, $action);
271
+ exit;
272
+ }
273
+ }
274
+
275
+ // Routes for standalone / ajax requests
276
+ function standalone_route($controller, $action){
277
+ global $frm_forms_controller;
278
+
279
+ if($controller=='forms'){
280
+ if($action=='preview')
281
+ $frm_forms_controller->preview($this->get_param('form'));
282
+ }
283
+ }
284
+
285
+ // Utility function to grab the parameter whether it's a get or post
286
+ function get_param($param, $default=''){
287
+ return (isset($_POST[$param])?$_POST[$param]:(isset($_GET[$param])?$_GET[$param]:$default));
288
+ }
289
+
290
+
291
+ function get_form_shortcode($atts){
292
+ global $frm_entries_controller;
293
+ extract(shortcode_atts(array('id' => '', 'key' => '', 'title' => false, 'description' => false), $atts));
294
+ return $frm_entries_controller->show_form($id, $key, $title, $description);
295
+ }
296
+
297
+
298
+ function widget_text_filter( $content ){
299
+ $regex = '/\[\s*formidable\s+.*\]/';
300
+ return preg_replace_callback( $regex, 'widget_text_filter_callback', $content );
301
+ }
302
+
303
+
304
+ function widget_text_filter_callback( $matches ) {
305
+ return do_shortcode( $matches[0] );
306
+ }
307
+ }
308
+ ?>
classes/controllers/FrmEntriesController.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmEntriesController{
4
+ function FrmEntriesController(){
5
+ add_action('admin_menu', array( $this, 'menu' ));
6
+ $this->views = FRM_VIEWS_PATH.'/frm-entries/';
7
+ }
8
+
9
+ function menu(){
10
+ global $frmpro_is_installed;
11
+ if(!$frmpro_is_installed)
12
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | Pro Entries', 'Pro Entries', 8, FRM_PLUGIN_NAME.'-entries',array($this,'list'));
13
+ }
14
+
15
+ function list_entries(){
16
+ require_once($this->views .'list.php');
17
+ }
18
+
19
+ function show_form($id, $key, $title, $description){
20
+ global $frm_form, $user_ID;
21
+ if ($id) $form = $frm_form->getOne($id);
22
+ else if ($key) $form = $frm_form->getOneByKey($key);
23
+ if (!$form or $form->is_template or $form->status == 'draft')
24
+ return 'Please select a valid form';
25
+ else if ($form->logged_in and !$user_ID)
26
+ return 'You must log in';
27
+ else
28
+ return $this->get_form($this->views.'frm-entry.php', $form, $title, $description);
29
+ }
30
+
31
+ function new_entry($form){
32
+ global $frm_form, $frm_field, $frm_entry, $frm_entry_meta, $frm_recaptcha_enabled, $user_ID;
33
+ $fields = $frm_field->getAll("fi.form_id='$form->id'", ' ORDER BY field_order');
34
+ $values = FrmEntriesHelper::setup_new_vars($fields);
35
+ $form_name = $form->name;
36
+
37
+ $params = $this->get_params($form);
38
+ $message = '';
39
+ $errors = '';
40
+
41
+ do_action('frm_display_form_action', $params, $fields, $form, $title, $description);
42
+ if (apply_filters('frm_continue_to_new', true)){
43
+ $values = FrmEntriesHelper::setup_new_vars($fields);
44
+ require_once($this->views .'new.php');
45
+ }
46
+ }
47
+
48
+ function create($form){
49
+ global $frm_form, $frm_field, $frm_entry, $frm_entry_meta, $frm_recaptcha_enabled, $user_ID;
50
+ $fields = $frm_field->getAll("fi.form_id='$form->id'", ' ORDER BY field_order');
51
+ $values = FrmEntriesHelper::setup_new_vars($fields);
52
+ $form_name = $form->name;
53
+
54
+ $failed_message = "We're sorry. There was an error processing your responses.";
55
+ $saved_message = "Your responses were successfully submitted. Thank you!";
56
+
57
+ $params = $this->get_params($form);
58
+ $message = '';
59
+
60
+ $errors = $frm_entry->validate($_POST);
61
+
62
+ if( count($errors) > 0 ){
63
+ $values = FrmEntriesHelper::setup_new_vars($fields);
64
+ require_once($this->views.'new.php');
65
+ }else{
66
+ do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description);
67
+ if (apply_filters('frm_continue_to_create', true)){
68
+ if ($frm_entry->create( $_POST ))
69
+ echo $saved_message;
70
+ else
71
+ echo $failed_message;
72
+ }
73
+ }
74
+ }
75
+
76
+ function get_form($filename, $form, $title, $description) {
77
+ if (is_file($filename)) {
78
+ ob_start();
79
+ include $filename;
80
+ $contents = ob_get_contents();
81
+ ob_end_clean();
82
+ return $contents;
83
+ }
84
+ return false;
85
+ }
86
+
87
+ function get_params($form=null){
88
+ global $frm_app_controller, $frm_form;
89
+
90
+ if(!$form)
91
+ $form = $frm_form->getAll('',' ORDER BY name',' LIMIT 1');
92
+ $action = apply_filters('frm_show_new_entry_page','new',$form);
93
+ $values = array();
94
+ foreach (array('id' => '','form_name' => '', 'paged' => 1,'form' => $form->id,'field_id' => '', 'search' => '','sort' => '','sdir' => '', 'form' => $form->id, 'action' => $action) as $var => $default)
95
+ $values[$var] = $frm_app_controller->get_param($var, $default);
96
+
97
+ return $values;
98
+ }
99
+
100
+ function route($form=false){
101
+ global $frm_app_controller;
102
+ $action = $frm_app_controller->get_param('action');
103
+ if (!$form)
104
+ $form = $frm_app_controller->get_param('form');
105
+ $action = apply_filters('frm_show_new_entry_page', $action, $form);
106
+ if($action=='create')
107
+ return $this->create($form);
108
+ else
109
+ return $this->new_entry($form);
110
+ }
111
+
112
+ }
113
+ ?>
classes/controllers/FrmFieldsController.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmFieldsController{
4
+ function FrmFieldsController(){
5
+ add_filter('frm_field_type',array( $this, 'change_type'));
6
+ add_action('wp_ajax_frm_insert_field', array($this, 'create') );
7
+ add_action('wp_ajax_frm_field_name_in_place_edit', array($this, 'edit_name') );
8
+ add_action('wp_ajax_frm_field_desc_in_place_edit', array($this, 'edit_description') );
9
+ add_action('wp_ajax_frm_mark_required', array($this, 'mark_required') );
10
+ add_action('wp_ajax_frm_unmark_required', array($this, 'unmark_required') );
11
+ add_action('wp_ajax_frm_delete_field', array($this, 'destroy') );
12
+ add_action('wp_ajax_frm_add_field_option',array($this, 'add_option'));
13
+ add_action('wp_ajax_frm_field_option_ipe', array($this, 'edit_option') );
14
+ add_action('wp_ajax_frm_delete_field_option',array($this, 'delete_option'));
15
+ add_action('wp_ajax_frm_update_field_order', array($this, 'update_order') );
16
+ }
17
+
18
+ function create(){
19
+ global $frm_field, $frm_recaptcha_enabled;
20
+ $field_data = $_POST['field'];
21
+ $form_id = $_POST['form_id'];
22
+
23
+ $field_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars($field_data, $form_id));
24
+ if (isset($_POST['position']))
25
+ $field_values['field_order'] = $_POST['position'];
26
+
27
+ $field_id = $frm_field->create( $field_values );
28
+
29
+ if ($field_id){
30
+ $field = FrmFieldsHelper::setup_edit_vars($frm_field->getOne($field_id));
31
+ $field_name = "item_meta[$field_id]";
32
+ $id = $form_id;
33
+ require(FRM_VIEWS_PATH.'/frm-forms/add_field.php');
34
+ require(FRM_VIEWS_PATH.'/frm-forms/new-field-js.php');
35
+ }
36
+ die();
37
+ }
38
+
39
+ function edit_name(){
40
+ global $frm_field;
41
+ $id = str_replace('field_', '', $_POST['element_id']);
42
+ $values = array('name' => $_POST['update_value']);
43
+ if ($_POST['original_html'] == 'Untitled')
44
+ $values['field_key'] = $_POST['update_value'];
45
+ $form = $frm_field->update($id, $values);
46
+ echo stripslashes($_POST['update_value']);
47
+ die();
48
+ }
49
+
50
+
51
+ function edit_description(){
52
+ global $frm_field;
53
+ $id = str_replace('field_', '', $_POST['element_id']);
54
+ $frm_field->update($id, array('description' => $_POST['update_value']));
55
+ echo stripslashes($_POST['update_value']);
56
+ die();
57
+ }
58
+
59
+ function mark_required(){
60
+ global $frm_field;
61
+ $id = str_replace('req_field_', '', $_POST['field']);
62
+ $frm_field->update($id, array('required' => '1'));
63
+ die();
64
+ }
65
+
66
+ function unmark_required(){
67
+ global $frm_field;
68
+ $id = str_replace('req_field_', '', $_POST['field']);
69
+ $frm_field->update($id, array('required' => '0'));
70
+ die();
71
+ }
72
+
73
+ function destroy(){
74
+ global $frm_field;
75
+ $field_id = $frm_field->destroy($_POST['field_id']);
76
+ die();
77
+ }
78
+
79
+ /* Field Options */
80
+ function add_option(){
81
+ global $frm_field;
82
+
83
+ $id = str_replace('field_', '', $_POST['field']);
84
+ $field = $frm_field->getOne($id);
85
+ $options = unserialize($field->options);
86
+ $last = max(array_keys($options));
87
+ $opt_key = $last + 1;
88
+ $opt = 'Option '.(count($options)+1);
89
+ $options[$opt_key] = $opt;
90
+ $frm_field->update($id, array('options' => serialize($options)));
91
+ $checked = '';
92
+
93
+ $field_data = $frm_field->getOne($id);
94
+ $field = array();
95
+ $field['type'] = $field_data->type;
96
+ $field['id'] = $id;
97
+ $field_name = "item_meta[$id]";
98
+
99
+ require(FRM_VIEWS_PATH.'/frm-fields/single-option.php');
100
+ require(FRM_VIEWS_PATH.'/frm-forms/new-option-js.php');
101
+ die();
102
+ }
103
+
104
+ function edit_option(){
105
+ global $frm_field;
106
+ $ids = explode('-',$_POST['element_id']);
107
+ $id = str_replace('field_', '', $ids[0]);
108
+ $field = $frm_field->getOne($id);
109
+ $options = unserialize($field->options);
110
+ $options[$ids[1]] = $_POST['update_value'];
111
+ $frm_field->update($id, array('options' => maybe_serialize($options)));
112
+ echo stripslashes($_POST['update_value']);
113
+ die();
114
+ }
115
+
116
+ function delete_option(){
117
+ global $frm_field;
118
+ $ids = explode('-',$_POST['field']);
119
+ $id = str_replace('frm_delete_field_', '', $ids[0]);
120
+ $field = $frm_field->getOne($id);
121
+ $options = unserialize($field->options);
122
+ unset($options[$ids[1]]);
123
+ $frm_field->update($id, array('options' => serialize($options)));
124
+ die();
125
+ }
126
+
127
+
128
+ function update_order(){
129
+ global $frm_field;
130
+ foreach ($_POST['frm_field_id'] as $position => $item)
131
+ $frm_field->update($item, array('field_order' => $position));
132
+ die();
133
+ }
134
+
135
+
136
+ function change_type($type){
137
+ global $frm_field_selection, $frmpro_is_installed;
138
+
139
+ if($frmpro_is_installed)
140
+ return $type;
141
+
142
+ $types = array_keys($frm_field_selection);
143
+ if (!in_array($type, $types))
144
+ $type = 'text';
145
+
146
+ return $type;
147
+ }
148
+ }
149
+ ?>
classes/controllers/FrmFormsController.php ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmFormsController{
4
+ function FrmFormsController(){
5
+ add_action('admin_menu', array( $this, 'menu' ));
6
+ add_action('admin_head-toplevel_page_'.FRM_PLUGIN_NAME, array($this,'head'));
7
+ add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-new', array($this,'head'));
8
+ add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-templates', array($this,'head'));
9
+ add_action('wp_ajax_frm_form_name_in_place_edit', array($this, 'edit_name') );
10
+ add_action('wp_ajax_frm_form_desc_in_place_edit', array($this, 'edit_description') );
11
+ add_action('wp_ajax_frm_delete_form_wo_fields',array($this, 'destroy_wo_fields'));
12
+ $this->views = FRM_VIEWS_PATH.'/frm-forms/';
13
+ }
14
+
15
+ function menu(){
16
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | Forms', 'Forms', 8, FRM_PLUGIN_NAME, array($this,'route'));
17
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | Create a Form', 'Create a Form', 8, FRM_PLUGIN_NAME.'-new', array($this,'new_form'));
18
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | Templates', 'Templates', 8, FRM_PLUGIN_NAME.'-templates', array($this, 'template_list'));
19
+ }
20
+
21
+ function head(){
22
+ $css_file = 'frm_admin.css';
23
+ $js_file = 'list-items.js';
24
+ require_once(FRM_VIEWS_PATH . '/shared/head.php');
25
+ }
26
+
27
+ function list_form(){
28
+ $params = $this->get_params();
29
+ $errors = apply_filters('frm_admin_list_form_action', $errors);
30
+ return $this->display_forms_list($params, '', false, false, $errors);
31
+ }
32
+
33
+ function template_list(){
34
+ $_POST['template'] = 1;
35
+ return $this->display_forms_list();
36
+ }
37
+
38
+ function new_form(){
39
+ global $frm_app_controller, $frm_form, $frm_field_selection, $frm_recaptcha_enabled, $frm_pro_field_selection, $frmpro_is_installed;
40
+
41
+ $action = $frm_app_controller->get_param('action');
42
+ if ($action == 'create')
43
+ return $this->create();
44
+ else if ($action == 'new'){
45
+ $values = FrmFormsHelper::setup_new_vars();
46
+ $id = $frm_form->create( $values );
47
+ require_once($this->views . 'new.php');
48
+ }else{
49
+ $all_templates = $frm_form->getAll('is_template=1',' ORDER BY name');
50
+ require_once($this->views . 'new-selection.php');
51
+ }
52
+ }
53
+
54
+ function create(){
55
+ global $frm_app_controller, $frm_app_helper, $frm_field_selection, $frm_entry, $frm_form, $frm_field, $frm_recaptcha_enabled, $frm_pro_field_selection, $frm_utils, $frmpro_is_installed;
56
+ $errors = $frm_form->validate($_POST);
57
+ $id = $frm_app_controller->get_param('id');
58
+
59
+ if( count($errors) > 0 ){
60
+ $record = $frm_form->getOne( $id );
61
+ $fields = $frm_field->getAll("fi.form_id=$id", ' ORDER BY field_order');
62
+ $values = $frm_app_helper->setup_edit_vars($record,'forms',$fields,true);
63
+ require_once($this->views . 'new.php');
64
+ }else{
65
+ $items = $frm_entry->getAll('',' ORDER BY it.name');
66
+ $record = $frm_form->update( $id, $_POST, true );
67
+ $message = "Form was Successfully Created";
68
+ $params = $this->get_params();
69
+ return $this->display_forms_list($params, $message);
70
+ }
71
+
72
+ }
73
+
74
+ function edit(){
75
+ global $frm_app_controller;
76
+ $id = $frm_app_controller->get_param('id');
77
+ return $this->get_edit_vars($id);
78
+ }
79
+
80
+ function edit_name(){
81
+ global $frm_form;
82
+ $values = array('name' => $_POST['update_value']);
83
+ $form = $frm_form->update($_POST['form_id'], $values);
84
+ echo stripslashes($_POST['update_value']);
85
+ die();
86
+ }
87
+
88
+ function edit_description(){
89
+ global $frm_form;
90
+ $form = $frm_form->update($_POST['form_id'], array('description' => $_POST['update_value']));
91
+ echo wpautop(stripslashes($_POST['update_value']));
92
+ die();
93
+ }
94
+
95
+ function update(){
96
+ global $frm_form, $frm_app_controller;
97
+ $errors = $frm_form->validate($_POST);
98
+ $id = $frm_app_controller->get_param('id');
99
+ if( count($errors) > 0 ){
100
+ return $this->get_edit_vars($id, $errors);
101
+ }else{
102
+ $record = $frm_form->update( $_POST['id'], $_POST );
103
+ $message = "Form was Successfully Updated";
104
+ return $this->get_edit_vars($id, '', $message);
105
+ }
106
+ }
107
+
108
+ function duplicate(){
109
+ global $frm_form;
110
+
111
+ $params = $this->get_params();
112
+ $record = $frm_form->duplicate( $params['id'], $params['template'] );
113
+ $message = ($params['template'])?('Form template was Successfully Created'):('Form was Successfully Copied');
114
+ if ($record)
115
+ return $this->get_edit_vars($record, '', $message, true);
116
+ else
117
+ return $this->display_forms_list($params, 'There was a problem creating new template.');
118
+ }
119
+
120
+ function page_preview(){
121
+ global $frm_form;
122
+ $description = true;
123
+ $title = true;
124
+ $params = $this->get_params();
125
+ if (!$params['form']) return;
126
+ $form = $frm_form->getOne($params['form']);
127
+ require_once(FRM_VIEWS_PATH.'/frm-entries/frm-entry.php');
128
+ }
129
+
130
+ function preview(){
131
+ global $frm_form;
132
+ if ( !defined( 'ABSPATH' ) && !defined( 'XMLRPC_REQUEST' )) {
133
+ $root = dirname(dirname(dirname(dirname(__FILE__))));
134
+ include_once( $root.'/wp-config.php' );
135
+ $wp->init();
136
+ $wp->register_globals();
137
+ }
138
+
139
+ header("Content-Type: text/html; charset=utf-8");
140
+
141
+ $key = (isset($_GET['form'])?$_GET['form']:(isset($_POST['form'])?$_POST['form']:''));
142
+ $form = $frm_form->getAll("form_key='$key'",'',' LIMIT 1');
143
+ if (!$form) $form = $frm_form->getAll('','',' LIMIT 1');
144
+ $description = true;
145
+ $title = true;
146
+
147
+ require_once(FRM_VIEWS_PATH.'/frm-entries/direct.php');
148
+ }
149
+
150
+ function destroy(){
151
+ global $frm_form;
152
+ $params = $this->get_params();
153
+ if ($frm_form->destroy( $params['id'] ))
154
+ $message = "Form was Successfully Deleted";
155
+ $this->display_forms_list($params, $message, '', 1);
156
+ }
157
+
158
+ function destroy_wo_fields(){
159
+ global $frm_field, $frm_form;
160
+ $id = $_POST['form_id'];
161
+ if ($frm_field->getRecordCount('fi.form_id='.$id) <= 0)
162
+ $frm_form->destroy($id);
163
+ die();
164
+ }
165
+
166
+ function display_forms_list($params=false, $message='', $page_params_ov = false, $current_page_ov = false, $errors = array()){
167
+ global $wpdb, $frm_utils, $frm_form, $frm_entry, $frm_page_size, $frmpro_is_installed;
168
+
169
+ if(!$params)
170
+ $params = $this->get_params();
171
+
172
+ if($message=='')
173
+ $message = FrmAppHelper::frm_get_main_message();
174
+
175
+ $controller_file = FRM_PLUGIN_NAME;
176
+ $page_params = '';
177
+ $where_clause = " (status is NULL OR status = '' OR status = 'published') AND default_template=0 AND is_template = ".$params['template'];
178
+
179
+ if ($params['template']){
180
+ $default_templates = $frm_form->getAll('default_template=1');
181
+ $all_templates = $frm_form->getAll('is_template=1',' ORDER BY name');
182
+ }
183
+
184
+ $form_vars = $this->get_form_sort_vars($params, $where_clause);
185
+
186
+ if($current_page_ov)
187
+ $current_page = $current_page_ov;
188
+ else
189
+ $current_page = $params['paged'];
190
+
191
+ if($page_params_ov)
192
+ $page_params = $page_params_ov;
193
+ else
194
+ $page_params = $form_vars['page_params'];
195
+
196
+ $sort_str = $form_vars['sort_str'];
197
+ $sdir_str = $form_vars['sdir_str'];
198
+ $search_str = $form_vars['search_str'];
199
+
200
+ $record_count = $frm_form->getRecordCount($form_vars['where_clause']);
201
+ $page_count = $frm_form->getPageCount($frm_page_size,$form_vars['where_clause']);
202
+ $forms = $frm_form->getPage($current_page,$frm_page_size,$form_vars['where_clause'],$form_vars['order_by']);
203
+ $page_last_record = $frm_utils->getLastRecordNum($record_count,$current_page,$frm_page_size);
204
+ $page_first_record = $frm_utils->getFirstRecordNum($record_count,$current_page,$frm_page_size);
205
+ require_once($this->views . 'list.php');
206
+ }
207
+
208
+ function get_form_sort_vars($params,$where_clause = ''){
209
+ $order_by = '';
210
+ $page_params = '';
211
+
212
+ // These will have to work with both get and post
213
+ $sort_str = $params['sort'];
214
+ $sdir_str = $params['sdir'];
215
+ $search_str = $params['search'];
216
+
217
+ // Insert search string
218
+ if(!empty($search_str)){
219
+ $search_params = explode(" ", $search_str);
220
+
221
+ foreach($search_params as $search_param){
222
+ if(!empty($where_clause))
223
+ $where_clause .= " AND";
224
+
225
+ $where_clause .= " (name like '%$search_param%' OR description like '%$search_param%' OR created_at like '%$search_param%')";
226
+ }
227
+
228
+ $page_params .="&search=$search_str";
229
+ }
230
+
231
+ // make sure page params stay correct
232
+ if(!empty($sort_str))
233
+ $page_params .="&sort=$sort_str";
234
+
235
+ if(!empty($sdir_str))
236
+ $page_params .= "&sdir=$sdir_str";
237
+
238
+ // Add order by clause
239
+ switch($sort_str){
240
+ case "id":
241
+ case "name":
242
+ case "description":
243
+ case "form_key":
244
+ $order_by .= " ORDER BY $sort_str";
245
+ break;
246
+ default:
247
+ $order_by .= " ORDER BY name";
248
+ }
249
+
250
+ // Toggle ascending / descending
251
+ if((empty($sort_str) and empty($sdir_str)) or $sdir_str == 'asc'){
252
+ $order_by .= ' ASC';
253
+ $sdir_str = 'asc';
254
+ }else{
255
+ $order_by .= ' DESC';
256
+ $sdir_str = 'desc';
257
+ }
258
+
259
+ return array('order_by' => $order_by,
260
+ 'sort_str' => $sort_str,
261
+ 'sdir_str' => $sdir_str,
262
+ 'search_str' => $search_str,
263
+ 'where_clause' => $where_clause,
264
+ 'page_params' => $page_params);
265
+ }
266
+
267
+ function get_edit_vars($id, $errors = '', $message='', $create_link=false){
268
+ global $frm_app_helper, $frm_field_selection, $frm_entry, $frm_form, $frm_field, $frm_recaptcha_enabled, $frm_pro_field_selection, $frm_utils, $frmpro_is_installed;
269
+ $record = $frm_form->getOne( $id );
270
+ $items = $frm_entry->getAll('',' ORDER BY it.name');
271
+
272
+ $fields = $frm_field->getAll("fi.form_id=$id", ' ORDER BY field_order');
273
+ $values = $frm_app_helper->setup_edit_vars($record,'forms',$fields,true);
274
+ if ($values['default_template'])
275
+ wp_die('That template cannot be edited');
276
+ else if($create_link)
277
+ require_once($this->views . 'new.php');
278
+ else
279
+ require_once($this->views . 'edit.php');
280
+ }
281
+
282
+ function get_params(){
283
+ global $frm_app_controller;
284
+ $values = array();
285
+ foreach (array('template' => 0,'id' => '','paged' => 1,'form' => '','search' => '','sort' => '','sdir' => '') as $var => $default)
286
+ $values[$var] = $frm_app_controller->get_param($var, $default);
287
+
288
+ return $values;
289
+ }
290
+
291
+ function route(){
292
+ global $frm_app_controller;
293
+ $action = $frm_app_controller->get_param('action');
294
+ if($action=='new')
295
+ return $this->new_form();
296
+ else if($action=='create')
297
+ return $this->create();
298
+ else if($action=='edit')
299
+ return $this->edit();
300
+ else if($action=='update')
301
+ return $this->update();
302
+ else if($action=='duplicate')
303
+ return $this->duplicate();
304
+ else if($action == 'destroy')
305
+ return $this->destroy();
306
+ else if($action == 'list-form')
307
+ return $this->list_form();
308
+ else
309
+ return $this->display_forms_list();
310
+ }
311
+
312
+ }
313
+ ?>
classes/controllers/FrmSettingsController.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmSettingsController{
4
+ function FrmSettingsController(){
5
+ add_action('admin_menu', array( $this, 'menu' ), 25);
6
+ add_action('admin_head-'.FRM_PLUGIN_NAME.'-settings', array($this,'head'));
7
+ $this->views = FRM_VIEWS_PATH.'/frm-settings/';
8
+ }
9
+
10
+ function menu(){
11
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | Settings', 'Settings', 8, FRM_PLUGIN_NAME.'-settings', array($this,'route'));
12
+ //add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. FRM_PLUGIN_TITLE . ' Pro', FRM_PLUGIN_TITLE . ' Pro', 8, FRM_PLUGIN_NAME.'-pro-settings', array($this,'pro_settings'));
13
+ }
14
+
15
+ function head(){
16
+ $css_file = 'frm_admin.css';
17
+ $js_file = 'list-items.js';
18
+ require_once(FRM_VIEWS_PATH . '/shared/admin_head.php');
19
+ }
20
+
21
+ function display_form(){
22
+ global $frm_settings;
23
+
24
+ require_once($this->views . 'form.php');
25
+ }
26
+
27
+ function process_form(){
28
+ global $frm_settings;
29
+
30
+ $errors = $frm_settings->validate($_POST,$errors);
31
+
32
+ $frm_settings->update($_POST);
33
+
34
+ if( empty($errors) ){
35
+ $frm_settings->store();
36
+ $message = 'Settings Saved';
37
+ }
38
+
39
+ require_once($this->views . 'form.php');
40
+ }
41
+
42
+ function pro_settings(){
43
+ global $frm_utils, $frmpro_is_installed, $frm_app_controller;
44
+
45
+ $action = $frm_app_controller->get_param('action');
46
+ $errors = array();
47
+
48
+ // variables for the field and option names
49
+ $frmpro_username = 'frmpro_username';
50
+ $frmpro_password = 'frmpro_password';
51
+ $hidden_field_name = 'frm_update_options';
52
+
53
+ // Read in existing option value from database
54
+ $frmpro_username_val = get_option( $frmpro_username );
55
+ $frmpro_password_val = get_option( $frmpro_password );
56
+
57
+ if($action == 'force-pro-reinstall'){
58
+ $frm_utils->download_and_install_pro($frmpro_username_val, $frmpro_password_val, true);
59
+ $message = _e(FRM_PLUGIN_TITLE .' Pro Successfully Reinstalled.', FRM_PLUGIN_NAME );
60
+ }else if($action == 'pro-uninstall'){
61
+ $frm_utils->uninstall_pro();
62
+ $message = _e(FRM_PLUGIN_TITLE .' Pro Successfully Uninstalled.', FRM_PLUGIN_NAME );
63
+ }else{
64
+ // See if the user has posted us some information
65
+ // If they did, this hidden field will be set to 'Y'
66
+ if( $frm_app_controller->get_param('$hidden_field_name') == 'Y' ){
67
+ // Validate This
68
+ // This is where the remote username / password will be validated
69
+
70
+ // Read their posted value
71
+ $prlipro_username_val = stripslashes($_POST[ $prlipro_username ]);
72
+ $prlipro_password_val = stripslashes($_POST[ $prlipro_password ]);
73
+
74
+ $user_type = $prli_utils->get_pro_user_type($prlipro_username_val, $prlipro_password_val);
75
+ if(empty($user_type))
76
+ $errors[] = "Your user account couldn't be validated...";
77
+
78
+ if( count($errors) > 0 ){
79
+ require(FRM_VIEWS_PATH.'/shared/errors.php');
80
+ }else{
81
+ // Save the posted value in the database
82
+ update_option( $frmpro_username, $frmpro_username_val );
83
+ update_option( $frmpro_password, $frmpro_password_val );
84
+
85
+ // Put an options updated message on the screen
86
+ $message = $prli_utils->download_and_install_pro($prlipro_username_val, $prlipro_password_val);
87
+
88
+ $message = (($message == 'SUCCESS')?FRM_PLUGIN_TITLE. 'has been installed':$message);
89
+ }
90
+ }
91
+ }
92
+ require_once($this->views . 'pro-settings.php');
93
+ }
94
+
95
+ function route(){
96
+ global $frm_app_controller;
97
+ $action = $frm_app_controller->get_param('action');
98
+ if($action=='process-form')
99
+ return $this->process_form();
100
+ else
101
+ return $this->display_form();
102
+ }
103
+ }
104
+ ?>
classes/controllers/FrmStatisticsController.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmStatisticsController{
4
+ function FrmStatisticsController(){
5
+ add_action('admin_menu', array( $this, 'menu' ), 30);
6
+ $this->views = FRM_VIEWS_PATH.'/frm-statistics/';
7
+ }
8
+
9
+ function menu(){
10
+ global $frmpro_is_installed;
11
+ if(!$frmpro_is_installed)
12
+ add_submenu_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE .' | Pro Statistics', 'Pro Statistics', 8, FRM_PLUGIN_TITLE.'-statistics',array($this,''));
13
+ }
14
+
15
+ function list_entries(){
16
+ require_once($this->views .'list.php');
17
+ }
18
+
19
+ }
20
+
21
+ ?>
classes/helpers/FrmAppHelper.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmAppHelper{
4
+ function FrmAppHelper(){}
5
+
6
+ function get_pages(){
7
+ return get_posts( array('post_type' => 'page', 'post_status' => 'published', 'numberposts' => 99, 'order_by' => 'post_title', 'order' => 'ASC'));
8
+ }
9
+
10
+ function value_is_selected($field_name, $field_value, $selected_value){
11
+ if( (isset($_POST[$field_name]) and $_POST[$field_name] == $selected_value) or (!isset($_POST[$field_name]) and $field_value == $selected_value) )
12
+ echo ' selected="selected"';
13
+ }
14
+
15
+ function value_is_checked($field_name, $field_value){
16
+ if( (isset($_POST) and $_POST[$field_name] == '1') or (!isset($_POST) and $field_value == '1') )
17
+ echo ' checked="checked"';
18
+ }
19
+
20
+ function value_is_checked_with_array($field_name, $index, $field_value){
21
+ if( ( $_POST['action'] == 'process_form' and isset( $_POST[ $field_name ][ $index ] ) ) or ( $_POST['action'] != 'process_form' and isset($field_value) ) )
22
+ echo ' checked="checked"';
23
+ }
24
+
25
+ function get_unique_key($name='', $table_name, $column, $id = 0,$num_chars = 6){
26
+ global $wpdb;
27
+
28
+ if ($name == ''){
29
+ $max_slug_value = pow(36,$num_chars);
30
+ $min_slug_value = 37; // we want to have at least 2 characters in the slug
31
+ $key = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
32
+ }else
33
+ $key = sanitize_title_with_dashes($name);
34
+
35
+ $query = "SELECT $column FROM $table_name WHERE $column = %s AND ID != %d LIMIT 1";
36
+ $key_check = $wpdb->get_var($wpdb->prepare($query, $key, $id));
37
+ if ($key_check){
38
+ $suffix = 2;
39
+ do {
40
+ $alt_post_name = substr($key, 0, 200-(strlen($suffix)+1)). "$suffix";
41
+ $key_check = $wpdb->get_var($wpdb->prepare($query, $alt_post_name, $id));
42
+ $suffix++;
43
+ } while ($key_check);
44
+ $key = $alt_post_name;
45
+ }
46
+ return $key;
47
+ }
48
+
49
+ function setup_edit_vars($record, $table, $fields='', $default=false){
50
+ if(!$record) return false;
51
+ global $frm_entry_meta, $frm_form, $frm_app_controller;
52
+ $values = array();
53
+
54
+ $values['id'] = $record->id;
55
+
56
+ foreach (array('name' => $record->name, 'description' => $record->description) as $var => $default_val)
57
+ $values[$var] = stripslashes($frm_app_controller->get_param($var, $default_val));
58
+
59
+ $values['form_name'] = ($record->form_id)?($frm_form->getName( $record->form_id )):('');
60
+
61
+ $values['fields'] = array();
62
+ if ($fields){
63
+ foreach($fields as $field){
64
+
65
+ if ($default)
66
+ $meta_value = $field->default_value;
67
+ else
68
+ $meta_value = $frm_entry_meta->get_entry_meta_by_field($record->id, $field->id, true);
69
+
70
+ $field_options = stripslashes_deep(unserialize($field->field_options));
71
+
72
+ $new_value = (isset($_POST['item_meta'][$field->id])) ? $_POST['item_meta'][$field->id] : $meta_value;
73
+ if ($field->type != 'checkbox')
74
+ $new_value = stripslashes($new_value);
75
+
76
+ $field_array = array('id' => $field->id,
77
+ 'value' => $new_value,
78
+ 'default_value' => stripslashes($field->default_value),
79
+ 'name' => stripslashes($field->name),
80
+ 'description' => stripslashes($field->description),
81
+ 'type' => apply_filters('frm_field_type',$field->type),
82
+ 'options' => stripslashes_deep(unserialize($field->options)),
83
+ 'required' => $field->required,
84
+ 'field_key' => $field->field_key,
85
+ 'field_order' => $field->field_order,
86
+ 'form_id' => $field->form_id);
87
+
88
+ foreach (array('size' => 75,'max' => '','label' => 'top','invalid' => '','required_indicator' => '*','blank' => '') as $opt => $default_opt)
89
+ $field_array[$opt] = ($_POST and isset($_POST['field_options'][$opt.'_'.$field->id]) ) ? $_POST['field_options'][$opt.'_'.$field->id] : (isset($field_options[$opt]) ? $field_options[$opt]: $default_opt);
90
+
91
+ $values['fields'][] = apply_filters('frm_setup_edit_fields_vars', $field_array, $field);
92
+ }
93
+ }
94
+
95
+ if ($table == 'entries')
96
+ $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
97
+ else if ($table == 'forms')
98
+ $values = FrmFormsHelper::setup_edit_vars( $values, $record );
99
+
100
+ return $values;
101
+ }
102
+
103
+ function frm_get_main_message( $message = ''){
104
+ /*
105
+ global $frmpro_is_installed;
106
+ include_once(ABSPATH."/wp-includes/class-IXR.php");
107
+
108
+ if($frmpro_is_installed){
109
+ $client = new IXR_Client('http://prettylinkpro.com/xmlrpc.php');
110
+ if ($client->query('prlipro.get_main_message'))
111
+ $message = $client->getResponse();
112
+ }else{
113
+ $client = new IXR_Client('http://blairwilliams.com/xmlrpc.php');
114
+ if ($client->query('prli.get_main_message'))
115
+ $message = $client->getResponse();
116
+ } */
117
+ return $message;
118
+ }
119
+
120
+ function display_recaptcha($errors) {
121
+ global $recaptcha_opt;
122
+
123
+ $format = <<<END
124
+ <script type='text/javascript'>var RecaptchaOptions={theme:'{$recaptcha_opt['re_theme_reg']}',lang:'{$recaptcha_opt['re_lang']}',tabindex:30};</script>
125
+ END;
126
+
127
+ $comment_string = <<<COMMENT_FORM
128
+ <script type='text/javascript'>document.getElementById('recaptcha_table').style.direction='ltr';</script>
129
+ COMMENT_FORM;
130
+
131
+ $use_ssl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? true : false;
132
+
133
+ if (IS_WPMU){
134
+ $error = $errors->get_error_message('captcha');
135
+ echo($error ? '<p class="error">'.$error.'</p>' : '');
136
+ }
137
+ echo $format . recaptcha_wp_get_html(isset($_GET['rerror'])?$_GET['rerror']:'', $use_ssl);
138
+ }
139
+
140
+ }
141
+
142
+ ?>
classes/helpers/FrmEntriesHelper.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmEntriesHelper{
4
+
5
+ function setup_new_vars($fields){
6
+ global $frm_app_controller, $frm_form;
7
+ $values = array();
8
+ foreach (array('name' => '', 'description' => '', 'item_key' => '') as $var => $default)
9
+ $values[$var] = stripslashes($frm_app_controller->get_param($var, $default));
10
+
11
+ $values['fields'] = array();
12
+ if ($fields){
13
+ foreach($fields as $field){
14
+ $default = $field->default_value;
15
+
16
+ $field_options = unserialize($field->field_options);
17
+ $new_value = ($_POST and isset($_POST['item_meta'][$field->id])) ? $_POST['item_meta'][$field->id] : $default;
18
+ if ($field->type != 'checkbox')
19
+ $new_value = stripslashes($new_value);
20
+
21
+ $field_array = array('id' => $field->id,
22
+ 'value' => $new_value,
23
+ 'default_value' => $new_value,
24
+ 'name' => stripslashes($field->name),
25
+ 'description' => stripslashes($field->description),
26