ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
37 
47  public function addFile($sid, $target_id, $file_xml)
48  {
49  $this->initAuth($sid);
50  $this->initIlias();
51 
52  if (!$this->__checkSession($sid)) {
53  return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
54  }
55  global $rbacsystem, $tree, $ilLog, $ilAccess;
56 
57  if (!$target_obj =&ilObjectFactory::getInstanceByRefId($target_id, false)) {
58  return $this->__raiseError('No valid target given.', 'Client');
59  }
60 
61 
63  return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_TARGET_DELETED');
64  }
65 
66  // Check access
67  $allowed_types = array('cat','grp','crs','fold','root');
68  if (!in_array($target_obj->getType(), $allowed_types)) {
69  return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
70  }
71 
72  if (!$ilAccess->checkAccess('create', '', $target_id, "file")) {
73  return $this->__raiseError('No permission to create Files in target ' . $target_id . '!', 'Client');
74  }
75 
76  // create object, put it into the tree and use the parser to update the settings
77  include_once './Modules/File/classes/class.ilFileXMLParser.php';
78  include_once './Modules/File/classes/class.ilFileException.php';
79  include_once './Modules/File/classes/class.ilObjFile.php';
80 
81  $file = new ilObjFile();
82  try {
83  $fileXMLParser = new ilFileXMLParser($file, $file_xml);
84 
85  if ($fileXMLParser->start()) {
86  global $ilLog;
87 
88  $ilLog->write(__METHOD__ . ': File type: ' . $file->getFileType());
89 
90  $file->create();
91  $file->createReference();
92  $file->putInTree($target_id);
93  $file->setPermissions($target_id);
94 
95  // we now can save the file contents since we know the obj id now.
96  $fileXMLParser->setFileContents();
97  #$file->update();
98 
99  return $file->getRefId();
100  } else {
101  return $this->__raiseError("Could not add file", "Server");
102  }
103  } catch (ilFileException $exception) {
104  return $this->__raiseError($exception->getMessage(), $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server");
105  }
106  }
107 
108 
118  public function updateFile($sid, $ref_id, $file_xml)
119  {
120  $this->initAuth($sid);
121  $this->initIlias();
122 
123  if (!$this->__checkSession($sid)) {
124  return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
125  }
126  global $rbacsystem, $tree, $ilLog, $ilAccess;
127 
128  if (ilObject::_isInTrash($ref_id)) {
129  return $this->__raiseError('Cannot perform update since file has been deleted.', 'CLIENT_OBJECT_DELETED');
130  }
131  // get obj_id
132  if (!$obj_id = ilObject::_lookupObjectId($ref_id)) {
133  return $this->__raiseError(
134  'No File found for id: ' . $ref_id,
135  'Client'
136  );
137  }
138 
139  // Check access
140  $permission_ok = false;
141  foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
142  if ($ilAccess->checkAccess('write', '', $ref_id)) {
143  $permission_ok = true;
144  break;
145  }
146  }
147 
148  if (!$permission_ok) {
149  return $this->__raiseError(
150  'No permission to edit the File with id: ' . $ref_id,
151  'Server'
152  );
153  }
154 
155 
156  $file = ilObjectFactory::getInstanceByObjId($obj_id, false);
157 
158  if (!is_object($file) || $file->getType()!= "file") {
159  return $this->__raiseError(
160  'Wrong obj id or type for File with id ' . $ref_id,
161  'Server'
162  );
163  }
164 
165  include_once './Modules/File/classes/class.ilFileXMLParser.php';
166  include_once './Modules/File/classes/class.ilFileException.php';
167  $fileXMLParser = new ilFileXMLParser($file, $file_xml, $obj_id);
168 
169  try {
170  if ($fileXMLParser->start()) {
171  $fileXMLParser->updateFileContents();
172 
173  return $file->update();
174  }
175  } catch (ilFileException $exception) {
176  return $this->__raiseError(
177  $exception->getMessage(),
178  $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server"
179  );
180  }
181  return false;
182  }
183 
194  public function getFileXML($sid, $ref_id, $attachFileContentsMode)
195  {
196  $this->initAuth($sid);
197  $this->initIlias();
198 
199  if (!$this->__checkSession($sid)) {
200  return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
201  }
202  if (!strlen($ref_id)) {
203  return $this->__raiseError(
204  'No ref id given. Aborting!',
205  'Client'
206  );
207  }
208  global $rbacsystem, $tree, $ilLog, $ilAccess;
209 
210 
211  // get obj_id
212  if (!$obj_id = ilObject::_lookupObjectId($ref_id)) {
213  return $this->__raiseError(
214  'No File found for id: ' . $ref_id,
215  'Client'
216  );
217  }
218 
219  if (ilObject::_isInTrash($ref_id)) {
220  return $this->__raiseError("Object with ID $ref_id has been deleted.", 'Client');
221  }
222 
223  // Check access
224  $permission_ok = false;
225  foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
226  if ($ilAccess->checkAccess('read', '', $ref_id)) {
227  $permission_ok = true;
228  break;
229  }
230  }
231 
232  if (!$permission_ok) {
233  return $this->__raiseError(
234  'No permission to edit the object with id: ' . $ref_id,
235  'Server'
236  );
237  }
238 
239  $file = ilObjectFactory::getInstanceByObjId($obj_id, false);
240 
241  if (!is_object($file) || $file->getType()!= "file") {
242  return $this->__raiseError(
243  'Wrong obj id or type for File with id ' . $ref_id,
244  'Server'
245  );
246  }
247  // store into xml result set
248  include_once './Modules/File/classes/class.ilFileXMLWriter.php';
249 
250  // create writer
251  $xmlWriter = new ilFileXMLWriter();
252  $xmlWriter->setFile($file);
253  $xmlWriter->setAttachFileContents($attachFileContentsMode);
254  $xmlWriter->start();
255 
256  return $xmlWriter->getXML();
257  }
258 }
addFile($sid, $target_id, $file_xml)
add an File with id.
static _isInTrash($a_ref_id)
checks wether object is in trash
$target_id
Definition: goto.php:49
Exercise XML Parser which completes/updates a given file by an xml string.
static _getAllReferences($a_id)
get all reference ids of object
static _lookupObjectId($a_ref_id)
lookup object id
updateFile($sid, $ref_id, $file_xml)
update a File with id.
__raiseError($a_message, $a_code)
Class to report exception.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
XML writer class.
getFileXML($sid, $ref_id, $attachFileContentsMode)
get File xml
initAuth($sid)
Init authentication.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file