/class.xmodinfotree.inc
PHP | 3241 lines | 2746 code | 202 blank | 293 comment | 486 complexity | b4262d8cd9d943f98eb8bdfea8d16a4f MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
- <?php
- /****c* XModule/XModInfoTree
- * NAME
- * XModInfoTree -- gestion d'un ensemble de rubriques structurees
- * DESCRIPTION
- * Module central de gestion d'un site internet, integrant la
- * gestion de rubriques structurees, le rattachement d'informations
- * a ces rubriques, ainsi que la creation de requetes.
- * SYNOPSIS
- ****/
- /// Module de gestion d'un ensemble de rbriques et de pages web
- class XModInfoTree extends XModule {
- public $table = 'T001';
- public $_rbrowse=NULL;
- public $cattemplate=NULL;
- public $preview='/index.php?_cachepolicy=forcecache';
- public $linkin='';
- public $urlext='';
- /// construction de la classe gestion de rubriques
- function __construct($ar=NULL) {
- parent::__construct($ar);
- XLabels::loadLabels('xmodinfotree');
- $this->_categories=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->table);
- $this->tname='IT'.$this->table;
- if(empty($this->_templates))
- $this->_templates=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS=TEMPLATES');
- XAlias::register($this);
- }
- /// initialisation des options
- public function initOptions() {
- parent::initOptions();
- $this->_options->setOpt(XLabels::getSysLabel('general','table'), 'table', 'table',array('validate'=>true));
- $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','cattemplate'), 'cattemplate', 'template',
- array('moid'=>$this->_moid,
- 'cond'=>"(gtype like 'categorie')"));
- $this->_options->setOpt(XLabels::getSysLabel('general','preview','text'), 'preview', 'text',NULL,'index.php?');
- $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','linkinfield','text'), 'linkin', 'field',
- array('compulsory'=>false),'linkin');
- $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','urlextfield','text'), 'urlext', 'field',
- array('compulsory'=>false),'urlext');
- $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','odt_texttpl','text'), 'odttpltxt', 'template',
- array('compulsory'=>false),NULL,'ODT');
- $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','odt_texttitlefield','text'), 'odttxttitlefield', 'text', NULL, 'title','ODT');
- $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','odt_textfield','text'), 'odttxtfield', 'text', NULL, 'txt1','ODT');
- $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','odt_imagetpl','text'), 'odttplimg', 'template',
- array('compulsory'=>false),NULL,'ODT');
- $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','odt_imagefield','text'), 'odtimgfield', 'text', NULL,'img1','ODT');
- $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','pdf_enabled','text'), 'pdf_enabled', 'boolean', NULL,false,'PDF');
- $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','pdf_css','text'), 'pdf_css', 'text', NULL,'css/pdf.css','PDF');
- $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','pdf_css_content','text'), 'pdf_css_content', 'text', NULL,'css/page-content.css','PDF');
- $tlabel=XLabels::getSysLabel('xmodule.tracking');
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','trackchanges'),'trackchanges','boolean',NULL,NULL,$tlabel);
- }
- /// securite des fonctions accessibles par le web
- function secGroups($function, $group=NULL) {
- $g=array('home'=>array('list','ro','rw','rwv','admin'),
- 'procHome'=>array('rw','rwv','admin'),
- 'rss'=>array('ro','rw','rwv','admin'),
- 'viewpage'=>array('ro','rw','rwv','admin'),
- 'viewsection'=>array('ro','rw','rwv','admin'),
- 'procQuery'=>array('ro','rw','rwv','admin'),
- 'query'=>array('ro','rw','rwv','admin'),
- 'browse'=>array('ro','rw','rwv','admin'),
- 'input'=>array('rw','rwv','admin'),
- 'procInput'=>array('rw','rwv','admin'),
- 'addSection'=>array('rw','rwv','admin'),
- 'newsection'=>array('rw','rwv','admin'),
- 'insertsection'=>array('rw','rwv','admin'),
- 'editsection'=>array('rw','rwv','admin'),
- 'savesection'=>array('rw','rwv','admin'),
- 'newfunction'=>array('rw','rwv','admin'),
- 'insertfunction'=>array('rw','rwv','admin'),
- 'editfunction'=>array('rw','rwv','admin'),
- 'savefunction'=>array('rw','rwv','admin'),
- 'insertquery'=>array('rw','rwv','admin'),
- 'editquery'=>array('rw','rwv','admin'),
- 'savequery'=>array('rw','rwv','admin'),
- 'delSection'=>array('rw','rwv','admin'),
- 'editpage'=>array('rw','rwv','admin'),
- 'delCat'=>array('rw','rwv','admin'),
- 'dupCat'=>array('rw','rwv','admin'),
- 'procEdit'=>array('rw','rwv','admin'),
- 'procEditAllLang'=>array('rw','rwv','admin'),
- 'editCat'=>array('rw','rwv','admin'),
- 'moveCat'=>array('rw','rwv','admin'),
- 'moveSection'=>array('rw','rwv','admin'),
- 'moveSelectedCat'=>array('rw','rwv','admin'),
- 'moveToTrash'=>array('rw','rwv','admin'),
- 'displayImage'=>array('rw','rwv','admin'),
- 'displaysection'=>array('ro','rw','rwv','admin'),
- 'dupsection'=>array('rw','rwv','admin'),
- 'publishCat'=>array('rwv','admin'),
- 'subscribe'=>array('ro','rw','rwv','admin'),
- 'preSubscribe'=>array('ro','rw','rwv','admin'),
- 'export'=>array('ro','rw','rwv','admin'),
- 'exportPdf'=>array('ro','rw','rwv','admin'),
- 'publish'=>array('rwv','admin'),
- 'preImportFromODT'=>array('rw','rwv','admin'),
- 'importFromODT'=>array('rw','rwv','admin'),
- 'adminNewSection'=>array('rw','rwv','admin'),
- 'adminProcNewSection'=>array('rw','rwv','admin'));
- if(isset($g[$function])) {
- if(!empty($group)) return in_array($group, $g[$function]);
- else return $g[$function];
- }
- return parent::secGroups($function,$group);
- }
- /// Action principale du menu
- public function getMainAction(){
- return $GLOBALS['TZR_SESSION_MANAGER']::complete_self().'moid='.$this->_moid.'&function=home&tplentry=mit&template=xmodinfotree/index.html';
- }
- /// list des tables dont on souhaite tracer les modifications
- function tablesToTrack() {
- $ret=array();
- if($this->trackchanges) {
- $tabs=selectQueryGetAll('SELECT DISTINCT tab FROM TEMPLATES WHERE modid=\''.$this->_moid.'\'');
- $ret=array($this->table);
- foreach($tabs as $tab) {
- $ret[]=$tab['tab'];
- }
- }
- return $ret;
- }
- /// Prepare l'ajout d'une nouvelle section function
- public function newfunction($ar=NULL){
- $p=new XParam($ar,NULL);
- $tplentry=$p->get('tplentry');
- $oidit=$p->get('oidit');
- $oidtpl=$p->get('oidtpl');
- $lang=XShell::getLangData();
- $tabletpl=Kernel::getTable($oidtpl);
- $rs=selectQuery('select * from '.$tabletpl.' where KOID="'.$oidtpl.'" AND LANG="'.$lang.'"');
- if($rs && $o1=$rs->fetch()) {
- $tabledst=$o1['tab'];
- // Infos d'affichage du template
- $template = $this->_disp2Template($oidtpl);
- $s['_tp'] = $template;
- $s['section']=$p->get('section');
- $s['position']=$p->get('position');
- $s['oidit']=$p->get('oidit');
- $s['oidtpl']=$p->get('oidtpl');
- $moid=$s['section']['moid'];
- $f=$s['section']['function'];
- $pf='UIParam_'.$f;
- $ef='UIEdit_'.$f;
- $m=XModule::objectFactory($moid);
- if(method_exists($m,$ef)) $ret=$m->$ef();
- else{
- $desc=$m->$pf();
- $ret=array('fields_object'=>array());
- foreach($desc as $fn=>&$f){
- $o=$desc[$fn]->edit();
- $ret['o'.$fn]=$ret['fields_object'][]=$o;
- }
- }
- $this->editTemplateOptions($ret, $oidtpl, $s['oidit']);
- $groups=array();
- foreach($ret as $n=>&$v) {
- if(!is_object($v) || !is_object($v->fielddef)) continue;
- if(empty($v->fielddef->fgroup)) $v->fielddef->fgroup='General';
- $groups[$v->fielddef->fgroup][]=&$v;
- }
- ksort($groups);
- if(count($groups)>1) $ret['_groups']=$groups;
- $s['olines'][]=$ret;
- XShell::toScreen1($tplentry,$s);
- }
- }
- /// Duplication d'un module, méthode interne
- /// Retour : duplicatetables => liste des tables dupliquées par le module (cle : ancienne table, valeur : nouvelle table))
- /// Retour : duplicatemods => liste des modules dupliqués par le module (cle : ancien moid, valeur : nouveau moid))
- function _duplicateModule($newmoid,&$params,$prefix) {
- if(!is_array($params['tables'])) $params['tables']=array();
- if(!$params['noduplicatetable']){
- // duplication de la table des rubriques
- if(empty($params['tables'][$this->table])){
- $ar['newtable']=XDSTable::newTableNumber();
- $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->table);
- if(($pos=strpos($xset->getLabel(),':'))!==false) $ar['mtxt']=$prefix.substr($xset->getLabel(),$pos);
- else $ar['mtxt']=$prefix.':'.$xset->getLabel();
- $ar['data']=false;
- $ar['_options']=array('local'=>1);
- $xset2=$xset->procDuplicateDataSource($ar);
- // correction du lien vers la rubrique mere
- $xset21=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ar['newtable']);
- $xset21->procEditField(array('field'=>'linkup','table'=>$newtable,'_todo'=>'save','target'=>$ar['newtable'],
- 'published'=>'off','queryable'=>'on','browsable'=>'on','compulsory'=>'off','translatable'=>'off',
- 'options'=>array('comment'=>array('FR'=>'Rubrique mere'))));
- $params['table']=$ar['newtable'];
- }else{
- $params['table']=$params['tables'][$this->table];
- }
- // creation de la table des liens
- XModInfoTreeWd::createLinkStructure($params['table']);
- // duplication des mises en page/gabarits
- $rs=selectQuery('SELECT KOID FROM TEMPLATES WHERE modid =\''.$this->_moid.'\'');
- $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS=TEMPLATES');
- while($rs && $ors=$rs->fetch()) {
- $ardup=array('_options'=>array('local'=>1));
- $ardup['oid']=$ors['KOID'];
- $nkoid=$xset->duplicate($ardup);
- preparedUpdateQuery('UPDATE TEMPLATES set modid=? where KOID=?',array($newmoid,$nkoid));
- }
- }
- unset($params['noduplicatetable']);
- return array('duplicatetables'=>array($this->table=>$params['table']),'duplicatemods'=>array());
- }
- /// Enregistre une section de type fonction
- public function insertfunction($ar=NULL){
- $p=new XParam($ar,NULL);
- $oidit=$p->get('oidit');
- $oidtpl=$p->get('oidtpl');
- $position=$p->get('position')+1;
- $section=$p->get('section');
- $moid=$section['moid'];
- $f=$section['function'];
- $pf='UIParam_'.$f;
- $ef='UIProcEdit_'.$f;
- $m=XModule::objectFactory($moid);
- if(method_exists($m,$ef)){
- $ret=$m->$ef($ar);
- if($ret) $section=array_merge($section,$ret);
- }else{
- $desc=$m->$pf();
- $options=array('_track'=>false);
- foreach($desc as $fn=>&$f){
- $value=$p->get($fn);
- $value_hid=$p->get($fn.'_HID');
- $options[$fn.'_HID']=$value_hid;
- $o=$desc[$fn]->post_edit($value,$options);
- if($f->multivalued && $f->get_fgender()=='Oid' && is_array($o->raw)){
- $o->raw=implode('||',$o->raw);
- }
- $section[$fn]=$o->raw;
- }
- }
- $val=addslashes(serialize($section));
- $nitoid=self::newItOid();
- updateQuery("UPDATE ".$this->tname." SET ORDER1=ORDER1+1 where KOIDSRC='$oidit' ".
- " AND ORDER1 >= $position");
- updateQuery('INSERT INTO '.$this->tname.' SET KOIDSRC="'.$oidit.'",KOIDDST="",KOIDTPL="'.$oidtpl.'",ORDER1="'.$position.'",'.
- 'QUERY="'.$val.'",ITOID="'.$nitoid.'"');
- return $nitoid;
- }
- /// Prépare l'edition d'une section fonction
- function editfunction($ar=NULL){
- $p=new XParam($ar,NULL);
- $tplentry=$p->get('tplentry');
- $oidit=$p->get('oidit');
- $oidsection=$p->get('oidsection');
- list($oidit,$oiddest,$oidtemplate)=$this->_getOids($oidsection);
- $rs=selectQuery('select * from '.$this->tname.' where ITOID="'.$oidsection.'"');
- if(!$ors=$rs->fetch()) return array();
- $params=unserialize($ors['QUERY']);
- $s=array();
- $template = $this->_disp2Template($oidtemplate);
- $s['_tp'] = $template;
- $s['oidit']=$oidit;
- $s['oidsection']=$oidsection;
- $s['section']=$params;
- $moid=$params['moid'];
- $f=$params['function'];
- $pf='UIParam_'.$f;
- $ef='UIEdit_'.$f;
- $m=XModule::objectFactory($moid);
- if(method_exists($m,$ef)) $ret=$m->$ef($params);
- else{
- $desc=$m->$pf();
- $ret=array('fields_object'=>array());
- foreach($desc as $fn=>&$f){
- $o=$f->edit($params[$fn]);
- $ret['o'.$fn]=$ret['fields_object'][]=$o;
- }
- }
- $this->editTemplateOptions($ret, $oidtemplate, $s['oidsection'], $params);
- $groups=array();
- foreach($ret as $n=>&$v) {
- if(!is_object($v) || !is_object($v->fielddef)) continue;
- if(empty($v->fielddef->fgroup)) $v->fielddef->fgroup='General';
- $groups[$v->fielddef->fgroup][]=&$v;
- }
- ksort($groups);
- if(count($groups)>1) $ret['_groups']=$groups;
- $s['olines'][]=$ret;
- return XShell::toScreen1($tplentry,$s);
- }
- /**
- * Ajoute les options du template à l'interface d'édition de la section fonction
- * @param &$ret array Tableau de valeurs disponible dans le template
- * @param $oid_template string KOID du template
- * @param $id_section string Identifiant unique de la section
- * @param $params array Tableau de valeurs des options du template
- */
- public function editTemplateOptions(&$ret, $oid_template, $id_section, $params = null) {
- // Récupère les options liées au TEMPLATE de mise en page
- $options_values = (object) null;
- $xoptions = $this->getTemplateOptions($oid_template, $id_section, $options_values);
- if (!is_null($xoptions)) {
- $template_options = $xoptions->getValues($options_values);
- foreach ($template_options as $option_id => $option) {
- $xoptions->set($options_values, $option_id, $params['_tploptions'][$option_id]);
- }
- $user_module_access_levels = current(XUser::getObjectAccess($this->_moid));
- $level = in_array('admin', $user_module_access_levels) ? 'admin' : 'none';
- $ret['_tploptions'] = $xoptions->getDialog($options_values, $params['_tploptions'], '_tploptions', $level);
- }
- }
- /**
- * Envoi un tableau des options disponibles pour le template
- * @param $oid_template string KOID du template
- * @param $id_section string Identifiant unique de la section
- * @param $options_values array Tableau de valeurs des options du template
- * @return XOptions Objet contenant les options du template / null si inexistant
- */
- public function getTemplateOptions($oid_template, $id_section, &$options_values) {
- $template = $this->_templates->rDisplay($oid_template);
- if (empty($template['oopts']->raw)) {
- return null;
- }
- $xopts = new XOptions($id_section);
- $xopts->setOptsFromXML($options_values, $template['oopts']->raw);
- return $xopts;
- }
- /// Enregistre une section de type fonction
- public function savefunction($ar=NULL){
- $p=new XParam($ar,NULL);
- $oidit=$p->get('oidit');
- $oidtpl=$p->get('oidtpl');
- $oidsection=$p->get('oidsection');
- $section=$p->get('section');
- $moid=$section['moid'];
- $f=$section['function'];
- $pf='UIParam_'.$f;
- $ef='UIProcEdit_'.$f;
- $m=XModule::objectFactory($moid);
- if(method_exists($m,$ef)){
- $ret=$m->$ef($ar);
- if($ret) $section=array_merge($section,$ret);
- }else{
- $desc=$m->$pf();
- $options=array('_track'=>false);
- foreach($desc as $fn=>&$f){
- $value=$p->get($fn);
- $value_hid=$p->get($fn.'_HID');
- $options[$fn.'_HID']=$value_hid;
- $o=$desc[$fn]->post_edit($value,$options);
- if($f->multivalued && $f->get_fgender()=='Oid' && is_array($o->raw)){
- $o->raw=implode('||',$o->raw);
- }
- $section[$fn]=$o->raw;
- }
- }
- $section['_tploptions'] = $p->get('_tploptions');
- $val=addslashes(serialize($section));
- updateQuery('UPDATE '.$this->tname.' SET KOIDSRC="'.$oidit.'",KOIDDST="",QUERY="'.$val.'" where ITOID="'.$oidsection.'"');
- return $oidsection;
- }
- /// Prepare l'ajout d'une section dans l'administration a partir d'une page donnee
- function adminNewSection($ar=NULL){
- $p=new XParam($ar,NULL);
- $tplentry=$p->get('tplentry');
- $newrub=$p->get('newrub');
- $fct=$p->get('fct');
- $r=array();
- if($newrub) $this->_categories->input(array('tplentry'=>$tplentry.'rub'));
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS=CS8SEC');
- $xds->input(array('tplentry'=>$tplentry.'sec'));
- $this->home(array('tplentry'=>$tplentry.'tree','maxlevel'=>1,'norubric'=>true));
- $fct=XModUser2::_normalizeBookmark($fct);
- $r['fct']=$fct;
- parse_str($fct,$infos);
- $f=$infos['_function']?$infos['_function']:$infos['function'];
- if($infos['moid'] && ($f=='procQuery' || $f=='browse')){
- $mod=XModule::objectFactory($infos['moid']);
- if($mod->persistentquery){
- $r['persistent']=1;
- }
- }
- return XShell::toScreen1($tplentry,$r);
- }
- /// Ajoute une section dans l'administration
- function adminProcNewSection($ar=NULL){
- $p=new XParam($ar,NULL);
- $linkup=$p->get('linkup');
- $createrub=$p->get('createrub');
- if($createrub){
- $rub=$this->procInput($ar);
- $linkup=$rub['oid'];
- }
- $ar2=$p->get('sec');
- $ar2['fct']=XModUser2::_normalizeBookmark($ar2['fct']);
- $ar2['oidit']=$linkup;
- $ar2['oidtpl']='TEMPLATES:ADMIN-'.$this->_moid;
- if(!empty($ar2['persistent'])) $ar2['fct'].='&_persistent=1';
- $this->insertsection($ar2);
- }
- /// Liste des actions générale du module
- protected function _actionlist(&$my) {
- parent::_actionlist($my);
- $myoid=@$_REQUEST['oidit'];
- $moid=$this->_moid;
- // Arbo
- $o1=new XModuleAction($this,'home',XLabels::getSysLabel('xmodinfotree','see_categories'),
- '&moid='.$moid.'&_function=home&template=xmodinfotree/index.html&tplentry=mit','display');
- $o1->setToolbar('general','browse');
- $my['home']=$o1;
- // Poubelle
- $o1=new XModuleAction($this,'trash',XLabels::getSysLabel('xmodinfotree','see_trash'),
- '&moid='.$moid.'&_function=home&template=xmodinfotree/index.html&tplentry=mit&aliastop=trash','display');
- $o1->setToolbar('general','trash');
- $my['trash']=$o1;
- // Recherche
- $o1=new XModuleAction($this,'home',XLabels::getSysLabel('general','query','text'),
- '&moid='.$moid.'&_function=query&template=xmodinfotree/query.html&tplentry=br','display');
- $o1->setToolbar('general','query');
- $my['query']=$o1;
- // Pile
- if($this->interactive) {
- $o1=new XModuleAction($this,'in',$this->modulename,
- '&moid='.$this->_moid.'&_function=home&template=xmodinfotree/index.html&tplentry=mit');
- $my['stack'][]=$o1;
- if (!empty($myoid)) {
- $nav=$this->getPath($myoid);
- foreach($nav['oiddown'] as $i=>$oid) {
- $o1=new XModuleAction($this,'i'.$i,$nav['labeldown'][$i],
- '&moid='.$this->_moid.'&_function=editpage&template=xmodinfotree/viewpage.html&tplentry=it&oidit='.$oid);
- $my['stack'][]=$o1;
- }
- }
- if(XShell::_function()=='editCat'){
- $br=&XShell::from_screen('editcat');
- $br=&$this->_categories->rDisplayText($br['oid'],array());
- $o1=new XModuleAction($this,'view',$br['link'],'&moid='.$this->_moid.'&_function=editpage&template=xmodinfotree/viewpage.html&tplentry=it&oidit='.$br['oid']);
- $my['stack'][]=$o1;
- }
- $modsubmoid=XModule::getMoid(XMODSUB_TOID);
- if(!empty($modsubmoid)){
- $o1=new XModuleAction($this,'subscribe',XLabels::getSysLabel('xmodsub','subadd','text'),
- '&moid='.$this->_moid.'&oid='.$myoid.'&_function=preSubscribe&tplentry=br&template=xmodinfotree/sub.html',
- 'more');
- $o1->menuable=true;
- $my['subscribe']=$o1;
- }
- if($this->odttpltxt && $this->odttplimg && $this->secure(NULL,'importFromODT')){
- $o1=new XModuleAction($this,'odtimport',XLabels::getSysLabel('xmodinfotree','odt_import','text'),
- '&moid='.$this->_moid.'&function=preImportFromODT&template=xmodinfotree/preImportFromODT.html&oidit='.$oid,'edit');
- $o1->menuable=true;
- $my['odtimport']=$o1;
- }
- }
- }
- /// Actions spécifique à "home"
- function al_home(&$my){
- $uniqid='v'.XShell::uniqid();
- $o1=new XModuleAction($this,'foldall',XLabels::getSysLabel('xmodinfotree','fold_all','text'),
- '&function=home&template=xmodinfotree/index.html&moid='.$this->_moid.'&do=foldall&tplentry=mit','display');
- $o1->menuable=true;
- $my['foldall']=$o1;
- $o1=new XModuleAction($this,'unfoldall',XLabels::getSysLabel('xmodinfotree','unfold_all','text'),
- '&function=home&template=xmodinfotree/index.html&moid='.$this->_moid.'&do=unfoldall&tplentry=mit','display');
- $o1->menuable=true;
- $my['unfoldall']=$o1;
- if($this->secure(NULL,'input')){
- $o1=new XModuleAction($this,'input',XLabels::getSysLabel('xmodinfotree','add_subtree','text'),
- '&moid='.$this->_moid.'&function=input&template=xmodinfotree/new.html&linkup=','edit');
- $o1->setToolbar('general','new');
- $my['input']=$o1;
- }
- // Publier/dépulier
- if($this->_categories->fieldExists('PUBLISH') && $this->secure(NULL,':rwv')){
- $o1=new XModuleAction($this,'publish',XLabels::getSysLabel('general','approve','text'),
- 'javascript:'.$uniqid.'.publishSelected(true);','edit');
- $o1->menuable=true;
- $my['publish']=$o1;
- $o1=new XModuleAction($this,'publish',XLabels::getSysLabel('general','unapprove','text'),
- 'javascript:'.$uniqid.'.publishSelected(false);','edit');
- $o1->menuable=true;
- $my['unpublish']=$o1;
- }
- // Supprimer
- if($this->secure(NULL,'moveToTrash')){
- $o1=new XModuleAction($this,'del',XLabels::getSysLabel('general','delete','text'),
- 'javascript:'.$uniqid.'.deleteselected();','edit');
- $o1->setToolbar('general','delete');
- $my['del']=$o1;
- }
- // Deplacer
- if($this->secure(NULL,'moveCat')){
- $o1=new XModuleAction($this,'move',XLabels::getSysLabel('general','move','text'),
- 'javascript:'.$uniqid.'.moveselected();','edit');
- $o1->menuable=true;
- $my['move']=$o1;
- }
- // Dupliquer
- if($this->secure(NULL,'dupCat')){
- $o1=new XModuleAction($this,'dup',XLabels::getSysLabel('general','clone','text'),
- 'javascript:'.$uniqid.'.duplicateselected();','edit');
- $o1->menuable=true;
- $my['dup']=$o1;
- }
- // Exporter
- if($this->secure(NULL,'export')){
- $o1=new XModuleAction($this,'export',XLabels::getSysLabel('general','export','text'),
- 'javascript:'.$uniqid.'.exportselected();','edit');
- $o1->menuable=true;
- $my['exp']=$o1;
- }
- }
- /// Actions spécifique à "viewpage"
- function al_viewpage(&$my){
- $uniqid='v'.XShell::uniqid();
- $oid=$_REQUEST['oidit'];
- // Navigation
- $o1=new XModuleAction($this,'nav',XLabels::getSysLabel('general','navigation','text'),'#');
- $o1->menuable=true;
- $o1->newgroup='nav';
- $my['nav']=$o1;
- $o1=new XModuleAction($this,'navall',XLabels::getSysLabel('xmodinfotree','treebrowser','text'),
- 'javascript:TZR.openPopup("'.$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'function=home&template=xmodinfotree/popaction.html'.
- '&_skip=1&moid='.$this->_moid.'&_raw=1&maxlevel=1&oid='.$oid.'&tplentry=mit&do=add&'.
- '&norubric=1&action=go&moduleid='.XShell::uniqid().'");','nav');
- $o1->menuable=true;
- $my['navall']=$o1;
- $it=&XShell::from_screen('it');
- $nav=&$it['nav'];
- if($nav['up']){
- $o1=new XModuleAction($this,'navup',$nav['up']['otitle']->html,'javascript:'.$uniqid.'.gopage("'.$nav['up']['oid'].'");','nav');
- $o1->menuable=true;
- $my['navup']=$o1;
- }
- if(!empty($nav['prev'])){
- $o1=new XModuleAction($this,'navprev',$nav['prev']['otitle']->html,'javascript:'.$uniqid.'.gopage("'.$nav['prev']['oid'].'");',
- 'nav');
- $o1->menuable=true;
- $my['navprev']=$o1;
- }
- if(!empty($nav['next'])){
- $o1=new XModuleAction($this,'navnext',$nav['next']['otitle']->html,'javascript:'.$uniqid.'.gopage("'.$nav['next']['oid'].'");',
- 'nav');
- $o1->menuable=true;
- $my['navnext']=$o1;
- }
- $rubs=&XShell::from_screen('ssrubs');
- foreach($rubs['lines_oid'] as $i=>$roid){
- $o1=new XModuleAction($this,'navssrub'.$i,$rubs['lines_otitle'][$i]->html,'javascript:'.$uniqid.'.gopage("'.$roid.'");','nav');
- $o1->menuable=true;
- $my['navssrub'.$i]=$o1;
- }
- // Prévisualisation
- if($this->preview){
- $o1=new XModuleAction($this,'view',XLabels::getSysLabel('general','view','text'),
- $this->preview.'&_lang='.XShell::getLangData().'&oidit='.$oid.'&nocache=1','edit');
- $o1->target='_blank';
- $o1->setToolbar('general','view');
- $my['view']=$o1;
- }
- // Publier/dépulier
- if($this->secure($oid,':rwv')){
- $it=XShell::from_screen('it');
- $publish=false;
- foreach($it['olines'] as $i=>$s){
- if(isset($s['oPUBLISH'])){
- $publish=true;
- break;
- }
- }
- if($publish){
- $o1=new XModuleAction($this,'publish',XLabels::getSysLabel('general','approve','text'),
- 'javascript:'.$uniqid.'.publishSelected(true);','edit');
- $o1->menuable=true;
- $my['publish']=$o1;
- $o1=new XModuleAction($this,'publish',XLabels::getSysLabel('general','unapprove','text'),
- 'javascript:'.$uniqid.'.publishSelected(false);','edit');
- $o1->menuable=true;
- $my['unpublish']=$o1;
- }
- }
- // Supprimer
- if($this->secure($oid,'delSection')){
- $o1=new XModuleAction($this,'del',XLabels::getSysLabel('general','delete','text'),
- 'javascript:'.$uniqid.'.deleteselected();','edit');
- $o1->menuable=true;
- $my['del']=$o1;
- }
- // Deplacer
- if($this->secure($oid,'moveSection')){
- $o1=new XModuleAction($this,'move',XLabels::getSysLabel('general','move','text'),
- 'javascript:'.$uniqid.'.moveselected(\'to\');','edit');
- $o1->menuable=true;
- $my['move']=$o1;
- $o1=new XModuleAction($this,'moveup',XLabels::getSysLabel('general','up','text'),
- 'javascript:'.$uniqid.'.moveselected(\'up\');','edit');
- $o1->menuable=true;
- $my['moveup']=$o1;
- $o1=new XModuleAction($this,'movedown',XLabels::getSysLabel('general','down','text'),
- 'javascript:'.$uniqid.'.moveselected(\'down\');','edit');
- $o1->menuable=true;
- $my['movedown']=$o1;
- }
- // Export PDF
- if($this->pdf_enabled && $this->secure($oid,'exportPdf')) {
- $o1=new XModuleAction($this,'exportPdf',XLabels::getSysLabel('xmodinfotree','export_pdf','text'),'&moid='.$this->_moid.'&_function=exportPdf&oidit='.$oid,'edit');
- $o1->target='_blank';
- $o1->ico='<img src="/tzr/templates/ico/mime/pdf.gif">';
- $o1->setToolbar();
- $my['exportPdf']=$o1;
- }
- }
- /// Actions spécifique à "editpage"
- function al_editpage(&$my){
- $this->al_viewpage($my);
- }
- /// Refait la numérotation de l'ordre des sections d'une catégorie
- protected function _reorderSections($oid) {
- $rs=selectQuery('select ITOID,ORDER1 from '.$this->tname.' where KOIDSRC="'.$oid.'" order by ORDER1,ITOID');
- $i=0;
- while($ors=$rs->fetch()) {
- $i++;
- if($i==$ors['ORDER1']) continue;
- updateQuery('UPDATE '.$this->tname.' set ORDER1='.$i.' where ITOID="'.$ors['ITOID'].'"');
- }
- $rs->closeCursor();
- }
- /// Refait la numérotation de l'ordre des catégories d'un noeud
- protected function _reorderCat($oid) {
- $lang=TZR_DEFAULT_LANG;
- if(!$oid) $oid='';
- $i=0;
- $rs=selectQuery('select distinct KOID,corder from '.$this->table.' where linkup="'.$oid.'" and LANG="'.$lang.'" order by corder');
- while($ors=$rs->fetch()) {
- $i++;
- if($i==$ors['corder']) continue;
- updateQuery('UPDATE '.$this->table.' set corder='.$i.',UPD=UPD where KOID="'.$ors['KOID'].'"');
- }
- $rs->closeCursor();
- }
- /// Change le parent d'une ou plusieurs catégories
- public function moveSelectedCat($ar) {
- $p=new XParam($ar, array());
- $dest=$p->get('_dest');
- if(!empty($dest) && !Kernel::isAKoid($dest)) {
- $dest=$this->getOidFromAlias($dest);
- }
- $sel=$p->get('_selected');
- $i=-count($sel);
- foreach($sel as $oid => $bid) {
- if($oid!=$dest) {
- updateQuery('UPDATE '.$this->table.' set linkup="'.$dest.'",corder='.$i.' where KOID="'.$oid.'"');
- }
- $i++;
- }
- $this->_reorderCat($dest);
- }
- /// teste si une rubrique est dans la poubelle
- protected function oidInTrash($oid) {
- $oidtrash = $this->getTrashOid();
- if(empty($oidtrash)) return false;
- $pathoids=$this->_getPathOids($oid);
- return in_array($oidtrash, $pathoids);
- }
- /// deplacement de la selection vers la poubelle, rubrique d'alias trash
- public function moveToTrash($ar) {
- $p=new XParam($ar, array());
- $oidtrash = $this->getTrashOid(true);
- $sel=$p->get('_selected');
- // si les elements sont deja dans la poubelle on les supprime
- $delnb=0;
- foreach($sel as $oid => $bid) {
- if($this->oidInTrash($oid)) {
- $ar1=array();
- $ar1['oid']=$oid;
- $ar1['_selected']=array();
- $ar1['_selectedok']='nok';
- $this->delCat($ar1);
- $delnb++;
- }
- }
- // si on a supprime tous les elements selectionnes pas la peine de
- // rentrer dans un traitement de la poubelle
- if($delnb==count($sel)) return;
- // creation d'une rubrique liee a la date de suppression
- $ar1=array('title'=>'-- '.date('c'),
- 'linkup'=>$oidtrash,
- 'corder'=>'0');
- $r1=&$this->procInput($ar1);
- $dest = $r1['oid'];
- foreach($sel as $oid => $bid) {
- if($oid!=$dest) {
- updateQuery('UPDATE '.$this->table." set linkup='$dest' where KOID='$oid'");
- }
- }
- // on parcourt la poubelle et on supprime dans la poubelle toutes les rubriques validees
- // ainsi que tous les alias
- $oids=$this->getSubObjects($oidtrash);
- foreach($oids as $oids1) {
- if($this->_categories->fieldExists('PUBLISH')) {
- updateQuery('UPDATE '.$this->table." set PUBLISH='2' WHERE KOID='$oids1'");
- }
- updateQuery('UPDATE '.$this->table." set alias='' WHERE KOID='$oids1'");
- }
- // on traite les liens internes. Ceux qui sont dans la poubelle sont supprimes
- // ceux qui vont vers la poubelle sont supprimes
- $rs=selectQuery('SELECT KOID,LANG,'.$this->linkin.' FROM '.$this->table.' WHERE '.$this->linkin.'!=\'\'');
- while($rs && ($ors=$rs->fetch())) {
- if($this->oidInTrash($ors['KOID'])) {
- updateQuery('UPDATE '.$this->table.' SET '.$this->linkin."='',UPD=UPD WHERE KOID='".$ors['KOID']."'");
- } elseif($this->oidInTrash($ors[$this->linkin])) {
- updateQuery('UPDATE '.$this->table.' SET '.$this->linkin."='',UPD=UPD WHERE KOID='".$ors['KOID']."' AND ".$this->linkin."='".$ors[$this->linkin]."'");
- }
- }
- }
- /// Change l'ordre et/ou le parent d'une catégorie
- public function moveCat($ar) {
- $p=new XParam($ar, array());
- $oid=$p->get('oid');
- $dir=$p->get('dir');
- $to=$p->get('to');
- // recherche de la rubrique mere
- $poid=$new_p=countSelectQuery('select distinct linkup from '.$this->table.' where KOID="'.$oid.'"');
- // on verifie et corrige l'ordre
- $this->_reorderCat($poid);
- if($to){
- $new_p=($to!='root'?$to:'');
- $this->_reorderCat($new_p);
- }
- // recherche de son ordre
- $o=countSelectQuery('select distinct corder from '.$this->table.' where KOID="'.$oid.'"');
- if($dir=='up'){
- $new_o=$o-1;
- updateQuery('UPDATE '.$this->table.' set corder='.$o.',UPD=UPD where corder='.$new_o.' and linkup="'.$poid.'"');
- }elseif($dir=='down'){
- $new_o=$o+1;
- updateQuery('UPDATE '.$this->table.' set corder='.$o.',UPD=UPD where corder='.$new_o.' and linkup="'.$poid.'"');
- }elseif(Kernel::isAKoid($dir)){
- $new_o=countSelectQuery('select distinct corder from '.$this->table.' where KOID="'.$dir.'"')+1;
- updateQuery('UPDATE '.$this->table.' set corder=corder+1,UPD=UPD where corder>='.$new_o.' and linkup="'.$new_p.'"');
- }else{
- $new_o=0;
- }
- updateQuery('UPDATE '.$this->table.' set corder='.$new_o.',linkup="'.$new_p.'" where KOID="'.$oid.'"');
- $this->_reorderCat($poid);
- if($new_p!=$poid) $this->_reorderCat($new_p);
- }
- /// suppression d'une rubrique et de toutes les sections associees
- function delCat($ar=NULL) {
- $p=new XParam($ar,array('_selectedok'=>'nok'));
- $lang_data=XShell::getLangData();
- if($lang_data==TZR_DEFAULT_LANG) $lang='';
- elseif(!$this->_categories->isTranslatable()) $lang='';
- else $lang="AND LANG='$lang_data'";
- $selected = $p->get('_selected');
- $selectedok = $p->get('_selectedok');
- if($selectedok=='ok') {
- foreach($selected as $oid => $bidon) {
- $ar['oid']=$oid;
- $ar['_selected']=array();
- $ar['_selectedok']='nok';
- $this->delCat($ar);
- }
- return;
- }
- $oid=$p->get('oid');
- $oids[$oid]=1;
- $kernel = new Kernel;
- while(count($oids)>0) {
- unset($oids2);
- foreach($oids as $k => $v) {
- $kernel->data_forcedDel(array('oid'=>$k,'action'=>'OK','_selectedok'=>'nok'));
- // suppression des sections
- $rs=selectQuery('select * from '.$this->tname." where KOIDSRC='$k'");
- while($ors=$rs->fetch()) {
- $itoid = $ors['ITOID'];
- $koiddst = $ors['KOIDDST'];
- if(!empty($koiddst)) {
- $tabledst = Kernel::getTable($koiddst);
- if(!empty($tabledst)) {
- if($lang_data == TZR_DEFAULT_LANG) {
- updateQuery('DELETE FROM '.$this->tname." where ITOID = '$itoid'");
- }
- $kernel->data_forcedDel(array('oid'=>$koiddst,'action'=>'OK','_selectedok'=>'nok'));
- }
- }
- }
- $rs->closeCursor();
- $rs=selectQuery('select distinct KOID from '.$this->table." where linkup='$k'");
- while($ors=$rs->fetch()) {
- $oids2[$ors['KOID']]=1;
- }
- $rs->closeCursor();
- }
- $oids=$oids2;
- }
- }
- /// suppression d'une categorie et de toutes les sections associees
- function dupCat($ar=NULL) {
- $p=new XParam($ar,array('_selectedok'=>'nok'));
- $lang_data=XShell::getLangData();
- if($lang_data==TZR_DEFAULT_LANG) $lang='';
- elseif(!$this->_categories->isTranslatable()) $lang='';
- else $lang="AND LANG='$lang_data'";
- $selected = $p->get('_selected');
- $selectedok = $p->get('_selectedok');
- if($selectedok=='ok') {
- foreach($selected as $oid => $bidon) {
- $ar['oid']=$oid;
- $ar['_selected']=array();
- $ar['_selectedok']='nok';
- $this->dupCat($ar);
- }
- return;
- }
- // duplication de la rubrique
- $oid=$p->get('oid');
- $nkoid=$this->_categories->duplicate(array('oid'=>$oid));
- $copy_of=XLabels::getSysLabel('general.copy_of');
- updateQuery('UPDATE '.$this->_categories->getTable()." set title=CONCAT('$copy_of ', title) where KOID='$nkoid'");
- updateQuery('UPDATE '.$this->_categories->getTable()." set alias=CONCAT(alias,'1') where KOID='$nkoid' and alias !=''");
- if($this->_categories->fieldExists('PUBLISH')) {
- updateQuery('UPDATE '.$this->_categories->getTable()." set PUBLISH='2' where KOID='$nkoid'");
- }
- // duplication des sections
- $rs=selectQuery('select * from '.$this->tname." where KOIDSRC='$oid'");
- if($rs->rowCount()>0) {
- $oids=array();
- $ors=array();
- while($ors=$rs->fetch()) {
- $oids[]=$ors['KOIDDST'];
- $itoids[]=$ors['ITOID'];
- }
- // duplication de chacune des sections
- $noids=array();
- foreach($oids as $i=>$oid1) {
- if(!empty($oid1)) {
- $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$oid1);
- $noids[$i]=$xset->duplicate(array('oid'=>$oid1));
- }
- }
- // duplication des liens
- updateQuery('CREATE TEMPORARY TABLE tmpo SELECT * FROM '.$this->tname." where KOIDSRC='$oid'");
- updateQuery("UPDATE tmpo set KOIDSRC='$nkoid'");
- foreach($oids as $i=>$oid1) {
- if(!empty($oid1)) {
- updateQuery("UPDATE tmpo set KOIDDST='".$noids[$i]."' where KOIDDST='$oid1' and KOIDSRC='$nkoid'");
- }
- }
- $rs=selectQuery('select * from tmpo');
- $ors=array();
- while($rs && ($ors=$rs->fetch())) {
- $olditoid=$ors['ITOID'];
- $n=self::newItOid();
- updateQuery("UPDATE tmpo set ITOID='$n' where ITOID='$olditoid'");
- }
- updateQuery('INSERT INTO '.$this->tname.' select * from tmpo');
- updateQuery('DROP TABLE tmpo');
- }
- $rs=selectQuery('SELECT DISTINCT KOID FROM '.$this->table." WHERE linkup='$oid'/* 1 */");
- while($ors=$rs->fetch()) {
- $ar1=array();
- $ar1['_selected']=array();
- $ar1['_selectedok']='nok';
- $ar1['oid']=$ors['KOID'];
- $nkoid2=$this->dupCat($ar1);
- XLogs::debug("recursive duplicate {$ors['KOID']} to $nkoid2");
- updateQuery("UPDATE {$this->table} set linkup='$nkoid' where KOID='$nkoid2'");
- }
- $rs->closeCursor();
- return $nkoid;
- }
- /// validation de sections ou de rubriques
- public function publish($ar) {
- $p = new XParam($ar,array('_pub'=>false));
- $selected = $p->get('_itoidselected');
- $pub = $p->get('_pub');
- $selectedoid = array();
- $oidsection=$p->get("oidsection");
- if(!empty($oidsection)) {
- $selected[$oidsection]=1;
- }
- if(is_array($selected)) {
- foreach($selected as $itoid => $foo) {
- $rs=selectQuery('select distinct KOIDDST from '.$this->tname." where ITOID='$itoid'");
- if($o=$rs->fetch()) {
- if(!empty($o['KOIDDST']))
- $selectedoid[]=$o['KOIDDST'];
- }
- }
- }
- $_selected=$p->get('_selected');
- if(!empty($_selected)) {
- $copy_of_selectedoid=$selectedoid;
- $selectedoid=array_merge(array_keys($_selected), $copy_of_selectedoid);
- }
- if(!empty($selectedoid)) {
- $ar['_selected']=$selectedoid;
- $ar['key']=false;
- $ar['value']=$pub;
- foreach($selectedoid as $oid) {
- $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$oid);
- $ar1=array('oid'=>$oid, 'value'=>$pub, '_selected'=>array());
- $xset->publish($ar1);
- }
- }
- }
- //// validation des oid ou des rubriques
- public function publishCat($ar) {
- $p=new XParam($ar,array('_pub'=>false));
- $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->table);
- $xset->publish($ar);
- }
- // Affichage de l'arboresnce
- //
- function homeedit($ar=NULL) {
- $p = new XParam($ar, array('level'=>'1','deroule'=>'1','sections'=>'1','tplentry'=>'mit','maxlevel'=>99));
- $this->home($ar);
- }
- // rend la liste des objets qui se trouvent en dessous de cet objet,
- // independamment des niveaux
- //
- public function &subObjects($oid) {
- return $this->getSubCats($oid, TZR_DEFAULT_LANG, 1, 20);
- }
- // rend vrai si le noeud oidit as des fils
- //
- protected function hasChildren($oidit) {
- $cnt=countSelectQuery('select * from '.$this->table." where linkup='$oidit'");
- return $cntt;
- }
- // rend l'url conseillee pour un noeud donné
- //
- protected function _selfUrl($oid, $alias=NULL) {
- if(!empty($alias)) {
- $html="alias=$alias";;
- } else {
- $html="oidit=$oid";
- }
- return $html;
- }
- function &procHome($ar=NULL) {
- $p = new XParam($ar, array());
- $aliases=$p->get('alias');
- $allmessages = array();
- if(is_array($aliases)) {
- foreach($aliases as $oid => $alias) {
- $message = '';
- $this->_checkAlias($alias, '', $oid, $message, NULL);
- if ($message == '')
- $this->_categories->procEdit(array('alias'=>$alias,'oid'=>$oid));
- else
- $allmessages[] = $message;
- }
- }
- XShell::setNextData('message', implode(', ',$allmessages));
- }
- /****m* XModInfoTree/home
- * NAME
- * XModInfoTree::home - creation de l'arborescence
- * DESCRIPTION
- * Preparation d'une structure de donnees pour affichage de la
- * hierarchie de rubriques
- * INPUTS
- * Passage de parametre indirect via $ar
- * level - numero du premier niveau, les niveaux sont numerotes a
- * partir de level, la valeur par defaut est 1 ;
- * maxlevel - nombre maximum de niveaux a explorer, valeur par defaut 99 ;
- * do - action a effectuer. showtree: exploration de toutes les branches ;
- * oidtop - oid de l'item pere de l'arboresence ;
- * aliastop - alias de l'item pere de l'arboresence ;
- ****/
- function &home($ar=NULL) {
- XLogs::debug('XModInfoTree::home: start');
- $p = new XParam($ar, array('level'=>'1','deroule'=>'1','sections'=>'1','myself'=>false,'tplentry'=>'mit','maxlevel'=>99,
- 'lastupd'=>false,'optimized'=>false,'cond_categ'=>array(),'where_categ'=>false));
- $do = $p->get('do');
- $myself=$p->get('myself');
- $niv = $p->get('level');
- $linkinfollow=$p->get('linkinfollow');
- $optimized = $p->get('optimized');
- $aliastop = $p->get('aliastop');
- $published = $p->get('_published');
- if(!empty($aliastop)) {
- if(Kernel::isAKoid($aliastop)) $oidtop=$aliastop;
- else $oidtop=$this->getOidFromAlias($aliastop);
- }
- if(empty($oidtop))
- $oidtop = $p->get('oidtop');
- $deroule = $p->get('deroule');
- if(!isset($deroule)) $deroule = $p->get('unfoldall');
- $computesections=$p->get('sections');
- $norubric=$p->get('norubric');
- $oidselected = $p->get('oid');
- $tplentry=$p->get('tplentry');
- $LANG_DATA = XShell::getLangData($p->get('LANG_DATA'));
- $LANG_TRAD = XShell::getLangData($p->get('LANG_TRAD'));
- if(!empty($LANG_TRAD)) {
- $lang_tree=$LANG_TRAD;
- $lang_other=$LANG_DATA;
- }
- $maxlevel = $p->get('maxlevel');
- $selectedfields=$p->get('selectedfields');
- if(XShell::admini_mode()) setSessionVar('module_name',$this->modulename);
- if($norubric) $rubric=array();
- else $rubric = getSessionVar('rubric');
- if($do=='add') {
- $st1=$this->getPath($oidselected);
- foreach($st1['oiddown'] as $i=>$oid1) $rubric[$oid1]='1';
- } elseif($do=='del') {
- unset($rubric[$oidselected]);
- } elseif($do=='foldall') {
- clearSessionVar('rubric');
- $rubric=array();
- } elseif($do=='unfoldall') {
- $deroul=true;
- } elseif($do=='showtree') {
- $deroul=true;
- $deroule=1;
- }
- if(empty($this->_rbrowse)) {
- $options=array();
- if(XShell::admini_mode() || $optimized) {
- $options['linkup']=array('nofollowlinks'=>1);
- }
- if(empty($selectedfields)){
- if(XShell::admini_mode()) $selectedfields = array('UPD','PUBLISH','title','corder','linkup','alias','picto','descr',$this->linkin);
- else $selectedfields='all';
- }elseif(is_array($selectedfields)){
- $selectedfields=array_merge($selectedfields,array('UPD','PUBLISH','title','corder','linkup','alias','picto','descr',$this->linkin));
- }
-
- $cond_categ = $p->get('cond_categ');
- $where_categ = $p->get('where_categ');
-
- $query = $this->_categories->select_query(array('cond'=>$cond_categ,
- 'where'=>$where_categ,
- 'selectedfields'=>$selectedfields,
- 'LANG_DATA'=>$lang_tree));
- $this->_rbrowse=&$this->_categories->browse(array('select'=>$query,
- 'pagesize'=>9999,
- 'selectedfields'=>$selectedfields,
- '_charset'=>@$_REQUEST['_charset'],
- 'order'=>'corder',
- 'options'=>$options,
- 'tplentry'=>TZR_RETURN_DATA,
- 'last'=>'9999','nocount'=>'1',
- '_options'=>array('local'=>1)));
- $this->_rbrowse['objects_sec']=$GLOBALS['XUSER']->getObjectsAccess($this,
- XShell::getLangData(),
- $this->_rbrowse['lines_oid']);
- // appliquer les droits sur les objets
- if ($this->object_sec) {
- $levelMax = $GLOBALS['XUSER']->secure8maxlevel($this, null, null, XShell::getLangData());
- // construction de l'arbre descendant pour l'héritage des droits
- foreach ($this->_rbrowse['lines_oid'] as $i => $oid) {
- $up = $this->_rbrowse['lines_olinkup'][$i]->raw;
- if (empty($this->_rbrowse['treedown'][$up]))
- $this->_rbrowse['treedown'][$up] = array();
- $this->_rbrowse['treedown'][$up][] = $oid;
- }
- $this->_rbrowse['oid_index'] = array_flip($this->_rbrowse['lines_oid']);
- // calcul des droits cumulés héritables et des enfants
- foreach ($this->_rbrowse['lines_oid'] as $i => $oid) {
- $this->_rbrowse['upobjects_sec'][$i] = $this->_upRights($i);
- $this->_rbrowse['downobjects_sec'][$i] = $this->_downRights($i, $oid);
- }
- foreach ($this->_rbrowse['lines_oid'] as $i => $oid) {
- // si pas de droits spécifiques sur ce noeud, hériter
- if (array_pop(array_keys($this->_rbrowse['objects_sec'][$i])) == $levelMax && !empty($this->_rbrowse['upobjects_sec'][$i])) {
- $this->_rbrowse['objects_sec'][$i] = $this->_rbrowse['upobjects_sec'][$i];
- }
- }
- // suppression des noeuds non lisibles et sans enfants lisibles
- foreach ($this->_rbrowse['lines_oid'] as $i => $oid) {
- if (!isset($this->_rbrowse['objects_sec'][$i]['ro']) && !isset($this->_rbrowse['downobjects_sec'][$i]['ro'])) {
- unset($this->_rbrowse['lines_oid'][$i]);
- }
- }
- }
- XLogs::debug('XModInfoTree: after security sort');
- }
- $rbrowse=&$this->_rbrowse;
- if(!empty($published)) {
- foreach($this->_rbrowse['lines_oid'] as $i => $oid) {
- $pub1=$this->_rbrowse['lines_published'][$i];
- if(empty($pub1)||($pub1==2)) {
- unset($this->_rbrowse['lines_oid'][$i]);
- }
- }
- }
- // on affiche la poubelle que si c'est l'alias qui est explicitement demandé
- if($aliastop!='trash') {
- $trashoid=$this->getTrashOid();
- if(!empty($trashoid)) {
- foreach($this->_rbrowse['lines_oid'] as $i => $oid) {
- if($oid==$trashoid) {
- unset($this->_rbrowse['lines_oid'][$i]);
- break;
- }
- }
- }
- }
- // on recherche les sommets a parcourir
- $stack=array();
- $koids=array_flip($rbrowse['lines_oid']);
- $koidtoprocess=array_reverse($rbrowse['lines_oid'],TRUE);
- $todel=array();
- foreach($koidtoprocess as $i => $oid) {
- $curi=$koids[$oid];
- $linkup = $rbrowse['lines_olinkup'][$curi]->raw;
- if($myself){
- if($oid==$oidtop){
- array_push($stack, array($oid,$niv,$curi,1,$linkup));
- array_push($todel, $i);
- break;
- }
- }else{
- if((empty($oidtop) && empty($linkup)) || ($oidtop==$linkup)) {
- array_push($stack, array($oid,$niv,$curi,1,$linkup));
- array_push($todel, $i);
- }
- }
- }
- while(count($todel)>0) unset($koidtoprocess[array_pop($todel)]);
- // recherche du nombre de sous-noeuds
- $section_nb = selectQuery('SELECT KOIDSRC,count(KOIDSRC) from '.$this->tname.' group by KOIDSRC')
- ->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP|PDO::FETCH_UNIQUE);
- // construction de l'arbre descendant
- $treedown = array();
- foreach($rbrowse['lines_oid'] as $i => $oid) {
- $up=$rbrowse['lines_olinkup'][$i]->raw;
- if(empty($treedown[$up])) $treedown[$up]=array();
- $treedown[$up][]=$oid;
- }
- // on parcourt ce qui nous interesse
- $r=array();
- $r['aliastop']=$aliastop;
- $r['self']=$this->_categories->display(array('tplentry'=>TZR_RETURN_DATA,'oid'=>$oidtop,'_options'=>array('local'=>true)));
- $r['lines_oid']=array();
- $lines_oid_cnt=0;
- $r['lines_level']=array();
- $r['lines_deroule']=array();
- $r['lines_ssrub']=array();
- $r['lines_sections']=array();
- $r['lines_lvl1pagenum']=array();
- $lvl1pagenum=0;
- $newkoids=array();
- while(!empty($stack)) {
- // on depile l'element a traiter
- list($curoid,$curlevel,$curi,$curderoul,$linkup)=array_pop($stack);
- if($curderoul && ($curlevel<=$maxlevel || isset($rubric[$curoid]) || isset($rubric[$linkup]))) {
- $r['lines_oid'][]=$curoid;
- $newkoids[$curoid]=$lines_oid_cnt;
- $lines_oid_cnt++;
- $r['lines_level'][]=$curlevel;
- $r['lines_ssrub'][]=0;
- if($computesections=='1') {
- if(!empty($section_nb[$curoid])) $r['lines_sections'][]=$section_nb[$curoid];
- else $r['lines_sections'][]=0;
- }
- if($do=='unfoldall') {
- $rubric[$curoid]='1';
- }
- $deroul=($do=='showtree'?'1':'0');
- $deroul=$deroul || (empty($rubric[$curoid])?'0':'1');
- $r['lines_deroule'][]=$deroul;
- if($curlevel>1) $lvl1pagenum++;
- else $lvl1pagenum=0;
- $r['lines_lvl1pagenum'][]=$lvl1pagenum;
- }
- $tmp1=@$newkoids[$rbrowse['lines_olinkup'][$curi]->raw];
- if(empty($r['lines_ssrub'][$tmp1])) $r['lines_ssrub'][$tmp1]=1;
- else $r['lines_ssrub'][$tmp1]++;
- if($this->linkin && $linkinfollow && $linkin && $linkin!=$rbrowse['lines_olinkup'][$curi]->raw){
- $tmp1=@$newkoids[$linkin];
- if(empty($r['lines_ssrub'][$tmp1])) $r['lines_ssrub'][$tmp1]=1;
- else $r['lines_ssrub'][$tmp1]++;
- }
- $ocuroid=$curoid;
- if($this->linkin && $linkinfollow && $rbrowse['lines_o'.$this->linkin][$curi]->raw)
- $curoid=$rbrowse['lines_o'.$this->linkin][$curi]->raw;
- if(!empty($treedown[$curoid]) && is_array($treedown[$curoid])) {
- $todel=array();
- foreach(array_reverse($treedown[$curoid]) as $i => $oid) {
- $oldi=$koids[$oid];
- $stack[]=array($oid,$curlevel+1,$oldi,$deroul,$ocuroid);
- $todel[]=$i;
- }
- foreach($todel as $t1=>$toid) unset($koidtoprocess[$toid]);
- }
- $curoid=$ocuroid;
- }
- if(!issetSessionVar('rubric')) {
- if(!empty($rubric)) {
- setSessionVar('rubric',$rubric);
- }
- } else {
- if(!empty($rubric)) {
- setSessionVar('rubric',$rubric);
- } else {
- clearSessionVar('rubric');
- }
- }
- // recopie des donnees du browse
- $norw=array('lines_all_labels','lines_all_codes');
- $rwall=array('objects_sec'=>true,'upobjects_sec'=>true);
- foreach($r['lines_oid'] as $i => $oid) {
- $oldi = $koids[$oid];
- foreach($rbrowse as $k => $v) {
- if(((substr($k, 0,6)=='lines_')||!empty($rwall[$k])) && !in_array($k,$norw)) {
- $r[$k][$i]=(empty($v[$oldi])?NULL:$v[$oldi]);
- }
- if(!empty($r['lines_o'.$this->linkin][$i]->raw)){
- $r['lines_sections'][$i]=@$section_nb[$r['lines_o'.$this->linkin][$i]->raw];
- }
- }
- if(!empty($r['lines_o'.$this->linkin][$i]->raw)){
- $r['lines_sections'][$i]=@$section_nb[$r['lines_o'.$this->linkin][$i]->raw];
- }
- }
- foreach($r['lines_oid'] as $i => $oid) {
- $r['lines_selfurl'][$i]=$this->_selfUrl($oid,$r['lines_oalias'][$i]->toText());
- }
- if(!empty($this->linkin) && $this->_categories->fieldExists($this->linkin)) {
- $r['lines_olinkin']=&$r['lines_o'.$this->linkin];
- }
- $r['moid']=$this->_moid;
- if (XShell::admini_mode()) {
- $r['_editLevel'] = array_shift($this->secGroups('editpage'));
- $r['_inputLevel'] = array_shift($this->secGroups('input'));
- $r['_viewLevel'] = array_shift($this->secGroups('viewpage'));
- }
- XLogs::debug('XModInfoTree::home: end');
- return Xshell::toScreen1($tplentry,$r);
- }
- // calcul les droits héritables
- private function _upRights($i, $first=true) {
- if ($this->_rbrowse['lines_olinkup'][$i]->raw) {
- // calcul des droits du parent
- $upRights = $this->_upRights($this->_rbrowse['oid_index'][$this->_rbrowse['lines_olinkup'][$i]->raw], false);
- if ($first) {
- return $upRights;
- } else {
- return array_merge($this->_rbrowse['objects_sec'][$i], $upRights);
- }
- } else {
- return array();
- }
- }
- // calcul les droits sur les enfants (+ droit sur l'objet)
- private function _downRights($i, $oid) {
- $downRights = $this->_rbrowse['objects_sec'][$i];
- foreach ($this->_rbrowse['treedown'][$oid] as $_oid) {
- $_i = $this->_rbrowse['oid_index'][$_oid];
- if (!isset($this->_rbrowse['downobjects_sec'][$_i]))
- $this->_rbrowse['downobjects_sec'][$_i] = $this->_downRights($_i, $_oid);
- $downRights = array_merge($downRights, $this->_rbrowse['downobjects_sec'][$_i]);
- }
- return $downRights;
- }
- /// Rend les infos sur les rubriques mere de la rubrique oid
- function getPath($ar) {
- if(is_array($ar)){
- $oid=$ar['oid'];
- $tplentry=$ar['tplentry'];
- $selectedfields = $ar['selectedfields'];
- }else{
- $oid=$ar;
- }
- if(empty($selectedfields)) $selectedfields = array('title','alias','linkup','style');
- // Browse de la categorie
- $v1=array();
- $stack=array();
- $nav_alias=$nav_cat=$nav_oid=$nav_url=array();
- do{
- $categ=$this->_categories->rDisplay($oid, array(), false,'','',array('selectedfields'=>$selectedfields));
- if(!is_array($categ)) break;
- $stack[]=$categ;
- $nav_cat[]= $categ['otitle']->toText();
- $nav_oid[]= $oid;
- $nav_alias[]=$categ['oalias']->toText();
- $nav_url[]='&moid='.$this->_moid.'&function=viewpage&template=xmodinfotree/viewpage.html&oidit='.$oid.'&tplentry=it';
- $oid=$categ['olinkup']->raw;
- unset($categ);
- } while($oid);
- $v1=array('labelup'=>$nav_cat,'urlup'=>$nav_url,'oidup'=>$nav_oid,'aliasup'=>$nav_alias,
- 'labeldown'=>array_reverse($nav_cat),'urldown'=>array_reverse($nav_url),
- 'aliasdown'=>array_reverse($nav_alias),
- 'oiddown'=>array_reverse($nav_oid),
- 'stack'=>array_reverse($stack));
- if(!empty($tplentry)) XShell::toScreen1($tplentry,$v1);
- return $v1;
- }
- function _getPathOids($oid) {
- $stack=array();
- $ors['linkup']=$oid;
- do{
- $stack[]=$ors['linkup'];
- $rs = selectQuery('SELECT linkup FROM '.$this->table.' WHERE KOID="'.$ors['linkup'].'"');
- } while($ors=$rs->fetch());
- return $stack;
- }
- function getPathString($koid) {
- $nav=$this->getPath($koid);
- $title='';
- foreach($nav['labeldown'] as $t) $title.='> '.$t;
- return $title;
- }
- protected function _followLinkIn($oid) {
- $links=array();
- if($this->_categories->fieldExists($this->linkin)) {
- $found=false;
- while(!$found && !in_array($oid, $links)) {
- $links[]=$oid;
- $query = 'SELECT KOID,'.$this->linkin.' FROM '.$this->_categories->getTable().
- ' WHERE LANG="'.TZR_DEFAULT_LANG.'" AND KOID="'.$oid.'"';
- $rs=selectQuery($query);
- if(!$ors=$rs->fetch()) {
- $found=true;
- } else {
- if(!Kernel::isAKoid($ors[$this->linkin])) {
- $found=true;
- } else {
- $oid=$ors[$this->linkin];
- }
- $rs->closeCursor();
- }
- }
- }
- return $oid;
- }
- /****m* XModInfoTree/procInput
- * NAME
- * XModInfoTree::procInput - creation d'une nouvelle rubrique
- * DESCRIPTION
- * Fonction d'ajout d'une rubrique dans l'admin en tenant compte du chgement d'ordre d'affichage.
- * INPUTS
- ****/
- function &procInput($ar=NULL) {
- $p = new XParam($ar, array());
- $title = $p->get('title');
- $linkup = $p->get('linkup');
- $order = $p->get('corder');
- $alias = $p->get('alias');
- if(empty($order)) $order='0';
- $ar['tplentry']=TZR_RETURN_DATA;
- $message='';
- $this->_checkAlias($alias, '', NULL, $message, $title);
- $ar['alias']=$alias;
- if(!empty($message)) {
- XShell::setNextData('message', $message);
- }
- $r=$this->_categories->procInput($ar);
- // positionnement des droits
- if(!empty($this->object_sec)) {
- $GLOBALS['XUSER']->setUserAccess(get_class($this),$this->_moid,XShell::getLangData(),$r['oid'],'admin');
- }
- // maj de l'order d'affichage de la rubrique.
- $this->majUpOtherOrder($title,$linkup,$order);
- return $r;
- }
- /****m* XModInfoTree/edit
- * NAME
- * XModInfoTree::edit - creation d'une nouvelle rubrique
- * DESCRIPTION
- * Fonction d'edition d'une rubrique dans l'admin en tenant compte du chgement d'ordre d'affichage.
- * INPUTS
- ****/
- //
- //
- function edit($ar=NULL) {
- $this->_categories->edit($ar);
- $GLOBALS['XSHELL']->tpldata['']['moid']=$this->_moid;
- }
- function input($ar=NULL) {
- $p = new XParam($ar, array());
- $ar['options']['linkup']['value']=$p->get('linkup');
- $ar['options']['corder']['value']=$p->get('order');
- $this->_categories->input($ar);
- $GLOBALS['XSHELL']->tpldata['']['title']=$GLOBALS['XSHELL']->tpldata['']['otitle']->html;
- $GLOBALS['XSHELL']->tpldata['']['order']=$GLOBALS['XSHELL']->tpldata['']['ocorder']->html;
- $GLOBALS['XSHELL']->tpldata['']['alias']=$GLOBALS['XSHELL']->tpldata['']['oalias']->html;
- $GLOBALS['XSHELL']->tpldata['']['moid']=$this->_moid;
- }
- // mise a jour d'une rubrique
- //
- function procEdit($ar=NULL) {
- $p = new XParam($ar, array());
- $oidMere = $p->get('linkup');
- $oid = $p->get('oid');
- $alias = $p->get('alias');
- $title = $p->get('title');
- $langs = $p->get('_langs');
- $lang_data = XShell::getLangData();
- // Traitement des cas ou l'on veut sauver dans plusieurs langues
- $ar['_langs']=$this->getAuthorizedLangs($langs,$oid,'procEdit');
- if($lang_data == TZR_DEFAULT_LANG) {
- $disp_cat = $this->_categories->display(array('oid'=>$oid,'tplentry'=>TZR_RETURN_DATA));
- $message='';
- $oldalias= $disp_cat['oalias']->raw;
- // vérification alias
- $this->_checkAlias($alias, $oldalias, $oid, $message, $title);
- $ar['alias'] = $alias; // peut-être modifié par _checkAlias
- // vérification de boucle sur linkin
- if ($this->linkin) {
- $linkin = $p->get($this->linkin);
- if ($linkin && !$this->_checkLinkin($oid, $linkin)) {
- $message .= '<br>' . $this->_categories->desc[$this->linkin]->label . ' : ' . XLabels::getSysLabel('xmodinfotree.circularity');
- }
- }
- if (!empty($message)) {
- unset($_REQUEST['skip'], $_REQUEST['_skip']);
- XShell::changeTemplate('xmodinfotree/editcat.html');
- XShell::setNext();
- XShell::toScreen2('', 'message', $message);
- $ar['options'] = $this->_categories->prepareReEdit($ar);
- $ar['tplentry'] = 'editcat';
- return $this->editcat($ar);
- }
- $oldOrder = $disp_cat['ocorder']->raw;
- $ar['tplentry']='addrub';
- $this->_categories->procEdit($ar);
- } else {
- $oldOrder = $disp_cat['ocorder']->raw;
- $this->_categories->procEdit($ar);
- }
- // maj de l'order d'affichage de la rubrique.
- $newOrder = $p->get('corder');
- $titre = $p->get('title');
- $oid = $p->get('linkup');
- $this->majOtherOrder($titre,$oid,$oldOrder,$newOrder);
- }
- /// Mise à jour d'une rubrique dans de toutes les langues pour lesquel l'utilisateur à les droits
- function procEditAllLang($ar) {
- $ar['_langs']='all';
- return $this->procEdit($ar);
- }
- // verification que l'alias est valide et generation eventuelle d'un alias
- //
- function _checkAlias(&$alias, $oldalias, $oid, &$message, $title=NULL) {
- if(empty($alias) && !empty($title)) {
- $alias=rewriteToAscii($title);
- }
- /* verification que les alias sont bien constitués de 2 à 40 chiffres, lettres _ et - */
- $aliasfield=&$this->_categories->getField('alias');
- $aliaslength=$aliasfield->get_fcount();
- if(!preg_match('/^([a-zA-Z0-9_-]{1,'.$aliaslength.'})$/',$alias)) {
- $message=XLabels::getSysLabel('xmodinfotree.aliasnotcorrect').' '.$alias;
- $alias=$oldalias;
- }
- /* verification de l'unicite des alias */
- if(!empty($alias) ) {
- $req = "select count(*) from ".$this->_categories->getTable()." where alias='".$alias."' ";
- if(!empty($oid)) $req .= "and KOID != '".$oid."' ";
- $cnt=countSelectQuery($req);
- if($cnt>0) {
- $message=XLabels::getSysLabel('xmodinfotree.aliasunique').' '.$alias;
- $alias=$oldalias;
- }
- }
- /* verification si l'alias est protege */
- if(($oldalias!=$alias) && !empty($oldalias) && $this->aliasIsProtected($oldalias)) {
- $message=XLabels::getSysLabel('xmodinfotree.aliasprotected').' '.$alias;
- $alias=$oldalias;
- $modif = 1;
- }
- }
- // test de circularité des redirections
- function _checkLinkin($oid, $linkin) {
- $path = $this->_getPathOids($oid);
- array_pop($path); // le dernier élément est vide
- // test la cible
- if (in_array($linkin, $path))
- return false;
- // test le lien de la cible
- $target_linkin = selectQuery("select {$this->linkin} from {$this->table} where koid='$linkin'")->fetch(PDO::FETCH_COLUMN);
- if ($target_linkin && in_array($target_linkin, $path))
- return false;
- // test les sous-noeuds de la cible
- return $this->_checkLinkinChild($linkin, $path);
- }
- // test de circularité des redirections pour les descendants
- function _checkLinkinChild($oid, $path) {
- $children = selectQuery("select KOID, {$this->linkin} from {$this->table} where linkup='$oid'")->fetchAll();
- foreach ($children as $child) {
- if ($child[$this->linkin] && in_array($child[$this->linkin], $path))
- return false;
- if (!$this->_checkLinkinChild($child['KOID'], $path))
- return false;
- }
- return true;
- }
-
- // Fonction de mise a jour de l'ordre d'affichage d'une rubrique.
- //
- function majUpOtherOrder($titre,$oid,$forder) {
- if ($oid == '' ) {
- $requete = 'UPDATE ' . $this->table .' set '.'corder'.
- "=IF(corder<9,CONCAT('0',corder+1),corder+1) where title!='" .
- $titre . "' and linkup = '' and corder>=" . $forder;
- } else {
- $requete = "UPDATE " . $this->table ." set corder=IF("."corder".
- "<9,CONCAT('0',corder+1),corder+1) where title!='" . $titre.
- "' and linkup = '$oid' and corder>=" . $forder;
- }
- updateQuery($requete);
- }
- // Fonction de mise a jour de l'ordre d'affichage d'une rubrique.
- //
- function majDownOtherOrder($titre,$oid,$forder) {
- if ($oid == '' ) {
- $requete = 'UPDATE ' . $this->table .' set corder=IF('.'corder'.
- "<11,CONCAT('0',corder-1),corder-1) where title!='" .
- $titre . "' and linkup = '' and corder>" . $forder;
- } else {
- $requete = 'UPDATE ' . $this->table .' set corder=IF('.'corder'.
- "<9,CONCAT('0',corder-1),corder-1) where title!='" . $titre .
- "' and linkup = '$oid' and corder>" . $forder;
- }
- updateQuery($requete);
- }
- // Fonction de mise a jour de l'ordre d'affichage d'une rubrique.
- //
- function majOtherOrder($titre,$oid,$oldOrder,$newOrder) {
- // Si augmente, -- sur les order > old et <= new
- // Si diminue, ++ sur les order >= new et < old
- if ( $newOrder > $oldOrder ) {
- // augmentation
- if ($oid == '' ) {
- $requete = 'UPDATE ' . $this->table .' set corder=IF('.'corder'.
- "<11,CONCAT('0',corder-1),corder-1) where title!='" .
- $titre . "' and linkup = '' and corder>" . $oldOrder . " and ".
- "corder"." <=" . $newOrder;
- } else {
- $requete = "UPDATE " . $this->table ." set corder=IF("."corder".
- "<11,CONCAT('0',corder-1),corder-1) where title!='" . $titre .
- "' and linkup = '$oid' and corder>" . $oldOrder . " and corder <=" .
- $newOrder;
- }
- }
- if ( $newOrder < $oldOrder ) {
- // diminution
- if ($oid == '' ) {
- $requete = 'UPDATE ' . $this->table ." set corder=IF(corder<9,CONCAT('0',".
- "corder"."+1),corder-1) where title!='" . $titre . "' and ".
- "linkup = '' and corder>=" . $newOrder . " and corder <" . $oldOrder;
- } else {
- $requete = 'UPDATE ' . $this->table ." set corder=IF(corder<9,CONCAT('0',".
- "corder"."+1),corder-1) where title!='" . $titre . "' and ".
- "linkup = '$oid' and corder>=" . $newOrder . " and corder <" . $oldOrder;
- }
- }
- updateQuery($requete);
- }
- //
- function confirmDel($ar=NULL) {
- global $XSHELL;
- $p = new XParam($ar, array( "tplentry"=>$this->table));
- $oid=$p->get("oid");
- $lang=XShell::getLangData();
- $oidContenu = array();
- $this->browse(array("oid"=>$oid,"level"=>$niv), $oidContenu);
- $result = array();
- $result["oid"] = $oid;
- $result["level"] = $niv;
- $XSHELL->tpldata["$tplentry"] = $result;
- }
- // rend la liste des templates avec eventuellement un selecteur sur la table destination
- // si subset est un ensemble de koid (tableau), seules les reponses
- // deja presente dans ce tableau seront retournees
- //
- protected function &_templatesList($tabledst=NULL,$filter="page",$oidit=NULL) {
- if(!empty($oidit) && $this->_categories->fieldExists('alayout')) {
- $r2= &$this->_categories->display(array("oid"=>$oidit,
- "_options"=>array("error"=>"return"),
- "tplentry"=>TZR_RETURN_DATA,
- "fallback"=>true));
- }
- if(!empty($r2['oalayout']->oidcollection)) {
- $subset=$r2['oalayout']->oidcollection;
- if(!empty($tabledst)) {
- $cond = $this->_templates->select_query(array("cond"=>array('tab'=>array("=",$tabledst),
- "modid"=>array("=",array($this->_moid,'')),
- "KOID"=>array("=",$subset))));
- } else {
- $cond = $this->_templates->select_query(array("cond"=>array("modid"=>array("=",array($this->_moid,'')),
- "gtype"=>array("=",$filter),
- "KOID"=>array("=",$subset))));
- }
- } else {
- if(!empty($tabledst)) {
- $cond = $this->_templates->select_query(array("cond"=>array('tab'=>array("=",$tabledst),
- "modid"=>array("=",array($this->_moid,'')))));
- } else {
- $cond = $this->_templates->select_query(array("cond"=>array("modid"=>array("=",array($this->_moid,'')),
- "gtype"=>array("=",$filter))));
- }
- }
- $r=&$this->_templates->browse(array("select"=>$cond,"first"=>"0","last"=>"999","pagesize"=>99,
- "order"=>'title',
- "tplentry"=>TZR_RETURN_DATA,
- "selectedfields"=>array("title","tab",'functions', 'modidd')));
- return $r;
- }
- // rend les donnees concernant un template d'oid fourni
- //
- function &_disp2Template($oidt=NULL) {
- $opt=array();
- $opt["oid"]=$oidt;
- $opt["tplentry"]=TZR_RETURN_DATA;
- $opt["_options"]=array("error"=>"return");
- $opt["fallback"]="true";
- $opt["_cacheobject"]="disp2template";
- $opt["_lastupdate"]=false;
- $r=$this->_templates->display($opt);
- return $r;
- }
- function editsection($ar) {
- global $XSHELL;
- $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
- $tplentry = $p->get("tplentry");
- $oidit = $p->get("oidit");
- $lang = XShell::getLangData();
- $oidsection=$p->get("oidsection");
- list($oidit,$oiddest,$oidtemplate)=$this->_getOids($oidsection);
- $tableofoid=Kernel::getTable($oiddest);
- // Browse des modeles de mise en page
- XShell::toScreen1('tple', $this->_templatesList($tableofoid,'page', $oidit));
- // infos d'affichage du template
- $r1=$this->_disp2Template($oidtemplate);
- XShell::toScreen1('tp',$r1);
- $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tableofoid);
- $ar["tplentry"]=TZR_RETURN_DATA;
- $ar['oid']=$oiddest;
- $ar['fallback']=true;
- if(empty($ar['fmoid'])) $ar['fmoid']=$this->_moid;
- $r=$xst->edit($ar);
- $s['olines'][]=$r;
- $s['olines_oid'][]=$oiddest;
- XShell::toScreen1('it',$s);
- XShell::toScreen1($tplentry,$r);
- XShell::toScreen2('section','oidit',$oidit);
- XShell::toScreen2('section','oidsection',$oidsection);
- }
- // affichage des donnees d'un objet particulier d'une page
- //
- function displaysection($ar) {
- $p = new XParam($ar, array("level"=>1,"tplentry"=>"it",
- "toc"=>"1","maxlevel"=>1));
- $tplentry = $p->get("tplentry");
- $oidsection = $p->get("oidsection");
- $lang = XShell::getLangData();
- $tab= XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$oidsection);
- if($tplentry==TZR_RETURN_DATA)
- return $tab->display(array("oid"=>$oidsection, "tplentry"=>TZR_RETURN_DATA));
- else
- $tab->display(array("oid"=>$oidsection, "tplentry"=>$tplentry));
- }
- /// Liste les types de sections qui peuvent etre créées
- public function addSection($ar=NULL){
- $p=new XParam($ar,NULL);
- $tplentry=$p->get('tplentry');
- $oidit=$p->get('oidit');
- $r['page']=&$this->_templatesList(NULL, 'page', $oidit);
- $r['query']=&$this->_templatesList(NULL, 'query', $oidit);
- $r['function']=&$this->_templatesList(NULL, 'function', $oidit);
- $r['position'] = selectQuery('select ORDER1 from '.$this->tname.' WHERE KOIDSRC="'.$oidit.'" order by ORDER1')->fetchAll(PDO::FETCH_COLUMN);
- $r['oidit']=$oidit;
- $modlist = XModule::modlist(array('tplentry'=>TZR_RETURN_DATA, 'basic' => 1, 'withmodules'=>1));
- for ($i=0; $i<count($modlist['lines_oid']); $i++) {
- $uiFunctions = $modlist['lines_mod'][$i]->getUIFunctionList();
- if ($modlist['lines_mod'][$i]->available_in_display_modules && !empty($uiFunctions)) {
- $r['modlist']['lines_oid'][] = $modlist['lines_oid'][$i];
- $r['modlist']['lines_mod'][] = $modlist['lines_mod'][$i];
- $r['modlist']['lines_name'][] = $modlist['lines_name'][$i];
- $r['modlist']['lines_group'][] = $modlist['lines_group'][$i];
- $r['modlist']['lines_toid'][] = $modlist['lines_toid'][$i];
- $r['modlist']['lines_classname'][] = $modlist['lines_classname'][$i];
- $r['modlist']['lines_functions'][] = $uiFunctions;
- $class = get_class($modlist['lines_mod'][$i]);
- $r['modlist']['lines_classes'][] = array_merge(class_parents($modlist['lines_mod'][$i]), array($class => $class));
- }
- }
- return XShell::toScreen1($tplentry,$r);
- }
- /// preparation de l'ecran de saisie d'une nouvelle section
- function newsection($ar) {
- global $XSHELL;
- $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
- $tplentry = $p->get("tplentry");
- $oidit = $p->get("oidit");
- $oidtpl = $p->get("oidtpl");
- $lang = XShell::getLangData();
- $tabletpl=Kernel::getTable($oidtpl);
- $rs=selectQuery("select * from $tabletpl where KOID='$oidtpl' AND LANG='$lang'");
- if($o1=$rs->fetch()) {
- $tabledst = $o1['tab'];
- // Browse des modeles de mise en page
- XShell::toScreen1('tple', $this->_templatesList($tabledst,"page",$oidit));
- // infos d'affichage du template
- $r1=$this->_disp2Template($oidtpl);
- XShell::toScreen1('tp',$r1);
- $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
- $ar["tplentry"]=TZR_RETURN_DATA;
- if(empty($ar['fmoid'])) $ar['fmoid']=$this->_moid;
- $r=$xst->input($ar);
- $s['position']=$p->get('position');
- $s['oidit']=$p->get('oidit');
- $s['oidtpl']=$p->get('oidtpl');
- $s['olines'][]=$r;
- $s['olines_oid'][]=$xst->getNewOID($ar);
- XShell::toScreen1($tplentry,$s);
- }
- }
- function editquery($ar) {
- $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
- $tplentry = $p->get("tplentry");
- $oidsection = $p->get("oidsection");
- list($oidsrc,$oiddest,$oidtpl)=$this->_getOids($oidsection);
- // recherche de l'item
- $rs=selectQuery("select * from ".$this->tname." where ITOID='$oidsection'");
- if(!$ors=$rs->fetch()) return array();
- $qinit = unserialize($ors['QUERY']);
- // table des templates
- $rtpl=$this->_disp2Template($oidtpl);
- $tabledst = $rtpl['otab']->raw;
- XShell::toScreen1('tple',$this->_templatesList($tabledst,'query',$oidit));
- // table dans laquelle se trouvenet les donnes
- $table = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
- $query=array();
- if(is_array($qinit)) {
- $query['operator']=$qinit['operator'];
- foreach($table->desc as $k => $v) {
- if(isset($qinit[$k]) || !empty($qinit[$k.'_PAR'])) {
- if($table->fieldExists($k)) {
- $query[$k]=$qinit['options'][$k];
- $query[$k]['value']=$qinit[$k];
- $query[$k]['op']=$qinit[$k.'_op'];
- $query[$k]['par']=$qinit[$k.'_PAR'];
- $query[$k]['fmt']=(isset($qinit[$k.'_FMT'])?$qinit[$k.'_FMT']:$qinit[$k.'_HID']);
- $query[$k]['notapplyqfmt']=true;
- } else {
- $query[$k]=$qinit[$k];
- }
- }
- }
- }
- $ar['tplentry']=TZR_RETURN_DATA;
- $ar['options']=$query;
- $ar['querymode']='pquery';
- if(empty($ar['fmoid'])) $ar['fmoid']=$this->_moid;
- $r=$table->query($ar);
- $r['oidit']=$oidsrc;
- $r['_select']=$qinit['_select'];
- $r['oidsection']=$oidsection;
- $r['pagesize']=$qinit['pagesize'];
- $r['setup']=$oidtpl;
- $r['labelin']=$qinit['labelin'];
- if(is_array($qinit['order'])) {
- foreach($qinit['order'] as $ki=>$vi){
- $torder=explode(" ",$qinit['order'][$ki]);
- $r['order'][$ki]=$torder[0];
- $r['_order'][$ki]=$torder[1];
- }
- } else {
- $torder=explode(" ",$qinit['order']);
- $r['order'][0]=$torder[0];
- $r['_order'][0]=$torder[1];
- }
- foreach($r['order'] as $ki=>$vi){
- $r['fieldselector'][$ki]=$table->order_selector(array('fieldname'=>'order[]','value'=>$r['order'][$ki],'random'=>($ki==0),
- 'compulsory'=>($ki==0)
- )
- );
- }
- if(empty($r['fieldselector'][0])) $r['fieldselector'][0] = $table->order_selector(array('fieldname'=>'order[]',
- 'value'=>'','compulsory'=>false));
- $r['emptyfieldselector'] = $table->order_selector(array('fieldname'=>'order[]','value'=>'','compulsory'=>false));
- $r['weborderselector'] = $table->order_selector(array('fieldname'=>'weborderselector[]','value'=>$qinit['weborderselector'],
- 'compulsory'=>false,'random'=>false,'multiple'=>true));
- $oidit=$oidsrc;
- return XShell::toScreen1('section',$r);
- }
- function savequery($ar) {
- $p = new XParam($ar, array('level'=>1,'tplentry'=>'it','toc'=>'1','maxlevel'=>1));
- $tplentry = $p->get("tplentry");
- $oidsection = $p->get("oidsection");
- $weborderselector=$p->get('weborderselector');
- $hasselect=$p->get('hasselect'); // true si la section utilise le mode expert et que l'on sauve sans les droits root
- $labelin=$p->get('labelin');
- // recherche de l'item
- list($oidsrc,$oiddest,$oidtpl)=$this->_getOids($oidsection);
- // table des templates
- $rtpl=$this->_disp2Template($oidtpl);
- // table dans laquelle se trouvenet les donnes
- $table = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$rtpl['otab']->raw);
- if($hasselect){
- $rs=selectQuery("select * from ".$this->tname." where ITOID='$oidsection'");
- if($ors=$rs->fetch()){
- $qinit=unserialize($ors['QUERY']);
- $ar['_select']=$qinit['_select'];
- $rs->closeCursor();
- }else{
- $ar['_select']='';
- }
- }
- $st=$table->captureQuery($ar);
- $st['weborderselector']=$weborderselector;
- $st['labelin']=$labelin;
- $r=addslashes(serialize($st));
- updateQuery("UPDATE ".$this->tname." SET QUERY='$r' where ITOID='$oidsection'");
- $setup=$p->get("setup");
- updateQuery("UPDATE ".$this->tname." set KOIDTPL='$setup' where ITOID='$oidsection'");
- $ar["oidit"]=$oidsrc;
- }
- /// insertion d'une nouvelle section
- function insertsection($ar=NULL) {
- $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
- $tplentry = $p->get("tplentry");
- $oidit = $p->get("oidit");
- $lang = XShell::getLangData();
- $oidtpl=$p->get("oidtpl");
- $tabletpl = Kernel::getTable($oidtpl);
- $rs=selectQuery("select * from $tabletpl where KOID='$oidtpl' AND LANG='$lang'");
- if($o1=$rs->fetch()) {
- $tabledst = $o1['tab'];
- $position = $p->get("position")+1;
- $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
- $ar2=$ar;
- $ar2['tplentry']=TZR_RETURN_DATA;
- $ar2['LANG_DATA']=$lang;
- $r=$xst->procInput($ar2);
- $oidsection=$r["oid"];
- updateQuery("UPDATE ".$this->tname." SET ORDER1=ORDER1+1 where KOIDSRC='$oidit' ".
- " AND ORDER1 >= $position");
- $nitoid=self::newItOid();
- updateQuery("INSERT INTO ".$this->tname." SET KOIDSRC='$oidit', KOIDDST='$oidsection',".
- "KOIDTPL='$oidtpl', ORDER1='$position', QUERY=NULL, ITOID='$nitoid'");
- $this->_reorderSections($oidit);
- $rs=selectQuery("select * from ".$this->tname." where KOIDSRC='$oidit' ".
- "and KOIDDST='$oidsection' and KOIDTPL='$oidtpl'");
- $return = NULL;
- if($rs && $ors=$rs->fetch()) {
- $return = array("oid"=>$oidsection,"itoid"=>$ors['ITOID']);
- }
- $rs->closeCursor();
- return $return;
- }
- }
- /// generation d'une nouvelle cle dans la table de liaison
- protected function newItOid() {
- $id= substr(md5(uniqid(rand(), true)),0,40);
- return $id;
- }
- /// insertion d'une requete dans la page
- function insertquery($ar) {
- $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
- $oidtpl = $p->get("oidtpl");
- $lang = XShell::getLangData();
- $oidit = $p->get("oidit");
- $rs=selectQuery("select * from TEMPLATES where KOID='$oidtpl'");
- if($ors=$rs->fetch()) {
- $tabledst=$ors['tab'];
- $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
- $position = $p->get("position")+1;
- updateQuery("UPDATE ".$this->tname." SET ORDER1=ORDER1+1 where KOIDSRC='$oidit' ".
- " AND ORDER1 > $position");
- $val=serialize(array('pagesize'=>20,'UPD'=>'xxxx'));
- $nitoid=self::newItOid();
- updateQuery("INSERT INTO ".$this->tname." SET KOIDSRC='$oidit', KOIDDST='', KOIDTPL='$oidtpl', ORDER1='$position',QUERY='$val', ITOID='$nitoid'");
- }
- $rs->closeCursor();
- $this->_reorderSections($oidit);
- $this->editpage($ar);
- }
- function _getOids($oidsection) {
- $rs=selectQuery("SELECT * FROM ".$this->tname." WHERE ITOID='$oidsection'");
- $ors=array();
- if($ors=$rs->fetch()) {
- $oidtemplate=$ors['KOIDTPL'];
- $oiddest=$ors['KOIDDST'];
- $oidit=$ors['KOIDSRC'];
- return array($oidit,$oiddest,$oidtemplate);
- } else {
- return NULL;
- }
- }
- /// Change l'ordre et/ou le parent d'une section
- public function moveSection($ar) {
- $p = new XParam($ar, array());
- $oidsection=$p->get("oidsection");
- $oidit=$p->get("oidit");
- $dir=$p->get("dir");
- if(!isset($oidsection)) {
- $oidsection=$p->get("_itoidselected");
- foreach($oidsection as $oid => $foo) {
- $ar['oidsection']=$oid;
- $this->moveSection($ar);
- }
- return;
- }
- $new_p=$p->get("_dest");
- if(!empty($new_p)){
- if(!Kernel::isAKoid($new_p)) $new_p=$this->getOidFromAlias($new_p);
- }else{
- $new_p=$oidit;
- }
-
- // securite: dans tous les cas, si on a pas les droits d'ecriture sur la source
- // on ne peut ni modifier l'ordre des sections, ni changer une section de page
- if(!$this->secure($oidit, ':rw')) return;
- if(($new_p!=$oidit ) && !$this->secure($new_p, ':rw')) return;
- $this->_reorderSections($oidit);
- if($new_p!=$oidit) $this->_reorderSections($new_p);
- $o=countSelectQuery('select distinct ORDER1 from '.$this->tname.' where ITOID="'.$oidsection.'"');
- if($dir=="top") {
- $new_o=0;
- } elseif($dir=="bottom") {
- $new_o=999;
- } elseif($dir=="up") {
- $new_o=$o-1;
- updateQuery('UPDATE '.$this->tname.' set ORDER1='.$o.' where ORDER1='.$new_o.' AND KOIDSRC="'.$oidit.'"');
- } elseif($dir=="down") {
- $new_o=$o+1;
- updateQuery('UPDATE '.$this->tname.' set ORDER1='.$o.' where ORDER1='.$new_o.' AND KOIDSRC="'.$oidit.'"');
- } elseif($dir=="to") {
- $new_o=0;
- } elseif(!empty($dir)) {
- $new_o=countSelectQuery('select distinct ORDER1 from '.$this->tname.' where ITOID="'.$dir.'"')+1;
- updateQuery('UPDATE '.$this->tname.' set ORDER1=ORDER1+1 where ORDER1>='.$new_o.' AND KOIDSRC="'.$oidit.'"');
- } else{
- $new_o=0;
- }
- updateQuery('UPDATE '.$this->tname.' set ORDER1='.$new_o.',KOIDSRC="'.$new_p.'" where ITOID="'.$oidsection.'"');
- $this->_reorderSections($oidit);
- if($new_p!=$oidit) $this->_reorderSections($new_p);
- }
- public function delSection($ar) {
- $p = new XParam($ar, array());
- $oidsection=$p->get("oidsection");
- if(!isset($oidsection)) {
- $oidsection=$p->get("_itoidselected");
- if(is_array($oidsection)) {
- foreach($oidsection as $oidit => $foo) {
- $this->delSection(array("oidsection"=>$oidit));
- }
- }
- return;
- }
- list($oidit,$oiddest,$oidtemplate)=$this->_getOids($oidsection);
- $lang = $p->get('LANG_DATA');
- if(!empty($oiddest)) {
- $k = new Kernel;
- $k->data_forcedDel(array("oid"=>$oiddest, "action"=>"OK","_selectedok"=>"nok"));
- if($lang == TZR_DEFAULT_LANG) {
- updateQuery("delete FROM ".$this->tname." WHERE ITOID='$oidsection' ");
- }
- } else {
- updateQuery("delete FROM ".$this->tname." WHERE ITOID='$oidsection'");
- }
- $this->_reorderSections($oidit);
- }
- /// sauvegarde du contenu d'une section
- function savesection($ar) {
- $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
- $langs=$p->get('_langs');
- $oidsection=$p->get("oidsection");
- list($oidit,$oiddest,$oidtemplate)=$this->_getOids($oidsection);
- // verification des droits sur la page
- if(!$this->secure($oidit, ':rw')) return;
- $lang = $p->get('LANG_DATA');
- // Traitement des cas ou l'on veut sauver dans plusieurs langues
- $ar['_langs']=$this->getAuthorizedLangs($langs,$oidit,'savesection');
- $tabledst = Kernel::getTable($oiddest);
- $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
- $ar2=$ar;
- $ar2['tplentry']=TZR_RETURN_DATA;
- $ar2['oid']=$oiddest;
- $xst->procEdit($ar2);
- $setup=$p->get("setup");
- $rq="UPDATE ".$this->tname." set KOIDTPL='$setup' where ITOID='$oidsection'";
- updateQuery($rq);
- }
- function dupsection($ar) {
- $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
- $oidsection=$p->get("oidsection");
- list($oidit,$oiddest,$oidtemplate)=$this->_getOids($oidsection);
- $lang = $p->get('LANG_DATA');
- $tabledst = Kernel::getTable($oiddest);
- $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
- $r=$xst->procEditDup(array("oid"=>$oiddest,"tplentry"=>TZR_RETURN_DATA));
- $setup=$p->get("setup");
- $koiddup=$r['oid'];
- $n=self::newItOid();
- $rq="INSERT INTO ".$this->tname." set KOIDTPL='$setup',KOIDSRC='$oidit',KOIDDST='$koiddup',ITOID='$n'";
- updateQuery($rq);
- }
- function editCat($ar=NULL) {
- $p=new XParam($ar,array());
- $oid=$p->get('oid');
- $tplentry=$p->get('tplentry');
- $ar['tplentry']=TZR_RETURN_DATA;
- if(empty($ar['fmoid'])) $ar['fmoid']=$this->_moid;
- $r2=$this->_categories->edit($ar);
- if(!empty($this->cattemplate)) {
- $r1=$this->_templates->display(array('tplentry'=>TZR_RETURN_DATA,'_options'=>array('error'=>'return'),'oid'=>$this->cattemplate));
- XShell::toScreen1('cat_mitt',$r1);
- }
- if($this->_categories->fieldExists('tpl')) XShell::toScreen1('tple',$this->_templatesList(NULL,'page_site',$oidit));
- if(XShell::admini_mode() && $this->object_sec) {
- $acl=$GLOBALS['XUSER']->listObjectAccess($this, XShell::getLangData(),$oid);
- $r2=array_merge($r2, $acl);
- $sec=$GLOBALS['XUSER']->getObjectAccess($this, XShell::getLangData(),$oid);
- $sec=array_flip($sec[0]);
- $r2['object_sec']=$sec;
- }
- if ($this->linkin)
- $r2['linkin']=$this->linkin;
- if (XShell::admini_mode()) {
- $r2['_publishLevel'] = array_shift($this->secGroups('publish'));
- }
- return XShell::toScreen1($tplentry, $r2);
- }
- function editpage($ar=NULL) {
- return $this->viewpage($ar);
- }
- /**
- Genère une liste des section classer par date de maj pour génération d'un rss
- oids : Array : tableau d'oid des rubrique a traiter
- return : Array :tableau d'element rss title,txt,image et date
- */
- public function &rss($ar=NULL) {
- $p = new XParam($ar);
- $tplentry = $p->get('tplentry');
- if( empty($tplentry)) $tplentry = 'rss';
- $oids = $p->get('oids');
- if(!is_array($oids)){
- $oids = array($oids);
- }
- $res = array();
- $res['descr'] = '';
- $res['title'] = '';
- $res['items'] = array();
- foreach($oids as $k=>$v){
- $rub = $this->viewpage(array('oidit'=>$v,'alias'=>''));
- //dissocier le faite qu'il y ai 1 ou plusieurs rubriques
- if(count($oids) == 1) {
- $res['descr'] = strip_tags($rub['cat_mit']['odescr']->html);
- $res['title'] = $rub['cat_mit']['otitle']->html;
- }else{
- $res['descr'] .= $rub['cat_mit']['title']." ";
- $res['title'] = XIni::get('societe');
- }
- $res['UPD'] = '';
- foreach($rub['olines'] as $key => $section){
- $tk = $section['oUPD']->raw.'_'.$key;
- $res['items'][$tk] = array();
- $res['items'][$tk]['pubDate'] = date("D, d M Y H:i:s O", strtotime($section['oUPD']->raw));
- $res['items'][$tk]['UPD'] = $section['UPD'];
- if($section['oUPD']->raw > $res['UPD']) $res['UPD'] = $section['oUPD']->raw;
- $res['items'][$tk]['oid'] = $section['oid'];
- $res['items'][$tk]['rub'] = $rub['cat_mit']['oid'];
- if($section['odescription']->raw){
- $res['items'][$tk]['description'] = $section['description'];
- $res['items'][$tk]['odescription'] = $section['odescription'];
- }
- foreach($section['fields_object'] as $obj){
- if($obj->fielddef->ftype == 'XShortTextDef' && empty($res['items'][$tk]['title']) && !empty($section['o'.$obj->field]->raw)){
- $res['items'][$tk]['title'] = $section['o'.$obj->field]->html;
- $res['items'][$tk]['otitle'] = $section['o'.$obj->field];
- }elseif(($obj->fielddef->ftype == 'XTextDef' || $obj->fielddef->ftype == 'XRichTextDef') && empty($res['items'][$tk]['description']) && !empty($section['o'.$obj->field]->raw) ){
- $res['items'][$tk]['description'] = $section['o'.$obj->field]->html;
- $res['items'][$tk]['odescription'] = $section['o'.$obj->field];
- }elseif($obj->fielddef->ftype == 'XImageDef' && empty($res['items'][$tk]['img']) && !empty($section['o'.$obj->field]->raw) ){
- $res['items'][$tk]['img'] = $section['o'.$obj->field]->html;
- $res['items'][$tk]['oimg'] = $section['o'.$obj->field];
- }
- };
- }
- }
- rsort($res['items']);
- return XShell::toScreen1($tplentry,$res);
- }
- /** Browse les paragraphes d'une rubrique, tries selon leur numero d'ordre.
- Pour chaque paragraphe, display son contenu (document).
- Produit les structures suivantes :
- olines[indice paragraphe] = array produit par le display du contenu (document/thumb/photo/fichier).
- tlines[indice paragraphe] = template de visualisation du contenu (document/thumb/photo/fichier).
- */
- public function &viewpage($ar=NULL) {
- $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1,"first"=>"0",
- "nodecontent"=>true,"_nav"=>"1","autoxhtml"=>false,'_linkin'=>true,'keepalive'=>false));
- $tplentry = $p->get("tplentry");
- $alias = $p->get("alias");
- $defaultalias = $p->get("defaultalias");
- $erroralias = $p->get("erroralias");
- $authalias = $p->get("authalias");
- if(empty($authalias)) $authalias=$erroralias;
- $oidit = $p->get("oidit");
- $linkin = $p->get("_linkin");
- XLogs::debug('XModInfoTree::viewpage: start '.$alias.' '.$oidit);
- $result = XShell::from_screen($tplentry);
- // calcul des alias et des oidit
- if(empty($alias) && empty($oidit)) {
- $alias=$defaultalias;
- XLogs::debug('XModInfoTree::viewpage: falling back to '.$defaultalias);
- }
- if(empty($alias) && !Kernel::isAKoid($oidit)) { $alias=$oidit; $oidit="";}
- if(!empty($alias)) {
- $oidit=$this->getOidFromAlias($alias);
- }
- // dans le cas ou cette rubrique est un lien, recherche du lien
- if ($linkin) {
- $result['baseoidit'] = $oidit;
- $oidit=$this->_followLinkIn($oidit);
- }
- // verification dans le cas ou il y a un aliastop
- $aliastop=$p->get('pagetop');
- if(!empty($aliastop)) {
- $navig = $this->getPath($oidit); /* calcul des chemins d'acces */
- $aliasdown=$navig['aliasdown'];
- if(!in_array($aliastop, $aliasdown)) return $this->redirect404($ar);
- }
- $first = $p->get("first");
- $keepalive=$p->get('keepalive');
- // recherche des langues
- $LANG_DATA = XShell::getLangData($p->get("LANG_DATA"));
- $LANG_TRAD = XShell::getLangTrad($p->get("LANG_TRAD"),$p->get('_notrad'));
- // verification des droits sur la rubrique
- $class=get_class($this);
- $moid=$this->_moid;
- if(empty($this->object_sec) || $this->secure($oidit,'viewpage',null,$LANG_DATA)) {
- debug("XModinfoTree:auth:ok |".get_class($this).'|viewpage|'.$this->_moid."|$LANG_DATA|$oidit| user".XUser::get_current_user_uid());
- } else {
- XLogs::critical("XModinfoTree:auth:access denied |$class|viewpage|$moid|$LANG_DATA|$oidit| user ".XUser::get_current_user_uid());
- $ar['alias']=$authalias;
- return $this->viewpage($ar);
- }
- $pagesize = $p->get("pagesize");
- $total_estimated = $p->get("total");
- $toc=$p->get("toc");
- $maxlevel=$p->get("maxlevel");
- $nodecontent=$p->get("nodecontent");
- $_format=$p->get("_format");
- // Informations de la page
- $result['cat_mit']=$this->_categories->display(array('oid'=>$oidit,'_options'=>array('error'=>'return'),'tplentry'=>TZR_RETURN_DATA,'fallback'=>true));
- // Redirection 404 si la page n'existe pas
- if(!XShell::admini_mode() && $alias!='error404' && !is_array($result['cat_mit'])) return $this->redirect404($ar);
- // date de derniere mise a jour de la page
- $lastpageupdate=$result["cat_mit"]['oUPD'];
- if($this->_categories->fieldExists('tpl')) {
- $r1=&$this->_templates->rDisplay($result["cat_mit"]["otpl"]->raw, array(), false, $LANG_DATA, XShell::getLangUser(),
- array('_charset'=>$_REQUEST['_charset']));
- if(is_array($r1)) {
- $result["cat_mit"]["otpl"]=&$r1['odisp'];
- }
- }
- // dans le cas ou on trouve une taille de page dans la rubrique a afficher, cette taille est prioritaire
- if(empty($pagesize)){
- if(!empty($result['cat_mit']['opgz']->raw)) $pagesize=$result['cat_mit']['opgz']->raw;
- else{
- $pagesize=XIni::get('xmodinfotree_pagesize');
- if(empty($pagesize)) $pagesize=99;
- }
- }
- $cond = 'KOIDSRC="'.$oidit.'" ';
- if(!$nodecontent) {
- $cond="";
- $oidits=$this->getSubCats($oidit, $LANG_DATA);
- foreach($oidits as $i=>$oid1) $cond.='KOIDSRC= "'.$oid1.'" OR ';
- $cond.="KOIDSRC= '$oid1'";
- }
- $rs=selectQuery('SELECT * FROM '.$this->tname.' WHERE '.$cond.' ORDER BY ORDER1');
- // On regarde si on demande un oid particulièr pour définir le first en automatique (oidsec : oid d'une fiche d'une rubrique dynamique)
- $oidsec=$p->get('oidsec');
- if(!XShell::admini_mode() && !empty($oidsec) && $rs->rowCount()>0){
- $myfirst = 0;
- $fnd = false;
- $tpldatas=array();
- while(($ors1=$rs->fetch()) && !$fnd) {
- $query_1 = $ors1['QUERY'];
- $oiditd_1 = $ors1['KOIDDST'];
- $oidittpl_1 = $ors1['KOIDTPL'];
- if(!isset($tpldatas[$oidittpl_1])) {
- $tpl=&$this->_disp2Template($oidittpl_1);
- if(is_array($tpl)) $tpldatas[$oidittpl_1]=&$tpl;
- else $tpldatas[$oidittpl_1]=NULL;
- }
- // on regarde si on doit generer en automatique cette section
- if($tpldatas[$oidittpl_1]==NULL) continue;
- $tabledst = $tpldatas[$oidittpl_1]['otab']->raw;
- $moddest = $tpldatas[$oidittpl_1]['omodidd']->raw;
- if(empty($xsts[$tabledst])) {
- if(XSystem::tableExists($tabledst))
- $xsts[$tabledst]=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
- else
- continue;
- }
- $xst = &$xsts[$tabledst];
- $mymoddest=NULL;
- if(!empty($moddest)) {
- $mymoddest=XModule::objectFactory($moddest);
- }
- $sessid='queryobject'.$oidit;
- if(empty($oiditd_1)) {
- $query2_1['tplentry']=TZR_RETURN_DATA;
- $query2_1['LANG_DATA']=$LANG_DATA;
- $query2_1['selectedfields']=array();
- $query2_1['first']=0;
- $query2_1['searchmode']='simple';
- $query2_1=unserialize($query_1);
- // on a garde en session les parametres
- if(issetSessionVar($sessid)) {
- $query2_1=getSessionVar($sessid)+$query2_1;
- }
- $qures=&$xst->procQuery($query2_1);
- foreach($qures['lines_oid'] as $krs => $vrs){
- if($vrs == $oidsec){
- $first = $myfirst;
- $fnd = true;
- break;
- }else $myfirst++;
- }
- }else{
- $myfirst++;
- }
- }
- $rs->closeCursor();
- $rs=selectQuery('SELECT * FROM '.$this->tname.' WHERE '.$cond.' ORDER BY ORDER1');
- }
- $o=array();
- $itoid=array();
- $total = $rs->rowCount();
- $t=array();
- $order1=array();
- $query2=NULL;
- $xsts=array();
- $tpldatas=array();
- $ot=array();
- $idx = 0;
- $ors=array();
- $idx2=0;
- while($rs && ($ors=$rs->fetch()) && ($idx < ($first+$pagesize))) {
- XLogs::debug("[section] viewpage $idx");
- $query = $ors['QUERY'];
- $oiditd = $ors['KOIDDST'];
- $oidittpl = $ors['KOIDTPL'];
- if(!isset($tpldatas[$oidittpl])) {
- $tpl=&$this->_disp2Template($oidittpl);
- if(is_array($tpl)) $tpldatas[$oidittpl]=&$tpl;
- else $tpldatas[$oidittpl]=NULL;
- }
- // on regarde si on doit generer en automatique cette section
- if($tpldatas[$oidittpl]==NULL) continue;
- $tabledst = $tpldatas[$oidittpl]['otab']->raw;
- $moddest = $tpldatas[$oidittpl]['omodidd']->raw;
- if(empty($xsts[$tabledst]) && !empty($tabledst)) {
- if(XSystem::tableExists($tabledst))
- $xsts[$tabledst]=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
- else
- continue;
- }
- if(!empty($tabledst)) {
- $xst = &$xsts[$tabledst];
- $mymoddest=NULL;
- if(!empty($moddest)) {
- $mymoddest=XModule::objectFactory($moddest);
- }
- }
- $sessid='queryobject'.$oidit;
- // Section de type fonction
- if(empty($oiditd) && $tpldatas[$oidittpl]['ogtype']->raw=='function'){
- $ot=$this->viewFunction($oidit,$oidittpl,$ors['ITOID'],$query);
- // Si pas de droit et qu'on est sur la page d'edition des sections, on remplace le template par le template affichant un message d'information
- if($ot===false && $idx>=$first && XShell::admini_mode() && XShell::getTemplate()=='xmodinfotree/viewpage.html'){
- $idx++;
- $o[$idx2]=array('_functionparams'=>1);
- $itoid[$idx2]=$ors['ITOID'];
- $t[$idx2]=&$this->_disp2Template('TEMPLATES:UNAUTH');
- $order1[$idx2]=$ors['ORDER1'];
- $idx2++;
- }elseif(is_array($ot) && $idx>=$first) {
- $idx++;
- $o[$idx2]=$ot;
- $itoid[$idx2]=$ors['ITOID'];
- $t[$idx2]=$tpldatas[$oidittpl];
- $order1[$idx2]=$ors['ORDER1'];
- $idx2++;
- }elseif(is_array($ot)) {
- $idx++;
- }
- }elseif(empty($oiditd)) {
- // generation des infos de visualisation du paragraphe
- // cas ou il s'agit d'une requete
- // on realise la requete et on developpe
- // Gestion de l'ordre : soit order = champ asc/desc, soit order=champ et _order=asc/desc
- $qorder=NULL;
- $order=$p->get('order');
- $_order=$p->get('_order');
- $forder=explode(' ',$order);
- $forder=$forder[0];
- $query2=unserialize($query);
- if(!empty($forder)){
- if(in_array($forder,$query2['weborderselector'])){
- $query2['order']=$order;
- if(!empty($_order)) $query2['order'].=' '.$_order;
- $qorder=$query2['order'];
- }
- }
- if($first==0 && !$keepalive) clearSessionVar($sessid);
- if(issetSessionVar($sessid)) {
- $query2=$query2+getSessionVar($sessid);
- }
- $query2['tplentry']=TZR_RETURN_DATA;
- $query2['LANG_DATA']=$LANG_DATA;
- $query2['selectedfields']=array('KOID');
- $query2['first']=0;
- $query2['searchmode']='simple';
- $query2['fmoid'] = $tpldatas[$oidittpl]['omodidd']->raw;
- // prepararation du formulaire interactif lorsqu'il y a une requete parametree
- $dynquery=$xst->prepareQuery($query2);
- $parametrized=$dynquery['parametrized'];
- // on a garde en session les parametres
- if(issetSessionVar($sessid)) {
- $query2=getSessionVar($sessid)+$query2;
- if(!empty($qorder)) $query2['order']=$qorder;
- }
- // Si l'ordre est aléatoire, on fourni un entier à rand pour que la pagination... garde le meme ordre
- if(substr($query2['order'],0,6)=='RAND()') $query2['order']='RAND('.rand(1,100000).')';
- // execution de la requete. query2 contient les donnees de
- // requete interactive ainsi que les donnees de requete stockee
- // on recupere d'abord le filtre du module si il existe
- if( !empty($mymoddest) ){
- $mymodfilter = $mymoddest->getFilter();
- if($mymodfilter) $query2['_filter'] = $mymodfilter;
- }
- $queryres=&$xst->procQuery($query2);
- if(!empty($queryres['order'])) $order=$queryres['order'];
- foreach($query2['weborderselector'] as $f){
- if(!empty($f)) $dynquery['weborderselector'][]=array('field'=>$f,'label'=>&$xst->desc[$f]->label,'selected'=>($f==$order));
- }
- // on ne met quelque chose en session que si cela est necessaire
- if($parametrized){
- $ok=false;
- foreach($queryres['queryobject'] as $tmp){
- if(!empty($tmp)){
- $ok=true;
- break;
- }
- }
- if($ok) setSessionVar($sessid,$queryres['queryobject']);
- }
- $ntmp=count($queryres['lines_oid']);
- if($ntmp>0) $total+=$ntmp-1;
- $boq=true;
- $qdisp=1;
- for($q=0;($q<$ntmp) && ($idx < ($first+$pagesize));$q++) {
- if($idx>=$first) {
- $oidt1=$queryres['lines_oid'][$q];
- if(is_object($mymoddest)) {
- $ot=$mymoddest->display(array('oid'=>$oidt1, 'tplentry'=>TZR_RETURN_DATA,'_format'=>$_format,
- '_options'=>array('error'=>'return'),'_dynquerymode'=>true,
- '_cacheobject'=>'vwp'.$this->_moid,'ssmoid'=>'all'));
- } else {
- $ot=$xst->display(array('oid'=>$oidt1, 'tplentry'=>TZR_RETURN_DATA,'_format'=>$_format,
- '_options'=>array('error'=>'return'),'_dynquerymode'=>true,
- '_cacheobject'=>'vwp'.$this->_moid));
- }
- }
- if(is_array($ot) && ($idx>=$first)) {
- if((($first+$pagesize-1)==$idx)||($q==($ntmp-1))) {
- $ot['_eoq']=true;
- $ot['_total']=$ntmp;
- $ot['_dynquery']=$dynquery;
- }
- if($boq) {
- $ot['_boq']=true;
- $ot['_dynquery']=$dynquery;
- $ot['_total']=$ntmp;
- $boq=false;
- }
- $ot['_type']='query';
- $ot['_q']="$q";
- $ot['_qdisp']=$qdisp;
- $o[$idx2]=$ot;
- if($ot['oUPD']->raw>$lastpageupdate->raw) {
- $lastpageupdate=$ot['oUPD'];
- }
- $t[$idx2]=&$tpldatas[$oidittpl];
- $itoid[$idx2] = $ors['ITOID'];
- $order1[$idx2] = $ors['ORDER1'];
- $qdisp++;
- $idx2++;
- }
- $idx++;
- }
- if($ntmp<=0) {
- $ot['_type']='query';
- $ot['_dynquery']=$dynquery;
- $t[$idx2]=&$tpldatas[$oidittpl];
- $ot['_q']='0';
- $ot['_empty']=true;
- $ot['_boq']='0';
- $ot['_total']='0';
- $o[$idx2]=$ot;
- if($ot['oUPD']->raw>$lastpageupdate->raw) {
- $lastpageupdate=$ot['oUPD'];
- }
- $itoid[$idx2] = $ors['ITOID'];
- $order1[$idx2] = $ors['ORDER1'];
- $idx2++;
- } else {
- $o[$idx2-1]['eoq']=true;
- }
- }
- // car ou il s'agit d'un paragraphe isole
- else {
- $ot=NULL;
- if(!empty($LANG_TRAD) && ($LANG_TRAD!=$LANG_DATA)) {
- $ot=&$xst->display(array('oid'=>$oiditd, 'tplentry'=>TZR_RETURN_DATA,'_format'=>$_format,
- 'LANG_DATA'=>$LANG_TRAD,
- '_cacheobject'=>$this->_moid,
- '_options'=>array('error'=>'return')));
- $ot2=&$xst->display(array('oid'=>$oiditd, 'tplentry'=>TZR_RETURN_DATA,
- 'LANG_TRAD'=>'',
- '_cacheobject'=>$this->_moid,
- '_options'=>array('error'=>'return')));
- $ot['_type']='section';
- $ot2['_type']='section';
- } else {
- $ot=&$xst->display(array('oid'=>$oiditd, 'tplentry'=>TZR_RETURN_DATA,'_format'=>$_format,
- '_cacheobject'=>$this->_moid,
- '_options'=>array('error'=>'return')));
- $ot['_type']='section';
- }
- if(is_array($ot) && $idx>=$first) {
- $idx++;
- $o[$idx2]=$ot;
- if($ot['oUPD']->raw>$lastpageupdate->raw) {
- $lastpageupdate=$ot['oUPD'];
- }
- $itoid[$idx2] = $ors['ITOID'];
- $t[$idx2] = $tpldatas[$oidittpl];
- $order1[$idx2] = $ors['ORDER1'];
- $idx2++;
- if(!empty($ot2)) {
- $o[$idx2]=$ot2;
- $itoid[$idx2] = $ors['ITOID'];
- $t[$idx2] = $tpldatas[$oidittpl];
- $order1[$idx2] = $ors['ORDER1'];
- $idx2++;
- }
- }elseif(is_array($ot)) {
- $idx++;
- }
- }
- }
- // Ajout des packs requis par les TEMPLATES au header
- foreach ($t as $template) {
- if (empty($template['opacks']->raw)) continue;
- $packs_to_autoload = preg_split('/[^\w]+/', $template['opacks']->raw);
- foreach ($packs_to_autoload as $packname) {
- $GLOBALS['TZR_PACKS']->addNamedPack($packname);
- }
- }
- if(!empty($this->cattemplate)) {
- $r1=&$this->_templates->display(array('tplentry'=>TZR_RETURN_DATA,'fallback'=>'true',
- '_options'=>array('error'=>'return'),
- 'oid'=>$this->cattemplate));
- if(is_array($r1)) XShell::toScreen1('cat_mitt',$r1);
- }
- if($toc) {
- $this->home(array('oidtop'=>$oidit,'tplentry'=>'ssrubs','do'=>'showtree','maxlevel'=>$maxlevel));
- }
- $result['query'] = $query2;
- $result['oidit']=$oidit;
- $result['itoid']=$itoid;
- $result['olines']=$o;
- $result['first']=$first;
- $result['last']=$total;
- $result['firstnext']=''.($first+$pagesize).'';
- $result['firstprev']=''.($first-$pagesize>=0?($first-$pagesize):$first).'';
- $result['total']=$total;
- $result['order']=$order1;
- $result['tlines']=$t;
- $result['pages_mode']='';
- $result['moid']=$this->_moid;
- if (XShell::admini_mode()) {
- $result['_editCat'] = array_shift($this->secGroups('editCat'));
- $result['_editLevel'] = array_shift($this->secGroups('editpage'));
- $result['_publishLevel'] = array_shift($this->secGroups('publish'));
- }
- if((@$_SERVER['REQUEST_METHOD']=='POST') || (@$_REQUEST['nocache']=='1')) {
- $result['pages_mode']='&nocache=1';
- }
- $result['lastpageupdate']=$lastpageupdate;
- // Met à jour la date de dernière révision si besoin
- if(!empty($result["cat_mit"]['olastrevision']) && $lastpageupdate->raw>$result["cat_mit"]['olastrevision']->raw){
- updateQuery('update '.$this->table.' set UPD=UPD,lastrevision="'.$lastpageupdate->raw.'" where KOID="'.$oidit.'" and LANG="'.$LANG_DATA.'"');
- }
- if($pagesize<$total) {
- $p1=0;
- $pages=array();
- for($i=0;$i<$total;$i+=$pagesize){
- $pages[$p1++]=$i;
- if($i==$first) $result['actpage']=$p1;
- }
- $result['pages']=$pages;
- $result['lastpage']=$p1;
- $result['firstlastpage']=$pages[$p1-1];
- }else{
- $result['actpage']=1;
- $result['lastpage']=1;
- }
- if($p->get('_nav')==1) $result['nav']=$this->_getNavigInfo($oidit);
- if($p->get('_path')==1) $result['path']=$this->getPath($oidit);
- XLogs::debug("XModInfoTree::viewpage: end $alias $oidit");
- return XShell::toScreen1($tplentry,$result);
- }
- /// Retourne les données d'une section dans une rubrique
- function viewsection($ar=NULL){
- $p=new XParam($ar);
- $tplentry=$p->get('tplentry');
- $oidit=$p->get('oidit');
- $alias=$p->get('alias');
- $oidsection=$p->get('oidsection');
- $LANG_DATA = XShell::getLangData($p->get("LANG_DATA"));
- if(!empty($alias)) $oidit=$this->getOidFromAlias($alias);
- $rs=selectQuery('select * from '.$this->tname.' WHERE ITOID="'.$oidsection.'" AND KOIDSRC="'.$oidit.'"');
- // Verifie que la section est bien dans la page demandée
- if(!$rs->rowCount()) securityWarning('XModInfoTree::viewsection: trying to display section '.$oidsection.' not in page '.$oidit);
- // Verifie les droits de la page
- if(!$this->secure($oidit,'viewsection',$u=NULL,$LANG_DATA)) {
- XLogs::critical('XModInfoTree::viewsection:access denied viewsection|'.$this->_moid.'|'.$LANG_DATA.'|'.$oidit.'| user '.XUser::get_current_user_uid());
- die();
- }
- $o=$itoid=$t=$result=array();
- // Infos de la page
- $result['cat_mit']=$this->_categories->display(array('oid'=>$oidit,'tplentry'=>TZR_RETURN_DATA));
- // Infos de la section
- $ors=$rs->fetch();
- $query=$ors['QUERY'];
- $oiditd=$ors['KOIDDST'];
- $oidittpl=$ors['KOIDTPL'];
- $tpl=&$this->_disp2Template($oidittpl);
- if(!$tpl) die();
- // Cas d'une section fonction
- if(empty($oiditd) && $tpl['ogtype']->raw=='function'){
- $ot=$this->viewFunction($oidit,$oidittpl,$ors['ITOID'],$query);
- if(empty($ot)) die();
- if(is_array($ot)) {
- $o[]=$ot;
- $itoid[]=$ors['ITOID'];
- $t[]=$tpl;
- }
- }
- $result['oidit']=$oidit;
- $result['itoid']=$itoid;
- $result['oidsection']=$oidsection;
- $result['olines']=$o;
- $result['tlines']=$t;
- $result['moid']=$this->_moid;
- return XShell::toScreen1($tplentry,$result);
- }
- /// Retourne les données d'une section de type fonction
- function &viewFunction($oidit,$oidittpl,$itoid,$query){
- $query2=unserialize($query);
- $moid=$query2['moid'];
- $function=$query2['function'];
- $UIParam_function='UIParam_'.$function;
- $UIView_function='UIView_'.$function;
- $module=XModule::objectFactory($moid);
- // Test les droits sur la fonction
- if($query2['__oid'] && !$module->secure($query2['__oid'],$function))
- return false;
- if(method_exists($module, $UIView_function)){
- $query2['oidit']=$oidit;
- $query2['itoid']=$itoid;
- $query2['_options']=array('local'=>1);
- $query2['tplentry']=TZR_RETURN_DATA;
- $ot=$module->$UIView_function($query2);
- $params=$query2;
- }else{
- if(!method_exists($module, $function) || !method_exists($module, $UIParam_function)) return NULL;
- $params=array('oidit'=>$oidit, '_options'=>array('local'=>1),'tplentry'=>true);
- $desc=$module->$UIParam_function();
- foreach($desc as $fn=>&$field){
- if(strpos($fn,'__')===0) $fn2=substr($fn,2);
- else $fn2=$fn;
- if(empty($query2[$fn])) continue;
- $params[$fn2]=$query2[$fn];
- if($field->multivalued && $field->get_fgender()=='Oid'){
- $params[$fn2]=explode('||',$params[$fn2]);
- }
- }
- $ot=$module->$function($params);
- }
- // Récupère les options de mise en page liées au TEMPLATE
- $options_values = (object) null;
- $xoptions = $this->getTemplateOptions($oidittpl, $itoid, $options_values);
- if (!is_null($xoptions)) {
- $xoptions->procDialog($options_values, $params['_tploptions']);
- $ot['_tploptions'] = (array) $options_values;
- }
- $ot['_functionparams']=array('function'=>$function,'moid'=>$query2['moid'],'params'=>$params,'modulename'=>$module->modulename);
- $ot['_type']='function';
- return $ot;
- }
- // recherche des info rubrique prec, suivant, top, etc...
- //
- protected function &_getNavigInfo($oidit) {
- $result=array();
- $published='';
- if(fieldExists($this->table, 'PUBLISH') && !XShell::admini_mode()) {
- $published=' AND PUBLISH="1" ';
- }
- $q = 'select distinct KOID,linkup,corder from '.$this->table.' where KOID="'.$oidit.'" '.$published;
- $rs=selectQuery($q);
- if($ors=$rs->fetch()) {
- $linkup=$ors['linkup'];
- $order=$ors['corder'];
- // recherche du next au meme niveau
- $q = 'select distinct KOID,linkup,corder from '.$this->table.' where '.
- "linkup='$linkup' and corder>'$order' $published order by corder";
- $rs=selectQuery($q);
- if($ors=$rs->fetch()) {
- $koidnext=$ors['KOID'];
- $r1=&$this->_categories->display(array('oid'=>$koidnext,'tplentry'=>TZR_RETURN_DATA,'_options'=>array('error'=>'return'), 'fallback'=>1));
- if(is_array($r1)) $result['next']=$r1;
- }
- // recherche du prev au meme niveau
- $q = 'select distinct KOID,linkup,corder from '.$this->table.' where '.
- "linkup='$linkup' and corder<'$order' $published order by corder";
- $rs=selectQuery($q);
- if($ors=$rs->fetch()) {
- $koidprev=$ors['KOID'];
- $r1=&$this->_categories->display(array('oid'=>$koidprev,'tplentry'=>TZR_RETURN_DATA,
- 'fallback'=>1,
- '_options'=>array('error'=>'return')));
- if(is_array($r1)) $result['prev']=$r1;
- }
- // recherche du up
- if(strlen($linkup)>1)
- $result['up']=&$this->_categories->display(array('oid'=>$linkup,'tplentry'=>TZR_RETURN_DATA, 'fallback'=>1));
- }
- return $result;
- }
- // rend la liste des oid ss categories
- //
- public function &getSubObjects($oid) {
- $stack=array($oid);
- $res=array();
- while(!empty($stack)) {
- $poped=array_pop($stack);
- if($poped!=$oid) array_push($res, $poped);
- $rs=selectQuery('SELECT DISTINCT KOID,alias FROM '.$this->table." WHERE linkup='$poped'");
- while($ors=$rs->fetch()) {
- array_push($stack, $ors['KOID']);
- }
- $rs->closeCursor();
- }
- return $res;
- }
- // rend la liste des ss categroies
- //
- public function getSubCats($oid, $lang, $level=1, $depth=9, $maxlevel=9) {
- if(!isset($oid)) {
- $query = $this->_categories->select_query(array('cond'=>array('linkup'=>array('=','NULL'))));
- } else {
- $query = $this->_categories->select_query(array('cond'=>array('linkup'=>array('=',$oid))));
- }
- $rcat=&$this->_categories->browse(array('selected'=>0,
- 'first'=>'0',
- 'select'=>$query,
- 'pagesize'=>1000,
- 'selectedfields'=>array('title','linkup'),
- 'order'=>'corder',
- 'tplentry'=>TZR_RETURN_DATA,
- 'header'=>'0','nocount'=>'1'));
- $OID[]=$oid;
- foreach($rcat['lines_oid'] as $i => $o) {
- $OID[]=$o;
- if($level < $depth) {
- $subOID = $this->getSubCats($o, $lang, $level+1, $depth);
- $OID=array_merge($OID,$subOID);
- }
- }
- return $OID;
- }
- /// rend l'oid de la poubelle
- protected function getTrashOid($createit=false) {
- // recherche de la poubelle
- $all=selectQueryGetOne('SELECT KOID FROM '.$this->table.' WHERE alias = "trash" and LANG="'.TZR_DEFAULT_LANG.'" LIMIT 1');
- $dest=$all['KOID'];
- // si la poubelle n'existe aps il faut la rajouter
- if(empty($dest) && $createit) {
- $ar1=array('title'=>XLabels::getSysLabel('general','trash','text'),
- 'alias'=>'trash',
- 'linkup'=>NULL,
- 'corder'=>'0');
- $r1=&$this->procInput($ar1);
- $dest=$r1['oid'];
- }
- return $dest;
- }
- /// rend la liste des aliases de ce module
- function getAliases() {
- $lang=XShell::getLangData();
- $set = selectQueryGetAll('SELECT DISTINCT KOID,alias FROM '.$this->table." WHERE LANG='$lang'");
- $setall=array();
- foreach($set as $i=>&$al) {
- if(!empty($al['alias'])) $setall[$al['KOID']]=$al['alias'];
- }
- return $setall;
- }
- /// rend l'oid correspondant à l'alias
- public function getOidFromAlias($alias) {
- if(Kernel::isAKoid($alias) && Kernel::objectExists($alias)) return $alias;
- if(isset($alias)) {
- $query=$this->_categories->select_query(array('cond'=>array('alias'=>array('=',$alias))));
- $rs=selectQuery($query);
- $oidit=NULL;
- if(!$rs) return NULL;
- while($ors=$rs->fetch()) {
- $oidit=$ors['KOID'];
- }
- $rs->closeCursor();
- return $oidit;
- }
- return NULL;
- }
- public function usedTables(){
- return array($this->table,$this->tname,'TEMPLATES');
- }
- public function usedMainTables(){
- return array($this->table);
- }
- public function usedBoids(){
- return array($this->_categories->getBoid());
- }
- function goto1($ar=NULL) {
- $p = new XParam($ar,array());
- $oid=$p->get('oid');
- $url=$GLOBALS['TZR_SESSION_MANAGER']::admin_url(true,false);
- $moid=$this->_moid;
- header("Location: {$url}moid=$moid&template=xmodinfotree/viewpage.html&oidit=$oid&function=editpage&tplentry=it");
- }
- function _mkInline(&$r) {
- }
- /// rend vrai si l'alias pass en parametre est protege
- public function aliasIsProtected($alias) {
- return false;
- }
- public function export($ar) {
- $r1=&$this->home(array('tplentry'=>TZR_RETURN_DATA,'do'=>'showtree'));
- foreach($r1['lines_oid'] as $i=>$oid) {
- $R2=&$this->viewpage(array('tplentry'=>TZR_RETURN_DATA, 'oidit'=>$oid));
- $r1['lines__it'][$i]=$R2['olines'];
- $r1['lines__tt'][$i]=$R2['tlines'];
- }
- XShell::toScreen1('mit', $r1);
- }
- public function apply($fsection) {
- $r1=$this->home(array('tplentry'=>TZR_RETURN_DATA,'do'=>'showtree'));
- foreach($r1['lines_oid'] as $oid) {
- $R2=$this->viewpage(array('tplentry'=>TZR_RETURN_DATA, 'oidit'=>$oid));
- $fsection($this, $R2['cat_mit']); /* conversion de la rubrique */
- foreach($R2['olines'] as $section) {
- $fsection($this, $section);
- }
- unset($R2);
- }
- }
- /**
- * Exporte la page au format PDF
- * @param ar Options de la fonction viewpage avec un paramètre 'action'
- * supplémentaire qui vaut 'display' par défaut pour renvoyer
- * directement un fichier à l'utilisateur ou 'generate' pour
- * seulement générer le fichier et renvoyer son nom.
- * @return String Nom du fichier généré
- */
- public function exportPdf($ar) {
- $p = new XParam($ar,array(
- 'pagesize' => 999,
- 'action' => 'display' // 'generate' ou 'display'
- ));
- $ar['pagesize'] = $p->get('pagesize');
- $ar['tplentry'] = 'it';
- $tpldata['it'] = $this->viewpage($ar);
- $xt = new XTemplate('xmodinfotree/exportPdf.html');
- $labels = $GLOBALS['XSHELL']->labels->get_labels(array('selectors'=>array('global'),'local'=>true));
- $xt->set_glob(array('labels'=>&$labels));
- $rawData = array('it_prop'=>$this);
- $content = $xt->parse($tpldata,$rawData,NULL);
- $pdfname = $tpldata['it']['cat_mit']['oalias']->html.'.pdf';
- $tmpname = princeTidyXML2PDF(null,$content);
- switch ($p->get('action')) {
- case 'generate' :
- $newname = dirname($tmpname).'/'.$pdfname;
- return @rename($tmpname,$newname) ? $newname : $tmpname;
- case 'display' :
- header('Content-type: application/pdf');
- header('Content-disposition: attachment; filename='.$pdfname);
- $size = filesize($tmpname);
- header('Accept-Ranges: bytes');
- header('Content-Length: '.$size);
- readfile($tmpname);
- unlink($tmpname);
- exit(0);
- }
- }
- public function &browse($ar) {
- return $this->_categories->browse($ar);
- }
- public function &query($ar) {
- return $this->_categories->query($ar);
- }
- public function &procQuery($ar) {
- $p=new XParam($ar, array());
- $tplentry=$p->get('tplentry');
- $ar1=$ar;
- $ar1['tplentry']=TZR_RETURN_DATA;
- $ar1['selectedfields']=array('UPD','PUBLISH','title','alias');
- $r=&$this->_categories->procQuery($ar1);
- $r['objects_sec']=$GLOBALS['XUSER']->getObjectsAccess($this, XShell::getLangData(), $r['lines_oid']);
- if($tplentry!=TZR_RETURN_DATA) {
- $this->browse_actions($r);
- }
- return XShell::toScreen1($tplentry, $r);
- }
- public function browse_actions(&$r) {
- $self=$GLOBALS['TZR_SESSION_MANAGER']::complete_self();
- $self.='&moid='.$this->_moid.'&oidit=<oid>&tplentry=it&function=';
- if(!is_array($r['lines_oid'])) return;
- $approved=XLabels::getSysLabel('general','approved');
- $not_approved=XLabels::getSysLabel('general','not_approved');
- $viewico = XLabels::getSysLabel('general','view');
- $viewtxt = XLabels::getSysLabel('general','view','text');
- $editico = XLabels::getSysLabel('general','edit');
- $edittxt = XLabels::getSysLabel('general','edit','text');
- $browseico = XLabels::getSysLabel('general','browse');
- $browsetxt = XLabels::getSysLabel('general','browse','text');
- foreach($r['lines_oid'] as $i =>$oid) {
- $self1=str_replace('<oid>',$oid,$self);
- $self1=str_replace('=it','=mit',$self1);
- $self1=str_replace('oidit','oid',$self1);
- $r['actions'][$i][0]='<a class="cv8-ajaxlink" href="'.$self1.'home&'.
- 'template=xmodinfotree/index.html&do=add" title="'.$browsetxt.'">'.$browseico.'</a>';
- $r['actions_label'][$i][0]=$viewico;
- $r['actions_url'][$i][0]=$self1.'home&template=xmodinfotree/index.html&do=add';
- $self1=str_replace('<oid>',$oid,$self);
- $r['actions'][$i][1]='<a class="cv8-ajaxlink" href="'.$self1.'viewpage&'.
- 'template=xmodinfotree/viewpage.html" title="'.$viewtxt.'">'.$viewico.'</a>';
- $r['actions_label'][$i][1]=$viewico;
- $r['actions_url'][$i][1]=$self1.'viewpage&template=xmodinfotree/viewpage.html';
- if(!empty($r['objects_sec'][$i]['rw'])) {
- $r['actions'][$i][2]='<a class="cv8-ajaxlink" href="'.$self1.'editpage&'.
- 'template=xmodinfotree/viewpage.html" title="'.$edittxt.'">'.$editico.'</a>';
- $r['actions_url'][$i][2]=$self1.'editpage&template=xmodinfotree/editpage.html';
- $r['actions_label'][$i][2]=$editico;
- }
- }
- }
- /// rend la date de derniere mise a jour de la page dont l'oid est fourni
- protected function lastUpdate($oid) {
- $rs=selectQuery('SELECT UPD,KOID FROM '.$this->table.' WHERE KOID="'.$oid.'" ORDER BY UPD DESC LIMIT 1');
- if(!$rs || !$ors=&$rs->fetch()) return NULL;
- $lastupd=$ors['UPD'];
- $lastoid=$ors['KOID'];
- // recherche de toutes les sections de la page
- $all=selectQueryGetAll('SELECT KOIDDST FROM '.$this->tname.' where KOIDSRC="'.$oid.'" AND KOIDDST != ""');
- foreach($all as $ors) {
- // recherche de la derniere mise a jour pour cette section
- $upd=XLogs::getLastUpdate($ors['KOIDDST'], NULL, true);
- if(!empty($upd) && ($upd['dateupd']>$lastupd)) {
- $lastupd=$upd['dateupd'];
- $lastoid=$ors['KOIDDST'];
- }
- }
- $update=XLogs::getLastUpdate($lastoid, NULL, true);
- return $update;
- }
- protected function _lasttimestamp() {
- $rs=selectQuery('SELECT MAX(UPD) AS UPD FROM '.$this->table.'');
- $ors=&$rs->fetch();
- $lastupd=$ors['UPD'];
- $rs=selectQuery('SELECT DISTINCT KOIDDST FROM '.$this->tname.' WHERE KOIDDST != ""');
- $tables=array();
- while($rs && ($ors=&$rs->fetch())) {
- $tables[]=Kernel::getTable($ors['KOIDDST']);
- }
- $tables_u=array_unique($tables);
- foreach($tables_u as $table) {
- if(empty($table)) continue;
- $ors=selectQueryGetOne('SELECT MAX('.$table.'.UPD) AS UPD FROM '.$table.','.$this->tname.' WHERE '.
- $table.'.KOID='.$this->tname.'.KOIDDST');
- if(!empty($ors) && ($lastupd < $ors['UPD'])) $lastupd=$ors['UPD'];
- }
- return $lastupd;
- }
- /// rend la liste des rubriques modifiees depuis ts et jusqu'a timestamp
- protected function _whatsNew($ts,$user, $group=NULL, $specs=NULL,$timestamp=NULL) {
- list($koid,$subdir) = explode(';',$specs);
- // recherche dans lines_oid de la liste des rubriques concernees par l'abonnement
- if($subdir) $r1=&$this->home(array('tplentry'=>TZR_RETURN_DATA,'do'=>'showtree','myself'=>true,'oidtop'=>$koid));
- else $r1=array('lines_oid'=>array($koid));
- // recherche de la date de derniere mise a jour pour cahcune des rubriques cocnernees
- $r1['lines_upd']=array();
- foreach($r1['lines_oid'] as $i=>$oid) {
- $r1['lines_upd'][$i]=$this->lastUpdate($oid);
- }
- $txt='';
- foreach($r1['lines_oid'] as $i => $oid) {
- if(($r1['lines_upd'][$i]['dateupd']>$ts) && ($r1['lines_upd'][$i]['dateupd']<$timestamp)) {
- $url=$GLOBALS['TZR_SESSION_MANAGER']::admin_url(true,false).'&moid='.$this->_moid.'&function=goto1&oid='.$oid.'&tplentry=br&template=xmodtable/view.html&_direct=1';
- $when=$r1['lines_upd'][$i]['dateupd'];
- $who=$r1['lines_upd'][$i]['usernam'];
- $title=$this->getPathString($oid);
- $txt.='<li><a href="'.$url.'">'.$title.'</a> ('.$when.','.$who.')</li>';
- }
- }
- return $txt;
- }
- function preSubscribe($ar=NULL) {
- $p=new XParam($ar,array());
- $oid=$p->get("oid");
- $tplentry=$p->get("tplentry");
- $subdir=$p->get("subdir");
- $br=&$this->viewpage(array('tplentry'=>TZR_RETURN_DATA, 'oidit'=>$oid));
- list($acl_user, $acl_grp)=XUser::getUsersAndGroups();
- XShell::toScreen1('users',$acl_user);
- XShell::toScreen1('grps',$acl_grp);
- return XShell::toScreen1($tplentry, $br);
- }
- function subscribe($ar=NULL) {
- $p=new XParam($ar,array());
- $oid=$p->get("oid");
- $subdir=$p->get("subdir");
- $uid=$p->get("uid");
- if(empty($uid)) $uid=XUser::get_current_user_uid();
- if(empty($subdir)) $subdir="0";else $subdir="1";
- $xmodsub = new XModSub(array('interactive'=>false));
- $xmodsub->addSub(array($uid), $this->_moid, $oid.';'.$subdir);
- }
- // rend une chaine qui représente l'abonnement
- //
- function _getSubTitle($oid) {
- $rs=selectQuery("select * from OPTS where KOID='$oid'");
- if($rs && ($ors=$rs->fetch())) {
- list($koid,$subdir)=explode(';',$ors['specs']);
- if(Kernel::objectExists($koid)) {
- // generation du libelle pour la rubrique
- $title=$this->getPathString($koid);
- $url=$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&moid='.$this->_moid.'&_function=goto1&oid='.$koid.'&tplentry=br';
- if(!empty($subdir)) {
- $subdir=' et sous rubriques';
- } else $subdir='';
- return '<A HREF="'.$url.'">'.$title.'</A> '.$subdir;
- } else {
- // l'abonnement concerne une donnee qui n'existe plus. on le supprimer
- updateQuery("delete from OPTS where KOID='$oid'");
- }
- }
- return NULL;
- }
- /// Prepare l'importation d'un fichier odt
- function preImportFromODT($ar=NULL){
- }
- /// importe un fichier odt
- function importFromODT($ar=NULL){
- $p=new XParam($ar,NULL);
- $linkup=$p->get('linkup');
- $rep=TZR_TMP_DIR.'odt_'.uniqid().'/';
- mkdir($rep);
- mkdir($rep.'in/');
- mkdir($rep.'out/');
- rename($_FILES['odtfile']['tmp_name'],$rep.'in/odtfile.odt');
- require_once('add-ons/odt2xhtml/odt2seolan.php');
- $xhtml2seolan = new xhtml2seolan(
- $this,
- $rep, 'odtfile.odt',
- array('txt' => array(
- 'tploid' => $this->odttpltxt,
- 'txtfield' => $this->odttxtfield,
- 'titlefield' => $this->odttxttitlefield),
- 'img' => array(
- 'tploid' => $this->odttplimg,
- 'imgfield' => $this->odtimgfield)),
- $linkup);
- $xhtml2seolan->import();
- XDir::unlink($rep);
- XShell::toScreen2('','message',XLabels::getSysLabel('xmodinfotree','odt_importok','text'));
- }
- /// Définit si le cache des droits doit être activé ou pas.
- public function rightCacheEnabled(){
- if($this->object_sec) return true;
- return false;
- }
- /// Retourne le parent direct de chaque oid passé en paramètre
- public function getParentsOids($oids){
- $ret=array();
- foreach($oids as $oid){
- if(!$oid) continue;
- $parent=selectQueryGetOne('select linkup from '.$this->table.' WHERE KOID="'.$oid.'" limit 1');
- if(!$parent || !$parent['linkup']) $ret[]='';
- else $ret[]=$parent['linkup'];
- }
- return $ret;
- }
- /// Redirige vers une page d'erreur 404
- function redirect404($ar=NULL){
- $p=new XParam($ar,NULL);
- $erroralias=$p->get('erroralias');
- header("HTTP/1.1 404 Not Found");
- if(empty($erroralias)) {
- header('Location: '.$GLOBALS['HOME_ROOT_URL']);
- exit(0);
- } else {
- $ar['alias']=$erroralias;
- $ar['oidit']=NULL;
- return $this->viewpage($ar);
- }
- }
- }
- function xmodinfotree_procEditInPlace(){
- activeSec();
- $p=new XParam($ar,NULL);
- $moid=$p->get('moid');
- $oid=$p->get('oid');
- $oidit=$p->get('oidit');
- $field=$p->get('field');
- $value=$p->get('value');
- $GLOBALS['XSHELL']=new XShell();
- $GLOBALS['XSHELL']->labels=new XLabels();
- $mod=XModule::objectFactory($moid);
- if(!$mod->secure($oidit,'savesection')) die('secerror');
- $table=Kernel::getTable($oid);
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
- $ar2['_options']['local']=true;
- $ar2['tplentry']=TZR_RETURN_DATA;
- $ar2['oid']=$oid;
- $ar2[$field]=$value;
- $ret=$xds->procEdit($ar2);
- die($value);
- }
- ?>