/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
Large files files are truncated, but you can click here to view the full file
- <?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…
Large files files are truncated, but you can click here to view the full file