1 <?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80 foldmethod=marker:
2 -------------------------------------------------------------------------------
5 -------------------------------------------------------------------------------
6 This file is part of YATTA!.
8 YATTA! is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your option)
13 YATTA! is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License; if not,
18 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 Boston, MA 02111-1307 USA
20 -------------------------------------------------------------------------------
21 Creado: mar ene 27 14:48:57 ART 2004
22 Autor: Martin Marrese <mmarre@mecon.gov.ar>
23 -------------------------------------------------------------------------------
25 -----------------------------------------------------------------------------*/
28 require_once 'MECON/HTML/QuickForm.php';
29 require_once 'MECON/HTML/Tabla.php';
30 require_once 'MECON/HTML/Error.php';
31 require_once 'MECON/HTML/Link.php';
32 require_once 'MECON/HTML/Image.php';
33 require_once 'MECON/HTML/Link.php';
36 require_once 'YATTA/Controlador.php';
37 require_once 'YATTA/ServidorDB.php';
41 //Obtengo los datos del get y del post {{{
42 $accion = (@$_REQUEST['accion']) ? $_REQUEST['accion'] : 'nuevo';
44 if (@$_REQUEST['_id']) {
45 $id = $_REQUEST['_id'];
47 elseif (@$_REQUEST['id']) {
48 $id = $_REQUEST['id'];
55 //Obtengo los datos del servidor {{{
56 $SERVIDOR =& new YATTA_ServidorDB();
59 $res = $SERVIDOR->buscar($DB, MECON_DBO_OR, 'nombre');
60 if (PEAR::isError($res)) {
61 trigger_error('Error: ' . $res->getMessage() . "\n", E_USER_ERROR);
63 $SERVIDOR->cargar($res);
67 //Creo los objetos necesarios {{{
68 $FORM =& new MECON_HTML_QuickForm('admin_servidores_abm', 'post',
69 'admin_servidores-abm');
70 $FORM->renderer->updateAttributes('width="400"');
73 //Armo el formulario {{{
75 $FORM->addElement('hidden', 'id', $id);
77 $FORM->addElement('hidden', 'accion', $accion.'2');
78 $FORM->addElement('header', 'cabecera', 'Datos del Servidor');
79 $nombre =& $FORM->addElement('text', 'nombre', 'Nombre', array('size'=>'30'));
80 $escala =& $FORM->addElement('text', 'escala', 'Escala', array('size'=>'3'));
81 $group[] =& HTML_QuickForm::createElement('submit', 'aceptar' , 'Aceptar');
82 $group[] =& HTML_QuickForm::createElement('submit', 'cancelar', 'Cancelar');
83 $FORM->addGroup($group,'botones');
85 if (@$accion == 'modificar') {
86 $nombre->setValue($SERVIDOR->nombre);
87 $escala->setValue($SERVIDOR->escala);
88 $group[0]->setValue('Modificar');
89 $group[0]->setName('modificar');
90 $FORM->addRule ('nombre', 'El nombre del servidor es obligatorio.', 'required');
91 $FORM->addRule ('escala', 'La escala del servidor es obligatoria', 'required');
93 elseif (@$accion == 'eliminar') {
94 $nombre->setValue($SERVIDOR->nombre);
95 $escala->setValue($SERVIDOR->escala);
96 $group[0]->setValue('Eliminar');
97 $group[0]->setName('eliminar');
101 $FORM->addRule ('nombre', 'El nombre del servidor es obligatorio.', 'required');
102 $FORM->addRule ('escala', 'La escala del servidor es obligatoria', 'required');
106 //Valido el formulario {{{
107 if ($FORM->validate()) {
108 $f_botones = $FORM->getSubmitValue('botones');
110 if (@$f_botones['cancelar']) {
111 header ('location: admin_servidores');
116 elseif (@$f_botones['aceptar']) {
117 $SERVIDOR->nombre = $nombre->getValue();
118 $SERVIDOR->escala = $escala->getValue();
119 $res = $SERVIDOR->guardar($DB, true);
123 elseif (@$f_botones['modificar']) {
124 $SERVIDOR->nombre = $nombre->getValue();
125 $SERVIDOR->escala = $escala->getValue();
126 $res = $SERVIDOR->guardar($DB, false);
130 elseif (@$f_botones['eliminar']) {
131 $res = $SERVIDOR->borrar($DB);
134 if (PEAR::isError($res)) {
135 trigger_error('Error: ' . $res->getMessage() . "\n", E_USER_ERROR);
137 header ('location: admin_servidores');
142 //Agrego la info al marco y la muestro {{{
143 $MARCO->addStyleSheet('css/yatta.css');
144 $MARCO->addBody($FORM);