Google Answers Logo
View Question
 
Q: simple image based CGI Script needed for stock control ( No Answer,   4 Comments )
Question  
Subject: simple image based CGI Script needed for stock control
Category: Computers > Programming
Asked by: bvandyk-ga
List Price: $25.00
Posted: 12 Jul 2006 04:10 PDT
Expires: 11 Aug 2006 04:10 PDT
Question ID: 745546
I need a very simple CGI script written that will act as a simple
stock management system for a website I run. It will be used multiple
times per webpage, with the following syntax:

<img src="cgi-bin/stock.cgi?model=nk6210">

Defined within the CGI script will be the following list of phone models:
nk3210 = 0 <meaning that the phone is OUT of stock>
nk6210 = 1 <meaning that the phone is IN stock>
...

If the requested item is in stock the "image 1" will be displayed, if
the item is out of stock then "image 2" will be returned, if the
requested phone was not found in the list then "image 3" will be
returned.

I can insert the binary for the images later if a marker is put in the
code for this.

The code should be very fast and efficient as the script maybe called
30 times on one html page.

Please ask me if any clarification is needed.

Request for Question Clarification by eiffel-ga on 12 Jul 2006 04:31 PDT
What scripting language are you using: Python, PHP, Ruby etc?

Clarification of Question by bvandyk-ga on 12 Jul 2006 04:52 PDT
I would prefer perl as I know a bit of perl already.

Request for Question Clarification by eiffel-ga on 12 Jul 2006 14:06 PDT
I'll leave this question for other researchers, as I don't speak perl fluently.
Answer  
There is no answer at this time.

Comments  
Subject: Re: simple image based CGI Script needed for stock control
From: bozo99-ga on 12 Jul 2006 16:14 PDT
 
Defined within the CGI script  ...

Surely stock levels are better defined in some readily changeable form
of data and the CGI will remain unchanged for the long term.
Subject: Re: simple image based CGI Script needed for stock control
From: bozo99-ga on 13 Jul 2006 02:10 PDT
 
#!/usr/bin/perl

print "Content-Type: image/png\n\n";
$got="unknown";
if (defined($ENV{QUERY_STRING})) {
    if ($ENV{QUERY_STRING} =~ /^model=(\w+)$/) {
        $sku=$1;
    }
}

$got="yes" if ("nk6210" eq $sku);
$got="no"  if ("nk6211" eq $sku);

if ("yes" eq $got) {
    open(IN, "</SOME-PATHNAME/hand.up.png") or die();
    undef $/;
    $_=<IN>;
    close(IN);
    printf("%s", $_);
    exit(0);
}
if ("no" eq $got) {
    open(IN, "</SOME-PATHNAME/broken.png") or die();
    undef $/;
    $_=<IN>;
    close(IN);
    printf("%s", $_);
    exit(0);
}

    open(IN, "</SOME-PATHNAME/bomb.png") or die();
    undef $/;
    $_=<IN>;
    close(IN);
    printf("%s", $_);
    exit(0);
Subject: Re: simple image based CGI Script needed for stock control
From: bozo99-ga on 13 Jul 2006 02:11 PDT
 
Would it be better to use the GCI to write the page containing these links?
This should reduce the number of CGI executions.
Subject: Re: simple image based CGI Script needed for stock control
From: bozo99-ga on 13 Jul 2006 02:19 PDT
 
In fact with multiple links on the page and only 3 outcomes you'll end
up serving the same image repeatedly instaed of using the cache.  I
definitely side with writing the HTML page dynamically intead of the
images.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy