<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Account extends Admin_Controller {

    function __construct() {
        parent::__construct();
	}
	
	public function index() {        
        
        $this->template
    		->set('view', 'admin/account/index')
            ->render();
	}
    
    function customerAction() {
        
        $customerName = $this->input->post('customername');
		$phoneNumber = $this->input->post('phonenumber');
		$mainContact = $this->input->post('mainContact');
        $email = $this->input->post('email');
        $address = $this->input->post('address');
        $city = $this->input->post('city');	
        $calendarId = $this->input->post('customerCalendarId');
        //$isActive = $this->input->post('isActive') ? 1 : 0;        

        $name = explode(' ', $mainContact); /***/  
        $userData = array(
            'firstname'  => $name[0],
            'lastname'   => defaultValue($name[1], ''),
            'email'      => $email,
            'phone'      => $phoneNumber,
            'password'   => $hashedPW,
            'isActive'   => 1,
            'salt'       => $salt,
            'typeId'     => 1,  
            'userLevel'  => 3, 
            'adminId'    => $result,
            'creationDate'  => date('Y-m-d H:i:s'),
            'lastUpdate'    => date('Y-m-d H:i:s')
        );

        $sqlData = array(
            'customerName'  => $customerName,
            'phoneNumber'   => $phoneNumber,
            'mainContact'   => $mainContact,
            'address'       => $address,
            'city'          => $city,
            'customerCalendarId' => $calendarId,
            //'isActive'      => $isActive,
            'lastUpdate'    => date('Y-m-d H:i:s')
        );
		$result = $this->general_model->updateRowById('customers', 'customerId', getAdminId(), $sqlData);
		if ($result) {
		    $this->session->set_flashdata('flashMsgType', 'Success'); 
			$this->session->set_flashdata('flashMsg','השינויים נשמרו בהצלחה!');
		}
		else {
		    $this->session->set_flashdata('flashMsgType', 'Error');  
			$this->session->set_flashdata('flashMsg','אופס! אירעה שגיאה, אנא נסה שנית.');
		}
		redirect('app/account', 'location');
		
	}    
    
}    