root/trunk/wifidog-auth/wifidog/admin/hotspot.php @ 420

Revision 420, 7.6 KB (checked in by aprilp, 8 years ago)

*** empty log message ***

  • 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 hotspot.php
22   * Node configuration page
23   * @author Copyright (C) 2005 Pascal Leclerc
24   */
25define('BASEPATH','../');
26require_once 'admin_common.php';
27require_once BASEPATH.'classes/Node.php';
28require_once BASEPATH.'classes/User.php';
29
30$user_id = $session->get(SESS_USERNAME_VAR);
31$smarty->assign("user_id", $user_id); // DEBUG
32
33empty($_REQUEST['action'])  ? $action  = '' : $action  = $_REQUEST['action'];
34empty($_REQUEST['node_id']) ? $node_id = '' : $node_id = $_REQUEST['node_id'];
35
36if ($action == 'edit_node') { // Allow node creation or node edition
37    $smarty->assign("title", _("Edit a hotspot"));
38   
39    if ($node_id != "new") { // Node creation
40        $node = Node::getNode($node_id);
41    }
42
43    $smarty->assign('node_id', $node->getID());
44    $smarty->assign('node_deployment_status', $node->getDeploymentStatus());
45    $smarty->assign('node_info', $node->getInfoArray());
46    $smarty->assign('all_deployment_status', Node::getAllDeploymentStatus());
47
48    $smarty->display('admin/templates/hotspot_edit.html');
49
50} else if ($action == 'add_node') { // Display hotspot creation form
51    /* max() + 1 doesn't work well when max() returns a String
52    if ("$node_id" == "new") { // Allow user to get a valide node_id
53        $db->ExecSqlUniqueRes("SELECT max(node_id) + 1 FROM nodes", $new_node, false);
54        $new_node = array_shift($new_node) or $new_node = 0;
55        $javascript = "<input type='button' value='Get valid ID' onclick='javascript:document.auth.new_node_id.value=$new_node; return false;'>";
56        $smarty->assign("javascript", $javascript);
57    }
58    */
59
60    $smarty->assign('title', _('Add a new hotspot'));
61    $smarty->assign('all_deployment_status', Node::getAllDeploymentStatus());
62    $smarty->display('admin/templates/hotspot_edit.html');
63
64} else if ($action == 'owner') { // Display hotspot owner list and add form
65    $smarty->assign('title', _('Owner hotspot with'));
66    try {
67        $node = Node::getNode($node_id);
68        $smarty->assign('node_id', $node->getName());
69        $smarty->assign('owner_list', $node->getOwners());
70        $smarty->display('admin/templates/hotspot_owner.html');
71    } catch (Exception $e) {
72        echo $e->getMessage();
73        exit;
74    }
75
76    //foreach($node_owner_results as $node_owner_row) {
77    //    $smarty->append("owner_list", $node_owner_row);
78    //}
79 
80} else {
81    if ($action == 'update_node' || $action == 'add_new_node') {
82        $new_node_id            = $_REQUEST['new_node_id'];
83        $name                   = $_REQUEST['name'];
84        $rss_url                = $_REQUEST['rss_url'];
85        $home_page_url          = $_REQUEST['home_page_url'];
86        $description            = $_REQUEST['description'];
87        $map_url                = $_REQUEST['map_url'];
88        $street_address         = $_REQUEST['street_address'];
89        $public_phone_number    = $_REQUEST['public_phone_number'];
90        $public_email           = $_REQUEST['public_email'];
91        $mass_transit_info      = $_REQUEST['mass_transit_info'];
92        $node_deployment_status = $_REQUEST['node_deployment_status'];
93
94        switch ($action) {
95            case 'add_new_node':
96                try {
97                    $node = Node::createNode(
98                            $new_node_id,
99                            $name,
100                            $rss_url,
101                            $home_page_url,
102                            $description,
103                            $map_url,
104                            $street_address,
105                            $public_phone_number,
106                            $public_email,
107                            $mass_transit_info,
108                            $node_deployment_status
109                        );
110                } catch (Exception $e) {
111                    echo '<p class="warning">'.$e->getMessage().'</p>'; 
112                }
113                break;
114
115            case 'update_node':
116                $description = $db->EscapeString($description);
117                $home_page_url = $db->EscapeString($home_page_url);
118                /* TODO Use object to update all of this and VALIDATE */
119
120                if ($new_node_id) {
121                    $sql_successful = $db->ExecSqlUpdate("UPDATE nodes SET node_id='$new_node_id',name='$name',rss_url='$rss_url',home_page_url='$home_page_url',description='$description',map_url='$map_url',street_address='$street_address',public_phone_number='$public_phone_number',public_email='$public_email',mass_transit_info='$mass_transit_info',node_deployment_status='$node_deployment_status' WHERE node_id='$node_id'");
122                } else {
123                    echo "NO NODE ID, this is a bug";
124                }
125                break;
126                /*
127                NOTE IMPORTANTE : Penser de mettre a jour les node_owners d'un node_id modifie
128                NOTE IMPORTANTE : Penser renommer le repertoire de l'ancien node_id vers le nouveau dans local_content
129                */
130
131            default:
132                echo '<p class="warning">Unexpected results</p>'; 
133                exit;
134                break;
135        }
136
137    } elseif ($action == 'del_node') {
138        try {
139            Node::deleteNode($node_id);
140        } catch (Exception $e) {
141            echo '<p class="warning">'.$e->getMessage().'</p>'; 
142        }
143        // NOTE IMPORTANTE : Penser d'effacer le contenu du node efface dans local_content/$node_id
144    } elseif ($action == 'add_owner') {
145        try {
146            if (User::UserExists($_REQUEST['owner_user_id'])) {
147                $node = Node::getNode($_REQUEST['node_id']);
148                $node->addOwner($_REQUEST['owner_user_id']);
149            } else {
150                throw new Exception(_('Invalid user!'));
151            }
152        } catch (Exception $e) {
153            echo '<p class="warning">' . $e->getMessage() . '</p>';
154        }
155    } elseif ($action == 'del_owner') {
156        try {
157            $node = Node::getNode($_REQUEST['node_id']);
158            $node->removeOwner($_REQUEST['owner_user_id']);
159        } catch (Exception $e) {
160            echo '<p class="warning">' . $e->getMessage() . '</p>';
161        }
162    }
163
164    $nodes = Node::getAllNodesOrdered("node_id");
165    if (is_array($nodes)) {
166        $smarty->assign('nodes', $nodes);
167    } else {
168        $smarty->assign('error_message', _('There are no hotspot on this network.'));
169    }
170    $smarty->display('admin/templates/hotspot_display.html');
171}
172
173?>
Note: See TracBrowser for help on using the browser.