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

class Superviseur_dash extends CI_Controller
{

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

    public function index()
    {
        if (!$this->session->userdata('email')) {

            $this->session->set_flashdata('error', 'log in first');
            $data['alert'] = "ok";
            $data['message'] = "Login first!";
            redirect('index.php', $data);

        } else {

            $count_g = $this->User_model->geolocatedCountByParrain($this->session->userdata('member_code'));
            $count_d = $this->User_model->getCountDemande($this->session->userdata('member_code'));
            $count_d_traite = $this->User_model->getCountDemandeByStatut($this->session->userdata('member_code'),1);
            $count_d_no_traite = $this->User_model->getCountDemandeByStatut($this->session->userdata('member_code'),0);

            $data['list_geolocated_users'] = $this->user_model->getUsersGeolocatedForSup($this->session->userdata('member_code'));

            $data['active'] = "dash";
            $data['token'] = $this->session->userdata('token');
            $data['email'] = $this->session->userdata('email');
            $data['firstname'] = $this->session->userdata('firstname');
            $data['lastname'] = $this->session->userdata('lastname');
            $data['member_code'] = $this->session->userdata('member_code');
            $data['phone'] = $this->session->userdata('phone');
            $data['adresse'] = $this->session->userdata('adresse');
            $data['category'] = $this->session->userdata('category');
            $data['network'] = $this->session->userdata('network');
            $data['code_parrain'] = $this->session->userdata('parrain');
            $data['listdem'] = $this->user_model->getDemandesForSuper($this->session->userdata('member_code'));
            $data['count_g_users'] = $count_g;
            $data['count_d_users'] = $count_d;
            $data['count_d_traite'] = $count_d_traite;
            $data['count_d_no_traite'] = $count_d_no_traite;
            $this->load->view('header_sup', $data);
            $this->load->view('superviseur_dash');
            $this->load->view('footer');
        }
    }

    public function getAllUser_g(){

        if (!$this->session->userdata('email')) {
            $this->session->set_flashdata('error', 'log in first');

            $data['alert'] = "ok";
            $data['message'] = "Login first!";


            redirect('index.php', $data);
        }
        else {

            $position = $this->user_model->getAllpositions($this->session->userdata('network'),'geolocated',$this->session->userdata('member_code'));

            $data['active'] = "geolocated";
            $data['positions']= $position;
            $numberGeo = $this->user_model->getNumberGeoBySuper($this->session->userdata('member_code'));
            if($numberGeo!=false){
                $data['numberGeo'] = $numberGeo;
            }else{
                $data['numberGeo'] = "";
            }
            $data['map_title'] = $this->lang->line('Utilisateurs géolocalisés');
            $data['total_points'] = $this->user_model->getCoutGeolocatedUsersForSuper($this->session->userdata('member_code'));
            $data['tab'] = $this->user_model->getUsersGeolocatedForSup($this->session->userdata('member_code'));
            $data['latitude'] = $this->session->userdata('latitude');
            $data['longitude'] = $this->session->userdata('longitude');
            $data['token'] = $this->session->userdata('token');
            $data['email'] = $this->session->userdata('email');
            $data['firstname'] = $this->session->userdata('firstname');
            $data['lastname'] = $this->session->userdata('lastname');
            $data['code_parrain'] = $this->session->userdata('code_parrain');
            $data['phone'] = $this->session->userdata('phone');
            $data['adresse'] = $this->session->userdata('adresse');
            $data['category'] = $this->session->userdata('category');
            $data['network'] = $this->session->userdata('network');
            $data['alert'] = "";
            $this->load->view('header_sup', $data);
            $this->load->view('listeadmin');
            $this->load->view('footer');
        }
    }

    public function getDemandes(){

        if (!$this->session->userdata('email')) {
            $this->session->set_flashdata('error', 'log in first');
            $data['alert'] = "ok";
            $data['message'] = "Login first!";
            $this->load->view('login', $data);
        } else {
            $network = $this->session->userdata('network');

            $data['active'] = "demandes";
            $data['type'] = $this->lang->line('crédits');
            $data['alert'] = "";
            $data['token'] = $this->session->userdata('token');
            $data['email'] = $this->session->userdata('email');
            $data['firstname'] = $this->session->userdata('firstname');
            $data['lastname'] = $this->session->userdata('lastname');
            $data['code_parrain'] = $this->session->userdata('code_parrain');
            $data['phone'] = $this->session->userdata('phone');
            $data['adresse'] = $this->session->userdata('adresse');
            $data['category'] = $this->session->userdata('category');
            $data['network'] = $this->session->userdata('network');
            $data['tab_fastDemande'] = $this->user_model->getRangeASCDemandes($this->session->userdata('member_code'));
            $data['tab_fastDemande_s'] = $this->user_model->getRangeASCDemandesOut($this->session->userdata('member_code'));
            $data['tab_slowDemande'] = $this->user_model->getRangeDESCDemandes($this->session->userdata('member_code'));
            $data['tab_slowDemande_s'] = $this->user_model->getRangeDESCDemandesOut($this->session->userdata('member_code'));
            $data['mydem'] = $this->user_model->getDemandesHyperForSuper($this->session->userdata('member_code'));
            $data['temp_moyen'] = $this->user_model->getTempsMoyen($this->session->userdata('member_code'));
            $data['temp_moyen_mine'] = $this->user_model->getTempsMoyenDemandeSup($this->session->userdata('member_code'));
            $data['list'] = $this->user_model->getDemandesForSuper($this->session->userdata('member_code'));
            $this->load->view('header_sup', $data);
            $this->load->view('demande');
            $this->load->view('footer');
        }
    }

    public function getDemandesAd(){

        if (!$this->session->userdata('email')) {
            $this->session->set_flashdata('error', 'log in first');
            $data['alert'] = "ok";
            $data['message'] = "Login first!";
            $this->load->view('login', $data);
        } else {
            $network = $this->session->userdata('network');

            $data['active'] = "demandesAd";
            $data['alert'] = "";
            $data['token'] = $this->session->userdata('token');
            $data['email'] = $this->session->userdata('email');
            $data['firstname'] = $this->session->userdata('firstname');
            $data['lastname'] = $this->session->userdata('lastname');
            $data['code_parrain'] = $this->session->userdata('code_parrain');
            $data['phone'] = $this->session->userdata('phone');
            $data['adresse'] = $this->session->userdata('adresse');
            $data['category'] = $this->session->userdata('category');
            $data['network'] = $this->session->userdata('network');
            $data['tab_fastDemande'] = $this->user_model->getRangeASCDemandesAd($this->session->userdata('member_code'));
            $data['tab_slowDemande'] = $this->user_model->getRangeDESCDemandesAd($this->session->userdata('member_code'));
            $data['mydem'] = $this->user_model->getDemandesHyperForSuper($this->session->userdata('member_code'));
            $data['temp_moyen'] = $this->user_model->getTempsMoyenAd($this->session->userdata('member_code'));
            $data['list'] = $this->user_model->getDemandesAdForSuper($this->session->userdata('member_code'));
            $data['type'] = 'adhésions';
            $this->load->view('header_sup', $data);
            $this->load->view('demande');
            $this->load->view('footer');
        }
    }
}
