root/trunk/wifidog-auth/wifidog/admin/generic_object_admin.php @ 684

Revision 684, 6.1 KB (checked in by fproulx, 8 years ago)

2005-08-11 Francois Proulx <francois.proulx@…>

  • Refactored the Admin UI.
  • I need to write the upload form and rewrite statistics
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2/********************************************************************\
3 * This program is free software; you can redistribute it and/or    *
4 * modify it under the terms of the GNU General Public License as   *
5 * published by the Free Software Foundation; either version 2 of   *
6 * the License, or (at your option) any later version.              *
7 *                                                                  *
8 * This program is distributed in the hope that it will be useful,  *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
11 * GNU General Public License for more details.                     *
12 *                                                                  *
13 * You should have received a copy of the GNU General Public License*
14 * along with this program; if not, contact:                        *
15 *                                                                  *
16 * Free Software Foundation           Voice:  +1-617-542-5942       *
17 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
18 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
19 *                                                                  *
20 \********************************************************************/
21/**@file generic_object_admin.php
22 * A simple interface to edit any object that implements the GenericObject interface.  The php file takes the following params:
23 * $_REQUEST['action']: new, edit, delete, preview (also save, but not meant for calling from outside this file)
24 * $_REQUEST['object_id']:  The id of the object ot be edited
25 * $_REQUEST['object_class']:  The class name of the object ot be edited
26 * $_REQUEST['node_id']: In preview mode, the current node to simulate display
27 * $_REQUEST['debug']:  If present and non empty, the $_REQUEST variables will be displayed
28 * @author Copyright (C) 2005 Benoit Grégoire <bock@step.polymtl.ca>,
29 * Technologies Coeus inc.
30 */
31define('BASEPATH', '../');
32require_once 'admin_common.php';
33require_once BASEPATH.'classes/GenericObject.php';
34
35if (!empty ($_REQUEST['debug'])) {
36        echo "<pre>";
37        print_r($_REQUEST);
38        echo "</pre>";
39}
40
41$html = "<div>";
42if (empty ($_REQUEST['object_class'])) {
43        echo "<div class='errormsg'>"._("Sorry, the 'object_class' parameter must be specified")."</div>\n";
44        exit;
45} else {
46        $class = $_REQUEST['object_class'];
47}
48
49if ($_REQUEST['action'] == 'new') {
50        $object = call_user_func(array ($class, 'createNewObject'));
51        $_REQUEST['action'] = 'edit';
52} else {
53        if (empty ($_REQUEST['object_id'])) {
54                echo "<div class='errormsg'>"._("Sorry, the 'object_id' parameter must be specified")."</div>\n";
55                exit;
56        }
57        $object = call_user_func(array ($class, 'getObject'), $_REQUEST['object_id']);
58}
59
60if ($_REQUEST['action'] == 'save') {
61        $html .= $object->processAdminUI();
62        $object = call_user_func(array ($class, 'getObject'), $_REQUEST['object_id']);
63        $_REQUEST['action'] = 'edit';
64}
65
66if ($_REQUEST['action'] == 'delete') {
67        $errmsg = '';
68
69        if ($object->delete($errmsg) == true) {
70                $html .= "<div class='successmsg'>"._("Object successfully deleted")."</div>\n";
71        } else {
72                $html .= "<div class='errormsg'>"._("Deletion failed, error was: ")."$errmsg</div>\n";
73                $_REQUEST['action'] = 'edit';
74        }
75}
76
77if ($_REQUEST['action'] == 'edit') {
78        $common_input = '';
79        if (!empty ($_REQUEST['debug'])) {
80                $common_input .= "<input type=submit name='debug' value='true'>\n";
81        }
82        $common_input .= "<input type='hidden' name='object_id' value='".$object->GetId()."'>\n";
83        $common_input .= "<input type='hidden' name='object_class' value='".get_class($object)."'>\n";
84
85        $html .= "<form enctype='multipart/form-data' action='".GENERIC_OBJECT_ADMIN_ABS_HREF."' method='post'>";
86        $html .= $common_input;
87        $html .= $object->getAdminUI();
88        $html .= "<input type='hidden' name='action' value='save'>\n";
89        $html .= "<input type=submit name='save_submit' value='"._("Save")." ".get_class($object)."'>\n";
90        $html .= '</form>';
91
92        $html .= "<form action='".GENERIC_OBJECT_ADMIN_ABS_HREF."' method='post'>";
93        $html .= $common_input;
94        $html .= "<input type='hidden' name='action' value='preview'>\n";
95        $html .= "<input type=submit name='preview_submit' value='"._("Preview")." ".get_class($object)."'>\n";
96        $html .= '</form>';
97
98        $html .= "<form action='".GENERIC_OBJECT_ADMIN_ABS_HREF."' method='post'>";
99        $html .= $common_input;
100        $html .= "<input type='hidden' name='action' value='delete'>\n";
101        $html .= "<input type=submit name='delete_submit' value='"._("Delete")." ".get_class($object)."'>\n";
102        $html .= '</form>';
103}
104
105if ($_REQUEST['action'] == 'preview') {
106        if (empty ($_REQUEST['node_id'])) {
107                $node_id = null;
108                $node = null;
109        } else {
110                $node_id = $_REQUEST['node_id'];
111                $node = Node :: getObject($node_id);
112                Node :: setCurrentNode($node);
113       
114        $html .= "<h1>"._("Showing preview as it would appear at ").$node->getName()."</h1><p>"; 
115        }
116        $common_input = '';
117        if (!empty ($_REQUEST['debug'])) {
118                $common_input .= "<input type=submit name='debug' value='true'>\n";
119        }
120        $common_input .= "<input type='hidden' name='object_id' value='".$object->GetId()."'>\n";
121        $common_input .= "<input type='hidden' name='object_class' value='".get_class($object)."'>\n";
122        $common_input .= "<input type='hidden' name='node_id' value='".$node_id."'>\n";
123
124        $html .= "<form action='".GENERIC_OBJECT_ADMIN_ABS_HREF."' method='post'>";
125        $html .= $common_input;
126
127        $name = "node_id";
128        $html .= Node :: getSelectNodeUI($name);
129   
130        $html .= $object->getUserUI();
131        $html .= "<input type='hidden' name='action' value='preview'>\n";
132        $html .= "<input type=submit name='preview_submit' value='"._("Preview")." ".get_class($object)."'>\n";
133        $html .= '</form>';
134
135        $html .= "<form action='".GENERIC_OBJECT_ADMIN_ABS_HREF."' method='post'>";
136        $html .= $common_input;
137        $html .= "<input type='hidden' name='action' value='edit'>\n";
138        $html .= "<input type=submit name='edit_submit' value='"._("Edit")." ".get_class($object)."'>\n";
139        $html .= '</form>';
140}
141$html .= "</div>";
142
143require_once BASEPATH.'classes/MainUI.php';
144$ui=new MainUI();
145$ui->setToolSection('ADMIN');
146$ui->setTitle(_("Generic object editor"));
147$ui->setMainContent($html);
148$ui->display();
149?>
Note: See TracBrowser for help on using the browser.