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 // +----------------------------------------------------------------------+
25 require_once 'MECON/HTML/QuickForm.php';
26 require_once 'MECON/HTML/Tabla.php';
27 require_once 'MECON/HTML/Error.php';
30 require_once 'SAMURAI/Permiso.php';
33 //CREO LOS OBJETO NECESARIOS {{{
34 $FORM = new MECON_HTML_QuickForm ('permisos_abm','post','permisos-abm');
36 //AGREGO LOS ELEMENTOS DEL FORM {{{
37 $FORM->addElement ('header', 'cabecera', 'ABM Permisos');
38 $FORM->addElement ('hidden', 'id_permiso');
39 $FORM->addElement ('text' , 'desc_permiso', 'Descripcion', array('size'=>'50'));
40 $FORM->addElement ('hidden', 'responsable' , $_SESSION['samurai']['login']);
41 $group[] = HTML_QuickForm::createElement('submit', 'aceptar' , 'Grabar');
42 $group[] = HTML_QuickForm::createElement('submit', 'cancelar', 'Cancelar', array ('onClick' => 'javascript:history.go(-1);return true;'));
43 $FORM->addGroup($group,'botones');
45 //AGREGO LAS REGLAS DE VALIDACION DE LOS ELEMENTOS {{{
46 $FORM->addRule('desc_permiso', 'El campo descripcion es obligatorio', 'required', '', 'client');
48 //CREO EL OBJETO PERMISO {{{
49 //Obtengo el id del permiso.
50 $idPermiso =& $FORM->getElement('id_permiso');
51 if (isset($_GET['accion']) && $_GET['accion'] != '') {
52 //Viene en el get es -> modificar o eliminar, me ocupo yo.
53 $id_permiso = $_GET['idPermiso'];
54 $idPermiso->setValue($id_permiso);
57 //Viene en el post, no me ocupo yo.
58 $id_permiso = $idPermiso->getValue();
60 $PERMISO = new SAMURAI_Permiso ($DB, $id_permiso);
62 //SETEO LOS VALORES DE LOS ELEMENTOS DEL OBJETO FORM {{{
63 if (isset($_GET['accion']) && $_GET['accion'] != '') {
64 //MODIFICACION -> agrego la info a los elementos
65 $desc_permiso =& $FORM->getElement ('desc_permiso');
66 $responsable =& $FORM->getElement ('responsable' );
67 $group =& $FORM->getElement ('botones' );
68 $group =& $group->getElements('aceptar' );
69 $aceptar =& $group[0];
71 $desc_permiso->setValue ($PERMISO->getDescripcion());
73 if ($PERMISO->getResponsable() != '') {
74 $responsable->setValue($PERMISO->getResponsable());
77 $aceptar->setValue('Modificar');
79 //ELIMINACION -> modifico el valor del boton
80 if ($_GET['accion'] == 'e') {
81 $aceptar->setValue('Eliminar');
86 //VALIDO EL FORMULARIO {{{
87 if ($FORM->validate()) {
88 // VEO SI SE CANCELO {{{
89 $botones = $FORM->getSubmitValue('botones');
90 if (@$botones['cancelar']) {
91 header('Location: perfiles');
94 $desc_permiso =& $FORM->getElement ('desc_permiso');
95 $responsable =& $FORM->getElement ('responsable' );
96 $group =& $FORM->getElement ('botones' );
97 $group =& $group->getElements('aceptar' );
98 $aceptar =& $group[0];
100 $PERMISO->setDescripcion($desc_permiso->getValue());
101 $PERMISO->setResponsable($responsable->getValue());
103 //Verifico si se produjo algun error
104 $res = $PERMISO->guardarDatos($aceptar->getValue());
106 if (PEAR::isError($res)) {
107 $ERROR = new MECON_HTML_Error($res->getMessage());
108 if ($aceptar->getValue() == 'Eliminar') {
114 header('Location: permisos');
118 //DIBUJO LA PAGINA {{{
119 $MARCO = new Marco ('../../conf/confSecciones.php');
120 $MARCO->addTitle('ABM Permisos');
122 $MARCO->addBody($ERROR);
124 $MARCO->addBody($FORM);