<% /////////////////////////////////////////////////////////////////////////////// // File: index.php // Purpose: displays guestbook // Remarks: requires common.php /////////////////////////////////////////////////////////////////////////////// // Functions: // string query_string(int) // void page_num_links() // void display_openbook(array) // void display_conventional(array) /////////////////////////////////////////////////////////////////////////////// require("./common.php"); $start_time=get_microtime(); session_start(); /////////////////////////////////////////////////////////////////////////////// // Function: string query_string(int $page) // Purpose: determines query string for page links // Parameters: // $page - page to link to // Returns: query string // Global references: none /////////////////////////////////////////////////////////////////////////////// function query_string($page) { $query_string=$GLOBALS['QUERY_STRING']; if(ereg("page=.*",$GLOBALS['QUERY_STRING'])) { $query_string=ereg_replace("page=.*", "page=$page", $query_string); } else { $query_string.="&page=$page"; } return $query_string; }// end query_string() /////////////////////////////////////////////////////////////////////////////// // Function: void page_num_links() // Purpose: page-spanning; displays page-numbered links // Parameters: none // Returns: nothing // Global references: // $PHP_SELF // $current_page - page number of current page // $total_num_pages - total number of pages /////////////////////////////////////////////////////////////////////////////// function page_num_links() { global $PHP_SELF; global $HTTP_GET_VARS; global $current_page; global $total_num_pages; echo "Page: "; if($current_page > 1) // not on 1st page so display links to 1st and previous pages { $prev_page=$current_page-1; echo "[ First ]"; echo "[ < ]"; } else { echo "[ First ]"; echo "[ < ]"; } /* page-numbered links code segment */ $start=$current_page-4; // 1st page link to display if($start < 1) { $start=1; } $end=$current_page+4; // last page link to display if($end > $total_num_pages) { $end=$total_num_pages; } for($pg=$start; $pg <= $end; $pg++) { if($pg == $current_page) // do not create hyperlink for current page { echo "[ $pg ] "; } else // create hyperlink to page $pg { echo "[ $pg ] "; } } /* END of page-numbered links code segment */ if($current_page < $total_num_pages) // not on last page so display links to last and next pages { $next_page=$current_page+1; echo "[ > ]"; echo "[ Last ]"; } else { echo "[ > ]"; echo "[ Last ]"; } }// end page_num_links() /////////////////////////////////////////////////////////////////////////////// // Function: void display_openbook(array $post) // Purpose: displays guestbook entry in $post; OpenBook style // Parameters: // $post - array containing details of guestbook entry // Returns: nothing // Global references: // $HTTP_SESSION_VARS // $HTTP_GET_VARS // Remarks: modify the HTML to suit your taste /////////////////////////////////////////////////////////////////////////////// function display_openbook($post) { global $HTTP_SESSION_VARS; global $HTTP_GET_VARS; if(empty($HTTP_GET_VARS['page'])) { $HTTP_GET_VARS['page']=1; } %> <% if(isset($HTTP_SESSION_VARS['admin_name'])) // user is administrator; display edit and delete entry options { %> <% } %>
Name Email Date posted
<%=stripslashes($post['username'])%> <% if($post['useremail']) echo "".$post['useremail'].""; else echo "withheld"; %> <% echo $post['date']; %>
<% if($post['subject']) echo stripslashes($post['subject']); else echo "Guestbook Entry" %>
<%=wordwrap(stripslashes(nl2br($post['message'])),50,"\n",1)%>
<% if(isset($post['reply'])) if($post['reply']) echo "Reply:
", wordwrap(stripslashes(nl2br($post['reply'])),50,"\n",1); %>
Edit Entry / Reply
<% }// end display_openbook() /////////////////////////////////////////////////////////////////////////////// // Function: void display_conventional(array $post) // Purpose: displays guestbook entry in $post; conventional guestbook style // Parameters: // $post - array containing details of guestbook entry // Returns: nothing // Global references: // $HTTP_SESSION_VARS // $HTTP_GET_VARS // Remarks: modify the HTML to suit your taste /////////////////////////////////////////////////////////////////////////////// function display_conventional($post) { global $HTTP_SESSION_VARS; global $HTTP_GET_VARS; if(empty($HTTP_GET_VARS['page'])) { $HTTP_GET_VARS['page']=1; } %> <% if(isset($HTTP_SESSION_VARS['admin_name'])) // display edit and delete entry options if user is administrator { %> <% } %>
Author Message
<%=stripslashes($post['username'])%>


<% if($post['useremail']) echo ""; %> <% if($post['homepage']) echo ""; %>
Posted: <%=$post['date']%>
<% if($post['subject']) echo stripslashes($post['subject']); else echo "Guestbook Entry" %>
<%=wordwrap(stripslashes(nl2br($post['message'])),50,"\n",1)%>

<% if(isset($post['reply'])) if($post['reply']) echo "
Reply:
", wordwrap(stripslashes(nl2br($post['reply'])),50,"\n",1); %>
Edit Entry / Reply
<% }// end display_conventional() /////////////////////////////////////////////////////////////////////////////// // script main /////////////////////////////////////////////////////////////////////////////// pageheader(); db_connect(); // retrieve total number of entries $query="SELECT count(*) AS total_entries FROM $posts_table"; $result=mysql_query($query); $row=mysql_fetch_array($result); $total_entries=$row['total_entries']; // total number of guestbook entries // calculate total number of pages $total_num_pages=ceil($total_entries/$OB_entries_per_page); if(isset($HTTP_GET_VARS['page'])) { if($HTTP_GET_VARS['page'] > 0 && $HTTP_GET_VARS['page'] <= $total_num_pages) // incorrect page requested; default to 1st page { $current_page=$HTTP_GET_VARS['page']; } else { $current_page=1; } } else // if no page value was passed, show the 1st page by default { $current_page=1; } // retrieve guestbook entries from db // Note: if you want to show the time use date_format(postdate,'%D %b %Y %r') instead $query="SELECT entryid,username,useremail,homepage,subject,message,date_format(postdate,'%D %b %Y') AS date,reply " ."FROM $posts_table " ."WHERE approved=1 " ."ORDER BY entryid DESC " ."LIMIT ".($current_page - 1) * $OB_entries_per_page.",".$OB_entries_per_page; $result=mysql_query($query); %>

Mosquito Association Guestbook

<% if(isset($HTTP_SESSION_VARS['admin_name'])) // if session variable $admin_name exists, then user is administrator { echo "Welcome to your guestbook ", $HTTP_SESSION_VARS['admin_name'], "!\n"; echo "
[Logout]
\n"; } %>
[Sign my guestbook]
Total number of entries: <%=$total_entries%>. <% page_num_links(); %>

<% if(@mysql_num_rows($result) == 0) // no entries in guestbook { echo "Your guestbook is empty!

\n"; } else // display each entry stored in db { $draw_hr=false; // to indicate whether to draw
// display guestbook entries while($post=mysql_fetch_array($result)) { if($draw_hr) echo "
\n"; // draw horizontal line separator $display_function="display_".$OB_display_type; $display_function($post); // dynamically call function to display guestbook entries $draw_hr=true; } } %>
Total number of entries: <%=$total_entries%>. <% page_num_links(); %>
[Sign my guestbook] | [Admin panel] (restricted)

<% /* $stop_time=get_microtime(); $exec_time=$stop_time - $start_time; echo "
\n"; echo "This page was generated in $exec_time seconds."; echo "
\n"; */ pagefooter(); %>