Save Contact Form 7 - Version 2.0

Version Description

Download this release

Release Info

Developer nimblechapps
Plugin Icon 128x128 Save Contact Form 7
Version 2.0
Comparing to
See all releases

Code changes from version 1.7 to 2.0

Files changed (2) hide show
  1. Readme.txt +5 -1
  2. save-contact-form-7.php +192 -172
Readme.txt CHANGED
@@ -6,7 +6,7 @@ Requires at least: 3.0
6
  Tested up to: 4.7.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
- Stable tag: 1.7
10
 
11
 
12
  Save Contact Form 7 data. Sort, search & export it in CSV+PDF. Best UI. Fully tested with WP 4.7.2 + CF7 4.6.1 & Totally Supported.
@@ -73,6 +73,10 @@ Select any form for which you want to download the entries, from the populated e
73
 
74
  == Changelog ==
75
 
 
 
 
 
76
  = 1.7 =
77
 
78
  * Solved conflict with contact form skin plugin.
6
  Tested up to: 4.7.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+ Stable tag: 2.0
10
 
11
 
12
  Save Contact Form 7 data. Sort, search & export it in CSV+PDF. Best UI. Fully tested with WP 4.7.2 + CF7 4.6.1 & Totally Supported.
73
 
74
  == Changelog ==
75
 
76
+ = 2.0 =
77
+
78
+ * Security update.
79
+
80
  = 1.7 =
81
 
82
  * Solved conflict with contact form skin plugin.
save-contact-form-7.php CHANGED
@@ -6,22 +6,24 @@
6
  Description: A simple plugin to save contact form data to db.
7
  Author: Nimblechapps
8
  Author URI: http://nimblechapps.com
9
- Version: 1.7
10
  */
11
  //function to check dependencies for Contact Form 7 Plugin
12
 
13
  if (!defined('ABSPATH')) {
14
  exit;
15
  }
16
- define('SAVE_CF7_ADMIN_MENU','save_contact_form_7'); // define menu slug name
17
- add_action('wp_head','nimble_scf7_ajaxurl');
 
18
  function nimble_scf7_ajaxurl() {
19
- ?>
20
- <script type="text/javascript">
21
- var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
22
- </script>
23
- <?php
24
  }
 
