ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapFileAdministration.php
Go to the documentation of this file.
1 <?php
2  /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
51  function addFile ($sid, $target_id, $file_xml) {
52 
53  if(!$this->__checkSession($sid))
54  {
55  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
56  }
57  include_once './include/inc.header.php';
58  global $rbacsystem, $tree, $ilLog;
59 
60  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id,false))
61  {
62  return $this->__raiseError('No valid target given.', 'Client');
63  }
64 
65 
67  {
68  return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_TARGET_DELETED');
69  }
70 
71  // Check access
72  $allowed_types = array('cat','grp','crs','fold');
73  if(!in_array($target_obj->getType(), $allowed_types))
74  {
75  return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
76  }
77 
78  if(!$rbacsystem->checkAccess('create',$target_id,"file"))
79  {
80  return $this->__raiseError('No permission to create Files in target '.$target_id.'!', 'Client');
81  }
82 
83  // create object, put it into the tree and use the parser to update the settings
84  include_once './Modules/File/classes/class.ilFileXMLParser.php';
85  include_once './Modules/File/classes/class.ilFileException.php';
86  include_once './Modules/File/classes/class.ilObjFile.php';
87 
88  $file = new ilObjFile();
89  try
90  {
91 
92  $fileXMLParser = new ilFileXMLParser($file, $file_xml);
93 
94  if ($fileXMLParser->start())
95  {
96  global $ilLog;
97 
98  $ilLog->write(__METHOD__.': File type: '.$file->getFileType());
99 
100  $file->create();
101  $file->createReference();
102  $file->putInTree($target_id);
103  $file->setPermissions($target_id);
104 
105  // we now can save the file contents since we know the obj id now.
106  $fileXMLParser->setFileContents();
107  #$file->update();
108 
109  return $file->getRefId();
110  }
111  else
112  {
113  return $this->__raiseError("Could not add file", "Server");
114  }
115  }
116  catch(ilFileException $exception) {
117  return $this->__raiseError($exception->getMessage(), $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server");
118  }
119  }
120 
121 
131  function updateFile ($sid, $ref_id, $file_xml) {
132  if(!$this->__checkSession($sid))
133  {
134  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
135  }
136  include_once './include/inc.header.php';
137  global $rbacsystem, $tree, $ilLog;
138 
140  {
141  return $this->__raiseError('Cannot perform update since file has been deleted.', 'CLIENT_OBJECT_DELETED');
142  }
143  // get obj_id
144  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
145  {
146  return $this->__raiseError('No File found for id: '.$ref_id,
147  'Client');
148  }
149 
150  // Check access
151  $permission_ok = false;
152  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
153  {
154  if($rbacsystem->checkAccess('edit',$ref_id))
155  {
156  $permission_ok = true;
157  break;
158  }
159  }
160 
161  if(!$permission_ok)
162  {
163  return $this->__raiseError('No permission to edit the File with id: '.$ref_id,
164  'Server');
165  }
166 
167 
168  $file = ilObjectFactory::getInstanceByObjId($obj_id, false);
169 
170  if (!is_object($file) || $file->getType()!= "file")
171  {
172  return $this->__raiseError('Wrong obj id or type for File with id '.$ref_id,
173  'Server');
174  }
175 
176  include_once './Modules/File/classes/class.ilFileXMLParser.php';
177  include_once './Modules/File/classes/class.ilFileException.php';
178  $fileXMLParser = new ilFileXMLParser($file, $file_xml, $obj_id);
179 
180  try
181  {
182 
183  if ($fileXMLParser->start())
184  {
185  $fileXMLParser->updateFileContents();
186 
187  return $file->update();
188  }
189  }
190  catch(ilFileException $exception)
191  {
192  return $this->__raiseError($exception->getMessage(),
193  $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server");
194  }
195  return false;
196  }
197 
208  function getFileXML ($sid, $ref_id, $attachFileContentsMode) {
209  if(!$this->__checkSession($sid))
210  {
211  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
212  }
213  if(!strlen($ref_id))
214  {
215  return $this->__raiseError('No ref id given. Aborting!',
216  'Client');
217  }
218  include_once './include/inc.header.php';
219  global $rbacsystem, $tree, $ilLog;
220 
221 
222  // get obj_id
223  if(!$obj_id = ilObject::_lookupObjectId($ref_id))
224  {
225  return $this->__raiseError('No File found for id: '.$ref_id,
226  'Client');
227  }
228 
230  {
231  return $this->__raiseError("Object with ID $ref_id has been deleted.", 'Client');
232  }
233 
234  // Check access
235  $permission_ok = false;
236  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
237  {
238  if($rbacsystem->checkAccess('read',$ref_id))
239  {
240  $permission_ok = true;
241  break;
242  }
243  }
244 
245  if(!$permission_ok)
246  {
247  return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
248  'Server');
249  }
250 
251  $file = ilObjectFactory::getInstanceByObjId($obj_id, false);
252 
253  if (!is_object($file) || $file->getType()!= "file")
254  {
255  return $this->__raiseError('Wrong obj id or type for File with id '.$ref_id,
256  'Server');
257  }
258  // store into xml result set
259  include_once './Modules/File/classes/class.ilFileXMLWriter.php';
260 
261  // create writer
262  $xmlWriter = new ilFileXMLWriter();
263  $xmlWriter->setFile($file);
264  $xmlWriter->setAttachFileContents($attachFileContentsMode);
265  $xmlWriter->start();
266 
267  return $xmlWriter->getXML();
268  }
269 }
270 ?>