<?
	require_once('../include/user.php');
	require_once('../include/authenticate.php');
	require_once('../include/mysql.php');
	require_once('../include/functions.php');
    require_once('../include/fb.php');

	ob_start();
	
	session_start();
	
	// SETUP MYSQL HANDLERS
	$mysqldb1 = new mysql($host, $user, $pswd, $db); $mysqldb1->connect(); $mysqldb1->select();
	$mysqldb2 = new mysql($host, $user, $pswd, $db); $mysqldb2->connect(); $mysqldb2->select();
	
	// SETUP GENERAL VARIABLES
	$url = $_SERVER['REQUEST_URI'];
	$id = $_GET['id']; if ($id == '') { $id = $_POST['id']; }
	$date = date('Y-m-d H:i:s', time());
	$error = $_GET['error'];
	$log = '';
	
	$upload_file_types = '';
	foreach ($file_types as $file_type) {
		$upload_file_types .= '*.'.$file_type.';';
	}
	
	$show_file_uploader = false;
	
	// SETUP RECORD HANDLER
	$table = str_replace('.php', '', page_name());
	$query = "SELECT * FROM ".$table." WHERE id='".$id."'";
	if ($id != '') { $mysqldb1->query($query); }
	$ROW = $mysqldb1->fetchArray();
	
	// HANDLE RECORD DUPLICATION
	if ($_GET['duplicate']) { $id = ''; }
	
	// SETUP FORM BUTTONS
	define('UPDATE_BUTTON', '<input name="update" type="submit" class="button" value="UPDATE">');
	define('INSERT_BUTTON', '<input name="insert" type="submit" class="button" value="INSERT">');
	
	// MODIFY POSTED FIELDS HERE BEFORE IT GETS INJECTED INTO THE DATABASE
	###
	
	// DATA ENGINE
    $debug = 0;
	require_once('../include/record.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><? print $table.':'.$id; ?></title>
<meta name="robots" content="noindex, nofollow, noarchive" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!--STYLES-->
<link type="text/css" rel="stylesheet" href="../styles/default/table.css"/>
<!--/STYLES-->
<!--JQUERY-->
<link type="text/css" rel="stylesheet" href="../styles/smoothness/jquery.ui.css"/>
<script type="text/javascript" src="../scripts/jquery.js"></script>
<script type="text/javascript" src="../scripts/jquery.ui.js"></script>
<script type="text/javascript" src="../scripts/jquery.imgpreview.js"></script>
<!--/JQUERY-->
<!--UPLOADIFY-->
<link rel="stylesheet" href="../uploadify/uploadify/uploadify.css" type="text/css" />
<link rel="stylesheet" href="../uploadify/css/uploadify.jGrowl.css" type="text/css" />
<script type="text/javascript" src="../uploadify/js/jquery.uploadify.js"></script>
<script type="text/javascript" src="../uploadify/js/jquery.jgrowl_minimized.js"></script>
<!--/UPLOADIFY-->
<!--TINYMCE-->
<script type="text/javascript" src="../scripts/tiny_mce/jquery.tinymce.js"></script>
<!--/TINYMCE-->
<!--CUSTOM-->
<script type="text/javascript" src="../scripts/jquery.cookie.js"></script>
<script type="text/javascript" src="../scripts/php.js"></script>
<script type="text/javascript" src="../scripts/custom.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	
	$("#tabs").tabs( { cookie: { expires: 30 } } );

	<? if ($show_file_uploader and $id != '') { ?>
	loadUploader('#fileUploadgrowl', '<? print $table; ?>', <? print $id; ?>, '<? print $fileDIR; ?>', '<? print $upload_file_types; ?>', <? print $file_size; ?>);
	fetchFiles('<? print $table; ?>', <? print $id; ?>);
	<? } ?>
	
});
</script>
<!--/CUSTOM-->
</head>
<body>
<? if ($id != '') { ?>
<div id="controls">
	<? if ($_SESSION['panel_view_url'] != '') { ?><a href="<? print $_SESSION['panel_view_url']; ?>"><img src="../styles/default/back.png" alt="back" border="0" class="button"/></a><? } ?>
	<a href="<? print $table.'.php?id='.$id; ?>"><img src="../styles/default/refresh.png" alt="refresh" border="0" class="button"/></a>
    <a href="<? print $table.'.php?id='.$id.'&duplicate=1'; ?>"><img src="../styles/default/copy.png" alt="duplicate" border="0" class="button"/></a>
    <a href="javascript:deleteRecord('<? print $table; ?>', <? print $id; ?>, '<? print $_SESSION['panel_view_url']; ?>');" id="delete"><img src="../styles/default/delete.png" alt="delete" border="0" class="button"/></a>
</div>
<div id="feedback"><? print $log; ?></div>
<? } ?>
<div id="tabs" class="ui-tabs">
<ul>
    <li><a href="#tabs-1">Data</a></li>
    <? if ($show_file_uploader and $id != '') { ?>
    <li><a href="#tabs-2">Files</a></li>
    <? } ?>
