From 538baf17dfa6ab4fd725f48d9970801d654c089f Mon Sep 17 00:00:00 2001 From: quix0r Date: Sun, 7 Oct 2012 20:46:28 +0000 Subject: [PATCH] Generalized more 'builder' functions, added XML template for editing user sub ids --- inc/filter-functions.php | 4 + inc/filters.php | 24 ++ inc/functions.php | 89 ++++++- inc/language/de.php | 2 + inc/modules/admin/admin-inc.php | 203 +-------------- inc/modules/member/what-subids.php | 12 +- inc/mysql-manager.php | 234 ++++++++++++++++-- .../member/member_list_user_subids_row.tpl | 2 +- .../member/member_edit_show_user_subid.xml | 111 +++++++++ 9 files changed, 447 insertions(+), 234 deletions(-) create mode 100644 templates/xml/member/member_edit_show_user_subid.xml diff --git a/inc/filter-functions.php b/inc/filter-functions.php index 66d04ec8bb..e72170c6e0 100644 --- a/inc/filter-functions.php +++ b/inc/filter-functions.php @@ -195,6 +195,10 @@ ORDER BY // Admin mail links registerFilter(__FUNCTION__, __LINE__, 'generate_admin_mail_links', 'GENERATE_POOL_MAIL_LINKS'); + + // Build mails + registerFilter(__FUNCTION__, __LINE__, 'send_build_mail', 'SEND_ADMIN_BUILD_MAIL'); + registerFilter(__FUNCTION__, __LINE__, 'send_build_mail', 'SEND_MEMBER_BUILD_MAIL'); } // "Registers" a new filter function diff --git a/inc/filters.php b/inc/filters.php index bd3d3fabbc..f5b846c5b9 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -1233,5 +1233,29 @@ function FILTER_INIT_SESSION ($filterData) { return $filterData; } +// Filter for sending "build mail" to admin +function FILTER_SEND_ADMIN_BUILD_MAIL ($filterData) { + // Is the module 'admin'? + if (getModule() == 'admin') { + // Okay, then call the proper function + call_user_func_array('sendAdminBuildMails', $filterData); + } // END - if + + // Return data + return $filterData; +} + +// Filter for sending "build mail" to member +function FILTER_SEND_MEMBER_BUILD_MAIL ($filterData) { + // Is the module 'login'? + if (getModule() == 'login') { + // Okay, then call the proper function + call_user_func_array('sendMemberBuildMails', $filterData); + } // END - if + + // Return data + return $filterData; +} + // [EOF] ?> diff --git a/inc/functions.php b/inc/functions.php index 9305df0bc2..47e600cbe8 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2282,6 +2282,79 @@ function removeDoubleDotFromSubject ($subject) { return $subject; } +// Adds a given entry to the database +function memberAddEntries ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $columnIndex = NULL) { + // Is it a member? + if (!isMember()) { + // Then abort here + return false; + } // END - if + + // Set POST data generic userid + setPostRequestElement('userid', getMemberId()); + + // Call inner function + doGenericAddEntries($tableName, $columns, $filterFunctions, $extraValues, $timeColumns, $columnIndex); + + // Entry has been added? + if ((!SQL_HASZEROAFFECTED()) && ($GLOBALS['__XML_PARSE_RESULT'] === true)) { + // Display success message + displayMessage('{--MEMBER_ENTRY_ADDED--}'); + } else { + // Display failed message + displayMessage('{--MEMBER_ENTRY_NOT_ADDED--}'); + } +} + +// Edit rows by given id numbers +function memberEditEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $editNow = array(false), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array()) { + // $tableName must be an array + 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 (!is_array($idColumn)) { + // $idColumn is no array + reportBug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array: userIdColumn=' . $userIdColumn); + } elseif (!is_array($userIdColumn)) { + // $userIdColumn is no array + reportBug(__FUNCTION__, __LINE__, 'userIdColumn[]=' . gettype($userIdColumn) . '!=array: userIdColumn=' . $userIdColumn); + } elseif (!is_array($editNow)) { + // $editNow is no array + reportBug(__FUNCTION__, __LINE__, 'editNow[]=' . gettype($editNow) . '!=array: userIdColumn=' . $userIdColumn); + } // END - if + + // Shall we change here or list for editing? + if ($editNow[0] === true) { + // Call generic change method + $affected = doGenericEditEntriesConfirm($tableName, $columns, $filterFunctions, $extraValues, $timeColumns, $editNow, $idColumn, $userIdColumn, $rawUserId, $cacheFiles); + + // Was this fine? + if ($affected == countPostSelection($idColumn[0])) { + // All deleted + displayMessage('{--MEMBER_ALL_ENTRIES_EDITED--}'); + } else { + // Some are still there :( + displayMessage(sprintf(getMessage('MEMBER_SOME_ENTRIES_NOT_EDITED'), $affected, countPostSelection($idColumn[0]))); + } + } else { + // List for editing + memberListBuilder('edit', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn); + } +} + +// Build a special template list +function memberListBuilder ($listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId = array('userid')) { + // Do this only for logged in member + assert(isMember()); + + // Call inner (general) function + doGenericListBuilder('member', $listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId); +} + +// ---------------------------------------------------------------------------- +// "Translatation" functions for points_data table +// ---------------------------------------------------------------------------- + // Translates generically some data into a target string function translateGeneric ($messagePrefix, $data) { // Is the method null or empty? @@ -2309,16 +2382,6 @@ function translateGeneric ($messagePrefix, $data) { return $return; } -// Translates task type to a human-readable version -function translateTaskType ($taskType) { - // Return it - return translateGeneric('ADMIN_TASK_TYPE', $taskType); -} - -// ---------------------------------------------------------------------------- -// "Translatation" functions for points_data table -// ---------------------------------------------------------------------------- - // Translates points subject to human-readable function translatePointsSubject ($subject) { // Remove any :x @@ -2358,6 +2421,12 @@ function translatePointsNotifyRecipient ($notifyRecipient) { return translateGeneric('POINTS_NOTIFY_RECIPIENT', $notifyRecipient); } +// Translates task type to a human-readable version +function translateTaskType ($taskType) { + // Return it + return translateGeneric('ADMIN_TASK_TYPE', $taskType); +} + //----------------------------------------------------------------------------- // Automatically re-created functions, all taken from user comments on www.php.net //----------------------------------------------------------------------------- diff --git a/inc/language/de.php b/inc/language/de.php index e167425687..928266ce50 100644 --- a/inc/language/de.php +++ b/inc/language/de.php @@ -992,6 +992,8 @@ addMessages(array( 'ADMIN_SOME_ENTRIES_NOT_DELETED' => "Es wurden %s von %s ausgewählten Einträge gelöscht.", 'ADMIN_ALL_ENTRIES_EDITED' => "Alle ausgewählten Einträge sind geändert.", 'ADMIN_SOME_ENTRIES_NOT_EDITED' => "Es wurden %s von %s ausgewählten Einträge geändert.", + 'MEMBER_ALL_ENTRIES_EDITED' => "Alle Ihre Änderungen wurden gespeichert.", + 'MEMBER_SOME_ENTRIES_NOT_EDITED' => "Es wurden %s von %s ausgewählten Einträge geändert. Wenn Sie keine neuen Werte eingegeben haben, ist diese Meldung normal.", 'USER_NOT_REGISTERED' => "Anmeldung hat nicht geklappt! :-( Ist unten eine Fehlermeldung eingeblendet? Bitte beim Support melden.", 'ADMIN_SELECTION_BOX_TITLE' => "Mitglied für Aktion auswählen", 'ADMIN_DO_ACTION' => "Aktion ausführen", diff --git a/inc/modules/admin/admin-inc.php b/inc/modules/admin/admin-inc.php index 38a180263d..b580547dd3 100644 --- a/inc/modules/admin/admin-inc.php +++ b/inc/modules/admin/admin-inc.php @@ -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=
'.print_r($listType,true).'
,tableName
'.print_r($tableName,true).'
,columns=
'.print_r($columns,true).'
,filterFunctions=
'.print_r($filterFunctions,true).'
,extraValues=
'.print_r($extraValues,true).'
,idColumn=
'.print_r($idColumn,true).'
,userIdColumn=
'.print_r($userIdColumn,true).'
,rawUserId=
'.print_r($rawUserId,true).'
'); - 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 - - // Is there 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 - - // Is there 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=
'.print_r($entries,true).'
'); - - // 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])) { diff --git a/inc/modules/member/what-subids.php b/inc/modules/member/what-subids.php index 5704491bff..335e90d457 100644 --- a/inc/modules/member/what-subids.php +++ b/inc/modules/member/what-subids.php @@ -59,7 +59,7 @@ $show = true; // Check for 'url_id' element //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isFormSent()=' . intval(isFormSent('add_subid')) . ',ifPostContainsSelections()=' . intval(ifPostContainsSelections()) . ',countRequestPost()=' . countRequestPost()); -if ((countRequestPost() > 0) && (!isFormSent('add_subid')) && ((!ifPostContainsSelections()) || (countRequestPost() == 0))) { +if ((countRequestPost('id') > 0) && (!isFormSent('add_subid')) && ((!ifPostContainsSelections('id')) || (countRequestPost('id') == 0))) { // Not found so output message displayMessage('{--MEMBER_SUBID_NO_SELECTIONS--}'); @@ -70,25 +70,25 @@ if ((countRequestPost() > 0) && (!isFormSent('add_subid')) && ((!ifPostContainsS // Edit or delete button hit? if (isFormSent('add_subid')) { // Add new sub id - showEntriesByXmlCallback('member_add_do_subid'); + showEntriesByXmlCallback('member_add_do_user_subid'); } elseif (isFormSent('edit')) { // Show entries for editing - showEntriesByXmlCallback('member_edit_show_subid'); + showEntriesByXmlCallback('member_edit_show_user_subid'); // Do not show the list of URLs after this template $show = false; } elseif (isFormSent('do_edit')) { // Change data of entries - showEntriesByXmlCallback('member_edit_do_subid'); + showEntriesByXmlCallback('member_edit_do_user_subid'); } elseif (isFormSent('delete')) { // Show entries for deletion - showEntriesByXmlCallback('member_delete_show_subid'); + showEntriesByXmlCallback('member_delete_show_user_subid'); // Do not show the list of URLs after this template $show = false; } elseif (isFormSent('do_delete')) { // Remove entries from database - showEntriesByXmlCallback('member_delete_do_subid'); + showEntriesByXmlCallback('member_delete_do_user_subid'); } // Show entries? diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 0513795fb2..4b02a5fa0d 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -2018,28 +2018,226 @@ function doGenericAddEntries ($tableName, $columns = array(), $filterFunctions = } // END - if } -// Adds a given entry to the database -function memberAddEntries ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $columnIndex = NULL) { - // Is it a member? - if (!isMember()) { - // Then abort here - return false; - } // END - if +// 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()) { + // 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]) + ); - // Set POST data generic userid - setPostRequestElement('userid', getMemberId()); + // "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 - // Call inner function - doGenericAddEntries($tableName, $columns, $filterFunctions, $extraValues, $timeColumns, $columnIndex); + // Debug message + //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',idColumn[0]=' . $idColumn[0] . ',entries=
'.print_r($entries,true).'
'); + + // 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]); + } - // Entry has been added? - if ((!SQL_HASZEROAFFECTED()) && ($GLOBALS['__XML_PARSE_RESULT'] === true)) { - // Display success message - displayMessage('{--MEMBER_ENTRY_ADDED--}'); - } else { - // Display failed message - displayMessage('{--MEMBER_ENTRY_NOT_ADDED--}'); + // 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); + + // Prepare filter data array + $filterData = array( + 'mode' => 'edit', + 'table_name' => $tableName, + 'content' => $content, + 'id' => $id, + 'subject' => '', + 'userid_column' => $userIdColumn + ); + + // Send "build mail" out + runFilterChain('send_build_mail', $filterData); + } // END - foreach + + // Delete cache? + if ((count($cacheFiles) > 0) && (!empty($cacheFiles[0]))) { + // Delete cache file(s) + foreach ($cacheFiles as $cache) { + // 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 + + // Return affected rows + return $affected; +} + +// Build a special template list +function doGenericListBuilder ($prefix, $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=
'.print_r($listType,true).'
,tableName
'.print_r($tableName,true).'
,columns=
'.print_r($columns,true).'
,filterFunctions=
'.print_r($filterFunctions,true).'
,extraValues=
'.print_r($extraValues,true).'
,idColumn=
'.print_r($idColumn,true).'
,userIdColumn=
'.print_r($userIdColumn,true).'
,rawUserId=
'.print_r($rawUserId,true).'
'); + 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 + + // Is there 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 ' . $prefix . '_list_builder_id_value!'); + $GLOBALS[$prefix . '_list_builder_id_value'] = bigintval($value); + } // END - if + + // Is there 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("%s_%s_%s_row", + $prefix, + $listType, + $tableName[0] + ), true, $content + ); + } // END - if + + // Free the result + SQL_FREERESULT($result); + } // END - foreach + + // Load master template + loadTemplate(sprintf("%s_%s_%s", + $prefix, + $listType, + $tableName[0] + ), false, $OUT + ); } // [EOF] diff --git a/templates/de/html/member/member_list_user_subids_row.tpl b/templates/de/html/member/member_list_user_subids_row.tpl index 9d8d0eeb91..4a580b8670 100644 --- a/templates/de/html/member/member_list_user_subids_row.tpl +++ b/templates/de/html/member/member_list_user_subids_row.tpl @@ -1,6 +1,6 @@ - +
diff --git a/templates/xml/member/member_edit_show_user_subid.xml b/templates/xml/member/member_edit_show_user_subid.xml new file mode 100644 index 0000000000..e383af5db9 --- /dev/null +++ b/templates/xml/member/member_edit_show_user_subid.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5