import of sql-ledger 2.0.8
[freeside.git] / sql-ledger / bin / mozilla / login.pl
1 ######################################################################
2 # SQL-Ledger Accounting
3 # Copyright (c) 1998-2002
4 #
5 #  Author: Dieter Simader
6 #   Email: dsimader@sql-ledger.org
7 #     Web: http://www.sql-ledger.org
8 #
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,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #######################################################################
23
24
25 use DBI;
26 use SL::User;
27 use SL::Form;
28
29
30 $form = new Form;
31
32 $locale = new Locale $language, "login";
33
34 # customization
35 if (-f "$form->{path}/custom_$form->{script}") {
36   eval { require "$form->{path}/custom_$form->{script}"; };
37   $form->error($@) if ($@);
38 }
39
40 # per login customization
41 if (-f "$form->{path}/$form->{login}_$form->{script}") {
42   eval { require "$form->{path}/$form->{login}_$form->{script}"; };
43   $form->error($@) if ($@);
44 }
45
46 # window title bar, user info
47 $form->{titlebar} = "SQL-Ledger ".$locale->text('Version'). " $form->{version}";
48
49 if ($form->{action}) {
50   $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
51   &{ $locale->findsub($form->{action}) };
52 } else {
53   &login_screen;
54 }
55
56
57 1;
58
59
60 sub login_screen {
61   
62   if (-f "css/sql-ledger.css") {
63     $form->{stylesheet} = "sql-ledger.css";
64   }
65
66   $form->header;
67
68   print qq|
69 <body class=login>
70
71 <pre>
72
73 </pre>
74
75 <center>
76 <table class=login border=3 cellpadding=20>
77   <tr>
78     <td class=login align=center><a href="http://www.sql-ledger.org" target=_top><img src=sql-ledger.png border=0></a>
79 <h1 class=login align=center>|.$locale->text('Version').qq| $form->{version}
80 </h1>
81
82 <p>
83
84 <form method=post action=$form->{script}>
85
86       <table width=100%>
87         <tr>
88           <td align=center>
89             <table>
90               <tr>
91                 <th align=right>|.$locale->text('Name').qq|</th>
92                 <td><input class=login name=login size=30></td>
93               </tr> 
94               <tr>
95                 <th align=right>|.$locale->text('Password').qq|</th>
96                 <td><input class=login type=password name=password size=30></td>
97               </tr>
98               <input type=hidden name=path value=$form->{path}>
99             </table>
100
101             <br>
102             <input type=submit name=action value="|.$locale->text('Login').qq|">
103
104           </td>
105         </tr>
106       </table>
107
108 </form>
109
110     </td>
111   </tr>
112 </table>
113   
114 </body>
115 </html>
116 |;
117
118 }
119
120
121 sub login {
122
123   $form->error($locale->text('You did not enter a name!')) unless ($form->{login});
124
125   $user = new User $memberfile, $form->{login};
126
127   # if we get an error back, bale out
128   if (($errno = $user->login(\%$form, $userspath)) <= -1) {
129     $errno *= -1;
130     $err[1] = $locale->text('Incorrect Password!');
131     $err[2] = $locale->text('Incorrect Dataset version!');
132     $err[3] = qq|$form->{login} |.$locale->text('is not a member!');
133     
134     $form->error($err[$errno]);
135   }
136   
137   # made it this far, execute the menu
138   $argv = "login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display";
139
140   exec ("perl", "menu.pl", $argv);
141
142 }
143
144
145
146 sub logout {
147
148   unlink "$userspath/$form->{login}.conf";
149   
150   # remove the callback to display the message
151   $form->{callback} = "login.pl?path=$form->{path}&action=&login=";
152   $form->redirect($locale->text('You are logged out!'));
153
154 }
155
156
157     
158 sub company_logo {
159   
160   require "$userspath/$form->{login}.conf";
161   $locale = new Locale $myconfig{countrycode}, "login" unless ($language eq $myconfig{countrycode});
162
163   $myconfig{address} =~ s/\\n/<br>/g;
164   $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
165
166   map { $form->{$_} = $myconfig{$_} } qw(charset stylesheet);
167   
168   $form->{title} = $locale->text('About');
169   
170  
171   # create the logo screen
172   $form->header unless $form->{noheader};
173
174   print qq|
175 <body>
176
177 <pre>
178
179 </pre>
180 <center>
181 <a href="http://www.sql-ledger.org" target=_top><img src=sql-ledger.png border=0></a>
182 <h1 class=login>|.$locale->text('Version').qq| $form->{version}</h1>
183
184 <p>
185 |.$locale->text('Licensed to').qq|
186 <p>
187 <b>
188 $myconfig{company}
189 <br>$myconfig{address}
190 </b>
191
192 <p>
193 <table>
194   <tr>
195     <th align=right>|.$locale->text('User').qq|</th>
196     <td>$myconfig{name}</td>
197   </tr>
198   <tr>
199     <th align=right>|.$locale->text('Dataset').qq|</th>
200     <td>$myconfig{dbname}</td>
201   </tr>
202   <tr>
203     <th align=right>|.$locale->text('Database Host').qq|</th>
204     <td>$myconfig{dbhost}</td>
205   </tr>
206 </table>
207
208 </center>
209
210 </body>
211 </html>
212 |;
213
214 }
215
216
217