Advanced Contact form 7 DB - Version 1.4.4

Version Description

  • Fixed issue related to export records in PDF.
  • Provided filter for excluding particular contact form entry to the database
  • Provided filter to add, modify, remove CF7 fields and data before submitting to the database.
Download this release

Release Info

Developer vsourz1td
Plugin Icon 128x128 Advanced Contact form 7 DB
Version 1.4.4
Comparing to
See all releases

Code changes from version 1.4.3 to 1.4.4

README.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: vsourz1td
3
  Tags: contact form 7 db, advanced cf7 db, contact form 7 database, contact form db, contact form 7, save form data, save contact form, save cf7, database, cf7db, save-contact-form, Save-Forms-Data, import-cf7, export-contact-data, view-cf7-entry
4
  Requires at least: 4.0
5
- Tested up to: 4.9.7
6
- Stable tag: 1.4.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -20,8 +20,8 @@ Attached files are stored in the /wp-content/uploads/advanced-cf7-upload directo
20
  = Features =
21
  * **Multisite compatible** to store individual site wise contact form data.
22
  * Save Contact Form 7 form submitted data to the database.
 
23
  * Display **all** created contact form 7 form list.
24
- * Select Form name to see the entries.
25
  * Keyword search for all the entries of selected form.
26
  * **Date range filter** to filter specific date related entries easily.
27
  * **Export all**, or only searched, filtered results with selected fields.
@@ -36,15 +36,23 @@ Attached files are stored in the /wp-content/uploads/advanced-cf7-upload directo
36
  * Easy to update each field label name.
37
  * Easy to setup **import functionality.**
38
  * Facility to import form related entries from CSV file.
 
 
39
 
40
- = Restrict IP address storage =
41
- * Some of Countries have introduced a Law to don't store the user's IP addresses into the database, So we had given provision to Restrict IP address storage.
 
42
 
43
- = How to Restrict IP address storage? =
44
- 1. Goto -> wp-content/themes/{active theme folder}/functions.php
45
- 2. Open the functions.php file and place the code **do_shortcode( '[cf7-db-display-ip]' );** at the end of the file.
46
 
47
- == Commercial Features ==
 
 
 
 
 
 
 
48
  We have also introduced new feature "Schedule Report". This add-on is specially for businesses that require daily, weekly or monthly reports for the data that are stored at **Advanced Contact form 7 DB**. **Schedule Report For Advanced CF7 DB** plugin will do the same and send the email as per schedule set(Daily, Monthly, Weekly or Yearly) with report attachment.
49
 
50
  You can download the plugin from <a target="_blank" href="https://codecanyon.net/item/schedule-report-for-advanced-cf7-db/21560647?s_rank=8">here</a>
@@ -57,6 +65,23 @@ You can download the plugin from <a target="_blank" href="https://codecanyon.net
57
  * You can manage the email content by defining TO, FROM and email body content for each scheduling event.
58
  * The added schedule event will be added to WordPress cron schedule and accordingly will be fire at the scheduled time.
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  **Need Support?** <mehul@vsourz.com>
62
 
@@ -109,6 +134,23 @@ Restriction is simple, just code **do_shortcode( '[cf7-db-display-ip]' );** to b
109
  **For Multisite** it should be **do_shortcode( '[cf7-db-display-ip site_id="(your-site-id)"]' );**
110
  - You need to add different shortcode for each site with specific siteId. If you need to restrict for all the sites then just place the shortcode without the parameter.
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  == Screenshots ==
113
 
114
  1. Display form related records.
@@ -120,6 +162,11 @@ Restriction is simple, just code **do_shortcode( '[cf7-db-display-ip]' );** to b
120
 
121
  == Changelog ==
122
 
 
 
 
 
 
123
  = 1.4.3 =
124
  * Fixed issue related to export records in PDF.
125
  * Multisite support for IP restrict.
2
  Contributors: vsourz1td
3
  Tags: contact form 7 db, advanced cf7 db, contact form 7 database, contact form db, contact form 7, save form data, save contact form, save cf7, database, cf7db, save-contact-form, Save-Forms-Data, import-cf7, export-contact-data, view-cf7-entry
4
  Requires at least: 4.0
5
+ Tested up to: 4.9.8
6
+ Stable tag: 1.4.4
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
20
  = Features =
21
  * **Multisite compatible** to store individual site wise contact form data.
22
  * Save Contact Form 7 form submitted data to the database.
23
+ * Easy to update/edit enquiry data.
24
  * Display **all** created contact form 7 form list.
 
25
  * Keyword search for all the entries of selected form.
26
  * **Date range filter** to filter specific date related entries easily.
27
  * **Export all**, or only searched, filtered results with selected fields.
36
  * Easy to update each field label name.
37
  * Easy to setup **import functionality.**
38
  * Facility to import form related entries from CSV file.
39
+ * Provided filters for excluding particular contact form entry to CF7 DB.
40
+ * Provided filter to add,modify,remove CF7 fields and data before submitting to CF7 DB.
41
 
42
+ == Commercial Features ==
43
+ **1. Advanced CF7 DB - GDPR compliant**
44
+ Advanced CF7 DB – GDPR compliant plugin assists website and web-shop owners to comply with European privacy regulations known as GDPR. Advanced CF7 DB – GDPR compliant is an add-on of Advanced Cf7 DB, based on GDPR rules to Export or Erase user’s personal data stored with advanced cf7 DB. For more details you can check the below download link.
45
 
46
+ You can download the plugin from <a target="_blank" href="https://codecanyon.net/item/advanced-cf7-db-gdpr-compliant/22386060">here</a>
 
 
47
 
48
+ = Advanced CF7 DB - GDPR compliant Plugin Features =
49
+ * Compatible with the latest WordPress version 4.9.6 and later for GDPR compliances. Meets with the new regulations for the data to be handled.
50
+ * Individual CF7 form wise settings to show the personal data on user’s request.
51
+ * Erase only the CF7 form personal data, that are required.
52
+ * Site owners can export a ZIP file containing a user’s personal data, including data collected by Advanced CF7 DB plugin.
53
+ * Site owners can erase a user’s personal data, including data collected by Advanced CF7 DB plugin.
54
+
55
+ **2. Schedule Report**
56
  We have also introduced new feature "Schedule Report". This add-on is specially for businesses that require daily, weekly or monthly reports for the data that are stored at **Advanced Contact form 7 DB**. **Schedule Report For Advanced CF7 DB** plugin will do the same and send the email as per schedule set(Daily, Monthly, Weekly or Yearly) with report attachment.
57
 
58
  You can download the plugin from <a target="_blank" href="https://codecanyon.net/item/schedule-report-for-advanced-cf7-db/21560647?s_rank=8">here</a>
65
  * You can manage the email content by defining TO, FROM and email body content for each scheduling event.
66
  * The added schedule event will be added to WordPress cron schedule and accordingly will be fire at the scheduled time.
67
 
68
+ **3. Advanced CF7 DB - User Access Manager**
69
+ Need to provide access to other users? Your, search ends now, this plugin provides access to individual users OR based on user Role and accordingly user can view or edit the contact form DB data. For more details you can check the below download link.
70
+
71
+ You can download the plugin from <a target="_blank" href="https://codecanyon.net/item/advanced-cf7-db-user-access-manager/22058788">here</a>
72
+
73
+ = Advanced CF7 DB - User Access Manager Plugin Features =
74
+ * Provide access of contact form 7 DB to View & Update data to individual users OR based on user Role.
75
+ * Provide access of Single/Multiple forms to single user.
76
+
77
+
78
+ == Plugin Customization ==
79
+ = Restrict IP address storage =
80
+ * Some of Countries have introduced a Law to don't store the user's IP addresses into the database, So we had given provision to Restrict IP address storage.
81
+
82
+ = How to Restrict IP address storage? =
83
+ 1. Goto -> wp-content/themes/{active theme folder}/functions.php
84
+ 2. Open the functions.php file and place the code **do_shortcode( '[cf7-db-display-ip]' );** at the end of the file.
85
 
86
  **Need Support?** <mehul@vsourz.com>
87
 
134
  **For Multisite** it should be **do_shortcode( '[cf7-db-display-ip site_id="(your-site-id)"]' );**
135
  - You need to add different shortcode for each site with specific siteId. If you need to restrict for all the sites then just place the shortcode without the parameter.
