<?php
include("postget.php");
include_once("common.php");
checklevel(4,$_REQUEST['clientid']);



//////////////////////////////////////////////////////////////// si se envi� el formulario, cargar los errores
if ($_REQUEST[click]==""._EDIT."") {
	$errors = '';
	if ($_POST['name']=='') {$errors.= "<br>".ucfirst(_NAME)." "._NOT_SPECIFIED."";}
	//	if ($_FILES['file']['name']=='') {$errors.= "<br>".ucfirst(_FILE)." "._NOT_SPECIFIED."";}
}

if($errors=='' AND $_REQUEST[click]==""._EDIT."") {


	$now=time()+$config[31][1]*3600;

	if($onlyclients=="on"){$onlyclients=1;}else{$onlyclients=0;}
	
	$query="UPDATE hd_downloads SET
	name='".$_POST['name']."', 
	description='".$_POST['description']."', 
	onlyclients='".$onlyclients."' 
	 WHERE id='$id'";
	if(!mysql_query($query,$db_link)){
		messagetop(_ERROR,"DEBUG: ".$query."<br>ERROR: ".mysql_error(),'downloads_admin.php',0); 
	}else{
		messagetop(_THE_CHANGES_WHERE_MADE_SUCCESSFULLY,'','downloads_admin.php',1);
	}
}



if($_REQUEST[id]) {
	$query="SELECT * FROM hd_downloads WHERE id='$_REQUEST[id]'";
	$output=mysql_query($query,$db_link);
	$row=mysql_fetch_array($output);
}
include("head_template.php");
echo '
<div class="container">
	<div class="row">


<table width="98%" class="table table-bordered">
		<tr>
		<td align="center" width="100%">
';

print(ucfirst(_DOWNLOADS));

echo '
		</td>
		</tr>
';

echo '
			<tr valign="top">
				<td>

';

//	viewhelp(48);


print("
	<form method='post'>
	

		<table border='0' width='100%'>
		<tr>
			<td align='right'><b>".ucfirst(_NAME).":</b></td>
			<td><input type='text' size='60' name='name' ");
if($_REQUEST[id]){print(" value='$row[name]'");}else{print(" value='$_POST[name]'");}
print("></td>
		</tr>
		
		<tr>
			<td align='right'><b>".ucfirst(_DESCRIPTION).":</b></td>
			<td><TEXTAREA cols=100 rows=8 name='description'>");
if($_REQUEST[id]){print($row[description]);}else{print($_POST[description]);}
print("</TEXTAREA></td>
		</tr>
		
		<tr>
			<td align='right'><b>".ucfirst(_FILE).":</b></td>
			<td><input type='text' size='60' name='file' value='".$row[file]."' disabled></td>
		</tr>
		
		<tr>
			<td align='right'><b>".ucfirst(_VISIBLE_ONLY_TO_REGISTERED_CLIENTS).":</b></td>
			<td>
			<input type='checkbox' name='onlyclients'");
if($_REQUEST[id]){
	if ($row[onlyclients]==1){
		print(" checked");
	};
}else{
	if ($_POST[description]==1){
		print(" checked");
	};
}

print("></td>
		</tr>");
		

	print("</table>
	

	<br>
	<input type='submit' name='click' value='"._EDIT."'><br>
	</form>
	");

echo '
		</td>
		</tr>
		</table>
</div>
</div>
';


include("foot_template.php");
?>