cm_soap.php 2.4 KB

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