abc = new Core_abc("clientes"); $this->abcUser = new Core_abc("usuarios"); $this->encrypt = new Core_encrypt(); $this->json = new Core_json(); $this->validador = new core_validador(); } public function __call($method, $args){ try{ if (substr_count(strtolower($method), "findby") != 1){ throw new Exception("Metodo no conocido"); } if (count($args) < 1 || count($args) > 2){ throw new Exception("Numero de Argumentos incorrecto."); } echo $field = substr($method, 6); $fields = $this->abc->viewFields(); $bandera = false; $i = 0; while (!$bandera && $i < count($fields["fields"])){ if ($fields["fields"][$i]["Field"] == $field){ $bandera = true; } $i++; } if ($bandera){ return $this->find($field, $args[0], $args[1]); }else{ throw new Exception("Tipo de busqueda Incorrecto"); } }catch (Exception $e){ return array("status" => false, "msg" => $e->getMessage()); } } private function find($field, $value, $like){ if ($like){ $tmp = str_replace("_", $value, $like); $where = "{$field} LIKE '{$tmp}'"; }else{ $where = "{$field} = '$value'"; } echo $where; return $this->abc->select(true,array("*"), $where, false, array("{$field} asc"), false); } public function addFisica($nombre, $paterno, $materno, $email, $nombrecomercial, $requirefactura, $rfc, $usuario, $contrasena){ try{ if (empty($nombre)){ throw new Exception("No se especifico el nombre."); } if (empty($paterno)){ throw new Exception("No se especifico el apellido paterno."); } if (empty($materno)){ $materno = "-"; } if (empty($email)){ throw new Exception("No se especifico el correo electronico."); } if (empty($nombrecomercial)){ $nombrecomercial = "-"; } if (empty($rfc)){ $rfc = "-"; } if (empty($usuario)){ throw new Exception("No se especifico el usuario."); } if (empty($contrasena)){ throw new Exception("No se especifico la contraƱa."); } if ($this->validador->comprobar_email($email)){ throw new Exception("Correo no valido."); } $nombre = $this->validador->sanitize($nombre, true); $paterno = $this->validador->sanitize($paterno, true); $materno = $this->validador->sanitize($materno, true); $email = $this->validador->sanitize($email, true); $nombrecomercial = $this->validador->sanitize($nombrecomercial, true); $requirefactura = $this->validador->sanitize($requirefactura, true); $rfc = $this->validador->sanitize($rfc, true); $usuario = $this->validador->sanitize($usuario, true); $contrasena = $this->validador->sanitize($contrasena, true); $tmp = $this->abcUser->select(true,array("usuario"), "usuario = '{$usuario}' and activo = 'S"); if ($tmp["total"] > 0){ throw new Exception("Ya existe ese nombre de usuario registrado."); } $tmp = $this->abc->insert(array("nombre" => $nombre, "paterno" => $paterno, "materno" => $materno, "email" => $email, "nombrecomercial" => $nombrecomercial, "requierefactura" => $requirefactura, "rfc" => $rfc, "tipopersona" => 'F')); if ($tmp["rows"] < 1){ throw new Exception("No se realizo el registro de cliente."); } $clienteKey = $tmp["id"]; $contrasena = sha1($contrasena); $tmp = $this->abcUser->insert(array("usuario" => $usuario, "contrasena" => $contrasena, "clienteFK" => $clienteKey, "tipo" => "A")); $clienteKey = $this->encrypt->encode($clienteKey, $this->key); echo $this->json->encode(array("status" => true, "msg" => $clienteKey)); } catch (Exception $e){ echo $this->json->encode(array("status" => false, "msg" => $e->getMessage())); } } public function update(){ } public function active ($active, $clienteKey){ try{ if ($active != 'S' && $active != 'N'){ throw new Exception("Opcion no valida"); } $active = $this->validador->sanitize($active, true); $clienteKey = $this->encrypt->decode($clienteKey, $this->key); $tmp = $this->abc->active((($active == "S")?true:false), "clienteKey = '{$clienteKey}'"); if ($tmp["rows"] < 1){ throw new Exception("La accion no fue ralizada."); } echo $this->json->encode(array("status" => true, "msg" => "Accion realizada exitosamente")); }catch (Exception $e){ echo $this->json->encode(array("status" => false, "msg" => $e->getMessage())); } } public function info($clienteKey){ try{ $clienteKey = $this->encrypt->decode($clienteKey, $this->key); $tmp = $this->abc->select(true,array("clienteKey","nombre", "paterno", "materno", "razonsocial","email", "nombrecomercial", "requierefactura", "tipopersona", "rfc", "activo"), "clienteKey = '{$clienteKey}'"); if (!$tmp["status"]){ throw new Exception($tmp["msg"]); } if ($tmp["total"] == 0){ throw new Exception("No se encontraron conincidencias."); } for ($i = 0; $i < $tmp["total"]; $i++){ $tmp["rows"][$i]["clienteKey"] = $this->encrypt->encode($tmp["rows"][$i]["clienteKey"], $this->key); } $tmp["rows"] = $this->validador->sanitize($tmp["rows"], false); echo $this->json->encode($tmp["rows"]); }catch (Exception $e){ echo $this->json->encode(array("status" => false, "msg" => $e->getMessage())); } } public function listado($active = 'S'){ try{ if ($active != 'S' && $active != 'N'){ throw new Exception("Opcion no valida"); } $active = $this->validador->sanitize($active, true); $tmp = $this->abc->select(true,array("clienteKey", "CONCAT_WS(' ', nombre, paterno, materno) nombre, razonsocial"), "activo = '$active'"); if (!$tmp["status"]){ throw new Exception($tmp["msg"]); } if ($tmp["total"] == 0){ throw new Exception("No se encontraron conincidencias."); } for ($i = 0; $i < $tmp["total"]; $i++){ $tmp["rows"][$i]["clienteKey"] = $this->encrypt->encode($tmp["rows"][$i]["clienteKey"], $this->key); } $tmp["rows"] = $this->validador->sanitize($tmp["rows"], false); echo $this->json->encode($tmp["rows"]); }catch (Exception $e){ echo $this->json->encode(array("status" => false, "msg" => $e->getMessage())); } } }