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

Revision 752, 31.3 KB (checked in by benoitg, 8 years ago)

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

  • schema_validate.php: Fix a bug version 26. The conversion of the old account_origin as a parameter to the authenticator was wrong. To fix it manually if you already ran the script, you must quote the parameter in column network_authenticator_params in the networks table.
  • Network.php: Fix improper quoting of Authenticator arguments.
  • RssPressReview?.php: Make expansion of today's item optionnal.
  • 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/********************************************************************\
5 * This program is free software; you can redistribute it and/or    *
6 * modify it under the terms of the GNU General Public License as   *
7 * published by the Free Software Foundation; either version 2 of   *
8 * the License, or (at your option) any later version.              *
9 *                                                                  *
10 * This program is distributed in the hope that it will be useful,  *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
13 * GNU General Public License for more details.                     *
14 *                                                                  *
15 * You should have received a copy of the GNU General Public License*
16 * along with this program; if not, contact:                        *
17 *                                                                  *
18 * Free Software Foundation           Voice:  +1-617-542-5942       *
19 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
20 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
21 *                                                                  *
22 \********************************************************************/
23/**@file Network.php
24 * @author Copyright (C) 2005 Benoit Grégoire <bock@step.polymtl.ca>
25 */
26require_once BASEPATH.'include/common.php';
27require_once BASEPATH.'classes/GenericObject.php';
28require_once BASEPATH.'classes/Content.php';
29require_once BASEPATH.'classes/User.php';
30
31/** Abstract a Network.  A network is an administrative entity with it's own users, nodes and authenticator. */
32class Network implements GenericObject
33{
34        private $id; /**< The network id */
35        private $mRow;
36
37        /** Get an instance of the object
38        * @see GenericObject
39        * @param $id The object id
40        * @return the Content object, or null if there was an error (an exception is also thrown)
41        */
42        static public function getObject($id)
43        {
44                return new self($id);
45        }
46
47        /** Get all the Networks configured on this server
48         * @return an array of Network objects.  The default network is returned
49         * first
50         */
51        static function getAllNetworks()
52        {
53                $retval = array ();
54                global $db;
55                $sql = "SELECT network_id FROM networks ORDER BY is_default_network DESC";
56                $network_rows = null;
57                $db->ExecSql($sql, $network_rows, false);
58                if ($network_rows == null)
59                {
60                        throw new Exception(_("Network::getAllNetworks:  Fatal error: No networks in the database!"));
61                }
62                foreach ($network_rows as $network_row)
63                {
64                        $retval[] = new self($network_row['network_id']);
65                }
66                return $retval;
67        }
68
69        /** Get the default network
70         * @return a Network object, NEVER returns null.
71         */
72        static function getDefaultNetwork($real_network_only = false)
73        {
74                $retval = null;
75                global $db;
76                $sql = "SELECT network_id FROM networks WHERE is_default_network=TRUE ORDER BY creation_date LIMIT 1";
77                $network_row = null;
78                $db->ExecSqlUniqueRes($sql, $network_row, false);
79                if ($network_row == null)
80                {
81                        throw new Exception(_("Network::getDefaultNetwork:  Fatal error: Unable to find the default network!"));
82                }
83                $retval = new self($network_row['network_id']);
84                return $retval;
85        }
86
87        /** Get the current network for which the portal is displayed or to which a user is physically connected.
88         * @param $real_network_only NOT IMPLEMENTED YET true or false.  If true,
89         * the real physical network where the user is connected is returned, and
90         * the node set by setCurrentNode is ignored.
91         * @return a Network object, NEVER returns null.
92         */
93        static function getCurrentNetwork($real_network_only = false)
94        {
95                $retval = null;
96                $current_node = Node :: getCurrentNode();
97                if ($current_node != null)
98                {
99                        $retval = $current_node->getNetwork();
100                }
101                else
102                {
103                        $retval = Network :: getDefaultNetwork();
104                }
105                return $retval;
106        }
107
108        /** Create a new Content object in the database
109         * @see GenericObject
110         * @param $network_id The network id of the new network.  If absent, will be
111         * assigned a guid.
112         * @return the newly created object, or null if there was an error
113         */
114        static function createNewObject($network_id = null)
115        {
116                global $db;
117                if(empty($network_id))
118                {
119                        $network_id = get_guid();
120                }
121                $network_id = $db->EscapeString($network_id);
122               
123                $sql = "INSERT INTO networks (network_id, network_authenticator_class) VALUES ('$network_id', 'AuthenticatorLocalUser')";
124
125                if (!$db->ExecSqlUpdate($sql, false))
126                {
127                        throw new Exception(_('Unable to insert the new network in the database!'));
128                }
129                $object = new self($network_id);
130                return $object;
131
132        }
133
134        /** Get an interface to pick a network.  If there is only one network available, no interface is actually shown
135        * @param $user_prefix A identifier provided by the programmer to recognise it's generated html form
136        * @return html markup
137        */
138        public static function getSelectNetworkUI($user_prefix)
139        {
140                $html = '';
141                $name = $user_prefix;
142                $html .= _("Network:")." \n";
143
144                global $db;
145                $sql = "SELECT network_id, name FROM networks ORDER BY is_default_network DESC";
146                $network_rows = null;
147                $db->ExecSql($sql, $network_rows, false);
148                if ($network_rows == null)
149                {
150                        throw new Exception(_("Network::getAllNetworks:  Fatal error: No networks in the database!"));
151                }
152
153                $network_array = self :: getAllNetworks();
154                $number_of_networks = count($network_rows);
155                if ($number_of_networks > 1)
156                {
157                        $i = 0;
158                        foreach ($network_rows as $network_row)
159                        {
160                                $tab[$i][0] = $network_row['network_id'];
161                                $tab[$i][1] = $network_row['name'];
162                                $i ++;
163                        }
164                        $html .= FormSelectGenerator :: generateFromArray($tab, null, $name, null, false);
165
166                }
167                else
168                {
169                        foreach ($network_rows as $network_row) //iterates only once...
170                        {
171                                $html .= " $network_row[name] ";
172                                $html .= "<input type='hidden' name='$name' value='$network_row[network_id]'>";
173                        }
174                }
175                return $html;
176        }
177
178        /** Get the selected Network object.
179         * @param $user_prefix A identifier provided by the programmer to recognise it's generated form
180         * @return the Network object
181         */
182        static function processSelectNetworkUI($user_prefix)
183        {
184                $object = null;
185                $name = "{$user_prefix}";
186                if (!empty ($_REQUEST[$name]))
187                        return new self($_REQUEST[$name]);
188                else
189                        return null;
190        }
191
192        /** Get an interface to create a new network.
193        * @return html markup
194        */
195        public static function getCreateNewObjectUI()
196        {
197                $html = '';
198                $html .= _("Create new network with id")." \n";
199                $name = "new_network_id";
200                $html .= "<input type='text' size='10' name='{$name}'>\n";
201                return $html;
202
203        }
204
205        /** Process the new object interface.
206         *  Will return the new object if the user has the credentials and the form was fully filled.
207         * @return the Network object or null if no new Network was created.
208         */
209        static function processCreateNewObjectUI()
210        {
211                $retval = null;
212                $name = "new_network_id";
213                if (!empty ($_REQUEST[$name]))
214                {
215                        $network_id = $_REQUEST[$name];
216                        if ($network_id)
217                        {
218                                if (!User :: getCurrentUser()->isSuperAdmin())
219                                {
220                                        throw new Exception(_("Access denied"));
221                                }
222                                $retval = self :: createNewObject($network_id);
223                        }
224                }
225                return $retval;
226        }
227
228        private function __construct($p_network_id)
229        {
230                global $db;
231
232                $network_id_str = $db->EscapeString($p_network_id);
233                $sql = "SELECT *, EXTRACT(EPOCH FROM validation_grace_time) as validation_grace_time_seconds FROM networks WHERE network_id='$network_id_str'";
234                $row = null;
235                $db->ExecSqlUniqueRes($sql, $row, false);
236                if ($row == null)
237                {
238                        throw new Exception("The network with id $network_id_str could not be found in the database");
239                }
240                $this->mRow = $row;
241                $this->id = $db->EscapeString($row['network_id']);
242        }
243
244        /** Retreives the id of the object
245         * @return The id */
246        public function getId()
247        {
248                return $this->id;
249        }
250
251        /** Retreives the network name
252         * @return The id */
253        public function getTechSupportEmail()
254        {
255                return $this->mRow['tech_support_email'];
256        }
257
258        /** Set the network's tech support and information email address
259         * @param $value The new value
260         * @return true on success, false on failure */
261        function setTechSupportEmail($value)
262        {
263                $retval = true;
264                if ($value != $this->getName())
265                {
266                        global $db;
267                        $value = $db->EscapeString($value);
268                        $retval = $db->ExecSqlUpdate("UPDATE networks SET tech_support_email = '{$value}' WHERE network_id = '{$this->getId()}'", false);
269                        $this->refresh();
270                }
271                return $retval;
272        }
273
274        /**
275         * Retrieves the network name
276         * @return A string
277         */
278        public function getName()
279        {
280                return $this->mRow['name'];
281        }
282
283        /** Set the network's name
284         * @param $value The new value
285         * @return true on success, false on failure
286         */
287        function setName($value)
288        {
289                $retval = true;
290                if ($value != $this->getName())
291                {
292                        global $db;
293                        $value = $db->EscapeString($value);
294                        $retval = $db->ExecSqlUpdate("UPDATE networks SET name = '{$value}' WHERE network_id = '{$this->getId()}'", false);
295                        $this->refresh();
296                }
297                return $retval;
298        }
299
300        /**
301         * Retrieves the network's creation date
302         * @return A string
303         */
304        public function getCreationDate()
305        {
306                return $this->mRow['creation_date'];
307        }
308
309        /** Retreives the network's homepage url
310         * @return The id */
311        public function getHomepageURL()
312        {
313                return $this->mRow['homepage_url'];
314        }
315
316        /** Set the network's homepage url
317         * @param $value The new value
318         * @return true on success, false on failure */
319        function setHomepageURL($value)
320        {
321                $retval = true;
322                if ($value != $this->getName())
323                {
324                        global $db;
325                        $value = $db->EscapeString($value);
326                        $retval = $db->ExecSqlUpdate("UPDATE networks SET homepage_url = '{$value}' WHERE network_id = '{$this->getId()}'", false);
327                        $this->refresh();
328                }
329                return $retval;
330        }
331
332        /** Retreives the network's authenticator's class.
333         *  @return    A string */
334        public function getAuthenticatorClassName()
335        {
336                return $this->mRow['network_authenticator_class'];
337        }
338
339        /** Set the network's authenticator's class.  The subclass of Authenticator to be used for user authentication (ex: AuthenticatorRadius)
340         * @param $value a string, the class name of a  subclass of Authenticator
341         * @return true on success, false on failure */
342        function setAuthenticatorClassName($value)
343        {
344                $retval = true;
345                if ($value != $this->getAuthenticatorClassName())
346                {
347                        global $db;
348                        $value = $db->EscapeString($value);
349                        $retval = $db->ExecSqlUpdate("UPDATE networks SET network_authenticator_class = '{$value}' WHERE network_id = '{$this->getId()}'", false);
350                        $this->refresh();
351                }
352                return $retval;
353        }
354
355        /** Retreives the authenticator's parameters
356         * @return A string */
357        public function getAuthenticatorConstructorParams()
358        {
359                return $this->mRow['network_authenticator_params'];
360        }
361
362        /** The explicit parameters to be passed to the authenticator's constructor (ex: 'my_network_id', '192.168.0.11', 1812, 1813, 'secret_key', 'CHAP_MD5')
363         * @param $value The new value
364         * @return true on success, false on failure */
365        function setAuthenticatorConstructorParams($value)
366        {
367                $retval = true;
368                if ($value != $this->getAuthenticatorConstructorParams())
369                {
370                        global $db;
371                        $value = $db->EscapeString($value);
372                        $retval = $db->ExecSqlUpdate("UPDATE networks SET network_authenticator_params = '{$value}' WHERE network_id = '{$this->getId()}'", false);
373                        $this->refresh();
374                }
375                return $retval;
376        }
377
378        /** Get the Authenticator object for this network
379         * @todo:  Reimplement this using the muich safer call_user_func_array
380         * instead of eval()  Benoitg 2005-09-10
381         * @return a subclass of Authenticator */
382        public function getAuthenticator()
383        {
384                require_once BASEPATH.'classes/Authenticator.php';
385                // Include only the authenticator we are about to use
386                require_once BASEPATH.'classes/'.$this->mRow['network_authenticator_class'].'.php';
387                if (strpos($this->mRow['network_authenticator_params'], ';') != false)
388                {
389                        throw new Exception("Network::getAuthenticator():  Security error:  The parameters passed to the constructor of the authenticator are potentially unsafe");
390                }
391                $objstring = 'return new '.$this->mRow['network_authenticator_class']."(".$this->mRow['network_authenticator_params'].");";
392                return eval ($objstring);
393        }
394
395        /** Is the network the default network?
396         * @return true or false */
397        public function isDefaultNetwork()
398        {
399                ($this->mRow['is_default_network'] == 't') ? $retval = true : $retval = false;
400                return $retval;
401        }
402
403        /** Set as the default network.  The can only be one default network, so this method will unset is_default_network for all other network
404         * @return true on success, false on failure */
405        function setAsDefaultNetwork()
406        {
407                $retval = true;
408                if (!$this->isDefaultNetwork())
409                {
410                        global $db;
411                        $sql = "UPDATE networks SET is_default_network = FALSE;\n";
412                        $sql .= "UPDATE networks SET is_default_network = TRUE WHERE network_id = '{$this->getId()}';\n";
413                        $retval = $db->ExecSqlUpdate($sql, false);
414                        $this->refresh();
415                }
416                return $retval;
417        }
418
419        /** Retreives the network's validation grace period
420         * @return An integer (seconds) */
421        public function getValidationGraceTime()
422        {
423                return $this->mRow['validation_grace_time_seconds'];
424        }
425
426        /** 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.
427         * @param $value The new value
428         * @return true on success, false on failure */
429        function setValidationGraceTime($value)
430        {
431                $retval = true;
432                if ($value != $this->getValidationGraceTime())
433                {
434                        global $db;
435                        $value = $db->EscapeString($value);
436                        $retval = $db->ExecSqlUpdate("UPDATE networks SET validation_grace_time = '{$value} seconds' WHERE network_id = '{$this->getId()}'", false);
437                        $this->refresh();
438                }
439                return $retval;
440        }
441
442        /** Retreives the FROM adress of the validation email
443         * @return A string */
444        public function getValidationEmailFromAddress()
445        {
446                return $this->mRow['validation_email_from_address'];
447        }
448
449        /** Set the FROM adress of the validation email
450         * @param $value The new value
451         * @return true on success, false on failure */
452        function setValidationEmailFromAddress($value)
453        {
454                $retval = true;
455                if ($value != $this->getValidationEmailFromAddress())
456                {
457                        global $db;
458                        $value = $db->EscapeString($value);
459                        $retval = $db->ExecSqlUpdate("UPDATE networks SET validation_email_from_address = '{$value}' WHERE network_id = '{$this->getId()}'", false);
460                        $this->refresh();
461                }
462                return $retval;
463        }
464
465        /** Can an account be connected more than once at the same time?
466         * @return true or false */
467        public function getMultipleLoginAllowed()
468        {
469                return ($this->mRow['allow_multiple_login'] == 't') ? true : false;
470        }
471
472        /** Set if a account be connected more than once at the same time?
473         * @param $value The new value, true or false
474         * @return true on success, false on failure */
475        function setMultipleLoginAllowed($value)
476        {
477                $retval = true;
478                if ($value != $this->getMultipleLoginAllowed())
479                {
480                        global $db;
481                        $value ? $value = 'TRUE' : $value = 'FALSE';
482                        $retval = $db->ExecSqlUpdate("UPDATE networks SET allow_multiple_login = {$value} WHERE network_id = '{$this->getId()}'", false);
483                        $this->refresh();
484                }
485                return $retval;
486        }
487
488        /** Are nodes allowed to be set as splash-only (no login)?
489         * @return true or false */
490        public function getSplashOnlyNodesAllowed()
491        {
492                return (($this->mRow['allow_splash_only_nodes'] == 't') ? true : false);
493        }
494
495        /** Set if nodes are allowed to be set as splash-only (no login)
496         * @param $value The new value, true or false
497         * @return true on success, false on failure */
498        function setSplashOnlyNodesAllowed($value)
499        {
500                $retval = true;
501                if ($value != $this->getSplashOnlyNodesAllowed())
502                {
503                        global $db;
504                        $value ? $value = 'TRUE' : $value = 'FALSE';
505                        $retval = $db->ExecSqlUpdate("UPDATE networks SET allow_splash_only_nodes = {$value} WHERE network_id = '{$this->getId()}'", false);
506                        $this->refresh();
507                }
508                return $retval;
509        }
510
511        /** 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.
512        * @param $username The username of the user
513        * @param $account_origin The account origin
514        * @return a User object
515        */
516        public function getSplashOnlyUser()
517        {
518                $username = 'SPLASH_ONLY_USER';
519
520                $user = User :: getUserByUsernameAndOrigin($username, $this);
521                if (!$user)
522                {
523                        $user = User :: createUser(get_guid(), $username, $this, '', '');
524                        $user->setAccountStatus(ACCOUNT_STATUS_ALLOWED);
525                }
526                return $user;
527        }
528        /** Are nodes allowed to redirect users to an arbitrary web page instead of the portal?
529         * @return true or false */
530        public function getCustomPortalRedirectAllowed()
531        {
532                return (($this->mRow['allow_custom_portal_redirect'] == 't') ? true : false);
533        }
534
535        /** Set if nodes are allowed to redirect users to an arbitrary web page instead of the portal?
536         * @param $value The new value, true or false
537         * @return true on success, false on failure */
538        function setCustomPortalRedirectAllowed($value)
539        {
540                $retval = true;
541                if ($value != $this->getCustomPortalRedirectAllowed())
542                {
543                        global $db;
544                        $value ? $value = 'TRUE' : $value = 'FALSE';
545                        $retval = $db->ExecSqlUpdate("UPDATE networks SET allow_custom_portal_redirect = {$value} WHERE network_id = '{$this->getId()}'", false);
546                        $this->refresh();
547                }
548                return $retval;
549        }
550
551        /** Does the user have admin access to this network?
552         * @return true our false*/
553        function hasAdminAccess(User $user)
554        {
555                global $db;
556                $retval = false;
557                if ($user != null)
558                {
559                        $user_id = $user->getId();
560                        $retval = false;
561                        $db->ExecSqlUniqueRes("SELECT * FROM network_stakeholders WHERE is_admin = true AND network_id='{$this->id}' AND user_id='{$user_id}'", $row, false);
562                        if ($row != null)
563                        {
564                                $retval = true;
565                        }
566                        else
567                                if ($user->isSuperAdmin())
568                                {
569                                        $retval = true;
570                                }
571                }
572                return $retval;
573        }
574
575        /**Get an array of all Content linked to the network
576        * @param boolean $exclude_subscribed_content
577        * @param User $subscriber The User object used to discriminate the content
578        * @return an array of Content or an empty arrray */
579        function getAllContent($exclude_subscribed_content = false, $subscriber = null)
580        {
581                global $db;
582                $retval = array ();
583                // Get all network, but exclude user subscribed content if asked
584                if ($exclude_subscribed_content == true && $subscriber)
585                        $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";
586                else
587                        $sql = "SELECT content_id FROM network_has_content WHERE network_id='$this->id' ORDER BY subscribe_timestamp DESC";
588                $db->ExecSql($sql, $content_rows, false);
589
590                if ($content_rows != null)
591                {
592                        foreach ($content_rows as $content_row)
593                        {
594                                $retval[] = Content :: getObject($content_row['content_id']);
595                        }
596                }
597                return $retval;
598        }
599
600        /** Retreives the admin interface of this object.
601         * @return The HTML fragment for this interface */
602
603        public function getAdminUI()
604        {
605                $html = '';
606                $html .= "<h3>"._("Network management")."</h3>\n";
607                $html .= "<div class='admin_container'>\n";
608                $html .= "<div class='admin_class'>Network (".get_class($this)." instance)</div>\n";
609
610                // network_id
611                $html .= "<div class='admin_section_container'>\n";
612                $html .= "<div class='admin_section_title'>"._("Network ID")." : </div>\n";
613                $html .= "<div class='admin_section_data'>\n";
614                $name = "network_".$this->getId()."_name";
615                $value = htmlspecialchars($this->getId(), ENT_QUOTES);
616                $html .= $value;
617                //$html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
618                $html .= "</div>\n";
619                $html .= "</div>\n";
620
621                // name
622                $html .= "<div class='admin_section_container'>\n";
623                $html .= "<div class='admin_section_title'>"._("Network name")." : </div>\n";
624                $html .= "<div class='admin_section_data'>\n";
625                $name = "network_".$this->getId()."_name";
626                $value = htmlspecialchars($this->getName(), ENT_QUOTES);
627                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
628                $html .= "</div>\n";
629                $html .= "</div>\n";
630
631                // homepage_url
632                $html .= "<div class='admin_section_container'>\n";
633                $html .= "<div class='admin_section_title'>"._("Network's web site")." : </div>\n";
634                $html .= "<div class='admin_section_data'>\n";
635                $name = "network_".$this->getId()."_homepage_url";
636                $value = htmlspecialchars($this->getHomepageURL(), ENT_QUOTES);
637                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
638                $html .= "</div>\n";
639                $html .= "</div>\n";
640
641                // tech_support_email
642                $html .= "<div class='admin_section_container'>\n";
643                $html .= "<div class='admin_section_title'>"._("Technical support email")." : </div>\n";
644                $html .= "<div class='admin_section_data'>\n";
645                $name = "network_".$this->getId()."_tech_support_email";
646                $value = htmlspecialchars($this->getTechSupportEmail(), ENT_QUOTES);
647                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
648                $html .= "</div>\n";
649                $html .= "</div>\n";
650
651                //  network_authenticator_class
652                $html .= "<div class='admin_section_container'>\n";
653                $html .= "<div class='admin_section_title'>"._("Network authenticator class.  The subclass of Authenticator to be used for user authentication (ex: AuthenticatorRadius)")." : </div>\n";
654                $html .= "<div class='admin_section_data'>\n";
655                $name = "network_".$this->getId()."_network_authenticator_class";
656                $value = htmlspecialchars($this->getAuthenticatorClassName(), ENT_QUOTES);
657                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
658                $html .= "</div>\n";
659                $html .= "</div>\n";
660
661                //  network_authenticator_params
662                $html .= "<div class='admin_section_container'>\n";
663                $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";
664                $html .= "<div class='admin_section_data'>\n";
665                $name = "network_".$this->getId()."_network_authenticator_params";
666                $value = htmlspecialchars($this->getAuthenticatorConstructorParams(), ENT_QUOTES);
667                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
668                $html .= "</div>\n";
669                $html .= "</div>\n";
670
671                //  is_default_network
672                $html .= "<div class='admin_section_container'>\n";
673                $html .= "<div class='admin_section_title'>"._("Is this network the default network?")." : </div>\n";
674                $html .= "<div class='admin_section_data'>\n";
675                $name = "network_".$this->getId()."_is_default_network";
676                $this->isDefaultNetwork() ? $checked = 'CHECKED' : $checked = '';
677                $html .= "<input type='checkbox' name='$name' $checked>\n";
678                $html .= "</div>\n";
679                $html .= "</div>\n";
680
681                //  validation_grace_time
682                $html .= "<div class='admin_section_container'>\n";
683                $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";
684                $html .= "<div class='admin_section_data'>\n";
685                $name = "network_".$this->getId()."_validation_grace_time";
686                $value = htmlspecialchars($this->getValidationGraceTime(), ENT_QUOTES);
687                $html .= "<input type='text' size ='5' value='$value' name='$name'>\n";
688                $html .= "</div>\n";
689                $html .= "</div>\n";
690
691                //  validation_email_from_address
692                $html .= "<div class='admin_section_container'>\n";
693                $html .= "<div class='admin_section_title'>"._("This will be the from adress of the validation email")." : </div>\n";
694                $html .= "<div class='admin_section_data'>\n";
695                $name = "network_".$this->getId()."_validation_email_from_address";
696                $value = htmlspecialchars($this->getValidationEmailFromAddress(), ENT_QUOTES);
697                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
698                $html .= "</div>\n";
699                $html .= "</div>\n";
700
701                //  allow_multiple_login
702                $html .= "<div class='admin_section_container'>\n";
703                $html .= "<div class='admin_section_title'>"._("Can an account be connected more than once at the same time?")." : </div>\n";
704                $html .= "<div class='admin_section_data'>\n";
705                $name = "network_".$this->getId()."_allow_multiple_login";
706                $this->getMultipleLoginAllowed() ? $checked = 'CHECKED' : $checked = '';
707                $html .= "<input type='checkbox' name='$name' $checked>\n";
708                $html .= "</div>\n";
709                $html .= "</div>\n";
710
711                //  allow_splash_only_nodes
712                $html .= "<div class='admin_section_container'>\n";
713                $html .= "<div class='admin_section_title'>"._("Are nodes allowed to be set as splash-only (no login)?")." : </div>\n";
714                $html .= "<div class='admin_section_data'>\n";
715                $name = "network_".$this->getId()."_allow_splash_only_nodes";
716                $this->getSplashOnlyNodesAllowed() ? $checked = 'CHECKED' : $checked = '';
717                $html .= "<input type='checkbox' name='$name' $checked>\n";
718                $html .= "</div>\n";
719                $html .= "</div>\n";
720
721                //  allow_custom_portal_redirect
722                $html .= "<div class='admin_section_container'>\n";
723                $html .= "<div class='admin_section_title'>"._("Are nodes allowed to redirect users to an arbitrary web page instead of the portal?")." : </div>\n";
724                $html .= "<div class='admin_section_data'>\n";
725                $name = "network_".$this->getId()."_allow_custom_portal_redirect";
726                $this->getCustomPortalRedirectAllowed() ? $checked = 'CHECKED' : $checked = '';
727                $html .= "<input type='checkbox' name='$name' $checked>\n";
728                $html .= "</div>\n";
729                $html .= "</div>\n";
730
731                //      network_stakeholders
732                $html .= "<div class='admin_section_container'>\n";
733                $html .= "<div class='admin_section_title'>"._("Network stakeholders")." : </div>\n";
734                $html .= "<div class='admin_section_data'>\n";
735                //$name = "network_".$this->getId()."_allow_custom_portal_redirect";
736                //$this->getCustomPortalRedirectAllowed()? $checked='CHECKED': $checked='';
737                //$html .= "<input type='checkbox' name='$name' $checked>\n";
738                $html .= "WRITEME!";
739                $html .= "</div>\n";
740                $html .= "</div>\n";
741
742                // Create new nodes
743                $html .= "<div class='admin_section_container'>\n";
744                $html .= "<div class='admin_section_title'>"._("New node ID")." : </div>\n";
745
746                $html .= "<div class='admin_section_data'>\n";
747
748                $html .= Node :: getCreateNewObjectUI($this);
749
750                $html .= "<div class='admin_section_tools'>\n";
751                $name = "network_{$this->getId()}_create_node";
752                $html .= "<input type='submit' name='{$name}' value='"._("Create a new node")."'>\n";
753                $html .= "</div>\n";
754
755                $html .= "</div>\n";
756                $html .= "</div>\n";
757
758                // Content management           
759                $html .= "<div class='admin_section_container'>\n";
760                $html .= "<div class='admin_section_title'>"._("Network content:")."</div>\n";
761                $html .= "<ul class='admin_section_list'>\n";
762                foreach ($this->getAllContent() as $content)
763                {
764                        $html .= "<li class='admin_section_list_item'>\n";
765                        $html .= "<div class='admin_section_data'>\n";
766                        $html .= $content->getListUI();
767                        $html .= "</div'>\n";
768                        $html .= "<div class='admin_section_tools'>\n";
769                        $name = "node_".$this->id."_content_".$content->GetId()."_edit";
770                        $html .= "<input type='button' name='$name' value='"._("Edit")."' onClick='window.location.href = \"".GENERIC_OBJECT_ADMIN_ABS_HREF."?object_class=Content&action=edit&object_id=".$content->GetId()."\";'>\n";
771                        $name = "content_group_".$this->id."_element_".$content->GetId()."_erase";
772                        $html .= "<input type='submit' name='$name' value='"._("Remove")."'>";
773                        $html .= "</div>\n";
774                        $html .= "</li>\n";
775                }
776                $html .= "<li class='admin_section_list_item'>\n";
777                $name = "network_{$this->id}_new_content";
778                $html .= Content :: getSelectContentUI($name, "AND content_id NOT IN (SELECT content_id FROM network_has_content WHERE network_id='$this->id')");
779                $name = "network_{$this->id}_new_content_submit";
780                $html .= "<input type='submit' name='$name' value='"._("Add")."'>";
781                $html .= "</li>\n";
782                $html .= "</ul>\n";
783                $html .= "</div>\n";
784                $html .= "</div>\n";
785
786                return $html;
787        }
788
789        /** Process admin interface of this object.
790        */
791        public function processAdminUI()
792        {
793                //pretty_print_r($_REQUEST);
794                $user = User :: getCurrentUser();
795                if (!$this->hasAdminAccess($user))
796                {
797                        throw new Exception(_('Access denied!'));
798                }
799
800                // name
801                $name = "network_".$this->getId()."_name";
802                $this->setName($_REQUEST[$name]);
803
804                // homepage_url
805                $name = "network_".$this->getId()."_homepage_url";
806                $this->setHomepageURL($_REQUEST[$name]);
807
808                // tech_support_email
809                $name = "network_".$this->getId()."_tech_support_email";
810                $this->setTechSupportEmail($_REQUEST[$name]);
811
812                //  network_authenticator_class
813                $name = "network_".$this->getId()."_network_authenticator_class";
814                $this->setAuthenticatorClassName($_REQUEST[$name]);
815
816                //  network_authenticator_params
817                $name = "network_".$this->getId()."_network_authenticator_params";
818                $this->setAuthenticatorConstructorParams($_REQUEST[$name]);
819
820                //  is_default_network
821                $name = "network_".$this->getId()."_is_default_network";
822                if (!empty($_REQUEST[$name]) && $_REQUEST[$name] == 'on')
823                        $this->setAsDefaultNetwork();
824               
825
826                //  validation_grace_time
827                $name = "network_".$this->getId()."_validation_grace_time";
828                $this->setValidationGraceTime($_REQUEST[$name]);
829
830                //  validation_email_from_address
831                $name = "network_".$this->getId()."_validation_email_from_address";
832                $this->setValidationEmailFromAddress($_REQUEST[$name]);
833
834                //  allow_multiple_login
835                $name = "network_".$this->getId()."_allow_multiple_login";
836                $this->setMultipleLoginAllowed(empty ($_REQUEST[$name]) ? false : true);
837
838                //  allow_splash_only_nodes
839                $name = "network_".$this->getId()."_allow_splash_only_nodes";
840                $this->setSplashOnlyNodesAllowed(empty ($_REQUEST[$name]) ? false : true);
841
842                //  allow_custom_portal_redirect
843                $name = "network_".$this->getId()."_allow_custom_portal_redirect";
844                $this->setCustomPortalRedirectAllowed(empty ($_REQUEST[$name]) ? false : true);
845
846                // Node creation
847                $new_node = Node :: processCreateNewObjectUI();
848                if ($new_node)
849                {
850                        $url = GENERIC_OBJECT_ADMIN_ABS_HREF."?".http_build_query(array ("object_class" => "Node", "action" => "edit", "object_id" => $new_node->getId()));
851                        header("Location: {$url}");
852                }
853                // Content management
854                foreach ($this->getAllContent() as $content)
855                {
856                        $name = "content_group_".$this->id."_element_".$content->GetId()."_erase";
857                        if (!empty ($_REQUEST[$name]))
858                        {
859                                $this->removeContent($content);
860                        }
861                }
862
863                $name = "network_{$this->id}_new_content_submit";
864                if (!empty ($_REQUEST[$name]))
865                {
866                        $name = "network_{$this->id}_new_content";
867                        $content = Content :: processSelectContentUI($name);
868                        if ($content)
869                                $this->addContent($content);
870                }
871        }
872
873        /** Add network-wide content to this network */
874        public function addContent(Content $content)
875        {
876                global $db;
877                $content_id = $db->EscapeString($content->getId());
878                $sql = "INSERT INTO network_has_content (network_id, content_id) VALUES ('$this->id','$content_id')";
879                $db->ExecSqlUpdate($sql, false);
880        }
881
882        /** Remove network-wide content from this network */
883        public function removeContent(Content $content)
884        {
885                global $db;
886                $content_id = $db->EscapeString($content->getId());
887                $sql = "DELETE FROM network_has_content WHERE network_id='$this->id' AND content_id='$content_id'";
888                $db->ExecSqlUpdate($sql, false);
889        }
890
891        /** Delete this Object form the it's storage mechanism
892         * @param &$errmsg Returns an explanation of the error on failure
893         * @return true on success, false on failure or access denied */
894        public function delete(& $errmsg)
895        {
896                $retval = false;
897                $user = User :: getCurrentUser();
898                if (!$user->isSuperAdmin())
899                {
900                        $errmsg = _('Access denied (must have super admin access)');
901                }
902                else
903                {
904                global $db;
905                $id = $db->EscapeString($this->getId());
906                if (!$db->ExecSqlUpdate("DELETE FROM networks WHERE network_id='{$id}'", false))
907                {
908                        $errmsg = _('Could not delete network!');
909                }
910                else
911                {
912                        $retval = true;
913                }
914                }
915                return $retval;
916        }
917        /** Reloads the object from the database.  Should normally be called after a set operation */
918        protected function refresh()
919        {
920                $this->__construct($this->id);
921        }
922
923} //End class
924?>
Note: See TracBrowser for help on using the browser.