<?php require_once 'auth.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
		"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title><?=getTitle(__FILE__)?></title>
	<link rel="stylesheet" href="phpME.css" type="text/css"></link>
</head>
<body onLoad='documentOnLoad()'>
<h3><?=getTitle(__FILE__)?></h3>
		<script language=javascript>
		function windowOpen(u) {
			var saveTarget = document.forms[0].target;
			var saveAction = document.forms[0].action;
			document.forms[0].target = "_blank";
			document.forms[0].action = u;
			document.forms[0].submit();
			document.forms[0].target = saveTarget;
			document.forms[0].action = saveAction;
		}
		</script>
<?php

	if ($isSupervisor) {
		$userAction['cleanReport'] = 1;
		$userAction['cleanTemp'] = 1;
		$userAction['cleanCrc'] = 1;
	} else {
		$baseFile = $arrFILE[basename(__FILE__)];
		$userAction = getUserActions($_SESSION['userid'], $baseFile);
	}

	if (in_array($_REQUEST['operation'],array(__('Change'),__('Add')))
	|| isset($_REQUEST['morechange']) || isset($_REQUEST['moreadd'])) {
	} else {
?>

<?php if ($userAction['cleanReport'] === 1) { ?>
<script language=javascript>
	function clean_report() {
		windowOpen('clean_report.php', 600, 200);
	}
</script>
<input type=button value='<?=__('Clean Report')?>' onClick="clean_report()">
<?php } ?>

<?php if ($userAction['cleanTemp'] === 1) { ?>
<script language=javascript>
	function clean_temp() {
		windowOpen('clean_temp.php', 600, 200);
	}
</script>
<input type=button value='<?=__('Clean Temp')?>' onClick="clean_temp()">
<?php } ?>

<?php if (false && $userAction['cleanCrc'] === 1) { ?>
<script language=javascript>
	function clean_crc() {
		windowOpen('clean_crc.php', 600, 200);
	}
</script>
<input type=button value='<?=__('Clean CRC')?>' onClick="clean_crc()">
<?php } ?>
<br/><br/>
<?php
	}

	if ($isSupervisor) {
		$userAction['viewHistory'] = 1;
		$userAction['viewLog'] = 1;
		$userAction['viewData'] = 1;
		$userAction['testDSN'] = 1;
		$userAction['dropTable'] = 1;
		$userAction['createTable'] = 1;
		$userAction['import'] = 1;
		$userAction['diff'] = 1;
		$userAction['crc'] = 1;
        $userAction['replace'] = 1;
        $userAction['update'] = 1;
	} else {
		$baseFile = $arrFILE[basename(__FILE__)];
		$userAction = getUserActions($_SESSION['userid'], $baseFile);
	}

	if (in_array($_REQUEST['operation'],array(__('Change'),__('Add')))
	|| isset($_REQUEST['morechange']) || isset($_REQUEST['moreadd'])) {
?>
<?php 		if ($userAction['viewHistory'] === 1) { ?>
		<input type=button value='<?=__('View History')?>' onClick='windowOpen("viewhistory.php")'>
<?php 		} ?>

<?php 		if ($userAction['viewLog'] === 1) { ?>
		<input type=button value='<?=__('View Log')?>' onClick='windowOpen("viewlog.php")'>
<?php 		} ?>

<?php 		if ($userAction['viewData'] === 1) { ?>
		<input type=button value='<?=__('View Data')?>' onClick='windowOpen("viewdata2.php")'>
<?php 		} ?>

<?php 		if ($userAction['testDSN'] === 1) { ?>
		<input type=button value='<?=__('Test DSN')?>' onClick='windowOpen("testdsn.php")'>
<?php 		} ?>

<?php 		if ($userAction['dropTable'] === 1) { ?>
		<input type=button value='<?=__('Drop Table')?>' onclick='windowOpen("droptable.php")'>
<?php 		} ?>

<?php 		if ($userAction['createTable'] === 1) { ?>
		<input type=button value='<?=__('Create Table')?>' onClick='windowOpen("createtable.php")'>
<?php 		} ?>

<?php 		if ($userAction['import'] === 1) { ?>
		<input type=button value='<?=__('Import')?>' onClick='windowOpen("importtable2.php")'>
<?php 		} ?>

<?php 		if ($userAction['diff'] === 1) { ?>
		<input type=button value='<?=__('Diff')?>' onClick='windowOpen("difftable.php")'>
<?php 		} ?>

<?php 		if ($userAction['replace'] === 1) { ?>
		<input type=button value='<?=__('replace')?>' onClick='windowOpen("replacetable.php")'>
<?php 		} ?>

<?php 		if ($userAction['update'] === 1) { ?>
		<input type=button value='<?=__('update')?>' onClick='windowOpen("updatetable.php")'>
<?php 		} ?>

<?php 		if (false && $userAction['crc'] === 1) { ?>
		<input type=button value='<?=__('CRC')?>' onClick='windowOpen("crctable.php")'>
<?php 		} ?>



		<br/><br/>
<?php
	}

	echo "
	<script language=javascript>
		function documentOnLoad() {
	";

	$rs = $adodb->Execute("SELECT * FROM qb_config WHERE id = ?", $_REQUEST['rec']);
	if (!$rs->EOF) {
		$rs = $adodb->Execute("SELECT * FROM ".$rs->fields['tableid']." LIMIT 1");
		if ($rs) {
			echo "
				if (document.forms[0] && document.forms[0].tableid) {
					document.forms[0].tableid.readOnly = true;
					document.forms[0].tableid.style.color = 'gray';
				}
			";
		}
	}
	echo "
		}
	</script>
	";

