| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if( !defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
|
| 6 |
if( !class_exists( 'vxg_googlesheets_pages' ) ) { |
| 7 |
|
| 8 |
/** |
| 9 |
* Main class |
| 10 |
* |
| 11 |
* @since 1.0.0 |
| 12 |
*/ |
| 13 |
class vxg_googlesheets_pages extends vxg_googlesheets{ |
| 14 |
public $ajax=false; |
| 15 |
/** |
| 16 |
* initialize plugin hooks |
| 17 |
* |
| 18 |
*/ |
| 19 |
public function __construct() { |
| 20 |
|
| 21 |
$this->data=$this->get_data_object(); |
| 22 |
global $pagenow; |
| 23 |
if(in_array($pagenow, array("admin-ajax.php"))){ |
| 24 |
add_action('wp_ajax_update_feed_'.$this->id, array($this, 'update_feed')); |
| 25 |
add_action('wp_ajax_update_feed_sort_'.$this->id, array($this, 'update_feed_sort')); |
| 26 |
add_action('wp_ajax_get_field_map_'.$this->id, array($this, 'get_field_map_ajax')); |
| 27 |
add_action('wp_ajax_get_field_map_object_'.$this->id, array($this, 'get_field_map_object_ajax')); |
| 28 |
add_action('wp_ajax_get_objects_'.$this->id, array($this, 'get_objects_ajax')); |
| 29 |
add_action('wp_ajax_log_detail_'.$this->id, array($this, 'log_detail')); |
| 30 |
add_action('wp_ajax_refresh_data_'.$this->id, array($this, 'refresh_data')); |
| 31 |
} |
| 32 |
if($this->is_crm_page()){ |
| 33 |
|
| 34 |
|
| 35 |
require_once(GFCommon::get_base_path() . "/tooltips.php"); |
| 36 |
add_filter('gform_tooltips', array($this, 'tooltips')); } |
| 37 |
|
| 38 |
//creates the subnav left menu |
| 39 |
//add_filter("gform_addon_navigation", array($this, 'create_menu'), 20); |
| 40 |
add_filter("gform_logging_supported", array($this, "set_logging_supported")); |
| 41 |
add_action( 'gform_form_settings_menu', array( $this, 'add_form_settings_menu' ), 10, 2 ); |
| 42 |
add_action( 'gform_form_settings_page_' . $this->id, array( $this, 'form_settings_page' ) ); |
| 43 |
add_filter("admin_menu", array($this, 'setup'), 10); |
| 44 |
|
| 45 |
add_action('gform_post_note_added', array($this, 'create_note'),10,6); |
| 46 |
add_action('gform_pre_note_deleted', array($this, 'delete_note'),10,2); |
| 47 |
//add_action('gform_delete_lead', array($this, 'delete_entry')); |
| 48 |
|
| 49 |
add_action('gform_entry_detail_sidebar_middle', array($this, 'send_entry_btn'),10,2); |
| 50 |
add_action( 'gform_entry_info', array($this, 'entry_info_send_checkbox'), 99, 2); |
| 51 |
|
| 52 |
add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 53 |
add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
} |
| 58 |
public function send_entry_btn($form,$lead){ |
| 59 |
if(!$this->show_send_to_crm_button()) { return ''; } |
| 60 |
$entry_id=$this->post('lid'); |
| 61 |
$form_id = $this->post('id'); |
| 62 |
if(empty($entry_id)){ |
| 63 |
$entry_id=$this->get_entry_id($form_id); |
| 64 |
} |
| 65 |
$log_url=admin_url( 'admin.php?page=gf_edit_forms&view=settings&subview='.$this->id.'&tab=log&id='.$form_id.'&entry_id='.$entry_id); |
| 66 |
|
| 67 |
$data=$this->get_data_object(); |
| 68 |
$log=$data->get_log_by_lead($entry_id); |
| 69 |
require_once(self::$path . 'templates/crm-entry-box.php'); |
| 70 |
} |
| 71 |
/** |
| 72 |
* Display custom notices |
| 73 |
* show googlesheets response |
| 74 |
* |
| 75 |
*/ |
| 76 |
public function admin_notices(){ |
| 77 |
|
| 78 |
$debug = !empty(self::$debug_html) && current_user_can($this->id.'_edit_settings'); |
| 79 |
if($debug){ |
| 80 |
echo "<div class='error'><p>".wp_kses_post(self::$debug_html)."</p></div>"; |
| 81 |
self::$debug_html=''; |
| 82 |
} |
| 83 |
if(!empty($_GET['vx_debug'])){ |
| 84 |
$html=get_option($this->id."_debug"); |
| 85 |
if(!empty($html)){ |
| 86 |
echo "<div class='error'><p>".wp_kses_post($html)."</p></div>"; |
| 87 |
update_option($this->id."_debug",''); |
| 88 |
} } |
| 89 |
if(isset($_GET[$this->id."_logs"]) && current_user_can($this->id.'_read_settings')){ |
| 90 |
$msg=__('Error While Clearing Google Sheets Logs','gravity-forms-googlesheets-crm'); |
| 91 |
$level="error"; |
| 92 |
if(!empty($_GET[$this->id."_logs"])){ |
| 93 |
$msg=__('Google Sheets Logs Cleared Successfully','gravity-forms-googlesheets-crm'); |
| 94 |
$level="updated"; |
| 95 |
} |
| 96 |
$this->screen_msg($msg,$level); |
| 97 |
} |
| 98 |
// if(isset($_REQUEST[$this->id.'_msg'])){ //send to crm in order page message |
| 99 |
$msg=get_option($this->id.'_msg'); |
| 100 |
update_option($this->id.'_msg',''); |
| 101 |
if(isset($msg['class'])){ |
| 102 |
$this->screen_msg($msg['msg'],$msg['class']); |
| 103 |
} |
| 104 |
// } |
| 105 |
} |
| 106 |
/** |
| 107 |
* Add settings and support link |
| 108 |
* |
| 109 |
* @param mixed $links |
| 110 |
* @param mixed $file |
| 111 |
*/ |
| 112 |
public function plugin_action_links( $links, $file ) { |
| 113 |
$slug=$this->get_slug(); |
| 114 |
if ( $file == $slug ) { |
| 115 |
$settings_link=$this->link_to_settings(); |
| 116 |
array_unshift( $links, '<a href="' .$settings_link. '">' . esc_html__('Settings', 'gravity-forms-googlesheets-crm') . '</a>' ); |
| 117 |
} |
| 118 |
return $links; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Renders the form settings page. |
| 123 |
* |
| 124 |
* @ignore |
| 125 |
*/ |
| 126 |
public function form_settings_page() { |
| 127 |
GFFormSettings::page_header( self::$title ); |
| 128 |
$this->mapping_page(); |
| 129 |
GFFormSettings::page_footer(); |
| 130 |
} |
| 131 |
/** |
| 132 |
* Add the form settings tab. |
| 133 |
* |
| 134 |
* Override this function to add the tab conditionally. |
| 135 |
* |
| 136 |
* |
| 137 |
* @param $tabs |
| 138 |
* @param $form_id |
| 139 |
* |
| 140 |
* @return array |
| 141 |
*/ |
| 142 |
public function add_form_settings_menu( $tabs, $form_id ) { |
| 143 |
|
| 144 |
$tabs[] = array( 'name' => $this->id, 'label' => esc_html__("Google Sheets", 'gravity-forms-googlesheets-crm') , 'query' => array( 'fid' => null),'icon' => 'dashicons-cloud dashicons' ); |
| 145 |
|
| 146 |
return $tabs; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
/** |
| 151 |
* delete note from crm when deleted from GF entry |
| 152 |
* |
| 153 |
* @param mixed $note_id |
| 154 |
* @param mixed $lead_id |
| 155 |
*/ |
| 156 |
public function delete_note($note_id,$lead_id){ |
| 157 |
$meta=get_option($this->type.'_settings',array()); |
| 158 |
|
| 159 |
if(!empty($meta['notes'])){ |
| 160 |
$entry=$this->get_gf_entry($lead_id); |
| 161 |
self::$note=array('id'=>$note_id); |
| 162 |
if(isset($entry['form_id'])){ |
| 163 |
$form=array('id'=>$entry['form_id']); |
| 164 |
$this->push($entry,$form,'delete_note'); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
} |
| 169 |
/** |
| 170 |
* send entry note to crm |
| 171 |
* |
| 172 |
* @param mixed $id |
| 173 |
* @param mixed $lead_id |
| 174 |
* @param mixed $user_id |
| 175 |
* @param mixed $user_name |
| 176 |
* @param mixed $note |
| 177 |
* @param mixed $note_type |
| 178 |
*/ |
| 179 |
public function create_note($id, $lead_id, $user_id, $user_name, $note, $note_type){ |
| 180 |
if(!empty($_POST['add_note'])){ |
| 181 |
$meta=get_option($this->type.'_settings',array()); |
| 182 |
|
| 183 |
if(!empty($meta['notes'])){ |
| 184 |
$entry=$this->get_gf_entry($lead_id); |
| 185 |
$title=substr($note,0,100); |
| 186 |
self::$note=array('id'=>$id,'body'=>$note,'title'=>$title); |
| 187 |
if(isset($entry['form_id'])){ |
| 188 |
$form=array('id'=>$entry['form_id']); |
| 189 |
$this->push($entry,$form,'add_note'); |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
/** |
| 195 |
* Creates left nav menu under Forms |
| 196 |
* |
| 197 |
* @param mixed $menus |
| 198 |
*/ |
| 199 |
public function create_menu($menus){ |
| 200 |
// Adding submenu if user has access |
| 201 |
$menus[] = array("name" => $this->id, "label" => esc_html__('Google Sheets','gravity-forms-googlesheets-crm'), "callback" => array($this, "mapping_page"), "permission" => $this->id.'_read_feeds'); |
| 202 |
|
| 203 |
return $menus; |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Creates or updates database tables. Will only run when version changes |
| 208 |
* |
| 209 |
*/ |
| 210 |
public function setup(){ |
| 211 |
|
| 212 |
GFForms::add_settings_page(array('name' => $this->id,'tab_label' => esc_html__('Google Sheets','gravity-forms-googlesheets-crm'),'icon' => 'dashicons-cloud dashicons',"handler"=>array($this, "settings_page"))); |
| 213 |
|
| 214 |
global $wpdb; |
| 215 |
if($this->post('vx_tab_action_'.$this->id)=="export_log"){ |
| 216 |
check_admin_referer('vx_nonce','vx_nonce'); |
| 217 |
if(!current_user_can($this->id."_export_logs")){ |
| 218 |
$msg=__('You do not have permissions to export logs','gravity-forms-googlesheets-crm'); |
| 219 |
$this->display_msg('admin',$msg); |
| 220 |
return; |
| 221 |
} |
| 222 |
header('Content-disposition: attachment; filename='.date("Y-m-d",current_time('timestamp')).'.csv'); |
| 223 |
header('Content-Type: application/excel'); |
| 224 |
$data=$this->get_data_object(); |
| 225 |
$sql_end=$data->get_log_query(); |
| 226 |
$objects=$this->get_objects(""); |
| 227 |
$forms=array(); |
| 228 |
$sql="select * $sql_end limit 3000"; |
| 229 |
$results = $wpdb->get_results($sql , ARRAY_A ); |
| 230 |
$fields=array(); $field_titles=array("#",__('Status','gravity-forms-googlesheets-crm'),__('Google Sheets ID','gravity-forms-googlesheets-crm') ,__('Entry ID','gravity-forms-googlesheets-crm'),__('Description','gravity-forms-googlesheets-crm'),__('Time','gravity-forms-googlesheets-crm')); |
| 231 |
$fp = fopen('php://output', 'w'); |
| 232 |
fputcsv($fp, $field_titles); |
| 233 |
$sno=0; |
| 234 |
foreach($results as $row){ |
| 235 |
$sno++; |
| 236 |
$row=$this->verify_log($row,$objects); |
| 237 |
fputcsv($fp, array($sno,$row['title'],$row['_crm_id'],$row['entry_id'],$row['desc'],$row['time'])); |
| 238 |
} |
| 239 |
fclose($fp); |
| 240 |
die(); |
| 241 |
} |
| 242 |
|
| 243 |
if($this->post('vx_tab_action_'.$this->id)=="clear_logs" ){ |
| 244 |
check_admin_referer('vx_nonce','vx_nonce'); |
| 245 |
if(!current_user_can($this->id."_edit_settings")){ |
| 246 |
$msg=__('You do not have permissions to clear logs','gravity-forms-googlesheets-crm'); |
| 247 |
$this->display_msg('admin',$msg); |
| 248 |
return; |
| 249 |
} |
| 250 |
$data=$this->get_data_object(); |
| 251 |
$clear=$data->clear_logs(); |
| 252 |
$log_str="Clearing Log"; |
| 253 |
$this->log_msg($log_str); |
| 254 |
wp_redirect(admin_url("admin.php?page=".$this->post('page')."&view=".$this->post('view')."&".$this->id."_logs=".$clear)); |
| 255 |
die(); |
| 256 |
} |
| 257 |
|
| 258 |
//send to crm |
| 259 |
if(isset($_POST[$this->id.'_send'])){ |
| 260 |
// Verify authenticity of request |
| 261 |
check_admin_referer('gforms_save_entry', 'gforms_save_entry'); |
| 262 |
// For admin_init hook, get the entry ID from the URL |
| 263 |
|
| 264 |
$entry_id = rgget('lid'); |
| 265 |
$form_id = rgget('id'); |
| 266 |
|
| 267 |
// fetch alternative entry id: look for gf list details when using pagination |
| 268 |
if(empty($entry_id)) { |
| 269 |
$entry_id=$this->get_entry_id($form_id); |
| 270 |
} |
| 271 |
$form = RGFormsModel::get_form_meta($form_id); |
| 272 |
|
| 273 |
if(!current_user_can($this->id."_send_to_crm")){ |
| 274 |
return; |
| 275 |
} |
| 276 |
|
| 277 |
$entry=$this->get_gf_entry($entry_id); |
| 278 |
// Export the entry |
| 279 |
$push=$this->push($entry, $form,"",true); |
| 280 |
|
| 281 |
if(!empty($push['msg'])){ |
| 282 |
update_option($this->id.'_msg',array('msg'=>$push['msg'],'class'=>$push['class'])); |
| 283 |
} |
| 284 |
|
| 285 |
} |
| 286 |
$this->setup_plugin(); |
| 287 |
} |
| 288 |
/** |
| 289 |
* CRM menu page |
| 290 |
* |
| 291 |
*/ |
| 292 |
public function mapping_page(){ |
| 293 |
$view = isset($_GET["tab"]) ? $this->post("tab") : ''; |
| 294 |
if( !empty($_GET["fid"]) ) { |
| 295 |
$this->edit_page($this->post("fid")); |
| 296 |
}else if($view == "log") { |
| 297 |
$this->log_page(); |
| 298 |
} else { |
| 299 |
$this->list_page(); |
| 300 |
} |
| 301 |
|
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
/** |
| 307 |
* Displays the crm feeds list page |
| 308 |
* |
| 309 |
*/ |
| 310 |
private function list_page(){ |
| 311 |
if(!current_user_can($this->id.'_read_feeds')){ |
| 312 |
esc_html_e('You do not have permissions to access this page','gravity-forms-googlesheets-crm'); |
| 313 |
return; |
| 314 |
} |
| 315 |
$is_section=apply_filters('add_page_html_'.$this->id,false); |
| 316 |
|
| 317 |
if($is_section === true){ |
| 318 |
return; |
| 319 |
} |
| 320 |
$offset=$this->time_offset(); |
| 321 |
wp_enqueue_script( 'jquery-ui-sortable'); |
| 322 |
if(isset($_POST["action"]) && $_POST["action"] == "delete"){ |
| 323 |
check_admin_referer("vx_crm_ajax"); |
| 324 |
|
| 325 |
$id = absint($this->post("action_argument")); |
| 326 |
$this->data->delete_feed($id); |
| 327 |
?> |
| 328 |
<div class="updated fade" style="margin:10px 0;"> |
| 329 |
<p> |
| 330 |
<?php esc_html_e("Feed deleted.", 'gravity-forms-googlesheets-crm') ?> |
| 331 |
</p> |
| 332 |
</div> |
| 333 |
<?php |
| 334 |
} |
| 335 |
else if (!empty($_POST["bulk_action"])){ |
| 336 |
check_admin_referer("vx_crm_ajax"); |
| 337 |
$selected_feeds =$this->post("feed"); |
| 338 |
if(is_array($selected_feeds)){ |
| 339 |
foreach($selected_feeds as $feed_id) |
| 340 |
$this->data->delete_feed($feed_id); |
| 341 |
} |
| 342 |
?> |
| 343 |
<div class="updated fade" style="margin:10px 0;"> |
| 344 |
<p> |
| 345 |
<?php esc_html_e("Feeds deleted.", 'gravity-forms-googlesheets-crm') ?> |
| 346 |
</p> |
| 347 |
</div> |
| 348 |
<?php |
| 349 |
} |
| 350 |
$form_id=$this->post('id'); |
| 351 |
$feeds = $this->data->get_feed_by_form($form_id); |
| 352 |
|
| 353 |
$page_link=$this->link_to_settings(); |
| 354 |
$menu_links=$this->get_menu_links('feed'); |
| 355 |
$data=$this->get_data_object(); |
| 356 |
$accounts=$data->get_accounts(true); |
| 357 |
$objects=$this->get_objects(); |
| 358 |
$config = $this->data->get_feed('new_form'); |
| 359 |
$new_feed_link=$this->get_feed_link($config['id']); |
| 360 |
if(!self::$is_pr){ |
| 361 |
$total=$this->data->get_feeds_total(); |
| 362 |
if($total > 2){ |
| 363 |
$new_feed_link='#'; |
| 364 |
} |
| 365 |
} |
| 366 |
$valid_accounts= is_array($accounts) && count($accounts) > 0 ? true : false; |
| 367 |
include_once(self::$path . "templates/feeds.php"); |
| 368 |
} |
| 369 |
/** |
| 370 |
* Displays the crm feeds list page |
| 371 |
* |
| 372 |
*/ |
| 373 |
public function log_page(){ |
| 374 |
|
| 375 |
if(!current_user_can($this->id.'_read_logs')){ |
| 376 |
esc_html_e('You do not have permissions to access this page','gravity-forms-googlesheets-crm'); |
| 377 |
return; |
| 378 |
} |
| 379 |
$is_section=apply_filters('add_page_html_'.$this->id,false); |
| 380 |
|
| 381 |
if($is_section === true){ |
| 382 |
return; |
| 383 |
} |
| 384 |
$offset=$this->time_offset(); |
| 385 |
$log_ids=array(); |
| 386 |
$bulk_action=$this->post('bulk_action'); |
| 387 |
if($bulk_action!=""){ |
| 388 |
$log_id=$this->post('log_id'); |
| 389 |
if(is_array($log_id) && count($log_id)>0){ |
| 390 |
foreach($log_id as $id){ |
| 391 |
if(is_numeric($id)){ |
| 392 |
$log_ids[]=(int)$id; |
| 393 |
} |
| 394 |
} |
| 395 |
if($bulk_action == "delete"){ |
| 396 |
$count=$this->data->delete_log($log_ids); |
| 397 |
$this->screen_msg(sprintf(__('Successfully Deleted %d Item(s)','gravity-forms-googlesheets-crm'),$count)); |
| 398 |
} |
| 399 |
else if(in_array($bulk_action,array("send_to_crm_bulk","send_to_crm_bulk_force"))){ |
| 400 |
self::$api_timeout='1000'; |
| 401 |
foreach($log_ids as $id){ |
| 402 |
$log = $this->data->get_log_by_id($id); |
| 403 |
$form_id=$this->post('form_id',$log); |
| 404 |
$entry_id=$this->post('entry_id',$log); |
| 405 |
if(!empty($form_id) && !empty($entry_id)){ |
| 406 |
$form = RGFormsModel::get_form_meta($form_id); |
| 407 |
$entry=$this->get_gf_entry($entry_id); |
| 408 |
if(is_array($entry)){ |
| 409 |
$push=$this->push($entry,$form,$log['event'],true,$log); |
| 410 |
}else{ |
| 411 |
$push=array('class'=>'error','msg'=>__('Entry Not Found','gravity-forms-googlesheets-crm')); |
| 412 |
} |
| 413 |
if(is_array($push) && isset($push['class'])){ |
| 414 |
$this->screen_msg($push['msg'],$push['class']); |
| 415 |
} |
| 416 |
} ///var_dump($log_ids,$log); die(); |
| 417 |
} |
| 418 |
|
| 419 |
} |
| 420 |
} |
| 421 |
unset($_GET['bulk_action']); |
| 422 |
unset($_GET['vx_nonce']); |
| 423 |
$log_q=$this->clean($_GET); $logs_link=admin_url('admin.php?'.http_build_query($log_q)); |
| 424 |
//wp_redirect($logs_link); |
| 425 |
// die(); |
| 426 |
} |
| 427 |
wp_enqueue_script('jquery-ui-datepicker' ); |
| 428 |
wp_enqueue_style('vx-datepicker'); |
| 429 |
$times=array("today"=>"Today","yesterday"=>"Yesterday","this_week"=>"This Week","last_7"=>"Last 7 Days","last_30"=>"Last 30 Days","this_month"=>"This Month","last_month"=>"Last Month","custom"=>"Select Range"); |
| 430 |
$data= $this->data->get_log(); $items=count($data['feeds']); |
| 431 |
$crm_order=$entry_order=$desc_order=$time_order="up"; |
| 432 |
$crm_class=$entry_class=$desc_class=$time_class="vx_hide_sort"; |
| 433 |
$order=$this->post('order'); |
| 434 |
$order_icon= $order == "desc" ? "down" : "up"; |
| 435 |
if(isset($_REQUEST['orderby'])){ |
| 436 |
switch($_REQUEST['orderby']){ |
| 437 |
case"crm_id": $crm_order=$order_icon; $crm_class=""; break; |
| 438 |
case"entry_id": $entry_order=$order_icon; $entry_class=""; break; |
| 439 |
case"object": $desc_order=$order_icon; $desc_class=""; break; |
| 440 |
case"time": $time_order=$order_icon; $time_class=""; break; |
| 441 |
} |
| 442 |
} |
| 443 |
$bulk_actions=array(""=>__('Bulk Action','gravity-forms-googlesheets-crm'),"delete"=>__('Delete','gravity-forms-googlesheets-crm'), |
| 444 |
'send_to_crm_bulk'=>__('Send to Google Sheets','gravity-forms-googlesheets-crm'),'send_to_crm_bulk_force'=>__('Force Send to Google Sheets - Ignore filters','gravity-forms-googlesheets-crm')); |
| 445 |
$base_url=$this->get_base_url(); |
| 446 |
|
| 447 |
$objects=$this->get_objects(); |
| 448 |
|
| 449 |
$statuses=array("1"=>__("Created",'gravity-forms-googlesheets-crm'),"2"=>__("Updated",'gravity-forms-googlesheets-crm'),"error"=>__("Failed",'gravity-forms-googlesheets-crm'),"4"=>__("Filtered",'gravity-forms-googlesheets-crm'),"5"=>__("Deleted",'gravity-forms-googlesheets-crm')); |
| 450 |
|
| 451 |
$menu_links=$this->get_menu_links('log'); |
| 452 |
|
| 453 |
include_once(self::$path . "templates/logs.php"); |
| 454 |
} |
| 455 |
/** |
| 456 |
* Menu links |
| 457 |
* |
| 458 |
*/ |
| 459 |
public function get_menu_links($current_page=""){ |
| 460 |
$settings_link=$this->link_to_settings(); |
| 461 |
$id=isset($_GET['id']) ? sanitize_text_field($_GET['id']) : ''; |
| 462 |
$logs_link=admin_url( "admin.php?page=gf_edit_forms&view=settings&subview={$this->id}&tab=log&id={$id}" ); |
| 463 |
$feeds_link=admin_url( "admin.php?page=gf_edit_forms&view=settings&subview={$this->id}&tab=feed&id={$id}" ); |
| 464 |
|
| 465 |
$menu_links=array( |
| 466 |
'settings'=> array( |
| 467 |
"title"=>__('Google Sheets Settings','gravity-forms-googlesheets-crm'), |
| 468 |
"link"=>$settings_link, |
| 469 |
"current"=>$current_page == 'settings' ? true : false |
| 470 |
), |
| 471 |
'feed'=> array( |
| 472 |
"title"=>__('Google Sheets Feeds','gravity-forms-googlesheets-crm'), |
| 473 |
"link"=>$feeds_link, |
| 474 |
"current"=>$current_page == 'feed' ? true : false |
| 475 |
), |
| 476 |
'log'=> array( |
| 477 |
"title"=>__('Google Sheets Log','gravity-forms-googlesheets-crm'), |
| 478 |
"link"=>$logs_link, |
| 479 |
"current"=>$current_page == 'log' ? true : false |
| 480 |
)); |
| 481 |
$menu_links=apply_filters('menu_links_'.$this->id,$menu_links); |
| 482 |
return $menu_links; |
| 483 |
} |
| 484 |
/** |
| 485 |
* feed link |
| 486 |
* |
| 487 |
* @param mixed $id |
| 488 |
*/ |
| 489 |
public function get_feed_link($id="",$form_id=""){ |
| 490 |
if(empty($form_id) && isset($_GET['id'])){ |
| 491 |
$form_id=$this->post('id'); |
| 492 |
} |
| 493 |
$str="admin.php?page=gf_edit_forms&view=settings&subview={$this->id}&id={$form_id}" ; |
| 494 |
if(!empty($id)){ |
| 495 |
$str.="&tab=feed&fid={$id}"; |
| 496 |
}else{ |
| 497 |
$str.='&tab=feed'; |
| 498 |
} |
| 499 |
return admin_url( $str ); |
| 500 |
} |
| 501 |
/** |
| 502 |
* get logs link |
| 503 |
* |
| 504 |
* @param mixed $id |
| 505 |
*/ |
| 506 |
public function get_log_link($id="",$form_id=""){ |
| 507 |
if(empty($form_id) && isset($_GET['id'])){ |
| 508 |
$form_id=$this->post('id'); |
| 509 |
} |
| 510 |
$str="admin.php?page=gf_edit_forms&view=settings&subview={$this->id}&id={$form_id}" ; |
| 511 |
if(!empty($id)){ |
| 512 |
$str.="&tab=log&log_id={$id}"; |
| 513 |
}else{ |
| 514 |
$str.='&tab=log'; |
| 515 |
} |
| 516 |
return admin_url( $str ); |
| 517 |
} |
| 518 |
|
| 519 |
/** |
| 520 |
* Field mapping HTML |
| 521 |
* |
| 522 |
* @param mixed $feed |
| 523 |
* @param mixed $settings |
| 524 |
* @param mixed $refresh |
| 525 |
* @return mixed |
| 526 |
*/ |
| 527 |
private function get_field_mapping($feed,$info="",$refresh=false){ |
| 528 |
|
| 529 |
|
| 530 |
$fields=array(); |
| 531 |
if($info == ""){ |
| 532 |
$account=$this->post('account',$feed); |
| 533 |
$info=$this->get_info($account); |
| 534 |
} |
| 535 |
|
| 536 |
if(empty($feed['form_id']) || empty($feed['object'])){ |
| 537 |
return ''; |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
$module=''; $form_id=0; |
| 542 |
if(isset($feed['object'])) |
| 543 |
$module=$feed['object']; |
| 544 |
if(isset($feed['form_id'])) |
| 545 |
$form_id=$feed['form_id']; |
| 546 |
// |
| 547 |
$api_type=isset($info['data']['api']) ? $info['data']['api'] : ''; |
| 548 |
$info_meta= isset($info['meta']) && is_array($info['meta']) ? $info['meta'] : array(); |
| 549 |
$feed_meta= isset($feed['meta']) && is_array($feed['meta']) ? $feed['meta'] : array(); |
| 550 |
$info_data= isset($info['data']) && is_array($info['data']) ? $info['data'] : array(); |
| 551 |
|
| 552 |
// |
| 553 |
$meta=isset($feed['data']) && is_array($feed['data']) ? $feed['data'] : array(); |
| 554 |
|
| 555 |
|
| 556 |
$map=isset($meta['map']) && is_array($meta['map']) ? $meta['map'] : array(); |
| 557 |
$tab=isset($meta['tab']) ? $meta['tab'] : ''; |
| 558 |
|
| 559 |
$optin_field=isset($meta['optin_field']) ?$meta['optin_field'] : ''; |
| 560 |
// |
| 561 |
$api_type=$this->post('api',$info_data); |
| 562 |
|
| 563 |
if(!isset($meta['row_type'])){ |
| 564 |
$meta['row_type']=''; |
| 565 |
if(empty($feed['account'])){ |
| 566 |
$meta['row_type']='INSERT_ROWS'; |
| 567 |
} } |
| 568 |
|
| 569 |
if($this->ajax){ |
| 570 |
|
| 571 |
$api=$this->get_api($info); |
| 572 |
|
| 573 |
$fields=$api->get_crm_fields($module,$tab); |
| 574 |
|
| 575 |
if(is_array($fields) && is_array($fields['fields'])){ |
| 576 |
$info_meta['fields']=$fields; |
| 577 |
$info_meta['object']=$module; |
| 578 |
$info_meta['feed_id']=$this->post('id'); |
| 579 |
$this->update_info( array('meta'=>$info_meta),$info['id']); |
| 580 |
} |
| 581 |
}else{ |
| 582 |
$fields=$this->post('fields',$feed_meta); |
| 583 |
} |
| 584 |
|
| 585 |
if(!is_array($fields)){ |
| 586 |
$fields= $fields == "" ? "Error while getting fields" : $fields; |
| 587 |
?> |
| 588 |
<div class="error below-h2"> |
| 589 |
<p><?php echo $fields?></p> |
| 590 |
</div> |
| 591 |
<?php |
| 592 |
return; |
| 593 |
} |
| 594 |
|
| 595 |
$tabs= is_array($fields) && !empty($fields['tabs']) ? $fields['tabs'] : array(); |
| 596 |
$fields= is_array($fields) && !empty($fields['fields']) ? $fields['fields'] : array(); |
| 597 |
|
| 598 |
$vx_op=$this->get_filter_ops(); |
| 599 |
if(isset($meta['filters']) && is_array($meta['filters'])&& count($meta['filters'])>0){ |
| 600 |
$filters=$meta['filters']; |
| 601 |
}else{ |
| 602 |
$filters=array("1"=>array("1"=>array("field"=>""))); |
| 603 |
} |
| 604 |
$has_contact=false; |
| 605 |
$map_fields=array(); |
| 606 |
foreach($fields as $k=>$v){ |
| 607 |
if(count($map_fields)<4){ |
| 608 |
|
| 609 |
$map_fields[$k]=$v; |
| 610 |
} |
| 611 |
} |
| 612 |
//mapping fields |
| 613 |
$n=0; |
| 614 |
foreach($map as $field_k=>$field_v){ |
| 615 |
if(isset($fields[$field_k])){ $n++; |
| 616 |
if($n == 1){ $fields[$field_k]['req']='true'; } |
| 617 |
$map_fields[$field_k]=$fields[$field_k]; |
| 618 |
} |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
$sel_fields=array(""=>__("Standard Field",'gravity-forms-googlesheets-crm'),"value"=>__("Custom Value",'gravity-forms-googlesheets-crm')); |
| 623 |
?> |
| 624 |
<div class="vx_div"> |
| 625 |
<div class="vx_head"> |
| 626 |
<div class="crm_head_div"> <?php esc_html_e('4. Select Google Sheet Tab.', 'gravity-forms-googlesheets-crm'); ?></div> |
| 627 |
<div class="crm_btn_div" title="<?php esc_html_e('Expand / Collapse','gravity-forms-googlesheets-crm') ?>"><i class="fa crm_toggle_btn vx_action_btn fa-minus"></i></div> |
| 628 |
<div class="crm_clear"></div> |
| 629 |
</div> |
| 630 |
|
| 631 |
<div class="vx_group"> |
| 632 |
<div class="vx_row"> |
| 633 |
<div class="vx_col1"> |
| 634 |
<label for="vx_module" class="left_header"><?php esc_html_e("Google Sheets Tab", 'gravity-forms-googlesheets-crm'); ?> |
| 635 |
</label> |
| 636 |
</div> |
| 637 |
<div class="vx_col2"> |
| 638 |
<select id="vx_tab" class="load_form crm_sel" name="meta[tab]" autocomplete="off"> |
| 639 |
<?php |
| 640 |
foreach ($tabs as $k=>$v){ |
| 641 |
$sel=$meta['tab'] == $v ? 'selected="selected"' : ""; |
| 642 |
?> |
| 643 |
<option value="<?php echo esc_attr($v) ?>" <?php echo esc_attr($sel); ?>><?php echo esc_attr($v) ?></option> |
| 644 |
<?php |
| 645 |
} |
| 646 |
?> |
| 647 |
</select> |
| 648 |
</div> |
| 649 |
<div class="clear"></div> |
| 650 |
</div> |
| 651 |
</div> |
| 652 |
</div> |
| 653 |
<?php |
| 654 |
include_once(self::$path . "templates/fields-mapping.php"); |
| 655 |
} |
| 656 |
|
| 657 |
/** |
| 658 |
* Updates feed |
| 659 |
* |
| 660 |
*/ |
| 661 |
public function update_feed(){ |
| 662 |
check_ajax_referer('vx_crm_ajax','vx_crm_ajax'); |
| 663 |
if(!current_user_can($this->id."_edit_feeds")){ |
| 664 |
return; |
| 665 |
} |
| 666 |
$id = $this->post("feed_id"); |
| 667 |
$feed = $this->data->get_feed($id); |
| 668 |
$this->data->update_feed(array("is_active"=>$this->post("is_active")),$id); |
| 669 |
} |
| 670 |
|
| 671 |
/** |
| 672 |
* Update the feed sort order |
| 673 |
* |
| 674 |
* @since 3.1 |
| 675 |
* @return void |
| 676 |
*/ |
| 677 |
public function update_feed_sort(){ |
| 678 |
check_ajax_referer('vx_crm_ajax','vx_crm_ajax'); |
| 679 |
if(!current_user_can($this->id."_edit_feeds")){ |
| 680 |
return; |
| 681 |
} |
| 682 |
if( empty( $_POST['sort'] )) |
| 683 |
{ |
| 684 |
exit(false); |
| 685 |
} |
| 686 |
|
| 687 |
$sort=$this->post('sort'); |
| 688 |
$this->data->update_feed_order($sort); |
| 689 |
} |
| 690 |
public function set_logging_supported($plugins) { |
| 691 |
$slug=$this->plugin_dir_name(); |
| 692 |
$plugins[$slug] = esc_html__('Google Sheets','gravity-forms-googlesheets-crm'); |
| 693 |
return $plugins; |
| 694 |
} |
| 695 |
/** |
| 696 |
* Field map ajax method |
| 697 |
* |
| 698 |
*/ |
| 699 |
public function get_field_map_ajax(){ |
| 700 |
check_ajax_referer('vx_crm_ajax','vx_crm_ajax'); |
| 701 |
if(!current_user_can($this->id."_read_feeds")){ |
| 702 |
return; |
| 703 |
} |
| 704 |
$this->ajax=true; |
| 705 |
//loading Gravity Forms tooltips |
| 706 |
require_once(GFCommon::get_base_path() . "/tooltips.php"); |
| 707 |
$msg=""; |
| 708 |
if(empty($_REQUEST['module'])){ |
| 709 |
$msg=__("Please Choose Object",'gravity-forms-googlesheets-crm'); |
| 710 |
}else if(empty($_REQUEST['form_id'])){ |
| 711 |
$msg=__("Please Choose Form",'gravity-forms-googlesheets-crm'); |
| 712 |
} |
| 713 |
if($msg !=""){ |
| 714 |
?> |
| 715 |
<div class="error below-h2" style="background: #f3f3f3"> |
| 716 |
<p><?php echo wp_kses_post($msg); ?></p> |
| 717 |
</div> |
| 718 |
<?php |
| 719 |
die(); |
| 720 |
} |
| 721 |
$module=$this->post('module'); |
| 722 |
$form_id=$this->post('form_id'); |
| 723 |
$tab=$this->post('tab'); |
| 724 |
$refresh=$_REQUEST['refresh'] == "true" ? true: false; |
| 725 |
$id=$this->post('id'); |
| 726 |
$feed=$this->data->get_feed($id); |
| 727 |
$this->account=$account=$this->post('account'); |
| 728 |
|
| 729 |
$info=$this->get_info($account); |
| 730 |
if(!isset($feed['data'])){ $feed['data']=array(); } |
| 731 |
/* $object=$this->post('object',$feed); |
| 732 |
if(!$refresh && $object != $module){ |
| 733 |
$refresh=true; |
| 734 |
} */ |
| 735 |
$feed['form_id']=$form_id; |
| 736 |
$feed['object']=$module; |
| 737 |
$feed['data']['tab']=$tab; |
| 738 |
|
| 739 |
$this->get_field_mapping($feed,$info,true); |
| 740 |
die(); |
| 741 |
} |
| 742 |
public function get_field_map_object_ajax(){ |
| 743 |
check_ajax_referer('vx_crm_ajax','vx_crm_ajax'); |
| 744 |
if(!current_user_can($this->id."_read_feeds")){ |
| 745 |
return; |
| 746 |
} |
| 747 |
$this->ajax=true; |
| 748 |
//loading Gravity Forms tooltips |
| 749 |
require_once(GFCommon::get_base_path() . "/tooltips.php"); |
| 750 |
$msg=""; |
| 751 |
if(empty($_REQUEST['account'])){ |
| 752 |
$msg=__("Please Choose Account",'gravity-forms-googlesheets-crm'); |
| 753 |
} |
| 754 |
if($msg !=""){ |
| 755 |
?> |
| 756 |
<div class="error below-h2" style="background: #f3f3f3"> |
| 757 |
<p><?php echo wp_kses_post($msg); ?></p> |
| 758 |
</div> |
| 759 |
<?php |
| 760 |
die(); |
| 761 |
} |
| 762 |
$this->account=$account=$this->post('account'); |
| 763 |
$id=$this->post('id'); |
| 764 |
$feed= $this->data->get_feed($id); |
| 765 |
|
| 766 |
$info=$this->get_info($account); |
| 767 |
/* $object=$this->post('object',$feed); |
| 768 |
if(!$refresh && $object != $module){ |
| 769 |
$refresh=true; |
| 770 |
} */ |
| 771 |
$this->field_map_object($account,$feed,$info); |
| 772 |
die(); |
| 773 |
} |
| 774 |
/** |
| 775 |
* available operators for custom filters |
| 776 |
* |
| 777 |
*/ |
| 778 |
public function get_filter_ops(){ |
| 779 |
return array("is"=>"Exactly Matches","is_not"=>"Does Not Exactly Match","contains"=>"(Text) Contains","not_contains"=>"(Text) Does Not Contain","is_in"=>"(Text) Is In","not_in"=>"(Text) Is Not In","starts"=>"(Text) Starts With","not_starts"=>"(Text) Does Not Start With","ends"=>"(Text) Ends With","not_ends"=>"(Text) Does Not End With","less"=>"(Number) Less Than","greater"=>"(Number) Greater Than","less_date"=>"(Date/Time) Less Than","greater_date"=>"(Date/Time) Greater Than","equal_date"=>"(Date/Time) Equals","empty"=>"Is Empty","not_empty"=>"Is Not Empty"); |
| 780 |
} |
| 781 |
/** |
| 782 |
* crm fields select options |
| 783 |
* |
| 784 |
* @param mixed $fields |
| 785 |
* @param mixed $selected |
| 786 |
*/ |
| 787 |
public function crm_select($fields,$selected,$first_empty=true){ |
| 788 |
$field_options=""; |
| 789 |
if($first_empty){ |
| 790 |
$field_options="<option value=''></option>"; |
| 791 |
} |
| 792 |
if(is_array($fields)){ |
| 793 |
foreach($fields as $k=>$v){ |
| 794 |
if(isset($v['label'])){ |
| 795 |
$sel=$selected == $k ? 'selected="selected"' : ""; |
| 796 |
$field_options.="<option value='".$k."' ".$sel.">".$v['label']."</option>"; |
| 797 |
} |
| 798 |
} |
| 799 |
} |
| 800 |
return $field_options; |
| 801 |
} |
| 802 |
/** |
| 803 |
* general(key/val) select options |
| 804 |
* |
| 805 |
* @param mixed $fields |
| 806 |
* @param mixed $selected |
| 807 |
*/ |
| 808 |
public function gen_select($fields,$selected,$placeholder=""){ |
| 809 |
$field_options=''; |
| 810 |
if($placeholder!= false){ |
| 811 |
$field_options="<option value=''>".$placeholder."</option>"; |
| 812 |
} |
| 813 |
if(is_array($fields)){ |
| 814 |
foreach($fields as $k=>$v){ |
| 815 |
$sel=$selected == $k ? 'selected="selected"' : ""; |
| 816 |
$field_options.='<option value="'.esc_attr($k).'" '.$sel.'>'.esc_html($v).'</option>'; |
| 817 |
} |
| 818 |
} |
| 819 |
return $field_options; |
| 820 |
} |
| 821 |
/** |
| 822 |
* refresh data , ajax method |
| 823 |
* |
| 824 |
*/ |
| 825 |
public function refresh_data(){ |
| 826 |
check_ajax_referer("vx_crm_ajax","vx_crm_ajax"); |
| 827 |
if(!current_user_can($this->id."_read_settings")){ |
| 828 |
die(); |
| 829 |
} |
| 830 |
$res=array(); |
| 831 |
$action=$this->post('vx_action'); |
| 832 |
$camp_id_sel=$this->post('camp_id'); |
| 833 |
|
| 834 |
$account=$this->post('account'); |
| 835 |
$status_sel=$this->post('status'); |
| 836 |
$owner_sel=$this->post('owner'); |
| 837 |
|
| 838 |
$info=array(); $meta=array(); |
| 839 |
if(!empty($account)){ |
| 840 |
$info=$this->get_info($account); |
| 841 |
if(!empty($info['meta']) ){ |
| 842 |
$meta=$info['meta']; |
| 843 |
} |
| 844 |
} |
| 845 |
$api=$this->get_api($info); |
| 846 |
switch($action){ |
| 847 |
case"refresh_campaigns": |
| 848 |
$camps=$api->get_campaigns(); |
| 849 |
$status_list=$api->get_member_status(); //var_dump($status_list); die(); |
| 850 |
|
| 851 |
$data=array(); |
| 852 |
if(is_array($status_list)){ |
| 853 |
$res['status']="ok"; |
| 854 |
$data['crm_sel_camp']=$this->gen_select($camps,$status_sel,__('Select Campaign','gravity-forms-googlesheets-crm')); |
| 855 |
$meta['member_status']=$status_list; |
| 856 |
}else{ |
| 857 |
$res['error']=$status_list; |
| 858 |
} |
| 859 |
if(is_array($camps)){ |
| 860 |
$res['status']="ok"; |
| 861 |
$data['crm_sel_status']=$this->gen_select($status_list,$camp_id_sel,__('Select Status','gravity-forms-googlesheets-crm')); |
| 862 |
$meta['campaigns']=$camps; |
| 863 |
}else{ |
| 864 |
$res['error']=$camps; |
| 865 |
} |
| 866 |
|
| 867 |
$res['data']=$data; |
| 868 |
break; |
| 869 |
case"refresh_users": |
| 870 |
$users=$api->get_users(); |
| 871 |
|
| 872 |
$data=array(); |
| 873 |
if(is_array($users)){ |
| 874 |
$res['status']="ok"; |
| 875 |
$data['crm_sel_user']=$this->gen_select($users,$owner_sel,__('Select User','gravity-forms-googlesheets-crm')); |
| 876 |
$meta['users']=$users; |
| 877 |
}else{ |
| 878 |
$res['error']=$users; |
| 879 |
} |
| 880 |
|
| 881 |
$res['data']=$data; |
| 882 |
break; |
| 883 |
|
| 884 |
} |
| 885 |
|
| 886 |
if(isset($info['id'])){ |
| 887 |
$this->update_info( array("meta"=>$meta) , $info['id'] ); |
| 888 |
} |
| 889 |
if(isset($res['error'])){ |
| 890 |
$res['status']='error'; |
| 891 |
if(empty($res['error'])){ |
| 892 |
$res['error']=__('Unknown Error','gravity-forms-googlesheets-crm'); |
| 893 |
} |
| 894 |
} |
| 895 |
die(json_encode($res)); |
| 896 |
} |
| 897 |
/** |
| 898 |
* plugin start |
| 899 |
* |
| 900 |
*/ |
| 901 |
public function setup_plugin(){ |
| 902 |
|
| 903 |
if(isset($_REQUEST[$this->id.'_tab_action']) && $_REQUEST[$this->id.'_tab_action']=="get_code" && current_user_can($this->id."_edit_settings")){ |
| 904 |
$state=urldecode($this->post('state')); |
| 905 |
//$state=str_replace("-__-","&",$state); |
| 906 |
|
| 907 |
if(isset($_REQUEST['code'])){ |
| 908 |
$state.='&code='.$this->post('code'); |
| 909 |
} |
| 910 |
if(isset($_REQUEST['error'])){ |
| 911 |
$state.='&error='.$this->post('error'); |
| 912 |
} |
| 913 |
//esc_url($link).'&'.$this->id."_tab_action=get_token&vx_action=redirect&id=".$id."&vx_nonce=".$nonce |
| 914 |
wp_safe_redirect($state); |
| 915 |
die(); |
| 916 |
} |
| 917 |
|
| 918 |
if(isset($_REQUEST[$this->id.'_tab_action']) && $_REQUEST[$this->id.'_tab_action']=="get_token"){ |
| 919 |
check_admin_referer('vx_nonce','vx_nonce'); |
| 920 |
if(!current_user_can($this->id."_edit_settings")){ |
| 921 |
$msg=__('You do not have permissions to add token','gravity-forms-googlesheets-crm'); |
| 922 |
$this->display_msg('admin',$msg); |
| 923 |
return; |
| 924 |
} |
| 925 |
$id=$this->post('id'); |
| 926 |
$info=$this->get_info($id); |
| 927 |
$api=$this->get_api($info); |
| 928 |
$info_data=$api->handle_code(); |
| 929 |
//var_dump($info_data); die(); |
| 930 |
$redir=$this->link_to_settings(); |
| 931 |
wp_redirect($redir.'&id='.$id); |
| 932 |
die(); |
| 933 |
} |
| 934 |
|
| 935 |
if(isset($_REQUEST[$this->id.'_tab_action']) && $_REQUEST[$this->id.'_tab_action']=="del_account"){ |
| 936 |
check_admin_referer('vx_nonce','vx_nonce'); |
| 937 |
if( current_user_can($this->id."_edit_settings")){ |
| 938 |
$id=$this->post('id'); |
| 939 |
$data=$this->get_data_object(); |
| 940 |
$res=$data->del_account($id); |
| 941 |
if($res){ |
| 942 |
$msg=__('Account Deleted Successfully','gravity-forms-googlesheets-crm'); |
| 943 |
$msg_arr=array('msg'=>$msg,'class'=>'updated'); |
| 944 |
}else{ |
| 945 |
$msg=__('Error While Removing Account','gravity-forms-googlesheets-crm'); |
| 946 |
$msg_arr=array('msg'=>$msg,'class'=>'error'); |
| 947 |
} |
| 948 |
update_option($this->id.'_msg',$msg_arr); |
| 949 |
} |
| 950 |
$redir=$this->link_to_settings(); |
| 951 |
wp_redirect($redir.'&'.$this->id.'_msg=1'); |
| 952 |
die(); |
| 953 |
} |
| 954 |
|
| 955 |
|
| 956 |
} |
| 957 |
/** |
| 958 |
* Log detail |
| 959 |
* |
| 960 |
*/ |
| 961 |
public function log_detail(){ |
| 962 |
$log_id=$this->post('id'); |
| 963 |
$log=$this->data->get_log_by_id($log_id); |
| 964 |
$data=json_decode($log['data'],true); |
| 965 |
$response=json_decode($log['response'],true); |
| 966 |
$triggers=array('manual'=>'Submitted Manually','submit'=>'Form Submission','after_submit'=>'After Form Submission','paid'=>'Payment Completed','update'=>'Entry Update' |
| 967 |
,'delete'=>'Entry Deletion','add_note'=>'Entry Note Created','delete_note'=>'Entry Note Deleted','restore'=>'Entry Restored'); |
| 968 |
$event= empty($log['event']) ? 'manual' : $log['event']; |
| 969 |
$extra=array('Object'=>$log['object']); |
| 970 |
if(isset($triggers[$event])){ |
| 971 |
$extra['Trigger']=$triggers[$event]; |
| 972 |
} |
| 973 |
$extra_log=json_decode($log['extra'],true); |
| 974 |
if(is_array($extra_log)){ |
| 975 |
$extra=array_merge($extra,$extra_log); |
| 976 |
} |
| 977 |
$error=true; |
| 978 |
$vx_ops=$this->get_filter_ops(); |
| 979 |
$form_id=$this->post('form_id',$log); |
| 980 |
$labels=array("url"=>"URL","body"=>"Search Body","response"=>"Search Response","filter"=>"Filter",'note_object_link'=>'Note Object ID'); |
| 981 |
include_once(self::$path . "templates/log.php"); |
| 982 |
die(); |
| 983 |
} |
| 984 |
|
| 985 |
/** |
| 986 |
* Get Objects , AJAX method |
| 987 |
* @return null |
| 988 |
*/ |
| 989 |
public function get_objects_ajax(){ |
| 990 |
check_ajax_referer('vx_crm_ajax','vx_crm_ajax'); |
| 991 |
|
| 992 |
$object=$this->post('object'); |
| 993 |
$account=$this->post('account'); |
| 994 |
$info=$this->get_info($account); |
| 995 |
|
| 996 |
$objects=$this->get_objects($info,true); |
| 997 |
|
| 998 |
$field_options="<option>".__("Select Google Sheet",'gravity-forms-googlesheets-crm')."</option>"; |
| 999 |
if(is_array($objects)){ |
| 1000 |
foreach($objects as $k=>$v){ |
| 1001 |
$sel=""; |
| 1002 |
if($k == $object){ |
| 1003 |
$sel='selected="selected"'; |
| 1004 |
} |
| 1005 |
$field_options.='<option value="'.esc_attr($k).'" '.$sel.'>'.esc_html($v).'</option>'; |
| 1006 |
} |
| 1007 |
} |
| 1008 |
echo $field_options; |
| 1009 |
|
| 1010 |
die(); |
| 1011 |
} |
| 1012 |
|
| 1013 |
public function get_object_feeds($form_id,$account,$object,$skip=''){ |
| 1014 |
$feeds=$this->data->get_object_feeds($form_id,$account,$object,$skip); |
| 1015 |
$arr=array(); |
| 1016 |
if(is_array($feeds) && count($feeds)>0){ |
| 1017 |
foreach($feeds as $k=>$feed){ |
| 1018 |
if(isset($feed['id'])){ |
| 1019 |
$arr[$feed['id']]=$feed['name']; |
| 1020 |
} |
| 1021 |
} |
| 1022 |
} |
| 1023 |
return $arr; |
| 1024 |
} |
| 1025 |
|
| 1026 |
/** |
| 1027 |
* Settings page |
| 1028 |
* |
| 1029 |
*/ |
| 1030 |
public function settings_page(){ |
| 1031 |
if(!current_user_can($this->id.'_read_settings')){ |
| 1032 |
$msg_text=__('You do not have permissions to access this page','gravity-forms-googlesheets-crm'); |
| 1033 |
$this->display_msg('admin',$msg_text); |
| 1034 |
return; |
| 1035 |
} |
| 1036 |
$is_section=apply_filters('add_page_html_'.$this->id,false); |
| 1037 |
|
| 1038 |
if($is_section === true){ |
| 1039 |
return; |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
$msgs=array(); $lic_key=false; |
| 1044 |
$message=$force_check= false; |
| 1045 |
$offset=$this->time_offset(); |
| 1046 |
$id=$this->post('id'); |
| 1047 |
if(!empty($_POST[$this->id."_uninstall"])){ |
| 1048 |
check_admin_referer("vx_nonce"); |
| 1049 |
if(!current_user_can($this->id."_uninstall")){ |
| 1050 |
return; |
| 1051 |
} |
| 1052 |
$this->uninstall(); |
| 1053 |
$uninstall_msg=sprintf(__("Gravity Forms Google Sheets Plugin has been successfully uninstalled. It can be re-activated from the %s plugins page %s.", 'gravity-forms-googlesheets-crm'),"<a href='plugins.php'>","</a>"); |
| 1054 |
$this->screen_msg($uninstall_msg); |
| 1055 |
return; |
| 1056 |
} |
| 1057 |
else if(!empty($_POST['crm'])){ |
| 1058 |
check_admin_referer("vx_nonce"); |
| 1059 |
if(!current_user_can($this->id."_edit_settings")){ |
| 1060 |
$msg=__('You do not have permissions to save settings','gravity-forms-googlesheets-crm'); |
| 1061 |
$this->display_msg('admin',$msg); |
| 1062 |
return; |
| 1063 |
} |
| 1064 |
$msgs['submit']=array('class'=>'updated','msg'=>__('Settings Changed Successfully','gravity-forms-googlesheets-crm')); |
| 1065 |
$valid_email=true; |
| 1066 |
if($this->post('error_email',$_POST['crm']) !=""){ |
| 1067 |
$emails=explode(",",$this->post('error_email',$_POST['crm'])); |
| 1068 |
foreach($emails as $email){ |
| 1069 |
$email=trim($email); |
| 1070 |
if($email !="" && !$this->is_valid_email($email)){ |
| 1071 |
$valid_email=false; |
| 1072 |
} |
| 1073 |
} |
| 1074 |
} |
| 1075 |
if(!$valid_email){ |
| 1076 |
$msgs['submit']=array("class"=>"error","msg"=>__('Invalid Email(s)','gravity-forms-googlesheets-crm')); |
| 1077 |
} |
| 1078 |
$crm=$this->get_info($id); |
| 1079 |
$data=isset($crm['data']) && is_array($crm['data']) ? $crm['data'] : array(); |
| 1080 |
///////////// |
| 1081 |
$crm_post=$this->post('crm'); |
| 1082 |
$data=array_merge($data,$crm_post); |
| 1083 |
$data['custom_app']=$this->post('custom_app',$crm_post); |
| 1084 |
|
| 1085 |
//$data=json_decode($json,1); |
| 1086 |
$this->update_info(array('data'=> $data),$id); |
| 1087 |
$force_check=true; |
| 1088 |
//////////////////// |
| 1089 |
} |
| 1090 |
|
| 1091 |
$data=$this->get_data_object(); |
| 1092 |
$new_account_id=$data->get_new_account(); |
| 1093 |
$page_link=$this->link_to_settings(); |
| 1094 |
$new_account=$page_link."&id=".$new_account_id; |
| 1095 |
if(!empty($id)){ |
| 1096 |
$info=$this->get_info($id); |
| 1097 |
if(!is_array($info) || !isset($info['id'])){ |
| 1098 |
$id=""; |
| 1099 |
} } |
| 1100 |
if(!empty($id)){ |
| 1101 |
$valid_user=false; |
| 1102 |
|
| 1103 |
$api=$this->get_api($info); |
| 1104 |
/// $res=$api->get_crm_objects(); var_dump($res); die(); |
| 1105 |
if(empty($_POST)){ |
| 1106 |
$api->timeout="5"; |
| 1107 |
} |
| 1108 |
$client=$api->client_info(); |
| 1109 |
// $token=$api->get_crm_objects(); var_dump($token); |
| 1110 |
// $token=$api->get_crm_fields('1DlqOHRI7oURppt23n_VQ0kybvfiqZ00WMXh9GFarplA'); var_dump($token); |
| 1111 |
$link=$this->link_to_settings(); |
| 1112 |
|
| 1113 |
if(!$force_check && isset($_POST['vx_test_connection'])){ |
| 1114 |
$force_check=true; |
| 1115 |
} |
| 1116 |
// |
| 1117 |
if($this->post('vx_tab_action')== "refresh_lists_".$this->id){ |
| 1118 |
check_admin_referer('vx_nonce'); |
| 1119 |
if(!current_user_can($this->id."_read_settings")){ |
| 1120 |
$msg=__('You do not have permissions to refresh lists','gravity-forms-googlesheets-crm'); |
| 1121 |
$this->display_msg('admin',$msg); |
| 1122 |
return; |
| 1123 |
} |
| 1124 |
$meta=$this->post('meta',$info); |
| 1125 |
if(isset($meta['lists'])){ |
| 1126 |
unset($meta['lists']); |
| 1127 |
} |
| 1128 |
$this->update_info(array('meta'=>$meta),$id); |
| 1129 |
$msgs['refresh']=array("class"=>"updated","msg"=>__('Successfully Refreshed Picklists','gravity-forms-googlesheets-crm')); |
| 1130 |
|
| 1131 |
} |
| 1132 |
|
| 1133 |
$force_check=false; |
| 1134 |
if(isset($_POST['vx_test_connection']) || isset($_POST['crm'])){ |
| 1135 |
$force_check=true; |
| 1136 |
} |
| 1137 |
|
| 1138 |
//verify connection |
| 1139 |
$info=$this->validate_api($info,$force_check); |
| 1140 |
// $tooltips=self::$tooltips ; |
| 1141 |
$conn_class=$this->post('class',$info); |
| 1142 |
if(!empty($conn_class)){ |
| 1143 |
$msgs['connection']=array('class'=>$info['class'],'msg'=>$info['msg']); |
| 1144 |
} |
| 1145 |
if(isset($_POST['vx_test_connection'])){ |
| 1146 |
$msg=__('Connection to Google Sheets is Working','gravity-forms-googlesheets-crm'); |
| 1147 |
|
| 1148 |
if($conn_class != "updated" ){ |
| 1149 |
$msg=__('Connection to Google Sheets is NOT Working','gravity-forms-googlesheets-crm'); |
| 1150 |
} |
| 1151 |
$title=__('Test Connection: ','gravity-forms-googlesheets-crm'); |
| 1152 |
$msgs['test']=array('class'=>$conn_class,'msg'=>'<b>'.$title.'</b>'.$msg); |
| 1153 |
} |
| 1154 |
if(isset($_GET['vx_debug'])){ |
| 1155 |
$msgs['debug']=array('class'=>'error','msg'=>json_encode($info)); |
| 1156 |
} |
| 1157 |
}else{ |
| 1158 |
$accounts=$data->get_accounts(); |
| 1159 |
|
| 1160 |
} |
| 1161 |
$meta=get_option($this->type.'_settings',array()); |
| 1162 |
|
| 1163 |
if(!empty($_POST['save'])){ |
| 1164 |
check_admin_referer("vx_nonce"); |
| 1165 |
if(current_user_can($this->id."_edit_settings")){ |
| 1166 |
|
| 1167 |
$meta=$this->post('meta'); if(!is_array($meta)){ $meta=array(); } |
| 1168 |
|
| 1169 |
$msgs['submit']=array('class'=>'updated','msg'=>__('Settings Changed Successfully','gravity-forms-googlesheets-crm')); |
| 1170 |
update_option($this->type.'_settings',$meta); |
| 1171 |
} |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
$nonce=wp_create_nonce("vx_nonce"); |
| 1176 |
include_once(self::$path . "templates/settings.php"); |
| 1177 |
|
| 1178 |
} |
| 1179 |
|
| 1180 |
/** |
| 1181 |
* Create or edit crm feed page |
| 1182 |
* |
| 1183 |
*/ |
| 1184 |
private function edit_page($fid=""){ |
| 1185 |
if(!current_user_can($this->id.'_read_feeds')){ |
| 1186 |
esc_html_e('You do not have permissions to access this page','gravity-forms-googlesheets-crm'); |
| 1187 |
return; |
| 1188 |
} |
| 1189 |
$base_url=$this->get_base_url(); |
| 1190 |
$sel2_js=$base_url. 'js/select2.min.js'; |
| 1191 |
$sel2_css=$base_url. 'css/select2.min.css'; |
| 1192 |
$is_section=apply_filters('add_page_html_'.$this->id,false); |
| 1193 |
|
| 1194 |
if($is_section === true){ |
| 1195 |
return; |
| 1196 |
} |
| 1197 |
|
| 1198 |
if(!function_exists('$this->tooltip')) { |
| 1199 |
require_once(GFCommon::get_base_path() . "/tooltips.php"); |
| 1200 |
} |
| 1201 |
$feed= $this->data->get_feed($fid); |
| 1202 |
|
| 1203 |
//updating meta information |
| 1204 |
if(isset($_POST[$this->id."_submit"])){ |
| 1205 |
check_admin_referer("vx_nonce"); |
| 1206 |
if(!current_user_can($this->id.'_edit_feeds')){ |
| 1207 |
esc_html_e('You do not have permissions to edit/save feed','gravity-forms-googlesheets-crm'); |
| 1208 |
return; |
| 1209 |
} |
| 1210 |
// |
| 1211 |
$time = current_time( 'mysql' ,1); |
| 1212 |
$feed_update=array("data"=>$this->post("meta"),"name"=>$this->post('name'),"account"=>$this->post('account'),"object"=>$this->post('object'),"form_id"=>$this->post('form_id'),"time"=>$time); |
| 1213 |
if(!empty($_POST['account'])){ |
| 1214 |
$info=$this->get_info($this->post('account')); |
| 1215 |
|
| 1216 |
if(isset($info['meta']['feed_id']) && isset($info['meta']['fields']) && !empty($info['meta']['feed_id']) && $info['meta']['feed_id'] == $fid && !empty($info['meta']['object']) && $info['meta']['object'] == $feed_update['object']){ |
| 1217 |
$meta=isset($feed['meta']) && is_array($feed['meta']) ? $feed['meta'] : array(); |
| 1218 |
$meta['fields']=$info['meta']['fields']; |
| 1219 |
$feed_update['meta']=$meta; |
| 1220 |
unset($info['meta']['feed_id']); |
| 1221 |
|
| 1222 |
$this->update_info(array('meta'=>$info['meta']),$info['id']); |
| 1223 |
} } |
| 1224 |
if(is_array($feed_update) && is_array($feed)){ |
| 1225 |
$feed=array_merge($feed,$feed_update); |
| 1226 |
} |
| 1227 |
$is_valid=$this->data->update_feed($feed_update,$fid); |
| 1228 |
|
| 1229 |
$msg=''; $class='updated'; |
| 1230 |
if($is_valid){ |
| 1231 |
$feed_link=$this->get_feed_link(); |
| 1232 |
$msg=sprintf(__("Feed Updated. %sback to list%s", 'gravity-forms-googlesheets-crm'), '<a href="'.$feed_link.'">', "</a>"); |
| 1233 |
} |
| 1234 |
else{ |
| 1235 |
$msg=__("Feed could not be updated. Please enter all required information below.", 'gravity-forms-googlesheets-crm'); |
| 1236 |
$class='error'; |
| 1237 |
} |
| 1238 |
if(!empty($msg)){ |
| 1239 |
$this->screen_msg($msg,$class); |
| 1240 |
} |
| 1241 |
} |
| 1242 |
//getting API |
| 1243 |
$menu_links=$this->get_menu_links('feed'); |
| 1244 |
$_data=$this->get_data_object(); |
| 1245 |
$accounts=$_data->get_accounts(true); |
| 1246 |
|
| 1247 |
|
| 1248 |
$this->account=$account=$this->post('account',$feed); |
| 1249 |
$info=$this->get_info($account); |
| 1250 |
$form_id=isset($_GET['id']) ? $this->post('id') : ''; |
| 1251 |
if(!empty($_POST['form_id'])){ |
| 1252 |
$form_id=$this->post('form_id'); |
| 1253 |
} |
| 1254 |
$config = $this->data->get_feed('new_form'); |
| 1255 |
$new_feed_link=$this->get_feed_link($config['id']); |
| 1256 |
if(!self::$is_pr){ |
| 1257 |
$total=$this->data->get_feeds_total(); |
| 1258 |
if($total > 2){ |
| 1259 |
$new_feed_link='#'; |
| 1260 |
} |
| 1261 |
} |
| 1262 |
|
| 1263 |
$feeds_link=admin_url( "admin.php?page=gf_edit_forms&view=settings&subview={$this->id}&tab=feed&id=$form_id" ); |
| 1264 |
|
| 1265 |
include_once(self::$path . "templates/feed-account.php"); |
| 1266 |
} |
| 1267 |
/** |
| 1268 |
* field mapping box's Contents |
| 1269 |
* |
| 1270 |
*/ |
| 1271 |
public function field_map_object($account,$feed,$info) { |
| 1272 |
|
| 1273 |
|
| 1274 |
$api_type=$this->post('api',$info); |
| 1275 |
|
| 1276 |
//get objects from crm |
| 1277 |
$objects=$this->get_objects($info); |
| 1278 |
|
| 1279 |
if(empty($feed['object'])){ |
| 1280 |
$feed['object']=""; |
| 1281 |
} |
| 1282 |
if(!empty($feed['object']) && is_array($objects) && !isset($objects[$feed['object']])){ |
| 1283 |
$feed['object']=""; |
| 1284 |
} |
| 1285 |
|
| 1286 |
$meta=$this->post('meta',$info); |
| 1287 |
|
| 1288 |
if(!is_array($objects) && !empty($objects)){ |
| 1289 |
$this->screen_msg($objects,'error'); |
| 1290 |
return; |
| 1291 |
} |
| 1292 |
|
| 1293 |
include_once(self::$path."templates/feed-object.php"); |
| 1294 |
} |
| 1295 |
/** |
| 1296 |
* Formats Log table row |
| 1297 |
* |
| 1298 |
* @param mixed $row |
| 1299 |
*/ |
| 1300 |
public function verify_log($row,$objects=''){ |
| 1301 |
$crm_id=$link="N/A"; $desc="Added to "; |
| 1302 |
$status_imgs=array("1"=>"created","5"=>"deleted","2"=>"updated","4"=>"filtered"); |
| 1303 |
|
| 1304 |
if($objects == ''){ |
| 1305 |
$objects=$this->get_objects(""); |
| 1306 |
} |
| 1307 |
if(isset($objects[$row['object']])){ |
| 1308 |
$row['object']=$objects[$row['object']]; |
| 1309 |
} |
| 1310 |
if( !empty($row['status'])){ |
| 1311 |
if($row['link'] !=""){ |
| 1312 |
$title='Row #'.$row['crm_id']; |
| 1313 |
if (filter_var($row['link'], FILTER_VALIDATE_URL) === true) { |
| 1314 |
$title=basename($row['link']); |
| 1315 |
} |
| 1316 |
$link='<a href="'.$row['link'].'" title="'.$row['crm_id'].'" target="_blank">'.$title.'</a>'; |
| 1317 |
$crm_id=$row['crm_id']; |
| 1318 |
} |
| 1319 |
if($row['status'] == 2){ |
| 1320 |
$desc="Updated to "; |
| 1321 |
} |
| 1322 |
if($row['status'] == 3){ |
| 1323 |
$row['status']=1; |
| 1324 |
$desc.=" Web2".$row['object']; |
| 1325 |
}else if($row['status'] == 4){ |
| 1326 |
$desc=sprintf(__('%s Filtered','gravity-forms-googlesheets-crm'),$row['object']); |
| 1327 |
}else if($row['status'] == 5){ |
| 1328 |
$desc=sprintf(__('%s Deleted','gravity-forms-googlesheets-crm'),$row['object']); |
| 1329 |
}else{ |
| 1330 |
$desc.=$row['object']; |
| 1331 |
} |
| 1332 |
}else{ |
| 1333 |
$desc= !empty($row['error']) ? $row['error'] : "Unknown Error"; |
| 1334 |
} |
| 1335 |
|
| 1336 |
$title=__("Failed",'gravity-forms-googlesheets-crm'); |
| 1337 |
if( $row['status'] == 1){ |
| 1338 |
$title=__("Created",'gravity-forms-googlesheets-crm'); |
| 1339 |
}else if($row['status'] == 2){ |
| 1340 |
$title=__("Updated",'gravity-forms-googlesheets-crm'); |
| 1341 |
}else if($row['status'] == 4){ |
| 1342 |
$title=__("Filtered",'gravity-forms-googlesheets-crm'); |
| 1343 |
}else if($row['status'] == 5){ |
| 1344 |
$title=__("Deleted",'gravity-forms-googlesheets-crm'); |
| 1345 |
} |
| 1346 |
$row['status_img']=isset($status_imgs[$row["status"]]) ? $status_imgs[$row["status"]] : 'failed'; |
| 1347 |
$row['_crm_id']= $crm_id; |
| 1348 |
$row['a_link']=$link; |
| 1349 |
$row['desc']=$desc; |
| 1350 |
$row['title']=$title; |
| 1351 |
return $row; |
| 1352 |
} |
| 1353 |
/** |
| 1354 |
* gravity forms form fields |
| 1355 |
* |
| 1356 |
* @param mixed $form_id |
| 1357 |
*/ |
| 1358 |
public function get_gf_fields($form_id,$account='',$feed_id=''){ |
| 1359 |
if($this->fields){ |
| 1360 |
return $this->fields; |
| 1361 |
} |
| 1362 |
$form = RGFormsModel::get_form_meta($form_id); |
| 1363 |
$fields = array(); |
| 1364 |
|
| 1365 |
//Adding default fields |
| 1366 |
$form_fields = rgar( $form, 'fields' ); |
| 1367 |
|
| 1368 |
$skip_inputs=array('checkbox','select','time','date','radio','poll','multi_choice'); //multi_choice |
| 1369 |
if(is_array($form_fields)){ |
| 1370 |
foreach($form_fields as $field){ |
| 1371 |
//if(!isset($field->type)){ $field->type=''; } |
| 1372 |
if(isset($field["inputs"]) && is_array($field["inputs"]) && !in_array($field->type ,$skip_inputs) ){ |
| 1373 |
|
| 1374 |
$field_type=RGFormsModel::get_input_type($field); |
| 1375 |
//If this is an address field, add full name to the list |
| 1376 |
if( $field_type == "address") { |
| 1377 |
$fields[] = array($field["id"], GFCommon::get_label($field) . " (" . _x("Full" , 'Full field label', 'gravity-forms-googlesheets-crm') . ")"); |
| 1378 |
} |
| 1379 |
|
| 1380 |
foreach($field["inputs"] as $input) |
| 1381 |
$fields[] = array($input["id"], GFCommon::get_label($field, $input["id"])); |
| 1382 |
} |
| 1383 |
else if(empty($field["displayOnly"])){ |
| 1384 |
if(!self::$is_pr && in_array($field->type,array('phone','fileupload'))){ continue; } |
| 1385 |
$field_label=GFCommon::get_label($field); |
| 1386 |
if(empty($field_label) && isset($field->type)){ |
| 1387 |
$field_label=$field->type.' - '.$field->id; |
| 1388 |
} |
| 1389 |
$fields[] = array($field["id"], $field_label); |
| 1390 |
} |
| 1391 |
} |
| 1392 |
} |
| 1393 |
|
| 1394 |
$fields[]=array('id',__('Entry ID','gravity-forms-googlesheets-crm')); |
| 1395 |
$fields[]=array('form_id',__('Form ID','gravity-forms-googlesheets-crm')); |
| 1396 |
$fields[]=array('entry_url',__('Entry URL','gravity-forms-googlesheets-crm')); |
| 1397 |
$fields[]=array('date_created',__('Entry Date','gravity-forms-googlesheets-crm')); |
| 1398 |
$fields[]=array('ip',__('User IP','gravity-forms-googlesheets-crm')); |
| 1399 |
$fields[]=array('source_url',__('Source Url','gravity-forms-googlesheets-crm')); |
| 1400 |
$fields[]=array('form_title',__('Form Title','gravity-forms-googlesheets-crm')); |
| 1401 |
$fields[]=array('status',__('Entry Status','gravity-forms-googlesheets-crm')); |
| 1402 |
$fields[]=array('payment_status',__('Payment Status','gravity-forms-googlesheets-crm')); |
| 1403 |
$fields[]=array('payment_date',__('Payment Date','gravity-forms-googlesheets-crm')); |
| 1404 |
$fields[]=array('payment_amount',__('Payment Amount','gravity-forms-googlesheets-crm')); |
| 1405 |
$fields[]=array('transaction_id',__('Transaction Id','gravity-forms-googlesheets-crm')); |
| 1406 |
$fields[]=array('currency',__('Currency','gravity-forms-googlesheets-crm')); |
| 1407 |
$this->fields=array('gf'=>array("title"=>__('Gravity Forms Fields','gravity-forms-googlesheets-crm'),"fields"=>$fields)); |
| 1408 |
|
| 1409 |
if(self::$is_pr){ |
| 1410 |
$fields=apply_filters('vx_mapping_standard_fields',$this->fields); |
| 1411 |
$contact_feeds=$this->get_object_feeds($form_id,$account,'',$feed_id); |
| 1412 |
// var_dump($contact_feeds,$form_id,$account,$feed_id); |
| 1413 |
$feeds=array(); |
| 1414 |
if(!empty($contact_feeds)){ |
| 1415 |
foreach($contact_feeds as $k=>$v){ |
| 1416 |
$feeds['_vx_feed-'.$k]=array('id'=>'_vx_feed-'.$k,'label'=>$v); |
| 1417 |
} |
| 1418 |
$fields['feeds']=array("title"=>__('ID from other Feeds','gravity-forms-googlesheets-crm'),"fields"=>$feeds); |
| 1419 |
} |
| 1420 |
$this->fields=$fields; |
| 1421 |
} |
| 1422 |
|
| 1423 |
|
| 1424 |
return $this->fields; |
| 1425 |
} |
| 1426 |
/** |
| 1427 |
* gravity forms fields label |
| 1428 |
* |
| 1429 |
* @param mixed $form_id |
| 1430 |
* @param mixed $key |
| 1431 |
*/ |
| 1432 |
public function get_gf_field_label($form_id,$key){ |
| 1433 |
$fields=$this->get_gf_fields($form_id); |
| 1434 |
$label=$key; |
| 1435 |
if(is_array($fields)){ |
| 1436 |
foreach($fields as $ke=>$field){ |
| 1437 |
if(isset($field['fields']) && is_array($field['fields']) ){ |
| 1438 |
foreach($field['fields'] as $k=>$v){ |
| 1439 |
if($ke == "gf"){ |
| 1440 |
$k=$v[0]; |
| 1441 |
} |
| 1442 |
if($k == $key ){ |
| 1443 |
if($ke == "gf"){ |
| 1444 |
$label=$v[1]; |
| 1445 |
}else if(isset($v['label'])){ |
| 1446 |
$label= $v['label']; |
| 1447 |
} |
| 1448 |
|
| 1449 |
} |
| 1450 |
|
| 1451 |
} |
| 1452 |
} |
| 1453 |
|
| 1454 |
}} |
| 1455 |
|
| 1456 |
return $label; |
| 1457 |
} |
| 1458 |
/** |
| 1459 |
* gravity forms field select options |
| 1460 |
* |
| 1461 |
* @param mixed $form_id |
| 1462 |
* @param mixed $selected_val |
| 1463 |
*/ |
| 1464 |
public function gf_fields_options($form_id,$sel_val='',$account='',$feed_id=''){ |
| 1465 |
if($this->fields == null){ |
| 1466 |
$this->fields=$this->get_gf_fields($form_id,$account,$feed_id); |
| 1467 |
} |
| 1468 |
if(!is_array($sel_val)){ |
| 1469 |
$sel_val=array($sel_val); |
| 1470 |
} |
| 1471 |
$sel="<option value=''></option>"; |
| 1472 |
$fields=$this->fields; |
| 1473 |
if(is_array($fields)){ |
| 1474 |
foreach($fields as $key=>$fields_arr){ |
| 1475 |
if(is_array($fields_arr['fields'])){ |
| 1476 |
$sel.='<optgroup label="'.esc_html($fields_arr['title']).'">'; |
| 1477 |
foreach($fields_arr['fields'] as $k=>$v){ |
| 1478 |
$option_k=$k; |
| 1479 |
$option_name=$v; |
| 1480 |
if($key == "gf"){ |
| 1481 |
$option_k=$v[0]; $option_name=$v[1]; |
| 1482 |
}else{ |
| 1483 |
$option_name=$v['label']; |
| 1484 |
} |
| 1485 |
$select=""; |
| 1486 |
if( in_array($option_k,$sel_val)){ |
| 1487 |
$select='selected="selected"'; |
| 1488 |
} |
| 1489 |
$sel.='<option value="'.esc_attr($option_k).'" '.$select.'>'.esc_html($option_name).'</option>'; |
| 1490 |
} } |
| 1491 |
}} |
| 1492 |
return $sel; |
| 1493 |
} |
| 1494 |
/** |
| 1495 |
* validate API |
| 1496 |
* |
| 1497 |
* @param mixed $info |
| 1498 |
* @param mixed $force_check |
| 1499 |
*/ |
| 1500 |
public function validate_api($row,$check=false){ |
| 1501 |
$info=$this->post('data',$row); |
| 1502 |
$api_check=(int)$this->post('valid_api',$info); |
| 1503 |
|
| 1504 |
if($check){ |
| 1505 |
$api=$this->get_api($row); |
| 1506 |
$res=$api->get_crm_objects(); |
| 1507 |
if(!empty($res) && is_string($res)){ |
| 1508 |
$info['error']=$res; |
| 1509 |
unset($info['access_token']); |
| 1510 |
} |
| 1511 |
} |
| 1512 |
if(!empty($info['access_token']) && !empty($info['refresh_token'])) { |
| 1513 |
$msg=__( 'Successfully Connected to Google Sheets','gravity-forms-googlesheets-crm' ); |
| 1514 |
if(!empty($info['time'])){ |
| 1515 |
if(!is_numeric($info['time'])){ |
| 1516 |
$info['time']=strtotime($info['time']); |
| 1517 |
} |
| 1518 |
$msg.=" - ".date('F d, Y h:i:s A',$info['time']); |
| 1519 |
} |
| 1520 |
$info['msg']=$msg; |
| 1521 |
$info['class']="updated"; |
| 1522 |
|
| 1523 |
}else{ |
| 1524 |
$info['class']=""; |
| 1525 |
if(isset($info['error']) && isset($info['expires']) && $info['error'] !=""){ |
| 1526 |
$info['msg']=$info['error']; |
| 1527 |
$info['class']="error"; |
| 1528 |
} } |
| 1529 |
|
| 1530 |
return $info; |
| 1531 |
} |
| 1532 |
} |
| 1533 |
} |
| 1534 |
new vxg_googlesheets_pages(); |
| 1535 |
|