cm_soap.php 2.5 KB

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