<?php require_once('../functions/crm_settings.php'); ?>
<html>
<head>
	<meta charset="utf-8" />
	<title>Файловая система</title>
	<link rel="stylesheet" href="/<? echo $folder; ?>/assets/css/style.css" />
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" />
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.js"></script>
	<style type="text/css">
		body { 
			width:auto!important;
			font-family:Arial;
			margin:15px!important;
		}
		ol:nth-child(1) {
			margin:0px!important;
			padding:0px!important;
		}
		ol {
			font-size:10pt;
		}
		ol li {
			display:block;
			line-height:25px;
			padding:0 0px 0 5px;
			border:0px;
			margin:3px 0px;
		}
		ol li .date {
			display:inline-block;
			line-height:25px;
			background:#00557e;
			color:#fff;
			padding:0px 10px;
			margin-right:10px;
			margin-left:-5px;
			cursor:default;
		}
		ol li .date.select {
			background:#3ba605;
			color:#fff;
		}
		ol li .date.dir {
			cursor:pointer;
		}
		ol li {
			background:rgba(129,146,154,0.1);
		}
		ol li ol li {
			background:rgba(129,146,154,0.15);
		}
		ol li ol li ol li {
			background:rgba(129,146,154,0.3);
		}
	</style>
</head>
<body style="margin:50px 0px;">
	<div class="loader"></div>
	<h1>Файловая система<span style="float:right;"><i class="fa fa-fw fa-th-list" title="Развернуть/Свернуть"></i></span></h1>
	<div class="container">
		<?php
		// Запрос вида /_wb/admin/crm-files.php?day=0
		// где day - количество дней назад
		
		if(isset($_GET["day"]) and $_GET["day"] != '') {
			$num = '-' . $_GET["day"];
		} else {
			$num = '0';
		}
		function listFolderFiles($dir){
			global $num;
			
			$ffs = scandir($dir);

			unset($ffs[array_search('.', $ffs, true)]);
			unset($ffs[array_search('..', $ffs, true)]);

			// prevent empty ordered elements
			if (count($ffs) < 1)
				return;
			echo '<ol>';
			foreach($ffs as $ff){
				echo '<li style="display:block;">';
						if(is_dir($dir.'/'.$ff)){
							echo '<span class="date '; if(is_dir($dir.'/'.$ff)){echo 'dir ';} if(date ("d.m.Y", filemtime($dir.'/'.$ff)) == date('d.m.Y', strtotime("$num day"))){echo 'select';} echo '" title="Развернуть папку">' . date ("d.m.Y", filemtime($dir.'/'.$ff)) . '</span>';
						} else {
							echo '<span class="date '; if(date ("d.m.Y", filemtime($dir.'/'.$ff)) == date('d.m.Y', strtotime("$num day"))){echo 'select';} echo '">' . date ("d.m.Y", filemtime($dir.'/'.$ff)) . '</span>';
						}
					if(is_dir($dir.'/'.$ff)){echo '<i class="fa fa-fw fa-folder"></i>';} else {echo '<i class="fa fa-fw fa-file-text-o"></i>';}
					echo $ff;
					if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);
				echo '</li>';
			}
			echo '</ol>';
		}
		listFolderFiles(ROOT);
		?>
	</div>
	
	<script>
		$('ol li span.date').each(function(){
			$(this).click(function(){
				$(this).parent().children('ol').toggle();
			});
		});
		$('i.fa-th-list').click(function(){
			$('ol:nth-child(1) li ol').toggle();
		});
		$(document).ready(function() {
			$('ol:nth-child(1) li ol').hide();
			$('li span.select').each(function(){
				$(this).parent().parent().parent().children('span.date').addClass('select');
			});
			$('.loader').fadeOut(1000);
		});
		
	</script>
</body>
</html>