<?php

if ($_POST['submit'] != '') {
	$this->settings['role_ct'] = $_POST['wctrole_ct'];
	$this->settings['role_css'] = $_POST['wctrole_css'];
	$this->settings['role_archive'] = $_POST['wctrole_archive'];

	if ($_POST['wct_immaster'] != 'yes') { $_POST['wct_immaster'] = 'no'; }
	$this->settings['wct_immaster'] = $_POST['wct_immaster'];

	$qry = $wpdb->get_results("SELECT `id`,`name` FROM `".$wpdb->prefix."wct_list`;");
	foreach ($qry as $row) {
		if ($_POST['wctreset'] != '1') {
			$this->settings['crole'.$row->id.'_s'] = $_POST['wctrole_crole'.$row->id.'_s'];
			$this->settings['crole'.$row->id.'_c'] = $_POST['wctrole_crole'.$row->id.'_c'];
			$this->settings['crole'.$row->id.'_i'] = $_POST['wctrole_crole'.$row->id.'_i'];
		}
		else {
			$this->settings['crole'.$row->id.'_s'] = $_POST['wctrole_crolem_s'];
			$this->settings['crole'.$row->id.'_c'] = $_POST['wctrole_crolem_c'];
			$this->settings['crole'.$row->id.'_i'] = $_POST['wctrole_crolem_i'];
		}
	}

	$this->settings['wct_cachetime'] = $_POST['wctrole_cachetime'];

	update_option('wuk_custom_tables', $this->settings);

	echo __('Changes successfully saved', 'wct');
}

echo "<style type=\"text/css\">
fieldset
{
	margin-top: 1em;
	margin-right: 0pt;
	margin-bottom: 1em;
	margin-left: 0pt;
	background-color: #fdfdfd;
	background-image: none;
	background-repeat: repeat;
	background-attachment: scroll;
	background-position: 0% 0%;
	padding-top: 0pt;
	padding-right: 1em;
	padding-bottom: 1em;
	padding-left: 1em;
	border-top-width: 1px;
	border-right-width-value: 1px;
	border-right-width-ltr-source: physical;
	border-right-width-rtl-source: physical;
	border-bottom-width: 1px;
	border-left-width-value: 1px;
	border-left-width-ltr-source: physical;
	border-left-width-rtl-source: physical;
	border-top-style: solid;
	border-right-style-value: solid;
	border-right-style-ltr-source: physical;
	border-right-style-rtl-source: physical;
	border-bottom-style: solid;
	border-left-style-value: solid;
	border-left-style-ltr-source: physical;
	border-left-style-rtl-source: physical;
	border-top-color: #bbbbbb;
	border-right-color-value: #bbbbbb;
	border-right-color-ltr-source: physical;
	border-right-color-rtl-source: physical;
	border-bottom-color: #bbbbbb;
	border-left-color-value: #bbbbbb;
	border-left-color-ltr-source: physical;
	border-left-color-rtl-source: physical;
}
</style>
<form action=\"admin.php?page=".$_GET['page']."\" method=\"post\" onSubmit=\"return validate(this)\" name=\"wctform\">".__('Setup who can access which pages of the plugin.<br/>You can only break down on groups, not on users!','wct')."<fieldset><legend><strong>" . __('Rights', 'wct') . "</strong></legend><h3>". __('Global rights', 'wct')."</h3><table>";
$this->tablerights(__('Create Table', 'wct') ,'ct',$this->settings['role_ct']);
$this->tablerights(__('Edit CSS', 'wct') ,'css',$this->settings['role_css']);
$this->tablerights(__('Archive Setup', 'wct') ,'archive',$this->settings['role_archive']);

echo "</table><h3>". __('Table rights', 'wct')."</h3><table><tr><td valign=\"top\"><table>";
$qry = $wpdb->get_results("SELECT `id`,`name` FROM `".$wpdb->prefix."wct_list`;");
foreach ($qry as $row) {
	if (!array_key_exists('crole'.$row->id.'_s',$this->settings)) {
		$this->settings['crole'.$row->id.'_s'] = 'administrator';
		update_option('crole'.$row->id.'_s', $this->settings);
	}
	if (!array_key_exists('crole'.$row->id.'_c',$this->settings)) {
		$this->settings['crole'.$row->id.'_c'] = 'contributor';
		update_option('crole'.$row->id.'_c', $this->settings);
	}
	if (!array_key_exists('crole'.$row->id.'_i',$this->settings)) {
		$this->settings['crole'.$row->id.'_i'] = 'editor';
		update_option('crole'.$row->id.'_i', $this->settings);
	}
	$this->tablerights("&raquo; ".$row->name." ".__('Setup Option', 'wct'),'crole'.$row->id.'_s',$this->settings['crole'.$row->id.'_s']);
	$this->tablerights("&raquo; ".$row->name." ".__('Import/Export', 'wct'),'crole'.$row->id.'_i',$this->settings['crole'.$row->id.'_i']);
	$this->tablerights("&raquo; ".$row->name." ".__('Content', 'wct'),'crole'.$row->id.'_c',$this->settings['crole'.$row->id.'_c']);
	echo "<tr height=\"10\"><td colspan=\"2\"></td></tr>";
}
echo "</table></td><td style=\"background-image:url(" . plugins_url('custom-tables/img/table.png') . ");\" valign=\"bottom\"><img src=\"".plugins_url('custom-tables/img/tableend.png')."\" border=\"0\" alt=\"\"/></td><td valign=\"top\">
<input type=\"checkbox\" name=\"wctreset\" value=\"1\"> ".__('Reset all tables to following Standard').":<table>";

$this->tablerights( __('Setup Option', 'wct'),'crolem_s','administrator');
$this->tablerights( __('Import/Export', 'wct'),'crolem_i','editor');
$this->tablerights( __('Content', 'wct'),'crolem_c','contributor');

echo "</table></td></tr></table><input type=\"submit\" name=\"submit\" value=\"". __('Save all Changes', 'wct') ."\"></fieldset>
<fieldset><legend><strong>" . __('Cache', 'wct') . "</strong></legend><table>";
$this->option(__('Cache expire', 'wct'),'cachetime',$this->settings['wct_cachetime'],__('How long is the Cache valid in secounds', 'wct'));
echo "</table>". __('<b>Attention:</b> Cache functionality will only work, if the Caching functionality in WordPress is enabled and a cache plugin is installed.','wct')."<br/><input type=\"submit\" name=\"submit\" value=\"". __('Save all Changes', 'wct') ."\"></fieldset>

<fieldset><legend><strong>" . __('Advanced Features', 'wct') . "</strong></legend>".
__('Table Indexes', 'wct')." <input type=\"checkbox\" name=\"wct_immaster\" value=\"yes\"";
if ($this->settings['wct_immaster'] == 'yes') { echo " checked"; }
echo "> ".__('If you want to enable Table Indexes to define which fields can be searched faster.', 'wct')."<br/>".
__('<b>Attention:</b> This feature should only be used by Database Engineers which knowing what they are doing. In fact, correct indexes can speedup the database by user searches, but on wrong indexes destroy database performance at all.','wct')."
<br/><input type=\"submit\" name=\"submit\" value=\"". __('Save all Changes', 'wct') ."\"></fieldset></form>";


?>