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('button', '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');
82 $aceptar->updateAttributes(array ('onClick' => 'javascript:if (confirm(\'¿Esta Seguro?\')) return true;return false;'));
87 //VALIDO EL FORMULARIO {{{
88 if ($FORM->validate()) {
89 // VEO SI SE CANCELO {{{
90 $botones = $FORM->getSubmitValue('botones');
91 if (@$botones['cancelar']) {
92 header('Location: permisos');
95 $desc_permiso =& $FORM->getElement ('desc_permiso');
96 $responsable =& $FORM->getElement ('responsable' );
97 $group =& $FORM->getElement ('botones' );
98 $group =& $group->getElements('aceptar' );
99 $aceptar =& $group[0];
101 $PERMISO->setDescripcion($desc_permiso->getValue());
102 $PERMISO->setResponsable($responsable->getValue());
104 //Verifico si se produjo algun error
105 $res = $PERMISO->guardarDatos($aceptar->getValue());
107 if (PEAR::isError($res)) {
108 $ERROR = new MECON_HTML_Error(traducir($res->getMessage()));
109 if ($aceptar->getValue() == 'Eliminar') {
115 header('Location: permisos');
119 //DIBUJO LA PAGINA {{{
120 $MARCO = new Marco ('../../conf/confSecciones.php');
121 $MARCO->addTitle('ABM Permisos');
123 $MARCO->addBody($ERROR);
125 $MARCO->addBody($FORM);