SetCreator(PDF_CREATOR); $pdf->SetFillColor(255, 255, 255); $pdf->setLanguageArray("pl"); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $sprzedawca = $baza->unserialize( $dane['sprzedawca'] ) ; $kupujacy = $baza->unserialize( $dane['kupujacy'] ) ; $pdf->AddPage(); $pdf->SetFont('freesans' , 'B' , 14); $data = $dane['data'] ; //date( 'Y-m-d' ) ; $data2 = date( 'Y-m-d', strtotime( $dane['data'].' + 7 days' )) ; if( file_exists( 'img/faktura.png' )) { $pdf->Image('img/faktura.png', 10, 10, '', '', 'PNG', '', '', false, 150, '', false, false, 0, false, false, false); // $pdf->Ln(); } elseif( file_exists( 'img/faktura.jpg' )) { //$img = getimagesize( 'img/faktura.jpg' ) ; $pdf->Image('img/faktura.jpg', 10, 10, '', '', 'JPEG', '', '', false, 150, '', false, false, 0, false, false, false); // $pdf->Ln(); } $row = $dane['rok'] - 1 ; $numer = $dane['numer'] ; if( $dane['typ'] == 'dodanie' ) $tytulem = $config['fvat_dodanie'] ; //'Dodanie wpisu do katalogu firm aaa lll vvv' ; else $tytulem = $config['fvat_promo'] ; //'Wykupienie pakietu promocyjnego: '.$dane['typ'] ; $dane['numer'] = $numer.'/'.$dane['rok'].'/'.$config['fvat_nazwa'] ; //$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', 'Faktura nr '.$config['faktura_numer'], $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true); // $pdf->MultiCell(250, 5, "\r\n".'Faktura nr '.$dane['numer']."\r\n\r\n", 0, 'C', 1, 1, '', '', true, 0, false, true, 40, 'T'); $pdf->SetFont('freesans' , '' , 10); $pdf->MultiCell(120, 5, 'Data wystawienia: '.$data, 0, 'R', 1, 0, '', '', true, 0, false, true, 40, 'T'); $pdf->MultiCell(60, 5, 'Data sprzedaży: '.$data, 0, 'R', 1, 1, '', '', true, 0, false, true, 40, 'T'); $pdf->MultiCell(120, 5, 'Data płatości: '.$data2, 0, 'R', 1, 0, '', '', true, 0, false, true, 40, 'T'); $pdf->MultiCell(60, 5, 'Metoda płatości: przelew', 0, 'R', 1, 1, '', '', true, 0, false, true, 40, 'T'); $pdf->Ln(); $pdf->SetFont('freesans' , 'B' , 14); $pdf->MultiCell(90, 5, 'Sprzedawca', 0, 'J', 1, 0, '', '', true, 0, false, true, 40, 'T'); $pdf->MultiCell(90, 5, 'Nabywca', 0, 'J', 1, 1, '', '', true, 0, false, true, 40, 'T'); $sprzedawca_dane = $sprzedawca['nazwa']."\r\n".$sprzedawca['adres']."\r\n".$sprzedawca['nip']."\r\n".$sprzedawca['konto'] ; $kupujacy_dane = $kupujacy['nazwa']."\r\n".$kupujacy['adres']."\r\n".$kupujacy['nip'] ; $pdf->SetFont('freesans' , '' , 12); $pdf->MultiCell(90, 5, $sprzedawca_dane, 0, 'J', 1, 0, '', '', true, 0, false, true, 40, 'T'); $pdf->MultiCell(90, 5, $kupujacy_dane, 0, 'J', 1, 1, '', '', true, 0, false, true, 40, 'T'); $pdf->Ln() ; $pdf->SetFont('freesans' , 'B' , 14); $pdf->MultiCell(180,7,"Oryginał" , 0 , "R" , 0,1); $pdf->SetFont('freesans' , '' , 10); // MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0) // set cell padding $pdf->setCellPaddings(1, 1, 1, 1); // set cell margins $pdf->setCellMargins(0, 0, 0, 0); $pdf->MultiCell(10,7,"Lp", 1, "C", 0,0); $pdf->MultiCell(50,7,"Nazwa" , 1 , "C" , 0,0,NULL,NULL,1); $pdf->MultiCell(10,7,"Jedn" , 1 , "C" , 0,0); $pdf->MultiCell(10,7,"Ilość" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Cena netto" , 1 , "C" , 0,0); $pdf->MultiCell(16,7,"Stawka" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Wartość netto" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Wartość brutto" , 1 , "C" , 0,1); $netto = round(($dane['kwota']*100)/(100+$config['fvat_vat']),2) ; $vat = $dane['kwota'] - $netto ; $pdf->MultiCell(10,7,"1", 1, "C", 0,0); $pdf->MultiCell(50, 7, $tytulem, 1, 'C', 0, 0, null, null, true, 0, false, true, 7, 'M', true); //$pdf->MultiCell(50,7,$tytulem , 1 , "C" , 0,0,NULL,NULL,1); $pdf->MultiCell(10,7,"szt." , 1 , "C" , 0,0); $pdf->MultiCell(10,7,"1" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,cena_4($netto) , 1 , "C" , 0,0); $pdf->MultiCell(16,7,$config['fvat_vat']."%" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,cena_4($netto) , 1 , "C" , 0,0); $pdf->MultiCell(30,7,cena_4($dane['kwota']) , 1 , "C" , 0,1); $pdf->Ln() ; $pdf->MultiCell(30,7,"Stawka VAT", 1, "C", 0,0); $pdf->MultiCell(30,7,"Wartość netto" , 1 , "C" , 0,0,NULL,NULL,1); $pdf->MultiCell(30,7,"Kwota VAT" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Wartość brutto" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Zapłacono", 0, "R", 0,0); $pdf->MultiCell(30,7,cena_4($dane['kwota']).' PLN' , 0 , "R" , 0,1); $pdf->MultiCell(30,7,$config['fvat_vat']."%", 1, "C", 0,0); $pdf->MultiCell(30,7,cena_4($netto) , 1 , "C" , 0,0,NULL,NULL,1); $pdf->MultiCell(30,7,cena_4($vat) , 1 , "C" , 0,0); $pdf->MultiCell(30,7,cena_4($dane['kwota']) , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Do zapłaty" , 0 , "R" , 0,0); $pdf->MultiCell(30,7,cena_4( 0 ).' PLN' , 0 , "R" , 0,1); $pdf->MultiCell(30,7,"Razem", 1, "C", 0,0); $pdf->MultiCell(30,7,cena_4($netto) , 1 , "C" , 0,0,NULL,NULL,1); $pdf->MultiCell(30,7,cena_4($vat) , 1 , "C" , 0,0); $pdf->MultiCell(30,7,cena_4($dane['kwota']) , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Razem" , 0 , "R" , 0,0); $pdf->MultiCell(30,7,cena_4($dane['kwota']).' PLN', 0 , "R" , 0,1); $razem_brutto = round( $dane['kwota'], 2 ) ; $grosze = round(($razem_brutto-(int)floor($razem_brutto))*100); //echo (($razem_brutto-floor( $razem_brutto ))*100) ; //echo (string)floor( ($razem_brutto-floor($razem_brutto))*100) ; $slownie = str_replace(range(0,9),array("zero*","jed*","dwa*","trzy*","czt*","pie*","sze*","sie*","osi*","dzie*"),(string)floor($razem_brutto))."zł*".str_replace(range(0,9),array("zero*","jed*","dwa*","trzy*","czt*","pie*","sze*","sie*","osi*","dzie*"),(string)(($grosze)))."gr" ; $pdf->MultiCell(180,7,"Słownie" , 0 , "R" , 0,1); $pdf->MultiCell(180,7,$slownie, 0 , "R" , 0,1); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->SetFont('freesans' , '' , 9); $pdf->Multicell( 90, 7, 'Imię i nazwisko osoby uprawnionej'."\r\n".'do wystawiania faktury', 0, 'C', 0, 0 ) ; $pdf->Multicell( 90, 7, 'Imię i nazwisko osoby uprawnionej'."\r\n".'do odbioru faktury', 0, 'C', 0, 1 ) ; $pdf->AddPage(); $pdf->SetFont('freesans' , 'B' , 14); $data = date( 'Y-m-d' ) ; $data2 = date( 'Y-m-d', strtotime( 'Today + 7 days' )) ; if( file_exists( 'img/faktura.png' )) { $pdf->Image('img/faktura.png', 10, 10, '', '', 'PNG', '', '', false, 150, '', false, false, 0, false, false, false); // $pdf->Ln(); } elseif( file_exists( 'img/faktura.jpg' )) { //$img = getimagesize( 'img/faktura.jpg' ) ; $pdf->Image('img/faktura.jpg', 10, 10, '', '', 'JPEG', '', '', false, 150, '', false, false, 0, false, false, false); // $pdf->Ln(); } $pdf->MultiCell(250, 5, "\r\n".'Faktura nr '.$dane['numer']."\r\n\r\n", 0, 'C', 1, 1, '', '', true, 0, false, true, 40, 'T'); $pdf->SetFont('freesans' , '' , 10); $pdf->MultiCell(120, 5, 'Data wystawienia: '.$data, 0, 'R', 1, 0, '', '', true, 0, false, true, 40, 'T'); $pdf->MultiCell(60, 5, 'Data sprzedaży: '.$data, 0, 'R', 1, 1, '', '', true, 0, false, true, 40, 'T'); $pdf->MultiCell(120, 5, 'Data płatości: '.$data2, 0, 'R', 1, 0, '', '', true, 0, false, true, 40, 'T'); $pdf->MultiCell(60, 5, 'Metoda płatości: przelew', 0, 'R', 1, 1, '', '', true, 0, false, true, 40, 'T'); $pdf->Ln(); $pdf->SetFont('freesans' , 'B' , 14); $pdf->MultiCell(90, 5, 'Sprzedawca', 0, 'J', 1, 0, '', '', true, 0, false, true, 40, 'T'); $pdf->MultiCell(90, 5, 'Nabywca', 0, 'J', 1, 1, '', '', true, 0, false, true, 40, 'T'); $sprzedawca_dane = $sprzedawca['nazwa']."\r\n".$sprzedawca['adres']."\r\n".$sprzedawca['nip']."\r\n".$sprzedawca['konto'] ; $kupujacy_dane = $kupujacy['nazwa']."\r\n".$kupujacy['adres']."\r\n".$kupujacy['nip'] ; $pdf->SetFont('freesans' , '' , 12); $pdf->MultiCell(90, 5, $sprzedawca_dane, 0, 'J', 1, 0, '', '', true, 0, false, true, 40, 'T'); $pdf->MultiCell(90, 5, $kupujacy_dane, 0, 'J', 1, 1, '', '', true, 0, false, true, 40, 'T'); $pdf->Ln() ; $pdf->SetFont('freesans' , 'B' , 14); $pdf->MultiCell(180,7,"Kopia" , 0 , "R" , 0,1); $pdf->SetFont('freesans' , '' , 10); // MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0) // set cell padding $pdf->setCellPaddings(1, 1, 1, 1); // set cell margins $pdf->setCellMargins(0, 0, 0, 0); $pdf->MultiCell(10,7,"Lp", 1, "C", 0,0); $pdf->MultiCell(50,7,"Nazwa" , 1 , "C" , 0,0,NULL,NULL,1); $pdf->MultiCell(10,7,"Jedn" , 1 , "C" , 0,0); $pdf->MultiCell(10,7,"Ilość" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Cena netto" , 1 , "C" , 0,0); $pdf->MultiCell(16,7,"Stawka" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Wartość netto" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Wartość brutto" , 1 , "C" , 0,1); $netto = round(($dane['kwota']*100)/(100+$config['fvat_vat']),2) ; $vat = $dane['kwota'] - $netto ; $pdf->MultiCell(10,7,"1", 1, "C", 0,0); $pdf->MultiCell(50,7,$tytulem , 1 , "C" , 0,0,NULL,NULL,1); $pdf->MultiCell(10,7,"szt." , 1 , "C" , 0,0); $pdf->MultiCell(10,7,"1" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,cena_4($netto) , 1 , "C" , 0,0); $pdf->MultiCell(16,7,$config['fvat_vat']."%" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,cena_4($netto) , 1 , "C" , 0,0); $pdf->MultiCell(30,7,cena_4($dane['kwota']) , 1 , "C" , 0,1); $pdf->Ln() ; $pdf->MultiCell(30,7,"Stawka VAT", 1, "C", 0,0); $pdf->MultiCell(30,7,"Wartość netto" , 1 , "C" , 0,0,NULL,NULL,1); $pdf->MultiCell(30,7,"Kwota VAT" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Wartość brutto" , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Zapłacono", 0, "R", 0,0); $pdf->MultiCell(30,7,cena_4($dane['kwota']).' PLN' , 0 , "R" , 0,1); $pdf->MultiCell(30,7,$config['fvat_vat']."%", 1, "C", 0,0); $pdf->MultiCell(30,7,cena_4($netto) , 1 , "C" , 0,0,NULL,NULL,1); $pdf->MultiCell(30,7,cena_4($vat) , 1 , "C" , 0,0); $pdf->MultiCell(30,7,cena_4($dane['kwota']) , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Do zapłaty" , 0 , "R" , 0,0); $pdf->MultiCell(30,7,cena_4( 0 ).' PLN' , 0 , "R" , 0,1); $pdf->MultiCell(30,7,"Razem", 1, "C", 0,0); $pdf->MultiCell(30,7,cena_4($netto) , 1 , "C" , 0,0,NULL,NULL,1); $pdf->MultiCell(30,7,cena_4($vat) , 1 , "C" , 0,0); $pdf->MultiCell(30,7,cena_4($dane['kwota']) , 1 , "C" , 0,0); $pdf->MultiCell(30,7,"Razem" , 0 , "R" , 0,0); $pdf->MultiCell(30,7,cena_4($dane['kwota']).' PLN', 0 , "R" , 0,1); $razem_brutto = round( $dane['kwota'], 2 ) ; $grosze = round(($razem_brutto-(int)floor($razem_brutto))*100); //echo (($razem_brutto-floor( $razem_brutto ))*100) ; //echo (string)floor( ($razem_brutto-floor($razem_brutto))*100) ; $slownie = str_replace(range(0,9),array("zero*","jed*","dwa*","trzy*","czt*","pie*","sze*","sie*","osi*","dzie*"),(string)floor($razem_brutto))."zł*".str_replace(range(0,9),array("zero*","jed*","dwa*","trzy*","czt*","pie*","sze*","sie*","osi*","dzie*"),(string)(($grosze)))."gr" ; $pdf->MultiCell(180,7,"Słownie" , 0 , "R" , 0,1); $pdf->MultiCell(180,7,$slownie, 0 , "R" , 0,1); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->SetFont('freesans' , '' , 9); $pdf->Multicell( 90, 7, 'Imię i nazwisko osoby uprawnionej'."\r\n".'do wystawiania faktury', 0, 'C', 0, 0 ) ; $pdf->Multicell( 90, 7, 'Imię i nazwisko osoby uprawnionej'."\r\n".'do odbioru faktury', 0, 'C', 0, 1 ) ; //Close and output PDF document $pdf->Output('img/upload/faktura_'.$dane['id'].'.pdf', 'F'); } function przelicz_kategorie() { global $baza, $prefix ; $baza->query( "select * from ".$prefix."firma_kategoria" ) ; while( $row = $baza->get_array() ) { $lista[$row['id_kategorii']]++ ; } $baza->query( "update ".$prefix."kategoria set liczba = 0" ) ; foreach( $lista as $id_kat => $value ) { $baza->query( " UPDATE ".$prefix."kategoria k1 LEFT JOIN ".$prefix."kategoria k2 ON k1.rodzic = k2.id SET k1.liczba = k1.liczba+$value, k2.liczba = k2.liczba+$value WHERE k1.id = '$id_kat'" ) ; //$baza->query(( "update ".$prefix."kategorie set liczba = '$value' where id = '$'" ) } } function get_url_var( $var ) { if( !empty( $_GET[$var] )) return $_GET[$var] ; $vars = parse_url( ''.$_SERVER['REQUEST_URI'] ) ; if( empty( $vars['query'] )) return ; parse_str( $vars['query'], $vars ) ; $_GET[$var] = $vars[$var] ; return $vars[$var] ; } function get_url_vars() { $vars = parse_url( ''.$_SERVER['REQUEST_URI'] ) ; parse_str( $vars['query'], $vars ) ; return $vars ; } function array_diff_ORG_NEW(&$org, &$new, $type='VALUES'){ switch($type){ case 'VALUES': $int = array_values(array_intersect($org, $new)); //C = A ^ B $org = array_values(array_diff($org, $int)); //A' = A - C $new= array_values(array_diff($new, $int)); //B' = B - C break; case 'KEYS': $int = array_values(array_intersect_key($org, $new)); //C = A ^ B $org = array_values(array_diff_key($org, $int)); //A' = A - C $new= array_values(array_diff_key($new, $int)); //B' = B - C break; } } function zapisz_slowa( $tab, $id ) { global $baza, $prefix ; foreach( $tab as $slowo ) { $slowo = trim( $slowo ) ; if( !empty( $slowo )) { $slowo = $baza->safe_string( $slowo ) ; $tab_id[$slowo] = 0 ; $slowa[] = $slowo ; } } $new_id = array() ; $slowa = implode( "','", $slowa ) ; $baza->query( "select id, nazwa from ".$prefix."tagi where nazwa in ('$slowa')" ) ; while( $row = $baza->get_array() ) { $tab_id[$row['nazwa']] = $row['id'] ; $new_id[] = $row['id'] ; } $data = date( 'Y-m-d' ) ; foreach( $tab_id as $slowo => $i ) { if( empty( $i )) { $baza->query( "insert into ".$prefix."tagi ( nazwa, data_dodania, widoczny ) values ( '$slowo', '$data', 1)" ) ; $id_slowa = mysql_insert_id() ; $tab_id[$slowo] = $id_slowa ; $new_id[] = $id_slowa ; } } $old_id = array() ; $baza->query( "select id_tagu from ".$prefix."firma_tagi where id_firmy = '$id'" ) ; while( $row = $baza->get_array() ) { $old_id[] = $row['id_tagu'] ; } $baza->query( "delete from ".$prefix."firma_tagi where id_firmy = '$id'" ) ; foreach( $new_id as $id_slowa ) { $baza->query( "insert into ".$prefix."firma_tagi (id_firmy, id_tagu) values ( '$id', '$id_slowa')" ) ; } // $diff1 = array_diff( $old_id, $new_id ) ; // $diff2 = array_diff( $new_id, $old_id ) ; array_diff_ORG_NEW( $old_id, $new_id ) ; if( !empty( $old_id ) ) { $old = implode( "','", $old_id ) ; $baza->query( "update ".$prefix."tagi set liczba = liczba - 1 where id in ('$old')" ) ; } if( !empty( $new_id ) ) { $new = implode( "','", $new_id ) ; $baza->query( "update ".$prefix."tagi set liczba = liczba + 1 where id in ('$new')" ) ; } // print_r( $old_id ) ; // print_r( $new_id ) ; // print_r( $diff1 ) ; // print_r( $diff2 ) ; } function array_sort($array, $on, $order='SORT_ASC') { $new_array = array(); $sortable_array = array(); if (count($array) > 0) { foreach ($array as $k => $v) { if (is_array($v)) { foreach ($v as $k2 => $v2) { if ($k2 == $on) { $sortable_array[$k] = $v2; } } } else { $sortable_array[$k] = $v; } } switch($order) { case 'SORT_ASC': // echo "ASC"; asort($sortable_array); break; case 'SORT_DESC': // echo "DESC"; arsort($sortable_array); break; } foreach($sortable_array as $k => $v) { $new_array[] = $array[$k]; } } return $new_array; } function bbcode( &$txt ) { $tags = array( 'strong', 'b', 'em', 'u', 'i', 'ul', 'ol', 'li', 'strike', 'p' ) ; foreach( $tags as $tag ) { $txt = str_replace( '<'.$tag.'>', '['.$tag.']', $txt ) ; $txt = str_replace( '', '[/'.$tag.']', $txt ) ; } } function unbbcode( &$txt ) { $tags = array( 'strong', 'b', 'em', 'u', 'i', 'ul', 'ol', 'li', 'strike', 'p' ) ; foreach( $tags as $tag ) { $txt = str_replace( '['.$tag.']', '<'.$tag.'>', $txt ) ; $txt = str_replace( '[/'.$tag.']','', $txt ) ; } $txt = str_replace( '\r\n', '
', $txt ) ; $txt = str_replace( '

