From a77cf3db1fbace39c49b030b9e144a316f007373 Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Thu, 5 Nov 2015 07:28:56 +0100 Subject: [PATCH] load data from usernet table or create a default instance --- TODO.txt | 33 +++++++++++-- ...00-anagr.sql.devel => 900-anagr.sql.devel} | 0 web/Obj/brisk.phh | 10 ++-- web/Obj/dbase_base.phh | 49 +++++++++++++++++-- web/Obj/dbase_pgsql.phh | 22 +++++++++ 5 files changed, 103 insertions(+), 11 deletions(-) rename sql/sql.d/{100-anagr.sql.devel => 900-anagr.sql.devel} (100%) diff --git a/TODO.txt b/TODO.txt index 8de1e80..321039a 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,7 +3,35 @@ FEATURES | ----------+ + * Users Network construction + DONE - sql + - dbase API + - enhance info interface + . disable parts of interface + - minisplash at end of the match + + * Double click on chat to open preferences + + * APPRENTICE + Phase2 + DONE - match counters (part 2) + DONE . migration script for old users + - guarantee for apprentice + + BUGS | + ------+ - Global vars checker + - Remove books from chat + - Not triple chars between letters + - 10002 message when already clicked + + +--------- + - APPRENTICE + Phase2 + DONE - match counters (part 2) + DONE . migration script for old users + - APPRENTICE Phase1 DONE - correggere minuta giornaliera @@ -30,11 +58,6 @@ DONE - fix layout of tables DONE - aggiungere books.png - Phase2 - - match counters (part 2) - . migration script for old users - - guarantee for apprentice - - MENTORS - listen all diff --git a/sql/sql.d/100-anagr.sql.devel b/sql/sql.d/900-anagr.sql.devel similarity index 100% rename from sql/sql.d/100-anagr.sql.devel rename to sql/sql.d/900-anagr.sql.devel diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index 1eb6f94..760e377 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -1660,13 +1660,13 @@ class Brisk $ret = 2; break; } - if (($user_item = $bdb->getitem_bylogin($user_login, $user_code)) == FALSE) { + if ($user_login == $user->name) { $ret = 3; + $mesg = sprintf($mlang_brisk['inf_self'][$G_lang]); break; } - if ($user_login == $user->name) { + if (($user_item = $bdb->getitem_bylogin($user_login, $user_code)) == FALSE) { $ret = 4; - $mesg = sprintf($mlang_brisk['inf_self'][$G_lang]); break; } if (($guar_item = $bdb->getitem_bycode($user_item->guar_code_get())) != FALSE) { @@ -1677,6 +1677,10 @@ class Brisk } $user_tos_vers = $user_item->tos_vers_get(); + if (($usernet_item = $bdb->usernet_bycode($user->code, $user_item->code)) == FALSE) { + $usernet_item = $bdb->usernet_default($user->code, $user_item->code); + } + if (versions_cmp($user_tos_vers, "1.2") < 0) { $mesg = sprintf($mlang_brisk['tos_old'][$G_lang], xcape($user_login)); } diff --git a/web/Obj/dbase_base.phh b/web/Obj/dbase_base.phh index 1e7a19a..5e65ec8 100644 --- a/web/Obj/dbase_base.phh +++ b/web/Obj/dbase_base.phh @@ -3,7 +3,7 @@ * brisk - dbase_base.phh * * Copyright (C) 2011-2012 Matteo Nastasi - * mailto: nastasi@alternativeoutput.it + * mailto: nastasi@alternativeoutput.it * matteo.nastasi@milug.org * web: http://www.alternativeoutput.it * @@ -56,7 +56,7 @@ class LoginDBItem { static function LoginDBItemFromRecord($rec) { - $ret = new LoginDBItem($rec->code, $rec->login, $rec->pass, + $ret = new LoginDBItem($rec->code, $rec->login, $rec->pass, $rec->email, $rec->type, $rec->last_dona, $rec->supp_comp, $rec->tos_vers, $rec->disa_reas, $rec->guar_code, $rec->match_cnt, $rec->game_cnt); @@ -73,7 +73,7 @@ class LoginDBItem { { return $this->login; } - + function pass_get() { return $this->pass; @@ -181,4 +181,47 @@ class MailDBItem { return $bdb->mail_add_fromitem($this); } } + +define('USERNET_FRIEND', 0); +define('USERNET_CLEVER', 1); +define('USERNET_TRUST', 2); +class UserNetItem { + var $owner; + var $target; + var $friend; + var $clever; + var $trust; + + var $from_db; + + function UserNetItem($owner, $target, $friend, $clever, $trust, $from_db) + { + $this->owner = $owner; + $this->target = $target; + $this->friend = $friend; + $this->clever = $clever; + $this->trust = $trust; + + $this->from_db = $from_db; + } + + static function UserNetItemFromRecord($rec) + { + $ret = new UserNetItem($rec->owner, $rec->target, $rec->friend, + $rec->clever, $rec->trust, TRUE); + + return ($ret); + } + + static function UserNetItemDefaults($owner, $target) + { + $ret = new UserNetItem($owner, $target, USERNET_FRIEND, + USERNET_CLEVER, USERNET_TRUST, FALSE); + + return ($ret); + } + + +} + ?> \ No newline at end of file diff --git a/web/Obj/dbase_pgsql.phh b/web/Obj/dbase_pgsql.phh index 77c215f..e3e1551 100644 --- a/web/Obj/dbase_pgsql.phh +++ b/web/Obj/dbase_pgsql.phh @@ -855,6 +855,28 @@ INSERT INTO %smails (code, ucode, type, tstamp, subj, body_txt, body_htm, hash) return (TRUE); } + function usernet_bycode($owner, $target) + { + GLOBAL $G_dbpfx; + $ret = FALSE; + + $net_sql = sprintf("SELECT * FROM %susers_net WHERE owner = %d AND target = %d;", + $G_dbpfx, $owner, $target); + if (($net_pg = $this->query($net_sql)) == FALSE) { + return FALSE; + } + if (pg_numrows($net_pg) != 1) + return FALSE; + + $net_obj = pg_fetch_object($net_pg, 0); + + return (UserNetItem::UserNetItemFromRecord($net_obj)); + } + + function usernet_default($owner, $target) + { + return (UserNetItem::UserNetItemDefaults($owner, $target)); + } } // End class BriskDB -- 2.17.1