summaryrefslogtreecommitdiff
path: root/rhimport
diff options
context:
space:
mode:
Diffstat (limited to 'rhimport')
-rwxr-xr-xrhimport75
1 files changed, 57 insertions, 18 deletions
diff --git a/rhimport b/rhimport
index c8cfd47..05fc757 100755
--- a/rhimport
+++ b/rhimport
@@ -38,7 +38,7 @@ my $DB = "rivendell";
my $HELP = 0;
my $FILE = "";
my $POOL = 0;
-my $EMPTYCARTS = 1;
+my $EMPTYCARTS = 0;
my $DROPBOX = "";
my $LISTALLOWED = 0;
@@ -69,18 +69,7 @@ my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
my $dbh = DBI->connect("DBI:mysql:$DB:$DBHOST","$DBUSER","$DBPW") or die "Database Error: $DBI::errstr";
-my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.PATH from USER_PERMS, DROPBOXES where USER_PERMS.USER_NAME='$user' and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME;};
-my $sth = $dbh->prepare($sql);
-$sth->execute();
-my @allowed_dbs;
-while(my ($group, $path) = $sth->fetchrow_array()) {
- $path =~ s/\/\*$//;
- my $perm = {};
- $perm->{'GROUP'} = $group;
- $perm->{'PATH'} = $path;
- push @allowed_dbs, $perm;
-}
-$sth->finish();
+my @allowed_dbs = rhimport::get_dropboxes($dbh, $user);
if($LISTALLOWED) {
for my $href ( @allowed_dbs ) {
@@ -166,12 +155,17 @@ sub start_import_gui()
$filechooser->unselect_all;
my $co_dropbox = $guixml->get_widget('co_dropbox');
- my $dropbox = $co_dropbox->get_active_text;
+ my $dropbox = $allowed_dbs[$co_dropbox->get_active]->{'PATH'};
+ my $group = $allowed_dbs[$co_dropbox->get_active]->{'GROUP'};
$l_status->set_label("importiere von $file");
my $ret;
if($POOL) {
+ my $cb_clear_carts = $guixml->get_widget('cb_clear_carts');
+ if($cb_clear_carts->get_active) {
+ rhimport::empty_carts($dbh, $group);
+ }
$ret = rhimport::import_playlist($file, $dropbox);
} else {
$ret = rhimport::import_file($file, $dropbox);
@@ -180,7 +174,29 @@ sub start_import_gui()
return $ret;
}
-if(!$FILE && !$DROPBOX) {
+sub show_used_carts_gui()
+{
+ if(!$guixml) {
+ print STDERR "no GUI definition found!\n";
+ exit 0;
+ }
+
+ my $co_dropbox = $guixml->get_widget('co_dropbox');
+ my $group = $allowed_dbs[$co_dropbox->get_active]->{'GROUP'};
+
+
+ my $l_status = $guixml->get_widget('l_status');
+ my ($low_cart, $high_cart) = rhimport::get_cart_range($dbh, $group);
+ $l_status->set_label("Carts: $low_cart - $high_cart");
+
+
+# my $usedcartswin = $guixml->get_widget('usedcartswin');
+# $usedcartswin or die "can't find Widget";
+# $usedcartswin->resize(640,480);
+# $usedcartswin->show;
+}
+
+if(!$FILE || !$DROPBOX) {
Gtk2->init;
$guixml = Gtk2::GladeXML->new('rhimport.glade');
@@ -188,17 +204,24 @@ if(!$FILE && !$DROPBOX) {
require gui_callbacks;
$guixml->signal_autoconnect_from_package('gui_callbacks');
- my $model = Gtk2::ListStore->new('Glib::String');
+ my $model = Gtk2::ListStore->new('Glib::String', 'Glib::String', 'Glib::String');
for my $href ( @allowed_dbs ) {
- $model->set ($model->append, 0, $href->{'PATH'});
+ $model->set ($model->append, 0, $href->{'PATH'}, 1, $href->{'GROUP'}, 2, $href->{'NAME'});
}
my $co_dropbox = $guixml->get_widget('co_dropbox');
$co_dropbox->set_model($model);
my $renderer = Gtk2::CellRendererText->new;
$co_dropbox->pack_start($renderer, 1);
- $co_dropbox->add_attribute($renderer, text => 0);
+ $co_dropbox->add_attribute($renderer, text => 2);
$co_dropbox->set_active(0);
+ my $cb_clear_carts = $guixml->get_widget('cb_clear_carts');
+ if($EMPTYCARTS) {
+ $cb_clear_carts->set_active(1);
+ } else {
+ $cb_clear_carts->set_active(0);
+ }
+
if($POOL) {
set_mode_playlist_gui();
} else {
@@ -225,8 +248,24 @@ if($POOL) {
print "will import $FILE, with user $user\n\n";
}
+my $group = '';
+for my $href (@allowed_dbs) {
+ if($href->{'PATH'} eq $DROPBOX) {
+ $group = $href->{'GROUP'};
+ }
+}
+
+if($group eq '') {
+ print "Dropbox not found or not allowed";
+ exit 1
+}
+
my $ret;
if($POOL) {
+ if($EMPTYCARTS) {
+ rhimport::empty_carts($dbh, $group);
+ }
+
$ret = rhimport::import_playlist($FILE, $DROPBOX);
} else {
$ret = rhimport::import_file($FILE, $DROPBOX);