user_info.soap.php 7.1 KB

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