<?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: headlines.php,v 1.5.2.6 2004/08/15 12:58:04 kirilt 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.       */
/************************************************************************/

checkAccess( 'blocks', array( 'head', 'left' ) );

/*********************************************************/
/* Headlines Grabber to put other sites news in our site */
/*********************************************************/

function HeadlinesAdmin() {
    global $hlpfile, $admin, $mpnTables,$phpEx;
    include ("header.$phpEx");
    GraphicAdmin($hlpfile);
    OpenTable();
    echo "
    <center><font size=4><b>".translate("Headlines")."</b></font></center>
    <form action=admin.$phpEx method=post>
    <center><table border=1 width=90%><tr>
    <td bgcolor=0000BA><font color=white><center>".translate("ID")."</td>
    <td bgcolor=0000BA><font color=white><center>".translate("Site Name")."</td>
    <td bgcolor=0000BA><font color=white><center>".translate("URL")."</td>
    <td bgcolor=0000BA><font color=white><center>".translate("Status")."</td>
    <td bgcolor=0000BA><font color=white><center>".translate("Functions")."</td><tr>";
    $result = mysql_query("select hid, sitename, url, status from ".$mpnTables['headlines']." order by hid");
    while(list($hid, $sitename, $url, $status) = mysql_fetch_row($result)) {
    echo "
    <td bgcolor=009999 align=center><font color=white>$hid</td>
    <td bgcolor=009999 align=center><font color=white><a href=$url target=new>$sitename</a></td>
    <td bgcolor=009999 align=center><font color=white>$url</td>";
    if($status == 1) {
        $status = "<font color=Yellow>".translate("Active")."</font>";
    } else {
        $status = "".translate("Inactive")."";
    }
    echo "
    <td bgcolor=009999 align=center><font color=white>$status</td>
    <td bgcolor=009999 align=center><font color=white><a href=admin.$phpEx?op=HeadlinesEdit&hid=$hid>".translate("Edit")."</a> | <a href=admin.$phpEx?op=HeadlinesDel&hid=$hid&ok=0>".translate("Delete")."</a></td><tr>";
    }
    echo "</form></td></tr></table>
    <br><br>
    </center><font size=4><b>".translate("Add Headline")."</b><br><br>
    <font size=2>
    <form action=admin.$phpEx method=post>
    <table border=0 width=100%><tr><td>
    ".translate("Site Name:")." </td><td><input type=text name=xsitename size=31 maxlength=30></td></tr><tr><td>
    ".translate("URL:")." </td><td><input type=text name=url size=50 maxlength=100></td></tr><tr><td>
    ".translate("URL for the RDF/XML file:")." </td><td><input type=text name=headlinesurl size=50 maxlength=200></td></tr><tr><td>
    ".translate("Status:")." </td><td><select name=status>
    <option name=status value=1>".translate("Active")."</option>
    <option name=status value=0 selected>".translate("Inactive")."</option>
    </select></td></tr></table>
    <input type=hidden name=op value=HeadlinesAdd>
    <input class='button' type=submit value=".translate("Add").">
    </form>
    </td></tr></table></td></tr></table>";
    include("footer.$phpEx");
}

function HeadlinesEdit($hid) {
    global $language, $hlpfile, $admin, $mpnTables,$phpEx;
    include ("header.$phpEx");
    GraphicAdmin($hlpfile);
    $result = mysql_query("select sitename, url, headlinesurl, status from ".$mpnTables['headlines']." where hid='$hid'");
    list($xsitename, $url, $headlinesurl, $status) = mysql_fetch_row($result);
    OpenTable();
    echo "
    <center><font size=4><b>".translate("Edit Headline")."</b></font></center>
    <form action=admin.$phpEx method=post>
    <input type=hidden name=hid value=$hid>
    <table border=0 width=100%><tr><td>
    ".translate("Site Name:")." </td><td><input type=text name=xsitename size=31 maxlength=30 value=$xsitename></td></tr><tr><td>
    ".translate("URL:")." </td><td><input type=text name=url size=50 maxlength=100 value=$url></td></tr><tr><td>
    ".translate("URL for the RDF/XML file:")." </td><td><input type=text name=headlinesurl size=50 maxlength=200 value=$headlinesurl></td></tr><tr><td>
    ".translate("Status:")." </td><td><select name=status>";

    $sel_a = $sel_i = null;

    if($status == 1) {
        $sel_a = "selected";
    } else {
        $sel_i = "selected";
    }
    echo "
    <option name=status value=1 $sel_a>".translate("Active")."</option>
    <option name=status value=0 $sel_i>".translate("Inactive")."</option>
    </select></td></tr></table>
    <input type=hidden name=op value=HeadlinesSave>
    <input class='button' type=submit value=".translate("Save Changes").">
    </form>
    </td></tr></table></td></tr></table>";
    include("footer.$phpEx");
}

function HeadlinesSave($hid, $xsitename, $url, $headlinesurl, $status) {
    global $mpnTables,$phpEx;
    $xsitename = ereg_replace(" ", "", $xsitename);
    mysql_query("update ".$mpnTables['headlines']." set sitename='$xsitename', url='$url', headlinesurl='$headlinesurl', status='$status' where hid='$hid'");
    $del_cache = "cache/newsheadline-".$hid.".cache";
    if ($status == "0" && file_exists($del_cache)) {
    if (!unlink ($del_cache)) die ("Unable to delete the headlines cache file");
    }

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

}

function HeadlinesAdd($xsitename, $url, $headlinesurl, $status) {
    global $mpnTables,$phpEx;
    $xsitename = ereg_replace(" ", "", $xsitename);
    mysql_query("insert into ".$mpnTables['headlines']." values (NULL, '$xsitename', '$url', '$headlinesurl', '$status')");

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

function HeadlinesDel($hid, $ok=0) {
    global $mpnTables,$phpEx;
    if($ok==1) {
    mysql_query("delete from ".$mpnTables['headlines']." where hid=$hid");

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

    } else {
    include("header.$phpEx");
    GraphicAdmin($hlpfile);
    OpenTable();
    echo "<center><br>";
    echo "<font size=3 color=Red>";
    echo "<b>".translate("WARNING: Are you sure you want to delete this Headline?")."</b><br><br><font color=Black>";
    }
    echo "[ <a href=admin.$phpEx?op=HeadlinesDel&hid=$hid&ok=1>".translate("Yes")."</a> | <a href=admin.$phpEx?op=HeadlinesAdmin>".translate("No")."</a> ]<br><br>";
    echo "</TD></TR></TABLE></TD></TR></TABLE>";
    include("footer.$phpEx");
}

switch($op) {

        case "HeadlinesDel":
            HeadlinesDel($hid, $ok);
            break;

        case "HeadlinesAdd":
            HeadlinesAdd($xsitename, $url, $headlinesurl, $status);
            break;

        case "HeadlinesSave":
            HeadlinesSave($hid, $xsitename, $url, $headlinesurl, $status);
            break;

        case "HeadlinesAdmin":
            HeadlinesAdmin();
            break;

        case "HeadlinesEdit":
            HeadlinesEdit($hid);
            break;

}

?>
