]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/network_functions.php
A lot forced-space characters ( ) removed, naming convention applied also in...
[mailer.git] / inc / libs / network_functions.php
index b33bfea63ba7edea3f7d49082ede2fad9a7fb682..11ca2ba09d9984c2cb994c9557d783326e606faf 100644 (file)
@@ -42,6 +42,16 @@ if (!defined('__SECURITY')) {
        die();
 } // END - if
 
+// Private setter for current network id
+function setCurrentNetworkId ($id) {
+       $GLOBALS['current_network_id'] = bigintval($id);
+}
+
+// Private getter for current network id
+function getCurrentNetworkId () {
+       return $GLOBALS['current_network_id'];
+}
+
 // Handle a (maybe) sent form here
 function doNetworkHandleForm () {
        // Was the form sent?
@@ -139,6 +149,9 @@ function getNetworkDataById ($id, $column = '') {
                debug_report_bug('Network id ' . $id . ' is smaller than 1.');
        } // END - if
 
+       // Set current network id
+       setCurrentNetworkId($id);
+
        // Is it cached?
        if (!isset($GLOBALS['network_data'][$id])) {
                // By default we have no data
@@ -174,6 +187,57 @@ LIMIT 1",
        }
 }
 
+// "Getter" for a network's data by provided type id number
+function getNetworkDataByTypeId ($id, $column = '') {
+       // Ids lower one are not accepted
+       if ($id < 1) {
+               // Not good, should be fixed
+               debug_report_bug('Network type id ' . $id . ' is smaller than 1.');
+       } // END - if
+
+       // Set current network id
+       setCurrentNetworkId($id);
+
+       // Is it cached?
+       if (!isset($GLOBALS['network_data'][$id])) {
+               // By default we have no data
+               $GLOBALS['network_data'][$id] = array();
+
+               // Query for the network data
+               $result = SQL_QUERY_ESC("SELECT
+       d.`network_id`, d.`network_short_name`, d.`network_title`, d.`network_reflink`, d.`network_data_seperator`, d.`network_row_seperator`, d.`network_request_type`, d.`network_charset`,
+       t.`network_type_handle`, t.`network_type_api_url`, t.`network_type_click_url`, t.`network_type_banner_url`
+FROM
+       `{?_MYSQL_PREFIX?}_network_data` AS d
+LEFT JOIN
+       `{?_MYSQL_PREFIX?}_network_types` AS t
+ON
+       d.`network_id`=t.`network_id`
+WHERE
+       t.`network_type_id`=%s
+LIMIT 1",
+                       array(bigintval($id)), __FUNCTION__, __LINE__);
+
+               // Do we have an entry?
+               if (SQL_NUMROWS($result) == 1) {
+                       // Then get it
+                       $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result);
+               } // END - if
+
+               // Free result
+               SQL_FREERESULT($result);
+       } // END - if
+
+       // Return result
+       if (empty($column)) {
+               // Return array
+               return $GLOBALS['network_data'][$id];
+       } else {
+               // Return column
+               return $GLOBALS['network_data'][$id][$column];
+       }
+}
+
 // "Getter" for a network type data by provided id number
 function getNetworkTypeDataById ($id) {
        // Ids lower one are not accepted
@@ -371,6 +435,51 @@ ORDER BY
        return $content;
 }
 
+// Generator (somewhat getter) for a list of network types for all types
+function generateAdminDistinctNetworkTypeList () {
+       // Init content
+       $content = '';
+
+       // Query all types of this network
+       $result = SQL_QUERY("SELECT
+       t.`network_type_id`, t.`network_type_handle`, d.`network_title`
+FROM
+       `{?_MYSQL_PREFIX?}_network_types` AS t
+LEFT JOIN
+       `{?_MYSQL_PREFIX?}_network_data` AS d
+ON
+       t.`network_id`=d.`network_id`
+ORDER BY
+       d.`network_short_name` ASC,
+       t.`network_type_handle` ASC", __FILE__, __LINE__);
+
+       // Do we have entries?
+       if (SQL_NUMROWS($result) > 0) {
+               // List all entries
+               $rows = array();
+               while ($row = SQL_FETCHARRAY($result)) {
+                       // Is this valid, then add it
+                       if ((is_array($row)) && (isset($row['network_type_id']))) {
+                               // Add entry
+                               $rows[$row['network_type_id']] = $row;
+                       } // END - if
+               } // END - while
+
+               // Generate the selection box
+               $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
+       } else {
+               // Nothing selected
+               $content = loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_ENTRIES_404'));
+       }
+
+       // Free the result
+       SQL_FREERESULT($result);
+       //* DEBUG: */ die('<pre>'.htmlentities($content).'</pre>');
+
+       // Return content
+       return $content;
+}
+
 // Generator (somewhat getter) for network type options
 function generateNetworkTypeOptions ($id) {
        // Is this an array, then we just came back from edit/delete actions
@@ -451,14 +560,16 @@ function generateNetworkArrayTranslationOptions ($default) {
        if (!isset($GLOBALS['network_array_translation'][$default])) {
                // Generate and cache it
                $GLOBALS['network_array_translation'][$default] = generateOptionList(
-                       'network_request_params',
-                       'network_param_id',
-                       'request_param_key',
+                       'network_translations',
+                       'network_translation',
+                       'network_translation',
                        $default,
                        '',
-                       sprintf("WHERE `network_id`='%s'", bigintval(getRequestParameter('network'))),
+                       sprintf("WHERE `network_type_id`=%s",
+                               bigintval(getRequestParameter('network_type'))
+                       ),
                        $GLOBALS['network_array_translation_disabled'],
-                       'ADMIN_NETWORK_REQUEST_PARAMETER_'
+                       'ADMIN_NETWORK_ARRAY_TRANSLATION_'
                );
        } // END - if
 
@@ -1038,12 +1149,15 @@ function doAdminNetworkProcessAddnetworkparamForm () {
 function doExpressionNetwork ($data) {
        // Construct replacer
        $replacer = sprintf(
-               "\" . %s(%s, '%s') . \"",
+               "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
                $data['callback'],
                $data['matches'][4][$data['key']],
                $data['extra_func']
        );
 
+       // Replace %network% with the current network id
+       $replacer = str_replace('%network%', getCurrentNetworkId(), $replacer);
+
        // Replace the code
        $code = replaceExpressionCode($data, $replacer);
 
@@ -1053,3 +1167,4 @@ function doExpressionNetwork ($data) {
 
 // [EOF]
 ?>
+