X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmodules%2Fguest%2Fwhat-sponsor_reg.php;h=d0d9fff8bbe604188c307bbc9fc9abd278c0670c;hp=059a38206946eec84dbc2799153f807a0575ac2c;hb=0715fa7aa8e5e70bcf1d957fb09ae655c3896c4e;hpb=fb7120ffa230b62b54895bcf95952e1cf30f8594 diff --git a/inc/modules/guest/what-sponsor_reg.php b/inc/modules/guest/what-sponsor_reg.php index 059a382069..d0d9fff8bb 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($FORM_ERRORS) > 0) unsetPostRequestParameter('ok'); } -if ((IS_FORM_SENT()) && (count($FORM_ERRORS) == 0)) { +if ((isFormSent()) && (count($FORM_ERRORS) == 0)) { // Generate message array - $MSGs = array( + $messageArray = array( 'failed' => getMessage('SPONSOR_REGISTRATION_FAILED'), 'added' => getMessage('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` AS pay, `pay_currency` AS curr +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_pay' , $pay); + postRequestParameter('last_curr' , $curr); // Register sponsor but never ever update here! - $STATUS = SPONSOR_HANDLE_SPONSOR(REQUEST_POST_ARRAY(), true, $MSGs, true); + $STATUS = handlSponsorRequest(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(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; + 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['gender'] = translateGender(postRequestParameter('gender')); + $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'), getMessage('SPONSOR_PLEASE_CONFIRM_SUBJ'), $message); + + // Send mail to admin + sendAdminNotification(getMessage('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')); + } - 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; + // 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; } // Display message - LOAD_TEMPLATE("admin_settings_saved", false, $MSG); + loadTemplate('admin_settings_saved', false, $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__); + $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) { // Load all types... // @TODO Swap this HTML code to templates - $OUT = "\n"; + $OUT = "
\n"; $SW = 2; while ($content = SQL_FETCHARRAY($result)) { // Prepare content for output $content['sw'] = $SW; - $content['res'] = TRANSLATE_COMMA($content['pay_rate'] * $content['pay_min_count']); + $content['res'] = translateComma($content['pay_rate'] * $content['pay_min_count']); // Load row template and switch color - $OUT .= LOAD_TEMPLATE("guest_sponsor_payment_row", false, $content); + $OUT .= loadTemplate('guest_sponsor_payment_row', false, $content); $SW = 3 - $SW; } $OUT .= "
\n"; - // @TODO Rewrite this constant - define('__PAYMENT_LIST', $OUT); + // Remember the list in table + $content['payment_list'] = $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','fix','cell','email','url','rec_y','rec_n','form_errors','refid') as $entry) { + $content[$entry] = ''; + } // END - foreach // Check for invalid entries if (count($FORM_ERRORS) > 0) { // Some found... :-( - // @TODO Rewrite these constants - 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','fix','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['rec_y'] = ''; + $content['rec_n'] = ''; - // Errors found - $OUT = "

-

".SPONSOR_REGISTER_SOMETHING_MISSING.":

-

-
    \n"; - foreach ($FORM_ERRORS as $error) { - $OUT .= "
  1. ".$error."
  2. \n"; + // Check for receive_warnings + $content['rec_' . strtolower(postRequestParameter('receive_warnings'))] = ' selected="selected"'; + $OUT = ''; + + // Errors found? + if (count($FORM_ERRORS) > 0) { + $OUT = loadTemplate('admin_settings_saved', true, getMessage('SPONSOR_REGISTER_SOMETHING_MISSING'); + $OUT .= '
      '; + foreach ($FORM_ERRORS 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; + $content['refid'] = bigintval(postRequestParameter('refid')); + } // END - if - // 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'))); - } + // Prepare referal id + $content['refid'] = determineReferalId(); // 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, getMessage('SPONSOR_PAYMENT_LIST_IS_EMPTY')); + loadTemplate('admin_settings_saved', false, getMessage('SPONSOR_PAYMENT_LIST_IS_EMPTY')); } // Free memory SQL_FREERESULT($result); } -// +// [EOF] ?>