smarty_dir.'Smarty.class.php'); class Functions { var $mysql; var $queries = 0; var $simplequeries = 0; //function Functions(){ function __construct() { global $var; global $smarty; global $PHP_SELF; $this->mysql = mysqli_connect($var->mysql_host, $var->mysql_user, $var->mysql_pass) or die("Could not connect to mysql server: " . mysqli_error()); //mysqli_set_charset($this->mysql,'utf8'); mysqli_set_charset($this->mysql,'latin1'); $smarty->template_dir = $var->smarty_template_dir; $smarty->compile_dir = $var->smarty_compile_dir; $smarty->config_dir = $var->smarty_config_dir; $smarty->cache_dir = $var->smarty_cache_dir; $smarty->left_delimiter = $var->smarty_left; $smarty->right_delimiter = $var->smarty_right; //$smarty->cache = 0; $smarty->assign("page", $PHP_SELF); mysqli_select_db($this->mysql, $var->mysql_db) or die("Could not select database $var->mysql_db"); } function get_var($varname, $esc = 0){ global $_GET; global $_POST; global $HTTP_SESSION_VARS; if (isset($_GET["$varname"])) return $esc ? $_GET["$varname"] : $_GET["$varname"]; if (isset($_POST["$varname"])) return $esc ? $_POST["$varname"] : $_POST["$varname"]; if (isset($_SESSION["$varname"])) return $esc ? $_SESSION["$varname"] : $_SESSION["$varname"]; if (isset($HTTP_SESSION_VARS["$varname"])) return $esc ? $HTTP_SESSION_VARS["$varname"] : $HTTP_SESSION_VARS["$varname"]; } function get_var_esc($varname){ return $this->get_var($varname, 1); } function set_var($varname, $value){ $HTTP_GET_VARS["$varname"] = $value; $HTTP_POST_VARS["$varname"] = $value; $HTTP_SESSION_VARS["$varname"] = $value; $_SESSION["$varname"] = $value; } function del_var($arr){ foreach ($arr as $var){ $this->set_var($var, ''); } } function reload_vars(){ global $smarty; foreach ($HTTP_POST_VARS as $name => $value){ $smarty->assign($name,$value); } } function simplequery($query){ $this->simplequeries++; $this->queries++; $result = mysqli_query($query) or die("Query ($query) failed : " . mysql_error()); $line = ''; if ($result) $line = mysqli_fetch_array($result, MYSQL_ASSOC); return $line; } function query($query){ $this->queries++; $result = mysqli_query($query) or die("Query ($query) failed : " . mysql_error()); return $result; } function debugquery($query){ $this->queries++; print $query; return $this->query($query); } function insert($query){ $result = $this->query($query); return mysql_insert_id(); } function log($table, $id, $action){ $res = $this->simplequery("SELECT id FROM object WHERE objecttype='$table' AND value='$id'"); if ($res) $oid = $res["id"]; else $oid = $this->insert("INSERT INTO object (objecttype, value) VALUES ('$table', '$id')"); $this->insert("INSERT INTO history (object_id, korisnici_id, datum, action) VALUES ('$oid', '".$this->get_var("userid")."', NOW(), '$action')"); } function reload_form($arr) { global $smarty; foreach($arr as $k){ $smarty->assign($k, $this->get_var($k)); } } function get_time($prefix){ return mktime($this->get_var($prefix."Hour"),$this->get_var($prefix."Minute"),0,$this->get_var($prefix."Month"),$this->get_var($prefix."Day"),$this->get_var($prefix."Year")); } function get_date($prefix){ return mktime($this->get_var($prefix."Month"),$this->get_var($prefix."Day"),$this->get_var($prefix."Year")); } function pagelister_navbar ($page, $numpages, $PHP_SELF, $lg) { switch ($lg) { case "sr": $title="Stranice"; break; case "hu": $title="Oldalak"; break; case "en": $title="Pages"; break; } $return_string="

$title: "; for($i = 1; $i <= $numpages; $i++) { #loop to print << 1 2 3... $numpages >> if($i == 1 && $page > 1) #Prints the << first to goto the previous page (not on page 1) $return_string=$return_string."«  "; if($i == $page) #Doesn't print a link itself, just prints page number $return_string=$return_string." $i "; if($i != $page) #Other links that aren't this page go here $return_string=$return_string." $i "; if($i == $numpages && $page != $numpages) # Link for next page >> (not on last page) $return_string=$return_string."  »"; }; $return_string=$return_string."

"; return $return_string; } }//End of class //session_start(); $smarty = new Smarty() or die("Smarty init failed"); $func = new Functions(); ?>