+
+ // Now call "get.php"
+ $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)) {
+ // API returned non-errous response, 'data=' must be found
+ assert(substr($response['response'], 0, 5) == 'data=');
+
+ // And remove it, this is now BASE64-encoded
+ $encodedData = urldecode(substr($response['response'], 5));
+
+ // And decode it (all steps separated to later "easily" debug them)
+ $decodedData = base64_decode($encodedData);
+
+ /*
+ * Do some checks on the decoded string, it should be a
+ * serialized array with 10 entries (see above
+ * executeWernisApiGet() call).
+ */
+ assert(substr($decodedData, 0, 6) == 'a:10:{');
+ assert(substr($decodedData, -1, 1) == '}');
+
+ // The array seems to be fine, unserialize it
+ $userData = unserialize($decodedData);
+
+ // All mappings WDS66->mailer
+ $mappings = array(
+ 'vorname' => 'surname',
+ 'name' => 'family',
+ 'strasse' => 'street_nr',
+ 'plz' => 'zip',
+ 'ort' => 'city',
+ 'email' => 'email',
+ 'birth_day' => 'birth_day',
+ 'birth_month' => 'birth_month',
+ 'birth_year' => 'birth_year',
+ 'werber' => 'wernis_refid'
+ );
+
+ // Map all WDS66 entries into mailer entries
+ foreach ($mappings as $from => $to) {
+ // All must exist
+ if (!isset($userData[$from])) {
+ // Element $from does not exist
+ reportBug(__FUNCTION__, __LINE__, 'Cannot map from=' . $from . ' -> to=' . $to . ': element does not exist.');
+ } // END - if
+
+ // "Map" all
+ $return['mapped_data'][$to] = convertEmptyToNull($userData[$from]);
+ } // END - foreach
+
+ // Both arrays must have same size
+ assert(count($userData) == count($return['mapped_data']));
+
+ // Now add userid from WDS66
+ $return['mapped_data']['wernis_userid'] = bigintval($rows[0]['wernis_userid']);
+ } else {
+ // Something bad happened so copy the message
+ $return['message'] = $response['message'];
+ }
+
+ // Return mapped data array
+ return $return;
+}
+
+// Updates auth status by given key/value pair
+function updateWernisRegistrationDataByKey ($updatedColumn, $key, $oldValue, $newValue) {
+ // Run the update
+ sqlQueryEscaped("UPDATE
+ `{?_MYSQL_PREFIX?}_wernis_regs`
+SET
+ `%s`='%s'
+WHERE
+ `%s`='%s' AND
+ `%s` != '%s'
+LIMIT 1",
+ array(
+ $updatedColumn,
+ $newValue,
+ $key,
+ $updatedColumn,
+ $oldValue
+ ), __FUNCTION__, __LINE__
+ );
+
+ // Check if rows as been affected
+ return ifSqlHasZeroAffectedRows();
+}
+
+// "Getter" for Wernis registration data by given key and value
+function getWernisRegistrationDataByKey ($key, $value, $limit = 1) {
+ // Init array
+ $rows = array();
+
+ // Now search for it
+ $result = sqlQueryEscaped("SELECT
+ `local_userid`,
+ `wernis_userid`,
+ `api_auth_status`,
+ `api_auth_key`,
+ `api_redirect_challenge`,
+ UNIX_TIMESTAMP(`record_inserted`) AS `record_inserted`
+FROM
+ `{?_MYSQL_PREFIX?}_wernis_regs`
+WHERE
+ `%s`='%s'
+ORDER BY
+ `id`
+LIMIT %d",
+ array(
+ $key,
+ $value,
+ $limit
+ ), __FUNCTION__, __LINE__
+ );
+
+ // Is there an entry?
+ if (sqlNumRows($result) > 0) {
+ // At least one entry has been found, so loop through all
+ while ($row = sqlFetchArray($result)) {
+ // Add it
+ array_push($rows, $row);
+ } // END - while
+ } // END - if
+
+ // Free result
+ sqlFreeResult($result);
+
+ // Return found entries
+ return $rows;