<?php include('inc/header.php'); ?>
<h1>Settings - Site: Downloads</h1>
<div class="container">
<?php
	odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['web'] . ']');
	if(isset($_POST['downloadsbm'])) {
		if($_POST['title'] == '' || $_POST['link'] == '' || $_POST['description'] == '') {
			echo '<div class="fail">You must fill-in all fields!</div>';
		} else {
			odbc_exec($odbc_connect, 'INSERT INTO [web_downloads](title, description, link, datetime) VALUES(\''.mssql_escape_string($_POST['title']).'\', \''.mssql_escape_string($_POST['description']).'\', \''.mssql_escape_string($_POST['link']).'\', \''.date('d.m.Y H:i:s').'\')');
			echo '<div class="success">The download has successfully been added!</div>';
		}
	} elseif(isset($_POST['savedownloadsbm'])) {
		if($_POST['edit_title'] == '' || $_POST['edit_link'] == '' || $_POST['edit_description'] == '') {
			echo '<div class="fail">You must fill-in all fields!</div>';
		} else {
			odbc_exec($odbc_connect, 'UPDATE [web_downloads] SET title=\''.mssql_escape_string($_POST['edit_title']).'\', link=\''.mssql_escape_string($_POST['edit_link']).'\', description=\''.mssql_escape_string($_POST['edit_description']).'\' WHERE dlid=\''.mssql_escape_string($_POST['edit_did']).'\'');
			echo '<div class="success">The download has successfully been changed!</div>';
		}
	}
	echo '<span id="text"></span>';
	echo '<div id="box"></div>';
	echo '<table><tr><td><a href="javascript:download_addform();" title="Add" rel="tooltip"><img src="../images/add.png" /></a></td><td>Add Download</td></tr></table>';
	$select = odbc_exec($odbc_connect, 'SELECT * FROM [web_downloads] ORDER BY datetime');
	echo '<form method="post" id="dladdform" style="display: none;">
		<table id="table">
			<tr>
				<td id="key">Title:</td>
				<td id="value"><input type="text" name="title" style="width: 200px;" /></td>
			</tr>
			<tr>
				<td id="key">Link:</td>
				<td id="value"><input type="text" name="link" value="http://" style="width: 200px;" /></td>
			</tr>
			<tr>
				<td id="key" style="vertical-align: top;">Description:</td>
				<td id="value"><textarea name="description" style="width: 200px; height: 50px;"></textarea></td>
			</tr>
			<tr>
				<td></td>
				<td id="value"><input type="submit" name="downloadsbm" value="Add Download" /></td>
			</tr>
		</table>
	</form><br/>';
	echo '<table id="table" style="width: 100%;">
		<tr>
			<td id="key">Title</td>
			<td id="key">Description</td>
			<td id="key">Link</td>
			<td id="key"><table><tr><td><img src="../images/date.png" /></td><td>Added</td></tr></table></td>
			<td id="key" style="width:50px;"></td>
		</tr>';
	while($result = odbc_fetch_array($select)) {
		echo '<tr id="did_'.$result['dlid'].'" class="row">
			<td id="value">'.$result['title'].'</td>
			<td id="value">'.$result['description'].'</td>
			<td id="value">'.$result['link'].'</td>
			<td id="value">'.date('Y/m/d', strtotime($result['datetime'])).'</td>
			<td id="value"><a href="javascript:download_edit('.$result['dlid'].');" title="Edit" rel="tooltip"><img src="../images/edit.png" /></a> <a href="javascript:download_delete('.$result['dlid'].');" title="Delete" rel="tooltip"><img src="../images/delete.png" /></a></td>
		</tr>';
	}
	echo '</table>';
?>
</div>
<?php include('inc/footer.php'); ?>