2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/19/2003 *
4 * =================== Last change: 08/12/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-points.php *
8 * -------------------------------------------------------------------- *
9 * Short description : All your collected points... *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Alle Ihrer gesammelten Punkte *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2015 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Sets a status message and code
44 function setWernisStatusMessage ($message, $status) {
45 $GLOBALS['wernis_data']['message'] = $message;
46 $GLOBALS['wernis_data']['status'] = $status;
49 // Get the status message
50 function getWernisErrorMessage () {
51 if (isset($GLOBALS['wernis_data']['message'])) {
53 return $GLOBALS['wernis_data']['message'];
54 } elseif (isset($GLOBALS['wernis_data']['status'])) {
55 // Fall-back to status
56 return '{%message,WERNIS_ERROR_STATUS=' . $GLOBALS['wernis_data']['status'] . '%}';
58 // Something bad happend
59 return '{--WERNIS_UNKNOWN_ERROR--}';
63 // Get the status code
64 function getWernisErrorCode () {
65 if (isset($GLOBALS['wernis_data']['status'])) {
67 return $GLOBALS['wernis_data']['status'];
69 // Something bad happend
70 return '{--WERNIS_UNKNOWN_ERROR--}';
74 // Sends out a request to the API and returns it's result
75 function sendWernisApiRequest ($scriptName, $requestData = array()) {
77 //* DEBUG */ reportBug(__FUNCTION__, __LINE__, 'scriptName=' . $scriptName . ',requestData=<pre>' . print_r($requestData, TRUE) . '</pre>');
79 // Is the requestData an array?
80 if (!is_array($requestData)) {
83 'status' => 'failed_general',
84 'message' => '{--WERNIS_API_REQUEST_DATA_INVALID--}'
88 // Is the API id and MD5 hash there?
89 if ((getWernisApiId() == '') || (getWernisApiMd5() == '')) {
92 'status' => 'failed_general',
93 'message' => '{--WERNIS_API_REQUEST_DATA_MISSING--}'
97 // Add more request data
98 $requestData['api_id'] = getWernisApiId();
99 $requestData['api_key'] = getWernisApiMd5();
101 // Is a purpose there?
102 if (!empty($requestData['purpose'])) {
104 eval('$purpose = "' . doFinalCompilation($requestData['purpose'], FALSE) . '";');
106 // Prepare the purpose, it needs encoding
107 $requestData['purpose'] = encodeString($purpose);
110 // Construct the request string
111 $requestString = getWernisApiUrl() . $scriptName;
113 // Get the raw response from the lower function
114 $response = sendHttpPostRequest($requestString, $requestData);
116 // Check the response header if all is fine
117 if (!isHttpStatusOkay($response[0])) {
118 // Something bad happend... :(
120 'status' => 'request_error',
121 'message' => '{%message,WERNIS_API_REQUEST_ERROR=' . $response[0] . '%}'
125 // All (maybe) fine so remove the response header from server
126 $responseLine = '*INVALID*';
127 for ($idx = (count($response) - 1); $idx > 1; $idx--) {
128 $line = trim($response[$idx]);
130 $responseLine = $line;
135 // Is the response leaded by a & symbol?
136 if (substr($responseLine, 0, 1) != '&') {
137 // Something badly happened on server-side
139 'status' => 'request_problem',
140 'message' => sprintf(getMessage('WERNIS_API_REQUEST_PROBLEM'), $response[0], secureString($responseLine))
144 // Remove the leading & (which can be used in Flash)
145 $responseLine = substr($responseLine, 1);
147 // Bring back the response
148 $data = explode('=', $responseLine);
150 // Default return array (should not stay empty)
153 // We use only the first two entries (which shall be fine)
154 if ($data[0] === 'error') {
155 // The request has failed... :(
157 case '404': // Invalid API id
158 case 'AUTH': // Authorization has failed
160 'status' => 'auth_failed',
161 'message' => '{--WERNIS_API_REQUEST_FAILED_AUTH--}'
165 case 'LOCKED': // User account is locked!
166 case 'PASS': // Bad passphrase entered
167 case 'USER': // Missing account or invalid password
169 'status' => 'user_failed',
170 'message' => '{--WERNIS_API_REQUEST_FAILED_USER--}'
174 case 'OWN': // Transfer to own account
176 'status' => 'own_failed',
177 'message' => '{--WERNIS_API_REQUEST_FAILED_OWN--}'
181 case 'AMOUNT': // Amount is depleted
183 'status' => 'amount_failed',
184 'message' => '{--WERNIS_API_REQUEST_FAILED_AMOUNT--}'
188 case 'AMOUNT-SEND': // API amount is depleted
190 'status' => 'api_amount_failed',
191 'message' => '{--WERNIS_API_REQUEST_FAILED_API_AMOUNT--}'
195 default: // Unknown error (maybe new?)
196 logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unknown error %s from WDS66 API received.', $data[1]));
198 'status' => 'request_failed',
199 'message' => '{%message,WERNIS_API_REQUEST_FAILED=' . $data[1] . '%}'
204 // All fine, then analyze API response
205 $return = convertApiResponseToArray($responseLine, '&', '=');
207 // Nothing is fine now
208 $return['status'] = 'generic_failed';
209 $return['message'] = '--WERNIS_API_REQUEST_FAILED_GENERIC--}';
211 // Are 'encrypted', 'key' and 'iv' set?
212 //* DEBUG-DIE */ die(__FUNCTION__ . ':return=<pre>' . print_r($return, TRUE) . '</pre>');
213 if ((isset($return['encrypted'])) && (isset($return['key'])) && (isset($return['iv']))) {
214 // Fully decode it (URL-encoded BASE64)
215 $decoded = decodeString($return['encrypted']);
216 $iv = decodeString($return['iv']);
218 // Generate decryption key
219 $decryptionKey = generateWernisDecryptionKey($return['key']);
222 $decrypted = decrytStringByCipher($decoded, getWernisEncryptionAlgorithm(), getWernisEncryptionMode(), $decryptionKey, $iv);
223 //* DEBUG-DIE */ die('key="' . $return['key'] . '"<br />decryptionKey="' . $decryptionKey . '"<br />decoded="' . $decoded . '"<br />decrypted="' . $decrypted . '"');
225 // First char must be an &
226 assert(substr($decrypted, 0, 1) == '&');
228 // Now the string needs to be turned into an array, first explode all &
229 $elements = explode('&', $decrypted);
231 // And remove first element
232 array_shift($elements);
233 //* DEBUG-DIE */ die('elements=<pre>' . print_r($elements, TRUE) . '</pre>');
235 // Now "walk" all ements
236 foreach ($elements as $idx => $element) {
238 $keyValue = explode('=', $element);
240 // Make sure it is valid
241 assert(count($keyValue) == 2);
243 // Now handle all over
244 $return[$keyValue[0]] = $keyValue[1];
247 // Remove encryption stuff
248 unset($return['encrypted'], $return['key'], $return['iv']);
252 $return['status'] = 'OK';
253 $return['message'] = NULL;
257 //* DEBUG-DIE */ die(__FUNCTION__ . ':return=<pre>' . print_r($return, TRUE) . '</pre>');
261 // Tests the function by calling balance.php on the API
262 function doAdminTestWernisApi () {
266 // Result is always failed
269 // Prepare the request data
270 $requestData = array(
271 't_uid' => getWernisRefid(),
272 't_md5' => getWernisPassMd5()
275 // Return the result from the lower functions
276 $return = sendWernisApiRequest('balance.php', $requestData);
278 // Did it went smoothly?
279 if (isHttpResponseStatusOkay($return)) {
283 // Status failure text
284 setWernisStatusMessage($return['message'], $return['status']);
291 // Widthdraw this amount
292 function executeWernisApiWithdraw ($wdsId, $userMd5, $amount) {
293 // Is the sponsor extension installed?
294 if (!isWernisWithdrawActive()) {
295 if (!isExtensionActive('sponsor')) {
298 } elseif (!isSponsor()) {
299 // No sponsor, not allowed to withdraw!
304 // Default is failed attempt
307 // Prepare the request data
308 $requestData = array(
309 'sub_request' => 'receive',
310 't_uid' => bigintval($wdsId),
312 'r_uid' => getWernisRefid(),
313 'amount' => bigintval($amount),
314 'purpose' => getMaskedMessage('WERNIS_API_PURPOSE_WITHDRAW', getMemberId())
317 // Return the result from the lower functions
318 $return = sendWernisApiRequest('book.php', $requestData);
320 // Did it went smoothly?
321 if (isHttpResponseStatusOkay($return)) {
326 logWernisTransfer($wdsId, $amount, 'WITHDRAW');
328 // Status failure text
329 setWernisStatusMessage($return['message'], $return['status']);
332 logWernisTransfer($wdsId, $amount, 'FAILED', $return['message'], $return['status']);
339 // Payout this amount
340 function executeWernisApiPayout ($wdsId, $amount) {
341 // Default is failed attempt
344 // Prepare the request data
345 $requestData = array(
346 'sub_request' => 'send',
347 't_uid' => getWernisRefid(),
348 't_md5' => getWernisPassMd5(),
349 'r_uid' => bigintval($wdsId),
350 'amount' => bigintval($amount),
351 'purpose' => getMaskedMessage('WERNIS_API_PURPOSE_PAYOUT', getMemberId())
354 // Return the result from the lower functions
355 $return = sendWernisApiRequest('book.php', $requestData);
357 if (isHttpResponseStatusOkay($return)) {
362 logWernisTransfer($wdsId, $amount, 'PAYOUT');
364 // Status failure text
365 setWernisStatusMessage($return['message'], $return['status']);
368 logWernisTransfer($wdsId, $amount, 'FAILED', $return['message'], $return['status']);
375 // Execute auth.php request
376 function executeWernisApiAuth ($wernisId, $wernisPassword) {
377 // Prepare request data
378 $requestData = array(
379 't_uid' => bigintval($wernisId),
380 't_md5' => hashSha256($wernisPassword),
384 $return = sendWernisApiRequest('auth.php', $requestData);
390 // Execute get.php reguest with given auth data (not all are used)
391 function executeWernisApiGet ($authData, $subRequest, $fields) {
392 // It must be an array
393 assert(is_array($authData));
395 // Check required array elements
396 assert(isset($authData['wernis_userid']));
397 assert(isset($authData['api_auth_key']));
398 assert(isset($authData['api_redirect_challenge']));
400 // Then create request array
401 $requestData = array(
402 'sub_request' => $subRequest,
404 't_uid' => bigintval($authData['wernis_userid']),
405 't_md5' => getWernisPassMd5(),
406 'auth_key' => $authData['api_auth_key'],
407 'challenge' => $authData['api_redirect_challenge']
411 $return = sendWernisApiRequest('get.php', $requestData);
417 // Translate the status IN/OUT
418 function translateWernisTransferStatus ($status) {
419 // Default status is unknown
420 $return = '{%message,WERNIS_STATUS_UNKNWOWN=' . $status . '%}';
422 // Construct message id
423 $messageId = 'WERNIS_STATUS_' . $status;
426 if (isMessageIdValid($messageId)) {
427 // Then use it as message string
428 $return = '{--' . $messageId . '--}';
436 function logWernisTransfer ($wdsId, $amount, $type = 'FAILED', $message = '', $status = '') {
437 // Register this wernis movement
438 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_user_wernis` (`userid`, `wernis_account`, `wernis_amount`, `wernis_timestamp`, `wernis_type`, `wernis_api_message`, `wernis_api_status`) VALUES (%s, %s, %s, UNIX_TIMESTAMP(), '%s', '%s', '%s')",
446 ), __FUNCTION__, __LINE__);
449 // Calulcate fees and factor
450 function calculateWernisFee ($points, $mode) {
451 // Payout or withdraw are allowed modes!
452 //* DEBUG: */ debugOutput('mode=' . $mode . ',points=' . $points);
453 if (!in_array($mode, array('payout', 'withdraw'))) {
454 // Log error and abort
455 logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . getMemberId() . ',mode=' . $mode . ',points=' . $points . ' - unknown mode detected.');
459 // Is there a percentage or fixed fee?
460 if (getConfig('wernis_' . $mode . '_fee_percent') > 0) {
462 $points -= $points * getConfig('wernis_'.$mode.'_fee_percent') / 100;
463 } elseif (getConfig('wernis_' . $mode . '_fee_fix') > 0) {
465 $points -= getConfig('wernis_' . $mode . '_fee_fix');
468 // Divide/multiply the factor
469 if ($mode == 'payout') {
471 $points = $points / getWernisPayoutFactor();
473 // Multiply for withdraw
474 $points = $points * getWernisWithdrawFactor();
478 //* DEBUG: */ debugOutput('mode=' . $mode . ',points=' . $points);
482 // Add withdraw fees and factor
484 function calulcateWernisWithdrawFee ($points) {
485 // Is there a percentage or fixed fee?
486 if (getWernisWithdrawFeePercent() > 0) {
488 $points += $points * getWernisWithdrawFeePercent() / 100;
489 } elseif (getWernisWithdrawFeeFix() > 0) {
491 $points += getWernisWithdrawFeeFix();
498 // Displays registration form for WDS66 registration
499 function doDisplayWernisUserRegistrationForm () {
501 if (isFormSent('register')) {
503 if (!isPostRequestElementSet('wernis_id')) {
505 displayMessage('{--GUEST_WERNIS_REGISTRATION_ID_NOT_SET--}');
506 } elseif (!isPostRequestElementSet('wernis_password')) {
508 displayMessage('{--GUEST_WERNIS_REGISTRATION_PASSWORD_NOT_SET--}');
510 // So far, all fine, then let's do the call-back on auth.php ...
511 $args = executeWernisApiAuth(postRequestElement('wernis_id'), postRequestElement('wernis_password'));
514 if (isHttpResponseStatusOkay($args)) {
516 //* DEBUG-DIE */ die('response=<pre>' . print_r($response, TRUE) . '</pre>,args=' . '<pre>'.print_r($args, TRUE).'</pre>');
517 assert(isset($args['auth_status']));
520 $args['wernis_userid'] = postRequestElement('wernis_id');
522 // "Detect" auth status
523 $callbackFunction = 'doWernisAuth' . capitalizeUnderscoreString($args['auth_status']);
525 // Is the call-back there?
526 if (!is_callable($callbackFunction, FALSE, $callableName)) {
527 // Not there, could be bad. :(
528 reportBug(__FUNCTION__, __LINE__, 'Unsupported auth_status=' . $args['auth_status'] . ',args()=' . count($args) . ',callbackFunction=' . $callbackFunction . ' detected.');
532 $status = call_user_func($callbackFunction, $args);
534 // @TODO Something more to do here?
535 die(__FUNCTION__ . ':' . __LINE__ . ': status[' . gettype($status) . ']=' . $status . ' - Unfinished.');
537 // Something bad happened
538 displayMessage($args['message']);
543 // Is there a challenge + response?
544 if ((isGetRequestElementSet('status')) && (isGetRequestElementSet('challenge')) && (isGetRequestElementSet('__challenge_response'))) {
545 // Redirect from modules.php?module=auth, so validate challenge response ...
546 // 1) Get first 24 characters = salt
547 $salt = substr(getRequestElement('__challenge_response'), 0, 24);
549 // 2) Generate hash for challenge response
550 $challengeResponse = $salt . hashSha256($salt . getWernisApiMd5() . getRequestElement('challenge'));
552 // Is the response valid?
553 if ($challengeResponse != getRequestElement('__challenge_response')) {
555 displayMessage('{--GUEST_WERNIS_REGISTRATION_INVALID_CHALLENGE_RESPONSE--}');
560 * Now, that the challenge-response is the same, the challenge itself
561 * is also the same. Next get the data from wernis_regs table by
562 * challenge. There is currently no other way to get the data as there
563 * is no Wernis user id provided. Later on the stored challenge response
564 * can be compared with provided.
566 $return = doWernisFinishUserRegistration(getRequestElement('challenge'), getRequestElement('__challenge_response'), getRequestElement('status'));
568 // Is the registration finished?
569 if ($return === FALSE) {
570 // No, then abort here silently as the function should have already displayed a message
573 } elseif (!isFormSent('register')) {
574 // Form not send, so load form template
575 loadTemplate('guest_wernis_registration_rpc_form');
579 // Finish user registration with WDS66 API
580 function doWernisFinishUserRegistration ($challenge, $challengeResponse, $status) {
581 // Is the status 1? (= all fine with API call)
582 if ($status == '1') {
583 // Get mapped data based on challenge
584 $return = getWernisMappedDataFromApiByChallenge($challenge, $status);
586 // Is the array filled?
587 //* DEBUG-DIE */ die(__METHOD__ . ':return=<pre>' . print_r($return, TRUE) . '</pre> - EXIT!');
588 if ((isset($return['mapped_data'])) && (count($return['mapped_data']) > 0) && (empty($return['message']))) {
589 // Set must-fillout fields
590 $return['mapped_data'] = runFilterChain('register_must_fillout', $return['mapped_data']);
592 // Add missing elements
593 $return['mapped_data']['gender'] = NULL;
594 $return['mapped_data']['birthday_selection'] = generateDayMonthYearSelectionBox($return['mapped_data']['birth_day'], $return['mapped_data']['birth_month'], $return['mapped_data']['birth_year']);
595 $return['mapped_data']['challenge'] = getRequestElement('challenge');
596 $return['mapped_data']['__challenge_response'] = getRequestElement('__challenge_response');
599 loadTemplate('guest_wernis_registration_form', FALSE, $return['mapped_data']);
604 // Something unexpected happened (e.g. no API requests left)
605 displayMessage($return['message']);
609 // Status does not need to be changed
610 die(__FUNCTION__ . ':' . __LINE__ . ': Reached!');
614 // "Getter" for mapped data by calling the API and given challenge and status
615 function getWernisMappedDataFromApiByChallenge ($challenge, $status) {
616 // Get stored registration data
617 $rows = getWernisRegistrationDataByKey('api_redirect_challenge', $challenge);
619 // Zero result found?
620 if (count($rows) == 0) {
622 displayMessage('{--GUEST_WERNIS_REGISTRATION_ZERO_ROWS_FOUND--}');
625 loadTemplate('guest_wernis_registration_rpc_form');
632 'mapped_data' => array(),
633 // Any error message from API
637 // Has the auth status changed?
638 if ($rows[0]['api_auth_status'] != 'ACCEPTED') {
640 * The authorization of this application has been accepted, so
641 * update it and ignore result from function because the update
644 updateWernisRegistrationDataByKey('api_auth_status', 'api_redirect_challenge', $challenge, 'ACCEPTED');
647 // Now call "get.php"
648 $response = executeWernisApiGet($rows[0], 'data', 'vorname|name|strasse|plz|ort|birth_day|birth_month|birth_year|email|werber');
650 // Was the status okay?
651 //* DEBUG-DIE */ die(__FUNCTION__ . ':response=<pre>' . print_r($response, TRUE) . '</pre>');
652 if (isHttpResponseStatusOkay($response)) {
653 // API returned non-errous response, 'data=' must be found
654 assert(isset($response['data']));
656 // And decode it (all steps separated to later "easily" debug them)
657 $decodedData = base64_decode(urldecode($response['data']));
658 //* DEBUG-DIE */ die(__FUNCTION__ . ':decodedData=' . $decodedData);
661 * Do some checks on the decoded string, it should be a
662 * serialized array with 10 entries (see above
663 * executeWernisApiGet() call).
665 assert(substr($decodedData, 0, 6) == 'a:10:{');
666 assert(substr($decodedData, -1, 1) == '}');
668 // The array seems to be fine, unserialize it
669 $userData = unserialize($decodedData);
670 //* DEBUG-DIE */ die(__METHOD__ . ':userData=<pre>' . print_r($userData, TRUE) . '</pre> - EXIT!');
672 // All mappings WDS66->mailer
674 'vorname' => 'surname',
676 'strasse' => 'street_nr',
680 'birth_day' => 'birth_day',
681 'birth_month' => 'birth_month',
682 'birth_year' => 'birth_year',
683 'werber' => 'wernis_refid'
686 // Map all WDS66 entries into mailer entries
687 foreach ($mappings as $from => $to) {
689 if (!isset($userData[$from])) {
690 // Element $from does not exist
691 reportBug(__FUNCTION__, __LINE__, 'Cannot map from=' . $from . ' -> to=' . $to . ': element does not exist.');
695 $return['mapped_data'][$to] = convertEmptyToNull($userData[$from]);
698 // Both arrays must have same size
699 assert(count($userData) == count($return['mapped_data']));
701 // Now add userid from WDS66
702 $return['mapped_data']['wernis_userid'] = bigintval($rows[0]['wernis_userid']);
704 // Something bad happened so copy the message
705 $return['message'] = $response['message'];
708 // Return mapped data array
709 //* DEBUG-DIE */ die(__METHOD__ . ':return=<pre>' . print_r($return, TRUE) . '</pre> - EXIT!');
713 // Updates auth status by given key/value pair
714 function updateWernisRegistrationDataByKey ($updatedColumn, $key, $oldValue, $newValue) {
716 sqlQueryEscaped("UPDATE
717 `{?_MYSQL_PREFIX?}_wernis_regs`
731 ), __FUNCTION__, __LINE__
734 // Check if rows as been affected
735 return ifSqlHasZeroAffectedRows();
738 // "Getter" for Wernis registration data by given key and value
739 function getWernisRegistrationDataByKey ($key, $value, $limit = 1) {
744 $result = sqlQueryEscaped("SELECT
749 `api_redirect_challenge`,
750 UNIX_TIMESTAMP(`record_inserted`) AS `record_inserted`
752 `{?_MYSQL_PREFIX?}_wernis_regs`
762 ), __FUNCTION__, __LINE__
765 // Is there an entry?
766 if (sqlNumRows($result) > 0) {
767 // At least one entry has been found, so loop through all
768 while ($row = sqlFetchArray($result)) {
770 array_push($rows, $row);
775 sqlFreeResult($result);
777 // Return found entries
781 // Do local user registration with data from WDS66 API
782 function doWernisUserRegistration () {
783 // Call generic registration function
784 $status = doGenericUserRegistration();
786 // Does this went fine?
787 if ($status === FALSE) {
788 // No, then abort here silently
792 // Make sure the user id is valid
793 assert(isset($GLOBALS['register_userid']));
794 assert(isValidId($GLOBALS['register_userid']));
796 // Generic registration is finished, so add more data:
799 // Generates decrption key based on private key, public key and API key
800 function generateWernisDecryptionKey ($publicKey) {
801 // Generate key from most known data
802 $key = hashSha256(sprintf(
805 getWernisPrivateKey(),
813 //-----------------------------------------------------------------------------
814 // Auth status callback functions
815 //-----------------------------------------------------------------------------
817 // Handler for auth_status=PENDING
818 function doWernisAuthPending ($args) {
819 // $args must always be an array
820 assert(is_array($args));
822 // auth_key and wernis_userid must be set
823 assert(isset($args['auth_key']));
824 assert(isset($args['wernis_userid']));
826 // Generate a challenge that will be added to the URL
827 $challenge = hashSha256(generatePassword(128));
829 // Search entry in database by auth_key
830 if (countSumTotalData($args['auth_key'], 'wernis_regs', 'id', 'api_auth_key', TRUE) == 0) {
831 // "Register" this call
832 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_wernis_regs` (
836 `api_redirect_challenge`
844 bigintval($args['wernis_userid']),
847 ), __FUNCTION__, __LINE__
851 sqlQueryEscaped("UPDATE
852 `{?_MYSQL_PREFIX?}_wernis_regs`
854 `api_redirect_challenge`='%s'
856 `api_auth_key`='%s' AND
857 `wernis_userid`=%s AND
858 `api_auth_status`='PENDING'
863 bigintval($args['wernis_userid'])
864 ), __FUNCTION__, __LINE__
868 // Should always update/insert
869 assert(sqlAffectedRows() == 1);
871 // Redirect to WDS66 module=auth ...
872 //* DEBUG-DIE */ die(__FUNCTION__ . ':' . __LINE__ . '<pre>' . print_r($args, TRUE) . '</pre>');
873 redirectToUrl(getWernisBaseUrl() . '/modules.php?module=auth&auth_key=' . trim($args['auth_key']) . '&params=' . urlencode(base64_encode('&module=' . getModule() . '&what=' . getWhat())) . '&challenge=' . $challenge, FALSE, FALSE);
876 // Handler for auth_status=ACCEPTED
877 function doWernisAuthAccepted ($args) {
878 // $args must always be an array
879 assert(is_array($args));
881 // auth_key and wernis_userid must be set
882 assert(isset($args['auth_key']));
883 assert(isset($args['wernis_userid']));
884 die(__FUNCTION__ . ':' . __LINE__ . '<pre>' . print_r($args, TRUE) . '</pre>');
887 //------------------------------------------------------------------------------
888 // Template helper functions
889 //------------------------------------------------------------------------------
891 // Template helper to generate a selection box for encryption alogrithms
892 function doTemplateSelectWernisEncryptionAlgorithm ($templateName, $clear = FALSE, $default = NULL) {
893 // Get all available algorithms
894 $algorithms = getSupportedEncryptionAlgorithms();
895 //* DEBUG-DIE */ die('algorithms=<pre>' . print_r($algorithms, TRUE) . '</pre>');
901 foreach ($algorithms as $key => $dummy) {
902 $options[$key] = array('algorithms' => $key);
905 // Handle it over to generateSelectionBoxFromArray()
906 $content = generateSelectionBoxFromArray($options, 'wernis_encryption_algorithm', 'algorithms', '', '_wernis', '', $default, '', TRUE, FALSE);
908 // Return prepared content
912 // Template helper to generate a selection box for encryption alogrithms
913 function doTemplateSelectWernisEncryptionMode ($templateName, $clear = FALSE, $default = NULL) {
914 // Get all available modes
915 $modes = getSupportedEncryptionModes();
921 foreach ($modes as $key => $dummy) {
922 $options[$key] = array('modes' => $key);
925 // Handle it over to generateSelectionBoxFromArray()
926 $content = generateSelectionBoxFromArray($options, 'wernis_encryption_mode', 'modes', '', '_wernis', '', $default, '', TRUE, FALSE);
928 // Return prepared content
932 //-----------------------------------------------------------------------------
934 //-----------------------------------------------------------------------------
936 // Wrapper function for 'wernis_refid'
937 function getWernisRefid () {
939 if (!isset($GLOBALS[__FUNCTION__])) {
941 $GLOBALS[__FUNCTION__] = getConfig('wernis_refid');
945 return $GLOBALS[__FUNCTION__];
948 // Wrapper function for 'wernis_pass_md5'
949 function getWernisPassMd5 () {
951 if (!isset($GLOBALS[__FUNCTION__])) {
953 $GLOBALS[__FUNCTION__] = getConfig('wernis_pass_md5');
957 return $GLOBALS[__FUNCTION__];
960 // Wrapper function for 'wernis_api_id'
961 function getWernisApiId () {
963 if (!isset($GLOBALS[__FUNCTION__])) {
965 $GLOBALS[__FUNCTION__] = getConfig('wernis_api_id');
969 return $GLOBALS[__FUNCTION__];
972 // Wrapper function for 'wernis_api_md5'
973 function getWernisApiMd5 () {
975 if (!isset($GLOBALS[__FUNCTION__])) {
977 $GLOBALS[__FUNCTION__] = getConfig('wernis_api_md5');
981 return $GLOBALS[__FUNCTION__];
984 // Wrapper function for 'wernis_api_url'
985 function getWernisApiUrl () {
987 if (!isset($GLOBALS[__FUNCTION__])) {
989 $GLOBALS[__FUNCTION__] = getConfig('wernis_api_url');
993 return $GLOBALS[__FUNCTION__];
996 // Wrapper function for 'wernis_withdraw_active'
997 function getWernisWithdrawActive () {
999 if (!isset($GLOBALS[__FUNCTION__])) {
1001 $GLOBALS[__FUNCTION__] = getConfig('wernis_withdraw_active');
1005 return $GLOBALS[__FUNCTION__];
1008 // Wrapper function for 'wernis_payout_active'
1009 function getWernisPayoutActive () {
1011 if (!isset($GLOBALS[__FUNCTION__])) {
1013 $GLOBALS[__FUNCTION__] = getConfig('wernis_payout_active');
1017 return $GLOBALS[__FUNCTION__];
1020 // Wrapper function for 'wernis_withdraw_active'
1021 function isWernisWithdrawActive () {
1023 if (!isset($GLOBALS[__FUNCTION__])) {
1025 $GLOBALS[__FUNCTION__] = (getConfig('wernis_withdraw_active') == 'Y');
1029 return $GLOBALS[__FUNCTION__];
1032 // Wrapper function for 'wernis_payout_active'
1033 function isWernisPayoutActive () {
1035 if (!isset($GLOBALS[__FUNCTION__])) {
1037 $GLOBALS[__FUNCTION__] = (getConfig('wernis_payout_active') == 'Y');
1041 return $GLOBALS[__FUNCTION__];
1044 // Wrapper function for 'wernis_withdraw_factor'
1045 function getWernisWithdrawFactor () {
1047 if (!isset($GLOBALS[__FUNCTION__])) {
1049 $GLOBALS[__FUNCTION__] = getConfig('wernis_withdraw_factor');
1053 return $GLOBALS[__FUNCTION__];
1056 // Wrapper function for 'wernis_payout_factor'
1057 function getWernisPayoutFactor () {
1059 if (!isset($GLOBALS[__FUNCTION__])) {
1061 $GLOBALS[__FUNCTION__] = getConfig('wernis_payout_factor');
1065 return $GLOBALS[__FUNCTION__];
1068 // Wrapper function for 'wernis_withdraw_fee_percent'
1069 function getWernisWithdrawFeePercent () {
1071 if (!isset($GLOBALS[__FUNCTION__])) {
1073 $GLOBALS[__FUNCTION__] = getConfig('wernis_withdraw_fee_percent');
1077 return $GLOBALS[__FUNCTION__];
1080 // Wrapper function for 'wernis_withdraw_fee_fix'
1081 function getWernisWithdrawFeeFix () {
1083 if (!isset($GLOBALS[__FUNCTION__])) {
1085 $GLOBALS[__FUNCTION__] = getConfig('wernis_withdraw_fee_fix');
1089 return $GLOBALS[__FUNCTION__];
1092 // Wrapper function for 'wernis_payout_fee_percent'
1093 function getWernisPayoutFeePercent () {
1095 if (!isset($GLOBALS[__FUNCTION__])) {
1097 $GLOBALS[__FUNCTION__] = getConfig('wernis_payout_fee_percent');
1101 return $GLOBALS[__FUNCTION__];
1104 // Wrapper function for 'wernis_payout_fee_fix'
1105 function getWernisPayoutFeeFix () {
1107 if (!isset($GLOBALS[__FUNCTION__])) {
1109 $GLOBALS[__FUNCTION__] = getConfig('wernis_payout_fee_fix');
1113 return $GLOBALS[__FUNCTION__];
1116 // Wrapper function for 'wernis_min_payout'
1117 function getWernisMinPayout () {
1119 if (!isset($GLOBALS[__FUNCTION__])) {
1121 $GLOBALS[__FUNCTION__] = getConfig('wernis_min_payout');
1125 return $GLOBALS[__FUNCTION__];
1128 // Wrapper function for 'wernis_min_withdraw'
1129 function getWernisMinWithdraw () {
1131 if (!isset($GLOBALS[__FUNCTION__])) {
1133 $GLOBALS[__FUNCTION__] = getConfig('wernis_min_withdraw');
1137 return $GLOBALS[__FUNCTION__];
1140 // Wrapper function for 'wernis_base_url'
1141 function getWernisBaseUrl () {
1143 if (!isset($GLOBALS[__FUNCTION__])) {
1145 $GLOBALS[__FUNCTION__] = getConfig('wernis_base_url');
1149 return $GLOBALS[__FUNCTION__];
1152 // Wrapper function for 'wernis_encryption_algorithm'
1153 function getWernisEncryptionAlgorithm () {
1155 if (!isset($GLOBALS[__FUNCTION__])) {
1157 $GLOBALS[__FUNCTION__] = getConfig('wernis_encryption_algorithm');
1161 return $GLOBALS[__FUNCTION__];
1164 // Wrapper function for 'wernis_encryption_mode'
1165 function getWernisEncryptionMode () {
1167 if (!isset($GLOBALS[__FUNCTION__])) {
1169 $GLOBALS[__FUNCTION__] = getConfig('wernis_encryption_mode');
1173 return $GLOBALS[__FUNCTION__];
1176 // Wrapper function for 'wernis_private_key'
1177 function getWernisPrivateKey () {
1179 if (!isset($GLOBALS[__FUNCTION__])) {
1181 $GLOBALS[__FUNCTION__] = getConfig('wernis_private_key');
1185 return $GLOBALS[__FUNCTION__];