<?
Serval::call('tpl')->settings = $config['settings'];  

switch($path['2']){
	case '':
		Serval::call('tpl')->PAGE['name'] = "Проекты";
		Serval::call('tpl')->PAGE['meta_title'] = "Проекты";
		Serval::call('tpl')->PAGE['url']	= "projects";
		Serval::call('tpl')->getList = Serval::call('Projects')->getList(array('page'=>$_GET['page']));
		if($_GET['users_id']>0){
			Serval::call('tpl')->getFilter = "users_id=".(int)$_GET['users_id'];
		}
		Serval::call('tpl')->display("projects");
	break;
	default:
		if( $getProject = Serval::call('Projects')->getProject((int)$path[2]) ){
			Serval::call('tpl')->getProject = $getProject;
			Serval::call('tpl')->project_id = $getProject['id'];
			switch($path['3']){
				case 'structure':
					if($log = Serval::call('db')->SelectRecord("mod_scan","","is_last='yes' AND project_id=".$getProject['id']) ){
						$where = array(
							"project_id='{$getProject['id']}'",
							"scan_id={$log['id']}"
						);

						if($_GET['level']>0){
							$where[] = "level=".(int)$_GET['level'];
						}else{
							$where[] = "level=0";
						}
						if(!empty($_GET['path'])){
							$where[] = "path LIKE(".Serval::call('db')->Quote($_GET['path'].'%').")";
						}
						Serval::call('tpl')->getList = array(
							'file'=>Serval::call('db')->Select("mod_scan_log","",implode(" AND ",$where),"ORDER BY path"),
							'dir'=>Serval::call('db')->Select("mod_scan_dir","",implode(" AND ",$where),"ORDER BY path")
						);
					}
					Serval::call('tpl')->header = false;
					Serval::call('tpl')->footer = false;
					Serval::call('tpl')->display("projects_structure",empty($_GET['ajax']));
				break;
				case 'log':
					Serval::call('tpl')->PAGE['meta_title'] = "Лог изменений: ".$getProject['domain'];
					Serval::call('tpl')->popup = true;
					Serval::call('tpl')->getList = Serval::call('Projects')->getLogList(array('project_id'=>$getProject['id'],'page'=>$_GET['page']));
					Serval::call('tpl')->header = false;
					Serval::call('tpl')->footer = false;
					Serval::call('tpl')->PAGE['url'] = "projects/".$path[2]."/log";
					Serval::call('tpl')->display("projects_log");
				break;
				case 'download':
					$data		= file_get_contents("./data/Scanner.php");        
					$data		= str_replace("{[sCODE]}",md5($getProject['scode'].$config['solt']),$data);
					$copyright = "/**\n";
					$copyright.= " * SerVal site safe PHP-scanner\n"; 
					$copyright.= " * v. 1.6\n";
					$copyright.= " * More information on site http://www.serval.site\n";
					$copyright.= " * The project of the ELiTES http://www.elites.ru\n";
					$copyright.= " */\n\r";
          
          
					if(empty($getProject['path'])){
						?><script>alert('Укажите адрес скрипта мониторинга!');</script><?
					}else{   
						if(isset($_GET['src'])){
								$data		= str_replace("{[copyright]}",$copyright,$data);
								$file		=	pathinfo($getProject['path']);
								header('Content-Type: application/force-download');
								header('Content-Disposition: inline; filename="'.$file['basename'].'"');
								echo $data;
								die();
						}else{
							$data		= str_replace("{[copyright]}","",$data);
							Serval::call('PhpObfuscator')->saveFile 	= false;
							Serval::call('PhpObfuscator')->content 	= true;
							if($f = Serval::call('PhpObfuscator')->obfuscate($data,$copyright)){
								$file=pathinfo($getProject['path']);
								header('Content-Type: application/force-download');
								header('Content-Disposition: inline; filename="'.$file['basename'].'"');
								echo $f;
							}else{
								?><script>alert('Ошибка!');</script><?
							}   
						}      
					}
					die();
				break;
				case 'verified':
				
				break;
				default:
					Serval::call('tpl')->error404();
			}
		}else{
			Serval::call('tpl')->error404();
		}
}
?>