HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.34
System: Linux atalantini.com 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64
User: root (0)
PHP: 7.2.34
Disabled: NONE
Upload Files
File: /var/www/html/toniolo/wp-content/plugins/arformspaypal/arformspaypal.php
<?php

/**
  Plugin Name: ARForms - PayPal Addon
  Description: Extension for ARForms plugin to accept paypal payments. ( This plugin will work with ARForms plugin only. )
  Version: 2.7
  Plugin URI: http://www.arformsplugin.com/
  Author: Repute InfoSystems
  Author URI: http://reputeinfosystems.com/
  Text Domain: ARForms-paypal
 */

global $arfsiteurl;
$arfsiteurl = home_url();
if ( is_ssl() && ( ! preg_match( '/^https:\/\/.*\..*$/', $arfsiteurl ) || ! preg_match( '/^https:\/\/.*\..*$/', WP_PLUGIN_URL ) ) ) {
	$arfsiteurl = str_replace( 'http://', 'https://', $arfsiteurl );
	define( 'ARF_PAYPAL_URL', str_replace( 'http://', 'https://', WP_PLUGIN_URL . '/arformspaypal' ) );
} else {
	define( 'ARF_PAYPAL_URL', WP_PLUGIN_URL . '/arformspaypal' );
}

if ( ! defined( 'ARF_PAYPAL_DIR' ) ) {
	define( 'ARF_PAYPAL_DIR', WP_PLUGIN_DIR . '/arformspaypal' );
}

load_plugin_textdomain( 'ARForms-paypal', false, 'arformspaypal/languages/' );

global $arf_paypal;
$arf_paypal = new ARF_Paypal();

global $arf_paypal_version;
$arf_paypal_version = '2.7';

global $arf_paypal_assets_version;
$arf_paypal_assets_version = $arf_paypal_version . '_' . rand( 1000, 9999 );

global $arf_paypal_shortname;
$arf_paypal_shortname = 'ARFPAY';

class ARF_Paypal {

	public $db_paypal_forms;
	public $db_paypal_order;

	function __construct() {

		global $wpdb,$is_version_compatible, $arf_version;
		$arf_version = $this->get_arforms_version();
		$is_version_compatible = $this->is_arforms_version();

		$this->db_paypal_forms = $wpdb->prefix . 'arf_paypal_forms';
		$this->db_paypal_order = $wpdb->prefix . 'arf_paypal_order';

		add_action( 'init', array( $this, 'arf_paypal_db_check' ) );

		register_activation_hook( __FILE__, array( 'ARF_Paypal', 'install' ) );

		register_activation_hook( __FILE__, array( 'ARF_Paypal', 'arf_paypal_check_network_activation' ) );

		register_uninstall_hook( __FILE__, array( 'ARF_Paypal', 'uninstall' ) );

		if( !function_exists('is_plugin_active') ){
			include_once ABSPATH . 'wp-admin/includes/plugin.php';
		}

		if( is_plugin_active('arforms/arforms.php') ){

			add_action( 'admin_menu', array( $this, 'arf_paypal_menu' ), 27 );

			add_action( 'arfaftercreateentry', array( $this, 'arf_paypal_submission' ), 100, 2 );

			add_action( 'admin_notices', array( $this, 'arf_paypal_admin_notices' ) );

			add_filter( 'arf_entry_payment_detail', array( $this, 'arf_paypal_payment_detail' ), 11, 1 );

			add_filter( 'arf_check_payment', array( $this, 'arf_check_payment' ), 11, 3 );

			add_action( 'wp_ajax_arf_paypal_delete_order', array( $this, 'arf_paypal_delete_order' ) );

			add_action( 'wp_ajax_arf_paypal_order_bulk_act', array( $this, 'arf_paypal_order_bulk_act' ) );

			add_action( 'wp_ajax_arf_paypal_delete_form', array( $this, 'arf_paypal_delete_form' ) );

			add_action( 'wp_ajax_arf_paypal_form_bulk_act', array( $this, 'arf_paypal_form_bulk_act' ) );

			add_action( 'admin_enqueue_scripts', array( $this, 'arf_set_js' ), 11 );

			add_action( 'admin_enqueue_scripts', array( $this, 'arf_set_css' ), 11 );

			add_action( 'wp_head', array( $this, 'arf_set_front_css') );

			add_action( 'wp_ajax_arf_paypal_field_dropdown', array( $this, 'arf_paypal_field_dropdown' ) );

			add_action( 'arfbeforedestroyform', array( $this, 'arfdelete_paypal_form' ), 11, 1 );

			add_action( 'parse_request', array( $this, 'paypal_api' ) );

			add_action( 'wp', array( $this, 'paypal_response' ), 5 );

			add_filter( 'upgrader_pre_install', array( $this, 'arfpaypal_backup' ), 10, 2 );

			add_action( 'admin_init', array( $this, 'upgrade_data' ) );

			add_action( 'wp_ajax_arfp_form_order', array( $this, 'arfp_form_order' ) );

			add_action( 'init', array( $this, 'parse_standalone_request' ) );

			add_action( 'arf_after_paypal_successful_paymnet', array( $this, 'arf_change_form_entry' ), 8, 3 );

			if ( $is_version_compatible ) {
				add_action( 'wp_ajax_add_new_rule_paypal', array( $this, 'add_new_rule_paypal_v3' ) );
			} else {
				add_action( 'wp_ajax_add_new_rule_paypal', array( $this, 'add_new_rule_paypal' ) );
			}

			add_action( 'wp_ajax_add_new_rule_multiple_subscription', array( $this, 'add_new_rule_multiple_subscription' ) );

			if( version_compare( $arf_version, '4.4', '<' ) ){
				add_action( 'check_arf_payment_gateway', array( $this, 'arf_paypal_check_response' ), 20, 2 );
			} else {
				add_action( 'check_arf_payment_gateway', array( $this, 'arf_paypal_check_response_v3' ), 20, 2 );
			}

			add_action( 'user_register', array( $this, 'arf_add_capabilities_to_new_user' ) );

			add_filter( 'arf_hide_forms', array( $this, 'arf_display_message_content' ), 10, 2 );

			add_filter( 'arf_prevent_paypal_to_stop_sending_email_outside', array( $this, 'arf_paypal_to_prevent_send_mail' ), 10, 3 );

			add_action( 'wp_ajax_arf_paypal_save_settings', array( $this, 'arf_paypal_save_settings_callback' ) );

			add_action( 'admin_init', array( $this, 'arf_paypal_check_redirection' ) );

			add_action( 'arf_afterdisplay_form', array( $this, 'arf_set_paypal_front_js' ) );

			add_action( 'arf_update_admin_email_notification_data_outside', array( $this, 'arf_paypal_admin_email_notification_data' ), 10, 3 );

			add_action( 'wp_ajax_arf_retrieve_paypal_config_data', array( $this, 'arf_retrieve_paypal_config_data' ) );

			add_action( 'wp_ajax_arf_retrieve_paypal_transaction_data', array( $this, 'arf_retrieve_paypal_transaction_data' ) );
		
		}
	}

	function arf_retrieve_paypal_config_data(){

		global $wpdb, $arf_paypal, $MdlDb, $arfform, $arf_version, $arfsettings;
		
		$requested_data = arf_json_decode( stripslashes_deep( $_REQUEST['data'] ), true );

		$filtered_aoData  = $requested_data['aoData'];

		$return_data = array();

		$order_by = !empty( $filtered_aoData['iSortCol_0'] ) ? $filtered_aoData['iSortCol_0'] : 1;

		$order_by_str = 'ORDER BY';

	    if( 1 == $order_by ){
	        $order_by_str .= ' arfrm.form_id';
	    } else if( 2 == $order_by ){
	        $order_by_str .= ' arfrm.form_name';
	    } else if( 3 == $order_by ){
	        $order_by_str .= ' total_entries';
	    } else if( 4 == $order_by ){
	        $order_by_str .= ' total_amount';
	    } else if( 5 == $order_by ){
	        $order_by_str .= ' arfrm.created_at';
	    } else {
	        $order_by_str .= ' arfrm.form_id';
	    }

	    $order_by_str .=  ' ' . ( !empty( $filtered_aoData['sSortDir_0'] ) ? strtoupper($filtered_aoData['sSortDir_0']) : 'DESC' );
	    
	    $form_params = 'arfrm.*,SUM(ord.mc_gross) as total_amount, COUNT(ord.form_id) as total_entries';
	    $group_by_param = 'GROUP BY arfrm.id';

	    $offset = isset($filtered_aoData['iDisplayStart']) ? $filtered_aoData['iDisplayStart'] : 0;
	    $limit = isset($filtered_aoData['iDisplayLength']) ? $filtered_aoData['iDisplayLength'] : 10;

	    $limit_param = 'LIMIT '.$offset.', '.$limit;

	    $where_clause = "WHERE arfrm.id != '' " ;
	    $where_params = array();

	    if( !empty( $filtered_aoData['sSearch'] ) ){
	        $wild = '%';
	        $find = trim( $filtered_aoData['sSearch'] );
	        $getdate = date("F j, Y", strtotime( $find ) );
	        $checkdate = $wild . $wpdb->esc_like( date('Y-m-d', strtotime( $getdate ) ) ) . $wild;
	        $like = $wild . $wpdb->esc_like( $find ) . $wild;
	        $where_clause .= ' AND ( arfrm.form_name LIKE %s ) OR arfrm.form_id LIKE %s OR arfrm.created_at LIKE %s';
	        $where_params[0] = $like;
	        $where_params[1] = $like;
	        $where_params[2] = $checkdate;
	    }
	    
	    if( version_compare( $arf_version, '4.3','<' ) ){
				$forms = $wpdb->get_results( 'SELECT pyl.*,frm.name FROM ' . $arf_paypal->db_paypal_forms . ' pyl INNER JOIN ' . $MdlDb->forms . ' frm ON frm.id=pyl.form_id ORDER BY pyl.id DESC' );
			} else {
				//$paypal_form_table = $arf_paypal->db_paypal_forms . ' pyl INNER JOIN ' . $MdlDb->forms . ' f ON f.id=pyl.form_id ';

				$paypal_form_table = $arf_paypal->db_paypal_forms . ' arfrm LEFT JOIN ' . $arf_paypal->db_paypal_order . ' ord ON arfrm.form_id=ord.form_id ';
				$forms = $arfform->arf_select_db_data( true, '', $paypal_form_table, $form_params, $where_clause, $where_params, $group_by_param, $order_by_str, $limit_param );
			}
			
			
			$total_records = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_forms. ' arfrm', 'COUNT( arfrm.id )',$where_clause, $where_params, '', '', '', true );

	    $data = array();
	    if( count( $forms ) > 0 ){
	    	$ai = 0;
    		foreach ( $forms as $form_data ) {
    			$options     = maybe_unserialize( $form_data->options );
				$data[$ai][0] = "<div class='arf_custom_checkbox_wrapper arfmarginl15'>
															<input id='cb-item-action-'" . esc_html( $form_data->id ) ."' class='' type='checkbox' value='". esc_html( $form_data->id ) ."' name='item-action[]' />
															<svg width='18px' height='18px'>". ARF_CUSTOM_UNCHECKED_ICON . ARF_CUSTOM_CHECKED_ICON ."</svg>
														</div>
														<label for='cb-item-action-'". esc_html( $form_data->id ) ."'><span></span></label>";

          		$data[$ai][1] = $form_data->form_id;
         
         		$data[$ai][2] = "<a class='row-title' href='".wp_nonce_url( "?page=ARForms-Paypal&arfaction=edit&id={$form_data->id}")."'>".stripslashes( $form_data->form_name )."</a>";
         

          		$data[$ai][3] = "<a href='" . wp_nonce_url( "?page=ARForms-Paypal-order&form={$form_data->form_id}" ) . "'>" . $form_data->total_entries . "</a>";

          		$total_amount = isset( $form_data->total_amount ) ? $form_data->total_amount : 0;

				if( $arfsettings->decimal_separator == ',' ){
					$total_amount = number_format( (float)$form_data->total_amount, 2, ',', '.' );
				} else {
					$total_amount = number_format( (float) $form_data->total_amount, 2 );
				} 

          		$data[$ai][4] = $total_amount . ' ' . $options['currency'];

          		$data[$ai][5] = date( get_option( 'date_format' ), strtotime( $form_data->created_at ) );

          		$edit_link = "?page=ARForms-Paypal&arfaction=edit&id={$form_data->id}";

          		$action_row_data = "<div class='arf-row-actions'>";

          		$action_row_data .= "<div class='arfformicondiv arfhelptip' title='" . esc_html__( 'Edit Configuration', 'ARForms-paypal' ) . "'><a href='" . wp_nonce_url( $edit_link ) . "'><svg width='30px' height='30px' viewBox='-5 -4 30 30' class='arfsvgposition'><path xmlns='http://www.w3.org/2000/svg' fill='#ffffff' d='M17.469,7.115v10.484c0,1.25-1.014,2.264-2.264,2.264H3.75c-1.25,0-2.262-1.014-2.262-2.264V5.082  c0-1.25,1.012-2.264,2.262-2.264h9.518l-2.264,2.001H3.489v13.042h11.979V9.379L17.469,7.115z M15.532,2.451l-0.801,0.8l2.4,2.401  l0.801-0.8L15.532,2.451z M17.131,0.85l-0.799,0.801l2.4,2.4l0.801-0.801L17.131,0.85z M6.731,11.254l2.4,2.4l7.201-7.202  l-2.4-2.401L6.731,11.254z M5.952,14.431h2.264l-2.264-2.264V14.431z'></path></svg></a></div>"; 

          		$action_row_data .= "<div class='arfformicondiv arfhelptip' title='" . esc_html__( 'Transactions', 'ARForms-paypal' ) . "'><a href='" . wp_nonce_url( "?page=ARForms-Paypal-order&form={$form_data->form_id}" ) . "'><svg width='30px' height='30px' viewBox='-5 -4 30 30' class='arfsvgposition'><path xmlns='http://www.w3.org/2000/svg' fill='#ffffff' d='M12.32,5.952c1.696-1.316,2.421-2.171,2.747-3.272c0.307-1.039-0.35-2.396-1.703-2.576    c-0.881-0.114-2.071,0.374-3.53,0.811c-0.477,0.143-0.979,0.143-1.451,0c-1.459-0.432-2.653-0.965-3.53-0.811    C3.234,0.389,2.892,1.73,3.149,2.68C3.45,3.789,4.2,4.635,5.896,5.952c-2.319,1.745-4.889,6.095-4.889,8.504    c0,3.314,3.854,5.647,8.101,5.647s8.141-2.333,8.141-5.647C17.249,12.047,14.639,7.696,12.32,5.952z M4.762,2.231    c-0.04-0.143-0.068-0.399,0.311-0.469c0.444-0.082,1.3-0.227,2.837,0.229c0.786,0.232,1.618,0.232,2.405,0    c1.536-0.457,2.393-0.307,2.837-0.229c0.313,0.053,0.346,0.326,0.31,0.469c-0.285,1.019-1.02,1.817-2.797,2.824    C10.167,4.884,9.65,4.79,9.116,4.79c-0.533,0-1.056,0.094-1.549,0.265C5.778,4.048,5.043,3.247,4.762,2.231z M9.108,18.093    c-2.462,0-5.51-0.747-5.51-3.637c0-2.633,2.624-8.007,5.51-8.007s5.471,5.374,5.471,8.007    C14.579,17.346,11.615,18.093,9.108,18.093z M9.202,12.316c-0.408,0-0.742-0.334-0.742-0.742s0.334-0.742,0.742-0.742    c0.208,0,0.399,0.082,0.542,0.232c0.27,0.286,0.722,0.302,1.007,0.033s0.302-0.721,0.033-1.007    c-0.241-0.257-0.539-0.448-0.869-0.563H8.489c-0.849,0.298-1.456,1.101-1.456,2.046c0,1.194,0.975,2.168,2.169,2.168    c0.407,0,0.742,0.334,0.742,0.742c0,0.408-0.335,0.742-0.742,0.742c-0.208,0-0.399-0.082-0.542-0.232    c-0.27-0.285-0.722-0.302-1.007-0.033s-0.302,0.722-0.033,1.007c0.241,0.257,0.538,0.449,0.869,0.563c0,0,0.738,0.281,1.426,0    c0.849-0.297,1.455-1.101,1.455-2.046C11.37,13.286,10.396,12.316,9.202,12.316z'/></svg></a></div>";
         

         		$action_row_data .= "<div class='arfformicondiv arfhelptip arfdeleteform_div_" . $form_data->id . "' title='" . esc_html__( 'Delete', 'ARForms-paypal' ) . "'><a class='arf_paypal_delete' data-id='" . $form_data->id . "' ><svg width='30px' height='30px' viewBox='-5 -5 32 32' class='arfsvgposition'><path xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' clip-rule='evenodd' fill='#ffffff' d='M18.435,4.857L18.413,19.87L3.398,19.88L3.394,4.857H1.489V2.929  h1.601h3.394V0.85h8.921v2.079h3.336h1.601l0,0v1.928H18.435z M15.231,4.857H6.597H5.425l0.012,13.018h10.945l0.005-13.018H15.231z   M11.4,6.845h2.029v9.065H11.4V6.845z M8.399,6.845h2.03v9.065h-2.03V6.845z' /></svg></a></div>";
          
          		$action_row_data .= "</div>";

          		$data[$ai][6] = $action_row_data ;

          		$ai++;

    		}

	    	$sEcho = isset($filtered_aoData['sEcho']) ? intval($filtered_aoData['sEcho']) : intval(10);

	        $return_data = array(
				'sEcho' => $sEcho,
				'iTotalRecords' => (int)$total_records,
				'iTotalDisplayRecords' => (int)$total_records,
				'aaData' => $data,
	        );
	    } else {
			$sEcho = isset($filtered_aoData['sEcho']) ? intval($filtered_aoData['sEcho']) : intval(10);
			$return_data = array(
				'sEcho' => $sEcho,
				'iTotalRecords' => (int)$total_records,
				'iTotalDisplayRecords' => (int)$total_records,
				'aaData' => $data,
			);
	    }

