user_info.soap.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 DokeosWSCourseList 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('DokeosWSCourseListOfUser', // 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#DokeosWSUserInfo', // 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 Dokeos
  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 DokeosWSCourseListOfUser($username, $signature) {
  67. if (empty($username) or empty($signature)) { return -1; }
  68. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  69. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  70. global $_configuration;
  71. $info = api_get_user_info_from_username($username);
  72. $user_id = $info['user_id'];
  73. $list = UserManager::get_api_keys($user_id, 'dokeos');
  74. $key = '';
  75. foreach ($list as $key) {
  76. break;
  77. }
  78. $local_key = $username.$key;
  79. if (!api_is_valid_secret_key($signature, $local_key)) {
  80. return -1; // The secret key is incorrect.
  81. }
  82. // libraries
  83. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  84. $courses_list = array();
  85. $courses_list_tmp = CourseManager::get_courses_list_by_user_id($user_id);
  86. foreach ($courses_list_tmp as $index => $course) {
  87. $course_info = CourseManager::get_course_information($course['code']);
  88. $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']);
  89. }
  90. return $courses_list;
  91. }
  92. /* Register DokeosWSEventsList function */
  93. // Register the data structures used by the service
  94. $server->wsdl->addComplexType(
  95. 'eventDetails',
  96. 'complexType',
  97. 'struct',
  98. 'all',
  99. '',
  100. array(
  101. 'name'=>'datestart','type'=>'xsd:string',
  102. 'name'=>'dateend','type'=>'xsd:string',
  103. 'name'=>'title','type'=>'xsd:string',
  104. 'name'=>'link','type'=>'xsd:string',
  105. 'name'=>'coursetitle','type'=>'xsd:string',
  106. )
  107. );
  108. $server->wsdl->addComplexType(
  109. 'eventsList',
  110. 'complexType',
  111. 'array',
  112. '',
  113. 'SOAP-ENC:Array',
  114. array(),
  115. array(
  116. array('ref'=>'SOAP:ENC:arrayType',
  117. 'wsdl:arrayType'=>'tns:eventDetails[]')
  118. ),
  119. 'tns:eventDetails'
  120. );
  121. // Register the method to expose
  122. $server->register('DokeosWSEventsList', // method name
  123. array('username' => 'xsd:string',
  124. 'signature' => 'xsd:string',
  125. 'datestart' => 'xsd:int',
  126. 'dateend' => 'xsd:int'), // input parameters
  127. array('return' => 'xsd:Array'), // output parameters
  128. 'urn:WSUserInfo', // namespace
  129. 'urn:WSUserInfo#DokeosWSEventsList', // soapaction
  130. 'rpc', // style
  131. 'encoded', // use
  132. 'This service returns a list of events of the courses the given user is subscribed to' // documentation
  133. );
  134. /**
  135. * Get a list of events between two dates for the given username
  136. * Function registered as service. Returns strings in UTF-8.
  137. * @param string Username
  138. * @param string User's API key (the user's API key)
  139. * @param int Start date, in YYYYMMDD format
  140. * @param int End date, in YYYYMMDD format
  141. * @return array Events list
  142. */
  143. function DokeosWSEventsList($username, $signature, $datestart = 0, $dateend = 0) {
  144. if (empty($username) or empty($signature)) { return -1; }
  145. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  146. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  147. global $_configuration;
  148. $info = api_get_user_info_from_username($username);
  149. $user_id = $info['user_id'];
  150. $list = UserManager::get_api_keys($user_id, 'dokeos');
  151. $key = '';
  152. foreach ($list as $key) {
  153. break;
  154. }
  155. $local_key = $username.$key;
  156. if (!api_is_valid_secret_key($signature, $local_key)) {
  157. return -1; // The secret key is incorrect.
  158. }
  159. // Libraries
  160. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  161. $events_list = array();
  162. $user_id = UserManager::get_user_id_from_username($username);
  163. if ($user_id === false) { return $events_list; } // Error in user id recovery.
  164. require_once '../calendar/myagenda.inc.php';
  165. $ds = substr($datestart,0,4).'-'.substr($datestart,4,2).'-'.substr($datestart,6,2).' 00:00:00';
  166. $de = substr($dateend,0,4).'-'.substr($dateend,4,2).'-'.substr($dateend,6,2).' 00:00:00';
  167. $events_list = get_personal_agenda_items_between_dates($user_id, $ds, $de);
  168. return $events_list;
  169. }
  170. // Use the request to (try to) invoke the service.
  171. $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
  172. $server->service($HTTP_RAW_POST_DATA);