From: Matteo Nastasi (mop) Date: Sat, 21 Nov 2015 17:35:35 +0000 (+0100) Subject: info save added X-Git-Tag: v5.3.0~48 X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=4d6334859a2357cd090fd0e58b8f3b6356a0cfc1;p=brisk.git info save added --- diff --git a/web/Obj/dbase_pgsql.phh b/web/Obj/dbase_pgsql.phh index 7cd0c4b..8316d85 100644 --- a/web/Obj/dbase_pgsql.phh +++ b/web/Obj/dbase_pgsql.phh @@ -880,7 +880,72 @@ INSERT INTO %smails (code, ucode, type, tstamp, subj, body_txt, body_htm, hash) { return (UsersNetItem::UsersNetItemDefaults($owner, $target)); } + function usersnet_save($owner_id, $json) + { + GLOBAL $G_dbpfx; + $ret = 99999; + $trans = FALSE; + + do { + $friend = usersnet_friend_getid($json->friend); + + if ($json->skill < 1 || $json->skill > 5 || + $json->trust < 1 || $json->trust > 5 || + $friend == FALSE) { + $ret = 1; + break; + } + + $this->transaction('BEGIN'); + $trans = TRUE; + + // 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(" + 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; + } + } + 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); + + if ($trans) + $this->transaction('ROLLBACK'); + + return ($ret); + } } // End class BriskDB class LoginDBOld diff --git a/web/index_wr.php b/web/index_wr.php index b0c9ac0..20f4167 100644 --- a/web/index_wr.php +++ b/web/index_wr.php @@ -117,6 +117,8 @@ Ti sei registrato col nickname \'%s\',
Ciò è necessario per ottenere la password.

Saluti e buone partite, mop.
', 'en' => 'EN mhtml [%s] [%s]'), + 'info_err' => array( 'it' => 'E\' occorso un errore (%d), riprova più tardi.', + 'en' => 'Some error occurs (%d), retry later.') ); define('LICMGR_CHO_ACCEPT', 0); @@ -351,6 +353,22 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie) if ($argz[0] == 'ping') { log_wr("PING RECEIVED"); } + else if ($argz[0] == 'info') { + if ($argz[1] == 'save') { + if (!isset($post['info'])) { + return FALSE; + } + + if (($ret = $brisk->info_save($user, $post['info'])) == TRUE) { + if ($ret == TRUE) { + echo "1"; + return TRUE; + } + } + printf($mlang_indwr['info_err'][$G_lang], $ret); + return FALSE; + } + } else if ($argz[0] == 'prefs') { if ($argz[1] == 'save') { if (!isset($post['prefs'])) { diff --git a/web/info.js b/web/info.js index 8e30988..fb9e087 100644 --- a/web/info.js +++ b/web/info.js @@ -72,3 +72,20 @@ function info_reset() target = $('info').getElementsByClassName('login_id')[0].innerHTML; return info_show(target); } + +function info_save() +{ + var info, jinfo, ret; + + info = info_fld($('info')); + jinfo = info.dom2json(); + + ret = server_request('mesg', 'info|save','__POST__', 'info', JSON.stringify(jinfo)); + + if (ret == 1) { + $('info').style.visibility = 'hidden'; + } + else { + alert(ret); + } +}