customizable support icon finalized
[brisk.git] / web / Obj / brisk.phh
index 4c9c26e..53c46a7 100644 (file)
@@ -716,6 +716,7 @@ class Client_prefs {
     {
         $thiz = new Client_prefs();
         if ($thiz->json_load($json) == FALSE) {
+            unset($thiz);
             return (FALSE);
         }
 
@@ -733,17 +734,36 @@ class Client_prefs {
 
     function json_load($json_s)
     {
-        if (gettype($json_s) == "string") {
-            if (($json = json_decode($json_s)) == FALSE)
-                return FALSE;
-        }
-        else {
-            $json = $json_s;
-        }
-        $this->listen    = $json->listen;
-        $this->supp_comp = $json->supp_comp;
+        $ret = FALSE;
+
+        do {
+            if (gettype($json_s) == "string") {
+                if (($json = json_decode($json_s)) == FALSE)
+                    break;
+            }
+            else {
+                $json = $json_s;
+            }
+            if ($this->listen < 0 || $this->listen > 2)
+                break;
+            $this->listen = $json->listen;
+
+            if (mb_strlen($json->supp_comp, "ASCII") != 12)
+                break;
 
-        return TRUE;
+            for ($i = 0, $idx = 0 ; $i < 12 ; $i++) {
+                if (($json->supp_comp[$i] >= '0' && $json->supp_comp[$i] <= '9') ||
+                    ($json->supp_comp[$i] >= 'a' && $json->supp_comp[$i] <= 'f'))
+                    continue;
+                break;
+            }
+            if ($i < 12)
+                break;
+            $this->supp_comp = $json->supp_comp;
+            $ret = TRUE;
+        } while (FALSE);
+
+        return ($ret);
     }
 
     function store($user, $is_save)
@@ -754,7 +774,9 @@ class Client_prefs {
         $user->flags_set(($this->listen << 2), USER_FLAG_MAP_AUTH);
         fprintf(STDERR, "QQ %s::%s %x\n", __CLASS__, __FUNCTION__,
                 $user->flags);
-        $user->rec->supp_comp = $this->supp_comp;
+        if ($user->rec != FALSE && $user->rec->last_dona > 1356994800) {
+            $user->rec->supp_comp = $this->supp_comp;
+        }
         if ($is_save)
             $user->store_set();
     }
@@ -2196,18 +2218,28 @@ class Room
     
     $content = ' j_stand_cont( [ ';
 
+    $user_cur_id = $user->idx_get();
     for ($i = 0 , $ct = 0 ; $i < MAX_PLAYERS ; $i++) {
       if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
         continue;
       
       $flags = $this->user[$i]->flags;
-      
+
+      // sql record exists AND last donate > 2013-01-01
+      if ($this->user[$i]->rec != FALSE && $this->user[$i]->rec->last_dona > 1356994800) {
+          $supp_comp_s = sprintf(', "%s"', $this->user[$i]->rec->supp_comp);
+      }
+      else {
+          $supp_comp_s = '';
+      }
+
       if ($this->user[$i]->subst == "standup") {
-          if ($user->idx_get() == $i) { 
+          if ($user_cur_id == $i) {
               $flags |= 1;
           }
           
-          $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$i]->name));
+          $content .= sprintf('%s[ %d, "%s"%s ]',($ct > 0 ? ', ' : ''), $flags,
+                              xcape($this->user[$i]->name), $supp_comp_s);
           $ct++;
       }
     }
@@ -2231,18 +2263,24 @@ class Room
     if ($user->stat != 'room')
       return;
     
+    $user_cur_id = $user->idx_get();
     $content = "[ ";
     for ($i = 0 ; $i < $table->player_n ; $i++) {
         $user_cur = $this->user[$table->player[$i]];
         
         $flags = $user_cur->flags;
         
-        if ($user->idx_get() == $table->player[$i]) 
+        if ($user_cur_id == $table->player[$i])
             $flags |= 1;
         
         log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
-        
-        $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
+        if ($user_cur->rec != FALSE && $user_cur->rec->last_dona > 1356994800)
+            $supp_comp_s = sprintf(', "%s"', $user_cur->rec->supp_comp);
+        else
+            $supp_comp_s = '';
+
+        $content .= sprintf('%s[ %d, "%s"%s ]',($i == 0 ? '' : ', '), $flags,
+                            xcape($user_cur->name), $supp_comp_s);
     }
 
     $content .= ' ]';