<?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: mainGallery.php,v 1.5.2.2 2004/04/18 12:47:18 ajvwaay Exp $




function displayIconCat($row)
{
    global $modulepath, $admin, $user, $baseurl;
    $imgsize = @getimagesize("$modulepath/gallery/" . $row['galloc'] . "/" . $row['gallimg']);
    if ($row['visible'] == 1)
    {
        if (is_admin($admin) || is_user($user))
        {
            return "<a href=\"$baseurl&amp;do=showgall&amp;gid=" . $row['gallid'] . "\">"
          ."<img src=\"$modulepath/gallery/" . $row['galloc'] . "/" . $row['gallimg'] . "\" alt=\"" . $row['gallname'] . "\" $imgsize[3] border=\"0\"></a>"
          .'</a>';
        }
        else
        {
            return "<img src=\"$modulepath/gallery/" . $row['galloc'] . "/" . $row['gallimg'] . "\" alt=\"" . $row['gallname'] . "\" $imgsize[3] border=\"0\">";
        }
    }
    else
    {
        return "<a href=\"$baseurl&amp;do=showgall&amp;gid=" . $row['gallid'] . "\">"
          ."<img src=\"$modulepath/gallery/" . $row['galloc'] . "/" . $row['gallimg'] . "\" alt=\"" . $row['gallname'] . "\" $imgsize[3] border=\"0\"></a>"
          .'</a>';
    }
}


function displayDescriptionCat($row)
{
    return "<font class=\"meg-normal\">".nl2br($row['description']).'</font>';
}


function displayCatName($row)
{
    global $imagepath, $baseurl, $textcolor1, $textcolor2, $admin, $user, $adminurl;
    if ($row['visible']==1 && !is_user($user))
    {
        $vis = '<font class=\"meg-sub\">(*)</font>';
    }
    else
    {
        $vis = null;
    }

    if (is_admin($admin))
    {
        switch ($row['visible'])
    {
        case 0:
        $vis .= "&nbsp;<a class=\"meg-title\" 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-title\" 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-title\" 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;
        }
    }

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

    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']).'">';
    }

    return $out;
}


function navigationSubCat($row)
{
    global $module_name, $baseurl, $bgcolor1, $bgcolor2, $admin, $mpnTables;
    if (is_admin($admin))
    {
        $result = mysql_query("SELECT gallid, gallname FROM ".$mpnTables['gallery_categories']." WHERE parent=" . $row['gallid'] . " AND visible>=0");
    }
    else
    {
        $result = mysql_query("SELECT gallid, gallname FROM ".$mpnTables['gallery_categories']." WHERE parent=" . $row['gallid'] . " AND visible>0");
    }

    if (!mysql_num_rows($result))
    {
        return;
    }

    $c = false;
    $out = '<table border="0" cellpadding="0" cellspacing="0">'
      .'<tr><td>';

    while($row = mysql_fetch_array($result))
    {
        if ($c)
        {
            $out.= ', ';
    }

        $out .= "<a class=\"meg-title\" href=$baseurl&do=showgall&gid=" . $row['gallid'] . ">" . $row['gallname'] . "</a>";
    $c = true;;
    }

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


function viewcats()
{
    global $textcolor1, $textcolor2, $adminpath, $admin, $user, $maintemplate, $modulepath, $mpnTables, $HTTP_POST_VARS;
    include "$adminpath/config.php";
    $trow = mysql_fetch_array(mysql_query("SELECT templateCategory, templateCSS FROM ".$mpnTables['gallery_template_types']." WHERE id=$maintemplate"));

    if (is_admin($admin))
    {
        $galresult = mysql_query("SELECT *, (TO_DAYS(NOW()) - TO_DAYS(lastadd)) AS new_day FROM ".$mpnTables['gallery_categories']." WHERE parent=-1 AND visible>=0 ORDER BY gallname");
    }
    else
    {
        $galresult = mysql_query("SELECT *, (TO_DAYS(NOW()) - TO_DAYS(lastadd)) AS new_day FROM ".$mpnTables['gallery_categories']." WHERE parent=-1 AND visible>0 ORDER BY gallname");
    }

    $res = mysql_fetch_array(mysql_query("SELECT count(*) as total FROM ".$mpnTables['gallery_categories']." WHERE parent=-1 AND visible=1"));

    $nb = mysql_numrows($galresult);
    if ($nb >= $numColMain)
    {
        $pc = 100/$numColMain;
    }
    else
    {
        if ($nb > 0)
        {
            $pc = 100/$nb;
        $numColMain = $nb;
    }
    else
        {
            $pc = 100;
        $numColMain = 1;
    }
    }

    // Start Of Output
    galleryHeader();
    OpenTable();
    print '<br>'.navigationGall().'<br><table border="0" width="100%" align="center" cellpadding="2"><tr>';
    $c = 0;
    while($row = mysql_fetch_array($galresult))
    {
        $template = $trow['templateCategory'];
    $template = str_replace(':IMG:', displayIconCat($row), $template);
    $template = str_replace(':GALLNAME:', displayCatName($row), $template);
    $template = str_replace(':DESCRIP:', displayDescriptionCat($row), $template);
    $template = str_replace(':SUBCAT:', navigationSubCat($row), $template);
    print "<td align=\"center\" valign=\"top\" width=\"$pc%\">$template</td>";
    $c++;
    if ($c == $numColMain & $nb != $numColMain)
        {
            print '</tr><tr>';
        $c = 0;
    }
    }

    print '</tr>'
     ."<tr><td colspan=\"$numColMain\" align=\"center\"><br>"
     .search_form($HTTP_POST_VARS);

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

    print '</td></tr></table>';
    CloseTable();
    print '<p align="right">'
     .'<font class="meg-sub">'
     .sprintf(_GALCOPYRIGHT, $version, "$baseurl?op=modload&amp;name=$module_name&amp;file=credits")
     .'</font>'
     .'</p>';
    include 'footer.php';
}

?>
