ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapWebLinkAdministration.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './webservice/soap/classes/class.ilSoapAdministration.php';
5 
14 {
18  public function __construct()
19  {
21  }
22 
29  public function readWebLink($sid,$ref_id)
30  {
31  $this->initAuth($sid);
32  $this->initIlias();
33 
34  if(!$this->__checkSession($sid))
35  {
36  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
37  }
38  if(!strlen($ref_id))
39  {
40  return $this->__raiseError('No ref id given. Aborting!',
41  'Client');
42  }
43  global $rbacsystem, $tree, $ilLog;
44 
45  // get obj_id
46  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
47  {
48  return $this->__raiseError('No weblink found for id: '.$ref_id,
49  'Client');
50  }
51 
53  {
54  return $this->__raiseError("Parent with ID $ref_id has been deleted.", 'Client');
55  }
56 
57  // Check access
58  $permission_ok = false;
59  $write_permission_ok = false;
60  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
61  {
62  if($rbacsystem->checkAccess('edit',$ref_id))
63  {
64  $write_permission_ok = true;
65  break;
66  }
67  if($rbacsystem->checkAccess('read',$ref_id))
68  {
69  $permission_ok = true;
70  break;
71  }
72 
73  }
74 
75  if(!$permission_ok && !$write_permission_ok)
76  {
77  return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
78  'Server');
79  }
80 
81  try
82  {
83  include_once './Modules/WebResource/classes/class.ilWebLinkXmlWriter.php';
84  $writer = new ilWebLinkXmlWriter();
85  $writer->setObjId($obj_id);
86  $writer->write();
87 
88  return $writer->xmlDumpMem(true);
89  }
90  catch(UnexpectedValueException $e)
91  {
92  return $this->__raiseError($e->getMessage(), 'Client');
93  }
94  }
95 
105  public function createWebLink($sid,$target_id, $weblink_xml)
106  {
107  $this->initAuth($sid);
108  $this->initIlias();
109 
110  if(!$this->__checkSession($sid))
111  {
112  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
113  }
114  global $rbacsystem, $tree, $ilLog;
115 
116  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id,false))
117  {
118  return $this->__raiseError('No valid target given.', 'Client');
119  }
120 
122  {
123  return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
124  }
125 
126  // Check access
127  // TODO: read from object definition
128  $allowed_types = array('cat','grp','crs','fold','root');
129  if(!in_array($target_obj->getType(), $allowed_types))
130  {
131  return $this->__raiseError('No valid target type. Target must be reference id of "course, group, root, category or folder"', 'Client');
132  }
133 
134  if(!$rbacsystem->checkAccess('create',$target_id,"webr"))
135  {
136  return $this->__raiseError('No permission to create weblink in target '.$target_id.'!', 'Client');
137  }
138 
139 
140  // create object, put it into the tree and use the parser to update the settings
141  include_once './Modules/WebResource/classes/class.ilObjLinkResource.php';
142  include_once './Modules/WebResource/classes/class.ilWebLinkXmlParser.php';
143 
144  $webl = new ilObjLinkResource();
145  $webl->setTitle('XML Import');
146  $webl->create(true);
147  $webl->createReference();
148  $webl->putInTree($target_id);
149  $webl->setPermissions($target_id);
150 
151  try
152  {
153  $parser = new ilWebLinkXmlParser($webl,$weblink_xml);
154  $parser->setMode(ilWebLinkXmlParser::MODE_CREATE);
155  $parser->start();
156  }
157  catch(ilSaxParserException $e)
158  {
159  return $this->__raiseError($e->getMessage(),'Client');
160  }
161  catch(ilWebLinkXMLParserException $e)
162  {
163  return $this->__raiseError($e->getMessage(),'Client');
164  }
165 
166  // Check if required
167  return $webl->getRefId();
168  }
169 
179  function updateWebLink($sid, $ref_id, $weblink_xml)
180  {
181  $this->initAuth($sid);
182  $this->initIlias();
183 
184  if(!$this->__checkSession($sid))
185  {
186  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
187  }
188  global $rbacsystem, $tree, $ilLog;
189 
191  {
192  return $this->__raiseError('Cannot perform update since weblink has been deleted.', 'CLIENT_OBJECT_DELETED');
193  }
194  // get obj_id
195  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
196  {
197  return $this->__raiseError('No weblink found for id: '.$ref_id,
198  'CLIENT_OBJECT_NOT_FOUND');
199  }
200 
201  // Check access
202  $permission_ok = false;
203  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
204  {
205  if($rbacsystem->checkAccess('edit',$ref_id))
206  {
207  $permission_ok = true;
208  break;
209  }
210  }
211 
212  if(!$permission_ok)
213  {
214  return $this->__raiseError('No permission to edit the weblink with id: '.$ref_id,
215  'Server');
216  }
217 
218  $webl = ilObjectFactory::getInstanceByObjId($obj_id, false);
219  if(!is_object($webl) or $webl->getType()!= "webr")
220  {
221  return $this->__raiseError('Wrong obj id or type for weblink with id '.$ref_id,
222  'Client');
223  }
224 
225  try
226  {
227  include_once './Modules/WebResource/classes/class.ilWebLinkXmlParser.php';
228  $parser = new ilWebLinkXmlParser($webl,$weblink_xml);
229  $parser->setMode(ilWebLinkXmlParser::MODE_UPDATE);
230  $parser->start();
231  }
232  catch(ilSaxParserException $e)
233  {
234  return $this->__raiseError($e->getMessage(),'Client');
235  }
236  catch(ilWebLinkXMLParserException $e)
237  {
238  return $this->__raiseError($e->getMessage(),'Client');
239  }
240 
241  // Check if required
242  return true;
243  }
244 }
245 ?>