[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[5447] trunk



Revision: 5447
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5447&view=rev
Author:   einhverfr
Date:     2012-12-31 12:10:10 +0000 (Mon, 31 Dec 2012)
Log Message:
-----------
DB listing now supported

Modified Paths:
--------------
    trunk/LedgerSMB/Database.pm
    trunk/LedgerSMB/Scripts/setup.pm

Added Paths:
-----------
    trunk/UI/setup/list_databases.html

Modified: trunk/LedgerSMB/Database.pm
===================================================================
--- trunk/LedgerSMB/Database.pm	2012-12-31 11:03:40 UTC (rev 5446)
+++ trunk/LedgerSMB/Database.pm	2012-12-31 12:10:10 UTC (rev 5447)
@@ -413,11 +413,17 @@
         "dbi:Pg:dbname=postgres", 
          "$creds->{login}", "$creds->{password}", { AutoCommit => 0 }
     );
-    my @results = $dbh->selectall_array(
+    my $resultref = $dbh->selectall_arrayref(
         "SELECT datname FROM pg_database 
           WHERE datname <> 'postgres' AND datname NOT LIKE 'template%'"
     );
+    my @results;
+    for my $r (@$resultref){
+        push @results, values @$r;
+    }
+
     $dbh->disconnect;
+    use Data::Dumper;
     return @results;
 }
 

Modified: trunk/LedgerSMB/Scripts/setup.pm
===================================================================
--- trunk/LedgerSMB/Scripts/setup.pm	2012-12-31 11:03:40 UTC (rev 5446)
+++ trunk/LedgerSMB/Scripts/setup.pm	2012-12-31 12:10:10 UTC (rev 5447)
@@ -58,7 +58,8 @@
     $logger->trace("\$request=$request \$request->{dbh}=$request->{dbh} request=".Data::Dumper::Dumper(\$request));
     my $creds = LedgerSMB::Auth::get_credentials('setup');
     if (!$request->{database}){
-        $request->error($request->{_locale}->text('No database specified'));
+        list_databases($request);
+        return;
     }
     my $database = LedgerSMB::Database->new(
                {username => $creds->{login},
@@ -150,6 +151,32 @@
 
 }
 
+=item list_databases
+Lists all databases as hyperlinks to continue operations.
+
+=cut
+
+sub list_databases {
+    my ($request) = @_;
+    my $creds = LedgerSMB::Auth::get_credentials('setup');
+    my $database = LedgerSMB::Database->new(
+               {username => $creds->{login},
+            company_name => $request->{database},
+                password => $creds->{password}}
+    );
+    my @results = $database->list;
+    $request->{dbs} = [];
+    for my $r (@results){
+       push @{$request->{dbs}}, {row_id => $r, db => $r };
+    }
+    my $template = LedgerSMB::Template->new(
+            path => 'UI/setup',
+            template => 'list_databases',
+	    format => 'HTML',
+    );
+    $template->render($request);
+}
+
 =item backup_db
 
 Backs up a full db

Added: trunk/UI/setup/list_databases.html
===================================================================
--- trunk/UI/setup/list_databases.html	                        (rev 0)
+++ trunk/UI/setup/list_databases.html	2012-12-31 12:10:10 UTC (rev 5447)
@@ -0,0 +1,17 @@
+<?lsmb INCLUDE "ui-header.html"
+stylesheet="ledgersmb.css"
+include_stylesheet=["UI/setup/stylesheet.css"];
+       PROCESS "elements.html";
+       PROCESS "dynatable.html"; ?>
+<body>
+<div class="listtop"><?lsmb text('Available Databases') ?></div>
+<?lsmb 
+    INCLUDE dynatable
+            columns = [{col_id = 'db', 
+                       name = text('Database'), 
+                       type = 'href'
+                  href_base = 'setup.pl?action=login&database='}]
+            tbody = {rows = dbs}
+              id = 'db_list' ?>
+</body>
+</html>

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.