PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/class.xmodinfotree.inc

https://github.com/jcplat/console-seolan
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
  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_shift($this->secGroups('editpage'));
  1225. $r['_inputLevel'] = array_shift($this->secGroups('input'));
  1226. $r['_viewLevel'] = array_shift($this->secGroups('viewpage'));
  1227. }
  1228. XLogs::debug('XModInfoTree::home: end');
  1229. return Xshell::toScreen1($tplentry,$r);
  1230. }
  1231. // calcul les droits héritables
  1232. private function _upRights($i, $first=true) {
  1233. if ($this->_rbrowse['lines_olinkup'][$i]->raw) {
  1234. // calcul des droits du parent
  1235. $upRights = $this->_upRights($this->_rbrowse['oid_index'][$this->_rbrowse['lines_olinkup'][$i]->raw], false);
  1236. if ($first) {
  1237. return $upRights;
  1238. } else {
  1239. return array_merge($this->_rbrowse['objects_sec'][$i], $upRights);
  1240. }
  1241. } else {
  1242. return array();
  1243. }
  1244. }
  1245. // calcul les droits sur les enfants (+ droit sur l'objet)
  1246. private function _downRights($i, $oid) {
  1247. $downRights = $this->_rbrowse['objects_sec'][$i];
  1248. foreach ($this->_rbrowse['treedown'][$oid] as $_oid) {
  1249. $_i = $this->_rbrowse['oid_index'][$_oid];
  1250. if (!isset($this->_rbrowse['downobjects_sec'][$_i]))
  1251. $this->_rbrowse['downobjects_sec'][$_i] = $this->_downRights($_i, $_oid);
  1252. $downRights = array_merge($downRights, $this->_rbrowse['downobjects_sec'][$_i]);
  1253. }
  1254. return $downRights;
  1255. }
  1256. /// Rend les infos sur les rubriques mere de la rubrique oid
  1257. function getPath($ar) {
  1258. if(is_array($ar)){
  1259. $oid=$ar['oid'];
  1260. $tplentry=$ar['tplentry'];
  1261. $selectedfields = $ar['selectedfields'];
  1262. }else{
  1263. $oid=$ar;
  1264. }
  1265. if(empty($selectedfields)) $selectedfields = array('title','alias','linkup','style');
  1266. // Browse de la categorie
  1267. $v1=array();
  1268. $stack=array();
  1269. $nav_alias=$nav_cat=$nav_oid=$nav_url=array();
  1270. do{
  1271. $categ=$this->_categories->rDisplay($oid, array(), false,'','',array('selectedfields'=>$selectedfields));
  1272. if(!is_array($categ)) break;
  1273. $stack[]=$categ;
  1274. $nav_cat[]= $categ['otitle']->toText();
  1275. $nav_oid[]= $oid;
  1276. $nav_alias[]=$categ['oalias']->toText();
  1277. $nav_url[]='&moid='.$this->_moid.'&function=viewpage&template=xmodinfotree/viewpage.html&oidit='.$oid.'&tplentry=it';
  1278. $oid=$categ['olinkup']->raw;
  1279. unset($categ);
  1280. } while($oid);
  1281. $v1=array('labelup'=>$nav_cat,'urlup'=>$nav_url,'oidup'=>$nav_oid,'aliasup'=>$nav_alias,
  1282. 'labeldown'=>array_reverse($nav_cat),'urldown'=>array_reverse($nav_url),
  1283. 'aliasdown'=>array_reverse($nav_alias),
  1284. 'oiddown'=>array_reverse($nav_oid),
  1285. 'stack'=>array_reverse($stack));
  1286. if(!empty($tplentry)) XShell::toScreen1($tplentry,$v1);
  1287. return $v1;
  1288. }
  1289. function _getPathOids($oid) {
  1290. $stack=array();
  1291. $ors['linkup']=$oid;
  1292. do{
  1293. $stack[]=$ors['linkup'];
  1294. $rs = selectQuery('SELECT linkup FROM '.$this->table.' WHERE KOID="'.$ors['linkup'].'"');
  1295. } while($ors=$rs->fetch());
  1296. return $stack;
  1297. }
  1298. function getPathString($koid) {
  1299. $nav=$this->getPath($koid);
  1300. $title='';
  1301. foreach($nav['labeldown'] as $t) $title.='> '.$t;
  1302. return $title;
  1303. }
  1304. protected function _followLinkIn($oid) {
  1305. $links=array();
  1306. if($this->_categories->fieldExists($this->linkin)) {
  1307. $found=false;
  1308. while(!$found && !in_array($oid, $links)) {
  1309. $links[]=$oid;
  1310. $query = 'SELECT KOID,'.$this->linkin.' FROM '.$this->_categories->getTable().
  1311. ' WHERE LANG="'.TZR_DEFAULT_LANG.'" AND KOID="'.$oid.'"';
  1312. $rs=selectQuery($query);
  1313. if(!$ors=$rs->fetch()) {
  1314. $found=true;
  1315. } else {
  1316. if(!Kernel::isAKoid($ors[$this->linkin])) {
  1317. $found=true;
  1318. } else {
  1319. $oid=$ors[$this->linkin];
  1320. }
  1321. $rs->closeCursor();
  1322. }
  1323. }
  1324. }
  1325. return $oid;
  1326. }
  1327. /****m* XModInfoTree/procInput
  1328. * NAME
  1329. * XModInfoTree::procInput - creation d'une nouvelle rubrique
  1330. * DESCRIPTION
  1331. * Fonction d'ajout d'une rubrique dans l'admin en tenant compte du chgement d'ordre d'affichage.
  1332. * INPUTS
  1333. ****/
  1334. function &procInput($ar=NULL) {
  1335. $p = new XParam($ar, array());
  1336. $title = $p->get('title');
  1337. $linkup = $p->get('linkup');
  1338. $order = $p->get('corder');
  1339. $alias = $p->get('alias');
  1340. if(empty($order)) $order='0';
  1341. $ar['tplentry']=TZR_RETURN_DATA;
  1342. $message='';
  1343. $this->_checkAlias($alias, '', NULL, $message, $title);
  1344. $ar['alias']=$alias;
  1345. if(!empty($message)) {
  1346. XShell::setNextData('message', $message);
  1347. }
  1348. $r=$this->_categories->procInput($ar);
  1349. // positionnement des droits
  1350. if(!empty($this->object_sec)) {
  1351. $GLOBALS['XUSER']->setUserAccess(get_class($this),$this->_moid,XShell::getLangData(),$r['oid'],'admin');
  1352. }
  1353. // maj de l'order d'affichage de la rubrique.
  1354. $this->majUpOtherOrder($title,$linkup,$order);
  1355. return $r;
  1356. }
  1357. /****m* XModInfoTree/edit
  1358. * NAME
  1359. * XModInfoTree::edit - creation d'une nouvelle rubrique
  1360. * DESCRIPTION
  1361. * Fonction d'edition d'une rubrique dans l'admin en tenant compte du chgement d'ordre d'affichage.
  1362. * INPUTS
  1363. ****/
  1364. //
  1365. //
  1366. function edit($ar=NULL) {
  1367. $this->_categories->edit($ar);
  1368. $GLOBALS['XSHELL']->tpldata['']['moid']=$this->_moid;
  1369. }
  1370. function input($ar=NULL) {
  1371. $p = new XParam($ar, array());
  1372. $ar['options']['linkup']['value']=$p->get('linkup');
  1373. $ar['options']['corder']['value']=$p->get('order');
  1374. $this->_categories->input($ar);
  1375. $GLOBALS['XSHELL']->tpldata['']['title']=$GLOBALS['XSHELL']->tpldata['']['otitle']->html;
  1376. $GLOBALS['XSHELL']->tpldata['']['order']=$GLOBALS['XSHELL']->tpldata['']['ocorder']->html;
  1377. $GLOBALS['XSHELL']->tpldata['']['alias']=$GLOBALS['XSHELL']->tpldata['']['oalias']->html;
  1378. $GLOBALS['XSHELL']->tpldata['']['moid']=$this->_moid;
  1379. }
  1380. // mise a jour d'une rubrique
  1381. //
  1382. function procEdit($ar=NULL) {
  1383. $p = new XParam($ar, array());
  1384. $oidMere = $p->get('linkup');
  1385. $oid = $p->get('oid');
  1386. $alias = $p->get('alias');
  1387. $title = $p->get('title');
  1388. $langs = $p->get('_langs');
  1389. $lang_data = XShell::getLangData();
  1390. // Traitement des cas ou l'on veut sauver dans plusieurs langues
  1391. $ar['_langs']=$this->getAuthorizedLangs($langs,$oid,'procEdit');
  1392. if($lang_data == TZR_DEFAULT_LANG) {
  1393. $disp_cat = $this->_categories->display(array('oid'=>$oid,'tplentry'=>TZR_RETURN_DATA));
  1394. $message='';
  1395. $oldalias= $disp_cat['oalias']->raw;
  1396. // vérification alias
  1397. $this->_checkAlias($alias, $oldalias, $oid, $message, $title);
  1398. $ar['alias'] = $alias; // peut-être modifié par _checkAlias
  1399. // vérification de boucle sur linkin
  1400. if ($this->linkin) {
  1401. $linkin = $p->get($this->linkin);
  1402. if ($linkin && !$this->_checkLinkin($oid, $linkin)) {
  1403. $message .= '<br>' . $this->_categories->desc[$this->linkin]->label . ' : ' . XLabels::getSysLabel('xmodinfotree.circularity');
  1404. }
  1405. }
  1406. if (!empty($message)) {
  1407. unset($_REQUEST['skip'], $_REQUEST['_skip']);
  1408. XShell::changeTemplate('xmodinfotree/editcat.html');
  1409. XShell::setNext();
  1410. XShell::toScreen2('', 'message', $message);
  1411. $ar['options'] = $this->_categories->prepareReEdit($ar);
  1412. $ar['tplentry'] = 'editcat';
  1413. return $this->editcat($ar);
  1414. }
  1415. $oldOrder = $disp_cat['ocorder']->raw;
  1416. $ar['tplentry']='addrub';
  1417. $this->_categories->procEdit($ar);
  1418. } else {
  1419. $oldOrder = $disp_cat['ocorder']->raw;
  1420. $this->_categories->procEdit($ar);
  1421. }
  1422. // maj de l'order d'affichage de la rubrique.
  1423. $newOrder = $p->get('corder');
  1424. $titre = $p->get('title');
  1425. $oid = $p->get('linkup');
  1426. $this->majOtherOrder($titre,$oid,$oldOrder,$newOrder);
  1427. }
  1428. /// Mise à jour d'une rubrique dans de toutes les langues pour lesquel l'utilisateur à les droits
  1429. function procEditAllLang($ar) {
  1430. $ar['_langs']='all';
  1431. return $this->procEdit($ar);
  1432. }
  1433. // verification que l'alias est valide et generation eventuelle d'un alias
  1434. //
  1435. function _checkAlias(&$alias, $oldalias, $oid, &$message, $title=NULL) {
  1436. if(empty($alias) && !empty($title)) {
  1437. $alias=rewriteToAscii($title);
  1438. }
  1439. /* verification que les alias sont bien constitués de 2 à 40 chiffres, lettres _ et - */
  1440. $aliasfield=&$this->_categories->getField('alias');
  1441. $aliaslength=$aliasfield->get_fcount();
  1442. if(!preg_match('/^([a-zA-Z0-9_-]{1,'.$aliaslength.'})$/',$alias)) {
  1443. $message=XLabels::getSysLabel('xmodinfotree.aliasnotcorrect').' '.$alias;
  1444. $alias=$oldalias;
  1445. }
  1446. /* verification de l'unicite des alias */
  1447. if(!empty($alias) ) {
  1448. $req = "select count(*) from ".$this->_categories->getTable()." where alias='".$alias."' ";
  1449. if(!empty($oid)) $req .= "and KOID != '".$oid."' ";
  1450. $cnt=countSelectQuery($req);
  1451. if($cnt>0) {
  1452. $message=XLabels::getSysLabel('xmodinfotree.aliasunique').' '.$alias;
  1453. $alias=$oldalias;
  1454. }
  1455. }
  1456. /* verification si l'alias est protege */
  1457. if(($oldalias!=$alias) && !empty($oldalias) && $this->aliasIsProtected($oldalias)) {
  1458. $message=XLabels::getSysLabel('xmodinfotree.aliasprotected').' '.$alias;
  1459. $alias=$oldalias;
  1460. $modif = 1;
  1461. }
  1462. }
  1463. // test de circularité des redirections
  1464. function _checkLinkin($oid, $linkin) {
  1465. $path = $this->_getPathOids($oid);
  1466. array_pop($path); // le dernier élément est vide
  1467. // test la cible
  1468. if (in_array($linkin, $path))
  1469. return false;
  1470. // test le lien de la cible
  1471. $target_linkin = selectQuery("select {$this->linkin} from {$this->table} where koid='$linkin'")->fetch(PDO::FETCH_COLUMN);
  1472. if ($target_linkin && in_array($target_linkin, $path))
  1473. return false;
  1474. // test les sous-noeuds de la cible
  1475. return $this->_checkLinkinChild($linkin, $path);
  1476. }
  1477. // test de circularité des redirections pour les descendants
  1478. function _checkLinkinChild($oid, $path) {
  1479. $children = selectQuery("select KOID, {$this->linkin} from {$this->table} where linkup='$oid'")->fetchAll();
  1480. foreach ($children as $child) {
  1481. if ($child[$this->linkin] && in_array($child[$this->linkin], $path))
  1482. return false;
  1483. if (!$this->_checkLinkinChild($child['KOID'], $path))
  1484. return false;
  1485. }
  1486. return true;
  1487. }
  1488. // Fonction de mise a jour de l'ordre d'affichage d'une rubrique.
  1489. //
  1490. function majUpOtherOrder($titre,$oid,$forder) {
  1491. if ($oid == '' ) {
  1492. $requete = 'UPDATE ' . $this->table .' set '.'corder'.
  1493. "=IF(corder<9,CONCAT('0',corder+1),corder+1) where title!='" .
  1494. $titre . "' and linkup = '' and corder>=" . $forder;
  1495. } else {
  1496. $requete = "UPDATE " . $this->table ." set corder=IF("."corder".
  1497. "<9,CONCAT('0',corder+1),corder+1) where title!='" . $titre.
  1498. "' and linkup = '$oid' and corder>=" . $forder;
  1499. }
  1500. updateQuery($requete);
  1501. }
  1502. // Fonction de mise a jour de l'ordre d'affichage d'une rubrique.
  1503. //
  1504. function majDownOtherOrder($titre,$oid,$forder) {
  1505. if ($oid == '' ) {
  1506. $requete = 'UPDATE ' . $this->table .' set corder=IF('.'corder'.
  1507. "<11,CONCAT('0',corder-1),corder-1) where title!='" .
  1508. $titre . "' and linkup = '' and corder>" . $forder;
  1509. } else {
  1510. $requete = 'UPDATE ' . $this->table .' set corder=IF('.'corder'.
  1511. "<9,CONCAT('0',corder-1),corder-1) where title!='" . $titre .
  1512. "' and linkup = '$oid' and corder>" . $forder;
  1513. }
  1514. updateQuery($requete);
  1515. }
  1516. // Fonction de mise a jour de l'ordre d'affichage d'une rubrique.
  1517. //
  1518. function majOtherOrder($titre,$oid,$oldOrder,$newOrder) {
  1519. // Si augmente, -- sur les order > old et <= new
  1520. // Si diminue, ++ sur les order >= new et < old
  1521. if ( $newOrder > $oldOrder ) {
  1522. // augmentation
  1523. if ($oid == '' ) {
  1524. $requete = 'UPDATE ' . $this->table .' set corder=IF('.'corder'.
  1525. "<11,CONCAT('0',corder-1),corder-1) where title!='" .
  1526. $titre . "' and linkup = '' and corder>" . $oldOrder . " and ".
  1527. "corder"." <=" . $newOrder;
  1528. } else {
  1529. $requete = "UPDATE " . $this->table ." set corder=IF("."corder".
  1530. "<11,CONCAT('0',corder-1),corder-1) where title!='" . $titre .
  1531. "' and linkup = '$oid' and corder>" . $oldOrder . " and corder <=" .
  1532. $newOrder;
  1533. }
  1534. }
  1535. if ( $newOrder < $oldOrder ) {
  1536. // diminution
  1537. if ($oid == '' ) {
  1538. $requete = 'UPDATE ' . $this->table ." set corder=IF(corder<9,CONCAT('0',".
  1539. "corder"."+1),corder-1) where title!='" . $titre . "' and ".
  1540. "linkup = '' and corder>=" . $newOrder . " and corder <" . $oldOrder;
  1541. } else {
  1542. $requete = 'UPDATE ' . $this->table ." set corder=IF(corder<9,CONCAT('0',".
  1543. "corder"."+1),corder-1) where title!='" . $titre . "' and ".
  1544. "linkup = '$oid' and corder>=" . $newOrder . " and corder <" . $oldOrder;
  1545. }
  1546. }
  1547. updateQuery($requete);
  1548. }
  1549. //
  1550. function confirmDel($ar=NULL) {
  1551. global $XSHELL;
  1552. $p = new XParam($ar, array( "tplentry"=>$this->table));
  1553. $oid=$p->get("oid");
  1554. $lang=XShell::getLangData();
  1555. $oidContenu = array();
  1556. $this->browse(array("oid"=>$oid,"level"=>$niv), $oidContenu);
  1557. $result = array();
  1558. $result["oid"] = $oid;
  1559. $result["level"] = $niv;
  1560. $XSHELL->tpldata["$tplentry"] = $result;
  1561. }
  1562. // rend la liste des templates avec eventuellement un selecteur sur la table destination
  1563. // si subset est un ensemble de koid (tableau), seules les reponses
  1564. // deja presente dans ce tableau seront retournees
  1565. //
  1566. protected function &_templatesList($tabledst=NULL,$filter="page",$oidit=NULL) {
  1567. if(!empty($oidit) && $this->_categories->fieldExists('alayout')) {
  1568. $r2= &$this->_categories->display(array("oid"=>$oidit,
  1569. "_options"=>array("error"=>"return"),
  1570. "tplentry"=>TZR_RETURN_DATA,
  1571. "fallback"=>true));
  1572. }
  1573. if(!empty($r2['oalayout']->oidcollection)) {
  1574. $subset=$r2['oalayout']->oidcollection;
  1575. if(!empty($tabledst)) {
  1576. $cond = $this->_templates->select_query(array("cond"=>array('tab'=>array("=",$tabledst),
  1577. "modid"=>array("=",array($this->_moid,'')),
  1578. "KOID"=>array("=",$subset))));
  1579. } else {
  1580. $cond = $this->_templates->select_query(array("cond"=>array("modid"=>array("=",array($this->_moid,'')),
  1581. "gtype"=>array("=",$filter),
  1582. "KOID"=>array("=",$subset))));
  1583. }
  1584. } else {
  1585. if(!empty($tabledst)) {
  1586. $cond = $this->_templates->select_query(array("cond"=>array('tab'=>array("=",$tabledst),
  1587. "modid"=>array("=",array($this->_moid,'')))));
  1588. } else {
  1589. $cond = $this->_templates->select_query(array("cond"=>array("modid"=>array("=",array($this->_moid,'')),
  1590. "gtype"=>array("=",$filter))));
  1591. }
  1592. }
  1593. $r=&$this->_templates->browse(array("select"=>$cond,"first"=>"0","last"=>"999","pagesize"=>99,
  1594. "order"=>'title',
  1595. "tplentry"=>TZR_RETURN_DATA,
  1596. "selectedfields"=>array("title","tab",'functions', 'modidd')));
  1597. return $r;
  1598. }
  1599. // rend les donnees concernant un template d'oid fourni
  1600. //
  1601. function &_disp2Template($oidt=NULL) {
  1602. $opt=array();
  1603. $opt["oid"]=$oidt;
  1604. $opt["tplentry"]=TZR_RETURN_DATA;
  1605. $opt["_options"]=array("error"=>"return");
  1606. $opt["fallback"]="true";
  1607. $opt["_cacheobject"]="disp2template";
  1608. $opt["_lastupdate"]=false;
  1609. $r=$this->_templates->display($opt);
  1610. return $r;
  1611. }
  1612. function editsection($ar) {
  1613. global $XSHELL;
  1614. $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
  1615. $tplentry = $p->get("tplentry");
  1616. $oidit = $p->get("oidit");
  1617. $lang = XShell::getLangData();
  1618. $oidsection=$p->get("oidsection");
  1619. list($oidit,$oiddest,$oidtemplate)=$this->_getOids($oidsection);
  1620. $tableofoid=Kernel::getTable($oiddest);
  1621. // Browse des modeles de mise en page
  1622. XShell::toScreen1('tple', $this->_templatesList($tableofoid,'page', $oidit));
  1623. // infos d'affichage du template
  1624. $r1=$this->_disp2Template($oidtemplate);
  1625. XShell::toScreen1('tp',$r1);
  1626. $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tableofoid);
  1627. $ar["tplentry"]=TZR_RETURN_DATA;
  1628. $ar['oid']=$oiddest;
  1629. $ar['fallback']=true;
  1630. if(empty($ar['fmoid'])) $ar['fmoid']=$this->_moid;
  1631. $r=$xst->edit($ar);
  1632. $s['olines'][]=$r;
  1633. $s['olines_oid'][]=$oiddest;
  1634. XShell::toScreen1('it',$s);
  1635. XShell::toScreen1($tplentry,$r);
  1636. XShell::toScreen2('section','oidit',$oidit);
  1637. XShell::toScreen2('section','oidsection',$oidsection);
  1638. }
  1639. // affichage des donnees d'un objet particulier d'une page
  1640. //
  1641. function displaysection($ar) {
  1642. $p = new XParam($ar, array("level"=>1,"tplentry"=>"it",
  1643. "toc"=>"1","maxlevel"=>1));
  1644. $tplentry = $p->get("tplentry");
  1645. $oidsection = $p->get("oidsection");
  1646. $lang = XShell::getLangData();
  1647. $tab= XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$oidsection);
  1648. if($tplentry==TZR_RETURN_DATA)
  1649. return $tab->display(array("oid"=>$oidsection, "tplentry"=>TZR_RETURN_DATA));
  1650. else
  1651. $tab->display(array("oid"=>$oidsection, "tplentry"=>$tplentry));
  1652. }
  1653. /// Liste les types de sections qui peuvent etre créées
  1654. public function addSection($ar=NULL){
  1655. $p=new XParam($ar,NULL);
  1656. $tplentry=$p->get('tplentry');
  1657. $oidit=$p->get('oidit');
  1658. $r['page']=&$this->_templatesList(NULL, 'page', $oidit);
  1659. $r['query']=&$this->_templatesList(NULL, 'query', $oidit);
  1660. $r['function']=&$this->_templatesList(NULL, 'function', $oidit);
  1661. $r['position'] = selectQuery('select ORDER1 from '.$this->tname.' WHERE KOIDSRC="'.$oidit.'" order by ORDER1')->fetchAll(PDO::FETCH_COLUMN);
  1662. $r['oidit']=$oidit;
  1663. $modlist = XModule::modlist(array('tplentry'=>TZR_RETURN_DATA, 'basic' => 1, 'withmodules'=>1));
  1664. for ($i=0; $i<count($modlist['lines_oid']); $i++) {
  1665. $uiFunctions = $modlist['lines_mod'][$i]->getUIFunctionList();
  1666. if ($modlist['lines_mod'][$i]->available_in_display_modules && !empty($uiFunctions)) {
  1667. $r['modlist']['lines_oid'][] = $modlist['lines_oid'][$i];
  1668. $r['modlist']['lines_mod'][] = $modlist['lines_mod'][$i];
  1669. $r['modlist']['lines_name'][] = $modlist['lines_name'][$i];
  1670. $r['modlist']['lines_group'][] = $modlist['lines_group'][$i];
  1671. $r['modlist']['lines_toid'][] = $modlist['lines_toid'][$i];
  1672. $r['modlist']['lines_classname'][] = $modlist['lines_classname'][$i];
  1673. $r['modlist']['lines_functions'][] = $uiFunctions;
  1674. $class = get_class($modlist['lines_mod'][$i]);
  1675. $r['modlist']['lines_classes'][] = array_merge(class_parents($modlist['lines_mod'][$i]), array($class => $class));
  1676. }
  1677. }
  1678. return XShell::toScreen1($tplentry,$r);
  1679. }
  1680. /// preparation de l'ecran de saisie d'une nouvelle section
  1681. function newsection($ar) {
  1682. global $XSHELL;
  1683. $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
  1684. $tplentry = $p->get("tplentry");
  1685. $oidit = $p->get("oidit");
  1686. $oidtpl = $p->get("oidtpl");
  1687. $lang = XShell::getLangData();
  1688. $tabletpl=Kernel::getTable($oidtpl);
  1689. $rs=selectQuery("select * from $tabletpl where KOID='$oidtpl' AND LANG='$lang'");
  1690. if($o1=$rs->fetch()) {
  1691. $tabledst = $o1['tab'];
  1692. // Browse des modeles de mise en page
  1693. XShell::toScreen1('tple', $this->_templatesList($tabledst,"page",$oidit));
  1694. // infos d'affichage du template
  1695. $r1=$this->_disp2Template($oidtpl);
  1696. XShell::toScreen1('tp',$r1);
  1697. $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
  1698. $ar["tplentry"]=TZR_RETURN_DATA;
  1699. if(empty($ar['fmoid'])) $ar['fmoid']=$this->_moid;
  1700. $r=$xst->input($ar);
  1701. $s['position']=$p->get('position');
  1702. $s['oidit']=$p->get('oidit');
  1703. $s['oidtpl']=$p->get('oidtpl');
  1704. $s['olines'][]=$r;
  1705. $s['olines_oid'][]=$xst->getNewOID($ar);
  1706. XShell::toScreen1($tplentry,$s);
  1707. }
  1708. }
  1709. function editquery($ar) {
  1710. $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
  1711. $tplentry = $p->get("tplentry");
  1712. $oidsection = $p->get("oidsection");
  1713. list($oidsrc,$oiddest,$oidtpl)=$this->_getOids($oidsection);
  1714. // recherche de l'item
  1715. $rs=selectQuery("select * from ".$this->tname." where ITOID='$oidsection'");
  1716. if(!$ors=$rs->fetch()) return array();
  1717. $qinit = unserialize($ors['QUERY']);
  1718. // table des templates
  1719. $rtpl=$this->_disp2Template($oidtpl);
  1720. $tabledst = $rtpl['otab']->raw;
  1721. XShell::toScreen1('tple',$this->_templatesList($tabledst,'query',$oidit));
  1722. // table dans laquelle se trouvenet les donnes
  1723. $table = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
  1724. $query=array();
  1725. if(is_array($qinit)) {
  1726. $query['operator']=$qinit['operator'];
  1727. foreach($table->desc as $k => $v) {
  1728. if(isset($qinit[$k]) || !empty($qinit[$k.'_PAR'])) {
  1729. if($table->fieldExists($k)) {
  1730. $query[$k]=$qinit['options'][$k];
  1731. $query[$k]['value']=$qinit[$k];
  1732. $query[$k]['op']=$qinit[$k.'_op'];
  1733. $query[$k]['par']=$qinit[$k.'_PAR'];
  1734. $query[$k]['fmt']=(isset($qinit[$k.'_FMT'])?$qinit[$k.'_FMT']:$qinit[$k.'_HID']);
  1735. $query[$k]['notapplyqfmt']=true;
  1736. } else {
  1737. $query[$k]=$qinit[$k];
  1738. }
  1739. }
  1740. }
  1741. }
  1742. $ar['tplentry']=TZR_RETURN_DATA;
  1743. $ar['options']=$query;
  1744. $ar['querymode']='pquery';
  1745. if(empty($ar['fmoid'])) $ar['fmoid']=$this->_moid;
  1746. $r=$table->query($ar);
  1747. $r['oidit']=$oidsrc;
  1748. $r['_select']=$qinit['_select'];
  1749. $r['oidsection']=$oidsection;
  1750. $r['pagesize']=$qinit['pagesize'];
  1751. $r['setup']=$oidtpl;
  1752. $r['labelin']=$qinit['labelin'];
  1753. if(is_array($qinit['order'])) {
  1754. foreach($qinit['order'] as $ki=>$vi){
  1755. $torder=explode(" ",$qinit['order'][$ki]);
  1756. $r['order'][$ki]=$torder[0];
  1757. $r['_order'][$ki]=$torder[1];
  1758. }
  1759. } else {
  1760. $torder=explode(" ",$qinit['order']);
  1761. $r['order'][0]=$torder[0];
  1762. $r['_order'][0]=$torder[1];
  1763. }
  1764. foreach($r['order'] as $ki=>$vi){
  1765. $r['fieldselector'][$ki]=$table->order_selector(array('fieldname'=>'order[]','value'=>$r['order'][$ki],'random'=>($ki==0),
  1766. 'compulsory'=>($ki==0)
  1767. )
  1768. );
  1769. }
  1770. if(empty($r['fieldselector'][0])) $r['fieldselector'][0] = $table->order_selector(array('fieldname'=>'order[]',
  1771. 'value'=>'','compulsory'=>false));
  1772. $r['emptyfieldselector'] = $table->order_selector(array('fieldname'=>'order[]','value'=>'','compulsory'=>false));
  1773. $r['weborderselector'] = $table->order_selector(array('fieldname'=>'weborderselector[]','value'=>$qinit['weborderselector'],
  1774. 'compulsory'=>false,'random'=>false,'multiple'=>true));
  1775. $oidit=$oidsrc;
  1776. return XShell::toScreen1('section',$r);
  1777. }
  1778. function savequery($ar) {
  1779. $p = new XParam($ar, array('level'=>1,'tplentry'=>'it','toc'=>'1','maxlevel'=>1));
  1780. $tplentry = $p->get("tplentry");
  1781. $oidsection = $p->get("oidsection");
  1782. $weborderselector=$p->get('weborderselector');
  1783. $hasselect=$p->get('hasselect'); // true si la section utilise le mode expert et que l'on sauve sans les droits root
  1784. $labelin=$p->get('labelin');
  1785. // recherche de l'item
  1786. list($oidsrc,$oiddest,$oidtpl)=$this->_getOids($oidsection);
  1787. // table des templates
  1788. $rtpl=$this->_disp2Template($oidtpl);
  1789. // table dans laquelle se trouvenet les donnes
  1790. $table = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$rtpl['otab']->raw);
  1791. if($hasselect){
  1792. $rs=selectQuery("select * from ".$this->tname." where ITOID='$oidsection'");
  1793. if($ors=$rs->fetch()){
  1794. $qinit=unserialize($ors['QUERY']);
  1795. $ar['_select']=$qinit['_select'];
  1796. $rs->closeCursor();
  1797. }else{
  1798. $ar['_select']='';
  1799. }
  1800. }
  1801. $st=$table->captureQuery($ar);
  1802. $st['weborderselector']=$weborderselector;
  1803. $st['labelin']=$labelin;
  1804. $r=addslashes(serialize($st));
  1805. updateQuery("UPDATE ".$this->tname." SET QUERY='$r' where ITOID='$oidsection'");
  1806. $setup=$p->get("setup");
  1807. updateQuery("UPDATE ".$this->tname." set KOIDTPL='$setup' where ITOID='$oidsection'");
  1808. $ar["oidit"]=$oidsrc;
  1809. }
  1810. /// insertion d'une nouvelle section
  1811. function insertsection($ar=NULL) {
  1812. $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
  1813. $tplentry = $p->get("tplentry");
  1814. $oidit = $p->get("oidit");
  1815. $lang = XShell::getLangData();
  1816. $oidtpl=$p->get("oidtpl");
  1817. $tabletpl = Kernel::getTable($oidtpl);
  1818. $rs=selectQuery("select * from $tabletpl where KOID='$oidtpl' AND LANG='$lang'");
  1819. if($o1=$rs->fetch()) {
  1820. $tabledst = $o1['tab'];
  1821. $position = $p->get("position")+1;
  1822. $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
  1823. $ar2=$ar;
  1824. $ar2['tplentry']=TZR_RETURN_DATA;
  1825. $ar2['LANG_DATA']=$lang;
  1826. $r=$xst->procInput($ar2);
  1827. $oidsection=$r["oid"];
  1828. updateQuery("UPDATE ".$this->tname." SET ORDER1=ORDER1+1 where KOIDSRC='$oidit' ".
  1829. " AND ORDER1 >= $position");
  1830. $nitoid=self::newItOid();
  1831. updateQuery("INSERT INTO ".$this->tname." SET KOIDSRC='$oidit', KOIDDST='$oidsection',".
  1832. "KOIDTPL='$oidtpl', ORDER1='$position', QUERY=NULL, ITOID='$nitoid'");
  1833. $this->_reorderSections($oidit);
  1834. $rs=selectQuery("select * from ".$this->tname." where KOIDSRC='$oidit' ".
  1835. "and KOIDDST='$oidsection' and KOIDTPL='$oidtpl'");
  1836. $return = NULL;
  1837. if($rs && $ors=$rs->fetch()) {
  1838. $return = array("oid"=>$oidsection,"itoid"=>$ors['ITOID']);
  1839. }
  1840. $rs->closeCursor();
  1841. return $return;
  1842. }
  1843. }
  1844. /// generation d'une nouvelle cle dans la table de liaison
  1845. protected function newItOid() {
  1846. $id= substr(md5(uniqid(rand(), true)),0,40);
  1847. return $id;
  1848. }
  1849. /// insertion d'une requete dans la page
  1850. function insertquery($ar) {
  1851. $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
  1852. $oidtpl = $p->get("oidtpl");
  1853. $lang = XShell::getLangData();
  1854. $oidit = $p->get("oidit");
  1855. $rs=selectQuery("select * from TEMPLATES where KOID='$oidtpl'");
  1856. if($ors=$rs->fetch()) {
  1857. $tabledst=$ors['tab'];
  1858. $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
  1859. $position = $p->get("position")+1;
  1860. updateQuery("UPDATE ".$this->tname." SET ORDER1=ORDER1+1 where KOIDSRC='$oidit' ".
  1861. " AND ORDER1 > $position");
  1862. $val=serialize(array('pagesize'=>20,'UPD'=>'xxxx'));
  1863. $nitoid=self::newItOid();
  1864. updateQuery("INSERT INTO ".$this->tname." SET KOIDSRC='$oidit', KOIDDST='', KOIDTPL='$oidtpl', ORDER1='$position',QUERY='$val', ITOID='$nitoid'");
  1865. }
  1866. $rs->closeCursor();
  1867. $this->_reorderSections($oidit);
  1868. $this->editpage($ar);
  1869. }
  1870. function _getOids($oidsection) {
  1871. $rs=selectQuery("SELECT * FROM ".$this->tname." WHERE ITOID='$oidsection'");
  1872. $ors=array();
  1873. if($ors=$rs->fetch()) {
  1874. $oidtemplate=$ors['KOIDTPL'];
  1875. $oiddest=$ors['KOIDDST'];
  1876. $oidit=$ors['KOIDSRC'];
  1877. return array($oidit,$oiddest,$oidtemplate);
  1878. } else {
  1879. return NULL;
  1880. }
  1881. }
  1882. /// Change l'ordre et/ou le parent d'une section
  1883. public function moveSection($ar) {
  1884. $p = new XParam($ar, array());
  1885. $oidsection=$p->get("oidsection");
  1886. $oidit=$p->get("oidit");
  1887. $dir=$p->get("dir");
  1888. if(!isset($oidsection)) {
  1889. $oidsection=$p->get("_itoidselected");
  1890. foreach($oidsection as $oid => $foo) {
  1891. $ar['oidsection']=$oid;
  1892. $this->moveSection($ar);
  1893. }
  1894. return;
  1895. }
  1896. $new_p=$p->get("_dest");
  1897. if(!empty($new_p)){
  1898. if(!Kernel::isAKoid($new_p)) $new_p=$this->getOidFromAlias($new_p);
  1899. }else{
  1900. $new_p=$oidit;
  1901. }
  1902. // securite: dans tous les cas, si on a pas les droits d'ecriture sur la source
  1903. // on ne peut ni modifier l'ordre des sections, ni changer une section de page
  1904. if(!$this->secure($oidit, ':rw')) return;
  1905. if(($new_p!=$oidit ) && !$this->secure($new_p, ':rw')) return;
  1906. $this->_reorderSections($oidit);
  1907. if($new_p!=$oidit) $this->_reorderSections($new_p);
  1908. $o=countSelectQuery('select distinct ORDER1 from '.$this->tname.' where ITOID="'.$oidsection.'"');
  1909. if($dir=="top") {
  1910. $new_o=0;
  1911. } elseif($dir=="bottom") {
  1912. $new_o=999;
  1913. } elseif($dir=="up") {
  1914. $new_o=$o-1;
  1915. updateQuery('UPDATE '.$this->tname.' set ORDER1='.$o.' where ORDER1='.$new_o.' AND KOIDSRC="'.$oidit.'"');
  1916. } elseif($dir=="down") {
  1917. $new_o=$o+1;
  1918. updateQuery('UPDATE '.$this->tname.' set ORDER1='.$o.' where ORDER1='.$new_o.' AND KOIDSRC="'.$oidit.'"');
  1919. } elseif($dir=="to") {
  1920. $new_o=0;
  1921. } elseif(!empty($dir)) {
  1922. $new_o=countSelectQuery('select distinct ORDER1 from '.$this->tname.' where ITOID="'.$dir.'"')+1;
  1923. updateQuery('UPDATE '.$this->tname.' set ORDER1=ORDER1+1 where ORDER1>='.$new_o.' AND KOIDSRC="'.$oidit.'"');
  1924. } else{
  1925. $new_o=0;
  1926. }
  1927. updateQuery('UPDATE '.$this->tname.' set ORDER1='.$new_o.',KOIDSRC="'.$new_p.'" where ITOID="'.$oidsection.'"');
  1928. $this->_reorderSections($oidit);
  1929. if($new_p!=$oidit) $this->_reorderSections($new_p);
  1930. }
  1931. public function delSection($ar) {
  1932. $p = new XParam($ar, array());
  1933. $oidsection=$p->get("oidsection");
  1934. if(!isset($oidsection)) {
  1935. $oidsection=$p->get("_itoidselected");
  1936. if(is_array($oidsection)) {
  1937. foreach($oidsection as $oidit => $foo) {
  1938. $this->delSection(array("oidsection"=>$oidit));
  1939. }
  1940. }
  1941. return;
  1942. }
  1943. list($oidit,$oiddest,$oidtemplate)=$this->_getOids($oidsection);
  1944. $lang = $p->get('LANG_DATA');
  1945. if(!empty($oiddest)) {
  1946. $k = new Kernel;
  1947. $k->data_forcedDel(array("oid"=>$oiddest, "action"=>"OK","_selectedok"=>"nok"));
  1948. if($lang == TZR_DEFAULT_LANG) {
  1949. updateQuery("delete FROM ".$this->tname." WHERE ITOID='$oidsection' ");
  1950. }
  1951. } else {
  1952. updateQuery("delete FROM ".$this->tname." WHERE ITOID='$oidsection'");
  1953. }
  1954. $this->_reorderSections($oidit);
  1955. }
  1956. /// sauvegarde du contenu d'une section
  1957. function savesection($ar) {
  1958. $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
  1959. $langs=$p->get('_langs');
  1960. $oidsection=$p->get("oidsection");
  1961. list($oidit,$oiddest,$oidtemplate)=$this->_getOids($oidsection);
  1962. // verification des droits sur la page
  1963. if(!$this->secure($oidit, ':rw')) return;
  1964. $lang = $p->get('LANG_DATA');
  1965. // Traitement des cas ou l'on veut sauver dans plusieurs langues
  1966. $ar['_langs']=$this->getAuthorizedLangs($langs,$oidit,'savesection');
  1967. $tabledst = Kernel::getTable($oiddest);
  1968. $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
  1969. $ar2=$ar;
  1970. $ar2['tplentry']=TZR_RETURN_DATA;
  1971. $ar2['oid']=$oiddest;
  1972. $xst->procEdit($ar2);
  1973. $setup=$p->get("setup");
  1974. $rq="UPDATE ".$this->tname." set KOIDTPL='$setup' where ITOID='$oidsection'";
  1975. updateQuery($rq);
  1976. }
  1977. function dupsection($ar) {
  1978. $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1));
  1979. $oidsection=$p->get("oidsection");
  1980. list($oidit,$oiddest,$oidtemplate)=$this->_getOids($oidsection);
  1981. $lang = $p->get('LANG_DATA');
  1982. $tabledst = Kernel::getTable($oiddest);
  1983. $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
  1984. $r=$xst->procEditDup(array("oid"=>$oiddest,"tplentry"=>TZR_RETURN_DATA));
  1985. $setup=$p->get("setup");
  1986. $koiddup=$r['oid'];
  1987. $n=self::newItOid();
  1988. $rq="INSERT INTO ".$this->tname." set KOIDTPL='$setup',KOIDSRC='$oidit',KOIDDST='$koiddup',ITOID='$n'";
  1989. updateQuery($rq);
  1990. }
  1991. function editCat($ar=NULL) {
  1992. $p=new XParam($ar,array());
  1993. $oid=$p->get('oid');
  1994. $tplentry=$p->get('tplentry');
  1995. $ar['tplentry']=TZR_RETURN_DATA;
  1996. if(empty($ar['fmoid'])) $ar['fmoid']=$this->_moid;
  1997. $r2=$this->_categories->edit($ar);
  1998. if(!empty($this->cattemplate)) {
  1999. $r1=$this->_templates->display(array('tplentry'=>TZR_RETURN_DATA,'_options'=>array('error'=>'return'),'oid'=>$this->cattemplate));
  2000. XShell::toScreen1('cat_mitt',$r1);
  2001. }
  2002. if($this->_categories->fieldExists('tpl')) XShell::toScreen1('tple',$this->_templatesList(NULL,'page_site',$oidit));
  2003. if(XShell::admini_mode() && $this->object_sec) {
  2004. $acl=$GLOBALS['XUSER']->listObjectAccess($this, XShell::getLangData(),$oid);
  2005. $r2=array_merge($r2, $acl);
  2006. $sec=$GLOBALS['XUSER']->getObjectAccess($this, XShell::getLangData(),$oid);
  2007. $sec=array_flip($sec[0]);
  2008. $r2['object_sec']=$sec;
  2009. }
  2010. if ($this->linkin)
  2011. $r2['linkin']=$this->linkin;
  2012. if (XShell::admini_mode()) {
  2013. $r2['_publishLevel'] = array_shift($this->secGroups('publish'));
  2014. }
  2015. return XShell::toScreen1($tplentry, $r2);
  2016. }
  2017. function editpage($ar=NULL) {
  2018. return $this->viewpage($ar);
  2019. }
  2020. /**
  2021. Genère une liste des section classer par date de maj pour génération d'un rss
  2022. oids : Array : tableau d'oid des rubrique a traiter
  2023. return : Array :tableau d'element rss title,txt,image et date
  2024. */
  2025. public function &rss($ar=NULL) {
  2026. $p = new XParam($ar);
  2027. $tplentry = $p->get('tplentry');
  2028. if( empty($tplentry)) $tplentry = 'rss';
  2029. $oids = $p->get('oids');
  2030. if(!is_array($oids)){
  2031. $oids = array($oids);
  2032. }
  2033. $res = array();
  2034. $res['descr'] = '';
  2035. $res['title'] = '';
  2036. $res['items'] = array();
  2037. foreach($oids as $k=>$v){
  2038. $rub = $this->viewpage(array('oidit'=>$v,'alias'=>''));
  2039. //dissocier le faite qu'il y ai 1 ou plusieurs rubriques
  2040. if(count($oids) == 1) {
  2041. $res['descr'] = strip_tags($rub['cat_mit']['odescr']->html);
  2042. $res['title'] = $rub['cat_mit']['otitle']->html;
  2043. }else{
  2044. $res['descr'] .= $rub['cat_mit']['title']." ";
  2045. $res['title'] = XIni::get('societe');
  2046. }
  2047. $res['UPD'] = '';
  2048. foreach($rub['olines'] as $key => $section){
  2049. $tk = $section['oUPD']->raw.'_'.$key;
  2050. $res['items'][$tk] = array();
  2051. $res['items'][$tk]['pubDate'] = date("D, d M Y H:i:s O", strtotime($section['oUPD']->raw));
  2052. $res['items'][$tk]['UPD'] = $section['UPD'];
  2053. if($section['oUPD']->raw > $res['UPD']) $res['UPD'] = $section['oUPD']->raw;
  2054. $res['items'][$tk]['oid'] = $section['oid'];
  2055. $res['items'][$tk]['rub'] = $rub['cat_mit']['oid'];
  2056. if($section['odescription']->raw){
  2057. $res['items'][$tk]['description'] = $section['description'];
  2058. $res['items'][$tk]['odescription'] = $section['odescription'];
  2059. }
  2060. foreach($section['fields_object'] as $obj){
  2061. if($obj->fielddef->ftype == 'XShortTextDef' && empty($res['items'][$tk]['title']) && !empty($section['o'.$obj->field]->raw)){
  2062. $res['items'][$tk]['title'] = $section['o'.$obj->field]->html;
  2063. $res['items'][$tk]['otitle'] = $section['o'.$obj->field];
  2064. }elseif(($obj->fielddef->ftype == 'XTextDef' || $obj->fielddef->ftype == 'XRichTextDef') && empty($res['items'][$tk]['description']) && !empty($section['o'.$obj->field]->raw) ){
  2065. $res['items'][$tk]['description'] = $section['o'.$obj->field]->html;
  2066. $res['items'][$tk]['odescription'] = $section['o'.$obj->field];
  2067. }elseif($obj->fielddef->ftype == 'XImageDef' && empty($res['items'][$tk]['img']) && !empty($section['o'.$obj->field]->raw) ){
  2068. $res['items'][$tk]['img'] = $section['o'.$obj->field]->html;
  2069. $res['items'][$tk]['oimg'] = $section['o'.$obj->field];
  2070. }
  2071. };
  2072. }
  2073. }
  2074. rsort($res['items']);
  2075. return XShell::toScreen1($tplentry,$res);
  2076. }
  2077. /** Browse les paragraphes d'une rubrique, tries selon leur numero d'ordre.
  2078. Pour chaque paragraphe, display son contenu (document).
  2079. Produit les structures suivantes :
  2080. olines[indice paragraphe] = array produit par le display du contenu (document/thumb/photo/fichier).
  2081. tlines[indice paragraphe] = template de visualisation du contenu (document/thumb/photo/fichier).
  2082. */
  2083. public function &viewpage($ar=NULL) {
  2084. $p = new XParam($ar, array("level"=>1,"tplentry"=>"it","toc"=>"1","maxlevel"=>1,"first"=>"0",
  2085. "nodecontent"=>true,"_nav"=>"1","autoxhtml"=>false,'_linkin'=>true,'keepalive'=>false));
  2086. $tplentry = $p->get("tplentry");
  2087. $alias = $p->get("alias");
  2088. $defaultalias = $p->get("defaultalias");
  2089. $erroralias = $p->get("erroralias");
  2090. $authalias = $p->get("authalias");
  2091. if(empty($authalias)) $authalias=$erroralias;
  2092. $oidit = $p->get("oidit");
  2093. $linkin = $p->get("_linkin");
  2094. XLogs::debug('XModInfoTree::viewpage: start '.$alias.' '.$oidit);
  2095. $result = XShell::from_screen($tplentry);
  2096. // calcul des alias et des oidit
  2097. if(empty($alias) && empty($oidit)) {
  2098. $alias=$defaultalias;
  2099. XLogs::debug('XModInfoTree::viewpage: falling back to '.$defaultalias);
  2100. }
  2101. if(empty($alias) && !Kernel::isAKoid($oidit)) { $alias=$oidit; $oidit="";}
  2102. if(!empty($alias)) {
  2103. $oidit=$this->getOidFromAlias($alias);
  2104. }
  2105. // dans le cas ou cette rubrique est un lien, recherche du lien
  2106. if ($linkin) {
  2107. $result['baseoidit'] = $oidit;
  2108. $oidit=$this->_followLinkIn($oidit);
  2109. }
  2110. // verification dans le cas ou il y a un aliastop
  2111. $aliastop=$p->get('pagetop');
  2112. if(!empty($aliastop)) {
  2113. $navig = $this->getPath($oidit); /* calcul des chemins d'acces */
  2114. $aliasdown=$navig['aliasdown'];
  2115. if(!in_array($aliastop, $aliasdown)) return $this->redirect404($ar);
  2116. }
  2117. $first = $p->get("first");
  2118. $keepalive=$p->get('keepalive');
  2119. // recherche des langues
  2120. $LANG_DATA = XShell::getLangData($p->get("LANG_DATA"));
  2121. $LANG_TRAD = XShell::getLangTrad($p->get("LANG_TRAD"),$p->get('_notrad'));
  2122. // verification des droits sur la rubrique
  2123. $class=get_class($this);
  2124. $moid=$this->_moid;
  2125. if(empty($this->object_sec) || $this->secure($oidit,'viewpage',null,$LANG_DATA)) {
  2126. debug("XModinfoTree:auth:ok |".get_class($this).'|viewpage|'.$this->_moid."|$LANG_DATA|$oidit| user".XUser::get_current_user_uid());
  2127. } else {
  2128. XLogs::critical("XModinfoTree:auth:access denied |$class|viewpage|$moid|$LANG_DATA|$oidit| user ".XUser::get_current_user_uid());
  2129. $ar['alias']=$authalias;
  2130. return $this->viewpage($ar);
  2131. }
  2132. $pagesize = $p->get("pagesize");
  2133. $total_estimated = $p->get("total");
  2134. $toc=$p->get("toc");
  2135. $maxlevel=$p->get("maxlevel");
  2136. $nodecontent=$p->get("nodecontent");
  2137. $_format=$p->get("_format");
  2138. // Informations de la page
  2139. $result['cat_mit']=$this->_categories->display(array('oid'=>$oidit,'_options'=>array('error'=>'return'),'tplentry'=>TZR_RETURN_DATA,'fallback'=>true));
  2140. // Redirection 404 si la page n'existe pas
  2141. if(!XShell::admini_mode() && $alias!='error404' && !is_array($result['cat_mit'])) return $this->redirect404($ar);
  2142. // date de derniere mise a jour de la page
  2143. $lastpageupdate=$result["cat_mit"]['oUPD'];
  2144. if($this->_categories->fieldExists('tpl')) {
  2145. $r1=&$this->_templates->rDisplay($result["cat_mit"]["otpl"]->raw, array(), false, $LANG_DATA, XShell::getLangUser(),
  2146. array('_charset'=>$_REQUEST['_charset']));
  2147. if(is_array($r1)) {
  2148. $result["cat_mit"]["otpl"]=&$r1['odisp'];
  2149. }
  2150. }
  2151. // dans le cas ou on trouve une taille de page dans la rubrique a afficher, cette taille est prioritaire
  2152. if(empty($pagesize)){
  2153. if(!empty($result['cat_mit']['opgz']->raw)) $pagesize=$result['cat_mit']['opgz']->raw;
  2154. else{
  2155. $pagesize=XIni::get('xmodinfotree_pagesize');
  2156. if(empty($pagesize)) $pagesize=99;
  2157. }
  2158. }
  2159. $cond = 'KOIDSRC="'.$oidit.'" ';
  2160. if(!$nodecontent) {
  2161. $cond="";
  2162. $oidits=$this->getSubCats($oidit, $LANG_DATA);
  2163. foreach($oidits as $i=>$oid1) $cond.='KOIDSRC= "'.$oid1.'" OR ';
  2164. $cond.="KOIDSRC= '$oid1'";
  2165. }
  2166. $rs=selectQuery('SELECT * FROM '.$this->tname.' WHERE '.$cond.' ORDER BY ORDER1');
  2167. // On regarde si on demande un oid particulièr pour définir le first en automatique (oidsec : oid d'une fiche d'une rubrique dynamique)
  2168. $oidsec=$p->get('oidsec');
  2169. if(!XShell::admini_mode() && !empty($oidsec) && $rs->rowCount()>0){
  2170. $myfirst = 0;
  2171. $fnd = false;
  2172. $tpldatas=array();
  2173. while(($ors1=$rs->fetch()) && !$fnd) {
  2174. $query_1 = $ors1['QUERY'];
  2175. $oiditd_1 = $ors1['KOIDDST'];
  2176. $oidittpl_1 = $ors1['KOIDTPL'];
  2177. if(!isset($tpldatas[$oidittpl_1])) {
  2178. $tpl=&$this->_disp2Template($oidittpl_1);
  2179. if(is_array($tpl)) $tpldatas[$oidittpl_1]=&$tpl;
  2180. else $tpldatas[$oidittpl_1]=NULL;
  2181. }
  2182. // on regarde si on doit generer en automatique cette section
  2183. if($tpldatas[$oidittpl_1]==NULL) continue;
  2184. $tabledst = $tpldatas[$oidittpl_1]['otab']->raw;
  2185. $moddest = $tpldatas[$oidittpl_1]['omodidd']->raw;
  2186. if(empty($xsts[$tabledst])) {
  2187. if(XSystem::tableExists($tabledst))
  2188. $xsts[$tabledst]=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
  2189. else
  2190. continue;
  2191. }
  2192. $xst = &$xsts[$tabledst];
  2193. $mymoddest=NULL;
  2194. if(!empty($moddest)) {
  2195. $mymoddest=XModule::objectFactory($moddest);
  2196. }
  2197. $sessid='queryobject'.$oidit;
  2198. if(empty($oiditd_1)) {
  2199. $query2_1['tplentry']=TZR_RETURN_DATA;
  2200. $query2_1['LANG_DATA']=$LANG_DATA;
  2201. $query2_1['selectedfields']=array();
  2202. $query2_1['first']=0;
  2203. $query2_1['searchmode']='simple';
  2204. $query2_1=unserialize($query_1);
  2205. // on a garde en session les parametres
  2206. if(issetSessionVar($sessid)) {
  2207. $query2_1=getSessionVar($sessid)+$query2_1;
  2208. }
  2209. $qures=&$xst->procQuery($query2_1);
  2210. foreach($qures['lines_oid'] as $krs => $vrs){
  2211. if($vrs == $oidsec){
  2212. $first = $myfirst;
  2213. $fnd = true;
  2214. break;
  2215. }else $myfirst++;
  2216. }
  2217. }else{
  2218. $myfirst++;
  2219. }
  2220. }
  2221. $rs->closeCursor();
  2222. $rs=selectQuery('SELECT * FROM '.$this->tname.' WHERE '.$cond.' ORDER BY ORDER1');
  2223. }
  2224. $o=array();
  2225. $itoid=array();
  2226. $total = $rs->rowCount();
  2227. $t=array();
  2228. $order1=array();
  2229. $query2=NULL;
  2230. $xsts=array();
  2231. $tpldatas=array();
  2232. $ot=array();
  2233. $idx = 0;
  2234. $ors=array();
  2235. $idx2=0;
  2236. while($rs && ($ors=$rs->fetch()) && ($idx < ($first+$pagesize))) {
  2237. XLogs::debug("[section] viewpage $idx");
  2238. $query = $ors['QUERY'];
  2239. $oiditd = $ors['KOIDDST'];
  2240. $oidittpl = $ors['KOIDTPL'];
  2241. if(!isset($tpldatas[$oidittpl])) {
  2242. $tpl=&$this->_disp2Template($oidittpl);
  2243. if(is_array($tpl)) $tpldatas[$oidittpl]=&$tpl;
  2244. else $tpldatas[$oidittpl]=NULL;
  2245. }
  2246. // on regarde si on doit generer en automatique cette section
  2247. if($tpldatas[$oidittpl]==NULL) continue;
  2248. $tabledst = $tpldatas[$oidittpl]['otab']->raw;
  2249. $moddest = $tpldatas[$oidittpl]['omodidd']->raw;
  2250. if(empty($xsts[$tabledst]) && !empty($tabledst)) {
  2251. if(XSystem::tableExists($tabledst))
  2252. $xsts[$tabledst]=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tabledst);
  2253. else
  2254. continue;
  2255. }
  2256. if(!empty($tabledst)) {
  2257. $xst = &$xsts[$tabledst];
  2258. $mymoddest=NULL;
  2259. if(!empty($moddest)) {
  2260. $mymoddest=XModule::objectFactory($moddest);
  2261. }
  2262. }
  2263. $sessid='queryobject'.$oidit;
  2264. // Section de type fonction
  2265. if(empty($oiditd) && $tpldatas[$oidittpl]['ogtype']->raw=='function'){
  2266. $ot=$this->viewFunction($oidit,$oidittpl,$ors['ITOID'],$query);
  2267. // Si pas de droit et qu'on est sur la page d'edition des sections, on remplace le template par le template affichant un message d'information
  2268. if($ot===false && $idx>=$first && XShell::admini_mode() && XShell::getTemplate()=='xmodinfotree/viewpage.html'){
  2269. $idx++;
  2270. $o[$idx2]=array('_functionparams'=>1);
  2271. $itoid[$idx2]=$ors['ITOID'];
  2272. $t[$idx2]=&$this->_disp2Template('TEMPLATES:UNAUTH');
  2273. $order1[$idx2]=$ors['ORDER1'];
  2274. $idx2++;
  2275. }elseif(is_array($ot) && $idx>=$first) {
  2276. $idx++;
  2277. $o[$idx2]=$ot;
  2278. $itoid[$idx2]=$ors['ITOID'];
  2279. $t[$idx2]=$tpldatas[$oidittpl];
  2280. $order1[$idx2]=$ors['ORDER1'];
  2281. $idx2++;
  2282. }elseif(is_array($ot)) {
  2283. $idx++;
  2284. }
  2285. }elseif(empty($oiditd)) {
  2286. // generation des infos de visualisation du paragraphe
  2287. // cas ou il s'agit d'une requete
  2288. // on realise la requete et on developpe
  2289. // Gestion de l'ordre : soit order = champ asc/desc, soit order=champ et _order=asc/desc
  2290. $qorder=NULL;
  2291. $order=$p->get('order');
  2292. $_order=$p->get('_order');
  2293. $forder=explode(' ',$order);
  2294. $forder=$forder[0];
  2295. $query2=unserialize($query);
  2296. if(!empty($forder)){
  2297. if(in_array($forder,$query2['weborderselector'])){
  2298. $query2['order']=$order;
  2299. if(!empty($_order)) $query2['order'].=' '.$_order;
  2300. $qorder=$query2['order'];
  2301. }
  2302. }
  2303. if($first==0 && !$keepalive) clearSessionVar($sessid);
  2304. if(issetSessionVar($sessid)) {
  2305. $query2=$query2+getSessionVar($sessid);
  2306. }
  2307. $query2['tplentry']=TZR_RETURN_DATA;
  2308. $query2['LANG_DATA']=$LANG_DATA;
  2309. $query2['selectedfields']=array('KOID');
  2310. $query2['first']=0;
  2311. $query2['searchmode']='simple';
  2312. $query2['fmoid'] = $tpldatas[$oidittpl]['omodidd']->raw;
  2313. // prepararation du formulaire interactif lorsqu'il y a une requete parametree
  2314. $dynquery=$xst->prepareQuery($query2);
  2315. $parametrized=$dynquery['parametrized'];
  2316. // on a garde en session les parametres
  2317. if(issetSessionVar($sessid)) {
  2318. $query2=getSessionVar($sessid)+$query2;
  2319. if(!empty($qorder)) $query2['order']=$qorder;
  2320. }
  2321. // Si l'ordre est aléatoire, on fourni un entier à rand pour que la pagination... garde le meme ordre
  2322. if(substr($query2['order'],0,6)=='RAND()') $query2['order']='RAND('.rand(1,100000).')';
  2323. // execution de la requete. query2 contient les donnees de
  2324. // requete interactive ainsi que les donnees de requete stockee
  2325. // on recupere d'abord le filtre du module si il existe
  2326. if( !empty($mymoddest) ){
  2327. $mymodfilter = $mymoddest->getFilter();
  2328. if($mymodfilter) $query2['_filter'] = $mymodfilter;
  2329. }
  2330. $queryres=&$xst->procQuery($query2);
  2331. if(!empty($queryres['order'])) $order=$queryres['order'];
  2332. foreach($query2['weborderselector'] as $f){
  2333. if(!empty($f)) $dynquery['weborderselector'][]=array('field'=>$f,'label'=>&$xst->desc[$f]->label,'selected'=>($f==$order));
  2334. }
  2335. // on ne met quelque chose en session que si cela est necessaire
  2336. if($parametrized){
  2337. $ok=false;
  2338. foreach($queryres['queryobject'] as $tmp){
  2339. if(!empty($tmp)){
  2340. $ok=true;
  2341. break;
  2342. }
  2343. }
  2344. if($ok) setSessionVar($sessid,$queryres['queryobject']);
  2345. }
  2346. $ntmp=count($queryres['lines_oid']);
  2347. if($ntmp>0) $total+=$ntmp-1;
  2348. $boq=true;
  2349. $qdisp=1;
  2350. for($q=0;($q<$ntmp) && ($idx < ($first+$pagesize));$q++) {
  2351. if($idx>=$first) {
  2352. $oidt1=$queryres['lines_oid'][$q];
  2353. if(is_object($mymoddest)) {
  2354. $ot=$mymoddest->display(array('oid'=>$oidt1, 'tplentry'=>TZR_RETURN_DATA,'_format'=>$_format,
  2355. '_options'=>array('error'=>'return'),'_dynquerymode'=>true,
  2356. '_cacheobject'=>'vwp'.$this->_moid,'ssmoid'=>'all'));
  2357. } else {
  2358. $ot=$xst->display(array('oid'=>$oidt1, 'tplentry'=>TZR_RETURN_DATA,'_format'=>$_format,
  2359. '_options'=>array('error'=>'return'),'_dynquerymode'=>true,
  2360. '_cacheobject'=>'vwp'.$this->_moid));
  2361. }
  2362. }
  2363. if(is_array($ot) && ($idx>=$first)) {
  2364. if((($first+$pagesize-1)==$idx)||($q==($ntmp-1))) {
  2365. $ot['_eoq']=true;
  2366. $ot['_total']=$ntmp;
  2367. $ot['_dynquery']=$dynquery;
  2368. }
  2369. if($boq) {
  2370. $ot['_boq']=true;
  2371. $ot['_dynquery']=$dynquery;
  2372. $ot['_total']=$ntmp;
  2373. $boq=false;
  2374. }
  2375. $ot['_type']='query';
  2376. $ot['_q']="$q";
  2377. $ot['_qdisp']=$qdisp;
  2378. $o[$idx2]=$ot;
  2379. if($ot['oUPD']->raw>$lastpageupdate->raw) {
  2380. $lastpageupdate=$ot['oUPD'];
  2381. }
  2382. $t[$idx2]=&$tpldatas[$oidittpl];
  2383. $itoid[$idx2] = $ors['ITOID'];
  2384. $order1[$idx2] = $ors['ORDER1'];
  2385. $qdisp++;
  2386. $idx2++;
  2387. }
  2388. $idx++;
  2389. }
  2390. if($ntmp<=0) {
  2391. $ot['_type']='query';
  2392. $ot['_dynquery']=$dynquery;
  2393. $t[$idx2]=&$tpldatas[$oidittpl];
  2394. $ot['_q']='0';
  2395. $ot['_empty']=true;
  2396. $ot['_boq']='0';
  2397. $ot['_total']='0';
  2398. $o[$idx2]=$ot;
  2399. if($ot['oUPD']->raw>$lastpageupdate->raw) {
  2400. $lastpageupdate=$ot['oUPD'];
  2401. }
  2402. $itoid[$idx2] = $ors['ITOID'];
  2403. $order1[$idx2] = $ors['ORDER1'];
  2404. $idx2++;
  2405. } else {
  2406. $o[$idx2-1]['eoq']=true;
  2407. }
  2408. }
  2409. // car ou il s'agit d'un paragraphe isole
  2410. else {
  2411. $ot=NULL;
  2412. if(!empty($LANG_TRAD) && ($LANG_TRAD!=$LANG_DATA)) {
  2413. $ot=&$xst->display(array('oid'=>$oiditd, 'tplentry'=>TZR_RETURN_DATA,'_format'=>$_format,
  2414. 'LANG_DATA'=>$LANG_TRAD,
  2415. '_cacheobject'=>$this->_moid,
  2416. '_options'=>array('error'=>'return')));
  2417. $ot2=&$xst->display(array('oid'=>$oiditd, 'tplentry'=>TZR_RETURN_DATA,
  2418. 'LANG_TRAD'=>'',
  2419. '_cacheobject'=>$this->_moid,
  2420. '_options'=>array('error'=>'return')));
  2421. $ot['_type']='section';
  2422. $ot2['_type']='section';
  2423. } else {
  2424. $ot=&$xst->display(array('oid'=>$oiditd, 'tplentry'=>TZR_RETURN_DATA,'_format'=>$_format,
  2425. '_cacheobject'=>$this->_moid,
  2426. '_options'=>array('error'=>'return')));
  2427. $ot['_type']='section';
  2428. }
  2429. if(is_array($ot) && $idx>=$first) {
  2430. $idx++;
  2431. $o[$idx2]=$ot;
  2432. if($ot['oUPD']->raw>$lastpageupdate->raw) {
  2433. $lastpageupdate=$ot['oUPD'];
  2434. }
  2435. $itoid[$idx2] = $ors['ITOID'];
  2436. $t[$idx2] = $tpldatas[$oidittpl];
  2437. $order1[$idx2] = $ors['ORDER1'];
  2438. $idx2++;
  2439. if(!empty($ot2)) {
  2440. $o[$idx2]=$ot2;
  2441. $itoid[$idx2] = $ors['ITOID'];
  2442. $t[$idx2] = $tpldatas[$oidittpl];
  2443. $order1[$idx2] = $ors['ORDER1'];
  2444. $idx2++;
  2445. }
  2446. }elseif(is_array($ot)) {
  2447. $idx++;
  2448. }
  2449. }
  2450. }
  2451. // Ajout des packs requis par les TEMPLATES au header
  2452. foreach ($t as $template) {
  2453. if (empty($template['opacks']->raw)) continue;
  2454. $packs_to_autoload = preg_split('/[^\w]+/', $template['opacks']->raw);
  2455. foreach ($packs_to_autoload as $packname) {
  2456. $GLOBALS['TZR_PACKS']->addNamedPack($packname);
  2457. }
  2458. }
  2459. if(!empty($this->cattemplate)) {
  2460. $r1=&$this->_templates->display(array('tplentry'=>TZR_RETURN_DATA,'fallback'=>'true',
  2461. '_options'=>array('error'=>'return'),
  2462. 'oid'=>$this->cattemplate));
  2463. if(is_array($r1)) XShell::toScreen1('cat_mitt',$r1);
  2464. }
  2465. if($toc) {
  2466. $this->home(array('oidtop'=>$oidit,'tplentry'=>'ssrubs','do'=>'showtree','maxlevel'=>$maxlevel));
  2467. }
  2468. $result['query'] = $query2;
  2469. $result['oidit']=$oidit;
  2470. $result['itoid']=$itoid;
  2471. $result['olines']=$o;
  2472. $result['first']=$first;
  2473. $result['last']=$total;
  2474. $result['firstnext']=''.($first+$pagesize).'';
  2475. $result['firstprev']=''.($first-$pagesize>=0?($first-$pagesize):$first).'';
  2476. $result['total']=$total;
  2477. $result['order']=$order1;
  2478. $result['tlines']=$t;
  2479. $result['pages_mode']='';
  2480. $result['moid']=$this->_moid;
  2481. if (XShell::admini_mode()) {
  2482. $result['_editCat'] = array_shift($this->secGroups('editCat'));
  2483. $result['_editLevel'] = array_shift($this->secGroups('editpage'));
  2484. $result['_publishLevel'] = array_shift($this->secGroups('publish'));
  2485. }
  2486. if((@$_SERVER['REQUEST_METHOD']=='POST') || (@$_REQUEST['nocache']=='1')) {
  2487. $result['pages_mode']='&nocache=1';
  2488. }
  2489. $result['lastpageupdate']=$lastpageupdate;
  2490. // Met à jour la date de dernière révision si besoin
  2491. if(!empty($result["cat_mit"]['olastrevision']) && $lastpageupdate->raw>$result["cat_mit"]['olastrevision']->raw){
  2492. updateQuery('update '.$this->table.' set UPD=UPD,lastrevision="'.$lastpageupdate->raw.'" where KOID="'.$oidit.'" and LANG="'.$LANG_DATA.'"');
  2493. }
  2494. if($pagesize<$total) {
  2495. $p1=0;
  2496. $pages=array();
  2497. for($i=0;$i<$total;$i+=$pagesize){
  2498. $pages[$p1++]=$i;
  2499. if($i==$first) $result['actpage']=$p1;
  2500. }
  2501. $result['pages']=$pages;
  2502. $result['lastpage']=$p1;
  2503. $result['firstlastpage']=$pages[$p1-1];
  2504. }else{
  2505. $result['actpage']=1;
  2506. $result['lastpage']=1;
  2507. }
  2508. if($p->get('_nav')==1) $result['nav']=$this->_getNavigInfo($oidit);
  2509. if($p->get('_path')==1) $result['path']=$this->getPath($oidit);
  2510. XLogs::debug("XModInfoTree::viewpage: end $alias $oidit");
  2511. return XShell::toScreen1($tplentry,$result);
  2512. }
  2513. /// Retourne les données d'une section dans une rubrique
  2514. function viewsection($ar=NULL){
  2515. $p=new XParam($ar);
  2516. $tplentry=$p->get('tplentry');
  2517. $oidit=$p->get('oidit');
  2518. $alias=$p->get('alias');
  2519. $oidsection=$p->get('oidsection');
  2520. $LANG_DATA = XShell::getLangData($p->get("LANG_DATA"));
  2521. if(!empty($alias)) $oidit=$this->getOidFromAlias($alias);
  2522. $rs=selectQuery('select * from '.$this->tname.' WHERE ITOID="'.$oidsection.'" AND KOIDSRC="'.$oidit.'"');
  2523. // Verifie que la section est bien dans la page demandée
  2524. if(!$rs->rowCount()) securityWarning('XModInfoTree::viewsection: trying to display section '.$oidsection.' not in page '.$oidit);
  2525. // Verifie les droits de la page
  2526. if(!$this->secure($oidit,'viewsection',$u=NULL,$LANG_DATA)) {
  2527. XLogs::critical('XModInfoTree::viewsection:access denied viewsection|'.$this->_moid.'|'.$LANG_DATA.'|'.$oidit.'| user '.XUser::get_current_user_uid());
  2528. die();
  2529. }
  2530. $o=$itoid=$t=$result=array();
  2531. // Infos de la page
  2532. $result['cat_mit']=$this->_categories->display(array('oid'=>$oidit,'tplentry'=>TZR_RETURN_DATA));
  2533. // Infos de la section
  2534. $ors=$rs->fetch();
  2535. $query=$ors['QUERY'];
  2536. $oiditd=$ors['KOIDDST'];
  2537. $oidittpl=$ors['KOIDTPL'];
  2538. $tpl=&$this->_disp2Template($oidittpl);
  2539. if(!$tpl) die();
  2540. // Cas d'une section fonction
  2541. if(empty($oiditd) && $tpl['ogtype']->raw=='function'){
  2542. $ot=$this->viewFunction($oidit,$oidittpl,$ors['ITOID'],$query);
  2543. if(empty($ot)) die();
  2544. if(is_array($ot)) {
  2545. $o[]=$ot;
  2546. $itoid[]=$ors['ITOID'];
  2547. $t[]=$tpl;
  2548. }
  2549. }
  2550. $result['oidit']=$oidit;
  2551. $result['itoid']=$itoid;
  2552. $result['oidsection']=$oidsection;
  2553. $result['olines']=$o;
  2554. $result['tlines']=$t;
  2555. $result['moid']=$this->_moid;
  2556. return XShell::toScreen1($tplentry,$result);
  2557. }
  2558. /// Retourne les données d'une section de type fonction
  2559. function &viewFunction($oidit,$oidittpl,$itoid,$query){
  2560. $query2=unserialize($query);
  2561. $moid=$query2['moid'];
  2562. $function=$query2['function'];
  2563. $UIParam_function='UIParam_'.$function;
  2564. $UIView_function='UIView_'.$function;
  2565. $module=XModule::objectFactory($moid);
  2566. // Test les droits sur la fonction
  2567. if($query2['__oid'] && !$module->secure($query2['__oid'],$function))
  2568. return false;
  2569. if(method_exists($module, $UIView_function)){
  2570. $query2['oidit']=$oidit;
  2571. $query2['itoid']=$itoid;
  2572. $query2['_options']=array('local'=>1);
  2573. $query2['tplentry']=TZR_RETURN_DATA;
  2574. $ot=$module->$UIView_function($query2);
  2575. $params=$query2;
  2576. }else{
  2577. if(!method_exists($module, $function) || !method_exists($module, $UIParam_function)) return NULL;
  2578. $params=array('oidit'=>$oidit, '_options'=>array('local'=>1),'tplentry'=>true);
  2579. $desc=$module->$UIParam_function();
  2580. foreach($desc as $fn=>&$field){
  2581. if(strpos($fn,'__')===0) $fn2=substr($fn,2);
  2582. else $fn2=$fn;
  2583. if(empty($query2[$fn])) continue;
  2584. $params[$fn2]=$query2[$fn];
  2585. if($field->multivalued && $field->get_fgender()=='Oid'){
  2586. $params[$fn2]=explode('||',$params[$fn2]);
  2587. }
  2588. }
  2589. $ot=$module->$function($params);
  2590. }
  2591. // Récupère les options de mise en page liées au TEMPLATE
  2592. $options_values = (object) null;
  2593. $xoptions = $this->getTemplateOptions($oidittpl, $itoid, $options_values);
  2594. if (!is_null($xoptions)) {
  2595. $xoptions->procDialog($options_values, $params['_tploptions']);
  2596. $ot['_tploptions'] = (array) $options_values;
  2597. }
  2598. $ot['_functionparams']=array('function'=>$function,'moid'=>$query2['moid'],'params'=>$params,'modulename'=>$module->modulename);
  2599. $ot['_type']='function';
  2600. return $ot;
  2601. }
  2602. // recherche des info rubrique prec, suivant, top, etc...
  2603. //
  2604. protected function &_getNavigInfo($oidit) {
  2605. $result=array();
  2606. $published='';
  2607. if(fieldExists($this->table, 'PUBLISH') && !XShell::admini_mode()) {
  2608. $published=' AND PUBLISH="1" ';
  2609. }
  2610. $q = 'select distinct KOID,linkup,corder from '.$this->table.' where KOID="'.$oidit.'" '.$published;
  2611. $rs=selectQuery($q);
  2612. if($ors=$rs->fetch()) {
  2613. $linkup=$ors['linkup'];
  2614. $order=$ors['corder'];
  2615. // recherche du next au meme niveau
  2616. $q = 'select distinct KOID,linkup,corder from '.$this->table.' where '.
  2617. "linkup='$linkup' and corder>'$order' $published order by corder";
  2618. $rs=selectQuery($q);
  2619. if($ors=$rs->fetch()) {
  2620. $koidnext=$ors['KOID'];
  2621. $r1=&$this->_categories->display(array('oid'=>$koidnext,'tplentry'=>TZR_RETURN_DATA,'_options'=>array('error'=>'return'), 'fallback'=>1));
  2622. if(is_array($r1)) $result['next']=$r1;
  2623. }
  2624. // recherche du prev au meme niveau
  2625. $q = 'select distinct KOID,linkup,corder from '.$this->table.' where '.
  2626. "linkup='$linkup' and corder<'$order' $published order by corder";
  2627. $rs=selectQuery($q);
  2628. if($ors=$rs->fetch()) {
  2629. $koidprev=$ors['KOID'];
  2630. $r1=&$this->_categories->display(array('oid'=>$koidprev,'tplentry'=>TZR_RETURN_DATA,
  2631. 'fallback'=>1,
  2632. '_options'=>array('error'=>'return')));
  2633. if(is_array($r1)) $result['prev']=$r1;
  2634. }
  2635. // recherche du up
  2636. if(strlen($linkup)>1)
  2637. $result['up']=&$this->_categories->display(array('oid'=>$linkup,'tplentry'=>TZR_RETURN_DATA, 'fallback'=>1));
  2638. }
  2639. return $result;
  2640. }
  2641. // rend la liste des oid ss categories
  2642. //
  2643. public function &getSubObjects($oid) {
  2644. $stack=array($oid);
  2645. $res=array();
  2646. while(!empty($stack)) {
  2647. $poped=array_pop($stack);
  2648. if($poped!=$oid) array_push($res, $poped);
  2649. $rs=selectQuery('SELECT DISTINCT KOID,alias FROM '.$this->table." WHERE linkup='$poped'");
  2650. while($ors=$rs->fetch()) {
  2651. array_push($stack, $ors['KOID']);
  2652. }
  2653. $rs->closeCursor();
  2654. }
  2655. return $res;
  2656. }
  2657. // rend la liste des ss categroies
  2658. //
  2659. public function getSubCats($oid, $lang, $level=1, $depth=9, $maxlevel=9) {
  2660. if(!isset($oid)) {
  2661. $query = $this->_categories->select_query(array('cond'=>array('linkup'=>array('=','NULL'))));
  2662. } else {
  2663. $query = $this->_categories->select_query(array('cond'=>array('linkup'=>array('=',$oid))));
  2664. }
  2665. $rcat=&$this->_categories->browse(array('selected'=>0,
  2666. 'first'=>'0',
  2667. 'select'=>$query,
  2668. 'pagesize'=>1000,
  2669. 'selectedfields'=>array('title','linkup'),
  2670. 'order'=>'corder',
  2671. 'tplentry'=>TZR_RETURN_DATA,
  2672. 'header'=>'0','nocount'=>'1'));
  2673. $OID[]=$oid;
  2674. foreach($rcat['lines_oid'] as $i => $o) {
  2675. $OID[]=$o;
  2676. if($level < $depth) {
  2677. $subOID = $this->getSubCats($o, $lang, $level+1, $depth);
  2678. $OID=array_merge($OID,$subOID);
  2679. }
  2680. }
  2681. return $OID;
  2682. }
  2683. /// rend l'oid de la poubelle
  2684. protected function getTrashOid($createit=false) {
  2685. // recherche de la poubelle
  2686. $all=selectQueryGetOne('SELECT KOID FROM '.$this->table.' WHERE alias = "trash" and LANG="'.TZR_DEFAULT_LANG.'" LIMIT 1');
  2687. $dest=$all['KOID'];
  2688. // si la poubelle n'existe aps il faut la rajouter
  2689. if(empty($dest) && $createit) {
  2690. $ar1=array('title'=>XLabels::getSysLabel('general','trash','text'),
  2691. 'alias'=>'trash',
  2692. 'linkup'=>NULL,
  2693. 'corder'=>'0');
  2694. $r1=&$this->procInput($ar1);
  2695. $dest=$r1['oid'];
  2696. }
  2697. return $dest;
  2698. }
  2699. /// rend la liste des aliases de ce module
  2700. function getAliases() {
  2701. $lang=XShell::getLangData();
  2702. $set = selectQueryGetAll('SELECT DISTINCT KOID,alias FROM '.$this->table." WHERE LANG='$lang'");
  2703. $setall=array();
  2704. foreach($set as $i=>&$al) {
  2705. if(!empty($al['alias'])) $setall[$al['KOID']]=$al['alias'];
  2706. }
  2707. return $setall;
  2708. }
  2709. /// rend l'oid correspondant à l'alias
  2710. public function getOidFromAlias($alias) {
  2711. if(Kernel::isAKoid($alias) && Kernel::objectExists($alias)) return $alias;
  2712. if(isset($alias)) {
  2713. $query=$this->_categories->select_query(array('cond'=>array('alias'=>array('=',$alias))));
  2714. $rs=selectQuery($query);
  2715. $oidit=NULL;
  2716. if(!$rs) return NULL;
  2717. while($ors=$rs->fetch()) {
  2718. $oidit=$ors['KOID'];
  2719. }
  2720. $rs->closeCursor();
  2721. return $oidit;
  2722. }
  2723. return NULL;
  2724. }
  2725. public function usedTables(){
  2726. return array($this->table,$this->tname,'TEMPLATES');
  2727. }
  2728. public function usedMainTables(){
  2729. return array($this->table);
  2730. }
  2731. public function usedBoids(){
  2732. return array($this->_categories->getBoid());
  2733. }
  2734. function goto1($ar=NULL) {
  2735. $p = new XParam($ar,array());
  2736. $oid=$p->get('oid');
  2737. $url=$GLOBALS['TZR_SESSION_MANAGER']::admin_url(true,false);
  2738. $moid=$this->_moid;
  2739. header("Location: {$url}moid=$moid&template=xmodinfotree/viewpage.html&oidit=$oid&function=editpage&tplentry=it");
  2740. }
  2741. function _mkInline(&$r) {
  2742. }
  2743. /// rend vrai si l'alias pass en parametre est protege
  2744. public function aliasIsProtected($alias) {
  2745. return false;
  2746. }
  2747. public function export($ar) {
  2748. $r1=&$this->home(array('tplentry'=>TZR_RETURN_DATA,'do'=>'showtree'));
  2749. foreach($r1['lines_oid'] as $i=>$oid) {
  2750. $R2=&$this->viewpage(array('tplentry'=>TZR_RETURN_DATA, 'oidit'=>$oid));
  2751. $r1['lines__it'][$i]=$R2['olines'];
  2752. $r1['lines__tt'][$i]=$R2['tlines'];
  2753. }
  2754. XShell::toScreen1('mit', $r1);
  2755. }
  2756. public function apply($fsection) {
  2757. $r1=$this->home(array('tplentry'=>TZR_RETURN_DATA,'do'=>'showtree'));
  2758. foreach($r1['lines_oid'] as $oid) {
  2759. $R2=$this->viewpage(array('tplentry'=>TZR_RETURN_DATA, 'oidit'=>$oid));
  2760. $fsection($this, $R2['cat_mit']); /* conversion de la rubrique */
  2761. foreach($R2['olines'] as $section) {
  2762. $fsection($this, $section);
  2763. }
  2764. unset($R2);
  2765. }
  2766. }
  2767. /**
  2768. * Exporte la page au format PDF
  2769. * @param ar Options de la fonction viewpage avec un paramètre 'action'
  2770. * supplémentaire qui vaut 'display' par défaut pour renvoyer
  2771. * directement un fichier à l'utilisateur ou 'generate' pour
  2772. * seulement générer le fichier et renvoyer son nom.
  2773. * @return String Nom du fichier généré
  2774. */
  2775. public function exportPdf($ar) {
  2776. $p = new XParam($ar,array(
  2777. 'pagesize' => 999,
  2778. 'action' => 'display' // 'generate' ou 'display'
  2779. ));
  2780. $ar['pagesize'] = $p->get('pagesize');
  2781. $ar['tplentry'] = 'it';
  2782. $tpldata['it'] = $this->viewpage($ar);
  2783. $xt = new XTemplate('xmodinfotree/exportPdf.html');
  2784. $labels = $GLOBALS['XSHELL']->labels->get_labels(array('selectors'=>array('global'),'local'=>true));
  2785. $xt->set_glob(array('labels'=>&$labels));
  2786. $rawData = array('it_prop'=>$this);
  2787. $content = $xt->parse($tpldata,$rawData,NULL);
  2788. $pdfname = $tpldata['it']['cat_mit']['oalias']->html.'.pdf';
  2789. $tmpname = princeTidyXML2PDF(null,$content);
  2790. switch ($p->get('action')) {
  2791. case 'generate' :
  2792. $newname = dirname($tmpname).'/'.$pdfname;
  2793. return @rename($tmpname,$newname) ? $newname : $tmpname;
  2794. case 'display' :
  2795. header('Content-type: application/pdf');
  2796. header('Content-disposition: attachment; filename='.$pdfname);
  2797. $size = filesize($tmpname);
  2798. header('Accept-Ranges: bytes');
  2799. header('Content-Length: '.$size);
  2800. readfile($tmpname);
  2801. unlink($tmpname);
  2802. exit(0);
  2803. }
  2804. }
  2805. public function &browse($ar) {
  2806. return $this->_categories->browse($ar);
  2807. }
  2808. public function &query($ar) {
  2809. return $this->_categories->query($ar);
  2810. }
  2811. public function &procQuery($ar) {
  2812. $p=new XParam($ar, array());
  2813. $tplentry=$p->get('tplentry');
  2814. $ar1=$ar;
  2815. $ar1['tplentry']=TZR_RETURN_DATA;
  2816. $ar1['selectedfields']=array('UPD','PUBLISH','title','alias');
  2817. $r=&$this->_categories->procQuery($ar1);
  2818. $r['objects_sec']=$GLOBALS['XUSER']->getObjectsAccess($this, XShell::getLangData(), $r['lines_oid']);
  2819. if($tplentry!=TZR_RETURN_DATA) {
  2820. $this->browse_actions($r);
  2821. }
  2822. return XShell::toScreen1($tplentry, $r);
  2823. }
  2824. public function browse_actions(&$r) {
  2825. $self=$GLOBALS['TZR_SESSION_MANAGER']::complete_self();
  2826. $self.='&moid='.$this->_moid.'&oidit=<oid>&tplentry=it&function=';
  2827. if(!is_array($r['lines_oid'])) return;
  2828. $approved=XLabels::getSysLabel('general','approved');
  2829. $not_approved=XLabels::getSysLabel('general','not_approved');
  2830. $viewico = XLabels::getSysLabel('general','view');
  2831. $viewtxt = XLabels::getSysLabel('general','view','text');
  2832. $editico = XLabels::getSysLabel('general','edit');
  2833. $edittxt = XLabels::getSysLabel('general','edit','text');
  2834. $browseico = XLabels::getSysLabel('general','browse');
  2835. $browsetxt = XLabels::getSysLabel('general','browse','text');
  2836. foreach($r['lines_oid'] as $i =>$oid) {
  2837. $self1=str_replace('<oid>',$oid,$self);
  2838. $self1=str_replace('=it','=mit',$self1);
  2839. $self1=str_replace('oidit','oid',$self1);
  2840. $r['actions'][$i][0]='<a class="cv8-ajaxlink" href="'.$self1.'home&'.
  2841. 'template=xmodinfotree/index.html&do=add" title="'.$browsetxt.'">'.$browseico.'</a>';
  2842. $r['actions_label'][$i][0]=$viewico;
  2843. $r['actions_url'][$i][0]=$self1.'home&template=xmodinfotree/index.html&do=add';
  2844. $self1=str_replace('<oid>',$oid,$self);
  2845. $r['actions'][$i][1]='<a class="cv8-ajaxlink" href="'.$self1.'viewpage&'.
  2846. 'template=xmodinfotree/viewpage.html" title="'.$viewtxt.'">'.$viewico.'</a>';
  2847. $r['actions_label'][$i][1]=$viewico;
  2848. $r['actions_url'][$i][1]=$self1.'viewpage&template=xmodinfotree/viewpage.html';
  2849. if(!empty($r['objects_sec'][$i]['rw'])) {
  2850. $r['actions'][$i][2]='<a class="cv8-ajaxlink" href="'.$self1.'editpage&'.
  2851. 'template=xmodinfotree/viewpage.html" title="'.$edittxt.'">'.$editico.'</a>';
  2852. $r['actions_url'][$i][2]=$self1.'editpage&template=xmodinfotree/editpage.html';
  2853. $r['actions_label'][$i][2]=$editico;
  2854. }
  2855. }
  2856. }
  2857. /// rend la date de derniere mise a jour de la page dont l'oid est fourni
  2858. protected function lastUpdate($oid) {
  2859. $rs=selectQuery('SELECT UPD,KOID FROM '.$this->table.' WHERE KOID="'.$oid.'" ORDER BY UPD DESC LIMIT 1');
  2860. if(!$rs || !$ors=&$rs->fetch()) return NULL;
  2861. $lastupd=$ors['UPD'];
  2862. $lastoid=$ors['KOID'];
  2863. // recherche de toutes les sections de la page
  2864. $all=selectQueryGetAll('SELECT KOIDDST FROM '.$this->tname.' where KOIDSRC="'.$oid.'" AND KOIDDST != ""');
  2865. foreach($all as $ors) {
  2866. // recherche de la derniere mise a jour pour cette section
  2867. $upd=XLogs::getLastUpdate($ors['KOIDDST'], NULL, true);
  2868. if(!empty($upd) && ($upd['dateupd']>$lastupd)) {
  2869. $lastupd=$upd['dateupd'];
  2870. $lastoid=$ors['KOIDDST'];
  2871. }
  2872. }
  2873. $update=XLogs::getLastUpdate($lastoid, NULL, true);
  2874. return $update;
  2875. }
  2876. protected function _lasttimestamp() {
  2877. $rs=selectQuery('SELECT MAX(UPD) AS UPD FROM '.$this->table.'');
  2878. $ors=&$rs->fetch();
  2879. $lastupd=$ors['UPD'];
  2880. $rs=selectQuery('SELECT DISTINCT KOIDDST FROM '.$this->tname.' WHERE KOIDDST != ""');
  2881. $tables=array();
  2882. while($rs && ($ors=&$rs->fetch())) {
  2883. $tables[]=Kernel::getTable($ors['KOIDDST']);
  2884. }
  2885. $tables_u=array_unique($tables);
  2886. foreach($tables_u as $table) {
  2887. if(empty($table)) continue;
  2888. $ors=selectQueryGetOne('SELECT MAX('.$table.'.UPD) AS UPD FROM '.$table.','.$this->tname.' WHERE '.
  2889. $table.'.KOID='.$this->tname.'.KOIDDST');
  2890. if(!empty($ors) && ($lastupd < $ors['UPD'])) $lastupd=$ors['UPD'];
  2891. }
  2892. return $lastupd;
  2893. }
  2894. /// rend la liste des rubriques modifiees depuis ts et jusqu'a timestamp
  2895. protected function _whatsNew($ts,$user, $group=NULL, $specs=NULL,$timestamp=NULL) {
  2896. list($koid,$subdir) = explode(';',$specs);
  2897. // recherche dans lines_oid de la liste des rubriques concernees par l'abonnement
  2898. if($subdir) $r1=&$this->home(array('tplentry'=>TZR_RETURN_DATA,'do'=>'showtree','myself'=>true,'oidtop'=>$koid));
  2899. else $r1=array('lines_oid'=>array($koid));
  2900. // recherche de la date de derniere mise a jour pour cahcune des rubriques cocnernees
  2901. $r1['lines_upd']=array();
  2902. foreach($r1['lines_oid'] as $i=>$oid) {
  2903. $r1['lines_upd'][$i]=$this->lastUpdate($oid);
  2904. }
  2905. $txt='';
  2906. foreach($r1['lines_oid'] as $i => $oid) {
  2907. if(($r1['lines_upd'][$i]['dateupd']>$ts) && ($r1['lines_upd'][$i]['dateupd']<$timestamp)) {
  2908. $url=$GLOBALS['TZR_SESSION_MANAGER']::admin_url(true,false).'&moid='.$this->_moid.'&function=goto1&oid='.$oid.'&tplentry=br&template=xmodtable/view.html&_direct=1';
  2909. $when=$r1['lines_upd'][$i]['dateupd'];
  2910. $who=$r1['lines_upd'][$i]['usernam'];
  2911. $title=$this->getPathString($oid);
  2912. $txt.='<li><a href="'.$url.'">'.$title.'</a> ('.$when.','.$who.')</li>';
  2913. }
  2914. }
  2915. return $txt;
  2916. }
  2917. function preSubscribe($ar=NULL) {
  2918. $p=new XParam($ar,array());
  2919. $oid=$p->get("oid");
  2920. $tplentry=$p->get("tplentry");
  2921. $subdir=$p->get("subdir");
  2922. $br=&$this->viewpage(array('tplentry'=>TZR_RETURN_DATA, 'oidit'=>$oid));
  2923. list($acl_user, $acl_grp)=XUser::getUsersAndGroups();
  2924. XShell::toScreen1('users',$acl_user);
  2925. XShell::toScreen1('grps',$acl_grp);
  2926. return XShell::toScreen1($tplentry, $br);
  2927. }
  2928. function subscribe($ar=NULL) {
  2929. $p=new XParam($ar,array());
  2930. $oid=$p->get("oid");
  2931. $subdir=$p->get("subdir");
  2932. $uid=$p->get("uid");
  2933. if(empty($uid)) $uid=XUser::get_current_user_uid();
  2934. if(empty($subdir)) $subdir="0";else $subdir="1";
  2935. $xmodsub = new XModSub(array('interactive'=>false));
  2936. $xmodsub->addSub(array($uid), $this->_moid, $oid.';'.$subdir);
  2937. }
  2938. // rend une chaine qui représente l'abonnement
  2939. //
  2940. function _getSubTitle($oid) {
  2941. $rs=selectQuery("select * from OPTS where KOID='$oid'");
  2942. if($rs && ($ors=$rs->fetch())) {
  2943. list($koid,$subdir)=explode(';',$ors['specs']);
  2944. if(Kernel::objectExists($koid)) {
  2945. // generation du libelle pour la rubrique
  2946. $title=$this->getPathString($koid);
  2947. $url=$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&moid='.$this->_moid.'&_function=goto1&oid='.$koid.'&tplentry=br';
  2948. if(!empty($subdir)) {
  2949. $subdir=' et sous rubriques';
  2950. } else $subdir='';
  2951. return '<A HREF="'.$url.'">'.$title.'</A> '.$subdir;
  2952. } else {
  2953. // l'abonnement concerne une donnee qui n'existe plus. on le supprimer
  2954. updateQuery("delete from OPTS where KOID='$oid'");
  2955. }
  2956. }
  2957. return NULL;
  2958. }
  2959. /// Prepare l'importation d'un fichier odt
  2960. function preImportFromODT($ar=NULL){
  2961. }
  2962. /// importe un fichier odt
  2963. function importFromODT($ar=NULL){
  2964. $p=new XParam($ar,NULL);
  2965. $linkup=$p->get('linkup');
  2966. $rep=TZR_TMP_DIR.'odt_'.uniqid().'/';
  2967. mkdir($rep);
  2968. mkdir($rep.'in/');
  2969. mkdir($rep.'out/');
  2970. rename($_FILES['odtfile']['tmp_name'],$rep.'in/odtfile.odt');
  2971. require_once('add-ons/odt2xhtml/odt2seolan.php');
  2972. $xhtml2seolan = new xhtml2seolan(
  2973. $this,
  2974. $rep, 'odtfile.odt',
  2975. array('txt' => array(
  2976. 'tploid' => $this->odttpltxt,
  2977. 'txtfield' => $this->odttxtfield,
  2978. 'titlefield' => $this->odttxttitlefield),
  2979. 'img' => array(
  2980. 'tploid' => $this->odttplimg,
  2981. 'imgfield' => $this->odtimgfield)),
  2982. $linkup);
  2983. $xhtml2seolan->import();
  2984. XDir::unlink($rep);
  2985. XShell::toScreen2('','message',XLabels::getSysLabel('xmodinfotree','odt_importok','text'));
  2986. }
  2987. /// Définit si le cache des droits doit être activé ou pas.
  2988. public function rightCacheEnabled(){
  2989. if($this->object_sec) return true;
  2990. return false;
  2991. }
  2992. /// Retourne le parent direct de chaque oid passé en paramètre
  2993. public function getParentsOids($oids){
  2994. $ret=array();
  2995. foreach($oids as $oid){
  2996. if(!$oid) continue;
  2997. $parent=selectQueryGetOne('select linkup from '.$this->table.' WHERE KOID="'.$oid.'" limit 1');
  2998. if(!$parent || !$parent['linkup']) $ret[]='';
  2999. else $ret[]=$parent['linkup'];
  3000. }
  3001. return $ret;
  3002. }
  3003. /// Redirige vers une page d'erreur 404
  3004. function redirect404($ar=NULL){
  3005. $p=new XParam($ar,NULL);
  3006. $erroralias=$p->get('erroralias');
  3007. header("HTTP/1.1 404 Not Found");
  3008. if(empty($erroralias)) {
  3009. header('Location: '.$GLOBALS['HOME_ROOT_URL']);
  3010. exit(0);
  3011. } else {
  3012. $ar['alias']=$erroralias;
  3013. $ar['oidit']=NULL;
  3014. return $this->viewpage($ar);
  3015. }
  3016. }
  3017. }
  3018. function xmodinfotree_procEditInPlace(){
  3019. activeSec();
  3020. $p=new XParam($ar,NULL);
  3021. $moid=$p->get('moid');
  3022. $oid=$p->get('oid');
  3023. $oidit=$p->get('oidit');
  3024. $field=$p->get('field');
  3025. $value=$p->get('value');
  3026. $GLOBALS['XSHELL']=new XShell();
  3027. $GLOBALS['XSHELL']->labels=new XLabels();
  3028. $mod=XModule::objectFactory($moid);
  3029. if(!$mod->secure($oidit,'savesection')) die('secerror');
  3030. $table=Kernel::getTable($oid);
  3031. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
  3032. $ar2['_options']['local']=true;
  3033. $ar2['tplentry']=TZR_RETURN_DATA;
  3034. $ar2['oid']=$oid;
  3035. $ar2[$field]=$value;
  3036. $ret=$xds->procEdit($ar2);
  3037. die($value);
  3038. }
  3039. ?>