function jazyk($str1,$str2,$lang = NULL){
if(strcmp($_SESSION['lang'],'pol')==0)return $str1;else return $str2;
}
function naglowek($str1,$str2,$lang = NULL,$extra = NULL){
print '
'.jazyk($str1,$str2).$extra.'
';
}
function send_mail($do, $temat, $wiadomosc, $naglowki = NULL) {
if($wynik = mail ($do, $temat, $wiadomosc, $naglowki)) {
return true;
}
}
function error_display ($txt) {
print '
'
.jazyk('Błąd','Error').
'
'
.$txt.
'
';
}
function wroc () {
return ' '.jazyk("Wróć do sklepu","Continue shopping").' ';
}
function litery($q, $lang = NULL) {
if(!empty($lang)) $lang = " and lang='".$_SESSION['lang']."'";
if($q == "pictures") $link = "gallery"; else $link = $q;
print '';
$res = mysql_query("select id from ".$q." where artist regexp '^[0-9].*$'".$lang);
if(mysql_num_rows($res) > 0) {
print '
# ';
}
for($i=65;$i<91;$i++) {
if(mysql_num_rows(mysql_query("select id from $q where artist regexp '^[[.\\..][:space:]]*".chr($i).".*$'$lang"))>0) {
print '
'.chr($i).' ';
}
}
print '
';
}
function DBQuery( $q , $show = NULL) {
if(!empty($show)) {
print " ".$q." ";
}
$my_result = mysql_query($q) or die("ERROR: Could not run query ".mysql_error());
$array = explode(" ",$q);
$cnt = count( $array );
for( $i=0 ; $i<$cnt ; $i++ ) {
if(preg_match("/delete/i",$array[$i]))
$table_name = $array[$i+2];
}
if(isset($table_name)) {
$query_opt = "optimize table $table_name";
if(!mysql_query($query_opt)) print "Failed optimizing table ".mysql_error();
}
return $my_result;
}
function login($login, $pass)
{
list($pass_confirm) = mysql_fetch_row( DBQuery("select pass from users where email='$login'"));
if (md5($pass) == $pass_confirm) {
$_SESSION['kto'] = $login;
} else {
global $login_error;
$login_error = jazyk("NIEPOPRAWNY LOGIN/HASŁO","LOGIN/PASS INCORRECT");
}
}
function is_email_correct($email) // troche se już ma, ciekawe czy chodzi
{
if(!preg_match( "/^([[:alnum:]\._-])+@([[:alnum:]_-]+\.[[:alpha:]]+)*$/" , $email)) {
return 0;
}
$email = split( "@" , $email );
if(!checkdnsrr( $email[1] )) {
return 0;
}
return 1;
}
function user_input_correct($fname) //zbiorcza, bo co sie bede jebał...
{
if(empty($_POST[$fname])) {
return false;
}
else if($fname == "email") {
if(!is_email_correct($_POST['email'])) {
unset($_POST['email']);
return false;
}
}
else if($fname == "postcode") {
if($_SESSION['lang'] == "pol") { // a może $lang ?? a może jest w sesji... ??
if(!preg_match('/^\d{2}-\d{3}$/', $_POST[$fname])) {
unset($_POST[$fname]);
return false;
}
}
if($_SESSION['lang'] == "eng") {
if(!preg_match(EN_PC_PATTERN, $_POST[$fname])) {
unset($_POST[$fname]);
return false;
}
}
}
else if($fname == "telefon") { //nowe nr telefonu są alfanumeryczne... np. 616szatan, no i czy kierunkowy stacjonarny z prefixem?
if(!preg_match('/[(\d{7,10})|\d{9}]/', $_POST[$fname])) { //stac, kom, a jak bedzie wewnętrzny? :-)
unset($_POST[$fname]);
return false;
}
}
else if($fname == "postcode") {
if(!preg_match('/[(\d{7,12})|\d{9}]/', $_POST[$fname])) { //same cyferki?
unset($_POST[$fname]);
return false;
}
}
else if(!empty($_POST['pass1']) && !empty($_POST['pass2'])) {
if($_POST['pass1'] != $_POST['pass2']) {
$_POST['pass1'] = $_POST['pass2'] = NULL;
return false;
}
}
return true;
}
function check_field($field,$req_fields)
{
return (in_array($field, $req_fields)
? (empty($_POST[$field]) ? "#990000" : "#272626" )
: "#272626");
}
function check_post(&$validd, $field)
{
if(!empty($_POST[$field])) {
return ($validd[$field] = $_POST[$field]);
}
return NULL;
}
function get_db_fields(&$df)
{
$r = mysql_query("show columns from users");
$r2 = mysql_query("select * from users limit 1");
$i = 0;
while($arr = mysql_fetch_array($r,MYSQL_NUM)) {
$df[$arr[0]] = mysql_field_len($r2, $i);
$i++;
}
}
function field_len($dbfields, $name)
{
return $dbfields[$name];
}
function print_form($arr, $req_fields, $dbfields, $lang)
{
foreach($arr as $fname=>$inputname)
{
if(strstr($fname , "_"))
{
$fname = str_replace("_","",$fname);
$gwiazdka="* ";
}
else {$gwiazdka = "";
}
print'
'.$gwiazdka.jazyk($inputname[0],$inputname[1],$lang).'
';
}
}
function user_is_registered($email)
{
if(mysql_num_rows(DBQuery("select email from users where email = '$email'"))){
return true;
} else {
return false;
}
}
function rewrite_url_params($garr , $without_arr = array())
{
$url = "";
foreach($garr as $k=>$v) {
if(!in_array($k, $without_arr)) {
$url .= "$k=$v&";
}
}
return $url;
}
function select_url_params($arr , $keys)
{
$url = "";
foreach($arr as $k=>$v) {
$url .= (in_array($k, $keys) ? "$k=$v&" : '');
}
return $url;
}
function pages_display($liczba, $ilosc, $title = '') {
$lang = $_SESSION['lang'];
$stekst['pol']=array('strona','poprzednia','następna','pierwsza','ostatnia','z','Nie znaleziono wyników w bazie.');
$stekst['eng']=array('page','previous','next','first','last','of','No matches found in database.');
if($liczba>0) {
$ilosc_stron = ceil($liczba/$ilosc);
$ref = '?'.rewrite_url_params($_GET,array("str"));
if(!empty($_GET['str'])) {
$gp = $_GET['str'];
if($_GET['str'] < 1) {
$gp = 1;
}
if ($_GET['str'] > $ilosc_stron) {
$gp = $ilosc_stron;
}
} else {
$gp = 1;
}
$strony = "$title ".$stekst[$lang][0]." ".$gp." (".$stekst[$lang][5]." ".(ceil($liczba/$ilosc)).") ";
if($ilosc_stron > 1) {
if($gp>1) {
$ig = $gp-1;
if($ig<1) {
$ig = 1;
}
$strony.="[".$stekst[$lang][3]."] [".$stekst[$lang][1]."] ";
}
if($gp<6) {
$ip=5;
} else {
$ip=$gp;
}
if($gp>ceil($liczba/$ilosc)-4) {
$ip=ceil($liczba/$ilosc)-3;
}
$ipp = $ip-4;
if($ipp<1) {
$ipp = 1;
}
for($ig=$ipp;($ig < $ipp + 9 && $ig < ceil($liczba/$ilosc)+1);$ig++) {
if($ig!=$gp) {
$strony.=" $ig ";
} else {
$strony.=" $ig ";
}
}
if($gpceil($liczba/$ilosc)) {
$ig=ceil($liczba/$ilosc);
}
$strony.="[".$stekst[$lang][2]."] [".$stekst[$lang][4]."] ";
}
}
$start_query_limit=($gp-1)*$ilosc;
if($liczba-$start_query_limit<$ilosc) {
$end_query_limit=$liczba-$start_query_limit;
} else {
$end_query_limit=$ilosc;
}
} else {
$strony=$stekst[$lang][6];$start_query_limit=0;$end_query_limit=0;
}
return array($strony,$start_query_limit,$end_query_limit);
}
function check_url($url, $mode = 0, $end = 1) {
if(!empty($url)) {
$url = preg_replace('/^[a-z]*:\/\//', "", strtolower($url));
$adres_url = array();
$adres_url[0] = '([\w\.-]+)\.(\w{2,6}){1}';
$adres_url[1] = '(\/[\w-]+)*(\/){0,1}';
$adres_url[2] = '((\w|\.|-)+\.\w{1,6}){0,1}';
$adres_url[3] = '(\?((\w+={0,1}\w*)&{0,1})*)*';
$check_url = '/^';
for($i = 0; $i <= $mode; $i++) {
$check_url .= $adres_url[$i];
}
if($end > 0) {
$check_url .= '$';
}
$check_url .= '/';
if(!preg_match($check_url, $url)) {
return false;
} else {
return $url;
}
}
}
?>