From 5cf7309d9937fba5b9b97c3bf0d7c6ca2db1e4df Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Thu, 12 Nov 2015 18:35:33 +0100 Subject: [PATCH] partial refactoring for info command, new nasty devel username to check deeper login conversion consistency --- sql/sql.d/075-users-network.sql | 24 +++++++++ sql/sql.d/900-anagr.sql.devel | 4 +- sql/sql.d/910-usernet-sql.devel | 5 ++ web/Obj/brisk.phh | 6 +-- web/fieldify.js | 38 +++++++++++++- web/index.php | 6 ++- web/info.js | 93 +++++++++++++++++++++++++++++++++ web/room.js | 45 +--------------- 8 files changed, 171 insertions(+), 50 deletions(-) create mode 100644 sql/sql.d/075-users-network.sql create mode 100644 sql/sql.d/910-usernet-sql.devel create mode 100644 web/info.js diff --git a/sql/sql.d/075-users-network.sql b/sql/sql.d/075-users-network.sql new file mode 100644 index 0000000..9356b37 --- /dev/null +++ b/sql/sql.d/075-users-network.sql @@ -0,0 +1,24 @@ +-- +-- Table to manage users trust network +-- +DROP TABLE IF EXISTS #PFX#usersnet; +CREATE TABLE #PFX#usersnet ( + owner integer REFERENCES #PFX#users (code) + ON DELETE cascade ON UPDATE cascade, -- network owner + target integer REFERENCES #PFX#users (code) + ON DELETE cascade ON UPDATE cascade, -- evaluated user + friend integer, -- friendship level + skill integer, -- skill level + trust integer, -- auth + ctime timestamp DEFAULT now(), -- creation time + mtime timestamp DEFAULT to_timestamp(0) -- modification time + ); + +DROP INDEX IF EXISTS #PFX#usersnet_owner_idx; +DROP INDEX IF EXISTS #PFX#usersnet_target_idx; +DROP INDEX IF EXISTS #PFX#usersnet_owner_target_idx; +CREATE INDEX #PFX#usersnet_owner_idx ON #PFX#usersnet (owner); +CREATE INDEX #PFX#usersnet_target_idx ON #PFX#usersnet (target); +CREATE UNIQUE INDEX #PFX#usersnet_owner_target_idx ON #PFX#usersnet (owner,target); + + diff --git a/sql/sql.d/900-anagr.sql.devel b/sql/sql.d/900-anagr.sql.devel index 9de8924..131b8ec 100644 --- a/sql/sql.d/900-anagr.sql.devel +++ b/sql/sql.d/900-anagr.sql.devel @@ -25,4 +25,6 @@ DELETE FROM #PFX#users WHERE code = 10105; INSERT INTO #PFX#users (code, login, pass, email, type, guar_code) VALUES (10105, 'cin', md5('fiv'), 'cin@pluto.com', CAST (X'00010000' as integer), 10103); DELETE FROM #PFX#users WHERE code = 10106; INSERT INTO #PFX#users (code, login, pass, email, type, guar_code) VALUES (10106, 'sei', md5('six'), 'sei@pluto.com', CAST (X'00210000' as integer), 10103); -ALTER SEQUENCE #PFX#users_code_seq RESTART WITH 10107; +DELETE FROM #PFX#users WHERE code = 10107; +INSERT INTO #PFX#users (code, login, pass, email, type, guar_code) VALUES (10107, E'"/\\''|', md5('sev'), 'sev@pluto.com', CAST (X'00210000' as integer), 10103); +ALTER SEQUENCE #PFX#users_code_seq RESTART WITH 10108; diff --git a/sql/sql.d/910-usernet-sql.devel b/sql/sql.d/910-usernet-sql.devel new file mode 100644 index 0000000..cbd0954 --- /dev/null +++ b/sql/sql.d/910-usernet-sql.devel @@ -0,0 +1,5 @@ +DELETE FROM #PFX#usersnet WHERE owner = 10101 AND friend = 10102; +INSERT INTO #PFX#usersnet (owner, target, friend, skill, trust) VALUES (10101, 10102, 3, 2, 3); +DELETE FROM #PFX#usersnet WHERE owner = 10101 AND friend = 10107; +INSERT INTO #PFX#usersnet (owner, target, friend, skill, trust) VALUES (10101, 10107, 3, 3, 4); + diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index efb360e..ce5d106 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -2078,10 +2078,10 @@ class Brisk } while (0); } // nick chat command else if (strncmp($msg, "/info ", 6) == 0) { - $guar_user = substr($msg, 6); + $info_user = substr($msg, 6); - error_log("here [" . $guar_user."]"); - echo $this->info_show($user, $guar_user, $dt); + error_log("here [" . $info_user."][".escsql(urldecode($info_user)). "]"); + echo $this->info_show($user, urldecode($info_user), $dt); } else if (strncmp($msg, "/st ", 4) == 0) { log_main("chatt_send BEGIN"); diff --git a/web/fieldify.js b/web/fieldify.js index 5be1dea..19bf23f 100644 --- a/web/fieldify.js +++ b/web/fieldify.js @@ -19,7 +19,7 @@ Fieldify.prototype = { }, // { 'name': 'value' } - populate: function(field_values) + json2dom: function(field_values) { for (k in this.field) { if (this.field[k].type == 'value') { @@ -31,11 +31,32 @@ Fieldify.prototype = { } }, + dom2json: function() + { + var ret = {}; + for (k in this.field) { + if (this.field[k].perms == 'ro') + continue; + if (this.field[k].type == 'value') { + ret[k] = this.fld_value_get(k); + } + else if (this.field[k].type == 'radio') { + ret[k] = this.fld_radio_get(k); + } + } + return ret; + }, + fld_value_set: function(name, value) { this.ancestor.getElementsByClassName(name + '_id')[0].innerHTML = value; }, + fld_value_get: function(name) + { + return this.ancestor.getElementsByClassName(name + '_id')[0].innerHTML; + }, + fld_radio_set: function(name, value) { var arr = this.ancestor.getElementsByClassName(name + '_id'); @@ -47,5 +68,20 @@ Fieldify.prototype = { arr[k].checked = false; } }, + + fld_radio_get: function(name) + { + var arr = this.ancestor.getElementsByClassName(name + '_id'); + ret = null; + + for (k in arr) { + if (arr[k].checked == true) { + ret = arr[k].value; + break; + } + } + return ret; + }, + tap: null } diff --git a/web/index.php b/web/index.php index 43e1b0c..7a3538a 100644 --- a/web/index.php +++ b/web/index.php @@ -1003,6 +1003,7 @@ supported by:
+ @@ -1171,6 +1172,7 @@ cookie_law(null); + @@ -1421,8 +1423,8 @@ type="submit" class="button" onclick="this.form.elements['realsub'].value = 'chi
- + +
diff --git a/web/info.js b/web/info.js new file mode 100644 index 0000000..c7f473f --- /dev/null +++ b/web/info.js @@ -0,0 +1,93 @@ +/* + * brisk - info.js + * + * Copyright (C) 2015 Matteo Nastasi + * mailto: nastasi@alternativeoutput.it + * matteo.nastasi@milug.org + * web: http://www.alternativeoutput.it + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. You should have received a + * copy of the GNU General Public License along with this program; if + * not, write to the Free Software Foundation, Inc, 59 Temple Place - + * Suite 330, Boston, MA 02111-1307, USA. + * + */ + +function info_fld(dobj) +{ + var fields = { login: { type: 'value' }, + state: { type: 'value', perms: 'ro' }, + guar: { type: 'value', perms: 'ro' }, + match: { type: 'value', perms: 'ro' }, + game: { type: 'value', perms: 'ro' }, + friend: { type: 'radio' }, + skill: { type: 'radio' }, + trust: { type: 'radio' } + }; + + return (new Fieldify(dobj, fields)); + } + +function info_show(username) +{ + var info_in_in = server_request('mesg', 'chatt|/info ' + + encodeURIComponent(username)); + var info_in = JSON.parse(info_in_in); + var info = null; + + if (info_in.ret == 0) { + info = info_fld($('info')); + info.json2dom(info_in); + info.visible(true); + } + else { + alert("error: open info window failed"); + } +} + +var g__info_show_target = ""; +function info_show_cb(e) +{ + if (g__info_show_target == e.target.innerHTML) { + g__info_show_target = ""; + info_show(e.target.innerHTML); + } + else { + g__info_show_target = e.target.innerHTML; + } +} + +function info_save() +{ + var ret; + + info = info_fld($('info')); + ret = info.dom2json(); + + console.log(ret); + + if (0 == 1) { + if (typeof(g_prefs) == 'undefined') + return false; + + ret = server_request('mesg', 'info|save','__POST__', 'prefs', JSON.stringify(g_prefs)); + + if (ret == 1) + $('preferences').style.visibility = 'hidden'; + } +} + +function info_reset() +{ + var ret; + + ret = server_request('mesg', 'prefs|reset'); +} diff --git a/web/room.js b/web/room.js index a8230db..2dd207c 100644 --- a/web/room.js +++ b/web/room.js @@ -426,7 +426,7 @@ function j_stand_cont(ddata) var usr = $("standup").getElementsByClassName("id_usr"); for (i = 0 ; i < usr.length ; i++) { - addEvent(usr[i], "click", click_update_cb); + addEvent(usr[i], "click", info_show_cb); } } @@ -437,47 +437,6 @@ function esco_cb() { act_logout(0); }; -var g_user_info_target = ""; - -function info_show(username) -{ - // ret = server_request('mesg', 'prefs|save','__POST__', 'prefs', JSON.stringify(g_prefs)); - var info_in = JSON.parse(server_request('mesg', 'chatt|/info ' + username)); - var info = null; - - if (info_in.ret == 0) { - var fields = { login: { type: 'value' }, - state: { type: 'value' }, - guar: { type: 'value' }, - match: { type: 'value' }, - game: { type: 'value' }, - friend: { type: 'radio' }, - skill: { type: 'radio' }, - trust: { type: 'radio' } - }; - - info = new Fieldify($('info'), fields); - info.populate(info_in); - info.visible(true); - } - else { - console.log("some error: open a dialog"); - } - // FIXME: just to be finished - console.log(info); -} - -function click_update_cb(e) -{ - if (g_user_info_target == e.target.innerHTML) { - g_user_info_target = ""; - info_show(e.target.innerHTML); - } - else { - g_user_info_target = e.target.innerHTML; - } -} - function j_tab_cont(table_idx, data) { var i; @@ -491,7 +450,7 @@ function j_tab_cont(table_idx, data) $("table"+table_idx).innerHTML = content; var usr = $("table"+table_idx).getElementsByClassName("id_usr"); for (i = 0 ; i < usr.length ; i++) { - addEvent(usr[i], "click", click_update_cb); + addEvent(usr[i], "click", info_show_cb); } } -- 2.17.1