<?php
require_once "cmsAdmin/lib/viewer_functions.php";   
 if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }
  $tableName       = 'stories';
  $recordNum       = null; // you must set either $recordNum or $preSaveTempId to null
  $preSaveTempId   = @$_REQUEST['preSaveTempId'] ? $_REQUEST['preSaveTempId'] : uniqid('x');
  $errorsAndAlerts = '';

  ### insert record
  if (@$_REQUEST['submitForm']) {

    // error checking
    if (!@$_REQUEST['title'])    { $errorsAndAlerts .= "Please specify title!<br/>\n"; }

    // update record
    if (!@$errorsAndAlerts) {
      mysqlStrictMode(false); // disable Mysql strict errors for when a field isn't defined below (can be caused when fields are added later)
      $query = "INSERT INTO `{$TABLE_PREFIX}$tableName` SET
                    createdDate      = NOW(),
                    createdByUserNum = '" .intval( @$CURRENT_USER['num'] ). "',
                    updatedDate      = NOW(),
                    updatedByUserNum = '" .intval( @$CURRENT_USER['num'] ). "',

                    title            = '".mysql_escape( $_REQUEST['title'] )."'";
      mysql_query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
      $newRecordNum = mysql_insert_id();

      // adopt temp uploads (IMPORTANT - DON'T FORGET THIS STEP!!!)
      adoptUploads($tableName, $preSaveTempId, $newRecordNum);
      removeExpiredUploads(); // erase old expired uploads

      // display thanks message and clear form
      $errorsAndAlerts = "Thanks, we've added your record!";
      $_REQUEST      = array();
    }
  }

?><!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
  body, td { font-family: arial }
</style>
</head>
<body>

<blockquote>
	<h1><font color="#FF0000">Add Personal Story</font></h1>

<?php if (@$errorsAndAlerts): ?>
  	<div style="color: #C00; font-weight: bold; font-size: 14px;"><?php echo $errorsAndAlerts; ?></div>
<?php endif ?>
<hr/>
</blockquote>



<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
<input type="hidden" name="submitForm" value="1" />
<input type="hidden" name="num" value="<?php echo $recordNum ?>" />
<input type="hidden" name="preSaveTempId" value="<?php echo $preSaveTempId ?>" />
<div align="center">
			<div style="border: 1px solid #000; background-color: #E9E9D1; padding: 10px; width: 767px; height:346px">
				<table border="0" cellpadding="2" width="93%" id="table2"> <tr>
  <td valign="top"><b>Title</b></td>
  <td>
	<input  type="text" name="title" value="<?php echo htmlspecialchars(@$_REQUEST['title']) ?>" size="65" /></td>
</tr>
 <tr>
  <td valign="top"><b>Summary: </b> </td>
  <td><textarea name="notes" cols="48" rows="4"><?php echo htmlspecialchars(@$_REQUEST['summary']) ?></textarea>
   </td>
</tr>
 <tr>
  <td valign="top"><b>Uploads</b></td>
  <td>

    <?php /* TODO: Add security check in uploadForm2_iframe.php to limit access to only allowed uploads */ ?>
    <iframe src='uploadForm2_iframe.php?table=<?php echo $tableName ?>&amp;field=uploads&amp;num=<?php echo $recordNum ?>&amp;preSaveTempId=<?php echo $preSaveTempId ?>'
            height='100' width='600' frameborder='0' scrolling='no'>
    </iframe><br/>
  </td>
</tr>
 <tr>
  <td valign="top"><b>Content: </b> </td>
  <td>
	<textarea class="text-input medium-input" rows="7" cols="53" name="description" value="<?php echo htmlspecialchars(@$_REQUEST['content']); ?>" size="30" /><?php echo htmlspecialchars(@$_REQUEST['content']) ?></textarea>&nbsp;

	<p>
<input class="button" type="submit" name="submitForm" value="Add Your Story &gt;&gt;" />
</form>

</body>
</html>