/***************************************************************************************************
* Knihovna pro praci s mysql databazi
*
***************************************************************************************************/
class cdatabase {
var $site, $user, $pass;
var $spojeni, $database;
var $last_query;
var $error_stream; // kam zapisovat chyby
// new cdatabase($db_server, $db_user, $db_pass, $db_database, $db_error_file, $pathReq);
function cdatabase($s, $u, $p, $d, $cesta_k_data="", $err_stream){
$this->site = $s;
$this->user = $u;
$this->pass = $p;
$this->database = $d;
$this->spojeni = @mysql_connect($s, $u, $p) or die("Omlouváme se, nelze se spojit s databázovým serverem.");
@mysql_select_db($d) or die("Omlouváme se, databáze neexistuje.");
//@mysql_query('SET NAMES CP1250');
@mysql_query('SET NAMES UTF8');
//if($err_stream){
// $this->error_stream = $cesta_k_data;
//} else {
$this->error_stream = $cesta_k_data;
//}
}
function close(){
@mysql_close($this->spojeni);
}
function error($errno, $errmess) { // $errno - cislo chyby, $errmess - popis chyby
echo StrFTime ("%d.%m.%Y %H:%M:%S")." > $errno > ".$errmess."\n"; echo $this->error_stream;
$fp = fopen($this->error_stream, "a");
fputs ($fp, StrFTime ("%d.%m.%Y %H:%M:%S")." > $errno > ".strip_tags($errmess)."\r\n\r\n");
fclose ($fp);
}
function query($s, $nezapisovat = 0){
global $DEBUG_SQL_QUERY, $DEBUG_SQL_QUERY_FILE_HANDLE ,$cesta_k_req;
if($DEBUG_SQL_QUERY == "DEBUG"){
fwrite($DEBUG_SQL_QUERY_FILE_HANDLE, $s."\r\n");
}
if($nezapisovat == 0){
//saveApplicationLog($s);
}
$result = @mysql_query($s);
if(!$result){
$this->error(2, "Query error in [$s]. ".mysql_error().".");
}
$this->last_query = $result;
return $this->last_query;
}
function fetch_array($q, $limit = 0){
global $result;
if($limit > 0){
$q .= " LIMIT ".$limit;
}
if ($q) {
$this->query($q);
}
$num = $this->num_rows($result);
for ($i = 0; $i < $num; $i++) {
$arr[] = @mysql_fetch_array($this->last_query);
}
if(isset($arr) && is_array($arr)){
if($limit == 1 && is_array($arr[0])){
foreach($arr[0] AS $key=>$val){
$array[$key] = stripslashes($val);
}
$arr = $array;
}
return $arr;
}
else {
return false;
}
}
function num_rows($result = "") {
if ($result == "") {
return @mysql_num_rows($this->last_query);
}
else {
return @mysql_num_rows($result);
}
}
function affected_rows(){
return @mysql_affected_rows($this->spojeni);
}
function insert_id(){
return @mysql_insert_id();
}
function fetch_all(){
$rows = $this->num_rows();
$a = array();
for ($i=0; $i<$rows; $i++)
{
$a[$i] = $this->fetch_array();
}
return $a;
}
function exists_table($name) {
$this->last_query = @mysql_query("DESCRIBE $name");
if ($this->last_query):
return $this->fetch_all();
else:
return false;
endif;
}
function index_value($q, $index, $value = "") {
$result = $this->query($q);
if ($result) {
while($row = mysql_fetch_array($result)){
$arr[$row[$index]] = stripslashes($row[$value]);
}
if(isset($arr)){
return $arr;
}
}
else {
return false;
}
}
} // endclass
?>
/**********************************************
/*
/* Knihovna pro preklady
/*
/*
/* function cpreklady($s, $j, $m = '', $cesta_k_data = '') - inicializace objektu pro preklady (pro $module != '' se vola
/* funkce pridej_modul)
/* function pridej_modul($modul) - nacte preklady pro modul
/* function preloz($modul_a_kod) - vraci preklad pro zadany kod
/* function _zapis_kod($modul, $kod, $typ) - privatni metoda, ktera zapisuje do souboru, pokud funkce
/* get_translation nenajde kod nebo je preklad pro kod prazdny
/* function _je_v_prekladech($modul, $kod) - privatni metoda, test, zda je kod obsazen v prekladech
/* function _je_v_modulu_prazdy($modul, $kod) - privatni metoda, test, zda je kod v prekladech neprazdny
/*
/* ***DB INFO*********************************
CREATE TABLE translations (
id serial,
modul varchar(50),
kod varchar(30),
id_jazyk integer,
fraze text
);
/* ***DB INFO*********************************
/*
/**********************************************/
class ctranslates {
var $spojeni, // databazove spojeni
$idLang; // jazyk, pro ktery nacitame preklady
//$preklady, // asociativni pole obsahujici preklady
//$soubor_neni_v_db, // soubor, kam se budou zapisovat preklady, ktere nejsou v databazi
//$soubor_je_prazdny; // soubor, kam se budou zapisovat preklady, ktere maji prazdnou hodnotu
function ctranslates($s, $j) {
$this->spojeni = $s;
$this->idLang = $j;
//$this->preklady = array();
//$this->soubor_neni_v_db = $cesta_k_data.'data/preklady_neni_v_db.txt';
//$this->soubor_je_prazdny = $cesta_k_data.'data/preklady_je_prazdny.txt';
}
function translate($code) {
$idLang = intval($this->idLang);
//$code = $this->code;
$tr = $this->spojeni->fetch_array("SELECT `translate` FROM `translates` WHERE `code` REGEXP '^".$code."$' AND `idLanguage` = ".$idLang, 1 );
if(isset($tr) && is_array($tr) && strlen($tr['translate']) ){
return $tr['translate'];
}
else{
$this->spojeni->query("REPLACE INTO `translates` (`code`, `idLanguage`) VALUES ('".$code."', ".$idLang.")" );
return $code;
}
}
}
?>