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

Revision 1083, 59.4 KB (checked in by max-horvath, 7 years ago)

"2006-08-28 Benoit Gregoire <bock@…>

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