
lilacNlillies
New User
Nov 23, 2010, 12:22 PM
Post #1 of 3
(968 views)
|
A Simple Calculation Error Or Something More Sinister?
|
Can't Post
|
|
Hi, I was given a cgi/perl script the other day and in running the script and it's components everything worked fine when I installed it on my Linux server. However, the end result is that the add message feature keeps multiplying the message number on the URL (which is used to access the message that has been saved). I am a PRE-Newbie and have yet to even begin tutorials, but the code and it's package was given to me and I'd like to make the most of it. I think I've placed in the code where the problem is happening, but because I do not know/code perl, i do not know how to remedy it. In my search to find answers I've come upon some cgi/perl tutorials - but I simply can't at this time, wait for this problem to be solved as I plan to use it in a bigger, time-sensetive project shortly. Would you be able to take a look at the code and advise me? I think the problem has something to do with the calculations... either the ++2 or the [#] related to the message number commands. I have attached an image of what the resulting code looks like when it is running on the Linux server. [If you look under the "Edit Message" on the image, you will see that the "Message 4" has multiple copies. If you only have 1 message saved, then you create a second message- after you save message 2 both available message links then become "Message 2" (and message 1 can only be accessed by changing the URL in the browser bar) this keeps happening and if you try to save 6 messages all 6 message links will say "Message 6"] What is making it multiply like this? *this is the section where I believe the problem is happening: (I will be happy to provide the entire cgi file if needed) ===================================================================<code> open(FILE,"$FORM{'ar'}/periods.txt"); flock(FILE,$LOCK_EX); foreach(<FILE>) {push(@periods,$_)} close(FILE); @periods[0]=0; $numb=0; opendir(DIR,"@_[0]") || die "Cannot open $userdir!"; while (@files=readdir(DIR)) { foreach $file(@files){ if ($file ne ".." && $file ne "." && $file ne "" && $file=~/letter\d*\.txt/) { push(@list1,$file); @listing=sort blia @list1; @listing[$#listing]=~/(\d+)/; $num=$1; if($numb>$#periods){@periods[$numb]=@periods[$numb-1]+1}; print "<tr><td><p><a href='$scripturl?mode=read&fname=@listing[$#listing]&ar=@_[0]&num=$1&password=$FORM{'password'}'>Message $num</a></p></td><td><p> sent after <INPUT class='edit1' name=@listing[$#listing] size='5' value='@periods[$numb]'> days"; ($pattach)=getattach("$FORM{'ar'}/@listing[$#listing]"); $pattach=~/.*\.(.*)$/; if ($pattach ne ""){ $size=-s "$FORM{'ar'}/upfile$num.$1"; print " with attachment: <font color='red'>$pattach</font> ($size bytes)</p></td></tr>"; } else { print "</p></td></tr>"; } $numb++; } } }; close(DIR); if ($#listing==-1){ print "<tr><td><p>You have no letters!</p></td></tr>"; } else { }; $newlet=$#listing+2; print "</table>"; print "<input class='edit1' type='image' src='".$imgpath."/add_message.gif' value='Add New Message' onclick=\"document.letters.mode.value='newlet'\"> <input class='edit1' type='image' src='".$imgpath."/save_intervals.gif' value='Save Intervals' onclick=\"document.letters.mode.value='saveletter'\"><br><br>\n"; print "<table width='100%' border='0' cellspacing='0' cellpadding='0' background='".$imgpath."/bg.gif'><tr><td><img src='".$imgpath."/poloska.gif'></td></tr></table>\n"; print " <p><b><u>Prospects</u></b><br>Do you want to add new contacts to your 'active prospects' list?<br>Just insert their names and addresses below in the following format:<br><b>John Smith|john\@email.com</b><br>or:<br><b>john\@email.com</b><br>(one address per line)<br>Import prospects into sequence beginning with <b>message number</b> <input class='edit1' name='period' size='2' value='1'></p>\n"; print " <textarea class='edit1' rows='8' name='import' cols='50'></textarea><br>\n"; print " <input class='edit1' type='image' src='".$imgpath."/import.gif' value='Import Prospects' onclick=\"document.letters.mode.value='saveletter'\"> "; print " <input type='image' src='".$imgpath."/export.gif' onclick=\"window.open ('$scripturl?mode=export&ar=$FORM{'ar'}&password=$FORM{'password'}', 'newwindow', config='height=500, width=400, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no'); return false;\"><br><br>\n"; print "<table width='100%' border='0' cellspacing='0' cellpadding='0' background='".$imgpath."/bg.gif'><tr><td><img src='".$imgpath."/poloska.gif'></td></tr></table>\n"; print " <input type='hidden' name='ar' value='@_[0]'><input type='hidden' name='mode'>\n"; $numb++; print " <input type='hidden' name='newone' value='$numb'>\n"; print " <input type='hidden' name='password' value='$FORM{'password'}'>\n"; print "</form><br><br>\n"; print "<!--//LETTERS//-->\n"; &footer; }; ==========================================================</code> I am willing to pay for the fix. Your help is appreciated. Lilac
(This post was edited by lilacNlillies on Nov 23, 2010, 12:30 PM)
|