From d244a130edade844993478bace7a45fd556e85c8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mart=C3=ADn=20Marrese?= Date: Wed, 12 Mar 2003 16:42:58 +0000 Subject: [PATCH] Reacomodamiento de directorios Sin cambios funcionales --- samurai_lib/{src => php}/Samurai/Perm.php | 9 +- .../{src => php}/Samurai/Perm/db_Conf.php | 0 .../{src => php}/Samurai/Perm/sql_Conf.php | 0 samurai_lib/php/prueba.php | 23 +++ samurai_lib/php/samurai_lib.php | 160 ++++++++++++++++++ samurai_lib/php/samurai_lib_db_conf.inc | 9 + samurai_lib/php/samurai_lib_sql.inc | 12 ++ samurai_lib/{src => test}/prueba.php | 2 +- 8 files changed, 207 insertions(+), 8 deletions(-) rename samurai_lib/{src => php}/Samurai/Perm.php (95%) rename samurai_lib/{src => php}/Samurai/Perm/db_Conf.php (100%) rename samurai_lib/{src => php}/Samurai/Perm/sql_Conf.php (100%) create mode 100644 samurai_lib/php/prueba.php create mode 100644 samurai_lib/php/samurai_lib.php create mode 100644 samurai_lib/php/samurai_lib_db_conf.inc create mode 100644 samurai_lib/php/samurai_lib_sql.inc rename samurai_lib/{src => test}/prueba.php (93%) diff --git a/samurai_lib/src/Samurai/Perm.php b/samurai_lib/php/Samurai/Perm.php similarity index 95% rename from samurai_lib/src/Samurai/Perm.php rename to samurai_lib/php/Samurai/Perm.php index b4885fa..c122317 100644 --- a/samurai_lib/src/Samurai/Perm.php +++ b/samurai_lib/php/Samurai/Perm.php @@ -161,14 +161,9 @@ class SA_Perm extends PEAR { function tieneUn($permiso) { $result = true; //Asumo que no va a fallar - if (!isset($permiso)) { //Tiene que pasar un permiso si o si - $result = false; - } - else { - if (!in_array($permiso, $this->permisos)) { //Si no esta en el array, no tiene el permiso + if (!in_array($permiso, $this->permisos)) { //Si no esta en el array, no tiene el permiso $result = false; } - } return $result; } @@ -203,7 +198,7 @@ class SA_Perm extends PEAR { */ function _conectarDB() { - $datos = include 'include/samurai_lib_db_conf.inc'; + $datos = include 'Perm/db_Conf.php'; $dsn = $datos['db_type']."://".$datos['db_user'].":".$datos['db_pass']."@".$datos['db_host']."/".$datos['db_name']; $db = DB::connect($dsn, true); //Quiero que la conexion sea persistente if (DB::isError($db)) { diff --git a/samurai_lib/src/Samurai/Perm/db_Conf.php b/samurai_lib/php/Samurai/Perm/db_Conf.php similarity index 100% rename from samurai_lib/src/Samurai/Perm/db_Conf.php rename to samurai_lib/php/Samurai/Perm/db_Conf.php diff --git a/samurai_lib/src/Samurai/Perm/sql_Conf.php b/samurai_lib/php/Samurai/Perm/sql_Conf.php similarity index 100% rename from samurai_lib/src/Samurai/Perm/sql_Conf.php rename to samurai_lib/php/Samurai/Perm/sql_Conf.php diff --git a/samurai_lib/php/prueba.php b/samurai_lib/php/prueba.php new file mode 100644 index 0000000..55aa828 --- /dev/null +++ b/samurai_lib/php/prueba.php @@ -0,0 +1,23 @@ +"; +print "
"; + +$pp = new SA_Perm(28924563); + +var_dump($pp); + +print "
"; +print "
"; + +printf("%s",$pp->nrodoc); + +var_dump($pp->SQL); + +?> diff --git a/samurai_lib/php/samurai_lib.php b/samurai_lib/php/samurai_lib.php new file mode 100644 index 0000000..cde41ed --- /dev/null +++ b/samurai_lib/php/samurai_lib.php @@ -0,0 +1,160 @@ + | +// +--------------------------------------------------------------------+ +// +// $Id$ +// +// $URL$ +// $Rev$ +// $Date$ +// $Author$ +// + +require_once 'PEAR.php'; +require_once 'DB.php'; + +/** + * Manejo de permisos. + * + * Libreria para le manejo de los permisos. Basada en la lase HE_Perm de + * Leandro Lucarella + * + * @package SA_Perm + * @version $Rev$ + * @author $Author$ + */ +class SA_Perm extends PEAR { + + /** + * Identificacion del usuario. + * + * @var int(11) nrodoc + */ + var $nrodoc; + + /** + * Login del usuario + * + * @var string login + */ + var $login; + + /** + * Consultas SQL. + * + * @var array SQL + */ + var $SQL; + + + /** + * Conexion a la Base de Datos . + * + * @var $DB + */ + var $DB; + + /** + * Identificacion del sistema + * + * @var $sistema + */ + var $sistema + + /** + * Constructor. + * + * @param int $nrodoc Numero de documento del usuario. + * @param string $login Login del usuario de la forma @ + * @param int $sistema Identificacion del sistema (id_sistema) + * + * @return bool true si esta nrodoc, false en caso contrario + * + * @access public + */ + function SA_Perm($nrodoc = null, $login = null, $sistema = null) + { + $creacion = false; //Asumo que va a fallar + if (isset($nrodoc) && isset($sistema) && isset($login)) { + $this->nrodoc = $nrodoc; + $this->sistema = $sistema; + $this->login = $login; + $this->SQL = include 'samurai_lib_sql.inc'; + $this->DB = $this->_SA_conectarDB(); + $creacion = true; + } + return $creacion; + } + + /** + * Verifica los permisos de un usuario + * + * Compara los permisos que tiene un usuario en relacion a los + * pasados como parametro. Devuelve true si cumple con todos los + * permisos, en caso contrario devuelve false + * + * @param array permisos + * + * @return bool + * + * @access public + */ + function SA_verifPerm () + { + $args = func_get_args(); + $result = true; //Asumo que no va a fallar + + if (!count($args)) { + $result = false; + } + else { + //Obtengo los perfiles de un usuario {{{ + $sql = $this->SQL['obtener_perfil_usuario']; + $re = $this->DB->prepare($sql); + $re = $this->DB->execute($this->login, $this->sistema); + // }}} + + // Por cada perfil, busco sus permisos y los comparo con los pasados + // por el argumento {{{ + while ($res = $re->fetchRow(DB_FETCHMODE_ASSOC)) { + $sql = $this->SQL['obtener_permisos_perfil']; + $re = $this->DB->prepare($sql); + $re = $this->DB->execute($res['id_perfil'], $this->sistema); + //TODO: Verificar que este tomando bien los datos de la base + } + /// }}} + } + return $result; + } + + /** + * Conecta el objeto a la base de datos, segun lo especificado + * en samurai_lib_dc_conf.inc. + * + * @return db conexion hecha + * + * @access private + */ + function _SA_conectarDB () + { + $datos = include 'samurai_lib_db_conf.inc'; + $dsn = $datos['db_type']."://".$datos['db_user'].":".$datos['db_pass']."@".$datos['db_host']."/".$datos['db_name']; + $db = DB::connect($dsn, true); //Quiero que la conexion sea persistente + if (DB::isError($db)) { + die($db->getMessage()); + } + return $db; + } + + //Fin Clase +} +?> diff --git a/samurai_lib/php/samurai_lib_db_conf.inc b/samurai_lib/php/samurai_lib_db_conf.inc new file mode 100644 index 0000000..010be67 --- /dev/null +++ b/samurai_lib/php/samurai_lib_db_conf.inc @@ -0,0 +1,9 @@ + 'mysql' , + 'db_user' => 'intranet' , + 'db_pass' => 'intranet' , + 'db_host' => 'localhost', + 'db_name' => 'samurai' + ) +?> diff --git a/samurai_lib/php/samurai_lib_sql.inc b/samurai_lib/php/samurai_lib_sql.inc new file mode 100644 index 0000000..3057dea --- /dev/null +++ b/samurai_lib/php/samurai_lib_sql.inc @@ -0,0 +1,12 @@ + 'SELECT psu.login AS login, psu.id_perfil AS id_perfil, psu.id_sistema AS id_sistema + FROM perfil_sist_usuario AS psu + WHERE login = ? AND id_sistema = ? + ORDER BY id_perfil DESC', + 'obtener_permisos_perfil' => 'SELECT e.desc_permiso AS desc_permiso + FROM perm_perfil_sist AS pps, permiso AS e + WHERE pps.id_perfil = ? AND pps.id_sistema = ? AND pps.id_permiso = e.id_permiso + ORDER BY e.id_permiso DESC' + ); +?> diff --git a/samurai_lib/src/prueba.php b/samurai_lib/test/prueba.php similarity index 93% rename from samurai_lib/src/prueba.php rename to samurai_lib/test/prueba.php index a47e1f7..e9993b6 100644 --- a/samurai_lib/src/prueba.php +++ b/samurai_lib/test/prueba.php @@ -1,6 +1,6 @@ "; -- 2.43.0