<?php

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

/**
 *
 *
 * @author Lalendra
 */
class Public_Controller extends CI_Controller {

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

    public function Activity_Suggestions() {
        if ($this->input->is_ajax_request() && $this->input->method() == "post") {
            $key = $this->input->post('Key');
            if ($key == "") {
                echo json_encode(['']);
            }
            $res = $this->Activity_model->getActivity_Suggestions($key);
            echo json_encode($res);
        } else {
            $this->output->set_status_header('400');
            $this->data['message'] = 'You can not access';
            echo json_encode($this->data);
        }
    }

    public function validate_empID() {
        if ($this->input->is_ajax_request() && $this->input->method() == "post") {
            $empId = $this->input->post('empId');
            if ($empId == "") {
                $this->output->set_status_header('400');
                $this->data['message'] = 'Error,Empty EmpID';
                echo json_encode($this->data);
            }
            $res = $this->user_model->validateEmpID($empId);
            if (count($res) > 0) {
                echo json_encode(FALSE);
            } else {
                echo json_encode(TRUE);
            }
        } else {
            $this->output->set_status_header('400');
            $this->data['message'] = 'You can not access';
            echo json_encode($this->data);
        }
    }

    public function addEmpActivity() {
        if ($this->input->is_ajax_request() && $this->input->method() == "post") {
            $empName = $this->input->post('empName');
            $designation = $this->input->post('designation');
            $empID = $this->input->post('empID');
            $department = $this->input->post('department');
            $supervisor = $this->input->post('supervisor');
            $duration = $this->input->post('duration');
            if ($empName == "" || $empID == "" || $department == "" || $supervisor == "" || $duration == "" || $designation=="") {
                $this->output->set_status_header('400');
                $this->data['message'] = 'Error,Emp Info missing';
                echo json_encode($this->data);
                return FALSE;
            }

            $activityarr = $this->input->post('activityarr');
            $frequentArr = $this->input->post('frequentArr');
            $timeArr = $this->input->post('timeArr');
            $hourArr = $this->input->post('hourArr');
            $satisfactionArr = $this->input->post('satisfactionArr');


            if (!(is_array($activityarr) && is_array($frequentArr) && is_array($timeArr) && is_array($hourArr) && is_array($satisfactionArr))) {
                $this->output->set_status_header('400');
                $this->data['message'] = 'Error,Activity missmatch';
                echo json_encode($this->data);
                return FALSE;
            }

            $countMin=1;

            if (!(count($hourArr) >= $countMin && count($activityarr) >=  $countMin && count($timeArr) >=  $countMin && count($frequentArr) >=  $countMin && count($satisfactionArr) >=  $countMin)) {
                $this->output->set_status_header('400');
                $this->data['message'] = 'Error,Activity missmatch';
                echo json_encode($this->data);
                return FALSE;
            }

			$targetTextArr = $this->input->post('targetTextArr');
			$targetSatisfactionArr = $this->input->post('targetSatisfactionArr');
			$targetMonitorArr = $this->input->post('targetMonitorArr');
			$monitorFrequentArr = $this->input->post('monitorFrequentArr');
			$suggestionArr = $this->input->post('suggestionArr');

            $return=$this->Activity_model->addEmpInfoActivity($empID, $empName,$designation, $department, $supervisor, $duration,
				$activityarr,$frequentArr,$timeArr,$hourArr,$satisfactionArr,$targetTextArr,$targetSatisfactionArr,$targetMonitorArr,
				$monitorFrequentArr,$suggestionArr);
            echo json_encode($return);
        } else {
            $this->output->set_status_header('400');
            $this->data['message'] = 'You can not access';
            echo json_encode($this->data);
            return FALSE;
        }
    }


//    public function test(){
//    	$this->Activity_model->testF("Answering sales calls",'21');
//	}
}