', '

 

', $txt ) ; } function sprawdz_dane_firmy( &$tab ) { global $baza ; $wynik = true ; if( !empty( $tab['alias'] )) { $tmp_alias = preg_replace("/[^0-9a-zA-Z]/","", $tab['alias'] ); if( $tmp_alias != $tab['alias'] ) $wynik = false ; else { $baza->query( "select count(*) as liczba from ".$prefix."firma where alias = '$tmp_alias'" ) ; $row = $baza->get_array() ; if( $row['liczba'] > 0 ) { $wynik = false ; } } } if( !empty( $tab['www'] ) && !eregi( 'http', $tab['www'] )) { $tab['www'] = 'http://'.$tab['www'] ; } bbcode($tab['dlugi_opis']) ; bbcode($tab['promocje']) ; bbcode($tab['cennik']) ; foreach( $tab as $key => $value ) { if( $key != 'podkategoria' && $key != 'tagi' ) $tab[$key] = ( $value ) ; } $kategorie = $tab['podkategoria'] ; $wyn = array() ; foreach( $kategorie as $id ) { $val = $id+ 0 ; if( $val != 0 ) { $wyn[] = $id ; } } $tab['kategoria'] = $wyn ; $tagi = $tab['tagi'] ; $wyn = array() ; foreach( $tagi as $id ) { $wyn[] = $baza->safe_string( $id ) ; } $tab['tagi'] = $wyn ; $required = array( 'nazwa', 'kategoria', 'miasto', 'adres', 'email' ) ; foreach( $required as $str ) { if( empty( $tab[$str] )) { $wynik = false ; //echo $str ; } } //echo (int)$wynik ; return $wynik ; } function checkEmail($email) { if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)){ /* list($username,$domain)=split('@',$email); if(!checkdnsrr($domain,'MX')) { return false; } */ return true; } return false; } function wyslij_maila( $email, $subject, $body, $from = '', $attach = '' ) { global $config ; // $from = '' ; if( $config['smtp_host'] != '' ) { $mail = new PHPMailer(); $mail->SMTPDebug = 1; // enables SMTP debug information (for testing) $mail->IsSMTP(); // telling the class to use SMTP $mail->IsHTML( true ) ; $mail->SMTPAuth = true; // enable SMTP authentication if( $config['smtp_tls' ] == 1 ) $mail->SMTPSecure = "tls"; else $mail->SMTPSecure = 'ssl' ; $mail->Host = $config['smtp_host']; // SMTP server $mail->Username = $config['smtp_user']; // SMTP account username $mail->Password = $config['smtp_pass']; // SMTP account password $mail->Port = $config['smtp_port']; if( empty( $from )) { $mail->SetFrom($config['smtp_from'],$config['smtp_from_name']); $mail->AddReplyTo($config['smtp_from'],$config['smtp_from_name']); } else { $mail->SetFrom($config['smtp_from'],$config['smtp_from_name']); //$mail->SetFrom($from,$from); $mail->AddReplyTo($from,$from); } if( !empty( $attach )) { $mail->AddAttachment( $attach, 'faktura.pdf' ) ; } $mail->Subject = $subject; $mail->MsgHTML($body); $mail->AltBody = strip_tags( $body ) ; $mail->AddAddress($email); if(!$mail->Send()) { // echo "Mailer Error: " . $mail->ErrorInfo; return false ; } else { // echo "Message sent!"; return true ; } } /* wysyłka przy pomocy mail*/ else { if( empty( $config['smtp_from2'] )) $config['smtp_from2'] = $config['smtp_from'] ; if( empty( $config['smtp_from_name'] )) $config['smtp_from_name'] = $config['smtp_user'] ; $headers = 'From: '.$config['smtp_from_name'].' <'.$config['smtp_from2'] . ">\r\n" . 'Reply-To: '.$config['smtp_from_name'].' <'.$config['smtp_from2'] . ">\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($email, $subject, $body, $headers); } } function longWordWrap($string) { $string = str_replace("\n", "\n ", $string); // add a space after newline characters, so that 2 words only seperated by \n are not considered as 1 word $words = explode(" ", $string); // now split by space foreach ($words as $word) { $outstring .= chunk_split($word, 20, " ") . " "; } return $outstring; } function dateDiff( $data1, $data2 ) { if( empty( $data1 )) return 0 ; if( $data1 == '0000-00-00' ) return 0 ; $data1 = explode( "-", $data1 ) ; $data2 = explode( "-", $data2 ) ; $d1=mktime(0,0,0,$data1[1],$data1[2],$data1[0]); $d2=mktime(0,0,0,$data2[1],$data2[2],$data2[0]); return floor(abs($d2-$d1)/86400) ; } //PageRank Lookup v1.1 by HM2K (update: 31/01/07) //based on an alogoritham found here: http://pagerank.gamesaga.net/ //settings - host and user agent $googlehost='toolbarqueries.google.com'; $googleua='Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5'; //convert a string to a 32-bit integer function StrToNum($Str, $Check, $Magic) { $Int32Unit = 4294967296; // 2^32 $length = strlen($Str); for ($i = 0; $i < $length; $i++) { $Check *= $Magic; //If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31), // the result of converting to integer is undefined // refer to http://www.php.net/manual/en/language.types.integer.php if ($Check >= $Int32Unit) { $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit)); //if the check less than -2^31 $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check; } $Check += ord($Str{$i}); } return $Check; } //genearate a hash for a url function HashURL($String) { $Check1 = StrToNum($String, 0x1505, 0x21); $Check2 = StrToNum($String, 0, 0x1003F); $Check1 >>= 2; $Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F); $Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF); $Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF); $T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F ); $T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 ); return ($T1 | $T2); } //genearate a checksum for the hash string function CheckHash($Hashnum) { $CheckByte = 0; $Flag = 0; $HashStr = sprintf('%u', $Hashnum) ; $length = strlen($HashStr); for ($i = $length - 1; $i >= 0; $i --) { $Re = $HashStr{$i}; if (1 === ($Flag % 2)) { $Re += $Re; $Re = (int)($Re / 10) + ($Re % 10); } $CheckByte += $Re; $Flag ++; } $CheckByte %= 10; if (0 !== $CheckByte) { $CheckByte = 10 - $CheckByte; if (1 === ($Flag % 2) ) { if (1 === ($CheckByte % 2)) { $CheckByte += 9; } $CheckByte >>= 1; } } return '7'.$CheckByte.$HashStr; } //return the pagerank checksum hash function getch($url) { return CheckHash(HashURL($url)); } //return the pagerank figure function getpr($url) { global $googlehost,$googleua; $ch = getch($url); $fp = fsockopen($googlehost, 80, $errno, $errstr, 30); if ($fp) { $out = "GET /tbr?client=navclient-auto&ch=$ch&features=Rank&q=info:$url HTTP/1.1\r\n"; //echo "
$out
\n"; //debug only $out .= "User-Agent: $googleua\r\n"; $out .= "Host: $googlehost\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); echo $out ; //$pagerank = substr(fgets($fp, 128), 4); //debug only //echo $pagerank; //debug only while (!feof($fp)) { $data = fgets($fp, 128); // echo $data.'
'; $pos = strpos($data, "Rank_"); if($pos === false){} else{ $pr=substr($data, $pos + 9); $pr=trim($pr); $pr=str_replace("\n",'',$pr); return $pr; } } //else { echo "$errstr ($errno)
\n"; } //debug only fclose($fp); } } //generate the graphical pagerank function pagerank($url,$width=40,$method='style') { if (!preg_match('/^(http:\/\/)?([^\/]+)/i', $url)) { $url='http://'.$url; } // $pr = GooglePageRankChecker::getRank( $row['www'] ) ; $pr=getpr($url); if( empty( $pr )) $pagerank = 0 ; else $pagerank = $pr ; // $pagerank="$pr/10"; return $pagerank; } class GooglePageRankChecker { // Track the instance private static $instance; // Constructor function getRank($page) { // Create the instance, if one isn't created yet if(!isset(self::$instance)) { self::$instance = new self(); } // Return the result return self::$instance->check($page); } // Convert string to a number function stringToNumber($string,$check,$magic) { $int32 = 4294967296; // 2^32 $length = strlen($string); for ($i = 0; $i < $length; $i++) { $check *= $magic; //If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31), // the result of converting to integer is undefined // refer to http://www.php.net/manual/en/language.types.integer.php if($check >= $int32) { $check = ($check - $int32 * (int) ($check / $int32)); //if the check less than -2^31 $check = ($check < -($int32 / 2)) ? ($check + $int32) : $check; } $check += ord($string{$i}); } return $check; } // Create a url hash function createHash($string) { $check1 = $this->stringToNumber($string, 0x1505, 0x21); $check2 = $this->stringToNumber($string, 0, 0x1003F); $factor = 4; $halfFactor = $factor/2; $check1 >>= $halfFactor; $check1 = (($check1 >> $factor) & 0x3FFFFC0 ) | ($check1 & 0x3F); $check1 = (($check1 >> $factor) & 0x3FFC00 ) | ($check1 & 0x3FF); $check1 = (($check1 >> $factor) & 0x3C000 ) | ($check1 & 0x3FFF); $calc1 = (((($check1 & 0x3C0) << $factor) | ($check1 & 0x3C)) << $halfFactor ) | ($check2 & 0xF0F ); $calc2 = (((($check1 & 0xFFFFC000) << $factor) | ($check1 & 0x3C00)) << 0xA) | ($check2 & 0xF0F0000 ); return ($calc1 | $calc2); } // Create checksum for hash function checkHash($hashNumber) { $check = 0; $flag = 0; $hashString = sprintf('%u', $hashNumber) ; $length = strlen($hashString); for ($i = $length - 1; $i >= 0; $i --) { $r = $hashString{$i}; if(1 === ($flag % 2)) { $r += $r; $r = (int)($r / 10) + ($r % 10); } $check += $r; $flag ++; } $check %= 10; if(0 !== $check) { $check = 10 - $check; if(1 === ($flag % 2) ) { if(1 === ($check % 2)) { $check += 9; } $check >>= 1; } } return '7'.$check.$hashString; } function check($page) { // Open a socket to the toolbarqueries address, used by Google Toolbar $socket = fsockopen("toolbarqueries.google.com", 80, $errno, $errstr, 30); // If a connection can be established if($socket) { // Prep socket headers $out = "GET /tbr?client=navclient-auto&ch=".$this->checkHash($this->createHash($page)). "&features=Rank&q=info:".$page."&num=100&filter=0 HTTP/1.1\r\n"; $out .= "Host: toolbarqueries.google.com\r\n"; $out .= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP 5.1)\r\n"; $out .= "Connection: Close\r\n\r\n"; // Write settings to the socket fwrite($socket, $out); // When a response is received... $result = ""; while(!feof($socket)) { $data = fgets($socket, 128); // echo $data ; $pos = strpos($data, "Rank_"); if($pos !== false){ $pagerank = substr($data, $pos + 9); $result += $pagerank; } } // Close the connection fclose($socket); // Return the rank! return $result; } } } function ip2bin($ip) { if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) return base_convert(ip2long($ip),10,2); if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) return false; if(($ip_n = inet_pton($ip)) === false) return false; $bits = 15; // 16 x 8 bit = 128bit (ipv6) while ($bits >= 0) { $bin = sprintf("%08b",(ord($ip_n[$bits]))); $ipbin = $bin.$ipbin; $bits--; } return $ipbin; } function bin2ip($bin) { if(strlen($bin) <= 32) // 32bits (ipv4) return long2ip(base_convert($bin,2,10)); if(strlen($bin) != 128) return false; $pad = 128 - strlen($bin); for ($i = 1; $i <= $pad; $i++) { $bin = "0".$bin; } $bits = 0; while ($bits <= 7) { $bin_part = substr($bin,($bits*16),16); $ipv6 .= dechex(bindec($bin_part)).":"; $bits++; } return inet_ntop(inet_pton(substr($ipv6,0,-1))); } ?> $value ) { $str[] = $key.' => '.$value ; } return implode( '****', $str ) ; } function unserialize( $str ) { $tab = explode( '****', $str ) ; $array = array() ; foreach( $tab as $row ) { $str = explode( ' => ', $row ) ; $array[$str[0]] = $str[1] ; } return $array ; } function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } function clear() { mysql_free_result( $this->result ) ; } function prefix( $str ) { $this->prefix = $str ; } function CBaza() { $this->sqlq = 0 ; $this->debug = 0 ; $this->time_start = $this->getmicrotime(); } function close() { if( $this->debug == 1 ) { $czas = $this->getmicrotime() - $this->time_start ; $c = count( $this->query_list ) ; echo ' ' ; for( $a = 0 ; $a < $c ; $a++ ) { $q = @$this->query_list[$a]['q'] ; $l = @$this->query_list[$a]['l'] ; $qc = round($this->query_list[$a]['c'],4) ; echo '' ; $result = @mysql_query( 'explain '.$q ) ; echo '' ; $fields = @mysql_num_fields($result); for ($i = 0; $i < $fields; $i++) { echo '' ; } echo '' ; while( $row = @mysql_fetch_assoc( $result )) { echo '' ; $d = 0 ; foreach( $row as $key => $value ) { if( $d == 3 && $value == 'ALL') echo '' ; else echo '' ; $d++ ; } echo '' ; } } echo '
Debug: '.$this->sqlq.' zapytań, strona w '.$czas.' sekund

