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

//Validaciones para el modelo de usuarios
class Nuevo_lib {

	public function __construct(){
		$this->CI =& get_instance();//para acceder a la instancia que carga la libreria

		$this->CI->load->model('principal/Model_nuevo','mn');

		$this->CI->load->helper('email');
	}

	public function norep($registro,$campo){
		$value = str_replace(' ', '', $registro[$campo]);
		$query = $this->CI->db->query("SELECT cp.pk_cat_personal,cp.nombre,cp.apat,cp.amat,cg.correo,cp.usuario 
										FROM cat_personal cp, cat_generales cg 
										WHERE cp.fk_cat_generales=cg.pk_cat_generales and $campo='".$value."'");
		//print_r($query);
		//$this->CI->db->where($campo,$registro[$campo]);
		//$query = $this->CI->db->get('cat_personal');

		if ($query->num_rows() > 0 AND (!isset($registro['pk_cat_personal']) OR ($registro['pk_cat_personal'] != $query->row('pk_cat_personal')))) 
			return FALSE;
		else
			return TRUE;
	}

	public function emailok($email){
		if(valid_email($email))
			return TRUE;
		else
			return FALSE;
	}

	public function normaliza($cadena){
	    $originales = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕ';
	    $modificadas = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr';
	    $cadena = utf8_decode($cadena);
	    $cadena = strtr($cadena, utf8_decode($originales), $modificadas);
	    $cadena = strtolower($cadena);
	    $cadena = str_replace(","," ",$cadena);
		$cadena = str_replace(".","",$cadena);
	    return utf8_encode($cadena);
	}

}

?>