Location: PHPKode > projects > ProNuke. Postnuke To Oracle > postnuke/html/modules/NS-Ephemerids/admin/modules/ephemerids.php
<?php
// File: $Id: ephemerids.php,v 1.15 2001/12/04 13:07:46 jgm Exp $ $Name:  $
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Based on:
// PHP-NUKE Web Portal System - http://phpnuke.org/
// Thatware - http://thatware.org/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: 
// Purpose of file: 
// ----------------------------------------------------------------------

if (!eregi("admin.php", $PHP_SELF)) { die ("Access Denied"); }
$hlpfile = "manual/ephem.html";
modules_get_language();

/*********************************************************/
/* Ephemerids Functions to have a Historic Ephemerids    */
/*********************************************************/

function Ephemerids() {
    global $hlpfile, $admin, $currentlang, $dbconn, $pntable; /* ML Oh well added this to be able to pre-select a language */
//FTO Remove warning
    global $bgcolor1;
    
    include ("header.php");
    GraphicAdmin($hlpfile);
    OpenTable();
    echo "<center><font class=\"pn-title\"><b>"._EPHEMADMIN."</b></font></center>";
    CloseTable();
    echo "<br>";

    if (!authorised(0, 'Ephemerids::', '::', ACCESS_EDIT)) {
        echo _EPHEMNOAUTH;
        include "footer.php";
        return;
    }

    if (authorised(0, 'Ephemerids::', '::', ACCESS_ADD)) {
        OpenTable();
        echo "<center><font class=\"pn-title\"><b>"._ADDEPHEM."</b></font></center><br>"
            ."<form action=\"admin.php\" method=\"post\">";
        $nday = "1";
        echo ""._DAY.": <select name=\"did\">";
        while ($nday<=31) {
            echo "<option name=\"did\">$nday</option>";
            $nday++;
        }
        echo "</select>";
        $nmonth = "1";
        echo ""._UMONTH.": <select name=\"mid\">";
        while ($nmonth<=12) {
            echo "<option name=\"mid\">$nmonth</option>";
            $nmonth++;
        }
        echo "</select>"._YEAR.": <input type=\"text\" name=\"yid\" maxlength=\"4\" size=\"5\"><br><br>"
            .'<b>'._LANGUAGE.': </b>'
            .'<select name="elanguage" size="1">';
        $lang = languagelist();
        if (!$elanguage)
        {
            $sel_lang[0] = ' selected';
        } else {
            $sel_lang[$elanguage] = ' selected';
        }
        print "<option value=\"\" $sel_lang[0]>"._ALL.'</option>';
        $handle = opendir('language');
        while ($f = readdir($handle))
        {
            if (is_dir("language/$f") && $lang[$f])
            {
                $langlist[$f] = $lang[$f];
            }
        }
        asort($langlist);
        foreach ($langlist as $k=>$v)
        {
            print "<option value=\"$k\"$sel_lang[$k]>$v</option>\n";
        }
        print '</select><br><br>' /* ML END */
              ."<b>"._EPHEMDESC.":</b><br>"
              ."<textarea name=\"content\" cols=\"60\" rows=\"10\"></textarea><br><br>"
              ."<input type=\"hidden\" name=\"op\" value=\"Ephemeridsadd\">"
              ."<input type=\"submit\" value=\""._OK."\">"
              ."</form>";
        CloseTable();
        echo "<br>";
    }

    if (authorised(0, 'Ephemerids::', '::', ACCESS_EDIT)) {
        OpenTable();
            echo "<center><font class=\"pn-title\"><b>"._EPHEMMAINT."</b></font></center><br>"
            ."<center><form action=\"admin.php\" method=\"post\">";
        $nday = "1";
        echo ""._DAY.": <select name=\"did\">";
        while ($nday<=31) {
            echo "<option name=\"did\">$nday</option>";
            $nday++;
        }
        echo "</select>";
        $nmonth = "1";
        echo ""._UMONTH.": <select name=\"mid\">";
        while ($nmonth<=12) {
            echo "<option name=\"mid\">$nmonth</option>";
            $nmonth++;
        }
        echo "</select>"
            ."<input type=\"hidden\" name=\"op\" value=\"Ephemeridsmaintenance\">"
            ."<input type=\"submit\" value=\""._EDIT."\">"
            ."</form></center>";
        CloseTable();
        echo "<br>";
    }

    OpenTable();
    echo "<br>";
    echo "<center><b>Current Ephemerids</b></center><br>";
    echo "<center><table border=\"1\" width=\"100%\" bgcolor=\"$bgcolor1\"><tr>"
        ."<td><b>&nbsp;&nbsp;Day&nbsp;&nbsp;</b></td>"
        ."<td><b>&nbsp;&nbsp;Month&nbsp;&nbsp;</b></td>"
        ."<td><b>&nbsp;&nbsp;Year&nbsp;&nbsp;</b></td>"
        ."<td><b>&nbsp;&nbsp;Event Name</b></td>"
        ."<td colspan=2>Modify</td></tr>";
    $result=$dbconn->Execute(buildSimpleQuery('ephem', array ('eid', 'did', 'mid', 'yid', 'content', 'elanguage')));
    
// FTO Check EOF and databse error
    if (!$result) {
          PN_DBMsgError($dbconn, __FILE__, __LINE__, "An error ocurred");
          die();
        }

    while(!$result->EOF) {

        list($eid, $did, $mid, $yid, $content, $elanguage) = $result->fields;

        $result->MoveNext();
    
        if (authorised(0, 'Ephemerids::', "$content:$eid", ACCESS_EDIT)) {
            echo "<tr><td align=\"center\">$did</td>"
                ."<td align=\"center\">$mid</td>"
                ."<td align=\"center\">$yid</td>"
                ."<td width=\"100%\">&nbsp;&nbsp;$content</td>";
            if (authorised(0, 'Ephemerids::', "$content:$eid", ACCESS_EDIT)) {
                echo "<td align=\"center\"><a href=\"admin.php?op=Ephemeridsedit&eid=$eid&did=$did&mid=$mid\">"._EDIT."</td>";
                if (authorised(0, 'Ephemerids::', "$content::$eid", ACCESS_DELETE)) {
                    echo "<td align=\"center\"><a href=\"admin.php?op=Ephemeridsdel&eid=$eid&did=$did&mid=$mid\">"._DELETE."</td>";
                } else {
                    echo "<td>&nbsp;</td>";
                }
            } else {
                echo "<td>&nbsp;</td><td>&nbsp;</td>";
            }
            echo "</tr>";
        }
    }
    echo "</table>";
    CloseTable();

    include ("footer.php");
}