		echo json_encode( $return_data );
        die;
	}

	function arf_retrieve_paypal_transaction_data(){


		global $wpdb, $arf_paypal, $MdlDb, $arfform, $arf_version, $arfsettings, $arrecordcontroller;
		

		$requested_data = arf_json_decode( stripslashes_deep( $_REQUEST['data'] ), true );

		$filtered_aoData  = $requested_data['aoData'];

		$form_id = !empty( $filtered_aoData['form_id'] ) ? $filtered_aoData['form_id'] : '';


		$start_date = !empty( $filtered_aoData['start_date'] ) ? $filtered_aoData['start_date'] : '';

		$end_date = !empty( $filtered_aoData['end_date'] ) ? $filtered_aoData['end_date'] : '';

		$return_data = array();

		$order_by = !empty( $filtered_aoData['iSortCol_0'] ) ? $filtered_aoData['iSortCol_0'] : 5;

	    $order_by_str = 'ORDER BY';

	    if( 1 == $order_by ){
	        $order_by_str .= ' txn_id';
	    } else if( 2 == $order_by ){
	        $order_by_str .= ' payment_status';
	    } else if( 3 == $order_by ){
	        $order_by_str .= ' mc_gross';
	    } else if( 5 == $order_by ){
	        $order_by_str .= ' created_at';
	    } else if( 6 == $order_by ){
	        $order_by_str .= ' payer_email';
	    } else if( 7 == $order_by ){
	        $order_by_str .= ' payer_name';
	    } else {
	        $order_by_str .= ' created_at';
	    }
	    


		$wp_format_date = get_option( 'date_format' );

		if ( $wp_format_date == 'F j, Y' || $wp_format_date == 'm/d/Y' ) {
			$date_format_new = 'mm/dd/yy';
		} elseif ( $wp_format_date == 'd/m/Y' ) {
			$date_format_new = 'dd/mm/yy';
		} elseif ( $wp_format_date == 'Y/m/d' ) {
			$date_format_new = 'dd/mm/yy';
		} else {
			$date_format_new = 'mm/dd/yy';
		}

		$datequery = '';
		if ( $start_date != '' and $end_date != '' ) {
			if ( $date_format_new == 'dd/mm/yy' ) {
				$start_date = str_replace( '/', '-', $start_date );
				$end_date   = str_replace( '/', '-', $end_date );
			}
			$new_start_date_var = date( 'Y-m-d', strtotime( $start_date ) );
			$new_end_date_var   = date( 'Y-m-d', strtotime( $end_date ) );

			$datequery .= " and DATE( created_at) >= '" . $new_start_date_var . "' and DATE( created_at) <= '" . $new_end_date_var . "'";
		} elseif ( $start_date != '' and $end_date == '' ) {
			if ( $date_format_new == 'dd/mm/yy' ) {
				$start_date = str_replace( '/', '-', $start_date );
			}
			$new_start_date_var = date( 'Y-m-d', strtotime( $start_date ) );

			$datequery .= " and DATE( created_at) >= '" . $new_start_date_var . "'";
		} elseif ( $start_date == '' and $end_date != '' ) {
			if ( $date_format_new == 'dd/mm/yy' ) {
				$end_date = str_replace( '/', '-', $end_date );
			}
			$new_end_date_var = date( 'Y-m-d', strtotime( $end_date ) );

			$datequery .= " and DATE( created_at) <= '" . $new_end_date_var . "'";
		}

	    $order_by_str .=  ' ' . ( !empty( $filtered_aoData['sSortDir_0'] ) ? strtoupper($filtered_aoData['sSortDir_0']) : 'DESC' );

	    $form_table_param = $MdlDb->forms .' f LEFT JOIN '.$MdlDb->entries.' e ON f.id = e.form_id';

	    $group_by_param = 'GROUP BY f.id';

	    $offset = isset($filtered_aoData['iDisplayStart']) ? $filtered_aoData['iDisplayStart'] : 0;
	    $limit = isset($filtered_aoData['iDisplayLength']) ? $filtered_aoData['iDisplayLength'] : 10;

	    $limit_param = 'LIMIT '.$offset.', '.$limit;
	    
	    $where_clause = " WHERE id != '' ";
	    
	    $where_params = array();
	    

	    if( !empty( $filtered_aoData['sSearch'] ) ){
	    		
	        $wild = '%';
	        $find = trim( $filtered_aoData['sSearch'] );
	        $like = $wild . $wpdb->esc_like( $find ) . $wild;
	        $where_clause .= ' AND ( txn_id LIKE %s OR payment_status LIKE %s OR mc_gross LIKE %s OR payer_email LIKE %s OR payer_name LIKE %s )';
	        $where_params[0] = $like;
					$where_params[1] = $like;
					$where_params[2] = $like;
					$where_params[3] = $like;
					$where_params[4] = $like;
	    }
	   

		if ( isset( $form_id ) and $form_id != '' ) {
			if( version_compare( $arf_version, '4.3', '<') ){
				$orders = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $arf_paypal->db_paypal_order . ' WHERE form_id = %d '. $datequery .' ORDER BY id DESC', $form_id ) );
			} else {
				$where_clause .= ' AND form_id = %d';
				//$where_params[5] = $form_id;
				$where_params[] = $form_id;
				$orders = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_order, '*', $where_clause.$datequery, $where_params, '', $order_by_str, $limit_param );
			}	
		} else {
			if( version_compare( $arf_version, '4.3', '<' ) ){
				$orders = $wpdb->get_results( 'SELECT * FROM ' . $arf_paypal->db_paypal_order . $datequery . ' ORDER BY id DESC' );
			} else {
				$orders = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_order, '*', $where_clause.$datequery, $where_params, '', $order_by_str, $limit_param );
			}	
		}

		

		$total_records = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_order. ' ord', 'COUNT( ord.id )',$where_clause.$datequery, $where_params, '', '', '', true );

	    $data = array();
	    if( count( $orders ) > 0 ){
			$ai = 0;
			foreach ( $orders as $order ) {
				$data[$ai][0] = "<div class='arf_custom_checkbox_wrapper arfmarginl15'>
									<input id='cb-item-action-'" . esc_html( $order->id ) ."' class='' type='checkbox' value='". esc_html( $order->id ) ."' name='item-action[]' />
									<svg width='18px' height='18px'>". ARF_CUSTOM_UNCHECKED_ICON . ARF_CUSTOM_CHECKED_ICON ."</svg>
								</div>
								<label for='cb-item-action-'". esc_html( $order->id ) ."'><span></span></label>";

				$data[$ai][1] = $order->txn_id;

				$data[$ai][2] = ( $order->payment_status == 'Completed' ) ? '<font class="arf_pp_complete_status">' . $order->payment_status . '</font>' : '<font class="arf_pp_incomplete_status">' . $order->payment_status . '</font>';

				$order_mc_gross = $order->mc_gross;

				if( $arfsettings->decimal_separator == ',' ){
					$data[$ai][3] = number_format( (float) $order->mc_gross, 2, ',', '.' );
				} else {
					$data[$ai][3] = number_format( (float) $order->mc_gross, 2 );
				}

				if ( isset( $order->payment_type ) and $order->payment_type == 1 ) {
					$data[$ai][4] = esc_html( 'Donations', 'ARForms-paypal' );
				} elseif ( isset( $order->payment_type ) and $order->payment_type == 2 ) {
					$data[$ai][4] = esc_html( 'Subscription', 'ARForms-paypal' );
				} else {
					$data[$ai][4] = esc_html( 'Product / Service', 'ARForms-paypal' );
				}

				$data[$ai][5] = date( get_option( 'date_format' ), strtotime( $order->created_at ) );

				$data[$ai][6] = esc_html( $order->payer_email );

				$data[$ai][7] = esc_html( $order->payer_name );


				$action_row_data = "<div class='arf-row-actions'>";

				$action_row_data .= "<div class='arfformicondiv arfhelptip' title='" . esc_html__( 'View Entry', 'ARForms-paypal' ) . "'><a href='javascript:void(0);' onclick='open_entry_thickbox({$order->entry_id});'><svg width='30px' height='30px' viewBox='-3 -8 32 32' class='arfsvgposition'><path xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' clip-rule='evenodd' fill='#ffffff' d='M12.993,15.23c-7.191,0-11.504-7.234-11.504-7.234  S5.801,0.85,12.993,0.85c7.189,0,11.504,7.19,11.504,7.19S20.182,15.23,12.993,15.23z M12.993,2.827  c-5.703,0-8.799,5.214-8.799,5.214s3.096,5.213,8.799,5.213c5.701,0,8.797-5.213,8.797-5.213S18.694,2.827,12.993,2.827z   M12.993,11.572c-1.951,0-3.531-1.581-3.531-3.531s1.58-3.531,3.531-3.531c1.949,0,3.531,1.581,3.531,3.531  S14.942,11.572,12.993,11.572z'/></svg></a></div>"; 

				$action_row_data .= "<div class='arfformicondiv arfhelptip arfdeleteentry_div_" . $order->id . "' title='" . esc_html__( 'Delete', 'ARForms-paypal' ) . "'><a class='arf_delete_entry' data-id='" . $order->id . "' ><svg width='30px' height='30px' viewBox='-5 -5 32 32' class='arfsvgposition'><path xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' clip-rule='evenodd' fill='#ffffff' d='M18.435,4.857L18.413,19.87L3.398,19.88L3.394,4.857H1.489V2.929  h1.601h3.394V0.85h8.921v2.079h3.336h1.601l0,0v1.928H18.435z M15.231,4.857H6.597H5.425l0.012,13.018h10.945l0.005-13.018H15.231z   M11.4,6.845h2.029v9.065H11.4V6.845z M8.399,6.845h2.03v9.065h-2.03V6.845z' /></svg></a></div>";


				$action_row_data .= "<div id='view_entry_detail_container_{$order->entry_id}' class='arf_pp_display_none'>" . $arrecordcontroller->get_entries_list( $order->entry_id ) . "</div><div class='arf_clear_both arfmnarginbtm10'></div>";


				$action_row_data .= "</div>";

				$data[$ai][8] = $action_row_data ;

				$ai++;
	    	}

	    	$sEcho = isset($filtered_aoData['sEcho']) ? intval($filtered_aoData['sEcho']) : intval(10);

	        $return_data = array(
				'sEcho' => $sEcho,
				'iTotalRecords' => (int)$total_records,
				'iTotalDisplayRecords' => (int)$total_records,
				'aaData' => $data,
			);
	    } else {
			$sEcho = isset($filtered_aoData['sEcho']) ? intval($filtered_aoData['sEcho']) : intval(10);
			$return_data = array(
			    'sEcho' => $sEcho,
			    'iTotalRecords' => (int)$total_records,
			    'iTotalDisplayRecords' => (int)$total_records,
			    'aaData' => $data,
			);
	    }
	    
		echo json_encode( $return_data );
        die;
	}

	function arf_paypal_check_redirection() {
		global $wpdb,$arf_paypal, $arfform, $arf_version;
		if ( isset( $_REQUEST['arfaction'] ) && 'edit' == $_REQUEST['arfaction'] && isset( $_REQUEST['id'] ) && isset($_REQUEST['page']) && 'ARForms-Paypal' == $_REQUEST['page'] ) {
			if( version_compare( $arf_version, '4.3', '<') ){
				$form_data = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $arf_paypal->db_paypal_forms . ' WHERE id = %d', $_REQUEST['id'] ) );
			} else {
				$form_data = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_forms, '*', 'WHERE id = %d', array( $_REQUEST['id'] ) );
			}
			if ( count( $form_data ) == 0 ) {
				wp_redirect( admin_url( 'admin.php?page=ARForms-Paypal&err=1' ), 302, 'ARForms-Paypal' );
				die;
			}
		}
	}

	function arf_set_paypal_front_js( $form ) {
		global $wpdb, $MdlDb, $arf_paypal, $arf_paypal_assets_version, $arfform, $arf_version;
		if ( '' != $form->id ) {
			if( version_compare( $arf_version, '4.3', '<') ){
				$form_data = $wpdb->get_var( $wpdb->prepare( 'SELECT count(*) FROM `' . $arf_paypal->db_paypal_forms . '` WHERE form_id = %d', $form->id ) );
			} else {
				$form_data = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_forms, 'count(*)', 'WHERE form_id = %d', array( $form->id ), '', '', '', true );
			}
			if ( $form_data > 0 ) {

				wp_register_script( 'arf_paypal_front_js', ARF_PAYPAL_URL . '/js/arf_paypal_front.js', array(), $arf_paypal_assets_version );
				wp_enqueue_script( 'arf_paypal_front_js' );
			}
		}
	}

	function arf_paypal_to_prevent_send_mail( $prevent_sending_email, $entry_id, $form_id ) {
		global $wpdb,$MdlDb, $arfform, $arf_version;
		if ( $prevent_sending_email ) {
			return $prevent_sending_email;
		}
		if( version_compare( $arf_version, '4.3', '<') ){
			$form_data = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM  ' . $this->db_paypal_forms . ' WHERE form_id = %d', $form_id ) );
		} else {
			$form_data = $arfform->arf_select_db_data( true, '', $this->db_paypal_forms, '*', 'WHERE form_id = %d', array( $form_id ) );
		}
		if ( ! $form_data || count( $form_data ) < 1 ) {
			$prevent_sending_email = false;
		} else {
			$form_options = maybe_unserialize( $form_data[0]->options );

			$mapped_conditional_field = array();
			$mapped_field_values      = array();

			if ( $form_options['paypal_condition'] && 1 == $form_options['paypal_condition'] ) {
				$rules = $form_options['conditional_logic']['rules'] ? $form_options['conditional_logic']['rules'] : array();
				if ( $rules ) {
					foreach ( $rules as $rule ) {
						if ( '' != $rule['field_id'] ) {
							   $mapped_conditional_field[] = $rule['field_id'];
						}
					}
				}
			}

			$query_in = ' field_id IN';
			if ( count( $mapped_conditional_field ) == 1 ) {
				$query_in .= '( ' . $mapped_conditional_field[0] . ')';
			} elseif ( count( $mapped_conditional_field ) == 1 ) {
				$query_in .= '( ' . implode( ',', $mapped_conditional_field ) . ')';
			} else {
				$query_in = '1=1';
			}
			if( version_compare( $arf_version, '4.3', '<') ){
				$values = $wpdb->get_results( $wpdb->prepare( 'SELECT `field_id`,`entry_value` FROM `' . $MdlDb->entry_metas . "` WHERE `entry_id` = %d AND {$query_in}", $entry_id ) );
			} else {
				$values = $arfform->arf_select_db_data( true, '', $MdlDb->entry_metas, 'field_id, entry_value', 'WHERE entry_id = %d AND ' . $query_in, array( $entry_id ) );
			}
			foreach ( $values as $value ) {
				$mapped_field_values[ $value->field_id ] = $value->entry_value;
			}

			if ( $form_options['paypal_condition'] && 1 == $form_options['paypal_condition'] ) {
				$rules = $form_options['conditional_logic']['rules'] ? $form_options['conditional_logic']['rules'] : array();

				if ( $rules ) {
					$matched     = 0;
					$total_rules = 0;

					foreach ( $rules as $rule ) {
						if ( '' != $rule['field_id'] ) {
							$total_rules++;
							$value1   = isset( $mapped_field_values[ $rule['field_id'] ] ) ? $mapped_field_values[ $rule['field_id'] ] : '';
							$value1   = is_array( $value1 ) ? $value1 : trim( strtolower( $value1 ) );
							$value2   = isset( $rule['value'] ) ? trim( strtolower( $rule['value'] ) ) : '';
							$operator = $rule['operator'];
							if ( $this->calculate_rule( $value1, $value2, $operator, $rule['field_type'] ) ) {
								$matched++;
							}
						}
					}

					if ( ( 'all' == $form_options['conditional_logic']['if_cond'] && $total_rules == $matched ) || ( 'any' == $form_options['conditional_logic']['if_cond'] && $matched > 0 ) ) {
						$prevent_sending_email = false;
					} else {
						$prevent_sending_email = true;
					}
				}
			}
		}

		return $prevent_sending_email;
	}

	public static function arf_paypal_check_network_activation( $network_wide ) {
		if ( ! $network_wide ) {
			return;
		}

		deactivate_plugins( plugin_basename( __FILE__ ), true, true );

		header( 'Location: ' . network_admin_url( 'plugins.php?deactivate=true' ) );
		exit;
	}


	function arf_paypal_getapiurl() {
		$api_url = 'https://www.arpluginshop.com/';
		return $api_url;
	}

	function arf_paypal_get_remote_post_params( $plugin_info = '' ) {
		global $wpdb, $arfversion;

		$action = '';
		$action = $plugin_info;

		if ( ! function_exists( 'get_plugins' ) ) {
			include_once ABSPATH . 'wp-admin/includes/plugin.php';
		}
		$plugin_list = get_plugins();
		$site_url    = home_url();
		$plugins     = array();

		$active_plugins = get_option( 'active_plugins' );

		foreach ( $plugin_list as $key => $plugin ) {
			$is_active = in_array( $key, $active_plugins );

			if ( strpos( strtolower( $plugin['Title'] ), 'arformspaypal' ) !== false ) {
				$name      = substr( $key, 0, strpos( $key, '/' ) );
				$plugins[] = array(
					'name'      => $name,
					'version'   => $plugin['Version'],
					'is_active' => $is_active,
				);
			}
		}
		$plugins = json_encode( $plugins );

		$theme            = wp_get_theme();
		$theme_name       = $theme->get( 'Name' );
		$theme_uri        = $theme->get( 'ThemeURI' );
		$theme_version    = $theme->get( 'Version' );
		$theme_author     = $theme->get( 'Author' );
		$theme_author_uri = $theme->get( 'AuthorURI' );

		$im        = is_multisite();
		$sortorder = get_option( 'arfSortOrder' );

		$post = array(
			'wp'        => get_bloginfo( 'version' ),
			'php'       => phpversion(),
			'mysql'     => $wpdb->db_version(),
			'plugins'   => $plugins,
			'tn'        => $theme_name,
			'tu'        => $theme_uri,
			'tv'        => $theme_version,
			'ta'        => $theme_author,
			'tau'       => $theme_author_uri,
			'im'        => $im,
			'sortorder' => $sortorder,
		);

		return $post;
	}

	function arf_add_capabilities_to_new_user( $user_id ) {
		if ( '' == $user_id ) {
			return;
		}
		if ( user_can( $user_id, 'administrator' ) ) {

			$paypalcapabilities = array(
				'arfpaypalconfiguration' => esc_html__( 'Configure PayPal Forms', 'ARForms-paypal' ),
				'arfpaypaltransaction'   => esc_html__( 'View PayPal Transactions', 'ARForms-paypal' ),
			);

			$arfroles = $paypalcapabilities;

			$userObj = new WP_User( $user_id );
			foreach ( $arfroles as $arfrole => $arfroledescription ) {
				$userObj->add_cap( $arfrole );
			}
			unset( $arfrole );
			unset( $arfroles );
			unset( $arfroledescription );
		}
	}

	public static function arf_paypal_db_check() {
		global $arf_paypal;
		$arf_paypal_version = get_option( 'arf_paypal_version' );

		if ( ! isset( $arf_paypal_version ) || '' == $arf_paypal_version ) {
			$arf_paypal->install();
		}
	}

	public static function install() {
		global $arf_paypal;
		$arf_paypal_version = get_option( 'arf_paypal_version' );

		if ( ! isset( $arf_paypal_version ) || '' == $arf_paypal_version ) {

			global $wpdb, $arf_paypal_version,$arf_paypal;

			update_option( 'arf_paypal_version', $arf_paypal_version );

			$charset_collate = '';

			if ( ! empty( $wpdb->charset ) ) {
				$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
			}

			if ( ! empty( $wpdb->collate ) ) {
				$charset_collate .= " COLLATE $wpdb->collate";
			}

			if ( file_exists( ABSPATH . 'wp-admin/includes/upgrade.php' ) ) {
				include_once ABSPATH . 'wp-admin/includes/upgrade.php';
			}

			$table_name = $arf_paypal->db_paypal_order;

			$sql = "CREATE TABLE {$table_name} ( 
    
                    id int( 11) NOT NULL auto_increment,
                    
                    item_name varchar( 255) default NULL,
                    
                    txn_id varchar( 255) default NULL,
                     
                    payment_status varchar( 255) default NULL,               
    
                    mc_gross float( 11,2) default NULL,
    
                    mc_currency varchar( 255) default NULL,
                    
                    quantity varchar( 255) default NULL,
                    
                    payer_email varchar( 255) default NULL,
                    
                    payer_name varchar( 255) default NULL,
                    
                    payment_type varchar( 255) default NULL,
                            
                    user_id int( 11) default NULL,
                    
                    entry_id int( 11) default NULL,  
    
                    form_id int( 11) default NULL,
                    
                    payment_date varchar( 255) NOT NULL,
                    
                    created_at datetime NOT NULL,
                    
                    is_verified tinyint( 1) default 0, 
    
                    PRIMARY KEY ( id)
    
                  ) {$charset_collate};";

			dbDelta( $sql );

			$table_name = $arf_paypal->db_paypal_forms;

			$sql = "CREATE TABLE {$table_name} ( 
    
                    id int( 11) NOT NULL auto_increment,
                    
                    form_id int( 11) NOT NULL,
                    
                    form_name varchar( 255) default NULL,
                    
                    options longtext default NULL,
                    
                    created_at datetime NOT NULL,
                        
                    PRIMARY KEY ( id)
    
                  ) {$charset_collate};";

			dbDelta( $sql );

			$arf_paypal->getwpversion();
		}

		$args  = array(
			'role'   => 'administrator',
			'fields' => 'id',
		);
		$users = get_users( $args );
		if ( count( $users ) > 0 ) {
			foreach ( $users as $key => $user_id ) {

				$paypalcapabilities = array(
					'arfpaypalconfiguration' => esc_html__( 'Configure PayPal Forms', 'ARForms-paypal' ),
					'arfpaypaltransaction'   => esc_html__( 'View PayPal Transactions', 'ARForms-paypal' ),
				);
				$arfroles           = $paypalcapabilities;

				$userObj = new WP_User( $user_id );
				foreach ( $arfroles as $arfrole => $arfroledescription ) {
					$userObj->add_cap( $arfrole );
				}
				unset( $arfrole );
				unset( $arfroles );
				unset( $arfroledescription );
			}
		}
	}

	public static function uninstall() {
		global $wpdb,$arf_paypal;
		if ( is_multisite() ) {
			$blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A );
			if ( $blogs ) {
				foreach ( $blogs as $blog ) {
					switch_to_blog( $blog['blog_id'] );

					delete_option( 'arf_paypal_version' );
					$wpdb->query( 'DROP TABLE IF EXISTS ' . $arf_paypal->db_paypal_forms );
					$wpdb->query( 'DROP TABLE IF EXISTS ' . $arf_paypal->db_paypal_order );
				}
				restore_current_blog();
			}
		} else {
			delete_option( 'arf_paypal_version' );
			$wpdb->query( 'DROP TABLE IF EXISTS ' . $arf_paypal->db_paypal_forms );
			$wpdb->query( 'DROP TABLE IF EXISTS ' . $arf_paypal->db_paypal_order );
		}
	}

	function arf_paypal_admin_notices() {

		global $wp_version,$arf_version;

		if ( version_compare( $wp_version, '4.5.0', '<' ) ) {
			deactivate_plugins( __FILE__, false, true );

			echo "<div class='updated'><p>" . esc_html__( 'Please meet the minimum requirement of WordPress version 4.5 to active ARForms Paypal add-on', 'ARForms-paypal' );
		}

		if ( ! $this->is_arforms_support() ) {
			echo "<div class='updated'><p>" . esc_html__( 'Paypal For ARForms plugin requires ARForms Plugin installed and active.', 'ARForms-paypal' ) . '</p></div>';

		} elseif ( ! version_compare( $arf_version, '2.0.4', '>=' ) ) {
			echo "<div class='updated'><p>" . esc_html__( 'Paypal For ARForms plugin requires ARForms plugin installed with version 2.0.4 or higher.', 'ARForms-paypal' ) . '</p></div>';
		}
	}

	function is_arforms_support() {
		if ( file_exists( ABSPATH . 'wp-admin/includes/plugin.php' ) ) {
			include_once ABSPATH . 'wp-admin/includes/plugin.php';
		}
		return is_plugin_active( 'arforms/arforms.php' );
	}

	function get_arforms_version() {

		$arf_db_version = get_option( 'arf_db_version' );

		return ( isset( $arf_db_version ) ) ? $arf_db_version : 0;
	}

	function route() {
		global $arf_paypal, $arf_paypal_version, $arrecordcontroller,$is_version_compatible,$is_version_compatible;
		if ( isset( $_REQUEST['page'] ) && 'ARForms-Paypal' == $_REQUEST['page'] && isset( $_REQUEST['arfaction'] ) && ( 'new' == $_REQUEST['arfaction'] || 'edit' == $_REQUEST['arfaction'] ) ) {
			if ( $is_version_compatible ) {
				include ARF_PAYPAL_DIR . '/core/edit_3.0.php';
			} else {
				include ARF_PAYPAL_DIR . '/core/edit.php';
			}
		} elseif ( isset( $_REQUEST['page'] ) && 'ARForms-Paypal-order' == $_REQUEST['page'] ) {

			return $arf_paypal->list_orders();
		} else {

			return $arf_paypal->list_forms();
		}
	}

	function arf_paypal_menu() {
		global $arf_version;
		if ( version_compare( $arf_version, '2.0.4', '>=' ) ) {

			global $arfsettings;

			add_submenu_page( 'ARForms', 'ARForms | ' . esc_html__( 'PayPal Configuration', 'ARForms-paypal' ), esc_html__( 'PayPal Configuration', 'ARForms-paypal' ), 'arfpaypalconfiguration', 'ARForms-Paypal', array( $this, 'route' ) );

			add_submenu_page( 'ARForms', 'ARForms | ' . esc_html__( 'PayPal Transactions', 'ARForms-paypal' ), esc_html__( 'PayPal Transactions', 'ARForms-paypal' ), 'arfpaypaltransaction', 'ARForms-Paypal-order', array( $this, 'route' ) );
		}
	}

	function arf_set_js() {
		global $arf_paypal_assets_version,$is_version_compatible,$arf_version;

		wp_register_script( 'arfpaypal-js', ARF_PAYPAL_URL . '/js/arf_paypal.js', array( 'jquery' ), $arf_paypal_assets_version );

		if( version_compare( $arf_version, '5.6', '<' ) ){
			wp_register_script( 'bootstrap', ARFURL . '/bootstrap/js/bootstrap.min.js', array( 'jquery' ), $arf_paypal_assets_version );

			wp_register_script( 'bootstrap-select', ARFURL . '/bootstrap/js/bootstrap-select.js', array( 'jquery' ), $arf_paypal_assets_version );			

			wp_enqueue_script( 'bootstrap' );

			wp_enqueue_script( 'bootstrap-select' );
		}



		if( version_compare( $arf_version, '4.2', '<' ) ){

			wp_register_script( 'jquery_dataTables', ARFURL . '/datatables/media/js/jquery.dataTables.js', array(), $arf_paypal_assets_version );

			wp_register_script( 'ColVis', ARFURL . '/datatables/media/js/ColVis.js', array(), $arf_paypal_assets_version );

			wp_register_script( 'FixedColumns', ARFURL . '/datatables/media/js/FixedColumns.js', array(), $arf_paypal_assets_version );

			wp_register_style( 'demo_page', ARFURL . '/datatables/media/css/demo_page.css', array(), $arf_paypal_assets_version );
			
			wp_register_style( 'demo_table_ui', ARFURL . '/datatables/media/css/demo_table_ui.css', array(), $arf_paypal_assets_version );
			
			wp_register_style( 'jquery-ui', ARFURL . '/datatables/media/css/jquery-ui-1.8.4.custom.css.css', array(), $arf_paypal_assets_version );

			wp_register_style( 'ColVis', ARFURL . '/datatables/media/css/ColVis.css', array(), $arf_paypal_assets_version );
		}

		wp_register_script( 'tipso', ARFURL . '/js/tipso.min.js', array( 'jquery' ), $arf_paypal_assets_version );

		wp_register_script( 'bootstrap-locale', ARFURL . '/bootstrap/js/moment-with-locales.js', array(), $arf_paypal_assets_version );

		wp_register_script( 'bootstrap-datetimepicker', ARFURL . '/bootstrap/js/bootstrap-datetimepicker.js', array( 'jquery' ), $arf_paypal_assets_version, true );

		if ( isset( $_REQUEST['page'] ) && '' != $_REQUEST['page'] && ( 'ARForms-Paypal' == $_REQUEST['page'] || 'ARForms-Paypal-order' == $_REQUEST['page'] ) ) {

			wp_enqueue_script( 'arfpaypal-js' );



			if( version_compare( $arf_version, '4.2', '<' ) ){
				wp_enqueue_script( 'jquery-migrate' );
				wp_enqueue_script( 'jquery_dataTables' );
				wp_enqueue_script( 'ColVis' );
				wp_enqueue_script( 'FixedColumns' );

				wp_enqueue_style( 'demo_page' );
				wp_enqueue_style( 'demo_table_ui' );
				wp_enqueue_style( 'jquery-ui' );
				wp_enqueue_style( 'ColVis' );

			}else{

				wp_enqueue_script( 'datatables' );
                wp_enqueue_script( 'buttons-colvis' );
                wp_enqueue_style( 'datatables' );
			}

				wp_enqueue_script( 'jquery' );

				wp_enqueue_script( 'tipso' );

			wp_enqueue_script( 'bootstrap-locale' );

			wp_enqueue_script( 'bootstrap-datetimepicker' );
		}

		$script_data  = "__NO_FORM_FOUND_MSG='" . esc_html__( 'There is no any form found', 'ARForms-paypal' ) . "';";
		$script_data .= "__VALID_ACTION='" . esc_html__( 'Please select valid action', 'ARForms-paypal' ) . "';";
		$script_data .= "__SELECT_RECORD='" . esc_html__( 'Please select one or more record to perform action', 'ARForms-paypal' ) . "';";
		$script_data .= "__ARFADDRULE='" . esc_html__( 'Please add one or more rules', 'ARForms-paypal' ) . "';";
		$script_data .= "__INVALID_FORM_MSG='" . esc_html__( 'This form is already deleted or does not exist.', 'ARForms-paypal' ) . "';";
		$script_data .= "__DELETE_CONFIG='" . sprintf( esc_html__( 'Are you sure you want to %s delete this configuration?', 'ARForms-paypal' ), '<br/>' ) . "';";
		$script_data .= "__DELETE_ORDER='" . sprintf( esc_html__( 'Are you sure you want to %s delete this transaction?', 'ARForms-paypal' ), '<br/>' ) . "';";
		$script_data .= "__DELETE='" . esc_html__( 'Delete', 'ARForms-paypal' )."';";
		$script_data .= "__CANCEL='" . esc_html__( 'Cancel', 'ARForms-paypal' )."';";
		$script_data .= "__ARF_SEARCH_PLACEHOLDER='" . esc_html__( 'Search', 'ARForms-paypal' )."';";
		$script_data .= "__ARF_DB_VERSION= parseFloat('" . $arf_version . "');";
		wp_add_inline_script( 'arfpaypal-js', $script_data, 'after' );
	}

	function arf_set_css() {
		global $arf_paypal_version,$is_version_compatible,$arf_paypal_assets_version, $arf_version;


		if( version_compare( $arf_version, '5.6', '<' ) ){
			wp_register_style( 'bootstrap', ARFURL . '/bootstrap/css/bootstrap.css', array(), $arf_paypal_assets_version );

			wp_register_style( 'bootstrap-select', ARFURL . '/bootstrap/css/bootstrap-select.css', array(), $arf_paypal_assets_version );
			
			wp_enqueue_style( 'bootstrap' );

			wp_enqueue_style( 'bootstrap-select' );
		}

		wp_register_style( 'arfpaypal-css', ARF_PAYPAL_URL . '/css/arf_paypal.css', array(), $arf_paypal_assets_version );


		wp_register_style( 'tipso', ARFURL . '/css/tipso.min.css', array(), $arf_paypal_assets_version );

		wp_register_style( 'bootstrap-datetimepicker', ARFURL . '/bootstrap/css/bootstrap-datetimepicker.css', array(), $arf_paypal_assets_version );

		if ( isset( $_REQUEST['page'] ) && '' != $_REQUEST['page'] && ( 'ARForms-Paypal' == $_REQUEST['page'] || 'ARForms-Paypal-order' == $_REQUEST['page'] ) ) {

			wp_enqueue_style( 'arfpaypal-css' );


			wp_enqueue_style( 'tipso' );

			wp_enqueue_style( 'bootstrap-datetimepicker' );
		}

		if( isset( $hook ) && 'plugins.php' == $hook ){
			global $wp_version;

			if( version_compare($wp_version, '4.5', '<') ){
				wp_print_styles( 'arfpaypal-css' );
				deactivate_plugins( plugin_basename( __FILE__ ), true, false );
				$redirect_url = network_admin_url( 'plugins.php?deactivate=true' );
				wp_die( '<div class="arf_paypal_wp_notice"><p class="arf_paypal_wp_notice_text" >Please meet the minimum requirement of WordPress version 4.5 to activate ARForms - PayPal Add-on<p class="arf_paypal_wp_notice_continue">Please <a href="javascript:void(0)" onclick="window.location.href=\'' . esc_url( $redirect_url ) . '\'">Click Here</a> to continue.</p></div>' );
			}
		}
	}

	function arf_set_front_css(){
		global $wpdb,$MdlDb,$arf_paypal_assets_version, $arfform, $arf_version;

		wp_register_style( 'arf_paypal_front_css', ARF_PAYPAL_URL . '/css/arf_paypal_front.css',array(), $arf_paypal_assets_version );

		if ( isset( $_REQUEST['arf_conf'] ) && '' != $_REQUEST['arf_conf'] ) {
			$form_id = $_REQUEST['arf_conf'];
			if( version_compare( $arf_version, '4.3', '<') ){
				$form_data = $wpdb->get_var( $wpdb->prepare( 'SELECT count(*) FROM ' . $this->db_paypal_forms . " WHERE `form_id` = '%d'", $form_id ) );
			} else {
				$form_data = $arfform->arf_select_db_data( true, '', $this->db_paypal_forms, 'count(*)', 'WHERE form_id = %d', array( $form_id ), '', '', '', true );
			}

			if( $form_data > 0 ){
				wp_enqueue_style( 'arf_paypal_front_css' );
			}
		}
	}

	function arf_paypal_submission( $entry_id, $form_id ) {
		global $wpdb, $arfrecordmeta,$arf_paypal,$arfform, $arf_version, $arfsettings;
		if( version_compare( $arf_version, '4.3', '<') ){
			$form_data = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM  ' . $arf_paypal->db_paypal_forms . ' WHERE form_id = %d', $form_id ) );
		} else {
			$form_data = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_forms, '*', 'WHERE form_id = %d', array( $form_id ) );
		}

		if ( count( $form_data ) > 0 ) {

			$form_data = $form_data[0];

			$options = maybe_unserialize( $form_data->options );

			$paypal_field_amount = '';

			if ( '' != $options['amount'] ) {
				$paypal_field_amount = $options['amount'];
			}

			if ( '' != $options['arf_multiple_product_service_amount'] ) {
				$paypal_field_amount = $options['arf_multiple_product_service_amount'];
			}

			if( '' != $options['arf_multiple_donations_service_amount'] ){
				$paypal_field_amount = $options['arf_multiple_donations_service_amount'];	
			}

			if ( '' != $options['arf_multiple_subscription_amount'] ) {
				$paypal_field_amount = $options['arf_multiple_subscription_amount'];
			}

			global $paypal_fields;
			$paypal_fields = array(
				'first_name' => $options['first_name'],
				'last_name'  => $options['last_name'],
				'email'      => $options['email'],
				'address1'   => $options['address'],
				'address2'   => $options['address_2'],
				'city'       => $options['city'],
				'state'      => $options['state'],
				'zip'        => $options['zip'],
				'country'    => $options['country'],
			);

			if ( ! isset( $paypal_field_amount ) || '' == $paypal_field_amount ) {
				return;
			}

			$entry_ids = array( $entry_id );
			$values    = $arfrecordmeta->getAll( 'it.field_id != 0 and it.entry_id in ( ' . implode( ',', $entry_ids ) . ')', ' ORDER BY fi.id' );

			$amount        = '';
			$paypal_values = array();

			$mapped_conditional_field = array();
			if ( $options['paypal_condition'] && 1 == $options['paypal_condition'] ) {
				$rules = $options['conditional_logic']['rules'] ? $options['conditional_logic']['rules'] : array();
				if ( $rules ) {
					foreach ( $rules as $rule ) {
						if ( '' != $rule['field_id'] ) {
							$mapped_conditional_field[] = $rule['field_id'];
						}
					}
				}
			}

			$mapped_field_values = array();
			if ( count( $values ) > 0 ) {
				foreach ( $values as $value ) {
					if ( $value->field_id == $paypal_field_amount ) {
						$amount = $value->entry_value;
					}

					if ( $mapped_conditional_field ) {
						foreach ( $mapped_conditional_field as $rule_field ) {
							if ( $rule_field == $value->field_id ) {
								$mapped_field_values[ $value->field_id ] = $value->entry_value;
							}
						}
					}

					foreach ( $paypal_fields as $paypal_field_key => $paypal_field_id ) {
						if ( $value->field_id == $paypal_field_id ) {
							$paypal_values[ $paypal_field_key ] = $value->entry_value;
						}
					}
				}
			}

			$mapped_conditional_field = array();
			if ( $options['paypal_condition'] && $options['paypal_condition'] == 1 ) {
				$rules = $options['conditional_logic']['rules'] ? $options['conditional_logic']['rules'] : array();

				if ( $rules ) {
					$matched     = 0;
					$total_rules = 0;

					foreach ( $rules as $rule ) {
						if ( '' != $rule['field_id'] ) {
							$total_rules++;

							$value1 = isset( $mapped_field_values[ $rule['field_id'] ] ) ? $mapped_field_values[ $rule['field_id'] ] : '';

							$value1 = trim( strtolower( $value1 ) );

							$value2 = trim( strtolower( $rule['value'] ) );

							$operator = $rule['operator'];

							if ( $this->calculate_rule( $value1, $value2, $operator, $rule['field_type'] ) ) {
								$matched++;
							}
						}
					}

					if ( ( 'all' == $options['conditional_logic']['if_cond'] && $total_rules == $matched ) || ( 'any' == $options['conditional_logic']['if_cond'] && $matched > 0 ) ) {
						/* Do Nothing */
					} else {

						return false;
					}
				}
			}

			if ( 'arf_payment_type_multiple' == $options['arf_payment_type'] ) {

				$as__payment_type = $this->arf_get_multiple_payment_type( $values, $form_data );

				if ( isset( $as__payment_type['type'] ) ) {
					if ( 'product_service' != $as__payment_type['type'] && 'subscription' != $as__payment_type['type'] && 'donation' != $as__payment_type['type'] ) {
						return false;
					}
				} else {
					return false;
				}

				if ( ! empty( $as__payment_type ) ) {
					if ( 'product_service' == $as__payment_type['type'] ) {
						$amount                  = $as__payment_type['amount'];
						$options['payment_type'] = $as__payment_type['type'];
					}

					if ( 'donation' == $as__payment_type['type']) {
                        $amount = $as__payment_type['amount'];
                        $options['payment_type'] = $as__payment_type['type'];
                    }

					if ( 'subscription' == $as__payment_type['type'] ) {

						$amount                  = $as__payment_type['amount'];
						$options['payment_type'] = $as__payment_type['type'];

						$options['paypal_days']   = $as__payment_type['billing_cycle']['arf_paypal_days'];
						$options['paypal_months'] = $as__payment_type['billing_cycle']['arf_paypal_months'];
						$options['paypal_years']  = $as__payment_type['billing_cycle']['arf_paypal_years'];

						$options['paypal_recurring_type'] = $as__payment_type['billing_cycle']['recurring_type'];
						$options['paypal_recurring_time'] = $as__payment_type['billing_cycle']['recurring_time'];
					}
				}
			}

			$amount = isset( $amount ) ? $amount : 0;

			$sandbox = ( isset( $options['paypal_mode'] ) && 0 == $options['paypal_mode'] ) ? 'sandbox.' : '';

			$currency = ( isset( $options['currency'] ) ) ? $options['currency'] : 'USD';

			$merchant_email = ( isset( $options['merchant_email'] ) ) ? esc_attr( $options['merchant_email'] ) : '';

			$item_name = ( isset( $options['title'] ) ) ? esc_attr( $options['title'] ) : '';

			$cancel_url = ( isset( $options['cancel_url'] ) ) ? esc_attr( $options['cancel_url'] ) : '';

			$continue_text = ( isset( $options['continue_label'] ) ) ? esc_attr( $options['continue_label'] ) : '';

			if ( is_numeric( $amount ) && 0 == $amount ) {
				return;
			}

			$amount = str_replace($arfsettings->decimal_separator, ".", $amount);

			if ( '' != $merchant_email ) {
				global $MdlDb;

				$pageURL = 'http';
				if ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) {
					$pageURL .= 's';
				}
				$pageURL .= '://';
				if ( isset( $_SERVER['SERVER_PORT'] ) && '80' != $_SERVER['SERVER_PORT'] ) {
					$pageURL .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
				} else {
					$pageURL .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
				}

				$wpdb->update( $MdlDb->entries, array( 'form_id' => '0' ), array( 'id' => $entry_id ) );

				$_SESSION['arf_return_url'][ $form_id ] = $pageURL;

				if ( is_numeric( $amount ) ) {
					$amount = number_format( (float) $amount, 2 );
				}

				if ( is_numeric( $amount ) && ( 'HUF' == $currency || 'JPY' == $currency || 'TWD' == $currency ) ) {
					$amount = (float) $amount;
					$amount = floor( $amount );
				}

				$amount = preg_replace( '/\,/', '', $amount );

				if ( ! isset( $cancel_url ) || empty( $cancel_url ) ) {
					$cancel_url = get_home_url();
				}

				if ( ! isset( $continue_text ) || empty( $continue_text ) ) {
					$continue_text = esc_html__( 'Click here to continue', 'ARForms-paypal' );
				}

				$payment_type_val_int = 0;
				if ( isset( $options['payment_type'] ) ) {
					if ( 'donation' == $options['payment_type'] ) {
						$payment_type_val_int = 1;
					} elseif ( 'subscription' == $options['payment_type'] ) {
						$payment_type_val_int = 2;
					} else {
						$payment_type_val_int = 0;
					}
				} else {
					$payment_type_val_int = 0;
				}
				$payment_type = $payment_type_val_int;

				$payment_type_val = ( isset( $options['payment_type'] ) ) ? $options['payment_type'] : 'product_service';

				if ( 'donation' == $payment_type_val ) {
					$cmd = '_donations';
				} elseif ( 'product_service' == $payment_type_val ) {
					$cmd = '_xclick';
				} elseif ( 'subscription' == $payment_type_val ) {
					$cmd = '_xclick-subscriptions';
				} else {
					$cmd = '_xclick';
				}

				$recurring_type = ( isset( $options['paypal_recurring_type'] ) ) ? $options['paypal_recurring_type'] : 'M';
				$recurring_days = '1';
				if ( 'D' == $recurring_type ) {
					$recurring_days = ( isset( $options['paypal_days'] ) ) ? $options['paypal_days'] : '1';
				} elseif ( 'M' == $recurring_type ) {
					$recurring_days = ( isset( $options['paypal_months'] ) ) ? $options['paypal_months'] : '1';
				} elseif ( 'Y' == $recurring_type ) {
					$recurring_days = ( isset( $options['paypal_years'] ) ) ? $options['paypal_years'] : '1';
				}
				$recurring_time  = ( isset( $options['paypal_recurring_time'] ) && 'infinite' != $options['paypal_recurring_time'] ) ? $options['paypal_recurring_time'] : '';
				$recurring_retry = $options['paypal_recurring_retry'] ? '1' : '0';

				$trial_period_val     = ( isset( $options['paypal_trial_period'] ) ) ? $options['paypal_trial_period'] : 0;
				$trial_amount_val     = ( isset( $options['paypal_trial_amount'] ) ) ? $options['paypal_trial_amount'] : 0;
				$trial_recurring_type = ( isset( $options['paypal_trial_recurring_type'] ) ) ? $options['paypal_trial_recurring_type'] : 'M';
				$trial_days           = '1';
				if ( 'D' == $trial_recurring_type ) {
					$trial_days = ( isset( $options['paypal_trial_days'] ) ) ? $options['paypal_trial_days'] : '1';
				} elseif ( 'M' == $trial_recurring_type ) {
					$trial_days = ( isset( $options['paypal_trial_months'] ) ) ? $options['paypal_trial_months'] : '1';
				} elseif ( 'Y' == $trial_recurring_type ) {
					$trial_days = ( isset( $options['paypal_trial_years'] ) ) ? $options['paypal_trial_years'] : '1';
				}

				$arf_pyapal_home_url = get_home_url() . '/';

				if ( strstr( $arf_pyapal_home_url, '?' ) ) {
					$apyapal_return_url    = $arf_pyapal_home_url . '&arf_page=arforms_paypal_response&custom=' . $entry_id . '|' . $form_id . '|' . $payment_type;
					$arf_pyapal_notify_url = $arf_pyapal_home_url . '&arf_page=arforms_paypal_api';
				} else {
					$apyapal_return_url    = $arf_pyapal_home_url . '?arf_page=arforms_paypal_response&custom=' . $entry_id . '|' . $form_id . '|' . $payment_type;
					$arf_pyapal_notify_url = $arf_pyapal_home_url . '?arf_page=arforms_paypal_api';
				}

				if ( 1 == $arfsettings->form_submit_type ) {
					$return['conf_method'] = 'addon';
				}
				$message          = '';
				$is_normal_submit = '';
				if ( 1 != $arfsettings->form_submit_type ) {
					global $arf_paypal_assets_version;
					$is_normal_submit = 'arf_paypal_form_normal';
					wp_print_scripts( 'jquery' );
					wp_register_script( 'arf_paypal_front_js', ARF_PAYPAL_URL . '/js/arf_paypal_front.js', array(), $arf_paypal_assets_version );
					wp_print_scripts( 'arf_paypal_front_js' );
				}
				$message .= '<form name="_xclick" class="' . $is_normal_submit . '" id="arf_paypal_form" action="https://www.' . $sandbox . 'paypal.com/cgi-bin/webscr" method="post">
                    <input type="hidden" name="cmd" value="' . $cmd . '">
                    <input type="hidden" name="charset" value="UTF-8">
                    <input type="hidden" name="business" value="' . $merchant_email . '">
                    <input type="hidden" name="notify_url" value="' . esc_url( $arf_pyapal_notify_url ) . '">
                    <input type="hidden" name="return" value="' . esc_url( $apyapal_return_url ) . '">
                    <input type="hidden" name="cancel_return" value="' . $cancel_url . '">
                
                    <input type="hidden" name="currency_code" value="' . $currency . '" />
                    <input type="hidden" name="item_name" value="' . $item_name . '">
                    
                    <input type="hidden" name="custom" value="' . $entry_id . '|' . $form_id . '|' . $payment_type . '">
                    
                    <input type="hidden" name="cbt" value="' . $continue_text . '">
                    <input type="hidden" name="rm" value="2">';

				if ( 'subscription' == $payment_type_val ) {
					$message .= '<input type="hidden" name="a3" value="' . $amount . '">
                        <input type="hidden" name="p3" value="' . $recurring_days . '">
                        <input type="hidden" name="t3" value="' . $recurring_type . '">';

					$message .= '<input type="hidden" name="sra" value="' . $recurring_retry . '">';

					$message .= '<input type="hidden" name="src" value="1">';

					if ( $recurring_time > 1 ) {

						$message .= '<input type="hidden" name="srt" value="' . $recurring_time . '">';
					}
					if ( '1' == $trial_period_val ) {
						$message .= '<input type="hidden" name="a1" value="' . $trial_amount_val . '">
                                <input type="hidden" name="p1" value="' . $trial_days . '">
                                <input type="hidden" name="t1" value="' . $trial_recurring_type . '">';
					}
				} else {
					$message .= '<input type="hidden" name="amount" value="' . $amount . '">';
				}

				if ( isset( $options['shipping_info'] ) && 1 == $options['shipping_info'] ) {
					$message .= '<input type="hidden" name="first_name" value="' . ( isset( $paypal_values['first_name'] ) ? $paypal_values['first_name'] : '' ) . '" />
                    <input type="hidden" name="last_name" value="' . ( isset( $paypal_values['last_name'] ) ? $paypal_values['last_name'] : '' ) . '" />
                    <input type="hidden" name="email" value="' . ( isset( $paypal_values['email'] ) ? $paypal_values['email'] : '' ) . '" />
                    <input type="hidden" name="address1" value="' . ( isset( $paypal_values['address1'] ) ? $paypal_values['address1'] : '' ) . '" />
                    <input type="hidden" name="address2" value="' . ( isset( $paypal_values['address2'] ) ? $paypal_values['address2'] : '' ) . '" />
                    <input type="hidden" name="city" value="' . ( isset( $paypal_values['city'] ) ? $paypal_values['city'] : '' ) . '" />
                    <input type="hidden" name="state" value="' . ( isset( $paypal_values['state'] ) ? $paypal_values['state'] : '' ) . '" />
                    <input type="hidden" name="zip" value="' . ( isset( $paypal_values['zip'] ) ? $paypal_values['zip'] : '' ) . '" />
                    <input type="hidden" name="country" value="' . ( isset( $paypal_values['country'] ) ? $paypal_values['country'] : '' ) . '" />';
				}

				$message .= '</form>';

				$return['message'] = $message;

				$return = apply_filters( 'arf_reset_built_in_captcha', $return, $_POST );

				if ( $arfsettings->form_submit_type == 1 ) {
					echo json_encode( $return );
				} else {
					echo $message;
				}

				exit;
			}
		}
	}

	function list_orders() {
		global $arf_paypal_version, $arrecordcontroller, $arf_paypal,$is_version_compatible;
		if ( $is_version_compatible ) {
			$file = 'list_orders_3.0.php';
		} else {
			$file = 'list_orders.php';
		}
		include ARF_PAYPAL_DIR . '/core/' . $file;
	}

	function arf_check_payment( $arf_check_payment, $form_id , $entry_id){
		global $arfrecordmeta, $arf_paypal, $arfform;

		if ( $arf_check_payment ) {
			return $arf_check_payment;
		}
		
		$is_paypal_form = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_forms, 'COUNT(id)', 'WHERE form_id = %d', array( $form_id ), '', '', '', true );
		if( $is_paypal_form > 0 ){
			
			$paypal_form_data = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_forms, '*', 'WHERE form_id = %d', array( $form_id ) );
			$options = maybe_unserialize($paypal_form_data[0]->options);

			if ( $options['paypal_condition'] == 1 ) {
				$entry_ids = array( $entry_id );
				$values    = $arfrecordmeta->getAll( 'it.field_id != 0 and it.entry_id in ( ' . implode( ',', $entry_ids ) . ')', ' ORDER BY fi.id' );
				$mapped_conditional_field = array();
				if ( $options['paypal_condition'] && 1 == $options['paypal_condition'] ) {
					$rules = $options['conditional_logic']['rules'] ? $options['conditional_logic']['rules'] : array();
					if ( $rules ) {
						foreach ( $rules as $rule ) {
							if ( '' != $rule['field_id'] ) {
								$mapped_conditional_field[] = $rule['field_id'];
							}
						}
					}
				}

				$mapped_field_values = array();
				if ( count( $values ) > 0 ) {
					foreach ( $values as $value ) {
						if ( $mapped_conditional_field ) {
							foreach ( $mapped_conditional_field as $rule_field ) {
								if ( $rule_field == $value->field_id ) {
									$mapped_field_values[ $value->field_id ] = $value->entry_value;
								}
							}
						}
					}
				}

				$mapped_conditional_field = array();

				if ( $options['paypal_condition'] && $options['paypal_condition'] == 1 ) {
						$rules = $options['conditional_logic']['rules'] ? $options['conditional_logic']['rules'] : array();

						if ( $rules ) {
							$matched     = 0;
							$total_rules = 0;

							foreach ( $rules as $rule ) {
								if ( '' != $rule['field_id'] ) {
									$total_rules++;

									$value1 = isset( $mapped_field_values[ $rule['field_id'] ] ) ? $mapped_field_values[ $rule['field_id'] ] : '';

									$value1 = trim( strtolower( $value1 ) );

									$value2 = trim( strtolower( $rule['value'] ) );

									$operator = $rule['operator'];

									if ( $this->calculate_rule( $value1, $value2, $operator, $rule['field_type'] ) ) {
										$matched++;
									}
								}
							}

							if ( ( 'all' == $options['conditional_logic']['if_cond'] && $total_rules == $matched ) || ( 'any' == $options['conditional_logic']['if_cond'] && $matched > 0 ) ) {
								$arf_check_payment = true;			
							} else {
								$arf_check_payment = false;
							}
						}
				}
			} else {
					$arf_check_payment = true;
			}
		} 

		return $arf_check_payment;
	}

	function arf_paypal_payment_detail( $entry_id ) {

		global $armainhelper,$arf_paypal,$is_version_compatible;
		$var = '';

		if ( $entry_id ) {
			global $wpdb,$arformcontroller,$arfform,$arf_version;
			if( version_compare( $arf_version, '4.3', '<') ){
				$payment_detail = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $arf_paypal->db_paypal_order . ' WHERE entry_id = %d', $entry_id ) );
			} else {
				$payment_detail = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_order, '*', 'WHERE entry_id = %d', array( $entry_id ) );
			}
			if ( isset( $payment_detail ) && '' != $payment_detail && is_array( $payment_detail ) && isset( $payment_detail[0] ) ) {
				$payment_detail = $payment_detail[0];
			}

			if ( ! empty( $payment_detail ) ) {

				$var .= '</tbody></table><div class="arfentrydivider">' . esc_html__( 'Payment Details', 'ARForms-paypal' ) . '</div><table class="form-table"><tbody>';

				$var .= '<tr class="arfviewentry_row" scope="row"><td class="arfviewentry_left"><strong>' . esc_html__( 'Transaction ID', 'ARForms-paypal' ) . ':</strong></td><td class="arfviewentry_right">' . $payment_detail->txn_id . '</td></tr>';

				$var .= '<tr class="arfviewentry_row" scope="row"><td class="arfviewentry_left"><strong>' . esc_html__( 'Payment Status', 'ARForms-paypal' ) . ':</strong></td><td class="arfviewentry_right">' . ( ( 'Completed' == $payment_detail->payment_status ) ? '<font class="arf_pp_complete_status">' . $payment_detail->payment_status . '</font>' : '<font class="arf_pp_incomplete_status">' . $payment_detail->payment_status . '</font>' ) . '</td></tr>';

				if ( $is_version_compatible ) {
					$var .= '<tr class="arfviewentry_row" scope="row"><td class="arfviewentry_left"><strong>' . esc_html__( 'Total Amount', 'ARForms-paypal' ) . ':</strong></td><td class="arfviewentry_right">' . $arformcontroller->arfdeciamlseparator( $payment_detail->mc_gross ) . ' ' . $payment_detail->mc_currency . '</td></tr>';
				} else {
					$var .= '<tr class="arfviewentry_row" scope="row"><td class="arfviewentry_left"><strong>' . esc_html__( 'Total Amount', 'ARForms-paypal' ) . ':</strong></td><td class="arfviewentry_right">' . $payment_detail->mc_gross . ' ' . $payment_detail->mc_currency . '</td></tr>';
				}

				$date_format  = get_option( 'date_format' );
				$time_format  = get_option( 'time_format' );
				$payment_date = $armainhelper->get_formatted_time( $payment_detail->created_at, $date_format, $time_format );

				$var .= '<tr class="arfviewentry_row" scope="row"><td class="arfviewentry_left"><strong>' . esc_html__( 'Payment at', 'ARForms-paypal' ) . ':</strong></td><td class="arfviewentry_right">' . $payment_date . '</td></tr>';

				$var .= '<tr class="arfviewentry_row" scope="row"><td class="arfviewentry_left"><strong>' . esc_html__( 'Payer email', 'ARForms-paypal' ) . ':</strong></td><td class="arfviewentry_right">' . $payment_detail->payer_email . '</td></tr>';

				$var .= '<tr class="arfviewentry_row" scope="row"><td class="arfviewentry_left"><strong>' . esc_html__( 'Payer name', 'ARForms-paypal' ) . ':</strong></td><td class="arfviewentry_right">' . $payment_detail->payer_name . '</td></tr>';
			}
		}

		return $var;
	}

	function currency_list() {
		$currency = array( 'USD', 'AUD', 'BRL', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MYR', 'MXN', 'NOK', 'NZD', 'PHP', 'PLN', 'GBP', 'RUB', 'SGD', 'SEK', 'CHF', 'TWD', 'THB' );

		return $currency;
	}

	function currency_symbol( $currency_code = 'USD' ) {
		$currency_symbol = array(
			'USD' => 'USD   &nbsp;( &nbsp;&nbsp;$&nbsp;&nbsp;)',
			'AUD' => 'AUD   &nbsp;( &nbsp;&nbsp;$&nbsp;&nbsp;)',
			'BRL' => 'BRL   &nbsp;( &nbsp;&nbsp;R$&nbsp;&nbsp;)',
			'CAD' => 'CAD   &nbsp;( &nbsp;&nbsp;$&nbsp;&nbsp;)',
			'CZK' => 'CZK   &nbsp;( &nbsp;&nbsp;&#75;&#269;&nbsp;&nbsp;)',
			'DKK' => 'DKK   &nbsp;( &nbsp;&nbsp;&#107;&#114;&nbsp;&nbsp;)',
			'EUR' => 'EUR   &nbsp;( &nbsp;&nbsp;&#128;&nbsp;&nbsp;)',
			'HKD' => 'HKD   &nbsp;( &nbsp;&nbsp;&#20803;&nbsp;&nbsp;)',
			'HUF' => 'HUF   &nbsp;( &nbsp;&nbsp;&#70;&#116;&nbsp;&nbsp;)',
			'ILS' => 'ILS   &nbsp;( &nbsp;&nbsp;&#8362;&nbsp;&nbsp;)',
			'JPY' => 'JPY   &nbsp;( &nbsp;&nbsp;&#165;&nbsp;&nbsp;)',
			'MYR' => 'MYR   &nbsp;( &nbsp;&nbsp;&#82;&#77;&nbsp;&nbsp;)',
			'MXN' => 'MXN   &nbsp;( &nbsp;&nbsp;&#36;&nbsp;&nbsp;)',
			'NOK' => 'NOK   &nbsp;( &nbsp;&nbsp;&#107;&#114;&nbsp;&nbsp;)',
			'NZD' => 'NZD   &nbsp;( &nbsp;&nbsp;&#36;&nbsp;&nbsp;)',
			'PHP' => 'PHP   &nbsp;( &nbsp;&nbsp;&#80;&#104;&#8369;&nbsp;&nbsp;)',
			'PLN' => 'PLN   &nbsp;( &nbsp;&nbsp;&#122;&#322;&nbsp;&nbsp;)',
			'GBP' => 'GBP   &nbsp;( &nbsp;&nbsp;&#163;&nbsp;&nbsp;)',
			'RUB' => 'RUB   &nbsp;( &nbsp;&nbsp;&#1088;&#1091;&nbsp;&nbsp;)',
			'SGD' => 'SGD   &nbsp;( &nbsp;&nbsp;&#36;&nbsp;&nbsp;)',
			'SEK' => 'SEK   &nbsp;( &nbsp;&nbsp;&#107;&#114;&nbsp;&nbsp;)',
			'CHF' => 'CHF   &nbsp;( &nbsp;&nbsp;&#67;&#72;&#70;&nbsp;&nbsp;)',
			'TWD' => 'TWD   &nbsp;( &nbsp;&nbsp;&#36;&nbsp;&nbsp;)',
			'THB' => 'THB   &nbsp;( &nbsp;&nbsp;&#3647;&nbsp;&nbsp;)',
		);

		return $currency_symbol;
	}

	function arf_paypal_delete_order() {
		$id      = isset( $_POST['id'] ) ? $_POST['id'] : '';
		$action  = isset( $_POST['act'] ) ? $_POST['act'] : '';
		$form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : '';

		$startdate = isset( $_POST['start_date'] ) ? $_POST['start_date'] : '';
		$enddate   = isset( $_POST['end_date'] ) ? $_POST['end_date'] : '';

		global $style_settings, $wp_scripts;
		$wp_format_date = get_option( 'date_format' );

		if ( $wp_format_date == 'F j, Y' || $wp_format_date == 'm/d/Y' ) {
			$date_format_new = 'mm/dd/yy';
		} elseif ( $wp_format_date == 'd/m/Y' ) {
			$date_format_new = 'dd/mm/yy';
		} elseif ( $wp_format_date == 'Y/m/d' ) {
			$date_format_new = 'dd/mm/yy';
		} else {
			$date_format_new = 'mm/dd/yy';
		}

		$datequery = '';
		if ( '' != $startdate && '' != $enddate ) {
			if ( 'dd/mm/yy' == $date_format_new ) {
				$startdate = str_replace( '/', '-', $startdate );
				$enddate   = str_replace( '/', '-', $enddate );
			}
			$new_start_date_var = date( 'Y-m-d', strtotime( $startdate ) );
			$new_end_date_var   = date( 'Y-m-d', strtotime( $enddate ) );

			$datequery .= " and DATE( created_at) >= '" . $new_start_date_var . "' and DATE( created_at) <= '" . $new_end_date_var . "'";
		} elseif ( $startdate != '' && $enddate == '' ) {
			if ( $date_format_new == 'dd/mm/yy' ) {
				$startdate = str_replace( '/', '-', $startdate );
			}
			$new_start_date_var = date( 'Y-m-d', strtotime( $startdate ) );

			$datequery .= " and DATE( created_at) >= '" . $new_start_date_var . "'";
		} elseif ( $startdate == '' && $enddate != '' ) {
			if ( $date_format_new == 'dd/mm/yy' ) {
				$enddate = str_replace( '/', '-', $enddate );
			}
			$new_end_date_var = date( 'Y-m-d', strtotime( $enddate ) );

			$datequery .= " and DATE( created_at) <= '" . $new_end_date_var . "'";
		}


		if ( $action == 'delete' && $id ) {
			$res     = $this->delete_orders( $id );
			$message = esc_html__( 'Record is deleted successfully.', 'ARForms-paypal' );
			$errors  = array();
			global $is_version_compatible, $arf_version;

			if ( version_compare( $arf_version, '5.0', '>' ) ) {
				global $wpdb, $MdlDb, $arformcontroller;
				echo json_encode(
					array(
						'errors'   => $errors,
						'message'  => $message,
					)
				);
			} else {
				$gridData = $this->arf_paypal_get_order_data( $form_id, $datequery );
				echo json_encode(
					array(
						'errors'   => $errors,
						'message'  => $message,
						'gridData' => $gridData,
					)
				);
			}
		}
		
		die();
	}

	function delete_orders( $id = 0 ) {
		if ( $id == 0 ) {
			return;
		}

		if ( $id ) {
			global $wpdb,$arf_paypal;
			$res = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $arf_paypal->db_paypal_order . ' WHERE id = %d', $id ) );

			return $res;
		}
	}

	function arf_paypal_order_bulk_act() {

		global $armainhelper, $arf_version, $arfform;


		if ( ! isset( $_POST ) ) {
			return;
		}
		

		$bulkaction = $armainhelper->get_param( 'action1' );

		$message = '';

		$errors = array();
		

		if ( $bulkaction == -1 ) {
			$bulkaction = $armainhelper->get_param( 'action3' );
		}

		if ( ! empty( $bulkaction ) and strpos( $bulkaction, 'bulk_' ) === 0 ) {

			if ( isset( $_GET ) and isset( $_GET['action1'] ) ) {
				$_SERVER['REQUEST_URI'] = str_replace( '&action=' . $_GET['action1'], '', $_SERVER['REQUEST_URI'] );
			}

			if ( isset( $_GET ) and isset( $_GET['action3'] ) ) {
				$_SERVER['REQUEST_URI'] = str_replace( '&action=' . $_GET['action3'], '', $_SERVER['REQUEST_URI'] );
			}

			$bulkaction = str_replace( 'bulk_', '', $bulkaction );
		} else {
			$bulkaction = '-1';

			if ( isset( $_POST['bulkaction'] ) and $_POST['bulkaction1'] != '-1' ) {
				$bulkaction = $_POST['bulkaction1'];

			} elseif ( isset( $_POST['bulkaction2'] ) and $_POST['bulkaction2'] != '-1' ) {
				$bulkaction = $_POST['bulkaction2'];
			}
		}

		$ids = $armainhelper->get_param( 'item-action', '' );

		$form_id   = $_POST['p_form_id'];
		$startdate = $_POST['start_date'];
		$enddate   = $_POST['end_date'];

		global $style_settings, $wp_scripts;
		$wp_format_date = get_option( 'date_format' );

		if ( $wp_format_date == 'F j, Y' || $wp_format_date == 'm/d/Y' ) {
			$date_format_new = 'mm/dd/yy';
		} elseif ( $wp_format_date == 'd/m/Y' ) {
			$date_format_new = 'dd/mm/yy';
		} elseif ( $wp_format_date == 'Y/m/d' ) {
			$date_format_new = 'dd/mm/yy';
		} else {
			$date_format_new = 'mm/dd/yy';
		}

		$datequery = '';
		if ( $startdate != '' and $enddate != '' ) {
			if ( $date_format_new == 'dd/mm/yy' ) {
				$startdate = str_replace( '/', '-', $startdate );
				$enddate   = str_replace( '/', '-', $enddate );
			}
			$new_start_date_var = date( 'Y-m-d', strtotime( $startdate ) );
			$new_end_date_var   = date( 'Y-m-d', strtotime( $enddate ) );

			$datequery .= " and DATE( created_at) >= '" . $new_start_date_var . "' and DATE( created_at) <= '" . $new_end_date_var . "'";
		} elseif ( $startdate != '' and $enddate == '' ) {
			if ( $date_format_new == 'dd/mm/yy' ) {
				$startdate = str_replace( '/', '-', $startdate );
			}
			$new_start_date_var = date( 'Y-m-d', strtotime( $startdate ) );

			$datequery .= " and DATE( created_at) >= '" . $new_start_date_var . "'";
		} elseif ( $startdate == '' and $enddate != '' ) {
			if ( $date_format_new == 'dd/mm/yy' ) {
				$enddate = str_replace( '/', '-', $enddate );
			}
			$new_end_date_var = date( 'Y-m-d', strtotime( $enddate ) );

			$datequery .= " and DATE( created_at) <= '" . $new_end_date_var . "'";
		}

		if ( empty( $ids ) ) {
			$errors[] = esc_html__( 'Please select one or more records.', 'ARForms-paypal' );
		} else {
			if ( ! is_array( $ids ) ) {
				$ids = explode( ',', $ids );
			}

			if ( is_array( $ids ) ) {
				if ( $bulkaction == 'delete' ) {

					foreach ( $ids as $oid ) {
						$res_var = $this->delete_orders( $oid );
					}

					if ( $res_var ) {
						$message = esc_html__( 'Record is deleted successfully.', 'ARForms-paypal' );
					}
				} elseif ( $bulkaction == 'csv' ) {
					echo json_encode(
						array(
							'errors'   => $errors,
							'message'  => 'csv',
							'url'      => ARFSCRIPTURL . '-Paypal&arfaction=csv&entry_id=' . implode( ',', $ids ),
							'gridData' => $this->arf_paypal_get_order_data( $form_id, $datequery )
						)
					);
					die;
				}
			}
		}

		if ( version_compare( $arf_version, '5.0', '>' ) ) {
			global $wpdb, $MdlDb, $arformcontroller;
			echo json_encode(
				array(
					'errors'   => $errors,
					'message'  => $message,
				)
			);	
		} else {
			$gridData = $this->arf_paypal_get_order_data( $form_id, $datequery );
			echo json_encode(
				array(
					'errors'   => $errors,
					'message'  => $message,
					'gridData' => $gridData,
				)
			);	
		}
		

		
		die();
	}

	function arf_paypal_get_order_data( $form_id, $datequery ) {
		global $wpdb, $arrecordcontroller, $arf_paypal,$MdlDb,$arformcontroller,$style_settings, $wp_scripts, $is_version_compatible, $arfform, $arf_version;

		$orderData = array();

		if ( isset( $form_id ) and $form_id != '' ) {
			if ( $datequery != '' ) {
				if( version_compare( $arf_version, '4.3', '<') ){
					$orders = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $arf_paypal->db_paypal_order . ' WHERE form_id = %d ' . $datequery . ' ORDER BY id DESC', $form_id ) );
				} else {
					$orders = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_order, '*', 'WHERE form_id = %d ' . $datequery, array( $form_id ), '', 'ORDER BY id DESC' );
				}
			} else {
				if( version_compare( $arf_version, '4.3', '<') ){
					$orders = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $arf_paypal->db_paypal_order . ' WHERE form_id = %d ORDER BY id DESC', $form_id ) );
				} else {
					$orders = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_order, '*', 'WHERE form_id = %d', array( $form_id ), '', 'ORDER BY id DESC' );
				}
			}
		} else {
			if ( $datequery != '' ) {
				if( version_compare( $arf_version, '4.3', '<') ){
					$orders = $wpdb->get_results( 'SELECT * FROM ' . $arf_paypal->db_paypal_order . " WHERE id!='' " . $datequery . ' ORDER BY id DESC' );
				} else {
					$orders = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_order, '*', "WHERE id != '' " . $datequery, array(), '', 'ORDER BY id DESC' );
				}
			} else {
				if( version_compare( $arf_version, '4.3', '<') ){
					$orders = $wpdb->get_results( 'SELECT * FROM ' . $arf_paypal->db_paypal_order . ' ORDER BY id DESC' );
				} else {
					$orders = $arfform->arf_select_db_data( true, '', $arf_paypal->db_paypal_order, '*', '', array(), '', 'ORDER BY id DESC' );
				}
			}
		}

		if ( count( $orders ) > 0 ) {
			$o = 0;
			foreach ( $orders as $order ) {
				if ( ! isset( $orderData[ $o ] ) ) {
					$orderData[ $o ] = array();
				}
				if ( $is_version_compatible ) {
					$orderData[ $o ][] = '<div class="arf_custom_checkbox_wrapper arfmarginl15"><input id="cb-item-action-' . $order->id . '" type="checkbox" value="' . $order->id . '" name="item-action[]" /><svg width="18px" height="18px">' . ARF_CUSTOM_UNCHECKED_ICON . ARF_CUSTOM_CHECKED_ICON . '</svg></div><label for="cb-item-action-' . $order->id . '"><span></span></label>';
				} else {
					$orderData[ $o ][] = '<input id="cb-item-action-' . $order->id . '" class="chkstanard" type="checkbox" value="' . $order->id . '" name="item-action[]"><label for="cb-item-action-' . $order->id . '"><span></span></label>';
				}

				$orderData[ $o ][] = $order->txn_id;
				$orderData[ $o ][] = ( $order->payment_status == 'Completed' ) ? "<font class='arf_pp_complete_status'>" . $order->payment_status . '</font>' : "<font class='arf_pp_incomplete_status'>" . $order->payment_status . '</font>';

				if ( $is_version_compatible ) {
					$orderData[ $o ][] = $arformcontroller->arfdeciamlseparator( $order->mc_gross ) . ' ' . $order->mc_currency;
				} else {
					$orderData[ $o ][] = $order->mc_gross . ' ' . $order->mc_currency;
				}

				if ( isset( $order->payment_type ) && 1 == $order->payment_type ) {
					$orderData[ $o ][] = esc_html__( 'Donations', 'ARForms-paypal' );
				} elseif ( isset( $order->payment_type ) && 2 == $order->payment_type ) {
					$orderData[ $o ][] = esc_html__( 'Subscription', 'ARForms-paypal' );
				} else {
					$orderData[ $o ][] = esc_html__( 'Product / Service', 'ARForms-paypal' );
				}

				$orderData[ $o ][] = date( get_option( 'date_format' ), strtotime( $order->created_at ) );
				$orderData[ $o ][] = $order->payer_email;
				$orderData[ $o ][] = $order->payer_name;

				if ( $is_version_compatible ) {
					$action_btn = '<div class="arf-row-actions">';

					$action_btn .= "<div class='arfformicondiv arfhelptip' title='" . esc_html__( 'View Entry', 'ARForms-paypal' ) . "'><a href='javascript:void( 0);' onclick='open_entry_thickbox( {$order->entry_id});'><svg width='30px' height='30px' viewBox='-3 -8 32 32' class='arfsvgposition'><path xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' clip-rule='evenodd' fill='#ffffff' d='M12.993,15.23c-7.191,0-11.504-7.234-11.504-7.234  S5.801,0.85,12.993,0.85c7.189,0,11.504,7.19,11.504,7.19S20.182,15.23,12.993,15.23z M12.993,2.827 c-5.703,0-8.799,5.214-8.799,5.214s3.096,5.213,8.799,5.213c5.701,0,8.797-5.213,8.797-5.213S18.694,2.827,12.993,2.827z M12.993,11.572c-1.951,0-3.531-1.581-3.531-3.531s1.58-3.531,3.531-3.531c1.949,0,3.531,1.581,3.531,3.531  S14.942,11.572,12.993,11.572z'/></svg></a></div>";

					$action_btn .= "<div class='arfformicondiv arfhelptip arfdeleteentry_div_" . $order->id . "' title='" . esc_html__( 'Delete', 'ARForms-paypal' ) . "'><a class='arf_delete_entry' data-id='" . $order->id . "'><svg width='30px' height='30px' viewBox='-5 -5 32 32' class='arfsvgposition'><path xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' clip-rule='evenodd' fill='#ffffff' d='M18.435,4.857L18.413,19.87L3.398,19.88L3.394,4.857H1.489V2.929  h1.601h3.394V0.85h8.921v2.079h3.336h1.601l0,0v1.928H18.435z M15.231,4.857H6.597H5.425l0.012,13.018h10.945l0.005-13.018H15.231z   M11.4,6.845h2.029v9.065H11.4V6.845z M8.399,6.845h2.03v9.065h-2.03V6.845z' /></svg></a></div>";

					$action_btn .= "<div id='view_entry_detail_container_{$order->entry_id}' class='arf_pp_display_none'>" . $arrecordcontroller->get_entries_list( $order->entry_id ) . "</div><div class='arfmnarginbtm10 arf_clear_both'></div>";

					$action_btn .= '</div>';
				} else {
					$action_btn = "<a href='javascript:void(0);' onclick='open_entry_thickbox({$order->entry_id});'><img src='" . esc_url( ARFIMAGESURL . '/view_icon23.png' ) . "' title='" . esc_html__( 'View Entry', 'ARForms-paypal' ) . "' onmouseover=\"this.src='" . esc_url( ARFIMAGESURL . '/view_icon23_hover.png' ) . "';\" onmouseout=\"this.src='" . esc_url( ARFIMAGESURL . '/view_icon23.png' ) . "';\" class='arfhelptip' /></a>";

					$action_btn .= "<img src='" . esc_url( ARFIMAGESURL . '/delete_icon223.png' ) . "' title='" . esc_html__( 'Delete', 'ARForms-paypal' ) . "' onmouseover=\"this.src='" . esc_url( ARFIMAGESURL . '/delete_icon223_hover.png' ) . "';\" onmouseout=\"this.src='" . esc_url( ARFIMAGESURL . '/delete_icon223.png' ) . "';\" onclick=\"arf_ChangeID({$order->id})\" data-toggle='arfmodal' href='#delete_form_message' class='arfhelptip' />";

					$action_btn .= "<div id='view_entry_{$order->entry_id}' class='arfviewentrymodal arfmodal arfhide arffade arf_pp_view_entry_modal'>
										<div class='arfnewmodalclose' data-dismiss='arfmodal'><img src='" . esc_url( ARFIMAGESURL . '/close-button.png' ) . "' align='absmiddle' /></div>
    
                                        <div class='newform_modal_title_container'>
                                            <div class='newform_modal_title arf_pp_text_align_center'><img src='" . esc_url( ARFIMAGESURL . '/view-entry-icon.png' ) . "' align='absmiddle' />&nbsp;" . esc_html__( 'VIEW ENTRY', 'ARForms-paypal' ) . "</div>
                                        </div>	
    
								   		<div class='arfentry_modal_content'>" . $arrecordcontroller->get_entries_list( $order->entry_id ) . "</div>
										
										<div class='arf_clear_both'></div>
										
										<div class='arfviewentryclose arf_pp_view_entry_modal_close' data-dismiss='arfmodal'><img src='" . esc_url( ARFIMAGESURL . '/close-btnicon.png' ) . "' align='absmiddle' />" . esc_html__( 'Close', 'ARForms-paypal' ) . '</div>
									</div>';
				}

				$orderData[ $o ][] = $action_btn;
				$o++;
			}
		}

		return $orderData;
	}

	function list_forms( $message = '' ) {
		global $arf_paypal_version,$is_version_compatible;
		if ( $is_version_compatible ) {
			$file = 'list_forms_3.0.php';
		} else {
			$file = 'list_forms.php';
		}
		include ARF_PAYPAL_DIR . '/core/' . $file;
	}

	function arf_paypal_delete_form() {
		global $is_version_compatible, $arf_version;
		$id     = $_POST['id'];
		$action = $_POST['act'];
		if ( $action == 'delete' && $id ) {
			$res     = $this->delete_forms( $id );
			$message = esc_html__( 'Record is deleted successfully.', 'ARForms-paypal' );
			$errors  = array();
			if ( version_compare( $arf_version, '5.0', '>' ) ) {
				global $wpdb, $MdlDb, $arformcontroller;
				echo json_encode(
					array(
						'errors'   => $errors,
						'message'  => $message,
					)
				);
			} else {
				echo json_encode(
					array(
						'errors'   => $errors,
						'message'  => $message,
						'gridData' => $this->arf_get_paypal_form_data(),
					)
				);
			}
		}
		die();
	}

	function delete_forms( $id = 0 ) {
		if ( $id == 0 ) {
			return;
		}

		if ( $id ) {
			global $wpdb,$arf_paypal;
			$form = $wpdb->get_results( $wpdb->prepare( 'SELECT form_id FROM ' . $arf_paypal->db_paypal_forms . ' WHERE id = %d', $id ) );
			$form = $form[0];

			if ( isset( $form->form_id ) and $form->form_id != '' ) {
				$res = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $arf_paypal->db_paypal_order . ' WHERE form_id = %d', $form->form_id ) );
			}

			$res = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $arf_paypal->db_paypal_forms . ' WHERE id = %d', $id ) );

			return $res;
		}
	}

	function arf_paypal_form_bulk_act() {

		global $armainhelper, $arf_version;

		if ( ! isset( $_POST ) ) {
			return;
		}

		global $arfform;

		$bulkaction = $armainhelper->get_param( 'action1' );
		
		$message = '';

		$errors = array();


		if ( $bulkaction == -1 ) {
			$bulkaction = $armainhelper->get_param( 'action3' );
		}

		if ( ! empty( $bulkaction ) and strpos( $bulkaction, 'bulk_' ) === 0 ) {
			

			if ( isset( $_GET ) and isset( $_GET['action1'] ) ) {
				$_SERVER['REQUEST_URI'] = str_replace( '&action=' . $_GET['action1'], '', $_SERVER['REQUEST_URI'] );
			}

			if ( isset( $_GET ) and isset( $_GET['action3'] ) ) {
				$_SERVER['REQUEST_URI'] = str_replace( '&action=' . $_GET['action3'], '', $_SERVER['REQUEST_URI'] );
			}

			$bulkaction = str_replace( 'bulk_', '', $bulkaction );
						
		} else {
			$bulkaction = '-1';

			if ( isset( $_POST['bulkaction'] ) and $_POST['bulkaction1'] != '-1' ) {
				$bulkaction = $_POST['bulkaction1'];

			} elseif ( isset( $_POST['bulkaction3'] ) and $_POST['bulkaction3'] != '-1' ) {
				$bulkaction = $_POST['bulkaction3'];
			}
		}
		

		$ids = $armainhelper->get_param( 'item-action', '' );

		if ( empty( $ids ) ) {
			$errors[] = esc_html__( 'Please select one or more records', 'ARForms-paypal' );
		} else {
			if ( ! is_array( $ids ) ) {
				$ids = explode( ',', $ids );
			}

			if ( is_array( $ids ) ) {
				if ( $bulkaction == 'delete' ) {

					foreach ( $ids as $fid ) {
						$res_var = $this->delete_forms( $fid );
					}

					if ( $res_var ) {
						$message = esc_html__( 'Record is deleted successfully.', 'ARForms-paypal' );
					}
				}
			}
		}

		if ( version_compare( $arf_version, '5.0', '>' ) ) {
			global $wpdb, $MdlDb, $arformcontroller;
			echo json_encode(
				array(
					'errors'   => $errors,
					'message'  => $message,
				)
			);
		} else {
			echo json_encode(
				array(
					'errors'   => $errors,
					'message'  => $message,
					'gridData' => $this->arf_get_paypal_form_data(),
				)
			);		
		}

		die();
	}

	function arf_get_paypal_form_data() {
		global $wpdb, $arf_paypal, $MdlDb, $arformcontroller, $is_version_compatible;

		$rowData = array();
		$forms   = $wpdb->get_results( 'SELECT * FROM ' . $arf_paypal->db_paypal_forms . ' ORDER BY id DESC' );
		if ( count( $forms ) > 0 ) {
			$n = 0;
			foreach ( $forms as $form ) {
				$options = maybe_unserialize( $form->options );
				if ( ! isset( $rowData[ $n ] ) ) {
					$rowData[ $n ] = array();
				}
				if ( $is_version_compatible ) {

					$rowData[ $n ][] = "<div class='arf_custom_checkbox_wrapper arfmarginl15'><input id='cb-item-action-" . $form->id . "' type='checkbox' value='" . $form->id . "'  name='item-action[]' /><svg width='18px' height='18px'>" . ARF_CUSTOM_UNCHECKED_ICON . ARF_CUSTOM_CHECKED_ICON . "</svg></div><label for='cb-item-action-" . $form->id . "'></label>";
				} else {
					$rowData[ $n ][] = '<input id="cb-item-action-' . $form->id . '" class="chkstanard" type="checkbox" value="' . $form->id . '" name="item-action[]"><label for="cb-item-action-' . $form->id . '"><span></span></label>';
				}

				$rowData[ $n ][] = $form->form_id;

				$rowData[ $n ][] = "<a class='row-title' href='" . wp_nonce_url( "?page=ARForms-Paypal&arfaction=edit&id={$form->id}" ) . "'>" . $form->form_name . '</a>';

				$record_count = $wpdb->get_var( $wpdb->prepare( 'SELECT count( *) AS record_count FROM ' . $arf_paypal->db_paypal_order . ' WHERE form_id = %d', $form->form_id ) );

				$rowData[ $n ][] = "<a href='" . wp_nonce_url( '?page=ARForms-Paypal-order&form=' . $form->form_id ) . "'>" . $record_count . '</a>';

				$total_amount = $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( mc_gross) AS total_amount FROM ' . $arf_paypal->db_paypal_order . ' WHERE form_id = %d', $form->form_id ) );
				if ( $is_version_compatible ) {
					$rowData[ $n ][] = ( ( isset( $total_amount ) ) ? $arformcontroller->arfdeciamlseparator( $total_amount ) : $arformcontroller->arfdeciamlseparator( 0 ) ) . ' ' . $options['currency'];
				} else {
					$rowData[ $n ][] = ( ( isset( $total_amount->total_amount ) ) ? number_format( (float) $total_amount->total_amount, 2 ) : '0.00' ) . ' ' . $options['currency'];
				}

				$rowData[ $n ][] = date( get_option( 'date_format' ), strtotime( $form->created_at ) );

				$edit_link = "?page=ARForms-Paypal&arfaction=edit&id={$form->id}";

				if ( $is_version_compatible ) {

					$action_div = "<div class='arf-row-actions'>";

					$action_div .= "<div class='arfformicondiv arfhelptip' title='" . esc_html__( 'Edit Configuration', 'ARForms-paypal' ) . "'><a href='" . wp_nonce_url( $edit_link ) . "'><svg width='30px' height='30px' viewBox='-5 -4 30 30' class='arfsvgposition'><path xmlns='http://www.w3.org/2000/svg' fill='#ffffff' d='M17.469,7.115v10.484c0,1.25-1.014,2.264-2.264,2.264H3.75c-1.25,0-2.262-1.014-2.262-2.264V5.082  c0-1.25,1.012-2.264,2.262-2.264h9.518l-2.264,2.001H3.489v13.042h11.979V9.379L17.469,7.115z M15.532,2.451l-0.801,0.8l2.4,2.401  l0.801-0.8L15.532,2.451z M17.131,0.85l-0.799,0.801l2.4,2.4l0.801-0.801L17.131,0.85z M6.731,11.254l2.4,2.4l7.201-7.202  l-2.4-2.401L6.731,11.254z M5.952,14.431h2.264l-2.264-2.264V14.431z'></path></svg></a></div>";

					$action_div .= "<div class='arfformicondiv arfhelptip' title='" . esc_html__( 'Transactions', 'ARForms-paypal' ) . "'><a href='" . wp_nonce_url( "?page=ARForms-Paypal-order&form={$form->form_id}" ) . "'><svg width='30px' height='30px' viewBox='-5 -4 30 30' class='arfsvgposition'><path xmlns='http://www.w3.org/2000/svg' fill='#ffffff' d='M12.32,5.952c1.696-1.316,2.421-2.171,2.747-3.272c0.307-1.039-0.35-2.396-1.703-2.576    c-0.881-0.114-2.071,0.374-3.53,0.811c-0.477,0.143-0.979,0.143-1.451,0c-1.459-0.432-2.653-0.965-3.53-0.811    C3.234,0.389,2.892,1.73,3.149,2.68C3.45,3.789,4.2,4.635,5.896,5.952c-2.319,1.745-4.889,6.095-4.889,8.504    c0,3.314,3.854,5.647,8.101,5.647s8.141-2.333,8.141-5.647C17.249,12.047,14.639,7.696,12.32,5.952z M4.762,2.231    c-0.04-0.143-0.068-0.399,0.311-0.469c0.444-0.082,1.3-0.227,2.837,0.229c0.786,0.232,1.618,0.232,2.405,0    c1.536-0.457,2.393-0.307,2.837-0.229c0.313,0.053,0.346,0.326,0.31,0.469c-0.285,1.019-1.02,1.817-2.797,2.824    C10.167,4.884,9.65,4.79,9.116,4.79c-0.533,0-1.056,0.094-1.549,0.265C5.778,4.048,5.043,3.247,4.762,2.231z M9.108,18.093    c-2.462,0-5.51-0.747-5.51-3.637c0-2.633,2.624-8.007,5.51-8.007s5.471,5.374,5.471,8.007    C14.579,17.346,11.615,18.093,9.108,18.093z M9.202,12.316c-0.408,0-0.742-0.334-0.742-0.742s0.334-0.742,0.742-0.742    c0.208,0,0.399,0.082,0.542,0.232c0.27,0.286,0.722,0.302,1.007,0.033s0.302-0.721,0.033-1.007    c-0.241-0.257-0.539-0.448-0.869-0.563H8.489c-0.849,0.298-1.456,1.101-1.456,2.046c0,1.194,0.975,2.168,2.169,2.168    c0.407,0,0.742,0.334,0.742,0.742c0,0.408-0.335,0.742-0.742,0.742c-0.208,0-0.399-0.082-0.542-0.232    c-0.27-0.285-0.722-0.302-1.007-0.033s-0.302,0.722-0.033,1.007c0.241,0.257,0.538,0.449,0.869,0.563c0,0,0.738,0.281,1.426,0    c0.849-0.297,1.455-1.101,1.455-2.046C11.37,13.286,10.396,12.316,9.202,12.316z'/></svg></a></div>";

					$action_div .= "<div class='arfformicondiv arfhelptip arfdeleteform_div_" . $form->id . "' title='" . esc_html__( 'Delete', 'ARForms-paypal' ) . "'><a class='arf_paypal_delete' data-id='" . $form->id . "'><svg width='30px' height='30px' viewBox='-5 -5 32 32' class='arfsvgposition'><path xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' clip-rule='evenodd' fill='#ffffff' d='M18.435,4.857L18.413,19.87L3.398,19.88L3.394,4.857H1.489V2.929  h1.601h3.394V0.85h8.921v2.079h3.336h1.601l0,0v1.928H18.435z M15.231,4.857H6.597H5.425l0.012,13.018h10.945l0.005-13.018H15.231z   M11.4,6.845h2.029v9.065H11.4V6.845z M8.399,6.845h2.03v9.065h-2.03V6.845z' /></svg></a></div>";

					$action_div .= '</div>';
				} else {
					$action_div = "<a href='" . wp_nonce_url( $edit_link ) . "'><img src='" . esc_url( ARFIMAGESURL . '/edit-icon22.png' ) . "' onmouseover=\"this.src='" . esc_url( ARFIMAGESURL . '/edit-icon_hover22.png' ) . "';\" class='arfhelptip' title='" . esc_html__( 'Edit Configuration', 'ARForms-paypal' ) . "' onmouseout=\"this.src='" . esc_url( ARFIMAGESURL . '/edit-icon22.png' ) . "';\" /></a>";

					$action_div .= "<a href='" . wp_nonce_url( "?page=ARForms-Paypal-order&form={$form->form_id}" ) . "'><img src='" . esc_url( ARF_PAYPAL_URL . '/images/trans.png' ) . "' title='" . esc_html__( 'Transactions', 'ARForms-paypal' ) . "' class='arfhelptip' onmouseover=\"this.src='" . esc_url( ARF_PAYPAL_URL . '/images/trans_hover.png' ) . "';\" onmouseout=\"this.src='" . esc_url( ARF_PAYPAL_URL . '/images/trans.png' ) . "';\" /></a>";

					$action_div .= "<img src='" . esc_url( ARFIMAGESURL . '/delete_icon223.png' ) . "' title=" . esc_html__( 'Delete', 'ARForms-paypal' ) . " onmouseover=\"this.src='" . esc_url( ARFIMAGESURL . '/delete_icon223_hover.png' ) . "';\" onmouseout=\"this.src='" . esc_url( ARFIMAGESURL . '/delete_icon223.png' ) . "';\" class='arfhelptip arf_pp_cursor_pointer' onclick=\"arf_ChangeID({$form->id})\" data-toggle='arfmodal' href='#delete_form_message' /></a>";
				}

				$rowData[ $n ][] = $action_div;

				$n++;
			}
		}

		return $rowData;

	}

	function arf_paypal_save_settings_callback() {
		global $wpdb, $arfform, $armainhelper, $arformcontroller, $arf_paypal_version, $arfieldhelper, $arnotifymodel, $arf_paypal,$MdlDb,$is_version_compatible;

		$check_cap = $this->arf_paypal_check_user_cap( 'arfpaypalconfiguration', true );

		if ( 'success' != $check_cap ) {
			$user_cap = json_decode( $check_cap, true );
			echo json_encode(
				array(
					'success' => false,
					'message' => $user_cap[0],
				)
			);
			die;
		}

		if ( isset( $_REQUEST['arfaction'] ) && 'edit' == $_REQUEST['arfaction'] ) {
			$id = isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : '';

			if ( '' == $id ) {
				echo json_encode(
					array(
						'success' => false,
						'message' => 'redirect',
						'url'     => admin_url( 'admin.php?page=ARForms-Paypal&err=1' ),
					)
				);
				die;
			} else {
				$arf_form_chk = $wpdb->get_results( $wpdb->prepare( 'SELECT id FROM `' . $MdlDb->forms . '` WHERE id = %d', $_REQUEST['form_id'] ), ARRAY_A );
				$form_chk     = $wpdb->get_results( $wpdb->prepare( 'SELECT id FROM `' . $arf_paypal->db_paypal_forms . '` WHERE id = %d', $id ), ARRAY_A );
				if ( count( $arf_form_chk ) == 0 || count( $form_chk ) == 0 ) {
					echo json_encode(
						array(
							'success' => false,
							'message' => 'redirect',
							'url'     => admin_url( 'admin.php?page=ARForms-Paypal&err=1' ),
						)
					);
					die;
				} else {
					$form_data = $arfform->getOne( $_REQUEST['form_id'] );

					$new_values['form_name'] = $form_data->name;

					$options['merchant_email'] = esc_attr( $_REQUEST['arf_paypal_email'] );

					$options['paypal_mode'] = esc_attr( $_REQUEST['arf_paypal_mode'] );

					$options['continue_label'] = esc_attr( $_REQUEST['arf_paypal_continue_label'] );

					$options['cancel_url'] = esc_attr( $_REQUEST['arf_paypal_cancel_url'] );

					$options['notification'] = isset( $_REQUEST['arf_paypal_notification'] ) ? 1 : 0;

					$options['user_notification']  = isset( $_REQUEST['arf_paypal_user_notification'] ) ? 1 : 0;
					$options['user_email_content'] = esc_attr( isset( $_REQUEST['user_email_content'] ) ? $_REQUEST['user_email_content'] : '' );

					$options['title'] = esc_attr( $_REQUEST['arf_paypal_title'] );

					$options['currency'] = esc_attr( $_REQUEST['arf_paypal_currency'] );

					$options['first_name'] = esc_attr( $_REQUEST['arf_first_name'] );

					$options['last_name'] = esc_attr( $_REQUEST['arf_last_name'] );

					$options['email'] = esc_attr( $_REQUEST['arf_email'] );

					$options['state'] = esc_attr( $_REQUEST['arf_state'] );

					$options['address'] = esc_attr( $_REQUEST['arf_address'] );

					$options['address_2'] = esc_attr( $_REQUEST['arf_address_2'] );

					$options['city'] = esc_attr( $_REQUEST['arf_city'] );

					$options['zip'] = esc_attr( $_REQUEST['arf_zip'] );

					$options['country'] = esc_attr( $_REQUEST['arf_country'] );

					$options['amount'] = esc_attr( $_REQUEST['arf_amount'] );

					$options['payment_type'] = esc_attr( $_REQUEST['arf_paypal_payment_type'] );

					$options['email_content'] = esc_attr( $_REQUEST['email_content'] );

					$options['shipping_info'] = ( isset( $_REQUEST['shipping_info'] ) ) ? esc_attr( $_REQUEST['shipping_info'] ) : 0;

					$options['paypal_condition'] = ( isset( $_REQUEST['arf_paypal_condition'] ) ) ? esc_attr( $_REQUEST['arf_paypal_condition'] ) : 0;

					$options['arf_payment_type'] = esc_attr( $_REQUEST['arf_payment_type'] );

					$options['arf_multiple_product_service_type']           = ( isset( $_REQUEST['arf_multiple_product_service_type'] ) ) ? esc_attr( $_REQUEST['arf_multiple_product_service_type'] ) : 0;
					$options['arf_cl_field_multiple_product_service_type']  = esc_attr( $_REQUEST['arf_cl_field_multiple_product_service_type'] );
					$options['arf_cl_op_multiple_product_service_type']     = esc_attr( $_REQUEST['arf_cl_op_multiple_product_service_type'] );
					$options['cl_rule_value_multiple_product_service_type'] = esc_attr( $_REQUEST['cl_rule_value_multiple_product_service_type'] );
					$options['arf_multiple_product_service_amount'] = esc_attr( $_REQUEST['arf_multiple_product_service_amount'] );

					$options['arf_multiple_donations_service_type'] = (isset($_REQUEST['arf_multiple_donations_service_type'])) ? esc_attr($_REQUEST['arf_multiple_donations_service_type']) : 0;
	                $options['arf_cl_field_multiple_donations_service_type'] = esc_attr($_REQUEST['arf_cl_field_multiple_donations_service_type']);
	                $options['arf_cl_op_multiple_donations_service_type'] = esc_attr($_REQUEST['arf_cl_op_multiple_donations_service_type']);
	                $options['cl_rule_value_multiple_donations_service_type'] = esc_attr($_REQUEST['cl_rule_value_multiple_donations_service_type']);
	                $options['arf_multiple_donations_service_amount'] = esc_attr($_REQUEST['arf_multiple_donations_service_amount']);



					$options['arf_multiple_subscription_type'] = ( isset( $_REQUEST['arf_multiple_subscription_type'] ) ) ? esc_attr( $_REQUEST['arf_multiple_subscription_type'] ) : 0;
					$options['arf_cl_field_multiple_subscription_type']  = esc_attr( $_REQUEST['arf_cl_field_multiple_subscription_type'] );
					$options['arf_cl_op_multiple_subscription_type']     = esc_attr( $_REQUEST['arf_cl_op_multiple_subscription_type'] );
					$options['cl_rule_value_multiple_subscription_type'] = esc_attr( $_REQUEST['cl_rule_value_multiple_subscription_type'] );

					$options['arf_multiple_subscription_amount'] = esc_attr( $_REQUEST['arf_multiple_subscription_amount'] );

					$multiple_subscription_conditional_logic_rules = array();

					$rule_array = ( isset( $_REQUEST['rule_array_multiple_subscription'] ) && ! empty( $_REQUEST['rule_array_multiple_subscription'] ) ) ? $_REQUEST['rule_array_multiple_subscription'] : array();


					if ( count( $rule_array ) > 0 ) {
						$i = 1;
						foreach ( $rule_array as $v ) {

							$arf_paypal_days   = isset( $_REQUEST['arf_paypal_days_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_paypal_days_' . $v ] ) : '';
							$arf_paypal_months = isset( $_REQUEST['arf_paypal_months_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_paypal_months_' . $v ] ) : '';
							$arf_paypal_years  = isset( $_REQUEST['arf_paypal_years_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_paypal_years_' . $v ] ) : '';

							$arf_paypal_recurring_type = isset( $_REQUEST['arf_paypal_recurring_type_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_paypal_recurring_type_' . $v ] ) : '';

							$arf_paypal_recurring_time = isset( $_REQUEST['arf_paypal_recurring_time_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_paypal_recurring_time_' . $v ] ) : '';

							$arf_cl_op_multiple_subscription_duration_type = isset( $_REQUEST['arf_cl_op_multiple_subscription_duration_type_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_cl_op_multiple_subscription_duration_type_' . $v ] ) : '';

							$cl_rule_value_multiple_subscription_duration_type = isset( $_REQUEST['cl_rule_value_multiple_subscription_duration_type_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'cl_rule_value_multiple_subscription_duration_type_' . $v ] ) : '';

							$multiple_subscription_conditional_logic_rules[ $i ] = array(
								'id'                => $i,
								'arf_paypal_days'   => $arf_paypal_days,
								'arf_paypal_months' => $arf_paypal_months,
								'arf_paypal_years'  => $arf_paypal_years,
								'recurring_type'    => $arf_paypal_recurring_type,
								'recurring_time'    => $arf_paypal_recurring_time,
								'operator'          => $arf_cl_op_multiple_subscription_duration_type,
								'value'             => $cl_rule_value_multiple_subscription_duration_type,
							);
							$i++;
						}
					}

					$options['multiple_subscription_conditional_logic'] = array( 'rules' => $multiple_subscription_conditional_logic_rules );

					$conditional_logic_rules = array();

					$rule_array = ( isset( $_REQUEST['rule_array_paypal'] ) && ! empty( $_REQUEST['rule_array_paypal'] ) ) ? $_REQUEST['rule_array_paypal'] : array();

					if ( count( $rule_array ) > 0 ) {
						$i = 1;
						foreach ( $rule_array as $v ) {

							$conditional_logic_field      = isset( $_REQUEST['arf_cl_field_paypal_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_cl_field_paypal_' . $v ] ) : '';
							$conditional_logic_field_type = $arfieldhelper->get_field_type( $conditional_logic_field );
							$conditional_logic_op         = isset( $_REQUEST['arf_cl_op_paypal_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_cl_op_paypal_' . $v ] ) : '';
							$conditional_logic_value      = isset( $_REQUEST['cl_rule_value_paypal_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'cl_rule_value_paypal_' . $v ] ) : '';

							$conditional_logic_rules[ $i ] = array(
								'id'         => $i,
								'field_id'   => $conditional_logic_field,
								'field_type' => $conditional_logic_field_type,
								'operator'   => $conditional_logic_op,
								'value'      => $conditional_logic_value,
							);
							$i++;
						}
					}

					$options['conditional_logic'] = array(
						'if_cond' => isset( $_REQUEST['conditional_logic_if_cond_paypal'] ) ? esc_attr( $_REQUEST['conditional_logic_if_cond_paypal'] ) : '',
						'rules'   => $conditional_logic_rules,
					);

					$options['paypal_days']   = ( isset( $_REQUEST['arf_paypal_days'] ) ) ? esc_attr( $_REQUEST['arf_paypal_days'] ) : 1;
					$options['paypal_months'] = ( isset( $_REQUEST['arf_paypal_months'] ) ) ? esc_attr( $_REQUEST['arf_paypal_months'] ) : 1;
					$options['paypal_years']  = ( isset( $_REQUEST['arf_paypal_years'] ) ) ? esc_attr( $_REQUEST['arf_paypal_years'] ) : 1;

					$options['paypal_recurring_type'] = ( isset( $_REQUEST['arf_paypal_recurring_type'] ) ) ? esc_attr( $_REQUEST['arf_paypal_recurring_type'] ) : 'M';
					$options['paypal_recurring_time'] = ( isset( $_REQUEST['arf_paypal_recurring_time'] ) ) ? esc_attr( $_REQUEST['arf_paypal_recurring_time'] ) : 'infinite';

					$options['paypal_recurring_retry'] = ( isset( $_REQUEST['arf_paypal_recurring_retry'] ) ) ? esc_attr( $_REQUEST['arf_paypal_recurring_retry'] ) : '0';

					$options['paypal_trial_period'] = ( isset( $_REQUEST['arf_paypal_trial_period'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_period'] ) : '0';
					$options['paypal_trial_amount'] = ( isset( $_REQUEST['arf_paypal_trial_amount'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_amount'] ) : '0';
					$options['paypal_trial_days']   = ( isset( $_REQUEST['arf_paypal_trial_days'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_days'] ) : '1';
					$options['paypal_trial_months'] = ( isset( $_REQUEST['arf_paypal_trial_months'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_months'] ) : '1';
					$options['paypal_trial_years']  = ( isset( $_REQUEST['arf_paypal_trial_years'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_years'] ) : '1';

					$options['paypal_trial_recurring_type'] = ( isset( $_REQUEST['arf_paypal_trial_recurring_type'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_recurring_type'] ) : 'M';

					$form_options                    = maybe_unserialize( $form_data->options );
					$form_options['success_action']  = esc_attr( $_REQUEST['success_action'] );
					$form_options['success_msg']     = esc_attr( $_REQUEST['success_msg'] );
					$form_options['success_url']     = esc_attr( $_REQUEST['success_url'] );
					$form_options['success_page_id'] = esc_attr( $_REQUEST['success_page_id'] );
					$new_form_options                = maybe_serialize( $form_options );

					$opt_to_update = array(
						'options' => $new_form_options,
					);
					if ( $is_version_compatible ) {
						$form_options = maybe_unserialize( $form_data->arf_mapped_addon );
						if ( isset( $form_options['arf_mapped_addon'] ) && ! empty( $form_options['arf_mapped_addon'] ) ) {
							if ( ! in_array( 'paypal', $form_options['arf_mapped_addon'] ) ) {
								array_push( $form_options['arf_mapped_addon'], 'paypal' );
							}
						} else {
							$form_options                     = array();
							$form_options['arf_mapped_addon'] = array( 'paypal' );
						}

						$new_form_options_mapped_addon     = maybe_serialize( $form_options );
						$opt_to_update['arf_mapped_addon'] = $new_form_options_mapped_addon;
					}

					$wpdb->update(
						$MdlDb->forms,
						$opt_to_update,
						array( 'id' => $form_data->id )
					);

					$options               = apply_filters( 'arf_trim_values', $options );
					$new_values['options'] = maybe_serialize( $options );

					global $arf_paypal;
					$res = $wpdb->update( $arf_paypal->db_paypal_forms, $new_values, array( 'id' => $id ) );

					$values = array();

					$values = $new_values;

					$values['form_id'] = esc_attr( $_REQUEST['form_id'] );

					$values['form_name'] = esc_attr( $_REQUEST['form_name'] );

					$values['success_action'] = esc_attr( $_REQUEST['success_action'] );

					$values['success_msg'] = esc_attr( $_REQUEST['success_msg'] );

					$values['success_url'] = esc_attr( $_REQUEST['success_url'] );

					$values['success_page_id'] = esc_attr( $_REQUEST['success_page_id'] );

					$values['id'] = $id;

					unset( $values['options'] );

					foreach ( $options as $option_key => $option_val ) {
						   $values[ $option_key ] = $option_val;
					}

					$arfaction = 'edit';

					$message = esc_html__( 'Configuration saved successfully.', 'ARForms-paypal' );

					echo json_encode(
						array(
							'success' => true,
							'message' => $message,
						)
					);
					die;
				}
			}
		} else {

			if ( isset( $_REQUEST['arf_paypal_form'] ) && '' != $_REQUEST['arf_paypal_form'] ) {
				$new_form_id = $_REQUEST['arf_paypal_form'];

				$form_data = $arfform->getOne( $new_form_id );

				$new_values['form_id'] = $new_form_id;

				$new_values['form_name'] = $form_data->name;

				$options['merchant_email'] = esc_attr( $_REQUEST['arf_paypal_email'] );

				$options['paypal_mode'] = esc_attr( $_REQUEST['arf_paypal_mode'] );

				$options['continue_label'] = esc_attr( $_REQUEST['arf_paypal_continue_label'] );

				$options['cancel_url'] = esc_attr( $_REQUEST['arf_paypal_cancel_url'] );

				$options['notification'] = isset( $_REQUEST['arf_paypal_notification'] ) ? 1 : 0;

				$options['user_notification']  = isset( $_REQUEST['arf_paypal_user_notification'] ) ? 1 : 0;
				$options['user_email_content'] = esc_attr( isset( $_REQUEST['user_email_content'] ) ? $_REQUEST['user_email_content'] : '' );

				$options['title'] = esc_attr( $_REQUEST['arf_paypal_title'] );

				$options['currency'] = esc_attr( $_REQUEST['arf_paypal_currency'] );

				$options['first_name'] = esc_attr( $_REQUEST['arf_first_name'] );

				$options['last_name'] = esc_attr( $_REQUEST['arf_last_name'] );

				$options['email'] = esc_attr( $_REQUEST['arf_email'] );

				$options['state'] = esc_attr( $_REQUEST['arf_state'] );

				$options['address'] = esc_attr( $_REQUEST['arf_address'] );

				$options['address_2'] = esc_attr( $_REQUEST['arf_address_2'] );

				$options['city'] = esc_attr( $_REQUEST['arf_city'] );

				$options['zip'] = esc_attr( $_REQUEST['arf_zip'] );

				$options['country'] = esc_attr( $_REQUEST['arf_country'] );

				$options['amount'] = esc_attr( $_REQUEST['arf_amount'] );

				$options['payment_type'] = esc_attr( $_REQUEST['arf_paypal_payment_type'] );

				$options['email_content'] = esc_attr( $_REQUEST['email_content'] );

				$options['shipping_info'] = ( isset( $_REQUEST['shipping_info'] ) ) ? esc_attr( $_REQUEST['shipping_info'] ) : 0;

				$options['paypal_condition'] = ( isset( $_REQUEST['arf_paypal_condition'] ) ) ? esc_attr( $_REQUEST['arf_paypal_condition'] ) : 0;

				$options['arf_payment_type'] = esc_attr( $_REQUEST['arf_payment_type'] );

				$options['arf_multiple_product_service_type']           = ( isset( $_REQUEST['arf_multiple_product_service_type'] ) ) ? esc_attr( $_REQUEST['arf_multiple_product_service_type'] ) : 0;
				$options['arf_cl_field_multiple_product_service_type']  = esc_attr( $_REQUEST['arf_cl_field_multiple_product_service_type'] );
				$options['arf_cl_op_multiple_product_service_type']     = esc_attr( $_REQUEST['arf_cl_op_multiple_product_service_type'] );
				$options['cl_rule_value_multiple_product_service_type'] = esc_attr( $_REQUEST['cl_rule_value_multiple_product_service_type'] );
				$options['arf_multiple_product_service_amount'] = esc_attr( $_REQUEST['arf_multiple_product_service_amount'] );

				$options['arf_multiple_donations_service_type'] = (isset($_REQUEST['arf_multiple_donations_service_type'])) ? esc_attr($_REQUEST['arf_multiple_donations_service_type']) : 0;
                $options['arf_cl_field_multiple_donations_service_type'] = esc_attr($_REQUEST['arf_cl_field_multiple_donations_service_type']);
                $options['arf_cl_op_multiple_donations_service_type'] = esc_attr($_REQUEST['arf_cl_op_multiple_donations_service_type']);
                $options['cl_rule_value_multiple_donations_service_type'] = esc_attr($_REQUEST['cl_rule_value_multiple_donations_service_type']);
                $options['arf_multiple_donations_service_amount'] = esc_attr($_REQUEST['arf_multiple_donations_service_amount']);

				$options['arf_multiple_subscription_type'] = ( isset( $_REQUEST['arf_multiple_subscription_type'] ) ) ? esc_attr( $_REQUEST['arf_multiple_subscription_type'] ) : 0;
				$options['arf_cl_field_multiple_subscription_type']  = esc_attr( $_REQUEST['arf_cl_field_multiple_subscription_type'] );
				$options['arf_cl_op_multiple_subscription_type']     = esc_attr( $_REQUEST['arf_cl_op_multiple_subscription_type'] );
				$options['cl_rule_value_multiple_subscription_type'] = esc_attr( $_REQUEST['cl_rule_value_multiple_subscription_type'] );

				$options['arf_multiple_subscription_amount'] = esc_attr( $_REQUEST['arf_multiple_subscription_amount'] );

				$multiple_subscription_conditional_logic_rules = array();

				$rule_array = ( isset( $_REQUEST['rule_array_multiple_subscription'] ) && ! empty( $_REQUEST['rule_array_multiple_subscription'] ) ) ? $_REQUEST['rule_array_multiple_subscription'] : array();

				if ( count( $rule_array ) > 0 ) {
					$i = 1;
					foreach ( $rule_array as $v ) {

						$arf_paypal_days   = isset( $_REQUEST['arf_paypal_days_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_paypal_days_' . $v ] ) : '';
						$arf_paypal_months = isset( $_REQUEST['arf_paypal_months_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_paypal_months_' . $v ] ) : '';
						$arf_paypal_years  = isset( $_REQUEST['arf_paypal_years_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_paypal_years_' . $v ] ) : '';

						$arf_paypal_recurring_type = isset( $_REQUEST['arf_paypal_recurring_type_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_paypal_recurring_type_' . $v ] ) : '';

						$arf_paypal_recurring_time = isset( $_REQUEST['arf_paypal_recurring_time_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_paypal_recurring_time_' . $v ] ) : '';

						$arf_cl_op_multiple_subscription_duration_type = isset( $_REQUEST['arf_cl_op_multiple_subscription_duration_type_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_cl_op_multiple_subscription_duration_type_' . $v ] ) : '';

						$cl_rule_value_multiple_subscription_duration_type = isset( $_REQUEST['cl_rule_value_multiple_subscription_duration_type_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'cl_rule_value_multiple_subscription_duration_type_' . $v ] ) : '';

						$multiple_subscription_conditional_logic_rules[ $i ] = array(
							'id'                => $i,
							'arf_paypal_days'   => $arf_paypal_days,
							'arf_paypal_months' => $arf_paypal_months,
							'arf_paypal_years'  => $arf_paypal_years,
							'recurring_type'    => $arf_paypal_recurring_type,
							'recurring_time'    => $arf_paypal_recurring_time,
							'operator'          => $arf_cl_op_multiple_subscription_duration_type,
							'value'             => $cl_rule_value_multiple_subscription_duration_type,
						);
						$i++;
					}
				}

				$options['multiple_subscription_conditional_logic'] = array( 'rules' => $multiple_subscription_conditional_logic_rules );

				$conditional_logic_rules = array();

				$rule_array = ( isset( $_REQUEST['rule_array_paypal'] ) && ! empty( $_REQUEST['rule_array_paypal'] ) ) ? $_REQUEST['rule_array_paypal'] : array();

				if ( count( $rule_array ) > 0 ) {
					$i = 1;
					foreach ( $rule_array as $v ) {

						$conditional_logic_field      = isset( $_REQUEST['arf_cl_field_paypal_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_cl_field_paypal_' . $v ] ) : '';
						$conditional_logic_field_type = $arfieldhelper->get_field_type( $conditional_logic_field );
						$conditional_logic_op         = isset( $_REQUEST['arf_cl_op_paypal_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'arf_cl_op_paypal_' . $v ] ) : '';
						$conditional_logic_value      = isset( $_REQUEST['cl_rule_value_paypal_' . $v] ) ? stripslashes_deep( $_REQUEST[ 'cl_rule_value_paypal_' . $v ] ) : '';

						$conditional_logic_rules[ $i ] = array(
							'id'         => $i,
							'field_id'   => $conditional_logic_field,
							'field_type' => $conditional_logic_field_type,
							'operator'   => $conditional_logic_op,
							'value'      => $conditional_logic_value,
						);
						$i++;
					}
				}

				$options['conditional_logic'] = array(
					'if_cond' => isset( $_REQUEST['conditional_logic_if_cond_paypal'] ) ? esc_attr( $_REQUEST['conditional_logic_if_cond_paypal'] ) : '',
					'rules'   => $conditional_logic_rules,
				);

				$options['paypal_days']   = ( isset( $_REQUEST['arf_paypal_days'] ) ) ? esc_attr( $_REQUEST['arf_paypal_days'] ) : 1;
				$options['paypal_months'] = ( isset( $_REQUEST['arf_paypal_months'] ) ) ? esc_attr( $_REQUEST['arf_paypal_months'] ) : 1;
				$options['paypal_years']  = ( isset( $_REQUEST['arf_paypal_years'] ) ) ? esc_attr( $_REQUEST['arf_paypal_years'] ) : 1;

				$options['paypal_recurring_type'] = ( isset( $_REQUEST['arf_paypal_recurring_type'] ) ) ? esc_attr( $_REQUEST['arf_paypal_recurring_type'] ) : 'M';
				$options['paypal_recurring_time'] = ( isset( $_REQUEST['arf_paypal_recurring_time'] ) ) ? esc_attr( $_REQUEST['arf_paypal_recurring_time'] ) : 'infinite';

				$options['paypal_recurring_retry'] = ( isset( $_REQUEST['arf_paypal_recurring_retry'] ) ) ? esc_attr( $_REQUEST['arf_paypal_recurring_retry'] ) : '0';

				$options['paypal_trial_period'] = ( isset( $_REQUEST['arf_paypal_trial_period'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_period'] ) : '0';
				$options['paypal_trial_amount'] = ( isset( $_REQUEST['arf_paypal_trial_amount'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_amount'] ) : '0';
				$options['paypal_trial_days']   = ( isset( $_REQUEST['arf_paypal_trial_days'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_days'] ) : '1';
				$options['paypal_trial_months'] = ( isset( $_REQUEST['arf_paypal_trial_months'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_months'] ) : '1';
				$options['paypal_trial_years']  = ( isset( $_REQUEST['arf_paypal_trial_years'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_years'] ) : '1';

				$options['paypal_trial_recurring_type'] = ( isset( $_REQUEST['arf_paypal_trial_recurring_type'] ) ) ? esc_attr( $_REQUEST['arf_paypal_trial_recurring_type'] ) : 'M';

				$form_options                    = maybe_unserialize( $form_data->options );
				$form_options['success_action']  = esc_attr( $_REQUEST['success_action'] );
				$form_options['success_msg']     = esc_attr( $_REQUEST['success_msg'] );
				$form_options['success_url']     = esc_attr( $_REQUEST['success_url'] );
				$form_options['success_page_id'] = esc_attr( $_REQUEST['success_page_id'] );

				$new_form_options                = maybe_serialize( $form_options );

				$opt_to_update = array(
					'options' => $new_form_options,
				);
				if ( $is_version_compatible ) {
					$form_arf_mapped_addon = maybe_unserialize( $form_data->arf_mapped_addon );
					if ( isset( $form_arf_mapped_addon['arf_mapped_addon'] ) && ! empty( $form_arf_mapped_addon['arf_mapped_addon'] ) ) {
						if ( ! in_array( 'paypal', $form_arf_mapped_addon['arf_mapped_addon'] ) ) {
							array_push( $form_arf_mapped_addon['arf_mapped_addon'], 'paypal' );
						}
					} else {
						$form_arf_mapped_addon                     = array();
						$form_arf_mapped_addon['arf_mapped_addon'] = array( 'paypal' );
					}
					$new_form_arf_mapped_addon         = maybe_serialize( $form_arf_mapped_addon );
					$opt_to_update['arf_mapped_addon'] = $new_form_arf_mapped_addon;
				}

				$wpdb->update(
					$MdlDb->forms,
					$opt_to_update,
					array( 'id' => $form_data->id )
				);

				$options               = apply_filters( 'arf_trim_values', $options );

				$new_values['options'] = maybe_serialize( $options );

				$new_values['created_at'] = current_time( 'mysql' );

				$id = $wpdb->insert( $arf_paypal->db_paypal_forms, $new_values );

				$id = $wpdb->insert_id;

				$values = array();

				$values = $new_values;

				$values['success_action'] = esc_attr( $_REQUEST['success_action'] );

				$values['success_msg'] = esc_attr( $_REQUEST['success_msg'] );

				$values['success_url'] = esc_attr( $_REQUEST['success_url'] );

				$values['success_page_id'] = esc_attr( $_REQUEST['success_page_id'] );

				$values['id'] = $id;

				unset( $values['options'] );

				foreach ( $options as $option_key => $option_val ) {
						  $values[ $option_key ] = $option_val;
				}

				$arfaction = 'edit';

				$message = esc_html__( 'Configuration saved successfully.', 'ARForms-paypal' );

				echo json_encode(
					array(
						'success'   => true,
						'message'   => $message,
						'arfaction' => 'new',
						'new_id'    => $id,
						'form_id'   => $new_form_id,
						'form_name' => $new_values['form_name'],
					)
				);
			}
		}
		die;
	}

	function field_dropdown( $form_id, $name , $class , $default_value , $field_array ) {
		

		global $arffield, $MdlDb, $armainhelper,$is_version_compatible, $arfieldhelper;
		$field_list = array();
		$id         = ( isset( $id ) && $id != '' ) ? $id : '';
		$field_list = $field_array;

		$exclude    = array( 'divider', 'captcha', 'section', 'break', 'file', 'like','arf_repeater', 'matrix' );

		if ( $name == 'arf_amount' || $name == 'arf_multiple_product_service_amount' || $name == 'arf_multiple_donations_service_amount' || $name == 'arf_multiple_subscription_amount') {

			$selected_list_id      = '';
			$selected_list_label   = esc_html__( 'Select Field', 'ARForms-paypal' );
			$responder_list_option = '';
			if ( count( $field_list ) > 0 ) {
				array_push($exclude, 'arf_multiselect', 'checkbox');
				$cntr = 0;
				foreach ( $field_list as $field ) {
					if ( in_array( $field->type, $exclude ) ) {
						continue;
					}
					if( isset($field->field_options['parent_field_type']) && 'arf_repeater' == $field->field_options['parent_field_type'] ){
						continue;
					}

					if ( $default_value == $field->id ) {
						$selected_list_id    = $field->id;
						$selected_list_label = esc_attr( $field->name );
					}
					if ( $is_version_compatible ) {

						$responder_list_option .= '<li class="arf_selectbox_option" data-value="' . esc_attr( $field->id ) . '" data-label="' . $arfieldhelper->arf_execute_function( $field->name, 'strip_tags' ) . '">' . $armainhelper->truncate( $arfieldhelper->arf_execute_function( $field->name, 'strip_tags' ), 33 ) . '</li>';
					}
					$cntr++;
				}
			}

			?>

			<?php if ( $is_version_compatible ) { ?>
			<input id="<?php echo esc_attr( $name ); ?>"  name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $selected_list_id ); ?>" type="hidden" >
			<dl class="arf_selectbox arf_pp_small_dd_field" data-name="<?php echo esc_attr( $name ); ?>" data-id="<?php echo ( $id == '' ) ? esc_attr( $name ) : esc_attr( $id ); ?>">
				<dt><span><?php echo $arfieldhelper->arf_execute_function( $selected_list_label, 'strip_tags' ); ?></span>
				<input value="<?php echo esc_attr( $selected_list_id ); ?>" class="arf_autocomplete" type="text" autocomplete="off" />
				<svg viewBox="0 0 2000 1000" width="15px" height="15px">
				<g fill="#000">
				<path d="M1024 320q0 -26 -19 -45t-45 -19h-896q-26 0 -45 19t-19 45t19 45l448 448q19 19 45 19t45 -19l448 -448q19 -19 19 -45z"></path>
				</g>
				</svg>
				</dt>
				<dd>
					<ul data-id="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( 'add_field_' . $name ); ?>" class="<?php echo esc_attr( $class ); ?>">
						<li class="arf_selectbox_option" data-value="" data-label="<?php esc_html_e( 'Select Field', 'ARForms-paypal' ); ?>"><?php esc_html_e( 'Select Field', 'ARForms-paypal' ); ?></li>
						<?php echo $responder_list_option; ?>
					</ul>
				</dd>
			</dl>
		
			<?php } else { ?>

				<div class="sltstandard">
					<select name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $name ); ?>" class="<?php echo esc_attr( $class ); ?> arf_pp_small_dd_field frm-dropdown" data-width="211px" data-size="15">
						<option value=""><?php echo esc_html__( 'Select Field', 'ARForms-paypal' ); ?></option>
				<?php
				if ( count( $field_list ) > 0 ) {
					foreach ( $field_list as $field ) {
						if ( in_array( $field->type, $exclude ) ) {
								continue;
						}
						if( isset($field->field_options['parent_field_type']) && 'arf_repeater' == $field->field_options['parent_field_type'] ){
							continue;
						}
						?>
								<option value="<?php echo esc_attr( $field->id ); ?>" <?php selected( $default_value, $field->id ); ?>><?php echo $armainhelper->truncate( $field->name, 33 ); ?></option>
						<?php
					}
				}
				?>
					</select>
				</div>
				<?php
			}
		} else {
			$selected_list_id      = '';
			$selected_list_label   = esc_html__( 'Select Field', 'ARForms-paypal' );
			$responder_list_option = '';
			if ( count( $field_list ) > 0 ) {
				$cntr = 0;
				foreach ( $field_list as $field ) {
					if ( in_array( $field->type, $exclude ) ) {
						continue;
					}
					if( isset($field->field_options['parent_field_type']) && 'arf_repeater' == $field->field_options['parent_field_type'] ){
						continue;
					}

					if ( $default_value == $field->id ) {
						$selected_list_id    = $field->id;
						$selected_list_label = $field->name;
					}
					if ( $is_version_compatible ) {
						   $responder_list_option .= '<li class="arf_selectbox_option" data-value="' . $field->id . '" data-label="' . $arfieldhelper->arf_execute_function( $field->name, 'strip_tags' ) . '">' . $armainhelper->truncate( $arfieldhelper->arf_execute_function( $field->name, 'strip_tags' ), 33 ) . '</li>';
					}
					$cntr++;
				}
			}

			?>

			<?php if ( $is_version_compatible ) { ?>
				<input id="<?php echo esc_attr( $name ); ?>"  name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $selected_list_id ); ?>" type="hidden" >
				<dl class="arf_selectbox arf_pp_small_dd_field" data-name="<?php echo esc_attr( $name ); ?>" data-id="
																					  <?php
																						if ( $id == '' ) {
																							echo esc_attr( $name );
																						} else {
																							echo esc_attr( $id );
																						}
																						?>
																		   ">
					<dt>
						<span><?php echo $arfieldhelper->arf_execute_function( $selected_list_label, 'strip_tags' ); ?></span>
						<input value="<?php echo esc_html( $selected_list_id ); ?>" class="arf_autocomplete" type="text" autocomplete="off" />
						<svg viewBox="0 0 2000 1000" width="15px" height="15px">
							<g fill="#000">
								<path d="M1024 320q0 -26 -19 -45t-45 -19h-896q-26 0 -45 19t-19 45t19 45l448 448q19 19 45 19t45 -19l448 -448q19 -19 19 -45z"></path>
							</g>
						</svg>
					</dt>
					<dd>
						<ul data-id="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( 'add_field_' . $name ); ?>" class="<?php echo esc_attr( $class ); ?>">
							<li class="arf_selectbox_option" data-value="" data-label="<?php esc_html_e( 'Select Field', 'ARForms-paypal' ); ?>"><?php esc_html_e( 'Select Field', 'ARForms-paypal' ); ?></li>
							<?php echo $responder_list_option; ?>
						</ul>
					</dd>
				</dl>
				<?php
			} else {
				?>
			<div class="sltstandard">
				<select name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $name ); ?>" class="<?php echo esc_attr( $class ); ?> arf_pp_small_dd_field frm-dropdown" data-width="211px" data-size="15">
					<option value=""><?php echo esc_html__( 'Select Field', 'ARForms-paypal' ); ?></option>
				<?php
				if ( count( $field_list ) > 0 ) {
					foreach ( $field_list as $field ) {
						if ( in_array( $field->type, $exclude ) ) {
							continue;
						}
						if( isset($field->field_options['parent_field_type']) && 'arf_repeater' == $field->field_options['parent_field_type'] ){
							continue;
						}
						?>
							<option value="<?php echo esc_html( $field->id ); ?>" <?php selected( $default_value, $field->id ); ?>><?php echo $armainhelper->truncate( $field->name, 33 ); ?></option>
						<?php
					}
				}
				?>
				</select>
			</div>
		 
				<?php
			}
		}
	}

	function arf_paypal_field_dropdown() {

		global $arffield, $MdlDb, $armainhelper,$is_version_compatible,$arfieldhelper;

		$form_id = $_REQUEST['form_id'];

		$field_list = array();
		$res        = '';
		if ( is_numeric( $form_id ) ) {

			$exclude = "'divider','section','captcha','break','file','like','arf_repeater', 'checkbox', 'arf_multiselect', 'matrix'";

			$field_list = $arffield->getAll( 'fi.type not in ( ' . $exclude . ') and fi.form_id=' . (int) $form_id, 'id' );
		}
		?>
	   
		<?php
		if ( ! $is_version_compatible ) {
			if ( count( $field_list ) > 0 ) {
				foreach ( $field_list as $field ) {
					?>
					<option value="<?php echo esc_html( $field->id ); ?>"><?php echo $armainhelper->truncate( $field->name, 33 ); ?></option>
					<?php
				}
			}
		} else {
			global $armainhelper;
			$selected_list_id      = '';
			$selected_list_label   = esc_html__( 'Select Field', 'ARForms-paypal' );
			$responder_list_option = '<li class="arf_selectbox_option" data-value="" data-label=' . esc_html__( 'Select Field', 'ARForms-paypal' ) . '>' . esc_html__( 'Select Field', 'ARForms-paypal' ) . '</li>';
			if ( count( $field_list ) > 0 ) {
				$cntr = 0;
				foreach ( $field_list as $field ) {

					if( isset($field->field_options['parent_field_type']) && 'arf_repeater' == $field->field_options['parent_field_type']){
						continue;

					}
					if ( isset( $default_value ) && $default_value == $field->id ) {
						$selected_list_id    = $field->id;
						$selected_list_label = $field->name;
					}
					$responder_list_option .= '<li class="arf_selectbox_option" data-value="' . esc_html( $field->id ) . '" data-label="' . $arfieldhelper->arf_execute_function( $field->name, 'strip_tags' ) . '">' . $armainhelper->truncate( $arfieldhelper->arf_execute_function( $field->name, 'strip_tags' ), 33 ) . '</li>';
					$cntr++;
				}
			}	
		}
		$res .= $responder_list_option;
		$res .= '^|^';
		if ( is_numeric( $form_id ) ) {
			$exclude = "'divider','section','captcha','break','file','like','arf_repeater', 'matrix'";

			$field_list = $arffield->getAll( 'fi.type not in ( ' . $exclude . ') and fi.form_id=' . (int) $form_id, 'id' );
		}

		if ( ! $is_version_compatible ) {
			$responder_list_option = '<option value="">' . esc_html__( 'Select Field', 'ARForms-paypal' ) . '</option>';

			if ( count( $field_list ) > 0 ) {
				foreach ( $field_list as $field ) {
					$responder_list_option .= '<option value="' . esc_html( $field->id ) . '">' . $armainhelper->truncate( $field->name, 33 ) . '</option>';
				}
			}
		} else {
			$selected_list_id      = '';
			$selected_list_label   = esc_html__( 'Select Field', 'ARForms-paypal' );
			$responder_list_option = '';
			if ( count( $field_list ) > 0 ) {
				$cntr = 0;
				foreach ( $field_list as $field ) {
					if(isset($field->field_options['parent_field_type']) && 'arf_repeater' == $field->field_options['parent_field_type']){
						continue;

					}
					if ( isset( $default_value ) && $default_value == $field->id ) {
						$selected_list_id    = $field->id;
						$selected_list_label = $field->name;
					}
					$responder_list_option .= '<li class="arf_selectbox_option" data-value="' . esc_html( $field->id ) . '" data-label="' . $arfieldhelper->arf_execute_function( $field->name, 'strip_tags' ) . '">' . $armainhelper->truncate( $arfieldhelper->arf_execute_function( $field->name, 'strip_tags' ), 33 ) . '</li>';
					$cntr++;
				}
			}
		}

		$res .= $responder_list_option;
		echo $res;
		die();
	}

	function arfdelete_paypal_form( $form_id ) {
		global $wpdb, $db_record,$MdlDb,$arf_paypal;

		if ( ! $form_id ) {
			return;
		}

		$form_data = $wpdb->get_results( $wpdb->prepare( 'SELECT id FROM ' . $arf_paypal->db_paypal_forms . ' WHERE form_id = %d', $form_id ) );

		if ( count( $form_data ) > 0 ) {
			$form_data = $form_data[0];
			$entries   = $db_record->getAll( array( 'it.form_id' => $form_id ) );
			if ( count( $entries ) > 0 ) {
				foreach ( $entries as $item ) {
					$res = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $arf_paypal->db_paypal_order . ' WHERE entry_id = %d', $item->id ) );
				}
			}

			$res = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $arf_paypal->db_paypal_forms . ' WHERE id = %d', $form_data->id ) );
		}
	}

	function paypal_api() {

		global $arnotifymodel, $arf_paypal,$armainhelper,$arfieldhelper,$MdlDb;
		if ( ! $this->is_arforms_support() ) {
			return;
		}

		if ( ( ! isset( $_REQUEST['page'] ) || $_REQUEST['page'] != 'arforms_paypal_api' ) && ( ! isset($_REQUEST['arf_page'] ) || $_REQUEST['arf_page'] != 'arforms_paypal_api' ) ) {
			return;
		}

		if ( isset( $_POST['txn_id'] ) ) {
			global $wpdb;

			$req = 'cmd=_notify-validate';

			foreach ( $_POST as $key => $value ) {
				$value = urlencode( stripslashes( $value ) );
				$req  .= "&$key=$value";
			}

			$customs = explode( '|', $_REQUEST['custom'] );
			$form_id = $customs[1];
			if ( ! $form_id ) {
				return;
			}

			$form_data = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $arf_paypal->db_paypal_forms . ' WHERE form_id = %d', $form_id ) );

			if ( count( $form_data ) == 0 ) {
				return;
			}

			$form_data = $form_data[0];
			$options   = maybe_unserialize( $form_data->options );

			$sandbox = ( isset( $options['paypal_mode'] ) and $options['paypal_mode'] == 0 ) ? 'sandbox.' : '';

			$url = 'https://www.' . $sandbox . 'paypal.com/cgi-bin/webscr/';

			$request  = new WP_Http();
			$response = $request->post(
				$url,
				array(
					'sslverify' => false,
					'ssl'       => true,
					'body'      => $req,
					'timeout'   => 20,
				)
			);

			if ( ! is_wp_error( $response ) and $response['body'] == 'VERIFIED' ) {


				$txn_id          = isset( $_POST['txn_id'] ) ? $_POST['txn_id'] : '';
				$payment_status  = isset( $_POST['payment_status'] ) ? $_POST['payment_status'] : '';
				
				$is_payment_exists = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) from `" . $arf_paypal->db_paypal_order . "` WHERE txn_id = %s AND payment_status = %s", $txn_id, $payment_status  ) );

				if( $is_payment_exists > 0 ){
					return;
				}

				
				$payment_results = $wpdb->get_row( $wpdb->prepare( 'SELECT payment_status FROM ' . $arf_paypal->db_paypal_order . ' WHERE txn_id = %s', $txn_id ) );

				$existed_payment_status = !empty( $payment_results ) ? $payment_results->payment_status : '';

				if( $existed_payment_status != '' && $existed_payment_status == $payment_status ){
					return;
				}

				$item_name        = isset( $_POST['item_name'] ) ? $_POST['item_name'] : '';
				$txn_id           = isset( $_POST['txn_id'] ) ? $_POST['txn_id'] : '';
				$payment_status   = isset( $_POST['payment_status'] ) ? $_POST['payment_status'] : '';
				$payment_amount   = isset( $_POST['mc_gross'] ) ? $_POST['mc_gross'] : '';
				$payment_currency = isset( $_POST['mc_currency'] ) ? $_POST['mc_currency'] : '';
				$receiver_email   = isset( $_POST['receiver_email'] ) ? $_POST['receiver_email'] : '';
				$payer_email      = isset( $_POST['payer_email'] ) ? $_POST['payer_email'] : '';
				$quantity         = isset( $_POST['quantity'] ) ? $_POST['quantity'] : '';
				$user_id          = get_current_user_id();
				$payment_date     = isset( $_POST['payment_date'] ) ? $_POST['payment_date'] : '';
				$payer_name       = ( isset( $_POST['first_name'] ) && isset( $_POST['last_name'] ) ) ? $_POST['first_name'] . ' ' . $_POST['last_name'] : '';
				$entry_id         = $customs[0];
				$form_id          = $customs[1];
				$payment_type     = $customs[2];

				$insert_array = array(
					'item_name'      => $item_name,
					'txn_id'         => $txn_id,
					'payment_status' => $payment_status,
					'mc_gross'       => floatval( $payment_amount ),
					'mc_currency'    => $payment_currency,
					'quantity'       => $quantity,
					'payer_email'    => $payer_email,
					'payer_name'     => $payer_name,
					'payment_type'   => $payment_type,
					'user_id'        => $user_id,
					'entry_id'       => $entry_id,
					'form_id'        => $form_id,
					'payment_date'   => $payment_date,
					'created_at'     => current_time( 'mysql' ),
					'is_verified'    => 1,
				);
				if( empty( $payment_results ) ){
					$wpdb->insert(
						$arf_paypal->db_paypal_order,
						$insert_array,
						array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%s', '%s', '%d' ) );
				} else if( $existed_payment_status != $payment_status) {
					$wpdb->update(
						$arf_paypal->db_paypal_order,
						array(
							'payment_status' => $payment_status
						),
						array(
							'id' => $payment_results->id,
							'txn_id' => $txn_id
						)
					);
					return;
				} else if( $existed_payment_status == $payment_status ){
					return;
				}

				$wpdb->update( $MdlDb->entries, array( 'form_id' => $form_id ), array( 'id' => $entry_id ) );

				update_option( 'IPN_LOG' . $form_id . '_' . time(), maybe_serialize( $_POST ) );

				do_action( 'arf_after_paypal_successful_paymnet', $form_id, $entry_id, $txn_id );

				if ( ( ( isset( $options['notification'] ) and $options['notification'] ) || ( isset( $options['user_notification'] ) and $options['user_notification'] ) ) and $this->is_arforms_support() ) {
					global $arfsettings,$MdlDb;

					$arf_form_data = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $MdlDb->forms . ' WHERE id = %d', $form_id ) );
					$arf_form_data = $arf_form_data[0];
					$arf_options   = maybe_unserialize( $arf_form_data->options );

					$arfblogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );

					$admin_email = $arf_options['reply_to'];
					if ( ! is_email( $admin_email ) ) {
						$admin_email = $arfsettings->reply_to;
					}

					$admin_from_reply = $arf_options['ar_admin_from_email'];
					if ( ! is_email( $admin_from_reply ) ) {
						$admin_from_reply = $admin_email;
					}

					$reply_to_name = ( isset( $arf_options['ar_admin_from_name'] ) ) ? $arf_options['ar_admin_from_name'] : $arfsettings->reply_to_name;

					$entry = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM `' . $MdlDb->entries . '` WHERE id = %d', $entry_id ) );

					$admin_nreply_to = isset( $arf_options['ar_admin_reply_to_email'] ) ? $arf_options['ar_admin_reply_to_email'] : $arfsettings->reply_to_email;

					if ( isset( $admin_from_reply ) && $admin_from_reply != '' ) {
						$shortcodes       = $armainhelper->get_shortcodes( $admin_from_reply, $form_id );
						$reply_to         = $arfieldhelper->replace_shortcodes( $admin_from_reply, $entry, $shortcodes );
						$reply_to         = trim( $reply_to );
						$admin_from_reply = $arfieldhelper->arf_replace_shortcodes( $reply_to, $entry );
					}

					if ( isset( $admin_nreply_to ) && $admin_nreply_to != '' ) {
						$shortcodes      = $armainhelper->get_shortcodes( $admin_nreply_to, $form_id );
						$reply_to        = $arfieldhelper->replace_shortcodes( $admin_nreply_to, $entry, $shortcodes );
						$reply_to        = trim( $reply_to );
						$admin_nreply_to = $arfieldhelper->arf_replace_shortcodes( $reply_to, $entry );
					}

					$reply_to_name = ( isset( $arf_options['ar_admin_from_name'] ) ) ? $arf_options['ar_admin_from_name'] : $arfsettings->reply_to_name;

					$user_from_email = isset( $arf_options['ar_user_from_email'] ) ? $arf_options['ar_user_from_email'] : $arfsettings->reply_to;

					if ( isset( $user_from_email ) && $user_from_email != '' ) {
						$shortcodes      = $armainhelper->get_shortcodes( $user_from_email, $form_id );
						$reply_to        = $arfieldhelper->replace_shortcodes( $user_from_email, $entry, $shortcodes );
						$reply_to        = trim( $reply_to );
						$user_from_email = $arfieldhelper->arf_replace_shortcodes( $reply_to, $entry );
					}

					$user_reply_to_email = isset( $arf_options['ar_user_nreplyto_email'] ) ? $arf_options['ar_user_nreplyto_email'] : $arfsettings->reply_to_email;

					if ( isset( $user_reply_to_email ) && $user_reply_to_email != '' ) {
						$shortcodes          = $armainhelper->get_shortcodes( $user_reply_to_email, $form_id );
						$reply_to            = $arfieldhelper->replace_shortcodes( $user_reply_to_email, $entry, $shortcodes );
						$reply_to            = trim( $reply_to );
						$user_reply_to_email = $arfieldhelper->arf_replace_shortcodes( $reply_to, $entry );
					}

					$user_reply_to_name = isset( $arf_options['ar_user_from_name'] ) ? $arf_options['ar_user_from_name'] : $arfsettings->reply_to_name;

					$item_name        = $_POST['item_name'];
					$txn_id           = $_POST['txn_id'];
					$payment_status   = $_POST['payment_status'];
					$payment_amount   = $_POST['mc_gross'];
					$payment_currency = $_POST['mc_currency'];
					$payment_date     = $_POST['payment_date'];
					$payer_email      = $_POST['payer_email'];
					$payer_id         = $_POST['payer_id'];
					$payer_fname      = $_POST['first_name'];
					$payer_lname      = $_POST['last_name'];

					if ( isset( $options['notification'] ) and $options['notification'] ) {

						$subject = esc_html__( 'Payment received on', 'ARForms-paypal' ) . ' ' . $arfblogname;
						$message = nl2br( $options['email_content'] );
						if ( empty( $message ) ) {
							$message = $arf_paypal->defalut_email_content();
						}

						$message = str_replace( '[transaction_id]', $txn_id, $message );
						$message = str_replace( '[amount]', floatval( $payment_amount ), $message );
						$message = str_replace( '[currency]', $payment_currency, $message );
						$message = str_replace( '[payment_date]', $payment_date, $message );
						$message = str_replace( '[site_name]', $arfblogname, $message );
						$message = str_replace( '[payer_email]', $payer_email, $message );
						$message = str_replace( '[payer_id]', $payer_id, $message );
						$message = str_replace( '[payer_fname]', $payer_fname, $message );
						$message = str_replace( '[payer_lname]', $payer_lname, $message );

						$arnotifymodel->send_notification_email_user( $admin_email, $subject, $message, $admin_from_reply, $reply_to_name, true, array(), false, false, true, false, $admin_nreply_to );
					}

					if ( isset( $options['user_notification'] ) and $options['user_notification'] ) {
						$email_field       = $options['email'];
						$entry_payer_email = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $MdlDb->entry_metas . ' WHERE field_id = %d AND entry_id = %d', $email_field, $entry_id ) )->entry_value;

						echo esc_html( $email_field );
						echo '<br>' . esc_html( $entry_payer_email );

						if ( ! empty( $entry_payer_email ) ) {
							$subject = esc_html__( 'Payment received on', 'ARForms-paypal' ) . ' ' . $arfblogname;
							$message = nl2br( $options['user_email_content'] );
							if ( empty( $message ) ) {
								$message = $arf_paypal->user_defalut_email_content();
							}

							$message = str_replace( '[transaction_id]', $txn_id, $message );
							$message = str_replace( '[amount]', floatval( $payment_amount ), $message );
							$message = str_replace( '[currency]', $payment_currency, $message );
							$message = str_replace( '[payment_date]', $payment_date, $message );
							$message = str_replace( '[site_name]', $arfblogname, $message );
							$message = str_replace( '[payer_email]', $payer_email, $message );
							$message = str_replace( '[payer_id]', $payer_id, $message );
							$message = str_replace( '[payer_fname]', $payer_fname, $message );
							$message = str_replace( '[payer_lname]', $payer_lname, $message );

							$arnotifymodel->send_notification_email_user( $entry_payer_email, $subject, $message, $admin_from_reply, $reply_to_name, true, array(), false, false, true, false, $user_reply_to_email );
						}
					}
				}
			}
		}
	}

	function paypal_response() {
		if ( ! $this->is_arforms_support() ) {
			return;
		}

		if ( ( ! isset( $_REQUEST['page'] ) || $_REQUEST['page'] != 'arforms_paypal_response' ) && ( !isset( $_REQUEST['arf_page'] ) || $_REQUEST['arf_page'] != 'arforms_paypal_response' ) ) {
			return;
		}

		global $wpdb,$arf_paypal,$MdlDb,$arrecordcontroller, $maincontroller, $arf_version, $arnotifymodel,$fid;

		$maincontroller->arf_start_session(true);

		if ( isset( $_POST['txn_id'] ) and $_POST['txn_id'] != '' ) {

			$item_name        = !empty( $_POST['item_name'] ) ? $_POST['item_name'] : '';
			$txn_id           = $_POST['txn_id'];
			$payment_status   = $_POST['payment_status'];
			$payment_amount   = $_POST['mc_gross'];
			$payment_currency = $_POST['mc_currency'];
			$receiver_email   = isset( $_POST['receiver_email'] ) ? $_POST['receiver_email'] : '';
			$payer_email      = $_POST['payer_email'];
			$quantity         = !empty( $_POST['quantity'] ) ? $_POST['quantity'] : 1;
			$user_id          = get_current_user_id();
			$payment_date     = $_POST['payment_date'];
			$customs          = explode( '|', $_REQUEST['custom'] );
			$entry_id         = $customs[0];
			$form_id          = $customs[1];
			$payment_type     = $customs[2];
			$fid = $form_id;

			$payment_results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $arf_paypal->db_paypal_order . ' WHERE txn_id = %s', $txn_id ) );

			$pageurl = isset( $_SESSION['arf_return_url'][ $form_id ] ) ? $_SESSION['arf_return_url'][ $form_id ] : '';
			if ( ! isset( $pageurl ) || $pageurl == '' ) {
				$pageurl = get_home_url();
			}

			if( version_compare( $arf_version, '4.4', '<' ) ){
				$this->arf_paypal_check_response( $_SESSION, true );
			} else {

				$admin_email_notification_data = get_option( 'arf_paypal_admin_email_notification_' . $entry_id . '_' . $form_id );
				$user_email_notification_data = get_option( 'arf_paypal_user_email_notification_' . $entry_id . '_' . $form_id );

				if( !empty( $admin_email_notification_data ) ){
					$admin_email_notify_data = json_decode( $admin_email_notification_data, true );

					$arf_to_mail       			= $admin_email_notify_data['arf_admin_emails'];
					$arf_admin_subject  		= $admin_email_notify_data['arf_admin_subject'];
					$arf_admin_mail_body       	= $admin_email_notify_data['arf_admin_mail_body'];
					$arf_admin_reply_to      	= $admin_email_notify_data['arf_admin_reply_to'];
					$arf_admin_reply_to_email   = $admin_email_notify_data['arf_admin_reply_to_email'];
					$arf_admin_reply_to_name 	= $admin_email_notify_data['arf_admin_reply_to_name'];
					$arf_admin_plain_text    	= $admin_email_notify_data['arf_admin_plain_text'];
					$arf_admin_attachments   	= $admin_email_notify_data['arf_admin_attachments'];
					$arf_admin_cc_emails 		= $admin_email_notify_data['arf_admin_cc_emails'];
					$arf_admin_bcc_emails 		= $admin_email_notify_data['arf_admin_bcc_emails'];
					foreach( $arf_to_mail as $email ){
						$arnotifymodel->send_notification_email_user( $email, $arf_admin_subject, $arf_admin_mail_body, $arf_admin_reply_to, $arf_admin_reply_to_name, $arf_admin_plain_text, $arf_admin_attachments, false, false, true, false, $arf_admin_reply_to_email, $arf_admin_cc_emails, $arf_admin_bcc_emails );
					}
					delete_option( 'arf_paypal_admin_email_notification_' . $entry_id . '_' . $form_id );
				}

				if( !empty( $user_email_notification_data ) ){
					$user_email_notify_data = json_decode( $user_email_notification_data, true );

					$arf_to_mail       = $user_email_notify_data['to'];
					$arf_mail_subject  = $user_email_notify_data['subject'];
					$arf_message       = $user_email_notify_data['message'];
					$arf_reply_to      = $user_email_notify_data['reply_to'];
					$arf_reply_to_name = $user_email_notify_data['reply_to_name'];
					$arf_plain_text    = $user_email_notify_data['plain_text'];
					$arf_attachments   = $user_email_notify_data['attachments'];
					$arf_return_value  = $user_email_notify_data['return_value'];
					$arf_use_only_smtp = $user_email_notify_data['use_only_smtp'];
					$arf_nreply_to     = $user_email_notify_data['nreply_to'];
					$arnotifymodel->send_notification_email_user( $arf_to_mail, $arf_mail_subject, $arf_message, $arf_reply_to, $arf_reply_to_name, $arf_plain_text, $arf_attachments, $arf_return_value, $arf_use_only_smtp, true, false, $arf_nreply_to );
					delete_option( 'arf_paypal_user_email_notification_' . $entry_id . '_' . $form_id );
				}

			}

			$arnotifymodel->arf_autoreponder_entry($entry_id, $form_id, true);
			do_action( 'arf_after_payment_check' , $entry_id , $form_id );

			$wpdb->update( $MdlDb->entries, array( 'form_id' => $form_id ), array( 'id' => $entry_id ) );

			$arf_form_data = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $MdlDb->forms . ' WHERE id = %d', $form_id ) );
			$arf_form_data = $arf_form_data[0];
			$arf_options   = maybe_unserialize( $arf_form_data->options );

			if ( $arf_options['success_action'] == 'redirect' and isset( $arf_options['success_url'] ) and $arf_options['success_url'] != '' ) {
				if ( isset( $arf_options['arf_data_with_url'] ) && $arf_options['arf_data_with_url'] == 1 ) {
					$fields            = $wpdb->get_results( $wpdb->prepare( 'SELECT id FROM `' . $MdlDb->fields . '` WHERE form_id = %d', $form_id ) );
					$posted_field_data = array();
					foreach ( $fields as $k => $field ) {
						$field_id    = $field->id;
						$entry_value = $wpdb->get_row( $wpdb->prepare( 'SELECT entry_value FROM `' . $MdlDb->entry_metas . '` WHERE entry_id = %d AND field_id = %d', $entry_id, $field_id ) );
						if ( isset( $entry_value ) ) {
							$posted_field_data[ $field_id ] = $entry_value->entry_value;
						}
					}

					echo $arrecordcontroller->generate_redirect_form( $arf_form_data, $arf_options['success_url'], $arf_options['arf_data_with_url_type'], $posted_field_data );
				} else {
					wp_redirect( $arf_options['success_url'] );
					die;
				}
				exit;
			} else {

				$entry_metas = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $MdlDb->entry_metas . ' WHERE field_id = 0 AND entry_id = %d', $entry_id ) );
				if ( isset( $entry_metas->entry_value ) ) {
					$page_return_url = explode( '|', $entry_metas->entry_value );
				} else {
					$page_return_url = array(
						'0' => '1',
						'1' => '',
					);
				}

				if ( isset( $page_return_url[1] ) && $page_return_url[1] != '' ) {
					$pageurl = $page_return_url[1];
				}

				if ( isset( $page_return_url[0] ) && $page_return_url[0] == 0 ) {

					if ( strstr( $pageurl, '?' ) ) {
						$pageurl = esc_url( $pageurl . '&arf_conf=' . $form_id );
					} else {
						$pageurl = esc_url( $pageurl . '?arf_conf=' . $form_id );
					}
				}

				wp_redirect( html_entity_decode( $pageurl ) );
				exit;
			}
		} else {
			if ( isset( $_GET['custom'] ) && $_GET['custom'] != '' ) {
				$customs  = explode( '|', $_GET['custom'] );
				$entry_id = $customs[0];
				$form_id  = $customs[1];

				$pageurl = isset( $_SESSION['arf_return_url'][ $form_id ] ) ? $_SESSION['arf_return_url'][ $form_id ] : '';
				if ( ! isset( $pageurl ) || $pageurl == '' ) {
					$pageurl = get_home_url();
				}

				if( version_compare( $arf_version, '4.3.6', '<' ) ){
					$this->arf_paypal_check_response( $_SESSION, true );
				} else {
					$admin_email_notification_data = get_option( 'arf_paypal_admin_email_notification_' . $entry_id . '_' . $form_id );
					$user_email_notification_data = get_option( 'arf_paypal_user_email_notification_' . $entry_id . '_' . $form_id );

					if( !empty( $admin_email_notification_data ) ){
						$admin_email_notify_data = json_decode( $admin_email_notification_data, true );

						$arf_to_mail       			= $admin_email_notify_data['arf_admin_emails'];
						$arf_admin_subject  		= $admin_email_notify_data['arf_admin_subject'];
						$arf_admin_mail_body       	= $admin_email_notify_data['arf_admin_mail_body'];
						$arf_admin_reply_to      	= $admin_email_notify_data['arf_admin_reply_to'];
						$arf_admin_reply_to_email   = $admin_email_notify_data['arf_admin_reply_to_email'];
						$arf_admin_reply_to_name 	= $admin_email_notify_data['arf_admin_reply_to_name'];
						$arf_admin_plain_text    	= $admin_email_notify_data['arf_admin_plain_text'];
						$arf_admin_attachments   	= $admin_email_notify_data['arf_admin_attachments'];
						$arf_admin_cc_emails 		= $admin_email_notify_data['arf_admin_cc_emails'];
						$arf_admin_bcc_emails 		= $admin_email_notify_data['arf_admin_bcc_emails'];
						foreach( $arf_to_mail as $email ){
							$arnotifymodel->send_notification_email_user( $email, $arf_admin_subject, $arf_admin_mail_body, $arf_admin_reply_to, $arf_admin_reply_to_name, $arf_admin_plain_text, $arf_admin_attachments, false, false, true, false, $arf_admin_reply_to_email, $arf_admin_cc_emails, $arf_admin_bcc_emails );
						}
						delete_option( 'arf_paypal_admin_email_notification_' . $entry_id . '_' . $form_id );
					}

					if( !empty( $user_email_notification_data ) ){
						$user_email_notify_data = json_decode( $user_email_notification_data, true );

						$arf_to_mail       = $user_email_notify_data['to'];
						$arf_mail_subject  = $user_email_notify_data['subject'];
						$arf_message       = $user_email_notify_data['message'];
						$arf_reply_to      = $user_email_notify_data['reply_to'];
						$arf_reply_to_name = $user_email_notify_data['reply_to_name'];
						$arf_plain_text    = $user_email_notify_data['plain_text'];
						$arf_attachments   = $user_email_notify_data['attachments'];
						$arf_return_value  = $user_email_notify_data['return_value'];
						$arf_use_only_smtp = $user_email_notify_data['use_only_smtp'];
						$arf_nreply_to     = $user_email_notify_data['nreply_to'];
						$arnotifymodel->send_notification_email_user( $arf_to_mail, $arf_mail_subject, $arf_message, $arf_reply_to, $arf_reply_to_name, $arf_plain_text, $arf_attachments, $arf_return_value, $arf_use_only_smtp, true, false, $arf_nreply_to );
						delete_option( 'arf_paypal_user_email_notification_' . $entry_id . '_' . $form_id );
					}
				}
				$arnotifymodel->arf_autoreponder_entry($entry_id, $form_id, true);
				do_action( 'arf_after_payment_check' , $entry_id , $form_id );
				$wpdb->update( $MdlDb->entries, array( 'form_id' => $form_id ), array( 'id' => $entry_id ) );

				$arf_form_data = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $MdlDb->forms . ' WHERE id = %d', $form_id ) );
				$arf_form_data = $arf_form_data[0];
				$arf_options   = maybe_unserialize( $arf_form_data->options );

				if ( $arf_options['success_action'] == 'redirect' and isset( $arf_options['success_url'] ) and $arf_options['success_url'] != '' ) {

					if ( isset( $arf_options['arf_data_with_url'] ) && $arf_options['arf_data_with_url'] == 1 ) {
						$fields            = $wpdb->get_results( $wpdb->prepare( 'SELECT id FROM `' . $MdlDb->fields . '` WHERE form_id = %d', $form_id ) );
						$posted_field_data = array();
						foreach ( $fields as $k => $field ) {
							$field_id    = $field->id;
							$entry_value = $wpdb->get_row( $wpdb->prepare( 'SELECT entry_value FROM `' . $MdlDb->entry_metas . '` WHERE entry_id = %d AND field_id = %d', $entry_id, $field_id ) );
							if ( isset( $entry_value ) ) {
								$posted_field_data[ $field_id ] = $entry_value->entry_value;
							}
						}
						echo $arrecordcontroller->generate_redirect_form( $arf_form_data, $arf_options['success_url'], $arf_options['arf_data_with_url_type'], $posted_field_data );
					} else {
						wp_redirect( $arf_options['success_url'] );
						die;
					}
					exit;
				} else {

					$entry_metas = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $MdlDb->entry_metas . ' WHERE field_id = 0 AND entry_id = %d', $entry_id ) );
					if ( isset( $entry_metas->entry_value ) ) {
						$page_return_url = explode( '|', $entry_metas->entry_value );
					} else {
						$page_return_url = array(
							'0' => '1',
							'1' => '',
						);
					}

					if ( isset( $page_return_url[1] ) and $page_return_url[1] != '' ) {
						$pageurl = $page_return_url[1];
					}

					if ( isset( $page_return_url[0] ) and $page_return_url[0] == 0 ) {

						if ( strstr( $pageurl, '?' ) ) {
							$pageurl = esc_url( $pageurl . '&arf_conf=' . $form_id );
						} else {
							$pageurl = esc_url( $pageurl . '?arf_conf=' . $form_id );
						}
					}
					wp_redirect( html_entity_decode( $pageurl ) );
					exit;
				}
			} else {
				$pageurl = get_home_url();
				wp_redirect( $pageurl );
				exit;
			}
		}
	}

	function getwpversion() {
		global $arf_paypal_version, $arf_paypal;
		$bloginformation = array();
		$str             = $arf_paypal->get_rand_alphanumeric( 10 );

		$bloginformation[] = get_bloginfo( 'name' );
		$bloginformation[] = get_bloginfo( 'description' );
		$bloginformation[] = home_url();
		$bloginformation[] = get_bloginfo( 'admin_email' );
		$bloginformation[] = get_bloginfo( 'version' );
		$bloginformation[] = get_bloginfo( 'language' );
		$bloginformation[] = $arf_paypal_version;
		$bloginformation[] = $_SERVER['SERVER_ADDR'];
		$bloginformation[] = $str;

		update_option( 'wp_paypal_get_version', $str );

		$valstring  = implode( '||', $bloginformation );
		$encodedval = base64_encode( $valstring );

		$urltopost = 'http://reputeinfosystems.net/arforms/wpinfo_paypal.php';
		$response  = wp_remote_post(
			$urltopost,
			array(
				'method'      => 'POST',
				'timeout'     => 45,
				'redirection' => 5,
				'httpversion' => '1.0',
				'blocking'    => true,
				'headers'     => array(),
				'body'        => array( 'wpversion' => $encodedval ),
				'cookies'     => array(),
			)
		);
	}

	function assign_rand_value( $num ) {

		switch ( $num ) {
			case '1':
				$rand_value = 'a';
				break;
			case '2':
				$rand_value = 'b';
				break;
			case '3':
				$rand_value = 'c';
				break;
			case '4':
				$rand_value = 'd';
				break;
			case '5':
				$rand_value = 'e';
				break;
			case '6':
				$rand_value = 'f';
				break;
			case '7':
				$rand_value = 'g';
				break;
			case '8':
				$rand_value = 'h';
				break;
			case '9':
				$rand_value = 'i';
				break;
			case '10':
				$rand_value = 'j';
				break;
			case '11':
				$rand_value = 'k';
				break;
			case '12':
				$rand_value = 'l';
				break;
			case '13':
				$rand_value = 'm';
				break;
			case '14':
				$rand_value = 'n';
				break;
			case '15':
				$rand_value = 'o';
				break;
			case '16':
				$rand_value = 'p';
				break;
			case '17':
				$rand_value = 'q';
				break;
			case '18':
				$rand_value = 'r';
				break;
			case '19':
				$rand_value = 's';
				break;
			case '20':
				$rand_value = 't';
				break;
			case '21':
				$rand_value = 'u';
				break;
			case '22':
				$rand_value = 'v';
				break;
			case '23':
				$rand_value = 'w';
				break;
			case '24':
				$rand_value = 'x';
				break;
			case '25':
				$rand_value = 'y';
				break;
			case '26':
				$rand_value = 'z';
				break;
			case '27':
				$rand_value = '0';
				break;
			case '28':
				$rand_value = '1';
				break;
			case '29':
				$rand_value = '2';
				break;
			case '30':
				$rand_value = '3';
				break;
			case '31':
				$rand_value = '4';
				break;
			case '32':
				$rand_value = '5';
				break;
			case '33':
				$rand_value = '6';
				break;
			case '34':
				$rand_value = '7';
				break;
			case '35':
				$rand_value = '8';
				break;
			case '36':
				$rand_value = '9';
				break;
		}
		return $rand_value;
	}

	function get_rand_alphanumeric( $length ) {
		if ( $length > 0 ) {
			$rand_id = '';
			for ( $i = 1; $i <= $length; $i++ ) {
				mt_srand( (float) microtime() * 1000000 );
				$num      = mt_rand( 1, 36 );
				$rand_id .= $this->assign_rand_value( $num );
			}
		}
		return $rand_id;
	}

	function arfpaypal_backup() {
		$databaseversion = get_option( 'arf_paypal_version' );
		update_option( 'old_arf_paypal_version', $databaseversion );
	}

	function upgrade_data() {

		global $newarfpaypalversion;

		if ( ! isset( $newarfpaypalversion ) || $newarfpaypalversion == '' ) {
			$newarfpaypalversion = get_option( 'arf_paypal_version' );
		}

		if ( version_compare( $newarfpaypalversion, '2.6', '<' ) ) {
			$path = ARF_PAYPAL_DIR . '/core/upgrade_arfpaypal_latest_data.php';
			if ( file_exists( $path ) ) {
				include $path;
			}
		}
	}

	function paypal_form_dropdown( $name, $default_value = '', $blank = true, $onchange = false ) {
		global $wpdb,$arf_paypal,$MdlDb,$is_version_compatible;
		$forms                 = $wpdb->get_results( 'SELECT pyl.*,frm.name FROM ' . $arf_paypal->db_paypal_forms . ' pyl INNER JOIN ' . $MdlDb->forms . ' frm ON frm.id=pyl.form_id' );
		$responder_list_option = '';
		$def_id                = '';
		$def_label             = '-' . $blank . ' -';
		foreach ( $forms as $form ) {
			if ( $default_value == $form->form_id ) {
				$def_id    = $form->form_id;
				$def_label = $form->form_name;
			}
			$form_title             = $this->get_form_name( $form->form_id );
			$responder_list_option .= '<li class="arf_selectbox_option" data-value="' . esc_html( $form->form_id ) . '" data-label="' . $form_title . '">' . $form_title . ' (' . $this->get_order_count( $form->form_id ) . ')</li>';
		}
		?>
		
		<?php if ( $is_version_compatible ) { ?>
	   <input name="<?php echo esc_html( $name ); ?>" id="<?php echo esc_html( $name ); ?>" <?php if ( $onchange ) { echo 'onchange="' . $onchange . '"'; } ?>value="<?php echo isset( $def_id ) ? esc_html( $def_id ) : ''; ?>" type="hidden" />
			
		<dl class="arf_selectbox" data-name="<?php echo esc_html( $name ); ?>" data-id="<?php echo esc_html( $name ); ?>">
		<dt><span><?php echo isset( $def_label ) ? esc_attr($def_label) : ''; ?></span>
		<input value="<?php echo isset( $def_id ) ? esc_html( $def_id ) : ''; ?>" class="arf_autocomplete" type="text" autocomplete="off">
		<svg viewBox="0 0 2000 1000" width="15px" height="15px">
		<g fill="#000">
		<path d="M1024 320q0 -26 -19 -45t-45 -19h-896q-26 0 -45 19t-19 45t19 45l448 448q19 19 45 19t45 -19l448 -448q19 -19 19 -45z"></path>
		</g>
		</svg>
		</dt>
		<dd>
		<ul data-id="<?php echo esc_html($name); ?>">
			<li class="arf_selectbox_option" data-value="<?php echo esc_html( $def_id ); ?>" data-label="<?php echo $def_label; ?>"><?php echo $def_label; ?></li>
			<?php echo $responder_list_option; ?>
		</ul>
		</dd>
	</dl>
		<?php } else { ?>
		<select name="<?php echo esc_html( $name ); ?>" id="<?php echo esc_html( $name ); ?>" 
			<?php
			if ( $onchange ) {
				echo 'onchange="' . $onchange . '"';
			}
			?>
									 data-width="290px" data-size="20">
			<option value=""><?php echo ( $blank == 1 ) ? '' : '- ' . $blank . ' -'; ?></option>
			<?php
			if ( count( $forms ) > 0 ) {
				foreach ( $forms as $form ) {
					?>
					<option value="<?php echo esc_html( $form->form_id ); ?>" <?php selected( $default_value, $form->form_id ); ?>><?php echo $form->name; ?> ( <?php echo $this->get_order_count( $form->form_id ); ?>)</option> 
					<?php
				}
			}
			?>
		</select>
	 
			<?php
		}
	}

	function get_order_count( $form_id = 0 ) {
		global $wpdb,$arf_paypal;
		$record_count = $wpdb->get_results( $wpdb->prepare( 'SELECT count(*) AS record_count FROM ' . $arf_paypal->db_paypal_order . ' WHERE form_id = %d', $form_id ) );
		$record_count = $record_count[0];
		return ( isset( $record_count->record_count ) ) ? $record_count->record_count : 0;
	}

	function get_form_name( $form_id = 0 ) {
		global $wpdb,$MdlDb;
		$form_name = $wpdb->get_results( $wpdb->prepare( 'SELECT name FROM ' . $MdlDb->forms . ' WHERE id = %d', $form_id ) );
		$form_name = $form_name[0];
		return ( isset( $form_name->name ) ) ? stripslashes( $form_name->name ) : '';
	}

	function arfp_form_order() {
		$form_id = $_POST['form_id'];

		$startdate = $_POST['start_date'];
		$enddate   = $_POST['end_date'];

		global $style_settings, $wp_scripts;
		$wp_format_date = get_option( 'date_format' );

		if ( $wp_format_date == 'F j, Y' || $wp_format_date == 'm/d/Y' ) {
			$date_format_new = 'mm/dd/yy';
		} elseif ( $wp_format_date == 'd/m/Y' ) {
			$date_format_new = 'dd/mm/yy';
		} elseif ( $wp_format_date == 'Y/m/d' ) {
			$date_format_new = 'dd/mm/yy';
		} else {
			$date_format_new = 'mm/dd/yy';
		}

		$datequery = '';
		if ( $startdate != '' and $enddate != '' ) {
			if ( $date_format_new == 'dd/mm/yy' ) {
				$startdate = str_replace( '/', '-', $startdate );
				$enddate   = str_replace( '/', '-', $enddate );
			}
			$new_start_date_var = date( 'Y-m-d', strtotime( $startdate ) );
			$new_end_date_var   = date( 'Y-m-d', strtotime( $enddate ) );

			$datequery .= " and DATE( created_at) >= '" . $new_start_date_var . "' and DATE( created_at) <= '" . $new_end_date_var . "'";
		} elseif ( $startdate != '' and $enddate == '' ) {
			if ( $date_format_new == 'dd/mm/yy' ) {
				$startdate = str_replace( '/', '-', $startdate );
			}
			$new_start_date_var = date( 'Y-m-d', strtotime( $startdate ) );

			$datequery .= " and DATE( created_at) >= '" . $new_start_date_var . "'";
		} elseif ( $startdate == '' and $enddate != '' ) {
			if ( $date_format_new == 'dd/mm/yy' ) {
				$enddate = str_replace( '/', '-', $enddate );
			}
			$new_end_date_var = date( 'Y-m-d', strtotime( $enddate ) );

			$datequery .= " and DATE( created_at) <= '" . $new_end_date_var . "'";
		}

		$message = '';
		$errors  = array();
		global $is_version_compatible;
		$gridData = $this->arf_paypal_get_order_data( $form_id, $datequery );

		echo json_encode(
			array(
				'errors'   => $errors,
				'message'  => $message,
				'gridData' => $gridData,
			)
		);
		die();
	}

	function defalut_email_content() {
		$message = '';

		$message .= esc_html__( 'Hello admin,', 'ARForms-paypal' ) . "\n\n";
		$message .= esc_html__( 'Payment successfully received from', 'ARForms-paypal' ) . " [site_name]. \r\n\n";
		$message .= esc_html__( 'Following are the payment details:', 'ARForms-paypal' ) . "\r\n\n";
		$message .= esc_html__( 'Transaction id', 'ARForms-paypal' ) . ": [transaction_id] \n";
		$message .= esc_html__( 'Amount paid', 'ARForms-paypal' ) . ": [amount] [currency] \n";
		$message .= esc_html__( 'Payment date', 'ARForms-paypal' ) . ": [payment_date] \n";
		$message .= esc_html__( 'Payer Email', 'ARForms-paypal' ) . ": [payer_email] \n";
		$message .= esc_html__( 'Payer ID', 'ARForms-paypal' ) . ": [payer_id]\n";
		$message .= esc_html__( 'Payer First name', 'ARForms-paypal' ) . ": [payer_fname] \n";
		$message .= esc_html__( 'Payer Last name', 'ARForms-paypal' ) . ': [payer_lname]';
		$message .= "\n\n\n" . esc_html__( 'Thank you', 'ARForms-paypal' );
		$message .= "\n[site_name]";

		return $message;
	}

	function user_defalut_email_content() {
		$message  = '';
		$message .= esc_html__( 'Hello user,', 'ARForms-paypal' ) . "\n\n";
		$message .= esc_html__( 'Payment successfully received from', 'ARForms-paypal' ) . " [site_name]. \r\n\n";
		$message .= esc_html__( 'Following are the payment details:', 'ARForms-paypal' ) . "\r\n\n";
		$message .= esc_html__( 'Transaction id', 'ARForms-paypal' ) . ": [transaction_id] \n";
		$message .= esc_html__( 'Amount paid', 'ARForms-paypal' ) . ": [amount] [currency] \n";
		$message .= esc_html__( 'Payment date', 'ARForms-paypal' ) . ": [payment_date] \n";
		$message .= esc_html__( 'Payer Email', 'ARForms-paypal' ) . ": [payer_email] \n";
		$message .= esc_html__( 'Payer ID', 'ARForms-paypal' ) . ": [payer_id]\n";
		$message .= esc_html__( 'Payer First name', 'ARForms-paypal' ) . ": [payer_fname] \n";
		$message .= esc_html__( 'Payer Last name', 'ARForms-paypal' ) . ': [payer_lname]';
		$message .= "\n\n\n" . esc_html__( 'Thank you', 'ARForms-paypal' );
		$message .= "\n[site_name]";
		return $message;
	}

	function parse_standalone_request() {

		global $armainhelper;
		if ( ! $this->is_arforms_support() ) {
			return;
		}

		$plugin = $armainhelper->get_param( 'plugin' );

		$action = isset( $_REQUEST['arfaction'] ) ? 'arfaction' : 'action';

		$action = $armainhelper->get_param( $action );

		if ( ! empty( $plugin ) and $plugin == 'ARForms-Paypal' and ! empty( $action ) and $action == 'csv' ) {

			$this->export_to_csv();
		}
	}

	function export_to_csv() {
		if ( ! current_user_can( 'arfpaypaltransaction' ) ) {

			global $arfsettings;

			wp_die( $arfsettings->admin_permission );
		}

		if ( ! ini_get( 'safe_mode' ) ) {
			set_time_limit( 0 );
		}

		global $current_user, $arfform, $arffield, $db_record, $arfrecordmeta, $wpdb, $style_settings;

		include ARF_PAYPAL_DIR . '/core/export_data.php';
	}

	function arf_change_form_entry( $form_id, $entry_id, $txn_id ) {
		if ( ! $entry_id || ! $form_id ) {
			return;
		}

		global $wpdb,$MdlDb;

		$wpdb->update( $MdlDb->entries, array( 'form_id' => $form_id ), array( 'id' => $entry_id ) );
	}

	function add_new_rule_paypal_v3() {
		global $arf_paypal,$arffield;
		$form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : '';
		$rule_i  = isset( $_POST['next_rule_id'] ) ? $_POST['next_rule_id'] : 1;
		$field_array = array();
		if ( isset( $form_id ) && $form_id != '' && $form_id != '0' ) {
			$field_array = $arffield->getAll( 'fi.form_id=' . (int) $form_id, 'id' );
		}
		?>
		<input type="hidden" name="rule_array_paypal[]" value="<?php echo esc_html( $rule_i ); ?>" />
		<div class="sltstandard arf_pp_cl_field_dd"><?php echo $arf_paypal->arf_cl_field_menu( $form_id, 'arf_cl_field_paypal_' . $rule_i, 'arf_cl_field_paypal_' . $rule_i, '', $field_array ); ?></div>
	  
		<div class="sltstandard arf_pp_cl_field_dd"><?php echo $arf_paypal->arf_cl_rule_menu( 'arf_cl_op_paypal_' . $rule_i, 'arf_cl_op_paypal_' . $rule_i, 'is' ); ?></div>
		
		<input type="text" name="cl_rule_value_paypal<?php echo esc_html( '_' .  $rule_i ); ?>" id="cl_rule_value_paypal<?php echo esc_html( '_' . $rule_i ); ?>" class="txtmodal1 arf_pp_cl_field_input" />
		&nbsp;
		<span class="bulk_add_remove">
			<span onclick="arf_add_new_law_paypal();" class="bulk_add"><svg viewBox="0 -4 32 32"><g><?php echo ARF_PLUS_ICON; ?></g></svg></span>
			<span onclick="delete_rule_paypal( this);" class="bulk_remove"><svg viewBox="0 -4 32 32"><g><?php echo ARF_MINUS_ICON; ?></g></svg></span>
		</span>
		<?php
		die();
	}

	function add_new_rule_paypal() {
		global $arffield;
		$form_id = $_POST['form_id'];
		$rule_i  = $_POST['next_rule_id'] ? $_POST['next_rule_id'] : 1;

		if ( isset( $form_id ) && $form_id != '' && $form_id != '0' ) {
			$field_array = $arffield->getAll( 'fi.form_id=' . (int) $form_id, 'id' );
		}
		?>
		<input type="hidden" name="rule_array_paypal[]" value="<?php echo esc_html( $rule_i ); ?>" />
		<div class="sltstandard arf_pp_cl_field_dd"><?php echo $this->arf_cl_field_menu( $form_id, 'arf_cl_field_paypal_' . $rule_i, 'arf_cl_field_paypal_' . $rule_i, '', $field_array ); ?></div>
		
		<div class="sltstandard arf_pp_cl_field_dd"><?php echo $this->arf_cl_rule_menu( 'arf_cl_op_paypal_' . $rule_i, 'arf_cl_op_paypal_' . $rule_i, 'is' ); ?></div>
		
		<input type="text" name="cl_rule_value_paypal<?php echo esc_html( '_' . $rule_i ); ?>" id="cl_rule_value_paypal<?php echo esc_html( '_' . $rule_i ); ?>" class="txtstandardnew" value="" />
		&nbsp;
		<span class="bulk_add_remove">
			<button type="button" onclick="arf_add_new_law_paypal();" class="bulk_add">&nbsp;</button>
			<span onclick="delete_rule_paypal( this);" class="bulk_remove">&nbsp;</span>
		</span>
		<?php
		die();
	}

	function arf_cl_field_menu( $form_id, $select_name, $select_id , $default_field_id , $field_array ) {

		global $arffield, $arfieldhelper,$is_version_compatible,$armainhelper;
		$field_list = array();
		$field_list = $field_array;
		$id         = ( isset( $id ) && $id != '' ) ? $id : '';
		$exclude    = array( 'divider', 'section', 'captcha', 'break', 'file','arf_repeater', 'matrix');

		$select_id = ( isset( $select_id ) ) ? $select_id : $select_name;

		$selected_list_id      = '';
		$selected_list_label   = esc_html__( 'Select Field', 'ARForms-paypal' );
		$responder_list_option = '';
		if ( count( $field_list ) > 0 ) {
			$cntr = 0;
			foreach ( $field_list as $field ) {
				if ( in_array( $field->type, $exclude ) ) {
					continue;
				}
				if(isset($field->field_options['parent_field_type']) && 'arf_repeater' == $field->field_options['parent_field_type'] ){
						continue;
				}

				if ( $default_field_id == $field->id ) {
					$selected_list_id    = $field->id;
					$selected_list_label = $field->name;
				}
				if ( $is_version_compatible ) {
					$responder_list_option .= '<li class="arf_selectbox_option" data-value="' . esc_html( $field->id ) . '" data-label="' . $arfieldhelper->arf_execute_function( $field->name, 'strip_tags' ) . '">' . $armainhelper->truncate( $arfieldhelper->arf_execute_function( $field->name, 'strip_tags' ), 33 ) . '</li>';
				}
				$cntr++;
			}
		}

		if ( $is_version_compatible ) {
			?>
			<input id="<?php echo esc_attr( $select_name ); ?>"  name="<?php echo esc_html( $select_name ); ?>" value="<?php echo esc_attr( $default_field_id ); ?>" type="hidden" >
			<dl class="arf_selectbox arf_pp_small_dd_field" data-name="<?php echo esc_html( $select_name ); ?>" data-id="
															<?php
															if ( $id == '' ) {
																								  echo esc_html( $select_name );
															} else {
																							echo esc_html( $id );
															}
															?>
												 ">
				<dt><span><?php echo $arfieldhelper->arf_execute_function( $selected_list_label, 'strip_tags' ); ?></span>
				<input value="<?php echo esc_html( $selected_list_id ); ?>" class="arf_autocomplete" type="text" autocomplete="off">
				<svg viewBox="0 0 2000 1000" width="15px" height="15px">
				<g fill="#000">
				<path d="M1024 320q0 -26 -19 -45t-45 -19h-896q-26 0 -45 19t-19 45t19 45l448 448q19 19 45 19t45 -19l448 -448q19 -19 19 -45z"></path>
				</g>
				</svg>
				</dt>
				<dd>
					<ul data-id="<?php echo esc_html( $select_name ); ?>" id="<?php echo esc_html( 'add_field_' . $select_id ); ?>" class="arf_paypal_fields">
			<?php echo $responder_list_option; ?>
					</ul>
				</dd>
			</dl>
	
			<?php

		} else {

			$fields = $field_array;
			echo '<select name="' . esc_html( $select_name ) . '" id="' . esc_attr( $select_id ) . '" class="arf_paypal_fields field_dropdown_menu" data-size="6" data-width="150px">';
			echo '<option value="">' . esc_html__( 'Select Field', 'ARForms-paypal' ) . '</option>';

			if ( count( $fields ) > 0 ) {
				foreach ( $fields as $field ) {
					if ( in_array( $field->type, $exclude ) ) {
						continue;
					}
					if( isset($field->field_options['parent_field_type']) && 'arf_repeater' == $field->field_options['parent_field_type'] ){
						continue;
					}

					$field_id = $arfieldhelper->get_actual_id( $field->id );

					if ( $default_field_id != 0 and $default_field_id == $field_id ) {
						echo '<option value="' . esc_html( $field_id ) . '" selected="selected">' . $field->name . '</option>';
					} else {
						echo '<option value="' . esc_html( $field_id ) . '">' . $field->name . '</option>';
					}
				}
			}
			echo '</select>';
		}

	}

	function arf_wp_pages_dropdown( $field_name, $page_id, $truncate = false, $id = '' ) {
		global $wpdb, $armainhelper;

		$pages = $armainhelper->get_pages();

		if ( $id != '' ) {
			$selec_id = $id;
		} else {
			$selec_id = $field_name;
		}

		$arf_cl_field_selected_option = array();
		$arf_cl_field_options         = '';
		$cntr                         = 0;
		foreach ( $pages as $page ) {

			$post_title_value = ( $truncate ) ? $armainhelper->truncate( $page->post_title, $truncate ) : $page->post_title;
			$selected         = '';
			if ( ( isset( $_POST[ $field_name ] ) and $_POST[ $field_name ] == $page->ID ) or ( ! isset( $_POST[ $field_name ] ) and $page_id == $page->ID ) || $cntr == 0 ) {
				$arf_cl_field_selected_option['page_id'] = $page->ID;
				$arf_cl_field_selected_option['name']    = $post_title_value;
				$selected                                = ' selected="selected" ';
			}

			$arf_cl_field_options .= '<option value="' . esc_html( $page->ID ) . '" ' . $selected . ' >' . $post_title_value . '</option>';
			$cntr++;
		}
		$arf_cl_selected_page_id = isset( $arf_cl_field_selected_option['page_id'] ) ? $arf_cl_field_selected_option['page_id'] : '';
		$arf_cl_selected_name    = isset( $arf_cl_field_selected_option['name'] ) ? $arf_cl_field_selected_option['name'] : '';
		echo "<select name='" . $field_name . "' id='" . $selec_id . "' data-size='10'>";
			echo $arf_cl_field_options;
		echo '</select>';
	}

	function arf_cl_rule_menu( $select_name, $select_id = '', $default_rule = 'is' ) {

		$conditional_rules = array(
			'is'           => esc_html__( 'equals', 'ARForms-paypal' ),
			'is not'       => esc_html__( 'not equals', 'ARForms-paypal' ),
			'greater than' => esc_html__( 'greater than', 'ARForms-paypal' ),
			'less than'    => esc_html__( 'less than', 'ARForms-paypal' ),
			'contains'     => esc_html__( 'contains', 'ARForms-paypal' ),
			'not contains' => esc_html__( 'not contains', 'ARForms-paypal' ),
		);

		$select_id = ( isset( $select_id ) ) ? $select_id : $select_name;

		global $armainhelper,$is_version_compatible;
		unset( $responder_list_option );
		$responder_list_option = '';
		$id                    = ( isset( $id ) && $id != '' ) ? $id : '';
		$cnt                   = 0;
		foreach ( $conditional_rules as $rule_id => $rule ) {
			if ( $default_rule == $rule_id ) {
				$selected_list_id    = $rule_id;
				$selected_list_label = $rule;
			} elseif ( $cnt == 0 ) {
				$selected_list_id    = $rule_id;
				$selected_list_label = $rule;
			}
			$cnt++;
			$responder_list_option .= '<li class="arf_selectbox_option" data-value="' . esc_html( $rule_id ) . '" data-label="' . esc_attr( $rule ) . '">' . $rule . '</li>';
		}

		if ( $is_version_compatible ) {
			?>
			<input id="<?php echo esc_html( $select_name ); ?>"  name="<?php echo esc_html( $select_name ); ?>" value="<?php echo esc_html( $default_rule ); ?>" type="hidden" />
			<dl class="arf_selectbox arf_pp_bulk_act_dd" data-name="<?php echo esc_html( $select_name ); ?>" data-id="
															<?php
															if ( $id == '' ) {
																									  echo esc_html( $select_name );
															} else {
																							 echo esc_html( $id );
															}
															?>
												 ">
				<dt><span><?php echo $selected_list_label; ?></span>
				<input value="<?php echo esc_html( $selected_list_id ); ?>" class="" type="text">
				<svg viewBox="0 0 2000 1000" width="15px" height="15px">
				<g fill="#000">
				<path d="M1024 320q0 -26 -19 -45t-45 -19h-896q-26 0 -45 19t-19 45t19 45l448 448q19 19 45 19t45 -19l448 -448q19 -19 19 -45z"></path>
				</g>
				</svg>
				</dt>
				<dd>
					<ul data-id="<?php echo esc_html( $select_name ); ?>" id="<?php echo esc_attr( 'add_field_' . $select_id ); ?>" class="operator_dropdown_menu">
			<?php echo $responder_list_option; ?>
					</ul>
				</dd>
			</dl>
	 
			<?php
		} else {

			echo '<select name="' . esc_html( $select_name ) . '" class="operator_dropdown_menu" id="' . $select_id . '" data-width="150px">';
			foreach ( $conditional_rules as $rule_id => $rule ) {

				if ( isset( $default_rule ) and $default_rule == $rule_id ) {
					echo '<option value="' . $rule_id . '" selected="selected">' . $rule . '</option>';
				} else {
					echo '<option value="' . $rule_id . '">' . $rule . '</option>';
				}
			}
			echo '</select>';
		}
	}

	function calculate_rule( $value1, $value2, $operator, $field_type ) {
		global $arfieldhelper;
		if ( $field_type == 'checkbox' || $field_type == 'arf_multiselect' ) {
			$chk           = 0;
			$default_value = maybe_unserialize( $value1 );

			if ( $default_value && is_array( $default_value ) ) {
				foreach ( $default_value as $chk_value ) {
					$value1 = trim( strtolower( $chk_value ) );
					if ( $arfieldhelper->ar_match_rule( $value1, $value2, $operator ) ) {
						$chk++;
					}
				}
			} elseif ( $arfieldhelper->ar_match_rule( $value1, $value2, $operator ) ) {
				$chk++;
			}

			if ( $chk > 0 ) {
				return true;
			} else {
				return false;
			}
		} else {

			return $arfieldhelper->ar_match_rule( $value1, $value2, $operator );
		}

		return false;
	}

	function add_new_rule_multiple_subscription() {

		global $arf_paypal,$is_version_compatible;
		$form_id       = $_POST['form_id'];
		$rule_i        = $_POST['next_rule_id'] ? $_POST['next_rule_id'] : 1;
		$duration_name = $_POST['duration_name'] ? $_POST['duration_name'] : '';

		$responder_list_option = $def_val = $selected_list_id = $selected_list_label = '';
		?>
	
		<input type="hidden"  name="rule_array_multiple_subscription[]" value="<?php echo esc_html( $rule_i ); ?>" />
		<label class="lblsubtitle arf_pp_billing_cycle_label"><b><?php esc_html_e( 'Billing Cycle', 'ARForms-paypal' ); ?></b></label>
		<div class="arf_form_dropdown">
			<div class="sltstandard">
				<div id="arf_paypal_days_main_<?php echo esc_html( $rule_i ); ?>" class="arf_pp_float_left arf_pp_display_none">
			
		<?php
		unset( $def_val );
		$def_val = '1';
		for ( $i = 1;$i <= 90;$i++ ) {
			if ( isset( $values['paypal_days'] ) && $values['paypal_days'] == $i ) {
				   $def_val = $i;
			}

			$responder_list_option .= '<li class="arf_selectbox_option" data-value="' . $i . '" data-label="' . $i . '">' . $i . '</li>';
		}
		?>
			  
		<?php if ( $is_version_compatible ) { ?>
				<input name="arf_paypal_days_<?php echo esc_html( $rule_i ); ?>" id="arf_paypal_days_<?php echo esc_html( $rule_i ); ?>" value="<?php echo esc_html( $def_val ); ?>" type="hidden">
			
				<dl class="arf_selectbox arf_pp_rec_type_dd" data-name="arf_paypal_days_<?php echo esc_html( $rule_i ); ?>" data-id="arf_paypal_days_<?php echo esc_html( $rule_i ); ?>">
				<dt><span><?php echo esc_html( $def_val ); ?></span>
				<input value="<?php echo esc_html( $def_val ); ?>" class="" type="text">
				<svg viewBox="0 0 2000 1000" width="15px" height="15px">
				<g fill="#000">
				<path d="M1024 320q0 -26 -19 -45t-45 -19h-896q-26 0 -45 19t-19 45t19 45l448 448q19 19 45 19t45 -19l448 -448q19 -19 19 -45z"></path>
				</g>
				</svg>
				</dt>
				<dd>
				<ul data-id="arf_paypal_days_<?php echo esc_html( $rule_i ); ?>" class="">
					<?php echo $responder_list_option; ?>
				</ul>
				</dd>
			</dl>
			
		<?php } else { ?>
					<select name="arf_paypal_days_<?php echo esc_html( $rule_i ); ?>" id="arf_paypal_days_<?php echo esc_html( $rule_i ); ?>" class="frm-dropdown arf_pp_rec_type_dd" data-width="80px" data-size="6">
			<?php for ( $i = 1; $i <= 90; $i++ ) { ?>
											<option value="<?php echo esc_html( $i ); ?>" 
																	  <?php
																		if ( isset( $values['paypal_days'] ) && $i == $values['paypal_days'] ) {
																			echo "selected='selected'";
																		}
																		?>
											><?php echo esc_html( $i ); ?></option>
			<?php } ?>
					</select>
		<?php } ?>
			 
				</div>



				<div id="arf_paypal_months_main_<?php echo esc_html( $rule_i ); ?>" class="arf_pp_float_left">
			
		<?php
		unset( $def_val );
		$responder_list_option = '';
		$def_val = '1';
		for ( $i = 1;$i <= 24;$i++ ) {
			if ( isset( $values['paypal_months'] ) && $values['paypal_months'] == $i ) {
				$def_val = $i;
			}

			$responder_list_option .= '<li class="arf_selectbox_option" data-value="' . $i . '" data-label="' . $i . '">' . $i . '</li>';
		}
		?>
		
		<?php if ( $is_version_compatible ) { ?>
				<input name="arf_paypal_months_<?php echo esc_html( $rule_i ); ?>" id="arf_paypal_months_<?php echo esc_html( $rule_i ); ?>" value="<?php echo esc_html( $def_val ); ?>" type="hidden">
			
				<dl class="arf_selectbox arf_pp_rec_type_dd" data-name="arf_paypal_months_<?php echo esc_html( $rule_i ); ?>" data-id="arf_paypal_months_<?php echo esc_html( $rule_i ); ?>">
				<dt><span><?php echo esc_html( $def_val ); ?></span>
				<input value="<?php echo esc_html( $def_val ); ?>" type="text" />
				<svg viewBox="0 0 2000 1000" width="15px" height="15px">
				<g fill="#000">
				<path d="M1024 320q0 -26 -19 -45t-45 -19h-896q-26 0 -45 19t-19 45t19 45l448 448q19 19 45 19t45 -19l448 -448q19 -19 19 -45z"></path>
				</g>
				</svg>
				</dt>
				<dd>
				<ul data-id="arf_paypal_months_<?php echo esc_html( $rule_i ); ?>">
			<?php echo $responder_list_option; ?>
				</ul>
				</dd>
			</dl>
				
		<?php } else { ?>
					<select name="arf_paypal_months_<?php echo esc_html( $rule_i ); ?>" id="arf_paypal_months_<?php echo esc_html( $rule_i ); ?>" class="frm-dropdown arf_pp_rec_type_dd" data-width="80px" data-size="6">
			<?php for ( $i = 1; $i <= 24; $i++ ) { ?>
											<option value="<?php echo esc_html( $i ); ?>" 
																	  <?php
																		if ( isset( $values['paypal_months'] ) && $i == $values['paypal_months'] ) {
																			echo "selected='selected'";
																		}
																		?>
											><?php echo esc_html( $i ); ?></option>
			<?php } ?>
					</select>
		<?php } ?>
				</div>

				<div id="arf_paypal_years_main_<?php echo esc_html( $rule_i ); ?>" class="arf_pp_display_none arf_pp_float_left">
		<?php
		
		unset( $def_val );
		$responder_list_option = '';
		$def_val = '1';
		for ( $i = 1;$i <= 5;$i++ ) {
			if ( isset( $values['paypal_years'] ) && $values['paypal_years'] == $i ) {
				$def_val = $i;
			}

			$responder_list_option .= '<li class="arf_selectbox_option" data-value="' . $i . '" data-label="' . $i . '">' . $i . '</li>';
		}
		?>
		
		<?php if ( $is_version_compatible ) { ?>
				<input name="arf_paypal_years_<?php echo esc_html( $rule_i ); ?>" id="arf_paypal_years_<?php echo esc_html( $rule_i ); ?>" value="<?php echo esc_html( $def_val ); ?>" type="hidden">
			
				<dl class="arf_selectbox arf_pp_rec_type_dd" data-name="arf_paypal_years_<?php echo esc_html( $rule_i ); ?>" data-id="arf_paypal_years_<?php echo esc_html( $rule_i ); ?>">
				<dt><span><?php echo esc_html( $def_val ); ?></span>
				<input value="<?php echo esc_html( $def_val ); ?>" class="" type="text">
				<svg viewBox="0 0 2000 1000" width="15px" height="15px">
				<g fill="#000">
				<path d="M1024 320q0 -26 -19 -45t-45 -19h-896q-26 0 -45 19t-19 45t19 45l448 448q19 19 45 19t45 -19l448 -448q19 -19 19 -45z"></path>
				</g>
				</svg>
				</dt>
				<dd>
				<ul data-id="arf_paypal_years_<?php echo esc_html( $rule_i ); ?>" class="">
			<?php echo $responder_list_option; ?>
				</ul>
				</dd>
			</dl>
		<?php } else { ?>
					<select name="arf_paypal_years_<?php echo esc_html( $rule_i ); ?>" id="arf_paypal_years_<?php echo esc_html( $rule_i ); ?>" class="frm-dropdown arf_pp_rec_type_dd" data-width="80px" data-size="6">
			<?php for ( $i = 1; $i <= 5; $i++ ) { ?>
											<option value="<?php echo esc_html( $i ); ?>" 
																	  <?php
																		if ( isset( $values['paypal_years'] ) && $i == $values['paypal_years'] ) {
																			echo "selected='selected'";
																		}
																		?>
											><?php echo esc_html( $i ); ?></option>
			<?php } ?>
					</select>
		<?php } ?>
				</div>

				<div id="arf_paypal_recurring_type_main_<?php echo esc_html( $rule_i ); ?>" class="arf_pp_ruccring_type_main_wrapper">
			
		<?php
		unset( $selected_list_id );
		unset( $selected_list_label );

		if ( isset($values['paypal_recurring_type']) && $values['paypal_recurring_type'] == 'D' ) {
			$selected_list_id    = 'D';
			$selected_list_label = esc_html__( 'Day( s)', 'ARForms-paypal' );

		} elseif ( ( isset($values['paypal_recurring_type']) && $values['paypal_recurring_type'] == 'M' ) || empty($values['paypal_recurring_type'])) {

			$selected_list_id    = 'M';
			$selected_list_label = esc_html__( 'Month( s)', 'ARForms-paypal' );

		} elseif ( isset($values['paypal_recurring_type']) && $values['paypal_recurring_type'] == Y ) {

			$selected_list_id    = 'Y';
			$selected_list_label = esc_html__( 'Year( s)', 'ARForms-paypal' );
		}
		?>
		
		<?php if ( $is_version_compatible ) { ?>
				<input name="arf_paypal_recurring_type_<?php echo esc_html( $rule_i ); ?>" id="arf_paypal_recurring_type_<?php echo esc_html( $rule_i ); ?>" value="<?php echo esc_html( $selected_list_id ); ?>" type="hidden" onChange="arf_multiple_subscription_paypal_recurring_type_select( <?php echo esc_html( $rule_i ); ?>);">
			
				<dl class="arf_selectbox arf_pp_all_rec_type_dd" data-name="arf_paypal_recurring_type_<?php echo esc_html( $rule_i ); ?>" data-id="arf_paypal_recurring_type_<?php echo esc_html( $selected_list_id ); ?>">
				<dt><span><?php echo $selected_list_label; ?></span>
				<input value="<?php echo esc_html( $selected_list_id ); ?>" class="" type="text">
				<svg viewBox="0 0 2000 1000" width="15px" height="15px">
				<g fill="#000">
				<path d="M1024 320q0 -26 -19 -45t-45 -19h-896q-26 0 -45 19t-19 45t19 45l448 448q19 19 45 19t45 -19l448 -448q19 -19 19 -45z"></path>
				</g>
				</svg>
				</dt>
				<dd>
				<ul data-id="arf_paypal_recurring_type_<?php echo esc_html( $rule_i ); ?>" class="">
				  <li class="arf_selectbox_option" data-value="D" data-label="<?php esc_html_e( 'Day( s)', 'ARForms-paypal' ); ?>"><?php esc_html_e( 'Day( s)', 'ARForms-paypal' ); ?></li>
				  <li class="arf_selectbox_option" data-value="M" data-label="<?php esc_html_e( 'Month( s)', 'ARForms-paypal' ); ?>"><?php esc_html_e( 'Month( s)', 'ARForms-paypal' ); ?></li>
				  <li class="arf_selectbox_option" data-value="Y" data-label="<?php esc_html_e( 'Year( s)', 'ARForms-paypal' ); ?>"><?php esc_html_e( 'Year( s)', 'ARForms-paypal' ); ?></li>
				</ul>
				</dd>
			</dl>

		<?php } else { ?>   

					<select name="arf_paypal_recurring_type_<?php echo esc_html( $rule_i ); ?>" id="arf_paypal_recurring_type_<?php echo esc_html( $rule_i ); ?>" class="frm-dropdown arf_pp_all_rec_type_dd" data-width="100px" data-size="15"  onChange="arf_multiple_subscription_paypal_recurring_type_select( <?php echo esc_html( $rule_i ); ?>);">
						<option value="D" 
			<?php
			if ( isset( $values['paypal_recurring_type'] ) && $values['paypal_recurring_type'] == 'D' ) {
				echo "selected='selected'";
			}
			?>
						><?php esc_html_e( 'Day( s)', 'ARForms-paypal' ); ?></option>
						<option value="M" 
			<?php
			if ( ( isset( $values['paypal_recurring_type'] ) && $values['paypal_recurring_type'] == 'M' ) || ( ! isset( $values['paypal_recurring_type'] ) ) ) {
				echo "selected='selected'";
			}
			?>
						><?php esc_html_e( 'Month( s)', 'ARForms-paypal' ); ?></option>
						<option value="Y" 
			<?php
			if ( isset( $values['paypal_recurring_type'] ) && $values['paypal_recurring_type'] == 'Y' ) {
				echo "selected='selected'";
			}
			?>
						><?php esc_html_e( 'Year( s)', 'ARForms-paypal' ); ?></option>
					</select>
		<?php } ?>
			 
				</div>
			</div>



			<div class="sltstandard arf_pp_ruccring_type_main_wrapper">
		<?php
		unset( $responder_list_option );
		unset( $def_val );
		$def_val = 'infinite';
		$responder_list_option = '';
		for ( $i = 2;$i <= 30;$i++ ) {
			if ( isset($values['paypal_recurring_time']) && $values['paypal_recurring_time'] == $i ) {
				$def_val = $i;
			} elseif ( isset($values['paypal_recurring_time']) && 'infinite' == $values['paypal_recurring_time'] ) {
				$def_val = 'infinite';
			}

			$responder_list_option .= '<li class="arf_selectbox_option" data-value="' . $i . '" data-label="' . $i . '">' . $i . '</li>';
		}
		?>
		
		<?php if ( $is_version_compatible ) { ?>
			<input name="arf_paypal_recurring_time_<?php echo esc_html( $rule_i ); ?>" id="arf_paypal_recurring_time_<?php echo esc_html( $rule_i ); ?>" value="<?php echo esc_html( $def_val ); ?>" type="hidden">

			<dl class="arf_selectbox arf_pp_all_rec_type_dd" data-name="arf_paypal_recurring_time_<?php echo esc_html( $rule_i ); ?>" data-id="arf_paypal_recurring_time_<?php echo esc_html( $rule_i ); ?>">
				<dt>
					<span><?php echo esc_html( $def_val ); ?></span>
					<input value="<?php echo esc_html( $def_val ); ?>" class="" type="text" />
					<svg viewBox="0 0 2000 1000" width="15px" height="15px">
						<g fill="#000">
							<path d="M1024 320q0 -26 -19 -45t-45 -19h-896q-26 0 -45 19t-19 45t19 45l448 448q19 19 45 19t45 -19l448 -448q19 -19 19 -45z"></path>
						</g>
					</svg>
				</dt>
				<dd>
					<ul data-id="arf_paypal_recurring_time_<?php echo esc_html( $rule_i ); ?>">
						<li class="arf_selectbox_option" data-value="infinite" data-label="Infinite">Infinite</li>
			<?php echo $responder_list_option; ?>
					</ul>
				</dd>
			</dl>
		<?php } else { ?>
				<select name="arf_paypal_recurring_time_<?php echo esc_html( $rule_i ); ?>" id="arf_paypal_recurring_time_<?php echo esc_html( $rule_i ); ?>" class="frm-dropdown arf_pp_all_rec_type_dd" data-width="105px" data-size="6">
					<option value="infinite" 
			<?php
			if ( isset( $values['paypal_recurring_time'] ) && $values['paypal_recurring_time'] == 'infinite' ) {
				echo "selected='selected'";
			}
			?>
					><?php esc_html_e( 'Infinite', 'ARForms-paypal' ); ?></option>
			<?php for ( $i = 2; $i <= 30; $i++ ) { ?>
						<option value="<?php echo esc_html( $i ); ?>" 
				<?php
				if ( isset( $values['paypal_recurring_time'] ) && $i == $values['paypal_recurring_time'] ) {
					echo "selected='selected'";
				}
				?>
						><?php echo esc_html( $i ); ?></option>
			<?php } ?>
				</select>
		<?php } ?>
		<?php
		global $is_version_compatible;
		if ( ! $is_version_compatible ) {
			echo '<br>';
		}
		?>
		<label class="lblsubtitle arf_label arf_pp_recurring_time_label">( <?php echo stripslashes( esc_html__( 'Recurring Times', 'ARForms-paypal' ) ); ?>)</label>
			</div>
		&nbsp;&nbsp;&nbsp;
			<label class="lblsubtitle arf_pp_cl_if_label"><?php esc_html_e( 'If', 'ARForms-paypal' ); ?></label>

			<span class="bulk_add_remove_subscription_multiple arf_pp_cl_buttons">
		<span onclick="arf_add_new_law_multiple_subscription();" class="bulk_add">
			<svg viewBox="0 -4 32 32"><g><?php echo ARF_PLUS_ICON; ?></g></svg>
		</span>
		<span onclick="delete_rule_multiple_subscription( this);" class="bulk_remove <?php echo( isset( $rule_i ) && $rule_i == '1' ) ? ' arf_pp_display_none ' : ''; ?>" >
			<svg viewBox="0 -4 32 32"><g><?php echo ARF_MINUS_ICON; ?></g></svg>
		</span>
			</span>


			<div class="arf_pp_cl_field_wrapper">
				<div class="arf_pp_cl_duration_field_wrapper">
					<label class="lblsubtitle duration_feiled arf_pp_float_right"><?php echo esc_html( $duration_name ); ?></label>
				</div>

				<div class="arf_amount_dropdown arf_pp_float_left">

					<div id="arf_cl_rule_multiple_subscription_type">
						<div class="sltstandard arf_pp_display_inline_with_float">
		<?php echo $arf_paypal->arf_cl_rule_menu( 'arf_cl_op_multiple_subscription_duration_type_' . $rule_i, 'arf_cl_op_multiple_subscription_type_' . $rule_i, 'is' ); ?>
						</div>
						
						<input type="text" name="cl_rule_value_multiple_subscription_duration_type_<?php echo esc_html( $rule_i ); ?>" id="cl_rule_value_multiple_subscription_duration_type_<?php echo esc_html( $rule_i ); ?>" class="txtmodal1 arf_pp_cl_rule_value_input arf_pp_float_left" value="" />
						&nbsp;
					</div>
				</div>
			</div>
		</div>
		</br>
		<?php
		die();
	}

	function arf_get_multiple_payment_type( $values, $form_data ) {

		global $arfieldhelper;
		$options             = maybe_unserialize( $form_data->options );
		$paypal_field_amount = $options['amount'];

		if ( $options['arf_payment_type'] == 'arf_payment_type_single' ) {
			return true;
		}

		$ReturnPaymentType = array();
		if ( $options['arf_payment_type'] == 'arf_payment_type_multiple' ) {

			if ( isset( $options['arf_multiple_product_service_type'] ) && $options['arf_multiple_product_service_type'] == '1' ) {

				$mapped_field_values_product_service        = '';
				$mapped_field_values_product_service_amount = '';
				if ( count( $values ) > 0 ) {
					foreach ( $values as $value ) {
						if ( $options['arf_cl_field_multiple_product_service_type'] == $value->field_id ) {
							$mapped_field_values_product_service = $value->entry_value;
						}
						if ( $options['arf_multiple_product_service_amount'] == $value->field_id ) {
							$mapped_field_values_product_service_amount = $value->entry_value;
						}
					}
				}

				$field_type = $arfieldhelper->get_field_type( $options['arf_cl_field_multiple_product_service_type'] );

				$value1 = isset( $mapped_field_values_product_service ) ? $mapped_field_values_product_service : '';

				$value1 = trim( strtolower( $value1 ) );

				$value2 = trim( strtolower( $options['cl_rule_value_multiple_product_service_type'] ) );

				$operator = $options['arf_cl_op_multiple_product_service_type'];

				if ( $this->calculate_rule( $value1, $value2, $operator, $field_type ) ) {
					$ReturnPaymentType = array(
						'type'   => 'product_service',
						'amount' => $mapped_field_values_product_service_amount,
					);
				}
			}

			if (isset($options['arf_multiple_donations_service_type']) && $options['arf_multiple_donations_service_type'] == '1') {

                $mapped_field_values_donations_service = '';
                $mapped_field_values_donations_service_amount = '';
                if (count($values) > 0) {
                    foreach ($values as $value) {
                        if ($options['arf_cl_field_multiple_donations_service_type'] == $value->field_id) {
                            $mapped_field_values_donations_service = $value->entry_value;
                        }
                        if ($options['arf_multiple_donations_service_amount'] == $value->field_id) {
                            $mapped_field_values_donations_service_amount = $value->entry_value;
                        }
                    }
                }

                $field_type = $arfieldhelper->get_field_type($options['arf_cl_field_multiple_donations_service_type']);

                $value1 = isset($mapped_field_values_donations_service) ? $mapped_field_values_donations_service : '';

                $value1 = trim(strtolower($value1));

                $value2 = trim(strtolower($options['cl_rule_value_multiple_donations_service_type']));

                $operator = $options['arf_cl_op_multiple_donations_service_type'];


                if ($this->calculate_rule($value1, $value2, $operator, $field_type)) {
                    $ReturnPaymentType = array(
                        'type' => 'donation',
                        'amount' => $mapped_field_values_donations_service_amount,
                    );
                }
            }

			if ( isset( $options['arf_multiple_subscription_type'] ) && $options['arf_multiple_subscription_type'] == '1' ) {

				$subscription_amount = $options['arf_multiple_subscription_amount'];

				$mapped_field_values_subscription        = '';
				$mapped_field_values_subscription_amount = '';
				if ( count( $values ) > 0 ) {
					foreach ( $values as $value ) {
						if ( $options['arf_cl_field_multiple_subscription_type'] == $value->field_id ) {
							$mapped_field_values_subscription = $value->entry_value;
						}

						if ( $subscription_amount == $value->field_id ) {
							$mapped_field_values_subscription_amount = $value->entry_value;
						}
					}
				}

				$field_type = $arfieldhelper->get_field_type( $options['arf_cl_field_multiple_subscription_type'] );

				$value1 = isset( $mapped_field_values_subscription ) ? $mapped_field_values_subscription : '';

				$value1 = trim( strtolower( $value1 ) );

				$value2 = trim( strtolower( $options['cl_rule_value_multiple_subscription_type'] ) );

				$operator = $options['arf_cl_op_multiple_subscription_type'];

				if ( $this->calculate_rule( $value1, $value2, $operator, $field_type ) ) {

					if ( count( $options['multiple_subscription_conditional_logic']['rules'] ) > 0 ) {

						foreach ( $options['multiple_subscription_conditional_logic']['rules'] as $key => $rules_value ) {

							$conditional_logic_field_type = $arfieldhelper->get_field_type( $subscription_amount );

							$conditional_logic_value1 = isset( $mapped_field_values_subscription_amount ) ? $mapped_field_values_subscription_amount : '';

							$conditional_logic_value1 = trim( strtolower( $conditional_logic_value1 ) );

							$conditional_logic_value2 = trim( strtolower( $rules_value['value'] ) );

							$conditional_logic_operator = $rules_value['operator'];

							if ( count( $options['multiple_subscription_conditional_logic']['rules'] ) == 1 && $conditional_logic_value2 == '' ) {
								$ReturnPaymentType = array(
									'type'          => 'subscription',
									'amount'        => $mapped_field_values_subscription_amount,
									'billing_cycle' => $rules_value,
								);
							} elseif ( $this->calculate_rule( $conditional_logic_value1, $conditional_logic_value2, $conditional_logic_operator, $conditional_logic_field_type ) ) {
								$ReturnPaymentType = array(
									'type'          => 'subscription',
									'amount'        => $mapped_field_values_subscription_amount,
									'billing_cycle' => $rules_value,
								);
							}
						}
					}
				}
			}
		}

		return $ReturnPaymentType;
	}

	function arf_paypal_admin_email_notification_data( $notification_data, $entry_id, $form_id ){
		global $arfform;

		$is_paypal_form = $arfform->arf_select_db_data( true, '', $this->db_paypal_forms, 'COUNT(id)', 'WHERE form_id = %d', array( $form_id ), '', '', '', true );

		if( $is_paypal_form > 0 ){
			update_option( 'arf_paypal_admin_email_notification_' . $entry_id . '_' . $form_id, json_encode( $notification_data ) );
		}
	}

	function arf_paypal_check_response_v3( $response = array(), $paypal = false ){
		global $is_submit, $arnotifymodel, $wpdb, $MdlDb, $arfform, $arfrecordmeta;

		if( false == $paypal ){
			$form_id = isset( $response['form_id'] ) ? $response['form_id'] : '';

			if( '' == $form_id ){
				$is_submit = true;
			} else {
				$is_paypal_form = $arfform->arf_select_db_data( true, '', $this->db_paypal_forms, 'COUNT(id)', 'WHERE form_id = %d', array( $form_id ), '', '', '', true );
				if( $is_paypal_form > 0 ){

					$paypal_form_data = $arfform->arf_select_db_data( true, '', $this->db_paypal_forms, '*', 'WHERE form_id = %d', array( $form_id ) );

					$entry_id = $response['entry_id'];

					$options = maybe_unserialize($paypal_form_data[0]->options);

					if ( $options['paypal_condition'] == 1 ) {
						$entry_ids = array( $entry_id );
						$values    = $arfrecordmeta->getAll( 'it.field_id != 0 and it.entry_id in ( ' . implode( ',', $entry_ids ) . ')', ' ORDER BY fi.id' );
						
						$mapped_conditional_field = array();
						if ( $options['paypal_condition'] && 1 == $options['paypal_condition'] ) {
							$rules = $options['conditional_logic']['rules'] ? $options['conditional_logic']['rules'] : array();
							if ( $rules ) {
								foreach ( $rules as $rule ) {
									if ( '' != $rule['field_id'] ) {
										$mapped_conditional_field[] = $rule['field_id'];
									}
								}
							}
						}

						$mapped_field_values = array();
						if ( count( $values ) > 0 ) {
							foreach ( $values as $value ) {
								if ( $mapped_conditional_field ) {
									foreach ( $mapped_conditional_field as $rule_field ) {
										if ( $rule_field == $value->field_id ) {
											$mapped_field_values[ $value->field_id ] = $value->entry_value;
										}
									}
								}
							}
						}

						$mapped_conditional_field = array();
						if ( $options['paypal_condition'] && $options['paypal_condition'] == 1 ) {
							$rules = $options['conditional_logic']['rules'] ? $options['conditional_logic']['rules'] : array();

							if ( $rules ) {
								$matched     = 0;
								$total_rules = 0;

								foreach ( $rules as $rule ) {
									if ( '' != $rule['field_id'] ) {
										$total_rules++;

										$value1 = isset( $mapped_field_values[ $rule['field_id'] ] ) ? $mapped_field_values[ $rule['field_id'] ] : '';

										$value1 = trim( strtolower( $value1 ) );

										$value2 = trim( strtolower( $rule['value'] ) );

										$operator = $rule['operator'];

										if ( $this->calculate_rule( $value1, $value2, $operator, $rule['field_type'] ) ) {
											$matched++;
										}
									}
								}

								if ( ( 'all' == $options['conditional_logic']['if_cond'] && $total_rules == $matched ) || ( 'any' == $options['conditional_logic']['if_cond'] && $matched > 0 ) ) {
									update_option( 'arf_paypal_user_email_notification_' . $entry_id .'_'.$form_id, json_encode( $response ) );
									$is_submit = false;			
								} else {
									$is_submit = true;
								}
							}
						}
					} else {
						update_option( 'arf_paypal_user_email_notification_' . $entry_id .'_'.$form_id, json_encode( $response ) );
						$is_submit = false;	
					}

				} else {
					$is_submit = true;
				}
			}
		}
	}

	function arf_paypal_check_response( $response = array(), $paypal = false ) {

		global $is_submit,$arnotifymodel,$arf_paypal,$wpdb,$MdlDb, $maincontroller;

		if ( $paypal == false ) {
			$form_id = isset( $response['form_id'] ) ? $response['form_id'] : '';
			if ( $form_id === '' ) {
				$is_submit = true;
			} else {
				global $wpdb;
				$table          = $arf_paypal->db_paypal_forms;
				$is_paypal_form = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( *) FROM `{$table}` WHERE form_id =%d ", $form_id ) );
				if ( $is_paypal_form > 0 ) {
					$maincontroller->arf_start_session( true );
					$_SESSION['arf_to_mail']        = isset( $response['to'] ) ? $response['to'] : '';
					$_SESSION['arf_mail_subject']   = isset( $response['subject'] ) ? $response['subject'] : '';
					$_SESSION['arf_message']        = isset( $response['message'] ) ? $response['message'] : '';
					$_SESSION['arf_reply_to']       = isset( $response['reply_to'] ) ? $response['reply_to'] : '';
					$_SESSION['arf_reply_to_name']  = isset( $response['reply_to_name'] ) ? $response['reply_to_name'] : '';
					$_SESSION['arf_plain_text']     = isset( $response['plain_text'] ) ? $response['plain_text'] : '';
					$_SESSION['arf_attachments']    = isset( $response['attachments'] ) ? $response['attachments'] : array();
					$_SESSION['arf_return_value']   = isset( $response['return_value'] ) ? $response['return_value'] : '';
					$_SESSION['arf_use_only_smtp']  = isset( $response['use_only_smtp'] ) ? $response['use_only_smtp'] : '';
					$_SESSION['arf_reply_to_email'] = isset( $response['nreply_to'] ) ? $response['nreply_to'] : '';
					$_SESSION['form_id']            = isset( $response['form_id'] ) ? $response['form_id'] : '';
					$is_submit                      = false;
				} else {
					$is_submit = true;
				}
			}
		} else {
			$is_submit = true;
			if ( isset( $_SESSION['form_id'] ) && $_SESSION['form_id'] != '' ) {
				$form_id      = $_SESSION['form_id'];
				$options      = $wpdb->get_row( $wpdb->prepare( 'SELECT options FROM `' . $MdlDb->forms . '` WHERE ID = %d LIMIT 1', $form_id ) );
				$form_options = maybe_unserialize( $options->options );
				if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] == 1 ) {
					$arf_to_mail       = $_SESSION['arf_to_mail'];
					$arf_mail_subject  = $_SESSION['arf_mail_subject'];
					$arf_message       = $_SESSION['arf_message'];
					$arf_reply_to      = $_SESSION['arf_reply_to'];
					$arf_reply_to_name = $_SESSION['arf_reply_to_name'];
					$arf_plain_text    = $_SESSION['arf_plain_text'];
					$arf_attachments   = $_SESSION['arf_attachments'];
					$arf_return_value  = $_SESSION['use_only_smtp'];
					$arf_use_only_smtp = $_SESSION['arf_use_only_smtp'];
					$arf_nreply_to     = $_SESSION['arf_reply_to_email'];
					unset( $_SESSION['arf_to_mail'] );
					unset( $_SESSION['arf_mail_subject'] );
					unset( $_SESSION['arf_message'] );
					unset( $_SESSION['arf_reply_to'] );
					unset( $_SESSION['arf_reply_to_name'] );
					unset( $_SESSION['arf_plain_text'] );
					unset( $_SESSION['arf_attachments'] );
					unset( $_SESSION['use_only_smtp'] );
					unset( $_SESSION['arf_use_only_smtp'] );
					unset( $_SESSION['form_id'] );
					unset( $_SESSION['arf_from_autoresponder'] );
					unset( $_SESSION['arf_reply_to_email'] );
					$arnotifymodel->send_notification_email_user( $arf_to_mail, $arf_mail_subject, $arf_message, $arf_reply_to, $arf_reply_to_name, $arf_plain_text, $arf_attachments, $arf_return_value, $arf_use_only_smtp, true, false, $arf_nreply_to );
				}

				if ( isset( $form_options['chk_admin_notification'] ) && $form_options['chk_admin_notification'] == 1 ) {
					$admin_emails = isset( $_SESSION['arf_admin_emails'] ) ? $_SESSION['arf_admin_emails'] : array();
					if ( ! empty( $admin_emails ) ) {
						$arf_admin_subject        = $_SESSION['arf_admin_subject'];
						$arf_admin_mail_body      = $_SESSION['arf_admin_mail_body'];
						$arf_admin_reply_to       = $_SESSION['arf_admin_reply_to'];
						$arf_admin_reply_to_name  = $_SESSION['arf_admin_reply_to_name'];
						$arf_admin_plain_text     = $_SESSION['arf_admin_plain_text'];
						$arf_admin_attachments    = $_SESSION['arf_admin_attachments'];
						$arf_admin_reply_to_email = $_SESSION['arf_admin_reply_to_email'];
						unset( $_SESSION['arf_admin_emails'] );
						unset( $_SESSION['arf_admin_subject'] );
						unset( $_SESSION['arf_admin_mail_body'] );
						unset( $_SESSION['arf_admin_reply_to'] );
						unset( $_SESSION['arf_admin_reply_to_name'] );
						unset( $_SESSION['arf_admin_plain_text'] );
						unset( $_SESSION['arf_admin_attachments'] );
						unset( $_SESSION['arf_admin_reply_to_email'] );
						foreach ( $admin_emails as $email ) {
							$arnotifymodel->send_notification_email_user( $email, $arf_admin_subject, $arf_admin_mail_body, $arf_admin_reply_to, $arf_admin_reply_to_name, $arf_admin_plain_text, $arf_admin_attachments, false, false, true, false, $arf_admin_reply_to_email );
						}
					}
				}
			}
		}
	}

	function is_arforms_version() {
		if ( version_compare( self::get_arforms_version(), '3.0', '>=' ) ) {
			return true;
		} else {
			return false;
		}
	}

	function arf_display_message_content( $content, $form_id ) {
		global $arformcontroller,$wpdb,$MdlDb;

		$return = array();
		if ( $form_id != '' && isset( $_REQUEST['arf_conf'] ) && $_REQUEST['arf_conf'] == $form_id ) {
			$table     = $MdlDb->forms;
			$form_data = $wpdb->get_row( $wpdb->prepare( 'SELECT `options` FROM ' . $table . " WHERE `id` = '%d'", $form_id ) );

			$options = maybe_unserialize( $form_data->options );

			$success_msg = $options['success_msg'];

			$msg  = "<div class='arf_form ar_main_div_{$form_id}' id='arffrm_{$form_id}_container'><div id='arf_message_success'><div class='msg-detail'><div class='msg-description-success arf_pp_text_align_center'>{$success_msg}</div></div></div>";
			$msg = apply_filters('arf_display_digital_product_link',$msg, $options, $form_id);
			$msg .= "</div>";

			$return['conf_method'] = 'message';
			$return['message']     = $msg;

			if ( empty( $form_data ) ) {
				return $content;
			}
			if ( empty( $return ) ) {
				return $content;
			}
			return json_encode( $return );
		}
		return $content;
	}

	function arf_paypal_check_user_cap( $capability = '', $ajax_call = false ) {

		if ( true == $ajax_call ) {
			if ( ! current_user_can( $capability ) ) {
				return json_encode(
					array(
						esc_html__( 'Sorry, you do not have enough permission to perform this action', 'ARForms-paypal' ),
					)
				);
			}
		}

		$arf_paypal_nonce = isset( $_POST['_wpnonce_arfpaypal'] ) ? $_POST['_wpnonce_arfpaypal'] : '';
		if ( '' == $arf_paypal_nonce ) {
			$arf_paypal_nonce = isset( $_REQUEST['_wpnonce_arfpaypal'] ) ? $_REQUEST['_wpnonce_arfpaypal'] : '';
		}

		$arfpaypal_nonce_flag = wp_verify_nonce( $arf_paypal_nonce, 'arforms_paypal_nonce' );

		if ( ! $arfpaypal_nonce_flag ) {
			return json_encode(
				array(
					esc_html__( 'Sorry, your request could not be processed due to security reason', 'ARForms-paypal' ),
				)
			);
		}

		return 'success';

	}

}

global $arf_paypal_api_url, $arf_paypal_plugin_slug;

$arf_paypal_api_url     = $arf_paypal->arf_paypal_getapiurl();
$arf_paypal_plugin_slug = basename( dirname( __FILE__ ) );

add_filter( 'pre_set_site_transient_update_plugins', 'arf_paypal_check_for_plugin_update' );

function arf_paypal_check_for_plugin_update( $checked_data ) {
	global $arf_paypal_api_url, $arf_paypal_plugin_slug, $wp_version, $arf_paypal, $arf_paypal_version,$arf_version;

	if ( empty( $checked_data->checked ) ) {
		return $checked_data;
	}

	$args = array(
		'slug'            => $arf_paypal_plugin_slug,
		'version'         => $arf_paypal_version,
		'arf_version' => $arf_version,
		'other_variables' => $arf_paypal->arf_paypal_get_remote_post_params(),
	);

	$request_string = array(
		'body'       => array(
			'action'  => 'basic_check',
			'request' => serialize( $args ),
			'api-key' => md5( home_url() ),
		),
		'user-agent' => 'ARFPAYPAL-WordPress/' . $wp_version . '; ' . home_url(),
	);

	$raw_response = wp_remote_post( $arf_paypal_api_url, $request_string );

	if ( ! is_wp_error( $raw_response ) && ( $raw_response['response']['code'] == 200 ) ) {

		$response = ( isset( $raw_response['body'] ) && ! empty( $raw_response['body'] ) ) ? maybe_unserialize( $raw_response['body'] ) : '';
	}

	if ( isset( $response ) && ! empty( $response ) && isset( $response->token ) && $response->token != '' ) {
		update_option( 'arfpaypal_update_token', $response->token );
	}

	if ( isset( $response ) && is_object( $response ) && is_object( $checked_data ) && ! empty( $response ) ) {
		$checked_data->response[ $arf_paypal_plugin_slug . '/' . $arf_paypal_plugin_slug . '.php' ] = $response;
	}

	return $checked_data;
}

add_filter( 'plugins_api', 'arf_paypal_plugin_api_call', 11, 3 );

function arf_paypal_plugin_api_call( $def, $action, $args ) {
	global $arf_paypal_plugin_slug, $arf_paypal_api_url, $wp_version,$arf_version;

	if ( ! isset( $args->slug ) || ( $args->slug != $arf_paypal_plugin_slug ) ) {
		return false;
	}

	$plugin_info     = get_site_transient( 'update_plugins' );
	$current_version = $plugin_info->checked[ $arf_paypal_plugin_slug . '/' . $arf_paypal_plugin_slug . '.php' ];
	$args->version   = $current_version;

	$request_string = array(
		'body'       => array(
			'action'       => $action,
			'update_token' => get_site_option( 'arfpaypal_update_token' ),
			'request'      => serialize( $args ),
			'arf_version' => $arf_version,
			'api-key'      => md5( home_url() ),
		),
		'user-agent' => 'ARFPAYPAL-WordPress/' . $wp_version . '; ' . home_url(),
	);

	$request = wp_remote_post( $arf_paypal_api_url, $request_string );

	if ( is_wp_error( $request ) ) {
		$res = new WP_Error( 'plugins_api_failed', 'An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>', $request->get_error_message() );
	} else {
		$res = maybe_unserialize( $request['body'] );

		if ( $res === false ) {
			$res = new WP_Error( 'plugins_api_failed', 'An unknown error occurred', $request['body'] );
		}
	}

	return $res;
}

?>