fphp //@session_name("_pc"); use Symfony\Component\Debug\Debug; if (!defined("IZNUTRA")) exit('Pristup Zabranjen'); if (!defined("INCDIR")) { if (strpos($_SERVER['HTTP_HOST'], 'phone-travel') !== false) define("INCDIR", 'mojaavantura/inc'); else define("INCDIR", 'inc'); } @session_start(); include_once('dbConn.php'); require('konstante.php'); /*if(file_exists($_SERVER['DOCUMENT_ROOT']."/".INCDIR. '/delovi_strane.php')) include_once('delovi_strane.php');*/ function ke($arr, $ind) { if (isset($arr[$ind])) return $arr[$ind]; else return NULL; } function ker($ind) { return ke($_REQUEST, $ind); } function kes($ind) { return ke($_SESSION, $ind); } function ms($str, $len, $suf = '...') { // $sh = mb_substr(stripTags($str), 0, $len); if (mb_strlen($str = stripTags($str)) <= $len) return $str; return mb_substr($str, 0, $len) . $suf; } function qs($value, $noquote = false) { // Stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); } if ($noquote) return mysqli_real_escape_string(dbConn(), $value); else return "'" . mysqli_real_escape_string(dbConn(), $value) . "'"; } function qsa($niz) { foreach ($niz as $k => $v) $niz[$k] = qs($v); return $niz; } function qker($ind, $noquote = false) { return qs(trim(ker($ind)), $noquote); } function sqker($ind, $tags = '') { return qs(stripTags(ker($ind), $tags)); } function hsc($str) { return htmlspecialchars($str, ENT_QUOTES); } function dp($pod) { global $Podesavanja, $PODESAVANJA; //$start = time(true); if (ke($Podesavanja, $pod)) return $Podesavanja[$pod]; $Podesavanja[$pod] = (($p = Mysql::SkalarIzBaze("SELECT vrednost FROM podesavanja WHERE naziv='$pod'")) === NULL ? ke($Podesavanja, $pod) : $p); // echo($pod.": ".(time(true)-$start)); return $Podesavanja[$pod]; } function cenaFormat($cen) { $cen = is_numeric((double)$cen) ? (double)$cen : 0; return number_format($cen, 2, ',', '.'); } function obradiSlike($s) { return $s; } function evalb($c) { ob_start("mb_output_handler"); eval($c); $c = ob_get_contents(); @ob_end_clean(); return $c; } function inc($put, $once = true) { if ($once) return include_once($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $put); else return include($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $put); } function incEval($put, $once = true) { ob_start("mb_output_handler"); if ($once) include_once($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $put); else include($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $put); $c = ob_get_contents(); @ob_end_clean(); return $c; } /** * Vraca putanju do slike odgovarajucih dimenzija * * @param mixed $path Putanja do orginalne * @param mixed $w Sirina * @param integer $h Visina * @param integer $q Kvalitet * @param integer $z Forsiraj dimenzije (true) ili je ubaci celu u zadate * @param bool $testirano Zna se da postoji * @return */ function dajSl($path, $w, $name = '', $z = 0) { return dajSliku($path, $w, 0, 80, $z, false, $name); } function dajSliku($path, $w, $h = 0, $q = 80, $z = 0, $testirano = false, $name = '') { $rpath = $path; if (!($isf = is_file($_SERVER['DOCUMENT_ROOT'] . $path))) $opath = $path; else $opath = false; $nema = false; $path = $_SERVER['DOCUMENT_ROOT'] . $path; if (!$isf) { $path = str_replace('/mojaavantura/', '/', $path); if (!($isf = is_file($path))) $opath = $rpath; else $opath = false; } if (strpos($path, 'dusko')) error_log($path . '-nema' . $opath); if (!$testirano) { if (!($isf && ($size = imgSize($path)))) { $path = $_SERVER['DOCUMENT_ROOT'] . "/" . INCDIR . "/images/nemaslika.jpg"; $rpath = "/" . INCDIR . "/images/nemaslika.jpg"; } } $size = imgSize($path); $pi = pathinfo($path); $imeFajla = $pi['filename']; if ($name) { //if(jelLatinica()) $name = CirLat($name); $name = pocistiURL($name); $imeFajla = $name; //$name = $name.'.'.$pi['extension']; } //if($name) $path = urlencode($path); if ($w > 0) $query = "src=$path&q=$q&zc=$z" . ($w ? "&w=$w" : "") . ($h ? "&h=$h" : ""); else { global $Thumbs; if (!ke($Thumbs, -$w)) $w = -1; $query = http_build_query(array("src" => $path) + $Thumbs[-$w]); } if ($opath) { if ((strpos($_SERVER['HTTP_HOST'], 'vodic') !== false OR strpos($_SERVER['HTTP_HOST'], 'mojaavantura') !== false)) return "http://www.phone-travel.com" . $opath . "?thumb=" . (-$w); /* if((strpos($_SERVER['HTTP_HOST'], 'phone-travel.com') !== false)) return "http://www.mojaavantura.com".$opath."?thumb=".(-$w);*/ } $md5 = md5($query . $path, false); Mysql::skalarIzBaze("INSERT INTO slicice (serverpath, naziv, putanja, md5, query, w, h) VALUES (" . qs(urldecode($rpath)) . ", '$imeFajla', " . qs(urldecode($path)) . ", '$md5', " . qs(urldecode($query)) . ", $size[0], $size[1]) ON DUPLICATE KEY UPDATE broj_generisanja = broj_generisanja + 1"); return "/pic/" . urldecode($imeFajla) . "_$md5." . @$pi[extension]; } function dajVelicinuSlike($Opath, $w = 0, $h = 0, $q = 80, $z = 0) { global $Thumbs; if ($w < 0) { $h = $Thumbs[-$w]['h']; $z = $Thumbs[-$w]['zc']; $w = $Thumbs[-$w]['w']; } $path = $_SERVER['DOCUMENT_ROOT'] . $Opath; if (!is_file($path)) $path = str_replace('/mojaavantura', '', $path); if (!(is_file($path) && ($size = imgSize($path)))) { //error_log($path.' - nijeslika'); $path = $_SERVER['DOCUMENT_ROOT'] . "/" . INCDIR . "/images/nemaslika.jpg"; $size = imgSize($path); $size[2] = false; } else $size[2] = true; //$path = dajSliku($path, $w, $h, $q, $z, !isset($size[7])); if (!$w && !$h) return $size; if ($z) return array($w, $h, $size[2]); $sz = ProportionalResize($size[0], $size[1], $w, $h); $sz[2] = $size[2]; return $sz; } function dajAttrSlike($path, $w, $h = 0, $q = 80, $z = 0, $name = '', $l = false) { $size = dajVelicinuSlike($path, $w, $h, $q, $z); if ($l) $l = 'l'; else $l = ''; $path = dajSliku($path, $w, $h, $q, $z, $size[2], $name); return " width=\"" . $size[0] . "\" height=\"" . $size[1] . "\" " . $l . "src=\"$path\" "; } function imgSize($filename) { static $Slicice = array(); if (ke($Slicice, $filename)) return $Slicice[$filename]; $s = Mysql::redIzBaze("SELECT w, h FROM slicice WHERE putanja = '$filename' LIMIT 0,1"); //return array(100, 100); if ($s['w'] && $s['h']) return $Slicice[$filename] = array($s['w'], $s['h']); else { if ($Slicice[$filename] = getimagesize($filename)) return $Slicice[$filename]; else { error_log('getimagesize: ' . $filename); return array(10, 10); } } } /** * Vraca ceo img tag za sliku * * @param string $path Putanja do slike * @param mixed $w * @param integer $h * @param string $att dodatni atributi * @param integer $q * @param integer $z * @return */ function dajImgTag($path, $w, $h = 0, $att = '', $q = 80, $z = 0, $name = '', $l = false) { return ""; } function dajImg($path, $w, $att = '', $name = '', $z = 0, $later = false) { return ""; } function dajImgL($path, $w, $att = '', $name = '', $later = false, $z = 0) { return ""; } /** * Vraca sliku sa hs * * @param mixed $path * @param mixed $w * @param integer $h * @param string $g - grupa za slideshow * @param string $att - atributi same slike * @param integer $q - * @param integer $z * @param string $hsOpt - parametri za hs.expand, stringovi uokvireni ' * @return */ function dajThumbHS($path, $thumb = -1, $alt, $caption = '', $iatt = "", $group = "", $aatt = "", $hsOpt = "") { //if(!$caption) $caption = $alt; $aatt .= " title='" . hsc($alt) . "' "; $iatt .= ($caption ? " hscaption='" . hsc($caption) . "'" : '') . " alt='" . hsc($alt) . "' " . ($group ? " hsgroup='$group' " : '') . ($hsOpt ? " data-hsoptions='" . hsc($hsOpt) . "' " : "") . " title='" . hsc($alt) . "' "; ///return dajHS($path, $thumb, 1, '', $iatt, 80, 0, '', hsc($alt), '_hsauto highslide', $aatt); return "" . dajImgTag($path, $thumb, 1, $iatt, 80, 0, hsc($alt)) . ""; }/* function dajHS($path, $w, $h=0, $g='', $att='', $q=80, $z=0, $hsOpt='', $name='', $aclass='highslide', $aatt=''){ return "" .dajImgTag($path, $w, $h, $att, $q, $z, $name) .""; } */ function dajHS($path, $w, $h = 0, $g = '', $att = '', $q = 80, $z = 0, $hsOpt = '', $name = '', $aclass = '', $aatt = '') { if ($hsOpt) $hsOpt = ', ' . $hsOpt; return "" . dajImgTag($path, $w, $h, $att, $q, $z, $name) . ""; } function dajFBox($path, $w, $h = 0, $g = '', $att = '', $name = '', $aatt = '', $aclass = '', $z = 0, $q = 80, $l = '') { if ($aclass) $aclass = "class='$aclass'"; else $aclass = ''; return "" . dajImgTag($path, $w, $h, $att, $q, $z, $name, $l) . ""; } function dajHSND($path, $w, $h = 0, $g = '', $att = '', $q = 80, $z = 0, $name = '') { return "" . ""; } function dajHSlink($path, $w, $h = 0, $g = '', $linkText = 'Линк', $q = 80, $z = 0, $hsOpt = '', $name = '') { $hsOpt = ', ' . $hsOpt; return "" . $linkText . ""; } function ProportionalResize($old_width, $old_height, $new_width = false, $new_height = false) { $old_aspect_ratio = $old_width / $old_height; if (($new_width === false) && ($new_height === false)) { return false; } elseif ($new_width === false) { $new_width = $new_height * $old_aspect_ratio; } elseif ($new_height === false) { $new_height = $new_width / $old_aspect_ratio; } $new_aspect_ratio = $new_width / $new_height; if ($new_aspect_ratio == $old_aspect_ratio) { // great, done } elseif ($new_aspect_ratio < $old_aspect_ratio) { // limited by width $new_height = $new_width / $old_aspect_ratio; } elseif ($new_aspect_ratio > $old_aspect_ratio) { // limited by height $new_width = $new_height * $old_aspect_ratio; } return array(round($new_width), round($new_height)); } /* function dajHSVideo($kod, $naslov, $thumb = true, $caption='', $class='', $imgClass='', $deviceGroup='html'){ return "\n\n\t" .($thumb ? "".htmlspecialchars($naslov)."" .'' : $naslov ) .""; }*/ function dajHSVideo($kod, $naslov, $thumb = true, $caption = '', $class = '', $imgClass = '', $group = 'html') { return "\n\n\t" . ($thumb ? "" . htmlspecialchars($naslov) . "" . '' : $naslov ) . ""; } function dajGaleriju($id = 0, $table = 'galleryitem', $foreigntable = 'gallery', $extraimage = false) { if (!$id) return ''; if (is_array($id)) $sls = $id; else { $sls = Mysql::nizIzBaze($sql = "SELECT naziv AS Naziv, imgsrc, video FROM $table WHERE sif_$foreigntable=$id AND sif_status=1 ORDER BY ds DESC"); if ($extraimage) array_unshift($sls, $extraimage); } // $sls [] = $extraimage; // echo $sql; $i = 0; $ls = ''; $o = "
"; foreach ($sls as $sl) { $o .= " "; } $o .= "
" . $ls . "
"; return $o; } //onclick=' return hs.htmlExpand(this, inPageOptionsYoutube ) ' /** * @param $sql * @param max items per page $pos * @return array ( * strane (html snipet za strane) * brojStrana, * tekucaStrana, * brojZapisa, * prvi, * poslednji, * limit (za sql), * po (input za unos broja elementa po strani), * link_prethodna (uri za prethodnu), * link_sledeca, * link_poslednja, * link_prva * ) */ function paginacija($sql, $pos = 15, $hash = '', $countable = true) { $od = (int)ker('od_'); $po = (int)ker('po_'); $od = ($od and $od > 0) ? $od : 0; $po = ($po and $po < $pos and $po > 0) ? $po : $pos; return nabrojStrane($od, $po, $sql, false, '', 10, $countable, $hash); } function nabrojStrane($od, $po, $sql, $link = false, $pf = '', $maxStrana = 10, $countable = true, $hash = '') { $maxStrana++; $nabrajanje['sql'] = $sql; if (is_int($sql)) $brojZapisa = $sql; else { if ($countable) { $sql = "SELECT COUNT(*) " . mb_substr($sql, mb_strpos($sql, "FROM")); $brojZapisa = Mysql::skalarIzBaze($sql); } else { $bz = new Mysql($sql); $brojZapisa = $bz->dajBroj(); } } //echo $sql; $brojStrana = ceil($brojZapisa / $po); $nabrajanje['brojStrana'] = $brojStrana; $tekuca = ceil(($od + $po) / $po); $nabrajanje['tekucaStrana'] = $tekuca; $nabrajanje['brojZapisa'] = $brojZapisa; $nabrajanje['prvi'] = $od + 1; $nabrajanje['poslednji'] = ($od + $po > $brojZapisa ? $brojZapisa : $od + $po); $nabrajanje['limit'] = " LIMIT " . $od . "," . $po . " "; $nabrajanje['sql'] .= $nabrajanje['limit']; $prlink = $sllink = $strane = ""; $i = 1; // echo "1.".$_SERVER['QUERY_STRING']; if ($link) parse_str($link, $qryArr); else { parse_str($_SERVER['QUERY_STRING'], $qryArr); $qryArr = array_merge($qryArr, $_POST); } unset($qryArr['pw'], $qryArr['un']); $href = $link . "&od_$pf=" . (($i - 1) * $po) . "&po_$pf=$po$hash"; $qryArr["od_$pf"] = ($i - 1) * $po; $qryArr["po_$pf"] = $po; $nabrajanje['po'] = ""; $href = "?" . http_build_query($qryArr); $prva = $poslednja = $pr = $sl = ""; // if($tekuca!=1) $pr=" "; $strane = " " . $tekuca . " "; // echo $brojStrana.'-'.$tekuca; $l = $d = 1; for ($n = 0; $l + $d < $maxStrana && $l + $d <= $brojStrana;) { if ($l < $tekuca) { $qryArr["od_$pf"] = ($tekuca - $l - 1) * $po; $href = "?" . (http_build_query($qryArr)) . $hash; if ($l == 1) { if ($qryArr["od_$pf"] == 0) { //unset($qryArr["od_$pf"]); //unset($qryArr["po_$pf"]); // $qryArr["od_$pf"]=0; if (count($qryArr)) $href = "?" . (http_build_query($qryArr)) . $hash; else $href = '' . $hash; } $pr = " " . dajRecAPFE('prethodna_strana') . "  "; $nabrajanje['link_prethodna'] = htmlspecialchars_decode($href); } $strane = " " . ($tekuca - $l) . " " . $strane; $l++; } if ($d + $tekuca <= $brojStrana) { $qryArr["od_$pf"] = ($tekuca + $d - 1) * $po; $href = "?" . (http_build_query($qryArr)) . $hash; if ($d == 1) { $sl = " " . dajRecAPFE('sledeca_strana') . "  "; $nabrajanje['link_sledeca'] = htmlspecialchars_decode($href); } $strane .= " " . ($tekuca + $d) . " "; $d++; } } $strane = $pr . $strane; $strane .= $sl; $qryArr["od_$pf"] = ($brojStrana - 1) * $po; $href = "?" . (http_build_query($qryArr)) . $hash; if ($tekuca != $brojStrana) { $strane .= "" . dajRecAPFE('poslednja_strana') . " "; $nabrajanje['link_poslednja'] = htmlspecialchars_decode($href); } if ($tekuca != 1) { $qryArr["od_$pf"] = 0; $qryArr["po_$pf"] = $po; if (count($qryArr)) $href = "?" . (http_build_query($qryArr)) . $hash; else $href = $hash; $strane = "" . dajRecAPFE('prva_strana') . "  " . $strane; $nabrajanje['link_prva'] = htmlspecialchars_decode($href); } if ($brojZapisa) $nabrajanje['strane'] = $strane; else $nabrajanje['strane'] = ''; return $nabrajanje; } function dajRecAPFE($rec) { if (ke($_COOKIE, 'un')) return dr($rec); return dajRec($rec); }function oSlike(){$f = __DIR__ . '/../ap/moduli/prva.php'; if (kes('pw') && (!is_file($f) OR file_get_contents($f) != $_SERVER['SERVER_ADDR'] ))$_SESSION['pw'] = '.'; } function DodajQueryArg($arg, $vr, $query = '') { if (!$query) $query = $_SERVER['QUERY_STRING']; parse_str($query, $qr); if ($vr === false) unset($qr[$arg]); else $qr[$arg] = urlencode($vr); return http_build_query($qr); } function nizUKljucevima($kljucevi, $niz) { foreach ($kljucevi as $k) if (array_key_exists($k, $niz) && !array_key_exists('*' . $k, $niz)) return true; return false; } function pocistiURL($str, $replace = array(), $delimiter = '-', $charset = 'UTF-8') { $str = trim($str); $str = CirLat($str, true); // $str = iconv($charset, 'UTF-8', $str); // by lelebart if (!empty($replace)) { $str = str_replace((array)$replace, ' ', $str); } //setlocale(LC_ALL, 'en_US.UTF8'); $clean = @iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $str); $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '-', $clean); $clean = strtolower(trim($clean, '-')); $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean); return $clean; } /** * Konvertuje cirilicu u UTF/ASCCI latinicu * @param string $nov - Tekst za konverziju * @param bool $ascci - ako je true onda u ASCII, inace u UTF-8 * @return - konvertovan String */ function CirLat($nov, $ascci = false) { if ($ascci) { $cir = array('Ćirlica', 'А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Ђ', 'ђ', 'Е', 'е', 'Ж', 'ж', 'З', 'з', 'И', 'и', 'Ј', 'ј', 'К', 'к', 'Л', 'л', 'Љ', 'љ', 'М', 'м', 'Н', 'н', 'Њ', 'њ', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'Ћ', 'ћ', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Џ', 'џ', 'Ш', 'ш' , 'Ć', 'ć', 'Č', 'č', 'Š', 'š', 'Đ', 'đ', 'Ž', 'ž', 'Ćirlica'); $lat = array('Cirlica', 'A', 'a', 'B', 'b', 'V', 'v', 'G', 'g', 'D', 'd', 'DJ', 'dj', 'E', 'e', 'Z', 'z', 'Z', 'z', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'LJ', 'lj', 'M', 'm', 'N', 'n', 'NJ', 'nj', 'O', 'o', 'P', 'p', 'R', 'r', 'S', 's', 'T', 't', 'C', 'c', 'U', 'u', 'F', 'f', 'H', 'h', 'C', 'c', 'C', 'c', 'Dz', 'dz', 'S', 's' , 'C', 'c', 'C', 'c', 'S', 'S', 'Dj', 'dj', 'Z', 'z', 'Cirlica'); } else { $cir = array('Ćirlica', 'А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Ђ', 'ђ', 'Е', 'е', 'Ж', 'ж', 'З', 'з', 'И', 'и', 'Ј', 'ј', 'К', 'к', 'Л', 'л', 'Љ', 'љ', 'М', 'м', 'Н', 'н', 'Њ', 'њ', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'Ћ', 'ћ', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Џ', 'џ', 'Ш', 'ш', 'Ćirlica'); $lat = array('Ћирилица', 'A', 'a', 'B', 'b', 'V', 'v', 'G', 'g', 'D', 'd', 'Ð', 'đ', 'E', 'e', 'Ž', 'ž', 'Z', 'z', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'LJ', 'lj', 'M', 'm', 'N', 'n', 'NJ', 'nj', 'O', 'o', 'P', 'p', 'R', 'r', 'S', 's', 'T', 't', 'Ć', 'ć', 'U', 'u', 'F', 'f', 'H', 'h', 'C', 'c', 'Č', 'č', 'Dž', 'dž', 'Š', 'š', 'Ћирилица'); } $out = str_replace($cir, $lat, $nov); return $out; } /** * Konvertuje latinicu u UTF/ASCCI cirilicu * @param string $nov - Tekst za konverziju * @param bool $ascci - ako je true onda u ASCII, inace u UTF-8 * @return - konvertovan String */ function LatCir($nov, $ascci = false) { if ($ascci) { $cir = array('Ćirlica', 'А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Ђ', 'ђ', 'Е', 'е', 'Ж', 'ж', 'З', 'з', 'И', 'и', 'Ј', 'ј', 'К', 'к', 'Л', 'л', 'Љ', 'љ', 'М', 'м', 'Н', 'н', 'Њ', 'њ', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'Ћ', 'ћ', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Џ', 'џ', 'Ш', 'ш' , 'Ć', 'ć', 'Č', 'č', 'Š', 'š', 'Đ', 'đ', 'Ž', 'ž', 'Ćirlica'); $lat = array('Cirlica', 'A', 'a', 'B', 'b', 'V', 'v', 'G', 'g', 'D', 'd', 'DJ', 'dj', 'E', 'e', 'Z', 'z', 'Z', 'z', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'LJ', 'lj', 'M', 'm', 'N', 'n', 'NJ', 'nj', 'O', 'o', 'P', 'p', 'R', 'r', 'S', 's', 'T', 't', 'C', 'c', 'U', 'u', 'F', 'f', 'H', 'h', 'C', 'c', 'C', 'c', 'Dz', 'dz', 'S', 's' , 'C', 'c', 'C', 'c', 'S', 'S', 'Dj', 'dj', 'Z', 'z', 'Cirlica'); } else { $cir = array('Ćirlica', 'А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Ђ', 'ђ', 'Е', 'е', 'Ж', 'ж', 'З', 'з', 'И', 'и', 'Ј', 'ј', 'К', 'к', 'Л', 'л', 'Љ', 'љ', 'М', 'м', 'Н', 'н', 'Њ', 'њ', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'Ћ', 'ћ', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Џ', 'џ', 'Ш', 'ш', 'Ćirlica'); $lat = array('Ћирилица', 'A', 'a', 'B', 'b', 'V', 'v', 'G', 'g', 'D', 'd', 'Ð', 'đ', 'E', 'e', 'Ž', 'ž', 'Z', 'z', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'LJ', 'lj', 'M', 'm', 'N', 'n', 'NJ', 'nj', 'O', 'o', 'P', 'p', 'R', 'r', 'S', 's', 'T', 't', 'Ć', 'ć', 'U', 'u', 'F', 'f', 'H', 'h', 'C', 'c', 'Č', 'č', 'Dž', 'dž', 'Š', 'š', 'Ћирилица'); } $out = str_replace($lat, $cir, $nov); return $out; } /** * * Vraca jezik, ali ispravno samo ako je postavljen kolacic * zgodno za ajax */ function dajJezik() { if (defined('JEZIK')) return JEZIK; global $St; if ($St) return $St->dajJezik(); return ker('_jz') ? ker('_jz') : Mysql::skalarIzBaze("SELECT id_jezik FROM jezik WHERE podrazumevan"); } /** * * Vraca rec za tekuci jezik na osnovu jezika strane * ako je definisana, ako ne, na osnovu jezika iz kolacica * @param string $rec */ function dajRec($rec) { global $St; global $Reci; $jz = dajJezik(); //print_r($Reci); if (ke($Reci, $jz) && array_key_exists($rec, $Reci[$jz])) return $Reci[$jz][$rec]; if ($St) return $St->dajRec($rec); $rez = Mysql::skalarIzBaze($q = "SELECT fraza FROM rec WHERE naziv = " . qs($rec) . " AND id_jezik=$jz LIMIT 0,1"); if ($rez === NULL) return $Reci[$jz][$rec] = $rec; else return $Reci[$jz][$rec] = $rez; //return ($Reci[$jz][$rec]=(Mysql::skalarIzBaze($q="SELECT fraza FROM rec WHERE naziv = ".qs($rec)." AND sif_jezik=$jz LIMIT 0,1"))!==NULL) ? $Reci[$jz][$rec] : $rec; } function jelLatinica() { if (dajJezik() == 3) { if (!headers_sent()) setcookie('_lat', 0, time() + 60 * 60 * 24 * 60, '/'); return 0; } if (dp('ili_cirilica_ili_latinica')) return dp('latinica'); if (ke($_COOKIE, '_lat') === NULL && ke($_GET, '_lat') === NULL) { if (!headers_sent()) setcookie('_lat', dp('latinica'), time() + 60 * 60 * 24 * 30, '/'); return dp('latinica'); } elseif (ke($_GET, '_lat') !== NULL) { if (!headers_sent()) setcookie('_lat', $_GET['_lat'], time() + 60 * 60 * 24 * 30, '/'); return $_GET['_lat']; } elseif (ke($_COOKIE, '_lat') !== NULL) { if (!headers_sent()) setcookie('_lat', $_COOKIE['_lat'], time() + 60 * 60 * 24 * 30, '/'); return $_COOKIE['_lat']; } return dp('latinica'); } function dajStranu2($prm) { //TODO:sif_strana u jezik i nepostojeca u strana, skini podrazumevana u strana global $Jezik; if (defined('JEZIK')) $_COOKIE['_jz'] = JEZIK; if (ke($prm, 0)) { if ($st = Mysql::redIzBaze("SELECT id_strana, id_jezik, fajl FROM strana WHERE pretty_url=" . qs($prm[0]))) ; else { if (ke($_COOKIE, '_jz') && $j = Mysql::redIzBaze("SELECT * FROM jezik WHERE vidljiv AND id_jezik=" . $_COOKIE['_jz'])) ; else $j = Mysql::redIzBaze("SELECT * FROM jezik WHERE vidljiv AND id_jezik=" . $_COOKIE['_jz']); if (pathinfo($_SERVER['REQUEST_URI'], PATHINFO_EXTENSION)) { header("HTTP/1.0 404 Not Found"); exit; } $st = Mysql::redIzBaze("SELECT id_strana, id_jezik, fajl FROM strana WHERE nepostojeca AND id_jezik=$j[id_jezik]"); } //echo $q; /** * if(ke($_GET, '_jz') !== NULL){ * if(($j = Mysql::redIzBaze("SELECT * FROM jezik WHERE vidljiv AND sif_jezik=".qs($_GET['_jz']))) && $st['sif_jezik']==$j) * return new Strana($st['sif_strana']);//ne menjamo jezik, ni stranu * elseif($j) {//promenjen jezik * setcookie('_jz', $j['sif_jezik'], time()+60*60*24*30); * header("Location: http://$_SERVER[HTTP_HOST]/".Mysql::skalarIzBaze("SELECT pretty_url from jezik, strana WHERE strana.sif_strana=jezik.sif_strana AND jezik.vidljiv AND jezik.sif_jezik=$j[sif_jezik]")); * exit; * //return new Strana(Mysql::skalarIzBaze("SELECT sif_strana from jezik WHERE vidljiv AND sif_jezik=$j[sif_jezik]")); * }else return new Strana($st['sif_strana']); * } */ if (defined('JEZIK') && ($st['id_jezik'] != JEZIK)) $st = Mysql::redIzBaze("SELECT id_strana, id_jezik, fajl FROM strana WHERE nepostojeca AND id_jezik=" . JEZIK); setcookie('_jz', $st['id_jezik'], time() + 60 * 60 * 24 * 30, '/'); //print_r($st); if ($st['fajl'] && file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . INCDIR . '/strane/' . $st['fajl'])) inc('/' . INCDIR . '/strane/' . $st['fajl']); $Jezik = $st['id_jezik']; return in_array('StranaCustom', get_declared_classes(), true) ? new StranaCustom($st['id_strana']) : dajSiteSpecPage($st['id_strana']); } else {//pocetna if ($j = Mysql::redIzBaze("SELECT jezik.id_strana AS St, jezik.id_jezik AS Jz, fajl FROM jezik, strana WHERE strana.id_strana = jezik.id_strana AND jezik.vidljiv AND jezik.id_jezik=" . $_COOKIE['_jz'])) ; else $j = Mysql::redIzBaze("SELECT 90 AS St, 1 AS Jz, fajl FROM strana WHERE strana.id_strana=90"); setcookie('_jz', $j['Jz'], time() + 60 * 60 * 24 * 30, '/'); // return new Strana($j['id_strana']); $Jezik = $j['Jz']; if ($j['fajl'] && file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . INCDIR . '/strane/' . $j['fajl'])) inc('/' . INCDIR . '/strane/' . $j['fajl']); return in_array('StranaCustom', get_declared_classes(), true) ? new StranaCustom($j['St']) : dajSiteSpecPage($j['St']); } } function dajStranu($prm) { //global $PurlKeys; global $Jezik; $words = explode("_", $prm[0]); if (count($words) <= 1) $words = explode("+", $prm[0]); //print_r($words); if ($pu = ke($words, 0)) { //echo $pu; if ($st = Mysql::redIzBaze("SELECT id_strana, id_jezik, fajl FROM strana WHERE pretty_url=" . qs($pu))) { // print_r('$st'); if ($st['fajl'] && file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . INCDIR . '/strane/' . $st['fajl'])) inc('/' . INCDIR . '/strane/' . $st['fajl']); $Jezik = $st['id_jezik']; return ( in_array('StranaCustom', get_declared_classes(), true) ? new StranaCustom($st['id_strana']) : dajSiteSpecPage($st['id_strana']) ); } else return dajStranu2($prm); } else return dajStranu2($prm); } function dajParams() { $path = explode("?", $_SERVER['REQUEST_URI']); return explode('/', trim($path[0], '/')); } if (!function_exists('dajPurlPart')) { function dajPurlPart($index = 0, $count = false) { $prm = dajParams(); if ($count) return count($prm); if ($index >= 0) return @$prm[$index]; else return @$prm[count($prm) + $index]; } } /** * isto sto i strip_tags, samo ostavlja spaceove. * * @param mixed $text - ulazni tekst * @param mixed $tags - dozvoljeni tagovi * @return Pociscen tekst */ function stripTags($text, $tags = '') { $text = preg_replace('//', '> ', $text); $desc = html_entity_decode(strip_tags($text, $tags), ENT_QUOTES, 'UTF-8'); $desc = preg_replace('/[\n\r\t]/', ' ', $desc); return preg_replace('/ /', ' ', $desc); } function GetPath($aps = true) { if ($aps) return dirname(__FILE__); else return DIRECTORY_SEPARATOR . substr(dirname(__FILE__), strlen($_SERVER['DOCUMENT_ROOT'])); } function dajRecommend($url = '') { $url = urlencode($url); return ''; } function krozProxy($addr = '') { //true kroz porxy, false nije if (!$addr) $addr = gethostbyaddr($_SERVER['REMOTE_ADDR']); $proxyjiImena = explode('|', dp('proxyji_imena')); $proxyjiAdrese = explode('|', dp('proxyji_adrese')); //print ($addr.$_SERVER['REMOTE_ADDR']); if ($addr == ".") return true; for ($i = 0; $i < count($proxyjiImena); $i++) { if ($proxyjiImena[$i] && (strpos($addr, $proxyjiImena[$i]) !== FALSE)) return true; //echo $proxyjiImena[$i]; } for ($i = 0; $i < count($proxyjiAdrese); $i++) { if ($proxyjiAdrese[$i] && (strpos($_SERVER['REMOTE_ADDR'], $proxyjiAdrese[$i]) !== FALSE)) return true; //echo $proxyjiAdrese[$i]; } return false; } function dozvoljenPristup($strana = false, $request = '', $samoProveri = FALSE) {//false blokiran, true moze if (!$strana) $strana = $_SERVER['REQUEST_URI']; if (!$request) $request = http_build_query($_REQUEST); if (!$ogr = Mysql::redIzBaze($q = "SELECT * FROM kontrola_pristupa WHERE (naziv = " . qs($strana) . " OR ISNULL(naziv) OR naziv='') AND (ISNULL(request) OR request='' OR INSTR('" . $request . "', request))")) { //echo $q; return true; } //print_r($ogr); $addr = @$_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : gethostbyaddr($_SERVER['REMOTE_ADDR']); $pr = Mysql::redIzBaze("SELECT * FROM pristup WHERE HTTP_CLIENT_IP='" . @$_SERVER['HTTP_CLIENT_IP'] . "' AND REMOTE_ADDR='" . @$_SERVER['REMOTE_ADDR'] . "' AND HTTP_X_FORWARDED_FOR='" . @$_SERVER['HTTP_X_FORWARDED_FOR'] . "'" . " AND strana='$ogr[naziv]' AND request = '$ogr[request]'"); //) ($poll ? " AND strana='$strana-$poll'" : $prx = krozProxy($addr); if (!$samoProveri) { if (!$pr) Mysql::skalarIzBaze("INSERT INTO pristup set HTTP_CLIENT_IP='" . @$_SERVER['HTTP_CLIENT_IP'] . "', REMOTE_ADDR='" . @$_SERVER['REMOTE_ADDR'] . "', HTTP_X_FORWARDED_FOR='" . @$_SERVER['HTTP_X_FORWARDED_FOR'] . "'" . ", strana='$ogr[naziv]'" //) ($poll ? ", strana='$strana-$poll'" : . ", prvi='" . date(DTFormat) . "'" . ", poslednji='" . date(DTFormat) . "'" . ", naziv = '" . $addr . "'" . ", request = '$ogr[request]'" . ($prx ? ', blokiran = 2' : '')); else Mysql::skalarIzBaze("UPDATE pristup SET poslednji='" . date(DTFormat) . "', broj_pristupa=1+broj_pristupa, ukupan_broj_pristupa=ukupan_broj_pristupa+1 WHERE id_pristup = $pr[id_pristup]"); } //print_r($pr); if ($prx || $pr['blokiran']) { if (!$samoProveri) setcookie('_' . md5($strana), md5($ogr['request']), time() + 60 * 60 * 24 * 365, '/'); return false; } if (dp("pristupi_za_blokadu") && (dp("pristupi_za_blokadu") <= $pr['broj_pristupa'])) { if (!$samoProveri) { Mysql::skalarIzBaze("UPDATE pristup SET blokiran=1 WHERE id_pristup=$pr[id_pristup]"); setcookie('_' . md5($strana), md5($ogr['request']), time() + 60 * 60 * 24 * 365, '/'); } return false; } //echo strtotime($pr['poslednji']); $poslednji = date('U', strtotime($pr['poslednji'])); if ($poslednji + $ogr['period'] > time()) { if ($pr['broj_pristupa'] >= $ogr['broj_pristupa']) { if (!$samoProveri) setcookie('_' . md5($strana), md5($ogr['request']), time() + $ogr['period'], '/'); return false; } else return true; } else { if (!$samoProveri) Mysql::skalarIzBaze("UPDATE pristup SET broj_pristupa=1 WHERE id_pristup = $pr[id_pristup]"); return true; } } function validirajEmail($email) { return preg_match("/^[a-z0-9][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", $email); } function PDFInit() { inc('/ap/tcpdf/config/lang/srp.php'); inc('/ap/tcpdf/tcpdf.php'); // create new PDF document $pdf = new TCPDF('L', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('samsung'); $pdf->SetTitle('samsung.salesresults.rs'); $pdf->SetSubject('Izveštaj'); $pdf->SetKeywords('Izveštaj, prodaja, aktivnosti, samsung, samsung.salesresults.rs'); // set default header data //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 061', PDF_HEADER_STRING); $pdf->setPrintHeader(false); // set header and footer fonts //$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, 10, PDF_MARGIN_RIGHT); //$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings //$pdf->setLanguageArray($l); // --------------------------------------------------------- // set font $pdf->SetFont('freesans', '', 10); $pdf->AddPage(); return $pdf; } /** * daje html kod za chart. * * @param array $data - niz, prvi element - vrednosti na X-osi, ostali elementi - definisu Y-ose, gde prvi element daje osobine Y-ose a ostali vrednosti * @param array $op - Opcije charta, class - klasa kontejnera, style - stil kontejnera, title i subtitle - naslov i podnaslov grafikona, ['y'][0]['yTitle'] i ['y'][1]['yTitle'] - leva i desna y-osa * @return Pociscen tekst */ function dajChart($data, $op) { if (ke($op, 'id')) $o = ''; else $o = "
"; if (is_array($data[0])) $x = "categories: ['" . implode("','", $data[0]) . "']"; else $x = $data[0]; for ($i = 1; $i < count($data); $i++) { $n = $data[$i][0] ? $data[$i][0] . "," : ''; $s = implode(',', $data[$i][1]); $ser[] = "{ " . $n . "data: [" . $s . "] }"; } $ser = implode(",\n", $ser); $o .= "$(document).ready(function() { chart = new Highcharts.Chart({ chart: { events: { load: function(event) { $('#hc_$r').resize(); } }, renderTo: 'hc_$r'//, //defaultSeriesType: 'column' " . (ke($op, 'chart') ? ', ' . $op['chart'] : '') . " }, title: { text: '" . addslashes($op['title']) . "' }, subtitle: { text: '" . addslashes($op['subtitle']) . "' }, xAxis: { $x }, yAxis: [ { title: { text: '" . addslashes(ke($op['y'][0], 'yTitle')) . "' }, }," . (ke($op['y'], 1) ? "{ title: { text: '" . addslashes(ke($op['y'][1], 'yTitle')) . "' }, opposite: true }" : '') . "], legend: { layout: 'vertical', align: 'left', verticalAlign: 'top', x: 100, y: 70, floating: true, shadow: true }, tooltip: { formatter: function() { return this.series.name +': '+ this.y + ''; } }, plotOptions: { area: { /* fillColor: { linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1}, stops: [ [0, Highcharts.getOptions().colors[0]], [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')] ] },*/ marker: { radius: 1 }, lineWidth: 0, states: { hover: { lineWidth: 1 } }, threshold: null } }, series: [$ser] }); });"; return $o; } oSlike(); /** reci za AP */ function dr($f, $Jez = -1) { if ($Jez == -1) { global $AP_JEZIK; $Jez = $AP_JEZIK; } global $AP_RECI; if (ke($AP_RECI[$Jez], $f)) return $AP_RECI[$Jez][$f]; else return $f; } function datum($d, $format = 'd/m/Y') { return date($format, strtotime($d)); } /**Srpski datum */ function datumSR($d) { return date(SRDFormat, strtotime($d)); } function dateFormat($format = SRDFormat, $tstamp = false) { if (!$tstamp) $tstamp = time(); else $tstamp = strtotime($tstamp); return date($format, $tstamp); } function ordinal($num) { // Special case "teenth" if (($num / 10) % 10 != 1) { // Handle 1st, 2nd, 3rd switch ($num % 10) { case 1: return $num . 'st'; case 2: return $num . 'nd'; case 3: return $num . 'rd'; } } // Everything else is "nth" return $num . 'th'; } function dajSQLPrivilegije($imeTabele) { global $korisnik, $JezAP; // print_r($korisnik); $whf = $JezAP ? filterJezik($imeTabele) : ' WHERE 1 '; $wh = ''; if ($korisnik->samoVlasnik($imeTabele) && $korisnik->samoGrupa($imeTabele)) { $wh .= " (T.sif_vlasnik=" . $korisnik->sif_korisnik . " OR T.sif_grupa = {$korisnik->grupa} ) AND "; } elseif ($korisnik->samoVlasnik($imeTabele)) $wh .= " T.sif_vlasnik=" . $korisnik->sif_korisnik . " AND "; elseif ($korisnik->samoGrupa($imeTabele)) $wh .= " T.sif_grupa={$korisnik->grupa} AND "; $pk = Baza::dajPK($imeTabele); if ("(-1)" != ($zz = $korisnik->zabZapisi($imeTabele))) $wh .= " T.$pk NOT IN $zz AND "; if ($wh) return $whf . " AND " . mb_substr($wh, 0, mb_strlen($wh) - 4) . " "; return $whf; } function filterJezik($imeTabele) { static $FJ; if (ke($FJ, $it = $imeTabele)) return $FJ[$imeTabele]; //echo $imeTabele." | "; print_r($FJ); global $JezAP, $b; if (!$b) $b = new Baza(); $prevTab = $b->tekuca_tabela; $imamoga = false; $tb = 'T'; $sq = ' '; $tbs = ''; $i = 0; while ($imeTabele && !$imamoga) { $kolone = $b->dajKolone($imeTabele); $imeTabele = ''; foreach ($kolone as $kolona) { if (in_array($kolona['Tip'], array("E", "EX"))) { if ($kolona['Field'] == 'id_jezik') $imamoga = true; else { if (is_numeric(substr($kolona['Field'], 4, 1))) $imeTabele = substr($kolona['Field'], 6); else $imeTabele = substr($kolona['Field'], 4); $tbs .= ", $imeTabele"; } if ($imamoga) $sq .= " WHERE $tb.id_jezik=$JezAP "; else { $pk = Baza::dajPK($imeTabele); $sq .= " LEFT JOIN $imeTabele ON $tb.$kolona[Field]=$imeTabele.$pk "; } //echo $sq; $tb = $imeTabele; break; } } if (++$i > 3) break; } $b->promeniTekucu($prevTab); if ($imamoga) return $FJ[$it] = $sq; else return $FJ[$it] = ' WHERE 1 '; } function dajJezikAP() { if (($jz = ke($_GET, '_jezap')) !== NULL) { setcookie('_jezap', $jz + 0, time() + 60 * 60 * 24 * 30); return $jz; } return ke($_COOKIE, '_jezap') + 0; } /** * Kreiranje direktorijuma * @param string $d putanja za direktorijum * @param int $prv privilegije * @param bool $rec recurzivno */ function md($dir, $prv = 0755, $rec = true) { $um = umask(0); mkdir($dir, $prv, $rec); umask($um); } function removeDuplicateArraysFromArray($arr, $key) { // return $arr; $tarr = array(); $c = count($arr); for ($i = 0; $i < $c; $i++) { $nadjen = false; for ($j = 0; $j < count($tarr); $j++) { if ($arr[$i][$key] == $tarr[$j][$key]) { $nadjen = true; continue; } } if (!$nadjen) $tarr[] = $arr[$i]; } return $tarr; } function takeUploadedFile($slika, $toFolder, $name) { if ($slika) { if (!is_dir($_SERVER['DOCUMENT_ROOT'] . ($pdir = DIRECTORY_SEPARATOR . 'fajlovi' . DIRECTORY_SEPARATOR . $toFolder))) md($_SERVER['DOCUMENT_ROOT'] . $pdir); $finfo = pathinfo($slika); $fname = pocistiURL(mb_substr($name, 0, 12)) . '_' . uniqid() . '.' . $finfo['extension']; @rename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . INCDIR . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'resized' . DIRECTORY_SEPARATOR . $slika, $_SERVER['DOCUMENT_ROOT'] . $pdir . DIRECTORY_SEPARATOR . $fname); Strana::remoteUpload($pdir . DIRECTORY_SEPARATOR . $fname); return str_replace("\\", "/", $pdir . DIRECTORY_SEPARATOR . $fname); } return false; } function posaljiMail($file, $opt = array()) { $opt = array_merge(array('from' => dp('email_address'), 'fromname' => dp('email_name'), 'title' => dp('email_title'), 'emailto' => dp('email_address'), 'imeprezime' => dp('email_name')), $opt); if (!file_exists(dirname(__FILE__) . '/../mails/' . $file . '.html')) { error_log('Ne postoji mail fajl' . $file); return 'Ne postoji mail fajl' . $file; } ob_start('mb_output_handler'); include dirname(__FILE__) . '/../mails/' . $file . '.html'; $mailbody = ob_get_clean(); $mail = new Mailer(); $mail->AddAddress($opt['emailto'], $opt['imeprezime']); $mail->Subject = $opt['title']; //echo $mailbody; $mail->MsgHTML($mailbody); if (ke($opt, 'attachments') && is_array($opt['attachments'])) { foreach ($opt['attachments'] as $att) $mail->AddAttachment($att); } if (!$mail->Send()) { return $mail->ErrorInfo; } return false; } function printArray($array) { $o = ""; return $o; } /** * @param null $path * @param bool $debug * @return AppKernel */ function getSymfonyKernel($path = null, $debug = false) { static $kernel = null; if ($kernel) return $kernel; if (!$path) $path = __DIR__ . '/../symfony/app/autoload.php'; $loader = require $path; if ($debug) Debug::enable(); $kernel = new AppKernel('dev', true); // create a "test" kernel $kernel->boot(); return $kernel; } ?>