<?
require_once("functions.php");
global $action,$userinfo;
chkuserlogin($userinfo);
$userinfo['userlevel']=1;
$table="announcements";
fheader();
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="includes/styles.css" rel="stylesheet" type="text/css">
<table width="757" border="0" align="center" cellpadding="4" bordercolor="#333333" bgcolor="#FFFFFF" class="default">
<tr>
<td align="center" bgcolor="#999999">
<font color="#FFFFFF" size="4"><b>Announcement
Maintenance</b></font>
</td>
</tr>
<?
function flist() {
global $action,$url,$table,$sql,$recperpage,$search,$navinfo,$userinfo,$recperpage,$search;
$searchfor = initobj("searchfor");
$searchvalue = initobj("searchvalue");
$arrsearch = Array("Announcement"=>"announcement");
$condition = ($searchfor!="") ? "where $searchfor like '%$searchvalue%'" : "";
$sql = "select * from $table $condition";
?>
<tr>
<td align="center" valign="top">
<table width="100%" cellpadding="4" cellspacing="2" class="default">
<tr>
<td colspan="2" align="center">
<table width="100%" border="1" cellpadding="1" cellspacing="0" class="default">
<tr>
<td align="center" valign="middle" bgcolor="#CCCCCC">
<input type="button" name="add" value="Add Item" onclick="location='<?=$url?>?action=formadd&uid=0'" />
<input type="button" name="listall" value="List All" onclick="location='<?=$url?>'" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<table width="100%" border="1" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF" class="default">
<tr>
<td width="100%">
<table width="100%" border="0" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF" class="default">
<form name="frm" method="post" action="<?=$url?>">
<tr>
<td width="100%" colspan="3">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="default">
<tr>
<td width="15%">
Search
</td>
<td width="7%" align="left">
<select name="searchfor">
<? foreach ($arrsearch as $key=>$value) {
if ($searchfor==$value) {
$tag = "selected";
$search = $key;
} else
$tag = "";
?>
<option value="<?=$value?>" <?=$tag?>>
<?=$key?>
</option>
<? } ?>
</select>
</td>
<td width="51%" align="left">
<b> =</b>
<input type="text" name="searchvalue" size="12" />
<input type="submit" name="Submit" value="Submit" />
<input type="hidden" name="action" value="list" />
</td>
<td width="27%" align="right">
</td>
</tr>
</table>
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<table width="100%" cellpadding="3" cellspacing="1" class="default">
<?
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if (is_array($row)) {
?>
<tr>
<td width="7%" height="17" align="left" bgcolor="#CCCCCC">
<b>ID</b>
</td>
<td width="37%" height="17" align="left" bgcolor="#CCCCCC">
<b>Announcement</b>
</td>
<td width="56%" height="17" bgcolor="#CCCCCC">
</td>
</tr>
<?
$ct = 0;
do {
$id = $row['id'];
$announcement = $row['announcement'];
$ct++;
if ($ct % 2 == 0)
$bgcolor = "white";
else
$bgcolor = "";
?>
<tr bgcolor="<?=$bgcolor?>">
<td width="7%">
<?=$id?>
</td>
<td width="37%">
<a href="<?=$url?>?action=formedit&uid=<?=$id?>"><u>
<?=$announcement?>
</u></a>
</td>
<td width="56%" align="left">
<? if ($userinfo['userlevel']==1) { ?>
<u><a href="<?=$url?>?action=delete&uid=<?=$id?>" title="Delete ID# <?=$id?>" onClick="return confirm('You cannot undo this operation!\nDo you wish to delete this record?')" ><u><font color="#FF0000">Delete</font></u></a></u>
<? } ?>
</td>
</tr>
<?
} while ($row = mysql_fetch_array($result));
} else {
?>
<tr>
<td colspan="3">
<font color="#0000FF">No record is available. </font>
</td>
</tr>
<? } ?>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<table width="100%" border="1" cellpadding="1" cellspacing="0" class="default">
<tr>
<td align="center" valign="middle" bgcolor="#CCCCCC">
<input type="button" name="add" value="Add Item" onclick="location='<?=$url?>?action=formadd&uid=0'" />
<input type="button" name="listall" value="List All" onclick="location='<?=$url?>'" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<?
}
function fform() {
global $userinfo,$table,$uid,$url,$ptr,$id,$announcement,$link;
if ($uid != 0) {
$sql = "select * from $table where id=$uid";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$id = $row['id'];
$announcement = $row['announcement'];
$action = "saveedit";
$label = "UPDATE RECORD";
} else {
$action = "saveadd";
$label = "ADD RECORD";
}
?>
<tr>
<td align="center" valign="top">
<table width="80%" cellpadding="5" cellspacing="2" class="default">
<tr>
<td colspan="2" align="center">
<table width="70%" border="1" cellpadding="3" cellspacing="0" class="default">
<tr>
<td align="center" valign="middle">
<table width="100%" cellpadding="4" cellspacing="0" class="default">
<form name="frm" method="post" action="<?=$url?>" onSubmit="return checkrequired(this)">
<tr align="center" bgcolor="#CCCCCC">
<td height="30" colspan="2" bgcolor="#CCCCCC">
<b><font size="2">
<?=$label?>
</font></b>
</td>
</tr>
<tr>
<td width="29%" align="right">
<b>Announcement</b>
</td>
<td width="71%">
<input name="_announcement" type="text" id="_announcement" value="<?=$announcement?>" size="30">
</td>
</tr>
<tr align="center">
<td colspan="2" bgcolor="#CCCCCC">
<? if ($userinfo['userlevel']==1 || $userinfo['userlevel']==2) { ?>
<input type="submit" name="Submit" value="Submit">
<? } ?>
<input type="button" name="Back" value="< Back" onclick="location=''">
<input type="hidden" name="action" value="<?=$action?>">
<input type="hidden" name="id" value="<?=$id?>">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<?
}
function fsave() {
global $action,$table,$ptr;
$id = initobj("id");
$announcement = initobj("_announcement");
$link = initobj("_link");
if ($action=="saveadd") {
$row = fetcharray("select * from $table where announcement='$announcement'");
if (!is_array($row)) {
$sql = "insert into announcements (announcement) values ";
$sql.= "('$announcement')";
mysql_query($sql);
}
} elseif ($action=="saveedit") {
$sql = "update announcements set announcement='$announcement' ";
$sql.= "where id=$id";
mysql_query($sql);
}
flist();
}
function fdelete() {
global $table,$uid;
mysql_query("delete from $table where id=$uid");
flist();
}
switch ($action)
{
case "formadd":
fform();
break;
case "formedit":
fform();
break;
case "saveadd":
fsave();
break;
case "saveedit":
fsave();
break;
case "delete":
fdelete();
break;
default:
flist();
break;
}
?>
</table>
<? ffooter() ?>