%PDF- %PDF-
Direktori : /home/alliance/domains/congress-intercultural.eu/public_html/inc/classes/ |
Current File : /home/alliance/domains/congress-intercultural.eu/public_html/inc/classes/Page.php |
<?php class Page extends Load { var $bd; var $language; var $sect; var $bloc; var $nom_table='page'; var $clef_primaire='id_page'; var $table=array('section','ordre','type','date_debut','date_fin','date_crea','calendrier'); var $table_lang=array('titre','soustitre','permalien'); function Page($connection) { //constructor parent::Load(); $this->bd = new BaseOps($connection); $this->language = new Lang($connection); $this->sect = new Section($connection); $this->lang = new Lang($connection); $this->bloc = new Bloc($connection); } // lien vers une page function page_link($id) { $page = $this->infos_page($id); if($page != null) { $section = $this->sect->aff_section($page['section']); return $section['id']."-".$section['permalien']."/".$page['id']."-".$page['permalien'].".html"; } else { return null; } } function infos_page($id,$id_lang=null) { if($id_lang==null){ $id_lang=$this->language->getlangid(); } $query = "SELECT * FROM `page` WHERE id_page = ".$id; if($this->bd->isres($query)) { $data = $this->bd->select_array($query); $query = "SELECT * FROM `page_lang` WHERE id_page = ".$data['id_page']." AND id_lang = ".$id_lang; $datalang = $this->bd->select_array($query); if($datalang['titre']=="" && $this->language->getlangid()!=2){ $query = "SELECT * FROM `page_lang` WHERE id_page = ".$data['id_page']." AND id_lang = 2"; $datalang = $this->bd->select_array($query); } $res = array ( 'id' => $data['id_page'], 'section' => $data['section'], 'ordre' => $data['ordre'], 'titre' => $datalang['titre'], 'type' => $data['type'], 'soustitre' => $datalang['soustitre'], 'permalien' => $datalang['permalien'], 'couleur' => $this->sect->couleur_section($data['section']) ); return $res; } else { return null; } } // Liste des blocs function liste_blocs($page,$id_lang=null){ if($id_lang==null){ $id_lang=$this->language->getlangid(); } $query = "SELECT * FROM `bloc` WHERE id_page = ".$page." ORDER BY ordre"; if($this->bd->isres($query)) { $result = $this->bd->q($query); $nb = 0; while( $data = mysqli_fetch_assoc($result)) { $query = "SELECT * FROM `bloc_lang` WHERE id_bloc = ".$data['id_bloc']." AND id_lang = ".$id_lang; $datalang = $this->bd->select_array($query); if($datalang==null || $datalang['valide']=0){ $query = "SELECT * FROM `bloc_lang` WHERE id_bloc = ".$data['id_bloc']." AND id_lang = 2"; $datalang = $this->bd->select_array($query); } $res[$nb] = array ( 'id_bloc' => $data['id_bloc'], 'id_page' => $data['id_page'], 'ordre' => $data['ordre'], 'valide' => $datalang['valide'], 'type' => $data['type'], 'photo' => $data['photo'], 'taillephoto' => $data['taillephoto'], 'texte' => htmldecode($datalang['texte']), 'soustitre' => $datalang['soustitre'], 'nom_fichier' => $datalang['nom_fichier'], 'tags' => $datalang['tags'], 'copyright' => $datalang['copyright'], 'bouton' => $datalang['bouton'], 'lien_bouton' => $data['lien_bouton'] ); $nb++; } return $res; } else { return null; } } // Liste des blocs function get_premier_texte($page) { $query = "SELECT * FROM `bloc` WHERE id_page = ".$page." AND (`type`=1 OR `type`=2 OR `type`=3) ORDER BY ordre"; if($this->bd->isres($query)) { $result = $this->bd->q($query); $nb = 0; while( $data = mysql_fetch_assoc($result)) { $query = "SELECT * FROM `bloc_lang` WHERE id_bloc = ".$data['id_bloc']." AND id_lang = ".$this->language->getlangid(); $datalang = $this->bd->select_array($query); $res[$nb] = array ( 'id_bloc' => $data['id_bloc'], 'id_page' => $data['id_page'], 'ordre' => $data['ordre'], 'type' => $data['type'], 'photo' => $data['photo'], 'taillephoto' => $data['taillephoto'], 'texte' => htmldecode($datalang['texte']), 'soustitre' => $datalang['soustitre'], 'bouton' => $datalang['bouton'], 'lien_bouton' => $data['lien_bouton'] ); $nb++; } return $res; } else { return null; } } // Afficher un array de bloc selon le template function afficher_bloc($unbloc, $template = false) { if(!$template) $template = "page"; include("templates/".$template."/bloc".$unbloc['type'].".php"); } // Liste des pages function liste_pages($section=false, $limit=false, $debut=false,$type=false,$order=false) { if(!$section){ $query = "SELECT * FROM `page` t "; if($type){ $query .=" WHERE t.`type`='".$type."'"; } } else{ $query = "SELECT *,t.ordre as ordre FROM `page_theme` t LEFT JOIN `page` p ON p.id_page=t.id_page WHERE t.id_section = ".$section; if($type){ $query .=" AND t.`type`='".$type."'"; } } if(!$debut) $debut = 0; if($order==false){ $query .= " ORDER BY t.ordre"; } else{ $query .= " ORDER BY date_crea DESC"; } if($limit) { $query .= " LIMIT ".$debut.",".$limit; } if($this->bd->isres($query)) { $result = $this->bd->q($query); $nb = 0; while( $data = mysql_fetch_assoc($result)) { /*$query = "SELECT * FROM `page_lang` WHERE id_page = ".$data['id_page']." AND id_lang = ".$this->language->getlangid(); $datalang = $this->bd->select_array($query);*/ $datas=$this->getPage($data['id_page']); if(isset($datas['titre_'.$this->language->getlangid()]) && $datas['titre_'.$this->language->getlangid()]!="") { $datalang['titre']=$datas['titre_'.$this->language->getlangid()]; $datalang['soustitre']=$datas['soustitre_'.$this->language->getlangid()]; $datalang['permalien']=$datas['permalien_'.$this->language->getlangid()]; } else{ $datalang['titre']=$datas['titre_2']; $datalang['soustitre']=$datas['soustitre_2']; $datalang['permalien']=$datas['permalien_2']; } $res[$nb] = array ( 'id_page' => $data['id_page'], 'section' => $data['section'], 'ordre' => $data['ordre'], 'type' => $data['type'], 'titre' => $datalang['titre'], 'soustitre' => $datalang['soustitre'], 'date_crea' => $data['date_crea'], 'permalien' => $datalang['permalien'], 'couleur' => $this->sect->couleur_section($data['section']) ); $nb++; } return $res; } else { return null; } } // Liste des pages function liste_pages_perdues() { $query="SELECT * FROM `page` p WHERE p.`type`='page'"; if($this->bd->isres($query)) { $result = $this->bd->q($query); $nb = 0; while( $data = mysqli_fetch_assoc($result)) { /*$query = "SELECT * FROM `page_lang` WHERE id_page = ".$data['id_page']." AND id_lang = ".$this->language->getlangid(); $datalang = $this->bd->select_array($query);*/ $datas=$this->getPage($data['id_page']); if(isset($datas['titre_'.$this->language->getlangid()]) && $datas['titre_'.$this->language->getlangid()]!="") { $datalang['titre']=$datas['titre_'.$this->language->getlangid()]; $datalang['soustitre']=$datas['soustitre_'.$this->language->getlangid()]; $datalang['permalien']=$datas['permalien_'.$this->language->getlangid()]; } else{ $datalang['titre']=$datas['titre_2']; $datalang['soustitre']=$datas['soustitre_2']; $datalang['permalien']=$datas['permalien_2']; } $res[$nb] = array ( 'id_page' => $data['id_page'], 'section' => $data['section'], 'ordre' => $data['ordre'], 'titre' => $datalang['titre'], 'soustitre' => $datalang['soustitre'], 'permalien' => $datalang['permalien'], 'couleur' => $this->sect->couleur_section($data['section']) ); $nb++; } return $res; } else { return null; } } function bloc_page($bloc) { $query = "SELECT * FROM `bloc` WHERE id_bloc = ".$bloc; $data = $this->bd->select_array($query); return $data['id_page']; } function suppr_photo($bloc) { $query = "SELECT * FROM `bloc` WHERE id_bloc =".$bloc; $data = $this->bd->select_array($query); if($data['photo'] != null && file_exists("uploads/".$data['photo'])) { unlink("uploads/".$data['photo']); } } function getPage($id_page){ $query = "SELECT * FROM `page` WHERE id_page =".$id_page; $return=$this->bd->select_array($query); $query = "SELECT * FROM `page_lang` WHERE `id_page`=".$id_page; $lang_traductions=$this->bd->select_arrays($query); foreach($lang_traductions as $lang_traduction){ foreach($this->table_lang as $unchamp){ $return[$unchamp.'_'.$lang_traduction['id_lang']]=$lang_traduction[$unchamp]; } } return $return; } // Liste des actualités function liste_actus($section=false, $limit=false, $id_lang=0,$date_debut=null) { if(!$section){ $query="SELECT * FROM `page` WHERE type='news' "; } else{ $query="SELECT * FROM `page_theme` t LEFT JOIN `page` p ON p.id_page=t.id_page WHERE t.type='news' "; } if($date_debut!=null){ $query.=" AND date_debut>'".$date_debut."'"; } $query.=" ORDER BY `date_crea` DESC"; $tab_actus=$this->bd->select_arrays($query); $return=array(); foreach($tab_actus as $actu){ if($id_lang==0){ $return[]=$this->getPage($actu['id_page']); } else{ $id_lang=$this->valideLang($actu['id_page'],$id_lang); $query = "SELECT * FROM `page` p LEFT JOIN `page_lang` pl ON p.id_page=pl.id_page WHERE p.`id_page`=".$actu['id_page']." AND id_lang=".$id_lang; $return[]=$this->bd->select_array($query); } } return $return; } // Liste des évènements function liste_events($section=false, $limit=false, $id_lang=0,$date_debut=null) { if(!$section){ $query="SELECT * FROM `page` WHERE type='event' "; } else{ $query="SELECT * FROM `page_theme` t LEFT JOIN `page` p ON p.id_page=t.id_page WHERE t.type='event' "; } if($date_debut!=null){ $query.=" AND date_debut>'".$date_debut."'"; } $query.=" ORDER BY `date_debut` DESC"; $tab_actus=$this->bd->select_arrays($query); $return=array(); foreach($tab_actus as $actu){ if($id_lang==0){ $return[]=$this->getPage($actu['id_page']); } else{ if($id_lang!=2){ $id_lang=$this->valideLang($actu['id_page'],$id_lang); } $query = "SELECT * FROM `page` p LEFT JOIN `page_lang` pl ON p.id_page=pl.id_page WHERE p.`id_page`=".$actu['id_page']." AND id_lang=".$id_lang; $return[]=$this->bd->select_array($query); } } return $return; } function aff_actu($id_page,$id_lang){ $id_lang=$this->valideLang($id_page,$id_lang); $query="SELECT * FROM `page` p LEFT JOIN `page_lang` pl ON p.id_page=pl.id_page WHERE pl.id_lang=".$id_lang." AND p.id_page=".$id_page; $actu=$this->bd->select_array($query); // on choppe le premier texte // type 1 2 ou 3 $query="SELECT * FROM `bloc` b LEFT JOIN `bloc_lang` bl ON b.id_bloc=bl.id_bloc WHERE bl.id_lang=".$id_lang." AND (b.type=1 OR b.type=2 OR b.type=3) AND b.id_page=".$id_page." ORDER BY ordre"; $texte=$this->bd->select_array($query); $actu['texte']=htmldecode($texte['texte']); // on choppe la première image // type 2 3 4 9 ou 10 $query="SELECT * FROM `bloc` b LEFT JOIN `bloc_lang` bl ON b.id_bloc=bl.id_bloc WHERE bl.id_lang=".$id_lang." AND (b.type=2 OR b.type=3 OR b.type=4 OR b.type=9 OR b.type=10) AND b.id_page=".$id_page." ORDER BY ordre"; $image=$this->bd->select_array($query); $actu['photo']=$image['photo']; $actu['copyright']=$image['copyright']; return $actu; } // retourne la langue demandée si la page existe dans la langue sinon retourne anglais function valideLang($id_page,$id_lang){ // si anglais on laisse tomber la verif if($id_lang==2){ return $id_lang; } $query="SELECT * FROM `page_lang` WHERE id_page=".$id_page." AND id_lang=".$id_lang; $page_lang=$this->bd->select_array($query); if($page_lang==null || $page_lang['titre']==""){ return 2; } $query="SELECT * FROM `bloc` WHERE id_page='".$id_page."' "; $tab_blocs=$this->bd->select_arrays($query); foreach($tab_blocs as $unbloc){ $query="SELECT valide FROM `bloc_lang` WHERE id_bloc=".$unbloc['id_bloc']." AND id_lang=".$id_lang; $bloc_lang=$this->bd->select_array($query); if(!isset($bloc_lang['valide']) || !$bloc_lang['valide']){ return 2; } } return $id_lang; } function isValideLang($id_page,$id_lang){ // si anglais on laisse tomber la verif $query="SELECT * FROM `page_lang` WHERE id_page=".$id_page." AND id_lang=".$id_lang; $page_lang=$this->bd->select_array($query); if($page_lang==null || $page_lang['titre']==""){ return false; } $query="SELECT * FROM `bloc` WHERE id_page='".$id_page."' "; $tab_blocs=$this->bd->select_arrays($query); foreach($tab_blocs as $unbloc){ $query="SELECT valide FROM `bloc_lang` WHERE id_bloc=".$unbloc['id_bloc']." AND id_lang=".$id_lang; $bloc_lang=$this->bd->select_array($query); if(!isset($bloc_lang['valide']) || !$bloc_lang['valide']){ return false; } } return true; } function flagLang($id_page){ $tablang=$this->lang->getTabLang(); // ajout des traductions $trad_valid=array(); $html='<div class="info_flag_bloc">'; foreach($tablang as $unelang){ if($this->isValideLang($id_page,$unelang['id'])){ $html.='<div class="info_flag valide">'.$unelang['code'].'</div>'; } else{ $html.='<div class="info_flag invalide">'.$unelang['code'].'</div>'; } } $html.='</div>'; return $html; } function list_actu_theme($id_theme){ $query="SELECT * FROM `page_theme` t LEFT JOIN `page` p ON p.id_page=t.id_page WHERE id_section=".$id_theme." AND (p.`type`='event' || p.`type`='news') ORDER BY p.date_crea DESC"; return $this->bd->select_arrays($query); } function list_actu($type="news",$numpage=null){ $query="SELECT * FROM `page` p WHERE p.`type`='".$type."' ORDER BY p.date_crea DESC"; if($numpage!=null){ $query.=" LIMIT ".(($numpage-1)*30).",".($numpage*30); } $list_top=$this->bd->select_arrays($query); $i=0; $type="top"; if($list_top!=null){ foreach($list_top as $uneactu){ $actu=$this->aff_actu($uneactu['id_page'],$this->language->id()); include("templates/accueil/actu.php"); $i++; if($i>3){ $type="bottom"; } } } } function list_calendar($numpage=null){ $query="SELECT * FROM `page` p WHERE p.`calendrier`=1 ORDER BY p.date_crea DESC"; if($numpage!=null){ $query.=" LIMIT ".(($numpage-1)*30).",".($numpage*30); } $list_top=$this->bd->select_arrays($query); $i=0; $type="top"; if($list_top!=null){ foreach($list_top as $uneactu){ $actu=$this->aff_actu($uneactu['id_page'],$this->language->id()); include("templates/accueil/actu.php"); $i++; if($i>3){ $type="bottom"; } } } } //4 types news,event,calendar ou theme // si thème id du theme function list_rss($url_site,$type="news",$theme=0){ if($type=="news"){ $query="SELECT * FROM `page` p WHERE p.`type`='news' ORDER BY p.date_crea DESC"; } elseif($type=="all"){ $query="SELECT * FROM `page` p WHERE p.id_page IN ( SELECT `id_page` FROM `page_theme` t) OR p.`type`!='page' ORDER BY p.date_crea DESC"; } elseif($type=="event"){ $query="SELECT * FROM `page` p WHERE p.`type`='event' ORDER BY p.date_crea DESC"; } elseif($type=="calendar"){ $query="SELECT * FROM `page` p WHERE p.`calendrier`=1 ORDER BY p.date_crea DESC"; } else{ $query="SELECT * FROM `page_theme` t LEFT JOIN `page` p ON p.id_page=t.id_page WHERE id_section=".$theme." AND (p.`type`='event' || p.`type`='news') ORDER BY p.date_crea DESC"; } $list_top=$this->bd->select_arrays($query); $result=""; if($list_top!=null){ foreach($list_top as $uneactu){ $actu=$this->aff_actu($uneactu['id_page'],$this->language->id()); $result.='<item> <title>'.htmldecode($actu['titre']).'</title> <link>'.$url_site.$this->language->getlang().'/page/'.$actu['id_page'].'-'.str_replace(array('«','»'),array('',''),$actu['permalien']).'.html</link>'; if(isset($actu['photo']) && $actu['photo']!=""){ //$result.='<description><![CDATA[<img src="'.$url_site.'uploads/'.$actu['photo'].'" />'.$actu['texte'].'"]]></description>'; $result.='<description><![CDATA[<img src="'.$url_site.thumb($actu['photo'], 50).'" />'. texte_resume($actu['texte'], 350, false, '...') .']]></description>'; } else{ $result.='<description><![CDATA['.texte_resume($actu['texte'], 350, false, '...').']]></description> '; } $result.='<pubDate>'.date("D, d M Y H:i:s", strtotime($actu['date_crea'])).'</pubDate> </item>'; } } return $result; } } ?>