View file portfolio/modules/portfolio/inc/edit_work.php

File size: 4.82Kb
<?php

  ###################################################
  #  Скрипт портфолио								      #
  #  Версия системы: 1.0							      #
  #  Автор: RonsoN								      #
  #  ICQ: 7-191-321									      #
  # Email: [email protected]					      #
  ###################################################

if (!isset($user)) { header('Location: /'); exit; }

$id_work = int($_GET['id_work']);

if ($db->query("SELECT * FROM `works` WHERE `id` = '". $id_work ."' LIMIT 1")->rowCount() == 0) {

	header('Location: /pages/404.xhtml');
	exit();

}
$system['page_title'] = 'Изменить работу';

require_once(HOME .'/system/header.php');


echo '<div class="menu">Изменить работу</div>';

	if(isset($_POST['edit'])) {

		$rand = rand(1111,9999);

		$title = txt($_POST['title']);
	    	if (empty($title)) $err .= 'Ошибка ! Не введено название работы<br />';

		$text = txt($_POST['text']);
		
		$cost = txt($_POST['cost']);
		
		$pre = txt($_POST['pre']);

		$id_category = txt($_POST['id_category']);
	    	if (empty($id_category)) $err .= 'Ошибка ! Не выбрана категория<br />';

		$status = txt($_POST['status']);
	    	if (empty($id_category)) $err .= 'Ошибка ! Не выбран статус<br />';

		
			if (is_uploaded_file($_FILES['scr']['tmp_name'])) {
			
				$exts = array('gif', 'png'); 
				$ext = pathinfo(strtolower($_FILES['scr']['name']), PATHINFO_EXTENSION);
				if (!in_array($ext, $exts) && !preg_match('/^(php|htaccess)$/i', $ext))  $err .='Недопустимое расширение скриншота!';
				$scr = 'scr_'.$rand.'.'.$ext.''; 
				
			} 

			if (is_uploaded_file($_FILES['file']['tmp_name'])) {
			
				$exts = array('zip', 'gif', 'png'); 
				$ext = pathinfo(strtolower($_FILES['file']['name']), PATHINFO_EXTENSION);
				if (!in_array($ext, $exts) && !preg_match('/^(php|htaccess)$/i', $ext))  $err .='Недопустимое расширение файла!'; 
				$file = $rand.'.'.$ext.''; 
				
				
				
		} 

			if (!isset($err)) {

				move_uploaded_file($_FILES['scr']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/files/screens/scr_'.$rand.'.'.$ext);
				move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/files/loads/'.$rand.'.'.$ext);
				$db->query("UPDATE `works` SET `title` = '".$title."', `text` = '". $text ."', `cost` = '".$cost."', `pre` = '".$pre."', `id_category` = '".$id_category."', `status` = '".$status."', `scr` = '". $scr ."', `file` = '". $file ."'  WHERE `id` =  '".$id_work."'");

				header('location: /panel/works.xhtml'); exit;

			}
	
	}

$work = $db->query("SELECT * FROM `works` WHERE `id` =  '".$id_work."'")->fetch();

$category_sql = $db->query("SELECT * FROM `category` ORDER BY `id` ASC");

while($cats = $category_sql->fetch()) {

	$category.= '<option value="'. $cats['id'] .'" '.($work['id_category'] == $cats['id'] ? 'selected="selected"':NULL).'>'. $cats['title'] .'</option>';
	
}

if(isset($err)) error($err);

echo '<div class="main">
		<form action="/portfolio/inc/edit_work/'.$id_work.'.xhtml" method="post" enctype="multipart/form-data">
			Название:<br/>
			<input name="title" value="'.$work['title'].'" type="text" /><br/>

			Описание:<br/>
			<textarea name="text" rows="5" cols="20">'.$work['text'].'</textarea><br/>

			Категория:<br/>
			<select name="id_category" size="1">
			'.$category.'
			</select><br/>
			
			Стоимость работы:<br/>
			<input name="cost" value="'.$work['cost'].'" size="10" type="text" />
			<select name="pre" size="1">
			<option value="WMR" '.($work['pre'] == 'WMR' ? 'selected="selected"':NULL).'>WMR</option>
			<option value="WMZ" '.($work['pre'] == 'WMZ' ? 'selected="selected"':NULL).'>WMZ</option>
			<option value="WMU" '.($work['pre'] == 'WMU' ? 'selected="selected"':NULL).'>WMU</option>
			</select>
			<br/>

			Статус работы:<br/>
			<select name="status" size="1">
			<option value="1" '.($work['status'] == '1' ? 'selected="selected"':NULL).'>На продажу</option>
			<option value="2" '.($work['status'] == '2' ? 'selected="selected"':NULL).'>На заказ</option>
			<option value="3" '.($work['status'] == '3' ? 'selected="selected"':NULL).'>Бесплатно</option>
			</select><br/>
			
			Скриншот:<br />
			<input type="file" name="scr" /><br />

			Файл (если работа бесплатная):<br />
			<input type="file" name="file" /><br />

			<input name="edit" type="submit" value="Изменить" /><br/>
		</form>
		</div>';


echo '<div class="navi">
'.NAVI.'<a href="/panel/category.xhtml">Категории</a><br/>
'.INDEX.'<a href="/">Главная</a>
</div>';

require_once(HOME.'/system/footer.php');

?>