Adjusts ad bidding to avoid round off errors, updates seekquarry ad purchase link, allows ad script to work for range of db versions, a=chris

Chris Pollett [2015-09-01 15:Sep:st]
Adjusts ad bidding to avoid round off errors, updates seekquarry ad purchase link, allows ad script to work for range of db versions, a=chris
Filename
src/controllers/components/AdvertisementComponent.php
src/models/AdvertisementModel.php
src/views/elements/ManagecreditsElement.php
src/views/elements/ServersettingsElement.php
diff --git a/src/controllers/components/AdvertisementComponent.php b/src/controllers/components/AdvertisementComponent.php
index 87096ea25..b35f1d8e2 100644
--- a/src/controllers/components/AdvertisementComponent.php
+++ b/src/controllers/components/AdvertisementComponent.php
@@ -92,7 +92,7 @@ class AdvertisementComponent extends Component
             $ad_script_found = false;
             for ($i = C\YIOOP_VERSION; $i >= C\MIN_AD_VERSION; $i++) {
                 $get_credit_token_initialize_script =
-                    "FN" . L\crawlHash(C\NAME_SERVER . C\YIOOP_VERSION .
+                    "FN" . md5(C\NAME_SERVER . C\YIOOP_VERSION .
                     "getCreditTokenInitializeScript");
                 if (method_exists( C\NS_CONFIGS . "CreditConfig",
                     $get_credit_token_initialize_script)) {
@@ -261,7 +261,7 @@ class AdvertisementComponent extends Component
                     $message = "";
                     $translate_holder = tl('advertisement_component_buy_ad');
                     $advertisement_model->addAdvertisement($advertisement,
-                        $data["AD_KEYWORDS"], $data["BUDGET"], $user_id);
+                        $data["AD_KEYWORDS"], $data['AD_MIN_BID'], $user_id);
                     $credit_model->updateCredits($user_id,
                         -$data["BUDGET"],
                         'advertisement_component_buy_ad');
diff --git a/src/models/AdvertisementModel.php b/src/models/AdvertisementModel.php
index 84d2e6ec6..8fac2a6da 100644
--- a/src/models/AdvertisementModel.php
+++ b/src/models/AdvertisementModel.php
@@ -145,15 +145,27 @@ class AdvertisementModel extends Model
         $ad_day_count = $ad_date_diff/C\ONE_DAY;
         $keywords = array_keys($keyword_min_prices);
         $overbid_ratio = $ad['BUDGET']/$min_bid;
+        $left_over = 0;
         foreach ($keywords as $keyword) {
             $date = $ad['START_DATE'];
             for ($j = 0 ; $j < $ad_day_count ; $j++ ) {
-                $day_bid_amt = ceil($overbid_ratio *
-                    $keyword_min_prices[$keyword][$date]);
+                $rational_day_bid_amt = $overbid_ratio *
+                    $keyword_min_prices[$keyword][$date];
+                $day_bid_amt = floor($rational_day_bid_amt);
+                $left_over += $rational_day_bid_amt - $day_bid_amt;
+                // left over code used to handle rounding
+                if ($left_over >= 1) {
+                    $day_bid_amt++;
+                    $left_over--;
+                }
                 $this->addBid($ad_id, $keyword, $day_bid_amt, $date);
+                $old_date = $date;
                 $date = date(C\AD_DATE_FORMAT, strtotime($date .' +1 day'));
             }
         }
+        if ($left_over > 0) {
+            $this->addBid($ad_id, $keyword, 1, $old_date);
+        }
     }
     /**
      * Update an existing advertisement in the database
diff --git a/src/views/elements/ManagecreditsElement.php b/src/views/elements/ManagecreditsElement.php
index bf1b73a0b..b9d782f7a 100644
--- a/src/views/elements/ManagecreditsElement.php
+++ b/src/views/elements/ManagecreditsElement.php
@@ -123,20 +123,22 @@ class ManagecreditsElement extends Element
                 tl('managecredits_element_purchase')
                 ?>" type="submit" />
             <?php
-            $ad_script_found = false;
-            for ($i = C\YIOOP_VERSION; $i >= C\MIN_AD_VERSION; $i++) {
-                $get_submit_purchase_script = "FN" . L\crawlHash(
-                    C\NAME_SERVER . C\YIOOP_VERSION .
-                    "getSubmitPurchaseScript");
-                if (method_exists( C\NS_CONFIGS . "CreditConfig",
-                    $get_submit_purchase_script)) {
-                    $ad_script_found = true;
-                    break;
+            if (C\CreditConfig::isActive()) {
+                $ad_script_found = false;
+                for ($i = C\YIOOP_VERSION; $i >= C\MIN_AD_VERSION; $i++) {
+                    $get_submit_purchase_script = "FN" . md5(
+                        C\NAME_SERVER . C\YIOOP_VERSION .
+                        "getSubmitPurchaseScript");
+                    if (method_exists( C\NS_CONFIGS . "CreditConfig",
+                        $get_submit_purchase_script)) {
+                        $ad_script_found = true;
+                        break;
+                    }
+                }
+                if ($ad_script_found) {
+                    $data['SCRIPT'] .=
+                        e(C\CreditConfig::$get_submit_purchase_script());
                 }
-            }
-            if ($ad_script_found) {
-                $data['SCRIPT'] .=
-                    e(C\CreditConfig::$get_submit_purchase_script());
             }
             ?>
             </td>
diff --git a/src/views/elements/ServersettingsElement.php b/src/views/elements/ServersettingsElement.php
index 20a92e77f..f3ff7c2cf 100644
--- a/src/views/elements/ServersettingsElement.php
+++ b/src/views/elements/ServersettingsElement.php
@@ -272,7 +272,7 @@ class ServersettingsElement extends Element
             if (!C\CreditConfig::isActive()) { ?>
                 <br /><b class="red"><?=
                 tl('serversettings_element_no_payment_processing') ?></b><br />
-                [<a href="https://www.seekquarry.com/"><?=
+                [<a href="https://www.seekquarry.com/adscript"><?=
                 tl('serversettings_element_purchase_processing')
                 ?></a>]
                 <?php
ViewGit