<?php
include_once 'common.php';

$user_data = authenticate($C_event_users, $translate);
$dir = $C_event_props;

if(isset($_REQUEST['delete']) && !empty($_REQUEST['delete'])) {
	$delete_enc = base64_decode($_REQUEST['delete']);
	$iv = substr($delete_enc, 0, openssl_cipher_iv_length('aes256'));
	$delete_dec = openssl_decrypt(substr($delete_enc, openssl_cipher_iv_length('aes256')), 'aes256', hash('sha256', SECRET, true), 0, $iv);
	if(is_file($dir."/".$delete_dec)) {
		unlink($dir."/".$delete_dec);
	}
}

?>
<!DOCTYPE html>
<html lang="<?php echo($actual); ?>">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Polemic Tweet &mdash; event form</title>
    <meta http-equiv="X-UA-Compatible" content="IE=9" />

    <!-- FONT -->
    <link href='<?php echo(registry_url('PT-Sans_Narrow','font'))?>' rel='stylesheet' type='text/css'>
    <link href='<?php echo(registry_url('PT-Sans','font'))?>' rel='stylesheet' type='text/css'>
    
    <!-- CSS -->
    <link rel="stylesheet" href="<?php echo(registry_url('blueprint-screen','css'));?>" type="text/css" media="screen, projection"/>
    <link rel="stylesheet" href="<?php echo(registry_url('blueprint-print','css'));?>" type="text/css" media="print"/>
    <!--[if lt IE 8]><link rel="stylesheet" href="<?php echo(registry_url('blueprint-ie','css'));?>" type="text/css" media="screen, projection"><![endif]-->
	<link rel="stylesheet" href="<?php echo(registry_url('blueprint-plugins-fancy-type','css'));?>" type="text/css" media="screen, projection"/>
	<link rel="stylesheet" href="<?php echo(registry_url('custom','css'));?>" type="text/css" media="screen, projection"/>
    
    <!-- JAVASCRIPT -->
    <script type="text/javascript" src="<?php echo(registry_url('jquery','js'))?>"></script>
    <script type="text/javascript" src="<?php echo(registry_url('underscore','js'))?>"></script>
    
    <script type="text/javascript">
    	$(function() {
        	$(".delete-lnk").click(function(e) {
            	if(!confirm("<?php echo $translate->_('Event_confirm_delete_archive'); ?>")) {
                	e.preventDefault();
            	}
        	});
    	});
    </script>
    
</head>
<body>

	<div id="sendUsFeedBack"><a href="<?php echo($C_feedback_form_url); ?>" target="_blank"><img src="<?php echo(URL_ROOT); ?>images/sendusfeedback.png"></a></div>
    <div class="container">
      <img src="images/ENMI_2010_logo.gif" class="logo">
	  <ul class="menu">
		  <li class="menuUnderline"><a href="<?php echo(URL_ROOT); ?>" class="menuLink">
		  	<?php print $translate->_("Accueil"); ?></a></li>
		  <li class="menuUnderline"><a href="<?php echo(URL_ROOT); ?>about.php" class="menuLink">
		  	<?php print $translate->_("A propos"); ?></a></li>
		  <li ><a href="mailto:contact@iri.centrepompidou.fr" class="menuLink" >
		  	<?php print $translate->_("Contact"); ?></a></li>
	  </ul>
	  <ul class="menu">
		  <li class="menuUnderline"><a href="<?php echo(URL_ROOT); ?>archives.php" class="menuLink">
		  	<?php print $translate->_("Archives"); ?></a></li>
		<?php
		if($_SESSION['auth']) { ?>
		  <li class="menuUnderline"><a href="<?php echo(URL_ROOT); ?>logout.php" class="menuLink">
		  	<?php print $translate->_("Logout"); ?></a></li>
		<?php
		}
		?>
	  </ul>
	  
	  
	  <ul class="menu lang" >
	  <li class="menuUnderline"><a href="<?php echo(URL_ROOT); ?>event_list.php?lang=ja_JP" class="menuLink" >
	       <img src='images/flag_jp.gif'<?php if($actual!="ja_JP"){echo("style='opacity: .5;'"); } ?> />
	        <?php print $translate->_("Japonais"); ?></a></li>
	  <li class="menuUnderline"><a href="<?php echo(URL_ROOT); ?>event_list.php?lang=fr" class="menuLink">
	       <img src='images/flag_fr.gif' <?php if($actual!="fr"){echo("style='opacity: .5;'"); } ?> />
	       <?php print $translate->_("Français"); ?></a></li>
	  <li ><a href="<?php echo(URL_ROOT); ?>event_list.php?lang=en" class="menuLink">
	       <img src='images/flag_en.gif' <?php if($actual!="en"){echo("style='opacity: .5;'"); } ?> />
	       <?php print $translate->_("Anglais"); ?></a></li>
	  </ul>
	</div>
	<div class="container">
	<?php
	if(!isset($user_data) || isset($user_data['error'])) {
		print "<div class=\"error-message\"><h2>".$user_data['error']."</h2></div>";
	}
	else {
	?>
	
		<ul class="event-list">
		<?php
		$files = scandir($dir);
		$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes256'));
		
		foreach($files as $ind_file) {
			if (stripos($ind_file, '.') !== 0) {
				$token = base64_encode(
					$iv .
					openssl_encrypt(
						$ind_file,
						'aes256',
						hash('sha256', SECRET, true),
						0,
						$iv
					)
				);
		?>
			<li><a href="<?php echo "event_props/".$ind_file;?>"><?php echo $ind_file;?></a><a href="?delete=<?php print urlencode($token); ?>" class="delete-lnk"><span class="delete-btn"></span></a></li>
		<?php
			}
		}
		?>
		</ul>
	<?php }?>
	</div>
</body>
</html>