@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | if ( !class_exists('ClockworkException') ) { |
13 | - require_once('exception.php'); |
|
13 | + require_once('exception.php'); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | /** |
@@ -21,130 +21,130 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class Clockwork { |
23 | 23 | |
24 | - /* |
|
24 | + /* |
|
25 | 25 | * Version of this class |
26 | 26 | */ |
27 | - const VERSION = '1.3.1'; |
|
28 | - |
|
29 | - /** |
|
30 | - * All Clockwork API calls start with BASE_URL |
|
31 | - * @author Martin Steel |
|
32 | - */ |
|
33 | - const API_BASE_URL = 'api.clockworksms.com/xml/'; |
|
34 | - |
|
35 | - /** |
|
36 | - * string to append to API_BASE_URL to check authentication |
|
37 | - * @author Martin Steel |
|
38 | - */ |
|
39 | - const API_AUTH_METHOD = 'authenticate'; |
|
40 | - |
|
41 | - /** |
|
42 | - * string to append to API_BASE_URL for sending SMS |
|
43 | - * @author Martin Steel |
|
44 | - */ |
|
45 | - const API_SMS_METHOD = 'sms'; |
|
46 | - |
|
47 | - /** |
|
48 | - * string to append to API_BASE_URL for checking message credit |
|
49 | - * @author Martin Steel |
|
50 | - */ |
|
51 | - const API_CREDIT_METHOD = 'credit'; |
|
52 | - |
|
53 | - /** |
|
54 | - * string to append to API_BASE_URL for checking account balance |
|
55 | - * @author Martin Steel |
|
56 | - */ |
|
57 | - const API_BALANCE_METHOD = 'balance'; |
|
58 | - |
|
59 | - /** |
|
60 | - * Clockwork API Key |
|
61 | - * |
|
62 | - * @var string |
|
63 | - * @author Martin Steel |
|
64 | - */ |
|
65 | - public $key; |
|
66 | - |
|
67 | - /** |
|
68 | - * Use SSL when making HTTP requests |
|
69 | - * |
|
70 | - * If this is not set, SSL will be used where PHP supports it |
|
71 | - * |
|
72 | - * @var bool |
|
73 | - * @author Martin Steel |
|
74 | - */ |
|
75 | - public $ssl; |
|
76 | - |
|
77 | - /** |
|
78 | - * Proxy server hostname (Optional) |
|
79 | - * |
|
80 | - * @var string |
|
81 | - * @author Martin Steel |
|
82 | - */ |
|
83 | - public $proxy_host; |
|
84 | - |
|
85 | - /** |
|
86 | - * Proxy server port (Optional) |
|
87 | - * |
|
88 | - * @var integer |
|
89 | - * @author Martin Steel |
|
90 | - */ |
|
91 | - public $proxy_port; |
|
92 | - |
|
93 | - /** |
|
94 | - * From address used on text messages |
|
95 | - * |
|
96 | - * @var string (11 characters or 12 numbers) |
|
97 | - * @author Martin Steel |
|
98 | - */ |
|
99 | - public $from; |
|
100 | - |
|
101 | - /** |
|
102 | - * Allow long SMS messages (Cost up to 3 credits) |
|
103 | - * |
|
104 | - * @var bool |
|
105 | - * @author Martin Steel |
|
106 | - */ |
|
107 | - public $long; |
|
108 | - |
|
109 | - /** |
|
110 | - * Truncate message text if it is too long |
|
111 | - * |
|
112 | - * @var bool |
|
113 | - * @author Martin Steel |
|
114 | - */ |
|
115 | - public $truncate; |
|
116 | - |
|
117 | - /** |
|
118 | - * Enables various logging of messages when true. |
|
119 | - * |
|
120 | - * @var bool |
|
121 | - * @author Martin Steel |
|
122 | - */ |
|
123 | - public $log; |
|
124 | - |
|
125 | - /** |
|
126 | - * What Clockwork should do if you send an invalid character |
|
127 | - * |
|
128 | - * Possible values: |
|
129 | - * 'error' - Return an error (Messasge is not sent) |
|
130 | - * 'remove' - Remove the invalid character(s) |
|
131 | - * 'replace' - Replace invalid characters where possible, remove others |
|
132 | - * @author Martin Steel |
|
133 | - */ |
|
134 | - public $invalid_char_action; |
|
135 | - |
|
136 | - /** |
|
137 | - * Create a new instance of the Clockwork wrapper |
|
138 | - * |
|
139 | - * @param string key Your Clockwork API Key |
|
140 | - * @param array options Optional parameters for sending SMS |
|
141 | - * @author Martin Steel |
|
142 | - */ |
|
143 | - public function __construct($key, array $options = array()) { |
|
27 | + const VERSION = '1.3.1'; |
|
28 | + |
|
29 | + /** |
|
30 | + * All Clockwork API calls start with BASE_URL |
|
31 | + * @author Martin Steel |
|
32 | + */ |
|
33 | + const API_BASE_URL = 'api.clockworksms.com/xml/'; |
|
34 | + |
|
35 | + /** |
|
36 | + * string to append to API_BASE_URL to check authentication |
|
37 | + * @author Martin Steel |
|
38 | + */ |
|
39 | + const API_AUTH_METHOD = 'authenticate'; |
|
40 | + |
|
41 | + /** |
|
42 | + * string to append to API_BASE_URL for sending SMS |
|
43 | + * @author Martin Steel |
|
44 | + */ |
|
45 | + const API_SMS_METHOD = 'sms'; |
|
46 | + |
|
47 | + /** |
|
48 | + * string to append to API_BASE_URL for checking message credit |
|
49 | + * @author Martin Steel |
|
50 | + */ |
|
51 | + const API_CREDIT_METHOD = 'credit'; |
|
52 | + |
|
53 | + /** |
|
54 | + * string to append to API_BASE_URL for checking account balance |
|
55 | + * @author Martin Steel |
|
56 | + */ |
|
57 | + const API_BALANCE_METHOD = 'balance'; |
|
58 | + |
|
59 | + /** |
|
60 | + * Clockwork API Key |
|
61 | + * |
|
62 | + * @var string |
|
63 | + * @author Martin Steel |
|
64 | + */ |
|
65 | + public $key; |
|
66 | + |
|
67 | + /** |
|
68 | + * Use SSL when making HTTP requests |
|
69 | + * |
|
70 | + * If this is not set, SSL will be used where PHP supports it |
|
71 | + * |
|
72 | + * @var bool |
|
73 | + * @author Martin Steel |
|
74 | + */ |
|
75 | + public $ssl; |
|
76 | + |
|
77 | + /** |
|
78 | + * Proxy server hostname (Optional) |
|
79 | + * |
|
80 | + * @var string |
|
81 | + * @author Martin Steel |
|
82 | + */ |
|
83 | + public $proxy_host; |
|
84 | + |
|
85 | + /** |
|
86 | + * Proxy server port (Optional) |
|
87 | + * |
|
88 | + * @var integer |
|
89 | + * @author Martin Steel |
|
90 | + */ |
|
91 | + public $proxy_port; |
|
92 | + |
|
93 | + /** |
|
94 | + * From address used on text messages |
|
95 | + * |
|
96 | + * @var string (11 characters or 12 numbers) |
|
97 | + * @author Martin Steel |
|
98 | + */ |
|
99 | + public $from; |
|
100 | + |
|
101 | + /** |
|
102 | + * Allow long SMS messages (Cost up to 3 credits) |
|
103 | + * |
|
104 | + * @var bool |
|
105 | + * @author Martin Steel |
|
106 | + */ |
|
107 | + public $long; |
|
108 | + |
|
109 | + /** |
|
110 | + * Truncate message text if it is too long |
|
111 | + * |
|
112 | + * @var bool |
|
113 | + * @author Martin Steel |
|
114 | + */ |
|
115 | + public $truncate; |
|
116 | + |
|
117 | + /** |
|
118 | + * Enables various logging of messages when true. |
|
119 | + * |
|
120 | + * @var bool |
|
121 | + * @author Martin Steel |
|
122 | + */ |
|
123 | + public $log; |
|
124 | + |
|
125 | + /** |
|
126 | + * What Clockwork should do if you send an invalid character |
|
127 | + * |
|
128 | + * Possible values: |
|
129 | + * 'error' - Return an error (Messasge is not sent) |
|
130 | + * 'remove' - Remove the invalid character(s) |
|
131 | + * 'replace' - Replace invalid characters where possible, remove others |
|
132 | + * @author Martin Steel |
|
133 | + */ |
|
134 | + public $invalid_char_action; |
|
135 | + |
|
136 | + /** |
|
137 | + * Create a new instance of the Clockwork wrapper |
|
138 | + * |
|
139 | + * @param string key Your Clockwork API Key |
|
140 | + * @param array options Optional parameters for sending SMS |
|
141 | + * @author Martin Steel |
|
142 | + */ |
|
143 | + public function __construct($key, array $options = array()) { |
|
144 | 144 | if (empty($key)) { |
145 | - throw new ClockworkException("Key can't be blank"); |
|
145 | + throw new ClockworkException("Key can't be blank"); |
|
146 | 146 | } else { |
147 | - $this->key = $key; |
|
147 | + $this->key = $key; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | $this->ssl = (array_key_exists('ssl', $options)) ? $options['ssl'] : null; |
@@ -155,22 +155,22 @@ discard block |
||
155 | 155 | $this->truncate = (array_key_exists('truncate', $options)) ? $options['truncate'] : null; |
156 | 156 | $this->invalid_char_action = (array_key_exists('invalid_char_action', $options)) ? $options['invalid_char_action'] : null; |
157 | 157 | $this->log = (array_key_exists('log', $options)) ? $options['log'] : false; |
158 | - } |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * Send some text messages |
|
162 | - * |
|
163 | - * |
|
164 | - * @author Martin Steel |
|
165 | - */ |
|
166 | - public function send(array $sms) { |
|
160 | + /** |
|
161 | + * Send some text messages |
|
162 | + * |
|
163 | + * |
|
164 | + * @author Martin Steel |
|
165 | + */ |
|
166 | + public function send(array $sms) { |
|
167 | 167 | if (!is_array($sms)) { |
168 | - throw new ClockworkException("sms parameter must be an array"); |
|
168 | + throw new ClockworkException("sms parameter must be an array"); |
|
169 | 169 | } |
170 | 170 | $single_message = $this->is_assoc($sms); |
171 | 171 | |
172 | 172 | if ($single_message) { |
173 | - $sms = array($sms); |
|
173 | + $sms = array($sms); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | $req_doc = new DOMDocument('1.0', 'UTF-8'); |
@@ -182,70 +182,70 @@ discard block |
||
182 | 182 | $root->appendChild($user_node); |
183 | 183 | |
184 | 184 | for ($i = 0; $i < count($sms); $i++) { |
185 | - $single = $sms[$i]; |
|
185 | + $single = $sms[$i]; |
|
186 | 186 | |
187 | - $sms_node = $req_doc->createElement('SMS'); |
|
187 | + $sms_node = $req_doc->createElement('SMS'); |
|
188 | 188 | |
189 | - // Phone number |
|
190 | - $sms_node->appendChild($req_doc->createElement('To', $single['to'])); |
|
189 | + // Phone number |
|
190 | + $sms_node->appendChild($req_doc->createElement('To', $single['to'])); |
|
191 | 191 | |
192 | - // Message text |
|
193 | - $content_node = $req_doc->createElement('Content'); |
|
194 | - $content_node->appendChild($req_doc->createTextNode($single['message'])); |
|
195 | - $sms_node->appendChild($content_node); |
|
192 | + // Message text |
|
193 | + $content_node = $req_doc->createElement('Content'); |
|
194 | + $content_node->appendChild($req_doc->createTextNode($single['message'])); |
|
195 | + $sms_node->appendChild($content_node); |
|
196 | 196 | |
197 | - // From |
|
198 | - if (array_key_exists('from', $single) || isset($this->from)) { |
|
197 | + // From |
|
198 | + if (array_key_exists('from', $single) || isset($this->from)) { |
|
199 | 199 | $from_node = $req_doc->createElement('From'); |
200 | 200 | $from_node->appendChild($req_doc->createTextNode(array_key_exists('from', $single) ? $single['from'] : $this->from)); |
201 | 201 | $sms_node->appendChild($from_node); |
202 | - } |
|
202 | + } |
|
203 | 203 | |
204 | - // Client ID |
|
205 | - if (array_key_exists('client_id', $single)) { |
|
204 | + // Client ID |
|
205 | + if (array_key_exists('client_id', $single)) { |
|
206 | 206 | $client_id_node = $req_doc->createElement('ClientID'); |
207 | 207 | $client_id_node->appendChild($req_doc->createTextNode($single['client_id'])); |
208 | 208 | $sms_node->appendChild($client_id_node); |
209 | - } |
|
209 | + } |
|
210 | 210 | |
211 | - // Long |
|
212 | - if (array_key_exists('long', $single) || isset($this->long)) { |
|
211 | + // Long |
|
212 | + if (array_key_exists('long', $single) || isset($this->long)) { |
|
213 | 213 | $long = array_key_exists('long', $single) ? $single['long'] : $this->long; |
214 | 214 | $long_node = $req_doc->createElement('Long'); |
215 | 215 | $long_node->appendChild($req_doc->createTextNode($long ? 1 : 0)); |
216 | 216 | $sms_node->appendChild($long_node); |
217 | - } |
|
217 | + } |
|
218 | 218 | |
219 | - // Truncate |
|
220 | - if (array_key_exists('truncate', $single) || isset($this->truncate)) { |
|
219 | + // Truncate |
|
220 | + if (array_key_exists('truncate', $single) || isset($this->truncate)) { |
|
221 | 221 | $truncate = array_key_exists('truncate', $single) ? $single['truncate'] : $this->truncate; |
222 | 222 | $trunc_node = $req_doc->createElement('Truncate'); |
223 | 223 | $trunc_node->appendChild($req_doc->createTextNode($truncate ? 1 : 0)); |
224 | 224 | $sms_node->appendChild($trunc_node); |
225 | - } |
|
225 | + } |
|
226 | 226 | |
227 | - // Invalid Char Action |
|
228 | - if (array_key_exists('invalid_char_action', $single) || isset($this->invalid_char_action)) { |
|
227 | + // Invalid Char Action |
|
228 | + if (array_key_exists('invalid_char_action', $single) || isset($this->invalid_char_action)) { |
|
229 | 229 | $action = array_key_exists('invalid_char_action', $single) ? $single['invalid_char_action'] : $this->invalid_char_action; |
230 | 230 | switch (strtolower($action)) { |
231 | - case 'error': |
|
231 | + case 'error': |
|
232 | 232 | $sms_node->appendChild($req_doc->createElement('InvalidCharAction', 1)); |
233 | - break; |
|
234 | - case 'remove': |
|
233 | + break; |
|
234 | + case 'remove': |
|
235 | 235 | $sms_node->appendChild($req_doc->createElement('InvalidCharAction', 2)); |
236 | - break; |
|
237 | - case 'replace': |
|
236 | + break; |
|
237 | + case 'replace': |
|
238 | 238 | $sms_node->appendChild($req_doc->createElement('InvalidCharAction', 3)); |
239 | + break; |
|
240 | + default: |
|
239 | 241 | break; |
240 | - default: |
|
241 | - break; |
|
242 | 242 | } |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | - // Wrapper ID |
|
246 | - $sms_node->appendChild($req_doc->createElement('WrapperID', $i)); |
|
245 | + // Wrapper ID |
|
246 | + $sms_node->appendChild($req_doc->createElement('WrapperID', $i)); |
|
247 | 247 | |
248 | - $root->appendChild($sms_node); |
|
248 | + $root->appendChild($sms_node); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | $req_xml = $req_doc->saveXML(); |
@@ -259,12 +259,12 @@ discard block |
||
259 | 259 | $err_desc = null; |
260 | 260 | |
261 | 261 | foreach($resp_doc->documentElement->childNodes AS $doc_child) { |
262 | - switch(strtolower($doc_child->nodeName)) { |
|
262 | + switch(strtolower($doc_child->nodeName)) { |
|
263 | 263 | case 'sms_resp': |
264 | 264 | $resp = array(); |
265 | 265 | $wrapper_id = null; |
266 | 266 | foreach($doc_child->childNodes AS $resp_node) { |
267 | - switch(strtolower($resp_node->nodeName)) { |
|
267 | + switch(strtolower($resp_node->nodeName)) { |
|
268 | 268 | case 'messageid': |
269 | 269 | $resp['id'] = $resp_node->nodeValue; |
270 | 270 | break; |
@@ -277,13 +277,13 @@ discard block |
||
277 | 277 | case 'wrapperid': |
278 | 278 | $wrapper_id = $resp_node->nodeValue; |
279 | 279 | break; |
280 | - } |
|
280 | + } |
|
281 | 281 | } |
282 | 282 | if( array_key_exists('error_code', $resp ) ) |
283 | 283 | { |
284 | - $resp['success'] = 0; |
|
284 | + $resp['success'] = 0; |
|
285 | 285 | } else { |
286 | - $resp['success'] = 1; |
|
286 | + $resp['success'] = 1; |
|
287 | 287 | } |
288 | 288 | $resp['sms'] = $sms[$wrapper_id]; |
289 | 289 | array_push($response, $resp); |
@@ -294,28 +294,28 @@ discard block |
||
294 | 294 | case 'errdesc': |
295 | 295 | $err_desc = $doc_child->nodeValue; |
296 | 296 | break; |
297 | - } |
|
297 | + } |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | if (isset($err_no)) { |
301 | - throw new ClockworkException($err_desc, $err_no); |
|
301 | + throw new ClockworkException($err_desc, $err_no); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | if ($single_message) { |
305 | - return $response[0]; |
|
305 | + return $response[0]; |
|
306 | 306 | } else { |
307 | - return $response; |
|
307 | + return $response; |
|
308 | 308 | } |
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Check how many SMS credits you have available |
|
313 | - * |
|
314 | - * @return integer SMS credits remaining |
|
315 | - * @deprecated Use checkBalance() instead |
|
316 | - * @author Martin Steel |
|
317 | - */ |
|
318 | - public function checkCredit() { |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Check how many SMS credits you have available |
|
313 | + * |
|
314 | + * @return integer SMS credits remaining |
|
315 | + * @deprecated Use checkBalance() instead |
|
316 | + * @author Martin Steel |
|
317 | + */ |
|
318 | + public function checkCredit() { |
|
319 | 319 | // Create XML doc for request |
320 | 320 | $req_doc = new DOMDocument('1.0', 'UTF-8'); |
321 | 321 | $root = $req_doc->createElement('Credit'); |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | $err_desc = null; |
337 | 337 | |
338 | 338 | foreach ($resp_doc->documentElement->childNodes AS $doc_child) { |
339 | - switch ($doc_child->nodeName) { |
|
339 | + switch ($doc_child->nodeName) { |
|
340 | 340 | case "Credit": |
341 | 341 | $credit = $doc_child->nodeValue; |
342 | 342 | break; |
@@ -348,22 +348,22 @@ discard block |
||
348 | 348 | break; |
349 | 349 | default: |
350 | 350 | break; |
351 | - } |
|
351 | + } |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | if (isset($err_no)) { |
355 | - throw new ClockworkException($err_desc, $err_no); |
|
355 | + throw new ClockworkException($err_desc, $err_no); |
|
356 | 356 | } |
357 | 357 | return $credit; |
358 | - } |
|
358 | + } |
|
359 | 359 | |
360 | - /** |
|
361 | - * Check your account balance |
|
362 | - * |
|
363 | - * @return array Array of account balance: |
|
364 | - * @author Martin Steel |
|
365 | - */ |
|
366 | - public function checkBalance() { |
|
360 | + /** |
|
361 | + * Check your account balance |
|
362 | + * |
|
363 | + * @return array Array of account balance: |
|
364 | + * @author Martin Steel |
|
365 | + */ |
|
366 | + public function checkBalance() { |
|
367 | 367 | // Create XML doc for request |
368 | 368 | $req_doc = new DOMDocument('1.0', 'UTF-8'); |
369 | 369 | $root = $req_doc->createElement('Balance'); |
@@ -384,20 +384,20 @@ discard block |
||
384 | 384 | $err_desc = null; |
385 | 385 | |
386 | 386 | foreach ($resp_doc->documentElement->childNodes as $doc_child) { |
387 | - switch ($doc_child->nodeName) { |
|
387 | + switch ($doc_child->nodeName) { |
|
388 | 388 | case "Balance": |
389 | 389 | $balance = number_format(floatval($doc_child->nodeValue), 2); |
390 | 390 | break; |
391 | 391 | case "Currency": |
392 | 392 | foreach ($doc_child->childNodes as $resp_node) { |
393 | - switch ($resp_node->tagName) { |
|
393 | + switch ($resp_node->tagName) { |
|
394 | 394 | case "Symbol": |
395 | 395 | $symbol = $resp_node->nodeValue; |
396 | 396 | break; |
397 | 397 | case "Code": |
398 | 398 | $code = $resp_node->nodeValue; |
399 | 399 | break; |
400 | - } |
|
400 | + } |
|
401 | 401 | } |
402 | 402 | break; |
403 | 403 | case "ErrNo": |
@@ -408,23 +408,23 @@ discard block |
||
408 | 408 | break; |
409 | 409 | default: |
410 | 410 | break; |
411 | - } |
|
411 | + } |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | if (isset($err_no)) { |
415 | - throw new ClockworkException($err_desc, $err_no); |
|
415 | + throw new ClockworkException($err_desc, $err_no); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | return array( 'symbol' => $symbol, 'balance' => $balance, 'code' => $code ); |
419 | - } |
|
419 | + } |
|
420 | 420 | |
421 | - /** |
|
422 | - * Check whether the API Key is valid |
|
423 | - * |
|
424 | - * @return bool True indicates a valid key |
|
425 | - * @author Martin Steel |
|
426 | - */ |
|
427 | - public function checkKey() { |
|
421 | + /** |
|
422 | + * Check whether the API Key is valid |
|
423 | + * |
|
424 | + * @return bool True indicates a valid key |
|
425 | + * @author Martin Steel |
|
426 | + */ |
|
427 | + public function checkKey() { |
|
428 | 428 | // Create XML doc for request |
429 | 429 | $req_doc = new DOMDocument('1.0', 'UTF-8'); |
430 | 430 | $root = $req_doc->createElement('Authenticate'); |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | $err_desc = null; |
446 | 446 | |
447 | 447 | foreach ($resp_doc->documentElement->childNodes AS $doc_child) { |
448 | - switch ($doc_child->nodeName) { |
|
448 | + switch ($doc_child->nodeName) { |
|
449 | 449 | case "CustID": |
450 | 450 | $cust_id = $doc_child->nodeValue; |
451 | 451 | break; |
@@ -457,33 +457,33 @@ discard block |
||
457 | 457 | break; |
458 | 458 | default: |
459 | 459 | break; |
460 | - } |
|
460 | + } |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | if (isset($err_no)) { |
464 | - throw new ClockworkException($err_desc, $err_no); |
|
464 | + throw new ClockworkException($err_desc, $err_no); |
|
465 | 465 | } |
466 | 466 | return isset($cust_id); |
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * Make an HTTP POST to Clockwork |
|
471 | - * |
|
472 | - * @param string method Clockwork method to call (sms/credit) |
|
473 | - * @param string data Content of HTTP POST |
|
474 | - * |
|
475 | - * @return string Response from Clockwork |
|
476 | - * @author Martin Steel |
|
477 | - */ |
|
478 | - protected function postToClockwork($method, $data) { |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * Make an HTTP POST to Clockwork |
|
471 | + * |
|
472 | + * @param string method Clockwork method to call (sms/credit) |
|
473 | + * @param string data Content of HTTP POST |
|
474 | + * |
|
475 | + * @return string Response from Clockwork |
|
476 | + * @author Martin Steel |
|
477 | + */ |
|
478 | + protected function postToClockwork($method, $data) { |
|
479 | 479 | if ($this->log) { |
480 | - $this->logXML("API $method Request XML", $data); |
|
480 | + $this->logXML("API $method Request XML", $data); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | if( isset( $this->ssl ) ) { |
484 | - $ssl = $this->ssl; |
|
484 | + $ssl = $this->ssl; |
|
485 | 485 | } else { |
486 | - $ssl = $this->sslSupport(); |
|
486 | + $ssl = $this->sslSupport(); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | $url = $ssl ? 'https://' : 'http://'; |
@@ -492,152 +492,152 @@ discard block |
||
492 | 492 | $response = $this->xmlPost($url, $data); |
493 | 493 | |
494 | 494 | if ($this->log) { |
495 | - $this->logXML("API $method Response XML", $response); |
|
495 | + $this->logXML("API $method Response XML", $response); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | return $response; |
499 | - } |
|
500 | - |
|
501 | - /** |
|
502 | - * Make a HTTP POST |
|
503 | - * |
|
504 | - * cURL will be used if available, otherwise tries the PHP stream functions |
|
505 | - * |
|
506 | - * @param string url URL to send to |
|
507 | - * @param string data Data to POST |
|
508 | - * @return string Response returned by server |
|
509 | - * @author Martin Steel |
|
510 | - */ |
|
511 | - protected function xmlPost($url, $data) { |
|
499 | + } |
|
500 | + |
|
501 | + /** |
|
502 | + * Make a HTTP POST |
|
503 | + * |
|
504 | + * cURL will be used if available, otherwise tries the PHP stream functions |
|
505 | + * |
|
506 | + * @param string url URL to send to |
|
507 | + * @param string data Data to POST |
|
508 | + * @return string Response returned by server |
|
509 | + * @author Martin Steel |
|
510 | + */ |
|
511 | + protected function xmlPost($url, $data) { |
|
512 | 512 | if(extension_loaded('curl')) { |
513 | - $ch = curl_init($url); |
|
514 | - curl_setopt($ch, CURLOPT_POST, 1); |
|
515 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
516 | - curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
|
517 | - curl_setopt($ch, CURLOPT_USERAGENT, 'Clockwork PHP Wrapper/1.0' . self::VERSION); |
|
518 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
|
519 | - if (isset($this->proxy_host) && isset($this->proxy_port)) { |
|
513 | + $ch = curl_init($url); |
|
514 | + curl_setopt($ch, CURLOPT_POST, 1); |
|
515 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
516 | + curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
|
517 | + curl_setopt($ch, CURLOPT_USERAGENT, 'Clockwork PHP Wrapper/1.0' . self::VERSION); |
|
518 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
|
519 | + if (isset($this->proxy_host) && isset($this->proxy_port)) { |
|
520 | 520 | curl_setopt($ch, CURLOPT_PROXY, $this->proxy_host); |
521 | 521 | curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxy_port); |
522 | - } |
|
522 | + } |
|
523 | 523 | |
524 | - $response = curl_exec($ch); |
|
525 | - $info = curl_getinfo($ch); |
|
524 | + $response = curl_exec($ch); |
|
525 | + $info = curl_getinfo($ch); |
|
526 | 526 | |
527 | - if ($response === false || $info['http_code'] != 200) { |
|
527 | + if ($response === false || $info['http_code'] != 200) { |
|
528 | 528 | throw new Exception('HTTP Error calling Clockwork API - HTTP Status: ' . $info['http_code'] . ' - cURL Erorr: ' . curl_error($ch)); |
529 | - } elseif (curl_errno($ch) > 0) { |
|
529 | + } elseif (curl_errno($ch) > 0) { |
|
530 | 530 | throw new Exception('HTTP Error calling Clockwork API - cURL Error: ' . curl_error($ch)); |
531 | - } |
|
531 | + } |
|
532 | 532 | |
533 | - curl_close($ch); |
|
533 | + curl_close($ch); |
|
534 | 534 | |
535 | - return $response; |
|
535 | + return $response; |
|
536 | 536 | } elseif (function_exists('stream_get_contents')) { |
537 | - // Enable error Track Errors |
|
538 | - $track = ini_get('track_errors'); |
|
539 | - ini_set('track_errors',true); |
|
537 | + // Enable error Track Errors |
|
538 | + $track = ini_get('track_errors'); |
|
539 | + ini_set('track_errors',true); |
|
540 | 540 | |
541 | - $params = array('http' => array( |
|
542 | - 'method' => 'POST', |
|
543 | - 'header' => "Content-Type: text/xml\r\nUser-Agent: mediaburst PHP Wrapper/" . self::VERSION . "\r\n", |
|
544 | - 'content' => $data |
|
545 | - )); |
|
541 | + $params = array('http' => array( |
|
542 | + 'method' => 'POST', |
|
543 | + 'header' => "Content-Type: text/xml\r\nUser-Agent: mediaburst PHP Wrapper/" . self::VERSION . "\r\n", |
|
544 | + 'content' => $data |
|
545 | + )); |
|
546 | 546 | |
547 | - if (isset($this->proxy_host) && isset($this->proxy_port)) { |
|
547 | + if (isset($this->proxy_host) && isset($this->proxy_port)) { |
|
548 | 548 | $params['http']['proxy'] = 'tcp://'.$this->proxy_host . ':' . $this->proxy_port; |
549 | 549 | $params['http']['request_fulluri'] = True; |
550 | - } |
|
550 | + } |
|
551 | 551 | |
552 | - $ctx = stream_context_create($params); |
|
553 | - $fp = @fopen($url, 'rb', false, $ctx); |
|
554 | - if (!$fp) { |
|
552 | + $ctx = stream_context_create($params); |
|
553 | + $fp = @fopen($url, 'rb', false, $ctx); |
|
554 | + if (!$fp) { |
|
555 | 555 | ini_set('track_errors',$track); |
556 | 556 | throw new Exception("HTTP Error calling Clockwork API - fopen Error: $php_errormsg"); |
557 | - } |
|
558 | - $response = @stream_get_contents($fp); |
|
559 | - if ($response === false) { |
|
557 | + } |
|
558 | + $response = @stream_get_contents($fp); |
|
559 | + if ($response === false) { |
|
560 | 560 | ini_set('track_errors',$track); |
561 | 561 | throw new Exception("HTTP Error calling Clockwork API - stream Error: $php_errormsg"); |
562 | - } |
|
563 | - ini_set('track_errors',$track); |
|
564 | - return $response; |
|
562 | + } |
|
563 | + ini_set('track_errors',$track); |
|
564 | + return $response; |
|
565 | 565 | } else { |
566 | - throw new Exception("Clockwork requires PHP5 with cURL or HTTP stream support"); |
|
566 | + throw new Exception("Clockwork requires PHP5 with cURL or HTTP stream support"); |
|
567 | 567 | } |
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Does the server/HTTP wrapper support SSL |
|
572 | - * |
|
573 | - * This is a best guess effort, some servers have weird setups where even |
|
574 | - * though cURL is compiled with SSL support is still fails to make |
|
575 | - * any requests. |
|
576 | - * |
|
577 | - * @return bool True if SSL is supported |
|
578 | - * @author Martin Steel |
|
579 | - */ |
|
580 | - protected function sslSupport() { |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * Does the server/HTTP wrapper support SSL |
|
572 | + * |
|
573 | + * This is a best guess effort, some servers have weird setups where even |
|
574 | + * though cURL is compiled with SSL support is still fails to make |
|
575 | + * any requests. |
|
576 | + * |
|
577 | + * @return bool True if SSL is supported |
|
578 | + * @author Martin Steel |
|
579 | + */ |
|
580 | + protected function sslSupport() { |
|
581 | 581 | $ssl = false; |
582 | 582 | // See if PHP is compiled with cURL |
583 | 583 | if (extension_loaded('curl')) { |
584 | - $version = curl_version(); |
|
585 | - $ssl = ($version['features'] & CURL_VERSION_SSL) ? true : false; |
|
584 | + $version = curl_version(); |
|
585 | + $ssl = ($version['features'] & CURL_VERSION_SSL) ? true : false; |
|
586 | 586 | } elseif (extension_loaded('openssl')) { |
587 | - $ssl = true; |
|
587 | + $ssl = true; |
|
588 | 588 | } |
589 | 589 | return $ssl; |
590 | - } |
|
591 | - |
|
592 | - /** |
|
593 | - * Log some XML, tidily if possible, in the PHP error log |
|
594 | - * |
|
595 | - * @param string log_msg The log message to prepend to the XML |
|
596 | - * @param string xml An XML formatted string |
|
597 | - * |
|
598 | - * @return void |
|
599 | - * @author Martin Steel |
|
600 | - */ |
|
601 | - protected function logXML($log_msg, $xml) { |
|
590 | + } |
|
591 | + |
|
592 | + /** |
|
593 | + * Log some XML, tidily if possible, in the PHP error log |
|
594 | + * |
|
595 | + * @param string log_msg The log message to prepend to the XML |
|
596 | + * @param string xml An XML formatted string |
|
597 | + * |
|
598 | + * @return void |
|
599 | + * @author Martin Steel |
|
600 | + */ |
|
601 | + protected function logXML($log_msg, $xml) { |
|
602 | 602 | // Tidy if possible |
603 | 603 | if (class_exists('tidy')) { |
604 | - $tidy = new tidy; |
|
605 | - $config = array( |
|
606 | - 'indent' => true, |
|
607 | - 'input-xml' => true, |
|
608 | - 'output-xml' => true, |
|
609 | - 'wrap' => 200 |
|
610 | - ); |
|
611 | - $tidy->parseString($xml, $config, 'utf8'); |
|
612 | - $tidy->cleanRepair(); |
|
613 | - $xml = $tidy; |
|
604 | + $tidy = new tidy; |
|
605 | + $config = array( |
|
606 | + 'indent' => true, |
|
607 | + 'input-xml' => true, |
|
608 | + 'output-xml' => true, |
|
609 | + 'wrap' => 200 |
|
610 | + ); |
|
611 | + $tidy->parseString($xml, $config, 'utf8'); |
|
612 | + $tidy->cleanRepair(); |
|
613 | + $xml = $tidy; |
|
614 | 614 | } |
615 | 615 | // Output |
616 | 616 | error_log("Clockwork $log_msg: $xml"); |
617 | - } |
|
618 | - |
|
619 | - /** |
|
620 | - * Check if an array is associative |
|
621 | - * |
|
622 | - * @param array $array Array to check |
|
623 | - * @return bool |
|
624 | - * @author Martin Steel |
|
625 | - */ |
|
626 | - protected function is_assoc($array) { |
|
617 | + } |
|
618 | + |
|
619 | + /** |
|
620 | + * Check if an array is associative |
|
621 | + * |
|
622 | + * @param array $array Array to check |
|
623 | + * @return bool |
|
624 | + * @author Martin Steel |
|
625 | + */ |
|
626 | + protected function is_assoc($array) { |
|
627 | 627 | return (bool)count(array_filter(array_keys($array), 'is_string')); |
628 | - } |
|
628 | + } |
|
629 | 629 | |
630 | - /** |
|
631 | - * Check if a number is a valid MSISDN |
|
632 | - * |
|
633 | - * @param string $val Value to check |
|
634 | - * @return bool True if valid MSISDN |
|
635 | - * @author James Inman |
|
636 | - * @since 1.3.0 |
|
637 | - * @todo Take an optional country code and check that the number starts with it |
|
638 | - */ |
|
639 | - public static function is_valid_msisdn($val) { |
|
630 | + /** |
|
631 | + * Check if a number is a valid MSISDN |
|
632 | + * |
|
633 | + * @param string $val Value to check |
|
634 | + * @return bool True if valid MSISDN |
|
635 | + * @author James Inman |
|
636 | + * @since 1.3.0 |
|
637 | + * @todo Take an optional country code and check that the number starts with it |
|
638 | + */ |
|
639 | + public static function is_valid_msisdn($val) { |
|
640 | 640 | return preg_match( '/^[1-9][0-9]{7,12}$/', $val ); |
641 | - } |
|
641 | + } |
|
642 | 642 | |
643 | 643 | } |
@@ -27,18 +27,18 @@ |
||
27 | 27 | $array_keys = array_keys($_GET); |
28 | 28 | |
29 | 29 | if (!empty($array_keys)) { |
30 | - $username = substr($array_keys[0],0,20); // max len of an username |
|
31 | - $friend_id = UserManager::get_user_id_from_username($username); |
|
30 | + $username = substr($array_keys[0],0,20); // max len of an username |
|
31 | + $friend_id = UserManager::get_user_id_from_username($username); |
|
32 | 32 | |
33 | - if ($friend_id) { |
|
34 | - SocialManager::display_individual_user($friend_id); |
|
35 | - } else { |
|
36 | - // we cant find your friend |
|
37 | - header('Location: whoisonline.php'); |
|
38 | - exit; |
|
39 | - } |
|
33 | + if ($friend_id) { |
|
34 | + SocialManager::display_individual_user($friend_id); |
|
35 | + } else { |
|
36 | + // we cant find your friend |
|
37 | + header('Location: whoisonline.php'); |
|
38 | + exit; |
|
39 | + } |
|
40 | 40 | } else { |
41 | - // we cant find your friend |
|
42 | - header('Location: whoisonline.php'); |
|
43 | - exit; |
|
41 | + // we cant find your friend |
|
42 | + header('Location: whoisonline.php'); |
|
43 | + exit; |
|
44 | 44 | } |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | /* For licensing terms, see /license.txt */ |
3 | 3 | /** |
4 | - * This script allows for specific registration rules (see CustomPages feature of Chamilo) |
|
5 | - * Please contact CBlue regarding any licences issues. |
|
6 | - * Author: [email protected] |
|
7 | - * Copyright: CBlue SPRL, 20XX (GNU/GPLv3) |
|
8 | - * @package chamilo.custompages |
|
9 | - **/ |
|
4 | + * This script allows for specific registration rules (see CustomPages feature of Chamilo) |
|
5 | + * Please contact CBlue regarding any licences issues. |
|
6 | + * Author: [email protected] |
|
7 | + * Copyright: CBlue SPRL, 20XX (GNU/GPLv3) |
|
8 | + * @package chamilo.custompages |
|
9 | + **/ |
|
10 | 10 | |
11 | 11 | require_once('language.php'); |
12 | 12 | require_once('../inc/global.inc.php'); |
@@ -27,22 +27,22 @@ |
||
27 | 27 | |
28 | 28 | if (!empty($_POST)) |
29 | 29 | { |
30 | - foreach ( $_POST as $key => $value ) |
|
31 | - { |
|
32 | - if ( ( !is_string($value) && !is_numeric($value) ) || !is_string($key) ) |
|
33 | - continue; |
|
30 | + foreach ( $_POST as $key => $value ) |
|
31 | + { |
|
32 | + if ( ( !is_string($value) && !is_numeric($value) ) || !is_string($key) ) |
|
33 | + continue; |
|
34 | 34 | |
35 | - if ( get_magic_quotes_gpc() ) |
|
36 | - $value = htmlspecialchars( stripslashes((string)$value) ); |
|
37 | - else |
|
38 | - $value = htmlspecialchars( (string)$value ); |
|
35 | + if ( get_magic_quotes_gpc() ) |
|
36 | + $value = htmlspecialchars( stripslashes((string)$value) ); |
|
37 | + else |
|
38 | + $value = htmlspecialchars( (string)$value ); |
|
39 | 39 | ?> |
40 | 40 | <tr> |
41 | 41 | <th style="vertical-align: top"><?php echo htmlspecialchars( (string)$key ); ?></th> |
42 | 42 | <td><pre class="samples"><?php echo $value; ?></pre></td> |
43 | 43 | </tr> |
44 | 44 | <?php |
45 | - } |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | ?> |
48 | 48 | </table> |
@@ -188,7 +188,7 @@ |
||
188 | 188 | |
189 | 189 | //Show the chamilo mascot |
190 | 190 | if (empty($courseAndSessions['html']) && !isset($_GET['history'])) { |
191 | - $controller->tpl->assign('welcome_to_course_block', $controller->return_welcome_to_course_block()); |
|
191 | + $controller->tpl->assign('welcome_to_course_block', $controller->return_welcome_to_course_block()); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | $controller->tpl->assign('content', $courseAndSessions['html']); |
@@ -7,7 +7,7 @@ |
||
7 | 7 | |
8 | 8 | $actions = ''; |
9 | 9 | if (api_is_platform_admin()) { |
10 | - $actions = '<a href="'.api_get_path(WEB_PATH).'main/admin/system_announcements.php">'. |
|
10 | + $actions = '<a href="'.api_get_path(WEB_PATH).'main/admin/system_announcements.php">'. |
|
11 | 11 | Display::return_icon('edit.png', get_lang('EditSystemAnnouncement'), array(), 32).'</a>'; |
12 | 12 | } |
13 | 13 |
@@ -684,7 +684,7 @@ |
||
684 | 684 | |
685 | 685 | foreach ($user_data as $key => $value) { |
686 | 686 | if (substr($key, 0, 6) == 'extra_') { //an extra field |
687 | - continue; |
|
687 | + continue; |
|
688 | 688 | } elseif (strpos($key, 'remove_extra_') !== false) { |
689 | 689 | } else { |
690 | 690 | if (in_array($key, $available_values_to_modify)) { |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * |
15 | 15 | **/ |
16 | 16 | function cas_configured() { |
17 | - global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri; |
|
17 | + global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri; |
|
18 | 18 | $res = false; |
19 | 19 | if (!empty($cas_auth_ver) && !empty($cas_auth_server) && !empty($cas_auth_port)) { |
20 | 20 | $res = true; |
@@ -32,23 +32,23 @@ discard block |
||
32 | 32 | |
33 | 33 | function cas_is_authenticated() |
34 | 34 | { |
35 | - global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri; |
|
36 | - global $PHPCAS_CLIENT; |
|
37 | - global $logout; |
|
35 | + global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri; |
|
36 | + global $PHPCAS_CLIENT; |
|
37 | + global $logout; |
|
38 | 38 | |
39 | 39 | if (!cas_configured()) { |
40 | 40 | return; |
41 | 41 | } |
42 | 42 | |
43 | - if (!is_object($PHPCAS_CLIENT)) { |
|
44 | - phpCAS::client($cas_auth_ver,$cas_auth_server,$cas_auth_port,$cas_auth_uri); |
|
45 | - phpCAS::setNoCasServerValidation(); |
|
46 | - } |
|
47 | - $auth = phpCAS::checkAuthentication(); |
|
43 | + if (!is_object($PHPCAS_CLIENT)) { |
|
44 | + phpCAS::client($cas_auth_ver,$cas_auth_server,$cas_auth_port,$cas_auth_uri); |
|
45 | + phpCAS::setNoCasServerValidation(); |
|
46 | + } |
|
47 | + $auth = phpCAS::checkAuthentication(); |
|
48 | 48 | |
49 | - if ($auth) { |
|
50 | - $login= trim(phpCAS::getUser()); |
|
51 | - /* |
|
49 | + if ($auth) { |
|
50 | + $login= trim(phpCAS::getUser()); |
|
51 | + /* |
|
52 | 52 | Get user attributes. Here are the attributes for crdp platform |
53 | 53 | sn => name |
54 | 54 | ENTPersonMailInterne => mail |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | ENTPersonProfils => profil |
57 | 57 | givenName => first name |
58 | 58 | */ |
59 | - /*$user=phpCAS::getAttributes(); |
|
59 | + /*$user=phpCAS::getAttributes(); |
|
60 | 60 | $firstName = trim($user['givenName']); |
61 | 61 | $lastName = trim($user['sn']); |
62 | 62 | $login = trim($user['ENTPersonAlias']); |
@@ -79,54 +79,54 @@ discard block |
||
79 | 79 | default: |
80 | 80 | $status=5; // Student |
81 | 81 | }*/ |
82 | - if (!$logout){ |
|
83 | - // get user info from username |
|
84 | - $tab_user_info = api_get_user_info($login); |
|
85 | - |
|
86 | - // user found in the chamilo database |
|
87 | - if (is_array($tab_user_info)) { |
|
88 | - // if option is on we update user automatically from ldap server |
|
89 | - if (api_get_setting("update_user_info_cas_with_ldap") == "true") { |
|
82 | + if (!$logout){ |
|
83 | + // get user info from username |
|
84 | + $tab_user_info = api_get_user_info($login); |
|
85 | + |
|
86 | + // user found in the chamilo database |
|
87 | + if (is_array($tab_user_info)) { |
|
88 | + // if option is on we update user automatically from ldap server |
|
89 | + if (api_get_setting("update_user_info_cas_with_ldap") == "true") { |
|
90 | 90 | $ldapuser = extldap_authenticate($login, 'nopass', true); |
91 | 91 | if ($ldapuser !== false) { |
92 | 92 | $chamilo_user = extldap_get_chamilo_user($ldapuser); |
93 | 93 | $chamilo_user['user_id'] = $tab_user_info['user_id']; |
94 | 94 | $chamilo_user['status'] = $tab_user_info['status']; |
95 | - UserManager::update_user ($chamilo_user["user_id"], $chamilo_user["firstname"], $chamilo_user["lastname"], $login, null, null, $chamilo_user["email"], $chamilo_user["status"], '', '', '', '', 1, null, 0, null,'') ; |
|
96 | - } |
|
97 | - } |
|
98 | - return $login; |
|
99 | - } |
|
100 | - // user not found |
|
101 | - else { |
|
102 | - // if option is on we can ADD user automatically from ldap server or by modify own profil |
|
103 | - $user_added = false; |
|
104 | - switch (api_get_setting("cas_add_user_activate")) { |
|
105 | - case PLATFORM_AUTH_SOURCE : |
|
106 | - // user will have to modify firstname, lastname, email in chamilo profil edit |
|
107 | - $userdata = get_lang("EditInProfil"); |
|
108 | - UserManager::create_user($userdata, $userdata, '5', $userdata, $login, 'casplaceholder', '','','','',CAS_AUTH_SOURCE); |
|
109 | - $user_added = $login; |
|
110 | - break; |
|
111 | - case LDAP_AUTH_SOURCE : |
|
112 | - // user info are read from ldap connexion |
|
113 | - // get user info from ldap server |
|
114 | - // user has already been authenticated by CAS |
|
115 | - // If user not found in LDAP, user not created |
|
116 | - $ldapuser = extldap_authenticate($login, 'nopass', true); |
|
117 | - if ($ldapuser !== false) { |
|
118 | - $chamilo_user = extldap_get_chamilo_user($ldapuser); |
|
95 | + UserManager::update_user ($chamilo_user["user_id"], $chamilo_user["firstname"], $chamilo_user["lastname"], $login, null, null, $chamilo_user["email"], $chamilo_user["status"], '', '', '', '', 1, null, 0, null,'') ; |
|
96 | + } |
|
97 | + } |
|
98 | + return $login; |
|
99 | + } |
|
100 | + // user not found |
|
101 | + else { |
|
102 | + // if option is on we can ADD user automatically from ldap server or by modify own profil |
|
103 | + $user_added = false; |
|
104 | + switch (api_get_setting("cas_add_user_activate")) { |
|
105 | + case PLATFORM_AUTH_SOURCE : |
|
106 | + // user will have to modify firstname, lastname, email in chamilo profil edit |
|
107 | + $userdata = get_lang("EditInProfil"); |
|
108 | + UserManager::create_user($userdata, $userdata, '5', $userdata, $login, 'casplaceholder', '','','','',CAS_AUTH_SOURCE); |
|
109 | + $user_added = $login; |
|
110 | + break; |
|
111 | + case LDAP_AUTH_SOURCE : |
|
112 | + // user info are read from ldap connexion |
|
113 | + // get user info from ldap server |
|
114 | + // user has already been authenticated by CAS |
|
115 | + // If user not found in LDAP, user not created |
|
116 | + $ldapuser = extldap_authenticate($login, 'nopass', true); |
|
117 | + if ($ldapuser !== false) { |
|
118 | + $chamilo_user = extldap_get_chamilo_user($ldapuser); |
|
119 | 119 | $chamilo_user['username'] = $login; |
120 | 120 | $chamilo_user['auth_source'] = CAS_AUTH_SOURCE; |
121 | 121 | $chamilo_uid = external_add_user($chamilo_user); |
122 | - $user_added = $login; |
|
123 | - } |
|
124 | - break; |
|
125 | - default : break; |
|
126 | - } |
|
127 | - return $user_added; |
|
128 | - } |
|
129 | - } |
|
122 | + $user_added = $login; |
|
123 | + } |
|
124 | + break; |
|
125 | + default : break; |
|
126 | + } |
|
127 | + return $user_added; |
|
128 | + } |
|
129 | + } |
|
130 | 130 | // //If the user is in the dokeos database and we are ,not in a logout request, we upgrade his infomration by ldap |
131 | 131 | // if (! $logout){ |
132 | 132 | // $user_table = Database::get_main_table(TABLE_MAIN_USER); |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | // |
149 | 149 | // } |
150 | 150 | // } |
151 | - return $login; |
|
151 | + return $login; |
|
152 | 152 | } else { |
153 | - return false; |
|
154 | - } |
|
153 | + return false; |
|
154 | + } |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 | */ |
30 | 30 | /** |
31 | - * @file CAS/PGTStorage/pgt-file.php |
|
32 | - * Basic class for PGT file storage |
|
33 | - */ |
|
31 | + * @file CAS/PGTStorage/pgt-file.php |
|
32 | + * Basic class for PGT file storage |
|
33 | + */ |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * @class PGTStorageFile |
@@ -44,231 +44,231 @@ discard block |
||
44 | 44 | |
45 | 45 | class PGTStorageFile extends PGTStorage |
46 | 46 | { |
47 | - /** |
|
48 | - * @addtogroup internalPGTStorageFile |
|
49 | - * @{ |
|
50 | - */ |
|
47 | + /** |
|
48 | + * @addtogroup internalPGTStorageFile |
|
49 | + * @{ |
|
50 | + */ |
|
51 | 51 | |
52 | - /** |
|
53 | - * a string telling where PGT's should be stored on the filesystem. Written by |
|
54 | - * PGTStorageFile::PGTStorageFile(), read by getPath(). |
|
55 | - * |
|
56 | - * @private |
|
57 | - */ |
|
58 | - var $_path; |
|
52 | + /** |
|
53 | + * a string telling where PGT's should be stored on the filesystem. Written by |
|
54 | + * PGTStorageFile::PGTStorageFile(), read by getPath(). |
|
55 | + * |
|
56 | + * @private |
|
57 | + */ |
|
58 | + var $_path; |
|
59 | 59 | |
60 | - /** |
|
61 | - * This method returns the name of the directory where PGT's should be stored |
|
62 | - * on the filesystem. |
|
63 | - * |
|
64 | - * @return the name of a directory (with leading and trailing '/') |
|
65 | - * |
|
66 | - * @private |
|
67 | - */ |
|
68 | - function getPath() |
|
60 | + /** |
|
61 | + * This method returns the name of the directory where PGT's should be stored |
|
62 | + * on the filesystem. |
|
63 | + * |
|
64 | + * @return the name of a directory (with leading and trailing '/') |
|
65 | + * |
|
66 | + * @private |
|
67 | + */ |
|
68 | + function getPath() |
|
69 | 69 | { |
70 | - return $this->_path; |
|
70 | + return $this->_path; |
|
71 | 71 | } |
72 | 72 | |
73 | - /** |
|
74 | - * a string telling the format to use to store PGT's (plain or xml). Written by |
|
75 | - * PGTStorageFile::PGTStorageFile(), read by getFormat(). |
|
76 | - * |
|
77 | - * @private |
|
78 | - */ |
|
79 | - var $_format; |
|
73 | + /** |
|
74 | + * a string telling the format to use to store PGT's (plain or xml). Written by |
|
75 | + * PGTStorageFile::PGTStorageFile(), read by getFormat(). |
|
76 | + * |
|
77 | + * @private |
|
78 | + */ |
|
79 | + var $_format; |
|
80 | 80 | |
81 | - /** |
|
82 | - * This method returns the format to use when storing PGT's on the filesystem. |
|
83 | - * |
|
84 | - * @return a string corresponding to the format used (plain or xml). |
|
85 | - * |
|
86 | - * @private |
|
87 | - */ |
|
88 | - function getFormat() |
|
81 | + /** |
|
82 | + * This method returns the format to use when storing PGT's on the filesystem. |
|
83 | + * |
|
84 | + * @return a string corresponding to the format used (plain or xml). |
|
85 | + * |
|
86 | + * @private |
|
87 | + */ |
|
88 | + function getFormat() |
|
89 | 89 | { |
90 | - return $this->_format; |
|
90 | + return $this->_format; |
|
91 | 91 | } |
92 | 92 | |
93 | - // ######################################################################## |
|
94 | - // DEBUGGING |
|
95 | - // ######################################################################## |
|
93 | + // ######################################################################## |
|
94 | + // DEBUGGING |
|
95 | + // ######################################################################## |
|
96 | 96 | |
97 | - /** |
|
98 | - * This method returns an informational string giving the type of storage |
|
99 | - * used by the object (used for debugging purposes). |
|
100 | - * |
|
101 | - * @return an informational string. |
|
102 | - * @public |
|
103 | - */ |
|
104 | - function getStorageType() |
|
97 | + /** |
|
98 | + * This method returns an informational string giving the type of storage |
|
99 | + * used by the object (used for debugging purposes). |
|
100 | + * |
|
101 | + * @return an informational string. |
|
102 | + * @public |
|
103 | + */ |
|
104 | + function getStorageType() |
|
105 | 105 | { |
106 | - return "file"; |
|
106 | + return "file"; |
|
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * This method returns an informational string giving informations on the |
|
111 | - * parameters of the storage.(used for debugging purposes). |
|
112 | - * |
|
113 | - * @return an informational string. |
|
114 | - * @public |
|
115 | - */ |
|
116 | - function getStorageInfo() |
|
109 | + /** |
|
110 | + * This method returns an informational string giving informations on the |
|
111 | + * parameters of the storage.(used for debugging purposes). |
|
112 | + * |
|
113 | + * @return an informational string. |
|
114 | + * @public |
|
115 | + */ |
|
116 | + function getStorageInfo() |
|
117 | 117 | { |
118 | - return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\''; |
|
118 | + return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\''; |
|
119 | 119 | } |
120 | 120 | |
121 | - // ######################################################################## |
|
122 | - // CONSTRUCTOR |
|
123 | - // ######################################################################## |
|
121 | + // ######################################################################## |
|
122 | + // CONSTRUCTOR |
|
123 | + // ######################################################################## |
|
124 | 124 | |
125 | - /** |
|
126 | - * The class constructor, called by CASClient::SetPGTStorageFile(). |
|
127 | - * |
|
128 | - * @param $cas_parent the CASClient instance that creates the object. |
|
129 | - * @param $format the format used to store the PGT's (`plain' and `xml' allowed). |
|
130 | - * @param $path the path where the PGT's should be stored |
|
131 | - * |
|
132 | - * @public |
|
133 | - */ |
|
134 | - function PGTStorageFile($cas_parent,$format,$path) |
|
125 | + /** |
|
126 | + * The class constructor, called by CASClient::SetPGTStorageFile(). |
|
127 | + * |
|
128 | + * @param $cas_parent the CASClient instance that creates the object. |
|
129 | + * @param $format the format used to store the PGT's (`plain' and `xml' allowed). |
|
130 | + * @param $path the path where the PGT's should be stored |
|
131 | + * |
|
132 | + * @public |
|
133 | + */ |
|
134 | + function PGTStorageFile($cas_parent,$format,$path) |
|
135 | 135 | { |
136 | - phpCAS::traceBegin(); |
|
137 | - // call the ancestor's constructor |
|
138 | - $this->PGTStorage($cas_parent); |
|
136 | + phpCAS::traceBegin(); |
|
137 | + // call the ancestor's constructor |
|
138 | + $this->PGTStorage($cas_parent); |
|
139 | 139 | |
140 | - if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
141 | - if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
140 | + if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
141 | + if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
142 | 142 | |
143 | - // check that the path is an absolute path |
|
144 | - if (getenv("OS")=="Windows_NT"){ |
|
143 | + // check that the path is an absolute path |
|
144 | + if (getenv("OS")=="Windows_NT"){ |
|
145 | 145 | |
146 | - if (!preg_match('`^[a-zA-Z]:`', $path)) { |
|
147 | - phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
148 | - } |
|
146 | + if (!preg_match('`^[a-zA-Z]:`', $path)) { |
|
147 | + phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
148 | + } |
|
149 | 149 | |
150 | - } |
|
151 | - else |
|
152 | - { |
|
150 | + } |
|
151 | + else |
|
152 | + { |
|
153 | 153 | |
154 | - if ( $path[0] != '/' ) { |
|
155 | - phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
156 | - } |
|
154 | + if ( $path[0] != '/' ) { |
|
155 | + phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
156 | + } |
|
157 | 157 | |
158 | - // store the path (with a leading and trailing '/') |
|
159 | - $path = preg_replace('|[/]*$|','/',$path); |
|
160 | - $path = preg_replace('|^[/]*|','/',$path); |
|
161 | - } |
|
158 | + // store the path (with a leading and trailing '/') |
|
159 | + $path = preg_replace('|[/]*$|','/',$path); |
|
160 | + $path = preg_replace('|^[/]*|','/',$path); |
|
161 | + } |
|
162 | 162 | |
163 | - $this->_path = $path; |
|
164 | - // check the format and store it |
|
165 | - switch ($format) { |
|
166 | - case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN: |
|
163 | + $this->_path = $path; |
|
164 | + // check the format and store it |
|
165 | + switch ($format) { |
|
166 | + case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN: |
|
167 | 167 | case CAS_PGT_STORAGE_FILE_FORMAT_XML: |
168 | - $this->_format = $format; |
|
169 | - break; |
|
170 | - default: |
|
171 | - phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)'); |
|
172 | - } |
|
173 | - phpCAS::traceEnd(); |
|
168 | + $this->_format = $format; |
|
169 | + break; |
|
170 | + default: |
|
171 | + phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)'); |
|
172 | + } |
|
173 | + phpCAS::traceEnd(); |
|
174 | 174 | } |
175 | 175 | |
176 | - // ######################################################################## |
|
177 | - // INITIALIZATION |
|
178 | - // ######################################################################## |
|
176 | + // ######################################################################## |
|
177 | + // INITIALIZATION |
|
178 | + // ######################################################################## |
|
179 | 179 | |
180 | - /** |
|
181 | - * This method is used to initialize the storage. Halts on error. |
|
182 | - * |
|
183 | - * @public |
|
184 | - */ |
|
185 | - function init() |
|
180 | + /** |
|
181 | + * This method is used to initialize the storage. Halts on error. |
|
182 | + * |
|
183 | + * @public |
|
184 | + */ |
|
185 | + function init() |
|
186 | 186 | { |
187 | - phpCAS::traceBegin(); |
|
188 | - // if the storage has already been initialized, return immediatly |
|
189 | - if ( $this->isInitialized() ) |
|
190 | - return; |
|
191 | - // call the ancestor's method (mark as initialized) |
|
192 | - parent::init(); |
|
193 | - phpCAS::traceEnd(); |
|
187 | + phpCAS::traceBegin(); |
|
188 | + // if the storage has already been initialized, return immediatly |
|
189 | + if ( $this->isInitialized() ) |
|
190 | + return; |
|
191 | + // call the ancestor's method (mark as initialized) |
|
192 | + parent::init(); |
|
193 | + phpCAS::traceEnd(); |
|
194 | 194 | } |
195 | 195 | |
196 | - // ######################################################################## |
|
197 | - // PGT I/O |
|
198 | - // ######################################################################## |
|
196 | + // ######################################################################## |
|
197 | + // PGT I/O |
|
198 | + // ######################################################################## |
|
199 | 199 | |
200 | - /** |
|
201 | - * This method returns the filename corresponding to a PGT Iou. |
|
202 | - * |
|
203 | - * @param $pgt_iou the PGT iou. |
|
204 | - * |
|
205 | - * @return a filename |
|
206 | - * @private |
|
207 | - */ |
|
208 | - function getPGTIouFilename($pgt_iou) |
|
200 | + /** |
|
201 | + * This method returns the filename corresponding to a PGT Iou. |
|
202 | + * |
|
203 | + * @param $pgt_iou the PGT iou. |
|
204 | + * |
|
205 | + * @return a filename |
|
206 | + * @private |
|
207 | + */ |
|
208 | + function getPGTIouFilename($pgt_iou) |
|
209 | 209 | { |
210 | - phpCAS::traceBegin(); |
|
211 | - $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat(); |
|
212 | - phpCAS::traceEnd($filename); |
|
213 | - return $filename; |
|
210 | + phpCAS::traceBegin(); |
|
211 | + $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat(); |
|
212 | + phpCAS::traceEnd($filename); |
|
213 | + return $filename; |
|
214 | 214 | } |
215 | 215 | |
216 | - /** |
|
217 | - * This method stores a PGT and its corresponding PGT Iou into a file. Echoes a |
|
218 | - * warning on error. |
|
219 | - * |
|
220 | - * @param $pgt the PGT |
|
221 | - * @param $pgt_iou the PGT iou |
|
222 | - * |
|
223 | - * @public |
|
224 | - */ |
|
225 | - function write($pgt,$pgt_iou) |
|
216 | + /** |
|
217 | + * This method stores a PGT and its corresponding PGT Iou into a file. Echoes a |
|
218 | + * warning on error. |
|
219 | + * |
|
220 | + * @param $pgt the PGT |
|
221 | + * @param $pgt_iou the PGT iou |
|
222 | + * |
|
223 | + * @public |
|
224 | + */ |
|
225 | + function write($pgt,$pgt_iou) |
|
226 | 226 | { |
227 | - phpCAS::traceBegin(); |
|
228 | - $fname = $this->getPGTIouFilename($pgt_iou); |
|
229 | - if ( $f=fopen($fname,"w") ) { |
|
230 | - if ( fputs($f,$pgt) === FALSE ) { |
|
231 | - phpCAS::error('could not write PGT to `'.$fname.'\''); |
|
232 | - } |
|
233 | - fclose($f); |
|
234 | - } else { |
|
235 | - phpCAS::error('could not open `'.$fname.'\''); |
|
236 | - } |
|
237 | - phpCAS::traceEnd(); |
|
227 | + phpCAS::traceBegin(); |
|
228 | + $fname = $this->getPGTIouFilename($pgt_iou); |
|
229 | + if ( $f=fopen($fname,"w") ) { |
|
230 | + if ( fputs($f,$pgt) === FALSE ) { |
|
231 | + phpCAS::error('could not write PGT to `'.$fname.'\''); |
|
232 | + } |
|
233 | + fclose($f); |
|
234 | + } else { |
|
235 | + phpCAS::error('could not open `'.$fname.'\''); |
|
236 | + } |
|
237 | + phpCAS::traceEnd(); |
|
238 | 238 | } |
239 | 239 | |
240 | - /** |
|
241 | - * This method reads a PGT corresponding to a PGT Iou and deletes the |
|
242 | - * corresponding file. |
|
243 | - * |
|
244 | - * @param $pgt_iou the PGT iou |
|
245 | - * |
|
246 | - * @return the corresponding PGT, or FALSE on error |
|
247 | - * |
|
248 | - * @public |
|
249 | - */ |
|
250 | - function read($pgt_iou) |
|
240 | + /** |
|
241 | + * This method reads a PGT corresponding to a PGT Iou and deletes the |
|
242 | + * corresponding file. |
|
243 | + * |
|
244 | + * @param $pgt_iou the PGT iou |
|
245 | + * |
|
246 | + * @return the corresponding PGT, or FALSE on error |
|
247 | + * |
|
248 | + * @public |
|
249 | + */ |
|
250 | + function read($pgt_iou) |
|
251 | 251 | { |
252 | - phpCAS::traceBegin(); |
|
253 | - $pgt = FALSE; |
|
254 | - $fname = $this->getPGTIouFilename($pgt_iou); |
|
255 | - if ( !($f=fopen($fname,"r")) ) { |
|
256 | - phpCAS::trace('could not open `'.$fname.'\''); |
|
257 | - } else { |
|
258 | - if ( ($pgt=fgets($f)) === FALSE ) { |
|
259 | - phpCAS::trace('could not read PGT from `'.$fname.'\''); |
|
260 | - } |
|
261 | - fclose($f); |
|
262 | - } |
|
252 | + phpCAS::traceBegin(); |
|
253 | + $pgt = FALSE; |
|
254 | + $fname = $this->getPGTIouFilename($pgt_iou); |
|
255 | + if ( !($f=fopen($fname,"r")) ) { |
|
256 | + phpCAS::trace('could not open `'.$fname.'\''); |
|
257 | + } else { |
|
258 | + if ( ($pgt=fgets($f)) === FALSE ) { |
|
259 | + phpCAS::trace('could not read PGT from `'.$fname.'\''); |
|
260 | + } |
|
261 | + fclose($f); |
|
262 | + } |
|
263 | 263 | |
264 | - // delete the PGT file |
|
265 | - @unlink($fname); |
|
264 | + // delete the PGT file |
|
265 | + @unlink($fname); |
|
266 | 266 | |
267 | - phpCAS::traceEnd($pgt); |
|
268 | - return $pgt; |
|
267 | + phpCAS::traceEnd($pgt); |
|
268 | + return $pgt; |
|
269 | 269 | } |
270 | 270 | |
271 | - /** @} */ |
|
271 | + /** @} */ |
|
272 | 272 | |
273 | 273 | } |
274 | 274 |