HEX
Server: Apache
System: Linux 244.240.109.208.host.secureserver.net 5.14.0-611.11.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Dec 3 09:47:37 EST 2025 x86_64
User: icsla (1002)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/icsla/.trash/rteitel.com/documents/tell_friend.php
<?php
$version="tell a friend 1.60";
/*
	tell_friend.php
	http://www.ezgenerator.com
	Copyright (c) 2004-2009 Image-line
*/
include ('../documents/htmlMimeMail.php');
include_once ('../ezg_data/functions.php');
$sa_mode='1';  // 0- embedded on page with JS; 1- standalone (normal);  2- as hidden div; 3 - inside page
$root_mode='0';
$db_fname='../'.$f_db_folder.'tell_friend_log.ezg.php';
$frames_on=false;
$site_charsets_arr=explode('|', $f_site_charsets); array_pop($site_charsets_arr);
$site_languages_arr=explode('|', urldecode($f_site_languages)); array_pop($site_languages_arr);
$current_lang=(isset($_REQUEST['language'])?f_strip_tags($_REQUEST['language']):$site_languages_arr[0]);
if(!in_array($current_lang, $site_languages_arr)) $current_lang='';
$page_charset=$site_charsets_arr[array_search($current_lang, $site_languages_arr)] ; 
if($page_charset=='0')	$page_charset='utf-8'; elseif($page_charset=='') $page_charset='iso-8859-1';
$full_path=f_build_self_url('tell_friend.php');
$full_path_to_script=substr($full_path,0,strrpos($full_path, "/"));

