ILIAS  Release_4_1_x_branch Revision 61804
 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";
120  return ilObjMediaObject::_saveTempFileAsMediaObject($name, $tmp_name);
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,$rbacreview;
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  // rbac log
383  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
384  $rbac_log_roles = $rbacreview->getParentRoleIds($new_obj->getRefId(), false);
385  $rbac_log = ilRbacLog::gatherFaPa($new_obj->getRefId(), array_keys($rbac_log_roles));
386  ilRbacLog::add(ilRbacLog::COPY_OBJECT, $new_obj->getRefId(), $rbac_log, (int)$source_id);
387 
388  // Finally add new mapping entry
389  $cp_options->appendMapping($source_id,$new_obj->getRefId());
390  return $new_obj->getRefId();
391  }
392 
400  private function cloneDependencies($node,$cp_options)
401  {
402  global $ilLog;
403 
404  $source_id = $node['child'];
405  $mappings = $cp_options->getMappings();
406 
407  if(!isset($mappings[$source_id]))
408  {
409  $ilLog->write(__METHOD__.': Omitting node '.$source_id.', '.$node['title'].', '.$node['type']. '. No mapping found.');
410  return true;
411  }
412  $target_id = $mappings[$source_id];
413 
414  $orig = ilObjectFactory::getInstanceByRefId((int) $source_id);
415  $orig->cloneDependencies($target_id,$cp_options->getCopyId());
416  return true;
417  }
418 
426  private function linkNode($node,$cp_options)
427  {
428  global $ilLog,$ilAccess,$rbacreview;
429 
430  $source_id = $node['child'];
431  $parent_id = $node['parent'];
432  $options = $cp_options->getOptions($node['child']);
433  $mappings = $cp_options->getMappings();
434 
435  if(!$ilAccess->checkAccess('delete','',$node['child']))
436  {
437  $ilLog->write(__METHOD__.': No delete permission granted: '.$source_id.', '.$node['title'].', '.$node['type']);
438  return false;
439 
440  }
441  if(!isset($mappings[$parent_id]))
442  {
443  $ilLog->write(__METHOD__.': Omitting node '.$source_id.', '.$node['title'].', '.$node['type']. '. No target found.');
444  return true;
445  }
446  $target_id = $mappings[$parent_id];
447 
448  $orig = ilObjectFactory::getInstanceByRefId((int) $source_id);
449  $new_ref_id = $orig->createReference();
450  $orig->putInTree($target_id);
451  $orig->setPermissions($target_id);
452 
453  if(!($new_ref_id))
454  {
455  $ilLog->write(__METHOD__.': Error linking '.$source_id.', '.$node['title'].', '.$node['type'].'. No target found.');
456  return false;
457  }
458 
459  // rbac log
460  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
461  $rbac_log_roles = $rbacreview->getParentRoleIds($new_ref_id, false);
462  $rbac_log = ilRbacLog::gatherFaPa($new_ref_id, array_keys($rbac_log_roles));
463  ilRbacLog::add(ilRbacLog::LINK_OBJECT, $new_ref_id, $rbac_log, (int)$source_id);
464 
465  // Finally add new mapping entry
466  $cp_options->appendMapping($source_id,$new_ref_id);
467  return $new_ref_id;
468  }
469 
476  static function validateXML ($xml) {
477  // validate to prevent wrong XMLs
478  $dom = @domxml_open_mem($xml, DOMXML_LOAD_VALIDATING, $error);
479  if ($error)
480  {
481  $msg = array();
482  if (is_array($error))
483  {
484  foreach ($error as $err) {
485  $msg []= "(".$err["line"].",".$err["col"]."): ".$err["errormessage"];
486  }
487  }
488  else
489  {
490  $msg[] = $error;
491  }
492  $msg = join("\n",$msg);
493  return $msg;
494  }
495  return true;
496  }
497 
498  public function handleECSTasks($sid)
499  {
500  $this->initAuth($sid);
501  $this->initIlias();
502 
503  if(!$this->__checkSession($sid))
504  {
505  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
506  }
507 
508  include_once('./Services/WebServices/ECS/classes/class.ilECSTaskScheduler.php');
509 
510  global $ilLog;
511 
512  $scheduler = ilECSTaskScheduler::_getInstance();
513  $ilLog->write(__METHOD__.': Starting task execution...');
514  $scheduler->startTaskExecution();
515 
516  return true;
517  }
518 
532  {
533  $this->initAuth($sid);
534  $this->initIlias();
535 
536  // Session check not possible -> anonymous user is the trigger
537 
538  global $ilDB, $ilLog;
539 
540  $ilLog->write(__METHOD__.': Started deletion of inactive user objects with expired confirmation hash values (dual opt in) ...');
541 
542  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
543  $oRegSettigs = new ilRegistrationSettings();
544 
545  $query = '';
546 
547  /*
548  * Fetch the current actuator user object first, because this user will try to perform very probably
549  * a new registration with the same login name in a few seconds ;-)
550  *
551  */
552  if((int)$usr_id > 0)
553  {
554  $query .= 'SELECT usr_id, create_date, reg_hash FROM usr_data '
555  . 'WHERE active = 0 '
556  . 'AND reg_hash IS NOT NULL '
557  . 'AND usr_id = '.$ilDB->quote($usr_id, 'integer').' ';
558  $query .= 'UNION ';
559  }
560 
561  $query .= 'SELECT usr_id, create_date, reg_hash FROM usr_data '
562  . 'WHERE active = 0 '
563  . 'AND reg_hash IS NOT NULL '
564  . 'AND usr_id != '.$ilDB->quote($usr_id, 'integer').' ';
565 
566  $res = $ilDB->query($query);
567 
568  $ilLog->write(__METHOD__.': '.$ilDB->numRows($res).' inactive user objects with confirmation hash values (dual opt in) found ...');
569 
570  /*
571  * mjansen: 15.12.2010:
572  * I perform the expiration check in php because of multi database support (mysql, postgresql).
573  * I did not find an oracle equivalent for mysql: UNIX_TIMESTAMP()
574  */
575 
576  $num_deleted_users = 0;
577  while($row = $ilDB->fetchAssoc($res))
578  {
579  if($row['usr_id'] == ANONYMOUS_USER_ID || $row['usr_id'] == SYSTEM_USER_ID) continue;
580  if(!strlen($row['reg_hash'])) continue;
581 
582  if((int)$oRegSettigs->getRegistrationHashLifetime() > 0 &&
583  $row['create_date'] != '' &&
584  time() - $oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date']))
585  {
586  $user = ilObjectFactory::getInstanceByObjId($row['usr_id'], false);
587  if($user instanceof ilObjUser)
588  {
589  $ilLog->write(__METHOD__.': User '.$user->getLogin().' (obj_id: '.$user->getId().') will be deleted due to an expired registration hash ...');
590  $user->delete();
591  ++$num_deleted_users;
592  }
593  }
594  }
595 
596  $ilLog->write(__METHOD__.': '.$num_deleted_users.' inactive user objects with expired confirmation hash values (dual opt in) deleted ...');
597 
598  $ilLog->write(__METHOD__.': Finished deletion of inactive user objects with expired confirmation hash values (dual opt in) ...');
599 
600  return true;
601  }
602 }
603 ?>