}
}
-define('USERSNET_FRIEND', 1);
-define('USERSNET_SKILL', 1);
-define('USERSNET_TRUST', 2);
+define('USERSNET_DEF_FRIEND', 2);
+define('USERSNET_DEF_SKILL', 2);
+define('USERSNET_DEF_TRUST', 2);
+
class UsersNetItem {
var $owner;
var $target;
static function UsersNetItemDefaults($owner, $target, $widefriend, $narrowfriend)
{
- $ret = new UsersNetItem($owner, $target, USERSNET_FRIEND,
- USERSNET_SKILL, USERSNET_TRUST,
+ $ret = new UsersNetItem($owner, $target, USERSNET_DEF_FRIEND,
+ USERSNET_DEF_SKILL, USERSNET_DEF_TRUST,
$widefriend, $narrowfriend, FALSE);
return ($ret);
return (FALSE);
}
- if (($sere_pg = $this->query($sere_sql)) == FALSE) {
- return (FALSE);
- }
-
$sere_sql = sprintf("SELECT * FROM %sselfreg_chk WHERE (ip & %d) = %d;",
$G_dbpfx, int2four($G_selfreg_mask), int2four($laddr & $G_selfreg_mask));
if (($sere_pg = $this->query($sere_sql)) == FALSE) {
$this->transaction('BEGIN');
$trans = TRUE;
- // try to update
- $net_sql = sprintf("
+ if ($friend == USERSNET_FRIEND_UNKNOWN) {
+ // try to update
+ $net_sql = sprintf("
+ DELETE FROM %susersnet
+ USING %susers as us
+ WHERE owner = %d AND us.login = '%s' AND target = us.code;",
+ $G_dbpfx, $G_dbpfx,
+ $owner_id, escsql($json->login));
+
+ if (($net_pg = $this->query($net_sql)) == FALSE) {
+ $ret = 5;
+ break;
+ }
+ }
+ else { // if ($friend == USERSNET_FRIEND_UNKNOWN
+ // try to update
+ $net_sql = sprintf("
UPDATE %susersnet SET (friend, skill, trust, mtime) =
(%d, %d, %d, now())
FROM %susers as us
WHERE owner = %d AND us.login = '%s' AND target = us.code RETURNING *;",
- $G_dbpfx,
- $friend, $json->skill, $json->trust,
- $G_dbpfx,
- $owner_id, escsql($json->login));
- if (($net_pg = $this->query($net_sql)) == FALSE || pg_numrows($net_pg) == 0) {
- $net_sql = sprintf("
+ $G_dbpfx,
+ $friend, $json->skill, $json->trust,
+ $G_dbpfx,
+ $owner_id, escsql($json->login));
+ if (($net_pg = $this->query($net_sql)) == FALSE || pg_numrows($net_pg) == 0) {
+ $net_sql = sprintf("
INSERT INTO %susersnet SELECT %d AS owner, us.code as target,
%d as friend, %d as skill, %d as trust
FROM %susers as us WHERE us.login = '%s' RETURNING *;",
- $G_dbpfx, $owner_id,
- $friend, $json->skill, $json->trust,
- $G_dbpfx, $json->login);
- if (($net_pg = $this->query($net_sql)) == FALSE) {
- log_wr('insert query failed');
- $ret = 2;
- break;
- }
- if (pg_numrows($net_pg) != 1) {
- log_wr(sprintf('insert numrow failed [%s] [%d]', $net_sql, pg_numrows($net_pg)));
- $ret = 3;
- break;
+ $G_dbpfx, $owner_id,
+ $friend, $json->skill, $json->trust,
+ $G_dbpfx, $json->login);
+ if (($net_pg = $this->query($net_sql)) == FALSE) {
+ log_wr('insert query failed');
+ $ret = 2;
+ break;
+ }
+ if (pg_numrows($net_pg) != 1) {
+ log_wr(sprintf('insert numrow failed [%s] [%d]', $net_sql, pg_numrows($net_pg)));
+ $ret = 3;
+ break;
+ }
}
- }
- else {
- if (pg_numrows($net_pg) != 1) {
- log_wr('update numrow failed');
- $ret = 4;
- break;
+ else {
+ if (pg_numrows($net_pg) != 1) {
+ log_wr('update numrow failed');
+ $ret = 4;
+ break;
+ }
}
}
-
- $net_obj = pg_fetch_object($net_pg, 0);
$this->transaction('COMMIT');
return (0);
} while (0);
} // end class User
+define('USERSNET_FRIEND_BLACK', 1);
+define('USERSNET_FRIEND_UNKNOWN', 2);
+define('USERSNET_FRIEND_TEST', 3);
+define('USERSNET_FRIEND_FRIEND', 4);
+define('USERSNET_FRIEND_BFF', 5);
+
if (!isset($__usersnet_friend_map)) {
$__usersnet_friend_map = array("black", "unknown", "test", "friend", "bff");
}