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

Revision 715, 28.5 KB (checked in by fproulx, 8 years ago)

2005-08-31 Francois Proulx <francois.proulx@…>

  • Removed update.php script ( should not have been in CVS )
  • Moved authenticator require in Network getAuthenticator()
  • 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        /** Retreives the network's homepage url
247         * @return The id */
248        public function getHomepageURL()
249        {
250                return $this->mRow['homepage_url'];
251        }
252
253        /** Set the network's homepage url
254         * @param $value The new value
255         * @return true on success, false on failure */
256        function setHomepageURL($value)
257        {
258                $retval = true;
259                if ($value != $this->getName())
260                {
261                        global $db;
262                        $value = $db->EscapeString($value);
263                        $retval = $db->ExecSqlUpdate("UPDATE networks SET homepage_url = '{$value}' WHERE network_id = '{$this->getId()}'", false);
264                        $this->refresh();
265                }
266                return $retval;
267        }
268
269        /** Retreives the network's authenticator's class.
270         *  @return    A string */
271        public function getAuthenticatorClassName()
272        {
273                return $this->mRow['network_authenticator_class'];
274        }
275
276        /** Set the network's authenticator's class.  The subclass of Authenticator to be used for user authentication (ex: AuthenticatorRadius)
277         * @param $value a string, the class name of a  subclass of Authenticator
278         * @return true on success, false on failure */
279        function setAuthenticatorClassName($value)
280        {
281                $retval = true;
282                if ($value != $this->getAuthenticatorClassName())
283                {
284                        global $db;
285                        $value = $db->EscapeString($value);
286                        $retval = $db->ExecSqlUpdate("UPDATE networks SET network_authenticator_class = '{$value}' WHERE network_id = '{$this->getId()}'", false);
287                        $this->refresh();
288                }
289                return $retval;
290        }
291               
292        /** Retreives the authenticator's parameters
293         * @return A string */
294        public function getAuthenticatorConstructorParams()
295        {
296                return $this->mRow['network_authenticator_params'];
297        }
298
299        /** 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')
300         * @param $value The new value
301         * @return true on success, false on failure */
302        function setAuthenticatorConstructorParams($value)
303        {
304                $retval = true;
305                if ($value != $this->getAuthenticatorConstructorParams())
306                {
307                        global $db;
308                        $value = $db->EscapeString($value);
309                        $retval = $db->ExecSqlUpdate("UPDATE networks SET network_authenticator_params = '{$value}' WHERE network_id = '{$this->getId()}'", false);
310                        $this->refresh();
311                }
312                return $retval;
313        }
314       
315        /** Get the Authenticator object for this network
316         * @return a subclass of Authenticator */
317        public function getAuthenticator()
318        {
319                require_once BASEPATH.'classes/Authenticator.php';
320                // Include only the authenticator we are about to use
321                require_once BASEPATH.'classes/'.$this->mRow['network_authenticator_class'].'.php';
322                if (strpos($this->mRow['network_authenticator_params'], ';') != false)
323                {
324                        throw new Exception("Network::getAuthenticator():  Security error:  The parameters passed to the constructor of the authenticator are potentially unsafe");
325                }
326                $objstring = 'return new '.$this->mRow['network_authenticator_class'].'('.$this->mRow['network_authenticator_params'].');';
327                return eval ($objstring);
328        }
329               
330        /** Is the network the default network?
331         * @return true or false */
332        public function isDefaultNetwork()
333        {
334                ($this->mRow['is_default_network']=='t')?$retval=true:$retval=false;
335                return $retval;
336        }
337
338        /** Set as the default network.  The can only be one default network, so this method will unset is_default_network for all other network
339         * @return true on success, false on failure */
340        function setAsDefaultNetwork()
341        {
342                $retval = true;
343                if (!$this->isDefaultNetwork())
344                {
345                        global $db;
346                        $sql = "UPDATE networks SET is_default_network = FALSE;\n";
347                        $sql .= "UPDATE networks SET is_default_network = TRUE WHERE network_id = '{$this->getId()}';\n";
348                        $retval = $db->ExecSqlUpdate($sql, false);
349                        $this->refresh();
350                }
351                return $retval;
352        }
353
354        /** Retreives the network's validation grace period
355         * @return An integer (seconds) */
356        public function getValidationGraceTime()
357        {
358                return $this->mRow['validation_grace_time_seconds'];
359        }
360
361        /** 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.
362         * @param $value The new value
363         * @return true on success, false on failure */
364        function setValidationGraceTime($value)
365        {
366                $retval = true;
367                if ($value != $this->getValidationGraceTime())
368                {
369                        global $db;
370                        $value = $db->EscapeString($value);
371                        $retval = $db->ExecSqlUpdate("UPDATE networks SET validation_grace_time = '{$value} seconds' WHERE network_id = '{$this->getId()}'", false);
372                        $this->refresh();
373                }
374                return $retval;
375        }
376                       
377        /** Retreives the FROM adress of the validation email
378         * @return A string */
379        public function getValidationEmailFromAddress()
380        {
381                return $this->mRow['validation_email_from_address'];
382        }
383
384        /** Set the FROM adress of the validation email
385         * @param $value The new value
386         * @return true on success, false on failure */
387        function setValidationEmailFromAddress($value)
388        {
389                $retval = true;
390                if ($value != $this->getValidationEmailFromAddress())
391                {
392                        global $db;
393                        $value = $db->EscapeString($value);
394                        $retval = $db->ExecSqlUpdate("UPDATE networks SET validation_email_from_address = '{$value}' WHERE network_id = '{$this->getId()}'", false);
395                        $this->refresh();
396                }
397                return $retval;
398        }
399               
400        /** Can an account be connected more than once at the same time?
401         * @return true or false */
402        public function getMultipleLoginAllowed()
403        {
404                ($this->mRow['allow_multiple_login']=='t')?$retval=true:$retval=false;
405                return $retval;
406        }
407
408        /** Set if a account be connected more than once at the same time?
409         * @param $value The new value, true or false
410         * @return true on success, false on failure */
411        function setMultipleLoginAllowed($value)
412        {
413                $retval = true;
414                if ($value != $this->getMultipleLoginAllowed())
415                {
416                        global $db;
417                        $value?$value='TRUE':$value='FALSE';
418                        $retval = $db->ExecSqlUpdate("UPDATE networks SET allow_multiple_login = {$value} WHERE network_id = '{$this->getId()}'", false);
419                        $this->refresh();
420                }
421                return $retval;
422        }
423
424        /** Are nodes allowed to be set as splash-only (no login)?
425         * @return true or false */
426        public function getSplashOnlyNodesAllowed()
427        {
428                return (($this->mRow['allow_splash_only_nodes']=='t') ? true : false);
429        }
430
431        /** Set if nodes are allowed to be set as splash-only (no login)
432         * @param $value The new value, true or false
433         * @return true on success, false on failure */
434        function setSplashOnlyNodesAllowed($value)
435        {
436                $retval = true;
437                if ($value != $this->getSplashOnlyNodesAllowed())
438                {
439                        global $db;
440                        $value?$value='TRUE':$value='FALSE';
441                        $retval = $db->ExecSqlUpdate("UPDATE networks SET allow_splash_only_nodes = {$value} WHERE network_id = '{$this->getId()}'", false);
442                        $this->refresh();
443                }
444                return $retval;
445        }               
446       
447        /** Are nodes allowed to redirect users to an arbitrary web page instead of the portal?
448         * @return true or false */
449        public function getCustomPortalRedirectAllowed()
450        {
451                return (($this->mRow['allow_custom_portal_redirect']=='t') ? true : false);
452        }
453
454        /** Set if nodes are allowed to redirect users to an arbitrary web page instead of the portal?
455         * @param $value The new value, true or false
456         * @return true on success, false on failure */
457        function setCustomPortalRedirectAllowed($value)
458        {
459                $retval = true;
460                if ($value != $this->getCustomPortalRedirectAllowed())
461                {
462                        global $db;
463                        $value?$value='TRUE':$value='FALSE';
464                        $retval = $db->ExecSqlUpdate("UPDATE networks SET allow_custom_portal_redirect = {$value} WHERE network_id = '{$this->getId()}'", false);
465                        $this->refresh();
466                }
467                return $retval;
468        }               
469
470        /**Get an array of all Content linked to the network
471        * @param boolean $exclude_subscribed_content
472        * @param User $subscriber The User object used to discriminate the content
473        * @return an array of Content or an empty arrray */
474        function getAllContent($exclude_subscribed_content = false, $subscriber = null)
475        {
476                global $db;
477                $retval = array ();
478                // Get all network, but exclude user subscribed content if asked
479                if ($exclude_subscribed_content == true && $subscriber)
480                        $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";
481                else
482                        $sql = "SELECT content_id FROM network_has_content WHERE network_id='$this->id' ORDER BY subscribe_timestamp DESC";
483                $db->ExecSql($sql, $content_rows, false);
484
485                if ($content_rows != null)
486                {
487                        foreach ($content_rows as $content_row)
488                        {
489                                $retval[] = Content :: getObject($content_row['content_id']);
490                        }
491                }
492                return $retval;
493        }
494
495        /** Retreives the admin interface of this object.
496         * @return The HTML fragment for this interface */
497
498        public function getAdminUI()
499        {
500                $html = '';
501                $html .= "<h3>"._("Network management")."</h3>\n";
502                $html .= "<div class='admin_container'>\n";
503                $html .= "<div class='admin_class'>Network (".get_class($this)." instance)</div>\n";
504
505                // network_id
506                $html .= "<div class='admin_section_container'>\n";
507                $html .= "<div class='admin_section_title'>"._("Network ID")." : </div>\n";
508                $html .= "<div class='admin_section_data'>\n";
509                $name = "network_".$this->getId()."_name";
510                $value = htmlspecialchars($this->getId(), ENT_QUOTES);
511                $html .= $value;
512                //$html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
513                $html .= "</div>\n";
514                $html .= "</div>\n";
515               
516                // name
517                $html .= "<div class='admin_section_container'>\n";
518                $html .= "<div class='admin_section_title'>"._("Network name")." : </div>\n";
519                $html .= "<div class='admin_section_data'>\n";
520                $name = "network_".$this->getId()."_name";
521                $value = htmlspecialchars($this->getName(), ENT_QUOTES);
522                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
523                $html .= "</div>\n";
524                $html .= "</div>\n";
525
526                // homepage_url
527                $html .= "<div class='admin_section_container'>\n";
528                $html .= "<div class='admin_section_title'>"._("Network's web site")." : </div>\n";
529                $html .= "<div class='admin_section_data'>\n";
530                $name = "network_".$this->getId()."_homepage_url";
531                $value = htmlspecialchars($this->getHomepageURL(), ENT_QUOTES);
532                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
533                $html .= "</div>\n";
534                $html .= "</div>\n";
535
536                // tech_support_email
537                $html .= "<div class='admin_section_container'>\n";
538                $html .= "<div class='admin_section_title'>"._("Technical support email")." : </div>\n";
539                $html .= "<div class='admin_section_data'>\n";
540                $name = "network_".$this->getId()."_tech_support_email";
541                $value = htmlspecialchars($this->getTechSupportEmail(), ENT_QUOTES);
542                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
543                $html .= "</div>\n";
544                $html .= "</div>\n";
545
546
547                //  network_authenticator_class
548                $html .= "<div class='admin_section_container'>\n";
549                $html .= "<div class='admin_section_title'>"._("Network authenticator class.  The subclass of Authenticator to be used for user authentication (ex: AuthenticatorRadius)")." : </div>\n";
550                $html .= "<div class='admin_section_data'>\n";
551                $name = "network_".$this->getId()."_network_authenticator_class";
552                $value = htmlspecialchars($this->getAuthenticatorClassName(), ENT_QUOTES);
553                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
554                $html .= "</div>\n";
555                $html .= "</div>\n";
556
557                //  network_authenticator_params
558                $html .= "<div class='admin_section_container'>\n";
559                $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";
560                $html .= "<div class='admin_section_data'>\n";
561                $name = "network_".$this->getId()."_network_authenticator_params";
562                $value = htmlspecialchars($this->getAuthenticatorConstructorParams(), ENT_QUOTES);
563                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
564                $html .= "</div>\n";
565                $html .= "</div>\n";           
566               
567                //  is_default_network
568                $html .= "<div class='admin_section_container'>\n";
569                $html .= "<div class='admin_section_title'>"._("Is this network the default network?")." : </div>\n";
570                $html .= "<div class='admin_section_data'>\n";
571                $name = "network_".$this->getId()."_is_default_network";
572                $this->isDefaultNetwork()? $checked='CHECKED': $checked='';
573                $html .= "<input type='checkbox' name='$name' $checked>\n";
574                $html .= "</div>\n";
575                $html .= "</div>\n";                   
576       
577                //  validation_grace_time
578                $html .= "<div class='admin_section_container'>\n";
579                $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";
580                $html .= "<div class='admin_section_data'>\n";
581                $name = "network_".$this->getId()."_validation_grace_time";
582                $value = htmlspecialchars($this->getValidationGraceTime(), ENT_QUOTES);
583                $html .= "<input type='text' size ='5' value='$value' name='$name'>\n";
584                $html .= "</div>\n";
585                $html .= "</div>\n";
586                       
587                //  validation_email_from_address
588                $html .= "<div class='admin_section_container'>\n";
589                $html .= "<div class='admin_section_title'>"._("This will be the from adress of the validation email")." : </div>\n";
590                $html .= "<div class='admin_section_data'>\n";
591                $name = "network_".$this->getId()."_validation_email_from_address";
592                $value = htmlspecialchars($this->getValidationEmailFromAddress(), ENT_QUOTES);
593                $html .= "<input type='text' size ='50' value='$value' name='$name'>\n";
594                $html .= "</div>\n";
595                $html .= "</div>\n";
596               
597                //  allow_multiple_login
598                $html .= "<div class='admin_section_container'>\n";
599                $html .= "<div class='admin_section_title'>"._("Can an account be connected more than once at the same time?")." : </div>\n";
600                $html .= "<div class='admin_section_data'>\n";
601                $name = "network_".$this->getId()."_allow_multiple_login";
602                $this->getMultipleLoginAllowed()? $checked='CHECKED': $checked='';
603                $html .= "<input type='checkbox' name='$name' $checked>\n";
604                $html .= "</div>\n";
605                $html .= "</div>\n";
606               
607                //  allow_splash_only_nodes
608                $html .= "<div class='admin_section_container'>\n";
609                $html .= "<div class='admin_section_title'>"._("Are nodes allowed to be set as splash-only (no login)?")." : </div>\n";
610                $html .= "<div class='admin_section_data'>\n";
611                $name = "network_".$this->getId()."_allow_splash_only_nodes";
612                $this->getSplashOnlyNodesAllowed()? $checked='CHECKED': $checked='';
613                $html .= "<input type='checkbox' name='$name' $checked>\n";
614                $html .= "</div>\n";
615                $html .= "</div>\n";
616               
617                //  allow_custom_portal_redirect
618                $html .= "<div class='admin_section_container'>\n";
619                $html .= "<div class='admin_section_title'>"._("Are nodes allowed to redirect users to an arbitrary web page instead of the portal?")." : </div>\n";
620                $html .= "<div class='admin_section_data'>\n";
621                $name = "network_".$this->getId()."_allow_custom_portal_redirect";
622                $this->getCustomPortalRedirectAllowed()? $checked='CHECKED': $checked='';
623                $html .= "<input type='checkbox' name='$name' $checked>\n";
624                $html .= "</div>\n";
625                $html .= "</div>\n";
626               
627                //      network_stakeholders
628                $html .= "<div class='admin_section_container'>\n";
629                $html .= "<div class='admin_section_title'>"._("Network stakeholders")." : </div>\n";
630                $html .= "<div class='admin_section_data'>\n";
631                //$name = "network_".$this->getId()."_allow_custom_portal_redirect";
632                //$this->getCustomPortalRedirectAllowed()? $checked='CHECKED': $checked='';
633                //$html .= "<input type='checkbox' name='$name' $checked>\n";
634                $html .= "WRITEME!";
635                $html .= "</div>\n";
636                $html .= "</div>\n";           
637                               
638                // Create new nodes
639                $html .= "<div class='admin_section_container'>\n";
640                $html .= "<div class='admin_section_title'>"._("New node ID")." : </div>\n";
641
642                $html .= "<div class='admin_section_data'>\n";
643                $name = "network_{$this->getId()}_new_node_id";
644                $html .= "<input type='text' size='10' name='{$name}'>\n";
645
646                $html .= "<div class='admin_section_tools'>\n";
647                $name = "network_{$this->getId()}_create_node";
648                $html .= "<input type='submit' name='{$name}' value='"._("Create a new node")."'>\n";
649                $html .= "</div>\n";
650
651                $html .= "</div>\n";
652                $html .= "</div>\n";
653
654                // Content management           
655                $html .= "<div class='admin_section_container'>\n";
656                $html .= "<div class='admin_section_title'>"._("Network content:")."</div>\n";
657                $html .= "<ul class='admin_section_list'>\n";
658                foreach ($this->getAllContent() as $content)
659                {
660                        $html .= "<li class='admin_section_list_item'>\n";
661                        $html .= "<div class='admin_section_data'>\n";
662                        $html .= $content->getListUI();
663                        $html .= "</div'>\n";
664                        $html .= "<div class='admin_section_tools'>\n";
665                        $name = "node_".$this->id."_content_".$content->GetId()."_edit";
666                        $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";
667                        $name = "content_group_".$this->id."_element_".$content->GetId()."_erase";
668                        $html .= "<input type='submit' name='$name' value='"._("Remove")."'>";
669                        $html .= "</div>\n";
670                        $html .= "</li>\n";
671                }
672                $html .= "<li class='admin_section_list_item'>\n";
673                $name = "network_{$this->id}_new_content";
674                $html .= Content :: getSelectContentUI($name, "AND content_id NOT IN (SELECT content_id FROM network_has_content WHERE network_id='$this->id')");
675                $name = "network_{$this->id}_new_content_submit";
676                $html .= "<input type='submit' name='$name' value='"._("Add")."'>";
677                $html .= "</li>\n";
678                $html .= "</ul>\n";
679                $html .= "</div>\n";
680                $html .= "</div>\n";
681
682                return $html;
683        }
684
685        /** Process admin interface of this object.
686        */
687        public function processAdminUI()
688        {
689                //pretty_print_r($_REQUEST);
690                $user = User :: getCurrentUser();
691                if (!$user->isSuperAdmin())
692                {
693                        throw new Exception(_('Access denied!'));
694                }
695
696                // name
697                $name = "network_".$this->getId()."_name";
698                $this->setName($_REQUEST[$name]);
699               
700                // homepage_url
701                $name = "network_".$this->getId()."_homepage_url";
702                $this->setHomepageURL($_REQUEST[$name]);
703
704
705                // tech_support_email
706                $name = "network_".$this->getId()."_tech_support_email";
707                $this->setTechSupportEmail($_REQUEST[$name]);
708
709                //  network_authenticator_class
710                $name = "network_".$this->getId()."_network_authenticator_class";
711                $this->setAuthenticatorClassName($_REQUEST[$name]);
712
713                //  network_authenticator_params
714                $name = "network_".$this->getId()."_network_authenticator_params";
715                $this->setAuthenticatorConstructorParams($_REQUEST[$name]);
716               
717                //  is_default_network
718                $name = "network_".$this->getId()."_is_default_network";
719                if($_REQUEST[$name]=='on')
720                        $this->setAsDefaultNetwork();
721       
722                //  validation_grace_time
723                $name = "network_".$this->getId()."_validation_grace_time";
724                $this->setValidationGraceTime($_REQUEST[$name]);
725                       
726                //  validation_email_from_address
727                $name = "network_".$this->getId()."_validation_email_from_address";
728                $this->setValidationEmailFromAddress($_REQUEST[$name]); 
729               
730                //  allow_multiple_login
731                $name = "network_".$this->getId()."_allow_multiple_login";
732                $this->setMultipleLoginAllowed(empty($_REQUEST[$name])?false:true);     
733               
734                //  allow_splash_only_nodes
735                $name = "network_".$this->getId()."_allow_splash_only_nodes";
736                $this->setSplashOnlyNodesAllowed(empty($_REQUEST[$name])?false:true);   
737
738                //  allow_custom_portal_redirect
739                $name = "network_".$this->getId()."_allow_custom_portal_redirect";
740                $this->setCustomPortalRedirectAllowed(empty($_REQUEST[$name])?false:true);     
741                               
742                // Node creation
743                $create_new_node = "network_{$this->getId()}_create_node";
744                $new_node_id = "network_{$this->getId()}_new_node_id";
745                if (!empty ($_REQUEST[$create_new_node]))
746                        if (!empty ($_REQUEST[$new_node_id]))
747                        {
748                                Node :: createNewNode($_REQUEST[$new_node_id], $this);
749                                $url = GENERIC_OBJECT_ADMIN_ABS_HREF."?".http_build_query(array ("object_class" => "Node", "action" => "edit", "object_id" => $_REQUEST[$new_node_id]));
750                                header("Location: {$url}");
751                        }
752                        else
753                                echo _("You MUST enter a node ID.");
754
755                // Content management
756                foreach ($this->getAllContent() as $content)
757                {
758                        $name = "content_group_".$this->id."_element_".$content->GetId()."_erase";
759                        if (!empty ($_REQUEST[$name]))
760                        {
761                                $this->removeContent($content);
762                        }
763                }
764
765                $name = "network_{$this->id}_new_content_submit";
766                if (!empty ($_REQUEST[$name]))
767                {
768                        $name = "network_{$this->id}_new_content";
769                        $content = Content :: processSelectContentUI($name);
770                        if ($content)
771                                $this->addContent($content);
772                }
773        }
774
775        /** Add network-wide content to this network */
776        public function addContent(Content $content)
777        {
778                global $db;
779                $content_id = $db->EscapeString($content->getId());
780                $sql = "INSERT INTO network_has_content (network_id, content_id) VALUES ('$this->id','$content_id')";
781                $db->ExecSqlUpdate($sql, false);
782        }
783
784        /** Remove network-wide content from this network */
785        public function removeContent(Content $content)
786        {
787                global $db;
788                $content_id = $db->EscapeString($content->getId());
789                $sql = "DELETE FROM network_has_content WHERE network_id='$this->id' AND content_id='$content_id'";
790                $db->ExecSqlUpdate($sql, false);
791        }
792
793        /** Delete this Object form the it's storage mechanism
794         * @param &$errmsg Returns an explanation of the error on failure
795         * @return true on success, false on failure or access denied */
796        public function delete(& $errmsg)
797        {
798                $errmsg = _("Network::delete() not supported");
799                return false;
800        }
801
802        /** Reloads the object from the database.  Should normally be called after a set operation */
803        protected function refresh()
804        {
805                $this->__construct($this->id);
806        }
807
808} //End class
809?>
Note: See TracBrowser for help on using the browser.