<?php

if (!empty($_FILES['file']))
{

if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `wall_cache` WHERE `user_id` = '".$user_id."' LIMIT 1"),0) == false) mysql_query("INSERT INTO `wall_cache` SET `user_id` = '".$user_id."'");

$arr_wall_cache = mysql_fetch_array(mysql_query("SELECT * FROM `wall_cache` WHERE `user_id` = '".$user_id."' LIMIT 1"));
	
	if (!is_dir(HOME.'/files/wall/'.$user_id))
	{
		mkdir(HOME.'/files/wall/'.$user_id,0777);
		mkdir(HOME.'/files/wall/'.$user_id.'/photos',0777);
		mkdir(HOME.'/files/wall/'.$user_id.'/photos/icons',0777);
		mkdir(HOME.'/files/wall/'.$user_id.'/photos/mini',0777);
		mkdir(HOME.'/files/wall/'.$user_id.'/photos/preview',0777);
	}
	
if ($arr_wall_cache['count_photos'] < 10)
{
	require_once HOME.'/toolkit/AcImage.php';
	AcImage::setTransparency(true);
	if(AcImage::isFileExists($_FILES['file']['tmp_name'])) {} else {$err = true;}
	if($err == false && AcImage::isFileImage($_FILES['file']['tmp_name']))
	{
		$file_name = time().'.jpg';
		copy($_FILES['file']['tmp_name'], HOME.'/files/wall/'.$user_id.'/photos/'.$file_name);
		///
		$savePath = HOME.'/files/wall/'.$user_id.'/photos/icons/'.$file_name;
		$filePath = HOME.'/files/wall/'.$user_id.'/photos/'.$file_name;
		$image = AcImage::createImage($filePath);
		$image
		->cropCenter('4pr', '4pr')
		->resizeByWidth(50)
		->save($savePath);
		$savePath1 = HOME.'/files/wall/'.$user_id.'/photos/mini/'.$file_name;
		$filePath1 = HOME.'/files/wall/'.$user_id.'/photos/'.$file_name;
		$image1 = AcImage::createImage($filePath1);
		$image1
		->cropCenter('4pr', '4pr')
		->resizeByWidth(150)
		->save($savePath1);
		$savePath2 = HOME.'/files/wall/'.$user_id.'/photos/preview/'.$file_name;
		$filePath2 = HOME.'/files/wall/'.$user_id.'/photos/'.$file_name;
		$image2 = AcImage::createImage($filePath2);
		$image2
		->resizeByWidth(600)
		->resizeByHeight(400)
		->save($savePath2);
		
		mysql_query("UPDATE `wall_cache` SET `photos` = '".$arr_wall_cache['photos']."|".$file_name."|' , count_photos=count_photos+1 WHERE `user_id` = '".$user_id."' LIMIT 1");
		
		$q = explode("||", substr($arr_wall_cache['photos'], 1, -1));
		if ($ajax == 'yes') echo '<a id="'.time().'" class="del_cache" href="'.URL.'/wall/upload.php?del_photo='.$file_name.'" onclick="FormContent.DelCache(this.id,this.href); return false"><img class="preview_icons" src="'.URL.'/files/wall/'.$user_id.'/photos/icons/'.$file_name.'"/>';
	}
}
if ($ajax == 'yes') exit;
else go(URL.'/wall/upload.php?from='.$from);
}

?>