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

class GeolocatedUsers extends CI_Controller
{

	function __construct()
	{
		parent::__construct();

		// Load member model
		$this->load->model('pagination/GeolocatedUsers_model', 'gu_model');

	}


	function getLists()
	{
		$list = array();

		// Fetch member's records
		$datas = $this->gu_model->getRows($_POST);

		foreach ($datas as $row) {

			$status = $this->lang->line($row->active==1 ? 'Oui' : 'Non');

			$code_parrain = $row->code_parrain;
			if($row->code_parrain==$this->session->userdata('member_code')){
				$code_parrain = $this->lang->line("Vous");
			}

			$data = array("<button class='btn btn-default btn-center openSupervisorModal' data-code_parrain='$row->code_parrain'>$code_parrain</button>",
				$row->lastname,$row->adresse, $row->code_membre , $row->email, $row->phone , $row->provider_class ,$status);

			if($_POST['category'] == 'geolocated'){
				if($row->qr_code)
					$data[] = "<a href='".$row->qr_code."' class='btn btn-success btn-center' target='_blank'>" . $this->lang->line('display') . "</a>";
				else
					$data[] = "<button class='btn btn-primary btn-center generateQRCode' data-id_agent='$row->id'>" . $this->lang->line('generate') . "</button>";
			}

			if ($this->session->userdata("category") == "0" or $this->session->userdata("category") == "hyper")
				$data[] = "<button data-toggle='modal' data-category='$row->category' data-lastname='$row->lastname' data-adresse='$row->adresse' data-network_agent_id='$row->network_agent_id' data-provider_class_id='$row->provider_class_id'
 				data-network='$row->network' data-member_code='$row->code_membre' data-email='$row->email' data-phone='$row->phone' class='open-modal modif btn btn-success' data-target='#editModal'><i class='fa fa-edit'></i></button>";


			$list[] = $data;

		}

		$output = array(
			"draw" => $_POST['draw'],
			"recordsTotal" => $this->gu_model->countAll($_POST),
			"recordsFiltered" => $this->gu_model->countFiltered($_POST),
			"data" => $list,
		);

		// Output to JSON format
		echo json_encode($output);
	}

}
