in reply to Re: Add timestamp to helpdesk form
in thread Add timestamp to helpdesk form

In Chapter 22 you built a simple helpdesk form. “Spice up” that form with fancy colors or fonts. Also, add a timestamp so the repair technician will know when it was submitted. That is what the assignment asks for. I already editted the formatting and such just not sure about adding a timestamp this way.

Replies are listed 'Best First'.
Re^3: Add timestamp to helpdesk form
by jeffa (Bishop) on Jul 03, 2014 at 21:12 UTC

    But where is the ticket being stored? If this were an enterprise level solution then you would store the ticket as a record in a database table. When you insert the record, you could set up a timestamp column. When the technician requests those tickets assigned to themselves, the ticket is pulled from the database as a record and you simply display the fields on the form, including the date/time.

    And if you are storing these as a flat file, well, there really isn't much difference because in the end you will be pulling all the data about that ticket and displaying most of it (if not all) on the ticket page. Make sense?

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Ahhh I see. The book is Sam's Teach Yourself PERL in 24 hours. That form sends data to this CGI I believe (nothing is really functional just theory behind how it would work I guess. Here is the CGI file at hand:
      #!/usr/bin/perl -w use strict; use CGI qw(:all); use Fcntl qw(:flock); # Location of the guestbook log file. Change this to suit your needs my $gbdata="http://www.perl03.georgeself.com/cgi-bin/forms.txt"; # Any file name will do for semaphore. my $semaphore_file="/tmp/helpdesk.sem"; # Function to lock (waits indefinitely) sub get_lock { open(SEM, ">$semaphore_file") || die "Cannot create semaphore: $!"; flock(SEM, LOCK_EX) || die "Cannot lock: $!"; } # Function to unlock sub release_lock { close(SEM); } # This function saves a passed-in help desk HTML form to a file sub save { get_lock(); open(GB, ">>$gbdata") || die "Cannot open $gbdata: $!"; print GB "name: ", param('name'), "\n"; print GB "type: ", param('probtype'), "\n"; print GB "problem: ", param('problem'), "\n"; close(GB); release_lock(); } # This function displays the contents of the help desk log file as HTM +L, # with minimal formatting. sub display { open(GB, $gbdata) || die "Cannot open $gbdata: $!"; while(<GB>){ print "<B>$_</B><P>"; # The name my($type,$prob); $type=<GB>; # Assumes that each entry is $prob=<GB>; # exactly 3-lines long... print "$type<P>"; print "$prob<BR><HR>"; } close(GB); } print header; # The parameter 'submit' is only passed if this CGI program was # executed by pressing the 'submit' button in the form in listing 22.7 if (defined param('submit')) { save; display; } else { display; }

        Ok. So your "database" is defined here:

        my $gbdata="http://www.perl03.georgeself.com/cgi-bin/forms.txt";

        All you should need to do is add a line to save() and a few more lines to display():

        sub save { ... print GB "problem: ", param('problem'), "\n"; print GB "time: ", scalar(localtime), "\n"; ... } ... sub display { ... $prob=<GB>; my $time=<GB>; ... # print $time however you like }
        See if this works for ya!

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)
        
      Ok I added your code and uploaded them however the problem I'm running into is when I run the helpdesk.html and input random nonsense, as soon as I hit submit it locates the cgi file but nothing is displayed at all just a blank webpage. Also I look at the "database" file forms.txt and nothing was written to it. Sorry for all the questions I'm so new to PERL and not fully understanding this section. I'll post both the HTML and the CGI file. Here is a link to the helpdesk ticket submit page. http://www.perl03.georgeself.com/helpdesk.html
      <form action="/cgi-bin/helpdesk.cgi" name="helpdesk"> <body style="background-color:yellow;"> <p> <u><h1 style="font-family:verdana;"><strong>Problem type:</strong></h1 +></u> <input type="radio" name="probtype" value="hardware"/><strong>Hardware +</strong> <input type="radio" name="probtype" value="software"/><strong>Software +</strong> <br/> <textarea name="problem" rows="10 cols="40"> Describe your problem. </textarea> <br/> <strong>YourName:</strong> <input type="text" width="40" name="name" /><br/> <input type="submit" name="submit" value="Submit Problem" /> </form>
      CGI:
      #!/usr/bin/perl -w use strict; use CGI qw(:all); use Fcntl qw(:flock); # Location of the guestbook log file. Change this to suit your needs my $gbdata="http://www.perl03.georgeself.com/cgi-bin/forms.txt"; # Any file name will do for semaphore. my $semaphore_file="/tmp/helpdesk.sem"; # Function to lock (waits indefinitely) sub get_lock { open(SEM, ">$semaphore_file") || die "Cannot create semaphore: $!"; flock(SEM, LOCK_EX) || die "Cannot lock: $!"; } # Function to unlock sub release_lock { close(SEM); } # This function saves a passed-in help desk HTML form to a file sub save { get_lock(); open(GB, ">>$gbdata") || die "Cannot open $gbdata: $!"; print GB "name: ", param('name'), "\n"; print GB "type: ", param('probtype'), "\n"; print GB "problem: ", param('problem'), "\n"; print GB "time: ", scalar(localtime), "\n"; close(GB); release_lock(); } # This function displays the contents of the help desk log file as HTM +L, # with minimal formatting. sub display { open(GB, $gbdata) || die "Cannot open $gbdata: $!"; while(<GB>){ print "<B>$_</B><P>"; # The name my($type,$prob); $type=<GB>; # Assumes that each entry is $prob=<GB>; # exactly 3-lines long... my $time=<GB>; print "$type<P>"; print "$prob<BR><HR>"; print $time; } close(GB); } print header; # The parameter 'submit' is only passed if this CGI program was # executed by pressing the 'submit' button in the form in listing 22.7 if (defined param('submit')) { save; display; } else { display; }
        Add this line to your cgi and try again
        use CGI::Carp 'fatalsToBrowser';
        Remove or comment out when script is working.
        poj
Re^3: Add timestamp to helpdesk form
by Anonymous Monk on Jul 03, 2014 at 21:13 UTC
    In Chapter 22 of what book?