include_once( "Date.php" );
include_once( "Transaction.php" );
include_once( "Net.php" );
// ==================================================================
// remove below function when finished troubleshooting
function zgpLog99($msg){
$zgpLogPath = __DIR__ . "/AuthorizeNetLog.txt";
$fp = fopen($zgpLogPath, 'a');//opens file in append mode
fwrite($fp, $msg . "\r");
fclose($fp);
}
function zgpAuthnetSend($keyValues){
$xml = '
' . $keyValues["x_Login"] . '
' . $keyValues["x_Tran_Key"] . '
authCaptureTransaction
' . $keyValues["x_Amount"] . '
' . $keyValues["x_Card_Num"] . '
' . $keyValues["x_Exp_Date"] . '
' . $keyValues["x_Invoice_Num"] . '
Polaris Global Purchase
individual
' . $keyValues["x_Cust_ID"] . '
' . $keyValues["x_Email"] . '
' . $keyValues["x_First_Name"] . '
' . $keyValues["x_Last_Name"] . '
' . $keyValues["x_Company"] . '
' . $keyValues["x_Address"] . '
' . $keyValues["x_City"] . '
' . $keyValues["x_State"] . '
' . $keyValues["x_Zip"] . '
' . $keyValues["x_Country"] . '
' . $keyValues["x_Phone"] . '
' . $keyValues["x_Ship_To_First_Name"] . '
' . $keyValues["x_Ship_To_Last_Name"] . '
' . $keyValues["x_Ship_To_Company"] . '
' . $keyValues["x_Ship_To_Address"] . '
' . $keyValues["x_Ship_To_City"] . '
' . $keyValues["x_Ship_To_State"] . '
' . $keyValues["x_Ship_To_Zip"] . '
' . $keyValues["x_Ship_To_Country"] . '
duplicateWindow
0
';
//echo "
";
//echo htmlentities($xml);
//echo "
";
//$authnetURL = "https://api2.authorize.net/xml/v1/request.api";
$authnetURL = "https://api.authorize.net/xml/v1/request.api";
// $authnetURL = "https://apitest.authorize.net/xml/v1/request.api"; //test
$jsonResponse = SendToAuthorizeNet($authnetURL, $xml, $keyValues);
return $jsonResponse;
}
function SendToAuthorizeNet($url, $request, $keyValues){
$ch = curl_init();
if (FALSE === $ch){
// file_put_contents('./AuthorizeNetLog', date('Y-m-d H:i:s').': '.curl_error($ch));
zgpLog99(date('Y-m-d H:i:s').': '.curl_error($ch));
throw new Exception('failed to initialize');
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
$content = curl_exec($ch);
if (FALSE === $content){
//throw new Exception(curl_error($ch), curl_errno($ch));
die("Authorize.net response is empty.");
// $this -> setGatewayResponse("Authorize.net response is empty.");
}
curl_close($ch);
$dateTime = date("Y-m-d h:i:sa");
$orderID = $keyValues["x_Invoice_Num"];
zgpLog99($dateTime . " - " . $orderID .": raw response: $content");
$duplicateError = "A duplicate transaction has been submitted.";
$pos = strpos($content, $duplicateError);
if ($pos === false) {
$xmlResult = simplexml_load_string($content);
$jsonResult = json_encode($xmlResult);
return $jsonResult;
}else{
return $duplicateError;
}
}
// remove above function when finished troubleshooting
// ==================================================================
if (!class_exists('AuthorizeNet')) {
class AuthorizeNet {
var $gatewayAddress;
var $postString;
var $transaction;
//response variables
//----------------------------------------------------------------------------------------------
var $responseCodes = array("", "approved", "declined", "error");
var $gatewayResponse;
var $response;
var $responseMsg;
var $responseCode;
var $responseSubCode;
var $responseReasonCode;
var $responseReasonText;
var $approvalCode;
var $AVSResultCode;
var $AVSResultCodes = array("A"=>"Address(Street) Matches, ZIP Does Not","B"=>"Address information not provided for AVS check","E"=>"AVS Error","G"=>"Non-U.S. Card Issuing Bank","N"=>"No Match on Address (Street) or ZIP","P"=>"AVS not applicable for this transaction","R"=>"Retry -- System unavailable or timed out","S"=>"Service not supported by issuer","U"=>"Address information is unavailable","W"=>"9 digit ZIP matches, Address (Street) does not","X"=>"Address (Street) and 9 digit ZIP match","Y"=>"Address (Street) and 5 digit ZIP match","5 digit ZIP matches, Address (Street) does not");
var $transactionId;
var $md5Hash;
var $cardCodeResponse;
//end response variables
//----------------------------------------------------------------------------------------------
//a.net variables
var $x_Login;
var $x_Password;
var $x_Tran_Key;
var $x_Version;
var $x_Test_Request;
var $x_Delim_Data;
var $x_Delim_Char;
var $x_Encap_Char;
var $x_Relay_Response;
//name and address info
var $x_First_Name;
var $x_Last_Name;
var $x_Company;
var $x_Address;
var $x_City;
var $x_State;
var $x_Zip;
var $x_Country;
var $x_Phone;
var $x_Fax;
//additional customer data
var $x_Cust_ID;
var $x_Customer_IP;
var $x_Customer_Tax_ID;
var $x_Customer_Organization_Type;
var $x_Drivers_License_Num;
var $x_Drivers_License_State;
var $x_Drivers_License_DOB;
//email settings
var $x_Email;
var $x_Email_Customer;
var $x_Merchant_Email;
//invoice information
var $x_Invoice_Num;
var $x_Description;
//shipping information
var $x_Ship_To_First_Name;
var $x_Ship_To_Last_Name;
var $x_Ship_To_Company;
var $x_Ship_To_Address;
var $x_Ship_To_City;
var $x_Ship_To_State;
var $x_Ship_To_Zip;
var $x_Ship_To_Country;
//transaction data
var $x_Amount;
var $x_Currency_Code;
var $x_Method;
var $x_Type;
var $x_Bank_ABA_Code;
var $x_Bank_Acct_Num;
var $x_Bank_Acct_Type;
var $x_Bank_Name;
var $x_Bank_Account_Name;
var $x_Echeck_Type;
var $x_Card_Num;
var $x_Exp_Date;
var $x_Card_Code;
var $x_Trans_ID;
var $x_Auth_Code;
//level 2 code
var $x_PO_Num;
var $x_Tax;
var $x_Tax_Exempt;
var $x_Freight;
var $x_Duty;
//----------------------------------------------------------------------------------------------
//constructor
function AuthorizeNet() {
// $this->setGatewayAddress("https://test.authorize.net/gateway/transact.dll");
// $this->setGatewayAddress("https://secure.authorize.net/gateway/transact.dll");
//$this->setGatewayAddress("https://secure2.authorize.net/gateway/transact.dll"); //New URL 2016
$this->setGatewayAddress("https://api2.authorize.net/xml/v1/request.api"); //New URL 2018
$this->setX_Version("3.1");
$this->setX_Delim_Data("true");
$this->setX_Delim_Char(",");
/*optional parameters
1 - login
2 - password
3 - transaction key
4 - version
5 - data delimited
6 - type
7 - amount
8 - cc number
9 - expiration date
*/
if (func_num_args() > 0) $this->setX_Amount(func_get_arg(0));
if (func_num_args() > 1) $this->setX_Card_Num(func_get_arg(1));
if (func_num_args() > 2) $this->setX_Exp_Date(func_get_arg(2));
if (func_num_args() > 3) $this->setX_Type(func_get_arg(3));
}
function makePostString() {
$keyValues = array();
// $arrayname[indexname] = $value;
$queryString = "";
if (is_array(get_object_vars($this))){
foreach (get_object_vars($this) as $key=>$value) {
if (stristr($key,"x_")) {
if ($value) $queryString .= "&".strtolower($key)."=".urlencode($value);
}
if(!$keyValues[$key]){
$keyValues[$key] = $value;
}
}
}
$queryString = substr($queryString,1);
$this->setPostString($queryString);
return $keyValues;
}
function writeme($str){
echo $str . "
";
}
function sendTransaction() {
$keyValues = ($this -> makePostString());
$response = zgpAuthnetSend($keyValues); // ZGP xml approach
if($response != "A duplicate transaction has been submitted."){
$jsonObject = json_decode($response);
$responseCode = $jsonObject->transactionResponse->responseCode;
$resultCode = $jsonObject->messages->resultCode;
$code = $jsonObject->messages->message->code;
$details = $jsonObject->messages->message->text;
$transactionID = $jsonObject->transactionResponse->transId;
$authCode = $jsonObject->transactionResponse->authCode;
$avsResultCode = $jsonObject->transactionResponse->avsResultCode;
$ccNumber = $jsonObject->transactionResponse->accountNumber;
$ccType = $jsonObject->transactionResponse->accountType;
$errorText = $jsonObject->transactionResponse->errors->error->errorText;
$description = $jsonObject->transactionResponse->messages->message->description; //added by mark
$theReason = $jsonObject->transactionResponse->messages->message->description;
}else{
// A duplicate transaction has been submitted.
$responseCode = 3;
$resultCode = "E00027";
$details = $response;
$errorText = $response;
}
$this -> setResponseCode($responseCode);
$this -> setResponseReasonCode($resultCode);
$this -> setResponseReasonText($details);
$this -> setApprovalCode($authCode);
$this -> setAVSResultCode($avsResultCode);
$this -> setTransactionId($transactionID);
$this -> setMd5Hash("1234"); // always empty
$this -> setCardCodeResponse(""); // always empty
// $gatewayResponse = $description . "," . $responseCode . "," . $resultCode . "," . $details . "," . $transactionID . "," . $authCode . "," . $avsResultCode . "," . $ccNumber . "," . $ccType . "," . $errorText . ","; //added by mark
// $this -> setGatewayResponse($gatewayResponse); //added by mark
if ( !$this -> getResponseCode() ) { // Response Code is missing!
$this -> setResponseCode( 0 );
$this -> setResponseReasonText( "WARNING! AuthorizeNet did not return a response code. AuthorizeNet response: " . $this -> getResponseReasonText() );
//$this -> setResponseReasonText( "PG WARNING! AuthorizeNet did not return a response code. AuthorizeNet response: " . $this -> getResponseReasonText() );
$this -> setGatewayResponse($details);
}
// Declined or Error Response Code
else if ( $this -> getResponseCode() != 1 ) {
// TO DO
// ... nothing for now
$gatewayResponse = $errorText . " - " . $details; //added by mark
$this -> setGatewayResponse($gatewayResponse); //added by mark
}
// Success Response Code
else if ( $this -> getResponseCode() == 1 ) {
$gatewayResponse = $description . "," . $responseCode . "," . $resultCode . "," . $details . "," . $transactionID . "," . $authCode . "," . $avsResultCode . "," . $ccNumber . "," . $ccType . "," . $errorText; //added by mark
$this -> setGatewayResponse($gatewayResponse); //added by mark
// Must return a transactionId and it must be a number
if ( $transactionID > 0 && is_numeric($transactionID) ) {
if ( is_object( $this -> getConnection() ) && $this -> getX_Type() != "CREDIT" ) {
$transaction = new Transaction( $this -> getConnection() );
$transaction -> setUserId( $this -> getX_Cust_ID() );
$transaction -> setTypeId( 1 ); // CC
$transaction -> setRefNo( $this -> getTransactionId() );
$transaction -> setAmount( $this -> getX_Amount() );
$transaction -> setStatus( 'COMPLETED' );
$transaction -> setIp( Net::getIp() );
$transaction -> setCcLastFour( substr($this -> getX_Card_Num(), -4, 4) );
$transaction -> setCreatedMysqlDate( Date::getNowMysqlDatetime() );
$transaction -> setMemo( $responseMsg );
$transaction -> insertTransaction();
$this -> setTransaction( $transaction );
}
}
// AuthorizeNet fucked up royally
//else if ( strtolower($this -> getX_Test_Request()) != "true" ) {
// $this -> setResponseCode( 0 );
// $this -> setResponseReasonText( "PG WARNING! AuthorizeNet returned SUCCESS as a response code; however, Transaction Id is missing, or it contains characters other than digits. AuthorizeNet response: " . $this -> getResponseReasonText() );
//}
// Test transaction
else {
// TO DO
// ... nothing for now
}
}
}
// ======================================================================
// GETTERS
// ======================================================================
function getTransaction() {
return $this -> transaction;
}
function getPostString() {
return $this->postString;
}
function getGatewayAddress() {
return $this->gatewayAddress;
}
function getResponse() {
return $this->responseCodes[$this->responseCode];
}
function getResponseCode() {
return $this->responseCode;
}
function getGatewayResponse() {
return $this->gatewayResponse;
}
function getResponseSubCode() {
return $this->responseSubCode;
}
function getResponseReasonCode() {
return $this->responseReasonCode;
}
function getResponseReasonText() {
return $this->responseReasonText;
}
function getApprovalCode() {
return $this->approvalCode;
}
function getAVSResultCode() {
return $this->AVSResultCode;
}
function getTransactionId() {
return $this->transactionId;
}
function getMd5Hash() {
return $this->md5Hash;
}
function getCardCodeResponse() {
return $this->cardCodeResponse;
}
function getX_Login() {
return $this->x_Login;
}
function getX_Password() {
return $this->x_Password;
}
function getX_Tran_Key() {
return $this->x_Tran_Key;
}
function getX_Version() {
return $this->x_Version;
}
function getX_Test_Request() {
return $this->x_Test_Request;
}
function getX_Delim_Data() {
return $this->x_Delim_Data;
}
function getX_Delim_Char() {
return $this->x_Delim_Char;
}
function getX_Encap_Char() {
return $this->x_Encap_Char;
}
function getX_Relay_Response() {
return $this->x_Relay_Response;
}
function getX_First_Name() {
return $this->x_First_Name;
}
function getX_Last_Name() {
return $this->x_Last_Name;
}
function getX_Company() {
// $value = str_replace('&', 'and', $value);
return str_replace('&', 'and', $this->x_Company);
}
function getX_Address() {
// return $this->x_Address;
return substr($this->x_Address,0,59);
}
function getX_City() {
return $this->x_City;
}
function getX_State() {
return $this->x_State;
}
function getX_Zip() {
return $this->x_Zip;
}
function getX_Country() {
return $this->x_Country;
}
function getX_Phone() {
return $this->x_Phone;
}
function getX_Fax() {
return $this->x_Fax;
}
function getX_Cust_ID() {
return $this->x_Cust_ID;
}
function getX_Customer_IP() {
return $this->x_Customer_IP;
}
function getX_Customer_Tax_ID() {
return $this->x_Customer_Tax_ID;
}
function getX_Customer_Organization_Type() {
return $this->x_Customer_Organization_Type;
}
function getX_Drivers_License_Num() {
return $this->x_Drivers_License_Num;
}
function getX_Drivers_License_State() {
return $this->x_Drivers_License_State;
}
function getX_Drivers_License_DOB() {
return $this->x_Drivers_License_DOB;
}
function getX_Email() {
return $this->x_Email;
}
function getX_Email_Customer() {
return $this->x_Email_Customer;
}
function getX_Merchant_Email() {
return $this->x_Merchant_Email;
}
function getX_Invoice_Num() {
return $this->x_Invoice_Num;
}
function getX_Description() {
return $this->x_Description;
}
function getX_Ship_To_First_Name() {
return $this->x_Ship_To_First_Name;
}
function getX_Ship_To_Last_Name() {
return $this->x_Ship_To_Last_Name;
}
function getX_Ship_To_Company() {
//$value = str_replace('&', 'and', $value);
return str_replace('&', 'and', $this->x_Ship_To_Company);
}
function getX_Ship_To_Address() {
return $this->x_Ship_To_Address;
return substr($this->x_Ship_To_Address,0,59);
}
function getX_Ship_To_City() {
return $this->x_Ship_To_City;
}
function getX_Ship_To_State() {
return $this->x_Ship_To_State;
}
function getX_Ship_To_Zip() {
return $this->x_Ship_To_Zip;
}
function getX_Ship_To_Country() {
return $this->x_Ship_To_Country;
}
function getX_Amount() {
return $this->x_Amount;
}
function getX_Currency_Code() {
return $this->x_Currency_Code;
}
function getX_Method() {
return $this->x_Method;
}
function getX_Type() {
return $this->x_Type;
}
function getX_Bank_ABA_Code() {
return $this->x_Bank_ABA_Code;
}
function getX_Bank_Acct_Num() {
return $this->x_Bank_Acct_Num;
}
function getX_Bank_Acct_Type() {
return $this->x_Bank_Acct_Type;
}
function getX_Bank_Name() {
return $this->x_Bank_Name;
}
function getX_Bank_Account_Name() {
return $this->x_Bank_Account_Name;
}
function getX_Echeck_Type() {
return $this->x_Echeck_Type;
}
function getX_Card_Num() {
return $this->x_Card_Num;
}
function getX_Exp_Date() {
return $this->x_Exp_Date;
}
function getX_Card_Code() {
return $this->x_Card_Code;
}
function getX_Trans_ID() {
return $this->x_Trans_ID;
}
function getX_Auth_Code() {
return $this->x_Auth_Code;
}
function getX_PO_Num() {
return $this->x_PO_Num;
}
function getX_Tax() {
return $this->x_Tax;
}
function getX_Tax_Exempt() {
return $this->x_Tax_Exempt;
}
function getX_Freight() {
return $this->x_Freight;
}
function getX_Duty() {
return $this->x_Duty;
}
// ======================================================================
// SETTERS
// ======================================================================
function setTransaction( $value ) {
$this -> transaction = $value;
}
function setPostString($value) {
$this->postString = $value;
}
function setGatewayAddress($value) {
$this->gatewayAddress = $value;
}
function setResponseCode($value) {
$this->responseCode = $value;
}
function setGatewayResponse($value) {
$this->gatewayResponse = $value;
}
function setResponseSubCode($value) {
$this->responseSubCode = $value;
}
function setResponseReasonCode($value) {
$this->responseReasonCode = $value;
}
function setResponseReasonText($value) {
$this->responseReasonText = $value;
}
function setApprovalCode($value) {
$this->approvalCode = $value;
}
function setAVSResultCode($value) {
$this->AVSResultCode = $value;
}
function setTransactionId($value) {
$this->transactionId = $value;
}
function setMd5Hash($value) {
$this->md5Hash = $value;
}
function setCardCodeResponse($value) {
$this->cardCodeResponse = $value;
}
function setX_Login($value) {
$this->x_Login = $value;
}
function setX_Password($value) {
$this->x_Password = $value;
}
function setX_Tran_Key($value) {
$this->x_Tran_Key = $value;
}
function setX_Version($value) {
$this->x_Version = $value;
}
function setX_Test_Request($value) {
$this->x_Test_Request = $value;
}
function setX_Delim_Data($value) {
$this->x_Delim_Data = $value;
}
function setX_Delim_Char($value) {
$this->x_Delim_Char = $value;
}
function setX_Encap_Char($value) {
$this->x_Encap_Char = $value;
}
function setX_Relay_Response($value) {
$this->x_Relay_Response = $value;
}
function setX_First_Name($value) {
$this->x_First_Name = $value;
}
function setX_Last_Name($value) {
$this->x_Last_Name = $value;
}
function setX_Company($value) {
$value = str_replace('&', 'and', $value);
$value = substr($value, 0, 20);
$this->x_Company = $value;
}
function setX_Address($value) {
$value = substr($value, 0, 59);
$this->x_Address = $value;
}
function setX_City($value) {
$this->x_City = $value;
}
function setX_State($value) {
$this->x_State = $value;
}
function setX_Zip($value) {
$this->x_Zip = $value;
}
function setX_Country($value) {
$this->x_Country = $value;
}
function setX_Phone($value) {
$this->x_Phone = $value;
}
function setX_Fax($value) {
$this->x_Fax = $value;
}
function setX_Cust_ID($value) {
$this->x_Cust_ID = $value;
}
function setX_Customer_IP($value) {
$this->x_Customer_IP = $value;
}
function setX_Customer_Tax_ID($value) {
$this->x_Customer_Tax_ID = $value;
}
function setX_Customer_Organization_Type($value) {
$this->x_Customer_Organization_Type = $value;
}
function setX_Drivers_License_Num($value) {
$this->x_Drivers_License_Num = $value;
}
function setX_Drivers_License_State($value) {
$this->x_Drivers_License_State = $value;
}
function setX_Drivers_License_DOB($value) {
$this->x_Drivers_License_DOB = $value;
}
function setX_Email($value) {
$this->x_Email = $value;
}
function setX_Email_Customer($value) {
$this->x_Email_Customer = $value;
}
function setX_Merchant_Email($value) {
$this->x_Merchant_Email = $value;
}
function setX_Invoice_Num($value) {
$this->x_Invoice_Num = $value;
}
function setX_Description($value) {
$this->x_Description = $value;
}
function setX_Ship_To_First_Name($value) {
$this->x_Ship_To_First_Name = $value;
}
function setX_Ship_To_Last_Name($value) {
$this->x_Ship_To_Last_Name = $value;
}
function setX_Ship_To_Company($value) {
$value = str_replace('&', 'and', $value);
$value = substr($value, 0, 20);
$this->x_Ship_To_Company = $value;
}
function setX_Ship_To_Address($value) {
$this->x_Ship_To_Address = $value;
}
function setX_Ship_To_City($value) {
$this->x_Ship_To_City = $value;
}
function setX_Ship_To_State($value) {
$this->x_Ship_To_State = $value;
}
function setX_Ship_To_Zip($value) {
$this->x_Ship_To_Zip = $value;
}
function setX_Ship_To_Country($value) {
$this->x_Ship_To_Country = $value;
}
function setX_Amount($value) {
$this->x_Amount = $value;
}
function setX_Currency_Code($value) {
$this->x_Currency_Code = $value;
}
function setX_Method($value) {
$this->x_Method = $value;
}
function setX_Type($value) {
$this->x_Type = $value;
}
function setX_Bank_ABA_Code($value) {
$this->x_Bank_ABA_Code = $value;
}
function setX_Bank_Acct_Num($value) {
$this->x_Bank_Acct_Num = $value;
}
function setX_Bank_Acct_Type($value) {
$this->x_Bank_Acct_Type = $value;
}
function setX_Bank_Name($value) {
$this->x_Bank_Name = $value;
}
function setX_Bank_Account_Name($value) {
$this->x_Bank_Account_Name = $value;
}
function setX_Echeck_Type($value) {
$this->x_Echeck_Type = $value;
}
function setX_Card_Num($value) {
// $this->x_Card_Num = $value;
$this->x_Card_Num = str_replace(' ', '', $value);
}
function setX_Exp_Date($value) {
$this->x_Exp_Date = $value;
}
function setX_Card_Code($value) {
$this->x_Card_Code = $value;
}
function setX_Trans_ID($value) {
$this->x_Trans_ID = $value;
}
function setX_Auth_Code($value) {
$this->x_Auth_Code = $value;
}
function setX_PO_Num($value) {
$this->x_PO_Num = $value;
}
function setX_Tax($value) {
$this->x_Tax = $value;
}
function setX_Tax_Exempt($value) {
$this->x_Tax_Exempt = $value;
}
function setX_Freight($value) {
$this->x_Freight = $value;
}
function setX_Duty($value) {
$this->x_Duty = $value;
}
//----------------------------------------------------------------------------------------------
}
}
?>
include_once("SQLSelect.php");
include_once("SQLInsert.php");
include_once("SQLUpdate.php");
include_once("SQLDelete.php");
include_once("Date.php");
include_once("String.php");
class GoalProgress {
var $connection;
var $goalProgressId;
var $goalId;
var $progressDate;
var $progress;
var $error;
function GoalProgress($pConnection) {
$this->setConnection($pConnection);
$this->setProgressDate(new Date());
if (func_num_args() > 1) $this->setGoalId(func_get_arg(1));
if (func_num_args() > 2) $this->setProgress(func_get_arg(2));
if (func_num_args() > 3) $this->setProgressYear(func_get_arg(3));
if (func_num_args() > 4) $this->setProgressMonth(func_get_arg(4));
if (func_num_args() > 5) $this->setProgressDay(func_get_arg(5));
}
function selectGoalProgress() {
if (func_num_args() > 0) $this->setGoalProgressId(func_get_arg(0));
if (!$this->getGoalProgressId()) $this->myThrow("Cannot select Goal Progress. Goal Progress ID not specified.");
$select = new SQLSelect($this->getConnection());
$sql = "SELECT * FROM GOAL_PROGRESS WHERE GOAL_PROGRESS_ID = '".String::sqlEncode($this->getGoalProgressId())."'";
$select->executeQuery($sql);
if ($select->getNumRows() > 0) {
$goalObj = $select->getFirstRow();
$this->setGoalId($goalObj->GOAL_ID);
$this->setProgressMysqlDate($goalObj->DATETIME);
$this->setProgress($goalObj->PROGRESS);
$found = true;
} else {
$found = false;
}
$select->freeResult();
return $found;
}
function insertGoalProgress() {
$insert = new SQLInsert($this->getConnection());
$sql = "INSERT INTO GOAL_PROGRESS (GOAL_ID,DATETIME,PROGRESS) VALUES (
'".String::sqlEncode($this->getGoalId())."',
'".String::sqlEncode($this->getProgressMysqlDate())."',
'".String::sqlEncode($this->getProgress())."'
)";
$insert->executeQuery($sql);
$this->setGoalProgressId($insert->getInsertId());
return $this->getGoalProgressId();
}
function updateGoalProgress() {
if (func_num_args() > 0) $this->setGoalProgressId(func_get_arg(0));
if (!$this->getGoalProgressId()) $this->myThrow("Cannot update Goal Progress. Goal Progress ID not specified.");
$sql = "UPDATE GOAL_PROGRESS SET
GOAL_ID = '".String::sqlEncode($this->getGoalId())."'
DATETIME = '".String::sqlEncode($this->getProgressMysqlDate())."'
PROGRESS = '".String::sqlEncode($this->getProgress())."'
WHERE GOAL_PROGRESS_ID = '".String::sqlEncode($this->getGoalProgressId())."'";
}
function deleteGoalProgress() {
if (func_num_args() > 0) $this->setGoalProgressId(func_get_arg(0));
if (!$this->getGoalProgressId()) $this->myThrow("Cannot delete Goal Progress. Goal Progress ID not specified.");
$sql = "DELETE * FROM GOAL_PROGRESS WHERE GOAL_PROGRESS_ID = '".String::sqlEncode($this->getGoalProgressId())."'";
$delete->executeQuery($sql);
$this->clearValues();
}
function myThrow($errMsg){
if (is_object($this->getError())) {
$this->error->throw($errMsg);
} else {
die($errMsg);
}
}
function mapValues($postVars) {
if(is_array($postVars)){
foreach ($postVars as $key=>$value) {
$methodName = "set" . ucfirst($key);
if (method_exists($this,$methodName)) {
$this->$methodName($value);
}
}
}
}
function clearValues() {
if(is_array(get_object_vars($this))){
foreach (get_object_vars($this) as $key=>$value) {
if ($key != "connection") {
if (is_array($value)) {
$this->$key = array();
} elseif(is_object($value)) {
$class = get_class($value);
if (in_array(strtolower("setConnection"),get_class_methods($class))) {
$this->$key = new $class($this->getConnection());
} else {
$this->$key = new $class();
}
} else {
$this->$key = "";
}
}
}
}
}
//getters
function getConnection() {
return $this->connection;
}
function getGoalProgressId() {
return $this->goalProgressId;
}
function getGoalId() {
return $this->goalId;
}
function getProgressDate() {
return $this->progressDate;
}
function getProgressYear() {
if (is_object($this->getProgressDate())) return $this->progressDate->getYear();
}
function getProgressMonth() {
if (is_object($this->getProgressDate())) return $this->progressDate->getMonth();
}
function getProgressDay() {
if (is_object($this->getProgressDate())) return $this->progressDate->getDay();;
}
function getProgressHour() {
if (is_object($this->getProgressDate())) return $this->progressDate->getHour();
}
function getProgressMinute() {
if (is_object($this->getProgressDate())) return $this->progressDate->getMinute();
}
function getProgressSeconds() {
if (is_object($this->getProgressDate())) return $this->progressDate->getSeconds();
}
function getProgressAmPm() {
if (is_object($this->getProgressDate())) return $this->progressDate->getAmPm();
}
function getProgressMysqlDate() {
if (is_object($this->getProgressDate())) return $this->progressDate->getMysqlDate();
}
function getProgress() {
return $this->progress;
}
function getError() {
return $this->error;
}
//setters
function setConnection($value) {
$this->connection = $value;
}
function setGoalProgressId($value) {
$this->goalProgressId = $value;
}
function setGoalId($value) {
$this->goalId = $value;
}
function setProgressDate($value) {
$this->progressDate = $value;
}
function setProgressYear($value) {
if (is_object($this->getProgressDate())) $this->progressDate->setYear($value);
}
function setProgressMonth($value) {
if (is_object($this->getProgressDate())) $this->progressDate->setMonth($value);
}
function setProgressDay($value) {
if (is_object($this->getProgressDate())) $this->progressDate->setDay($value);
}
function setProgressHour($value) {
if (is_object($this->getProgressDate())) $this->progressDate->setHour($value);
}
function setProgressMinute($value) {
if (is_object($this->getProgressDate())) $this->progressDate->setMinute($value);
}
function setProgressSeconds($value) {
if (is_object($this->getProgressDate())) $this->progressDate->setSeconds($value);
}
function setProgressAmPm($value) {
if (is_object($this->getProgressDate())) $this->progressDate->setAmPm($value);
}
function setProgressMysqlDate($value) {
if (is_object($this->getProgressDate())) $this->progressDate->setMysqlDate($value);
}
function setProgress($value) {
$this->progress = $value;
}
function setError($value) {
$this->error = $value;
}
}
?>