From 675778ff98b75b6c5071e2709c2d6b0af86cf79d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 23 Jul 2010 03:11:12 +0000 Subject: [PATCH] Some sponsor API functions added, expression function for user moved: - Missing function generateSponsorEmailLink() added - Sponsor registration rewritten to make usage of API function, we can use the function in admin area again, so the code is shorter - Usage of EL in admin template for ext-sponsor - TODOs.txt updated --- DOCS/TODOs.txt | 2 +- inc/expression-functions.php | 36 -------- inc/extensions/ext-sponsor.php | 21 +++-- inc/libs/sponsor_functions.php | 92 +++++++++++++++++++ inc/libs/user_functions.php | 44 ++++++++- inc/modules/admin/what-add_sponsor.php | 2 +- inc/modules/admin/what-unlock_sponsor.php | 12 +-- inc/modules/guest/what-sponsor_reg.php | 51 +--------- inc/template-functions.php | 4 +- .../html/admin/admin_unlock_sponsor_row.tpl | 2 +- 10 files changed, 153 insertions(+), 113 deletions(-) diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index 14ca982ac5..fd9e0f4c99 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -7,7 +7,7 @@ ./inc/cache/config-local.php:126:// @TODO Rewrite the following three constants, somehow... ./inc/classes/cachesystem.class.php:474: // @TODO Add support for more types which break in last else-block ./inc/config-functions.php:141: // @TODO Make this all better... :-/ -./inc/expression-functions.php:202:// @TODO FILTER_COMPILE_CONFIG does not handle call-back functions so we handle it here again +./inc/expression-functions.php:166:// @TODO FILTER_COMPILE_CONFIG does not handle call-back functions so we handle it here again ./inc/expression-functions.php:48: // @TODO is escapeQuotes() enougth for strings with single/double quotes? ./inc/extensions/ext-html_mail.php:138: // @TODO Move these arrays into config ./inc/extensions/ext-menu.php:54: // @TODO Convert menu-Id to one coding-standard. admin(edit|_add) => admin_menu_(edit|add), mem(edit|_add) => mem_menu_(edit|add) diff --git a/inc/expression-functions.php b/inc/expression-functions.php index 9f309b9d86..6d393659b1 100644 --- a/inc/expression-functions.php +++ b/inc/expression-functions.php @@ -138,42 +138,6 @@ function doExpressionServer ($data) { return $code; } -// Expression call-back function for fetching user data -function doExpressionUser ($data) { - // Use current userid by default - $functionName = 'getMemberId()'; - - // User-related data, so is there a userid? - if (!empty($data['matches'][4][$data['key']])) { - // Do we have a userid or $userid? - if ($data['matches'][4][$data['key']] == '$userid') { - // Use dynamic call - $functionName = "getFetchedUserData('userid', \$userid, '" . $data['callback'] . "')"; - } elseif (!empty($data['matches'][4][$data['key']])) { - // User data found - $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", '" . $data['callback'] . "')"; - } - } elseif ((!empty($data['callback'])) && (isUserDataValid())) { - // "Call-back" alias column for current logged in user's data - $functionName = "getUserData('" . $data['callback'] . "')"; - } - - // Do we have another function to run (e.g. translations) - if (!empty($data['extra_func'])) { - // Surround the original function call with it - $functionName = $data['extra_func'] . '(' . $functionName . ')'; - } // END - if - - // Generate replacer - $replacer = '{DQUOTE} . ' . $functionName . ' . {DQUOTE}'; - - // Now replace the code - $code = replaceExpressionCode($data, $replacer); - - // Return replaced code - return $code; -} - // Expression call-back function for getting extension data function doExpressionExt ($data) { // Not installed is default diff --git a/inc/extensions/ext-sponsor.php b/inc/extensions/ext-sponsor.php index d13faf9373..d0e0cf08a5 100644 --- a/inc/extensions/ext-sponsor.php +++ b/inc/extensions/ext-sponsor.php @@ -318,16 +318,17 @@ PRIMARY KEY (`id`) addAdminMenuSql('sponsor','edit_sponsor','Sponsor ändern','Sponsorenaccount ändern (Grundaten, nicht Freigabe!).', 4); addAdminMenuSql('sponsor','lock_sponsor','Sponsor ent-/sperren','Sponsorenaccount sperren und entsperren.', 5); addAdminMenuSql('sponsor','del_sponsor','Sponsor löschen','Sponsorenaccount löschen.', 6); - addAdminMenuSql('sponsor','allow_sponsor_data','Datenverwaltung','Stellen Sie hier ein, welche Daten der Sponsor im Mitgliedsbereich über sicht anzeigen darf und welche nicht.', 7); - addAdminMenuSql('sponsor','list_sponsor_pays','Bestellungen...','Bestellungen der Sponsoren auflisten / bearbeiten.', 8); - addAdminMenuSql('sponsor','list_sponsor_menu','Sponsorenmenü','Das Sponsorenmenü kann hier geändert werden.', 9); - addAdminMenuSql('sponsor','list_sponsor_campaigns','Kampagnen...','Management aller von Ihren Sponsoren eingerichteten Kampagnen.', 10); - addAdminMenuSql('sponsor','list_sponsor_urls','URL-Management','Management (freischalten, sperren, löschen, testen, bearbeiten usw.) von gebuchten URLs.', 11); - addAdminMenuSql('sponsor','list_sponsor_banner','Banner-Management','Management (freischalten, sperren, löschen, testen, bearbeiten usw.) von gebuchten Bannern.', 12); - addAdminMenuSql('sponsor','list_sponsor_reg','Sponsor-Aktionen','Alle Sponsor-Aktionen auflisten und verwalten.', 13); - addAdminMenuSql('sponsor','list_sponsor_pay','Buchungspakete','Die Sponsoren können sich {OPEN_CONFIG}POINTS{CLOSE_CONFIG}-Pakete kaufen. Hier können Sie diese verwalten.', 14); - addAdminMenuSql('sponsor','list_sponsor_conv','{OPEN_CONFIG}POINTS{CLOSE_CONFIG} umwandeln...','Mit den vom Sponsor gekauften {OPEN_CONFIG}POINTS{CLOSE_CONFIG} kann er Aktionen buchen. Hier stellen Sie die Umrechnungsrate von {OPEN_CONFIG}POINTS{CLOSE_CONFIG} nach Sponsoraktionen um. Beispiel: 1 {OPEN_CONFIG}POINTS{CLOSE_CONFIG} = 10 Mails.', 15); - addAdminMenuSql('sponsor','config_sponsor','Einstellungen','Allgemeine Einstellungen am Sponsoring-System.', 16); + addAdminMenuSql('sponsor','sponsor_contct','Sponsor kontaktieren','Kontaktieren Sie Sponsoren komfortabel über dieses {?TITLE?}.', 7); + addAdminMenuSql('sponsor','allow_sponsor_data','Datenverwaltung','Stellen Sie hier ein, welche Daten der Sponsor im Mitgliedsbereich über sicht anzeigen darf und welche nicht.', 8); + addAdminMenuSql('sponsor','list_sponsor_pays','Bestellungen...','Bestellungen der Sponsoren auflisten / bearbeiten.', 9); + addAdminMenuSql('sponsor','list_sponsor_menu','Sponsorenmenü','Das Sponsorenmenü kann hier geändert werden.', 10); + addAdminMenuSql('sponsor','list_sponsor_campaigns','Kampagnen...','Management aller von Ihren Sponsoren eingerichteten Kampagnen.', 11); + addAdminMenuSql('sponsor','list_sponsor_urls','URL-Management','Management (freischalten, sperren, löschen, testen, bearbeiten usw.) von gebuchten URLs.', 12); + addAdminMenuSql('sponsor','list_sponsor_banner','Banner-Management','Management (freischalten, sperren, löschen, testen, bearbeiten usw.) von gebuchten Bannern.', 13); + addAdminMenuSql('sponsor','list_sponsor_reg','Sponsor-Aktionen','Alle Sponsor-Aktionen auflisten und verwalten.', 14); + addAdminMenuSql('sponsor','list_sponsor_pay','Buchungspakete','Die Sponsoren können sich {OPEN_CONFIG}POINTS{CLOSE_CONFIG}-Pakete kaufen. Hier können Sie diese verwalten.', 15); + addAdminMenuSql('sponsor','list_sponsor_conv','{OPEN_CONFIG}POINTS{CLOSE_CONFIG} umwandeln...','Mit den vom Sponsor gekauften {OPEN_CONFIG}POINTS{CLOSE_CONFIG} kann er Aktionen buchen. Hier stellen Sie die Umrechnungsrate von {OPEN_CONFIG}POINTS{CLOSE_CONFIG} nach Sponsoraktionen um. Beispiel: 1 {OPEN_CONFIG}POINTS{CLOSE_CONFIG} = 10 Mails.', 16); + addAdminMenuSql('sponsor','config_sponsor','Einstellungen','Allgemeine Einstellungen am Sponsoring-System.', 17); addAdminMenuSql('repair','repr_sponsor','Sponsormenü','Gewichtung des Sponsormenüs reparieren.', 5); // // Menu system (still admin menu) diff --git a/inc/libs/sponsor_functions.php b/inc/libs/sponsor_functions.php index b4e78c2ae7..1d883513c0 100644 --- a/inc/libs/sponsor_functions.php +++ b/inc/libs/sponsor_functions.php @@ -531,5 +531,97 @@ function saveSponsorData ($postData, $content) { return $message; } +// 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; +} + // [EOF] ?> diff --git a/inc/libs/user_functions.php b/inc/libs/user_functions.php index 6e8ebaf67d..758ad55be1 100644 --- a/inc/libs/user_functions.php +++ b/inc/libs/user_functions.php @@ -530,12 +530,52 @@ function insertUserStatsRecord ($userid, $statsType, $statsData) { if ((!getTimestampFromUserStats($statsType, $statsData, $userid)) && (!is_array($statsData))) { // Then insert it! SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_stats_data` (`userid`,`stats_type`,`stats_data`) VALUES (%s,'%s','%s')", - array(bigintval($userid), $statsType, $statsData), __FUNCTION__, __LINE__); + array( + bigintval($userid), + $statsType, + $statsData + ), __FUNCTION__, __LINE__); } elseif (is_array($statsData)) { // Invalid data! - logDebugMessage(__FUNCTION__, __LINE__, "userid={$userid},type={$statsType},data={".gettype($statsData).": Invalid statistics data type!"); + logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',type=' . $statsType . ',data=' . gettype($statsData) . ': Invalid statistics data type!'); } } +// Expression call-back function for fetching user data +function doExpressionUser ($data) { + // Use current userid by default + $functionName = 'getMemberId()'; + + // User-related data, so is there a userid? + if (!empty($data['matches'][4][$data['key']])) { + // Do we have a userid or $userid? + if ($data['matches'][4][$data['key']] == '$userid') { + // Use dynamic call + $functionName = "getFetchedUserData('userid', \$userid, '" . $data['callback'] . "')"; + } elseif (!empty($data['matches'][4][$data['key']])) { + // User data found + $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", '" . $data['callback'] . "')"; + } + } elseif ((!empty($data['callback'])) && (isUserDataValid())) { + // "Call-back" alias column for current logged in user's data + $functionName = "getUserData('" . $data['callback'] . "')"; + } + + // Do we have another function to run (e.g. translations) + if (!empty($data['extra_func'])) { + // Surround the original function call with it + $functionName = $data['extra_func'] . '(' . $functionName . ')'; + } // END - if + + // Generate replacer + $replacer = '{DQUOTE} . ' . $functionName . ' . {DQUOTE}'; + + // Now replace the code + $code = replaceExpressionCode($data, $replacer); + + // Return replaced code + return $code; +} + // [EOF] ?> diff --git a/inc/modules/admin/what-add_sponsor.php b/inc/modules/admin/what-add_sponsor.php index bc1fc7e25a..9c60770993 100644 --- a/inc/modules/admin/what-add_sponsor.php +++ b/inc/modules/admin/what-add_sponsor.php @@ -47,7 +47,7 @@ addMenuDescription('admin', __FILE__); if (isFormSent()) { // Save sponsor in database - handleSponsorRequest(postRequestArray()); + doProcessSponsorFormRequest(); } else { // Output form loadTemplate('admin_add_sponsor'); diff --git a/inc/modules/admin/what-unlock_sponsor.php b/inc/modules/admin/what-unlock_sponsor.php index d91a05ba8d..3bff5d8455 100644 --- a/inc/modules/admin/what-unlock_sponsor.php +++ b/inc/modules/admin/what-unlock_sponsor.php @@ -197,16 +197,8 @@ if (!SQL_HASZERONUMS($result)) { // Entries found so let's list them! $OUT = ''; while ($content = SQL_FETCHARRAY($result)) { - // Transfer data to array - $content = array( - 'id' => $content['id'], - 'gender' => $content['gender'], - 'surname' => $content['surname'], - 'family' => $content['family'], - 'email' => generateEmailLink($content['email'], 'sponsor_data'), - 'remote_addr' => $content['remote_addr'], - 'sponsor_created' => generateDateTime($content['sponsor_created'], 2), - ); + // Translate some data + $content['sponsor_created'] = generateDateTime($content['sponsor_created'], 2); // Load row template and switch colors $OUT .= loadTemplate('admin_unlock_sponsor_row', true, $content); diff --git a/inc/modules/guest/what-sponsor_reg.php b/inc/modules/guest/what-sponsor_reg.php index 7e8f5c997b..8c9f367acc 100644 --- a/inc/modules/guest/what-sponsor_reg.php +++ b/inc/modules/guest/what-sponsor_reg.php @@ -227,56 +227,7 @@ LIMIT 1", postRequestParameter('last_curr' , $curr); // Register sponsor but never ever update here! - $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; - } + $message = doProcessSponsorFormRequest($messageArray); // Display message loadTemplate('admin_settings_saved', false, $message); diff --git a/inc/template-functions.php b/inc/template-functions.php index 66867e6963..daed3210c6 100644 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -1071,10 +1071,10 @@ function generateEmailLink ($email, $table = 'admins') { $EMAIL = generateAdminEmailLink($email); } elseif ((isExtensionInstalledAndNewer('user', '0.3.3')) && ($table == 'user_data')) { // Create email link for contacting a member within admin area (or later in other areas, too?) - $EMAIL = generateUserEmailLink($email, 'admin'); + $EMAIL = generateUserEmailLink($email); } elseif ((isExtensionActive('sponsor')) && ($table == 'sponsor_data')) { // Create email link to contact sponsor within admin area (or like the link above?) - $EMAIL = generateSponsorEmailLink($email, 'sponsor_data'); + $EMAIL = generateSponsorEmailLink($email); } // Shall I close the link when there is no admin? diff --git a/templates/de/html/admin/admin_unlock_sponsor_row.tpl b/templates/de/html/admin/admin_unlock_sponsor_row.tpl index 773302f0ff..1bdad4a1a9 100644 --- a/templates/de/html/admin/admin_unlock_sponsor_row.tpl +++ b/templates/de/html/admin/admin_unlock_sponsor_row.tpl @@ -3,7 +3,7 @@ - {%pipe,translateGender=$content[gender]%} $content[surname] $content[family] + {%pipe,translateGender=$content[gender]%} $content[surname] $content[family] $content[remote_addr] -- 2.39.2