+// Create email link to sponsor's account
+function generateSponsorEmailLink ($email, $mod = 'admin') {
+ // Show contact link only if sponsor is confirmed by default
+ $locked = " AND `status`='CONFIRMED'";
+
+ // But admins shall always see it
+ if (isAdmin()) $locked = '';
+
+ $result = SQL_QUERY_ESC("SELECT
+ `id`
+FROM
+ `{?_MYSQL_PREFIX?}_sponsor_data`
+WHERE
+ `email`='%s'" . $locked."
+LIMIT 1",
+ array($email), __FUNCTION__, __LINE__);
+ if (SQL_NUMROWS($result) == 1) {
+ // Load sponsor_id
+ list($sponsor_id) = SQL_FETCHROW($result);
+
+ // Rewrite email address to contact link
+ $email = '{%url=modules.php?module=' . $mod . '&what=sponsor_contct&sponsor_id=' . bigintval($sponsor_id) . '%}';
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+
+ // Return rewritten (?) email address
+ return $email;
+}
+
+// Processes a sponsor request and handles it
+function doProcessSponsorFormRequest ($messageArray = array()) {
+ // Default message
+ $message = '';
+
+ // Handle the request
+ $status = handleSponsorRequest(postRequestArray(), true, $messageArray, true);
+
+ // Check the status of the registration process
+ switch ($status) {
+ case 'added': // Sponsor successfully added with account status = UNCONFIRMED!
+ // Check for his id number
+ $result = SQL_QUERY_ESC("SELECT `id`, `hash` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `email`='%s' LIMIT 1",
+ array(postRequestParameter('email')), __FILE__, __LINE__);
+ if (SQL_NUMROWS($result) == 1) {
+ // id found so let's load it for the confirmation email
+ list($id, $hash) = SQL_FETCHROW($result);
+
+ // Prepare data for the email template
+ $content['id'] = $id;
+ $content['hash'] = $hash;
+ $content['email'] = secureString(postRequestParameter('email'));
+ $content['surname'] = secureString(postRequestParameter('surname'));
+ $content['family'] = secureString(postRequestParameter('family'));
+ $content['timestamp'] = generateDateTime(time(), 0);
+ $content['password'] = secureString(postRequestParameter('pass1'));
+
+ // Generate email and send it to the new sponsor
+ $message = loadEmailTemplate('sponsor_confirm', $hash);
+ sendEmail(postRequestParameter('email'), '{--SPONSOR_PLEASE_CONFIRM_SUBJECT--}', $message);
+
+ // Send mail to admin
+ sendAdminNotification('{--ADMIN_NEW_SPONSOR--}', 'admin_sponsor_reg', $hash);
+
+ // Output message: DONE
+ $message = $messageArray['added'];
+ } else {
+ // Sponsor account not found???
+ $message = getMaskedMessage('SPONSOR_EMAIL_404', postRequestParameter('email'));
+ }
+
+ // Free memory
+ SQL_FREERESULT($result);
+ break;
+
+ default:
+ logDebugMessage(__FILE__, __LINE__, sprintf("Unknown status %s detected.", $status));
+ if (!isAdmin()) {
+ // Message for testing admin
+ $message = getMaskedMessage('ADMIN_SPONSOR_UNKNOWN_STATUS', $status);
+ } else {
+ // Message for the guest
+ $message = getMaskedMessage('SPONSOR_UNKNOWN_STATUS', $status);
+ }
+ break;
+ }
+
+ // Return message
+ return $message;
+}
+