add tables for apprentices
[brisk.git] / web / index_wr.php
index 7d816d7..ea88b0f 100644 (file)
@@ -42,6 +42,8 @@ $mlang_indwr = array( 'unknownerr'    => array( 'it' => 'errore sconosciuto',
                                            'en' => 'To send a message to the administrator you have to be authenticated'),
                       'shutmsg'  => array( 'it' => '<b>Il server sta per essere riavviato, non possono avere inizio nuove partite.</b>',
                                            'en' => '<b>The server is going to be rebooted, new games are not allowed.</b>'),
+                      'mustappr' => array( 'it' => '<b>Il tavolo a cui volevi sederti richiede autentifica o apprendistato.</b>',
+                                           'en' => '<b>The table where you want to sit require authentication or apprentice</b>'),
                       'mustauth' => array( 'it' => '<b>Il tavolo a cui volevi sederti richiede autentifica.</b>',
                                            'en' => '<b>The table where you want to sit require authentication</b>'),
                       'mustcert' => array( 'it' => '<b>Il tavolo a cui volevi sederti richiede autentifica e certificazione.</b>',
@@ -117,6 +119,8 @@ Ti sei registrato col nickname \'%s\',<br>
 Ciò è necessario per ottenere la password.<br><br>
 Saluti e buone partite, mop.<br>',
                                            'en' => 'EN mhtml [%s] [%s]'),
+                      'info_err' => array( 'it' => 'E\' occorso un errore (%d), riprova più tardi.',
+                                           'en' => 'Some error occurs (%d), retry later.')
                       );
 
 define('LICMGR_CHO_ACCEPT', 0);
@@ -125,7 +129,7 @@ define('LICMGR_CHO_AFTER',  2);
 
 function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie)
 {
-    GLOBAL $G_domain, $G_webbase, $G_mail_seed;
+    GLOBAL $G_domain, $G_webbase, $G_mail_seed, $G_notguar_code;
     GLOBAL $G_shutdown, $G_alarm_passwd, $G_ban_list, $G_black_list, $G_lang, $G_room_help, $G_room_about;
     GLOBAL $G_room_passwdhowto, $mlang_indwr;
     GLOBAL $G_tos_vers;
@@ -239,8 +243,10 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie)
             // check existence of username or email
             $is_trans = FALSE;
             do {
-                if (($bdb = BriskDB::create()) == FALSE)
+                if (($bdb = BriskDB::create()) == FALSE) {
+                    $mesg_to_user = "Connessione al database fallita";
                     break;
+                }
 
                 // check IP address as previous requirer
                 if ($bdb->selfreg_check($remote_ip) == FALSE) {
@@ -265,13 +271,15 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie)
                 // FIXME: move 'no-guaran' user into configuration file
                 if (($usr_obj = $bdb->user_add($cli_name, 'THE_PASS', $cli_email,
                                                USER_FLAG_TY_DISABLE | USER_FLAG_TY_APPR,
-                                               USER_DIS_REA_NU_MAILED, 10103)) == FALSE) {
+                                               USER_DIS_REA_NU_MAILED, $G_notguar_code)) == FALSE) {
                     fprintf(STDERR, "ERROR: user_add FAILED\n");
+                    $mesg_to_user = "Fallito inserimento nel database.";
                     break;
                 }
 
                 if (($mail_code = $bdb->mail_reserve_code()) == FALSE) {
                     fprintf(STDERR, "ERROR: mail reserve code FAILED\n");
+                    $mesg_to_user = "Fallita creazione codice email.";
                     break;
                 }
                 $hash = md5($curtime . $G_alarm_passwd . $cli_name . $cli_email);
@@ -291,6 +299,7 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie)
                 if ($mail_item->store($bdb) == FALSE) {
                     // store mail error
                     fprintf(STDERR, "ERROR: store mail FAILED\n");
+                    $mesg_to_user = "Fallita procedura di store.";
                     break;
                 }
 
@@ -303,6 +312,7 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie)
                 if (brisk_mail($cli_email, $subj, $body_txt, $body_htm) == FALSE) {
                     // mail error
                     fprintf(STDERR, "ERROR: mail send FAILED\n");
+                    $mesg_to_user = "Fallito invio email.";
                     break;
                 }
 
@@ -311,7 +321,8 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie)
                 echo "1";
                 return TRUE;
             } while(FALSE);
-            $bdb->transaction('ROLLBACK');
+            if ($is_trans)
+                $bdb->transaction('ROLLBACK');
             echo "$mesg_to_user";
             return FALSE;
         }
@@ -344,6 +355,20 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie)
     if ($argz[0] == 'ping') {
         log_wr("PING RECEIVED");
     }
+    else if ($argz[0] == 'info') {
+        if ($argz[1] == 'save') {
+            if (!isset($post['info'])) {
+                return FALSE;
+            }
+            if (($ret = $brisk->info_save($user, $post['info'])) == 0) {
+                echo "1";
+                return TRUE;
+            }
+
+            printf($mlang_indwr['info_err'][$G_lang], $ret);
+            return FALSE;
+        }
+    }
     else if ($argz[0] == 'prefs') {
         if ($argz[1] == 'save') {
             if (!isset($post['prefs'])) {
@@ -405,7 +430,7 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie)
                 if (($wa_lock = Warrant::lock_data(TRUE)) != FALSE) {
                     if (($fp = @fopen(LEGAL_PATH."/warrant.txt", 'a')) != FALSE) {
                         /* Unix time | session | nickname | IP | where was | mesg */
-                        fwrite($fp, sprintf("%ld|%s|%s|%s|\n", $curtime, xcapelt($user->name), xcapelt(urldecode($cli_name)), xcapelt(urldecode($cli_email))));
+                        fwrite($fp, sprintf("%ld|%s|%s|%s|\n", $curtime, xcapelt($user->name), xcapelt(trim(urldecode($cli_name))), xcapelt(trim(urldecode($cli_email)))));
                         fclose($fp);
                     }
                     Warrant::unlock_data($wa_lock);
@@ -427,8 +452,8 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie)
                     if (($bdb = BriskDB::create()) == FALSE)
                         break;
 
-                    $cli_name = urldecode($cli_name);
-                    $cli_email = urldecode($cli_email);
+                    $cli_name = trim(urldecode($cli_name));
+                    $cli_email = trim(urldecode($cli_email));
 
                     // check for already used fields
                     if (($idret = $bdb->check_record_by_login_or_email($cli_name, $cli_email)) != 0) {
@@ -586,7 +611,7 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie)
         $dobreak = FALSE;
         do {
             log_wr("INFO:SKIP:argz == poll name: [".$cli_poll_name."] AUTH: ".$user->is_auth());
-            if ( ! $user->is_auth() ) {
+            if ( ! $user->is_auth() || $user->is_appr() ) {
                 // MLANG: <b>Per partecipare al sondaggio devi essere autenticato.</b>
                 $mesg_to_user = nickserv_msg($dt, $mlang_indwr['pollmust'][$G_lang]);
                 log_wr("break1");
@@ -804,6 +829,10 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie)
                           (!$user->is_auth() || $user->is_appr()) ) {
                     $not_allowed_msg = nickserv_msg($dt, $mlang_indwr['mustauth'][$G_lang]);
                 }
+                else if ( $table->auth_type == TABLE_AUTH_TY_APPR &&
+                          (!$user->is_auth()) ) {
+                    $not_allowed_msg = nickserv_msg($dt, $mlang_indwr['mustappr'][$G_lang]);
+                }
                 else if ($user->flags & USER_FLAG_TY_FIRONLY && $table->player_n > 0) {
                     $not_allowed_msg = nickserv_msg($dt, $mlang_indwr['mustfirst'][$G_lang]);
                 }