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

Revision 713, 28.3 KB (checked in by aprilp, 8 years ago)

Typos, small changes

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