136
 
137
+ = How to restrict the plugin from storing form entry to contact form DB? =
138
+ Restriction is simple, just following below steps :
139
+ - Goto -> wp-content/themes/{active theme folder}/functions.php
140
+ - Open the functions.php file and place below code at the end of the file.
141
+ add_filter('vsz_cf7_unwanted_form_data_submission','vsz_restrict_form_data_submission');
142
+ function vsz_restrict_form_data_submission($contact_form_ids){
143
+ $contact_form_ids[] = {your-contact-form-id};
144
+ return $contact_form_ids;
145
+ }
146
+ **For multiple forms**
147
+ add_filter('vsz_cf7_unwanted_form_data_submission','vsz_restrict_form_data_submission');
148
+ function vsz_restrict_form_data_submission($contact_form_ids){
149
+ $contact_form_ids[] = ['{your-contact-form-id}','{your-contact-form-id}'];
150
+ return $contact_form_ids;
151
+ }
152
+
153
+
154
  == Screenshots ==
155
 
156
  1. Display form related records.
162
 
163
  == Changelog ==
164
 
165
+ = 1.4.4 =
166
+ * Fixed issue related to export records in PDF.
167
+ * Provided filter for excluding particular contact form entry to the database
168
+ * Provided filter to add, modify, remove CF7 fields and data before submitting to the database.
169
+
170
  = 1.4.3 =
171
  * Fixed issue related to export records in PDF.
172
  * Multisite support for IP restrict.
