HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/shootinschool/wp-content/plugins/shootin-school-plugin/manage_emails.php
<?php
if (!class_exists('WP_List_Table')) {
    require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
function render_siab_emails(){
    // wp_send_distribution_email();
    // exit();
    class Email_List_Table extends WP_List_Table
    {
        /**
         * Prepare the items for the table to process
         *
         * @return Void
         */

        public function prepare_items()
        {
            $columns = $this->get_columns();
            $hidden = $this->get_hidden_columns();
            $sortable = $this->get_sortable_columns();

            $data = $this->table_data();
            usort($data, array(&$this, 'sort_data'));

            $perPage = 10;
            $currentPage = $this->get_pagenum();
            $totalItems = count($data);

            $this->set_pagination_args(array(
                'total_items' => $totalItems,
                'per_page'    => $perPage
            ));

            $data = array_slice($data, (($currentPage - 1) * $perPage), $perPage);

            $this->_column_headers = array($columns, $hidden, $sortable);
            $this->items = $data;
        }

        /**
         * Override the parent columns method. Defines the columns to use in your listing table
         *
         * @return Array
         */
        public function get_columns()
        {
            $columns = array(
                'mailto' => "Email To",
                'title'    => 'Email Title',
                'actions' => 'Actions',

            );

            return $columns;
        }

        /**
         * Define which columns are hidden
         *
         * @return Array
         */
        public function get_hidden_columns()
        {
            return array();
        }

        /**
         * Define the sortable columns
         *
         * @return Array
         */
        public function get_sortable_columns()
        {
            return array('mailto' => array('mailto', false));
        }

        /**
         * Get the table data
         *
         * @return Array
         */
        private function table_data()
        {
            global $wpdb;
            $query = "SELECT * FROM ".DB_EMAILS." ORDER BY id ASC";
            $data = $wpdb->get_results($query, ARRAY_A);
            return $data;
        }

        /**
         * Define what data to show on each column of the table
         *
         * @param  Array $item        Data
         * @param  String $column_name - Current column name
         *
         * @return Mixed
         */
        public function column_default($item, $column_name)
        {
            switch ($column_name) {
                case 'mailto':
                case 'title':
                    return $item[$column_name];
                default:
                    return print_r($item, true);
            }
        }

        function column_actions($item)
        {
            $actions = array(
                'edit' => sprintf('<a href="?page=siab-email-edit&id=' . $item['id'] . '">Edit</a>'),
            );

            return sprintf(
                // '%1$s <span style="color:silver">(Edit:%2$s)</span>%3$s',
                /*$1%s*/
                // $item['title'],
                /*$2%s*/
                // $item['id'],
                /*$3%s*/
                $this->row_actions($actions)
            );
        }

        /**
         * Allows you to sort the data by the variables set in the $_GET
         *
         * @return Mixed
         */
        private function sort_data($a, $b)
        {
            // Set defaults
            $orderby = 'id';
            $order = 'asc';

            // If orderby is set, use this as the sort column
            if (!empty($_GET['orderby'])) {
                $orderby = $_GET['orderby'];
            }

            // If order is set use this as the order
            if (!empty($_GET['order'])) {
                $order = $_GET['order'];
            }

            $result = strcmp($a[$orderby], $b[$orderby]);

            if ($order === 'asc') {
                return $result;
            }

            return -$result;
        }
    }

    $importedListTable = new Email_List_Table();
    $importedListTable->prepare_items();
    ?>

    <div class="wrap">
        <div class="alert alert-info" role="alert" style="border: 1px solid green;border-radius: 5px;">
            <h3> Email And SMS Management </h3>
            <!-- <a class="add-new-h2" href="admin.php?page=add_package_group">Add New Package Group</a>
		<a class="add-new-h2" href="admin.php?page=add_session">Add Session </a> -->
        </div>
        <?php $importedListTable->display(); ?>
    </div>

    <?php
}
function importdatas1(){

    // require_once(YITH_WCSTRIPE_DIR . 'includes/class-yith-stripe-api.php');
    // require_once(YITH_WCSTRIPE_DIR . 'includes/class-yith-stripe-gateway.php');
    // require_once(YITH_WCSTRIPE_DIR . 'includes/class-yith-stripe-gateway-advanced.php');

    // $fetch_yith_gateway = new YITH_WCStripe_Gateway_Advanced();
    // $fetch_yith_gateway->init_stripe_sdk();
    // $api = new YITH_Stripe_API('sk_live_p483REumPLfWcOhWp643HCkd');
	// require_once(plugin_dir_path(__FILE__).'/stripe-sdk/vendor/autoload.php');

    // $charge = $stripe->charges->create([
    //     'amount' => 2000,
    //     'currency' => 'usd',
    //     'source' => 'tok_visa', // obtained with Stripe.js
    //     'description' => 'My First Test Charge (created for API docs)'
    //   ], [
    //     'idempotency_key' => 'IFdHHPhPsHmBaWAa'
    // ]);
    // $res = $api->get_customer($customer);

    // $customer['cards'] =  $res['sources']->data;
    // $stripe = new \Stripe\StripeClient(
    //     'sk_test_Qf9JajukBCaNmVubuYsDix5u'
    //   );

    //   $stripe->subscriptions->create([
    //     'customer' => 'cus_HBUES8P2tp4MR7',
    //     'items' => [
    //       ['price' => 'price_0ISj6o9GOnIA4dMQjfPj6BPm'],
    //     ],
    //   ]);


     

      
      echo "<pre>";

      
    require_once(YITH_WCSTRIPE_DIR . 'includes/class-yith-stripe-api.php');
    require_once(YITH_WCSTRIPE_DIR . 'includes/class-yith-stripe-gateway.php');
    require_once(YITH_WCSTRIPE_DIR . 'includes/class-yith-stripe-gateway-advanced.php');

    $fetch_yith_gateway = new YITH_WCStripe_Gateway_Advanced();
    $fetch_yith_gateway->init_stripe_sdk();

    //$fetch_if_test_or_live = $fetch_yith_gateway->env;


    $savedCard_id = "";
    $stripe_error = "";

// error_log($stripe_error);

    // $user_id = $result['customer_id'];
    $customer = YITH_WCStripe()->get_customer()->get_usermeta_info(359);
    //   $stripe_customer = $stripe->customers->retrieve(
    //     'cus_HBUES8P2tp4MR7',
    //     []
    //   );

      print_r($customer['id']);

    //   if($stripe_customer->invoice_settings->default_payment_method != ''){
    //     $source = $stripe_customer->invoice_settings->default_payment_method;
    //   }else{
    //     $source = $stripe_customer->default_source;
    //   }


    //   if($source != ''){
    //       print_r($stripe->paymentIntents->create([
    //         'amount' => 20000,
    //         'currency' => 'usd',

    //         'customer' => 'cus_HBUES8P2tp4MR7',
    //         'payment_method_types' => ['card'],
    //         ]));
    //   }

  

    // print_r($stripe->paymentMethods->all([
    //     'customer' => 'cus_HBUES8P2tp4MR7',
    //     'type' => 'card',
    // ]));
    // $res = $api->get_customer($customer);
    // $customer = YITH_WCStripe()->get_customer()->get_usermeta_info(359);
    // $res = $api->get_customer($customer);

    // $customer['cards'] =  $res['sources']->data;

    // $customer['cards'] =  $res['sources']->data;

    // print_r($res);
    //   print_r($stripe->paymentIntents->confirm(
    //     'pi_0ISxcf9GOnIA4dMQ8x8kkHCU',
    //     ['payment_method' => 'pm_0Gd7GO9GOnIA4dMQGFg1P0yc']
    //   ));
      echo "</pre>";

    exit();



}

function importdatas(){
    ini_set('max_execution_time', 300);
    global $wpdb;
    global $woocommerce;
    
    $tablename = "wp_5d4e9f5293ff5_siab_customer_purchase_credits";
    
    
    $result = 	$wpdb->get_results("select * from wp_excel_data",ARRAY_A);
    
    $headers[] = 'Content-Type: text/html; charset=UTF-8';
    $headers[] = 'From: ShootInSchool <noreply@shootinschool.com>';
    
    // // $count =0;
    $emails = array();
    $passwords = array();
    $count = 0;
    $flag =0;
    foreach ($result as $key => $value) {
    // 	# code...
    	$parts = explode("@", $value['parent_email']);
    	$username = $parts[0];
    	$email = $value['parent_email'];
    	$password = wp_generate_password(8, false);
    
    
        if( email_exists($email)) {
            $user_id = email_exists($email);
            // var_dump($user_id);
            // exit();
            // array_push($emails,$email);
            // array_push($passwords,$user_id);
            $wpdb->update( DB_USERS, array('display_name'=> $value['parent_name']), array('ID' => $user_id) );
        
        // if($value['individual_sessions'] != 0 ){
        //     // var_dump($email);
           
        // }
    
          
        // if($value['personal_sessions'] != 0 ){
        //     // var_dump($email);
           
        // }
    
    
    	// if(count($purch)== 0){
            // var_dump($email);
            
          if($flag == 1){
            if($value['individual_sessions'] != 0){
                $credits = $value['individual_sessions'];
                $purch = 	$wpdb->get_results("select * from ".DB_WC_GF_CUSTOMER_PURCHASES." where credits=".$credits." and customer_id=".$user_id." and child_type='individual'" ,ARRAY_A);
                
                // var_dump("select * from ".DB_WC_GF_CUSTOMER_PURCHASES." where credits=".$credits." and customer_id=".$user_id." and child_type='individual'");
                
                // exit();
                // if(count($purch) == 0){
                    $order = wc_create_order();
    
                    // The add_product() function below is located in /plugins/woocommerce/includes/abstracts/abstract_wc_order.php
                    $order->add_product( get_product('1794'), 1); // This is an existing SIMPLE product
                    //
                    $order->calculate_totals();
                    $order->update_status( 'processing' );
                    $hidden_name = 'individual';
                    
                    if(trim($value['player_name']) != ""){
                    $player = explode(" ",$value['player_name']);
                    $args = array(
                        "user_id" => $user_id,
                        "first_name" => $player[0],
                        "grade" => '',
                        "jersey_size" => '',
                        "child_type" => $hidden_name
                    );
                    if(count($player)>1){
                        $args['last_name'] = $player[1];
                    }else{
                        $args['last_name'] = '';
                    }
    
    
                    $children = $wpdb->get_results("select * from ".DB_CHILD_DETAILS." where first_name='".$player[0]."' and user_id=".$user_id ,ARRAY_A);
            
    
                    // if(count($children)== 0){
                        $sqlInsert = $wpdb->insert(DB_CHILD_DETAILS, $args);
                    // }
            
                
                    }
            
                    $credits = $value['individual_sessions'];
                    $data = [
                        'customer_id' => $user_id,
                        'gf_form_id' =>15,
                        'order_id' => $order->ID,
                        'package_hidden_name' => $hidden_name,
                        'credits' => $credits
                    ];
                
                    $wpdb->insert($tablename,$data);
                // }
           
            
            }
            if($value['group_sessions'] != 0 ){
                $credits = $value['group_sessions'];
                $purch = 	$wpdb->get_results("select * from ".DB_WC_GF_CUSTOMER_PURCHASES." where credits=".$credits." and customer_id=".$user_id." and child_type='group'" ,ARRAY_A);
                // var_dump("select * from ".DB_WC_GF_CUSTOMER_PURCHASES." where credits=".$credits." and customer_id=".$user_id." and child_type='individual'");
                
                // exit();
                // if(count($purch) == 0){
                    $order = wc_create_order();
    
                    // The add_product() function below is located in /plugins/woocommerce/includes/abstracts/abstract_wc_order.php
                    $order->add_product( get_product('5'), 1); // This is an existing SIMPLE product
                    //
                    $order->calculate_totals();
                    $order->update_status( 'processing' );
                    $hidden_name = 'group';
            
                    if(trim($value['player_name']) != ""){
                        $player = explode(" ",$value['player_name']);
                        $args = array(
                            "user_id" => $user_id,
                            "first_name" => $player[0],
                            "grade" => '',
                            "jersey_size" => '',
                            "child_type" => $hidden_name
                        );
                        if(count($player)>1){
                            $args['last_name'] = $player[1];
                        }else{
                            $args['last_name'] = '';
                        }
                
                        $children = $wpdb->get_results("select * from ".DB_CHILD_DETAILS." where first_name='".$player[0]."' and user_id=".$user_id ,ARRAY_A);
            
    
                        // if(count($children)== 0){
                            $sqlInsert = $wpdb->insert(DB_CHILD_DETAILS, $args);
                        // }
                    }
                    $credits = $value['group_sessions'];
                    $data = [
                        'customer_id' => $user_id,
                        'gf_form_id' =>13,
                        'order_id' => $order->ID,
                        'package_hidden_name' => $hidden_name,
                        'credits' => $credits
                    ];
                    $wpdb->insert($tablename,$data);
            }
          }
           
            $count++;
            if($email == 'kimm79@icloud.com'){
                $flag =1;
            }
    	}else{
         
            $username = $value['parent_email'];
    		$user_id = wp_create_user( $username, $password, $email );
    		$user = new WP_User($user_id);
    		$user->set_role('customer');
            array_push($emails,$email);
    		array_push($passwords,$password);

            if($value['individual_sessions'] != 0){
                $credits = $value['individual_sessions'];
                $purch = 	$wpdb->get_results("select * from ".DB_WC_GF_CUSTOMER_PURCHASES." where credits=".$credits." and customer_id=".$user_id." and child_type='individual'" ,ARRAY_A);
                
                // var_dump("select * from ".DB_WC_GF_CUSTOMER_PURCHASES." where credits=".$credits." and customer_id=".$user_id." and child_type='individual'");
                
                // exit();
                // if(count($purch) == 0){
                    $order = wc_create_order();
    
                    // The add_product() function below is located in /plugins/woocommerce/includes/abstracts/abstract_wc_order.php
                    $order->add_product( get_product('1794'), 1); // This is an existing SIMPLE product
                    //
                    $order->calculate_totals();
                    $order->update_status( 'processing' );
                    $hidden_name = 'individual';
                    
                    if(trim($value['player_name']) != ""){
                    $player = explode(" ",$value['player_name']);
                    $args = array(
                        "user_id" => $user_id,
                        "first_name" => $player[0],
                        "grade" => '',
                        "jersey_size" => '',
                        "child_type" => $hidden_name
                    );
                    if(count($player)>1){
                        $args['last_name'] = $player[1];
                    }else{
                        $args['last_name'] = '';
                    }
    
    
                    $children = $wpdb->get_results("select * from ".DB_CHILD_DETAILS." where first_name='".$player[0]."' and user_id=".$user_id ,ARRAY_A);
            
    
                    // if(count($children)== 0){
                        $sqlInsert = $wpdb->insert(DB_CHILD_DETAILS, $args);
                    // }
            
                
                    }
            
                    $credits = $value['individual_sessions'];
                    $data = [
                        'customer_id' => $user_id,
                        'gf_form_id' =>15,
                        'order_id' => $order->ID,
                        'package_hidden_name' => $hidden_name,
                        'credits' => $credits
                    ];
                
                    $wpdb->insert($tablename,$data);
                // }
           
            
            }
            if($value['group_sessions'] != 0 ){
                $credits = $value['group_sessions'];
                $purch = 	$wpdb->get_results("select * from ".DB_WC_GF_CUSTOMER_PURCHASES." where credits=".$credits." and customer_id=".$user_id." and child_type='group'" ,ARRAY_A);
                // var_dump("select * from ".DB_WC_GF_CUSTOMER_PURCHASES." where credits=".$credits." and customer_id=".$user_id." and child_type='individual'");
                
                // exit();
                // if(count($purch) == 0){
                    $order = wc_create_order();
    
                    // The add_product() function below is located in /plugins/woocommerce/includes/abstracts/abstract_wc_order.php
                    $order->add_product( get_product('5'), 1); // This is an existing SIMPLE product
                    //
                    $order->calculate_totals();
                    $order->update_status( 'processing' );
                    $hidden_name = 'group';
            
                    if(trim($value['player_name']) != ""){
                        $player = explode(" ",$value['player_name']);
                        $args = array(
                            "user_id" => $user_id,
                            "first_name" => $player[0],
                            "grade" => '',
                            "jersey_size" => '',
                            "child_type" => $hidden_name
                        );
                        if(count($player)>1){
                            $args['last_name'] = $player[1];
                        }else{
                            $args['last_name'] = '';
                        }
                
                        $children = $wpdb->get_results("select * from ".DB_CHILD_DETAILS." where first_name='".$player[0]."' and user_id=".$user_id ,ARRAY_A);
            
    
                        // if(count($children)== 0){
                            $sqlInsert = $wpdb->insert(DB_CHILD_DETAILS, $args);
                        // }
                    }
                    $credits = $value['group_sessions'];
                    $data = [
                        'customer_id' => $user_id,
                        'gf_form_id' =>13,
                        'order_id' => $order->ID,
                        'package_hidden_name' => $hidden_name,
                        'credits' => $credits
                    ];
                    $wpdb->insert($tablename,$data);
            }
        }
    
    
        
        
    
      
        
    
           
        }
      
    
    foreach ($emails as $key => $value) {
    	$msg = "Hi,<br> Your account has been created in shootinschool. Please use the below credentials to login <br><br> Email:".$value."<br>Password:".$passwords[$key]."<br><br>Thank you.";
    	wp_mail($value, "Account created | Shootinschool",$msg , $headers);
    }
    
    
    
    var_dump("success");
    exit();
    }