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