protected function _post_args($key, $type = ARGS_TYPE_STRING, $default = '', $params = array()) { $value = ''; $post_default = ''; $key_exist = array_key_exists($key, $_POST); $override = array_key_exists('override', $params) ? $params['override'] : FALSE; $entities_to_ascii = array_key_exists('entities_to_ascii', $params) ? $params['entities_to_ascii'] : FALSE; $gtzero = array_key_exists('gtzero', $params) ? $params['gtzero'] : TRUE; switch ($type) { case ARGS_TYPE_STRING: $post_default = $override ? $default : ''; $value = $key_exist ? $this->input->post($key, TRUE) ? $this->input->post($key, TRUE) : $post_default : $default; if ($entities_to_ascii) { $value = entities_to_ascii($value); } break; case ARGS_TYPE_INT: $default = validate_integer($default) ? to_int($default) : 0; $post_default = $override ? $default : 0; $value = $key_exist ? ($value = $this->input->post($key)) && gtzero_integer($value) ? to_int($value) : $post_default : $default; break; case ARGS_TYPE_TRUE_FALSE: $default = validate_integer($default) ? gtzero_integer($default) ? TRUE : FALSE : FALSE; $post_default = $override ? $default : FALSE; $value = $key_exist ? ($value = $this->input->post($key)) && ($gtzero && gtzero_integer($value) || !$gtzero && validate_integer($value)) ? TRUE : $post_default : $default; break; case ARGS_TYPE_ARRAY: $value = $key_exist ? ($value = $this->input->post($key)) && is_array($value) ? $value : array() : (is_array($default) ? $default : array()); break; case ARGS_TYPE_DECIMAL: $default = gtzero_decimal($default) ? to_float($default) : 0; $post_default = $override ? $default : 0; $value = $key_exist ? ($value = $this->input->post($key)) && gtzero_decimal($value) ? to_float($value) : $post_default : $default; break; case ARGS_TYPE_DATE: $default = validate_date($default) ? $default : ''; $post_default = $override ? $default : ''; $value = $key_exist ? ($value = $this->input->post($key)) && validate_date($value) ? $value : $post_default : $default; break; case ARGS_TYPE_DATETIME: $default = validate_datetime($default) ? $default : ''; $post_default = $override ? $default : ''; $value = $key_exist ? ($value = $this->input->post($key)) && validate_date($value) ? $value : $post_default : $default; break; default: $post_default = $override ? $default : ''; $value = $key_exist ? $this->input->post($key, TRUE) ? $this->input->post($key, TRUE) : $post_default : $default; break; } unset($post_default); return $value; }
/** * Método que pone la coma a los decimales * @param unknown_type $valor */ function to_spanish_float($valor) { // Obtengo las posiciones de los signos de puntuacion $coma = strpos($valor, ","); $punto = strpos($valor, "."); // si tiene punto y está a la izquierda de la coma, eliminamos el punto porque es de miles if ($coma > -1) { // 22,000.00 if ($coma < $punto) { $valor = str_replace(",", "", $valor); // replace '.' with '' } } $valor = to_float($valor); $valor = str_replace(",", ".", $valor); // replace ',' with '.' $formato_americano = sprintf('%.2f', $valor); return str_replace(".", ",", $formato_americano); }
<?php require 'test-more.php'; require '../../cacti/scripts/ss_get_by_ssh.php'; $debug = true; is(to_float('74900191315.1170664159 dollars per hour'), '74900191315.1170664159', 'to_float 74900191315.1170664159'); /* This function was used for diskstats, but then discarded # ============================================================================ # Divide $left by $right as accurately as possible with reasonable effort. # ============================================================================ function big_divide ($left, $right) { if ( function_exists("bcdiv") ) { debug(array('bcdiv', $left, $right, 6)); return rtrim(bcdiv( $left, $right, 6 ), '0'); } else { debug(array('sprintf', $left, $right)); return rtrim(sprintf(".0f", $left / $right), '0'); } } is( big_divide('500000', '128.193474'), '3900.354553', 'big_divide 500000.0/128.193474' ); */ is(extract_desired(array('items' => 'a1,a2'), 'a1:45 b2:90 a3:0'), 'a1:45', 'extract_desired');
/** Sjekk for IP-ban */ private function check_ip_ban() { global $_base; // sjekk for IP-ban if ($_SERVER['REQUEST_METHOD'] == "CRON") { return; } // allerede sjekket og OK? if (cache::fetch("ip_ok_" . $_SERVER['REMOTE_ADDR'])) { return; } $ip = \Kofradia\DB::quote(to_float(ip2long($_SERVER['REMOTE_ADDR']))); $time = time(); $result = \Kofradia\DB::get()->query("SELECT bi_ip_start, bi_ip_end, bi_time_start, bi_time_end, bi_reason FROM ban_ip WHERE {$ip} BETWEEN bi_ip_start AND bi_ip_end AND IF(ISNULL(bi_time_end), {$time} >= bi_time_start, {$time} BETWEEN bi_time_start AND bi_time_end) ORDER BY bi_ip_end - bi_ip_start"); // fant ingen IP-ban oppføring if ($result->rowCount() == 0) { // sjekk om vi venter en kommende IP-ban $result = \Kofradia\DB::get()->query("SELECT bi_time_start FROM ban_ip WHERE {$ip} BETWEEN bi_ip_start AND bi_ip_end AND {$time} <= bi_time_start ORDER BY bi_time_start LIMIT 1"); if ($result->rowCount() > 0) { $next = $result->fetchColumn(0); // marker som ok for tiden før IP-ban starter cache::store("ip_ok_" . $_SERVER['REMOTE_ADDR'], true, $next - $time); return; } // marker som ok cache::store("ip_ok_" . $_SERVER['REMOTE_ADDR'], true); return; } // utestengt via IP // mer enn 1 uke vil vise som ubestemt tid // sett opp grunner $ban_end = 0; $reasons = array(); while ($row = $result->fetch()) { if ($ban_end !== false && empty($row['bi_time_end'])) { $ban_end = false; } elseif ($ban_end !== false && $row['bi_time_end'] > $ban_end) { $ban_end = $row['bi_time_end']; } // sett opp IP-adresse (range?) $ip = '<b>' . long2ip($row['bi_ip_start']); if ($row['bi_ip_start'] != $row['bi_ip_end']) { // range $ip .= ' - ' . long2ip($row['bi_ip_end']); } $ip .= '</b>'; // grunn oppgitt? if (empty($row['bi_reason'])) { // nei $reason = 'Grunn ikke oppgitt.'; } else { // ja $reason = game::bb_to_html($row['bi_reason']); } #$reasons[] = '<p>'.$ip.': '.$reason.'</p>'; $reasons[] = '<fieldset><legend>' . $ip . '</legend><p>' . $reason . '</p></fieldset>'; } // "jukse" til ubestemt tid? #if ($ban_end !== false && $ban_end > time()+604800) $ban_end = false; #$timeinfo = $ban_end === false ? '<p>Din IP-adresse er utestengt på ubestemt tid.</p>' : '<p>Din IP-adresse er utestengt til <b>'.$_base->date->get($ban_end)->format(date::FORMAT_SEC).'</b>.</p>'; putlog("ABUSE", "%c8%bIP-Blokk:%b%c %u{$_SERVER['REMOTE_ADDR']}%u - {$_SERVER['HTTP_USER_AGENT']}"); // send feilmelding etc header("HTTP/1.0 403 Forbidden"); echo '<!DOCTYPE html> <html lang="no"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="author" content="Henrik Steen; http://www.henrist.net" /> <title>IP-blokkering</title> <style type="text/css"> <!-- body { font-family: tahoma; font-size: 14px; } h1 { font-size: 23px; } .hsws { color: #CCCCCC; font-size: 12px; } .subtitle { font-size: 16px; font-weight: bold; } fieldset { margin: 10px 0 } fieldset p { margin: 8px 3px 5px; padding: 0 } legend { color: #FFFFFF; background-color: #222222; padding: 3px 5px; border: 3px solid #FFFFFF; border-width: 0 3px } --> </style> </head> <body> <h1>IP-blokkering</h1> <p>Din IP-adresse er blokkert/utestengt.</p> <p>IP-adresse og eventuelle grunner:</p> ' . implode("\n", $reasons) . ' <p class="hsws"><a href="http://hsw.no/">hsw.no</a></p> </body> </html>'; die; }
<?php require "config.php"; global $__server; access::need("mod"); ess::$b->page->add_title("IP-ban"); if (isset($_POST['ip'])) { $ip = ip2long(postval("ip")); if (!$ip) { ess::$b->page->add_message("Ugyldig IP-adresse.", "error"); } else { $ip = to_float($ip); $ip_str = long2ip($ip); $time = intval(postval('time')); $begrunnelse = trim(postval('begrunnelse')); $interninfo = trim(postval('interninfo')); if (isset($_POST['confirm'])) { // legg til oppføring \Kofradia\DB::get()->exec("INSERT INTO ban_ip SET bi_ip_start = {$ip}, bi_ip_end = {$ip}, bi_time_start = " . time() . ", bi_time_end = " . ($time == 0 ? 'NULL' : $time + time()) . ", bi_reason = " . \Kofradia\DB::quote($begrunnelse) . ", bi_info = " . \Kofradia\DB::quote($interninfo)); // fjern mulig cache cache::delete("ip_ok_{$ip_str}"); // IRC melding putlog("CREWCHAN", "%bNY IP-BAN:%b " . login::$user->player->data['up_name'] . " la til IP-ban for {$ip_str} " . ess::$s['spath'] . "/admin/brukere/ip_sessions?ip={$ip_str}"); ess::$b->page->add_message('IP-adressen ' . $ip_str . ' er nå blokkert/utestengt.'); redirect::handle(); } echo ' <h1>IP-ban</h1> <p align="center" class="dark"> Du har valgt følgende info: </p>
return $options; } function to_float($sum) { if (strpos($sum, ".")) { $sum = round($sum, 2); } else { $sum = $sum . ".0"; } return $sum; } $sys_options = billing_init_system_options($LINK); $login = $sys_options['onpay_login']; $secret = $sys_options['onpay_secret']; $curency = $sys_options['onpay_ccy']; $url_result = $sys_options['onpay_url_success']; $fio2 = $uid; $description = $uid; $text = iconv("CP1251", "UTF-8", "Пополнить счет на сумму: " . $summa . " " . $curency); $text2 = iconv("CP1251", "UTF-8", "Пополнить"); $title = iconv("CP1251", "UTF-8", "Пополнение OnPay"); $text3 = iconv("CP1251", "UTF-8", "Оплатить в "); $text4 = iconv("CP1251", "UTF-8", "Вернуться"); $fio = iconv("CP1251", "UTF-8", $fio); mysql_query("INSERT INTO " . BILL_ONPAY_TABLE . " (`payid` ,`uid` ,`order_amount` ,`order_currency` ,`type` ,`comment` ,`paymentDateTime` ,`onpay_id`,`user_phone` ) VALUES (NULL, '" . $uid . "','" . $summa . "','" . $curency . "','','" . $uid . "',CURRENT_TIMESTAMP,'',''); ", $LINK) or die(mysql_error($LINK)); $tranzakt_onpay_payid = mysql_insert_id(); $md5check = md5("fix;" . to_float($sum) . ";" . $curency . ";" . $tranzakt_onpay_payid . ";yes;" . $secret); $utl_text = "pay_mode=fix&price={$sum}¤cy={$curency}&pay_for={$tranzakt_onpay_payid}&convert=yes&md5={$md5check}&url_success=" . $url_result; $url = "http://secure.onpay.ru/pay/" . $login . "?" . $utl_text; header('Location: ' . stripslashes($url)); mysql_close($LINK);
<?php // implicitly weak mode code function to_int(int &$x) { } function to_float(float &$x) { } function to_string(string &$x) { } function to_bool(bool &$x) { } $x = 1.0; var_dump($x); to_int($x); // because $x is by-reference, the weak type hint converts it var_dump($x); to_float($x); var_dump($x); to_string($x); var_dump($x); to_bool($x); var_dump($x);
function process_first_step() { $sum = $_REQUEST['sum']; $output = ''; $err = ''; if (is_numeric($sum)) { //проверяем являются ли введенные данные числом $result = data_create_operation($sum); } else { $err = 'В поле сумма не числовое значение'; } //если данные в базу поместились, идем дальше. if ($result) { $number = mysql_insert_id(); //определяем id записи в бд $sumformd5 = to_float($sum); //преобразуем число к числу с плавающей точкой //создаем хеш данных для проверки безопасности $md5check = md5("fix;{$sumformd5};RUR;{$number};yes;" . get_constant('private_code')); //создаем строчку для запроса $url = "http://secure.onpay.ru/pay/" . get_constant('onpay_login') . "?" . get_iframe_url_params($number, $sum, $md5check); //вывод формы onpay с заданными параметрами $output = '<iframe src="' . $url . '" width="300" height="500" frameborder=no scrolling=no></iframe> <form method=post action="' . $_SERVER['HTTP_REFERER'] . '"><input type="submit" value="Вернуться"></form>'; } else { $err = empty($err) ? mysql_error() : $err; $output = "onpay script: Ошибка сохранения данных. (" . $err . ")"; } return $output; }
public function details($user_id) { $uc = "(SELECT user_id,company_id FROM user_company UNION SELECT clu.user_id,cu.company_id FROM user_clients clu INNER JOIN clients cu ON clu.client_id = cu.id) uc"; $this->db->select('u.id, u.username, u.email, u.first_name, u.last_name, u.avatar, u.phone, g.id as group_id, u.postcode, u.gmt_offset, u.active, u.avatar, u.workhours, u.gps_device_id, u.hourly_rate, u.latitude, u.longitude, u.is_deleted')->select("CONCAT(u.first_name,' ', u.last_name) AS full_name", FALSE)->select('g.name as group_name, g.description as group_description, g.id as group_id')->select('com.id AS company_id, com.name AS company_name')->from('users u')->join('users_groups ug', 'u.id = ug.user_id', 'LEFT')->join('groups g', 'ug.group_id = g.id', 'LEFT')->join($uc, 'u.id=uc.user_id', 'LEFT')->join('companies com', 'uc.company_id=com.id', 'LEFT')->where('u.id', to_int($user_id))->group_by('u.id'); $user_info = $this->db->get()->row(); $user_info->id = to_int($user_info->id); $user_info->group_id = to_int($user_info->group_id); $user_info->hourly_rate = to_float($user_info->hourly_rate); $user_info->latitude = !is_null($user_info->latitude) ? $user_info->latitude : ''; $user_info->longitude = !is_null($user_info->longitude) ? $user_info->longitude : ''; //$user_info->region_name = !is_null($user_info->region_name) ? $user_info->region_name : ''; $user_info->avatar = !is_null($user_info->avatar) ? $user_info->avatar : ''; $user_info->active = to_int($user_info->active); $user_info->hourly_rate = to_float($user_info->hourly_rate); $user_info->is_deleted = to_float($user_info->is_deleted); $user_info->{'company_id'} = 0; $user_info->{'client_ids'} = array(); if (_has_company_group_access($user_info->group_id)) { $user_info->{'company_id'} = $this->user_company_by_user_id($user_info->id); } if ($user_info->group_id == GROUP_CLIENT_USER) { $clients = array(); if (($clients = $this->get_client_by_user_id($user_info->id)) != FALSE) { $user_info->{'client_ids'} = $clients; } unset($clients); } return $user_info; }
function gtzero_decimal($value) { return ($value = to_float($value)) && $value > 0 ? TRUE : FALSE; }