PluginProbe
Smart Forms – when you need more than just a contact form / 0.7
Smart Forms – when you need more than just a contact form v0.7
trunk 0.5 0.5.5 0.6 0.7 0.8 0.8.5 0.9.1
← All changes | smart-forms-ajax.php +141 -662 trunk0.7 View file →
@@ -1,120 +1,14 @@
1 1 <?php
2 2
3 3 function GetPostValue($parameterName)
4 4 {
5 - require_once SMART_FORMS_DIR.'utilities/JSONSanitizer.php';
6 5 if(isset($_POST[$parameterName]))
7 - if(is_array(($_POST[$parameterName])))
8 - return RednaoJSONSanitizer::Sanitize($_POST[$parameterName],(Object)['Data'=>(object)[]]);
9 - else
10 - return stripslashes(RednaoJSONSanitizer::Sanitize($_POST[$parameterName],(Object)['Data'=>(object)[]]));
6 + return stripslashes($_POST[$parameterName]);
11 7
12 8 return "";
13 9 }
14 10
15 -function rednao_smart_forms_export(){
16 -
17 - require_once SMART_FORMS_DIR.'smart-forms-export-form.php';
18 -
19 -
20 - die();
21 -}
22 -
23 -function smart_forms_export(){
24 - if(!wp_verify_nonce(GetPostValue('nonce'),'smart_forms_list_entries')||!current_user_can('edit_pages'))
25 - {
26 - echo json_encode(array(
27 - 'success'=>false,
28 - 'errorMessage'=>'Invalid Request'
29 - ));
30 - die();
31 - }
32 -
33 - require_once 'smart-forms-exporter.php';
34 -}
35 -
36 -function smart_forms_skip_tutorial(){
37 - if(!wp_verify_nonce(GetPostValue('nonce'),'save_nonce')||!current_user_can('edit_pages'))
38 - {
39 - echo json_encode(array(
40 - 'success'=>false,
41 - 'errorMessage'=>'Invalid Request'
42 - ));
43 - die();
44 - }
45 -
46 - update_site_option('smart_forms_show_tutorial','y');
47 -}
48 -
49 -function smart_forms_save_settings(){
50 - if((!wp_verify_nonce(GetPostValue('nonce'),'smart-forms-save-settings'))||!current_user_can('edit_pages'))
51 - {
52 - echo json_encode(array(
53 - 'success'=>false,
54 - 'message'=>'Invalid request'
55 - ));
56 - die();
57 - }
58 - $options=GetPostValue('options');
59 - if($options=='')
60 - return;
61 - foreach($options as $value)
62 - {
63 - update_option($value['key'],$value['value']);
64 - }
65 -}
66 -
67 -function rednao_smart_forms_resend_email(){
68 - $data=GetPostValue('data');
69 -
70 -
71 - require_once SMART_FORMS_DIR.'utilities/JSONSanitizer.php';
72 - $data=RednaoJSONSanitizer::Sanitize(json_decode(stripslashes($_POST['data'])),(object)[
73 - "EmailIndex"=>0,
74 - "FormId"=>0,
75 - "EntryId"=>0,
76 - "Nonce"=>''
77 - ]);
78 -
79 - if(!wp_verify_nonce($data->Nonce,'smart_forms_list_entries')||!current_user_can('edit_pages'))
80 - {
81 - echo json_encode(array(
82 - 'success'=>false,
83 - 'errorMessage'=>'Invalid Request'
84 - ));
85 - die();
86 - }
87 - $emailIndex=$data->EmailIndex;
88 - $form=$data->Form;
89 - $entryId=$data->EntryId;
90 -
91 - include_once(SMART_FORMS_DIR.'php_classes/save/php_entry_saver_base.php');
92 -
93 - global $wpdb;
94 - $entryRow=$wpdb->get_row($wpdb->prepare('select data from '.SMART_FORMS_ENTRY.' where entry_id=%d',$entryId));
95 - $form=$wpdb->get_row($wpdb->prepare('select * from '.SMART_FORMS_TABLE_NAME.' where form_id=%d',$form));
96 -
97 -
98 - $phpEntry=new php_entry_saver_base($data->Form,$entryRow->data,'n','',json_decode($form->form_options,true),json_decode($form->element_options,true));
99 - if($phpEntry->FormOptions['Emails']!=null&&count($phpEntry->FormOptions['Emails'])>$emailIndex)
100 - {
101 - require_once SMART_FORMS_DIR.'php_classes/save/insert_entry_base.php';
102 - require_once SMART_FORMS_DIR.'php_classes/save/pre_insert_entry.php';
103 - $additionalData=[];
104 - $preInsertedEntry=new PreInsertEntry($data->Form,$phpEntry->FormEntryData,$phpEntry->FormOptions,$phpEntry->ElementOptions,$additionalData);
105 - $phpEntry->SendFormEmail($phpEntry->FormOptions['Emails'][$emailIndex],$phpEntry->FormEntryData,$phpEntry->ElementOptions,$preInsertedEntry,false);
106 - }
107 -
108 - echo json_encode(array(
109 - 'success'=>true,
110 - 'result'=>true
111 - ));
112 -
113 - die();
114 -
115 -}
116 -
117 11 function rednao_smart_forms_save()
118 12 {
119 13 $form_id=GetPostValue("id");
120 14 $element_options=GetPostValue("element_options");
@@ -119,19 +13,9 @@
119 13 $form_id=GetPostValue("id");
120 14 $element_options=GetPostValue("element_options");
121 15 $form_options=GetPostValue("form_options");
122 16 $client_form_options=GetPostValue("client_form_options");
123 - $donation_email=GetPostValue("donation_email");
124 - $nonce='';
125 - if(isset($_POST['nonce']))
126 - $nonce=$_POST['nonce'];
127 17
128 - if(!wp_verify_nonce($nonce,'save_nonce')||!current_user_can('manage_options'))
129 - {
130 - $form_id=intval($form_id);
131 - echo "{\"FormId\":\"$form_id\",\"Message\":\"Invalid Request\"}";
132 - die();
133 - }
134 18 //$form_options=str_replace("\\\"","\"",$form_options);
135 19 $formParsedValues=json_decode($form_options);
136 20
137 21
@@ -153,10 +37,9 @@
153 37 {
154 38 $values=array('form_name'=>$formParsedValues->Name,
155 39 'element_options'=>$element_options,
156 40 'form_options'=>$form_options,
157 - 'client_form_options'=>$client_form_options,
158 - 'donation_email'=>$donation_email
41 + 'client_form_options'=>$client_form_options
159 42 );
160 43
161 44 $wpdb->insert(SMART_FORMS_TABLE_NAME,$values);
162 45 $form_id=$wpdb->insert_id;
@@ -168,10 +51,9 @@
168 51 $wpdb->update(SMART_FORMS_TABLE_NAME,array(
169 52 'form_name'=>$formParsedValues->Name,
170 53 'element_options'=>$element_options,
171 54 'form_options'=>$form_options,
172 - 'client_form_options'=>$client_form_options,
173 - 'donation_email'=>$donation_email
55 + 'client_form_options'=>$client_form_options
174 56 ),array("form_id"=>$form_id));
175 57 $message="saved";
176 58 delete_transient("rednao_smart_forms_$form_id");
177 59
@@ -179,158 +61,165 @@
179 61
180 62 }
181 63
182 64
183 - echo json_encode(array(
184 - 'FormId'=>$form_id,
185 - 'Message'=>$message
186 - ));
65 + echo "{\"FormId\":\"$form_id\",\"Message\":\"$message\"}";
187 66
188 67 die();
189 68 }
190 69
191 70
192 -function rednao_smart_form_short_code_setup()
71 +function rednao_smart_form_list()
193 72 {
194 - if ( (! current_user_can('edit_posts') && ! current_user_can('edit_pages'))||!wp_verify_nonce($_POST['nonce'],'short_code_setup') ) {
73 + if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {
195 74 return;
196 75 }
197 76
198 77 global $wpdb;
78 + $result=$wpdb->get_results("SELECT form_id,form_name FROM ".SMART_FORMS_TABLE_NAME);
199 79
200 - $shortCodeOptions=array();
201 - array_push($shortCodeOptions,array(
202 - "Name"=>"Forms",
203 - "ShortCode"=>"sform",
204 - "Elements"=>array()
205 - ));
206 -
207 - $result=$wpdb->get_results("SELECT form_id,form_name FROM ".SMART_FORMS_TABLE_NAME);
208 - //echo "[{\"Id\":\"0\",\"Name\":\"Select a Form\"}";
80 + echo "[{\"Id\":\"0\",\"Name\":\"Select a Form\"}";
209 81 foreach($result as $key=>$row)
210 82 {
211 - array_push($shortCodeOptions[0]["Elements"],array(
212 - "Id"=>$row->form_id,
213 - "Name"=>$row->form_name
214 - ));
215 -
83 + echo ",{\"Id\":\"$row->form_id\",\"Name\":\"$row->form_name\"}";
216 84 }
217 -
218 - $shortCodeOptions=apply_filters("smart_forms_get_short_code_options",$shortCodeOptions);
219 -
220 - echo json_encode($shortCodeOptions);
85 + echo"]";
221 86 die();
222 87 }
223 88
224 89
225 -
226 -
227 90 function rednao_smart_forms_save_form_values()
228 91 {
229 - include_once(SMART_FORMS_DIR.'php_classes/save/php_entry_saver_base.php');
230 -
231 92 $form_id=GetPostValue("form_id");
232 93 $formString=GetPostValue("formString");
233 94
234 - if(isset($_POST['nonce']))
235 - $nonce=$_POST['nonce'];
95 + $entryData=json_decode($formString,true);
236 96
237 - $blockAnonymousSubmissions=get_option('smart_forms_block_anonymous_submissions');
238 - if(apply_filters('smart_forms_block_annonymous_submissions',$blockAnonymousSubmissions)&&!wp_verify_nonce($nonce,'save_form'))
239 - {
240 - echo '{"message":"'.__("Invalid submission, please refresh your screen and try again.").'","refreshCaptcha":"n","success":"n"}';
241 - die();
97 + global $wpdb;
98 + $result=$wpdb->get_results($wpdb->prepare("select form_options,element_options from ".SMART_FORMS_TABLE_NAME." where form_id=%d",$form_id));
99 +
100 + $formOptions=null;
101 + $elementOptions=null;
102 +
103 + if(count($result)>0){
104 + $formOptions=json_decode($result[0]->form_options,true);
105 + $elementOptions=json_decode($result[0]->element_options,true);
242 106 }
243 107
244 - $captcha="";
245 - if(isset($_POST["captcha"]))
246 - if(is_array($_POST["captcha"]))
108 + if($formOptions["UsesCaptcha"]=="y")
109 + {
110 + if(!isset($_POST["captcha"]))
247 111 {
248 - require_once SMART_FORMS_DIR.'utilities/JSONSanitizer.php';
249 - $captcha=(array)RednaoJSONSanitizer::Sanitize($_POST["captcha"],(object)[
250 - "version"=>"",
251 - "response"=>''
252 - ]);
112 + echo '{"message":"'.__("Invalid captcha.").'", "success":"n"}';
113 + die();
253 114 }
254 - else
255 - $captcha=sanitize_text_field(stripslashes($_POST["captcha"]));
115 + $captchaPost=$_POST["captcha"];
116 + $captcha=ARRAY();
117 + $captcha["challenge"]=stripslashes($captchaPost["challenge"]);
118 + $captcha["response"]=stripslashes($captchaPost["response"]);
119 + $captcha["remoteip"]=$_SERVER['REMOTE_ADDR'];
120 + $captcha["privatekey"]="6Lf2J-wSAAAAAOH6uSmSdx75ZLRpDIfvSeAdx9ST";
256 121
257 - $phpEntry=new php_entry_saver_base($form_id,$formString,$captcha);
258 - $phpEntry->ProcessEntry();
259 - die();
260 -}
122 + $args=Array();
261 123
262 -function rednao_smart_forms_get_form_element_info()
263 -{
264 - $formId=GetPostValue("formId");
265 - $nonce=GetPostValue("nonce");
266 - if (( ! current_user_can('edit_posts') && ! current_user_can('edit_pages'))||!wp_verify_nonce($nonce,'save_nonce') ) {
267 - return;
268 - }
124 + $args['headers']=Array
125 + (
126 + 'Content-Type'=>'application/x-www-form-urlencoded;',
127 + 'Method'=>'Post'
128 + );
129 + $args['body']=$captcha;
130 + $res=wp_remote_post('http://www.google.com/recaptcha/api/verify',$args);
131 + if(strpos($res["body"],"true")!==0)
132 + {
133 + echo '{"message":"'.__("Invalid captcha.").'","refreshCaptcha":"y","success":"n"}';
134 + die();
135 + }
269 136
270 - global $wpdb;
271 - $result=$wpdb->get_var($wpdb->prepare("SELECT element_options FROM ".SMART_FORMS_TABLE_NAME.' where form_id=%d',$formId));
272 137
273 - echo json_encode(array(
274 - 'elementsInfo'=>json_decode($result)
138 + }
139 +
140 + $result=$wpdb->insert(SMART_FORMS_ENTRY,array(
141 + 'form_id'=>$form_id,
142 + 'date'=>date('Y-m-d H:i:s'),
143 + 'data'=>$formString,
144 + 'ip'=>$_SERVER['REMOTE_ADDR'],
275 145 ));
276 146
277 - die();
147 + if($formOptions["SendNotificationEmail"]=="y")
148 + send_form_email($formOptions["Emails"][0],$entryData,$elementOptions,false);
149 +
150 + if($result==true)
151 + echo '{"message":"'.__("Information submitted successfully.").'","success":"y"}';
152 + else
153 + echo '{"message":"'.__("An error occurred, please try again later.").'","success":"n"}';
154 + die();
278 155 }
279 156
280 -function rednao_smart_forms_get_form_options()
157 +function send_form_email($formOptions,$entryData,$elementOptions,$useTestData)
281 158 {
282 - $formId=GetPostValue("formId");
283 - $nonce=GetPostValue("nonce");
284 - if (( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )||!wp_verify_nonce($nonce,'save_nonce')) {
285 - return;
159 + include(SMART_FORMS_DIR.'string_renderer/rednao_string_builder.php');
160 +
161 +
162 +
163 + $stringBuilder=new rednao_string_builder();
164 + $EmailText=$formOptions["EmailText"];
165 + $FromName=$formOptions["FromName"];
166 + $FromEmail=$formOptions["FromEmail"];
167 + $ToEmail=$formOptions["ToEmail"];
168 + $EmailSubject=$formOptions["EmailSubject"];
169 +
170 +
171 + if($FromName=="")
172 + $FromName="Wordpress";
173 +
174 + if($EmailSubject=="")
175 + $EmailSubject="Form Submitted";
176 +
177 + if($ToEmail=="")
178 + $ToEmail=get_option("admin_email");
179 +
180 + preg_match_all('/\\[field ([^\\]]+)/',$EmailText, $matches, PREG_PATTERN_ORDER);
181 +
182 + foreach($matches[1] as $match)
183 + {
184 + $value=GetValueByField($stringBuilder,$match,$entryData,$elementOptions,$useTestData);
185 + $EmailText=str_replace("[field $match]",$value,$EmailText);
286 186 }
287 187
288 - global $wpdb;
289 - $result=$wpdb->get_results($wpdb->prepare("SELECT form_options,element_options FROM ".SMART_FORMS_TABLE_NAME.' where form_id=%d',$formId));
290 188
291 - global $current_user;
292 - echo json_encode(array(
293 - 'formOptions'=>json_decode($result[0]->form_options),
294 - 'elementOptions'=>json_decode($result[0]->element_options),
295 - 'CurrentEmail'=>strval($current_user->user_email)
296 - ));
297 - die();
298 -}
189 +/*
299 190
300 -function rednao_get_fixed_field_value($match,$entryData,$elementOptions,$useTestData)
301 -{
302 - require_once(SMART_FORMS_DIR.'filter_listeners/fixed-field-listeners.php');
303 - $match=str_replace("'","\"",$match);
304 - $fixedFieldParameters=json_decode($match,true);
305 - if($fixedFieldParameters==null)
306 - {
307 - error_log('error parsing fixed field');
308 - return '';
309 - }
310 191
311 - try{
312 - $value=apply_filters("smart-forms-fixed-field-value-".$fixedFieldParameters["Op"],$fixedFieldParameters,$entryData,$elementOptions,$useTestData);
313 - if($value==$fixedFieldParameters)
314 - return "";
315 - if($value==null)
316 - $value='';
317 - return strval($value);
318 - }catch(Exception $e)
319 - {
320 - error_log("Couldn't format date ".$e->getMessage());
321 - }
192 + foreach($entryData as $key=>$value)
193 + {
322 194
323 - return "";
195 + $element=null;
196 + foreach($elementOptions as $item)
197 + {
198 + if($item->Id==$key)
199 + {
200 + $element=$item;
201 + break;
202 + }
203 + }
204 +
205 + $emailText.="<tr>". $stringBuilder->GetStringFromColumn($element,$value)."</tr>";
206 + }
207 + $emailText.="</table>";*/
208 +
209 + $headers = 'MIME-Version: 1.0' . "\r\n";
210 + $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
211 + $headers.= "$FromName <$FromEmail>";
212 + if(trim($ToEmail)!="")
213 + {
214 + return wp_mail($ToEmail, $EmailSubject, $EmailText, $headers);
215 + }
216 +
217 + return false;
324 218 }
325 219
326 220 function GetValueByField($stringBuilder,$match,$entryData,$elementOptions,$useTestData)
327 221 {
328 - if(strpos(trim($match),'{')===0)
329 - {
330 - return rednao_get_fixed_field_value($match,$entryData,$elementOptions,$useTestData);
331 - }
332 -
333 222 foreach($entryData as $key=>$value)
334 223 {
335 224 $element=null;
336 225 if($key!=$match)
@@ -357,129 +246,44 @@
357 246 if($useTestData)
358 247 return "sample text";
359 248 }
360 249
361 -function rednao_smart_forms_send_files(){
362 - require_once SMART_FORMS_DIR.'smart_forms_uploader.php';
363 - die();
364 -}
365 -
366 -function rednao_smart_form_delete_entries(){
367 - $data=json_decode(GetPostValue('data'));
368 -
369 - $nonce=$data->Nonce;
370 -
371 - if(!wp_verify_nonce($nonce,'smart_delete_entry')||!current_user_can('edit_pages'))
372 - {
373 - echo json_encode(array(
374 - 'success'=>false,
375 - 'errorMessage'=>'Invalid nonce, please refresh your screen and try again'
376 - ));
377 - die();
378 - }
379 -
380 - if($data==null||!isset($data->Ids))
381 - {
382 - echo json_encode(array(
383 - 'success'=>false,
384 - 'errorMessage'=>'Invalid values'
385 - ));
386 - die();
387 - }
388 -
389 - global $wpdb;
390 -
391 - $how_many = count($data->Ids);
392 - $placeholders = array_fill(0, $how_many, '%d');
393 - $format = implode(', ', $placeholders);
394 - $query = "DELETE FROM ".SMART_FORMS_ENTRY." WHERE entry_id IN($format)";
395 - $wpdb->query( $wpdb->prepare($query, $data->Ids) );
396 -
397 -
398 - $query = "DELETE FROM ".SMART_FORMS_ENTRY_DETAIL." WHERE entry_id IN($format)";
399 - $wpdb->query( $wpdb->prepare($query, $data->Ids) );
400 -
401 - echo json_encode(array(
402 - 'success'=>true,
403 - 'result'=>true
404 - ));
405 -
406 - die();
407 -
408 -
409 -}
410 -
411 250 function rednao_smart_forms_entries_list()
412 251 {
413 - $data=json_decode(GetPostValue('data'));
252 + $startDate=GetPostValue("startDate");
253 + $endDate=GetPostValue("endDate");
254 + $formId=GetPostValue("form_id");
414 255
415 - if(!isset($data->nonce)||!wp_verify_nonce($data->nonce,'smart_forms_list_entries')||(!current_user_can('manage_options')&&!current_user_can('smart_forms_view_entries'))) {
416 - echo json_encode(array(
417 - 'success' => false,
418 - 'errorMessage' => 'Invalid Request'
419 - ));
420 - die();
421 - }
422 - if($data==null)
423 - {
424 - echo json_encode(array(
425 - 'success'=>false,
426 - 'errorMessage'=>'Invalid values'
427 - ));
428 - die();
429 - }
256 + $startDate=date('Y-m-d H:i:s', strtotime($startDate));
257 + $endDate=date('Y-m-d H:i:s', strtotime($endDate .' +1 day'));
430 258
431 - require_once SMART_FORMS_API;
259 + $query="select data from ".SMART_FORMS_ENTRY."
260 + where date between '$startDate' and '$endDate' and form_id=$formId";
432 261
433 - $query=new SmartFormsQuery($data->Form);
434 262
435 -
436 263 global $wpdb;
264 + $result=$wpdb->get_results($query);
265 + $isFirstRecord=true;
437 266
438 -
439 - foreach($data->Conditions as $condition)
267 + echo '{"entries":[';
268 + foreach($result as $row)
440 269 {
441 - if(isset($condition->FieldId)&&isset($condition->Comparison)&& $condition->FieldId!=''&&$condition->Comparison!='')
442 - {
443 - $query->AddCondition($condition->FieldId,$condition->Comparison,$condition->Value);
444 - }
445 - }
270 + if($isFirstRecord)
271 + $isFirstRecord=false;
272 + else
273 + echo ",";
446 274
447 - if($data->StartDate!=0)
448 - {
449 - $query->AddCondition('_Date','>=',get_gmt_from_date(date('Y-m-d H:i:s',$data->StartDate)));
275 + echo $row->data;
450 276
451 277 }
278 + echo '],"formOptions":';
452 279
453 - if($data->EndDate!=0)
454 - {
455 - $query->AddCondition('_Date','<',get_gmt_from_date(date('Y-m-d H:i:s',$data->EndDate+86400)));
456 - }
280 + $query="select element_options from ".SMART_FORMS_TABLE_NAME." where form_id=".$formId;
281 + $elementOptions=$wpdb->get_var($query);
282 + echo $elementOptions.'}';
457 283
458 284
459 - $result=$query->GetRaw($data->PageSize,$data->PageSize*$data->PageIndex);
460 - $entries=array();
461 - foreach($result as $row)
462 - {
463 - $entries[]=array(
464 - "date"=>get_date_from_gmt($row['date']),
465 - "entry_id"=>$row['entry_id'],
466 - "user_name"=>$row['user_name'],
467 - "user_id"=>$row['user_id'],
468 - "user_ip"=>$row['user_ip'],
469 - "data"=>json_decode($row['data'])
470 - );
471 -
472 - }
473 - echo json_encode(array(
474 - 'success'=>true,
475 - 'result'=>array(
476 - 'rows'=>json_encode($entries),
477 - 'count'=>$query->GetCount()
478 - )
479 - ));
480 285 die();
481 -
482 286 }
483 287
484 288 function rednao_smart_form_send_test_email()
485 289 {
@@ -484,36 +288,22 @@
484 288 function rednao_smart_form_send_test_email()
485 289 {
486 290 $FromEmail=GetPostValue("FromEmail");
487 291 $FromName=GetPostValue("FromName");
488 - $ToEmail=rtrim(GetPostValue("ToEmail"),",");
292 + $ToEmail=GetPostValue("ToEmail");
489 293 $EmailSubject=GetPostValue("EmailSubject");
490 294 $EmailText=GetPostValue("EmailText");
491 - $ReplyTo=GetPostValue("ReplyTo");
492 - $Bcc=GetPostValue("Bcc");
493 295 $elementOptions=GetPostValue("element_options");
494 - $pdfs=GetPostValue("PDFS");
495 - $nonce=GetPostValue('nonce');
496 296
497 - if(!wp_verify_nonce($nonce,'save_nonce')||!current_user_can('edit_pages'))
498 - {
499 - echo '{"Message":"'.__("Invalid request").'"}';
500 - die();
501 - }
297 + $elementOptions=json_decode($elementOptions);
502 298
503 - if(!is_array($elementOptions))
504 - $elementOptions=json_decode($elementOptions,true);
505 299
506 -
507 300 $valueArray=Array(
508 301 "FromEmail"=>$FromEmail,
509 302 "FromName"=>$FromName,
510 303 "ToEmail"=>$ToEmail,
511 304 "EmailSubject"=>$EmailSubject,
512 - "EmailText"=>$EmailText,
513 - "ReplyTo"=>$ReplyTo,
514 - "PDFS"=>$pdfs,
515 - "Bcc"=>$Bcc
305 + "EmailText"=>$EmailText
516 306 );
517 307 $entryData=Array();
518 308
519 309
@@ -522,11 +312,9 @@
522 312 echo '{"Message":"'.__("Email text can't be empty").'"}';
523 313 die();
524 314 }
525 315
526 - include_once(SMART_FORMS_DIR.'php_classes/save/php_entry_saver_base.php');
527 - $entrySaver=new php_entry_saver_base("","","");
528 - if($entrySaver->SendFormEmail($valueArray,$entryData,$elementOptions,null,true))
316 + if(send_form_email($valueArray,$entryData,$elementOptions,true))
529 317 echo '{"Message":"'.__("Email sent successfully").'"}';
530 318 else
531 319 echo '{"Message":"'.__("There was an error sending the email, please check the configuration").'"}';
532 320 die();
@@ -531,334 +319,25 @@
531 319 echo '{"Message":"'.__("There was an error sending the email, please check the configuration").'"}';
532 320 die();
533 321 }
534 322
535 -
536 323 function rednao_smart_forms_submit_license()
537 324 {
538 325 include_once(SMART_FORMS_DIR.'smart-forms-license.php');
539 326
540 -
541 -
542 327 $email=GetPostValue("email");
543 328 $key=GetPostValue("key");
544 - $nonce=GetPostValue('nonce');
545 - if(!wp_verify_nonce($nonce,'save_nonce')||!current_user_can('edit_pages'))
546 - {
547 - echo json_encode(array(
548 - 'success'=>false,
549 - 'errorMessage'=>'Invalid Request'
550 - ));
551 - die();
552 - }
553 329
554 - $license=smart_forms_check_license($email,$key,$error);
555 - if($license["is_valid"])
330 + if(smart_forms_check_license($email,$key,$error))
556 331 {
557 - echo '{"IsValid":"y","Message":"'.__("License submitted successfully, thank you!!").'","licenseType":""}';
332 + echo '{"IsValid":"y","Message":"'.__("License submitted successfully, thank you!!").'"}';
558 333 }else
559 334 {
560 335 if($error==null)
561 336 {
562 337 echo '{"IsValid":"n", "Message":"'.__("Invalid user or license").'"}';
563 - }else {
564 - echo '{"IsValid":"n","Message":"' . __("An error occurred") . '"}';
565 - }
338 + }else
339 + echo '{"IsValid":"n","Message":"'.__("An error occurred $error").'"}';
566 340 }
567 341
568 - die();
569 -}
570 -
571 -function rednao_smart_forms_execute_op()
572 -{
573 - $id=GetPostValue('TransactionId');
574 - $oper=GetPostValue('oper');
575 - $nonce=GetPostValue('nonce');
576 -
577 - if (( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )||!wp_verify_nonce($nonce,'smart_forms_list_entries')) {
578 - return;
579 - }
580 - if($oper=="del")
581 - {
582 - global $wpdb;
583 - if($wpdb->query($wpdb->prepare("delete from ".SMART_FORMS_ENTRY." WHERE entry_id=%d",$id))>0)
584 - {
585 - $wpdb->query($wpdb->prepare("delete from ".SMART_FORMS_ENTRY_DETAIL." WHERE entry_id=%d",$id));
586 - echo '{"success":"1"}';
587 - }
588 - else
589 - echo '{"success":"0","message":"'.__("Could not delete row").'"}';
590 - die();
591 - }
592 -
593 - if($oper=='massDelete')
594 - {
595 - global $wpdb;
596 - $ids=GetPostValue('entriesToDelete');
597 - $ids=json_decode($ids);
598 - $idwhere='';
599 - foreach($ids as $id)
600 - {
601 - if($idwhere!='')
602 - $idwhere.=',';
603 - $idwhere.=$wpdb->prepare('%d',$id);
604 - }
605 -
606 - $wpdb->query('delete from '.SMART_FORMS_ENTRY.' where entry_id in('.$idwhere.')');
607 - $wpdb->query('delete from '.SMART_FORMS_ENTRY_DETAIL.' where entry_id in('.$idwhere.')');
608 - echo '{"success":"1"}';
609 - die();
610 -
611 - }
612 -
613 -}
614 -
615 -function rednao_smart_forms_send_test()
616 -{
617 - if (( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )||!wp_verify_nonce(GetPostValue('nonce'),'save_nonce')) {
618 - return;
619 - }
620 -
621 - require_once SMART_FORMS_DIR.'php_classes/smart_forms_troubleshoot/smart_forms_email.php';
622 - switch(GetPostValue('Id'))
623 - {
624 - case "basic":
625 - $smartFormsEmail=new smart_forms_email_troubleshoot_basic();
626 - break;
627 - case "custom":
628 - $smartFormsEmail=new smart_forms_email_troubleshoot_custom_smtp();
629 - break;
630 - }
631 - if($smartFormsEmail->Start())
632 - echo json_encode(
633 - array(
634 - "Passed"=>'y'
635 - ));
636 - else
637 - echo json_encode(
638 - array(
639 - "Passed"=>'n',
640 - "Message"=>$smartFormsEmail->LatestError
641 - ));
642 - die();
643 -}
644 -
645 -function rednao_smart_forms_export_entries(){
646 - if(!isset($_GET['data']))
647 - {
648 - echo "Invalid request";
649 - die();
650 - }
651 -
652 - require_once SMART_FORMS_DIR.'utilities/JSONSanitizer.php';
653 - $data=RednaoJSONSanitizer::Sanitize(json_decode(stripslashes($_GET['data'])),(object)[
654 - "Nonce"=>'',
655 - "Form"=>0,
656 - "StartDate"=>0,
657 - "EndDate"=>0,
658 - "Conditions"=>[(object)[
659 - "FieldId"=>"",
660 - "Comparison"=>"",
661 - "Value"=>"",
662 -
663 - ]]
664 - ]);
665 -
666 - if($data==null)
667 - {
668 - echo "Invalid request";
669 - die();
670 - }
671 -
672 - if(!wp_verify_nonce($data->Nonce,'smart_forms_export')||!current_user_can('manage_options'))
673 - {
674 - echo "Invalid request";
675 - die();
676 - }
677 - require_once SMART_FORMS_API;
678 - $query=new SmartFormsQuery($data->Form);
679 -
680 -
681 - global $wpdb;
682 -
683 -
684 - foreach($data->Conditions as $condition)
685 - {
686 - if(isset($condition->FieldId)&&isset($condition->Comparison)&& $condition->FieldId!=''&&$condition->Comparison!='')
687 - {
688 - $query->AddCondition($condition->FieldId,$condition->Comparison,$condition->Value);
689 - }
690 - }
691 -
692 - if($data->StartDate!=0)
693 - {
694 - $query->AddCondition('_Date','>=',get_gmt_from_date(date('Y-m-d H:i:s',$data->StartDate)));
695 -
696 - }
697 -
698 - if($data->EndDate!=0)
699 - {
700 - $query->AddCondition('_Date','<',get_gmt_from_date(date('Y-m-d H:i:s',$data->EndDate+86400)));
701 - }
702 -
703 -
704 - $formName=$wpdb->get_var($wpdb->prepare('select form_name from '.SMART_FORMS_TABLE_NAME.' where form_id=%s',$data->Form));
705 -
706 - $result=$query->GetResults('','','array');
707 - $fh = fopen('php://output', 'w');
708 - $headers=array();
709 -
710 - header('Pragma: public');
711 - header('Expires: 0');
712 - header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
713 - header('Cache-Control: private', false);
714 - header('Content-Type: application/octet-stream');
715 - header('Content-Disposition: attachment; filename="' . str_replace('"', '\"', $formName[0].'_Export') . '.csv";');
716 - header('Content-Transfer-Encoding: binary');
717 -
718 - foreach($query->selectColumns as $column)
719 - {
720 - if($column=='_Date')
721 - $headers[]='Date';
722 - if($column=='_UserName')
723 - $headers[]='User Name';
724 -
725 - if(isset($query->fieldDictionary[$column]))
726 - {
727 - $field=$query->fieldDictionary[$column];
728 - if($field['ClassName']=='rednaosurveytable')
729 - {
730 - foreach($field['Rows'] as $row)
731 - {
732 - $headers[]=$row['label'];
733 - }
734 - }else
735 - $headers[]=$field['Label'];
736 - }
737 - }
738 -
739 - fputcsv($fh,$headers);
740 -
741 - foreach($result as $row)
742 - {
743 - $csvRow=array();
744 - foreach($query->selectColumns as $column)
745 - {
746 - if($column=='_Date')
747 - $csvRow[]=$row['_Date'];
748 - if($column=='_UserName')
749 - $csvRow[]=$row['_UserName'];
750 -
751 -
752 - if(!isset($query->fieldDictionary[$column]))
753 - continue;
754 - $field=$query->fieldDictionary[$column];
755 - if($field['ClassName']=='rednaosurveytable')
756 - {
757 - $raw=$row[$column]['raw'];
758 - foreach($field['Rows'] as $fieldRow)
759 - {
760 - $value='';
761 - if(isset($raw['values'])&&is_array($raw['values']))
762 - {
763 - foreach($raw['values'] as $surveyRow)
764 - {
765 - if(isset($surveyRow['QuestionLabel'])&&$surveyRow['QuestionLabel']==$fieldRow['label']){
766 - $value=$surveyRow['ValueLabel'];
767 - }
768 - }
769 - }
770 -
771 - $csvRow[]=str_replace(array("\n", "\r"), ' ', $value);
772 - }
773 - }else
774 - $csvRow[]=str_replace(array("\n", "\r"), ' ', $row[$column]['plain']);
775 - }
776 - fputcsv($fh,$csvRow);
777 - }
778 -
779 - die();
780 -
781 -
782 -}
783 -
784 -function rednao_smart_forms_edit_form_values()
785 -{
786 - $entryId=GetPostValue("entryId");
787 - $entryString=GetPostValue("entryString");
788 - $elementOptions=GetPostValue("elementOptions");
789 - $nonce=GetPostValue("nonce");
790 -
791 - if(!wp_verify_nonce($nonce,'smart_forms_edit_values')||!current_user_can('edit_pages'))
792 - {
793 - echo json_encode(array('result'=>false));
794 - die();
795 -
796 - }
797 -
798 -
799 -
800 - include_once(SMART_FORMS_DIR.'php_classes/save/php_entry_editor.php');
801 - $phpEditor=new php_entry_editor();
802 - echo json_encode(array('result'=>$phpEditor->execute_editor($entryId,$entryString,$elementOptions)));
803 - die();
804 -}
805 -
806 -function rednao_smart_forms_get_file(){
807 - if(!isset($_GET['id']))
808 - {
809 - echo "Invalid request";
810 - die();
811 - }
812 - $id=sanitize_text_field($_GET['id']);
813 - global $wpdb;
814 - $result=$wpdb->get_row($wpdb->prepare('select original_name,file_name,file_mime from '.SMART_FORMS_UPLOADED_FILES.' where file_key=%s',$id));
815 - if($result==false)
816 - {
817 - echo 'File not found';
818 - die();
819 - }
820 - header('Content-type: '.$result->file_mime);
821 - header('Content-Disposition: attachment; filename="'.$result->original_name.'"');
822 - readfile($result->file_name);
823 - die();
824 -}
825 -
826 -function rednao_smart_forms_update_order()
827 -{
828 - if(!isset($_POST['nonce'])||!wp_verify_nonce($_POST['nonce'],'smart_forms_update_order')||!current_user_can('manage_options'))
829 - {
830 - echo json_encode(array(
831 - 'success'=>false,
832 - 'errorMessage'=>'Invalid Request'
833 - ));
834 - die();
835 - }
836 -
837 - if(!isset($_POST['order'])||!is_array($_POST['order']))
838 - {
839 - echo json_encode(array(
840 - 'success'=>false,
841 - 'errorMessage'=>'Invalid order data'
842 - ));
843 - die();
844 - }
845 -
846 - global $wpdb;
847 - $order=array_map('intval',$_POST['order']);
848 -
849 - foreach($order as $position=>$form_id)
850 - {
851 - $wpdb->update(
852 - SMART_FORMS_TABLE_NAME,
853 - array('form_order'=>$position),
854 - array('form_id'=>$form_id),
855 - array('%d'),
856 - array('%d')
857 - );
858 - }
859 -
860 - echo json_encode(array(
861 - 'success'=>true
862 - ));
863 342 die();
864 343 }