'.$q.'
'.$l.'
'.$qc.' s

'.mysql_field_name($result, $i).'
'.$value.''.$value.'
' ; } mysql_close( $this->_link ) ; } function field_value( $pole ) { return $this->tab[$pole] ; } function row_count() { return $this->row_count ; } function error() { return mysql_error() ; } function select_records( $tablica, $pola = "*", $warunki = '', $sortuj = '' ) { $tab = array() ; $this->query( "select $pola from ".$this->prefix."$tablica" ) ; while( $row = $this->get_array() ) { $tab[] = $row ; } return $tab ; } /** wykonaj zapytanie mysql */ function query( $zapytanie ) { $a = $this->sqlq ; if( $this->debug == 1 ) { $dbg = debug_backtrace() ; $dbg = $dbg[0] ; $dbg['file'] = substr( $dbg['file'], strpos( $dbg['file'], 'htdocs') + 6 ) ; // $file = fopen( 'log/query.txt', 'a' ) ; // fwrite( $file, $dbg['file']."\r\n".$zapytanie."\r\n" ) ; // echo $zapytanie.'
' ; $start = $this->getmicrotime() ; if( @eregi( "select", $zapytanie )) { $dbg = debug_backtrace() ; $dbg = $dbg[0] ; $dbg['file'] = substr( $dbg['file'], strpos( $dbg['file'], 'htdocs') + 6 ) ; $this->query_list[$a] = array( 'q' => $zapytanie, 'l' => $dbg['file'].':'.$dbg['line'] ) ; } } $this->result = mysql_query( $zapytanie, $this->_link ) ; if( $this->debug == 1 ) { // fwrite( $file, 'Wynik: '.$this->result."\r\n\r\n" ) ; // fclose( $file ) ; $czas = $this->getmicrotime() - $start ; $this->query_list[$a]['c'] = $czas ; } if( $this->result ) { // $this->row_count = mysql_num_rows( $this->result ) ; / // if( $this->row_count == 1 ) {} // $this->tab = mysql_fetch_assoc( $this->result ) ; } else { $this->row_count = 0 ; $this->tab = array() ; } $this->sqlq++ ; return $this->result ; } /** Zabezpiecz dane przed umieszczeniem w bazie */ function safe_string( $string ) { if( !defined( 'ADMIN_IN_' )) $wynik = strip_tags( $string ) ; else $wynik = $string ; /*if (!get_magic_quotes_gpc()) $wynik = mysql_escape_string( $wynik ) ; */ $wynik = mysql_real_escape_string( get_magic_quotes_gpc()?stripslashes($wynik):$wynik ) ; return $wynik ; } /** Podaj jeden wiersz z wyniku jako tablicę asocjacyjną */ function get_array() { return @mysql_fetch_array( $this->result, MYSQL_ASSOC ) ; } /** Podaj jeden wiersz z wyniku jako tablicę z indeksami liczbowymi */ function get_row() { return @mysql_fetch_row( $this->result ) ; } /** polacz z baza danych */ function connect( $db_host, $db_user, $db_pass, $db_db ) { $db = mysql_connect($db_host, $db_user, $db_pass ) ; $this->_link = $db ; if ( !$db ) { return 0 ; } $ok = mysql_select_db($db_db) ; if ( !$ok ) { // echo( "Nie ma takiej bazy" ) ; return 0 ; } mysql_query("SET NAMES 'utf8'"); // mysql_query("SET CHARACTER SET 'ISO-8859-2'"); // echo mysql_error() ; return 1 ; } /** polacz dane tak, aby zawieraly instrukcje insert lub update */ function polacz_post( $post, $operacja = "insert" ) { if( $operacja == "insert" ) { $klucze = $wartosci = array() ; foreach( $post as $key => $value ) { $klucze[] = $this->safe_string($key) ; $wartosci[] = $this->safe_string($value) ; } $wynik = "( ".implode( ", ", $klucze )." ) VALUES ( '".implode( "','", $wartosci )."' )" ; } else { $wynik = array() ; foreach( $post as $key => $value ) $wynik[] = '`'.$this->safe_string($key)."` = '".$this->safe_string( $value )."'" ; $wynik = implode( ", ", $wynik ) ; } return $wynik ; } /** Skasuj wybrany wiersz */ function delete( $tabela, $kolumna, $id ) { $id = $id + 0 ; $query = "delete from ".$tabela." where ".$this->safe_string($kolumna)." = '$id'" ; return $this->query( $query ) ; } /** Zapisz dane do tablicy */ function save( $tabela, $dane, $kolumna, $id = "", $where = "" ) { $id = $dane[$kolumna] ; unset( $dane[$kolumna] ) ; if( empty( $id )) { // insert $query = "insert into ".$tabela." ".$this->polacz_post( $dane ) ; } else { // update $id = $id + 0 ; $query = "update ".$tabela." SET ".$this->polacz_post( $dane, "update" )." where ".$this->safe_string( $kolumna )." = '$id'" ; if( !empty( $where )) { $query .= ' and '.$where ; } } // echo $query ; return $this->query( $query ) ; } } ?>description = array() ; $this->title = array() ; $this->keywords = array() ; $this->css = array() ; $this->meta = array() ; } function setDescription( $desc, $priority = 0 ) { $this->description[$priority] = $desc ; } function setKeywords( $keywords ) { $keywords = explode( ",", $keywords ) ; $this->keywords = array_merge( $this->keywords, $keywords ) ; } function setTitle( $title, $priority = 0 ) { $this->title[$priority] = $title ; } function getDescription() { return @implode(" ",$this->description) ; } function getKeywords() { return @implode( ",", $this->keywords ) ; } function getTitle( $sign ) { ksort( $this->title ) ; $wynik = array() ; foreach( $this->title as $priority => $output ) { $tab = array() ; if( is_array( $output )) { foreach( $output as $key => $value ) { $tab[] = $value ; } $tab = array_reverse( $tab ) ; } else $tab[] = $output ; $wynik[] = implode( $sign, $tab ) ; } return implode( $sign, $wynik ) ; } function addjavascript( $src ) { $this->js[] = $src ; } function addcss( $src ) { $this->css[]['src'] = $src ; } function addcsstxt( $txt ) { // echo 'aa'.$txt ; $this->css[]['txt'] = $txt ; } function getjavascript() { if( empty( $this->js )) return '' ; $txt = '' ; foreach( $this->js as $src ) { $txt .= ''."\r\n" ; } return $txt ; } function getcss() { $txt = '' ; $c = count( $this->css ); //print_r( $this->css ) ; for( $a = 0 ; $a < $c ; $a++ ) { $src = $this->css[$a] ; // print_r( $src ) ; if( !empty($src['src']) ) $txt .= '' ; elseif( !empty( $src['txt'] )) { $txt .= $src['txt'] ; } } // echo $txt ; return $txt ; } function addMeta( $tab ) { $this->meta = array_merge( $this->meta, $tab ) ; } function getMeta( $key ) { // print_r( $this->meta ) ; if( empty( $key )) return $this->meta ; else { return $this->meta['meta_'.$key] ; } } function addRss( $path, $title ) { $title = htmlentities( $title, ENT_COMPAT, 'UTF-8' ) ; $this->addons[] = '' ; } function putHeader( &$smarty ) { if( !empty( $this->addons )) $smarty->assign( 'addons', implode( "\r\n", $this->addons )) ; $smarty->assign( 'keywords', $this->getKeywords() ) ; $smarty->assign( 'description', $this->getDescription() ) ; $smarty->assign( 'javascript', $this->getjavascript() ) ; $smarty->assign( 'css', $this->getcss() ) ; $smarty->Assign( 'title', $this->getTitle( ' » ' )) ; } } ?>