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

class Welcome extends CI_Controller {

	public function index()
	{

		// Collecting Front Countdown Numbers
		$this->load->model('front_countdown_model');
		$data['results'] = $this->front_countdown_model->show_front_countdown();
		
		// Collecting Client & Partners
		$this->load->model('logo_model');
        $data['logos'] = $this->logo_model->show_logo();
		$this->load->view('front/index', $data);
	}
	
	public function portfolio(){
	    // Collecting Portfolio
		$this->load->model('portfolio_model');
        $data['portfolios'] = $this->portfolio_model->show_portfolio();
		$this->load->view('front/portfolio', $data);
	}

	public function about(){
		$this->load->view('front/about');
	}

	public function contact(){
		$this->load->view('front/contact');
	}

	public function software()
	{
		// Collecting Softwares
		$this->load->model('software_model');
		$data['softwares'] = $this->software_model->show_software();
		
		$this->load->view('front/software', $data);
	}

	public function shared_hosting(){
		// Collecting domain_hosting packages

		$this->load->model('hosting_package_model');
		$data['shared_hosting_packages'] = $this->hosting_package_model->show_shared_hosting_package();

		$this->load->model('hosting_package_model');
		$data['wordpress_hosting_packages'] = $this->hosting_package_model->show_wordpress_hosting_package();


		
		$this->load->view('front/shared_hosting', $data);
	}

	public function email_marketing(){
		// Collecting email_marketing packages

		$this->load->model('hosting_package_model');
		$data['email_marketing_packages'] = $this->hosting_package_model->show_email_marketing_package();


		
		$this->load->view('front/email_marketing', $data);
	}

	public function facebook_marketing(){
		// Collecting facebook_marketing packages

		$this->load->model('hosting_package_model');
		$data['facebook_marketing_packages'] = $this->hosting_package_model->show_facebook_marketing_package();


		
		$this->load->view('front/facebook_marketing', $data);
	}

	public function google_adwords(){
		// Collecting google_adwords packages

		$this->load->model('hosting_package_model');
		$data['google_adwords_packages'] = $this->hosting_package_model->show_google_adwords_package();

		$this->load->view('front/google_adwords', $data);
	}


	public function sms_marketing(){

		// Collecting sms_marketing packages

		$this->load->model('sms_marketing_model');
		$data['non_masking_packages'] = $this->sms_marketing_model->show_non_masking_package();
		$data['masking_packages'] = $this->sms_marketing_model->show_masking_package();


		$this->load->view('front/sms_marketing', $data);
	}

	public function web_packages(){

		// Collecting sms_marketing packages

		$this->load->model('web_package_model');
		$data['business_packages'] = $this->web_package_model->show_business_package();
		$data['ecommerce_packages'] = $this->web_package_model->show_ecommerce_package();


		$this->load->view('front/web_packages', $data);
	}

	public function reseller(){
		// Go to reseller packages
		$this->load->view('front/reseller');
	}


	public function ssl_package(){
		// Go to reseller packages
		$this->load->view('front/ssl_package');
	}


	public function order(){
		$this->load->view('front/order');
	}

	public function submitOrder(){

		$this->form_validation->set_rules('name', 'Name', 'required');
		$this->form_validation->set_rules('email', 'Email', 'required');
		$this->form_validation->set_rules('phone', 'Phone', 'required');

        if ($this->form_validation->run() == FALSE){

			$this->session->set_flashdata('error', 'Set Name, Email and Phone');

        	redirect('Welcome/order');
                
        }
        else{

			$data = array(
				'client_name' => $this->input->post('name'),
				'title' => $this->input->post('title'),
				'price' => $this->input->post('price'),
				'package' => $this->input->post('package'),
				'packageid' => $this->input->post('packageid'),
				'type' => $this->input->post('type'),
				'email' => $this->input->post('email'),
				'phone' => $this->input->post('phone'),
				'address' => $this->input->post('address'),
				'status' => 1
			);

			$this->load->model('order_model');
			$res = $this->order_model->insert_order($data);

			if($res == TRUE){
				$this->session->set_flashdata('success', 'Successfully Ordered! Please Visit Our Pages To Order Again');
				redirect("Welcome/startProject");
			}
			else{
				$this->session->set_flashdata('error', 'Something went wrong');
				redirect("Welcome/startProject");
			}
            
        }

	}

	public function startProject(){
		$this->load->view('front/start_project');
	}
	
	public function sendProject(){
	    $this->form_validation->set_rules('name', 'Name', 'required');
		$this->form_validation->set_rules('email', 'Email', 'required');
		$this->form_validation->set_rules('phone', 'Phone', 'required');
		$this->form_validation->set_rules('project_type', 'Project Type', 'required');

        if ($this->form_validation->run() == FALSE){

			$this->session->set_flashdata('error', 'Set Name, Email, Phone and Project Type');

        	redirect('Welcome/startProject');
                
        }
        else{
    		$this->load->library('email');
    		$this->email->set_mailtype("html");
    		
    		$data = array(
    			'name' => $this->input->post('name'),
    			'email' => $this->input->post('email'),
    			'phone' => $this->input->post('phone'),
    			'address' => $this->input->post('address'),
    			'company' => $this->input->post('company'),
    			'project_type' => $this->input->post('project_type'), 
    			'description' => $this->input->post('description'), 
    		);
    
    		$this->email->from($data['email'], $data['name']);
    		$this->email->to('hakikzaman@iciclelimited.com');
    		$this->email->cc('feedback@iciclelimited.com');
    
    		$this->email->subject("Start A Project!");
    		
    		
    		$this->email->message("Hello from ".$data['name'].",<br><br><br> My Email is ". $data['email'].", and my phone ". $data['phone'].".<br><br>I want to talk about ".$data['project_type']." Product.<br><br><br> Some Description of my project:<br>".$data['description']."<br><br><br>Sincerely,<br>".$data['name']."<br>".$data['address']);
    
    		$this->email->send();
    		
    		$this->session->set_flashdata('success', 'Successfully Send! We Will be in Touch Soon');
				redirect("Welcome/startProject");
    		
    		
        }
	}

	public function sendMessage(){
	    $this->form_validation->set_rules('name', 'Name', 'required');
		$this->form_validation->set_rules('email', 'Email', 'required');
		$this->form_validation->set_rules('subject', 'Subject', 'required');
		$this->form_validation->set_rules('message', 'Message', 'required');

        if ($this->form_validation->run() == FALSE){

			$this->session->set_flashdata('error', 'Set Name, Email, Subject and Message');

        	redirect('Welcome/contact');
                
        }
        else{
    		$this->load->library('email');
    		
    		$data = array(
    			'name' => $this->input->post('name'),
    			'email' => $this->input->post('email'),
    			'subject' => $this->input->post('subject'),
    			'message' => $this->input->post('message')
    		);
    
    		$this->email->from($data['email'], $data['name']);
    		$this->email->to('hakikzaman@iciclelimited.com');
    		$this->email->cc('feedback@iciclelimited.com');
    
    		$this->email->subject($data['subject']);
    		$this->email->message($data['message']);
    
    		$this->email->send();
    		
    		$this->session->set_flashdata('success', 'Successfully Send! Please Visit Our Pages To Order Again');
				redirect("Welcome/contact");
    		
    		
        }
	}


}
