- #=====================================================================
- # LedgerSMB
- # Small Medium Business Accounting software
- # http://www.ledgersmb.org/
- #
- #
- # Copyright (C) 2006
- # This work contains copyrighted information from a number of sources all used
- # with permission.
- #
- # This file contains source code included with or based on SQL-Ledger which
- # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
- # under the GNU General Public License version 2 or, at your option, any later
- # version. For a full list including contact information of contributors,
- # maintainers, and copyright holders, see the CONTRIBUTORS file.
- #
- # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
- # Copyright (c) 2000
- #
- # Author: DWS Systems Inc.
- # Web: http://www.sql-ledger.org
- #
- # Contributors:
- #
- #
- #======================================================================
- #
- # This file has undergone whitespace cleanup.
- #
- #======================================================================
- #
- # setup module
- # add/edit/delete users
- #
- #======================================================================
- use LedgerSMB::Form;
- use LedgerSMB::Locale;
- use LedgerSMB::User;
- use LedgerSMB::Session;
- $form = new Form;
- $locale = LedgerSMB::Locale->get_handle( ${LedgerSMB::Sysconfig::language} )
- or
- $form->error( __FILE__ . ':' . __LINE__ . ': ' . "Locale not loaded: $!\n" );
- $locale->encoding('UTF-8');
- $form->{charset} = 'UTF-8';
- eval { require DBI; };
- $form->error(
- __FILE__ . ':' . __LINE__ . ': ' . $locale->text('DBI not installed!') )
- if ($@);
- $form->{stylesheet} = "ledgersmb.css";
- $form->{favicon} = "favicon.ico";
- $form->{timeout} = 600;
- require "bin/pw.pl";
- # customization
- if ( -f "bin/custom/$form->{script}" ) {
- eval { require "bin/custom/$form->{script}"; };
- $form->error( __FILE__ . ':' . __LINE__ . ': ' . $@ ) if ($@);
- }
- if ( $form->{action} ) {
- &check_password unless $form->{action} eq 'logout';
- &{ $form->{action} };
- }
- else {
- # if there are no drivers bail out
- $form->error( __FILE__ . ':' . __LINE__ . ': '
- . $locale->text('No Database Drivers available!') )
- unless ( LedgerSMB::User->dbdrivers );
- $root = LedgerSMB::User->new('admin');
- &adminlogin;
- }
- 1;
- # end
- sub adminlogin {
- my ($errorMessage) = @_;
- $form->{title} =
- qq|LedgerSMB $form->{version} | . $locale->text('Administration');
- $myheaderadd = qq|
- <script language="JavaScript" type="text/javascript">
- <!--
- function sf(){
- document.admin.password.focus();
- }
- // End -->
- </script>
- |;
- $form->header( undef, $myheaderadd );
- print qq|
- <body class="admin" onload="sf()">
- <div align="center">
- <a href="http://www.ledgersmb.org/"><img src="images/ledgersmb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
- <h1 class="login">|
- . $locale->text('Version')
- . qq| $form->{version} <br />|
- . $locale->text('Administration')
- . qq|</h1>
- <form method="post" action="admin.pl" name="admin">
- <table>
- <tr>
- <th>| . $locale->text('Password') . qq|</th>
- <td><input type="password" name="password" /></td>
- <td><button type="submit" class="submit" name="action" value="login">|
- . $locale->text('Login')
- . qq|</button></td>
- </tr>
- </table>
- <input type="hidden" name="action" value="login" />
- <input type="hidden" name="path" value="$form->{path}" />
- </form>
- |;
- if ($errorMessage) {
- print
- qq|<p><span style="font-weight:bold; color:red;">$errorMessage</span></p><br />|;
- }
- print qq|
- <br /><br />
- <p><a href="login.pl"
- >| . $locale->text("Application Login") . qq|</a></p>
- <br /><br />
- <a style="font-size: 0.8em;" href="http://www.ledgersmb.org/">|
- . $locale->text('LedgerSMB website') . qq|</a>
- </div>
- </body>
- </html>
- |;
- }
- sub login {
- &list_users;
- }
- sub logout {
- $form->{login} = 'admin';
- $form->{callback} = "admin.pl?action=adminlogin";
- Session::session_destroy($form);
- $form->redirect( $locale->text('You are logged out') );
- }
- sub add_user {
- $form->{title} =
- "LedgerSMB "
- . $locale->text('Accounting') . " "
- . $locale->text('Administration') . " / "
- . $locale->text('Add User');
- if ( -f "css/ledgersmb.css" ) {
- $myconfig->{stylesheet} = "ledgersmb.css";
- }
- $myconfig->{vclimit} = 1000;
- $myconfig->{menuwidth} = 155;
- $myconfig->{timeout} = 3600;
- &form_header;
- &form_footer;
- }
- sub edit {
- $form->{title} =
- "LedgerSMB "
- . $locale->text('Accounting') . " "
- . $locale->text('Administration') . " / "
- . $locale->text('Edit User');
- $form->{edit} = 1;
- &form_header;
- &form_footer;
- }
- sub form_footer {
- if ( $form->{edit} ) {
- $delete =
- qq|<button type="submit" class="submit" name="action" value="delete">|
- . $locale->text('Delete')
- . qq|</button>
- <input type="hidden" name="edit" value="1" />|;
- }
- print qq|
- <input name="callback" type="hidden" value="$form->{script}?action=list_users&path=$form->{path}" />
- <input type="hidden" name="path" value="$form->{path}" />
- <button type="submit" class="submit" name="action" value="save">|
- . $locale->text('Save')
- . qq|</button>
- $delete
- </form>
- </body>
- </html>
- |;
- }
- sub list_users {
- # use the central database handle
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
- my $fetchMembers = $dbh->selectall_arrayref(
- "SELECT uc.name, uc.company, uc.templates,
- uc.dbuser, uc.dbdriver, uc.dbname,
- uc.dbhost, u.username
- FROM users as u, users_conf as uc
- WHERE u.id = uc.id
- AND u.id > 1
- ORDER BY u.username;", { Slice => {} }
- );
- my @memberArray = ();
- my @member = ();
- foreach my $memberArray (@$fetchMembers) {
- $member{ $memberArray->{username} } = $memberArray;
- }
- # type=submit $locale->text('Pg Database Administration')
- # type=submit $locale->text('PgPP Database Administration')
- foreach $item ( LedgerSMB::User->dbdrivers ) {
- $dbdrivers .=
- qq|<button name="action" type="submit" class="submit" value="|
- . ( lc $item )
- . '_database_administration">'
- . $locale->text("$item Database Administration")
- . qq|</button>|;
- }
- $column_header{login} = qq|<th>| . $locale->text('Login') . qq|</th>|;
- $column_header{name} = qq|<th>| . $locale->text('Name') . qq|</th>|;
- $column_header{company} = qq|<th>| . $locale->text('Company') . qq|</th>|;
- $column_header{dbdriver} = qq|<th>| . $locale->text('Driver') . qq|</th>|;
- $column_header{dbhost} = qq|<th>| . $locale->text('Host') . qq|</th>|;
- $column_header{dataset} = qq|<th>| . $locale->text('Dataset') . qq|</th>|;
- $column_header{templates} =
- qq|<th>| . $locale->text('Templates') . qq|</th>|;
- @column_index = qw(login name company dbdriver dbhost dataset templates);
- $form->{title} =
- "LedgerSMB "
- . $locale->text('Accounting') . " "
- . $locale->text('Administration');
- $form->{login} = "admin";
- $form->header;
- print qq|
- <body class="admin">
- <form method="post" action="$form->{script}">
- <table width="100%">
- <tr class="listheading">
- <th>$form->{title}</th>
- </tr>
- <tr size="5"></tr>
- <tr>
- <td>
- <table width="100%">
- <tr class="listheading">|;
- for (@column_index) { print "$column_header{$_}\n" }
- print qq| </tr>|;
- foreach $key ( sort keys %member ) {
- $href = "$script?action=edit&login=$key&path=$form->{path}";
- $href =~ s/ /%20/g;
- $member{$key}{templates} =~ s/^${LedgerSMB::Sysconfig::templates}\///;
- $column_data{login} = qq|<td><a href="$href">$key</a></td>|;
- $column_data{name} = qq|<td>$member{$key}{name}</td>|;
- $column_data{company} = qq|<td>$member{$key}{company}</td>|;
- $column_data{dbdriver} = qq|<td>$member{$key}{dbdriver}</td>|;
- $column_data{dbhost} = qq|<td>$member{$key}{dbhost}</td>|;
- $column_data{dataset} = qq|<td>$member{$key}{dbname}</td>|;
- $column_data{templates} = qq|<td>$member{$key}{templates}</td>|;
- $i++;
- $i %= 2;
- print qq| <tr class="listrow$i">|;
- for (@column_index) { print "$column_data{$_}\n"; }
- print qq| </tr>|;
- }
- print qq| </table>
- </td>
- </tr>
- <tr>
- <td><hr size="3" noshade /></td>
- </tr>
- </table>
- <input type="hidden" name="path" value="$form->{path}" />
- <br />
- <button type="submit" class="submit" name="action" value="add_user">|
- . $locale->text('Add User')
- . qq|</button>
- <button type="submit" class="submit" name="action" value="change_admin_password">|
- . $locale->text('Change Admin Password')
- . qq|</button>
- $dbdrivers
- <button type="submit" class="submit" name="action" value="logout">|
- . $locale->text('Logout')
- . qq|</button>
- </form>
- | . $locale->text('Click on login name to edit!') . qq|
- <br />
- |
- . $locale->text(
- 'To add a user to a group edit a name, change the login name and save. A new user with the same variables will then be saved under the new login name.'
- )
- . qq|
- </body>
- </html>|;
- }
- sub form_header {
- # if there is a login, get user
- if ( $form->{login} ) {
- # get user
- %{$myconfig} = %{ LedgerSMB::User->fetch_config( $form->{login} ) };
- for (qw(company address signature)) {
- $myconfig->{$_} = $form->quote( $myconfig->{$_} );
- }
- for (qw(address signature)) { $myconfig->{$_} =~ s/\\n/\n/g }
- # strip basedir from templates directory
- $myconfig->{templates} =~ s/^${LedgerSMB::Sysconfig::templates}\///;
- }
- foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd))
- {
- $dateformat .=
- ( $item eq $myconfig->{dateformat} )
- ? "<option selected>$item</option>\n"
- : "<option>$item</option>\n";
- }
- my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);
|