<?PHP
function can_i_use_nslookup_via_php()
	{
	@exec("nslookup google.com -sil", $result);

	$buffer="";
	foreach ($result as $result) { $buffer.=$result; }

	if (trim($buffer)!="") { return 0; }
	else { return 1; }
	}

# parse out lang. dir's
function available_languages($server_inc)
	{
	$buffer="";
	clearstatcache();
	if ($dir=opendir($server_inc."/languages"))
		{
		while (false!==($file=readdir($dir))) 
			{ 
			if ($file!=="."&&$file!=="..") 
				{ 
				if (is_dir($server_inc."/languages/".$file)) 
					{ 
					$buffer.=$file."|"; 
					}
				}
			}
		closedir($dir);
		}

	return $buffer;
	}

# recreate and resend password to client who enters
# an email address
function recreate_password($email, $site_name, $email_admin)
	{
	# create a password
	$password=substr(create_sid(), 0, 8);

	# encrypt it
	$xpassword=md5(strtolower($password));
	
	# update the user table with new information
	$query="update ";
	$query.="user ";
	$query.="set ";
	$query.="password='".addslashes(trim($xpassword))."' ";
	$query.="where ";
	$query.="email='".addslashes(strtolower($email))."'";

	mysql_query($query);

	# pull in username for email below
	$query1="select ";
	$query1.="username ";
	$query1.="from ";
	$query1.="user ";
	$query1.="where ";
	$query1.="email='".addslashes(strtolower($email))."'";

	$rs1=mysql_fetch_row(mysql_query($query1));

	# define vars
	# {{generate_date}}
	# {{site_name}}
	# {{username}}
	# {{password}}

	$generate_date=date("m/d/Y h:i:s a");
	$username=stripslashes(trim($rs1[0]));

	# pull in email template
	$query2="select ";
	$query2.="subject, ";
	$query2.="message ";
	$query2.="from ";
	$query2.="email_templates ";
	$query2.="where ";
	$query2.="emid='33'";

	$rs2=mysql_fetch_row(mysql_query($query2));

	$subject=stripslashes(trim($rs2[0]));
	$message=stripslashes(trim($rs2[1]));
	
	# parse out templates
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);
	$subject=str_replace("{{site_name}}", $site_name, $subject);
	$subject=str_replace("{{username}}", $username, $subject);
	$subject=str_replace("{{password}}", $password, $subject);
	
	$message=str_replace("{{generate_date}}", $generate_date, $message);
	$message=str_replace("{{site_name}}", $site_name, $message);
	$message=str_replace("{{username}}", $username, $message);
	$message=str_replace("{{password}}", $password, $message);

	// mail out the email
	mail($email, $subject, $message, "From: ".$email_admin."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}

// checks addon_specs to see if any of the
// addon_choices is a dedicated IP
function display_addons_ordered_clientarea($addon_choices, $http_images)
	{
	echo("
		<table width='100%' cellpadding='2' cellspacing='0' border='0'>
			<tr>
				<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='4'></td>
			</tr>
			<tr>
				<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'>Package Addons:</td>
			</tr>
			<tr>
				<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='2'></td>
			</tr>
		");
	$count=substr_count($addon_choices, "|");
	$explode=explode("|", $addon_choices);
	for ($i=0; $i<=$count; $i++) 
		{ 
		if (trim($explode[$i])!="")
			{
			$query2="select ";
			$query2.="addon_name, ";				// 0
			$query2.="setup_cost, ";				// 1
			$query2.="setup_activate, ";			// 2
			$query2.="addon_cost, ";				// 3
			$query2.="addon_state, ";				// 4
			$query2.="addon_activate ";				// 5
			$query2.="from addon_specs ";
			$query2.="where aid='".addslashes(trim($explode[$i]))."'";

			$rs2=mysql_fetch_row(mysql_query($query2));

			$addon_name=stripslashes(trim($rs2[0])); 
			$setup_cost=stripslashes(trim($rs2[1])); 
			$setup_activate=stripslashes(trim($rs2[2]));
			$addon_cost=stripslashes(trim($rs2[3]));
			$addon_state=stripslashes(trim($rs2[4]));
			$addon_activate=stripslashes(trim($rs2[5]));

			echo("
				<tr>
					<td align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'>".$addon_name."</td>
					<td align='left' valign='top'>
					<table width='100%' cellpadding='0' cellspacing='0' border='0'>
						<tr>
							<td width='1%' align='left' valign='top'>Setup Fee:</td>
							<td width='99%' align='left' valign='top'>
						");
					if ($setup_activate==1) { echo $currency."".sprintf("%01.2f", $setup_cost)." ".$currency_type; }
					else { echo "No Cost"; }
					echo("
							</td>
						</tr>
						<tr>
							<td width='1%' align='left' valign='top'>Cost:</td>
							<td width='99%' align='left' valign='top'>
						");
					if ($addon_activate==1) 
						{ 
						echo $currency."".sprintf("%01.2f", $addon_cost)." ".$currency_type; 
						
						if ($addon_state==1) { echo " One Time Fee"; }
						else if ($addon_state==2) { echo " Per Month"; }
						else if ($addon_state==3) { echo " Per Year"; }
						}
					else { echo "No Cost"; }
					echo("
							</td>
						</tr>
						<tr>
							<td width='1%' align='left' valign='top'><img src='".$http_images."/space.gif' width='100' height='12'></td>
							<td width='99%' align='left' valign='top'></td>
						</tr>
					</table>
					</td>
				</tr>
				");

			unset($addon_name);
			unset($setup_cost);
			unset($setup_activate);
			unset($addon_cost);
			unset($addon_state);
			unset($addon_activate);
			unset($query2);
			unset($rs2);
			}
		}
	echo"</table>";
	}

// clean the invoices temp files
function clean_dir($below_public)
	{
	clearstatcache();
	if ($dir = opendir($below_public))
		{
		while (false !== ($file = readdir($dir)))
			{					
			if (ereg("_invoice", $file)==true)
				{
				if ((fileatime($below_public."/".$file)+300)<=time())
					{
					unlink($below_public."/".$file);
					}
				}
			}
		closedir($dir);
		}
	}

// Create a session ID
function create_sid()
	{
	return md5(date("mdyhisa"));
	}

// CLIENT AREA/LOGIN FUNCTION

// returns 1 if administrators are defined
// returns 0 if not
function isset_admin()
	{
	$rs=mysql_fetch_row(mysql_query("select count(*) from user where status='69'"));
	if ($rs[0]>=1)
		{
		return 1;
		}
	else
		{
		return 0;
		}
	}

// update sid when un/pw are available to authenicate against
function update_sid_w_un_pw($username, $password, $sid)
	{
	mysql_query("update user set sid='".addslashes(trim($sid))."' where username='".addslashes(strtolower($username))."' and password='".md5(strtolower($password))."'");
	}

// update sid when un/pw are available to authenicate against
function update_sid_w_uid($uid, $sid)
	{
	mysql_query("update user set sid='".addslashes(trim($sid))."' where uid='".addslashes(strtolower($uid))."'");
	}

// authenicate user when un/pw are available to authenicate against
function auth_un_pw($username, $password)
	{
	$rs0=mysql_fetch_row(mysql_query("select count(*) from user where username='".addslashes(strtolower($username))."' and password='".md5(strtolower($password))."'"));

	return $rs0[0];
	}

// authenicate admin when un/pw are available to authenicate against
function auth_un_pw_admin($username, $password)
	{
	$rs0=mysql_fetch_row(mysql_query("select count(*) from user where username='".addslashes(strtolower($username))."' and password='".md5(strtolower($password))."' and status='69'"));

	return $rs0[0];
	}

// authenicate user when sid is available to authenicate against
function auth_sid($sid)
	{
	if (strlen(trim($sid))==0)
		{
		return 1;
		}
	else
		{
		$rs=mysql_fetch_row(mysql_query("select count(*) from user where sid='".addslashes(trim($sid))."'"));
		if ($rs[0]==1) 
			{ 
			return 0; 
			} 
		else 
			{ 
			return 1; 
			}
		}
	}

// renew the SID
function renew_sid($sid)
	{
	$uid=addslashes(trim($rs0[0]));
	$xsid=$sid;
	$sid=create_sid();
	
	mysql_query("update user set sid='".addslashes(trim($sid))."' where sid='".addslashes(trim($xsid))."'");

	return $sid;
	}

// authenicate user when sid is available to authenicate against
function auth_sid_admin($sid)
	{
	$rs=mysql_fetch_row(mysql_query("select count(*) from user where sid='".addslashes(trim($sid))."' and status='69'"));
	if ($rs[0]==1) 
		{ 
		return 0; 
		} 
	else 
		{
		return 1; 
		}
	}

// get the count of records that use x email in user table
function check_ct_user_by_email($email)
	{
	$rs0=mysql_fetch_row(mysql_query("select count(*) from user where email='".addslashes(strtolower($email))."'"));

	return $rs0[0];
	}

function grab_news($below_public)
	{
	// read in news file	
	$read = fopen ($below_public."/news.nfo", "r");
	$news = fread ($read, filesize($below_public."/news.nfo"));
	fclose ($read);
	
	$news=wordwrap($news, 45);

	return nl2br(trim($news));
	}

function grab_aff_para_admin($below_public)
	{
	if (!file_exists($below_public."/affiliate_paragraph.nfo"))
		{
		$news="";
		write_affiliate($below_public, $news);
		}
	else
		{
		// read in news file	
		$read=fopen($below_public."/affiliate_paragraph.nfo", "r");
		$news=fread($read, filesize($below_public."/affiliate_paragraph.nfo"));
		fclose($read);
		}

	return trim($news);
	}

function grab_aff_para($below_public)
	{
	// read in news file	
	$read = fopen ($below_public."/affiliate_paragraph.nfo", "r");
	$news = fread ($read, filesize($below_public."/affiliate_paragraph.nfo"));
	fclose ($read);
	
	// $news=wordwrap($news, 45);

	return nl2br(trim($news));
	}

function grab_news_admin($below_public)
	{
	if (!file_exists($below_public."/news.nfo"))
		{
		$news="";
		write_news($below_public, $news);
		}
	else
		{
		// read in news file	
		$read=fopen($below_public."/news.nfo", "r");
		$news=fread($read, filesize($below_public."/news.nfo"));
		fclose($read);
		}

	return trim($news);
	}

function write_affiliate($below_public, $news)
	{
	// read in news file	
	$read = fopen ($below_public."/affiliate_paragraph.nfo", "w");
	$news = fwrite ($read, trim($news));
	fclose ($read);

	chmod($below_public."/affiliate_paragraph.nfo", 0777);

	return 1;
	}

function write_news($below_public, $news)
	{
	// read in news file	
	$read = fopen ($below_public."/news.nfo", "w");
	$news = fwrite ($read, trim($news));
	fclose ($read);

	chmod($below_public."/news.nfo", 0777);

	return 1;
	}

function update_session_with_uid($sid, $username, $password)
	{
	// grab the uid
	$rs=mysql_fetch_row(mysql_query("select uid from user where username='".addslashes(trim($username))."' and password='".md5(strtolower($password))."'"));

	// update the session
	mysql_query("update session_history set uid='".addslashes(trim($rs[0]))."', ogcreate='".time."' where sid='".addslashes(trim($sid))."'");
	
	return 1;
	}

// END CLIENT AREA/LOGIN FUNCTION

// check to see if record is locked
function is_locked($sid)
	{
	$rs=mysql_fetch_row(mysql_query("select locked from session_history where sid='".addslashes(trim($sid))."'"));
	if ($rs[0]==1)
		{
		return 1;
		}
	}

// get the image for the payment type
function pay_image($payment_method, $http_images)
	{
	$rs3=mysql_fetch_row(mysql_query("select name from payment_process where pid='".addslashes(trim($payment_method))."'"));
	if (ereg("mail in payment", strtolower($rs3[0]))==true) { return "<img src='".$http_images."/mailin.gif'>"; }
	else if (ereg("paypal", strtolower($rs3[0]))==true) { return "<img src='".$http_images."/paypal.gif'>"; }
	else if (ereg("tpp-pro", strtolower($rs3[0]))==true) { return "<img src='".$http_images."/paysystems.gif'>"; }
	else if (ereg("worldpay", strtolower($rs3[0]))==true) { return "<img src='".$http_images."/worldpay.gif'>"; }
	else if (ereg("checkout", strtolower($rs3[0]))==true) { return "<img src='".$http_images."/2checkout.gif'>"; }
	else if (ereg("authorize", strtolower($rs3[0]))==true) { return "<img src='".$http_images."/authorize.gif'>"; }
	}

// Check for duplicate users
function check_user($username)
	{
	$rs0=mysql_fetch_row(mysql_query("select count(*) from user where username='".addslashes(trim(strtolower($username)))."'"));
	if ($rs0[0]<=0)
		{
		return 0;
		}
	else
		{
		return 1;
		}
	}

// Check for duplicate email
function check_email($email)
	{
	$rs0=mysql_fetch_row(mysql_query("select count(*) from user where email='".addslashes(trim(strtolower($email)))."'"));
	if ($rs0[0]<=0)
		{
		return 0;
		}
	else
		{
		return 1;
		}
	}

// If a domain has been unresolved within 48hours of install
// or within 48hrs of last resolve attempt
// send out an email letting them know of the issue
function send_unresolved_email($oid, $email_admin)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='1'"));
	$default_email=stripslashes(trim($rs[2]));

	// GATHER USER DATA
	# $rs0=mysql_fetch_row(mysql_query("select user.first_name, hosting_order.domain_name, hosting_order.ns1, hosting_order.ns2, UNIX_TIMESTAMP(hosting_order.ogcreate), user.email from user, hosting_order where user.uid=hosting_order.uid and hosting_order.oid='".addslashes(trim($oid))."' order by user.uid asc"));
	$rs0=mysql_fetch_row(mysql_query("select user.first_name, hosting_order.domain_name, hosting_order.ns1, hosting_order.ns2, hosting_order.ogcreate, user.email, hosting_order.whm_id from user, hosting_order where user.uid=hosting_order.uid and hosting_order.oid='".addslashes(trim($oid))."' order by user.uid asc"));
	
	// DEFINE VARs
	$first_name=stripslashes(trim($rs0[0]));
	$client_email=stripslashes(trim($rs0[5]));
	$domain_name=stripslashes(trim($rs0[1]));
	$generate_date=date("m/d/Y h:i:s a");
	$installed_date=date("m/d/Y", $rs0[4]);

	$rs1=mysql_fetch_row(mysql_query("select primary_ns, primary_ns_ip, secondary_ns, secondary_ns_ip from server_config where whm_id='".$rs0[6]."'"));
	
	$ns1=stripslashes(trim($rs1[0]));
	$ns1_ip=stripslashes(trim($rs1[1]));
	$ns2=stripslashes(trim($rs1[2]));
	$ns2_ip=stripslashes(trim($rs1[3]));

	// ATTRIBUTES AVAILABLE
	// {{first_name}}
	// {{domain_name}}
	// {{ns1}}
	// {{ns1_ip}}
	// {{ns2}}
	// {{ns2_ip}}
	// {{generate_date}}
	// {{installed_date}}

	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{first_name}}", $first_name, $subject);
	$subject=str_replace("{{domain_name}}", $domain_name, $subject);
	$subject=str_replace("{{ns1}}", $ns1, $subject);
	$subject=str_replace("{{ns1_ip}}", $ns1_ip, $subject);
	$subject=str_replace("{{ns2}}", $ns2, $subject);
	$subject=str_replace("{{ns2_ip}}", $ns2_ip, $subject);
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);
	$subject=str_replace("{{installed_date}}", $installed_date, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{first_name}}", $first_name, $message);
	$message=str_replace("{{domain_name}}", $domain_name, $message);
	$message=str_replace("{{ns1}}", $ns1, $message);
	$message=str_replace("{{ns1_ip}}", $ns1_ip, $message);
	$message=str_replace("{{ns2}}", $ns2, $message);
	$message=str_replace("{{ns2_ip}}", $ns2_ip, $message);
	$message=str_replace("{{generate_date}}", $generate_date, $message);
	$message=str_replace("{{installed_date}}", $installed_date, $message);

	mail($client_email, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}

// If a domain resolved successful
function send_successfully_resolved_email($oid, $email_admin)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='2'"));
	$default_email=stripslashes(trim($rs[2]));

	// GATHER USER DATA
	$rs0=mysql_fetch_row(mysql_query("select user.first_name, hosting_order.domain_name, hosting_order.whm_username, hosting_order.whm_password, user.email from user, hosting_order where user.uid=hosting_order.uid and hosting_order.oid='".addslashes(trim($oid))."' order by user.uid asc"));

	// DEFINE VARs
	$first_name=stripslashes(trim($rs0[0]));
	$domain_name=stripslashes(trim($rs0[1]));
	$username=stripslashes(trim($rs0[2]));
	$password=stripslashes(trim($rs0[3]));
	$generate_date=date("m/d/Y h:i:s a");
	$client_email=stripslashes(trim($rs0[4]));

	// ATTRIBUTES AVAILABLE
	// {{first_name}}
	// {{domain_name}}
	// {{username}}
	// {{password}}
	// {{generate_date}}

	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{first_name}}", $first_name, $subject);
	$subject=str_replace("{{domain_name}}", $domain_name, $subject);
	$subject=str_replace("{{username}}", $username, $subject);
	$subject=str_replace("{{password}}", $password, $subject);
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{first_name}}", $first_name, $message);
	$message=str_replace("{{domain_name}}", $domain_name, $message);
	$message=str_replace("{{username}}", $username, $message);
	$message=str_replace("{{password}}", $password, $message);
	$message=str_replace("{{generate_date}}", $generate_date, $message);

	mail($client_email, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}

// If a domain was resolved successfully, now is not!
function send_admin_notice_domain_stopped_responding($oid, $email_admin)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='3'"));
	$default_email=stripslashes(trim($rs[2]));

	// GATHER USER DATA
	$rs0=mysql_fetch_row(mysql_query("select domain_name, whm_id from hosting_order where oid='".addslashes(trim($oid))."'"));
	
	// GRAB THE SERVER NAME
	$rs1=mysql_fetch_row(mysql_query("select server_name from server_config where whm_id='".addslashes(trim($rs0[1]))."'"));

	// DEFINE VARs
	$domain_name=stripslashes(trim($rs0[0]));
	$server=stripslashes(trim($rs1[0]));
	$generate_date=date("m/d/Y h:i:s a");

	// ATTRIBUTES AVAILABLE
	// {{domain_name}}
	// {{server}} 
	// {{generate_date}}

	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{domain_name}}", $domain_name, $subject);
	$subject=str_replace("{{server}}", $server, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{domain_name}}", $domain_name, $message);
	$message=str_replace("{{server}}", $server, $message);
	$message=str_replace("{{generate_date}}", $generate_date, $message);

	mail($email_admin, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}
	
