Changeset 788 for trunk/wifidog-auth/wifidog/classes/Node.php
- Timestamp:
- 10/05/05 22:57:30 (8 years ago)
- Files:
-
- 1 modified
-
trunk/wifidog-auth/wifidog/classes/Node.php (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/wifidog/classes/Node.php
r779 r788 21 21 \********************************************************************/ 22 22 /**@file Node.php 23 * @author Copyright (C) 2005 Benoit Gr �goire <bock@step.polymtl.ca>23 * @author Copyright (C) 2005 Benoit Grégoire <bock@step.polymtl.ca> 24 24 */ 25 25 … … 86 86 $retval = null; 87 87 $sql = "SELECT node_id, last_heartbeat_ip from nodes WHERE last_heartbeat_ip='$_SERVER[REMOTE_ADDR]' ORDER BY last_heartbeat_timestamp DESC"; 88 $node_rows = null; 88 89 $db->ExecSql($sql, $node_rows, false); 89 90 $num_match = count($node_rows); … … 292 293 $html = ''; 293 294 $name = "{$user_prefix}"; 294 $status_list = self :: getAllDeploymentStatus(); 295 if ($status_list != null) 296 { 295 $status_list = null; 296 $db->ExecSql("SELECT node_deployment_status FROM node_deployment_status", $status_list, false); 297 if ($status_list == null) 298 throw new Exception(_("No deployment statues could be found in the database")); 299 297 300 $tab = array (); 298 301 foreach ($status_list as $status) 299 $tab[] = array ($status , $status);302 $tab[] = array ($status['node_deployment_status'], $status['node_deployment_status']); 300 303 $html .= FormSelectGenerator :: generateFromArray($tab, $this->getDeploymentStatus(), $name, null, false); 301 }302 304 return $html; 303 305 } … … 322 324 $node_id_str = $db->EscapeString($node_id); 323 325 $sql = "SELECT * FROM nodes WHERE node_id='$node_id_str'"; 326 $row = null; 324 327 $db->ExecSqlUniqueRes($sql, $row, false); 325 328 if ($row == null) … … 336 339 } 337 340 341 /** Changing the id of a Node is supported. 342 * Be carefull to anly call this when all other changes are processed, 343 * or the id used to generate the form names may no longer match. 344 * @param $id, string, the new node id. 345 * @return true on success, false on failure. Check this, 346 * as it's possible that someone will enter an existing id, especially 347 * if the MAC address is used and hardware is recycled. 348 */ 349 function setId($id) 350 { 351 $id = $this->mDb->EscapeString($id); 352 $retval = $this->mDb->ExecSqlUpdate("UPDATE nodes SET node_id = '{$id}' WHERE node_id = '{$this->getId()}'"); 353 if($retval) 354 { 355 $this->id = $id; 356 $this->refresh(); 357 } 358 return $retval; 359 } 360 338 361 /** Gets the Network to which the node belongs 339 362 * @return Network object (never returns null) … … 657 680 $html .= "<div class='admin_section_title'>"._("Information about the node:")."</div>\n"; 658 681 682 683 // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores ) 684 $hashed_node_id = md5($this->getId()); 685 659 686 // Node ID 660 687 $value = htmlspecialchars($this->getId(), ENT_QUOTES); 661 688 $html .= "<div class='admin_section_container'>\n"; 662 $html .= "<div class='admin_section_title'>"._("ID")." : {$value}</div>\n"; 663 //$html .= "<div class='admin_section_data'>\n"; 664 //$name = "node_".$this->getId()."_id"; 665 //$html .= "<input type='text' readonly='' size='10' value='$value' name='$name'>\n"; 666 //$html .= "</div>\n"; 667 $html .= "</div>\n"; 668 669 // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores ) 670 $hashed_node_id = md5($this->getId()); 689 $html .= "<div class='admin_section_title'>"._("ID")." : </div>\n"; 690 $html .= "<div class='admin_section_data'>\n"; 691 $name = "node_".$hashed_node_id."_id"; 692 $html .= "<input type='text' size='20' value='$value' name='$name'>\n"; 693 $html .= "</div>\n"; 694 $html .= "</div>\n"; 671 695 672 696 // Name … … 1160 1184 Content::processLinkedContentUI($name, 'node_has_content', 'node_id', $this->id); 1161 1185 1162 } 1186 // Name 1187 $name = "node_".$hashed_node_id."_id"; 1188 $this->setId($_REQUEST[$name]); 1189 } 1163 1190 1164 1191 // Redirect to this node's portal page … … 1196 1223 global $db; 1197 1224 $retval = array (); 1225 $content_rows = null; 1198 1226 // Get all network, but exclude user subscribed content if asked 1199 1227 if ($exclude_subscribed_content == true && $subscriber) … … 1220 1248 $retval = array (); 1221 1249 $sql = "SELECT * FROM content_group JOIN content ON (content.content_id = content_group.content_group_id) JOIN node_has_content ON (node_has_content.content_id = content_group.content_group_id AND node_has_content.node_id = '{$this->getId()}') WHERE is_persistent = true AND is_artistic_content = true AND is_locative_content = true ORDER BY subscribe_timestamp DESC"; 1250 $content_rows = null; 1222 1251 $db->ExecSql($sql, $content_rows, false); 1223 1252 if ($content_rows != null) … … 1242 1271 } 1243 1272 1244 /** Return all the nodes1245 */1246 static function getAllNodes()1247 {1248 global $db;1249 1250 $db->ExecSql("SELECT * FROM nodes", $nodes, false);1251 1252 if ($nodes == null)1253 throw new Exception(_("No nodes could not be found in the database"));1254 1255 return $nodes;1256 }1257 1258 static function getAllNodesOrdered($order_by)1259 {1260 global $db;1261 1262 $nodes = null;1263 $db->ExecSql("SELECT * FROM nodes ORDER BY $order_by", $nodes, false);1264 1265 if ($nodes == null)1266 throw new Exception(_("No nodes could not be found in the database"));1267 1268 return $nodes;1269 }1270 1271 static function getAllDeploymentStatus()1272 {1273 global $db;1274 1275 $statuses = null;1276 $db->ExecSql("SELECT * FROM node_deployment_status", $statuses, false);1277 if ($statuses == null)1278 throw new Exception(_("No deployment statues could be found in the database"));1279 1280 $statuses_array = array ();1281 foreach ($statuses as $status)1282 array_push($statuses_array, $status['node_deployment_status']);1283 1284 return $statuses_array;1285 }1286 1287 1273 /** The list of users online at this node 1288 1274 * @return An array of User object, or en empty array */ … … 1291 1277 global $db; 1292 1278 $retval = array (); 1279 $users = null; 1293 1280 $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); 1294 1281 if ($users != null) … … 1305 1292 * @return Number of online users 1306 1293 */ 1307 function getNumOnlineUsers( $node_id = null)1294 function getNumOnlineUsers() 1308 1295 { 1309 1296 global $db; 1310 1297 $retval = array (); 1298 $row = null; 1311 1299 $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); 1312 1300 return $row['count']; 1313 1301 } 1314 1302 1303 /** The list of all real owners of this node 1304 * @return An array of User object, or en empty array */ 1315 1305 function getOwners() 1316 1306 { 1317 1307 global $db; 1318 1308 $retval = array (); 1309 $owners = null; 1319 1310 $db->ExecSql("SELECT user_id FROM node_stakeholders WHERE is_owner = true AND node_id='{$this->id}'", $owners, false); 1320 1311 if ($owners != null) … … 1328 1319 } 1329 1320 1321 /** The list of all Technical officers of this node. 1322 * Technical officers are displayed highlited and in the online user's list, 1323 * and are contacted when the Node goes down. 1324 * @return An array of User object, or en empty array */ 1330 1325 function getTechnicalOfficers() 1331 1326 { 1332 1327 global $db; 1333 1328 $retval = array (); 1329 $officers = null; 1334 1330 $db->ExecSql("SELECT user_id FROM node_stakeholders WHERE is_tech_officer = true AND node_id='{$this->id}'", $officers, false); 1335 1331 if ($officers != null) … … 1349 1345 { 1350 1346 global $db; 1347 $rows = null; 1351 1348 $db->ExecSql("SELECT * FROM node_stakeholders WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}'", $rows, false); 1352 1349 if (!$rows) … … 1366 1363 { 1367 1364 global $db; 1365 $rows = null; 1368 1366 $db->ExecSql("SELECT * FROM node_stakeholders WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}'", $rows, false); 1369 1367 if (!$rows) … … 1374 1372 else 1375 1373 if (!$db->ExecSqlUpdate("UPDATE node_stakeholders SET is_tech_officer = true WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}';", false)) 1376 throw new Exception(_('Could not addtech officer'));1377 } 1378 1379 /** Remove a technical officer ( tech support ) fromthis node1374 throw new Exception(_('Could not set existing user as tech officer')); 1375 } 1376 1377 /** Remove owner flag for a stakeholder of this node 1380 1378 * @param User 1381 1379 */ … … 1387 1385 } 1388 1386 1389 /** Remove a technical officer ( tech support ) fromthis node1387 /** Remove technical officer flag for a stakeholder of this node 1390 1388 * @param User 1391 1389 */ … … 1406 1404 $user_id = $user->getId(); 1407 1405 $retval = false; 1406 $row = null; 1408 1407 $db->ExecSqlUniqueRes("SELECT * FROM node_stakeholders WHERE is_owner = true AND node_id='{$this->id}' AND user_id='{$user_id}'", $row, false); 1409 1408 if ($row != null) … … 1424 1423 $user_id = $user->getId(); 1425 1424 $retval = false; 1425 $row = null; 1426 1426 $db->ExecSqlUniqueRes("SELECT * FROM node_stakeholders WHERE is_tech_officer = true AND node_id='{$this->id}' AND user_id='{$user_id}'", $row, false); 1427 1427 if ($row != null) … … 1440 1440 $id_str = $db->EscapeString($id); 1441 1441 $sql = "SELECT * FROM nodes WHERE node_id='{$id_str}'"; 1442 $row = null; 1442 1443 $db->ExecSqlUniqueRes($sql, $row, false); 1443 1444 if ($row != null) … … 1448 1449 } 1449 1450 1450 /** Warning, the semantics of this function will change *1451 * @deprecated version - 2005-04-29 USE getOnlineUsers instead1452 * */1453 public static function getAllOnlineUsers()1454 {1455 global $db;1456 $db->ExecSql("SELECT * FROM connections,users,nodes WHERE token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND nodes.node_id=connections.node_id ORDER BY timestamp_in DESC", $online_users);1457 return $online_users;1458 }1459 1460 1451 /** Reloads the object from the database. Should normally be called after a set operation */ 1461 1452 protected function refresh()
