]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/rallye_functions.php
HTML->XHTML preparation (still *A LOT* to convert
[mailer.git] / inc / libs / rallye_functions.php
index 9e096a317e5d761be0a2ac3de513272a537c1592..c6ad2db0051b3fa74dd5c17d1ae7ffd089e5accb 100644 (file)
@@ -42,7 +42,7 @@ function RALLYE_AUTOSTART_RALLYES($result)
 {
        // Global data array for LOAD_EMAIL_TEMPLATE()
        $DATA = array();
-       global $DATA, $_CONFIG;
+       global $DATA;
 
        // Load all rallyes (usally we have only one rallye active per time!
        list($id, $title, $start, $end, $notify, $min_users, $min_prices) = SQL_FETCHROW($result);
@@ -184,8 +184,6 @@ function RALLYE_ADD_PRICES($rallye,$mode="email")
 //
 function RALLYE_ADD_TOPUSERS($rallye,$default=0)
 {
-       global $_CONFIG;
-
        // First check how many prices are set
        $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id=%s ORDER BY price_level",
         array(bigintval($rallye)), __FILE__, __LINE__);
@@ -251,14 +249,14 @@ LIMIT 1", array(bigintval($uid), getConfig('ref_payout')), __FILE__, __LINE__);
                $OUT .= "<TR>
   <TD class=\"switch_sw".$SW." bottom2\">&nbsp;&nbsp;".($idx+1).".</TD>
   <TD align=\"center\" class=\"switch_sw".$SW." bottom2\">";
-               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "<STRONG>";
+               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "<strong>";
                $OUT .= $DATA['uid'][$idx];
-               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "</STRONG>";
+               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "</strong>";
                $OUT .= "</TD>
   <TD align=\"center\" class=\"switch_sw".$SW." bottom2\">";
-               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "<STRONG>";
+               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "<strong>";
                $OUT .= $DATA['ref'][$idx];
-               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "</STRONG>";
+               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "</strong>";
                $OUT .= "</TD>
 </TR>\n";
                $SW = 3 - $SW;
@@ -348,7 +346,7 @@ VALUES ('%s','%s','0')",
 //
 function RALLYE_EXPIRE_RALLYES($result)
 {
-       global $DATA, $_CONFIG;
+       global $DATA;
 
        // Load rallye data
        list($id, $title, $start, $end, $notify, $min_users, $min_prices) = SQL_FETCHROW($result);
@@ -513,9 +511,9 @@ function RALLYE_LOAD_PRICES_ARRAY($rallye)
        // Return array
        return $prices;
 }
+
 //
-function RALLYE_LOAD_USERS_ARRAY($rallye)
-{
+function RALLYE_LOAD_USERS_ARRAY ($rallye) {
        global $_CONFIG;
 
        // Fix zero points to 0.00000
@@ -530,9 +528,8 @@ function RALLYE_LOAD_USERS_ARRAY($rallye)
 
        // Load users                          uid    old  points earned
        $result_user = SQL_QUERY_ESC("SELECT userid, refs, curr_points FROM "._MYSQL_PREFIX."_rallye_users WHERE rallye_id=%s ORDER BY userid",
-        array(bigintval($rallye)), __FILE__, __LINE__);
-       while(list($uid, $refs, $cpoints) = SQL_FETCHROW($result_user))
-       {
+               array(bigintval($rallye)), __FILE__, __LINE__);
+       while (list($uid, $refs, $cpoints) = SQL_FETCHROW($result_user)) {
                // Load current ref count
                $cnt = RALLYE_GET_REFCOUNT($uid, $refs);
 
@@ -564,21 +561,23 @@ WHERE d.status='CONFIRMED' AND d.max_mails > 0 AND d.mails_confirmed >= %s AND p
        $prices = RALLYE_LOAD_PRICES_ARRAY($rallye);
 
        // Merge users into prices
-       foreach ($prices['level'] as $k => $lvl)
-       {
-               $prices['uid'][$k]  = $users['uid'][$k];
-               if (empty($prices['uid'][$k])) $prices['uid'][$k]  = "---";
-               $prices['ref'][$k] = $users['ref'][$k];
-               if (empty($prices['ref'][$k])) $prices['ref'][$k] = "---";
-               $prices['cpoints'][$k] = $users['cpoints'][$k];
-       }
+       foreach ($prices['level'] as $k => $lvl) {
+               // We only need to check one element in $users, see above while() block
+               if (isset($users['uid'][$k])) {
+                       $prices['uid'][$k]  = $users['uid'][$k];
+                       if (empty($prices['uid'][$k])) $prices['uid'][$k]  = "---";
+                       $prices['ref'][$k] = $users['ref'][$k];
+                       if (empty($prices['ref'][$k])) $prices['ref'][$k] = "---";
+                       $prices['cpoints'][$k] = $users['cpoints'][$k];
+               } // END - if
+       } // END - foreach
 
        // Return completed array
        return $prices;
 }
+
 //
-function RALLYE_LIST_WINNERS($rallye,$default=0)
-{
+function RALLYE_LIST_WINNERS ($rallye, $default=0) {
        // First check how many prices are set
        $result_prices = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id=%s ORDER BY price_level",
         array(bigintval($rallye)), __FILE__, __LINE__);
@@ -624,19 +623,19 @@ function RALLYE_LIST_WINNERS($rallye,$default=0)
                $OUT .= "<TR>
   <TD class=\"switch_sw".$SW." bottom2".$ADD."\">&nbsp;&nbsp;".($idx+1).".</TD>
   <TD align=\"center\" class=\"switch_sw".$SW." bottom2".$ADD."\">";
-               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "<STRONG>";
+               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "<strong>";
                $OUT .= $DATA['uid'][$idx];
-               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "</STRONG>";
+               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "</strong>";
                $OUT .= "</TD>
   <TD align=\"center\" class=\"switch_sw".$SW." bottom2".$ADD."\">";
-               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "<STRONG>";
+               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "<strong>";
                $OUT .= $DATA['ref'][$idx];
-               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "</STRONG>";
+               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "</strong>";
                $OUT .= "</TD>
   <TD align=\"center\" class=\"switch_sw".$SW." bottom2".$ADD."\">";
-               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "<STRONG>";
+               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "<strong>";
                $OUT .= $DATA['infos'][$idx];
-               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "</STRONG>";
+               if (($DATA['uid'][$idx] == $default) && ($default > 0)) $OUT .= "</strong>";
                $OUT .= "</TD>
 </TR>\n";
                $SW = 3 - $SW;
@@ -650,7 +649,7 @@ function RALLYE_LIST_WINNERS($rallye,$default=0)
 //
 function RALLYE_DELETE_EXPIRED_RALLYES()
 {
-       global $DATA, $_CONFIG;
+       global $DATA;
 
        // Check for expired rallyes
        $EXPIRE = getConfig('one_day') * 3; // @TODO The hard-coded value...
@@ -718,15 +717,15 @@ function RALLYE_TEMPLATE_SELECTION($name="template", $default="")
        if (!empty($ral[0]))
        {
                // Generate selection box for all found templates
-               $OUT  = "<SELECT name=\"".$name."\" size=\"1\" class=\"admin_select\">
-  <OPTION value=\"\">".SELECT_NONE."</OPTION>\n";
+               $OUT  = "<select name=\"".$name."\" size=\"1\" class=\"admin_select\">
+  <option value=\"\">".SELECT_NONE."</option>\n";
                foreach ($ral as $rallye)
                {
-                    $OUT .= "  <OPTION value=\"".$rallye."\"";
+                    $OUT .= "  <option value=\"".$rallye."\"";
                        if ($default == $rallye) $OUT .= " selected default";
-                       $OUT .= ">".$rallye."</OPTION>\n";
+                       $OUT .= ">".$rallye."</option>\n";
                }
-               $OUT .= "</SELECT>\n";
+               $OUT .= "</select>\n";
        }
         else
        {
@@ -739,21 +738,21 @@ function RALLYE_TEMPLATE_SELECTION($name="template", $default="")
 }
 //
 function RALLYE_GET_REFCOUNT($uid, $old=0) {
-       global $_CONFIG, $cacheArray;
+       global $cacheArray;
 
        // Check current refs
        if (GET_EXT_VERSION("cache") >= "0.1.2") {
                // Get refs from cache
                $cnt = 0;
-               foreach ($cacheArray['ref_system']['userid'] as $id => $u_id) {
+               foreach ($cacheArray['refsystem']['userid'] as $id => $u_id) {
                        // Do we have a ref for this user?
-                       //* DEBUG: */ echo "id={$id},u_id={$u_id},uid={$uid},old={$old},level={$cacheArray['ref_system']['level'][$id]}<br />\n";
-                       if (($u_id == $uid) && ($cacheArray['ref_system']['level'][$id] == 1)) {
+                       //* DEBUG: */ echo "id={$id},u_id={$u_id},uid={$uid},old={$old},level={$cacheArray['refsystem']['level'][$id]}<br />\n";
+                       if (($u_id == $uid) && ($cacheArray['refsystem']['level'][$id] == 1)) {
                                //* DEBUG: */ echo "uid matches!<br />\n";
                                foreach ($cacheArray['ref_depths']['level'] as $level) {
-                                       if (($level == $cacheArray['ref_system']['level'][$id]) && ($level == 1)) {
+                                       if (($level == $cacheArray['refsystem']['level'][$id]) && ($level == 1)) {
                                                // Level does exist so abort here
-                                               $cnt = $cacheArray['ref_system']['counter'][$id];
+                                               $cnt = $cacheArray['refsystem']['counter'][$id];
                                                //* DEBUG: */ echo "*".$uid."/".$cnt."*<br />";
                                                break;
                                        } elseif ($level > 1) {
@@ -766,14 +765,14 @@ function RALLYE_GET_REFCOUNT($uid, $old=0) {
                                if ($cnt > 0) break;
                        }
                }
-               //* DEBUG: */ echo "<PRE>";
-               //* DEBUG: */ print_r($cacheArray['ref_system']);
-               //* DEBUG: */ echo "</PRE>";
+               //* DEBUG: */ echo "<pre>";
+               //* DEBUG: */ print_r($cacheArray['refsystem']);
+               //* DEBUG: */ echo "</pre>";
                //* DEBUG: */ die();
 
                if ($cnt > 0) {
                        // Count cache hits
-                       if (getConfig('cache_hits') > 0) { $_CONFIG['cache_hits']++; } else { $_CONFIG['cache_hits'] = 1; }
+                       incrementConfigEntry('cache_hits');
 
                        // Remove old refs
                        //* DEBUG: */ echo "+".$cnt."/".$old."+<br />";
@@ -788,12 +787,9 @@ ON s.level=d.level
 WHERE s.userid=%s AND s.level=1", array(bigintval($uid)), __FILE__, __LINE__);
                list($cnt) = SQL_FETCHROW($result_ref);
                SQL_FREERESULT($result_ref);
-               if (empty($cnt))
-               {
+               if (empty($cnt)) {
                        $cnt = 0;
-               }
-                else
-               {
+               } else {
                        $cnt -= $old;
                }
        }