</ul>
<form name="<? print $table.'_'.$id; ?>" id="<? print $table.'_'.$id; ?>" method="post" action="<? print $table.'.php'; ?>">
<!--DATA UPLOADER-->
<div id="tabs-1" class="ui-tabs-hide"> 
<input type="hidden" name="id" id="id" value="<? echo $id; ?>" />
<input type="hidden" name="date_modified" id="date_modified" value="<? echo $date; ?>" />
<table border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td class="field_name">name</td>
    <td class="field"><input name="name" type="text" id="name" value="<? echo $ROW['name']; ?>" size="60" maxlength="100" /></td>
  </tr>
  <tr>
    <td class="field_name">date modified</td>
    <td class="field"><? if ($ROW['date_modified'] != '') { print ' Last modifed on: '.$ROW['date_modified']; } ?></td>
  </tr>
  <tr>
    <td class="field_name">date created</td>
    <td class="field"><input name="date_created" type="text" id="date_created" value="<? if ($id == '') { echo $date; } else { echo $ROW['date_created']; } ?>" size="20" maxlength="20" readonly="true"/></td>
  </tr>
  <tr>
    <td class="field_name">status</td>
    <td class="field"><? print gen_drop_menu('status', array('enabled', 'disabled'), $ROW['status']); ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><? if ($id == '') { print INSERT_BUTTON; } else { print UPDATE_BUTTON; } ?></td>
    <td>&nbsp;</td>
  </tr>
</table>
</div>
<!--/DATA UPLOADER-->
</form>
<!--FILE UPLOADER-->
<? if ($show_file_uploader and $id != '') { ?>
<div id="tabs-2" class="ui-tabs-hide">
<fieldset>
    <legend><strong>Upload Files</strong></legend>
    <p>File Size Limited to <? print number_format(($file_size / 1024 / 1024), 0, '.', ','); ?>MB<!-- - Queue Size <font id="queue_size"></font>--></p>
    <div id="fileUploadgrowl">You have a problem with your javascript</div>
    <div id="upload_controls" style="display:none;"><a href="javascript:$('#fileUploadgrowl').fileUploadStart()" id="start_upload"><img src="../styles/default/start.png" alt="start" border="0" class="button"/></a> <a href="javascript:clearUploadQueue();" id="clear_queue"><img src="../styles/default/clear.png" alt="clear" border="0" class="button"/></a></div>
    <p></p>
</fieldset>
<fieldset>
    <legend><strong>Uploaded Files</strong></legend>
    <div id="files"></div>
    <p></p>
</fieldset>
</div>
<? } ?>
<!--/FILE UPLOADER-->
</div>
<? require_once("../panel/dialog.php"); ?>
</body>
</html>
<?
	$mysqldb1->close();
	$mysqldb2->close();
?>