Formidable Forms – Form Builder for WordPress - Version 1.03.03

Version Description

  • Added options to allow users other than admins to access Formidable
  • Added uninstall button
  • Fixed multiple submissions for pages with multiple forms
  • PRO: Added [frm-graph] shortcode for front-end graphical reports! Default values: [frm-graph id=x include_js=1 colors="#EF8C08,#21759B,#1C9E05" bg_color="#FFFFFF" height=400 width=400]. Show multiple fields with [frm-graph id="x,y,z"]
  • PRO: Added "value" parameter to the frm-stats shortcode for counting number of entries with specified value [frm-stats id=8 value="Hello" type=count]
  • PRO: Added a field drop-down for searching specific fields on the entries page
  • PRO: Added option to allow users to edit any entry instead of only their own and other user-role options
  • PRO: Added calendar format option on the Formidable Settings page
  • PRO: Changed "entry_id" in the "display-frm-data" to accept multiple entry IDs. ex: [display-frm-data id=x entry_id="34,35,36"]
  • PRO: Added "equals" option to if statements. ex: [if 283 equals=hello]show this if the field with id 283 equals hello[/if 283]
Download this release

Release Info

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

Code changes from version 1.02.01 to 1.03.03

Files changed (60) hide show
  1. classes/controllers/FrmAppController.php +75 -137
  2. classes/controllers/FrmEntriesController.php +24 -19
  3. classes/controllers/FrmFieldsController.php +42 -16
  4. classes/controllers/FrmFormsController.php +58 -34
  5. classes/controllers/FrmSettingsController.php +11 -16
  6. classes/controllers/FrmStatisticsController.php +2 -2
  7. classes/helpers/FrmAppHelper.php +90 -19
  8. classes/helpers/FrmEntriesHelper.php +15 -10
  9. classes/helpers/FrmFieldsHelper.php +22 -15
  10. classes/helpers/FrmFormsHelper.php +43 -14
  11. classes/models/FrmDb.php +202 -0
  12. classes/models/FrmEntry.php +39 -49
  13. classes/models/FrmEntryMeta.php +36 -39
  14. classes/models/FrmField.php +20 -21
  15. classes/models/FrmForm.php +30 -29
  16. classes/models/FrmNotification.php +19 -38
  17. classes/models/FrmSettings.php +63 -4
  18. classes/models/FrmUpdate.php +24 -9
  19. classes/views/frm-entries/direct.php +1 -7
  20. classes/views/frm-entries/form.php +6 -4
  21. classes/views/frm-entries/frm-entry.php +11 -3
  22. classes/views/frm-entries/list.php +3 -2
  23. classes/views/frm-entries/new.php +2 -5
  24. classes/views/frm-fields/input.php +7 -7
  25. classes/views/frm-fields/radio.php +1 -1
  26. classes/views/frm-fields/single-option.php +2 -2
  27. classes/views/frm-forms/add_field.php +55 -47
  28. classes/views/frm-forms/add_field_links.php +21 -21
  29. classes/views/frm-forms/default-templates.php +16 -15
  30. classes/views/frm-forms/edit.php +2 -2
  31. classes/views/frm-forms/footer.php +34 -56
  32. classes/views/frm-forms/form.php +77 -39
  33. classes/views/frm-forms/list.php +66 -43
  34. classes/views/frm-forms/new-field-js.php +1 -1
  35. classes/views/frm-forms/new-selection.php +1 -1
  36. classes/views/frm-forms/new.php +2 -2
  37. classes/views/frm-settings/form.php +58 -10
  38. classes/views/frm-statistics/list.php +1 -1
  39. classes/views/shared/item-table-nav.php +4 -4
  40. classes/views/shared/nav.php +14 -4
  41. classes/views/shared/pagination.php +12 -6
  42. css/frm_admin.css +122 -172
  43. formidable.php +31 -6
  44. images/add.png +0 -0
  45. images/black_arrow.png +0 -0
  46. images/black_arrow_big.png +0 -0
  47. images/readonly.png +0 -0
  48. images/required.png +0 -0
  49. images/tooltip.png +0 -0
  50. js/formidable.js +163 -25
  51. js/jquery/jquery-1.3.2.min.js +0 -19
  52. js/jquery/jquery-ui-1.7.2.min.js +0 -10
  53. js/jquery/jquery-ui-datepicker.js +0 -12
  54. js/jquery/jquery-ui-themepicker.js +1 -4
  55. js/jquery/jquery.editinplace.js +10 -9
  56. js/jquery/jquery.editinplace.packed.js +7 -7
  57. js/jquery/jquery.elastic.js +1 -0
  58. js/jquery/jquery.tools.min.js +20 -0
  59. readme.txt +84 -24
  60. screenshot-1.png +0 -0
classes/controllers/FrmAppController.php CHANGED
@@ -2,33 +2,60 @@
2
 
3
  class FrmAppController{
4
  function FrmAppController(){
5
- add_action('admin_menu', array( $this, 'menu' ));
6
- add_filter( 'plugin_action_links_'.FRM_PLUGIN_NAME.'/'.FRM_PLUGIN_NAME.'.php', array( $this, 'settings_link'), 10, 2 );
7
- add_action('after_plugin_row_'.FRM_PLUGIN_NAME.'/'.FRM_PLUGIN_NAME.'.php', array( $this,'frmpro_action_needed'));
8
- add_action('admin_notices', array( $this,'frmpro_get_started_headline'));
9
- add_filter('the_content', array( $this, 'page_route' ), 1);
10
- add_action('init', array($this, 'front_head'));
11
- add_action('admin_init', array( $this, 'admin_js'));
12
- register_activation_hook(FRM_PATH."/formidable.php", array( $this, 'install' ));
 
 
13
 
14
  // Used to process standalone requests
15
- add_action('init', array($this,'parse_standalone_request'));
16
 
17
  //Shortcodes
18
- add_shortcode('formidable', array($this,'get_form_shortcode'));
19
- add_filter( 'widget_text', array($this,'widget_text_filter'), 9 );
20
  }
21
 
22
  function menu(){
23
- global $frm_forms_controller;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- add_menu_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE, 8, FRM_PLUGIN_NAME, array($frm_forms_controller,'route'), FRM_URL . '/images/icon_16.png');
 
 
26
  }
27
 
28
  // Adds a settings link to the plugins page
29
  function settings_link($links, $file){
30
  $settings = '<a href="'.admin_url('admin.php?page='.FRM_PLUGIN_NAME).'">' . __('Settings', FRM_PLUGIN_NAME) . '</a>';
31
  array_unshift($links, $settings);
 
32
  return $links;
33
  }
34
 
@@ -65,140 +92,51 @@ class FrmAppController{
65
  }
66
  }
67
 
68
- function head(){
69
- $css_file = FRM_URL. '/css/frm_admin.css';
70
- $js_file = FRM_URL . '/js/formidable.js';
71
- require(FRM_VIEWS_PATH . '/shared/head.php');
72
- }
73
-
74
  function admin_js(){
75
- wp_enqueue_script('jQuery');
76
- wp_enqueue_script('jQuery-ui', FRM_URL.'/js/jquery/jquery-ui-1.7.2.min.js', '', '1.7.2');
77
- add_thickbox();
 
 
 
 
 
 
 
 
 
 
78
  }
79
 
80
  function front_head(){
 
 
81
  if (IS_WPMU){
82
- $db_version = 1.01; // this is the version of the database we're moving to
83
  $old_db_version = get_option('frm_db_version');
84
  if ($db_version != $old_db_version)
85
  $this->install();
86
  }
87
- //if (!is_admin()){
88
- $css = apply_filters('get_frm_stylesheet', FRM_URL .'/css/frm_display.css');
89
- wp_enqueue_style('frm-forms', $css);
90
- //}
 
91
  }
92
 
93
  function install(){
94
- global $wpdb, $frm_form, $frm_field, $frm_app_helper;
95
- $db_version = 1.01; // this is the version of the database we're moving to
96
- $old_db_version = get_option('frm_db_version');
97
-
98
- if ($db_version != $old_db_version){
99
- $fields_table = $wpdb->prefix . "frm_fields";
100
- $forms_table = $wpdb->prefix . "frm_forms";
101
- $items_table = $wpdb->prefix . "frm_items";
102
- $item_metas_table = $wpdb->prefix . "frm_item_metas";
103
-
104
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
105
-
106
- $charset_collate = '';
107
- if( $wpdb->has_cap( 'collation' ) ){
108
- if( !empty($wpdb->charset) )
109
- $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
110
- if( !empty($wpdb->collate) )
111
- $charset_collate .= " COLLATE $wpdb->collate";
112
- }
113
-
114
- /* Create/Upgrade Fields Table */
115
- $sql = "CREATE TABLE {$fields_table} (
116
- id int(11) NOT NULL auto_increment,
117
- field_key varchar(255) default NULL,
118
- name varchar(255) default NULL,
119
- description text default NULL,
120
- type text default NULL,
121
- default_value longtext default NULL,
122
- options longtext default NULL,
123
- field_order int(11) default 0,
124
- required int(1) default NULL,
125
- field_options longtext default NULL,
126
- form_id int(11) default NULL,
127
- created_at datetime NOT NULL,
128
- PRIMARY KEY (id),
129
- KEY form_id (form_id)
130
- ) {$charset_collate};";
131
-
132
- dbDelta($sql);
133
-
134
- /* Create/Upgrade Forms Table */
135
- $sql = "CREATE TABLE {$forms_table} (
136
- id int(11) NOT NULL auto_increment,
137
- form_key varchar(255) default NULL,
138
- name varchar(255) default NULL,
139
- description text default NULL,
140
- logged_in boolean default NULL,
141
- editable boolean default NULL,
142
- is_template boolean default 0,
143
- default_template boolean default 0,
144
- status varchar(255) default NULL,
145
- prli_link_id int(11) default NULL,
146
- options longtext default NULL,
147
- created_at datetime NOT NULL,
148
- PRIMARY KEY (id)
149
- ) {$charset_collate};";
150
-
151
- dbDelta($sql);
152
-
153
- /* Create/Upgrade Items Table */
154
- $sql = "CREATE TABLE {$items_table} (
155
- id int(11) NOT NULL auto_increment,
156
- item_key varchar(255) default NULL,
157
- name varchar(255) default NULL,
158
- description text default NULL,
159
- form_id int(11) default NULL,
160
- created_at datetime NOT NULL,
161
- PRIMARY KEY (id),
162
- KEY form_id (form_id)
163
- ) {$charset_collate};";
164
-
165
- dbDelta($sql);
166
-
167
- /* Create/Upgrade Meta Table */
168
- $sql = "CREATE TABLE {$item_metas_table} (
169
- id int(11) NOT NULL auto_increment,
170
- meta_key varchar(255) default NULL,
171
- meta_value longtext default NULL,
172
- field_id int(11) NOT NULL,
173
- item_id int(11) NOT NULL,
174
- created_at datetime NOT NULL,
175
- PRIMARY KEY (id),
176
- KEY field_id (field_id),
177
- KEY item_id (item_id)
178
- ) {$charset_collate};";
179
-
180
- dbDelta($sql);
181
-
182
- /**** ADD DEFAULT TEMPLATES ****/
183
- $templates = glob(FRM_TEMPLATES_PATH."/*.php");
184
-
185
- for($i = count($templates) - 1; $i >= 0; $i--){
186
- $filename = preg_replace("#".FRM_TEMPLATES_PATH."/#","",$templates[$i]);
187
- $filename = str_replace('.php','', $filename);
188
- $form = $frm_form->getAll("form_key='{$filename}' and is_template='1' and default_template='1'", '', ' LIMIT 1');
189
- $values = FrmFormsHelper::setup_new_vars();
190
- $values['form_key'] = $filename;
191
- $values['is_template'] = $values['default_template'] = 1;
192
- require_once($templates[$i]);
193
- }
194
-
195
- /***** SAVE DB VERSION *****/
196
- update_option('frm_db_version',$db_version);
197
- }
198
-
199
- do_action('frm_after_install');
200
  }
201
 
 
 
 
 
 
 
 
 
202
 
203
  // Routes for wordpress pages -- we're just replacing content here folks.
