<?php
/*
copyright: copyright 2004 Php Image Host. All Rights Reserved. You may modify this file for use on your
					site running a licenced copy of the Php Image Host scripts.
					You must not distribute this file or derivations of it.
Nullified By CrAcKlOvE
*/

require_once(dirname(__FILE__).'/includes/config.inc.php');
require_once(dirname(__FILE__).'/../classes/images.class.php');
$images =& new images($ace);

$pagesizes = array(10, 25, 50, 100, 250, 500, 1000);

$message = '';
$errors = array();
$criteria = array();

$ids = isset($_POST['ids']) ? $ace->getids($_POST['ids']) : array();
if( count($ids) > 0 ){
	if( $ace->getstr('delete', $_POST) != '' ){
		$delimages = $ace->getint('deleteimages', $_POST);
		$message .= $images->deletegalleries($ids, $delimages)." galleries ".($delimages ? 'and all images in them ' : '')."deleted.";
	}
}

$perpage = $ace->getint('perpage', $_REQUEST, 10);

$name = $ace->getstr('name', $_REQUEST);
$username = $ace->getstr('username', $_REQUEST);

$orderby = $ace->getstr('orderby', $_REQUEST);
$orderdir = $ace->getstr('orderdir', $_REQUEST);

if( $username != '' ) $criteria['username'] = $username;
if( $name != '' ) $criteria['name'] = $name;

$criteria['count'] = true;

$numgalleries = $images->getgalleries($criteria);

$numpages = ceil($numgalleries / $perpage);

$page = $ace->getint('page', $_REQUEST, 1);
if( $page < 1 ) $page = 1;
if( $page > $numpages ) $page =$numpages;

$first = ($page-1) * $perpage;
$last = min($numgalleries,(($page) * $perpage));

$criteria['count'] = false;

if( $numgalleries > 0 ){
	$gals = $images->getgalleries($criteria, $orderby, $orderdir, $first, $perpage);
}

$pageurl = $_SERVER['SCRIPT_NAME']."?name=$name&username=$username&perpage=$perpage&page={page}&orderby=$orderby&orderdir=$orderdir";

require_once(dirname(__FILE__).'/includes/header.inc.php');

?>
<div style="text-align: center;">
<b>Manage Galleries</b><br /><br />
This page lets you view and delete the galleries created by your users. 
Use the form on the left to filter
which galleries are displayed.
<br /><br />
<table border="0" cellspacing="0" cellpadding="10" width="95%">
<tr>
<td style="text-align: center; vertical-align: top; width: 150px; color: #555555; font-weight: bold;">
<div style="padding: 5px; border: 2px solid #555555; ">
<div style="border-bottom: 2px solid #555555; font-weight: bold;text-align: center;padding: 3px;margin-bottom: 5px;">Search Images</div>
<a href="<?php echo $_SERVER['SCRIPT_NAME'];?>">List All Galleries</a>
<br /><br />
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="get">
Gallery Name Like<br />
<input type="text" name="name" value="<?php echo htmlspecialchars($name);?>" />
<br />(Use * as wildcard)
<br /><br />Username<br />
<input type="text" name="username" value="<?php echo htmlspecialchars($username);?>" />
<br />Use * as wildcard.
<br /><br />Order By<br />
<select name="orderby">
	<option value="url">URL</option>
	<option value="name"<?php if( $orderby =='name' ) echo ' SELECTED ';?></option>
	<option value="username"<?php if( $orderby =='username' ) echo ' SELECTED ';?></option>
</select>
<br />
<select name="orderdir">
	<option value="asc">ascending</option>
	<option value="desc"<?php if( $orderdir == 'desc' ) echo ' SELECTED ';?>>descending</option>
</select>
<br /><br />Display<br />
<input style="width: 40px;" type="text" name="perpage" value="<?php echo $perpage;?>" />
<br />Per Page
<br /><br /><input type="submit" value="List Galleries" />
</form>
</div>
</td>
<td style="text-align: center; vertical-align: top;">

<div class="errors">
<?php if( $message != '' ) echo $message."<br /><br />";?>
<?php if( count($errors) > 0 ) echo join("<br />", $errors)."<br /><br />";?>
<?php echo $numgalleries;?> galleries matched your criteria.
</div>
<?php
if( $numgalleries > 0 ){
?>
Listing galleries <?php echo ($first+1).' to '.$last.' of '.$numgalleries.'.';?><br /><br />
Page <?php echo $page.' of '.$numpages.'.';?><br /><br />
View Page:
<?php
	for( $i = 1; $i <= $numpages; $i++){
?>
<a href="<?php echo str_replace('{page}', $i,$pageurl);?>"><?php echo $i;?></a>
<?php
	}
?>
<br /><br />
<form name="iform" id="iform" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
<input type="hidden" name="name" value="<?php echo htmlspecialchars($name);?>" />
<input type="hidden" name="username" value="<?php echo htmlspecialchars($username);?>" />
<input type="hidden" name="perpage" value="<?php echo $perpage;?>" />
<input type="hidden" name="orderby" value="<?php echo $orderby;?>" />
<input type="hidden" name="orderdir" value="<?php echo $orderdir;?>" />
<table class="formtable" cellspacing="1" cellpadding="0" border="0" align="center" style="background-color: #555555; width: 95%;">
<tr>
	<th>&nbsp;</th>
	<th>Gallery</th>
	<th>Username</th>
	<th>Images</th>
	<th>URL</th>
</tr>
<?php
	$tr = 0;
	foreach( $gals as $i ){
?>
<tr class="tr<?php echo ($tr+1);?>">
	<td style="width: 24px; text-align: center;">
		<input type="checkbox" name="ids[]" value="<?php echo $i->gallery_id;?>" />
	</td>
	<td><a target="_blank" href="../gallery.php?u=<?php echo $i->username;?>&g=<?php echo $i->gallery_name;?>"><?php echo $i->gallery_name;?></a></td>
	<td style="text-align: center;">
		<a href="<?php echo $_SERVER['SCRIPT_NAME'];?>?username=<?php echo htmlspecialchars($i->username);?>&perpage=<?php echo $perpage;?>"><?php echo $i->username;?></a>
		[<a href="users.php?userid=<?php echo $i->user_id;?>">View</a>]
	</td>
	<td><a href="images.php?checked=-1&username=<?php echo $i->username;?>&gallery=<?php echo $i->gallery_name;?>"><?php echo $i->images;?></a></td>
	<td><input type="text" class="gurlinput" value="<?php echo htmlspecialchars($ace->config->siteurl.'gallery.php?u='.$i->username.'&g='.$i->gallery_name);?>" onFocus="this.select();" /></td>
</tr>
<?php
		$tr = 1 - $tr;
	}
?>
</table>
<br clear="all" />
<input type="button" onClick="check(this.form,true);" value="Select All" />
<input type="button" onClick="check(this.form,false);" value="Select None" />
<input type="button" onClick="invert(this.form);" value="Invert Selection" />
<noscript>
<br />The buttons above require javascript to be enabled in order to function.
</noscript>
<br /><br />
<input type="submit" name="delete" value="Delete Selected Galleries" onClick="return confirm('Are you sure you want to delete all the selected galleries?');" />
<br /><input type="checkbox" name="deleteimages" value="1" /> and delete all the images in the galleries.
</form>
<br />
View Page:
<?php
	for( $i = 1; $i <= $numpages; $i++){
?>
<a href="<?php echo str_replace('{page}', $i,$pageurl);?>"><?php echo $i;?></a>
<?php
	}
?>
<br /><br />
Page <?php echo $page.' of '.$numpages.'.';?><br /><br />
Listing galleries <?php echo ($first+1).' to '.$last.' of '.$numgalleries.'.';?>
<?php
}
?>
</td>
</tr>
</table>
</div>
<?php


require_once(dirname(__FILE__).'/includes/footer.inc.php');

?>
