Heacy rewrite/cleanup:
[mailer.git] / inc / mysql-manager.php
index bacb22cb67ec91d55483936337025f6fd7a36f54..f6f55610d44d93cc4c46f339f61176a49dc25025 100644 (file)
@@ -580,7 +580,7 @@ function isAdmin () {
        } // END - if
 
        // No admin in installation phase!
-       if ((isInstallationPhase()) || (!isAdminRegistered())) {
+       if ((isInstaller()) || (!isAdminRegistered())) {
                $GLOBALS[__FUNCTION__] = FALSE;
                return FALSE;
        } // END - if
@@ -1837,7 +1837,12 @@ LIMIT %s",
 function reduceRecipientReceivedMails ($column, $id, $count) {
        // Search for mail in database
        $result = sqlQueryEscaped("SELECT * FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s ORDER BY `userid` ASC LIMIT %s",
-               array($column, bigintval($id), $count), __FUNCTION__, __LINE__);
+               array(
+                       $column,
+                       bigintval($id),
+                       $count
+               ), __FUNCTION__, __LINE__
+       );
 
        // Are there entries?
        if (!ifSqlHasZeroNums($result)) {
@@ -1849,10 +1854,10 @@ function reduceRecipientReceivedMails ($column, $id, $count) {
 
                        // We must now look if he has already confirmed this mail, so might sound double, but it may resolve problems
                        // @TODO Rewrite this to a filter
-                       if ((isset($data['stats_id'])) && ($data['stats_id'] > 0)) {
+                       if ((isset($data['stats_id'])) && (isValidId($data['stats_id']))) {
                                // User email
                                $num = countSumTotalData($data['userid'], 'user_stats_data', 'id', 'userid', TRUE, sprintf(" AND `stats_type`='mailid' AND `stats_data`=%s", bigintval($data['stats_id'])));
-                       } elseif ((isset($data['bonus_id'])) && ($data['bonus_id'] > 0)) {
+                       } elseif ((isset($data['bonus_id'])) && (isValidId($data['bonus_id']))) {
                                // Bonus mail
                                $num = countSumTotalData($data['userid'], 'user_stats_data', 'id', 'userid', TRUE, sprintf(" AND `stats_type`='bonusid' AND `stats_data`=%s", bigintval($data['bonus_id'])));
                        }
@@ -1863,7 +1868,7 @@ function reduceRecipientReceivedMails ($column, $id, $count) {
                        } // END - if
                } // END - while
 
-               if (count($userids) > 0) {
+               if (isFilledArray($userids)) {
                        // Now update all user accounts
                        sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `emails_received`=`emails_received`-1 WHERE `userid` IN (%s) LIMIT %s",
                                array(
@@ -1936,7 +1941,7 @@ function doGenericJoinedListEntries ($tableTemplate, $rowTemplate, $noEntryMessa
        if ((!is_array($tableName)) || (count($tableName) != 1)) {
                // No tableName specified
                reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array,tableTemplate=' . $tableTemplate . ',rowTemplate=' . $rowTemplate);
-       } elseif (count($columns) == 0) {
+       } elseif (!isFilledArray($columns)) {
                // No columns specified
                reportBug(__FUNCTION__, __LINE__, 'columns is not given. Please fix your XML,tableTemplate=' . $tableTemplate . ',rowTemplate=' . $rowTemplate . ',tableName[0]=' . $tableName[0]);
        }
@@ -1969,7 +1974,7 @@ function doGenericListEntries ($tableTemplate, $rowTemplate, $noEntryMessageId,
        if ((!is_array($tableName)) || (count($tableName) != 1)) {
                // No tableName specified
                reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array,tableTemplate=' . $tableTemplate . ',rowTemplate=' . $rowTemplate);
-       } elseif (count($columns) == 0) {
+       } elseif (!isFilledArray($columns)) {
                // No columns specified
                reportBug(__FUNCTION__, __LINE__, 'columns is not given. Please fix your XML,tableTemplate=' . $tableTemplate . ',rowTemplate=' . $rowTemplate . ',tableName[0]=' . $tableName[0]);
        }
@@ -2025,7 +2030,7 @@ function doListEntries ($sql, $tableTemplate, $noEntryMessageId, $rowTemplate, $
                } // END - while
 
                // Is at least one entry set in content?
-               if ((is_array($content)) && (count($content) > 0)) {
+               if (isFilledArray($content)) {
                        // Then add generic 'rows' element
                        $content['rows'] = $OUT;
                } else {
@@ -2051,7 +2056,7 @@ function doGenericAddEntries ($tableName, $columns = array(), $filterFunctions =
        if ((!is_array($tableName)) || (count($tableName) != 1)) {
                // No tableName specified
                reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn);
-       } elseif (count($columns) == 0) {
+       } elseif (!isFilledArray($columns)) {
                // No columns specified
                reportBug(__FUNCTION__, __LINE__, 'columns is not given. Please fix your XML.');
        }
@@ -2064,7 +2069,7 @@ function doGenericAddEntries ($tableName, $columns = array(), $filterFunctions =
        $GLOBALS['__XML_PARSE_RESULT'] = TRUE;
 
        // Is there "time columns"?
-       if (count($timeColumns) > 0) {
+       if (isFilledArray($timeColumns)) {
                // Then "walk" through all entries
                foreach ($timeColumns as $column) {
                        // Convert all (possible) selections
@@ -2088,9 +2093,18 @@ function doGenericAddEntries ($tableName, $columns = array(), $filterFunctions =
                // Debug message
                //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',columnName[' . gettype($columnName) . ']=' . $columnName . ',filterFunctions=' . $filterFunctions[$key] . ',extraValues=' . intval(isset($extraValues[$key])) . ',extraValuesName=' . intval(isset($extraValues[$columnName . '_list'])));
 
+               // Get value back (no array supported)
+               $value = postRequestElement($columnName);
+
+               // Is this an array and element 0 is set?
+               if ((is_array($value)) && (isset($value[0]))) {
+                       // Then only take this
+                       $value = $value[0];
+               } // END - if
+
                // Copy entry securely to the final arrays
                $sqlColumns[$key] = sqlEscapeString($columnName);
-               $sqlValues[$key]  = sqlEscapeString(postRequestElement($columnName));
+               $sqlValues[$key]  = sqlEscapeString($value);
 
                // Search for it
                $search = key(search_array($columns, 'column', $columnName));
@@ -2154,7 +2168,7 @@ function doGenericAddEntries ($tableName, $columns = array(), $filterFunctions =
 // Edit rows by given id numbers
 function doGenericEditEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $editNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array(), $subject = '') {
        // Is there "time columns"?
-       if (count($timeColumns) > 0) {
+       if (isFilledArray($timeColumns)) {
                // Then "walk" through all entries
                foreach ($timeColumns as $column) {
                        // Convert all (possible) selections
@@ -2274,7 +2288,7 @@ function doGenericEditEntriesConfirm ($tableName, $columns = array(), $filterFun
        } // END - foreach
 
        // Delete cache?
-       if ((count($cacheFiles) > 0) && (!empty($cacheFiles[0]))) {
+       if ((isFilledArray($cacheFiles)) && (!empty($cacheFiles[0]))) {
                // Delete cache file(s)
                foreach ($cacheFiles as $cache) {
                        // Skip any empty entries
@@ -2436,7 +2450,7 @@ function doGenericListBuilder ($prefix, $listType, $tableName, $columns, $filter
                        } // END - foreach
 
                        // Then list it
-                       $OUT .= loadTemplate(sprintf("%s_%s_%s_row",
+                       $OUT .= loadTemplate(sprintf('%s_%s_%s_row',
                                $prefix,
                                $listType,
                                $tableName[0]
@@ -2449,7 +2463,7 @@ function doGenericListBuilder ($prefix, $listType, $tableName, $columns, $filter
        } // END - foreach
 
        // Is there an entry in $content?
-       if ((is_array($content)) && (count($content) > 0)) {
+       if (isFilledArray($content)) {
                // Use generic 'rows'
                $content['rows'] = $OUT;
        } else {
@@ -2459,7 +2473,7 @@ function doGenericListBuilder ($prefix, $listType, $tableName, $columns, $filter
 
        // Load master template
        loadTemplate(
-               sprintf("%s_%s_%s",
+               sprintf('%s_%s_%s',
                        $prefix,
                        $listType,
                        $tableName[0]
@@ -2480,7 +2494,7 @@ function addKeyValueSql ($key, $value) {
                );
        } elseif ((is_double($value)) || (is_float($value)) || (is_int($value))) {
                // Is a number, so addd it directly
-               $sql .= sprintf(" `%s`=%s,",
+               $sql .= sprintf(' `%s`=%s,',
                        sqlEscapeString($key),
                        $value
                );