// Send out the resolver report
function send_resolve_report($email_admin, $number_resolved, $successful_domain_list, $number_unresolved, $unsuccessful_domain_list, $stopped_responding, $stopped_responding_list, $dom_30a, $dom_30, $dom_5a, $dom_5, $dom_expirea, $dom_expire)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='4'"));
	$default_email=stripslashes(trim($rs[2]));

	// DEFINE VARs
	$x30_day_ct=$dom_30a;

	if (strlen(trim($dom_30))==0)
		{
		$x30_day_list="- No 30 day expires for this run.";
		}
	else
		{
		$x30_day_list=$dom_30;
		}

	$x5_day_ct=$dom_5a;

	if (strlen(trim($dom_5))==0)
		{
		$x5_day_list="- No 5 day expires for this run.";
		}
	else
		{
		$x5_day_list=$dom_5;
		}

	$expired_ct=$dom_expirea;

	if (strlen(trim($dom_expire))==0)
		{
		$expired_list="- No expired domains for this run.";
		}
	else
		{
		$expired_list=$dom_expire;
		}

	$generate_date=date("m/d/Y h:i:s a");

	// ATTRIBUTES AVAILABLE
	// {{generate_date}}
	// {{number_resolved}}
	// {{successful_domain_list}}
	// {{number_unresolved}}
	// {{unsuccessful_domain_list}}
	// {{stopped_responding}}
	// {{stopped_responding_list}}
	// {{x30_day_ct}}
	// {{x30_day_list}}
	// {{x5_day_ct}}
	// {{x5_day_list}}
	// {{expired_ct}}
	// {{expired_list}}

	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);
	$subject=str_replace("{{number_resolved}}", $number_resolved, $subject);
	$subject=str_replace("{{successful_domain_list}}", $successful_domain_list, $subject);
	$subject=str_replace("{{number_unresolved}}", $number_unresolved, $subject);
	$subject=str_replace("{{unsuccessful_domain_list}}", $unsuccessful_domain_list, $subject);
	$subject=str_replace("{{stopped_responding}}", $stopped_responding, $subject);
	$subject=str_replace("{{stopped_responding_list}}", $stopped_responding_list, $subject);
	$subject=str_replace("{{x30_day_ct}}", $x30_day_ct, $subject);
	$subject=str_replace("{{x30_day_list}}", $x30_day_list, $subject);
	$subject=str_replace("{{x5_day_ct}}", $x5_day_ct, $subject);
	$subject=str_replace("{{x5_day_list}}", $x5_day_list, $subject);
	$subject=str_replace("{{expired_ct}}", $expired_ct, $subject);
	$subject=str_replace("{{expired_list}}", $expired_list, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{generate_date}}", $generate_date, $message);
	$message=str_replace("{{number_resolved}}", $number_resolved, $message);
	$message=str_replace("{{successful_domain_list}}", $successful_domain_list, $message);
	$message=str_replace("{{number_unresolved}}", $number_unresolved, $message);
	$message=str_replace("{{unsuccessful_domain_list}}", $unsuccessful_domain_list, $message);
	$message=str_replace("{{stopped_responding}}", $stopped_responding, $message);
	$message=str_replace("{{stopped_responding_list}}", $stopped_responding_list, $message);
	$message=str_replace("{{x30_day_ct}}", $x30_day_ct, $message);
	$message=str_replace("{{x30_day_list}}", $x30_day_list, $message);
	$message=str_replace("{{x5_day_ct}}", $x5_day_ct, $message);
	$message=str_replace("{{x5_day_list}}", $x5_day_list, $message);
	$message=str_replace("{{expired_ct}}", $expired_ct, $message);
	$message=str_replace("{{expired_list}}", $expired_list, $message);

	mail($email_admin, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}
	
