<?php

if (!empty($_GET['del_photo']) && is_numeric($_GET['del_photo']))
{
	$del_photo = abs(intval($_GET['del_photo']));
	
	if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `photos_file` WHERE `id` = '".$del_photo."' AND `user_id` = '".$user_id."' LIMIT 1"),0) == true)
	{
		$arr = mysql_fetch_array(mysql_query("SELECT * FROM `photos_file` WHERE `id` = '".$del_photo."' AND `user_id` = '".$user_id."' LIMIT 1"));
		mysql_query("DELETE FROM `photos_file` WHERE `id` = '".$del_photo."'");
		mysql_query("DELETE FROM `photos_comm` WHERE `fid` = '".$del_photo."'");
		
		if (file_exists(HOME .'/files/photos/'. $user_id.'/'.$arr['name'])) {@unlink(HOME .'/files/photos/'. $user_id.'/'.$arr['name']);}
		if (file_exists(HOME .'/files/photos/'. $user_id.'/preview/'.$arr['name'])) {@unlink(HOME .'/files/photos/'. $user_id.'/preview/'.$arr['name']);}
		if (file_exists(HOME .'/files/photos/'. $user_id.'/mini/'.$arr['name'])) {@unlink(HOME .'/files/photos/'. $user_id.'/mini/'.$arr['name']);}
		if (file_exists(HOME .'/files/photos/'. $user_id.'/icons/'.$arr['name'])) {@unlink(HOME .'/files/photos/'. $user_id.'/icons/'.$arr['name']);}

		mysql_query("UPDATE `users` SET count_photos=count_photos-1 WHERE `id` = '".$user_id."'");
		if ($arr['name'] == $arr_album['cover']) $new_cover = mysql_fetch_array(mysql_query("SELECT * FROM `photos_file` WHERE `user_id` = '".$user_id."' AND `aid` = '".$arr_album['id']."' ORDER by `time` DESC LIMIT 1")); else $new_cover['name'] = $arr_album['cover'];
		mysql_query("UPDATE `photos_albums` SET count_photos=count_photos-1, `cover` = '".$new_cover['name']."' WHERE `id` = '".$arr['aid']."'");
	}
}


?>