/class.xmoddocmgt.inc
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
- <?php
- /// Classe de base d'un document integre dans la base documentaire (xmoddocmgt)
- class XDocumentDT {
- public $title;
- public $comment;
- public $countdocs=0;
- public $countdirs=0;
- public $node=false;
- public $tpl;
- public $fields;
- public $insearchengine=true;
- protected $symbol='';
- static $rep_rep=array();
- static function &objectFactory($oid, &$docmgt, $ors=NULL, $ar=NULL) {
- if(isset($docmgt->doccache[$oid])) return $docmgt->doccache[$oid];
- $doc=array();
- if(empty($ors)) {
- $rs=selectQuery('SELECT * FROM '.$docmgt->id.',_TYPES WHERE '.$docmgt->id.'.KOID="'.$oid.'" AND '.
- '_TYPES.KOID=DTYPE');
- $ors=$rs->fetch();
- if(empty($ors)) return $doc;
- else $rs->closeCursor();
- }
- $docclass=strtolower($ors['docclas'].'DT');
- if(!empty($ors['docclas'])) {
- include_once('class.'.$docclass.'.inc');
- if(!class_exists($docclass)) {
- if($ors['node']==1) $docclass='XDirectoryDT';
- else $docclass='XDocumentDT';
- }
- } else {
- if($ors['node']==1) $docclass='XDirectoryDT';
- else $docclass='XDocumentDT';
- }
- $docmgt->doccache[$oid]=new $docclass($oid, $ors, $docmgt, $ar);
- // Si l'objet n'a pas été correctement initialisé, on le déclare vide
- if (empty($docmgt->doccache[$oid]->fields)) $docmgt->doccache[$oid] = '';
- return $docmgt->doccache[$oid];
- }
- static function &repositoryFactory($typeraw=NULL, $typedisp=NULL) {
- if(!empty($typeraw)) {
- $module=$typeraw['modidd'];
- $tab=$typeraw['dtab'];
- } else {
- $module=$typedisp['omodidd']->raw;
- $tab=$typedisp['odtab']->raw;
- }
- if(!empty($tab)) {
- if(empty(self::$rep_rep[$tab])) {
- self::$rep_rep[$tab]=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$tab);
- }
- $mod=&self::$rep_rep[$tab];
- } else {
- if(empty(self::$rep_rep[$module])) {
- self::$rep_rep[$module]=XModule::objectFactory($module);
- }
- $mod=&self::$rep_rep[$module];
- }
- return $mod;
- }
- function __construct($oid, &$ors, &$docmgt, $ar=NULL) {
- $mod=&XDocumentDT::repositoryFactory($ors);
- if(is_object($mod)) {
- $dar=array('oid'=>$oid,'_lastupdate'=>false,'_options'=>array('local'=>1,'error'=>'return'),'fmoid'=>$docmgt->_moid,'tplentry'=>TZR_RETURN_DATA);
- if ($ar) $dar=array_merge($dar,$ar);
- $result=&$mod->XMCdisplay($dar,false);
- // 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)
- if (!is_array($result)) return $result;
- $this->fields=&$result;
- $this->oid=$oid;
- $this->repository=&$mod;
- $this->module=&$docmgt;
- $this->tpl=&$docmgt->getTypes($ors['DTYPE']);
- $lines = explode("\n", stripslashes($this->tpl['oopts']->toText()));
- $this->tploptions=array();
- foreach($lines as &$line) {
- @list($var,$val)=explode('=',$line);
- if(!empty($var) && !empty($val)) {
- $var=trim($var);$val=trim($val);
- $this->tploptions[$var]=$val;
- }
- }
- $this->options=unserialize(stripslashes($ors['DPARAM']));
- $this->icon=&$this->tpl['oicon'];
- if(isset($this->tpl['osmallic']) && $this->tpl['osmallic']->raw!=''){
- $this->smallicon=&$this->tpl['osmallic']->html;
- $this->smalliconurl=&$this->tpl['osmallic']->url;
- }else{
- $this->smallicon=XLabels::getSysLabel('xmoddocmgt','defaultsdoc');
- $this->smalliconurl=TZR_SHARE_URL.'ico/'.XLabels::getSysLabel('xmoddocmgt','defaultsdoc_ico');
- }
- $this->title = $this->getTitle();
- $this->docs=$this->getFiles();
- $this->short=$this->title;
- $this->symbol = $ors['symbol'];
- $this->node=false;
- }
- }
- function saveOptions() {
- $dparam=addslashes(serialize($this->options));
- preparedUpdateQuery('UPDATE '.$this->module->id." SET DPARAM=? WHERE KOID=?",array($dparam,$this->oid));
- }
- function setOption($option, &$value) {
- $this->options[$option]=$value;
- }
- function &getOption($option) {
- if($this->options[$option]) return $this->options[$option];
- else return $this->tploptions[$option];
- }
- function getDocumentsDetails($oids=NULL) {
- }
- function getDirectoriesDetails($level=1) {
- }
- function getParents($level=1) {
- $this->parents=array();
- $this->parentsoid=array();
- if($this->oid==$this->module->rootOid()) return;
- $set=$this->module->father($this->oid);
- foreach($set as &$ors) {
- $oiddst=$ors['KOIDDST'];
- if(!empty($oiddst) && !in_array($oiddst,$this->parentsoid)) {
- if($this->module->secure1($oiddst,'index',$ors['node'])) {
- $d1=&XDocumentDT::objectFactory($oiddst,$this->module,$ors);
- if($level>1) $d1->getParents($level-1);
- $this->parents[]=&$d1;
- $this->parentsoid[]=$oiddst;
- }
- }
- }
- }
- // recherche de tous les chemins possibles qui sont stockés dans $this->paths
- //
- function getAllPaths() {
- $this->paths=array();
- $this->_getAllPaths1($this->paths, array($this->oid));
- foreach($this->paths as $i=>&$path) {
- $path=array_reverse($path);
- foreach($path as $j=>&$oidi) {
- $path[$j]=&XDocumentDT::objectFactory($oidi, $this->module);
- if($path[$j]->node!=1) unset($path[$j]);
- }
- }
- }
- private function _getAllPaths1(&$global, $currentpath) {
- if(empty($this->parents)) {
- if(!empty($currentpath)) {
- $global[]=$currentpath;
- }
- } else {
- foreach($this->parents as $i => &$p) {
- if(!in_array($p->oid, $currentpath)) {
- $copy=$currentpath;
- $copy[]=$this->parents[$i]->oid;
- $p->_getAllPaths1($global, $copy);
- }
- }
- }
- }
- function getContent($final=true,$update=true) {
- $oids=$this->module->subObjects4($this->oid, 1, false);
- if(!empty($this->oid)) {
- $this->docsoids = array_values($oids['2']);
- $this->countdocs = count($this->docsoids);
- }
- $this->dirsoids = array_values($oids['1']);
- $this->countdirs = count($this->dirsoids);
- }
- function getTitle() {
- return strip_tags($this->fields['link']);
- }
- /// rend le texte associe au document
- function getDescription() {
- return (!empty($this->fields['oremark'])?$this->fields['oremark']->html:'');
- }
- /// Retourne au format html la liste des fichiers du document
- function getFiles() {
- $this->countfiles=0;
- $txt='';
- foreach($this->fields['fields_object'] as $i=>&$v) {
- if(!empty($v->html)){
- if($v->fielddef instanceof XFileDef) {
- $txt.='<div class="tzr-xdirdef-dir"><div>'.$v->html.'</div></div> ';
- $this->countfiles++;
- }elseif($v->fielddef instanceof XFolderDef) {
- $txt.=$v->html.' ';
- if(isset($v->catalog)) $this->countfiles+=count($v->catalog);
- }
- }
- }
- return $txt;
- }
- /// rend liste des fichiers d'un document
- function getFilesDetails() {
- return getFilesDetails($this->fields);
- }
- /// liste les actions possible sur un document
- function &getActions() {
- static $m1=array('ro','rw','unlock');
- static $m2=array('ro');
- static $m3=array('ro','rw');
- static $m4=array();
- static $m5=array('ro','rw','lock');
- if($this->module->secure1($this->oid, 'edit',($this->node?"1":"2"))) {
- if(!empty($GLOBALS['XLOCK'])) {
- if(!empty($this->fields['_lock'])) {
- if(!empty($this->fields['_lock_editable'])) {
- $this->actions=&$m1;
- } else {
- $this->actions=&$m2;
- }
- } else $this->actions=&$m5;
- } elseif($this->tpl['omodid']->raw!=$this->module->_moid) {
- // si c'est un document partage et qu'on n'est pas dans son module d'origine
- $this->actions=&$m2;
- } else {
- $this->actions=&$m3;
- }
- } elseif($this->module->secure1($this->oid, 'display',($this->node?"1":"2"))) {
- $this->actions=&$m2;
- } else {
- $this->actions=&$m4;
- }
- }
- function del() {
- $mod = &XDocumentDT::repositoryFactory(NULL,$this->tpl);
- $mod->XMCdel(array('oid'=>$this->oid,'tplentry'=>TZR_RETURN_DATA));
- }
- function journal() {
- $mod = &XDocumentDT::repositoryFactory(NULL,$this->tpl);
- if(method_exists($mod,'journal')) {
- return $mod->journal(array('oid'=>$this->oid,'tplentry'=>TZR_RETURN_DATA));
- } else return NULL;
- }
- /// Ajout d'un document au moteur de recherche
- function addToSearchEngine(&$searchEngine) {
- $fields = $this->getSearchEngineData();
- $searchEngine->addItem($this->oid,$fields,$this->module->_moid,NULL);
- XLogs::notice(get_class($this),get_class($this).'::addToSearchEngine lucene');
- }
- function &getSearchEngineData(){
- $fields = array('notice'=>'', 'contents'=>'', 'title'=>'');
- $fields['contents']=getFilesContent($this->fields);
- $fields['title'] = $this->title;
- $fields['notice'] = $this->getSearchEngineNotice();
- return $fields;
- }
- function &getSearchEngineNotice(){
- $notice = '';
- // les champs !publiés et non fichiers dans la notice
- foreach($this->fields['fields_object'] as $i=>&$v) {
- $field = $v->fielddef;
- if ($field->indexable
- && (!$field->get_published()
- && !($field instanceof XFileDef)
- && !($field instanceof XFolderDef))){
- $notice .= ' '.$v->toText();
- }
- }
- // ajout des noms des champs fichiers
- $indexables = $this->getIndexablesFields();
- $files = getFilesDetails($this->fields);
- foreach($files as $afile){
- if (in_array($afile['field'], $indexables)){
- $notice .= ' '.$afile['title'];
- if ($afile['name'] != $afile['title'])
- $notice .= ' '.$afile['name'];
- }
- }
- return $notice;
- }
- /// rend la liste des champs indexables
- function getIndexablesFields(){
- $list = array();
- foreach($this->fields['fields_object'] as $i=>&$v) {
- if ($v->fielddef->indexable)
- $list[] = $v->fielddef->field;
- }
- return $list;
- }
- }
- /// Classe de base d'un document container (repertoire/dossier) integre dans la base documentaire (xmoddocmgt)
- class XDirectoryDT extends XDocumentDT {
- function __construct($oid, &$ors, &$docmgt, $ar=NULL) {
- parent::__construct($oid, $ors, $docmgt, $ar);
- $this->node=true;
- $this->comment=$this->getDescription();
- if(empty($this->icon->html)) {
- $this->icon->url=XLabels::getSysLabel('xmoddocmgt','directorybig','url');
- }
- if(isset($this->tpl['osmallic']->raw) && $this->tpl['osmallic']->raw!=''){
- $this->smallicon=&$this->tpl['osmallic']->html;
- $this->smalliconurl=&$this->tpl['osmallic']->url;
- }else{
- $this->smallicon=XLabels::getSysLabel('xmoddocmgt','defaultsdir');
- $this->smalliconurl=TZR_SHARE_URL.'ico/'.XLabels::getSysLabel('xmoddocmgt','defaultsdir_ico');
- }
- }
- /// la gestion des types possibles peut etre modifiee avec allowedChildType
- function getNewTypes($docs=false, $dirs=false) {
- if ($docs || $dirs){
- $phrase = '';
- $exp = $this->tpl['ocrules']->raw;
- $l = preg_split('/$/m', $exp);
- $convs = array(); /* tableau des associations antre symboles et lettres simples */
- $exps = array(); /* tableau des expressions a verifier */
- foreach($l as $foo=>$c){
- $c = trim($c);
- if (empty($c)) continue;
- /* si la chaine commence par un : c'est une affectation */
- $f = strpos($c, ':');
- if ($f !== false && $f == 0) {
- $c1 = substr($c, 1);
- list($symbol, $letter) = explode('=', $c1);
- $convs[$symbol] = $letter;
- } else {
- $exps[] = $c;
- }
- }
- $childsTypes = array(); /* tableau des types de descendants */
- foreach($this->documents as $oiddoc=>&$cdoc){
- $s = $cdoc->tpl['osymbol']->raw;
- if (isset($convs[$s])) $s = $convs[$s];
- $childsTypes[] = $s;
- }
- foreach($this->directories as $oiddoc=>&$cdoc){
- $s = $cdoc->tpl['osymbol']->raw;
- if (isset($convs[$s])) $s = $convs[$s];
- $childsTypes[] = $s;
- }
- }
- $exp = '';
- foreach($exps as $foo=>$e){
- if($exp != '') $exp .= '|'.$e;
- else $exp.=$e;
- }
- if(empty($exp)) $exp=".*";
- if($docs) {
- $typesname=array();
- $dtypes=$this->module->getTypes();
- foreach($dtypes as $i=>&$tpl) {
- $childsTypes2 = $childsTypes;
- $s = $tpl['osymbol']->raw;
- if (isset($convs[$s])) $s = $convs[$s];
- else $s='x';
- $childsTypes2[] = $s;
- sort($childsTypes2);
- $phrase2 = implode($childsTypes2, '');
- if($tpl['onode']->raw==2 && preg_match('/^('.$exp.')$/', $phrase2) && $this->allowedChildType($tpl, $childs) && $tpl['_rwsecure']) {
- $this->newdocs[$i]=&$tpl;
- $typesname[$i]=$tpl['otitle']->raw;
- }
- }
- array_multisort($typesname,$this->newdocs);
- }
- if($dirs) {
- $typesname=array();
- $oidtoprotect=$this->module->protectedOids();
- $dtypes=&$this->module->getTypes();
- foreach($dtypes as $i=>&$tpl) {
- if(!in_array($tpl['oid'], $oidtoprotect)) {
- $childsTypes2 = $childsTypes;
- $s = $tpl['osymbol']->raw;
- if (isset($convs[$s])) $s = $convs[$s];
- else $s='x';
- $childsTypes2[] = $s;
- sort($childsTypes2);
- $phrase2 = implode($childsTypes2, '');
- if($tpl['onode']->raw==1 && preg_match('/^('.$exp.')$/i', $phrase2) && $this->allowedChildType($tpl, $childs) && $tpl['_rwsecure']) {
- $this->newdirs[$i]=&$tpl;
- $typesname[$i]=$tpl['otitle']->raw;
- }
- }
- }
- array_multisort($typesname,$this->newdirs);
- }
- }
- /// types possibles pour un dossier des modeles
- function getNewTypesM($docs=false, $dirs=false) {
- $dtypes=&$this->module->getTypes();
- if($docs) {
- foreach($dtypes as $i=>&$tpl) {
- if($tpl['onode']->raw==2 && $tpl['_rwsecure']) {
- $this->newdocs[$i]=&$tpl;
- }
- }
- }
- if($dirs) {
- foreach($dtypes as $i=>&$tpl) {
- if($tpl['onode']->raw==1 && $tpl['_rwsecure']) {
- $this->newdirs[$i]=&$tpl;
- }
- }
- }
- }
- /// controle sur les regles du type : ne doit pas pouvoir etre surchargee
- private function _allowedChildType($csymbol, $phrase){
- return true;
- }
- protected function allowedChildType($csymbol) {
- return true;
- }
- function getDocumentsDetails() {
- if(!empty($this->documents)) return;
- if(empty($this->docsoids)) return;
- $order=$this->getOption('fileorder');
- list($order,$direction)=explode(' ',$order);
- // recherche des documents qui sont dans ce repertoire
- foreach($this->docsoids as $oid) {
- if(empty($set)) $set="'".$oid."'";
- else $set.=",'".$oid."'";
- }
- $rs=selectQuery('SELECT * FROM '.$this->module->idx.','.$this->module->id.',_TYPES where KOIDSRC in ('.$set.') '.
- ' and KOIDSRC='.$this->module->id.'.KOID and node=2 and '.$this->module->id.'.DTYPE=_TYPES.KOID/*2*/');
- if($rs) {
- $this->documents=array();
- $documents=array();
- $tmporder=array(); /* tableau temporaire construit pour le tri */
- $tmporder2=array(); /* tableau temporaire construit pour le tri */
- while($ors=$rs->fetch()) {
- if(!empty($ors['KOIDSRC'])) {
- // voir si document sur xdatasource et pas module -> false toujours ?
- $seenhere=in_array($ors['KOIDSRC'], $this->docsoids);
- if(!$seenhere) continue;
- $doc1 = &XDocumentDT::objectFactory($ors['KOIDSRC'], $this->module, $ors);
- // Si l'objet n'est pas accessible (dépublié par exemple)
- if (!is_object($doc1)) continue;
- $doc1->getActions();
- $documents[$ors['KOIDSRC']]=$doc1;
- $this->documents[$ors['KOIDSRC']]=NULL;
- if(isset($documents[$ors['KOIDSRC']]->fields['o'.$order])) {
- $tmporder[$ors['KOIDSRC']]=$documents[$ors['KOIDSRC']]->fields['o'.$order]->raw;
- } elseif($order=='doctype') {
- $tmporder[$ors['KOIDSRC']]=$documents[$ors['KOIDSRC']]->tpl['osymbol']->raw;
- } else {
- $tmporder[$ors['KOIDSRC']]=$documents[$ors['KOIDSRC']]->title;
- }
- $tmporder2[$ors['KOIDSRC']]=$documents[$ors['KOIDSRC']]->title;
- }
- }
- }
- if($direction=='DESC') array_multisort($tmporder, SORT_DESC, $tmporder2, $this->documents);
- else array_multisort($tmporder, SORT_ASC, $tmporder2, $this->documents);
- foreach($this->documents as $key=>&$val)
- $val=$documents[$key];
- }
- function getDirectoriesDetails($level=1) {
- if(!empty($this->directories)) return;
- if(empty($this->dirsoids)) return;
- $order=$this->getOption('directoryorder');
- list($order,$direction)=explode(' ',$order);
- // recherche des documents qui sont dans ce repertoire
- foreach($this->dirsoids as $oid) {
- if(empty($set)) $set="'".$oid."'";
- else $set.=",'".$oid."'";
- }
- $rs=selectQuery('SELECT * FROM '.$this->module->idx.','.$this->module->id.',_TYPES where KOIDSRC in ('.$set.') '.
- ' and KOIDSRC='.$this->module->id.'.KOID and '.$this->module->id.'.DTYPE=_TYPES.KOID/*1*/');
- if($rs) {
- $this->directories=array(); /* tableau des documents tries */
- $directories=array(); /* tableau des documents non tries */
- $tmporder=array(); /* tableau temporaire construit pour le tri */
- $tmporder2=array(); /* tableau temporaire construit pour le tri */
- while($ors=$rs->fetch()) {
- if(!empty($ors['KOIDSRC'])) {
- if(!$this->module->secure1($ors['KOIDSRC'], 'index',$ors['node'])) continue;
- $doc1 = &XDocumentDT::objectFactory($ors['KOIDSRC'], $this->module, $ors);
- $doc1->parents[]=&$this;
- $doc1->parentsoids[]=$this->oid;
- $this->directories[$ors['KOIDSRC']]=NULL;
- $directories[$ors['KOIDSRC']]=$doc1;
- $directories[$ors['KOIDSRC']]->getContent();
- if($level>0) {
- $directories[$ors['KOIDSRC']]->getDirectoriesDetails($level-1);
- }
- if(isset($directories[$ors['KOIDSRC']]->fields['o'.$order])) {
- $tmporder[$ors['KOIDSRC']]=$directories[$ors['KOIDSRC']]->fields['o'.$order]->raw;
- } elseif($order=='doctype') {
- $tmporder[$ors['KOIDSRC']]=$directories[$ors['KOIDSRC']]->tpl['osymbol']->raw;
- } else {
- $tmporder[$ors['KOIDSRC']]=$directories[$ors['KOIDSRC']]->title;
- }
- $tmporder2[$ors['KOIDSRC']]=$directories[$ors['KOIDSRC']]->title;
- }
- }
- if($direction=='DESC') array_multisort($tmporder, SORT_DESC, $tmporder2, $this->directories);
- else array_multisort($tmporder, SORT_ASC, $tmporder2, $this->directories);
- foreach($this->directories as $key=>&$val)
- $val=$directories[$key];
- }
- $rs->closeCursor();
- }
- // notice du repertoire pour moteur de recherche
- // le reste = document (si fichiers ils sont pris)
- function getSearchEngineNotice(){
- $notice = parent::getSearchEngineNotice();
- if (isset($this->fields['oremark']) && is_object($this->fields['oremark']) && (!$this->fields['oremark']->fielddef->indexable)){
- $notice = $this->fields['oremark']->text.' '.$notice;
- }
- return $notice;
- }
- // ajout d'un descendant
- //
- function addChild($oid) {
- $q="SELECT COUNT(*) FROM {$this->module->idx} WHERE KOIDSRC='$oid' AND KOIDDST='{$this->oid}'";
- $rs=selectQuery($q);
- $ors=$rs->fetch();
- if($ors['COUNT(*)']<=0) {
- $q='INSERT INTO '.$this->module->idx.' SET KOIDSRC="'.$oid.'", KOIDDST="'.$this->oid.'"';
- updateQuery($q);
- }
- }
- }
- /// Module de gestion d'une base documentaire
- class XModDocMgt extends XModule {
- public $prefix='DM';
- // suffixe de l'oid du dosssier qui contient les modeles
- var $patternSuffix = 'TEMPLATES';
- // table (xset) de description par defaut des dossiers
- public $defaultFolderTable = 'REP1';
- var $doccache=array();
- var $documentssec=true;
- public $trackchanges=true;
- public $trackaccess=false;
- public $searchtemplate='xmoddocmgt/searchResult.html';
- var $_s=array();
- function __construct($ar=NULL) {
- parent::__construct($ar);
- $this->idx = $this->prefix.'IDX';
- $this->id = $this->prefix.'ID';
- $this->lang = XShell::getLangData();
- $this->_f=array();
- $this->opts=XOpts::getOpt(XUser::get_current_user_uid(), $this->_moid, 'opts');
- XLabels::loadLabels('xmoddocmgt');
- }
- /// Liste des tables utilisées par le module
- public function usedTables(){
- $ret=$this->usedMainTables();
- $ret[]=$this->idx;
- $ret[]=$this->id;
- return $ret;
- }
- public function usedMainTables() {
- $rs=&selectQuery('select modidd,dtab from _TYPES where modid="'.$this->_moid.'"');
- $ret=array();
- while($ors=$rs->fetch()){
- if(!empty($ors['dtab'])) $ret[]=$ors['dtab'];
- else{
- $mod=XModule::objectFactory($ors['modidd']);
- if(is_object($mod)){
- $t=$mod->usedTables();
- if($t) $ret=array_merge($ret,$t);
- }
- }
- }
- return $ret;
- }
- /// rend la liste des types de doc ou le type de doc d'oid $oid
- public function &getTypes($oid=NULL) {
- $foooid=NULL;
- if(empty($this->doctypes) || empty($this->doctypes[$oid])) {
- // recherche des types de document
- $mods=array_keys(XModule::modulesUsingTable('_TYPES',false,false,false));
- $moid=$mods[0];
- $mod=XModule::objectFactory($moid);
- $oids=$mod->xset->browseOids(array('_filter'=>'(modid="'.$this->_moid.'" OR KOID="'.$oid.'")','_options'=>array('local'=>true)));
- if($mod->object_sec) $oidsrights=$GLOBALS['XUSER']->getObjectsAccess($mod,XShell::getLangData(),$oids);
- foreach($oids as $i=>$toid){
- $foo1=$mod->xset->rDisplay($toid);
- if(!$mod->object_sec || array_key_exists('ro',$oidsrights[$i])) $foo1['_rwsecure']=true;
- if($foo1['omodid']->raw==$this->_moid) {
- $this->doctypes[$toid]=$foo1;
- } else {
- $foo1['otitle']->html.=' / '.XLabels::getSysLabel('xmoddocmgt.source').' '.$foo1['omodid']->html;
- }
- if($foo1['oid']==$oid) $foooid=$foo1;
- }
- }
- if(empty($oid)) return $this->doctypes;
- elseif(!empty($foooid)) return $foooid;
- else return $this->doctypes[$oid];
- }
- function protectedOids() {
- $oidtoprotect=array('_TYPES:root-'.$this->_moid,
- '_TYPES:lostandfound-'.$this->_moid,
- '_TYPES:trash-'.$this->_moid,
- '_TYPES:archive-'.$this->_moid);
- return $oidtoprotect;
- }
- /// Suppression du module
- function delete($ar=NULL) {
- parent::delete($ar);
- // Suppression des types de docs du module
- updateQuery('delete from _TYPES where modid="'.$this->_moid.'"');
- }
- /// Initialisation des propriétés
- public function initOptions() {
- parent::initOptions();
- $slabel=XLabels::getSysLabel('general','security','text');
- $this->_options->setOpt('Gerer la securite sur les documents', 'documentssec', 'boolean', NULL, true, $slabel);
- $tlabel=XLabels::getSysLabel('xmodule.tracking');
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','trackaccess'),'trackaccess','boolean',NULL,NULL,$tlabel);
- $this->_options->setOpt('Préfixe','prefix','text');
- $this->_options->setOpt('Table par défaut des repertoires','defaultFolderTable','table');
- }
- /// securite des fonctions accessibles par le web
- function secGroups($function, $group=NULL) {
- $g=array();
- $g['index']=array('list','ro','rw','rwv','admin');
- $g['index2']=array('list','ro','rw','rwv','admin');
- $g['index2Light']=array('list','ro','rw','rwv','admin');
- $g['viewDir']=array('list', 'ro','rw','rwv','admin');
- $g['ajaxLoadDir']=array('list','ro','rw','rwv','admin');
- $g['ajaxLoadDirTree']=array('list','ro','rw','rwv','admin');
- $g['input']=array('rw','rwv','admin');
- $g['procInput']=array('rw','rwv','admin');
- $g['journal']=array('ro','rw','rwv','admin');
- $g['edit']=array('rw','rwv','admin');
- $g['display']=array('ro','rw','rwv','admin');
- $g['procEdit']=array('rw','rwv','admin');
- $g['del']=array('rw','rwv','admin');
- $g['search']=array('list','ro','rw','rwv','admin');
- $g['advsearch']=array('list','ro','rw','rwv','admin');
- $g['linkTo']=array('list', 'ro', 'rw','rwv','admin');
- $g['getLast']=array('list','ro','rw','rwv','admin');
- $g['getUnread']=array('list','ro','rw','rwv','admin');
- $g['markAsRead']=array('list','ro','rw','rwv','admin');
- $g['subscribe']=array('ro','rw','rwv','admin');
- $g['preSubscribe']=array('ro','rw','rwv','admin');
- $g['admin']=array('admin');
- $g['documentsDownload']=array('ro','rw','rwv','admin');
- $g['export']=array('ro','rw','rwv','admin');
- $g['exportFTP']=array('ro','rw','rwv','admin');
- $g['exportBatch']=array('ro','rw','rwv','admin');
- $g['procSendACopyTo']=array('list', 'ro','rw','rwv','admin');
- $g['prePrintDisplay']=array('list','ro','rw','rwv','admin');
- $g['printDisplay']=array('ro','rw','rwv','admin');
- $g['share']=array('rw','rwv','admin');
- $g['procShare']=array('rw','rwv','admin');
- $g['setRootOid']=array('ro','rw','rwv','admin');
- $g['clearRootOid']=array('ro','rw','rwv','admin');
- if(isset($g[$function])) {
- if(!empty($group)) return in_array($group, $g[$function]);
- return $g[$function];
- }
- return parent::secGroups($function,$group);
- }
- /// Action principale du menu
- public function getMainAction(){
- return $GLOBALS['TZR_SESSION_MANAGER']::complete_self().'moid='.$this->_moid.'&_function=index&tplentry=br&template=xmoddocmgt/index2.html&maxlevel=2&'.
- 'clear=1&oid='.$this->rootOid();
- }
- /// Cette fonction est appliquee pour afficher l'ensemble des methodes de ce module
- protected function _actionlist(&$my=NULL) {
- parent::_actionlist($my);
- $myclass=get_class($this);
- $moid=$this->_moid;
- $uniqid='v'.XShell::uniqid();
- $dir='xmoddocmgt';
- $myoid = @$_REQUEST['oid'];
- $mypoid = @$_REQUEST['_parentoid'];
- if(empty($myoid)) $myoid=$this->rootOid();
- $ri=XUser::secure8maxlevel($this);
- if($ri=='admin'){
- $o1=new XModuleAction($this, 'exportfs', XLabels::getSysLabel('general','export','text'),
- '&moid='.$moid.
- '&_function=index&tplentry=br&'.
- 'template='.$dir.'/export.html&_parentoid='.$mypoid.'&oid='.$myoid);
- $o1->homepageable=false;
- $o1->menuable=true;
- $o1->quicklinkable=true;
- $o1->group='actions';
- $my['exportfs']=$o1;
- }
- $suid=getSessionVar('SUID');
- if(!empty($suid)) {
- if(!empty($this->opts['home'])) {
- $o1=new XModuleAction($this, 'clearrootoid', XLabels::getSysLabel('xmoddocmgt','clearrootoid','text'),
- '&moid='.$moid.'&_function=clearRootOid&tplentry=br&'.'template='.$dir.'/index2.html&maxlevel=2&clear=1',
- 'more');
- $o1->menuable=true;
- $my['setrootoid']=$o1;
- } elseif(!empty($myoid)) {
- $o1=new XModuleAction($this, 'setrootoid', XLabels::getSysLabel('xmoddocmgt','setrootoid','text'),
- '&moid='.$moid.'&_function=setRootOid&tplentry=br&'.'template='.$dir.'/index2.html&maxlevel=2&clear=1&'.
- '&oid='.$myoid,'more');
- $o1->menuable=true;
- $my['setrootoid']=$o1;
- }
- }
- $rw=$this->secure($myoid,'edit');
- $admin=$this->secure($myoid,'secEdit');
- if(XShell::_function()!='index2') {
- // Arbo a plat
- $o1=new XModuleAction($this, 'index1', XLabels::getSysLabel('xmoddocmgt','index','text'),
- '&moid='.$moid.'&_function=index&tplentry=br&'.'template='.$dir.'/index2.html&maxlevel=2&clear=1&'.
- '_parentoid='.$mypoid.'&oid='.$myoid,'display');
- $o1->setToolbar('general','browse');
- $o1->order=1;
- $my['index1']=$o1;
- // Arborescence
- $o1=new XModuleAction($this, 'index2', XLabels::getSysLabel('general','tree','text'),
- '&moid='.$moid.'&_function=index2&tplentry=br&template='.$dir.'/index3.html&maxlevel=10&'.
- '_parentoid='.$mypoid.'&oid='.$myoid,'display');
- $o1->setToolbar('general','tree');
- $o1->order=2;
- $my['index2']=$o1;
- // Recherche avancée
- if($this->secure('','advsearch')){
- $o1=new XModuleAction($this,'advsearch', XLabels::getSysLabel('xmoddocmgt','advsearch','text'),
- '&moid='.$moid.'&_function=advsearch&tplentry=br&template='.$dir.'/advsearch.html','display');
- $o1->setToolbar('xmoddocmgt','advsearch');
- $o1->order=3;
- $my['advsearch']=$o1;
- }
- if(!empty($myoid) && Kernel::isAKoid($myoid)) {
- $o1=new XModuleAction($this,'display',XLabels::getSysLabel('general', 'view','text'),
- '&moid='.$moid.'&_function=display&tplentry=br&'.'template='.$dir.'/display.html&oid='.$myoid,'edit');
- $o1->setToolbar('general','display');
- $o1->order=1;
- $my['display']=$o1;
- if($myoid!=$this->rootOid()) {
- if($rw){
- // Edition
- $o1=new XModuleAction($this,'edit',XLabels::getSysLabel('general','edit','text'),
- '&moid='.$moid.'&_function=edit&tplentry=br&template='.$dir.'/edit.html&_parentoid='.$mypoid.
- '&oid='.$myoid,'edit');
- $o1->setToolbar('general','edit');
- $o1->order=2;
- $my['edit']=$o1;
- // Réservation
- if(!empty($GLOBALS['XLOCK']) && !$GLOBALS['XLOCK']->locked($myoid,TZR_DEFAULT_LANG)) {
- if(!empty($myoid)) $dmyoid=&XDocumentDT::objectFactory($myoid, $this);
- if(is_object($dmyoid) && !($dmyoid instanceof XDirectoryDT)) {
- $o1=new XModuleAction($this,'lock', XLabels::getSysLabel('general','lock','text'),
- '&moid='.$moid.'&_function=edit&tplentry=br&_mode=lock&'.
- 'template='.$dir.'/edit.html&_parentoid='.$mypoid.'&oid='.$myoid,'edit');
- $o1->setToolbar('general','lock');
- $o1->order=3;
- $my['lock']=$o1;
- }
- }
- }
- // Droits
- if($admin) {
- $self=$GLOBALS['TZR_SESSION_MANAGER']::complete_self(true);
- $o1=new XModuleAction($this,'security',XLabels::getSysLabel('general','security','text'),
- 'javascript:TZR.editSec("'.$self.'","'.$moid.'","'.$myoid.'",'.$uniqid.');','edit');
- $o1->menuable=true;
- $o1->setToolbar('general','security');
- $my['security2']=$o1;
- }
- // Pour ces deux actions les droits dependent de la destination
- // Copier
- $o1=new XModuleAction($this,'linkTo',XLabels::getSysLabel('general','copy','text'),
- 'javascript:'.$uniqid.'.copyselected("'.$myoid.'");','edit');
- $o1->menuable=true;
- $my['copy']=$o1;
- // Liaison
- $o1=new XModuleAction($this,'linkTo',XLabels::getSysLabel('xmoddocmgt','link','text'),
- 'javascript:'.$uniqid.'.linkselected("'.$myoid.'");','edit');
- $o1->menuable=true;
- $my['link']=$o1;
- // Déplacement
- if($rw){
- $o1=new XModuleAction($this,'linkTo',XLabels::getSysLabel('general','move','text'),
- 'javascript:'.$uniqid.'.moveselected("'.$myoid.'");','edit');
- $o1->setToolbar('general','move');
- $my['move']=$o1;
- }
- }
- // Suppression
- if($this->secure($myoid,'del')){
- $o1=new XModuleAction($this,'del',XLabels::getSysLabel('general', 'delete','text'),'javascript:'.$uniqid.'.deleteselected('.($myoid!=$this->rootOid()?'':'true').');',
- 'edit');
- $o1->setToolbar('general','delete');
- $o1->order=4;
- $my['delete']=$o1;
- }
- }
- }else{
- // Vue a plat du dossier en cours
- $o1=new XModuleAction($this, 'index1', XLabels::getSysLabel('xmoddocmgt','index','text'),'javascript:'.$uniqid.'.gotonode();');
- $o1->homepageable=$o1->menuable=true;
- $o1->quicklinkable=true;
- $o1->group='display';
- $o1->setToolbar('general','browse');
- $my['index1']=$o1;
- // Suppression
- if($this->secure($myoid,'del')){
- $o1=new XModuleAction($this,'del',XLabels::getSysLabel('general','delete','text'),'javascript:'.$uniqid.'.deleteselected();',
- 'edit');
- $o1->menuable=true;
- $o1->setToolbar('general','delete');
- $my['delete']=$o1;
- }
- }
- // Téléchargement
- $o1=new XModuleAction($this,'download',XLabels::getSysLabel('xmoddocmgt','downloadselected','text'),
- 'javascript:'.$uniqid.'.downloadselected();','edit');
- $o1->menuable=true;
- $my['download']=$o1;
- if(!empty($myoid) && Kernel::isAKoid($myoid)){
- // Abonnement
- $xmodsubmoid=XModule::getMoid(XMODSUB_TOID);
- if(!empty($xmodsubmoid) && $this->secure($myoid,'preSubscribe')){
- $o1=new XModuleAction($this,'subscribe',XLabels::getSysLabel('xmodsub', 'subscribe', 'text'),
- '&moid='.$this->_moid.'&oid='.$myoid.'&_function=preSubscribe&tplentry=br&template=xmoddocmgt/sub.html',
- 'more');
- $o1->menuable=true;
- $my['subscribe']=$o1;
- }
- if ($this->secure($myoid,'sendACopyTo')){
- // Avertir
- if(XShell::_function()=='display' || XShell::_function()=='edit'){
- $o1=new XModuleAction($this,'sendACopy',XLabels::getSysLabel('xmodule','sendacopyto','text'),
- '&moid='.$this->_moid.'&tplentry=br&oid='.$myoid.
- '&_function=sendACopyTo&template=xmodule/sendacopyto.html&tplentry=br','more');
- }else{
- $o1=new XModuleAction($this,'sendACopy',XLabels::getSysLabel('xmodule','sendacopyto','text'),
- 'javascript:TZR.applySelected("sendACopyTo",document.forms["browse'.XShell::uniqid().'"],"","xmodule/sendacopyto.html",'.
- '"br","'.addslashes(XLabels::getSysLabel('general','error_select_object','text')).'");','more');
- }
- $o1->menuable=true;
- $my['sendacopy']=$o1;
- }
- }
- // Voir les derniers documents
- $o1=new XModuleAction($this,'lastdoc',XLabels::getSysLabel('xmoddocmgt','lastdoc','text'),
- '&moid='.$this->_moid.'&_function=getLast&tplentry=br&template=xmoddocmgt/getlast.html','display');
- $o1->menuable=true;
- $my['lastdoc']=$o1;
- // Voir les documents non lus
- if($this->trackaccess && $this->secure('','getUnread')){
- $o1=new XModuleAction($this,'lastdoc',XLabels::getSysLabel('xmodule','unread','text'),
- '&moid='.$this->_moid.'&_function=getUnread&tplentry=br&template=xmoddocmgt/getUnread.html','display');
- $o1->menuable=true;
- $my['unread']=$o1;
- }
- // Création du contexte si en mode interactif
- if($this->interactive) $this->mkContext2($my, $myoid);
- }
- /// Menu spécifique au display
- function al_display(&$my){
- $this->getSSMAl($my);
- $br=XShell::from_screen('br');
- if(method_exists($br['here']->repository,'printDisplay') && $br['here']->repository->secure($oid,'printDisplay')){
- $o1=new XModuleAction($this,'print',XLabels::getSysLabel('general','print','text'),
- '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');
- $o1->setToolbar('general','print');
- $o1->order=3;
- $my['print']=$o1;
- }
- }
- function al_edit(&$my){
- $this->al_display($my);
- }
- /// duplication d'un module, méthode interne (retour : tables => liste des tables dupliquées par le module (cle : ancienne table, valeur : nouvelle table))
- function _duplicateModule($newmoid,&$params,$prefix) {
- if(!empty($params['tables']) && is_array($params['tables'])) $mods=$params['mods'];
- else $mods=array();
- if(!empty($params['tables']) && is_array($params['tables'])) $tables=$params['tables'];
- else $tables=array();
- // creation des tables dmid et dmidx
- $newprefix = XModDocMgtWd::newPrefix();
- updateQuery('CREATE TABLE '.$newprefix.'ID like '.$this->id);
- updateQuery('CREATE TABLE '.$newprefix.'IDX like '.$this->idx);
- XModDocMgtWd::createStructure($newprefix);
- $params['prefix']=$newprefix;
- $tables[$this->id]=$newprefix.'ID';
- $tables[$this->idx]=$newprefix.'IDX';
-
- // copie des donnees dans la structure
- updateQuery('INSERT INTO '.$newprefix.'ID select * from '.$this->id);
- updateQuery('INSERT INTO '.$newprefix.'IDX select * from '.$this->idx);
- // Duplication de toutes les tables de documents et des types de doc
- $moid=$this->_moid;
- $all=selectQueryGetAll('select KOID,dtab,modidd from _TYPES where modid="'.$this->_moid.'"');
- $dstype=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS=_TYPES');
- foreach($all as $data) {
- $tab=$ntab=NULL;
- $koid=$data['KOID'];
- if(empty($data['modidd']) && !empty($data['dtab'])) {
- // duplication du module dans le cas ou le doc est gere par une source de donnees
- // Etape 1 : duplication de la table
- $tab=$data['dtab'];
- if(empty($tables[$tab])){
- $ntab=$ar['newtable']=XDSTable::newTableNumber();
- $tables[$tab]=$ntab;
- $xset=XDataSource::objectFactoryHelper8('SPECS='.$data['dtab']);
- if(($pos=strpos($xset->getLabel(),':'))!==false) $ar['mtxt']=$prefix.substr($xset->getLabel(),$pos);
- else $ar['mtxt']=$prefix.':'.$xset->getLabel();
- $ar['data']=true;
- $ar['_options']=array('local'=>1);
- $xset2=$xset->procDuplicateDataSource($ar);
- }else{
- $ntab=$tables[$tab];
- }
- XLogs::debug('XModDocMgt::_duplicateModule: cloning table '.$tab.' to '.$ntab);
- // etape 2 :duplication de l'entree dans la liste des documents type
- $ardup=array('_options'=>array('local'=>1));
- $ardup['oid']=$koid;
- $nkoid=$dstype->duplicate($ardup);
- preparedUpdateQuery('UPDATE _TYPES set dtab=?,modid=? where KOID=?',array($ntab,$newmoid,$nkoid));
- } elseif(!empty($data['modidd'])) {
- // duplication de la table quand les doc sont gere par un un module
- if(empty($mods[$data['modidd']])){
- $module=XModule::objectFactory($data['modidd']);
- // etape 1 : duplication du module
- $ret=$module->duplicateModule(array('tables'=>$tables,'group'=>(!empty($params['group'])?$params['group']:$this->group)));
- $thenewmoid=$ret['moid'];
- $tables=$tables+$ret['duplicatetables'];
- $mods=$mods+$ret['duplicatemods'];
- }else{
- $thenewmoid=$mods[$data['modidd']];
- }
- // etape 2 : duplication de l'entree dans la liste des documents type
- $ardup=array('_options'=>array('local'=>1));
- $ardup['oid']=$koid;
- $nkoid=$dstype->duplicate($ardup);
- preparedUpdateQuery('UPDATE _TYPES set modidd=?,modid=? where KOID=?',array($thenewmoid,$newmoid,$nkoid));
- $newmodule=XModule::objectFactory($thenewmoid);
- $ntab=$newmodule->table;
- $tab=$module->table;
- XLogs::debug('XModDocMgt::_duplicateModule: cloning module '.$data['modidd'].' to '.$thenewmoid.' table '.$ntab);
- }
- // on renomme la racine
- if(preg_match('@_TYPES\:root-([0-9]+)@',$koid)) {
- $nnkoid='_TYPES:root-'.$newmoid;
- preparedUpdateQuery('UPDATE _TYPES set KOID=? where KOID=?',array($nnkoid,$nkoid));
- $nkoid=$nnkoid;
- // on renseigne la table des dossiers par defaut
- $rsroot=selectQuery('SELECT * FROM _TYPES WHERE KOID="'.$nkoid.'"');
- if($rsroot && $orsroot=$rsroot->fetch()) {
- if(!empty($orsroot['dtab'])) $params['defaultFolderTable']=$orsroot['dtab'];
- }
- }
- if(!empty($ntab) && !empty($tab)) {
- // on renomme les oids un peu partout
- updateQuery('update '.$newprefix."ID set UPD=UPD,KOID='$ntab:root-$newmoid' where KOID='$tab:root-$moid'");
- updateQuery('update '.$newprefix.'ID set UPD=UPD,KOID=replace(KOID,"'.$tab.':","'.$ntab.':")');
- updateQuery('update '.$newprefix.'ID set UPD=UPD,DTYPE="'.$nkoid.'" WHERE DTYPE="'.$koid.'"');
- updateQuery('update '.$newprefix."IDX set KOIDDST='$ntab:root-$newmoid' WHERE KOIDDST='$tab:root-$moid'");
- updateQuery('update '.$newprefix."IDX set KOIDSRC='$ntab:root-$newmoid' WHERE KOIDSRC='$tab:root-$moid'");
- updateQuery('update '.$newprefix.'IDX set KOIDSRC=replace(KOIDSRC,"'.$tab.':","'.$ntab.':")');
- updateQuery('update '.$newprefix.'IDX set KOIDDST=replace(KOIDDST,"'.$tab.':","'.$ntab.':")');
- }
- }
-
- return array('duplicatetables'=>$tables,'duplicatemods'=>$moids);
- }
- function getSSMAl(&$my){
- $uniqid='v'.XShell::uniqid();
- $br=XShell::from_screen('br');
- $myoid=$br['oid'];
- $max=count($br['__ssmod']);
- $ssmmenu=array();
- for($i=0;$i<$max;$i++) {
- $f='ssmod'.$i;
- $ft=$br['__ssprops'][$i]['modulename'];
- $ff=$br['__ssprops'][$i]['linkedfield'];
- $fa=$br['__ssprops'][$i]['activate_additem'];
- $fmoid=$br['__ssprops'][$i]['_moid'];
- if($ff && ($ff!='*none*' && $fa && $br['__ssinsert'][$i])){
- $o1=new XModuleAction($this,$f,$br['__ssprops'][$i]['modulename'],
- 'javascript:'.$uniqid.'.addTabs("'.$fmoid.'","'.$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&moid='.$fmoid.'&_linkedfield='.$ff.
- '&_parentoid='.$myoid.'&function=insert&template=xmodtable/new.html&tplentry=br&_raw=1&_ajax=1&skip=1'.
- '&tabsmode=1","'.XLabels::getSysLabel('general','add','text').' : '.$ft.'");');
- $o1->menuable=true;
- $ssmmenu[]=$o1;
- }
- }
- if(count($ssmmenu)>1){
- $o1=new XModuleAction($this,'alladd',XLabels::getSysLabel('general','add','text'),'#');
- $o1->menuable=true;
- $o1->newgroup='ssm';
- $my['ssm']=$o1;
- foreach($ssmmenu as &$o1){
- $o1->group='ssm';
- $my[$o1->xfunction]=$o1;
- }
- }else{
- foreach($ssmmenu as &$o1){
- $o1->name=XLabels::getSysLabel('general','add','text').' : '.$o1->name;
- $my[$o1->xfunction]=$o1;
- }
- }
- }
- /// Suppression dans le module des documents qui sont effaces depuis d'autres modules
- function _removeRegisteredOid($oid) {
- updateQuery('delete from '.$this->idx.' where KOIDSRC="'.$oid.'"');
- updateQuery('delete from '.$this->id.' where KOID="'.$oid.'"');
- $this->delDocFromSearchEngine($oid);
- }
- function status($ar=NULL) {
- // inserez votre code personnalise ici
- }
- /// Affichage sur deux niveaux des dossiers et des fichiers
- function &index($ar=NULL) {
- $p=new XParam($ar,array('up'=>1,'down'=>1,'oid'=>'','maxlevel'=>2, 'showfiles'=>1, 'clear'=>false));
- $clear=$p->get('clear');
- if(!empty($clear)) $this->_clearSession('docmode');
- if($this->_getSession('docmode')=='index2') {
- $GLOBALS['XSHELL']->setTemplates('xmoddocmgt/index3.html');
- return $this->index2($ar);
- }
- $tplentry=$p->get('tplentry');
- $maxlevel=$p->get('maxlevel');
- $showfiles=$p->get('showfiles');
- $fileorder=$p->get('fileorder');
- $directoryorder=$p->get('directoryorder');
- $oid=$p->get('oid');
- // Si pas d'oid, on prend la racine
- if(empty($oid)) $_REQUEST['oid']=$oid=$this->rootOid();
- // Recherche du dossier parent si le document que l'on essaie d'afficher n'est pas un dossier
- $rs=selectQuery('select * from '.$this->id.' left outer join _TYPES on '.$this->id.'.DTYPE=_TYPES.KOID '.
- 'where '.$this->id.'.KOID="'.$oid.'"');
- if($rs && ($ors=$rs->fetch())) {
- if($ors['node']==2) {
- $rs=selectQuery('select * from '.$this->idx.' where KOIDSRC="'.$oid.'"/*6*/');
- if($rs && ($ors=$rs->fetch())) $_REQUEST['oid']=$oid=$ors['KOIDDST'];
- }
- }
- $r['here']=&XDocumentDT::objectFactory($oid, $this);
- // Si l'ordre de tri a changé, on le sauvegarde
- if(!empty($fileorder)) {
- $r['here']->setOption('fileorder',$fileorder);
- $r['here']->saveOptions();
- }
- if(!empty($directoryorder)) {
- $r['here']->setOption('directoryorder',$directoryorder);
- $r['here']->saveOptions();
- }
- // Recupere les details du document
- $r['here']->getContent(true);
- $r['here']->getDocumentsDetails();
- $r['here']->getDirectoriesDetails($maxlevel-1);
- $r['here']->getActions();
- $path=&$this->mkContext($oid);
- if($showfiles==2) {
- foreach($r['here']->directories as &$dir) {
- $dir->getDocumentsDetails();
- }
- }
- $r['path']=&$path;
- $r['oidcurrent']=$r['here']->oid;
- // Liste des types qui peuvent etre ajouté dans le dossier en court
- if($this->getPatternsFolderOid()==$path[0]->oid) $r['here']->getNewTypesM(true,true);
- else $r['here']->getNewTypes(true, true);
- // Liste des tris possible sur les dossiers
- $sorting=@$r['here']->tploptions['dirsorting'];
- if(!empty($sorting)){
- $sortinglist=array();
- $list=explode(';',$sorting);
- foreach($list as $i=>$f){
- $param=explode(',',$f);
- if(count($param)==2) $sortinglist[]=array('name'=>$param[0],'order'=>$param[1]);
- }
- $r['dirsorting']=$sortinglist;
- }
- // Liste des tris possible sur les documents
- $sorting=@$r['here']->tploptions['sorting'];
- if(!empty($sorting)){
- $sortinglist=array();
- $list=explode(';',$sorting);
- foreach($list as $i=>$f){
- $param=explode(',',$f);
- if(count($param)==2) $sortinglist[]=array('name'=>$param[0],'order'=>$param[1]);
- }
- $r['sorting']=$sortinglist;
- }
- if($this->interactive && $this->trackaccess) XLogs::uniqueUpdate('access',$oid);
- return XShell::toScreen1($tplentry, $r);
- }
- // visualisation arborescente partielle
- // -> = index2 mais sur le premier niveau et les dossier du path en cours seulement
- //
- public function &index2Light($ar){
- $p=new XParam($ar,array('up'=>1,'down'=>1,'oid'=>'','maxlevel'=>2, 'showfiles'=>2, 'nosess'=>0));
- $nosess=$p->get('nosess');
- if(empty($nosess)) $this->_setSession('docmode','index2');
- $oid=$p->get('oid');
- if(empty($oid)){
- $oid=$this->rootOid();
- $_REQUEST['oid'] = $oid; // templates au moins index2 utilisent ceci
- }
- $tplentry=$p->get('tplentry');
- $maxlevel=$p->get('maxlevel');
- $actiontotest=$p->get('action');
- if(!in_array($actiontotest, array('linkTo','display'))) $actiontotest='index';
- $showfiles=$p->get('showfiles');
- if($showfiles==1) $docstolist=2;
- else $docstolist=1;
- // Les fils directs de root
- $rets = &$this->subObjects4($this->rootOid(), 1, false, 1, $docstolist);
- // Creation du contexte
- $path=&$this->mkContext($oid);
- $oidcurrent=NULL;
- // Construction des noeuds du chemin
- foreach($path[0] as $i=>&$o2) {
- $oidcurrent=$o2->oid;
- if(($oidcurrent != $this->rootOid()) && !in_array($oidcurrent, $rets['1'])){
- $prets = &$this->subObjects4($path[0][$i-1]->oid, 1, false, $i, 1);
- $dx=array_search($path[0][$i-1]->oid, $rets['1']);
- $rets['1'] = array_merge(array_slice($rets['1'], 0, $dx+1), $prets['1'], array_slice($rets['1'], $dx+1));
- $rets['ors']=array_merge($rets['ors'],$prets['ors']);
- }
- }
- // Recupere les dossiers
- foreach($rets['1'] as $i=>&$myoid) {
- $ors=&$rets['ors'][$myoid];
- if(isset($ors)) {
- $rets['docs'][$i]=&XDocumentDT::objectFactory($myoid, $this);
- $rets['docs'][$i]->getContent();
- // nolinkto est utilisé pour cacher certains dossier pour la fonction de copie, lien...
- // il n'est donc pas necessaire de la calculer si on doit retourner aussi les docs car on ne sera pas dans ce cas
- if($docstolist==1) $rets['ors'][$myoid]['noLinkTo']=($this->secure1($myoid, 'edit', $ors['node'])?0:1);
- }
- }
- // Recupere les documents
- if($docstolist==2){
- foreach($rets['2'] as $j=>&$myoid) {
- $ors=&$rets['ors'][$myoid];
- if(isset($ors)) {
- $rets['docs'][$i+1+$j]=&XDocumentDT::objectFactory($myoid, $this);
- $rets['docs'][$i+1+$j]->getContent();
- }
- }
- }
- $order=array();
- $prev=0;
- $prevlabels=array();
- foreach($rets['1'] as $i=>$oid) {
- $o1=&$rets['ors'][$oid];
- $cur=$o1['level'];
- $prevlabels[$cur]=$rets['docs'][$i]->title;
- if($cur<$prev) {
- foreach($prevlabels as $j=>$v) {
- if($j>$cur) unset($prevlabels[$j]);
- }
- }
- $order[$i]=$prevlabels;
- $prev=$o1['level'];
- }
- $orderstring=array();
- foreach($order as $i=>&$o) {
- // en cas d'egalite il faut un discriminant pour que multisort n'aille pas dans le tableau des docs ?
- $orderstring[$i]=implode('>',$o).$i;
- }
- array_multisort($orderstring, SORT_ASC, $rets['docs']);
- $sors=$rets['ors'];
- $rets['ors']=array();
- foreach($rets['docs'] as $i=>&$o) {
- $rets['ors'][$i]=$sors[$o->oid];
- }
- unset($sors);
- $orderstring=array_values($orderstring);
- $oidcurrent=NULL;
- foreach($path[0] as $i=>&$ob) {
- $oidcurrent=$ob->oid;
- foreach($rets['docs'] as $oid=>&$doc) {
- if($ob->oid==$doc->oid) {
- $foo = 'current find';
- $doc->current=true;
- }
- }
- }
- $rets['docs']=array_values($rets['docs']);
- $rets['ors']=array_values($rets['ors']);
- $rets['path']=&$path;
- $rets['oidcurrent']=$oidcurrent;
- if($this->interactive && $this->trackaccess) XLogs::uniqueUpdate('access',$oid);
- return XShell::toScreen1($tplentry, $rets);
- }
- // visualisation arborescente des repertoires
- //
- function &index2($ar=NULL) {
- $p=new XParam($ar,array('up'=>1,'down'=>1,'oid'=>'','maxlevel'=>2, 'showfiles'=>2, 'nosess'=>0));
- $tpl=$p->get('tplentry');
- // Affichage en arbo, on change de fonction
- if($tpl!=TZR_RETURN_DATA && XShell::getTemplate()=='xmoddocmgt/index3.html'){
- XLogs::notice('XModdocMgt::index2', ' index3 required : call to index2Light');
- return $this->index2Light($ar);
- }
- $nosess=$p->get('nosess');
- if(empty($nosess)) $this->_setSession('docmode','index2');
- $oid=$p->get('oid');
- if(empty($oid)){
- $oid=$this->rootOid();
- $_REQUEST['oid']=$oid;
- }
- $tplentry=$p->get('tplentry');
- $maxlevel=$p->get('maxlevel');
- $actiontotest=$p->get('action');
- $move=$p->get('_move');
- $_selected=$p->get('_selected');
- $except=!empty($move) && empty($_selected) ? array($oid):array();
- if(!in_array($actiontotest, array('linkTo','display'))) $actiontotest='display';
- $showfiles=$p->get('showfiles');
- if($showfiles==1)
- $docstolist=array(1,2);
- else
- $docstolist=array(1);
- $rets=&$this->subObjects2($this->rootOid(),$docstolist,100,true,$actiontotest,$except);
- $todel_level=NULL;
- $cnt=count($rets['ors']);
- $lvlprev=0;
- foreach($rets['ors'] as $i=>&$o){
- $rets['docs'][$i]=&XDocumentDT::objectFactory($o['KOIDSRC'], $this);
- $rets['docs'][$i]->getContent();
- }
- $order=array();
- $prev=0;
- $prevlabels=array();
- foreach($rets['ors'] as $i=>&$o) {
- $cur=$o['level'];
- $prevlabels[$cur]=$rets['docs'][$i]->title;
- if($cur<$prev) {
- foreach($prevlabels as $j=>$v) {
- if($j>$cur) unset($prevlabels[$j]);
- }
- }
- $order[$i]=$prevlabels;
- $prev=$o['level'];
- }
- $orderstring=array();
- foreach($order as $i=>&$o) {
- $orderstring[$i]=implode('>',$o).$i;
- // en cas d'egalite il faut un discriminant pour que multisort n'aille pas dans le tableau des docs ?
- }
- $docs=&$rets['docs'];
- $ors=&$rets['ors'];
- array_multisort($orderstring, SORT_ASC, $docs, $ors);
- $path=&$this->mkContext($oid);
- $oidcurrent=NULL;
- foreach($path[0] as $i=>&$ob) {
- $oidcurrent=$ob->oid;
- foreach($rets['docs'] as $j=>&$doc) {
- if($ob->oid==$doc->oid) {
- $doc->current=true;
- }
- }
- }
- $rets['path']=&$path;
- $rets['oidcurrent']=$oidcurrent;
- if($this->interactive && $this->trackaccess) XLogs::uniqueUpdate('access',$oid);
- return XShell::toScreen1($tplentry, $rets);
- }
- /// Retourne la liste des dossiers fils d'un dossier
- function &viewDirFolders($ar=NULL) {
- $p=new XParam($ar,array('up'=>1,'down'=>1,'oid'=>'','maxlevel'=>2, 'showfiles'=>1));
- $oid=$p->get('oid');
- $tplentry=$p->get('tplentry');
- $doc=&XDocumentDT::objectFactory($oid, $this);
- $doc->getContent();
- $fileorder=$p->get('fileorder');
- if(!empty($fileorder)) $doc->setOption('fileorder',$fileorder);
- $doc->getDirectoriesDetails(1);
- $r['doc']=$doc;
- return XShell::toScreen1($tplentry, $r);
- }
- /// Retourne la liste des dossiers/fichiers fils d'un dossier au format JSON allégé
- function ajaxLoadDirTree(){
- $p=new XParam($ar, array('showfiles'=>0));
- $ar['tplentry']=TZR_RETURN_DATA;
- $r=$this->viewDirFolders($ar);
- $showfiles=$p->get('showfiles');
- // l'objet en reponse JSON
- $ret=(object)array('doc'=>(object)array('oid'=>$p->get('oid')),
- 'directories'=>array(),'documents'=>array());
- foreach($r['doc']->directories as $something => &$dir){
- if(!$showfiles) $noLinkTo=($this->secure1($dir->oid, 'edit', 1)?0:1);
- else $noLinkTo=0;
- $ret->directories[]=(object)array('oid'=>$dir->oid,'title'=>htmlspecialchars($dir->title),'countdirs'=>$dir->countdirs,'countdocs'=>$dir->countdocs,
- 'smalliconurl'=>$dir->smalliconurl,'noLinkTo'=>$noLinkTo);
- }
- if($showfiles){
- $r=$this->viewDir($ar);
- foreach($r['doc']->documents as $something => &$dir){
- $ret->documents[]=(object)array('oid'=>$dir->oid,'title'=>htmlspecialchars($dir->title),
- 'smalliconurl'=>$dir->smalliconurl,'noLinkTo'=>0);
- }
- }
- die(json_encode((object)$ret));
- }
- /// Retourne le contenu d'un repertoire
- function &viewDir($ar=NULL) {
- $p=new XParam($ar,array('up'=>1,'down'=>1,'oid'=>'','maxlevel'=>2, 'showfiles'=>1));
- $oid=$p->get('oid');
- $tplentry=$p->get('tplentry');
- $doc=&XDocumentDT::objectFactory($oid, $this);
- $doc->getContent();
- $doc->getActions();
- $fileorder=$p->get('fileorder');
- if(!empty($fileorder)) $doc->setOption('fileorder',$fileorder);
- $doc->getDocumentsDetails();
- $r['doc']=$doc;
- // dossier modele ou descendant
- $path=&$this->mkContext($oid);
- if ($this->getPatternsFolderOid() == $path[0]->oid) {
- $r['doc']->getNewTypesM(true, true);
- } else {
- $r['doc']->getNewTypes(true, true);
- }
- return XShell::toScreen1($tplentry, $r);
- }
- /// Retourne le contenu d'un repertoire au format JSON allégé
- function ajaxLoadDir(){
- $p=new XParam($ar, array());
- $oid=$p->get('oid');
- $r=$this->viewDir($ar);
- // Simplifier la reponse
- $paths=$mpaths=array();
- $parent='';
- $dpaths=$this->mkContext($oid);
- $nbpaths=count($dpaths);
- $self=$GLOBALS['TZR_SESSION_MANAGER']::complete_self(true,false);
- // Créé le fil d'arianne
- foreach($dpaths as $foo=>$path){
- foreach($path as $foo2=>$node){
- if($foo2>0) $parentoid='&parentoid='.$path[$foo2-1]->oid;
- else $parentoid='';
- $link='<a class="cv8-ajaxlink" href="'.$self.'&oid='.$node->oid.$parentoid.'&moid='.$this->_moid.'&function=index2&'.
- 'template=xmoddocmgt/index3.html&tplentry=br">'.$node->title.'</a>';
- if($foo2>0 && $foo==0){
- $paths[]=$link;
- $parent=$path[$foo2-1]->oid;
- }
- if($nbpaths>1) $mpaths[$foo][]=$link;
- }
- }
- // Prepare la liste
- $sorting=$r['doc']->tploptions['sorting'];
- $sortinglist=array();
- if(!empty($sorting)){
- $list=explode(';',$sorting);
- foreach($list as $i=>$f){
- $param=explode(',',$f);
- if(count($param)==2) $sortinglist[]=array('name'=>$param[0],'order'=>$param[1]);
- }
- }
- $ret=(object)array('tpl'=>(object)array('title'=>$r['doc']->tpl['otitle']->raw),
- 'doc'=>(object)array('title'=>html_entity_decode($r['doc']->title),'parentoid'=>$parent,
- 'comment'=>html_entity_decode($r['doc']->comment),'oid'=>$p->get('oid'),'paths'=>$paths,
- 'mpaths'=>$mpaths,'newdirs'=>array(),'newdocs'=>array(),'documents'=>array(),
- 'sorting'=>$sortinglist,'actions'=>','.implode($r['doc']->actions,',').',')
- );
- foreach($r['doc']->newdirs as $it=>&$tpl){
- $url=$self.'&moid='.$this->_moid.'&function=input&template=xmoddocmgt/input.html&doid='.$tpl['oid'].'&tplentry=br&parentoid='.$oid.
- '&oid='.$oid;
- $ret->doc->newdirs[]=(object)array('title'=>$tpl['otitle']->raw,'url'=>$url);
- }
- foreach($r['doc']->newdocs as $it=>&$tpl){
- $url=$self.'&moid='.$this->_moid.'&function=input&template=xmoddocmgt/input.html&doid='.$tpl['oid'].'&tplentry=br&parentoid='.$oid.
- '&oid='.$oid;
- $ret->doc->newdocs[]=(object)array('title'=>$tpl['otitle']->raw,'url'=>$url);
- }
- foreach($r['doc']->documents as $it=>&$doc){
- $url1=$self.'&moid='.$this->_moid.'&function=edit&template=xmoddocmgt/edit.html&oid='.$doc->oid.'&tplentry=br&findex2=index2';
- $url2=$self.'&moid='.$this->_moid.'&function=display&template=xmoddocmgt/display.html&oid='.$doc->oid.'&tplentry=br&findex2=index2';
- $o=(object)array('oid'=>$doc->oid,'tpltitle'=>$doc->tpl['otitle']->raw,'title'=>html_entity_decode($doc->title),
- 'urledit'=>$url1,'urlview'=>$url2,'docs'=>$doc->countfiles>0?$doc->docs:'','upd'=>$doc->fields['oUPD']->toText(),
- 'actions'=>','.implode(',',$doc->actions).',','lock'=>$doc->fields['_lock_user']
- );
- if(isset($doc->fields['oOWN'])) $o->own=$doc->fields['oOWN']->toText();
- $ret->doc->documents[]=$o;
- }
- die(json_encode((object)$ret));
- }
- // creation des informations sur le chemin d'acces
- //
- protected function &mkContext($doc) {
- $doco = &XDocumentDT::objectFactory($doc,$this);
- $doco->getParents(10);
- $doco->getAllPaths();
- return $doco->paths;
- }
- protected function mkContext2(&$my, $doc) {
- $docmode=$this->_getSession('docmode');
- $doco = &XDocumentDT::objectFactory($doc,$this);
- $doco->getParents(10);
- $doco->getAllPaths();
- foreach($doco->paths[0] as $i=>&$o) {
- if($i==0){
- $title=$this->modulename; // on met le titre du module en avant
- $parentoid = '';
- }else{
- $title=$o->title;
- $parentoid = 'parentoid='.$doco->paths[0][$i-1]->oid.'&';
- }
- if($docmode=='index2'){
- $o1=new XModuleAction($this, 'i'.$i, $title,'&moid='.$this->_moid.'&_function=index2&tplentry=br&'.$parentoid.
- 'template=xmoddocmgt/index3.html&tplentry=br&oid='.$o->oid);
- }else{
- $o1=new XModuleAction($this, 'i'.$i, $title,'&moid='.$this->_moid.'&_function=index&tplentry=br&'.$parentoid.
- 'template=xmoddocmgt/index2.html&tplentry=br&oid='.$o->oid);
- }
- $my['stack'][]=$o1;
- }
- }
- // creation d'un nouveau document
- //
- function input($ar=NULL) {
- $p=new XParam($ar,array());
- $doid=$p->get('doid');
- $poid=$p->get('parentoid');
- $tplentry=$p->get('tplentry');
- // lecture du type de noeud nouveau
- $xt = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.'_TYPES');
- $d1 = &$xt->display(array('oid'=>$doid, 'tplentry'=>TZR_RETURN_DATA));
- XShell::toScreen1('brt',$d1);
- $lines = explode("\n", stripslashes($d1['oopts']->toText()));
- $tploptions=array();
- foreach($lines as &$line) {
- @list($var,$val)=explode('=',$line);
- if(!empty($var) && !empty($val)) {
- $var=trim($var);$val=trim($val);
- $tploptions[$var]=$val;
- }
- }
- $path = &$this->mkContext($poid);
- $ar['path'] = &$path; // contexte basedoc pour le repository
- // traitement d'insertion
- $mod=&XDocumentDT::repositoryFactory(NULL, $d1);
- if(!empty($tploptions['peremption'])) {
- $ts=mktime();
- $ts=$ts+$tploptions['peremption']*24*60*60;
- $ar['options']['PRP']['value']=DATE('Y-m-d',$ts);
- }
- $ar['fmoid']=$this->_moid;
- $mod->XMCinput($ar);
- $br=XSHell::from_screen($tplentry);
- XShell::toScreen2($tplentry, 'path', $path);
- }
- function registerDoc($oid, $doctype, $own=true) {
- $q="SELECT COUNT(KOID) FROM {$this->id} WHERE KOID='$oid'";
- $rs=selectQuery($q);
- if($rs && $ors=$rs->fetch()) {
- if($ors['COUNT(KOID)']<=0) {
- if($own) $q='INSERT INTO '.$this->id.' SET KOID="'.$oid.'", DTYPE="'.$doctype.'", ENDO=1, DPARAM=""';
- else $q='INSERT INTO '.$this->id.' SET KOID="'.$oid.'", DTYPE="'.$doctype.'", ENDO=2, DPARAM=""';
- updateQuery($q);
- }
- }
- }
- function newDoc($fields, $typeoid) {
- $xt = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.'_TYPES');
- $d1 = &$xt->display(array('oid'=>$typeoid, 'tplentry'=>TZR_RETURN_DATA));
- $mod=&XDocumentDT::repositoryFactory(NULL,$d1);
- $fields['_options']=array('local'=>1);
- $fields['tplentry']=TZR_RETURN_DATA;
- $r1=$mod->XMCprocInput($fields);
- $oidres=$r1['oid'];
- $this->registerDoc($oidres, $typeoid);
- return $oidres;
- }
- // validation de la creation
- //
- function procInput($ar=NULL) {
- $p=new XParam($ar,array());
- $doid=$p->get('doid');
- $auth=$this->getTypes($doid);
- $noworkflow=$p->get('_noworkflow');
- if(empty($auth)){
- XLogs::critical('security',"access type denied |".get_class($this)."|procInput|".$this->_moid."|TYPE ".$doid.
- "| user ".XUser::get_current_user_uid());
- XShell::redirect2auth();
- }
- $parentoid=$p->get('parentoid');
- if(empty($parentoid)) $parentoid=$this->rootOid();
- $xt = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS=_TYPES');
- $d1 = &$xt->display(array('oid'=>$doid, 'tplentry'=>TZR_RETURN_DATA));
- $ar['tplentry']=TZR_RETURN_DATA;
- $mod=&XDocumentDT::repositoryFactory(NULL,$d1);
- $r1=$mod->XMCprocInput($ar);
- $oidres=$r1['oid'];
- $this->registerDoc($oidres, $doid);
- $docparent = &XDocumentDT::objectFactory($parentoid, $this);
- $docparent->addChild($oidres);
- if(XModule::getMoid(XMODWORKFLOW_TOID) && empty($noworkflow)) {
- $umod=XModule::singletonFactory(XMODWORKFLOW_TOID);
- $umod->checkAndRun($this, $mod, $oidres, 'new');
- }
- // creation des fils par clone du modele
- if (!empty($d1['opattern']->raw)){
- XLogs::notice(get_class($this), "Pattern");
- $this->cloneChilds($d1['opattern'], $oidres);
- }
- return array('oid'=>$oidres);
- }
- // clone des fils d'un noeud
- //
- protected function cloneChilds($opattern, $parentoid){
- // lire le modele
- $pdoc = $this->index(array('tplentry'=>TZR_RETURN_DATA,
- 'oid'=>$opattern->raw));
- // traiter les fils du modele (dossiers)
- foreach($pdoc['docs'] as $docoid=>$doc){
- XLogs::notice(get_class($this), "cloneChild $doc->title $docoid");
- $oidres = $doc->repository->XMCduplicate($docoid);
- // creer l'id et idx
- $q='insert into '.$this->idx.' set KOIDSRC="'.$oidres.'", KOIDDST="'.$parentoid.'"';
- updateQuery($q);
- $q='insert into '.$this->id.' set KOID="'.$oidres.'", DTYPE="'.$doc->tpl['oid'].'", ENDO=1, DPARAM=""';
- updateQuery($q);
- /* a voir ???
- if (!empty($doc->tpl['opattern']->raw)){
- $this->cloneChilds($doc->tpl['opattern'], $oidres);
- }
- */
- }
- // traiter les fils du modele (documents)
- foreach($pdoc['here']->documents as $docoid=>$doc){
- XLogs::notice(get_class($this), "cloneChild $doc->title $docoid");
- $oidres = $doc->repository->XMCduplicate($docoid);
- // creer l'id et idx
- $q='insert into '.$this->idx.' set KOIDSRC="'.$oidres.'", KOIDDST="'.$parentoid.'"';
- updateQuery($q);
- $q='insert into '.$this->id.' set KOID="'.$oidres.'", DTYPE="'.$doc->tpl['oid'].'", ENDO=1, DPARAM=""';
- updateQuery($q);
- }
- }
- /// Edition d'un document
- function edit($ar=NULL) {
- $p=new XParam($ar,array());
- $oid=$p->get('oid');
- $tplentry=$p->get('tplentry');
- $doc=&XDocumentDT::objectFactory($oid, $this);
- XShell::toScreen1('brt',$doc->tpl);
- $ar['fmoid']=$this->_moid;
- if($this->interactive && $this->trackaccess) $ar['accesslog']=1;
- $d=&$doc->repository->XMCedit($ar);
- $d['path']=&$this->mkContext($oid);
- $d['here']=$doc;
- if($doc->tpl['oshared']->raw==1) {
- $m1=XModule::modlist(array('basic'=>true,'toid'=>XMODDOCMGT_TOID,'tplentry'=>TZR_RETURN_DATA));
- // s'il y a un autre module autorise que le module courant
- if(count($m1['lines_oid'])>1) {
- $d['modlist']=&$m1;
- }
- }
- return XShell::toScreen1($tplentry,$d);
- }
- /// Prépare le partage d'un document entre plusieurs bases documentaires
- function share($ar=NULL){
- $p=new XParam($ar,NULL);
- $oid=$p->get('oid');
- $tplentry=$p->get('tplentry');
- $ret=array();
- $doc=&XDocumentDT::objectFactory($oid, $this);
- if($doc->tpl['oshared']->raw==1) {
- $ret['modlist']=XModule::modlist(array('basic'=>true,'toid'=>XMODDOCMGT_TOID,'tplentry'=>TZR_RETURN_DATA));
- foreach($ret['modlist']['lines_oid'] as $i=>$moid){
- $mod=XModule::objectFactory($moid);
- $f=$mod->father1($oid);
- foreach($f as $foid){
- if($mod->secure($foid,'input')) $dest[$moid][]=XDocumentDT::objectFactory($foid,$mod);
- }
- }
- }
- $ret['doc']=$doc;
- $ret['dest']=$dest;
- return XShell::toScreen1($tplentry,$ret);
- }
- /// Partage un document avec d'autres bases documentaires
- function procShare($ar=NULL){
- $p=new XParam($ar,NULL);
- $oid=$p->get('oid');
- $share=$p->get('_share');
- $doc=&XDocumentDT::objectFactory($oid, $this);
- foreach($share as $moid=>$dests){
- $mod=XModule::objectFactory($moid);
- if(is_object($mod)){
- foreach($dests as $old=>$dest){
- if(empty($dest)){
- if(Kernel::isAKoid($old)){
- // Suppression d'un partage
- if(!$mod->secure($old,'del')) continue;
- $mod->del(array('_options'=>array('local'=>true),'physical'=>0,'oid'=>$oid,'parentoid'=>$old));
- }
- }else{
- if(Kernel::isAKoid($old) && ($old!=$dest)){
- // Modification d'un partage
- if(!$mod->secure($dest,'input') || !$mod->secure($old,'del')) continue;
- $doc2=&XDocumentDT::objectFactory($dest,$mod);
- $doc2->addChild($oid);
- $mod->del(array('_options'=>array('local'=>true),'physical'=>0,'oid'=>$oid,'parentoid'=>$old));
- }else{
- // Insertion d'un partage
- if(!$mod->secure($dest,'input')) continue;
- $mod->registerDoc($oid,$doc->tpl['oid']);
- $doc2=&XDocumentDT::objectFactory($dest,$mod);
- $doc2->addChild($oid);
- }
- }
- }
- }
- }
- }
- /// Visualiser un document ou un repertoire
- function &display($ar=NULL) {
- $p=new XParam($ar,array());
- $oid=$p->get('oid');
- $tplentry=$p->get('tplentry');
- $doc=&XDocumentDT::objectFactory($oid, $this);
- XShell::toScreen1('brt',$doc->tpl);
- $ar['fmoid']=$this->_moid;
- if($this->interactive && $this->trackaccess) $ar['accesslog']=1;
- $d=&$doc->repository->XMCdisplay($ar,false);
- $d['path']=&$this->mkContext($oid);
- $d['here']=$doc;
- return XShell::toScreen1($tplentry,$d);
- }
- /// Validation de la creation
- function procEdit($ar=NULL) {
- $p=new XParam($ar,array());
- $oid=$p->get('oid');
- $share=$p->get('_share');
- $noworkflow=$p->get('_noworkflow');
- $doc=&XDocumentDT::objectFactory($oid, $this);
- XShell::toScreen1('brt',$doc->tpl);
- $doc->repository->XMCprocEdit($ar);
- updateQuery('UPDATE '.$this->id.' SET UPD=NULL WHERE KOID="'.$oid.'"');
- if(XModule::getMoid(XMODWORKFLOW_TOID) && empty($noworkflow)) {
- $umod=XModule::singletonFactory(XMODWORKFLOW_TOID);
- $umod->checkAndRun($this, $doc->repository, $oid, 'edit');
- }
- }
- /// Journal d'un document
- function journal($ar=NULL) {
- $p=new XParam($ar,array());
- $oid=$p->get('oid');
- $tplentry=$p->get('tplentry');
- $doc=&XDocumentDT::objectFactory($oid, $this);
- XShell::toScreen1('brt',$doc->tpl);
- $journal=$doc->journal();
- $journal['_repository']['archive']=$doc->repository->archive;
- $journal['_repository']['trackchanges']=$doc->repository->trackchanges;
- return XShell::toScreen1($tplentry,$journal);
- }
- // suppression
- // si physical on supprime partout y compris physiquement
- // sinon on supprime physiquement si c'est le dernier lien
- //
- // suppression std avec secu
- // si physical on supprime partout y compris physiquement
- // sinon on supprime physiquement si c'est le dernier lien
- //
- function del($ar=NULL) {
- $p=new XParam($ar,array('deldoc'=>true));
- $oid=$p->get('oid');
- $tplentry=$p->get('tplentry');
- $selected=$p->get('_selected');
- $physical=$p->get('physical');
- $delshare=$p->get('delshare');
- $deldoc=$p->get('deldoc');
- $parentoid=$p->get('parentoid');
- if(empty($selected)) {
- $cnt = countSelectQuery('select COUNT(KOIDDST) from '.$this->idx.' where KOIDSRC=\''.$oid.'\'');
- if($cnt<=1) {
- $physical=1;
- } else {
- $q='delete from '.$this->idx.' where KOIDSRC="'.$oid.'" AND KOIDDST="'.$parentoid.'"';
- updateQuery($q);
- }
- if(!empty($physical) && $physical==1) {
- $doc=&XDocumentDT::objectFactory($oid, $this);
- // traiter les fils s'il s'agit de répertoire
- if ($doc->node == true){
- $isadmin = $this->secure1($oid, ':admin', ($doc->node?'1':'2'));
- // dossier vide ou admin
- $v = $this->subObjects1($doc->oid, 99, false);
- $coids = array_merge($v[1], $v[2]);
- if (count($coids)>0 && !$isadmin){ // on n'efface que les dossiers vides
- if($tplentry!=TZR_RETURN_DATA) {
- $message=XLabels::getSysLabel('xmoddocmgt','deletednotempty','text');
- XShell::setNext($GLOBALS['TZR_SESSION_MANAGER']::complete_self()."&oid={$oid}&moid={$this->_moid}&class=".get_class($this).
- "&tplentry=br&template=xmoddocmgt/index2.html&function=index&message=".urlencode($message));
- XShell::toScreen2('', 'message', $message);
- }
- return false;
- }
- // avoir les droits sur les descendants
- foreach($coids as $foo=>$coid){
- if (!$this->secure($coid, 'del')){
- if($tplentry!=TZR_RETURN_DATA) {
- $message=XLabels::getSysLabel('xmoddocmgt','deleteforbidden','text');
- XShell::setNext($GLOBALS['TZR_SESSION_MANAGER']::complete_self()."&oid={$oid}&moid={$this->_moid}&class=".get_class($this).
- "&tplentry=br&template=xmoddocmgt/index2.html&function=index&message=".urlencode($message));
- XShell::toScreen2('', 'message', $message);
- }
- return false; // stop ici
- }
- }
- // on enleve les fils
- $v = $this->subObjects1($doc->oid, 2, false);
- $coids = array_merge($v[1], $v[2]);
- if ($coids){
- foreach($coids as $foo=>$coid){
- $physical = 0;
- // avec phyical = 0, seul les noeuds n'ayant qu'un parent (donc ce noeud) seront enleves
- // rem : on a, au dessus, verifie qu'on a les droits sur tous les descendants
- $this->del(array('oid'=>$coid, 'physical'=>$physical, 'parentoid'=>$oid,
- '_selected'=>array(), 'tplentry'=>TZR_RETURN_DATA));
- }
- }
- }
- // On supprime la fiche du document
- if($deldoc){
- // Si le document est de type commun, on parcourt toutes les bases doc pour savoir si le document doit etre supprimé ou non
- if($doc->tpl['oshared']->raw==1) {
- $del=true;
- $mods=XModule::modlist(array('basic'=>true,'toid'=>XMODDOCMGT_TOID,'noauth'=>true));
- foreach($mods['lines_oid'] as $moid) {
- $mod=XModule::objectFactory($moid);
- $nb=countSelectQuery('select count(*) from '.$mod->id.' where KOID="'.$oid.'"');
- if($nb>0){
- if(!$delshare){
- // On ne veut effacer que dans la base en cours et le document est présent dans une autre base documentaire, on ne l'efface pas
- $del=false;
- break;
- }else{
- // On ne veut effacer partout et le document est présent dans une autre base documentaire, on tente de l'effacer
- if($mod->secure($oid,'del')){
- $ok=$mod->del(array('_options'=>array('local'=>true),'tplentry'=>TZR_RETURN_DATA,'oid'=>$oid,'deldoc'=>false,'physical'=>1));
- if($del) $del=$ok;
- }else{
- $del=false;
- }
- }
- }
- }
- if($del) $doc->del();
- }else{
- $doc->del();
- }
- }
- // On supprime le noeud de la base doc
- updateQuery('delete from '.$this->idx.' where KOIDSRC="'.$oid.'"');
- updateQuery('delete from '.$this->id.' where KOID="'.$oid.'"');
- $this->delDocFromSearchEngine($oid);
- return true;
- }
- } else {
- // RZ un document est supprimable si le pere est en ecriture et si lui-meme est en ecriture
- $parentoid = $oid;
- if($this->secure($oid,':rw')) {
- foreach($selected as $koid=>$foo) {
- if($this->secure($koid,':rw')) {
- $this->del(array('oid'=>$koid, 'physical'=>$physical, 'parentoid'=>$oid, '_selected'=>array(), 'tplentry'=>TZR_RETURN_DATA));
- } else {
- $mess=XLabels::getSysLabel('xmoddocmgt','deleteforbidden','text');
- }
- }
- } else {
- $mess=XLabels::getSysLabel('xmoddocmgt','deleteforbidden','text');
- }
- }
- if($tplentry!=TZR_RETURN_DATA && !XShell::hasNext()){
- XShell::setNext($GLOBALS['TZR_SESSION_MANAGER']::complete_self()."&oid={$parentoid}&moid={$this->_moid}&class=".get_class($this).
- "&tplentry=br&template=xmoddocmgt/index2.html&function=index&message=$mess");
- }
- }
- function &father($oid) {
- if(!isset($this->_f[$oid])) {
- $set=selectQueryGetAll('SELECT * FROM '.$this->idx.','.$this->id.',_TYPES WHERE KOIDSRC="'.$oid.'" and KOIDDST='.$this->id.'.KOID and '.
- $this->id.'.DTYPE=_TYPES.KOID/*X*/');
- $this->_f[$oid]=array();
- foreach($set as &$f1) $this->_f[$oid][$f1['KOIDDST']]=$f1;
- }
- return $this->_f[$oid];
- }
- function &father1($oid) {
- if(!isset($this->_f1[$oid])) {
- $set=selectQueryGetAll('SELECT KOIDDST FROM '.$this->idx.' WHERE KOIDSRC="'.$oid.'"');
- $this->_f1[$oid]=array();
- foreach($set as &$f1) $this->_f1[$oid][]=$f1['KOIDDST'];
- }
- return $this->_f1[$oid];
- }
- protected function getPath($oid) {
- // recherche des parents
- $next=$oid;
- $path=array();
- $i=0;
- while(!empty($next)) {
- $path[$i++]=$next;
- $rs=selectQuery('select * from '.$this->idx.' where KOIDSRC="'.$next.'"');
- $next='';
- if($rs) {
- $ors=$rs->fetch();
- $next=$ors['KOIDDST'];
- }
- }
- $path=array_reverse($path);
- foreach($path as $i=>$koid) {
- $path[$i]=&XDocumentDT::objectFactory($koid, $this);
- }
- return $path;
- }
- // id du dossier qui contient les modele
- //
- protected function getPatternsFolderOid(){
- return $this->defaultFolderTable.':'.$this->patternSuffix;
- }
- // liste des modeles definis pour cette base documentaire
- // -> oid du dossier
- // -> description
- //
- public function getPatterns() {
- $patternOid = $this->getPatternsFolderOid();
- // verif dossier modele existe
- $cnt=selectQuery('select COUNT(*) from '.$this->id.' where KOID=\''.$patternOid.'\'');
- if($cnt<=0) return array();
- // lecture du rep des modeles
- $pf = $this->index(array('tplentry'=>TZR_RETURN_DATA,
- 'oid'=>$patternOid,
- 'maxlevel'=>2,
- 'up'=>1,
- 'down'=>1
- )
- );
- // menu contient les dossiers fils
- if (count($pf['menu']) == 0)
- return array();
- $docs = &$pf['docs'];
- $r = array();
- foreach($pf['menu'] as $foo=>&$menu){
- $r[] = &$docs[$menu[0]];
- }
- return $r;
- }
- /// Recupere les infos d'un objet par l'affichage du résultat d'une recherche
- public function getSearchResult($oid,$filter=NULL){
- $d1=&XDocumentDT::objectFactory($oid,$this);
- $type=@$filter['type'];
- if(in_array($d1->tpl['oid'],$type) || empty($type)) {
- $d1->getParents(2);
- return $d1;
- }else return false;
- }
- /// presentation d'un resultat de recherche dans le module
- public function showSearchResult($oids) {
- $_REQUEST = array(
- 'function' => 'advsearch',
- 'template' => 'xmoddocmgt/advsearch2.html',
- 'moid' => $this->_moid,
- 'tplentry' => 'br',
- 'clearrequest' => 1,
- 'oids' => $oids
- );
- $GLOBALS['XSHELL']->run();
- exit;
- }
- /// Recherche avancée
- function advsearch($ar) {
- $p=new XParam($ar,array());
- $oids=$p->get('oids');
- $doctype=$p->get('type');
- $dosearch=$p->get('dosearch');
- $structsearch=$p->get("structsearch");
-
- // Recherche des types de documents
- $types=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS=_TYPES');
- $doctypes=&$types->browse(array('order'=>'title','pagesize'=>100, 'where'=>"modid = '".$this->_moid."'", '_local'=>true));
- // Si un type est selectionné, on prepare le formulaire de recherche et on effectue la recherche si necessaire
- if(!empty($doctype)) {
- $disp=&$types->display(array('tplentry'=>TZR_RETURN_DATA,'oid'=>$doctype));
- $mod=&XDocumentDT::repositoryFactory(NULL,$disp);
- if(!empty($structsearch)) $mod->XMCquery($ar);
- if(!empty($dosearch)) {
- if(empty($structsearch)) {
- $r1=&$this->search(array('tplentry'=>TZR_RETURN_DATA,'type'=>$doctype));
- XShell::toScreen2('br','docs',$r1['modules'][$this->_moid]['lines_obj']);
- } else {
- $ar['tplentry']=TZR_RETURN_DATA;
- $ar['pagesize']=9999;
- $r1=&$mod->XMCprocQuery($ar);
- }
- }
- }elseif(!empty($oids)){
- if(!$oids[0]) $r1['lines_oid']=array_keys($oids);
- else $r1['lines_oid']=$oids;
- }
- if(!empty($r1['lines_oid'])){
- $idx=0;
- foreach($r1['lines_oid'] as $oid) {
- $d1=&XDocumentDT::objectFactory($oid,$this);
- if(is_object($d1) && ($d1->tpl['oid']==$doctype || empty($doctype)) && $this->secure($d1->oid, 'display')) {
- $docs[$idx]=$d1;
- $docs[$idx]->getParents(2);
- $sort[$idx]=$d1->parents[0]->parents[0]->short.$d1->parents[0]->short.$oid;
- $idx++;
- }
- }
- array_multisort($sort, $docs);
- XShell::toScreen2('br','docs',$docs);
- }
- XShell::toScreen1('doctypes',$doctypes);
- }
- /// Recherche libre
- function search($ar) {
- $p=new XParam($ar,array());
- $type=$p->get('type');
- if(!is_array($type)){
- if(!empty($type)) $type=array($type);
- else $type=array();
- }
- $tplentry=$p->get('tplentry');
- $ar['moidfilter']=$this->_moid;
- $ar['advfilter']['type']=$type;
- $searchEngine=&XSearch::objectFactory();
- return $searchEngine->globalSearch($ar);
- }
- /// Indexation du module dans le moteur de recherche
- public function _buildSearchIndex(&$searchEngine,$checkbefore=true,$limit=NULL,$cond=NULL){
- $done=0;
- if(!empty($cond)){
- if($cond=='UPD'){
- $last=XDbIni::get('lastindexation_'.$this->_moid,'val');
- if(empty($last)) $last=date('2000-01-01 00:00:00');
- XDbIni::set('lastindexation_'.$this->_moid,date('Y-m-d H:i:s'));
- $cond=$this->id.'.UPD>="'.$last.'"';
- }
- $cond=' where '.$cond;
- }else{
- $cond='';
- }
- $rs=selectQuery('SELECT * FROM '.$this->id.' '.
- 'left outer join '.$this->idx.' on '.$this->id.'.KOID=KOIDSRC '.
- 'left outer join _TYPES on '.$this->id.'.DTYPE=_TYPES.KOID '.$cond.' order by rand()');
- while($rs && ($ors=$rs->fetch())) {
- XLogs::debug('XModDocMgt::buildSearchIndex: testing '.$ors['KOIDSRC']);
- if($checkbefore && $searchEngine->docExists($ors['KOIDSRC'],$this->_moid,NULL)) continue;
- XLogs::debug('XModDocMgt::buildSearchIndex: adding '.$ors['KOIDSRC']);
- $mydoc=&XDocumentDT::objectFactory($ors['KOIDSRC'],$this,$ors);
- $mydoc->addToSearchEngine($searchEngine);
- $done++;
- if($done%30==0){
- XLogs::debug('XModDocMgt::buildSearchIndex: commit');
- $searchEngine->index->commit();
- }
- if($limit && $done>$limit){
- XLogs::debug('XModDocMgt::buildSearchIndex: break at '.$done);
- break;
- }
- }
- return true;
- }
- /// Daemon qui lance en particulier l'indexation des champs
- protected function _daemon($at) {
- if($at=="daily") {
- // Verifie que les liens de la base doc pointent toujours sur un objet
- $rs=selectQuery('SELECT * FROM '.$this->id);
- while($rs && ($ors=$rs->fetch())) {
- $table=Kernel::getTable($ors['KOID']);
- $cnt=countSelectQuery('SELECT COUNT(*) FROM '.$table.' WHERE KOID="'.$ors['KOID'].'"');
- if($cnt<=0) {
- updateQuery('DELETE FROM '.$this->id.' WHERE KOID="'.$ors['KOID'].'"');
- updateQuery('DELETE FROM '.$this->idx.' WHERE KOIDSRC="'.$ors['KOID'].'"');
- updateQuery('UPDATE '.$this->idx.' SET KOIDSRC="" WHERE KOIDSRC="'.$ors['KOID'].'"');
- }
- }
- // Supression de toutes les aretes dont les departs sont inexistants
- $rs=selectQuery('SELECT KOIDSRC,KOID FROM '.$this->idx.' LEFT OUTER JOIN '.$this->id.' ON KOID=KOIDSRC WHERE ISNULL(KOID);');
- while($rs && ($ors=$rs->fetch())) updateQuery('DELETE FROM '.$this->idx.' WHERE KOIDSRC="'.$ors['KOIDSRC'].'"');
- }
- }
- /// Supprime un document de l'index
- function delDocFromSearchEngine($oid) {
- $se=&XSearch::objectFactory();
- $se->deleteItem($oid,$this->_moid);
- }
- function goto1($ar=NULL) {
- $p = new XParam($ar,array());
- $oid=$p->get('oid');
- $url=$GLOBALS['TZR_SESSION_MANAGER']::admin_url(true,true);
- $moid=$this->_moid;
- $rs=selectQuery('select * from '.$this->idx.','.$this->id.',_TYPES where KOIDSRC="'.$oid.'" and '.
- 'KOIDSRC='.$this->id.'.KOID and '.$this->id.'.DTYPE=_TYPES.KOID');
- if($ors=$rs->fetch()) {
- if($ors['node']==1) {
- $right= $this->secure($oid, 'index');
- if(!$right) securityWarning('XModDocMgt (1)::goto1: could not access to objet '.$oid.' in module '.$moid);
- header("Location: {$url}&moid=$moid&template=xmoddocmgt/index2.html&oid=$oid&function=index&tplentry=br&skip=1");
- } else {
- $right= $this->secure($oid, 'display');
- if(!$right) securityWarning('XModDocMgt (2)::goto1: could not access to objet '.$oid.' in module '.$moid);
- header("Location: {$url}&moid=$moid&function=display&template=xmoddocmgt/display.html&oid=$oid&tplentry=br&skip=1");
- }
- }else{
- $last=XDbIni::get('xmoddocmgt:lastindexation');
- if(empty($last)) $last=date('Y-m-d H:i:s',strtotime('-4 hours'));
- XDbIni::set('xmoddocmgt:lastindexation',date('Y-m-d H:i:s'));
- $rs=selectQuery('SELECT '.$this->idx.'.*, '.$this->id.'.*, _TYPES.* FROM '.$this->idx.','.
- $this->id.',_TYPES where '.$this->id.'.UPD >= "'.$last.'" and '.
- 'KOIDSRC='.$this->id.'.KOID and '.$this->id.'.DTYPE=_TYPES.KOID');
- XLogs::notice(get_class($this), get_class($this)."::_daemon indexation des {$rs->rowCount()} depuis $last");
- $searchEngine = XSearch::objectFactory();
- while($ors=$rs->fetch()) {
- if($searchEngine->docExists($ors['KOIDSRC'],$this->_moid,NULL)) continue;
- $mydoc=&XDocumentDT::objectFactory($ors['KOIDSRC'],$this,$ors);
- $mydoc->addToSearchEngine();
- }
- }
- }
- // rend la liste des objets qui se trouvent en dessous de cet objet,
- // independamment des niveaux
- //
- public function &subObjects($oid) {
- $subs=&$this->subObjects1($oid);
- $all=array_merge($subs[1], $subs[2]);
- return $all;
- }
- /// changement du root d'un user
- public function setRootOid($ar=NULL) {
- $p=new XParam($ar, array());
- $oid=$p->get('oid');
- $uid=XUser::get_current_user_uid();
- XOpts::setSubOpt($uid, $this->_moid, 'opts', 'home', $oid);
- }
- /// effacement du root d'un user
- public function clearRootOid($ar=NULL) {
- $p=new XParam($ar, array());
- $uid=XUser::get_current_user_uid();
- XOpts::unsetSubOpt($uid, $this->_moid, 'opts', 'home');
- }
- public function rootOid() {
- if(!empty($this->opts['home'])) return $this->opts['home'];
- return $this->defaultFolderTable.':root-'.$this->_moid;
- }
- // recherche de tous les oids fils d'un objet y compris lui-meme
- // si types=array(1) on ne rend que les repertoires
- // si types=array(1,2) on rend tous les objets
- // si types=array(2) on rend les documents seulements
- //
- public function &subObjects1($oid, $levels=99, $myself=true) {
- if(empty($oid)) $oid=$this->rootOid();
- $open=array($oid);
- $node=array(1);
- $level=array(1);
- $oids=array('1'=>array(),'2'=>array());
- $ooid=$oid;
- $done=array(); /* liste des noeuds examines pour ne pas repasser dessus */
- while(!empty($open)) {
- $oid=array_pop($open);
- $n=array_pop($node);
- $l=array_pop($level);
- $done[]=$oid;
- if(!empty($oid)) {
- if(!$this->secure1($oid, 'index',$n['node'])) continue;
- $oids[$n][]=$oid;
- }
- if(($n==1) && ($l<$levels)) {
- if(!isset($this->adjacence[$oid]))
- $this->adjacence[$oid]=selectQueryGetAll('SELECT DISTINCT KOIDSRC,node,DTYPE FROM '.$this->idx.','.$this->id.
- ',_TYPES WHERE KOIDDST="'.$oid.'"'.
- ' AND '.$this->id.'.KOID=KOIDSRC AND '.$this->id.'.DTYPE=_TYPES.KOID');
- foreach($this->adjacence[$oid] as $oid=>&$ors) {
- $oid=$ors['KOIDSRC'];
- if(!in_array($oid,$done) && !in_array($oid,$open)) {
- $open[]=$oid;
- $node[]=$ors['node'];
- $level[]=$l+1;
- }
- }
- }
- }
- if(!$myself) { /* on vire l'oid d'origine s'il n'est pas demande */
- $dx=array_search($ooid,$oids['1']);
- if(!($dx===FALSE)) {
- unset($oids['1'][$dx]);
- }
- $dx=array_search($ooid,$oids['2']);
- if(!($dx===FALSE)) {
- unset($oids['2'][$dx]);
- }
- }
- return $oids;
- }
- // recherche de tous les oids fils direct d'un objet (types: 1=>seulement dossier, autre=>tous)
- // $myself inutile
- public function &subObjects3($oid, $levels=99, $myself=true,$level=1,$types=0) {
- if(empty($oid)) $oid=$this->rootOid();
- if(isset($this->_s[$oid])) return $this->_s[$oid];
- XLogs::debug("XModDocMgt::subObjects3: $oid");
- $open=array($oid);
- $node=array(1);
- $oids=array('1'=>array(),'2'=>array());
- if($levels==0) return $oids;
- $ooid=$oid;
- $done=array(); /* liste des noeuds examines pour ne pas repasser dessus */
- if(!isset($this->adjacence[$oid]))
- $this->adjacence[$oid]=selectQueryGetAll('SELECT DISTINCT KOIDSRC,node,DTYPE FROM '.$this->idx.' '.
- 'left outer join '.$this->id.' on '.$this->id.'.KOID=KOIDSRC '.
- 'left outer join _TYPES on '.$this->id.'.DTYPE=_TYPES.KOID WHERE KOIDDST="'.$oid.'" /*41*/');
- foreach($this->adjacence[$oid] as $oid2=>&$ors) {
- $oid2=$ors['KOIDSRC'];
- if(empty($ors['node']) || empty($ors['DTYPE'])) continue;
- if(($types==1) && ($ors['node']==2)) continue;
- if(($ors['node']==1) && !$this->secure1($oid2, 'index', $ors['node'])) continue;
- if(($ors['node']==2) && !$this->secure1($oid2, 'display', $ors['node'])) continue;
- // on supprime les fils dossier qui sont vides et sur lesquels on n'a pas le droit de lecture
- if($ors['node']==1){
- $oidssub=&$this->subObjects3($oid2, $levels-1, true, $level+1, $types);
- if(empty($oidssub['1']) && empty($oidssub['2']) && !$this->secure1($oid2, 'display', $ors['node'])) {
- continue;
- }
- }
- $oids[$ors['node']][]=$oid2;
- $ors['level']=$level;
- $oids['ors'][$oid2]=$ors;
- }
- $oids['1']=array_unique($oids['1']);
- $oids['2']=array_unique($oids['2']);
- $this->_s[$oid]=$oids;
- if(!$myself) {
- $dx=array_search($ooid,$oids['1']);
- if(!($dx===FALSE)) {
- unset($oids['1'][$dx]);
- }
- $dx=array_search($ooid,$oids['2']);
- if(!($dx===FALSE)) {
- unset($oids['2'][$dx]);
- }
- }
- return $oids;
- }
- /// recherche de tous les oids fils lisibles d'un objet y compris lui-meme, sans tenir compte de l'action
- public function &subObjects4($oid, $levels=99, $myself=true, $level=1, $types=0) {
- if(empty($oid)) $oid=$this->rootOid();
- if(isset($this->_s[$oid])) return $this->_s[$oid];
- XLogs::debug("XModDocMgt::subObjects4: $oid");
- $open=array($oid);
- $node=array(1);
- $oids=array('1'=>array(),'2'=>array());
- if($levels==0) return $oids;
- $ooid=$oid;
- $done=array(); /* liste des noeuds examines pour ne pas repasser dessus */
- $adj=selectQueryGetAll('SELECT DISTINCT KOIDSRC,node,DTYPE FROM '.$this->idx.' '.
- 'left outer join '.$this->id.' on '.$this->id.'.KOID=KOIDSRC '.
- 'left outer join _TYPES on '.$this->id.'.DTYPE=_TYPES.KOID WHERE KOIDDST="'.$oid.'" /*42*/');
- foreach($adj as $ii=>&$ors) {
- $oid2=$ors['KOIDSRC'];
- if(empty($ors['node']) || empty($ors['DTYPE'])) continue;
- if(($types==1) && ($ors['node']==2)) continue;
- if(($ors['node']==1) && !$this->secure1($oid2, 'index', $ors['node'])) continue;
- if(($ors['node']==2) && !$this->secure1($oid2, 'display', $ors['node'])) continue;
- if(($ors['node']==1) && !$this->secure1($oid2, 'display', $ors['node'])) {
- $any=$this->subObjects4_1($oid2);
- // on supprime les fils qui sont vides et sur lesquels on n'a pas le droit de lecture
- if(!$any) continue;
- }
- $oids[$ors['node']][]=$oid2;
- $ors['level']=$level;
- $oids['ors'][$oid2]=$ors;
- }
- $oids['1']=array_unique($oids['1']);
- $oids['2']=array_unique($oids['2']);
- $this->_s[$oid]=$oids;
- if(!$myself) {
- $dx=array_search($ooid,$oids['1']);
- if(!($dx===FALSE)) {
- unset($oids['1'][$dx]);
- }
- $dx=array_search($ooid,$oids['2']);
- if(!($dx===FALSE)) {
- unset($oids['2'][$dx]);
- }
- }
- return $oids;
- }
- // recherche de tous les oids fils d'un objet y compris lui-meme
- //
- public function subObjects4_1($oid,$actiontotest=':ro',$types=array(1,2)) {
- if(isset($this->_s1[$oid])) return $this->_s1[$oid];
- XLogs::debug("XModDocMgt::subObjects4_1: $oid");
- $adj=selectQueryGetAll('SELECT DISTINCT KOIDSRC,node,DTYPE FROM '.$this->idx.' '.
- 'left outer join '.$this->id.' on '.$this->id.'.KOID=KOIDSRC '.
- 'left outer join _TYPES on '.$this->id.'.DTYPE=_TYPES.KOID WHERE KOIDDST="'.$oid.'" /*43*/');
- foreach($adj as $ii=>&$ors) {
- $oid2=$ors['KOIDSRC'];
- if(empty($ors['node']) || empty($ors['DTYPE'])) continue;
- if(!in_array($ors['node'],$types)) continue;
- // si repertoire et pas de traversee.. on saute
- if(($ors['node']==1) && !$this->secure1($oid2, ':list', $ors['node'])) continue;
- // si fichier et pas de lecture.. on saute
- if(($ors['node']==2) && !$this->secure1($oid2, $actiontotest, $ors['node'])) continue;
- // si repertoire et pas de lecture, on regarde ce qu'il y a en dessous
- if(($ors['node']==1) && !$this->secure1($oid2, $actiontotest, $ors['node'])) {
- if($this->subObjects4_1($oid2,$actiontotest,$types)) {
- $this->_s1[$oid]=true;
- return true;
- }
- continue;
- }
- $this->_s1[$oid]=true;
- return true;
- }
- $this->_s1[$oid]=false;
- return false;
- }
- // recherche de tous les oids et le ors fils d'un objet y compris lui-meme
- // si types=array(1) on ne rend que les repertoires
- // si types=array(1,2) on rend tous les objets
- // si types=array(2) on rend les documents seulements
- // except : tableau d'oid a exclure
- //
- public function &subObjects2($oid, $types=array(1,2), $levels=99, $myself=true, $actiontotest="display", $except=array()) {
- $open=array($oid);
- $node=array(array('node'=>1, 'KOIDSRC'=>$oid));
- //$node=array();
- $level=array(1);
- $oids=array();
- $orss=array();
- $ooid=$oid;
- $done=array(); /* liste des noeuds examines pour ne pas repasser dessus */
- while(!empty($open)) {
- $oid=array_pop($open);
- $done[]=$oid;
- $n=array_pop($node);
- $l=array_pop($level);
- if(!empty($oid)) {
- if(!$this->secure1($oid,$actiontotest,$n['node'])){
- if($this->subObjects4_1($oid,':rw',array(1))) {
- $this->_s1[$oid]=true;
- $n['noLinkTo']=false;
- } else {
- $n['noLinkTo']=true;
- continue;
- }
- }
- if(in_array($n['node'],$types)) {
- $oids[]=$oid;
- $n['level']=$l;
- $orss[]=$n;
- }
- }
- if($l<$levels) {
- if(!isset($this->adjacence[$oid]))
- $this->adjacence[$oid]=selectQueryGetAll('SELECT DISTINCT KOIDSRC,node,DTYPE FROM '.$this->idx.','.$this->id.
- ',_TYPES WHERE KOIDDST="'.$oid.'"'.
- ' AND '.$this->id.'.KOID=KOIDSRC AND '.$this->id.'.DTYPE=_TYPES.KOID');
- foreach($this->adjacence[$oid] as $oid=>&$ors) {
- $oid=$ors['KOIDSRC'];
- if(in_array($oid,$except)) continue;
- if(!in_array($oid,$open) && !in_array($oid,$done)) {
- $open[]=$oid;
- $node[]=$ors;
- $level[]=$l+1;
- }
- }
- }
- }
- if(!$myself) { /* on vire l'oid d'origine s'il n'est pas demande */
- $dx=array_search($ooid,$oids);
- if(!($dx===FALSE)) {
- unset($oids[$dx]);
- unset($orss[$dx]);
- }
- }
- $r=array('oids'=>$oids, 'ors'=>$orss);
- return $r;
- }
- /// Rend les x derniers documents deposés dans la base documentaire
- function getLast($ar=NULL){
- $p=new XParam($ar,array('nb'=>20));
- $nb=$p->get('nb');
- $type=$p->get('type');
- $tplentry=$p->get('tplentry');
- $docs=array();
- if(empty($type)) $cond='1';
- else $cond=' DTYPE="'.$type.'"';
- $rs=selectQuery('SELECT T1.KOID FROM '.$this->id.' as T1,_TYPES WHERE '.$cond.' AND T1.DTYPE=_TYPES.KOID AND '.
- 'T1.KOID!="'.$this->rootOid().'" ORDER BY T1.UPD DESC LIMIT 0,2000');
- $idx=0;
- while($nb-- && $rs && ($ors=$rs->fetch())){
- $oid=$ors['KOID'];
- if(!$this->secure($oid, 'display')){
- $nb++;
- continue;
- }
- $d1=&XDocumentDT::objectFactory($oid,$this);
- $d1->getParents(2);
- $sort[$idx]=$d1->parents[0]->parents[0]->short.$d1->parents[0]->short.$idx;
- $docs[$idx]=$d1;
- $idx++;
- }
- $rs->closeCursor();
- array_multisort($sort,$docs);
- // Liste des types et creation de la liste de pagesize disponible
- $types=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS=_TYPES');
- $doctypes=$types->browse(array('order'=>'title','pagesize'=>100, 'tplentry'=>TZR_RETURN_DATA));
- for($i=20;$i<=100;$i+=20) $pagesize[]=$i;
- XShell::toScreen1('doctypes',$doctypes);
- XShell::toScreen2('docs','pagesize',$pagesize);
-
- if($tplentry==TZR_RETURN_DATA) return $docs;
- else XShell::toScreen2($tplentry,'docs',$docs);
- }
- /// Rend les documents qui n'ont jamais été consultés
- function getUnread($ar=NULL){
- $p=new XParam($ar,array('nb'=>20));
- $tplentry=$p->get('tplentry');
- $docs=array();
- $rs=selectQuery('select '.$this->id.'.* from '.$this->id.' left outer join _TYPES on _TYPES.KOID='.$this->id.'.DTYPE left outer join LOGS on '.$this->id.'.KOID=LOGS.object and LOGS.etype="access" and LOGS.user="'.XUser::get_current_user_uid().'" and LOGS.UPD>'.$this->id.'.UPD where _TYPES.node=2 and LOGS.KOID is null order by '.$this->id.'.UPD');
- while($rs && $ors=$rs->fetch()){
- $oid=$ors['KOID'];
- if(!$this->secure($oid,'display')) continue;
- $docs[]=&XDocumentDT::objectFactory($oid,$this);
- }
- return XShell::toScreen2($tplentry,'docs',$docs);
- }
-
- /// Marque des documents comme lu
- function markAsRead($ar=NULL){
- $p=new XParam($ar,NULL);
- $oids=$p->get('_selected');
- $selectedok=$p->get('_selectedok');
- if($selectedok!='ok' || empty($oids)) $oids=$p->get('oid');
- else $oids=array_keys($oids);
- if(!is_array($oids)) $oids=array($oids);
- foreach($oids as $i=>$oid){
- XLogs::uniqueUpdate('access',$oid);
- }
- }
- function preSubscribe($ar=NULL) {
- $p=new XParam($ar,array());
- $oid=$p->get("oid");
- $tplentry=$p->get("tplentry");
- $subdir=$p->get("subdir");
- $here=XDocumentDT::objectFactory($oid, $this);
- $here->getDocumentsDetails();
- $br['here']=$here;
- if($this->secure($here->oid, 'admin')) {
- list($acl_user, $acl_grp)=XUser::getUsersAndGroups();
- XShell::toScreen1('users',$acl_user);
- XShell::toScreen1('grps',$acl_grp);
- }
- return XShell::toScreen1($tplentry, $br);
- }
- /// Preparation de l'impression d'un document
- function prePrintDisplay($ar=NULL){
- $p=new XParam($ar,NULL);
- $oid=$p->get('oid');
- $doc=&XDocumentDT::objectFactory($oid, $this);
- $doc->repository->prePrintDisplay($ar);
- }
- /// Impression d'un document
- function printDisplay($ar=NULL){
- $p=new XParam($ar,NULL);
- $oid=$p->get('oid');
- $doc=&XDocumentDT::objectFactory($oid, $this);
- $doc->repository->printDisplay($ar);
- }
- /// Abonnement à un document
- function subscribe($ar=NULL) {
- $p=new XParam($ar,array());
- $oid=$p->get("oid");
- $subdir=$p->get("subdir");
- $uid=$p->get("uid");
- if(empty($uid)) $uid=XUser::get_current_user_uid();
- if(empty($subdir)) $subdir="0";else $subdir="1";
- $xmodsub = new XModSub(array('interactive'=>false));
- $xmodsub->addSub(array($uid), $this->_moid, $oid.';'.$subdir);
- }
- function linkTo($ar=NULL) {
- $p = new XParam($ar,array());
- $move=$p->get('_move');
- $copy=$p->get('_copy');
- $oids=array_keys($p->get('_selected'));
- $oid=$p->get('oid');
- if(empty($oids)) {
- if(!empty($oid)) $oids=array($oid);
- $parentoid=$p->get('parentoid');
- if(empty($parentoid)){
- $ors=selectQueryGetAll('SELECT KOIDDST FROM '.$this->idx.' WHERE KOIDSRC="'.$oid.'"');
- if(count($ors)==1) $parentoid=$ors[0]['KOIDDST'];
- }
- } else {
- $parentoid=$oid;
- }
- if(empty($parentoid)) $parentoid=$this->rootOid();
- $oiddst=$p->get('targetoid');
- // droits en ecriture sur la destination ... quel que soit le cas
- if (!$this->secure1($oiddst, 'edit', 1)){
- XLogs::critical(get_class($this), get_class($this).'::linkTo trying to move|copy|link to ro target '.$oiddst);
- if (!empty($oid))
- XShell::setNextData('oid', $oid);
- XShell::setNextData('message', XLabels::getSysLabel('security.default'));
- } else {
- if(!empty($move)) {
- // droits en ecriture sur le parent ... dans le cas du move
- if (!$this->secure1($parentoid, 'edit', 1)){
- XLogs::critical(get_class($this), get_class($this).'::linkTo trying to move|copy|link to ro target '.$oiddst);
- if (!empty($oid))
- XShell::setNextData('oid', $oid);
- XShell::setNextData('message', XLabels::getSysLabel('security.default'));
- } else {
- foreach($oids as $i=>$oid) {
- $notok=$this->subObjects2($oid,array(1,2));
- if(!in_array($oiddst,$notok['oids']) && $oid!=$oiddst)
- updateQuery('UPDATE '.$this->idx.' SET KOIDDST="'.$oiddst.'" WHERE KOIDSRC="'.$oid.'" AND KOIDDST="'.$parentoid.'"');
- }
- }
- } elseif(!empty($copy)) {
- foreach($oids as $i=>$oid) {
- // droits en lecture sur la source : ne se produira que pour des dossiers
- if (!$this->secure1($oid, 'display', 1)){
- XLogs::critical(get_class($this), get_class($this).'::linkTo trying to move|copy|link not readable source '.$oid);
- XShell::setNextData('message', XLabels::getSysLabel('security.default'));
- continue;
- }
- if($oid!=$oiddst){
- $this->copyTo($oid,$oiddst);
- }
- }
- } else {
- foreach($oids as $i=>$oid) {
- // droits en lecture sur la source : ne se produira que pour des dossiers
- if (!$this->secure1($oid, 'display', 1)){
- XLogs::critical(get_class($this), get_class($this).'::linkTo trying to move|copy|link not readable source '.$oid);
- XShell::setNextData('message', XLabels::getSysLabel('security.default'));
- continue;
- }
- if($oid!=$oiddst) updateQuery('INSERT INTO '.$this->idx.' SET KOIDDST="'.$oiddst.'", KOIDSRC="'.$oid.'"');
- }
- }
- }
- }
- /// Copie d'un noeud
- function copyTo($oid,$oiddst){
- // Duplication du noeud
- $doc=XDocumentDT::objectFactory($oid, $this, NULL);
- $oidres=$doc->repository->XMCduplicate(array('oid'=>$oid,'lastonly'=>false,'changeown'=>true));
- updateQuery('insert into '.$this->idx.' set KOIDSRC="'.$oidres.'", KOIDDST="'.$oiddst.'"');
- updateQuery('insert into '.$this->id.' set KOID="'.$oidres.'", DTYPE="'.$doc->tpl['oid'].'", ENDO=1, DPARAM=""');
- // Duplication des fils
- $subobj=$this->subObjects3($oid);
- foreach($subobj['ors'] as $oiddoc=>$ors) $this->copyTo($oiddoc,$oidres);
- }
- protected function _lasttimestamp() {
- $rs=selectQueryByNum('select MAX(UPD) from '.$this->id);
- if($ors=$rs->fetch()) {
- $rs->closeCursor();
- return $ors[0];
- }
- return 0;
- }
- protected function _whatsNew($ts,$user, $group=NULL, $specs=NULL,$timestamp=NULL) {
- list($koid,$subdir) = explode(';',$specs);
- if($subdir) {
- $subobjects=$this->subobjects1($koid,10);
- $oids=$subobjects[1];
- } else {
- $oids=array($koid);
- }
- $condoid=join('","',$oids);
- $rs=selectQuery('select * from '.$this->id.','.$this->idx.' where UPD>="'.$ts.'" and UPD<"'.$timestamp.'" '.
- 'and KOID=KOIDSRC and (KOIDDST IN ("'.$condoid.'") OR KOIDSRC="'.$koid.'")');
- $txt='';
- while($rs && ($ors=$rs->fetch())) {
- $oid=$ors['KOID'];
- $d2=&XDocumentDT::objectFactory($oid,$this);
- if(!$this->secure($d2->oid,'display')) continue;
- $url=$GLOBALS['TZR_SESSION_MANAGER']::admin_url(true,false).'&moid='.$this->_moid.'&function=goto1&oid='.$oid.'&tplentry=br&template=xmoddocmgt/display.html&_direct=1';
- $d1=&$d2->fields;
- if(is_array($d1) && ($d1['lst_upd']['user']!=$user)) {
- $when=$d1['oUPD']->raw;
- $who=$d1['lst_upd']['usernam'];
- $txt.='<li><a href="'.$url.'">'.$d2->title.'</a> ('.$when.', '.$who.')</li>';
- }
- }
- return $txt;
- }
- // rend une chaine qui représente l'abonnement
- //
- function _getSubTitle($oid) {
- $rs=selectQuery("select * from OPTS where KOID='$oid'");
- if($rs && ($ors=$rs->fetch())) {
- list($koid,$subdir)=explode(';',$ors['specs']);
- if(Kernel::objectExists($koid)) {
- $d1=&XDocumentDT::objectFactory($koid,$this);
- $d1->getParents(10);
- $path='';
- foreach($d1->parents as &$doc) {
- $path.=$doc->title.' > ';
- }
- $url=$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&moid='.$this->_moid.'&_function=goto1&oid='.$koid.'&tplentry=br';
- if(!empty($subdir)) {
- $subdir=' et sous dossiers';
- } else $subdir='';
- return XLabels::getSysLabel('xmoddocmgt','defaultsdir').' <A HREF="'.$url.'">'.$path.$d1->title.'</A> '.$subdir;
- } else {
- // l'abonnement concerne une donnee qui n'existe plus. on le supprimer
- updateQuery("delete from OPTS where KOID='$oid'");
- }
- }
- return NULL;
- }
- function &getTasklet() {
- // recherche de tous les documents qui ont été verrouillés et qui sont en attente
- $now=date("YmdHis",time());
- $rs=selectQuery('select * from '.$this->id.',_LOCKS WHERE '.$this->id.'.KOID=_LOCKS.KOID AND '.
- '_LOCKS.OWN="'.XUser::get_current_user_uid().'" AND _LOCKS.DEND<"'.$now.'" order by _LOCKS.DSTART ASC');
- $lines=array();
- $users=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.'USERS');
- $i=0;
- $txt='';
- while($ors=$rs->fetch()) {
- $oid=$ors['KOID'];
- $t=XDocumentDT::objectFactory($oid,$this);
- if($this->secure($t->oid, 'display')) {
- $url=$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&moid='.$this->_moid.'&_function=goto1&oid='.$oid.'&tplentry=br';
- $txt.='<p>'.$t->smallicon.' <a href="'.$url.'">'.$t->short.'</A> réservé le '.XDateTimeDef::dateFormat($t->fields['_lock']['DSTART']).' jusqu\'au '.XDateTimeDef::dateFormat($t->fields['_lock']['DEND']).'</p>';
- }
- }
- if(!empty($txt)) $txt='<h2>Vos réservations de documents en cours</h2><div>'.$txt.'</div>';
- return $txt;
- }
- function chk($message) {
- // OID,OID type,Nom type,Nom dossier,OID destination,Module,Node type
- $idtocheck=array(array($this->defaultFolderTable.':root-'.$this->_moid,'_TYPES:root-'.$this->_moid,'Root','Dossiers',NULL,$this->_moid,1));
- /*
- array($this->defaultFolderTable.':lostandfound','_TYPES:lostandfound','Lost and found','Perdus ou retrouvés', $rootoid),
- array($this->defaultFolderTable.':trash','_TYPES:trash','Trash','Poubelle',$rootoid),
- array($this->defaultFolderTable.':archives','_TYPES:archives','Archives','Archives',$rootoid));
- */
- foreach($idtocheck as $idsbis) {
- $rootid=$idsbis[0];
- $roottemplateid=$idsbis[1];
- if($rootid){
- // Creation dans $this->id
- $cnt=countSelectQuery('SELECT COUNT(*) FROM '.$this->id.' WHERE KOID="'.$rootid.'"');
- if(!$cnt) {
- updateQuery('INSERT INTO '.$this->id.' SET KOID="'.$rootid.'", DTYPE="'.$roottemplateid.'", ENDO=0, UPD=NULL');
- }
- // Création dans la table des repertoires
- $cnt=countSelectQuery('SELECT COUNT(*) FROM '.$this->defaultFolderTable.' WHERE KOID="'.$rootid.'"');
- if(!$cnt) {
- updateQuery('INSERT INTO '.$this->defaultFolderTable.' SET KOID="'.$rootid.'", UPD=NULL, LANG="'.TZR_DEFAULT_LANG.'",'.
- 'title="'.$idsbis[3].'"');
- }
- }
- // Création type
- $cnt=countSelectQuery('SELECT COUNT(*) FROM _TYPES WHERE KOID="'.$roottemplateid.'"');
- if(!$cnt) {
- updateQuery('INSERT INTO _TYPES SET KOID="'.$roottemplateid.'", LANG="'.TZR_DEFAULT_LANG.'", modid="'.$idsbis[5].'",'.
- 'UPD=NULL, dtab="'.$this->defaultFolderTable.'", node='.$idsbis[6].', title="'.$idsbis[2].'"');
- }
- // Création dans $this->idx
- if(!empty($idsbis[4])) {
- $cnt=countSelectQuery('SELECT COUNT(*) FROM '.$this->idx.' WHERE KOIDSRC="'.$rootid.'"');
- if(!$cnt) {
- updateQuery('INSERT INTO '.$this->idx.' SET KOIDSRC="'.$rootid.'", '.
- 'KOIDDST="'.$idsbis[4].'"');
- }
- }
- }
- updateQuery('update '.$this->idx.' set KOIDDST="'.$this->rootOid().'" where KOIDDST is NULL or KOIDDST=""');
- updateQuery('update '.$this->idx.' set KOIDDST="'.$this->rootOid().'" where KOIDDST ="'.$this->defaultFolderTable.':0"');
- return true;
- }
- /// recherche fils de niveau d'accès demandé, parent supposé accessible
- /// parcours de toute l'arborescence pour l'élaguer en plaçant des règles dans le cache des acl
- public function hasSubObject($oid, $levels=99, $user=null, $right=':ro') {
- if(empty($oid)) $oid=$this->rootOid();
- $open=array($oid);
- $node=array(1);
- $level=array(1);
- $ooid=$oid;
- $done=array(); /* liste des noeuds examines pour ne pas repasser dessus */
- $return = false;
- $this->adjacence = selectQuery('SELECT DISTINCT KOIDDST,KOIDDST,KOIDSRC,node,DTYPE FROM '.$this->idx.','.$this->id.',_TYPES '.
- 'WHERE '.$this->id.'.KOID=KOIDSRC AND '.$this->id.'.DTYPE=_TYPES.KOID')->fetchAll(PDO::FETCH_GROUP);
- while(!empty($open)) {
- $oid=array_pop($open);
- $n=array_pop($node);
- $l=array_pop($level);
- $done[]=$oid;
- $acls[$oid] = array(
- $right => XUser::secure8oid($right, $this, $oid, $user, null, true),
- ':rw' => XUser::secure8oid(':rw', $this, $oid, $user, null, true),
- );
- if($n==1 && $l<$levels && XUser::secure8oid('index', $this, $oid, $user, null, true)) {
- $acls[$oid]['index'] = true;
- foreach($this->adjacence[$oid] as $ors) {
- $childOid=$ors['KOIDSRC'];
- $this->_f1[$childOid][] = $oid; // _f1 cache des parents
- if(!in_array($childOid,$done) && !in_array($childOid,$open)){
- $open[]=$childOid;
- $node[]=$ors['node'];
- $level[]=$l+1;
- }
- }
- }
- }
- $acls = $this->_acls($ooid, $acls, $right);
- foreach ($acls as $oid => $acl) {
- $return |= $acl['visible'];
- if (!$acl['visible'] && !$acl[$right] && !$acl[':rw']) {
- $need = false;
- foreach ($this->_f1[$oid] as $parentOid) // si un parent est visible, on a besoin de la règle
- $need |= $acls[$parentOid]['visible'];
- if ($need) {
- XUser::setCache(null, 'index', null, $this->_moid, $oid, 0, 'hasSubObject', 'none');
- XUser::setCache(null, ':list', null, $this->_moid, $oid, 0, 'hasSubObject', 'none');
- }
- }
- }
- return $return;
- }
-
- /// calcul la visibilité
- private function _acls($oid, $acls, $right) {
- foreach ($this->adjacence[$oid] as $node) {
- $nodeoid = $node['KOIDSRC'];
- if ($node['node'] == 1 && !isset($acls[$nodeoid]['visible']))
- $acls = $this->_acls($nodeoid, $acls, $right);
- // visible si un fils visible ou lecture ou plus
- $acls[$oid]['visible'] |= ($acls[$nodeoid][$right] || $acls[$nodeoid][':rw']
- || $acls[$nodeoid]['visible']);
- }
- return $acls;
- }
- // Alias de secure pour garder la compatibilité d'avant la refonte de droits
- function secure1($oid, $function, $node=0, &$user=NULL) {
- return parent::secure($oid,$function,$user);
- }
- /// ok si accessible et non vide (cas des dossier)
- function secureNotEmpty($oid, $function, $user=null, $lang=TZR_DEFAULT_LANG) {
- if (XShell::isRoot())
- return true;
- return $this->hasSubObject($oid, 99, $user, ':ro');
- }
- /// Définit si la sécurité sur les objets est activé
- public function objectSecurityEnabled(){
- if($this->object_sec || $this->documentssec) return true;
- return false;
- }
- /// Définit si le cache des droits doit être activé ou pas.
- public function rightCacheEnabled(){
- return $this->objectSecurityEnabled();
- }
- /// Retourne le parent direct de chaque oid passé en paramètre
- public function getParentsOids($oids){
- $ret=array();
- foreach($oids as $oid){
- if(!$oid) continue;
- $parents=$this->father1($oid);
- if(!$parents) $ret[]='';
- else $ret=array_merge($ret,$parents);
- }
- return $ret;
- }
- // telechargement dans un zip d'un ensembl de documents
- function documentsDownload($ar=NULL) {
- $p=new XParam($ar,array());
- $selected=$p->get('_selected');
- if(empty($selected)) $selected=array($p->get('oid')=>1);
- $dir=TZR_TMP_DIR.'download-'.uniqid();
- @mkdir($dir);
- $nbfiles=0;
- foreach($selected as $koid=>$foo) {
- $doc=&XDocumentDT::objectFactory($koid, $this);
- $details=$doc->getFilesDetails();
- $asciify=rewriteToAscii($doc->title);
- $path=$dir.'/'.$asciify;
- @mkdir($path);
- foreach($details as &$e) {
- copy($e['filename'], $path.'/'.$e['name']);
- $nbfiles++;
- }
- }
- exec('(cd '.$dir.';zip -r '.$dir.'.zip .)2>&1 > '.TZR_TMP_DIR.'errorlog');
- $size=filesize($dir.'.zip');
- header('Content-type: application/zip');
- header('Content-disposition: attachment; filename=download.zip');
- header('Accept-Ranges: bytes');
- header('Content-Length: '.$size);
- @readfile($dir.'.zip');
- XDir::unlink($dir);
- unlink($dir.'.zip');
- exit(0);
- }
- function &portlet2() {
- $txt ='<h1>'.$this->modulename.'</h1>';
- $txt.='<p><form action="'.$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'" method="post" onsubmit="return TZR.ajaxSubmitForm(this,\'#cv8-content\');">';
- $txt.='<input type="hidden" name="moid" value="'.$this->_moid.'">';
- $txt.='<input type="hidden" name="function" value="search">';
- $txt.='<input type="hidden" name="template" value="xmoddocmgt/query2.html">';
- $txt.='<input type="hidden" name="tplentry" value="br">';
- $txt.='<input type="text" name="query">';
- $txt.='<input type="submit" value="'.XLabels::getSysLabel('xmoddocmgt','search','text').'">';
- $txt.='</form></p>';
- return $txt;
- }
- function &export($ar=NULL) {
- $p=new XParam($ar, array());
- $o['ftphost']=$p->get('ftphost');
- $o['ftpuser']=$p->get('ftpuser');
- $o['ftppass']=$p->get('ftppass');
- $o['ftproot']=$p->get('ftproot');
- $o['oid']=$p->get('oid');
- $o['function']='exportBatch';
- $scheduler= new XModScheduler(array('tplentry'=>TZR_RETURN_DATA));
- $roid=$scheduler->createJob($this->_moid, NULL,'Export XModDoc',$o,'', NULL, NULL);
- XShell::toScreen2('br','message','L\'export de données a été programmé et sera rapidement disponible');
- }
- function exportBatch(XModScheduler &$scheduler, &$o, &$more) {
- $ftphost=$more->ftphost;
- $ftpuser=$more->ftpuser;
- $ftppass=$more->ftppass;
- $ftproot=$more->ftproot;
- $oid=$more->oid;
- $this->exportFTP(array('ftphost'=>$ftphost, 'ftpuser'=>$ftpuser, 'ftppass'=>$ftppass, 'ftproot'=>$ftproot,
- 'oid'=>$oid,'tplentry'=>TZR_RETURN_DATA));
- }
- function &exportFTP($ar=NULL) {
- $p=new XParam($ar, array());
- $ftphost = $p->get('ftphost');
- $ftpuser = $p->get('ftpuser');
- $ftppass = $p->get('ftppass');
- $ftproot = $p->get('ftproot');
- $oid = $p->get('oid');
- if(empty($oid)) $oid=$this->rootOid();
- $ftphost=str_replace('ftp://','',$ftphost);
- $conn_id = ftp_connect($ftphost);
- if (!$conn_id) return 'Unable to connect to '.$ftphost;
- $login_result = ftp_login($conn_id, $ftpuser, $ftppass);
- if(!$login_result) return 'Error logging into '.$ftphost;
- if(!empty($ftproot)) {
- ftp_mkdir($conn_id, $ftproot);
- ftp_chdir($conn_id, $ftproot);
- }
- $this->exportFTP1($conn_id, $oid);
- ftp_close($conn_id);
- }
- function &exportFTP1(&$conn_id, $oid) {
- $br=$this->index(array('tplentry'=>TZR_RETURN_DATA, 'oid'=>$oid));
- $node=&$br['here'];
- $title=$node->title;
- $title=cleanFilename($title);
- ftp_mkdir($conn_id, $title);
- ftp_chdir($conn_id, $title);
- foreach($node->dirsoids as $i=>$oid1) {
- $this->exportFTP1($conn_id, $oid1);
- }
- foreach($node->docsoids as $i=>$oid1) {
- $this->exportFTP2($conn_id, $oid1);
- }
- ftp_cdup($conn_id);
- }
- /// export d'un document de type document
- function &exportFTP2(&$conn_id, $oid) {
- $node=&XDocumentDT::objectFactory($oid, $this);
- $details=$node->getFilesDetails();
- $asciify=rewriteToAscii($node->title);
- $dir=TZR_TMP_DIR.'download-'.uniqid();
- @mkdir($dir);
- $path=$dir.'/'.$asciify;
- @mkdir($path);
- $xt = new XTemplate(TZR_SHARE_DIR.'xmoddocmgt/template-display.txt');
- $tpldata['br']=&$node->repository->XMCdisplay(array('oid'=>$oid, 'tplentry'=>TZR_RETURN_DATA));
- $r3=array();
- $notice=$xt->parse($tpldata,$r3,NULL);
- foreach($details as &$e) {
- copy($e['filename'], $path.'/'.$e['name']);
- $nbfiles++;
- }
- file_put_contents($path.'/notice.txt', $notice);
- exec('(cd '.$dir.';zip -r '.$dir.'.zip .)2>&1 > '.TZR_TMP_DIR.'errorlog');
- ftp_put ($conn_id, $asciify.'.zip', $dir.'.zip', FTP_BINARY);
- XDir::unlink($dir);
- unlink($dir.'.zip');
- }
- /// liste des tables utilisees par ce module
- function tablesToTrack() {
- $rs=selectQuery('SELECT distinct dtab FROM _TYPES');
- $res=array();
- while($rs && $ors=$rs->fetch()) {
- if(!empty($ors['dtab'])) $res[]=$ors['dtab'];
- }
- return $res;
- }
- /// Recupere des infos sur le module : nom (modulename), nombre d'enregistrement (cnt), espace occupé (size)
- function getInfos($ar=NULL){
- $p=new XParam($ar,array('tplentry'=>TZR_RETURN_DATA));
- $tplentry=$p->get('tplentry');
- $ar['tplentry']=TZR_RETURN_DATA;
- $ret=parent::getInfos($ar);
- // Nombre de documents
- $ret['infos']['cnt']=(object)array('label'=>XLabels::getSysLabel('xmoddocmgt','docs','text'),
- 'html'=>$ret['cnt']=countSelectQuery('select count(*) from '.$this->id));
- // Espace occupé
- $tabs=$this->usedMainTables();
- $tot=0;
- foreach($tabs as $t){
- $s=XDbIni::get('xmodadmin:workspacesize_'.$t,'val');
- if($s===NULL){
- $tot=NULL;
- continue;
- }
- $tot+=$s*1024;
- }
- $ret['infos']['size']->label=XLabels::getSysLabel('xmodule','workspace','text');
- if($tot!==NULL){
- $ret['size'] = $tot;
- $ret['infos']['size']->html=getStringBytes($ret['size']);
- }
- else $ret['infos']['size']->html=XLabels::getSysLabel('xmodule','infonotcalculate','text');
- return XShell::toScreen1($tplentry,$ret);
- }
- }
- ?>