Added (unfinished) a way to edit forced ads, rwritten many XML templates
[mailer.git] / inc / callback-functions.php
index 91356f11722b34c03a64b6fb3cabe9aa2cbff555..c8a4e052551721de61a17641bddd9e1649bfe011 100644 (file)
@@ -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