Location: PHPKode > projects > Slashster > slashster/html/newsadmin.php
<?

# Slashster: Open Source Friend of a Friend Software
# Copyright 2004 Mark El-Wakil
# Contact: hide@address.com
# http://seventhcycle.net
#
# This file is part of Slashster.
#
# Slashster 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, or
# (at your option) any later version.
#
# Slashster 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.
#
# You should have received a copy of the GNU General Public License
# along with Slashster; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


   import_request_variables("gPc");

   require("PageClass.php");
   $mpage = new PageClass();

   if (!$mpage->Admin)
   {
     echo "You must be an admin to submit news";
     $mpage->ClosePage();
   }

   $oplst = array("sub", "lst", "rem");
   $op = (in_array($op, $oplst)) ? $op : "lst";

   $oparr = array();

   $oparr[lst] = "Edit";
   $oparr[rem] = "Remove";


   if ($op == "sub")
   {
      if ($submit)
      {
         $sql = "insert into UpdateTable
                 set Title=\"$title\", Txt=\"$txt\", Date=NOW(), Submittee=$mpage->IdNum";

         $mpage->DoQuery($sql);
      }

      SubmitForm();
   }
   elseif ($op == "rem")
   {
      if ($id)
      {
         $sql = "delete from UpdateTable where Id = \"$id\" ";
         $mpage->DoQuery($sql);
      }

      ListEntries();
   }

   elseif ($op == "lst")
   {
      if ($submit)
      {
         $sql = "update UpdateTable 
                 set Title = \"$title\", Txt = \"$txt\" where Id = \"$id\" ";

         $mpage->DoQuery($sql);
      }

      if ($id)
      {
         EditForm($id);
      }
      else
      {
         ListEntries();
      }
   }

   $mpage->ClosePage();

function ListEntries()
{
   global $mpage;
   global $oparr;
   global $op;

   $sql = "select * from UpdateTable order by Id desc";
   $r = $mpage->DoQuery($sql,1);
?>  

<BR>
   <table width=600 align=center><tr><td>

<span class="title1"><?= $oparr[$op] ?> News Updates</span>

<? Menu() ?>

<ul>
<?
   foreach ($r as $s)
   { ?>
<li><a href="newsadmin.php?op=<?= $op ?>&id=<?= $s[Id] ?>"><?= $s[Title] ?></a>
   <? } 
?>
</ul>

   </td></tr></table>

<?
}

function Menu()
{ ?>

<BR><small>
[<a href="newsadmin.php?op=sub">Submit New News</a>] |
[<a href="newsadmin.php?op=lst">Edit News Update</a>] |
[<a href="newsadmin.php?op=rem">Remove News Update</a>]
</small>

<? }

function Submitted()
{ ?>

<BR>
<table border=4 bordercolor=red cellspacing=0 cellpadding=5px>
<tr><td style="font: bold 16px arial; color:red;">
Thank You
</td></tr>
</table>  

<? }

function SubmitForm()
{ ?>

   <BR>

<form method = "POST">

<table align=center width=600><tr><td>

<span class = "title1"> Submit News </span>
<? Menu() ?>

<BR>
<? if ($_POST[submit]) Submitted(); ?>


<BR>Title<BR>
<input type = "text" name = "title">

<BR><br>Update Text<br>

<textarea name = "txt" rows=15 cols=70 wrap="soft">
</textarea>

<input type = "submit" name = "submit" value = "Submit" class="submit">

</td></tr></table>

</form>

<?
}


function EditForm($id)
{ 
   global $mpage;

   $sql = "select * from UpdateTable where Id = \"$id\" ";
   $r = $mpage->DoQuery($sql,1);

   if (!sizeof($r)) $mpage-ClosePage();

   $r = $r[0];

?>
   <BR>

<form method = "POST">

<table align=center width=600><tr><td>

<span class = "title1"> Edit News Item</span>
<? Menu() ?>

<BR>
<? if ($_POST[submit]) Submitted(); ?>


<BR>Title<BR>
<input type = "text" name = "title" value="<?= htmlentities($r[Title]) ?>">

<BR><br>Update Text<br>

<textarea name = "txt" rows=15 cols=70 wrap="soft">
<?= htmlentities($r[Txt]) ?>
</textarea>

<input type = "submit" name = "submit" value = "Submit" class="submit">

</td></tr></table>

</form>

<?
}


?>
Return current item: Slashster