<?php

@( (bool)FALSE === strpos( $_SERVER['REQUEST_URI'], basename( __FILE__ ) ) ) OR exit( '!! 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.13.2.10 2004/08/15 12:58:04 kirilt Exp $

######################################################################
# PHP-NUKE: Web Portal System
# ===========================
#
# Copyright (c) 2000 by Francisco Burzi (fburzi@ncc.org.ve)
# http://phpnuke.org
#
# This modules is the main administration part
#
# 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
#
######################################################################

checkAccess( 'modules', array( 'section' ) );


/*********************************************************/
/* Sections Manager Functions                            */
/*********************************************************/

function sections() {
    global $hlpfile, $admin, $admart, $mpnTables;
    include("header.php");
    GraphicAdmin($hlpfile);
    $result = mysql_query("select secid, secname from ".$mpnTables['sections']." order by secid");
    if (mysql_num_rows($result)==0) {
    }

if (mysql_num_rows($result) > 0) {
    OpenTable();
    echo "
    <b><center>" . translate("Current Active Sections") . "</b><br>" . translate("Click to Edit") . "</center><br>
    <center><table border=0 width=100% align=center cellpadding=1><tr><td align=center>
    ";
        while (list($secid, $secname) = mysql_fetch_array($result)) {
        ?>
        <li><?php echo "<a href=admin.php?op=sectionedit&secid=$secid>"; ?><?php echo $secname ?></a>
        <?php
        }
        echo "</td></tr></table>";
    ?>
    </td></tr></table></td></tr></table>
    <br>
    <?php OpenTable() ?>
    <font size=4><b><?php echo translate("Add Article in Sections") ?></b></font><font size=2>
    <br><br>

    <form action="admin.php" method="post"><br>
    <b><?php echo translate("Title:") ?></b><br>
    <input class=textbox type="text" name="title" size=30 value="">
    <br><br>

    <b><?php echo translate("By Line (a description of the article)") ?></b><br>
    <textarea class=textbox name="byline" cols=70 rows=5 value=""></textarea>
    <br><br>

    <b><?php echo translate("Author:") ?></b>

    <br>
    <input class=textbox type="text" name="author" size="30" maxlength="255">
    <br><br>

    <b><?php echo translate("Email:") ?></b>
    <br>
    <input class=textbox type="text" name="authoremail" size="30" maxlength="255">
    <br><br>

    <?php
       // Get the current date
       $currentdate = mktime (0,0,0,date("m"),date("d"),  date("Y"));
       $year = strftime("%Y", $currentdate);
       $month = strftime("%m", $currentdate);
       $day = strftime("%d", $currentdate);
    ?>

    <!-- Date -->
    <table>

        <td width="82"> <?php echo translate("Year") ?><br>
          <select name="year">
            <?php
       //Print out options for 1995-2000
       for ($i = 1995; $i <= 2010; $i++){
         if ($i == $year)
           echo "<option value=\"$i\" selected>$i</option>\n";
         else
           echo "<option value=\"$i\">$i</option>\n";
       }
    ?>
          </select>
      </td>
        <td width="103"> <?php echo translate("Month") ?><br>
          <select name="month">
            <?php
//Print out options for 1-12
for ($i = 1; $i <= 12; $i++){
  if ($i == $month)
    echo "<option value=\"$i\" selected>$i</option>\n";
  else
    echo "<option value=\"$i\">$i</option>\n";
}
?>
          </select>
      </td>
      <td width="222"> <?php echo translate("Day") ?><br>
          <select name="day">
            <?php
//Print out options for 1-31
for ($i = 1; $i <= 31; $i++){
  if ($i == $day)
    echo "<option value=\"$i\" selected>$i</option>\n";
  else
    echo "<option value=\"$i\">$i</option>\n";
}
?>
          </select></td></table>
    <br><br>
    <b><?php echo translate("Section:") ?><br></b>
    <?php
    $result = mysql_query("select secid, secname from ".$mpnTables['sections']." order by secid");
    while(list($secid, $secname) = mysql_fetch_array($result)) {
    echo "<input type=radio name=secid value=$secid>$secname<br>";
    } ?>
    <br>
    <b><?php echo translate("Content:") ?></b><br>
    <textarea class=textbox name="content" cols=70 rows=20></textarea>
    <br><br>


    <?php

    addFormatOption();

    echo "<input type='hidden' name='clickit_form' value='content' />\n";
    echo "<input type='hidden' name='stripit_form' value='title|byline|author|authoremail' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    ?>


    <input type=hidden name=op value=secarticleadd>
    <INPUT class='button' type="submit" value="<?php echo translate("Add Article!") ?>">
    </form>
    </td></tr></table></td></tr></table>
    <br>


    <?php OpenTable(); ?>


    <font size=4><b><?php echo translate("Last"); echo " $admart "; echo translate("Articles"); ?></b><font size=2>
    <br><br>
    <ul>
    <?php
    $result = mysql_query("select artid, secid, title, content from ".$mpnTables['seccont']." order by artid desc limit 0,$admart");
    while(list($artid, $secid, $title, $content) = mysql_fetch_array($result)) {
        $result2 = mysql_query("select secid, secname from ".$mpnTables['sections']." where secid='$secid'");
        list($secid, $secname) = mysql_fetch_row($result2);
        echo "<li>$title ($secname) [ <a href=admin.php?op=secartedit&artid=$artid>" . translate("Edit") . "</a> ]";
    } ?>
    </ul>
    <form action="admin.php" method="post">
    <?php echo translate("Edit Article ID:") ?> <input class=textbox type="text" NAME="artid" SIZE=10>
    <input type=hidden name=op value="secartedit">
    <input class='button' type="submit" value="<?php echo translate("Go!") ?>">
    <?php mysql_free_result($result); ?>
    </form></td></tr></table></td></tr></table>
    </ul>
<?php }
    OpenTable(); ?>
    <font size=4><b><?php echo translate("Add a New Section") ?></b><font size=2>
    <br><br>
    <form action="admin.php" method="post"><br>
    <b><?php echo translate("Section Name:") ?></b><br>
    <input class=textbox type="text" name="secname" size=40 maxlength=40><br><br>
    <b>
    <?php
    echo translate('Section Description');
    ?>
    </b><br>

    <textarea class=textbox name="secdesc" cols=70 rows=5 value=""></textarea><br><br>


    <?php

        echo "<input type='hidden' name='clickit_form' value='secdesc' />\n";
        echo "<input type='hidden' name='stripit_form' value='title|byline|author|authoremail' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    ?>


    <!--<b><?php echo translate("Section Image:") ?> </b>&nbsp; <?php echo translate("(example: opinion.gif)") ?><br>
    <input class=textbox type="text" name="image" size=40 maxlength=50><br><br>-->
    <input type=hidden name=op value=sectionmake>
    <INPUT class='button' type="submit" value="<?php echo translate("Add Section!") ?>">
    </form>
    </td></tr></table></td></tr></table>
    <?php
    include("footer.php");
}


function secartedit($artid) {
    global $mpnTables, $hlpfile;

    include("header.php");

    GraphicAdmin($hlpfile);

    $result = mysql_query("select artid, secid, title, byline, author, authoremail, date, content FROM ".$mpnTables['seccont']." WHERE artid='$artid'");

    list($artid, $secid, $title, $byline, $author, $authoremail, $timestamp, $content) = mysql_fetch_array($result);

    // Kiril: Start New Sanitizer

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

    // End New Sanitizer

    OpenTable();
    ?>
    <font size=4><b><?php echo translate("Edit Article") ?></b><font size=2>
    <br><br>
    <form action="admin.php" method="post"><br>
    <b><?php echo translate("Title:") ?></b><br>
    <input class=textbox type="text" name="title" size=60 value="<?php echo $title ?>"><br><br>

    <b><?php echo translate("By Line:") ?></b><br>
    <textarea class=textbox name=byline cols=70 rows=5><?php echo $byline ?></textarea><br><br>

    <?php
    $result2 = mysql_query("select secid, secname from ".$mpnTables['sections']." order by secname");
    while(list($secid2, $secname) = mysql_fetch_array($result2)) {
        $che = ($secid2==$secid) ? ( "checked" ) : ( '' );
        echo "<input type=radio name=secid value=$secid2 $che>$secname<br>";
    } ?>
    <br>

        <b><?php echo translate("Author:") ?></b>

    <br>

  <input class=textbox type="text" name="author" size="60" maxlength="255" value="<?php echo $author ?>">
    <br><br>

    <b><?php echo translate("Email:") ?></b>
    <br>

  <input class=textbox type="text" name="authoremail" size="60" maxlength="255" value="<?php echo $authoremail ?>">
    <br><br>

    <?php
       // Get the date from the timestamp   0123-56-89
       $year = substr($timestamp, 0, 4);
       $month = substr($timestamp, 5, 2);
       $day = substr($timestamp, 8, 2);
    ?>

    <!-- Date -->
    <table>

        <td width="82"> <?php echo translate("Year") ?><br>
          <select name="year">
            <?php
       //Print out options for 1995-2000
       for ($i=1995; $i<=2010; $i++){
         if ($i == $year)
           print("<option value=\"$i\" selected>$i</option>\n");
         else
           print("<option value=\"$i\">$i</option>\n");
       }
    ?>
          </select>
      </td>
        <td width="103"> <?php echo translate("Month") ?><br>
          <select name="month">
            <?php
//Print out options for 1-12
for ($i=1; $i<=12; $i++){
  if ($i == $month)
    print("<option value=\"$i\" selected>$i</option>\n");
  else
    print("<option value=\"$i\">$i</option>\n");
}
?>
          </select>
      </td>
      <td width="222"> <?php echo translate("Day") ?><br>
          <select name="day">
            <?php
//Print out options for 1-31
for ($i=1; $i<=31; $i++){
  if ($i == $day)
    print("<option value=\"$i\" selected>$i</option>\n");
  else
    print("<option value=\"$i\">$i</option>\n");
}
?>
          </select></td></table><br>

    <b><?php echo translate("Content") ?></b><br>


    <textarea class=textbox name=content cols=70 rows=20><?php echo $content ?></textarea>


    <?php

     addFormatOption();

     echo "<input type='hidden' name='clickit_form' value='content' />\n";
     echo "<input type='hidden' name='stripit_form' value='author|authoremail|title' />\n";
     echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

     ?>


    <input type=hidden name=artid value="<?php echo $artid ?>">
    <input type=hidden name=op value=secartchange>
    <table border=0><tr><td>
    <INPUT class='button' type="submit" value="<?php echo translate("Save Changes!") ?>">
    </form></td><td>
    <form action="admin.php" method="post"><br>
    <input type=hidden name=artid value="<?php echo $artid ?>">
    <input type=hidden name=op value=secartdelete>
    <INPUT class='button' type="submit" value="<?php echo translate("Delete Article!") ?>">
    </form></td></tr></table>
    </td></tr></table></td></tr></table>
    <?php
    include("footer.php");
}

function sectionmake($secname, $secdesc, $image) {
    global $mpnTables;

    $sql = "INSERT INTO " . $mpnTables['sections'] . " VALUES ( NULL, '$secname', '$image', '$secdesc' )";

    @( mysql_query( $sql ) )
      OR goBack( translate( 'Query Failed' ) . '**' . __FILE__ . '***' .  __LINE__ );

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=sections' );
}

function sectionedit($secid)
{
    global $mpnTables, $hlpfile;
    include("header.php");
    GraphicAdmin($hlpfile);

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

    $result2 = mysql_query("select artid from ".$mpnTables['seccont']." where secid=$secid");
    $number = mysql_num_rows($result2);

    // Kiril New Sanitizer

    $sanity_ary = compact( 'secname', 'secdesc' );
    $_SERVER['SAN'] -> slashIT( $secdesc );
    extract( $sanity_ary );
    unset( $sanity_ary );


    // End New Sanitizer

    OpenTable();
    ?>
    <!--<?php //echo "<img src=images/sections/$image border=0><br><br>"; ?>-->
    <font size=4><b><?php echo translate("Edit Section:") ?> <?php echo $secname ?></b><font size=2>
    <br>
    <?php echo sprintf(translate("(This Section has %s articles attached)"), $number) ?>
    <br><br>
    <form action="admin.php" method="post"><br>
    <b><?php echo translate("Section Name:") ?></b> <?php echo translate("(40 characters Max.)") ?><br>
    <input class=textbox type="text" name="secname" size=40 maxlength=40 value="<?php echo $secname ?>"><br><br>
    <b><?php echo translate("Section Description") ?></b><br>
    <textarea class=textbox name=secdesc cols=70 rows=5><?php echo $secdesc ?></textarea><br><br>
    <!--<b><?php //echo translate("Section Image:") ?></b> <?php //echo translate("(example: opinion.gif)") ?><br>
    <input class=textbox type="text" name="image" size=40 maxlength=50 value="<?php //echo $image ?>"><br><br>-->

    <?php

    addFormatOption();

    echo "<input type='hidden' name='clickit_form' value='secdesc' />\n";
    echo "<input type='hidden' name='stripit_form' value='secname' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    ?>

    <input type=hidden name=secid value="<?php echo $secid ?>">
    <input type=hidden name=op value=sectionchange>
    <table border=0><tr><td>
    <INPUT class='button' type="submit" value="<?php echo translate("Save Changes!") ?>">
    </form></td><td>
    <form action="admin.php" method="post">
    <input type=hidden name=secid value="<?php echo "$secid"; ?>">
    <input type=hidden name=op value=sectiondelete>
    <INPUT class='button' type="submit" value="Delete Section!">
    </form></td></tr></table>

    </td></tr></table></td></tr></table>
    <?php
    include("footer.php");
}

function sectionchange($secid, $secname, $secdesc, $image) {
    global $mpnTables;

    mysql_query("update ".$mpnTables['sections']." set secname='$secname', secdesc='$secdesc', image='$image' where secid=$secid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=sections' );
}


################################################
# function secarticleadd
# Inserts the article in the database
################################################

function secarticleadd($secid, $title, $byline, $content, $author, $authoremail, $year, $month, $day) {
    global $mpnTables;

    //Generate the appropriate timestamp
    $unixTimeStamp = mktime (0,0,0,$month,$day,$year);
    $timestamp = strftime("%Y-%m-%d %H:%M:%S", $unixTimeStamp);

    //Insert data into the database
    mysql_query("INSERT INTO ".$mpnTables['seccont']." (secid, title, byline, author, authoremail, date, content) VALUES ('$secid','$title','$byline','$author','$authoremail','$timestamp','$content')");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=sections' );
}


###############################################
# function secartchange
# modifies the current article
###############################################

function secartchange($artid, $secid, $title, $byline, $content, $author, $authoremail, $year, $month, $day) {
    global $mpnTables;

    //Generate the appropriate timestamp
    $unixTimeStamp = mktime (0,0,0,$month,$day,$year);
    $timestamp = strftime("%Y-%m-%d %H:%M:%S", $unixTimeStamp);

    mysql_query("update ".$mpnTables['seccont']." set secid='$secid', title='$title', byline='$byline', content='$content', author='$author', authoremail='$authoremail', date='$timestamp' where artid=$artid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=sections' );

}


function sectiondelete($secid, $ok=0) {
    global $mpnTables, $hlpfile;
    if ($ok==1) {
        mysql_query("delete from ".$mpnTables['seccont']." where secid='$secid'");
        mysql_query("delete from ".$mpnTables['sections']." where secid='$secid'");

        $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=sections' );

    } else {
        include("header.php");
        GraphicAdmin($hlpfile);
        $result=mysql_query("select secname from ".$mpnTables['sections']." where secid=$secid");
        list($secname) = mysql_fetch_row($result);
        OpenTable();
        echo "
        <center><b>".translate("Delete Section: ")."$secname</b><br><br>
        ".translate("Are you sure you want to delete section")." $secname?<br>
        ".translate("This will delete ALL its articles!")."<br><br>
        [ <a href=\"admin.php?op=sections\">".translate("No")."</a> | <a href=\"admin.php?op=sectiondelete&secid=$secid&ok=1\">".translate("Yes")."</a> ]</center><br><br></center>
        </td></tr></table></center></td></tr></table>";
        include("footer.php");
    }
}

function secartdelete($artid, $ok=0) {
    global $mpnTables, $hlpfile;
    if ($ok==1) {
        mysql_query("delete from ".$mpnTables['seccont']." where artid='$artid'");

        $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=sections' );

    } else {
        include("header.php");
        GraphicAdmin($hlpfile);
        $result = mysql_query("select title from ".$mpnTables['seccont']." where artid=$artid");
        list($title) = mysql_fetch_row($result);
        OpenTable();
        echo "
        <center><b>".translate("Delete Article: ")."$title</b><br><br>
        ".translate("Are you sure you want to delete this article?")."<br><br>
        [ <a href=\"admin.php?op=sections\">".translate("No")."</a> | <a href=\"admin.php?op=secartdelete&artid=$artid&ok=1\">".translate("Yes")."</a> ]</center><br><br></center>
        </td></tr></table></center></td></tr></table>";
        include("footer.php");
    }
}

switch ($op) {

        case "sections":
            sections();
            break;

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

        case "sectionmake":
            if (!isset($image))
            {
                $image = '';
            }

            sectionmake($secname, $secdesc, $image);
            break;

        case "sectiondelete":
            if (!isset($ok))
            {
                $ok = null;
            }

            sectiondelete($secid, $ok);
            break;

        case "sectionchange":
            if (!isset($image))
            {
                $image = '';
            }

            sectionchange($secid, $secname, $secdesc, $image);
            break;

        case "secarticleadd":
            secarticleadd($secid, $title, $byline, $content, $author, $authoremail, $year, $month, $day);
            break;

        case "secartedit":
            secartedit($artid);
            break;

        case "secartchange":
            secartchange($artid, $secid, $title, $byline, $content, $author, $authoremail, $year, $month, $day);
            break;

        case "secartdelete":
            if (!isset($ok))
            {
                $ok = null;
            }
            secartdelete($artid, $ok);
            break;

}

?>
