<?php
/***************************************************************************
* functions.php script-name: phpECard *
* --------------------------------------------------------------------- *
* version : 2.0 *
* script suport page : http://quick-xs.net/phpecard *
* author email : phpecard@quickxs.net *
* *
***************************************************************************
* *
* The complete functionality of the script is defined in this file. *
* ANYTHING YOU EDIT HERE CAN PREVENT THE SCRIPT FROM WORKING *
* *
***************************************************************************/
// First lets perform some required actions
// Function to make links in gallery
function makelink($image_name)
{
if (file_exists($include_path.'lang_'.$language.'.php')) {
$language_preset = 'language='.$language.'&';
}
return $PHP_SELF.'?'.$preset_vars.$language_preset.'card='.$image_name;
}
// Check language, else get default language file [TRYOUT]
if (file_exists($include_path.'lang_'.$language.'.php')) {
include($include_path.'lang_'.$language.'.php');
}
else
{
include($include_path.'lang_'.$default_language.'.php');
}
// Make sure that $action always is "compose" if not "send"
if ($action != 'send')
{
$action = 'compose';
}
// function to test email-syntax, used later on
function IsEmail($mail)
{
return ereg("[A-Za-z0-9_-]+([\.]{1}[A-Za-z0-9_-]+)*@[A-Za-z0-9-]+([\.]{1}[A-Za-z0-9-]+)+", $mail); }
// check to see weither an id is defined
if ((IsSet($id)) && ($id != '')) {
// Check to see if id-datafile is present
{
// Include the datafile and send confirmation back to sender if wanted
include($include_path.'userdata/'.$id.'.php');
if ($notify_sender == 'on')
{
$comeback_url = 'http://'.$_SERVER['SERVER_NAME'].$PHP_SELF;
$notify_mail_sender = $lang['dear'].' '.$sender_name.','."\n\n".$recipient_name.' ('.$recipient_email.')'.$lang['recipient_has_seen']."\n\n".$lang['please_come_back']."\n".$comeback_url."\n\n".$lang['regards']."\n\n$service_name (".$admin_email.')'.$add;
mail($sender_email,$recipient_name.$lang['notify_sender_subject'],$notify_mail_sender,"From: $service_name<$admin_email>");
$CRD_datafile =
'<?php
$notify_sender = "off";
$sender_email = "'.$sender_email.'";
$recipient_email = "'.$recipient_email.'";
$date = "'.$date.'";
$time = "'.$time.'";
$card = "'.$card.'";
$index_url = "'.$index_url.'";
?>';
fwrite(fopen($include_path.'userdata/'.$id.'.php',"w"),$CRD_datafile); }
$card_info = $lang['card_to'].' <u>'.$recipient_name.'</u> - '.$lang['sent_at'].' '.$date.', '.$lang['at'].' '.$time.$lang['hour'];
$template = 'view';
include($include_path.'template.php');
}
// else id is not present
else
{
$template = 'id_error';
include($include_path.'template.php');
}
}
// So if no id is defined... lets see weither to send or to compose?
else
{
if ($action == 'send')
{
// Check the variables for IsSet & syntaxis:
if ($subject == '')
{
$error1 = $lang['enter_subject'].'<br><br>';
}
if (($msg == '') or ($msg == $lang['type_msg']))
{
$error2 = $lang['enter_msg'].'<br><br>';
}
if (($sender_name == '') or ($sender_name == $lang['name_here']))
{
$error3 = $lang['enter_sender_name'].'<br><br>';
}
if ((!IsEmail($sender_email)) or ($sender_email == ''))
{
$error4 = $lang['enter_sender_email'].'<br><br>';
}
if ($recipient_name == '')
{
$error5 = $lang['enter_recipient_name'].'<br><br>';
}
if ((!IsEmail($recipient_email)) or ($recipient_email == ''))
{
$error6 = $lang['enter_recipient_email'].'<br><br>';
}
$error = $error1.$error2.$error3.$error4.$error5.$error6;
if ($error == '')
{
// So the form is submitted and there are no errors
// ... now we can save the data and email the recipient
$teller = fread(fopen($include_path.'userdata/teller.txt',"r"),4096) + 1;
fwrite(fopen($include_path.'userdata/teller.txt',"w+"),$teller);
$id = 'CRD'.date("ymdHi").$teller;
$CRD_datafile =
'<?php
$notify_sender = "'.$notify_sender.'";
$sender_email = "'.$sender_email.'";
$recipient_email = "'.$recipient_email.'";
$date = "'.date("d-m-Y").'"; $time = "'.date("H:i").'"; $card = "'.$card.'";
$index_url = "http://'.$_SERVER['SERVER_NAME'].$PHP_SELF.'";
?>';
fwrite(fopen($include_path.'userdata/'.$id.'.php',"w+"),$CRD_datafile);
$notify_mail_recipient = $lang['dear_recipient']."\n\n".$lang['sender_has_sent']."\n\n". $lang['get_card_here'] ."\n".'http://'.$_SERVER['SERVER_NAME'].$PHP_SELF.'?id='.$id."\n\n". $lang['time_limit']."\n\n". $lang['regards'] ."\n\n$service_name (".$admin_email.')'.$add;
mail($recipient_email,$lang['notify_recipient_subject'],$notify_mail_recipient, "From: E-Card service<$admin_email>");
if ($notify_sender == 'off')
{
$lang['card_viewed_confirm'] = '';
}
$template = 'sent';
include($include_path.'template.php');
}
// Else if no sending is wanted or if there are errors ...
elseif ($error != '')
{
$action = 'compose';
}
}
if ($action == 'compose')
{
if ((!IsSet($card)) or
($card == '')) {
// Show gallery
include($include_path.'_gallery.php');
}
else
{
// Check input fields for IsSet, if not assign defaults
if ((!IsSet($msg)) or
($msg == '')) {
$msg_echo = $lang['type_msg'];
}
else
{
$msg_echo = $msg;
}
if ((!IsSet($sender_email)) or
($sender_email == '')) {
$sender_email_echo = $lang['email_here'];
}
else
{
$sender_email_echo = $sender_email;
}
if ((!IsSet($sender_name)) or
($sender_name == '')) {
$sender_name_echo = $lang['name_here'];
}
else
{
$sender_name_echo = $sender_name;
}
// Include compose-template
$template = 'compose';
include($include_path.'template.php');
}
}
}
?>