$default_labels=array('tell_friend'=>'tell a friend', 'your_name'=>'your name', 'your_email'=>'your email', 'recipient_email'=>'recipient email', 'message'=>'message', 'send'=>'send', 'clear_fields'=>'clear fields', 'close'=>'close', 'administrator'=>'administrator', 'required_msg'=>'Fields marked with * are required', 'email_msg'=>'Invalid email address', 'on_success_msg'=>'The Message Was Sent', 'on_fail_msg'=> 'The Message Could Not Be Sent', 'code'=>'code'); 
$settings_keys=array('tell_friend', 'your_name', 'your_email', 'recipient_email', 'message', 'send', 'clear_fields', 'close', 'administrator', 'required_msg', 'email_msg', 'on_success_msg', 'on_fail_msg', 'code', 'from_address', 'subject', 'default_message', 'hidden_message', 'include_url', 'allow_msg_change','include_captcha'); 
$default_msg="Dear Friend, I am happy to share with you this interesting site:";
$source_page=f_define_source_page();
$rel_path=(strpos($source_page,'../')===false? '': '../'); 
$source_page=(strpos($source_page,'../')!==false? '': '../').$source_page;
$doc_dir='documents';
$doc_dir_path=$rel_path.$doc_dir.'/';
// ---------------------------------------------------------------------
function show_error($error)
{
	global $source_page,$db_fname;
	print f_fmt_in_template($source_page,f_fmt_error_msg($error,$db_fname));
}
function prepare_for_write($data)
{
	foreach ($data as $k=>$v) {$temp=trim($v); $data[$k]=f_esc($v);}
	$line=implode('|',$data);
	return $line;
}
function build_ass_array_record($value, $key)  // format data  from db  as a record (associative array)
{
	$output=array();
	foreach($key as $k=>$v) { $output[$v]=(current($value)?current($value):'NULL'); next($value); }
	return $output;
}
function define_lang_label($name)
{
	global $default_labels,$settings;
	return (isset($settings[$name]) && $settings[$name]!='NULL'? f_sth($settings[$name]): $default_labels[$name]);
}
function GT($html_output,$msg,$include_menu=true) 
{
	global $doc_dir,$sa_mode,$f_bg_tag,$source_page,$rel_path,$full_path_to_script;

	$contents=f_fmt_in_template($source_page,$html_output,'',$f_bg_tag,$include_menu);
	if($sa_mode!='3' && (!$include_menu)) 
	{ 
		$contents=str_replace(f_GFS($contents,'<!--menu_java-->','<!--/menu_java-->'),'',$contents);
		$contents=str_replace('onload="preloadimages();"','',$contents);
	}	
	if($rel_path=='')
	{
		$contents=str_replace('</title>','</title> <base href="'.str_replace($doc_dir,'',$full_path_to_script).'">',$contents);
		$contents=str_replace('action="../','action="',$contents); 
	}
	$contents=str_replace('<title>'.f_GFS($contents,'<title>','</title>').'</title>','<title>'.$msg.'</title>',$contents);
	$contents=f_removeAreas($contents);
	return $contents;
}
function db_write_data($record_line,$open_tag,$close_tag,$flag='log')  //  writing data in log file
{
	global $db_fname,$f_db_first_line,$f_db_last_line,$f_lf;

	$buf='';$old_data='';
	clearstatcache();
	if(file_exists($db_fname))
	{
		if(!$handle=@fopen($db_fname,"r+")) {print show_error('DBFILE_NEEDCHMOD'); exit;}
		flock($handle,LOCK_EX);
		if(filesize($db_fname)==0) $buf.=$f_db_first_line.$open_tag.$record_line.$close_tag.$f_db_last_line;
		else 
		{
			$old_data=fread($handle,filesize($db_fname));
			if($flag=="log")
			{
				if(strpos($old_data,$close_tag)!==false) $buf.=str_replace($close_tag,$record_line.$close_tag." ",$old_data);
				else $buf.=str_replace($f_db_last_line,$open_tag.$record_line.$close_tag.$f_db_last_line,$old_data);
			}
			else
			{
				if(strpos($old_data,$close_tag)!==false)
				{
					$for_replace=substr($old_data,strpos($old_data, $open_tag),strpos($old_data, $close_tag)-strpos($old_data,$open_tag)+ strlen($close_tag));
					$buf.=str_replace(trim($for_replace),$open_tag.$record_line.$close_tag." ",$old_data);
				}
				else $buf.=str_replace($f_db_last_line,$open_tag.$record_line.$close_tag.$f_db_last_line,$old_data);
			}
			if(ftruncate($handle,0)===false) {echo "Failed to truncate file --> last update failed"; exit;}
			fseek($handle,0);
		}
		if(fwrite($handle,$buf)===FALSE) {echo "Failed to edit file --> last update failed";exit;}
		flock($handle,LOCK_UN);
		fclose($handle);
	}
}
function build_tell_friend_form($suggested_url,$msg='',$sender_name='',$sender_from='',$send_to='',$message='')
{
	global $full_path_to_script,$current_lang,$default_msg,$f_br,$f_ct,$frames_on,$sa_mode,$f_lf,$doc_dir,$rel_path,$root_mode,$settings;

	$span8='<span class="rvts8">%s<em style="color:red;">*</em></span>'.$f_br;

	if(strpos($suggested_url,"../")!==false)
		$full_path_fixed=str_replace('/'.$doc_dir,'',$full_path_to_script).str_replace('..','',$suggested_url);
	else if(strpos($suggested_url,"/")==0)
		$full_path_fixed=str_replace('/'.$doc_dir,'/',$full_path_to_script).str_replace('..','',$suggested_url);
	else 
		$full_path_fixed=$full_path_to_script."/".str_replace($doc_dir.'/','',$suggested_url);
	
	if($settings['include_url']=='no') $full_path_fixed='';		
	if($frames_on) $full_path_fixed=$full_path_to_script."/". "tell_friend.php?action=load&amp;language=".$current_lang.'&amp;url='.$full_path_fixed;
	
	$default_message=($message!='')?f_sth($message):(($settings['default_message']!='NULL'? f_sth($settings['default_message']): $default_msg).' '.$full_path_fixed);

	if($sa_mode=='0') $default_message=str_replace(array("\r\n","\r","\n"),array("","",""),$default_message);

	$script_folder=($sa_mode==1 || $sa_mode==3? $rel_path: (substr_count($suggested_url, '/')>1? '../': '')).$doc_dir;

	$output='<div style="padding:10px">'.$f_br.'<form name="tell_friend_frm" action="'.$script_folder.'/tell_friend.php?action=send&amp;sa='.f_sth($sa_mode).($root_mode=='1'? '&amp;root='.f_sth($root_mode):''). (isset($_GET['divid'])?'&amp;divid='.f_sth(f_strip_tags($_GET['divid'])):''). ($sa_mode!='1'?'&amp;url='.$suggested_url:'').'" method="post" name="tell_friend">';
	$output.='<span class="rvts8"><b>'.define_lang_label('tell_friend').$f_br.$msg.'</b></span>'.$f_br;
	$output.=f_build_input_cap(define_lang_label('your_name'),true,'Sender',f_sth($sender_name),'width:270px',50).$f_br;
	$output.=f_build_input('language',$current_lang,'','','hidden');
	$output.=f_build_input_cap(define_lang_label('your_email'),true,'Sender_email',$sender_from,'width:270px',50).$f_br;
	$output.=f_build_input_cap(define_lang_label('recipient_email'),true,'Recipient_email',$send_to,'width:270px',50).$f_br;
	$output.=sprintf($span8,define_lang_label('message'));
	$output.='<textarea class="input1" style="width:270px" name="Message" cols="50" '.($settings['allow_msg_change']=='no'?'readonly="readonly"':'').' rows="15">'.$default_message.'</textarea>'.$f_br;
	
	if($settings['include_captcha']=='yes')
	{
		$output.=sprintf($span8,define_lang_label('code')).'<input class="input1" type="text" name="Validator" id="validator" size="6" maxlength="4"'.$f_ct; 
		if(f_is_able_build_img()) {$output.=' <img src="'.$script_folder.'/tell_friend.php?action=captcha" border="0" alt="" style="vertical-align: middle;"'.$f_ct;}
		else
		{
			$captcha=f_generate_captcha_code(); 
			f_set_session_var('CAPTCHA_CODE',md5($captcha));
			$output.=' <span class="rvts0"><b>'.$captcha.'</b></span>';
		}
		$output.=$f_br.$f_br;
	}
	$output.=f_build_input('Send',define_lang_label('send'),'','','submit');
	$output.=' '.f_build_input('Send',define_lang_label('clear_fields'),'','','button','onclick="javascript:document.tell_friend_frm.reset();"');
	if($sa_mode=='1') $output.=' '.f_build_input('Send',define_lang_label('close'),'','','button','onclick="javascript:window.close();"');
	$output.='</form></div>';
	return $output;
}
function build_settings_form() 
{
	global $site_languages_arr,$current_lang,$settings,$default_labels,$f_br,$f_ct,$doc_dir_path,$doc_dir,$full_path_to_script,$rel_path;
	
	$input='<input class="input1" type="text" name="%s" value="%s" style="width:450px" maxlength="250"'.$f_ct;
	$input_c='<input type="checkbox" name="%s" value="yes" %s'.$f_ct.'%s';
	$area='<textarea class="input1" name="%s" cols="80" rows="8" style="width:450px">%s</textarea>'; 
	$jstring='onchange="document.location=\''.(($rel_path=='')?f_build_self_url('tell_friend.php'):'tell_friend.php').'?action=admin&amp;language=\' + this.options[this.selectedIndex].value;"';
	
	$table_data=array();		
	$table_data[]=array('language',f_build_select("language",$site_languages_arr,$current_lang,'','value',$jstring));
	foreach($settings as $k=>$v) 
	{
		if(array_key_exists($k,$default_labels)) 
		{
			if($k=='required_msg')		$ms='required fields msg';
			elseif($k=='email_msg')		$ms='email not valid msg'; 
			elseif($k=='on_fail_msg')	$ms='fail message';
			elseif($k=='on_success_msg')$ms='success message';
			else $ms=$default_labels[$k];
			$table_data[]=array($ms, sprintf($input,$k,($v!='NULL'?f_sth($v):'')));
		}
	}	
	$table_data[]=array(''.$f_br.'from address', sprintf($input,'from_address',($settings['from_address']=='NULL'?'':f_sth($settings['from_address']))));
	$table_data[]=array('subject', sprintf($input,'subject',($settings['subject']=='NULL'?'':f_sth($settings['subject']))));
	
	$table_data[]=array('Default message',sprintf($area,'default_message', ($settings['default_message']=='NULL'?'':f_sth($settings['default_message']))));
	$table_data[]=array('Hidden message',sprintf($area,'hidden_message', ($settings['hidden_message']=='NULL'?'': f_sth($settings['hidden_message']))));
	$table_data[]=sprintf($input_c,'include_url',(($settings['include_url']=='yes')?" checked='checked'" :''),'<span class="rvts8">Include page URL in msg</span>');
	$table_data[]=sprintf($input_c,'allow_msg_change',(($settings['allow_msg_change']=='yes')?' checked="checked"':''),'<span class="rvts8">Allow users to edit msg</span>');
	$table_data[]=sprintf($input_c,'include_captcha',(($settings['include_captcha']=='yes')?' checked="checked"':''),'<span class="rvts8">Include captcha</span>');
	$table_data[]=$f_br.'<input class="input1" name="save" type="submit" value=" '.'save changes'.' "'.$f_ct.$f_br.$f_br;
	
	$output='<div><form method="post" action="'.$doc_dir_path.'tell_friend.php?action=admin">';
	$output.=f_addentrytable('settings ', $table_data);
	$output.='</form></div>';
	return $output;
}
function send($suggested_url) 
{
	global $f_mail_type,$f_use_linefeed,$f_lf,$sa_mode,$page_charset,$doc_dir,$f_return_path,$f_SMTP_HOST,$f_SMTP_PORT,$f_SMTP_HELLO,
		$f_SMTP_AUTH,$f_SMTP_AUTH_USR,$f_SMTP_AUTH_PWD, $f_br, $f_ct, $f_sendmail_from, $f_http_prefix,$full_path_to_script,$root_mode,$settings;

	$output=''; $spem='<span class="rvts8"><em style="color: red;">'; $dir=$doc_dir.'/';
	$sender_name=f_un_esc(f_strip_tags($_POST['Sender']));
	$sender_email=f_strip_tags($_POST['Sender_email']);
	$send_to=f_strip_tags($_POST['Recipient_email']);
	$message=f_un_esc(f_strip_tags($_POST['Message']));
	$send_to_array=array(f_strip_tags($_POST['Recipient_email']));
	$sender_ip=(isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:"unknown");
	
	if($f_sendmail_from!='') ini_set('sendmail_from',$f_sendmail_from);
	if(empty($_SESSION)) f_int_start_session();
	if(!f_is_logged('SID_ALLOW_TELLFRIEND')) {echo "This is illegal operation. You are not allowed to use this Tell a friend.";exit;}

	if(isset($_POST['Send']))
	{
		$spam_check=str_replace($f_http_prefix.$_SERVER['HTTP_HOST'],'',$message);
		$errors='';
		if(empty($_POST['Sender']) || empty($_POST['Sender_email']) || empty($_POST['Recipient_email']) || empty($_POST['Message'])) 
		{
			$errors=define_lang_label('required_msg');	
		}
		elseif(!f_validate_email($sender_email)) {$errors=define_lang_label('email_msg'); $sender_email='';	}
		elseif(!f_validate_email($send_to))		{$errors=define_lang_label('email_msg'); $send_to='';}
		elseif(($settings['include_captcha']=='yes') && (!isset($_POST['Validator']) || $_POST['Validator']=='' || md5(strtolower($_POST['Validator']))!=$_SESSION['CAPTCHA_CODE'])) 
		{
			$errors=define_lang_label('required_msg');	
		}
		elseif(strpos($spam_check,'http:')!==false || strpos($spam_check,'https:')!==false || strpos($spam_check,'www.')!==false) 
		{
			$errors="You are not allowed to include external url in message.";	
		}

		if($errors!='')
		{
			$msg=$spem.$errors."</em></span>";	
			$output.=build_tell_friend_form($suggested_url,$msg,$sender_name,$sender_email,$send_to,$message);
		}
		else 
		{
			$message.=$f_lf.$f_lf.(($settings['hidden_message']!='NULL')? str_replace(array('\\\\','\\\'','\"'), array('\\','\'','"'), $settings['hidden_message']): "");
			$send_from=(($settings['from_address']!='NULL')? $settings['from_address']: $sender_email);
			$message=str_replace(array("%%SENDERNAME%%","%%SENDEREMAIL%%"),array($sender_name,$sender_email), $message);
			$message=str_replace(array("%%SENDERIP%%","%%RECIPIENTEMAIL%%"),array($sender_ip,$send_to), $message);

			$mail=new htmlMimeMail();
			if($f_use_linefeed) $mail->setCrlf($f_lf);
			$mail->setHeadCharset($page_charset); 
			$mail->setTextCharset($page_charset); 
			$mail->setSubject(($settings['subject']!='NULL')?str_replace(array('\\\\','\\\'','\"'),array('\\','\'','"' ),$settings['subject']): 'I want to share with you');
			$mail->setText(str_replace(array('\\\\','\\\'','\"'),array('\\','\'','"'),$message));				
			$mail->setFrom(str_replace(array('\\\\','\\\'','\"'),array('\\','\'','"'),$send_from));
			if ($f_return_path!= '')  $mail->setReturnPath($f_return_path);
			if(($f_mail_type=='smtp')&&($f_SMTP_HOST!=='')) $mail->setSMTPParams($f_SMTP_HOST,$f_SMTP_PORT,$f_SMTP_HELLO,$f_SMTP_AUTH,$f_SMTP_AUTH_USR,$f_SMTP_AUTH_PWD);

			$output.='<div align="center">'.$f_br.'<span class="rvts8">';
			if((strpos(strtolower($message),'mime-version')!==false) || (strpos(strtolower($message),'content-type')!==false))
			{
				$msg="FAILED - possible dangerous content";
				$output.=define_lang_label('on_fail_msg')."</span>";
			}
			else 
			{
				$result=$mail->send($send_to_array,$f_mail_type);
				if($result) { $msg="SENT"; $output.=define_lang_label('on_success_msg')."</span>";}
				else { $msg="FAILED"; $output.=define_lang_label('on_fail_msg')."</span>"; }
			}
			if($sa_mode=='1')
			{ 
				$output.=$f_br.$f_br.'<input class="input1" type="button" value=" '.define_lang_label('close').' " onclick="javascript:window.close();"'.$f_ct;
			}
			$output.="</div>";
			$msg=preg_replace("'<[/!]*?[^<>]*?>'si"," ",$msg); $msg=str_replace($f_lf,'',$msg);
			$record_line=mktime()."==>". $sender_email.','.$sender_ip.','.$send_to.','.urlencode($message).'==>'.$msg.$f_lf;
			$record_line=str_replace(array('\\\\', '\\\'', '\"'),array( '\\', '\'', '"' ),$record_line) ; 
			db_write_data($record_line, '<LOG>', '</LOG>');
			f_unset_session();
		}
	}
	if($sa_mode=='1' || $sa_mode=='3')
	{
	  $output=GT($output,$settings['tell_friend'],$sa_mode=='3');
	  $output=str_replace('charset='.f_GFS($output,'charset=','"'),'charset='.$page_charset,$output);
	  print $output;
	}
	elseif($sa_mode=='2')
	{
		$fixed_url=(file_exists($suggested_url)?$suggested_url :'../'.$suggested_url );	
		$contents=f_read_file($fixed_url);

		$old_form=f_GFS($contents,'<!--tellfriend-->','<!--/tellfriend-->');
		$contents=str_replace($old_form,$output,$contents);

		$show_div='showHdiv('.f_sth(f_tags_strip($_GET['divid'])).',1000)';	
		$contents=str_replace(array('<BODY','</BODY'),array('<body','</body'),$contents);	
		$contents=str_replace(array('ONLOAD=','onLoad='),array('onload=','onload='),$contents);
		$old_body='<body'.f_GFS($contents,'<body','</body>').'</body>';
		if(strpos($old_body, 'onload="')!==false) $new_body=str_replace('onload="','onload="'.$show_div.';',$old_body);	
		else $new_body=str_replace('<body','<body onload="'.$show_div.';"',$old_body); 
		$contents=str_replace($old_body,$new_body,$contents);
		if($root_mode=='1') 
		{ 
			$contents=str_replace('</title>','</title> <base href="'.str_replace($doc_dir,'',$full_path_to_script).'">',$contents); 
			$contents=str_replace('action="../','action="',$contents); 
		}
		print $contents;
	}
	else
	{
		$fixed_url=(file_exists($suggested_url)?$suggested_url :'../'.$suggested_url );
		$contents=f_read_file($fixed_url);

		$j_scr='<script language="javascript" type="text/javascript" src="%stell_friend.php';
		$pat=sprintf($j_scr,$dir);
		if(strpos($contents,$pat)===false)$pat=sprintf($j_scr,'../'.$dir);
		$pattern=f_GFSAbi($contents,$pat,'</script>');
		$contents=str_replace($pattern, $output, $contents);
		if($root_mode=='1') 
		{ 
			$contents=str_replace('</title>','</title> <base href="'.str_replace($doc_dir,'',$full_path_to_script).'">',$contents); 
			$contents=str_replace('action="../','action="',$contents); 
		}
		print $contents;
	}
}
function build_admin_screen($action_id)
{
	global $db_fname,$current_lang,$doc_dir_path,$page_charset,$f_br,$f_ct,$f_lf;
	
	$span8='<span class="rvts8">';
	$logcontent=''; $output=''; $record_array=array();
	$url=$doc_dir_path.'tell_friend.php?action=';
	$captions=array(); $urls=array(); 
	$captions[]='settings'; $urls[]=$url."admin&amp;language=".$current_lang;
	$captions[]='check log'; $urls[]=$url."checklog&amp;language=".$current_lang;
	$captions[]='logout'; $urls[]=$doc_dir_path."centraladmin.php?process=logoutadmin";
	$captions[]='CENTRAL ADMIN'; $urls[]=$doc_dir_path."centraladmin.php?process=index";
	$admin_menu=f_admin_navigation($captions,$urls,($action_id=='admin'?0:1));

	if(!file_exists($db_fname)) {print show_error('MISSING_DBFILE'); exit;}
	
	$output.='<div align="center">';
	if($action_id=='checklog' && isset($_POST['clear_log'])) 
	{
		if(filesize($db_fname)>0) 
		{
			if(!$handle=@fopen($db_fname,'r+')) {print show_error('DBFILE_NEEDCHMOD'); exit;}
			flock($handle,LOCK_EX);
			$logcontent=fread($handle,filesize($db_fname));
			if(strpos($logcontent,'<LOG>')!==false) 
			{
				$buf=f_GFS($logcontent,'<LOG>','</LOG>');
				$logcontent=str_replace($buf," ",$logcontent);
				if(ftruncate($handle,0)===false) {echo "Failed to truncate file --> last update failed";exit;}
				fseek($handle,0);
				if(fwrite($handle,$logcontent)===FALSE) {echo "Failed to edit file --> last update failed";exit;}
				$output.=$f_br.$span8.'Log file was cleared.</span>';
			}
			else $output.=$f_br.$span8.'Log file is empty. No need to clear it.</span>';
			flock($handle,LOCK_UN);
			fclose($handle);
		}
		else $output.=$f_br.$span8.'Log file is empty. No need to clear it. </span>';
	}
	elseif($action_id=='checklog') 
	{
		$max_rec=20;$log_output=array();
		if(file_exists($db_fname))
		{
			$logcontent=f_read_file($db_fname);
			$logcontent=trim(f_GFS($logcontent,'<LOG>','</LOG>'));
			$lines_a=explode($f_lf,$logcontent); $count=count($lines_a);
			for($i=0;$i<$count;$i++) 
			{ 
				if(!empty($lines_a[$i]) && $lines_a[$i]!=' ' && strpos($lines_a[$i],'==>')!==false)
				{ 
					list($tt,$gg)=explode('==>',$lines_a[$i]); $tt=trim($tt);
					if(!empty($tt)) 
					{ 
						if(substr_count($lines_a[$i],'==>')>=2) { list($date,$details,$result)=explode('==>',$lines_a[$i]);}
						else 
						{
							list($date,$details)=explode('==>',$lines_a[$i]); 
							$temp=f_GFSAbi($logcontent,$date,'==> Result:'); 
							list($date,$details,$result)=explode('==>',$temp);			
						}			
						$pos_msg=strpos($details,'Message:');
						if($pos_msg!==false) {  $message= substr($details,$pos_msg); list($sender,$ip,$recipient)=explode(',',$details); }
						else { list($sender,$ip,$recipient,$message)=explode(',',$details); }
						$sender=str_replace('Sender:','',$sender); $ip=str_replace('Sender IP:','',$ip);
						$recipient=str_replace('Recipient:','',$recipient); $message=str_replace('Message:','',$message);

						if(empty($result)) 
							{$result=(strpos($lines_a[$i+2],'Result:')!==false)? trim($lines_a[$i+2]): ''; $result=str_replace('==>','',$result);}
						$log_output[]=array('date'=>trim($date),'sender'=>trim($sender).$f_br.f_ip_locator(trim($ip)),'recipient'=>trim($recipient),
							'message'=>trim(urldecode($message)), 'result'=>str_replace('Result:','',trim($result)));
					}
				}
			}
		}	
		if(!empty($log_output))
		{
			$log_output=array_reverse($log_output);
			$records_count=count($log_output);
			$screen=(isset($_GET['page'])? intval($_GET['page']):1); 
			$offset=($screen==1)?0:($screen-1)*$max_rec;
			$limit_rec_to=($screen*$max_rec>$records_count)?$max_rec-($screen*$max_rec-$records_count):$max_rec;
			$show_records=array_slice($log_output,$offset,$limit_rec_to);
				
			$nav_labels=array('first'=>'first','prev'=>'prev','next'=>'next','last'=>'last');
			$url_part=$url.'checklog&amp;language='.$current_lang;
			$nav=f_page_navigation($records_count, $url_part, $max_rec, $screen, 'of', "class='rvts12'", $nav_labels);
			$cap_arrays=array('date','sender','recipient','message','result');
			$table_data=array();
				
			foreach($show_records as $key=>$value)
			{
				if(!empty($value)) 
				{
					if(strpos($value['date'],':')) $date_value=$value['date'];
					else $date_value=date("d M Y H:i:s",f_tzone_date($value['date']));
					$row_data=array($span8.$date_value."</span>",$span8.$value['sender']."</span>", $span8.$value['recipient']."</span>", $span8.$value['message']."</span>",$span8.$value['result']."</span>");
					$table_data[]=$row_data;	
				}
			}
			$append=$f_br.'<form method="post" action="'.$url.'checklog&amp;language='.$current_lang.'">'.'<input class="input1" type="submit" name="clear_log" value=" Clear Log " onclick="javascript:return confirm(\'Are you sure you want to clear this log file?\')"'.$f_ct."</form>";
			$output.=f_admintable($nav,$cap_arrays,$table_data,$append);
		}
		else $output.=$span8.'Log file is empty.'."</span>";
	}
	else 
	{
		if(isset($_POST['save']))
		{
			$lang=f_strip_tags($_POST['language']);
			foreach($_POST as $k=>$v)
			{
				if($k!='language' && $k!='save' && $k!='allow_msg_change' && $k!='include_url' && $k!='include_captcha') $record_array[$k]=($v!='')?$v:'NULL';
			}
			$record_array['include_url']=(isset($_POST['include_url']))? 'yes': 'no'; 
			$record_array['allow_msg_change']=(isset($_POST['allow_msg_change']))? 'yes': 'no';
			$record_array['include_captcha']=(isset($_POST['include_captcha']))? 'yes': 'no';
			
			$record_line=prepare_for_write($record_array);
			db_write_data($record_line,"<LANGUAGE_$lang>","</LANGUAGE_$lang>",'lang');
			$output.=$span8.'Settings saved.</span>';
		}
		else {$output.=build_settings_form();}
	}
	$output.="</div>";
	$output=f_fmt_admin_screen($output,$admin_menu);
	$output=GT($output,'Tell A Friend Admin'); 
	$output=str_replace('charset='.f_GFS($output,'charset=','"'),'charset='.$page_charset,$output);
	print $output;
}
function process_tell()
{
	global $sa_mode,$root_mode,$version,$doc_dir_path,$db_fname,$settings,$source_page,$db_fname,$current_lang,$settings,$settings_keys, $default_labels,$page_charset,$doc_dir;	

	$suggested_url='';
	if(isset($_GET['url'])) $suggested_url=f_strip_tags($_GET['url']);
	if(isset($_REQUEST['sa'])) $sa_mode=f_strip_tags($_REQUEST['sa']);
	if(isset($_REQUEST['root'])) $root_mode=f_strip_tags($_REQUEST['root']);
	$action_id=(isset($_REQUEST['action']))?f_strip_tags($_REQUEST['action']):'index';
	
	if($action_id!="version" && $action_id!="captcha")
	{
		$db_content=f_read_file($db_fname);
		if($db_content=='') 
		{
			f_db_convert("../documents/tell_friend_log.ezg.php",$db_fname);
			$db_content=f_read_file($db_fname);
		}	
		if(strpos($db_content,'<LANGUAGE_'.$current_lang)!==false)
		{
			$settings_raw=explode('|', f_GFS($db_content,'<LANGUAGE_'.$current_lang.'>','</LANGUAGE_'.$current_lang.'>'));
			$settings=build_ass_array_record($settings_raw, $settings_keys);
		}
		else  {$settings=array_merge($default_labels, array('from_address'=>'NULL', 'subject'=>'NULL', 'default_message'=>'NULL', 'hidden_message'=>'NULL', 'include_url'=>'yes', 'allow_msg_change'=>'yes','include_captcha'=>'yes'));}
		$db_content='';
	}

	if($action_id=="index")
	{
		if(empty($_SESSION)) {f_int_start_session();}
		f_set_session_var('SID_ALLOW_TELLFRIEND',session_id());
		$output=build_tell_friend_form($suggested_url);
		if($sa_mode=='1' || $sa_mode=='3') 
		{
			$output=GT($output,$settings['tell_friend'],$sa_mode=='3');
			$output=str_replace('charset='.f_GFS($output,'charset=','"'),'charset='.$page_charset,$output);
			print $output;
		}
		else print "document.write('".$output."');";
	}
	elseif($action_id=="send")	  {send($suggested_url);}
	elseif($action_id=="version") {echo $version;}
	elseif($action_id=="captcha")	
		{$captcha=f_generate_captcha_code(); f_set_session_var('CAPTCHA_CODE',md5($captcha)); f_draw_captcha(strtoupper($captcha));}
	elseif($action_id=="admin" || $action_id=="checklog")
	{
 		if(empty($_SESSION)) f_int_start_session();
		if(function_exists('session_regenerate_id') && version_compare(phpversion(),"4.3.3",">=")) session_regenerate_id();  
		if(!f_is_logged('SID_ADMIN') || f_is_logged('HTTP_USER_AGENT') && ($_SESSION['HTTP_USER_AGENT']!=md5($_SERVER['HTTP_USER_AGENT'])))
			{f_url_redirect('../'.$doc_dir.'/'."centraladmin.php?process=index",false);exit;}
		build_admin_screen($action_id);
	}
}

process_tell();

?>