Skip to content

Instantly share code, notes, and snippets.

@tarolandia
Created January 19, 2012 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarolandia/1642766 to your computer and use it in GitHub Desktop.
Save tarolandia/1642766 to your computer and use it in GitHub Desktop.
<?php
define("HMAC_ERROR", 1);
define("EMAIL_ERROR", 2);
define("REQUEST_ERROR", 3);
define("POST_ERROR", 4);
require_once 'includes/Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
$response = array("result" => 0, "link" => "", "error" => 0);
if($_POST) {
if( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['address'])
&& isset($_POST['client_id']) && isset($_POST['security_code']) ) {
include_once("includes/tmMessageClass.php");
if ($tmMessage = tmMessage::load($_POST['client_id'], $_POST['email'], $_POST['name'], $_POST['address'], $_POST['security_code'] )) {
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => '',
'username' => '',
'password' => '',
'dbname' => ''
));
$sql = 'SELECT * FROM users WHERE email = ?';
$result = $db->fetchAll($sql, $db->quote($_POST['email']));
if( empty($resutl) ) {
$sql = 'SELECT * FROM templatemonster_requests WHERE email = ?';
$result = $db->fetchAll($sql, $db->quote($_POST['email']));
$hashLink = $tmMessage->getHashLink();
$link = "https://secure.maxcdn.com/tm/" .$hashLink;
$data = $tmMessage->getFieldsAsArray();
$data['hash_link'] = $hashLink;
$data['status'] = "pending";
$data['expiration_date'] = gmdate("Y-m-d H:i:s", strtotime("+7 days"));;
if( empty($result) ) {
$db->insert("templatemonster_requests", $data);
$response['result'] = 1;
$response['link'] = $link;
} else {
$result = $result[0];
if( strtotime($result['expiration_date') <= gmtime() ) {
$db->update("templatemonster_requests", $data, "id = " . $result['id']);
$response['result'] = 1;
$response['link'] = $link;
} else {
$response['error'] = REQUEST_ERROR;
}
}
} else {
$response['error'] = EMAIL_ERROR;
}
} else {
$response['error'] = HMAC_ERROR;
}
} else {
$response['error'] = POST_ERROR;
}
} else {
$response["error"] = POST_ERROR;
}
echo json_encode($response);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment