Просмотр файла admin/sites.php

Размер файла: 6.25Kb
<?php
require_once('includes/db.php');
require_once('includes/config.php');
require_once('includes/auth.php');

require_once('includes/header.php');

// функция удаления файла
function delete($file)
{
   chmod($file,0777);
   if (is_dir($file))
   {
      $handle = opendir($file);
      while($filename = readdir($handle))
      {
         if ($filename != "." && $filename != "..")
         {
            delete($file."/".$filename);
         }
      }
      closedir($handle);
      rmdir($file);
   }
   else
   {
      unlink($file);
   }
}

if(isset($_POST['delete']))
{
   if(isset($_POST['check']))
   {
      foreach($_POST['check'] as $id => $value)
      {
         if($value == 1)
         {
            $categories = mysql_query('SELECT login FROM users WHERE id = "' . $id . '"');
            list($login) = mysql_fetch_array($categories);
            mysql_query('DELETE FROM users WHERE id = "' . $id . '"');
            mysql_query('DELETE FROM guest_book WHERE user_id = "' . $id . '"');
            mysql_query('DELETE FROM links WHERE user_id = "' . $id . '"');
            mysql_query('DELETE FROM news WHERE user_id = "' . $id . '"');

            $questions = mysql_query('SELECT id FROM polls_questions WHERE user_id = "' . $id . '"');
            while($question = mysql_fetch_array($questions, MYSQL_ASSOC))
            {
               mysql_query('DELETE FROM polls_answers WHERE qid = "' . $question['id'] . '"');
            }
            mysql_query('DELETE FROM polls_questions WHERE user_id = "' . $id . '"');

            if($login != '')
               delete('../' . $login);

            // deleting sub-domain
            file('https://' . $cpanel_login . ':' . $cpanel_pass . '@' . $cpanel_server . ':2083/frontend/rucp/subdomain/dodeldomain.html?domain=' . $login . '_' . $server_name);
         }
      }
   }
}
?>
<table align="center" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="addbg"><td align="center" background="images/t5.gif"><font color="#FFFFFF"></font>
        <font class="header">
         Сайты
        </font></td>
</tr></table>

<div align="center">
&nbsp;
</div>
<?php
   if(!isset($_GET['page']))
      $page = 1;
   else
      $page = $_GET['page'];
?>
&nbsp;Сортировать по <a href="sites.php?sort=0&page=<?php echo $page; ?>">ID</a>, <a href="sites.php?sort=1&page=<?php echo $page; ?>">посещениям</a>, <a href="sites.php?sort=2&page=<?php echo $page; ?>">блокировке</a>
<br>
<form action="" method="post">
&nbsp;Поиск <input type="text" name="search" value=""> по <select name="search_by"><option value="id">ID</option><option value="login">логину</option></select>
<input type="submit" name="submit" value="OK">
</form>

<table width="99%" align="center" border="0" cellspacing="1" cellpadding="5" class="listtable">
<tr class="tablehead" align="center">
<td><b>ID</td>
<td><b>Домен</td>
<td><b>Имя</td>
<td><b>Фамилия</td>
<td><b>e-mail</td>
<td><b>Баннер</td>
<td><b>Посещения</td>
<td><b>Блокирован</td>
<td colspan="2"><b>Действия</td>
<form action="" method="post">
</tr>

<?php

$max_sites = 50;

if(!isset($_POST['search']) || (isset($_POST['search']) && $_POST['search'] == ''))
{
   $categories = mysql_query('SELECT count(*) as count FROM users');
   list($num_sites) = mysql_fetch_array($categories);
   $n_pages = ceil($num_sites / $max_sites); // число страниц
   echo '&nbsp;';
   for($i = 1; $i <= $n_pages; $i++)
   {
      echo "<a href=\"sites.php?page=$i\">$i</a> ";
   }
   echo '<br>';
   echo '<br>';

   if(isset($_GET['page']))
   {
      $limit = ' LIMIT ' . ($_GET['page'] - 1) * $max_sites . ', ' . $max_sites;
   }
   else
   {
      $limit = ' LIMIT 0, ' . $max_sites;
   }
}

if(!isset($_GET['sort']))
   $sort = 0;
else
   $sort = $_GET['sort'];

switch($sort)
{
   case 0: $sort_by = 'u.id'; break;
   case 1: $sort_by = 'total DESC'; break;
   case 2: $sort_by = 'u.active'; break;
   default: $sort_by = 'u.id';
}

//$categories = mysql_query('SELECT u.id as id, login, name, surname, email, banner, today, total FROM users u LEFT JOIN counter c ON u.id = c.id ORDER BY ' . $sort_by . ' ' . $limit);
if(isset($_POST['search']) && $_POST['search'] != '')
{
   if($_POST['search_by'] == 'login')
      $categories = mysql_query('SELECT u.id as id, active, block_date, login, name, surname, email, banner, today, total FROM users u, counter c WHERE u.login = "' . $_POST['search'] . '" AND u.id = c.id');
   else
      $categories = mysql_query('SELECT u.id as id, active, block_date, login, name, surname, email, banner, today, total FROM users u, counter c WHERE u.id = "' . (int)$_POST['search'] . '" AND u.id = c.id');
}
else
{
   $categories = mysql_query('SELECT u.id as id, active, block_date, login, name, surname, email, banner, today, total FROM users u, counter c WHERE u.id = c.id ORDER BY ' . $sort_by . $limit);
}

echo mysql_error();
$i = 1;
while($category = mysql_fetch_array($categories, MYSQL_ASSOC))
{
   $i = ($i == 1) ? 2 : 1;
   switch($category['banner'])
   {
      case 'top': $banner = 'Вверху'; break;
      case 'bottom': $banner = 'Внизу'; break;
      case 'none': $banner = 'Нет'; break;
   }
   if($category['active'] == 0)
   {
      $blocked = $category['block_date'];
   }
   else
   {
      $blocked = 'нет';
   }
   echo '
<tr class="bg' . $i . '">
<td align="center">' . $category['id'] . '</td>
<td align="left"><a href="editsite.php?id=' . $category['id'] . '" title="' . EDIT . '">' . $category['login'] . '</a></td>
<td align="left">' . $category['name'] . '</td>
<td align="left">' . $category['surname'] . '</td>
<td align="center">' . $category['email'] . '</td>
<td align="center">' . $banner . '</td>
<td align="center">' . (int)$category['total'] . '</td>
<td align="center">' . $blocked . '</td>
<td align="center"><a href="editsite.php?id=' . $category['id'] . '" title="Ред.">Ред.</a></td>
<td align="center"><input type="checkbox" name="check[' . $category['id'] . ']" value="1"></td>
</tr>
';
}

?>

<tr class="tablehead">
<td colspan="10" align="right"><input type="submit" name="delete" value="<?php echo DELETE; ?>" onclick="javascript:return Submit();"></td>
</tr>
</form>
</table>

<?php
require_once('includes/footer.php');
?>