Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts

    my $time = &get_time problem

    So I have a CGI script that sends a message to the users internal message box. It is placing date & time into the table BUT it is listing it 10 days ahead of the current day which is screwing up the messaging system from sending an email to the users external email account to alert them they have a new message. I have tried several different things and nothing has solved it.

    Here is the CGI script coding I have:

    Code:
    #!/usr/bin/perl -w
    use CGI::Carp qw(fatalsToBrowser carpout);
    use CGI qw(:standard);
    use DBD::mysql;
    use LWP::Simple;
    use URI;
    print "Content-type: text/html \n\n";
    
       ###############################
     # find the root if this is IIS:
     ###############################
     if($ENV{'SERVER_SOFTWARE'} =~ m/IIS/)
     {
    	if($root eq "" && $ENV{'PATH_TRANSLATED'} ne "")
    	{
    		my $pt = $ENV{'PATH_TRANSLATED'};
    		my @pts = split(/\\/, $pt);
    		$pts[-1] = "";
    		$root = join "/", @pts;
    		$OS = "NT";
    	}
     }
    
     ###############################
     # functions library:
     ###############################
     if(!$dontparse){
            require "${root}data/config/pmpre.cfg";
            require "${root}lib/mysql.lib";
            require "${root}lib/pm.lib";
            require "${root}lib/phpbb.lib" if($plugin_phpbb eq "yes");
     }
    
     ###############################
     # Read the data coming from the form..
     ###############################
     if(!$dontparse){ &readit; }
     ###############################
    
      if($use_cookie eq "yes" && !$dontparse && $input{'ID'}<1 && $input{'action'} ne "register"){
       #- retrieve existing cookie
       $lp = $req->cookie("pmpre");
       my ($clogin, $cID) = split(/\|/, pm_decode($lp));
       if(($clogin ne "") and ($cID ne "")){
    	   if($input{'login'} eq ""){
    		$input{'login'} = $clogin;
    	   }
    	   if($input{'ID'} eq "" && $input{'password'} eq ""){
    		$input{'ID'} = $cID;
    	   }
       }
    
     }
    
    
    my $count = 0;
    my $subject = "New message";
    my $flag = "1";
    my $from = "admin";
    my $time = &get_time;
    
    $query = "SELECT MAX(mailno) FROM `mailbox`";
    my $sth = $dbh->prepare($query);
    $sth->execute();
    my $data = $sth->fetchrow_array();
    my $mailno = ($data + 1);
    
    
    my $profiles_sth = $dbh->prepare("SELECT * FROM `departures` WHERE `departures_states` = ?") or die $DBI::errstr;
    $profiles_sth->execute($input{'state'}) or die $DBI::errstr;
    while(my $profiles = $profiles_sth->fetchrow_hashref()){
    my $firstname = "$profiles->{'firstname'}";
    my $login = "$profiles->{'login'}";
    # add personalized mail
    my $body = "You have recent posts from your state. <a href=pm.cgi?action=app_list&app=ship1&app_id=".$input{'app_id'}.">Click Here</a> to view it.";
    
    my $mail_sth = $dbh->prepare("INSERT INTO `mailbox` (`mailno`, `time`, `newflag`, `from`, `to`, `subject`, `body`)
    VALUES (?, ?, ?, ?, ?, ?, ?)") or die $DBI::errstr;
    $mail_sth->execute($mailno, $time, $flag, $from, $login, $subject, $body) or die $DBI::errstr;
    $mail_sth->finish;
    $count = ($count + 1);
    $mailno = ($mailno + 1);
    }
    $profiles_sth->finish;
    
    print "<br>$count ";
    
    	if ($count == 1){
    	print "Member has";
    	} else {
    	print "members have";
    	}
    
    print " been alerted about this post..<br><br>";
    exit;

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Your script has several problems beyond your date issue.

    C:\test>perl -c awayne96.pl
    Prototype mismatch: sub main::head: none vs ($) at awayne96.pl line 5
    [Wed Dec 2 15:36:58 2009] awayne96.pl: Name "main::plugin_phpbb" used only once: possible typo at awayne96.pl line 31.
    [Wed Dec 2 15:36:58 2009] awayne96.pl: Name "main::req" used only once: possible typo at awayne96.pl line 42.
    [Wed Dec 2 15:36:58 2009] awayne96.pl: Name "main::use_cookie" used only once: possible typo at awayne96.pl line 40.
    [Wed Dec 2 15:36:58 2009] awayne96.pl: Name "main::OS" used only once: possible typo at awayne96.pl line 20.
    You should use the warnings pragma instead of the -w switch and you should add the strict pragma. Those 2 pragmas should be in every Perl script.

    You need to show us the get_time() sub which I assume is in one of the files that you load via one of the require statements.

  • #3
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Well I went through all the files that are linked to the CGI file and the only one that has &get_time is the pm.lib. This is where I had copied it from and it worked except it is posting it 10 days ahead. Before I changed it to this the code on that line was:

    Code:
    my $time = "time";
    That was just posting a NULL value to the table which then displayed "time" as the time the new message was sent.

    Here is a snip of the code from pm.lib since it is extremely long and ever place &get_time is used is the same:

    Code:
    ###############################
    # logging
    ###############################
    sub log_event
    {
     my ($event) = @_;
     &get_time;
     &get_OS_n_browser;
     open(STAT, ">>${root}$stat_file");
     print STAT "$stat_no|$event|$input{'login'}|$time|$ENV{'REMOTE_ADDR'}|$ENV{'REMOTE_HOST'}|$browser|$OS\n";
     close STAT;
    }
    As for the issues the code has... This CGI was built by someone else. But in compairing that CGI and another CGI that came with the original software there are differences with some of it.... So I will look at that part of your post in more detail and post again regarding that.

    Thanks again for your help so far!

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Hmm, does that mean that you've fixed the problem?

    If you haven't fixed the problem, you need to look for the subroutine definition which begins with:
    Code:
    sub get_time {
    You have an inconsistency in how you're using the get_time() sub. In one script it assigns a $time var and in another it's used in void context.

  • #5
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    Hmm, does that mean that you've fixed the problem?

    If you haven't fixed the problem, you need to look for the subroutine definition which begins with:
    Code:
    sub get_time {
    You have an inconsistency in how you're using the get_time() sub. In one script it assigns a $time var and in another it's used in void context.
    Nope, didn't fix the problem... now that would have been too easy LOL.

    But I DID find sub get_time {... Here is the code:

    Code:
    ###############################
    # time and time variables
    ###############################
    sub get_time
    {
     ($sec, $min, $hr, $day, $month, $ye, $wd, $yd, $ds) =  localtime(time+$timezone);
     $sec += 10;$min += 10;$hr += 10;$day += 10;$month += 10;$yd +=100;
    
     $stat_no = "$ye$yd$hr$min$sec";
     $time = localtime(time+$timezone);
     $time =~ s/.20..$//; # remove the year
     my @times = split(/ /, $time);
     $time = "$times[0], $times[1] $times[2] $times[3] $times[4]";	#, $times[4]";
     $timeno = (1900+$ye)."\_".($month-9)."\_$day\_".($hr-10)."\_".($min-10)."\_$sec";
    }
    
    sub get_this_year
    {
     ($sec, $min, $hr, $day, $month, $ye, $wd, $yd, $ds) =  localtime(time+$timezone);
      return $ye+1900;
    }
    
    sub get_this_yearday
    {
     ($sec, $min, $hr, $day, $month, $ye, $wd, $yd, $ds) =  localtime(time+$timezone);
      return sprintf("%d%03d", ($ye+1900), ($yd+1));
    }
    
    sub get_expiration
    {
     my ($dur) = @_;
     ($sec, $min, $hr, $day, $month, $ye, $wd, $yd, $ds) =  localtime(time+$timezone);
     $yd = $yd+1;
     my $addyear = int(($yd+$dur)/365);
     my $remain = $dur - ($addyear*365);
     return sprintf("%d%03d", ($ye+1900+$addyear), ($yd+$remain));
    }

  • #6
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Here's your problem with the day of month being off by 10.
    Code:
    $sec += 10;$min += 10;$hr += 10;$day += 10;$month += 10;$yd +=100;
    Most of the code is very sloppy.

  • Users who have thanked FishMonger for this post:

    awayne96 (12-03-2009)

  • #7
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    Here's your problem with the day of month being off by 10.
    Code:
    $sec += 10;$min += 10;$hr += 10;$day += 10;$month += 10;$yd +=100;
    Thanks! That did do the trick....

    I wonder why it was like that to begin with? I didn't change anything regarding that and the rest of the displayed date and time is correct even with the += 10 with the others.

    I thought that the date was causing the email notification to not work properly and now that this is fixed it STILL doesn't work.. UGH

    I wonder what is hanging it up to not notify when this message comes in from this script BUT a message sent from one user to another works perfectly. I don't know if its something that all of you might be able to help me with it since this it was built into the software package that was purchased.?.?

  • #8
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    Most of the code is very sloppy.

    What part are you referring too? The sub get_time code I posted or the other that was developed by someone else?

    Thanks again for all your help with this!

  • #9
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Everyone of those assignments in that line of code is wrong.

    Clearly the intent was to convert/format single digit numbers to 2 digit numbers that have a leading 0. That's what sprintf is used for.

    When I said that is was sloppy code, I was being polite and referring to most, if not all, of the code you posted.

  • #10
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    I didn't change anything regarding that and the rest of the displayed date and time is correct even with the += 10 with the others.
    That's because this line reversed some of those additions.
    Code:
    $timeno = (1900+$ye)."\_".($month-9)."\_$day\_".($hr-10)."\_".($min-10)."\_$sec";

  • #11
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Hey, you can be honest with me since i spent $$$ having this site developed and I am now fixing problems and editing to 100% of what I want.

    I did not make this site myself so you would not be offend me lol.

    So what would be my best bet regarding making the code not so "sloppy"?

  • #12
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    That's because this line reversed some of those additions.
    Code:
    $timeno = (1900+$ye)."\_".($month-9)."\_$day\_".($hr-10)."\_".($min-10)."\_$sec";
    Ah, I see that now.

    Well with the day problem I just changed the 10 to 0 and it works correctly for my messaging

  • #13
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Based on the portion I've seen, I'd dump the whole thing and rewrite it from scratch. That's close to the worst code that I've seen. But you probably spent too much $$$ to want to start over.

  • #14
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    Based on the portion I've seen, I'd dump the whole thing and rewrite it from scratch. That's close to the worst code that I've seen. But you probably spent too much $$$ to want to start over.
    Yes, I have spent too much $$$ and would hate to start over especially since I got screwed over by another developer and lost $2300 and haven't spoken to him in over a year... and he started this project 2 years ago and I got pretty much nothing for my $$$.

    I guess once I have some extra $$$ I will look into getting it redone since I don't have the know how to do it all myself. I know enough to get things done the way I want them especially with some of the help out here on the good old internet.

    Again thanks for your assistance with my ever growing problems with my site!
    Last edited by awayne96; 12-03-2009 at 01:58 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •