• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

webservice/soap/classes/class.ilSoapFileAdministration.php

Go to the documentation of this file.
00001 <?php
00002   /*
00003    +-----------------------------------------------------------------------------+
00004    | ILIAS open source                                                           |
00005    +-----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007    |                                                                             |
00008    | This program is free software; you can redistribute it and/or               |
00009    | modify it under the terms of the GNU General Public License                 |
00010    | as published by the Free Software Foundation; either version 2              |
00011    | of the License, or (at your option) any later version.                      |
00012    |                                                                             |
00013    | This program is distributed in the hope that it will be useful,             |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016    | GNU General Public License for more details.                                |
00017    |                                                                             |
00018    | You should have received a copy of the GNU General Public License           |
00019    | along with this program; if not, write to the Free Software                 |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021    +-----------------------------------------------------------------------------+
00022   */
00023 
00024 
00033 include_once './webservice/soap/classes/class.ilSoapAdministration.php';
00034 
00035 class ilSoapFileAdministration extends ilSoapAdministration
00036 {
00037         function ilSoapFileAdministration()
00038         {
00039                 parent::ilSoapAdministration();
00040         }
00041 
00051         function addFile ($sid, $target_id, $file_xml) {
00052 
00053             if(!$this->__checkSession($sid))
00054                 {
00055                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00056                 }
00057         include_once './include/inc.header.php';
00058         global $rbacsystem, $tree, $ilLog;
00059 
00060         if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id,false))
00061                 {
00062                         return $this->__raiseError('No valid target given.', 'Client');
00063                 }
00064 
00065 
00066                 if(ilObject::_isInTrash($target_id))
00067                 {
00068                         return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_TARGET_DELETED');
00069                 }
00070 
00071                 // Check access
00072                 $allowed_types = array('cat','grp','crs','fold');
00073                 if(!in_array($target_obj->getType(), $allowed_types))
00074                 {
00075                         return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
00076                 }
00077 
00078             if(!$rbacsystem->checkAccess('create',$target_id,"file"))
00079                 {
00080                         return $this->__raiseError('No permission to create Files in target  '.$target_id.'!', 'Client');
00081                 }
00082 
00083         // create object, put it into the tree and use the parser to update the settings
00084                 include_once './Modules/File/classes/class.ilFileXMLParser.php';
00085                 include_once './Modules/File/classes/class.ilFileException.php';
00086                 include_once './Modules/File/classes/class.ilObjFile.php';
00087 
00088                 $file = new ilObjFile();
00089     try
00090         {
00091 
00092                 $fileXMLParser = new ilFileXMLParser($file, $file_xml);
00093 
00094                 if ($fileXMLParser->start()) 
00095                 {
00096           $file->create();
00097                 $file->createReference();
00098                 $file->putInTree($target_id);
00099                 $file->setPermissions($target_id);
00100 
00101                 // we now can save the file contents since we know the obj id now.
00102                 $fileXMLParser->setFileContents();
00103 
00104           return $file->getRefId();
00105         } else 
00106         {
00107                 return $this->__raiseError("Could not add file", "Server");
00108         } 
00109         } catch(ilFileException $exception) {
00110           return $this->__raiseError($exception->getMessage(), $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server");
00111         }
00112            }
00113 
00114 
00124         function updateFile ($sid, $ref_id, $file_xml) {
00125             if(!$this->__checkSession($sid))
00126                 {
00127                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00128                 }
00129         include_once './include/inc.header.php';
00130         global $rbacsystem, $tree, $ilLog;
00131 
00132                 if(ilObject::_isInTrash($ref_id))
00133                 {
00134                         return $this->__raiseError('Cannot perform update since file has been deleted.', 'CLIENT_OBJECT_DELETED');
00135                 }
00136         // get obj_id
00137                 if(!$obj_id = ilObject::_lookupObjectId($ref_id))
00138                 {
00139                         return $this->__raiseError('No File found for id: '.$ref_id,
00140                                                                            'Client');
00141                 }
00142 
00143                 // Check access
00144                 $permission_ok = false;
00145                 foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
00146                 {
00147                         if($rbacsystem->checkAccess('edit',$ref_id))
00148                         {
00149                                 $permission_ok = true;
00150                                 break;
00151                         }
00152                 }
00153 
00154                 if(!$permission_ok)
00155                 {
00156                         return $this->__raiseError('No permission to edit the File with id: '.$ref_id,
00157                                                                            'Server');
00158                 }
00159 
00160 
00161                 $file = ilObjectFactory::getInstanceByObjId($obj_id, false);
00162 
00163                 if (!is_object($file) || $file->getType()!= "file")
00164                 {
00165             return $this->__raiseError('Wrong obj id or type for File with id '.$ref_id,
00166                                                                            'Server');
00167                 }
00168 
00169                 include_once './Modules/File/classes/class.ilFileXMLParser.php';
00170                 include_once './Modules/File/classes/class.ilFileException.php';
00171         $fileXMLParser = new ilFileXMLParser($file, $file_xml, $obj_id);
00172 
00173         try
00174         {
00175 
00176             if ($fileXMLParser->start())
00177             {
00178                 $fileXMLParser->updateFileContents();
00179 
00180                 return  $file->update();
00181             }
00182         } catch(ilFileException $exception) {
00183            return $this->__raiseError($exception->getMessage(),
00184                                                                            $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server");
00185         }
00186         return false;
00187     }
00188 
00199         function getFileXML ($sid, $ref_id, $attachFileContentsMode) {
00200             if(!$this->__checkSession($sid))
00201                 {
00202                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00203                 }
00204                 if(!strlen($ref_id))
00205                 {
00206                         return $this->__raiseError('No ref id given. Aborting!',
00207                                                                            'Client');
00208                 }
00209             include_once './include/inc.header.php';
00210                 global $rbacsystem, $tree, $ilLog;
00211 
00212 
00213                 // get obj_id
00214                 if(!$obj_id = ilObject::_lookupObjectId($ref_id))
00215                 {
00216                         return $this->__raiseError('No File found for id: '.$ref_id,
00217                                                                            'Client');
00218                 }
00219 
00220                 if(ilObject::_isInTrash($ref_id))
00221                 {
00222                         return $this->__raiseError("Object with ID $ref_id has been deleted.", 'Client');
00223                 }
00224 
00225                 // Check access
00226                 $permission_ok = false;
00227                 foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
00228                 {
00229                         if($rbacsystem->checkAccess('read',$ref_id))
00230                         {
00231                                 $permission_ok = true;
00232                                 break;
00233                         }
00234                 }
00235 
00236                 if(!$permission_ok)
00237                 {
00238                         return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
00239                                                                            'Server');
00240                 }
00241 
00242                 $file = ilObjectFactory::getInstanceByObjId($obj_id, false);
00243 
00244                 if (!is_object($file) || $file->getType()!= "file")
00245                 {
00246             return $this->__raiseError('Wrong obj id or type for File with id '.$ref_id,
00247                                                                            'Server');
00248                 }
00249             // store into xml result set
00250                 include_once './Modules/File/classes/class.ilFileXMLWriter.php';
00251 
00252                 // create writer
00253                 $xmlWriter = new ilFileXMLWriter();
00254                 $xmlWriter->setFile($file);
00255                 $xmlWriter->setAttachFileContents($attachFileContentsMode);
00256                 $xmlWriter->start();
00257 
00258                 return $xmlWriter->getXML();
00259         }
00260 }
00261 ?>

Generated on Fri Dec 13 2013 17:57:03 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1