+// List all given joined rows (callback function from XML)
+function doGenericJoinedListEntries ($tableTemplate, $rowTemplate, $noEntryMessageId, $tableName, $tableJoinType, $tableJoinName, $joinOnLeftTable, $joinOnCondition, $joinOnRightTable, $columns, $whereColumns, $orderByColumns, $callbackColumns, $extraParameters = array(), $conditions = array(), $content = array()) {
+ // Verify that tableName and columns are not empty
+ 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 (!isFilledArray($columns)) {
+ // No columns specified
+ reportBug(__FUNCTION__, __LINE__, 'columns is not given. Please fix your XML,tableTemplate=' . $tableTemplate . ',rowTemplate=' . $rowTemplate . ',tableName[0]=' . $tableName[0]);
+ }
+
+ // This is the minimum query, so at least columns and tableName must have entries
+ $sql = 'SELECT ';
+
+ // Get the sql part back from given array
+ $sql .= getSqlPartFromXmlArray($columns);
+
+ // Add "FROM"
+ $sql .= getSqlXmlFromTable($tableName);
+
+ // Add "JOIN"
+ $sql .= getSqlXmlJoinedTable($tableJoinType, $tableJoinName, $joinOnLeftTable, $joinOnCondition, $joinOnRightTable);
+
+ // Add "WHERE"
+ $sql .= getSqlXmlWhereConditions($whereColumns, $conditions);
+
+ // Add "ORDER BY"
+ $sql .= getSqlXmlOrderBy($orderByColumns);
+
+ // Now handle all over to the inner function which will execute the listing
+ doListEntries($sql, $tableTemplate, $noEntryMessageId, $rowTemplate, $callbackColumns, $extraParameters, $content);
+}
+
+// List all given rows (callback function from XML)
+function doGenericListEntries ($tableTemplate, $rowTemplate, $noEntryMessageId, $tableName, $columns, $whereColumns, $orderByColumns, $callbackColumns, $extraParameters = array(), $conditions = array(), $content = array()) {
+ // Verify that tableName and columns are not empty
+ 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 (!isFilledArray($columns)) {
+ // No columns specified
+ reportBug(__FUNCTION__, __LINE__, 'columns is not given. Please fix your XML,tableTemplate=' . $tableTemplate . ',rowTemplate=' . $rowTemplate . ',tableName[0]=' . $tableName[0]);
+ }
+
+ // This is the minimum query, so at least columns and tableName must have entries
+ $sql = 'SELECT ';
+
+ // Get the sql part back from given array
+ $sql .= getSqlPartFromXmlArray($columns);
+
+ // Add "FROM"
+ $sql .= getSqlXmlFromTable($tableName);
+
+ // Add "WHERE"
+ $sql .= getSqlXmlWhereConditions($whereColumns, $conditions);
+
+ // Add "ORDER BY"
+ $sql .= getSqlXmlOrderBy($orderByColumns);
+
+ // Now handle all over to the inner function which will execute the listing
+ doListEntries($sql, $tableTemplate, $noEntryMessageId, $rowTemplate, $callbackColumns, $extraParameters, $content);
+}
+
+// Do the listing of entries
+function doListEntries ($sql, $tableTemplate, $noEntryMessageId, $rowTemplate, $callbackColumns, $extraParameters = array(), $content = array()) {
+ // Run the SQL query
+ $result = sqlQuery($sql, __FUNCTION__, __LINE__);
+
+ // Are there some URLs left?
+ if (!ifSqlHasZeroNumRows($result)) {
+ // List all URLs
+ $OUT = '';
+ while ($row = sqlFetchArray($result)) {
+ // "Translate" content
+ foreach ($callbackColumns as $columnName => $callbackName) {
+ // Fill the callback arguments
+ $args = array($row[$columnName]);
+
+ // Is there more to add?
+ if (isset($extraParameters[$columnName])) {
+ // Add them as well
+ $args = merge_array($args, $extraParameters[$columnName]);
+ } // END - if
+
+ // Call the callback-function
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'callbackFunction=' . $callbackName . ',args=<pre>'.print_r($args, TRUE).'</pre>');
+ // @TODO If the EL sub-system can support more than one parameter, this call_user_func_array() can be avoided
+ $row[$columnName] = call_user_func_array($callbackName, $args);
+ } // END - foreach
+
+ // Load row template
+ $OUT .= loadTemplate(trim($rowTemplate[0]), TRUE, $row);
+ } // END - while
+
+ // Is at least one entry set in content?
+ if (isFilledArray($content)) {
+ // Then add generic 'rows' element
+ $content['rows'] = $OUT;
+ } else {
+ // Direct output is content
+ $content = $OUT;
+ }
+
+ // Load main template
+ loadTemplate(trim($tableTemplate[0]), FALSE, $content);
+ } else {
+ // No URLs in surfbar
+ displayMessage('{--' .$noEntryMessageId[0] . '--}');
+ }
+
+ // Free result
+ sqlFreeResult($result);
+}
+
+// Adds a given entry to the database
+function doGenericAddEntries ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $columnIndex = NULL) {
+ //* DEBUG: */ die(__FUNCTION__.':columns=<pre>'.print_r($columns,TRUE).'</pre>,filterFunctions=<pre>'.print_r($filterFunctions,TRUE).'</pre>,extraValues=<pre>'.print_r($extraValues,TRUE).'</pre>,timeColumns=<pre>'.print_r($timeColumns,TRUE).'</pre>,columnIndex=<pre>'.print_r($columnIndex,TRUE).'</pre>,POST=<pre>'.print_r($_POST,TRUE).'</pre>');
+ // Verify that tableName and columns are not empty
+ 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 (!isFilledArray($columns)) {
+ // No columns specified
+ reportBug(__FUNCTION__, __LINE__, 'columns is not given. Please fix your XML.');
+ }
+
+ // Init columns and value elements
+ $sqlColumns = array();
+ $sqlValues = array();
+
+ // Default is that all went fine
+ $GLOBALS['__XML_PARSE_RESULT'] = TRUE;
+
+ // Is there "time columns"?
+ if (isFilledArray($timeColumns)) {
+ // Then "walk" through all entries
+ foreach ($timeColumns as $column) {
+ // Convert all (possible) selections
+ convertSelectionsToEpocheTimeInPostData($column . '_ye');
+ } // END - foreach
+ } // END - if
+
+ // 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('columnName=<pre>'.print_r($columnName,TRUE).'</pre>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'])));
+
+ // 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($value);
+
+ // Search for it
+ $search = key(search_array($columns, 'column', $columnName));
+
+ // Try to handle call-back functions and/or extra values on the list
+ //* DEBUG: */ outputHtml($key . '/' . $columnName . '=<pre>'.print_r($columns,true).'</pre>search_array()=<pre>'.print_r(search_array($columns, 'column', $columnName), TRUE).'</pre>');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sqlValues[' . $key . '(' . gettype($key) . ')][' . gettype($sqlValues[$key]) . ']=' . $sqlValues[$key] . ' - BEFORE!');
+ if (is_string($key)) {
+ // Key is a string
+ $sqlValues[$key] = doHandleExtraValues($filterFunctions, $extraValues, $key . '_list', $sqlValues[$key], array(''), $search);
+ } else {
+ // Is a number
+ $sqlValues[$key] = doHandleExtraValues($filterFunctions, $extraValues, $key, $sqlValues[$key], array(''), $search);
+ }
+
+ // Is the value not a number?
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sqlValues[' . $key . '(' . gettype($key) . ')][' . gettype($sqlValues[$key]) . ']=' . $sqlValues[$key] . ' - AFTER!');
+ 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
+ sqlQuery($sql, __FUNCTION__, __LINE__);
+
+ // Add id number
+ setPostRequestElement('id', getSqlInsertId());
+
+ // Prepare filter data array
+ $filterData = array(
+ 'mode' => 'add',
+ 'table_name' => $tableName,
+ 'content' => postRequestArray(),
+ 'id' => getSqlInsertId(),
+ 'subject' => '',
+ // @TODO Used generic 'userid' here
+ 'userid_column' => array('userid'),
+ 'raw_userid' => array('userid'),
+ 'affected' => sqlAffectedRows(),
+ '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 = '') {
+ // Is there "time columns"?
+ if (isFilledArray($timeColumns)) {
+ // Then "walk" through all entries
+ foreach ($timeColumns as $column) {
+ // Convert all (possible) selections
+ convertSelectionsToEpocheTimeInPostData($column . '_ye');
+ } // END - foreach
+ } // END - if
+
+ // 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',
+ sqlEscapeString($tableName[0])
+ );
+
+ // "Walk" through all entries
+ foreach (postRequestArray() as $key => $entries) {
+ // Skip raw userid which is always invalid
+ if (($key == $rawUserId[0]) || ($key == ($rawUserId[0] . '_raw')) || ($key == 'do_edit')) {
+ // 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 . ',id=' . $id . ',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]))) {
+ // Search for the right array index
+ $search = key(search_array($columns, 'column', $key));
+
+ // Add this entry to content
+ $content[$key] = $entries[$id];
+
+ // Debug message
+ //* BUG: */ die($key.'/'.$id.'/'.$search.'=<pre>'.print_r($columns,TRUE).'</pre><pre>'.print_r($filterFunctions,TRUE).'</pre>');
+
+ // Handle possible call-back functions and/or extra values
+ $entries[$id] = doHandleExtraValues($filterFunctions, $extraValues, $key, $entries[$id], $userIdColumn, $search);
+
+ // Add key/value pair to SQL string
+ $sql .= addKeyValueSql($key, $entries[$id]);
+ } elseif (($key != $idColumn[0]) && (!is_array($entries))) {
+ // Search for it
+ $search = key(search_array($columns, 'column', $key));
+ //* BUG: */ die($key.'/<pre>'.print_r($search, TRUE).'</pre>=<pre>'.print_r($columns, TRUE).'</pre>');
+
+ // Debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',entries[' . gettype($entries) . ']=' . $entries . ',search=' . $search . ' - BEFORE!');
+
+ // Add normal entries as well
+ $content[$key] = $entries;
+
+ // Handle possible call-back functions and/or extra values
+ $entries = doHandleExtraValues($filterFunctions, $extraValues, $key, $entries, $userIdColumn, $search);
+
+ // Debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',entries[' . gettype($entries) . ']=' . $entries . ',search=' . $search . ' - AFTER!');
+
+ // Add key/value pair to SQL string
+ $sql .= addKeyValueSql($key, $entries);
+ }
+ } // END - foreach
+
+ // Finish SQL command
+ $sql = substr($sql, 0, -1) . " WHERE `" . sqlEscapeString($idColumn[0]) . "`=" . $id;
+ if ((isset($rawUserId[0])) && (isset($userIdColumn[0])) && (isPostRequestElementSet($rawUserId[0])) && (!is_array(postRequestElement($rawUserId[0])))) {
+ // Add user id as well
+ $sql .= ' AND `' . $userIdColumn[0] . '`=' . bigintval(postRequestElement($rawUserId[0]));
+ } // END - if
+ $sql .= " LIMIT 1";
+
+ // Run this query
+ //* BUG: */ die($sql.'<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
+ sqlQuery($sql, __FUNCTION__, __LINE__);
+
+ // Add affected rows
+ $edited = sqlAffectedRows();
+ $affected += $edited;
+
+ // Load all data from that id
+ $result = sqlQueryEscaped("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, sqlFetchArray($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
+ sqlFreeResult($result);
+ } // END - foreach
+
+ // Delete cache?
+ if ((isFilledArray($cacheFiles)) && (!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
+
+ // Use rebuildCache() to delete it
+ rebuildCache($cache);
+ } // END - foreach
+ } // END - if
+
+ // Return affected rows
+ return $affected;
+}
+
+// Delete rows by given id numbers
+function doGenericDeleteEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $deleteNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array()) {
+ // The base SQL command:
+ $sql = "DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s` IN (%s)";
+
+ // Is a user id provided?
+ //* BUG: */ die('<pre>'.print_r($rawUserId,TRUE).'</pre><pre>'.print_r($userIdColumn,TRUE).'</pre>');
+ if ((isset($rawUserId[0])) && (isset($userIdColumn[0])) && (isPostRequestElementSet($rawUserId[0])) && (!is_array(postRequestElement($rawUserId[0])))) {
+ // Add user id as well
+ $sql .= ' AND `' . $userIdColumn[0] . '`=' . bigintval(postRequestElement($rawUserId[0]));
+ } // END - if
+
+ // $idColumn[0] in POST must be an array again
+ if (!is_array(postRequestElement($idColumn[0]))) {
+ // This indicates that you have conflicting form field naming with XML names
+ reportBug(__FUNCTION__, __LINE__, 'You have a wrong form field element, idColumn[0]=' . $idColumn[0]);
+ } // END - if
+
+ // Delete them all
+ //* BUG: */ die($sql.'<pre>'.print_r($tableName,TRUE).'</pre><pre>'.print_r($columns,TRUE).'</pre><pre>'.print_r($filterFunctions,TRUE).'</pre><pre>'.print_r($extraValues,TRUE).'</pre><pre>'.print_r($deleteNow,TRUE).'</pre><pre>'.print_r($idColumn,TRUE).'</pre>');
+ $idList = '';
+ foreach (postRequestElement($idColumn[0]) as $id => $sel) {
+ // Is id zero?
+ if (!isValidId($id)) {
+ // Then skip this
+ continue;
+ } // END - if
+
+ // Is there a userid?
+ if (isPostRequestElementSet($userIdColumn[0])) {
+ // Load all data from that id
+ $result = sqlQueryEscaped("SELECT * FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`=%s LIMIT 1",
+ array(
+ $tableName[0],
+ $idColumn[0],
+ $id
+ ), __FUNCTION__, __LINE__);
+
+ // Fetch the data
+ $content = sqlFetchArray($result);
+
+ // Free the result
+ sqlFreeResult($result);
+
+ // Send "build mails" out
+ sendGenericBuildMails('delete', $tableName, $content, $id, '', $userIdColumn);
+ } // END - if
+
+ // Add id number
+ $idList .= $id . ',';
+ } // END - foreach
+
+ // Run the query
+ sqlQueryEscaped($sql,
+ array(
+ $tableName[0],
+ $idColumn[0],
+ convertNullToZero(substr($idList, 0, -1))
+ ), __FUNCTION__, __LINE__);
+
+ // Return affected rows
+ return sqlAffectedRows();
+}
+
+// Build a special template list
+// @TODO cacheFiles is not yet supported
+function doGenericListBuilder ($prefix, $listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId = array('userid'), $content = array()) {
+ // $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 = getSqlResultFromArray($tableName[0], $columns, $idColumn[0], $id, __FUNCTION__, __LINE__);
+
+ // Is there one entry?
+ if (sqlNumRows($result) == 1) {
+ // Load all data
+ $row = sqlFetchArray($result);
+
+ // Filter all data
+ foreach ($row as $key => $value) {
+ // Search index
+ $idx = searchXmlArray($key, $columns, 'column');
+
+ // Default name is NULL
+ $name = NULL;
+
+ // Is the name there?
+ if (isset($columns[$idx]['name'])) {
+ // Then use it
+ $name = $columns[$idx]['name'];
+ } // END - if
+
+ // 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]);
+ $row[$userIdColumn[0]] = convertZeroToNull($value);
+ $row[$userIdColumn[0] . '_raw'] = $row[$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
+
+ // Try to handle call-back functions and/or extra values
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'idx=' . $idx . ',row[' . $key . ']=' . $row[$key]);
+ //if ($key == 'forced_campaign_created') die($idx.'=<pre>'.print_r($columns,true).'</pre><pre>'.print_r($extraValues,true).'</pre>');
+ $row[$key] = doHandleExtraValues($filterFunctions, $extraValues, $idx, $row[$key], $userIdColumn, ((!is_null($name)) ? $name : $key), $id);
+ } // END - foreach
+
+ // Then list it
+ $OUT .= loadTemplate(sprintf('%s_%s_%s_row',
+ $prefix,
+ $listType,
+ $tableName[0]
+ ), TRUE, $row
+ );
+ } // END - if
+
+ // Free the result
+ sqlFreeResult($result);
+ } // END - foreach
+
+ // Is there an entry in $content?
+ if (isFilledArray($content)) {
+ // Use generic 'rows'
+ $content['rows'] = $OUT;
+ } else {
+ // Use direct output
+ $content = $OUT;
+ }
+
+ // Load master template
+ loadTemplate(
+ sprintf('%s_%s_%s',
+ $prefix,
+ $listType,
+ $tableName[0]
+ ), FALSE, $content
+ );
+}
+
+// Adds key/value pair to a working SQL string together
+function addKeyValueSql ($key, $value) {
+ // Init SQL
+ $sql = '';
+
+ // Is it NULL?
+ if (($value == 'NULL') || (is_null($value))) {
+ // Add key with NULL
+ $sql .= sprintf(' `%s`=NULL,',
+ sqlEscapeString($key)
+ );
+ } elseif ((is_double($value)) || (is_float($value)) || (is_int($value))) {
+ // Is a number, so addd it directly
+ $sql .= sprintf(' `%s`=%s,',
+ sqlEscapeString($key),
+ $value
+ );
+ } else {
+ // Else add the value escape'd
+ $sql .= sprintf(" `%s`='%s',",
+ sqlEscapeString($key),
+ sqlEscapeString($value)
+ );
+ }
+
+ // Return SQL string
+ return $sql;
+}
+
+// "Getter" for an array from given table and columns
+function getArrayFromTable ($tableName, $columns, $orderBy, $ordered = 'ASC', $whereSql = '') {
+ // The table must exist
+ assert(ifSqlTableExists($tableName));
+
+ // Search for it
+ $result = sqlQueryEscaped('SELECT
+ `' . implode('`, `', $columns) . '`
+FROM
+ `{?_MYSQL_PREFIX?}_%s`
+' . $whereSql . '
+ORDER BY
+ `%s` %S',
+ array(
+ $tableName,
+ $orderBy,
+ $ordered
+ ), __FUNCTION__, __LINE__
+ );
+
+ // Init array
+ $rows = array();
+
+ // Are there entries?
+ if (!ifSqlHasZeroNumRows($result)) {
+ // Load all entries
+ while ($row = sqlFetchArray($result)) {
+ array_push($rows, $row);
+ } // END - while
+ } // END - if
+
+ // Free result
+ sqlFreeResult($result);
+
+ // Return all found rows
+ return $rows;
+}
+