// Display the resolver report
function display_resolve_report($email_admin, $individual)
	{
	GLOBAL $cron; 

	$query="select ";
	$query.="subject, ";
	$query.="message, ";
	$query.="default_email ";
	$query.="from ";
	$query.="email_templates ";
	$query.="where emid='4'";

	$rs=mysql_fetch_row(mysql_query($query));

	$default_email=stripslashes(trim($rs[2]));
	
	# ------------------------------------------------------------------
	
	if ($individual==0) { $results=resolver($email_admin); }
	else { $results=resolver_individual($email_admin, $individual); }

	list($resolved, $unresolved, $monitor, $domain_expire_30, $domain_expire_5, $domain_expired)=explode("{", $results);
	
	# list($resolved_data, $resolved_count)=explode("|", $resolved);
	# $resolved_data=$resolved_data;
	$resolved_data="";
	$resolved_count=0;
	$buffer=explode("|", $resolved);
	$total_count=(count($buffer)-1);
	foreach ($buffer as $current_count => $line)
		{
		if (strcmp($current_count, $total_count)!=0) 
			{ 
			if (strcmp("None for this run.", $line)!=0)
				{ 
				$resolved_data.=($current_count+1).". ".$line; 
				}
			else { $resolved_data.=$line; } 
			}
		else { $resolved_count=$line; }
		}
	unset($line);
	unset($total_count);
	unset($current_count);
	unset($buffer);
	

	$unresolved_data="";
	$unresolved_count=0;
	$buffer=explode("|", $unresolved);
	$total_count=(count($buffer)-1);
	foreach ($buffer as $current_count => $line)
		{
		if (strcmp($current_count, $total_count)!=0) 
			{ 
			if (strcmp("None for this run.", $line)!=0)
				{ 
				$unresolved_data.=($current_count+1).". ".$line; 
				}
			else { $unresolved_data.=$line; }  
			}
		else { $unresolved_count=$line; }
		}
	unset($line);
	unset($total_count);
	unset($current_count);
	unset($buffer);
	
	# list($monitor_data, $monitor_count)=explode("|", $monitor);
	# $monitor_data=$monitor_data;
	$monitor_data="";
	$monitor_count=0;
	$buffer=explode("|", $monitor);
	$total_count=(count($buffer)-1);
	foreach ($buffer as $current_count => $line)
		{
		if (strcmp($current_count, $total_count)!=0) 
			{ 
			if (strcmp("None for this run.", $line)!=0)
				{ 
				$monitor_data.=($current_count+1).". ".$line; 
				}
			else { $monitor_data.=$line; }  
			}
		else { $monitor_count=$line; }
		}
	unset($line);
	unset($total_count);
	unset($current_count);
	unset($buffer);
	
	# list($domain_expire_30_data, $domain_expire_30_count)=explode("|", $domain_expire_30);
	# $domain_expire_30_data=$domain_expire_30_data;
	$domain_expire_30_data="";
	$domain_expire_30_count=0;
	$buffer=explode("|", $domain_expire_30);
	$total_count=(count($buffer)-1);
	foreach ($buffer as $current_count => $line)
		{
		if (strcmp($current_count, $total_count)!=0) 
			{ 
			if (strcmp("None for this run.", $line)!=0)
				{ 
				$domain_expire_30_data.=($current_count+1).". ".$line; 
				}
			else { $domain_expire_30_data.=$line; }  
			}
		else { $domain_expire_30_count=$line; }
		}
	unset($line);
	unset($total_count);
	unset($current_count);
	unset($buffer);
	
	# list($domain_expire_5_data, $domain_expire_5_count)=explode("|", $domain_expire_5);
	# $domain_expire_5_data=$domain_expire_5_data;
	$domain_expire_5_data="";
	$domain_expire_5_count=0;
	$buffer=explode("|", $domain_expire_5);
	$total_count=(count($buffer)-1);
	foreach ($buffer as $current_count => $line)
		{
		if (strcmp($current_count, $total_count)!=0) 
			{
			if (strcmp("None for this run.", $line)!=0)
				{ 
				$domain_expire_5_data.=($current_count+1).". ".$line; 
				}
			else { $domain_expire_5_data.=$line; } 
			}
		else { $domain_expire_5_count=$line; }
		}
	unset($line);
	unset($total_count);
	unset($current_count);
	unset($buffer);
	
	# list($domain_expired_data, $domain_expired_count)=explode("|", $domain_expired);
	# $domain_expired_data=$domain_expired_data;
	$domain_expired_data="";
	$domain_expired_count=0;
	$buffer=explode("|", $domain_expired);
	$total_count=(count($buffer)-1);
	foreach ($buffer as $current_count => $line)
		{
		if (strcmp($current_count, $total_count)!=0) 
			{ 
			if (strcmp("None for this run.", $line)!=0)
				{
				$domain_expired_data.=($current_count+1).". ".$line; 
				}
			else { $domain_expired_data.=$line; } 
			}
		else { $domain_expired_count=$line; }
		}
	unset($line);
	unset($total_count);
	unset($current_count);
	unset($buffer);

	$generate_date=date("m/d/Y h:i:s a");
	
	# ------------------------------------------------------------------

	// ATTRIBUTES AVAILABLE
	// {{generate_date}}
	// {{number_resolved}}
	// {{successful_domain_list}}
	// {{number_unresolved}}
	// {{unsuccessful_domain_list}}
	// {{stopped_responding}}
	// {{stopped_responding_list}}

	// {{x30_day_ct}}
	// {{x30_day_list}}
	// {{x5_day_ct}}
	// {{x5_day_list}}
	// {{expired_ct}}
	// {{expired_list}}

	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);
	$subject=str_replace("{{number_resolved}}", $resolved_count, $subject);
	$subject=str_replace("{{successful_domain_list}}", $resolved_data, $subject);
	$subject=str_replace("{{number_unresolved}}", $unresolved_count, $subject);
	$subject=str_replace("{{unsuccessful_domain_list}}", $unresolved_data, $subject);
	$subject=str_replace("{{stopped_responding}}", $monitor_count, $subject);
	$subject=str_replace("{{stopped_responding_list}}", $monitor_data, $subject);
	$subject=str_replace("{{x30_day_ct}}", $domain_expire_30_count, $subject);
	$subject=str_replace("{{x30_day_list}}", $domain_expire_30_data, $subject);
	$subject=str_replace("{{x5_day_ct}}", $domain_expire_5_count, $subject);
	$subject=str_replace("{{x5_day_list}}", $domain_expire_5_data, $subject);
	$subject=str_replace("{{expired_ct}}", $domain_expired_count, $subject);
	$subject=str_replace("{{expired_list}}", $domain_expired_data, $subject);

	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{generate_date}}", $generate_date, $message);
	$message=str_replace("{{number_resolved}}", $resolved_count, $message);
	$message=str_replace("{{successful_domain_list}}", $resolved_data, $message);
	$message=str_replace("{{number_unresolved}}", $unresolved_count, $message);
	$message=str_replace("{{unsuccessful_domain_list}}", $unresolved_data, $message);
	$message=str_replace("{{stopped_responding}}", $monitor_count, $message);
	$message=str_replace("{{stopped_responding_list}}", $monitor_data, $message);
	$message=str_replace("{{x30_day_ct}}", $domain_expire_30_count, $message);
	$message=str_replace("{{x30_day_list}}", $domain_expire_30_data, $message);
	$message=str_replace("{{x5_day_ct}}", $domain_expire_5_count, $message);
	$message=str_replace("{{x5_day_list}}", $domain_expire_5_data, $message);
	$message=str_replace("{{expired_ct}}", $domain_expired_count, $message);
	$message=str_replace("{{expired_list}}", $domain_expired_data, $message);
	
	if ($cron==69)
		{
		mail($email_admin, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
		}
	else { return $message; }
	}

