users importer from file to database
[brisk.git] / web / admin.php
1 <?php
2   /*
3    *  brisk - admin.php
4    *
5    *  Copyright (C) 2006-2011 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 require_once("Obj/brisk.phh");
26 require_once("Obj/dbase_pgsql.phh");
27
28 $cont = "";
29
30 function main()
31 {
32     GLOBAL $cont, $G_alarm_passwd, $F_pass_private, $F_ACT, $F_filename;
33
34     if ($F_ACT == "append") {
35         do {
36             if ($F_pass_private != $G_alarm_passwd) {
37                 $cont .= sprintf("Wrong password, operation aborted.<br>\n");
38                 break;
39             }
40             $cont .= sprintf("FILENAME: %s<br>\n", $F_filename); 
41             if (($olddb = new LoginDBOld($F_filename)) == FALSE) {
42                 $cont .= sprintf("Loading failed.<br>\n"); 
43                 break;
44             }
45             $newdb = new LoginDB();
46             if ($newdb->addusers_from_olddb($olddb, $cont) == FALSE) {
47                 $cont .= sprintf("Insert failed.<br>\n"); 
48             }
49             $cont .= sprintf("Item number: %d<br>\n", $olddb->count());
50         } while (0);
51     }
52 }
53
54 main();
55
56 ?>
57 <html>
58 <body>
59 <?php
60 echo "$cont";
61 ?>
62 <b>Append users from a file</b><br>
63 <form accept-charset="utf-8" method="post" action="<?php echo $PHP_SELF;?>" onsubmit="return j_login_manager(this);">
64       <input type="hidden" name="F_ACT" value="append">
65       <table><tr><td>Admin Password:</td>
66       <td><input name="F_pass_private" type="password" value=""></td></tr>
67       <tr><td>Filename:</td>
68       <td><input type="text" name="F_filename"></td></tr>
69       <tr><td colspan=2><input type="submit" value="append users"></td></tr>
70       </table>
71 </form>
72 </body>
73 </html>