detectExtraTemplatePath() cached, ext-network continued:
authorRoland Häder <roland@mxchange.org>
Sun, 15 Nov 2009 19:09:00 +0000 (19:09 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 15 Nov 2009 19:09:00 +0000 (19:09 +0000)
- Function detectExtraTemplatePath() is now 'cached' by $GLOBALS usage
- Extension ext-network contined, so a selection box for networks is generated

.gitattributes
inc/functions.php
inc/language/de.php
inc/language/network_de.php
inc/libs/network_functions.php
inc/modules/admin/what-list_network_types.php
inc/modules/admin/what-list_payouts.php
inc/modules/admin/what-stats_mods.php
inc/mysql-manager.php
templates/de/html/select/.htaccess [new file with mode: 0644]
templates/de/html/select/select_network_box.tpl [new file with mode: 0644]

index 5c459e0ef7de9a7e0748ae4ed53f78ec58ffa948..44b342d3ada2968b55a146cc443e5c01b36a2536 100644 (file)
@@ -1588,6 +1588,8 @@ templates/de/html/register_header.tpl -text
 templates/de/html/removeip_level.tpl -text
 templates/de/html/runtime_fatal_row.tpl -text
 templates/de/html/runtime_fatal_table.tpl -text
+templates/de/html/select/.htaccess -text
+templates/de/html/select/select_network_box.tpl -text
 templates/de/html/show_bonus.tpl -text
 templates/de/html/show_bonus_footer.tpl -text
 templates/de/html/show_bonus_header.tpl -text
index d077a3c7a875919cf5f86af638de2b3b28272b8e..521a3fa7ba782f2ba231f30385f1186abcda4ba2 100644 (file)
@@ -312,7 +312,7 @@ function loadTemplate ($template, $return = false, $content = array()) {
                        eval($GLOBALS['template_eval'][$template]);
                } elseif ((isAdmin()) || ((isInstalling()) && (!isInstalled()))) {
                        // Only admins shall see this warning or when installation mode is active
-                       $ret = '<br /><span class=\\"guest_failed\\">{--TEMPLATE_404--}</span><br />
+                       $ret = '<br /><span class="guest_failed">{--TEMPLATE_404--}</span><br />
 (' . $template . ')<br />
 <br />
 {--TEMPLATE_CONTENT--}
@@ -350,44 +350,53 @@ function detectExtraTemplatePath ($template) {
        // Default is empty
        $extraPath = '';
 
-       // Check for admin/guest/member templates
-       if (substr($template, 0, 6) == 'admin_') {
-               // Admin template found
-               $extraPath = 'admin/';
-       } elseif (substr($template, 0, 6) == 'guest_') {
-               // Guest template found
-               $extraPath = 'guest/';
-       } elseif (substr($template, 0, 7) == 'member_') {
-               // Member template found
-               $extraPath = 'member/';
-       } elseif (substr($template, 0, 8) == 'install_') {
-               // Installation template found
-               $extraPath = 'install/';
-       } elseif (substr($template, 0, 4) == 'ext_') {
-               // Extension template found
-               $extraPath = 'ext/';
-       } elseif (substr($template, 0, 3) == 'la_') {
-               // 'Logical-area' template found
-               $extraPath = 'la/';
-       } elseif (substr($template, 0, 3) == 'js_') {
-               // JavaScript template found
-               $extraPath = 'js/';
-       } elseif (substr($template, 0, 5) == 'menu_') {
-               // Menu template found
-               $extraPath = 'menu/';
-       } else {
-               // Test for extension
-               $test = substr($template, 0, strpos($template, '_'));
+       // Do we have cache?
+       if (!isset($GLOBALS['extra_path'][$template])) {
+               // Check for admin/guest/member/etc. templates
+               if (substr($template, 0, 6) == 'admin_') {
+                       // Admin template found
+                       $extraPath = 'admin/';
+               } elseif (substr($template, 0, 6) == 'guest_') {
+                       // Guest template found
+                       $extraPath = 'guest/';
+               } elseif (substr($template, 0, 7) == 'member_') {
+                       // Member template found
+                       $extraPath = 'member/';
+               } elseif (substr($template, 0, 7) == 'select_') {
+                       // Selection template found
+                       $extraPath = 'select/';
+               } elseif (substr($template, 0, 8) == 'install_') {
+                       // Installation template found
+                       $extraPath = 'install/';
+               } elseif (substr($template, 0, 4) == 'ext_') {
+                       // Extension template found
+                       $extraPath = 'ext/';
+               } elseif (substr($template, 0, 3) == 'la_') {
+                       // 'Logical-area' template found
+                       $extraPath = 'la/';
+               } elseif (substr($template, 0, 3) == 'js_') {
+                       // JavaScript template found
+                       $extraPath = 'js/';
+               } elseif (substr($template, 0, 5) == 'menu_') {
+                       // Menu template found
+                       $extraPath = 'menu/';
+               } else {
+                       // Test for extension
+                       $test = substr($template, 0, strpos($template, '_'));
 
-               // Probe for valid extension name
-               if (isExtensionNameValid($test)) {
-                       // Set extra path to extension's name
-                       $extraPath = $test . '/';
-               } // END - if
-       }
+                       // Probe for valid extension name
+                       if (isExtensionNameValid($test)) {
+                               // Set extra path to extension's name
+                               $extraPath = $test . '/';
+                       } // END - if
+               }
+
+               // Store it in cache
+               $GLOBALS['extra_path'][$template] = $extraPath;
+       } // END - if
 
        // Return result
-       return $extraPath;
+       return $GLOBALS['extra_path'][$template];
 }
 
 // Loads an email template and compiles it
@@ -3815,6 +3824,58 @@ function sendModeMails ($mod, $modes) {
        loadTemplate('admin_settings_saved', false, $content);
 }
 
+// Generates a 'selection box' from given array
+function generateSelectionBoxFromArray ($options, $name, $optionValue, $optionContent) {
+       // Start the output
+       $OUT = '<select name="' . $name . '" size="1" class="admin_select">
+<option value="X" disabled="disabled">{--PLEASE_SELECT--}</option>';
+
+       // Walk through all options
+       foreach ($options as $option) {
+               // Add the <option> entry
+               $OUT .= '<option value="' . $option[$optionValue] . '">' . $option[$optionContent] . '</option>';
+       } // END - foreach
+
+       // Finish selection box
+       $OUT .= '</select>';
+
+       // Prepare output
+       $content = array(
+               'selection_box' => $OUT,
+               'module'        => getModule(),
+               'what'          => getWhat()
+       );
+
+       // Load template and return it
+       return loadTemplate('select_' . $name . '_box', true, $content);
+}
+
+// Get a module from filename and access level
+function getModuleFromFileName ($file, $accessLevel) {
+       // Default is 'invalid';
+       $modCheck = 'invalid';
+
+       // @TODO This is still very static, rewrite it somehow
+       switch ($accessLevel) {
+               case 'admin':
+                       $modCheck = 'admin';
+                       break;
+
+               case 'sponsor':
+               case 'guest':
+               case 'member':
+                       $modCheck = getModule();
+                       break;
+
+               default: // Unsupported file name / access level
+                       debug_report_bug('Unsupported file name=' . basename($file) . '/access level=' . $accessLevel);
+                       break;
+       }
+
+       // Return result
+       return $modCheck;
+}
+
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////
index 8873a637a13e4ec415cbaca5c5dfc3e1de162e9a..32e8bafd628341b69897e6d74f6394787fdea8ed 100644 (file)
@@ -1138,6 +1138,7 @@ addMessages(array(
        'ADMIN_EXTENSIONS_REMOVED' => "Es wurden <span class=\"data\">%s</span> Erweiterungen aus Ihrem {?mt_word?} entfernt.",
        'ADMIN_WARNING_SQL_PATCHES_MISSING' => "Eine essentielle Erweiterung <span=\"data\">sql_patches</span> ist noch nicht installiert. Bitte erledigen Sie dies bald, da Ihr {?mt_word?} sonst nicht funktioniert.",
        'ADMIN_EXTENSION_IS_NON_PRODUCTIVE' => "Die von Ihnen ausgew&auml;hlte Erweiterung <span=\"data\">%s</span> ist noch nicht f&uuml;r den produktiven Betrieb freigegeben und befindet sich somit noch in der Entwicklung. Bitte nur verwenden, wenn Sie wissen, was Sie tun.",
+       'ADMIN_ENTRIES_404' => "Es wurden keine Eintr&auml;ge gefunden.",
 
        'MEMBER_MAIL_BONUS_CONFIRMED_ON' => "Sie haben diese Bonusmail <span class=\"data\">%s</span> best&auml;tigt.",
        'MEMBER_MAIL_NORMAL_CONFIRMED_ON' => "Sie haben diese Klickmail <span class=\"data\">%s</span> best&auml;tigt.",
index f917795c7f2e4a5682d93bcbf93fd2c0401def5c..e360e4d8f669038e4b6a9bf2b2d894dd37d88eae 100644 (file)
@@ -54,6 +54,7 @@ addMessages(array(
        'ADMIN_NETWORK_ADD_TITLE' => "Neues Werbenetzwerk hinzuf&uuml;gen - Allgemeine Daten",
        'ADMIN_NETWORK_EDIT_TITLE' => "Werbenetzwerk editieren - Allgemeine Daten",
        'ADMIN_NETWORK_DELETE_TITLE' => "Werbenetzwerk l&ouml;schen - Allgemeine Daten",
+       'ADMIN_NETWORK_SELECT_TITLE' => "Werbenetzwerk ausw&auml;hlen",
        // - Link titles
        'ADMIN_NETWORK_LIST_TYPES_LINK_TITLE' => "Weiter zu den Werbearten",
        'ADMIN_NETWORK_LIST_PARAMS_LINK_TITLE' => "Weiter zu den Abfrageparametern",
@@ -65,6 +66,7 @@ addMessages(array(
        'ADMIN_NETWORK_CHANGE' => "Daten &auml;ndern",
        'ADMIN_NETWORK_DELETE' => "L&ouml;schen",
        'ADMIN_NETWORK_REMOVE' => "Daten entfernen",
+       'ADMIN_NETWORK_CHOOSE' => "Werbenetzwerk ausw&auml;hlen",
        // - Success nots
        'ADMIN_NETWORK_UPDATED' => "Es wurden <span class=\"data\">%s</span> Eintr&auml;ge in den allgemeinen Daten aktualisiert.",
        'ADMIN_NETWORK_REMOVED' => "Es wurden <span class=\"data\">%s</span> Eintr&auml;ge aus den allgemeinen Dateen gel&ouml;scht.",
index e90f6340229a7e983c64b1b92569ef7e399003a6..dfa15112c76a72414f199c3333b1d351ea9062b9 100644 (file)
@@ -139,6 +139,42 @@ function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
        return SQL_AFFECTEDROWS();
 }
 
+// Generates a list of networks for given script and returns it
+function generateAdminNetworkList () {
+       // Init output
+       $content = '';
+
+       // Query for all networks
+       $result = SQL_QUERY("SELECT
+       `network_id`, `network_title`
+FROM
+       `{?_MYSQL_PREFIX?}_network_data`
+ORDER BY
+       `network_title` 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_id']))) $rows[] = $row;
+               } // END - while
+
+               // Generate the selection box
+               $content = generateSelectionBoxFromArray($rows, 'network', 'network_id', 'network_title');
+       } else {
+               // Nothing selected
+               $content = loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ENTRIES_404'));
+       }
+
+       // Free the result
+       SQL_FREERESULT($result);
+
+       // Return the list
+       return $content;
+}
+
 //------------------------------------------------------------------------------
 //                             Call-back functions
 //------------------------------------------------------------------------------
index fc31ab8560e52297bd74ca6d46c4d34b1b6b3a94..4e856c6a32d68ad66338cb92e3e8021670861d0e 100644 (file)
@@ -44,5 +44,15 @@ if ((!defined('__SECURITY')) || (!isAdmin())) {
 // Add description as navigation point
 addMenuDescription('admin', __FILE__);
 
+// Do we have a network selected?
+if (isGetRequestElementSet('network')) {
+       // Get its data for template
+       $networkData = getNetworkDataById(getRequestElement('network'));
+       print('<pre>'.print_r($networkData, true).'</pre>');
+} else {
+       // Generate network list for this script
+       outputHtml(generateAdminNetworkList());
+}
+
 // [EOF]
 ?>
index 63ca2e494693e11e313089e20ffb9748a58d963d..df76022cf6a82921972078cf09233b2480d633bc 100644 (file)
@@ -39,7 +39,7 @@
 // Some security stuff...
 if ((!defined('__SECURITY')) || (!isAdmin())) {
        die();
-}
+} // END - if
 
 // Add description as navigation point
 addMenuDescription('admin', __FILE__);
@@ -208,8 +208,6 @@ LIMIT 1",
                loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_FAILED_OBTAIN_TASK_ID'));
        }
 } else {
-       if (!isGetRequestElementSet('do')) setRequestGetElement('do', '');
-
        if (getRequestElement('do') == 'delete') {
                // Delete all requests
                $result = SQL_QUERY("TRUNCATE `{?_MYSQL_PREFIX?}_user_payouts`", __FILE__, __LINE__);
index 7157b6e835740dceb13a54551ab497e4417ee719..59101e257ec9ea38532ff9397453da5e19107815 100644 (file)
 // Some security stuff...
 if ((!defined('__SECURITY')) || (!isAdmin())) {
        die();
-}
+} // END - if
 
 // Add description as navigation point
 addMenuDescription('admin', __FILE__);
 
-// If var is empty set it to empty
-if (!isGetRequestElementSet('mod')) setRequestGetElement('mod', '');
-
 // Check if module was selected
 if ((getRequestElement('mod') == 'index') || (getRequestElement('mod') == 'login')) {
        // Select menu system
index 9503fff2fa96259510081d2eaa9c8c41743f6447..e691d6cf7cc8a5ea6e4fe1da19b04f9cdf7a4d65 100644 (file)
@@ -299,40 +299,27 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = tru
                // This is an action file!
                $type = 'action';
                $search = substr($file, 7);
-               switch ($accessLevel) {
-                       case 'admin':
-                               $modCheck = 'admin';
-                               break;
-
-                       case 'sponsor':
-                       case 'guest':
-                       case 'member':
-                               $modCheck = getModule();
-                               break;
-               }
+
+               // Get access level from it
+               $modCheck = getModuleFromFileName($file, $accessLevel);
+
+               // Add what
                $AND = " AND (`what`='' OR `what` IS NULL)";
        } elseif (substr($file, 0, 5) == 'what-') {
                // This is an admin what file!
                $type = 'what';
                $search = substr($file, 5);
-               $AND = '';
-               switch ($accessLevel) {
-                       case 'admin':
-                               $modCheck = 'admin';
-                               break;
-
-                       case 'guest':
-                       case 'member':
-                               $modCheck = getModule();
-                               if (!isAdmin()) {
-                                       $AND = " AND `visible`='Y' AND `locked`='N'";
-                               }
-                               break;
-               }
+               $AND = " AND `visible`='Y' AND `locked`='N'";
+
+               // Get access level from it
+               $modCheck = getModuleFromFileName($file, $accessLevel);
+
+               // Do we have admin? Then display all
+               if (isAdmin()) $AND = '';
 
                $dummy = substr($search, 0, -4);
                $AND .= " AND `action`='".getModeAction($accessLevel, $dummy)."'";
-       } elseif (($accessLevel == 'sponsor') || ($accessLevel == "engine")) {
+       } elseif (($accessLevel == 'sponsor') || ($accessLevel == 'engine')) {
                // Sponsor / engine menu
                $type     = 'what';
                $search   = $file;
@@ -1556,7 +1543,12 @@ function generateOptionList ($table, $id, $name, $default='', $special='', $wher
 
                // Query the database
                $result = SQL_QUERY_ESC("SELECT `%s`, `%s`".$SPEC." FROM `{?_MYSQL_PREFIX?}_%s` ".$where." ORDER BY `%s` ASC",
-                       array($id, $name, $table, $name), __FUNCTION__, __LINE__);
+                       array(
+                               $id,
+                               $name,
+                               $table,
+                               $name
+                       ), __FUNCTION__, __LINE__);
 
                // Do we have rows?
                if (SQL_NUMROWS($result) > 0) {
@@ -1569,13 +1561,13 @@ function generateOptionList ($table, $id, $name, $default='', $special='', $wher
                                if (!empty($add)) $add = ' ('.$add.')';
                                $ret .= '>' . $title . $add . '</option>';
                        } // END - while
-
-                       // Free memory
-                       SQL_FREERESULT($result);
                } else {
                        // No data found
                        $ret = '<option value="x">{--SELECT_NONE--}</option>';
                }
+
+               // Free memory
+               SQL_FREERESULT($result);
        }
 
        // Return - hopefully - the requested data
diff --git a/templates/de/html/select/.htaccess b/templates/de/html/select/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/templates/de/html/select/select_network_box.tpl b/templates/de/html/select/select_network_box.tpl
new file mode 100644 (file)
index 0000000..2d7d80b
--- /dev/null
@@ -0,0 +1,17 @@
+<div align="center">
+<form accept-charset="utf-8" action="{?URL?}/modules.php" method="GET">
+<input type="hidden" name="module" value="$content[module]" />
+<input type="hidden" name="what" value="$content[what]" />
+<div class="admin_table dashed">
+       <div class="admin_title bottom">
+               <strong>{--ADMIN_NETWORK_SELECT_TITLE--}</strong>
+       </div>
+       <div class="bottom">
+               $content[selection_box]
+       </div>
+       <div class="admin_footer">
+               <input type="submit" class="admin_submit" value="{--ADMIN_NETWORK_CHOOSE--}" />
+       </div>
+</div>
+</form>
+</div>