<?php 
/*Libreria de La Rojeña Don Antonio*/
class lib{
private $url_webservice = '';

function __construct($url) {

	$this->url_webservice = $url;
	// echo $this->url_webservice;
}
	public function webservice_post($data_array){
		$json_data = json_encode($data_array);
			// echo $this->url_webservice;
		try {
			$ch = curl_init($this->url_webservice);
			 if (FALSE === $ch)
		        throw new Exception('failed to initialize');
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data_array));
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			$result = curl_exec($ch);
			if (FALSE === $result)
		        throw new Exception(curl_error($ch), curl_errno($ch));
			curl_close($ch);
			return json_decode($result);
		} catch(Exception $e) {
		    // trigger_error(sprintf('Curl failed with error #%d: %s',$e->getCode(), $e->getMessage()),E_USER_ERROR);
		    $obj = new stdClass();
		    $obj->userverify = false;
		    $obj->resp = "Error de conexión, Verifica la IP DEL SERVIDOR";
		    $data[0] = $obj;
		    return $data;
		}
	}/*webservice_post*/

	public function webservice_get($string){
		try {
			// Get cURL resource
			$curl = curl_init($this->url_webservice.'?'.$string);
			if (FALSE === $curl)
				throw new Exception('failed to initialize');			
			// Set some options - we are passing in a useragent too here
			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
			// curl_setopt_array($curl, array(
			//     CURLOPT_RETURNTRANSFER => 1,
			//     CURLOPT_USERAGENT => 'Codular Sample cURL Request'
			// ));
			// Send the request & save response to $resp
			$resp = curl_exec($curl);
			if (FALSE === $resp)
				throw new Exception(curl_error($curl), curl_errno($curl));
			// Close request to clear up some resources
			curl_close($curl);
			return json_decode($resp);
		} catch(Exception $e) {

			trigger_error(sprintf(
				'Curl failed with error #%d: %s',
				$e->getCode(), $e->getMessage()),
			E_USER_ERROR);
		}
	}/*webservice_get*/	

	public function setTokenCSRF(){
		return $_SESSION['FKey'] = uniqid(mt_rand(), true);
	}

	public function setFiltro($roles){
		if (!in_array($_SESSION['lrda_rol'], $roles)) {
		    header("Location: login.php");
		    exit;
		}
	}

	public function getToday(){
		date_default_timezone_set("America/Mexico_City");
		$datetime= date("Y-m-d H:i:s");
		return  $datetime;
	}
}/*lib*/
/*Libreria de la plataforma PierreFaure de Zamora*/
?>