+<?php
+// vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker:
+// +----------------------------------------------------------------------+
+// | PHP Version 4 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2003 The PHP Group |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/2_02.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Created: mié jul 16 13:37:33 ART 2003
+// | Author: Martin Marrese <mmarre@mecon.gov.ar>
+// +----------------------------------------------------------------------+
+//
+// $Id$
+//
+
+//REQUIRE ONCE {{{
+ //MECON {{{
+ require_once 'MECON/HTML/QuickForm.php';
+ require_once 'MECON/HTML/Tabla.php';
+ require_once 'MECON/HTML/Error.php';
+ //}}}
+ //SAMURAI {{{
+ require_once 'SAMURAI/Perfil.php';
+ require_once 'SAMURAI/Usuario.php';
+ require_once 'SAMURAI/Sistema.php';
+ //}}}
+ require_once 'HTML/Image.php';
+// }}}
+//VEO SI HAY QUE ELEGIR EN QUE SISTEMA TRABAJAR {{{
+if (!@$_SESSION['samurai']['id_sistema'] || !@$_SESSION['samurai']['login']) {
+ header('Location: ./../sel-sistema');
+}
+// }}}
+//CREO LOS OBJETOS NECESARIOS {{{
+ if (@$_GET['login']) {
+ $login = $_GET['login'];
+ $validar = 0;
+ }
+ else {
+ $validar = 1;
+ $login = null;
+ }
+ $TABLA = new Tabla ('cellspacing=0');
+ $FORM = new MECON_HTML_QuickForm ('usuarios_abm','post','usuarios-abm');
+ $SISTEMA = new SAMURAI_Sistema($DB, $_SESSION['samurai']['id_sistema']);
+ $USUARIO = new SAMURAI_Usuario($DB, $login);
+// }}}
+//OBTENGO LOS DATOS DE LA BASE {{{
+ $tmps = SAMURAI_Perfil::getPerfiles($DB, null, $_SESSION['samurai']['id_sistema']);
+ foreach ($tmps as $tmp) {
+ $PERFILES[$tmp->getId()] = $tmp->getDescripcion();
+ }
+//}}}
+//AGREGO LOS DATOS A LAS TABLAS {{{
+ $imagen = new HTML_Image('/MECON/images/vinetas_flecha_doble.gif');
+ $row = array ($imagen->toHtml().' <b>SISTEMA: '.$SISTEMA->getNombre().'</b>');
+ $TABLA->addRow($row,'align=left');
+//}}}
+//AGREGO LOS ELEMENTOS DEL FORM {{{
+ $FORM->addElement ('header', 'cabecera' , 'ABM Usuarios');
+ if ($login) { //Si esta el login solo permito modificar los perfiles asociados
+ $FORM->addElement ('static', 'login2', 'Login' , $login );
+ $FORM->addElement ('hidden', 'login' , $login );
+ $FORM->addElement ('static', 'nombre', 'Nombre', $USUARIO->getNombre());
+ }
+ else {
+ $FORM->addElement ('text' , 'login' , 'Login' , array( 'value' => $login , 'size' => '20'));
+ }
+ $FORM->addElement ('select', 'perfiles' , 'Perfiles', $PERFILES, array('size' => '5', 'multiple' => 'true'));
+ $FORM->addElement ('hidden', 'responsable', $_SESSION['samurai']['login']);
+ $group[] = HTML_QuickForm::createElement('submit', 'aceptar' , 'Grabar');
+ $group[] = HTML_QuickForm::createElement('submit', 'cancelar', 'Cancelar', array ('onClick' => 'javascript:history.go(-1);return true;'));
+ $FORM->addGroup($group,'botones');
+// }}}
+//AGREO LAS REGLAS DE VALIDACION {{{
+ if (@$validar) {
+ $FORM->addRule ('login', 'Se debe ingresar el login del usuario', 'required');
+ }
+ $FORM->addRule ('perfiles', 'Se debe seleccionar al menos un perfil', 'required');
+// }}}
+//SETEO LOS PERFILES SELECCIONADOS {{{
+ if (isset($_GET['accion']) && $_GET['accion'] != '') {
+ $perfiles =& $FORM->getElement ('perfiles');
+ $group =& $FORM->getElement ('botones' );
+ $group =& $group->getElements('aceptar' );
+ $aceptar =& $group[0];
+
+ $perfiles->setSelected($USUARIO->getPerfiles());
+
+ //Modifico el valor del boton
+ $aceptar->setValue('Modificar');
+
+ //ELIMINACION -> modifico el valor del boton
+ if ($_GET['accion'] == 'e') {
+ $aceptar->setValue('Eliminar');
+ $FORM->freeze();
+ }
+ }
+// }}}
+//VALIDO EL FORMULARIO {{{
+ if ($FORM->validate()) {
+ // VEO SI SE CANCELO {{{
+ $botones = $FORM->getSubmitValue('botones');
+ if (@$botones['cancelar']) {
+ header('Location: perfiles');
+ }
+ // }}}
+ else {
+ $login2 =& $FORM->getElement ('login' );
+ $nombre =& $FORM->getElement ('nombre' );
+ $perfiles =& $FORM->getElement ('perfiles');
+ $group =& $FORM->getElement ('botones' );
+ $group =& $group->getElements('aceptar' );
+ $aceptar =& $group[0];
+ $res = '';
+
+ if ($login) {
+ $login3 = $login2->_text;
+ }
+ else {
+ $login3 = $login2->getValue();
+ }
+ $USUARIO->setLogin($login3);
+ $res = $USUARIO->verificarLogin();
+ if (PEAR::isError($res)) {
+ $ERROR = new MECON_HTML_Error($res->getMessage());
+ }
+ else {
+ $USUARIO->setPerfiles($perfiles->getSelected());
+
+ $res = $USUARIO->guardarDatos($aceptar->getValue());
+
+ if (PEAR::isError($res)) {
+ $ERROR = new MECON_HTML_Error($res->getMessage());
+ if ($aceptar->getValue() == 'Eliminar') {
+ $FORM->freeze();
+ }
+ }
+ else {
+ $FORM->freeze();
+ header('Location: usuarios');
+ }
+ }
+ }
+ }
+// }}}
+//DIBUJO LA PAGINA {{{
+ $MARCO = new Marco ('../../conf/confSecciones.php');
+ $MARCO->addBody($TABLA);
+ if (isset($ERROR)) {
+ $MARCO->addBody($ERROR);
+ }
+ $MARCO->addBody($FORM);
+ $MARCO->display();
+// }}}
+//FIN
+?>