root/trunk/wifidog-auth/wifidog/classes/Node.php @ 708

Revision 708, 41.4 KB (checked in by benoitg, 8 years ago)

2005-09-01 Benoit Gr�goire <bock@…>

WARNING: DO NOT use the CVS auth server in production until further notice.
Massive internal changes are underway.
Use the release tagged 1.0m1 in production.

  • Network abstraction mostly complete, including UI. All that is missing is new network creation, network stakeholder UI and testing.
  • Cleanup the config file of all the now unneeded constants. Note that the install script is currently broken. There can now be multiple networks on the server. The install script will have to make sure that there is at least one, with one super-admin
  • 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 Node.php
22 * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca>
23 */
24
25require_once BASEPATH.'include/common.php';
26require_once 'Content/ContentGroup.php';
27require_once 'User.php';
28require_once 'GisPoint.php';
29require_once 'AbstractGeocoder.php';
30
31/** Abstract a Node.  A Node is an actual physical transmitter. */
32class Node implements GenericObject
33{
34        private $mRow;
35        private $mdB; /**< An AbstractDb instance */
36        private $id;
37        private static $current_node_id = null;
38
39        /** Instantiate a node object
40         * @param $id The id of the requested node
41         * @return a Node object, or null if there was an error
42         */
43        static function getObject($id)
44        {
45                $object = null;
46                $object = new self($id);
47                return $object;
48        }
49
50        /** Get the current node for which the portal is displayed or to which a user is physically connected.
51         * @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.
52         * @return a Node object, or null if it can't be found.
53         */
54        static function getCurrentNode($real_node_only = false)
55        {
56                $object = null;
57                if (self :: $current_node_id != null && $real_node_only == false)
58                {
59                        $object = new self(self :: $current_node_id);
60                }
61                else
62                {
63                        $object = self :: getCurrentRealNode();
64                }
65                return $object;
66        }
67
68        /** Set the current node where the user is to be considered connected to.  (For portal and content display purpuses, among other.
69         * @param $node Node.  The new current node.
70         * @return true  */
71        static function setCurrentNode(Node $node)
72        {
73                self :: $current_node_id = $node->GetId();
74                return true;
75        }
76
77        /** 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
78         * @param        * @return a Node object, or null if it can't be found.
79         */
80        public static function getCurrentRealNode()
81        {
82                global $db;
83                $retval = null;
84                $sql = "SELECT node_id, last_heartbeat_ip from nodes WHERE last_heartbeat_ip='$_SERVER[REMOTE_ADDR]'";
85                $db->ExecSql($sql, $node_rows, false);
86                $num_match = count($node_rows);
87                if ($num_match == 0)
88                {
89
90                        // User is not physically connected to a node
91                        $retval = null;
92                }
93                else
94                        if ($num_match = 1)
95                        {
96                                // Only a single node matches, the user is presumed to be there
97                                $retval = new self($node_rows[0]['node_id']);
98                        }
99                        else
100                        {
101                                /* We have more than one node matching the IP (the nodes are behind the same NAT).
102                                 * We will try to discriminate by finding which node the user last authenticated against.
103                                 * If the IP matches, we can be pretty certain the user is there.
104                                 */
105                                $retval = null;
106                                $current_user = User :: getCurrentUser();
107                                if ($current_user != null)
108                                {
109                                        $current_user_id = $current_user->getId();
110                                        $_SERVER['REMOTE_ADDR'];
111                                        $sql = "SELECT node_id, last_heartbeat_ip from connections NATURAL JOIN nodes WHERE user_id='$current_user_id' ORDER BY last_updated DESC ";
112                                        $db->ExecSql($sql, $node_rows, false);
113                                        $node_row = $node_rows[0];
114                                        if ($node_row != null && $node_row['last_heartbeat_ip'] == $_SERVER['REMOTE_ADDR'])
115                                        {
116                                                $retval = new self($node_row['node_id']);
117                                        }
118                                }
119                        }
120                return $retval;
121        }
122
123        public function delete(& $errmsg)
124        {
125                $retval = false;
126                $user = User :: getCurrentUser();
127                if ($this->isOwner($user) || $user->isSuperAdmin())
128                {
129                        $errmsg = _('Access denied!');
130                }
131
132                global $db;
133                $id = $db->EscapeString($this->getId());
134                if (!$db->ExecSqlUpdate("DELETE FROM nodes WHERE node_id='{$id}'", false))
135                {
136                        $errmsg = _('Could not delete node!');
137                }
138                else
139                {
140                        $retval = true;
141                }
142
143                return $retval;
144        }
145
146        /** Create a new Node in the database
147         * @param $id The id to be given to the new node
148         * @return the newly created Node object, or null if there was an error
149         */
150        static function createNewObject()
151        {
152                global $db;
153
154                $node_id = $db->EscapeString(get_guid());
155                $object = self::createNewNode($node_id, Network::getCurrentNetwork());
156                return $object;
157        }
158
159        /** Create a new Node in the database
160         * @param $node_id The id to be given to the new node
161         * @param $network Network object.  The node's network
162         * @todo Implement network
163         * @return the newly created Node object, or null if there was an error
164         */
165        static function createNewNode($node_id, Network $network)
166        {
167                global $db;
168                $node_id = $db->EscapeString($node_id);
169                $node_deployment_status = $db->EscapeString("IN_PLANNING");
170                $node_name = _("New node");
171                if (Node :: nodeExists($node_id))
172                        throw new Exception(_('This node already exists.'));
173
174                $sql = "INSERT INTO nodes (node_id, creation_date, node_deployment_status, name) VALUES ('$node_id', NOW(),'$node_deployment_status', '$node_name')";
175
176                if (!$db->ExecSqlUpdate($sql, false))
177                {
178                        throw new Exception(_('Unable to insert new node into database!'));
179                }
180                $object = new self($node_id);
181                return $object;
182        }
183
184        /** Get an interface to pick a node.
185        * @param $user_prefix A identifier provided by the programmer to recognise it's generated html form
186        * @param $sql_additional_where Addidional where conditions to restrict the candidate objects
187        * @return html markup
188        */
189        public static function getSelectNodeUI($user_prefix, $sql_additional_where = null)
190        {
191                global $db;
192                $html = '';
193                $name = "{$user_prefix}";
194                $html .= "Node: \n";
195                $sql = "SELECT node_id, name from nodes WHERE 1=1 $sql_additional_where ORDER BY node_id";
196                $db->ExecSql($sql, $node_rows, false);
197                if ($node_rows != null)
198                {
199                        $i = 0;
200                        foreach ($node_rows as $node_row)
201                        {
202                                $tab[$i][0] = $node_row['node_id'];
203                                $tab[$i][1] = $node_row['node_id'].": ".$node_row['name'];
204                                $i ++;
205                        }
206                        $html .= FormSelectGenerator :: generateFromArray($tab, null, $name, null, false);
207                }
208                return $html;
209        }
210
211        /** Get the selected Network object.
212         * @param $user_prefix A identifier provided by the programmer to recognise it's generated form
213         * @return the node object
214         */
215        static function processSelectNodeUI($user_prefix)
216        {
217                $object = null;
218                $name = "{$user_prefix}";
219                return new self($_REQUEST[$name]);
220        }
221
222        /** Get an interface to select the deployment status
223        * @param $user_prefix A identifier provided by the programmer to recognise it's generated html form
224        * @return html markup
225        */
226        public function getSelectDeploymentStatus($user_prefix)
227        {
228                global $db;
229                $html = '';
230                $name = "{$user_prefix}";
231                $status_list = self :: getAllDeploymentStatus();
232                if ($status_list != null)
233                {
234                        $tab = array ();
235                        foreach ($status_list as $status)
236                                $tab[] = array ($status, $status);
237                        $html .= FormSelectGenerator :: generateFromArray($tab, $this->getDeploymentStatus(), $name, null, false);
238                }
239                return $html;
240        }
241
242        /** Get the selected deployment status
243         * @param $user_prefix A identifier provided by the programmer to recognise it's generated form
244         * @return the deployment status
245         */
246        public function processSelectDeploymentStatus($user_prefix)
247        {
248                $object = null;
249                $name = "{$user_prefix}";
250                return $_REQUEST[$name];
251        }
252
253        /** @param $node_id The id of the node */
254        private function __construct($node_id)
255        {
256                global $db;
257                $this->mDb = & $db;
258               
259                $node_id_str = $db->EscapeString($node_id);
260                $sql = "SELECT * FROM nodes WHERE node_id='$node_id_str'";
261                $db->ExecSqlUniqueRes($sql, $row, false);
262                if ($row == null)
263                {
264                        throw new Exception(_("The id $node_id_str could not be found in the database"));
265                }
266                $this->mRow = $row;
267                $this->id = $row['node_id'];
268        }
269
270        function getId()
271        {
272                return $this->id;
273        }
274
275        /** Gets the Network to which the node belongs
276         * @return Network object (never returns null)
277         */
278        public function getNetwork()
279        {
280                        return Network::getObject($this->mRow['network_id']);
281        }
282
283        /** Get a GisPoint object ; altide is not supported yet
284         */
285        function getGisLocation()
286        {
287                // Altitude is not supported yet
288                return new GisPoint($this->mRow['latitude'], $this->mRow['longitude'], 0);
289        }
290
291        function setGisLocation($pt)
292        {
293                if (!empty ($pt))
294                {
295                        $lat = $this->mDb->EscapeString($pt->getLatitude());
296                        $long = $this->mDb->EscapeString($pt->getLongitude());
297
298                        if (!empty ($lat) && !empty ($long))
299                                $this->mDb->ExecSqlUpdate("UPDATE nodes SET latitude = $lat, longitude = $long WHERE node_id = '{$this->getId()}'");
300                        else
301                                $this->mDb->ExecSqlUpdate("UPDATE nodes SET latitude = NULL, longitude = NULL WHERE node_id = '{$this->getId()}'");
302                        $this->refresh();
303                }
304        }
305
306        /** Return the name of the node
307         */
308        function getName()
309        {
310                return $this->mRow['name'];
311        }
312
313        function setName($name)
314        {
315                $name = $this->mDb->EscapeString($name);
316                $this->mDb->ExecSqlUpdate("UPDATE nodes SET name = '{$name}' WHERE node_id = '{$this->getId()}'");
317                $this->refresh();
318        }
319
320        function getHomePageURL()
321        {
322                return $this->mRow['home_page_url'];
323        }
324
325        function setHomePageUrl($url)
326        {
327                $url = $this->mDb->EscapeString($url);
328                $this->mDb->ExecSqlUpdate("UPDATE nodes SET home_page_url = '{$url}' WHERE node_id = '{$this->getId()}'");
329                $this->refresh();
330        }
331
332        function getDescription()
333        {
334                return $this->mRow['description'];
335        }
336
337        function setDescription($description)
338        {
339                $description = $this->mDb->EscapeString($description);
340                $this->mDb->ExecSqlUpdate("UPDATE nodes SET description = '{$description}' WHERE node_id = '{$this->getId()}'");
341                $this->refresh();
342        }
343
344        function getMapURL()
345        {
346                return $this->mRow['map_url'];
347        }
348
349        function setMapURL($url)
350        {
351                $url = $this->mDb->EscapeString($url);
352                $this->mDb->ExecSqlUpdate("UPDATE nodes SET map_url = '{$url}' WHERE node_id = '{$this->getId()}'");
353                $this->refresh();
354        }
355
356        public function getCivicNumber()
357        {
358                return $this->mRow['civic_number'];
359        }
360
361        public function setCivicNumber($civic_number)
362        {
363                $civic_number = $this->mDb->EscapeString($civic_number);
364                $this->mDb->ExecSqlUpdate("UPDATE nodes SET civic_number = '{$civic_number}' WHERE node_id = '{$this->getId()}'");
365                $this->refresh();
366        }
367
368        public function getStreetName()
369        {
370                return $this->mRow['street_name'];
371        }
372
373        public function setStreetName($street_name)
374        {
375                $street_name = $this->mDb->EscapeString($street_name);
376                $this->mDb->ExecSqlUpdate("UPDATE nodes SET street_name = '{$street_name}' WHERE node_id = '{$this->getId()}'");
377                $this->refresh();
378        }
379
380        public function getCity()
381        {
382                return $this->mRow['city'];
383        }
384
385        public function setCity($city)
386        {
387                $city = $this->mDb->EscapeString($city);
388                $this->mDb->ExecSqlUpdate("UPDATE nodes SET city = '{$city}' WHERE node_id = '{$this->getId()}'");
389                $this->refresh();
390        }
391
392        public function getProvince()
393        {
394                return $this->mRow['province'];
395        }
396
397        public function setProvince($province)
398        {
399                $province = $this->mDb->EscapeString($province);
400                $this->mDb->ExecSqlUpdate("UPDATE nodes SET province = '{$province}' WHERE node_id = '{$this->getId()}'");
401                $this->refresh();
402        }
403
404        public function getCountry()
405        {
406                return $this->mRow['country'];
407        }
408
409        protected function setCountry($country)
410        {
411                $country = $this->mDb->EscapeString($country);
412                $this->mDb->ExecSqlUpdate("UPDATE nodes SET country = '{$country}' WHERE node_id = '{$this->getId()}'");
413                $this->refresh();
414        }
415
416        public function getPostalCode()
417        {
418                return $this->mRow['postal_code'];
419        }
420
421        public function setPostalCode($postal_code)
422        {
423                $postal_code = $this->mDb->EscapeString($postal_code);
424                $this->mDb->ExecSqlUpdate("UPDATE nodes SET postal_code = '{$postal_code}' WHERE node_id = '{$this->getId()}'");
425                $this->refresh();
426        }
427
428        function getTelephone()
429        {
430                return $this->mRow['public_phone_number'];
431        }
432
433        function setTelephone($phone)
434        {
435                $phone = $this->mDb->EscapeString($phone);
436                $this->mDb->ExecSqlUpdate("UPDATE nodes SET public_phone_number = '{$phone}' WHERE node_id = '{$this->getId()}'");
437                $this->refresh();
438        }
439
440        function getTransitInfo()
441        {
442                return $this->mRow['mass_transit_info'];
443        }
444
445        function setTransitInfo($transit_info)
446        {
447                $transit_info = $this->mDb->EscapeString($transit_info);
448                $this->mDb->ExecSqlUpdate("UPDATE nodes SET mass_transit_info = '{$transit_info}' WHERE node_id = '{$this->getId()}'");
449                $this->refresh();
450        }
451
452        function getEmail()
453        {
454                return $this->mRow['public_email'];
455        }
456
457        function setEmail($email)
458        {
459                $email = $this->mDb->EscapeString($email);
460                $this->mDb->ExecSqlUpdate("UPDATE nodes SET public_email = '{$email}' WHERE node_id = '{$this->getId()}'");
461                $this->refresh();
462        }
463
464        function getDeploymentStatus()
465        {
466                return $this->mRow['node_deployment_status'];
467        }
468
469        function setDeploymentStatus($status)
470        {
471                $status = $this->mDb->EscapeString($status);
472                $this->mDb->ExecSqlUpdate("UPDATE nodes SET node_deployment_status = '{$status}' WHERE node_id = '{$this->getId()}'");
473                $this->refresh();
474        }
475
476        /** Retreives the admin interface of this object.
477         * @return The HTML fragment for this interface */
478        public function getAdminUI()
479        {
480                //TODO: Most of this code will be moved to Hotspot class when the abtraction will be completed
481
482                $html = '';
483                $html .= "<div class='admin_container'>\n";
484                $html .= "<div class='admin_class'>Node (".get_class($this)." instance)</div>\n";
485                $html .= "<h3>"._("Edit a hotspot")."</h3>\n";
486
487                // Information about the node
488                $html .= "<div class='admin_section_container'>\n";
489                $html .= "<div class='admin_section_title'>"._("Information about the node:")."</div>\n";
490
491                // Node ID
492                $value = htmlspecialchars($this->getId(), ENT_QUOTES);
493                $html .= "<div class='admin_section_container'>\n";
494                $html .= "<div class='admin_section_title'>"._("ID")." : {$value}</div>\n";
495                //$html .= "<div class='admin_section_data'>\n";
496                //$name = "node_".$this->getId()."_id";
497                //$html .= "<input type='text' readonly='' size='10' value='$value' name='$name'>\n";
498                //$html .= "</div>\n";
499                $html .= "</div>\n";
500
501                // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores )
502                $hashed_node_id = md5($this->getId());
503               
504                // Name
505                $html .= "<div class='admin_section_container'>\n";
506                $html .= "<div class='admin_section_title'>"._("Name")." : </div>\n";
507                $html .= "<div class='admin_section_data'>\n";
508                $name = "node_".$hashed_node_id."_name";
509                $value = htmlspecialchars($this->getName(), ENT_QUOTES);
510                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
511                $html .= "</div>\n";
512                $html .= "</div>\n";
513
514                // Homepage URL
515                $html .= "<div class='admin_section_container'>\n";
516                $html .= "<div class='admin_section_title'>"._("Homepage URL")." : </div>\n";
517                $html .= "<div class='admin_section_data'>\n";
518                $name = "node_".$hashed_node_id."_homepage_url";
519                $value = htmlspecialchars($this->getHomePageURL(), ENT_QUOTES);
520                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
521                $html .= "</div>\n";
522                $html .= "</div>\n";
523
524                // Description
525                $html .= "<div class='admin_section_container'>\n";
526                $html .= "<div class='admin_section_title'>"._("Description")." : </div>\n";
527                $html .= "<div class='admin_section_data'>\n";
528                $name = "node_".$hashed_node_id."_description";
529                $value = htmlspecialchars($this->getDescription(), ENT_QUOTES);
530                $html .= "<textarea cols='50' rows='5' name='$name'>$value</textarea>\n";
531                $html .= "</div>\n";
532                $html .= "</div>\n";
533
534                // Map URL
535                $html .= "<div class='admin_section_container'>\n";
536                $html .= "<div class='admin_section_title'>"._("Map URL")." : </div>\n";
537                $html .= "<div class='admin_section_data'>\n";
538                $name = "node_".$hashed_node_id."_map_url";
539                $value = htmlspecialchars($this->getMapURL(), ENT_QUOTES);
540                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
541                $html .= "</div>\n";
542                $html .= "</div>\n";
543
544                // Civic number
545                $html .= "<div class='admin_section_container'>\n";
546                $html .= "<div class='admin_section_title'>"._("Civic number")." : </div>\n";
547                $html .= "<div class='admin_section_data'>\n";
548                $name = "node_".$hashed_node_id."_civic_number";
549                $value = htmlspecialchars($this->getCivicNumber(), ENT_QUOTES);
550                $html .= "<input type='text' size ='10' value='$value' name='$name'>\n";
551                $html .= "</div>\n";
552                $html .= "</div>\n";
553
554                // Street name
555                $html .= "<div class='admin_section_container'>\n";
556                $html .= "<div class='admin_section_title'>"._("Street name")." : </div>\n";
557                $html .= "<div class='admin_section_data'>\n";
558                $name = "node_".$hashed_node_id."_street_name";
559                $value = htmlspecialchars($this->getStreetName(), ENT_QUOTES);
560                $html .= "<input type='text' size ='25' value='$value' name='$name'>\n";
561                $html .= "</div>\n";
562                $html .= "</div>\n";
563
564                // City
565                $html .= "<div class='admin_section_container'>\n";
566                $html .= "<div class='admin_section_title'>"._("City")." : </div>\n";
567                $html .= "<div class='admin_section_data'>\n";
568                $name = "node_".$hashed_node_id."_city";
569                $value = htmlspecialchars($this->getCity(), ENT_QUOTES);
570                $html .= "<input type='text' size ='25' value='$value' name='$name'>\n";
571                $html .= "</div>\n";
572                $html .= "</div>\n";
573
574                // Province
575                $html .= "<div class='admin_section_container'>\n";
576                $html .= "<div class='admin_section_title'>"._("Province / State")." : </div>\n";
577                $html .= "<div class='admin_section_data'>\n";
578                $name = "node_".$hashed_node_id."_province";
579                $value = htmlspecialchars($this->getProvince(), ENT_QUOTES);
580                $html .= "<input type='text' size ='15' value='$value' name='$name'>\n";
581                $html .= "</div>\n";
582                $html .= "</div>\n";
583
584                // Postal Code
585                $html .= "<div class='admin_section_container'>\n";
586                $html .= "<div class='admin_section_title'>"._("Postal code")." : </div>\n";
587                $html .= "<div class='admin_section_data'>\n";
588                $name = "node_".$hashed_node_id."_postal_code";
589                $value = htmlspecialchars($this->getPostalCode(), ENT_QUOTES);
590                $html .= "<input type='text' size ='10' value='$value' name='$name'>\n";
591                $html .= "</div>\n";
592                $html .= "</div>\n";
593
594                // Country
595                $html .= "<div class='admin_section_container'>\n";
596                $html .= "<div class='admin_section_title'>"._("Country")." : </div>\n";
597                $html .= "<div class='admin_section_data'>\n";
598                $name = "node_".$hashed_node_id."_country";
599                $value = htmlspecialchars($this->getCountry(), ENT_QUOTES);
600                $html .= "<input type='text' size ='15' value='$value' name='$name'>\n";
601                $html .= "</div>\n";
602                $html .= "</div>\n";
603
604                // Public phone #
605                $html .= "<div class='admin_section_container'>\n";
606                $html .= "<div class='admin_section_title'>"._("Public phone number")." : </div>\n";
607                $html .= "<div class='admin_section_data'>\n";
608                $name = "node_".$hashed_node_id."_public_phone";
609                $value = htmlspecialchars($this->getTelephone(), ENT_QUOTES);
610                $html .= "<input type='text' size ='20' value='$value' name='$name'>\n";
611                $html .= "</div>\n";
612                $html .= "</div>\n";
613
614                // Public mail
615                $html .= "<div class='admin_section_container'>\n";
616                $html .= "<div class='admin_section_title'>"._("Public email")." : </div>\n";
617                $html .= "<div class='admin_section_data'>\n";
618                $name = "node_".$hashed_node_id."_public_email";
619                $value = htmlspecialchars($this->getEmail(), ENT_QUOTES);
620                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
621                $html .= "</div>\n";
622                $html .= "</div>\n";
623
624                // Mass transit info
625                $html .= "<div class='admin_section_container'>\n";
626                $html .= "<div class='admin_section_title'>"._("Mass transit info")." : </div>\n";
627                $html .= "<div class='admin_section_data'>\n";
628                $name = "node_".$hashed_node_id."_mass_transit_info";
629                $value = htmlspecialchars($this->getTransitInfo(), ENT_QUOTES);
630                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
631                $html .= "</div>\n";
632                $html .= "</div>\n";
633
634                // Deployment status
635                $html .= "<div class='admin_section_container'>\n";
636                $html .= "<div class='admin_section_title'>"._("Node deployment status")." : </div>\n";
637                $html .= "<div class='admin_section_data'>\n";
638                $name = "node_".$hashed_node_id."_deployment_status";
639                $html .= self :: getSelectDeploymentStatus($name);
640                $html .= "</div>\n";
641                $html .= "</div>\n";
642
643                // End of information section
644                $html .= "</div>\n";
645
646                // Node GIS data
647                $html .= "<div class='admin_section_container'>\n";
648                $html .= "<div class='admin_section_title'>"._("GIS data")." : </div>\n";
649
650                // Build HTML form fields names & values
651                $gis_point = $this->getGisLocation();
652                $gis_lat_name = "node_".$hashed_node_id."_gis_latitude";
653                $gis_lat_value = htmlspecialchars($gis_point->getLatitude(), ENT_QUOTES);
654                $gis_long_name = "node_".$hashed_node_id."_gis_longitude";
655                $gis_long_value = htmlspecialchars($gis_point->getLongitude(), ENT_QUOTES);
656
657                $html .= "<div class='admin_section_container'>\n";
658                $html .= "<div class='admin_section_title'>"._("Latitude")." : </div>\n";
659                $html .= "<div class='admin_section_data'>\n";
660                $html .= "<input type='text' size ='15' value='$gis_lat_value' id='$gis_lat_name' name='$gis_lat_name'>\n";
661                $html .= "</div>\n";
662                $html .= "</div>\n";
663
664                $html .= "<div class='admin_section_container'>\n";
665                $html .= "<div class='admin_section_title'>"._("Longitude")." : </div>\n";
666                $html .= "<div class='admin_section_data'>\n";
667                $html .= "<input type='text' size ='15' value='$gis_long_value' id='$gis_long_name' name='$gis_long_name'>\n";
668                $html .= "</div>\n";
669                $html .= "</div>\n";
670
671                /*
672                 * If Google Maps is enabled, call the geocoding service,
673                 * then use Google Maps to let the user choose a more precise location
674                 *
675                 * otherwise
676                 *
677                 * Simply use a geocoding service.
678                 */
679
680                if (defined('GMAPS_HOTSPOTS_MAP_ENABLED') && GMAPS_HOTSPOTS_MAP_ENABLED === true)
681                {
682                        $html .= "<div class='admin_section_container'>\n";
683                        $html .= "<div class='admin_section_data'>\n";
684                        $html .= "<input type='submit' name='geocode_only' value='"._("Geocode only")."'>\n";
685                        $html .= "<input type='button' name='google_maps_geocode' value='"._("Check using Google Maps")."' onClick='window.open(\"hotspot_location_map.php?node_id={$this->getId()}\", \"hotspot_location\", \"toolbar=0,scrollbars=1,resizable=1,location=0,statusbar=0,menubar=0,width=600,height=600\");'>\n";
686                        $html .= " ("._("Use a geocoding service, then use Google Maps to pinpoint the exact location.").")";
687                        $html .= "</div>\n";
688                        $html .= "</div>\n";
689                }
690                else
691                {
692                        $html .= "<div class='admin_section_container'>\n";
693                        $html .= "<div class='admin_section_data'>\n";
694                        $html .= "<input type='submit' name='geocode_only' value='"._("Geocode location")."'>\n";
695                        $html .= " ("._("Use a geocoding service").")";
696                        $html .= "</div>\n";
697                        $html .= "</div>\n";
698                }
699
700                // End of GIS data
701                $html .= "</div>\n";
702
703                // Owners management
704                $html .= "<div class='admin_section_container'>\n";
705                $html .= "<div class='admin_section_title'>"._("Node owners")." : </div>\n";
706                $html .= "<ul class='admin_section_list'>\n";
707                foreach ($this->getOwners() as $owner)
708                {
709                        $html .= "<li class='admin_section_list_item'>\n";
710                        $html .= "<div class='admin_section_data'>\n";
711                        $html .= "{$owner->getUsername()}";
712                        $html .= "</div>\n";
713                        $html .= "<div class='admin_section_tools'>\n";
714                        $name = "node_{$this->getId()}_owner_{$owner->GetId()}_remove";
715                        $html .= "<input type='submit' name='$name' value='"._("Remove owner")."'>";
716                        $html .= "</div>\n";
717                        $html .= "</li>\n";
718                }
719                $html .= "<li class='admin_section_list_item'>\n";
720                $name = "node_{$this->getId()}_new_owner";
721                $html .= User :: getSelectUserUI($name);
722                $name = "node_{$this->getId()}_new_owner_submit";
723                $html .= "<input type='submit' name='$name' value='"._("Add owner")."'>";
724                $html .= "</li>\n";
725                $html .= "</ul>\n";
726                $html .= "</div>\n";
727                $html .= "</div>\n";
728
729                // Tech officers management
730                $html .= "<div class='admin_section_container'>\n";
731                $html .= "<div class='admin_section_title'>"._("Technical officers")." : </div>\n";
732                $html .= "<ul class='admin_section_list'>\n";
733                foreach ($this->getTechnicalOfficers() as $tech_officer)
734                {
735                        $html .= "<li class='admin_section_list_item'>\n";
736                        $html .= "<div class='admin_section_data'>\n";
737                        $html .= "{$tech_officer->getUsername()}";
738                        $html .= "</div>\n";
739                        $html .= "<div class='admin_section_tools'>\n";
740                        $name = "node_{$this->getId()}_tech_officer_{$tech_officer->GetId()}_remove";
741                        $html .= "<input type='submit' name='$name' value='"._("Remove technical officer")."'>";
742                        $html .= "</div>\n";
743                        $html .= "</li>\n";
744                }
745                $html .= "<li class='admin_section_list_item'>\n";
746                $name = "node_{$this->getId()}_new_tech_officer";
747                $html .= User :: getSelectUserUI($name);
748                $name = "node_{$this->getId()}_new_tech_officer_submit";
749                $html .= "<input type='submit' name='$name' value='"._("Add technical officer")."'>";
750                $html .= "</li>\n";
751                $html .= "</ul>\n";
752                $html .= "</div>\n";
753                $html .= "</div>\n";
754
755                // Display stats
756                $html .= "<div class='admin_section_container'>\n";
757                $html .= "<div class='admin_section_title'>"._("Statistics:")."</div>\n";
758                $html .= "<div class='admin_section_data'>\n";
759                $name = "node_".$this->id."_get_stats";
760                $html .= "<input type='submit' name='$name' value='"._("Get access statistics")."'>";
761                $html .= "</div>\n";
762                $html .= "</div>\n";
763
764                $html .= "<div class='admin_section_container'>\n";
765                $html .= "<div class='admin_section_title'>"._("Node content:")."</div>\n";
766
767                $html .= "<ul class='admin_section_list'>\n";
768                foreach ($this->getAllContent() as $content)
769                {
770                        $html .= "<li class='admin_section_list_item'>\n";
771                        $html .= "<div class='admin_section_data'>\n";
772                        $html .= $content->getListUI();
773                        $html .= "</div>\n";
774                        $html .= "<div class='admin_section_tools'>\n";
775                        $name = "node_".$this->id."_content_".$content->GetId()."_edit";
776                        $html .= "<input type='button' name='$name' value='"._("Edit")."' onClick='window.location.href = \"".GENERIC_OBJECT_ADMIN_ABS_HREF."?object_class=Content&action=edit&object_id=".$content->GetId()."\";'>\n";
777                        $name = "node_".$this->id."_content_".$content->GetId()."_erase";
778                        $html .= "<input type='submit' name='$name' value='"._("Remove")."'>";
779                        $html .= "</div>\n";
780                        $html .= "</li>\n";
781                }
782                $html .= "<li class='admin_section_list_item'>\n";
783                $name = "node_{$this->id}_new_content";
784                $html .= Content :: getSelectContentUI($name, "AND content_id NOT IN (SELECT content_id FROM node_has_content WHERE node_id='$this->id')");
785                $name = "node_{$this->id}_new_content_submit";
786                $html .= "<input type='submit' name='$name' value='"._("Add")."'>";
787                $html .= "</li>\n";
788                $html .= "</ul>\n";
789                $html .= "</div>\n";
790
791                return $html;
792        }
793
794        /** Process admin interface of this object.
795        */
796        public function processAdminUI()
797        {
798                $user = User :: getCurrentUser();
799                if (!$this->isOwner($user) && !$user->isSuperAdmin())
800                {
801                        throw new Exception(_('Access denied!'));
802                }
803
804                // Information about the node
805               
806                // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores )
807                $hashed_node_id = md5($this->getId());
808               
809                // Name
810                $name = "node_".$hashed_node_id."_name";
811                $this->setName($_REQUEST[$name]);
812
813                // Homepage URL
814                $name = "node_".$hashed_node_id."_homepage_url";
815                $this->setHomePageUrl($_REQUEST[$name]);
816
817                // Description
818                $name = "node_".$hashed_node_id."_description";
819                $this->setDescription($_REQUEST[$name]);
820
821                // Map URL
822                $name = "node_".$hashed_node_id."_map_url";
823                $this->setMapUrl($_REQUEST[$name]);
824
825                // Civic number
826                $name = "node_".$hashed_node_id."_civic_number";
827                $this->setCivicNumber($_REQUEST[$name]);
828
829                // Street name
830                $name = "node_".$hashed_node_id."_street_name";
831                $this->setStreetName($_REQUEST[$name]);
832
833                // City
834                $name = "node_".$hashed_node_id."_city";
835                $this->setCity($_REQUEST[$name]);
836
837                // Province
838                $name = "node_".$hashed_node_id."_province";
839                $this->setProvince($_REQUEST[$name]);
840
841                // Postal Code
842                $name = "node_".$hashed_node_id."_postal_code";
843                $this->setPostalCode($_REQUEST[$name]);
844
845                // Country
846                $name = "node_".$hashed_node_id."_country";
847                $this->setCountry($_REQUEST[$name]);
848
849                // Public phone #
850                $name = "node_".$hashed_node_id."_public_phone";
851                $this->setTelephone($_REQUEST[$name]);
852
853                // Public mail
854                $name = "node_".$hashed_node_id."_public_email";
855                $this->setEmail($_REQUEST[$name]);
856
857                // Mass transit info
858                $name = "node_".$hashed_node_id."_mass_transit_info";
859                $this->setTransitInfo($_REQUEST[$name]);
860
861                // Deployment status
862                $name = "node_".$hashed_node_id."_deployment_status";
863                $this->setDeploymentStatus(self :: processSelectDeploymentStatus($name));
864
865                // GIS data
866                // Get a geocoder for a given country
867                if (!empty ($_REQUEST['geocode_only']))
868                {
869                        $geocoder = AbstractGeocoder :: getGeocoder($this->getCountry());
870                        if ($geocoder != null)
871                        {
872                                $geocoder->setCivicNumber($this->getCivicNumber());
873                                $geocoder->setStreetName($this->getStreetName());
874                                $geocoder->setCity($this->getCity());
875                                $geocoder->setProvince($this->getProvince());
876                                $geocoder->setPostalCode($this->getPostalCode());
877                                if ($geocoder->validateAddress() === true)
878                                {
879                                        if (($point = $geocoder->getGisLocation()) !== null)
880                                                $this->setGisLocation($point);
881                                        else
882                                                echo _("It appears that the Geocoder could not be reached or could not geocode the given address.");
883                                }
884                                else
885                                        echo _("You must enter a valid address.");
886                        }
887                }
888                else
889                {
890                        // Use what has been set by the user.   
891                        $gis_lat_name = "node_".$hashed_node_id."_gis_latitude";
892                        $gis_long_name = "node_".$hashed_node_id."_gis_longitude";
893                        $this->setGisLocation(new GisPoint($_REQUEST[$gis_lat_name], $_REQUEST[$gis_long_name], .0));
894                }
895
896                // Statistics
897                $name = "node_{$this->id}_get_stats";
898                if (!empty ($_REQUEST[$name]))
899                        header("Location: hotspot_log.php?node_id=".urlencode($this->getId()));
900
901                // Owners processing
902                // Rebuild user id, and delete if it was selected
903                foreach ($this->getOwners() as $owner)
904                {
905                        $name = "node_{$this->getId()}_owner_{$owner->GetId()}_remove";
906                        if (!empty ($_REQUEST[$name]))
907                        {
908                                if ($this->isOwner($owner))
909                                        $this->removeOwner($owner);
910                                else
911                                        echo _("Invalid user!");
912                        }
913                }
914               
915                $name = "node_{$this->getId()}_new_owner_submit";
916                if (!empty ($_REQUEST[$name]))
917                {
918                        $name = "node_{$this->getId()}_new_owner";
919                        $owner = User :: processSelectUserUI($name);
920                        if ($owner)
921                        {
922                                if ($this->isOwner($owner))
923                                        echo _("The user is already an owner of this node.");
924                                else
925                                        $this->addOwner($owner);
926                        }
927                }
928
929                // Technical officers processing
930                // Rebuild user id, and delete if it was selected
931                foreach ($this->getTechnicalOfficers() as $tech_officer)
932                {
933                        $name = "node_{$this->getId()}_tech_officer_{$tech_officer->GetId()}_remove";
934                        if (!empty ($_REQUEST[$name]))
935                        {
936                                if ($this->isTechnicalOfficer($tech_officer))
937                                        $this->removeTechnicalOfficer($tech_officer);
938                                else
939                                        echo _("Invalid user!");
940                        }
941                }
942
943                $name = "node_{$this->getId()}_new_tech_officer_submit";
944                if (!empty ($_REQUEST[$name]))
945                {
946                        $name = "node_{$this->getId()}_new_tech_officer";
947                        $tech_officer = User :: processSelectUserUI($name);
948                        if ($tech_officer)
949                        {
950                                if ($this->isTechnicalOfficer($tech_officer))
951                                        echo _("The user is already a technical officer of this node.");
952                                else
953                                        $this->addTechnicalOfficer($tech_officer);
954                        }
955                }
956
957                // Content processing
958                // Rebuild content id and deleting if it was selected for deletion )
959                foreach ($this->getAllContent() as $content)
960                {
961                        $name = "node_".$this->id."_content_".$content->GetId()."_erase";
962                        if (!empty ($_REQUEST[$name]))
963                        {
964                                $this->removeContent($content);
965                        }
966                }
967
968                $name = "node_{$this->id}_new_content_submit";
969                if (!empty ($_REQUEST[$name]))
970                {
971                        $name = "node_{$this->id}_new_content";
972                        $content = Content :: processSelectContentUI($name);
973                        if ($content)
974                                $this->addContent($content);
975                }
976        }
977
978        // Redirect to this node's portal page
979        public function getUserUI()
980        {
981                header("Location: ".BASE_SSL_PATH."portal/?gw_id=".$this->getId());
982        }
983
984        /** Add content to this node */
985        public function addContent(Content $content)
986        {
987                global $db;
988                $content_id = $db->EscapeString($content->getId());
989                $sql = "INSERT INTO node_has_content (node_id, content_id) VALUES ('$this->id','$content_id')";
990                $db->ExecSqlUpdate($sql, false);
991        }
992
993        /** Remove content from this node */
994        public function removeContent(Content $content)
995        {
996                global $db;
997                $content_id = $db->EscapeString($content->getId());
998                $sql = "DELETE FROM node_has_content WHERE node_id='$this->id' AND content_id='$content_id'";
999                $db->ExecSqlUpdate($sql, false);
1000        }
1001
1002        /**Get an array of all Content linked to this node
1003         * @param boolean $exclude_subscribed_content
1004        * @param User $subscriber The User object used to discriminate the content
1005        * @return an array of Content or an empty arrray */
1006        function getAllContent($exclude_subscribed_content = false, $subscriber = null)
1007        {
1008                global $db;
1009                $retval = array ();
1010                // Get all network, but exclude user subscribed content if asked
1011                if ($exclude_subscribed_content == true && $subscriber)
1012                        $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 DESC";
1013                else
1014                        $sql = "SELECT content_id FROM node_has_content WHERE node_id='$this->id' ORDER BY subscribe_timestamp DESC";
1015                $db->ExecSql($sql, $content_rows, false);
1016
1017                if ($content_rows != null)
1018                {
1019                        foreach ($content_rows as $content_row)
1020                        {
1021                                $retval[] = Content :: getObject($content_row['content_id']);
1022                        }
1023                }
1024                return $retval;
1025        }
1026
1027        /** Get an array of all artistic and locative Content for this hotspot
1028        * @return an array of Content or an empty arrray */
1029        function getAllLocativeArtisticContent()
1030        {
1031                global $db;
1032                $retval = array ();
1033                $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 ORDER BY subscribe_timestamp DESC";
1034                $db->ExecSql($sql, $content_rows, false);
1035                if ($content_rows != null)
1036                {
1037                        foreach ($content_rows as $content_row)
1038                        {
1039                                // Create a content group object and grab only those that have content for the current Node
1040                                $content_group = Content :: getObject($content_row['content_group_id']);
1041                                if ($content_group->getDisplayNumElements() >= 1)
1042                                {
1043                                        if ($content_group->isDisplayableAt($this))
1044                                        {
1045                                                // Disable logging and allow content to expand ( if possible )
1046                                                $content_group->setExpandStatus(true);
1047                                                $content_group->setLoggingStatus(false);
1048                                                $retval[] = $content_group;
1049                                        }
1050                                }
1051                        }
1052                }
1053                return $retval;
1054        }
1055
1056        /** Return all the nodes
1057         */
1058        static function getAllNodes()
1059        {
1060                global $db;
1061
1062                $db->ExecSql("SELECT * FROM nodes", $nodes, false);
1063
1064                if ($nodes == null)
1065                        throw new Exception(_("No nodes could not be found in the database"));
1066
1067                return $nodes;
1068        }
1069
1070        static function getAllNodesOrdered($order_by)
1071        {
1072                global $db;
1073
1074                $db->ExecSql("SELECT * FROM nodes ORDER BY $order_by", $nodes, false);
1075
1076                if ($nodes == null)
1077                        throw new Exception(_("No nodes could not be found in the database"));
1078
1079                return $nodes;
1080        }
1081
1082        static function getAllNodesWithStatus()
1083        {
1084                global $db;
1085
1086                $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);
1087
1088                if ($nodes == null)
1089                        throw new Exception(_("No nodes could not be found in the database"));
1090
1091                return $nodes;
1092        }
1093
1094        static function getAllDeploymentStatus()
1095        {
1096                global $db;
1097
1098                $db->ExecSql("SELECT * FROM node_deployment_status", $statuses, false);
1099                if ($statuses == null)
1100                        throw new Exception(_("No deployment statues  could be found in the database"));
1101
1102                $statuses_array = array ();
1103                foreach ($statuses as $status)
1104                        array_push($statuses_array, $status['node_deployment_status']);
1105
1106                return $statuses_array;
1107        }
1108
1109        /** The list of users online at this node
1110         * @return An array of User object, or en empty array */
1111        function getOnlineUsers()
1112        {
1113                global $db;
1114                $retval = array ();
1115                $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);
1116                if ($users != null)
1117                {
1118                        foreach ($users as $user_row)
1119                        {
1120                                $retval[] = User :: getObject($user_row['user_id']);
1121                        }
1122                }
1123                return $retval;
1124        }
1125
1126        function getOwners()
1127        {
1128                global $db;
1129                $retval = array ();
1130                $db->ExecSql("SELECT user_id FROM node_stakeholders WHERE is_owner = true AND node_id='{$this->id}'", $owners, false);
1131                if ($owners != null)
1132                {
1133                        foreach ($owners as $owner_row)
1134                        {
1135                                $retval[] = User :: getObject($owner_row['user_id']);
1136                        }
1137                }
1138                return $retval;
1139        }
1140
1141        function getTechnicalOfficers()
1142        {
1143                global $db;
1144                $retval = array ();
1145                $db->ExecSql("SELECT user_id FROM node_stakeholders WHERE is_tech_officer = true AND node_id='{$this->id}'", $officers, false);
1146                if ($officers != null)
1147                {
1148                        foreach ($officers as $officer_row)
1149                        {
1150                                $retval[] = User :: getObject($officer_row['user_id']);
1151                        }
1152                }
1153                return $retval;
1154        }
1155
1156        /** Associates an owner to this node
1157         * @param User
1158         */
1159        function addOwner(User $user)
1160        {
1161                global $db;
1162                $db->ExecSql("SELECT * FROM node_stakeholders WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}'", $rows, false);
1163                if (!$rows)
1164                {
1165                        if (!$db->ExecSqlUpdate("INSERT INTO node_stakeholders (node_id, user_id, is_owner) VALUES ('{$this->getId()}','{$user->getId()}', true)", false))
1166                                throw new Exception(_('Could not add owner'));
1167                }
1168                else
1169                        if (!$db->ExecSqlUpdate("UPDATE node_stakeholders SET is_owner = true WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}';", false))
1170                                throw new Exception(_('Could not add owner'));
1171        }
1172
1173        /** Associates a technical officer ( tech support ) to this node
1174         * @param User
1175         */
1176        function addTechnicalOfficer(User $user)
1177        {
1178                global $db;
1179                $db->ExecSql("SELECT * FROM node_stakeholders WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}'", $rows, false);
1180                if (!$rows)
1181                {
1182                        if (!$db->ExecSqlUpdate("INSERT INTO node_stakeholders (node_id, user_id, is_tech_officer) VALUES ('{$this->getId()}','{$user->getId()}', true)", false))
1183                                throw new Exception(_('Could not add tech officer'));
1184                }
1185                else
1186                        if (!$db->ExecSqlUpdate("UPDATE node_stakeholders SET is_tech_officer = true WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}';", false))
1187                                throw new Exception(_('Could not add tech officer'));
1188        }
1189
1190        /** Remove a technical officer ( tech support ) from this node
1191         * @param User
1192         */
1193        function removeOwner(User $user)
1194        {
1195                global $db;
1196                if (!$db->ExecSqlUpdate("UPDATE node_stakeholders SET is_owner = false WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}';", false))
1197                        throw new Exception(_('Could not remove owner'));
1198        }
1199
1200        /** Remove a technical officer ( tech support ) from this node
1201         * @param User
1202         */
1203        function removeTechnicalOfficer(User $user)
1204        {
1205                global $db;
1206                if (!$db->ExecSqlUpdate("UPDATE node_stakeholders SET is_tech_officer = false WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}';", false))
1207                        throw new Exception(_('Could not remove tech officer'));
1208        }
1209
1210        /** Is the user an owner of the Node?
1211         * @return true our false*/
1212        function isOwner(User $user)
1213        {
1214                global $db;
1215                if ($user != null)
1216                {
1217                        $user_id = $user->getId();
1218                        $retval = false;
1219                        $db->ExecSqlUniqueRes("SELECT * FROM node_stakeholders WHERE is_owner = true AND node_id='{$this->id}' AND user_id='{$user_id}'", $row, false);
1220                        if ($row != null)
1221                        {
1222                                $retval = true;
1223                        }
1224                }
1225                return $retval;
1226        }
1227
1228        /** Is the user a technical officer of the Node?
1229         * @return true our false*/
1230        function isTechnicalOfficer(User $user)
1231        {
1232                global $db;
1233                if ($user != null)
1234                {
1235                        $user_id = $user->getId();
1236                        $retval = false;
1237                        $db->ExecSqlUniqueRes("SELECT * FROM node_stakeholders WHERE is_tech_officer = true AND node_id='{$this->id}' AND user_id='{$user_id}'", $row, false);
1238                        if ($row != null)
1239                        {
1240                                $retval = true;
1241                        }
1242                }
1243                return $retval;
1244        }
1245
1246        /** Check if an node exists */
1247        private function nodeExists($id)
1248        {
1249                global $db;
1250                $retval = false;
1251                $id_str = $db->EscapeString($id);
1252                $sql = "SELECT * FROM nodes WHERE node_id='{$id_str}'";
1253                $db->ExecSqlUniqueRes($sql, $row, false);
1254                if($row!=null)
1255                {
1256                        $retval = true;
1257                }
1258                return $retval;
1259        }
1260
1261        /** Warning, the semantics of this function will change *
1262         * @deprecated version - 2005-04-29 USE getOnlineUsers instead
1263         * */
1264        public static function getAllOnlineUsers()
1265        {
1266                global $db;
1267                $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);
1268                return $online_users;
1269        }
1270
1271        /** Reloads the object from the database.  Should normally be called after a set operation */
1272        protected function refresh()
1273        {
1274                $this->__construct($this->id);
1275        }
1276
1277} // End class
1278?>
Note: See TracBrowser for help on using the browser.