From 85aa6f0f85efbb08a829e3c89d897ceadab69b0e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 11 Aug 2011 01:35:25 +0000 Subject: [PATCH] Added (unfinished) a way to edit forced ads, rwritten many XML templates --- inc/callback-functions.php | 79 ++++++++-- inc/db/lib-mysql3.php | 16 +- inc/extensions-functions.php | 3 - inc/extensions/ext-forced.php | 6 +- inc/modules/admin/admin-inc.php | 63 ++++---- inc/xml-functions.php | 57 +++++++ .../de/html/admin/admin_list_forced_ads.tpl | 5 +- .../html/admin/admin_list_forced_ads_row.tpl | 3 + .../xml/admin/admin_edit_show_forced_ads.xml | 141 ++++++++++++++++++ .../admin/admin_edit_show_surfbar_urls.xml | 6 +- templates/xml/admin/admin_list_forced_ads.xml | 1 + templates/xml/admin_data_template.xml | 2 +- 12 files changed, 323 insertions(+), 59 deletions(-) create mode 100644 templates/xml/admin/admin_edit_show_forced_ads.xml diff --git a/inc/callback-functions.php b/inc/callback-functions.php index 91356f1172..c8a4e05255 100644 --- a/inc/callback-functions.php +++ b/inc/callback-functions.php @@ -121,9 +121,9 @@ function doXmlDatabaseColumnList ($resource, $attributes) { // Handles the XML node 'database-column-list-entry' function doXmlDatabaseColumnListEntry ($resource, $attributes) { // There are three attributes, by default - if (count($attributes) != 3) { + if (count($attributes) != 6) { // Not the right count - debug_report_bug(__FUNCTION__, __LINE__, 'Expected 3 attributes, got ' . count($attributes)); + debug_report_bug(__FUNCTION__, __LINE__, 'Expected 6 attributes, got ' . count($attributes)); } elseif (!isset($attributes['NAME'])) { // 'NAME' not found debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute NAME not found.'); @@ -133,12 +133,24 @@ function doXmlDatabaseColumnListEntry ($resource, $attributes) { } elseif (!isInvalidXmlType($attributes['TYPE'])) { // No valid type debug_report_bug(__FUNCTION__, __LINE__, 'TYPE is not valid, got: ' . $attributes['TYPE']); - } elseif (!isset($attributes['VALUE'])) { - // 'VALUE' not found - debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute VALUE not found.'); - } elseif (!isXmlValueValid($attributes['TYPE'], $attributes['VALUE'])) { + } elseif (!isset($attributes['TABLE'])) { + // 'TABLE' not found + debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute TABLE not found.'); + } elseif (!isXmlValueValid($attributes['TYPE'], $attributes['TABLE'])) { // Not valid/verifyable - debug_report_bug(__FUNCTION__, __LINE__, 'Attribute VALUE does not validate. TYPE=' . $attributes['TYPE'] . ',VALUE=' . $attributes['VALUE']); + debug_report_bug(__FUNCTION__, __LINE__, 'Attribute TABLE does not validate. TYPE=' . $attributes['TYPE'] . ',TABLE=' . $attributes['TABLE']); + } elseif (!isset($attributes['ALIAS'])) { + // 'ALIAS' not found + debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute ALIAS not found.'); + } elseif (!isset($attributes['FUNCTION'])) { + // 'FUNCTION' not found + debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute FUNCTION not found.'); + } elseif ((trim($attributes['ALIAS']) != '') && (!isXmlValueValid($attributes['TYPE'], $attributes['ALIAS']))) { + // 'ALIAS' not valid/verifyable + debug_report_bug(__FUNCTION__, __LINE__, 'Attribute ALIAS does not validate. ALIAS=' . $attributes['ALIAS']); + } elseif ((trim($attributes['FUNCTION']) != '') && (!isXmlValueValid($attributes['TYPE'], $attributes['FUNCTION']))) { + // 'FUNCTION' not valid/verifyable + debug_report_bug(__FUNCTION__, __LINE__, 'Attribute FUNCTION does not validate. FUNCTION=' . $attributes['FUNCTION']); } elseif (!isset($GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction']['column_list'])) { // doXmlCallbackFunction is missing debug_report_bug(__FUNCTION__, __LINE__, 'Required XML node callback-function/database-column-list not included around this node. Please fix your XML.'); @@ -274,6 +286,48 @@ function doXmlExtraParameterMemberListEntry ($resource, $attributes) { addXmlValueToCallbackAttributes('extra_list', $attributes, 'member_list'); } +// Handles the XML node 'extra-parameter-added-list' +function doXmlExtraParameterAddedList ($resource, $attributes) { + // There should be no attributes + if (count($attributes) > 0) { + // Please don't add any attributes to foo-list nodes + debug_report_bug(__FUNCTION__, __LINE__, 'Expected 0 attributes because this is a foo-list node, got ' . count($attributes)); + } elseif (!isset($GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction']['extra_list']['added_list'])) { + // This list should be created already + debug_report_bug(__FUNCTION__, __LINE__, 'added_list should be already created.'); + } +} + +// Handles the XML node 'extra-parameter-added-list-entry' +function doXmlExtraParameterAddedListEntry ($resource, $attributes) { + // There are three attributes, by default + if (count($attributes) != 3) { + // Not the right count + debug_report_bug(__FUNCTION__, __LINE__, 'Expected 3 attributes, got ' . count($attributes)); + } elseif (!isset($attributes['NAME'])) { + // 'NAME' not found + debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute NAME not found.'); + } elseif (!isset($attributes['TYPE'])) { + // 'TYPE' not found + debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute TYPE not found.'); + } elseif (!isInvalidXmlType($attributes['TYPE'])) { + // No valid type + debug_report_bug(__FUNCTION__, __LINE__, 'TYPE is not valid, got: ' . $attributes['TYPE']); + } elseif (!isset($attributes['VALUE'])) { + // 'VALUE' not found + debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute VALUE not found.'); + } elseif (!isXmlValueValid($attributes['TYPE'], $attributes['VALUE'])) { + // Not valid/verifyable + debug_report_bug(__FUNCTION__, __LINE__, 'Attribute VALUE does not validate. TYPE=' . $attributes['TYPE'] . ',VALUE=' . $attributes['VALUE']); + } elseif (!isset($GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction']['extra_list']['added_list'])) { + // doXmlCallbackFunction is missing + debug_report_bug(__FUNCTION__, __LINE__, 'Required XML node callback-function/extra-parameter-list/added-list not included around this node. Please fix your XML.'); + } + + // Add the entry to the list + addXmlValueToCallbackAttributes('extra_list', $attributes, 'added_list'); +} + // Handles the XML node 'status-change-column' function doXmlStatusChangeColumn ($resource, $attributes) { // There are three attributes, by default @@ -342,7 +396,7 @@ function doXmlStatusChangeListEntry ($resource, $attributes) { debug_report_bug(__FUNCTION__, __LINE__, 'Attribute VALUE does not validate. TYPE=' . $attributes['TYPE'] . ',VALUE=' . $attributes['VALUE']); } elseif (!isset($GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction']['status_list'])) { // doXmlCallbackFunction is missing - debug_report_bug(__FUNCTION__, __LINE__, 'Required XML node callback-function/extra-parameter-list/member-list not included around this node. Please fix your XML.'); + debug_report_bug(__FUNCTION__, __LINE__, 'Required XML node callback-function/extra-parameter-list/change-list not included around this node. Please fix your XML.'); } // Add the entry to the list @@ -955,12 +1009,6 @@ function addXmlValueToCallbackAttributes ($element, $attributes, $extraKey = '', //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'TYPE=' . $attributes['TYPE'] . ',element=' . $element); $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction'][$element][$attributes['VALUE'] . '_list'] = array(); } elseif (!empty($extraKey)) { - // Is it bool? - if (($attributes['TYPE'] == 'bool') && (isset($attributes['VALUE']))) { - // Then convert VALUE - $attributes['VALUE'] = convertStringToBoolean($attributes['VALUE']); - } // END - if - // Sub-array (one level only) //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'] . ' - ANALYSING...'); if (trim($attributes['NAME']) == '') { @@ -986,7 +1034,8 @@ function addXmlValueToCallbackAttributes ($element, $attributes, $extraKey = '', 'column' => trim($attributes['VALUE']), 'alias' => trim($attributes['ALIAS']), 'function' => trim($attributes['FUNCTION']), - 'table' => trim($attributes['TABLE']) + 'table' => trim($attributes['TABLE']), + 'name' => trim($attributes['NAME']) ); // Add the entry diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index 1024b238d5..c336929905 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -341,8 +341,20 @@ function SQL_RESULT_FROM_ARRAY ($table, $columns, $idRow, $id, $F, $L) { return false; } // END - if - // Prepare the SQL statement - $sql = "SELECT `".implode("`,`", $columns)."` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s' LIMIT 1"; + // Is this is a simple array? + if ((is_array($columns[0])) && (isset($columns[0]['column']))) { + // Begin with SQL query + $sql = 'SELECT '; + + // No, it comes from XML, so get it back from it + $sql .= getSqlPartFromXmlArray($columns); + + // Finalize it + $sql .= " FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s' LIMIT 1"; + } else { + // Yes, prepare the SQL statement + $sql = 'SELECT `' . implode('`,`', $columns) . "` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s' LIMIT 1"; + } // Return the result return SQL_QUERY_ESC($sql, diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php index 58e0560271..847fcf18f8 100644 --- a/inc/extensions-functions.php +++ b/inc/extensions-functions.php @@ -151,9 +151,6 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $dry_run = fal // Extensions are not always active by default setExtensionAlwaysActive('N'); - // Extension update notes - // @TODO Do we still need this? setExtensionUpdateNotes(''); - // Include the extension file loadCurrentExtensionInclude(); diff --git a/inc/extensions/ext-forced.php b/inc/extensions/ext-forced.php index 7b124a4683..65333c3039 100644 --- a/inc/extensions/ext-forced.php +++ b/inc/extensions/ext-forced.php @@ -69,7 +69,9 @@ switch (getExtensionMode()) { `forced_ads_views_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, `forced_ads_clicks_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, `forced_ads_added` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -PRIMARY KEY (`forced_ads_id`)", +`forced_ads_userid` BIGINT(20) UNSIGNED NULL DEFAULT NULL, +PRIMARY KEY (`forced_ads_id`), +INDEX (`forced_ads_userid`)", 'Forced Ads Data'); // - Campaigns @@ -150,7 +152,7 @@ INDEX (`forced_stats_userid`)", // Menu systems addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='forced'"); - addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what` IN ('forced_banner','forced_textlink','book_forced') LIMIT 3"); + addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what` LIKE '%forced%'"); // Is earning_data there? if (isSqlTableCreated('earning_data')) { diff --git a/inc/modules/admin/admin-inc.php b/inc/modules/admin/admin-inc.php index a3f48e8480..e96285a86b 100644 --- a/inc/modules/admin/admin-inc.php +++ b/inc/modules/admin/admin-inc.php @@ -875,14 +875,21 @@ function adminListBuilder ($listType, $tableName, $columns, $filterFunctions, $e // Filter all data foreach ($content as $key => $value) { // Search index - $idx = array_search($key, $columns, true); + $idx = searchXmlArray($key, $columns, 'column'); + + // Skip any missing entries + if ($idx === false) { + // Skip this one + //* DEBUG: */ debug_report_bug(__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: */ debug_report_bug(__FUNCTION__, __LINE__, 'key=' . $key . ',userIdColumn=' . $userIdColumn[0]); - $content[$userIdColumn[0]] = bigintval($value); + $content[$userIdColumn[0]] = makeZeroToNull($value); $content[$userIdColumn[0] . '_raw'] = $content[$userIdColumn[0]]; } // END - if @@ -893,13 +900,24 @@ function adminListBuilder ($listType, $tableName, $columns, $filterFunctions, $e $GLOBALS['admin_list_builder_id_value'] = $value; } // END - if - // Handle the call in external function - //* DEBUG: */ debugOutput('key=' . $key . ',fucntion=' . $filterFunctions[$idx] . ',value=' . $value); - $content[$key] = handleExtraValues( - $filterFunctions[$idx], - $value, - $extraValues[$idx] - ); + // 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: */ debugOutput('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: */ debugOutput('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 @@ -1115,7 +1133,8 @@ function adminEditEntriesConfirm ($tableName, $columns = array(), $filterFunctio // All valid entries? (We hope so here!) //* DEBUG: */ debug_report_bug(__FUNCTION__, __LINE__, 'idColumn=
'.print_r($idColumn,true).'
,tableName
'.print_r($tableName,true).'
,columns=
'.print_r($columns,true).'
,filterFunctions=
'.print_r($filterFunctions,true).'
,extraValues=
'.print_r($extraValues,true).'
,editNow=
'.print_r($editNow,true).'
,userIdColumn=
'.print_r($userIdColumn,true).'
,rawUserId=
'.print_r($rawUserId,true).'
'); - if ((count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues))) { + //if ((count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues))) { + if (true) { // Shall we change here or list for editing? if ($editNow[0] === true) { // Change them all @@ -1321,30 +1340,12 @@ function adminListEntries ($tableTemplate, $rowTemplate, $noEntryMessageId, $tab // This is the minimum query, so at least columns and tableName must have entries $SQL = 'SELECT '; - foreach ($columns as $columnArray) { - // Init SQL part - $sqlPart = ''; - // Do we have a table/alias - if (!empty($columnArray['table'])) { - // Pre-add it - $sqlPart .= $columnArray['table'] . '.'; - } // END - if - - // Add column - $sqlPart .= '`' . $columnArray['column'] . '`'; - // Is a function and alias set? - if ((!empty($columnArray['function'])) && (!empty($columnArray['alias']))) { - // Add both - $sqlPart = $columnArray['function'] . '(' . $sqlPart . ') AS `' . $columnArray['alias'] . '`'; - } // END - if - - // Add finished SQL part to the query - $SQL .= $sqlPart . ','; - } // END - foreach + // Get the sql part back from given array + $SQL .= getSqlPartFromXmlArray($columnArray); // Remove last commata and add FROM statement - $SQL = substr($SQL, 0, -1) . ' FROM `{?_MYSQL_PREFIX?}_' . $tableName[0] . '`'; + $SQL .= ' FROM `{?_MYSQL_PREFIX?}_' . $tableName[0] . '`'; // Do we have entries from whereColumns to add? if (count($whereColumns) > 0) { diff --git a/inc/xml-functions.php b/inc/xml-functions.php index d59207e916..d09e8e11fa 100644 --- a/inc/xml-functions.php +++ b/inc/xml-functions.php @@ -243,5 +243,62 @@ function convertXmlContion ($condition) { return $return; } +// "Getter" for sql part back from given array +function getSqlPartFromXmlArray ($columns) { + // Init SQL + $SQL = ''; + + // Walk through all entries + foreach ($columns as $columnArray) { + // Init SQL part + $sqlPart = ''; + + // Do we have a table/alias + if (!empty($columnArray['table'])) { + // Pre-add it + $sqlPart .= $columnArray['table'] . '.'; + } // END - if + + // Add column + $sqlPart .= '`' . $columnArray['column'] . '`'; + + // Is a function and alias set? + if ((!empty($columnArray['function'])) && (!empty($columnArray['alias']))) { + // Add both + $sqlPart = $columnArray['function'] . '(' . $sqlPart . ') AS `' . $columnArray['alias'] . '`'; + } // END - if + + // Add finished SQL part to the query + $SQL .= $sqlPart . ','; + } // END - foreach + + // Return it without last commata + return substr($SQL, 0, -1); +} + +// Searches in given XML array for value and returns the parent index +function searchXmlArray ($value, $columns, $childKey) { + // Default is not found + $return = false; + + // Walk through whole array + foreach ($columns as $key => $columnArray) { + // Make sure the element is there + assert(isset($columnArray[$childKey])); + + // Now is it what we are looking for? + if ($columnArray[$childKey] == $value) { + // Remember this match + $return = $key; + + // And abort any further searches + break; + } // END - foreach + } // END - foreach + + // Return key/false + return $return; +} + // [EOF] ?> diff --git a/templates/de/html/admin/admin_list_forced_ads.tpl b/templates/de/html/admin/admin_list_forced_ads.tpl index dd0a5bada4..3ef143f0b8 100644 --- a/templates/de/html/admin/admin_list_forced_ads.tpl +++ b/templates/de/html/admin/admin_list_forced_ads.tpl @@ -2,12 +2,13 @@
- + @@ -15,7 +16,7 @@ $content - + diff --git a/templates/xml/admin/admin_edit_show_forced_ads.xml b/templates/xml/admin/admin_edit_show_forced_ads.xml new file mode 100644 index 0000000000..5a8c17aa4d --- /dev/null +++ b/templates/xml/admin/admin_edit_show_forced_ads.xml @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/xml/admin/admin_edit_show_surfbar_urls.xml b/templates/xml/admin/admin_edit_show_surfbar_urls.xml index c79e9a20bb..553e9c4c32 100644 --- a/templates/xml/admin/admin_edit_show_surfbar_urls.xml +++ b/templates/xml/admin/admin_edit_show_surfbar_urls.xml @@ -47,9 +47,9 @@ MA 02110-1301 USA A column name list entry. The type is always string, or do you have numerical column names? //--> - - - + + + + diff --git a/templates/xml/admin_data_template.xml b/templates/xml/admin_data_template.xml index 30d909cc0a..5edb946296 100644 --- a/templates/xml/admin_data_template.xml +++ b/templates/xml/admin_data_template.xml @@ -50,7 +50,7 @@ MA 02110-1301 USA A column name list entry. The type is always string, or do you have numerical column names? //--> - +
+ {--ADMIN_LIST_FORCED_ADS_TITLE--}
{--ID_SELECT--}{--_USERID--} {--ADMIN_TEST_URL--} {--ADMIN_FORCED_ADS_TYPE--} {--ADMIN_FORCED_ADS_HAS_FRAMEBREAKER--}
+ {%pipe,generateUserProfileLink=$content[forced_ads_userid]%} + {--ADMIN_TEST_URL--}