204
  function page_route($content){
@@ -229,10 +167,9 @@ class FrmAppController{
229
  function standalone_route($controller, $action=''){
230
  global $frm_forms_controller;
231
 
232
- if($controller=='forms'){
233
- //if($action=='preview')
234
  $frm_forms_controller->preview($this->get_param('form'));
235
- }else
236
  do_action('frm_standalone_route', $controller, $action);
237
  }
238
 
@@ -244,7 +181,8 @@ class FrmAppController{
244
 
245
  function get_form_shortcode($atts){
246
  global $frm_entries_controller;
247
- extract(shortcode_atts(array('id' => '', 'key' => '', 'title' => false, 'description' => false), $atts));
 
248
  return $frm_entries_controller->show_form($id, $key, $title, $description);
249
  }
250
 
2
 
3
  class FrmAppController{
4
  function FrmAppController(){
5
+ add_action('admin_menu', array( &$this, 'menu' ), 1);
6
+ add_filter('frm_nav_array', array( &$this, 'frm_nav'), 1);
7
+ add_filter('plugin_action_links_'.FRM_PLUGIN_NAME.'/'.FRM_PLUGIN_NAME.'.php', array( &$this, 'settings_link'), 10, 2 );
8
+ add_action('after_plugin_row_'.FRM_PLUGIN_NAME.'/'.FRM_PLUGIN_NAME.'.php', array( &$this,'frmpro_action_needed'));
9
+ add_action('admin_notices', array( &$this,'frmpro_get_started_headline'));
10
+ add_filter('the_content', array( &$this, 'page_route' ), 1);
11
+ add_action('init', array(&$this, 'front_head'));
12
+ add_action('admin_init', array( &$this, 'admin_js'));
13
+ register_activation_hook(FRM_PATH."/formidable.php", array( &$this, 'install' ));
14
+ add_action('wp_ajax_frm_uninstall', array(&$this, 'uninstall') );
15
 
16
  // Used to process standalone requests
17
+ add_action('init', array(&$this,'parse_standalone_request'));
18
 
19
  //Shortcodes
20
+ add_shortcode('formidable', array(&$this,'get_form_shortcode'));
21
+ add_filter( 'widget_text', array(&$this,'widget_text_filter'), 9 );
22
  }
23
 
24
  function menu(){
25
+ if(current_user_can('administrator') and !current_user_can('frm_view_forms')){
26
+ global $wp_roles;
27
+ $frm_roles = FrmAppHelper::frm_capabilities();
28
+ foreach($frm_roles as $frm_role => $frm_role_description)
29
+ $wp_roles->add_cap( 'administrator', $frm_role );
30
+ }
31
+ global $frmpro_is_installed;
32
+ if(current_user_can('frm_view_forms')){
33
+ global $frm_forms_controller;
34
+ add_menu_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE, 'frm_view_forms', FRM_PLUGIN_NAME, array($frm_forms_controller,'route'), FRM_URL . '/images/icon_16.png');
35
+ }elseif(current_user_can('frm_view_entries') and $frmpro_is_installed){
36
+ global $frmpro_entries_controller;
37
+ add_menu_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE, 'frm_view_entries', FRM_PLUGIN_NAME, array($frmpro_entries_controller,'route'), FRM_URL . '/images/icon_16.png');
38
+ }
39
+ }
40
+
41
+ function frm_nav(){
42
+ $nav = array();
43
+ if(current_user_can('frm_view_forms'))
44
+ $nav[FRM_PLUGIN_NAME] = __('Forms', FRM_PLUGIN_NAME);
45
+
46
+ if(current_user_can('frm_edit_forms'))
47
+ $nav[FRM_PLUGIN_NAME . '-new'] = __('Create a Form', FRM_PLUGIN_NAME);
48
 
49
+ if(current_user_can('frm_view_forms'))
50
+ $nav[FRM_PLUGIN_NAME . '-templates'] = __('Templates', FRM_PLUGIN_NAME);
51
+ return $nav;
52
  }
53
 
54
  // Adds a settings link to the plugins page
55
  function settings_link($links, $file){
56
  $settings = '<a href="'.admin_url('admin.php?page='.FRM_PLUGIN_NAME).'">' . __('Settings', FRM_PLUGIN_NAME) . '</a>';
57
  array_unshift($links, $settings);
58
+
59
  return $links;
60
  }
61
 
92
  }
93
  }
94
 
 
 
 
 
 
 
95
  function admin_js(){
96
+ global $frm_version;
97
+ wp_enqueue_script('jquery');
98
+ wp_enqueue_script('jquery-ui-core');
99
+ if(!(isset($_GET) and isset($_GET['page'])) or (isset($_GET['page']) and preg_match('/formidable*/', $_GET['page'])))
100
+ wp_enqueue_script('jquery-tools', FRM_URL.'/js/jquery/jquery.tools.min.js', array('jquery'), '1.1.2');
101
+ if(isset($_GET) and isset($_GET['page']) and preg_match('/formidable*/', $_GET['page'])){
102
+ wp_enqueue_script('jquery-ui-sortable');
103
+ wp_enqueue_script('jquery-ui-draggable');
104
+ wp_enqueue_script('formidable', FRM_URL . '/js/formidable.js', array('jquery'), $frm_version);
105
+ wp_enqueue_style('formidable-admin', FRM_URL. '/css/frm_admin.css', $frm_version);
106
+ wp_enqueue_script('jquery-elastic', FRM_URL.'/js/jquery/jquery.elastic.js', array('jquery'));
107
+ add_thickbox();
108
+ }
109
  }
110
 
111
  function front_head(){
112
+ global $frm_settings, $frm_version;
113
+
114
  if (IS_WPMU){
115
+ $db_version = 1.03; // this is the version of the database we're moving to
116
  $old_db_version = get_option('frm_db_version');
117
  if ($db_version != $old_db_version)
118
  $this->install();
119
  }
120
+
121
+ if(!is_admin() and !$frm_settings->custom_stylesheet){
122
+ $css = apply_filters('get_frm_stylesheet', FRM_URL .'/css/frm_display.css');
123
+ wp_enqueue_style('frm-forms', $css, array(), $frm_version);
124
+ }
125
  }
126
 
127
  function install(){
128
+ global $frmdb;
129
+ $frmdb->upgrade();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  }
131
 
132
+ function uninstall(){
133
+ if(current_user_can('administrator')){
134
+ global $frmdb;
135
+ $frmdb->uninstall();
136
+ wp_die(__('Formidable was successfully uninstalled.', 'formidable'));
137
+ }else
138
+ wp_die(__('You don\'t have permission to do that!', 'formidable'));
139
+ }
140
 
141
  // Routes for wordpress pages -- we're just replacing content here folks.
