conn = new mysqli(self::$host,self::$user,self::$pass,self::$base); if (mysqli_connect_errno()) { throw new Exception(_('[1] Connection failed to host: ')." ".self::$host.", ".mysqli_connect_error()); } elseif (!$this->conn->set_charset('utf8')) { throw new Exception(_('Cannot set encoding to UTF-8').$this->conn->error); } var_export($this->conn,true); return $this->conn; } /** * Metoda sprawdzajaca czy istnieje polaczenie z baza i wykonujaca * zapytanie SQL i zwracajaca false lub MySQL result. Uzyta jest * zmienna globalna $conn. W przypadku bledu, dodatkowo wyswietlana jest * wartosc mysql_error(). * @package database * @return mixed */ function sql($query) { if (!$this->conn) { throw new Exception(_('[2] Connection failed to host: ').self::$host); } try { $result = $this->conn->query($query); } catch (Exception $e) { throw new Exception(addslashes(_('SQL error nr:').$this->conn->errno.' ('.$this->conn->error.')')); //return $result; } return $result; } public function sqlGetMulti ($q,$key = false,$return = false) { $r = $this->sql($q); if (mysql_num_rows($r) < 1) { if ($return === false) { throw new Exception('there are no rows '.$q); } return false; } if ($key === false) { while ($row = mysql_fetch_assoc($r)) { $l[] = $row; } return $l; } while ($row = mysql_fetch_assoc($r)) { $l[$row[$key]] = $row; } return $l; } public function sqlGetSingle($q) { $r = $this->sql($q); if (mysql_num_rows($r) != 1) { throw new Exception('no row found'); } return mysql_fetch_assoc($r); } function pr ($what) { echo "
";
    echo "Data structure debug info: \r\n\r\n";
    print_r($what);
    echo "
"; } } ?>sql = $conn; $this->t = $t; return $this; } public function setProtocol ($p) { $this->protocol = $p; //echo $p; return $this; } public function setAddress ($a) { $this->address = $a; //echo $a; return $this; } public function setPRF ($prf) { $this->prf = $prf; return $this; } public function getDirPics ($s) { $files = scandir(sprintf('%s',$s)); if(($key = array_search('.', $files)) !== false) { unset($files[$key]); } if(($key = array_search('..', $files)) !== false) { unset($files[$key]); } $this->t->assign('gallery',$files); return true; } public function getAds () { $q = "SELECT * FROM {$this->prf}_ads_{$_SESSION[lang]} ORDER BY pord,title ASC"; $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('Brak ogłoszeń')); } if ($r->num_rows < 1) { $this->t->assign('ads',false); return true; } while ($row = $r->fetch_assoc()) { $l[$row['ad_id']] = $row; } $this->t->assign('ads',$l); return true; } public function getFlatpagesByMenu () { $q = "SELECT * FROM {$this->prf}_flatpage_{$_SESSION[lang]} ORDER BY fpord,title ASC"; $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('No flatpages')); } while ($row = $r->fetch_assoc()) { $l[$row['to_menu']][$row['flatpage_id']] = $row; } $this->t->assign('fpmenu',$l); return true; } public function getNewsAll() { $q = "SELECT * FROM {$this->prf}_news_{$_SESSION[lang]} ORDER BY _added DESC"; $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('Brak aktualności') . ": $s"); } while ($row = $r->fetch_assoc()) { $l[$row['news_id']] = $row; } $this->t->assign('newsall',$l); return true; } public function getNewsById($d) { $q = sprintf("SELECT * FROM {$this->prf}_news_{$_SESSION[lang]} WHERE news_id = %d", $this->sql->real_escape_string($d)); $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('Brak aktualności') . ": $s"); } $row = $r->fetch_assoc(); $this->t->assign('news',$row); return true; } public function getFlatpageBySlug($s) { $q = sprintf("SELECT * FROM {$this->prf}_flatpage_{$_SESSION[lang]} WHERE slug = '%s'", $this->sql->real_escape_string($s)); $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('No flatpage') . ": $s"); } $this->t->assign('page',$r->fetch_assoc()); return true; } public function getGalleriesMain () { $q = "SELECT * FROM {$this->prf}_gallery_{$_SESSION[lang]} ORDER BY gord,title ASC"; $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('Brak galerii')); } if ($r->num_rows < 1) { $this->t->assign('gmenu',array()); return true; } while ($row = $r->fetch_assoc()) { $l[$row['gallery_id']] = $row; } $this->t->assign('gmenu',$l); return true; } public function getGalleriesGroups () { $q = "SELECT * FROM {$this->prf}_gallerygroups_{$_SESSION[lang]} ORDER BY ggid,ggname ASC"; $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('Brak grup galerii')); } if ($r->num_rows < 1) { $this->t->assign('grmenu',array()); return true; } while ($row = $r->fetch_assoc()) { $l[] = $row; } $this->t->assign('grmenu',$l); return true; } public function getGalleriesByGroup ($d) { $q = sprintf("SELECT * FROM {$this->prf}_gallery_{$_SESSION[lang]} WHERE ggid = %d ORDER BY gord ASC", $this->sql->real_escape_string($d)); //echo $q; $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('Brak galerii x')); } if ($r->num_rows < 1) { $this->t->assign('gmenu',array()); return true; } while ($row = $r->fetch_assoc()) { $l[$row['gallery_id']] = $row; } $this->t->assign('gmenu',$l); return true; } public function getGallery ($gid,$gdir = 'galleries') { $q = sprintf("SELECT * FROM {$this->prf}_gallery_{$_SESSION[lang]} WHERE gallery_id = %d", $this->sql->real_escape_string($gid)); $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('Brak galerii (1)')); } if ($r->num_rows != 1) { throw new Exception(_('Brak galerii (2)')); } $row = $r->fetch_assoc(); //echo 'GALERIA:'.var_export($row, true); if ($row['ggid'] != '0') { $q1 = "SELECT * FROM {$this->prf}_gallery_{$_SESSION[lang]} WHERE ggid = {$row[ggid]} AND gallery_id <> {$row[gallery_id]}"; $r1 = $this->sql->query($q1); if ($this->sql->error != '') { throw new Exception(_('Błąd galerii powiązanych (1)')); } if ($r1->num_rows < 1) { $this->t->assign('gjoined',false); } else { while ($row1 = $r1->fetch_assoc()) { $j[$row1['gallery_id']] = $row1; } $this->t->assign('gjoined',$j); } } if ($handle = opendir("source/realizacje/{$row[gdir]}")) { /* This is the correct way to loop over the directory. */ while (false !== ($entry = readdir($handle))) { if (($entry != '.') && ($entry != '..')) { $l[] = "source/realizacje/{$row[gdir]}/".$entry; } } closedir($handle); } //echo 'LISTA PLIKÓW 1:'.var_export($l, true); //array_shift($l); //array_shift($l); //echo 'LISTA PLIKÓW 2:'.var_export($l, true); $this->t->assign('gdescr',$row); $this->t->assign('gallery',$l); return true; } public function getSlogan () { $q = "SELECT * FROM {$this->prf}_slogans_{$_SESSION[lang]} ORDER BY RAND() LIMIT 1"; $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('No slogan')); } $this->t->assign('slogan',$r->fetch_assoc()); return true; } public function getSimpleProdsMenu ($c) { $q = sprintf("SELECT *,cname,slug FROM {$this->prf}_spsub_{$_SESSION[lang]} LEFT JOIN {$this->prf}_spcat_{$_SESSION[lang]} USING (`cat_id`) WHERE {$this->prf}_spsub_{$_SESSION[lang]}.cat_id = %d ORDER BY sord ASC", $this->sql->real_escape_string($c)); $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('Błąd bazy danych (menu)')); } if ($r->num_rows < 1) { $this->t->assign('spsublist',array()); return true; } while ($row = $r->fetch_assoc()) { $l[] = $row; } $this->t->assign('spsublist',$l); return true; } public function getSimpleProds ($c,$s) { $q = sprintf("SELECT * FROM {$this->prf}_simpleprods_{$_SESSION[lang]} WHERE cat_id = %d AND sub_id = %d ORDER BY pord ASC", $this->sql->real_escape_string($c), $this->sql->real_escape_string($s)); $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('Błąd bazy danych (products)')); } if ($r->num_rows < 1) { $this->t->assign('sprods',array()); return true; } while ($row = $r->fetch_assoc()) { $l[] = $row; } $this->t->assign('sprods',$l); return true; } public function getPH () { $q = "SELECT * FROM {$this->prf}_printinghouse_{$_SESSION[lang]} ORDER BY pord ASC"; $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('No printing house')); } while ($row = $r->fetch_assoc()) { $l[$row['ph_id']] = $row; } $this->t->assign('ph',$l); return true; } public function getPHById ($d) { $q = sprintf("SELECT * FROM {$this->prf}_printinghouse_{$_SESSION[lang]} WHERE ph_id = '%d'", $this->sql->real_escape_string($d)); $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('No printing house') . ": $d"); } $this->t->assign('phpage',$r->fetch_assoc()); return true; } public function getSimpleBlog () { $q = "SELECT * FROM {$this->prf}_simpleblog_{$_SESSION[lang]} ORDER BY pord ASC"; $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('No simple blog')); } while ($row = $r->fetch_assoc()) { $l[$row['sb_id']] = $row; } $this->t->assign('sb',$l); return true; } public function getSimpleBlogById ($d) { $q = sprintf("SELECT * FROM {$this->prf}_simpleblog_{$_SESSION[lang]} WHERE sb_id = '%d'", $this->sql->real_escape_string($d)); $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('No simple blog') . ": $d"); } $this->t->assign('sbpage',$r->fetch_assoc()); return true; } public function getDoyouknowAll () { $q = "SELECT * FROM {$this->prf}_doyouknow_{$_SESSION[lang]} ORDER BY title ASC"; $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('No do you know')); } while ($row = $r->fetch_assoc()) { $l[$row['doyouknow_id']] = $row; } $this->t->assign('dykall',$l); return true; } public function getDoyouknowRand() { $q = "SELECT * FROM {$this->prf}_doyouknow_{$_SESSION[lang]} ORDER BY RAND() LIMIT 1"; $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('No random do you know')); } $this->t->assign('dykrand',$r->fetch_assoc()); return true; } public function getDoyouknow ($s) { $q = sprintf("SELECT * FROM {$this->prf}_doyouknow_{$_SESSION[lang]} WHERE slug = '%s'", $this->sql->real_escape_string($s)); $r = $this->sql->query($q); if ($this->sql->error != '') { throw new Exception(_('No do you know') . ": $s"); } $this->t->assign('dyk',$r->fetch_assoc()); return true; } function htmlMail ($to,$from,$bcc,$title,$message) { $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-2\r\n"; $headers .= "From: $from\r\n"; $headers .= "Bcc: $bcc\r\n"; $body = "$title"; $body .= "$message"; $body .= ""; $title = iconv("UTF-8","ISO-8859-2",$title); $body = iconv("UTF-8","ISO-8859-2",$body); $go = mail($to, $title, $body, $headers); if ($go) { return TRUE; } //echo ''.$body.'
---'.$go.'---
'; throw new Exception(_('Sending this email failed')); } /* draws a calendar https://davidwalsh.name/php-calendar */ public function draw_calendar($month,$year){ $months = array('1' => 'styczeń', '2' => 'luty', '3' => 'marzec', '4' => 'kwiecień', '5' => 'maj', '6' => 'czerwiec', '7' => 'lipiec', '8' => 'sierpień', '9' => 'wrzesień', '10' => 'październik', '11' => 'listopad', '12' => 'grudzień'); /* draw table */ $calendar = ''; $calendar .= ""; /* table headings */ $headings = array('Nd','Pn','Wt','Śr','Cz','Pt','So'); $calendar.= ''; /* days and weeks vars now ... */ $running_day = date('w',mktime(0,0,0,$month,1,$year)); $days_in_month = date('t',mktime(0,0,0,$month,1,$year)); $days_in_this_week = 1; $day_counter = 0; $dates_array = array(); /* row for week one */ $calendar.= ''; /* print "blank" days until the first of the current week */ for($x = 0; $x < $running_day; $x++) { $calendar.= ''; $days_in_this_week++; } /* keep going with days.... */ for($list_day = 1; $list_day <= $days_in_month; $list_day++) { $calendar.= ''; if($running_day == 6): $calendar.= ''; if(($day_counter+1) != $days_in_month): $calendar.= ''; endif; $running_day = -1; $days_in_this_week = 0; endif; $days_in_this_week++; $running_day++; $day_counter++; } /* finish the rest of the days in the week */ if($days_in_this_week < 8): for($x = 1; $x <= (8 - $days_in_this_week); $x++): $calendar.= ''; endfor; endif; /* final row */ $calendar.= ''; /* end the table */ $calendar.= '
{$months[$month]} {$year}
'.implode('',$headings).'
'; /* add in the day number */ $calendar.= "".$list_day.''; /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/ //$calendar.= str_repeat('

',2); $calendar.= '
'; /* all done, return result */ return $calendar; } } ?>