cm_soap.php 2.5 KB

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