From: Roland Häder Date: Thu, 27 Nov 2008 21:27:04 +0000 (+0000) Subject: URL edit in surfbar continued (unfinished) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8f045e5cfa4abad39d0de560b1eae26ea8ba05cf;p=mailer.git URL edit in surfbar continued (unfinished) --- diff --git a/inc/databases.php b/inc/databases.php index c6f35b9113..74522f8b05 100644 --- a/inc/databases.php +++ b/inc/databases.php @@ -114,7 +114,7 @@ define('USAGE_BASE', "usage"); define('SERVER_URL', "http://www.mxchange.org"); // This current patch level -define('CURR_SVN_REVISION', "564"); +define('CURR_SVN_REVISION', "565"); // Take a prime number which is long (if you know a longer one please try it out!) define('_PRIME', 591623); diff --git a/inc/language/surfbar_de.php b/inc/language/surfbar_de.php index 2690cff77b..26ab9647ce 100644 --- a/inc/language/surfbar_de.php +++ b/inc/language/surfbar_de.php @@ -150,6 +150,7 @@ define('ADMIN_SURFBAR_NOTIFY_URL_DELETED_SUBJECT', "[Surfbar:] URL gelöscht define('ADMIN_SURFBAR_NOTIFY_URL_REJECTED_SUBJECT', "[Surfbar:] URL abgelehnt"); define('ADMIN_SURFBAR_NOTIFY_URL_PENDING_SUBJECT', "[Surfbar:] URL-Buchung zugestimmt"); define('ADMIN_SURFBAR_NOTIFY_URL_DEPLETED_SUBJECT', "[Surfbar:] URL automatisch angehalten"); +define('ADMIN_SURFBAR_NOTIFY_URL_EDITED_SUBJECT', "[Surfbar:'] Mitglied hat URL geändert"); define('ADMIN_SURFBAR_NOTIFY_DEFAULT_SUBJECT', "Problem in Surfbar-Betreff"); // Auto-generated admin subject lines @@ -159,22 +160,23 @@ define('ADMIN_ACTIVE_SURFBAR_URLS_SUBJECT', "[Surfbar:] Freigabe einer URL"); define('ADMIN_LOCKED_SURFBAR_URLS_SUBJECT', "[Surfbar:] Sperrung einer URL"); // Subject lines for members -define('MEMBER_SURFBAR_NOTIFY_URL_UNLOCK_SUBJECT', "Ihre URL wurde in die Surfbar aufgenommen"); -define('MEMBER_SURFBAR_NOTIFY_URL_REG_SUBJECT', "Ihre URL in der Surfbar wartet auf Freischaltung"); -define('MEMBER_SURFBAR_NOTIFY_URL_MIGRATE_SUBJECT', "Ihre Mailbuchung wurde in die Surfbar migriert"); -define('MEMBER_SURFBAR_NOTIFY_URL_ACTIVE_SUBJECT', "Ihre URL wurde für die Surfbar freigegeben"); -define('MEMBER_SURFBAR_NOTIFY_URL_DELETED_SUBJECT', "Löschung Ihrer URL aus der Surfbar"); -define('MEMBER_SURFBAR_NOTIFY_URL_REJECTED_SUBJECT', "Ihre URL wurde für die Surfbar abgelehnt!"); -define('MEMBER_SURFBAR_NOTIFY_URL_PENDING_SUBJECT', "Zustimmung zur URL-Buchung in Surfbar erhalten"); -define('MEMBER_SURFBAR_NOTIFY_URL_DEPLETED_SUBJECT', "Ihre URL wurde automatisch angehalten"); +define('MEMBER_SURFBAR_NOTIFY_URL_UNLOCK_SUBJECT', "[Surfbar:] Ihre URL wurde aufgenommen"); +define('MEMBER_SURFBAR_NOTIFY_URL_REG_SUBJECT', "[Surfbar:] Ihre URL wartet auf Freischaltung"); +define('MEMBER_SURFBAR_NOTIFY_URL_MIGRATE_SUBJECT', "[Surfbar:] Ihre URL aus der Mailbuchung wurde migriert"); +define('MEMBER_SURFBAR_NOTIFY_URL_ACTIVE_SUBJECT', "[Surfbar:] Ihre URL wurde freigegeben"); +define('MEMBER_SURFBAR_NOTIFY_URL_DELETED_SUBJECT', "[Surfbar:] Löschung Ihrer URL"); +define('MEMBER_SURFBAR_NOTIFY_URL_REJECTED_SUBJECT', "[Surfbar:] Ihre URL wurde abgelehnt!"); +define('MEMBER_SURFBAR_NOTIFY_URL_PENDING_SUBJECT', "[Surfbar:] Zustimmung zur URL-Buchung erhalten"); +define('MEMBER_SURFBAR_NOTIFY_URL_DEPLETED_SUBJECT', "[Surfbar:] Ihre URL wurde automatisch angehalten"); +define('MEMBER_SURFBAR_NOTIFY_URL_EDITED_SUBJECT', "[Surfbar:] Sie haben Ihre URL geändert"); define('MEMBER_SURFBAR_NOTIFY_DEFAULT_SUBJECT', "[Fehler:] Bitte leiten Sie diese Mail an uns weiter!"); -define('MEMBER_SURFBAR_NOTIFY_LOW_POINTS_SUBJECT', "Ihr {!POINTS!}-Stand ist sehr niedrig!"); +define('MEMBER_SURFBAR_NOTIFY_LOW_POINTS_SUBJECT', "[Surfbar:] Ihr {!POINTS!}-Stand ist sehr niedrig!"); // Auto-generated member subject lines -define('MEMBER_DEL_SURFBAR_URLS_SUBJECT', "Ihre URL wurde aus der Surfbar entfernt"); -define('MEMBER_EDIT_SURFBAR_URLS_SUBJECT', "Änderung Ihrer URL in der Surfbar"); -define('MEMBER_LOCKED_SURFBAR_URLS_SUBJECT', "Sperrung Ihrer URL in Surfbar, bitte AGBs beachten!"); -define('MEMBER_ACTIVE_SURFBAR_URLS_SUBJECT', "Freigabe Ihrer URL in Surfbar"); +define('MEMBER_DEL_SURFBAR_URLS_SUBJECT', "[Surfbar:] Ihre URL wurde entfernt"); +define('MEMBER_EDIT_SURFBAR_URLS_SUBJECT', "[Surfbar:] Änderung Ihrer URL durch Admin"); +define('MEMBER_LOCKED_SURFBAR_URLS_SUBJECT', "[Surfbar:] Sperrung Ihrer URL, bitte AGBs beachten!"); +define('MEMBER_ACTIVE_SURFBAR_URLS_SUBJECT', "[Surfbar:] Freigabe Ihrer URL"); // URL status define('SURFBAR_URL_STATUS_ACTIVE', "Freigegeben"); @@ -207,5 +209,10 @@ define('MEMBER_SURFBAR_ACTION_BOOKNOW_TITLE', "Die URL wurde aus einer Mailbuchu define('MEMBER_SURFBAR_ACTION_PAUSE_TITLE', "Halten Sie die URL in der Surfbar kurz an, wenn sie gerade nicht erreichbar ist. Dies geschieht nicht automatisch."); define('MEMBER_SURFBAR_ACTION_UNPAUSE_TITLE', "Lassen Sie die URL in der Surfbar weiterlaufen, wenn Sie dies möchten. Wir müssen die URL jedoch erneut freigeben."); +// Internal errors +define('MEMBER_SURFBAR_EXECUTE_ACTION_404', "Auszuführende Funktion %s nicht gefunden!"); +define('ADMIN_SURFBAR_NOTIFY_SUBJECT_404', "Admin-Betreffzeile %s nicht gefunden."); +define('MEMBER_SURFBAR_NOTIFY_SUBJECT_404', "Mitglieder-Betreffzeile %s nicht gefunden."); + // ?> diff --git a/inc/libs/surfbar_functions.php b/inc/libs/surfbar_functions.php index fa03501c1d..a4623cdf85 100644 --- a/inc/libs/surfbar_functions.php +++ b/inc/libs/surfbar_functions.php @@ -225,8 +225,17 @@ function SURFBAR_MEMBER_DO_FORM ($formData, $URLs) { return false; } + // Secure action + $action = SQL_ESCAPE(htmlentities(strip_tags($formData['action']), ENT_QUOTES)); + + // Has it changed? + if ($action != $formData['action']) { + // Invalid data in action found + return false; + } // END - if + // Create the function name for selected action - $functionName = sprintf("SURFBAR_MEMBER_%s_ACTION", strtoupper(SQL_ESCAPE($formData['action']))); + $functionName = sprintf("SURFBAR_MEMBER_%s_ACTION", strtoupper($action)); // Is the function there? if (function_exists($functionName)) { @@ -234,7 +243,7 @@ function SURFBAR_MEMBER_DO_FORM ($formData, $URLs) { $URLs[$formData['id']]['new_status'] = $SURFBAR_CACHE['new_status']; // Extract URL data for call-back - $urlData = array($URLs[$formData['id']]); + $urlData = array(array_merge($URLs[$formData['id']], array($action => $formData))); // Action found so execute it $performed = call_user_func_array($functionName, $urlData); @@ -298,7 +307,7 @@ function SURFBAR_MEMBER_BOOKNOW_ACTION ($urlData) { // Show edit form or do the changes function SURFBAR_MEMBER_EDIT_ACTION ($urlData) { // Is the "execute" flag there? - if (isset($urlData['execute'])) { + if (isset($urlData['edit']['execute'])) { // Execute the changes return SURFBAR_MEMBER_EXECUTE_ACTION("edit", $urlData); } // END - if @@ -309,13 +318,13 @@ function SURFBAR_MEMBER_EDIT_ACTION ($urlData) { // Show delete form or do the changes function SURFBAR_MEMBER_DELETE_ACTION ($urlData) { // Is the "execute" flag there? - if (isset($urlData['execute'])) { + if (isset($urlData['delete']['execute'])) { // Execute the changes - return SURFBAR_MEMBER_EXECUTE_ACTION("del", $urlData); + return SURFBAR_MEMBER_EXECUTE_ACTION("delete", $urlData); } // END - if // Display form - return SURFBAR_MEMBER_DISPLAY_ACTION_FORM("del", $urlData); + return SURFBAR_MEMBER_DISPLAY_ACTION_FORM("delete", $urlData); } // Display selected "action form" function SURFBAR_MEMBER_DISPLAY_ACTION_FORM ($action, $urlData) { @@ -351,6 +360,69 @@ function SURFBAR_MEMBER_DISPLAY_ACTION_FORM ($action, $urlData) { // All fine by default ... ;-) return true; } +// Execute choosen action +function SURFBAR_MEMBER_EXECUTE_ACTION ($action, $urlData) { + // By default nothing is executed + $executed = false; + + // Is limitation "no" and "limit" is > 0? + if ((isset($urlData[$action]['limited'])) && ($urlData[$action]['limited'] == "N") && ((isset($urlData[$action]['limit'])) && ($urlData[$action]['limit'] > 0)) || (!isset($urlData[$action]['limit']))) { + // Set it to unlimited + $urlData[$action]['limit'] = 0; + } // END - if + + // Construct function name + $functionName = sprintf("SURFBAR_MEMBER_EXECUTE_%s_ACTION", strtoupper($action)); + + // Is 'userid' set and not 'uid' ? + if ((!isset($urlData['uid'])) && (isset($urlData['userid']))) { + // Auto-fix this + $urlData['uid'] = $urlData['userid']; + } // END - if + + // Is that function there? + if (function_exists($functionName)) { + // Execute the function + if (call_user_func_array($functionName, array($urlData)) == true) { + // Update status as well + $executed = SURFBAR_CHANGE_STATUS($urlData['id'], $urlData['status'], $urlData['new_status'], array($urlData['id'] => $urlData)); + } // END - if + } else { + // Not found! + ADD_FATAL(sprintf(MEMBER_SURFBAR_EXECUTE_ACTION_404, $functionName)); + } + + // Return status + return $executed; +} +// "Execute edit" function: Update changed data +function SURFBAR_MEMBER_EXECUTE_EDIT_ACTION ($urlData) { + // Translate URLs for testing + $url1 = COMPILE_CODE($urlData['url']); + $url2 = COMPILE_CODE($urlData['edit']['url']); + + // Has the URL or limit changed? + if (true) { + //if (($urlData['views_allowed'] != $urlData['edit']['limit']) || ($url1 != $url2)) { + // Run the query + SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_surfbar_urls SET url='%s', views_allowed=%s, views_max=%s WHERE id=%s AND status='%s' LIMIT 1", + array($urlData['url'], $urlData['edit']['limit'], $urlData['edit']['limit'], $urlData['id'], $urlData['status']), __FILE__, __LINE__); + + // Prepare new data + $urlData['new_url'] = $urlData['edit']['url']; + $urlData['new_limit'] = $urlData['edit']['limit']; + unset($urlData['edit']); + + // Send admin notification + SURFBAR_NOTIFY_ADMIN("url_edited", $urlData); + + // Send user notification + SURFBAR_NOTIFY_USER("url_edited", $urlData); + } // END - if + + // All fine! + return true; +} // // ----------------------------------------------------------------------------- // Self-maintenance functions @@ -545,10 +617,25 @@ function SURFBAR_NOTIFY_ADMIN ($messageType, $content) { // Set default subject if following eval() wents wrong $subject = ADMIN_SURFBAR_NOTIFY_DEFAULT_SUBJECT; - // Prepare subject - $subject = constant(sprintf("ADMIN_SURFBAR_NOTIFY_%s_SUBJECT", + // Create constant name + $constantName = sprintf("ADMIN_SURFBAR_NOTIFY_%s_SUBJECT", strtoupper($messageType) - )); + ); + + // Prepare subject + if (defined($constantName)) { + $subject = constant($constantName); + } else { + ADD_FATAL(ADMIN_SURFBAR_NOTIFY_SUBJECT_404, $constantName); + } + + // Translate some data if present + if (isset($content['status'])) $content['status'] = SURFBAR_TRANSLATE_STATUS($content['status']); + if (isset($content['registered'])) $content['registered'] = MAKE_DATETIME($content['registered'], "2"); + if (isset($content['last_locked'])) $content['last_locked'] = MAKE_DATETIME($content['last_locked'], "2"); + if (isset($content['views_total'])) $content['views_total'] = TRANSLATE_COMMA($content['views_total']); + if (isset($content['views_allowed'])) $content['views_allowed'] = TRANSLATE_COMMA($content['views_allowed']); + if (isset($content['views_max'])) $content['views_max'] = TRANSLATE_COMMA($content['views_max']); // Send the notification out return SEND_ADMIN_NOTIFICATION($subject, $templateName, $content, $content['uid']); @@ -566,10 +653,17 @@ function SURFBAR_NOTIFY_USER ($messageType, $content) { // Set default subject if following eval() wents wrong $subject = MEMBER_SURFBAR_NOTIFY_DEFAULT_SUBJECT; - // Prepare subject - $subject = constant(sprintf("MEMBER_SURFBAR_NOTIFY_%s_SUBJECT", + // Create constant name + $constantName = sprintf("MEMBER_SURFBAR_NOTIFY_%s_SUBJECT", strtoupper($messageType) - )); + ); + + // Prepare subject + if (defined($constantName)) { + $subject = constant($constantName); + } else { + ADD_FATAL(MEMBER_SURFBAR_NOTIFY_SUBJECT_404, $constantName); + } // Load template $mailText = LOAD_EMAIL_TEMPLATE($templateName, $content, $content['uid']); @@ -1077,6 +1171,12 @@ function SURFBAR_CHANGE_STATUS ($urlId, $prevStatus, $newStatus, $data=array()) $data = SURFBAR_GET_URL_DATA($urlId); } // END - if + // Is the new status set? + if ((!is_string($newStatus)) || (empty($newStatus))) { + // Abort here, but fine! + return true; + } // END - if + // Is the status like prevStatus is saying? if ($data[$urlId]['status'] != $prevStatus) { // No, then abort here