<?php
print "
<div class='container'>
	<form action='".$_SERVER['REQUEST_URI']."' method='post' enctype='multipart/form-data'>
		<div class='form'>
			<div class='form-head toggle ";
	if (isset($_SESSION['backend']['toggle_filter']) && $_SESSION['backend']['toggle_filter']) print'toggled';
	print "'>
				<i class='material-icons md-24'>filter_alt</i>".LABEL_FILTER."<i class='ico-toggle material-icons md-24'>expand_less</i>
			</div>
			<div class='form-content ";
	if (isset($_SESSION['backend']['toggle_filter'])) print $_SESSION['backend']['toggle_filter'];
	print "' data-module='".$module."' data-backend-module='".$backend_module."'>
				<input type='hidden' name='csrf_token' value='".htmlspecialchars(csrf_token())."'>
				<input type='hidden' name='filter' value='1' />
				<input type='hidden' name='export' value='0' />";
	
	include('function/encrypt.php');
	
	print "
				<div class='form-action'>
					<button type='submit' class='btn search' title='".LABEL_DO_FILTER."'><i class='material-icons md-24'>filter_alt</i>".LABEL_DO_FILTER."</button>
				</div><!-- /.form-action -->
				
			</div><!-- /.form-content -->
		</div><!-- /.form -->";



print "	
		<div class='table'>
			<div class='table-head'>
				<div class='table-row'>
					<div class='table-cell size-medium'><a href='#'>".LABEL_MODULE."</a></div><!-- /.table-cell -->
					<div class='table-cell size-medium'><a href='#'>".LABEL_TITLE."</a></div><!-- /.table-cell -->
					<div class='table-cell'><a href='#'>".LABEL_ENCRYPTED_FIELDS."</a></div><!-- /.table-cell -->
					<div class='table-cell toolbar size-1'></div><!-- /.table-cell -->
				</div><!-- /.table-row -->
			</div><!-- /.table-head -->";
			

$encrypt_modules = array();
$modules_folder = array_diff(scandir('modules'), array('.', '..'));
foreach ($modules_folder as $module_folder){
  if (is_dir('modules/'.$module_folder) && is_file('modules/'.$module_folder.'/encrypt_config.php')){
    $encrypt_modules[$module_folder] = include('modules/'.$module_folder.'/encrypt_config.php');
  }
}

if (isset($encrypt_modules) && is_array($encrypt_modules)){
	print "
			<div class='table-body no-context'>";
	foreach ($encrypt_modules AS $module_key => $module_value){
		foreach ($module_value AS $table_key => $table_value){
			if (check_table($table_key)){
				$count_fields = count($table_value);
				$count_encrypted_fields = 0;
				foreach ($table_value AS $field => $field_data){
					if (check_column($table_key, $field.'_hash')) $count_encrypted_fields++;
				}
				print "
				<div class='table-row'>
					<div class='table-cell'>".$module_key."</div><!-- /.table-cell -->
					<div class='table-cell'>".$table_key."</div><!-- /.table-cell -->
					<div class='table-cell'>".$count_encrypted_fields." / ".$count_fields."</div><!-- /.table-cell -->
					<div class='table-cell toolbar'>
						<a href='#' class='edit' data-id='".$table_key."' data-module='".$module."' data-backend-module='".$backend_module."' title='".LABEL_EDIT."'><i class='material-icons md-22'>edit</i></a>
					</div><!-- /.table-cell -->
				</div><!-- /.table-row -->";
			}
		}
	}
	print "
			</div><!-- /.table-body -->";
}
		
print "
	</div><!-- /.table -->
</div><!-- /.container -->";