<?php
class ControllerToolDeercaseUyeler extends Controller{

    public function index(){

        $file_path = '/home/deer2piyersoft/public_html/';

        die();

        if(!isset($this->session->data['users'])){

            $this->session->data['users'] = array();

            $row = 1;
            if (($handle = fopen($file_path . "uyeler.csv", "r")) !== FALSE) {
                while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                    $num = count($data);
                    for ($c=0; $c < $num; $c++) {
                        //echo $data[$c] . "<br />\n";
                        $this->session->data['users'][$row][] = $data[$c];
                    }
                    $row++;
                }
                fclose($handle);
            }
        }

        foreach ($this->session->data['users'] as $user){

            $this->db->query("INSERT INTO ps_customer SET 
                customer_group_id = '1', 
                old_id = '" . $user[0] . "', 
                store_id = '0', 
                language_id = '1', 
                firstname = '" . $this->db->escape($user[1]) . "', 
                lastname = '" . $this->db->escape($user[2]) . "', 
                tc = '" . $this->db->escape($user[3]) . "', 
                email = '" . $this->db->escape($user[4]) . "', 
                telephone = '" . $this->db->escape($user[6]) . "', 
                custom_field = '" . $this->db->escape(isset($user) ? json_encode($user) : '') . "', 
                salt = '" . $this->db->escape($salt = token(9)) . "', 
                password = '" . $this->db->escape($user[5]) . "', 
                newsletter = '0', 
                ip = '" . $this->db->escape($user[14]) . "', 
                status = '1', 
                approved = '1', 
                date_added = '" . $this->db->escape($user[18]) . "' ");

            $customer_id = $this->db->getLastId();

            $this->db->query("INSERT INTO ps_address SET 
			customer_id = '" . (int)$customer_id . "', 
			firstname = '" . $this->db->escape($user[1]) . "', 
            lastname = '" . $this->db->escape($user[2]) . "', 
			company = '', 
			address_1 = '" . $this->db->escape($user[7]) . "', 
			address_2 = '', 
			city = '" . $this->db->escape($user[8] . ' - ' .$user[9]) . "', 
			postcode = '', 
			country_id = '215', 
			zone_id = '',
			custom_field = '' ");

            $address_id = $this->db->getLastId();

            $this->db->query("UPDATE ps_customer SET 
			address_id = '" . (int)$address_id . "' WHERE customer_id = '" . (int)$customer_id . "' ");

            //die();


        }


    }

}