File size: 3.78Kb
<?php
/**********************************************/
/* Автор скрипта: Александр Есин */
/* E-Mail: [email protected] ([email protected]) */
/* ICQ: 6464729 */
/* Site: http://ticlove.ru */
/**********************************************/
?>
<?php define ('SECURED', true); ?>
<?php require (dirname(__FILE__).'/../_inc/sql.php'); ?>
<?php require (dirname(__FILE__).'/../_inc/config.php'); ?>
<?php require (dirname(__FILE__).'/../_inc/function.php'); ?>
<?php
if (!empty($_SESSION['auth_id']) && (intval($_POST['user_id']) == $_SESSION['auth_id']))
{
$fid = intval($_POST['fid']);
$sql = mysql_query("SELECT * FROM `q_photo` WHERE `id_photo` = '".$fid."' LIMIT 1;");
$arr_photo = mysql_fetch_array($sql);
$name_photo = explode('.', $arr_photo['name']);
$page = isset($_GET['page']) ? $_GET['page'] : NULL;
switch($page)
{
case 'update':
$name_photo = str_replace($name_photo[0], $name_photo[0].'_s', $arr_photo['name']);
$sql = mysql_query("SELECT `avatar`, `photo` FROM `q_users` WHERE `id_user` = '".$_SESSION['auth_id']."' LIMIT 1;");
$u_arr = mysql_fetch_array($sql);
$avatar = $u_arr[0];
$all_photos = $u_arr[1];
if ($avatar == $name_photo) mysql_query("UPDATE `q_users` SET `avatar` = '' WHERE `id_user` = '".$_SESSION['auth_id']."';");
unlink('../'.DIR_PHOTOS.'/'.$_SESSION['auth_id'].'/'.$arr_photo['name']);
unlink('../'.DIR_PHOTOS.'/'.$_SESSION['auth_id'].'/'.str_replace('.', '_p.', $arr_photo['name']));
unlink('../'.DIR_PHOTOS.'/'.$_SESSION['auth_id'].'/'.str_replace('.', '_s.', $arr_photo['name']));
$all_photos = $all_photos - 1;
if ($all_photos == 0) rmdir('../'.DIR_PHOTOS.'/'.$_SESSION['auth_id']);
if (mysql_query("DELETE FROM `q_photo_comm` WHERE `id_foto` = '".$fid."' AND `uid_user` = '".$_SESSION['auth_id']."';")
&& mysql_query("DELETE FROM `q_photo_vote` WHERE `id_foto` = '".$fid."' AND `uid_user` = '".$_SESSION['auth_id']."';")
&& mysql_query("DELETE FROM `q_photo` WHERE `id_photo` = '".$fid."' AND `id_user` = '".$_SESSION['auth_id']."';")
&& mysql_query("UPDATE `q_users` SET `photo` = `photo` - '1' WHERE `id_user` = '".$_SESSION['auth_id']."';")) echo '<div>Фотография успешно удалена</div>';
break;
default:
$name_photo_p = str_replace($name_photo[0], $name_photo[0].'_p', $arr_photo['name']);
?>
<div class="box_bg" style="width: 340px;">
<div class="box_title">
<div class="left" style="padding-top: 2px; padding-left: 10px;">Удаление фото</div><div class="box_close right b-modal_close arcticmodal-close"></div>
</div>
<div class="clear"></div>
<div class="box_conetnt">
<div style="padding: 10px;">
<div id="photo_delete_status">
<div>Вы действительно хотите удалить эту фотографию?</div>
<div style="padding: 10px 0; text-align: center;">
<img class="photo_bor" src="<?php echo DIR_PHOTOS; ?>/<?php echo $arr_photo['id_user']; ?>/<?php echo $name_photo_p; ?>" alt="" />
</div>
<div style="padding-bottom: 10px; text-align: center;">
<input type="submit" class="submit" onclick="javascript:photo_delete_update('<?php echo $fid; ?>')" value="Удалить" />
</div>
</div>
</div>
</div>
<div class="box_footer">
<div class="right"><button class="submit_red b-modal_close arcticmodal-close">Отмена</button></div>
</div>
<div class="clear"></div>
</div>
<?php
break;
}
}
?>