<?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: categories.php,v 1.9.2.3 2004/04/18 20:15:19 ajvwaay Exp $




/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)            */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

$index = 0;
$categories = 1;
$cat = $catid;
automatednews();

function theindex($catid)
{
    global $mpnTables,$phpEx, $screen;
    global $storyhome, $httpref, $httprefmax, $topicname, $topicimage, $topictext, $datetime, $user, $cookie;
    include("header.$phpEx");

    if (isset($cookie[3])) {
    $storynum = $cookie[3];
    } else {
    $storynum = $storyhome;
    }
    mysql_query("update ".$mpnTables['stories_cat']." set counter=counter+1 where catid='$catid'");

    $result = mysql_query("SELECT count(sid) FROM ".$mpnTables['stories']." WHERE catid = '$catid'");
    $total_records = mysql_result($result, 0);
    $pages = ceil($total_records / $storynum);
    if (!isset($screen)) $screen = 0;
    $page = $screen + 1;
    $start = $screen * $storynum;

    $result = mysql_query("SELECT sid, aid, title, time, hometext, bodytext, comments, counter, topic, informant, notes FROM ".$mpnTables['stories']." where catid='$catid' ORDER BY sid DESC limit $start, $storynum");
    if(!$result) {
    echo mysql_errno(). ": ".mysql_error(). "<br>"; exit();
    }
    while (list($s_sid, $aid, $title, $time, $hometext, $bodytext, $comments, $counter, $topic, $informant, $notes) = mysql_fetch_row($result))
    {

        // Kiril: Start New Sanitizer

        $sanity_ary = compact( 'title', 'hometext', 'bodytext', 'notes', 'informant' );
        $_SERVER['SAN'] -> slashIT( $sanity_ary );
        extract( $sanity_ary );

        // Adjust Formatting

        if ( $_SERVER['F_LIB'] -> checkPostDate( $time ) )
        {
            $slice_ary = array_slice( $sanity_ary, 1, 3 );
            $_SERVER['SAN'] -> sanitizeLegacyContent( $slice_ary );
        }
        else
        {
            $slice_ary = array_slice( $sanity_ary, 1, 3 );
            $_SERVER['SAN'] -> adjustFormat( $slice_ary, 3, 10 );
        }

        extract( $slice_ary );
        unset( $sanity_ary, $slice_ary );

        // End New Sanitizer


    $printP = "<a href='print.$phpEx?sid=$s_sid'><img src='images/print.gif' border='0' alt='".translate("Printer Friendly Page")."' width='15' height='11' /></a>&nbsp;";
    $sendF = "<a href='friend.$phpEx?op=FriendSend&sid=$s_sid'><img src='images/friend.gif' border='0' alt='".translate("Send this Story to a Friend")."' width='15' height='11' /></a>";
    getTopics($s_sid);
    formatTimestamp($time);

/*//        $subject = $myts->makeTboxData4Show($subject);
        $title = $myts->makeTboxData4Show($title);
        $hometext = $myts->makeTareaData4Show($hometext);
    $notes = $myts->makeTareaData4Show($notes);*/

    $introcount = strlen($hometext);
    $fullcount = strlen($bodytext);
    $totalcount = $introcount + $fullcount;
    $morelink = "( ";
    if ($fullcount > 1) {
        $morelink .= "<a href='article.$phpEx?sid=$s_sid";
        if (isset($cookie[4])) { $morelink .= "&mode=$cookie[4]"; } else { $morelink .= "&mode=thread"; }
        if (isset($cookie[5])) { $morelink .= "&order=$cookie[5]"; } else { $morelink .= "&order=0"; }
        $morelink .= "'><b>".translate("Read More...")."</b></a> | $totalcount ".translate("bytes more")." | "; }
        $count = $comments;
        $morelink .= "<a href='article.$phpEx?sid=$s_sid";
        if (isset($cookie[4])) { $morelink .= "&mode=$cookie[4]"; } else { $morelink .= "&mode=thread"; }
        if (isset($cookie[5])) { $morelink .= "&order=$cookie[5]"; } else { $morelink .= "&order=0"; }
        if (isset($cookie[6])) { $morelink .= "&thold=$cookie[6]"; } else { $morelink .= "&thold=0"; }
        $morelink2 = "<a href='article.$phpEx?sid=$s_sid";
        if (isset($cookie[4])) { $morelink2 .= "&mode=$cookie[4]"; } else { $morelink2 .= "&mode=thread"; }
        if (isset($cookie[5])) { $morelink2 .= "&order=$cookie[5]"; } else { $morelink2 .= "&order=0"; }
        if (isset($cookie[6])) { $morelink2 .= "&thold=$cookie[6]"; } else { $morelink2 .= "&thold=0"; }
        if(($count==0)) {
        $morelink .= "'>".translate("comments?")."</a> | $printP $sendF )";
    } else {
        if (($fullcount<1)) {
        if(($count==1)) {
            $morelink .= "'><b>".translate("Read More...")."</b></a> | $morelink2'>$count ".translate("comment")."</a> | $printP $sendF )";
        } else {
            $morelink .= "'><b>".translate("Read More...")."</b></a> | $morelink2'>$count ".translate("comments")."</a> | $printP $sendF )";
        }
        } else {
        if(($count==1)) {
            $morelink .= "'>$count ".translate("comment")."</a> | $printP $sendF )";
        } else {
            $morelink .= "'>$count ".translate("comments")."</a> | $printP $sendF )";
        }
        }
    }
    $sid = $s_sid;
    $selcat = mysql_query("select title from ".$mpnTables['stories_cat']." where catid='$catid'");
    list($title1) = mysql_fetch_row($selcat);
    $title = "$title1: $title";

    themeindex($aid, $informant, $datetime, $title, $counter, $topic, $hometext, $notes, $morelink, $topicname, $topicimage, $topictext);

    }

    // let's create the dynamic links now
    echo "<table width=\"100%\" cellspacing=\"0\" border=\"0\" cellpadding=\"0\">\n";
    echo "<tr><td width = \"33%\" align =\"left\">\n";
    if ($screen > 0) {
        $url = "categories.$phpEx?op=newindex&catid=$catid&screen=" . ($screen - 1);
            echo "<a href=\"$url\"><b>< ".translate("Previous Page")."</b></a>\n";
    }
    echo "</td><td width = \"33%\" align = \"center\">".translate("Page")." $page</td>\n";
        echo "<td width = \"33%\" align =\"right\">\n";
    if ($screen < ($pages - 1)) {
        $url = "categories.$phpEx?op=newindex&catid=$catid&screen=" . ($screen + 1);
        echo "<a href=\"$url\"><b>".translate("Next Page")."></b></a>\n";
    }
    echo "</td></tr></table>\n";

    mysql_free_result($result);
    if ($httpref==1) {
    $referer = getenv("HTTP_REFERER");
    if ($referer=="" OR ereg("unknown", $referer) OR eregi( _MPN_ROOT_URI, $referer )) {
    } else {
            mysql_query("insert into ".$mpnTables['referer']." values (NULL, '$referer')");
    }
    $result = mysql_query("select * from ".$mpnTables['referer']);
    $numrows = mysql_num_rows($result);
    if($numrows == $httprefmax) {
            mysql_query("delete from ".$mpnTables['referer']);
    }
    }
    include("footer.$phpEx");
}

switch ($op) {
    case "newindex":
        if ($catid == 0 OR $catid == "")
        {
            $_SERVER['F_LIB'] -> redirectRequest( 'index.php' );
        }
        theindex($catid);
        break;

    default:
        $_SERVER['F_LIB'] -> redirectRequest( 'index.php' );
    break;

}

?>
