| [400] | 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 Node.php |
|---|
| 22 | * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca> |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | require_once BASEPATH.'include/common.php'; |
|---|
| 26 | |
|---|
| 27 | /** Abstract a Node. A Node is an actual physical transmitter. */ |
|---|
| [402] | 28 | class Node { |
|---|
| [400] | 29 | private $mRow; |
|---|
| 30 | private $mId; |
|---|
| 31 | |
|---|
| 32 | /** Instantiate a node object |
|---|
| 33 | * @param $id The id of the requested node |
|---|
| 34 | * @return a Node object, or null if there was an error |
|---|
| 35 | */ |
|---|
| [402] | 36 | static function getObject($id) { |
|---|
| [400] | 37 | $object = null; |
|---|
| 38 | $object = new self($id); |
|---|
| 39 | return $object; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | /** Create a new Node in the database |
|---|
| 43 | * @param $id The id to be given to the new node |
|---|
| 44 | * @return the newly created Node object, or null if there was an error |
|---|
| 45 | */ |
|---|
| [402] | 46 | static function createObject($id) { |
|---|
| 47 | global $db; |
|---|
| 48 | |
|---|
| [400] | 49 | $object = null; |
|---|
| 50 | $id_str = $db->EscapeString($id); |
|---|
| 51 | $sql = "INSERT INTO nodes values (node_id) VALUES ('$id_str')"; |
|---|
| 52 | $db->ExecSqlUpdate($sql, false); |
|---|
| 53 | $object = new self($id); |
|---|
| 54 | return $object; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | /** @param $node_id The id of the node */ |
|---|
| [402] | 58 | function __construct($node_id) { |
|---|
| 59 | global $db; |
|---|
| [400] | 60 | $node_id_str = $db->EscapeString($node_id); |
|---|
| [402] | 61 | $sql = "SELECT * FROM nodes WHERE node_id='$node_id_str'"; |
|---|
| [400] | 62 | $db->ExecSqlUniqueRes($sql, $row, false); |
|---|
| [402] | 63 | if ($row == null) { |
|---|
| 64 | throw new Exception(_("The id $node_id_str could not be found in the database"), "EXCEPTION_CREATE_OBJECT_FAILED"); |
|---|
| 65 | } |
|---|
| 66 | $this->mRow = $row; |
|---|
| 67 | $this->mId = $row['node_id']; |
|---|
| [400] | 68 | }//End class |
|---|
| 69 | |
|---|
| [402] | 70 | /** Return the name of the node |
|---|
| 71 | */ |
|---|
| 72 | function getName() { |
|---|
| 73 | return $this->mRow['name']; |
|---|
| [400] | 74 | } |
|---|
| [402] | 75 | |
|---|
| 76 | function getID() { |
|---|
| 77 | return $this->mRow['node_id']; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | function getRSSURL() { |
|---|
| 81 | return $this->mRow['rss_url']; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | function getEmail() { |
|---|
| 85 | return $this->mRow['public_email']; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | function getDeploymentStatus() { |
|---|
| 89 | return $this->mRow['node_deployment_status']; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | /** Return all the nodes |
|---|
| 93 | */ |
|---|
| 94 | static function getAllNodes() { |
|---|
| 95 | global $db; |
|---|
| 96 | |
|---|
| 97 | $db->ExecSql("SELECT * FROM nodes", $nodes, false); |
|---|
| 98 | if ($nodes == null) { |
|---|
| 99 | throw new Exception(_("No nodes could not be found in the database"), "EXCEPTION_NO_NODES"); |
|---|
| 100 | } |
|---|
| 101 | return $nodes; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | static function getAllDeploymentStatus() { |
|---|
| 105 | global $db; |
|---|
| 106 | |
|---|
| 107 | $db->ExecSql("SELECT * FROM node_deployment_status", $statuses, false); |
|---|
| 108 | if ($statuses == null) { |
|---|
| 109 | throw new Exception(_("No deployment statues could be found in the database"), "EXCEPTION_NO_STATUSES"); |
|---|
| 110 | } |
|---|
| 111 | $statuses_array = array(); |
|---|
| 112 | foreach ($statuses as $status) { |
|---|
| 113 | array_push($statuses_array, $status['node_deployment_status']); |
|---|
| 114 | } |
|---|
| 115 | return $statuses_array; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | function getOnlineUsers() { |
|---|
| 119 | global $db; |
|---|
| 120 | $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->mId}'", $users, false); |
|---|
| 121 | return $users; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| [400] | 124 | }// End class |
|---|
| 125 | ?> |
|---|