+// 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;
+}
+
+// Encodes an URL for adding session id, etc.
+function encodeUrl ($url, $outputMode = '0') {
+ // Do we have already have a PHPSESSID inside? Then it is already converted...
+ if (strpos($url, session_name()) !== false) return $url;
+
+ // Do we have a valid session?
+ if (((!isset($GLOBALS['valid_session'])) || ($GLOBALS['valid_session'] === false) || (!isset($_COOKIE[session_name()]))) && (isSpider() === false)) {
+ // Invalid session
+ // Determine right seperator
+ $seperator = '&';
+ if (strpos($url, '?') === false) {
+ // No question mark
+ $seperator = '?';
+ } elseif ((getOutputMode() != '0') || ($outputMode != '0')) {
+ // Non-HTML mode
+ $seperator = '&';
+ }
+
+ // Add it to URL
+ if (session_id() != '') {
+ $url .= $seperator . session_name() . '=' . session_id();
+ } // END - if
+ } // END - if
+
+ // Add {?URL?} ?
+ if ((substr($url, 0, strlen(getConfig('URL'))) != getConfig('URL')) && (substr($url, 0, 7) != '{?URL?}') && (substr($url, 0, 7) != 'http://') && (substr($url, 0, 8) != 'https://')) {
+ // Add it
+ $url = '{?URL?}/' . $url;
+ } // END - if
+
+ // Return the URL
+ return $url;
+}
+
+// Simple check for spider
+function isSpider () {
+ // Get the UA
+ $userAgent = strtolower(detectUserAgent(true));
+
+ // It should not be empty, if so it is better a spider/bot
+ if (empty($userAgent)) return true;
+
+ // Is it a spider?
+ return ((strpos($userAgent, 'spider') !== false) || (strpos($userAgent, 'slurp') !== false) || (strpos($userAgent, 'bot') !== false));
+}
+
+// Prepares the header for HTML output
+function loadHtmlHeader () {
+ // Determine the page title
+ $content['header_title'] = determinePageTitle();
+
+ // Output page header code
+ $GLOBALS['page_header'] = loadTemplate('page_header', true, $content);
+
+ // Include meta data in 'guest' module
+ if (getModule() == 'index') {
+ // Load meta data template
+ $GLOBALS['page_header'] .= loadTemplate('metadata', true);
+
+ // Add meta description to header
+ if ((isInstalled()) && (isAdminRegistered()) && (SQL_IS_LINK_UP())) {
+ // Add meta description not in admin and login module and when the script is installed
+ generateMetaDescriptionCode();
+ } // END - if
+ } // END - if
+
+ // Include more header data here
+ $GLOBALS['page_header'] .= loadTemplate('header', true);
+
+ // Include stylesheet
+ loadIncludeOnce('inc/stylesheet.php');
+
+ // Closing HEAD tag
+ $GLOBALS['page_header'] .= '</head>';
+}
+
+// Adds page header and footer to output array element
+function addPageHeaderFooter () {
+ // Add them all together. This is maybe to simple
+ $GLOBALS['output'] = $GLOBALS['page_header'] . $GLOBALS['output'] . $GLOBALS['page_footer'];
+}
+
+// Generates meta description for current module and 'what' value
+function generateMetaDescriptionCode () {
+ // Only include from guest area
+ if (getModule() == 'index') {
+ // Construct dynamic description
+ $DESCR = '{?MAIN_TITLE?} '.trim(getConfig('title_middle')) . ' ' . getTitleFromMenu('guest', getWhat());
+
+ // Output it directly
+ $GLOBALS['page_header'] .= '<meta name="description" content="' . $DESCR . '" />';
+ } // END - if
+
+ // Remove depth
+ unset($GLOBALS['ref_level']);
+}
+