+<?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: mar may 27 15:16:38 ART 2003
+// | Author: Martin Marrese <mmarre@mecon.gov.ar>
+// +----------------------------------------------------------------------+
+//
+// $Id$
+// $Author$
+// $URL$
+// $Date$
+// $Rev$
+//
+
+ require_once 'MECON/HTML/QuickForm.php';
+
+//CREO LOS OBJETO NECESARIOS {{{
+ $SAMURAI = new Samurai($DB);
+ $FORM = new MECON_HTML_QuickForm ('permisos_abm','post','permisos-abm');
+// }}}
+//AGREGO LOS ELEMENTOS DEL FORM {{{
+ $FORM->addElement ('header', 'cabecera', 'ABM Permisos');
+ $FORM->addElement ('hidden', 'id_permiso');
+ $FORM->addElement ('text' , 'desc_permiso', 'Descripcion', array('size'=>'50'));
+ $FORM->addElement ('static', 'responsable' , 'Responsable', $_SESSION['samurai']['login']);
+ $group[] = HTML_QuickForm::createElement('submit', 'aceptar' , 'Grabar');
+ $FORM->addGroup($group,'botones');
+// }}}
+//AGREGO LAS REGLAS DE VALIDACION DE LOS ELEMENTOS {{{
+ $FORM->addRule('desc_permiso', 'El campo descripcion es obligatorio', 'required', '', 'client');
+// }}}
+//CREO EL OBJETO PERMISO {{{
+ //Obtengo el id del permiso.
+ $idPermiso =& $FORM->getElement('id_permiso');
+ if (isset($_GET['accion']) && $_GET['accion'] != '') {
+ //Viene en el get es -> modificar o eliminar, me ocupo yo.
+ $id_permiso = $_GET['idPermiso'];
+ $idPermiso->setValue($id_permiso);
+ }
+ else {
+ //Viene en el post, no me ocupo yo.
+ $id_permiso = $idPermiso->getValue();
+ }
+ $PERMISO = new Permiso ($DB, $id_permiso);
+// }}}
+//SETEO LOS VALORES DE LOS ELEMENTOS DEL OBJETO FORM {{{
+ if (isset($_GET['accion']) && $_GET['accion'] != '') {
+ //MODIFICACION -> agrego la info a los elementos
+ $desc_permiso =& $FORM->getElement ('desc_permiso');
+ $responsable =& $FORM->getElement ('responsable' );
+ $group =& $FORM->getElement ('botones' );
+ $group =& $group->getElements('aceptar' );
+ $aceptar =& $group[0];
+
+ $desc_permiso->setValue ($PERMISO->getDescripcion());
+
+ if ($PERMISO->getResponsable() != '') {
+ $responsable->setValue($PERMISO->getResponsable());
+ }
+
+ $aceptar->setValue('Modificar');
+
+ //ELIMINACION -> modifico el valor del boton
+ if ($_GET['accion'] == 'e') {
+ $aceptar->setValue('Eliminar');
+ $FORM->freeze();
+ }
+ }
+// }}}
+//VALIDO EL FORMULARIO {{{
+ if ($FORM->validate()) {
+ $desc_permiso =& $FORM->getElement ('desc_permiso');
+ $responsable =& $FORM->getElement ('responsable' );
+ $group =& $FORM->getElement ('botones' );
+ $group =& $group->getElements('aceptar' );
+ $aceptar =& $group[0];
+
+ $PERMISO->setDescripcion($desc_permiso->getValue());
+ $PERMISO->setResponsable($responsable->_text); //TODO URGENTE Modificar esto. No tiene metodo static::getValue()
+
+ //Verifico si se produjo algun error
+ $res = $PERMISO->guardarDatos($aceptar->getValue());
+
+ if (PEAR::isError($res)) {
+ $group = array ();
+ $group[] = HTML_QuickForm::createElement('static', 'error' , 'Error:', $res->getMessage());
+ $group[] = HTML_QuickForm::createElement('submit', 'aceptar' , $aceptar->getValue());
+ $FORM->removeElement('botones');
+ $FORM->addGroup($group,'botones', '', '<br>');
+ }
+ else {
+ $FORM->freeze();
+ header('Location: permisos');
+ }
+ }
+// }}}
+
+//DIBUJO LA PAGINA {{{
+ $MARCO = new Marco ('../../conf/confSecciones.php');
+ $MARCO->addTitle('ABM Permisos');
+ $MARCO->addBody($FORM);
+ $MARCO->display();
+//
+//FIN
+?>