Page 1 of 1

Out of Office Message Board on my Intrant Home Page

Posted: Wed Feb 13, 2008 11:58 am
by Zero20two
I am a new php programmer. I am running Sharepoint services for my Intranet but I am designing a new Intranet site. The main function is a message board on our home page that people can post on. Here are the needed fields and functions:

Name
Message
Date Added
Date the message expires - Auto delete itself.

When someone adds a message, it needs to look nice and not take up much space. Is there something already out there or can someone point ,me in the right direction? I have looked at bulliten boards and message boards but that is not helpful. Thanks!

Re: Out of Office Message Board on my Intrant Home Page

Posted: Wed Feb 13, 2008 2:29 pm
by Jonah Bron
UT (un-tested)

Code: Select all

<?php
$xml = new DOMDocument();
$xml->load('posts.xml');
$xml->formatOutput = true;
if (isset($_POST['post'])){
$info['name'] = $_POST['name'];
$info['text'] = $_POST['text'];
$info['title'] = $_POST['title'];
$info['date'] = date('l, d F, y H:i:s');
$info['exp']['date'] = $_POST['d'] .' '. $_POST['m'] .', '. $_POST['y'];
$info['exp']['stamp'] = strtotime($info['exp']['date']);
$new_post = $xml->createElement('post', $info['text']);
$name_attr = $xml->createAttribute('poster');
$title_attr = $xml->createAttribute('title');
$date_attr = $xml->createAttribute('date');
$exp_d_attr = $xml->createAttribute('exp-d');
$exp_s_attr = $xml->createAttribute('exp-s');
$name_attr->appendChild($xml->createTextNode($info['name']));
$title_attr->appendChild($xml->createTextNode($info['title']));
$date_attr->appendChild($xml->createTextNode($info['date']));
$exp_d_attr->appendChild($xml->createTextNode($info['exp']['date']));
$exp_s_attr->appendChild($xml->createTextNode($info['exp']['stamp']));
$new_post->appendChild($name_attr);
$new_post->appendChild($title_attr);
$new_post->appendChild($date_attr);
$new_post->appendChild($exp_d_attr);
$new_post->appendChild($exp_s_attr);
$xml->save('posts.xml');
}
$xml->load('posts.xml');
$posts = array();
foreach ($xml->documentElement->getElementsByTagName('post') as $x_post){
$post = array();
$post['poster'] = $x_post->getAttribute('poster');
$post['text'] = $x_post->nodeValue;
$post['title'] = $x_post->getAttribute('title');
$post['date'] = $x_post->getAttribute('date');
$post['exp-d'] = $x_post->getAttribute('exp-d');
$post['exp-s'] = $x_post->getAttribute('exp-s');
if ($post['exp-s'] < time()){
$xml->documentElement->removeChild($x_post);
}else{
$posts[count($posts)] = $post;
}
}
$xml->save('posts.xml');
?>

Code: Select all

<html>
<head>
<title>Posts</title>
</head>
<body>
<form action="this_page.php" method="post">
<input type="hidden" name="post" value="" />
<input type="text" name="name" value="your name" /><br />
<input type="text" name="title" value="Title" /><br />
<textarea name="text">Your post here</textarea><br />
<input type="text" name="d" value="day" /><br />
<input type="text" name="m" value="month" /><br />
<input type="text" name="y" value="2008" /><br />
<input type="submit" value="Post" />
</form>

Code: Select all

<?php
$posts = array_reverse($posts);
foreach ($posts as $post){
echo '<div><strong>'. $post['title'] .'</strong> by '. $post['poster'] .' on '. $post['date'] .', expires '. $post['exp-d'] .'
<p>'. $post['text'] .'</p></div>
';
}
?>

Code: Select all

</body>
</html>

Re: Out of Office Message Board on my Intrant Home Page

Posted: Wed Feb 13, 2008 2:42 pm
by Zero20two
This is a great start! I am very new to xml though. Does all of this code go into the same page? Where does the post.xml come from? Can you give me a little more guidance? Thank you!

Re: Out of Office Message Board on my Intrant Home Page

Posted: Wed Feb 13, 2008 3:02 pm
by Zero20two
I created an xml doc called posts.xml and placed the <?xml version="1.0"?> tag in it.
Now I get an error:
Warning: DOMDocument::load() [function.DOMDocument-load]: Start tag expected, '<' not found in file:///C%3A/Program%20Files/Apache%20Software%20Foundation/Apache2.2/htdocs/posts.xml, line: 2 in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\addannounce.php on line 3

Any ideas?