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