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

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

Revision 1.1, Fri Jun 3 09:28:47 2011 UTC (12 years, 9 months ago) by yason
Branch: MAIN

Initial revision

#!/usr/bin/perl
# $Id: zstatus.pl,v 1.1 2011/06/03 09:28:47 yason Exp $
use DBI;

my $DB_SERVER = "MSSQL";  # from /usr/local/etc/freetds.conf
my $DB_USER = "it_men";
my $DB_PASS = "itmen712";
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 "jpeg" && $ARGV[1] ne "proba")
{
    print "Usage:\n";
    print "zstatus <NumCard> <tiff|jpeg|proba> <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 Manager");

$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 "jpeg");
$sth = $dbh->prepare("SELECT ID,Status from upload_files WHERE NumCard=$numcard AND type_file=2") if($type eq "proba");
$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 "jpeg");
$sth = $dbh->prepare("UPDATE upload_files SET Status=$value WHERE NumCard=$numcard AND type_file=2") if($type eq "proba");
$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";