user_info.soap.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script provides the caller service with user details.
  5. * It is set to work with the Chamilo module for Drupal:
  6. * http://drupal.org/project/chamilo
  7. *
  8. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  9. * @package chamilo.webservices
  10. */
  11. require_once '../inc/global.inc.php';
  12. $libpath = api_get_path(LIBRARY_PATH);
  13. require_once $libpath.'nusoap/nusoap.php';
  14. // Create the server instance
  15. $server = new soap_server();
  16. // Initialize WSDL support
  17. $server->configureWSDL('WSUserInfo', 'urn:WSUserInfo');
  18. /* Register WSCourseList function */
  19. // Register the data structures used by the service
  20. $server->wsdl->addComplexType(
  21. 'courseDetails',
  22. 'complexType',
  23. 'struct',
  24. 'all',
  25. '',
  26. array(
  27. 'name'=>'code' , 'type'=>'xsd:string',
  28. 'name'=>'title' , 'type'=>'xsd:string',
  29. 'name'=>'url' , 'type'=>'xsd:string',
  30. 'name'=>'teacher', 'type'=>'xsd:string',
  31. 'name'=>'language','type'=>'xsd:string',
  32. )
  33. );
  34. $server->wsdl->addComplexType(
  35. 'courseList',
  36. 'complexType',
  37. 'array',
  38. '',
  39. 'SOAP-ENC:Array',
  40. array(),
  41. array(
  42. array('ref'=>'SOAP:ENC:arrayType',
  43. 'wsdl:arrayType'=>'tns:courseDetails[]')
  44. ),
  45. 'tns:courseDetails'
  46. );
  47. // Register the method to expose
  48. $server->register('WSCourseListOfUser', // method name
  49. array('username' => 'xsd:string',
  50. 'signature' => 'xsd:string'), // input parameters
  51. array('return' => 'xsd:Array'), // output parameters
  52. 'urn:WSUserInfo', // namespace
  53. 'urn:WSUserInfo#WSUserInfo', // soapaction
  54. 'rpc', // style
  55. 'encoded', // use
  56. 'This service returns a list of courses' // documentation
  57. );
  58. /**
  59. * Get a list of courses (code, url, title, teacher, language) for a specific
  60. * user and return to caller
  61. * Function registered as service. Returns strings in UTF-8.
  62. * @param string User name in Chamilo
  63. * @param string Signature (composed of the sha1(username+apikey)
  64. * @return array Courses list (code=>[title=>'title',url='http://...',teacher=>'...',language=>''],code=>[...],...)
  65. */
  66. function WSCourseListOfUser($username, $signature) {
  67. if (empty($username) or empty($signature)) { return -1; }
  68. global $_configuration;
  69. $info = api_get_user_info_from_username($username);
  70. $user_id = $info['user_id'];
  71. $list = UserManager::get_api_keys($user_id, 'dokeos');
  72. $key = '';
  73. foreach ($list as $key) {
  74. break;
  75. }
  76. $local_key = $username.$key;
  77. if (!api_is_valid_secret_key($signature, $local_key)) {
  78. return -1; // The secret key is incorrect.
  79. }
  80. $courses_list = array();
  81. $courses_list_tmp = CourseManager::get_courses_list_by_user_id($user_id);
  82. foreach ($courses_list_tmp as $index => $course) {
  83. $course_info = CourseManager::get_course_information($course['code']);
  84. $courses_list[] = array('code' => $course['code'], 'title' => api_utf8_encode($course_info['title']), 'url' => api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/', 'teacher' => api_utf8_encode($course_info['tutor_name']), 'language' => $course_info['course_language']);
  85. }
  86. return $courses_list;
  87. }
  88. /* Register WSEventsList function */
  89. // Register the data structures used by the service
  90. $server->wsdl->addComplexType(
  91. 'eventDetails',
  92. 'complexType',
  93. 'struct',
  94. 'all',
  95. '',
  96. array(
  97. 'name'=>'datestart','type'=>'xsd:string',
  98. 'name'=>'dateend','type'=>'xsd:string',
  99. 'name'=>'title','type'=>'xsd:string',
  100. 'name'=>'link','type'=>'xsd:string',
  101. 'name'=>'coursetitle','type'=>'xsd:string',
  102. )
  103. );
  104. $server->wsdl->addComplexType(
  105. 'eventsList',
  106. 'complexType',
  107. 'array',
  108. '',
  109. 'SOAP-ENC:Array',
  110. array(),
  111. array(
  112. array('ref'=>'SOAP:ENC:arrayType',
  113. 'wsdl:arrayType'=>'tns:eventDetails[]')
  114. ),
  115. 'tns:eventDetails'
  116. );
  117. // Register the method to expose
  118. $server->register('WSEventsList', // method name
  119. array('username' => 'xsd:string',
  120. 'signature' => 'xsd:string',
  121. 'datestart' => 'xsd:int',
  122. 'dateend' => 'xsd:int'), // input parameters
  123. array('return' => 'xsd:Array'), // output parameters
  124. 'urn:WSUserInfo', // namespace
  125. 'urn:WSUserInfo#WSEventsList', // soapaction
  126. 'rpc', // style
  127. 'encoded', // use
  128. 'This service returns a list of events of the courses the given user is subscribed to' // documentation
  129. );
  130. /**
  131. * Get a list of events between two dates for the given username
  132. * Function registered as service. Returns strings in UTF-8.
  133. * @param string Username
  134. * @param string User's API key (the user's API key)
  135. * @param int Start date, in YYYYMMDD format
  136. * @param int End date, in YYYYMMDD format
  137. * @return array Events list
  138. */
  139. function WSEventsList($username, $signature, $datestart = 0, $dateend = 0) {
  140. if (empty($username) or empty($signature)) { return -1; }
  141. global $_configuration;
  142. $info = api_get_user_info_from_username($username);
  143. $user_id = $info['user_id'];
  144. $list = UserManager::get_api_keys($user_id, 'dokeos');
  145. $key = '';
  146. foreach ($list as $key) {
  147. break;
  148. }
  149. $local_key = $username.$key;
  150. if (!api_is_valid_secret_key($signature, $local_key)) {
  151. return -1; // The secret key is incorrect.
  152. }
  153. $events_list = array();
  154. $user_id = UserManager::get_user_id_from_username($username);
  155. if ($user_id === false) { return $events_list; } // Error in user id recovery.
  156. require_once '../calendar/myagenda.inc.php';
  157. $ds = substr($datestart,0,4).'-'.substr($datestart,4,2).'-'.substr($datestart,6,2).' 00:00:00';
  158. $de = substr($dateend,0,4).'-'.substr($dateend,4,2).'-'.substr($dateend,6,2).' 00:00:00';
  159. $events_list = get_personal_agenda_items_between_dates($user_id, $ds, $de);
  160. return $events_list;
  161. }
  162. // Use the request to (try to) invoke the service.
  163. $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
  164. $server->service($HTTP_RAW_POST_DATA);