<!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">
<link rel="stylesheet" type="text/css" href="/new.css">
<?php
include "ddfuncs/ad2.php";
require('../setClassPath.php');
require_once('db/TransManager.php');
require_once('util/InputHelper.php');

$input = InputHelper::getInstance();
$trans = TransManager::getInstance();

$cookieval      = $input->fullySanitize($_COOKIE['mystic']);
$catpath        = $input->fullySanitize($_GET['cat_path']);

$trans->beginTrans();
$pdo = $trans->getPDO();

if ($catpath != '')  {
    $stmt = $pdo->prepare('SELECT name FROM advice_cat WHERE cat_path = ?');
    $stmt->bindParam(1, $catpath);
    $stmt->execute();
    $catname = '';
    if ($myrow = $stmt->fetch(PDO::FETCH_NUM))
        $catname = $myrow[0];
?>
<title><?= $catname ?> - Add Advice</title></head><body>
<div class="box full" style="background-color: #ffddcc;">
<h1><?= $catname ?></h1>
</div>

<div class="boxt fullnp">
  <div class="boxtr rside flr ctr">
    <?= getAd($cookieval, '120x240', 'f', $pdo) ?>
  </div>
  <div class="main pad">
<?php
     if ($_POST['body'] == '') {
?>
    <h2>Add Advice to This Category</h2>
    <form action="post_advice.html" method="post">
      <table>
        <tr><td>Your name: </td><td><input name="name" size="30" maxlength="60"></td></tr>
        <tr><td>Your location: </td><td><input name="location" size="30" maxlength="80"></td></tr>
        <tr><td>Your email address: </td><td><input name="email" size="30" maxlength="80"></td></tr>
        <tr><td>Title your advice: </td><td><input name="title" size="40" maxlength="80"></td></tr>
        <tr><td colspan="2">Enter your advice below:<br>
          <textarea name="body" cols="60" rows="14"></textarea>
        </td></tr>
        <tr><td colspan="2"><input type="submit" value="Submit Advice"></td></tr>
      </table>
<?php
     }
     else {
         $body      = $input->fullySanitize($_POST['body']);
         $name      = $input->fullySanitize($_POST['name']);
         $location  = $input->fullySanitize($_POST['location']);
         $email     = $input->fullySanitize($_POST['email']);
         $title     = $input->fullySanitize($_POST['title']);
         $today     = date('Y-m-d');
         $stmt = $pdo->prepare('INSERT INTO advice (name, email, location, body, cat_path, title, date_added) VALUES (?, ?, ?, ?, ?, ?, ?)');
         $stmt->bindParam(1, $name);
         $stmt->bindParam(2, $email);
         $stmt->bindParam(3, $location);
         $stmt->bindParam(4, $body);
         $stmt->bindParam(5, $catpath);
         $stmt->bindParam(6, $title);
         $stmt->bindParam(7, $today);
         $stmt->execute();
?>
      <h2>Your Advice Has Been Recorded</h2>
      <p>Advice submitted to Dating Diversions does not "go live" immediately. It is first reviewed by our editors before being posted to the advice section.  Thank you for your submission!</p>
      <br><br><br><br>
      <div class="ctr">
        <?= getAd($cookieval, '468x60', 'f', $pdo) ?>
      </div>
<?php
    }
?>
</div>

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