SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CGI to PHP and MySQL

    i need to turn this code into PHP and i havent been able to

    PHP Code:
    if ($t eq "configure") {

    print 
    "Content-type: text/html\n\n";
    print 
    qq~<body background="/admin/plainback2.gif"><center>
    <
    font size="5" face="verdana" color="#000000"><u>Mass E-Mail Manager</u></font>
    </
    center><br>~;

    if (
    exists $formdata{'done'}) {

    $formdata{'emessage'} =~ s/\n/{enter}/g;

    open (FILE">$emaildatadir$formdata{'date'}");
        
    print 
    FILE <<"File";
    $formdata{'subject'}
    $formdata{'emessage'}
    File

    close 
    (FILE);

    print 
    "<b>E-Mail Successfully Updated</b><br>";

    }

    print <<
    "File";
    <
    hr>
    <
    center>
    <
    form action="email.cgi?t=configure" method="POST">

    <
    select name="month">
    <
    option value="" selected>MM</option>
    <
    option value="01">01</option>
    <
    option value="02">02</option>
    <
    option value="03">03</option>
    <
    option value="04">04</option>
    <
    option value="05">05</option>
    <
    option value="06">06</option>
    <
    option value="07">07</option>
    <
    option value="08">08</option>
    <
    option value="09">09</option>
    <
    option value="10">10</option>
    <
    option value="11">11</option>
    <
    option value="12">12</option>
    </
    select>/
    <
    select name="day">
    <
    option value="" selected>DD</option>
    <
    option value="01">01</option>
    <
    option value="02">02</option>
    <
    option value="03">03</option>
    <
    option value="04">04</option>
    <
    option value="05">05</option>
    <
    option value="06">06</option>
    <
    option value="07">07</option>
    <
    option value="08">08</option>
    <
    option value="09">09</option>
    <
    option value="10">10</option>
    <
    option value="11">11</option>
    <
    option value="12">12</option>
    <
    option value="13">13</option>
    <
    option value="14">14</option>
    <
    option value="15">15</option>
    <
    option value="16">16</option>
    <
    option value="17">17</option>
    <
    option value="18">18</option>
    <
    option value="19">19</option>
    <
    option value="20">20</option>
    <
    option value="21">21</option>
    <
    option value="22">22</option>
    <
    option value="23">23</option>
    <
    option value="24">24</option>
    <
    option value="25">25</option>
    <
    option value="26">26</option>
    <
    option value="27">27</option>
    <
    option value="28">28</option>
    <
    option value="29">29</option>
    <
    option value="30">30</option>
    <
    option value="31">31</option>
    </
    select>/
    <
    select name="year">
    <
    option value="" selected>YYYY</option>
    <
    option value="2000">2000</option>
    <
    option value="2001">2001</option>
    <
    option value="2002">2002</option>
    <
    option value="2003">2003</option>
    <
    option value="2004">2004</option>
    <
    option value="2005">2005</option>
    <
    option value="2006">2006</option>
    <
    option value="2007">2007</option>
    <
    option value="2008">2008</option>
    <
    option value="2009">2009</option>
    <
    option value="2010">2010</option>
    <
    option value="2011">2011</option>
    <
    option value="2012">2012</option>
    <
    option value="2013">2013</option>
    <
    option value="2014">2014</option>
    <
    option value="2015">2015</option>
    <
    option value="2016">2016</option>
    <
    option value="2017">2017</option>
    <
    option value="2018">2018</option>
    <
    option value="2019">2019</option>
    <
    option value="2020">2020</option>
    </
    select>
    <
    input type="submit" value="Go To the E-Mail">

    </
    form>
    <
    form action="email.cgi?t=sendmail" method="POST">
        
    Send to members <input name=usersmin type=text value=1 size=5> -
    File

    open 
    (FILE$emaildata);
    @
    emails = <FILE>;
    close (FILE);

    $usertotal = @emails;
    print 
    "<input type=text name=usersmax value=$usertotal size=5>";
    print <<
    "File";
    <
    br>
        <
    input type="submit" value="Send Today's E-Mail"><br>
    NOTICEYou must have the e-mail written for todaymake sure you don't
    submit this form more than once, or else it may send the mailing twice.
    </form>
    </center>
    <hr>
    File

    $tdate = $formdata{'
    month'} . $formdata{'day'} . $formdata{'year'};

    if (($formdata{'
    month'} gt "") && 
       ($formdata{'
    day'} gt "") && 
       ($formdata{'
    year'} gt "") && 
       (-e "$emaildatadir$tdate")) {

    $message = "<b>Editing E-Mail...</b><br>";

    $nicedate = $formdata{'
    month'} . "/" . $formdata{'day'} . "/" . $formdata{'year'};
    $hiddendate = $formdata{'
    month'} . $formdata{'day'} . $formdata{'year'};

    open (FILE, "$emaildatadir$tdate");
    @email = <FILE>;
    close (FILE);

    $subject = $email[0];
    $emessage = $email[1];

    } elsif (($formdata{'
    month'} gt "") && 
       ($formdata{'
    day'} gt "") && 
       ($formdata{'
    year'} gt "")) {

    $nicedate = $formdata{'
    month'} . "/" . $formdata{'day'} . "/" . $formdata{'year'};
    $hiddendate = $formdata{'
    month'} . $formdata{'day'} . $formdata{'year'};

    } elsif (-e "$emaildatadir$date") {

    $message = "<b>Editing E-Mail...</b><br>";

    $nicedate = $mon . "/" . $mday . "/" . $year;
    $hiddendate = $mon . $mday . $year;

    open (FILE, "$emaildatadir$date");
    @email = <FILE>;
    close (FILE);

    $subject = $email[0];
    $emessage = $email[1];

    } else {

    $nicedate = $mon . "/" . $mday . "/" . $year;
    $hiddendate = $mon . $mday . $year;

    }

    $emessage =~ s/</\</g;
    $emessage =~ s/>/\>/g;
    $emessage =~ s/{enter}/\n/gi;

    $message = "<p><big>E-Mail not created yet...</big>" if($message eq "");

    print <<"File";
    <center><h3>E-Mail For: $nicedate</h3>

    $message

    </center>

    <form action="email.cgi?t=configure&done=yes&date=$hiddendate" method="POST">

    Subject:<br>
    <input type="text" name="subject" value="$subject"><br>

    Message<br>
    <textarea name="emessage" cols="80" rows="40">$emessage</textarea><br>

    </td></tr></table></center>
    <br><input type="submit" value="Save the E-Mail">
    </form>
    </body>
    File



    if ($t eq "build") {

            opendir (FILE, "$userdatadir");
            @users = readdir(FILE);
            closedir (FILE);

            foreach $user (@users) {
           
                    open (FILE, "$userdatadir$user");
                    @file = <FILE>;
                    close (FILE);
           
                    foreach $rline (@file) {
                            ($first,$second) = split(/::/, $rline);
                            push(@emails, $second) if($first eq "email");
                    }
           
            }
           
            open (FILE, ">$emaildata");
            foreach $email (@emails) {
                    print FILE $email;
            }
            close (FILE);

            print "Content-type: text/html\n\n";
            print "E-Mail Database Built";

    }
    if ($t eq "sendmail") {

    $min = $formdata{'
    usersmin'};
    $max =$formdata{'
    usersmax'};

    open (FILE, $emaildata);
    @emails = <FILE>;
    close (FILE);

    $usertotal = @emails;

    $toprint .= qq~As of $currentdate, there are currently $usertotal e-mail addresses in the database.~;
    $pid = fork();
    print "<br> fork failed: $!<br>" unless defined
    $pid;
    if ($pid) {
            #parent
    print "Content-type: text/html\n\n<h1>Sending E-Mail</h1><i>Please wait for the WHOLE page to load.
    DO NOT REFRESH THIS PAGE, OR ELSE THE MAILING WILL BE SENT OUT AGAIN.</i>";
    print "<br>Mailing Complete";
           exit(0);
            }
    else {    
            #child
     close (STDOUT);
    if (-e "$emaildatadir$date") {

    open (FILE, "$emaildatadir$date");
    @letter = <FILE>;
    close (FILE);

    $subject = $letter[0];
    $emessage = $letter[1];
    $emessage =~ s/{enter}/\n/ig;

    $usercount = 1;
    if ($max>$usertotal){$max=$usertotal;}
    for ($i=$min; $i <= $max; ++$i) {

    $emails[$i] =~ s/\n//gi;
    $emailaddy = $emails[$i];

    if (length($emailaddy) >= 6) {

    open (EMAIL, "|$sendmail -t");

    print EMAIL <<"File";
    To: $emailaddy 
    From: rewards\@$siteaddr
    Subject: $subject

    $emessage
    File

    close (EMAIL);

    $usercount += 1;

    }

    }

    $toprint .= "The Daily E-mail was sent to $usercount valid e-mail addresses.";

    } else {

    $toprint .= "No daily E-Mail was sent because there was no E-Mail Created.";

    }

    open (EMAIL, "|$sendmail -t");

    print EMAIL <<"File";
    To: webmaster\@$siteaddr
    From: $noreplyemail\@$siteaddr
    Subject: $title Daily Stats

    $toprint
    File

    close (EMAIL);
    }

    PLEASE HELP

  2. #2
    Sports Publisher mjames's Avatar
    Join Date
    Jan 2000
    Location
    Charlotte, NC
    Posts
    5,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I don't think it's reasonable to ask someone to do this gigantic task for you. That's a lot of code. If you have a specific question, that's more appropriate.

  3. #3
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not looking for someone to do the whole script for me im looking for some pointers

    Thats all

    like how i would call MySQl and make sure that it would add the credit and not add it again and so forth

  4. #4
    SitePoint Evangelist compwizard's Avatar
    Join Date
    May 2002
    Location
    United States
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    could you post a link with the working version so i could see how it is supposed to look...i am willing to help with part of it

  5. #5
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Their is no working code that i have

    and the code up top is from the wrong file

    heres the right code

    PHP Code:
    if ($formdata{'t'gt "") {

        
    open (USER"$pedata");
        @
    links = <USER>;
        
    close (USER);

        
    $found 0;

        foreach 
    $line (@links) {
        
            
    $line =~ s/\n//g;
            
    @edit split(/::/, $line);
        
            if ((
    $formdata{'t'eq $edit[0]) && ($found == 0)) {
                
    $cash $edit[1];
                
    $found 1;
            }
        }
        
        if (
    $found == 1) {
        
            &
    page($top);
        
            print 
    qq~
            <
    h3>Email Address Logged</h3>
            <
    form action="$petrack?id=$formdata{'t'}" method="post">
            
    Please enter your Usernameso that we may track your visit to this Paid-Email:<br>
            (
    You will earn $cash cents once you visit this site.)<br>
            <
    input type="text" name="username"><br><br>
            <
    input type="submit" value="Visit">
            </
    form>
            ~;
            
            &
    page($bottom);
            
        } else {
            &
    page($top);
            &
    message('Error','Paid-Email not found.');    
        }
        
    elsif ($formdata{'username'gt "") {

        
    unless ((-"$userdatadir$formdata{'username'}") && ($formdata{'username'gt "")) {
            &
    page($top);
            &
    message('Error','Username does not exist.');
        }

        
    open (USER"$pedata");
        @
    links = <USER>;
        
    close (USER);

        
    $found 0;

        foreach 
    $line (@links) {
        
            
    $line =~ s/\n//g;
            
    @edit split(/::/, $line);
        
            if ((
    $formdata{'id'eq $edit[0]) && ($found == 0)) {
            
                
    open (FILE"$pedatadir$edit[0]");
                @
    ltotal = <FILE>;
                
    close (FILE);
                
                
    $done 0;
                
                foreach 
    $user (@ltotal) {
                    
    $user =~ s/\n//g;
                    
    if ($user eq $formdata{'username'}) {
                        
    $done 1;
                    }
                }
                
                if (
    $done == 0) {
                    
    open (FILE">>$pedatadir$edit[0]");
                    print 
    FILE "$formdata{'username'}\n";
                    
    close (FILE);
                }
                
                
    $cash $edit[1];
                
    $url $edit[3];
                
                
    $found 1;
                
            }
        }
        
        if (
    $found == 1) {
        
            if (
    $done == 1) {
                &
    page($top);
                &
    message('Error','You have already visited this site and received credit.');
            }
        
            
    open (USER"$userdatadir$formdata{'username'}");
            @
    user = <USER>;
            
    close (USER);
        
            foreach 
    $line (@user) {
        
                (
    $first,$second) = split(/::/, $line);
                
    $second =~ s/\n//g;
        
                
    if ($first eq "clicks") {
                    
    $moneymade $second $cash;
                    
    $user[$linenumber] = "clicks::$moneymade\n";
                    
    $flag 1;
                }
                
    $linenumber $linenumber 1;
            }
        
            
    open (USER">$userdatadir$formdata{'username'}");
            foreach 
    $line (@user) {
                print 
    USER "$line";
            }            
            
    close (USER);
            
            print 
    "Location: $url\n\n";
            
        } else {
            &
    page($top);
            &
    message('Error','Paid-Email not found.');
        }
        

    Sorry for the mistake

  6. #6
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, PHP's foreaches, greater-than comparison signs, regexps, file manipulation functions, arrays, hashes, and functions are all different. As much as we would like to help you translate it, you should probably learn PHP on your own and finish this task yourself.


Bookmarks

Posting Permissions

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