<?php include('inc/header.php'); ?>
<h1>Settings - Site: Partner</h1>
<div class="container">
<?php
	odbc_exec($odbc_connect, 'USE [WEBSITE_REV3]');
	if(isset($_POST['addpartnersbm'])) {
		if($_POST['title'] == '' || $_POST['link'] == '' || $_POST['banner'] == '') {
			echo '<div class="fail"You must fill-in all fields!></div>';
		} else {
			odbc_exec($odbc_connect, 'INSERT INTO [rev3_partner](title, link, banner) VALUES(\''.mssql_escape_string($_POST['title']).'\', \''.mssql_escape_string($_POST['link']).'\', \''.mssql_escape_string($_POST['banner']).'\')');
			echo '<div class="success">The partner has successfully been added!</div>';
		}
	} elseif(isset($_POST['savepartnersbm'])) {
		if($_POST['edit_title'] == '' || $_POST['edit_link'] == '' || $_POST['edit_banner'] == '') {
			echo '<div class="fail"You must fill-in all fields!></div>';
		} else {
			odbc_exec($odbc_connect, 'UPDATE [rev3_partner] SET title=\''.mssql_escape_string($_POST['edit_title']).'\', link=\''.mssql_escape_string($_POST['edit_link']).'\', banner=\''.mssql_escape_string($_POST['edit_banner']).'\' WHERE pid=\''.mssql_escape_string($_POST['edit_pid']).'\'');
			echo '<div class="success">The partner has successfully been changed!</div>';
		}
	}
	$select = odbc_exec($odbc_connect, 'SELECT * FROM [rev3_partner]');
	echo '<div id="box"></div>';
	echo '<span id="text"></span>';
	echo '<table><tr><td><a href="javascript:partner_addform();" title="Add" rel="tooltip"><img src="../images/add.png" /></a></td><td>Add Partner</td></tr></table>';
	echo '<form method="post" id="addform" style="display: none;">
		<table id="table">
			<tr>
				<td id="key">Title:</id>
				<td id="value"><input type="text" name="title" style="width: 200px;" /></id>
			</tr>
			<tr>
				<td id="key">Link:</id>
				<td id="value"><input type="text" name="link" value="http://" style="width: 200px;" /></id>
			</tr>
			<tr>
				<td id="key">Banner:</id>
				<td id="value"><input type="text" name="banner" value="http://" style="width: 200px;" /></id>
			</tr>
			<tr>
				<td></id>
				<td id="value"><input type="submit" name="addpartnersbm" value="Add Partner" /></id>
			</tr>
		</table>
	</form><br/>';
	echo '<table id="table" style="width: 100%;">
		<tr>
			<td id="key">Title</td>
			<td id="key">Link</td>
			<td id="key">Banner</td>
			<td id="key" style="width: 52px;"></td>
		</tr>';
	while($result = odbc_fetch_array($select)) {
		echo '<tr id="pid_'.$result['pid'].'" class="row">
			<td id="value">'.$result['title'].'</td>
			<td id="value"><a href="'.$result['link'].'" target="_blank">'.$result['link'].'</a></td>
			<td id="value"><a href="'.$result['banner'].'" target="_blank">'.$result['banner'].'</a></td>
			<td id="value"><a href="javascript:partner_edit(\''.$result['pid'].'\');" title="Edit" rel="tooltip"><img src="../images/edit.png" /></a> <a href="javascript:partner_delete(\''.$result['pid'].'\');" title="Delete" rel="tooltip"><img src="../images/delete.png" /></a></td>
		</tr>';
	}
	echo '</table>';
?>
</div>
<?php include('inc/footer.php'); ?>