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

class Registration_request extends CI_Controller {

public function __construct() {
		parent::__construct();				
		$this->load->model('Regrequest_model');		
        
        }

	
	
	public function editExpresss($Express_id){	
	    $id=decode_param($Express_id);
        $template['Express_id'] =encode_param($id);	
		$template['page_title'] = "Login";
		$template['ExpressData'] = $this->Regrequest_model->getExpressData($id);	
		$this->load->view('Regexpress_request', $template);
	
	    }
	
	public function updateExpress($Express_id = ''){
		$id=decode_param($Express_id);
		$err = 0;
		$errMsg = '';
		$flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'danger');
		if(!isset($_POST) || empty($_POST) || !isset($_FILES) || empty($_FILES)){
			$this->session->set_flashdata('message',$flashMsg);
            redirect(base_url('Registration_request/editExpresss/'.$Express_id));
		}
		
		if($err == 0 && (!isset($_POST['name']) || empty($_POST['name']))){
			$err = 1;
			$errMsg = 'Provide Express Name';
		}else if($err == 0 && (!isset($_POST['email']) || empty($_POST['email']))){
			$err = 1;
			$errMsg = 'Provide a Express Email';
		}else if($err == 0 && (!isset($_POST['phone']) || empty($_POST['phone']))){
			$err = 1;
			$errMsg = 'Provide Express Phone';
	
        }
    	
        if($err == 0){
	       $config = set_upload_service("assets/uploads/express");
            $this->load->library('upload');
            $config['file_name'] = time()."_".$_FILES['profile_image']['name'];
            $this->upload->initialize($config);
            if(!$this->upload->do_upload('profile_image')){
                $err = 1;
                $errMsg = $this->upload->display_errors();
            }else{
                $upload_data = $this->upload->data();
                 $image = $upload_data['file_name'];
            $new_array = array('width'=>100, 'height'=>100);
           
                $image_file = $config['upload_path']."/".$upload_data['file_name'];
              
             $_POST['profile_image'] = $image_file;
            }
	    }

		if($err == 1){
			$flashMsg['message'] = $errMsg;
			$this->session->set_flashdata('message',$flashMsg);
            redirect(base_url('Registration_request/editExpresss/'.$Express_id));
		}
		
        $status = $this->Regrequest_model->updateExpress($id,$_POST);
       
        if($status == 1){
            $flashMsg = array('message'=>'Update Successfully!','class'=>'success');
            $this->session->set_flashdata('message', $flashMsg);
           redirect(base_url());
        } else if($status == 2){
            $flashMsg = array('message'=>'Email ID already exist..!','class'=>'danger');
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editExpresss/'.$Express_id));
        } else if($status == 3){
            $flashMsg = array('message'=>'Phone Number already exist..!','class'=>'danger');
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editExpresss/'.$Express_id));
        } else if($status == 4){
            $flashMsg = array('message'=>'User Name already exist..!','class'=>'danger');
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editExpresss/'.$Express_id));
        } 
        else {
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editExpresss/'.$Express_id));
        }
	}


public function editGarege($Garege_id){	
	    $id=decode_param($Garege_id);
        $template['Garege_id'] =encode_param($id);	
		$template['page_title'] = "Login";
		$template['services'] = $this->Regrequest_model->getGarageServices();
        $template['garageData'] = $this->Regrequest_model->getGarageData($id);
        $template['amenities'] = $this->Regrequest_model->getAmenities();
        $template['serviceData'] = $this->Regrequest_model->getServiceData($id);
		$this->load->view('Reggarage_request', $template);
	
	    }

