class Modules_edit
{
public $tmpl;
public $select_default = null;
public $on_change = "";
function __construct($tmpl)
{
$this->tmpl = $tmpl;
if(isset($_GET["id_m"]))
$this->tmpl->set_var('cms_back', "location.href='modules.php?".mb_ereg_replace("&","&",path_from_get(array("idd","action")))."';");
else if(isset($_GET["str"]))
$this->tmpl->set_var('cms_back', "location.href='modules.php?str=".$_GET["str"]."';");
else
$this->tmpl->set_var('cms_back', "location.href='modules.php?id=".$_GET["id"]."';");
}
function add_row_photo($label, $name, $value, $path, $type = 'modul_file')
{
$this->tmpl->set_var('row_lab', $name);
$this->tmpl->set_var('row_name', $label);
$this->tmpl->set_var('a_target', "");
if(isset($value))
{
$this->tmpl->set_var('a_href',"javascript:photo_display('war_foto', '".$path.$value."');void(0);");
$this->tmpl->set_var('a_value', "
");
$this->tmpl->parse('row_val','modul_a');
}
else
$this->tmpl->set_var('row_val', "");
$this->tmpl->parse('tab_rows_',$type,true);
}
function add_row_file($label, $name, $value, $path, $type = 'modul_file')
{
$this->tmpl->set_var('row_lab', $name);
$this->tmpl->set_var('row_name', $label);
$this->tmpl->set_var('a_target', "");
if(isset($value))
{
$this->tmpl->set_var('a_href', $path.$value);
$this->tmpl->set_var('a_value',$value);
$this->tmpl->parse('row_val','modul_a');
}
else
$this->tmpl->set_var('row_val', "");
$this->tmpl->parse('tab_rows_',$type,true);
}
function add_row_check($label, $name, $value, $ro = null)
{
$this->tmpl->set_var('row_lab', $name);
$this->tmpl->set_var('row_name', $label);
if($value == "1")
$this->tmpl->set_var('inp_checked', " checked=\"true\"");
else
$this->tmpl->set_var('inp_checked', "");
$this->tmpl->parse('tab_rows_','modul_check',true);
}
function add_row_iframe($label, $idek_r, $id_str)
{
$this->tmpl->set_var('row_name', $label);
$this->tmpl->set_var('inp_str', $id_str);
$this->tmpl->set_var('inp_id_m', $_GET["id"]."&id_lang=".$_GET["id_lang"]);
$this->tmpl->set_var('inp_idd_m', $idek_r);
$db2 = new DB__("select template_menu.id_template from template_menu
where template_menu.id_menu='".$_GET["id"]."'");
if($db2->next_record())
{
$this->tmpl->set_var('inp_id_template', $db2->f('id_template'));
$this->tmpl->parse('tab_rows_','modul_iframe',true);
}
}
function add_row_select($label, $name, $value, $sql)
{
$this->tmpl->set_var('row_lab', $name);
$this->tmpl->set_var('row_name',$label);
$this->tmpl->set_var('inp_onchange', $this->on_change);
$this->tmpl->set_var('inp_options', "");
$db2 = new DB__($sql);
while($db2->next_record())
{
if($db2->f('id') == $value || (isset($this->select_default) && !isset($_GET["idd"]) && ($db2->f('id') == $this->select_default)))
$this->tmpl->set_var('inp_selected', " selected=\"true\"");
else
$this->tmpl->set_var('inp_selected', "");
$this->tmpl->set_var('row_val', $db2->f('id'));
$this->tmpl->set_var('inp_text', $db2->f('name'));
$this->tmpl->parse('inp_options','modul_select_option',true);
}
$this->tmpl->parse('tab_rows_','modul_select',true);
}
/*
$lab = "id_category[]";
$sql1 = "select category_multi_lang.*, institution_multi_temp.id_institution from category_multi_lang
left join institution_multi_temp on institution_multi_temp.id_category=category_multi_lang.id and institution_multi_temp.id_institution='".$_GET["idd"]."'
where category_multi_lang.id_menu='99' and id_lang='".ID_LANG_MAIN."' and category_multi_lang.id not in (select id_category from institution_multi_temp where id_institution!='".$_GET["idd"]."')
order by institution_multi_temp.id_institution desc, category_multi_lang.name";
$sql2 = "select category_multi_lang.* from category_multi_lang
where category_multi_lang.id_menu='99' and id_lang='".ID_LANG_MAIN."'
order by category_multi_lang.name";
$me->add_row_select_multi($lab, "Kategoria", "id_institution", $sql1, $sql2);
*/
function add_row_select_multi($label, $name, $value, $sql1, $sql2, $ro = null)
{
if(isset($ro) || isset($this->ro))
$this->tmpl->set_var('id_inp', " disabled=\"disabled\"");
else
$this->tmpl->set_var('id_inp', "");
$this->tmpl->set_var('row_lab', $name);
$this->tmpl->set_var('row_name',$label);
$this->tmpl->set_var('inp_size', "8");
$this->tmpl->set_var('inp_onchange', "");
$this->tmpl->set_var('inp_options', "");
if(isset($_GET["idd"]))
$db2 = new DB__($sql1);
else
$db2 = new DB__($sql2);
while($db2->next_record())
{
if($db2->f($value))
$this->tmpl->set_var('inp_selected', " selected=\"true\"");
else
$this->tmpl->set_var('inp_selected', "");
$this->tmpl->set_var('row_val', $db2->f('id'));
$this->tmpl->set_var('inp_text', $db2->f('name'));
$this->tmpl->parse('inp_options','modul_select_option',true);
}
$this->tmpl->parse('tab_rows_','modul_select_multi',true);
}
function add_row_select_refresh($label, $name, $value, $sql, $id_refresh)
{
$this->tmpl->set_var('row_lab', $name);
$this->tmpl->set_var('row_name',$label);
$this->tmpl->set_var('inp_onchange', "");
$this->tmpl->set_var('inp_options', "");
$db2 = new DB__($sql);
while($db2->next_record())
{
if($db2->f('id') == $value || (isset($this->select_default) && !isset($_GET["idd"]) && ($db2->f('id') == $this->select_default)))
$this->tmpl->set_var('inp_selected', " selected=\"true\"");
else
$this->tmpl->set_var('inp_selected', "");
$this->tmpl->set_var('row_val', $db2->f('id'));
$this->tmpl->set_var('inp_text', $db2->f('name'));
$this->tmpl->parse('inp_options','modul_select_option',true);
}
$this->tmpl->set_var('refresh_id', $id_refresh);
$this->tmpl->parse('tab_rows_','modul_select_refresh',true);
}
function add_row($label, $name, $value, $type)
{
$this->tmpl->set_var('row_lab', $name);
$this->tmpl->set_var('row_name',$label);
$this->tmpl->set_var('row_val', $value);
$this->tmpl->parse('tab_rows_', $type, true);
}
function add_row_active($value)
{
$lab = "active";
$this->tmpl->set_var('row_lab',"Widoczny");
$this->tmpl->set_var('row_name',$lab);
if($value == "1" || !isset($_GET["idd"]))
$this->tmpl->set_var('inp_checked', " checked=\"true\"");
else
$this->tmpl->set_var('inp_checked', "");
$this->tmpl->parse('tab_rows_','modul_check',true);
}
function add_row_checkbox($label, $name, $value)
{
$this->tmpl->set_var('row_lab', $name);
$this->tmpl->set_var('row_name',$label);
if($value == "1")
$this->tmpl->set_var('inp_checked', " checked=\"true\"");
else
$this->tmpl->set_var('inp_checked', "");
$this->tmpl->parse('tab_rows_','modul_check',true);
}
function add_row_date_($label, $name, $value, $type)
{
$this->tmpl->set_var('row_lab',$name);
$this->tmpl->set_var('row_name',$label);
if(isset($_GET["idd"]))
$this->tmpl->set_var('row_val', $value);
else
$this->tmpl->set_var('row_val',date("Y-m-d"));
$this->tmpl->parse('tab_rows_', $type, true);
}
}
class Baza
{
public $over_lang = 1;//nadrzedny domyslny ???
public $filus_adm = 1;
private $main_roots = array();
private $main_roots_struct = array();
public $users_services = array();
public $users_sites = array();
public $name = null;
function __construct()
{
$this->authorisation();
$this->set_user_tabs();
$this->site_access();
}
function authorisation()
{
if(isset($_SESSION["id_user"]) && isset($_SESSION["uniq_user"]))
{
$db = new DB__("select users.* from users
where users.id='".$_SESSION["id_user"]."' and users.uniq='".$_SESSION["uniq_user"]."' and users.active='1'");
if(!$db->next_record())
header("Location: index.php");
else
$this->name = $db->f('name')." ".$db->f('surname');
}
else
header("Location: index.php");
}
function set_user_tabs()
{
if($_SESSION["guru"] == 2)
{
$db = new DB__("select users_site.id_menu, menu.id_service from users_site, menu
where menu.id=users_site.id_menu and users_site.id_user='".$_SESSION["id_user"]."'");
if($db->nf())
{
while($db->next_record())
{
$this->users_sites[] = $db->f('id_menu');
if(!in_array($db->f('id_service'), $this->users_services))
$this->users_services[] = $db->f('id_service');
}
}
else
{
$db2 = new DB__("select users_service.id_service from users_service
where users_service.id_user='".$_SESSION["id_user"]."'");
if($db2->nf())
{
while($db2->next_record())
$this->users_services[] = $db2->f('id_service');
}
}
sort($this->users_services);
}
}
function site_access()
{
if(!isset($_GET["id"]))
$_GET["id"] = NULL;
else
{
$_GET["id"] = intval($_GET["id"]);
if($_GET["id"] <= 0 || $_GET["id"] == "")
$_GET["id"] = NULL;
}
if($_SESSION["guru"] == 1)
{
if(!isset($_SESSION["lang"]))
{
$db = new DB__("select menu_service.id from menu_service
order by menu_service.id
limit 0,1");
if($db->next_record())
$_SESSION["lang"] = $db->f('id');
}
}
else if($_SESSION["guru"] != 1)
{
if(!isset($_SESSION["lang"]))
{
$_SESSION["lang"] = $this->users_services[0];
}
if(!empty($this->users_services))
{
if(!in_array($_SESSION["lang"], $this->users_services))
{
$_SESSION["lang"] = null;
header("Location: cms.php");
}
}
if(!empty($this->users_sites))
{
if(isset($_GET["id"]))
{
reset($this->users_sites);
while(list($k, $v) = each($this->users_sites))
{
if(in_array($_GET["id"], $this->all_childs($v)) || $_GET["id"] == $v)
return true;
}
header("Location: cms.php");
}
}
}
}
function template_access()
{
$tab_services = array();
$db = new DB__("select template_menu.id_menu, menu_lang.name as menu_name, menu.id_service as menu_service, m2.name as m2_name from template_menu
left join menu on menu.id=template_menu.id_menu
left join menu_lang on menu_lang.id_menu=template_menu.id_menu
left join menu_lang as m2 on m2.id_menu=menu.id_menu
where template_menu.id_template=
(select template_menu.id_template from template_menu
where template_menu.id_menu='".$_GET["id"]."')
order by menu_name");
while($db->next_record())
{
if($_SESSION["guru"] == 1 || in_array($db->f('id_menu'), $this->users_sites) || (empty($this->users_sites) && in_array($db->f('menu_service'), $this->users_services)))
$tab_services[$db->f('id_menu')] = $db->f('menu_name')." <= ".$db->f('m2_name');
}
return $tab_services;
}
static function search_path($id)
{
$str = "";
$db = new DB__("select menu.id, menu_lang.name from menu_root, menu
left join menu_lang on menu_lang.id_menu=menu.id and menu_lang.id_lang='".$_SESSION["id_language"]."'
where menu_root.id_root = menu.id and menu_root.id_menu = '$id' and menu.type in ('1','0')
order by menu_root.ord desc");
while($db->next_record())
{
$str .= "
f('name'),$db->f('id'))."\">".$db->f('name')."";
}
$db = new DB__("select menu.id, menu_lang.name from menu
left join menu_lang on menu_lang.id_menu=menu.id and menu_lang.id_lang='".$_SESSION["id_language"]."'
where menu.id = '$id' and menu.type in ('1','0')");
if($db->next_record())
$str .= "f('name'),$db->f('id'))."\">".$db->f('name')."";
return $str;
}
static function show_registry($id, $idd = null)
{
$text = "";
$where = "";
$where2 = "";
$ider_reg = 209;
if(isset($idd))
$where = "and registry.idd = '$idd'";
/*
//Rejestr zmian podstrony
$db = new DB__("select registry.date_, registry.id, concat(users.name, ' ', users.surname) as name_ from registry, users
where registry.id_user=users.id and registry.id_menu = '$id' $where and registry.kind in (1,2,3,7,8,9,10,11,12)
order by registry.date_
limit 0,1");
if(0)//$db->next_record())
{
if(isset($idd))
$text .= "Rejestr zmian podstrony
";
else
$text .= "Rejestr zmian podstrony
";
}
//wprowadzil
$db = new DB__("select registry.date_, registry.id, concat(users.name, ' ', users.surname) as name_ from registry, users
where registry.id_user=users.id and registry.id_menu = '$id' $where and registry.kind in (1,2,3,7,8,9,10,11,12)
order by registry.date_
limit 0,1");
if(0)//$db->next_record())
{
$text .= "Informację wprowadził(a): ".$db->f('name_')." (".$db->f('date_').")
";
}
//zmodyfikował
$db2 = new DB__("select registry.date_, concat(users.name, ' ', users.surname) as name_ from registry, users
where registry.id_user=users.id and registry.id_menu = '$id' $where and registry.kind in (1,2,3,7,8,9,10,11,12) and registry.id!='".$db->f('id')."'
order by registry.date_ desc
limit 0,1");
if(0)//$db2->next_record())
{
$text .= "Informację zmodyfikował(a): ".$db2->f('name_')." (".$db2->f('date_').")
";
}
*/
//Liczba odwiedzin
if(isset($idd))
$db2 = new DB__("SELECT sum(counter) as amount from stats_site where id_site='".$id."' and idd_site='".$idd."'");
else
$db2 = new DB__("SELECT sum(counter) as amount from stats_site where id_site='".$id."' and idd_site='0'");
if($db2->next_record())
{
$text .= "Liczba odwiedzin: ".$db2->f('amount')."
";
}
return $text;
}
static function have_children($id)
{
$db = new DB__("select menu.id from menu
where menu.id_menu='".intval($id)."'");
if($db->next_record())
return true;
else
return false;
}
function have_children_struct($id)
{
$db = new DB__("select structure.id from structure
where structure.root='".intval($id)."'");
if($db->next_record())
return true;
else
return false;
}
static function have_files($id)
{
$db = new DB__("select file.id from file
where file.idd='".intval($id)."' and file.id_template='0'");
if($db->nf())
return $db->nf();
else
return false;
}
static function have_photos($id)
{
$db = new DB__("select photo.id from photo
where photo.idd='".intval($id)."' and photo.id_template='0'");
if($db->nf())
return $db->nf();
else
return false;
}
function get_site_name_www($id)
{
$db = new DB__("select menu_lang.name from menu_lang
where menu_lang.id_menu='".intval($id)."' and menu_lang.id_lang='".$_SESSION["id_language"]."'");
if($db->next_record())
return $db->f('name');
else
return false;
}
function get_site_name($id)
{
$db = new DB__("select menu_lang.name from menu_lang
where menu_lang.id_menu='".intval($id)."' and menu_lang.id_lang='".$_SESSION["id_lang_cms"]."'");
if($db->next_record())
return $db->f('name');
else
return false;
}
static function get_service_main_id($id)
{
$db = new DB__("select menu.id from menu
where menu.id_service='".intval($id)."' and menu.type='2'");
if($db->next_record())
return $db->f('id');
else
return false;
}
function get_root($id)
{
$db = new DB__("select menu.id_menu from menu
where menu.id='".intval($id)."'");
if($db->next_record())
return $db->f('id_menu');
else
return false;
}
function get_root_struct($id)
{
$db = new DB__("select structure.root from structure
where structure.id='".intval($id)."'");
if($db->next_record())
return $db->f('root');
else
return false;
}
function main_root($id)
{
$db = new DB__("select menu.main_root from menu
where menu.id='".intval($id)."'");
if($db->next_record())
return $db->f('main_root');
else
return false;
}
function make_main_roots($id)
{
$db = new DB__("select menu.id_menu from menu
where menu.id='".$id."'");
if($db->next_record())
{
if($db->f('id_menu') == 0)
return $this->main_roots;
else
{
$this->main_roots[] = $db->f('id_menu');
$this->make_main_roots($db->f('id_menu'));
}
}
return $this->main_roots;
}
function make_main_roots_struct($id)
{
$db = new DB__("select structure.root from structure
where structure.id='".$id."'");
if($db->next_record())
{
if($db->f('root') == 0)
return $this->main_roots_struct;
else
{
$this->main_roots_struct[] = $db->f('root');
$this->make_main_roots_struct($db->f('root'));
}
}
return $this->main_roots_struct;
}
static function tab_of_roots($id)
{
$tab = array();
$db = new DB__("select menu_root.id_root from menu_root
where menu_root.id_menu='".intval($id)."'
order by menu_root.ord");
while($db->next_record())
{
$tab[] = $db->f('id_root');
}
return $tab;
}
function tab_of_roots_struct($id)
{
$tab = array();
$db = new DB__("select structure_root.id_root from structure_root
where structure_root.id_menu='".intval($id)."'
order by structure_root.ord");
while($db->next_record())
{
$tab[] = $db->f('id_root');
}
return $tab;
}
function all_childs($id)
{
$tab = array();
$db = new DB__("select menu_root.id_menu from menu_root
where menu_root.id_root='".intval($id)."'");
while($db->next_record())
$tab[] = $db->f('id_menu');
return $tab;
}
function all_childs_struct($id)
{
$tab = array();
$db = new DB__("select structure_root.id_menu from structure_root
where structure_root.id_root='".intval($id)."'");
while($db->next_record())
$tab[] = $db->f('id_menu');
return $tab;
}
function registry($act, $id, $idd = "", $txt = "")
{
$in = 1;
/*
if($idd && $act >= 7 && $act <= 12)
{
$db = new DB__("select id from registry where id_menu='$id' and idd='$idd'");
if(!$db->nf())
{
$in = null;
}
}*/
$db = new DB__("select name from menu_lang where id_menu='$id' and id_lang='".$_SESSION["id_lang_cms"]."'");
if($db->next_record() && isset($in))
{
$txt = str_replace("\r\n", " ", $txt);
$txt = str_replace("\n", " ", $txt);
if($act == 1)
$chan = "Dodanie informacji $txt na stronie - ".$db->f('name');
else if($act == 2)
$chan = "Edycja informacji ".$txt." na stronie - ".$db->f('name');
else if($act == 3)
$chan = "Usunięcie informacji $txt na stronie - ".$db->f('name');
else if($act == 4)
$chan = "Stworzenie strony - ".$db->f('name');
else if($act == 5)
$chan = "Edycja nazwy strony - ".$db->f('name');
else if($act == 6)
$chan = "Usunięcie strony - ".$txt;
else if($act == 7)
$chan = "Dodanie załącznika $txt na stronie - ".$db->f('name');
else if($act == 8)
$chan = "Edycja załącznika $txt na stronie - ".$db->f('name');
else if($act == 9)
$chan = "Usunięcie załącznika $txt na stronie - ".$db->f('name');
else if($act == 10)
$chan = "Dodanie foto $txt na stronie - ".$db->f('name');
else if($act == 11)
$chan = "Edycja foto $txt na stronie - ".$db->f('name');
else if($act == 12)
$chan = "Usunięcie fotki na $txt stronie - ".$db->f('name');
$datka = date("Y-m-d H:i:s");
new DB__("insert into registry (id_user, text, date_, id_menu, idd, kind) values ('".$_SESSION["id_user"]."', '".addslashes($chan)."', '".$datka."', '".$id."', '".$idd."','".$act."')");
}
}
function paste()
{
//musimy zmienic inne ordy - najpierw stary ord
$old_ord = null;
$dbb = new DB__("select ord, id_menu, id_service from menu where id = '".$_SESSION["cut"]."'");
if($dbb->next_record())
{
$old_ord = $dbb->f('ord');
new DB__("update menu set ord=ord-1 where ord > '".$dbb->f('ord')."' and id_menu = '".$dbb->f('id_menu')."' and id_service = '".$dbb->f('id_service')."'");
}
//musimy zmienic inne ordy - potem nowy
if(isset($old_ord))
new DB__("update menu set ord=ord+1 where ord >= '".$old_ord."' and id_menu = '".$_GET["id"]."' and id_service = '".$_SESSION["lang"]."'");
$main_root = $this->main_root($_GET["id"]);
new DB__("update menu set id_menu='".$_GET["id"]."', id_service='".$_SESSION["lang"]."', main_root='$main_root'
where id='".$_SESSION["cut"]."'");
new DB__("delete from menu_root where id_menu='".$_SESSION["cut"]."'");
$tab_mr = array();
$tab_mr = $this->tab_of_roots($_GET["id"]);
array_unshift($tab_mr, $_GET["id"]);
$i = 0;
while(list($k, $l)=each($tab_mr))
{
$i++;
new DB__("insert into menu_root (id_menu, id_root, ord) values ('".$_SESSION["cut"]."', '$l', '$i')");
}
$childs = $this->all_childs($_SESSION["cut"]);
for($i = 0;$i < sizeof($childs);$i++)
{
new DB__("update menu set id_service='".$_SESSION["lang"]."', main_root='$main_root' where id='".$childs[$i]."'");
$db = new DB__("select menu.id_menu from menu where menu.id='".$childs[$i]."'");
if($db->next_record())
{
new DB__("delete from menu_root where id_menu='".$childs[$i]."'");
$tab_mr = array();
$tab_mr = $this->tab_of_roots($db->f('id_menu'));
array_unshift($tab_mr, $db->f('id_menu'));
$ii = 0;
while(list($k, $l)=each($tab_mr))
{
$ii++;
new DB__("insert into menu_root (id_menu, id_root, ord) values ('".$childs[$i]."', '$l', '$ii')");
}
}
}
}
function paste_struct()
{
new DB__("update structure set root='".$_GET["idd"]."'
where id='".$_SESSION["cut_struct"]."'");
new DB__("delete from structure_root where id_menu='".$_SESSION["cut_struct"]."'");
$tab_mr = array();
$tab_mr = $this->tab_of_roots_struct($_GET["idd"]);
array_unshift($tab_mr, $_GET["idd"]);
$i = 0;
while(list($k, $l)=each($tab_mr))
{
$i++;
new DB__("insert into structure_root (id_menu, id_root, ord) values ('".$_SESSION["cut_struct"]."', '$l', '$i')");
}
$childs = $this->all_childs_struct($_SESSION["cut_struct"]);
for($i = 0;$i < sizeof($childs);$i++)
{
$db = new DB__("select structure.root from structure where structure.id='".$childs[$i]."'");
if($db->next_record())
{
new DB__("delete from structure_root where id_menu='".$childs[$i]."'");
$tab_mr = array();
$tab_mr = $this->tab_of_roots_struct($db->f('root'));
array_unshift($tab_mr, $db->f('root'));
$ii = 0;
while(list($k, $l)=each($tab_mr))
{
$ii++;
new DB__("insert into structure_root (id_menu, id_root, ord) values ('".$childs[$i]."', '$l', '$ii')");
}
}
}
}
function del()
{
//kasowanie po nowemu and id_lang='".$_SESSION["id_lang_cms"]."'
//niezaleznie od wersji (kazda ma osobne): file, text, link, photo_lang
// and id_lang='".$_SESSION["id_lang_cms"]."'
//podzielimy na kasowanie all i czyszczenie wersji jęz.
//all
$db = new DB__("select * from file where file.idd='".intval($_GET["id"])."' and file.id_template='0'");
while($db->next_record())
{
if($db->f('path'))
File::file_del(PATH_DOC.$db->f('path'));
}
new DB__("delete from file where file.idd='".intval($_GET["id"])."' and file.id_template='0'");
$db = new DB__("select photo.* from photo where photo.idd='".intval($_GET["id"])."' and photo.id_template='0'");
while($db->next_record())
{
if($db->f('photo_m'))
File::file_del(PATH_IMG.$db->f('photo_m'));
if($db->f('photo_b'))
File::file_del(PATH_IMG.$db->f('photo_b'));
new DB__("delete from photo_lang where photo_lang.id_photo='".$db->f('id')."'");
}
new DB__("delete from photo where photo.idd='".intval($_GET["id"])."' and photo.id_template='0'");
new DB__("delete from users_site where id_menu='".$_GET["id"]."'");
new DB__("delete from template_menu where id_menu='".$_GET["id"]."'");
new DB__("delete from text where id_menu='".$_GET["id"]."'");
new DB__("delete from link where id_menu='".$_GET["id"]."'");
new DB__("delete from menu_root where id_menu='".$_GET["id"]."'");
$db2 = new DB__("select id, ord, id_menu, id_service from menu
where id='".$_GET["id"]."'");
if($db2->next_record())
{
//zmiana orda
new DB__("update menu set ord=ord-1 where ord > '".$db2->f('ord')."' and id_menu = '".$db2->f('id_menu')."' and id_service = '".$db2->f('id_service')."'");
$this->registry(6, $_GET["id"], "", $db2->f('id'));
}
new DB__("delete from menu where id='".$_GET["id"]."'");
new DB__("delete from menu_lang where id_menu='".$_GET["id"]."'");
$childs = $this->all_childs($_GET["id"]);
for($i = 0;$i < sizeof($childs);$i++)
{
$db3 = new DB__("select id from menu where id='".$childs[$i]."'");
if($db3->next_record())
$this->registry(6, $childs[$i], "", $db3->f('id'));
$db = new DB__("select * from file where file.idd='".$childs[$i]."' and file.id_template='0'");
while($db->next_record())
{
if($db->f('path'))
File::file_del(PATH_DOC.$db->f('path'));
}
new DB__("delete from file where file.idd='".$childs[$i]."' and file.id_template='0'");
$db = new DB__("select * from photo where photo.idd='".$childs[$i]."' and photo.id_template='0'");
while($db->next_record())
{
if($db->f('photo_m'))
File::file_del(PATH_IMG.$db->f('photo_m'));
if($db->f('photo_b'))
File::file_del(PATH_IMG.$db->f('photo_b'));
new DB__("delete from photo_lang where photo_lang.id_photo='".$db->f('id')."'");
}
new DB__("delete from photo where photo.idd='".$childs[$i]."' and photo.id_template='0'");
new DB__("delete from menu where id='".$childs[$i]."'");
new DB__("delete from menu_lang where id_menu='".$childs[$i]."'");
new DB__("delete from text where id_menu='".$childs[$i]."'");
new DB__("delete from link where id_menu='".$childs[$i]."'");
new DB__("delete from template_menu where id_menu='".$childs[$i]."'");
new DB__("delete from menu_root where id_menu='".$childs[$i]."'");
}
$_GET["id"] = $db2->f('id_menu');
}
function del_struct()
{
$id_temp = "";
$db = new DB__("select * from file where file.idd='".intval($_GET["idd"])."' and file.id_template=(select id_template from template_menu where template_menu.id_menu='".$_GET["id"]."')");
while($db->next_record())
{
$id_temp = $db->f('id_template');
if($db->f('path'))
File::file_del(PATH_DOC.$db->f('path'));
}
new DB__("delete from file where file.idd='".intval($_GET["idd"])."' and file.id_template='".$id_temp."'");
new DB__("delete from structure_root where id_menu='".$_GET["idd"]."'");
$db2 = new DB__("select root, name, id_menu, ord from structure where id='".$_GET["idd"]."'");
if($db2->next_record())
{
//zmiana orda
new DB__("update structure set ord=ord-1 where ord > '".$db2->f('ord')."' and id_menu = '".$db2->f('id_menu')."' and root = '".$db2->f('root')."'");
$this->registry(3, $_GET["id"], $_GET["idd"], $db2->f('name'));
}
new DB__("delete from structure where id='".$_GET["idd"]."'");
$childs = $this->all_childs_struct($_GET["idd"]);
for($i = 0;$i < sizeof($childs);$i++)
{
$db3 = new DB__("select name from structure where id='".$childs[$i]."'");
if($db3->next_record())
$this->registry(3, $_GET["id"], $childs[$i], $db3->f('name'));
$db3 = new DB__("select * from file where file.idd='".$childs[$i]."' and file.id_template='".$id_temp."'");
while($db3->next_record())
{
if($db3->f('path'))
File::file_del(PATH_DOC.$db3->f('path'));
}
new DB__("delete from file where file.idd='".$childs[$i]."' and file.id_template='".$id_temp."'");
new DB__("delete from structure where id='".$childs[$i]."'");
new DB__("delete from structure_root where id_menu='".$childs[$i]."'");
}
$_GET["idd"] = $db2->f('root');
}
function order($tab)
{
if(list($k, $l) = each($tab))
{
$l = intval($l);
if($l == 0)
$l = 1;
if($k > 0)
{
//musimy zmienic inne ordy
$dbb = new DB__("select ord, id_menu, id_service from menu where id = '$k'");
if($dbb->next_record())
{
if($l > $dbb->f('ord'))
new DB__("update menu set ord=ord-1 where ord <= '".$l."' and ord > '".$dbb->f('ord')."' and id_menu = '".$dbb->f('id_menu')."' and id_service = '".$dbb->f('id_service')."'");
else if($l < $dbb->f('ord'))
new DB__("update menu set ord=ord+1 where ord >= '".$l."' and ord < '".$dbb->f('ord')."' and id_menu = '".$dbb->f('id_menu')."' and id_service = '".$dbb->f('id_service')."'");
}
new DB__("update menu set ord='$l' where id = '$k'");
}
}
}
function order_struct($tab)
{
if(list($k, $l) = each($tab))
{
$l = intval($l);
if($l == 0)
$l = 1;
if($k > 0)
{
//musimy zmienic inne ordy
$dbb = new DB__("select ord, id_menu, root from structure where id = '$k'");
if($dbb->next_record())
{
if($l > $dbb->f('ord'))
new DB__("update structure set ord=ord-1 where ord <= '".$l."' and ord > '".$dbb->f('ord')."' and id_menu = '".$dbb->f('id_menu')."' and root = '".$dbb->f('root')."'");
else if($l < $dbb->f('ord'))
new DB__("update structure set ord=ord+1 where ord >= '".$l."' and ord < '".$dbb->f('ord')."' and id_menu = '".$dbb->f('id_menu')."' and root = '".$dbb->f('root')."'");
}
new DB__("update structure set ord='$l' where id = '$k'");
}
}
}
function update($tab)
{
while(list($k,$l)=each($tab))
{
if($l != "")
{
if($k != "0")
{
$db = new DB__("select name from menu_lang where id_menu='$k' and id_lang='".$_SESSION["id_lang_cms"]."'");
if($db->nf())
new DB__("update menu_lang set name='$l' where id_menu='$k' and id_lang='".$_SESSION["id_lang_cms"]."'");
else
new DB__("insert into menu_lang (id_menu, id_lang, name) values ('$k', '".$_SESSION["id_lang_cms"]."', '$l')");
$this->registry("5", $k, "", "");
$_GET["id"] = $k;
header("Location: cms.php?id=".$k);
}
else
{
if($_POST["menu_go"] > 0)
{
$main_root = $this->main_root($_POST["menu_go"]);
$db = new DB__("insert into menu (id_menu, ord, id_service, main_root) VALUES ('".$_POST["menu_go"]."','".$_POST["menu_ord"][0]."','".$_SESSION['lang']."','$main_root')");
$_GET["id"] = $db->maxid();
new DB__("insert into menu_lang (id_menu, id_lang, name) VALUES ('".$_GET["id"]."', '".$_SESSION["id_lang_cms"]."', '$l')");
//musimy zmienic inne ordy
$dbb = new DB__("select id_menu, id_service from menu where id = '".$_GET["id"]."'");
if($dbb->next_record())
{
new DB__("update menu set ord=ord+1 where ord >= '".$_POST["menu_ord"][0]."' and id_menu = '".$dbb->f('id_menu')."' and id_service = '".$dbb->f('id_service')."' and id != '".$_GET["id"]."'");
}
$this->registry("4", $_GET["id"], "", "");
//echo "reg4".$_GET["id"];
$tab_mr = array();
$tab_mr = $this->make_main_roots($_GET["id"]);
$i = 0;
while(list($k, $l)=each($tab_mr))
{
$i++;
new DB__("insert into menu_root (id_menu, id_root, ord) values ('".$_GET["id"]."', '$l', '$i')");
}
header("Location: cms.php?id=".$_GET["id"]);
}
else
{
if(isset($this->filus_adm))
{
$db = new DB__("insert into menu (id_menu, ord, id_service, type) VALUES (0, '".$_POST["menu_ord"][0]."','".$_SESSION['lang']."','4')");
$_GET["id"] = $db->maxid();
new DB__("insert into menu_lang (id_menu, id_lang, name) VALUES ('".$_GET["id"]."', '".$_SESSION["id_lang_cms"]."', '$l')");
new DB__("update menu set main_root='".$_GET["id"]."' where id='".$_GET["id"]."'");
$this->registry("4", $db->maxid(), "", "");
header("Location: cms.php?id=".$_GET["id"]);
}
}
}
$db3 = new DB__("select name from menu_lang where id_menu='".$_GET["id"]."' and id_lang='".$_SESSION["id_lang_cms"]."'");
if($db3->next_record())
{
$path = "../graph/menu_up/";
$font = "../graph/myriadpro1.ttf";
$name = $_SESSION["id_lang_cms"]."menu_up".$_GET["id"];
$name_ = mb_strtolower($db3->f('name'));
$size = 12;
File::make_menu_img($path, $name_, $name, $font, $size);
/*
$font = "../graph/myriadpro1.ttf";
$size = 14;
$name = $_SESSION["id_lang_cms"]."label".$_GET["id"];
$name_ = mb_strtoupper($db3->f('name'));
File::make_menu_img2($path, $name_, $name, $font, $size);
$size = 18;
$name = $_SESSION["id_lang_cms"]."label_main".$_GET["id"];
$name_ = mb_strtoupper($db3->f('name'));
File::make_menu_img3($path, $name_, $name, $font, $size);
$name = "title".$_GET["id"];
$name_ = mb_strtoupper($db3->f('name'));
$size = 12;
File::make_menu_img($path, $name_, $name, $font, $size);
*/
//$font = "../graph/shardee.ttf";
//$name = "label".$_GET["id"];
//File::make_menu_img_shardee($path, $name_, $name, $font);
}
}
}
}
function update_struct($tab)
{
while(list($k,$l)=each($tab))
{
if($l != "")
{
if($k != "0")
{
new DB__("update structure set name='$l' where id='$k'");
$this->registry("2", $_GET["id"], $k, $l);
header("Location: modules.php?id=".$_GET["id"]."&idd=".$k);
}
else
{
if($_POST["menu_go"] > 0)
{
$db = new DB__("insert into structure (name, id_menu, root, ord) VALUES ('$l','".$_GET["id"]."','".$_POST["menu_go"]."','".$_POST["menu_ord"][0]."')");
$_GET["idd"] = $db->maxid();
//musimy zmienic inne ordy
$dbb = new DB__("select id_menu, root from structure where id = '".$_GET["id"]."'");
if($dbb->next_record())
{
new DB__("update menu set ord=ord+1 where ord >= '".$_POST["menu_ord"][0]."' and id_menu = '".$dbb->f('id_menu')."' and root = '".$dbb->f('root')."' and id != '".$_GET["id"]."'");
}
$this->registry("1", $_GET["id"], $_GET["idd"], $l);
$tab_mr = array();
$tab_mr = $this->make_main_roots_struct($_GET["idd"]);
$i = 0;
while(list($k, $l)=each($tab_mr))
{
$i++;
new DB__("insert into structure_root (id_menu, id_root, ord) values ('".$_GET["idd"]."', '$l', '$i')");
}
header("Location: modules.php?id=".$_GET["id"]."&idd=".$_GET["idd"]);
}
else
{
if(isset($this->filus_adm))
{
$db = new DB__("insert into structure (name, root, id_menu, ord) VALUES ('$l',0, '".$_GET["id"]."', '".$_POST["menu_ord"][0]."')");
$_GET["idd"] = $db->maxid();
$this->registry("1", $_GET["id"], $_GET["idd"], $l);
header("Location: modules.php?id=".$_GET["id"]."&idd=".$_GET["idd"]);
}
}
}
}
}
}
function del_content()
{
new DB__("delete from text where id_menu='".$_GET["id"]."' and id_lang='".$_SESSION["id_lang_cms"]."'");
$this->registry("3", $_GET["id"]);
return 0;
}
function edit_content()
{
new DB__("update menu set level='".intval($_POST["text_level"])."' where id='".$_GET["id"]."'");
new DB__("update menu set type = '".intval($_POST["text_type"])."' where id = '".$_GET["id"]."'");
new DB__("update menu_lang set title = '".$_POST["title"]."', keywords = '".$_POST["keywords"]."', description = '".$_POST["description"]."' where id_menu = '".$_GET["id"]."' and id_lang='".$_SESSION["id_lang_cms"]."'");
if(isset($_POST["text_active"]))
$_POST["text_active"] = "1";
else
$_POST["text_active"] = "0";
$db = new DB__("select text from text
where id_menu='".$_GET["id"]."' and id_lang='".$_SESSION["id_lang_cms"]."'");
if($db->nf())
{
new DB__("update text set text='".$_POST["text_inp"]."', active='".$_POST["text_active"]."' where id_menu='".$_GET["id"]."' and id_lang='".$_SESSION["id_lang_cms"]."'");
$this->registry("2", $_GET["id"]);
}
else
{
new DB__("insert into text (id_menu, id_lang, text, active) values ('".$_GET["id"]."', '".$_SESSION["id_lang_cms"]."', '".$_POST["text_inp"]."', '".$_POST["text_active"]."')");
$this->registry("1", $_GET["id"]);
}
return 1;
}
}
class Admin extends Baza
{
private $tab_roots = array();
function __construct()
{
if(isset($_GET["id"]))
if($_GET["id"] != "")
$this->tab_roots = $this->tab_of_roots($_GET["id"]);
}
function show_menu($id = 0, $depth = 0)
{
global $tmpl;
$space = 1;
if($depth == 0 && $id != 0)
{
$db = new DB__("select menu.id, menu.type, menu.id_menu, if(menu_lang.name is null, concat(''), menu_lang.name) as name, if(menu_lang.name is null, 0, 1) as is_name, menu.ord from menu
left join menu_lang on menu_lang.id_menu=menu.id and menu_lang.id_lang='".$_SESSION["id_lang_cms"]."'
left join menu_lang as ml_main on ml_main.id_menu=menu.id and ml_main.id_lang='".$this->over_lang."'
where menu.id='$id' and menu.id_service='".$_SESSION["lang"]."'
order by menu.ord");
}
else
{
$db = new DB__("select menu.id, menu.type, menu.id_menu, if(menu_lang.name is null, concat(''), menu_lang.name) as name, if(menu_lang.name is null, 0, 1) as is_name, menu.ord from menu
left join menu_lang on menu_lang.id_menu=menu.id and menu_lang.id_lang='".$_SESSION["id_lang_cms"]."'
left join menu_lang as ml_main on ml_main.id_menu=menu.id and ml_main.id_lang='".$this->over_lang."'
where menu.id_menu='$id' and menu.id_service='".$_SESSION["lang"]."'
order by menu.ord");
}
$tmpl->set_var('tree_row_ul', '