Changeset 40
- Timestamp:
- 09/07/06 14:00:00 (2 years ago)
- Files:
-
- wifidog/wifidog-auth/wifidog/classes/Mail.php (modified) (3 diffs)
- wifidog/wifidog-auth/wifidog/classes/Node.php (modified) (19 diffs)
- wifidog/wifidog-auth/wifidog/classes/Statistics.php (modified) (5 diffs)
- wifidog/wifidog-auth/wifidog/classes/User.php (modified) (44 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
wifidog/wifidog-auth/wifidog/classes/Mail.php
r39 r40 38 38 * @author Francois Proulx <francois.proulx@gmail.com> 39 39 * @copyright 2005-2006 Francois Proulx, Technologies Coeus inc. 40 * @version Subversion $Id: Mail.php 10 88 2006-09-03 03:35:06Z max-horvath$40 * @version Subversion $Id: Mail.php 1090 2006-09-06 13:01:54Z benoitg $ 41 41 * @link http://www.wifidog.org/ 42 42 */ … … 45 45 * Load required classes 46 46 */ 47 require_once(' include/class.phpmailer.php');48 require_once(' include/class.smtp.php');47 require_once('lib/PHPMailer/class.phpmailer.php'); 48 require_once('lib/SMTP/class.smtp.php'); 49 49 50 50 /** … … 136 136 * 137 137 * @return string Encoded MIME header 138 * 139 * @access private 138 140 139 * 141 140 * @see http://www.php.net/manual/en/function.mb-send-mail.php wifidog/wifidog-auth/wifidog/classes/Node.php
r39 r40 38 38 * @author Benoit Grégoire <bock@step.polymtl.ca> 39 39 * @copyright 2005-2006 Benoit Grégoire, Technologies Coeus inc. 40 * @version Subversion $Id: Node.php 10 83 2006-08-28 19:32:54Z benoitg $40 * @version Subversion $Id: Node.php 1092 2006-09-07 08:38:25Z benoitg $ 41 41 * @link http://www.wifidog.org/ 42 42 */ … … 50 50 require_once('classes/Utils.php'); 51 51 require_once('classes/DateTime.php'); 52 require_once('classes/InterfaceElements.php');53 52 54 53 /** … … 68 67 private $id; 69 68 private static $current_node_id = null; 69 70 /** 71 * List of deployment statuses 72 * 73 * @var array 74 * @access private 75 */ 76 private $_deploymentStatuses = array(); 70 77 71 78 /** … … 187 194 } 188 195 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 { 196 /** 197 * Create a new Node in the database 198 * 199 * @param string $node_id The Id to be given to the new node. If not 200 * present, guid will be assigned. 201 * @param object $network Network object. The node's network. If not 202 * present, the current Network will be assigned 203 * 204 * @return mixed The newly created Node object, or null if there was 205 * an error 206 * 207 * @static 208 * @access public 209 */ 210 public static function createNewObject($node_id = null, $network = null) 211 { 212 // Define globals 213 global $db; 214 215 if (empty ($node_id)) { 202 216 $node_id = get_guid(); 203 217 } 218 204 219 $node_id = $db->escapeString($node_id); 205 220 206 if (empty ($network)) 207 {208 $network = Network :: getCurrentNetwork();209 } 221 if (empty ($network)) { 222 $network = Network::getCurrentNetwork(); 223 } 224 210 225 $network_id = $db->escapeString($network->getId()); 211 226 212 227 $node_deployment_status = $db->escapeString("IN_PLANNING"); 213 228 $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; 229 230 if (Node::nodeExists($node_id)) { 231 throw new Exception(_('This node already exists.')); 232 } 233 234 $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')"; 235 236 if (!$db->execSqlUpdate($sql, false)) { 237 throw new Exception(_('Unable to insert new node into database!')); 238 } 239 240 $object = new self($node_id); 241 242 return $object; 225 243 } 226 244 … … 235 253 $html = ''; 236 254 $name = "{$user_prefix}"; 255 256 $_deploymentStatuses = array( 257 "DEPLOYED" => _("Deployed"), 258 "IN_PLANNING" => _("In planning"), 259 "IN_TESTING" => _("In testing"), 260 "NON_WIFIDOG_NODE" => _("Non-Wifidog node"), 261 "PERMANENTLY_CLOSED" => _("Permanently closed"), 262 "TEMPORARILY_CLOSED" => _("Temporarily closed") 263 ); 264 237 265 $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 266 $node_rows = null; 239 267 $db->execSql($sql, $node_rows, false); 240 if ($node_rows != null) 241 {268 269 if ($node_rows != null) { 242 270 Utils :: natsort2d($node_rows, "node_id"); 243 271 if ($type_interface != "table") { … … 267 295 { 268 296 $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"; 297 $_deployStatusNode = $node_row['node_deployment_status']; 298 $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 299 } 271 300 $html .= "\t\t\t</tbody>\n\t\t</table>\n"; … … 317 346 } 318 347 319 /** Process the new object interface. 320 * Will return the new object if the user has the credentials and the form was fully filled. 348 /** 349 * Process the new object interface. 350 * 351 * Will return the new object if the user has the credentials and the form was fully filled. 321 352 * @return the node object or null if no new node was created. 322 353 */ 323 static function processCreateNewObjectUI() 324 { 354 public static function processCreateNewObjectUI() 355 { 356 // Init values 325 357 $retval = null; 326 358 $name = "new_node_id"; 327 if (!empty ($_REQUEST[$name])) 328 {359 360 if (!empty ($_REQUEST[$name])) { 329 361 $node_id = $_REQUEST[$name]; 330 362 $name = "new_node_network_id"; 331 if (!empty ($_REQUEST[$name])) 332 { 333 $network = Network :: getObject($_REQUEST[$name]); 334 } 335 else 336 { 337 $network = Network :: processSelectNetworkUI('new_node'); 338 } 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 } 363 364 if (!empty ($_REQUEST[$name])) { 365 $network = Network::getObject($_REQUEST[$name]); 366 } else { 367 $network = Network::processSelectNetworkUI('new_node'); 368 } 369 370 if ($node_id && $network) { 371 try { 372 if (!$network->hasAdminAccess(User :: getCurrentUser())) { 373 throw new Exception(_("Access denied")); 374 } 375 } catch (Exception $e) { 376 $ui = new MainUI(); 377 $ui->setToolSection('ADMIN'); 378 $ui->displayError($e->getMessage(), false); 379 exit; 380 } 381 382 $retval = self::createNewObject($node_id, $network); 383 } 384 } 385 348 386 return $retval; 349 387 } … … 356 394 * 357 395 * @return string HTML markup 358 *359 * @access public360 396 */ 361 397 public function getSelectDeploymentStatus($user_prefix) … … 377 413 378 414 foreach ($status_list as $status) { 379 $tab[] = array($status['node_deployment_status'], $status['node_deployment_status']); 415 $_statusvalue = $status['node_deployment_status']; 416 $tab[] = array($_statusvalue, $this->_deploymentStatuses["$_statusvalue"]); 380 417 } 381 418 … … 385 422 } 386 423 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 424 /** 425 * Get the selected deployment status 426 * 427 * @param string $user_prefix An identifier provided by the programmer to 428 * recognise it's generated form 429 * 430 * @return string The deployment status 431 * 432 * @access public 390 433 */ 391 434 public function processSelectDeploymentStatus($user_prefix) … … 410 453 throw new Exception(sprintf(_("The node %s could not be found in the database!"), $node_id_str)); 411 454 } 455 456 $this->_deploymentStatuses = array( 457 "DEPLOYED" => _("Deployed"), 458 "IN_PLANNING" => _("In planning"), 459 "IN_TESTING" => _("In testing"), 460 "NON_WIFIDOG_NODE" => _("Non-Wifidog node"), 461 "PERMANENTLY_CLOSED" => _("Permanently closed"), 462 "TEMPORARILY_CLOSED" => _("Temporarily closed") 463 ); 464 412 465 $this->mRow = $row; 413 466 $this->id = $row['node_id']; … … 744 797 * Retrieves the admin interface of this object 745 798 * 746 * @return The HTML fragment for this interface799 * @return string The HTML fragment for this interface 747 800 * 748 801 * @access public … … 753 806 public function getAdminUI() 754 807 { 808 require_once('classes/InterfaceElements.php'); 755 809 // Init values 756 810 $html = ''; 757 758 if (!User::getCurrentUser()) { 759 throw new Exception(_('Access denied!')); 760 } 811 if (!User::getCurrentUser()) { 812 throw new Exception(_('Access denied!')); 813 } 761 814 762 815 // Get information about the network … … 815 868 $_data = Content::getLinkedContentUI("node_" . $hashed_node_id . "_content", "node_has_content", "node_id", $this->id, "portal"); 816 869 $html .= InterfaceElements::generateAdminSectionContainer("node_content", $_title, $_data); 817 870 818 871 // Name 819 872 $_title = _("Name"); … … 944 997 // custom_portal_redirect_url 945 998 if ($network->getCustomPortalRedirectAllowed()) { 946 $_title = _("URL to show instead of the portal (if this is not empty, the portal will be disabled and this URL will be shown instead)");999 $_title = _("URL to show instead of the portal"); 947 1000 $_data = InterfaceElements::generateInputText("node_" . $hashed_node_id . "_custom_portal_redirect_url", $this->getCustomPortalRedirectUrl(), "node_custom_portal_redirect_url_input"); 948 $_html_node_config[] = InterfaceElements::generateAdminSectionContainer("node_custom_portal_redirect_url", $_title, $_data); 1001 $_data .= _("If this is not empty, the portal will be disabled and this URL will be shown instead"); 1002 $_html_node_config[] = InterfaceElements::generateAdminSectionContainer("node_custom_portal_redirect_url", $_title, $_data); 949 1003 } 950 1004 … … 996 1050 } 997 1051 998 /** Process admin interface of this object. 999 */ 1052 /** 1053 * Process admin interface of this object. 1054 * 1055 * @return void 1056 * 1057 * @access public 1058 */ 1000 1059 public function processAdminUI() 1001 1060 { 1002 $user = User ::getCurrentUser();1003 1004 if (!$this->isOwner($user) && !$user->isSuperAdmin()) 1005 { 1006 throw new Exception(_('Access denied!')); 1007 } 1061 $user = User::getCurrentUser(); 1062 1063 if (!$this->isOwner($user) && !$user->isSuperAdmin()) { 1064 throw new Exception(_('Access denied!')); 1065 } 1066 1008 1067 1009 1068 // Check if user is a admin … … 1288 1347 } 1289 1348 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 (); 1349 /** 1350 * The list of users online at this node 1351 * 1352 * @return array An array of User object, or an empty array 1353 * 1354 * @access public 1355 */ 1356 public function getOnlineUsers() 1357 { 1358 // Define globals 1359 global $db; 1360 1361 // Init values 1362 $retval = array(); 1296 1363 $users = null; 1364 $anonUsers = 0; 1365 1297 1366 $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']);1303 }1304 } 1367 1368 if ($users != null) { 1369 foreach ($users as $user_row) { 1370 $retval[] = User::getObject($user_row['user_id']); 1371 } 1372 } 1373 1305 1374 return $retval; 1306 1375 } 1307 1376 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; 1377 /** 1378 * Find out how many users are online this specific Node 1379 * 1380 * @return int Number of online users 1381 * 1382 * @access public 1383 */ 1384 public function getNumOnlineUsers() 1385 { 1386 // Define globals 1387 global $db; 1388 1389 // Init values 1314 1390 $retval = array (); 1315 1391 $row = null; 1316 if(!$this->isConfiguredSplashOnly()) 1392 1393 if (!$this->isConfiguredSplashOnly()) { 1317 1394 $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 else1395 } else { 1319 1396 $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); 1397 } 1398 1320 1399 return $row['count']; 1321 1400 } … … 1465 1544 private static function nodeExists($id) 1466 1545 { 1467 // Define globals1546 // Define globals 1468 1547 global $db; 1469 1548 … … 1490 1569 1491 1570 // BEGIN :DRAZZIB: Ajout fonction specifique pour le ping 1492 public function ping($node_heartbeat_ip, $user_agent)1493 {1494 $this->mDb->execSqlUpdate("UPDATE nodes SET last_heartbeat_ip='{$node_heartbeat_ip}', last_heartbeat_timestamp=NOW(), last_heartbeat_user_agent='{$user_agent}' WHERE node_id='{$this->getId()}'");1495 }1571 public function ping($node_heartbeat_ip, $user_agent) 1572 { 1573 $this->mDb->execSqlUpdate("UPDATE nodes SET last_heartbeat_ip='{$node_heartbeat_ip}', last_heartbeat_timestamp=NOW(), last_heartbeat_user_agent='{$user_agent}' WHERE node_id='{$this->getId()}'"); 1574 } 1496 1575 // END :DRAZZIB: 1497 1576 wifidog/wifidog-auth/wifidog/classes/Statistics.php
r39 r40 39 39 * @author Benoit Grégoire <bock@step.polymtl.ca> 40 40 * @copyright 2004-2006 Benoit Grégoire, Technologies Coeus inc. 41 * @version Subversion $Id: Statistics.php 10 78 2006-07-20 16:19:19Z benoitg $41 * @version Subversion $Id: Statistics.php 1091 2006-09-06 14:58:06Z benoitg $ 42 42 * @link http://www.wifidog.org/ 43 43 */ … … 304 304 $id = $db->escapeString($id); 305 305 $first ? $sql .= "" : $sql .= " OR "; 306 // :DRAZZIB: Utilisation de la table des connections. 306 // :DRAZZIB: Utilisation de la table connections 307 307 $sql .= "connections.$column = '$id'"; 308 308 $first = false; … … 379 379 * 380 380 * @return string HTML markup 381 * 382 * @access private 381 383 */ 382 384 private function getSelectedNodesUI() 383 385 { 386 // Define globals 384 387 global $db; 388 389 // Init values 385 390 $html = ''; 391 386 392 $name = "statistics_selected_nodes[]"; 387 $user = User :: getCurrentUser(); 388 if ($user->isSuperAdmin()) 389 { 390 $sql_join = ''; 391 } 392 else 393 { 394 $user_id = $db->escapeString($user->getId()); 395 $sql_join = " JOIN node_stakeholders ON (nodes.node_id=node_stakeholders.node_id AND user_id='$user_id') "; 396 } 397 $sql = "SELECT nodes.node_id, nodes.name from nodes $sql_join WHERE 1=1 ORDER BY lower(node_id)"; 398 $node_rows = null; 399 $db->execSql($sql, $node_rows, false); 400 $html .= "<select multiple size = 6 name='$name'>\n"; 401 402 /*count($this->report_selected_nodes)==0?$selected=' SELECTED ':$selected=''; 403 $html.= "<option value='' $selected>"._("Statistics for all nodes")."</option>\n"; 404 */ 405 if ($node_rows != null) 406 { 407 foreach ($node_rows as $node_row) 408 { 409 $html .= "<option "; 410 if (array_key_exists($node_row['node_id'], $this->report_selected_nodes)) 411 { 412 $html .= " SELECTED "; 393 $user = User::getCurrentUser(); 394 395 if (!isset($user)) { 396 throw new Exception(_('Access denied!')); 397 } else if ((!$user->isSuperAdmin() && !$user->isOwner()) || $user->isNobody()) { 398 throw new Exception(_('Access denied!')); 399 } 400 401 if ($user->isSuperAdmin()) { 402 $sql_join = ''; 403 } else { 404 $user_id = $db->escapeString($user->getId()); 405 $sql_join = " JOIN node_stakeholders ON (nodes.node_id=node_stakeholders.node_id AND user_id='$user_id') "; 406 } 407 408 $sql = "SELECT nodes.node_id, nodes.name from nodes $sql_join WHERE 1=1 ORDER BY lower(node_id)"; 409 $node_rows = null; 410 $db->execSql($sql, $node_rows, false); 411 $html .= "<select multiple size = 6 name='$name'>\n"; 412 413 if ($node_rows != null) { 414 foreach ($node_rows as $node_row) { 415 $html .= "<option "; 416 417 if (array_key_exists($node_row['node_id'], $this->report_selected_nodes)) { 418 $html .= " SELECTED "; 419 } 420 421 $nom = $node_row['node_id'].": ".$node_row['name']; 422 $nom = htmlspecialchars($nom, ENT_QUOTES, 'UTF-8'); 423 $primary_key = htmlentities($node_row['node_id'], ENT_QUOTES, 'UTF-8'); 424 $html .= "value='$primary_key'>$nom</option>\n"; 413 425 } 414 415 $nom = $node_row['node_id'].": ".$node_row['name']; 416 $nom = htmlspecialchars($nom, ENT_QUOTES, 'UTF-8'); 417 $primary_key = htmlentities($node_row['node_id'], ENT_QUOTES, 'UTF-8'); 418 $html .= "value='$primary_key'>$nom</option>\n"; 419 } 420 } 421 $html .= "</select>\n"; 426 } 427 428 $html .= "</select>\n"; 429 430 422 431 return $html; 423 432 } … … 544 553 $username = $db->escapeString($_REQUEST['stats_selected_users']); 545 554 $row = null; 546 // :DRAZZIB: Suppression du debug547 555 $db->execSqlUniqueRes("SELECT user_id FROM users WHERE username='$username'", $row, false); 548 556 if ($row) … … 601 609 $html .= "<div class='admin_element_tools'><input type='checkbox' name='$key' $checked /></div>\n"; 602 610 $html .= "<div class='admin_element_label'>$name</div>\n"; 603 611 604 612 $html .= "</li>\n"; 605 613 } wifidog/wifidog-auth/wifidog/classes/User.php
r33 r40 1 1 <?php 2 2 3 3 4 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ … … 38 39 * @author Benoit Grégoire <bock@step.polymtl.ca> 39 40 * @copyright 2005-2006 Benoit Grégoire, Technologies Coeus inc. 40 * @version Subversion $Id: User.php 10 70 2006-06-08 21:24:39Z benoitg $41 * @version Subversion $Id: User.php 1093 2006-09-07 08:45:11Z benoitg $ 41 42 * @link http://www.wifidog.org/ 42 43 */ … … 45 46 * Load required classes 46 47 */ 47 require_once ('classes/Network.php');48 require_once ('classes/Mail.php');49 require_once ('classes/InterfaceElements.php');48 require_once ('classes/Network.php'); 49 require_once ('classes/Mail.php'); 50 require_once ('classes/InterfaceElements.php'); 50 51 51 52 /** … … 56 57 * @copyright 2005-2006 Benoit Grégoire, Technologies Coeus inc. 57 58 */ 58 class User implements GenericObject 59 { 59 class User implements GenericObject { 60 60 private $mRow; 61 61 private $id; … … 65 65 * @return a User object, or null if there was an error 66 66 */ 67 public static function getObject($id) 68 { 67 public static function getObject($id) { 69 68 $object = null; 70 69 $object = new self($id); … … 72 71 } 73 72 74 static function createNewObject() 75 { 73 static function createNewObject() { 76 74 echo "<h1>Use User::createUser() instead</h1>"; 77 75 } … … 79 77 * @return html markup 80 78 */ 81 public static function getCreateNewObjectUI() 82 { 79 public static function getCreateNewObjectUI() { 83 80 return null; 84 81 } … … 90 87 * @return the node object or null if no new node was created. 91 88 */ 92 static function processCreateNewObjectUI() 93 { 89 static function processCreateNewObjectUI() { 94 90 return self :: createNewObject(); 95 91 } … … 98 94 * 99 95 * @return mixed A User object, or null if there was an error 100 * 101 * @static 102 * @access public 103 */ 104 public static function getCurrentUser() 105 { 106 require_once('classes/Session.php'); 96 97 */ 98 public static function getCurrentUser() { 99 require_once ('classes/Session.php'); 107 100 $session = new Session(); 108 101 $user = null; 109 try 110 { 102 try { 111 103 $user = self :: getObject($session->get(SESS_USER_ID_VAR)); 112 104 //$user = new User($session->get(SESS_USER_ID_VAR)); 113 } 114 catch (Exception $e) 115 { 105 } catch (Exception $e) { 116 106 /**If any problem occurs, the user should be considered logged out*/ 117 107 $session->set(SESS_USER_ID_VAR, null); … … 128 118 * 129 119 * @return bool True if everything went well setting the session 130 * 131 * @static 132 * @access public 133 */ 134 public static function setCurrentUser(User $user) 135 { 136 try 137 { 120 121 */ 122 public static function setCurrentUser(User $user) { 123 try { 138 124 $session = new Session(); 139 125 $session->set(SESS_USER_ID_VAR, $user->getId()); 140 126 $session->set(SESS_PASSWORD_HASH_VAR, $user->getPasswordHash()); 141 127 return true; 142 } 143 catch (Exception $e) 144 { 128 } catch (Exception $e) { 145 129 return false; 146 130 } … … 151 135 * 152 136 * @return string Hostname of server 153 * 154 * @static 155 * @access public 156 */ 157 public static function getCurrentServer() 158 { 137 138 */ 139 public static function getCurrentServer() { 159 140 return $_SERVER['SERVER_NAME']; 160 141 } … … 165 146 * @return a User object, or null if there was an error 166 147 */ 167 public static function getUserByUsernameAndOrigin($username, Network $account_origin) 168 { 148 public static function getUserByUsernameAndOrigin($username, Network $account_origin) { 169 149 global $db; 170 150 $object = null; … … 184 164 * @return a User object, or null if there was an error 185 165 */ 186 public static function getUserByEmailAndOrigin($email, Network $account_origin) 187 { 166 public static function getUserByEmailAndOrigin($email, Network $account_origin) { 188 167 global $db; 189 168 $object = null; … … 201 180 * @return The 32 character hash. 202 181 */ 203 public static function passwordHash($password) 204 { 182 public static function passwordHash($password) { 205 183 /** 206 184 * utf8_decode is used for backward compatibility with old passwords … … 215 193 * @return the newly created User object, or null if there was an error 216 194 */ 217 static function createUser($id, $username, Network $account_origin, $email, $password) 218 { 195 static function createUser($id, $username, Network $account_origin, $email, $password) { 219 196 global $db; 220 197 … … 235 212 } 236 213 237 /* public static function purgeUnvalidatedUsers($days_since_creation)238 {239 global $db;240 $days_since_creation = $db->escapeString($days_since_creation);241 242 //$db->execSqlUpdate("INSERT INTO users (user_id,username, account_origin,email,pass,account_status,validation_token,reg_date) VALUES ('$id_str','$username_str','$account_origin_str','$email_str','$password_hash','$status','$token',NOW())");243 }*/214 /* public static function purgeUnvalidatedUsers($days_since_creation) 215 { 216 global $db; 217 $days_since_creation = $db->escapeString($days_since_creation); 218 219 //$db->execSqlUpdate("INSERT INTO users (user_id,username, account_origin,email,pass,account_status,validation_token,reg_date) VALUES ('$id_str','$username_str','$account_origin_str','$email_str','$password_hash','$status','$token',NOW())"); 220 }*/ 244 221 245 222 /** @param $object_id The id of the user */ 246 function __construct($object_id) 247 { 223 function __construct($object_id) { 248 224 global $db; 249 225 $this->mDb = & $db; … … 251 227 $sql = "SELECT * FROM users WHERE user_id='{$object_id_str}'"; 252 228 $db->execSqlUniqueRes($sql, $row, false); 253 if ($row == null) 254 { 229 if ($row == null) { 255 230 throw new Exception(sprintf(_("User id: %s could not be found in the database"), $object_id_str)); 256 231 } … … 259 234 } //End class 260 235 261 function getId() 262 { 236 function getId() { 263 237 return $this->id; 264 238 } … … 267 241 * @return Network object (never returns null) 268 242 */ 269 public function getNetwork() 270 { 243 public function getNetwork() { 271 244 return Network :: getObject($this->mRow['account_origin']); 272 245 } 273 246 274 247 /** Get a user display suitable for a user list. Will include link to the user profile. */ 275 function getListUI() 276 { 248 function getListUI() { 277 249 /* $roles = array (); 278 279 if ($current_node->isOwner($online_user)) {250 251 if ($current_node->isOwner($online_user)) { 280 252 $roles[] = _("owner"); 281 }282 283 if ($current_node->isTechnicalOfficer($online_user)) {253 } 254 255 if ($current_node->isTechnicalOfficer($online_user)) { 284 256 $roles[] = _("technical officer"); 285 }286 287 if ($roles) {257 } 258 259 if ($roles) { 288 260 $rolenames = join($roles, ","); 289 }*/261 }*/ 290 262 $html = ''; 291 $html .= $this->getUserName(); 263 if ($this->isSplashOnlyUser()) { 264 $html .= _("Guest"); 265 } 266 else { 267 $html .= $this->getUserName(); 268 } 292 269 return $html; 293 270 } 294 271 295 function getUsername() 296 { 272 function getUsername() { 297 273 return $this->mRow['username']; 298 274 } 299 300 /** Set the user's username301 * @param $value The new value302 * @return true on success, false on failure303 * @throws exception if the user tries to set a duplicate username304 */275 276 /** Set the user's username 277 * @param $value The new value 278 * @return true on success, false on failure 279 * @throws exception if the user tries to set a duplicate username 280 */ 305 281 function setUsername($value) { 306 282 $retval = true; … … 308 284 global $db; 309 285 $value = $db->escapeString($value); 310 $retval = @$db->execSqlUpdate("UPDATE users SET username = '{$value}' WHERE user_id='{$this->id}'", false); 311 if(!$retval) 312 { 313 throw new exception (sprintf(_("Sorry, the username %s is not available"), $value)); 286 $retval = @ $db->execSqlUpdate("UPDATE users SET username = '{$value}' WHERE user_id='{$this->id}'", false); 287 if (!$retval) { 288 throw new exception(sprintf(_("Sorry, the username %s is not available"), $value)); 314 289 } 315 290 $this->refresh(); … … 318 293 } 319 294 320 public function getEmail() 321 { 295 public function getEmail() { 322 296 return $this->mRow['email']; 323 297 } 324 298 325 public function setEmail($email) 326 { 327 $email_str = $this->mDb->escapeString($email); 328 if (!($update = $this->mDb->execSqlUpdate("UPDATE users SET email='{$email_str}' WHERE user_id='{$this->id}'"))) 329 { 330 throw new Exception(_("Could not update email address.")); 331 } 332 $this->mRow['email'] = $email; // unescaped 333 } 334 335 function setIsInvisible($value) 336 { 337 $retval = true; 338 if ($value != $this->isAdvertised()) 339 { 340 global $db; 341 $value ? $value = 'TRUE' : $value = 'FALSE'; 342 $retval = $db->execSqlUpdate("UPDATE users SET is_invisible = {$value} WHERE user_id = '{$this->getId()}'", false); 343 $this->refresh(); 344 } 345 return $retval; 346 } 347 348 public function isInvisible() 349 { 350 return (($this->mRow['is_invisible'] == 't') ? true : false); 299 public function setEmail($email) { 300 $email_str = $this->mDb->escapeString($email); 301 if (!($update = $this->mDb->execSqlUpdate("UPDATE users SET email='{$email_str}' WHERE user_id='{$this->id}'"))) { 302 throw new Exception(_("Could not update email address.")); 303 } 304 $this->mRow['email'] = $email; // unescaped 305 } 306 307 function setIsInvisible($value) { 308 $retval = true; 309 if ($value != $this->isAdvertised()) { 310 global $db; 311 $value ? $value = 'TRUE' : $value = 'FALSE'; 312 $retval = $db->execSqlUpdate("UPDATE users SET is_invisible = {$value} WHERE user_id = '{$this->getId()}'", false); 313 $this->refresh(); 314 } 315 return $retval; 316 } 317 318 public function isInvisible() { 319 return (($this->mRow['is_invisible'] == 't') ? true : false); 351 320 } 352 321 353 322 /**What locale (language) does the user prefer? */ 354 public function getPreferedLocale() 355 { 356 global $session; 357 $locale = $this->mRow['prefered_locale']; 358 if (empty($locale) && !empty($session)) 359 $locale = $session->get(SESS_LANGUAGE_VAR); 360 if (empty($locale)) 361 $locale = DEFAULT_LANG; 362 return $locale; 363 } 364 365 public function setPreferedLocale($locale) 366 { 367 $locale_str = $this->mDb->escapeString($locale); 368 if (!($update = $this->mDb->execSqlUpdate("UPDATE users SET prefered_locale='{$locale_str}' WHERE user_id='{$this->id}'"))) 369 { 370 throw new Exception(_("Could not update username locale.")); 371 } 372 $this->mRow['prefered_locale'] = $locale; 323 public function getPreferedLocale() { 324 global $session; 325 $locale = $this->mRow['prefered_locale']; 326
