db = $db; $this->slowniki = $this->setSlowniki(); $this->ustawienia = $this->setUstawienia(); $this->autoryzacja = $autoryzacja; $this->wyszukiwanie = array(); if (isset($_SESSION[CFG_SESSION_NAME]['wyszukiwanie'])) { $this->wyszukiwanie = $_SESSION[CFG_SESSION_NAME]['wyszukiwanie']; } if (isset($_SESSION[CFG_SESSION_NAME]['wyszukiwanie_sort'])) { $this->wyszukiwanie_sort = $_SESSION[CFG_SESSION_NAME]['wyszukiwanie_sort']; } if (isset($_SESSION[CFG_SESSION_NAME]['wyszukiwanie_archiwum'])) { $this->wyszukiwanie_archiwum = $_SESSION[CFG_SESSION_NAME]['wyszukiwanie_archiwum']; } } //}}} //{{{ setPathInfo() function setPathInfo() { $info = explode(',', str_replace($_SERVER['SCRIPT_NAME'], '', substr(str_replace('.html', '', $_SERVER['REQUEST_URI']), 1))); if ($info[0]) { $this->element = basename($info[0]); } if ($info[1]) { $this->id = $info[1]; } if ($info[2]) { $this->reszta = $info[2]; } if ($info[3]) { $this->id2 = $info[3]; } if ($info[4]) { $this->reszta2= $info[4]; } if ($this->element == 'index.php' || $this->element == '/' || $this->element == '') { $this->element = 'main'; } if ($this->element == 'dealer' || $this->element == 'dealer_about_me' || $this->element == 'dealer_email') { if (is_numeric($this->id)) { $this->id_klienta = $this->id; } } elseif ($this->element == 'dealer_offers') { $this->id_klienta = $this->reszta; } $this->request_uri = $_SERVER['REQUEST_URI']; $this->request = $_REQUEST; $request_a = array_reverse(explode(',', $_SERVER['REQUEST_URI'])); if (is_numeric($request_a[0])) { unset($request_a[0]); } $this->url2 = implode(',', array_reverse($request_a)); return true; } //}}} /* SLOWNIKI / USTAWIENIA / TOPY */ //{{{ setSlowniki() function setSlowniki() { $elementy = array('marki', 'modele', 'rodzaje', 'rodzaje_czesci', 'rodzaje_akcesoria', 'kolory', 'paliwa', 'skrzynie_biegow', 'typy_napedow', 'wyposazenie', 'historia', 'stan_techniczny', 'pochodzenie', 'kraje', 'dodatkowe_informacje'); $lista = array(); foreach($elementy as $element) { $query = "select * from {$element} where 1=1 and nazwa not ilike '%inny%' order by kolejnosc, nazwa"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $lista[$element][$row['id']] = $row; } } } return $lista; } //}}} //{{{ getSlowniki() function getSlowniki() { return $this->slowniki; } //}}} //{{{ setUstawienia() function setUstawienia() { $ustawienia = array(); $query = "select * from ustawienia where id = 1"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $ustawienia = $result->FetchRow(); } return $ustawienia; } //}}} //{{{ getTop() function getTop() { $query = "select zt.*, t.* from zdjecia_topy zt, topy t where zt.id_topu = t.id and t.pokaz = 't' order by random()"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $row = $result->FetchRow(); $plik = "data/topy/{$row['id_topu']}/o/{$row['plik']}"; return $plik; } return ''; } //}}} /* STRONA */ //{{{ getRodzajeWWW() function getRodzajeWWW() { $lista = array(); $query = "select * from rodzaje where 1=1 and nazwa not ilike '%inny%' and id in (select id_rodzaju from ogloszenia where typ = 1 and widoczny_do > now() and archiwum = 'f') order by kolejnosc, nazwa"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $lista[$row['id']] = $row['nazwa']; } } return $lista; } //}}} //{{{ getRodzajeCzesciWWW() function getRodzajeCzesciWWW() { $lista = array(); $query = "select * from rodzaje_czesci where 1=1 and nazwa not ilike '%inny%' and id in (select id_rodzaju from ogloszenia where typ = 2 and widoczny_do > now() and archiwum = 'f') order by kolejnosc, nazwa"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $lista[$row['id']] = $row['nazwa']; } } return $lista; } //}}} //{{{ getRodzajeAkcesoriaWWW() function getRodzajeAkcesoriaWWW() { $lista = array(); $query = "select * from rodzaje_akcesoria where 1=1 and nazwa not ilike '%inny%' and id in (select id_rodzaju from ogloszenia where typ = 3 and widoczny_do > now() and archiwum = 'f') order by kolejnosc, nazwa"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $lista[$row['id']] = $row['nazwa']; } } return $lista; } //}}} /* OGLOSZENIA */ //{{{ getOgloszenia() function getOgloszenia($count = false) { $ogloszenia = array(); $ogloszenia_tmp = array(); $pole = 'id'; if ($count === true) { $pole = 'count(*) as ilosc'; } $query = "select {$pole} from ogloszenia where 1=1 "; if (is_object($this->autoryzacja)) { if ($this->element == 'my_offers' || $this->element == 'my_parts' || $this->element == 'my_accessories') { $query .= " and id_klienta = '{$this->autoryzacja->id}'"; if ($this->wyszukiwanie_archiwum == 2) { $query .= " and (widoczny_do < now() or archiwum = 't') "; } elseif ($this->wyszukiwanie_archiwum == 1) { $query .= " and widoczny_do > now() and archiwum = 'f' "; } } else { $query .= " and widoczny_do > now() and archiwum = 'f' "; } if ($this->element == 'watchlist') { $query .= " and id in (select id_ogloszenia from parking where id_klienta = '{$this->autoryzacja->id}') "; } /* if ($this->element == 'my_offers' && $query .= " and (widoczny_do < now() or archiwum = 't') "; } elseif ($this->element == 'my_offers') { $query .= " and widoczny_do > now() and archiwum = 'f' "; } */ } else { $query .= " and widoczny_do > now() and archiwum = 'f' "; } if ($this->element == 'wyszukiwanie') { if ($this->wyszukiwanie['id_marki'] || $this->wyszukiwanie['id_modelu']) { if ($this->wyszukiwanie['id_marki']) { $query .= " and id_marki = '{$this->wyszukiwanie['id_marki']}'"; } if ($this->wyszukiwanie['id_modelu']) { $query .= " and id_modelu = '{$this->wyszukiwanie['id_modelu']}'"; } } if ($this->wyszukiwanie['fraza']) { // $query .= " and (nazwa ilike '%{$this->wyszukiwanie['fraza']}%' or id_modelu in (select id_modelu from lista_view where nazwa ilike '%{$this->wyszukiwanie['fraza']}%') )"; $query .= " and id in (select id from wyszukiwanie_view where fraza ilike '%{$this->wyszukiwanie['fraza']}%')"; } if ($this->wyszukiwanie['id_rodzaju']) { $query .= " and id_rodzaju = '{$this->wyszukiwanie['id_rodzaju']}'"; } if ($this->wyszukiwanie['id_paliwa']) { $query .= " and id_paliwa = '{$this->wyszukiwanie['id_paliwa']}'"; } if ($this->wyszukiwanie['id_skrzynii']) { $query .= " and id_skrzynii = '{$this->wyszukiwanie['id_skrzynii']}'"; } if ($this->wyszukiwanie['id_napedu']) { $query .= " and id_napedu = '{$this->wyszukiwanie['id_napedu']}'"; } if ($this->wyszukiwanie['cena_s']) { $cena_s = array_map("trim", explode('-', $this->wyszukiwanie['cena_s'])); $cena_od = $cena_s[0]; $cena_do = $cena_s[1]; $query .= " and cena >= '{$cena_od}' and cena <= '{$cena_do}'"; } if ($this->wyszukiwanie['pojemnosc_s']) { $pojemnosc_s = array_map("trim", explode('-', $this->wyszukiwanie['pojemnosc_s'])); $pojemnosc_od = $pojemnosc_s[0]; $pojemnosc_do = $pojemnosc_s[1]; $query .= " and pojemnosc >= '{$pojemnosc_od}' and pojemnosc <= '{$pojemnosc_do}'"; } if ($this->wyszukiwanie['przebieg_s']) { $przebieg_s = array_map("trim", explode('-', $this->wyszukiwanie['przebieg_s'])); $przebieg_od = $przebieg_s[0]; $przebieg_do = $przebieg_s[1]; $query .= " and przebieg >= '{$przebieg_od}' and przebieg <= '{$przebieg_do}'"; } if ($this->wyszukiwanie['rok_s']) { $rok_s = array_map("trim", explode('-', $this->wyszukiwanie['rok_s'])); $rok_od = $cena_s[0]; $rok_do = $cena_s[1]; $query .= " and rok >= '{$rok_od}' and rok <= '{$rok_do}'"; } } if ($this->element == 'parts' || $this->element == 'my_parts') { $query .= " and typ = 2 "; if ($this->reszta) { $query .= " and id_rodzaju = '{$this->reszta}' "; } } else if ($this->element == 'accessories' || $this->element == 'my_accessories') { $query .= " and typ = 3 "; if ($this->reszta) { $query .= " and id_rodzaju = '{$this->reszta}' "; } } elseif ($this->element == 'dealer_offers' && $this->id_klienta) { $query .= " and typ = 1 "; $query .= " and id_klienta = '{$this->id_klienta}' "; } else { $query .= " and typ = 1 "; if ($this->reszta) { $query .= " and id_rodzaju = '{$this->reszta}' "; } } $strona = 1; if ($this->id) { $strona = $this->id; } if ($count === true) { $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $row = $result->FetchRow(); if ($this->reszta) { $paginator = new Paginator($row['ilosc'], CFG_OFFER_PER_PAGE, $strona, $this->element.',(:num),'.$this->reszta.'.html'); } else { $paginator = new Paginator($row['ilosc'], CFG_OFFER_PER_PAGE, $strona, $this->element.',(:num).html'); } return $paginator; } } $limit = CFG_OFFER_PER_PAGE; $offset = ($strona-1)*CFG_OFFER_PER_PAGE; if ($this->wyszukiwanie_sort == 1) { $order_by = 'kolejnosc, id desc'; } elseif ($this->wyszukiwanie_sort == 2) { $order_by = 'kolejnosc, id'; } elseif ($this->wyszukiwanie_sort == 3) { $order_by = 'kolejnosc, cena desc'; } elseif ($this->wyszukiwanie_sort == 4) { $order_by = 'kolejnosc, cena'; } elseif ($this->wyszukiwanie_sort == 5) { $order_by = 'kolejnosc, rok desc'; } elseif ($this->wyszukiwanie_sort == 6) { $order_by = 'kolejnosc, rok'; } elseif ($this->wyszukiwanie_sort == 7) { $order_by = 'kolejnosc, przebieg desc'; } elseif ($this->wyszukiwanie_sort == 8) { $order_by = 'kolejnosc, przebieg'; } //else { $order_by = 'kolejnosc_random'; } else { $order_by = 'kolejnosc, id desc'; } $query .= "order by {$order_by} offset {$offset} limit {$limit}"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); /* if ($i==0 && $strona == 1) { $ogloszenie_ob = Ogloszenie::pobierz($this->db, 377); $ogloszenie_ob->rekord_db = $this->_setSlowniki($ogloszenie_ob->rekord_db); $ogloszenia_tmp[] = $ogloszenie_ob; } */ $ogloszenie_ob = Ogloszenie::pobierz($this->db, $row['id']); $ogloszenie_ob->rekord_db = $this->_setSlowniki($ogloszenie_ob->rekord_db); $ogloszenia_tmp[] = $ogloszenie_ob; } } $ogloszenia = $ogloszenia_tmp; return $ogloszenia; } //}}} //{{{ getPowiazane() function getPowiazane($ogloszenie) { $id = $ogloszenie->rekord_db['id']; $id_marki = $ogloszenie->rekord_db['id_marki']; $id_modelu = $ogloszenie->rekord_db['id_modelu']; $pojemnosc = $ogloszenie->rekord_db['pojemnosc']; $id_rodzaju = $ogloszenie->rekord_db['id_rodzaju']; if (!$id_rodzaju) { $id_rodzaju = 'null'; } $ogloszenia = array(); $ogloszenia_tmp = array(); if (!$pojemnosc) { $pojemnosc = 0; } if (!$id_marki || !$id_modelu || !$id_rodzaju) { return array(); } if ($ogloszenie->rekord_db['typ'] == 1) { $query = "(select id, 1 as typ from ogloszenia where id_marki = '{$id_marki}' and id_modelu = '{$id_modelu}' and id <> '{$id}' and widoczny_do > now() and archiwum = 'f' order by random()) UNION (select id, 2 as typ from ogloszenia where id_marki = '{$id_marki}' and id_rodzaju = {$id_rodzaju} and id <> '{$id}' and widoczny_do > now() and archiwum = 'f' order by random()) UNION (select id, 3 as typ from ogloszenia where id_rodzaju = {$id_rodzaju} and id <> '{$id}' and pojemnosc <= '{$pojemnosc}' + 100 and pojemnosc > '{$pojemnosc}' - 100 and widoczny_do > now() and archiwum = 'f' order by random())"; } else { $query = "(select id, 1 as typ from ogloszenia where id_rodzaju = {$id_rodzaju} and id <> '{$id}' and widoczny_do > now() and archiwum = 'f' )"; } $query .= "order by typ desc"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $ogloszenie_ob = Ogloszenie::pobierz($this->db, $row['id']); $ogloszenie_ob->rekord_db = $this->_setSlowniki($ogloszenie_ob->rekord_db); $ogloszenia_tmp[] = $ogloszenie_ob; } } $ogloszenia = array_merge($ogloszenia_tmp); return $ogloszenia; } //}}} //{{{ getOstatnio() function getOstatnio() { $ogloszenia = array(); $ogloszenia_tmp = array(); $query = "select id from ogloszenia order by id desc limit 2"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $ogloszenie_ob = Ogloszenie::pobierz($this->db, $row['id']); $ogloszenie_ob->rekord_db = $this->_setSlowniki($ogloszenie_ob->rekord_db); $ogloszenia_tmp[] = $ogloszenie_ob; } } $ogloszenia = array_merge($ogloszenia_tmp); return $ogloszenia; } //}}} //{{{ getIdOgloszeniaByAkol() function getIdOgloszeniaByAkol($id_akol) { $query = "select id from ogloszenia where id_akol = '{$id_akol}' and widoczny_do > now() and archiwum = 'f'"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $row = $result->FetchRow(); return $row['id']; } return false; } //}}} //{{{ checkOgloszenie() function checkOgloszenie($id_ogloszenia) { $query = "select id from ogloszenia where (id = '{$id_ogloszenia}' and widoczny_do > now() and archiwum = 'f') or id_klienta = '1229'"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $row = $result->FetchRow(); return $row['id']; } return false; } //}}} //{{{ getOgloszenie() function getOgloszenie($id = null) { if (!$id) { $id = $this->id; } $ogloszenie_ob = Ogloszenie::pobierz($this->db, $id); $ogloszenie_ob->rekord_db = $this->_setSlowniki($ogloszenie_ob->rekord_db); return $ogloszenie_ob; } //}}} //{{{ getStrona() function getStrona($id = null) { if (!$id) { $id = $this->id; } $strona_ob = Strona::pobierz($this->db, $id); return $strona_ob; } //}}} //{{{ getPorownanie() function getPorownanie() { $lista = array(); if ($this->autoryzacja !== false) { $id_klienta = $this->autoryzacja->id; $tabela = 'porownywarka'; } else { $id_klienta = session_id(); $tabela = 'porownywarka2'; } $query = "select distinct o.id from ogloszenia o, {$tabela} p where o.id = p.id_ogloszenia and p.id_klienta = '{$id_klienta}'"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $ogloszenie_ob = $this->getOgloszenie($row['id']); $dane = $ogloszenie_ob->rekord_db; $lista[] = $dane; } } return $lista; } //}}} /* POROWNYWARKA */ //{{{ dodajPorownywarka() function dodajPorownywarka($id_ogloszenia) { $id_klienta = session_id(); $dane = array('id_ogloszenia' => $id_ogloszenia, 'id_klienta' => $id_klienta); $this->db->AutoExecute("porownywarka2", $dane, "INSERT"); } //}}} //{{{ usunPorownywarka() function usunPorownywarka($id_ogloszenia) { $id_klienta = session_id(); $query = "delete from porownywarka2 where id_klienta = '{$id_klienta}' and id_ogloszenia = '{$id_ogloszenia}'"; $this->db->Execute($query); return true; } //}}} //{{{ isPorownywarka() function isPorownywarka($id_ogloszenia) { $id_klienta = session_id(); $query = "select * from porownywarka2 where id_ogloszenia = '{$id_ogloszenia}' and id_klienta = '{$id_klienta}'"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { return true; } return false; } //}}} /* DEALER */ //{{{ getKlient() function getKlient($id_klienta) { $dane = array(); $query = "select * from klienci where id = '{$id_klienta}'"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $dane = $result->FetchRow(); } return $dane; } //}}} //{{{ getKlientZdjecia() function getKlientZdjecia($id_klienta) { $query = "select *, '/data/clients/'||id_klienta||'/s/'||plik as plik_s, '/data/clients/'||id_klienta||'/m/'||plik as plik_m, '/data/clients/'||id_klienta||'/b/'||plik as plik_b from zdjecia_klienci where id_klienta = '{$id_klienta}' order by kolejnosc"; $result = $this->db->Execute($query); $zdjecia = $result->GetRows(); return $zdjecia; } //}}} //{{{ zapiszKlientKontakt() function zapiszKlientKontakt($dane) { $dane['ip'] = $_SERVER['REMOTE_ADDR']; $wynik = $this->db->AutoExecute('klienci_email', $dane, 'INSERT'); return true; } //}}} //{{{ wyslijKlientKontakt() function wyslijKlientKontakt($dane) { $crlf = "\n"; $from = 'info@kupmotor.pl'; $hdrs = array('From' => $from, 'X-Sender'=> $from, 'Reply-To'=> $from, 'Return-Path'=> $from, //'Bcc' => 'krystian@webandart.nu', 'Subject' => $dane['tytul']); $mime = new Mail_mime($crlf); $template = new Smarty(); $template->left_delimiter = "{%"; $template->right_delimiter = "%}"; $template->assign('dane', $dane); $content = $template->fetch('email_klient.tpl'); $mime->addHTMLImage("img/email_top1.jpg"); $html = $content; $mail =& Mail::factory('mail'); $mime->setHTMLBody($html, false); $body = array(); $body['text_charset'] = 'utf-8'; $body['html_charset'] = 'utf-8'; $body['head_charset'] = 'utf-8'; $body = $mime->get($body); $hdrs = $mime->headers($hdrs); $klient = $this->getKlient($dane['id_klienta']); $mail->send($klient['email'], $hdrs, $body); return true; } //}}} /* KONTAKT */ //{{{ getKontakt() function getKontakt($id_kontaktu) { $dane = array(); $query = "select * from kontakt where id = '{$id_kontaktu}'"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $dane = $result->FetchRow(); } return $dane; } //}}} //{{{ zapiszKontakt() function zapiszKontakt($dane) { $dane['ip'] = $_SERVER['REMOTE_ADDR']; $wynik = $this->db->AutoExecute('kontakt', $dane, 'INSERT'); return true; } //}}} //{{{ wyslijKontakt() function wyslijKontakt($dane) { $crlf = "\n"; $from = 'info@kupmotor.pl'; $hdrs = array('From' => $from, 'X-Sender'=> $from, 'Reply-To'=> $from, 'Return-Path'=> $from, //'Bcc' => 'krystian@webandart.nu', 'Subject' => 'Bądźmy w kontakcie'); $mime = new Mail_mime($crlf); $template = new Smarty(); $template->left_delimiter = "{%"; $template->right_delimiter = "%}"; $template->assign('dane', $dane); $content = $template->fetch('email_kontakt.tpl'); $mime->addHTMLImage("img/email_top1.jpg"); $html = $content; $mail =& Mail::factory('mail'); $mime->setHTMLBody($html, false); $body = array(); $body['text_charset'] = 'utf-8'; $body['html_charset'] = 'utf-8'; $body['head_charset'] = 'utf-8'; $body = $mime->get($body); $hdrs = $mime->headers($hdrs); $mail->send('info@kupmotor.pl', $hdrs, $body); return true; } //}}} /* LOGGER */ //{{{ logger() function logger() { $data = date("Y-m-d H:i:s"); $plik = $_SERVER['SCRIPT_FILENAME']; $id_sesji = session_id(); $txt = "WYNIK: $wynik\n"; $txt .= "DATA: $data\n"; $txt .= "IP: {$_SERVER['REMOTE_ADDR']}\n"; $txt .= "SESJA: {$id_sesji}\n"; $txt .= "REQUEST_URI: {$this->request_uri}\n"; $txt .= "PLIK: $plik\n\n"; $txt .= "SESSION\n"; ob_start(); print_r($_SESSION); $txt.=ob_get_contents(); ob_end_clean(); $txt .= "\n\nREQUEST\n"; ob_start(); print_r($_REQUEST); $txt.=ob_get_contents(); ob_end_clean(); $txt .= "\n\nSERWER\n"; ob_start(); print_r($_SERVER); $txt.=ob_get_contents(); ob_end_clean(); $txt .= "\n\nFILES\n"; ob_start(); print_r($_FILES); $txt.=ob_get_contents(); ob_end_clean(); $txt .= "\n-----------------------\n"; $plik = CFG_KATALOG_ERRORLOG.'/logger/'.date("Y-m-d").'.log'; $fp = fopen($plik, 'a+'); fputs($fp, $txt); fclose($fp); return true; } //}}} /* PANEL */ //{{{ getOpisDaneForm() function getOpisDaneForm() { $lista = array(); $query = "select * from opisy where 1=1 order by kolejnosc, nazwa"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $lista[] = str_pad($row['id'], 4, "0", STR_PAD_LEFT).'|'.$row['numer'].'|'.$row['nazwa']; } } $tresc = implode("\n", $lista); return $tresc; } //}}} //{{{ getListaDaneForm() function getListaDaneForm($element) { $lista = array(); $query = "select * from {$element} where pokaz = 't' order by kolejnosc, nazwa"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $lista[] = str_pad($row['id'], 4, "0", STR_PAD_LEFT).'|'.$row['nazwa'].'|'.$row['nazwa_akol'].'|'.$row['opis']; } } $tresc = implode("\n", $lista); return $tresc; } //}}} //{{{ getListaModeleDaneForm() function getListaModeleDaneForm($element, $id_marki = 0) { $lista = array(); $query = "select * from {$element} where 1=1 and id_marki = '{$id_marki}' order by nazwa"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $lista[] = str_pad($row['id'], 4, "0", STR_PAD_LEFT).'|'.$row['nazwa']; } } $tresc = implode("\n", $lista); return $tresc; } //}}} //{{{ setOpisDaneForm() function setOpisDaneForm($lista) { $this->db->BeginTrans(); $query = "update opisy set pokaz = 'f'"; $result = $this->db->Execute($query); if (!$result) { $this->db->RollbackTrans(); return false; } $lista_a = array_map("trim", explode("\n", trim($lista))); foreach($lista_a as $kolejnosc=>$dane) { $dane_a = array_map("trim", explode('|', $dane)); $dane_elementu = array('id' => (int) $dane_a[0], 'numer' => $dane_a[1], 'nazwa' => $dane_a[2], 'pokaz' => 't', 'kolejnosc' => $kolejnosc); if (is_numeric($dane_elementu['id']) && $dane_elementu['id'] > 0) { $result = $this->db->AutoExecute('opisy', $dane_elementu, "UPDATE", "id = '{$dane_elementu['id']}'"); if (!$result) { $this->db->RollbackTrans(); return false; } } else { $query = "select nextval('opisy_id_seq') as id"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $row = $result->FetchRow(); $dane_elementu['id'] = $row['id']; $result = $this->db->AutoExecute('opisy', $dane_elementu, "INSERT"); if (!$result) { $this->db->RollbackTrans(); return false; } } } } $this->db->CommitTrans(); return true; } //}}} //{{{ setListaDaneForm() function setListaDaneForm($element, $lista) { $this->db->BeginTrans(); $query = "update {$element} set pokaz = 'f'"; $result = $this->db->Execute($query); if (!$result) { $this->db->RollbackTrans(); return false; } $lista_a = array_map("trim", explode("\n", trim($lista))); foreach($lista_a as $kolejnosc=>$dane) { $dane_a = array_map("trim", explode('|', $dane)); $dane_elementu = array('id' => (int) $dane_a[0], 'nazwa' => $dane_a[1], 'nazwa_akol' => $dane_a[2], 'opis' => $dane_a[3], 'pokaz' => 't', 'kolejnosc' => $kolejnosc); if (is_numeric($dane_elementu['id']) && $dane_elementu['id'] > 0) { $result = $this->db->AutoExecute($element, $dane_elementu, "UPDATE", "id = '{$dane_elementu['id']}'"); if (!$result) { $this->db->RollbackTrans(); return false; } } else { $query = "select nextval('{$element}_id_seq') as id"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $row = $result->FetchRow(); $dane_elementu['id'] = $row['id']; $result = $this->db->AutoExecute($element, $dane_elementu, "INSERT"); if (!$result) { $this->db->RollbackTrans(); return false; } } } } $this->db->CommitTrans(); return true; } //}}} //{{{ setListaModeleDaneForm() function setListaModeleDaneForm($element, $id_marki, $lista) { $this->db->BeginTrans(); $query = "update {$element} set pokaz = 't' where id_marki = '{$id_marki}'"; $result = $this->db->Execute($query); if (!$result) { $this->db->RollbackTrans(); return false; } $lista_a = array_map("trim", explode("\n", trim($lista))); foreach($lista_a as $dane) { $dane_a = array_map("trim", explode('|', $dane)); $dane_elementu = array('id' => (int) $dane_a[0], 'id_marki' => $id_marki, 'nazwa' => $dane_a[1], 'pokaz' => 't'); if (is_numeric($dane_elementu['id']) && $dane_elementu['id'] > 0) { $result = $this->db->AutoExecute($element, $dane_elementu, "UPDATE", "id = '{$dane_elementu['id']}'"); if (!$result) { $this->db->RollbackTrans(); return false; } } else { $query = "select nextval('{$element}_id_seq') as id"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $row = $result->FetchRow(); $dane_elementu['id'] = $id_elementu; $result = $this->db->AutoExecute($element, $dane_elementu, "INSERT"); if (!$result) { $this->db->RollbackTrans(); return false; } } } } $this->db->CommitTrans(); return true; } //}}} //{{{ getUzytkownicy() function getUzytkownicy() { $query = "select * from uzytkownicy order by id desc"; $result = $this->db->Execute($query); $lista = $result->GetRows(); return $lista; } //}}} //{{{ getKlienci() function getKlienci() { $query = "select * from klienci order by id desc"; $result = $this->db->Execute($query); $lista = $result->GetRows(); return $lista; } //}}} //{{{ getOgloszeniaPanel() function getOgloszeniaPanel() { $lista = array(); $query = "select id from ogloszenia order by id desc"; $result = $this->db->Execute($query); $lista_tmp = $result->GetRows(); foreach($lista_tmp as $value) { $ogloszenie = $this->getOgloszenie($value['id']); $dane = $ogloszenie->rekord_db; $dane['klient_nazwa'] = $ogloszenie->klient_db['nazwa']; $lista[] = $dane; } return $lista; } //}}} //{{{ getStrony() function getStrony() { $query = "select * from strony order by id desc"; $result = $this->db->Execute($query); $lista = $result->GetRows(); return $lista; } //}}} //{{{ getKontakty() function getKontakty() { $query = "select * from kontakt order by id desc"; $result = $this->db->Execute($query); $lista = $result->GetRows(); return $lista; } //}}} //{{{ getTopy() function getTopy() { $query = "select t.*, (select count(*) from zdjecia_topy zt where zt.id_topu = t.id) as ilosc_zdjec, (select 'data/topy/'||zt.id_topu||'/m/'||plik from zdjecia_topy zt where zt.id_topu = t.id order by id limit 1) as plik from topy t order by id desc"; $result = $this->db->Execute($query); $lista = $result->GetRows(); return $lista; } //}}} //{{{ getUstawienia() function getUstawienia() { $query = "select * from ustawienia where id = 1"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $row = $result->FetchRow(); return $row; } } //}}} //{{{ zapiszUstawienia() function zapiszUstawienia($dane) { $this->db->AutoExecute("ustawienia", $dane, "UPDATE", "id = 1"); } //}}} //{{{ generujListaJs() function generujListaJs() { $content = 'var motorbikes = {'; $content_a = array(); $query = "select * from lista_view order by nazwa"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $row = array_map("trim", $row); $row['nazwa'] = str_replace('"', "", $row['nazwa']); $content_a[] = "\"{$row['id_marki']}_{$row['id_modelu']}\": \"{$row['nazwa']}\""; } } $content .= implode(',', $content_a); $content .= '}'; $fp = fopen("js/motorbikes.js", 'w+'); fputs($fp, $content); fclose($fp); return true; } //}}} //{{{ getMarkaModelFromNazwa() function getMarkaModelFromNazwa($nazwa) { $query = "select * from lista_view where nazwa = '{$nazwa}'"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { $row = $result->FetchRow(); return $row; } return false; } //}}} /* POZOSTALE*/ //{{{ getModeleByIdMarki() function getModeleByIdMarki($id_marki = null) { $inny = false; $lista = array(); if (is_numeric($id_marki)) { $query = "select * from modele where id_marki = '{$id_marki}' order by nazwa"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); if ($row['nazwa'] == 'Inny' || $row['nazwa'] == 'inny') { $inny = $row; } else { $lista[] = $row; } } } if ($inny !== false) { $lista[] = $inny; } } return $lista; } //}}} //{{{ checkLogin() function checkLogin($username) { $query = "select * from klienci where username = '{$username}'"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { return false; } return true; } //}}} //{{{ generujOpisy() function generujOpisy() { $opisy = array(); $lista = array(); $query = "select * from opisy"; $result = $this->db->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $lista[$row['numer']][] = $row['nazwa']; } } foreach($lista as $numer=>$lista_element) { $rnd = rand(0, count($lista_element)-1); $opisy[$numer] = $lista_element[$rnd]; } return $opisy; } //}}} /* NOTOS */ //{{{ getNotosSklepKategorie() function getNotosSklepKategorie($db_notos) { $lista = array(); $query = "select distinct kategorie from sklep_produkty_lista_widok where udostepnij = 't' order by kategorie"; $result = $db_notos->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $lista[] = $row['kategorie']; } } return $lista; } //}}} //{{{ getNotosSklepProdukty() function getNotosSklepProdukty($db_notos) { $lista = array(); $query = "select id from sklep_produkty_lista_widok where pokaz = 't' and udostepnij = 't' order by random() limit 20"; $result = $db_notos->Execute($query); if ($result && $result->RecordCount() > 0) { for($i=0; $i<$result->RecordCount(); $i++) { $row = $result->FetchRow(); $produkt = SklepProdukt::pobierz($db_notos, $row['id']); if (is_object($produkt)) { $lista[] = $produkt; } } } return $lista; } //}}} /* PRIVATE */ //{{{ _setSlowniki() function _setSlowniki($dane) { $dane['marka'] = $this->slowniki['marki'][$dane['id_marki']]['nazwa']; $dane['model'] = $this->slowniki['modele'][$dane['id_modelu']]['nazwa']; $dane['rodzaj'] = $this->slowniki['rodzaje'][$dane['id_rodzaju']]['nazwa']; $dane['naped'] = $this->slowniki['typy_napedow'][$dane['id_napedu']]['nazwa']; $dane['paliwo'] = $this->slowniki['paliwa'][$dane['id_paliwa']]['nazwa']; $dane['kolor'] = $this->slowniki['kolory'][$dane['id_koloru']]['nazwa']; $dane['skrzynia'] = $this->slowniki['skrzynie_biegow'][$dane['id_skrzynii']]['nazwa']; $skrzynia_opis = $this->slowniki['skrzynie_biegow'][$dane['id_skrzynii']]['opis']; $skrzynia_opis_a = explode(';', $skrzynia_opis); $dane['skrzynia_opis'] = $skrzynia_opis_a[rand(0, count($skrzynia_opis_a)-1)]; $naped_opis = $this->slowniki['typy_napedow'][$dane['id_napedu']]['opis']; $naped_opis_a = explode(';', $naped_opis); $dane['naped_opis'] = $naped_opis_a[rand(0, count($naped_opis_a)-1)]; $stan_opis = $this->slowniki['stan_techniczny'][$dane['id_stanu']]['opis']; $stan_opis_a = explode(';', $stan_opis); $dane['stan_opis'] = $stan_opis_a[rand(0, count($stan_opis_a)-1)]; $pochodzenie_opis = $this->slowniki['pochodzenie'][$dane['id_pochodzenia']]['opis']; $pochodzenie_opis_a = explode(';', $pochodzenie_opis); $dane['pochodzenie_opis'] = $pochodzenie_opis_a[rand(0, count($pochodzenie_opis_a)-1)]; $kraje_opis = $this->slowniki['kraje'][$dane['id_kraju']]['opis']; $kraje_opis_a = explode(';', $kraje_opis); $dane['kraje_opis'] = $kraje_opis_a[rand(0, count($kraje_opis_a)-1)]; $historia = array(); $historia_a = array_map("intval", explode(';', $dane['historia'])); foreach($historia_a as $element) { if ($this->slowniki['historia'][$element]['nazwa']) { $historia[] = $this->slowniki['historia'][$element]['nazwa']; } } $dane['historia'] = implode(", ", $historia); $wyposazenie = array(); $wyposazenie_a = array_map("intval", explode(';', $dane['wyposazenie'])); foreach($wyposazenie_a as $element) { if ($this->slowniki['wyposazenie'][$element]['nazwa']) { $wyposazenie[] = $this->slowniki['wyposazenie'][$element]['nazwa']; } } $dane['wyposazenie'] = implode(", ", $wyposazenie); $dodatkowe_informacje = array(); $dodatkowe_informacje_opisy = array(); $dodatkowe_informacje_a = array_map("intval", explode(';', $dane['dodatkowe_informacje'])); foreach($dodatkowe_informacje_a as $element) { if ($this->slowniki['dodatkowe_informacje'][$element]['nazwa']) { $dodatkowe_informacje[] = $this->slowniki['dodatkowe_informacje'][$element]['nazwa']; $dodatkowe_opisy_a = explode(';', $this->slowniki['dodatkowe_informacje'][$element]['opis']); $opis = $dodatkowe_opisy_a[rand(0, count($dodatkowe_opisy_a)-1)]; if ($opis) { $dodatkowe_informacje_opisy[] = $opis; } } } $dane['dodatkowe_informacje'] = implode(", ", $dodatkowe_informacje); $dane['dodatkowe_informacje_opisy'] = implode(", ", $dodatkowe_informacje_opisy); $dane['status_sprowadzenia'] = $this->slowniki['status_sprowadzenia'][$dane['id_status_sprowadzenia']]['nazwa']; return $dane; } //}}} } ?>