<?
session_start();
require_once('../connect/connect.php');
include_once('../lib/lib.php');
require('pdk.php');
$base_path="../";


if($_POST['submit1'] )
{
	if($_POST['arr'])
	{
	$dops="";
	$i=0;

	foreach ($_POST['arr'] as $aa=>$ind)
		{
		if($i>0) $dops .= ",";
		$dops .= $aa;
		$i++;
		}
	$dops="id_akk IN (".$dops.")";
	mysql_query("UPDATE akk SET blok='1' WHERE ".$dops);  
	}
}

if($_POST['submit2'])
{
	if($_POST['arr'])
	{
	$dops="";
	$i=0;

	foreach ($_POST['arr'] as $aa=>$ind)
		{
		if(!$ind)
			{
			if($i>0) $dops .= ",";
			$dops .= $aa;
			$i++;
			}
		}
		
	if($dops)
		{
		mysql_query("UPDATE akk SET blok='2' WHERE id_akk IN (".$dops.")");  
		} 
	}
}



if($_POST['submit_ud'])
{
	if($_POST['arr'])
	{
	
	$dops="";
	$i=0;
	
	foreach ($_POST['arr'] as $ar=>$ind)
		{
		if($ar && !$abn[$ar] && !$ind)
			{
			if($i>0) $dops .= ",";
			$dops .= $ar;
			$i++;
			}
		}

	if($dops)
		{
		$dop_a="id_akk IN (".$dops.")";
		mysql_query ("DELETE FROM akk WHERE ".$dop_a) or die(mysql_error());
		}
	}
}

if (isset($_GET['sort']))
	{
	switch ($_GET['sort'])
  		{
		case "v1": $sort=" id_akk ASC"; $v1='<img border=0 src="../icon/s_asc.png">'; break;
		case "n1": $sort=" id_akk DESC"; $v1='<img border=0 src="../icon/s_desc.png" >'; break;
		case "n2": $sort=" blok DESC"; $v2='<img border=0 src="../icon/s_desc.png" >'; break;
		case "v2": $sort=" blok ASC"; $v2='<img border=0 src="../icon/s_asc.png" >'; break;
		case "v5": $sort=" email ASC"; $v5='<img border=0 src="../icon/s_asc.png" >'; break;
		case "n5": $sort=" email DESC"; $v5='<img border=0 src="../icon/s_desc.png" >'; break;
		case "v6": $sort=" summa ASC"; $v6='<img border=0 src="../icon/s_asc.png" >'; break;
		case "n6": $sort=" summa DESC"; $v6='<img border=0 src="../icon/s_desc.png" >'; break;
  		}
	$add="&sort=".$_GET['sort'];
	} 
else {$sort=" id_akk DESC"; $add="";}


$maxRows_Recordset1 = 20;
$pn = 0;
if (isset($_GET['pn'])) 
$pn = $_GET['pn'];

$startRow_Recordset1 = $pn * $maxRows_Recordset1;
$query_Recordset1 = "SELECT * FROM akk ORDER BY ".$sort."";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;


$titl="Пользователи";
require ('top.php'); 

if($_POST['submit4'] && $_POST['arr'])
	{
   	echo '<form name="form_ud" method="post" action="">
   	<font color="red">Вы действительно хотите удалить эти
   	аккаунты ?';
	foreach($_POST['arr'] as $aa=>$ars)
		{
		echo " - ".$aa;
    	echo '<input type="hidden" name=arr['.$aa.'] value="'.$ars.'">';
		}
   	echo '</font><br><input type="submit" name="submit_ud" value="Удалить">
   	</form>';
    }  
?>

<form name="form" method="post" action="">
   
