<?php
	require_once 'RemoteAgent.php';
    require_once RUTA_APP.'Conexion.php';
	class RemoteAgentDatos{
		public static function getRemoteAgentById($id){
		
		}
		public static function getRemoteAgentsByCliente($cliente, $texto, $pagina, $limite){
			
		}
		public static function getRemoteAgents($texto, $pagina, $limite){
			
		}
		public static function countRemoteAgentsByCliente($cliente, $texto){
			
		}
		public static function countRemoteAgents($texto){
			
		}
		public static function addRemoteAgent($remoteAgent){
			$con = getConnection();
			$ret = -1;
			$query = "INSERT INTO vicidial_remote_agents(user_start,number_of_lines,server_ip,conf_exten,status,campaign_id) VALUES(
				'".limpia($remoteAgent->getUserStart())."',
				'".limpia($remoteAgent->getLineas())."',
				'".limpia(SERVER_IP_REAL)."',
				'".limpia($remoteAgent->getExtension())."',
				'".limpia($remoteAgent->getStatus())."',
				'".limpia($remoteAgent->getCampana())."'
			)";
			if(sv_mysqli_query($con,$query))$ret = 0;
			sv_mysqli_close($con);
			return $ret;
		}		
		public static function editRemoteAgent($remoteAgent){
			
		}
		public static function countLinesByCliente($cliente){
			$con = getConnection();
			$resp = 0;
			$query = "SELECT SUM(number_of_lines) AS SUMA FROM vicidial_remote_agents WHERE campaign_id IN (SELECT campaign_id FROM vicidial_campaigns WHERE user_group = '".limpia($cliente->getId())."')";
			if($result = sv_mysqli_query($con, $query)){
				if($row = sv_mysqli_fetch_array($result)){
					$resp = $row["SUMA"];
				}
			}
			sv_mysqli_close($con);
			return $resp;
		}
		public static function deleteRemoteAgent($remoteAgent){
			
		}
	}
?>