<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: displayCategory.php,v 1.8.2.3 2004/04/18 20:15:21 ajvwaay Exp $




include ("$basepath/imageFunctions.php");
include ("$adminpath/fileFunctions.php");

function getThumbnail($img, $galloc)
{
    global $gallerypath, $imagepath, $mpnTables;
    $ext = substr($img, (strrpos($img,'.') +  1));
    $name_gif = str_replace(".$ext", ".gif", $img);
    $name_jpg = str_replace(".$ext", ".jpg", $img);
    $name_png = str_replace(".$ext", '.png', $img);

    if (file_exists("$gallerypath/$galloc/thumb/$name_gif"))
    {
        $thumb = "$gallerypath/$galloc/thumb/$name_gif";
    }
    elseif (file_exists("$gallerypath/$galloc/thumb/$name_jpg"))
    {
        $thumb = "$gallerypath/$galloc/thumb/$name_jpg";
    }
    elseif (file_exists("$gallerypath/$galloc/thumb/$name_png"))
    {
        $thumb = "$gallerypath/$galloc/thumb/$name_png";
    }
    else
    {
        $row = mysql_fetch_array(mysql_query("SELECT thumbnail from ".$mpnTables['gallery_media_types']." where extension='$ext'"));
    $thumbnail = $row['thumbnail'];
    $thumb = "$imagepath/$thumbnail";
    }

    return $thumb;
}


function displayPictureGall($filetype, $pid, $galloc, $name, $img, $orderby)
{
    global $module_name, $gallerypath, $baseurl, $adminpath, $imagepath, $thumbnailwidth, $imageSoftware;

    $image = "$gallerypath/$galloc/$img";
    $thumb_dir = "$gallerypath/$galloc/thumb";
    $thumb = "$thumb_dir/$img";

    // create the thumbnail if missing
    if (!file_exists($thumb))
    {
        if (!file_exists($thumb_dir))
    {
        makeDir("$gallerypath/$galloc", "thumb");
    }

        if ($filetype == 1)
        {
            $thumb = RatioResizeImg("$gallerypath/$galloc/$img", $thumb, $thumbnailwidth);
        }

        if ($thumb == 'browser')
        {
            $thumb = $image;
        }
        else
        {
            $thumb = getThumbnail($img, $galloc);
    }
    }

    return "<a class=\"meg-normal\" href=\"$baseurl&amp;do=showpic&amp;pid=$pid&amp;orderby=$orderby\">"
          ."<img src=\"$thumb\" width=\"$thumbnailwidth\" alt=\"".underscoreTospace($name)."\" border=\"0\">"
      .'</a>';
}


function displayDescriptionGall($row, $crow)
{
    global $textcolor1, $textcolor2;
    $m = 90 / $crow['numcol'];
    if (strlen($row['description']) > $m)
    {
        $row['description'] = trim(substr($row['description'],0,$m));
    $p = strrpos($row['description'], ' ');
    $row['description'] = trim(substr($row['description'],0,$p)).'...';
    }

    return "<font class=\"meg-sub\">" . $row['description'] . "</font>\n";
}


function displayNewGall($row)
{
    global $imagepath;
    if ($row['new_day'] == 0)
    {
        return "<img src=\"$imagepath/newred.gif\" border=\"0\" width=\"34\" height=\"14\" alt=\""._GALNEWMEDIA1.'">';
    }
    elseif($row['new_day'] < 3)
    {
        return "<img src=\"$imagepath/newgreen.gif\" border=\"0\" width=\"34\" height=\"14\" alt=\"".sprintf(_GALNEWMEDIA2, $row['new_day']).'">';
    }
    elseif($row['new_day'] < 7)
    {
        return "<img src=\"$imagepath/newblue.gif\" border=\"0\" width=\"34\" height=\"14\" alt=\"".sprintf(_GALNEWMEDIA2, $row['new_day']).'">';
    }
}


