<?php
//filter by gallery categories
$filter = explode("filter=", $_SERVER['REQUEST_URI']);
$filter = (int)$filter[1];
//go to first gallery if there is only one, but only if gallery setting is yes
$show_gallery_cats_onload = settings('show_gallery_cats_onload');
if($filter == 0 && $show_gallery_cats_onload['show_gallery_cats_onload'] == 'n')
{
$q = $mysql->query("ID", $mysql->perfix."gallery_cats", "password = '' ORDER BY `order` LIMIT 1");
$check = $mysql->num_rows($q);
if($check == 1)
{
$filter = $mysql->get_array($q);
$filter = ((int)$filter['ID'] > 0) ? $filter['ID'] : 0;
}
}
//if filter isnt set, show categories
if($filter == 0)
{
$catquery = $mysql->query("ID,name,password", $mysql->perfix."gallery_cats", "1 ORDER BY `order`");
while($cats = $mysql->get_array($catquery))
{
//first image from the category
$img = $mysql->get_array($mysql->query("thumb", $mysql->perfix."gallery", "cat = {$cats['ID']} ORDER BY `order` ASC LIMIT 1"));
//if the category is password protected and user hasn't logged in, show the lock image
if(!empty($cats['password']))
{
if(!isset($_COOKIE['gallery'.$filter]))
{
$img['thumb'] = 'lock.jpg';
}
}
//image table
$img = '<a href="'.$temp[0].'?filter='.$cats['ID'].'"><img src="/inc/gallery/images/clear.gif" style="background-image: url(\'/inc/gallery/thumbs/'.$img['thumb'].'\')" border="0" alt="'.stripslashes($cats['name']).'" /></a>';
$array['images'] .= '<table border="0" cellspacing="0" cellpadding="0"><tr><th>'.$img.'</th><tr><td>'.stripslashes($cats['name']).'</td></tr></table>';
}
}
//cat links
if($filter > 0)
{
$catquery = $mysql->query("ID,name", $mysql->perfix."gallery_cats", "1 ORDER BY `order`");
if($mysql->num_rows($catquery) <= 10)
{
$array['images'] = '<a name="gall"></a><p>Gallery categories: ';
while($cats = $mysql->get_array($catquery))
{
$temp = explode("?", $_SERVER['REQUEST_URI']);
$array['images'] .= '<a href="'.$temp[0].'?filter='.$cats['ID'].'#gall">'.stripslashes($cats['name']).'</a>|';
}
$array['images'] = substr($array['images'], 0, -1);
$array['images'] .= '</p>';
}
else
{
$array['images'] = '<a name="gall"></a><p>Gallery Categories: <select name="j" onchange="window.location=this.value;">';
while($cats = $mysql->get_array($catquery))
{
$temp = explode("?", $_SERVER['REQUEST_URI']);
$selected = ($filter == $cats['ID']) ? ' selected' : '';
$array['images'] .= '<option value="'.$temp[0].'?filter='.$cats['ID'].'#gall"'.$selected.'>'.stripslashes($cats['name']).'</option>';
}
$array['images'] .= '</select></p>';
}
//pics
$query = $mysql->query("ID,caption,thumb,large", $mysql->perfix."gallery", "cat = $filter ORDER BY `order` ASC");
while($data1 = $mysql->get_array($query))
{
$protected = $mysql->get_array($mysql->query("password", $mysql->perfix."gallery_cats", "ID = $filter LIMIT 1"));
if(!empty($protected['password']))
{
if(isset($_COOKIE['gallery'.$filter]))
{
$img = '<a href="javascript:Zoom(\'/inc/gallery/large/'.stripslashes($data1['large']).'\');"><img src="/inc/gallery/images/clear.gif" style="background-image: url(\'/inc/gallery/thumbs/'.stripslashes($data1['thumb']).'\')" border="0" alt="'.stripslashes($data1['caption']).'" /></a>';
}
else
{
$img = '<a href="javascript:;" onclick="window.open(\'/inc/gallery/login.php?cat='.$filter.'\',\'\',\'status=yes,scrollbars=yes,resizable=yes,width=400,height=150\');">
<img src="/inc/gallery/images/clear.gif" style="background-image: url(\'/inc/gallery/thumbs/lock.jpg\')" border="0" alt="'.stripslashes($data1['caption']).'" /></a>';
}
$array['images'] .= '<table border="0" cellspacing="0" cellpadding="0"><tr><th>'.$img.'</th><tr><td>'.stripslashes($data1['caption']).'</td></tr></table>';
}
else
{
$array['images'] .= '<table border="0" cellspacing="0" cellpadding="0"><tr><th><a href="javascript:Zoom(\'/inc/gallery/large/'.stripslashes($data1['large']).'\');"><img src="/inc/gallery/images/clear.gif" style="background-image: url(\'/inc/gallery/thumbs/'.stripslashes($data1['thumb']).'\')" border="0" alt="'.stripslashes($data1['caption']).'" /></a></th><tr><td>'.stripslashes($data1['caption']).'</td></tr></table>';
}
}
}
if($gobalFilter)
{
echo $html.'<div id="gallery">'.$array['images'].'</div>';
}
else
{
$mainhtml .= $html.'<div id="gallery">'.$array['images'].'</div>';
}
//place css and js in the head
$code = '<script type="text/javascript">function Zoom(sPicURL){window.open("/inc/gallery/large/pop.htm?"+sPicURL, "", "resizable=1,HEIGHT=400,WIDTH=600");}</script>';
$mainhtml = str_replace("</head>", $code.'</head>', $mainhtml);
//include this add-ons's overwrite css file from the template being used, if there is one
$t = settings('template');
if(file_exists('templates/'.$t['template'].'/addons/gallery_basic.css'))
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="/templates/'.$t['template'].'/addons/gallery_basic.css" /></head>', $mainhtml);
}
else
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="//www.freesites.com.au/addons/gallery_basic.css" /></head>', $mainhtml);
}
//end
?>