ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapUtils.php
Go to the documentation of this file.
1 <?php
2  /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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  function ilSoapUtils()
38  {
40  }
41 
42  function ignoreUserAbort()
43  {
44  ignore_user_abort();
45  }
46 
47  function disableSOAPCheck()
48  {
49  $this->sauth->disableSOAPCheck();
50  }
51 
52  function sendMail($sid,$to,$cc,$bcc,$sender,$subject,$message,$attach)
53  {
54  if(!$this->__checkSession($sid))
55  {
56  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
57  }
58 
59  // Include main header
60  include_once './include/inc.header.php';
61 
62  global $ilLog;
63 
64  include_once 'Services/Mail/classes/class.ilMimeMail.php';
65 
66  $mmail = new ilMimeMail();
67  $mmail->autoCheck(false);
68  $mmail->From($sender);
69  $mmail->To(explode(',',$to));
70  $mmail->Subject($subject);
71  $mmail->Body($message);
72 
73  if($cc)
74  {
75  $mmail->Cc(explode(',',$cc));
76  }
77 
78  if($bcc)
79  {
80  $mmail->Bcc(explode(',',$bcc));
81  }
82  if($attach)
83  {
84  // mjansen: switched separator from "," to "#:#" because of mantis bug #6039
85  // for backward compatibility we have to check if the substring "#:#" exists as leading separator
86  // otherwise we should use ";"
87  if(strpos($attach, '#:#') === 0)
88  {
89  $attach = substr($attach, strlen('#:#'));
90  $attachments = explode('#:#', $attach);
91  }
92  else
93  {
94  $attachments = explode(',', $attach);
95  }
96  foreach ($attachments as $attachment)
97  {
98  $mmail->Attach($attachment);
99  }
100  }
101 
102  $mmail->Send();
103  $ilLog->write('SOAP: sendMail(): '.$to.', '.$cc.', '.$bcc);
104 
105  return true;
106  }
107 
108  function saveTempFileAsMediaObject($sid, $name, $tmp_name)
109  {
110  if(!$this->__checkSession($sid))
111  {
112  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
113  }
114 
115  // Include main header
116  include_once './include/inc.header.php';
117  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
118  return ilObjMediaObject::_saveTempFileAsMediaObject($name, $tmp_name);
119  }
120 
121  function getMobsOfObject($sid, $a_type, $a_id)
122  {
123  if(!$this->__checkSession($sid))
124  {
125  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
126  }
127 
128  // Include main header
129  include_once './include/inc.header.php';
130  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
131  return ilObjMediaObject::_getMobsOfObject($a_type, $a_id);
132  }
133 
141  public function ilCloneDependencies($sid,$copy_identifier)
142  {
143  if(!$this->__checkSession($sid))
144  {
145  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
146  }
147 
148  // Include main header
149  include_once './include/inc.header.php';
150 
151  global $ilLog,$ilUser;
152 
153  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
154  $cp_options = ilCopyWizardOptions::_getInstance($copy_identifier);
155 
156  // Check owner of copy procedure
157  if(!$cp_options->checkOwner($ilUser->getId()))
158  {
159  $ilLog->write(__METHOD__.': Permission check failed for user id: '.$ilUser->getId().', copy id: '.$copy_identifier);
160  return false;
161  }
162 
163  // Fetch first node
164  if(($node = $cp_options->fetchFirstDependenciesNode()) === false)
165  {
166  $cp_options->deleteAll();
167  $ilLog->write(__METHOD__.': Finished copy step 2. Copy completed');
168 
169  return true;
170  }
171 
172  // Check options of this node
173  $options = $cp_options->getOptions($node['child']);
174  $new_ref_id = 0;
175  switch($options['type'])
176  {
178  $ilLog->write(__METHOD__.': Omitting node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
179  $this->callNextDependency($sid,$cp_options);
180  break;
181 
183  $ilLog->write(__METHOD__.': Nothing to do for node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
184  $this->callNextDependency($sid,$cp_options);
185  break;
186 
188  $ilLog->write(__METHOD__.': Start cloning dependencies: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
189  $this->cloneDependencies($node,$cp_options);
190  $this->callNextDependency($sid,$cp_options);
191  break;
192 
193  default:
194  $ilLog->write(__METHOD__.': No valid action type given for node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
195  $this->callNextDependency($sid,$cp_options);
196  break;
197  }
198  return true;
199  }
200 
209  public function ilClone($sid,$copy_identifier)
210  {
211  if(!$this->__checkSession($sid))
212  {
213  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
214  }
215 
216  // Include main header
217  include_once './include/inc.header.php';
218 
219  global $ilLog,$ilUser;
220 
221  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
222  $cp_options = ilCopyWizardOptions::_getInstance($copy_identifier);
223 
224  // Check owner of copy procedure
225  if(!$cp_options->checkOwner($ilUser->getId()))
226  {
227  $ilLog->write(__METHOD__.': Permission check failed for user id: '.$ilUser->getId().', copy id: '.$copy_identifier);
228  return false;
229  }
230 
231 
232  // Fetch first node
233  if(($node = $cp_options->fetchFirstNode()) === false)
234  {
235  $ilLog->write(__METHOD__.': Finished copy step 1. Starting copying of object dependencies...');
236  return $this->ilCloneDependencies($sid,$copy_identifier);
237  }
238 
239  // Check options of this node
240  $options = $cp_options->getOptions($node['child']);
241 
242  $new_ref_id = 0;
243  switch($options['type'])
244  {
246  $ilLog->write(__METHOD__.': Omitting node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
247  // set mapping to zero
248  $cp_options->appendMapping($node['child'],0);
249  $this->callNextNode($sid,$cp_options);
250  break;
251 
253  $ilLog->write(__METHOD__.': Start cloning node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
254  $new_ref_id = $this->cloneNode($node,$cp_options);
255  $this->callNextNode($sid,$cp_options);
256  break;
257 
259  $ilLog->write(__METHOD__.': Start linking node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
260  $new_ref_id = $this->linkNode($node,$cp_options);
261  $this->callNextNode($sid,$cp_options);
262  break;
263 
264  default:
265  $ilLog->write(__METHOD__.': No valid action type given for node: '.$node['obj_id'].', '.$node['title'].', '.$node['type']);
266  $this->callNextNode($sid,$cp_options);
267  break;
268 
269  }
270  return $new_ref_id;
271  }
272 
279  private function callNextNode($sid,$cp_options)
280  {
281  global $ilLog;
282 
283  $cp_options->dropFirstNode();
284 
285  if($cp_options->isSOAPEnabled())
286  {
287  // Start next soap call
288  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
289  $soap_client = new ilSoapClient();
290  $soap_client->setTimeout(1);
291  $soap_client->setResponseTimeout(1);
292  $soap_client->enableWSDL(true);
293  $soap_client->init();
294  $soap_client->call('ilClone',array($sid,$cp_options->getCopyId()));
295  }
296  else
297  {
298  $ilLog->write(__METHOD__.': Cannot call SOAP server');
299  $cp_options->read();
300  include_once('./webservice/soap/include/inc.soap_functions.php');
301  $res = ilSoapFunctions::ilClone($sid,$cp_options->getCopyId());
302  }
303  return true;
304  }
305 
306  private function callNextDependency($sid,$cp_options)
307  {
308  global $ilLog;
309 
310  $cp_options->dropFirstDependenciesNode();
311 
312  if($cp_options->isSOAPEnabled())
313  {
314  // Start next soap call
315  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
316  $soap_client = new ilSoapClient();
317  $soap_client->setTimeout(1);
318  $soap_client->setResponseTimeout(1);
319  $soap_client->enableWSDL(true);
320  $soap_client->init();
321  $soap_client->call('ilCloneDependencies',array($sid,$cp_options->getCopyId()));
322  }
323  else
324  {
325  $ilLog->write(__METHOD__.': Cannot call SOAP server');
326  $cp_options->read();
327  include_once('./webservice/soap/include/inc.soap_functions.php');
328  $res = ilSoapFunctions::ilCloneDependencies($sid,$cp_options->getCopyId());
329  }
330  return true;
331  }
332 
340  private function cloneNode($node,$cp_options)
341  {
342  global $ilLog,$tree,$ilAccess;
343 
344  #sleep(20);
345 
346  $source_id = $node['child'];
347  $parent_id = $node['parent'];
348  $options = $cp_options->getOptions($node['child']);
349  $mappings = $cp_options->getMappings();
350 
351  if(!$ilAccess->checkAccess('copy','',$node['child']))
352  {
353  $ilLog->write(__METHOD__.': No copy permission granted: '.$source_id.', '.$node['title'].', '.$node['type']);
354  return false;
355 
356  }
357  if(!isset($mappings[$parent_id]))
358  {
359  $ilLog->write(__METHOD__.': Omitting node '.$source_id.', '.$node['title'].', '.$node['type']. '. No target found.');
360  return true;
361  }
362  $target_id = $mappings[$parent_id];
363 
364  if(!$tree->isInTree($target_id))
365  {
366  $ilLog->write(__METHOD__.': Omitting node '.$source_id.', '.$node['title'].', '.$node['type']. '. Object has been deleted.');
367  return false;
368  }
369 
370  $orig = ilObjectFactory::getInstanceByRefId((int) $source_id);
371  $new_obj = $orig->cloneObject((int) $target_id,$cp_options->getCopyId());
372 
373  if(!is_object($new_obj))
374  {
375  $ilLog->write(__METHOD__.': Error copying '.$source_id.', '.$node['title'].', '.$node['type'].'. No target found.');
376  return false;
377  }
378 
379  // Finally add new mapping entry
380  $cp_options->appendMapping($source_id,$new_obj->getRefId());
381  return $new_obj->getRefId();
382  }
383 
391  private function cloneDependencies($node,$cp_options)
392  {
393  global $ilLog;
394 
395  $source_id = $node['child'];
396  $mappings = $cp_options->getMappings();
397 
398  if(!isset($mappings[$source_id]))
399  {
400  $ilLog->write(__METHOD__.': Omitting node '.$source_id.', '.$node['title'].', '.$node['type']. '. No mapping found.');
401  return true;
402  }
403  $target_id = $mappings[$source_id];
404 
405  $orig = ilObjectFactory::getInstanceByRefId((int) $source_id);
406  $orig->cloneDependencies($target_id,$cp_options->getCopyId());
407  return true;
408  }
409 
417  private function linkNode($node,$cp_options)
418  {
419  global $ilLog,$ilAccess;
420 
421  $source_id = $node['child'];
422  $parent_id = $node['parent'];
423  $options = $cp_options->getOptions($node['child']);
424  $mappings = $cp_options->getMappings();
425 
426  if(!$ilAccess->checkAccess('write','',$node['child']))
427  {
428  $ilLog->write(__METHOD__.': No write permission granted: '.$source_id.', '.$node['title'].', '.$node['type']);
429  return false;
430 
431  }
432  if(!isset($mappings[$parent_id]))
433  {
434  $ilLog->write(__METHOD__.': Omitting node '.$source_id.', '.$node['title'].', '.$node['type']. '. No target found.');
435  return true;
436  }
437  $target_id = $mappings[$parent_id];
438 
439  $orig = ilObjectFactory::getInstanceByRefId((int) $source_id);
440  $new_ref_id = $orig->createReference();
441  $orig->putInTree($target_id);
442  $orig->setPermissions($target_id);
443  $orig->setRefId($new_ref_id);
444  $orig->initDefaultRoles();
445 
446 
447  if(!($new_ref_id))
448  {
449  $ilLog->write(__METHOD__.': Error linking '.$source_id.', '.$node['title'].', '.$node['type'].'. No target found.');
450  return false;
451  }
452 
453  // Finally add new mapping entry
454  $cp_options->appendMapping($source_id,$new_ref_id);
455  return $new_ref_id;
456  }
457 
464  static function validateXML ($xml) {
465  // validate to prevent wrong XMLs
466  $dom = @domxml_open_mem($xml, DOMXML_LOAD_VALIDATING, $error);
467  if ($error)
468  {
469  $msg = array();
470  if (is_array($error))
471  {
472  foreach ($error as $err) {
473  $msg []= "(".$err["line"].",".$err["col"]."): ".$err["errormessage"];
474  }
475  }
476  else
477  {
478  $msg[] = $error;
479  }
480  $msg = join("\n",$msg);
481  return $msg;
482  }
483  return true;
484  }
485 
486  public function handleECSTasks($sid)
487  {
488  if(!$this->__checkSession($sid))
489  {
490  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
491  }
492 
493  // Include main header
494  include_once './include/inc.header.php';
495  include_once('./Services/WebServices/ECS/classes/class.ilECSTaskScheduler.php');
496 
497  global $ilLog;
498 
499  $scheduler = ilECSTaskScheduler::_getInstance();
500  $ilLog->write(__METHOD__.': Starting task execution...');
501  $scheduler->startTaskExecution();
502 
503  return true;
504  }
505 }
506 ?>