X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmodules%2Fguest%2Fwhat-sponsor_reg.php;h=bc5bbdfcdea337564f92a30bd4a25b4f0a4e18e5;hp=ceb9c6638c2c6d8b1c51f8c531f529dc0b4f1a66;hb=391c98ab7233ff3e640d8b9fad8df92ce45e9b31;hpb=d8148e3f1f3a6762b2e786dbe99ada269dcf2ea0 diff --git a/inc/modules/guest/what-sponsor_reg.php b/inc/modules/guest/what-sponsor_reg.php index ceb9c6638c..bc5bbdfcde 100644 --- a/inc/modules/guest/what-sponsor_reg.php +++ b/inc/modules/guest/what-sponsor_reg.php @@ -1,7 +1,7 @@ 0) REQUEST_UNSET_POST('ok'); -} + if (count($formErrors) > 0) unsetPostRequestParameter('ok'); +} // END - if -if ((IS_FORM_SENT()) && (count($FORM_ERRORS) == 0)) { +if ((isFormSent()) && (count($formErrors) == 0)) { // Generate message array - $MSGs = array( - 'failed' => getMessage('SPONSOR_REGISTRATION_FAILED'), - 'added' => getMessage('SPONSOR_REGISTRATION_COMPLETED'), + $messageArray = array( + 'failed' => '{--SPONSOR_REGISTRATION_FAILED--}', + 'added' => '{--SPONSOR_REGISTRATION_COMPLETED--}', ); // Calulate points - $result = SQL_QUERY_ESC("SELECT (pay_rate * pay_min_count) AS points, pay_min_count AS pay, pay_currency AS curr -FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` -WHERE id='%s' LIMIT 1", array(REQUEST_POST('pay_type')), __FILE__, __LINE__); + $result = SQL_QUERY_ESC("SELECT + (`pay_rate` * `pay_min_count`) AS `points`, `pay_min_count`, `pay_currency` +FROM + `{?_MYSQL_PREFIX?}_sponsor_paytypes` +WHERE + `id`=%s +LIMIT 1", + array(postRequestParameter('pay_type')), __FILE__, __LINE__); list($points, $pay, $curr) = SQL_FETCHROW($result); // Free memory SQL_FREERESULT($result); // Add points to array - REQUEST_POST('points_amount', $points); - REQUEST_POST('points_used' , "0.00000"); - REQUEST_POST('last_pay' , $pay); - REQUEST_POST('last_curr' , $curr); + postRequestParameter('points_amount', $points); + postRequestParameter('points_used' , '0.00000'); + postRequestParameter('last_payment' , $pay); + postRequestParameter('last_currency', $curr); // Register sponsor but never ever update here! - $STATUS = SPONSOR_HANDLE_SPONSOR(REQUEST_POST_ARRAY(), true, $MSGs, 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(REQUEST_POST('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 - define('__ID' , $id); - define('__HASH' , $hash); - define('__EMAIL' , REQUEST_POST('email')); - define('__SURNAME' , REQUEST_POST('surname')); - define('__FAMILY' , REQUEST_POST('family')); - define('__GENDER' , TRANSLATE_GENDER(REQUEST_POST('gender'))); - define('__TIMESTAMP', MAKE_DATETIME(time(), 0)); - define('__PASSWORD' , REQUEST_POST('pass1')); - - // Generate email and send it to the new sponsor - $EMAIL_MSG = LOAD_EMAIL_TEMPLATE("sponsor_confirm", $hash); - SEND_EMAIL(REQUEST_POST('email'), getMessage('SPONSOR_PLEASE_CONFIRM_SUBJ'), $EMAIL_MSG); - - // Send mail to admin - SEND_ADMIN_NOTIFICATION(getMessage('ADMIN_NEW_SPONSOR'), "admin_sponsor_reg", $hash); - - // Output message: DONE - $MSG = $MSGs['added']; - } else { - // Sponsor account not found??? - $MSG = sprintf(getMessage('SPONSOR_EMAIL_404'), REQUEST_POST('email')); - } - - // Free memory - SQL_FREERESULT($result); - break; - - default: - DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown status %s detected.", $STATUS)); - if (!IS_ADMIN()) { - // Message for testing admin - $MSG = sprintf(getMessage('ADMIN_SPONSOR_UNKNOWN_STATUS'), $STATUS); - } else { - // Message for the guest - $MSG = sprintf(getMessage('SPONSOR_UNKNOWN_STATUS'), $STATUS); - } - break; - } + $message = doProcessSponsorFormRequest($messageArray); // Display message - LOAD_TEMPLATE("admin_settings_saved", false, $MSG); + displayMessage($message); } else { // Check for payment types - $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_currency, pay_min_count -FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` -ORDER BY pay_name", __FILE__, __LINE__); - if (SQL_NUMROWS($result) > 0) { + $result = SQL_QUERY('SELECT + `id`, `pay_name`, `pay_rate`, `pay_currency`, `pay_min_count` +FROM + `{?_MYSQL_PREFIX?}_sponsor_paytypes` +ORDER BY + `pay_name` ASC', __FILE__, __LINE__); + if (!SQL_HASZERONUMS($result)) { // Load all types... - // @TODO Swap this HTML code to templates - $OUT = "\n"; - $SW = 2; - while (list($id, $name, $rate, $curr, $min) = SQL_FETCHROW($result)) { - $OUT .= " - -\n"; - $SW = 3 - $SW; - } - $OUT .= "
-  ".$name."
-
(".$min." ".$curr." = ".TRANSLATE_COMMA($rate * $min)." {!POINTS!})
-
\n"; - define('__PAYMENT_LIST', $OUT); - SQL_FREERESULT($result); + $OUT = ''; + while ($content = SQL_FETCHARRAY($result)) { + // Prepare content for output + $content['res'] = translateComma($content['pay_rate'] * $content['pay_min_count']); + + // Load row template and switch color + $OUT .= loadTemplate('guest_sponsor_payment_row', true, $content); + } // END - while + + // Remember the list in table + $content['payment_list'] = loadTemplate('guest_sponsor_payment', true, $OUT); + + // Init a lot array elements + foreach (array('company','position','tax_ident','gender_m','gender_f','gender_c','surname','family','street_nr1','street_nr2','country','zip','city','phone','fax','cell','email','url','receive_warnings_y','receive_warnings_n','form_errors','refid') as $entry) { + $content[$entry] = ''; + } // END - foreach // Check for invalid entries - if (count($FORM_ERRORS) > 0) - { + if (count($formErrors) > 0) { // Some found... :-( - define('__COMPANY' , COMPILE_CODE(REQUEST_POST('company'))); - define('__POSITION' , COMPILE_CODE(REQUEST_POST('position'))); - define('__TAX_IDENT', COMPILE_CODE(REQUEST_POST('tax_ident'))); - define('__SURNAME' , COMPILE_CODE(REQUEST_POST('surname'))); - define('__FAMILY' , COMPILE_CODE(REQUEST_POST('family'))); - define('__STREET1' , COMPILE_CODE(REQUEST_POST('street_nr1'))); - define('__STREET2' , COMPILE_CODE(REQUEST_POST('street_nr2'))); - define('__COUNTRY' , COMPILE_CODE(REQUEST_POST('country'))); - define('__ZIP' , COMPILE_CODE(REQUEST_POST('zip'))); - define('__CITY' , COMPILE_CODE(REQUEST_POST('city'))); - define('__PHONE' , COMPILE_CODE(REQUEST_POST('phone'))); - define('__FAX' , COMPILE_CODE(REQUEST_POST('fax'))); - define('__CELL' , COMPILE_CODE(REQUEST_POST('cell'))); - define('__EMAIL' , COMPILE_CODE(REQUEST_POST('email'))); - define('__URL' , COMPILE_CODE(REQUEST_POST('url'))); + foreach (array('company','position','tax_ident','surname','family','street_nr1','street_nr2','country','zip','city','phone','fax','cell','email','url') as $entry) { + $content[$entry] = secureString(postRequestParameter($entry)); + } // END - foreach + + // Init gender + foreach (array('m', 'f', 'c') as $gender) { + $content['gender_' . $gender] = ''; + } // END - foreach // Check for gender selection - switch (REQUEST_POST('gender')) - { - case "M": // Male - define('__GENDER_M' , " selected=\"selected\""); - define('__GENDER_F' , ""); - define('__GENDER_C' , ""); - break; - - case "F": // Female - define('__GENDER_M' , ""); - define('__GENDER_F' , " selected=\"selected\""); - define('__GENDER_C' , ""); - break; - - case "C": // Company - define('__GENDER_M' , ""); - define('__GENDER_F' , ""); - define('__GENDER_C' , " selected=\"selected\""); - break; - } + $content['gender_' . strtolower(postRequestParameter('gender'))] = ' selected="selected"'; - // Check for receive_warnings - switch (REQUEST_POST('receive_warnings')) - { - case "Y": - define('__REC_Y' , " selected=\"selected\""); - define('__REC_N' , ""); - break; - - case "N": - define('__REC_Y' , ""); - define('__REC_N' , " selected=\"selected\""); - break; - } + // Init receive selection + $content['receive_warnings_y'] = ''; + $content['receive_warnings_n'] = ''; - // Errors found - $OUT = "