// caclulate totals for order
function calc_totals($payment_term, $domain_registration, $domain_fee, $pid, $addon_choices)
	{
	GLOBAL $tld_id;

	$query0="select ";
	$query0.="monthly_cost, ";		// 0
	$query0.="quarterly_cost, ";	// 1
	$query0.="semi_annual_cost, ";	// 2
	$query0.="annual_cost, ";		// 3
	$query0.="setup_cost ";			// 4
	$query0.="from plan_specs ";
	$query0.="where pid='".addslashes(trim($pid))."'";

	$rs0=mysql_fetch_row(mysql_query($query0));
	
	$monthly_cost=stripslashes(trim($rs0[0]));
	$quarterly_cost=stripslashes(trim($rs0[1]));
	$semi_annual_cost=stripslashes(trim($rs0[2]));
	$annual_cost=stripslashes(trim($rs0[3]));
	$setup_cost=stripslashes(trim($rs0[4]));
	
	$total_due_today=sprintf("%01.2f", $setup_cost);

	if ($domain_registration==1&&$domain_fee==0) 
		{ 
		$query_tld="select ";
		$query_tld.="cost ";
		$query_tld.="from ";
		$query_tld.="tld_chart ";
		$query_tld.="where ";
		$query_tld.="tld_id='".addslashes(trim($tld_id))."'";
		
		$rs_tld=mysql_fetch_row(mysql_query($query_tld));

		$total_due_today+=sprintf("%01.2f", $rs_tld[0]); 
		}

	$payment_term=strtolower(trim($payment_term));
	$payment_term=str_replace("-", "_", $payment_term);
	if (strcmp("monthly", $payment_term)==0)
		{
		$payment_term="Monthly";
		$monthly_cost=sprintf("%01.2f", $monthly_cost);
		$total_due_today+=$monthly_cost;
		$total_reoccur=$monthly_cost;
		$term=1;
		}
	else if (strcmp("quarterly", $payment_term)==0)
		{
		$payment_term="Quarterly";
		$quarterly_cost=sprintf("%01.2f", $quarterly_cost);
		$total_due_today+=sprintf("%01.2f", $quarterly_cost);
		$total_reoccur=$quarterly_cost;
		$term=3;
		}
	else if (strcmp("semi_annual", $payment_term)==0)
		{
		$payment_term="Semi-Annual";
		$semi_annual_cost=sprintf("%01.2f", $semi_annual_cost);
		$total_due_today+=sprintf("%01.2f", $semi_annual_cost);
		$total_reoccur=$semi_annual_cost;
		$term=6;
		}
	else if (strcmp("annual", $payment_term)==0)
		{
		$payment_term="Annual";
		$annual_cost=sprintf("%01.2f", $annual_cost);
		$total_due_today+=sprintf("%01.2f", $annual_cost);
		$total_reoccur=$annual_cost;
		$term=12;
		}

	$tok=strtok($addon_choices, "|");
	while ($tok)
		{
		$query1="select ";
		$query1.="setup_activate, ";	// 0
		$query1.="setup_cost, ";		// 1
		$query1.="addon_activate, ";	// 2
		$query1.="addon_state, ";		// 3
		$query1.="addon_cost, ";		// 4
		$query1.="unique_ip, ";			// 5
		$query1.="extra_webspace ";		// 6
		$query1.="from addon_specs ";
		$query1.="where aid='".addslashes(trim($tok))."'";

		$rs1=mysql_fetch_row(mysql_query($query1));

		$setup_activate=stripslashes(trim($rs1[0]));
		$setup_cost=stripslashes(trim($rs1[1]));
		$addon_activate=stripslashes(trim($rs1[2]));
		$addon_state=stripslashes(trim($rs1[3]));
		$addon_cost=stripslashes(trim($rs1[4]));
		$unique_ip=stripslashes(trim($rs1[5]));
		$extra_webspace=stripslashes(trim($rs1[6]));

		if ($setup_activate==1) { $total_due_today+=sprintf("%01.2f", $setup_cost); }

		# charge payment for addon?
		if ($addon_activate==1) 
			{
			if ($addon_state==1) 
				{ 
				# one time
				$total_due_today+=sprintf("%01.2f", $addon_cost); 
				} 
			else if ($addon_state==2) 
				{
				# per month
				$total_due_today+=sprintf("%01.2f", ($addon_cost*$term));
				$total_reoccur+=sprintf("%01.2f", ($addon_cost*$term));
				}
			else if ($addon_state==3) 
				{
				# per year
				$total_due_today+=sprintf("%01.2f", $addon_cost);
				}
			}
		
		unset($setup_activate);
		unset($setup_cost);
		unset($addon_activate);
		unset($addon_state);
		unset($addon_cost);

		$tok=strtok("|");
		}

	return $total_due_today."|".$total_reoccur."|".$payment_term."|";
	}

