]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/surfbar_functions.php
Surfbar member actions continued (good night! :))
[mailer.git] / inc / libs / surfbar_functions.php
index 0a404409889307001f540de5bdd5c47da6afd272..9d4ebe630d6364392ee9a29fa149bec768c43c9a 100644 (file)
@@ -40,7 +40,7 @@ if (!defined('__SECURITY')) {
 // -----------------------------------------------------------------------------
 //                               Admin functions
 // -----------------------------------------------------------------------------
-
+//
 // Admin has added an URL with given user id and so on
 function SURFBAR_ADMIN_ADD_URL ($url) {
        // Do some pre-checks
@@ -91,11 +91,11 @@ function SURFBAR_ADMIN_UNLOCK_URL_IDS ($IDs) {
        // Return total status
        return $done;
 }
-
+//
 // -----------------------------------------------------------------------------
 //                               Member functions
 // -----------------------------------------------------------------------------
-
+//
 // Member has added an URL
 function SURFBAR_MEMBER_ADD_URL ($url) {
        global $_CONFIG;
@@ -122,10 +122,58 @@ function SURFBAR_MEMBER_ADD_URL ($url) {
        // Register the new URL
        return SURFBAR_REGISTER_URL($url, $GLOBALS['userid'], $reward, $costs);
 }
+// Create list of actions depending on status for the user
+function SURFBAR_MEMBER_ACTIONS ($urlId, $status) {
+       // Load all actions in an array for given status
+       $actionArray = SURFBAR_GET_ACTION_ARRAY($status);
+
+       // Init HTML code
+       $OUT = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\">
+<tr>\n";
+
+       // Calculate width
+       $width = round(100 / count($actionArray));
+
+       // "Walk" through all actions and create forms
+       foreach ($actionArray as $actionId=>$action) {
+               // Add form for this action
+               $OUT .= sprintf("       <td align=\"center\" width=\"%d%%\">
+               <form action=\"".URL."/modules.php?module=login&amp;what=surfbar_list\" method=\"post\" style=\"padding-bottom:0px\">
+                       <input type=\"hidden\" name=\"id\" value=\"%s\" />
+                       <input type=\"hidden\" name=\"action\" value=\"%s\" />
+                       <input type=\"submit\" class=\"member_submit\" name=\"ok\" title=\"{--MEMBER_SURFBAR_ACTION_%s_TITLE--}\" value=\"{--MEMBER_SURFBAR_ACTION_%s_SUBMIT--}\" />
+               </form>
+       </td>\n",
+                       $width,
+                       bigintval($urlId),
+                       strtolower($action),
+                       strtoupper($action),
+                       strtoupper($action)
+               );
+       } // END - foreach
+
+       // Close table
+       $OUT .= "</tr>
+</table>\n";
+
+       // Return code
+       return $OUT;
+}
+// Do the member form request
+function SURFBAR_MEMBER_DO_FORM ($formData, $URLs) {
+       // Is this a member?
+       if (!IS_MEMBER()) {
+               // No member!
+               return false;
+       } // END - if
+
+       /* DEBUG: */ die("<pre>".print_r($formData, true)."</pre><pre>".print_r($URLs, true)."</pre>");
+}
+//
 // -----------------------------------------------------------------------------
 //                               Generic functions
 // -----------------------------------------------------------------------------
-
+//
 // Looks up by an URL
 function SURFBAR_LOOKUP_BY_URL ($url) {
        // Now lookup that given URL by itself
@@ -481,7 +529,7 @@ LIMIT %s",
        return $cnt;
 }
 // Generate a validation code for the given id number
-function SURFBAR_GENERATE_VALIDATION_CODE ($id, $salt="") {
+function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt="") {
        global $_CONFIG, $SURFBAR_CACHE;
 
        // @TODO Invalid salt should be refused
@@ -508,7 +556,7 @@ function SURFBAR_GENERATE_VALIDATION_CODE ($id, $salt="") {
                }
 
                // ... and now the validation code
-               $valCode = GEN_RANDOM_CODE($length, sha1(SURFBAR_GET_SALT().":".$id), $GLOBALS['userid']);
+               $valCode = GEN_RANDOM_CODE($length, sha1(SURFBAR_GET_SALT().":".$urlId), $GLOBALS['userid']);
                //DEBUG_LOG(__FUNCTION__.":valCode={$valCode}");
        } // END - while
 
@@ -521,14 +569,14 @@ function SURFBAR_GENERATE_VALIDATION_CODE ($id, $salt="") {
        return $valHashedCode;
 }
 // Check validation code
-function SURFBAR_CHECK_VALIDATION_CODE ($id, $check, $salt) {
+function SURFBAR_CHECK_VALIDATION_CODE ($urlId, $check, $salt) {
        global $SURFBAR_CACHE;
 
        // Secure id number
-       $id = bigintval($id);
+       $urlId = bigintval($urlId);
 
        // Now generate the code again
-       $code = SURFBAR_GENERATE_VALIDATION_CODE($id, $salt);
+       $code = SURFBAR_GENERATE_VALIDATION_CODE($urlId, $salt);
 
        // Return result of checking hashes and salts
        //DEBUG_LOG(__FUNCTION__.":---".$code."|".$check."---");
@@ -536,19 +584,19 @@ function SURFBAR_CHECK_VALIDATION_CODE ($id, $check, $salt) {
        return (($code == $check) && ($salt == SURFBAR_GET_DATA('last_salt')));
 }
 // Lockdown the userid/id combination (reload lock)
-function SURFBAR_LOCKDOWN_ID ($id) {
+function SURFBAR_LOCKDOWN_ID ($urlId) {
        //* //DEBUG: */ print "LOCK!");
        ///* //DEBUG: */ return;
        // Just add it to the database
        SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_surfbar_locks (userid, url_id) VALUES(%s, %s)",
-               array($GLOBALS['userid'], bigintval($id)), __FILE__, __LINE__);
+               array($GLOBALS['userid'], bigintval($urlId)), __FILE__, __LINE__);
 
        // Remove the salt from database
        SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_surfbar_salts WHERE url_id=%s AND userid=%s LIMIT 1",
-               array(bigintval($id), $GLOBALS['userid']), __FILE__, __LINE__);
+               array(bigintval($urlId), $GLOBALS['userid']), __FILE__, __LINE__);
 }
 // Pay points to the user and remove it from the sender
-function SURFBAR_PAY_POINTS ($id) {
+function SURFBAR_PAY_POINTS ($urlId) {
        // Remove it from the URL owner
        //DEBUG_LOG(__FUNCTION__.":uid=".SURFBAR_GET_USERID().",costs=".SURFBAR_GET_COSTS()."");
        if (SURFBAR_GET_USERID() > 0) {
@@ -613,15 +661,15 @@ function SURFBAR_UPDATE_SALT_STATS () {
        return (SQL_AFFECTEDROWS() == 1);
 }
 // Check if the reload lock is active for given id
-function SURFBAR_CHECK_RELOAD_LOCK ($id) {
-       //DEBUG_LOG(__FUNCTION__.":id={$id}");
+function SURFBAR_CHECK_RELOAD_LOCK ($urlId) {
+       //DEBUG_LOG(__FUNCTION__.":id={$urlId}");
        // Ask the database
        $result = SQL_QUERY_ESC("SELECT COUNT(id) AS cnt
 FROM "._MYSQL_PREFIX."_surfbar_locks
 WHERE userid=%s AND url_id=%s AND (UNIX_TIMESTAMP() - ".SURFBAR_GET_DATA('surf_lock').") < UNIX_TIMESTAMP(last_surfed)
 ORDER BY last_surfed ASC
 LIMIT 1",
-               array($GLOBALS['userid'], bigintval($id)), __FILE__, __LINE__
+               array($GLOBALS['userid'], bigintval($urlId)), __FILE__, __LINE__
        );
 
        // Fetch counter
@@ -718,19 +766,19 @@ function SURFBAR_DETERMINE_WAIT_TIME () {
        return $time;
 }
 // Changes the status of an URL from given to other
-function SURFBAR_CHANGE_STATUS ($id, $prevStatus, $newStatus) {
+function SURFBAR_CHANGE_STATUS ($urlId, $prevStatus, $newStatus) {
        // Get URL data for status comparison
-       $data = SURFBAR_GET_URL_DATA($id);
+       $data = SURFBAR_GET_URL_DATA($urlId);
 
        // Is the status like prevStatus is saying?
-       if ($data[$id]['status'] != $prevStatus) {
+       if ($data[$urlId]['status'] != $prevStatus) {
                // No, then abort here
                return false;
        } // END - if
 
        // Update the status now
        SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_surfbar_urls SET status='%s' WHERE id=%s LIMIT 1",
-               array($newStatus, bigintval($id)), __FILE__, __LINE__);
+               array($newStatus, bigintval($urlId)), __FILE__, __LINE__);
 
        // Was that fine?
        if (SQL_AFFECTEDROWS() != 1) {
@@ -739,19 +787,19 @@ function SURFBAR_CHANGE_STATUS ($id, $prevStatus, $newStatus) {
        } // END - if
 
        // Prepare content for notification routines
-       $data[$id]['uid']         = $data[$id]['userid'];
-       $data[$id]['frametester'] = FRAMETESTER($data[$id]['url']);
-       $data[$id]['reward']      = TRANSLATE_COMMA($data[$id]['reward']);
-       $data[$id]['costs']       = TRANSLATE_COMMA($data[$id]['costs']);
-       $data[$id]['status']      = SURFBAR_TRANSLATE_STATUS($newStatus);
-       $data[$id]['registered']  = MAKE_DATETIME($data[$id]['registered'], "2");
+       $data[$urlId]['uid']         = $data[$urlId]['userid'];
+       $data[$urlId]['frametester'] = FRAMETESTER($data[$urlId]['url']);
+       $data[$urlId]['reward']      = TRANSLATE_COMMA($data[$urlId]['reward']);
+       $data[$urlId]['costs']       = TRANSLATE_COMMA($data[$urlId]['costs']);
+       $data[$urlId]['status']      = SURFBAR_TRANSLATE_STATUS($newStatus);
+       $data[$urlId]['registered']  = MAKE_DATETIME($data[$urlId]['registered'], "2");
        $newStatus = strtolower($newStatus);
 
        // Send admin notification
-       SURFBAR_NOTIFY_ADMIN("url_{$newStatus}", $data[$id]);
+       SURFBAR_NOTIFY_ADMIN("url_{$newStatus}", $data[$urlId]);
 
        // Send user notification
-       SURFBAR_NOTIFY_USER("url_{$newStatus}", $data[$id]);
+       SURFBAR_NOTIFY_USER("url_{$newStatus}", $data[$urlId]);
 
        // All done!
        return true;
@@ -963,31 +1011,9 @@ function SURFBAR_GET_ACTION_ARRAY ($status) {
        // Return result
        return $returnArray;
 }
-// Create list of actions depending on status for the user
-function SURFBAR_MEMBER_ACTIONS ($id, $status) {
-       // Load all actions in an array for given status
-       $actionArray = SURFBAR_GET_ACTION_ARRAY($status);
-
-       // Init HTML code
-       $OUT = "";
-
-       // "Walk" through all actions and create forms
-       foreach ($actionArray as $action) {
-               // Add form for this action
-               $OUT .= sprintf("<form action=\"".URL."/modules.php?module=login&amp;what=surfbar_list\" method=\"post\" style=\"padding-bottom:0px\">
-<input type=\"submit\" name=\"%s\" value=\"{--MEMBER_SURFBAR_ACTION_%s_SUBMIT--}\" />
-</form>",
-                       $action,
-                       strtoupper($action)
-               );
-       } // END - if
-
-       // Return code
-       return $OUT;
-}
 // Determine next id for surfbar or get data for given id, always call this before you call other
 // getters below this function!!!
-function SURFBAR_DETERMINE_NEXT_ID ($id = 0) {
+function SURFBAR_DETERMINE_NEXT_ID ($urlId = 0) {
        global $SURFBAR_CACHE, $_CONFIG;
 
        // Default is no id and no random number
@@ -995,7 +1021,7 @@ function SURFBAR_DETERMINE_NEXT_ID ($id = 0) {
        $randNum = 0;
 
        // Is the ID set?
-       if ($id == 0) {
+       if ($urlId == 0) {
                // Get array with lock ids
                $USE = SURFBAR_GET_LOCK_IDS();
 
@@ -1049,7 +1075,7 @@ LEFT JOIN "._MYSQL_PREFIX."_surfbar_locks AS l
 ON sbu.id=l.url_id
 WHERE sbu.userid != %s AND sbu.status='CONFIRMED' AND sbu.id=%s
 LIMIT 1",
-                       array($GLOBALS['userid'], bigintval($id)), __FILE__, __LINE__
+                       array($GLOBALS['userid'], bigintval($urlId)), __FILE__, __LINE__
                );
        }