From 97323fb5f40779cf38a96325ece5efb16812870d Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@spreadspace.org>
Date: Wed, 18 May 2016 15:58:29 +0200
Subject: rhrd-show can now edit show info


diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index 1172acd..1286a46 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -1492,6 +1492,24 @@ sub create_show_dropbox
   return ($cnt, 'OK', 'success');
 }
 
+sub update_show_dropbox
+{
+  my ($ctx, $show_id, $rhythm, $dow, $starttime, $len) = @_;
+  my $param = join(';', ('S', $rhythm, $dow, $starttime, $len));
+
+  my $sql = qq{update DROPBOXES set SET_USER_DEFINED = ? where TO_CART = ?};
+
+  my $sth = $ctx->{'dbh'}->prepare($sql)
+    or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+  my $cnt = $sth->execute($param, $show_id)
+    or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+  $sth->finish();
+
+  return ($cnt, 'OK', 'success');
+}
+
 sub remove_show
 {
   my ($ctx, $showid) = @_;
diff --git a/utils/rhrd-show b/utils/rhrd-show
index cab6ead..731b627 100755
--- a/utils/rhrd-show
+++ b/utils/rhrd-show
@@ -21,7 +21,6 @@
 #
 
 use strict;
-use lib "../lib/";
 use RHRD::rddb;
 use RHRD::utils;
 use Date::Calc;
@@ -180,9 +179,10 @@ sub add
   return 0;
 }
 
+
 sub edit__check_arguments
 {
-  my ($showid, $title, $rhythm, $dow, $starttime, $len) = @_;
+  my ($show_id, $title, $rhythm, $dow, $starttime, $len) = @_;
 
   my ($result, $err, $hint) = RHRD::utils::dropbox_param_rhythm_ok($rhythm);
   unless($result) {
@@ -213,16 +213,26 @@ sub edit__check_arguments
 
 sub edit
 {
-  my ($ctx, $showid, $title, $rhythm, $dow, $starttime, $len) = @_;
+  my ($ctx, $show_id, $title, $rhythm, $dow, $starttime, $len) = @_;
 
-  my $ret = edit__check_arguments($showid, $title, $rhythm, $dow, $starttime, $len);
+  my $ret = edit__check_arguments($show_id, $title, $rhythm, $dow, $starttime, $len);
   if($ret) {
     return $ret;
   }
+  ($dow, undef, undef) = RHRD::utils::cmdline_dow($dow);
 
-  print " not yet implemented!!\n";
+  my ($result, $status, $errorstring) = RHRD::rddb::update_show_dropbox($ctx, $show_id, $rhythm, $dow, $starttime, $len);
+  unless(defined $result) {
+    print STDERR $status . ": " . $errorstring . "\n";
+    return 1;
+  }
+  if ($result != 1) {
+    print "show '" . $show_id ."' does not exist.\n";
+    return 1;
+  }
 
-  return 1;
+  print "show '" . $show_id . "' successfully changed!\n";
+  return 0;
 }
 
 sub remove
-- 
cgit v0.10.2