ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapObjectAdministration.php
Go to the documentation of this file.
1 <?php
2  /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22  */
23 
24 
33 include_once './webservice/soap/classes/class.ilSoapAdministration.php';
34 
36 {
38  {
40  }
41 
42  function getObjIdByImportId($sid,$import_id)
43  {
44  $this->initAuth($sid);
45  $this->initIlias();
46 
47  if(!$this->__checkSession($sid))
48  {
49  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
50  }
51  if(!$import_id)
52  {
53  return $this->__raiseError('No import id given.',
54  'Client');
55  }
56 
57  global $ilLog;
58 
59  $obj_id = ilObject::_lookupObjIdByImportId($import_id);
60  $ilLog->write("SOAP getObjIdByImportId(): import_id = ".$import_id.' obj_id = '.$obj_id);
61 
62  return $obj_id ? $obj_id : "0";
63  }
64 
65  function getRefIdsByImportId($sid,$import_id)
66  {
67  $this->initAuth($sid);
68  $this->initIlias();
69 
70  if(!$this->__checkSession($sid))
71  {
72  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
73  }
74  if(!$import_id)
75  {
76  return $this->__raiseError('No import id given.',
77  'Client');
78  }
79 
80  global $tree;
81 
82  $obj_id = ilObject::_lookupObjIdByImportId($import_id);
83 
84 
85  $ref_ids = ilObject::_getAllReferences($obj_id);
86 
87  foreach($ref_ids as $ref_id)
88  {
89  // only get non deleted reference ids
90  if ($tree->isInTree($ref_id))
91  {
92  $new_refs[] = $ref_id;
93  }
94  }
95  return $new_refs ? $new_refs : array();
96  }
97 
98  function getRefIdsByObjId($sid,$obj_id)
99  {
100  $this->initAuth($sid);
101  $this->initIlias();
102 
103  if(!$this->__checkSession($sid))
104  {
105  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
106  }
107  if(!$obj_id)
108  {
109  return $this->__raiseError('No object id given.',
110  'Client');
111  }
112 
113  $ref_ids = ilObject::_getAllReferences($obj_id);
114  foreach($ref_ids as $ref_id)
115  {
116  $new_refs[] = $ref_id;
117  }
118  return $new_refs ? $new_refs : array();
119  }
120 
129  function getObjIdsByRefIds($sid, $ref_ids)
130  {
131  $this->initAuth($sid);
132  $this->initIlias();
133 
134  if(!$this->__checkSession($sid))
135  {
136  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
137  }
138 
139 
140  if(!count($ref_ids) || !is_array ($ref_ids))
141  {
142  return $this->__raiseError('No reference id(s) given.', 'Client');
143  }
144 
145  $obj_ids = array();
146  if (count($ref_ids)) {
147  foreach ($ref_ids as $ref_id)
148  {
149  $ref_id = trim($ref_id);
150  if (!is_numeric($ref_id)){
151  return $this->__raiseError('Reference ID has to be numeric. Value: '.$ref_id, 'Client');
152  }
153 
154  $obj_id = ilObject::_lookupObjectId($ref_id);
155  if (!$obj_id){
156  return $this->__raiseError('No object found for reference ID. Value: '.$ref_id, 'Client');
157  }
158  if (!ilObject::_hasUntrashedReference($obj_id)){
159  return $this->__raiseError('No untrashed reference found for reference ID. Value: '.$ref_id, 'Client');
160  }
161  $obj_ids[] = $obj_id;
162  }
163  }
164  return $obj_ids;
165  }
166 
167 
168 
169  function getObjectByReference($sid,$a_ref_id,$user_id)
170  {
171  $this->initAuth($sid);
172  $this->initIlias();
173 
174  if(!$this->__checkSession($sid))
175  {
176  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
177  }
178  if(!is_numeric($a_ref_id))
179  {
180  return $this->__raiseError('No valid reference id given. Please choose an existing reference id of an ILIAS object',
181  'Client');
182  }
183 
184  if(!$tmp_obj = ilObjectFactory::getInstanceByRefId($a_ref_id,false))
185  {
186  return $this->__raiseError('Cannot create object instance!','Server');
187  }
188 
189 
190  if(ilObject::_isInTrash($a_ref_id))
191  {
192  return $this->__raiseError("Object with ID $a_ref_id has been deleted.", 'Client');
193  }
194 
195  include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
196 
197  $xml_writer = new ilObjectXMLWriter();
198  $xml_writer->enablePermissionCheck(true);
199  if($user_id)
200  {
201  $xml_writer->setUserId($user_id);
202  $xml_writer->enableOperations(true);
203  }
204  $xml_writer->setObjects(array($tmp_obj));
205  if($xml_writer->start())
206  {
207  return $xml_writer->getXML();
208  }
209 
210  return $this->__raiseError('Cannot create object xml !','Server');
211  }
212 
213  function getObjectsByTitle($sid,$a_title,$user_id)
214  {
215  $this->initAuth($sid);
216  $this->initIlias();
217 
218  if(!$this->__checkSession($sid))
219  {
220  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
221  }
222  if(!strlen($a_title))
223  {
224  return $this->__raiseError('No valid query string given.',
225  'Client');
226  }
227 
228  include_once './Services/Search/classes/class.ilQueryParser.php';
229 
230  $query_parser =& new ilQueryParser($a_title);
231  $query_parser->setMinWordLength(0,true);
232  $query_parser->setCombination(QP_COMBINATION_AND);
233  $query_parser->parse();
234  if(!$query_parser->validate())
235  {
236  return $this->__raiseError($query_parser->getMessage(),
237  'Client');
238  }
239 
240  include_once './Services/Search/classes/class.ilObjectSearchFactory.php';
241 
242  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
243  $object_search = new ilLikeObjectSearch($query_parser);
244 
245  #$object_search =& ilObjectSearchFactory::_getObjectSearchInstance($query_parser);
246  $object_search->setFields(array('title'));
247  $object_search->appendToFilter('role');
248  $object_search->appendToFilter('rolt');
249  $res =& $object_search->performSearch();
250  if($user_id)
251  {
252  $res->setUserId($user_id);
253  }
254 
255  $res->filter(ROOT_FOLDER_ID,true);
256 
257  $objs = array();
258  foreach($res->getUniqueResults() as $entry)
259  {
260  if($entry['type'] == 'role' or $entry['type'] == 'rolt')
261  {
262  if($tmp = ilObjectFactory::getInstanceByObjId($entry['obj_id'],false))
263  {
264  $objs[] = $tmp;
265  }
266  continue;
267  }
268  if($tmp = ilObjectFactory::getInstanceByRefId($entry['ref_id'],false))
269  {
270  $objs[] = $tmp;
271  }
272  }
273  if(!count($objs))
274  {
275  return '';
276  }
277 
278  include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
279 
280  $xml_writer = new ilObjectXMLWriter();
281  $xml_writer->enablePermissionCheck(true);
282  if($user_id)
283  {
284  $xml_writer->setUserId($user_id);
285  $xml_writer->enableOperations(true);
286  }
287  $xml_writer->setObjects($objs);
288  if($xml_writer->start())
289  {
290  return $xml_writer->getXML();
291  }
292 
293  return $this->__raiseError('Cannot create object xml !','Server');
294  }
295 
296  function searchObjects($sid,$types,$key,$combination,$user_id)
297  {
298  $this->initAuth($sid);
299  $this->initIlias();
300 
301  if(!$this->__checkSession($sid))
302  {
303  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
304  }
305  if(!is_array($types))
306  {
307  return $this->__raiseError('Types must be an array of object types.',
308  'Client');
309  }
310  if($combination != 'and' and $combination != 'or')
311  {
312  return $this->__raiseError('No valid combination given. Must be "and" or "or".',
313  'Client');
314  }
315 
316 
317  include_once './Services/Search/classes/class.ilQueryParser.php';
318 
319  $query_parser =& new ilQueryParser($key);
320  #$query_parser->setMinWordLength(3);
321  $query_parser->setCombination($combination == 'and' ? QP_COMBINATION_AND : QP_COMBINATION_OR);
322  $query_parser->parse();
323  if(!$query_parser->validate())
324  {
325  return $this->__raiseError($query_parser->getMessage(),
326  'Client');
327  }
328 
329  #include_once './Services/Search/classes/class.ilObjectSearchFactory.php';
330  #$object_search =& ilObjectSearchFactory::_getObjectSearchInstance($query_parser);
331 
332  include_once './Services/Search/classes/Like/class.ilLikeObjectSearch.php';
333  $object_search = new ilLikeObjectSearch($query_parser);
334 
335  $object_search->setFilter($types);
336 
337  $res =& $object_search->performSearch();
338  if($user_id)
339  {
340  $res->setUserId($user_id);
341  }
342  $res->setMaxHits(999999);
343  $res->filter(ROOT_FOLDER_ID,$combination == 'and' ? true : false);
344 
345  $counter = 0;
346  $objs = array();
347  foreach($res->getUniqueResults() as $entry)
348  {
349  $objs[] = ilObjectFactory::getInstanceByRefId($entry['ref_id'],false);
350  }
351  if(!count($objs))
352  {
353  return '';
354  }
355 
356  include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
357 
358  $xml_writer = new ilObjectXMLWriter();
359  $xml_writer->enablePermissionCheck(true);
360 
361  if($user_id)
362  {
363  $xml_writer->setUserId($user_id);
364  $xml_writer->enableOperations(true);
365  }
366 
367  $xml_writer->setObjects($objs);
368  if($xml_writer->start())
369  {
370  return $xml_writer->getXML();
371  }
372 
373  return $this->__raiseError('Cannot create object xml !','Server');
374  }
375 
376  function getTreeChilds($sid,$ref_id,$types,$user_id)
377  {
378  $this->initAuth($sid);
379  $this->initIlias();
380 
381  if(!$this->__checkSession($sid))
382  {
383  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
384  }
385 
386  $all = false;
387 
388  global $tree;
389 
390  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($ref_id,false))
391  {
392  return $this->__raiseError('No valid reference id given.',
393  'Client');
394  }
395  if (intval($ref_id) == SYSTEM_FOLDER_ID) {
396  return $this->__raiseError('No valid reference id given.',
397  'Client');
398  }
399 
400  if(!$types)
401  {
402  $all = true;
403  }
404  $filter = is_array($types) ? $types : array();
405 
406  $objs = array();
407  foreach($tree->getChilds($ref_id,'title') as $child)
408  {
409  if($all or in_array($child['type'],$types))
410  {
411  if($tmp = ilObjectFactory::getInstanceByRefId($child['ref_id'],false))
412  {
413  $objs[] = $tmp;
414  }
415  }
416  }
417 
418  include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
419 
420  $xml_writer = new ilObjectXMLWriter();
421  $xml_writer->enablePermissionCheck(true);
422  $xml_writer->setObjects($objs);
423  $xml_writer->enableOperations(true);
424  if($user_id)
425  {
426  $xml_writer->setUserId($user_id);
427  }
428 
429  if ($xml_writer->start())
430  {
431  return $xml_writer->getXML();
432  }
433 
434  return $this->__raiseError('Cannot create object xml !','Server');
435  }
436 
437  function getXMLTree($sid, $ref_id, $types, $user_id)
438  {
439  $this->initAuth($sid);
440  $this->initIlias();
441 
442  if (!$this->__checkSession($sid))
443  {
444  return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
445  }
446 
447  global $tree;
448 
449  $nodedata = $tree->getNodeData($ref_id);
450 
451  $nodearray = $tree->getSubTree($nodedata);
452 
453  $filter = is_array($types)?$types: array ("0"=>"root", "adm", "lngf", "mail",
454  "usrf", "rolf", "taxf", "trac", "pays",
455  "auth", "chac", "objf", "recf", "assf",
456  "stys", "seas", "extt");
457 
458  foreach ($nodearray as $node)
459  {
460  if (!in_array($node['type'], $filter))
461  {
462  if ($tmp = ilObjectFactory::getInstanceByRefId($node['ref_id'], false))
463  {
464  $nodes[] = $tmp;
465  }
466  }
467  }
468 
469 
470  include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
471 
472  $xml_writer = new ilObjectXMLWriter();
473  $xml_writer->enablePermissionCheck(true);
474  $xml_writer->setObjects($nodes);
475  $xml_writer->enableOperations(false);
476 
477  if ($user_id)
478  {
479  $xml_writer->setUserId($user_id);
480  }
481 
482  if ($xml_writer->start())
483  {
484  return $xml_writer->getXML();
485  }
486 
487  return $this->__raiseError('Cannot create object xml !', 'Server');
488  }
489 
490 
491  function addObject($sid,$a_target_id,$a_xml)
492  {
493  $this->initAuth($sid);
494  $this->initIlias();
495 
496  if(!$this->__checkSession($sid))
497  {
498  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
499  }
500  if(!strlen($a_xml))
501  {
502  return $this->__raiseError('No valid xml string given.',
503  'Client');
504  }
505 
506  global $rbacsystem, $objDefinition,$ilUser, $lng, $ilObjDataCache;
507 
508  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($a_target_id,false))
509  {
510  return $this->__raiseError('No valid target given.',
511  'Client');
512  }
513 
514  if(ilObject::_isInTrash($a_target_id))
515  {
516  return $this->__raiseError("Parent with ID $a_target_id has been deleted.", 'Client');
517  }
518 
519  $allowed_types = array('root','cat','grp','crs','fold');
520  if(!in_array($target_obj->getType(),$allowed_types))
521  {
522  return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"',
523  'Client');
524  }
525 
526  $allowed_subtypes = $objDefinition->getSubObjects($target_obj->getType());
527 
528  foreach($allowed_subtypes as $row)
529  {
530  if($row['name'] != 'rolf')
531  {
532  $allowed[] = $row['name'];
533  }
534  }
535 
536  include_once './webservice/soap/classes/class.ilObjectXMLParser.php';
537 
538  $xml_parser =& new ilObjectXMLParser($a_xml, true);
539  try {
540  $xml_parser->startParsing();
541  }
542  catch (ilSaxParserException $se){
543  return $this->__raiseError($se->getMessage(),'Client');
544  }
545  catch(ilObjectXMLException $e) {
546  return $this->__raiseError($e->getMessage(),'Client');
547  }
548 
549  foreach($xml_parser->getObjectData() as $object_data)
550  {
551  $res = $this->validateReferences('create',$object_data,$a_target_id);
552  if($this->isFault($res))
553  {
554  return $res;
555  }
556 
557  // Check possible subtype
558  if(!in_array($object_data['type'],$allowed))
559  {
560  return $this->__raiseError('Objects of type: '.$object_data['type'].' are not allowed to be subobjects of type '.
561  $target_obj->getType().'!',
562  'Client');
563  }
564  if(!$rbacsystem->checkAccess('create',$a_target_id,$object_data['type']))
565  {
566  return $this->__raiseError('No permission to create objects of type '.$object_data['type'].'!',
567  'Client');
568  }
569  if($object_data['type'] == 'crs')
570  {
571  return $this->__raiseError('Cannot create course objects. Use method addCourse() ',
572  'Client');
573  }
574 
575  // It's not possible to add objects with non unique import ids
576  if(strlen($object_data['import_id']) and ilObject::_lookupObjIdByImportId($object_data['import_id']))
577  {
578  return $this->__raiseError('An object with import id '.$object_data['import_id'].' already exists!',
579  'Server');
580  }
581 
582  // call gui object method
583  $class_name = $objDefinition->getClassName($object_data['type']);
584  $location = $objDefinition->getLocation($object_data['type']);
585 
586  $class_constr = "ilObj".$class_name;
587  require_once($location."/class.ilObj".$class_name.".php");
588 
589  $newObj = new $class_constr();
590 
591  if(isset($object_data['owner']) && strlen($object_data['owner']))
592  {
593  if((int)$object_data['owner'])
594  {
595  if(ilObject::_exists((int)$object_data['owner']) &&
596  $ilObjDataCache->lookupType((int)$object_data['owner']) == 'usr')
597  {
598  $newObj->setOwner((int)$object_data['owner']);
599  }
600  }
601  else
602  {
603  $usr_id = ilObjUser::_lookupId(trim($object_data['owner']));
604  if((int)$usr_id)
605  {
606  $newObj->setOwner((int)$usr_id);
607  }
608  }
609  }
610 
611  $newObj->setType($object_data['type']);
612  if(strlen($object_data['import_id']))
613  {
614  $newObj->setImportId($object_data['import_id']);
615  }
616  $newObj->setTitle($object_data['title']);
617  $newObj->setDescription($object_data['description']);
618  $newObj->create(); // true for upload
619  $newObj->createReference();
620  $newObj->putInTree($a_target_id);
621  $newObj->setPermissions($a_target_id);
622 
623  switch($object_data['type'])
624  {
625  case 'grp':
626  // Add member
627  $newObj->addMember($object_data['owner'] ? $object_data['owner'] : $ilUser->getId(),
628  $newObj->getDefaultAdminRole());
629  break;
630 
631  case 'lm':
632  case 'dbk':
633  $newObj->createLMTree();
634  break;
635  case 'cat':
636  $newObj->addTranslation($object_data["title"],$object_data["description"], $lng->getLangKey(), $lng->getLangKey());
637  break;
638  }
639 
640  $this->addReferences($newObj,$object_data);
641 
642  }
643  $ref_id = $newObj->getRefId();
644  return $ref_id ? $ref_id : "0";
645  }
646 
647  function addReference($sid,$a_source_id,$a_target_id)
648  {
649  $this->initAuth($sid);
650  $this->initIlias();
651 
652  if(!$this->__checkSession($sid))
653  {
654  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
655  }
656  if(!is_numeric($a_source_id))
657  {
658  return $this->__raiseError('No source id given.',
659  'Client');
660  }
661  if(!is_numeric($a_target_id))
662  {
663  return $this->__raiseError('No target id given.',
664  'Client');
665  }
666 
667  global $objDefinition, $rbacsystem, $tree;
668 
669  if(!$source_obj =& ilObjectFactory::getInstanceByRefId($a_source_id,false))
670  {
671  return $this->__raiseError('No valid source id given.',
672  'Client');
673  }
674  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($a_target_id,false))
675  {
676  return $this->__raiseError('No valid target id given.',
677  'Client');
678  }
679 
680  if(!$objDefinition->allowLink($source_obj->getType()) and
681  $source_obj->getType() != 'cat' and
682  $source_obj->getType() != 'crs')
683  {
684  return $this->__raiseError('Linking of object type: '.$source_obj->getType().' is not allowed',
685  'Client');
686  }
687 
688  $allowed_subtypes = $objDefinition->getSubObjects($target_obj->getType());
689  foreach($allowed_subtypes as $row)
690  {
691  if($row['name'] != 'rolf')
692  {
693  $allowed[] = $row['name'];
694  }
695  }
696  if(!in_array($source_obj->getType(),$allowed))
697  {
698  return $this->__raiseError('Objects of type: '.$source_obj->getType().' are not allowed to be subobjects of type '.
699  $target_obj->getType().'!',
700  'Client');
701  }
702 
703  // Permission checks
704  if(!$rbacsystem->checkAccess('create',$target_obj->getRefId(),$source_obj->getType()))
705  {
706  return $this->__raiseError('No permission to create objects of type '.$source_obj->getType().'!',
707  'Client');
708  }
709  if(!$rbacsystem->checkAccess('delete',$source_obj->getRefId()))
710  {
711  return $this->__raiseError('No permission to link object with id: '.$source_obj->getRefId().'!',
712  'Client');
713  }
714 
715 
716  if($source_obj->getType() != 'cat' and $source_obj->getType() != 'crs')
717  {
718  // check if object already linked to target
719  $possibleChilds = $tree->getChildsByType($target_obj->getRefId(), $source_obj->getType());
720  foreach ($possibleChilds as $child)
721  {
722  if ($child["obj_id"] == $source_obj->getId())
723  return $this->__raiseError("Object already linked to target.","Client");
724  }
725 
726  // Finally link it to target position
727 
728  $new_ref_id = $source_obj->createReference();
729  $source_obj->putInTree($target_obj->getRefId());
730  $source_obj->setPermissions($target_obj->getRefId());
731 
732  if($tree->checkForParentType($target_obj->getRefId(), 'crs'))
733  {
734  // Update crs_items
735  include_once './Modules/Course/classes/class.ilCourseItems.php';
736  new ilCourseItems($target_obj,$target_obj->getRefId());
737  }
738 
739  return $new_ref_id ? $new_ref_id : "0";
740  }
741  else
742  {
743  switch($source_obj->getType())
744  {
745  case 'cat':
746  include_once('./Modules/CategoryReference/classes/class.ilObjCategoryReference.php');
747  $new_ref = new ilObjCategoryReference();
748  break;
749 
750  case 'crs':
751  include_once('./Modules/CourseReference/classes/class.ilObjCourseReference.php');
752  $new_ref = new ilObjCourseReference();
753  break;
754  }
755  $new_ref->create();
756  $new_ref_id = $new_ref->createReference();
757 
758  $new_ref->putInTree($target_obj->getRefId());
759  $new_ref->setPermissions($target_obj->getRefId());
760 
761  $new_ref->setTargetId($source_obj->getId());
762  $new_ref->update();
763 
764  return $new_ref_id ? $new_ref_id : 0;
765  }
766  }
767 
768  function deleteObject($sid,$reference_id)
769  {
770  $this->initAuth($sid);
771  $this->initIlias();
772 
773  if(!$this->__checkSession($sid))
774  {
775  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
776  }
777  if(!is_numeric($reference_id))
778  {
779  return $this->__raiseError('No reference id given.',
780  'Client');
781  }
782  global $tree, $rbacsystem, $rbacadmin;
783 
784  if(!$del_obj =& ilObjectFactory::getInstanceByRefId($reference_id,false))
785  {
786  return $this->__raiseError('No valid reference id given.',
787  'Client');
788  }
789  if(!$rbacsystem->checkAccess('delete',$del_obj->getRefId()))
790  {
791  return $this->__raiseError('No permission to delete object with id: '.$del_obj->getRefId().'!',
792  'Client');
793  }
794 
795  // Delete tree
796  if($tree->isDeleted($reference_id))
797  {
798  return $this->__raiseError('Node already deleted','Server');
799  }
800 
801  if($del_obj->getType() == 'rolf')
802  {
803  return $this->__raiseError('Delete is not available for role folders.','Client');
804  }
805 
806  $subnodes = $tree->getSubtree($tree->getNodeData($reference_id));
807  foreach($subnodes as $subnode)
808  {
809  $rbacadmin->revokePermission($subnode["child"]);
810  // remove item from all user desktops
811  $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]);
812  }
813  if(!$tree->saveSubTree($reference_id))
814  {
815  return $this->__raiseError('Node already deleted','Client');
816  }
817 
818  return true;
819  }
820 
821  function removeFromSystemByImportId($sid,$import_id)
822  {
823  $this->initAuth($sid);
824  $this->initIlias();
825 
826  if(!$this->__checkSession($sid))
827  {
828  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
829  }
830  if(!strlen($import_id))
831  {
832  return $this->__raiseError('No import id given. Aborting!',
833  'Client');
834  }
835  global $rbacsystem, $tree, $ilLog;
836 
837  // get obj_id
838  if(!$obj_id = ilObject::_lookupObjIdByImportId($import_id))
839  {
840  return $this->__raiseError('No object found with import id: '.$import_id,
841  'Client');
842  }
843 
844  // Check access
845  $permission_ok = false;
846  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
847  {
848  if($rbacsystem->checkAccess('delete',$ref_id))
849  {
850  $permission_ok = true;
851  break;
852  }
853  }
854  if(!$permission_ok)
855  {
856  return $this->__raiseError('No permission to delete the object with import id: '.$import_id,
857  'Server');
858  }
859 
860  // Delete all references (delete permssions and entries in object_reference)
861  foreach($ref_ids as $ref_id)
862  {
863  // All subnodes
864  $node_data = $tree->getNodeData($ref_id);
865  $subtree_nodes = $tree->getSubtree($node_data);
866 
867  foreach($subtree_nodes as $node)
868  {
869  $ilLog->write('Soap: removeFromSystemByImportId(). Deleting object with title id: '.$node['title']);
870  $tmp_obj = ilObjectFactory::getInstanceByRefId($node['ref_id']);
871  if(!is_object($tmp_obj))
872  {
873  return $this->__raiseError('Cannot create instance of reference id: '.$node['ref_id'],
874  'Server');
875  }
876  $tmp_obj->delete();
877  }
878  // Finally delete tree
879  $tree->deleteTree($node_data);
880 
881  }
882 
883  return true;
884  }
885 
886 
887  function updateObjects($sid,$a_xml)
888  {
889  $this->initAuth($sid);
890  $this->initIlias();
891 
892  if(!$this->__checkSession($sid))
893  {
894  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
895  }
896  if(!strlen($a_xml))
897  {
898  return $this->__raiseError('No valid xml string given.',
899  'Client');
900  }
901 
902  global $rbacreview, $rbacsystem, $lng,$ilAccess;
903 
904  include_once './webservice/soap/classes/class.ilObjectXMLParser.php';
905  $xml_parser =& new ilObjectXMLParser($a_xml, true);
906  try
907  {
908  $xml_parser->startParsing();
909  }
910  catch (ilSaxParserException $se){
911  return $this->__raiseError($se->getMessage(),'Client');
912  }
913  catch(ilObjectXMLException $e) {
914  return $this->__raiseError($e->getMessage(),'Client');
915  }
916 
917 
918  // Validate incoming data
919  $object_datas = $xml_parser->getObjectData();
920  foreach($object_datas as & $object_data)
921  {
922  $res = $this->validateReferences('update',$object_data);
923  if($this->isFault($res))
924  {
925  return $res;
926  }
927 
928 
929  if(!$object_data["obj_id"])
930  {
931  return $this->__raiseError('No obj_id in xml found.', 'Client');
932  }
933  elseif ((int) $object_data["obj_id"] == -1 && count($object_data["references"])>0)
934  {
935  // object id might be unknown, resolve references instead to determine object id
936  // all references should point to the same object, so using the first one is ok.
937  foreach ($object_data["references"] as $refid)
938  {
939  if(ilObject::_isInTrash($refid))
940  {
941  continue;
942  }
943  break;
944  }
945 
946  $obj_id_from_refid = ilObject::_lookupObjectId($object_data["references"][0], false);
947  if (!$obj_id_from_refid)
948  {
949  return $this->__raiseError('No obj_id found for reference id '.$object_data["references"][0], 'CLIENT_OBJECT_NOT_FOUND');
950  } else
951  {
952  $tmp_obj = ilObjectFactory::getInstanceByObjId($object_data['obj_id'], false);
953  $object_data["obj_id"] = $obj_id_from_refid;
954  }
955  }
956 
957  $tmp_obj = ilObjectFactory::getInstanceByObjId($object_data['obj_id'], false);
958  if ($tmp_obj == null)
959  {
960  return $this->__raiseError('No object for id '.$object_data['obj_id'].'!', 'CLIENT_OBJECT_NOT_FOUND');
961  }
962  else
963  {
964  $object_data["instance"] = $tmp_obj;
965  }
966 
967  if($object_data['type'] == 'role')
968  {
969  $rolf_ids = $rbacreview->getFoldersAssignedToRole($object_data['obj_id'],true);
970  $rolf_id = $rolf_ids[0];
971 
972  if(!$rbacsystem->checkAccess('write',$rolf_id))
973  {
974  return $this->__raiseError('No write permission for object with id '.$object_data['obj_id'].'!', 'Client');
975  }
976  }
977  else
978  {
979  $permission_ok = false;
980  foreach(ilObject::_getAllReferences($object_data['obj_id']) as $ref_id)
981  {
982  if($rbacsystem->checkAccess('write',$object_data['obj_id']))
983  {
984  $permission_ok = true;
985  break;
986  }
987  }
988  if(!$permission_ok)
989  {
990  return $this->__raiseError('No write permission for object with id '.$object_data['obj_id'].'!', 'Client');
991  }
992  }
993  }
994  // perform update
995  if (count ($object_datas) > 0)
996  {
997  foreach($object_datas as $object_data)
998  {
999  $this->updateReferences($object_data);
1000 
1001  $tmp_obj = $object_data["instance"];
1002  $tmp_obj->setTitle($object_data['title']);
1003  $tmp_obj->setDescription($object_data['description']);
1004  switch ($object_data['type'])
1005  {
1006  case 'cat':
1007  $tmp_obj->updateTranslation($object_data["title"],$object_data["description"], $lng->getLangKey(), $lng->getLangKey());
1008  break;
1009  }
1010  $tmp_obj->update();
1011  if(strlen($object_data['owner']) && is_numeric($object_data['owner']))
1012  {
1013  $tmp_obj->setOwner($object_data['owner']);
1014  $tmp_obj->updateOwner();
1015  }
1016 
1017  }
1018  return true;
1019  }
1020  return false;
1021  }
1022 
1023  function moveObject ($sid, $ref_id, $target_id)
1024  {
1025  $this->initAuth($sid);
1026  $this->initIlias();
1027 
1028  if(!$this->__checkSession($sid))
1029  {
1030  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
1031  }
1032 
1033  include_once './webservice/soap/classes/class.ilSoapUtils.php';
1034  global $rbacreview, $rbacadmin, $objDefinition, $rbacsystem, $lng, $ilUser, $tree;
1035 
1036  // does source object exist
1037  if(!$source_object_type = ilObjectFactory::getTypeByRefId($ref_id, false))
1038  {
1039  return $this->__raiseError('No valid source given.', 'Client');
1040  }
1041 
1042  // does target object exist
1043  if(!$target_object_type = ilObjectFactory::getTypeByRefId($target_id, false))
1044  {
1045  return $this->__raiseError('No valid target given.', 'Client');
1046  }
1047 
1048  // check for trash
1050  {
1051  return $this->__raiseError('Object is trashed.', 'Client');
1052  }
1053 
1055  {
1056  return $this->__raiseError('Object is trashed.', 'Client');
1057  }
1058 
1059  $canAddType = $this->canAddType($source_object_type, $target_object_type, $target_id);
1060  if ($this->isFault($canAddType))
1061  {
1062  return $canAddType;
1063  }
1064 
1065  // check if object already linked to target
1066  $possibleChilds = $tree->getChildsByType($target_id, $ref_id);
1067  foreach ($possibleChilds as $child)
1068  {
1069  if ($child["obj_id"] == $ref_id)
1070  return $this->__raiseError("Object already exists in target.","Client");
1071  }
1072 
1073  // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
1074  $node_data = $tree->getNodeData($ref_id);
1075  $subtree_nodes = $tree->getSubTree($node_data);
1076 
1077  $all_node_data[] = $node_data;
1078  $all_subtree_nodes[] = $subtree_nodes;
1079 
1080  // CHECK DELETE PERMISSION OF ALL OBJECTS IN ACTUAL SUBTREE
1081  foreach ($subtree_nodes as $node)
1082  {
1083  if($node['type'] == 'rolf')
1084  {
1085  continue;
1086  }
1087 
1088  if (!$rbacsystem->checkAccess('delete',$node["ref_id"]))
1089  {
1090  $no_cut[] = $node["ref_id"];
1091  }
1092  }
1093 
1094  // IF THERE IS ANY OBJECT WITH NO PERMISSION TO 'delete'
1095  if (count($no_cut))
1096  {
1097  return $this->__raiseError("Object contains references which you are not allowed to delete.","Client");
1098  }
1099 
1100  // CHECK IF PASTE OBJECT SHALL BE CHILD OF ITSELF
1101  if ($tree->isGrandChild($ref_id,$target_id))
1102  {
1103  return $this->__raiseError("Cannot move object into itself.","Client");
1104  }
1105 
1106  $old_parent = $tree->getParentId($ref_id);
1107  $tree->moveTree($ref_id,$target_id);
1108  $rbacadmin->adjustMovedObjectPermissions($ref_id,$old_parent);
1109 
1110  include_once('classes/class.ilConditionHandler.php');
1112  return true;
1113  }
1114 
1120  function copyObject($sid, $copy_settings_xml)
1121  {
1122  $this->initAuth($sid);
1123  $this->initIlias();
1124 
1125  if(!$this->__checkSession($sid))
1126  {
1127  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
1128  }
1129 
1130 
1131  include_once './webservice/soap/classes/class.ilSoapUtils.php';
1132  global $rbacreview, $objDefinition, $rbacsystem, $lng, $ilUser;
1133 
1134  include_once './webservice/soap/classes/class.ilCopyWizardSettingsXMLParser.php';
1135  $xml_parser = new ilCopyWizardSettingsXMLParser($copy_settings_xml);
1136  try {
1137  $xml_parser->startParsing();
1138  } catch (ilSaxParserException $se){
1139  return $this->__raiseError($se->getMessage(), "Client");
1140  }
1141 
1142  // checking copy permissions, objects and create permissions
1143  if(!$rbacsystem->checkAccess('copy',$xml_parser->getSourceId()))
1144  {
1145  return $this->__raiseError("Missing copy permissions for object with reference id ".$xml_parser->getSourceId(), 'Client');
1146  }
1147 
1148  // checking copy permissions, objects and create permissions
1149  $source_id = $xml_parser->getSourceId();
1150  $target_id = $xml_parser->getTargetId();
1151 
1152 
1153  // does source object exist
1154  if(!$source_object_type = ilObjectFactory::getTypeByRefId($source_id, false))
1155  {
1156  return $this->__raiseError('No valid source given.', 'Client');
1157  }
1158 
1159  // does target object exist
1160  if(!$target_object_type = ilObjectFactory::getTypeByRefId($xml_parser->getTargetId(), false))
1161  {
1162  return $this->__raiseError('No valid target given.', 'Client');
1163  }
1164 
1165 
1166  $canAddType = $this->canAddType($source_object_type, $target_object_type, $target_id);
1167  if ($this->isFault($canAddType))
1168  {
1169  return $canAddType;
1170  }
1171 
1172  // if is container object than clone with sub items
1173  $options = $xml_parser->getOptions();
1174 // print_r($options);
1175  $source_object = ilObjectFactory::getInstanceByRefId($source_id);
1176  if ($source_object instanceof ilContainer) {
1177  // get client id from sid
1178  $clientid = substr($sid, strpos($sid, "::") + 2);
1179  $sessionid = str_replace("::".$clientid, "", $sid);
1180  // call container clone
1181  return $source_object->cloneAllObject($sessionid, $clientid,
1182  $source_object_type,
1183  $target_id,
1184  $source_id,
1185  $options, true);
1186 
1187  } else {
1188  // create copy wizard settings
1190  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
1191  $wizard_options->saveOwner($ilUser->getId());
1192  $wizard_options->saveRoot($source_id);
1193 
1194  foreach($options as $source_id => $option)
1195  {
1196  $wizard_options->addEntry($source_id,$option);
1197  }
1198  $wizard_options->read();
1199 
1200  // call object clone
1201  $newObject = $source_object->cloneObject($xml_parser->getTargetId(), $copy_id);
1202  return is_object($newObject) ? $newObject->getRefId() : -1;
1203  }
1204  }
1205 
1206  function getPathForRefId($sid, $ref_id)
1207  {
1208  $this->initAuth($sid);
1209  $this->initIlias();
1210 
1211  if(!$this->__checkSession($sid))
1212  {
1213  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
1214  }
1215 
1216  global $ilAccess, $objDefinition, $rbacsystem, $lng, $ilUser;
1217 
1218  if(!$rbacsystem->checkAccess('read', $ref_id))
1219  {
1220  return $this->__raiseError("Missing read permissions for object with reference id ".$ref_id, 'Client');
1221  }
1222 
1224  {
1225  return $this->__raiseError("Object is in Trash", 'Client');
1226  }
1227  global $tree, $lng;
1228  $items = $tree->getPathFull($ref_id);
1229 
1230  include_once 'webservice/soap/classes/class.ilXMLResultSet.php';
1231  include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
1232  include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
1233 
1234  $xmlResultSet = new ilXMLResultSet();
1235  $xmlResultSet->addColumn("ref_id");
1236  $xmlResultSet->addColumn("type");
1237  $xmlResultSet->addColumn("title");
1238 
1239  $writer = new ilXMLResultSetWriter($xmlResultSet);
1240  foreach ($items as $item) {
1241  if ($item["ref_id"] == $ref_id)
1242  continue;
1243  if ($item["title"] == "ILIAS" && $item["type"] == "root")
1244  {
1245  $item["title"] = $lng->txt("repository");
1246  }
1247 
1248  $row = new ilXMLResultSetRow();
1249  $xmlResultSet->addRow($row);
1250  $row->setValue("ref_id", $item["ref_id"]);
1251  $row->setValue("type", $item["type"]);
1252  $row->setValue("title", $item["title"]);
1253  }
1254  $writer->start();
1255  return $writer->getXML();
1256  }
1257 
1258 
1259  private function canAddType ($type, $target_type, $target_id)
1260  {
1261  // checking for target subtypes. Can we add source to target
1262  global $objDefinition, $rbacsystem;
1263 
1264  $allowed_types = array('root','cat','grp','crs','fold');
1265  if(!in_array($target_type, $allowed_types))
1266  {
1267  return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
1268  }
1269 
1270  $allowed_subtypes = $objDefinition->getSubObjects($target_type);
1271  $allowed = array();
1272 
1273  foreach($allowed_subtypes as $row)
1274  {
1275  if($row['name'] != 'rolf')
1276  {
1277  $allowed[] = $row['name'];
1278  }
1279  }
1280 
1281  if(!in_array($type, $allowed))
1282  {
1283  return $this->__raiseError('Objects of type: '.$type.' are not allowed to be subobjects of type '.$target_type.'!','Client');
1284  }
1285  if(!$rbacsystem->checkAccess('create',$target_id, $type))
1286  {
1287  return $this->__raiseError('No permission to create objects of type '.$type.'!', 'Client');
1288  }
1289 
1290  return true;
1291  }
1292 
1293  private function validateReferences($a_action,$a_object_data,$a_target_id = 0)
1294  {
1295  global $ilAccess;
1296 
1297  if(!isset($a_object_data['references']) or !count($a_object_data['references']))
1298  {
1299  return true;
1300  }
1301  if($a_action == 'create')
1302  {
1303  if(count($a_object_data['references']) > 1)
1304  {
1305  if(in_array($a_object_data['type'],array('cat','crs','grp','fold')))
1306  {
1307  return $this->__raiseError("Cannot create references for type ".$a_object_data['type'],
1308  'Client');
1309  }
1310  }
1311  if(count($a_object_data['references']) == 1)
1312  {
1313  if($a_target_id != $a_object_data['references'][0]['parent_id'])
1314  {
1315  return $this->__raiseError("Cannot create references for type ".$a_object_data['type'],
1316  'Client');
1317  }
1318  }
1319 
1320  foreach($a_object_data['references'] as $ref_data)
1321  {
1322  if(!$ref_data['parent_id'])
1323  {
1324  return $this->__raiseError('Element References: No parent Id given!','Client');
1325  }
1326 
1327  $target_type = ilObject::_lookupType(ilObject::_lookupObjId($ref_data['parent_id']));
1328  $can_add_type = $this->canAddType($a_object_data['type'],$target_type,$ref_data['parent_id']);
1329  if($this->isFault($can_add_type))
1330  {
1331  return $can_add_type;
1332  }
1333  }
1334  return true;
1335  }
1336 
1337  if($a_action == 'update')
1338  {
1339  foreach($a_object_data['references'] as $ref_data)
1340  {
1341  if(!$ref_data['ref_id'])
1342  {
1343  return $this->__raiseError('Element References: No reference id given!','Client');
1344  }
1345  // check permissions
1346  if(!$ilAccess->checkAccess('write','',$ref_data['ref_id']))
1347  {
1348  return $this->__raiseError('No write permission for object with reference id '.$ref_data['ref_id'].'!', 'Client');
1349  }
1350  // TODO: check if all references belong to the same object
1351  }
1352  return true;
1353  }
1354  }
1355 
1356  private function updateReferences($a_object_data)
1357  {
1358  global $tree,$ilLog;
1359 
1360  if(!isset($a_object_data['references']) or !count($a_object_data['references']))
1361  {
1362  return true;
1363  }
1364 
1365  foreach($a_object_data['references'] as $ref_data)
1366  {
1367  if(isset($ref_data['time_target']) and ($crs_ref_id = $tree->checkForParentType($ref_data['ref_id'],'crs')))
1368  {
1369  $crs_obj = ilObjectFactory::getInstanceByRefId($crs_ref_id,false);
1370  include_once('./Modules/Course/classes/class.ilCourseItems.php');
1371  include_once('./webservice/soap/classes/class.ilObjectXMLWriter.php');
1372 
1373 
1374  $items = new ilCourseItems($crs_obj->getRefId(),$ref_data['parent_id']);
1375  $old = $items->getItem($ref_data['ref_id']);
1376 
1377  $items->toggleChangeable(isset($ref_data['time_target']['changeable']) ? $ref_data['time_target']['changeable'] : $old['changeable']);
1378  $items->setTimingStart(isset($ref_data['time_target']['starting_time']) ? $ref_data['time_target']['starting_time'] : $old['timing_start']);
1379  $items->setTimingEnd(isset($ref_data['time_target']['ending_time']) ? $ref_data['time_target']['ending_time'] : $old['timing_end']);
1380  $items->toggleVisible(isset($ref_data['time_target']['timing_visibility']) ? $ref_data['time_target']['timing_visibility'] : $old['visible']);
1381  $items->setSuggestionStart(isset($ref_data['time_target']['suggestion_start']) ? $ref_data['time_target']['suggestion_start'] : $old['suggestion_start']);
1382  $items->setSuggestionEnd(isset($ref_data['time_target']['suggestion_end']) ? $ref_data['time_target']['suggestion_end'] : $old['suggestion_end']);
1383  $items->setEarliestStart(isset($ref_data['time_target']['earliest_start']) ? $ref_data['time_target']['earliest_start'] : $old['earliest_start']);
1384  $items->setLatestEnd(isset($ref_data['time_target']['latest_end']) ? $ref_data['time_target']['latest_end'] : $old['latest_end']);
1385 
1386  switch($ref_data['time_target']['timing_type'])
1387  {
1389  $ilLog->write(__METHOD__.IL_CRS_TIMINGS_DEACTIVATED.' '.$ref_data['time_target']['timing_type']);
1390  $items->setTimingType(IL_CRS_TIMINGS_DEACTIVATED);
1391  break;
1392 
1394  $ilLog->write(__METHOD__.IL_CRS_TIMINGS_ACTIVATION.' '.$ref_data['time_target']['timing_type']);
1395  $items->setTimingType(IL_CRS_TIMINGS_ACTIVATION);
1396  break;
1397 
1399  $ilLog->write(__METHOD__.IL_CRS_TIMINGS_PRESETTING.' '.$ref_data['time_target']['timing_type']);
1400  $items->setTimingType(IL_CRS_TIMINGS_PRESETTING);
1401  break;
1402  }
1403  $items->update($ref_data['ref_id']);
1404  }
1405  }
1406  return true;
1407  }
1408 
1409 
1410  private function addReferences($source,$a_object_data)
1411  {
1412  global $tree,$ilLog;
1413 
1414  if(!isset($a_object_data['references']) or !count($a_object_data['references']))
1415  {
1416  return true;
1417  }
1418 
1419  $original_id = $source->getRefId();
1420 
1421  foreach($a_object_data['references'] as $ref_data)
1422  {
1423  $new_ref_id = $ref_id = $original_id;
1424  if($tree->getParentId($original_id) != $ref_data['parent_id'])
1425  {
1426  // New reference requested => create it
1427  $new_ref_id = $source->createReference();
1428  $source->putInTree($ref_data['parent_id']);
1429  $source->setPermissions($ref_data['parent_id']);
1430  }
1431  if(isset($ref_data['time_target']) and ($crs_ref_id = $tree->checkForParentType($new_ref_id,'crs')))
1432  {
1433 
1434  $crs_obj = ilObjectFactory::getInstanceByRefId($crs_ref_id,false);
1435  include_once('./Modules/Course/classes/class.ilCourseItems.php');
1436  include_once('./webservice/soap/classes/class.ilObjectXMLWriter.php');
1437 
1438  $items = new ilCourseItems($crs_obj->getRefId(),$ref_data['parent_id']);
1439 
1440  if(!isset($ref_data['time_target']['starting_time']))
1441  {
1442  $ref_data['time_target']['starting_time'] = time();
1443  }
1444  if(!isset($ref_data['time_target']['ending_time']))
1445  {
1446  $ref_data['time_target']['ending_time'] = time();
1447  }
1448 
1449  $items->toggleChangeable($ref_data['time_target']['changeable']);
1450  $items->setTimingStart($ref_data['time_target']['starting_time']);
1451  $items->setTimingEnd($ref_data['time_target']['ending_time']);
1452  $items->toggleVisible($ref_data['time_target']['timing_visibility']);
1453  $items->setSuggestionStart($ref_data['time_target']['suggestion_start']);
1454  $items->setSuggestionEnd($ref_data['time_target']['suggestion_end']);
1455  $items->setEarliestStart($ref_data['time_target']['earliest_start']);
1456  $items->setLatestEnd($ref_data['time_target']['latest_end']);
1457 
1458  switch($ref_data['time_target']['timing_type'])
1459  {
1461  $ilLog->write(__METHOD__.IL_CRS_TIMINGS_DEACTIVATED.' '.$ref_data['time_target']['timing_type']);
1462  $items->setTimingType(IL_CRS_TIMINGS_DEACTIVATED);
1463  break;
1464 
1466  $ilLog->write(__METHOD__.IL_CRS_TIMINGS_ACTIVATION.' '.$ref_data['time_target']['timing_type']);
1467  $items->setTimingType(IL_CRS_TIMINGS_ACTIVATION);
1468  break;
1469 
1471  $ilLog->write(__METHOD__.IL_CRS_TIMINGS_PRESETTING.' '.$ref_data['time_target']['timing_type']);
1472  $items->setTimingType(IL_CRS_TIMINGS_PRESETTING);
1473  break;
1474  }
1475  $items->update($new_ref_id);
1476  }
1477  }
1478 
1479  }
1480 
1481 
1482 
1483 }
1484 ?>