public function updateGarage($Garage_id = ''){
		$id=decode_param($Garage_id);
		$err = 0;
		$errMsg = '';
		$flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'danger');
		if(!isset($_POST) || empty($_POST) || !isset($_FILES) || empty($_FILES)){
			$this->session->set_flashdata('message',$flashMsg);
            redirect(base_url('Registration_request/editGarege/'.$Garage_id));
		}
		
		if($err == 0 && (!isset($_POST['name']) || empty($_POST['name']))){
			$err = 1;
			$errMsg = 'Provide Garage Name';
		}else if($err == 0 && (!isset($_POST['email']) || empty($_POST['email']))){
			$err = 1;
			$errMsg = 'Provide a Garage Email';
		}else if($err == 0 && (!isset($_POST['phone']) || empty($_POST['phone']))){
			$err = 1;
			$errMsg = 'Provide Garage Phone';
	
        }
    	
        if($err == 0){
	       $config = set_upload_service("assets/uploads/Garage");
            $this->load->library('upload');
            $config['file_name'] = time()."_".$_FILES['profile_image']['name'];
            $this->upload->initialize($config);
            if(!$this->upload->do_upload('profile_image')){
                $err = 1;
                $errMsg = $this->upload->display_errors();
            }else{
                $upload_data = $this->upload->data();
                 $image = $upload_data['file_name'];
            $new_array = array('width'=>100, 'height'=>100);
           
                $image_file = $config['upload_path']."/".$upload_data['file_name'];
              
             $_POST['profile_image'] = $image_file;
            }
	    }

		if($err == 1){
			$flashMsg['message'] = $errMsg;
			$this->session->set_flashdata('message',$flashMsg);
            redirect(base_url('Registration_request/editGarege/'.$Garage_id));
		}
		
        $status = $this->Regrequest_model->updateGarage($id,$_POST);
       
        if($status == 1){
            $flashMsg = array('message'=>'Update Successfully!','class'=>'success');
            $this->session->set_flashdata('message', $flashMsg);
           redirect(base_url('Registration_request/editGarege/'.encode_param($id)));
        } else if($status == 2){
            $flashMsg = array('message'=>'Email ID already exist..!','class'=>'danger');
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editGarege/'.$Garage_id));
        } else if($status == 3){
            $flashMsg = array('message'=>'Phone Number already exist..!','class'=>'danger');
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editGarege/'.$Garage_id));
        } else if($status == 4){
            $flashMsg = array('message'=>'User Name already exist..!','class'=>'danger');
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editGarege/'.$Garage_id));
        } 
        else {
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editGarege/'.$Garage_id));
        }
	}






public function editPos($Pos_id){ 
        $id=decode_param($Pos_id);
        $template['Pos_id'] =encode_param($id);  
        $template['page_title'] = "Login";
        $template['PosData'] = $this->Regrequest_model->getPosData($id);
        $this->load->view('Regpos_request', $template);
    //print_r($template['PosData']);exit;
        }

public function updatePos($Pos_id = ''){
        $id=decode_param($Pos_id);
        $err = 0;
        $errMsg = '';
        $flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'danger');
        if(!isset($_POST) || empty($_POST) || !isset($_FILES) || empty($_FILES)){
            $this->session->set_flashdata('message',$flashMsg);
            redirect(base_url('Registration_request/editPos/'.$Pos_id));
        }
        
        if($err == 0 && (!isset($_POST['name']) || empty($_POST['name']))){
            $err = 1;
            $errMsg = 'Provide Pos Name';
        }else if($err == 0 && (!isset($_POST['email']) || empty($_POST['email']))){
            $err = 1;
            $errMsg = 'Provide a Pos Email';
        }else if($err == 0 && (!isset($_POST['phone']) || empty($_POST['phone']))){
            $err = 1;
            $errMsg = 'Provide Pos Phone';
    
        }
    
        if($err == 0){
            $config = set_upload_service("assets/uploads/Pos");
            $this->load->library('upload');
            $config['file_name'] = time()."_".$_FILES['profile_image']['name'];
            $this->upload->initialize($config);
            if(!$this->upload->do_upload('profile_image')){
                $err = 1;
                $errMsg = $this->upload->display_errors();
            }else{
                $upload_data = $this->upload->data();
                 $image = $upload_data['file_name'];
            $new_array = array('width'=>100, 'height'=>100);
           
                $image_file = $config['upload_path']."/".$upload_data['file_name'];
              
             $_POST['profile_image'] = $image_file;
            }
        }

        if($err == 1){
            $flashMsg['message'] = $errMsg;
            $this->session->set_flashdata('message',$flashMsg);
            redirect(base_url('Registration_request/editPos/'.$Pos_id));
        }
        
        $status = $this->Regrequest_model->updatePos($id,$_POST);
       
        if($status == 1){
            $flashMsg = array('message'=>'Update Successfully!','class'=>'success');
            $this->session->set_flashdata('message', $flashMsg);
           redirect(base_url('Registration_request/editPos/'.$Pos_id));
        } else if($status == 2){
            $flashMsg = array('message'=>'Email ID already exist..!','class'=>'danger');
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editPos/'.$Pos_id));
        } else if($status == 3){
            $flashMsg = array('message'=>'Phone Number already exist..!','class'=>'danger');
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editPos/'.$Pos_id));
        } else if($status == 4){
            $flashMsg = array('message'=>'User Name already exist..!','class'=>'danger');
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editPos/'.$Pos_id));
        } 
        else {
            $this->session->set_flashdata('message', $flashMsg);
            redirect(base_url('Registration_request/editPos/'.$Pos_id));
        }
    }







}