function Ephemeridsadd($did, $mid, $yid, $content, $elanguage) {
    global $pntable, $dbconn;
//FTO : Remove warning
    global $hlpfile;

    csrfcheck();

    if (!authorised(0, 'Ephemerids::', "$content::", ACCESS_ADD)) {
        include "header.php";
        GraphicAdmin($hlpfile);
        OpenTable();
        echo "<center><font class=\"pn-title\"><b>"._EPHEMADMIN."</b></font></center>";
        CloseTable();
        echo "<br>";
        echo _EPHEMADDNOAUTH;
        include "footer.php";
        return;
    }

    $column =&$pntable['ephem_column'];
// FTO : Add SEQ suffix to avoid conflict name with ORACLE
    $nextid = $dbconn->GenId("{$pntable['ephem']}_SEQ");
    
    $dbconn->Execute("INSERT INTO $pntable[ephem] ($column[eid], $column[did], $column[mid], $column[yid], $column[content], $column[elanguage]) VALUES ($nextid, '$did', '$mid', '$yid', '$content', '$elanguage')");
    pnRedirect('admin.php?op=Ephemerids');
}

function Ephemeridsmaintenance($did, $mid) {
    global $pntable, $dbconn;
//FTO : Remove warning
    global $hlpfile;

    include ("header.php");

    GraphicAdmin($hlpfile);
    OpenTable();
    echo "<center><font class=\"pn-title\"><b>"._EPHEMADMIN."</b></font></center>";
    CloseTable();
    echo "<br>";

    if (!authorised(0, 'Ephemerids::', '::', ACCESS_EDIT)) {
        echo _EPHEMEDITNOAUTH;
        include "footer.php";
        return;
    }

    OpenTable();
    echo "<center><font class=\"pn-title\"><b>"._EPHEMMAINT." $did/$mid</b></font></center><br>";

    $column =&$pntable['ephem_column'];
    $result=$dbconn->Execute("SELECT $column[eid], $column[did], $column[mid], $column[yid], $column[content], $column[elanguage] FROM $pntable[ephem] WHERE $column[did]=$did AND $column[mid]=$mid");
// FTO Check EOF and databse error
    if (!$result) {
          PN_DBMsgError($dbconn, __FILE__, __LINE__, "An error ocurred");
          die();
        }

    while(!$result->EOF) {

        list($eid, $did, $mid, $yid, $content, $elanguage) = $result->fields;

        $result->MoveNext();
        echo "<font class=\"pn-normal\"><b>$yid</b> - ";
    if (!empty($elanguage)) {
        echo "($elanguage) - ";
    }
        if (authorised(0, 'Ephemerids::', "$content::$eid", ACCESS_EDIT)) {
        echo "[ <a href=\"admin.php?op=Ephemeridsedit&amp;eid=$eid&amp;did=$did&amp;mid=$mid\">"._EDIT."</a> ";
            if (authorised(0, 'Ephemerids::', "$content::$eid", ACCESS_DELETE)) {
                echo " | <a href=\"admin.php?op=Ephemeridsdel&amp;eid=$eid&amp;did=$did&amp;mid=$mid\">"._DELETE."</a> ]";
            } else {
                echo ' ]';
            }
        }
        echo "<br><font class=\"pn-sub\">$content</font><br><br><br>";
    }

    CloseTable();
    include ('footer.php');
}

