/class.xmodinfotree.inc

https://github.com/jcplat/console-seolan · PHP · 3241 lines · 2746 code · 202 blank · 293 comment · 486 complexity · b4262d8cd9d943f98eb8bdfea8d16a4f MD5 · raw file

Large files are truncated click here to view the full file

  1. <?php
  2. /****c* XModule/XModInfoTree
  3. * NAME
  4. * XModInfoTree -- gestion d'un ensemble de rubriques structurees
  5. * DESCRIPTION
  6. * Module central de gestion d'un site internet, integrant la
  7. * gestion de rubriques structurees, le rattachement d'informations
  8. * a ces rubriques, ainsi que la creation de requetes.
  9. * SYNOPSIS
  10. ****/
  11. /// Module de gestion d'un ensemble de rbriques et de pages web
  12. class XModInfoTree extends XModule {
  13. public $table = 'T001';
  14. public $_rbrowse=NULL;
  15. public $cattemplate=NULL;
  16. public $preview='/index.php?_cachepolicy=forcecache';
  17. public $linkin='';
  18. public $urlext='';
  19. /// construction de la classe gestion de rubriques
  20. function __construct($ar=NULL) {
  21. parent::__construct($ar);
  22. XLabels::loadLabels('xmodinfotree');
  23. $this->_categories=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->table);
  24. $this->tname='IT'.$this->table;
  25. if(empty($this->_templates))
  26. $this->_templates=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS=TEMPLATES');
  27. XAlias::register($this);
  28. }
  29. /// initialisation des options
  30. public function initOptions() {
  31. parent::initOptions();
  32. $this->_options->setOpt(XLabels::getSysLabel('general','table'), 'table', 'table',array('validate'=>true));
  33. $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','cattemplate'), 'cattemplate', 'template',
  34. array('moid'=>$this->_moid,
  35. 'cond'=>"(gtype like 'categorie')"));
  36. $this->_options->setOpt(XLabels::getSysLabel('general','preview','text'), 'preview', 'text',NULL,'index.php?');
  37. $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','linkinfield','text'), 'linkin', 'field',
  38. array('compulsory'=>false),'linkin');
  39. $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','urlextfield','text'), 'urlext', 'field',
  40. array('compulsory'=>false),'urlext');
  41. $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','odt_texttpl','text'), 'odttpltxt', 'template',
  42. array('compulsory'=>false),NULL,'ODT');
  43. $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','odt_texttitlefield','text'), 'odttxttitlefield', 'text', NULL, 'title','ODT');
  44. $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','odt_textfield','text'), 'odttxtfield', 'text', NULL, 'txt1','ODT');
  45. $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','odt_imagetpl','text'), 'odttplimg', 'template',
  46. array('compulsory'=>false),NULL,'ODT');
  47. $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','odt_imagefield','text'), 'odtimgfield', 'text', NULL,'img1','ODT');
  48. $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','pdf_enabled','text'), 'pdf_enabled', 'boolean', NULL,false,'PDF');
  49. $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','pdf_css','text'), 'pdf_css', 'text', NULL,'css/pdf.css','PDF');
  50. $this->_options->setOpt(XLabels::getSysLabel('xmodinfotree','pdf_css_content','text'), 'pdf_css_content', 'text', NULL,'css/page-content.css','PDF');
  51. $tlabel=XLabels::getSysLabel('xmodule.tracking');
  52. $this->_options->setOpt(XLabels::getSysLabel('xfielddef','trackchanges'),'trackchanges','boolean',NULL,NULL,$tlabel);
  53. }
  54. /// securite des fonctions accessibles par le web
  55. function secGroups($function, $group=NULL) {
  56. $g=array('home'=>array('list','ro','rw','rwv','admin'),
  57. 'procHome'=>array('rw','rwv','admin'),
  58. 'rss'=>array('ro','rw','rwv','admin'),
  59. 'viewpage'=>array('ro','rw','rwv','admin'),
  60. 'viewsection'=>array('ro','rw','rwv','admin'),
  61. 'procQuery'=>array('ro','rw','rwv','admin'),
  62. 'query'=>array('ro','rw','rwv','admin'),
  63. 'browse'=>array('ro','rw','rwv','admin'),
  64. 'input'=>array('rw','rwv','admin'),
  65. 'procInput'=>array('rw','rwv','admin'),
  66. 'addSection'=>array('rw','rwv','admin'),
  67. 'newsection'=>array('rw','rwv','admin'),
  68. 'insertsection'=>array('rw','rwv','admin'),
  69. 'editsection'=>array('rw','rwv','admin'),
  70. 'savesection'=>array('rw','rwv','admin'),
  71. 'newfunction'=>array('rw','rwv','admin'),
  72. 'insertfunction'=>array('rw','rwv','admin'),
  73. 'editfunction'=>array('rw','rwv','admin'),
  74. 'savefunction'=>array('rw','rwv','admin'),
  75. 'insertquery'=>array('rw','rwv','admin'),
  76. 'editquery'=>array('rw','rwv','admin'),
  77. 'savequery'=>array('rw','rwv','admin'),
  78. 'delSection'=>array('rw','rwv','admin'),
  79. 'editpage'=>array('rw','rwv','admin'),
  80. 'delCat'=>array('rw','rwv','admin'),
  81. 'dupCat'=>array('rw','rwv','admin'),
  82. 'procEdit'=>array('rw','rwv','admin'),
  83. 'procEditAllLang'=>array('rw','rwv','admin'),
  84. 'editCat'=>array('rw','rwv','admin'),
  85. 'moveCat'=>array('rw','rwv','admin'),
  86. 'moveSection'=>array('rw','rwv','admin'),
  87. 'moveSelectedCat'=>array('rw','rwv','admin'),
  88. 'moveToTrash'=>array('rw','rwv','admin'),
  89. 'displayImage'=>array('rw','rwv','admin'),
  90. 'displaysection'=>array('ro','rw','rwv','admin'),
  91. 'dupsection'=>array('rw','rwv','admin'),
  92. 'publishCat'=>array('rwv','admin'),
  93. 'subscribe'=>array('ro','rw','rwv','admin'),
  94. 'preSubscribe'=>array('ro','rw','rwv','admin'),
  95. 'export'=>array('ro','rw','rwv','admin'),
  96. 'exportPdf'=>array('ro','rw','rwv','admin'),
  97. 'publish'=>array('rwv','admin'),
  98. 'preImportFromODT'=>array('rw','rwv','admin'),
  99. 'importFromODT'=>array('rw','rwv','admin'),
  100. 'adminNewSection'=>array('rw','rwv','admin'),
  101. 'adminProcNewSection'=>array('rw','rwv','admin'));
  102. if(isset($g[$function])) {
  103. if(!empty($group)) return in_array($group, $g[$function]);
  104. else return $g[$function];
  105. }
  106. return parent::secGroups($function,$group);
  107. }
  108. /// Action principale du menu
  109. public function getMainAction(){
  110. return $GLOBALS['TZR_SESSION_MANAGER']::complete_self().'moid='.$this->_moid.'&function=home&tplentry=mit&template=xmodinfotree/index.html';
  111. }
  112. /// list des tables dont on souhaite tracer les modifications
  113. function tablesToTrack() {
  114. $ret=array();
  115. if($this->trackchanges) {
  116. $tabs=selectQueryGetAll('SELECT DISTINCT tab FROM TEMPLATES WHERE modid=\''.$this->_moid.'\'');
  117. $ret=array($this->table);
  118. foreach($tabs as $tab) {
  119. $ret[]=$tab['tab'];
  120. }
  121. }
  122. return $ret;
  123. }
  124. /// Prepare l'ajout d'une nouvelle section function
  125. public function newfunction($ar=NULL){
  126. $p=new XParam($ar,NULL);
  127. $tplentry=$p->get('tplentry');
  128. $oidit=$p->get('oidit');
  129. $oidtpl=$p->get('oidtpl');
  130. $lang=XShell::getLangData();
  131. $tabletpl=Kernel::getTable($oidtpl);
  132. $rs=selectQuery('select * from '.$tabletpl.' where KOID="'.$oidtpl.'" AND LANG="'.$lang.'"');
  133. if($rs && $o1=$rs->fetch()) {
  134. $tabledst=$o1['tab'];
  135. // Infos d'affichage du template
  136. $template = $this->_disp2Template($oidtpl);
  137. $s['_tp'] = $template;
  138. $s['section']=$p->get('section');
  139. $s['position']=$p->get('position');
  140. $s['oidit']=$p->get('oidit');
  141. $s['oidtpl']=$p->get('oidtpl');
  142. $moid=$s['section']['moid'];
  143. $f=$s['section']['function'];
  144. $pf='UIParam_'.$f;
  145. $ef='UIEdit_'.$f;
  146. $m=XModule::objectFactory($moid);
  147. if(method_exists($m,$ef)) $ret=$m->$ef();
  148. else{
  149. $desc=$m->$pf();
  150. $ret=array('fields_object'=>array());
  151. foreach($desc as $fn=>&$f){
  152. $o=$desc[$fn]->edit();
  153. $ret['o'.$fn]=$ret['fields_object'][]=$o;
  154. }
  155. }
  156. $this->editTemplateOptions($ret, $oidtpl, $s['oidit']);
  157. $groups=array();
  158. foreach($ret as $n=>&$v) {
  159. if(!is_object($v) || !is_object($v->fielddef)) continue;
  160. if(empty($v->fielddef->fgroup)) $v->fielddef->fgroup='General';
  161. $groups[$v->fielddef->fgroup][]=&$v;
  162. }
  163. ksort($groups);
  164. if(count($groups)>1) $ret['_groups']=$groups;
  165. $s['olines'][]=$ret;
  166. XShell::toScreen1($tplentry,$s);
  167. }
  168. }
  169. /// Duplication d'un module, méthode interne
  170. /// Retour : duplicatetables => liste des tables dupliquées par le module (cle : ancienne table, valeur : nouvelle table))
  171. /// Retour : duplicatemods => liste des modules dupliqués par le module (cle : ancien moid, valeur : nouveau moid))
  172. function _duplicateModule($newmoid,&$params,$prefix) {
  173. if(!is_array($params['tables'])) $params['tables']=array();
  174. if(!$params['noduplicatetable']){
  175. // duplication de la table des rubriques
  176. if(empty($params['tables'][$this->table])){
  177. $ar['newtable']=XDSTable::newTableNumber();
  178. $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->table);
  179. if(($pos=strpos($xset->getLabel(),':'))!==false) $ar['mtxt']=$prefix.substr($xset->getLabel(),$pos);
  180. else $ar['mtxt']=$prefix.':'.$xset->getLabel();
  181. $ar['data']=false;
  182. $ar['_options']=array('local'=>1);
  183. $xset2=$xset->procDuplicateDataSource($ar);
  184. // correction du lien vers la rubrique mere
  185. $xset21=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ar['newtable']);
  186. $xset21->procEditField(array('field'=>'linkup','table'=>$newtable,'_todo'=>'save','target'=>$ar['newtable'],
  187. 'published'=>'off','queryable'=>'on','browsable'=>'on','compulsory'=>'off','translatable'=>'off',
  188. 'options'=>array('comment'=>array('FR'=>'Rubrique mere'))));
  189. $params['table']=$ar['newtable'];
  190. }else{
  191. $params['table']=$params['tables'][$this->table];
  192. }
  193. // creation de la table des liens
  194. XModInfoTreeWd::createLinkStructure($params['table']);
  195. // duplication des mises en page/gabarits
  196. $rs=selectQuery('SELECT KOID FROM TEMPLATES WHERE modid =\''.$this->_moid.'\'');
  197. $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS=TEMPLATES');
  198. while($rs && $ors=$rs->fetch()) {
  199. $ardup=array('_options'=>array('local'=>1));
  200. $ardup['oid']=$ors['KOID'];
  201. $nkoid=$xset->duplicate($ardup);
  202. preparedUpdateQuery('UPDATE TEMPLATES set modid=? where KOID=?',array($newmoid,$nkoid));
  203. }
  204. }
  205. unset($params['noduplicatetable']);
  206. return array('duplicatetables'=>array($this->table=>$params['table']),'duplicatemods'=>array());
  207. }
  208. /// Enregistre une section de type fonction
  209. public function insertfunction($ar=NULL){
  210. $p=new XParam($ar,NULL);
  211. $oidit=$p->get('oidit');
  212. $oidtpl=$p->get('oidtpl');
  213. $position=$p->get('position')+1;
  214. $section=$p->get('section');
  215. $moid=$section['moid'];
  216. $f=$section['function'];
  217. $pf='UIParam_'.$f;
  218. $ef='UIProcEdit_'.$f;
  219. $m=XModule::objectFactory($moid);
  220. if(method_exists($m,$ef)){
  221. $ret=$m->$ef($ar);
  222. if($ret) $section=array_merge($section,$ret);
  223. }else{
  224. $desc=$m->$pf();
  225. $options=array('_track'=>false);
  226. foreach($desc as $fn=>&$f){
  227. $value=$p->get($fn);
  228. $value_hid=$p->get($fn.'_HID');
  229. $options[$fn.'_HID']=$value_hid;
  230. $o=$desc[$fn]->post_edit($value,$options);
  231. if($f->multivalued && $f->get_fgender()=='Oid' && is_array($o->raw)){
  232. $o->raw=implode('||',$o->raw);
  233. }
  234. $section[$fn]=$o->raw;
  235. }
  236. }
  237. $val=addslashes(serialize($section));
  238. $nitoid=self::newItOid();
  239. updateQuery("UPDATE ".$this->tname." SET ORDER1=ORDER1+1 where KOIDSRC='$oidit' ".
  240. " AND ORDER1 >= $position");
  241. updateQuery('INSERT INTO '.$this->tname.' SET KOIDSRC="'.$oidit.'",KOIDDST="",KOIDTPL="'.$oidtpl.'",ORDER1="'.$position.'",'.
  242. 'QUERY="'.$val.'",ITOID="'.$nitoid.'"');
  243. return $nitoid;
  244. }
  245. /// Prépare l'edition d'une section fonction
  246. function editfunction($ar=NULL){
  247. $p=new XParam($ar,NULL);
  248. $tplentry=$p->get('tplentry');
  249. $oidit=$p->get('oidit');
  250. $oidsection=$p->get('oidsection');
  251. list($oidit,$oiddest,$oidtemplate)=$this->_getOids($oidsection);
  252. $rs=selectQuery('select * from '.$this->tname.' where ITOID="'.$oidsection.'"');
  253. if(!$ors=$rs->fetch()) return array();
  254. $params=unserialize($ors['QUERY']);
  255. $s=array();
  256. $template = $this->_disp2Template($oidtemplate);
  257. $s['_tp'] = $template;
  258. $s['oidit']=$oidit;
  259. $s['oidsection']=$oidsection;
  260. $s['section']=$params;
  261. $moid=$params['moid'];
  262. $f=$params['function'];
  263. $pf='UIParam_'.$f;
  264. $ef='UIEdit_'.$f;
  265. $m=XModule::objectFactory($moid);
  266. if(method_exists($m,$ef)) $ret=$m->$ef($params);
  267. else{
  268. $desc=$m->$pf();
  269. $ret=array('fields_object'=>array());
  270. foreach($desc as $fn=>&$f){
  271. $o=$f->edit($params[$fn]);
  272. $ret['o'.$fn]=$ret['fields_object'][]=$o;
  273. }
  274. }
  275. $this->editTemplateOptions($ret, $oidtemplate, $s['oidsection'], $params);
  276. $groups=array();
  277. foreach($ret as $n=>&$v) {
  278. if(!is_object($v) || !is_object($v->fielddef)) continue;
  279. if(empty($v->fielddef->fgroup)) $v->fielddef->fgroup='General';
  280. $groups[$v->fielddef->fgroup][]=&$v;
  281. }
  282. ksort($groups);
  283. if(count($groups)>1) $ret['_groups']=$groups;
  284. $s['olines'][]=$ret;
  285. return XShell::toScreen1($tplentry,$s);
  286. }
  287. /**
  288. * Ajoute les options du template à l'interface d'édition de la section fonction
  289. * @param &$ret array Tableau de valeurs disponible dans le template
  290. * @param $oid_template string KOID du template
  291. * @param $id_section string Identifiant unique de la section
  292. * @param $params array Tableau de valeurs des options du template
  293. */
  294. public function editTemplateOptions(&$ret, $oid_template, $id_section, $params = null) {
  295. // Récupère les options liées au TEMPLATE de mise en page
  296. $options_values = (object) null;
  297. $xoptions = $this->getTemplateOptions($oid_template, $id_section, $options_values);
  298. if (!is_null($xoptions)) {
  299. $template_options = $xoptions->getValues($options_values);
  300. foreach ($template_options as $option_id => $option) {
  301. $xoptions->set($options_values, $option_id, $params['_tploptions'][$option_id]);
  302. }
  303. $user_module_access_levels = current(XUser::getObjectAccess($this->_moid));
  304. $level = in_array('admin', $user_module_access_levels) ? 'admin' : 'none';
  305. $ret['_tploptions'] = $xoptions->getDialog($options_values, $params['_tploptions'], '_tploptions', $level);
  306. }
  307. }
  308. /**
  309. * Envoi un tableau des options disponibles pour le template
  310. * @param $oid_template string KOID du template
  311. * @param $id_section string Identifiant unique de la section
  312. * @param $options_values array Tableau de valeurs des options du template
  313. * @return XOptions Objet contenant les options du template / null si inexistant
  314. */
  315. public function getTemplateOptions($oid_template, $id_section, &$options_values) {
  316. $template = $this->_templates->rDisplay($oid_template);
  317. if (empty($template['oopts']->raw)) {
  318. return null;
  319. }
  320. $xopts = new XOptions($id_section);
  321. $xopts->setOptsFromXML($options_values, $template['oopts']->raw);
  322. return $xopts;
  323. }
  324. /// Enregistre une section de type fonction
  325. public function savefunction($ar=NULL){
  326. $p=new XParam($ar,NULL);
  327. $oidit=$p->get('oidit');
  328. $oidtpl=$p->get('oidtpl');
  329. $oidsection=$p->get('oidsection');
  330. $section=$p->get('section');
  331. $moid=$section['moid'];
  332. $f=$section['function'];
  333. $pf='UIParam_'.$f;
  334. $ef='UIProcEdit_'.$f;
  335. $m=XModule::objectFactory($moid);
  336. if(method_exists($m,$ef)){
  337. $ret=$m->$ef($ar);
  338. if($ret) $section=array_merge($section,$ret);
  339. }else{
  340. $desc=$m->$pf();
  341. $options=array('_track'=>false);
  342. foreach($desc as $fn=>&$f){
  343. $value=$p->get($fn);
  344. $value_hid=$p->get($fn.'_HID');
  345. $options[$fn.'_HID']=$value_hid;
  346. $o=$desc[$fn]->post_edit($value,$options);
  347. if($f->multivalued && $f->get_fgender()=='Oid' && is_array($o->raw)){
  348. $o->raw=implode('||',$o->raw);
  349. }
  350. $section[$fn]=$o->raw;
  351. }
  352. }
  353. $section['_tploptions'] = $p->get('_tploptions');
  354. $val=addslashes(serialize($section));
  355. updateQuery('UPDATE '.$this->tname.' SET KOIDSRC="'.$oidit.'",KOIDDST="",QUERY="'.$val.'" where ITOID="'.$oidsection.'"');
  356. return $oidsection;
  357. }
  358. /// Prepare l'ajout d'une section dans l'administration a partir d'une page donnee
  359. function adminNewSection($ar=NULL){
  360. $p=new XParam($ar,NULL);
  361. $tplentry=$p->get('tplentry');
  362. $newrub=$p->get('newrub');
  363. $fct=$p->get('fct');
  364. $r=array();
  365. if($newrub) $this->_categories->input(array('tplentry'=>$tplentry.'rub'));
  366. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS=CS8SEC');
  367. $xds->input(array('tplentry'=>$tplentry.'sec'));
  368. $this->home(array('tplentry'=>$tplentry.'tree','maxlevel'=>1,'norubric'=>true));
  369. $fct=XModUser2::_normalizeBookmark($fct);
  370. $r['fct']=$fct;
  371. parse_str($fct,$infos);
  372. $f=$infos['_function']?$infos['_function']:$infos['function'];
  373. if($infos['moid'] && ($f=='procQuery' || $f=='browse')){
  374. $mod=XModule::objectFactory($infos['moid']);
  375. if($mod->persistentquery){
  376. $r['persistent']=1;
  377. }
  378. }
  379. return XShell::toScreen1($tplentry,$r);
  380. }
  381. /// Ajoute une section dans l'administration
  382. function adminProcNewSection($ar=NULL){
  383. $p=new XParam($ar,NULL);
  384. $linkup=$p->get('linkup');
  385. $createrub=$p->get('createrub');
  386. if($createrub){
  387. $rub=$this->procInput($ar);
  388. $linkup=$rub['oid'];
  389. }
  390. $ar2=$p->get('sec');
  391. $ar2['fct']=XModUser2::_normalizeBookmark($ar2['fct']);
  392. $ar2['oidit']=$linkup;
  393. $ar2['oidtpl']='TEMPLATES:ADMIN-'.$this->_moid;
  394. if(!empty($ar2['persistent'])) $ar2['fct'].='&_persistent=1';
  395. $this->insertsection($ar2);
  396. }
  397. /// Liste des actions générale du module
  398. protected function _actionlist(&$my) {
  399. parent::_actionlist($my);
  400. $myoid=@$_REQUEST['oidit'];
  401. $moid=$this->_moid;
  402. // Arbo
  403. $o1=new XModuleAction($this,'home',XLabels::getSysLabel('xmodinfotree','see_categories'),
  404. '&moid='.$moid.'&_function=home&template=xmodinfotree/index.html&tplentry=mit','display');
  405. $o1->setToolbar('general','browse');
  406. $my['home']=$o1;
  407. // Poubelle
  408. $o1=new XModuleAction($this,'trash',XLabels::getSysLabel('xmodinfotree','see_trash'),
  409. '&moid='.$moid.'&_function=home&template=xmodinfotree/index.html&tplentry=mit&aliastop=trash','display');
  410. $o1->setToolbar('general','trash');
  411. $my['trash']=$o1;
  412. // Recherche
  413. $o1=new XModuleAction($this,'home',XLabels::getSysLabel('general','query','text'),
  414. '&moid='.$moid.'&_function=query&template=xmodinfotree/query.html&tplentry=br','display');
  415. $o1->setToolbar('general','query');
  416. $my['query']=$o1;
  417. // Pile
  418. if($this->interactive) {
  419. $o1=new XModuleAction($this,'in',$this->modulename,
  420. '&moid='.$this->_moid.'&_function=home&template=xmodinfotree/index.html&tplentry=mit');
  421. $my['stack'][]=$o1;
  422. if (!empty($myoid)) {
  423. $nav=$this->getPath($myoid);
  424. foreach($nav['oiddown'] as $i=>$oid) {
  425. $o1=new XModuleAction($this,'i'.$i,$nav['labeldown'][$i],
  426. '&moid='.$this->_moid.'&_function=editpage&template=xmodinfotree/viewpage.html&tplentry=it&oidit='.$oid);
  427. $my['stack'][]=$o1;
  428. }
  429. }
  430. if(XShell::_function()=='editCat'){
  431. $br=&XShell::from_screen('editcat');
  432. $br=&$this->_categories->rDisplayText($br['oid'],array());
  433. $o1=new XModuleAction($this,'view',$br['link'],'&moid='.$this->_moid.'&_function=editpage&template=xmodinfotree/viewpage.html&tplentry=it&oidit='.$br['oid']);
  434. $my['stack'][]=$o1;
  435. }
  436. $modsubmoid=XModule::getMoid(XMODSUB_TOID);
  437. if(!empty($modsubmoid)){
  438. $o1=new XModuleAction($this,'subscribe',XLabels::getSysLabel('xmodsub','subadd','text'),
  439. '&moid='.$this->_moid.'&oid='.$myoid.'&_function=preSubscribe&tplentry=br&template=xmodinfotree/sub.html',
  440. 'more');
  441. $o1->menuable=true;
  442. $my['subscribe']=$o1;
  443. }
  444. if($this->odttpltxt && $this->odttplimg && $this->secure(NULL,'importFromODT')){
  445. $o1=new XModuleAction($this,'odtimport',XLabels::getSysLabel('xmodinfotree','odt_import','text'),
  446. '&moid='.$this->_moid.'&function=preImportFromODT&template=xmodinfotree/preImportFromODT.html&oidit='.$oid,'edit');
  447. $o1->menuable=true;
  448. $my['odtimport']=$o1;
  449. }
  450. }
  451. }
  452. /// Actions spécifique à "home"
  453. function al_home(&$my){
  454. $uniqid='v'.XShell::uniqid();
  455. $o1=new XModuleAction($this,'foldall',XLabels::getSysLabel('xmodinfotree','fold_all','text'),
  456. '&function=home&template=xmodinfotree/index.html&moid='.$this->_moid.'&do=foldall&tplentry=mit','display');
  457. $o1->menuable=true;
  458. $my['foldall']=$o1;
  459. $o1=new XModuleAction($this,'unfoldall',XLabels::getSysLabel('xmodinfotree','unfold_all','text'),
  460. '&function=home&template=xmodinfotree/index.html&moid='.$this->_moid.'&do=unfoldall&tplentry=mit','display');
  461. $o1->menuable=true;
  462. $my['unfoldall']=$o1;
  463. if($this->secure(NULL,'input')){
  464. $o1=new XModuleAction($this,'input',XLabels::getSysLabel('xmodinfotree','add_subtree','text'),
  465. '&moid='.$this->_moid.'&function=input&template=xmodinfotree/new.html&linkup=','edit');
  466. $o1->setToolbar('general','new');
  467. $my['input']=$o1;
  468. }
  469. // Publier/dépulier
  470. if($this->_categories->fieldExists('PUBLISH') && $this->secure(NULL,':rwv')){
  471. $o1=new XModuleAction($this,'publish',XLabels::getSysLabel('general','approve','text'),
  472. 'javascript:'.$uniqid.'.publishSelected(true);','edit');
  473. $o1->menuable=true;
  474. $my['publish']=$o1;
  475. $o1=new XModuleAction($this,'publish',XLabels::getSysLabel('general','unapprove','text'),
  476. 'javascript:'.$uniqid.'.publishSelected(false);','edit');
  477. $o1->menuable=true;
  478. $my['unpublish']=$o1;
  479. }
  480. // Supprimer
  481. if($this->secure(NULL,'moveToTrash')){
  482. $o1=new XModuleAction($this,'del',XLabels::getSysLabel('general','delete','text'),
  483. 'javascript:'.$uniqid.'.deleteselected();','edit');
  484. $o1->setToolbar('general','delete');
  485. $my['del']=$o1;
  486. }
  487. // Deplacer
  488. if($this->secure(NULL,'moveCat')){
  489. $o1=new XModuleAction($this,'move',XLabels::getSysLabel('general','move','text'),
  490. 'javascript:'.$uniqid.'.moveselected();','edit');
  491. $o1->menuable=true;
  492. $my['move']=$o1;
  493. }
  494. // Dupliquer
  495. if($this->secure(NULL,'dupCat')){
  496. $o1=new XModuleAction($this,'dup',XLabels::getSysLabel('general','clone','text'),
  497. 'javascript:'.$uniqid.'.duplicateselected();','edit');
  498. $o1->menuable=true;
  499. $my['dup']=$o1;
  500. }
  501. // Exporter
  502. if($this->secure(NULL,'export')){
  503. $o1=new XModuleAction($this,'export',XLabels::getSysLabel('general','export','text'),
  504. 'javascript:'.$uniqid.'.exportselected();','edit');
  505. $o1->menuable=true;
  506. $my['exp']=$o1;
  507. }
  508. }
  509. /// Actions spécifique à "viewpage"
  510. function al_viewpage(&$my){
  511. $uniqid='v'.XShell::uniqid();
  512. $oid=$_REQUEST['oidit'];
  513. // Navigation
  514. $o1=new XModuleAction($this,'nav',XLabels::getSysLabel('general','navigation','text'),'#');
  515. $o1->menuable=true;
  516. $o1->newgroup='nav';
  517. $my['nav']=$o1;
  518. $o1=new XModuleAction($this,'navall',XLabels::getSysLabel('xmodinfotree','treebrowser','text'),
  519. 'javascript:TZR.openPopup("'.$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'function=home&template=xmodinfotree/popaction.html'.
  520. '&_skip=1&moid='.$this->_moid.'&_raw=1&maxlevel=1&oid='.$oid.'&tplentry=mit&do=add&'.
  521. '&norubric=1&action=go&moduleid='.XShell::uniqid().'");','nav');
  522. $o1->menuable=true;
  523. $my['navall']=$o1;
  524. $it=&XShell::from_screen('it');
  525. $nav=&$it['nav'];
  526. if($nav['up']){
  527. $o1=new XModuleAction($this,'navup',$nav['up']['otitle']->html,'javascript:'.$uniqid.'.gopage("'.$nav['up']['oid'].'");','nav');
  528. $o1->menuable=true;
  529. $my['navup']=$o1;
  530. }
  531. if(!empty($nav['prev'])){
  532. $o1=new XModuleAction($this,'navprev',$nav['prev']['otitle']->html,'javascript:'.$uniqid.'.gopage("'.$nav['prev']['oid'].'");',
  533. 'nav');
  534. $o1->menuable=true;
  535. $my['navprev']=$o1;
  536. }
  537. if(!empty($nav['next'])){
  538. $o1=new XModuleAction($this,'navnext',$nav['next']['otitle']->html,'javascript:'.$uniqid.'.gopage("'.$nav['next']['oid'].'");',
  539. 'nav');
  540. $o1->menuable=true;
  541. $my['navnext']=$o1;
  542. }
  543. $rubs=&XShell::from_screen('ssrubs');
  544. foreach($rubs['lines_oid'] as $i=>$roid){
  545. $o1=new XModuleAction($this,'navssrub'.$i,$rubs['lines_otitle'][$i]->html,'javascript:'.$uniqid.'.gopage("'.$roid.'");','nav');
  546. $o1->menuable=true;
  547. $my['navssrub'.$i]=$o1;
  548. }
  549. // Prévisualisation
  550. if($this->preview){
  551. $o1=new XModuleAction($this,'view',XLabels::getSysLabel('general','view','text'),
  552. $this->preview.'&_lang='.XShell::getLangData().'&oidit='.$oid.'&nocache=1','edit');
  553. $o1->target='_blank';
  554. $o1->setToolbar('general','view');
  555. $my['view']=$o1;
  556. }
  557. // Publier/dépulier
  558. if($this->secure($oid,':rwv')){
  559. $it=XShell::from_screen('it');
  560. $publish=false;
  561. foreach($it['olines'] as $i=>$s){
  562. if(isset($s['oPUBLISH'])){
  563. $publish=true;
  564. break;
  565. }
  566. }
  567. if($publish){
  568. $o1=new XModuleAction($this,'publish',XLabels::getSysLabel('general','approve','text'),
  569. 'javascript:'.$uniqid.'.publishSelected(true);','edit');
  570. $o1->menuable=true;
  571. $my['publish']=$o1;
  572. $o1=new XModuleAction($this,'publish',XLabels::getSysLabel('general','unapprove','text'),
  573. 'javascript:'.$uniqid.'.publishSelected(false);','edit');
  574. $o1->menuable=true;
  575. $my['unpublish']=$o1;
  576. }
  577. }
  578. // Supprimer
  579. if($this->secure($oid,'delSection')){
  580. $o1=new XModuleAction($this,'del',XLabels::getSysLabel('general','delete','text'),
  581. 'javascript:'.$uniqid.'.deleteselected();','edit');
  582. $o1->menuable=true;
  583. $my['del']=$o1;
  584. }
  585. // Deplacer
  586. if($this->secure($oid,'moveSection')){
  587. $o1=new XModuleAction($this,'move',XLabels::getSysLabel('general','move','text'),
  588. 'javascript:'.$uniqid.'.moveselected(\'to\');','edit');
  589. $o1->menuable=true;
  590. $my['move']=$o1;
  591. $o1=new XModuleAction($this,'moveup',XLabels::getSysLabel('general','up','text'),
  592. 'javascript:'.$uniqid.'.moveselected(\'up\');','edit');
  593. $o1->menuable=true;
  594. $my['moveup']=$o1;
  595. $o1=new XModuleAction($this,'movedown',XLabels::getSysLabel('general','down','text'),
  596. 'javascript:'.$uniqid.'.moveselected(\'down\');','edit');
  597. $o1->menuable=true;
  598. $my['movedown']=$o1;
  599. }
  600. // Export PDF
  601. if($this->pdf_enabled && $this->secure($oid,'exportPdf')) {
  602. $o1=new XModuleAction($this,'exportPdf',XLabels::getSysLabel('xmodinfotree','export_pdf','text'),'&moid='.$this->_moid.'&_function=exportPdf&oidit='.$oid,'edit');
  603. $o1->target='_blank';
  604. $o1->ico='<img src="/tzr/templates/ico/mime/pdf.gif">';
  605. $o1->setToolbar();
  606. $my['exportPdf']=$o1;
  607. }
  608. }
  609. /// Actions spécifique à "editpage"
  610. function al_editpage(&$my){
  611. $this->al_viewpage($my);
  612. }
  613. /// Refait la numérotation de l'ordre des sections d'une catégorie
  614. protected function _reorderSections($oid) {
  615. $rs=selectQuery('select ITOID,ORDER1 from '.$this->tname.' where KOIDSRC="'.$oid.'" order by ORDER1,ITOID');
  616. $i=0;
  617. while($ors=$rs->fetch()) {
  618. $i++;
  619. if($i==$ors['ORDER1']) continue;
  620. updateQuery('UPDATE '.$this->tname.' set ORDER1='.$i.' where ITOID="'.$ors['ITOID'].'"');
  621. }
  622. $rs->closeCursor();
  623. }
  624. /// Refait la numérotation de l'ordre des catégories d'un noeud
  625. protected function _reorderCat($oid) {
  626. $lang=TZR_DEFAULT_LANG;
  627. if(!$oid) $oid='';
  628. $i=0;
  629. $rs=selectQuery('select distinct KOID,corder from '.$this->table.' where linkup="'.$oid.'" and LANG="'.$lang.'" order by corder');
  630. while($ors=$rs->fetch()) {
  631. $i++;
  632. if($i==$ors['corder']) continue;
  633. updateQuery('UPDATE '.$this->table.' set corder='.$i.',UPD=UPD where KOID="'.$ors['KOID'].'"');
  634. }
  635. $rs->closeCursor();
  636. }
  637. /// Change le parent d'une ou plusieurs catégories
  638. public function moveSelectedCat($ar) {
  639. $p=new XParam($ar, array());
  640. $dest=$p->get('_dest');
  641. if(!empty($dest) && !Kernel::isAKoid($dest)) {
  642. $dest=$this->getOidFromAlias($dest);
  643. }
  644. $sel=$p->get('_selected');
  645. $i=-count($sel);
  646. foreach($sel as $oid => $bid) {
  647. if($oid!=$dest) {
  648. updateQuery('UPDATE '.$this->table.' set linkup="'.$dest.'",corder='.$i.' where KOID="'.$oid.'"');
  649. }
  650. $i++;
  651. }
  652. $this->_reorderCat($dest);
  653. }
  654. /// teste si une rubrique est dans la poubelle
  655. protected function oidInTrash($oid) {
  656. $oidtrash = $this->getTrashOid();
  657. if(empty($oidtrash)) return false;
  658. $pathoids=$this->_getPathOids($oid);
  659. return in_array($oidtrash, $pathoids);
  660. }
  661. /// deplacement de la selection vers la poubelle, rubrique d'alias trash
  662. public function moveToTrash($ar) {
  663. $p=new XParam($ar, array());
  664. $oidtrash = $this->getTrashOid(true);
  665. $sel=$p->get('_selected');
  666. // si les elements sont deja dans la poubelle on les supprime
  667. $delnb=0;
  668. foreach($sel as $oid => $bid) {
  669. if($this->oidInTrash($oid)) {
  670. $ar1=array();
  671. $ar1['oid']=$oid;
  672. $ar1['_selected']=array();
  673. $ar1['_selectedok']='nok';
  674. $this->delCat($ar1);
  675. $delnb++;
  676. }
  677. }
  678. // si on a supprime tous les elements selectionnes pas la peine de
  679. // rentrer dans un traitement de la poubelle
  680. if($delnb==count($sel)) return;
  681. // creation d'une rubrique liee a la date de suppression
  682. $ar1=array('title'=>'-- '.date('c'),
  683. 'linkup'=>$oidtrash,
  684. 'corder'=>'0');
  685. $r1=&$this->procInput($ar1);
  686. $dest = $r1['oid'];
  687. foreach($sel as $oid => $bid) {
  688. if($oid!=$dest) {
  689. updateQuery('UPDATE '.$this->table." set linkup='$dest' where KOID='$oid'");
  690. }
  691. }
  692. // on parcourt la poubelle et on supprime dans la poubelle toutes les rubriques validees
  693. // ainsi que tous les alias
  694. $oids=$this->getSubObjects($oidtrash);
  695. foreach($oids as $oids1) {
  696. if($this->_categories->fieldExists('PUBLISH')) {
  697. updateQuery('UPDATE '.$this->table." set PUBLISH='2' WHERE KOID='$oids1'");
  698. }
  699. updateQuery('UPDATE '.$this->table." set alias='' WHERE KOID='$oids1'");
  700. }
  701. // on traite les liens internes. Ceux qui sont dans la poubelle sont supprimes
  702. // ceux qui vont vers la poubelle sont supprimes
  703. $rs=selectQuery('SELECT KOID,LANG,'.$this->linkin.' FROM '.$this->table.' WHERE '.$this->linkin.'!=\'\'');
  704. while($rs && ($ors=$rs->fetch())) {
  705. if($this->oidInTrash($ors['KOID'])) {
  706. updateQuery('UPDATE '.$this->table.' SET '.$this->linkin."='',UPD=UPD WHERE KOID='".$ors['KOID']."'");
  707. } elseif($this->oidInTrash($ors[$this->linkin])) {
  708. updateQuery('UPDATE '.$this->table.' SET '.$this->linkin."='',UPD=UPD WHERE KOID='".$ors['KOID']."' AND ".$this->linkin."='".$ors[$this->linkin]."'");
  709. }
  710. }
  711. }
  712. /// Change l'ordre et/ou le parent d'une catégorie
  713. public function moveCat($ar) {
  714. $p=new XParam($ar, array());
  715. $oid=$p->get('oid');
  716. $dir=$p->get('dir');
  717. $to=$p->get('to');
  718. // recherche de la rubrique mere
  719. $poid=$new_p=countSelectQuery('select distinct linkup from '.$this->table.' where KOID="'.$oid.'"');
  720. // on verifie et corrige l'ordre
  721. $this->_reorderCat($poid);
  722. if($to){
  723. $new_p=($to!='root'?$to:'');
  724. $this->_reorderCat($new_p);
  725. }
  726. // recherche de son ordre
  727. $o=countSelectQuery('select distinct corder from '.$this->table.' where KOID="'.$oid.'"');
  728. if($dir=='up'){
  729. $new_o=$o-1;
  730. updateQuery('UPDATE '.$this->table.' set corder='.$o.',UPD=UPD where corder='.$new_o.' and linkup="'.$poid.'"');
  731. }elseif($dir=='down'){
  732. $new_o=$o+1;
  733. updateQuery('UPDATE '.$this->table.' set corder='.$o.',UPD=UPD where corder='.$new_o.' and linkup="'.$poid.'"');
  734. }elseif(Kernel::isAKoid($dir)){
  735. $new_o=countSelectQuery('select distinct corder from '.$this->table.' where KOID="'.$dir.'"')+1;
  736. updateQuery('UPDATE '.$this->table.' set corder=corder+1,UPD=UPD where corder>='.$new_o.' and linkup="'.$new_p.'"');
  737. }else{
  738. $new_o=0;
  739. }
  740. updateQuery('UPDATE '.$this->table.' set corder='.$new_o.',linkup="'.$new_p.'" where KOID="'.$oid.'"');
  741. $this->_reorderCat($poid);
  742. if($new_p!=$poid) $this->_reorderCat($new_p);
  743. }
  744. /// suppression d'une rubrique et de toutes les sections associees
  745. function delCat($ar=NULL) {
  746. $p=new XParam($ar,array('_selectedok'=>'nok'));
  747. $lang_data=XShell::getLangData();
  748. if($lang_data==TZR_DEFAULT_LANG) $lang='';
  749. elseif(!$this->_categories->isTranslatable()) $lang='';
  750. else $lang="AND LANG='$lang_data'";
  751. $selected = $p->get('_selected');
  752. $selectedok = $p->get('_selectedok');
  753. if($selectedok=='ok') {
  754. foreach($selected as $oid => $bidon) {
  755. $ar['oid']=$oid;
  756. $ar['_selected']=array();
  757. $ar['_selectedok']='nok';
  758. $this->delCat($ar);
  759. }
  760. return;
  761. }
  762. $oid=$p->get('oid');
  763. $oids[$oid]=1;
  764. $kernel = new Kernel;
  765. while(count($oids)>0) {
  766. unset($oids2);
  767. foreach($oids as $k => $v) {
  768. $kernel->data_forcedDel(array('oid'=>$k,'action'=>'OK','_selectedok'=>'nok'));
  769. // suppression des sections
  770. $rs=selectQuery('select * from '.$this->tname." where KOIDSRC='$k'");
  771. while($ors=$rs->fetch()) {
  772. $itoid = $ors['ITOID'];
  773. $koiddst = $ors['KOIDDST'];
  774. if(!empty($koiddst)) {
  775. $tabledst = Kernel::getTable($koiddst);
  776. if(!empty($tabledst)) {
  777. if($lang_data == TZR_DEFAULT_LANG) {
  778. updateQuery('DELETE FROM '.$this->tname." where ITOID = '$itoid'");
  779. }
  780. $kernel->data_forcedDel(array('oid'=>$koiddst,'action'=>'OK','_selectedok'=>'nok'));
  781. }
  782. }
  783. }
  784. $rs->closeCursor();
  785. $rs=selectQuery('select distinct KOID from '.$this->table." where linkup='$k'");
  786. while($ors=$rs->fetch()) {
  787. $oids2[$ors['KOID']]=1;
  788. }
  789. $rs->closeCursor();
  790. }
  791. $oids=$oids2;
  792. }
  793. }
  794. /// suppression d'une categorie et de toutes les sections associees
  795. function dupCat($ar=NULL) {
  796. $p=new XParam($ar,array('_selectedok'=>'nok'));
  797. $lang_data=XShell::getLangData();
  798. if($lang_data==TZR_DEFAULT_LANG) $lang='';
  799. elseif(!$this->_categories->isTranslatable()) $lang='';
  800. else $lang="AND LANG='$lang_data'";
  801. $selected = $p->get('_selected');
  802. $selectedok = $p->get('_selectedok');
  803. if($selectedok=='ok') {
  804. foreach($selected as $oid => $bidon) {
  805. $ar['oid']=$oid;
  806. $ar['_selected']=array();
  807. $ar['_selectedok']='nok';
  808. $this->dupCat($ar);
  809. }
  810. return;
  811. }
  812. // duplication de la rubrique
  813. $oid=$p->get('oid');
  814. $nkoid=$this->_categories->duplicate(array('oid'=>$oid));
  815. $copy_of=XLabels::getSysLabel('general.copy_of');
  816. updateQuery('UPDATE '.$this->_categories->getTable()." set title=CONCAT('$copy_of ', title) where KOID='$nkoid'");
  817. updateQuery('UPDATE '.$this->_categories->getTable()." set alias=CONCAT(alias,'1') where KOID='$nkoid' and alias !=''");
  818. if($this->_categories->fieldExists('PUBLISH')) {
  819. updateQuery('UPDATE '.$this->_categories->getTable()." set PUBLISH='2' where KOID='$nkoid'");
  820. }
  821. // duplication des sections
  822. $rs=selectQuery('select * from '.$this->tname." where KOIDSRC='$oid'");
  823. if($rs->rowCount()>0) {
  824. $oids=array();
  825. $ors=array();
  826. while($ors=$rs->fetch()) {
  827. $oids[]=$ors['KOIDDST'];
  828. $itoids[]=$ors['ITOID'];
  829. }
  830. // duplication de chacune des sections
  831. $noids=array();
  832. foreach($oids as $i=>$oid1) {
  833. if(!empty($oid1)) {
  834. $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$oid1);
  835. $noids[$i]=$xset->duplicate(array('oid'=>$oid1));
  836. }
  837. }
  838. // duplication des liens
  839. updateQuery('CREATE TEMPORARY TABLE tmpo SELECT * FROM '.$this->tname." where KOIDSRC='$oid'");
  840. updateQuery("UPDATE tmpo set KOIDSRC='$nkoid'");
  841. foreach($oids as $i=>$oid1) {
  842. if(!empty($oid1)) {
  843. updateQuery("UPDATE tmpo set KOIDDST='".$noids[$i]."' where KOIDDST='$oid1' and KOIDSRC='$nkoid'");
  844. }
  845. }
  846. $rs=selectQuery('select * from tmpo');
  847. $ors=array();
  848. while($rs && ($ors=$rs->fetch())) {
  849. $olditoid=$ors['ITOID'];
  850. $n=self::newItOid();
  851. updateQuery("UPDATE tmpo set ITOID='$n' where ITOID='$olditoid'");
  852. }
  853. updateQuery('INSERT INTO '.$this->tname.' select * from tmpo');
  854. updateQuery('DROP TABLE tmpo');
  855. }
  856. $rs=selectQuery('SELECT DISTINCT KOID FROM '.$this->table." WHERE linkup='$oid'/* 1 */");
  857. while($ors=$rs->fetch()) {
  858. $ar1=array();
  859. $ar1['_selected']=array();
  860. $ar1['_selectedok']='nok';
  861. $ar1['oid']=$ors['KOID'];
  862. $nkoid2=$this->dupCat($ar1);
  863. XLogs::debug("recursive duplicate {$ors['KOID']} to $nkoid2");
  864. updateQuery("UPDATE {$this->table} set linkup='$nkoid' where KOID='$nkoid2'");
  865. }
  866. $rs->closeCursor();
  867. return $nkoid;
  868. }
  869. /// validation de sections ou de rubriques
  870. public function publish($ar) {
  871. $p = new XParam($ar,array('_pub'=>false));
  872. $selected = $p->get('_itoidselected');
  873. $pub = $p->get('_pub');
  874. $selectedoid = array();
  875. $oidsection=$p->get("oidsection");
  876. if(!empty($oidsection)) {
  877. $selected[$oidsection]=1;
  878. }
  879. if(is_array($selected)) {
  880. foreach($selected as $itoid => $foo) {
  881. $rs=selectQuery('select distinct KOIDDST from '.$this->tname." where ITOID='$itoid'");
  882. if($o=$rs->fetch()) {
  883. if(!empty($o['KOIDDST']))
  884. $selectedoid[]=$o['KOIDDST'];
  885. }
  886. }
  887. }
  888. $_selected=$p->get('_selected');
  889. if(!empty($_selected)) {
  890. $copy_of_selectedoid=$selectedoid;
  891. $selectedoid=array_merge(array_keys($_selected), $copy_of_selectedoid);
  892. }
  893. if(!empty($selectedoid)) {
  894. $ar['_selected']=$selectedoid;
  895. $ar['key']=false;
  896. $ar['value']=$pub;
  897. foreach($selectedoid as $oid) {
  898. $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$oid);
  899. $ar1=array('oid'=>$oid, 'value'=>$pub, '_selected'=>array());
  900. $xset->publish($ar1);
  901. }
  902. }
  903. }
  904. //// validation des oid ou des rubriques
  905. public function publishCat($ar) {
  906. $p=new XParam($ar,array('_pub'=>false));
  907. $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->table);
  908. $xset->publish($ar);
  909. }
  910. // Affichage de l'arboresnce
  911. //
  912. function homeedit($ar=NULL) {
  913. $p = new XParam($ar, array('level'=>'1','deroule'=>'1','sections'=>'1','tplentry'=>'mit','maxlevel'=>99));
  914. $this->home($ar);
  915. }
  916. // rend la liste des objets qui se trouvent en dessous de cet objet,
  917. // independamment des niveaux
  918. //
  919. public function &subObjects($oid) {
  920. return $this->getSubCats($oid, TZR_DEFAULT_LANG, 1, 20);
  921. }
  922. // rend vrai si le noeud oidit as des fils
  923. //
  924. protected function hasChildren($oidit) {
  925. $cnt=countSelectQuery('select * from '.$this->table." where linkup='$oidit'");
  926. return $cntt;
  927. }
  928. // rend l'url conseillee pour un noeud donné
  929. //
  930. protected function _selfUrl($oid, $alias=NULL) {
  931. if(!empty($alias)) {
  932. $html="alias=$alias";;
  933. } else {
  934. $html="oidit=$oid";
  935. }
  936. return $html;
  937. }
  938. function &procHome($ar=NULL) {
  939. $p = new XParam($ar, array());
  940. $aliases=$p->get('alias');
  941. $allmessages = array();
  942. if(is_array($aliases)) {
  943. foreach($aliases as $oid => $alias) {
  944. $message = '';
  945. $this->_checkAlias($alias, '', $oid, $message, NULL);
  946. if ($message == '')
  947. $this->_categories->procEdit(array('alias'=>$alias,'oid'=>$oid));
  948. else
  949. $allmessages[] = $message;
  950. }
  951. }
  952. XShell::setNextData('message', implode(', ',$allmessages));
  953. }
  954. /****m* XModInfoTree/home
  955. * NAME
  956. * XModInfoTree::home - creation de l'arborescence
  957. * DESCRIPTION
  958. * Preparation d'une structure de donnees pour affichage de la
  959. * hierarchie de rubriques
  960. * INPUTS
  961. * Passage de parametre indirect via $ar
  962. * level - numero du premier niveau, les niveaux sont numerotes a
  963. * partir de level, la valeur par defaut est 1 ;
  964. * maxlevel - nombre maximum de niveaux a explorer, valeur par defaut 99 ;
  965. * do - action a effectuer. showtree: exploration de toutes les branches ;
  966. * oidtop - oid de l'item pere de l'arboresence ;
  967. * aliastop - alias de l'item pere de l'arboresence ;
  968. ****/
  969. function &home($ar=NULL) {
  970. XLogs::debug('XModInfoTree::home: start');
  971. $p = new XParam($ar, array('level'=>'1','deroule'=>'1','sections'=>'1','myself'=>false,'tplentry'=>'mit','maxlevel'=>99,
  972. 'lastupd'=>false,'optimized'=>false,'cond_categ'=>array(),'where_categ'=>false));
  973. $do = $p->get('do');
  974. $myself=$p->get('myself');
  975. $niv = $p->get('level');
  976. $linkinfollow=$p->get('linkinfollow');
  977. $optimized = $p->get('optimized');
  978. $aliastop = $p->get('aliastop');
  979. $published = $p->get('_published');
  980. if(!empty($aliastop)) {
  981. if(Kernel::isAKoid($aliastop)) $oidtop=$aliastop;
  982. else $oidtop=$this->getOidFromAlias($aliastop);
  983. }
  984. if(empty($oidtop))
  985. $oidtop = $p->get('oidtop');
  986. $deroule = $p->get('deroule');
  987. if(!isset($deroule)) $deroule = $p->get('unfoldall');
  988. $computesections=$p->get('sections');
  989. $norubric=$p->get('norubric');
  990. $oidselected = $p->get('oid');
  991. $tplentry=$p->get('tplentry');
  992. $LANG_DATA = XShell::getLangData($p->get('LANG_DATA'));
  993. $LANG_TRAD = XShell::getLangData($p->get('LANG_TRAD'));
  994. if(!empty($LANG_TRAD)) {
  995. $lang_tree=$LANG_TRAD;
  996. $lang_other=$LANG_DATA;
  997. }
  998. $maxlevel = $p->get('maxlevel');
  999. $selectedfields=$p->get('selectedfields');
  1000. if(XShell::admini_mode()) setSessionVar('module_name',$this->modulename);
  1001. if($norubric) $rubric=array();
  1002. else $rubric = getSessionVar('rubric');
  1003. if($do=='add') {
  1004. $st1=$this->getPath($oidselected);
  1005. foreach($st1['oiddown'] as $i=>$oid1) $rubric[$oid1]='1';
  1006. } elseif($do=='del') {
  1007. unset($rubric[$oidselected]);
  1008. } elseif($do=='foldall') {
  1009. clearSessionVar('rubric');
  1010. $rubric=array();
  1011. } elseif($do=='unfoldall') {
  1012. $deroul=true;
  1013. } elseif($do=='showtree') {
  1014. $deroul=true;
  1015. $deroule=1;
  1016. }
  1017. if(empty($this->_rbrowse)) {
  1018. $options=array();
  1019. if(XShell::admini_mode() || $optimized) {
  1020. $options['linkup']=array('nofollowlinks'=>1);
  1021. }
  1022. if(empty($selectedfields)){
  1023. if(XShell::admini_mode()) $selectedfields = array('UPD','PUBLISH','title','corder','linkup','alias','picto','descr',$this->linkin);
  1024. else $selectedfields='all';
  1025. }elseif(is_array($selectedfields)){
  1026. $selectedfields=array_merge($selectedfields,array('UPD','PUBLISH','title','corder','linkup','alias','picto','descr',$this->linkin));
  1027. }
  1028. $cond_categ = $p->get('cond_categ');
  1029. $where_categ = $p->get('where_categ');
  1030. $query = $this->_categories->select_query(array('cond'=>$cond_categ,
  1031. 'where'=>$where_categ,
  1032. 'selectedfields'=>$selectedfields,
  1033. 'LANG_DATA'=>$lang_tree));
  1034. $this->_rbrowse=&$this->_categories->browse(array('select'=>$query,
  1035. 'pagesize'=>9999,
  1036. 'selectedfields'=>$selectedfields,
  1037. '_charset'=>@$_REQUEST['_charset'],
  1038. 'order'=>'corder',
  1039. 'options'=>$options,
  1040. 'tplentry'=>TZR_RETURN_DATA,
  1041. 'last'=>'9999','nocount'=>'1',
  1042. '_options'=>array('local'=>1)));
  1043. $this->_rbrowse['objects_sec']=$GLOBALS['XUSER']->getObjectsAccess($this,
  1044. XShell::getLangData(),
  1045. $this->_rbrowse['lines_oid']);
  1046. // appliquer les droits sur les objets
  1047. if ($this->object_sec) {
  1048. $levelMax = $GLOBALS['XUSER']->secure8maxlevel($this, null, null, XShell::getLangData());
  1049. // construction de l'arbre descendant pour l'héritage des droits
  1050. foreach ($this->_rbrowse['lines_oid'] as $i => $oid) {
  1051. $up = $this->_rbrowse['lines_olinkup'][$i]->raw;
  1052. if (empty($this->_rbrowse['treedown'][$up]))
  1053. $this->_rbrowse['treedown'][$up] = array();
  1054. $this->_rbrowse['treedown'][$up][] = $oid;
  1055. }
  1056. $this->_rbrowse['oid_index'] = array_flip($this->_rbrowse['lines_oid']);
  1057. // calcul des droits cumulés héritables et des enfants
  1058. foreach ($this->_rbrowse['lines_oid'] as $i => $oid) {
  1059. $this->_rbrowse['upobjects_sec'][$i] = $this->_upRights($i);
  1060. $this->_rbrowse['downobjects_sec'][$i] = $this->_downRights($i, $oid);
  1061. }
  1062. foreach ($this->_rbrowse['lines_oid'] as $i => $oid) {
  1063. // si pas de droits spécifiques sur ce noeud, hériter
  1064. if (array_pop(array_keys($this->_rbrowse['objects_sec'][$i])) == $levelMax && !empty($this->_rbrowse['upobjects_sec'][$i])) {
  1065. $this->_rbrowse['objects_sec'][$i] = $this->_rbrowse['upobjects_sec'][$i];
  1066. }
  1067. }
  1068. // suppression des noeuds non lisibles et sans enfants lisibles
  1069. foreach ($this->_rbrowse['lines_oid'] as $i => $oid) {
  1070. if (!isset($this->_rbrowse['objects_sec'][$i]['ro']) && !isset($this->_rbrowse['downobjects_sec'][$i]['ro'])) {
  1071. unset($this->_rbrowse['lines_oid'][$i]);
  1072. }
  1073. }
  1074. }
  1075. XLogs::debug('XModInfoTree: after security sort');
  1076. }
  1077. $rbrowse=&$this->_rbrowse;
  1078. if(!empty($published)) {
  1079. foreach($this->_rbrowse['lines_oid'] as $i => $oid) {
  1080. $pub1=$this->_rbrowse['lines_published'][$i];
  1081. if(empty($pub1)||($pub1==2)) {
  1082. unset($this->_rbrowse['lines_oid'][$i]);
  1083. }
  1084. }
  1085. }
  1086. // on affiche la poubelle que si c'est l'alias qui est explicitement demandé
  1087. if($aliastop!='trash') {
  1088. $trashoid=$this->getTrashOid();
  1089. if(!empty($trashoid)) {
  1090. foreach($this->_rbrowse['lines_oid'] as $i => $oid) {
  1091. if($oid==$trashoid) {
  1092. unset($this->_rbrowse['lines_oid'][$i]);
  1093. break;
  1094. }
  1095. }
  1096. }
  1097. }
  1098. // on recherche les sommets a parcourir
  1099. $stack=array();
  1100. $koids=array_flip($rbrowse['lines_oid']);
  1101. $koidtoprocess=array_reverse($rbrowse['lines_oid'],TRUE);
  1102. $todel=array();
  1103. foreach($koidtoprocess as $i => $oid) {
  1104. $curi=$koids[$oid];
  1105. $linkup = $rbrowse['lines_olinkup'][$curi]->raw;
  1106. if($myself){
  1107. if($oid==$oidtop){
  1108. array_push($stack, array($oid,$niv,$curi,1,$linkup));
  1109. array_push($todel, $i);
  1110. break;
  1111. }
  1112. }else{
  1113. if((empty($oidtop) && empty($linkup)) || ($oidtop==$linkup)) {
  1114. array_push($stack, array($oid,$niv,$curi,1,$linkup));
  1115. array_push($todel, $i);
  1116. }
  1117. }
  1118. }
  1119. while(count($todel)>0) unset($koidtoprocess[array_pop($todel)]);
  1120. // recherche du nombre de sous-noeuds
  1121. $section_nb = selectQuery('SELECT KOIDSRC,count(KOIDSRC) from '.$this->tname.' group by KOIDSRC')
  1122. ->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP|PDO::FETCH_UNIQUE);
  1123. // construction de l'arbre descendant
  1124. $treedown = array();
  1125. foreach($rbrowse['lines_oid'] as $i => $oid) {
  1126. $up=$rbrowse['lines_olinkup'][$i]->raw;
  1127. if(empty($treedown[$up])) $treedown[$up]=array();
  1128. $treedown[$up][]=$oid;
  1129. }
  1130. // on parcourt ce qui nous interesse
  1131. $r=array();
  1132. $r['aliastop']=$aliastop;
  1133. $r['self']=$this->_categories->display(array('tplentry'=>TZR_RETURN_DATA,'oid'=>$oidtop,'_options'=>array('local'=>true)));
  1134. $r['lines_oid']=array();
  1135. $lines_oid_cnt=0;
  1136. $r['lines_level']=array();
  1137. $r['lines_deroule']=array();
  1138. $r['lines_ssrub']=array();
  1139. $r['lines_sections']=array();
  1140. $r['lines_lvl1pagenum']=array();
  1141. $lvl1pagenum=0;
  1142. $newkoids=array();
  1143. while(!empty($stack)) {
  1144. // on depile l'element a traiter
  1145. list($curoid,$curlevel,$curi,$curderoul,$linkup)=array_pop($stack);
  1146. if($curderoul && ($curlevel<=$maxlevel || isset($rubric[$curoid]) || isset($rubric[$linkup]))) {
  1147. $r['lines_oid'][]=$curoid;
  1148. $newkoids[$curoid]=$lines_oid_cnt;
  1149. $lines_oid_cnt++;
  1150. $r['lines_level'][]=$curlevel;
  1151. $r['lines_ssrub'][]=0;
  1152. if($computesections=='1') {
  1153. if(!empty($section_nb[$curoid])) $r['lines_sections'][]=$section_nb[$curoid];
  1154. else $r['lines_sections'][]=0;
  1155. }
  1156. if($do=='unfoldall') {
  1157. $rubric[$curoid]='1';
  1158. }
  1159. $deroul=($do=='showtree'?'1':'0');
  1160. $deroul=$deroul || (empty($rubric[$curoid])?'0':'1');
  1161. $r['lines_deroule'][]=$deroul;
  1162. if($curlevel>1) $lvl1pagenum++;
  1163. else $lvl1pagenum=0;
  1164. $r['lines_lvl1pagenum'][]=$lvl1pagenum;
  1165. }
  1166. $tmp1=@$newkoids[$rbrowse['lines_olinkup'][$curi]->raw];
  1167. if(empty($r['lines_ssrub'][$tmp1])) $r['lines_ssrub'][$tmp1]=1;
  1168. else $r['lines_ssrub'][$tmp1]++;
  1169. if($this->linkin && $linkinfollow && $linkin && $linkin!=$rbrowse['lines_olinkup'][$curi]->raw){
  1170. $tmp1=@$newkoids[$linkin];
  1171. if(empty($r['lines_ssrub'][$tmp1])) $r['lines_ssrub'][$tmp1]=1;
  1172. else $r['lines_ssrub'][$tmp1]++;
  1173. }
  1174. $ocuroid=$curoid;
  1175. if($this->linkin && $linkinfollow && $rbrowse['lines_o'.$this->linkin][$curi]->raw)
  1176. $curoid=$rbrowse['lines_o'.$this->linkin][$curi]->raw;
  1177. if(!empty($treedown[$curoid]) && is_array($treedown[$curoid])) {
  1178. $todel=array();
  1179. foreach(array_reverse($treedown[$curoid]) as $i => $oid) {
  1180. $oldi=$koids[$oid];
  1181. $stack[]=array($oid,$curlevel+1,$oldi,$deroul,$ocuroid);
  1182. $todel[]=$i;
  1183. }
  1184. foreach($todel as $t1=>$toid) unset($koidtoprocess[$toid]);
  1185. }
  1186. $curoid=$ocuroid;
  1187. }
  1188. if(!issetSessionVar('rubric')) {
  1189. if(!empty($rubric)) {
  1190. setSessionVar('rubric',$rubric);
  1191. }
  1192. } else {
  1193. if(!empty($rubric)) {
  1194. setSessionVar('rubric',$rubric);
  1195. } else {
  1196. clearSessionVar('rubric');
  1197. }
  1198. }
  1199. // recopie des donnees du browse
  1200. $norw=array('lines_all_labels','lines_all_codes');
  1201. $rwall=array('objects_sec'=>true,'upobjects_sec'=>true);
  1202. foreach($r['lines_oid'] as $i => $oid) {
  1203. $oldi = $koids[$oid];
  1204. foreach($rbrowse as $k => $v) {
  1205. if(((substr($k, 0,6)=='lines_')||!empty($rwall[$k])) && !in_array($k,$norw)) {
  1206. $r[$k][$i]=(empty($v[$oldi])?NULL:$v[$oldi]);
  1207. }
  1208. if(!empty($r['lines_o'.$this->linkin][$i]->raw)){
  1209. $r['lines_sections'][$i]=@$section_nb[$r['lines_o'.$this->linkin][$i]->raw];
  1210. }
  1211. }
  1212. if(!empty($r['lines_o'.$this->linkin][$i]->raw)){
  1213. $r['lines_sections'][$i]=@$section_nb[$r['lines_o'.$this->linkin][$i]->raw];
  1214. }
  1215. }
  1216. foreach($r['lines_oid'] as $i => $oid) {
  1217. $r['lines_selfurl'][$i]=$this->_selfUrl($oid,$r['lines_oalias'][$i]->toText());
  1218. }
  1219. if(!empty($this->linkin) && $this->_categories->fieldExists($this->linkin)) {
  1220. $r['lines_olinkin']=&$r['lines_o'.$this->linkin];
  1221. }
  1222. $r['moid']=$this->_moid;
  1223. if (XShell::admini_mode()) {
  1224. $r['_editLevel'] = array