<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  require_once "/home/fraction/public_html/cmsAdmin/lib/viewer_functions.php";

// submit form
if (@$_REQUEST['submit']) {

  // error checking
  $errorsAndAlerts = "";
  if (!@$_REQUEST['content'])  { $errorsAndAlerts .= "Please write a comment!<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}comments` SET
                      content          = '".mysql_real_escape_string( $_REQUEST['content'] )."',
                      reference        = '".mysql_real_escape_string( $_REQUEST['reference'] )."',
                      author        = '".mysql_real_escape_string( $_REQUEST['author'] )."',

                      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!  Your comment has been added below.";
    $_REQUEST = array();
  }

}

?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  require_once "/home/fraction/public_html/cmsAdmin/lib/viewer_functions.php";

  list($newsRecords, $newsMetaData) = getRecords(array(
    'tableName'   => 'news',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $newsRecord = @$newsRecords[0]; // get first record

  // show error message if no matching record is found
  if (!$newsRecord) {
    header("HTTP/1.0 404 Not Found");
    print "Record not found!";
    exit;
  }

?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  require_once "/home/fraction/public_html/cmsAdmin/lib/viewer_functions.php";

  list($commentsRecords, $commentsMetaData) = getRecords(array(
    'tableName'   => 'comments',
  ));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Fraction Facts: <?php echo $newsRecord['title'] ?></title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />

<link rel="stylesheet" href="css/fractionfacts.css" type="text/css" />
<script src="js/click.js" type="text/javascript"></script>
<script src="js/jquery-1.4.min.js" type="text/javascript"></script>

		<script src="js/cufon-yui.js" type="text/javascript"></script>
		<script src="js/Maiandra_GD_400.font.js" type="text/javascript"></script>
		<script type="text/javascript">
			Cufon.replace('h1');
			Cufon.replace('h3');
		</script>
</head>
<body>
<div id="pagewidth" >
    <?php
    include("insertHeader.php");
    ?> 
    
    <?php
    include("insertNavigation.php");
    ?>    
    <div id="wrapper" class="clearfix" >
    <div id="rightcol">
        <div id="rightPanel">
            <h3>Your Comments</h3>
                    <?php if (!$CURRENT_USER): ?><p>Please <a href="signup.php">register</a> to add your comments</p><?php endif ?>
                    <?php if ($CURRENT_USER): ?><p>
                    <form method="post" action="">
                        <input type="hidden" name="submit" value="1" />
                        <input type="hidden" name="reference" value="<?php echo $newsRecord['num']; ?>">
                        <input type="hidden" name="author" value="<?php echo $CURRENT_USER['username'] ?>">
        
                        <?php if (@$errorsAndAlerts): ?>
                          <div id="noticeDisplay">
                            <?php echo $errorsAndAlerts; ?>
                          </div>
                        <?php endif ?>
                        
                        
                        <textarea name="content" rows="4" class="help"><?php echo htmlspecialchars(@$_REQUEST['content']) ?></textarea><br />
                        <input name="add" type="submit" class="searchbutton" value="Add Record &gt;&gt;" />
                        
                    </form>
                    </p><?php endif ?>
        
        </div>
        <div id="rightPanel">
            <?php  $item = $newsRecord['num'] ?>
            <?php foreach ($commentsRecords as $record): ?>
                <?php if ($record['reference'] == $item ): ?>
                <?php if ($record['response'] == 1 ): ?><div id="commentGroupResponse"><?php endif; ?>
                <?php if ($record['response'] != 1 ): ?><div id="commentGroup"><?php endif; ?>
                      <div id="comment"><?php echo $record['content'] ?></div>
                <?php if ($record['response'] == 1 ): ?><div id="commentDateResponse"><?php endif; ?>
                <?php if ($record['response'] != 1 ): ?><div id="commentDate"><?php endif; ?>
					  <?php echo date("d|m|Y", strtotime($record['createdDate'])) ?>, <?php echo $record['author'] ?></div>
                    </div>
				<?php endif; ?>

            <?php endforeach ?>
        
          <!-- /STEP2: Display Records -->
          </div>
      </div>

<div id="maincol_text" > 

    <h1><?php echo $newsRecord['title'] ?></h1><div id="previousPage"> | <a href="javascript:history.go(-1)">Previous Page</a></div>
    <div class="clearfix"></div>
    <?php echo $newsRecord['content'] ?>    
        
    </div>
    </div>

    <?php
    include("insertFooter.php");
    ?>   

</div>
    <?php
    include("insertGooglecode.php");
    ?>   
</body>
</html>