Go Back   Free website templates > Web Template Help > PHP and MySQL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Join now to download all the free website templates or post on the forum. If you have never been on a forum before read the FAQ. It's quick, easy and free to join!
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-15-2008, 10:58 AM
vareside's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 254
vareside is on a distinguished road
Post Guestbook Customization

Hi folks,

for another time I need the help and support of the united knowledge of all of you guys. I have a guestbook php script but I need to change a few things. I do not know how to do this. Can someone customize the script-part below:

PHP Code:
<?php 
class maxGuestbook
   var 
$messageDir 'messages'
   var 
$dateFormat 'Y-m-d g:i:s A'
   var 
$itemsPerPage 10
   var 
$messageList
    
function 
processGuestbook(){ 
   if (isset(
$_POST['submit'])) { 
      
$this->insertMessage(); 
   } 
   
$page = isset($_GET['page']) ? $_GET['page'] : 1
    
   
$this->displayGuestbook($page); 

    
function 
getMessageList(){ 
     
   
$this->messageList = array(); 
    
    
// Open the actual directory 
    
if ($handle = @opendir($this->messageDir)) { 
        
// Read all file from the actual directory 
        
while ($file readdir($handle))  { 
            if (!
is_dir($file)) { 
               
$this->messageList[] = $file
          } 
        } 
    }     
     
    
rsort($this->messageList); 
     
    return 
$this->messageList
}    

function 
displayGuestbook($page=1){ 
      
$list $this->getMessageList(); 
      
//echo "<center><a href='add.php'>Leave a message</a></center>"; 
      
echo "<table class='newsList'>"
       
      
//Get start point and end point 
      
$startItem = ($page-1)*$this->itemsPerPage
      if ((
$startItem $this->itemsPerPage) > sizeof($list)) $endItem sizeof($list); 
      else 
$endItem $startItem $this->itemsPerPage;  
       
      for (
$i=$startItem;$i<$endItem;$i++){ 
         
//foreach ($list as $value) { 
         
$value $list[$i]; 
          
$data file($this->messageDir.DIRECTORY_SEPARATOR.$value); 
          
$name  trim($data[0]); 
          
$email trim($data[1]); 
         
$submitDate trim($data[2]);     
         unset (
$data['0']); 
         unset (
$data['1']); 
         unset (
$data['2']); 
           
         
$content ""
         foreach (
$data as $value) { 
               
$content .= $value
         } 
           
          echo 
"<tr><th align='left'><a href=\"mailto:$email\">$name</a></th> 
                    <th class='right'>$submitDate</th></tr>"

          echo 
"<tr><td colspan='2'>".nl2br(htmlspecialchars($content))."<br/></td></tr>"
      } 
      echo 
"</table>"
      if (
sizeof($list) == 0){ 
         echo 
"<center><p>No messages at the moment!</p><p>&nbsp;</p></center>"
      } 
      
// Create pagination 
      
if (sizeof($list) > $this->itemsPerPage){ 
         echo 
"<div id=\"navigation\">"
         if (
$startItem == 0) { 
            if (
$endItem sizeof($list)){ 
               echo 
"<div id=\"nright\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Next &raquo;</a></div>"
            } else { 
               
// Nothing to display 
            

         } else { 
            if (
$endItem sizeof($list)){ 
               echo 
"<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Prev</a></div>"
               echo 
"<div id=\"nright\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Next &raquo;</a></div>"
            } else { 
               echo 
"<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Prev</a></div>"
            } 
         } 
          
         echo 
"<br/></div><br/>"
      } 
      echo 
"<hr />"
      
$this->displayAddForm(); 


function 
displayAddForm(){ 
?>   
  <form class="iform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
    Name:<br/> 
    <input type="text" name="name" size="30"/><br/><br/> 
    Email:<br/> 
    <input type="text" name="email" size="30"/><br/><br/> 
    Your message:<br/> 
    <textarea name="message" rows="7" cols="49"></textarea><br/> 
    <center><input type="submit" name="submit" value="Save" /></center> 
  </form>  
    
<?php    


function 
insertMessage(){ 
   
$name   = isset($_POST['name']) ? $_POST['name'] : 'Anonymous'
   
$email  = isset($_POST['email']) ? $_POST['email'] : ''
   
$submitDate  date($this->dateFormat); 
   
$content = isset($_POST['message']) ? $_POST['message'] : ''
    
   if (
trim($name) == ''$name 'Anonymous'
   if (
strlen($content)<5) { 
      exit(); 
   } 
    
   
$filename date('YmdHis'); 
   if (!
file_exists($this->messageDir)){ 
      
mkdir($this->messageDir); 
   } 
   
$f fopen($this->messageDir.DIRECTORY_SEPARATOR.$filename.".txt","w+");          
   
fwrite($f,$name."\n"); 
   
fwrite($f,$email."\n"); 
   
fwrite($f,$submitDate."\n"); 
   
fwrite($f,$content."\n"); 
   
fclose($f); 
    


?>
I want users to submit a URL and a description for the website into the message-field. Nothing else! Could anyone edit it?

Best regards,
Max

Last edited by vareside; 08-15-2008 at 11:52 AM.
Reply With Quote
  #2 (permalink)  
Old 08-15-2008, 12:02 PM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,360
ishkey will become famous soon enough
Default You could get spammed to death

max - You must have gotten my brain dead sickness, that I had last week.

PHP Code:
<?php
/**
 * edited code
 * 
 * somethings commited out 
 * somethings deleted
 */
?>
<?php
class maxGuestbook{
   var 
$messageDir 'messages';
 
/*  var $dateFormat = 'Y-m-d g:i:s A'; */
   
var $itemsPerPage 5;
   var 
$messageList;
 
function 
processGuestbook(){
   if (isset(
$_POST['submit'])) {
      
$this->insertMessage();
   }
   
$page = isset($_GET['page']) ? $_GET['page'] : 1;
 
   
$this->displayGuestbook($page);
}
 
function 
getMessageList(){
 
   
$this->messageList = array();
 
 
// Open the actual directory
 
if ($handle = @opendir($this->messageDir)) {
  
// Read all file from the actual directory
  
while ($file readdir($handle))  {
      if (!
is_dir($file)) {
         
$this->messageList[] = $file;
       }
  }
 } 
 
 
rsort($this->messageList);
 
 return 
$this->messageList;
}   
function 
displayGuestbook($page=1){
      
$list $this->getMessageList();
      
//echo "<center><a href='add.php'>Leave a Website Description</a></center>";
      
echo "<table class='newsList'>";
 
      
//Get start point and end point
      
$startItem = ($page-1)*$this->itemsPerPage;
      if ((
$startItem $this->itemsPerPage) > sizeof($list)) $endItem sizeof($list);
      else 
$endItem $startItem $this->itemsPerPage
 
      for (
$i=$startItem;$i<$endItem;$i++){
         
//foreach ($list as $value) {
         
$value $list[$i];
       
$data file($this->messageDir.DIRECTORY_SEPARATOR.$value);
       
$name  trim($data[0]);
        unset (
$data['0']);
 
         
$content "";
         foreach (
$data as $value) {
            
$content .= $value;
         }
 
       echo 
"<tr><th align='left'>$name</a></th></tr>";
       echo 
"<tr><td colspan='2'>".nl2br(htmlspecialchars($content))."<br/></td></tr>";
      }
      echo 
"</table>";
      if (
sizeof($list) == 0){
         echo 
"<center><p>No messages at the moment!</p><p>&nbsp;</p></center>";
      }
      
// Create pagination
      
if (sizeof($list) > $this->itemsPerPage){
         echo 
"<div id=\"navigation\">";
         if (
$startItem == 0) {
            if (
$endItem sizeof($list)){
               echo 
"<div id=\"nright\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Next &raquo;</a></div>";
            } else {
               
// Nothing to display
            
}
         } else {
            if (
$endItem sizeof($list)){
               echo 
"<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Prev</a></div>";
               echo 
"<div id=\"nright\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\" >Next &raquo;</a></div>";
            } else {
               echo 
"<div id=\"nleft\"><a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\" >&laquo; Prev</a></div>";
            }
         }
 
         echo 
"<br/></div><br/>";
      }
      echo 
"<hr />";
      
$this->displayAddForm();
}
function 
displayAddForm(){
?>  
  <form class="iform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Website Name:<br/>
    <input type="text" name="name" size="30"/><br/><br/>
    Website Description:<br/>
    <textarea name="message" rows="7" cols="49"></textarea><br/>
    <center><input type="submit" name="submit" value="Save" /></center>
  </form> 
 
<?php   
}
function 
insertMessage(){
   
$name   = isset($_POST['name']) ? $_POST['name'] : 'Anonymous';
/*   $email  = isset($_POST['email']) ? $_POST['email'] : '';
   $submitDate  = date($this->dateFormat); */
   
$content = isset($_POST['message']) ? $_POST['message'] : '';
 
   if (
trim($name) == ''$name 'Anonymous';
   if (
strlen($content)<5) {
      exit();
   }
 
   
$filename date('YmdHis');
   if (!
file_exists($this->messageDir)){
      
mkdir($this->messageDir);
   }
   
$f fopen($this->messageDir.DIRECTORY_SEPARATOR.$filename.".txt","w+");         
   
fwrite($f,$name."\n");
/*   fwrite($f,$email."\n");
   fwrite($f,$submitDate."\n"); */
   
fwrite($f,$content."\n");
   
fclose($f);
 
}
}
?>
__________________
RIF= Reading Is Fun - Understanding Funner
cleandeck - lawn mower undercoating and wilmargraphite - graphite lubricants
Reply With Quote
  #3 (permalink)  
Old 08-15-2008, 12:12 PM
vareside's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 254
vareside is on a distinguished road
Default

But I ment it that way:
1st field: Website Name
2nd field: URL
3rd field: Description

The name should be displayed as a link! And below that, the desc.
Reply With Quote
  #4 (permalink)  
Old 08-15-2008, 12:43 PM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,360
ishkey will become famous soon enough
Default

Have I lost my mind?
I saw a post which said
I only want the web address and description not the name, date or email......
__________________
RIF= Reading Is Fun - Understanding Funner
cleandeck - lawn mower undercoating and wilmargraphite - graphite lubricants
Reply With Quote
  #5 (permalink)  
Old 08-15-2008, 12:45 PM
vareside's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 254
vareside is on a distinguished road
Default

Yes, because you came up with website name!

So, how to do it?
Reply With Quote
  #6 (permalink)  
Old 08-15-2008, 01:04 PM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,360
ishkey will become famous soon enough
Default

Well it would be the first time I've lost it.
Now you have two files to compare and should be able to code like you want.

put this and the rest of the code for it back in
echo "<tr><th align='left'><a href=\"<A href="mailto:$email\">$name</a></th">mailto:$email\">$name</a></th> "old code"
and edit the mailto so it's linkable.

add the second field code
edit the style.css file
should work.
Gotta go work calls.
__________________
RIF= Reading Is Fun - Understanding Funner
cleandeck - lawn mower undercoating and wilmargraphite - graphite lubricants
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:56 AM.



mouseover mouseover mouseover