<?php
include("postget.php");
include_once("common.php");
checklevel(4,$_REQUEST['clientid']);
if ($config[56][1]==1){
	$disabled=" disabled ";
	$mensaje= " "._CHANGE_NOT_ALLOWED_IN_DEMO_MODE;
}else{
	$disabled=" ";
	$mensaje= "";
}


//////////////////////////////////////////////////////////////// si se envi� el formulario, cargar los errores
if ($_REQUEST[sendclick]==""._SEND."") {
	$estiloerror = "class='formfielderror'";
	$errors = '';
	$deptos = query("SELECT email FROM hd_tickets_dep WHERE email='".$_POST['Xadmin_mail_from']."'",2);
	if ($deptos) {$errors.= "<br><b>".strtoupper(_EMAILS." "._ADMINISTRATION)."</b> > ".ucfirst(_FIELD_FROM)." ".strtolower(_MUST_BE_DIFFERENT_TO)." ".$_POST['Xadmin_mail_from'];}

	if (!preg_match ('/'.$regex4mail.'/i', $_POST['Xadmin_mail_from'])) {			$errors.= "<br>".strtoupper(_EMAILS." "._ADMINISTRATION)." "._FIELD_FROM.": <b>".ucfirst(_INVALID_EMAIL)."</b>"; $estilo3=$estiloerror;}
	if (!preg_match ('/'.$regex4mail.'/i', $_POST['Xadmin_mail_replyto'])) {		$errors.= "<br>".strtoupper(_EMAILS." "._ADMINISTRATION)." "._FIELD_REPLYTO.": <b>".ucfirst(_INVALID_EMAIL)."</b>"; $estilo4=$estiloerror;}
}



if($errors=='' AND $_REQUEST[sendclick] ==""._SEND."") {
	if($Xemails2queue=="on"){$Xemails2queue=1;}else{$Xemails2queue=0;}

	mysql_query("UPDATE hd_config SET valor='$Xadmin_mail_from' WHERE variable='admin_mail_from'",$db_link);
	mysql_query("UPDATE hd_config SET valor='$Xadmin_mail_replyto' WHERE variable='admin_mail_replyto'",$db_link);
	mysql_query("UPDATE hd_config SET valor='$Xadmin_mail_bcc' WHERE variable='admin_mail_bcc'",$db_link);
	mysql_query("UPDATE hd_config SET valor='$Xemails2queue' WHERE ref='59'",$db_link);

	messagetop(_THE_CHANGES_WHERE_MADE_SUCCESSFULLY,'','preferences.php',1);
}else{


	$query="SELECT * FROM hd_config ORDER BY ref";
	$result=mysql_query($query,$db_link);
	$fila=0;
	while($row=mysql_fetch_array($result)) 	{
		$Config[$fila][0]=$row["variable"] ;
		$Config[$fila][1]="'".$row["valor"]."'";
		$fila++ ;

	}



	print errors($errors); $errors = '';

	print("<form method='POST'>");
	echo '<table class="table table-striped">';

	print("<tr><td colspan=2 align=center height=10></td></tr>");

	print("<tr><td colspan=2 align=center bgcolor='#cccccc'>".tip(52)."<B>".strtoupper(_EMAILS." "._ADMINISTRATION)."</B></td></tr>");

	echo '<tr>';
	print("<td><b>"._FIELD_FROM.":</b> </td><td>");
	print("<input $estilo3 name=Xadmin_mail_from value=".$Config[19][1]." size=60></td></tr>");

	echo '<tr>';
	print("<td><b>"._FIELD_REPLYTO.":</b> </td><td>");
	print("<input $estilo4 name=Xadmin_mail_replyto value=".$Config[20][1]." size=60></td></tr>");

	echo '<tr>';
	print("<td>"._FIELD_BCC.": </td><td>");
	print("<input name=Xadmin_mail_bcc value=".$Config[21][1]." size=60></td></tr>");

	print("<tr><td colspan=2 align=center height=10></td></tr>");

	echo '<tr>';
	print("<td>".tip(54).""._SEND_EMAILS_TO_THE_QUEUE.": </td><td>");
	print("<input type='checkbox' name=Xemails2queue");
	if ($Config[59][1]=="'1'"){print(" checked");};
	print("></td></tr>");


	print("</table>");
	print("<input type=submit name=sendclick value="._SEND." $disabled>$mensaje</form>");


}
?>