// client area functions

// Send out newly installed account welcome email
function resend_welcome_email_ip($email_admin, $oid, $unique_ip_ordered)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='10'"));
	$default_email=stripslashes(trim($rs[2]));
	
	// build query
	$query="select ";
	$query.="hosting_order.domain_name, ";				// 0
	$query.="hosting_order.ip, ";						// 1
	$query.="hosting_order.whm_username, ";				// 2
	$query.="hosting_order.whm_password, ";				// 3
	$query.="user.email, ";								// 4
	$query.="hosting_order.whm_id ";					// 5
	$query.="from user, hosting_order ";
	$query.="where user.uid=hosting_order.uid ";
	$query.="and hosting_order.oid='".addslashes(trim($oid))."' ";
	$query.="order by user.uid asc";

	$rs1=mysql_fetch_row(mysql_query($query));
	
	$whm_id=stripslashes(trim($rs1[5]));

	$dns=mysql_fetch_row(mysql_query("select primary_ns, primary_ns_ip, secondary_ns, secondary_ns_ip from server_config where whm_id='".addslashes(trim($whm_id))."'"));
	
	$primary_ns=$dns[0];
	$primary_ns_ip=$dns[1];
	$secondary_ns=$dns[2];
	$secondary_ns_ip=$dns[3];

	// DEFINE VARs
	$ip=stripslashes(trim($rs1[1]));
	$whm_username=stripslashes(trim($rs1[2]));
	$whm_password=stripslashes(trim($rs1[3]));
	$domain_name=stripslashes(trim($rs1[0]));
	$user_email=stripslashes(trim($rs1[4]));
	$user_username=stripslashes(trim($rs1[6]));
	$user_temppass=stripslashes(trim($rs1[7]));
	$client_login_temp=stripslashes(trim($rs1[8]));
	$generate_date=date("m/d/Y h:i:s a");
	if ($unique_ip_ordered==1) { $temporary_path="http://".$ip; }
	else { $temporary_path="http://".$ip."/~".$whm_username."/"; }

	// ATTRIBUTES AVAILABLE
	// {{ip}}
	// {{whm_username}}
	// {{whm_password}}
	// {{domain_name}}
	// {{primary_ns}}
	// {{primary_ns_ip}}
	// {{secondary_ns}}
	// {{secondary_ns_ip}}
	// {{generate_date}}
	// {{temporary_path}}
	// {{clientarea_username}}
	// {{clientarea_password}}
	// {{clientarea_loginlink}}


	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{ip}}", $ip, $subject);
	$subject=str_replace("{{whm_username}}", $whm_username, $subject);
	$subject=str_replace("{{whm_password}}", $whm_password, $subject);
	$subject=str_replace("{{domain_name}}", $domain_name, $subject);
	$subject=str_replace("{{primary_ns}}", $primary_ns, $subject);
	$subject=str_replace("{{primary_ns_ip}}", $primary_ns_ip, $subject);
	$subject=str_replace("{{secondary_ns}}", $secondary_ns, $subject);
	$subject=str_replace("{{secondary_ns_ip}}", $secondary_ns_ip, $subject);
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);
	$subject=str_replace("{{temporary_path}}", $temporary_path, $subject);
	$subject=str_replace("{{clientarea_username}}", $user_username, $subject);
	$subject=str_replace("{{clientarea_password}}", $user_temppass, $subject);
	$subject=str_replace("{{clientarea_loginlink}}", $client_login, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{ip}}", $ip, $message);
	$message=str_replace("{{whm_username}}", $whm_username, $message);
	$message=str_replace("{{whm_password}}", $whm_password, $message);
	$message=str_replace("{{domain_name}}", $domain_name, $message);
	$message=str_replace("{{primary_ns}}", $primary_ns, $message);
	$message=str_replace("{{primary_ns_ip}}", $primary_ns_ip, $message);
	$message=str_replace("{{secondary_ns}}", $secondary_ns, $message);
	$message=str_replace("{{secondary_ns_ip}}", $secondary_ns_ip, $message);
	$message=str_replace("{{generate_date}}", $generate_date, $message);
	$message=str_replace("{{temporary_path}}", $temporary_path, $message);
	$message=str_replace("{{clientarea_username}}", $user_username, $message);
	$message=str_replace("{{clientarea_password}}", $user_temppass, $message);
	$message=str_replace("{{clientarea_loginlink}}", $client_login, $message);

	mail($user_email, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}


