From: Roland Häder Date: Wed, 9 Jan 2013 05:14:09 +0000 (+0000) Subject: Introduced padLeftZero() X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=94eb7e461c29c7050a41aa6d5edcd3a1707bf904;p=mailer.git Introduced padLeftZero() --- diff --git a/inc/extensions/ext-bonus.php b/inc/extensions/ext-bonus.php index 4ba29ce01f..a076266253 100644 --- a/inc/extensions/ext-bonus.php +++ b/inc/extensions/ext-bonus.php @@ -365,14 +365,14 @@ INDEX `userid` (`userid`)", case '0.5.6': // SQL queries for v0.5.6 // Get current month - $curr = str_pad(getMonth(), 2, '0', STR_PAD_LEFT); + $curr = padLeftZero(getMonth()); if ($curr == '00') $curr = '12'; // Generate timemark... $mark = mktime(0, 0, 0, $curr, 1, getYear()); // Update accounts which are not active last months - addExtensionSql("UPDATE + addExtensionSql('UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `turbo_bonus`=0, @@ -381,9 +381,9 @@ SET `bonus_stats`=0, `bonus_ref`=0 WHERE - `last_online` < ".$mark." + `last_online` < ' . $mark . ' ORDER BY - `userid` ASC"); + `userid` ASC'); // Update notes (these will be set as task text!) setExtensionUpdateNotes("Ein weiterer Scriptfehler hat nur die Gewinner aus der Aktiv-Rallye genommen. Die anderen Mitglieder sind somit "nach oben gerutsch"."); diff --git a/inc/functions.php b/inc/functions.php index 76b7859dbb..f6ac219435 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -928,7 +928,7 @@ function encodeHashForCookie ($passHash) { $mod = substr($mod, 0, 2); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'idx=' . $idx . ',part1=' . $part1 . '/part2=' . $part2 . '/mod=' . $mod . '(' . strlen($mod) . ')'); - $mod = str_pad($mod, 2, '0', STR_PAD_LEFT); + $mod = padLeftZero($mod); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mod(' . ($idx * 2) . ')=' . $mod . '*'); $start += 2; $newHash .= $mod; diff --git a/inc/modules/admin/what-list_beg.php b/inc/modules/admin/what-list_beg.php index 1eb7c9ca10..48f249efbc 100644 --- a/inc/modules/admin/what-list_beg.php +++ b/inc/modules/admin/what-list_beg.php @@ -47,7 +47,7 @@ if (isBegRallyeEnabled()) { // Shall I withdraw now? if (isPostRequestElementSet('withdraw')) { // Okay, let's prepare... - $curr = str_pad((getMonth() - 1), 2, '0', STR_PAD_LEFT); + $curr = padLeftZero(getMonth() - 1); updateConfiguration('last_month', $curr); displayMessage('{--ADMIN_BEG_WITHDRAW_PREPARED--}'); } // END - if diff --git a/inc/modules/admin/what-list_bonus.php b/inc/modules/admin/what-list_bonus.php index 78e687de93..6f516c0f45 100644 --- a/inc/modules/admin/what-list_bonus.php +++ b/inc/modules/admin/what-list_bonus.php @@ -47,7 +47,7 @@ if (isBonusRallyeActive()) { // Shall I withdraw now? if (isPostRequestElementSet('withdraw')) { // Okay, let's prepare... - $curr = str_pad((getMonth() - 1), 2, '0', STR_PAD_LEFT); + $curr = padLeftZero(getMonth() - 1); updateConfiguration('last_month', $curr); displayMessage('{--ADMIN_BONUS_WITHDRAW_PREPARED--}'); } // END - if diff --git a/inc/modules/guest/what-login.php b/inc/modules/guest/what-login.php index ac02edd488..566fc5ae6c 100644 --- a/inc/modules/guest/what-login.php +++ b/inc/modules/guest/what-login.php @@ -49,9 +49,9 @@ if ((!isExtensionActive('user')) && (!isAdmin())) { return; } // END - if -// Initialize variables +// Initialize variables as not logged in $errorCode = '0'; -$userid = FALSE; +$userid = NULL; $hash = ''; $url = ''; $add = ''; @@ -85,10 +85,6 @@ if ((isMemberIdSet()) && (isSessionVariableSet('u_hash'))) { $userid = bigintval(postRequestElement('id')); } } // END - if -} else { - // Not logged in - $userid = NULL; - $hash = ''; } if (isMember()) { @@ -131,7 +127,7 @@ if (!empty($errorCode)) { fetchUserData(getSession('userid')); } // END - if - // @TODO Move this HTML code into a template + // Add message code $content['message'] = loadTemplate('guest_login_error_message', TRUE, $errorCode); } // END - if diff --git a/inc/modules/member/what-cash_coupon.php b/inc/modules/member/what-cash_coupon.php index 7fb6dee336..71fdec3434 100644 --- a/inc/modules/member/what-cash_coupon.php +++ b/inc/modules/member/what-cash_coupon.php @@ -57,27 +57,27 @@ if (isFormSent()) { if (isPostRequestElementSet('coupon_code')) { // Search for the coupon $result = SQL_QUERY_ESC("SELECT - c.`coupon_id`, - c.`userid`, - c.`coupon_code`, - UNIX_TIMESTAMP(d.`coupon_created`) AS `coupon_created`, - UNIX_TIMESTAMP(d.`coupon_expired`) AS `coupon_expired`, - d.`coupon_type`, - d.`total_created`, - d.`total_cashed`, - d.`points`, - d.`coupon_description` + `c`.`coupon_id`, + `c`.`userid`, + `c`.`coupon_code`, + UNIX_TIMESTAMP(`d`.`coupon_created`) AS `coupon_created`, + UNIX_TIMESTAMP(`d`.`coupon_expired`) AS `coupon_expired`, + `d`.`coupon_type`, + `d`.`total_created`, + `d`.`total_cashed`, + `d`.`points`, + `d`.`coupon_description` FROM - `{?_MYSQL_PREFIX?}_user_coupons` AS c + `{?_MYSQL_PREFIX?}_user_coupons` AS `c` INNER JOIN - `{?_MYSQL_PREFIX?}_coupon_data` AS d + `{?_MYSQL_PREFIX?}_coupon_data` AS `d` ON - c.`coupon_id`=d.`id` + `c`.`coupon_id`=`d`.`id` WHERE - c.`coupon_code`='%s' AND - c.`userid`=%s AND - c.`cashed_on` IS NULL AND - UNIX_TIMESTAMP(d.`coupon_expired`) > UNIX_TIMESTAMP() + `c`.`coupon_code`='%s' AND + `c`.`userid`=%s AND + `c`.`cashed_on` IS NULL AND + UNIX_TIMESTAMP(`d`.`coupon_expired`) > UNIX_TIMESTAMP() LIMIT 1", array( postRequestElement('coupon_code'), diff --git a/inc/modules/member/what-mydata.php b/inc/modules/member/what-mydata.php index 3b76993684..d2644c773c 100644 --- a/inc/modules/member/what-mydata.php +++ b/inc/modules/member/what-mydata.php @@ -79,8 +79,8 @@ switch ($mode) { $content['change'] = loadTemplate('member_mydata_button', TRUE); } - $content['birth_day'] = str_pad($content['birth_day'] , 2, '0', STR_PAD_LEFT); - $content['birth_month'] = str_pad($content['birth_month'], 2, '0', STR_PAD_LEFT); + $content['birth_day'] = padLeftZero($content['birth_day']); + $content['birth_month'] = padLeftZero($content['birth_month']); switch (getLanguage()) { case 'de': $content['dob'] = $content['birth_day'] . '.' . $content['birth_month'] . '.' . $content['birth_year']; break; @@ -99,7 +99,7 @@ switch ($mode) { case 'edit': // Edit data if (isExtensionActive('country', TRUE)) { // New way - $result = SQL_QUERY_ESC("SELECT + $result = SQL_QUERY_ESC('SELECT `surname`, `family`, `street_nr`, @@ -118,11 +118,11 @@ FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s -LIMIT 1", +LIMIT 1', array(getMemberId()), __FILE__, __LINE__); } else { // Old way - $result = SQL_QUERY_ESC("SELECT + $result = SQL_QUERY_ESC('SELECT `surname`, `family`, `street_nr`, @@ -141,7 +141,7 @@ FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s -LIMIT 1", +LIMIT 1', array(getMemberId()), __FILE__, __LINE__); } @@ -192,7 +192,7 @@ LIMIT 1", if (isExtensionActive('country')) { // Init WHERE statement - $whereStatement = "WHERE `is_active`='Y'"; + $whereStatement = " WHERE `is_active`='Y'"; if (isAdmin()) $whereStatement = ''; // Generate selection box diff --git a/inc/modules/member/what-order.php b/inc/modules/member/what-order.php index a1ee17e7e3..d17dc594c2 100644 --- a/inc/modules/member/what-order.php +++ b/inc/modules/member/what-order.php @@ -48,7 +48,12 @@ if ((!isExtensionActive('order')) && (!isAdmin())) { return; } // END - if -$url = ''; $id = '0'; +// Init data +$data = array( + 'id' => '0', + 'data_type' => 'TEMP', + 'url' => '', +); $ALLOWED = getUserData('receive_mails') - getUserData('mail_orders'); if (getConfig('order_max_full') == 'MAX') $ALLOWED = getUserData('receive_mails'); @@ -56,7 +61,8 @@ if (getConfig('order_max_full') == 'MAX') $ALLOWED = getUserData('receive_mails' // Now check his points amount $totalPoints = getTotalPoints(getMemberId()); -if ((isExtensionInstalledAndNewer('holiday', '0.1.3')) && (isUserDataEnabled('holiday_active'))) { +// Admin can always book +if ((isExtensionInstalledAndNewer('holiday', '0.1.3')) && (isUserDataEnabled('holiday_active')) && (!isAdmin())) { // Holiday is active! displayMessage('{--MEMBER_HOLIDAY_ORDER_NOT_POSSIBLE--}'); } elseif ((isPostRequestElementSet('frametester')) && ($ALLOWED > 0) && (postRequestElement('receiver') > 0)) { @@ -78,25 +84,23 @@ LIMIT 1", postRequestElement('url') ), __FILE__, __LINE__); - $type = 'TEMP'; $id = '0'; if (SQL_NUMROWS($result) == 1) { // Load id and mail type - // @TODO Rewrite this to SQL_FETCHARRAY() - list($id, $type) = SQL_FETCHROW($result); + $data = SQL_FETCHARRAY($result); } // END - if // Free result SQL_FREERESULT($result); - if ($type == 'TEMP') { + if ($data['data_type'] == 'TEMP') { // No entry found, so we need to check out the stats table as well... :) // We have to add that suff here, now we continue WITHOUT checking and check the text and subject against some filters - $url = ''; + $data['url'] = ''; if (getConfig('allow_url_in_text') == 'Y') { // Test submitted text against some filters (length, URLs in text etc.) if ((isInStringIgnoreCase('https://', postRequestElement('text'))) || (isInStringIgnoreCase('http://', postRequestElement('text'))) || (isInStringIgnoreCase('www', postRequestElement('text')))) { // URL found - $url = 'modules.php?module=login&what=order&code=' . getCode('URL_FOUND'); + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('URL_FOUND'); } // END - if // Remove new-line and carriage-return characters @@ -105,7 +109,7 @@ LIMIT 1", // Text length within allowed length? if (strlen($TEST) > getConfig('max_tlength')) { // Text is too long! - $url = 'modules.php?module=login&what=order&code=' . getCode('OVERLENGTH'); + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('OVERLENGTH'); } // END - if } // END - if @@ -115,26 +119,26 @@ LIMIT 1", setPostRequestElement('subject', str_replace(chr(92), '[nl]', substr(postRequestElement('subject'), 0, 200))); if ((isInStringIgnoreCase('https://', postRequestElement('subject'))) || (isInStringIgnoreCase('http://', postRequestElement('subject'))) || (isInStringIgnoreCase('www', postRequestElement('subject')))) { // URL in subject found - $url = 'modules.php?module=login&what=order&code=' . getCode('SUBJECT_URL'); + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('SUBJECT_URL'); } // END - if } // END - if // And shall I check that his URL is not in the black list? if (isUrlBlacklisted(postRequestElement('url'))) { // Create redirect-URL - $url = 'modules.php?module=login&what=order&code=' . getCode('BLIST_URL') . '&blist=' . $GLOBALS['blacklist_data'][postRequestElement('url')]['timestamp']; + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('BLIST_URL') . '&blist=' . $GLOBALS['blacklist_data'][postRequestElement('url')]['timestamp']; } // END - if // Enougth receivers entered? if ((postRequestElement('receiver') < getConfig('order_min')) && (!isAdmin())) { // Less than allowed receivers entered! - $url = 'modules.php?module=login&what=order&code=' . getCode('MORE_RECEIVERS3'); + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('MORE_RECEIVERS3'); } // END - if // Validate URL if (!isUrlValid(postRequestElement('url'))) { // URL is invalid! - $url = 'modules.php?module=login&what=order&code=' . getCode('INVALID_URL'); + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('INVALID_URL'); } // END - if // Probe for HTML extension @@ -145,7 +149,7 @@ LIMIT 1", setPostRequestElement('text', checkHtmlTags(postRequestElement('text'))); // Maybe invalid tags found? - if (!isPostRequestElementSet('text')) $url = 'modules.php?module=login&what=order&code=' . getCode('INVALID_TAGS')."&id=".$id; + if (!isPostRequestElementSet('text')) $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('INVALID_TAGS') . '&id=' . $data['id']; } else { // Remove any HTML code setPostRequestElement('text', str_replace(array('<', '>'), array('{OPEN_HTML}', '{CLOSE_HTML}'), postRequestElement('text'))); @@ -155,32 +159,32 @@ LIMIT 1", // Is mail type set? if ((!isPostRequestElementSet('mail_type')) || (postRequestElement('mail_type') < 1)) { // Not correctly set - $url = 'modules.php?module=login&what=order&code=' . getCode('NO_MAIL_TYPE'); + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('NO_MAIL_TYPE'); } // END - if } elseif (!isAdmin()) { // He has already sent a mail within a specific time - $url = 'modules.php?module=login&what=order&code=' . getCode('URL_TIME_LOCK') . '&id=' . $id; + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('URL_TIME_LOCK') . '&id=' . $data['id']; } // Still no error? - if (empty($url)) { + if (empty($data['url'])) { // Check for userids $result = SQL_QUERY_ESC("SELECT - c.`userid` + `c`.`userid` FROM `{?_MYSQL_PREFIX?}_user_cats` AS c INNER JOIN `{?_MYSQL_PREFIX?}_user_data` AS d ON - c.`userid`=d.`userid` + `c`.`userid`=`d`.`userid` WHERE - c.`cat_id`=%s AND - c.`userid` != %s AND - d.`status`='CONFIRMED' + `c`.`cat_id`=%s AND + `c`.`userid` != %s AND + `d`.`status`='CONFIRMED' " . runFilterChain('user_exclusion_sql', ' ') . " AND - d.`receive_mails` > 0 + `d`.`receive_mails` > 0 ORDER BY - d.`{?order_select?}` {?order_mode?}", + `d`.`{?order_select?}` {?order_mode?}", array( bigintval(postRequestElement('cat')), getMemberId() @@ -251,9 +255,9 @@ LIMIT 1", // Check if he has enougth points for this order and selected more than 0 receivers if (($usedPoints > 0) && ($usedPoints <= $totalPoints) && ($content['target_send'] > 0)) { // Gettings points is okay, so we can add $usedPoints later from - if ((!isValidId($id)) || ($type != 'TEMP')) { + if ((!isValidId($data['id'])) || ($data['data_type'] != 'TEMP')) { // New order - $id = '0'; + $data['id'] = '0'; if (isExtensionActive('html_mail')) { // HTML extension is active SQL_QUERY_ESC("INSERT INTO @@ -340,7 +344,7 @@ LIMIT 1", } // Get insert id - $id = SQL_INSERTID(); + $data['id'] = SQL_INSERTID(); } else { // Change current order if (isExtensionActive('html_mail')) { @@ -371,7 +375,7 @@ LIMIT 1", $content['target_send'], bigintval(postRequestElement('zip')), postRequestElement('html'), - bigintval($id) + bigintval($data['id']) ), __FILE__, __LINE__); } else { // No HTML extension is active @@ -399,31 +403,31 @@ LIMIT 1", bigintval(postRequestElement('cat')), $content['target_send'], bigintval(postRequestElement('zip')), - bigintval($id) + bigintval($data['id']) ), __FILE__, __LINE__); } } // Make sure only valid id numbers can pass - assert(isValidId($id)); + assert(isValidId($data['id'])); // Id is received so we can redirect the user, used points will be added when he send's out the mail - $url = 'modules.php?module=frametester&order=' . $id; + $data['url'] = 'modules.php?module=frametester&order=' . $data['id']; } elseif ($content['target_send'] == '0') { // Not enougth receivers found which can receive mails - $url = 'modules.php?module=login&what=order&code=' . getCode('MORE_RECEIVERS2'); + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('MORE_RECEIVERS2'); } else { // No enougth points left! - $url = 'modules.php?module=login&what=order&code=' . getCode('MORE_POINTS'); + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('MORE_POINTS'); } } else { // Ordered more mails than he can send in this category - $url = 'modules.php?module=login&what=order&code=' . getCode('NO_RECS_LEFT'); + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('NO_RECS_LEFT'); } } // END - if } elseif (postRequestElement('receiver') == '0') { // Not enougth receivers selected - $url = 'modules.php?module=login&what=order&code=' . getCode('MORE_RECEIVERS1'); + $data['url'] = 'modules.php?module=login&what=order&code=' . getCode('MORE_RECEIVERS1'); } elseif (($ALLOWED == '0') && (getConfig('order_max_full') == 'ORDER')) { // No more mail orders allowed displayMessage('{--MEMBER_ORDER_ALLOWED_EXHAUSTED--}'); @@ -482,20 +486,20 @@ ORDER BY if (isExtensionInstalledAndNewer('holiday', '0.1.3')) { // Check user's holiday status $result_holiday = SQL_QUERY_ESC("SELECT - COUNT(d.`userid`) AS `cnt` + COUNT(`d`.`userid`) AS `cnt` FROM `{?_MYSQL_PREFIX?}_user_data` AS d LEFT JOIN `{?_MYSQL_PREFIX?}_user_holidays` AS h ON - d.`userid`=h.`userid` + `d`.`userid`=`h`.`userid` WHERE - d.`userid`=%s AND - d.`receive_mails` > 0 AND - d.`status`='CONFIRMED' AND - d.`holiday_active`='Y' AND - h.`holiday_start` < UNIX_TIMESTAMP() AND - h.`holiday_end` > UNIX_TIMESTAMP() + `d`.`userid`=%s AND + `d`.`receive_mails` > 0 AND + `d`.`status`='CONFIRMED' AND + `d`.`holiday_active`='Y' AND + `h`.`holiday_start` < UNIX_TIMESTAMP() AND + `h`.`holiday_end` > UNIX_TIMESTAMP() LIMIT 1", array(bigintval($userid)), __FILE__, __LINE__); @@ -542,7 +546,7 @@ LIMIT 1", // Now we need to load the mail types... $result = SQL_QUERY("SELECT `id`, `price`, `payment`, `mail_title` FROM `{?_MYSQL_PREFIX?}_payments` ORDER BY `payment` ASC", __FILE__, __LINE__); - $types = array(); + $payments = array(); if (!SQL_HASZERONUMS($result)) { // Is the error code set? if (isGetRequestElementSet('code')) { @@ -551,8 +555,8 @@ LIMIT 1", } // END - if // Load all email types... - while ($type = SQL_FETCHARRAY($result)) { - array_push($types, $type); + while ($payment = SQL_FETCHARRAY($result)) { + array_push($payments, $payment); } // END - while // Free memory @@ -633,12 +637,12 @@ LIMIT 1", // Mail type $content['type_selection'] = ''; - foreach ($types as $key => $value) { + foreach ($payments as $key => $value) { if (is_array($value)) { // Output option line - $content['type_selection'] .= ' '; } // END - for break; diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 6c394da6cd..c936142288 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -3410,5 +3410,11 @@ function shift_array (&$array, $value, $key = '0') { array_shift($array); } +// Wrapper for str_pad() with left padding zeros +function padLeftZero ($str, $amount = 2) { + // Pad it + return str_pad($str, $amount, '0', STR_PAD_LEFT) +} + // [EOF] ?>