add tables for apprentices
[brisk.git] / web / Obj / brisk.phh
index a8220f8..d543267 100644 (file)
@@ -28,6 +28,7 @@ define('FTOK_PATH', "/var/lib/brisk");
 define('LEGAL_PATH', "/tmp/legal_brisk");
 define('PROXY_PATH', "/var/lib/brisk_proxy");
 define('TABLES_N', 36);
+define('TABLES_APPR_N', 12);
 define('TABLES_AUTH_N', 8);
 define('TABLES_CERT_N', 4);
 define('PLAYERS_N', 3);
@@ -634,8 +635,9 @@ class Vect {
 }
 
 define('TABLE_AUTH_TY_PUBL', 0);
-define('TABLE_AUTH_TY_AUTH', 1);
-define('TABLE_AUTH_TY_CERT', 2);
+define('TABLE_AUTH_TY_APPR', 1);
+define('TABLE_AUTH_TY_AUTH', 2);
+define('TABLE_AUTH_TY_CERT', 3);
 
 
 class Table {
@@ -671,6 +673,8 @@ class Table {
         $thiz->auth_type =   TABLE_AUTH_TY_CERT;
     else if ($idx < TABLES_AUTH_N)
         $thiz->auth_type =   TABLE_AUTH_TY_AUTH;
+    else if ($idx < TABLES_APPR_N)
+        $thiz->auth_type =   TABLE_AUTH_TY_APPR;
     else
         $thiz->auth_type =   TABLE_AUTH_TY_PUBL;
 
@@ -825,6 +829,12 @@ class Table {
               else
                   $act = 'reserved';
               break;
+          case TABLE_AUTH_TY_APPR:
+              if ($user->is_auth())
+                  $act = "sitappr";
+              else
+                  $act = 'reserved';
+              break;
           default:
               $act = 'sit';
               break;
@@ -1644,12 +1654,12 @@ class Brisk
   }
 
   /*
-    function info_show($user, $user_login, $dt)
+    function info_show($user, $target, $dt)
 
     if success return assoc. array with "ret" => 0 and other fields
     else return an assoc. array with "ret: != 0 and "mesg" with an error description
   */
-  function info_show($user, $user_login, $dt)
+  function info_show($user, $target, $dt)
   {
       GLOBAL $G_lang, $mlang_brisk, $G_base;
 
@@ -1658,7 +1668,7 @@ class Brisk
       $ret = 0;
 
       do {
-          if ($user_login == "") {
+          if ($target == "") {
               $ret = 1;
               break;
           }
@@ -1666,12 +1676,12 @@ class Brisk
               $ret = 2;
               break;
           }
-          if ($user_login == $user->name) {
+          if ($target == $user->name) {
               $ret = 3;
               $mesg = sprintf($mlang_brisk['inf_self'][$G_lang]);
               break;
           }
-          if (($user_item = $bdb->getitem_bylogin($user_login, $user_code)) == FALSE) {
+          if (($user_item = $bdb->getitem_bylogin($target, $user_code)) == FALSE) {
               $ret = 4;
               break;
           }
@@ -1688,10 +1698,10 @@ class Brisk
           }
 
           if (versions_cmp($user_tos_vers, "1.2") < 0) {
-              $mesg = sprintf($mlang_brisk['tos_old'][$G_lang], xcape($user_login));
+              $mesg = sprintf($mlang_brisk['tos_old'][$G_lang], xcape($target));
           }
           else if ($guar_login == "") {
-              $mesg = sprintf($mlang_brisk['inf_nfd'][$G_lang], xcape($user_login));
+              $mesg = sprintf($mlang_brisk['inf_nfd'][$G_lang], xcape($target));
           }
       } while (0);
 
@@ -1705,7 +1715,7 @@ class Brisk
       else {
           $jret = json_encode(array("ret" => 0,
                                     "mesg" => "",
-                                    "login" => $user_login,
+                                    "login" => $target,
                                     // FIXME: state internationalization
                                     "state" =>
                                     ($user_item->type & USER_FLAG_TY_APPR ? "Apprendista" :
@@ -1724,6 +1734,34 @@ class Brisk
       return $jret;
   }
 
+  function info_save($user, $json_s)
+  {
+      GLOBAL $G_lang, $mlang_brisk, $G_base;
+
+      $mesg = "";
+      $user_code = -1;
+      $ret = 0;
+
+      do {
+          if (($json = json_decode($json_s)) == FALSE) {
+              $ret = 1;
+              break;
+          }
+
+          if (($bdb = BriskDB::create()) == FALSE) {
+              $ret = 2;
+              break;
+          }
+
+          if (($user_item = $bdb->usersnet_save($user->code, $json)) != 0) {
+              $ret = 4000 + $user_item;
+              break;
+          }
+      } while(0);
+
+      return ($ret);
+  }
+
   function room_outstandup($user)
   {
     $this->room_sitdown($user, -1);
@@ -2086,7 +2124,6 @@ class Brisk
     else if (strncmp($msg, "/info ", 6) == 0) {
         $info_user = substr($msg, 6);
 
-        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) {