add new type of tables (certified only) and new type of user (certified)
[brisk.git] / web / room.js
index 46f8612..59117c9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  brisk - room.js
  *
- *  Copyright (C) 2006-2009 Matteo Nastasi
+ *  Copyright (C) 2006-2014 Matteo Nastasi
  *                          mailto: nastasi@alternativeoutput.it 
  *                                  matteo.nastasi@milug.org
  *                          web: http://www.alternativeoutput.it
 
 
 /* 
+
    data = [ [ flags, name ],  ... ]
    
 */
 
-var l_list_all = 0x00;
-var l_list_auth = 0x01;
-var l_list_isol = 0x02;
 
-function state_add(flags)
+function state_add(flags, comp)
 {
-    var content = "";
-    var st, name = "";
-    var tit = "";
+    var content = "", supercont = "";
+    var st, superst, name = "", supername = "", supersfx = "";
+    var tit = "", supertit = "";
+
 
     if ((flags & 0xf00) != 0) {
         st = flags & 0xf00;
@@ -73,14 +72,66 @@ function state_add(flags)
             name = "st_rabbit.png";
             tit = (g_lang == 'en' ? "Rabbit time" : "sono a spasso col coniglio");
             break;
+        case 0x900:
+            name = "st_soccer.png";
+            tit = (g_lang == 'en' ? "Soccer time" : "c'è la partita!!");
+            break;
+        case 0xa00:
+            name = "st_baby.png";
+            tit = (g_lang == 'en' ? "Children time" : "ho il pupo da accudire");
+            break;
+        case 0xb00:
+            name = "st_mop.png";
+            tit = (g_lang == 'en' ? "Mop time" : "sto rassettando");
+            break;
+        case 0xc00:
+            name = "st_babbo.png";
+            tit = (g_lang == 'en' ? "Sto dando i regali" : "sto dando i regali");
+            break;
+        case 0xd00:
+            name = "st_renna.png";
+            tit = (g_lang == 'en' ? "in giro per regali" : "in giro per regali");
+            break;
+        case 0xe00:
+            name = "st_pupaz.png";
+            tit = (g_lang == 'en' ? "Neve a gogò" : "neve a gogò");
+            break;
+        case 0xf00:
+            name = "st_visch.png";
+            tit = (g_lang == 'en' ? "aspettando sotto al vischio" : "aspettando sotto al vischio");
+            break;
         default:
             break;
         }
+    }
+
+    if ((flags & 0xf0000) != 0) {
+        superst = flags & 0xf0000;
         if (name != "") {
-            content += '&nbsp;<img title="'+tit+'" class="unbo" src="img/'+name+'">';
+            supersfx = "_side";                
+        }
+
+        switch (superst) {
+        case 0x20000:
+            if (comp != null) {
+                supername = "suprend.php?comp="+comp+"&sfx="+supersfx;
+            }
+            else {
+                supername = "img/superuser"+supersfx+".png";
+            }
+            supertit = (g_lang == 'en' ? "Brisk Supporter" : "Brisk Supporter");
+            break;
         }
     }
 
+    if (supername != "") {
+        content += '&nbsp;<img title="'+supertit+'" class="inline" src="'+supername+'">';
+    }
+    
+    if (name != "") {
+        content += '&nbsp;<img title="'+tit+'" class="inline" src="img/'+name+'">';
+    }
+
     return content;
 }
 
