<?php

		  // PHPCards v0.2, Allows people to set up simple online greeting cards. 
                  // Copyright (C) 2000, Mike Gifford www.openconcept.on.ca 
                  // 
                  // This script 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. 
                  // 
                  // This program 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 http://www.gnu.org/copyleft/ for more details. 
                  // 
                  // If you distribute this code, please maintain this header. 
                  // 
                  // This script allows users to select an image and write a personalized message. 
                  // It then sends a notice to the user specified email address and saves that 
                  // information to a text file. The receipient then can go and access both 
                  // the saved message and image from the website at a specified URL. 
                  // 
                  // Includes: send.php3, send.php3, receive.phtml, receive.php3 
                  
                  
                  
function alphabet_soup() { 

$letter_length = 6; 
srand((double)microtime()*1000000); 


$cons = array("b", "c", "d", "g", "h", "j", "k", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr", "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "B", "C", "D", "G", "H", "J", "K", "M", "N", "P", "R", "S", "T", "U", "V", "W", "Tr", "Cr", "Br", "Fr", "Th", "Dr", "Ch", "Ph", "Wr", "St", "Sp", "Sw", "Pr", "TR", "CR", "BR", "FR", "TH", "DR", "CH", "PH", "WR", "ST", "SP", "SW", "PR"); 
$vowels = array("a", "e", "i", "o", "u", "y", "A", "E", "I", "O", "U", "Y"); 
$numbers = array("2","3","4","5","6","7","8","9"); 
$num_vowels = count($vowels); 
$num_cons = count($cons); 

for($i = 0; $i < $letter_length; $i++){ 
$password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)]; 
} 

$password = substr($password, 0, $letter_length).rand(10,99); 

return $password; 
}
                  
                  
                  

include("$DOCUMENT_ROOT/ireru/ecardsconfig.php3");

// Counter Script
$free=0;
$empty="empty\n";
$oldcards = file($cardfile);
$total = count($oldcards);



for($i = 0 ; $i < count($oldcards) ; $i++) 
{
	if($array[$i] == $empty) 
	{
	$free=$i;
	}
}

if($free=="0")
{
if($oldcards==$empty)
	{
	$free=0;
	}
	else
	{
	$free=$total;
	}
}

// Place existing cards into an array.
$fd = fopen("$cardfile", "r"); 
$oldcards = "";       // Leave this blank 
	while ($buffer = fgets($fd, 4096)) { 
	$oldcards .= $buffer; 
} 
fclose($fd); 

// Change Text so that it doesn't interfere with messages
// $message = str_replace(":",chr(0),$message);  		    // Colon to null character
 $message = str_replace("  ","&nbsp; ",$message);  	  // Double Space to HTML Space (&nbsp;) 
// $remail = str_replace(":",chr(0),$remail);    		
// $recipient = str_replace(":",chr(0),$recipient);    		
// $email = str_replace(":",chr(0),$email);    		
// $name = str_replace(":",chr(0),$name);    		

// Generate a Random Number - Security
$eci = alphabet_soup();

  // What is written to the Text File

$newcard = $free+1 . "<>" . $picture . "<>" . nl2br(htmlentities($remail)) . "<>" . nl2br(htmlentities($recipient)) . "<>" . nl2br(htmlentities($email)) . "<>" . nl2br(htmlentities($name)) . "<>" . ereg_replace("\n", "<br />", $message ) . "<>" . $eci . "\n<>";    

$allcards = $oldcards . $newcard;
$idnumber=$free+1;

  // If the recipient's email is correct
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$", $remail)) {  
                  
// Preview Message

// echo "<img src=\"graphics/$picture\"><a href=\"mailto:$remail\">";
// echo stripslashes(htmlentities($recipient))."</a>From: <a href=\"mailto:$email\">";
// echo stripslashes(htmlentities($name))  . "</a>";
// echo "Message:<br />" . stripslashes(nl2br(htmlentities($message))) ;

  // If the name's email is correct
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$", $email)) {

	
		// ***************************************************************************************************************************************************
		// Post the message
		// ***************************************************************************************************************************************************

		
		$cartFile = fopen("$cardfile","w"); 
		fwrite($cartFile,$allcards); 
		fclose($cartFile); 
		
		
		// Message to be included in email
		  
		$email_message = "Greetings!
		This is to let you know that $name has created a $sitename e-card for you.  
		To see your card, click the link below:
		
		".$site_url."ecards/receive.php3?eci=".$idnumber."-".$eci."
	
		 	
		or copy and paste the following website address into your browser:
		
		".$site_url."ecards/receive.php3 
		and enter Confirmation number: ".$idnumber."-".$eci;
		
		
		  // Send to recipient  - Taken Out: Reply-To: $email \r\n X-Mailer: PHP3 \r\n 
		mail(stripslashes($recipient) . "<$remail>", "A ".$sitename." e-card from ".stripslashes($name) , $email_message,"From: $email \nReply-To:$email\nX-Mailer: PHP3\r\n Errors-To: $errors_to_email"); 
		
		// ***************************************************************************************************************************************************
		// Print a confirmation
		// ***************************************************************************************************************************************************
		print '<h1>Celtic e-Cards</h1>';		
		print '<p>Your e-card has been sent to '.stripslashes($recipient); 
		print '<p>Click <a href="'.$ecards_home_url.'">here</a> to send another card<p>';
		$now = time(); echo date('j M y - H:i', $now);
		

}  

// ***************************************************************************************************************************************************

		// End of verification for $email
else { echo "<strong>This card was NOT sent because a valid email address was not provided!</strong><p>\n"; }

}  		// End of verification for $remail
else { echo "<strong>A preview was NOT provided because a valid email address was not provided!</strong><p>\n"; }

?>