<TABLE width="100%" style="BORDER-COLLAPSE: collapse" cellpadding="1" cellspacing="1" border="1" bordercolor="#E2E2E2">
	<tr align="center" valign="middle" >
	<td width="2%" scope="col"></td>
	
	<td width="8%" scope="col">
	<a class="style4" title="<? if ($_GET['sort']=="v1") echo "Отсортировать по убыванию"; else echo "Отсортировать по возрастанию"; ?>"
	href="<? if ($_GET['sort']=="v1") echo $currentPage."?sort=n1"; 
	else echo $currentPage."?sort=v1"; ?>" >Аккаунт</a> <? echo $v1; ?>
	</td>
	
	<td width="15%" scope="col">
	<a class="style4" title="<? if ($_GET['sort']=="v2") echo "Отсортировать по убыванию"; else echo "Отсортировать по возрастанию"; ?>"
	href="<? if ($_GET['sort']=="v2") echo $currentPage."?sort=n2"; 
	else echo $currentPage."?sort=v2"; ?>" >Статус</a> <? echo $v2; ?>	
	</td>
    
    <td width="15%" scope="col">
	<a class="style4" title="<? if ($_GET['sort']=="v6") echo "Отсортировать по убыванию"; else echo "Отсортировать по возрастанию"; ?>"
	href="<? if ($_GET['sort']=="v6") echo $currentPage."?sort=n6"; 
	else echo $currentPage."?sort=v6"; ?>" >Summa (<?=$rru['cena_valuta']?>)</a> <? echo $v6; ?>	
	</td>
	
	<td width="20%" scope="col">
	Контактное лицо
	</td>
	
    <td width="20%" scope="col">
	<a class="style4" title="<? if ($_GET['sort']=="v5") echo "Отсортировать по убыванию"; else echo "Отсортировать по возрастанию"; ?>"
	href="<? if ($_GET['sort']=="v5") echo $currentPage."?sort=n5"; 
	else echo $currentPage."?sort=v5"; ?>" >E-mail</a> <? echo $v5; ?>	
	</td>
	
    <td width="20%" scope="col">
	Пароль	
	</td>
   <?
///////////////// 
do 
	{
	if($row_Recordset1['id_akk']) 
		{
		if(!$i) $color_tr='bgcolor="#DDDDDD"'; else $color_tr='';
		echo '<tr '.$color_tr.'>';

		echo '<td>';
		echo '<input type="checkbox" name=arr['.$row_Recordset1['id_akk'].'] value="'.$row_Recordset1['summa'].'">';

		echo '<td>';
		echo $row_Recordset1['id_akk'];
		echo '<br><a href="akk_stat.php?id_akk='.$row_Recordset1['id_akk'].'" class="fancy_stat">Статистика</a>';

		echo '<td align=center >';
		switch ($row_Recordset1['blok'])
			{
			case 0: $u='<font color=gray><b>Н</b></font>'; break;
			case 1: $u='<font color=green><b>Р</b></font>'; break;
			case 2: $u='<font color=red><b>Б</b></font>'; break;
			}
		echo $u;

		echo '<td align=center>';
		if($row_Recordset1['summa'])
		echo '<font color=green>'.$row_Recordset1['summa'].'</font>';
		else echo '<font color=red>0</font>';
		echo '<td>';
		echo '<a title="Пополнить счет" href="aa.php?id_user='.$row_Recordset1['id_akk'].'"><font color=green size=+1>+</font></a> ';
		echo $row_Recordset1['contakt'];
		echo '<td>';
		echo '<a href="mailto:'.$row_Recordset1['email'].'">'.$row_Recordset1['email'].'</a>';
		if(!$i) $i=1; else $i=0;
		echo '<td>';
		echo $row_Recordset1['pass'];
		} 
	} while($row_Recordset1 = mysql_fetch_array($Recordset1));

   ?>

</TABLE>
<br>
<input class="submit" type="submit" name="submit1" value="Активировать">
<input class="submit" type="submit" name="submit2" value="Заблокировать">
<input class="submit" type="submit" name="submit4" value="Удалить">
<input type="hidden" name="MM_insert" value="form">
</form>
<p>
<? 
pages3(20, $totalPages_Recordset1, $pn, $add);
	
include_once('bottom.php'); ?>