<?php
$storyType = false;
$storyKey  = false;
if (isset($_GET['story_type'])) {
    $storyType = $_GET['story_type'];
    if (preg_match('/[^a-z0-9_]/', $storyType))
        die ("Bad user input");
}
else
    die ("Bad user input");
if (isset($_GET['story'])) {
    $storyKey = $_GET['story'];
    if (preg_match('/[^a-z0-9_]/', $storyKey))
        die ("Bad user input");
}

require('../../setClassPath.php');
require_once('db/TransManager.php');
require_once('util/InputHelper.php');

$input = InputHelper::getInstance();
$trans = TransManager::getInstance();
$trans->beginTrans();
$pdo = $trans->getPDO();

if ($storyKey) {
    
    $storyKey       = $input->fullySanitize($storyKey);

    
    $stmt = $pdo->prepare('SELECT title, body, email, blurb, name, location FROM story WHERE story_key = ? AND admin_flag = \'A\'');
    $stmt->bindParam(1, $storyKey);
    $stmt->execute();
    if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
        $title      = $row[0];
        $body       = $row[1];
        $email      = $row[2];
        $blurb      = $row[3];
        $name       = $row[4];
        $location   = $row[5];
    }
    else
        die('Unexpected error');

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><?= $title ?></title>
    <link rel="stylesheet" type="text/css" href="/new.css">
    <script type="text/javascript">
var _gaq=_gaq||[];_gaq.push(['_setAccount','UA-628020-4']);_gaq.push(['_trackPageview']);(function(){var ga=document.createElement('script');ga.type='text/javascript';ga.async=true;ga.src=('https:'==document.location.protocol?'https://ssl':'http://www')+'.google-analytics.com/ga.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s);})();
</script>

    </head>
    <body>
    
    <div class="box full" style="background-color: #fdc;">
    <h1><?= $title ?></h1>
    <a href="/">Dating Diversions</a> | 
    <a href="/advice.html">Dating Advice</a> | 
    <a href="/stories.mv">More Dating Stories</a> | 
    <a href="/dating_jokes.html">Dating Jokes</a> | 
    <a href="/singles-US/main.html">Geographical Dating Tips</a> | 
    <a href="/gift_ideas.html">Gift Ideas</a>
    </div>

    <div class="boxt fullnp">
      <div class="boxtr rside flr ctr">
        

        <a target="_blank" href="http://www.dpbolvw.net/sq112xdmjdl0277AA67021473152" onmouseover="window.status='http://www.napster.com';return true;" onmouseout="window.status=' ';return true;">
<img src="http://www.awltovhc.com/4j116xjnbhf0277AA67021473152" alt="Napster" border="0"></a>
      </div>
    <div class="main pad">

      <p><b><?= $blurb ?></b></p>
    
      <p>By <?= $name ?>
         (<?= $email ?>)
         of <?= $location ?>
      </p>
    
      <p><?= $body ?></p>
    </div>
    </div>
    <br><br>
    <span class="sm"><b>Copyright Information: You may not reproduce this or other content on DatingDiversions.com without explicit permission</b></span><br>
    View our <a href="/privacy.html">Privacy Policy</a>
    
    
</body></html>
<?php
}
else {

    $stmt = $pdo->prepare('SELECT name, description FROM story_type WHERE story_type = ?');
    $stmt->bindParam(1, $storyType);
    $stmt->execute();
    if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
        $name = $row[0];
        $description = $row[1];
    }
    else
        die('Unexpected error');
        
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?= $name ?> at Dating Diversions</title>
<link rel="stylesheet" type="text/css" href="/new.css">
<script type="text/javascript">
var _gaq=_gaq||[];_gaq.push(['_setAccount','UA-628020-4']);_gaq.push(['_trackPageview']);(function(){var ga=document.createElement('script');ga.type='text/javascript';ga.async=true;ga.src=('https:'==document.location.protocol?'https://ssl':'http://www')+'.google-analytics.com/ga.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s);})();
</script>
</head>
<body>
 
 <div class="box full" style="background-color: #fdc;">
 <h1><?= $name ?></h1>
 <a href="/">Dating Diversions</a> | 
 <a href="/advice.html">Dating Advice</a> | 
 <a href="/stories.mv">More Dating Stories</a> | 
 <a href="/dating_jokes.html">Dating Jokes</a> | 
 <a href="/singles-US/main.html">Geographical Dating Tips</a> | 
 <a href="/gift_ideas.html">Gift Ideas</a>
 </div>

 <div class="boxt fullnp">
   <div class="boxtr rside flr ctr">
     

        <a target="_blank" href="http://www.jdoqocy.com/9h115zw41w3JLQQTTPQJOKQNOKO" onmouseover="window.status='http://www.date.com';return true;" onmouseout="window.status=' ';return true;">
<img src="http://www.ftjcfx.com/ee66ax0pvtEGLLOOKLEJFLIJFJ" alt="" border="0"></a>
      </div>
    <div class="main pad">

      <h2><a href="/stories.mv">Dating Stories</a> at <a href="/">Dating Diversions</a></h2>
    
      <p><?= $description ?></p>
      
      <h3>Our Stories:</h3>
<?php
    $stmt = $pdo->prepare('SELECT story_key, title, name, blurb FROM story WHERE story_type = ? AND admin_flag = \'A\'');
    $stmt->bindParam(1, $storyType);
    $stmt->execute();
    while ($myrow = $stmt->fetch(PDO::FETCH_NUM))
        printf("<p><a href=\"%s/story.html\">%s</a> by %s<br>%s</p><br>\r\n", $myrow[0], $myrow[1], $myrow[2], $myrow[3]);

?>
    
   <!--
    <h2>Tell Us Your Story:</h2>
    <form action="stories.html" method="post">
        <input type="hidden" name="action" value="add">
        <table>
        <tr><td>Name: </td><td><input type="text" name="na" size="20" maxlength="60"></td></tr>
        <tr><td>Email: </td><td><input type="text" name="em" size="20" maxlength="80"></td></tr>
        <tr><td>location: </td><td class="sm"><input type="text" name="lo" size="20" maxlength="60">
        Ex. London, England or Atanta, GA, USA</td></tr>
        <tr><td>title: </td><td><input type="text" name="ti" size="40" maxlength="80"></td></tr>
        <tr><td colspan="2">Your Story:<br>
        <textarea name="bo" cols="60" rows="15"></textarea></td></tr>
        <tr><td>&nbsp;</td>
        <td class="sm">Note, stories may be edited for length, clarity, or other factors.<br>
        By submitting a story, you agree to give the owner of DatingDiversions.com the right to post it on the internet free from restrictions.<br>
        <input type="submit" value=" Submit Story "></td></tr>
        </table>
    </form>
    -->
    </div>
    </div>
    View our <a href="/privacy.html">Privacy Policy</a>

</body></html>
<?php
}
$trans->commit(TRUE);
?>
