PageRenderTime 89ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 1ms

/class.xmoddocmgt.inc

https://github.com/jcplat/console-seolan
PHP | 2972 lines | 2560 code | 164 blank | 248 comment | 522 complexity | 32ede034b84a718cb9f08adbc4693c1a MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /// Classe de base d'un document integre dans la base documentaire (xmoddocmgt)
  3. class XDocumentDT {
  4. public $title;
  5. public $comment;
  6. public $countdocs=0;
  7. public $countdirs=0;
  8. public $node=false;
  9. public $tpl;
  10. public $fields;
  11. public $insearchengine=true;
  12. protected $symbol='';
  13. static $rep_rep=array();
  14. static function &objectFactory($oid, &$docmgt, $ors=NULL, $ar=NULL) {
  15. if(isset($docmgt->doccache[$oid])) return $docmgt->doccache[$oid];
  16. $doc=array();
  17. if(empty($ors)) {
  18. $rs=selectQuery('SELECT * FROM '.$docmgt->id.',_TYPES WHERE '.$docmgt->id.'.KOID="'.$oid.'" AND '.
  19. '_TYPES.KOID=DTYPE');
  20. $ors=$rs->fetch();
  21. if(empty($ors)) return $doc;
  22. else $rs->closeCursor();
  23. }
  24. $docclass=strtolower($ors['docclas'].'DT');
  25. if(!empty($ors['docclas'])) {
  26. include_once('class.'.$docclass.'.inc');
  27. if(!class_exists($docclass)) {
  28. if($ors['node']==1) $docclass='XDirectoryDT';
  29. else $docclass='XDocumentDT';
  30. }
  31. } else {
  32. if($ors['node']==1) $docclass='XDirectoryDT';
  33. else $docclass='XDocumentDT';
  34. }
  35. $docmgt->doccache[$oid]=new $docclass($oid, $ors, $docmgt, $ar);
  36. // Si l'objet n'a pas été correctement initialisé, on le déclare vide
  37. if (empty($docmgt->doccache[$oid]->fields)) $docmgt->doccache[$oid] = '';
  38. return $docmgt->doccache[$oid];
  39. }
  40. static function &repositoryFactory($typeraw=NULL, $typedisp=NULL) {
  41. if(!empty($typeraw)) {
  42. $module=$typeraw['modidd'];
  43. $tab=$typeraw['dtab'];
  44. } else {
  45. $module=$typedisp['omodidd']->raw;
  46. $tab=$typedisp['odtab']->raw;
  47. }
  48. if(!empty($tab)) {
  49. if(empty(self::$rep_rep[$tab])) {
  50. self::$rep_rep[$tab]=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tab);
  51. }
  52. $mod=&self::$rep_rep[$tab];
  53. } else {
  54. if(empty(self::$rep_rep[$module])) {
  55. self::$rep_rep[$module]=XModule::objectFactory($module);
  56. }
  57. $mod=&self::$rep_rep[$module];
  58. }
  59. return $mod;
  60. }
  61. function __construct($oid, &$ors, &$docmgt, $ar=NULL) {
  62. $mod=&XDocumentDT::repositoryFactory($ors);
  63. if(is_object($mod)) {
  64. $dar=array('oid'=>$oid,'_lastupdate'=>false,'_options'=>array('local'=>1,'error'=>'return'),'fmoid'=>$docmgt->_moid,'tplentry'=>TZR_RETURN_DATA);
  65. if ($ar) $dar=array_merge($dar,$ar);
  66. $result=&$mod->XMCdisplay($dar,false);
  67. // S'il y a eu une erreur lors de la tentative de récupération des données de l'objet (dans ce cas $result contient le message d'erreur)
  68. if (!is_array($result)) return $result;
  69. $this->fields=&$result;
  70. $this->oid=$oid;
  71. $this->repository=&$mod;
  72. $this->module=&$docmgt;
  73. $this->tpl=&$docmgt->getTypes($ors['DTYPE']);
  74. $lines = explode("\n", stripslashes($this->tpl['oopts']->toText()));
  75. $this->tploptions=array();
  76. foreach($lines as &$line) {
  77. @list($var,$val)=explode('=',$line);
  78. if(!empty($var) && !empty($val)) {
  79. $var=trim($var);$val=trim($val);
  80. $this->tploptions[$var]=$val;
  81. }
  82. }
  83. $this->options=unserialize(stripslashes($ors['DPARAM']));
  84. $this->icon=&$this->tpl['oicon'];
  85. if(isset($this->tpl['osmallic']) && $this->tpl['osmallic']->raw!=''){
  86. $this->smallicon=&$this->tpl['osmallic']->html;
  87. $this->smalliconurl=&$this->tpl['osmallic']->url;
  88. }else{
  89. $this->smallicon=XLabels::getSysLabel('xmoddocmgt','defaultsdoc');
  90. $this->smalliconurl=TZR_SHARE_URL.'ico/'.XLabels::getSysLabel('xmoddocmgt','defaultsdoc_ico');
  91. }
  92. $this->title = $this->getTitle();
  93. $this->docs=$this->getFiles();
  94. $this->short=$this->title;
  95. $this->symbol = $ors['symbol'];
  96. $this->node=false;
  97. }
  98. }
  99. function saveOptions() {
  100. $dparam=addslashes(serialize($this->options));
  101. preparedUpdateQuery('UPDATE '.$this->module->id." SET DPARAM=? WHERE KOID=?",array($dparam,$this->oid));
  102. }
  103. function setOption($option, &$value) {
  104. $this->options[$option]=$value;
  105. }
  106. function &getOption($option) {
  107. if($this->options[$option]) return $this->options[$option];
  108. else return $this->tploptions[$option];
  109. }
  110. function getDocumentsDetails($oids=NULL) {
  111. }
  112. function getDirectoriesDetails($level=1) {
  113. }
  114. function getParents($level=1) {
  115. $this->parents=array();
  116. $this->parentsoid=array();
  117. if($this->oid==$this->module->rootOid()) return;
  118. $set=$this->module->father($this->oid);
  119. foreach($set as &$ors) {
  120. $oiddst=$ors['KOIDDST'];
  121. if(!empty($oiddst) && !in_array($oiddst,$this->parentsoid)) {
  122. if($this->module->secure1($oiddst,'index',$ors['node'])) {
  123. $d1=&XDocumentDT::objectFactory($oiddst,$this->module,$ors);
  124. if($level>1) $d1->getParents($level-1);
  125. $this->parents[]=&$d1;
  126. $this->parentsoid[]=$oiddst;
  127. }
  128. }
  129. }
  130. }
  131. // recherche de tous les chemins possibles qui sont stockés dans $this->paths
  132. //
  133. function getAllPaths() {
  134. $this->paths=array();
  135. $this->_getAllPaths1($this->paths, array($this->oid));
  136. foreach($this->paths as $i=>&$path) {
  137. $path=array_reverse($path);
  138. foreach($path as $j=>&$oidi) {
  139. $path[$j]=&XDocumentDT::objectFactory($oidi, $this->module);
  140. if($path[$j]->node!=1) unset($path[$j]);
  141. }
  142. }
  143. }
  144. private function _getAllPaths1(&$global, $currentpath) {
  145. if(empty($this->parents)) {
  146. if(!empty($currentpath)) {
  147. $global[]=$currentpath;
  148. }
  149. } else {
  150. foreach($this->parents as $i => &$p) {
  151. if(!in_array($p->oid, $currentpath)) {
  152. $copy=$currentpath;
  153. $copy[]=$this->parents[$i]->oid;
  154. $p->_getAllPaths1($global, $copy);
  155. }
  156. }
  157. }
  158. }
  159. function getContent($final=true,$update=true) {
  160. $oids=$this->module->subObjects4($this->oid, 1, false);
  161. if(!empty($this->oid)) {
  162. $this->docsoids = array_values($oids['2']);
  163. $this->countdocs = count($this->docsoids);
  164. }
  165. $this->dirsoids = array_values($oids['1']);
  166. $this->countdirs = count($this->dirsoids);
  167. }
  168. function getTitle() {
  169. return strip_tags($this->fields['link']);
  170. }
  171. /// rend le texte associe au document
  172. function getDescription() {
  173. return (!empty($this->fields['oremark'])?$this->fields['oremark']->html:'');
  174. }
  175. /// Retourne au format html la liste des fichiers du document
  176. function getFiles() {
  177. $this->countfiles=0;
  178. $txt='';
  179. foreach($this->fields['fields_object'] as $i=>&$v) {
  180. if(!empty($v->html)){
  181. if($v->fielddef instanceof XFileDef) {
  182. $txt.='<div class="tzr-xdirdef-dir"><div>'.$v->html.'</div></div> ';
  183. $this->countfiles++;
  184. }elseif($v->fielddef instanceof XFolderDef) {
  185. $txt.=$v->html.' ';
  186. if(isset($v->catalog)) $this->countfiles+=count($v->catalog);
  187. }
  188. }
  189. }
  190. return $txt;
  191. }
  192. /// rend liste des fichiers d'un document
  193. function getFilesDetails() {
  194. return getFilesDetails($this->fields);
  195. }
  196. /// liste les actions possible sur un document
  197. function &getActions() {
  198. static $m1=array('ro','rw','unlock');
  199. static $m2=array('ro');
  200. static $m3=array('ro','rw');
  201. static $m4=array();
  202. static $m5=array('ro','rw','lock');
  203. if($this->module->secure1($this->oid, 'edit',($this->node?"1":"2"))) {
  204. if(!empty($GLOBALS['XLOCK'])) {
  205. if(!empty($this->fields['_lock'])) {
  206. if(!empty($this->fields['_lock_editable'])) {
  207. $this->actions=&$m1;
  208. } else {
  209. $this->actions=&$m2;
  210. }
  211. } else $this->actions=&$m5;
  212. } elseif($this->tpl['omodid']->raw!=$this->module->_moid) {
  213. // si c'est un document partage et qu'on n'est pas dans son module d'origine
  214. $this->actions=&$m2;
  215. } else {
  216. $this->actions=&$m3;
  217. }
  218. } elseif($this->module->secure1($this->oid, 'display',($this->node?"1":"2"))) {
  219. $this->actions=&$m2;
  220. } else {
  221. $this->actions=&$m4;
  222. }
  223. }
  224. function del() {
  225. $mod = &XDocumentDT::repositoryFactory(NULL,$this->tpl);
  226. $mod->XMCdel(array('oid'=>$this->oid,'tplentry'=>TZR_RETURN_DATA));
  227. }
  228. function journal() {
  229. $mod = &XDocumentDT::repositoryFactory(NULL,$this->tpl);
  230. if(method_exists($mod,'journal')) {
  231. return $mod->journal(array('oid'=>$this->oid,'tplentry'=>TZR_RETURN_DATA));
  232. } else return NULL;
  233. }
  234. /// Ajout d'un document au moteur de recherche
  235. function addToSearchEngine(&$searchEngine) {
  236. $fields = $this->getSearchEngineData();
  237. $searchEngine->addItem($this->oid,$fields,$this->module->_moid,NULL);
  238. XLogs::notice(get_class($this),get_class($this).'::addToSearchEngine lucene');
  239. }
  240. function &getSearchEngineData(){
  241. $fields = array('notice'=>'', 'contents'=>'', 'title'=>'');
  242. $fields['contents']=getFilesContent($this->fields);
  243. $fields['title'] = $this->title;
  244. $fields['notice'] = $this->getSearchEngineNotice();
  245. return $fields;
  246. }
  247. function &getSearchEngineNotice(){
  248. $notice = '';
  249. // les champs !publiés et non fichiers dans la notice
  250. foreach($this->fields['fields_object'] as $i=>&$v) {
  251. $field = $v->fielddef;
  252. if ($field->indexable
  253. && (!$field->get_published()
  254. && !($field instanceof XFileDef)
  255. && !($field instanceof XFolderDef))){
  256. $notice .= ' '.$v->toText();
  257. }
  258. }
  259. // ajout des noms des champs fichiers
  260. $indexables = $this->getIndexablesFields();
  261. $files = getFilesDetails($this->fields);
  262. foreach($files as $afile){
  263. if (in_array($afile['field'], $indexables)){
  264. $notice .= ' '.$afile['title'];
  265. if ($afile['name'] != $afile['title'])
  266. $notice .= ' '.$afile['name'];
  267. }
  268. }
  269. return $notice;
  270. }
  271. /// rend la liste des champs indexables
  272. function getIndexablesFields(){
  273. $list = array();
  274. foreach($this->fields['fields_object'] as $i=>&$v) {
  275. if ($v->fielddef->indexable)
  276. $list[] = $v->fielddef->field;
  277. }
  278. return $list;
  279. }
  280. }
  281. /// Classe de base d'un document container (repertoire/dossier) integre dans la base documentaire (xmoddocmgt)
  282. class XDirectoryDT extends XDocumentDT {
  283. function __construct($oid, &$ors, &$docmgt, $ar=NULL) {
  284. parent::__construct($oid, $ors, $docmgt, $ar);
  285. $this->node=true;
  286. $this->comment=$this->getDescription();
  287. if(empty($this->icon->html)) {
  288. $this->icon->url=XLabels::getSysLabel('xmoddocmgt','directorybig','url');
  289. }
  290. if(isset($this->tpl['osmallic']->raw) && $this->tpl['osmallic']->raw!=''){
  291. $this->smallicon=&$this->tpl['osmallic']->html;
  292. $this->smalliconurl=&$this->tpl['osmallic']->url;
  293. }else{
  294. $this->smallicon=XLabels::getSysLabel('xmoddocmgt','defaultsdir');
  295. $this->smalliconurl=TZR_SHARE_URL.'ico/'.XLabels::getSysLabel('xmoddocmgt','defaultsdir_ico');
  296. }
  297. }
  298. /// la gestion des types possibles peut etre modifiee avec allowedChildType
  299. function getNewTypes($docs=false, $dirs=false) {
  300. if ($docs || $dirs){
  301. $phrase = '';
  302. $exp = $this->tpl['ocrules']->raw;
  303. $l = preg_split('/$/m', $exp);
  304. $convs = array(); /* tableau des associations antre symboles et lettres simples */
  305. $exps = array(); /* tableau des expressions a verifier */
  306. foreach($l as $foo=>$c){
  307. $c = trim($c);
  308. if (empty($c)) continue;
  309. /* si la chaine commence par un : c'est une affectation */
  310. $f = strpos($c, ':');
  311. if ($f !== false && $f == 0) {
  312. $c1 = substr($c, 1);
  313. list($symbol, $letter) = explode('=', $c1);
  314. $convs[$symbol] = $letter;
  315. } else {
  316. $exps[] = $c;
  317. }
  318. }
  319. $childsTypes = array(); /* tableau des types de descendants */
  320. foreach($this->documents as $oiddoc=>&$cdoc){
  321. $s = $cdoc->tpl['osymbol']->raw;
  322. if (isset($convs[$s])) $s = $convs[$s];
  323. $childsTypes[] = $s;
  324. }
  325. foreach($this->directories as $oiddoc=>&$cdoc){
  326. $s = $cdoc->tpl['osymbol']->raw;
  327. if (isset($convs[$s])) $s = $convs[$s];
  328. $childsTypes[] = $s;
  329. }
  330. }
  331. $exp = '';
  332. foreach($exps as $foo=>$e){
  333. if($exp != '') $exp .= '|'.$e;
  334. else $exp.=$e;
  335. }
  336. if(empty($exp)) $exp=".*";
  337. if($docs) {
  338. $typesname=array();
  339. $dtypes=$this->module->getTypes();
  340. foreach($dtypes as $i=>&$tpl) {
  341. $childsTypes2 = $childsTypes;
  342. $s = $tpl['osymbol']->raw;
  343. if (isset($convs[$s])) $s = $convs[$s];
  344. else $s='x';
  345. $childsTypes2[] = $s;
  346. sort($childsTypes2);
  347. $phrase2 = implode($childsTypes2, '');
  348. if($tpl['onode']->raw==2 && preg_match('/^('.$exp.')$/', $phrase2) && $this->allowedChildType($tpl, $childs) && $tpl['_rwsecure']) {
  349. $this->newdocs[$i]=&$tpl;
  350. $typesname[$i]=$tpl['otitle']->raw;
  351. }
  352. }
  353. array_multisort($typesname,$this->newdocs);
  354. }
  355. if($dirs) {
  356. $typesname=array();
  357. $oidtoprotect=$this->module->protectedOids();
  358. $dtypes=&$this->module->getTypes();
  359. foreach($dtypes as $i=>&$tpl) {
  360. if(!in_array($tpl['oid'], $oidtoprotect)) {
  361. $childsTypes2 = $childsTypes;
  362. $s = $tpl['osymbol']->raw;
  363. if (isset($convs[$s])) $s = $convs[$s];
  364. else $s='x';
  365. $childsTypes2[] = $s;
  366. sort($childsTypes2);
  367. $phrase2 = implode($childsTypes2, '');
  368. if($tpl['onode']->raw==1 && preg_match('/^('.$exp.')$/i', $phrase2) && $this->allowedChildType($tpl, $childs) && $tpl['_rwsecure']) {
  369. $this->newdirs[$i]=&$tpl;
  370. $typesname[$i]=$tpl['otitle']->raw;
  371. }
  372. }
  373. }
  374. array_multisort($typesname,$this->newdirs);
  375. }
  376. }
  377. /// types possibles pour un dossier des modeles
  378. function getNewTypesM($docs=false, $dirs=false) {
  379. $dtypes=&$this->module->getTypes();
  380. if($docs) {
  381. foreach($dtypes as $i=>&$tpl) {
  382. if($tpl['onode']->raw==2 && $tpl['_rwsecure']) {
  383. $this->newdocs[$i]=&$tpl;
  384. }
  385. }
  386. }
  387. if($dirs) {
  388. foreach($dtypes as $i=>&$tpl) {
  389. if($tpl['onode']->raw==1 && $tpl['_rwsecure']) {
  390. $this->newdirs[$i]=&$tpl;
  391. }
  392. }
  393. }
  394. }
  395. /// controle sur les regles du type : ne doit pas pouvoir etre surchargee
  396. private function _allowedChildType($csymbol, $phrase){
  397. return true;
  398. }
  399. protected function allowedChildType($csymbol) {
  400. return true;
  401. }
  402. function getDocumentsDetails() {
  403. if(!empty($this->documents)) return;
  404. if(empty($this->docsoids)) return;
  405. $order=$this->getOption('fileorder');
  406. list($order,$direction)=explode(' ',$order);
  407. // recherche des documents qui sont dans ce repertoire
  408. foreach($this->docsoids as $oid) {
  409. if(empty($set)) $set="'".$oid."'";
  410. else $set.=",'".$oid."'";
  411. }
  412. $rs=selectQuery('SELECT * FROM '.$this->module->idx.','.$this->module->id.',_TYPES where KOIDSRC in ('.$set.') '.
  413. ' and KOIDSRC='.$this->module->id.'.KOID and node=2 and '.$this->module->id.'.DTYPE=_TYPES.KOID/*2*/');
  414. if($rs) {
  415. $this->documents=array();
  416. $documents=array();
  417. $tmporder=array(); /* tableau temporaire construit pour le tri */
  418. $tmporder2=array(); /* tableau temporaire construit pour le tri */
  419. while($ors=$rs->fetch()) {
  420. if(!empty($ors['KOIDSRC'])) {
  421. // voir si document sur xdatasource et pas module -> false toujours ?
  422. $seenhere=in_array($ors['KOIDSRC'], $this->docsoids);
  423. if(!$seenhere) continue;
  424. $doc1 = &XDocumentDT::objectFactory($ors['KOIDSRC'], $this->module, $ors);
  425. // Si l'objet n'est pas accessible (dépublié par exemple)
  426. if (!is_object($doc1)) continue;
  427. $doc1->getActions();
  428. $documents[$ors['KOIDSRC']]=$doc1;
  429. $this->documents[$ors['KOIDSRC']]=NULL;
  430. if(isset($documents[$ors['KOIDSRC']]->fields['o'.$order])) {
  431. $tmporder[$ors['KOIDSRC']]=$documents[$ors['KOIDSRC']]->fields['o'.$order]->raw;
  432. } elseif($order=='doctype') {
  433. $tmporder[$ors['KOIDSRC']]=$documents[$ors['KOIDSRC']]->tpl['osymbol']->raw;
  434. } else {
  435. $tmporder[$ors['KOIDSRC']]=$documents[$ors['KOIDSRC']]->title;
  436. }
  437. $tmporder2[$ors['KOIDSRC']]=$documents[$ors['KOIDSRC']]->title;
  438. }
  439. }
  440. }
  441. if($direction=='DESC') array_multisort($tmporder, SORT_DESC, $tmporder2, $this->documents);
  442. else array_multisort($tmporder, SORT_ASC, $tmporder2, $this->documents);
  443. foreach($this->documents as $key=>&$val)
  444. $val=$documents[$key];
  445. }
  446. function getDirectoriesDetails($level=1) {
  447. if(!empty($this->directories)) return;
  448. if(empty($this->dirsoids)) return;
  449. $order=$this->getOption('directoryorder');
  450. list($order,$direction)=explode(' ',$order);
  451. // recherche des documents qui sont dans ce repertoire
  452. foreach($this->dirsoids as $oid) {
  453. if(empty($set)) $set="'".$oid."'";
  454. else $set.=",'".$oid."'";
  455. }
  456. $rs=selectQuery('SELECT * FROM '.$this->module->idx.','.$this->module->id.',_TYPES where KOIDSRC in ('.$set.') '.
  457. ' and KOIDSRC='.$this->module->id.'.KOID and '.$this->module->id.'.DTYPE=_TYPES.KOID/*1*/');
  458. if($rs) {
  459. $this->directories=array(); /* tableau des documents tries */
  460. $directories=array(); /* tableau des documents non tries */
  461. $tmporder=array(); /* tableau temporaire construit pour le tri */
  462. $tmporder2=array(); /* tableau temporaire construit pour le tri */
  463. while($ors=$rs->fetch()) {
  464. if(!empty($ors['KOIDSRC'])) {
  465. if(!$this->module->secure1($ors['KOIDSRC'], 'index',$ors['node'])) continue;
  466. $doc1 = &XDocumentDT::objectFactory($ors['KOIDSRC'], $this->module, $ors);
  467. $doc1->parents[]=&$this;
  468. $doc1->parentsoids[]=$this->oid;
  469. $this->directories[$ors['KOIDSRC']]=NULL;
  470. $directories[$ors['KOIDSRC']]=$doc1;
  471. $directories[$ors['KOIDSRC']]->getContent();
  472. if($level>0) {
  473. $directories[$ors['KOIDSRC']]->getDirectoriesDetails($level-1);
  474. }
  475. if(isset($directories[$ors['KOIDSRC']]->fields['o'.$order])) {
  476. $tmporder[$ors['KOIDSRC']]=$directories[$ors['KOIDSRC']]->fields['o'.$order]->raw;
  477. } elseif($order=='doctype') {
  478. $tmporder[$ors['KOIDSRC']]=$directories[$ors['KOIDSRC']]->tpl['osymbol']->raw;
  479. } else {
  480. $tmporder[$ors['KOIDSRC']]=$directories[$ors['KOIDSRC']]->title;
  481. }
  482. $tmporder2[$ors['KOIDSRC']]=$directories[$ors['KOIDSRC']]->title;
  483. }
  484. }
  485. if($direction=='DESC') array_multisort($tmporder, SORT_DESC, $tmporder2, $this->directories);
  486. else array_multisort($tmporder, SORT_ASC, $tmporder2, $this->directories);
  487. foreach($this->directories as $key=>&$val)
  488. $val=$directories[$key];
  489. }
  490. $rs->closeCursor();
  491. }
  492. // notice du repertoire pour moteur de recherche
  493. // le reste = document (si fichiers ils sont pris)
  494. function getSearchEngineNotice(){
  495. $notice = parent::getSearchEngineNotice();
  496. if (isset($this->fields['oremark']) && is_object($this->fields['oremark']) && (!$this->fields['oremark']->fielddef->indexable)){
  497. $notice = $this->fields['oremark']->text.' '.$notice;
  498. }
  499. return $notice;
  500. }
  501. // ajout d'un descendant
  502. //
  503. function addChild($oid) {
  504. $q="SELECT COUNT(*) FROM {$this->module->idx} WHERE KOIDSRC='$oid' AND KOIDDST='{$this->oid}'";
  505. $rs=selectQuery($q);
  506. $ors=$rs->fetch();
  507. if($ors['COUNT(*)']<=0) {
  508. $q='INSERT INTO '.$this->module->idx.' SET KOIDSRC="'.$oid.'", KOIDDST="'.$this->oid.'"';
  509. updateQuery($q);
  510. }
  511. }
  512. }
  513. /// Module de gestion d'une base documentaire
  514. class XModDocMgt extends XModule {
  515. public $prefix='DM';
  516. // suffixe de l'oid du dosssier qui contient les modeles
  517. var $patternSuffix = 'TEMPLATES';
  518. // table (xset) de description par defaut des dossiers
  519. public $defaultFolderTable = 'REP1';
  520. var $doccache=array();
  521. var $documentssec=true;
  522. public $trackchanges=true;
  523. public $trackaccess=false;
  524. public $searchtemplate='xmoddocmgt/searchResult.html';
  525. var $_s=array();
  526. function __construct($ar=NULL) {
  527. parent::__construct($ar);
  528. $this->idx = $this->prefix.'IDX';
  529. $this->id = $this->prefix.'ID';
  530. $this->lang = XShell::getLangData();
  531. $this->_f=array();
  532. $this->opts=XOpts::getOpt(XUser::get_current_user_uid(), $this->_moid, 'opts');
  533. XLabels::loadLabels('xmoddocmgt');
  534. }
  535. /// Liste des tables utilisées par le module
  536. public function usedTables(){
  537. $ret=$this->usedMainTables();
  538. $ret[]=$this->idx;
  539. $ret[]=$this->id;
  540. return $ret;
  541. }
  542. public function usedMainTables() {
  543. $rs=&selectQuery('select modidd,dtab from _TYPES where modid="'.$this->_moid.'"');
  544. $ret=array();
  545. while($ors=$rs->fetch()){
  546. if(!empty($ors['dtab'])) $ret[]=$ors['dtab'];
  547. else{
  548. $mod=XModule::objectFactory($ors['modidd']);
  549. if(is_object($mod)){
  550. $t=$mod->usedTables();
  551. if($t) $ret=array_merge($ret,$t);
  552. }
  553. }
  554. }
  555. return $ret;
  556. }
  557. /// rend la liste des types de doc ou le type de doc d'oid $oid
  558. public function &getTypes($oid=NULL) {
  559. $foooid=NULL;
  560. if(empty($this->doctypes) || empty($this->doctypes[$oid])) {
  561. // recherche des types de document
  562. $mods=array_keys(XModule::modulesUsingTable('_TYPES',false,false,false));
  563. $moid=$mods[0];
  564. $mod=XModule::objectFactory($moid);
  565. $oids=$mod->xset->browseOids(array('_filter'=>'(modid="'.$this->_moid.'" OR KOID="'.$oid.'")','_options'=>array('local'=>true)));
  566. if($mod->object_sec) $oidsrights=$GLOBALS['XUSER']->getObjectsAccess($mod,XShell::getLangData(),$oids);
  567. foreach($oids as $i=>$toid){
  568. $foo1=$mod->xset->rDisplay($toid);
  569. if(!$mod->object_sec || array_key_exists('ro',$oidsrights[$i])) $foo1['_rwsecure']=true;
  570. if($foo1['omodid']->raw==$this->_moid) {
  571. $this->doctypes[$toid]=$foo1;
  572. } else {
  573. $foo1['otitle']->html.=' / '.XLabels::getSysLabel('xmoddocmgt.source').' '.$foo1['omodid']->html;
  574. }
  575. if($foo1['oid']==$oid) $foooid=$foo1;
  576. }
  577. }
  578. if(empty($oid)) return $this->doctypes;
  579. elseif(!empty($foooid)) return $foooid;
  580. else return $this->doctypes[$oid];
  581. }
  582. function protectedOids() {
  583. $oidtoprotect=array('_TYPES:root-'.$this->_moid,
  584. '_TYPES:lostandfound-'.$this->_moid,
  585. '_TYPES:trash-'.$this->_moid,
  586. '_TYPES:archive-'.$this->_moid);
  587. return $oidtoprotect;
  588. }
  589. /// Suppression du module
  590. function delete($ar=NULL) {
  591. parent::delete($ar);
  592. // Suppression des types de docs du module
  593. updateQuery('delete from _TYPES where modid="'.$this->_moid.'"');
  594. }
  595. /// Initialisation des propriétés
  596. public function initOptions() {
  597. parent::initOptions();
  598. $slabel=XLabels::getSysLabel('general','security','text');
  599. $this->_options->setOpt('Gerer la securite sur les documents', 'documentssec', 'boolean', NULL, true, $slabel);
  600. $tlabel=XLabels::getSysLabel('xmodule.tracking');
  601. $this->_options->setOpt(XLabels::getSysLabel('xfielddef','trackaccess'),'trackaccess','boolean',NULL,NULL,$tlabel);
  602. $this->_options->setOpt('Préfixe','prefix','text');
  603. $this->_options->setOpt('Table par défaut des repertoires','defaultFolderTable','table');
  604. }
  605. /// securite des fonctions accessibles par le web
  606. function secGroups($function, $group=NULL) {
  607. $g=array();
  608. $g['index']=array('list','ro','rw','rwv','admin');
  609. $g['index2']=array('list','ro','rw','rwv','admin');
  610. $g['index2Light']=array('list','ro','rw','rwv','admin');
  611. $g['viewDir']=array('list', 'ro','rw','rwv','admin');
  612. $g['ajaxLoadDir']=array('list','ro','rw','rwv','admin');
  613. $g['ajaxLoadDirTree']=array('list','ro','rw','rwv','admin');
  614. $g['input']=array('rw','rwv','admin');
  615. $g['procInput']=array('rw','rwv','admin');
  616. $g['journal']=array('ro','rw','rwv','admin');
  617. $g['edit']=array('rw','rwv','admin');
  618. $g['display']=array('ro','rw','rwv','admin');
  619. $g['procEdit']=array('rw','rwv','admin');
  620. $g['del']=array('rw','rwv','admin');
  621. $g['search']=array('list','ro','rw','rwv','admin');
  622. $g['advsearch']=array('list','ro','rw','rwv','admin');
  623. $g['linkTo']=array('list', 'ro', 'rw','rwv','admin');
  624. $g['getLast']=array('list','ro','rw','rwv','admin');
  625. $g['getUnread']=array('list','ro','rw','rwv','admin');
  626. $g['markAsRead']=array('list','ro','rw','rwv','admin');
  627. $g['subscribe']=array('ro','rw','rwv','admin');
  628. $g['preSubscribe']=array('ro','rw','rwv','admin');
  629. $g['admin']=array('admin');
  630. $g['documentsDownload']=array('ro','rw','rwv','admin');
  631. $g['export']=array('ro','rw','rwv','admin');
  632. $g['exportFTP']=array('ro','rw','rwv','admin');
  633. $g['exportBatch']=array('ro','rw','rwv','admin');
  634. $g['procSendACopyTo']=array('list', 'ro','rw','rwv','admin');
  635. $g['prePrintDisplay']=array('list','ro','rw','rwv','admin');
  636. $g['printDisplay']=array('ro','rw','rwv','admin');
  637. $g['share']=array('rw','rwv','admin');
  638. $g['procShare']=array('rw','rwv','admin');
  639. $g['setRootOid']=array('ro','rw','rwv','admin');
  640. $g['clearRootOid']=array('ro','rw','rwv','admin');
  641. if(isset($g[$function])) {
  642. if(!empty($group)) return in_array($group, $g[$function]);
  643. return $g[$function];
  644. }
  645. return parent::secGroups($function,$group);
  646. }
  647. /// Action principale du menu
  648. public function getMainAction(){
  649. return $GLOBALS['TZR_SESSION_MANAGER']::complete_self().'moid='.$this->_moid.'&_function=index&tplentry=br&template=xmoddocmgt/index2.html&maxlevel=2&'.
  650. 'clear=1&oid='.$this->rootOid();
  651. }
  652. /// Cette fonction est appliquee pour afficher l'ensemble des methodes de ce module
  653. protected function _actionlist(&$my=NULL) {
  654. parent::_actionlist($my);
  655. $myclass=get_class($this);
  656. $moid=$this->_moid;
  657. $uniqid='v'.XShell::uniqid();
  658. $dir='xmoddocmgt';
  659. $myoid = @$_REQUEST['oid'];
  660. $mypoid = @$_REQUEST['_parentoid'];
  661. if(empty($myoid)) $myoid=$this->rootOid();
  662. $ri=XUser::secure8maxlevel($this);
  663. if($ri=='admin'){
  664. $o1=new XModuleAction($this, 'exportfs', XLabels::getSysLabel('general','export','text'),
  665. '&moid='.$moid.
  666. '&_function=index&tplentry=br&'.
  667. 'template='.$dir.'/export.html&_parentoid='.$mypoid.'&oid='.$myoid);
  668. $o1->homepageable=false;
  669. $o1->menuable=true;
  670. $o1->quicklinkable=true;
  671. $o1->group='actions';
  672. $my['exportfs']=$o1;
  673. }
  674. $suid=getSessionVar('SUID');
  675. if(!empty($suid)) {
  676. if(!empty($this->opts['home'])) {
  677. $o1=new XModuleAction($this, 'clearrootoid', XLabels::getSysLabel('xmoddocmgt','clearrootoid','text'),
  678. '&moid='.$moid.'&_function=clearRootOid&tplentry=br&'.'template='.$dir.'/index2.html&maxlevel=2&clear=1',
  679. 'more');
  680. $o1->menuable=true;
  681. $my['setrootoid']=$o1;
  682. } elseif(!empty($myoid)) {
  683. $o1=new XModuleAction($this, 'setrootoid', XLabels::getSysLabel('xmoddocmgt','setrootoid','text'),
  684. '&moid='.$moid.'&_function=setRootOid&tplentry=br&'.'template='.$dir.'/index2.html&maxlevel=2&clear=1&'.
  685. '&oid='.$myoid,'more');
  686. $o1->menuable=true;
  687. $my['setrootoid']=$o1;
  688. }
  689. }
  690. $rw=$this->secure($myoid,'edit');
  691. $admin=$this->secure($myoid,'secEdit');
  692. if(XShell::_function()!='index2') {
  693. // Arbo a plat
  694. $o1=new XModuleAction($this, 'index1', XLabels::getSysLabel('xmoddocmgt','index','text'),
  695. '&moid='.$moid.'&_function=index&tplentry=br&'.'template='.$dir.'/index2.html&maxlevel=2&clear=1&'.
  696. '_parentoid='.$mypoid.'&oid='.$myoid,'display');
  697. $o1->setToolbar('general','browse');
  698. $o1->order=1;
  699. $my['index1']=$o1;
  700. // Arborescence
  701. $o1=new XModuleAction($this, 'index2', XLabels::getSysLabel('general','tree','text'),
  702. '&moid='.$moid.'&_function=index2&tplentry=br&template='.$dir.'/index3.html&maxlevel=10&'.
  703. '_parentoid='.$mypoid.'&oid='.$myoid,'display');
  704. $o1->setToolbar('general','tree');
  705. $o1->order=2;
  706. $my['index2']=$o1;
  707. // Recherche avancée
  708. if($this->secure('','advsearch')){
  709. $o1=new XModuleAction($this,'advsearch', XLabels::getSysLabel('xmoddocmgt','advsearch','text'),
  710. '&moid='.$moid.'&_function=advsearch&tplentry=br&template='.$dir.'/advsearch.html','display');
  711. $o1->setToolbar('xmoddocmgt','advsearch');
  712. $o1->order=3;
  713. $my['advsearch']=$o1;
  714. }
  715. if(!empty($myoid) && Kernel::isAKoid($myoid)) {
  716. $o1=new XModuleAction($this,'display',XLabels::getSysLabel('general', 'view','text'),
  717. '&moid='.$moid.'&_function=display&tplentry=br&'.'template='.$dir.'/display.html&oid='.$myoid,'edit');
  718. $o1->setToolbar('general','display');
  719. $o1->order=1;
  720. $my['display']=$o1;
  721. if($myoid!=$this->rootOid()) {
  722. if($rw){
  723. // Edition
  724. $o1=new XModuleAction($this,'edit',XLabels::getSysLabel('general','edit','text'),
  725. '&moid='.$moid.'&_function=edit&tplentry=br&template='.$dir.'/edit.html&_parentoid='.$mypoid.
  726. '&oid='.$myoid,'edit');
  727. $o1->setToolbar('general','edit');
  728. $o1->order=2;
  729. $my['edit']=$o1;
  730. // Réservation
  731. if(!empty($GLOBALS['XLOCK']) && !$GLOBALS['XLOCK']->locked($myoid,TZR_DEFAULT_LANG)) {
  732. if(!empty($myoid)) $dmyoid=&XDocumentDT::objectFactory($myoid, $this);
  733. if(is_object($dmyoid) && !($dmyoid instanceof XDirectoryDT)) {
  734. $o1=new XModuleAction($this,'lock', XLabels::getSysLabel('general','lock','text'),
  735. '&moid='.$moid.'&_function=edit&tplentry=br&_mode=lock&'.
  736. 'template='.$dir.'/edit.html&_parentoid='.$mypoid.'&oid='.$myoid,'edit');
  737. $o1->setToolbar('general','lock');
  738. $o1->order=3;
  739. $my['lock']=$o1;
  740. }
  741. }
  742. }
  743. // Droits
  744. if($admin) {
  745. $self=$GLOBALS['TZR_SESSION_MANAGER']::complete_self(true);
  746. $o1=new XModuleAction($this,'security',XLabels::getSysLabel('general','security','text'),
  747. 'javascript:TZR.editSec("'.$self.'","'.$moid.'","'.$myoid.'",'.$uniqid.');','edit');
  748. $o1->menuable=true;
  749. $o1->setToolbar('general','security');
  750. $my['security2']=$o1;
  751. }
  752. // Pour ces deux actions les droits dependent de la destination
  753. // Copier
  754. $o1=new XModuleAction($this,'linkTo',XLabels::getSysLabel('general','copy','text'),
  755. 'javascript:'.$uniqid.'.copyselected("'.$myoid.'");','edit');
  756. $o1->menuable=true;
  757. $my['copy']=$o1;
  758. // Liaison
  759. $o1=new XModuleAction($this,'linkTo',XLabels::getSysLabel('xmoddocmgt','link','text'),
  760. 'javascript:'.$uniqid.'.linkselected("'.$myoid.'");','edit');
  761. $o1->menuable=true;
  762. $my['link']=$o1;
  763. // Déplacement
  764. if($rw){
  765. $o1=new XModuleAction($this,'linkTo',XLabels::getSysLabel('general','move','text'),
  766. 'javascript:'.$uniqid.'.moveselected("'.$myoid.'");','edit');
  767. $o1->setToolbar('general','move');
  768. $my['move']=$o1;
  769. }
  770. }
  771. // Suppression
  772. if($this->secure($myoid,'del')){
  773. $o1=new XModuleAction($this,'del',XLabels::getSysLabel('general', 'delete','text'),'javascript:'.$uniqid.'.deleteselected('.($myoid!=$this->rootOid()?'':'true').');',
  774. 'edit');
  775. $o1->setToolbar('general','delete');
  776. $o1->order=4;
  777. $my['delete']=$o1;
  778. }
  779. }
  780. }else{
  781. // Vue a plat du dossier en cours
  782. $o1=new XModuleAction($this, 'index1', XLabels::getSysLabel('xmoddocmgt','index','text'),'javascript:'.$uniqid.'.gotonode();');
  783. $o1->homepageable=$o1->menuable=true;
  784. $o1->quicklinkable=true;
  785. $o1->group='display';
  786. $o1->setToolbar('general','browse');
  787. $my['index1']=$o1;
  788. // Suppression
  789. if($this->secure($myoid,'del')){
  790. $o1=new XModuleAction($this,'del',XLabels::getSysLabel('general','delete','text'),'javascript:'.$uniqid.'.deleteselected();',
  791. 'edit');
  792. $o1->menuable=true;
  793. $o1->setToolbar('general','delete');
  794. $my['delete']=$o1;
  795. }
  796. }
  797. // Téléchargement
  798. $o1=new XModuleAction($this,'download',XLabels::getSysLabel('xmoddocmgt','downloadselected','text'),
  799. 'javascript:'.$uniqid.'.downloadselected();','edit');
  800. $o1->menuable=true;
  801. $my['download']=$o1;
  802. if(!empty($myoid) && Kernel::isAKoid($myoid)){
  803. // Abonnement
  804. $xmodsubmoid=XModule::getMoid(XMODSUB_TOID);
  805. if(!empty($xmodsubmoid) && $this->secure($myoid,'preSubscribe')){
  806. $o1=new XModuleAction($this,'subscribe',XLabels::getSysLabel('xmodsub', 'subscribe', 'text'),
  807. '&moid='.$this->_moid.'&oid='.$myoid.'&_function=preSubscribe&tplentry=br&template=xmoddocmgt/sub.html',
  808. 'more');
  809. $o1->menuable=true;
  810. $my['subscribe']=$o1;
  811. }
  812. if ($this->secure($myoid,'sendACopyTo')){
  813. // Avertir
  814. if(XShell::_function()=='display' || XShell::_function()=='edit'){
  815. $o1=new XModuleAction($this,'sendACopy',XLabels::getSysLabel('xmodule','sendacopyto','text'),
  816. '&moid='.$this->_moid.'&tplentry=br&oid='.$myoid.
  817. '&_function=sendACopyTo&template=xmodule/sendacopyto.html&tplentry=br','more');
  818. }else{
  819. $o1=new XModuleAction($this,'sendACopy',XLabels::getSysLabel('xmodule','sendacopyto','text'),
  820. 'javascript:TZR.applySelected("sendACopyTo",document.forms["browse'.XShell::uniqid().'"],"","xmodule/sendacopyto.html",'.
  821. '"br","'.addslashes(XLabels::getSysLabel('general','error_select_object','text')).'");','more');
  822. }
  823. $o1->menuable=true;
  824. $my['sendacopy']=$o1;
  825. }
  826. }
  827. // Voir les derniers documents
  828. $o1=new XModuleAction($this,'lastdoc',XLabels::getSysLabel('xmoddocmgt','lastdoc','text'),
  829. '&moid='.$this->_moid.'&_function=getLast&tplentry=br&template=xmoddocmgt/getlast.html','display');
  830. $o1->menuable=true;
  831. $my['lastdoc']=$o1;
  832. // Voir les documents non lus
  833. if($this->trackaccess && $this->secure('','getUnread')){
  834. $o1=new XModuleAction($this,'lastdoc',XLabels::getSysLabel('xmodule','unread','text'),
  835. '&moid='.$this->_moid.'&_function=getUnread&tplentry=br&template=xmoddocmgt/getUnread.html','display');
  836. $o1->menuable=true;
  837. $my['unread']=$o1;
  838. }
  839. // Création du contexte si en mode interactif
  840. if($this->interactive) $this->mkContext2($my, $myoid);
  841. }
  842. /// Menu spécifique au display
  843. function al_display(&$my){
  844. $this->getSSMAl($my);
  845. $br=XShell::from_screen('br');
  846. if(method_exists($br['here']->repository,'printDisplay') && $br['here']->repository->secure($oid,'printDisplay')){
  847. $o1=new XModuleAction($this,'print',XLabels::getSysLabel('general','print','text'),
  848. 'javascript:window.open("'.$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&function=prePrintDisplay&moid='.$this->_moid.'&template=xmodtable/preprintview.html&tplentry=br&oid='.$br['oid'].'","print","width=650,height=550,scrollbars=yes,location=no,resizable=yes,menubar=yes");','display');
  849. $o1->setToolbar('general','print');
  850. $o1->order=3;
  851. $my['print']=$o1;
  852. }
  853. }
  854. function al_edit(&$my){
  855. $this->al_display($my);
  856. }
  857. /// duplication d'un module, méthode interne (retour : tables => liste des tables dupliquées par le module (cle : ancienne table, valeur : nouvelle table))
  858. function _duplicateModule($newmoid,&$params,$prefix) {
  859. if(!empty($params['tables']) && is_array($params['tables'])) $mods=$params['mods'];
  860. else $mods=array();
  861. if(!empty($params['tables']) && is_array($params['tables'])) $tables=$params['tables'];
  862. else $tables=array();
  863. // creation des tables dmid et dmidx
  864. $newprefix = XModDocMgtWd::newPrefix();
  865. updateQuery('CREATE TABLE '.$newprefix.'ID like '.$this->id);
  866. updateQuery('CREATE TABLE '.$newprefix.'IDX like '.$this->idx);
  867. XModDocMgtWd::createStructure($newprefix);
  868. $params['prefix']=$newprefix;
  869. $tables[$this->id]=$newprefix.'ID';
  870. $tables[$this->idx]=$newprefix.'IDX';
  871. // copie des donnees dans la structure
  872. updateQuery('INSERT INTO '.$newprefix.'ID select * from '.$this->id);
  873. updateQuery('INSERT INTO '.$newprefix.'IDX select * from '.$this->idx);
  874. // Duplication de toutes les tables de documents et des types de doc
  875. $moid=$this->_moid;
  876. $all=selectQueryGetAll('select KOID,dtab,modidd from _TYPES where modid="'.$this->_moid.'"');
  877. $dstype=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS=_TYPES');
  878. foreach($all as $data) {
  879. $tab=$ntab=NULL;
  880. $koid=$data['KOID'];
  881. if(empty($data['modidd']) && !empty($data['dtab'])) {
  882. // duplication du module dans le cas ou le doc est gere par une source de donnees
  883. // Etape 1 : duplication de la table
  884. $tab=$data['dtab'];
  885. if(empty($tables[$tab])){
  886. $ntab=$ar['newtable']=XDSTable::newTableNumber();
  887. $tables[$tab]=$ntab;
  888. $xset=XDataSource::objectFactoryHelper8('SPECS='.$data['dtab']);
  889. if(($pos=strpos($xset->getLabel(),':'))!==false) $ar['mtxt']=$prefix.substr($xset->getLabel(),$pos);
  890. else $ar['mtxt']=$prefix.':'.$xset->getLabel();
  891. $ar['data']=true;
  892. $ar['_options']=array('local'=>1);
  893. $xset2=$xset->procDuplicateDataSource($ar);
  894. }else{
  895. $ntab=$tables[$tab];
  896. }
  897. XLogs::debug('XModDocMgt::_duplicateModule: cloning table '.$tab.' to '.$ntab);
  898. // etape 2 :duplication de l'entree dans la liste des documents type
  899. $ardup=array('_options'=>array('local'=>1));
  900. $ardup['oid']=$koid;
  901. $nkoid=$dstype->duplicate($ardup);
  902. preparedUpdateQuery('UPDATE _TYPES set dtab=?,modid=? where KOID=?',array($ntab,$newmoid,$nkoid));
  903. } elseif(!empty($data['modidd'])) {
  904. // duplication de la table quand les doc sont gere par un un module
  905. if(empty($mods[$data['modidd']])){
  906. $module=XModule::objectFactory($data['modidd']);
  907. // etape 1 : duplication du module
  908. $ret=$module->duplicateModule(array('tables'=>$tables,'group'=>(!empty($params['group'])?$params['group']:$this->group)));
  909. $thenewmoid=$ret['moid'];
  910. $tables=$tables+$ret['duplicatetables'];
  911. $mods=$mods+$ret['duplicatemods'];
  912. }else{
  913. $thenewmoid=$mods[$data['modidd']];
  914. }
  915. // etape 2 : duplication de l'entree dans la liste des documents type
  916. $ardup=array('_options'=>array('local'=>1));
  917. $ardup['oid']=$koid;
  918. $nkoid=$dstype->duplicate($ardup);
  919. preparedUpdateQuery('UPDATE _TYPES set modidd=?,modid=? where KOID=?',array($thenewmoid,$newmoid,$nkoid));
  920. $newmodule=XModule::objectFactory($thenewmoid);
  921. $ntab=$newmodule->table;
  922. $tab=$module->table;
  923. XLogs::debug('XModDocMgt::_duplicateModule: cloning module '.$data['modidd'].' to '.$thenewmoid.' table '.$ntab);
  924. }
  925. // on renomme la racine
  926. if(preg_match('@_TYPES\:root-([0-9]+)@',$koid)) {
  927. $nnkoid='_TYPES:root-'.$newmoid;
  928. preparedUpdateQuery('UPDATE _TYPES set KOID=? where KOID=?',array($nnkoid,$nkoid));
  929. $nkoid=$nnkoid;
  930. // on renseigne la table des dossiers par defaut
  931. $rsroot=selectQuery('SELECT * FROM _TYPES WHERE KOID="'.$nkoid.'"');
  932. if($rsroot && $orsroot=$rsroot->fetch()) {
  933. if(!empty($orsroot['dtab'])) $params['defaultFolderTable']=$orsroot['dtab'];
  934. }
  935. }
  936. if(!empty($ntab) && !empty($tab)) {
  937. // on renomme les oids un peu partout
  938. updateQuery('update '.$newprefix."ID set UPD=UPD,KOID='$ntab:root-$newmoid' where KOID='$tab:root-$moid'");
  939. updateQuery('update '.$newprefix.'ID set UPD=UPD,KOID=replace(KOID,"'.$tab.':","'.$ntab.':")');
  940. updateQuery('update '.$newprefix.'ID set UPD=UPD,DTYPE="'.$nkoid.'" WHERE DTYPE="'.$koid.'"');
  941. updateQuery('update '.$newprefix."IDX set KOIDDST='$ntab:root-$newmoid' WHERE KOIDDST='$tab:root-$moid'");
  942. updateQuery('update '.$newprefix."IDX set KOIDSRC='$ntab:root-$newmoid' WHERE KOIDSRC='$tab:root-$moid'");
  943. updateQuery('update '.$newprefix.'IDX set KOIDSRC=replace(KOIDSRC,"'.$tab.':","'.$ntab.':")');
  944. updateQuery('update '.$newprefix.'IDX set KOIDDST=replace(KOIDDST,"'.$tab.':","'.$ntab.':")');
  945. }
  946. }
  947. return array('duplicatetables'=>$tables,'duplicatemods'=>$moids);
  948. }
  949. function getSSMAl(&$my){
  950. $uniqid='v'.XShell::uniqid();
  951. $br=XShell::from_screen('br');
  952. $myoid=$br['oid'];
  953. $max=count($br['__ssmod']);
  954. $ssmmenu=array();
  955. for($i=0;$i<$max;$i++) {
  956. $f='ssmod'.$i;
  957. $ft=$br['__ssprops'][$i]['modulename'];
  958. $ff=$br['__ssprops'][$i]['linkedfield'];
  959. $fa=$br['__ssprops'][$i]['activate_additem'];
  960. $fmoid=$br['__ssprops'][$i]['_moid'];
  961. if($ff && ($ff!='*none*' && $fa && $br['__ssinsert'][$i])){
  962. $o1=new XModuleAction($this,$f,$br['__ssprops'][$i]['modulename'],
  963. 'javascript:'.$uniqid.'.addTabs("'.$fmoid.'","'.$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&moid='.$fmoid.'&_linkedfield='.$ff.
  964. '&_parentoid='.$myoid.'&function=insert&template=xmodtable/new.html&tplentry=br&_raw=1&_ajax=1&skip=1'.
  965. '&tabsmode=1","'.XLabels::getSysLabel('general','add','text').' : '.$ft.'");');
  966. $o1->menuable=true;
  967. $ssmmenu[]=$o1;
  968. }
  969. }
  970. if(count($ssmmenu)>1){
  971. $o1=new XModuleAction($this,'alladd',XLabels::getSysLabel('general','add','text'),'#');
  972. $o1->menuable=true;
  973. $o1->newgroup='ssm';
  974. $my['ssm']=$o1;
  975. foreach($ssmmenu as &$o1){
  976. $o1->group='ssm';
  977. $my[$o1->xfunction]=$o1;
  978. }
  979. }else{
  980. foreach($ssmmenu as &$o1){
  981. $o1->name=XLabels::getSysLabel('general','add','text').' : '.$o1->name;
  982. $my[$o1->xfunction]=$o1;
  983. }
  984. }
  985. }
  986. /// Suppression dans le module des documents qui sont effaces depuis d'autres modules
  987. function _removeRegisteredOid($oid) {
  988. updateQuery('delete from '.$this->idx.' where KOIDSRC="'.$oid.'"');
  989. updateQuery('delete from '.$this->id.' where KOID="'.$oid.'"');
  990. $this->delDocFromSearchEngine($oid);
  991. }
  992. function status($ar=NULL) {
  993. // inserez votre code personnalise ici
  994. }
  995. /// Affichage sur deux niveaux des dossiers et des fichiers
  996. function &index($ar=NULL) {
  997. $p=new XParam($ar,array('up'=>1,'down'=>1,'oid'=>'','maxlevel'=>2, 'showfiles'=>1, 'clear'=>false));
  998. $clear=$p->get('clear');
  999. if(!empty($clear)) $this->_clearSession('docmode');
  1000. if($this->_getSession('docmode')=='index2') {
  1001. $GLOBALS['XSHELL']->setTemplates('xmoddocmgt/index3.html');
  1002. return $this->index2($ar);
  1003. }
  1004. $tplentry=$p->get('tplentry');
  1005. $maxlevel=$p->get('maxlevel');
  1006. $showfiles=$p->get('showfiles');
  1007. $fileorder=$p->get('fileorder');
  1008. $directoryorder=$p->get('directoryorder');
  1009. $oid=$p->get('oid');
  1010. // Si pas d'oid, on prend la racine
  1011. if(empty($oid)) $_REQUEST['oid']=$oid=$this->rootOid();
  1012. // Recherche du dossier parent si le document que l'on essaie d'afficher n'est pas un dossier
  1013. $rs=selectQuery('select * from '.$this->id.' left outer join _TYPES on '.$this->id.'.DTYPE=_TYPES.KOID '.
  1014. 'where '.$this->id.'.KOID="'.$oid.'"');
  1015. if($rs && ($ors=$rs->fetch())) {
  1016. if($ors['node']==2) {
  1017. $rs=selectQuery('select * from '.$this->idx.' where KOIDSRC="'.$oid.'"/*6*/');
  1018. if($rs && ($ors=$rs->fetch())) $_REQUEST['oid']=$oid=$ors['KOIDDST'];
  1019. }
  1020. }
  1021. $r['here']=&XDocumentDT::objectFactory($oid, $this);
  1022. // Si l'ordre de tri a changé, on le sauvegarde
  1023. if(!empty($fileorder)) {
  1024. $r['here']->setOption('fileorder',$fileorder);
  1025. $r['here']->saveOptions();
  1026. }
  1027. if(!empty($directoryorder)) {
  1028. $r['here']->setOption('directoryorder',$directoryorder);
  1029. $r['here']->saveOptions();
  1030. }
  1031. // Recupere les details du document
  1032. $r['here']->getContent(true);
  1033. $r['here']->getDocumentsDetails();
  1034. $r['here']->getDirectoriesDetails($maxlevel-1);
  1035. $r['here']->getActions();
  1036. $path=&$this->mkContext($oid);
  1037. if($showfiles==2) {
  1038. foreach($r['here']->directories as &$dir) {
  1039. $dir->getDocumentsDetails();
  1040. }
  1041. }
  1042. $r['path']=&$path;
  1043. $r['oidcurrent']=$r['here']->oid;
  1044. // Liste des types qui peuvent etre ajouté dans le dossier en court
  1045. if($this->getPatternsFolderOid()==$path[0]->oid) $r['here']->getNewTypesM(true,true);
  1046. else $r['here']->getNewTypes(true, true);
  1047. // Liste des tris possible sur les dossiers
  1048. $sorting=@$r['here']->tploptions['dirsorting'];
  1049. if(!empty($sorting)){
  1050. $sortinglist=array();
  1051. $list=explode(';',$sorting);
  1052. foreach($list as $i=>$f){
  1053. $param=explode(',',$f);
  1054. if(count($param)==2) $sortinglist[]=array('name'=>$param[0],'order'=>$param[1]);
  1055. }
  1056. $r['dirsorting']=$sortinglist;
  1057. }
  1058. // Liste des tris possible sur les documents
  1059. $sorting=@$r['here']->tploptions['sorting'];
  1060. if(!empty($sorting)){
  1061. $sortinglist=array();
  1062. $list=explode(';',$sorting);
  1063. foreach($list as $i=>$f){
  1064. $param=explode(',',$f);
  1065. if(count($param)==2) $sortinglist[]=array('name'=>$param[0],'order'=>$param[1]);
  1066. }
  1067. $r['sorting']=$sortinglist;
  1068. }
  1069. if($this->interactive && $this->trackaccess) XLogs::uniqueUpdate('access',$oid);
  1070. return XShell::toScreen1($tplentry, $r);
  1071. }
  1072. // visualisation arborescente partielle
  1073. // -> = index2 mais sur le premier niveau et les dossier du path en cours seulement
  1074. //
  1075. public function &index2Light($ar){
  1076. $p=new XParam($ar,array('up'=>1,'down'=>1,'oid'=>'','maxlevel'=>2, 'showfiles'=>2, 'nosess'=>0));
  1077. $nosess=$p->get('nosess');
  1078. if(empty($nosess)) $this->_setSession('docmode','index2');
  1079. $oid=$p->get('oid');
  1080. if(empty($oid)){
  1081. $oid=$this->rootOid();
  1082. $_REQUEST['oid'] = $oid; // templates au moins index2 utilisent ceci
  1083. }
  1084. $tplentry=$p->get('tplentry');
  1085. $maxlevel=$p->get('maxlevel');
  1086. $actiontotest=$p->get('action');
  1087. if(!in_array($actiontotest, array('linkTo','display'))) $actiontotest='index';
  1088. $showfiles=$p->get('showfiles');
  1089. if($showfiles==1) $docstolist=2;
  1090. else $docstolist=1;
  1091. // Les fils directs de root
  1092. $rets = &$this->subObjects4($this->rootOid(), 1, false, 1, $docstolist);
  1093. // Creation du contexte
  1094. $path=&$this->mkContext($oid);
  1095. $oidcurrent=NULL;
  1096. // Construction des noeuds du chemin
  1097. foreach($path[0] as $i=>&$o2) {
  1098. $oidcurrent=$o2->oid;
  1099. if(($oidcurrent != $this->rootOid()) && !in_array($oidcurrent, $rets['1'])){
  1100. $prets = &$this->subObjects4($path[0][$i-1]->oid, 1, false, $i, 1);
  1101. $dx=array_search($path[0][$i-1]->oid, $rets['1']);
  1102. $rets['1'] = array_merge(array_slice($rets['1'], 0, $dx+1), $prets['1'], array_slice($rets['1'], $dx+1));
  1103. $rets['ors']=array_merge($rets['ors'],$prets['ors']);
  1104. }
  1105. }
  1106. // Recupere les dossiers
  1107. foreach($rets['1'] as $i=>&$myoid) {
  1108. $ors=&$rets['ors'][$myoid];
  1109. if(isset($ors)) {
  1110. $rets['docs'][$i]=&XDocumentDT::objectFactory($myoid, $this);
  1111. $rets['docs'][$i]->getContent();
  1112. // nolinkto est utilisé pour cacher certains dossier pour la fonction de copie, lien...
  1113. // il n'est donc pas necessaire de la calculer si on doit retourner aussi les docs car on ne sera pas dans ce cas
  1114. if($docstolist==1) $rets['ors'][$myoid]['noLinkTo']=($this->secure1($myoid, 'edit', $ors['node'])?0:1);
  1115. }
  1116. }
  1117. // Recupere les documents
  1118. if($docstolist==2){
  1119. foreach($rets['2'] as $j=>&$myoid) {
  1120. $ors=&$rets['ors'][$myoid];
  1121. if(isset($ors)) {
  1122. $rets['docs'][$i+1+$j]=&XDocumentDT::objectFactory($myoid, $this);
  1123. $rets['docs'][$i+1+$j]->getContent();
  1124. }
  1125. }
  1126. }
  1127. $order=array();
  1128. $prev=0;
  1129. $prevlabels=array();
  1130. foreach($rets['1'] as $i=>$oid) {
  1131. $o1=&$rets['ors'][$oid];
  1132. $cur=$o1['level'];
  1133. $prevlabels[$cur]=$rets['docs'][$i]->title;
  1134. if($cur<$prev) {
  1135. foreach($prevlabels as $j=>$v) {
  1136. if($j>$cur) unset($prevlabels[$j]);
  1137. }
  1138. }
  1139. $order[$i]=$prevlabels;
  1140. $prev=$o1['level'];
  1141. }
  1142. $orderstring=array();
  1143. foreach($order as $i=>&$o) {
  1144. // en cas d'egalite il faut un discriminant pour que multisort n'aille pas dans le tableau des docs ?
  1145. $orderstring[$i]=implode('>',$o).$i;
  1146. }
  1147. array_multisort($orderstring, SORT_ASC, $rets['docs']);
  1148. $sors=$rets['ors'];
  1149. $rets['ors']=array();
  1150. foreach($rets['docs'] as $i=>&$o) {
  1151. $rets['ors'][$i]=$sors[$o->oid];
  1152. }
  1153. unset($sors);
  1154. $orderstring=array_values($orderstring);
  1155. $oidcurrent=NULL;
  1156. foreach($path[0] as $i=>&$ob) {
  1157. $oidcurrent=$ob->oid;
  1158. foreach($rets['docs'] as $oid=>&$doc) {
  1159. if($ob->oid==$doc->oid) {
  1160. $foo = 'current find';
  1161. $doc->current=true;
  1162. }
  1163. }
  1164. }
  1165. $rets['docs']=array_values($rets['docs']);
  1166. $rets['ors']=array_values($rets['ors']);
  1167. $rets['path']=&$path;
  1168. $rets['oidcurrent']=$oidcurrent;
  1169. if($this->interactive && $this->trackaccess) XLogs::uniqueUpdate('access',$oid);
  1170. return XShell::toScreen1($tplentry, $rets);
  1171. }
  1172. // visualisation arborescente des repertoires
  1173. //
  1174. function &index2($ar=NULL) {
  1175. $p=new XParam($ar,array('up'=>1,'down'=>1,'oid'=>'','maxlevel'=>2, 'showfiles'=>2, 'nosess'=>0));
  1176. $tpl=$p->get('tplentry');
  1177. // Affichage en arbo, on change de fonction
  1178. if($tpl!=TZR_RETURN_DATA && XShell::getTemplate()=='xmoddocmgt/index3.html'){
  1179. XLogs::notice('XModdocMgt::index2', ' index3 required : call to index2Light');
  1180. return $this->index2Light($ar);
  1181. }
  1182. $nosess=$p->get('nosess');
  1183. if(empty($nosess)) $this->_setSession('docmode','index2');
  1184. $oid=$p->get('oid');
  1185. if(empty($oid)){
  1186. $oid=$this->rootOid();
  1187. $_REQUEST['oid']=$oid;
  1188. }
  1189. $tplentry=$p->get('tplentry');
  1190. $maxlevel=$p->get('maxlevel');
  1191. $actiontotest=$p->get('action');
  1192. $move=$p->get('_move');
  1193. $_selected=$p->get('_selected');
  1194. $except=!empty($move) && empty($_selected) ? array($oid):array();
  1195. if(!in_array($actiontotest, array('linkTo','display'))) $actiontotest='display';
  1196. $showfiles=$p->get('showfiles');
  1197. if($showfiles==1)
  1198. $docstolist=array(1,2);
  1199. else
  1200. $docstolist=array(1);
  1201. $rets=&$this->subObjects2($this->rootOid(),$docstolist,100,true,$actiontotest,$except);
  1202. $todel_level=NULL;
  1203. $cnt=count($rets['ors']);
  1204. $lvlprev=0;
  1205. foreach($rets['ors'] as $i=>&$o){
  1206. $rets['docs'][$i]=&XDocumentDT::objectFactory($o['KOIDSRC'], $this);
  1207. $rets['docs'][$i]->getContent();
  1208. }
  1209. $order=array();
  1210. $prev=0;
  1211. $prevlabels=array();
  1212. foreach($rets['ors'] as $i=>&$o) {
  1213. $cur=$o['level'];
  1214. $prevlabels[$cur]=$rets['docs'][$i]->title;
  1215. if($cur<$prev) {
  1216. foreach($prevlabels as $j=>$v) {
  1217. if($j>$cur) unset($prevlabels[$j]);
  1218. }
  1219. }
  1220. $order[$i]=$prevlabels;
  1221. $prev=$o['level'];
  1222. }
  1223. $orderstring=array();
  1224. foreach($order as $i=>&$o) {
  1225. $orderstring[$i]=implode('>',$o).$i;
  1226. // en cas d'egalite il faut un discriminant pour que multisort n'aille pas dans le tableau des docs ?
  1227. }
  1228. $docs=&$rets['docs'];
  1229. $ors=&$rets['ors'];
  1230. array_multisort($orderstring, SORT_ASC, $docs, $ors);
  1231. $path=&$this->mkContext($oid);
  1232. $oidcurrent=NULL;
  1233. foreach($path[0] as $i=>&$ob) {
  1234. $oidcurrent=$ob->oid;
  1235. foreach($rets['docs'] as $j=>&$doc) {
  1236. if($ob->oid==$doc->oid) {
  1237. $doc->current=true;
  1238. }
  1239. }
  1240. }
  1241. $rets['path']=&$path;
  1242. $rets['oidcurrent']=$oidcurrent;
  1243. if($this->interactive && $this->trackaccess) XLogs::uniqueUpdate('access',$oid);
  1244. return XShell::toScreen1($tplentry, $rets);
  1245. }
  1246. /// Retourne la liste des dossiers fils d'un dossier
  1247. function &viewDirFolders($ar=NULL) {
  1248. $p=new XParam($ar,array('up'=>1,'down'=>1,'oid'=>'','maxlevel'=>2, 'showfiles'=>1));
  1249. $oid=$p->get('oid');
  1250. $tplentry=$p->get('tplentry');

Large files files are truncated, but you can click here to view the full file