<?PHP
include"../inc/var.php";
include "../inc/connect.php";
include $server_inc."/client_functions.php";
include $server_inc."/whm_functions.php";
include $server_inc."/login_functions.php";

// START FORM HANDLER

if (isset($submit))
	{
	mysql_query("update email_templates set subject='".addslashes(trim($subject))."', message='".addslashes(trim($message))."', default_email='".addslashes(trim($default_email))."' where emid='".addslashes(trim($emid))."'");
	}

// END FORM HANDLER

include $server_admin_inc."/header.php";

echo("
	<form action='".$PHP_SELF."' method='POST'>
	<input type='hidden' name='sid' value='".trim($sid)."'>
	<table width='725' cellpadding='2' cellspacing='0' border='0'>
		<tr> 
			<td width='20%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='1'><a href='".$http_admin."/index2.php?sid=".trim($sid)."'><img border='0' src='".$http_images."/menu_arrow_back.gif'><b>Go back</b></a></td>
			<td width='80%' align='left' valign='top'><select name='emid' ".$input_style.">
		");
$row=mysql_query("select emid, name from email_templates order by emid asc");
while ($rs=mysql_fetch_row($row))
	{
	echo"<option value='".$rs[0]."'".((isset($emid))?"".(($emid==$rs[0])?" selected":"")."":"").">[emid: ".$rs[0]."] ".$rs[1]."</option>\n";
	}
echo("
			</select> <input ".$button_style." type='submit' name='xsubmit' value='Edit Email Template Now &gt&gt'></td>
		</tr>
	</form>
	</table>
	");
if (isset($emid))
	{
	echo("
		<table width='725' cellpadding='2' cellspacing='0' border='0'>
		<form action='".$PHP_SELF."' method='POST'>
		<input type='hidden' name='sid' value='".trim($sid)."'>
		<input type='hidden' name='emid' value='".trim($emid)."'>
			<tr>
				<td colspan='2' align='left' valign='top'><hr color='#F0EFED'></td>
			</tr>
			<tr>
				<td width='1%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='1'></td>
				<td width='99%' align='left' valign='top'>
				<table width='100%' cellpadding='2' cellspacing='0' border='0'>
					<tr>
						<td colspan='4'><font color='#990000'>Objects Available:</font></td>
					</tr>
		");
	$rs0=mysql_fetch_row(mysql_query("select subject, message, attr_avail, default_email from email_templates where emid='".addslashes(trim($emid))."'"));
	
	$total=substr_count($rs0[2], "|");
	$g=1;
	$tok = strtok($rs0[2],"|");
	while ($tok) 
		{
		if ($g==1)
			{
			echo"<tr>\n\t<td>".$tok."</td>\n";
			$g=2;
			}
		else if ($g==2)
			{
			echo"\t<td>".$tok."</td>\n";
			$g=3;
			}
		else if ($g==3)
			{
			echo"\t<td>".$tok."</td>\n";
			$g=4;
			}
		else if ($g==4)
			{
			echo"\t<td>".$tok."</td>\n</tr>\n";
			$g=1;
			}
		$tok = strtok("|");
		}

	// finish out table html
	if ($g==2)
		{
		echo"\t<td></td>\n";
		echo"\t<td></td>\n";
		echo"\t<td></td>\n</tr>\n";
		$g=3;
		}
	else if ($g==3)
		{
		echo"\t<td></td>\n";
		echo"\t<td></td>\n</tr>\n";
		$g=4;
		}
	else if ($g==4)
		{
		echo"\t<td></td>\n</tr>\n";
		$g=1;
		}
	echo("
				</table>
				</td>
			</tr>
			<tr>
				<td colspan='4' align='left' valign='top'><hr color='#F0EFED'></td>
			</tr>
			<tr>
				<td width='1%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='1'></td>
				<td width='99%' align='left' valign='top'>	
				<table width='100%' cellpadding='2' cellspacing='0' border='0'>
					<tr>
						<td>Email From: <input ".$input_style." size='70' maxlength='255' type='text' name='default_email' value='".((trim($rs0[3])=="")?"".$email_admin."":"".$rs0[3]."")."'></td>
					</tr>
					<tr>
						<td>Subject:&nbsp;&nbsp;<input ".$input_style." size='72' maxlength='255' type='text' name='subject' value='".stripslashes(trim($rs0[0]))."'></td>
					</tr>
					<tr>
						<td><textarea name='message' rows='15' cols='80' ".$input_style.">".stripslashes(trim($rs0[1]))."</textarea></td>
					</tr>
					<tr>
						<td><img src='".$http_images."/space.gif' width='1' height='4'></td>
					</tr>
					<tr>
						<td><input ".$button_style." type='submit' name='submit' value='Update Email Template Now &gt&gt'></td>
					</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td colspan='2'><img src='".$http_images."/space.gif' width='1' height='15'></td>
			</tr>
		</table>
		</form>
		"); 
	}
else
	{
	echo("
			<tr>
				<td colspan='2'><img src='".$http_images."/space.gif' width='1' height='15'></td>
			</tr>
		</table>
		");
	}
include $server_admin_inc."/footer.php";
mysql_close($dblink);
?>