PluginProbe
WP Zoho for Contact Form 7, WPForms, Elementor, Formidable and Ninja Forms – CRM, Bigin / trunk
WP Zoho for Contact Form 7, WPForms, Elementor, Formidable and Ninja Forms – CRM, Bigin vtrunk
trunk 1.0 1.0.2 1.0.3 1.0.4 1.0.5 1.1.2 1.1.4 1.1.5 1.2.4 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3
cf7-zoho / cf7-zoho.php

cf7-zoho.php in WP Zoho for Contact Form 7, WPForms, Elementor, Formidable and Ninja Forms – CRM, Bigin trunk, at cf7-zoho.php

2,074 lines 65.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WP Contact Form Zoho
4 * Description: Integrates Contact Form 7, <a href="https://wordpress.org/plugins/contact-form-entries/">Contact Form Entries Plugin</a> and many other forms with Zoho allowing form submissions to be automatically sent to your Zoho account
5 * Version: 1.3.3
6 * Requires at least: 3.8
7 * Author URI: https://www.crmperks.com
8 * Plugin URI: https://www.crmperks.com/plugins/contact-form-plugins/contact-form-zoho-plugin/
9 * Author: CRM Perks
10 * Text Domain: contact-form-zoho
11 * Domain Path: /languages/
12 */
13 // Exit if accessed directly
14 if( !defined( 'ABSPATH' ) ) exit;
15
16
17 if( !class_exists( 'vxcf_zoho' ) ):
18
19 class vxcf_zoho {
20
21
22 public $url = "https://www.crmperks.com";
23
24 public $crm_name = "zoho";
25 public $id = "vxcf_zoho";
26 public $domain = "vxcf-zoho";
27 public $version = "1.3.3";
28 public $update_id = "6000001";
29 public $min_cf_version = "1.0";
30 public $type = "vxcf_zoho";
31 public $fields = null;
32 public $form_fields = null;
33 public $data = null;
34
35 private $filter_condition;
36 private $plugin_dir= "";
37 private $temp;
38 private $crm_arr= false;
39 public $notice_js= false;
40 public static $title='Contact Form Zoho Plugin';
41 public static $path = '';
42 public static $slug = "";
43 public static $debug_html = '';
44 public static $save_key='';
45 public static $lic_msg = "";
46 public static $db_version='';
47 public static $vx_plugins;
48 public static $note;
49 public static $feeds_res;
50 public static $cf_status='';
51 public static $cf_status_msg='';
52 public static $tooltips;
53 public static $entry_created=false;
54 public static $plugin;
55 public static $is_pr;
56 public static $api_timeout;
57
58 public function instance(){
59 add_action( 'plugins_loaded', array( $this, 'setup_main' ) );
60 register_deactivation_hook(__FILE__,array($this,'deactivate'));
61 register_activation_hook(__FILE__,(array($this,'activate')));
62
63
64
65 }
66
67 public function init(){
68 /* self::$cf_status= $this->cf_status();
69 if(self::$cf_status !== 1){
70 add_action( 'admin_notices', array( $this, 'install_cf_notice' ) );
71 add_action( 'after_plugin_row_'.self::$slug, array( $this, 'install_cf_notice_plugin_row' ) );
72 return;
73 }
74 */
75
76 $pro_file=self::$path . 'wp/crmperks-notices.php';
77 if(file_exists($pro_file)){
78 include_once($pro_file);
79 }else{
80 //plugin api
81 $this->plugin_api(true);
82 self::$is_pr=true;
83 $pro_file=self::$path . 'pro/add-ons.php';
84 if(file_exists($pro_file)){
85 include_once($pro_file);
86 } }
87
88 require_once(self::$path . "includes/crmperks-cf.php");
89 require_once(self::$path . "includes/plugin-pages.php");
90
91 }
92
93 /**
94 * create tables and roles
95 *
96 */
97 public function setup_main(){
98
99
100 add_action('cfx_form_submitted', array($this, 'entry_created_crmperks'),10,3);
101 add_action('vxcf_entry_created', array($this, 'entry_created'),10,3);
102 add_action('vx_contact_created', array($this, 'entry_created_contacts'),10,3);
103 add_action('vx_callcenter_entry_created', array($this, 'entry_created_callcenter'),10,3);
104
105 //add_filter('wpcf7_before_send_mail', array($this, 'create_entry_cf'),99);
106 //formidable
107 add_action('wpcf7_mail_sent', array($this, 'create_entry_cf'), 99);
108 add_action('frm_after_create_entry', array($this, 'create_entry_fd'), 99, 2);
109 add_action('ninja_forms_after_submission', array($this, 'create_entry_na'),99);
110 add_action( 'wpforms_process_entry_save',array(&$this,'create_entry_wp'), 99, 4 );
111 //elemntor form
112 add_action( 'elementor_pro/forms/new_record', array($this,'create_entry_el'), 99 );
113
114 if(is_admin()){
115 self::$path=$this->get_base_path();
116 add_action('init', array($this,'init'));
117 //loading translations
118 //load_plugin_textdomain('contact-form-zoho-crm', FALSE, $this->plugin_dir_name(). '/languages/' );
119 $this->maybe_install(true);
120 }
121
122 }
123
124 public function plugin_api($start_instance=false){
125 if(empty(self::$path)){ self::$path=$this->get_base_path(); }
126 $api_file=self::$path . "pro/plugin-api.php";
127 if(!class_exists('vxcf_plugin_api') && file_exists( $api_file)){
128 require_once( $api_file );
129 }
130 if(class_exists('vxcf_plugin_api')){
131 $slug=$this->get_slug();
132 $settings_link=$this->link_to_settings();
133 $is_plugin_page=$this->is_crm_page();
134 self::$plugin=new vxcf_plugin_api($this->id,$this->version,$this->type,$this->domain,$this->update_id,self::$title,$slug,self::$path,$settings_link,$is_plugin_page);
135 if($start_instance){
136 self::$plugin->instance();
137 }
138 } }
139 /**
140 * create tables and roles
141 *
142 */
143 public function maybe_install($version_check=false){
144
145 if(current_user_can( 'manage_options' )){
146 self::$db_version=get_option($this->type."_version");
147 $do_install=false;
148 if($version_check == false){
149 $do_install=true;
150 }else if(self::$db_version != $this->version){
151 $do_install=true;
152 }
153 if($do_install){
154 $data=$this->get_data_object();
155 $data->update_table();
156 update_option($this->type."_version", $this->version);
157 //add post permissions
158 require_once(self::$path . "includes/install.php");
159 $install=new vxcf_zoho_install();
160 $install->create_roles();
161 }
162 }
163 }
164 public function form_submitted($form){
165
166 //entries plugin exists , do not use this hook
167 if(class_exists('vxcf_form')){ return; }
168 $form_id=$form->id();
169 $submission = WPCF7_Submission::get_instance();
170
171 $lead = $submission->uploaded_files();
172 if(!is_array($lead)){ $lead=array(); }
173 $form_title=$form->title();
174 $tags=array();
175
176 if(method_exists('WPCF7_ShortcodeManager','get_instance') || method_exists('WPCF7_FormTagsManager','get_instance')){
177
178 $form_text=get_post_meta($form_id ,'_form',true);
179
180 if(method_exists('WPCF7_FormTagsManager','get_instance')){
181 $manager=WPCF7_FormTagsManager::get_instance();
182 $contents=$manager->scan($form_text);
183 $tags=$manager->get_scanned_tags();
184
185 }else if(method_exists('WPCF7_ShortcodeManager','get_instance')){ //
186 $manager = WPCF7_ShortcodeManager::get_instance();
187 $contents=$manager->do_shortcode($form_text);
188 $tags=$manager->get_scanned_tags();
189 } }
190
191
192 if(is_array($tags)){
193 foreach($tags as $k=>$v){
194 if(!empty($v['name'])){
195 $name=$v['name'];
196 $val=$submission->get_posted_data($name);
197
198 if( !empty($val) && $v['basetype'] == 'mfile' && function_exists('dnd_get_upload_dir') ){
199 $dir=dnd_get_upload_dir();
200 $f_arr=array();
201 foreach($val as $file){
202 $file_name=explode('/',$file);
203 if(count($file_name)>1){
204 $f_arr[]=$dir['upload_url'].'/'.$file_name[1];
205 }
206 }
207 $val=$f_arr;
208 }
209 if(!isset($lead[$name])){ $lead[$name]=wp_unslash($val); }
210
211 } }
212 }
213
214 $form_arr=array('id'=>'cf_'.$form_id,'name'=>$form_title,'fields'=>$tags);
215 $this->entry_created($lead,'0',$form_arr);
216
217 }
218 public function create_entry_cf($form){
219 if(class_exists('vxcf_form')){ return; }
220 $form_id=$form->id();
221
222 $submission = WPCF7_Submission::get_instance();
223 $uploaded_files = $submission->uploaded_files();
224
225 $form_title=$form->title();
226 $tags=$this->get_form_fields('cf_'.$form_id);
227 $post_data=$submission->get_posted_data();
228 //var_dump($post_data); die();
229 $lead=array();
230 if(is_array($post_data)){
231 foreach($post_data as $k=>$val){
232 if(in_array($k,array('vx_width','vx_height','vx_url','g-recaptcha-response'))){ continue; }
233 if(isset($tags[$k])){
234 $v=$tags[$k]; //$v is empty for non form fields
235 }
236 $name=$k; //$v['name'] //if empty then $v is old
237 //var_dump($v);
238 if(isset($uploaded_files[$name])){
239 $val=$uploaded_files[$name];
240 }
241
242 if( !empty($val) && isset($v['basetype']) && $v['basetype'] == 'mfile' && function_exists('dnd_get_upload_dir') ){
243 $dir=dnd_get_upload_dir();
244 $f_arr=array();
245 foreach($val as $file){
246 $file_name=explode('/',$file);
247 if(count($file_name)>1){
248 $f_arr[]=$dir['upload_url'].'/'.end($file_name);
249 }
250 }
251 $val=$f_arr;
252 }
253 if(!isset($uploaded_files[$name])){
254 $val=wp_unslash($val);
255 }
256 $lead[$k]=$val;
257 }
258 }
259 //var_dump($lead,$post_data); die('-----------');
260 $form_arr=array('id'=>'cf_'.$form_id,'name'=>$form_title,'fields'=>$tags);
261 $this->entry_created($lead,'0',$form_arr);
262
263 }
264 public function create_entry_na($data){
265 if(class_exists('vxcf_form')){ return; }
266 $form_id=$data['form_id'];
267
268
269 if(empty($data['form_id'])){
270 return;
271 }
272
273 $form_title=$data['settings']['title'];
274 $lead=$upload_files=array();
275 if(!empty($data['fields'])){
276 foreach($data['fields'] as $v){
277 $field_id=$v['id'];
278 if(!empty($v['value'])){
279 if($v['type'] == 'file_upload'){
280 $upload_files[$field_id]=$v['value'];
281 }else{
282 $lead[$field_id]=$v['value'];
283 }
284 }
285 }
286
287 if(is_array($upload_files)){
288 foreach($upload_files as $k=>$v){
289 $lead[$k]=$v;
290 }
291 }
292 $form_arr=array('id'=>'na_'.$form_id,'name'=>$form_title,'fields'=>$data['fields']);
293 $this->entry_created($lead,'0',$form_arr);
294
295 }
296 }
297
298 public function create_entry_wp($fields, $entry, $form_id, $form_data){
299 if(class_exists('vxcf_form')){ return; }
300
301
302 $upload_files=$lead=array();
303 if(!empty($fields)){
304 foreach($fields as $v){
305 if($v['type'] == 'file-upload'){
306 $v['value']=array_map('trim',explode("\n",$v['value']));
307 $upload_files[$v['id']]=$v['value'];
308 }else{
309 $val=$v['value'];
310 if(in_array($v['type'],array('payment-select','payment-multiple'))){
311 $val=$v['amount'];
312 }else if($v['type'] == 'checkbox'){
313 $val=array_map('trim',explode("\n",$val));
314 }
315 $lead[$v['id']]=$val;
316 } }
317
318
319 if(is_array($upload_files)){
320 foreach($upload_files as $k=>$v){
321 $lead[$k]=$v;
322 } }
323
324 $form_arr=array('id'=>'wp_'.$form_data['id'],'name'=>'WP Forms','fields'=>$form_data['fields']);
325 if(!empty($form_data['fields']['settings']['form_title'])){
326 $form_arr['name']=$form_data['fields']['settings']['form_title'];
327 }
328 $id=isset($entry['id']) ? $entry['id'] : '0';
329 $this->entry_created($lead,$id,$form_arr);
330 }
331 //var_dump($fields); die();
332 }
333 public function create_entry_el( $record){
334 if(class_exists('vxcf_form')){ return; }
335 $data=$record->get_formatted_data();
336 $form_id_p=$this->post('form_id');
337 $post_id_p=$this->post('post_id');
338
339 $form_id=$form_id_p.'_'.$post_id_p;
340
341 $fields=$this->get_form_fields('el_'.$form_id);
342 $upload_files=$lead=array();
343 if(!empty($fields)){
344 foreach($fields as $v){
345 if(isset($data[$v['label']])){
346 $val=$data[$v['label']];
347 if($v['type'] == 'upload'){
348 $upload_files[$v['id']]=$val;
349 }else{
350
351 if(in_array($v['type'],array('checkbox','multiselect'))){
352 $val=array_map('trim',explode(',',$val));
353 }
354 $lead[$v['id']]=$val;
355 } } }
356
357 if(is_array($upload_files)){
358 foreach($upload_files as $k=>$v){
359 $lead[$k]=$v;
360 } }
361 //var_dump($lead,$data); die();
362 $form_arr=array('id'=>'el_'.$form_id,'name'=>'Elementor Forms','fields'=>$fields);
363 $this->entry_created($lead,'0',$form_arr);
364
365 }
366 //var_dump($fields); die();
367 }
368 public function create_entry_fd($entry_id,$form_id){
369 if(class_exists('vxcf_form')){ return; }
370
371 $fields=$this->get_form_fields('fd_'.$form_id);
372 global $wpdb;
373 $table=$wpdb->prefix.'frm_item_metas';
374 $sql=$wpdb->prepare("Select * from $table where item_id=%d",$entry_id);
375 $entry=$wpdb->get_results($sql,ARRAY_A);
376 $detail=array();
377 if(is_array($entry) && count($entry)>0){
378 foreach($entry as $v){
379 $detail[$v['field_id']]=$v['meta_value'];
380 }
381 }
382 //var_dump($tags); die();
383 $lead=array();
384 if(is_array($fields)){
385 $uploaded_files_form=array();
386 foreach($fields as $k=>$v){
387
388 $name=$v['name'];
389 if(isset($detail[$name])){
390 $val=$detail[$name];
391 if(is_serialized($val)){
392 $val=unserialize($val, array('allowed_classes' => false));
393 }
394 if($v['type'] == 'file'){
395 $val= wp_get_attachment_url($val) ;
396 $base_url=get_site_url();
397 $val=str_replace($base_url,trim(ABSPATH,'/'),$val);
398 $uploaded_files_form[$name]=$val;
399 }
400 $lead[$name]=$detail[$name];
401 }
402 }
403 //
404
405 if(is_array($uploaded_files_form)){
406 foreach($uploaded_files_form as $k=>$v){
407 $lead[$k]=$v;
408 }
409 }
410 }
411 global $wpdb;
412 $table=$wpdb->prefix.'frm_forms';
413 $sql=$wpdb->prepare("Select name from $table where id=%d",$form_id);
414 $form_name=$wpdb->get_var($sql);
415 $form_arr=array('id'=>'fd_'.$form_id,'name'=>$form_name,'fields'=>$fields);
416 $this->entry_created($lead,'0',$form_arr);
417 }
418
419 /**
420 * contact form entry created
421 *
422 * @param mixed $entry
423 * @param mixed $form
424 */
425 public function entry_created($entry,$entry_id,$form){
426
427 self::$entry_created=true;
428
429 if($this->do_actions()){
430 do_action('vx_addons_save_entry',$entry_id,$entry,'cf',$form);
431 }
432
433 $entry['__vx_id']=$entry_id;
434 $this->push($entry,$form,'submit',false);
435 }
436 public function entry_created_crmperks($entry_id,$entry,$form){
437 self::$entry_created=true;
438 if($this->do_actions()){
439 do_action('vx_addons_save_entry',$entry_id,$entry,'vf',$form);
440 }
441
442 $form['id']='vf_'.$form['id'];
443 $form['cfx_type']='vf';
444 $entry['__vx_id']=$entry_id;
445 $this->push($entry,$form,'',false);
446 }
447 public function entry_created_contacts($entry,$entry_id,$form){
448
449 if($this->do_actions()){
450 do_action('vx_addons_save_entry',$entry_id,$entry,'cc',$form);
451 }
452
453 $entry['__vx_id']=$entry_id;
454 $this->push($entry,$form,'',false);
455 }
456 public function entry_created_callcenter($entry,$entry_id,$form){
457 $this->push($entry,$form,'',false);
458 }
459
460 /**
461 * Install Contact Form Notice
462 *
463 */
464 public function install_cf_notice(){
465 $message=self::$cf_status_msg;
466 if(!empty($message)){
467 $this->display_msg('admin',$message,'gravity');
468 $this->notice_js=true;
469
470 }
471 }
472 public function submit(){
473 $entry='{"your-name":"Your Name (required)","your-email":"admin@localhost.com","your-subject":"subject test","your-message":"sdfsdfsdfsdf","your-country":["India"],"your-sports":["Tennis"],"your-fruit":["Banana"],"your-browser":"Safari","your-file":""}';
474 $form='{"id":69,"name":"Contact form 1"}';
475 $entry=json_decode($entry,true);
476 $form=json_decode($form,true);
477 apply_filters('vx_addons_save_entry',false,$entry_id,$entry,'cf',$form);
478 $entry['__vx_id']="1";
479 $p=$this->push($entry,$form);
480 var_dump($p); die();
481 }
482
483 /**
484 * Install Contact Form Notice (plugin row)
485 *
486 */
487 public function install_cf_notice_plugin_row(){
488 $message=self::$cf_status_msg;
489 if(!empty($message)){
490 $this->display_msg('',$message,'gravity');
491 }
492 }
493 /**
494 * display admin notice
495 *
496 * @param mixed $type
497 * @param mixed $message
498 * @param mixed $id
499 */
500 public function display_msg($type,$message,$id=""){
501 //exp
502 global $wp_version;
503 $ver=floatval($wp_version);
504 if($type == "admin"){
505 if($ver<4.2){
506 ?>
507 <div class="error vx_notice notice" data-id="<?php echo esc_attr($id) ?>"><p style="display: table"><span style="display: table-cell; width: 98%"><span class="dashicons dashicons-megaphone"></span> <b><?php esc_html_e('Contact Form Zoho Plugin','contact-form-zoho-crm') ?>. </b><?php echo wp_kses_post($message);?> </span>
508 <span style="display: table-cell; padding-left: 10px; vertical-align: middle;"><a href="#" class="notice-dismiss" title="<?php esc_html_e('Dismiss Notice','contact-form-zoho-crm') ?>">dismiss</a></span> </p></div>
509 <?php
510 }else{
511 ?>
512 <div class="error vx_notice notice below-h2 is-dismissible" data-id="<?php echo esc_attr($id) ?>"><p><span class="dashicons dashicons-megaphone"></span> <b><?php esc_html_e('Contact Form Zoho Plugin','contact-form-zoho-crm') ?>. </b> <?php echo wp_kses_post($message);?> </p>
513 </div>
514 <?php
515 }
516 }else{
517 ?>
518 <tr class="plugin-update-tr"><td colspan="5" class="plugin-update">
519 <style type="text/css"> .vx_msg a{color: #fff; text-decoration: underline;} .vx_msg a:hover{color: #eee} </style>
520 <div style="background-color: rgba(224, 224, 224, 0.5); padding: 9px; margin: 0px 10px 10px 28px "><div style="background-color: #d54d21; padding: 5px 10px; color: #fff" class="vx_msg"> <span class="dashicons dashicons-info"></span> <?php echo wp_kses_post($message) ?>
521 </div></div></td></tr>
522 <?php
523 }
524 }
525 /**
526 * admin_screen_message function.
527 *
528 * @param mixed $message
529 * @param mixed $level
530 */
531 public function screen_msg( $message, $level = 'updated') {
532 echo '<div class="'. esc_attr( $level ) .' notice below-h2 is-dismissible"><p>';
533 echo wp_kses_post($message) ;
534 echo '</p></div>';
535 }
536
537 /**
538 * Contact Form status
539 *
540 */
541 public function cf_status() {
542
543 $installed = 0;
544 if(!class_exists('vxcf_form')) {
545 if(file_exists(WP_PLUGIN_DIR.'/contact-form-entries-pro/contact-form-entries-pro.php')) {
546 $installed=2;
547 }
548 }else{
549 $installed=1;
550 if(!$this->is_cf_supported()){
551 $installed=3;
552 }
553 }
554 if($installed !=1){
555 if($installed === 0){ // not found
556 $message = sprintf(__("%sContact Form Entries%s is required. %s it today!%s", 'contact-form-zoho-crm'), "<a href='https://www.crmperks.com/'>", "</a>", "<a href='https://www.crmperks.com/'>", "</a>");
557 }else if($installed === 2){ // not active
558 $message = sprintf(__('Contact Form Entries is installed but not active. %sActivate Contact Form Entries%s to use the Contact Form Zoho Plugin','contact-form-zoho-crm'), '<strong><a href="'.wp_nonce_url(admin_url('plugins.php?action=activate&plugin=contact-form-entries-pro/contact-form-entries-pro.php'), 'activate-plugin_contact-form-entries-pro/contact-form-entries-pro.php').'">', '</a></strong>');
559 } else if($installed === 3){ // not supported
560 $message = sprintf(__("A higher version of %sContact Form Entries%s is required. %sPurchase it today!%s", 'contact-form-zoho-crm'), "<a href='https://www.crmperks.com/'>", "</a>", "<a href='https://www.crmperks.com/'>", "</a>");
561 }
562 self::$cf_status_msg=$message;
563 }
564 return $installed;
565 }
566
567
568 /**
569 * Returns true if the current page is an Feed pages. Returns false if not
570 *
571 * @param mixed $page
572 */
573 public function is_crm_page($page=""){
574 if(empty($page)) {
575 $page = $this->post("page");
576 }
577 return $page == $this->id;
578 }
579
580
581 /**
582 * form fields
583 *
584 * @param mixed $form_id
585 */
586 public function get_form_fields($form_id){
587 $fields=array();
588
589 $fields=apply_filters('vx_add_crm_form_fields',$fields,$form_id);
590 if(empty($fields)){
591 global $vxcf_form;
592
593 if(is_object($vxcf_form) && method_exists($vxcf_form,'get_form_fields')){
594 $fields=$vxcf_form->get_form_fields($form_id);
595 }else{
596
597 $form_arr=explode('_',$form_id);
598 $type=$id='';
599 $fields = array();
600 if(isset($form_arr[0])){
601 $type=$form_arr[0];
602 }
603 if(isset($form_arr[1])){
604 $id=$form_arr[1];
605 }
606 switch($type){
607 case'cf':
608 if(method_exists('WPCF7_ShortcodeManager','get_instance') || method_exists('WPCF7_FormTagsManager','get_instance')){
609 $id=substr($form_id,3);
610 $form_text=get_post_meta($id,'_form',true);
611
612 if(method_exists('WPCF7_FormTagsManager','get_instance')){
613 $manager=WPCF7_FormTagsManager::get_instance();
614 $contents=$manager->scan($form_text);
615 $tags=$manager->get_scanned_tags();
616
617 }else if(method_exists('WPCF7_ShortcodeManager','get_instance')){ //
618 $manager = WPCF7_ShortcodeManager::get_instance();
619 $contents=$manager->do_shortcode($form_text);
620 $tags=$manager->get_scanned_tags();
621 }
622
623 if(is_array($tags)){
624 foreach($tags as $tag){
625 if(is_object($tag)){ $tag=(array)$tag; }
626 if(!empty($tag['name'])){
627 $id=str_replace(' ','',$tag['name']);
628 $tag['label']=ucwords(str_replace(array('-','_')," ",$tag['name']));
629 $tag['type_']=$tag['type'];
630 $tag['type']=$tag['basetype'];
631 $tag['req']=strpos($tag['type'],'*') !==false ? 'true' : '';
632 if($tag['type'] == 'select' && !empty($tag['options']) && array_search('multiple',$tag['options'])!== false){
633 $tag['type']='multiselect';
634 }
635 $fields[$id]=$tag;
636 }
637 }
638 }
639 }
640 break;
641 case'na':
642 if(class_exists('Ninja_Forms')){
643
644 $form_fields = Ninja_Forms()->form( $id )->get_fields(); //var_dump($form_fields); die('----------');
645 foreach ($form_fields as $obj) {
646 $field=array();
647 if( is_object( $obj ) ) {
648 $field = $obj->get_settings();
649 $field['id']= $obj->get_id();
650 }
651
652 $arr=array('name'=>$field['id']);
653 $type=$field['type'];
654 if($type == 'textbox'){ $type='text'; }
655 if($type == 'starrating'){ $type='text'; }
656 if($type == 'file_upload'){ $type='file'; }
657 if(in_array($type,array('spam','confirm','submit','repeater','save','html','hr')) ){ continue; } //|| !isset($field['required']) // it is not set for hidden fields that is why removed it
658 if($type == 'checkbox'){
659 $arr['values']=array(array('text'=>$field['label'],'value'=>'1'));
660 }
661 if(in_array($type,array('listmultiselect','listcheckbox','listradio','listselect'))){
662 $type=ltrim($type,'list');
663 $vals=array();
664 if(!empty($field['options'])){
665 foreach($field['options'] as $v){
666 $vals[]=array('text'=>$v['label'],'value'=>$v['value']);
667 }
668 }
669 $arr['values']=$vals;
670 }
671
672 $arr['type']=$type;
673 $arr['label']=$field['label'];
674 $arr['req']=!empty($field['required']) ? 'true' : 'false';
675 $fields[$field['id']]=$arr;
676 }
677 }
678 break;
679 case'el':
680 if(isset($form_arr[2])){
681 $post_id=$form_arr[2];
682 $forms=get_post_meta($post_id,'_elementor_data',true);
683 $forms=json_decode($forms,true);
684 if(!empty($forms)){
685 $form=self::find_el_form($forms,$id);
686
687 if(!empty($form['form_fields'])){
688 foreach($form['form_fields'] as $tag){
689 if(!empty($tag['custom_id']) ){
690 if(empty($tag['field_type'])){ $tag['field_type']=$tag['custom_id']; }
691 if(!in_array($tag['field_type'],array('html','step','honeypot','recaptcha','recaptcha_v3'))){
692 $field=array('id'=>$tag['custom_id']);
693 $field['name']=$tag['custom_id'];
694 $field['label']=$tag['field_label'];
695 $field['type']=$tag['field_type'];
696 $field['req']=!empty($tag['required']) ? 'true' : '';
697 if(!empty($tag['allow_multiple']) ){
698 $field['type']='multiselect';
699 }
700 if($field['type'] == 'acceptance'){
701 $field['type']='checkbox';
702 $field['values']=array(array('label'=>$tag['acceptance_text'],'value'=>'on'));
703 }
704 if($field['type'] == 'upload'){
705 $field['type']='file';
706 }
707 if(!empty($tag['field_options'])){
708 $opts_array=explode("\n",$tag['field_options']);
709 $ops=array();
710 foreach($opts_array as $v){
711 $v_arr=explode('|',$v);
712 if(!isset($v_arr[1])){ $v_arr[1]=$v_arr[0]; }
713 $ops[]=array('label'=>$v_arr[0],'value'=>$v_arr[1]);
714 }
715 $field['values']=$ops;
716 }
717 $fields[$tag['custom_id']]=$field;
718 } }
719 }
720 }
721 }
722
723 }
724 break;
725 case'fd':
726 global $wpdb;
727 $table=$wpdb->prefix.'frm_fields';
728 $sql=$wpdb->prepare("Select * from $table where form_id=%d",$id);
729 $fields_arr=$wpdb->get_results($sql,ARRAY_A);
730 if(count($fields_arr)>0){
731 foreach($fields_arr as $field){
732 $field['label']=$field['name'];
733 $field['name']=$field['id'];
734 if(!empty($field['options'])){
735 $field['values']=maybe_unserialize($field['options']);
736 }
737 $fields[$field['id']]=$field;
738 }
739 }
740 break;
741 case'wp':
742 if(function_exists('wpforms') && method_exists(wpforms()->form,'get')){
743 $forms_arr=wpforms()->form->get( $id );
744 if(!empty($forms_arr)){
745 $form=json_decode($forms_arr->post_content,true);
746 $fields=array();
747 foreach($form['fields'] as $v){
748 $type=$v['type'];
749 if($type == 'name'){ $type='text'; }
750 if($type == 'payment-select'){ $type='select'; }
751 if($type == 'payment-multiple'){ $type='radio'; }
752 if($type == 'payment-single'){ $type='text'; }
753 if($type == 'file-upload'){ $type='file'; }
754 if($type == 'date-time'){ $type='date'; }
755 if($type == 'address'){ $type='textarea'; }
756 if($type == 'phone'){ $type='tel'; }
757 $label=isset($v['label']) ? $v['label'] : $type;
758 // if(in_array($type,array('text','textarea','email','number','hidden','select','checkbox','radio','url','password','tel','date','file','number-slider'))){
759 $field=array('id'=>$v['id'],'name'=>$v['id'],'label'=>$label,'type'=>$type);
760 $field['req']=!empty($v['required']) ? true : false;
761 if(in_array($type,array('radio','checkbox','select'))){
762 $is_val=false;
763 if(in_array($v['type'],array('payment-select','payment-multiple'))){ $is_val=true; }
764 $choices=array();
765 if(!empty($v['choices'])){
766 foreach($v['choices'] as $c){
767 $c_val=$is_val ? $c['value'] : $c['label'];
768 $choices[]=array('text'=>$c['label'],'value'=>$c_val);
769 }
770 }
771 $field['values']=$choices;
772 }
773 $fields[$v['id']]=$field;
774 // }
775
776 }
777 } } //var_dump($form['fields']);
778 break;
779 }
780 }
781 }
782 return $fields;
783
784
785 }
786 public static function find_el_form($var,$key=''){
787
788 if(is_array($var) && isset($var[0]) ){
789 foreach($var as $v){
790 if (!empty($v['elements']) && is_array( $v['elements'] ) ) {
791 $se=self::find_el_form($v['elements'],$key);
792 if(!empty($se)){ return $se; }
793 }
794 if($v['id'] == $key){ // var_dump($v); echo '----<hr>';
795 return $v['settings'];
796 }
797 }
798
799 }
800 }
801 public static function find_el_forms($var,&$forms=array()){
802
803 if(is_array($var) && isset($var[0]) ){
804 foreach($var as $v){
805 if(isset($v['widgetType']) && $v['widgetType'] == 'form'){
806 $forms[]= $v;
807 }
808 if (!empty($v['elements']) && is_array( $v['elements'] ) ) {
809 self::find_el_forms($v['elements'],$forms);
810 }
811
812 }
813
814 }
815 return $forms;
816 }
817 public function get_form($form_id){
818
819 $title='Contacts Addon';
820 if($form_id !='vx_contacts'){
821 global $vxcf_form;
822 if(is_object($vxcf_form) && method_exists($vxcf_form,'get_forms')){
823 $forms=$vxcf_form->get_forms();
824 if(is_array($forms) && count($forms)>0){
825 foreach($forms as $key=>$vals){
826 $found=false;
827 if(!empty($vals['forms']) && is_array($vals['forms'])){
828 foreach($vals['forms'] as $k=>$v){
829 $f_id=$key.'_'.$k;
830 if($f_id == $form_id){
831 $found=true;
832 if(!empty($v)){
833 $title=$v;
834 }
835 break;
836 }
837 }
838 }
839 if($found){
840 break;
841 }
842 }
843 }
844 }
845 }
846 $form=array('id'=>$form_id,'title'=>$title,'name'=>$title);
847
848 return $form;
849 }
850
851
852 /**
853 * settings link
854 *
855 * @param mixed $escaped
856 */
857 public function link_to_settings( $tab='' ) {
858 $q=array('page'=>$this->id);
859 if(!empty($tab)){
860 $q['tab']=$tab;
861 }
862 $url = admin_url('admin.php?'.http_build_query($q));
863
864 return $url;
865 }
866
867
868 /**
869 * Get CRM info
870 *
871 */
872 public function get_info($id){
873 $data=$this->get_data_object();
874 $info=$data->get_account($id);
875 $data=array(); $meta=$info_arr=array();
876 if(is_array($info)){
877 if(!empty($info['data'])){
878 $info['data']=trim($info['data']);
879 if(strpos($info['data'],'{') !== 0){
880 $info['data']=$this->de_crypt($info['data']);
881 }
882 $info_arr=json_decode($info['data'],true);
883 if(!is_array($info_arr)){
884 $info_arr=array();
885 }
886 }
887
888 $info_arr['time']=$info['time'];
889 $info_arr['id']=$info['id'];
890 $info['data']=$info_arr;
891 if(!empty($info['meta'])){
892 $meta=json_decode($info['meta'],true);
893 }
894 $info['meta']=is_array($meta) ? $meta : array();
895
896 }
897 return $info;
898 }
899 /**
900 * update account
901 *
902 * @param mixed $data
903 * @param mixed $id
904 */
905 public function update_info($data,$id) {
906
907 if(empty($id)){
908 return;
909 }
910
911 $time = current_time( 'mysql' ,1);
912
913 $sql=array('updated'=>$time);
914 if(is_array($data)){
915
916
917 if(isset($data['meta'])){
918 $sql['meta']= json_encode($data['meta']);
919 }
920 if( isset($data['data']) && is_array($data['data'])){
921 $_data=$this->get_data_object();
922 $acount=$_data->get_account($id);
923 if(array_key_exists('time' , $data['data']) && empty($data['data']['time'])){
924 $sql['time']= $time;
925 $sql['status']= '2';
926 }
927 if(isset($data['data']['class'])){
928 $sql['status']= $data['data']['class'] == 'updated' ? '1' : '2';
929 }
930 if(isset($data['data']['meta'])){
931 unset($data['data']['meta']);
932 }
933 if(isset($data['data']['status'])){
934 unset($data['data']['status']);
935 }
936 if(isset($data['data']['name'])){
937 $sql['name']=$data['data']['name'];
938 // unset($data['data']['name']);
939 }else if(isset($_GET['id'])){
940 $sql['name']="Account #".$this->post('id');
941 }
942
943 $enc_str=json_encode($data['data']);
944 //$enc_str=$this->en_crypt($enc_str);
945 $sql['data']=$enc_str;
946 }
947 }
948
949 $data=$this->get_data_object();
950 $result = $data->update_info_data($sql,$id);
951
952
953 return $result;
954 }
955
956 public function verify_field_val($entry,$field_id,$sf_id=''){
957 $value=false;
958
959
960 if(isset($entry[$field_id])){
961 $value=$entry[$field_id];
962 if(is_array($value) && isset($value['value'])){
963 $value=$value['value'];
964 }
965 if(!is_array($value)){
966 // $value=maybe_unserialize($value);
967 }
968
969 }else if(isset($_REQUEST[$field_id])){
970 $value=$this->post($field_id);
971 }
972
973 $fields=$this->form_fields;
974 $type=isset($fields[$field_id]['type']) ? $fields[$field_id]['type'] : '';
975 if( $type == 'file' && !empty($value)){
976 if(class_exists('vxcf_form')){
977 $upload=vxcf_form::get_upload_dir();
978 $temp_files=array(); $value=maybe_unserialize($value); // mfile field uses serialized
979 if(!is_array($value)){ $value=array($value); }
980 foreach($value as $f){
981 if(filter_var($f,FILTER_VALIDATE_URL) === false){
982 if(strpos($sf_id,'vx_list_files') !== false){
983 $f=$upload['dir'].$f;
984 }else{
985 $f=$upload['url'].$f; //url , dir
986 } }
987 $temp_files[]=$f;
988 } $value=$temp_files;
989 }
990 $value=trim(implode(',',$value)); // api accepts comma
991 }else if( is_array($value) && count($value) == 1 ){
992 $value=trim(implode(' ',$value));
993 }
994
995 return $value;
996 }
997 /**
998 * filter enteries
999 *
1000 * @param mixed $feed
1001 * @param mixed $entry
1002 * @param mixed $form
1003 */
1004 public function check_filter($feed,$entry){
1005 $filters=$this->post('filters',$feed);
1006 $final=$this->filter_condition=null;
1007 if(is_array($filters)){
1008 $time=current_time('timestamp');
1009 foreach($filters as $filter_s){
1010 $check=null; $and=null;
1011 if(is_array($filter_s)){
1012 foreach($filter_s as $filter){
1013 $field=$filter['field'];
1014 $fval=$filter['value'];
1015 $val=$this->verify_field_val($entry,$field);
1016 if(is_array($val)){ $val=trim(implode(' ',$val)); }
1017 switch($filter['op']){
1018 case"is": $check=$fval == $val; break;
1019 case"is_not": $check=$fval != $val; break;
1020 case"contains": $check=strpos($val,$fval) !==false; break;
1021 case"not_contains": $check=strpos($val,$fval) ===false; break;
1022 case"is_in": $check=strpos($fval,$val) !==false; break;
1023 case"not_in": $check=strpos($fval,$val) ===false; break;
1024 case"starts": $check=strpos($val,$fval) === 0; break;
1025 case"not_starts": $check=strpos($val,$fval) !== 0; break;
1026 case"ends": $check=(strpos($val,$fval)+strlen($fval)) == strlen($val); break;
1027 case"not_ends": $check=(strpos($val,$fval)+strlen($fval)) != strlen($val); break;
1028 case"less": $check=(float)$val<(float)$fval; break;
1029 case"greater": $check=(float)$val>(float)$fval; break;
1030 case"less_date": $check=strtotime($val,$time) < strtotime($fval,$time); break;
1031 case"greater_date": $check=strtotime($val,$time) > strtotime($fval,$time); break;
1032 case"equal_date": $check=strtotime($val,$time) == strtotime($fval,$time); break;
1033 case"empty": $check=$val == ""; break;
1034 case"not_empty": $check=$val != ""; break;
1035 }
1036 $and_c[]=array("check"=>$check,"field_val"=>$fval,"input"=>$val,"field"=>$field,"op"=>$filter['op']);
1037 if($check !== null){
1038 if($and !== null){
1039 $and=$and && $check;
1040 }else{
1041 $and=$check;
1042 }
1043 }
1044 } //end and loop filter
1045 }
1046 if($and !== null){
1047 if($final !== null){
1048 $final=$final || $and;
1049 }else{
1050 $final=$and;
1051 }
1052 }
1053 $this->filter_condition[]=$and_c;
1054 } // end or loop
1055 }
1056 return $final === null ? true : $final;
1057 }
1058 /**
1059 * Logs page row
1060 *
1061 * @param mixed $feed
1062 */
1063 public function verify_log($feed){
1064 $link="N/A"; $desc=__("Added to ",'contact-form-zoho-crm');
1065 $status_imgs=array("1"=>"created","2"=>"updated","4"=>"filtered",'5'=>'deleted');
1066 $feed['status_img']=isset($status_imgs[$feed["status"]]) ? $status_imgs[$feed["status"]] : 'failed';
1067 if(!empty($feed['crm_id'])&& !empty($feed['object']) && !empty($feed['status'])){
1068 if(in_array($feed['object'],array('Note','Task'))){
1069 $link=$feed['crm_id'];
1070 }else if(!empty($feed['link'])){
1071 $link='<a href="'.$feed['link'].'" title="'.$feed['crm_id'].'" target="_blank">'.$feed['crm_id'].'</a>';
1072 }else{
1073 $link=$feed['crm_id'];
1074 }
1075 if($feed['status'] == 2){
1076 $desc="Updated to ";
1077 }
1078 $desc.=$feed['object'];
1079 if($feed['status'] == 5){
1080 $desc=sprintf(__("%s Deleted",'contact-form-zoho-crm'),$feed['object']);
1081 }
1082 }else if($feed['status'] == 4){
1083 $desc=sprintf(__("%s Filtered",'contact-form-zoho-crm'),$feed['object']);
1084 }else{
1085 $desc= !empty($feed['error']) ? $feed['error'] : esc_html__("Unknown Error",'contact-form-zoho-crm');
1086 }
1087 $title=__("Failed",'contact-form-zoho-crm');
1088 if($feed['status'] == 1){
1089 $title=__("Created",'contact-form-zoho-crm');
1090 }else if($feed['status'] == 2){
1091 $title=__("Updated",'contact-form-zoho-crm');
1092 }else if($feed['status'] == 4){
1093 $title=__("Filtered",'contact-form-zoho-crm');
1094 }else if($feed['status'] == 5){
1095 $title=__("Deleted",'contact-form-zoho-crm');
1096 }
1097 $feed['_crm_id']= !empty($feed['crm_id']) ? $feed['crm_id'] : "N/A";
1098 $feed['a_link']=$link;
1099 $feed['desc']=$desc;
1100 $feed['title']=$title;
1101 return $feed;
1102 }
1103 /**
1104 * get address components
1105 *
1106 * @param mixed $entry
1107 * @param mixed $field_id
1108 * @param mixed $type
1109 */
1110 private function get_address($entry, $field_id,$type=""){
1111 $street_value = str_replace(" ", " ", trim($entry[$field_id . ".1"]));
1112 $street2_value = str_replace(" ", " ", trim($entry[$field_id . ".2"]));
1113 $city_value = str_replace(" ", " ", trim($entry[$field_id . ".3"]));
1114 $state_value = str_replace(" ", " ", trim($entry[$field_id . ".4"]));
1115 $zip_value = trim($entry[$field_id . ".5"]);
1116 if(method_exists('GF_Field_Address','get_country_code')){
1117 $field_c=new GF_Field_Address();
1118 $country_value=$field_c->get_country_code(trim($entry[$field_id . ".6"]));
1119 }else{
1120 $country_value = GFCommon::get_country_code(trim($entry[$field_id . ".6"]));
1121 }
1122 $country =trim($entry[$field_id . ".6"]);
1123 $address = $street_value;
1124 $address .= !empty($address) && !empty($street2_value) ? " $street2_value" : $street2_value;
1125 if($type =="json"){
1126 $arr=array("street"=>$address,"city"=>$city_value,"state"=>$state_value,"zip"=>$zip_value,"country"=>$country);
1127 return json_encode($arr);
1128 }
1129 $address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? " $city_value" : $city_value;
1130 $address .= !empty($address) && !empty($city_value) && !empty($state_value) ? " $state_value" : $state_value;
1131 $address .= !empty($address) && !empty($zip_value) ? " $zip_value" : $zip_value;
1132 $address .= !empty($address) && !empty($country_value) ? " $country_value" : $country_value;
1133
1134 return $address;
1135 }
1136
1137 /**
1138 * Add checkbox to entry info - option to send entry to crm
1139 *
1140 * @param mixed $form_id
1141 * @param mixed $lead
1142 */
1143 public function entry_info_send_checkbox( $form_id, $lead ) {
1144
1145 // If this entry's form isn't connected to crm, don't show the checkbox
1146 if(!$this->show_send_to_crm_button() ) { return; }
1147
1148 // If this is not the Edit screen, get outta here.
1149 if(empty($_POST["screen_mode"]) || $_POST["screen_mode"] === 'view') { return; }
1150
1151 if(!current_user_can($this->id."_send_to_crm")){return; }
1152
1153 if( apply_filters( $this->id.'_show_manual_export_button', true ) ) {
1154 printf('<input type="checkbox" name="'.esc_attr($this->id).'_update" id="'.esc_attr($this->id).'_update" value="1" /><label for="'.esc_attr($this->id).'_update" title="%s">%s</label><br /><br />', esc_html__('Create or update this entry in Zoho. The fields will be mapped according to the form feed settings.', 'contact-form-zoho-crm'), esc_html__('Send to Zoho', 'contact-form-zoho-crm'));
1155 } else {
1156 echo '<input type="hidden" name="'.esc_attr($this->id).'_update" id="'.esc_attr($this->id).'_update" value="1" />';
1157 }
1158 }
1159 /**
1160 * Add button to entry info - option to send entry to crm
1161 *
1162 * @param mixed $button
1163 */
1164 public function entry_info_send_button( $button = '' ) {
1165 // If this entry's form isn't connected to crm, don't show the button
1166 if(!$this->show_send_to_crm_button()) { return $button; }
1167 if(!current_user_can($this->id."_send_to_crm")){return; }
1168 // Is this the view or the edit screen?
1169 $mode = empty($_POST["screen_mode"]) ? "view" : $this->post("screen_mode");
1170 if($mode === 'view') {
1171 $margin="";
1172 if(defined("vx_btn")){
1173 $margin="margin-top: 5px;";
1174 }else{define('vx_btn','true');}
1175 $button.= '<input type="submit" class="button button-large button-secondary alignright" name="'.esc_attr($this->id).'_send" style="margin-left:5px; '.$margin.'" title="'.__('Create or update this entry in Zoho. The fields will be mapped according to the form feed settings.','contact-form-zoho-crm').'" value="'.__('Send to Zoho', 'contact-form-zoho-crm').'" onclick="jQuery(\'#action\').val(\'send_to_crm\')" />';
1176 //logs button
1177
1178 $entry_id=$this->post('lid');
1179 $form_id = rgget('id');
1180 if(empty($entry_id)){
1181 $entry_id=$this->get_entry_id($form_id);
1182 }
1183 $log_url=admin_url( 'admin.php?page=gf_edit_forms&view=settings&subview='.$this->id.'&tab=log&id='.$this->post('id').'&entry_id='.$entry_id);
1184 $button.= '<a class="button button-large button-secondary alignright" style="margin-left:5px; margin-top:5px; " title="'.__('Go to Zoho Logs','contact-form-zoho-crm').'" href="'.esc_url($log_url).'">'.__('Zoho Logs','contact-form-zoho-crm').'</a>';
1185
1186 }
1187 return $button;
1188 }
1189 /**
1190 * Whether to show the Entry "Send to CRM" button or not
1191 *
1192 * If the entry's form has been mapped to CRM feed, show the Send to CRM button. Otherwise, don't.
1193 *
1194 * @return boolean True: Show the button; False: don't show the button.
1195 */
1196 private function show_send_to_crm_button() {
1197
1198 $form_id = rgget('id');
1199
1200 return $this->has_feed($form_id);
1201 }
1202 /**
1203 * Does the current form have a feed assigned to it?
1204 * @param INT $form_id Form ID
1205 * @return boolean
1206 */
1207 function has_feed($form_id) {
1208 $data=$this->get_data_object();
1209 $feeds = $data->get_feed_by_form( $form_id , true);
1210
1211 return !empty($feeds);
1212 }
1213
1214
1215
1216 /**
1217 * if contact form installed and supported
1218 *
1219 */
1220 private function is_cf_supported(){
1221 if(class_exists("vxcf_form")){
1222 global $vxcf_form;
1223 $version='1.0';
1224 if($vxcf_form->version){
1225 $version=$vxcf_form->version;
1226 }
1227 $is_correct_version = version_compare($version, $this->min_cf_version, ">=");
1228 return $is_correct_version;
1229 }
1230 else{
1231 return false;
1232 }
1233 }
1234 /**
1235 * uninstall plugin
1236 *
1237 */
1238 public function uninstall(){
1239 //droping all tables
1240 require_once(self::$path . "includes/install.php");
1241 $install=new vxcf_zoho_install();
1242 do_action('uninstall_vx_plugin_'.$install->id);
1243 $install->remove_data();
1244 $install->remove_roles();
1245 }
1246 /**
1247 * email validation
1248 *
1249 * @param mixed $email
1250 */
1251 public function is_valid_email($email){
1252 if(function_exists('filter_var')){
1253 if(filter_var($email, FILTER_VALIDATE_EMAIL)){
1254 return true;
1255 }
1256 }else{
1257 if(strpos($email,"@")>1){
1258 return true;
1259 }
1260 }
1261 return false;
1262 }
1263 /**
1264 * deactivate
1265 *
1266 * @param mixed $action
1267 */
1268 public function deactivate($action="deactivate"){
1269 do_action('plugin_status_'.$this->type,$action);
1270 }
1271 /**
1272 * activate plugin
1273 *
1274 */
1275 public function activate(){
1276 $this->plugin_api(true);
1277 $this->maybe_install();
1278 do_action('plugin_status_'.$this->type,'activate');
1279 }
1280 /**
1281 * Send CURL Request
1282 *
1283 * @param mixed $body
1284 * @param mixed $path
1285 * @param mixed $method
1286 */
1287 public function request($path="",$method='POST',$body="",$head=array()) {
1288
1289 $args = array(
1290 'body' => $body,
1291 'headers'=> $head,
1292 'method' => strtoupper($method), // GET, POST, PUT, DELETE, etc.
1293 'sslverify' => false,
1294 'timeout' => 20,
1295 );
1296
1297 $response = wp_remote_request($path, $args);
1298
1299 if(is_wp_error($response)) {
1300 $this->error_msg= $response->get_error_message();
1301 return false;
1302 } else if(isset($response['response']['code']) && $response['response']['code'] != 200 && $response['response']['code'] != 404) {
1303 $this->error_msg = strip_tags($response['body']);
1304 return false;
1305 } else if(!$response) {
1306 return false;
1307 }
1308 $result=wp_remote_retrieve_body($response);
1309 return $result;
1310 }
1311
1312 /**
1313 * Formates User Informations and submitted form to string
1314 * This string is sent to email and zoho
1315 * @param array $info User informations
1316 * @param bool $is_html If HTML needed or not
1317 * @return string formated string
1318 */
1319 public function format_user_info($info,$is_html=false){
1320 $str=""; $file="";
1321 if($is_html){
1322 self::$path=$this->get_base_path();
1323 if(file_exists(self::$path."templates/email.php")){
1324 ob_start();
1325 include_once(self::$path."templates/email.php");
1326 $file= ob_get_contents(); // data is now in here
1327 ob_end_clean();
1328 }
1329 if(trim($file) == "")
1330 $is_html=false;
1331 }
1332 if(isset($info['info']) && is_array($info['info'])){
1333 if($is_html){
1334 if(isset($info['info_title'])){
1335 $str.='<tr><td style="font-family: Helvetica, Arial, sans-serif;background-color: #C35050; height: 36px; color: #fff; font-size: 24px; padding: 0px 10px">'.$info['info_title'].'</td></tr>'."\n";
1336 }
1337 if(is_array($info['info']) && count($info['info'])>0){
1338 $str.='<tr><td style="padding: 10px;"><table border="0" cellpadding="0" cellspacing="0" width="100%;"><tbody>';
1339 foreach($info['info'] as $f_k=>$f_val){
1340 $str.='<tr><td style="padding-top: 10px;color: #303030;font-family: Helvetica;font-size: 13px;line-height: 150%;text-align: right; font-weight: bold; width: 28%; padding-right: 10px;">'.$f_k.'</td><td style="padding-top: 10px;color: #303030;font-family: Helvetica;font-size: 13px;line-height: 150%;text-align: left; word-break:break-all;">'.$f_val.'</td></tr>'."\n";
1341 }
1342 $str.="</table></td></tr>";
1343 }
1344 }else{
1345 if(isset($info['title']))
1346 $str.="\n".$info['title']."\n";
1347 foreach($info['info'] as $f_k=>$f_val){
1348 $str.=$f_k." : ".$f_val."\n";
1349 }
1350 }
1351 }
1352 if($is_html){
1353 $str=str_replace(array("{title}","{msg}","{sf_contents}"),array($info['title'],$info['msg'],$str),$file);
1354 }
1355 return $str;
1356 }
1357
1358
1359 /**
1360 * if plugin user is valid
1361 *
1362 * @param mixed $update
1363 */
1364
1365 public function is_valid_user($update){
1366 return is_array($update) && isset($update['user']['user']) && $update['user']['user']!=""&& isset($update['user']['expires']);
1367 }
1368 public function post($key, $arr="") {
1369 if($arr!=""){
1370 return isset($arr[$key]) ? $arr[$key] : "";
1371 }
1372 return isset($_REQUEST[$key]) ? self::clean($_REQUEST[$key]) : "";
1373 }
1374 public static function clean($var,$key=''){
1375 if ( is_array( $var ) ) {
1376 $a=array();
1377 foreach($var as $k=>$v){
1378 $a[$k]=self::clean($v,$k);
1379 }
1380 return $a;
1381 }else {
1382 $var=wp_unslash($var);
1383 if(in_array($key,array('note_val','value'))){
1384 $var=sanitize_textarea_field($var);
1385 }else{
1386 $var=sanitize_text_field($var);
1387 }
1388 return $var;
1389 }
1390 }
1391 public static function get_key(){
1392 $k='Wezj%+l-x.4fNzx%hJ]FORKT5Ay1w,iczS=DZrp~H+ve2@1YnS;;g?_VTTWX~-|t';
1393 if(defined('AUTH_KEY')){
1394 $k=AUTH_KEY;
1395 }
1396 return substr($k,0,30);
1397 }
1398 /**
1399 * check if other version of this plugin exists
1400 *
1401 */
1402 public function other_plugin_version(){
1403 $status=0;
1404 if(class_exists('vxcf_zoho_wp')){
1405 $status=1;
1406 }else if( file_exists(WP_PLUGIN_DIR.'/contact-form-zoho-crm/contact-form-zoho-crm.php')) {
1407 $status=2;
1408 }
1409 return $status;
1410 }
1411 /**
1412 * Get time Offset
1413 *
1414 */
1415 public function time_offset(){
1416 $offset = (int) get_option('gmt_offset');
1417 return $offset*3600;
1418 }
1419 /**
1420 * Decrypts Values
1421 * @param array $info Zoho encrypted API info
1422 * @return array API settings
1423 */
1424 public static function de_crypt($info){
1425 $info=trim($info);
1426 if($info == "")
1427 return '';
1428 $str=base64_decode($info);
1429 $key=self::get_key();
1430 $decrypted_string='';
1431 if(function_exists("openssl_encrypt") && strpos($str,':')!==false ) {
1432 $method='AES-256-CBC';
1433 $arr = explode(':', $str);
1434 if(isset($arr[1]) && $arr[1]!=""){
1435 $decrypted_string=openssl_decrypt($arr[0],$method,$key,false, base64_decode($arr[1]));
1436 }
1437 }else{
1438 $decrypted_string=$str;
1439 }
1440 return $decrypted_string;
1441 }
1442 /**
1443 * Encrypts Values
1444 * @param string $str
1445 * @return string Encrypted Value
1446 */
1447 public static function en_crypt($str){
1448 $str=trim($str);
1449 if($str == "")
1450 return '';
1451 $key=self::get_key();
1452 if(function_exists("openssl_encrypt")) {
1453 $method='AES-256-CBC';
1454 $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
1455 $enc_str=openssl_encrypt($str,$method, $key,false,$iv);
1456 $enc_str.=":".base64_encode($iv);
1457 }else{
1458 $enc_str=$str;
1459 }
1460 $enc_str=base64_encode($enc_str);
1461 return $enc_str;
1462 }
1463
1464 /**
1465 * Get variable from array
1466 *
1467 * @param mixed $key
1468 * @param mixed $key2
1469 * @param mixed $arr
1470 */
1471 public function post2($key,$key2, $arr="") {
1472 if(is_array($arr)){
1473 return isset($arr[$key][$key2]) ? self::clean($arr[$key][$key2]) : "";
1474 }
1475 return isset($_REQUEST[$key][$key2]) ? self::clean($_REQUEST[$key][$key2]) : "";
1476 }
1477 /**
1478 * Get variable from array
1479 *
1480 * @param mixed $key
1481 * @param mixed $key2
1482 * @param mixed $arr
1483 */
1484 public function post3($key,$key2,$key3, $arr="") {
1485 if(is_array($arr)){
1486 return isset($arr[$key][$key2][$key3]) ? self::clean($arr[$key][$key2][$key3]) : "";
1487 }
1488 return isset($_REQUEST[$key][$key2][$key3]) ? self::clean($_REQUEST[$key][$key2][$key3]) : "";
1489 }
1490 /**
1491 * get base url
1492 *
1493 */
1494 public function get_base_url(){
1495 return plugin_dir_url(__FILE__);
1496 }
1497 /**
1498 * get plugin direcotry name
1499 *
1500 */
1501 public function plugin_dir_name(){
1502 if(!empty($this->plugin_dir)){
1503 return $this->plugin_dir;
1504 }
1505 if(empty(self::$path)){
1506 self::$path=$this->get_base_path();
1507 }
1508 $this->plugin_dir=basename(self::$path);
1509 return $this->plugin_dir;
1510 }
1511 /**
1512 * get plugin slug
1513 *
1514 */
1515 public function get_slug(){
1516 return plugin_basename(__FILE__);
1517 }
1518 public function do_actions(){
1519 if(!is_object(self::$plugin) ){ $this->plugin_api(); }
1520 if(is_object(self::$plugin) && method_exists(self::$plugin,'valid_addons')){
1521 return self::$plugin->valid_addons();
1522 }
1523
1524 return false;
1525 }
1526 /**
1527 * Returns the physical path of the plugin's root folder
1528 *
1529 */
1530 public function get_base_path(){
1531 return plugin_dir_path(__FILE__);
1532 }
1533
1534 /**
1535 * get api object
1536 *
1537 * @param mixed $settings
1538 * @return vxg_api_zoho
1539 */
1540 public function get_api($crm=""){
1541 $api = false;
1542 $api_class=$this->id."_api";
1543 if(!class_exists($api_class))
1544 require_once(self::$path."api/api.php");
1545
1546 $api = new $api_class($crm);
1547 return $api;
1548 }
1549 /**
1550 * get contact form entry
1551 *
1552 */
1553 public function get_cf_entry($entry_id,$type=''){
1554 $entry=array();
1555
1556 if($type == 'addon'){
1557
1558 if( class_exists( 'vxcf_crm' ) && !empty( $entry_id ) ) {
1559 $entry = vxcf_crm::get_entry( $entry_id );
1560 $entry['__vx_id']=$entry_id;
1561 $entry['form_id']='vx_contacts';
1562 }
1563 }
1564 else{
1565 if( class_exists( 'vxcf_form' ) && !empty( $entry_id ) ) {
1566 $entry = vxcf_form::get_entry( $entry_id );
1567 $entry['__vx_id']=$entry_id;
1568 }
1569 }
1570 return $entry;
1571 }
1572 /**
1573 * get contact form entry
1574 *
1575 */
1576 public function get_cf_entry_detail($entry_id){
1577 $entry=array();
1578 if( class_exists( 'vxcf_form' ) && !empty( $entry_id ) ) {
1579 $entry = vxcf_form::get_entry_detail( $entry_id );
1580
1581 }
1582 return $entry;
1583 }
1584 /**
1585 * get data object
1586 *
1587 */
1588 public function get_data_object(){
1589 require_once(self::$path . "includes/data.php");
1590 if(!is_object($this->data))
1591 $this->data=new vxcf_zoho_data();
1592 return $this->data;
1593 }
1594
1595
1596 /**
1597 * push form data to crm
1598 *
1599 * @param mixed $entry
1600 * @param mixed $form
1601 * @param mixed $is_admin
1602 */
1603 public function push($entry, $form,$event="",$is_admin=true,$log=""){
1604
1605 $data_db=$this->get_data_object();
1606 $log_id=''; $feeds_meta=array();
1607 if(!empty($log)){
1608 if(isset($log['id'])){
1609 $log_id=$log['id'];
1610 }
1611 $log_feed=$data_db->get_feed($log['feed_id']);
1612
1613 if(!empty($log_feed)){
1614 $feeds_meta=array($log_feed);
1615 }
1616 }else{
1617 //get feeds of a form
1618 $feeds=$data_db->get_feed_by_form($form['id'],true);
1619
1620 if(is_array($feeds) && count($feeds)>0){
1621 $e=1000; $k=1;
1622 foreach($feeds as $feed){
1623 $data=isset($feed['data']) ? json_decode($feed['data'],true) : array();
1624 $meta=isset($feed['meta']) ? json_decode($feed['meta'],true) : array();
1625 $feed['meta']=$meta;
1626 $feed['data']=$data;
1627 if(!empty($data['account_check']) || !empty($data['vendor_check'])){
1628 $feeds_meta[$e++]=$feed;
1629 }else{
1630 $feeds_meta[$k++]=$feed;
1631 }
1632 }
1633 ksort($feeds_meta);
1634 }
1635
1636 }
1637
1638 $entry_id=$this->post('__vx_id',$entry);
1639
1640 $type='cf';
1641 if($form['id'] == 'vx_contacts'){
1642 $type='cc';
1643 }
1644
1645 if(empty($form['__vx_addons']) && ($event == '' || $event == 'update' || $event == 'submit')){
1646 $entry=apply_filters('vx_crm_post_fields',$entry,$entry_id,$type,$form);
1647 }
1648 if(isset($form['id'])){
1649 $entry['_vx_form_id']=$form['id'];
1650 }
1651 if( isset($form['title'])){
1652 $entry['_vx_form_name']=$form['title'];
1653 }
1654
1655 $local_time=current_time( 'mysql');
1656 $entry['_vx_created']=isset($entry['__vx_entry']['created']) ? $entry['__vx_entry']['created'] : $local_time;
1657 $entry['_vx_updated']=isset($entry['__vx_entry']['updated']) ? $entry['__vx_entry']['updated'] : $local_time;
1658
1659 if(!empty($entry['_vx_created'])){
1660 $entry['_vx_created']=date('M/d/Y h:i A',strtotime($entry['_vx_created']));
1661 }
1662 if(!empty($entry['_vx_updated'])){
1663 $entry['_vx_updated']=date('M/d/Y h:i A',strtotime($entry['_vx_updated']));
1664 }
1665 if(!empty($entry['__vx_entry'])){
1666 $entry['_vx_url']=$entry['__vx_entry']['url'];
1667 }
1668 //var_dump($entry); die();
1669 $n=0;
1670 $screen_msg_class="updated"; $notice=""; $log_link='';
1671 if(is_array($feeds_meta) && count($feeds_meta)>0){
1672 while($feed=current($feeds_meta)){
1673 next($feeds_meta);
1674 $n++;
1675 $temp=array();
1676 $force_send=false;
1677 $post_comment=true;
1678 $screen_msg="";
1679 $parent_id=0;
1680 if(isset($entry['__vx_parent_id'])){
1681 $parent_id=$entry['__vx_parent_id'];
1682 }
1683 $object=$this->post('object',$feed);
1684 if(empty($object)){
1685 continue;
1686 }
1687 //
1688 $data=$meta=array();
1689
1690 if(is_array($feed)){
1691 if(isset($feed['data']) && is_array($feed['data'])){
1692 $data=$feed['data'];
1693 }
1694 //
1695 if(isset($feed['meta']) && is_array($feed['meta'])){
1696 $meta=$feed['meta'];
1697 }
1698 }
1699 //
1700
1701 if(in_array($event,array('restore','update','delete','add_note','delete_note'))){
1702 $is_admin=true;
1703 $search_object=$object;
1704 if(in_array($event,array('add_note','delete_note')) && !empty($log)){
1705
1706 if($event == 'add_note'){
1707 $note=json_decode($log['data'],true);
1708 if(!empty($note['Title']['value'])){
1709 self::$note=array('id'=>$log['parent_id']);
1710 self::$note['title']=$note['Title']['value'];
1711 self::$note['body']=$note['Body']['value'];
1712 }
1713 }
1714 }
1715 if($event == 'delete_note' && !empty(self::$note)){
1716 $parent_id=self::$note['id'];
1717 }
1718
1719 if(in_array($event,array('delete_note','add_note'))){
1720 //check feed
1721 $order_notes=$this->post('entry_notes',$data); //if notes sync not enabled in feed return
1722 if( empty($order_notes)){
1723 continue;
1724 }
1725 //change main object to Note
1726 $feed['related_object']=$object;
1727 $object=$data['object']='Note';
1728 }
1729 if($event == 'delete_note'){
1730 //when deleting note search note object
1731 $search_object='Note';
1732 }
1733 $_data=$this->get_data_object();
1734 $feed_log=$_data->get_feed_log($feed['id'],$entry_id,$search_object,$parent_id);
1735 //var_dump($feed_log); die();
1736 if($event == 'restore' && $feed_log['status'] != 5) { // only allow successfully deleted records
1737 continue;
1738 }
1739
1740 if( in_array($event,array('update','delete') ) && !in_array($feed_log['status'],array(1,2) ) ){ // only allow successfully sent records
1741 continue;
1742 }
1743
1744 if(empty($feed_log['crm_id']) || empty($feed_log['object']) || $feed_log['object'] != $search_object){
1745
1746 continue;
1747 }
1748 if($event !='restore'){
1749 $feed['crm_id']=$feed_log['crm_id'];
1750 unset($feed['primary_key']);
1751 }
1752 $feed['event']=$event;
1753 // add note and save related extra info
1754 if( $event == 'add_note' && !empty(self::$note)){
1755 $temp=array('Title'=>array('label'=>'Note Title','value'=>self::$note['title']),'Body'=>array('label'=>'Note Content','value'=>self::$note['body']),'ParentId'=>array('label'=>'entityId', 'value'=> $feed['crm_id']));
1756 $parent_id=self::$note['id'];
1757 $feed['note_object_link']='<a href="'.$feed_log['link'].'" target="_blank">'.$feed_log['crm_id'].'</a>';
1758 }
1759 // delete not and save extra info
1760 if( $event == 'delete_note'){
1761
1762 $feed_log_arr= json_decode($feed_log['extra'],true);
1763 if(isset($feed_log_arr['note_object_link'])){
1764 $feed['note_object_link']=$feed_log_arr['note_object_link'];
1765 }
1766 $temp=array('ParentId'=>array('value'=> $feed['crm_id']));
1767 }
1768 //delete object
1769 if( $event == 'delete'){
1770 $temp=array('Id'=>array('value'=> $feed['crm_id']));
1771 }
1772 //
1773 if(!in_array($event , array('update','restore') )){
1774 //do not apply filters when adding note , deleting note , entry etc
1775 $force_send=true;
1776 }
1777 //do not post comment in al other cases
1778 $post_comment=false;
1779
1780 }
1781 // var_dump(self::$note,$object,$feed['note_object'],$feed['object'],$feed['crm_id'],$feed['event'],$temp,$force_send);
1782 //continue;
1783 // die();
1784 if(isset($entry['__vx_data'])){
1785 $force_send=true;
1786 $temp=$entry['__vx_data'];
1787 }
1788
1789 if(!$force_send && isset($data['map']) && is_array($data['map']) && count($data['map'])>0){
1790
1791 $custom= isset($meta['fields']) && is_array($meta['fields']) ? $meta['fields'] : array();
1792 if(empty($this->form_fields)){
1793 $this->form_fields=$this->get_form_fields($form['id']);
1794 }
1795 $skip_feed=false;
1796 foreach($data['map'] as $k=>$v){
1797 ///
1798 $value='';
1799 if(!empty($v)){ //if value not empty
1800 if($this->post('type',$v) == "value"){ //custom value
1801 $value=trim($this->post('value',$v));
1802 $value=$this->process_tags($entry,$value);
1803 if(trim($value) == ''){ $value=false; }
1804
1805 }else{ //general field
1806 $field=$this->post('field',$v);
1807 if($field !=""){
1808 if(strpos($field,'_vx_feed-') !== false){
1809 $temp_feed_id=substr($field,9);
1810
1811 if(isset(self::$feeds_res[$temp_feed_id])){
1812 $value= !empty(self::$feeds_res[$temp_feed_id]['id']) ? self::$feeds_res[$temp_feed_id]['id'] : '';
1813
1814 }else if($n < count($feeds_meta) ){ // it is not last element
1815 $feeds_meta[]=$feed; $skip_feed=true;
1816 break;
1817 }
1818 }else if($field == '_vx_form_id' && isset($form['id'])){
1819 $value=$form['id'];
1820 }else if($field == '_vx_form_name' && isset($form['title'])){
1821 $value=$form['title'];
1822 }else{
1823 $value=$this->verify_field_val($entry,$field);
1824 }
1825 }
1826 }
1827 if( $value !== false ){
1828 if(isset($custom[$k])){
1829 $temp[$k]=array("value"=>$value,"label"=>$custom[$k]['label']);
1830 }
1831 }
1832 }
1833 }
1834 //var_dump($temp,$entry); die();
1835 if($skip_feed){ continue; }
1836 //change owner id
1837 if(!empty($data['owner']) && !empty($data['user']) ){
1838 $data['user']=apply_filters('vx_assigned_user_id',$data['user'],$this->id,$feed['id'],$entry);
1839 }
1840 //add note
1841 if(!empty($data['note_check']) ){
1842 $entry_note=''; $entry_note_title='';
1843 if(!empty($data['note_fields']) && is_array($data['note_fields'])){
1844 $data['note_val']='{'.implode("}\n{",$data['note_fields'])."}";
1845 }
1846 if(!empty($data['note_val'])){
1847 $entry_note=$this->process_tags($entry,$data['note_val']);
1848 if(empty($entry_note_title)){
1849 $entry_note_title=substr($entry_note,0,20);
1850 }
1851 if(!empty($entry_note)){
1852 $feed['__vx_entry_note']=array('Title'=>$entry_note_title,'Body'=>$entry_note);
1853 }
1854 }
1855 }
1856
1857 }
1858 //var_dump($temp); die('---------');
1859 $no_filter=true;
1860
1861 //not submitted by admin
1862 if( !$is_admin && $this->post('manual_export',$data) == "1"){ //if manual export is yes
1863 continue;
1864 }
1865 if(isset($_REQUEST['bulk_action']) && $_REQUEST['bulk_action'] =="send_to_crm_bulk_force" && !empty($log_id)){
1866 $force_send=true;
1867 }
1868 if(!$force_send && $this->post('optin_enabled',$data) == "1"){ //apply filters if not sending by force and optin is enabled
1869 $no_filter=$this->check_filter($data,$entry);
1870 $res=array("status"=>"4","extra"=>array("filter"=>$this->filter_condition),"data"=>$temp);
1871 }
1872 $account=$this->post('account',$feed);
1873 $info=$this->get_info($account);
1874 if(is_array($meta) && is_array($data)){
1875 $feed=array_merge($feed,$meta,$data);
1876 }
1877
1878 if($no_filter){ //get $res if no filter , other wise use filtered $res
1879 $api=$this->get_api($info);
1880
1881 $res=$api->push_object($feed['object'],$temp,$feed);
1882
1883 }
1884
1885 $feed_id=$this->post('id',$feed);
1886 self::$feeds_res[$feed_id]=$res;
1887 $status=$res['status']; $error=""; $id="";
1888 if($this->post('id',$res)!=""){
1889 $id=$res['id'];
1890 $action=$this->post('action',$res);
1891 if($action == "Added"){
1892 if(empty($res['link'])){
1893 $msg=sprintf(__('Successfully Added to Zoho (%s) with ID # %s .', 'contact-form-zoho-crm'),$feed['object'],$res['id']);
1894 }else{
1895 $msg=sprintf(__('Successfully Added to Zoho (%s) with ID # %s . View entry at %s', 'contact-form-zoho-crm'),$feed['object'],$res['id'],$res['link']);
1896 }
1897 $screen_msg=__( 'Entry added in Zoho', 'contact-form-zoho-crm');
1898 }else{
1899 if(empty($res['link'])){
1900 $msg=sprintf(__('Successfully Updated to Zoho (%s) with ID # %s . View entry at %s', 'contact-form-zoho-crm'),$feed['object'],$res['id'],$res['link']);
1901 }else{
1902 $msg=sprintf(__('Successfully Updated to Zoho (%s) with ID # %s .', 'contact-form-zoho-crm'),$feed['object'],$res['id']);
1903 }
1904 if($event == 'delete'){
1905 $screen_msg=__( 'Entry deleted from Zoho', 'contact-form-zoho-crm');
1906 }else{
1907 $screen_msg=__( 'Entry updated in Zoho', 'contact-form-zoho-crm');
1908 }
1909 }
1910
1911
1912 }else if($this->post('status',$res) == 4){
1913 $screen_msg=$msg=__( 'Entry filtered', 'contact-form-zoho-crm');
1914 }else{
1915 $status=0; $screen_msg_class="error";
1916 $screen_msg=__('Errors when adding to Zoho. Entry not sent! Check the Entry Notes below for more details.' , 'contact-form-zoho-crm' );
1917 if($log_id!=""){
1918 //message for bulk actions in logs
1919 $screen_msg=__('Errors when adding to Zoho. Entry not sent' , 'contact-form-zoho-crm' );
1920 }
1921 $msg=sprintf(__('Error while creating %s', 'contact-form-zoho-crm'),$feed['object']);
1922 if($this->post('error',$res)!=""){
1923 $error= is_array($res['error']) ? json_encode($res['error']) : $res['error'];
1924 $msg.=" ($error)";
1925
1926 $_REQUEST['VXGZohoError']=$msg; //front end form error for admin only
1927 }
1928 if(!$is_admin){
1929 $info['msg']=$msg;
1930 $this->send_error_email($info,$entry,$form);
1931 }
1932
1933 }
1934
1935 //insert log
1936 $arr=array("object"=>$feed["object"],"form_id"=>$form['id'],"status"=>$status,"entry_id"=>$entry_id,"crm_id"=>$id,"meta"=>$error,"time"=>date('Y-m-d H:i:s'),"data"=>$this->post('data',$res),"response"=>$this->post('response',$res),"extra"=>$this->post('extra',$res),"feed_id"=>$this->post('id',$feed),'parent_id'=>$parent_id,'event'=>$event,"link"=>$this->post('link',$res));
1937 $settings=get_option($this->type.'_settings',array());
1938 // if($this->post('disable_log',$settings) !="yes"){
1939 $insert_id=$data_db->insert_log($arr,$log_id);
1940 // }
1941 $log_link='';
1942 if(!empty($insert_id)){ //
1943 $log_url=admin_url( 'admin.php?page='.$this->id.'&tab=logs&log_id='.$insert_id);
1944 $log_link=' <a href="'.esc_url($log_url).'" class="vx_log_link" data-id="'.$insert_id.'">'.__('View Detail','contact-form-zoho-crm')."</a>";
1945 $screen_msg.=$log_link;
1946 }
1947 if($post_comment){
1948 //insert entry comment
1949 //$this->add_note($entry["id"], $msg);
1950 }
1951 if($notice!=""){
1952 $notice.='<br/>';
1953 }
1954 $notice.='<b>'.$object.': </b>'.$screen_msg;
1955
1956 }
1957 }
1958
1959 return array("msg"=>$notice,"class"=>$screen_msg_class);
1960 }
1961 public function process_tags($entry,$value){
1962 //starts with { and ends } , any char in brackets except {
1963 preg_match_all('/\{[^\{]+\}/',$value,$matches);
1964 if(!empty($matches[0])){
1965 $vals=array();
1966 foreach($matches[0] as $m){
1967 $m=trim($m,'{}');
1968 $val_cust=$this->verify_field_val($entry,$m);
1969 if(is_array($val_cust)){ $val_cust=trim(implode(' ',$val_cust)); }
1970 $vals['{'.$m.'}']=$val_cust;
1971 }
1972 $value=str_replace(array_keys($vals),array_values($vals),$value);
1973 }
1974 return $value;
1975 }
1976
1977 /**
1978 * Send error email
1979 *
1980 * @param mixed $info
1981 * @param mixed $entry
1982 * @param mixed $form
1983 */
1984 public function send_error_email($info,$entry,$form){
1985 if(!empty($info['data']['error_email'])){
1986 $subject="Error While Posting to Zoho";
1987 $entry_link=add_query_arg(array('page' => 'vxcf_leads','tab'=>'entries', 'id' => $entry['__vx_id']), admin_url('admin.php'));
1988 $page_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
1989
1990 $detail=array(
1991 "Time"=>date('d/M/y H:i:s',current_time('timestamp')),
1992 "Page URL"=>'<a href="'.$page_url.'" style="word-break:break-all;">'.$page_url.'</a>',
1993 "Entry ID"=>'<a href="'.$entry_link.'" target="_blank" style="word-break:break-all;">'.$entry_link.'</a>'
1994 );
1995 if(isset($form['title'])){
1996 $detail["Form Name"]=$form['title'];
1997 $detail["Form Id"]=$form['id'];
1998 }
1999 $email_info=array("msg"=>$info['msg'],"title"=>__('Zoho','contact-form-zoho-crm')." Error","info_title"=>"More Detail","info"=>$detail);
2000 $email_body=$this->format_user_info($email_info,true);
2001
2002 $error_emails=explode(",",$info['data']['error_email']);
2003 $headers = array('Content-Type: text/html; charset=UTF-8');
2004 foreach($error_emails as $email)
2005 wp_mail(trim($email),$subject, $email_body,$headers);
2006
2007 }
2008
2009 }
2010 /**
2011 * Get Objects from local options or from zoho
2012 *
2013 * @param mixed $check_option
2014 * @return array
2015 */
2016 public function get_objects($info="",$refresh=false){
2017
2018 $objects=array();
2019 if(!empty($info)){
2020 $meta=$this->post('meta',$info);
2021
2022 }else{
2023 $meta=get_option($this->id.'_meta',array());
2024 }
2025 if(empty($meta['objects'])){
2026 $refresh=true;
2027 }else{
2028 $objects=$meta['objects'];
2029 }
2030
2031 //get objects from streak
2032 if($refresh && !empty($info)){
2033 $api=$this->get_api($info);
2034 $objects=$api->get_crm_objects();
2035
2036 if(is_array($objects)){
2037 $option=get_option($this->id.'_meta',array());
2038 $meta_objects=$objects;
2039 if(!empty($option['objects']) && is_array($option['objects'])){
2040 $meta_objects=array_merge($option['objects'],$objects);
2041 }
2042
2043 $option['objects']=$meta_objects;
2044
2045 update_option($this->id.'_meta',$option); //save objects for logs search option
2046 $meta["objects"]=$objects;
2047 $this->update_info(array("meta"=>$meta),$info['id']);
2048 }
2049 }
2050
2051 return $objects;
2052 }
2053
2054
2055 /**
2056 * check if user conected to crm
2057 *
2058 * @param mixed $settings
2059 */
2060 public function api_is_valid($info="") {
2061
2062 if(isset($info['data']['class']) && is_array($info['data']) && $info['data']['class'] =='updated'){
2063 return true;
2064 }else{
2065 return false;}
2066 }
2067 }
2068
2069 $vxcf_zoho=new vxcf_zoho();
2070 $vxcf_zoho->instance();
2071 $vx_cf['vxcf_zoho']='vxcf_zoho';
2072 endif;
2073
2074