admin/class-advanced-cf7-db-admin.php CHANGED
@@ -196,7 +196,12 @@ class Advanced_Cf7_Db_Admin {
196
  $obj_form = vsz_cf7_get_the_form_list($fid);
197
 
198
  //get pre define form fields information
199
- $arr_form_tag = $obj_form[0]->scan_form_tags();
 
 
 
 
 
200
 
201
  /**** This functionality Added because when field settings not define then
202
  Fields display as per form design format*/
@@ -960,6 +965,103 @@ class Advanced_Cf7_Db_Admin {
960
  $role->add_cap('cf7_db_form_view'.$post_id);
961
  $role->add_cap('cf7_db_form_edit_'.$post_id);
962
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
963
  }//close class
964
 
965
  //Generate CSV file here
@@ -1005,6 +1107,7 @@ function vsz_cf7_export_to_excel($fid, $ids_export){
1005
 
1006
  $fid = intval($fid);
1007
  $fields = vsz_cf7_get_db_fields($fid);
 
1008
 
1009
  //Get form id related contact form object
1010
  $obj_form = vsz_cf7_get_the_form_list($fid);
@@ -1088,7 +1191,7 @@ function vsz_cf7_export_to_pdf($fid, $ids_export){
1088
  // require_once(dirname(__FILE__).'/pdfgenerate/mypdf.class.php');
1089
 
1090
  require_once(dirname(__FILE__).'/pdfgenerate/dompdf/autoload.inc.php');
1091
- require_once(dirname(__FILE__).'/pdfgenerate/dompdf/load_font.php');
1092
 
1093
  // $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'UTF-8', false);
1094
 
@@ -1117,6 +1220,7 @@ function vsz_cf7_export_to_pdf($fid, $ids_export){
1117
  width:100%;
1118
  white-space: normal;
1119
  word-wrap: break-word;
 
1120
  }
1121
  td{
1122
  padding:5px;
196
  $obj_form = vsz_cf7_get_the_form_list($fid);
197
 
198
  //get pre define form fields information
199
+ if(isset($obj_form[0])){
200
+ $arr_form_tag = $obj_form[0]->scan_form_tags();
201
+ }
202
+ else{
203
+ $arr_form_tag = array();
204
+ }
205
 
206
  /**** This functionality Added because when field settings not define then
207
  Fields display as per form design format*/
965
  $role->add_cap('cf7_db_form_view'.$post_id);
966
  $role->add_cap('cf7_db_form_edit_'.$post_id);
967
  }
968
+
969
+ // Function to upload file from edit file popup
970
+ function vsz_acf7_db_edit_scr_file_upload(){
971
+
972
+ if(!isset($_POST["fid"]) || empty($_POST["fid"])){
973
+ print 'error';
974
+ exit;
975
+ }
976
+ if(!isset($_POST["rid"]) || empty($_POST["rid"])){
977
+ print 'error';
978
+ exit;
979
+ }
980
+ if(!isset($_POST["field"]) || empty($_POST["field"])){
981
+ print 'error';
982
+ exit;
983
+ }
984
+
985
+ global $wpdb;
986
+ $fid = $_POST["fid"];
987
+ $rid = $_POST["rid"];
988
+ $field = $_POST["field"];
989
+
990
+ $upload_dir = wp_upload_dir();
991
+ $acf7db_upload_folder = VSZ_CF7_UPLOAD_FOLDER;
992
+ $temp_dir_upload = $upload_dir['basedir'].'/'.$acf7db_upload_folder;
993
+ wp_mkdir_p($temp_dir_upload);
994
+
995
+ if(is_array($_FILES) && !empty($_FILES)){
996
+ $maxsize = 8000000;
997
+ if(($_FILES['image']['size'] >= $maxsize)) {
998
+ echo 'invalid_size';
999
+ exit;
1000
+ }
1001
+ $filename = sanitize_text_field($_FILES["image"]["name"]);
1002
+ $file_basename = substr($filename, 0, strripos($filename, '.')); // get file name
1003
+ $file_ext = substr($filename, strripos($filename, '.')); // get file extention
1004
+ //unique file name
1005
+ $newfilename = wp_unique_filename($temp_dir_upload, $file_basename.$file_ext);
1006
+
1007
+ if(move_uploaded_file($_FILES["image"]["tmp_name"], $temp_dir_upload. '/' .$newfilename)){
1008
+ $file_url = $upload_dir['baseurl'] . '/' . $acf7db_upload_folder.'/'.$newfilename;
1009
+
1010
+ $res = $wpdb->update(VSZ_CF7_DATA_ENTRY_TABLE_NAME, array("value" => $file_url), array("data_id" => $rid, "cf7_id" => $fid, "name" => $field));
1011
+ if($res !== false){
1012
+ echo "$newfilename~~@@~~&&~~$file_url";
1013
+ wp_die();
1014
+ }
1015
+ else{
1016
+ echo "n";
1017
+ wp_die();
1018
+ }
1019
+ }
1020
+ }
1021
+ wp_die();
1022
+ }
1023
+
1024
+ // Function to delete file from edit file popup
1025
+ function vsz_acf7_db_edit_scr_file_delete(){
1026
+
1027
+ if(!isset($_POST["fid"]) || empty($_POST["fid"])){
1028
+ print 'error';
1029
+ exit;
1030
+ }
1031
+ if(!isset($_POST["rid"]) || empty($_POST["rid"])){
1032
+ print 'error';
1033
+ exit;
1034
+ }
1035
+ if(!isset($_POST["field"]) || empty($_POST["field"])){
1036
+ print 'error';
1037
+ exit;
1038
+ }
1039
+ if(!isset($_POST["val"]) || empty($_POST["val"])){
1040
+ print 'error';
1041
+ exit;
1042
+ }
1043
+
1044
+ $fid = $_POST["fid"];
1045
+ $rid = $_POST["rid"];
1046
+ $field = $_POST["field"];
1047
+ $val = $_POST["val"];
1048
+ global $wpdb;
1049
+
1050
+ $res = $wpdb->update(VSZ_CF7_DATA_ENTRY_TABLE_NAME, array("value" => ""), array("data_id" => $rid, "cf7_id" => $fid, "name" => $field));
1051
+ if($res !== false){
1052
+ $upload_dir = wp_upload_dir();
1053
+ $dir_upload = $upload_dir['basedir'] .'/' .VSZ_CF7_UPLOAD_FOLDER;
1054
+
1055
+ unlink($dir_upload.'/'.$val);
1056
+ echo "y";
1057
+ wp_die();
1058
+ }
1059
+ else{
1060
+ echo "n";
1061
+ wp_die();
1062
+ }
1063
+ }
1064
+
1065
  }//close class
1066
 
1067
  //Generate CSV file here
1107
 
1108
  $fid = intval($fid);
1109
  $fields = vsz_cf7_get_db_fields($fid);
1110
+ $fields1 = vsz_field_type_info($fid);
1111
 
1112
  //Get form id related contact form object
1113
  $obj_form = vsz_cf7_get_the_form_list($fid);
1191
  // require_once(dirname(__FILE__).'/pdfgenerate/mypdf.class.php');
1192
 
1193
  require_once(dirname(__FILE__).'/pdfgenerate/dompdf/autoload.inc.php');
1194
+ //require_once(dirname(__FILE__).'/pdfgenerate/dompdf/load_font.php');
1195
 
1196
  // $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'UTF-8', false);
1197
 
1220
  width:100%;
1221
  white-space: normal;
1222
  word-wrap: break-word;
1223
+ font-family: DroidSansFallback;
1224
  }
1225
  td{
1226
  padding:5px;
admin/js/advanced-cf7-db-admin.js CHANGED
@@ -198,6 +198,9 @@ jQuery(document).ready(function($) {
198
  //Remove previous define anchor tag in edit form
199
  if(jQuery('form#cf7d-modal-form-edit-value input[class^="field-'+fieldname+'"]').parent().find('a')){
200
  jQuery('form#cf7d-modal-form-edit-value input[class^="field-'+fieldname+'"]').parent().find('a').remove();
 
 
 
201
  }
202
  jQuery('form#cf7d-modal-form-edit-value input[class^="field-'+fieldname+'"]').attr('value', 'Loading...');
203
  }
@@ -250,10 +253,16 @@ jQuery(document).ready(function($) {
250
  //Set file field related functionality here
251
  else if(arr_field_type[index]['basetype'] == 'file'){
252
  if(el){
253
- var filename = el.split('/').pop()
 
254
  jQuery('form#cf7d-modal-form-edit-value .field-' + index).attr('value', filename);
255
  jQuery('form#cf7d-modal-form-edit-value .field-' + index).css("border","");
256
  jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().append('<a class="margin_left" href="'+el+'" target="_blank" download >Download</a>');
 
 
 
 
 
257
  }
258
  }
259
  //Check field type is text then execute this code
@@ -347,6 +356,188 @@ function validateEmail(email) {
347
  return expr.test(email);
348
  };
349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
 
351
  /**************** Check fields key related match key value empty or not *************************/
352
  jQuery(document).ready(function() {
198
  //Remove previous define anchor tag in edit form
199
  if(jQuery('form#cf7d-modal-form-edit-value input[class^="field-'+fieldname+'"]').parent().find('a')){
200
  jQuery('form#cf7d-modal-form-edit-value input[class^="field-'+fieldname+'"]').parent().find('a').remove();
201
+ jQuery('form#cf7d-modal-form-edit-value input[class^="field-'+fieldname+'"]').parent().find('.vsz_cf7_db_file_edit').remove();
202
+ jQuery('form#cf7d-modal-form-edit-value input[class^="field-'+fieldname+'"]').parent().find('.edit-field-file-val').remove();
203
+ jQuery('form#cf7d-modal-form-edit-value input[class^="field-'+fieldname+'"]').parent().find('span.margin_left').remove();
204
  }
205
  jQuery('form#cf7d-modal-form-edit-value input[class^="field-'+fieldname+'"]').attr('value', 'Loading...');
206
  }
253
  //Set file field related functionality here
254
  else if(arr_field_type[index]['basetype'] == 'file'){
255
  if(el){
256
+ var filename = el.split('/').pop();
257
+ // var filename = el;
258
  jQuery('form#cf7d-modal-form-edit-value .field-' + index).attr('value', filename);
259
  jQuery('form#cf7d-modal-form-edit-value .field-' + index).css("border","");
260
  jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().append('<a class="margin_left" href="'+el+'" target="_blank" download >Download</a>');
261
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().append('<a value="Change" class="vsz_cf7_db_file_edit" style="margin-left: 10px;" href="javascript:void(0);" >Remove</a>');
262
+ add_remove_file(index, filename);
263
+ }
264
+ else{
265
+ add_remove_file(index, "");
266
  }
267
  }
268
  //Check field type is text then execute this code
356
  return expr.test(email);
357
  };
358
 
359
+ // Define add remove file for edit section
360
+ function add_remove_file(index,filename){
361
+
362
+ if(filename != ""){
363
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).show();
364
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().find(".vsz_cf7_db_file_edit").each(function(){
365
+ jQuery(this).click(function(){
366
+ if(confirm("Are you sure to remove the file? File will be deleted permanently and could not be retrieved.")){
367
+
368
+ var fid = jQuery("input[name='fid']").val();
369
+ var rid = jQuery("input[name='rid']").val();
370
+ var field = index;
371
+
372
+ var fd = new FormData();
373
+ fd.append( "fid", fid);
374
+ fd.append( "rid", rid);
375
+ fd.append( "field", field);
376
+ fd.append( "val", filename);
377
+ fd.append( "action", "acf7_db_edit_scr_file_delete");
378
+
379
+ jQuery.ajax({
380
+ url: ajaxurl,
381
+ type: 'POST',
382
+ data : fd,
383
+ processData: false,
384
+ contentType: false,
385
+ beforeSend: function() {
386
+ document.getElementById('overlayLoader').style.display = "block";
387
+ },
388
+ success: function(data) {
389
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().prepend('<input type="file" name="field['+index+']" class="field-'+index+'-val edit-field-file-val" />');
390
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().find('a').remove();
391
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().append('<span class="margin_left">Maximum file size allowed : 7.60 MB.</span><span class="margin_left" style="display: block;">It is possible that server has limit less than 7.60 MB, in that case it can terminate the request. It is advisable to keep upload file size as minimum as possible.</span>');
392
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).hide();
393
+
394
+ document.getElementById('overlayLoader').style.display = "none";
395
+
396
+ jQuery(".field-"+index+"-val").change(function(){
397
+ var thisdata = jQuery(this);
398
+ var fileName = jQuery(thisdata).val();
399
+ var checkvalidate = 1;
400
+
401
+ if(fileName != "" && fileName != undefined){
402
+ var fd = new FormData();
403
+ var fid = jQuery("input[name='fid']").val();
404
+ var rid = jQuery("input[name='rid']").val();
405
+ var field = index;
406
+
407
+ fd.append( "image", jQuery(thisdata)[0].files[0]);
408
+ fd.append( "action", "acf7_db_edit_scr_file_upload");
409
+ fd.append( "fid", fid);
410
+ fd.append( "rid", rid);
411
+ fd.append( "field", field);
412
+
413
+ jQuery.ajax({
414
+ url: ajaxurl,
415
+ type: 'POST',
416
+ data : fd,
417
+ processData: false,
418
+ contentType: false,
419
+ beforeSend: function() {
420
+ document.getElementById('overlayLoader').style.display = "block";
421
+ },
422
+
423
+ success: function(data) {
424
+ if(data != "invalid_size"){
425
+ dataArr = data.split("~~@@~~&&~~");
426
+
427
+ var filename = dataArr[0];
428
+ var el = dataArr[1];
429
+
430
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).attr('value', filename);
431
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).css("border","");
432
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().append('<a class="margin_left" href="'+el+'" target="_blank" download >Download</a>');
433
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().append('<a value="Change" class="vsz_cf7_db_file_edit" style="margin-left: 10px;" href="javascript:void(0);" >Remove</a>');
434
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).show();
435
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().find('.field-'+index+'-val').remove();
436
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().find('span.margin_left').remove();
437
+
438
+ // Calling function which will handle the removal and new upload of the files
439
+ add_remove_file(index,filename);
440
+ }
441
+ else{
442
+ alert("Maximum file size allowed is 7.60 MB.");
443
+ }
444
+
445
+ document.getElementById('overlayLoader').style.display = "none";
446
+ },
447
+
448
+ error: function(data) {
449
+ console.log(data);
450
+ document.getElementById('overlayLoader').style.display = "none";
451
+ alert("Sorry file was not uploaded.");
452
+ return false;
453
+ },
454
+ });
455
+ }
456
+ });
457
+ },
458
+ error: function(data) {
459
+ console.log(data);
460
+ document.getElementById('overlayLoader').style.display = "none";
461
+ alert("Sorry file was not removed.");
462
+ return false;
463
+ },
464
+ });
465
+
466
+ }
467
+ });
468
+ });
469
+ }
470
+ else{
471
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().prepend('<input type="file" name="field['+index+']" class="field-'+index+'-val edit-field-file-val" />');
472
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().find('a').remove();
473
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().append('<span class="margin_left">Maximum file size allowed : 7.60 MB.</span><span class="margin_left" style="display: block;">It is possible that server has limit less than 7.60 MB, in that case it can terminate the request. It is advisable to keep upload file size as minimum as possible.</span>');
474
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).hide();
475
+
476
+ document.getElementById('overlayLoader').style.display = "none";
477
+
478
+ jQuery(".field-"+index+"-val").change(function(){
479
+ var thisdata = jQuery(this);
480
+ var fileName = jQuery(thisdata).val();
481
+ var checkvalidate = 1;
482
+
483
+ if(fileName != "" && fileName != undefined){
484
+ var fd = new FormData();
485
+ var fid = jQuery("input[name='fid']").val();
486
+ var rid = jQuery("input[name='rid']").val();
487
+ var field = index;
488
+
489
+ fd.append( "image", jQuery(thisdata)[0].files[0]);
490
+ fd.append( "action", "acf7_db_edit_scr_file_upload");
491
+ fd.append( "fid", fid);
492
+ fd.append( "rid", rid);
493
+ fd.append( "field", field);
494
+
495
+ jQuery.ajax({
496
+ url: ajaxurl,
497
+ type: 'POST',
498
+ data : fd,
499
+ processData: false,
500
+ contentType: false,
501
+ beforeSend: function() {
502
+ document.getElementById('overlayLoader').style.display = "block";
503
+ },
504
+
505
+ success: function(data) {
506
+ if(data != "invalid_size"){
507
+ dataArr = data.split("~~@@~~&&~~");
508
+
509
+ var filename = dataArr[0];
510
+ var el = dataArr[1];
511
+
512
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).attr('value', filename);
513
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).css("border","");
514
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().append('<a class="margin_left" href="'+el+'" target="_blank" download >Download</a>');
515
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().append('<a value="Change" class="vsz_cf7_db_file_edit" style="margin-left: 10px;" href="javascript:void(0);" >Remove</a>');
516
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).show();
517
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().find('.field-'+index+'-val').remove();
518
+ jQuery('form#cf7d-modal-form-edit-value .field-' + index).parent().find('span.margin_left').remove();
519
+
520
+ // Calling function which will handle the removal and new upload of the files
521
+ add_remove_file(index,filename);
522
+ }
523
+ else{
524
+ alert("Maximum file size allowed is 7.60 MB.");
525
+ }
526
+
527
+ document.getElementById('overlayLoader').style.display = "none";
528
+ },
529
+
530
+ error: function(data) {
531
+ console.log(data);
532
+ document.getElementById('overlayLoader').style.display = "none";
533
+ alert("Sorry file was not uploaded.");
534
+ return false;
535
+ },
536
+ });
537
+ }
538
+ });
539
+ }
540
+ }
541
 
