]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/admin/admin-inc.php
Generalized more 'builder' functions, added XML template for editing user sub ids
[mailer.git] / inc / modules / admin / admin-inc.php
index f2cae6f2983c341266b17f005086d3d1a8eb93c5..b580547dd3fe7d5132d4be92d97389428a628f40 100644 (file)
@@ -196,7 +196,7 @@ LIMIT 1",
                        $what
                ), __FUNCTION__, __LINE__);
 
-       // Do we have an entry?
+       // Is there an entry?
        if (SQL_NUMROWS($result_action) == 1) {
                // Is valid but does the inlcude file exists?
                $inc = sprintf("inc/modules/admin/action-%s.php", $action);
@@ -227,7 +227,7 @@ LIMIT 1",
  * combination (only one is allowed to be null!).
  */
 function isAdminAllowedAccessMenu ($action, $what = NULL) {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$action][$what])) {
                // ACL is always 'allow' when no ext-admins is installed
                // @TODO This can be rewritten into a filter
@@ -261,7 +261,7 @@ ORDER BY
        `sort` ASC,
        `id` DESC", __FUNCTION__, __LINE__);
 
-       // Do we have entries?
+       // Are there entries?
        if (!SQL_HASZERONUMS($result_main)) {
                $OUT .= '<ul class="admin_menu_main">';
 
@@ -350,12 +350,12 @@ ORDER BY
        // Start li-tag for sub menu content
        $OUT .= '<li class="admin_menu_sub" id="action_menu_' . $mainContent['main_action'] . '"' . addStyleMenuContent('admin', $mainContent['main_action'], $action) . '>';
 
-       // Do we have entries?
+       // Are there entries?
        if (ifAdminMenuHasEntries($mainContent['main_action'])) {
                // Sub menu has been called
                $SUB = true;
 
-               // Do we have entries?
+               // Are there entries?
                if (!SQL_HASZERONUMS($result_what)) {
                        // Start HTML code
                        $OUT .= '<ul class="admin_menu_sub">';
@@ -756,7 +756,7 @@ function adminGetMenuMode () {
                $result = SQL_QUERY_ESC("SELECT `la_mode` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
                        array($adminId), __FUNCTION__, __LINE__);
 
-               // Do we have an entry?
+               // Is there an entry?
                if (SQL_NUMROWS($result) == 1) {
                        // Load data
                        list($adminMode) = SQL_FETCHROW($result);
@@ -876,105 +876,8 @@ function sendAdminBuildMails ($mode, $tableName, $content, $id, $subjectPart = '
 
 // Build a special template list
 function adminListBuilder ($listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId = array('userid')) {
-       // $tableName and $idColumn must bove be arrays!
-       if ((!is_array($tableName)) || (count($tableName) != 1)) {
-               // $tableName is no array
-               reportBug(__FUNCTION__, __LINE__, 'tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn);
-       } elseif (!is_array($idColumn)) {
-               // $idColumn is no array
-               reportBug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array: userIdColumn=' . $userIdColumn);
-       } elseif ((!is_array($userIdColumn)) || (count($userIdColumn) != 1)) {
-               // $tableName is no array
-               reportBug(__FUNCTION__, __LINE__, 'userIdColumn[]=' . gettype($userIdColumn) . '!=array: userIdColumn=' . $userIdColumn);
-       }
-
-       // Init row output
-       $OUT = '';
-
-       // "Walk" through all entries
-       //* DEBUG: */ reportBug(__FUNCTION__, __LINE__, 'listType=<pre>'.print_r($listType,true).'</pre>,tableName<pre>'.print_r($tableName,true).'</pre>,columns=<pre>'.print_r($columns,true).'</pre>,filterFunctions=<pre>'.print_r($filterFunctions,true).'</pre>,extraValues=<pre>'.print_r($extraValues,true).'</pre>,idColumn=<pre>'.print_r($idColumn,true).'</pre>,userIdColumn=<pre>'.print_r($userIdColumn,true).'</pre>,rawUserId=<pre>'.print_r($rawUserId,true).'</pre>');
-       foreach (postRequestElement($idColumn[0]) as $id => $selected) {
-               // Secure id number
-               $id = bigintval($id);
-
-               // Get result from a given column array and table name
-               $result = SQL_RESULT_FROM_ARRAY($tableName[0], $columns, $idColumn[0], $id, __FUNCTION__, __LINE__);
-
-               // Is there one entry?
-               if (SQL_NUMROWS($result) == 1) {
-                       // Load all data
-                       $content = SQL_FETCHARRAY($result);
-
-                       // Filter all data
-                       foreach ($content as $key => $value) {
-                               // Search index
-                               $idx = searchXmlArray($key, $columns, 'column');
-
-                               // Skip any missing entries
-                               if ($idx === false) {
-                                       // Skip this one
-                                       //* DEBUG: */ reportBug(__FUNCTION__, __LINE__, 'key=' . $key . ' - SKIPPED!');
-                                       continue;
-                               } // END - if
-
-                               // Do we have a userid?
-                               //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',userIdColumn=' . $userIdColumn[0]);
-                               if ($key == $userIdColumn[0]) {
-                                       // Add it again as raw id
-                                       //* DEBUG: */ reportBug(__FUNCTION__, __LINE__, 'key=' . $key . ',userIdColumn=' . $userIdColumn[0]);
-                                       $content[$userIdColumn[0]] = convertZeroToNull($value);
-                                       $content[$userIdColumn[0] . '_raw'] = $content[$userIdColumn[0]];
-                               } // END - if
-
-                               // If the key matches the idColumn variable, we need to temporary remember it
-                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',idColumn=' . $idColumn[0] . ',value=' . $value);
-                               if ($key == $idColumn[0]) {
-                                       /*
-                                        * Found, so remember it securely (to make sure only id
-                                        * numbers can pass, don't use alpha-numerical values!)
-                                        */
-                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - set as admin_list_builder_id_value!');
-                                       $GLOBALS['admin_list_builder_id_value'] = bigintval($value);
-                               } // END - if
-
-                               // Do we have a call-back function and extra-value pair?
-                               if ((isset($filterFunctions[$idx])) && (isset($extraValues[$idx]))) {
-                                       // Handle the call in external function
-                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',fucntion=' . $filterFunctions[$idx] . ',value=' . $value);
-                                       $content[$key] = handleExtraValues(
-                                               $filterFunctions[$idx],
-                                               $value,
-                                               $extraValues[$idx]
-                                       );
-                               } elseif ((isset($columns[$idx]['name'])) && (isset($filterFunctions[$columns[$idx]['name']])) && (isset($extraValues[$columns[$idx]['name']]))) {
-                                       // Handle the call in external function
-                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',fucntion=' . $filterFunctions[$columns[$idx]['name']] . ',value=' . $value);
-                                       $content[$key] = handleExtraValues(
-                                               $filterFunctions[$columns[$idx]['name']],
-                                               $value,
-                                               $extraValues[$columns[$idx]['name']]
-                                       );
-                               }
-                       } // END - foreach
-
-                       // Then list it
-                       $OUT .= loadTemplate(sprintf("admin_%s_%s_row",
-                               $listType,
-                               $tableName[0]
-                               ), true, $content
-                       );
-               } // END - if
-
-               // Free the result
-               SQL_FREERESULT($result);
-       } // END - foreach
-
-       // Load master template
-       loadTemplate(sprintf("admin_%s_%s",
-               $listType,
-               $tableName[0]
-               ), false, $OUT
-       );
+       // Call inner (general) function
+       doGenericListBuilder('admin', $listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId);
 }
 
 // Change status of "build" list
@@ -1158,106 +1061,8 @@ function adminEditEntriesConfirm ($tableName, $columns = array(), $filterFunctio
 
        // Shall we change here or list for editing?
        if ($editNow[0] === true) {
-               // Change them all
-               $affected = '0';
-               foreach (postRequestElement($idColumn[0]) as $id => $sel) {
-                       // Prepare content array (new values)
-                       $content = array();
-
-                       // Prepare SQL for this row
-                       $sql = sprintf("UPDATE `{?_MYSQL_PREFIX?}_%s` SET",
-                               SQL_ESCAPE($tableName[0])
-                       );
-
-                       // "Walk" through all entries
-                       foreach (postRequestArray() as $key => $entries) {
-                               // Skip raw userid which is always invalid
-                               if ($key == $rawUserId[0]) {
-                                       // Continue with next field
-                                       //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',idColumn[0]=' . $idColumn[0] . ',rawUserId=' . $rawUserId[0]);
-                                       continue;
-                               } // END - if
-
-                               // Debug message
-                               //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',idColumn[0]=' . $idColumn[0] . ',entries=<pre>'.print_r($entries,true).'</pre>');
-
-                               // Is entries an array?
-                               if (($key != $idColumn[0]) && (is_array($entries)) && (isset($entries[$id]))) {
-                                       // Add this entry to content
-                                       $content[$key] = $entries[$id];
-
-                                       // Send data through the filter function if found
-                                       if ($key == $userIdColumn[0]) {
-                                               // Is the userid, we have to process it with convertZeroToNull()
-                                               $entries[$id] = convertZeroToNull($entries[$id]);
-                                       } elseif ((isset($filterFunctions[$key])) && (isset($extraValues[$key]))) {
-                                               // Filter function set!
-                                               $entries[$id] = handleExtraValues($filterFunctions[$key], $entries[$id], $extraValues[$key]);
-                                       }
-
-                                       // Is the value NULL?
-                                       if ($entries[$id] == 'NULL') {
-                                               // Add it directly
-                                               $sql .= sprintf(' `%s`=NULL,',
-                                                       SQL_ESCAPE($key)
-                                               );
-                                       } else {
-                                               // Else add the value covered
-                                               $sql .= sprintf(" `%s`='%s',",
-                                                       SQL_ESCAPE($key),
-                                                       SQL_ESCAPE($entries[$id])
-                                               );
-                                       }
-                               } elseif (($key != $idColumn[0]) && (!is_array($entries))) {
-                                       // Add normal entries as well!
-                                       $content[$key] =  $entries;
-                               }
-                       } // END - foreach
-
-                       // Finish SQL command
-                       $sql = substr($sql, 0, -1) . " WHERE `" . SQL_ESCAPE($idColumn[0]) . "`=" . bigintval($id) . " LIMIT 1";
-
-                       // Run this query
-                       SQL_QUERY($sql, __FUNCTION__, __LINE__);
-
-                       // Add affected rows
-                       $affected += SQL_AFFECTEDROWS();
-
-                       // Load all data from that id
-                       $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`=%s LIMIT 1",
-                               array(
-                                       $tableName[0],
-                                       $idColumn[0],
-                                       $id
-                               ), __FUNCTION__, __LINE__);
-
-                       // Fetch the data and merge it into $content
-                       $content = merge_array($content, SQL_FETCHARRAY($result));
-
-                       // Free the result
-                       SQL_FREERESULT($result);
-
-                       // Send "build mails" out
-                       sendAdminBuildMails('edit', $tableName, $content, $id, '', $userIdColumn);
-               } // END - foreach
-
-               // Delete cache?
-               if ((count($cacheFiles) > 0) && (!empty($cacheFiles[0]))) {
-                       // Delete cache file(s)
-                       foreach ($cacheFiles as $cacheF) {
-                               // Skip any empty entries
-                               if (empty($cache)) {
-                                       // This may cause trouble in loadCacheFile()
-                                       continue;
-                               } // END - if
-
-                               // Is the cache file loadable?
-                               if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
-                                       // Then remove it
-                                       $GLOBALS['cache_instance']->removeCacheFile();
-                               } // END - if
-                       } // END - foreach
-               } // END - if
+               // Call generic change method
+               $affected = doGenericEditEntriesConfirm($tableName, $columns, $filterFunctions, $extraValues, $timeColumns, $editNow, $idColumn, $userIdColumn, $rawUserId, $cacheFiles);
 
                // Was this fine?
                if ($affected == countPostSelection($idColumn[0])) {
@@ -1610,7 +1415,7 @@ function generateUnconfirmedAdminLink ($id, $unconfirmed, $type = 'bid') {
        // Init output
        $OUT = $unconfirmed;
 
-       // Do we have unconfirmed mails?
+       // Is there unconfirmed mails?
        if ($unconfirmed > 0) {
                // Add link to list_unconfirmed what-file
                $OUT = '<a href="{%url=modules.php?module=admin&amp;what=list_unconfirmed&amp;' . $type . '=' . $id . '%}">{%pipe,translateComma=' . $unconfirmed . '%}</a>';