@@ -91,7 +142,7 @@ var standup_data_old = null;
 
 function table_add(curtag, td)
 {
-    var tbody  = null, tr;
+    var tbody  = null, tr, ct;
 
     do {
         // console.log("wt: "+curtag.tagName);
@@ -209,27 +260,12 @@ function table_walk(curtag)
 
 function j_stand_tdcont(el)
 {
-    var content = "";
-
-    if (el[0] & 0x01)
-        content += '<b>';
-    
-    if (el[0] & 0x02)
-        content += '<i>';
-    
-    content += el[1];
-    
-    if (el[0] & 0x02)
-        content += '</i>';
-    
-    if (el[0] & 0x01)
-        content += '</b>';
-            
-    content += state_add(el[0]);
-    
-    return (content);
+    return (user_dec_and_state(el));
 }
 
+/*
+  ddata = [ [ <flags-int>, <nick-str>, <color-str> ], ... ]
+ */
 function j_stand_cont(ddata)
 {
     var i, ii;
@@ -252,9 +288,11 @@ function j_stand_cont(ddata)
     else
         data = ddata;
 
+    // WARNING:
+    //
+    //   managing update needs this branch (for few users and the else!!)
+    //
     if (standup_data_old == null || data.length < 4) {
-    // if (standup_data_old == null) {
-        
         content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
         for (i = 0 ; i < data.length ; i++) {
             if ((i % 4) == 0)
@@ -272,18 +310,6 @@ function j_stand_cont(ddata)
         
         $("standup").innerHTML = content;
 
-        // console.log("inizio");
-        // for (i = 0 , curtag = table_walk($("standup")) ; curtag != null ;  curtag = table_walk(curtag), i++ ) {
-        //     console.log("inloop["+i+"]: "+curtag.tagName+"  ID: "+curtag.id);
-        // }
-        // console.log("fine "+i);
-
-        // walktable($("standup"), nextag);
-        // console.log($("standup").firstChild);
-        // console.log($("standup").firstChild.firstChild.firstChild.firstChild);
-
-        // log_walk($("standup"));
-
         standup_data_old = data;
     }
     else {
@@ -313,7 +339,9 @@ function j_stand_cont(ddata)
             }
             else {
                 /* modified entries */
-                if (standup_data_old[i][0] != data[e][0]) {
+                if (standup_data_old[i][0] != data[e][0] ||
+                    standup_data_old[i].length != data[e].length ||
+                    (data[e].length == 3 && standup_data_old[i][2] != data[e][2])) {
                     arr_mod[idx_mod_n] = data[e];
                     idx_mod[idx_mod_n++] = i;
                 }
@@ -405,7 +433,7 @@ function esco_cb() {
     window.onbeforeunload = null; 
     window.onunload = null; 
     // nonunload = true; 
-    act_logout();
+    act_logout(0);
  };
 
 
@@ -416,20 +444,9 @@ function j_tab_cont(table_idx, data)
     var content = '';
 
     for (i = 0 ; i < data.length ; i++) {
-        if (data[i][0] & 0x01)
-            content += '<b>';
-
-        if (data[i][0] & 0x02)
-            content += '<i>';
-
-        content += data[i][1];
-        
-        if (data[i][0] & 0x02)
-            content += '</i>';
-
-        if (data[i][0] & 0x01)
-            content += '</b>';
-        content += state_add(data[i][0]);
+        // content += user_decorator(data[i]);
+        // content += state_add(data[i][0]);
+        content += j_stand_tdcont(data[i]);
 
         content += '<br>';
     }
@@ -443,14 +460,21 @@ function j_tab_act_cont(idx, act)
         $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'"  value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
     }
     else if (act == 'sitreser') {
-        // <img class="nobo" title="tavolo riservato agli utenti registrati" style="display: inline; margin-right: 80px;" src="img/okauth.png">
         // MLANG 1
-        $("table_act"+idx).innerHTML = '<input type="button" style="background-repeat: no-repeat; background-position: center; background-image: url(\'img/okauth.png\');" class="button" name="xhenter'+idx+'"  value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
+        $("table_act"+idx).innerHTML = '<input type="button" style="background-repeat: no-repeat; background-position: center; background-image: url(\'img/okauth.png\');" class="button" name="xhenter'+idx+'"  value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');" title="'+(g_lang == 'en' ? "reserved table for authenticated users only" : "tavolo riservato agli utenti registrati")+'" alt="'+(g_lang == 'en' ? "reserved table for authenticated users only" : "tavolo riservato agli utenti registrati")+'">';
+    }
+    else if (act == 'sitcert') {
+        // MLANG 1
+        $("table_act"+idx).innerHTML = '<input type="button" style="background-repeat: no-repeat; background-position: center; background-image: url(\'img/okcert.png\');" class="button" name="xhenter'+idx+'"  value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');" title="'+(g_lang == 'en' ? "reserved table for authenticated users only" : "tavolo riservato agli utenti registrati e certificati")+'" alt="'+(g_lang == 'en' ? "reserved table for authenticated and certificated users only" : "tavolo riservato agli utenti registrati e certificati")+'">';
     }
     else if (act == 'wake') {
         // MLANG 1
         $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup"  value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
     }
+    else if (act == 'resercert') {
+        // MLANG 1
+        $("table_act"+idx).innerHTML = '<img class="nobo" title="'+(g_lang == 'en' ? "reserved table for authenticated and certified users only" : "tavolo riservato agli utenti registrati e certificati")+'" style="margin-right: 20px;" src="img/onlycert.png">';
+    }
     else if (act == 'reserved') {
         // MLANG 1
         $("table_act"+idx).innerHTML = '<img class="nobo" title="'+(g_lang == 'en' ? "reserved table for authenticated users only" : "tavolo riservato agli utenti registrati")+'" style="margin-right: 20px;" src="img/onlyauth.png">';
@@ -676,77 +700,6 @@ function j_pollbox(form)
 }
 
 
-
-
-function list_set(what, is_update, info)
-{
-    // console.log(what);
-    var i;
-    var relo = false;
-    var old_st = readCookie("CO_list");
-    
-    if (what == 'auth') {
-        $('list_auth').style.color = 'red';
-        $('list_isol').style.color = 'black';
-        $('list_all').style.color = 'black';
-        if (old_st == 'isolation')
-            relo = true;
-        g_listen = l_list_auth;
-    }
-    else if (what == 'isolation') {
-        $('list_auth').style.color = 'black';
-        $('list_isol').style.color = 'red';
-        $('list_all').style.color = 'black';
-        if (old_st != 'isolation')
-            relo = true;
-        g_listen = l_list_isol;
-    }
-    else {
-        $('list_auth').style.color = 'black';
-        $('list_isol').style.color = 'black';
-        $('list_all').style.color = 'red';
-        if (old_st == 'isolation')
-            relo = true;
-        g_listen = l_list_all;
-    }
-
-    set_checked_value($('ra_listen_auth'), what);
-    set_checked_value($('ra_listen_isol'), what);
-    set_checked_value($('ra_listen_all'),  what);
-
-    $('list_info').innerHTML = info;
-    if (is_update) {
-        createCookie("CO_list", what, 24*365, cookiepath);
-    }
-
-
-    if (relo || !is_update) {
-        for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
-            
-            if (i % 4 == 0) {
-                $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
-            }
-            
-            $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
-        }
-        if (what == 'isolation') {
-            tra.hide_noauth();
-        }
-        else {
-            tra.show_noauth();
-        }
-            
-        if (false) {
-            // ricalculation of standup area
-            if (standup_data_old != null) {
-                standup_data = standup_data_old;
-                standup_data_old = null;
-                j_stand_cont(standup_data);
-            }
-        }
-    }
-}
-
 function sideslide(domobj, height, step)
 {
     this.st = 'wait';