-

".SPONSOR_REGISTER_SOMETHING_MISSING.":

-

-
    \n"; - foreach ($FORM_ERRORS as $error) { - $OUT .= "
  1. ".$error."
  2. \n"; + // Check for receive_warnings + $content['receive_warnings_' . strtolower(postRequestParameter('receive_warnings'))] = ' selected="selected"'; + $OUT = ''; + + // Errors found? + if (count($formErrors) > 0) { + $OUT = displayMessage('{--SPONSOR_REGISTER_SOMETHING_MISSING--}', true); + $OUT .= '
      '; + foreach ($formErrors as $error) { + $OUT .= '
    1. ' . $error . '
    2. '; + } // END - foreach + + $OUT .= '
    '; } // END - if - $OUT .= "

\n"; - define('__SPONSOR_FORM_ERRORS', $OUT); - define('__SPONSOR_REFID', REQUEST_POST('refid')); - } else { - // None found, first call - define('__COMPANY' , ""); - define('__POSITION' , ""); - define('__TAX_IDENT', ""); - define('__GENDER_M' , ""); - define('__GENDER_F' , ""); - define('__GENDER_C' , ""); - define('__SURNAME' , ""); - define('__FAMILY' , ""); - define('__STREET1' , ""); - define('__STREET2' , ""); - define('__COUNTRY' , ""); - define('__ZIP' , ""); - define('__CITY' , ""); - define('__PHONE' , ""); - define('__FAX' , ""); - define('__CELL' , ""); - define('__EMAIL' , ""); - define('__URL' , ""); - define('__REC_Y' , ""); - define('__REC_N' , ""); - - // No errors found so far - define('__SPONSOR_FORM_ERRORS', ""); - } + $content['form_errors'] = $OUT; - // Prepare referal things - if (!REQUEST_ISSET_GET(('refid'))) { - // No referal link - define('__SPONSOR_REFID', "0"); - } else { - // Referal ID transmitted, we don't care here if it is right or not - define('__SPONSOR_REFID', bigintval(REQUEST_GET('refid'))); - } + // @TODO Maybe a default referal id? + $content['refid'] = 0; + + // Is the referal id valid? + if ((isPostRequestParameterSet('refid')) && (isValidUserId(postRequestParameter('refid')))) { + // Transfer referal id + $content['refid'] = bigintval(postRequestParameter('refid')); + } // END - if + } // END - if // Display registration form - LOAD_TEMPLATE("guest_sponsor_reg"); + loadTemplate('guest_sponsor_reg', false, $content); } else { // Nothing added so far - LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_PAYMENT_LIST_IS_EMPTY); + displayMessage('{--SPONSOR_PAYMENT_LIST_IS_EMPTY--}'); } // Free memory SQL_FREERESULT($result); } -// +// [EOF] ?>