[BACK]Return to zstatus.pl CVS log [TXT][DIR] Up to [local] / wpscripts / zstatus

Annotation of wpscripts/zstatus/zstatus.pl, Revision 1.3

1.1       yason       1: #!/usr/bin/perl
1.3     ! yason       2: # $Id: zstatus.pl,v 1.2 2011/07/20 07:42:05 yason Exp $
1.1       yason       3: use DBI;
                      4:
1.2       yason       5: my $DB_SERVER = "pdc";  # from /usr/local/etc/freetds.conf
                      6: my $DB_USER = "sa";
                      7: my $DB_PASS = "aekghbynflvby";
1.1       yason       8: my $dsn = "DBI:Sybase:server=$DB_SERVER";
                      9: my $dbh;
                     10: my $sth;
                     11: my $numcard;
                     12: my $type;
                     13: my $value;
                     14: my @status;
                     15:
1.3     ! yason      16: if(scalar(@ARGV) != 3 || $ARGV[1] ne "tiff" && $ARGV[1] ne "proba" && $ARGV[1] ne "tt" && $ARGV[1] ne "jpeg")
1.1       yason      17: {
                     18:     print "Usage:\n";
1.3     ! yason      19:     print "zstatus <NumCard> <tiff|proba|tt|jpeg> <value>\n";
1.1       yason      20:     exit(-1);
                     21: }
                     22: $numcard = shift;
                     23: $type = shift;
                     24: $value = shift;
                     25: if($value != 0 && $value != 1)
                     26: {
                     27:     print "Status value out of range: valid values are 0 or 1\n";
                     28:     exit(-1);
                     29: }
                     30:
                     31: $dbh = DBI->connect($dsn, $DB_USER, $DB_PASS) or die("Can not connect to database!");
1.2       yason      32: $dbh->do("use full_print");
1.1       yason      33:
1.2       yason      34: $sth = $dbh->prepare("SELECT ID,status from upload_files WHERE numcard=$numcard AND type_file=0") if($type eq "tiff");
                     35: $sth = $dbh->prepare("SELECT ID,status from upload_files WHERE numcard=$numcard AND type_file=1") if($type eq "proba");
1.3     ! yason      36: $sth = $dbh->prepare("SELECT ID,status from upload_files WHERE numcard=$numcard AND type_file=2") if($type eq "tt");
        !            37: $sth = $dbh->prepare("SELECT ID,status from upload_files WHERE numcard=$numcard AND type_file=3") if($type eq "jpeg");
1.1       yason      38: $sth->execute( );
                     39:
                     40: @status = ($sth->fetchrow_array( ));
                     41: if(!$status[0])
                     42: {
                     43:     print "$type with NumCard=$numcard not found in the database!\n";
                     44:     exit(-1);
                     45: }
                     46:
1.2       yason      47: $sth = $dbh->prepare("UPDATE upload_files SET status=$value WHERE numcard=$numcard AND type_file=0") if($type eq "tiff");
                     48: $sth = $dbh->prepare("UPDATE upload_files SET status=$value WHERE numcard=$numcard AND type_file=1") if($type eq "proba");
1.3     ! yason      49: $sth = $dbh->prepare("UPDATE upload_files SET status=$value WHERE numcard=$numcard AND type_file=2") if($type eq "tt");
        !            50: $sth = $dbh->prepare("UPDATE upload_files SET status=$value WHERE numcard=$numcard AND type_file=3") if($type eq "jpeg");
1.1       yason      51: $sth->execute( ) or die("Can not execute SQL");
                     52: print "status changed from $status[1] " . ($status[1] == 0 ? "(NOT SENT)" : "(SENT)") . " to $value " . ($value == 1 ? "(SENT)" : "(NOT SENT)") . "\n";
                     53:
                     54:

CVSweb