<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  require_once "/var/www/forrest.id.au/public_html/nutsDemo/lib/viewer_functions.php";

  list($blogg_commentsRecords, $blogg_commentsMetaData) = getRecords(array(
    'tableName'   => 'blogg_comments',
  ));

  list($blogRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $blogRecord = @$blogRecords[0]; // get first record

  // show error message if no matching record is found
  if (!$blogRecord) {
    print "Record not found!";
    exit;
  }
  
  // submit form
  if (@$_REQUEST['submit']) {

  // error checking
  $errorsAndAlerts = "";
  if (!@$_REQUEST['title'])    { $errorsAndAlerts .= "Please specify your name!<br/>\n"; }
  if (!@$_REQUEST['content'])  { $errorsAndAlerts .= "Please write a comment!<br/>\n"; }
  if (!@$_REQUEST['email'])                   { $errorsAndAlerts .= "Please enter your email!<br/>\n"; }
  else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts .= "Please enter a valid email (example: user@example.com)<br/>\n"; }

  // turn off strict mysql error checking for: STRICT_ALL_TABLES
  mysqlStrictMode(false); // disable Mysql strict errors for when a field isn't defined below (can be caused when fields are added later)

  // add record
  if (!@$errorsAndAlerts) {
    mysql_query("INSERT INTO `{$TABLE_PREFIX}blogg_comments` SET
                      title            = '".mysql_real_escape_string( $_REQUEST['title'] )."',
                      content          = '".mysql_real_escape_string( $_REQUEST['content'] )."',
                      email            = '".mysql_real_escape_string( $_REQUEST['email'] )."',

                      publish          = '0',
                      ref_table        = '',
                      ref_num          = '".mysql_real_escape_string( $_REQUEST['ref_num'] )."',

                      createdDate      = NOW(),
                      updatedDate      = NOW(),
                      createdByUserNum = '0',
                      updatedByUserNum = '0'")
    or die("MySQL Error Creating Record:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
    $recordNum = mysql_insert_id();

    // display thanks message and clear form
    $errorsAndAlerts = "Thanks, we've added that record!";
    $_REQUEST = array();
  }

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<meta name="Description" content="Nuts and Bolts is a content management system by Toldeoh Enterprises" />
<meta name="Keywords" content="toledoh, cms, admin" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Robots" content="index,follow" />

<title>Nuts and Bolts Demonstration</title>	
<link href="images/Underground.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="shadowbox.css">
<script type="text/javascript" src="shadowbox.js"></script>
<script type="text/javascript">
Shadowbox.init({
    language: 'en',
    players:  ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv']
});
</script>
</head>


<body>
<!-- wrap starts here -->
<div id="wrap">

		<!-- header -->
		<div id="header">			
					
			<span id="slogan"> it's what holds your site together...</span>
			
    <?php
    include("navigation.php");
    ?>
		</div>
		
<div id="header-logo">			
			
			<div id="logo">nuts<span class="red">and</span>bolts</div>		
			
			<form method="post" class="search" action="news.php">
				<p><input name="title,summary,content_keyword" class="textbox" type="text" />
  				<input name="search" class="searchbutton" value="Search News" type="submit" /></p>
			</form>
</div>
		
<div id="sidebar" >	

        <h1>Add a comment</h1>
            <div class="left-box">						
                <form method="post" action="blogDetail2.php?<?php echo $blogRecord['num'] ?>">
                <input type="hidden" name="submit" value="1" />
                <input type="hidden" name="ref_num" value="<?php echo $blogRecord['num'] ?>" />
                
                    <?php if (@$errorsAndAlerts): ?>
                  <div style="color: red; font-weight: bold; font-size: 10px;"><br/>
                    <?php echo $errorsAndAlerts; ?>
                  </div>
                    <?php endif ?>
                
                
                    <table width="" border="0" align="center" cellpadding="5" cellspacing="5">
                     <tr>
                      <td valign="top">Name</td>
                      <td><input type="text" name="title" value="<?php echo htmlspecialchars(@$_REQUEST['title']) ?>" size="30" class="textbox" /></td>
                    </tr>
                     <tr>
                       <td valign="top">Email</td>
                       <td><input type="text" name="email" value="<?php echo htmlspecialchars(@$_REQUEST['email']) ?>" size="30" class="textbox" /></td>
                     </tr>
                     <tr>
                      <td valign="top">Content</td>
                      <td><textarea name="content" cols="30" rows="4" class="textbox"><?php echo htmlspecialchars(@$_REQUEST['content']) ?></textarea></td>
                    </tr>
                     <tr>
                       <td valign="top">&nbsp;</td>
                       <td><input type="submit" name="add" class="searchbutton" value="Add Record &gt;&gt;" /></td>
                     </tr>
                    </table>
                </form>
            
            </div>
            
			<h1>Comments</h1>
            <div class="left-box">
                <?php foreach ($blogg_commentsRecords as $record): ?>
                    <div id="blogComment"><strong><?php echo $record['title'] ?></strong> | <?php echo date("d/m/y", strtotime($record['createdDate'])) ?><br />
                    <em><?php echo $record['content'] ?></em></div>
                <?php endforeach; ?>
            </div>
</div>
            
<div id="main">				
			
			<h1><?php echo $blogRecord['title'] ?> | <?php echo date("D, M jS, Y", strtotime($blogRecord['date'])) ?></h1>
				
			<?php echo $blogRecord['content'] ?> 


			
<!-- wrap ends here -->
</div>
		
<!-- footer starts here -->
<div class="footer">
	
		<p>	
&copy; 2009 <strong><a href="http://www.toledoh.com.au">Toledoh Enterprises</a></strong></div>	
	
</body>
</html>
