ILIAS  Release_3_10_x_branch Revision 61812
 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  if(!$this->__checkSession($sid))
45  {
46  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
47  }
48  if(!$import_id)
49  {
50  return $this->__raiseError('No import id given.',
51  'Client');
52  }
53 
54  // Include main header
55  include_once './include/inc.header.php';
56  global $ilLog;
57 
58  $obj_id = ilObject::_lookupObjIdByImportId($import_id);
59  $ilLog->write("SOAP getObjIdByImportId(): import_id = ".$import_id.' obj_id = '.$obj_id);
60 
61  return $obj_id ? $obj_id : "0";
62  }
63 
64  function getRefIdsByImportId($sid,$import_id)
65  {
66  global $tree;
67 
68  if(!$this->__checkSession($sid))
69  {
70  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
71  }
72  if(!$import_id)
73  {
74  return $this->__raiseError('No import id given.',
75  'Client');
76  }
77 
78  // Include main header
79  include_once './include/inc.header.php';
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  if(!$this->__checkSession($sid))
101  {
102  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
103  }
104  if(!$obj_id)
105  {
106  return $this->__raiseError('No object id given.',
107  'Client');
108  }
109 
110  // Include main header
111  include_once './include/inc.header.php';
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  if(!$this->__checkSession($sid))
132  {
133  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
134  }
135 
136 
137  // Include main header
138  include_once './include/inc.header.php';
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  if(!$this->__checkSession($sid))
172  {
173  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
174  }
175  if(!is_numeric($a_ref_id))
176  {
177  return $this->__raiseError('No valid reference id given. Please choose an existing reference id of an ILIAS object',
178  'Client');
179  }
180 
181  // Include main header
182  include_once './include/inc.header.php';
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  if($user_id)
199  {
200  $xml_writer->setUserId($user_id);
201  $xml_writer->enableOperations(true);
202  }
203  $xml_writer->setObjects(array($tmp_obj));
204  if($xml_writer->start())
205  {
206  return $xml_writer->getXML();
207  }
208 
209  return $this->__raiseError('Cannot create object xml !','Server');
210  }
211 
212  function getObjectsByTitle($sid,$a_title,$user_id)
213  {
214  if(!$this->__checkSession($sid))
215  {
216  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
217  }
218  if(!strlen($a_title))
219  {
220  return $this->__raiseError('No valid query string given.',
221  'Client');
222  }
223 
224  // Include main header
225  include_once './include/inc.header.php';
226 
227  include_once './Services/Search/classes/class.ilQueryParser.php';
228 
229  $query_parser =& new ilQueryParser($a_title);
230  $query_parser->setMinWordLength(0,true);
231  $query_parser->setCombination(QP_COMBINATION_AND);
232  $query_parser->parse();
233  if(!$query_parser->validate())
234  {
235  return $this->__raiseError($query_parser->getMessage(),
236  'Client');
237  }
238 
239  include_once './Services/Search/classes/class.ilObjectSearchFactory.php';
240 
241  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
242  $object_search = new ilLikeObjectSearch($query_parser);
243 
244  #$object_search =& ilObjectSearchFactory::_getObjectSearchInstance($query_parser);
245  $object_search->setFields(array('title'));
246  $object_search->appendToFilter('role');
247  $object_search->appendToFilter('rolt');
248  $res =& $object_search->performSearch();
249  if($user_id)
250  {
251  $res->setUserId($user_id);
252  }
253 
254  $res->filter(ROOT_FOLDER_ID,true);
255 
256  $objs = array();
257  foreach($res->getUniqueResults() as $entry)
258  {
259  $objs[] = ilObjectFactory::getInstanceByObjId($entry['obj_id'],false);
260  }
261  if(!count($objs))
262  {
263  return '';
264  }
265 
266  include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
267 
268  $xml_writer = new ilObjectXMLWriter();
269  if($user_id)
270  {
271  $xml_writer->setUserId($user_id);
272  $xml_writer->enableOperations(true);
273  }
274  $xml_writer->setObjects($objs);
275  if($xml_writer->start())
276  {
277  return $xml_writer->getXML();
278  }
279 
280  return $this->__raiseError('Cannot create object xml !','Server');
281  }
282 
283  function searchObjects($sid,$types,$key,$combination,$user_id)
284  {
285  if(!$this->__checkSession($sid))
286  {
287  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
288  }
289  if(!is_array($types))
290  {
291  return $this->__raiseError('Types must be an array of object types.',
292  'Client');
293  }
294  if($combination != 'and' and $combination != 'or')
295  {
296  return $this->__raiseError('No valid combination given. Must be "and" or "or".',
297  'Client');
298  }
299 
300 
301  // Include main header
302  include_once './include/inc.header.php';
303 
304  include_once './Services/Search/classes/class.ilQueryParser.php';
305 
306  $query_parser =& new ilQueryParser($key);
307  $query_parser->setMinWordLength(0,true);
308  $query_parser->setCombination($combination == 'and' ? QP_COMBINATION_AND : QP_COMBINATION_OR);
309  $query_parser->parse();
310  if(!$query_parser->validate())
311  {
312  return $this->__raiseError($query_parser->getMessage(),
313  'Client');
314  }
315 
316  #include_once './Services/Search/classes/class.ilObjectSearchFactory.php';
317  #$object_search =& ilObjectSearchFactory::_getObjectSearchInstance($query_parser);
318 
319  include_once './Services/Search/classes/Like/class.ilLikeObjectSearch.php';
320  $object_search = new ilLikeObjectSearch($query_parser);
321 
322  $object_search->setFilter($types);
323 
324  $res =& $object_search->performSearch();
325  if($user_id)
326  {
327  $res->setUserId($user_id);
328  }
329  $res->setMaxHits(999999);
330  $res->filter(ROOT_FOLDER_ID,$combination == 'and' ? true : false);
331 
332 
333  // Limit to 30 objects
334  $counter = 0;
335  $objs = array();
336  foreach($res->getUniqueResults() as $entry)
337  {
338  /*if(++$counter == 30)
339  {
340  break;
341  }*/
342  $objs[] = ilObjectFactory::getInstanceByObjId($entry['obj_id'],false);
343  }
344  if(!count($objs))
345  {
346  return '';
347  }
348 
349  include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
350 
351  $xml_writer = new ilObjectXMLWriter();
352 
353  if($user_id)
354  {
355  $xml_writer->setUserId($user_id);
356  $xml_writer->enableOperations(true);
357  }
358 
359  $xml_writer->setObjects($objs);
360  if($xml_writer->start())
361  {
362  return $xml_writer->getXML();
363  }
364 
365  return $this->__raiseError('Cannot create object xml !','Server');
366  }
367 
368  function getTreeChilds($sid,$ref_id,$types,$user_id)
369  {
370  $all = false;
371 
372  if(!$this->__checkSession($sid))
373  {
374  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
375  }
376 
377  // Include main header
378  include_once './include/inc.header.php';
379  global $tree;
380 
381  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($ref_id,false))
382  {
383  return $this->__raiseError('No valid reference id given.',
384  'Client');
385  }
386  if (intval($ref_id) == SYSTEM_FOLDER_ID) {
387  return $this->__raiseError('No valid reference id given.',
388  'Client');
389  }
390 
391  if(!$types)
392  {
393  $all = true;
394  }
395  $filter = is_array($types) ? $types : array();
396 
397  $objs = array();
398  foreach($tree->getChilds($ref_id,'title') as $child)
399  {
400  if($all or in_array($child['type'],$types))
401  {
402  if($tmp = ilObjectFactory::getInstanceByRefId($child['ref_id'],false))
403  {
404  $objs[] = $tmp;
405  }
406  }
407  }
408 
409  /*if(!$objs)
410  {
411  return '';
412  }*/
413 
414  include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
415 
416  $xml_writer = new ilObjectXMLWriter();
417  $xml_writer->setObjects($objs);
418  $xml_writer->enableOperations(true);
419  if($user_id)
420  {
421  $xml_writer->setUserId($user_id);
422  }
423 
424  if($xml_writer->start())
425  {
426  return $xml_writer->getXML();
427  }
428 
429  return $this->__raiseError('Cannot create object xml !','Server');
430  }
431 
432  function getXMLTree($sid,$ref_id,$types,$user_id) {
433 
434  if(!$this->__checkSession($sid))
435  {
436  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
437  }
438 
439  include_once './include/inc.header.php';
440 
441  global $tree;
442 
443  $nodedata = $tree->getNodeData($ref_id);
444 
445  $nodearray = $tree->getSubTree($nodedata);
446 
447  $filter = is_array($types) ? $types : array("0" => "root","adm","lngf","mail",
448  "usrf","rolf","taxf","trac","pays",
449  "auth","chac","objf","recf","assf",
450  "stys","seas","extt");
451 
452  foreach($nodearray as $node) {
453  if (!in_array($node['type'], $filter)) {
454  if ($tmp = ilObjectFactory::getInstanceByRefId($node['ref_id'],false)) {
455  $nodes[] = $tmp;
456  }
457  }
458  }
459 
460 
461  include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
462 
463  $xml_writer = new ilObjectXMLWriter();
464  $xml_writer->setObjects($nodes);
465  $xml_writer->enableOperations(false);
466 
467  if($user_id)
468  {
469  $xml_writer->setUserId($user_id);
470  }
471 
472  if($xml_writer->start())
473  {
474  return $xml_writer->getXML();
475  }
476 
477  return $this->__raiseError('Cannot create object xml !','Server');
478  }
479 
480 
481  function addObject($sid,$a_target_id,$a_xml)
482  {
483  if(!$this->__checkSession($sid))
484  {
485  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
486  }
487  if(!strlen($a_xml))
488  {
489  return $this->__raiseError('No valid xml string given.',
490  'Client');
491  }
492 
493  // Include main header
494  include_once './include/inc.header.php';
495  global $rbacsystem, $objDefinition,$ilUser, $lng, $ilObjDataCache;
496 
497  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($a_target_id,false))
498  {
499  return $this->__raiseError('No valid target given.',
500  'Client');
501  }
502 
503  if(ilObject::_isInTrash($a_target_id))
504  {
505  return $this->__raiseError("Parent with ID $a_target_id has been deleted.", 'Client');
506  }
507 
508  $allowed_types = array('root','cat','grp','crs','fold');
509  if(!in_array($target_obj->getType(),$allowed_types))
510  {
511  return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"',
512  'Client');
513  }
514 
515  $allowed_subtypes = $objDefinition->getSubObjects($target_obj->getType());
516 
517  foreach($allowed_subtypes as $row)
518  {
519  if($row['name'] != 'rolf')
520  {
521  $allowed[] = $row['name'];
522  }
523  }
524 
525  include_once './webservice/soap/classes/class.ilObjectXMLParser.php';
526 
527  $xml_parser =& new ilObjectXMLParser($a_xml, true);
528  try {
529  $xml_parser->startParsing();
530  } catch (ilSaxParserException $se){
531  return $this->__raiseError($se->getMessage(), $se->getCode());
532  }
533 
534  foreach($xml_parser->getObjectData() as $object_data)
535  {
536  // Check possible subtype
537  if(!in_array($object_data['type'],$allowed))
538  {
539  return $this->__raiseError('Objects of type: '.$object_data['type'].' are not allowed to be subobjects of type '.
540  $target_obj->getType().'!',
541  'Client');
542  }
543  if(!$rbacsystem->checkAccess('create',$a_target_id,$object_data['type']))
544  {
545  return $this->__raiseError('No permission to create objects of type '.$object_data['type'].'!',
546  'Client');
547  }
548  if($object_data['type'] == 'crs')
549  {
550  return $this->__raiseError('Cannot create course objects. Use method addCourse() ',
551  'Client');
552  }
553 
554  // It's not possible to add objects with non unique import ids
555  if(strlen($object_data['import_id']) and ilObject::_lookupObjIdByImportId($object_data['import_id']))
556  {
557  return $this->__raiseError('An object with import id '.$object_data['import_id'].' already exists!',
558  'Server');
559  }
560 
561  // call gui object method
562  $class_name = $objDefinition->getClassName($object_data['type']);
563  $location = $objDefinition->getLocation($object_data['type']);
564 
565  $class_constr = "ilObj".$class_name;
566  require_once($location."/class.ilObj".$class_name.".php");
567 
568  $newObj = new $class_constr();
569 
570  if(isset($object_data['owner']) && strlen($object_data['owner']))
571  {
572  if((int)$object_data['owner'])
573  {
574  if(ilObject::_exists((int)$object_data['owner']) &&
575  $ilObjDataCache->lookupType((int)$object_data['owner']) == 'usr')
576  {
577  $newObj->setOwner((int)$object_data['owner']);
578  }
579  }
580  else
581  {
582  $usr_id = ilObjUser::_lookupId(trim($object_data['owner']));
583  if((int)$usr_id)
584  {
585  $newObj->setOwner((int)$usr_id);
586  }
587  }
588  }
589 
590  $newObj->setType($object_data['type']);
591  if(strlen($object_data['import_id']))
592  {
593  $newObj->setImportId($object_data['import_id']);
594  }
595  $newObj->setTitle($object_data['title']);
596  $newObj->setDescription($object_data['description']);
597  $newObj->create(); // true for upload
598  $newObj->createReference();
599  $newObj->putInTree($a_target_id);
600  $newObj->setPermissions($a_target_id);
601  $newObj->initDefaultRoles();
602 
603  switch($object_data['type'])
604  {
605  case 'grp':
606  // Add member
607  $newObj->addMember($object_data['owner'] ? $object_data['owner'] : $ilUser->getId(),
608  $newObj->getDefaultAdminRole());
609  break;
610 
611  case 'lm':
612  case 'dbk':
613  $newObj->createLMTree();
614  break;
615  case 'cat':
616  $newObj->addTranslation($object_data["title"],$object_data["description"], $lng->getLangKey(), $lng->getLangKey());
617  break;
618  }
619 
620  }
621  $ref_id = $newObj->getRefId();
622  return $ref_id ? $ref_id : "0";
623  }
624 
625  function addReference($sid,$a_source_id,$a_target_id)
626  {
627  if(!$this->__checkSession($sid))
628  {
629  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
630  }
631  if(!is_numeric($a_source_id))
632  {
633  return $this->__raiseError('No source id given.',
634  'Client');
635  }
636  if(!is_numeric($a_target_id))
637  {
638  return $this->__raiseError('No target id given.',
639  'Client');
640  }
641 
642  include_once './include/inc.header.php';
643  global $objDefinition, $rbacsystem, $tree;
644 
645  if(!$source_obj =& ilObjectFactory::getInstanceByRefId($a_source_id,false))
646  {
647  return $this->__raiseError('No valid source id given.',
648  'Client');
649  }
650  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($a_target_id,false))
651  {
652  return $this->__raiseError('No valid target id given.',
653  'Client');
654  }
655 
656  if(!$objDefinition->allowLink($source_obj->getType()) and
657  $source_obj->getType() != 'cat' and
658  $source_obj->getType() != 'crs')
659  {
660  return $this->__raiseError('Linking of object type: '.$source_obj->getType().' is not allowed',
661  'Client');
662  }
663 
664  $allowed_subtypes = $objDefinition->getSubObjects($target_obj->getType());
665  foreach($allowed_subtypes as $row)
666  {
667  if($row['name'] != 'rolf')
668  {
669  $allowed[] = $row['name'];
670  }
671  }
672  if(!in_array($source_obj->getType(),$allowed))
673  {
674  return $this->__raiseError('Objects of type: '.$source_obj->getType().' are not allowed to be subobjects of type '.
675  $target_obj->getType().'!',
676  'Client');
677  }
678 
679  // Permission checks
680  if(!$rbacsystem->checkAccess('create',$target_obj->getRefId(),$source_obj->getType()))
681  {
682  return $this->__raiseError('No permission to create objects of type '.$source_obj->getType().'!',
683  'Client');
684  }
685  if(!$rbacsystem->checkAccess('delete',$source_obj->getRefId()))
686  {
687  return $this->__raiseError('No permission to link object with id: '.$source_obj->getRefId().'!',
688  'Client');
689  }
690 
691 
692  if($source_obj->getType() != 'cat' and $source_obj->getType() != 'crs')
693  {
694  // check if object already linked to target
695  $possibleChilds = $tree->getChildsByType($target_obj->getRefId(), $source_obj->getType());
696  foreach ($possibleChilds as $child)
697  {
698  if ($child["obj_id"] == $source_obj->getId())
699  return $this->__raiseError("Object already linked to target.","Client");
700  }
701 
702  // Finally link it to target position
703 
704  $new_ref_id = $source_obj->createReference();
705  $source_obj->putInTree($target_obj->getRefId());
706  $source_obj->setPermissions($target_obj->getRefId());
707  $source_obj->initDefaultRoles();
708 
709  return $new_ref_id ? $new_ref_id : "0";
710  }
711  else
712  {
713  switch($source_obj->getType())
714  {
715  case 'cat':
716  include_once('./Modules/CategoryReference/classes/class.ilObjCategoryReference.php');
717  $new_ref = new ilObjCategoryReference();
718  break;
719 
720  case 'crs':
721  include_once('./Modules/CourseReference/classes/class.ilObjCourseReference.php');
722  $new_ref = new ilObjCourseReference();
723  break;
724  }
725  $new_ref->create();
726  $new_ref_id = $new_ref->createReference();
727 
728  $new_ref->putInTree($target_obj->getRefId());
729  $new_ref->setPermissions($target_obj->getRefId());
730  $new_ref->initDefaultRoles();
731 
732  $new_ref->setTargetId($source_obj->getId());
733  $new_ref->update();
734 
735  return $new_ref_id ? $new_ref_id : 0;
736  }
737  }
738 
739  function deleteObject($sid,$reference_id)
740  {
741  global $tree;
742 
743  if(!$this->__checkSession($sid))
744  {
745  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
746  }
747  if(!is_numeric($reference_id))
748  {
749  return $this->__raiseError('No reference id given.',
750  'Client');
751  }
752  include_once './include/inc.header.php';
753  global $tree, $rbacsystem, $rbacadmin;
754 
755  if(!$del_obj =& ilObjectFactory::getInstanceByRefId($reference_id,false))
756  {
757  return $this->__raiseError('No valid reference id given.',
758  'Client');
759  }
760  if(!$rbacsystem->checkAccess('delete',$del_obj->getRefId()))
761  {
762  return $this->__raiseError('No permission to delete object with id: '.$del_obj->getRefId().'!',
763  'Client');
764  }
765 
766  // Delete tree
767  if($tree->isDeleted($reference_id))
768  {
769  return $this->__raiseError('Node already deleted','Server');
770  }
771 
772  if($del_obj->getType() == 'rolf')
773  {
774  return $this->__raiseError('Delete is not available for role folders.','Client');
775  }
776 
777  $subnodes = $tree->getSubtree($tree->getNodeData($reference_id));
778  foreach($subnodes as $subnode)
779  {
780  $rbacadmin->revokePermission($subnode["child"]);
781  // remove item from all user desktops
782  $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]);
783  }
784  if(!$tree->saveSubTree($reference_id))
785  {
786  return $this->__raiseError('Node already deleted','Client');
787  }
788 
789  return true;
790  }
791 
792  function removeFromSystemByImportId($sid,$import_id)
793  {
794  if(!$this->__checkSession($sid))
795  {
796  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
797  }
798  if(!strlen($import_id))
799  {
800  return $this->__raiseError('No import id given. Aborting!',
801  'Client');
802  }
803  include_once './include/inc.header.php';
804  global $rbacsystem, $tree, $ilLog;
805 
806  // get obj_id
807  if(!$obj_id = ilObject::_lookupObjIdByImportId($import_id))
808  {
809  return $this->__raiseError('No object found with import id: '.$import_id,
810  'Client');
811  }
812 
813  // Check access
814  $permission_ok = false;
815  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
816  {
817  if($rbacsystem->checkAccess('delete',$ref_id))
818  {
819  $permission_ok = true;
820  break;
821  }
822  }
823  if(!$permission_ok)
824  {
825  return $this->__raiseError('No permission to delete the object with import id: '.$import_id,
826  'Server');
827  }
828 
829  // Delete all references (delete permssions and entries in object_reference)
830  foreach($ref_ids as $ref_id)
831  {
832  // All subnodes
833  $node_data = $tree->getNodeData($ref_id);
834  $subtree_nodes = $tree->getSubtree($node_data);
835 
836  foreach($subtree_nodes as $node)
837  {
838  $ilLog->write('Soap: removeFromSystemByImportId(). Deleting object with title id: '.$node['title']);
839  $tmp_obj = ilObjectFactory::getInstanceByRefId($node['ref_id']);
840  if(!is_object($tmp_obj))
841  {
842  return $this->__raiseError('Cannot create instance of reference id: '.$node['ref_id'],
843  'Server');
844  }
845  $tmp_obj->delete();
846  }
847  // Finally delete tree
848  $tree->deleteTree($node_data);
849 
850  }
851 
852  return true;
853  }
854 
855 
856  function updateObjects($sid,$a_xml)
857  {
858  if(!$this->__checkSession($sid))
859  {
860  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
861  }
862  if(!strlen($a_xml))
863  {
864  return $this->__raiseError('No valid xml string given.',
865  'Client');
866  }
867 
868  // Include main header
869  include_once './include/inc.header.php';
870  global $rbacreview, $rbacsystem, $lng;
871 
872  include_once './webservice/soap/classes/class.ilObjectXMLParser.php';
873  $xml_parser =& new ilObjectXMLParser($a_xml, true);
874  try {
875  $xml_parser->startParsing();
876  } catch (ilSaxParserException $se){
877  return $this->__raiseError($se->getMessage(), $se->getCode());
878  }
879 
880 
881  // Validate incoming data
882  $object_datas = $xml_parser->getObjectData();
883  foreach($object_datas as & $object_data)
884  {
885  if(!$object_data["obj_id"])
886  {
887  return $this->__raiseError('No obj_id in xml found.', 'Client');
888  }
889  elseif ((int) $object_data["obj_id"] == -1 && count($object_data["references"])>0)
890  {
891  // object id might be unknown, resolve references instead to determine object id
892  // all references should point to the same object, so using the first one is ok.
893  foreach ($object_data["references"] as $refid)
894  {
895  if(ilObject::_isInTrash($refid))
896  {
897  continue;
898  }
899  break;
900  }
901 
902  $obj_id_from_refid = ilObject::_lookupObjectId($object_data["references"][0], false);
903  if (!$obj_id_from_refid)
904  {
905  return $this->__raiseError('No obj_id found for reference id '.$object_data["references"][0], 'CLIENT_OBJECT_NOT_FOUND');
906  } else
907  {
908  $tmp_obj = ilObjectFactory::getInstanceByObjId($object_data['obj_id'], false);
909  $object_data["obj_id"] = $obj_id_from_refid;
910  }
911  }
912 
913  $tmp_obj = ilObjectFactory::getInstanceByObjId($object_data['obj_id'], false);
914  if ($tmp_obj == null)
915  {
916  return $this->__raiseError('No object for id '.$object_data['obj_id'].'!', 'CLIENT_OBJECT_NOT_FOUND');
917  }
918  else
919  {
920  $object_data["instance"] = $tmp_obj;
921  }
922 
923  if($object_data['type'] == 'role')
924  {
925  $rolf_ids = $rbacreview->getFoldersAssignedToRole($object_data['obj_id'],true);
926  $rolf_id = $rolf_ids[0];
927 
928  if(!$rbacsystem->checkAccess('write',$rolf_id))
929  {
930  return $this->__raiseError('No write permission for object with id '.$object_data['obj_id'].'!', 'Client');
931  }
932  }
933  else
934  {
935  $permission_ok = false;
936  foreach(ilObject::_getAllReferences($object_data['obj_id']) as $ref_id)
937  {
938  if($rbacsystem->checkAccess('write',$object_data['obj_id']))
939  {
940  $permission_ok = true;
941  break;
942  }
943  }
944  if(!$permission_ok)
945  {
946  return $this->__raiseError('No write permission for object with id '.$object_data['obj_id'].'!', 'Client');
947  }
948  }
949  }
950  // perform update
951  if (count ($object_datas) > 0)
952  {
953  foreach($object_datas as $object_data)
954  {
955  $tmp_obj = $object_data["instance"];
956  $tmp_obj->setTitle($object_data['title']);
957  $tmp_obj->setDescription($object_data['description']);
958  switch ($object_data['type']) {
959  case 'cat':
960  $tmp_obj->updateTranslation($object_data["title"],$object_data["description"], $lng->getLangKey(), $lng->getLangKey());
961  break;
962  }
963  $tmp_obj->update();
964  if(strlen($object_data['owner']) && is_numeric($object_data['owner']))
965  {
966  $tmp_obj->setOwner($object_data['owner']);
967  $tmp_obj->updateOwner();
968  }
969 
970  }
971  return true;
972  }
973  return false;
974  }
975 
976  function moveObject ($sid, $ref_id, $target_id)
977  {
978  if(!$this->__checkSession($sid))
979  {
980  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
981  }
982 
983  // Include main header
984  include_once './include/inc.header.php';
985  include_once './webservice/soap/classes/class.ilSoapUtils.php';
986  global $rbacreview, $rbacadmin, $objDefinition, $rbacsystem, $lng, $ilUser, $tree;
987 
988  // does source object exist
989  if(!$source_object_type = ilObjectFactory::getTypeByRefId($ref_id, false))
990  {
991  return $this->__raiseError('No valid source given.', 'Client');
992  }
993 
994  // does target object exist
995  if(!$target_object_type = ilObjectFactory::getTypeByRefId($target_id, false))
996  {
997  return $this->__raiseError('No valid target given.', 'Client');
998  }
999 
1000  // check for trash
1002  {
1003  return $this->__raiseError('Object is trashed.', 'Client');
1004  }
1005 
1007  {
1008  return $this->__raiseError('Object is trashed.', 'Client');
1009  }
1010 
1011  $canAddType = $this->canAddType($source_object_type, $target_object_type, $target_id);
1012  if ($this->isFault($canAddType))
1013  {
1014  return $canAddType;
1015  }
1016 
1017  // check if object already linked to target
1018  $possibleChilds = $tree->getChildsByType($target_id, $ref_id);
1019  foreach ($possibleChilds as $child)
1020  {
1021  if ($child["obj_id"] == $ref_id)
1022  return $this->__raiseError("Object already exists in target.","Client");
1023  }
1024 
1025  // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
1026  $node_data = $tree->getNodeData($ref_id);
1027  $subtree_nodes = $tree->getSubTree($node_data);
1028 
1029  $all_node_data[] = $node_data;
1030  $all_subtree_nodes[] = $subtree_nodes;
1031 
1032  // CHECK DELETE PERMISSION OF ALL OBJECTS IN ACTUAL SUBTREE
1033  foreach ($subtree_nodes as $node)
1034  {
1035  if($node['type'] == 'rolf')
1036  {
1037  continue;
1038  }
1039 
1040  if (!$rbacsystem->checkAccess('delete',$node["ref_id"]))
1041  {
1042  $no_cut[] = $node["ref_id"];
1043  }
1044  }
1045 
1046  // IF THERE IS ANY OBJECT WITH NO PERMISSION TO 'delete'
1047  if (count($no_cut))
1048  {
1049  return $this->__raiseError("Object contains references which you are not allowed to delete.","Client");
1050  }
1051 
1052  // CHECK IF PASTE OBJECT SHALL BE CHILD OF ITSELF
1053  if ($tree->isGrandChild($ref_id,$target_id))
1054  {
1055  return $this->__raiseError("Cannot move object into itself.","Client");
1056  }
1057 
1058  $old_parent = $tree->getParentId($ref_id);
1059  $tree->moveTree($ref_id,$target_id);
1060  $rbacadmin->adjustMovedObjectPermissions($ref_id,$old_parent);
1061 
1062  include_once('classes/class.ilConditionHandler.php');
1064  return true;
1065  }
1066 
1072  function copyObject($sid, $copy_settings_xml) {
1073  if(!$this->__checkSession($sid))
1074  {
1075  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
1076  }
1077 
1078 
1079  // Include main header
1080  include_once './include/inc.header.php';
1081  include_once './webservice/soap/classes/class.ilSoapUtils.php';
1082  global $rbacreview, $objDefinition, $rbacsystem, $lng, $ilUser;
1083 
1084  include_once './webservice/soap/classes/class.ilCopyWizardSettingsXMLParser.php';
1085  $xml_parser = new ilCopyWizardSettingsXMLParser($copy_settings_xml);
1086  try {
1087  $xml_parser->startParsing();
1088  } catch (ilSaxParserException $se){
1089  return $this->__raiseError($se->getMessage(), "Client");
1090  }
1091 
1092  // checking copy permissions, objects and create permissions
1093  if(!$rbacsystem->checkAccess('copy',$xml_parser->getSourceId()))
1094  {
1095  return $this->__raiseError("Missing copy permissions for object with reference id ".$xml_parser->getSourceId(), 'Client');
1096  }
1097 
1098  // checking copy permissions, objects and create permissions
1099  $source_id = $xml_parser->getSourceId();
1100  $target_id = $xml_parser->getTargetId();
1101 
1102 
1103  // does source object exist
1104  if(!$source_object_type = ilObjectFactory::getTypeByRefId($source_id, false))
1105  {
1106  return $this->__raiseError('No valid source given.', 'Client');
1107  }
1108 
1109  // does target object exist
1110  if(!$target_object_type = ilObjectFactory::getTypeByRefId($xml_parser->getTargetId(), false))
1111  {
1112  return $this->__raiseError('No valid target given.', 'Client');
1113  }
1114 
1115 
1116  $canAddType = $this->canAddType($source_object_type, $target_object_type, $target_id);
1117  if ($this->isFault($canAddType))
1118  {
1119  return $canAddType;
1120  }
1121 
1122  // if is container object than clone with sub items
1123  $options = $xml_parser->getOptions();
1124 // print_r($options);
1125  $source_object = ilObjectFactory::getInstanceByRefId($source_id);
1126  if ($source_object instanceof ilContainer) {
1127  // get client id from sid
1128  $clientid = substr($sid, strpos($sid, "::") + 2);
1129  $sessionid = str_replace("::".$clientid, "", $sid);
1130  // call container clone
1131  return $source_object->cloneAllObject($sessionid, $clientid,
1132  $source_object_type,
1133  $target_id,
1134  $source_id,
1135  $options, true);
1136 
1137  } else {
1138  // create copy wizard settings
1140  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
1141  $wizard_options->saveOwner($ilUser->getId());
1142  $wizard_options->saveRoot($source_id);
1143 
1144  foreach($options as $source_id => $option)
1145  {
1146  $wizard_options->addEntry($source_id,$option);
1147  }
1148  $wizard_options->read();
1149 
1150  // call object clone
1151  $newObject = $source_object->cloneObject($xml_parser->getTargetId(), $copy_id);
1152  return is_object($newObject) ? $newObject->getRefId() : -1;
1153  }
1154  }
1155 
1156  function getPathForRefId($sid, $ref_id) {
1157  if(!$this->__checkSession($sid))
1158  {
1159  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
1160  }
1161 
1162 
1163  // Include main header
1164  include_once './include/inc.header.php';
1165  global $ilAccess, $objDefinition, $rbacsystem, $lng, $ilUser;
1166 
1167  if(!$rbacsystem->checkAccess('read', $ref_id))
1168  {
1169  return $this->__raiseError("Missing read permissions for object with reference id ".$ref_id, 'Client');
1170  }
1171 
1173  {
1174  return $this->__raiseError("Object is in Trash", 'Client');
1175  }
1176  global $tree, $lng;
1177  $items = $tree->getPathFull($ref_id);
1178 
1179  include_once 'webservice/soap/classes/class.ilXMLResultSet.php';
1180  include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
1181  include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
1182 
1183  $xmlResultSet = new ilXMLResultSet();
1184  $xmlResultSet->addColumn("ref_id");
1185  $xmlResultSet->addColumn("type");
1186  $xmlResultSet->addColumn("title");
1187 
1188  $writer = new ilXMLResultSetWriter($xmlResultSet);
1189  foreach ($items as $item) {
1190  if ($item["ref_id"] == $ref_id)
1191  continue;
1192  if ($item["title"] == "ILIAS" && $item["type"] == "root")
1193  {
1194  $item["title"] = $lng->txt("repository");
1195  }
1196 
1197  $row = new ilXMLResultSetRow();
1198  $xmlResultSet->addRow($row);
1199  $row->setValue("ref_id", $item["ref_id"]);
1200  $row->setValue("type", $item["type"]);
1201  $row->setValue("title", $item["title"]);
1202  }
1203  $writer->start();
1204  return $writer->getXML();
1205  }
1206 
1207 
1208  private function canAddType ($type, $target_type, $target_id) {
1209  // checking for target subtypes. Can we add source to target
1210  global $objDefinition, $rbacsystem;
1211 
1212  $allowed_types = array('root','cat','grp','crs','fold');
1213  if(!in_array($target_type, $allowed_types))
1214  {
1215  return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
1216  }
1217 
1218  $allowed_subtypes = $objDefinition->getSubObjects($target_type);
1219  $allowed = array();
1220 
1221  foreach($allowed_subtypes as $row)
1222  {
1223  if($row['name'] != 'rolf')
1224  {
1225  $allowed[] = $row['name'];
1226  }
1227  }
1228 
1229  if(!in_array($type, $allowed))
1230  {
1231  return $this->__raiseError('Objects of type: '.$type.' are not allowed to be subobjects of type '.$target_type.'!','Client');
1232  }
1233  if(!$rbacsystem->checkAccess('create',$target_id, $type))
1234  {
1235  return $this->__raiseError('No permission to create objects of type '.$type.'!', 'Client');
1236  }
1237 
1238  return true;
1239  }
1240 
1241 }
1242 ?>