root/trunk/wifidog-auth/wifidog/classes/Network.php @ 1024

Revision 1024, 52.5 KB (checked in by fproulx, 7 years ago)

2006-04-25 François Proulx <francois.proulx@…>

  • Updated JavaScript? code to work with Google Maps v2 API
  • v2 will now provide full maps of European countries and is a bit faster
  • Updated the schema accordingly with new GMaps values
  • 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/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5// +-------------------------------------------------------------------+
6// | WiFiDog Authentication Server                                     |
7// | =============================                                     |
8// |                                                                   |
9// | The WiFiDog Authentication Server is part of the WiFiDog captive  |
10// | portal suite.                                                     |
11// +-------------------------------------------------------------------+
12// | PHP version 5 required.                                           |
13// +-------------------------------------------------------------------+
14// | Homepage:     http://www.wifidog.org/                             |
15// | Source Forge: http://sourceforge.net/projects/wifidog/            |
16// +-------------------------------------------------------------------+
17// | This program is free software; you can redistribute it and/or     |
18// | modify it under the terms of the GNU General Public License as    |
19// | published by the Free Software Foundation; either version 2 of    |
20// | the License, or (at your option) any later version.               |
21// |                                                                   |
22// | This program is distributed in the hope that it will be useful,   |
23// | but WITHOUT ANY WARRANTY; without even the implied warranty of    |
24// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     |
25// | GNU General Public License for more details.                      |
26// |                                                                   |
27// | You should have received a copy of the GNU General Public License |
28// | along with this program; if not, contact:                         |
29// |                                                                   |
30// | Free Software Foundation           Voice:  +1-617-542-5942        |
31// | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        |
32// | Boston, MA  02111-1307,  USA       gnu@gnu.org                    |
33// |                                                                   |
34// +-------------------------------------------------------------------+
35
36/**
37 * @package    WiFiDogAuthServer
38 * @author     Benoit Gregoire <bock@step.polymtl.ca>
39 * @author     Max Horvath <max.horvath@maxspot.de>
40 * @copyright  2005-2006 Benoit Gregoire, Technologies Coeus inc.
41 * @copyright  2006 Max Horvath, maxspot GmbH
42 * @version    Subversion $Id$
43 * @link       http://www.wifidog.org/
44 */
45
46/**
47 * Load required classes
48 */
49require_once('classes/GenericObject.php');
50require_once('classes/Content.php');
51require_once('classes/User.php');
52require_once('classes/Node.php');
53require_once('classes/GisPoint.php');
54require_once('classes/Cache.php');
55
56/**
57 * Abstract a Network.
58 *
59 * A network is an administrative entity with it's own users, nodes and authenticator.
60 *
61 * @package    WiFiDogAuthServer
62 * @author     Benoit Gregoire <bock@step.polymtl.ca>
63 * @author     Max Horvath <max.horvath@maxspot.de>
64 * @copyright  2005-2006 Benoit Gregoire, Technologies Coeus inc.
65 * @copyright  2006 Max Horvath, maxspot GmbH
66 */
67class Network implements GenericObject
68{
69        private $id; /**< The network id */
70        private $mRow;
71
72        /** Get an instance of the object
73        * @see GenericObject
74        * @param $id The object id
75        * @return the Content object, or null if there was an error (an exception is also thrown)
76        */
77        static public function getObject($id)
78        {
79                return new self($id);
80        }
81
82        /** Get all the Networks configured on this server
83         * @return an array of Network objects.  The default network is returned
84         * first
85         */
86        static function getAllNetworks()
87        {
88                $retval = array ();
89                global $db;
90                $sql = "SELECT network_id FROM networks ORDER BY is_default_network DESC";
91                $network_rows = null;
92                $db->execSql($sql, $network_rows, false);
93                if ($network_rows == null)
94                {
95                        throw new Exception(_("Network::getAllNetworks:  Fatal error: No networks in the database!"));
96                }
97                foreach ($network_rows as $network_row)
98                {
99                        $retval[] = new self($network_row['network_id']);
100                }
101                return $retval;
102        }
103
104        /** Get the default network
105         * @return a Network object, NEVER returns null.
106         */
107        static function getDefaultNetwork($real_network_only = false)
108        {
109                $retval = null;
110                global $db;
111                $sql = "SELECT network_id FROM networks WHERE is_default_network=TRUE ORDER BY creation_date LIMIT 1";
112                $network_row = null;
113                $db->execSqlUniqueRes($sql, $network_row, false);
114                if ($network_row == null)
115                {
116                        throw new Exception(_("Network::getDefaultNetwork:  Fatal error: Unable to find the default network!"));
117                }
118                $retval = new self($network_row['network_id']);
119                return $retval;
120        }
121
122        /** Get the current network for which the portal is displayed or to which a user is physically connected.
123         * @param $real_network_only NOT IMPLEMENTED YET true or false.  If true,
124         * the real physical network where the user is connected is returned, and
125         * the node set by setCurrentNode is ignored.
126         * @return a Network object, NEVER returns null.
127         */
128        static function getCurrentNetwork($real_network_only = false)
129        {
130                $retval = null;
131                $current_node = Node :: getCurrentNode();
132                if ($current_node != null)
133                {
134                        $retval = $current_node->getNetwork();
135                }
136                else
137                {
138                        $retval = Network :: getDefaultNetwork();
139                }
140                return $retval;
141        }
142
143        /** Create a new Content object in the database
144         * @see GenericObject
145         * @param $network_id The network id of the new network.  If absent, will be
146         * assigned a guid.
147         * @return the newly created object, or null if there was an error
148         */
149        static function createNewObject($network_id = null)
150        {
151                global $db;
152                if (empty ($network_id))
153                {
154                        $network_id = get_guid();
155                }
156                $network_id = $db->escapeString($network_id);
157
158                $sql = "INSERT INTO networks (network_id, network_authenticator_class) VALUES ('$network_id', 'AuthenticatorLocalUser')";
159
160                if (!$db->execSqlUpdate($sql, false))
161                {
162                        throw new Exception(_('Unable to insert the new network in the database!'));
163                }
164                $object = new self($network_id);
165                return $object;
166
167        }
168
169        /**
170         * Get an interface to pick a network
171         *
172         * If there is only one network available, no interface is actually shown
173         *
174     * @param string $user_prefix          A identifier provided by the
175     *                                     programmer to recognise it's
176     *                                     generated html form
177     * @param object $pre_selected_network Network object: The network to be
178     *                                     pre-selected in the form object
179     * @param string $additional_where     Additional SQL conditions for the
180     *                                     networks to select
181     *
182     * @return string HTML markup
183     *
184     * @static
185     * @access public
186     */
187        public static function getSelectNetworkUI($user_prefix, $pre_selected_network = null, $additional_where = null)
188        {
189                $html = '';
190                $name = $user_prefix;
191                $html .= _("Network:")." \n";
192
193                if ($pre_selected_network)
194                {
195                        $selected_id = $pre_selected_network->getId();
196                }
197                else
198                {
199                        $selected_id = null;
200                }
201                global $db;
202                $additional_where = $db->escapeString($additional_where);
203                $sql = "SELECT network_id, name FROM networks WHERE 1=1 $additional_where ORDER BY is_default_network DESC";
204                $network_rows = null;
205                $db->execSql($sql, $network_rows, false);
206                if ($network_rows == null)
207                {
208                        throw new Exception(_("Network::getAllNetworks:  Fatal error: No networks in the database!"));
209                }
210
211                $number_of_networks = count($network_rows);
212                if ($number_of_networks > 1)
213                {
214                        $i = 0;
215                        foreach ($network_rows as $network_row)
216                        {
217                                $tab[$i][0] = $network_row['network_id'];
218                                $tab[$i][1] = $network_row['name'];
219                                $i ++;
220                        }
221                        $html .= FormSelectGenerator :: generateFromArray($tab, $selected_id, $name, null, false);
222
223                }
224                else
225                {
226                        foreach ($network_rows as $network_row) //iterates only once...
227                        {
228                                $html .= " $network_row[name] ";
229                                $html .= "<input type='hidden' name='$name' value='".htmlspecialchars($network_row['network_id'], ENT_QUOTES, 'UTF-8')."'>";
230                        }
231                }
232
233                return $html;
234        }
235
236        /**
237         * Get the selected Network object.
238         *
239         * @param string $user_prefix A identifier provided by the programmer to
240         *                            recognise it's generated form
241         *
242         * @return mixed The network object or an exception
243         *
244         * @static
245         * @access public
246         */
247        public static function processSelectNetworkUI($user_prefix)
248        {
249                $name = "{$user_prefix}";
250                if (!empty ($_REQUEST[$name]))
251                        return new self($_REQUEST[$name]);
252                else
253                        throw new exception (sprintf(_("Unable to retrieve the selected network, the %s REQUEST parameter does not exist"), $name));
254        }
255
256        /** Get an interface to create a new network.
257        * @return html markup
258        */
259        public static function getCreateNewObjectUI()
260        {
261                $html = '';
262                $html .= _("Create a new network with ID")." \n";
263                $name = "new_network_id";
264                $html .= "<input type='text' size='10' name='{$name}'>\n";
265                return $html;
266
267        }
268
269        /** Process the new object interface.
270         *  Will return the new object if the user has the credentials and the form was fully filled.
271         * @return the Network object or null if no new Network was created.
272         */
273        static function processCreateNewObjectUI()
274        {
275                $retval = null;
276                $name = "new_network_id";
277                if (!empty ($_REQUEST[$name]))
278                {
279                        $network_id = $_REQUEST[$name];
280                        if ($network_id)
281                        {
282                                if (!User :: getCurrentUser()->isSuperAdmin())
283                                {
284                                        throw new Exception(_("Access denied"));
285                                }
286                                $retval = self :: createNewObject($network_id);
287                        }
288                }
289                return $retval;
290        }
291
292        private function __construct($p_network_id)
293        {
294                global $db;
295
296                $network_id_str = $db->escapeString($p_network_id);
297                $sql = "SELECT *, EXTRACT(EPOCH FROM validation_grace_time) as validation_grace_time_seconds FROM networks WHERE network_id='$network_id_str'";
298                $row = null;
299                $db->execSqlUniqueRes($sql, $row, false);
300                if ($row == null)
301                {
302                        throw new Exception("The network with id $network_id_str could not be found in the database");
303                }
304                $this->mRow = $row;
305                $this->id = $db->escapeString($row['network_id']);
306        }
307
308        /** Retreives the id of the object
309         * @return The id */
310        public function getId()
311        {
312                return $this->id;
313        }
314
315        /** Retreives the network name
316         * @return The id */
317        public function getTechSupportEmail()
318        {
319                return $this->mRow['tech_support_email'];
320        }
321
322        /** Set the network's tech support and information email address
323         * @param $value The new value
324         * @return true on success, false on failure */
325        function setTechSupportEmail($value)
326        {
327                $retval = true;
328                if ($value != $this->getName())
329                {
330                        global $db;
331                        $value = $db->escapeString($value);
332                        $retval = $db->execSqlUpdate("UPDATE networks SET tech_support_email = '{$value}' WHERE network_id = '{$this->getId()}'", false);
333                        $this->refresh();
334                }
335                return $retval;
336        }
337
338        /**
339         * Retrieves the network name
340         * @return A string
341         */
342        public function getName()
343        {
344                return $this->mRow['name'];
345        }
346
347        /** Set the network's name
348         * @param $value The new value
349         * @return true on success, false on failure
350         */
351        function setName($value)
352        {
353                $retval = true;
354                if ($value != $this->getName())
355                {
356                        global $db;
357                        $value = $db->escapeString($value);
358                        $retval = $db->execSqlUpdate("UPDATE networks SET name = '{$value}' WHERE network_id = '{$this->getId()}'", false);
359                        $this->refresh();
360                }
361                return $retval;
362        }
363
364        /**
365         * Retrieves the network's creation date
366         *
367         * @return string Network's creation date
368         */
369        public function getCreationDate()
370        {
371                return $this->mRow['creation_date'];
372        }
373
374        /**
375         * Set the network's creation date
376         *
377         * @param string $value The new creation date
378         *
379         * @return bool True on success, false on failure
380         *
381         * @access public
382         */
383        public function setCreationDate($value)
384        {
385            // Define globals
386                global $db;
387
388            // Init values
389                $_retVal = true;
390
391                if ($value != $this->getCreationDate()) {
392                        $value = $db->escapeString($value);
393                        $_retVal = $db->execSqlUpdate("UPDATE networks SET creation_date = '{$value}' WHERE network_id = '{$this->getId()}'", false);
394                        $this->refresh();
395                }
396
397                return $_retVal;
398        }
399
400        /** Retreives the network's homepage url
401         * @return The id */
402        public function getHomepageURL()
403        {
404                return $this->mRow['homepage_url'];
405        }
406
407        /** Set the network's homepage url
408         * @param $value The new value
409         * @return true on success, false on failure */
410        function setHomepageURL($value)
411        {
412                $retval = true;
413                if ($value != $this->getName())
414                {
415                        global $db;
416                        $value = $db->escapeString($value);
417                        $retval = $db->execSqlUpdate("UPDATE networks SET homepage_url = '{$value}' WHERE network_id = '{$this->getId()}'", false);
418                        $this->refresh();
419                }
420                return $retval;
421        }
422
423        /**
424         * Retreives the network's authenticator's class name.
425         *
426         * @return string Name of authenticator's class
427         *
428         * @access public
429         */
430        public function getAuthenticatorClassName()
431        {
432                return $this->mRow['network_authenticator_class'];
433        }
434
435        /**
436         * Set the network's authenticator's class.
437         *
438         * The subclass of Authenticator to be used for user authentication
439         * (ex: AuthenticatorRadius)
440         *
441         * @param string $value The class name of a  subclass of Authenticator
442         *
443         * @return bool True on success, false on failure
444         *
445         * @access public
446         */
447        public function setAuthenticatorClassName($value)
448        {
449            // Define globals
450                global $db;
451
452            // Init values
453                $retval = true;
454
455                if ($value != $this->getAuthenticatorClassName()) {
456                        $value = $db->escapeString($value);
457                        $retval = $db->execSqlUpdate("UPDATE networks SET network_authenticator_class = '{$value}' WHERE network_id = '{$this->getId()}'", false);
458                        $this->refresh();
459                }
460
461                return $retval;
462        }
463
464        /**
465         * Retreives the authenticator's parameters
466         *
467         * @return string Authenticator's parameters
468         *
469         * @access public
470         */
471        public function getAuthenticatorConstructorParams()
472        {
473                return $this->mRow['network_authenticator_params'];
474        }
475
476        /**
477         * The explicit parameters to be passed to the authenticator's constructor
478         * (ex: 'my_network_id', '192.168.0.11', 1812, 1813, 'secret_key',
479         * 'CHAP_MD5')
480         *
481         * @param string $value The new value
482         *
483         * @return bool True on success, false on failure
484         *
485         * @access public
486         */
487        public function setAuthenticatorConstructorParams($value)
488        {
489            // Define globals
490                global $db;
491
492                // init values
493                $retval = true;
494
495                if ($value != $this->getAuthenticatorConstructorParams()) {
496                        $value = $db->escapeString($value);
497                        $retval = $db->execSqlUpdate("UPDATE networks SET network_authenticator_params = '{$value}' WHERE network_id = '{$this->getId()}'", false);
498                        $this->refresh();
499                }
500
501                return $retval;
502        }
503
504        /**
505         * Get the Authenticator object for this network
506         *
507         * @return object A subclass of Authenticator
508         *
509         * @access public
510         */
511        public function getAuthenticator()
512        {
513                require_once('classes/Authenticator.php');
514
515                // Include only the authenticator we are about to use
516                require_once("classes/Authenticators/" . $this->mRow['network_authenticator_class'] . ".php");
517
518                if (strpos($this->mRow['network_authenticator_params'], ';') != false) {
519                        throw new Exception("Network::getAuthenticator(): Security error: The parameters passed to the constructor of the authenticator are potentially unsafe");
520                }
521
522                return call_user_func_array(array(new ReflectionClass($this->mRow['network_authenticator_class']), 'newInstance'), explode(",", str_replace(array("'", '"'), "", str_replace(", ", ",", $this->mRow['network_authenticator_params']))));
523        }
524
525    /**
526     * Get the list of available Authenticators on the system
527     *
528     * @return array An array of class names
529     *
530     * @static
531     * @access public
532     */
533    public static function getAvailableAuthenticators()
534    {
535        // Init values
536        $_authenticators = array();
537        $_useCache = false;
538        $_cachedData = null;
539
540        // Create new cache object with a lifetime of one week
541        $_cache = new Cache("AuthenticatorClasses", "ClassFileCaches", 604800);
542
543        // Check if caching has been enabled.
544        if ($_cache->isCachingEnabled) {
545            $_cachedData = $_cache->getCachedData("mixed");
546
547            if ($_cachedData) {
548                // Return cached data.
549                $_useCache = true;
550                $_authenticators = $_cachedData;
551            }
552        }
553
554        if (!$_useCache) {
555            $_dir = WIFIDOG_ABS_FILE_PATH . "classes/Authenticators";
556            $_dirHandle = @opendir($_dir);
557
558            if ($_dirHandle) {
559                // Loop over the directory
560                while (false !== ($_filename = readdir($_dirHandle))) {
561                    // Loop through sub-directories of Content
562                    if ($_filename != '.' && $_filename != '..') {
563                        $_matches = null;
564
565                        if (preg_match("/^(.*)\.php$/", $_filename, $_matches) > 0) {
566                            // Only add files containing a corresponding Authenticator class
567                            if (is_file("{$_dir}/{$_matches[0]}")) {
568                                $_authenticators[] = $_matches[1];
569                            }
570                        }
571                    }
572                }
573
574                closedir($_dirHandle);
575            } else {
576                throw new Exception(_('Unable to open directory ') . $_dir);
577            }
578
579            // Sort the result array
580            sort($_authenticators);
581
582            // Check if caching has been enabled.
583            if ($_cache->isCachingEnabled) {
584                // Save results into cache, because it wasn't saved into cache before.
585                $_cache->saveCachedData($_authenticators, "mixed");
586            }
587        }
588
589        return $_authenticators;
590    }
591
592        /**
593         * Get an interface to pick an Authenticator
594         *
595     * @param string $user_prefix                A identifier provided by the
596     *                                           programmer to recognise it's
597     *                                           generated html form
598     * @param string $pre_selected_authenticator The Authenticator to be
599     *                                           pre-selected in the form object
600     *
601     * @return string HTML markup
602     *
603     * @static
604     * @access public
605     */
606        public static function getSelectAuthenticator($user_prefix, $pre_selected_authenticator = null)
607        {
608            // Define globals
609                global $db;
610
611            // Init values
612                $_authenticators = array();
613
614                foreach (self::getAvailableAuthenticators() as $_authenticator) {
615                    $_authenticators[] = array($_authenticator, $_authenticator);
616                }
617
618                $_name = $user_prefix;
619
620                if ($pre_selected_authenticator) {
621                        $_selectedID = $pre_selected_authenticator;
622                } else {
623                        $_selectedID = null;
624                }
625
626                $_html = FormSelectGenerator::generateFromArray($_authenticators, $_selectedID, $_name, null, false);
627
628                return $_html;
629        }
630
631        /**
632         * Is the network the default network?
633         *
634         * @return true or false
635         */
636        public function isDefaultNetwork()
637        {
638                ($this->mRow['is_default_network'] == 't') ? $retval = true : $retval = false;
639                return $retval;
640        }
641
642        /** Set as the default network.  The can only be one default network, so this method will unset is_default_network for all other network
643         * @return true on success, false on failure */
644        function setAsDefaultNetwork()
645        {
646                $retval = true;
647                if (!$this->isDefaultNetwork())
648                {
649                        global $db;
650                        $sql = "UPDATE networks SET is_default_network = FALSE;\n";
651                        $sql .= "UPDATE networks SET is_default_network = TRUE WHERE network_id = '{$this->getId()}';\n";
652                        $retval = $db->execSqlUpdate($sql, false);
653                        $this->refresh();
654                }
655                return $retval;
656        }
657
658        /** Retreives the network's validation grace period
659         * @return An integer (seconds) */
660        public function getValidationGraceTime()
661        {
662                return $this->mRow['validation_grace_time_seconds'];
663        }
664
665        /** Set the network's validation grace period in seconds.  A new user is granted Internet access for this period check his email and validate his account.
666         * @param $value The new value
667         * @return true on success, false on failure */
668        function setValidationGraceTime($value)
669        {
670                $retval = true;
671                if ($value != $this->getValidationGraceTime())
672                {
673                        global $db;
674                        $value = $db->escapeString($value);
675                        $retval = $db->execSqlUpdate("UPDATE networks SET validation_grace_time = '{$value} seconds' WHERE network_id = '{$this->getId()}'", false);
676                        $this->refresh();
677                }
678                return $retval;
679        }
680
681        /** Retreives the FROM adress of the validation email
682         * @return A string */
683        public function getValidationEmailFromAddress()
684        {
685                return $this->mRow['validation_email_from_address'];
686        }
687
688        /** Set the FROM adress of the validation email
689         * @param $value The new value
690         * @return true on success, false on failure */
691        function setValidationEmailFromAddress($value)
692        {
693                $retval = true;
694                if ($value != $this->getValidationEmailFromAddress())
695                {
696                        global $db;
697                        $value = $db->escapeString($value);
698                        $retval = $db->execSqlUpdate("UPDATE networks SET validation_email_from_address = '{$value}' WHERE network_id = '{$this->getId()}'", false);
699                        $this->refresh();
700                }
701                return $retval;
702        }
703
704        /** Can an account be connected more than once at the same time?
705         * @return true or false */
706        public function getMultipleLoginAllowed()
707        {
708                return ($this->mRow['allow_multiple_login'] == 't') ? true : false;
709        }
710
711        /** Set if a account be connected more than once at the same time?
712         * @param $value The new value, true or false
713         * @return true on success, false on failure */
714        function setMultipleLoginAllowed($value)
715        {
716                $retval = true;
717                if ($value != $this->getMultipleLoginAllowed())
718                {
719                        global $db;
720                        $value ? $value = 'TRUE' : $value = 'FALSE';
721                        $retval = $db->execSqlUpdate("UPDATE networks SET allow_multiple_login = {$value} WHERE network_id = '{$this->getId()}'", false);
722                        $this->refresh();
723                }
724                return $retval;
725        }
726
727        /** Are nodes allowed to be set as splash-only (no login)?
728         * @return true or false */
729        public function getSplashOnlyNodesAllowed()
730        {
731                return (($this->mRow['allow_splash_only_nodes'] == 't') ? true : false);
732        }
733
734        /** Set if nodes are allowed to be set as splash-only (no login)
735         * @param $value The new value, true or false
736         * @return true on success, false on failure */
737        function setSplashOnlyNodesAllowed($value)
738        {
739                $retval = true;
740                if ($value != $this->getSplashOnlyNodesAllowed())
741                {
742                        global $db;
743                        $value ? $value = 'TRUE' : $value = 'FALSE';
744                        $retval = $db->execSqlUpdate("UPDATE networks SET allow_splash_only_nodes = {$value} WHERE network_id = '{$this->getId()}'", false);
745                        $this->refresh();
746                }
747                return $retval;
748        }
749
750        /**
751         * Get a GisPoint object
752         *
753         * @return object GisPoint object
754         *
755         * @access public
756         */
757        public function getGisLocation()
758        {
759                return new GisPoint($this->mRow['gmaps_initial_latitude'], $this->mRow['gmaps_initial_longitude'], $this->mRow['gmaps_initial_zoom_level']);
760        }
761
762        /**
763         * Set the network's GisPoint object
764         *
765         * @param $value The new GisPoint object
766         *
767         * @return bool True on success, false on failure
768         *
769         * @access public
770         */
771        public function setGisLocation($pt)
772        {
773            // Define globals
774            global $db;
775
776                if (!empty ($pt)) {
777                        $lat = $db->escapeString($pt->getLatitude());
778                        $long = $db->escapeString($pt->getLongitude());
779                    $alt = $db->escapeString($pt->getAltitude());
780
781                        if (!empty($lat) && !empty($long) && !empty($alt)) {
782                                $db->execSqlUpdate("UPDATE networks SET gmaps_initial_latitude = $lat, gmaps_initial_longitude = $long, gmaps_initial_zoom_level = $alt WHERE network_id = '{$this->getId()}'");
783                        } else {
784                                $db->execSqlUpdate("UPDATE networks SET gmaps_initial_latitude = NULL, gmaps_initial_longitude = NULL, gmaps_initial_zoom_level = NULL WHERE network_id = '{$this->getId()}'");
785                        }
786
787                        $this->refresh();
788                }
789        }
790
791        /**
792         * Retreives the default Google maps type
793         *
794         * @return string Default Google maps type
795         *
796         * @access public
797         */
798        public function getGisMapType()
799        {
800                return $this->mRow['gmaps_map_type'];
801        }
802
803        /**
804         * Set the network's default Google maps type
805         *
806         * @param $value The new default Google maps type
807         *
808         * @return bool True on success, false on failure
809         *
810         * @access public
811         */
812        public function setGisMapType($value)
813        {
814            // Define globals
815                global $db;
816
817                // Init values
818                $retval = true;
819
820                if ($value != $this->getGisMapType()) {
821                        $value = $db->escapeString($value);
822                        $retval = $db->execSqlUpdate("UPDATE networks SET gmaps_map_type = '{$value}' WHERE network_id = '{$this->getId()}'", false);
823                        $this->refresh();
824                }
825                return $retval;
826        }
827
828        /**
829         * Get an interface to pick a Google maps type
830         *
831     * @param string $user_prefix           A identifier provided by the
832     *                                      programmer to recognise it's
833     *                                      generated html form
834     * @param string $pre_selected_map_type The Google map type to be
835     *                                      pre-selected in the form object
836     *
837     * @return string HTML markup
838     *
839     * @static
840     * @access public
841     */
842        public static function getSelectGisMapType($user_prefix, $pre_selected_map_type = "G_NORMAL_MAP")
843        {
844            // Define globals
845                global $db;
846
847            // Init values
848                $_map_types = array(array("G_NORMAL_MAP", _("Map")), array("G_SATELLITE_MAP", _("Satellite")), array("G_HYBRID_MAP", _("Hybrid")));
849
850                $_name = $user_prefix;
851
852                if ($pre_selected_map_type) {
853                        $_selectedID = $pre_selected_map_type;
854                } else {
855                        $_selectedID = null;
856                }
857
858                $_html = FormSelectGenerator::generateFromArray($_map_types, $_selectedID, $_name, null, false);
859
860                return $_html;
861        }
862
863        /** Get's the splash-only user.  This is the user that people logged-in at a splash-only hotspot will show up as.  This user always has multiple-login capabilities.
864        * @param $username The username of the user
865        * @param $account_origin The account origin
866        * @return a User object
867        */
868        public function getSplashOnlyUser()
869        {
870                $username = 'SPLASH_ONLY_USER';
871
872                $user = User :: getUserByUsernameAndOrigin($username, $this);
873                if (!$user)
874                {
875                        $user = User :: createUser(get_guid(), $username, $this, '', '');
876                        $user->setAccountStatus(ACCOUNT_STATUS_ALLOWED);
877                }
878                return $user;
879        }
880
881        /**
882     * Find out the total number of users in this networks's database
883     *
884     * @return int Number of users
885     *
886     * @access public
887     */
888        public function getNumUsers()
889        {
890            // Define globals
891                global $db;
892
893                // Init values
894        $_retval = 0;
895                $_row = null;
896        $_useCache = false;
897        $_cachedData = null;
898
899        // Create new cache objects (valid for 1 minute)
900        $_cache = new Cache('network_' . $this->id . '_num_users', $this->id, 60);
901
902        // Check if caching has been enabled.
903        if ($_cache->isCachingEnabled) {
904            $_cachedData = $_cache->getCachedData();
905
906            if ($_cachedData) {
907                // Return cached data.
908                $_useCache = true;
909                $_retval = $_cachedData;
910            }
911        }
912
913        if (!$_useCache) {
914            // Get number of users
915                $_network_id = $db->escapeString($this->id);
916                $db->execSqlUniqueRes("SELECT COUNT(user_id) FROM users WHERE account_origin='$_network_id'", $_row, false);
917
918            // String has been found
919            $_retval = $_row['count'];
920
921            // Check if caching has been enabled.
922            if ($_cache->isCachingEnabled) {
923                // Save data into cache, because it wasn't saved into cache before.
924                $_cache->saveCachedData($_retval);
925            }
926        }
927
928                return $_retval;
929        }
930
931        /**
932     * Find out how many users are valid in this networks's database
933     *
934     * @return int Number of valid users
935     *
936     * @access public
937     */
938        public function getNumValidUsers()
939        {
940            // Define globals
941                global $db;
942
943                // Init values
944        $_retval = 0;
945                $_row = null;
946        $_useCache = false;
947        $_cachedData = null;
948
949        // Create new cache objects (valid for 1 minute)
950        $_cache = new Cache('network_' . $this->id . '_num_valid_users', $this->id, 60);
951
952        // Check if caching has been enabled.
953        if ($_cache->isCachingEnabled) {
954            $_cachedData = $_cache->getCachedData();
955
956            if ($_cachedData) {
957                // Return cached data.
958                $_useCache = true;
959                $_retval = $_cachedData;
960            }
961        }
962
963        if (!$_useCache) {
964            // Get number of valid users
965                $_network_id = $db->escapeString($this->id);
966                $db->execSqlUniqueRes("SELECT COUNT(user_id) FROM users WHERE account_status = ".ACCOUNT_STATUS_ALLOWED." AND account_origin='$_network_id'", $_row, false);
967
968            // String has been found
969            $_retval = $_row['count'];
970
971            // Check if caching has been enabled.
972            if ($_cache->isCachingEnabled) {
973                // Save data into cache, because it wasn't saved into cache before.
974                $_cache->saveCachedData($_retval);
975            }
976        }
977
978                return $_retval;
979        }
980
981        /**
982         * Find out how many users are online on the entire network or at a
983         * specific Hotspot on the network
984         *
985         * @return int Number of online users
986         *
987         * @access public
988         */
989        public function getNumOnlineUsers()
990        {
991            // Define globals
992                global $db;
993
994                // Init values
995        $_retval = 0;
996                $_row = null;
997        $_useCache = false;
998        $_cachedData = null;
999
1000        // Create new cache objects (valid for 1 minute)
1001        $_cache = new Cache('network_' . $this->id . '_num_online_users', $this->id, 60);
1002
1003        // Check if caching has been enabled.
1004        if ($_cache->isCachingEnabled) {
1005            $_cachedData = $_cache->getCachedData();
1006
1007            if ($_cachedData) {
1008                // Return cached data.
1009                $_useCache = true;
1010                $_retval = $_cachedData;
1011            }
1012        }
1013
1014        if (!$_useCache) {
1015            // Get number of online users
1016                $_network_id = $db->escapeString($this->id);
1017                $db->execSqlUniqueRes("SELECT COUNT(DISTINCT users.user_id) FROM users,connections NATURAL JOIN nodes JOIN networks ON (nodes.network_id=networks.network_id AND networks.network_id='$_network_id') "."WHERE connections.token_status='".TOKEN_INUSE."' "."AND users.user_id=connections.user_id ", $_row, false);
1018
1019            // String has been found
1020            $_retval = $_row['count'];
1021
1022            // Check if caching has been enabled.
1023            if ($_cache->isCachingEnabled) {
1024                // Save data into cache, because it wasn't saved into cache before.
1025                $_cache->saveCachedData($_retval);
1026            }
1027        }
1028
1029                return $_retval;
1030        }
1031
1032        /**
1033     * Find out how many nodes are registered in this networks's database
1034         *
1035         * @return int Number of nodes
1036         *
1037         * @access public
1038         */
1039        public function getNumNodes()
1040        {
1041            // Define globals
1042                global $db;
1043
1044                // Init values
1045        $_retval = 0;
1046                $_row = null;
1047        $_useCache = false;
1048        $_cachedData = null;
1049
1050        // Create new cache objects (valid for 5 minutes)
1051        $_cache = new Cache('network_' . $this->id . '_num_nodes', $this->id, 300);
1052
1053        // Check if caching has been enabled.
1054        if ($_cache->isCachingEnabled) {
1055            $_cachedData = $_cache->getCachedData();
1056
1057            if ($_cachedData) {
1058                // Return cached data.
1059                $_useCache = true;
1060                $_retval = $_cachedData;
1061            }
1062        }
1063
1064        if (!$_useCache) {
1065            // Get number of nodes
1066                $_network_id = $db->escapeString($this->id);
1067            $db->execSqlUniqueRes("SELECT COUNT(node_id) FROM nodes WHERE network_id = '$_network_id'", $_row, false);
1068
1069            // String has been found
1070            $_retval = $_row['count'];
1071
1072            // Check if caching has been enabled.
1073            if ($_cache->isCachingEnabled) {
1074                // Save data into cache, because it wasn't saved into cache before.
1075                $_cache->saveCachedData($_retval);
1076            }
1077        }
1078
1079                return $_retval;
1080        }
1081
1082        /**
1083     * Find out how many nodes are deployed in this networks's database
1084         *
1085         * @return int Number of deployed nodes
1086         *
1087         * @access public
1088         */
1089        public function getNumDeployedNodes()
1090        {
1091            // Define globals
1092                global $db;
1093
1094                // Init values
1095        $_retval = 0;
1096                $_row = null;
1097        $_useCache = false;
1098        $_cachedData = null;
1099
1100        // Create new cache objects (valid for 5 minutes)
1101        $_cache = new Cache('network_' . $this->id . '_num_deployed_nodes', $this->id, 300);
1102
1103        // Check if caching has been enabled.
1104        if ($_cache->isCachingEnabled) {
1105            $_cachedData = $_cache->getCachedData();
1106
1107            if ($_cachedData) {
1108                // Return cached data.
1109                $_useCache = true;
1110                $_retval = $_cachedData;
1111            }
1112        }
1113
1114        if (!$_useCache) {
1115            // Get number of deployed nodes
1116                $_network_id = $db->escapeString($this->id);
1117            $db->execSqlUniqueRes("SELECT COUNT(node_id) FROM nodes WHERE network_id = '$_network_id' AND (node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE')", $_row, false);
1118
1119            // String has been found
1120            $_retval = $_row['count'];
1121
1122            // Check if caching has been enabled.
1123            if ($_cache->isCachingEnabled) {
1124                // Save data into cache, because it wasn't saved into cache before.
1125                $_cache->saveCachedData($_retval);
1126            }
1127        }
1128
1129                return $_retval;
1130        }
1131
1132        /**
1133     * Find out how many deployed nodes are online in this networks's database
1134         *
1135         * @return int Number of deployed nodes which are online
1136         *
1137         * @access public
1138         */
1139        public function getNumOnlineNodes()
1140        {
1141            // Define globals
1142                global $db;
1143
1144                // Init values
1145        $_retval = 0;
1146                $_row = null;
1147        $_useCache = false;
1148        $_cachedData = null;
1149
1150        // Create new cache objects (valid for 5 minutes)
1151        $_cache = new Cache('network_' . $this->id . '_num_online_nodes', $this->id, 300);
1152
1153        // Check if caching has been enabled.
1154        if ($_cache->isCachingEnabled) {
1155            $_cachedData = $_cache->getCachedData();
1156
1157            if ($_cachedData) {
1158                // Return cached data.
1159                $_useCache = true;
1160                $_retval = $_cachedData;
1161            }
1162        }
1163
1164        if (!$_useCache) {
1165            // Get number of online nodes
1166                $_network_id = $db->escapeString($this->id);
1167            $db->execSqlUniqueRes("SELECT COUNT(node_id) FROM nodes WHERE network_id = '$_network_id' AND (node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE') AND ((NOW()-last_heartbeat_timestamp) < interval '5 minutes')", $_row, false);
1168
1169            // String has been found
1170            $_retval = $_row['count'];
1171
1172            // Check if caching has been enabled.
1173            if ($_cache->isCachingEnabled) {
1174                // Save data into cache, because it wasn't saved into cache before.
1175                $_cache->saveCachedData($_retval);
1176            }
1177        }
1178
1179                return $_retval;
1180        }
1181
1182        /** Are nodes allowed to redirect users to an arbitrary web page instead of the portal?
1183         * @return true or false */
1184        public function getCustomPortalRedirectAllowed()
1185        {
1186                return (($this->mRow['allow_custom_portal_redirect'] == 't') ? true : false);
1187        }
1188
1189        /** Set if nodes are allowed to redirect users to an arbitrary web page instead of the portal?
1190         * @param $value The new value, true or false
1191         * @return true on success, false on failure */
1192        function setCustomPortalRedirectAllowed($value)
1193        {
1194                $retval = true;
1195                if ($value != $this->getCustomPortalRedirectAllowed())
1196                {
1197                        global $db;
1198                        $value ? $value = 'TRUE' : $value = 'FALSE';
1199                        $retval = $db->execSqlUpdate("UPDATE networks SET allow_custom_portal_redirect = {$value} WHERE network_id = '{$this->getId()}'", false);
1200                        $this->refresh();
1201                }
1202                return $retval;
1203        }
1204
1205        /**
1206         * Does the user have admin access to this network?
1207         * @return boolean true our false
1208         */
1209        function hasAdminAccess(User $user)
1210        {
1211            // Define globals
1212                global $db;
1213
1214        // Init values
1215        $row = null;
1216                $retval = false;
1217
1218                if ($user != null) {
1219                        $user_id = $user->getId();
1220                        $db->execSqlUniqueRes("SELECT * FROM network_stakeholders WHERE is_admin = true AND network_id='{$this->id}' AND user_id='{$user_id}'", $row, false);
1221
1222                        if ($row != null) {
1223                                $retval = true;
1224                        } else {
1225                                if ($user->isSuperAdmin()) {
1226                                        $retval = true;
1227                                }
1228                        }
1229                }
1230
1231                return $retval;
1232        }
1233
1234        /**
1235         * Get an array of all Content linked to the network
1236         *
1237         * @param bool   $exclude_subscribed_content Exclude subscribed content?
1238         * @param object $subscriber                 The User object used to
1239         *                                           discriminate the content
1240         *
1241         * @return array An array of Content or an empty array
1242         *
1243         * @access public
1244         */
1245        /*public function getAllContent($exclude_subscribed_content = false, $subscriber = null)
1246        {
1247            // Define globals
1248                global $db;
1249
1250        // Init values
1251        $content_rows = null;
1252                $retval = array ();
1253
1254                // Get all network, but exclude user subscribed content if asked
1255                if ($exclude_subscribed_content == true && $subscriber) {
1256                        $sql = "SELECT content_id FROM network_has_content WHERE network_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";
1257                } else {
1258                        $sql = "SELECT content_id FROM network_has_content WHERE network_id='$this->id' ORDER BY subscribe_timestamp DESC";
1259                }
1260
1261                $db->execSql($sql, $content_rows, false);
1262
1263                if ($content_rows != null) {
1264                        foreach ($content_rows as $content_row) {
1265                                $retval[] = Content :: getObject($content_row['content_id']);
1266                        }
1267                }
1268
1269                return $retval;
1270        }
1271*/
1272        /**
1273         * Retreives the admin interface of this object
1274         *
1275         * @return string The HTML fragment for this interface
1276         *
1277         * @access public
1278         */
1279        public function getAdminUI()
1280        {
1281                $html = '';
1282                $html .= "<h3>"._("Network management")."</h3>\n";
1283                $html .= "<div class='admin_container'>\n";
1284                $html .= "<div class='admin_class'>Network (".get_class($this)." instance)</div>\n";
1285
1286                // network_id
1287                $html .= "<div class='admin_section_container'>\n";
1288                $html .= "<div class='admin_section_title'>"._("Network ID")." : </div>\n";
1289                $html .= "<div class='admin_section_data'>\n";
1290                $value = htmlspecialchars($this->getId(), ENT_QUOTES);
1291                $html .= $value;
1292                $html .= "</div>\n";
1293                $html .= "</div>\n";
1294
1295                // creation_date
1296                $name = "network_".$this->getId()."_creation_date";
1297                $value = htmlspecialchars($this->getCreationDate(), ENT_QUOTES);
1298
1299                $html .= "<div class='admin_section_container'>\n";
1300                $html .= "<div class='admin_section_title'>" . _("Network creation date") . ":</div>\n";
1301                $html .= "<div class='admin_section_data'>\n";
1302                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
1303                $html .= "</div>\n";
1304                $html .= "</div>\n";
1305
1306                // name
1307                $html .= "<div class='admin_section_container'>\n";
1308                $html .= "<div class='admin_section_title'>"._("Network name")." : </div>\n";
1309                $html .= "<div class='admin_section_data'>\n";
1310                $name = "network_".$this->getId()."_name";
1311                $value = htmlspecialchars($this->getName(), ENT_QUOTES);
1312                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
1313                $html .= "</div>\n";
1314                $html .= "</div>\n";
1315
1316                // homepage_url
1317                $html .= "<div class='admin_section_container'>\n";
1318                $html .= "<div class='admin_section_title'>"._("Network's web site")." : </div>\n";
1319                $html .= "<div class='admin_section_data'>\n";
1320                $name = "network_".$this->getId()."_homepage_url";
1321                $value = htmlspecialchars($this->getHomepageURL(), ENT_QUOTES);
1322                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
1323                $html .= "</div>\n";
1324                $html .= "</div>\n";
1325
1326                // tech_support_email
1327                $html .= "<div class='admin_section_container'>\n";
1328                $html .= "<div class='admin_section_title'>"._("Technical support email")." : </div>\n";
1329                $html .= "<div class='admin_section_data'>\n";
1330                $name = "network_".$this->getId()."_tech_support_email";
1331                $value = htmlspecialchars($this->getTechSupportEmail(), ENT_QUOTES);
1332                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
1333                $html .= "</div>\n";
1334                $html .= "</div>\n";
1335
1336                //  network_authenticator_class
1337                $html .= "<div class='admin_section_container'>\n";
1338                $html .= "<div class='admin_section_title'>"._("Network authenticator class.  The subclass of Authenticator to be used for user authentication (ex: AuthenticatorRadius)")." : </div>\n";
1339                $html .= "<div class='admin_section_data'>\n";
1340                $name = "network_".$this->getId()."_network_authenticator_class";
1341                $value = htmlspecialchars($this->getAuthenticatorClassName(), ENT_QUOTES);
1342                $html .= $this->getSelectAuthenticator($name, $value);
1343                $html .= "</div>\n";
1344                $html .= "</div>\n";
1345
1346                //  network_authenticator_params
1347                $html .= "<div class='admin_section_container'>\n";
1348                $html .= "<div class='admin_section_title'>"._("The explicit parameters to be passed to the authenticator (ex: 'my_network_id', '192.168.0.11', 1812, 1813, 'secret_key', 'CHAP_MD5')")." : </div>\n";
1349                $html .= "<div class='admin_section_data'>\n";
1350                $name = "network_".$this->getId()."_network_authenticator_params";
1351                $value = htmlspecialchars($this->getAuthenticatorConstructorParams(), ENT_QUOTES);
1352                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
1353                $html .= "</div>\n";
1354                $html .= "</div>\n";
1355
1356                //  is_default_network
1357                $html .= "<div class='admin_section_container'>\n";
1358                $html .= "<div class='admin_section_title'>"._("Is this network the default network?")." : </div>\n";
1359                $html .= "<div class='admin_section_data'>\n";
1360                $name = "network_".$this->getId()."_is_default_network";
1361                $this->isDefaultNetwork() ? $checked = 'CHECKED' : $checked = '';
1362                $html .= "<input type='checkbox' name='$name' $checked>\n";
1363                $html .= "</div>\n";
1364                $html .= "</div>\n";
1365
1366                //  validation_grace_time
1367                $html .= "<div class='admin_section_container'>\n";
1368                $html .= "<div class='admin_section_title'>"._("The length of the validation grace period in seconds.  A new user is granted Internet access for this period check his email and validate his account.")." : </div>\n";
1369                $html .= "<div class='admin_section_data'>\n";
1370                $name = "network_".$this->getId()."_validation_grace_time";
1371                $value = htmlspecialchars($this->getValidationGraceTime(), ENT_QUOTES);
1372                $html .= "<input type='text' size ='5' value='$value' name='$name'>\n";
1373                $html .= "</div>\n";
1374                $html .= "</div>\n";
1375
1376                //  validation_email_from_address
1377                $html .= "<div class='admin_section_container'>\n";
1378                $html .= "<div class='admin_section_title'>"._("This will be the from adress of the validation email")." : </div>\n";
1379                $html .= "<div class='admin_section_data'>\n";
1380                $name = "network_".$this->getId()."_validation_email_from_address";
1381                $value = htmlspecialchars($this->getValidationEmailFromAddress(), ENT_QUOTES);
1382                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
1383                $html .= "</div>\n";
1384                $html .= "</div>\n";
1385
1386                //  allow_multiple_login
1387                $html .= "<div class='admin_section_container'>\n";
1388                $html .= "<div class='admin_section_title'>"._("Can an account be connected more than once at the same time?")." : </div>\n";
1389                $html .= "<div class='admin_section_data'>\n";
1390                $name = "network_".$this->getId()."_allow_multiple_login";
1391                $this->getMultipleLoginAllowed() ? $checked = 'CHECKED' : $checked = '';
1392                $html .= "<input type='checkbox' name='$name' $checked>\n";
1393                $html .= "</div>\n";
1394                $html .= "</div>\n";
1395
1396                //  allow_splash_only_nodes
1397                $html .= "<div class='admin_section_container'>\n";
1398                $html .= "<div class='admin_section_title'>"._("Are nodes allowed to be set as splash-only (no login)?")." : </div>\n";
1399                $html .= "<div class='admin_section_data'>\n";
1400                $name = "network_".$this->getId()."_allow_splash_only_nodes";
1401                $this->getSplashOnlyNodesAllowed() ? $checked = 'CHECKED' : $checked = '';
1402                $html .= "<input type='checkbox' name='$name' $checked>\n";
1403                $html .= "</div>\n";
1404                $html .= "</div>\n";
1405
1406                //  allow_custom_portal_redirect
1407                $html .= "<div class='admin_section_container'>\n";
1408                $html .= "<div class='admin_section_title'>"._("Are nodes allowed to redirect users to an arbitrary web page instead of the portal?")." : </div>\n";
1409                $html .= "<div class='admin_section_data'>\n";
1410                $name = "network_".$this->getId()."_allow_custom_portal_redirect";
1411                $this->getCustomPortalRedirectAllowed() ? $checked = 'CHECKED' : $checked = '';
1412                $html .= "<input type='checkbox' name='$name' $checked>\n";
1413                $html .= "</div>\n";
1414                $html .= "</div>\n";
1415
1416                //      network_stakeholders
1417                $html .= "<div class='admin_section_container'>\n";
1418                $html .= "<div class='admin_section_title'>"._("Network stakeholders")." : </div>\n";
1419                $html .= "<div class='admin_section_data'>\n";
1420                //$name = "network_".$this->getId()."_allow_custom_portal_redirect";
1421                //$this->getCustomPortalRedirectAllowed()? $checked='CHECKED': $checked='';
1422                //$html .= "<input type='checkbox' name='$name' $checked>\n";
1423                $html .= "WRITEME!";
1424                $html .= "</div>\n";
1425                $html .= "</div>\n";
1426
1427                // Build HTML form fields names & values
1428                if (defined('GMAPS_HOTSPOTS_MAP_ENABLED') && GMAPS_HOTSPOTS_MAP_ENABLED === true) {
1429                $gis_point = $this->getGisLocation();
1430                $gis_lat_name = "network_".$this->getId()."_gis_latitude";
1431                $gis_lat_value = htmlspecialchars($gis_point->getLatitude(), ENT_QUOTES);
1432                $gis_long_name = "network_".$this->getId()."_gis_longitude";
1433                $gis_long_value = htmlspecialchars($gis_point->getLongitude(), ENT_QUOTES);
1434                $gis_alt_name = "network_".$this->getId()."_gis_altitude";
1435                $gis_alt_value = htmlspecialchars($gis_point->getAltitude(), ENT_QUOTES);
1436
1437                $html .= "<div class='admin_section_container'>\n";
1438                $html .= "<div class='admin_section_title'>"._("Center latitude for your the area of your wireless network")." : </div>\n";
1439                $html .= "<div class='admin_section_data'>\n";
1440                $html .= "<input type='text' size ='15' value='$gis_lat_value' id='$gis_lat_name' name='$gis_lat_name'>\n";
1441                $html .= "</div>\n";
1442                $html .= "</div>\n";
1443
1444                $html .= "<div class='admin_section_container'>\n";
1445                $html .= "<div class='admin_section_title'>"._("Center longitude for your the area of your wireless network")." : </div>\n";
1446                $html .= "<div class='admin_section_data'>\n";
1447                $html .= "<input type='text' size ='15' value='$gis_long_value' id='$gis_long_name' name='$gis_long_name'>\n";
1448                $html .= "</div>\n";
1449                $html .= "</div>\n";
1450
1451                $html .= "<div class='admin_section_container'>\n";
1452                $html .= "<div class='admin_section_title'>"._("Zoomlevel of the Google Map for your the area of your wireless network")." : </div>\n";
1453                $html .= "<div class='admin_section_data'>\n";
1454                $html .= "<input type='text' size ='15' value='$gis_alt_value' id='$gis_alt_name' name='$gis_alt_name'>\n";
1455                $html .= "</div>\n";
1456                $html .= "</div>\n";
1457
1458                $html .= "<div class='admin_section_container'>\n";
1459                $html .= "<div class='admin_section_title'>"._("Default Google Map type for your the area of your wireless network")." : </div>\n";
1460                $html .= "<div class='admin_section_data'>\n";
1461                $html .= $this->getSelectGisMapType("network_".$this->getId()."_gmaps_map_type", $this->getGisMapType());
1462                $html .= "</div>\n";
1463                $html .= "</div>\n";
1464                }
1465
1466                // Create new nodes
1467                $html .= "<div class='admin_section_container'>\n";
1468                $html .= "<div class='admin_section_title'>"._("New node ID")." : </div>\n";
1469
1470                $html .= "<div class='admin_section_data'>\n";
1471
1472                $html .= Node :: getCreateNewObjectUI($this);
1473
1474                $html .= "<div class='admin_section_tools'>\n";
1475                $name = "network_{$this->getId()}_create_node";
1476                $html .= "<input type='submit' name='{$name}' value='"._("Create a new node")."'>\n";
1477                $html .= "</div>\n";
1478
1479                $html .= "</div>\n";
1480                $html .= "</div>\n";
1481
1482                // Content management
1483        $title = _("Network content");
1484        $name = "network_" . $this->id . "_content";
1485        $data = Content::getLinkedContentUI($name, "network_has_content", "network_id", $this->id, $display_page = "portal");
1486        $html .= InterfaceElements::generateAdminSectionContainer("network_content", $title, $data);
1487
1488                return $html;
1489        }
1490
1491        /** Process admin interface of this object.
1492        */
1493        public function processAdminUI()
1494        {
1495                //pretty_print_r($_REQUEST);
1496                $user = User :: getCurrentUser();
1497                if (!$this->hasAdminAccess($user))
1498                {
1499                        throw new Exception(_('Access denied!'));
1500                }
1501
1502                // creation_date
1503                $name = "network_".$this->getId()."_creation_date";
1504                $this->setCreationDate($_REQUEST[$name]);
1505
1506                // name
1507                $name = "network_".$this->getId()."_name";
1508                $this->setName($_REQUEST[$name]);
1509
1510                // homepage_url
1511                $name = "network_".$this->getId()."_homepage_url";
1512                $this->setHomepageURL($_REQUEST[$name]);
1513
1514                // tech_support_email
1515                $name = "network_".$this->getId()."_tech_support_email";
1516                $this->setTechSupportEmail($_REQUEST[$name]);
1517
1518                //  network_authenticator_class
1519                $name = "network_".$this->getId()."_network_authenticator_class";
1520                $this->setAuthenticatorClassName($_REQUEST[$name]);
1521
1522                //  network_authenticator_params
1523                $name = "network_".$this->getId()."_network_authenticator_params";
1524                $this->setAuthenticatorConstructorParams($_REQUEST[$name]);
1525
1526                //  is_default_network
1527                $name = "network_".$this->getId()."_is_default_network";
1528                if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == 'on')
1529                        $this->setAsDefaultNetwork();
1530
1531                //  validation_grace_time
1532                $name = "network_".$this->getId()."_validation_grace_time";
1533                $this->setValidationGraceTime($_REQUEST[$name]);
1534
1535                //  validation_email_from_address
1536                $name = "network_".$this->getId()."_validation_email_from_address";
1537                $this->setValidationEmailFromAddress($_REQUEST[$name]);
1538
1539                //  allow_multiple_login
1540                $name = "network_".$this->getId()."_allow_multiple_login";
1541                $this->setMultipleLoginAllowed(empty ($_REQUEST[$name]) ? false : true);
1542
1543                //  allow_splash_only_nodes
1544                $name = "network_".$this->getId()."_allow_splash_only_nodes";
1545                $this->setSplashOnlyNodesAllowed(empty ($_REQUEST[$name]) ? false : true);
1546
1547                //  allow_custom_portal_redirect
1548                $name = "network_".$this->getId()."_allow_custom_portal_redirect";
1549                $this->setCustomPortalRedirectAllowed(empty ($_REQUEST[$name]) ? false : true);
1550
1551                // GIS data
1552                if (defined('GMAPS_HOTSPOTS_MAP_ENABLED') && GMAPS_HOTSPOTS_MAP_ENABLED === true) {
1553                $gis_lat_name = "network_".$this->getId()."_gis_latitude";
1554                $gis_long_name = "network_".$this->getId()."_gis_longitude";
1555                $gis_alt_name = "network_".$this->getId()."_gis_altitude";
1556                $this->setGisLocation(new GisPoint($_REQUEST[$gis_lat_name], $_REQUEST[$gis_long_name], $_REQUEST[$gis_alt_name]));
1557
1558                $name = "network_".$this->getId()."_gmaps_map_type";
1559                $this->setGisMapType($_REQUEST[$name]);
1560                }
1561
1562                // Node creation
1563                $new_node = Node :: processCreateNewObjectUI();
1564                if ($new_node)
1565                {
1566                        $url = GENERIC_OBJECT_ADMIN_ABS_HREF."?".http_build_query(array ("object_class" => "Node", "action" => "edit", "object_id" => $new_node->getId()));
1567                        header("Location: {$url}");
1568                }
1569                // Content management
1570        $name = "network_" . $this->id . "_content";
1571        Content::processLinkedContentUI($name, 'network_has_content', 'network_id', $this->id);
1572        }
1573
1574        /** Add network-wide content to this network */
1575        public function addContent(Content $content)
1576        {
1577                global $db;
1578                $content_id = $db->escapeString($content->getId());
1579                $sql = "INSERT INTO network_has_content (network_id, content_id) VALUES ('$this->id','$content_id')";
1580                $db->execSqlUpdate($sql, false);
1581        }
1582
1583        /** Remove network-wide content from this network */
1584        public function removeContent(Content $content)
1585        {
1586                global $db;
1587                $content_id = $db->escapeString($content->getId());
1588                $sql = "DELETE FROM network_has_content WHERE network_id='$this->id' AND content_id='$content_id'";
1589                $db->execSqlUpdate($sql, false);
1590        }
1591
1592        /** Delete this Object form the it's storage mechanism
1593         * @param &$errmsg Returns an explanation of the error on failure
1594         * @return true on success, false on failure or access denied */
1595        public function delete(& $errmsg)
1596        {
1597                $retval = false;
1598                $user = User :: getCurrentUser();
1599                if (!$user->isSuperAdmin())
1600                {
1601                        $errmsg = _('Access denied (must have super admin access)');
1602                }
1603                else
1604                {
1605                        if ($this->isDefaultNetwork() === true)
1606                                $errmsg = _('Cannot delete default network, create another one and select it before remove this one.');
1607                        else
1608                        {
1609                                global $db;
1610                                $id = $db->escapeString($this->getId());
1611                                if (!$db->execSqlUpdate("DELETE FROM networks WHERE network_id='{$id}'", false))
1612                                {
1613                                        $errmsg = _('Could not delete network!');
1614                                }
1615                                else
1616                                {
1617                                        $retval = true;
1618                                }
1619                        }
1620                }
1621                return $retval;
1622        }
1623        /** Reloads the object from the database.  Should normally be called after a set operation */
1624        protected function refresh()
1625        {
1626                $this->__construct($this->id);
1627        }
1628
1629        public static function assignSmartyValues($smarty, $net=null) {
1630                if (!$net) $net = Network::getCurrentNetwork();
1631
1632                $smarty->assign('networkName', $net ? $net->getName() : '');
1633                $smarty->assign('networkHomepageURL', $net ? $net->getHomepageURL() : '');
1634                // Set networks usage information
1635                $smarty->assign('networkNumValidUsers', $net ? $net->getNumValidUsers() : 0);
1636                $smarty->assign('networkNumOnlineUsers', $net ? $net->getNumOnlineUsers() : 0);
1637
1638                // Set networks node information
1639                $smarty->assign('networkNumDeployedNodes', $net ? $net->getNumDeployedNodes() : 0);
1640                $smarty->assign('networkNumOnlineNodes', $net ? $net->getNumOnlineNodes() : 0);
1641        }
1642}
1643
1644/*
1645 * Local variables:
1646 * tab-width: 4
1647 * c-basic-offset: 4
1648 * c-hanging-comment-ender-p: nil
1649 * End:
1650 */
Note: See TracBrowser for help on using the browser.