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

webservice/soap/classes/class.ilSoapUtils.php

Go to the documentation of this file.
00001 <?php
00002   /*
00003    +-----------------------------------------------------------------------------+
00004    | ILIAS open source                                                           |
00005    +-----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 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 ilSoapUtils extends ilSoapAdministration
00036 {
00037         function ilSoapUtils()
00038         {
00039                 parent::ilSoapAdministration();
00040         }
00041 
00042         function ignoreUserAbort()
00043         {
00044                 ignore_user_abort();
00045         }
00046 
00047         function disableSOAPCheck()
00048         {
00049                 $this->sauth->disableSOAPCheck();
00050         }
00051         
00052         function sendMail($sid,$to,$cc,$bcc,$sender,$subject,$message,$attach)
00053         {
00054                 if(!$this->__checkSession($sid))
00055                 {
00056                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00057                 }                       
00058 
00059                 // Include main header
00060                 include_once './include/inc.header.php';
00061 
00062                 global $ilLog;
00063 
00064                 include_once 'Services/Mail/classes/class.ilMimeMail.php';
00065 
00066                 $mmail = new ilMimeMail();
00067                 $mmail->autoCheck(false);
00068                 $mmail->From($sender);
00069                 $mmail->To(explode(',',$to));
00070                 $mmail->Subject($subject);
00071                 $mmail->Body($message);
00072 
00073                 if($cc)
00074                 {
00075                         $mmail->Cc(explode(',',$cc));
00076                 }
00077 
00078                 if($bcc)
00079                 {
00080                         $mmail->Bcc(explode(',',$bcc));
00081                 }
00082                 if($attach)
00083                 {
00084                         $attachments = explode(',',$attach);
00085                         foreach ($attachments as $attachment)
00086                         {
00087                                 $mmail->Attach($attachment);
00088                         }
00089                 }
00090 
00091                 $mmail->Send();
00092                 $ilLog->write('SOAP: sendMail(): '.$to.', '.$cc.', '.$bcc);
00093 
00094                 return true;
00095         }
00096         
00097         function saveTempFileAsMediaObject($sid, $name, $tmp_name)
00098         {
00099                 if(!$this->__checkSession($sid))
00100                 {
00101                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00102                 }                       
00103 
00104                 // Include main header
00105                 include_once './include/inc.header.php';
00106                 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
00107                 return ilObjMediaObject::_saveTempFileAsMediaObject($name, $tmp_name);
00108         }
00109         
00110         function getMobsOfObject($sid, $a_type, $a_id)
00111         {
00112                 if(!$this->__checkSession($sid))
00113                 {
00114                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00115                 }                       
00116 
00117                 // Include main header
00118                 include_once './include/inc.header.php';
00119                 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
00120                 return ilObjMediaObject::_getMobsOfObject($a_type, $a_id);
00121         }
00122         
00130         public function ilCloneDependencies($sid,$copy_identifier)
00131         {
00132                 if(!$this->__checkSession($sid))
00133                 {
00134                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00135                 }                       
00136 
00137                 // Include main header
00138                 include_once './include/inc.header.php';
00139                 
00140                 global $ilLog,$ilUser;
00141 
00142                 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
00143                 $cp_options = ilCopyWizardOptions::_getInstance($copy_identifier);
00144                 
00145                 // Check owner of copy procedure
00146                 if(!$cp_options->checkOwner($ilUser->getId()))
00147                 {
00148                         $ilLog->write(__METHOD__.': Permission check failed for user id: '.$ilUser->getId().', copy id: '.$copy_identifier);
00149                         return false;
00150                 }
00151                 
00152                 // Fetch first node
00153                 if(($node = $cp_options->fetchFirstDependenciesNode()) === false)
00154                 {
00155                         $cp_options->deleteAll();
00156                         $ilLog->write(__METHOD__.': Finished copy step 2. Copy completed');
00157                         
00158                         return true;
00159                 }
00160 
00161                 // Check options of this node
00162                 $options = $cp_options->getOptions($node['child']);
00163                 $new_ref_id = 0;
00164                 switch($options['type'])
00165                 {
00166                         case ilCopyWizardOptions::COPY_WIZARD_OMIT:
00167                                 $ilLog->write(__METHOD__.': Omitting node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
00168                                 $this->callNextDependency($sid,$cp_options);
00169                                 break;
00170                         
00171                         case ilCopyWizardOptions::COPY_WIZARD_LINK:
00172                                 $ilLog->write(__METHOD__.': Nothing to do for node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
00173                                 $this->callNextDependency($sid,$cp_options);
00174                                 break;
00175                                 
00176                         case ilCopyWizardOptions::COPY_WIZARD_COPY:
00177                                 $ilLog->write(__METHOD__.': Start cloning dependencies: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
00178                                 $this->cloneDependencies($node,$cp_options);
00179                                 $this->callNextDependency($sid,$cp_options);
00180                                 break;
00181                                 
00182                         default:
00183                                 $ilLog->write(__METHOD__.': No valid action type given for node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
00184                                 $this->callNextDependency($sid,$cp_options);
00185                                 break;
00186                 }
00187                 return true;
00188         }
00189         
00198         public function ilClone($sid,$copy_identifier)
00199         {
00200                 if(!$this->__checkSession($sid))
00201                 {
00202                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00203                 }                       
00204 
00205                 // Include main header
00206                 include_once './include/inc.header.php';
00207                 
00208                 global $ilLog,$ilUser;
00209                 
00210                 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
00211                 $cp_options = ilCopyWizardOptions::_getInstance($copy_identifier);
00212                 
00213                 // Check owner of copy procedure
00214                 if(!$cp_options->checkOwner($ilUser->getId()))
00215                 {
00216                         $ilLog->write(__METHOD__.': Permission check failed for user id: '.$ilUser->getId().', copy id: '.$copy_identifier);
00217                         return false;
00218                 }
00219                 
00220                 
00221                 // Fetch first node
00222                 if(($node = $cp_options->fetchFirstNode()) === false)
00223                 {
00224                         $ilLog->write(__METHOD__.': Finished copy step 1. Starting copying of object dependencies...');
00225                         return $this->ilCloneDependencies($sid,$copy_identifier);
00226                 }
00227         
00228                 // Check options of this node
00229                 $options = $cp_options->getOptions($node['child']);
00230                 
00231                 $new_ref_id = 0;
00232                 switch($options['type'])
00233                 {
00234                         case ilCopyWizardOptions::COPY_WIZARD_OMIT:
00235                                 $ilLog->write(__METHOD__.': Omitting node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
00236                                 // set mapping to zero
00237                                 $cp_options->appendMapping($node['child'],0);
00238                                 $this->callNextNode($sid,$cp_options);
00239                                 break;
00240                                 
00241                         case ilCopyWizardOptions::COPY_WIZARD_COPY:
00242                                 $ilLog->write(__METHOD__.': Start cloning node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
00243                                 $new_ref_id = $this->cloneNode($node,$cp_options);
00244                                 $this->callNextNode($sid,$cp_options);
00245                                 break;
00246                         
00247                         case ilCopyWizardOptions::COPY_WIZARD_LINK:
00248                                 $ilLog->write(__METHOD__.': Start linking node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
00249                                 $new_ref_id = $this->linkNode($node,$cp_options);
00250                                 $this->callNextNode($sid,$cp_options);
00251                                 break;
00252 
00253                         default:
00254                                 $ilLog->write(__METHOD__.': No valid action type given for node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
00255                                 $this->callNextNode($sid,$cp_options);
00256                                 break;
00257                                 
00258                 }
00259                 return $new_ref_id;
00260         }
00261         
00268         private function callNextNode($sid,$cp_options)
00269         {
00270                 global $ilLog;
00271 
00272                 $cp_options->dropFirstNode();
00273 
00274                 if($cp_options->isSOAPEnabled())
00275                 {
00276                         // Start next soap call
00277                         include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
00278                         $soap_client = new ilSoapClient();
00279                         $soap_client->setTimeout(1);
00280                         $soap_client->setResponseTimeout(1);
00281                         $soap_client->enableWSDL(true);
00282                         $soap_client->init();
00283                         $soap_client->call('ilClone',array($sid,$cp_options->getCopyId()));
00284                 }
00285                 else
00286                 {
00287                         $ilLog->write(__METHOD__.': Cannot call SOAP server');
00288                         $cp_options->read();                    
00289                         include_once('./webservice/soap/include/inc.soap_functions.php');
00290                         $res = ilClone($sid,$cp_options->getCopyId());
00291                 }
00292                 return true;
00293         }
00294         
00295         private function callNextDependency($sid,$cp_options)
00296         {
00297                 global $ilLog;
00298 
00299                 $cp_options->dropFirstDependenciesNode();
00300                 
00301                 if($cp_options->isSOAPEnabled())
00302                 {
00303                         // Start next soap call
00304                         include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
00305                         $soap_client = new ilSoapClient();
00306                         $soap_client->setTimeout(1);
00307                         $soap_client->setResponseTimeout(1);
00308                         $soap_client->enableWSDL(true);
00309                         $soap_client->init();
00310                         $soap_client->call('ilCloneDependencies',array($sid,$cp_options->getCopyId()));
00311                 }
00312                 else
00313                 {
00314                         $ilLog->write(__METHOD__.': Cannot call SOAP server');
00315                         $cp_options->read();
00316                         include_once('./webservice/soap/include/inc.soap_functions.php');
00317                         $res = ilCloneDependencies($sid,$cp_options->getCopyId());
00318                 }
00319                 return true;
00320         }
00321         
00329         private function cloneNode($node,$cp_options)
00330         {
00331                 global $ilLog,$tree,$ilAccess;
00332                 
00333                 #sleep(20);
00334                 
00335                 $source_id = $node['child'];
00336                 $parent_id = $node['parent'];
00337                 $options = $cp_options->getOptions($node['child']);
00338                 $mappings = $cp_options->getMappings();
00339                 
00340                 if(!$ilAccess->checkAccess('copy','',$node['child']))
00341                 {
00342                         $ilLog->write(__METHOD__.': No copy permission granted: '.$source_id.', '.$node['title'].', '.$node['type']);
00343                         return false;
00344                         
00345                 }
00346                 if(!isset($mappings[$parent_id]))
00347                 {
00348                         $ilLog->write(__METHOD__.': Omitting node '.$source_id.', '.$node['title'].', '.$node['type']. '. No target found.');
00349                         return true;
00350                 }
00351                 $target_id = $mappings[$parent_id];
00352                 
00353                 if(!$tree->isInTree($target_id))
00354                 {
00355                         $ilLog->write(__METHOD__.': Omitting node '.$source_id.', '.$node['title'].', '.$node['type']. '. Object has been deleted.');
00356                         return false;
00357                 }
00358 
00359                 $orig = ilObjectFactory::getInstanceByRefId((int) $source_id);
00360                 $new_obj = $orig->cloneObject((int) $target_id,$cp_options->getCopyId());
00361                 
00362                 if(!is_object($new_obj))
00363                 {
00364                         $ilLog->write(__METHOD__.': Error copying '.$source_id.', '.$node['title'].', '.$node['type'].'. No target found.');
00365                         return false;
00366                 }
00367                 
00368                 // Finally add new mapping entry
00369                 $cp_options->appendMapping($source_id,$new_obj->getRefId());
00370                 return $new_obj->getRefId();
00371         }
00372         
00380         private function cloneDependencies($node,$cp_options)
00381         {
00382                 global $ilLog;
00383                 
00384                 $source_id = $node['child'];
00385                 $mappings = $cp_options->getMappings();
00386                 
00387                 if(!isset($mappings[$source_id]))
00388                 {
00389                         $ilLog->write(__METHOD__.': Omitting node '.$source_id.', '.$node['title'].', '.$node['type']. '. No mapping found.');
00390                         return true;
00391                 }
00392                 $target_id = $mappings[$source_id];
00393 
00394                 $orig = ilObjectFactory::getInstanceByRefId((int) $source_id);
00395                 $orig->cloneDependencies($target_id,$cp_options->getCopyId());
00396                 return true;
00397         }
00398         
00406         private function linkNode($node,$cp_options)
00407         {
00408                 global $ilLog,$ilAccess;
00409                 
00410                 $source_id = $node['child'];
00411                 $parent_id = $node['parent'];
00412                 $options = $cp_options->getOptions($node['child']);
00413                 $mappings = $cp_options->getMappings();
00414                 
00415                 if(!$ilAccess->checkAccess('write','',$node['child']))
00416                 {
00417                         $ilLog->write(__METHOD__.': No write permission granted: '.$source_id.', '.$node['title'].', '.$node['type']);
00418                         return false;
00419                         
00420                 }
00421                 if(!isset($mappings[$parent_id]))
00422                 {
00423                         $ilLog->write(__METHOD__.': Omitting node '.$source_id.', '.$node['title'].', '.$node['type']. '. No target found.');
00424                         return true;
00425                 }
00426                 $target_id = $mappings[$parent_id];
00427 
00428                 $orig = ilObjectFactory::getInstanceByRefId((int) $source_id);
00429                 $new_ref_id = $orig->createReference();
00430                 $orig->putInTree($target_id);
00431                 $orig->setPermissions($target_id);
00432                 $orig->setRefId($new_ref_id);
00433                 $orig->initDefaultRoles();
00434                 
00435                 
00436                 if(!($new_ref_id))
00437                 {
00438                         $ilLog->write(__METHOD__.': Error linking '.$source_id.', '.$node['title'].', '.$node['type'].'. No target found.');
00439                         return false;
00440                 }
00441                 
00442                 // Finally add new mapping entry
00443                 $cp_options->appendMapping($source_id,$new_ref_id);
00444                 return $new_ref_id;             
00445         }
00446 }
00447 ?>

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