enable 'usersnet' table with indexes and reading info from it
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Fri, 6 Nov 2015 08:28:53 +0000 (09:28 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Fri, 6 Nov 2015 08:28:53 +0000 (09:28 +0100)
web/Obj/brisk.phh
web/Obj/dbase_base.phh
web/Obj/dbase_pgsql.phh
web/Obj/user.phh
web/fieldify.js
web/index.php
web/room.js

index 760e377..7d82d56 100644 (file)
@@ -1677,8 +1677,8 @@ 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 (($usersnet_item = $bdb->usersnet_bycode($user->code, $user_item->code)) == FALSE) {
+              $usersnet_item = $bdb->usersnet_default($user->code, $user_item->code);
           }
 
           if (versions_cmp($user_tos_vers, "1.2") < 0) {
@@ -1710,7 +1710,9 @@ class Brisk
                                                "" : $guar_login),
                                     "match" => (versions_cmp($user_tos_vers, "1.4") < 0 ? "non autorizzato" : $user_item->match_cnt) ,
                                     "game" => (versions_cmp($user_tos_vers, "1.4") < 0 ? "non autorizzato" : $user_item->game_cnt),
-                                    "friend" => "unknown"));
+                                    "friend" => usersnet_friend_getlabel($usersnet_item->friend),
+                                    "skill" => $usersnet_item->skill,
+                                    "trust"  => $usersnet_item->trust));
       }
 
       return $jret;
index 5e65ec8..dddd592 100644 (file)
@@ -182,41 +182,41 @@ class MailDBItem {
     }
 }
 
