<?php

define('_IN_JOHNCMS', 1);
require('../incfiles/core.php');
$lng_profile = core::load_lng('profile');

$al = isset($_REQUEST['al']) ? abs(intval($_REQUEST['al'])) : null;
$img = isset($_REQUEST['img']) ? abs(intval($_REQUEST['img'])) : null;

/*
-----------------------------------------------------------------
Переключаем режимы работы
-----------------------------------------------------------------
*/
$array = array(
'delete'         => 'includes/',
'edit'           => 'includes/',
'image_delete'   => 'includes/',
'image_download' => 'includes/',
'image_edit'     => 'includes/',
'image_move'     => 'includes/',
'moder'          => 'includes/',
'show'           => 'includes/',
'sort'           => 'includes/',
'top'            => 'includes/'
);
$path = !empty($array[$act]) ? $array[$act] . '/' : '';
if (array_key_exists($act, $array) && file_exists($path . $act . '.php')) {
require_once($path . $act . '.php');
} else {
require('../incfiles/head.php');

if ($rights == 9) {
echo '<div class="menu"><a href="moder.php">Admin panel</a></div>';
}
echo '<div class="menu"><a href="/"><img src="/ico/home.png"></a> » FOTO</div>';
echo '<div class="phdr"><center><b>Bo\'limlar</b></center></div>';
echo '<style>.catsTd a {color: #0D0F11;padding-left:22px; background:url(/ico/dir.png)no-repeat left center}</style>';
echo '<div class="menu"><table border="0" cellspacing="1" cellpadding="0" width="100%" class="catsTable">';
$req = mysql_query("SELECT * FROM `album_cat` WHERE `id` ORDER BY `sort` ASC");
while ($res = mysql_fetch_assoc($req)) {
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `album_files` WHERE `moder` = '0' AND `album_id` = '" . $res['id'] . "'"), 0);
$new = mysql_result(mysql_query("SELECT COUNT(*) FROM `album_files` WHERE `moder` = '0' AND `album_id` = '" . $res['id'] . "' AND `time` > '" . (time() - 259200) . "'"), 0);
echo '<tr><td style="width:100%" class="catsTd" valign="top" id="cid19"><a href="?act=show&al=' . $res['id'] . '">' . functions::checkout($res['name']) . '</a> <span class="catNumData" style="unicode-bidi:embed;">[' . $count . ' / <font color="red">+'.$new.'</font>]</span></td></tr>';
}

echo '</table></div>';
// fotoalbom
echo '<div class="phdr"><center><b>Yangi fotosuratlar</b></center></div>';
echo '<div class="menu" align="center"><p>';
$ichefan = mysql_query("SELECT `id`, `album_id`, `tmb_name` FROM `album_files` ORDER BY `time` DESC LIMIT 8");
$i=0;
while ($chefan = mysql_fetch_array($ichefan)) {
$i++;
echo $i % 2 ? '<div style="display: inline-block; position: relative;  top: 0px; margin-left: -10px;">' : '<div style="display: inline-block; position: relative;  top: 8px; margin-left: -10px;">';
echo ' <a href="?act=show&al=' . $chefan['album_id'] . '&img=' . $chefan['id'] . '&view"><img style="margin: 2px; border-radius: 15px; border: .14em solid #B9B4B4; width: 70px; height: 70px;" src="' . $set['homeurl'] . '/files/album/' . $chefan['tmb_name'] . '" alt="#" /></a>';
echo '</div>';
}
echo '</p></div>';

/*
-----------------------------------------------------------------
Выгрузка фотографии
-----------------------------------------------------------------
*/
require('../incfiles/lib/class.upload.php');
echo '<div class="phdr"><center><b>' . $lng_profile['upload_photo'] . '</b></center></div>';
if (isset($_POST['submit'])) {
$handle = new upload($_FILES['imagefile']);
if ($handle->uploaded) {
// Обрабатываем фото
$handle->image_watermark = '../images/watermark.png';
$handle->image_watermark_position = 'BR';
$handle->file_new_name_body = 'img_' . time();
$handle->allowed = array(
'image/jpeg',
'image/gif',
'image/png'
);
$handle->file_max_size = 1024 * $set['flsz'];
$handle->image_resize = true;
$handle->image_x = 1920;
$handle->image_y = 1024;
$handle->image_ratio_no_zoom_in = true;
$handle->image_convert = 'jpg';
$handle->process('../files/album/');
$img_name = $handle->file_dst_name;
if ($handle->processed) {
// Обрабатываем превьюшку
$handle->file_new_name_body = 'tmb_' . time();
$handle->image_resize = true;
$handle->image_x = 200;
$handle->image_y = 200;
$handle->image_ratio_no_zoom_in = true;
$handle->image_convert = 'jpg';
$handle->process('../files/album/');
$tmb_name = $handle->file_dst_name;
$cat_id = abs(intval($_POST['cat']));
if ($handle->processed) {
if ($rights = 9){
mysql_query("INSERT INTO `album_files` SET
`album_id` = '$cat_id',
`img_name` = '" . mysql_real_escape_string($img_name) . "',
`tmb_name` = '" . mysql_real_escape_string($tmb_name) . "',
`time` = '" . time() . "'
");



} else {
mysql_query("INSERT INTO `album_files` SET
`album_id` = '$cat_id',
`img_name` = '" . mysql_real_escape_string($img_name) . "',
`tmb_name` = '" . mysql_real_escape_string($tmb_name) . "',
`moder` = '1',
`time` = '" . time() . "'
");



}
echo '<div class="menu"><p><b>' . $lng_profile['photo_uploaded'] . '</b></p></div>';
} else {
echo functions::display_error($handle->error);
}
} else {
echo functions::display_error($handle->error);
}
$handle->clean();
}
} else {
echo '<form enctype="multipart/form-data" method="post" action="">' .
'<div class="menu"><p><select name="cat">';
$cats = mysql_query("SELECT * FROM `album_cat` WHERE `id` ORDER BY `sort` ASC");
while ($cat = mysql_fetch_assoc($cats)) {
echo '<option value="'.$cat['id'].'">' . functions::checkout($cat['name']) . '</option>';
}
echo '</select><br />'.
'<input type="file" name="imagefile" value="" /></p>' .
'<input type="hidden" name="MAX_FILE_SIZE" value="' . (1024 * $set['flsz']) . '" />' .
'<p><input type="submit" name="submit" value="' . $lng_profile['upload'] . '" /></p>' .
'</div></form>';
}


}
require('../incfiles/end.php');
?>
