+ // Add columns and values
+ foreach ($columns as $key => $columnName) {
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',columnName=' . $columnName);
+ // Is columnIndex set?
+ if (!is_null($columnIndex)) {
+ // Check conditions
+ //* DEBUG: */ die('columnIndex=<pre>'.print_r($columnIndex,TRUE).'</pre>'.debug_get_printable_backtrace());
+ assert((is_array($columnName)) && (is_string($columnIndex)) && (isset($columnName[$columnIndex])));
+
+ // Then use that index "blindly"
+ $columnName = $columnName[$columnIndex];
+ } // END - if
+
+ // 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'])) . '<br />');
+
+ // Copy entry securely to the final arrays
+ $sqlColumns[$key] = SQL_ESCAPE($columnName);
+ $sqlValues[$key] = SQL_ESCAPE(postRequestElement($columnName));
+
+ // Send data through the filter function if found
+ if ((isset($filterFunctions[$key])) && (isset($extraValues[$key . '_list']))) {
+ // Debug mode enabled?
+ if (isDebugModeEnabled()) {
+ // Then log it
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',sqlValues[' . $key . '][' . gettype($sqlValues[$key]) . ']=' . $sqlValues[$key] . ' - BEFORE!');
+ } // END - if
+
+ // Filter function set, so run it
+ $sqlValues[$key] = call_user_func_array($filterFunctions[$key], merge_array(array($columnName), $extraValues[$key . '_list']));
+
+ // Debug mode enabled?
+ if (isDebugModeEnabled()) {
+ // Then log it
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',sqlValues[' . $key . '][' . gettype($sqlValues[$key]) . ']=' . $sqlValues[$key] . ' - AFTER!');
+ } // END - if
+ } elseif ((isset($filterFunctions[$key])) && (!empty($filterFunctions[$key])) && (!empty($sqlValues[$key]))) {
+ // Debug mode enabled?
+ if (isDebugModeEnabled()) {
+ // Then log it
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',sqlValues[' . $key . '][' . gettype($sqlValues[$key]) . ']=' . $sqlValues[$key] . ' - BEFORE!');
+ } // END - if
+
+ // Run through an extra filter
+ $sqlValues[$key] = handleExtraValues($filterFunctions[$key], $sqlValues[$key], NULL);
+
+ // Debug mode enabled?
+ if (isDebugModeEnabled()) {
+ // Then log it
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',sqlValues[' . $key . '][' . gettype($sqlValues[$key]) . ']=' . $sqlValues[$key] . ' - AFTER!');
+ } // END - if
+
+ }
+
+ // Is the value not a number?
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sqlValues[' . $key . '][' . gettype($sqlValues[$key]) . ']=' . $sqlValues[$key]);
+ if (($sqlValues[$key] != 'NULL') && (is_string($sqlValues[$key]))) {
+ // Add quotes around it
+ $sqlValues[$key] = chr(39) . $sqlValues[$key] . chr(39);
+ } // END - if
+
+ // Is the value false?
+ if ($sqlValues[$key] === FALSE) {
+ // One "parser" didn't like it
+ $GLOBALS['__XML_PARSE_RESULT'] = FALSE;
+ break;
+ } // END - if
+ } // END - foreach
+
+ // If all values are okay, continue
+ if ($sqlValues[$key] !== FALSE) {
+ // Build the SQL query
+ $sql = 'INSERT INTO `{?_MYSQL_PREFIX?}_' . $tableName[0] . '` (`' . implode('`, `', $sqlColumns) . "`) VALUES (" . implode(',', $sqlValues) . ')';
+
+ // Run the SQL query
+ SQL_QUERY($sql, __FUNCTION__, __LINE__);
+
+ // Add id
+ setPostRequestElement('id', SQL_INSERTID());
+
+ // Prepare filter data array
+ $filterData = array(
+ 'mode' => 'add',
+ 'table_name' => $tableName,
+ 'content' => postRequestArray(),
+ 'id' => SQL_INSERTID(),
+ 'subject' => '',
+ // @TODO Used generic 'userid' here
+ 'userid_column' => array('userid'),
+ 'raw_userid' => array('userid'),
+ 'affected' => SQL_AFFECTEDROWS(),
+ 'sql' => $sql,
+ );
+
+ // Send "build mail" out
+ runFilterChain('send_build_mail', $filterData);
+ } // 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(), $subject = '') {
+ // Change them all
+ $affected = '0';
+ foreach (postRequestElement($idColumn[0]) as $id => $sel) {
+ // Secure id number
+ $id = bigintval($id);
+
+ // 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]))) {
+ //die($key.'/'.$id.'=<pre>'.print_r($columns,TRUE).'</pre><pre>'.print_r($filterFunctions,TRUE).'</pre>');
+ // Search for the right array index
+ $search = key(search_array($columns, 'column', $key));
+
+ // 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 + extra value set
+ $entries[$id] = handleExtraValues($filterFunctions[$key], $entries[$id], $extraValues[$key]);
+ } elseif (isset($filterFunctions[$search])) {
+ // Debug mode enabled?
+ if (isDebugModeEnabled()) {
+ // Then log it
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',filterFunctions=' . $filterFunctions[$search] . ',key=' . $key . ',id=' . $id . ',entries[' . gettype($entries[$id]) . ']=' . $entries[$id] . ' - BEFORE!');
+ } // END - if
+
+ // Handle extra values
+ $entries[$id] = handleExtraValues($filterFunctions[$search], $entries[$id], NULL);
+
+ // Debug mode enabled?
+ if (isDebugModeEnabled()) {
+ // Then log it
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',filterFunctions=' . $filterFunctions[$search] . ',key=' . $key . ',id=' . $id . ',entries[' . gettype($entries[$id]) . ']=' . $entries[$id] . ' - AFTER!');
+ } // END - if
+
+ // Make sure entries[id] is not bool, then something went wrong
+ assert(!is_bool($entries[$id]));
+ }
+
+ // 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);
+ if ((isset($rawUserId[0])) && (isPostRequestElementSet($rawUserId[0])) && (isset($userIdColumn[0]))) {
+ // Add user id as well
+ $sql .= ' AND `' . $userIdColumn[0] . '`=' . bigintval(postRequestElement($rawUserId[0]));
+ } // END - if
+ $sql .= " LIMIT 1";
+
+ // Run this query
+ SQL_QUERY($sql, __FUNCTION__, __LINE__);
+
+ // Add affected rows
+ $edited = SQL_AFFECTEDROWS();
+ $affected += $edited;
+
+ // 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));
+
+ // Prepare filter data array
+ $filterData = array(
+ 'mode' => 'edit',
+ 'table_name' => $tableName,
+ 'content' => $content,
+ 'id' => $id,
+ 'subject' => $subject,
+ 'userid_column' => $userIdColumn,
+ 'raw_userid' => $rawUserId,
+ 'affected' => $edited,
+ 'sql' => $sql,
+ );
+
+ // Send "build mail" out
+ runFilterChain('send_build_mail', $filterData);
+
+ // Free the result
+ SQL_FREERESULT($result);
+ } // 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