-define('USERNET_FRIEND', 0);
-define('USERNET_CLEVER', 1);
-define('USERNET_TRUST', 2);
-class UserNetItem {
+define('USERSNET_FRIEND', 1);
+define('USERSNET_SKILL', 1);
+define('USERSNET_TRUST', 2);
+class UsersNetItem {
     var $owner;
     var $target;
     var $friend;
-    var $clever;
+    var $skill;
     var $trust;
 
     var $from_db;
 
-    function UserNetItem($owner, $target, $friend, $clever, $trust, $from_db)
+    function UsersNetItem($owner, $target, $friend, $skill, $trust, $from_db)
     {
         $this->owner = $owner;
         $this->target = $target;
         $this->friend = $friend;
-        $this->clever = $clever;
+        $this->skill = $skill;
         $this->trust = $trust;
 
         $this->from_db = $from_db;
     }
 
-    static function UserNetItemFromRecord($rec)
+    static function UsersNetItemFromRecord($rec)
     {
-        $ret = new UserNetItem($rec->owner, $rec->target, $rec->friend,
-                               $rec->clever, $rec->trust, TRUE);
+        $ret = new UsersNetItem($rec->owner, $rec->target, $rec->friend,
+                               $rec->skill, $rec->trust, TRUE);
 
         return ($ret);
     }
 
-    static function UserNetItemDefaults($owner, $target)
+    static function UsersNetItemDefaults($owner, $target)
     {
-        $ret = new UserNetItem($owner, $target, USERNET_FRIEND,
-                               USERNET_CLEVER, USERNET_TRUST, FALSE);
+        $ret = new UsersNetItem($owner, $target, USERSNET_FRIEND,
+                               USERSNET_SKILL, USERSNET_TRUST, FALSE);
 
         return ($ret);
     }
index e3e1551..5c187aa 100644 (file)
@@ -855,12 +855,12 @@ INSERT INTO %smails (code, ucode, type, tstamp, subj, body_txt, body_htm, hash)
         return (TRUE);
     }
 
-    function usernet_bycode($owner, $target)
+    function usersnet_bycode($owner, $target)
     {
         GLOBAL $G_dbpfx;
         $ret = FALSE;
 
-        $net_sql = sprintf("SELECT * FROM %susers_net WHERE owner = %d AND target = %d;",
+        $net_sql = sprintf("SELECT * FROM %susersnet WHERE owner = %d AND target = %d;",
                             $G_dbpfx, $owner, $target);
         if (($net_pg  = $this->query($net_sql)) == FALSE) {
             return FALSE;
@@ -870,12 +870,12 @@ INSERT INTO %smails (code, ucode, type, tstamp, subj, body_txt, body_htm, hash)
 
         $net_obj = pg_fetch_object($net_pg, 0);
 
-        return (UserNetItem::UserNetItemFromRecord($net_obj));
+        return (UsersNetItem::UsersNetItemFromRecord($net_obj));
     }
 
-    function usernet_default($owner, $target)
+    function usersnet_default($owner, $target)
     {
-        return (UserNetItem::UserNetItemDefaults($owner, $target));
+        return (UsersNetItem::UsersNetItemDefaults($owner, $target));
     }
 
 } // End class BriskDB
index 361acda..99952e4 100644 (file)
@@ -923,5 +923,19 @@ function chunked_fini()
 
 } // end class User
 
+if (!isset($__usersnet_friend_map)) {
+    $__usersnet_friend_map = array("black", "unknown", "test", "friend", "bff");
+}
+
+function usersnet_friend_getlabel($id)
+{
+    GLOBAL $__usersnet_friend_map;
+
+    $id_i = intval($id);
 
+    if ($id_i < 0 || $id_i >= count($__usersnet_friend_map)) {
+        return FALSE;
+    }
+    return ($__usersnet_friend_map[$id_i]);
+}
 ?>
index 254dd0d..5be1dea 100644 (file)
@@ -3,7 +3,7 @@
 function Fieldify(ancestor, fieldsdescr)
 {
     this.ancestor = ancestor;
-    
+
     this.field = new Array();
     for (k in fieldsdescr) {
         this.field[k] = fieldsdescr[k];
@@ -13,7 +13,7 @@ function Fieldify(ancestor, fieldsdescr)
 Fieldify.prototype = {
     ancestor: null,
     field: null,
-    
+
     visible: function(is_visible) {
         this.ancestor.style.visibility = (is_visible ? "visible" : "hidden" );
     },
@@ -33,20 +33,17 @@ Fieldify.prototype = {
 
     fld_value_set: function(name, value)
     {
-        console.log(name + "=" + value);
         this.ancestor.getElementsByClassName(name + '_id')[0].innerHTML = value;
     },
-    
+
     fld_radio_set: function(name, value)
     {
         var arr = this.ancestor.getElementsByClassName(name + '_id');
 
-        console.log(name + "=" + value);
-
         for (k in arr) {
             if (arr[k].value == value)
                 arr[k].checked = true;
-            else 
+            else
                 arr[k].checked = false;
         }
     },
index d68f270..43e1b0c 100644 (file)
@@ -1410,11 +1410,11 @@ type="submit" class="button" onclick="this.form.elements['realsub'].value = 'chi
            <td class="c3t">3</td>
            <td class="c4t">4</td>
            <td class="c5t">5</td></tr>
-       <tr><td class="c1b"><input type="radio" name="credib" class="credib_id" value="1"></td>
-           <td class="c2b"><input type="radio" name="credib" class="credib_id" value="2"></td>
-           <td class="c3b"><input type="radio" name="credib" class="credib_id" value="3"></td>
-           <td class="c4b"><input type="radio" name="credib" class="credib_id" value="4"></td>
-           <td class="c5b"><input type="radio" name="credib" class="credib_id" value="5"></td>
+       <tr><td class="c1b"><input type="radio" name="trust" class="trust_id" value="1"></td>
+           <td class="c2b"><input type="radio" name="trust" class="trust_id" value="2"></td>
+           <td class="c3b"><input type="radio" name="trust" class="trust_id" value="3"></td>
+           <td class="c4b"><input type="radio" name="trust" class="trust_id" value="4"></td>
+           <td class="c5b"><input type="radio" name="trust" class="trust_id" value="5"></td>
        </tr>
     </table>
 </td></tr>
index f6d6d24..a8230db 100644 (file)
@@ -451,7 +451,10 @@ function info_show(username)
                        guar: { type: 'value' },
                        match: { type: 'value' },
                        game: { type: 'value' },
-                       friend: { type: 'radio' } };
+                       friend: { type: 'radio' },
+                       skill: { type: 'radio' },
+                       trust: { type: 'radio' }
+                     };
 
         info = new Fieldify($('info'), fields);
         info.populate(info_in);