CGI Script - Modify image handler to include hyperlink

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #16
    Originally posted by KevinADC
    PS: I accept donations.
    Aaaaalms for the poor......... ***ding - ding***..... Aaaaaalms for the poor.....

    Please sir, could you spare a pence or two to pay my 'lectric bill? This coding stuff does use power ya know.

    ;-|)
    Last edited by numberwhun; Jul 26 '07, 06:04 PM. Reason: spelling fix

    Comment

    • smarsh
      New Member
      • Jul 2007
      • 18

      #17
      Great! This time I got it to run on the 1st try... Thanks!

      Donation/compensation... you say tomato I say tomaaato... that's cool.
      Give me some details and I'll work on it.

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #18
        Originally posted by smarsh
        Great! This time I got it to run on the 1st try... Thanks!

        Donation/compensation... you say tomato I say tomaaato... that's cool.
        Give me some details and I'll work on it.

        Glad you go it working. I did spot an error in the last line of the code:

        Code:
        print qq{<a href="../$page title="$alt"><img src="../images/$image" alt="$alt"></a>};
        there should be a double-quote after $page:

        Code:
        print qq{<a href="../$page" title="$alt"><img src="../images/$image" alt="$alt"></a>};
        check your PM's.

        Comment

        • smarsh
          New Member
          • Jul 2007
          • 18

          #19
          All of a sudden (I think) I'm getting wacky results. I thought I tested the script during open and closed times, yet now nothing makes sense. The server is GMT-6 . I want the open time for Monday to be between 10 and 11 AM, so I set it that way. The only way I can get it to work and show the "open" graphic is by setting it to 6. The close time doesn't seem to work right at all - like setting it to 7 for 11AM (because of the 6 being 10???) it still stays open after 11.

          Any thoughts?

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #20
            post your current code.

            Comment

            • smarsh
              New Member
              • Jul 2007
              • 18

              #21
              This is the current script that as far as I know, I have only "modified" by setting the times for each day of the week. Monday should be [10,11] as well, but I changed that to [6,11] to get the open time to work at the actual 11:00AM. The server checks out to be running the correct time in the central time zone.

              I'm lost...

              Thanks.


              [CODE=perl]#!/usr/bin/perl

              use CGI::Carp qw/fatalsToBrowser/;

              use strict;
              use warnings;

              # path to folder where images are
              # assumes an image named open.gif and closed.gif
              my $path = '/home/fireplug/public_html/images/';

              # time in military format 0-23
              # first number is opening time
              # second number is closing time
              # 24-24 indicates always closed
              # server is central time
              my %schedule = (
              Sun => [9,11],
              Mon => [6,11],
              Tue => [10,11],
              Wed => [10,11],
              Thu => [10,11],
              Fri => [10,11],
              Sat => [24,24],
              );

              # default value
              my $image = 'closed.gif';
              my $alt = 'sorry, we are closed';
              my $page = 'closed.html';

              # get the day and hour
              my ($day, $hour) = (split(/ /,scalar localtime))[0,3];
              $hour = (split(/:/,$hour))[0];

              # check the day and hour
              if ($schedule{$day }[0] <= $hour && $schedule{$day}[1] > $hour) {
              $image = 'open.gif';
              $alt = 'we are open now';
              $page = 'open.html';
              }

              #print appropriate MIME type header
              print "Content-type: text/html\n\n";

              print qq{<a href="../$page" title="$alt"><i mg src="../images/$image" alt="$alt"borde r="0"></a>};[/CODE]

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #22
                You should offset the time here:

                Code:
                my ($day, $hour) = (split(/ /,scalar localtime))[0,3];
                add or subtract the number of seconds from 'time' to off set the server time to your desired time-zone, an example adding 6 hours:

                Code:
                my ($day, $hour) = (split(/ /,scalar localtime[B](time+21600)[/B]))[0,3];
                and use the actual hours of open/close in the hash of arrays:


                Code:
                my %schedule = (
                   Sun => [9,11],
                   Mon => [10,11],
                   Tue => [10,11],
                   Wed => [10,11],
                   Thu => [10,11],
                   Fri => [10,11],
                   Sat => [24,24],
                );
                to offset the server time by plus one hour: 60 * 60 * 1 = 3600

                localtime(time+ 3600)

                to offset the server time by minus 2 hours: 60 * 60 * 2 = 7200

                localtime(time-7200)

                I think you get the picture.

                Comment

                • smarsh
                  New Member
                  • Jul 2007
                  • 18

                  #23
                  I understand the time adjustment: I'm GMT-5 and the server is GMT-6, so if I use time+3600 I effectively adjust the server time to my time zone and the hash arrays schedule is entered based on my local time. But that's not the problem. It's just acting wacky.

                  I put in the time+3600 adjustment and to test changed the Wed schedule to
                  Code:
                  Wed => [18,20]
                  because I'm working on it at 6:15PM on Wed. It didn't work though. I had to back down to
                  Code:
                  Wed => [9,20]
                  to get the "open" image to appear. That's a time difference of 9 hours.

                  What can be going on?

                  Comment

                  • KevinADC
                    Recognized Expert Specialist
                    • Jan 2007
                    • 4092

                    #24
                    I asked you to post your current code, in that current code I see this line:

                    my ($day, $hour) = (split(/ /,scalar localtime))[0,3];

                    there is no offset. Offset the time how I showed you and use the real hours of business in the hash. If that does not work I am not sure what the problem is.

                    Comment

                    Working...