+ else if ($argz[0] == 'apprentice') {
+ if (($cli_name = gpcs_var('cli_name', $get, $post, $cookie)) === FALSE)
+ $cli_name = "";
+
+ if (($cli_email = gpcs_var('cli_email', $get, $post, $cookie)) === FALSE)
+ $cli_email = "";
+
+ $mesg_to_user = "";
+
+ // check existence of username or email
+ $is_trans = FALSE;
+ do {
+ 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) {
+ $mesg_to_user = $mlang_indwr['nu_netguard'][$G_lang];
+ break;
+ }
+
+ $cli_name = urldecode($cli_name);
+ $cli_email = urldecode($cli_email);
+
+ // check for already used fields
+ if (($idret = $bdb->check_record_by_login_or_email($cli_name, $cli_email)) != 0) {
+ $mesg_to_user = ($idret == 1 ? $mlang_indwr['nu_loginau'][$G_lang] :
+ ($idret == 2 ? $mlang_indwr['nu_emailau'][$G_lang] :
+ $mlang_indwr['unknownerr'][$G_lang]));
+ break;
+ }
+
+ $bdb->transaction('BEGIN');
+ $is_trans = TRUE;
+ // insert the new user disabled with reason NU_MAILED
+ // 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, $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);
+
+ $confirm_page = sprintf("http://%s/%s/mailmgr.php?f_act=checkmail&f_code=%d&f_hash=%s",
+ $G_domain, $G_webbase, $mail_code, $hash);
+ $subj = $mlang_indwr['nu_msubj'][$G_lang];
+ $body_txt = sprintf($mlang_indwr['ap_mtext'][$G_lang],
+ $cli_name, $confirm_page);
+ $body_htm = sprintf($mlang_indwr['ap_mhtml'][$G_lang],
+ $cli_name, $confirm_page);
+
+ $mail_item = new MailDBItem($mail_code, $usr_obj->code, MAIL_TYP_CHECK,
+ $curtime, $subj, $body_txt, $body_htm, $hash);
+
+ // save the mail
+ if ($mail_item->store($bdb) == FALSE) {
+ // store mail error
+ fprintf(STDERR, "ERROR: store mail FAILED\n");
+ $mesg_to_user = "Fallita procedura di store.";
+ break;
+ }
+
+ // check IP address as previous requirer
+ if ($bdb->selfreg_set($remote_ip) == FALSE) {
+ $mesg_to_user = $mlang_indwr['nu_unkerr'][$G_lang];
+ break;
+ }
+
+ 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;
+ }
+
+ $bdb->transaction('COMMIT');
+ fprintf(STDERR, "REMOTE: %d\n", $remote_ip);
+ echo "1";
+ return TRUE;
+ } while(FALSE);
+ if ($is_trans)
+ $bdb->transaction('ROLLBACK');
+ echo "$mesg_to_user";
+ return FALSE;