// Start Account Cancel Functions ------------------------------------------------------------------

// send cancel request to admin
function request_cancel_revoked($oid, $email_admin, $reason_for_revoke)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='26'"));
	$default_email=stripslashes(trim($rs[2]));

	$rs1=mysql_fetch_row(mysql_query("select domain_name from hosting_order where oid='".addslashes(trim($oid))."'"));

	// DEFINE VARs
	$domain_name="http://".$rs1[0];
	$generate_date=date("m/d/Y h:i:s a");

	// ATTRIBUTES AVAILABLE
	// {{domain_name}}
	// {{reason_for_revoke}}
	// {{generate_date}}


	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{domain_name}}", $domain_name, $subject);
	$subject=str_replace("{{reason_for_revoke}}", $reason_for_revoke, $subject);
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{domain_name}}", $domain_name, $message);
	$message=str_replace("{{reason_for_revoke}}", $reason_for_revoke, $message);
	$message=str_replace("{{generate_date}}", $generate_date, $message);

	mail($email_admin, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}

// send cancel request to admin
function request_cancel($oid, $email_admin, $reason_for_cancel)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='24'"));
	$default_email=stripslashes(trim($rs[2]));

	$rs1=mysql_fetch_row(mysql_query("select domain_name from hosting_order where oid='".addslashes(trim($oid))."'"));

	// DEFINE VARs
	$domain_name="http://".$rs1[0];
	$generate_date=date("m/d/Y h:i:s a");

	// ATTRIBUTES AVAILABLE
	// {{domain_name}}
	// {{reason_for_cancel}}
	// {{generate_date}}


	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{domain_name}}", $domain_name, $subject);
	$subject=str_replace("{{reason_for_cancel}}", $reason_for_cancel, $subject);
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{domain_name}}", $domain_name, $message);
	$message=str_replace("{{reason_for_cancel}}", $reason_for_cancel, $message);
	$message=str_replace("{{generate_date}}", $generate_date, $message);

	mail($email_admin, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}

// send cancel request to admin
function request_cancel_confirm($oid, $email_admin, $reason_for_cancel)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='25'"));
	$default_email=stripslashes(trim($rs[2]));

	$rs1=mysql_fetch_row(mysql_query("select hosting_order.domain_name, user.email from hosting_order, user where hosting_order.oid='".addslashes(trim($oid))."' and hosting_order.uid=user.uid order by hosting_order.oid asc limit 0, 1"));

	// DEFINE VARs
	$domain_name="http://".$rs1[0];
	$generate_date=date("m/d/Y h:i:s a");
	$client_email=$rs1[1];

	// ATTRIBUTES AVAILABLE
	// {{domain_name}}
	// {{reason_for_cancel}}
	// {{generate_date}}


	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{domain_name}}", $domain_name, $subject);
	$subject=str_replace("{{reason_for_cancel}}", $reason_for_cancel, $subject);
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{domain_name}}", $domain_name, $message);
	$message=str_replace("{{reason_for_cancel}}", $reason_for_cancel, $message);
	$message=str_replace("{{generate_date}}", $generate_date, $message);

	mail($client_email, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}

// send cancel request to client
function cancel_processed($oid, $email_admin, $reason_for_cancel)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='27'"));
	$default_email=stripslashes(trim($rs[2]));

	$query="select ";
	$query.="hosting_order.domain_name, ";			// 0
	$query.="user.email, ";							// 1 
	$query.="hosting_order.reason_for_cancel, ";	// 2
	# $query.="UNIX_TIMESTAMP(hosting_order.cancel_date) ";	// 3
	$query.="hosting_order.cancel_date ";	// 3
	$query.="from hosting_order, user ";	
	$query.="where ";
	$query.="hosting_order.oid='".addslashes(trim($oid))."' ";
	$query.="and ";
	$query.="hosting_order.uid=user.uid ";
	$query.="order by hosting_order.oid asc limit 0, 1";

	$rs1=mysql_fetch_row(mysql_query($query));

	// DEFINE VARs
	$reason_for_cancel=stripslashes(trim($rs1[2]));
	$cancel_date_time=date("m/d/Y h:i:s a", $rs1[3]);
	$domain_name="http://".$rs1[0];
	$generate_date=date("m/d/Y h:i:s a");
	$client_email=$rs1[1];

	// ATTRIBUTES AVAILABLE
	// {{domain_name}}
	// {{reason_for_cancel}}
	// {{cancel_date_time}}
	// {{generate_date}}


	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{domain_name}}", $domain_name, $subject);
	$subject=str_replace("{{reason_for_cancel}}", $reason_for_cancel, $subject);
	$subject=str_replace("{{cancel_date_time}}", $cancel_date_time, $subject);
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{domain_name}}", $domain_name, $message);
	$message=str_replace("{{reason_for_cancel}}", $reason_for_cancel, $message);
	$message=str_replace("{{cancel_date_time}}", $cancel_date_time, $message);
	$message=str_replace("{{generate_date}}", $generate_date, $message);

	mail($client_email, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}

