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




if ($_REQUEST['reset2default'] == 'yes') {
		mysql_query("UPDATE hd_config SET valor='' WHERE ref='86'",$db_link);
		mysql_query("UPDATE hd_config SET valor='' WHERE ref='87'",$db_link);
		mysql_query("UPDATE hd_config SET valor='' WHERE ref='90'",$db_link);
		mysql_query("UPDATE hd_config SET valor='' WHERE ref='91'",$db_link);
		mysql_query("UPDATE hd_config SET valor='' WHERE ref='92'",$db_link);
		go2('preferences.php?option=17&reload=yes');
}

if ($_REQUEST['reload'] == 'yes') {
		go2('preferences.php?option=17');
}

//////////////////////////////////////////////////////////////// si no hay errores y se presionó SEND
if(
$_REQUEST[send86] ==""._SEND."" OR 
$_REQUEST[send87] ==""._SEND."" 
) {
	if ($_FILES['attachment86']['name']) 	{
		$newfilename = time() . '_' . $_FILES['attachment86']['name'];
		$attachdir = 'attachments/';
		if(!@copy ($_FILES['attachment86']['tmp_name'], $attachdir . $newfilename)) {
			$errors= error_get_last();
			echo "COPY ERROR: ".$errors['type'];
			echo "<br />\n".$errors['message']; exit;
		}
		$attachment = $newfilename;
		mysql_query("UPDATE hd_config SET valor='$attachment' WHERE ref='86'",$db_link);
		messagetop(_THE_CHANGES_WHERE_MADE_SUCCESSFULLY,'','preferences.php?option=17',1);
	}
	if ($_REQUEST['send86']) {
		$filasafectadas = 0;
		if ($filasafectadas>0) {
			messagetop(_THE_CHANGES_WHERE_MADE_SUCCESSFULLY,'','preferences.php?option=17',1);
		}else{
			messagetop(_THERE_WERE_NO_CHANGES,'','preferences.php?option=17',2);
		}
	}


	if ($_FILES['attachment87']['name']) 	{
		$newfilename = time() . '_' . $_FILES['attachment87']['name'];
		$attachdir = 'attachments/';
		if(!@copy ($_FILES['attachment87']['tmp_name'], $attachdir . $newfilename)) {
			$errors= error_get_last();
			echo "COPY ERROR: ".$errors['type'];
			echo "<br />\n".$errors['message']; exit;
		}
		$attachment = $newfilename;
		mysql_query("UPDATE hd_config SET valor='$attachment' WHERE ref='87'",$db_link);
		messagetop(_THE_CHANGES_WHERE_MADE_SUCCESSFULLY,'','preferences.php?option=17',1);
	}



	if ($_FILES['attachment90']['name']) 	{
		$newfilename = time() . '_' . $_FILES['attachment90']['name'];
		$attachdir = 'attachments/';
		if(!@copy ($_FILES['attachment90']['tmp_name'], $attachdir . $newfilename)) {
			$errors= error_get_last();
			echo "COPY ERROR: ".$errors['type'];
			echo "<br />\n".$errors['message']; exit;
		}
		$attachment = $newfilename;
		mysql_query("UPDATE hd_config SET valor='$attachment' WHERE ref='90'",$db_link);
		messagetop(_THE_CHANGES_WHERE_MADE_SUCCESSFULLY,'','preferences.php?option=17',1);
	}

	if ($_FILES['attachment91']['name']) 	{
		$newfilename = time() . '_' . $_FILES['attachment91']['name'];
		$attachdir = 'attachments/';
		if(!@copy ($_FILES['attachment91']['tmp_name'], $attachdir . $newfilename)) {
			$errors= error_get_last();
			echo "COPY ERROR: ".$errors['type'];
			echo "<br />\n".$errors['message']; exit;
		}
		$attachment = $newfilename;
		mysql_query("UPDATE hd_config SET valor='$attachment' WHERE ref='91'",$db_link);
		messagetop(_THE_CHANGES_WHERE_MADE_SUCCESSFULLY,'','preferences.php?option=17',1);
	}

	if ($_FILES['attachment92']['name']) 	{
		$newfilename = time() . '_' . $_FILES['attachment92']['name'];
		$attachdir = 'attachments/';
		if(!@copy ($_FILES['attachment92']['tmp_name'], $attachdir . $newfilename)) {
			$errors= error_get_last();
			echo "COPY ERROR: ".$errors['type'];
			echo "<br />\n".$errors['message']; exit;
		}
		$attachment = $newfilename;
		mysql_query("UPDATE hd_config SET valor='$attachment' WHERE ref='92'",$db_link);
		messagetop(_THE_CHANGES_WHERE_MADE_SUCCESSFULLY,'','preferences.php?option=17',1);
	}



	messagetop(_THERE_WERE_NO_CHANGES,'','preferences.php?option=17',2);

}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"]."'";
		//	$Config[$fila][1]=$row["valor"];
		$fila++ ;
	}


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

	echo '<table class="table table-striped">';


	/////////////////////////// MAIN LOGO
	echo '<tr>';
	print("<td><form method='POST' enctype='multipart/form-data'>".tip(39)."<b>".ucfirst(_LOGO)."</b>
	<br><input type='file' name='attachment86'>
	</td>");
	print("<td><input type=submit name=send86 value="._SEND." $disabled>$mensaje</td>");
	print("<td align='right'>&nbsp;");
	if ($config[86][1]) {
		$extension = explode('.',$config[86][1]) ;
		$extension = array_pop($extension) ;
		$imagen =  "attachments/".$config[86][1]."" ;
		$tam = @getimagesize($imagen);
		print($tam[0]."px<br> X <br>".$tam[1]."px");
		print("</td>");
		print("<td align='right'>&nbsp;");
		if ($tam[0]>200) {$tam[0]=200; $resized='<br>'.ucfirst(_RESIZED_HERE);}else{$resized='';}
		print("<img src='".$imagen."' border='0' width='".$tam[0]."' title=''>$resized");
	}
	print("</form></td></tr>");

	/////////////////////////// MAILS LOGO
	echo '<tr>';
	print("<td><form method='POST' enctype='multipart/form-data'>".tip(40)."<b>".ucfirst(_LOGO." "._IN." "._EMAILS)."</b><br><input type='file' name='attachment87'></td>");
	print("<td><input type=submit name=send87 value="._SEND." $disabled>$mensaje</td>");
	print("<td align='right'>&nbsp;");
	if ($config[87][1]) {
		$extension = explode('.',$config[87][1]) ;
		$extension = array_pop($extension) ;
		$imagen =  "attachments/".$config[87][1]."" ;
		$tam = @getimagesize($imagen);
		print($tam[0]."px<br> X <br>".$tam[1]."px");
		print("</td>");
		print("<td align='right'>&nbsp;");
		if ($tam[0]>200) {$tam[0]=200; $resized='<br>'.ucfirst(_RESIZED_HERE);}else{$resized='';}
		print("<img src='".$imagen."' border='0' width='".$tam[0]."' title=''>$resized");
	}
	print("</form></td></tr>");








	print("</table>");

	redbutton('preferences.php?option=17&reset2default=yes',lang('_RESET_TO_DEFAULT_IMAGES'),1);

echo '
</div>
</div>
';

}
?>