add_register("cms_modules",true);
class cms_build{
var $data = "";
var $contener_list=array();
var $cadre_list=array();
var $objet_list=array();
var $name_list=array();
var $objets_att=array();
var $versions=array();
var $last_version_data=array();
var $classement_list=array();
var $pages_classement_list=array();
var $pages;
var $dom;
var $id_version;
//Constructeur
function cms_build(){
global $include_path,$charset;
@ini_set("zend.ze1_compatibility_mode", "0");
$this->dom = new DomDocument();
$this->dom->load("$include_path/cms/cms_build/cms_build_id.xml") ;
$cms_objects=$this->dom->getElementsByTagName('cms_object');
$this->contener_list=array();
$this->cadre_list=array();
$this->objet_list=array();
$this->page_list=array();
$this->name_list=array();
$this->versions=array();
$this->last_version_data=array();
$rqt = "select * from cms ";
$res=mysql_query($rqt);
if(!mysql_num_rows($res)){
// on crée un cms par défaut
$this->id_version=$this->create_new_cms();
}
$this->get_versions_list();
$this->id_version=$this->get_version_default();
foreach ($cms_objects as $cms_object){
$node_name=$cms_object->getAttribute('id');
if($cms_object->getAttribute('container')=='yes'&& $cms_object->getAttribute('receptable')=='yes'){
$this->contener_list[]=$node_name;
}elseif($cms_object->getAttribute('draggable')=='yes' && $cms_object->getAttribute('receptable')=='yes'){
// un cadre
$this->cadre_list[]=$node_name;
if($cms_object->getAttribute('zone')=='yes') {
$this->zone_list[]=$node_name;
}
}elseif($cms_object->getAttribute('draggable')=='yes'){
// un objet déplacable dans un cadre ou le contener
$this->objet_list[]=$node_name;
}
$label=$cms_object->getAttribute('label');
if ($charset!="utf-8") $label=utf8_decode($label);
$this->name_list[$cms_object->getAttribute('id')]=$label;
$this->objets_att[$node_name]['fixed']=0;
if($cms_object->getAttribute('fixed')=='yes'){
// print $cms_object->getElementsByTagName('parent')->item(0);
$this->objets_att[$node_name]['fixed']=1;
$rqt = "select * from cms_build where build_obj='".$node_name."'";
$res=mysql_query($rqt);
if(!mysql_num_rows($res)){
$placement = array();
if($cms_object->childNodes->length) {
foreach($cms_object->childNodes as $item) {
$placement[$item->nodeName] = $item->nodeValue;
}
}
$rqt_insert = "INSERT INTO cms_build SET
build_version_num='".$this->id_version."',
build_obj='$node_name',
build_fixed='1' ,
build_parent='".$placement['parent']."' ,
build_child_before='".$placement['child_before']."' ,
build_child_after='".$placement['child_after']."'
";
// print $rqt_insert."
";
mysql_query($rqt_insert);
}
}
}
$this->pages=new cms_pages();
$this->pages_classement_list=$this->pages->pages_classement_list;
$this->parser= new cms_modules_parser();
$this->modules = $this->parser->get_modules_list();
$this->cadres = $this->parser->get_cadres_list();
$this->cadres_classement_list=$this->parser->cadres_classement_list;
//printr($this->versions);
//print($this->id_version);
@ini_set("zend.ze1_compatibility_mode", "1");
}
function create_new_cms($name=''){
global $dbh,$msg,$PMBuserid;
if(!$name){ // c'est le tout premier
$selected=1;
$name=$msg["cms_build_version_cms_default_name"];
}
$rqt_insert = "INSERT INTO cms SET
cms_name='$name'
";
mysql_query($rqt_insert);
$id_cms = mysql_insert_id();
$rqt_insert = "INSERT INTO cms_version SET
version_cms_num = '$id_cms',
version_date = now(),
version_comment = '".$msg["cms_build_version_cms_default_tag_name"]."',
version_user = $PMBuserid
";
mysql_query($rqt_insert);
$id_version = mysql_insert_id();
return $id_version;
}
function save_version_form($id_cms=0){
global $name, $comment,$opac_default;
global $dbh,$msg,$PMBuserid;
if($id_cms){
$rqt="Update cms SET cms_name='$name',cms_comment='$comment',cms_opac_default='$opac_default' where id_cms=$id_cms ";
mysql_query($rqt);
}else{
$rqt.=" INSERT cms SET
cms_name='$name',
cms_comment='$comment' ,
cms_opac_default='$opac_default'";
mysql_query($rqt);
$id_cms = mysql_insert_id();
$rqt_insert = "INSERT INTO cms_version SET
version_cms_num = '$id_cms',
version_date = now(),
version_comment = '".$msg["cms_build_version_cms_default_tag_name"]."'
version_user = $PMBuserid
";
mysql_query($rqt_insert);
$id_version = mysql_insert_id();
}
if($opac_default){
// on nettoie les autres opac_default
$rqt="Update cms SET cms_opac_default=0 where id_cms!=$id_cms ";
mysql_query($rqt);
// Update du paramètre opac_cms permettant de le sélectionner par défaut
$req="update parametres set valeur_param='".$id_cms."' where type_param = 'opac' and sstype_param='cms' ";
mysql_query($req, $dbh);
}
$rqt="select count(1) from cms where cms_opac_default!=0 ";
$res = mysql_query($rqt, $dbh);
if(!mysql_result($res, 0, 0)){
$req="update parametres set valeur_param=0 where type_param = 'opac' and sstype_param='cms' ";
mysql_query($req, $dbh);
}
$this->get_versions_list();
}
function get_versions_list(){
global $dbh;
$this->versions=array();
$requete = "select * from cms order by cms_name ";
$res = mysql_query($requete, $dbh);
if(mysql_num_rows($res)){
while($row = mysql_fetch_object($res)){
$this->versions[$row->id_cms]['id']=$row->id_cms;
$this->versions[$row->id_cms]['name']=$row->cms_name;
$this->versions[$row->id_cms]['comment']=$row->cms_comment;
$this->versions[$row->id_cms]['selected']=$row->cms_selected;
$this->versions[$row->id_cms]['opac_default']=$row->cms_opac_default;
$this->versions[$row->id_cms]['versions']=array();
$requete = "select * from cms_version where version_cms_num='".$row->id_cms."' order by version_date desc ";
$res_version = mysql_query($requete, $dbh);
while($row_version = mysql_fetch_object($res_version)){
$this->versions[$row->id_cms]['versions'][$row_version->id_version]['id']=$row_version->id_version;
$this->versions[$row->id_cms]['versions'][$row_version->id_version]['date']=$row_version->version_date;
$this->versions[$row->id_cms]['versions'][$row_version->id_version]['comment']=$row_version->version_comment;
$this->versions[$row->id_cms]['versions'][$row_version->id_version]['user']=$row_version->version_user;
$this->versions[$row->id_cms]['versions'][$row_version->id_version]['selected']=$row_version->version_public;
$this->versions_info[$row_version->id_version]['id_cms']=$row->id_cms;
}
}
}
}
function get_version_default(){
global $dbh;
if($_SESSION["cms_in_use"]) $sel= " and id_cms='".$_SESSION["cms_in_use"]."' ";
// on prend la derniere version du cms utilisé
$requete = "select * from cms_version, cms where
id_cms=version_cms_num
$sel
order by version_date desc
";
$res = mysql_query($requete, $dbh);
if($row = mysql_fetch_object($res)){
$_SESSION["cms_in_use"]=$row->id_cms;
$_SESSION["cms_version"]=$row->id_version;
return $row->id_version;
}
// si pas trouvé on prend le premier venu
$requete = "select * from cms_version, cms where
id_cms=version_cms_num
order by version_date desc
";
$res = mysql_query($requete, $dbh);
if($row = mysql_fetch_object($res)){
$_SESSION["cms_in_use"]=$row->id_cms;
$_SESSION["cms_version"]=$row->id_version;
return $row->id_version;
}
}
function version_delete($id_version){
global $dbh;
$req = "delete from cms_version where id_version= $id_version ";
$res = mysql_query($req, $dbh);
$req = "delete from cms_build where build_version_num= $id_version ";
$res = mysql_query($req, $dbh);
$this->get_versions_list();
}
function cms_delete($id_cms){
global $dbh;
$requete = "select * from cms_version where version_cms_num='".$id_cms."' ";
$res_version = mysql_query($requete, $dbh);
while($row_version = mysql_fetch_object($res_version)){
$req = "delete from cms_build where build_version_num='". $row_version->id_version."' ";
mysql_query($req, $dbh);
}
$req = "delete from cms_version where version_cms_num='$id_cms' ";
$res = mysql_query($req, $dbh);
$req = "delete from cms where id_cms= $id_cms ";
$res = mysql_query($req, $dbh);
$this->get_versions_list();
}
function get_form_block(){
global $cms_build_block_tpl;
global $cms_build_pages_tpl;
global $cms_build_pages_tpl_item;
global $cms_build_modules_tpl,$cms_build_modules_tpl_item;
global $build_id_version;
global $dbh;
global $opac_cms;
global $pmb_opac_url,$cms_url_base_cms_build;
if($cms_url_base_cms_build){
$build_url=$cms_url_base_cms_build;
} else $build_url=$pmb_opac_url;
if($build_id_version){
$requete = "select * from cms_version where id_version =$build_id_version ";
$res = mysql_query($requete, $dbh);
if($row = mysql_fetch_object($res)){
$_SESSION["cms_in_use"]=$row->version_cms_num;
$_SESSION["cms_version"]=$row->id_version;
}
}
$tpl=$cms_build_block_tpl;
$javascript="";
if(count($this->contener_list))$javascript.="var cms_contener_list=new Array('".implode("','",$this->contener_list)."');";
if(count($this->cadre_list))$javascript.="var cms_zone_list=new Array('".implode("','",$this->cadre_list)."');";
if(count($this->zone_list))$javascript.="var cms_zone_list_dragable=new Array('".implode("','",$this->zone_list)."');";
if(count($this->objet_list))$javascript.="var cms_objet_list=new Array('".implode("','",$this->objet_list)."');";
$javascript.="var cms_name_list=new Array(); ";
foreach($this->name_list as $id_objet =>$name){
$javascript.="cms_name_list['$id_objet']='".addslashes($name)."'; \n";
}
$tpl=str_replace("!!cms_objet_list_declaration!!",$javascript,$tpl);
$tpl=str_replace("!!opac_url!!",$build_url,$tpl);
$pages_tpl=$this->pages->get_list($cms_build_pages_tpl,$cms_build_pages_tpl_item);
$tpl=str_replace("!!cms_objet_pages!!",$pages_tpl,$tpl);
$tpl=str_replace("!!cms_objet_modules!!", $this->build_modules_list(),$tpl);
$tpl=str_replace("!!id_version!!", $_SESSION["cms_version"],$tpl);
$tpl=str_replace("!!cadre_list_in_page!!", $this->build_cadres_list_in_page(),$tpl);
$tpl=str_replace("!!cadre_list_not_in_page!!", $this->build_cadres_list_not_in_page(),$tpl);
$tpl=str_replace("!!cms_objet_versions!!", $this->build_versions_list(),$tpl);
return $tpl;
}
function build_versions_list(){
global $msg,$cms_build_versions_tpl;
global $cms_build_versions_tpl_item;
$tpl=$cms_build_versions_tpl;
$cadre_portail_list=array();
$items="";
$pair='even';
foreach($this->versions as $version => $infos){
if($pair=='odd')$pair="even"; else $pair="odd";
$item=$cms_build_versions_tpl_item;
$item=str_replace("!!id!!", $infos['id'],$item);
$item=str_replace("!!name!!", $infos['name'],$item);
if($infos['opac_default']) $item=str_replace("!!opac_default!!", $msg["cms_build_cms_opac_default_info"],$item);
else $item=str_replace("!!opac_default!!", "",$item);
$item=str_replace("!!odd_even!!", $pair,$item);
if($_SESSION["cms_in_use"]==$infos['id'])
$item=str_replace("!!cms_in_use!!", "*",$item);
else
$item=str_replace("!!cms_in_use!!", "",$item);
$items.=$item;
}
$tpl=str_replace("!!items!!", $items,$tpl);
return $tpl;
}
function build_versions_list_ajax(){
global $msg;
global $cms_build_versions_tpl_item;
$items="";
$pair='even';
foreach($this->versions as $version => $infos){
if($pair=='odd')$pair="even"; else $pair="odd";
$item=$cms_build_versions_tpl_item;
$item=str_replace("!!id!!", $infos['id'],$item);
$item=str_replace("!!name!!", $infos['name'],$item);
if($infos['opac_default']) $item=str_replace("!!opac_default!!", $msg["cms_build_cms_opac_default_info"],$item);
else $item=str_replace("!!opac_default!!", "",$item);
$item=str_replace("!!odd_even!!", $pair,$item);
if($_SESSION["cms_in_use"]==$infos['id'])
$item=str_replace("!!cms_in_use!!", "*",$item);
else
$item=str_replace("!!cms_in_use!!", "",$item);
$items.=$item;
}
return $items;
}
public function get_version_form($id_cms,$ajax=0){
global $msg;
global $charset;
global $cms_build_version_form_tpl,$cms_build_version_form_ajax_tpl,$cms_build_version_del_button_tpl;
global $cms_build_version_tags_item;
if($ajax)$tpl= $cms_build_version_form_ajax_tpl;
else $tpl=$cms_build_version_form_tpl;
$tpl = str_replace("!!name!!",htmlentities($this->versions[$id_cms]['name'] ,ENT_QUOTES, $charset),$tpl);
$tpl = str_replace("!!comment!!",htmlentities($this->versions[$id_cms]['comment'] ,ENT_QUOTES, $charset),$tpl);
if($id_cms){
$tpl = str_replace("!!form_title!!",htmlentities($msg["cms_build_version_edit_bt"] ,ENT_QUOTES, $charset),$tpl);
$tpl = str_replace("!!form_suppr!!",$cms_build_version_del_button_tpl,$tpl);
$items="";
$pair='even';
foreach($this->versions[$id_cms]['versions'] as $version){
$item=$cms_build_version_tags_item;
$item = str_replace("!!version_date!!",$version['date'],$item);
$item = str_replace("!!id_version!!",$version['id'],$item);
if($version['selected']){
$selected=1;
$item = str_replace("!!checked!!","checked='checked'",$item);
}
else $item = str_replace("!!checked!!","",$item);
if($pair=='odd')$pair="even"; else $pair="odd";
$item=str_replace("!!odd_even!!", $pair,$item);
$items.=$item;
}
}else{
$tpl = str_replace("!!form_title!!",htmlentities($msg["cms_build_version_add_bt"] ,ENT_QUOTES, $charset),$tpl);
$tpl = str_replace("!!form_suppr!!","",$tpl);
}
//print_r($this->versions[$id_cms]);
if($this->versions[$id_cms]["opac_default"]==1) $tpl = str_replace("!!opac_default_checked!!","checked='checked'",$tpl);
else $tpl = str_replace("!!opac_default_checked!!","",$tpl);
$tpl = str_replace("!!version_list!!",$items,$tpl);
if($selected) $tpl = str_replace("!!version_checked!!","",$tpl);
else $tpl = str_replace("!!version_checked!!","checked='checked'",$tpl);
$tpl = str_replace("!!id!!",$id_cms,$tpl);
return $tpl;
}
function build_modules_list(){
global $msg,$cms_build_modules_tpl;
$tpl=$cms_build_modules_tpl;
$module_list="";
foreach($this->modules as $module => $infos){
$module_list.= "
"; } $tpl=str_replace("!!items!!", $module_list,$tpl); return $tpl; } public function save_cadre_classement($id_cadre,$classement){ $id_cadre+=0; $query = "update cms_cadres set cadre_classement='$classement' where id_cadre = ".$id_cadre; mysql_query($query); } function get_classement_list($classement_selected=""){ global $charset,$msg; $tpl=""; if(!$classement_selected) $tpl.=""; else $tpl.=""; foreach($this->cadres_classement_list as $classement=> $val){ if($classement_selected==$classement)$selected=" selected='selected' "; else $selected=""; $tpl.=""; } return $tpl; } public function build_cadres_list_in_page($in_page=""){ global $msg,$cms_build_cadres_in_page_tpl; global $cms_build_cadre_tpl_item; $tpl=$cms_build_cadres_in_page_tpl; $cadre_portail_list=array(); $items=""; $pair='even'; if(!$in_page)$in_page=array(); $classement=""; foreach($this->cadres as $cadre => $infos){ $item=$cms_build_cadre_tpl_item; if(in_array($infos->cadre_object."_".$infos->id_cadre,$in_page)){ if($classement!=$infos->cadre_classement){ $item="