<?php
$showm = '6';
include ("config.php");
include('functions.php');
$action	= (int) $_GET['action'];
$page	= (int) $_GET['page'];

if(empty($page) || !is_numeric($page))
	$page = 1;

$limit = 20;	//	videos per page
$from = $page * $limit - ($limit);

$count=mysql_query("SELECT * from utilizatori");
$total_videos = mysql_num_rows($count);

if(!empty($_POST['submit']) && $_POST['submit'] == 'Cauta') 
{
	$search_query = secure_sql(trim($_POST['keywords']));
	$search_type = $_POST['search_type'];

	$videosx = a_list_usersx($search_query, $search_type, $from, $limit, $page);
	$total_videos = preg_match_all("/<\/tr>/", $videosx, $matches);
} 
else 
{
	if($total_videos - $from == 1)
		$page--;
	
	$videosx = a_list_usersx('', '', $from, $limit, $page); 		
	
	if($total_videos - $from == 1)
		$page++;	
}

// generate smart pagination
$filename = basename($_SERVER['PHP_SELF']);
$pagination = '';
if(!isset($_POST['submit'])) 
	$pagination = generate_smart_pagination($page, $total_videos, $limit, 5, $filename, '');
?>
<div id="sub_menu">
<li><a href="addvideo.php">Adauga melodie</a></li>
</div>
<div id="content">
<h2>Manager Utilizatori</h2>
<div id="more_v_details">

</div>
<br />
<?
if(!empty($action) && $action != 9) 
{
	echo "<div class=\"info_msg_err\">Userul a fost sters.</div>";
}

//	Batch Delete
if($_POST['Submit'] == 'Sterge users')
{
	$video_ids = array();
	$video_ids = $_POST['video_ids'];
	
	$total_ids = count($video_ids);
	if($total_ids > 0)
	{
		$in_arr = '';
		for($i = 0; $i < $total_ids; $i++)
		{
			$in_arr .= "'" . $video_ids[ $i ] . "', ";
		}
		$in_arr = substr($in_arr, 0, -2);
		if(strlen($in_arr) > 0)
		{
			$sql = "DELETE FROM utilizatori WHERE id IN (" . $in_arr . ")";
			$result = @mysql_query($sql);
			
			if(!$result)
				echo '<div class="info_msg_errimg">There was an error while updating your database.<br />MySQL returned: '.mysql_error().'</div>';
			else
			{				
				echo '<div class="info_msg_ok">Userul a fost sters.</div>';
			}
		}
	}
	else
		echo '<div class="info_msg_ok">Nu ai selectat nici o melodie!</div>';
	$videosx = a_list_usersx('', '', $from, $limit, $page); 
}

?>
<table width="100%" border="0" cellspacing="1" cellpadding="3">
  <tr>
    <td valign="top">
	<form name="search" action="users.php" method="post" onsubmit="return validateSearch('true');">
	<input type="text" name="keywords" value="<?=$_POST['keywords']?>" />
	<select name="search_type">
	  <option value="username" selected>Username</option>
	  <option value="ip">IP</option>
	</select>
	<input name="submit" type="submit" value="Cauta" class="inputbutton" /><br />
	<small>Please make the search as descriptive as possible.</small>
	</form>	</td>
    <td width="220" valign="top"><div class="totals">Numar Users : <?=$total_videos?> </div></td>
  </tr>

</table>
<form name="videos_checkboxes" action="users.php?page=<?php echo $page;?>" method="post">
 <table id="videosSortTable" class="tablesorter" cellspacing="1">
  <thead>
   <tr>
	<th align="center" width="10"><input type="checkbox" name="checkall" onclick="checkUncheckAll(this);"/></th>
    <td align="center" style="color: #FFFFFF; background: #333333"><strong>ID</strong></td>
    <td align="center" style="color: #FFFFFF; background: #333333"><strong>Username</strong></td>
    <td align="center" style="color: #FFFFFF; background: #333333"><strong>Rank</strong></td>
    <td align="center" style="color: #FFFFFF; background: #333333"><strong>Inregistrat la</strong></td>
    <td align="center" style="color: #FFFFFF; background: #333333"><strong>IP</strong></td>
    <td align="center" style="color: #FFFFFF; background: #333333"><strong>Actiuni</strong></td>
   </tr>
  </thead>
  <tbody>
	<?=$videosx?>
  </tbody>
 </table>
 <table>
    <tr style="background-color: #fff;">
	<td colspan="2" align="left"><input type="submit" name="Submit" value="Sterge users" class="deletebutton"></td>
   </tr>
 </table>

</form>
<div align="center"><?=$pagination?></div>
</div>

<?
include('footer.php');
?>
