]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/rallye_functions.php
Even more rewrites/fixes from EL branch (please report any broken part after you...
[mailer.git] / inc / libs / rallye_functions.php
index 59c1f0192f29f6005113ce91fa2cea04f8588a34..4e03f7ecba9c6e2212103e1ee12d5bf12df7f1da 100644 (file)
@@ -159,21 +159,23 @@ function addReferalRallyePrices ($rallye, $mode='email') {
        } // END - switch
 
        // Load prices
-       $result_prices = SQL_QUERY("SELECT
+       $result_prices = SQL_QUERY_ESC("SELECT
        `price_level`, `points`, `info`
 FROM
        `{?_MYSQL_PREFIX?}_rallye_prices`
 WHERE
-       `rallye_id`='".$rallye."'
+       `rallye_id`=%s
 ORDER BY
        `price_level` ASC",
-               __FUNCTION__, __LINE__);
+               array($rallye), __FUNCTION__, __LINE__);
+
+       // Entries found?
        if (SQL_NUMROWS($result_prices) > 0) {
                // Load prices
                if ($mode == "\n") $prices = "{--RALLYE_MEMBER_PRICES_ADDED--}:".$mode."------------------------------".$mode;
                $prices = '';
                while ($content = SQL_FETCHARRAY($result_prices)) {
-                       $prices .= $content['price_level'].getMessage('RALLYE_PRICE').": ";
+                       $prices .= $content['price_level']. '{--RALLYE_PRICE--}: ';
                        if (!empty($content['info'])) {
                                $prices .= $content['info'];
                        } else {
@@ -304,9 +306,9 @@ LIMIT 1",
                $SW = 3 - $SW;
        } // END - for
 
-       // Translate min_prices/users
-       $content['min_prices'] = determineReferalRallyeMinimumPrices($min_prices);
-       $content['min_users']  = determineReferalRallyeMinimumUsers($min_users);
+       // Add min_prices/users
+       $content['min_prices'] = bigintval($min_prices);
+       $content['min_users']  = bigintval($min_users);
 
        // Add footer
        $OUT .= loadTemplate('guest_rallye_footer', true, $content);
@@ -320,7 +322,7 @@ function addUserToReferalRallye ($userid, $content = array()) {
        $add = '';
 
        // Updated extension?
-       if (getExtensionVersion('rallye') >= '0.2.0') {
+       if (isExtensionInstalledAndNewer('rallye', '0.2.0')) {
                $add .= ", `min_users`, `min_prices`";
        } // END - if
 
@@ -340,7 +342,7 @@ LIMIT 1", __FUNCTION__, __LINE__);
                $min_users = '0'; $min_prices = '0';
 
                // Load data
-               if (getExtensionVersion('rallye') >= '0.2.0') {
+               if (isExtensionInstalledAndNewer('rallye', '0.2.0')) {
                        list($id, $title, $start, $end, $notify, $min_users, $min_prices) = SQL_FETCHROW($result);
                } else {
                        list($id, $title, $start, $end, $notify) = SQL_FETCHROW($result);
@@ -777,21 +779,21 @@ function addReferalRallyeTemplateSelection ($name = 'template', $default = '') {
                $read = substr($read, 7, strpos($read, '.') - 7);
 
                // Accept only template names between 1 and 255 chars length
-               if ((strlen($read) < 256) && (!empty($read))) $ral[] = $read;
-       } // END - while
+               if ((strlen($read) < 256) && (!empty($read))) {
+                       // Valid entry found!
+                       $ral[$read] = $read;
+               } else {
+                       // Log invalid
+                       logDebugMessage(__FUNCTION__, __LINE__, sprintf("WARNING: Template %s not used.", $read));
+               }
+       } // END - foreach
 
        // Do we have found templates which we can link with the new rallye?
        if (!empty($ral[0])) {
                // Generate selection box for all found templates
-               // @TODO Rewrite this to our API function
-               $OUT  = "<select name=\"".$name."\" size=\"1\" class=\"admin_select\">
-  <option value=\"\">{--SELECT_NONE--}</option>\n";
-               foreach ($ral as $rallye) {
-                       $OUT .= "  <option value=\"".$rallye."\"";
-                       if ($default == $rallye) $OUT .= ' selected="selected"';
-                       $OUT .= ">".$rallye."</option>\n";
-               } // END - foreach
-               $OUT .= "</select>\n";
+               $OUT  = '<select name="' . $name . '" size="1" class="admin_select">';
+               $OUT .= generateOptionList('/ARRAY/', array_keys($ral), array_values($ral), $default, '', 'none');
+               $OUT .= '</select>';
        } else {
                // No rallye templates found
                $OUT = getMessage('RALLYE_NO_TEMPLATES_FOUND');
@@ -801,16 +803,16 @@ function addReferalRallyeTemplateSelection ($name = 'template', $default = '') {
        return $OUT;
 }
 
-//
-function getReferalRallyeRefsCount ($userid, $old = '0') {
+// @TODO Please document this function
+function getReferalRallyeRefsCount ($currUserid, $old = '0') {
        // Check current refs
-       if (getExtensionVersion('cache') >= '0.1.2') {
+       if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
                // Get refs from cache
                $cnt = '0';
                foreach ($GLOBALS['cache_array']['refsystem']['userid'] as $id => $userid) {
                        // Do we have a ref for this user?
                        //* DEBUG: */ print("id={$id},userid={$userid},userid={$userid},old={$old},level={$GLOBALS['cache_array']['refsystem']['level'][$id]}<br />");
-                       if (($userid == $userid) && ($GLOBALS['cache_array']['refsystem']['level'][$id] == 1)) {
+                       if (($currUserid == $userid) && ($GLOBALS['cache_array']['refsystem']['level'][$id] == 1)) {
                                //* DEBUG: */ print("userid matches!<br />");
                                foreach ($GLOBALS['cache_array']['refdepths']['level'] as $level) {
                                        if (($level == $GLOBALS['cache_array']['refsystem']['level'][$id]) && ($level == 1)) {
@@ -844,12 +846,25 @@ function getReferalRallyeRefsCount ($userid, $old = '0') {
                } // END - if
        } else {
                // Load current refs from database
-               $result_ref = SQL_QUERY_ESC("SELECT SUM(s.counter) AS cnt
-FROM `{?_MYSQL_PREFIX?}_refsystem` AS s
-LEFT JOIN `{?_MYSQL_PREFIX?}_refdepths` AS d
-ON s.level=d.level
-WHERE s.userid=%s AND s.level=1", array(bigintval($userid)), __FUNCTION__, __LINE__);
+               $result_ref = SQL_QUERY_ESC("SELECT
+       SUM(s.counter) AS cnt
+FROM
+       `{?_MYSQL_PREFIX?}_refsystem` AS s
+LEFT JOIN
+       `{?_MYSQL_PREFIX?}_refdepths` AS d
+ON
+       s.level=d.level
+WHERE
+       s.userid=%s AND
+       s.level=1",
+                       array(
+                               bigintval($userid)
+                       ), __FUNCTION__, __LINE__);
+
+               // Load count @TODO Can't we rewrite this to our API?
                list($cnt) = SQL_FETCHROW($result_ref);
+
+               // Free result
                SQL_FREERESULT($result_ref);
                if (empty($cnt)) {
                        $cnt = '0';