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

Revision 733, 29.2 KB (checked in by aprilp, 8 years ago)

isset, and issues preventing users from logging out.

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