function displaySizeGall($row, $crow)
{
    global $module_name, $textcolor1, $textcolor2, $gallerypath;
    if ($row['imginfo'][2])
    {
        $size = $row['imginfo'];
    return "<font class=\"meg-sub\"><b>"._GALSIZE."</b>: $size[0]x$size[1]</font>";
    }
    else
    {
    return "<font class=\"meg-sub\"><b>"._GALSIZE."</b>: "._GALUNKNOWN."</font>";
    }
}


function displayFormatGall($row)
{
    global $module_name, $textcolor1, $textcolor2, $mpnTables;
    $ext = $row['imginfo'][2];
    switch ($ext)
    {
        case 1:
        $type = 'GIF';
        break;

    case 2:
        $type = 'JPEG';
        break;

        case 3:
        $type = 'PNG';
        break;

        case 4:
        $type = 'WBMP';
        break;

    default:
        $type = $ext;
        break;
    }

    return "<font class=\"meg-sub\"><b>Format</b>: $type</font>";
}


function displayNumCommentsGall($row)
{
    global $allowcomments, $textcolor2, $mpnTables;
    $numcomments = mysql_fetch_array(mysql_query("SELECT COUNT(cid) AS total FROM ".$mpnTables['gallery_comments']." WHERE pid=" . $row['pid']));
    if ($allowcomments)
    {
        return "<font class=\"meg-sub\"><b>"._GALNBCOMMENTS."</b>: " . $numcomments['total'] . "</font>";
    }
}


function displayHitsGall($row)
{
    global $module_name, $textcolor2;
    return "<font class=\"meg-normal\"><b>"._GALHITS."</b><br>" . $row['counter'] . "</font>";
}


function displayRateGall($row)
{
    global $allowrate, $textcolor2;
    if ($allowrate)
    {
        return "<font class=\"meg-normal\"><b>"._GALRATING."</b><br>" . $row['rate'] . "</font>";
    }
}


function displayDateAddedGall($row)
{
    global $textcolor2;
    return "<font class=\"meg-normal\"><b>"._GALADDED.'</b><br>'.strftime(_GALDATEBRIEF,$row['unix_date']).'</font>';
}


function displayName($row)
{
    global $textcolor2;
    return "<font class=\"meg-normal\"><b>" . $row['name'] . "</b></font>";
}


function navigationCat($gid, $offset, $orderby)
{
    global $maxNumberMedia, $module_name, $baseurl, $mpnTables;
    $limit = $maxNumberMedia;
    $orderby = convertorderbyout($orderby);
    $numresults = mysql_query("select * from ".$mpnTables['gallery_pictures']." where gid=$gid");
    $numrows=mysql_num_rows($numresults);
    $nav = '';
    $pages=intval($numrows/$limit);

    if ($numrows>0 & $pages>=1)
    {
        if ($offset!=0)
        {
            $prevoffset=$offset-$limit;
            $nav = "<a class=\"meg-normal\" href=\"$baseurl&amp;do=showgall&amp;gid=$gid&amp;offset=$prevoffset&amp;orderby=$orderby\">[&lt;&lt;]</a>&nbsp;.&nbsp;";
    }

        if ($numrows%$limit)
        {
            $pages++;
    }

        for ($i=1;$i<=$pages; $i++)
        {
            $newoffset=$limit*($i-1);
            if ($newoffset==$offset)
            {
                $nav .= "<font class=\"meg-normal\">";
            if ($i == 1)
                {
                    if ($pages==1)
                    {
                        $nav .= "[&lt;&lt;] . ".$i." . [&gt;&gt;]";
                    }
                    else
                    {
                         $nav .= "[&lt;&lt;] . ".$i."&nbsp;.&nbsp;";
                    }
                }
                elseif  ($i==$pages)
                {
                    $nav .= $i."&nbsp;.&nbsp;[&gt;&gt;]";
                }
                else
                {
                    $nav .= $i."&nbsp;.&nbsp;";
                }

                $nav .= "</font>";
            }
            else
            {
                $nav .= "<a class=\"meg-normal\" href=\"$baseurl&amp;do=showgall&amp;gid=$gid&amp;offset=$newoffset&amp;orderby=$orderby\">$i</a>&nbsp;.&nbsp;";
            }
        }

        if (!(($offset/$limit)==($pages-1)) && $pages!=1)
        {
            $newoffset = $offset+$limit;
            $nav .= "<a class=\"meg-normal\" href=\"$baseurl&amp;do=showgall&amp;gid=$gid&amp;offset=$newoffset&amp;orderby=$orderby\">[&gt;&gt;]</a>";
    }
    }

    return $nav;
}


