<?php
session_start();
set_time_limit(6000*60); // lengthening the script execution time
if(!isset($_SESSION['admin']) OR $_SESSION['admin'] == 0) {
header("location:login.php");
}
include('../include/config.php');
include('../include/database.php');
include('inc/functions.php');
if (isset($_POST['action'])) {
$action = mysql_real_escape_string($_POST['action']); 
} else {
$action = '';
}
// ajax sort slider items by drag and drop 
if ($action == "sort_slider"){
	$records = $_POST['records'];
	$counter = 1;
	foreach ($records as $record) {
		$query = "UPDATE slider SET slider_order='$counter' WHERE slider_id='$record'";
		mysql_query($query) or die('Error, insert query failed');
		$counter = $counter + 1;	
	}
}

// ajax reset avatar image
if ($action == "delete_avatar"){
	$select = mysql_query("SELECT * FROM setting WHERE id='1' LIMIT 1");
	$row = mysql_fetch_array($select);
	@unlink('../uploads/avatar/'.$row['avatar_image']);
	$delete = mysql_query("UPDATE setting SET avatar_image='' WHERE id='1'");
	if ($delete) {
	echo 1;
	}
}

// ajax reset banner image
if ($action == "delete_banner"){
	$select = mysql_query("SELECT * FROM setting WHERE id='1' LIMIT 1");
	$row = mysql_fetch_array($select);
	@unlink('../uploads/avatar/'.$row['banner_image']);
	$delete = mysql_query("UPDATE setting SET banner_image='' WHERE id='1'");
	if ($delete) {
	echo 1;
	}
}
?>
