cm_soap.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.webservices
  5. */
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. require_once __DIR__.'/cm_webservice.php';
  8. $libpath = api_get_path(LIBRARY_PATH);
  9. /**
  10. * SOAP error handler. Handles an error sending a SOAP fault
  11. */
  12. class WSCMSoapErrorHandler implements WSCMErrorHandler
  13. {
  14. /**
  15. * Handles the error by sending a SOAP fault through the server
  16. *
  17. * @param WSError Error to handle
  18. */
  19. public function handle($error)
  20. {
  21. $server = WSCMSoapServer::singleton();
  22. $server->fault(strval($error->code), $error->message);
  23. }
  24. }
  25. /**
  26. * SOAP server wrapper implementing a Singleton
  27. */
  28. class WSCMSoapServer
  29. {
  30. /**
  31. * SOAP server instance
  32. *
  33. * @var soap_server
  34. */
  35. private static $_instance;
  36. /**
  37. * Private constructor
  38. */
  39. public function __construct()
  40. {
  41. }
  42. /**
  43. * Singleton method
  44. */
  45. public static function singleton()
  46. {
  47. if (!isset(self::$_instance)) {
  48. self::$_instance = new soap_server();
  49. // Set the error handler
  50. WSCMError::setErrorHandler(new WSCMSoapErrorHandler());
  51. // Configure the service
  52. self::$_instance->configureWSDL('WSCMService', 'urn:WSCMService');
  53. }
  54. return self::$_instance;
  55. }
  56. }
  57. $s = WSCMSoapServer::singleton();
  58. $s->wsdl->addComplexType(
  59. 'result',
  60. 'complexType',
  61. 'struct',
  62. 'all',
  63. '',
  64. array(
  65. 'code' => array('name' => 'code', 'type' => 'xsd:int'),
  66. 'message' => array('name' => 'message', 'type' => 'xsd:string')
  67. )
  68. );
  69. $s->wsdl->addComplexType(
  70. 'extra_field',
  71. 'complexType',
  72. 'struct',
  73. 'all',
  74. '',
  75. array(
  76. 'field_name' => array('name' => 'field_name', 'type' => 'xsd:string'),
  77. 'field_value' => array('name' => 'field_value', 'type' => 'xsd:string')
  78. )
  79. );
  80. $s->register(
  81. 'WSCM.verifyUserPass',
  82. array(
  83. 'username' => 'xsd:string',
  84. 'password' => 'xsd:string',
  85. ),
  86. array('return' => 'xsd:string')
  87. );
  88. $s->register(
  89. 'WSCM.encryptPass',
  90. array('password' => 'xsd:string'),
  91. array('return' => 'xsd:string')
  92. );
  93. $s->register(
  94. 'WSCM.test',
  95. array(),
  96. array('return' => 'xsd:string'),
  97. 'urn:WSCMService',
  98. '',
  99. '',
  100. '',
  101. ''
  102. );
  103. require_once __DIR__.'/cm_soap_inbox.php';
  104. require_once __DIR__.'/cm_soap_user.php';
  105. require_once __DIR__.'/cm_soap_courses.php';
  106. require_once __DIR__.'/cm_soap_announcements.php';
  107. require_once __DIR__.'/cm_soap_forum.php';
  108. // Use the request to (try to) invoke the service
  109. $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
  110. $s->service($HTTP_RAW_POST_DATA);