function navigationSubCat($gid)
{
    global $module_name, $baseurl, $imagepath, $bgcolor1, $bgcolor2, $admin, $user, $adminurl, $mpnTables;
    if (is_admin($admin))
    {
        $result = mysql_query("SELECT gallid, gallname, visible, total, (TO_DAYS(NOW()) - TO_DAYS(lastadd)) AS new_day FROM ".$mpnTables['gallery_categories']." WHERE parent=$gid AND visible>=0");
    }
    else
    {
        $result = mysql_query("SELECT gallid, gallname, visible, total, (TO_DAYS(NOW()) - TO_DAYS(lastadd)) AS new_day FROM ".$mpnTables['gallery_categories']." WHERE parent=$gid AND visible>0");
    }

    $nb = mysql_num_rows($result);
    if (!$nb)
    {
        return false;
    }

    $c = 0;
    $out = '<table border="0" width="50%" align="center" cellpadding="2"><tr>';
    $pc = ceil(100/3);

    $isuser = is_user($user);
    $isadmin = is_admin($admin);
    while($row = mysql_fetch_array($result))
    {
        $vis='';
    if ($row['visible']==1 && !$isuser)
        {
            $vis = '(*)';
        }

        if ($isadmin)
        {
            switch ($row['visible'])
        {
                case 0:
        $vis .= "&nbsp;<a class=\"meg-normal\" href=\"$adminurl&amp;do=editcategory&amp;type=status&amp;visible=1&amp;category=".$row['gallid']."\" title=\""._GALVISIBLEADMIN."\"><img src=\"$imagepath/red_dot.gif\" border=\"0\" width=\"10\" height=\"10\" alt=\""._GALVISIBLEADMIN.'"></a>&nbsp;';
        break;

                case 1:
        $vis .= "&nbsp;<a class=\"meg-normal\" href=\"$adminurl&amp;do=editcategory&amp;type=status&amp;visible=2&amp;category=".$row['gallid']."\" title=\""._GALVISIBLEMEMBER."\"><img src=\"$imagepath/yellow_dot.gif\" border=\"0\" width=\"10\" height=\"10\" alt=\""._GALVISIBLEMEMBER.'"></a>&nbsp;';
        break;

                default:
        $vis .= "&nbsp;<a class=\"meg-normal\" href=\"$adminurl&amp;do=editcategory&amp;type=status&amp;visible=0&amp;category=".$row['gallid']."\" title=\""._GALVISIBLEPUBLIC."\"><img src=\"$imagepath/green_dot.gif\" border=\"0\" width=\"10\" height=\"10\" alt=\""._GALVISIBLEPUBLIC.'"></a>&nbsp;';
        break;
        }
    }

        $out .= "<td width=\"$pc%\">"
               ."<font class=\"meg-sub\"><img src=\"$imagepath/folder.gif\" width=\"15\" height=\"13\" border=\"0\" alt=\"\"> ";

        if ($row['visible']==1 && !$isuser && !$isadmin)
        {
            $out .= underscoreTospace($row['gallname'])." (" . $row['total'] . ") $vis";
        }
        else
        {
            $out .= "<a class=\"meg-normal\" href=\"$baseurl&amp;do=showgall&amp;gid=" . $row['gallid'] . "\">".underscoreTospace($row['gallname'])."</a> (" . $row['total'] . ")  $vis";
        }

        if ($row['new_day'] == 0)
        {
            $out .= "<img src=\"$imagepath/newred.gif\" border=\"0\" width=\"34\" height=\"14\" alt=\""._GALNEWMEDIA1.'">';
    }
    elseif($row['new_day'] < 3)
        {
            $out .= "<img src=\"$imagepath/newgreen.gif\" border=\"0\" width=\"34\" height=\"14\" alt=\"".sprintf(_GALNEWMEDIA2, $row['new_day']).'">';
    }
        elseif($row['new_day'] < 7)
        {
            $out .= "<img src=\"$imagepath/newblue.gif\" border=\"0\" width=\"34\" height=\"14\" alt=\"".sprintf(_GALNEWMEDIA2, $row['new_day']).'">';
    }

        $out .= "\n</font>\n</td>";
        $c++;
    if ($c == 3 && $nb != 3)
        {
            $out .= '</tr><tr>';
        $c = 0;
    }
    }

    $out .= '</tr></table>';
    return $out;
}


