Changeset 1089 for trunk/wifidog-auth/wifidog/classes/Node.php
- Timestamp:
- 09/03/06 18:54:01 (6 years ago)
- Files:
-
- 1 modified
-
trunk/wifidog-auth/wifidog/classes/Node.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/wifidog/classes/Node.php
r1088 r1089 51 51 require_once('classes/DateTime.php'); 52 52 require_once('classes/InterfaceElements.php'); 53 require_once('classes/MainUI.php'); 53 54 54 55 /** … … 68 69 private $id; 69 70 private static $current_node_id = null; 71 72 /** 73 * List of deployment statuses 74 * 75 * @var array 76 * @access private 77 */ 78 private $_deploymentStatuses = array(); 70 79 71 80 /** … … 187 196 } 188 197 189 /** Create a new Node in the database 190 * @param $node_id The id to be given to the new node. If not present, a 191 * guid will be assigned. 192 * @param $network Network object. The node's network. If not present, 193 * the current Network will be assigned 194 * 195 * @return the newly created Node object, or null if there was an error 196 */ 197 static function createNewObject($node_id = null, $network = null) 198 { 199 global $db; 200 if (empty ($node_id)) 201 { 198 /** 199 * Create a new Node in the database 200 * 201 * @param string $node_id The Id to be given to the new node. If not 202 * present, guid will be assigned. 203 * @param object $network Network object. The node's network. If not 204 * present, the current Network will be assigned 205 * 206 * @return mixed The newly created Node object, or null if there was 207 * an error 208 * 209 * @static 210 * @access public 211 */ 212 public static function createNewObject($node_id = null, $network = null) 213 { 214 // Define globals 215 global $db; 216 217 if (empty ($node_id)) { 202 218 $node_id = get_guid(); 203 219 } 220 204 221 $node_id = $db->escapeString($node_id); 205 222 206 if (empty ($network)) 207 {208 $network = Network :: getCurrentNetwork();209 } 223 if (empty ($network)) { 224 $network = Network::getCurrentNetwork(); 225 } 226 210 227 $network_id = $db->escapeString($network->getId()); 211 228 212 229 $node_deployment_status = $db->escapeString("IN_PLANNING"); 213 230 $node_name = _("New node"); 214 if (Node :: nodeExists($node_id)) 215 throw new Exception(_('This node already exists.')); 216 217 $sql = "INSERT INTO nodes (node_id, network_id, creation_date, node_deployment_status, name) VALUES ('$node_id', '$network_id', NOW(),'$node_deployment_status', '$node_name')"; 218 219 if (!$db->execSqlUpdate($sql, false)) 220 { 221 throw new Exception(_('Unable to insert new node into database!')); 222 } 223 $object = new self($node_id); 224 return $object; 231 232 try { 233 if (Node::nodeExists($node_id)) { 234 throw new Exception(_('This node already exists.')); 235 } 236 237 $sql = "INSERT INTO nodes (node_id, network_id, creation_date, node_deployment_status, name) VALUES ('$node_id', '$network_id', NOW(),'$node_deployment_status', '$node_name')"; 238 239 if (!$db->execSqlUpdate($sql, false)) { 240 throw new Exception(_('Unable to insert new node into database!')); 241 } 242 243 $object = new self($node_id); 244 245 return $object; 246 } catch (Exception $e) { 247 $ui = new MainUI(); 248 $ui->setToolSection('ADMIN'); 249 $ui->displayError($e->getMessage(), false); 250 exit; 251 } 225 252 } 226 253 … … 235 262 $html = ''; 236 263 $name = "{$user_prefix}"; 264 265 $_deploymentStatuses = array( 266 "DEPLOYED" => _("Deployed"), 267 "IN_PLANNING" => _("In planning"), 268 "IN_TESTING" => _("In testing"), 269 "NON_WIFIDOG_NODE" => _("Non-Wifidog node"), 270 "PERMANENTLY_CLOSED" => _("Permanently closed"), 271 "TEMPORARILY_CLOSED" => _("Temporarily closed") 272 ); 273 237 274 $sql = "SELECT node_id, name, node_deployment_status, is_splash_only_node from nodes WHERE 1=1 $sql_additional_where ORDER BY lower(node_id)"; 238 275 $node_rows = null; 239 276 $db->execSql($sql, $node_rows, false); 240 if ($node_rows != null) 241 {277 278 if ($node_rows != null) { 242 279 Utils :: natsort2d($node_rows, "node_id"); 243 280 if ($type_interface != "table") { … … 267 304 { 268 305 $href = GENERIC_OBJECT_ADMIN_ABS_HREF."?object_id={$node_row['node_id']}&object_class=Node&action=edit"; 269 $html .= "\t\t\t\t<tr class='row' onclick=\"javascript:location.href='{$href}'\">\n\t\t\t\t\t<td>{$node_row['name']}<noscript>(<a href='{$href}'>edit</a>)</noscript></td>\n\t\t\t\t\t<td>{$node_row['node_id']}</td>\n\t\t\t\t\t<td>{$node_row['node_deployment_status']}</td>\n\t\t\t\t</tr>\n"; 306 $_deployStatusNode = $node_row['node_deployment_status']; 307 $html .= "\t\t\t\t<tr class='row' onclick=\"javascript:location.href='{$href}'\">\n\t\t\t\t\t<td>{$node_row['name']}<noscript>(<a href='{$href}'>edit</a>)</noscript></td>\n\t\t\t\t\t<td>{$node_row['node_id']}</td>\n\t\t\t\t\t<td>{$_deploymentStatuses[$_deployStatusNode]}</td>\n\t\t\t\t</tr>\n"; 270 308 } 271 309 $html .= "\t\t\t</tbody>\n\t\t</table>\n"; … … 317 355 } 318 356 319 /** Process the new object interface. 320 * Will return the new object if the user has the credentials and the form was fully filled. 357 /** 358 * Process the new object interface. 359 * 360 * Will return the new object if the user has the credentials and the form was fully filled. 321 361 * @return the node object or null if no new node was created. 322 362 */ 323 static function processCreateNewObjectUI() 324 { 363 public static function processCreateNewObjectUI() 364 { 365 // Init values 325 366 $retval = null; 326 367 $name = "new_node_id"; 327 if (!empty ($_REQUEST[$name])) 328 {368 369 if (!empty ($_REQUEST[$name])) { 329 370 $node_id = $_REQUEST[$name]; 330 371 $name = "new_node_network_id"; 331 if (!empty ($_REQUEST[$name])) 332 { 333 $network = Network :: getObject($_REQUEST[$name]); 372 373 if (!empty ($_REQUEST[$name])) { 374 $network = Network::getObject($_REQUEST[$name]); 375 } else { 376 $network = Network::processSelectNetworkUI('new_node'); 334 377 } 335 else 336 { 337 $network = Network :: processSelectNetworkUI('new_node'); 378 379 if ($node_id && $network) { 380 try { 381 if (!$network->hasAdminAccess(User :: getCurrentUser())) { 382 throw new Exception(_("Access denied")); 383 } 384 } catch (Exception $e) { 385 $ui = new MainUI(); 386 $ui->setToolSection('ADMIN'); 387 $ui->displayError($e->getMessage(), false); 388 exit; 389 } 390 391 $retval = self::createNewObject($node_id, $network); 338 392 } 339 if ($node_id && $network) 340 { 341 if (!$network->hasAdminAccess(User :: getCurrentUser())) 342 { 343 throw new Exception(_("Access denied")); 344 } 345 $retval = self :: createNewObject($node_id, $network); 346 } 347 } 393 } 394 348 395 return $retval; 349 396 } … … 377 424 378 425 foreach ($status_list as $status) { 379 $tab[] = array($status['node_deployment_status'], $status['node_deployment_status']); 426 $_statusvalue = $status['node_deployment_status']; 427 $tab[] = array($_statusvalue, $this->_deploymentStatuses["$_statusvalue"]); 380 428 } 381 429 … … 385 433 } 386 434 387 /** Get the selected deployment status 388 * @param $user_prefix A identifier provided by the programmer to recognise it's generated form 389 * @return the deployment status 435 /** 436 * Get the selected deployment status 437 * 438 * @param string $user_prefix An identifier provided by the programmer to 439 * recognise it's generated form 440 * 441 * @return string The deployment status 442 * 443 * @access public 390 444 */ 391 445 public function processSelectDeploymentStatus($user_prefix) … … 410 464 throw new Exception(sprintf(_("The node %s could not be found in the database!"), $node_id_str)); 411 465 } 466 467 $this->_deploymentStatuses = array( 468 "DEPLOYED" => _("Deployed"), 469 "IN_PLANNING" => _("In planning"), 470 "IN_TESTING" => _("In testing"), 471 "NON_WIFIDOG_NODE" => _("Non-Wifidog node"), 472 "PERMANENTLY_CLOSED" => _("Permanently closed"), 473 "TEMPORARILY_CLOSED" => _("Temporarily closed") 474 ); 475 412 476 $this->mRow = $row; 413 477 $this->id = $row['node_id']; … … 744 808 * Retrieves the admin interface of this object 745 809 * 746 * @return The HTML fragment for this interface810 * @return string The HTML fragment for this interface 747 811 * 748 812 * @access public … … 756 820 $html = ''; 757 821 758 if (!User::getCurrentUser()) { 759 throw new Exception(_('Access denied!')); 760 } 822 try { 823 if (!User::getCurrentUser()) { 824 throw new Exception(_('Access denied!')); 825 } 826 } catch (Exception $e) { 827 $ui = new MainUI(); 828 $ui->setToolSection('ADMIN'); 829 $ui->displayError($e->getMessage(), false); 830 exit; 831 } 761 832 762 833 // Get information about the network … … 996 1067 } 997 1068 998 /** Process admin interface of this object. 999 */ 1069 /** 1070 * Process admin interface of this object. 1071 * 1072 * @return void 1073 * 1074 * @access public 1075 */ 1000 1076 public function processAdminUI() 1001 1077 { 1002 $user = User :: getCurrentUser(); 1003 1004 if (!$this->isOwner($user) && !$user->isSuperAdmin()) 1005 { 1006 throw new Exception(_('Access denied!')); 1007 } 1078 $user = User::getCurrentUser(); 1079 1080 try { 1081 if (!$this->isOwner($user) && !$user->isSuperAdmin()) { 1082 throw new Exception(_('Access denied!')); 1083 } 1084 } catch (Exception $e) { 1085 $ui = new MainUI(); 1086 $ui->setToolSection('ADMIN'); 1087 $ui->displayError($e->getMessage(), false); 1088 exit; 1089 } 1008 1090 1009 1091 // Check if user is a admin … … 1288 1370 } 1289 1371 1290 /** The list of users online at this node 1291 * @return An array of User object, or en empty array */ 1292 function getOnlineUsers() 1293 { 1294 global $db; 1295 $retval = array (); 1372 /** 1373 * The list of users online at this node 1374 * 1375 * @return array An array of User object, or an empty array 1376 * 1377 * @access public 1378 */ 1379 public function getOnlineUsers() 1380 { 1381 // Define globals 1382 global $db; 1383 1384 // Init values 1385 $retval = array(); 1296 1386 $users = null; 1387 $anonUsers = 0; 1388 1297 1389 $db->execSql("SELECT users.user_id FROM users,connections WHERE connections.token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND connections.node_id='{$this->id}'", $users, false); 1298 if ($users != null) 1299 { 1300 foreach ($users as $user_row) 1301 { 1302 $retval[] = User :: getObject($user_row['user_id']); 1390 1391 if ($users != null) { 1392 foreach ($users as $user_row) { 1393 if ($this->isConfiguredSplashOnly()) { 1394 if (User::getObject($user_row['user_id']) == "SPLASH_ONLY_USER") { 1395 $anonUsers++; 1396 } else { 1397 $retval[] = User::getObject($user_row['user_id']); 1398 } 1399 } else { 1400 $retval[] = User::getObject($user_row['user_id']); 1401 } 1303 1402 } 1304 } 1403 1404 if ($this->isConfiguredSplashOnly() && $anonUsers == 1) { 1405 $retval[] = "One anonymous user"; 1406 } else if ($this->isConfiguredSplashOnly() && $anonUsers > 1) { 1407 $retval[] = sprintf("%d anonymous users", $anonUsers); 1408 } 1409 } 1410 1305 1411 return $retval; 1306 1412 } 1307 1413 1308 /** Find out how many users are online this specific Node 1309 * @return Number of online users 1310 */ 1311 function getNumOnlineUsers() 1312 { 1313 global $db; 1414 /** 1415 * Find out how many users are online this specific Node 1416 * 1417 * @return int Number of online users 1418 * 1419 * @access public 1420 */ 1421 public function getNumOnlineUsers() 1422 { 1423 // Define globals 1424 global $db; 1425 1426 // Init values 1314 1427 $retval = array (); 1315 1428 $row = null; 1316 if(!$this->isConfiguredSplashOnly()) 1429 1430 if (!$this->isConfiguredSplashOnly()) { 1317 1431 $db->execSqlUniqueRes("SELECT COUNT(DISTINCT users.user_id) as count FROM users,connections WHERE connections.token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND connections.node_id='{$this->id}'", $row, false); 1318 else1432 } else { 1319 1433 $db->execSqlUniqueRes("SELECT COUNT(DISTINCT connections.user_mac) as count FROM connections WHERE connections.token_status='".TOKEN_INUSE."' AND connections.node_id='{$this->id}'", $row, false); 1434 } 1435 1320 1436 return $row['count']; 1321 1437 }
