Location: PHPKode > projects > GeBlog > v.1/mod/News/admin/func.inc.php
<?php
// ----------------------------------------------------------------------
// GeBlog - Weblogging system
// Copyright (C) 2003 by the GeBlog Development Team.
// http://www.jaytalbot.com/
// ----------------------------------------------------------------------
// 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: Jay Talbot
// Purpose of file: To house the functions for admin script to the
//                  blog/news module.
// ----------------------------------------------------------------------

if (eregi("func.inc.php", $_SERVER['PHP_SELF']))
{
    die ("You can't access this file directly...");
}

function NewEntryProcess()
{
    extract($GLOBALS);
    extract($_POST);
    $conn->Connect($dbserver,$dbuser,$dbpass,$dbname);
    $sql = "INSERT INTO blog ( date , title , entry , mood , music ) VALUES ('".$time."', '".$title."', '".$story."', '".$mood."', '".$music."')";
    $rs = &$conn->Execute($sql);
    if (!$rs) die($conn->ErrorMsg());
    echo "Entry '".$title."' added successfully.";
}

function NewEntryForm()
{
    echo "<html>";
    echo "<head><title>Add an entry!</title></head>";
    echo "<body>";

    echo "<form method=post action=\"".$_SERVER['REQUEST_URI']."\">";

    echo "Title:<br>";
    echo "<input type=text name=\"title\"><br>";
    echo "Entry:<br>";
    echo "<textarea name=\"story\" rows=10 cols=60></textarea><br>";
    //echo "Mood:<br>";
    //echo "<input type=text name=\"mood\"><br>";
    //echo "Music:<br>";
    //echo "<input type=text name=\"music\"><br>";

    echo "<input type=submit name=\"submit\" value=\"Add Entry\">";
    echo "</form>";
    echo "</body>";
    echo "</html>";
}

function GetEntryInfo()
{
    extract($GLOBALS);
    extract($_GET);
    $sql = "SELECT id,DATE_FORMAT(date, '%m/%d/%Y %l:%i%p'),title,entry,mood,music FROM blog WHERE id=".$aid;
    $rs = $conn->Execute($sql);
    if (!$rs) die($conn->ErrorMsg());
    $entry['id']     = $rs->fields[0];
    $entry['edate']  = $rs->fields[1];
    $entry['btitle'] = $rs->fields[2];
    $entry['story']  = $rs->fields[3];
    $entry['mood']   = $rs->fields[4];
    $entry['music']  = $rs->fields[5];
    return $entry;
}

function EditEntryForm()
{
    GetEntryInfo();
    extract($entry);
    echo "<html>";
    echo "<head><title>Add an entry!</title></head>";
    echo "<body>";

    echo "<form method=post action=\"".$_SERVER['REQUEST_URI']."\">";

    echo "Title:<br>";
    echo "<input type=text name=\"title\" value=\"".$btitle."\"><br>";
    echo "Entry:<br>";
    echo "<textarea name=\"story\" value=\"".$story."\" rows=10 cols=60></textarea><br>";
    //echo "Mood:<br>";
    //echo "<input type=text name=\"mood\"><br>";
    //echo "Music:<br>";
    //echo "<input type=text name=\"music\"><br>";
    echo "<input type=hidden name=\"id\" value=\"".$id."\">";
    echo "<input type=hidden name=\"update\" value=\"1\">";
    echo "<input type=submit name=\"submit\" value=\"Update Entry\">";
    echo "</form>";
    echo "</body>";
    echo "</html>";
}

function UpdateEntry()
{
    extract($GLOBALS);
    extract($_GET);
    $sql = "UPDATE blog SET title=\"".$title."\",entry=\"".$story."\" WHERE id=".$id;
    $rs = $conn->Execute($sql);
    if (!$rs) die($conn->ErrorMsg());
    echo "Entry ".$title." has been updated!";
}

function GetEntryList()
{
    extract($GLOBALS);
    $sql = "SELECT id,DATE_FORMAT(date, '%m/%d/%Y %l:%i%p'),title,entry,mood,music FROM blog";
    $rs = &$conn->Execute($sql);
    if (!$rs) print $conn->ErrorMsg();
    echo "<TABLE WIDTH=\"60%\">\n";
    echo "<TR WIDTH=\"100%\">\n<TD WIDTH=\"10\">Date:</TD><TD>Subject:</TD></TR>\n";
    while(!$rs->EOF)
    {
        $entry['id']     = $rs->fields[0];
        $entry['edate']  = $rs->fields[1];
        $entry['btitle'] = $rs->fields[2];
        $entry['story']  = $rs->fields[3];
        $entry['mood']   = $rs->fields[4];
        $entry['music']  = $rs->fields[5];
        FormatEntryList($entry);
        $rs->MoveNext();
    }
    echo "</TABLE>\n";
}

function FormatEntryList($entry)
{
    extract($entry);
    $format = "<TR WIDTH=\"100%\"><TD WIDTH=\"10\">\n"
             .$edate."</TD>\n"
             ."<TD><a href=\"index.php?aid=".$id."\">".$btitle."</a>\n"
             ."</TD></TR>\n";
    echo $format;
}

function EntryMenu()
{
    $menu = "<TABLE WIDTH=\"50%\">\n"
           ."<TR><TD>\n"
           ."<a href=\"index.php?cmd=1\">List Entries</a>\n"
           ."</TD>\n"
           ."<TD>\n"
           ."<a href=\"index.php?cmd=2\">New Entry</a>\n"
           ."</TD></TR>\n"
           ."</TABLE>\n";
}

?>
Return current item: GeBlog