// End Account Cancel Functions ------------------------------------------------------------------


// -----------Affiliate-------------------------------------------

	
// notify admin of new affiliate request
function affiliate_request($email_admin, $uid)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='12'"));
	$default_email=stripslashes(trim($rs[2]));

	$rs1=mysql_fetch_row(mysql_query("select first_name, last_name, email from user where uid='".addslashes(trim($uid))."'"));

	// DEFINE VARs
	$generate_date=date("m/d/Y h:i:s a");
	$client_name=$rs1[0]." ".$rs1[1];
	$client_email=$rs1[2];

	// ATTRIBUTES AVAILABLE
	// {{generate_date}}
	// {{client_name}}

	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);
	$subject=str_replace("{{client_name}}", $client_name, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{generate_date}}", $generate_date, $message);
	$message=str_replace("{{client_name}}", $client_name, $message);

	mail($email_admin, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$client_email."\nX-Mailer: PHP/" . phpversion());
	}
	
// notify affilite of accpentance into program
function affiliate_approved($uid, $http_web, $email_admin)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='13'"));
	$default_email=stripslashes(trim($rs[2]));

	$rs1=mysql_fetch_row(mysql_query("select first_name, email from user where uid='".addslashes(trim($uid))."'"));

	// DEFINE VARs
	$generate_date=date("m/d/Y h:i:s a");
	$client_name=$rs1[0];
	$client_email=$rs1[1];
	$login_path=$http_web."/clogin.php";

	// ATTRIBUTES AVAILABLE
	// {{generate_date}}
	// {{client_name}}
	// {{login_path}}

	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);
	$subject=str_replace("{{client_name}}", $client_name, $subject);
	$subject=str_replace("{{login_path}}", $login_path, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{generate_date}}", $generate_date, $message);
	$message=str_replace("{{client_name}}", $client_name, $message);
	$message=str_replace("{{login_path}}", $login_path, $message);

	mail($client_email, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}
	
// notify affilite of denial of status
function affiliate_denied($uid, $http_web, $email_admin)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='14'"));
	$default_email=stripslashes(trim($rs[2]));

	$rs1=mysql_fetch_row(mysql_query("select first_name, email from user where uid='".addslashes(trim($uid))."'"));

	// DEFINE VARs
	$generate_date=date("m/d/Y h:i:s a");
	$client_name=$rs1[0];
	$client_email=$rs1[1];
	$minimum_period_to_reapply=30;

	// ATTRIBUTES AVAILABLE
	// {{generate_date}}
	// {{client_name}}
	// {{minimum_period_to_reapply}}

	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);
	$subject=str_replace("{{client_name}}", $client_name, $subject);
	$subject=str_replace("{{minimum_period_to_reapply}}", $minimum_period_to_reapply, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{generate_date}}", $generate_date, $message);
	$message=str_replace("{{client_name}}", $client_name, $message);
	$message=str_replace("{{minimum_period_to_reapply}}", $minimum_period_to_reapply, $message);

	mail($client_email, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}
	
// notify client of new affiliate sign up
function affiliate_notification_to_client($uid, $oid, $email_admin)
	{
	GLOBAL $referrer_id;

	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='16'"));
	$default_email=stripslashes(trim($rs[2]));

	$rs1=mysql_fetch_row(mysql_query("select first_name, last_name, email from user where uid='".addslashes(trim($uid))."'"));

	$rs2=mysql_fetch_row(mysql_query("select pid from hosting_order where oid='".addslashes(trim($oid))."'"));

	$rs3=mysql_fetch_row(mysql_query("select package_name from plan_specs where pid='".addslashes(trim($rs2[0]))."'"));

	$rs4=mysql_fetch_row(mysql_query("select email from user where uid='".addslashes(trim($referrer_id))."'"));

	// DEFINE VARs
	$client_email=$rs1[2];
	$generate_date=date("m/d/Y h:i:s a");
	$first_name=$rs1[0];
	$last_name=$rs1[1];
	$hosting_package=$rs3[0];

	// ATTRIBUTES AVAILABLE
	// {{generate_date}}
	// {{first_name}}
	// {{last_name}}
	// {{hosting_package}}

	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);
	$subject=str_replace("{{first_name}}", $first_name, $subject);
	$subject=str_replace("{{last_name}}", $last_name, $subject);
	$subject=str_replace("{{hosting_package}}", $hosting_package, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{generate_date}}", $generate_date, $message);
	$message=str_replace("{{first_name}}", $first_name, $message);
	$message=str_replace("{{last_name}}", $last_name, $message);
	$message=str_replace("{{hosting_package}}", $hosting_package, $message);

	mail($rs4[0], $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}
	
// notify client of commission paid
function notify_of_payout($uid, $email_admin, $payout_amount, $currency, $currency_type)
	{
	// PULL IN TEMPLATE
	$rs=mysql_fetch_row(mysql_query("select subject, message, default_email from email_templates where emid='28'"));
	$default_email=stripslashes(trim($rs[2]));

	$rs1=mysql_fetch_row(mysql_query("select email from user where uid='".addslashes(trim($uid))."'"));

	// DEFINE VARs
	$client_email=$rs1[0];
	$generate_date=date("m/d/Y h:i:s a");
	$payout_amount=$currency.$payout_amount.$currency_type;

	// ATTRIBUTES AVAILABLE
	// {{generate_date}}
	// {{payout_amount}}

	// parse out subject
	// this way is inefficient, but works on all OS's
	$subject=stripslashes(trim($rs[0]));
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);
	$subject=str_replace("{{payout_amount}}", $payout_amount, $subject);

	// parse out subject
	// this way is inefficient, but works on all OS's
	$message=stripslashes(trim($rs[1]));
	$message=str_replace("{{generate_date}}", $generate_date, $message);
	$message=str_replace("{{payout_amount}}", $payout_amount, $message);

	mail($client_email, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());

	$message.="\n\n\n-----------------------------------\nThis is a CC of what was sent to the client.";
	mail($email_admin, $subject, $message, "From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."\nReply-To: ".$email_admin."\nX-Mailer: PHP/" . phpversion());
	}

