blob: a8745a6cb32f0afd690d239def43181d9df85ece [file] [log] [blame]
<?php
/*******************************************************************************
* Copyright (c) 2014 Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://eclipse.org/legal/epl-v10.html
*
* Contributors:
* Edouard Poitras (Eclipse Foundation) - Further modifications
*******************************************************************************/
/* TShirt Table Schema
CREATE TABLE `tshirts` (`code` varchar(32) NOT NULL DEFAULT '',
`url` varchar(255) NOT NULL DEFAULT '',
`creation_date` DATE NOT NULL,
`sent_date` DATE,
`bugzilla_id` INT UNSIGNED,
`transaction_id` varchar(60),
`uid` varchar(60) NULL,
PRIMARY KEY (`code`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `tshirts` ADD INDEX tshirts_bugzilla_id(bugzilla_id);
ALTER TABLE `tshirts` ADD INDEX tshirts_sent_date(sent_date);
*/
/* Sample CSV
Code URL Created Date Sent Date Redemption Date Order Completed Date Order # Cost
SXZQYQBXWQ https://get.printfection.com/yourdomainhere/2048237065/sxzqyqbxwq 05/16/2014
HKZNWZBNPQ https://get.printfection.com/yourdomainhere/2048237065/hkznwzbnpq 05/16/2014
HSPSSYXWXJ https://get.printfection.com/yourdomainhere/2048237065/hspssyxwxj 05/16/2014
KQGKFFBGBW https://get.printfection.com/yourdomainhere/2048237065/kqgkffbgbw 05/16/2014
XJFWWBWXPJ https://get.printfection.com/yourdomainhere/2048237065/xjfwwbwxpj 05/16/2014
INSERT INTO tshirts VALUES ("SXZQYQBXWQ", "https://get.printfection.com/yourdomainhere/2048237065/sxzqyqbxwq", '2014-05-16', null, null, null, null);
*/
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php");
function get_tshirt_link($uid, $transaction_id) {
if ($transaction_id && $uid) {
// Check to see if this transaction has already been processed.
$check_contribution = new Contribution();
$check_transaction = $check_contribution->selectContributionExists($transaction_id);
if ($check_transaction == FALSE) {
$code = get_new_code();
// Set the uid for that code
consume_code($code['code'], $uid, $transaction_id);
} else { // Try getting the existing code
$code = get_existing_code($transaction_id);
if (!isset($code['url'])) { // Get new code
$code = get_new_code();
consume_code($code['code'], $uid, $transaction_id);
}
}
return $code['url'];
}
return "Invalid Transaction";
}
function get_new_code() {
$App = new App();
$sql = "SELECT code, url FROM tshirts WHERE sent_date IS NULL LIMIT 1";
$tmp = mysql_fetch_assoc($App->eclipse_sql($sql));
return $tmp;
}
function get_existing_code($transaction_id) {
$App = new App();
$sql = "SELECT code, url FROM tshirts WHERE transaction_id = " .
$App->returnQuotedString($App->sqlSanitize($transaction_id)) .
" ORDER BY sent_date DESC LIMIT 1";
$tmp = mysql_fetch_assoc($App->eclipse_sql($sql));
return $tmp;
}
function consume_code($code, $uid, $transaction_id) {
$App = new App();
$sql = "UPDATE tshirts SET sent_date = CURDATE(), uid = " .
$App->returnQuotedString($App->sqlSanitize($uid)) . ", transaction_id = " .
$App->returnQuotedString($App->sqlSanitize($transaction_id)) . " WHERE code = " .
$App->returnQuotedString($App->sqlSanitize($code));
$App->eclipse_sql($sql);
}