<table border="0" callspacing="3" width="100%">
<tr>
<?
if($_GET['startat'] == "") {
$startat = 0;
} else {
$startat = $_GET['startat'];
}
if($_GET['perpage'] == "") {
$perpage = $setting->perpage;
} else {
$perpage = $_GET['perpage'];
}

if(!$match_type){
$match_type = "all";
}

$line = $startat;
$templine = 0;
$recordnum = 0;
$total_views = 0;
$count_total = 0;

$photocount=1;

$gallery_result = mysql_query("SELECT * FROM photo_galleries where pub_pri = '0'", $db);
$gallery_rows = mysql_num_rows($gallery_result);
while($gallery = mysql_fetch_object($gallery_result)){
$approved_cats[] = $gallery->id;
}

$approved_cats = implode(", ", $approved_cats);


# START SEARCH FUNCTIONALITY

$my_search = strtolower($my_search);


$my_search_words = split(" ",$my_search);
$words = count($my_search_words);

for($z = 0; $z < $words; $z++){
if(strlen($my_search_words[$z]) >= 1){
$my_search_words2 = $my_search_words2 . "," . strtolower($my_search_words[$z]);
//$my_search_words2 = "," . $my_search_words2;
}
}

$my_search_words2 = split(",",$my_search_words2);
$words2 = count($my_search_words2);


//echo $words2;
//exit;
//$my_search = "t";
if($match_type == "id"){
$searcher = "SELECT * FROM photo_package where active = '1' and gallery_id IN ($approved_cats) and id = '" . $_POST['search'] . "'";
}
if($match_type != "id"){
if($words2 < 2){
$searcher = "SELECT * FROM photo_package where active = '1' and gallery_id IN ($approved_cats) and keywords like '%$my_search%'";
} else {
$searcher = "SELECT * FROM photo_package where active = '1' and gallery_id IN ($approved_cats) and (";
for($z2 = 1; $z2 < $words2; $z2++){
$searcher.= " keywords like '%" . $my_search_words2[$z2] . "%'";
if($z2 < ($words2 - 1)){
if($match_type == "any"){
$searcher.= " or ";
}
if($match_type == "all"){
$searcher.= " and ";
}
}
}
if($words2 > 0){
$searcher.= " or";
}
for($z3 = 1; $z3 < $words2; $z3++){
$searcher.= " title like '%" . $my_search_words2[$z3] . "%'";
if($z3 < ($words2 - 1)){
if($match_type == "any"){
$searcher.= " or ";
}
if($match_type == "all"){
$searcher.= " and ";
}
}
}
}
//$searcher.= "keywords like '%$my_search%' ";
$searcher.= ") order by 'cart_count' desc LIMIT 350";
}
//echo $words2;
//echo "

";
//echo $searcher;
//exit;

//echo $searcher;
//exit;
$package_result = mysql_query($searcher, $db);
$package_rows = mysql_num_rows($package_result);

//echo "

" . $package_rows;
//exit;
while($package = mysql_fetch_object($package_result)){

$photo_result = mysql_query("SELECT * FROM uploaded_images where reference = 'photo_package' and reference_id = '$package->id'", $db);
$photo_rows = mysql_num_rows($photo_result);
$photo = mysql_fetch_object($photo_result);


if($templine < $perpage and $line < $package_rows) {
if($line == $recordnum) {
$line++;
$templine++;
?>
<?
if($photocount == 1){
?>
</tr><tr>
<?
} else {
?>

<?
}
?>
<td align="center" valign="middle" bgcolor="#F9F9F9" style="border: 1px solid #eeeeee; padding: 5px 0px 5px 0px;">
<? if($photo_rows > 0){ ?>[img]image.php?src=<? echo $photo->id; ?>[/img]<? } else { ?>[img]images/no_photo.gif[/img]<? } ?>



<font color="#A4A4A4">
<? if($photo_rows > 0){ ?>Dettagli foto<?php if($setting->dis_title_gallery == 1){ ?>
<? if($setting->dis_filename == 1){ echo $photo->filename; } else { echo $package->title; }?><? } ?><?php if($setting->show_views == "1"){ ?>
Vista: <? echo $package->code; ?><? } } else { ?>Dettagli foto<? } ?>
<!--|
<?
if($_SESSION['sub_member']){
?>
Download
<?
} else {
?>
Acquista
<?
}
?>
-->
</td>
<?
if($photocount == $setting->dis_columns){
//echo "<br style=\"clear: both;\">";
$photocount = 1;
} else {
$photocount++;
}
}
$count_total = $count_total + $fcontents;


}
$recordnum++;
}
if($package_rows > 0){
$result_pages = ceil($package_rows/$perpage);

if($_GET['page_num'] == ""){
$page_num = 1;
} else {
$page_num = $_GET['page_num'];
}

if($result_pages < 1){
$result_pages = 1;
}
?>
</tr>
<tr>
<td colspan="4">

<div name="result_details" id="result_details" style="padding-left: 10px;padding-right: 10px;padding-top: 30px;width: 100%; clear: both;">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
disponibili: <? echo $package_rows; ?> Fotografie (<? echo $result_pages; ?> Pagine)
</td>
<td align="right">
Pag.:

<?
$page_startat = 0;
for($page=1; $page <= $result_pages; $page++){
if($page == $page_num){
echo "[" . $page . "] ";
} else {
echo "<a href=\"search.php?search=" . $my_search . "&match_type=" . $match_type . "&gid=" . $_GET['gid'] . "&sgid=" . $_GET['sgid'] . "&startat=" . $page_startat . "&perpage=" . $perpage . "&page_num=" . $page . "\">" . $page . "</a> ";
}
$page_startat = $page_startat + $perpage;
}
?>
:
<?
if($startat == 0){
?>
<font color="#B0B0B0">Precedente</font>
<?
}
else{
if(($startat - $perpage) < 1) {
?>
">Previous
<?
} else {
?>
&perpage=<?php print($perpage) . "&page_num=" . ($page_num-1) . "&sort_by=" . $sort_by; ?>">Precedente
<?
}
}
?>
|
<?

if(($startat + $perpage) >= $package_rows){
?>
<font color="#B0B0B0">Seguente</font>
<?
}
else{
if($line < $package_rows) {
?>
&perpage=<?php print($perpage) . "&page_num=" . ($page_num+1) . "&sort_by=" . $sort_by; ?>">Next
<?
} else {
?>
&perpage=<?php print($perpage) . "&page_num=" . ($page_num+1) . "&sort_by=" . $sort_by; ?>">Next
<?
}
}
?>

</td>
</tr>
</table>
</div>
<?
}
if($_GET['sgid'] == ""){
$sub_gallery_result = mysql_query("SELECT * FROM photo_galleries where active = '1' and nest_under = '" . $_GET['gid'] . "' order by 'title'", $db);
$sub_gallery_rows = mysql_num_rows($sub_gallery_result);
if($sub_gallery_rows > 0){
echo "<hr size=\"1\" class=\"hr\"><span style=\"padding-left: 8px;\"><font color=\"#333333\">Sub Categories of " . $current_gallery_name . "</span>";
}
while($sub_gallery = mysql_fetch_object($sub_gallery_result)){
?>

<span style="padding-left: 8px;"><? echo $sub_gallery->title; ?></span>
<?
}
if($package_rows < 1 and $sub_gallery_rows < 1){
echo "<span style=\"padding-left: 8px;\">There were no photos found. Please try searching again.</span>";
}
}
?>
</td>
</tr>
</table>