/*
 * IMPORTANT NOTE: This generated file contains only a subset of huge amount
 * of options that can be used with phpMyEdit. To get information about all
 * features offered by phpMyEdit, check official documentation. It is available
 * online and also for download on phpMyEdit project management page:
 *
 * http://www.platon.sk/projects/main_page.php?project_id=5
 */

// MySQL host name, user name, password, database, and table
require_once 'config.php';
$opts['hn'] = $adodb_host;
$opts['un'] = $adodb_user;
$opts['pw'] = $adodb_pass;
$opts['db'] = $adodb_db;
$opts['tb'] = 'qb_config';

// Name of field which is the unique key
$opts['key'] = 'id';

// Type of key field (int/real/string/date etc.)
$opts['key_type'] = 'int';

// Sorting field(s)
$opts['sort_field'] = array('id');

// Number of records to display on the screen
// Value of -1 lists all records in a table
$opts['inc'] = 25;

// Options you wish to give the users
// A - add,  C - change, P - copy, V - view, D - delete,
// F - filter, I - initial sort suppressed
$opts['options'] = 'ADCF'; // DPV

// Number of lines to display on multiple selection filters
$opts['multiple'] = '4';

// Navigation style: B - buttons (default), T - text links, G - graphic links
// Buttons position: U - up, D - down (default)
$opts['navigation'] = 'UG'; //'DB';

// Display special page elements
$opts['display'] = array(
	'form'  => true,
	'query' => true,
	'sort'  => true,
	'time'  => true,
	'tabs'  => true
);

$opts['logtable'] =  isLogTable($opts['tb']); //'qb_changelog';

/* Get the user's default language and use it if possible or you can
   specify particular one you want to use. Refer to official documentation
   for list of available languages. */
$opts['language'] = $HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE'];

/* Table-level filter capability. If set, it is included in the WHERE clause
   of any generated SELECT statement in SQL query. This gives you ability to
   work only with subset of data from table.

$opts['filters'] = "column1 like '%11%' AND column2<17";
$opts['filters'] = "section_id = 9";
$opts['filters'] = "PMEtable0.sessions_count > 200";
*/


