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