url protocol parametrization and some typo
[brisk.git] / web / usermgmt.php
1 <?php
2 /*
3  *  brisk - usermgmt.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 foreach (array("HTTP_HOST", "DOCUMENT_ROOT") as $i) {
26     if (isset($_SERVER[$i])) {
27         $$i = $_SERVER[$i];
28         }
29     }
30
31 foreach (array("pazz") as $i) {
32     if (isset($_POST[$i])) {
33         $$i = $_POST[$i];
34         }
35     }
36
37 foreach (array("sess") as $i) {
38     if (isset($_COOKIE[$i])) {
39         $$i = $_COOKIE[$i];
40         }
41     }
42
43 foreach (array("sess") as $i) {
44     if (isset($_COOKIE[$i])) {
45         $$i = $_COOKIE[$i];
46         }
47     }
48
49 $G_base = "";
50
51 $mlang_umgmt = array( 'nu_psubj' => array( 'it' => 'Brisk: credenziali di accesso.',
52                                            'en' => 'Brisk: credentials.'),
53                       'nu_ptext' => array( 'it' =>
54 'Ciao, sono l\' amministratore del sito di Brisk.
55
56 La verifica del tuo indirizzo di posta elettronica e del tuo nickname è andata a buon fine, per accedere al sito
57 d\'ora in poi potrai utilizzare l\' utente \'%s\' e la password \'%s\'.
58
59 Benvenuto e buone partite, mop.',
60                                            'en' => 'EN ptext [%s] [%s]'),
61                       'nu_phtml' => array( 'it' => 'Ciao, sono l\' amministratore del sito di Brisk.<br><br>
62 La verifica del tuo indirizzo di posta elettronica e del tuo nickname è andata a buon fine.<br><br>Per accedere al  sito d\'ora in poi potrai usare l\' utente \'%s\' e la password \'%s\'.<br><br>
63 Benvenuto e buone partite, mop.<br>',
64                                            'en' => 'EN phtml [%s] [%s]')
65                       );
66
67
68 ini_set("max_execution_time",  "240");
69
70 require_once($G_base."Obj/brisk.phh");
71 require_once($G_base."Obj/user.phh");
72 require_once($G_base."Obj/auth.phh");
73 require_once($G_base."Obj/mail.phh");
74 require_once($G_base."Obj/dbase_base.phh");
75 require_once($G_base."Obj/dbase_${G_dbasetype}.phh");
76 require_once($G_base."briskin5/Obj/briskin5.phh");
77 require_once($G_base."briskin5/Obj/placing.phh");
78 require_once($G_base."spush/brisk-spush.phh");
79 require_once($G_base."index_wr.php");
80
81 function check_auth()
82 {
83     GLOBAL $G_alarm_passwd, $sess, $_POST, $_SERVER;
84
85     $socket = FALSE;
86     $ret = FALSE;
87     $ip = $_SERVER["REMOTE_ADDR"];
88     $stp = 0;
89     $private = md5($G_alarm_passwd.$ip.$sess);
90     $cmd = array ("cmd" => "userauth", "sess" => $sess, "private" => $private, "the_end" => "true");
91     $cmd_ser = cmd_serialize($cmd);
92     $cmd_len = mb_strlen($cmd_ser, "ASCII");
93
94     do {
95         if (($socket = stream_socket_client("unix://".USOCK_PATH."2")) == FALSE)
96             break;
97         $stp = 1;
98         if (($rwr = fwrite($socket, $cmd_ser, $cmd_len)) == FALSE
99             || $rwr != $cmd_len)
100             break;
101         fflush($socket);
102         $stp = 2;
103         if (($buf = fread($socket, 4096)) == FALSE)
104             break;
105         $res = cmd_deserialize($buf);
106         $stp = 3;
107         if (!isset($res['val']) || $res['val'] != 200)
108             break;
109         $ret = TRUE;
110         $stp = 4;
111     } while (0);
112     if ($socket != FALSE)
113         fclose($socket);
114
115     if ($stp < 4) {
116         echo "STP: $stp<br>";
117     }
118     return ($ret);
119 }
120
121 $s_style = "
122 <style>
123      table.the_tab {
124             border-collapse: collapse;
125             margin: 8px;
126             }
127
128      table.the_tab td {
129             border: 1px solid black;
130             padding: 8px;
131             }
132 </style>";
133
134 function main() {
135     GLOBAL $s_style, $G_dbpfx, $G_lang, $G_alarm_passwd, $G_proto, $G_domain, $G_webbase;
136     GLOBAL $mlang_umgmt, $mlang_indwr, $f_mailusers, $sess, $_POST, $_SERVER;
137
138
139     $curtime = time();
140     $status = "";
141
142     if (check_auth() == FALSE) {
143         echo "Authentication failed";
144         exit;
145     }
146
147     $nocheck = FALSE;
148     if (isset($_GET['f_nocheck'])) {
149         $nocheck = TRUE;
150     }
151
152     if (isset($_GET['do']) && $_GET['do'] == 'newuser') {
153         if (isset($_POST['f_accept'])) {
154             $action = "accept";
155         }
156         else if (isset($_POST['f_delete'])) {
157             $action = "delete";
158         }
159         else {
160             $action = "show";
161         }
162
163         if ($action == "accept") {
164             foreach($_POST as $key => $value) {
165                 if (substr($key, 0, 9) != "f_newuser")
166                     continue;
167
168                 $id = (int)substr($key, 9);
169                 if ($id <= 0)
170                     continue;
171
172                 // check existence of username or email
173                 $is_trans = FALSE;
174                 $res = FALSE;
175                 do {
176                     if (($bdb = BriskDB::create()) == FALSE)
177                         break;
178
179                     // retrieve list added users
180                     $usr_sql = sprintf("
181 SELECT usr.*, guar.login AS guar_login
182      FROM %susers AS usr
183      JOIN %susers AS guar ON guar.code = usr.guar_code
184      WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer))
185          AND usr.disa_reas = %d AND usr.code = %d;",
186                                $G_dbpfx, $G_dbpfx,
187                                USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
188                                USER_DIS_REA_NU_ADDED, $id);
189                     if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
190                         log_crit("stat-day: select from tournaments failed");
191                         break;
192                     }
193                     $usr_n = pg_numrows($usr_pg);
194                     if ($usr_n != 1) {
195                         $status .= sprintf("Inconsistency for code %d, returned %d records, skipped.<br>",
196                                           $id, $usr_n);
197                         break;
198                     }
199
200                     $usr_obj = pg_fetch_object($usr_pg, 0);
201
202                     $bdb->transaction('BEGIN');
203                     $is_trans = TRUE;
204
205
206                     if (($bdb->user_update_flag_ty($usr_obj->code, USER_FLAG_TY_DISABLE,
207                                                    TRUE, USER_DIS_REA_NU_ADDED,
208                                                    TRUE, USER_DIS_REA_NU_MAILED)) == FALSE) {
209                         echo "fail 2<br>";
210                         break;
211                     }
212
213                     if (($mail_code = $bdb->mail_reserve_code()) == FALSE) {
214                         fprintf(STDERR, "ERROR: mail reserve code FAILED\n");
215                         break;
216                     }
217                     $hash = md5($curtime . $G_alarm_passwd . $usr_obj->login . $usr_obj->email);
218
219                     $confirm_page = sprintf("%s://%s/%s/mailmgr.php?f_act=checkmail&f_code=%d&f_hash=%s",
220                                             $G_proto, $G_domain, $G_webbase, $mail_code, $hash);
221                     $subj = $mlang_indwr['nu_msubj'][$G_lang];
222                     if (($usr_obj->type & USER_FLAG_TY_APPR) == USER_FLAG_TY_APPR) {
223                         $body_txt = sprintf($mlang_indwr['ap_mtext'][$G_lang],
224                                             $cli_name, $confirm_page);
225                         $body_htm = sprintf($mlang_indwr['ap_mhtml'][$G_lang],
226                                             $cli_name, $confirm_page);
227                     }
228                     else {
229                         $body_txt = sprintf($mlang_indwr['nu_mtext'][$G_lang],
230                                             $usr_obj->guar_login, $usr_obj->login, $confirm_page);
231                         $body_htm = sprintf($mlang_indwr['nu_mhtml'][$G_lang],
232                                             $usr_obj->guar_login, $usr_obj->login, $confirm_page);
233                     }
234
235                     $mail_item = new MailDBItem($mail_code, $usr_obj->code, MAIL_TYP_CHECK,
236                                                 $curtime, $subj, $body_txt, $body_htm, $hash);
237
238                     if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
239                         // mail error
240                         fprintf(STDERR, "ERROR: mail send FAILED\n");
241                         break;
242                     }
243                     // save the mail
244                     if ($mail_item->store($bdb) == FALSE) {
245                         // store mail error
246                         fprintf(STDERR, "ERROR: store mail FAILED\n");
247                         break;
248                     }
249                     $status .= sprintf("status change for %s: SUCCESS<br>", $usr_obj->login);
250                     $bdb->transaction('COMMIT');
251                     $res = TRUE;
252                 } while(FALSE);
253                 if ($res == FALSE) {
254                     $status .= sprintf("Error occurred during accept action<br>");
255                     if ($is_trans)
256                         $bdb->transaction('ROLLBACK');
257                     break;
258                 }
259             }
260         } // else if ($action == "accept") {
261
262
263         do {
264             if (($bdb = BriskDB::create()) == FALSE) {
265                 log_crit("stat-day: database connection failed");
266                 break;
267             }
268
269             // retrieve list added users
270             $usr_sql = sprintf("
271 SELECT usr.*, guar.login AS guar_login
272      FROM %susers AS usr
273      JOIN %susers AS guar ON guar.code = usr.guar_code
274      WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer))
275          AND usr.disa_reas = %d ORDER BY usr.lintm;",
276                                $G_dbpfx, $G_dbpfx,
277                                USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
278                                USER_DIS_REA_NU_ADDED);
279             if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
280                 log_crit("stat-day: select from tournaments failed");
281                 break;
282             }
283             $usr_n = pg_numrows($usr_pg);
284             $tab_lines = "<tr><th></th><th>User</th><th>Guar</th><th>Date</th></tr>";
285             for ($i = 0 ; $i < $usr_n ; $i++) {
286                 $usr_obj = pg_fetch_object($usr_pg, $i);
287
288                 $tab_lines .= sprintf("<tr><td><input name=\"f_newuser%d\" type=\"checkbox\" %s></td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
289                                       $usr_obj->code, ($nocheck ? "" : "CHECKED"),
290                                       eschtml($usr_obj->login), eschtml($usr_obj->guar_login), $usr_obj->lintm);
291             }
292
293
294             ?>
295 <html>
296 <head>
297 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
298 <title>Brisk: new imported users management.</title>
299      <?php echo "$s_style"; ?>
300 </head>
301 <body>
302 <h2> New imported users management.</h2>
303      <?php if ($status != "") { echo "$status"; } ?>
304 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
305 <table class="the_tab">
306 <?php
307      echo $tab_lines;
308 ?>
309 </table>
310 <input type="submit" name="f_accept" value="Newuser Accept">
311 <input type="submit" name="f_delete" value="Newuser Delete">
312 </form>
313 </body>
314 </html>
315 <?php
316            exit;
317         } while(FALSE);
318         printf("Some error occurred during newuser visualization\n");
319         exit;
320     }
321
322     if (isset($_GET['do']) && $_GET['do'] == 'mailed') {
323         if (isset($_POST['f_resend'])) {
324             $action = "resend";
325         }
326         else if (isset($_POST['f_delete'])) {
327             $action = "delete";
328         }
329         else {
330             $action = "show";
331         }
332
333         if ($action == "resend") {
334             foreach($_POST as $key => $value) {
335                 if (substr($key, 0, 9) != "f_newuser")
336                     continue;
337
338                 $id = (int)substr($key, 9);
339                 if ($id <= 0)
340                     continue;
341
342                 $res = FALSE;
343                 do {
344                     if (($bdb = BriskDB::create()) == FALSE) {
345                         $status .= "1<br>";
346                         break;
347                     }
348                     // retrieve list added users
349                     $mai_sql = sprintf("
350 SELECT mail.*, usr.email AS email
351      FROM %susers AS usr
352      JOIN %smails AS mail ON mail.ucode = usr.code
353      WHERE mail.ucode = %d AND mail.type = %d",
354                                        $G_dbpfx, $G_dbpfx, $id, MAIL_TYP_CHECK);
355                     if (($mai_pg = pg_query($bdb->dbconn->db(), $mai_sql)) == FALSE) {
356                         log_crit("retrieve mail failed");
357                         $status .= "2<br>";
358                         break;
359                     }
360                     $mai_n = pg_numrows($mai_pg);
361                     if ($mai_n != 1) {
362                         $status .= sprintf("Inconsistency for code %d, returned %d records, skipped.<br>",
363                                           $id, $mai_n);
364                         break;
365                     }
366                     $mai_obj = pg_fetch_object($mai_pg, 0);
367                     $mail = MailDBItem::MailDBItemFromRecord($mai_obj);
368
369                     if (brisk_mail($mai_obj->email, $mail->subj, $mail->body_txt, $mail->body_htm) == FALSE) {
370                         // mail error
371                         $status .= sprintf("Send mail filed for user id %d<br>\n", $id);
372                         break;
373                     }
374                     $res = TRUE;
375                 } while(FALSE);
376                 if ($res == FALSE) {
377                     $status .= sprintf("Error occurred during resend action<br>");
378                     break;
379                 }
380             } // foreach
381         }
382
383         do {
384             if (($bdb = BriskDB::create()) == FALSE) {
385                 log_crit("stat-day: database connection failed");
386                 break;
387             }
388
389             // retrieve list added users
390             $usr_sql = sprintf("
391 SELECT usr.*, guar.login AS guar_login
392      FROM %susers AS usr
393      JOIN %susers AS guar ON guar.code = usr.guar_code
394      WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer))
395          AND usr.disa_reas = %d ORDER BY usr.lintm;",
396                                $G_dbpfx, $G_dbpfx,
397                                USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
398                                USER_DIS_REA_NU_MAILED);
399             if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
400                 log_crit("stat-day: select from tournaments failed");
401                 break;
402             }
403             $usr_n = pg_numrows($usr_pg);
404             $tab_lines = "<tr><th></th><th>User</th><th>Guar</th><th>Date</th></tr>";
405             for ($i = 0 ; $i < $usr_n ; $i++) {
406                 $usr_obj = pg_fetch_object($usr_pg, $i);
407
408                 $tab_lines .= sprintf("<tr><td><input name=\"f_newuser%d\" type=\"checkbox\" %s></td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
409                                       $usr_obj->code, ($nocheck ? "" : "CHECKED"),
410                                       eschtml($usr_obj->login), eschtml($usr_obj->guar_login), $usr_obj->lintm);
411             }
412             ?>
413 <html>
414 <head>
415 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
416 <title>Brisk: new mailed users management.</title>
417      <?php echo "$s_style"; ?>
418 </head>
419 <body>
420 <h2> New mailed users management.</h2>
421      <?php if ($status != "") { echo "$status"; } ?>
422 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
423 <table class="the_tab">
424 <?php
425      echo $tab_lines;
426 ?>
427 </table>
428 <input type="submit" name="f_resend" value="Mailed Resend">
429 <input type="submit" name="f_delete" value="Mailed Delete">
430 </form>
431 </body>
432 </html>
433 <?php
434            exit;
435         } while(FALSE);
436         printf("Some error occurred during newuser visualization\n");
437         exit;
438     }
439     else { // if ($_GET['do'] ...
440         if (isset($_POST['f_accept'])) {
441             $action = "accept";
442         }
443         else if (isset($_POST['f_delete'])) {
444             $action = "delete";
445         }
446         else {
447             $action = "show";
448         }
449
450         if ($action == "accept") {
451             if (($bdb = BriskDB::create()) == FALSE) {
452                 log_crit("stat-day: database connection failed");
453                 break;
454             }
455
456             foreach($_POST as $key => $value) {
457                 if (substr($key, 0, 9) != "f_newuser")
458                     continue;
459
460                 $id = (int)substr($key, 9);
461                 if ($id <= 0)
462                     continue;
463
464
465                 // retrieve list of active tournaments
466                 $usr_sql = sprintf("
467 SELECT usr.*, guar.login AS guar_login
468      FROM %susers AS usr
469      JOIN %susers AS guar ON guar.code = usr.guar_code
470      WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer))
471          AND usr.disa_reas = %d AND usr.code = %d;",
472                                    $G_dbpfx, $G_dbpfx,
473                                    USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
474                                    USER_DIS_REA_NU_TOBECHK, $id);
475                 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
476                     log_crit("stat-day: select from tournaments failed");
477                     break;
478                 }
479                 $usr_obj = pg_fetch_object($usr_pg, 0);
480
481                 printf("KEY: %s: %s %s<br>\n", $id, $value, $usr_obj->login);
482                 // change state
483                 $passwd = passwd_gen();
484
485                 if (($bdb->user_update_passwd($usr_obj->code, $passwd)) == FALSE) {
486                     echo "fail 1.5<br>";
487                     break;
488                 }
489
490                 if (($bdb->user_update_flag_ty($usr_obj->code, USER_FLAG_TY_DISABLE,
491                                                TRUE, USER_DIS_REA_NU_TOBECHK,
492                                                FALSE, USER_DIS_REA_NONE)) == FALSE) {
493                     echo "fail 2<br>";
494                     break;
495                 }
496
497                 $bdb->user_update_login_time($usr_obj->code, 0);
498
499                 // send mail
500                 $subj = $mlang_umgmt['nu_psubj'][$G_lang];
501                 $body_txt = sprintf($mlang_umgmt['nu_ptext'][$G_lang],
502                                     $usr_obj->login, $passwd);
503                 $body_htm = sprintf($mlang_umgmt['nu_phtml'][$G_lang],
504                                     $usr_obj->login, $passwd);
505
506                 log_step(sprintf("[%s], [%s], [%s], [%s]\n", $usr_obj->email, $subj, $body_txt, $body_htm));
507
508
509                 if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
510                     // mail error
511                     fprintf(STDERR, "ERROR: mail send FAILED\n");
512                     break;
513                 }
514             }
515             exit;
516         }
517
518
519         else if ($action == "delete") {
520             foreach($_POST as $key => $value) {
521                 if (substr($key, 0, 9) != "f_newuser")
522                     continue;
523
524                 $id = (int)substr($key, 9);
525                 if ($id <= 0)
526                     continue;
527
528                 // check existence of username or email
529                 $is_trans = FALSE;
530                 $res = FALSE;
531                 do {
532                     if (($bdb = BriskDB::create()) == FALSE)
533                         break;
534
535                     // retrieve list added users
536                     $usr_sql = sprintf("
537 SELECT usr.*, guar.login AS guar_login
538      FROM %susers AS usr
539      JOIN %susers AS guar ON guar.code = usr.guar_code
540      WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer))
541          AND usr.disa_reas = %d AND usr.code = %d;",
542                                $G_dbpfx, $G_dbpfx,
543                                        USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
544                                        USER_DIS_REA_NU_TOBECHK, $id);
545
546
547                     if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
548                         log_crit("stat-day: select from tournaments failed");
549                         break;
550                     }
551                     $usr_n = pg_numrows($usr_pg);
552                     if ($usr_n != 1) {
553                         $status .= sprintf("Inconsistency for code %d, returned %d records, skipped.<br>",
554                                           $id, $usr_n);
555                         break;
556                     }
557
558                     $usr_obj = pg_fetch_object($usr_pg, 0);
559
560                     $bdb->transaction('BEGIN');
561                     $is_trans = TRUE;
562
563                     $del_sql = sprintf("DELETE FROM %susers WHERE code = %d;",
564                                        $G_dbpfx, $usr_obj->code);
565
566                     if (($del_pg = pg_query($bdb->dbconn->db(), $del_sql)) == FALSE) {
567                         log_crit("stat-day: select from tournaments failed");
568                         break;
569                     }
570
571                     // FIXME: add to index_wr.php strings
572                     $subj = "Brisk: nickname rifiutato";
573                     // the same for both cases:
574                     //  if (($usr_obj->type & USER_FLAG_TY_APPR) == USER_FLAG_TY_APPR) {
575                         $body_txt = sprintf('Ciao, sono l\' amministratore del sito di Brisk.
576
577 Ti volevo segnalare che il nickname \'%s\' con cui ti volevi registrare
578 non ha superato la fase di verifica manuale; il motivo può essere
579 la sua illeggibilità per gli altri utenti o il contenuto poco ortodosso
580 o troppo aggressivo o ci sono troppe cifre consecutive o qualcosa del genere.
581
582 La procedura di registrazione va ripetuta.
583
584 Saluti e buone partite, mop.', $usr_obj->login);
585
586                         $body_htm = sprintf('Ciao, sono l\' amministratore del sito di Brisk.<br><br>
587 Ti volevo segnalare che il nickname \'%s\' con cui ti volevi registrare
588 non ha superato la fase di verifica manuale; il motivo può essere
589 la sua illeggibilità per gli altri utenti o il contenuto poco ortodosso
590 o troppo aggressivo o ci sono troppe cifre consecutive o qualcosa del genere.<br><br>
591 La procedura di registrazione va ripetuta.<br><br>
592 Saluti e buone partite, mop.', $usr_obj->login);
593                     /* } */
594                     /* else { */
595                     /*     $body_txt = sprintf($mlang_indwr['nu_mtext'][$G_lang], */
596                     /*                         $usr_obj->guar_login, $usr_obj->login, $confirm_page); */
597                     /*     $body_htm = sprintf($mlang_indwr['nu_mhtml'][$G_lang], */
598                     /*                         $usr_obj->guar_login, $usr_obj->login, $confirm_page); */
599                     /* } */
600
601                     if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
602                         // mail error
603                         fprintf(STDERR, "ERROR: mail send FAILED\n");
604                         break;
605                     }
606                     $status .= sprintf("user delete for %s: SUCCESS<br>", $usr_obj->login);
607                     $bdb->transaction('COMMIT');
608                     $res = TRUE;
609                 } while(FALSE);
610                 if ($res == FALSE) {
611                     $status .= sprintf("Error occurred during accept action<br>");
612                     if ($is_trans)
613                         $bdb->transaction('ROLLBACK');
614                     break;
615                 }
616                 printf("Registration %s for login %s deleted<br>\n", $usr_obj->code, $usr_obj->login);
617             }
618         }
619         else {
620             do {
621             if (($bdb = BriskDB::create()) == FALSE) {
622                 log_crit("stat-day: database connection failed");
623                 break;
624             }
625
626             // retrieve list of active tournaments
627             $usr_sql = sprintf("
628 SELECT usr.*, guar.login AS guar_login
629      FROM %susers AS usr
630      JOIN %susers AS guar ON guar.code = usr.guar_code
631      WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer))
632          AND usr.disa_reas = %d ORDER BY usr.lintm;",
633                                $G_dbpfx, $G_dbpfx,
634                                USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
635                                USER_DIS_REA_NU_TOBECHK);
636             if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
637                 log_crit("stat-day: select from tournaments failed");
638                 break;
639             }
640
641             $usr_n = pg_numrows($usr_pg);
642             $tab_lines = "<tr><th></th><th>User</th><th>EMail</th><th>Guar</th><th>Apprendice</th><th>Date</th></tr>";
643             for ($i = 0 ; $i < $usr_n ; $i++) {
644                 $usr_obj = pg_fetch_object($usr_pg, $i);
645
646                 $tab_lines .= sprintf("<tr><td><input name=\"f_newuser%d\" type=\"checkbox\" %s></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
647                                       $usr_obj->code, ($nocheck ? "" : "CHECKED"),
648                                       eschtml($usr_obj->login), eschtml($usr_obj->email), eschtml($usr_obj->guar_login),
649                                       ($usr_obj->type & USER_FLAG_TY_APPR ? "Yes" : "No"),
650                                       $usr_obj->lintm);
651             }
652             ?>
653 <html>
654 <head>
655 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
656 <title>Brisk: email verified user management.</title>
657      <?php echo "$s_style"; ?>
658 </head>
659      <body>
660      <h2> E-mail verified user management.</h2>
661      <?php if ($status != "") { echo "$status"; } ?>
662      <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
663      <table class="the_tab">
664      <?php
665      echo $tab_lines;
666             ?>
667             </table>
668                   <input type="submit" name="f_accept" value="Accept">
669                   <input type="submit" name="f_delete" value="Delete">
670                   </form>
671                   </body>
672                   </html>
673                   <?php
674                   } while(FALSE);
675         } // else of if ($action ...
676     } // else of if ($do ...
677 }
678
679 main();
680
681 ?>