class Language {
var $db;
/**
* konstruktor klasy
* inicjuje uchwyt do bazy
**/
function Language(){
$this->db =& new DB();
global $languageList;
$this->languageList = $languageList;
echo $languagelist;
}
/**
* count all user
* @param
* @return int
*/
function getFileWithVariable($lang){
$likToFIle = fopen('./../includes/language/'.$lang.'.php', "r");
while($wiersz = @fgets($likToFIle, 1024))
{
$fileContent .= $wiersz;
}
fclose($likToFIle);
return $fileContent;
}
/**
* count all user
* @param
* @return int
*/
function getAllVisibleLanguage(){
if(is_array($this->languageList) AND count($this->languageList)>0){
foreach ($this->languageList as $i => $x){
if($this->languageList[$i]['visible'] == 1){
$temp[] = $this->languageList[$i]['name'];
}
}
return $temp;
}
}
/**
* count all user
* @param
* @return int
*/
function getAllLanguage(){
return $this->languageList;
}
/**
* get all user by range
* @param from
* @param range
* @return array of objects
*/
function getAllUsersByLimit($from, $to){
$sql = "SELECT cms_user.*, (SELECT _inserted FROM cms_audit_login WHERE cms_audit_login.id_user = cms_user.id ORDER BY _inserted ASC LIMIT 0, 1 ) as last_login FROM cms_user ORDER BY first_name, last_name ASC LIMIT $from, $to ";
$tab = $this->db->query($sql);
return $tab;
}
/**
* write new user
* @param
* @return int
*/
function writeNewLanguage(){
if (copy('./../includes/language/base.php', './../includes/language/temp_base.php')){
if(rename('./../includes/language/temp_base.php', './../includes/language/'.strtolower($_POST['formNazwa']).'.php'))
{
$newKey = end(array_keys($this->languageList))+1;
$this->languageList[$newKey]['name'] = $_POST['formNazwa'];
$this->languageList[$newKey]['visible'] = 0;
$this->writeToFile($this->languageList);
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
/**
* change language visible
* @language id
* @return bool result
*/
function changeLanguageVisible($id){
if(array_key_exists($id, $this->languageList))
{
$this->languageList[$id]['visible']==1 ? $visible=0 : $visible=1;
$this->languageList[$id]['visible'] = $visible;
$this->writeToFile($this->languageList);
return true;
}
else
{
return false;
}
}
/**
* change language priority
* @param id
* @param where
* @param priority
*/
function changeLanguagePriority($id, $where, $priority){
if($where=="up"){
$temp = $this->languageList[$id];
$this->languageList[$id] = $this->languageList[$id-1];
$this->languageList[$id-1] = $temp;
}
else{
$temp = $this->languageList[$id];
$this->languageList[$id] = $this->languageList[$id+1];
$this->languageList[$id+1] = $temp;
}
$this->writeToFile($this->languageList);
}
/**
* change language visible
* @language id
* @return bool result
*/
function updateLanguage($id){
if(array_key_exists($id, $this->languageList))
{
unlink('./../includes/language/'.strtolower($_POST['formNazwa']).'.php');
touch ('./../includes/language/'.strtolower($_POST['formNazwa']).'.php'); //utworz plik jeżeli go nie ma
chmod ('./../includes/language/'.strtolower($_POST['formNazwa']).'.php',0666);
$this->languageList[$id]['visible'] = $_POST['formWidoczna'];
$this->writeToFile($this->languageList);
$linkToFile = fopen ('./../includes/language/'.strtolower($_POST['formNazwa']).'.php',"r+");
fwrite ($linkToFile, ""); //zapisujemy zawartosc
fwrite ($linkToFile, "<?php ".stripslashes($_POST['formZmienne'])." ?>"); //zapisujemy zawartosc
fclose ($linkToFile); //zamknij plik
return true;
}
else
{
return false;
}
}
/**
* change language visible
* @language id
* @return bool result
*/
function deleteLanguage($id){
if(array_key_exists($id, $this->languageList))
{
unlink('./../includes/language/'.strtolower($this->languageList[$id]['name']).'.php');
$name = $this->languageList[$id]['name'];
$sql = "DELETE FROM cms_company_text WHERE language = '".$name."'";
$this->db->exec($sql);
$sql = "DELETE FROM cms_photo_text WHERE language = '".$name."'";
$this->db->exec($sql);
$sql = "DELETE FROM cms_post_text WHERE language = '".$name."'";
$this->db->exec($sql);
$sql = "DELETE FROM cms_product_text WHERE language = '".$name."'";
$this->db->exec($sql);
$sql = "DELETE FROM cms_wysiwyg_text WHERE language = '".$name."'";
$this->db->exec($sql);
unset($this->languageList[$id]);
if(is_array($this->languageList) AND count($this->languageList)>0){
foreach ($this->languageList as $i => $x){
$temp[] = $this->languageList[$i];
}
}
$this->writeToFile($temp);
return true;
}
else
{
return false;
}
}
/**
* write language into file
* @language tab
* @return
*/
function writeToFile($tab){
$stringConntent = "<?php\n";
$stringConntent .= "/* ----------------- lista dostępnych języków */\n";
if(is_array($tab) AND count($tab)>0){
foreach ($tab as $i => $x){
$stringConntent .= "$"."languageList"."[".$i."]['name'] = \"".$tab[$i]['name']."\";\n";
$stringConntent .= "$"."languageList"."[".$i."]['visible'] = \"".$tab[$i]['visible']."\";\n";
}
}
$stringConntent .= "?>";
touch (LANGUAGE_FILE_PATH
); //utworz plik jeżeli go nie ma
chmod (LANGUAGE_FILE_PATH,0666);
$linkToFile = fopen (LANGUAGE_FILE_PATH
,"r+") or
die("Nie mogę otworzyć pliku ".LANGUAGE_FILE_PATH
); //otwórz plik
fwrite ($linkToFile, $stringConntent); //zapisujemy zawartosc
fclose ($linkToFile); //zamknij plik
}
}