function convertorderbytrans($orderby)
{
    if ($orderby == "counter ASC") $orderbyTrans = ""._GALPOPULARITY1."";

    if ($orderby == "counter DESC") $orderbyTrans = ""._GALPOPULARITY2."";

    if ($orderby == "name ASC") $orderbyTrans = ""._GALNAMEAZ."";

    if ($orderby == "name DESC") $orderbyTrans = ""._GALNAMEZA."";

    if ($orderby == "date ASC") $orderbyTrans = ""._GALDATE1."";

    if ($orderby == "date DESC") $orderbyTrans = ""._GALDATE2."";

    if ($orderby == "rate ASC") $orderbyTrans = ""._GALRATING1."";

    if ($orderby == "rate DESC") $orderbyTrans = ""._GALRATING2."";

    return $orderbyTrans;
}


function search_split_query($q)
{
    $w = array();
    $qwords = explode(' ', $q);
    if (phpversion() >= '4.0.0')
    {
        foreach($qwords as $word)
        {
            $w[] = "%$word%";
    }
    }
    else
    {
        while(list($word) = each($qwords))
        {
            $w[] = "%$word%";
    }
    }

    return $w;
}


function search_go($vars)
{
    global $bgcolor1, $bgcolor2, $bgcolor3, $textcolor1, $textcolor2, $module_name, $baseurl, $gallerypath, $user, $admin, $mpnTables;
    $navgall = navigationGall();
    $w = search_split_query($vars['q']);
    $flag = false;

    if (is_admin($admin))
    {
        $query = "SELECT p.*, c.gallname, c.description AS galldesc, c.galloc, c.numcol, t.templateCategory, t.templateCSS, UNIX_TIMESTAMP(p.date) AS unix_date, (TO_DAYS(NOW()) - TO_DAYS(p.date)) AS new_day, f.displaytag, f.thumbnail, f.filetype, f.description AS description_media FROM ".$mpnTables['gallery_pictures']." AS p LEFT JOIN ".$mpnTables['gallery_categories']." AS c ON c.gallid=p.gid LEFT JOIN ".$mpnTables['gallery_template_types']." AS t ON t.id=c.template LEFT JOIN ".$mpnTables['gallery_media_types']." AS f ON f.extension=p.extension WHERE c.visible>=0 AND ";
    }
    elseif (is_user($user))
    {
        $query = "SELECT p.*, c.gallname, c.description AS galldesc, c.galloc, c.numcol, t.templateCategory, t.templateCSS, UNIX_TIMESTAMP(p.date) AS unix_date, (TO_DAYS(NOW()) - TO_DAYS(p.date)) AS new_day, f.displaytag, f.thumbnail, f.filetype, f.description AS description_media FROM ".$mpnTables['gallery_pictures']." AS p LEFT JOIN ".$mpnTables['gallery_categories']." AS c ON c.gallid=p.gid LEFT JOIN ".$mpnTables['gallery_template_types']." AS t ON t.id=c.template LEFT JOIN ".$mpnTables['gallery_media_types']." AS f ON f.extension=p.extension WHERE c.visible>=1 AND ";
    }
    else
    {
        $query = "SELECT p.*, c.gallname, c.description AS galldesc, c.galloc, c.numcol, t.templateCategory, t.templateCSS, UNIX_TIMESTAMP(p.date) AS unix_date, (TO_DAYS(NOW()) - TO_DAYS(p.date)) AS new_day, f.displaytag, f.thumbnail, f.filetype, f.description AS description_media FROM ".$mpnTables['gallery_pictures']." AS p LEFT JOIN ".$mpnTables['gallery_categories']." AS c ON c.gallid=p.gid LEFT JOIN ".$mpnTables['gallery_template_types']." AS t ON t.id=c.template LEFT JOIN ".$mpnTables['gallery_media_types']." AS f ON f.extension=p.extension WHERE c.visible>=2 AND ";
    }

    foreach ($w as $word)
    {
        if ($flag)
        {
            switch ($vars['bool'])
            {
                case 'AND' :
        $query .= ' AND ';
        break;

                case 'OR' :
        default :
        $query .= ' OR ';
        break;
            }
        }

        $query .= '(';
    if ($vars['search_picname'])
        {
            $query .= "p.name LIKE '$word' OR ";
    }

        if ($vars['search_picdesc'])
        {
            $query .= "p.description LIKE '$word' OR ";
    }

        if ($vars['search_catname'])
        {
            $query .= "c.gallname LIKE '$word' OR ";
        }

        if ($vars['search_catdesc'])
        {
            $query .= "c.description LIKE '$word' OR ";
        }

        $query .= '0)'; // little bit of filler to reduce code requirements :-)
    $flag = true;
    }

    $query .= ' ORDER BY c.gallname ASC, p.name ASC';
    $result = mysql_query($query);
    $total_rows = mysql_num_rows($result);
    include 'header.php';
    OpenTable();
    print '<table border="0" width="100%" align="center" cellpadding="0"><tr><td>';
    print '<table border="0" width="100%"><tr><td>'.$navgall.'</td></tr></table>';
    if ($total_rows)
    {
        $col = 1;

        print '<table border="0" width="100%"><tr>';

    $curGal = null;

    while($row = mysql_fetch_array($result))
        {
            if ($row['gid'] != $curGal)
            {
                if ($col <= 2)
                {
                    while($col <= 2)
                    {
                        print '<td>&nbsp;</td>';
            $col++;
            }
                }

                print "<tr bgcolor=\"$bgcolor2\"><td colspan=\"2\" align=\"center\"><font color=\"$textcolor1\">".underscoreTospace($row['gallname'])."</font></td></tr><tr>\n";
        $curGal = $row['gid'];
        $col = 1;
        }

            if ($col > 2)
            {
                print '</tr><tr>';
        $col = 1;
        }

        if (!isset($orderby))
        {
            $orderby = null;
        }

            $template = $row['templateCategory'];
            $template = str_replace(':IMG:', displayPictureGall($row['filetype'], $row['pid'], $row['galloc'], $row['name'], $row['img'], convertorderbyout($orderby)), $template);

        // get some image info stuff out of the way here
            //echo $row[extension];
            if ($row['filetype'] == 1)
            {
                $row['imginfo'] = @getimagesize("$gallerypath/" . $row['galloc'] . "/" . $row['img']);
            }
        else
            {
                $row['imginfo'] = false;
        $row['imginfo'][0] = $row['width'];
        $row[imginfo][1] = $row['height'];
        $row[imginfo][2] = $row['description_media'];
        $row[imginfo][3] = "width=\"" . $row['width'] . "\" height=\"" . $row['height'] . "\"";
        }

            // ok, back to what we were doing
            $val_description = displayDescriptionGall($row, $row);
        $val_rate = displayRateGall($row);
        $val_format = displayFormatGall($row);
        $val_size = displaySizeGall($row, $row);
        $val_nmbComments = displayNumCommentsGall($row);
        $val_new = displayNewGall($row);
        $val_hits = displayHitsGall($row);
        $val_date = displayDateAddedGall($row);
        $val_name = displayName($row);
        $template = str_replace(':DESCRIP:', $val_description, $template);
        $template = str_replace(':RATE:', $val_rate, $template);
        $template = str_replace(':FMAT:', $val_format, $template);
        $template = str_replace(':SIZE:', $val_size, $template);
        $template = str_replace(':NBCOMM:', $val_nmbComments, $template);
        $template = str_replace(':NEW:', $val_new, $template);
        $template = str_replace(':HITS:', $val_hits, $template);
        $template = str_replace(':DATE:', $val_date, $template);
        $template = str_replace(':NAME:', $val_name, $template);
        print "<td>$template</td>\n";
        $col++;
    }

        if ($col <= 2)
        {
            while($col <= 2)
            {
                print '<td>&nbsp;</td>';
        $col++;
        }
        }

        print '</tr></table>';
    }
    else
    {
        print '<p align="center">'._GALNOTHINGMATCHSEARCH.'</p>';
    }

    print search_form($vars);
    print '</td></tr></table>';
    CloseTable();
    include 'footer.php';
}


