ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilObjectDAV.php
Go to the documentation of this file.
1 <?php
2 // BEGIN WebDAV
3 /*
4  +-----------------------------------------------------------------------------+
5  | ILIAS open source |
6  +-----------------------------------------------------------------------------+
7  | Copyright (c) 1998-2005 ILIAS open source, University of Cologne |
8  | |
9  | This program is free software; you can redistribute it and/or |
10  | modify it under the terms of the GNU General Public License |
11  | as published by the Free Software Foundation; either version 2 |
12  | of the License, or (at your option) any later version. |
13  | |
14  | This program is distributed in the hope that it will be useful, |
15  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17  | GNU General Public License for more details. |
18  | |
19  | You should have received a copy of the GNU General Public License |
20  | along with this program; if not, write to the Free Software |
21  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22  +-----------------------------------------------------------------------------+
23 */
24 
38 {
42  var $refId;
43 
47  var $obj;
48 
53  var $isDebug = false;
54 
60  function __construct($refId, $obj = null)
61  {
62  if (is_object($obj))
63  {
64  $this->writelog('<constructor>('.$refId.','.get_class($obj).')');
65  }
66  $this->refId = $refId;
67  $this->obj =& $obj;
68  }
69 
70 
75  function getRefId()
76  {
77  return $this->refId;
78  }
83  function getObjectId()
84  {
85  return ($this->obj == null) ? null : $this->obj->getId();
86  }
87 
94  function getNodeId()
95  {
96  return 0;
97  }
98 
105  function initFromNull()
106  {
107  $this->obj->setPermissions($this->getRefId());
108  }
109 
110 
111 
112 
117  function read()
118  {
119  global $DIC;
120  $ilias = $DIC['ilias'];
121 
122  if (is_null($this->obj))
123  {
124  $this->obj =& $ilias->obj_factory->getInstanceByRefId($this->getRefId());
125  $this->obj->read();
126  }
127  }
132  function write()
133  {
134  $this->writelog('write() refid='.$this->refId);
135  $this->obj->update();
136  }
137 
138 
144  function getResourceName()
145  {
146  return $this->obj->getUntranslatedTitle();
147  }
153  function setResourceName($name)
154  {
155  $this->writelog('setResourceName('.$name.')');
156  return $this->obj->setTitle($name);
157  }
163  function getDisplayName()
164  {
165  return $this->obj->getTitle();
166  }
167 
174  {
175  return strtotime($this->obj->getCreateDate());
176  }
177 
184  {
185  return strtotime($this->obj->getLastUpdateDate());
186  }
187 
193  function getResourceType()
194  {
195  return "";
196  }
197 
203  function isCollection()
204  {
205  return $this->getResourceType() == 'collection';
206  }
212  function isFile()
213  {
214  return $this->getResourceType() == '';
215  }
220  function isNullResource()
221  {
222  return $this->getResourceType() == 'null';
223  }
224 
229  function getContentType()
230  {
231  return 'application/x-non-readable';//'application/octet-stream';
232  }
237  function setContentType($type)
238  {
239  // subclass responsibility
240  }
245  function setContentLength($length)
246  {
247  // subclass responsibility
248  }
253  function getContentLength()
254  {
255  return 0;
256  }
261  function getContentStream()
262  {
263  return null;
264  }
270  {
271  return null;
272  }
283  {
284  // subclass responsibility
285  }
291  function getContentData()
292  {
293  return null;
294  }
295 
299  function isOnline()
300  {
301  return true;
302  }
303 
314  function isPermitted($operations, $type = '')
315  {
316  // Mount instructions are always visible
317  if(isset($_GET['mount-instructions']))
318  {
319  return true;
320  }
321 
322  // The 'visible' operation is only permitted if the object is online,
323  // or if the user is also permitted the perform the 'write' operation.
324  if (false) // old implementation deactivated
325  {
326  $ops = explode(',',$operations);
327  if (in_array('visible',$ops) && ! in_array('write',$ops))
328  {
329  if (! $this->isOnline()) {
330  $operations .= ',write';
331  }
332  }
333 
334  global $DIC;
335  $rbacsystem = $DIC['rbacsystem'];
336  return $rbacsystem->checkAccess($operations, $this->getRefId(), $type);
337  }
338  else // this one fixes bug #5367
339  {
340  $GLOBALS['DIC']['ilLog']->write('Checking permission for ref_id: '.$this->getRefId());
341  $GLOBALS['DIC']['ilLog']->write("Operations: ".print_r($operations,true));
342 
343  global $DIC;
344  $ilAccess = $DIC['ilAccess'];
345  $operations = explode(",",$operations."");
346  foreach ($operations as $operation)
347  {
348  if (!$ilAccess->checkAccess($operation, '', $this->getRefId(), $type))
349  {
350  $GLOBALS['DIC']['ilLog']->write(__METHOD__.': Permission denied for user '.$GLOBALS['DIC']['ilUser']->getId());
351  return false;
352  }
353  }
354  return true;
355  }
356  }
357 
361  function getILIASType()
362  {
363  if($this->obj instanceof ilObject)
364  {
365  return $this->obj->getType();
366  }
367  $GLOBALS['DIC']['ilLog']->write(__METHOD__.': Invalid object given, class='.get_class($this->obj));
368  $GLOBALS['DIC']['ilLog']->logStack();
369  }
374  {
375  return 'fold';
376  }
380  function getILIASFileType()
381  {
382  return 'file';
383  }
384 
389  function createNewVersion() {
390  }
391 
392 
399  function createCollection($name)
400  {
401  global $DIC;
402  $tree = $DIC['tree'];
403 
404  // create and insert Folder in tree
405  require_once 'Modules/Folder/classes/class.ilObjFolder.php';
406  $newObj = new ilObjFolder(0);
407  $newObj->setType($this->getILIASCollectionType());
408  $newObj->setTitle($name);
409  //$newObj->setDescription('');
410  $newObj->create();
411  $newObj->createReference();
412  $newObj->setPermissions($this->getRefId());
413  $newObj->putInTree($this->getRefId());
414 
415  require_once 'class.ilObjFolderDAV.php';
416  return new ilObjFolderDAV($newObj->getRefId(), $newObj);
417  }
424  function createFile($name)
425  {
426  global $DIC;
427  $tree = $DIC['tree'];
428 
429  // create and insert Folder in tree
430  require_once 'Modules/File/classes/class.ilObjFile.php';
431  $newObj = new ilObjFile(0);
432  $newObj->setType($this->getILIASFileType());
433  $newObj->setTitle($name);
434  $newObj->setFileName($name);
435  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
436  $mime = ilMimeTypeUtil::getMimeType("", $name, 'application/octet-stream');
437  //$newObj->setFileType('application/octet-stream');
438  $newObj->setFileType($mime);
439  //$newObj->setDescription('');
440  $newObj->create();
441  $newObj->createReference();
442  $newObj->setPermissions($this->getRefId());
443  $newObj->putInTree($this->getRefId());
444  //$newObj->createDirectory();
445 
446  require_once 'class.ilObjFileDAV.php';
447  $objDAV = new ilObjFileDAV($newObj->getRefId(), $newObj);
448  /*
449  $fs = $objDAV->getContentOutputStream();
450  fwrite($fs,' ');
451  fclose($fs);
452  */
453  return $objDAV;
454  }
461  function createFileFromNull($name, &$nullDAV)
462  {
463  global $DIC;
464  $tree = $DIC['tree'];
465 
466  // create and insert Folder in tree
467  require_once 'Modules/File/classes/class.ilObjFile.php';
468  $objDAV =& $nullDAV->convertToILIASType($this->getRefId(), $this->getILIASFileType());
469  $objDAV->initFromNull();
470  return $objDAV;
471  }
479  function createNull($name)
480  {
481  global $DIC;
482  $tree = $DIC['tree'];
483 
484  // create and insert Folder in tree
485  require_once './Services/Object/classes/class.ilObject.php';
486  $newObj = new ilObject(0);
487  $newObj->setType('null');
488  $newObj->setTitle($name);
489  $newObj->create();
490  $newObj->createReference();
491  $newObj->setPermissions($this->getRefId());
492  $newObj->putInTree($this->getRefId());
493 
494  require_once 'class.ilObjNullDAV.php';
495  $objDAV = new ilObjNullDAV($newObj->getRefId(), $newObj);
496 
497  return $objDAV;
498  }
499 
500 
501 
507  function remove($objDAV)
508  {
509  global $DIC;
510  $tree = $DIC['tree'];
511  $rbacadmin = $DIC['rbacadmin'];
512 
513  $subnodes = $tree->getSubTree($tree->getNodeData($objDAV->getRefId()));
514  foreach ($subnodes as $node)
515  {
516  $rbacadmin->revokePermission($node["child"]);
517  $affectedUsers = ilUtil::removeItemFromDesktops($node["child"]);
518  }
519  $tree->saveSubTree($objDAV->getRefId());
520  $tree->deleteTree($tree->getNodeData($objDAV->getRefId()));
521  }
522 
530  function addCopy(&$objDAV, $newName = null)
531  {
532  $this->writelog("addCopy($objDAV,$newName) ....");
533  global $DIC;
534  $rbacadmin = $DIC['rbacadmin'];
535  $tree = $DIC['tree'];
536  $revIdMapping = array();
537  $newRef = $this->cloneNodes($objDAV->getRefId(),$this->getRefId(),$revIdMapping, $newName);
538  //$rbacadmin->adjustMovedObjectPermissions($newRef, $tree->getParentId($objDAV->getRefId()));
539  return self::createObject($newRef, $objDAV->getILIASType());
540  $this->writelog('... addCopy done.');
541  }
542 
553  function cloneNodes($srcRef,$dstRef,&$mapping, $newName=null)
554  {
555  $this->writelog("cloneNodes($srcRef,$dstRef,$mapping,$newName)");
556  global $DIC;
557  $tree = $DIC['tree'];
558  global $DIC;
559  $ilias = $DIC['ilias'];
560 
561  // clone the source node
562  $srcObj =& $ilias->obj_factory->getInstanceByRefId($srcRef);
563  $this->writelog('cloneNodes cloning srcRef='.$srcRef.' dstRef='.$dstRef.'...');
564  $newObj = $srcObj->cloneObject($dstRef);
565  $newRef = $newObj->getRefId();
566 
567  // We must immediately apply a new name to the object, to
568  // prevent confusion of WebDAV clients about having two objects with identical
569  // name in the repository.
570  $this->writelog("cloneNodes newname not null? ".(! is_null($newName)));
571  if (! is_null($newName))
572  {
573  $newObjDAV = self::createObject($newRef, $srcObj->getType());
574  $newObjDAV->setResourceName($newName);
575  $newObjDAV->write();
576  }
577  unset($srcObj);
578  $mapping[$newRef] = $srcRef;
579 
580  // clone all children of the source node
581  $children = $tree->getChilds($srcRef);
582  foreach ($tree->getChilds($srcRef) as $child)
583  {
584  // Don't clone role folders, because it does not make sense to clone local roles
585  // FIXME - Maybe it does make sense (?)
586  if ($child["type"] != 'rolf')
587  {
588  $this->cloneNodes($child["ref_id"],$newRef,$mapping,null);
589  }
590  else
591  {
592  if (count($rolf = $tree->getChildsByType($newRef,"rolf")))
593  {
594  $mapping[$rolf[0]["ref_id"]] = $child["ref_id"];
595  }
596  }
597  }
598  $this->writelog('cloneNodes ...cloned srcRef='.$srcRef.' dstRef='.$dstRef.' newRef='.$newRef);
599  return $newRef;
600  }
601 
609  function addMove(&$objDAV, $newName = null)
610  {
611  global $DIC;
612  $tree = $DIC['tree'];
613  global $DIC;
614  $rbacadmin = $DIC['rbacadmin'];
615  global $DIC;
616  $ilias = $DIC['ilias'];
617  global $DIC;
618  $log = $DIC['log'];
619 
620  $this->writelog('addMove('.$objDAV->getRefId().' to '.$this->getRefId().', newName='.$newName.')');
621 
622  // Step 0:Assign new name to moved object
623  if (! is_null($newName))
624  {
625  $objDAV->setResourceName($newName);
626  $objDAV->write();
627  }
628 
629  // Step 1: Store old parent
630  $old_parent = $tree->getParentId($objDAV->getRefId());
631 
632  // Step 2: Move the tree
633  $tree->moveTree($objDAV->getRefId(),$this->getRefId());
634 
635  // Step 3: Repair permissions
636  $rbacadmin->adjustMovedObjectPermissions($objDAV->getRefId(), $old_parent);
637 
638  /*
639  // STEP 1: Move subtree to trash
640  $this->writelog('addMove('.$objDAV->getRefId().' to '.$this->getRefId().') step 1: move subtree to trash');
641  $subnodes = $tree->getSubTree($tree->getNodeData($objDAV->getRefId()));
642  foreach ($subnodes as $node)
643  {
644  $rbacadmin->revokePermission($node["child"]);
645  $affectedUsers = ilUtil::removeItemFromDesktops($node["child"]);
646  }
647  $tree->saveSubTree($objDAV->getRefId());
648  $tree->deleteTree($tree->getNodeData($objDAV->getRefId()));
649 
650  // STEP 2: Move subtree to new location
651  // TODO: this whole put in place again stuff needs revision. Permission settings get lost.
652  $this->writelog('addMove() step 2: move subtree to new location');
653  // put top node to dest
654  $rbacadmin->revokePermission($subnodes[0]['child']);
655  $obj_data =& $ilias->obj_factory->getInstanceByRefId($subnodes[0]['child']);
656  $obj_data->putInTree($this->getRefId());
657  $obj_data->setPermissions($this->getRefId());
658  array_shift($subnodes);
659 
660  // put all sub nodes to their parent (of which we have moved top already to dest).
661  foreach ($subnodes as $node)
662  {
663  $rbacadmin->revokePermission($node['child']);
664  $obj_data =& $ilias->obj_factory->getInstanceByRefId($node['child']);
665  $obj_data->putInTree($node['parent']);
666  $obj_data->setPermissions($node['parent']);
667  }
668 
669  // STEP 3: Remove trashed objects from system
670  $this->writelog('addMove('.$objDAV->getRefID().') step 3: remove trashed objects from system');
671  require_once 'Services/Tree/classes/class.ilTree.php';
672  $trashTree = new ilTree(- (int) $objDAV->getRefId());
673  $node = $trashTree->getNodeData($objDAV->getRefId());
674  $subnodes = $trashTree->getSubTree($node);
675 
676  // remember already checked deleted node_ids
677  $checked[] = -(int) $objDAV->getRefId();
678 
679  // dive in recursive manner in each already deleted subtrees and remove these objects too
680  $this->removeDeletedNodes($objDAV->getRefId(), $checked, false);
681 
682  // delete trash tree
683  $tree->deleteTree($node);
684  $this->writelog('addMove('.$objDAV->getRefID().') all 3 steps done');
685  */
686  }
687 
696  function removeDeletedNodes($a_node_id, $a_checked, $a_delete_objects = true)
697  {
698  global $DIC;
699  $ilDB = $DIC['ilDB'];
700  $log = $DIC['log'];
701  $ilias = $DIC['ilias'];
702  $tree = $DIC['tree'];
703 
704  $query = "SELECT tree FROM tree WHERE parent = ? AND tree < 0 ";
705  $sta = $ilDB->prepare($query,array('integer','integer'));
706  $res = $ilDB->execute($sta,array(
707  $a_node_id,
708  0));
709 
710 
711  while($row = $ilDB->fetchObject($res))
712  {
713  // only continue recursion if fetched node wasn't touched already!
714  if (!in_array($row->tree,$a_checked))
715  {
716  $deleted_tree = new ilTree($row->tree);
717  $a_checked[] = $row->tree;
718 
719  $row->tree = $row->tree * (-1);
720  $del_node_data = $deleted_tree->getNodeData($row->tree);
721  $del_subtree_nodes = $deleted_tree->getSubTree($del_node_data);
722 
723  $this->removeDeletedNodes($row->tree,$a_checked);
724 
725  if ($a_delete_objects)
726  {
727  foreach ($del_subtree_nodes as $node)
728  {
729  $node_obj =& $ilias->obj_factory->getInstanceByRefId($node["ref_id"]);
730 
731  // write log entry
732  /*$this->writelog("removeDeletedNodes(), delete obj_id: ".$node_obj->getId().
733  ", ref_id: ".$node_obj->getRefId().", type: ".$node_obj->getType().", ".
734  "title: ".$node_obj->getTitle());
735  */
736  $node_obj->delete();
737  }
738  }
739 
740  $tree->deleteTree($del_node_data);
741 
742  // write log entry
743  //$this->writelog("removeDeletedNodes(), deleted tree, tree_id: ".$del_node_data["tree"].", child: ".$del_node_data["child"]);
744  }
745  }
746 
747  return true;
748  }
755  function children()
756  {
757  // FIXME: Remove duplicate entries from this list, because of RFC2518, chapter 5.2
758  // If a duplicate is found, the older object must win. We use the object
759  // id to determine this. This is based on the assumption, that new objects
760  // have higher object id's then older objects.
761 
762  global $DIC;
763  $tree = $DIC['tree'];
764 
765  $childrenDAV = array();
766  // Performance optimization. We sort the children using PHP instead of using the database.
767  //$childrenData =& $tree->getChilds($this->getRefId(),'title');
768  $childrenData =& $tree->getChilds($this->getRefId(),'');
769  foreach ($childrenData as $data)
770  {
771  $childDAV =& self::createObject($data['ref_id'],$data['type']);
772  if (! is_null($childDAV))
773  {
774  // Note: We must not assign with =& here, because this will cause trouble
775  // when other functions attempt to work with the $childrenDAV array.
776  $childrenDAV[] = $childDAV;
777  }
778 
779  }
780  return $childrenDAV;
781  }
791  function childrenWithPermission($operations, $type ='')
792  {
793  //$this->writelog('@'.$this->getRefId().'.childrenWithPermission('.$operations.','.$type.')');
794  $childrenDAV = $this->children();
795  $permittedChildrenDAV = array();
796  foreach ($childrenDAV as $childDAV)
797  {
798  if ($childDAV->isPermitted($operations, $type))
799  {
800  $permittedChildrenDAV[] = $childDAV;
801  }
802 
803  }
804  //$this->writelog('@'.$this->getRefId().'.childrenWithPermission():'.count($permittedChildrenDAV).' children');
805  return $permittedChildrenDAV;
806  }
807 
816  public static function createObject($refId, $type)
817  {
818  $newObj = null;
819 
820  switch ($type)
821  {
822  case 'mountPoint' :
823  require_once 'class.ilObjMountPointDAV.php';
824  $newObj = new ilObjMountPointDAV($refId,null);
825  break;
826  case 'root' :
827  require_once 'class.ilObjRootDAV.php';
828  $newObj = new ilObjRootDAV($refId,null);
829  break;
830  case 'cat' :
831  require_once 'class.ilObjCategoryDAV.php';
832  $newObj = new ilObjCategoryDAV($refId,null);
833  break;
834  case 'fold' :
835  require_once 'class.ilObjFolderDAV.php';
836  $newObj = new ilObjFolderDAV($refId,null);
837  break;
838  case 'crs' :
839  require_once 'class.ilObjCourseDAV.php';
840  $newObj = new ilObjCourseDAV($refId,null);
841  break;
842  case 'grp' :
843  require_once 'class.ilObjGroupDAV.php';
844  $newObj = new ilObjGroupDAV($refId,null);
845  break;
846  case 'file' :
847  require_once 'class.ilObjFileDAV.php';
848  $newObj = new ilObjFileDAV($refId,null);
849  break;
850  case 'null' :
851  require_once 'class.ilObjNullDAV.php';
852  $newObj = new ilObjNullDAV($refId,null);
853  break;
854  default :
855  break;
856  }
857  if (! is_null($newObj))
858  {
859  $newObj->read();
860  }
861  return $newObj;
862  }
869  function writelog($message)
870  {
871  if ($this->isDebug)
872  {
873  global $DIC;
874  $log = $DIC['log'];
875  $ilias = $DIC['ilias'];
876  $log->write(
877  $ilias->account->getLogin()
878  .' DAV .'.get_class($this).' '.str_replace("\n",";",$message)
879  );
880  /*
881  $fh = fopen('/opt/ilias/log/ilias.log', 'a');
882  fwrite($fh, date('Y-m-d h:i:s '));
883  fwrite($fh, str_replace("\n",";",$message));
884  fwrite($fh, "\n\n");
885  fclose($fh);
886  */
887  }
888  }
889 
894  function __toString() {
895  return get_class($this).'#'.$this->getObjectId();
896  }
897 }
898 // END WebDAV
899 ?>
getObjectId()
Returns the object id of this object.
children()
Returns the children of this object.
static createObject($refId, $type)
Static factory method to create a DAV object for a given refId and type.
getContentStream()
Returns the content of the object as a stream.
__toString()
This method is needed, because the object class in PHP 5.2 does not have a default implementation of ...
write()
Writes the object data.
static removeItemFromDesktops($a_id)
removes object from all user&#39;s desktops public
Class ilObjFolder.
createNewVersion()
Creates a new version of the object.
__construct($refId, $obj=null)
Constructor.
$_GET["client_id"]
getResourceType()
Returns the DAV resource type of this object.
childrenWithPermission($operations, $type='')
Returns the children of this object with the specified permissions.
createFile($name)
Creates a dav file as a child of this object.
Class ilObject Basic functions for all objects.
cloneNodes($srcRef, $dstRef, &$mapping, $newName=null)
Recursively clones all nodes of the RBAC tree.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
createFileFromNull($name, &$nullDAV)
Creates a dav file as a child of this object.
isNullResource()
Returns true if this is a null resource.
getILIASFileType()
Returns the ilias type for files that can be created as children of this object.
createCollection($name)
Creates a dav collection as a child of this object.
getDisplayName()
Returns the display name of this object.
getContentType()
Returns the mime type of the content of this object.
setContentLength($length)
Sets the length (number of bytes) of the content of this object.
static getMimeType($a_file='', $a_filename='', $a_mime='')
getModificationTimestamp()
Returns the modification date of this object as a Unix timestamp.
getResourceName()
Returns the resource name of this object.
read()
Reads the object data.
getILIASCollectionType()
Returns the ilias type for collections that can be created as children of this object.
isFile()
Returns true if this object is a DAV file.
createNull($name)
Creates a dav null object as a child of this object.
Class ilObjFile.
isCollection()
Returns true if this object is a DAV collection.
addMove(&$objDAV, $newName=null)
Adds (moves) the specified object as a child to this object.
getContentLength()
Returns the number of bytes of the content.
setContentType($type)
Sets the mime type of the content of this object.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Create styles array
The data for the language used.
removeDeletedNodes($a_node_id, $a_checked, $a_delete_objects=true)
remove already deleted objects within the objects in trash recursive function
isPermitted($operations, $type='')
Returns whether a specific operation is permitted for the current user.
getContentOutputStream()
Returns an output stream to the content.
global $ilDB
$refId
Refid to the object.
setResourceName($name)
Sets the resource name of this object.
initFromNull()
Initializes the object after it has been converted from NULL.
global $DIC
$isDebug
The ObjectDAV prints lots of log messages to the ilias log, if this variable is set to true...
getNodeId()
Returns the node id of this object.
getContentOutputStreamLength()
Returns the length of the content output stream.
isOnline()
Returns true if the object is online.
getCreationTimestamp()
Returns the creation date of this object as a Unix timestamp.
getILIASType()
Returns the ilias type of the current object.
getContentData()
Returns the content of the object as a byte array.
writelog($message)
Writes a message to the logfile.,.
$obj
Application layer object.
addCopy(&$objDAV, $newName=null)
Adds a copy of the specified object as a child to this object.
getRefId()
Returns the ref id of this object.