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