function execute() { $return = new stdClass(); $params = Request::_REQUEST(); Config::set("HideDebugger", true); if (isset($params["id"])) { $user = new Member($params["id"]); if (isset($user) && $user->isValid()) { if ($params["passwd"] != "") { $user->setPassword($params["passwd"]); } $user->setLevel($params["level"]); $user->setIsEnabled($params["is_enabled"]); $user->setUserFirstname($params["userFirstname"]); $user->setUserLastname($params["userLastname"]); $user->setUserEmail($params["useremail"]); $user->setUserBio($params["userBio"]); $user->setWeb($params["web"]); $user->setUserCompany($params["userCompany"]); $user->setUserCompanyType($params["userCompanyType"]); $user->setUserAddr1($params["userAddr1"]); $user->setUserAddr2($params["userAddr2"]); $user->setUserCity($params["userCity"]); $user->setUserState($params["userState"]); $user->setUserCountry($params["userCountry"]); $user->setUserZip($params["userZip"]); $user->setUserPhone($params["userPhone"]); $user->setUserAltPhone($params["userAltPhone"]); $user->setUserFax($params["userFax"]); $user->setSiteAreas($params["siteAreas"]); $user->setUpdates($params["updates"]); $user->setPaymentType($params["paymentType"]); $user->setPaymentTypeDetails($params["paymentTypeDetails"]); $user->setShipAddr1($params["shipAddr1"]); $user->setShipAddr2($params["shipAddr2"]); $user->setShipCity($params["shipCity"]); $user->setShipState($params["shipState"]); $user->setShipCountry($params["shipCountry"]); $user->setShipZip($params["shipZip"]); if ($user->save()) { // encrypt any credit card information then set the CC field // check for an existing private key first $existing_privateKey = CryptKey::findCryptKeyByUserID($user->getID()); $cc_privateKey = null; if (isset($existing_privateKey) && $existing_privateKey->isValid()) { // retrieve existing key Debugger::log("User crypt private key: " . $existing_privateKey->getKey()); $cc_privateKey = $existing_privateKey->getKey(); } else { // store key into keys table $user_key = new CryptKey(); $user_key->setUserID($user->getID()); $user_key->setKey(TwoWayEncryption::genPrivateKey()); if ($user_key->save()) { Debugger::log("Saved user crypt private key."); $cc_privateKey = $user_key->getKey(); } else { Debugger::log("Saving user crypt private key failed! Refusing to encrypt contents!"); } } if (!is_null($cc_privateKey)) { $cc_data = unserialize(TwoWayEncryption::decrypt($user->getCC(), $cc_privateKey)); $cc_data = array_merge($cc_data, array("name" => $params["ccc_name"], "ccNum" => $params["ccc_ccNum"], "MM" => $params["ccc_MM"], "YY" => $params["ccc_YY"], "ccCODE" => $params["ccc_ccCode"])); $cc_encrypted_data = TwoWayEncryption::encrypt(serialize($cc_data), $cc_privateKey); $user->setCC($cc_encrypted_data); $user->save(); } $return->id = $user->getID(); $return->updated = true; echo json_encode($return); return; } else { $error = DatabaseFactory::passinggreen_db()->getLastError(); $return->error = "could not update Member object because: " . $error; echo json_encode($return); return; } } else { $return->error = "ID is invalid!"; echo json_encode($return); return; } } else { $return->error = "Missing ID!"; echo json_encode($return); return; } }
function execute() { $return = new stdClass(); $params = Request::_REQUEST(); Config::set("HideDebugger", true); //comment this out to debug if (isset($params["id"])) { $user = new Member($params["id"]); if (isset($user) && $user->isValid()) { // retrieve account balance based on transactions $user_balance = 0.0; $user_commission = 0.0; /* $Referral_Join = DBObject::collection("Referral"); $Member_Join = DBObject::collection("Member"); $Member_Vendor_Join = DBObject::collection("Member"); $Transactions = DBObject::collection("Transaction") ->applyJoin("LEFT OUTER", $Referral_Join, array("ReferralID", "AutoID")) ->applyJoin("LEFT OUTER", $Member_Join, array("UserID", "AutoID")) ->applyJoin("LEFT OUTER", $Member_Vendor_Join, array("VendorID", "AutoID")) ->applyUserIDFilter($user->getID()); Debugger::log(Var_Dump::display($Transactions->getTransactions(), true)); */ $q = "SELECT\n\t\t\t\tt.`amount`,\n\t\t\t\tr.*,\n\t\t\t\tCONCAT(user.`userFirstname`, CONCAT(' ',user.`userLastname`)) as _from,\n\t\t\t\tCONCAT(vendor.`userFirstname`, CONCAT(' ',vendor.`userLastname`)) as _to\n\t\t\tFROM `transactions` t\n\n\t\t\tLEFT OUTER JOIN `referrals` r\n\t\t\t\tON (t.`ReferralID` = r.`AutoID`)\n\n\t\t\tLEFT OUTER JOIN `user_signup` user\n\t\t\t\tON (r.`UserID` = user.`AutoID`)\n\n\t\t\tLEFT OUTER JOIN `user_signup` vendor\n\t\t\t\tON (r.`VendorID` = vendor.`AutoID`)\n\n\t\t\tWHERE t.`UserID` ='" . $user->getID() . "'"; $user_transactions = DatabaseFactory::passinggreen_db()->query($q); Debugger::log(Var_Dump::display($user_transactions, true)); while ($user_transactions_row = $user_transactions->fetch_object()) { if ($user_transactions_row->UserID == $user->getID()) { $user_balance += $user_transactions_row->amount; //$referrals_passed[] = $row; } else { if ($user_transactions_row->VendorID == $user->getID()) { $user_commission += $user_transactions_row->amount; //$referrals_received[] = $row; } } #else #echo "PG.com +".$row->amount."<br>"; #echo "<pre>".print_r($row, true)."</pre>"; } // referrals $user_referrals_passed = DBObject::collection("Referral", DBObject::CONSISTENCY_ABSOLUTE)->applyUserIDFilter($user->getID())->getReferralCount(); $user_referrals_received = DBObject::collection("Referral", DBObject::CONSISTENCY_ABSOLUTE)->applyVendorIDFilter($user->getID())->getReferralCount(); Debugger::log("refs passed: {$user_referrals_passed}"); Debugger::log("refs recvd: {$user_referrals_received}"); // decrypt cc field if it is not empty $user_crypt_key = CryptKey::findCryptKeyByUserID($user->getID()); if (isset($user_crypt_key) && $user_crypt_key->isValid()) { Debugger::log("User crypt private key: " . $user_crypt_key->getKey()); $decoded_cc_data = unserialize(TwoWayEncryption::decrypt($user->getCC(), $user_crypt_key->getKey())); } else { $decoded_cc_data = null; } $return->id = $user->getID(); // object id $return->user = $user->toArray(); // set the base return, values can be overridden below. $return->user["userCompanyType[]"] = $user->getUserCompanyType(); $return->user["siteAreas[]"] = $user->getSiteAreas(); $return->user["passwd"] = null; $return->user["balance"] = number_format($user_balance, 2); if (!is_null($decoded_cc_data)) { $return->user["ccc"] = $decoded_cc_data["details"]; $return->user["ccc_status"] = $decoded_cc_data["status"]; $return->user["ccc_tcode"] = $decoded_cc_data["tcode"]; $return->user["ccc_name"] = $decoded_cc_data["name"]; $return->user["ccc_ccNum"] = $decoded_cc_data["ccNum"]; $return->user["ccc_MM"] = $decoded_cc_data["MM"]; $return->user["ccc_YY"] = $decoded_cc_data["YY"]; $return->user["ccc_ccCode"] = $decoded_cc_data["ccCODE"]; } $return->user["referralsPassed"] = $user_referrals_passed; $return->user["referralsReceived"] = $user_referrals_received; $return->user["accountBalance"] = number_format($user_balance, 2); $return->user["commissionDue"] = number_format($user_commission, 2); echo json_encode($return); return; } else { $return->error = "ID is invalid."; echo json_encode($return); return; } } else { $return->error = "Missing ID!"; echo json_encode($return); return; } }