More clear message when a user verify twice its email address
[brisk.git] / web / mailmgr.php
1 <?php
2 /*
3  *  brisk - mailmgr.php
4  *
5  *  Copyright (C) 2014      Matteo Nastasi
6  *                          mailto: nastasi@alternativeoutput.it
7  *                                  matteo.nastasi@milug.org
8  *                          web: http://www.alternativeoutput.it
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details. You should have received a
19  * copy of the GNU General Public License along with this program; if
20  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21  * Suite 330, Boston, MA 02111-1307, USA.
22  *
23  */
24
25 $G_base = "";
26
27 ini_set("max_execution_time", "240");
28
29 require_once($G_base."Obj/brisk.phh");
30 require_once($G_base."Obj/user.phh");
31 require_once($G_base."Obj/auth.phh");
32 require_once($G_base."Obj/dbase_${G_dbasetype}.phh");
33 require_once($G_base."Obj/singlemsg.phh");
34
35 require_once($G_base."spush/brisk-spush.phh");
36
37 define('MAILMGR_CHECKMAIL', 1);
38
39 function main() {
40     // GLOBAL $G_dbpfx, $G_alarm_passwd, $f_mailusers, $sess, $_POST, $_SERVER;
41     GLOBAL $G_dbpfx, $f_act, $f_code, $f_hash;
42
43     /* echo "act:  $f_act<br>";
44        echo "code: $f_code<br>";
45        echo "hash: $f_hash<br>"; */
46
47     if ($f_act == "checkmail") {
48         $errcode = 10000;
49         do {
50             if (($bdb = BriskDB::create()) == FALSE) {
51                 log_crit("stat-day: database connection failed");
52                 $errcode = 10001;
53                 break;
54             }
55             $bdb->transaction('BEGIN');
56
57             if (($mai = $bdb->mail_check($f_code, MAILMGR_CHECKMAIL, $f_hash)) == FALSE) {
58                 $errcode = 10002;
59                 break;
60             }
61
62             if (($bdb->user_update_flag_ty($mai->ucode, USER_FLAG_TY_DISABLE,
63                                         TRUE, USER_DIS_REA_NU_MAILED,
64                                         TRUE, USER_DIS_REA_NU_TOBECHK)) == FALSE) {
65                 $errcode = 10003;
66                 break;
67             }
68
69             if (($mai = $bdb->mail_delete($f_code)) == FALSE) {
70                 $errcode = 10004;
71                 break;
72             }
73             $bdb->transaction('COMMIT');
74
75             singlemsg("Verifica della e-mail andata a buon fine.", "Verifica della e-mail andata a buon fine.<br>Riceverai a breve una email con la tua nuova password.<br>Benvenuto!");
76             $errcode = 0;
77         } while (FALSE);
78         if ($errcode) {
79             if ($errcode == 10002) {
80                 singlemsg("L'email è già stata verificata con successo.",
81                           "L'email è già stata verificata con successo, ora attenda che le venga recapitata la password.");
82             }
83             else {
84                 singlemsg("E' occorso un errore durante la verifica della e-mail.",
85                           sprintf("E' occorso un errore durante la verifica della e-mail.<br><br>Codice d'errore: %d.<br>", $errcode));
86             }
87             $bdb->transaction('ROLLBACK');
88         }
89     }
90
91     exit;
92 }
93
94 main();
95 ?>