2 // vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker:
3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2003 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Created: mar may 27 15:16:38 ART 2003
17 // | Author: Martin Marrese <mmarre@mecon.gov.ar>
18 // +----------------------------------------------------------------------+
27 require_once 'MECON/HTML/QuickForm.php';
29 //CREO LOS OBJETO NECESARIOS {{{
30 $SAMURAI = new Samurai($DB);
31 $FORM = new MECON_HTML_QuickForm ('permisos_abm','post','permisos-abm');
33 //AGREGO LOS ELEMENTOS DEL FORM {{{
34 $FORM->addElement ('header', 'cabecera', 'ABM Permisos');
35 $FORM->addElement ('hidden', 'id_permiso');
36 $FORM->addElement ('text' , 'desc_permiso', 'Descripcion', array('size'=>'50'));
37 $FORM->addElement ('static', 'responsable' , 'Responsable', $_SESSION['samurai']['login']);
38 $group[] = HTML_QuickForm::createElement('submit', 'aceptar' , 'Grabar');
39 $FORM->addGroup($group,'botones');
41 //AGREGO LAS REGLAS DE VALIDACION DE LOS ELEMENTOS {{{
42 $FORM->addRule('desc_permiso', 'El campo descripcion es obligatorio', 'required', '', 'client');
44 //CREO EL OBJETO PERMISO {{{
45 //Obtengo el id del permiso.
46 $idPermiso =& $FORM->getElement('id_permiso');
47 if (isset($_GET['accion']) && $_GET['accion'] != '') {
48 //Viene en el get es -> modificar o eliminar, me ocupo yo.
49 $id_permiso = $_GET['idPermiso'];
50 $idPermiso->setValue($id_permiso);
53 //Viene en el post, no me ocupo yo.
54 $id_permiso = $idPermiso->getValue();
56 $PERMISO = new Permiso ($DB, $id_permiso);
58 //SETEO LOS VALORES DE LOS ELEMENTOS DEL OBJETO FORM {{{
59 if (isset($_GET['accion']) && $_GET['accion'] != '') {
60 //MODIFICACION -> agrego la info a los elementos
61 $desc_permiso =& $FORM->getElement ('desc_permiso');
62 $responsable =& $FORM->getElement ('responsable' );
63 $group =& $FORM->getElement ('botones' );
64 $group =& $group->getElements('aceptar' );
65 $aceptar =& $group[0];
67 $desc_permiso->setValue ($PERMISO->getDescripcion());
69 if ($PERMISO->getResponsable() != '') {
70 $responsable->setValue($PERMISO->getResponsable());
73 $aceptar->setValue('Modificar');
75 //ELIMINACION -> modifico el valor del boton
76 if ($_GET['accion'] == 'e') {
77 $aceptar->setValue('Eliminar');
82 //VALIDO EL FORMULARIO {{{
83 if ($FORM->validate()) {
84 $desc_permiso =& $FORM->getElement ('desc_permiso');
85 $responsable =& $FORM->getElement ('responsable' );
86 $group =& $FORM->getElement ('botones' );
87 $group =& $group->getElements('aceptar' );
88 $aceptar =& $group[0];
90 $PERMISO->setDescripcion($desc_permiso->getValue());
91 $PERMISO->setResponsable($responsable->_text); //TODO URGENTE Modificar esto. No tiene metodo static::getValue()
93 //Verifico si se produjo algun error
94 $res = $PERMISO->guardarDatos($aceptar->getValue());
96 if (PEAR::isError($res)) {
98 $group[] = HTML_QuickForm::createElement('static', 'error' , 'Error:', $res->getMessage());
99 $group[] = HTML_QuickForm::createElement('submit', 'aceptar' , $aceptar->getValue());
100 $FORM->removeElement('botones');
101 $FORM->addGroup($group,'botones', '', '<br>');
105 header('Location: permisos');
110 //DIBUJO LA PAGINA {{{
111 $MARCO = new Marco ('../../conf/confSecciones.php');
112 $MARCO->addTitle('ABM Permisos');
113 $MARCO->addBody($FORM);