25
  if (is_admin()) {
26
 
27
  // registering hooks for activation and deactivation of plugin
@@ -66,9 +68,9 @@ if (is_admin()) {
66
 
67
  function nimble_scripts($hook) {
68
 
69
- if ($hook != 'toplevel_page_'.SAVE_CF7_ADMIN_MENU) {
70
- return;
71
- }
72
 
73
  //register css for datatables and bootstrap
74
  wp_register_style('nimble_dt_process_circle_style', plugin_dir_url(__FILE__) . 'assets/DataTables/media/css/dataTables.customLoader.circle.css');
@@ -145,31 +147,30 @@ if (is_admin()) {
145
  <?php
146
  $nimble_cf7_names = nimble_get_cf7_name();
147
  $cf7_form_names = array();
148
- $cf7_existing = array();
149
- $cf7_deleted = array();
150
  foreach ($nimble_cf7_names as $nimble_cf_name) {
151
- $tbl = $wpdb->get_results("SHOW TABLES LIKE '" . $nimble_cf_name['CFDBA_table'] . "'");
 
152
  if ($wpdb->num_rows == 1 && !empty($tbl)) {
153
  if ($nimble_cf_name['CF7_version'] > '2.4.6' && $nimble_cf_name['CF7_from_wpposts_or_tbl'] == $wpdb->prefix . "posts") {
154
- $post_exists = $wpdb->get_results("select * from " . $wpdb->prefix . "posts where ID = " . $nimble_cf_name['CF7_form_id']);
155
  if ($wpdb->num_rows > 0 && !empty($post_exists)) {
156
  $cf7_form_names['CF7-Working'][$nimble_cf_name['ID']] = strtoupper($nimble_cf_name['form_title']);
157
  } else {
158
  $cf7_form_names['CF7-Deleted'][$nimble_cf_name['ID']] = strtoupper($nimble_cf_name['form_title']);
159
- $sql_flag_update = $wpdb->query("update SaveContactForm7_lookup SET CF7_removed_flag = 'YES' WHERE lookup_id = " . $nimble_cf_name['ID']);
 
160
  }
161
- } else {
162
- $post_exists = $wpdb->get_results("select * from " . $wpdb->prefix . "contact_form_7 where cf7_unit_id = " . $nimble_cf_name['CF7_form_id']);
163
  if ($wpdb->num_rows > 0 && !empty($post_exists)) {
164
  $cf7_form_names['CF7-Working'][$nimble_cf_name['ID']] = strtoupper($nimble_cf_name['form_title']);
165
  } else {
166
  $cf7_form_names['CF7-Deleted'][$nimble_cf_name['ID']] = strtoupper($nimble_cf_name['form_title']);
167
- $sql_flag_update = $wpdb->query("update SaveContactForm7_lookup SET CF7_removed_flag = 'YES' WHERE lookup_id = " . $nimble_cf_name['ID']);
168
  }
169
  }
170
  }
171
  }
172
-
173
  foreach ($cf7_form_names as $key => $value) {
174
  $optcolor = ($key == "CF7-Deleted" ? 'red' : '');
175
  echo "<optgroup label=" . $key . ">";
@@ -181,74 +182,71 @@ if (is_admin()) {
181
  ?>
182
  </select>
183
  </div>
184
- <div id="nimble_table_wrapper"><p><h4 align="center">Please Select a Form You Have Submitted To View Its Data........!</h4></p></div>
 
 
 
 
185
  </div>
186
  <?php
187
  }
188
 
189
  }
190
-
191
- /********************************************************************************************************************************************** */
192
- // code start for settings API use
193
- /********************************************************************************************************************************************** */
194
-
195
- add_action('admin_init', 'nimble_options');
196
 
197
- function nimble_options() {
198
- /* Display Options Section */
199
- add_settings_section(
200
- 'nimble_display_page', '', 'nimble_display_section_callback', 'nimble_settings_options'
201
- );
202
-
203
- add_settings_field(
204
- 'nimble_scf7_display_created_date', 'Show Created Date Field', 'nimble_display_date_options_callback', 'nimble_settings_options', 'nimble_display_page'
205
- );
206
-
207
-
208
- register_setting('nimble_settings_options', 'nimble_scf7_display_created_date');
209
- }
 
 
 
210
 
211
- /* Call Backs
212
- ----------------------------------------------------------------- */
213
 
214
- function nimble_display_section_callback() {
 
 
215
 
216
- //echo '<p> Display Data Options:</p>';
217
- }
 
218
 
219
- function nimble_display_date_options_callback() {
 
220
 
221
- echo '<input type="checkbox" id="nimble_scf7_display_created_date" name="nimble_scf7_display_created_date" value="1" ' . checked(1, get_option('nimble_scf7_display_created_date'), false) . '/> Display Entry Date & Time';
222
- }
223
-
224
-
225
-
226
- /* Display Page
227
- ----------------------------------------------------------------- */
228
-
229
- function nimble_settings_page() {
230
- global $wpdb;
231
- settings_errors();
232
-
233
- ?>
234
 
235
- <h2 class="nav-tab-wrapper">
236
- Display Settings
237
- </h2>
238
- <form method="post" action="options.php">
239
  <?php
240
- settings_fields('nimble_settings_options');
241
- do_settings_sections('nimble_settings_options');
242
  ?>
243
- <?php submit_button(); ?>
244
- </form>
245
- <?php
246
- }
 
 
247
 
248
- /********************************************************************************************************************************************** */
249
  // code after settings API use
250
- /********************************************************************************************************************************************** */
251
-
252
  // function to get submitted contact form 7 names
253
  function nimble_get_cf7_name() {
254
  global $wpdb;
@@ -256,8 +254,11 @@ if (is_admin()) {
256
  require_once ABSPATH . 'wp-admin/includes/plugin.php';
257
  }
258
  // get form title from Lookup table
259
- $sql = "select * from SaveContactForm7_lookup order by CF7_removed_flag desc";
260
- $contact_forms = $wpdb->get_results($sql);
 
 
 
261
  if (!empty($contact_forms)) {
262
  foreach ($contact_forms as $contact_form) {
263
  $form_name[] = array("ID" => $contact_form->lookup_id, "form_title" => $contact_form->CF7_created_title, "CFDBA_table" => $contact_form->CFDBA_tbl_name, "CF7_version" => $contact_form->CF7_version, "CF7_form_id" => $contact_form->CF7_form_id, "CF7_from_wpposts_or_tbl" => $contact_form->CF7_from_wpposts_or_tbl, "form_status" => $contact_form->CF7_removed_flag);
@@ -266,13 +267,14 @@ if (is_admin()) {
266
  }
267
  }
268
 
269
- // function to get db table fields name of selected form
270
  function nimble_getFields($tab, $export, $isHeader = false) {
271
  global $wpdb;
272
  $nimble_dir_pah = wp_upload_dir();
273
  $nimble_date_options = get_option('nimble_scf7_display_created_date');
274
  $id = explode("_", $tab);
275
- $col_with_cmnt = array();
 
276
  $row_fields = $wpdb->get_results("SHOW full COLUMNS FROM $tab");
277
  if (!empty($row_fields)) {
278
  if ($isHeader == true) {
@@ -290,26 +292,21 @@ if (is_admin()) {
290
  if (strlen($v->Comment) == 0) {
291
  $sendingArr[] = '`' . $v->Field . '`';
292
  } else {
293
-
294
- $sendingArr[] = ' IF( ' . $v->Field . ' IS NULL, "" , CONCAT("<a href=\'' . $nimble_dir_pah['baseurl'] . '/nimble_uploads/", `id`,"/",`' . $v->Field . '`,"\' target=\'_blank\' title=\'View-",' . $v->Field . ',"\' >","<i class=\'icon-view\'></i>","</a>","&nbsp;&nbsp;","<a href=\'' . $nimble_dir_pah['baseurl'] . '/nimble_uploads/", `id`,"/",`' . $v->Field . '`,"\' target=\'_blank\' title=\'Download-",' . $v->Field . ',"\' download>","<i class=\'icon-download\'></i>","</a>") ) as `' . $v->Field . '`';
295
-
296
  $sendingArr[] = 'CONCAT("' . $nimble_dir_pah['baseurl'] . '/nimble_uploads/", `id`,"/",`' . $v->Field . '`," ")';
 
297
  }
298
  }
299
  }
300
-
301
- if($nimble_date_options !== "")
302
- {
303
- unset($col_with_cmnt[1]);
304
- array_push($col_with_cmnt, "");
305
- $aaaa=array_values($col_with_cmnt);
306
- $arr = array($sendingArr, $aaaa);
307
- return $arr;
308
- }
309
- else
310
- {
311
- $arr = array($sendingArr, $col_with_cmnt);
312
- return $arr;
313
  }
314
  }
315
  }
@@ -320,7 +317,7 @@ if (is_admin()) {
320
  function nimble_populate_data() {
321
  global $wpdb;
322
  if (isset($_REQUEST['id'])) {
323
- $id = $_REQUEST['id'];
324
  }
325
 
326
  $dt_header = '<div class="nimble_table_inner"><table id="nimble_table_data" class="display hover" width="100%" cellspacing="0" border="0px" ><thead><tr>';
@@ -330,15 +327,14 @@ if (is_admin()) {
330
  $export = "";
331
  $db_fields = nimble_getFields($table, $export, true);
332
  $nimble_date_options = get_option('nimble_scf7_display_created_date');
333
-
334
-
335
  if (!empty($db_fields)) {
336
- if($nimble_date_options != "")
337
- {
338
- $i=0;
339
- $header_create_date_index = array_splice($db_fields[0],1,1);
340
- $header_fields_arr = array_merge($db_fields[0],$header_create_date_index);
341
-
342
  foreach ($header_fields_arr as $db_field) { // loop for column header
343
  if (!in_array($db_field, array("id"))) {
344
  $columns[] = array("db" => $db_field, "dt" => $i);
@@ -346,9 +342,9 @@ if (is_admin()) {
346
  $i++;
347
  }
348
  }
349
-
350
  foreach ($db_fields[1] as $key => $value) { // loop for export options columns like [0,1,2,3,5] and target column
351
- if ($key == 0 ) {
352
  continue;
353
  } elseif ($value == "") {
354
  $dt_columnslist .= $dt_columnslistCount . ",";
@@ -357,10 +353,8 @@ if (is_admin()) {
357
  }
358
  $dt_columnslistCount++;
359
  }
360
- }
361
- else
362
- {
363
- $i=0;
364
  foreach ($db_fields[0] as $db_field) { // loop for column header
365
  if (!in_array($db_field, array("id", "created_on"))) {
366
  $columns[] = array("db" => $db_field, "dt" => $i);
@@ -368,9 +362,9 @@ if (is_admin()) {
368
  $i++;
369
  }
370
  }
371
-
372
  foreach ($db_fields[1] as $key => $value) { // loop for export options columns like [0,1,2,3,5] and target column
373
- if ($key == 0 || $key == 1) {
374
  continue;
375
  } elseif ($value == "") {
376
  $dt_columnslist .= $dt_columnslistCount . ",";
@@ -380,7 +374,7 @@ if (is_admin()) {
380
  $dt_columnslistCount++;
381
  }
382
  }
383
-
384
  $dt_header .= '</tr></thead></table></div>';
385
  $data['dt_header'] = $dt_header;
386
  $data['dt_columnslist'] = rtrim($dt_columnslist, ",");
@@ -399,35 +393,32 @@ if (is_admin()) {
399
  if (!function_exists("nimble_populate_datatable")) {
400
 
401
  function nimble_populate_datatable() {
402
- $export ="";
403
  if (isset($_REQUEST['exportbutton'])) {
404
- $export = $_REQUEST['exportbutton'];
405
  }
 
406
  global $wpdb;
407
  $nimble_dir_pah = wp_upload_dir();
408
- $table = "SaveContactForm7_" . $_POST['id'];
409
  $db_fields = nimble_getFields($table, $export);
410
  $i = 0;
411
  $nimble_date_options = get_option('nimble_scf7_display_created_date');
412
-
413
- if (!empty($db_fields))
414
- {
415
- if($nimble_date_options != "")
416
- {
417
- $i=0;
418
- $header_create_date_index = array_splice($db_fields[0],1,1);
419
- $header_fields_arr = array_merge($db_fields[0],$header_create_date_index);
420
-
421
  foreach ($header_fields_arr as $db_field) { // loop for column header
422
  if (!in_array($db_field, array("`id`"))) {
423
  $columns[] = array("db" => $db_field, "dt" => $i);
424
  $i++;
425
  }
426
  }
427
- }
428
- else
429
- {
430
- $i=0;
431
  foreach ($db_fields[0] as $db_field) { // loop for column header
432
  if (!in_array($db_field, array("`id`", "`created_on`"))) {
433
  $columns[] = array("db" => $db_field, "dt" => $i);
@@ -435,7 +426,7 @@ if (is_admin()) {
435
  }
436
  }
437
  }
438
-
439
  $sql_details = array(
440
  'user' => $wpdb->dbuser,
441
  'pass' => $wpdb->dbpassword,
@@ -443,23 +434,20 @@ if (is_admin()) {
443
  'host' => $wpdb->dbhost
444
  );
445
  /** for custom filter and export data ** */
446
-
447
  if (isset($_REQUEST['searchvalue']) && $_REQUEST['searchvalue'] != '') {
448
- $search = $_REQUEST['searchvalue'];
449
-
450
-
451
  } else {
452
  $search = '';
453
  }
454
- $ordertype ="";
455
- $join="";
456
  if (isset($_REQUEST['column']) && $_REQUEST['column'] != '') {
457
- $columnorder = $_REQUEST['column'];
458
- $ordertype = $_REQUEST['ordertype'];
459
  } else {
460
  $columnorder = '';
461
  }
462
-
463
  /** for custom filter and export data code ends ** */
464
  $primaryKey = 'id';
465
  require( 'includes/ssp.class.php' );
@@ -474,9 +462,9 @@ if (is_admin()) {
474
  }
475
  }
476
  }
477
-
478
- echo json_encode($data);
479
- wp_die();
480
  }
481
 
482
  }
@@ -567,6 +555,7 @@ if (is_admin()) {
567
  if ($table != "") {
568
  $sql_create = "CREATE TABLE IF NOT EXISTS " . $table . "(`id` int(8) NOT NULL PRIMARY KEY AUTO_INCREMENT, `created_on` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " . $db_table_field . ") DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ";
569
  $wpdb->query($sql_create);
 
570
  }
571
  }
572
 
@@ -612,22 +601,22 @@ if (is_admin()) {
612
  function nimble_lookup_entry($CF7_form_id, $CF7_form_title, $CF7_version, $CF7_from, $form) {
613
  global $wpdb;
614
  $sql_lookup_insert = "INSERT INTO SaveContactForm7_lookup (`CF7_created_title`, `CF7_version`, `CF7_form_id`,`CF7_from_wpposts_or_tbl` )
615
- SELECT * FROM (SELECT '" . $CF7_form_title . "', '" . $CF7_version . "' , " . $CF7_form_id . ",'" . $CF7_from . "') AS tmp
616
  WHERE NOT EXISTS (
617
  SELECT CF7_form_id
618
  FROM SaveContactForm7_lookup
619
- WHERE `CF7_version` = '" . $CF7_version . "'
620
- AND `CF7_form_id` = '" . $CF7_form_id . "'
621
- AND `CF7_from_wpposts_or_tbl` = '" . $CF7_from . "'
622
  AND `CF7_removed_flag` = 'NO') LIMIT 1";
623
 
624
- if ($wpdb->query($sql_lookup_insert)) {
625
  $table = "SaveContactForm7_" . $wpdb->insert_id;
626
  } else {
627
  $table = "";
628
  }
629
- $sql_lookup_update = "UPDATE `SaveContactForm7_lookup` SET `CFDBA_tbl_name` = '" . $table . "' WHERE `lookup_id` = " . $wpdb->insert_id . "";
630
- $wpdb->query($sql_lookup_update);
631
  return $table;
632
  }
633
 
@@ -638,8 +627,8 @@ if (is_admin()) {
638
 
639
  function nimble_get_tbl_from_lookup($CF7_form_id, $CF7_title, $CF7_version, $CF7_from) {
640
  global $wpdb;
641
- $result = $wpdb->get_results("select `CFDBA_tbl_name` from SaveContactForm7_lookup where CF7_form_id = " . $CF7_form_id . " AND CF7_version = '" . $CF7_version . "' AND CF7_from_wpposts_or_tbl = '" . $CF7_from . "' AND CF7_removed_flag = 'NO' ");
642
 
 
643
  if (!empty($result[0]->CFDBA_tbl_name)) {
644
  return $result[0]->CFDBA_tbl_name;
645
  }
@@ -677,6 +666,7 @@ if (!function_exists("nimble_save_cf7_data")) {
677
  $submited['uploaded_files'] = $submission->uploaded_files();
678
  }
679
  $table = nimble_get_tbl_from_lookup($obj->id(), $obj->title(), $CF7_version, $CF7_from);
 
680
  if ($table == "") {
681
  $table = nimble_lookup_entry($obj->id(), $obj->title(), $CF7_version, $CF7_from, $form);
682
  }
@@ -712,6 +702,7 @@ if (!function_exists("nimble_save_cf7_data")) {
712
  $submited['uploaded_files'] = $submission->uploaded_files;
713
  }
714
  $table = nimble_get_tbl_from_lookup($submission->id, $submited['title'], $CF7_version, $CF7_from);
 
715
  if ($table == "") {
716
  $table = nimble_lookup_entry($submission->id, $submited['title'], $CF7_version, $CF7_from, $form);
717
  }
@@ -729,6 +720,7 @@ if (!function_exists("nimble_save_cf7_data")) {
729
  $submited['uploaded_files'] = $submission->uploaded_files;
730
  }
731
  $table = nimble_get_tbl_from_lookup($submission->id, $submited['title'], $CF7_version, $CF7_from);
 
732
  if ($table == "") {
733
  $table = nimble_lookup_entry($submission->id, $submited['title'], $CF7_version, $CF7_from, $form);
734
  }
@@ -746,6 +738,7 @@ if (!function_exists("nimble_save_cf7_data")) {
746
  $submited['uploaded_files'] = $submission->uploaded_files;
747
  }
748
  $table = nimble_get_tbl_from_lookup($submission->id, $submited['title'], $CF7_version, $CF7_from);
 
749
  if ($table == "") {
750
  $table = nimble_lookup_entry($submission->id, $submited['title'], $CF7_version, $CF7_from, $form);
751
  }
@@ -762,28 +755,26 @@ if (!function_exists("nimble_save_cf7_data")) {
762
  $submited['uploaded_files'] = $submission->uploaded_files;
763
  }
764
  $table = nimble_get_tbl_from_lookup($submission->id, $submited['title'], $CF7_version, $CF7_from);
 
765
  if ($table == "") {
766
  $table = nimble_lookup_entry($submission->id, $submited['title'], $CF7_version, $CF7_from, $form);
767
  }
768
  }
769
  // version check code ends here
770
-
771
  // $arr_default_field = array("_wpcf7", "_wpcf7_version", "_wpcf7_locale", "_wpcf7_unit_tag", "_wpnonce","g-recaptcha-response", "_wpcf7_is_ajax_call");
772
  $fields = array();
773
  $values = array();
774
  $posted_data = $submited['posted_data'];
775
  $allformdata = $form;
776
  $nimble_compare_array = array();
777
- foreach($allformdata as $nimble_data_single_value){
778
- if($nimble_data_single_value['type'] != "submit" && $nimble_data_single_value['name'] != "" ){
779
  $nimble_compare_array[] = $nimble_data_single_value['name'];
780
  }
781
  }
782
-
783
  /* for version 3.1 and 3.1.1 start */
784
  if ($plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] == "3.1.1" || $plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] == "3.1") {
785
-
786
- if(isset($table) && $table != ""){
787
  $row_fields = $wpdb->get_results("SHOW full COLUMNS FROM $table");
788
  }
789
  $fname = array_values($submited['uploaded_files']);
@@ -811,10 +802,9 @@ if (!function_exists("nimble_save_cf7_data")) {
811
  $key = str_replace("-", "_", $key);
812
  }
813
  $fields[] = "`" . $key . "`";
814
- if(is_array($sdata)){
815
  $sdata == "" ? $values[] = 'NULL' : $values[] = "'" . esc_sql(implode(",", $sdata)) . "'";
816
-
817
- }else{
818
  $sdata == "" ? $values[] = 'NULL' : $values[] = "'" . esc_sql($sdata) . "'";
819
  }
820
  }
@@ -822,9 +812,11 @@ if (!function_exists("nimble_save_cf7_data")) {
822
  $field = implode(",", $fields);
823
  $value = implode(",", $values);
824
  $sql_insert = "insert into $table ($field) values ($value)";
825
- if ($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table) {
 
826
 
827
  if ($plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] >= "4.2.2") {
 
828
  $obj = WPCF7_ContactForm::get_current();
829
  $shortcode = WPCF7_ShortcodeManager::get_instance();
830
  $form = $shortcode->scan_shortcode($obj->prop('form'));
@@ -892,35 +884,56 @@ if (!function_exists("nimble_save_cf7_data")) {
892
  }
893
 
894
  if ($query_status == TRUE) {
895
- //insert image into plugin upload directory into wp-content/uploads... directory
896
  $id = $wpdb->insert_id; // last inserted row id from databasr table
897
  $fieldname = key($submited['uploaded_files']); // form input file field name
898
  if ($fieldname != "") {
899
  if ($plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] == "3.1" || $plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] == "3.1.1") {
900
  $uploaded_file_info = pathinfo(implode("/", $fname)); //uploaded file info like basename,extension etc
901
  } else {
902
-
903
  $uploaded_file_info = pathinfo($submited['posted_data'][$fieldname]); //uploaded file info like basename,extension etc
904
-
905
  }
906
  if (!file_exists($nimble_dir_pah['basedir'] . "/nimble_uploads")) {
 
 
 
907
  mkdir($nimble_dir_pah['basedir'] . "/nimble_uploads", 0777);
 
 
908
  $filepath = array_values($submited['uploaded_files']); // source location of the file
909
  if (!isset($filepath)) {
 
910
  if (!file_exists($nimble_dir_pah['basedir'] . "/nimble_uploads/$id")) {
911
  mkdir($nimble_dir_pah['basedir'] . "/nimble_uploads/$id", 0777);
 
 
912
  $newfile = $nimble_dir_pah['basedir'] . "/nimble_uploads/$id/" . $uploaded_file_info['basename']; // destination location of the file
913
  copy($filepath[0], $newfile);
914
  } else {
 
 
 
 
 
 
 
 
 
915
  $newfile = $nimble_dir_pah['basedir'] . "/nimble_uploads/$id/" . $uploaded_file_info['basename']; // destination location of the file
916
  copy($filepath[0], $newfile);
917
  }
918
  }
919
  } else {
 
920
  $filepath = array_values($submited['uploaded_files']); // source location of the file
921
  if (isset($filepath)) {
922
  if (!file_exists($nimble_dir_pah['basedir'] . "/nimble_uploads/$id")) {
923
  mkdir($nimble_dir_pah['basedir'] . "/nimble_uploads/$id", 0777);
 
 
 
 
 
924
  $newfile = $nimble_dir_pah['basedir'] . "/nimble_uploads/$id/" . $uploaded_file_info['basename']; // destination location of the file
925
  copy($filepath[0], $newfile);
926
  } else {
@@ -933,6 +946,7 @@ if (!function_exists("nimble_save_cf7_data")) {
933
  }
934
  //file uploads code ends here
935
  }
 
936
  }
937
  add_action('wpcf7_before_send_mail', 'nimble_save_cf7_data');
938
 
@@ -966,7 +980,6 @@ if (!function_exists("nimble_after_cf7_update")) {
966
  $form = $shortcode->scan_shortcode($obj->prop('form'));
967
  $table = nimble_get_tbl_from_lookup($obj->id(), $CF7_form_title, $CF7_version, $CF7_from);
968
  } else if ($plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] >= "3.7") {
969
-
970
  $submission = $wpcf7;
971
  $CF7_form_title = $submission->title;
972
  $CF7_version = $plugin_data['contact-form-7/wp-contact-form-7.php']['Version'];
@@ -1011,14 +1024,21 @@ if (!function_exists("nimble_after_cf7_update")) {
1011
  if (!in_array($fields['name'], $db_table_fields)) {
1012
  if ($fields['type'] == 'file' || $fields['type'] == 'file*') {
1013
  $newFieldsArr[] = "`" . $fields['name'] . "` text COMMENT 'file_field' default NULL ";
 
 
1014
  } else {
 
1015
  $newFieldsArr[] = $fields['name'] . " text ";
 
 
1016
  }
1017
  }
1018
  }
1019
 
1020
  if (!empty($newFieldsArr)) {
 
1021
  $newFieldsStr = implode(',', $newFieldsArr);
 
1022
  $sql_alter = "ALTER TABLE $table ADD(" . $newFieldsStr . ")";
1023
  $wpdb->query($sql_alter);
1024
  }
@@ -1026,8 +1046,8 @@ if (!function_exists("nimble_after_cf7_update")) {
1026
  if ($CF7_form_title == "") {
1027
  $CF7_form_title = "Untitled";
1028
  }
1029
- $sql_alter_lookup = "UPDATE SaveContactForm7_lookup SET `CF7_created_title` = '$CF7_form_title' WHERE `CFDBA_tbl_name` = '$table'";
1030
- $wpdb->query($sql_alter_lookup);
1031
  }
1032
 
1033
  }
@@ -1041,8 +1061,8 @@ if (!function_exists("nimble_get_tbl_from_lookup")) {
1041
 
1042
  function nimble_get_tbl_from_lookup($CF7_form_id, $CF7_title, $CF7_version, $CF7_from) {
1043
  global $wpdb;
1044
- $result = $wpdb->get_results("select `CFDBA_tbl_name` from SaveContactForm7_lookup where CF7_form_id = " . $CF7_form_id . " AND CF7_created_title ='" . $CF7_title . "' AND CF7_version = '" . $CF7_version . "' AND CF7_from_wpposts_or_tbl = '" . $CF7_from . "' AND CF7_removed_flag = 'NO' ");
1045
-
1046
  if (!empty($result[0]->CFDBA_tbl_name)) {
1047
  return $result[0]->CFDBA_tbl_name;
1048
  }
@@ -1074,22 +1094,22 @@ if (!function_exists("nimble_lookup_entry")) {
1074
  function nimble_lookup_entry($CF7_form_id, $CF7_form_title, $CF7_version, $CF7_from, $form) {
1075
  global $wpdb;
1076
  $sql_lookup_insert = "INSERT INTO SaveContactForm7_lookup (`CF7_created_title`, `CF7_version`, `CF7_form_id`,`CF7_from_wpposts_or_tbl` )
1077
- SELECT * FROM (SELECT '" . $CF7_form_title . "', '" . $CF7_version . "' , " . $CF7_form_id . ",'" . $CF7_from . "') AS tmp
1078
  WHERE NOT EXISTS (
1079
  SELECT CF7_form_id
1080
  FROM SaveContactForm7_lookup
1081
- WHERE `CF7_version` = '" . $CF7_version . "'
1082
- AND `CF7_form_id` = '" . $CF7_form_id . "'
1083
- AND `CF7_from_wpposts_or_tbl` = '" . $CF7_from . "'
1084
  AND `CF7_removed_flag` = 'NO') LIMIT 1";
1085
 
1086
- if ($wpdb->query($sql_lookup_insert)) {
1087
  $table = "SaveContactForm7_" . $wpdb->insert_id;
1088
  } else {
1089
  $table = "";
1090
  }
1091
- $sql_lookup_update = "UPDATE `SaveContactForm7_lookup` SET `CFDBA_tbl_name` = '" . $table . "' WHERE `lookup_id` = " . $wpdb->insert_id . "";
1092
- $wpdb->query($sql_lookup_update);
1093
  return $table;
1094
  }
1095
 
6
  Description: A simple plugin to save contact form data to db.
7
  Author: Nimblechapps
8
  Author URI: http://nimblechapps.com
9
+ Version: 2.0
10
  */
11
  //function to check dependencies for Contact Form 7 Plugin
12
 
13
  if (!defined('ABSPATH')) {
14
  exit;
15
  }
16
+ define('SAVE_CF7_ADMIN_MENU', 'save_contact_form_7'); // define menu slug name
17
+ add_action('wp_head', 'nimble_scf7_ajaxurl');
18
+
19
  function nimble_scf7_ajaxurl() {
20
+ ?>
21
+ <script type="text/javascript">
22
+ var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
23
+ </script>
24
+ <?php
25
  }
26
+
27
  if (is_admin()) {
28
 
29
  // registering hooks for activation and deactivation of plugin
68
 
69
  function nimble_scripts($hook) {
70
 
71
+ if ($hook != 'toplevel_page_' . SAVE_CF7_ADMIN_MENU) {
72
+ return;
73
+ }
74
 
75
  //register css for datatables and bootstrap
76
  wp_register_style('nimble_dt_process_circle_style', plugin_dir_url(__FILE__) . 'assets/DataTables/media/css/dataTables.customLoader.circle.css');
147
  <?php
148
  $nimble_cf7_names = nimble_get_cf7_name();
149
  $cf7_form_names = array();
 
 
150
  foreach ($nimble_cf7_names as $nimble_cf_name) {
151
+ //$tbl = $wpdb->get_results("SHOW TABLES LIKE '" . $nimble_cf_name['CFDBA_table'] . "'");
152
+ $tbl = $wpdb->query($wpdb->prepare("SHOW TABLES LIKE '%s'", $nimble_cf_name['CFDBA_table']));
153
  if ($wpdb->num_rows == 1 && !empty($tbl)) {
154
  if ($nimble_cf_name['CF7_version'] > '2.4.6' && $nimble_cf_name['CF7_from_wpposts_or_tbl'] == $wpdb->prefix . "posts") {
155
+ $post_exists = $wpdb->query($wpdb->prepare("select * from " . $wpdb->prefix . "posts where ID = %d", (int) $nimble_cf_name['CF7_form_id']));
156
  if ($wpdb->num_rows > 0 && !empty($post_exists)) {
157
  $cf7_form_names['CF7-Working'][$nimble_cf_name['ID']] = strtoupper($nimble_cf_name['form_title']);
158
  } else {
159
  $cf7_form_names['CF7-Deleted'][$nimble_cf_name['ID']] = strtoupper($nimble_cf_name['form_title']);
160
+ $sql_flag_update = $wpdb->query($wpdb->prepare("update SaveContactForm7_lookup SET CF7_removed_flag = %s WHERE lookup_id = %d "), "YES", (int) $nimble_cf_name['ID']
161
+ );
162
  }
163
+ } else {
164
+ $post_exists = $wpdb->get_results($wpdb->prepare("select * from " . $wpdb->prefix . "contact_form_7 where cf7_unit_id = %s ", $nimble_cf_name['CF7_form_id']));
165
  if ($wpdb->num_rows > 0 && !empty($post_exists)) {
166
  $cf7_form_names['CF7-Working'][$nimble_cf_name['ID']] = strtoupper($nimble_cf_name['form_title']);
167
  } else {
168
  $cf7_form_names['CF7-Deleted'][$nimble_cf_name['ID']] = strtoupper($nimble_cf_name['form_title']);
169
+ $sql_flag_update = $wpdb->query($wpdb->prepare("update SaveContactForm7_lookup SET CF7_removed_flag = %s WHERE lookup_id = %d "), "YES", (int) $nimble_cf_name['ID']);
170
  }
171
  }
172
  }
173
  }
 
174
  foreach ($cf7_form_names as $key => $value) {
175
  $optcolor = ($key == "CF7-Deleted" ? 'red' : '');
176
  echo "<optgroup label=" . $key . ">";
182
  ?>
183
  </select>
184
  </div>
185
+ <div id="nimble_table_wrapper">
186
+ <p>
187
+ <h4 align="center">Please Select a Form You Have Submitted To View Its Data........!</h4>
188
+ </p>
189
+ </div>
190
  </div>
191
  <?php
192
  }
193
 
194
  }
 
 
 
 
 
 
195
 
196
+ /* * ******************************************************************************************************************************************** */
197
+ // code start for settings API use
198
+ /* * ******************************************************************************************************************************************** */
199
+
200
+ add_action('admin_init', 'nimble_options');
201
+
202
+ function nimble_options() {
203
+ /* Display Options Section */
204
+ add_settings_section(
205
+ 'nimble_display_page', '', 'nimble_display_section_callback', 'nimble_settings_options'
206
+ );
207
+ add_settings_field(
208
+ 'nimble_scf7_display_created_date', 'Show Created Date Field', 'nimble_display_date_options_callback', 'nimble_settings_options', 'nimble_display_page'
209
+ );
210
+ register_setting('nimble_settings_options', 'nimble_scf7_display_created_date');
211
+ }
212
 
213
+ /* Call Backs
214
+ ----------------------------------------------------------------- */
215
 
216
+ function nimble_display_section_callback() {
217
+ //echo '<p> Display Data Options:</p>';
218
+ }
219
 
220
+ function nimble_display_date_options_callback() {
221
+ echo '<input type="checkbox" id="nimble_scf7_display_created_date" name="nimble_scf7_display_created_date" value="1" ' . checked(1, get_option('nimble_scf7_display_created_date'), false) . '/> Display Entry Date & Time';
222
+ }
223
 
224
+ /* Display Page
225
+ ----------------------------------------------------------------- */
226
 
227
+ function nimble_settings_page() {
228
+ global $wpdb;
229
+ settings_errors();
230
+ ?>
 
 
 
 
 
 
 
 
 
231
 
232
+ <h2 class="nav-tab-wrapper">
233
+ Display Settings
234
+ </h2>
235
+ <form method="post" action="options.php">
236
  <?php
237
+ settings_fields('nimble_settings_options');
238
+ do_settings_sections('nimble_settings_options');
239
  ?>
240
+ <?php submit_button(); ?>
241
+ </form>
242
+ <?php
243
+ }
244
+
245
+ /* * ******************************************************************************************************************************************** */
246
 
 
247
  // code after settings API use
248
+ /* * ******************************************************************************************************************************************** */
249
+
250
  // function to get submitted contact form 7 names
251
  function nimble_get_cf7_name() {
252
  global $wpdb;
254
  require_once ABSPATH . 'wp-admin/includes/plugin.php';
255
  }
256
  // get form title from Lookup table
257
+
258
+ $contact_forms = $wpdb->get_results("select * from SaveContactForm7_lookup order by CF7_removed_flag desc");
259
+ //var_dump($contact_forms);exit;
260
+ //$sql = "select * from SaveContactForm7_lookup order by CF7_removed_flag desc";
261
+ //$contact_forms = $wpdb->get_results($sql);
262
  if (!empty($contact_forms)) {
263
  foreach ($contact_forms as $contact_form) {
264
  $form_name[] = array("ID" => $contact_form->lookup_id, "form_title" => $contact_form->CF7_created_title, "CFDBA_table" => $contact_form->CFDBA_tbl_name, "CF7_version" => $contact_form->CF7_version, "CF7_form_id" => $contact_form->CF7_form_id, "CF7_from_wpposts_or_tbl" => $contact_form->CF7_from_wpposts_or_tbl, "form_status" => $contact_form->CF7_removed_flag);
267
  }
268
  }
269
 
270
+ // function to get db table fields name of selected form
271
  function nimble_getFields($tab, $export, $isHeader = false) {
272
  global $wpdb;
273
  $nimble_dir_pah = wp_upload_dir();
274
  $nimble_date_options = get_option('nimble_scf7_display_created_date');
275
  $id = explode("_", $tab);
276
+ $col_with_cmnt = array();
277
+
278
  $row_fields = $wpdb->get_results("SHOW full COLUMNS FROM $tab");
279
  if (!empty($row_fields)) {
280
  if ($isHeader == true) {
292
  if (strlen($v->Comment) == 0) {
293
  $sendingArr[] = '`' . $v->Field . '`';
294
  } else {
 
 
 
295
  $sendingArr[] = 'CONCAT("' . $nimble_dir_pah['baseurl'] . '/nimble_uploads/", `id`,"/",`' . $v->Field . '`," ")';
296
+ $sendingArr[] = ' IF( ' . $v->Field . ' IS NULL, "" , CONCAT("<a href=\'' . $nimble_dir_pah['baseurl'] . '/nimble_uploads/", `id`,"/",`' . $v->Field . '`,"\' target=\'_blank\' title=\'View-",' . $v->Field . ',"\' >","<i class=\'icon-view\'></i>","</a>","&nbsp;&nbsp;","<a href=\'' . $nimble_dir_pah['baseurl'] . '/nimble_uploads/", `id`,"/",`' . $v->Field . '`,"\' target=\'_blank\' title=\'Download-",' . $v->Field . ',"\' download>","<i class=\'icon-download\'></i>","</a>") ) as `' . $v->Field . '`';
297
  }
298
  }
299
  }
300
+
301
+ if ($nimble_date_options !== "") {
302
+ unset($col_with_cmnt[1]);
303
+ array_push($col_with_cmnt, "");
304
+ $aaaa = array_values($col_with_cmnt);
305
+ $arr = array($sendingArr, $aaaa);
306
+ return $arr;
307
+ } else {
308
+ $arr = array($sendingArr, $col_with_cmnt);
309
+ return $arr;
 
 
 
310
  }
311
  }
312
  }
317
  function nimble_populate_data() {
318
  global $wpdb;
319
  if (isset($_REQUEST['id'])) {
320
+ $id = absint($_REQUEST['id']);
321
  }
322
 
323
  $dt_header = '<div class="nimble_table_inner"><table id="nimble_table_data" class="display hover" width="100%" cellspacing="0" border="0px" ><thead><tr>';
327
  $export = "";
328
  $db_fields = nimble_getFields($table, $export, true);
329
  $nimble_date_options = get_option('nimble_scf7_display_created_date');
330
+
331
+
332
  if (!empty($db_fields)) {
333
+ if ($nimble_date_options != "") {
334
+ $i = 0;
335
+ $header_create_date_index = array_splice($db_fields[0], 1, 1);
336
+ $header_fields_arr = array_merge($db_fields[0], $header_create_date_index);
337
+
 
338
  foreach ($header_fields_arr as $db_field) { // loop for column header
339
  if (!in_array($db_field, array("id"))) {
340
  $columns[] = array("db" => $db_field, "dt" => $i);
342
  $i++;
343
  }
344
  }
345
+
346
  foreach ($db_fields[1] as $key => $value) { // loop for export options columns like [0,1,2,3,5] and target column
347
+ if ($key == 0) {
348
  continue;
349
  } elseif ($value == "") {
350
  $dt_columnslist .= $dt_columnslistCount . ",";
353
  }
354
  $dt_columnslistCount++;
355
  }
356
+ } else {
357
+ $i = 0;
 
 
358
  foreach ($db_fields[0] as $db_field) { // loop for column header
359
  if (!in_array($db_field, array("id", "created_on"))) {
360
  $columns[] = array("db" => $db_field, "dt" => $i);
362
  $i++;
363
  }
364
  }
365
+
366
  foreach ($db_fields[1] as $key => $value) { // loop for export options columns like [0,1,2,3,5] and target column
367
+ if ($key == 0 || $key == 1) {
368
  continue;
369
  } elseif ($value == "") {
370
  $dt_columnslist .= $dt_columnslistCount . ",";
374
  $dt_columnslistCount++;
375
  }
376
  }
377
+
378
  $dt_header .= '</tr></thead></table></div>';
379
  $data['dt_header'] = $dt_header;
380
  $data['dt_columnslist'] = rtrim($dt_columnslist, ",");
393
  if (!function_exists("nimble_populate_datatable")) {
394
 
395
  function nimble_populate_datatable() {
396
+ $export = "";
397
  if (isset($_REQUEST['exportbutton'])) {
398
+ $export = sanitize_text_field($_REQUEST['exportbutton']);
399
  }
400
+
401
  global $wpdb;
402
  $nimble_dir_pah = wp_upload_dir();
403
+ $table = "SaveContactForm7_" . absint($_POST['id']);
404
  $db_fields = nimble_getFields($table, $export);
405
  $i = 0;
406
  $nimble_date_options = get_option('nimble_scf7_display_created_date');
407
+
408
+ if (!empty($db_fields)) {
409
+ if ($nimble_date_options != "") {
410
+ $i = 0;
411
+ $header_create_date_index = array_splice($db_fields[0], 1, 1);
412
+ $header_fields_arr = array_merge($db_fields[0], $header_create_date_index);
413
+
 
 
414
  foreach ($header_fields_arr as $db_field) { // loop for column header
415
  if (!in_array($db_field, array("`id`"))) {
416
  $columns[] = array("db" => $db_field, "dt" => $i);
417
  $i++;
418
  }
419
  }
420
+ } else {
421
+ $i = 0;
 
 
422
  foreach ($db_fields[0] as $db_field) { // loop for column header
423
  if (!in_array($db_field, array("`id`", "`created_on`"))) {
424
  $columns[] = array("db" => $db_field, "dt" => $i);
426
  }
427
  }
428
  }
429
+
430
  $sql_details = array(
431
  'user' => $wpdb->dbuser,
432
  'pass' => $wpdb->dbpassword,
434
  'host' => $wpdb->dbhost
435
  );
436
  /** for custom filter and export data ** */
 
437
  if (isset($_REQUEST['searchvalue']) && $_REQUEST['searchvalue'] != '') {
438
+ $search = sanitize_text_field($_REQUEST['searchvalue']);
 
 
439
  } else {
440
  $search = '';
441
  }
442
+ $ordertype = "";
443
+ $join = "";
444
  if (isset($_REQUEST['column']) && $_REQUEST['column'] != '') {
445
+ $columnorder = sanitize_text_field($_REQUEST['column']);
446
+ $ordertype = sanitize_text_field($_REQUEST['ordertype']);
447
  } else {
448
  $columnorder = '';
449
  }
450
+
451
  /** for custom filter and export data code ends ** */
452
  $primaryKey = 'id';
453
  require( 'includes/ssp.class.php' );
462
  }
463
  }
464
  }
465
+
466
+ echo json_encode($data);
467
+ wp_die();
468
  }
469
 
470
  }
555
  if ($table != "") {
556
  $sql_create = "CREATE TABLE IF NOT EXISTS " . $table . "(`id` int(8) NOT NULL PRIMARY KEY AUTO_INCREMENT, `created_on` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " . $db_table_field . ") DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ";
557
  $wpdb->query($sql_create);
558
+ // $wpdb->query( $wpdb->prepare("CREATE TABLE IF NOT EXISTS %s (`id` int(8) NOT NULL PRIMARY KEY AUTO_INCREMENT, `created_on` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, %s) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ", $table,$db_table_field) );
559
  }
560
  }
561
 
601
  function nimble_lookup_entry($CF7_form_id, $CF7_form_title, $CF7_version, $CF7_from, $form) {
602
  global $wpdb;
603
  $sql_lookup_insert = "INSERT INTO SaveContactForm7_lookup (`CF7_created_title`, `CF7_version`, `CF7_form_id`,`CF7_from_wpposts_or_tbl` )
604
+ SELECT * FROM (SELECT %s, %s, %d, %s) AS tmp
605
  WHERE NOT EXISTS (
606
  SELECT CF7_form_id
607
  FROM SaveContactForm7_lookup
608
+ WHERE `CF7_version` = %s
609
+ AND `CF7_form_id` = %d
610
+ AND `CF7_from_wpposts_or_tbl` = %s
611
  AND `CF7_removed_flag` = 'NO') LIMIT 1";
612
 
613
+ if ($wpdb->query($wpdb->prepare($sql_lookup_insert, $CF7_form_title, $CF7_version, $CF7_form_id, $CF7_from, $CF7_version, $CF7_form_id, $CF7_from))) {
614
  $table = "SaveContactForm7_" . $wpdb->insert_id;
615
  } else {
616
  $table = "";
617
  }
618
+ $sql_lookup_update = "UPDATE `SaveContactForm7_lookup` SET `CFDBA_tbl_name` = %s WHERE `lookup_id` = %d ";
619
+ $wpdb->query($wpdb->prepare($sql_lookup_update, $table, $wpdb->insert_id));
620
  return $table;
621
  }
622
 
627
 
628
  function nimble_get_tbl_from_lookup($CF7_form_id, $CF7_title, $CF7_version, $CF7_from) {
629
  global $wpdb;
 
630
 
631
+ $result = $wpdb->get_results($wpdb->prepare("select `CFDBA_tbl_name` from SaveContactForm7_lookup where CF7_form_id = %d AND CF7_version = %s AND CF7_from_wpposts_or_tbl = %s AND CF7_removed_flag = 'NO' ", (int) $CF7_form_id, $CF7_version, $CF7_from));
632
  if (!empty($result[0]->CFDBA_tbl_name)) {
633
  return $result[0]->CFDBA_tbl_name;
634
  }
666
  $submited['uploaded_files'] = $submission->uploaded_files();
667
  }
668
  $table = nimble_get_tbl_from_lookup($obj->id(), $obj->title(), $CF7_version, $CF7_from);
669
+
670
  if ($table == "") {
671
  $table = nimble_lookup_entry($obj->id(), $obj->title(), $CF7_version, $CF7_from, $form);
672
  }
702
  $submited['uploaded_files'] = $submission->uploaded_files;
703
  }
704
  $table = nimble_get_tbl_from_lookup($submission->id, $submited['title'], $CF7_version, $CF7_from);
705
+
706
  if ($table == "") {
707
  $table = nimble_lookup_entry($submission->id, $submited['title'], $CF7_version, $CF7_from, $form);
708
  }
720
  $submited['uploaded_files'] = $submission->uploaded_files;
721
  }
722
  $table = nimble_get_tbl_from_lookup($submission->id, $submited['title'], $CF7_version, $CF7_from);
723
+
724
  if ($table == "") {
725
  $table = nimble_lookup_entry($submission->id, $submited['title'], $CF7_version, $CF7_from, $form);
726
  }
738
  $submited['uploaded_files'] = $submission->uploaded_files;
739
  }
740
  $table = nimble_get_tbl_from_lookup($submission->id, $submited['title'], $CF7_version, $CF7_from);
741
+
742
  if ($table == "") {
743
  $table = nimble_lookup_entry($submission->id, $submited['title'], $CF7_version, $CF7_from, $form);
744
  }
755
  $submited['uploaded_files'] = $submission->uploaded_files;
756
  }
757
  $table = nimble_get_tbl_from_lookup($submission->id, $submited['title'], $CF7_version, $CF7_from);
758
+
759
  if ($table == "") {
760
  $table = nimble_lookup_entry($submission->id, $submited['title'], $CF7_version, $CF7_from, $form);
761
  }
762
  }
763
  // version check code ends here
 
764
  // $arr_default_field = array("_wpcf7", "_wpcf7_version", "_wpcf7_locale", "_wpcf7_unit_tag", "_wpnonce","g-recaptcha-response", "_wpcf7_is_ajax_call");
765
  $fields = array();
766
  $values = array();
767
  $posted_data = $submited['posted_data'];
768
  $allformdata = $form;
769
  $nimble_compare_array = array();
770
+ foreach ($allformdata as $nimble_data_single_value) {
771
+ if ($nimble_data_single_value['type'] != "submit" && $nimble_data_single_value['name'] != "") {
772
  $nimble_compare_array[] = $nimble_data_single_value['name'];
773
  }
774
  }
 
775
  /* for version 3.1 and 3.1.1 start */
776
  if ($plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] == "3.1.1" || $plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] == "3.1") {
777
+ if (isset($table) && $table != "") {
 
778
  $row_fields = $wpdb->get_results("SHOW full COLUMNS FROM $table");
779
  }
780
  $fname = array_values($submited['uploaded_files']);
802
  $key = str_replace("-", "_", $key);
803
  }
804
  $fields[] = "`" . $key . "`";
805
+ if (is_array($sdata)) {
806
  $sdata == "" ? $values[] = 'NULL' : $values[] = "'" . esc_sql(implode(",", $sdata)) . "'";
807
+ } else {
 
808
  $sdata == "" ? $values[] = 'NULL' : $values[] = "'" . esc_sql($sdata) . "'";
809
  }
810
  }
812
  $field = implode(",", $fields);
813
  $value = implode(",", $values);
814
  $sql_insert = "insert into $table ($field) values ($value)";
815
+
816
+ if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s ", $table)) != $table) {
817
 
818
  if ($plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] >= "4.2.2") {
819
+
820
  $obj = WPCF7_ContactForm::get_current();
821
  $shortcode = WPCF7_ShortcodeManager::get_instance();
822
  $form = $shortcode->scan_shortcode($obj->prop('form'));
884
  }
885
 
886
  if ($query_status == TRUE) {
887
+ //insert image into plugin upload directory into wp-content/uploads... directory
888
  $id = $wpdb->insert_id; // last inserted row id from databasr table
889
  $fieldname = key($submited['uploaded_files']); // form input file field name
890
  if ($fieldname != "") {
891
  if ($plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] == "3.1" || $plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] == "3.1.1") {
892
  $uploaded_file_info = pathinfo(implode("/", $fname)); //uploaded file info like basename,extension etc
893
  } else {
 
894
  $uploaded_file_info = pathinfo($submited['posted_data'][$fieldname]); //uploaded file info like basename,extension etc
 
895
  }
896
  if (!file_exists($nimble_dir_pah['basedir'] . "/nimble_uploads")) {
897
+
898
+
899
+
900
  mkdir($nimble_dir_pah['basedir'] . "/nimble_uploads", 0777);
901
+ chmod($nimble_dir_pah['basedir'] . "/nimble_uploads", 0777);
902
+
903
  $filepath = array_values($submited['uploaded_files']); // source location of the file
904
  if (!isset($filepath)) {
905
+
906
  if (!file_exists($nimble_dir_pah['basedir'] . "/nimble_uploads/$id")) {
907
  mkdir($nimble_dir_pah['basedir'] . "/nimble_uploads/$id", 0777);
908
+ chmod($nimble_dir_pah['basedir'] . "/nimble_uploads/$id", 0777);
909
+ echo $nimble_dir_pah['basedir'] . "/nimble_uploads/$id";
910
  $newfile = $nimble_dir_pah['basedir'] . "/nimble_uploads/$id/" . $uploaded_file_info['basename']; // destination location of the file
911
  copy($filepath[0], $newfile);
912
  } else {
913
+
914
+ $newfile = $nimble_dir_pah['basedir'] . "/nimble_uploads/$id/" . $uploaded_file_info['basename']; // destination location of the file
915
+ copy($filepath[0], $newfile);
916
+ }
917
+ }else{
918
+ if (!file_exists($nimble_dir_pah['basedir'] . "/nimble_uploads/$id")) {
919
+ mkdir($nimble_dir_pah['basedir'] . "/nimble_uploads/$id", 0777);
920
+ chmod($nimble_dir_pah['basedir'] . "/nimble_uploads/$id", 0777);
921
+
922
  $newfile = $nimble_dir_pah['basedir'] . "/nimble_uploads/$id/" . $uploaded_file_info['basename']; // destination location of the file
923
  copy($filepath[0], $newfile);
924
  }
925
  }
926
  } else {
927
+
928
  $filepath = array_values($submited['uploaded_files']); // source location of the file
929
  if (isset($filepath)) {
930
  if (!file_exists($nimble_dir_pah['basedir'] . "/nimble_uploads/$id")) {
931
  mkdir($nimble_dir_pah['basedir'] . "/nimble_uploads/$id", 0777);
932
+
933
+
934
+
935
+ chmod($nimble_dir_pah['basedir'] . "/nimble_uploads/$id", 0777);
936
+
937
  $newfile = $nimble_dir_pah['basedir'] . "/nimble_uploads/$id/" . $uploaded_file_info['basename']; // destination location of the file
938
  copy($filepath[0], $newfile);
939
  } else {
946
  }
947
  //file uploads code ends here
948
  }
949
+
950
  }
951
  add_action('wpcf7_before_send_mail', 'nimble_save_cf7_data');
952
 
980
  $form = $shortcode->scan_shortcode($obj->prop('form'));
981
  $table = nimble_get_tbl_from_lookup($obj->id(), $CF7_form_title, $CF7_version, $CF7_from);
982
  } else if ($plugin_data['contact-form-7/wp-contact-form-7.php']['Version'] >= "3.7") {
 
983
  $submission = $wpcf7;
984
  $CF7_form_title = $submission->title;
985
  $CF7_version = $plugin_data['contact-form-7/wp-contact-form-7.php']['Version'];
1024
  if (!in_array($fields['name'], $db_table_fields)) {
1025
  if ($fields['type'] == 'file' || $fields['type'] == 'file*') {
1026
  $newFieldsArr[] = "`" . $fields['name'] . "` text COMMENT 'file_field' default NULL ";
1027
+ // $sql_alter = "ALTER TABLE %s ADD( %s text COMMENT 'file_field' default NULL )";
1028
+ // $wpdb->query( $wpdb->prepare($sql_alter,$table,$fields['name']));
1029
  } else {
1030
+
1031
  $newFieldsArr[] = $fields['name'] . " text ";
1032
+ // $sql_alter = "ALTER TABLE %s ADD( %s text )";
1033
+ // $wpdb->query( $wpdb->prepare($sql_alter,$table,$fields['name']));
1034
  }
1035
  }
1036
  }
1037
 
1038
  if (!empty($newFieldsArr)) {
1039
+
1040
  $newFieldsStr = implode(',', $newFieldsArr);
1041
+
1042
  $sql_alter = "ALTER TABLE $table ADD(" . $newFieldsStr . ")";
1043
  $wpdb->query($sql_alter);
1044
  }
1046
  if ($CF7_form_title == "") {
1047
  $CF7_form_title = "Untitled";
1048
  }
1049
+ $sql_alter_lookup = "UPDATE SaveContactForm7_lookup SET `CF7_created_title` = %s WHERE `CFDBA_tbl_name` = %s";
1050
+ $wpdb->query($wpdb->prepare($sql_alter_lookup, $CF7_form_title, $table));
1051
  }
1052
 
1053
  }
1061
 
1062
  function nimble_get_tbl_from_lookup($CF7_form_id, $CF7_title, $CF7_version, $CF7_from) {
1063
  global $wpdb;
1064
+ //$result = $wpdb->get_results("select `CFDBA_tbl_name` from SaveContactForm7_lookup where CF7_form_id = " . $CF7_form_id . " AND CF7_created_title ='" . $CF7_title . "' AND CF7_version = '" . $CF7_version . "' AND CF7_from_wpposts_or_tbl = '" . $CF7_from . "' AND CF7_removed_flag = 'NO' ");
1065
+ $result = $wpdb->get_results($wpdb->prepare("select `CFDBA_tbl_name` from SaveContactForm7_lookup where CF7_form_id = %d AND CF7_created_title = %s AND CF7_version = %s AND CF7_from_wpposts_or_tbl = %s AND CF7_removed_flag = 'NO' ", $CF7_form_id, $CF7_title, $CF7_version, $CF7_from));
1066
  if (!empty($result[0]->CFDBA_tbl_name)) {
1067
  return $result[0]->CFDBA_tbl_name;
1068
  }
1094
  function nimble_lookup_entry($CF7_form_id, $CF7_form_title, $CF7_version, $CF7_from, $form) {
1095
  global $wpdb;
1096
  $sql_lookup_insert = "INSERT INTO SaveContactForm7_lookup (`CF7_created_title`, `CF7_version`, `CF7_form_id`,`CF7_from_wpposts_or_tbl` )
1097
+ SELECT * FROM (SELECT %s, %s, %d, %s) AS tmp
1098
  WHERE NOT EXISTS (
1099
  SELECT CF7_form_id
1100
  FROM SaveContactForm7_lookup
1101
+ WHERE `CF7_version` = %s
1102
+ AND `CF7_form_id` = %d
1103
+ AND `CF7_from_wpposts_or_tbl` = %s
1104
  AND `CF7_removed_flag` = 'NO') LIMIT 1";
1105
 
1106
+ if ($wpdb->query($wpdb->prepare($sql_lookup_insert, $CF7_form_title, $CF7_version, $CF7_form_id, $CF7_from, $CF7_version, $CF7_form_id, $CF7_from))) {
1107
  $table = "SaveContactForm7_" . $wpdb->insert_id;
1108
  } else {
1109
  $table = "";
1110
  }
1111
+ $sql_lookup_update = "UPDATE `SaveContactForm7_lookup` SET `CFDBA_tbl_name` = %s WHERE `lookup_id` = %d ";
1112
+ $wpdb->query($wpdb->prepare($sql_lookup_update, $table, $wpdb->insert_id));
1113
  return $table;
1114
  }
1115