542
  /**************** Check fields key related match key value empty or not *************************/
543
  jQuery(document).ready(function() {
advanced-cf7-db.php CHANGED
@@ -9,7 +9,7 @@
9
  * Plugin Name: Advanced CF7 DB
10
  * Plugin URI: https://wordpress.org/plugins/advanced-cf7-db/
11
  * Description: Save all contact form 7 submitted data to the database, View, Export, ordering, Change field labels, Import data using CSV very easily.
12
- * Version: 1.4.3
13
  * Author: Vsourz Digital
14
  * Author URI: https://www.vsourz.com
15
  * License: GPL-2.0+
@@ -23,7 +23,7 @@ if ( ! defined( 'WPINC' ) ) {
23
  die;
24
  }
25
  global $vsz_cf7db_current_version;
26
- $vsz_cf7db_current_version = '1.4.3';
27
  /**
28
  * Defining all the table names and setting their prefix here
29
  */
9
  * Plugin Name: Advanced CF7 DB
10
  * Plugin URI: https://wordpress.org/plugins/advanced-cf7-db/
11
  * Description: Save all contact form 7 submitted data to the database, View, Export, ordering, Change field labels, Import data using CSV very easily.
12
+ * Version: 1.4.4
13
  * Author: Vsourz Digital
14
  * Author URI: https://www.vsourz.com
15
  * License: GPL-2.0+
23
  die;
24
  }
25
  global $vsz_cf7db_current_version;
26
+ $vsz_cf7db_current_version = '1.4.4';
27
  /**
28
  * Defining all the table names and setting their prefix here
29
  */
includes/class-advanced-cf7-db.php CHANGED
@@ -210,7 +210,11 @@ class Advanced_Cf7_Db {
210
  // Provide custom capability
211
  $this->loader->add_action('save_post',$plugin_admin,'vsz_cf7_create_role_for_contact_form');
212
 
 
 
213
 
 
 
214
  }
215
 
216
  /**
210
  // Provide custom capability
211
  $this->loader->add_action('save_post',$plugin_admin,'vsz_cf7_create_role_for_contact_form');
212
 
213
+ // Edit Popup file upload
214
+ $this->loader->add_action('wp_ajax_acf7_db_edit_scr_file_upload',$plugin_admin,'vsz_acf7_db_edit_scr_file_upload');
215
 
216
+ // Edit Popup file delete
217
+ $this->loader->add_action('wp_ajax_acf7_db_edit_scr_file_delete',$plugin_admin,'vsz_acf7_db_edit_scr_file_delete');
218
  }
219
 
220
  /**
includes/vsz-cf7-db-function.php CHANGED
@@ -1,408 +1,439 @@
1
- <?php
2
- // Exit if accessed directly
3
- if ( !defined( 'ABSPATH' ) ){
4
- die('Un-authorized access!');
5
- }
6
-
7
-
8
- //Define contact form action which is call before mail is trigger
9
- add_action('wpcf7_before_send_mail','vsz_cf7_before_send_email');
10
- //Call this function when mail is trigger then get all form fields related information
11
- function vsz_cf7_before_send_email($contact_form){
12
- global $wpdb;
13
-
14
- //Define this action for customize form data before insert in DB
15
- do_action('vsz_cf7_before_insert_db', $contact_form);
16
-
17
- //Get submitted contact form id
18
- $cf7_id = $contact_form->id();
19
- $contact_form = vsz_cf7_get_posted_data($contact_form);
20
-
21
- //for database installion
22
- $contact_form = vsz_cf7_add_extra_fields($contact_form);
23
-
24
- //Modify $contact_form
25
- $contact_form = apply_filters('vsz_cf7_modify_form_before_insert_data', $contact_form);
26
-
27
- //Type's $contact_form->posted_data is array
28
- // Define filter for customize posted data
29
-
30
- $contact_form->posted_data = apply_filters('vsz_cf7_posted_data', $contact_form->posted_data);
31
-
32
- //Insert current form submission time in database
33
- $time = date('Y-m-d H:i:s');
34
- $wpdb->query($wpdb->prepare('INSERT INTO '.VSZ_CF7_DATA_TABLE_NAME.'(`created`) VALUES (%s)', $time));
35
- //Get last inserted id
36
- $data_id = $wpdb->insert_id;
37
-
38
- //Insert form values in custom data entry table
39
- if(!empty($cf7_id) && !empty($data_id)){
40
- //Get not inserted fields value list
41
- $cf7d_no_save_fields = vsz_cf7_no_save_fields();
42
- foreach ($contact_form->posted_data as $k => $v) {
43
- //Check not inserted fields name in array or not
44
- if(in_array($k, $cf7d_no_save_fields)) {
45
- continue;
46
- }
47
- else{
48
- //If value is check box and radio button value then creaye single string
49
- if(is_array($v)){
50
- $v = implode("\n", $v);
51
- }
52
- $k = htmlspecialchars($k);
53
- $v = htmlspecialchars($v);
54
- $wpdb->query($wpdb->prepare('INSERT INTO '.VSZ_CF7_DATA_ENTRY_TABLE_NAME.'(`cf7_id`, `data_id`, `name`, `value`) VALUES (%d,%d,%s,%s)', $cf7_id, $data_id, $k, $v));
55
- }
56
- }
57
- //Add action for customize process after insert value in data base
58
- do_action('vsz_cf7_after_insert_db', $contact_form, $cf7_id, $data_id);
59
- }
60
-
61
- }
62
-
63
- /*
64
- * Support CF7 functions
65
- */
66
- function vsz_cf7_get_posted_data($cf7){
67
-
68
- if (!isset($cf7->posted_data) && class_exists('WPCF7_Submission')) {
69
- // Contact Form 7 version 3.9 removed $cf7->posted_data and now
70
- // we have to retrieve it from an API
71
- $submission = WPCF7_Submission::get_instance();
72
- if ($submission){
73
- $data = array();
74
- $data['title'] = $cf7->title();
75
- $data['posted_data'] = $submission->get_posted_data();
76
- $data['uploaded_files'] = $submission->uploaded_files();
77
- $data['WPCF7_ContactForm'] = $cf7;
78
- $cf7 = (object) $data;
79
- }
80
- }
81
- return $cf7;
82
- }
83
-
84
- /*
85
- * Add additional value with form data
86
- */
87
- function vsz_cf7_add_extra_fields($cf7){
88
-
89
- $submission = WPCF7_Submission::get_instance();
90
-
91
- //Get time stamp value in valid date format
92
- $cf7->posted_data['submit_time'] = date_i18n('Y-m-d H:i:s', $submission->get_meta('timestamp'));
93
-
94
- if(!defined('vsz_cf7_display_ip')){
95
- //Get submitted ip address
96
- $cf7->posted_data['submit_ip'] = (isset($_SERVER['X_FORWARDED_FOR'])) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
97
- }
98
- return $cf7;
99
- }
100
-
101
- //save files uploaded by user and modify data before inserting to database
102
- add_filter('vsz_cf7_modify_form_before_insert_data', 'vsz_cf7_modify_form_before_insert_in_cf7_vdata_entry');
103
- if (!function_exists('vsz_cf7_modify_form_before_insert_in_cf7_vdata_entry')) {
104
- function vsz_cf7_modify_form_before_insert_in_cf7_vdata_entry($cf7){
105
- //if it has at lest 1 file uploaded
106
- if (count($cf7->uploaded_files) > 0) {
107
- //Get upload dir URL
108
- $upload_dir = wp_upload_dir();
109
- //Create custom upload folder
110
- $cf7d_upload_folder = VSZ_CF7_UPLOAD_FOLDER;
111
- $dir_upload = $upload_dir['basedir'] . '/' . $cf7d_upload_folder;
112
- wp_mkdir_p($dir_upload);
113
- //Get all uploaded files information
114
- foreach ($cf7->uploaded_files as $k => $v) {
115
- //Get file name
116
- $file_name = basename($v);
117
- //Create unique file name
118
- $file_name = wp_unique_filename($dir_upload, $file_name);
119
- //Setup filoe path
120
- $dst_file = $dir_upload . '/' . $file_name;
121
- //Copy file information in destination variable
122
- if (@copy($v, $dst_file)){
123
- //Setup customize file information in array
124
- $cf7->posted_data[$k] = $upload_dir['baseurl'] . '/' . $cf7d_upload_folder . '/' . $file_name;
125
- }
126
- }//Close foreach
127
- }//Close if
128
- return $cf7;
129
- }//Close function
130
- }//Close if for check function exist or not
131
-
132
- //Define function for which field value not insert in table
133
- function vsz_cf7_no_save_fields(){
134
- $cf7d_no_save_fields = array('_wpcf7', '_wpcf7_version', '_wpcf7_locale', '_wpcf7_unit_tag', '_wpcf7_is_ajax_call','_wpcf7_container_post');
135
- //Add filter for customize values
136
- return apply_filters('vsz_cf7_no_save_fields', $cf7d_no_save_fields);
137
- }//Close function
138
-
139
- //Get all contact form list here
140
- function vsz_cf7_get_the_form_list($fid = ''){
141
-
142
- //Get All form information
143
- $forms = WPCF7_ContactForm::find();
144
- $form = array();
145
- //fetch each form information
146
- foreach ($forms as $k => $v){
147
- //Check if form id not empty then get specific form related information
148
- if(!empty($fid)){
149
- if($v->id() === $fid){
150
- $form[] = $v;
151
- return $form;
152
- }
153
- }
154
- else{
155
- $form[] = $v;
156
- }
157
- }
158
- return $form;
159
- }//Close function
160
-
161
- /*
162
- * $data: rows from database
163
- * $fid: form id
164
- */
165
- function vsz_cf7_sortdata($data){
166
- $data_sorted = array();
167
- //Set submitted id wise form information
168
- foreach ($data as $k => $v) {
169
- if(!isset($data_sorted[$v->data_id])){
170
- $data_sorted[$v->data_id] = array();
171
- }
172
- $data_sorted[$v->data_id][$v->name] = apply_filters('cf7d_entry_value', trim(wp_unslash($v->value)), $v->name);
173
- }
174
-
175
- return $data_sorted;
176
- }
177
-
178
- //Get form id related fields information from DB
179
- function vsz_cf7_get_db_fields($fid, $filter = true){
180
- global $wpdb;
181
- $fid = (int)$fid;
182
- $sql = "SELECT `name` FROM `".VSZ_CF7_DATA_ENTRY_TABLE_NAME."` WHERE cf7_id = ".$fid." GROUP BY `name`";
183
- $data = $wpdb->get_results($sql);
184
-
185
- //Set each field value in array
186
- $fields = array();
187
- if(!empty($data)){
188
-
189
- foreach ($data as $k => $v) {
190
- if(defined('vsz_cf7_display_ip')){
191
- if($v->name != 'submit_ip'){
192
- $fields[$v->name] = htmlspecialchars_decode($v->name);
193
- }
194
- }
195
- else{
196
- $fields[$v->name] = htmlspecialchars_decode($v->name);
197
- }
198
- }
199
- }
200
-
201
- //Check if filter is true or not
202
- if ($filter) {
203
- //Get all fields information as per Setting screen
204
- $fields = apply_filters('vsz_cf7_admin_fields', $fields, $fid);
205
- }
206
-
207
- return $fields;
208
- }//Close function
209
-
210
- //Add option value in specific select box request
211
- if(!function_exists('vsz_cf7_arr_to_option')){
212
- function vsz_cf7_arr_to_option($arr){
213
- $html = '';
214
- if(!empty($arr) && is_array($arr)){
215
- foreach($arr as $k => $v) {
216
- $html .= '<option value="'.esc_html($k).'">'.esc_html($v).'</option>';
217
- }
218
- }
219
- return $html;
220
- }
221
- }
222
-
223
- //get speicfic fields related information
224
- function vsz_cf7_admin_get_field_name($field){
225
- return esc_html($field);
226
- }
227
-
228
- //Get form id and specific entry related keys information
229
- function get_entry_related_fields_info($fid,$entryId){
230
- $fields = array();
231
- if(!empty($fid) && !empty($entryId)){
232
-
233
- global $wpdb;
234
- $fid = intval($fid);
235
- $entryId = intval($entryId);
236
-
237
- $sql = "SELECT `name` FROM `".VSZ_CF7_DATA_ENTRY_TABLE_NAME."` WHERE `cf7_id` = ".$fid." AND `data_id` = ".$entryId." GROUP BY `name`";
238
- $data = $wpdb->get_results($sql);
239
- if(!empty($data)){
240
- foreach ($data as $k => $v) {
241
- $fields[$v->name] = htmlspecialchars_decode($v->name);
242
- }
243
- }
244
- }
245
- return $fields;
246
- }
247
-
248
- //Check current action
249
- function vsz_cf7_current_action(){
250
-
251
- $current_action = false;
252
- if (isset($_POST['action']) && -1 != $_POST['action'] && isset($_POST['btn_apply'])) {
253
- $current_action = sanitize_text_field($_POST['action']);
254
- return apply_filters('vsz_cf7_get_current_action', $current_action);
255
- }
256
-
257
- if (isset($_POST['action2']) && -1 != $_POST['action2'] && isset($_POST['btn_apply2'])) {
258
- $current_action = sanitize_text_field($_POST['action2']);
259
- return apply_filters('vsz_cf7_get_current_action', $current_action);
260
- }
261
- $current_action = apply_filters('vsz_cf7_get_current_action', $current_action);
262
- return false;
263
- }
264
-
265
-
266
- //Display field type related values here
267
- function vsz_display_field_type_value($type,$arr_field_type,$k,$v){
268
- $type = esc_html($type);
269
- $k = esc_html($k);
270
- if($type == 'checkbox'){
271
-
272
- if(is_array($v)){
273
- $label = esc_html($v['label']);
274
- }
275
- else{
276
- $label = esc_html($v);
277
- }
278
- $loading = __('Loading...');
279
- echo "<li class=\"clearfix\">
280
- <span class=\"label\">".$label." (".$type.")</span>
281
- <textarea name=\"field[".$k."]\" rows=\"3\" cols=\"20\" class=\"field-".$k."\" >".$loading."</textarea>
282
- <span class=\"margin_left\">(Multiple entry start from new line)</span>
283
- <div class=\"clear\"></div>
284
- </li>";
285
- }
286
- else if($type == 'radio'){
287
-
288
- if(is_array($v)){
289
- $label = esc_html($v['label']);
290
- }
291
- else{
292
- $label = esc_html($v);
293
- }
294
- $loading = __('Loading...');
295
- echo "<li class=\"clearfix\">
296
- <span class=\"label\">".$label." (".$type.")</span>
297
- <textarea name=\"field[".$k."]\" rows=\"3\" cols=\"20\" class=\"field-".$k."\" >".$loading."</textarea><div class=\"clear\"></div></li>";
298
- }
299
- else if($type == 'select'){
300
- if(is_array($v)){
301
- $label = esc_html($v['label']);
302
- }
303
- else{
304
- $label = esc_html($v);
305
- }
306
- $loading = __('Loading...');
307
- echo "<li class=\"clearfix\">
308
- <span class=\"label\">".$label." (".$type.")</span>
309
- <textarea name=\"field[".$k."]\" rows=\"3\" cols=\"20\" class=\"field-".$k."\" >".$loading."</textarea><div class=\"clear\"></div></li>";
310
- }
311
- else if($type == 'textarea'){
312
- if(is_array($v)){
313
- $label = esc_html($v['label']);
314
- }
315
- else{
316
- $label = esc_html($v);
317
- }
318
- $loading = __('Loading...');
319
- echo "<li class=\"clearfix\">
320
- <span class=\"label\">".$label."</span>
321
- <textarea name=\"field[".$k."]\" rows=\"3\" cols=\"20\" class=\"field-".$k."\" >".$loading."</textarea><div class=\"clear\"></div></li>";
322
- }
323
- else if($type == 'file'){
324
- if(is_array($v)){
325
- $label = esc_html($v['label']);
326
- }
327
- else{
328
- $label = esc_html($v);
329
- }
330
- $loading = __('Loading...');
331
- $disable = 'readonly';
332
- echo "<li class=\"clearfix\">
333
- <span class=\"label\">".$label."</span>
334
- <input class=\"field-".$k."\" type=\"text\" name=\"field[".$k."]\" value=\"".$loading."\" ".$disable." /><div class=\"clear\"></div></li>";
335
- }else if($type == 'tel'){
336
-
337
- if(is_array($v)){
338
- $label = esc_html($v['label']);
339
- }
340
- else{
341
- $label = esc_html($v);
342
- }
343
- $loading = __('Loading...');
344
- echo "<li class=\"clearfix\">
345
- <span class=\"label\">".$label."</span>
346
- <input class=\"field-".$k."\" type=\"text\" name=\"field[".$k."]\" value=\"".$loading."\" /><div class=\"clear\"></div></li>";
347
- }else if($type == 'dynamictext'|| $type == 'dynamichidden'|| $type == 'url' || $type == 'number' || $type == 'date' || $type == 'acceptance' || $type == 'quiz'){
348
- if(is_array($v)){
349
- $label = esc_html($v['label']);
350
- }
351
- else{
352
- $label = esc_html($v);
353
- }
354
- $loading = __('Loading...');
355
- echo "<li class=\"clearfix\">
356
- <span class=\"label\">".$label."</span>
357
- <input class=\"field-".$k."\" type=\"text\" name=\"field[".$k."]\" value=\"".$loading."\" /><div class=\"clear\"></div></li>";
358
- }else{
359
- if(is_array($v)){
360
- $label = esc_html($v['label']);
361
- }
362
- else{
363
- $label = esc_html($v);
364
- }
365
- $loading = __('Loading...');
366
- echo "<li class=\"clearfix\">
367
- <span class=\"label\">".$label."</span>
368
- <textarea name=\"field[".$k."]\" rows=\"3\" cols=\"20\" class=\"field-".$k."\" >".$loading."</textarea><div class=\"clear\"></div></li>";
369
- }
370
-
371
- }
372
-
373
- //Define sheet related date formates
374
- function vsz_cf7_import_date_format_callback(){
375
-
376
- $arr_dates = array('Y-m-d H:i:s P' => date('Y-m-d H:i:s P'),
377
- 'Y-m-d' => date('Y-m-d'),
378
- 'Y/m/d' => date('Y/m/d'),
379
- 'jS F, Y' => date('jS F, Y'),
380
- 'F j, Y' => date('F j, Y'),
381
- 'd/m/Y' => date('d/m/Y'),
382
- 'd-m-Y' => date('d-m-Y')
383
- );
384
- return $arr_dates;
385
- }
386
-
387
- //Get field name related type information
388
- function vsz_field_type_info($fid){
389
-
390
- if(empty($fid) || !intval($fid)) return ;
391
-
392
- $fid = intval($fid);
393
- $obj_form = vsz_cf7_get_the_form_list($fid);
394
- //get pre define fields information
395
- $arr_form_tag = $obj_form[0]->scan_form_tags();
396
- $arr_field_type = array();
397
- if(!empty($arr_form_tag)){
398
- //Get all fields related information
399
- foreach($arr_form_tag as $key => $arr_type){
400
- //Check if tag type is submit then ignore tag info
401
- if($arr_type['basetype'] == 'submit') continue;
402
- //get field type information
403
- $arr_field_type[$arr_type['name']] = $arr_type['basetype'];
404
- }
405
- }
406
-
407
- return $arr_field_type;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
  }
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ){
4
+ die('Un-authorized access!');
5
+ }
6
+
7
+
8
+ //Define contact form action which is call before mail is trigger
9
+ add_action('wpcf7_before_send_mail','vsz_cf7_before_send_email');
10
+ //Call this function when mail is trigger then get all form fields related information
11
+ function vsz_cf7_before_send_email($contact_form){
12
+ global $wpdb;
13
+ $contact_form_ids = array();
14
+ //Define this action for customize form data before insert in DB
15
+ do_action('vsz_cf7_before_insert_db', $contact_form);
16
+
17
+ //Get submitted contact form id
18
+ $cf7_id = $contact_form->id();
19
+
20
+ /*
21
+ * Restriction of the whole form submission to the database
22
+ * Filter provided to get all the un-necessary form data to be submitted
23
+ */
24
+
25
+ $arr_contact_form_ids = (array) apply_filters('vsz_cf7_unwanted_form_data_submission', $contact_form_ids);
26
+
27
+ if(!empty($arr_contact_form_ids) && is_array($arr_contact_form_ids) && in_array($cf7_id, $arr_contact_form_ids)) return;
28
+
29
+ $contact_form = vsz_cf7_get_posted_data($contact_form);
30
+
31
+ //for database installion
32
+ $contact_form = vsz_cf7_add_extra_fields($contact_form);
33
+
34
+ $contact_form = apply_filters('vsz_cf7_modify_form_before_insert_data', $contact_form);
35
+
36
+ //Type's $contact_form->posted_data is array
37
+ // Define filter for customize posted data
38
+ /* Below filter will be provided to the Users to modify the data
39
+ * Below is the process that can be performed
40
+ * 1) Add new data to the CF7 Form
41
+ * 2) Can modify the existing form submitted data
42
+ * 3) Can unset or remove the existing form data of CF7
43
+ *
44
+ */
45
+
46
+ $contact_form->posted_data = apply_filters('vsz_cf7_posted_data', $contact_form->posted_data);
47
+
48
+ //Insert current form submission time in database
49
+ $time = date('Y-m-d H:i:s');
50
+ $wpdb->query($wpdb->prepare('INSERT INTO '.VSZ_CF7_DATA_TABLE_NAME.'(`created`) VALUES (%s)', $time));
51
+ //Get last inserted id
52
+ $data_id = $wpdb->insert_id;
53
+
54
+ //Insert form values in custom data entry table
55
+ if(!empty($cf7_id) && !empty($data_id)){
56
+ //Get not inserted fields value list
57
+ $cf7d_no_save_fields = vsz_cf7_no_save_fields();
58
+ foreach ($contact_form->posted_data as $k => $v) {
59
+ //Check not inserted fields name in array or not
60
+ if(in_array($k, $cf7d_no_save_fields)) {
61
+ continue;
62
+ }
63
+ else{
64
+ //If value is check box and radio button value then creaye single string
65
+ if(is_array($v)){
66
+ $v = implode("\n", $v);
67
+ }
68
+ $k = htmlspecialchars($k);
69
+ $v = htmlspecialchars($v);
70
+ $wpdb->query($wpdb->prepare('INSERT INTO '.VSZ_CF7_DATA_ENTRY_TABLE_NAME.'(`cf7_id`, `data_id`, `name`, `value`) VALUES (%d,%d,%s,%s)', $cf7_id, $data_id, $k, $v));
71
+ }
72
+ }
73
+ //Add action for customize process after insert value in data base
74
+ do_action('vsz_cf7_after_insert_db', $contact_form, $cf7_id, $data_id);
75
+ }
76
+
77
+ }
78
+
79
+ /*
80
+ * Support CF7 functions
81
+ */
82
+ function vsz_cf7_get_posted_data($cf7){
83
+
84
+ if (!isset($cf7->posted_data) && class_exists('WPCF7_Submission')) {
85
+ // Contact Form 7 version 3.9 removed $cf7->posted_data and now
86
+ // we have to retrieve it from an API
87
+ $submission = WPCF7_Submission::get_instance();
88
+ if ($submission){
89
+ $data = array();
90
+ $data['title'] = $cf7->title();
91
+ $data['posted_data'] = $submission->get_posted_data();
92
+ $data['uploaded_files'] = $submission->uploaded_files();
93
+ $data['WPCF7_ContactForm'] = $cf7;
94
+ $cf7 = (object) $data;
95
+ }
96
+ }
97
+ return $cf7;
98
+ }
99
+
100
+ /*
101
+ * Add additional value with form data
102
+ */
103
+ function vsz_cf7_add_extra_fields($cf7){
104
+
105
+ $submission = WPCF7_Submission::get_instance();
106
+
107
+ //Get time stamp value in valid date format
108
+ $cf7->posted_data['submit_time'] = date_i18n('Y-m-d H:i:s', $submission->get_meta('timestamp'));
109
+
110
+ if(!defined('vsz_cf7_display_ip')){
111
+ //Get submitted ip address
112
+ $cf7->posted_data['submit_ip'] = (isset($_SERVER['X_FORWARDED_FOR'])) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
113
+ }
114
+ return $cf7;
115
+ }
116
+
117
+ //save files uploaded by user and modify data before inserting to database
118
+ add_filter('vsz_cf7_modify_form_before_insert_data', 'vsz_cf7_modify_form_before_insert_in_cf7_vdata_entry');
119
+ if (!function_exists('vsz_cf7_modify_form_before_insert_in_cf7_vdata_entry')) {
120
+ function vsz_cf7_modify_form_before_insert_in_cf7_vdata_entry($cf7){
121
+ //if it has at lest 1 file uploaded
122
+ if (count($cf7->uploaded_files) > 0) {
123
+ //Get upload dir URL
124
+ $upload_dir = wp_upload_dir();
125
+ //Create custom upload folder
126
+ $cf7d_upload_folder = VSZ_CF7_UPLOAD_FOLDER;
127
+ $dir_upload = $upload_dir['basedir'] . '/' . $cf7d_upload_folder;
128
+ wp_mkdir_p($dir_upload);
129
+ //Get all uploaded files information
130
+ foreach ($cf7->uploaded_files as $k => $v) {
131
+ //Get file name
132
+ $file_name = basename($v);
133
+ //Create unique file name
134
+ $file_name = wp_unique_filename($dir_upload, $file_name);
135
+ //Setup filoe path
136
+ $dst_file = $dir_upload . '/' . $file_name;
137
+ //Copy file information in destination variable
138
+ if (@copy($v, $dst_file)){
139
+ //Setup customize file information in array
140
+ $cf7->posted_data[$k] = $upload_dir['baseurl'] . '/' . $cf7d_upload_folder . '/' . $file_name;
141
+ }
142
+ }//Close foreach
143
+ }//Close if
144
+ return $cf7;
145
+ }//Close function
146
+ }//Close if for check function exist or not
147
+
148
+ //Define function for which field value not insert in table
149
+ function vsz_cf7_no_save_fields(){
150
+ $cf7d_no_save_fields = array('_wpcf7', '_wpcf7_version', '_wpcf7_locale', '_wpcf7_unit_tag', '_wpcf7_is_ajax_call','_wpcf7_container_post');
151
+ //Add filter for customize values
152
+ return apply_filters('vsz_cf7_no_save_fields', $cf7d_no_save_fields);
153
+ }//Close function
154
+
155
+ //Get all contact form list here
156
+ function vsz_cf7_get_the_form_list($fid = ''){
157
+
158
+ //Get All form information
159
+ $forms = WPCF7_ContactForm::find();
160
+ $form = array();
161
+ //fetch each form information
162
+
163
+ foreach ($forms as $k => $v){
164
+ //Check if form id not empty then get specific form related information
165
+ if(!empty($fid)){
166
+ if($v->id() === $fid){
167
+ $form[] = $v;
168
+ return $form;
169
+ }
170
+ }
171
+ else{
172
+ $form[] = $v;
173
+ }
174
+ }
175
+ // New function Added to sort the array by CF7 Name
176
+ usort($form, "cmp_sort_form_name");
177
+
178
+ return $form;
179
+ }//Close function
180
+ /*
181
+ * Sorting the contact forms to asc order by CF7 name
182
+ */
183
+ function cmp_sort_form_name($a, $b)
184
+ {
185
+ //return $a->name > $b->name;
186
+ return strcmp($a->name(), $b->name());
187
+
188
+ }
189
+
190
+
191
+
192
+ /*
193
+ * $data: rows from database
194
+ * $fid: form id
195
+ */
196
+ function vsz_cf7_sortdata($data){
197
+ $data_sorted = array();
198
+ //Set submitted id wise form information
199
+ foreach ($data as $k => $v) {
200
+ if(!isset($data_sorted[$v->data_id])){
201
+ $data_sorted[$v->data_id] = array();
202
+ }
203
+ $data_sorted[$v->data_id][$v->name] = apply_filters('cf7d_entry_value', trim(wp_unslash($v->value)), $v->name);
204
+ }
205
+
206
+ return $data_sorted;
207
+ }
208
+
209
+ //Get form id related fields information from DB
210
+ function vsz_cf7_get_db_fields($fid, $filter = true){
211
+ global $wpdb;
212
+ $fid = (int)$fid;
213
+ $sql = "SELECT `name` FROM `".VSZ_CF7_DATA_ENTRY_TABLE_NAME."` WHERE cf7_id = ".$fid." GROUP BY `name`";
214
+ $data = $wpdb->get_results($sql);
215
+
216
+ //Set each field value in array
217
+ $fields = array();
218
+ if(!empty($data)){
219
+
220
+ foreach ($data as $k => $v) {
221
+ if(defined('vsz_cf7_display_ip')){
222
+ if($v->name != 'submit_ip'){
223
+ $fields[$v->name] = htmlspecialchars_decode($v->name);
224
+ }
225
+ }
226
+ else{
227
+ $fields[$v->name] = htmlspecialchars_decode($v->name);
228
+ }
229
+ }
230
+ }
231
+
232
+ //Check if filter is true or not
233
+ if ($filter) {
234
+ //Get all fields information as per Setting screen
235
+ $fields = apply_filters('vsz_cf7_admin_fields', $fields, $fid);
236
+ }
237
+
238
+ return $fields;
239
+ }//Close function
240
+
241
+ //Add option value in specific select box request
242
+ if(!function_exists('vsz_cf7_arr_to_option')){
243
+ function vsz_cf7_arr_to_option($arr){
244
+ $html = '';
245
+ if(!empty($arr) && is_array($arr)){
246
+ foreach($arr as $k => $v) {
247
+ $html .= '<option value="'.esc_html($k).'">'.esc_html($v).'</option>';
248
+ }
249
+ }
250
+ return $html;
251
+ }
252
+ }
253
+
254
+ //get speicfic fields related information
255
+ function vsz_cf7_admin_get_field_name($field){
256
+ return esc_html($field);
257
+ }
258
+
259
+ //Get form id and specific entry related keys information
260
+ function get_entry_related_fields_info($fid,$entryId){
261
+ $fields = array();
262
+ if(!empty($fid) && !empty($entryId)){
263
+
264
+ global $wpdb;
265
+ $fid = intval($fid);
266
+ $entryId = intval($entryId);
267
+
268
+ $sql = "SELECT `name` FROM `".VSZ_CF7_DATA_ENTRY_TABLE_NAME."` WHERE `cf7_id` = ".$fid." AND `data_id` = ".$entryId." GROUP BY `name`";
269
+ $data = $wpdb->get_results($sql);
270
+ if(!empty($data)){
271
+ foreach ($data as $k => $v) {
272
+ $fields[$v->name] = htmlspecialchars_decode($v->name);
273
+ }
274
+ }
275
+ }
276
+ return $fields;
277
+ }
278
+
279
+ //Check current action
280
+ function vsz_cf7_current_action(){
281
+
282
+ $current_action = false;
283
+ if (isset($_POST['action']) && -1 != $_POST['action'] && isset($_POST['btn_apply'])) {
284
+ $current_action = sanitize_text_field($_POST['action']);
285
+ return apply_filters('vsz_cf7_get_current_action', $current_action);
286
+ }
287
+
288
+ if (isset($_POST['action2']) && -1 != $_POST['action2'] && isset($_POST['btn_apply2'])) {
289
+ $current_action = sanitize_text_field($_POST['action2']);
290
+ return apply_filters('vsz_cf7_get_current_action', $current_action);
291
+ }
292
+ $current_action = apply_filters('vsz_cf7_get_current_action', $current_action);
293
+ return false;
294
+ }
295
+
296
+
297
+ //Display field type related values here
298
+ function vsz_display_field_type_value($type,$arr_field_type,$k,$v){
299
+ $type = esc_html($type);
300
+ $k = esc_html($k);
301
+ if($type == 'checkbox'){
302
+
303
+ if(is_array($v)){
304
+ $label = esc_html($v['label']);
305
+ }
306
+ else{
307
+ $label = esc_html($v);
308
+ }
309
+ $loading = __('Loading...');
310
+ echo "<li class=\"clearfix\">
311
+ <span class=\"label\">".$label." (".$type.")</span>
312
+ <textarea name=\"field[".$k."]\" rows=\"3\" cols=\"20\" class=\"field-".$k."\" >".$loading."</textarea>
313
+ <span class=\"margin_left\">(Multiple entry start from new line)</span>
314
+ <div class=\"clear\"></div>
315
+ </li>";
316
+ }
317
+ else if($type == 'radio'){
318
+
319
+ if(is_array($v)){
320
+ $label = esc_html($v['label']);
321
+ }
322
+ else{
323
+ $label = esc_html($v);
324
+ }
325
+ $loading = __('Loading...');
326
+ echo "<li class=\"clearfix\">
327
+ <span class=\"label\">".$label." (".$type.")</span>
328
+ <textarea name=\"field[".$k."]\" rows=\"3\" cols=\"20\" class=\"field-".$k."\" >".$loading."</textarea><div class=\"clear\"></div></li>";
329
+ }
330
+ else if($type == 'select'){
331
+ if(is_array($v)){
332
+ $label = esc_html($v['label']);
333
+ }
334
+ else{
335
+ $label = esc_html($v);
336
+ }
337
+ $loading = __('Loading...');
338
+ echo "<li class=\"clearfix\">
339
+ <span class=\"label\">".$label." (".$type.")</span>
340
+ <textarea name=\"field[".$k."]\" rows=\"3\" cols=\"20\" class=\"field-".$k."\" >".$loading."</textarea><div class=\"clear\"></div></li>";
341
+ }
342
+ else if($type == 'textarea'){
343
+ if(is_array($v)){
344
+ $label = esc_html($v['label']);
345
+ }
346
+ else{
347
+ $label = esc_html($v);
348
+ }
349
+ $loading = __('Loading...');
350
+ echo "<li class=\"clearfix\">
351
+ <span class=\"label\">".$label."</span>
352
+ <textarea name=\"field[".$k."]\" rows=\"3\" cols=\"20\" class=\"field-".$k."\" >".$loading."</textarea><div class=\"clear\"></div></li>";
353
+ }
354
+ else if($type == 'file'){
355
+ if(is_array($v)){
356
+ $label = esc_html($v['label']);
357
+ }
358
+ else{
359
+ $label = esc_html($v);
360
+ }
361
+ $loading = __('Loading...');
362
+ $disable = 'readonly';
363
+ echo "<li class=\"clearfix\">
364
+ <span class=\"label\">".$label."</span>
365
+ <input class=\"field-".$k."\" type=\"text\" name=\"field[".$k."]\" value=\"".$loading."\" ".$disable." /><div class=\"clear\"></div></li>";
366
+ }else if($type == 'tel'){
367
+
368
+ if(is_array($v)){
369
+ $label = esc_html($v['label']);
370
+ }
371
+ else{
372
+ $label = esc_html($v);
373
+ }
374
+ $loading = __('Loading...');
375
+ echo "<li class=\"clearfix\">
376
+ <span class=\"label\">".$label."</span>
377
+ <input class=\"field-".$k."\" type=\"text\" name=\"field[".$k."]\" value=\"".$loading."\" /><div class=\"clear\"></div></li>";
378
+ }else if($type == 'dynamictext'|| $type == 'dynamichidden'|| $type == 'url' || $type == 'number' || $type == 'date' || $type == 'acceptance' || $type == 'quiz'){
379
+ if(is_array($v)){
380
+ $label = esc_html($v['label']);
381
+ }
382
+ else{
383
+ $label = esc_html($v);
384
+ }
385
+ $loading = __('Loading...');
386
+ echo "<li class=\"clearfix\">
387
+ <span class=\"label\">".$label."</span>
388
+ <input class=\"field-".$k."\" type=\"text\" name=\"field[".$k."]\" value=\"".$loading."\" /><div class=\"clear\"></div></li>";
389
+ }else{
390
+ if(is_array($v)){
391
+ $label = esc_html($v['label']);
392
+ }
393
+ else{
394
+ $label = esc_html($v);
395
+ }
396
+ $loading = __('Loading...');
397
+ echo "<li class=\"clearfix\">
398
+ <span class=\"label\">".$label."</span>
399
+ <textarea name=\"field[".$k."]\" rows=\"3\" cols=\"20\" class=\"field-".$k."\" >".$loading."</textarea><div class=\"clear\"></div></li>";
400
+ }
401
+
402
+ }
403
+
404
+ //Define sheet related date formates
405
+ function vsz_cf7_import_date_format_callback(){
406
+
407
+ $arr_dates = array('Y-m-d H:i:s P' => date('Y-m-d H:i:s P'),
408
+ 'Y-m-d' => date('Y-m-d'),
409
+ 'Y/m/d' => date('Y/m/d'),
410
+ 'jS F, Y' => date('jS F, Y'),
411
+ 'F j, Y' => date('F j, Y'),
412
+ 'd/m/Y' => date('d/m/Y'),
413
+ 'd-m-Y' => date('d-m-Y')
414
+ );
415
+ return $arr_dates;
416
+ }
417
+
418
+ //Get field name related type information
419
+ function vsz_field_type_info($fid){
420
+
421
+ if(empty($fid) || !intval($fid)) return ;
422
+
423
+ $fid = intval($fid);
424
+ $obj_form = vsz_cf7_get_the_form_list($fid);
425
+ //get pre define fields information
426
+ $arr_form_tag = $obj_form[0]->scan_form_tags();
427
+ $arr_field_type = array();
428
+ if(!empty($arr_form_tag)){
429
+ //Get all fields related information
430
+ foreach($arr_form_tag as $key => $arr_type){
431
+ //Check if tag type is submit then ignore tag info
432
+ if($arr_type['basetype'] == 'submit') continue;
433
+ //get field type information
434
+ $arr_field_type[$arr_type['name']] = $arr_type['basetype'];
435
+ }
436
+ }
437
+
438
+ return $arr_field_type;
439
  }