Fix for error and min/max refback displayed in edit form
[mailer.git] / inc / modules / member / what-refback.php
index 309e927efbdec11c5750ec45f2c49d432c429847..90d3ad7f624c3dde64cd0f7312325f47d9cf7006 100644 (file)
@@ -44,6 +44,14 @@ if (!defined('__SECURITY')) {
        return;
 }
 
+// Is the refback system enabled?
+if ($_CONFIG['refback_enabled'] == "N") {
+       // Output message
+       LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_REFBACK_DISABLED);
+       // Abort here
+       return false;
+} // END - if
+
 // Add description as navigation point
 ADD_DESCR("member", __FILE__);
 
@@ -51,19 +59,25 @@ ADD_DESCR("member", __FILE__);
 if ((isset($_POST['edit'])) && (isset($_POST['id']))) {
        // Okay, has the user entered some values?
        if (isset($_POST['percents'])) {
-               // Change ref-back for this direct id
-               $status = REFBACK_CHANGE_MEMBER_PERCENTS($_POST['id'], $_POST['percents']);
-
-               // Check status
-               if (isset($status['ok'])) {
-                       // No message found
-                       LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_REFBACK_DONE);
-               } elseif (isset($status['message'])) {
-                       // Something went wrong with error message
-                       LOAD_TEMPLATE("admin_settings_saved", false, sprintf(MEMBER_REFBACK_ERROR_MESSAGE, $status['message']));
+               // Validate percents
+               if ((($_POST['percents'] >= $_CONFIG['refback_min_percents']) || ($_POST['percents'] == 0)) && ($_POST['percents'] <= $_CONFIG['refback_max_percents'])) {
+                       // Change ref-back for this direct id
+                       $status = REFBACK_CHANGE_MEMBER_PERCENTS($_POST['id'], $_POST['percents']);
+
+                       // Check status
+                       if (isset($status['ok'])) {
+                               // No message found
+                               LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_REFBACK_DONE);
+                       } elseif (isset($status['message'])) {
+                               // Something went wrong with error message
+                               LOAD_TEMPLATE("admin_settings_saved", false, sprintf(MEMBER_REFBACK_ERROR_MESSAGE, $status['message']));
+                       } else {
+                               // No message found
+                               LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_REFBACK_ERROR_EMPTY_MESSAGE);
+                       }
                } else {
-                       // No message found
-                       LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_REFBACK_ERROR_EMPTY_MESSAGE);
+                       // Percents out-of-bounds ;-)
+                       LOAD_TEMPLATE("admin_settings_saved", false, sprintf(MEMBER_REFBACK_ERROR_OUT_OF_BOUNDS, $_CONFIG['refback_min_percents'], $_CONFIG['refback_max_percents']));
                }
 
                // Insert line
@@ -74,6 +88,8 @@ if ((isset($_POST['edit'])) && (isset($_POST['id']))) {
 
                // Translate comma
                $content['refback'] = TRANSLATE_COMMA($content['refback']);
+               $content['max']     = $_CONFIG['refback_max_percents'];
+               $content['min']     = $_CONFIG['refback_min_percents'];
 
                // Load form for editing
                LOAD_TEMPLATE("member_refback_edit", false, $content);
@@ -124,7 +140,7 @@ if (SQL_NUMROWS($result) > 0) {
 
                // Remember the content
                $content['counter']  = TRANSLATE_COMMA($counter);
-               $content['percents'] = TRANSLATE_COMMA($content['percents']);
+               $content['percents'] = TRANSLATE_COMMA($content['percents'], true, 1);
                $content['rows']     = $rows;
 
                // Load level template