142
  function page_route($content){
167
  function standalone_route($controller, $action=''){
168
  global $frm_forms_controller;
169
 
170
+ if($controller=='forms' and $action != 'export' and $action != 'import')
 
171
  $frm_forms_controller->preview($this->get_param('form'));
172
+ else
173
  do_action('frm_standalone_route', $controller, $action);
174
  }
175
 
181
 
182
  function get_form_shortcode($atts){
183
  global $frm_entries_controller;
184
+ extract(shortcode_atts(array('id' => '', 'key' => '', 'title' => false, 'description' => false, 'readonly' => false, 'entry_id' => false, 'fields' => array()), $atts));
185
+ do_action('formidable_shortcode_atts', compact('id', 'key', 'title', 'description', 'readonly', 'entry_id', 'fields'));
186
  return $frm_entries_controller->show_form($id, $key, $title, $description);
187
  }
188
 
classes/controllers/FrmEntriesController.php CHANGED
@@ -4,22 +4,17 @@ class FrmEntriesController{
4
  var $views;
5
 
6
  function FrmEntriesController(){
7
- add_action('admin_menu', array( $this, 'menu' ), 20);
8
  }
9
 
10
  function menu(){
11
  global $frmpro_is_installed;
12
  if(!$frmpro_is_installed){
13
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' |'. __('Pro Entries', FRM_PLUGIN_NAME), __('Pro Entries', FRM_PLUGIN_NAME), 8, FRM_PLUGIN_NAME.'-entries',array($this,'list_entries'));
14
- add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-entries', array($this,'head'));
15
  }
16
  }
17
 
18
- function head(){
19
- $css_file = FRM_URL. '/css/frm_admin.css';
20
- include(FRM_VIEWS_PATH . '/shared/head.php');
21
- }
22
-
23
  function list_entries(){
24
  require_once(FRM_VIEWS_PATH.'/frm-entries/list.php');
25
  }
@@ -28,11 +23,21 @@ class FrmEntriesController{
28
  global $frm_form, $user_ID;
29
  if ($id) $form = $frm_form->getOne($id);
30
  else if ($key) $form = $frm_form->getOne($key);
 
 
31
  if (!$form or $form->is_template or $form->status == 'draft')
32
  return __('Please select a valid form', FRM_PLUGIN_NAME);
33
- else if ($form->logged_in and !$user_ID)
34
- return __('You must log in', FRM_PLUGIN_NAME);
35
- else
 
 
 
 
 
 
 
 
36
  return FrmEntriesController::get_form(FRM_VIEWS_PATH.'/frm-entries/frm-entry.php', $form, $title, $description);
37
  }
38
 
@@ -48,21 +53,21 @@ class FrmEntriesController{
48
  }
49
 
50
  function get_params($form=null){
51
- global $frm_app_controller, $frm_form;
52
 
53
  if(!$form)
54
  $form = $frm_form->getAll('',' ORDER BY name',' LIMIT 1');
55
 
56
- $action = apply_filters('frm_show_new_entry_page','new',$form);
57
  $default_values = array('id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id, 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action);
58
 
59
- $posted_form_id = $frm_app_controller->get_param('form_id');
60
- if ($posted_form_id == '')
61
- $posted_form_id = $frm_app_controller->get_param('form');
62
-
63
- if ($form->id == $posted_form_id){
64
  foreach ($default_values as $var => $default)
65
- $values[$var] = $frm_app_controller->get_param($var, $default);
66
  }else{
67
  foreach ($default_values as $var => $default)
68
  $values[$var] = $default;
4
  var $views;
5
 
6
  function FrmEntriesController(){
7
+ add_action('admin_menu', array( &$this, 'menu' ), 20);
8
  }
9
 
10
  function menu(){
11
  global $frmpro_is_installed;
12
  if(!$frmpro_is_installed){
13
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' |'. __('Pro Entries', FRM_PLUGIN_NAME), __('Pro Entries', FRM_PLUGIN_NAME), 'administrator', FRM_PLUGIN_NAME.'-entries',array($this,'list_entries'));
14
+ //add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-entries', array($this,'head'));
15
  }
16
  }
17
 
 
 
 
 
 
18
  function list_entries(){
19
  require_once(FRM_VIEWS_PATH.'/frm-entries/list.php');
20
  }
23
  global $frm_form, $user_ID;
24
  if ($id) $form = $frm_form->getOne($id);
25
  else if ($key) $form = $frm_form->getOne($key);
26
+
27
+ $form_options = stripslashes_deep(maybe_unserialize($form->options));
28
  if (!$form or $form->is_template or $form->status == 'draft')
29
  return __('Please select a valid form', FRM_PLUGIN_NAME);
30
+ else if ($form->logged_in and !$user_ID){
31
+ global $frm_settings;
32
+ return $frm_settings->login_msg;
33
+ }else if($form->logged_in and $user_ID and isset($form_options['logged_in_role']) and $form_options['logged_in_role'] != ''){
34
+ if(FrmAppHelper::user_has_permission($form_options['logged_in_role']))
35
+ return FrmEntriesController::get_form(FRM_VIEWS_PATH.'/frm-entries/frm-entry.php', $form, $title, $description);
36
+ else{
37
+ global $frm_settings;
38
+ return $frm_settings->login_msg;
39
+ }
40
+ }else
41
  return FrmEntriesController::get_form(FRM_VIEWS_PATH.'/frm-entries/frm-entry.php', $form, $title, $description);
42
  }
43
 
53
  }
54
 
55
  function get_params($form=null){
56
+ global $frm_form;
57
 
58
  if(!$form)
59
  $form = $frm_form->getAll('',' ORDER BY name',' LIMIT 1');
60
 
61
+ $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param('action', 'new'), $form);
62
  $default_values = array('id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id, 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action);
63
 
64
+ $values['posted_form_id'] = FrmAppHelper::get_param('form_id');
65
+ if (!is_numeric($values['posted_form_id']))
66
+ $values['posted_form_id'] = FrmAppHelper::get_param('form');
67
+
68
+ if ($form->id == $values['posted_form_id']){ //if there are two forms on the same page, make sure not to submit both
69
  foreach ($default_values as $var => $default)
70
+ $values[$var] = FrmAppHelper::get_param($var, $default);
71
  }else{
72
  foreach ($default_values as $var => $default)
73
  $values[$var] = $default;
classes/controllers/FrmFieldsController.php CHANGED
@@ -2,23 +2,24 @@
2
 
3
  class FrmFieldsController{
4
  function FrmFieldsController(){
5
- add_action('wp_ajax_frm_insert_field', array($this, 'create') );
6
- add_action('wp_ajax_frm_field_name_in_place_edit', array($this, 'edit_name') );
7
- add_action('wp_ajax_frm_field_desc_in_place_edit', array($this, 'edit_description') );
8
- add_action('wp_ajax_frm_mark_required', array($this, 'mark_required') );
9
- add_action('wp_ajax_frm_clear_on_focus', array($this, 'clear_on_focus') );
10
- add_action('wp_ajax_frm_default_blank', array($this, 'default_blank') );
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
- add_filter('frm_field_type',array( $this, 'change_type'));
17
- add_filter('frm_display_field_options', array($this, 'display_field_options'));
 
18
  }
19
 
20
  function create(){
21
- global $frm_field;
22
  $field_data = $_POST['field'];
23
  $form_id = $_POST['form_id'];
24
 
@@ -39,7 +40,7 @@ class FrmFieldsController{
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);
@@ -88,7 +89,7 @@ class FrmFieldsController{
88
 
89
  /* Field Options */
90
  function add_option(){
91
- global $frm_field;
92
 
93
  $id = $_POST['field_id'];
94
  $field = $frm_field->getOne($id);
@@ -169,5 +170,30 @@ class FrmFieldsController{
169
 
170
  return $display;
171
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  }
173
  ?>
2
 
3
  class FrmFieldsController{
4
  function FrmFieldsController(){
5
+ add_action('wp_ajax_frm_insert_field', array(&$this, 'create') );
6
+ add_action('wp_ajax_frm_field_name_in_place_edit', array(&$this, 'edit_name') );
7
+ add_action('wp_ajax_frm_field_desc_in_place_edit', array(&$this, 'edit_description') );
8
+ add_action('wp_ajax_frm_mark_required', array(&$this, 'mark_required') );
9
+ add_action('wp_ajax_frm_clear_on_focus', array(&$this, 'clear_on_focus') );
10
+ add_action('wp_ajax_frm_default_blank', array(&$this, 'default_blank') );
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
+ add_filter('frm_field_type',array( &$this, 'change_type'));
17
+ add_filter('frm_display_field_options', array(&$this, 'display_field_options'));
18
+ add_action('frm_field_input_html', array(&$this,'input_html'));
19
  }
20
 
21
  function create(){
22
+ global $frm_field, $frm_ajax_url;
23
  $field_data = $_POST['field'];
24
  $form_id = $_POST['form_id'];
25
 
40
  function edit_name(){
41
  global $frm_field;
42
  $id = str_replace('field_', '', $_POST['element_id']);
43
+ $values = array('name' => trim($_POST['update_value']));
44
  if ($_POST['original_html'] == 'Untitled')
45
  $values['field_key'] = $_POST['update_value'];
46
  $form = $frm_field->update($id, $values);
89
 
90
  /* Field Options */
91
  function add_option(){
92
+ global $frm_field, $frm_ajax_url;
93
 
94
  $id = $_POST['field_id'];
95
  $field = $frm_field->getOne($id);
170
 
171
  return $display;
172
  }
173
+
174
+ function input_html($field){
175
+ $class = $field['type'];
176
+ if($field['type'] == 'date')
177
+ $class .= " frm_date";
178
+
179
+ $action = FrmAppHelper::get_param('action');
180
+ if(isset($field['required']) and $field['required']){
181
+ if($field['type'] == 'file' and $action == 'edit'){
182
+ //don't add the required class if this is a file upload when editing
183
+ }else
184
+ $class .= " required";
185
+ }
186
+
187
+ if(isset($field['size']) and $field['size'] > 0){
188
+ if($field['type'] != 'textarea')
189
+ echo ' size="'. $field['size'] .'"';
190
+ $class .= " auto_width";
191
+ }
192
+ if(isset($field['max']) and !in_array($field['type'], array('textarea','rte')))
193
+ echo ' maxlength="'. $field['max'] .'"';
194
+ if(isset($field['clear_on_focus']) and $field['clear_on_focus'])
195
+ echo ' onfocus="frmClearDefault(\''.$field['default_value'].'\', this)" onblur="frmReplaceDefault(\''.$field['default_value'].'\', this)"';
196
+ echo ' class="'.$class.'"';
197
+ }
198
  }
199
  ?>
classes/controllers/FrmFormsController.php CHANGED
@@ -2,24 +2,26 @@
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
  }
13
 
14
  function menu(){
15
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Forms', FRM_PLUGIN_NAME), __('Forms', FRM_PLUGIN_NAME), 8, FRM_PLUGIN_NAME, array($this,'route'));
16
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Create a Form', FRM_PLUGIN_NAME), __('Create a Form', FRM_PLUGIN_NAME), 8, FRM_PLUGIN_NAME.'-new', array($this,'new_form'));
17
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Templates', FRM_PLUGIN_NAME), __('Templates', FRM_PLUGIN_NAME), 8, FRM_PLUGIN_NAME.'-templates', array($this, 'template_list'));
18
  }
19
 
20
  function head(){
21
- $css_file = array(FRM_URL.'/css/ui-lightness/jquery-ui-1.7.2.custom.css', FRM_URL. '/css/frm_admin.css');
22
- $js_file = array(FRM_URL . '/js/formidable.js', FRM_URL . '/js/jquery/jquery-ui-themepicker.js', FRM_URL.'/js/jquery/jquery.editinplace.packed.js');
 
 
23
  require(FRM_VIEWS_PATH . '/shared/head.php');
24
  }
25
 
@@ -35,9 +37,9 @@ class FrmFormsController{
35
  }
36
 
37
  function new_form(){
38
- global $frm_app_controller, $frm_form, $frmpro_is_installed;
39
 
40
- $action = $frm_app_controller->get_param('action');
41
  if ($action == 'create')
42
  return $this->create();
43
  else if ($action == 'new'){
@@ -52,9 +54,9 @@ class FrmFormsController{
52
  }
53
 
54
  function create(){
55
- global $frm_app_controller, $frm_app_helper, $frm_entry, $frm_form, $frm_field, $frmpro_is_installed;
56
  $errors = $frm_form->validate($_POST);
57
- $id = $frm_app_controller->get_param('id');
58
 
59
  if( count($errors) > 0 ){
60
  $frm_field_selection = FrmFieldsHelper::field_selection();
@@ -73,14 +75,13 @@ class FrmFormsController{
73
  }
74
 
75
  function edit(){
76
- global $frm_app_controller;
77
- $id = $frm_app_controller->get_param('id');
78
  return $this->get_edit_vars($id);
79
  }
80
 
81
  function edit_name(){
82
  global $frm_form;
83
- $values = array('name' => $_POST['update_value']);
84
  $form = $frm_form->update($_POST['form_id'], $values);
85
  echo stripslashes($_POST['update_value']);
86
  die();
@@ -94,9 +95,9 @@ class FrmFormsController{
94
  }
95
 
96
  function update(){
97
- global $frm_form, $frm_app_controller;
98
  $errors = $frm_form->validate($_POST);
99
- $id = $frm_app_controller->get_param('id');
100
  if( count($errors) > 0 ){
101
  return $this->get_edit_vars($id, $errors);
102
  }else{
@@ -138,8 +139,8 @@ class FrmFormsController{
138
 
139
  header("Content-Type: text/html; charset=utf-8");
140
 
141
- $plugin = FrmAppController::get_param('plugin');
142
- $controller = FrmAppController::get_param('controller');
143
  $key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
144
  $form = $frm_form->getAll("form_key='$key'",'',' LIMIT 1');
145
  if (!$form) $form = $frm_form->getAll('','',' LIMIT 1');
@@ -151,6 +152,9 @@ class FrmFormsController{
151
  }
152
 
153
  function destroy(){
 
 
 
154
  global $frm_form;
155
  $params = $this->get_params();
156
  $message = '';
@@ -160,15 +164,15 @@ class FrmFormsController{
160
  }
161
 
162
  function destroy_wo_fields(){
163
- global $frm_field, $frm_form, $frm_app_helper;
164
  $id = $_POST['form_id'];
165
- if ($frm_app_helper->getRecordCount('form_id='.$id, $frm_field->table_name) <= 0)
166
  $frm_form->destroy($id);
167
  die();
168
  }
169
 
170
  function display_forms_list($params=false, $message='', $page_params_ov = false, $current_page_ov = false, $errors = array()){
171
- global $wpdb, $frm_app_helper, $frm_form, $frm_entry, $frm_page_size, $frmpro_is_installed;
172
 
173
  if(!$params)
174
  $params = $this->get_params();
@@ -201,9 +205,9 @@ class FrmFormsController{
201
  $sdir_str = $form_vars['sdir_str'];
202
  $search_str = $form_vars['search_str'];
203
 
204
- $record_count = $frm_app_helper->getRecordCount($form_vars['where_clause'], $frm_form->table_name);
205
- $page_count = $frm_app_helper->getPageCount($frm_page_size,$form_vars['where_clause'], $frm_form->table_name);
206
- $forms = $frm_app_helper->getPage($current_page, $frm_page_size, $form_vars['where_clause'], $form_vars['order_by'], $frm_form->table_name);
207
  $page_last_record = $frm_app_helper->getLastRecordNum($record_count,$current_page,$frm_page_size);
208
  $page_first_record = $frm_app_helper->getFirstRecordNum($record_count,$current_page,$frm_page_size);
209
  require_once(FRM_VIEWS_PATH.'/frm-forms/list.php');
@@ -269,7 +273,7 @@ class FrmFormsController{
269
  }
270
 
271
  function get_edit_vars($id, $errors = '', $message='', $create_link=false){
272
- global $frm_app_helper, $frm_entry, $frm_form, $frm_field, $frmpro_is_installed;
273
  $record = $frm_form->getOne( $id );
274
  $items = $frm_entry->getAll('',' ORDER BY it.name');
275
  $frm_field_selection = FrmFieldsHelper::field_selection();
@@ -284,17 +288,37 @@ class FrmFormsController{
284
  }
285
 
286
  function get_params(){
287
- global $frm_app_controller;
288
  $values = array();
289
  foreach (array('template' => 0,'id' => '','paged' => 1,'form' => '','search' => '','sort' => '','sdir' => '') as $var => $default)
290
- $values[$var] = $frm_app_controller->get_param($var, $default);
291
 
292
  return $values;
293
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
 
295
  function route(){
296
- $action = FrmAppController::get_param('action');
297
- if($action=='new')
298
  return $this->new_form();
299
  else if($action=='create')
300
  return $this->create();
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
  }
13
 
14
  function menu(){
15
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Forms', FRM_PLUGIN_NAME), __('Forms', FRM_PLUGIN_NAME), 'frm_view_forms', FRM_PLUGIN_NAME, array(&$this,'route'));
16
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Create a Form', FRM_PLUGIN_NAME), __('Create a Form', FRM_PLUGIN_NAME), 'frm_edit_forms', FRM_PLUGIN_NAME.'-new', array(&$this,'new_form'));
17
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Templates', FRM_PLUGIN_NAME), __('Templates', FRM_PLUGIN_NAME), 'frm_view_forms', FRM_PLUGIN_NAME.'-templates', array(&$this, 'template_list'));
18
  }
19
 
20
  function head(){
21
+ global $frm_settings;
22
+ if(!$frm_settings->custom_stylesheet)
23
+ $css_file = apply_filters('get_frm_stylesheet', FRM_URL .'/css/frm_display.css');
24
+ $js_file = array(FRM_URL . '/js/jquery/jquery-ui-themepicker.js', FRM_URL.'/js/jquery/jquery.editinplace.packed.js');
25
  require(FRM_VIEWS_PATH . '/shared/head.php');
26
  }
27
 
37
  }
38
 
39
  function new_form(){
40
+ global $frm_form, $frmpro_is_installed, $frm_ajax_url;
41
 
42
+ $action = FrmAppHelper::get_param('action');
43
  if ($action == 'create')
44
  return $this->create();
45
  else if ($action == 'new'){
54
  }
55
 
56
  function create(){
57
+ global $frm_app_helper, $frm_entry, $frm_form, $frm_field, $frmpro_is_installed;
58
  $errors = $frm_form->validate($_POST);
59
+ $id = FrmAppHelper::get_param('id');
60
 
61
  if( count($errors) > 0 ){
62
  $frm_field_selection = FrmFieldsHelper::field_selection();
75
  }
76
 
77
  function edit(){
78
+ $id = FrmAppHelper::get_param('id');
 
79
  return $this->get_edit_vars($id);
80
  }
81
 
82
  function edit_name(){
83
  global $frm_form;
84
+ $values = array('name' => trim($_POST['update_value']));
85
  $form = $frm_form->update($_POST['form_id'], $values);
86
  echo stripslashes($_POST['update_value']);
87
  die();
95
  }
96
 
97
  function update(){
98
+ global $frm_form;
99
  $errors = $frm_form->validate($_POST);
100
+ $id = FrmAppHelper::get_param('id');
101
  if( count($errors) > 0 ){
102
  return $this->get_edit_vars($id, $errors);
103
  }else{
139
 
140
  header("Content-Type: text/html; charset=utf-8");
141
 
142
+ $plugin = FrmAppHelper::get_param('plugin');
143
+ $controller = FrmAppHelper::get_param('controller');
144
  $key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
145
  $form = $frm_form->getAll("form_key='$key'",'',' LIMIT 1');
146
  if (!$form) $form = $frm_form->getAll('','',' LIMIT 1');
152
  }
153
 
154
  function destroy(){
155
+ if(!current_user_can('frm_delete_forms'))
156
+ wp_die(__('You don\'t have permission to delete forms', 'formidable'));
157
+
158
  global $frm_form;
159
  $params = $this->get_params();
160
  $message = '';
164
  }
165
 
166
  function destroy_wo_fields(){
167
+ global $frm_field, $frm_form, $frmdb;
168
  $id = $_POST['form_id'];
169
+ if ($frmdb->get_count($frmdb->fields, array('form_id' => $id)) <= 0)
170
  $frm_form->destroy($id);
171
  die();
172
  }
173
 
174
  function display_forms_list($params=false, $message='', $page_params_ov = false, $current_page_ov = false, $errors = array()){
175
+ global $wpdb, $frmdb, $frm_app_helper, $frm_form, $frm_entry, $frm_page_size, $frmpro_is_installed;
176
 
177
  if(!$params)
178
  $params = $this->get_params();
205
  $sdir_str = $form_vars['sdir_str'];
206
  $search_str = $form_vars['search_str'];
207
 
208
+ $record_count = $frm_app_helper->getRecordCount($form_vars['where_clause'], $frmdb->forms);
209
+ $page_count = $frm_app_helper->getPageCount($frm_page_size,$form_vars['where_clause'], $frmdb->forms);
210
+ $forms = $frm_app_helper->getPage($current_page, $frm_page_size, $form_vars['where_clause'], $form_vars['order_by'], $frmdb->forms);
211
  $page_last_record = $frm_app_helper->getLastRecordNum($record_count,$current_page,$frm_page_size);
212
  $page_first_record = $frm_app_helper->getFirstRecordNum($record_count,$current_page,$frm_page_size);
213
  require_once(FRM_VIEWS_PATH.'/frm-forms/list.php');
273
  }
274
 
275
  function get_edit_vars($id, $errors = '', $message='', $create_link=false){
276
+ global $frm_app_helper, $frm_entry, $frm_form, $frm_field, $frmpro_is_installed, $frm_ajax_url;
277
  $record = $frm_form->getOne( $id );
278
  $items = $frm_entry->getAll('',' ORDER BY it.name');
279
  $frm_field_selection = FrmFieldsHelper::field_selection();
288
  }
289
 
290
  function get_params(){
 
291
  $values = array();
292
  foreach (array('template' => 0,'id' => '','paged' => 1,'form' => '','search' => '','sort' => '','sdir' => '') as $var => $default)
293
+ $values[$var] = FrmAppHelper::get_param($var, $default);
294
 
295
  return $values;
296
  }
297
+
298
+ function add_default_templates($path, $default=true){
299
+ global $frm_form, $frm_field;
300
+ $templates = glob($path."/*.php");
301
+
302
+ for($i = count($templates) - 1; $i >= 0; $i--){
303
+ $filename = str_replace($path."/","",$templates[$i]);
304
+ $filename = str_replace('.php','', $filename);
305
+ $template_query = "form_key='{$filename}' and is_template='1'";
306
+ if($default) $template_query .= " and default_template='1'";
307
+ $form = $frm_form->getAll($template_query, '', ' LIMIT 1');
308
+
309
+ $values = FrmFormsHelper::setup_new_vars();
310
+ $values['form_key'] = $filename;
311
+ $values['is_template'] = 1;
312
+ $values['status'] = 'published';
313
+ if($default) $values['default_template'] = 1;
314
+
315
+ require_once($templates[$i]);
316
+ }
317
+ }
318
 
319
  function route(){
320
+ $action = FrmAppHelper::get_param('action');
321
+ if($action == 'new')
322
  return $this->new_form();
323
  else if($action=='create')
324
  return $this->create();
classes/controllers/FrmSettingsController.php CHANGED
@@ -2,13 +2,13 @@
2
 
3
  class FrmSettingsController{
4
  function FrmSettingsController(){
5
- add_action('admin_menu', array( $this, 'menu' ), 25);
6
- add_action('admin_menu', array( $this, 'pro_menu' ), 19);
7
- add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-settings', array($this,'head'));
8
  }
9
 
10
  function menu(){
11
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Settings', FRM_PLUGIN_NAME), __('Settings', FRM_PLUGIN_NAME), 8, FRM_PLUGIN_NAME.'-settings', array($this,'route'));
12
  }
13
 
14
  function pro_menu(){
@@ -16,21 +16,17 @@ class FrmSettingsController{
16
  if (IS_WPMU and !is_site_admin() and get_site_option($frm_update->pro_wpmu_store))
17
  return;
18
 
19
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. FRM_PLUGIN_TITLE . ' Pro', FRM_PLUGIN_TITLE . ' Pro', 8, FRM_PLUGIN_NAME.'-pro-settings', array($frm_update,'pro_cred_form'));
20
- }
21
-
22
- function head(){
23
- $css_file = array('frm_admin' => FRM_URL. '/css/frm_admin.css');
24
- require(FRM_VIEWS_PATH . '/shared/head.php');
25
  }
26
 
27
  function display_form(){
28
- global $frm_settings;
 
29
  require_once(FRM_VIEWS_PATH . '/frm-settings/form.php');
30
  }
31
 
32
  function process_form(){
33
- global $frm_settings;
34
 
35
  //$errors = $frm_settings->validate($_POST,array());
36
  $errors = array();
@@ -40,14 +36,13 @@ class FrmSettingsController{
40
  $frm_settings->store();
41
  $message = __('Settings Saved', FRM_PLUGIN_NAME);
42
  }
43
-
44
  require_once(FRM_VIEWS_PATH . '/frm-settings/form.php');
45
  }
46
 
47
  function route(){
48
- global $frm_app_controller;
49
- $action = $frm_app_controller->get_param('action');
50
- if($action=='process-form')
51
  return $this->process_form();
52
  else
53
  return $this->display_form();
2
 
3
  class FrmSettingsController{
4
  function FrmSettingsController(){
5
+ add_action('admin_menu', array( &$this, 'menu' ), 25);
6
+ add_action('admin_menu', array( &$this, 'pro_menu' ), 19);
7
+ //add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-settings', array($this,'head'));
8
  }
9
 
10
  function menu(){
11
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Settings', FRM_PLUGIN_NAME), __('Settings', FRM_PLUGIN_NAME), 'frm_change_settings', FRM_PLUGIN_NAME.'-settings', array($this,'route'));
12
  }
13
 
14
  function pro_menu(){
16
  if (IS_WPMU and !is_site_admin() and get_site_option($frm_update->pro_wpmu_store))
17
  return;
18
 
19
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. FRM_PLUGIN_TITLE . ' Pro', FRM_PLUGIN_TITLE . ' Pro', 'administrator', FRM_PLUGIN_NAME.'-pro-settings', array($frm_update,'pro_cred_form'));
 
 
 
 
 
20
  }
21
 
22
  function display_form(){
23
+ global $frm_settings, $frm_ajax_url;
24
+ $frm_roles = FrmAppHelper::frm_capabilities();
25
  require_once(FRM_VIEWS_PATH . '/frm-settings/form.php');
26
  }
27
 
28
  function process_form(){
29
+ global $frm_settings, $frm_ajax_url;
30
 
31
  //$errors = $frm_settings->validate($_POST,array());
32
  $errors = array();
36
  $frm_settings->store();
37
  $message = __('Settings Saved', FRM_PLUGIN_NAME);
38
  }
39
+ $frm_roles = FrmAppHelper::frm_capabilities();
40
  require_once(FRM_VIEWS_PATH . '/frm-settings/form.php');
41
  }
42
 
43
  function route(){
44
+ $action = FrmAppHelper::get_param('action');
45
+ if($action == 'process-form')
 
46
  return $this->process_form();
47
  else
48
  return $this->display_form();
classes/controllers/FrmStatisticsController.php CHANGED
@@ -2,13 +2,13 @@
2
 
3
  class FrmStatisticsController{
4
  function FrmStatisticsController(){
5
- add_action('admin_menu', array( $this, 'menu' ), 30);
6
  }
7
 
8
  function menu(){
9
  global $frmpro_is_installed;
10
  if(!$frmpro_is_installed)
11
- add_submenu_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE .' | Statistics', 'Statistics', 8, FRM_PLUGIN_TITLE.'-statistics',array($this,''));
12
  }
13
 
14
  function list_entries(){
2
 
3
  class FrmStatisticsController{
4
  function FrmStatisticsController(){
5
+ add_action('admin_menu', array( &$this, 'menu' ), 30);
6
  }
7
 
8
  function menu(){
9
  global $frmpro_is_installed;
10
  if(!$frmpro_is_installed)
11
+ add_submenu_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE .' | Statistics', 'Statistics', 'administrator', FRM_PLUGIN_TITLE.'-statistics',array($this,''));
12
  }
13
 
14
  function list_entries(){
classes/helpers/FrmAppHelper.php CHANGED
@@ -3,15 +3,17 @@
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 wp_pages_dropdown($field_name, $page_id){
11
- global $frm_app_controller;
12
-
13
- $field_value = $frm_app_controller->get_param($field_name);
14
- $pages = get_posts( array('post_type' => 'page', 'post_status' => 'published', 'numberposts' => 99, 'order_by' => 'post_title', 'order' => 'ASC'));
15
  ?>
16
  <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-dropdown frm-pages-dropdown">
17
  <option value=""></option>
@@ -21,28 +23,85 @@ class FrmAppHelper{
21
  </select>
22
  <?php
23
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  function value_is_checked_with_array($field_name, $index, $field_value){
26
  if( ( $_POST['action'] == 'process_form' and isset( $_POST[ $field_name ][ $index ] ) ) or ( $_POST['action'] != 'process_form' and isset($field_value) ) )
27
  echo ' checked="checked"';
28
  }
29
 
 
 
 
 
 
 
 
 
 
 
 
30
  function get_unique_key($name='', $table_name, $column, $id = 0,$num_chars = 6){
31
  global $wpdb;
32
-
33
  if ($name == ''){
34
  $max_slug_value = pow(36,$num_chars);
35
  $min_slug_value = 37; // we want to have at least 2 characters in the slug
36
  $key = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
37
  }else
38
  $key = sanitize_title_with_dashes($name);
39
-
40
- if (is_numeric($key))
41
  $key = $key .'a';
42
 
43
  $query = "SELECT $column FROM $table_name WHERE $column = %s AND ID != %d LIMIT 1";
44
  $key_check = $wpdb->get_var($wpdb->prepare($query, $key, $id));
45
- if ($key_check || is_numeric($key_check)){
 
46
  $suffix = 2;
47
  do {
48
  $alt_post_name = substr($key, 0, 200-(strlen($suffix)+1)). "$suffix";
@@ -57,16 +116,16 @@ class FrmAppHelper{
57
  //Editing a Form or Entry
58
  function setup_edit_vars($record, $table, $fields='', $default=false){
59
  if(!$record) return false;
60
- global $frm_entry_meta, $frm_form, $frm_app_controller, $frm_settings;
61
  $values = array();
62
 
63
  $values['id'] = $record->id;
64
 
65
  foreach (array('name' => $record->name, 'description' => $record->description) as $var => $default_val)
66
- $values[$var] = stripslashes($frm_app_controller->get_param($var, $default_val));
67
  $values['description'] = wpautop($values['description']);
68
  $values['fields'] = array();
69
- if ($fields){
70
  foreach($fields as $field){
71
 
72
  if ($default)
@@ -78,7 +137,7 @@ class FrmAppHelper{
78
  $field_type = isset($_POST['field_options']['type_'.$field->id]) ? $_POST['field_options']['type_'.$field->id] : $field->type;
79
  $new_value = (isset($_POST['item_meta'][$field->id])) ? $_POST['item_meta'][$field->id] : $meta_value;
80
  $new_value = stripslashes_deep(maybe_unserialize($new_value));
81
-
82
  $field_array = array('id' => $field->id,
83
  'value' => str_replace('"', '&quot;', $new_value),
84
  'default_value' => str_replace('"', '&quot;', stripslashes($field->default_value)),
@@ -90,13 +149,18 @@ class FrmAppHelper{
90
  'field_key' => $field->field_key,
91
  'field_order' => $field->field_order,
92
  'form_id' => $field->form_id);
93
-
94
- foreach (array('size' => '', 'max' => '', 'label' => 'top', 'invalid' => '', 'required_indicator' => '*', 'blank' => '', 'clear_on_focus' => 0, 'custom_html' => '', 'default_blank' => 0) as $opt => $default_opt)
95
- $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);
96
 
 
 
 
 
 
 
 
 
97
  if ($field_array['custom_html'] == '')
98
  $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field_type);
99
-
100
  $values['fields'][] = apply_filters('frm_setup_edit_fields_vars', stripslashes_deep($field_array), $field, $values['id']);
101
  }
102
  }
@@ -111,16 +175,23 @@ class FrmAppHelper{
111
  $options = stripslashes_deep(unserialize($form->options));
112
  if (is_array($options)){
113
  foreach ($options as $opt => $value)
114
- $values[$opt] = $frm_app_controller->get_param($opt, $value);
115
  }
116
  }
117
 
118
  $email = get_option('admin_email');
119
- foreach (array('custom_style' => $frm_settings->custom_style, 'email_to' => $email, 'submit_value' => $frm_settings->submit_value, 'success_msg' => $frm_settings->success_msg) as $opt => $default){
120
  if (!isset($values[$opt]))
121
  $values[$opt] = ($_POST and isset($_POST['options'][$opt])) ? $_POST['options'][$opt] : $default;
122
  }
123
 
 
 
 
 
 
 
 
124
  if (!isset($values['custom_style']))
125
  $values['custom_style'] = ($_POST and isset($_POST['options']['custom_style'])) ? $_POST['options']['custom_style'] : $frm_settings->custom_style;
126
 
3
  class FrmAppHelper{
4
  function FrmAppHelper(){}
5
 
6
+ function get_param($param, $default=''){
7
+ return (isset($_POST[$param])?$_POST[$param]:(isset($_GET[$param])?$_GET[$param]:$default));
8
+ }
9
+
10
  function get_pages(){
11
+ return get_posts( array('post_type' => 'page', 'post_status' => 'published', 'numberposts' => 99, 'orderby' => 'title', 'order' => 'ASC'));
12
  }
13
 
14
  function wp_pages_dropdown($field_name, $page_id){
15
+ $field_value = FrmAppHelper::get_param($field_name);
16
+ $pages = FrmAppHelper::get_pages();
 
 
17
  ?>
18
  <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-dropdown frm-pages-dropdown">
19
  <option value=""></option>
23
  </select>
24
  <?php
25
  }
26
+
27
+ function wp_roles_dropdown($field_name, $capability){
28
+ $field_value = FrmAppHelper::get_param($field_name);
29
+ $editable_roles = get_editable_roles();
30
+
31
+ ?>
32
+ <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-dropdown frm-pages-dropdown">
33
+ <?php foreach($editable_roles as $role => $details){
34
+ $name = translate_user_role($details['name'] ); ?>
35
+ <option value="<?php echo esc_attr($role) ?>" <?php echo (((isset($_POST[$field_name]) and $_POST[$field_name] == $role) or (!isset($_POST[$field_name]) and $capability == $role))?' selected="selected"':''); ?>><?php echo $name ?> </option>
36
+ <?php } ?>
37
+ </select>
38
+ <?php
39
+ }
40
+
41
+ function frm_capabilities(){
42
+ global $frmpro_is_installed;
43
+ $cap = array(
44
+ 'frm_view_forms' => __('View Forms and Templates', 'formidable'),
45
+ 'frm_edit_forms' => __('Create/Edit Forms and Templates', 'formidable'),
46
+ 'frm_delete_forms' => __('Delete Forms and Templates', 'formidable'),
47
+ 'frm_change_settings' => __('Access this Settings Page', 'formidable')
48
+ );
49
+ if($frmpro_is_installed){
50
+ $cap['frm_view_entries'] = __('View Entries from Admin Area', 'formidable');
51
+ $cap['frm_create_entries'] = __('Create Entries from Admin Area', 'formidable');
52
+ $cap['frm_edit_entries'] = __('Edit Entries from Admin Area', 'formidable');
53
+ $cap['frm_delete_entries'] = __('Delete Entries from Admin Area', 'formidable');
54
+ $cap['frm_view_reports'] = __('View Reports', 'formidable');
55
+ $cap['frm_edit_displays'] = __('Create/Edit Custom Displays', 'formidable');
56
+ }
57
+ return $cap;
58
+ }
59
+
60
+ function user_has_permission($needed_role){
61
+ if ($needed_role == '' or
62
+ ($needed_role == 'administrator' and current_user_can('administrator')) or
63
+ ($needed_role == 'subscriber' and current_user_can('level_0')) or
64
+ ($needed_role == 'contributer' and current_user_can('level_1')) or
65
+ ($needed_role == 'author' and (current_user_can('author') or current_user_can('editor') or current_user_can('administrator'))) or
66
+ ($needed_role == 'editor' and (current_user_can('editor') or current_user_can('administrator'))) )
67
+ return true;
68
+ else
69
+ return false;
70
+ }
71
 
72
  function value_is_checked_with_array($field_name, $index, $field_value){
73
  if( ( $_POST['action'] == 'process_form' and isset( $_POST[ $field_name ][ $index ] ) ) or ( $_POST['action'] != 'process_form' and isset($field_value) ) )
74
  echo ' checked="checked"';
75
  }
76
 
77
+ function get_file_contents($filename){
78
+ if (is_file($filename)){
79
+ ob_start();
80
+ include $filename;
81
+ $contents = ob_get_contents();
82
+ ob_end_clean();
83
+ return $contents;
84
+ }
85
+ return false;
86
+ }
87
+
88
  function get_unique_key($name='', $table_name, $column, $id = 0,$num_chars = 6){
89
  global $wpdb;
90
+
91
  if ($name == ''){
92
  $max_slug_value = pow(36,$num_chars);
93
  $min_slug_value = 37; // we want to have at least 2 characters in the slug
94
  $key = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
95
  }else
96
  $key = sanitize_title_with_dashes($name);
97
+
98
+ if (is_numeric($key) or in_array($key, array('id','key','created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')))
99
  $key = $key .'a';
100
 
101
  $query = "SELECT $column FROM $table_name WHERE $column = %s AND ID != %d LIMIT 1";
102
  $key_check = $wpdb->get_var($wpdb->prepare($query, $key, $id));
103
+
104
+ if ($key_check or is_numeric($key_check)){
105
  $suffix = 2;
106
  do {
107
  $alt_post_name = substr($key, 0, 200-(strlen($suffix)+1)). "$suffix";
116
  //Editing a Form or Entry
117
  function setup_edit_vars($record, $table, $fields='', $default=false){
118
  if(!$record) return false;
119
+ global $frm_entry_meta, $frm_form, $frm_settings;
120
  $values = array();
121
 
122
  $values['id'] = $record->id;
123
 
124
  foreach (array('name' => $record->name, 'description' => $record->description) as $var => $default_val)
125
+ $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default_val));
126
  $values['description'] = wpautop($values['description']);
127
  $values['fields'] = array();
128
+ if ($fields){
129
  foreach($fields as $field){
130
 
131
  if ($default)
137
  $field_type = isset($_POST['field_options']['type_'.$field->id]) ? $_POST['field_options']['type_'.$field->id] : $field->type;
138
  $new_value = (isset($_POST['item_meta'][$field->id])) ? $_POST['item_meta'][$field->id] : $meta_value;
139
  $new_value = stripslashes_deep(maybe_unserialize($new_value));
140
+
141
  $field_array = array('id' => $field->id,
142
  'value' => str_replace('"', '&quot;', $new_value),
143
  'default_value' => str_replace('"', '&quot;', stripslashes($field->default_value)),
149
  'field_key' => $field->field_key,
150
  'field_order' => $field->field_order,
151
  'form_id' => $field->form_id);
 
 
 
152
 
153
+ foreach (array('size' => '', 'max' => '', 'label' => 'top', 'invalid' => '', 'required_indicator' => '*', 'blank' => '', 'clear_on_focus' => 0, 'custom_html' => '', 'default_blank' => 0) as $opt => $default_opt){
154
+ $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);
155
+ if($opt == 'blank' and $field_array[$opt] == '')
156
+ $field_array[$opt] = $field_array['name'] . ' ' . __('can\'t be blank', FRM_PLUGIN_NAME);
157
+ else if($opt == 'invalid' and $field_array[$opt] == '')
158
+ $field_array[$opt] = $field_array['name'] . ' ' . __('is an invalid format', FRM_PLUGIN_NAME);
159
+ }
160
+
161
  if ($field_array['custom_html'] == '')
162
  $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field_type);
163
+
164
  $values['fields'][] = apply_filters('frm_setup_edit_fields_vars', stripslashes_deep($field_array), $field, $values['id']);
165
  }
166
  }
175
  $options = stripslashes_deep(unserialize($form->options));
176
  if (is_array($options)){
177
  foreach ($options as $opt => $value)
178
+ $values[$opt] = FrmAppHelper::get_param($opt, $value);
179
  }
180
  }
181
 
182
  $email = get_option('admin_email');
183
+ foreach (array('custom_style' => $frm_settings->custom_style, 'email_to' => $email) as $opt => $default){
184
  if (!isset($values[$opt]))
185
  $values[$opt] = ($_POST and isset($_POST['options'][$opt])) ? $_POST['options'][$opt] : $default;
186
  }
187
 
188
+ foreach (array('submit_value' => $frm_settings->submit_value, 'success_action' => 'message', 'success_msg' => $frm_settings->success_msg, 'show_form' => 1) as $opt => $default){
189
+ if (!isset($values[$opt]) or $values[$opt] == '')
190
+ $values[$opt] = ($_POST and isset($_POST['options'][$opt])) ? $_POST['options'][$opt] : $default;
191
+ }
192
+ if (!isset($values['show_form']))
193
+ $values['show_form'] = ($_POST and isset($_POST['options']['show_form'])) ? 1 : 0;
194
+
195
  if (!isset($values['custom_style']))
196
  $values['custom_style'] = ($_POST and isset($_POST['options']['custom_style'])) ? $_POST['options']['custom_style'] : $frm_settings->custom_style;
197
 
classes/helpers/FrmEntriesHelper.php CHANGED
@@ -3,10 +3,10 @@
3
  class FrmEntriesHelper{
4
 
5
  function setup_new_vars($fields, $form='', $reset=false){
6
- global $frm_app_controller, $frm_form, $frm_settings;
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){
@@ -19,10 +19,11 @@ class FrmEntriesHelper{
19
  else
20
  $new_value = ($_POST and isset($_POST['item_meta'][$field->id])) ? $_POST['item_meta'][$field->id] : $default;
21
 
22
- if ($field->type != 'checkbox')
23
- $new_value = apply_filters('frm_get_default_value', stripslashes_deep($new_value));
 
24
 
25
- $new_value = str_replace('"', '&quot;', stripslashes_deep(maybe_unserialize($new_value)));
26
 
27
  $field_array = array('id' => $field->id,
28
  'value' => $new_value,
@@ -52,7 +53,7 @@ class FrmEntriesHelper{
52
 
53
  if (is_array($options)){
54
  foreach ($options as $opt => $value)
55
- $values[$opt] = $frm_app_controller->get_param($opt, $value);
56
  }
57
 
58
  if (!isset($values['custom_style']))
@@ -85,13 +86,13 @@ class FrmEntriesHelper{
85
  $values['form_id'] = $record->form_id;
86
  return apply_filters('frm_setup_edit_entry_vars', $values);
87
  }
88
-
89
- function entries_dropdown( $form_id, $field_name, $field_value='', $blank=true, $blank_label='' ){
90
- global $frm_app_controller, $frm_entry;
91
 
92
  $entries = $frm_entry->getAll("it.form_id=".$form_id,' ORDER BY name');
93
  ?>
94
- <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-dropdown">
95
  <?php if ($blank){ ?>
96
  <option value=""><?php echo $blank_label; ?></option>
97
  <?php } ?>
@@ -101,6 +102,10 @@ class FrmEntriesHelper{
101
  </select>
102
  <?php
103
  }
 
 
 
 
104
  }
105
 
106
  ?>
3
  class FrmEntriesHelper{
4
 
5
  function setup_new_vars($fields, $form='', $reset=false){
6
+ global $frm_form, $frm_settings;
7
  $values = array();
8
  foreach (array('name' => '', 'description' => '', 'item_key' => '') as $var => $default)
9
+ $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default));
10
 
11
  $values['fields'] = array();
12
  if ($fields){
19
  else
20
  $new_value = ($_POST and isset($_POST['item_meta'][$field->id])) ? $_POST['item_meta'][$field->id] : $default;
21
 
22
+ $new_value = stripslashes_deep(maybe_unserialize($new_value));
23
+ if (!is_array($new_value))
24
+ $new_value = apply_filters('frm_get_default_value', $new_value, $field);
25
 
26
+ $new_value = str_replace('"', '&quot;', $new_value);
27
 
28
  $field_array = array('id' => $field->id,
29
  'value' => $new_value,
53
 
54
  if (is_array($options)){
55
  foreach ($options as $opt => $value)
56
+ $values[$opt] = FrmAppHelper::get_param($opt, $value);
57
  }
58
 
59
  if (!isset($values['custom_style']))
86
  $values['form_id'] = $record->form_id;
87
  return apply_filters('frm_setup_edit_entry_vars', $values);
88
  }
89
+
90
+ function entries_dropdown( $form_id, $field_name, $field_value='', $blank=true, $blank_label='', $onchange=false ){
91
+ global $frm_entry;
92
 
93
  $entries = $frm_entry->getAll("it.form_id=".$form_id,' ORDER BY name');
94
  ?>
95
+ <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-dropdown" <?php if ($onchange) echo 'onchange="'.$onchange.'"'; ?>>
96
  <?php if ($blank){ ?>
97
  <option value=""><?php echo $blank_label; ?></option>
98
  <?php } ?>
102
  </select>
103
  <?php
104
  }
105
+
106
+ function enqueue_scripts($params){
107
+ do_action('frm_enqueue_form_scripts', $params);
108
+ }
109
  }
110
 
111
  ?>
classes/helpers/FrmFieldsHelper.php CHANGED
@@ -18,20 +18,23 @@ class FrmFieldsHelper{
18
 
19
  function pro_field_selection(){
20
  return apply_filters('frm_pro_available_fields', array(
21
- 'divider' => __('Section Divider/Heading', FRM_PLUGIN_NAME),
22
  'break' => __('Page Break', FRM_PLUGIN_NAME),
23
  'file' => __('File Upload', FRM_PLUGIN_NAME),
24
  'rte' => __('Rich Text Editor', FRM_PLUGIN_NAME),
25
- 'phone' => __('Phone', FRM_PLUGIN_NAME),
26
- 'email' => __('Email', FRM_PLUGIN_NAME),
 
27
  'date' => __('Date', FRM_PLUGIN_NAME),
28
  //'time' => 'Time',
29
- 'hidden' => __('Hidden Field', FRM_PLUGIN_NAME),
30
- 'user_id' => __('Hidden User Id', FRM_PLUGIN_NAME),
31
  'website' => __('Website/URL', FRM_PLUGIN_NAME),
32
  'image' => __('Image URL', FRM_PLUGIN_NAME),
33
  '10radio' => __('Scale', FRM_PLUGIN_NAME),
34
- 'data' => __('Data from Entries', FRM_PLUGIN_NAME)
 
 
 
 
35
  //'multiple' => 'Multiple Select Box', //http://code.google.com/p/jquery-asmselect/
36
  //'address' => 'Address' //Address line 1, Address line 2, City, State/Providence, Postal Code, Select Country
37
  //'city_selector' => 'US State/County/City selector',
@@ -42,10 +45,10 @@ class FrmFieldsHelper{
42
  }
43
 
44
  function setup_new_vars($type='',$form_id=''){
45
- global $frm_field, $frm_app_helper;
46
 
47
- $field_count = $frm_app_helper->getRecordCount("form_id=$form_id", $frm_field->table_name);
48
- $key = FrmAppHelper::get_unique_key('', $frm_field->table_name, 'field_key');
49
 
50
  $values = array();
51
  foreach (array('name' => __('Untitled', FRM_PLUGIN_NAME), 'description' => '', 'field_key' => $key, 'type' => $type, 'options'=>'', 'default_value'=>'', 'field_order' => $field_count+1, 'required' => false, 'blank' => __('Untitled can\'t be blank', FRM_PLUGIN_NAME), 'invalid' => __('Untitled is an invalid format', FRM_PLUGIN_NAME), 'form_id' => $form_id) as $var => $default)
@@ -56,9 +59,9 @@ class FrmFieldsHelper{
56
  $values['field_options'][$var] = $default;
57
 
58
  if ($type == 'radio' || ($type == 'checkbox'))
59
- $values['options'] = serialize(array(1 => 'Option 1', 2 => 'Option 2'));
60
  else if ( $type == 'select')
61
- $values['options'] = serialize(array(1 => '', 2 => 'Option 1'));
62
  else if ($type == 'textarea')
63
  $values['field_options']['max'] = '5';
64
 
@@ -66,18 +69,18 @@ class FrmFieldsHelper{
66
  }
67
 
68
  function setup_edit_vars($record){
69
- global $frm_entry_meta, $frm_form, $frm_app_controller;
70
 
71
  $values = array();
72
  $values['id'] = $record->id;
73
  $values['form_id'] = $record->form_id;
74
  foreach (array('name' => $record->name, 'description' => $record->description) as $var => $default)
75
- $values[$var] = htmlspecialchars(stripslashes($frm_app_controller->get_param($var, $default)));
76
 
77
  $values['form_name'] = ($record->form_id)?($frm_form->getName( $record->form_id )):('');
78
 
79
  foreach (array('field_key' => $record->field_key, 'type' => $record->type, 'default_value'=> $record->default_value, 'field_order' => $record->field_order, 'required' => $record->required) as $var => $default)
80
- $values[$var] = $frm_app_controller->get_param($var, $default);
81
 
82
  $values['options'] = unserialize($record->options);
83
  $field_options = unserialize($record->field_options);
@@ -92,7 +95,7 @@ class FrmFieldsHelper{
92
  $values['default_blank'] = (isset($field_options['default_blank']))?($field_options['default_blank']):(0);
93
  $values['custom_html'] = (isset($field_options['custom_html']))? stripslashes($field_options['custom_html']): FrmFieldsHelper::get_default_html($record->type);
94
 
95
- return $values;
96
  }
97
 
98
  function get_form_fields($form_id, $error=false){
@@ -151,6 +154,10 @@ DEFAULT_HTML;
151
  $error_class = in_array('field'.$field['id'], $error_keys) ? ' frm_blank_field':'';
152
  $html = str_replace('[error_class]', $error_class, $html);
153
 
 
 
 
 
154
  //replace [input]
155
  ob_start();
156
  include(FRM_VIEWS_PATH.'/frm-fields/input.php');
18
 
19
  function pro_field_selection(){
20
  return apply_filters('frm_pro_available_fields', array(
21
+ 'divider' => __('Section Heading', FRM_PLUGIN_NAME),
22
  'break' => __('Page Break', FRM_PLUGIN_NAME),
23
  'file' => __('File Upload', FRM_PLUGIN_NAME),
24
  'rte' => __('Rich Text Editor', FRM_PLUGIN_NAME),
25
+ 'number' => __('Number', FRM_PLUGIN_NAME),
26
+ 'phone' => __('Phone Number', FRM_PLUGIN_NAME),
27
+ 'email' => __('Email Address', FRM_PLUGIN_NAME),
28
  'date' => __('Date', FRM_PLUGIN_NAME),
29
  //'time' => 'Time',
 
 
30
  'website' => __('Website/URL', FRM_PLUGIN_NAME),
31
  'image' => __('Image URL', FRM_PLUGIN_NAME),
32
  '10radio' => __('Scale', FRM_PLUGIN_NAME),
33
+ //'grid' => __('Grid', FRM_PLUGIN_NAME),
34
+ 'data' => __('Data from Entries', FRM_PLUGIN_NAME),
35
+ 'hidden' => __('Hidden Field', FRM_PLUGIN_NAME),
36
+ 'user_id' => __('Hidden User Id', FRM_PLUGIN_NAME),
37
+ 'tag' => __('Tags', FRM_PLUGIN_NAME)
38
  //'multiple' => 'Multiple Select Box', //http://code.google.com/p/jquery-asmselect/
39
  //'address' => 'Address' //Address line 1, Address line 2, City, State/Providence, Postal Code, Select Country
40
  //'city_selector' => 'US State/County/City selector',
45
  }
46
 
47
  function setup_new_vars($type='',$form_id=''){
48
+ global $frmdb, $frm_app_helper;
49
 
50
+ $field_count = $frm_app_helper->getRecordCount("form_id=$form_id", $frmdb->fields);
51
+ $key = FrmAppHelper::get_unique_key('', $frmdb->fields, 'field_key');
52
 
53
  $values = array();
54
  foreach (array('name' => __('Untitled', FRM_PLUGIN_NAME), 'description' => '', 'field_key' => $key, 'type' => $type, 'options'=>'', 'default_value'=>'', 'field_order' => $field_count+1, 'required' => false, 'blank' => __('Untitled can\'t be blank', FRM_PLUGIN_NAME), 'invalid' => __('Untitled is an invalid format', FRM_PLUGIN_NAME), 'form_id' => $form_id) as $var => $default)
59
  $values['field_options'][$var] = $default;
60
 
61
  if ($type == 'radio' || ($type == 'checkbox'))
62
+ $values['options'] = serialize(array('Option 1', 'Option 2'));
63
  else if ( $type == 'select')
64
+ $values['options'] = serialize(array('','Option 1'));
65
  else if ($type == 'textarea')
66
  $values['field_options']['max'] = '5';
67
 
69
  }
70
 
71
  function setup_edit_vars($record){
72
+ global $frm_entry_meta, $frm_form;
73
 
74
  $values = array();
75
  $values['id'] = $record->id;
76
  $values['form_id'] = $record->form_id;
77
  foreach (array('name' => $record->name, 'description' => $record->description) as $var => $default)
78
+ $values[$var] = htmlspecialchars(stripslashes(FrmAppHelper::get_param($var, $default)));
79
 
80
  $values['form_name'] = ($record->form_id)?($frm_form->getName( $record->form_id )):('');
81
 
82
  foreach (array('field_key' => $record->field_key, 'type' => $record->type, 'default_value'=> $record->default_value, 'field_order' => $record->field_order, 'required' => $record->required) as $var => $default)
83
+ $values[$var] = FrmAppHelper::get_param($var, $default);
84
 
85
  $values['options'] = unserialize($record->options);
86
  $field_options = unserialize($record->field_options);
95
  $values['default_blank'] = (isset($field_options['default_blank']))?($field_options['default_blank']):(0);
96
  $values['custom_html'] = (isset($field_options['custom_html']))? stripslashes($field_options['custom_html']): FrmFieldsHelper::get_default_html($record->type);
97
 
98
+ return apply_filters('frm_setup_edit_field_vars',$values);
99
  }
100
 
101
  function get_form_fields($form_id, $error=false){
154
  $error_class = in_array('field'.$field['id'], $error_keys) ? ' frm_blank_field':'';
155
  $html = str_replace('[error_class]', $error_class, $html);
156
 
157
+ //replace [entry_key]
158
+ $entry_key = (isset($_GET) and isset($_GET['entry'])) ? $_GET['entry'] : '';
159
+ $html = str_replace('[entry_key]', $entry_key, $html);
160
+
161
  //replace [input]
162
  ob_start();
163
  include(FRM_VIEWS_PATH.'/frm-fields/input.php');
classes/helpers/FrmFormsHelper.php CHANGED
@@ -24,40 +24,42 @@ class FrmFormsHelper{
24
  <?php
25
  }
26
 
27
- function forms_dropdown( $field_name, $field_value='', $blank=true, $field_id=false ){
28
- global $frm_app_controller, $frm_form;
29
  if (!$field_id)
30
  $field_id = $field_name;
31
 
32
  $forms = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')",' ORDER BY name');
33
  ?>
34
- <select name="<?php echo $field_name; ?>" id="<?php echo $field_id ?>" class="frm-dropdown">
35
  <?php if ($blank){ ?>
36
  <option value=""></option>
37
  <?php } ?>
38
  <?php foreach($forms as $form){ ?>
39
- <option value="<?php echo $form->id; ?>" <?php selected($field_value, $form->id); ?>><?php echo $form->name; ?></option>
40
  <?php } ?>
41
  </select>
42
  <?php
43
  }
44
 
45
  function setup_new_vars(){
46
- global $frm_app_controller, $frm_form, $frm_settings;
47
  $values = array();
48
  foreach (array('name' => __('Untitled Form', FRM_PLUGIN_NAME), 'description' => '') as $var => $default)
49
- $values[$var] = stripslashes($frm_app_controller->get_param($var, $default));
50
 
51
  $values['description'] = wpautop($values['description']);
52
 
53
  foreach (array('form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0) as $var => $default)
54
- $values[$var] = stripslashes($frm_app_controller->get_param($var, $default));
55
 
56
- $values['form_key'] = ($_POST and isset($_POST['form_key']))?$_POST['form_key']:(FrmAppHelper::get_unique_key('', $frm_form->table_name, 'form_key'));
57
  $values['email_to'] = ($_POST and isset($_POST['options']['email_to'])) ? $_POST['options']['email_to'] : $frm_settings->email_to;
58
  $values['custom_style'] = ($_POST and isset($_POST['options']['custom_style'])) ? $_POST['options']['custom_style'] : $frm_settings->custom_style;
59
  $values['submit_value'] = ($_POST and isset($_POST['options']['submit_value'])) ? $_POST['options']['submit_value'] : $frm_settings->submit_value;
 
60
  $values['success_msg'] = ($_POST and isset($_POST['options']['success_msg'])) ? $_POST['options']['success_msg'] : $frm_settings->success_msg;
 
61
  $values['akismet'] = ($_POST and isset($_POST['options']['akismet'])) ? 1 : 0;
62
  $values['before_html'] = FrmFormsHelper::get_default_html('before');
63
  $values['after_html'] = FrmFormsHelper::get_default_html('after');
@@ -66,11 +68,11 @@ class FrmFormsHelper{
66
  }
67
 
68
  function setup_edit_vars($values, $record){
69
- global $frm_form, $frm_app_controller;
70
 
71
- $values['form_key'] = $frm_app_controller->get_param('form_key', $record->form_key);
72
- $values['default_template'] = $frm_app_controller->get_param('default_template', $record->default_template);
73
- $values['is_template'] = $frm_app_controller->get_param('is_template', $record->is_template);
74
 
75
  return apply_filters('frm_setup_edit_form_vars', $values);
76
  }
@@ -88,11 +90,13 @@ BEFORE_HTML;
88
  }
89
 
90
  function replace_shortcodes($html, $form, $title=false, $description=false){
91
- foreach (array('form_name' => $title,'form_description' => $description) as $code => $show){
92
  if ($code == 'form_name')
93
  $replace_with = stripslashes($form->name);
94
  else if ($code == 'form_description')
95
  $replace_with = wpautop(stripslashes($form->description));
 
 
96
 
97
  if (($show == true || $show == 'true') && $replace_with != '' ){
98
  $html = str_replace('[if '.$code.']','',$html);
@@ -103,7 +107,32 @@ BEFORE_HTML;
103
  $html = str_replace('['.$code.']', $replace_with, $html);
104
  }
105
 
106
- return $html;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  }
108
 
109
  }
24
  <?php
25
  }
26
 
27
+ function forms_dropdown( $field_name, $field_value='', $blank=true, $field_id=false, $onchange=false ){
28
+ global $frm_form;
29
  if (!$field_id)
30
  $field_id = $field_name;
31
 
32
  $forms = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')",' ORDER BY name');
33
  ?>
34
+ <select name="<?php echo $field_name; ?>" id="<?php echo $field_id ?>" class="frm-dropdown" <?php if ($onchange) echo 'onchange="'.$onchange.'"'; ?>>
35
  <?php if ($blank){ ?>
36
  <option value=""></option>
37
  <?php } ?>
38
  <?php foreach($forms as $form){ ?>
39
+ <option value="<?php echo $form->id; ?>" <?php selected($field_value, $form->id); ?>><?php echo stripslashes($form->name); ?></option>
40
  <?php } ?>
41
  </select>
42
  <?php
43
  }
44
 
45
  function setup_new_vars(){
46
+ global $frmdb, $frm_settings;
47
  $values = array();
48
  foreach (array('name' => __('Untitled Form', FRM_PLUGIN_NAME), 'description' => '') as $var => $default)
49
+ $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default));
50
 
51
  $values['description'] = wpautop($values['description']);
52
 
53
  foreach (array('form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0) as $var => $default)
54
+ $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default));
55
 
56
+ $values['form_key'] = ($_POST and isset($_POST['form_key']))?$_POST['form_key']:(FrmAppHelper::get_unique_key('', $frmdb->forms, 'form_key'));
57
  $values['email_to'] = ($_POST and isset($_POST['options']['email_to'])) ? $_POST['options']['email_to'] : $frm_settings->email_to;
58
  $values['custom_style'] = ($_POST and isset($_POST['options']['custom_style'])) ? $_POST['options']['custom_style'] : $frm_settings->custom_style;
59
  $values['submit_value'] = ($_POST and isset($_POST['options']['submit_value'])) ? $_POST['options']['submit_value'] : $frm_settings->submit_value;
60
+ $values['success_action'] = ($_POST and isset($_POST['options']['success_action'])) ? $_POST['options']['success_action'] : 'message';
61
  $values['success_msg'] = ($_POST and isset($_POST['options']['success_msg'])) ? $_POST['options']['success_msg'] : $frm_settings->success_msg;
62
+ $values['show_form'] = ($_POST and isset($_POST['options']['show_form'])) ? 1 : 0;
63
  $values['akismet'] = ($_POST and isset($_POST['options']['akismet'])) ? 1 : 0;
64
  $values['before_html'] = FrmFormsHelper::get_default_html('before');
65
  $values['after_html'] = FrmFormsHelper::get_default_html('after');
68
  }
69
 
70
  function setup_edit_vars($values, $record){
71
+ global $frm_form;
72
 
73
+ $values['form_key'] = FrmAppHelper::get_param('form_key', $record->form_key);
74
+ $values['default_template'] = FrmAppHelper::get_param('default_template', $record->default_template);
75
+ $values['is_template'] = FrmAppHelper::get_param('is_template', $record->is_template);
76
 
77
  return apply_filters('frm_setup_edit_form_vars', $values);
78
  }
90
  }
91
 
92
  function replace_shortcodes($html, $form, $title=false, $description=false){
93
+ foreach (array('form_name' => $title,'form_description' => $description, 'entry_key' => true) as $code => $show){
94
  if ($code == 'form_name')
95
  $replace_with = stripslashes($form->name);
96
  else if ($code == 'form_description')
97
  $replace_with = wpautop(stripslashes($form->description));
98
+ else if($code == 'entry_key' and isset($_GET) and isset($_GET['entry']))
99
+ $replace_with = $_GET['entry'];
100
 
101
  if (($show == true || $show == 'true') && $replace_with != '' ){
102
  $html = str_replace('[if '.$code.']','',$html);
107
  $html = str_replace('['.$code.']', $replace_with, $html);
108
  }
109
 
110
+ return apply_filters('frm_form_replace_shortcodes', $html, $form);
111
+ }
112
+
113
+ function get_default_email(){
114
+ $email = <<<DEFAULT_EMAIL
115
+ <table style="border-bottom: 1px solid rgb(238, 238, 238); width: 100%; font-size: 12px; line-height: 135%; font-family: Lucida Grande,Tahoma,Arial,sans-serif;" cellspacing="0">
116
+ <tbody><tr style="background-color: rgb(245, 245, 245);">
117
+ <th style="border-top: 1px solid rgb(238, 238, 238); padding: 7px 9px; vertical-align: top; color: rgb(34, 34, 34); text-align: left;">
118
+ Number
119
+ </th>
120
+ <td style="border-top: 1px solid rgb(238, 238, 238); padding: 7px 9px 7px 0pt; vertical-align: top; color: rgb(51, 51, 51); width: 60%;">
121
+ <div>89</div>
122
+
123
+ </td>
124
+ </tr>
125
+ <tr style="background-color: rgb(255, 255, 255);">
126
+ <th style="border-top: 1px solid rgb(238, 238, 238); padding: 7px 9px; vertical-align: top; color: rgb(34, 34, 34); text-align: left;">
127
+ Email
128
+ </th>
129
+ <td style="border-top: 1px solid rgb(238, 238, 238); padding: 7px 9px 7px 0pt; vertical-align: top; color: rgb(51, 51, 51); width: 60%;">
130
+ <a href="mailto:stephywells@gmail.com" target="_blank">stephywells@gmail.com</a>
131
+ </td>
132
+ </tr>
133
+ </tbody></table>
134
+ DEFAULT_EMAIL;
135
+ return $email;
136
  }
137
 
138
  }
classes/models/FrmDb.php ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class FrmDb{
3
+ var $fields;
4
+ var $forms;
5
+ var $entries;
6
+ var $entry_metas;
7
+
8
+ function FrmDb(){
9
+ global $wpdb;
10
+ $this->fields = $wpdb->prefix . "frm_fields";
11
+ $this->forms = $wpdb->prefix . "frm_forms";
12
+ $this->entries = $wpdb->prefix . "frm_items";
13
+ $this->entry_metas = $wpdb->prefix . "frm_item_metas";
14
+ }
15
+
16
+ function upgrade(){
17
+ global $wpdb, $frm_form, $frm_field;
18
+ $db_version = 1.03; // this is the version of the database we're moving to
19
+ $old_db_version = get_option('frm_db_version');
20
+
21
+ if ($db_version != $old_db_version){
22
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
23
+
24
+ $charset_collate = '';
25
+ if( $wpdb->has_cap( 'collation' ) ){
26
+ if( !empty($wpdb->charset) )
27
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
28
+ if( !empty($wpdb->collate) )
29
+ $charset_collate .= " COLLATE $wpdb->collate";
30
+ }
31
+
32
+ /* Create/Upgrade Fields Table */
33
+ $sql = "CREATE TABLE {$this->fields} (
34
+ id int(11) NOT NULL auto_increment,
35
+ field_key varchar(255) default NULL,
36
+ name varchar(255) default NULL,
37
+ description text default NULL,
38
+ type text default NULL,
39
+ default_value longtext default NULL,
40
+ options longtext default NULL,
41
+ field_order int(11) default 0,
42
+ required int(1) default NULL,
43
+ field_options longtext default NULL,
44
+ form_id int(11) default NULL,
45
+ created_at datetime NOT NULL,
46
+ PRIMARY KEY (id),
47
+ KEY form_id (form_id)
48
+ ) {$charset_collate};";
49
+
50
+ dbDelta($sql);
51
+
52
+ /* Create/Upgrade Forms Table */
53
+ $sql = "CREATE TABLE {$this->forms} (
54
+ id int(11) NOT NULL auto_increment,
55
+ form_key varchar(255) default NULL,
56
+ name varchar(255) default NULL,
57
+ description text default NULL,
58
+ logged_in boolean default NULL,
59
+ editable boolean default NULL,
60
+ is_template boolean default 0,
61
+ default_template boolean default 0,
62
+ status varchar(255) default NULL,
63
+ prli_link_id int(11) default NULL,
64
+ options longtext default NULL,
65
+ notifications longtext default NULL,
66
+ created_at datetime NOT NULL,
67
+ PRIMARY KEY (id)
68
+ ) {$charset_collate};";
69
+
70
+ dbDelta($sql);
71
+
72
+ /* Create/Upgrade Items Table */
73
+ $sql = "CREATE TABLE {$this->entries} (
74
+ id int(11) NOT NULL auto_increment,
75
+ item_key varchar(255) default NULL,
76
+ name varchar(255) default NULL,
77
+ description text default NULL,
78
+ ip text default NULL,
79
+ form_id int(11) default NULL,
80
+ created_at datetime NOT NULL,
81
+ PRIMARY KEY (id),
82
+ KEY form_id (form_id)
83
+ ) {$charset_collate};";
84
+
85
+ dbDelta($sql);
86
+
87
+ /* Create/Upgrade Meta Table */
88
+ $sql = "CREATE TABLE {$this->entry_metas} (
89
+ id int(11) NOT NULL auto_increment,
90
+ meta_key varchar(255) default NULL,
91
+ meta_value longtext default NULL,
92
+ field_id int(11) NOT NULL,
93
+ item_id int(11) NOT NULL,
94
+ created_at datetime NOT NULL,
95
+ PRIMARY KEY (id),
96
+ KEY field_id (field_id),
97
+ KEY item_id (item_id)
98
+ ) {$charset_collate};";
99
+
100
+ dbDelta($sql);
101
+
102
+ /**** MIGRATE DATA ****/
103
+ if ($db_version == 1.03){
104
+ global $frm_entry;
105
+ $all_entries = $frm_entry->getAll();
106
+ foreach($all_entries as $ent){
107
+ $opts = maybe_unserialize($ent->description);
108
+ if(is_array($opts))
109
+ $wpdb->update( $this->entries, array('ip' => $opts['ip']), array( 'id' => $ent->id ) );
110
+ }
111
+ }
112
+
113
+ /**** ADD DEFAULT TEMPLATES ****/
114
+ FrmFormsController::add_default_templates(FRM_TEMPLATES_PATH);
115
+
116
+
117
+ /***** SAVE DB VERSION *****/
118
+ update_option('frm_db_version',$db_version);
119
+ }
120
+
121
+ do_action('frm_after_install');
122
+ }
123
+
124
+ function get_count($table, $args=array()){
125
+ global $wpdb;
126
+ extract(FrmDb::get_where_clause_and_values( $args ));
127
+
128
+ $query = "SELECT COUNT(*) FROM {$table}{$where}";
129
+ $query = $wpdb->prepare($query, $values);
130
+ return $wpdb->get_var($query);
131
+ }
132
+
133
+ function get_where_clause_and_values( $args ){
134
+ $where = '';
135
+ $values = array();
136
+ if(is_array($args)){
137
+ foreach($args as $key => $value){
138
+ if(!empty($where))
139
+ $where .= ' AND';
140
+ else
141
+ $where .= ' WHERE';
142
+
143
+ $where .= " {$key}=";
144
+
145
+ if(is_numeric($value))
146
+ $where .= "%d";
147
+ else
148
+ $where .= "%s";
149
+
150
+ $values[] = $value;
151
+ }
152
+ }
153
+
154
+ return compact('where','values');
155
+ }
156
+
157
+ function get_one_record($table, $args=array()){
158
+ global $wpdb;
159
+
160
+ extract(FrmDb::get_where_clause_and_values( $args ));
161
+
162
+ $query = "SELECT * FROM {$table}{$where} LIMIT 1";
163
+ $query = $wpdb->prepare($query, $values);
164
+ return $wpdb->get_row($query);
165
+ }
166
+
167
+ function get_records($table, $args=array(), $order_by='', $limit=''){
168
+ global $wpdb;
169
+
170
+ extract(FrmDb::get_where_clause_and_values( $args ));
171
+
172
+ if(!empty($order_by))
173
+ $order_by = " ORDER BY {$order_by}";
174
+
175
+ if(!empty($limit))
176
+ $limit = " LIMIT {$limit}";
177
+
178
+ $query = "SELECT * FROM {$table}{$where}{$order_by}{$limit}";
179
+ $query = $wpdb->prepare($query, $values);
180
+ return $wpdb->get_results($query);
181
+ }
182
+
183
+ function uninstall(){
184
+ if(!current_user_can('administrator'))
185
+ wp_die(__('You don\'t have permission to do that!', 'formidable'));
186
+
187
+ global $frm_update, $wpdb;
188
+ $wpdb->query('DROP TABLE IF EXISTS '. $this->fields);
189
+ $wpdb->query('DROP TABLE IF EXISTS '. $this->forms);
190
+ $wpdb->query('DROP TABLE IF EXISTS '. $this->entries);
191
+ $wpdb->query('DROP TABLE IF EXISTS '. $this->entry_metas);
192
+
193
+ delete_option('frm_options');
194
+ delete_option('frm_db_version');
195
+ delete_option($frm_update->pro_last_checked_store);
196
+ delete_option($frm_update->pro_auth_store);
197
+ delete_option($frm_update->pro_cred_store);
198
+
199
+ do_action('frm_after_uninstall');
200
+ }
201
+ }
202
+ ?>
classes/models/FrmEntry.php CHANGED
@@ -3,23 +3,21 @@ class FrmEntry{
3
  var $table_name;
4
 
5
  function FrmEntry(){
6
- global $wpdb;
7
- $this->table_name = "{$wpdb->prefix}frm_items";
8
  }
9
 
10
  function create( $values ){
11
- global $wpdb, $frm_entry_meta;
12
 
13
  $new_values = array();
14
- $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $this->table_name, 'item_key');
15
  $new_values['name'] = isset($values['name']) ? $values['name'] : $values['item_key'];
16
- $new_values['description'] = serialize(array('ip' => $_SERVER['REMOTE_ADDR'],
17
- 'browser' => $_SERVER['HTTP_USER_AGENT'],
18
  'referrer' => $_SERVER['HTTP_REFERER']));
19
  $new_values['form_id'] = isset($values['form_id']) ? (int)$values['form_id']: null;
20
  $new_values['created_at'] = current_time('mysql', 1);
21
 
22
- $query_results = $wpdb->insert( $this->table_name, $new_values );
23
 
24
  if($query_results){
25
  $entry_id = $wpdb->insert_id;
@@ -32,37 +30,38 @@ class FrmEntry{
32
  }
33
 
34
  function duplicate( $id ){
35
- global $wpdb, $frm_entry, $frm_entry_meta;
36
 
37
  $values = $frm_entry->getOne( $id );
38
 
39
  $new_values = array();
40
- $new_values['item_key'] = FrmAppHelper::get_unique_key('', $this->table_name, 'item_key');
41
  $new_values['name'] = $values->name;
42
  $new_values['form_id'] = ($values->form_id)?(int)$values->form_id: null;
43
  $new_values['created_at'] = current_time('mysql', 1);
44
 
45
- $query_results = $wpdb->insert( $this->table_name, $new_values );
46
-
47
  if($query_results){
 
48
  $frm_entry_meta->duplicate_entry_metas($id);
49
- return $wpdb->insert_id;
50
  }else
51
  return false;
52
  }
53
 
54
  function update( $id, $values ){
55
- global $wpdb, $frm_entry_meta, $frm_field;
56
 
57
  $new_values = array();
 
58
  if (isset($values['item_key']))
59
- $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $this->table_name, 'item_key', $id);
60
-
61
  $new_values['name'] = isset($values['name'])?$values['name']:'';
62
  $new_values['form_id'] = isset($values['form_id'])?(int)$values['form_id']: null;
63
  //$new_values['parent_item_id'] = isset($values['parent_item_id'])?(int)$values['parent_item_id']: null;
64
 
65
- $query_results = $wpdb->update( $this->table_name, $new_values, array( 'id' => $id ) );
66
 
67
  if (isset($values['item_meta']))
68
  $frm_entry_meta->update_entry_metas($id, $values['item_meta']);
@@ -71,31 +70,28 @@ class FrmEntry{
71
  }
72
 
73
  function destroy( $id ){
74
- global $wpdb, $frm_entry_meta;
75
 
76
  // Disconnect the child items from this parent item
77
- //$query_results = $wpdb->update( $this->table_name, array('parent_item_id' => null), array( 'parent_item_id' => $id ) );
78
 
79
- $reset = 'DELETE FROM ' . $frm_entry_meta->table_name . ' WHERE item_id=' . $id;
80
- $destroy = 'DELETE FROM ' . $this->table_name . ' WHERE id=' . $id;
81
 
82
  $wpdb->query($reset);
83
  return $wpdb->query($destroy);
84
  }
85
 
86
  function update_form( $id, $value, $form_id ){
87
- global $wpdb;
88
  $form_id = isset($value) ? $form_id : NULL;
89
- return $wpdb->update( $this->table_name, array('form_id' => $form_id), array( 'id' => $id ) );
90
  }
91
 
92
  function getOne( $id ){
93
- global $wpdb, $frm_form;
94
- $query = 'SELECT it.*, ' .
95
- 'fr.name as form_name, ' .
96
- 'fr.form_key as form_key ' .
97
- 'FROM '. $this->table_name . ' it ' .
98
- 'LEFT OUTER JOIN ' . $frm_form->table_name . ' fr ON it.form_id=fr.id';
99
  if(is_numeric($id))
100
  $query .= ' WHERE it.id=' . $id;
101
  else
@@ -104,8 +100,8 @@ class FrmEntry{
104
  }
105
 
106
  function exists( $id ){
107
- global $wpdb, $frm_form;
108
- $query = 'SELECT id FROM '. $this->table_name;
109
  if(is_numeric($id))
110
  $query .= ' WHERE id=' . $id;
111
  else
@@ -118,21 +114,17 @@ class FrmEntry{
118
  }
119
 
120
  function getAll($where = '', $order_by = '', $limit = ''){
121
- global $wpdb, $frm_form, $frm_app_helper;
122
- $query = 'SELECT it.*, ' .
123
- 'fr.name as form_name, ' .
124
- 'fr.form_key as form_key ' .
125
- 'FROM '. $this->table_name . ' it ' .
126
- 'LEFT OUTER JOIN ' . $frm_form->table_name . ' fr ON it.form_id=fr.id' .
127
  $frm_app_helper->prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
128
  return $wpdb->get_results($query);
129
  }
130
 
131
  // Pagination Methods
132
  function getRecordCount($where=""){
133
- global $wpdb, $frm_app_helper, $frm_form;
134
- $query = 'SELECT COUNT(*) FROM ' . $this->table_name . ' it ' .
135
- 'LEFT OUTER JOIN ' . $frm_form->table_name . ' fr ON it.form_id=fr.id' .
136
  $frm_app_helper->prepend_and_or_where(' WHERE ', $where);
137
  return $wpdb->get_var($query);
138
  }
@@ -142,26 +134,24 @@ class FrmEntry{
142
  }
143
 
144
  function getPage($current_p,$p_size, $where = "", $order_by = ''){
145
- global $wpdb, $frm_app_helper, $frm_form;
146
  $end_index = $current_p * $p_size;
147
  $start_index = $end_index - $p_size;
148
- $query = 'SELECT it.*, ' .
149
- 'fr.name as form_name ' .
150
- 'FROM ' . $this->table_name . ' it ' .
151
- 'LEFT OUTER JOIN ' . $frm_form->table_name . ' fr ON it.form_id=fr.id' .
152
- $frm_app_helper->prepend_and_or_where(' WHERE ', $where) . $order_by . ' ' .
153
- 'LIMIT ' . $start_index . ',' . $p_size . ';';
154
  $results = $wpdb->get_results($query);
155
  return $results;
156
  }
157
 
158
  function validate( $values ){
159
- global $wpdb, $frm_field, $frm_entry_meta;
160
 
161
  $errors = array();
162
 
163
  if( !isset($values['item_key']) or $values['item_key'] == '' )
164
- $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $this->table_name, 'item_key');
165
 
166
  $where = apply_filters('frm_posted_field_ids', 'fi.form_id='.$values['form_id']);
167
  $posted_fields = $frm_field->getAll($where, ' ORDER BY fi.field_order');
@@ -173,7 +163,7 @@ class FrmEntry{
173
  $value = $values['item_meta'][$posted_field->id];
174
 
175
  if (isset($field_options['default_blank']) and $field_options['default_blank'] and $value == $posted_field->default_value)
176
- $value = '';
177
 
178
  if ($posted_field->required == '1' and $value == ''){
179
  $errors['field'.$posted_field->id] = (!isset($field_options['blank']) or $field_options['blank'] == __('Untitled cannot be blank', FRM_PLUGIN_NAME) or $field_options['blank'] == '') ? ($posted_field->name . ' '. __('can\'t be blank', FRM_PLUGIN_NAME)) : $field_options['blank'];
3
  var $table_name;
4
 
5
  function FrmEntry(){
 
 
6
  }
7
 
8
  function create( $values ){
9
+ global $wpdb, $frmdb, $frm_entry_meta;
10
 
11
  $new_values = array();
12
+ $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $frmdb->entries, 'item_key');
13
  $new_values['name'] = isset($values['name']) ? $values['name'] : $values['item_key'];
14
+ $new_values['ip'] = $_SERVER['REMOTE_ADDR'];
15
+ $new_values['description'] = serialize(array('browser' => $_SERVER['HTTP_USER_AGENT'],
16
  'referrer' => $_SERVER['HTTP_REFERER']));
17
  $new_values['form_id'] = isset($values['form_id']) ? (int)$values['form_id']: null;
18
  $new_values['created_at'] = current_time('mysql', 1);
19
 
20
+ $query_results = $wpdb->insert( $frmdb->entries, $new_values );
21
 
22
  if($query_results){
23
  $entry_id = $wpdb->insert_id;
30
  }
31
 
32
  function duplicate( $id ){
33
+ global $wpdb, $frmdb, $frm_entry, $frm_entry_meta;
34
 
35
  $values = $frm_entry->getOne( $id );
36
 
37
  $new_values = array();
38
+ $new_values['item_key'] = FrmAppHelper::get_unique_key('', $frmdb->entries, 'item_key');
39
  $new_values['name'] = $values->name;
40
  $new_values['form_id'] = ($values->form_id)?(int)$values->form_id: null;
41
  $new_values['created_at'] = current_time('mysql', 1);
42
 
43
+ $query_results = $wpdb->insert( $frmdb->entries, $new_values );
 
44
  if($query_results){
45
+ $entry_id = $wpdb->insert_id;
46
  $frm_entry_meta->duplicate_entry_metas($id);
47
+ return $entry_id;
48
  }else
49
  return false;
50
  }
51
 
52
  function update( $id, $values ){
53
+ global $wpdb, $frmdb, $frm_entry_meta, $frm_field;
54
 
55
  $new_values = array();
56
+
57
  if (isset($values['item_key']))
58
+ $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $frmdb->entries, 'item_key', $id);
59
+
60
  $new_values['name'] = isset($values['name'])?$values['name']:'';
61
  $new_values['form_id'] = isset($values['form_id'])?(int)$values['form_id']: null;
62
  //$new_values['parent_item_id'] = isset($values['parent_item_id'])?(int)$values['parent_item_id']: null;
63
 
64
+ $query_results = $wpdb->update( $frmdb->entries, $new_values, array( 'id' => $id ) );
65
 
66
  if (isset($values['item_meta']))
67
  $frm_entry_meta->update_entry_metas($id, $values['item_meta']);
70
  }
71
 
</