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

File: [local] / wpscripts / zstatus / zstatus.pl (download)

Revision 1.3, Wed Dec 21 09:25:22 2011 UTC (12 years, 4 months ago) by yason
Branch: MAIN
Changes since 1.2: +7 -3 lines

reenable tt and jpeg

#!/usr/bin/perl
# $Id: zstatus.pl,v 1.3 2011/12/21 09:25:22 yason Exp $
use DBI;

my $DB_SERVER = "pdc";  # from /usr/local/etc/freetds.conf
my $DB_USER = "sa";
my $DB_PASS = "aekghbynflvby";
my $dsn = "DBI:Sybase:server=$DB_SERVER";
my $dbh;
my $sth;
my $numcard;
my $type;
my $value;
my @status;

if(scalar(@ARGV) != 3 || $ARGV[1] ne "tiff" && $ARGV[1] ne "proba" && $ARGV[1] ne "tt" && $ARGV[1] ne "jpeg")
{
    print "Usage:\n";
    print "zstatus <NumCard> <tiff|proba|tt|jpeg> <value>\n";
    exit(-1);
}
$numcard = shift;
$type = shift;
$value = shift;
if($value != 0 && $value != 1)
{
    print "Status value out of range: valid values are 0 or 1\n";
    exit(-1);
}

$dbh = DBI->connect($dsn, $DB_USER, $DB_PASS) or die("Can not connect to database!");
$dbh->do("use full_print");

$sth = $dbh->prepare("SELECT ID,status from upload_files WHERE numcard=$numcard AND type_file=0") if($type eq "tiff");
$sth = $dbh->prepare("SELECT ID,status from upload_files WHERE numcard=$numcard AND type_file=1") if($type eq "proba");
$sth = $dbh->prepare("SELECT ID,status from upload_files WHERE numcard=$numcard AND type_file=2") if($type eq "tt");
$sth = $dbh->prepare("SELECT ID,status from upload_files WHERE numcard=$numcard AND type_file=3") if($type eq "jpeg");
$sth->execute( );

@status = ($sth->fetchrow_array( ));
if(!$status[0])
{
    print "$type with NumCard=$numcard not found in the database!\n";
    exit(-1);
}

$sth = $dbh->prepare("UPDATE upload_files SET status=$value WHERE numcard=$numcard AND type_file=0") if($type eq "tiff");
$sth = $dbh->prepare("UPDATE upload_files SET status=$value WHERE numcard=$numcard AND type_file=1") if($type eq "proba");
$sth = $dbh->prepare("UPDATE upload_files SET status=$value WHERE numcard=$numcard AND type_file=2") if($type eq "tt");
$sth = $dbh->prepare("UPDATE upload_files SET status=$value WHERE numcard=$numcard AND type_file=3") if($type eq "jpeg");
$sth->execute( ) or die("Can not execute SQL");
print "status changed from $status[1] " . ($status[1] == 0 ? "(NOT SENT)" : "(SENT)") . " to $value " . ($value == 1 ? "(SENT)" : "(NOT SENT)") . "\n";