View file modules/downloads/attach_screen.php

File size: 7.4Kb
<?php
/**********************************
*	@package: PerfCMS			  *
*	@year: 2012					  *
*	@author: Artas				  *
*	@link: http://perfcms.org.ua  *
**********************************/
$locate	= 'in_downloads';
$file_id = abs(intval($_GET['id']));
if(!isset($file_id) && $db->query("SELECT * FROM `downloads_files` WHERE `id` = '$file_id'")->rowCount() == 0 || $user['level'] < 4)
	{
		header('location: /downloads/');
		exit;
	}
$filei = $db->query("SELECT * FROM `downloads_files` WHERE `id` = '". $file_id ."'")->fetch();
if(isset($_GET['act']) && $_GET['act'] == 'save')
	{
		import_lib('upload.class');
		if ($_FILES['screen_1']['tmp_name']) 
		{
			if(file_exists(ROOT.'/files/downloads_screens/screen_1_'.$filei['server_name'].'.png')) unlink(ROOT.'/files/downloads_screens/screen_1_'.$filei['server_name'].'.png');
			$handle = new upload($_FILES['screen_1']);
			if ($handle->uploaded) {
				$handle->allowed = array('image/*');
				$handle->file_new_name_body 	= 'screen_1_'.$filei['server_name'];
				$handle->image_convert 			= 'png';
				$handle->image_resize			= true;
				$handle->image_x				= 100;
				$handle->image_y				= 150;
				$handle->process(ROOT. '/files/downloads_screens/');
			if ($handle->processed) {
				// echo 'image resized';
				$handle->clean();
				} 
			else {
          // echo 'error : ' . $handle->error;
				}
			}
		}
		if ($_FILES['screen_2']['tmp_name']) 
		{
			if(file_exists(ROOT.'/files/downloads_screens/screen_2_'.$filei['server_name'].'.png')) unlink(ROOT.'/files/downloads_screens/screen_2_'.$filei['server_name'].'.png');
			$handle = new upload($_FILES['screen_2']);
			if ($handle->uploaded) {
				$handle->allowed = array('image/*');
				$handle->file_new_name_body 	= 'screen_2_'.$filei['server_name'];
				$handle->image_convert 			= 'png';
				$handle->image_resize			= true;
				$handle->image_x				= 100;
				$handle->image_y				= 150;
				$handle->process(ROOT. '/files/downloads_screens/');
			if ($handle->processed) {
				// echo 'image resized';
				$handle->clean();
				} 
			else {
          // echo 'error : ' . $handle->error;
				}
			}
		}
		if ($_FILES['screen_3']['tmp_name']) 
		{
			if(file_exists(ROOT.'/files/downloads_screens/screen_3_'.$filei['server_name'].'.png')) unlink(ROOT.'/files/downloads_screens/screen_3_'.$filei['server_name'].'.png');
			$handle = new upload($_FILES['screen_3']);
			if ($handle->uploaded) {
				$handle->allowed = array('image/*');
				$handle->file_new_name_body 	= 'screen_3_'.$filei['server_name'];
				$handle->image_convert 			= 'png';
				$handle->image_resize			= true;
				$handle->image_x				= 100;
				$handle->image_y				= 150;
				$handle->process(ROOT. '/files/downloads_screens/');
			if ($handle->processed) {
				// echo 'image resized';
				$handle->clean();
				} 
			else {
          // echo 'error : ' . $handle->error;
				}
			}
		}
		if ($_FILES['screen_4']['tmp_name']) 
		{
			if(file_exists(ROOT.'/files/downloads_screens/screen_4_'.$filei['server_name'].'.png')) unlink(ROOT.'/files/downloads_screens/screen_4_'.$filei['server_name'].'.png');
			$handle = new upload($_FILES['screen_4']);
			if ($handle->uploaded) {
				$handle->allowed = array('image/*');
				$handle->file_new_name_body 	= 'screen_4_'.$filei['server_name'];
				$handle->image_convert 			= 'png';
				$handle->image_resize			= true;
				$handle->image_x				= 100;
				$handle->image_y				= 150;
				$handle->process(ROOT. '/files/downloads_screens/');
			if ($handle->processed) {
				// echo 'image resized';
				$handle->clean();
				} 
			else {
          // echo 'error : ' . $handle->error;
				}
			}
		}
		if ($_FILES['screen_5']['tmp_name']) 
		{
			if(file_exists(ROOT.'/files/downloads_screens/screen_5_'.$filei['server_name'].'.png')) unlink(ROOT.'/files/downloads_screens/screen_5_'.$filei['server_name'].'.png');
			$handle = new upload($_FILES['screen_5']);
			if ($handle->uploaded) {
				$handle->allowed = array('image/*');
				$handle->file_new_name_body 	= 'screen_5_'.$filei['server_name'];
				$handle->image_convert 			= 'png';
				$handle->image_resize			= true;
				$handle->image_x				= 100;
				$handle->image_y				= 150;
				$handle->process(ROOT. '/files/downloads_screens/');
			if ($handle->processed) {
				// echo 'image resized';
				$handle->clean();
				} 
			else {
          // echo 'error : ' . $handle->error;
				}
			}
		}
	}
