<?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: sections.php,v 1.14.2.4 2004/07/17 20:52:05 ajvwaay Exp $




######################################################################
# PHP-NUKE: Web Portal System
# ===========================
#
# Copyright (c) 2000 by Francisco Burzi (fburzi@ncc.org.ve)
# http://phpnuke.org
#
# This modules is to have special sections for articles, reviews, etc.
#
# 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.
#
######################################################################
#
# Modified by Leonard Teo to better support articles on tech sites
# leonard@planet3dart.com
#
# modified: 31 Dec 2000
#
# http://www.planet3dart.com
#
######################################################################



/*******************************************
* Function: generateTime
* Purpose: Takes a mysql DATETIME and spits out a readable date
* dd monthname yyyy
*******************************************/
function generateTime($timestamp) {
    global $locale;
    $year = substr($timestamp, 0, 4);
    $month = substr($timestamp, 5, 2);
    $day = substr($timestamp, 8, 2);
    setlocale (LC_TIME, "$locale");
    $time = strftime("%d %B %Y", mktime(0, 0, 0, $month, $day, $year) );
    return $time;
} //end function generateTime



/*******************************************
* The following enables you to create a close a master table easily
*******************************************/
function listsections() {
    global $mpnTables;

    $result = mysql_query("select secid, secname, image, secdesc from ".$mpnTables['sections']." order by secname");

    include('header.php');
	echo "<div id='sectlist'>\n";
    echo "<h1>" . translate ( 'Extended Articles And Special Sections' ) . "</h1>\n";

    echo "<br /><br />\n";

    opentable();

    echo "<font class=\"sectiontitle\">" . translate("Choose a category: ") . "</font>";

    while (list($secid, $secname, $image, $secdesc) = mysql_fetch_row($result))
    {
        $_SERVER['SAN'] -> adjustFormat( $secdesc, 3, 10 );

//Diner mod -- I have removed the Section Images, but the variable is still there.  You can easily add them, although I think that you are better off with a description and text link for aestetic value.  I have also added the description of section.

        echo "<br /><br /><a class=\"sectiontopics\" href=\"sections.php?op=listarticles&secid=$secid\">$secname</a><br /><br />";

        echo "<div class='indent15'>$secdesc</div>";

        /*if ($count == 2) {
            echo "<tr>";
            $count = 0;
        }
        echo "<td><center><img name=\"placeholder\" src=\"images/pix.gif\" border=0 width=25 height=42><a href=sections.$phpEx?op=listarticles&secid=$secid><img src=images/sections/$image border=0 Alt=\"$secname\"></a>
              <br /><img name=\"placeholder\" src=\"images/pix.gif\" border=0 width=25 height=15>$secname";
        $count++;
        if ($count == 2) {
            echo "</center></tr>\n";
        }
        echo "</td>";*/
    }
    mysql_free_result($result);

    closetable();
	echo "</div>";
    include ('footer.php');
}

function listarticles($secid) {
    global $bgcolor1, $bgcolor2, $bgcolor3, $mpnTables;
    include ('header.php');
	echo "<div id='sectlist'>\n";
    $result = mysql_query("select secname from ".$mpnTables['sections']." where secid=$secid");
    list($secname) = mysql_fetch_row($result);
    mysql_free_result($result);
    $result = mysql_query("SELECT artid, secid, title, byline, author, date, counter FROM " . $mpnTables['seccont'] . " WHERE secid=$secid ORDER BY date DESC");
    $result2 = mysql_query("select image from " . $mpnTables['sections'] . " where secid=$secid");
    list($image) = mysql_fetch_row($result2);


    echo "<h1>$secname</h1>\n";
    echo "<h2>" . translate ( 'Following are the articles published in this category' ) . "</h2>\n";

    echo "<br /><br />\n";

    opentable();

    //Diner Mod -- Creates a nice looking table

    echo "<table border=0 width=\"90%\">

    <tr bgcolor=\"$bgcolor3\"><td><font class=\"sectiontitle\">" . translate("Title") . "</font></td><td><font class=\"sectiontitle\">" . translate("Author") . "</font></td><td><font class=\"sectiontitle\">" . translate("Date Written") . "</font></td><td><font class=\"sectiontitle\">" . translate("Read") . "</font></font></td>";

    #Print each article title
    //Diner Mod -- Brings the byline and counter down
    while (list($artid, $secid, $title, $byline, $author, $date, $counter) = mysql_fetch_row($result)) {

        #Generate the date
        $date = generateTime("$date");

        echo "
        <tr><td align=left bgcolor=\"$bgcolor1\"><a href=sections.php?op=viewarticle&artid=$artid>$title</a></td><td bgcolor=\"$bgcolor2\"><font class=\"sectionstory\">$author</font></td><td bgcolor=\"$bgcolor3\"><font class=\"sectionstory\">$date</font></td><td bgcolor=\"$bgcolor2\"><font class=\"sectionstory\">$counter</font></font></td></tr>\n
        <tr><td><div class='indent15'>$byline</div></td></tr>\n
        ";
    }


    echo "</table>
    <br /><br />
    [ <a href=sections.php>".translate("Return to Sections Index")."</a> ]
    <br />
    <br />
    ";

    mysql_free_result($result);

    closetable();
	echo "</div>";
    include ('footer.php');
}



