| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /********************************************************************\ |
|---|
| 4 | * This program is free software; you can redistribute it and/or * |
|---|
| 5 | * modify it under the terms of the GNU General Public License as * |
|---|
| 6 | * published by the Free Software Foundation; either version 2 of * |
|---|
| 7 | * the License, or (at your option) any later version. * |
|---|
| 8 | * * |
|---|
| 9 | * This program is distributed in the hope that it will be useful, * |
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|---|
| 12 | * GNU General Public License for more details. * |
|---|
| 13 | * * |
|---|
| 14 | * You should have received a copy of the GNU General Public License* |
|---|
| 15 | * along with this program; if not, contact: * |
|---|
| 16 | * * |
|---|
| 17 | * Free Software Foundation Voice: +1-617-542-5942 * |
|---|
| 18 | * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * |
|---|
| 19 | * Boston, MA 02111-1307, USA gnu@gnu.org * |
|---|
| 20 | * * |
|---|
| 21 | \********************************************************************/ |
|---|
| 22 | /**@file Node.php |
|---|
| 23 | * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca> |
|---|
| 24 | */ |
|---|
| 25 | |
|---|
| 26 | require_once BASEPATH.'include/common.php'; |
|---|
| 27 | require_once 'Content/ContentGroup.php'; |
|---|
| 28 | require_once BASEPATH.'classes/User.php'; |
|---|
| 29 | |
|---|
| 30 | /** Abstract a Node. A Node is an actual physical transmitter. */ |
|---|
| 31 | class Node implements GenericObject |
|---|
| 32 | { |
|---|
| 33 | private $mRow; |
|---|
| 34 | private $id; |
|---|
| 35 | private static $current_node_id = null; |
|---|
| 36 | |
|---|
| 37 | /** Instantiate a node object |
|---|
| 38 | * @param $id The id of the requested node |
|---|
| 39 | * @return a Node object, or null if there was an error |
|---|
| 40 | */ |
|---|
| 41 | static function getObject($id) |
|---|
| 42 | { |
|---|
| 43 | $object = null; |
|---|
| 44 | $object = new self($id); |
|---|
| 45 | return $object; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | /** Get the current node for which the portal is displayed or to which a user is physically connected. |
|---|
| 49 | * @param $real_node_only true or false. If true, the real physical node where the user is connected is returned, and the node set by setCurrentNode is ignored. |
|---|
| 50 | * @return a Node object, or null if it can't be found. |
|---|
| 51 | */ |
|---|
| 52 | static function getCurrentNode($real_node_only = false) |
|---|
| 53 | { |
|---|
| 54 | $object = null; |
|---|
| 55 | if (self :: $current_node_id != null && $real_node_only == false) |
|---|
| 56 | { |
|---|
| 57 | $object = new self(self :: $current_node_id); |
|---|
| 58 | } |
|---|
| 59 | else |
|---|
| 60 | { |
|---|
| 61 | $object = self :: getCurrentRealNode(); |
|---|
| 62 | } |
|---|
| 63 | return $object; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | /** Set the current node where the user is to be considered connected to. (For portal and content display purpuses, among other. |
|---|
| 67 | * @param $node Node. The new current node. |
|---|
| 68 | * @return true */ |
|---|
| 69 | static function setCurrentNode(Node $node) |
|---|
| 70 | { |
|---|
| 71 | self :: $current_node_id = $node->GetId(); |
|---|
| 72 | return true; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | /** Get the current node to which a user is physically connected, if any. This is done by an IP adress lookup against the last reported IP adress of the node |
|---|
| 76 | * @param * @return a Node object, or null if it can't be found. |
|---|
| 77 | */ |
|---|
| 78 | public static function getCurrentRealNode() |
|---|
| 79 | { |
|---|
| 80 | global $db; |
|---|
| 81 | $retval = null; |
|---|
| 82 | $sql = "SELECT node_id, last_heartbeat_ip from nodes WHERE last_heartbeat_ip='$_SERVER[REMOTE_ADDR]'"; |
|---|
| 83 | $db->ExecSql($sql, $node_rows, false); |
|---|
| 84 | $num_match = count($node_rows); |
|---|
| 85 | if ($num_match == 0) |
|---|
| 86 | { |
|---|
| 87 | |
|---|
| 88 | // User is not physically connected to a node |
|---|
| 89 | $retval = null; |
|---|
| 90 | } |
|---|
| 91 | else |
|---|
| 92 | if ($num_match = 1) |
|---|
| 93 | { |
|---|
| 94 | // Only a single node matches, the user is presumed to be there |
|---|
| 95 | $retval = new self($node_rows[0]['node_id']); |
|---|
| 96 | } |
|---|
| 97 | else |
|---|
| 98 | { |
|---|
| 99 | /* We have more than one node matching the IP (the nodes are behind the same NAT). |
|---|
| 100 | * We will try to discriminate by finding which node the user last authenticated against. |
|---|
| 101 | * If the IP matches, we can be pretty certain the user is there. |
|---|
| 102 | */ |
|---|
| 103 | $retval = null; |
|---|
| 104 | $current_user = User :: getCurrentUser(); |
|---|
| 105 | if ($current_user != null) |
|---|
| 106 | { |
|---|
| 107 | $current_user_id = $current_user->getId(); |
|---|
| 108 | $_SERVER['REMOTE_ADDR']; |
|---|
| 109 | $sql = "SELECT node_id, last_heartbeat_ip from connections NATURAL JOIN nodes WHERE user_id='$current_user_id' ORDER BY last_updated DESC "; |
|---|
| 110 | $db->ExecSql($sql, $node_rows, false); |
|---|
| 111 | $node_row = $node_rows[0]; |
|---|
| 112 | if ($node_row != null && $node_row['last_heartbeat_ip'] == $_SERVER['REMOTE_ADDR']) |
|---|
| 113 | { |
|---|
| 114 | $retval = new self($node_row['node_id']); |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | return $retval; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | public function delete(& $errmsg) |
|---|
| 122 | { |
|---|
| 123 | $retval = false; |
|---|
| 124 | $user = User :: getCurrentUser(); |
|---|
| 125 | if ($this->isOwner($user) || $user->isSuperAdmin()) |
|---|
| 126 | { |
|---|
| 127 | $errmsg = _('Access denied!'); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | global $db; |
|---|
| 131 | $id = $db->EscapeString($this->getId()); |
|---|
| 132 | if (!$db->ExecSqlUpdate("DELETE FROM nodes WHERE node_id='{$id}'", false)) |
|---|
| 133 | { |
|---|
| 134 | $errmsg = _('Could not delete node!'); |
|---|
| 135 | } |
|---|
| 136 | else |
|---|
| 137 | { |
|---|
| 138 | $retval = true; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | return $retval; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | /** Create a new Node in the database |
|---|
| 145 | * @deprecated version - 18-Apr-2005 |
|---|
| 146 | * @param $id The id to be given to the new node |
|---|
| 147 | * @return the newly created Node object, or null if there was an error |
|---|
| 148 | */ |
|---|
| 149 | static function createNewObject() |
|---|
| 150 | { |
|---|
| 151 | global $db; |
|---|
| 152 | |
|---|
| 153 | $node_id = $db->EscapeString(get_guid()); |
|---|
| 154 | $name = $db->EscapeString('New node'); |
|---|
| 155 | |
|---|
| 156 | $sql = "INSERT INTO nodes (node_id, name) VALUES ('$node_id','$name')"; |
|---|
| 157 | |
|---|
| 158 | if (!$db->ExecSqlUpdate($sql, false)) |
|---|
| 159 | { |
|---|
| 160 | throw new Exception(_('Unable to insert new node into database!')); |
|---|
| 161 | } |
|---|
| 162 | $object = new self($node_id); |
|---|
| 163 | return $object; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | /** Create a new Node in the database |
|---|
| 167 | * @deprecated version - 18-Apr-2005 |
|---|
| 168 | * @param $id The id to be given to the new node |
|---|
| 169 | * @return the newly created Node object, or null if there was an error |
|---|
| 170 | */ |
|---|
| 171 | static function createNode($node_id, $name, $rss_url = "", $home_page_url = "", $description = "", $map_url = "", $street_address = "", $public_phone_number = "", $public_email = "", $mass_transit_info = "", $node_deployment_status = "IN_PLANNING") |
|---|
| 172 | { |
|---|
| 173 | global $db; |
|---|
| 174 | |
|---|
| 175 | $node_id = $db->EscapeString($node_id); |
|---|
| 176 | $name = $db->EscapeString($name); |
|---|
| 177 | $home_page_url = $db->EscapeString($home_page_url); |
|---|
| 178 | $description = $db->EscapeString($description); |
|---|
| 179 | $map_url = $db->EscapeString($map_url); |
|---|
| 180 | $street_address = $db->EscapeString($street_address); |
|---|
| 181 | $public_phone_number = $db->EscapeString($public_phone_number); |
|---|
| 182 | $public_email = $db->EscapeString($public_email); |
|---|
| 183 | $mass_transit_info = $db->EscapeString($mass_transit_info); |
|---|
| 184 | $node_deployment_status = $db->EscapeString($node_deployment_status); |
|---|
| 185 | |
|---|
| 186 | if (Node :: nodeExists($node_id)) |
|---|
| 187 | throw new Exception(_('This node already exists.')); |
|---|
| 188 | |
|---|
| 189 | $sql = "INSERT INTO nodes (node_id, name, creation_date, home_page_url, description, map_url, street_address, public_phone_number, public_email, mass_transit_info, node_deployment_status) VALUES ('$node_id','$name',NOW(),'$home_page_url','$description','$map_url','$street_address','$public_phone_number','$public_email','$mass_transit_info','$node_deployment_status')"; |
|---|
| 190 | |
|---|
| 191 | if (!$db->ExecSqlUpdate($sql, false)) |
|---|
| 192 | { |
|---|
| 193 | throw new Exception(_('Unable to insert new node into database!')); |
|---|
| 194 | } |
|---|
| 195 | $object = new self($node_id); |
|---|
| 196 | return $object; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | /** Get an interface to pick a node. |
|---|
| 200 | * @param $user_prefix A identifier provided by the programmer to recognise it's generated html form |
|---|
| 201 | * @param $sql_additional_where Addidional where conditions to restrict the candidate objects |
|---|
| 202 | * @return html markup |
|---|
| 203 | */ |
|---|
| 204 | public static function getSelectNodeUI($user_prefix, $sql_additional_where = null) |
|---|
| 205 | { |
|---|
| 206 | global $db; |
|---|
| 207 | $html = ''; |
|---|
| 208 | $name = "{$user_prefix}"; |
|---|
| 209 | $html .= "Node: \n"; |
|---|
| 210 | $sql = "SELECT node_id, name from nodes WHERE 1=1 $sql_additional_where ORDER BY node_id"; |
|---|
| 211 | $db->ExecSql($sql, $node_rows, false); |
|---|
| 212 | if ($node_rows != null) |
|---|
| 213 | { |
|---|
| 214 | $i = 0; |
|---|
| 215 | foreach ($node_rows as $node_row) |
|---|
| 216 | { |
|---|
| 217 | $tab[$i][0] = $node_row['node_id']; |
|---|
| 218 | $tab[$i][1] = $node_row['node_id'].": ".$node_row['name']; |
|---|
| 219 | $i ++; |
|---|
| 220 | } |
|---|
| 221 | $html .= FormSelectGenerator :: generateFromArray($tab, null, $name, null, false); |
|---|
| 222 | } |
|---|
| 223 | return $html; |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | /** Get the selected Network object. |
|---|
| 227 | * @param $user_prefix A identifier provided by the programmer to recognise it's generated form |
|---|
| 228 | * @return the node object |
|---|
| 229 | */ |
|---|
| 230 | static function processSelectNodeUI($user_prefix) |
|---|
| 231 | { |
|---|
| 232 | $object = null; |
|---|
| 233 | $name = "{$user_prefix}"; |
|---|
| 234 | return new self($_REQUEST[$name]); |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | /** Get an interface to select the deployment status |
|---|
| 238 | * @param $user_prefix A identifier provided by the programmer to recognise it's generated html form |
|---|
| 239 | * @return html markup |
|---|
| 240 | */ |
|---|
| 241 | public function getSelectDeploymentStatus($user_prefix) |
|---|
| 242 | { |
|---|
| 243 | global $db; |
|---|
| 244 | $html = ''; |
|---|
| 245 | $name = "{$user_prefix}"; |
|---|
| 246 | $status_list = self :: getAllDeploymentStatus(); |
|---|
| 247 | if ($status_list != null) |
|---|
| 248 | { |
|---|
| 249 | $tab = array (); |
|---|
| 250 | foreach ($status_list as $status) |
|---|
| 251 | $tab[] = array ($status, $status); |
|---|
| 252 | $html .= FormSelectGenerator :: generateFromArray($tab, $this->getDeploymentStatus(), $name, null, false); |
|---|
| 253 | } |
|---|
| 254 | return $html; |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | /** Get the selected deployment status |
|---|
| 258 | * @param $user_prefix A identifier provided by the programmer to recognise it's generated form |
|---|
| 259 | * @return the deployment status |
|---|
| 260 | */ |
|---|
| 261 | public function processSelectDeploymentStatus($user_prefix) |
|---|
| 262 | { |
|---|
| 263 | $object = null; |
|---|
| 264 | $name = "{$user_prefix}"; |
|---|
| 265 | return $_REQUEST[$name]; |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | /** @param $node_id The id of the node */ |
|---|
| 269 | function __construct($node_id) |
|---|
| 270 | { |
|---|
| 271 | global $db; |
|---|
| 272 | |
|---|
| 273 | $node_id_str = $db->EscapeString($node_id); |
|---|
| 274 | $sql = "SELECT * FROM nodes WHERE node_id='$node_id_str'"; |
|---|
| 275 | $db->ExecSqlUniqueRes($sql, $row, false); |
|---|
| 276 | if ($row == null) |
|---|
| 277 | { |
|---|
| 278 | throw new Exception(_("The id $node_id_str could not be found in the database")); |
|---|
| 279 | } |
|---|
| 280 | $this->mRow = $row; |
|---|
| 281 | $this->mDb = & $db; |
|---|
| 282 | $this->id = $row['node_id']; |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | function getID() |
|---|
| 286 | { |
|---|
| 287 | return $this->mRow['node_id']; |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | /** Return the name of the node |
|---|
| 291 | */ |
|---|
| 292 | function getName() |
|---|
| 293 | { |
|---|
| 294 | return $this->mRow['name']; |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | function setName($name) |
|---|
| 298 | { |
|---|
| 299 | $name = $this->mDb->EscapeString($name); |
|---|
| 300 | $this->mDb->ExecSqlUpdate("UPDATE nodes SET name = '{$name}' WHERE node_id = '{$this->getId()}'"); |
|---|
| 301 | $this->refresh(); |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | function getHomePageURL() |
|---|
| 305 | { |
|---|
| 306 | return $this->mRow['home_page_url']; |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | function setHomePageUrl($url) |
|---|
| 310 | { |
|---|
| 311 | $url = $this->mDb->EscapeString($url); |
|---|
| 312 | $this->mDb->ExecSqlUpdate("UPDATE nodes SET home_page_url = '{$url}' WHERE node_id = '{$this->getId()}'"); |
|---|
| 313 | $this->refresh(); |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | function getDescription() |
|---|
| 317 | { |
|---|
| 318 | return $this->mRow['description']; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | function setDescription($description) |
|---|
| 322 | { |
|---|
| 323 | $description = $this->mDb->EscapeString($description); |
|---|
| 324 | $this->mDb->ExecSqlUpdate("UPDATE nodes SET description = '{$description}' WHERE node_id = '{$this->getId()}'"); |
|---|
| 325 | $this->refresh(); |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | function getMapURL() |
|---|
| 329 | { |
|---|
| 330 | return $this->mRow['map_url']; |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | function setMapURL($url) |
|---|
| 334 | { |
|---|
| 335 | $url = $this->mDb->EscapeString($url); |
|---|
| 336 | $this->mDb->ExecSqlUpdate("UPDATE nodes SET map_url = '{$url}' WHERE node_id = '{$this->getId()}'"); |
|---|
| 337 | $this->refresh(); |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | function getAddress() |
|---|
| 341 | { |
|---|
| 342 | return $this->mRow['street_address']; |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | function setAddress($address) |
|---|
| 346 | { |
|---|
| 347 | $address = $this->mDb->EscapeString($address); |
|---|
| 348 | $this->mDb->ExecSqlUpdate("UPDATE nodes SET street_address = '{$address}' WHERE node_id = '{$this->getId()}'"); |
|---|
| 349 | $this->refresh(); |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | function getTelephone() |
|---|
| 353 | { |
|---|
| 354 | return $this->mRow['public_phone_number']; |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | function setTelephone($phone) |
|---|
| 358 | { |
|---|
| 359 | $phone = $this->mDb->EscapeString($phone); |
|---|
| 360 | $this->mDb->ExecSqlUpdate("UPDATE nodes SET public_phone_number = '{$phone}' WHERE node_id = '{$this->getId()}'"); |
|---|
| 361 | $this->refresh(); |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | function getTransitInfo() |
|---|
| 365 | { |
|---|
| 366 | return $this->mRow['mass_transit_info']; |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | function setTransitInfo($transit_info) |
|---|
| 370 | { |
|---|
| 371 | $transit_info = $this->mDb->EscapeString($transit_info); |
|---|
| 372 | $this->mDb->ExecSqlUpdate("UPDATE nodes SET mass_transit_info = '{$transit_info}' WHERE node_id = '{$this->getId()}'"); |
|---|
| 373 | $this->refresh(); |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | function getEmail() |
|---|
| 377 | { |
|---|
| 378 | return $this->mRow['public_email']; |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | function setEmail($email) |
|---|
| 382 | { |
|---|
| 383 | $email = $this->mDb->EscapeString($email); |
|---|
| 384 | $this->mDb->ExecSqlUpdate("UPDATE nodes SET public_email = '{$email}' WHERE node_id = '{$this->getId()}'"); |
|---|
| 385 | $this->refresh(); |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | function getDeploymentStatus() |
|---|
| 389 | { |
|---|
| 390 | return $this->mRow['node_deployment_status']; |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | function setDeploymentStatus($status) |
|---|
| 394 | { |
|---|
| 395 | $status = $this->mDb->EscapeString($status); |
|---|
| 396 | $this->mDb->ExecSqlUpdate("UPDATE nodes SET node_deployment_status = '{$status}' WHERE node_id = '{$this->getId()}'"); |
|---|
| 397 | $this->refresh(); |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | /** Retreives the admin interface of this object. |
|---|
| 401 | * @return The HTML fragment for this interface */ |
|---|
| 402 | public function getAdminUI() |
|---|
| 403 | { |
|---|
| 404 | //TODO: Most of this code will be moved to Hotspot class when the abtraction will be completed |
|---|
| 405 | |
|---|
| 406 | $html = ''; |
|---|
| 407 | $html .= "<div class='admin_container'>\n"; |
|---|
| 408 | $html .= "<div class='admin_class'>Node (".get_class($this)." instance)</div>\n"; |
|---|
| 409 | $html .= "<h3>"._("Edit a hotspot")."</h3>\n"; |
|---|
| 410 | |
|---|
| 411 | // Information about the node |
|---|
| 412 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 413 | $html .= "<div class='admin_section_title'>"._("Information about the node:")."</div>\n"; |
|---|
| 414 | |
|---|
| 415 | // Node ID |
|---|
| 416 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 417 | $html .= "<div class='admin_section_title'>"._("ID")." : </div>\n"; |
|---|
| 418 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 419 | $name = "node_".$this->getId()."_id"; |
|---|
| 420 | $value = htmlspecialchars($this->getId(), ENT_QUOTES); |
|---|
| 421 | $html .= "<input type='text' readonly='' size='10' value='$value' name='$name'>\n"; |
|---|
| 422 | $html .= "</div>\n"; |
|---|
| 423 | $html .= "</div>\n"; |
|---|
| 424 | |
|---|
| 425 | // Name |
|---|
| 426 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 427 | $html .= "<div class='admin_section_title'>"._("Name")." : </div>\n"; |
|---|
| 428 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 429 | $name = "node_".$this->getId()."_name"; |
|---|
| 430 | $value = htmlspecialchars($this->getName(), ENT_QUOTES); |
|---|
| 431 | $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; |
|---|
| 432 | $html .= "</div>\n"; |
|---|
| 433 | $html .= "</div>\n"; |
|---|
| 434 | |
|---|
| 435 | // Homepage URL |
|---|
| 436 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 437 | $html .= "<div class='admin_section_title'>"._("Homepage URL")." : </div>\n"; |
|---|
| 438 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 439 | $name = "node_".$this->getId()."_homepage_url"; |
|---|
| 440 | $value = htmlspecialchars($this->getHomePageURL(), ENT_QUOTES); |
|---|
| 441 | $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; |
|---|
| 442 | $html .= "</div>\n"; |
|---|
| 443 | $html .= "</div>\n"; |
|---|
| 444 | |
|---|
| 445 | // Description |
|---|
| 446 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 447 | $html .= "<div class='admin_section_title'>"._("Description")." : </div>\n"; |
|---|
| 448 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 449 | $name = "node_".$this->getId()."_description"; |
|---|
| 450 | $value = htmlspecialchars($this->getDescription(), ENT_QUOTES); |
|---|
| 451 | $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; |
|---|
| 452 | $html .= "</div>\n"; |
|---|
| 453 | $html .= "</div>\n"; |
|---|
| 454 | |
|---|
| 455 | // Map URL |
|---|
| 456 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 457 | $html .= "<div class='admin_section_title'>"._("Map URL")." : </div>\n"; |
|---|
| 458 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 459 | $name = "node_".$this->getId()."_map_url"; |
|---|
| 460 | $value = htmlspecialchars($this->getMapURL(), ENT_QUOTES); |
|---|
| 461 | $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; |
|---|
| 462 | $html .= "</div>\n"; |
|---|
| 463 | $html .= "</div>\n"; |
|---|
| 464 | |
|---|
| 465 | // Street address |
|---|
| 466 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 467 | $html .= "<div class='admin_section_title'>"._("Street address")." : </div>\n"; |
|---|
| 468 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 469 | $name = "node_".$this->getId()."_street_address"; |
|---|
| 470 | $value = htmlspecialchars($this->getAddress(), ENT_QUOTES); |
|---|
| 471 | $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; |
|---|
| 472 | $html .= "</div>\n"; |
|---|
| 473 | $html .= "</div>\n"; |
|---|
| 474 | |
|---|
| 475 | // Public phone # |
|---|
| 476 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 477 | $html .= "<div class='admin_section_title'>"._("Public phone number")." : </div>\n"; |
|---|
| 478 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 479 | $name = "node_".$this->getId()."_public_phone"; |
|---|
| 480 | $value = htmlspecialchars($this->getTelephone(), ENT_QUOTES); |
|---|
| 481 | $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; |
|---|
| 482 | $html .= "</div>\n"; |
|---|
| 483 | $html .= "</div>\n"; |
|---|
| 484 | |
|---|
| 485 | // Public mail |
|---|
| 486 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 487 | $html .= "<div class='admin_section_title'>"._("Public email")." : </div>\n"; |
|---|
| 488 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 489 | $name = "node_".$this->getId()."_public_email"; |
|---|
| 490 | $value = htmlspecialchars($this->getEmail(), ENT_QUOTES); |
|---|
| 491 | $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; |
|---|
| 492 | $html .= "</div>\n"; |
|---|
| 493 | $html .= "</div>\n"; |
|---|
| 494 | |
|---|
| 495 | // Mass transit info |
|---|
| 496 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 497 | $html .= "<div class='admin_section_title'>"._("Mass transit info")." : </div>\n"; |
|---|
| 498 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 499 | $name = "node_".$this->getId()."_mass_transit_info"; |
|---|
| 500 | $value = htmlspecialchars($this->getTransitInfo(), ENT_QUOTES); |
|---|
| 501 | $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; |
|---|
| 502 | $html .= "</div>\n"; |
|---|
| 503 | $html .= "</div>\n"; |
|---|
| 504 | |
|---|
| 505 | // Deployment status |
|---|
| 506 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 507 | $html .= "<div class='admin_section_title'>"._("Node deployment status")." : </div>\n"; |
|---|
| 508 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 509 | $name = "node_".$this->getId()."_deployment_status"; |
|---|
| 510 | $html .= self :: getSelectDeploymentStatus($name); |
|---|
| 511 | $html .= "</div>\n"; |
|---|
| 512 | $html .= "</div>\n"; |
|---|
| 513 | |
|---|
| 514 | // End of information section |
|---|
| 515 | $html .= "</div>\n"; |
|---|
| 516 | |
|---|
| 517 | // Owners management |
|---|
| 518 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 519 | $html .= "<div class='admin_section_title'>"._("Node owners")." : </div>\n"; |
|---|
| 520 | $html .= "<ul class='admin_section_list'>\n"; |
|---|
| 521 | foreach ($this->getOwners() as $owner) |
|---|
| 522 | { |
|---|
| 523 | $html .= "<li class='admin_section_list_item'>\n"; |
|---|
| 524 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 525 | $html .= "{$owner->getUsername()}"; |
|---|
| 526 | $html .= "</div>\n"; |
|---|
| 527 | $html .= "<div class='admin_section_tools'>\n"; |
|---|
| 528 | $name = "node_{$this->getId()}_owner_{$owner->GetId()}_remove"; |
|---|
| 529 | $html .= "<input type='submit' name='$name' value='"._("Remove owner")."'>"; |
|---|
| 530 | $html .= "</div>\n"; |
|---|
| 531 | $html .= "</li>\n"; |
|---|
| 532 | } |
|---|
| 533 | $html .= "<li class='admin_section_list_item'>\n"; |
|---|
| 534 | $name = "node_{$this->getId()}_new_owner"; |
|---|
| 535 | $html .= User :: getSelectUserUI($name); |
|---|
| 536 | $name = "node_{$this->getId()}_new_owner_submit"; |
|---|
| 537 | $html .= "<input type='submit' name='$name' value='"._("Add owner")."'>"; |
|---|
| 538 | $html .= "</li>\n"; |
|---|
| 539 | $html .= "</ul>\n"; |
|---|
| 540 | $html .= "</div>\n"; |
|---|
| 541 | $html .= "</div>\n"; |
|---|
| 542 | |
|---|
| 543 | // Display stats |
|---|
| 544 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 545 | $html .= "<div class='admin_section_title'>"._("Statistics:")."</div>\n"; |
|---|
| 546 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 547 | $name = "node_".$this->id."_get_stats"; |
|---|
| 548 | $html .= "<input type='submit' name='$name' value='"._("Get access statistics")."'>"; |
|---|
| 549 | $html .= "</div>\n"; |
|---|
| 550 | $html .= "</div>\n"; |
|---|
| 551 | |
|---|
| 552 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 553 | $html .= "<div class='admin_section_title'>"._("Node content:")."</div>\n"; |
|---|
| 554 | |
|---|
| 555 | $html .= "<ul class='admin_section_list'>\n"; |
|---|
| 556 | foreach ($this->getAllContent() as $content) |
|---|
| 557 | { |
|---|
| 558 | $html .= "<li class='admin_section_list_item'>\n"; |
|---|
| 559 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 560 | $html .= $content->getListUI(); |
|---|
| 561 | $html .= "</div>\n"; |
|---|
| 562 | $html .= "<div class='admin_section_tools'>\n"; |
|---|
| 563 | $name = "node_".$this->id."_content_".$content->GetId()."_erase"; |
|---|
| 564 | $html .= "<input type='submit' name='$name' value='"._("Remove")."'>"; |
|---|
| 565 | $html .= "</div>\n"; |
|---|
| 566 | $html .= "</li>\n"; |
|---|
| 567 | } |
|---|
| 568 | $html .= "<li class='admin_section_list_item'>\n"; |
|---|
| 569 | $name = "node_{$this->id}_new_content"; |
|---|
| 570 | $html .= Content :: getSelectContentUI($name, "AND content_id NOT IN (SELECT content_id FROM node_has_content WHERE node_id='$this->id')"); |
|---|
| 571 | $name = "node_{$this->id}_new_content_submit"; |
|---|
| 572 | $html .= "<input type='submit' name='$name' value='"._("Add")."'>"; |
|---|
| 573 | $html .= "</li>\n"; |
|---|
| 574 | $html .= "</ul>\n"; |
|---|
| 575 | $html .= "</div>\n"; |
|---|
| 576 | $html .= "</div>\n"; |
|---|
| 577 | return $html; |
|---|
| 578 | } |
|---|
| 579 | |
|---|
| 580 | /** Process admin interface of this object. |
|---|
| 581 | */ |
|---|
| 582 | public function processAdminUI() |
|---|
| 583 | { |
|---|
| 584 | $user = User :: getCurrentUser(); |
|---|
| 585 | if (!$this->isOwner($user) && !$user->isSuperAdmin()) |
|---|
| 586 | { |
|---|
| 587 | throw new Exception(_('Access denied!')); |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | // Information about the node |
|---|
| 591 | |
|---|
| 592 | // Name |
|---|
| 593 | $name = "node_".$this->getId()."_name"; |
|---|
| 594 | $this->setName($_REQUEST[$name]); |
|---|
| 595 | |
|---|
| 596 | // Homepage URL |
|---|
| 597 | $name = "node_".$this->getId()."_homepage_url"; |
|---|
| 598 | $this->setHomePageUrl($_REQUEST[$name]); |
|---|
| 599 | |
|---|
| 600 | // Description |
|---|
| 601 | $name = "node_".$this->getId()."_description"; |
|---|
| 602 | $this->setDescription($_REQUEST[$name]); |
|---|
| 603 | |
|---|
| 604 | // Map URL |
|---|
| 605 | $name = "node_".$this->getId()."_map_url"; |
|---|
| 606 | $this->setMapUrl($_REQUEST[$name]); |
|---|
| 607 | |
|---|
| 608 | // Street address |
|---|
| 609 | $name = "node_".$this->getId()."_street_address"; |
|---|
| 610 | $this->setAddress($_REQUEST[$name]); |
|---|
| 611 | |
|---|
| 612 | // Public phone # |
|---|
| 613 | $name = "node_".$this->getId()."_public_phone"; |
|---|
| 614 | $this->setTelephone($_REQUEST[$name]); |
|---|
| 615 | |
|---|
| 616 | // Public mail |
|---|
| 617 | $name = "node_".$this->getId()."_public_email"; |
|---|
| 618 | $this->setEmail($_REQUEST[$name]); |
|---|
| 619 | |
|---|
| 620 | // Mass transit info |
|---|
| 621 | $name = "node_".$this->getId()."_mass_transit_info"; |
|---|
| 622 | $this->setTransitInfo($_REQUEST[$name]); |
|---|
| 623 | |
|---|
| 624 | // Deployment status |
|---|
| 625 | $name = "node_".$this->getId()."_deployment_status"; |
|---|
| 626 | $this->setDeploymentStatus(self :: processSelectDeploymentStatus($name)); |
|---|
| 627 | |
|---|
| 628 | // Statistics |
|---|
| 629 | $name = "node_{$this->id}_get_stats"; |
|---|
| 630 | if (!empty ($_REQUEST[$name])) |
|---|
| 631 | header("Location: hotspot_log.php?node_id=".urlencode($this->getId())); |
|---|
| 632 | |
|---|
| 633 | // Owners processing |
|---|
| 634 | // Rebuild user id, and delete if it was selected |
|---|
| 635 | foreach ($this->getOwners() as $owner) |
|---|
| 636 | { |
|---|
| 637 | $name = "node_{$this->getId()}_owner_{$owner->GetId()}_remove"; |
|---|
| 638 | if (!empty ($_REQUEST[$name])) |
|---|
| 639 | { |
|---|
| 640 | if ($this->isOwner($owner)) |
|---|
| 641 | $this->removeOwner($owner); |
|---|
| 642 | else |
|---|
| 643 | echo _("Invalid user!"); |
|---|
| 644 | } |
|---|
| 645 | } |
|---|
| 646 | |
|---|
| 647 | $name = "node_{$this->getId()}_new_owner_submit"; |
|---|
| 648 | if (!empty ($_REQUEST[$name])) |
|---|
| 649 | { |
|---|
| 650 | $name = "node_{$this->getId()}_new_owner"; |
|---|
| 651 | $owner = User :: processSelectUserUI($name); |
|---|
| 652 | if ($owner) |
|---|
| 653 | { |
|---|
| 654 | if ($this->isOwner($owner)) |
|---|
| 655 | echo _("The user is already an owner of this node."); |
|---|
| 656 | else |
|---|
| 657 | $this->addOwner($owner); |
|---|
| 658 | } |
|---|
| 659 | } |
|---|
| 660 | |
|---|
| 661 | // Content processing |
|---|
| 662 | // Rebuild content id and deleting if it was selected for deletion ) |
|---|
| 663 | foreach ($this->getAllContent() as $content) |
|---|
| 664 | { |
|---|
| 665 | $name = "node_".$this->id."_content_".$content->GetId()."_erase"; |
|---|
| 666 | if (!empty ($_REQUEST[$name])) |
|---|
| 667 | { |
|---|
| 668 | $this->removeContent($content); |
|---|
| 669 | } |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | $name = "node_{$this->id}_new_content_submit"; |
|---|
| 673 | if (!empty ($_REQUEST[$name])) |
|---|
| 674 | { |
|---|
| 675 | $name = "node_{$this->id}_new_content"; |
|---|
| 676 | $content = Content :: processSelectContentUI($name); |
|---|
| 677 | if ($content) |
|---|
| 678 | $this->addContent($content); |
|---|
| 679 | } |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | // Redirect to this node's portal page |
|---|
| 683 | public function getUserUI() |
|---|
| 684 | { |
|---|
| 685 | header("Location: ".BASE_SSL_PATH."portal/?gw_id=".$this->getId()); |
|---|
| 686 | } |
|---|
| 687 | |
|---|
| 688 | /** Add content to this node */ |
|---|
| 689 | public function addContent(Content $content) |
|---|
| 690 | { |
|---|
| 691 | global $db; |
|---|
| 692 | $content_id = $db->EscapeString($content->getId()); |
|---|
| 693 | $sql = "INSERT INTO node_has_content (node_id, content_id) VALUES ('$this->id','$content_id')"; |
|---|
| 694 | $db->ExecSqlUpdate($sql, false); |
|---|
| 695 | } |
|---|
| 696 | |
|---|
| 697 | /** Remove content from this node */ |
|---|
| 698 | public function removeContent(Content $content) |
|---|
| 699 | { |
|---|
| 700 | global $db; |
|---|
| 701 | $content_id = $db->EscapeString($content->getId()); |
|---|
| 702 | $sql = "DELETE FROM node_has_content WHERE node_id='$this->id' AND content_id='$content_id'"; |
|---|
| 703 | $db->ExecSqlUpdate($sql, false); |
|---|
| 704 | } |
|---|
| 705 | |
|---|
| 706 | /**Get an array of all Content linked to this node |
|---|
| 707 | * @param boolean $exclude_subscribed_content |
|---|
| 708 | * @param User $subscriber The User object used to discriminate the content |
|---|
| 709 | * @return an array of Content or an empty arrray */ |
|---|
| 710 | function getAllContent($exclude_subscribed_content = false, $subscriber = null) |
|---|
| 711 | { |
|---|
| 712 | global $db; |
|---|
| 713 | $retval = array (); |
|---|
| 714 | // Get all network, but exclude user subscribed content if asked |
|---|
| 715 | if ($exclude_subscribed_content == true && $subscriber) |
|---|
| 716 | $sql = "SELECT content_id FROM node_has_content WHERE node_id='$this->id' AND content_id NOT IN (SELECT content_id FROM user_has_content WHERE user_id = '{$subscriber->getId()}') ORDER BY subscribe_timestamp"; |
|---|
| 717 | else |
|---|
| 718 | $sql = "SELECT content_id FROM node_has_content WHERE node_id='$this->id' ORDER BY subscribe_timestamp"; |
|---|
| 719 | $db->ExecSql($sql, $content_rows, false); |
|---|
| 720 | |
|---|
| 721 | if ($content_rows != null) |
|---|
| 722 | { |
|---|
| 723 | foreach ($content_rows as $content_row) |
|---|
| 724 | { |
|---|
| 725 | $retval[] = Content :: getObject($content_row['content_id']); |
|---|
| 726 | } |
|---|
| 727 | } |
|---|
| 728 | return $retval; |
|---|
| 729 | } |
|---|
| 730 | |
|---|
| 731 | /** Get an array of all artistic and locative Content for this hotspot |
|---|
| 732 | * @return an array of Content or an empty arrray */ |
|---|
| 733 | function getAllLocativeArtisticContent() |
|---|
| 734 | { |
|---|
| 735 | global $db; |
|---|
| 736 | $retval = array (); |
|---|
| 737 | $sql = "SELECT * FROM content_group JOIN content ON (content.content_id = content_group.content_group_id) JOIN node_has_content ON (node_has_content.content_id = content_group.content_group_id AND node_has_content.node_id = '{$this->getId()}') WHERE is_persistent = true AND is_artistic_content = true AND is_locative_content = true"; |
|---|
| 738 | $db->ExecSql($sql, $content_rows, false); |
|---|
| 739 | if ($content_rows != null) |
|---|
| 740 | { |
|---|
| 741 | foreach ($content_rows as $content_row) |
|---|
| 742 | { |
|---|
| 743 | // Create a content group object and grab only those that have content for the current Node |
|---|
| 744 | $content_group = Content :: getObject($content_row['content_group_id']); |
|---|
| 745 | if ($content_group->getDisplayNumElements() >= 1) |
|---|
| 746 | { |
|---|
| 747 | if ($content_group->isDisplayableAt($this)) |
|---|
| 748 | { |
|---|
| 749 | // Disable logging and allow content to expand ( if possible ) |
|---|
| 750 | $content_group->setExpandStatus(true); |
|---|
| 751 | $content_group->setLoggingStatus(false); |
|---|
| 752 | $retval[] = $content_group; |
|---|
| 753 | } |
|---|
| 754 | } |
|---|
| 755 | } |
|---|
| 756 | } |
|---|
| 757 | return $retval; |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | /** Return all the nodes |
|---|
| 761 | */ |
|---|
| 762 | static function getAllNodes() |
|---|
| 763 | { |
|---|
| 764 | global $db; |
|---|
| 765 | |
|---|
| 766 | $db->ExecSql("SELECT * FROM nodes", $nodes, false); |
|---|
| 767 | |
|---|
| 768 | if ($nodes == null) |
|---|
| 769 | throw new Exception(_("No nodes could not be found in the database")); |
|---|
| 770 | |
|---|
| 771 | return $nodes; |
|---|
| 772 | } |
|---|
| 773 | |
|---|
| 774 | static function getAllNodesOrdered($order_by) |
|---|
| 775 | { |
|---|
| 776 | global $db; |
|---|
| 777 | |
|---|
| 778 | $db->ExecSql("SELECT * FROM nodes ORDER BY $order_by", $nodes, false); |
|---|
| 779 | |
|---|
| 780 | if ($nodes == null) |
|---|
| 781 | throw new Exception(_("No nodes could not be found in the database")); |
|---|
| 782 | |
|---|
| 783 | return $nodes; |
|---|
| 784 | } |
|---|
| 785 | |
|---|
| 786 | static function getAllNodesWithStatus() |
|---|
| 787 | { |
|---|
| 788 | global $db; |
|---|
| 789 | |
|---|
| 790 | $db->ExecSql("SELECT node_id, name, last_heartbeat_user_agent, (NOW()-last_heartbeat_timestamp) AS since_last_heartbeat, last_heartbeat_ip, CASE WHEN ((NOW()-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS online, creation_date, node_deployment_status FROM nodes ORDER BY node_id", $nodes, false); |
|---|
| 791 | |
|---|
| 792 | if ($nodes == null) |
|---|
| 793 | throw new Exception(_("No nodes could not be found in the database")); |
|---|
| 794 | |
|---|
| 795 | return $nodes; |
|---|
| 796 | } |
|---|
| 797 | |
|---|
| 798 | static function getAllDeploymentStatus() |
|---|
| 799 | { |
|---|
| 800 | global $db; |
|---|
| 801 | |
|---|
| 802 | $db->ExecSql("SELECT * FROM node_deployment_status", $statuses, false); |
|---|
| 803 | if ($statuses == null) |
|---|
| 804 | throw new Exception(_("No deployment statues could be found in the database")); |
|---|
| 805 | |
|---|
| 806 | $statuses_array = array (); |
|---|
| 807 | foreach ($statuses as $status) |
|---|
| 808 | array_push($statuses_array, $status['node_deployment_status']); |
|---|
| 809 | |
|---|
| 810 | return $statuses_array; |
|---|
| 811 | } |
|---|
| 812 | |
|---|
| 813 | /** The list of users online at this node |
|---|
| 814 | * @return An array of User object, or en empty array */ |
|---|
| 815 | function getOnlineUsers() |
|---|
| 816 | { |
|---|
| 817 | global $db; |
|---|
| 818 | $retval = array (); |
|---|
| 819 | $db->ExecSql("SELECT users.user_id FROM users,connections WHERE connections.token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND connections.node_id='{$this->id}'", $users, false); |
|---|
| 820 | if ($users != null) |
|---|
| 821 | { |
|---|
| 822 | foreach ($users as $user_row) |
|---|
| 823 | { |
|---|
| 824 | $retval[] = User :: getObject($user_row['user_id']); |
|---|
| 825 | } |
|---|
| 826 | } |
|---|
| 827 | return $retval; |
|---|
| 828 | } |
|---|
| 829 | |
|---|
| 830 | function getOwners() |
|---|
| 831 | { |
|---|
| 832 | global $db; |
|---|
| 833 | $retval = array (); |
|---|
| 834 | $db->ExecSql("SELECT user_id FROM node_owners WHERE node_id='{$this->id}'", $owners, false); |
|---|
| 835 | if ($owners != null) |
|---|
| 836 | { |
|---|
| 837 | foreach ($owners as $owner_row) |
|---|
| 838 | { |
|---|
| 839 | $retval[] = User :: getObject($owner_row['user_id']); |
|---|
| 840 | } |
|---|
| 841 | } |
|---|
| 842 | return $retval; |
|---|
| 843 | } |
|---|
| 844 | |
|---|
| 845 | function addOwner($user) |
|---|
| 846 | { |
|---|
| 847 | global $db; |
|---|
| 848 | if (!$db->ExecSqlUpdate("INSERT INTO node_owners (node_id, user_id) VALUES ('{$this->getId()}','{$user->getId()}')", false)) |
|---|
| 849 | throw new Exception(_('Could not add owner')); |
|---|
| 850 | } |
|---|
| 851 | |
|---|
| 852 | function removeOwner($user) |
|---|
| 853 | { |
|---|
| 854 | global $db; |
|---|
| 855 | if (!$db->ExecSqlUpdate("DELETE FROM node_owners WHERE node_id='{$this->getId()}' AND user_id='{$user->getId()}'", false)) |
|---|
| 856 | throw new Exception(_('Could not remove owner')); |
|---|
| 857 | } |
|---|
| 858 | |
|---|
| 859 | /** Is the user an owner of the Node? |
|---|
| 860 | * @return true our false*/ |
|---|
| 861 | function isOwner(User $user) |
|---|
| 862 | { |
|---|
| 863 | global $db; |
|---|
| 864 | if ($user != null) |
|---|
| 865 | { |
|---|
| 866 | $user_id = $user->getId(); |
|---|
| 867 | $retval = false; |
|---|
| 868 | $db->ExecSqlUniqueRes("SELECT * FROM node_owners WHERE node_id='{$this->id}' AND user_id='{$user_id}'", $row, false); |
|---|
| 869 | if ($row != null) |
|---|
| 870 | { |
|---|
| 871 | $retval = true; |
|---|
| 872 | } |
|---|
| 873 | } |
|---|
| 874 | return $retval; |
|---|
| 875 | } |
|---|
| 876 | |
|---|
| 877 | function nodeExists($id) |
|---|
| 878 | { |
|---|
| 879 | global $db; |
|---|
| 880 | $id_str = $db->EscapeString($id); |
|---|
| 881 | $sql = "SELECT * FROM nodes WHERE node_id='{$id_str}'"; |
|---|
| 882 | $db->ExecSqlUniqueRes($sql, $row, false); |
|---|
| 883 | return $row; |
|---|
| 884 | } |
|---|
| 885 | |
|---|
| 886 | /** Warning, the semantics of this function will change * |
|---|
| 887 | * @deprecated version - 2005-04-29 USE getOnlineUsers instead |
|---|
| 888 | * */ |
|---|
| 889 | public static function getAllOnlineUsers() |
|---|
| 890 | { |
|---|
| 891 | global $db; |
|---|
| 892 | $db->ExecSql("SELECT * FROM connections,users,nodes WHERE token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND nodes.node_id=connections.node_id ORDER BY timestamp_in DESC", $online_users); |
|---|
| 893 | return $online_users; |
|---|
| 894 | } |
|---|
| 895 | |
|---|
| 896 | /** Reloads the object from the database. Should normally be called after a set operation */ |
|---|
| 897 | protected function refresh() |
|---|
| 898 | { |
|---|
| 899 | $this->__construct($this->id); |
|---|
| 900 | } |
|---|
| 901 | |
|---|
| 902 | } // End class |
|---|
| 903 | ?> |
|---|