if(isset($_GET['delete']) && $_GET['delete'] >= 1 && $_GET['delete'] <=5) {
	unlink(ROOT.'/files/downloads_screens/screen_'.abs(intval($_GET['delete'])).'_'.$filei['server_name'].'.png');
	header('location: /downloads/attach_screen/'.$file_id);
	exit;
}
$title = $lang->word('dl_attach_screenshot').' | '.$lang->word('downloads');
require_once(SYS.'/view/header.php');
$tpl->div('title', $lang->word('dl_attach_screenshot'));
echo '<div class="menu">
		<form action="/downloads/attach_screen/'.$file_id.'?act=save" method="post" enctype="multipart/form-data">
		'.(file_exists(ROOT.'/files/downloads_screens/screen_1_'.$filei['server_name'].'.png') ?
			'<img src="/files/downloads_screens/screen_1_'.$filei['server_name'].'.png" weight="150" width="100" alt="Screen" /><br/>
			<a href="/downloads/attach_screen/'.$file_id.'?delete=1">'.$lang->word('delete').'</a><br/>
			' : NULL).'
			'.$lang->word('dl_choose_screenshot').':<br/>
			<input type="file" name="screen_1" /><br/>
		'.(file_exists(ROOT.'/files/downloads_screens/screen_2_'.$filei['server_name'].'.png') ?
			'<img src="/files/downloads_screens/screen_2_'.$filei['server_name'].'.png" weight="150" width="100" alt="Screen" /><br/>
			<a href="/downloads/attach_screen/'.$file_id.'?delete=2">'.$lang->word('delete').'</a><br/>' : NULL).'
			'.$lang->word('dl_choose_screenshot').':<br/>
			<input type="file" name="screen_2" /><br/>
		'.(file_exists(ROOT.'/files/downloads_screens/screen_3_'.$filei['server_name'].'.png') ?
			'<img src="/files/downloads_screens/screen_3_'.$filei['server_name'].'.png" weight="150" width="100" alt="Screen" /><br/>
			<a href="/downloads/attach_screen/'.$file_id.'?delete=3">'.$lang->word('delete').'</a><br/>' : NULL).'
			'.$lang->word('dl_choose_screenshot').':<br/>
			<input type="file" name="screen_3" /><br/>
		'.(file_exists(ROOT.'/files/downloads_screens/screen_4_'.$filei['server_name'].'.png') ?
			'<img src="/files/downloads_screens/screen_4_'.$filei['server_name'].'.png" weight="150" width="100" alt="Screen" /><br/>
			<a href="/downloads/attach_screen/'.$file_id.'?delete=4">'.$lang->word('delete').'</a><br/>' : NULL).'
			'.$lang->word('dl_choose_screenshot').':<br/>
			<input type="file" name="screen_4" /><br/>
		'.(file_exists(ROOT.'/files/downloads_screens/screen_5_'.$filei['server_name'].'.png') ?
			'<img src="/files/downloads_screens/screen_5_'.$filei['server_name'].'.png" weight="150" width="100" alt="Screen" /><br/>
			<a href="/downloads/attach_screen/'.$file_id.'?delete=5">'.$lang->word('delete').'</a><br/>' : NULL).'
			'.$lang->word('dl_choose_screenshot').':<br/>
			<input type="file" name="screen_5" /><br/>
		<input type="submit" value="'. $lang->word('save') .'" />
		</form>
	</div>';
$tpl->div('block', img('nav.png') . ' <a href="/downloads/file/'.$file_id.'">'. $lang->word('back') .'</a><br/>' 
				. img('download.png') . ' <a href="/downloads/">'. $lang->word('downloads') .'</a><br/>'
				. HICO .' <a href="/">'. $lang->word('home') .'</a>');
require_once(SYS.'/view/footer.php');
?>