user_info.soap.php 6.7 KB

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