- // Write back sorted array
- $array = $dummy;
-}
-
-//
-function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 'register_select') {
- $OUT = '';
-
- if ($type == 'yn') {
- // This is a yes/no selection only!
- if ($id > 0) $prefix .= "[" . $id."]";
- $OUT .= " <select name=\"" . $prefix."\" class=\"" . $class . "\" size=\"1\">\n";
- } else {
- // Begin with regular selection box here
- if (!empty($prefix)) $prefix .= "_";
- $type2 = $type;
- if ($id > 0) $type2 .= "[" . $id."]";
- $OUT .= " <select name=\"".strtolower($prefix . $type2)."\" class=\"" . $class . "\" size=\"1\">\n";
- }
-
- switch ($type) {
- case 'day': // Day
- for ($idx = 1; $idx < 32; $idx++) {
- $OUT .= "<option value=\"" . $idx."\"";
- if ($default == $idx) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- } // END - for
- break;
-
- case 'month': // Month
- foreach ($GLOBALS['month_descr'] as $month => $descr) {
- $OUT .= "<option value=\"" . $month."\"";
- if ($default == $month) $OUT .= ' selected="selected"';
- $OUT .= ">" . $descr."</option>\n";
- } // END - for
- break;
-
- case 'year': // Year
- // Get current year
- $year = date('Y', time());
-
- // Use configured min age or fixed?
- if ((isExtensionActive('other')) && (getExtensionVersion('other') >= '0.2.1')) {
- // Configured
- $startYear = $year - getConfig('min_age');
- } else {
- // Fixed 16 years
- $startYear = $year - 16;
- }
-
- // Calculate earliest year (100 years old people can still enter Internet???)
- $minYear = $year - 100;
-
- // Check if the default value is larger than minimum and bigger than actual year
- if (($default > $minYear) && ($default >= $year)) {
- for ($idx = $year; $idx < ($year + 11); $idx++) {
- $OUT .= "<option value=\"" . $idx."\"";
- if ($default == $idx) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- } // END - for
- } elseif ($default == -1) {
- // Current year minus 1
- for ($idx = $startYear; $idx <= ($year + 1); $idx++)
- {
- $OUT .= "<option value=\"" . $idx."\">" . $idx."</option>\n";
- }
- } else {
- // Get current year and subtract the configured minimum age
- $OUT .= "<option value=\"".($minYear - 1)."\"><" . $minYear."</option>\n";
- // Calculate earliest year depending on extension version
- if ((isExtensionActive('other')) && (getExtensionVersion('other') >= '0.2.1')) {
- // Use configured minimum age
- $year = date('Y', time()) - getConfig('min_age');
- } else {
- // Use fixed 16 years age
- $year = date('Y', time()) - 16;
- }
-
- // Construct year selection list
- for ($idx = $minYear; $idx <= $year; $idx++) {
- $OUT .= "<option value=\"" . $idx."\"";
- if ($default == $idx) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- } // END - for
- }
- break;
-
- case 'sec':
- case 'min':
- for ($idx = '0'; $idx < 60; $idx+=5) {
- if (strlen($idx) == 1) $idx = '0' . $idx;
- $OUT .= "<option value=\"" . $idx."\"";
- if ($default == $idx) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- } // END - for
- break;
-
- case 'hour':
- for ($idx = '0'; $idx < 24; $idx++) {
- if (strlen($idx) == 1) $idx = '0' . $idx;
- $OUT .= "<option value=\"" . $idx."\"";
- if ($default == $idx) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- } // END - for
- break;
-
- case 'yn':
- $OUT .= "<option value=\"Y\"";
- if ($default == 'Y') $OUT .= ' selected="selected"';
- $OUT .= ">{--YES--}</option>\n<option value=\"N\"";
- if ($default != 'Y') $OUT .= ' selected="selected"';
- $OUT .= ">{--NO--}</option>\n";
- break;
- }
- $OUT .= " </select>\n";
- return $OUT;
-}
-
-//
-// Deprecated : $length
-// Optional : $DATA
-//
-function generateRandomCode ($length, $code, $userid, $DATA = '') {
- // Build server string
- $server = $_SERVER['PHP_SELF'] . getConfig('ENCRYPT_SEPERATOR') . detectUserAgent() . getConfig('ENCRYPT_SEPERATOR') . getenv('SERVER_SOFTWARE') . getConfig('ENCRYPT_SEPERATOR') . detectRemoteAddr().":'.':".filemtime(getConfig('PATH').'inc/databases.php');
-
- // Build key string
- $keys = getConfig('SITE_KEY') . getConfig('ENCRYPT_SEPERATOR') . getConfig('DATE_KEY');
- if (isConfigEntrySet('secret_key')) $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('secret_key');
- if (isConfigEntrySet('file_hash')) $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('file_hash');
- $keys .= getConfig('ENCRYPT_SEPERATOR') . date('d-m-Y (l-F-T)', getConfig('patch_ctime'));
- if (isConfigEntrySet('master_salt')) $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('master_salt');
-
- // Build string from misc data
- $data = $code . getConfig('ENCRYPT_SEPERATOR') . $userid . getConfig('ENCRYPT_SEPERATOR') . $DATA;
-
- // Add more additional data
- if (isSessionVariableSet('u_hash')) $data .= getConfig('ENCRYPT_SEPERATOR') . getSession('u_hash');
-
- // Add referal id, language, theme and userid
- $data .= getConfig('ENCRYPT_SEPERATOR') . determineReferalId();
- $data .= getConfig('ENCRYPT_SEPERATOR') . getLanguage();
- $data .= getConfig('ENCRYPT_SEPERATOR') . getCurrentTheme();
- $data .= getConfig('ENCRYPT_SEPERATOR') . getMemberId();
-
- // Calculate number for generating the code
- $a = $code + getConfig('_ADD') - 1;
-
- if (isConfigEntrySet('master_salt')) {
- // Generate hash with master salt from modula of number with the prime number and other data
- $saltedHash = generateHash(($a % getConfig('_PRIME')) . getConfig('ENCRYPT_SEPERATOR') . $server . getConfig('ENCRYPT_SEPERATOR') . $keys . getConfig('ENCRYPT_SEPERATOR') . $data . getConfig('ENCRYPT_SEPERATOR') . getConfig('DATE_KEY') . getConfig('ENCRYPT_SEPERATOR') . $a, getConfig('master_salt'));
-
- // Create number from hash
- $rcode = hexdec(substr($saltedHash, strlen(getConfig('master_salt')), 9)) / abs(getConfig('rand_no') - $a + sqrt(getConfig('_ADD'))) / pi();
- } else {
- // Generate hash with "hash of site key" from modula of number with the prime number and other data
- $saltedHash = generateHash(($a % getConfig('_PRIME')) . getConfig('ENCRYPT_SEPERATOR') . $server . getConfig('ENCRYPT_SEPERATOR') . $keys . getConfig('ENCRYPT_SEPERATOR') . $data . getConfig('ENCRYPT_SEPERATOR') . getConfig('DATE_KEY') . getConfig('ENCRYPT_SEPERATOR') . $a, substr(sha1(getConfig('SITE_KEY')), 0, getConfig('salt_length')));
-
- // Create number from hash
- $rcode = hexdec(substr($saltedHash, 8, 9)) / abs(getConfig('rand_no') - $a + sqrt(getConfig('_ADD'))) / pi();
- }
-
- // At least 10 numbers shall be secure enought!
- $len = getConfig('code_length');
- if ($len == '0') $len = $length;
- if ($len == '0') $len = 10;
-
- // Cut off requested counts of number
- $return = substr(str_replace('.', '', $rcode), 0, $len);
-
- // Done building code
- return $return;
-}
-
-// Does only allow numbers
-function bigintval ($num, $castValue = true) {
- // Filter all numbers out
- $ret = preg_replace('/[^0123456789]/', '', $num);
-
- // Shall we cast?
- if ($castValue === true) $ret = (double)$ret;
-
- // Has the whole value changed?
- if ('' . $ret . '' != '' . $num . '') {
- // Log the values
- debug_report_bug('Problem with number found. ret=' . $ret . ', num='. $num);
- } // END - if
-
- // Return result
- return $ret;
-}
-
-// Insert the code in $img_code into jpeg or PNG image
-function generateImageOrCode ($img_code, $headerSent = true) {
- // Is the code size oversized or shouldn't we display it?
- if ((strlen($img_code) > 6) || (empty($img_code)) || (getConfig('code_length') == '0')) {
- // Stop execution of function here because of over-sized code length
- debug_report_bug('img_code ' . $img_code .' has invalid length. img_code()=' . strlen($img_code) . ' code_length=' . getConfig('code_length'));
- } elseif ($headerSent === false) {
- // Return an HTML code here
- return "<img src=\"{?URL?}/img.php?code=" . $img_code."\" alt=\"Image\" />\n";
- }
-
- // Load image
- $img = sprintf("%s/theme/%s/images/code_bg.%s",
- getConfig('PATH'),
- getCurrentTheme(),
- getConfig('img_type')
- );
-
- // Is it readable?
- if (isFileReadable($img)) {
- // Switch image type
- switch (getConfig('img_type'))
- {
- case 'jpg':
- // Okay, load image and hide all errors
- $image = imagecreatefromjpeg($img);
- break;
-
- case 'png':
- // Okay, load image and hide all errors
- $image = imagecreatefrompng($img);
- break;
- }
- } else {
- // Exit function here
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("File for image type %s not found.", getConfig('img_type')));
- return;
- }
-
- // Generate text color (red/green/blue; 0 = dark, 255 = bright)
- $text_color = imagecolorallocate($image, 0, 0, 0);
-
- // Insert code into image
- imagestring($image, 5, 14, 2, $img_code, $text_color);
-
- // Return to browser
- sendHeader('Content-Type: image/' . getConfig('img_type'));
-
- // Output image with matching image factory
- switch (getConfig('img_type')) {
- case 'jpg': imagejpeg($image); break;
- case 'png': imagepng($image); break;
- }
-
- // Remove image from memory
- imagedestroy($image);
-}
-// Create selection box or array of splitted timestamp
-function createTimeSelections ($timestamp, $prefix = '', $display = '', $align = 'center', $return_array=false) {
- // Calculate 2-seconds timestamp
- $stamp = round($timestamp);
- //* DEBUG: */ print("*" . $stamp.'/' . $timestamp."*<br />");
-
- // Do we have a leap year?
- $SWITCH = '0';
- $TEST = date('Y', time()) / 4;
- $M1 = date('m', time());
- $M2 = date('m', (time() + $timestamp));
-
- // If so and if current time is before 02/29 and estimated time is after 02/29 then add 86400 seconds (one day)
- if ((floor($TEST) == $TEST) && ($M1 == "02") && ($M2 > "02")) $SWITCH = getConfig('ONE_DAY');
-
- // First of all years...
- $Y = abs(floor($timestamp / (31536000 + $SWITCH)));
- //* DEBUG: */ print("Y={$Y}<br />");
- // Next months...
- $M = abs(floor($timestamp / 2628000 - $Y * 12));
- //* DEBUG: */ print("M={$M}<br />");
- // Next weeks
- $W = abs(floor($timestamp / 604800 - $Y * ((365 + $SWITCH / getConfig('ONE_DAY')) / 7) - ($M / 12 * (365 + $SWITCH / getConfig('ONE_DAY')) / 7)));
- //* DEBUG: */ print("W={$W}<br />");
- // Next days...
- $D = abs(floor($timestamp / 86400 - $Y * (365 + $SWITCH / getConfig('ONE_DAY')) - ($M / 12 * (365 + $SWITCH / getConfig('ONE_DAY'))) - $W * 7));
- //* DEBUG: */ print("D={$D}<br />");
- // Next hours...
- $h = abs(floor($timestamp / 3600 - $Y * (365 + $SWITCH / getConfig('ONE_DAY')) * 24 - ($M / 12 * (365 + $SWITCH / getConfig('ONE_DAY')) * 24) - $W * 7 * 24 - $D * 24));
- //* DEBUG: */ print("h={$h}<br />");
- // Next minutes..
- $m = abs(floor($timestamp / 60 - $Y * (365 + $SWITCH / getConfig('ONE_DAY')) * 24 * 60 - ($M / 12 * (365 + $SWITCH / getConfig('ONE_DAY')) * 24 * 60) - $W * 7 * 24 * 60 - $D * 24 * 60 - $h * 60));
- //* DEBUG: */ print("m={$m}<br />");
- // And at last seconds...
- $s = abs(floor($timestamp - $Y * (365 + $SWITCH / getConfig('ONE_DAY')) * 24 * 3600 - ($M / 12 * (365 + $SWITCH / getConfig('ONE_DAY')) * 24 * 3600) - $W * 7 * 24 * 3600 - $D * 24 * 3600 - $h * 3600 - $m * 60));
- //* DEBUG: */ print("s={$s}<br />");
-
- // Is seconds zero and time is < 60 seconds?
- if (($s == '0') && ($timestamp < 60)) {
- // Fix seconds
- $s = round($timestamp);
- } // END - if
-
- //
- // Now we convert them in seconds...
- //
- if ($return_array) {
- // Just put all data in an array for later use
- $OUT = array(
- 'YEARS' => $Y,
- 'MONTHS' => $M,
- 'WEEKS' => $W,
- 'DAYS' => $D,
- 'HOURS' => $h,
- 'MINUTES' => $m,
- 'SECONDS' => $s
- );
- } else {
- // Generate table
- $OUT = "<div align=\"" . $align."\">\n";
- $OUT .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"timebox_table dashed\">\n";
- $OUT .= "<tr>\n";
-
- if (ereg('Y', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_YEARS--}</strong></td>\n";
- }
-
- if (ereg('M', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_MONTHS--}</strong></td>\n";
- }
-
- if (ereg('W', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_WEEKS--}</strong></td>\n";
- }
-
- if (ereg('D', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_DAYS--}</strong></td>\n";
- }
-
- if (ereg('h', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_HOURS--}</strong></td>\n";
- }
-
- if (ereg('m', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_MINUTES--}</strong></td>\n";
- }
-
- if (ereg('s', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_SECONDS--}</strong></td>\n";
- }
-
- $OUT .= "</tr>\n";
- $OUT .= "<tr>\n";
-
- if (ereg('Y', $display) || (empty($display))) {
- // Generate year selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix."_ye\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 10; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
- if ($idx == $Y) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
- } else {
- $OUT .= "<input type=\"hidden\" name=\"" . $prefix."_ye\" value=\"0\" />\n";
- }
-
- if (ereg('M', $display) || (empty($display))) {
- // Generate month selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix."_mo\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 11; $idx++)
- {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
- if ($idx == $M) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
- } else {
- $OUT .= "<input type=\"hidden\" name=\"" . $prefix."_mo\" value=\"0\" />\n";
- }
-
- if (ereg('W', $display) || (empty($display))) {
- // Generate week selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix."_we\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 4; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
- if ($idx == $W) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
- } else {
- $OUT .= "<input type=\"hidden\" name=\"" . $prefix."_we\" value=\"0\" />\n";
- }
-
- if (ereg('D', $display) || (empty($display))) {
- // Generate day selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix."_da\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 31; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
- if ($idx == $D) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
- } else {
- $OUT .= "<input type=\"hidden\" name=\"" . $prefix."_da\" value=\"0\" />\n";
- }
-
- if (ereg('h', $display) || (empty($display))) {
- // Generate hour selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix."_ho\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 23; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
- if ($idx == $h) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
- } else {
- $OUT .= "<input type=\"hidden\" name=\"" . $prefix."_ho\" value=\"0\" />\n";
- }
-
- if (ereg('m', $display) || (empty($display))) {
- // Generate minute selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix."_mi\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 59; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
- if ($idx == $m) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
- } else {
- $OUT .= "<input type=\"hidden\" name=\"" . $prefix."_mi\" value=\"0\" />\n";
- }
-
- if (ereg('s', $display) || (empty($display))) {
- // Generate second selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix."_se\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 59; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
- if ($idx == $s) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
- } else {
- $OUT .= "<input type=\"hidden\" name=\"" . $prefix."_se\" value=\"0\" />\n";
- }
- $OUT .= "</tr>\n";
- $OUT .= "</table>\n";
- $OUT .= "</div>\n";
- // Return generated HTML code
- }
- return $OUT;
-}
-
-//
-function createTimestampFromSelections ($prefix, $postData) {
- // Initial return value
- $ret = '0';
-
- // Do we have a leap year?
- $SWITCH = '0';
- $TEST = date('Y', time()) / 4;
- $M1 = date('m', time());
- // If so and if current time is before 02/29 and estimated time is after 02/29 then add 86400 seconds (one day)
- if ((floor($TEST) == $TEST) && ($M1 == "02") && ($postData[$prefix."_mo"] > "02")) $SWITCH = getConfig('ONE_DAY');
- // First add years...
- $ret += $postData[$prefix."_ye"] * (31536000 + $SWITCH);
- // Next months...
- $ret += $postData[$prefix."_mo"] * 2628000;
- // Next weeks
- $ret += $postData[$prefix."_we"] * 604800;
- // Next days...
- $ret += $postData[$prefix."_da"] * 86400;
- // Next hours...
- $ret += $postData[$prefix."_ho"] * 3600;
- // Next minutes..
- $ret += $postData[$prefix."_mi"] * 60;
- // And at last seconds...
- $ret += $postData[$prefix."_se"];
- // Return calculated value
- return $ret;
-}
-
-// Creates a 'fancy' human-readable timestamp from a Uni* stamp
-function createFancyTime ($stamp) {
- // Get data array with years/months/weeks/days/...
- $data = createTimeSelections($stamp, '', '', '', true);
- $ret = '';
- foreach($data as $k => $v) {
- if ($v > 0) {
- // Value is greater than 0 "eval" data to return string
- eval("\$ret .= \", \".\$v.\" {--_".strtoupper($k)."--}\";");
- break;
- } // END - if
- } // END - foreach
-
- // Do we have something there?
- if (strlen($ret) > 0) {
- // Remove leading commata and space
- $ret = substr($ret, 2);
- } else {
- // Zero seconds
- $ret = "0 {--_SECONDS--}";
- }
-
- // Return fancy time string
- return $ret;
-}
-
-// Generates a navigation row for listing emails
-function addEmailNavigation ($PAGES, $offset, $show_form, $colspan, $return=false) {
- $SEP = ''; $TOP = '';
- if ($show_form === false) {
- $TOP = " top";
- $SEP = "<tr><td colspan=\"" . $colspan."\" class=\"seperator\"> </td></tr>";
- }
-
- $NAV = '';
- for ($page = 1; $page <= $PAGES; $page++) {
- // Is the page currently selected or shall we generate a link to it?
- if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
- // Is currently selected, so only highlight it
- $NAV .= '<strong>-';
- } else {
- // Open anchor tag and add base URL
- $NAV .= '<a href="{?URL?}/modules.php?module=admin&what=' . getWhat() . '&page=' . $page . '&offset=' . $offset;
-
- // Add userid when we shall show all mails from a single member
- if ((isGetRequestElementSet('userid')) && (bigintval(getRequestElement('userid')) > 0)) $NAV .= '&userid=' . bigintval(getRequestElement('userid'));
-
- // Close open anchor tag
- $NAV .= '">';
- }
- $NAV .= $page;
- if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
- // Is currently selected, so only highlight it
- $NAV .= '-</strong>';
- } else {
- // Close anchor tag
- $NAV .= '</a>';
- }
-
- // Add seperator if we have not yet reached total pages
- if ($page < $PAGES) $NAV .= ' | ';
- } // END - for
-
- // Define constants only once
- $content['nav'] = $NAV;
- $content['span'] = $colspan;
- $content['top'] = $TOP;
- $content['sep'] = $SEP;
-
- // Load navigation template
- $OUT = loadTemplate('admin_email_nav_row', true, $content);
-
- if ($return === true) {
- // Return generated HTML-Code
- return $OUT;
- } else {
- // Output HTML-Code
- outputHtml($OUT);
- }