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

Revision 400, 2.9 KB (checked in by benoitg, 8 years ago)

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

  • classes/Node.php: New file, untested code example
  • wifidog/admin/admin_common.php: Remove double-defined BASEPATH
  • 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';
26
27/** Abstract a Node.  A Node is an actual physical transmitter. */
28class Node{
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   */
36  static function GetObject($id)
37    {
38      $object = null;
39      $object = new self($id);
40      return $object;
41    }
42 
43  /** Create a new Node in the database
44   * @param $id The id to be given to the new node
45   * @return the newly created Node object, or null if there was an error
46   */
47  static function CreateObject($id)
48    {
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 */
58  function __construct($node_id)
59  {
60    $node_id_str = $db->EscapeString($node_id);
61    $sql = "SELECT * from nodes WHERE node_id='$node_id_str'";
62    $db->ExecSqlUniqueRes($sql, $row, false);
63    if ($row==null)
64      {
65        throw new Exception(_("The id $node_id_str could not be found in the database"), "EXCEPTION_CREATE_OBJECT_FAILED");
66      }
67    $this -> mRow=$row; 
68    $this -> mId=$row['node_id'];
69  }//End class
70 
71/** Return the name of the node
72*/
73  function GetName()
74  {
75    return $this -> mRow['name'];
76  }
77}// End class
78?>
Note: See TracBrowser for help on using the browser.