function showgall($gid, $orderby)
{
    global $textcolor1, $textcolor2, $filetypes, $adminpath, $defaultsortmedia, $mpnTables, $phpEx, $offset;
    include "$adminpath/config.$phpEx";

    $res = mysql_fetch_array(mysql_query("SELECT count(*) as total FROM ".$mpnTables['gallery_categories']." WHERE parent=$gid AND visible=1"));
    $crow = mysql_fetch_array(mysql_query("SELECT c.galloc, c.numcol, c.description, t.templateCategory, t.templateCSS FROM ".$mpnTables['gallery_categories']." AS c LEFT JOIN ".$mpnTables['gallery_template_types']." AS t ON t.id=c.template WHERE gallid=$gid"));

    // Start Of Output
    galleryHeader();
    OpenTable();
    if (isset($orderby))
    {
        $orderby = convertorderbyin($orderby);
    }
    else
    {
        $orderby = convertorderbyin($defaultsortmedia);
    }

    if (!$gid)
    {
        $_SERVER['F_LIB'] -> redirectRequest( $baseurl );

        exit;
    }

    $limit = $maxNumberMedia;

    if (empty($offset))
    {
        $offset = 0;
    }

    $orderbyTrans = convertorderbytrans($orderby);
    $navtree = navigationTree($gid, false);
    $nav =  navigationCat($gid, $offset, $orderby);
    $subcats = navigationSubCat($gid);
    $navgall = navigationGall();
    $result = mysql_query("SELECT m.*, UNIX_TIMESTAMP(m.date) AS unix_date, (TO_DAYS(NOW()) - TO_DAYS(m.date)) AS new_day, f.displaytag, f.thumbnail, f.filetype, f.description AS description_media FROM ".$mpnTables['gallery_pictures']." AS m LEFT JOIN ".$mpnTables['gallery_media_types']." AS f ON f.extension=m.extension WHERE gid=$gid ORDER BY $orderby LIMIT $offset,$limit");
    $nb = mysql_num_rows($result);
    $pc = ceil(100/$crow['numcol']);
    $c = 0;

    print '<table border="0" width="100%" align="center" cellpadding="0"><tr><td>';
    print '<table border="0" width="100%" align="center" cellpadding="2">'
         .'<tr><td>'.$navgall.'</td></tr>'
     .'<tr><td>'.$navtree.'</td></tr>'
     .'</table>'
     .'</td></tr>';

    if ($subcats != -1)
    {
        print "<tr><td align=\"center\">$subcats<hr>";
    }
    else
    {
        print '<tr><td align="center">';
    }

    print "<center><font class=\"meg-normal\">" . $crow['description'] . "</font></center><br>\n";
    if ($displaysortbar)
    {
        print '<font class="meg-sub">'._GALSORTMEDIABY.': '
          ._NAME." (<a class=\"meg-sub\" href=\"$baseurl&amp;do=showgall&amp;gid=$gid&amp;orderby=titleA\">"._GALASC."</a>\<a href=\"$baseurl&amp;do=showgall&amp;gid=$gid&amp;orderby=titleD\">"._GALDESC.'</a>) '
          ._DATE." (<a class=\"meg-sub\" href=\"$baseurl&amp;do=showgall&amp;gid=$gid&amp;orderby=dateA\">"._GALASC."</a>\<a href=\"$baseurl&amp;do=showgall&amp;gid=$gid&amp;orderby=dateD\">"._GALDESC.'</a>) '
          ._RATING." (<a class=\"meg-sub\" href=\"$baseurl&amp;&amp;do=showgall&amp;gid=$gid&amp;orderby=ratingA\">"._GALASC."</a>\<a href=\"$baseurl&amp;do=showgall&amp;gid=$gid&amp;orderby=ratingD\">"._GALDESC.'</a>) '
          ._POPULARITY." (<a class=\"meg-sub\" href=\"$baseurl&amp;do=showgall&amp;gid=$gid&amp;orderby=hitsA\">"._GALASC."</a>\<a href=\"$baseurl&amp;do=showgall&amp;gid=$gid&amp;orderby=hitsD\">"._GALDESC.'</a>) '
          .'<br>'._GALMEDIASORTED.": $orderbyTrans</font><br>";
    }

    print '</td></tr>';
    print '<tr><td align="center">'.$nav.'</td></tr>'
         .'<tr><td>'
     .'<table border="0" width="100%" align="center" cellpadding="2"><tr>';

    while($row = mysql_fetch_array($result))
    {
        $template = $crow['templateCategory'];
        $template = str_replace(':IMG:', displayPictureGall($row['filetype'], $row['pid'], $crow['galloc'], $row['name'], $row['img'], convertorderbyout($orderby)), $template);

    // get some image info stuff out of the way here
    if ($row['filetype'] == 1)
        {
            $row['imginfo'] = @getimagesize("$gallerypath/" . $crow['galloc'] . "/" . $row['img']);
    }
    else
        {
            $row['imginfo'] = false;
        $row['imginfo'][0] = $row['width'];
        $row['imginfo'][1] = $row['height'];
        $row['imginfo'][2] = $row['description_media'];
        $row['imginfo'][3] = "width=\"" . $row['width'] . "\" height=\"" . $row['height'] . "\"";
    }

        // ok, back to what we were doing
    $val_description = displayDescriptionGall($row, $crow);
    $val_rate = displayRateGall($row);
    $val_format = displayFormatGall($row);
    $val_size = displaySizeGall($row, $crow);
    $val_nmbComments = displayNumCommentsGall($row);
    $val_new = displayNewGall($row);
    $val_hits = displayHitsGall($row);
    $val_date = displayDateAddedGall($row);
    $val_name = displayName($row);
    $template = str_replace(':DESCRIP:', $val_description, $template);
    $template = str_replace(':RATE:', $val_rate, $template);
    $template = str_replace(':FMAT:', $val_format, $template);
    $template = str_replace(':SIZE:', $val_size, $template);
    $template = str_replace(':NBCOMM:', $val_nmbComments, $template);
    $template = str_replace(':NEW:', $val_new, $template);
    $template = str_replace(':HITS:', $val_hits, $template);
    $template = str_replace(':DATE:', $val_date, $template);
    $template = str_replace(':NAME:', $val_name, $template);

    print '<td width="'.$pc.'%">'.$template.'</td>';
    $c++;
    if ($c == $crow['numcol'] && $nb != $crow['numcol'])
        {
            print '</tr><tr>';
        $c = 0;
    }
    }

    print '</tr></table>'
     ."<center><br>$nav<br>"
     .search_form($GLOBALS['HTTP_POST_VARS']).'</center>';

    if ($res['total']>0 && !is_user($user))
    {
        print '<br><center><font class="meg-sub"><i>'._GALCATMEMBERS.'</i></font></center>';
    }

    print '</td></tr></table>';
    CloseTable();
    print '<p align="right">'
     .'<font class="meg-sub">'
     .sprintf(_GALCOPYRIGHT, _GALVERSION, "$baseurl/credits.php")
     .'</font>'
     .'</p>';

    mysql_free_result($result);
    include 'footer.php';
}

?>
