Location: PHPKode > projects > Slashster > slashster/html/invite.php
<?

# Slashster: Open Source Friend of a Friend Software
# Copyright 2004 Mark El-Wakil
# Contact: hide@address.com
# http://seventhcycle.net
#
# This file is part of Slashster.
#
# Slashster is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Slashster is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Slashster; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    import_request_variables("gPc");

    require_once("PageClass.php");

    $mpage = new PageClass("authonly");  
    $mpage->MembersOnly();
    $mpage->VerifiedOnly();

    $gdd = array();
    $gdd[fname] = $mpage->user[Fname];
    $gdd[linit] = $mpage->user[Lname];
    $gdd[email] = $mpage->user[Email];
    $gdd[id]    = $mpage->IdNum;

    $txt = $mpage->PrintSnippit("invite", $gdd);
    if ($optmsg)
    {
         $txt .= "\n\nPersonal message from " . $gdd[fname] . ":\n\n";
         $txt .= $optmsg;
    }

    $subj = "Invitation to join ". $mpage->sys[sitename] ." from "
          . $mpage->user[Fname] . " "
          . $mpage->user[Lname];

    $email = $mpage->user[Fname] . " " . $mpage->user[Lname] . " " 
           . "<" . $mpage->user[Email] . ">";

    $errmsg = "";

    if ($submit)
    {
         $emailarr = explode(",", $emails);

         if (!sizeof($emailarr))
         {
             $errmsg = "No emails entered";
         }         

         if (!$errmsg)
         {
             foreach ($emailarr as $k=>$v)
             {
                 $v = trim($v);
                 $v = strtolower($v);
                 $emailarr[$k] = $v;

                 if (!$v)
                 {
                     unset($emailarr[$k]);
                 }
                 elseif (!preg_match ("/^[\w\.\-]+\@[\w\.\-]+\.[a-z]{2,4}$/i", $v))
                 {
                     $errmsg .= "Invalid email: " 
                             . htmlentities(stripslashes($v)) . "<BR>";
                     unset($emailarr[$k]);
                 }
             }

         }

         if (!$errmsg && !sizeof($emailarr))
         {
             $errmsg = "No emails entered";
         }

         if (!$errmsg)
         {
             $emailarr = array_unique($emailarr);
             $eml2 = $emailarr;
             foreach ($eml2 as $k => $v) $eml2[$k] = "\"$v\"";

             $sql = "select Id, Email from UserTable where Email IN (
                    " . join(",", $eml2) . ")";

             $r = $mpage->DoQuery($sql,1);

             foreach ($r as $s) 
             {
                 if (!in_array($mpage->UserDistance($s[Id]), array(0,1)))
                 {
                     $mpage->FriendRequest($mpage->IdNum, $s[Id]);
                 }

                 $gta = array_search($s[Email], $emailarr);
                 unset($emailarr[$gta]);
             }

             foreach($emailarr as $k=>$e)
             {
                  $txt2 = str_replace("#yourmail#", $e, $txt);

                  $sql = "replace into InviteEmail set UserId=$mpage->IdNum,
                          Email = \"$e\" ";
                  $mpage->DoQuery($sql,1);

                  $fname = $mpage->user[Fname];
                  $lname = $mpage->user[Lname];
                  $emmml = $mpage->user[Email];

                  $from = "$fname $lname <$emmml>";
                 $retname = "$fname $lname";

$slashmail = 1;

                  $headers = "";

                  if (!$slashmail)
                  {
                       $headers .= "From: $from\r\n";
                  }

                  $headers .= "MIME-Version: 1.0\r\n";
//                  $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";


if (!$slashmail)    mail($v, $subj, $txt2, $headers);
if ($slashmail)     slashmail($v, $subj, $txt2, $headers, $from, $emmml, $retname);

                  unset($emailarr[$k]);
             }

             $emails = join(",", $emailarr);


             if ($mpage->user[Verified])
             {
                 $errmsg = "Thank You!";
             }
             else
             {
                 header("Location: main.php?" . sid);
                 exit;
             }

         }
         else
         {
             $emails = join(",", $emailarr);
         }
    }

    $mpage->Initialize("authremainder");




    $txt = str_replace("#yourmail#", "hide@address.com", $txt);


?>

<? if ($errmsg) { ?>


<P><BR>
<table border=4 bordercolor=red cellspacing=0 cellpadding=5px>
<tr><td style="font: bold 16px arial; color:red;">
<?= $errmsg ?>
</td></tr>
</table>
<P>

<? } ?>

<BR>
<P class="title1">Invite your Friends to <?= $mpage->sys[sitename] ?>.</p>

<P>
In order to do any sort of interaction on <?= $mpage->sys[sitename] ?>, you need to have friends on the site.
You can enter <BR>in their emails here, or go to <a href="usersearch.php">User Search</a> and look
your friends up by name.
</p>

<form method=post>
<BR>
<table width=600 border=0 cellpadding=2px cellspacing=0>
<tr><td width=50 valign=top  class="stdtable"><B>Subject:</b></td>
    <td width=550 valign=top class="stdfilling">
&nbsp;<?= $subj ?>
</td>
</tr>

<tr><td width=50 valign=top  class="stdtable"><B>Email:</b></td> 
    <td width=550 valign=top class="stdfilling"> 
&nbsp;<?= htmlentities($email) ?> 
</td> 
</tr>

<tr><td width=50 valign=top  class="stdtable"><B>To:</b></td>  
    <td width=550 valign=top class="stdfilling">
<small>Separate separate emails with commas</small><BR>
<textarea name="emails" cols=40 rows=3>
<?= $emails ?>
</textarea>
</td>
</tr>

<tr><td width=50 valign=top  class="stdtable"><B>Optional Message:</b></td>   
    <td width=550 valign=top class="stdfilling">
<textarea name="optmsg" cols=40 rows=3>
</textarea>
</td>
</tr>


<tr><td width=50 valign=top  class="stdtable"><B>Message:</b></td>
    <td width=550 valign=top class="stdfilling">
<pre>
<?= $txt ?>
</pre>

</td>
</tr>


<tr><td width=50 valign=top  class="stdtable">&nbsp;</td>
    <td width=550 valign=top class="stdfilling">
&nbsp;&nbsp;<small style="color:red"><B>Note</b></small><small>: hide@address.com will be replaced the email of the person mailed.
<BR>&nbsp;&nbsp;so if for some reason the person does not get your email, you can just paste them the link.
<BR>&nbsp;&nbsp;with their email replacing hide@address.com  Easy enough huh?
</small>
</td></tr>


<tr><td width=50 valign=top  class="stdtable">&nbsp;</td>
    <td width=550 valign=top class="stdfilling">

&nbsp;<input class="submit" name="submit" type="submit" value="Invite">

</td>
</tr>


</table>

</form>


<? $mpage->ClosePage(); ?>


<?

function slashmail($to, $subject, $txt, $headers, $from, $retpath, $retname)
{
   global $mpage;
  
   if ($mpage->sys[chretpath]) 
      $sendmail = "/usr/sbin/sendmail -t -f " . $mpage->sys[bounceadr];
   else
      $sendmail = "/usr/sbin/sendmail -t";

   $fd = popen($sendmail, "w");
   fputs($fd, "Reply-To: <$retpath>\r\n");
   fputs($fd, "From: $from\r\n");
   fputs($fd, "To: $to\r\n");
   fputs($fd, "Subject: $subject\r\n");
   fputs($fd, $headers);
   fputs($fd, $txt . "\r\n");
   pclose($fd);

}

?>
Return current item: Slashster