1 | <?php |
||
2 | |||
3 | /* For licensing terms, see /license.txt */ |
||
4 | |||
5 | /** |
||
6 | * This script provides the caller service with a list |
||
7 | * of courses that have a certain level of visibility |
||
8 | * on this chamilo portal. |
||
9 | * It is set to work with the Chamilo module for Drupal: |
||
10 | * http://drupal.org/project/chamilo. |
||
11 | * |
||
12 | * @author Yannick Warnier <[email protected]> |
||
13 | * |
||
14 | * @package chamilo.webservices |
||
15 | */ |
||
16 | require_once __DIR__.'/../inc/global.inc.php'; |
||
17 | |||
18 | api_protect_webservices(); |
||
19 | |||
20 | // Create the server instance |
||
21 | $server = new soap_server(); |
||
22 | // Initialize WSDL support |
||
23 | $server->configureWSDL('WSCourseList', 'urn:WSCourseList'); |
||
24 | |||
25 | /* Register WSCourseList function */ |
||
26 | // Register the data structures used by the service |
||
27 | |||
28 | $server->wsdl->addComplexType( |
||
29 | 'courseDetails', |
||
30 | 'complexType', |
||
31 | 'struct', |
||
32 | 'all', |
||
33 | '', |
||
34 | [ |
||
35 | 'name' => 'code', |
||
36 | 'type' => 'xsd:string', |
||
37 | 'name' => 'title', |
||
38 | 'type' => 'xsd:string', |
||
39 | 'name' => 'url', |
||
40 | 'type' => 'xsd:string', |
||
41 | 'name' => 'teacher', |
||
42 | 'type' => 'xsd:string', |
||
43 | 'name' => 'language', |
||
44 | 'type' => 'xsd:string', |
||
45 | ] |
||
46 | ); |
||
47 | |||
48 | $server->wsdl->addComplexType( |
||
49 | 'courseList', |
||
50 | 'complexType', |
||
51 | 'array', |
||
52 | '', |
||
53 | 'SOAP-ENC:Array', |
||
54 | [], |
||
55 | [ |
||
56 | ['ref' => 'SOAP-ENC:arrayType', |
||
57 | 'wsdl:arrayType' => 'tns:courseDetails[]', ], |
||
58 | ], |
||
59 | 'tns:courseDetails' |
||
60 | ); |
||
61 | |||
62 | // Register the method to expose |
||
63 | $server->register( |
||
64 | 'WSCourseList', // method name |
||
65 | ['username' => 'xsd:string', |
||
66 | 'signature' => 'xsd:string', |
||
67 | 'visibilities' => 'xsd:string', ], // input parameters |
||
68 | ['return' => 'xsd:Array'], // output parameters |
||
69 | 'urn:WSCourseList', // namespace |
||
70 | 'urn:WSCourseList#WSCourseList', // soapaction |
||
71 | 'rpc', // style |
||
72 | 'encoded', // use |
||
73 | 'This service returns a list of courses' // documentation |
||
74 | ); |
||
75 | |||
76 | /** |
||
77 | * Get a list of courses (code, url, title, teacher, language) and return to caller |
||
78 | * Function registered as service. Returns strings in UTF-8. |
||
79 | * |
||
80 | * @param string User name in Chamilo |
||
81 | * @param string Signature (composed of the sha1(username+apikey) |
||
82 | * @param mixed Array or string. Type of visibility of course (public, public-registered, private, closed) |
||
83 | * |
||
84 | * @return array Courses list (code=>[title=>'title',url='http://...',teacher=>'...',language=>''],code=>[...],...) |
||
85 | */ |
||
86 | function WSCourseList($username, $signature, $visibilities = 'public') |
||
87 | { |
||
88 | if (empty($username) or empty($signature)) { |
||
89 | return -1; |
||
90 | } |
||
91 | |||
92 | global $_configuration; |
||
93 | |||
94 | $info = api_get_user_info_from_username($username); |
||
95 | $user_id = $info['user_id']; |
||
96 | if (!UserManager::is_admin($user_id)) { |
||
97 | return -1; |
||
98 | } |
||
99 | |||
100 | $list = UserManager::get_api_keys($user_id, 'dokeos'); |
||
101 | $key = ''; |
||
102 | foreach ($list as $key) { |
||
103 | break; |
||
104 | } |
||
105 | |||
106 | $local_key = $username.$key; |
||
107 | |||
108 | if (!api_is_valid_secret_key($signature, $local_key) && |
||
109 | !api_is_valid_secret_key($signature, $username.$_configuration['security_key']) |
||
110 | ) { |
||
111 | return -1; // The secret key is incorrect. |
||
112 | } |
||
113 | //public-registered = open |
||
114 | $vis = ['public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0']; |
||
115 | |||
116 | $courses_list = []; |
||
117 | |||
118 | if (!is_array($visibilities)) { |
||
119 | $visibilities = split(',', $visibilities); |
||
120 | } |
||
121 | foreach ($visibilities as $visibility) { |
||
122 | if (!in_array($visibility, array_keys($vis))) { |
||
123 | return ['error_msg' => 'Security check failed']; |
||
124 | } |
||
125 | $courses_list_tmp = CourseManager::get_courses_list( |
||
126 | null, |
||
127 | null, |
||
128 | null, |
||
129 | null, |
||
130 | $vis[$visibility] |
||
131 | ); |
||
132 | foreach ($courses_list_tmp as $index => $course) { |
||
133 | $course_info = CourseManager::get_course_information($course['code']); |
||
0 ignored issues
–
show
|
|||
134 | $courses_list[] = [ |
||
135 | 'code' => $course['code'], |
||
136 | 'title' => api_utf8_encode($course_info['title']), |
||
137 | 'url' => api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/', |
||
138 | 'teacher' => api_utf8_encode($course_info['tutor_name']), |
||
139 | 'language' => $course_info['course_language'], |
||
140 | ]; |
||
141 | } |
||
142 | } |
||
143 | |||
144 | return $courses_list; |
||
145 | } |
||
146 | |||
147 | // Use the request to (try to) invoke the service. |
||
148 | $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; |
||
149 | $server->service($HTTP_RAW_POST_DATA); |
||
150 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.