Opps, not all elements for sprintf() has been set.
[mailer.git] / inc / libs / wernis_functions.php
index 90e88a01e7ffe298f3c3067112999490019b6e3a..263e40935d67291ca4f4e33c84b604d0e37058ce 100644 (file)
@@ -219,8 +219,8 @@ function doAdminTestWernisApi () {
 
        // Prepare the request data
        $requestData = array(
-               't_uid'       => getWernisRefid(),
-               't_md5'       => getWernisPassMd5()
+               't_uid' => getWernisRefid(),
+               't_md5' => getWernisPassMd5()
        );
 
        // Return the result from the lower functions
@@ -268,6 +268,7 @@ function executeWernisApiWithdraw ($wdsId, $userMd5, $amount) {
        // Return the result from the lower functions
        $return = sendWernisApiRequest('book.php', $requestData);
 
+       // Did it went smoothly?
        if (isHttpResponseStatusOkay($return)) {
                // All fine!
                $result = TRUE;
@@ -529,21 +530,29 @@ function doDisplayWernisUserRegistrationForm () {
 
 // Finish user registration with WDS66 API
 function doWernisFinishUserRegistration ($challenge, $challengeResponse, $status) {
-       // Check status from GET parameters and stored value
-       if (($status == '1') && (isFormSent('wernis_register'))) {
-               // Form has been sent
-               die(__FUNCTION__ . ':' . __LINE__ . ': Reached!');
-       } elseif ($status == '1') {
+       // Is the status 1? (= all fine with API call)
+       if ($status == '1') {
                // Get mapped data based on challenge
-               $return = getWernisMapedDataFromApiByChallenge($challenge, $status);
+               $return = getWernisMappedDataFromApiByChallenge($challenge, $status);
 
                // Is the array filled?
                if ((count($return['mapped_data']) > 0) && (empty($return['message']))) {
+                       // Set must-fillout fields
+                       $return['mapped_data'] = runFilterChain('register_must_fillout', $return['mapped_data']);
+
+                       // Add missing elements
+                       $return['mapped_data']['gender']               = NULL;
+                       $return['mapped_data']['birthday_selection']   = generateDayMonthYearSelectionBox($return['mapped_data']['birth_day'], $return['mapped_data']['birth_month'], $return['mapped_data']['birth_year']);
+                       $return['mapped_data']['challenge']            = getRequestElement('challenge');
+                       $return['mapped_data']['__challenge_response'] = getRequestElement('__challenge_response');
+
                        // Display form
                        loadTemplate('guest_wernis_registration_form', FALSE, $return['mapped_data']);
+
+                       // All fine
                        return TRUE;
                } else {
-                       // Something bad happened
+                       // Something unexpected happened (e.g. no API requests left)
                        displayMessage($return['message']);
                        return FALSE;
                }
@@ -554,7 +563,7 @@ function doWernisFinishUserRegistration ($challenge, $challengeResponse, $status
 }
 
 // "Getter" for mapped data by calling the API and given challenge and status
-function getWernisMapedDataFromApiByChallenge ($challenge, $status) {
+function getWernisMappedDataFromApiByChallenge ($challenge, $status) {
        // Get stored registration data
        $rows = getWernisRegistrationDataByKey('api_redirect_challenge', $challenge);
 
@@ -587,7 +596,7 @@ function getWernisMapedDataFromApiByChallenge ($challenge, $status) {
        } // END - if
 
        // Now call "get.php"
-       $response = executeWernisApiGet($rows[0], 'data', 'anrede|vorname|name|strasse|plz|ort|birth_day|birth_month|birth_year|email|werber');
+       $response = executeWernisApiGet($rows[0], 'data', 'vorname|name|strasse|plz|ort|birth_day|birth_month|birth_year|email|werber');
 
        // Was the status okay?
        if (isHttpResponseStatusOkay($response)) {
@@ -602,10 +611,10 @@ function getWernisMapedDataFromApiByChallenge ($challenge, $status) {
 
                /*
                 * Do some checks on the decoded string, it should be a
-                * serialized array with 11 entries (see above
+                * serialized array with 10 entries (see above
                 * executeWernisApiGet() call).
                 */
-               assert(substr($decodedData, 0, 6) == 'a:11:{');
+               assert(substr($decodedData, 0, 6) == 'a:10:{');
                assert(substr($decodedData, -1, 1) == '}');
 
                // The array seems to be fine, unserialize it
@@ -613,7 +622,6 @@ function getWernisMapedDataFromApiByChallenge ($challenge, $status) {
 
                // All mappings WDS66->mailer
                $mappings = array(
-                       'anrede'      => 'gender',
                        'vorname'     => 'surname',
                        'name'        => 'family',
                        'strasse'     => 'street_nr',
@@ -658,15 +666,16 @@ function updateWernisRegistrationDataByKey ($updatedColumn, $key, $oldValue, $ne
        sqlQueryEscaped("UPDATE
        `{?_MYSQL_PREFIX?}_wernis_regs`
 SET
-       `%s`='%s'
+       `%s` = '%s'
 WHERE
-       `%s`='%s' AND
+       `%s` = '%s' AND
        `%s` != '%s'
 LIMIT 1",
                array(
                        $updatedColumn,
                        $newValue,
                        $key,
+                       $oldValue,
                        $updatedColumn,
                        $oldValue
                ), __FUNCTION__, __LINE__
@@ -719,6 +728,24 @@ LIMIT %d",
        return $rows;
 }
 
+// Do local user registration with data from WDS66 API
+function doWernisUserRegistration () {
+       // Call generic registration function
+       $status = doGenericUserRegistration();
+
+       // Does this went fine?
+       if ($status === FALSE) {
+               // No, then abort here silently
+               return FALSE;
+       } // END - if
+
+       // Make sure the user id is valid
+       assert(isset($GLOBALS['register_userid']));
+       assert(isValidId($GLOBALS['register_userid']));
+
+       // Generic registration is finished, so add more data:
+}
+
 //-----------------------------------------------------------------------------
 //                      Auth status callback functions
 //-----------------------------------------------------------------------------
@@ -789,7 +816,7 @@ function doWernisAuthAccepted ($args) {
        // auth_key and wernis_userid must be set
        assert(isset($args['auth_key']));
        assert(isset($args['wernis_userid']));
-       die(__FUNCTION__ . '<pre>'.print_r($args, TRUE).'</pre>');
+       die(__FUNCTION__ . ':' . __LINE__ . '<pre>' . print_r($args, TRUE) . '</pre>');
 }
 
 //-----------------------------------------------------------------------------