########################################
# function viewarticle
# allows you to view the article in all its glory
########################################

function viewarticle($artid, $page) {
    global $mpnTables;
    mysql_query("update ".$mpnTables['seccont']." set counter=counter+1 where artid='$artid'");

    $result = mysql_query("select artid, secid, title, author, authoremail, date, content, counter from ".$mpnTables['seccont']." where artid=$artid");
    list($artid, $secid, $title, $author, $authoremail, $timestamp, $content, $counter) = mysql_fetch_row($result);




    $result2 = mysql_query("select secid, secname from ".$mpnTables['sections']." where secid=$secid");
    list($secid, $secname) = mysql_fetch_row($result2);


    // Kiril: Start New Sanitizer

    $sanity_ary = compact( 'title', 'author', 'authoremail', 'content', 'secname' );
    $_SERVER['SAN'] -> slashIT( $sanity_ary );
    extract( $sanity_ary );
    unset( $sanity_ary );

    if ( $_SERVER['F_LIB'] -> checkPostDate( $timestamp ) )
    {
        $_SERVER['SAN'] -> sanitizeLegacyContent( $content, NULL, FALSE, FALSE );
    }
    else
    {
        $_SERVER['SAN'] -> adjustFormat( $content, 3, 10 );
    }

    // End New Sanitizer



    $words = sizeof(explode(" ", $content));
    include("header.php");
	echo "<div id='sectview'>\n";
    echo "<table width=\"100%\"><tr><td align=left>
    <a href=\"printfeature.php?artid=$artid\"><img src=\"images/print.gif\" border=0 Alt=\"" . translate("Printer Friendly Page") . "\" width=15 height=11></a>&nbsp;&nbsp  <font class=\"sectionsub\">" . translate("Printer Friendly Page") . "</font>
    </td><td align=right><a href=\"friend.php?op=FriendSendSection&artid=$artid\"><img src=\"images/friend.gif\" border=0 Alt=\"" . translate("Send this Story to a Friend") . "\" width=15 height=11></a>&nbsp;&nbsp;<font class=\"sectionsub\">" . translate("Send this story to a friend") . "</font></td></tr>\n</table>";


    opentable();

    #Generate the date
    $articledate = generateTime($timestamp);

    #Rip the article into pages. Delimiter string is "[pagebreak]". This is for Dreamweaver users
    $contentpages = explode("<pagebreak />", $content );
    $pageno = count($contentpages);

    #Define the current page
    if (($page == "") || ($page < 1 ))
        $page = 1;
    if ($page > $pageno)
        $page = $pageno;

    $arrayelement = (int)$page;
    $arrayelement--;

    #Print the title
    //Check if the current page is > 1
    if ($page > 1) $title .= " - cont'd";
    echo "<p><font class=\"sectiontitle\"><b>$title</b></font><br />";
    if ($author != "") {
        echo "<font class=\"sectionstory\"><a href=\"mailto:$authoremail\">$author</a>, ";
    }
    echo "$articledate</font></p>";

    # This is where the content goes

    $display_text = $contentpages[$arrayelement];

    $_SERVER['SAN'] -> adjustFormat( $display_text, 3, 10 );

    echo "<div id='sectview'>\n";

        echo $display_text . "\n";

    echo "</div>\n";

    #Automatic footers!
    if($page >= $pageno)
      $next_page = "<a href=\"sections.php\">".translate("Back to Main")."</a>";
    else {
      $next_pagenumber = $page + 1;
      $next_page = "<a href=\"sections.php?op=viewarticle&artid=$artid&page=$next_pagenumber\">Next Page ($next_pagenumber of $pageno) >></a>";
    }

    if($page <= 1)
      $previous_page = "<a href=\"sections.php\">".translate("Back to Main")."</a>";
    else {
      $previous_pagenumber = $page -1;
      $previous_page = "<a href=\"sections.php?op=viewarticle&artid=$artid&page=$previous_pagenumber\"><< ".translate("Previous Page")." ($previous_pagenumber of $pageno)</a>";
    }

    //Print the table
    echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\"><tr>
          <td><font class=\"sectionsub\">$previous_page</font></td>
          <td><div align=\"right\"><font class=\"sectionsub\">$next_page</font></div></td>
          </tr>\n</table>" ;

    // End footer
    closetable();
    echo "
    <br /><br /><center>[ <a href=sections.php?op=listarticles&secid=$secid>".translate("Back to")." $secname</a> |
    <a href=sections.php>".translate("Sections Index")."</a> ]</center>";
    mysql_free_result($result);
    mysql_free_result($result2);
	echo "</div>";
    include ('footer.php');
}

########################################
# function printArticle
# printer friendly version
########################################

function printArticle($artid){

} //end function print article

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

switch($op) {

    case "viewarticle":
    if (!isset($page))
    {
        $page = null;
    }

    viewarticle($artid, $page);
    break;

    case "listarticles":
    listarticles($secid);
    break;

    default:
    listsections();
    break;

}

?>
