<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('[your data]','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
  
  // submit form
  if (@$_REQUEST['submit']) {

  // error checking
  $alertsAndErrors = "";
  if (!@$_REQUEST['a'])    { $alertsAndErrors .= "Need to set manditory fields!<br/>\n"; }  // NEED TO ADD FIELDS & MESSAGES FOR MANDITORY FIELDS

  // turn off strict mysql error checking for: STRICT_ALL_TABLES
  $mysqlVersion = preg_replace("/[^0-9\.]/", "", mysql_get_server_info());
  $isMySql5     = version_compare($mysqlVersion, '5.0.0', '>=');
  if ($isMySql5) {
    mysql_query("SET SESSION sql_mode = 'NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER'") or die("MySQL Error: " .mysql_error(). "\n");
  }

  // add record
  if (!@$alertsAndErrors) {
    mysql_query("INSERT INTO `{$TABLE_PREFIX}tell_a_friend` SET
		a                      = '".mysql_real_escape_string( $_REQUEST['a'] )."',
		b                      = '".mysql_real_escape_string( $_REQUEST['b'] )."',
		c                      = '".mysql_real_escape_string( $_REQUEST['c'] )."',
		d                      = '".mysql_real_escape_string( $_REQUEST['d'] )."',

                      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
    $alertsAndErrors = "We've sent that brochure!";

  // PDF VIA EMAIL
 $url = "[your data]?num=" . mysql_escape(@$_REQUEST['num']) . "";
 $data = createPDF_fromUrl($url);
   
sendMessage(array(   
    'from'    => @$_REQUEST['a'],   
    'to'      => @$_REQUEST['b'],   
    'subject' => @$_REQUEST['c'],   
    'text'    => @$_REQUEST['d'],   
    'attachments' => array( 
      'example.pdf'  => $data 
    )   
  ));

  }
}
?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

  // load records
  list($productsRecords, $productsMetaData) = getRecords(array(
    'tableName'   => 'products',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $productsRecord = @$productsRecords[0]; // get first record

  // show error message if no matching record is found
  if (!$productsRecord) {
    header("HTTP/1.0 404 Not Found");
    print "Record not found!";
    exit;


  }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>[your data]</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="keywords" content="[your data]" />
<meta name="description" content="[your data]" />

<!-- TELL A FRIEND -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript">
    jQuery.fn.fadeToggle = function(speed, easing, callback) {
    return this.animate({opacity: 'toggle'}, speed, easing, callback);  
    };
    
    $(document).ready(function() {
        $('#tellfriend').hide();
        $('li a.email, #tellfriend a.close').click(function() {
        $("#tellfriend").fadeToggle('slow');
      });
    }); 
    </script>

    <style type="text/css">
		#tellfriend {
			position: absolute;
			margin-top: -300px;
			left: 400px;
			width: 380px;
			z-index: 1;
			color:#000000;
		}
		
		.social_links {
			border-top: 1px solid #dcdcdc;
			border-bottom: 1px solid #dcdcdc;
			margin-bottom: 30px;
		}
		
		.social_links ul {
			border: 0px;
			margin-left: 0px;
			margin-bottom: 0px;
		}
		
		.social_links li {
			display: inline;
			padding-left: 0px;
			background-image: none;
		}
		
		.social_links li a {
			line-height: 50px;
			font-size: 13px;
			color: #808080;
			text-decoration: none;
			margin-right: 20px;
			padding-left: 20px;
			padding-top: 2px;
			padding-bottom: 2px;
		}
		
		.social_links li a:hover {
			color: #4d4d4d;
			text-decoration: underline;
		}
		
		.social_links li a.email {
			background: url(images/icon-email.png) no-repeat;
		}
		
		.social_links li a.brochure {
			background: url(images/icon-brochure.gif) no-repeat;
		}
		
		.social_links li#tellfriendhover {
			position: relative;
		}
		
		#tellfriend {
			position: absolute;
			margin:-100px;
			left:40%;
			color: #fff;
			padding: 15px;
			margin-bottom: 20px;
			width: 380px;
			z-index: 1;
			border: 1px solid #ccc;
			-webkit-border-radius: 5px;
			-moz-border-radius: 5px;
			background-color: #f2f2f2;
		}
		
		#tellfriend a.close {
			position: absolute;
			right: -10px;
			top: -10px;
			background: url(images/fancy_closebox.png) no-repeat;
			height: 30px;
			width: 30px;
			overflow: hidden;
			text-indent: -1000px;
		}
		
		#tellfriend form textarea {
			height: 80px;
		}
		
		.contact-form {
			padding: 15px;
			margin-bottom: 20px;
			border: 1px solid #ccc;
			-webkit-border-radius: 5px;
			-moz-border-radius: 5px;
			background-color: #f2f2f2;
		}
		
		.contact-form form input.std_input {
			margin-bottom: 10px;
		}
		
		form label.clear {
			clear: both;
			float: left;
			margin-top: 10px;
		}
		
		form label.full {
			width: 99%;
		}
		
		form label.required {
			font-weight: bold;
		}
		
		form select {
			margin-bottom: 10px;
			background-color: #fff;
			border: 1px solid #ccc;
			font: 14px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
			color: #6e6e6e;
		}
		
		form label {
			color: #808080;
			font-size: 14px;
		}
		
		form input.std_input,
		form textarea {
			border: 1px solid #ccc;
			width: 97%;
			font: 15px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
			padding: 5px;
			color: #6e6e6e;
		}
		
		form table {
			width: 100%;
		}
		
		form table input.std_input {
			width: 93%;
		}
		
		form table.three-col input.std_input {
			width: 90%;
		}
		
		form input.form_but {
			margin-top: 10px;
			background-color: #FFE7C1;
			border: 3px solid #FF9900;
			color: #333333;
			font: bold 15px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
			-webkit-border-radius: 5px;
			-moz-border-radius: 5px;
			padding: 5px 10px;
		}
    </style>
</head>
<body>
    <?php if (@$alertsAndErrors): ?>
    <div style="color: red; font-weight: bold; font-size: 16px; font-family: arial;"><br/>
    <?php echo $alertsAndErrors; ?><br/><br/>
    </div>
    <?php endif ?>
<div class="social_links">
    <ul>
        <li><a class="brochure" href="/productBrochure.php?num=<?php echo $productsRecord['num'] ?>" target="_blank">View Brochure</a></li>
        <li><a class="email" href="#emailpopup">Email Someone</a></li>
    </ul>
</div>     

<div id="tellfriend" class="contact_form">
    <a class="close" href="#close" >Close</a>

    <form id='tellafriend_form' method="post" action="">
    <input type="hidden" name="submit" value="1" />
        <label for="from">Your Email: </label>
        <input class="std_input" type="text" name="a" id="a" size="40" maxlength="35" value="<?php echo htmlspecialchars(@$_REQUEST['a']) ?>"/>
        <label for="to">To: </label>
        <input class="std_input" type="text" name="b" id="b" size="40" maxlength="35" value="<?php echo htmlspecialchars(@$_REQUEST['b']) ?>"/>
        <label for="subject">Subject: </label>
        <input class="std_input" type="text" name="c" id="c" size="40" maxlength="35" value="<?php echo htmlspecialchars(@$_REQUEST['c']) ?>"/>
        <label for="message">Message: </label>
        <input class="std_input" type="text" name="d" id="d" size="40" rows="18" cols="40" value="<?php echo htmlspecialchars(@$_REQUEST['d']) ?>"/>
    <input type="submit" name="add" class="form_but" value="Submit"/>
    </form> 
</div>

<h1>[your data]</h1>
[your data]
</body>
</html>