]> git.mxchange.org Git - mailer.git/blobdiff - inc/mysql-manager.php
Naming convention applied, new API function introduced:
[mailer.git] / inc / mysql-manager.php
index 6100e642258b06fed0d749c47479a9514254723e..874884fd8809d0e517ff1b928ef92604bf58ceeb 100644 (file)
@@ -125,7 +125,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) {
        }
 
        // Begin the navigation line
-       if ((!isset($GLOBALS['nav_depth'])) && ($return === false)) {
+       if (!isset($GLOBALS['nav_depth'])) {
                // Init nav_depth
                $GLOBALS['nav_depth'] = '0';
 
@@ -147,7 +147,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) {
        if (substr($search, -4, 4) == '.php') {
                // Remove the .php
                $search = substr($search, 0, -4);
-       } // END - i
+       } // END - if
 
        if (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) {
                // Output HTML code
@@ -262,7 +262,7 @@ ORDER BY
                                                $OUT .= '<a name="menu" class="menu_blur" href="{%url=modules.php?module=' . getModule() . '&amp;what=' . $content['sub_what'] . '%}" target="_self">';
                                        } else {
                                                // Not found! - open
-                                               $OUT .= '<em style="cursor:help" class="admin_note" title="{%message,MENU_WHAT_404=' . $content['sub_what'] . '%}">';
+                                               $OUT .= '<em style="cursor:help" class="notice" title="{%message,MENU_WHAT_404=' . $content['sub_what'] . '%}">';
                                        }
 
                                        // Menu title
@@ -371,10 +371,10 @@ function isMember () {
        if ((!isset($GLOBALS['last_online'])) || (!is_array($GLOBALS['last_online']))) $GLOBALS['last_online'] = array();
 
        // is the cache entry there?
-       if (isset($GLOBALS['is_member'])) {
+       if (isset($GLOBALS[__FUNCTION__])) {
                // Then return it
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHED! (' . intval($GLOBALS['is_member']) . ')');
-               return $GLOBALS['is_member'];
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHED! (' . intval($GLOBALS[__FUNCTION__]) . ')');
+               return $GLOBALS[__FUNCTION__];
        } elseif ((!isSessionVariableSet('userid')) || (!isSessionVariableSet('u_hash'))) {
                // No member
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'No member set in cookie/session.');
@@ -424,7 +424,7 @@ function isMember () {
        }
 
        // Cache status
-       $GLOBALS['is_member'] = $ret;
+       $GLOBALS[__FUNCTION__] = $ret;
 
        // Return status
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . intval($ret));
@@ -442,7 +442,7 @@ function fetchUserData ($userid, $column = 'userid') {
                setCurrentUserId($userid);
 
                // Don't look for invalid userids...
-               if ($userid < 1) {
+               if (!isValidUserId($userid)) {
                        // Invalid, so abort here
                        debug_report_bug(__FUNCTION__, __LINE__, 'User id ' . $userid . ' is invalid.');
                } elseif (isUserDataValid()) {
@@ -540,9 +540,9 @@ function isAdmin () {
        } // END - if
 
        // Do we have cache?
-       if (!isset($GLOBALS['is_admin'][$adminId])) {
+       if (!isset($GLOBALS[__FUNCTION__][$adminId])) {
                // Init it with failed
-               $GLOBALS['is_admin'][$adminId] = false;
+               $GLOBALS[__FUNCTION__][$adminId] = false;
 
                // Search in array for entry
                if (isset($GLOBALS['admin_hash'])) {
@@ -568,12 +568,12 @@ function isAdmin () {
                if (!empty($valPass)) {
                        // Check if password is valid
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie));
-                       $GLOBALS['is_admin'][$adminId] = (($GLOBALS['admin_hash'] == $passCookie) || ((strlen($GLOBALS['admin_hash']) == 32) && ($GLOBALS['admin_hash'] == md5($passCookie))) || (($GLOBALS['admin_hash'] == '*FAILED*') && (!isExtensionActive('cache'))));
+                       $GLOBALS[__FUNCTION__][$adminId] = (($GLOBALS['admin_hash'] == $passCookie) || ((strlen($GLOBALS['admin_hash']) == 32) && ($GLOBALS['admin_hash'] == md5($passCookie))) || (($GLOBALS['admin_hash'] == '*FAILED*') && (!isExtensionActive('cache'))));
                } // END - if
        } // END - if
 
        // Return result of comparision
-       return $GLOBALS['is_admin'][$adminId];
+       return $GLOBALS[__FUNCTION__][$adminId];
 }
 
 // Generates a list of "max receiveable emails per day"
@@ -716,7 +716,7 @@ function getActionFromModuleWhat ($module, $what) {
        // Init status
        $data['action'] = '';
 
-       //* DEBUG: */ debugOutput(__LINE__.'='.$module.'/'.$what.'/'.getAction().'=');
+       //* DEBUG: */ debugOutput(__LINE__ . '=' . $module . '/'.$what . '/' . getAction() . '=');
        if (!isExtensionInstalledAndNewer('sql_patches', '0.0.5')) {
                // sql_patches is missing so choose depending on mode
                if (isWhatSet()) {
@@ -863,7 +863,7 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = '', $
        $ret = 'failed';
 
        // Is the userid valid?
-       if ($userid > 0) {
+       if (isValidUserId($userid)) {
                // Remove entry from array
                unset($receivers[$key]);
 
@@ -988,7 +988,7 @@ function getReferalLevelPercents ($level) {
  * Dynamic referal system, can also send mails!
  *
  * subject     = Subject line, write in lower-case letters and underscore is allowed
- * userid         = Referal id wich should receive...
+ * userid      = Referal id wich should receive...
  * points      = ... xxx points
  * sendNotify  = shall I send the referal an email or not?
  * refid       = inc/modules/guest/what-confirm.php need this
@@ -1019,15 +1019,20 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify
                //* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>): Referal level increased. DEPTH='.$GLOBALS['ref_level']);
        }
 
-       // Default is 'normal' points
-       $data = 'points';
-
-       // Which points, locked or normal?
-       if ($locked === true) $data = 'locked_points';
-
        // Check user account
        //* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):userid='.$userid.',points='.$points);
        if (fetchUserData($userid)) {
+               // Determine wether the user has some mails to click before he/she gets the points
+               $locked = ifUserPointsLocked($userid);
+
+               // Default is 'normal' points
+               $data = 'points';
+
+               // Which points, locked or normal?
+               if ($locked === true) {
+                       $data = 'locked_points';
+               } // END - if
+
                // This is the user and his ref
                $GLOBALS['cache_array']['add_userid'][getUserData('refid')] = $userid;
 
@@ -1061,10 +1066,6 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify
                                //* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):data='.$data.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$add_mode.' - INSERTED! ('.SQL_AFFECTEDROWS().')');
                        } // END - if
 
-                       // Determine wether the user has some mails to click before he/she gets the points
-                       $locked = false;
-                       if ((getUserData('ref_payout') > 0) && (!isDirectPaymentAllowed())) $locked = true;
-
                        // Prepare data for the filter
                        $filterData = array(
                                'subject'  => $subject,
@@ -1094,10 +1095,10 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify
 
                                // Send email
                                sendEmail($userid, '{--THANX_REFERAL_ONE_SUBJECT--}', $message);
-                       } elseif (($sendNotify === true) && (getUserData('refid') == '0') && ($locked === false) && ($add_mode == 'direct')) {
+                       } elseif (($sendNotify === true) && (!isValidUserId(getUserData('refid'))) && ($locked === false) && ($add_mode == 'direct')) {
                                // Prepare content
                                $content = array(
-                                       'text'   => '{--REASON_DIRECT_PAYMENT--}',
+                                       'reason' => '{--REASON_DIRECT_PAYMENT--}',
                                        'points' => $ref_points
                                );
 
@@ -1106,7 +1107,10 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify
 
                                // And sent it away
                                sendEmail($userid, '{--DIRECT_PAYMENT_SUBJECT--}', $message);
-                               if (!isGetRequestParameterSet('mid')) loadTemplate('admin_settings_saved', false, '{--ADMIN_POINTS_ADDED--}');
+                               if (!isGetRequestParameterSet('mid')) {
+                                       // Output message to admin
+                                       loadTemplate('admin_settings_saved', false, '{--ADMIN_POINTS_ADDED--}');
+                               } // END - if
                        }
 
                        // Maybe there's another ref?
@@ -1376,11 +1380,11 @@ function getAdminDefaultAcl ($adminId) {
 }
 
 // Generates an option list from various parameters
-function generateOptionList ($table, $id, $name, $default='', $special='', $where='', $disabled=array()) {
+function generateOptionList ($table, $id, $name, $default = '', $special = '', $where = '', $disabled = array(), $callback = '') {
        $ret = '';
        if ($table == '/ARRAY/') {
                // Selection from array
-               if ((is_array($id)) && (is_array($name)) && (count($id)) == (count($name))) {
+               if ((is_array($id)) && (is_array($name)) && ((count($id)) == (count($name)) || (!empty($callback)))) {
                        // Both are arrays
                        foreach ($id as $idx => $value) {
                                $ret .= '<option value="' . $value . '"';
@@ -1391,11 +1395,19 @@ function generateOptionList ($table, $id, $name, $default='', $special='', $wher
                                        // Disabled!
                                        $ret .= ' disabled="disabled"';
                                }
+
+                               // Is the call-back function set?
+                               if (!empty($callback)) {
+                                       // Call it
+                                       $name[$idx] = call_user_func_array($callback, array($id[$idx]));
+                               } // END - if
+
+                               // Finish option tag
                                $ret .= '>' . $name[$idx] . '</option>';
                        } // END - foreach
                } else {
                        // Problem in request
-                       debug_report_bug(__FUNCTION__, __LINE__, 'Not all are arrays: id[' . count($id) . ']=' . gettype($id) . ',name[' . count($name) . ']=' . gettype($name));
+                       debug_report_bug(__FUNCTION__, __LINE__, 'Not all are arrays: id[' . count($id) . ']=' . gettype($id) . ',name[' . count($name) . ']=' . gettype($name) . ',callback=' . $callback);
                }
        } else {
                // Data from database
@@ -1425,7 +1437,17 @@ function generateOptionList ($table, $id, $name, $default='', $special='', $wher
                                        // Disabled!
                                        $ret .= ' disabled="disabled"';
                                }
+
+                               // Add it, if set
                                if (!empty($add)) $add = ' ('.$add.')';
+
+                               // Is the call-back function set?
+                               if (!empty($callback)) {
+                                       // Call it
+                                       $title = call_user_func_array($callback, array($title));
+                               } // END - if
+
+                               // Finish option list
                                $ret .= '>' . $title . $add . '</option>';
                        } // END - while
                } else {
@@ -1650,7 +1672,7 @@ function generateCategoryOptionsList ($mode) {
                } // END - foreach
        } else {
                // No cateogries are defined yet
-               $OUT = '<option class="member_failed">{--MEMBER_NO_CATEGORIES--}</option>';
+               $OUT = '<option class="notice">{--MEMBER_NO_CATEGORIES--}</option>';
        }
 
        // Return HTML code