View file apanel/pages/moder_photo.php

File size: 6.41Kb
<?php
/**********************************************/
/* Автор скрипта: Александр Есин              */
/* E-Mail: [email protected] ([email protected]) */
/* ICQ: 6464729                               */
/* Site: http://ticlove.ru                    */
/**********************************************/
?>
<?php if (!defined('SECURED')) die("SORRY! Unknown Error!"); ?>
<?php
if (!isset($_SESSION['page_photos'])) $_SESSION['page_photos'] = 10;
if (isset($_POST['act_photos']))
{
     $page_photos = intval($_POST['page_photos']);
     if ($page_photos < 5 or $page_photos > 30) $page_photos = 10;
     $_SESSION['page_photos'] = $page_photos;
}

if (isset($_POST['action']))
{
     if (isset($_POST['update']))
     {
          $count = count($_POST['sel']);
          if ($count > 0) {
	  for ($i = 0; $i < $count; $i++) {
               $photo_id = intval($_POST['sel'][$i]);
               mysql_query("UPDATE `q_photo` SET `moder` = '1' WHERE `id_photo` = '".$photo_id."';");
          }
          echo '<div style="padding-bottom: 25px; text-align: center; color: #009900;">Одобрено фотографий: <strong>'.$count.'</strong></div>';
          } else echo '<div style="padding-bottom: 25px; text-align: center; color: #ff0000;">Вы не отметили фотографии для одобрения</div>';
     }
     
     
     if (isset($_POST['delete']))
     {
          $count = count($_POST['sel']);
          if ($count > 0) {
	  for ($i = 0; $i < $count; $i++) {
               $photo_id = intval($_POST['sel'][$i]);
               
               $sql = mysql_query("SELECT * FROM `q_photo` WHERE `id_photo` = '".$photo_id."' LIMIT 1;");
               if (mysql_num_rows($sql) > 0) {
	       $arr_photo = mysql_fetch_array($sql);
               
               $name_photo = explode('.', $arr_photo['name']);
               $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` = '".$arr_photo['id_user']."' 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` = '".$arr_photo['id_user']."';");
	       
	       unlink('../'.DIR_PHOTOS.'/'.$arr_photo['id_user'].'/'.$arr_photo['name']);
	       unlink('../'.DIR_PHOTOS.'/'.$arr_photo['id_user'].'/'.str_replace('.', '_p.', $arr_photo['name']));
	       unlink('../'.DIR_PHOTOS.'/'.$arr_photo['id_user'].'/'.str_replace('.', '_s.', $arr_photo['name']));
	       
	       $all_photos = $all_photos - 1;
	       if ($all_photos == 0) rmdir('../'.DIR_PHOTOS.'/'.$arr_photo['id_user']);
               
               mysql_query("DELETE FROM `q_photo_comm` WHERE `id_foto` = '".$photo_id."' AND `uid_user` = '".$arr_photo['id_user']."';");
	       mysql_query("DELETE FROM `q_photo_vote` WHERE `id_foto` = '".$photo_id."' AND `uid_user` = '".$arr_photo['id_user']."';");
	       mysql_query("DELETE FROM `q_photo` WHERE `id_photo` = '".$photo_id."' AND `id_user` = '".$arr_photo['id_user']."';");
	       mysql_query("UPDATE `q_users` SET `photo` = `photo` - '1' WHERE `id_user` = '".$arr_photo['id_user']."';");
	       }
          }
          echo '<div style="padding-bottom: 25px; text-align: center; color: #009900;">Удалено фотографий: <strong>'.$count.'</strong></div>';
          } else echo '<div style="padding-bottom: 25px; text-align: center; color: #ff0000;">Вы не отметили фотографии для удаления</div>';
     }
}
?>
<h3>Одобрить фотографии</h3>
<?php
$col = $_SESSION['page_photos'];
if (isset($_GET['start'])) $start = abs(intval($_GET['start']));
else $start = 0;
$count_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `q_photo` WHERE `moder` = '0';"), 0);
if ($count_p > 0) {
if ($start >= $count_p) $start = 0;
$q = mysql_query("SELECT * FROM `q_photo` WHERE `moder` = '0' ORDER BY `id_photo` DESC LIMIT ".$start.", ".$col);
?>
<div style="padding: 5px 0;">
Для одобрения фотографий пометьте их галочкой и нажмите кнопку "Одобрить"
</div>
<div style="padding: 5px 0;">
Всего фото для одобрения: <strong><?php echo $count_p; ?></strong>
</div>
<div style="padding: 10px 0;">
<form action="apanel.php?page=moder_photo" method="post">
<input type="hidden" name="act_photos" value="1" />
Сколько фото выводить на странице:
<select class="select" name="page_photos">
<?php for ($i = 0; $i < 6; $i++) {
$arr = array('5', '10', '15', '20', '25', '30');
echo '<option value="'.$arr[$i].'" '.($_SESSION['page_photos'] == $arr[$i] ? 'selected="selected"' : '').'>'.$arr[$i].'</option>';
}
?>
</select>
<input class="submit_green" type="submit" value="Применить" />
</form>
</div>
<form action="apanel.php?page=moder_photo" method="post">
<input type="hidden" name="action" value="1" />
<table cellspacing="1" cellpadding="0">
<tr>
<td width="50" class="td_users"></td>
<td width="120" class="td_users">Фотографии</td>
<td width="500" class="td_users">Описание</td>
</tr>
<?php $i = 1; ?>
<?php while ($array = mysql_fetch_array($q)) { ?>
<?php
if ($i == 1) $bg_td = 'td_users_cont_w';
else { $bg_td = 'td_users_cont_t'; $i = 0; }
?>
<tr>
<td class="<?php echo $bg_td; ?>"><input type="checkbox" name="sel[]" value="<?php echo $array['id_photo']; ?>" /></td>
<td class="<?php echo $bg_td; ?>"><img src="../<?php echo DIR_PHOTOS; ?>/<?php echo $array['id_user']; ?>/<?php echo str_replace('.', '_p.', $array['name']); ?>" alt="" width="110" height="146" /></td>
<td class="<?php echo $bg_td; ?>"><?php echo (!empty($array['about']) ? htmlspecialchars($array['about'], ENT_QUOTES) : '-'); ?></td>
</tr>
<?php $i++; ?>
<?php } ?>
</table>
<?php function_page($_SERVER['PHP_SELF'].'?page=moder_photo&amp;', $col, $start, $count_p); ?>
<div style="padding-top: 10px;">
<input class="submit" type="submit" name="update" value="Одобрить" /> <input class="submit_red" type="submit" name="delete" value="Удалить отмеченные" />
</div>
</form>
<?php } else { ?>
<div style="padding-top: 10px; font-size: 16px; text-align : center;">Нет фотографий для одобрения!</div>
<?php } ?>