| 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 | */ |
|---|
| 25 | define('BASEPATH','../'); |
|---|
| 26 | require_once 'admin_common.php'; |
|---|
| 27 | require_once BASEPATH.'classes/Node.php'; |
|---|
| 28 | require_once BASEPATH.'classes/User.php'; |
|---|
| 29 | |
|---|
| 30 | $user_id = $session->get(SESS_USERNAME_VAR); |
|---|
| 31 | $smarty->assign("user_id", $user_id); // DEBUG |
|---|
| 32 | |
|---|
| 33 | empty($_REQUEST['action']) ? $action = '' : $action = $_REQUEST['action']; |
|---|
| 34 | empty($_REQUEST['node_id']) ? $node_id = '' : $node_id = $_REQUEST['node_id']; |
|---|
| 35 | |
|---|
| 36 | if ($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 | $map_url = $db->EscapeString($map_url); |
|---|
| 119 | $rss_url = $db->EscapeString($rss_url); |
|---|
| 120 | $public_phone_number = $db->EscapeString($public_phone_number); |
|---|
| 121 | $public_email = $db->EscapeString($public_email); |
|---|
| 122 | $mass_transit_info = $db->EscapeString($mass_transit_info); |
|---|
| 123 | $name = $db->EscapeString($name); |
|---|
| 124 | /* TODO Use object to update all of this and VALIDATE */ |
|---|
| 125 | |
|---|
| 126 | if ($new_node_id) { |
|---|
| 127 | $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'"); |
|---|
| 128 | } else { |
|---|
| 129 | echo "NO NODE ID, this is a bug"; |
|---|
| 130 | } |
|---|
| 131 | break; |
|---|
| 132 | /* |
|---|
| 133 | NOTE IMPORTANTE : Penser de mettre a jour les node_owners d'un node_id modifie |
|---|
| 134 | NOTE IMPORTANTE : Penser renommer le repertoire de l'ancien node_id vers le nouveau dans local_content |
|---|
| 135 | */ |
|---|
| 136 | |
|---|
| 137 | default: |
|---|
| 138 | echo '<p class="warning">Unexpected results</p>'; |
|---|
| 139 | exit; |
|---|
| 140 | break; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | } elseif ($action == 'del_node') { |
|---|
| 144 | try { |
|---|
| 145 | Node::deleteNode($node_id); |
|---|
| 146 | } catch (Exception $e) { |
|---|
| 147 | echo '<p class="warning">'.$e->getMessage().'</p>'; |
|---|
| 148 | } |
|---|
| 149 | // NOTE IMPORTANTE : Penser d'effacer le contenu du node efface dans local_content/$node_id |
|---|
| 150 | } elseif ($action == 'add_owner') { |
|---|
| 151 | try { |
|---|
| 152 | if (User::UserExists($_REQUEST['owner_user_id'])) { |
|---|
| 153 | $node = Node::getNode($_REQUEST['node_id']); |
|---|
| 154 | $node->addOwner($_REQUEST['owner_user_id']); |
|---|
| 155 | } else { |
|---|
| 156 | throw new Exception(_('Invalid user!')); |
|---|
| 157 | } |
|---|
| 158 | } catch (Exception $e) { |
|---|
| 159 | echo '<p class="warning">' . $e->getMessage() . '</p>'; |
|---|
| 160 | } |
|---|
| 161 | } elseif ($action == 'del_owner') { |
|---|
| 162 | try { |
|---|
| 163 | $node = Node::getNode($_REQUEST['node_id']); |
|---|
| 164 | $node->removeOwner($_REQUEST['owner_user_id']); |
|---|
| 165 | } catch (Exception $e) { |
|---|
| 166 | echo '<p class="warning">' . $e->getMessage() . '</p>'; |
|---|
| 167 | } |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | $nodes = Node::getAllNodesOrdered("node_id"); |
|---|
| 171 | if (is_array($nodes)) { |
|---|
| 172 | $smarty->assign('nodes', $nodes); |
|---|
| 173 | } else { |
|---|
| 174 | $smarty->assign('error_message', _('There are no hotspot on this network.')); |
|---|
| 175 | } |
|---|
| 176 | $smarty->display('admin/templates/hotspot_display.html'); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | ?> |
|---|