<?php
//if not logged in and not admin redirect to login page.
if (!isset($_SESSION['user']) || $_SESSION['user']['isAdmin']==0) header('Location: index.php');
include("includes/header.php");
//$sValue = stripslashes( $_POST['message'] ) ;
include_once("ckeditor/ckeditor.php") ;
$edit = false;
echo '<h3>Welcome, '.$_SESSION['user']['Username'].'</h3>';
switch($_GET['action']){
case "add":
//check required fields
if (!check_req('add')){
//display error
echo Config::reqFields;
} else {
$notice = new Notice($_POST['subject'],$_POST['message']);
try{ $notice->addNotice($db,$_SESSION['user']['Username']);
$alert = "Notice was Posted";
unset($_POST);
} catch (Exception $e) {
$alert=$e->getMessage();
}
}
break;
case "update":
//check required fields
if (!check_req('add')){
//display error
echo Config::reqFields;
} else {
foreach($_SESSION['notices'] as $k=>$n){
if($n->noticeID == $_GET['id']){
try {
$n->setMessage($_POST['message']);
$n->subject = $_POST['subject'];
$n->updateNotice($db, $_SESSION['user']['Username']);
$alert = "Notice was updated";
} catch (Exception $e) {
$alert=$e->getMessage();
}
}
}
}
case "edit":
$id = $_GET['id'];
$edit = true;
//get all data (variables) to populate the form with the notice information being edited
foreach($_SESSION['notices'] as $k=>$n){
if($n->noticeID == $id){
$title = $n->subject;
$message = $n->getMessage();
}
}
break;
}
if (isset($alert))echo '<p class="info">'.$alert.'</p>';
?>
<h2>Post a Notice</h2>
<form action="addnotice.php?action=<?php if($edit) echo 'update&id='.$id; else echo 'add';?>" method="post" id="editForm">
<div><label>Title: </label><input class="text" type="text" name="subject" value="<?php if($edit)echo $title; else echo $_POST['subject'];?>" /></div>
<div><label>Message: </label><a class="help" href="http://docs.ckeditor.net/ckeditor_2.x/Users_Guide" target="_blank" >( help )</a><br />
<textarea name="message">
<?php
if(isset($id)) echo $message;//enter message data here
else if (isset($_POST['message'])) echo $_POST['message'];
else echo '<p>Enter your notice here. Use the features above to change font styles, add images, etc.<br />
Click the help link above for help with this editor.</p>' ;
?>
</textarea>
<script> $(function(){ $('textarea').fck({path: '/employees/ckeditor/'}); }); </script>
</div>
<div class="submit"><input type="submit" value="Update" class="submit" /></div>
</form>
<?php
include("includes/footer.php"); ?>]
Tue, 05/15/2012 - 22:04
#1