function Ephemeridsdel($eid, $did, $mid) {
    global $pntable, $dbconn;

    csrfcheck();

    $column = &$pntable['ephem_column'];

    $result = $dbconn->Execute("SELECT $column[content]
                              FROM $pntable[ephem]
                              WHERE $column[eid]=$eid");
    list($content) = $result->fields;
    $result->Close();

    if (!authorised(0, 'Ephemerids::', "$content::$eid", ACCESS_DELETE)) {
        include "header.php";
        GraphicAdmin($hlpfile);
        OpenTable();
        echo "<center><font class=\"pn-title\"><b>"._EPHEMADMIN."</b></font></center>";
        CloseTable();
        echo "<br>";
        echo _EPHEMDELETENOAUTH;
        include "footer.php";
        return;
    }

    $dbconn->Execute("DELETE FROM $pntable[ephem] WHERE $column[eid]=$eid");
    pnRedirect('admin.php?op=Ephemeridsmaintenance&did='.$did.'&mid='.$mid);
}

function Ephemeridsedit($eid, $did, $mid) {
    global $pntable, $dbconn;
    include ("header.php");

    GraphicAdmin($hlpfile);
    OpenTable();
    echo "<center><font class=\"pn-title\"><b>"._EPHEMADMIN."</b></font></center>";
    CloseTable();
    echo "<br>";
    $column = &$pntable['ephem_column'];
    $result=$dbconn->Execute("SELECT $column[yid], $column[content], $column[elanguage] FROM $pntable[ephem] WHERE $column[eid]=$eid");
    list($yid, $content, $elanguage) = $result->fields;

    if (!authorised(0, 'Ephemerids::', "$content::$eid", ACCESS_EDIT)) {
        echo _EPHEMEDITNOAUTH;
        include "footer.php";
        return;
    }

    OpenTable();
    echo "<center><font size=4><b>"._EPHEMEDIT."</b></font></center><br>"
    ."<form action=\"admin.php\" method=\"post\">"
    ."<b>"._YEAR.":</b> <input type=\"text\" name=\"yid\" value=\"$yid\" maxlength=\"4\" size=\"5\"><br><br>"
        .'<b>'._LANGUAGE.': </b>' /* ML Added drop down to select one of the available languages, currentlang is pre-selected */
        .'<select name="elanguage" size="1">'   /* we could also set admlanguage (admin) to be default selected instead of currentlang */
    ;
    $lang = languagelist();
    if (!$elanguage)
    {
        $sel_lang[0] = ' selected';
    } else {
        $sel_lang[$elanguage] = ' selected';
    }
    print "<option value=\"\" $sel_lang[0]>"._ALL.'</option>';
    $handle = opendir('language');
    while ($f = readdir($handle))
    {
        if (is_dir("language/$f") && $lang[$f])
        {
            $langlist[$f] = $lang[$f];
        }
    }
    asort($langlist);
    foreach ($langlist as $k=>$v)
    {
        print "<option value=\"$k\"$sel_lang[$k]>$v</option>\n";
    }
    print '</select><br><br>' /* ML END */
    ."<b>"._EPHEMDESC."</b><br>"
    ."<textarea name=\"content\" cols=\"60\" rows=\"10\">$content</textarea><br><br>"
    ."<input type=\"hidden\" name=\"did\" value=\"$did\">"
    ."<input type=\"hidden\" name=\"mid\" value=\"$mid\">"
    ."<input type=\"hidden\" name=\"eid\" value=\"$eid\">"
    ."<input type=\"hidden\" name=\"op\" value=\"Ephemeridschange\">"
    ."<input type=\"submit\" value=\""._SAVECHANGES."\">"
    ."</form>";
    CloseTable();
    include ('footer.php');
}

function Ephemeridschange($eid, $did, $mid, $yid, $content, $elanguage) {
    global $pntable, $dbconn;

    csrfcheck();

    $content = stripslashes(FixQuotes($content));
    $column = &$pntable['ephem_column'];

    $result = $dbconn->Execute("SELECT $column[content]
                              FROM $pntable[ephem]
                              WHERE $column[eid]=$eid");
    list($oldcontent) = $result->fields;
    $result->Close();

    if (!authorised(0, 'Ephemerids::', "$oldcontent::$eid", ACCESS_EDIT)) {
        include "header.php";
        GraphicAdmin($hlpfile);
        OpenTable();
        echo "<center><font class=\"pn-title\"><b>"._EPHEMADMIN."</b></font></center>";
        CloseTable();
        echo "<br>";
        echo _EPHEMEDITNOAUTH;
        include "footer.php";
        return;
    }

    $dbconn->Execute("UPDATE $pntable[ephem] SET $column[yid]='$yid', $column[content]='$content', $column[elanguage]='$elanguage' WHERE $column[eid]=$eid");

    pnRedirect('admin.php?op=Ephemerids');
}

if (!authorised(0, 'Ephemerids::', '::', ACCESS_EDIT)) {
    include "header.php";
    GraphicAdmin($hlpfile);
    OpenTable();
    echo "<center><font class=\"pn-title\"><b>"._EPHEMADMIN."</b></font></center>";
    CloseTable();
    echo "<br>";
    echo _EPHEMNOAUTH;
    include "footer.php";
} else {
    switch($op) {

        case "Ephemeridsedit":
            Ephemeridsedit($eid, $did, $mid);
            break;

        case "Ephemeridschange":
            Ephemeridschange($eid, $did, $mid, $yid, $content, $elanguage);
            break;

        case "Ephemeridsdel":
            Ephemeridsdel($eid, $did, $mid);
            break;

        case "Ephemeridsmaintenance":
            Ephemeridsmaintenance($did, $mid);
            break;

        case "Ephemeridsadd":
            Ephemeridsadd($did, $mid, $yid, $content, $elanguage);
            break;

        case "Ephemerids":
            Ephemerids();
            break;
    }
}

?>
Return current item: ProNuke. Postnuke To Oracle