<!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="/geo.css">
<?php
require_once('../setClassPath.php');
require_once('db/TransManager.php');
require_once('util/InputHelper.php');

$input = InputHelper::getInstance();

if (strlen($_POST['action']) == 0) {
    $key = $input->fullySanitize($_GET['key']);
    
    if (strlen($key) == 0) $key = "singles-US";
    
    $depth      = 1;                    // 1 for country, 2 for state, 3 for city
    $keys       = explode("-", $key);
    $cat        = $keys[0];             // this is cat_path
    $country    = $keys[1];             // this is loc_path of country
    $state      = "";                   // this is loc_path of state
    $city       = "";                   // this is loc_path of city
    $catdisp    = "";                   // this is display value for category, ex. "Christian Singles"
    $peopledisp = "";                   // this is display value for people of above category, which may differ from above
    $locdesc    = "";                   // description of the top location, ex. "Reno, NV"
    $toplocpath = $country;
    
    if (count($keys) > 2) {
        $state      = $keys[2];
        $toplocpath = $state;
        $depth      = 2;
    }
    if (count($keys) > 3) {
        $city       = $keys[3] . '_' . strtolower($state);
        $toplocpath = $city;
        $depth      = 3;
    }

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

    $stmt = $pdo->prepare('SELECT display, people_disp FROM category WHERE cat_path = ?');
    $stmt->bindParam(1, $cat);
    $stmt->execute();
    $myrow = $stmt->fetch(PDO::FETCH_NUM);
    $catdisp = $myrow[0];
    $peopledisp = $myrow[1];

    $stmt = $pdo->prepare('SELECT name FROM location WHERE loc_path = ?');
    $stmt->bindParam(1, $toplocpath);
    $stmt->execute();
    $myrow = $stmt->fetch(PDO::FETCH_NUM);
    $locdesc = $myrow[0];
?>
<title>Submit Tip for <?= $peopledisp ?> in <?= $locdesc ?></title>
<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: #ffddcc;">
  <h1>Submit a Dating Tip on <a href="/">DatingDiversions.com</a></h1>
</div>
<div class="boxt fullnp">
  <div class="boxtr side flr">
    <a href="http://www.tkqlhce.com/gf102dlurlt8AFFIIEF8AEADCCC" target="_top" onmouseover="window.status='http://www.metrodate.com/';return true;" onmouseout="window.status=' ';return true;">
    <img src="http://www.ftjcfx.com/i2108nswkqo9BGGJJFG9BFBEDDD" alt="Metrodate.com - the Ultimate Singles Resource" border="0"/></a>
  </div>
  <div class="main pad">
    <h2>You are about to submit a dating tip for <?= strtolower($peopledisp) ?> in <?= $locdesc ?></h2>
    <p>
      If this is not the most appropriate category for your tip, please go back and select a different category.
    </p>
    <form action="post.html" method="post">
      <input type="hidden" name="action" value="post">
      <table>
        <tr>
          <td>Your Name: </td>
          <td><input type="text" name="name"></td>
        </tr>
        <tr>
          <td>Your Email </td>
          <td><input type="text" name="email"></td>
        </tr>
        <tr>
          <td>Your Location: </td>
          <td><input type="text" name="location"></td>
        </tr>
        <tr>
          <td colspan="2">Your tip or piece of advice:</td>
        </tr>
        <tr>
          <td colspan="2"><textarea name="tip" cols="50" rows="10"></textarea></td>
        </tr>
        <tr>
          <td colspan="2"><input type="submit" value=" Submit "></td>
        </tr>
      </table>
    </form>
  </div>
</div>

<?php
}
else {
    $name   = $input->fullySanitize($_POST['name']);
    $tip    = $input->fullySanitize($_POST['tip']);
    $email  = $input->fullySanitize($_POST['email']);
    $location = $input->fullySanitize($_POST['location']);
?>
<title>Thank You for Submiting a Dating Tip</title>
<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>
<?php
     if ((strlen($name)== 0) || (strlen($tip) == 0)) {
         $nameinput     = '<input type="text" name="name" value="' . htmlentites($name, ENT_COMPAT) . '">';
         $emailinput    = '<input type="text" name="email" value="' . htmlentites($email, ENT_COMPAT) . '">';
         $locationinput = '<input type="text" name="location" value="' . htmlentites($location, ENT_COMPAT) . '">';
         $nametd        = '';
         $tiptd         = '';
         if (strlen($name) == 0)
             $nametd = '<td class="alert">Your Name: </td>';
         else
             $nametd = '<td>Your Name: </td>';
         if (strlen($tip) == 0)
             $tiptd = '<td colspan="2" class="alert">Your tip or piece of advice:</td>';
         else
             $tiptd = '<td colspan="2">Your tip or piece of advice:</td>';
         
?>
<div class="box full" style="background-color: #ffddcc;">
  <h1>There Was a Problem With Your Submission</h1>
</div>
<div class="boxt fullnp">
  <div class="boxtr side flr">
    <a href="http://www.tkqlhce.com/gf102dlurlt8AFFIIEF8AEADCCC" target="_top" onmouseover="window.status='http://www.metrodate.com/';return true;" onmouseout="window.status=' ';return true;">
    <img src="http://www.ftjcfx.com/i2108nswkqo9BGGJJFG9BFBEDDD" alt="Metrodate.com - the Ultimate Singles Resource" border="0"/></a>
  </div>
  <div class="main pad">
    <h2>Please fill in the red field(s):</h2>
    <form action="post.html" method="post">
      <input type="hidden" name="action" value="post">
      <table>
        <tr>
          <?= $nametd ?>
          <td><?= $nameinput ?></td>
        </tr>
        <tr>
          <td>Your Email </td>
          <td><?= $emailinput ?></td>
        </tr>
        <tr>
          <td>Your Location: </td>
          <td><?= $locationinput ?></td>
        </tr>
        <tr>
          <?= $tiptd ?>
        </tr>
        <tr>
          <td colspan="2"><textarea name="tip" cols="50" rows="10"><?= htmlentities($tip, ENT_NOQUOTE) ?></textarea></td>
        </tr>
        <tr>
          <td colspan="2"><input type="submit" value=" Submit "></td>
        </tr>
      </table>
    </form>
  </div>
<?php
     }
     else {
         $key = $input->fullySanitize($_GET['key']);

         $depth      = 1;                    // 1 for country, 2 for state, 3 for city
         $keys       = explode("-", $key);
         $cat        = $keys[0];             // this is cat_path
         $country    = $keys[1];             // this is loc_path of country
         $state      = "";                   // this is loc_path of state
         $city       = "";                   // this is loc_path of city

         if (count($keys) > 2) {
             $state      = $keys[2];
             $toplocpath = $state;
             $depth      = 2;
         }
         if (count($keys) > 3) {
             $city       = $keys[3] . '_' . strtolower($state);
             $toplocpath = $city;
             $depth      = 3;
         }

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

         $stmt = $pdo->prepare('SELECT location_cat_id FROM location_cat WHERE cat_path = ? AND loc_path = ?');
         $stmt->bindParam(1, $cat);
         $stmt->bindParam(2, $toplocpath);
         $stmt->execute();
         $myrow = $stmt->fetch(PDO::FETCH_NUM);
         $loccatid = $myrow[0];


         if (!stristr($tip, 'a href') && !stristr($tip, '[url') && !stristr($tip, 'http://')) {
            $stmt = $pdo->prepare('INSERT INTO tip (name, email, location, body, location_cat_id, admin_flag) VALUES (?, ?, ?, ?, ?, \'U\')');
            if (strlen($name) != 0)
                $stmt->bindParam(1, $name);
            else
                $stmt->bindValue(1, null);
            if (strlen($email) != 0)
                $stmt->bindParam(2, $email);
            else                      
                $stmt->bindValue(2, null);
            if (strlen($location) != 0)
                $stmt->bindParam(3, $location);
            else
                $stmt->bindValue(3, null);
            if (strlen($tip) != 0)
                $stmt->bindParam(4, $tip);
            else
                $stmt->bindValue(4, null);
            $stmt->bindParam(5, $loccatid);
            $stmt->execute();
         }

         $trans->commit();
         $trans->disconnect();

?>
<div class="box full" style="background-color: #ffddcc;">
  <h1>Thank You For Your Submission</h1>
</div>
<div class="boxt fullnp">
  <div class="boxtr side flr">
    <a href="http://www.tkqlhce.com/gf102dlurlt8AFFIIEF8AEADCCC" target="_top" onmouseover="window.status='http://www.metrodate.com/';return true;" onmouseout="window.status=' ';return true;">
    <img src="http://www.ftjcfx.com/i2108nswkqo9BGGJJFG9BFBEDDD" alt="Metrodate.com - the Ultimate Singles Resource" border="0"/></a>
  </div>
  <div class="main pad">
    <h2>Thank you <?= $_POST['name'] ?>, your submission has been recorded</h2>

    <p>All submissions are reviewed before they "go live" on DatingDiversions.com.  Therefore your 
    tip or advice will not be displayed immediately.</p>

    <b>Thank you again for contributing to DatingDiversions.com.</b>
  </div>
<?php
     }
}
?>
</div></body></html>
