Просмотр файла mpanel/xstatus.php

Размер файла: 6.36Kb
<?php

require_once ('../includes/start.php');
require_once ('../includes/functions.php');
require_once ('../includes/header.php');
include_once ('../themes/header.php');

if (isset($_GET['act'])) {
	$act = check($_GET['act']);
} else {
	$act = 'index';
} 
if (isset($_GET['start'])) {
	$start = abs(intval($_GET['start']));
} else {
	$start = 0;
} 
if (isset($_GET['id'])) {
	$id = abs(intval($_GET['id']));
} else {
	$id = 0;
} 

if (is_admin()) {
	show_title('site.png', 'Управление x-статусами');
	$config['newtitle'] = 'Управление x-статусами';

	switch ($act):

		case 'index':
			$total = DB::run() -> querySingle("SELECT count(*) FROM `x-status`;");
			if ($total > 0) {
				if ($start >= $total) {
					$start = 0;
				} 
			echo '<a href="#down"><img src="../images/img/downs.gif" alt="image" /></a> ';
			$kolvo = 10; // по сколько статусов выводить на страницу
				$querystatus = DB::run() -> query("SELECT * FROM `x-status` ORDER BY id DESC LIMIT ".$start.", ".$kolvo.";");
				echo '<form action="xstatus.php?act=del&amp;start='.$start.'&amp;uid='.$_SESSION['token'].'&amp;'.SID.'" method="post">';
				while ($data = $querystatus -> fetch()) {
					echo '<div class="b">';
					echo '<div class="img"><img src="../images/xstatus/'.$data['image'].'" alt="x-status"></div>';
					echo $data['title'];
					echo '<span class="imgright"><input type="checkbox" name="del[]" value="'.$data['id'].'" /></span>';
					echo '</div>';
				}
				echo '<span class="imgright"><input type="submit" value="Удалить выбранное" /></span></form>';
				page_strnavigation('xstatus.php?', $kolvo, $start, $total);
			} else {
				echo '<img src="../images/img/error.gif" alt="Ошибка" />Статусы еще не добавлены. <a href="xstatus.php?act=add">Добавьте первый статус</a><br/>';
			}
			
			
			echo '<div class="form"><form action="xstatus.php?act=add" method="post">
			Название статуса:
			<br><input type="text" name="title">
			<input type="submit" value="Добавить">
			</form>
			</div><br/>';
		break;

		case 'add':
			if (isset($_POST['title'])) $title = check($_POST['title']);
				else $title = '';
			echo '
				<div class="form">
				<form action="xstatus.php?act=getadd&amp;'.SID.'" method="post" enctype="multipart/form-data">
				Название статуса: <input type="text" name="title" value="'.$title.'"><br>
				Картинка:<br>
				<input type="file" name="img"><br> 
				<input type="submit" value="Добавить"><br>
				</form>
				</div>
				
			';
			
			

			echo '<img src="../images/img/back.gif" alt="image" /> <a href="xstatus.php?'.SID.'">Вернуться</a><br />';
		break;
		

		case 'getadd':
			$title = check($_POST['title']);
			
				if (is_uploaded_file($_FILES['img']['tmp_name'])) {
					if (utf_strlen($title) >= 1 && utf_strlen($title) <= 50) {
							$ext = strtolower(substr(strrchr($_FILES['img']['name'], '.'), 1));

							if ($ext == 'jpg' || $ext == 'jpeg' || $ext == 'gif' || $ext == 'png') {
									echo $title;
									DB::run() -> query("INSERT INTO `x-status` (`image`,`title`) VALUES (?,?);", array('',$title));
									$lastid = DB::run() -> lastInsertId();
								
									DB::run() -> query("UPDATE `x-status` SET `image`=? WHERE `id`=?;", array($lastid.'.'.$ext, $lastid));
								
									include_once (BASEDIR.'includes/upload.php');

									$handle = new upload($_FILES['img']);

									if ($handle -> uploaded) {
										$handle -> file_new_name_body = $lastid;
										$handle -> image_resize = false;
										$handle -> image_ratio = false;
										$handle -> image_ratio_no_zoom_in = false;
										$handle -> file_overwrite = true;

													$handle -> process(BASEDIR.'images/xstatus/');
													if ($handle -> processed) {
														$handle -> clean();
														$_SESSION['note'] = 'Статус успешно добавлен';
														redirect("xstatus.php?".SID);
													} else {
														show_error('Ошибка! '.$handle -> error);
													} 
												} else {
													show_error('Ошибка! Не удалось загрузить изображение!');
												} 
											
							} else {
								show_error('Ошибка! Недопустимое расширение (Разрешено jpg, jpeg, gif и png)!');
							} 
						
					} else {
						show_error('Слишком длинное или короткое название (Необходимо от 1 до 50 символов)!');
					} 
				} else {
					show_error('Ошибка! Не удалось загрузить изображение!');
				} 
			
		break;
		
	
		
		case 'del':

			$uid = check($_GET['uid']);
			if (isset($_POST['del'])) {
				$del = intar($_POST['del']);
			} else {
				$del = 0;
			} 

			if ($uid == $_SESSION['token']) {
				if (!empty($del)) {
					$del = implode(',', $del);

					DB::run() -> query("DELETE FROM `x-status` WHERE id IN (".$del.");");
				
					$delimg = explode(',',$del);
					$count = count($delimg);
					for ($i = 0; $i < $count; $i++) {
						if (file_exists('../images/xstatus/'.$delimg[$i].'.png')) {
							unlink('../images/xstatus/'.$delimg[$i].'.png');
						}
						if (file_exists('../images/xstatus/'.$delimg[$i].'.jpg')) {
							unlink('../images/xstatus/'.$delimg[$i].'.jpg');
						}
						if (file_exists('../images/xstatus/'.$delimg[$i].'.jpeg')) {
							unlink('../images/xstatus/'.$delimg[$i].'.jpeg');
						}
						if (file_exists('../images/xstatus/'.$delimg[$i].'.gif')) {
							unlink('../images/xstatus/'.$delimg[$i].'.gif');
						}
					}
				
					$_SESSION['note'] = 'Статусы успешно удалены';
					redirect("xstatus.php?start=$start&".SID);
				} else {
					show_error('Отсутствуют выбранные статусы');
				} 
			} else {
				show_error('Ошибка! Неверный идентификатор сессии, повторите действие!');
			} 

			echo '<img src="../images/img/back.gif" alt="image" /> <a href="xstatus.php?start='.$start.'&amp;'.SID.'">Вернуться</a><br />';
		break;

	default:
		redirect("xstatus.php?".SID);
	endswitch;

	echo '<img src="../images/img/panel.gif" alt="image" /> <a href="index.php?'.SID.'">В админку</a><br />';

} else {
	redirect(BASEDIR.'index.php?'.SID);
} 

include_once ('../themes/footer.php');
?>