/* Field definitions

Fields will be displayed left to right on the screen in the order in which they
appear in generated list. Here are some most used field options documented.

['name'] is the title used for column headings, etc.;
['maxlen'] maximum length to display add/edit/search input boxes
['trimlen'] maximum length of string content to display in row listing
['width'] is an optional display width specification for the column
          e.g.  ['width'] = '100px';
['mask'] a string that is used by sprintf() to format field output
['sort'] true or false; means the users may sort the display on this column
['strip_tags'] true or false; whether to strip tags from content
['nowrap'] true or false; whether this field should get a NOWRAP
['required'] true or false; if generate javascript to prevent null entries
['select'] T - text, N - numeric, D - drop-down, M - multiple selection
['options'] optional parameter to control whether a field is displayed
  L - list, F - filter, A - add, C - change, P - copy, D - delete, V - view
            Another flags are:
            R - indicates that a field is read only
            W - indicates that a field is a password field
            H - indicates that a field is to be hidden and marked as hidden
['URL'] is used to make a field 'clickable' in the display
        e.g.: 'mailto:$value', 'http://$value' or '$page?stuff';
['URLtarget']  HTML target link specification (for example: _blank)
['textarea']['rows'] and/or ['textarea']['cols']
  specifies a textarea is to be used to give multi-line input
  e.g. ['textarea']['rows'] = 5; ['textarea']['cols'] = 10
['values'] restricts user input to the specified constants,
           e.g. ['values'] = array('A','B','C') or ['values'] = range(1,99)
['values']['table'] and ['values']['column'] restricts user input
  to the values found in the specified column of another table
['values']['description'] = 'desc_column'
  The optional ['values']['description'] field allows the value(s) displayed
  to the user to be different to those in the ['values']['column'] field.
  This is useful for giving more meaning to column values. Multiple
  descriptions fields are also possible. Check documentation for this.
*/

$opts['fdd']['id'] = array(
  'name'     => 'ID',
  'select'   => 'T',
  'options'  => 'AVCPDR', // auto increment
  'maxlen'   => 11,
  'default'  => '0',
  'sort'     => true
);
$opts['fdd']['tableid'] = array(
  'name'     => 'Tableid',
  'select'   => 'T',
  'maxlen'   => 32,
  'sort'     => true
);
$opts['fdd']['history_mode'] = array(
  'name'     => __("History Mode"),
  'select'   => 'T',
  'maxlen'   => 65535,
  'sort'     => false,
  'options'	=> 'AC',
  'values2'	=> array(3 => "", 0 => __("diff"), 1 => __("replace"), 2 => __("update"))
);
$opts['fdd']['sqlcreate'] = array(
  'name'     => 'SQL Create',
  'trimlen'  => 100,
  'select'   => 'T',
  'maxlen'   => 65535,
  'textarea' => array(
    'rows' => 5,
    'cols' => 50),
  'sort'     => true,
  'options'  => 'AC'
);
$opts['fdd']['dsn'] = array(
  'name'     => 'DSN',
  'select'   => 'T',
  'maxlen'   => 255,
  'sort'     => true,
  'options'  => 'AC',
//  'tab'     => 'Remote Connection'
);
$opts['fdd']['user'] = array(
  'name'     => 'User',
  'select'   => 'T',
  'maxlen'   => 255,
  'sort'     => true,
  'options'  => ''
);
$opts['fdd']['pass'] = array(
  'name'     => 'Pass',
  'select'   => 'T',
  'maxlen'   => 255,
  'sort'     => true,
  'options'  => ''
);
$opts['fdd']['sqlimport'] = array(
  'name'     => 'SQL Import',
  'trimlen'  => 100,
  'select'   => 'T',
  'maxlen'   => 65535,
  'sort'     => true,
  'textarea' => array(
    'rows' => 5,
    'cols' => 50),
);

$opts['triggers']['delete']['after'] = 'tableconfig.TDA.inc.php';

// Now important call to phpMyEdit
$moduleId = 'Import.Table Config';
$opts['options'] = getUserOptions($moduleId, $opts['options']);
$opts['filters'] = getUserFilters($moduleId);
require_once 'phpMyEdit.class.php';
new phpMyEdit($opts);

?>

</body>
</html>