function tt_client_new_ticket($ticket_number)
	{
	GLOBAL $uid;
	GLOBAL $email_admin;
	GLOBAL $email;

	# query out template
	$query0="select ";
	$query0.="subject, ";
	$query0.="message, ";
	$query0.="default_email ";
	$query0.="from ";
	$query0.="email_templates ";
	$query0.="where ";
	$query0.="emid='44' ";
	$query0.="limit 0, 1";

	$rs0=mysql_fetch_row(mysql_query($query0));

	$subject=stripslashes(trim($rs0[0]));
	$message=stripslashes(trim($rs0[1]));
	$default_email=stripslashes(trim($rs0[2]));

	# ---------------------------------------------
	
	$query="select ";
	$query.="first_name, ";
	$query.="last_name ";
	$query.="from ";
	$query.="user ";
	$query.="where ";
	$query.="uid='".addslashes(trim($uid))."'";
	
	$rs=mysql_fetch_row(mysql_query($query));

	$first_name=stripslashes(trim($rs[0]));
	$last_name=stripslashes(trim($rs[1]));

	# ---------------------------------------------

	$query="select ";
	$query.="message ";
	$query.="from ";
	$query.="ticket ";
	$query.="where ";
	$query.="id='".addslashes(trim($ticket_number))."'";

	$rs=mysql_fetch_row(mysql_query($query));

	$ticket_details=stripslashes(trim($rs[0]));

	# ---------------------------------------------

	$generate_date=date("m/d/Y h:i:s a");

	# {{first_name}}
	# {{last_name}}
	# {{ticket_number}}
	# {{ticket_details}}
	# {{generate_date}}

	
	$subject=str_replace("{{first_name}}", $first_name, $subject);
	$subject=str_replace("{{last_name}}", $last_name, $subject);
	$subject=str_replace("{{ticket_number}}", $ticket_number, $subject);
	$subject=str_replace("{{ticket_details}}", $ticket_details, $subject);
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);

	$message=str_replace("{{first_name}}", $first_name, $message);
	$message=str_replace("{{last_name}}", $last_name, $message);
	$message=str_replace("{{ticket_number}}", $ticket_number, $message);
	$message=str_replace("{{ticket_details}}", $ticket_details, $message);
	$message=str_replace("{{generate_date}}", $generate_date, $message);

	$headers="From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."";
	$headers.="\nReply-To: ".$email_admin;
	$headers.="\nX-Mailer: PHP/".phpversion();

	# mail($email, $subject, $message, $headers);
	mail($email_admin, $subject, $message, $headers);
	}

function tt_client_reply($ticket_number)
	{
	GLOBAL $uid;
	GLOBAL $email_admin;
	GLOBAL $email;

	# query out template
	$query0="select ";
	$query0.="subject, ";
	$query0.="message, ";
	$query0.="default_email ";
	$query0.="from ";
	$query0.="email_templates ";
	$query0.="where ";
	$query0.="emid='45' ";
	$query0.="limit 0, 1";

	$rs0=mysql_fetch_row(mysql_query($query0));

	$subject=stripslashes(trim($rs0[0]));
	$message=stripslashes(trim($rs0[1]));
	$default_email=stripslashes(trim($rs0[2]));

	# ---------------------------------------------
	
	$query="select ";
	$query.="first_name, ";
	$query.="last_name ";
	$query.="from ";
	$query.="user ";
	$query.="where ";
	$query.="uid='".addslashes(trim($uid))."'";
	
	$rs=mysql_fetch_row(mysql_query($query));

	$first_name=stripslashes(trim($rs[0]));
	$last_name=stripslashes(trim($rs[1]));

	# ---------------------------------------------

	$query="select ";
	$query.="message ";
	$query.="from ";
	$query.="ticket ";
	$query.="where ";
	$query.="id='".addslashes(trim($ticket_number))."'";

	$rs=mysql_fetch_row(mysql_query($query));

	$ticket_details=stripslashes(trim($rs[0]));

	# ---------------------------------------------

	$generate_date=date("m/d/Y h:i:s a");

	# {{first_name}}
	# {{last_name}}
	# {{ticket_number}}
	# {{ticket_details}}
	# {{generate_date}}

	
	$subject=str_replace("{{first_name}}", $first_name, $subject);
	$subject=str_replace("{{last_name}}", $last_name, $subject);
	$subject=str_replace("{{ticket_number}}", $ticket_number, $subject);
	$subject=str_replace("{{ticket_details}}", $ticket_details, $subject);
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);

	$message=str_replace("{{first_name}}", $first_name, $message);
	$message=str_replace("{{last_name}}", $last_name, $message);
	$message=str_replace("{{ticket_number}}", $ticket_number, $message);
	$message=str_replace("{{ticket_details}}", $ticket_details, $message);
	$message=str_replace("{{generate_date}}", $generate_date, $message);

	$headers="From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."";
	$headers.="\nReply-To: ".$email_admin;
	$headers.="\nX-Mailer: PHP/".phpversion();

	# mail($email, $subject, $message, $headers);
	mail($email_admin, $subject, $message, $headers);
	}

function tt_admin_reply($ticket_number)
	{
	GLOBAL $uid;
	GLOBAL $email_admin;
	GLOBAL $email;

	# query out template
	$query0="select ";
	$query0.="subject, ";
	$query0.="message, ";
	$query0.="default_email ";
	$query0.="from ";
	$query0.="email_templates ";
	$query0.="where ";
	$query0.="emid='46' ";
	$query0.="limit 0, 1";
	
	$rs0=mysql_fetch_row(mysql_query($query0));

	$subject=stripslashes(trim($rs0[0]));
	$message=stripslashes(trim($rs0[1]));
	$default_email=stripslashes(trim($rs0[2]));

	# ---------------------------------------------
	
	$query="select ";
	$query.="first_name, ";
	$query.="last_name ";
	$query.="from ";
	$query.="user ";
	$query.="where ";
	$query.="uid='".addslashes(trim($uid))."'";

	$rs=mysql_fetch_row(mysql_query($query));

	$first_name=stripslashes(trim($rs[0]));
	$last_name=stripslashes(trim($rs[1]));

	# ---------------------------------------------

	$query="select ";
	$query.="message ";
	$query.="from ";
	$query.="ticket ";
	$query.="where ";
	$query.="id='".addslashes(trim($ticket_number))."'";

	$rs=mysql_fetch_row(mysql_query($query));

	$ticket_details=stripslashes(trim($rs[0]));

	# ---------------------------------------------

	$generate_date=date("m/d/Y h:i:s a");

	# {{first_name}}
	# {{last_name}}
	# {{ticket_number}}
	# {{ticket_details}}
	# {{generate_date}}

	
	$subject=str_replace("{{first_name}}", $first_name, $subject);
	$subject=str_replace("{{last_name}}", $last_name, $subject);
	$subject=str_replace("{{ticket_number}}", $ticket_number, $subject);
	$subject=str_replace("{{ticket_details}}", $ticket_details, $subject);
	$subject=str_replace("{{generate_date}}", $generate_date, $subject);

	$message=str_replace("{{first_name}}", $first_name, $message);
	$message=str_replace("{{last_name}}", $last_name, $message);
	$message=str_replace("{{ticket_number}}", $ticket_number, $message);
	$message=str_replace("{{ticket_details}}", $ticket_details, $message);
	$message=str_replace("{{generate_date}}", $generate_date, $message);

	$query="select ";
	$query.="reply ";
	$query.="from ";
	$query.="ticket_reply ";
	$query.="where ";
	$query.="id='".addslashes(trim($ticket_number))."' ";
	$query.="and ";
	$query.="reply_status='1' ";
	$query.="order by rid desc ";
	$query.="limit 0, 1";
	
	$rs=mysql_fetch_row(mysql_query($query));

	$ticket_details=stripslashes(trim($rs[0]));
	$subject=str_replace("{{admin_reply_details}}", $ticket_details, $subject);
	$message=str_replace("{{admin_reply_details}}", $ticket_details, $message);

	$headers="From: ".(($default_email!="")?"".$default_email."":"".$email_admin."")."";
	$headers.="\nReply-To: ".$email_admin;
	$headers.="\nX-Mailer: PHP/".phpversion();

	# mail($email, $subject, $message, $headers);
	mail($email, $subject, $message, $headers);
	}
?>