<?php

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

class Front extends CI_Controller {

    public function index() {

        $page =(isset($_GET['page'])) ? $_GET['page'] : 0;
        $query=$this->db->select('requirement.*')->from('requirement')->where('status','Active')->order_by('id','desc')->limit(5,($page))->get();
        $num_rows=$this->db->where('status','Active')->order_by('id', 'desc')->get('requirement')->num_rows();
        $data['requirement']=$query->result_array();
        $data['news']=$this->db->where('status','Active')->order_by('id','desc')->limit(5)->get('news')->result_array();
        $data['links']=$this->pagi->pagination1('admin/requirement',$num_rows,5);
        $this->load->view('index',$data);

    }


    public function all_requirement()
    {
        $page =(isset($_GET['page'])) ? $_GET['page'] : 0;
        $query=$this->db->select('requirement.*')->from('requirement')->where('status','Active')->order_by('id','desc')->limit(20,($page))->get();
        $num_rows=$this->db->order_by('id', 'desc')->where('status','Active')->get('requirement')->num_rows();
        $data['requirement']=$query->result_array();
        $data['links']=$this->pagi->pagination1('admin/requirement',$num_rows,20);
        $this->load->view('requirement',$data);
    }

    public function aboutus() {
        $this->load->view('aboutus');

    }

   
  public function share_cv()
  {
    if ($this->input->server('REQUEST_METHOD') == 'POST') 
        {
            $journalName = str_replace(' ', '_', $_FILES['resume']['name']);
                $config['file_name'] = time() . $journalName;
                $config['upload_path'] = './uploads/resume/';
                $config['allowed_types'] = 'gif|jpg|png|JPG|JPEG|jpeg|docx|docs|pdf';
                $this->upload->initialize($config);
                $this->upload->do_upload('resume');
                $_POST['resume'] = $config['file_name'];
                if($this->db->insert('share_cv',$_POST))
                {
                    $this->session->set_flashdata('msg', 'Share CV Successfully Added');
                    return redirect(base_url('share-cv'),'refresh');
                }
                else
                {
                    $this->session->set_flashdata('err', 'Please try Again After SomeTimes');
                    return redirect(base_url('share-cv'),'refresh');
                }
        }
        else
    {
         $this->load->view('share_cv');
    }
  }

  public function share_requirement()
  {
     if ($this->input->server('REQUEST_METHOD') == 'POST') 
        {
          $this->db->insert('requirement',$_POST);
          $config = Array(
            'mailtype' => 'html',
            'charset' => 'iso-8859-1',
            'wordwrap' => TRUE
            );

             $config['newline'] = "\r\n";
             $message = "<table>";
        foreach ($_POST as $key => $value) {
            $message .= "<tr><th>" . $key . "</th><td>" . $value . "</td></tr>";
        }
        $message .= "</table>";
            $this->load->library('email',$config);

            $this->email->from("info@btechbymistake.com");
            $this->email->to($_POST['email']);
           
            $this->email->subject('NGIT GLOBAL');
            $this->email->message($message);

               if($this->email->send()){
                 redirect(base_url('thanks'),'refresh');  
          
        }
        else{
          return redirect(base_url('share-requirement'),'refresh');
        }
    }
        else
        {
           //return redirect(base_url('share-requirement'),'refresh');
            $this->load->view('share_requirement');
        }
  }

  
    public function contact() {

        $this->load->view('contact');

    }

    // signin
    public function signin() {

        $this->load->view('signin');

    }

    // signup
    public function signup() {

        $this->load->view('signup');

    }

    // forget password
    public function forget_password() {

        $this->load->view('forget_password');

    }

   
    

    public function enquiry() {

       
        $config = Array(
            'mailtype' => 'html',
            'charset' => 'iso-8859-1',
            'wordwrap' => TRUE
            );

             $config['newline'] = "\r\n";
             $message = "<table>";
        foreach ($_POST as $key => $value) {
            $message .= "<tr><th>" . $key . "</th><td>" . $value . "</td></tr>";
        }
        $message .= "</table>";
            $this->load->library('email',$config);

            $this->email->from($_POST['Email'], $_POST['Name']);
            $this->email->to('info@ngitglobal.com');
           
            $this->email->subject('NGIT Global');
            $this->email->message($message);
                
                if($this->email->send()){
                    echo 'Tanku';
                }
                else{
                   $this->load->view('index');
                }
               
            
            //$this->db->insert('enquiry', $_POST);
            //$this->session->set_flashdata('msg', 'Your Request Succeessfully Submiited');
          // redirect(base_url('thanks'), 'refresh');

    }


    public function all_news()
    {
        $data['news']=$this->db->where('status','Active')->order_by('id','desc')->get('news')->result_array();
        $this->load->view('all_news',$data);
    }
 public function news($id='')
    {
        $data['news']=$this->db->where(array('id'=>$id,'status'=>'Active'))->order_by('id','desc')->get('news')->row_array();
        $this->load->view('news',$data);
    }
 public function thanks() {

        $this->load->view('thanks');

    }

}