@@ -18,24 +18,24 @@ discard block |
||
18 | 18 | private $_nonce_chars; |
19 | 19 | |
20 | 20 | /** |
21 | - * Constructor |
|
21 | + * Constructor |
|
22 | 22 | * |
23 | - * @access public |
|
23 | + * @access public |
|
24 | 24 | * @param api_key (String) The API Key (sometimes referred to as the consumer key) This value is usually supplied by the site you wish to use. |
25 | 25 | * @param shared_secret (String) The shared secret. This value is also usually provided by the site you wish to use. |
26 | - * @return OAuthSimple (Object) |
|
26 | + * @return OAuthSimple (Object) |
|
27 | 27 | */ |
28 | 28 | function __construct ($APIKey = "", $sharedSecret=""){ |
29 | 29 | |
30 | 30 | if (!empty($APIKey)) |
31 | - { |
|
32 | - $this->_secrets['consumer_key'] = $APIKey; |
|
33 | - } |
|
31 | + { |
|
32 | + $this->_secrets['consumer_key'] = $APIKey; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | if (!empty($sharedSecret)) |
36 | - { |
|
37 | - $this->_secrets['shared_secret'] = $sharedSecret; |
|
38 | - } |
|
36 | + { |
|
37 | + $this->_secrets['shared_secret'] = $sharedSecret; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | $this->_default_signature_method = "HMAC-SHA1"; |
41 | 41 | $this->_action = "GET"; |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | - * Reset the parameters and URL |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @return OAuthSimple (Object) |
|
52 | - */ |
|
48 | + * Reset the parameters and URL |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @return OAuthSimple (Object) |
|
52 | + */ |
|
53 | 53 | public function reset() { |
54 | 54 | $this->_parameters = Array(); |
55 | 55 | $this->path = NULL; |
@@ -59,87 +59,87 @@ discard block |
||
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | - * Set the parameters either from a hash or a string |
|
63 | - * |
|
64 | - * @access public |
|
65 | - * @param(string, object) List of parameters for the call, this can either be a URI string (e.g. "foo=bar&gorp=banana" or an object/hash) |
|
66 | - * @return OAuthSimple (Object) |
|
67 | - */ |
|
62 | + * Set the parameters either from a hash or a string |
|
63 | + * |
|
64 | + * @access public |
|
65 | + * @param(string, object) List of parameters for the call, this can either be a URI string (e.g. "foo=bar&gorp=banana" or an object/hash) |
|
66 | + * @return OAuthSimple (Object) |
|
67 | + */ |
|
68 | 68 | public function setParameters ($parameters=Array()) { |
69 | 69 | |
70 | 70 | if (is_string($parameters)) |
71 | - { |
|
72 | - $parameters = $this->_parseParameterString($parameters); |
|
73 | - } |
|
71 | + { |
|
72 | + $parameters = $this->_parseParameterString($parameters); |
|
73 | + } |
|
74 | 74 | if (empty($this->_parameters)) |
75 | - { |
|
76 | - $this->_parameters = $parameters; |
|
77 | - } |
|
75 | + { |
|
76 | + $this->_parameters = $parameters; |
|
77 | + } |
|
78 | 78 | else if (!empty($parameters)) |
79 | - { |
|
80 | - $this->_parameters = array_merge($this->_parameters,$parameters); |
|
81 | - } |
|
79 | + { |
|
80 | + $this->_parameters = array_merge($this->_parameters,$parameters); |
|
81 | + } |
|
82 | 82 | if (empty($this->_parameters['oauth_nonce'])) |
83 | - { |
|
84 | - $this->_getNonce(); |
|
85 | - } |
|
83 | + { |
|
84 | + $this->_getNonce(); |
|
85 | + } |
|
86 | 86 | if (empty($this->_parameters['oauth_timestamp'])) |
87 | - { |
|
88 | - $this->_getTimeStamp(); |
|
89 | - } |
|
87 | + { |
|
88 | + $this->_getTimeStamp(); |
|
89 | + } |
|
90 | 90 | if (empty($this->_parameters['oauth_consumer_key'])) |
91 | - { |
|
92 | - $this->_getApiKey(); |
|
93 | - } |
|
91 | + { |
|
92 | + $this->_getApiKey(); |
|
93 | + } |
|
94 | 94 | if (empty($this->_parameters['oauth_token'])) |
95 | - { |
|
96 | - $this->_getAccessToken(); |
|
97 | - } |
|
95 | + { |
|
96 | + $this->_getAccessToken(); |
|
97 | + } |
|
98 | 98 | if (empty($this->_parameters['oauth_signature_method'])) |
99 | - { |
|
99 | + { |
|
100 | 100 | $this->setSignatureMethod(); |
101 | - } |
|
101 | + } |
|
102 | 102 | if (empty($this->_parameters['oauth_version'])) |
103 | - { |
|
103 | + { |
|
104 | 104 | $this->_parameters['oauth_version']="1.0"; |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | return $this; |
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | - * Convenience method for setParameters |
|
112 | - * |
|
113 | - * @access public |
|
114 | - * @see setParameters |
|
115 | - */ |
|
111 | + * Convenience method for setParameters |
|
112 | + * |
|
113 | + * @access public |
|
114 | + * @see setParameters |
|
115 | + */ |
|
116 | 116 | public function setQueryString ($parameters) |
117 | 117 | { |
118 | 118 | return $this->setParameters($parameters); |
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
122 | - * Set the target URL (does not include the parameters) |
|
123 | - * |
|
122 | + * Set the target URL (does not include the parameters) |
|
123 | + * |
|
124 | 124 | * @param path (String) the fully qualified URI (excluding query arguments) (e.g "http://example.org/foo") |
125 | - * @return OAuthSimple (Object) |
|
125 | + * @return OAuthSimple (Object) |
|
126 | 126 | */ |
127 | 127 | public function setURL ($path) |
128 | - { |
|
128 | + { |
|
129 | 129 | if (empty($path)) |
130 | - { |
|
130 | + { |
|
131 | 131 | throw new OAuthSimpleException('No path specified for OAuthSimple.setURL'); |
132 | - } |
|
132 | + } |
|
133 | 133 | $this->_path=$path; |
134 | 134 | |
135 | 135 | return $this; |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Convenience method for setURL |
|
139 | + * Convenience method for setURL |
|
140 | 140 | * |
141 | 141 | * @param path (String) |
142 | - * @see setURL |
|
142 | + * @see setURL |
|
143 | 143 | */ |
144 | 144 | public function setPath ($path) |
145 | 145 | { |
@@ -147,39 +147,39 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
150 | - * Set the "action" for the url, (e.g. GET,POST, DELETE, etc.) |
|
150 | + * Set the "action" for the url, (e.g. GET,POST, DELETE, etc.) |
|
151 | 151 | * |
152 | 152 | * @param action (String) HTTP Action word. |
153 | - * @return OAuthSimple (Object) |
|
153 | + * @return OAuthSimple (Object) |
|
154 | 154 | */ |
155 | 155 | public function setAction ($action) |
156 | 156 | { |
157 | 157 | if (empty($action)) |
158 | - { |
|
159 | - $action = 'GET'; |
|
160 | - } |
|
158 | + { |
|
159 | + $action = 'GET'; |
|
160 | + } |
|
161 | 161 | $action = strtoupper($action); |
162 | 162 | if (preg_match('/[^A-Z]/',$action)) |
163 | - { |
|
163 | + { |
|
164 | 164 | throw new OAuthSimpleException('Invalid action specified for OAuthSimple.setAction'); |
165 | - } |
|
165 | + } |
|
166 | 166 | $this->_action = $action; |
167 | 167 | |
168 | 168 | return $this; |
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | - * Set the signatures (as well as validate the ones you have) |
|
172 | + * Set the signatures (as well as validate the ones you have) |
|
173 | 173 | * |
174 | 174 | * @param signatures (object) object/hash of the token/signature pairs {api_key:, shared_secret:, oauth_token: oauth_secret:} |
175 | - * @return OAuthSimple (Object) |
|
175 | + * @return OAuthSimple (Object) |
|
176 | 176 | */ |
177 | 177 | public function signatures ($signatures) |
178 | 178 | { |
179 | 179 | if (!empty($signatures) && !is_array($signatures)) |
180 | - { |
|
180 | + { |
|
181 | 181 | throw new OAuthSimpleException('Must pass dictionary array to OAuthSimple.signatures'); |
182 | - } |
|
182 | + } |
|
183 | 183 | if (!empty($signatures)) |
184 | 184 | { |
185 | 185 | if (empty($this->_secrets)) |
@@ -189,33 +189,33 @@ discard block |
||
189 | 189 | $this->_secrets=array_merge($this->_secrets,$signatures); |
190 | 190 | } |
191 | 191 | if (isset($this->_secrets['api_key'])) |
192 | - { |
|
192 | + { |
|
193 | 193 | $this->_secrets['consumer_key'] = $this->_secrets['api_key']; |
194 | - } |
|
194 | + } |
|
195 | 195 | if (isset($this->_secrets['access_token'])) |
196 | - { |
|
196 | + { |
|
197 | 197 | $this->_secrets['oauth_token'] = $this->_secrets['access_token']; |
198 | - } |
|
198 | + } |
|
199 | 199 | if (isset($this->_secrets['access_secret'])) |
200 | - { |
|
200 | + { |
|
201 | 201 | $this->_secrets['shared_secret'] = $this->_secrets['access_secret']; |
202 | 202 | } |
203 | 203 | if (isset($this->_secrets['oauth_token_secret'])) |
204 | - { |
|
204 | + { |
|
205 | 205 | $this->_secrets['oauth_secret'] = $this->_secrets['oauth_token_secret']; |
206 | - } |
|
206 | + } |
|
207 | 207 | if (empty($this->_secrets['consumer_key'])) |
208 | - { |
|
208 | + { |
|
209 | 209 | throw new OAuthSimpleException('Missing required consumer_key in OAuthSimple.signatures'); |
210 | 210 | } |
211 | 211 | if (empty($this->_secrets['shared_secret'])) |
212 | - { |
|
212 | + { |
|
213 | 213 | throw new OAuthSimpleException('Missing requires shared_secret in OAuthSimple.signatures'); |
214 | - } |
|
214 | + } |
|
215 | 215 | if (!empty($this->_secrets['oauth_token']) && empty($this->_secrets['oauth_secret'])) |
216 | - { |
|
216 | + { |
|
217 | 217 | throw new OAuthSimpleException('Missing oauth_secret for supplied oauth_token in OAuthSimple.signatures'); |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | 220 | return $this; |
221 | 221 | } |
@@ -226,30 +226,30 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
229 | - * Set the signature method (currently only Plaintext or SHA-MAC1) |
|
229 | + * Set the signature method (currently only Plaintext or SHA-MAC1) |
|
230 | 230 | * |
231 | 231 | * @param method (String) Method of signing the transaction (only PLAINTEXT and SHA-MAC1 allowed for now) |
232 | - * @return OAuthSimple (Object) |
|
233 | - */ |
|
232 | + * @return OAuthSimple (Object) |
|
233 | + */ |
|
234 | 234 | public function setSignatureMethod ($method="") |
235 | - { |
|
235 | + { |
|
236 | 236 | if (empty($method)) |
237 | - { |
|
237 | + { |
|
238 | 238 | $method = $this->_default_signature_method; |
239 | - } |
|
239 | + } |
|
240 | 240 | $method = strtoupper($method); |
241 | 241 | switch($method) |
242 | 242 | { |
243 | 243 | case 'PLAINTEXT': |
244 | 244 | case 'HMAC-SHA1': |
245 | 245 | $this->_parameters['oauth_signature_method']=$method; |
246 | - break; |
|
246 | + break; |
|
247 | 247 | default: |
248 | 248 | throw new OAuthSimpleException ("Unknown signing method $method specified for OAuthSimple.setSignatureMethod"); |
249 | - break; |
|
249 | + break; |
|
250 | 250 | } |
251 | 251 | |
252 | - return $this; |
|
252 | + return $this; |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** sign the request |
@@ -258,30 +258,30 @@ discard block |
||
258 | 258 | * other helper functions. |
259 | 259 | * |
260 | 260 | * @param args (Array) hash of arguments for the call {action, path, parameters (array), method, signatures (array)} all arguments are optional. |
261 | - * @return (Array) signed values |
|
261 | + * @return (Array) signed values |
|
262 | 262 | */ |
263 | 263 | public function sign($args=array()) |
264 | 264 | { |
265 | 265 | if (!empty($args['action'])) |
266 | - { |
|
266 | + { |
|
267 | 267 | $this->setAction($args['action']); |
268 | - } |
|
268 | + } |
|
269 | 269 | if (!empty($args['path'])) |
270 | - { |
|
270 | + { |
|
271 | 271 | $this->setPath($args['path']); |
272 | 272 | } |
273 | 273 | if (!empty($args['method'])) |
274 | - { |
|
274 | + { |
|
275 | 275 | $this->setSignatureMethod($args['method']); |
276 | - } |
|
276 | + } |
|
277 | 277 | if (!empty($args['signatures'])) |
278 | - { |
|
278 | + { |
|
279 | 279 | $this->signatures($args['signatures']); |
280 | - } |
|
280 | + } |
|
281 | 281 | if (empty($args['parameters'])) |
282 | - { |
|
282 | + { |
|
283 | 283 | $args['parameters']=array(); |
284 | - } |
|
284 | + } |
|
285 | 285 | $this->setParameters($args['parameters']); |
286 | 286 | $normParams = $this->_normalizedParameters(); |
287 | 287 | |
@@ -295,29 +295,29 @@ discard block |
||
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
298 | - * Return a formatted "header" string |
|
298 | + * Return a formatted "header" string |
|
299 | 299 | * |
300 | 300 | * NOTE: This doesn't set the "Authorization: " prefix, which is required. |
301 | 301 | * It's not set because various set header functions prefer different |
302 | 302 | * ways to do that. |
303 | 303 | * |
304 | 304 | * @param args (Array) |
305 | - * @return $result (String) |
|
306 | - */ |
|
305 | + * @return $result (String) |
|
306 | + */ |
|
307 | 307 | public function getHeaderString ($args=array()) |
308 | 308 | { |
309 | 309 | if (empty($this->_parameters['oauth_signature'])) |
310 | - { |
|
310 | + { |
|
311 | 311 | $this->sign($args); |
312 | - } |
|
312 | + } |
|
313 | 313 | $result = 'OAuth '; |
314 | 314 | |
315 | 315 | foreach ($this->_parameters as $pName => $pValue) |
316 | 316 | { |
317 | 317 | if (strpos($pName,'oauth_') !== 0) |
318 | - { |
|
318 | + { |
|
319 | 319 | continue; |
320 | - } |
|
320 | + } |
|
321 | 321 | if (is_array($pValue)) |
322 | 322 | { |
323 | 323 | foreach ($pValue as $val) |
@@ -342,19 +342,19 @@ discard block |
||
342 | 342 | { |
343 | 343 | list ($key,$token) = explode('=',$element); |
344 | 344 | if ($token) |
345 | - { |
|
345 | + { |
|
346 | 346 | $token = urldecode($token); |
347 | - } |
|
347 | + } |
|
348 | 348 | if (!empty($result[$key])) |
349 | 349 | { |
350 | 350 | if (!is_array($result[$key])) |
351 | - { |
|
351 | + { |
|
352 | 352 | $result[$key] = array($result[$key],$token); |
353 | - } |
|
353 | + } |
|
354 | 354 | else |
355 | - { |
|
355 | + { |
|
356 | 356 | array_push($result[$key],$token); |
357 | - } |
|
357 | + } |
|
358 | 358 | } |
359 | 359 | else |
360 | 360 | $result[$key]=$token; |
@@ -366,14 +366,14 @@ discard block |
||
366 | 366 | private static function _oauthEscape($string) |
367 | 367 | { |
368 | 368 | if ($string === 0) { return 0; } |
369 | - if ($string == '0') { return '0'; } |
|
369 | + if ($string == '0') { return '0'; } |
|
370 | 370 | if (strlen($string) == 0) { return ''; } |
371 | 371 | if (is_array($string)) { |
372 | 372 | throw new OAuthSimpleException('Array passed to _oauthEscape'); |
373 | - } |
|
373 | + } |
|
374 | 374 | $string = urlencode($string); |
375 | 375 | |
376 | - //FIX: urlencode of ~ and '+' |
|
376 | + //FIX: urlencode of ~ and '+' |
|
377 | 377 | $string = str_replace( |
378 | 378 | Array('%7E','+' ), // Replace these |
379 | 379 | Array('~', '%20'), // with these |
@@ -410,13 +410,13 @@ discard block |
||
410 | 410 | private function _getAccessToken() |
411 | 411 | { |
412 | 412 | if (!isset($this->_secrets['oauth_secret'])) |
413 | - { |
|
413 | + { |
|
414 | 414 | return ''; |
415 | - } |
|
415 | + } |
|
416 | 416 | if (!isset($this->_secrets['oauth_token'])) |
417 | - { |
|
417 | + { |
|
418 | 418 | throw new OAuthSimpleException('No access token (oauth_token) set for OAuthSimple.'); |
419 | - } |
|
419 | + } |
|
420 | 420 | $this->_parameters['oauth_token'] = $this->_secrets['oauth_token']; |
421 | 421 | |
422 | 422 | return $this->_parameters['oauth_token']; |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | |
430 | 430 | private function _normalizedParameters() |
431 | 431 | { |
432 | - $normalized_keys = array(); |
|
433 | - $return_array = array(); |
|
432 | + $normalized_keys = array(); |
|
433 | + $return_array = array(); |
|
434 | 434 | |
435 | 435 | foreach ( $this->_parameters as $paramName=>$paramValue) { |
436 | 436 | if (preg_match('/w+_secret/', $paramName) OR |
@@ -439,59 +439,59 @@ discard block |
||
439 | 439 | } |
440 | 440 | // Read parameters from a file. Hope you're practicing safe PHP. |
441 | 441 | //if (strpos($paramValue, '@') !== 0 && !file_exists(substr($paramValue, 1))) |
442 | - //{ |
|
443 | - if (is_array($paramValue)) |
|
444 | - { |
|
445 | - $normalized_keys[self::_oauthEscape($paramName)] = array(); |
|
446 | - foreach($paramValue as $item) |
|
447 | - { |
|
448 | - array_push($normalized_keys[self::_oauthEscape($paramName)], self::_oauthEscape($item)); |
|
449 | - } |
|
450 | - } |
|
451 | - else |
|
452 | - { |
|
453 | - $normalized_keys[self::_oauthEscape($paramName)] = self::_oauthEscape($paramValue); |
|
454 | - } |
|
455 | - //} |
|
456 | - } |
|
457 | - |
|
458 | - ksort($normalized_keys); |
|
459 | - |
|
460 | - foreach($normalized_keys as $key=>$val) |
|
461 | - { |
|
462 | - if (is_array($val)) |
|
463 | - { |
|
464 | - sort($val); |
|
465 | - foreach($val as $element) |
|
466 | - { |
|
467 | - array_push($return_array, $key . "=" . $element); |
|
468 | - } |
|
469 | - } |
|
470 | - else |
|
471 | - { |
|
472 | - array_push($return_array, $key .'='. $val); |
|
473 | - } |
|
442 | + //{ |
|
443 | + if (is_array($paramValue)) |
|
444 | + { |
|
445 | + $normalized_keys[self::_oauthEscape($paramName)] = array(); |
|
446 | + foreach($paramValue as $item) |
|
447 | + { |
|
448 | + array_push($normalized_keys[self::_oauthEscape($paramName)], self::_oauthEscape($item)); |
|
449 | + } |
|
450 | + } |
|
451 | + else |
|
452 | + { |
|
453 | + $normalized_keys[self::_oauthEscape($paramName)] = self::_oauthEscape($paramValue); |
|
454 | + } |
|
455 | + //} |
|
456 | + } |
|
457 | + |
|
458 | + ksort($normalized_keys); |
|
459 | + |
|
460 | + foreach($normalized_keys as $key=>$val) |
|
461 | + { |
|
462 | + if (is_array($val)) |
|
463 | + { |
|
464 | + sort($val); |
|
465 | + foreach($val as $element) |
|
466 | + { |
|
467 | + array_push($return_array, $key . "=" . $element); |
|
468 | + } |
|
469 | + } |
|
470 | + else |
|
471 | + { |
|
472 | + array_push($return_array, $key .'='. $val); |
|
473 | + } |
|
474 | 474 | |
475 | 475 | } |
476 | 476 | $presig = join("&", $return_array); |
477 | 477 | $sig = $this->_generateSignature($presig); |
478 | 478 | $this->_parameters['oauth_signature']=$sig; |
479 | 479 | array_push($return_array, "oauth_signature=$sig"); |
480 | - return join("&", $return_array); |
|
480 | + return join("&", $return_array); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | |
484 | 484 | private function _generateSignature ($parameters="") |
485 | 485 | { |
486 | 486 | $secretKey = ''; |
487 | - if(isset($this->_secrets['shared_secret'])) |
|
488 | - { |
|
489 | - $secretKey = self::_oauthEscape($this->_secrets['shared_secret']); |
|
490 | - } |
|
491 | - |
|
492 | - $secretKey .= '&'; |
|
493 | - if(isset($this->_secrets['oauth_secret'])) |
|
494 | - { |
|
487 | + if(isset($this->_secrets['shared_secret'])) |
|
488 | + { |
|
489 | + $secretKey = self::_oauthEscape($this->_secrets['shared_secret']); |
|
490 | + } |
|
491 | + |
|
492 | + $secretKey .= '&'; |
|
493 | + if(isset($this->_secrets['oauth_secret'])) |
|
494 | + { |
|
495 | 495 | $secretKey .= self::_oauthEscape($this->_secrets['oauth_secret']); |
496 | 496 | } |
497 | 497 | if(!empty($parameters)){ |
@@ -507,33 +507,33 @@ discard block |
||
507 | 507 | return base64_encode(hash_hmac('sha1',$this->sbs,$secretKey,TRUE)); |
508 | 508 | default: |
509 | 509 | throw new OAuthSimpleException('Unknown signature method for OAuthSimple'); |
510 | - break; |
|
510 | + break; |
|
511 | 511 | } |
512 | 512 | } |
513 | 513 | } |
514 | 514 | |
515 | 515 | class OAuthSimpleException extends Exception { |
516 | 516 | |
517 | - public function __construct($err, $isDebug = FALSE) |
|
518 | - { |
|
519 | - self::log_error($err); |
|
520 | - if ($isDebug) |
|
521 | - { |
|
522 | - self::display_error($err, TRUE); |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - public static function log_error($err) |
|
527 | - { |
|
528 | - error_log($err, 0); |
|
529 | - } |
|
530 | - |
|
531 | - public static function display_error($err, $kill = FALSE) |
|
532 | - { |
|
533 | - print_r($err); |
|
534 | - if ($kill === FALSE) |
|
535 | - { |
|
536 | - die(); |
|
537 | - } |
|
538 | - } |
|
517 | + public function __construct($err, $isDebug = FALSE) |
|
518 | + { |
|
519 | + self::log_error($err); |
|
520 | + if ($isDebug) |
|
521 | + { |
|
522 | + self::display_error($err, TRUE); |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + public static function log_error($err) |
|
527 | + { |
|
528 | + error_log($err, 0); |
|
529 | + } |
|
530 | + |
|
531 | + public static function display_error($err, $kill = FALSE) |
|
532 | + { |
|
533 | + print_r($err); |
|
534 | + if ($kill === FALSE) |
|
535 | + { |
|
536 | + die(); |
|
537 | + } |
|
538 | + } |
|
539 | 539 | } |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | $last_access = ''; |
8 | 8 | // get the last time the user accessed the tool |
9 | 9 | if (isset($_SESSION[$_course['id']]) && $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] == '') { |
10 | - $last_access = get_last_tool_access(TOOL_DROPBOX); |
|
11 | - $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] = $last_access; |
|
10 | + $last_access = get_last_tool_access(TOOL_DROPBOX); |
|
11 | + $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] = $last_access; |
|
12 | 12 | } else { |
13 | - if (isset($_SESSION[$_course['id']])) { |
|
14 | - $last_access = $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX]; |
|
15 | - } |
|
13 | + if (isset($_SESSION[$_course['id']])) { |
|
14 | + $last_access = $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX]; |
|
15 | + } |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | $postAction = isset($_POST['action']) ? $_POST['action'] : null; |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | |
51 | 51 | // Display the form for adding a new dropbox item. |
52 | 52 | if ($action == 'add') { |
53 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
54 | - api_not_allowed(); |
|
55 | - } |
|
53 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
54 | + api_not_allowed(); |
|
55 | + } |
|
56 | 56 | display_add_form( |
57 | 57 | $dropbox_unid, |
58 | 58 | $viewReceivedCategory, |
@@ -62,56 +62,56 @@ discard block |
||
62 | 62 | } |
63 | 63 | |
64 | 64 | if (isset($_POST['submitWork'])) { |
65 | - $check = Security::check_token(); |
|
66 | - if ($check) { |
|
65 | + $check = Security::check_token(); |
|
66 | + if ($check) { |
|
67 | 67 | store_add_dropbox(); |
68 | - } |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Display the form for adding a category |
72 | 72 | if ($action == 'addreceivedcategory' || $action == 'addsentcategory') { |
73 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
74 | - api_not_allowed(); |
|
75 | - } |
|
76 | - $categoryName = isset($_POST['category_name']) ? $_POST['category_name'] : ''; |
|
77 | - display_addcategory_form($categoryName, '', $_GET['action']); |
|
73 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
74 | + api_not_allowed(); |
|
75 | + } |
|
76 | + $categoryName = isset($_POST['category_name']) ? $_POST['category_name'] : ''; |
|
77 | + display_addcategory_form($categoryName, '', $_GET['action']); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | // Editing a category: displaying the form |
81 | 81 | if ($action == 'editcategory' && isset($_GET['id'])) { |
82 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
83 | - api_not_allowed(); |
|
84 | - } |
|
85 | - if (!$_POST) { |
|
86 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
87 | - api_not_allowed(); |
|
88 | - } |
|
89 | - display_addcategory_form('', $_GET['id'], 'editcategory'); |
|
90 | - } |
|
82 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
83 | + api_not_allowed(); |
|
84 | + } |
|
85 | + if (!$_POST) { |
|
86 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
87 | + api_not_allowed(); |
|
88 | + } |
|
89 | + display_addcategory_form('', $_GET['id'], 'editcategory'); |
|
90 | + } |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Storing a new or edited category |
94 | 94 | if (isset($_POST['StoreCategory'])) { |
95 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
96 | - api_not_allowed(); |
|
97 | - } |
|
98 | - $return_information = store_addcategory(); |
|
99 | - if ($return_information['type'] == 'confirmation') { |
|
100 | - Display :: display_confirmation_message($return_information['message']); |
|
101 | - } |
|
102 | - if ($return_information['type'] == 'error') { |
|
103 | - Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete').'<br />'.$return_information['message']); |
|
104 | - display_addcategory_form($_POST['category_name'], $_POST['edit_id'], $postAction); |
|
105 | - } |
|
95 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
96 | + api_not_allowed(); |
|
97 | + } |
|
98 | + $return_information = store_addcategory(); |
|
99 | + if ($return_information['type'] == 'confirmation') { |
|
100 | + Display :: display_confirmation_message($return_information['message']); |
|
101 | + } |
|
102 | + if ($return_information['type'] == 'error') { |
|
103 | + Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete').'<br />'.$return_information['message']); |
|
104 | + display_addcategory_form($_POST['category_name'], $_POST['edit_id'], $postAction); |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
109 | 109 | // Move a File |
110 | 110 | if (($action == 'movesent' || $action == 'movereceived') AND isset($_GET['move_id'])) { |
111 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
112 | - api_not_allowed(); |
|
113 | - } |
|
114 | - display_move_form( |
|
111 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
112 | + api_not_allowed(); |
|
113 | + } |
|
114 | + display_move_form( |
|
115 | 115 | str_replace('move', '', $action), |
116 | 116 | $_GET['move_id'], |
117 | 117 | get_dropbox_categories(str_replace('move', '', $action)), |
@@ -122,33 +122,33 @@ discard block |
||
122 | 122 | ); |
123 | 123 | } |
124 | 124 | if (isset($_POST['do_move'])) { |
125 | - Display :: display_confirmation_message(store_move($_POST['id'], $_POST['move_target'], $_POST['part'])); |
|
125 | + Display :: display_confirmation_message(store_move($_POST['id'], $_POST['move_target'], $_POST['part'])); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | // Delete a file |
129 | 129 | if (($action == 'deletereceivedfile' || $action == 'deletesentfile') AND isset($_GET['id']) AND is_numeric($_GET['id'])) { |
130 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
131 | - api_not_allowed(); |
|
132 | - } |
|
133 | - $dropboxfile = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
134 | - if ($action == 'deletereceivedfile') { |
|
135 | - $dropboxfile->deleteReceivedWork($_GET['id']); |
|
136 | - $message = get_lang('ReceivedFileDeleted'); |
|
137 | - } |
|
138 | - if ($action == 'deletesentfile') { |
|
139 | - $dropboxfile->deleteSentWork($_GET['id']); |
|
140 | - $message = get_lang('SentFileDeleted'); |
|
141 | - } |
|
142 | - Display :: display_confirmation_message($message); |
|
130 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
131 | + api_not_allowed(); |
|
132 | + } |
|
133 | + $dropboxfile = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
134 | + if ($action == 'deletereceivedfile') { |
|
135 | + $dropboxfile->deleteReceivedWork($_GET['id']); |
|
136 | + $message = get_lang('ReceivedFileDeleted'); |
|
137 | + } |
|
138 | + if ($action == 'deletesentfile') { |
|
139 | + $dropboxfile->deleteSentWork($_GET['id']); |
|
140 | + $message = get_lang('SentFileDeleted'); |
|
141 | + } |
|
142 | + Display :: display_confirmation_message($message); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | // Delete a category |
146 | 146 | if (($action == 'deletereceivedcategory' || $action == 'deletesentcategory') AND isset($_GET['id']) AND is_numeric($_GET['id'])) { |
147 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
148 | - api_not_allowed(); |
|
149 | - } |
|
150 | - $message = delete_category($action, $_GET['id']); |
|
151 | - Display :: display_confirmation_message($message); |
|
147 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
148 | + api_not_allowed(); |
|
149 | + } |
|
150 | + $message = delete_category($action, $_GET['id']); |
|
151 | + Display :: display_confirmation_message($message); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // Do an action on multiple files |
@@ -163,27 +163,27 @@ discard block |
||
163 | 163 | $postAction == 'delete_sent' || |
164 | 164 | $postAction == 'download_sent') |
165 | 165 | ) { |
166 | - $display_message = handle_multiple_actions(); |
|
167 | - Display :: display_normal_message($display_message); |
|
166 | + $display_message = handle_multiple_actions(); |
|
167 | + Display :: display_normal_message($display_message); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | // Store Feedback |
171 | 171 | |
172 | 172 | if (isset($_POST['feedback'])) { |
173 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
174 | - api_not_allowed(); |
|
175 | - } |
|
176 | - $check = Security::check_token(); |
|
177 | - if ($check) { |
|
178 | - $display_message = store_feedback(); |
|
179 | - Display :: display_normal_message($display_message); |
|
180 | - Security::check_token(); |
|
181 | - } |
|
173 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
174 | + api_not_allowed(); |
|
175 | + } |
|
176 | + $check = Security::check_token(); |
|
177 | + if ($check) { |
|
178 | + $display_message = store_feedback(); |
|
179 | + Display :: display_normal_message($display_message); |
|
180 | + Security::check_token(); |
|
181 | + } |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // Error Message |
185 | 185 | if (isset($_GET['error']) AND !empty($_GET['error'])) { |
186 | - Display :: display_normal_message(get_lang($_GET['error'])); |
|
186 | + Display :: display_normal_message(get_lang($_GET['error'])); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | $dropbox_data_sent = array(); |
@@ -191,96 +191,96 @@ discard block |
||
191 | 191 | $dropbox_data_recieved = array(); |
192 | 192 | |
193 | 193 | if ($action != 'add') { |
194 | - // Getting all the categories in the dropbox for the given user |
|
195 | - $dropbox_categories = get_dropbox_categories(); |
|
196 | - // Greating the arrays with the categories for the received files and for the sent files |
|
197 | - foreach ($dropbox_categories as $category) { |
|
198 | - if ($category['received'] == '1') { |
|
199 | - $dropbox_received_category[] = $category; |
|
200 | - } |
|
201 | - if ($category['sent'] == '1') { |
|
202 | - $dropbox_sent_category[] = $category; |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - // ACTIONS |
|
207 | - if ($view == 'received' || !$showSentReceivedTabs) { |
|
208 | - //echo '<h3>'.get_lang('ReceivedFiles').'</h3>'; |
|
209 | - |
|
210 | - // This is for the categories |
|
211 | - if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') { |
|
212 | - $view_dropbox_category_received = $viewReceivedCategory; |
|
213 | - } else { |
|
214 | - $view_dropbox_category_received = 0; |
|
215 | - } |
|
216 | - |
|
217 | - /* Menu Received */ |
|
218 | - |
|
219 | - if (api_get_session_id() == 0) { |
|
220 | - echo '<div class="actions">'; |
|
221 | - if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { |
|
222 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
223 | - echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> '; |
|
224 | - $movelist[0] = 'Root'; // move_received selectbox content |
|
225 | - } else { |
|
226 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
227 | - } |
|
228 | - echo '</div>'; |
|
229 | - } else { |
|
230 | - if (api_is_allowed_to_session_edit(false, true)) { |
|
231 | - echo '<div class="actions">'; |
|
232 | - if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { |
|
233 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
234 | - echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> '; |
|
235 | - $movelist[0] = 'Root'; // move_received selectbox content |
|
236 | - } else { |
|
237 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
238 | - } |
|
239 | - echo '</div>'; |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - if (!$view || $view == 'sent' || !$showSentReceivedTabs) { |
|
245 | - // This is for the categories |
|
246 | - if (isset($viewSentCategory) AND $viewSentCategory != '') { |
|
247 | - $view_dropbox_category_sent = $viewSentCategory; |
|
248 | - } else { |
|
249 | - $view_dropbox_category_sent = 0; |
|
250 | - } |
|
251 | - |
|
252 | - /* Menu Sent */ |
|
253 | - |
|
254 | - if (api_get_session_id() == 0) { |
|
255 | - echo '<div class="actions">'; |
|
256 | - if ($view_dropbox_category_sent != 0) { |
|
257 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
258 | - echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> '; |
|
259 | - } else { |
|
260 | - echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n"; |
|
261 | - } |
|
262 | - if (empty($viewSentCategory)) { |
|
263 | - echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
264 | - } |
|
265 | - echo '</div>'; |
|
266 | - } else { |
|
267 | - if (api_is_allowed_to_session_edit(false, true)) { |
|
268 | - echo '<div class="actions">'; |
|
269 | - if ($view_dropbox_category_sent != 0) { |
|
270 | - echo get_lang('CurrentlySeeing').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> '; |
|
271 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
272 | - } else { |
|
273 | - echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n"; |
|
274 | - } |
|
275 | - if (empty($viewSentCategory)) { |
|
276 | - echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
277 | - } |
|
278 | - echo '</div>'; |
|
279 | - } |
|
280 | - } |
|
281 | - } |
|
282 | - /* THE MENU TABS */ |
|
283 | - if ($showSentReceivedTabs) { |
|
194 | + // Getting all the categories in the dropbox for the given user |
|
195 | + $dropbox_categories = get_dropbox_categories(); |
|
196 | + // Greating the arrays with the categories for the received files and for the sent files |
|
197 | + foreach ($dropbox_categories as $category) { |
|
198 | + if ($category['received'] == '1') { |
|
199 | + $dropbox_received_category[] = $category; |
|
200 | + } |
|
201 | + if ($category['sent'] == '1') { |
|
202 | + $dropbox_sent_category[] = $category; |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + // ACTIONS |
|
207 | + if ($view == 'received' || !$showSentReceivedTabs) { |
|
208 | + //echo '<h3>'.get_lang('ReceivedFiles').'</h3>'; |
|
209 | + |
|
210 | + // This is for the categories |
|
211 | + if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') { |
|
212 | + $view_dropbox_category_received = $viewReceivedCategory; |
|
213 | + } else { |
|
214 | + $view_dropbox_category_received = 0; |
|
215 | + } |
|
216 | + |
|
217 | + /* Menu Received */ |
|
218 | + |
|
219 | + if (api_get_session_id() == 0) { |
|
220 | + echo '<div class="actions">'; |
|
221 | + if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { |
|
222 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
223 | + echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> '; |
|
224 | + $movelist[0] = 'Root'; // move_received selectbox content |
|
225 | + } else { |
|
226 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
227 | + } |
|
228 | + echo '</div>'; |
|
229 | + } else { |
|
230 | + if (api_is_allowed_to_session_edit(false, true)) { |
|
231 | + echo '<div class="actions">'; |
|
232 | + if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { |
|
233 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
234 | + echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> '; |
|
235 | + $movelist[0] = 'Root'; // move_received selectbox content |
|
236 | + } else { |
|
237 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
238 | + } |
|
239 | + echo '</div>'; |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + if (!$view || $view == 'sent' || !$showSentReceivedTabs) { |
|
245 | + // This is for the categories |
|
246 | + if (isset($viewSentCategory) AND $viewSentCategory != '') { |
|
247 | + $view_dropbox_category_sent = $viewSentCategory; |
|
248 | + } else { |
|
249 | + $view_dropbox_category_sent = 0; |
|
250 | + } |
|
251 | + |
|
252 | + /* Menu Sent */ |
|
253 | + |
|
254 | + if (api_get_session_id() == 0) { |
|
255 | + echo '<div class="actions">'; |
|
256 | + if ($view_dropbox_category_sent != 0) { |
|
257 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
258 | + echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> '; |
|
259 | + } else { |
|
260 | + echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n"; |
|
261 | + } |
|
262 | + if (empty($viewSentCategory)) { |
|
263 | + echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
264 | + } |
|
265 | + echo '</div>'; |
|
266 | + } else { |
|
267 | + if (api_is_allowed_to_session_edit(false, true)) { |
|
268 | + echo '<div class="actions">'; |
|
269 | + if ($view_dropbox_category_sent != 0) { |
|
270 | + echo get_lang('CurrentlySeeing').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> '; |
|
271 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
272 | + } else { |
|
273 | + echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n"; |
|
274 | + } |
|
275 | + if (empty($viewSentCategory)) { |
|
276 | + echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
277 | + } |
|
278 | + echo '</div>'; |
|
279 | + } |
|
280 | + } |
|
281 | + } |
|
282 | + /* THE MENU TABS */ |
|
283 | + if ($showSentReceivedTabs) { |
|
284 | 284 | ?> |
285 | 285 | <ul class="nav nav-tabs"> |
286 | 286 | <li <?php if (!$view || $view == 'sent') { echo 'class="active"'; } ?> > |
@@ -294,80 +294,80 @@ discard block |
||
294 | 294 | </li> |
295 | 295 | </ul> |
296 | 296 | <?php |
297 | - } |
|
297 | + } |
|
298 | 298 | /* RECEIVED FILES */ |
299 | - if ($view == 'received' || !$showSentReceivedTabs) { |
|
300 | - // This is for the categories |
|
301 | - if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') { |
|
302 | - $view_dropbox_category_received = $viewReceivedCategory; |
|
303 | - } else { |
|
304 | - $view_dropbox_category_received = 0; |
|
305 | - } |
|
306 | - |
|
307 | - // Object initialisation |
|
308 | - $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
309 | - // note: are the $is_courseAdmin and $is_courseTutor parameters needed???? |
|
310 | - |
|
311 | - // Constructing the array that contains the total number of feedback messages per document. |
|
312 | - $number_feedback = get_total_number_feedback(); |
|
313 | - |
|
314 | - // Sorting and paging options |
|
315 | - $sorting_options = array(); |
|
316 | - $paging_options = array(); |
|
317 | - |
|
318 | - // The headers of the sortable tables |
|
319 | - $column_header = array(); |
|
320 | - $column_header[] = array('', false, ''); |
|
321 | - $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'); |
|
322 | - $column_header[] = array(get_lang('ReceivedTitle'), true, ''); |
|
323 | - $column_header[] = array(get_lang('Size'), true, ''); |
|
324 | - $column_header[] = array(get_lang('Authors'), true, ''); |
|
325 | - $column_header[] = array(get_lang('LastResent'), true); |
|
326 | - |
|
327 | - if (api_get_session_id() == 0) { |
|
328 | - $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
329 | - } elseif (api_is_allowed_to_session_edit(false,true)) { |
|
330 | - $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
331 | - } |
|
332 | - |
|
333 | - $column_header[] = array('RealDate', true); |
|
334 | - $column_header[] = array('RealSize', true); |
|
335 | - |
|
336 | - // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide |
|
337 | - $column_show[] = 1; |
|
338 | - $column_show[] = 1; |
|
339 | - $column_show[] = 1; |
|
340 | - $column_show[] = 1; |
|
341 | - $column_show[] = 1; |
|
342 | - $column_show[] = 1; |
|
343 | - |
|
344 | - if (api_get_session_id() == 0) { |
|
345 | - $column_show[] = 1; |
|
346 | - } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
347 | - $column_show[] = 1; |
|
348 | - } |
|
349 | - $column_show[] = 0; |
|
350 | - |
|
351 | - // Here we change the way how the columns are going to be sort |
|
352 | - // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate |
|
353 | - // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" |
|
354 | - |
|
355 | - $column_order[3] = 8; |
|
356 | - $column_order[5] = 7; |
|
357 | - |
|
358 | - // The content of the sortable table = the received files |
|
359 | - foreach ($dropbox_person -> receivedWork as $dropbox_file) { |
|
360 | - $dropbox_file_data = array(); |
|
361 | - if ($view_dropbox_category_received == $dropbox_file->category) { |
|
299 | + if ($view == 'received' || !$showSentReceivedTabs) { |
|
300 | + // This is for the categories |
|
301 | + if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') { |
|
302 | + $view_dropbox_category_received = $viewReceivedCategory; |
|
303 | + } else { |
|
304 | + $view_dropbox_category_received = 0; |
|
305 | + } |
|
306 | + |
|
307 | + // Object initialisation |
|
308 | + $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
309 | + // note: are the $is_courseAdmin and $is_courseTutor parameters needed???? |
|
310 | + |
|
311 | + // Constructing the array that contains the total number of feedback messages per document. |
|
312 | + $number_feedback = get_total_number_feedback(); |
|
313 | + |
|
314 | + // Sorting and paging options |
|
315 | + $sorting_options = array(); |
|
316 | + $paging_options = array(); |
|
317 | + |
|
318 | + // The headers of the sortable tables |
|
319 | + $column_header = array(); |
|
320 | + $column_header[] = array('', false, ''); |
|
321 | + $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'); |
|
322 | + $column_header[] = array(get_lang('ReceivedTitle'), true, ''); |
|
323 | + $column_header[] = array(get_lang('Size'), true, ''); |
|
324 | + $column_header[] = array(get_lang('Authors'), true, ''); |
|
325 | + $column_header[] = array(get_lang('LastResent'), true); |
|
326 | + |
|
327 | + if (api_get_session_id() == 0) { |
|
328 | + $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
329 | + } elseif (api_is_allowed_to_session_edit(false,true)) { |
|
330 | + $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
331 | + } |
|
332 | + |
|
333 | + $column_header[] = array('RealDate', true); |
|
334 | + $column_header[] = array('RealSize', true); |
|
335 | + |
|
336 | + // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide |
|
337 | + $column_show[] = 1; |
|
338 | + $column_show[] = 1; |
|
339 | + $column_show[] = 1; |
|
340 | + $column_show[] = 1; |
|
341 | + $column_show[] = 1; |
|
342 | + $column_show[] = 1; |
|
343 | + |
|
344 | + if (api_get_session_id() == 0) { |
|
345 | + $column_show[] = 1; |
|
346 | + } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
347 | + $column_show[] = 1; |
|
348 | + } |
|
349 | + $column_show[] = 0; |
|
350 | + |
|
351 | + // Here we change the way how the columns are going to be sort |
|
352 | + // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate |
|
353 | + // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" |
|
354 | + |
|
355 | + $column_order[3] = 8; |
|
356 | + $column_order[5] = 7; |
|
357 | + |
|
358 | + // The content of the sortable table = the received files |
|
359 | + foreach ($dropbox_person -> receivedWork as $dropbox_file) { |
|
360 | + $dropbox_file_data = array(); |
|
361 | + if ($view_dropbox_category_received == $dropbox_file->category) { |
|
362 | 362 | // we only display the files that are in the category that we are in. |
363 | - $dropbox_file_data[] = $dropbox_file->id; |
|
363 | + $dropbox_file_data[] = $dropbox_file->id; |
|
364 | 364 | |
365 | - if (isset($_SESSION['_seen']) && !is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) { |
|
366 | - $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = array(); |
|
367 | - } |
|
365 | + if (isset($_SESSION['_seen']) && !is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) { |
|
366 | + $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = array(); |
|
367 | + } |
|
368 | 368 | |
369 | - // New icon |
|
370 | - $new_icon = ''; |
|
369 | + // New icon |
|
370 | + $new_icon = ''; |
|
371 | 371 | if (isset($_SESSION['_seen'])) { |
372 | 372 | if ($dropbox_file->last_upload_date > $last_access && |
373 | 373 | !in_array( |
@@ -384,12 +384,12 @@ discard block |
||
384 | 384 | } |
385 | 385 | } |
386 | 386 | |
387 | - $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">'; |
|
388 | - $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>'; |
|
389 | - $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'. |
|
387 | + $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">'; |
|
388 | + $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>'; |
|
389 | + $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'. |
|
390 | 390 | Display::return_icon('save.png', get_lang('Download'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$dropbox_file->title.'</a>'.$new_icon.'<br />'.$dropbox_file->description; |
391 | - $file_size = $dropbox_file->filesize; |
|
392 | - $dropbox_file_data[] = format_file_size($file_size); |
|
391 | + $file_size = $dropbox_file->filesize; |
|
392 | + $dropbox_file_data[] = format_file_size($file_size); |
|
393 | 393 | |
394 | 394 | $authorInfo = api_get_user_info($dropbox_file->uploader_id); |
395 | 395 | if ($authorInfo) { |
@@ -398,62 +398,62 @@ discard block |
||
398 | 398 | $dropbox_file_data[] = ''; |
399 | 399 | } |
400 | 400 | |
401 | - $last_upload_date = api_get_local_time($dropbox_file->last_upload_date); |
|
402 | - $dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'. |
|
401 | + $last_upload_date = api_get_local_time($dropbox_file->last_upload_date); |
|
402 | + $dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'. |
|
403 | 403 | api_format_date($last_upload_date).'</span>'; |
404 | 404 | |
405 | - $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').' |
|
405 | + $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').' |
|
406 | 406 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=viewfeedback&id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',ICON_SIZE_SMALL).'</a> |
407 | 407 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movereceived&move_id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('move.png', get_lang('Move'),'',ICON_SIZE_SMALL).'</a> |
408 | 408 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletereceivedfile&id='.$dropbox_file->id.'&'.$sort_params.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'. |
409 | 409 | Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'; |
410 | 410 | |
411 | - // This is a hack to have an additional row in a sortable table |
|
412 | - |
|
413 | - if ($action == 'viewfeedback' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id == $_GET['id']) { |
|
414 | - $action_icons .= "</td></tr>"; // Ending the normal row of the sortable table |
|
415 | - $action_icons .= '<tr><td colspan="2"><a href="'.api_get_path(WEB_CODE_PATH).'dropbox/index.php?"'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a></td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>"; |
|
416 | - } |
|
417 | - if (api_get_session_id() == 0) { |
|
418 | - $dropbox_file_data[] = $action_icons; |
|
419 | - } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
420 | - $dropbox_file_data[] = $action_icons; |
|
421 | - } |
|
422 | - $action_icons = ''; |
|
423 | - $dropbox_file_data[] = $last_upload_date; |
|
424 | - $dropbox_file_data[] = $file_size; |
|
425 | - $dropbox_data_recieved[] = $dropbox_file_data; |
|
426 | - } |
|
427 | - } |
|
428 | - |
|
429 | - // The content of the sortable table = the categories (if we are not in the root) |
|
430 | - if ($view_dropbox_category_received == 0) { |
|
431 | - foreach ($dropbox_categories as $category) { |
|
432 | - /* Note: This can probably be shortened since the categories |
|
411 | + // This is a hack to have an additional row in a sortable table |
|
412 | + |
|
413 | + if ($action == 'viewfeedback' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id == $_GET['id']) { |
|
414 | + $action_icons .= "</td></tr>"; // Ending the normal row of the sortable table |
|
415 | + $action_icons .= '<tr><td colspan="2"><a href="'.api_get_path(WEB_CODE_PATH).'dropbox/index.php?"'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a></td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>"; |
|
416 | + } |
|
417 | + if (api_get_session_id() == 0) { |
|
418 | + $dropbox_file_data[] = $action_icons; |
|
419 | + } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
420 | + $dropbox_file_data[] = $action_icons; |
|
421 | + } |
|
422 | + $action_icons = ''; |
|
423 | + $dropbox_file_data[] = $last_upload_date; |
|
424 | + $dropbox_file_data[] = $file_size; |
|
425 | + $dropbox_data_recieved[] = $dropbox_file_data; |
|
426 | + } |
|
427 | + } |
|
428 | + |
|
429 | + // The content of the sortable table = the categories (if we are not in the root) |
|
430 | + if ($view_dropbox_category_received == 0) { |
|
431 | + foreach ($dropbox_categories as $category) { |
|
432 | + /* Note: This can probably be shortened since the categories |
|
433 | 433 | for the received files are already in the |
434 | 434 | $dropbox_received_category array;*/ |
435 | - $dropbox_category_data = array(); |
|
436 | - if ($category['received'] == '1') { |
|
437 | - $movelist[$category['cat_id']] = $category['cat_name']; |
|
435 | + $dropbox_category_data = array(); |
|
436 | + if ($category['received'] == '1') { |
|
437 | + $movelist[$category['cat_id']] = $category['cat_name']; |
|
438 | 438 | // This is where the checkbox icon for the files appear |
439 | - $dropbox_category_data[] = $category['cat_id']; |
|
440 | - // The icon of the category |
|
441 | - $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$category['cat_id'].'&view_sent_category='.$viewSentCategory.'&view='.$view.'">'; |
|
442 | - $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', $category['cat_name']).'</a>'; |
|
443 | - $dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=received">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$category['cat_name'].'</a>'; |
|
444 | - $dropbox_category_data[] = ''; |
|
445 | - $dropbox_category_data[] = ''; |
|
446 | - $dropbox_category_data[] = ''; |
|
447 | - $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a> |
|
439 | + $dropbox_category_data[] = $category['cat_id']; |
|
440 | + // The icon of the category |
|
441 | + $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$category['cat_id'].'&view_sent_category='.$viewSentCategory.'&view='.$view.'">'; |
|
442 | + $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', $category['cat_name']).'</a>'; |
|
443 | + $dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=received">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$category['cat_name'].'</a>'; |
|
444 | + $dropbox_category_data[] = ''; |
|
445 | + $dropbox_category_data[] = ''; |
|
446 | + $dropbox_category_data[] = ''; |
|
447 | + $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a> |
|
448 | 448 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletereceivedcategory&id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.Security::remove_XSS($category['cat_name']).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'; |
449 | - } |
|
450 | - if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) { |
|
451 | - $dropbox_data_recieved[] = $dropbox_category_data; |
|
452 | - } |
|
453 | - } |
|
454 | - } |
|
455 | - |
|
456 | - // Displaying the table |
|
449 | + } |
|
450 | + if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) { |
|
451 | + $dropbox_data_recieved[] = $dropbox_category_data; |
|
452 | + } |
|
453 | + } |
|
454 | + } |
|
455 | + |
|
456 | + // Displaying the table |
|
457 | 457 | $additional_get_parameters = array( |
458 | 458 | 'view' => $view, |
459 | 459 | 'view_received_category' => $viewReceivedCategory, |
@@ -464,15 +464,15 @@ discard block |
||
464 | 464 | 'download_received' => get_lang('Download') |
465 | 465 | ); |
466 | 466 | |
467 | - if (is_array($movelist)) { |
|
468 | - foreach ($movelist as $catid => $catname){ |
|
469 | - $selectlist['move_received_'.$catid] = get_lang('Move') . '->'. Security::remove_XSS($catname); |
|
470 | - } |
|
471 | - } |
|
467 | + if (is_array($movelist)) { |
|
468 | + foreach ($movelist as $catid => $catname){ |
|
469 | + $selectlist['move_received_'.$catid] = get_lang('Move') . '->'. Security::remove_XSS($catname); |
|
470 | + } |
|
471 | + } |
|
472 | 472 | |
473 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
474 | - $selectlist = array(); |
|
475 | - } |
|
473 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
474 | + $selectlist = array(); |
|
475 | + } |
|
476 | 476 | echo '<div class="files-table">'; |
477 | 477 | Display::display_sortable_config_table( |
478 | 478 | 'dropbox', |
@@ -486,154 +486,154 @@ discard block |
||
486 | 486 | $selectlist |
487 | 487 | ); |
488 | 488 | echo '</div>'; |
489 | - } |
|
490 | - |
|
491 | - /* SENT FILES */ |
|
492 | - |
|
493 | - if (!$view || $view == 'sent' || !$showSentReceivedTabs) { |
|
494 | - // This is for the categories |
|
495 | - if (isset($viewSentCategory) AND $viewSentCategory != '') { |
|
496 | - $view_dropbox_category_sent = $viewSentCategory; |
|
497 | - } else { |
|
498 | - $view_dropbox_category_sent = 0; |
|
499 | - } |
|
500 | - |
|
501 | - // Object initialisation |
|
502 | - $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
503 | - |
|
504 | - // Constructing the array that contains the total number of feedback messages per document. |
|
505 | - $number_feedback = get_total_number_feedback(); |
|
506 | - |
|
507 | - // Sorting and paging options |
|
508 | - $sorting_options = array(); |
|
509 | - $paging_options = array(); |
|
510 | - |
|
511 | - // The headers of the sortable tables |
|
512 | - $column_header = array(); |
|
513 | - |
|
514 | - $column_header[] = array('', false, ''); |
|
515 | - $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'); |
|
516 | - $column_header[] = array(get_lang('SentTitle'), true, ''); |
|
517 | - $column_header[] = array(get_lang('Size'), true, ''); |
|
518 | - $column_header[] = array(get_lang('SentTo'), true, ''); |
|
519 | - $column_header[] = array(get_lang('LastResent'), true, ''); |
|
520 | - |
|
521 | - if (api_get_session_id() == 0) { |
|
522 | - $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
523 | - } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
524 | - $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
525 | - } |
|
526 | - |
|
527 | - $column_header[] = array('RealDate', true); |
|
528 | - $column_header[] = array('RealSize', true); |
|
529 | - |
|
530 | - $column_show = array(); |
|
531 | - $column_order = array(); |
|
532 | - |
|
533 | - // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide |
|
534 | - $column_show[] = 1; |
|
535 | - $column_show[] = 1; |
|
536 | - $column_show[] = 1; |
|
537 | - $column_show[] = 1; |
|
538 | - $column_show[] = 1; |
|
539 | - $column_show[] = 1; |
|
540 | - if (api_get_session_id() == 0) { |
|
541 | - $column_show[] = 1; |
|
542 | - } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
543 | - $column_show[] = 1; |
|
544 | - } |
|
545 | - $column_show[] = 0; |
|
546 | - |
|
547 | - // Here we change the way how the colums are going to be sort |
|
548 | - // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate |
|
549 | - // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" |
|
550 | - |
|
551 | - $column_order[3] = 8; |
|
552 | - $column_order[5] = 7; |
|
553 | - |
|
554 | - // The content of the sortable table = the received files |
|
555 | - foreach ($dropbox_person->sentWork as $dropbox_file) { |
|
556 | - $dropbox_file_data = array(); |
|
557 | - |
|
558 | - if ($view_dropbox_category_sent == $dropbox_file->category) { |
|
559 | - $dropbox_file_data[] = $dropbox_file->id; |
|
560 | - $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">'; |
|
561 | - $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>'; |
|
562 | - $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'. |
|
489 | + } |
|
490 | + |
|
491 | + /* SENT FILES */ |
|
492 | + |
|
493 | + if (!$view || $view == 'sent' || !$showSentReceivedTabs) { |
|
494 | + // This is for the categories |
|
495 | + if (isset($viewSentCategory) AND $viewSentCategory != '') { |
|
496 | + $view_dropbox_category_sent = $viewSentCategory; |
|
497 | + } else { |
|
498 | + $view_dropbox_category_sent = 0; |
|
499 | + } |
|
500 | + |
|
501 | + // Object initialisation |
|
502 | + $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
503 | + |
|
504 | + // Constructing the array that contains the total number of feedback messages per document. |
|
505 | + $number_feedback = get_total_number_feedback(); |
|
506 | + |
|
507 | + // Sorting and paging options |
|
508 | + $sorting_options = array(); |
|
509 | + $paging_options = array(); |
|
510 | + |
|
511 | + // The headers of the sortable tables |
|
512 | + $column_header = array(); |
|
513 | + |
|
514 | + $column_header[] = array('', false, ''); |
|
515 | + $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'); |
|
516 | + $column_header[] = array(get_lang('SentTitle'), true, ''); |
|
517 | + $column_header[] = array(get_lang('Size'), true, ''); |
|
518 | + $column_header[] = array(get_lang('SentTo'), true, ''); |
|
519 | + $column_header[] = array(get_lang('LastResent'), true, ''); |
|
520 | + |
|
521 | + if (api_get_session_id() == 0) { |
|
522 | + $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
523 | + } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
524 | + $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
525 | + } |
|
526 | + |
|
527 | + $column_header[] = array('RealDate', true); |
|
528 | + $column_header[] = array('RealSize', true); |
|
529 | + |
|
530 | + $column_show = array(); |
|
531 | + $column_order = array(); |
|
532 | + |
|
533 | + // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide |
|
534 | + $column_show[] = 1; |
|
535 | + $column_show[] = 1; |
|
536 | + $column_show[] = 1; |
|
537 | + $column_show[] = 1; |
|
538 | + $column_show[] = 1; |
|
539 | + $column_show[] = 1; |
|
540 | + if (api_get_session_id() == 0) { |
|
541 | + $column_show[] = 1; |
|
542 | + } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
543 | + $column_show[] = 1; |
|
544 | + } |
|
545 | + $column_show[] = 0; |
|
546 | + |
|
547 | + // Here we change the way how the colums are going to be sort |
|
548 | + // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate |
|
549 | + // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" |
|
550 | + |
|
551 | + $column_order[3] = 8; |
|
552 | + $column_order[5] = 7; |
|
553 | + |
|
554 | + // The content of the sortable table = the received files |
|
555 | + foreach ($dropbox_person->sentWork as $dropbox_file) { |
|
556 | + $dropbox_file_data = array(); |
|
557 | + |
|
558 | + if ($view_dropbox_category_sent == $dropbox_file->category) { |
|
559 | + $dropbox_file_data[] = $dropbox_file->id; |
|
560 | + $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">'; |
|
561 | + $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>'; |
|
562 | + $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'. |
|
563 | 563 | Display::return_icon('save.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$dropbox_file->title.'</a><br />'.$dropbox_file->description; |
564 | - $file_size = $dropbox_file->filesize; |
|
565 | - $dropbox_file_data[] = format_file_size($file_size); |
|
564 | + $file_size = $dropbox_file->filesize; |
|
565 | + $dropbox_file_data[] = format_file_size($file_size); |
|
566 | 566 | $receivers_celldata = null; |
567 | - foreach ($dropbox_file->recipients as $recipient) { |
|
568 | - $userInfo = api_get_user_info($recipient['user_id']); |
|
569 | - $receivers_celldata = UserManager::getUserProfileLink($userInfo).', '.$receivers_celldata; |
|
570 | - } |
|
571 | - $receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma. |
|
572 | - $dropbox_file_data[] = $receivers_celldata; |
|
573 | - $last_upload_date = api_get_local_time($dropbox_file->last_upload_date); |
|
574 | - $dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'. |
|
575 | - api_format_date($last_upload_date).'</span>'; |
|
576 | - |
|
577 | - //$dropbox_file_data[] = $dropbox_file->author; |
|
578 | - $receivers_celldata = ''; |
|
579 | - |
|
580 | - $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').' |
|
567 | + foreach ($dropbox_file->recipients as $recipient) { |
|
568 | + $userInfo = api_get_user_info($recipient['user_id']); |
|
569 | + $receivers_celldata = UserManager::getUserProfileLink($userInfo).', '.$receivers_celldata; |
|
570 | + } |
|
571 | + $receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma. |
|
572 | + $dropbox_file_data[] = $receivers_celldata; |
|
573 | + $last_upload_date = api_get_local_time($dropbox_file->last_upload_date); |
|
574 | + $dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'. |
|
575 | + api_format_date($last_upload_date).'</span>'; |
|
576 | + |
|
577 | + //$dropbox_file_data[] = $dropbox_file->author; |
|
578 | + $receivers_celldata = ''; |
|
579 | + |
|
580 | + $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').' |
|
581 | 581 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=viewfeedback&id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',ICON_SIZE_SMALL).'</a> |
582 | 582 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movesent&move_id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('move.png', get_lang('Move'),'',ICON_SIZE_SMALL).'</a> |
583 | 583 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletesentfile&id='.$dropbox_file->id.'&'.$sort_params.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'; |
584 | - // This is a hack to have an additional row in a sortable table |
|
585 | - if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) { |
|
586 | - $action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table |
|
587 | - $action_icons .= "<tr><td colspan=\"2\">"; |
|
588 | - $action_icons .= "<a href=\"".api_get_path(WEB_CODE_PATH)."dropbox/index.php?".api_get_cidreq()."&view_received_category=".$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a>"; |
|
589 | - $action_icons .= "</td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>"; |
|
590 | - } |
|
591 | - $dropbox_file_data[] = $action_icons; |
|
592 | - $dropbox_file_data[] = $last_upload_date; |
|
593 | - $dropbox_file_data[] = $file_size; |
|
594 | - $action_icons = ''; |
|
595 | - $dropbox_data_sent[] = $dropbox_file_data; |
|
596 | - } |
|
597 | - } |
|
584 | + // This is a hack to have an additional row in a sortable table |
|
585 | + if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) { |
|
586 | + $action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table |
|
587 | + $action_icons .= "<tr><td colspan=\"2\">"; |
|
588 | + $action_icons .= "<a href=\"".api_get_path(WEB_CODE_PATH)."dropbox/index.php?".api_get_cidreq()."&view_received_category=".$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a>"; |
|
589 | + $action_icons .= "</td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>"; |
|
590 | + } |
|
591 | + $dropbox_file_data[] = $action_icons; |
|
592 | + $dropbox_file_data[] = $last_upload_date; |
|
593 | + $dropbox_file_data[] = $file_size; |
|
594 | + $action_icons = ''; |
|
595 | + $dropbox_data_sent[] = $dropbox_file_data; |
|
596 | + } |
|
597 | + } |
|
598 | 598 | |
599 | 599 | $moveList = array(); |
600 | - // The content of the sortable table = the categories (if we are not in the root) |
|
601 | - if ($view_dropbox_category_sent == 0) { |
|
602 | - foreach ($dropbox_categories as $category) { |
|
603 | - $dropbox_category_data = array(); |
|
600 | + // The content of the sortable table = the categories (if we are not in the root) |
|
601 | + if ($view_dropbox_category_sent == 0) { |
|
602 | + foreach ($dropbox_categories as $category) { |
|
603 | + $dropbox_category_data = array(); |
|
604 | 604 | |
605 | - if ($category['sent'] == '1') { |
|
605 | + if ($category['sent'] == '1') { |
|
606 | 606 | |
607 | 607 | $moveList[$category['cat_id']] = $category['cat_name']; |
608 | - $dropbox_category_data[] = $category['cat_id']; |
|
609 | - // This is where the checkbox icon for the files appear. |
|
610 | - $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$category['cat_id'].'&view='.$view.'">'; |
|
611 | - $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', Security::remove_XSS($category['cat_name'])).'</a>'; |
|
612 | - $dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=sent">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.Security::remove_XSS($category['cat_name']).'</a>'; |
|
613 | - //$dropbox_category_data[] = ''; |
|
614 | - $dropbox_category_data[] = ''; |
|
615 | - //$dropbox_category_data[] = ''; |
|
616 | - $dropbox_category_data[] = ''; |
|
617 | - $dropbox_category_data[] = ''; |
|
618 | - $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'. |
|
608 | + $dropbox_category_data[] = $category['cat_id']; |
|
609 | + // This is where the checkbox icon for the files appear. |
|
610 | + $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$category['cat_id'].'&view='.$view.'">'; |
|
611 | + $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', Security::remove_XSS($category['cat_name'])).'</a>'; |
|
612 | + $dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=sent">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.Security::remove_XSS($category['cat_name']).'</a>'; |
|
613 | + //$dropbox_category_data[] = ''; |
|
614 | + $dropbox_category_data[] = ''; |
|
615 | + //$dropbox_category_data[] = ''; |
|
616 | + $dropbox_category_data[] = ''; |
|
617 | + $dropbox_category_data[] = ''; |
|
618 | + $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'. |
|
619 | 619 | Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a> |
620 | 620 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletesentcategory&id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.Security::remove_XSS($category['cat_name']).'\');">'. |
621 | 621 | Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'; |
622 | - } |
|
623 | - if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) { |
|
624 | - $dropbox_data_sent[] = $dropbox_category_data; |
|
625 | - } |
|
626 | - } |
|
627 | - } |
|
628 | - |
|
629 | - // Displaying the table |
|
630 | - $additional_get_parameters = array( |
|
622 | + } |
|
623 | + if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) { |
|
624 | + $dropbox_data_sent[] = $dropbox_category_data; |
|
625 | + } |
|
626 | + } |
|
627 | + } |
|
628 | + |
|
629 | + // Displaying the table |
|
630 | + $additional_get_parameters = array( |
|
631 | 631 | 'view' => $view, |
632 | 632 | 'view_received_category' => $viewReceivedCategory, |
633 | 633 | 'view_sent_category' => $viewSentCategory |
634 | 634 | ); |
635 | 635 | |
636 | - $selectlist = array( |
|
636 | + $selectlist = array( |
|
637 | 637 | 'delete_received' => get_lang('Delete'), |
638 | 638 | 'download_received' => get_lang('Download') |
639 | 639 | ); |
@@ -644,12 +644,12 @@ discard block |
||
644 | 644 | } |
645 | 645 | } |
646 | 646 | |
647 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
648 | - $selectlist = array('download_received' => get_lang('Download')); |
|
649 | - } |
|
647 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
648 | + $selectlist = array('download_received' => get_lang('Download')); |
|
649 | + } |
|
650 | 650 | |
651 | 651 | echo '<div class="files-table">'; |
652 | - Display::display_sortable_config_table( |
|
652 | + Display::display_sortable_config_table( |
|
653 | 653 | 'dropbox', |
654 | 654 | $column_header, |
655 | 655 | $dropbox_data_sent, |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | $selectlist |
662 | 662 | ); |
663 | 663 | echo '</div>'; |
664 | - } |
|
664 | + } |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | Display::display_footer(); |
@@ -76,20 +76,20 @@ discard block |
||
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
79 | - /** |
|
80 | - * private function creating a new work object |
|
81 | - * |
|
82 | - * @param int $uploader_id |
|
83 | - * @param string $title |
|
84 | - * @param string $description |
|
85 | - * @param string $author |
|
86 | - * @param string $filename |
|
87 | - * @param int $filesize |
|
88 | - * |
|
89 | - * @todo $author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads) |
|
90 | - * As a consequence this parameter can be removed |
|
91 | - */ |
|
92 | - public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize) |
|
79 | + /** |
|
80 | + * private function creating a new work object |
|
81 | + * |
|
82 | + * @param int $uploader_id |
|
83 | + * @param string $title |
|
84 | + * @param string $description |
|
85 | + * @param string $author |
|
86 | + * @param string $filename |
|
87 | + * @param int $filesize |
|
88 | + * |
|
89 | + * @todo $author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads) |
|
90 | + * As a consequence this parameter can be removed |
|
91 | + */ |
|
92 | + public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize) |
|
93 | 93 | { |
94 | 94 | // Fill in the properties |
95 | 95 | $this->uploader_id = intval($uploader_id); |
@@ -104,17 +104,17 @@ discard block |
||
104 | 104 | // Check if object exists already. If it does, the old object is used |
105 | 105 | // with updated information (authors, description, upload_date) |
106 | 106 | $this->isOldWork = false; |
107 | - $sql = "SELECT id, upload_date FROM ". Database::get_course_table(TABLE_DROPBOX_FILE) ." |
|
107 | + $sql = "SELECT id, upload_date FROM ". Database::get_course_table(TABLE_DROPBOX_FILE) ." |
|
108 | 108 | WHERE c_id = $course_id AND filename = '".Database::escape_string($this->filename)."'"; |
109 | 109 | $result = Database::query($sql); |
110 | - $res = Database::fetch_array($result); |
|
111 | - if ($res) { |
|
112 | - $this->isOldWork = true; |
|
113 | - } |
|
114 | - // Insert or update the dropbox_file table and set the id property |
|
115 | - if ($this->isOldWork) { |
|
116 | - $this->id = $res['id']; |
|
117 | - $this->upload_date = $res['upload_date']; |
|
110 | + $res = Database::fetch_array($result); |
|
111 | + if ($res) { |
|
112 | + $this->isOldWork = true; |
|
113 | + } |
|
114 | + // Insert or update the dropbox_file table and set the id property |
|
115 | + if ($this->isOldWork) { |
|
116 | + $this->id = $res['id']; |
|
117 | + $this->upload_date = $res['upload_date']; |
|
118 | 118 | |
119 | 119 | $params = [ |
120 | 120 | 'filesize' => $this->filesize, |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | $params, |
131 | 131 | ['c_id = ? AND id = ?' => [$course_id, $this->id]] |
132 | 132 | ); |
133 | - } else { |
|
134 | - $this->upload_date = $this->last_upload_date; |
|
135 | - $params = [ |
|
133 | + } else { |
|
134 | + $this->upload_date = $this->last_upload_date; |
|
135 | + $params = [ |
|
136 | 136 | 'c_id' => $course_id, |
137 | 137 | 'uploader_id' => $this->uploader_id, |
138 | 138 | 'filename' => $this->filename, |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | 'last_upload_date' => $this->last_upload_date, |
145 | 145 | 'session_id' => api_get_session_id(), |
146 | 146 | 'cat_id' => 0 |
147 | - ]; |
|
147 | + ]; |
|
148 | 148 | |
149 | - $this->id = Database::insert(Database::get_course_table(TABLE_DROPBOX_FILE), $params); |
|
150 | - if ($this->id) { |
|
151 | - $sql = "UPDATE ". Database::get_course_table(TABLE_DROPBOX_FILE) ." SET id = iid WHERE iid = {$this->id}"; |
|
152 | - Database::query($sql); |
|
153 | - } |
|
154 | - } |
|
149 | + $this->id = Database::insert(Database::get_course_table(TABLE_DROPBOX_FILE), $params); |
|
150 | + if ($this->id) { |
|
151 | + $sql = "UPDATE ". Database::get_course_table(TABLE_DROPBOX_FILE) ." SET id = iid WHERE iid = {$this->id}"; |
|
152 | + Database::query($sql); |
|
153 | + } |
|
154 | + } |
|
155 | 155 | |
156 | 156 | $sql = "SELECT count(file_id) as count |
157 | 157 | FROM ". Database::get_course_table(TABLE_DROPBOX_PERSON) ." |
@@ -165,16 +165,16 @@ discard block |
||
165 | 165 | VALUES ($course_id, ".intval($this->id)." , ".intval($this->uploader_id).")"; |
166 | 166 | Database::query($sql); |
167 | 167 | } |
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * private function creating existing object by retreiving info from db |
|
172 | - * |
|
173 | - * @param int $id |
|
174 | - */ |
|
175 | - public function _createExistingWork($id) |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * private function creating existing object by retreiving info from db |
|
172 | + * |
|
173 | + * @param int $id |
|
174 | + */ |
|
175 | + public function _createExistingWork($id) |
|
176 | 176 | { |
177 | - $course_id = api_get_course_int_id(); |
|
177 | + $course_id = api_get_course_int_id(); |
|
178 | 178 | |
179 | 179 | $action = isset($_GET['action']) ? $_GET['action'] : null; |
180 | 180 | |
@@ -222,52 +222,52 @@ discard block |
||
222 | 222 | } |
223 | 223 | $this->feedback2= $feedback2; |
224 | 224 | } |
225 | - } |
|
225 | + } |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | class Dropbox_SentWork extends Dropbox_Work |
229 | 229 | { |
230 | - public $recipients; //array of ['id']['name'] arrays |
|
231 | - |
|
232 | - /** |
|
233 | - * Constructor calls private functions to create a new work or retreive an existing work from DB |
|
234 | - * depending on the number of parameters |
|
235 | - * |
|
236 | - * @param unknown_type $arg1 |
|
237 | - * @param unknown_type $arg2 |
|
238 | - * @param unknown_type $arg3 |
|
239 | - * @param unknown_type $arg4 |
|
240 | - * @param unknown_type $arg5 |
|
241 | - * @param unknown_type $arg6 |
|
242 | - * @param unknown_type $arg7 |
|
243 | - * @return Dropbox_SentWork |
|
244 | - */ |
|
245 | - public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null) |
|
230 | + public $recipients; //array of ['id']['name'] arrays |
|
231 | + |
|
232 | + /** |
|
233 | + * Constructor calls private functions to create a new work or retreive an existing work from DB |
|
234 | + * depending on the number of parameters |
|
235 | + * |
|
236 | + * @param unknown_type $arg1 |
|
237 | + * @param unknown_type $arg2 |
|
238 | + * @param unknown_type $arg3 |
|
239 | + * @param unknown_type $arg4 |
|
240 | + * @param unknown_type $arg5 |
|
241 | + * @param unknown_type $arg6 |
|
242 | + * @param unknown_type $arg7 |
|
243 | + * @return Dropbox_SentWork |
|
244 | + */ |
|
245 | + public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null) |
|
246 | 246 | { |
247 | - if (func_num_args() > 1) { |
|
248 | - $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7); |
|
249 | - } else { |
|
250 | - $this->_createExistingSentWork($arg1); |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * private function creating a new SentWork object |
|
256 | - * |
|
257 | - * @param int $uploader_id |
|
258 | - * @param string $title |
|
259 | - * @param string $description |
|
260 | - * @param string $author |
|
261 | - * @param string $filename |
|
262 | - * @param int $filesize |
|
263 | - * @param array $recipient_ids |
|
264 | - */ |
|
265 | - public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) |
|
247 | + if (func_num_args() > 1) { |
|
248 | + $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7); |
|
249 | + } else { |
|
250 | + $this->_createExistingSentWork($arg1); |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * private function creating a new SentWork object |
|
256 | + * |
|
257 | + * @param int $uploader_id |
|
258 | + * @param string $title |
|
259 | + * @param string $description |
|
260 | + * @param string $author |
|
261 | + * @param string $filename |
|
262 | + * @param int $filesize |
|
263 | + * @param array $recipient_ids |
|
264 | + */ |
|
265 | + public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) |
|
266 | 266 | { |
267 | 267 | $dropbox_cnf = getDropboxConf(); |
268 | 268 | $_course = api_get_course_info(); |
269 | 269 | |
270 | - // Call constructor of Dropbox_Work object |
|
270 | + // Call constructor of Dropbox_Work object |
|
271 | 271 | parent::__construct( |
272 | 272 | $uploader_id, |
273 | 273 | $title, |
@@ -277,33 +277,33 @@ discard block |
||
277 | 277 | $filesize |
278 | 278 | ); |
279 | 279 | |
280 | - $course_id = api_get_course_int_id(); |
|
281 | - |
|
282 | - // Do sanity checks on recipient_ids array & property fillin |
|
283 | - // The sanity check for ex-coursemembers is already done in base constructor |
|
284 | - $uploader_id = (int) $uploader_id; |
|
280 | + $course_id = api_get_course_int_id(); |
|
285 | 281 | |
286 | - $justSubmit = false; |
|
287 | - if (is_int($recipient_ids)) { |
|
288 | - $justSubmit = true; |
|
289 | - $recipient_ids = array($recipient_ids + $this->id); |
|
290 | - } elseif (count($recipient_ids) == 0) { |
|
291 | - $justSubmit = true; |
|
292 | - $recipient_ids = array($uploader_id); |
|
293 | - } |
|
282 | + // Do sanity checks on recipient_ids array & property fillin |
|
283 | + // The sanity check for ex-coursemembers is already done in base constructor |
|
284 | + $uploader_id = (int) $uploader_id; |
|
285 | + |
|
286 | + $justSubmit = false; |
|
287 | + if (is_int($recipient_ids)) { |
|
288 | + $justSubmit = true; |
|
289 | + $recipient_ids = array($recipient_ids + $this->id); |
|
290 | + } elseif (count($recipient_ids) == 0) { |
|
291 | + $justSubmit = true; |
|
292 | + $recipient_ids = array($uploader_id); |
|
293 | + } |
|
294 | 294 | |
295 | - if (! is_array($recipient_ids) || count($recipient_ids) == 0) { |
|
296 | - die(get_lang('GeneralError').' (code 209)'); |
|
297 | - } |
|
295 | + if (! is_array($recipient_ids) || count($recipient_ids) == 0) { |
|
296 | + die(get_lang('GeneralError').' (code 209)'); |
|
297 | + } |
|
298 | 298 | |
299 | - foreach ($recipient_ids as $rec) { |
|
300 | - if (empty($rec)) { |
|
301 | - continue; |
|
299 | + foreach ($recipient_ids as $rec) { |
|
300 | + if (empty($rec)) { |
|
301 | + continue; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | //this check is done when validating submitted data |
305 | - $this->recipients[] = array('id' => $rec); |
|
306 | - } |
|
305 | + $this->recipients[] = array('id' => $rec); |
|
306 | + } |
|
307 | 307 | |
308 | 308 | $table_post = Database::get_course_table(TABLE_DROPBOX_POST); |
309 | 309 | $table_person = Database::get_course_table(TABLE_DROPBOX_PERSON); |
@@ -313,12 +313,12 @@ discard block |
||
313 | 313 | $mailId = get_mail_id_base(); |
314 | 314 | |
315 | 315 | // Insert data in dropbox_post and dropbox_person table for each recipient |
316 | - foreach ($this->recipients as $rec) { |
|
316 | + foreach ($this->recipients as $rec) { |
|
317 | 317 | $file_id = (int)$this->id; |
318 | 318 | $user_id = (int)$rec['id']; |
319 | - $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id) |
|
319 | + $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id) |
|
320 | 320 | VALUES ($course_id, $file_id, $user_id, $session_id, '$now', 0)"; |
321 | - Database::query($sql); |
|
321 | + Database::query($sql); |
|
322 | 322 | // If work already exists no error is generated |
323 | 323 | |
324 | 324 | /** |
@@ -335,13 +335,13 @@ discard block |
||
335 | 335 | } |
336 | 336 | } |
337 | 337 | |
338 | - // Update item_property table for each recipient |
|
339 | - if (($ownerid = $this->uploader_id) > $mailId) { |
|
340 | - $ownerid = getUserOwningThisMailing($ownerid); |
|
341 | - } |
|
342 | - if (($recipid = $rec["id"]) > $mailId) { |
|
343 | - $recipid = $ownerid; // mailing file recipient = mailing id, not a person |
|
344 | - } |
|
338 | + // Update item_property table for each recipient |
|
339 | + if (($ownerid = $this->uploader_id) > $mailId) { |
|
340 | + $ownerid = getUserOwningThisMailing($ownerid); |
|
341 | + } |
|
342 | + if (($recipid = $rec["id"]) > $mailId) { |
|
343 | + $recipid = $ownerid; // mailing file recipient = mailing id, not a person |
|
344 | + } |
|
345 | 345 | api_item_property_update( |
346 | 346 | $_course, |
347 | 347 | TOOL_DROPBOX, |
@@ -351,90 +351,90 @@ discard block |
||
351 | 351 | null, |
352 | 352 | $recipid |
353 | 353 | ); |
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * private function creating existing object by retreiving info from db |
|
359 | - * |
|
360 | - * @param unknown_type $id |
|
361 | - */ |
|
362 | - public function _createExistingSentWork($id) |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * private function creating existing object by retreiving info from db |
|
359 | + * |
|
360 | + * @param unknown_type $id |
|
361 | + */ |
|
362 | + public function _createExistingSentWork($id) |
|
363 | 363 | { |
364 | 364 | $id = intval($id); |
365 | 365 | |
366 | - $course_id = api_get_course_int_id(); |
|
366 | + $course_id = api_get_course_int_id(); |
|
367 | 367 | |
368 | - // Call constructor of Dropbox_Work object |
|
369 | - parent::__construct($id); |
|
368 | + // Call constructor of Dropbox_Work object |
|
369 | + parent::__construct($id); |
|
370 | 370 | |
371 | - // Fill in recipients array |
|
372 | - $this->recipients = array(); |
|
373 | - $sql = "SELECT dest_user_id, feedback_date, feedback |
|
371 | + // Fill in recipients array |
|
372 | + $this->recipients = array(); |
|
373 | + $sql = "SELECT dest_user_id, feedback_date, feedback |
|
374 | 374 | FROM ".Database::get_course_table(TABLE_DROPBOX_POST)." |
375 | 375 | WHERE c_id = $course_id AND file_id = ".intval($id).""; |
376 | 376 | $result = Database::query($sql); |
377 | - while ($res = Database::fetch_array($result, 'ASSOC')) { |
|
378 | - // Check for deleted users |
|
379 | - $dest_user_id = $res['dest_user_id']; |
|
380 | - $user_info = api_get_user_info($dest_user_id); |
|
381 | - //$this->category = $res['cat_id']; |
|
382 | - if (!$user_info) { |
|
383 | - $this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', '')); |
|
384 | - } else { |
|
385 | - $this->recipients[] = array( |
|
377 | + while ($res = Database::fetch_array($result, 'ASSOC')) { |
|
378 | + // Check for deleted users |
|
379 | + $dest_user_id = $res['dest_user_id']; |
|
380 | + $user_info = api_get_user_info($dest_user_id); |
|
381 | + //$this->category = $res['cat_id']; |
|
382 | + if (!$user_info) { |
|
383 | + $this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', '')); |
|
384 | + } else { |
|
385 | + $this->recipients[] = array( |
|
386 | 386 | 'id' => $dest_user_id, |
387 | 387 | 'name' => $user_info['complete_name'], |
388 | 388 | 'user_id' => $dest_user_id, |
389 | - 'feedback_date' => $res['feedback_date'], |
|
389 | + 'feedback_date' => $res['feedback_date'], |
|
390 | 390 | 'feedback' => $res['feedback'] |
391 | 391 | ); |
392 | - } |
|
393 | - } |
|
394 | - } |
|
392 | + } |
|
393 | + } |
|
394 | + } |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | class Dropbox_Person |
398 | 398 | { |
399 | - // The receivedWork and the sentWork arrays are sorted. |
|
400 | - public $receivedWork; // an array of Dropbox_Work objects |
|
401 | - public $sentWork; // an array of Dropbox_SentWork objects |
|
402 | - |
|
403 | - public $userId = 0; |
|
404 | - public $isCourseAdmin = false; |
|
405 | - public $isCourseTutor = false; |
|
406 | - public $_orderBy = ''; // private property that determines by which field |
|
407 | - |
|
408 | - /** |
|
409 | - * Constructor for recreating the Dropbox_Person object |
|
410 | - * |
|
411 | - * @param int $userId |
|
412 | - * @param bool $isCourseAdmin |
|
413 | - * @param bool $isCourseTutor |
|
414 | - * @return Dropbox_Person |
|
415 | - */ |
|
416 | - public function __construct($userId, $isCourseAdmin, $isCourseTutor) |
|
399 | + // The receivedWork and the sentWork arrays are sorted. |
|
400 | + public $receivedWork; // an array of Dropbox_Work objects |
|
401 | + public $sentWork; // an array of Dropbox_SentWork objects |
|
402 | + |
|
403 | + public $userId = 0; |
|
404 | + public $isCourseAdmin = false; |
|
405 | + public $isCourseTutor = false; |
|
406 | + public $_orderBy = ''; // private property that determines by which field |
|
407 | + |
|
408 | + /** |
|
409 | + * Constructor for recreating the Dropbox_Person object |
|
410 | + * |
|
411 | + * @param int $userId |
|
412 | + * @param bool $isCourseAdmin |
|
413 | + * @param bool $isCourseTutor |
|
414 | + * @return Dropbox_Person |
|
415 | + */ |
|
416 | + public function __construct($userId, $isCourseAdmin, $isCourseTutor) |
|
417 | 417 | { |
418 | - $course_id = api_get_course_int_id(); |
|
418 | + $course_id = api_get_course_int_id(); |
|
419 | 419 | |
420 | - // Fill in properties |
|
420 | + // Fill in properties |
|
421 | 421 | $this->userId = $userId; |
422 | 422 | $this->isCourseAdmin = $isCourseAdmin; |
423 | 423 | $this->isCourseTutor = $isCourseTutor; |
424 | 424 | $this->receivedWork = array(); |
425 | 425 | $this->sentWork = array(); |
426 | 426 | |
427 | - // Note: perhaps include an ex coursemember check to delete old files |
|
427 | + // Note: perhaps include an ex coursemember check to delete old files |
|
428 | 428 | |
429 | - $session_id = api_get_session_id(); |
|
430 | - $condition_session = api_get_session_condition($session_id); |
|
429 | + $session_id = api_get_session_id(); |
|
430 | + $condition_session = api_get_session_condition($session_id); |
|
431 | 431 | |
432 | - $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST); |
|
433 | - $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON); |
|
434 | - $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE); |
|
432 | + $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST); |
|
433 | + $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON); |
|
434 | + $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE); |
|
435 | 435 | |
436 | 436 | // Find all entries where this person is the recipient |
437 | - $sql = "SELECT DISTINCT r.file_id, r.cat_id |
|
437 | + $sql = "SELECT DISTINCT r.file_id, r.cat_id |
|
438 | 438 | FROM $post_tbl r |
439 | 439 | INNER JOIN $person_tbl p |
440 | 440 | ON (r.file_id = p.file_id AND r.c_id = $course_id AND p.c_id = $course_id ) |
@@ -443,12 +443,12 @@ discard block |
||
443 | 443 | r.dest_user_id = ".intval($this->userId)." $condition_session "; |
444 | 444 | |
445 | 445 | $result = Database::query($sql); |
446 | - while ($res = Database::fetch_array($result)) { |
|
447 | - $temp = new Dropbox_Work($res['file_id']); |
|
448 | - $temp->category = $res['cat_id']; |
|
449 | - $this->receivedWork[] = $temp; |
|
450 | - } |
|
451 | - // Find all entries where this person is the sender/uploader |
|
446 | + while ($res = Database::fetch_array($result)) { |
|
447 | + $temp = new Dropbox_Work($res['file_id']); |
|
448 | + $temp->category = $res['cat_id']; |
|
449 | + $this->receivedWork[] = $temp; |
|
450 | + } |
|
451 | + // Find all entries where this person is the sender/uploader |
|
452 | 452 | $sql = "SELECT DISTINCT f.id |
453 | 453 | FROM $file_tbl f |
454 | 454 | INNER JOIN $person_tbl p |
@@ -459,160 +459,160 @@ discard block |
||
459 | 459 | $condition_session |
460 | 460 | "; |
461 | 461 | $result = Database::query($sql); |
462 | - while ($res = Database::fetch_array($result)) { |
|
463 | - $this->sentWork[] = new Dropbox_SentWork($res['id']); |
|
464 | - } |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Deletes all the received work of this person |
|
469 | - */ |
|
470 | - public function deleteAllReceivedWork() |
|
462 | + while ($res = Database::fetch_array($result)) { |
|
463 | + $this->sentWork[] = new Dropbox_SentWork($res['id']); |
|
464 | + } |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Deletes all the received work of this person |
|
469 | + */ |
|
470 | + public function deleteAllReceivedWork() |
|
471 | 471 | { |
472 | - $course_id = api_get_course_int_id(); |
|
473 | - // Delete entries in person table concerning received works |
|
474 | - foreach ($this->receivedWork as $w) { |
|
472 | + $course_id = api_get_course_int_id(); |
|
473 | + // Delete entries in person table concerning received works |
|
474 | + foreach ($this->receivedWork as $w) { |
|
475 | 475 | $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_PERSON) ." |
476 | 476 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'"; |
477 | - Database::query($sql); |
|
478 | - } |
|
477 | + Database::query($sql); |
|
478 | + } |
|
479 | 479 | // Check for unused files |
480 | - removeUnusedFiles(); |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Deletes all the received categories and work of this person |
|
485 | - * @param integer $id |
|
486 | - */ |
|
487 | - public function deleteReceivedWorkFolder($id) |
|
480 | + removeUnusedFiles(); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Deletes all the received categories and work of this person |
|
485 | + * @param integer $id |
|
486 | + */ |
|
487 | + public function deleteReceivedWorkFolder($id) |
|
488 | 488 | { |
489 | 489 | $course_id = api_get_course_int_id(); |
490 | 490 | |
491 | - $id = intval($id); |
|
492 | - $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_FILE) ." |
|
491 | + $id = intval($id); |
|
492 | + $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_FILE) ." |
|
493 | 493 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
494 | - if (!Database::query($sql)) return false; |
|
495 | - $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_CATEGORY) ." |
|
494 | + if (!Database::query($sql)) return false; |
|
495 | + $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_CATEGORY) ." |
|
496 | 496 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
497 | - if (!Database::query($sql)) return false; |
|
498 | - $sql = "DELETE FROM ".Database::get_course_table(TABLE_DROPBOX_POST)." |
|
497 | + if (!Database::query($sql)) return false; |
|
498 | + $sql = "DELETE FROM ".Database::get_course_table(TABLE_DROPBOX_POST)." |
|
499 | 499 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
500 | - if (!Database::query($sql)) return false; |
|
501 | - return true; |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * Deletes a received dropbox file of this person with id=$id |
|
506 | - * |
|
507 | - * @param integer $id |
|
508 | - */ |
|
509 | - public function deleteReceivedWork($id) |
|
500 | + if (!Database::query($sql)) return false; |
|
501 | + return true; |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * Deletes a received dropbox file of this person with id=$id |
|
506 | + * |
|
507 | + * @param integer $id |
|
508 | + */ |
|
509 | + public function deleteReceivedWork($id) |
|
510 | 510 | { |
511 | - $course_id = api_get_course_int_id(); |
|
512 | - $id = intval($id); |
|
513 | - |
|
514 | - // index check |
|
515 | - $found = false; |
|
516 | - foreach ($this->receivedWork as $w) { |
|
517 | - if ($w->id == $id) { |
|
518 | - $found = true; |
|
519 | - break; |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - if (!$found) { |
|
524 | - if (!$this->deleteReceivedWorkFolder($id)) { |
|
525 | - die(get_lang('GeneralError').' (code 216)'); |
|
526 | - } |
|
527 | - } |
|
528 | - // Delete entries in person table concerning received works |
|
511 | + $course_id = api_get_course_int_id(); |
|
512 | + $id = intval($id); |
|
513 | + |
|
514 | + // index check |
|
515 | + $found = false; |
|
516 | + foreach ($this->receivedWork as $w) { |
|
517 | + if ($w->id == $id) { |
|
518 | + $found = true; |
|
519 | + break; |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + if (!$found) { |
|
524 | + if (!$this->deleteReceivedWorkFolder($id)) { |
|
525 | + die(get_lang('GeneralError').' (code 216)'); |
|
526 | + } |
|
527 | + } |
|
528 | + // Delete entries in person table concerning received works |
|
529 | 529 | $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_PERSON) ." |
530 | 530 | WHERE c_id = $course_id AND user_id = '".$this->userId."' AND file_id ='".$id."'"; |
531 | - Database::query($sql); |
|
532 | - removeUnusedFiles(); // Check for unused files |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Deletes all the sent dropbox files of this person |
|
537 | - */ |
|
538 | - public function deleteAllSentWork() |
|
531 | + Database::query($sql); |
|
532 | + removeUnusedFiles(); // Check for unused files |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Deletes all the sent dropbox files of this person |
|
537 | + */ |
|
538 | + public function deleteAllSentWork() |
|
539 | 539 | { |
540 | - $course_id = api_get_course_int_id(); |
|
541 | - //delete entries in person table concerning sent works |
|
542 | - foreach ($this->sentWork as $w) { |
|
540 | + $course_id = api_get_course_int_id(); |
|
541 | + //delete entries in person table concerning sent works |
|
542 | + foreach ($this->sentWork as $w) { |
|
543 | 543 | $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_PERSON) ." |
544 | 544 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'"; |
545 | - Database::query($sql); |
|
546 | - removeMoreIfMailing($w->id); |
|
547 | - } |
|
548 | - removeUnusedFiles(); // Check for unused files |
|
549 | - } |
|
550 | - |
|
551 | - /** |
|
552 | - * Deletes a sent dropbox file of this person with id=$id |
|
553 | - * |
|
554 | - * @param unknown_type $id |
|
555 | - */ |
|
556 | - public function deleteSentWork($id) |
|
545 | + Database::query($sql); |
|
546 | + removeMoreIfMailing($w->id); |
|
547 | + } |
|
548 | + removeUnusedFiles(); // Check for unused files |
|
549 | + } |
|
550 | + |
|
551 | + /** |
|
552 | + * Deletes a sent dropbox file of this person with id=$id |
|
553 | + * |
|
554 | + * @param unknown_type $id |
|
555 | + */ |
|
556 | + public function deleteSentWork($id) |
|
557 | 557 | { |
558 | - $course_id = api_get_course_int_id(); |
|
559 | - |
|
560 | - $id = intval($id); |
|
561 | - |
|
562 | - // index check |
|
563 | - $found = false; |
|
564 | - foreach ($this->sentWork as $w) { |
|
565 | - if ($w->id == $id) { |
|
566 | - $found = true; |
|
567 | - break; |
|
568 | - } |
|
569 | - } |
|
570 | - if (!$found) { |
|
571 | - if (!$this->deleteReceivedWorkFolder($id)) { |
|
572 | - die(get_lang('GeneralError').' (code 219)'); |
|
573 | - } |
|
574 | - } |
|
575 | - //$file_id = $this->sentWork[$index]->id; |
|
576 | - // Delete entries in person table concerning sent works |
|
558 | + $course_id = api_get_course_int_id(); |
|
559 | + |
|
560 | + $id = intval($id); |
|
561 | + |
|
562 | + // index check |
|
563 | + $found = false; |
|
564 | + foreach ($this->sentWork as $w) { |
|
565 | + if ($w->id == $id) { |
|
566 | + $found = true; |
|
567 | + break; |
|
568 | + } |
|
569 | + } |
|
570 | + if (!$found) { |
|
571 | + if (!$this->deleteReceivedWorkFolder($id)) { |
|
572 | + die(get_lang('GeneralError').' (code 219)'); |
|
573 | + } |
|
574 | + } |
|
575 | + //$file_id = $this->sentWork[$index]->id; |
|
576 | + // Delete entries in person table concerning sent works |
|
577 | 577 | $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_PERSON) ." |
578 | 578 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$id."'"; |
579 | - Database::query($sql); |
|
580 | - removeMoreIfMailing($id); |
|
581 | - removeUnusedFiles(); // Check for unused files |
|
582 | - } |
|
583 | - |
|
584 | - /** |
|
585 | - * Updates feedback for received work of this person with id=$id |
|
586 | - * |
|
587 | - * @param string $id |
|
588 | - * @param string $text |
|
589 | - */ |
|
590 | - public function updateFeedback($id, $text) |
|
579 | + Database::query($sql); |
|
580 | + removeMoreIfMailing($id); |
|
581 | + removeUnusedFiles(); // Check for unused files |
|
582 | + } |
|
583 | + |
|
584 | + /** |
|
585 | + * Updates feedback for received work of this person with id=$id |
|
586 | + * |
|
587 | + * @param string $id |
|
588 | + * @param string $text |
|
589 | + */ |
|
590 | + public function updateFeedback($id, $text) |
|
591 | 591 | { |
592 | - $course_id = api_get_course_int_id(); |
|
592 | + $course_id = api_get_course_int_id(); |
|
593 | 593 | $_course = api_get_course_info(); |
594 | 594 | $dropbox_cnf = getDropboxConf(); |
595 | 595 | |
596 | - $id = intval($id); |
|
596 | + $id = intval($id); |
|
597 | 597 | |
598 | - // index check |
|
599 | - $found = false; |
|
600 | - $wi = -1; |
|
601 | - foreach ($this->receivedWork as $w) { |
|
602 | - $wi++; |
|
603 | - if ($w->id == $id){ |
|
604 | - $found = true; |
|
605 | - break; |
|
606 | - } // foreach (... as $wi -> $w) gives error 221! (no idea why...) |
|
607 | - } |
|
598 | + // index check |
|
599 | + $found = false; |
|
600 | + $wi = -1; |
|
601 | + foreach ($this->receivedWork as $w) { |
|
602 | + $wi++; |
|
603 | + if ($w->id == $id){ |
|
604 | + $found = true; |
|
605 | + break; |
|
606 | + } // foreach (... as $wi -> $w) gives error 221! (no idea why...) |
|
607 | + } |
|
608 | 608 | |
609 | - if (!$found) { |
|
610 | - return false; |
|
611 | - } |
|
609 | + if (!$found) { |
|
610 | + return false; |
|
611 | + } |
|
612 | 612 | |
613 | - $feedback_date = api_get_utc_datetime(); |
|
614 | - $this->receivedWork[$wi]->feedback_date = $feedback_date; |
|
615 | - $this->receivedWork[$wi]->feedback = $text; |
|
613 | + $feedback_date = api_get_utc_datetime(); |
|
614 | + $this->receivedWork[$wi]->feedback_date = $feedback_date; |
|
615 | + $this->receivedWork[$wi]->feedback = $text; |
|
616 | 616 | |
617 | 617 | $params = [ |
618 | 618 | 'feedback_date' => $feedback_date, |
@@ -630,11 +630,11 @@ discard block |
||
630 | 630 | ] |
631 | 631 | ); |
632 | 632 | |
633 | - // Update item_property table |
|
633 | + // Update item_property table |
|
634 | 634 | $mailId = get_mail_id_base(); |
635 | - if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $mailId) { |
|
636 | - $ownerid = getUserOwningThisMailing($ownerid); |
|
637 | - } |
|
635 | + if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $mailId) { |
|
636 | + $ownerid = getUserOwningThisMailing($ownerid); |
|
637 | + } |
|
638 | 638 | |
639 | 639 | api_item_property_update( |
640 | 640 | $_course, |
@@ -646,33 +646,33 @@ discard block |
||
646 | 646 | $ownerid |
647 | 647 | ); |
648 | 648 | |
649 | - } |
|
649 | + } |
|
650 | 650 | |
651 | - /** |
|
652 | - * Filter the received work |
|
653 | - * @param string $type |
|
654 | - * @param string $value |
|
655 | - */ |
|
656 | - public function filter_received_work($type, $value) |
|
651 | + /** |
|
652 | + * Filter the received work |
|
653 | + * @param string $type |
|
654 | + * @param string $value |
|
655 | + */ |
|
656 | + public function filter_received_work($type, $value) |
|
657 | 657 | { |
658 | 658 | $dropbox_cnf = getDropboxConf(); |
659 | - $new_received_work = array(); |
|
659 | + $new_received_work = array(); |
|
660 | 660 | $mailId = get_mail_id_base(); |
661 | 661 | foreach ($this->receivedWork as $work) { |
662 | - switch ($type) { |
|
663 | - case 'uploader_id': |
|
664 | - if ($work->uploader_id == $value || |
|
665 | - ($work->uploader_id > $mailId && |
|
662 | + switch ($type) { |
|
663 | + case 'uploader_id': |
|
664 | + if ($work->uploader_id == $value || |
|
665 | + ($work->uploader_id > $mailId && |
|
666 | 666 | getUserOwningThisMailing($work->uploader_id) == $value) |
667 | 667 | ) { |
668 | - $new_received_work[] = $work; |
|
669 | - } |
|
670 | - break; |
|
671 | - default: |
|
672 | - $new_received_work[] = $work; |
|
668 | + $new_received_work[] = $work; |
|
669 | + } |
|
670 | + break; |
|
671 | + default: |
|
672 | + $new_received_work[] = $work; |
|
673 | 673 | break; |
674 | - } |
|
675 | - } |
|
676 | - $this->receivedWork = $new_received_work; |
|
677 | - } |
|
674 | + } |
|
675 | + } |
|
676 | + $this->receivedWork = $new_received_work; |
|
677 | + } |
|
678 | 678 | } |
@@ -10,46 +10,46 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class ForumThreadLink extends AbstractLink |
12 | 12 | { |
13 | - private $forum_thread_table = null; |
|
14 | - private $itemprop_table = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * Constructor |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::__construct(); |
|
22 | - $this->set_type(LINK_FORUM_THREAD); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function get_type_name() |
|
29 | - { |
|
30 | - return get_lang('ForumThreads'); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function is_allowed_to_change_name() |
|
37 | - { |
|
38 | - return false; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | - */ |
|
45 | - public function get_not_created_links() |
|
46 | - { |
|
47 | - if (empty($this->course_code)) { |
|
48 | - die('Error in get_not_created_links() : course code not set'); |
|
49 | - } |
|
50 | - |
|
51 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | - $sql = 'SELECT thread_id,thread_title,thread_title_qualify |
|
13 | + private $forum_thread_table = null; |
|
14 | + private $itemprop_table = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * Constructor |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::__construct(); |
|
22 | + $this->set_type(LINK_FORUM_THREAD); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function get_type_name() |
|
29 | + { |
|
30 | + return get_lang('ForumThreads'); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function is_allowed_to_change_name() |
|
37 | + { |
|
38 | + return false; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | + */ |
|
45 | + public function get_not_created_links() |
|
46 | + { |
|
47 | + if (empty($this->course_code)) { |
|
48 | + die('Error in get_not_created_links() : course code not set'); |
|
49 | + } |
|
50 | + |
|
51 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | + $sql = 'SELECT thread_id,thread_title,thread_title_qualify |
|
53 | 53 | FROM '.$this->get_forum_thread_table().' |
54 | 54 | forum_thread WHERE thread_id NOT IN |
55 | 55 | ( |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | ) |
61 | 61 | AND forum_thread.session_id='.api_get_session_id(); |
62 | 62 | |
63 | - $result = Database::query($sql); |
|
63 | + $result = Database::query($sql); |
|
64 | 64 | |
65 | 65 | $cats = array(); |
66 | 66 | while ($data = Database::fetch_array($result)) { |
@@ -75,29 +75,29 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | return $cats; |
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Generate an array of all exercises available. |
|
82 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
83 | - */ |
|
84 | - public function get_all_links() |
|
85 | - { |
|
86 | - if (empty($this->course_code)) { |
|
87 | - die('Error in get_not_created_links() : course code not set'); |
|
88 | - } |
|
89 | - |
|
90 | - $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
91 | - $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
92 | - $session_id = api_get_session_id(); |
|
93 | - |
|
94 | - if ($session_id) { |
|
95 | - $session_condition = 'tl.session_id='.api_get_session_id(); |
|
96 | - } else { |
|
97 | - $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
98 | - } |
|
99 | - |
|
100 | - $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Generate an array of all exercises available. |
|
82 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
83 | + */ |
|
84 | + public function get_all_links() |
|
85 | + { |
|
86 | + if (empty($this->course_code)) { |
|
87 | + die('Error in get_not_created_links() : course code not set'); |
|
88 | + } |
|
89 | + |
|
90 | + $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
91 | + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
92 | + $session_id = api_get_session_id(); |
|
93 | + |
|
94 | + if ($session_id) { |
|
95 | + $session_condition = 'tl.session_id='.api_get_session_id(); |
|
96 | + } else { |
|
97 | + $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
98 | + } |
|
99 | + |
|
100 | + $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
101 | 101 | FROM '.$tbl_grade_links.' tl INNER JOIN '.$tbl_item_property.' ip |
102 | 102 | ON (tl.thread_id = ip.ref AND tl.c_id = ip.c_id) |
103 | 103 | WHERE |
@@ -108,23 +108,23 @@ discard block |
||
108 | 108 | '.$session_condition.' |
109 | 109 | '; |
110 | 110 | |
111 | - $result = Database::query($sql); |
|
112 | - while ($data = Database::fetch_array($result)) { |
|
113 | - if ( isset($data['thread_title_qualify']) && $data['thread_title_qualify'] != "") { |
|
114 | - $cats[] = array($data['thread_id'], $data['thread_title_qualify']); |
|
115 | - } else { |
|
116 | - $cats[] = array($data['thread_id'], $data['thread_title']); |
|
117 | - } |
|
118 | - } |
|
119 | - $my_cats = isset($cats) ? $cats : null; |
|
111 | + $result = Database::query($sql); |
|
112 | + while ($data = Database::fetch_array($result)) { |
|
113 | + if ( isset($data['thread_title_qualify']) && $data['thread_title_qualify'] != "") { |
|
114 | + $cats[] = array($data['thread_id'], $data['thread_title_qualify']); |
|
115 | + } else { |
|
116 | + $cats[] = array($data['thread_id'], $data['thread_title']); |
|
117 | + } |
|
118 | + } |
|
119 | + $my_cats = isset($cats) ? $cats : null; |
|
120 | 120 | |
121 | - return $my_cats; |
|
122 | - } |
|
121 | + return $my_cats; |
|
122 | + } |
|
123 | 123 | |
124 | 124 | /** |
125 | - * Has anyone done this exercise yet ? |
|
126 | - * @return boolean |
|
127 | - */ |
|
125 | + * Has anyone done this exercise yet ? |
|
126 | + * @return boolean |
|
127 | + */ |
|
128 | 128 | public function has_results() |
129 | 129 | { |
130 | 130 | $table = Database :: get_course_table(TABLE_FORUM_POST); |
@@ -138,50 +138,50 @@ discard block |
||
138 | 138 | $number = Database::fetch_row($result); |
139 | 139 | |
140 | 140 | return $number[0] != 0; |
141 | - } |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * @param int $stud_id |
|
143 | + /** |
|
144 | + * @param int $stud_id |
|
145 | 145 | * @param string $type |
146 | 146 | * |
147 | - * @return array|null |
|
148 | - */ |
|
149 | - public function calc_score($stud_id = null, $type = null) |
|
150 | - { |
|
147 | + * @return array|null |
|
148 | + */ |
|
149 | + public function calc_score($stud_id = null, $type = null) |
|
150 | + { |
|
151 | 151 | require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
152 | 152 | $threadInfo = get_thread_information('', $this->get_ref_id()); |
153 | 153 | |
154 | - $thread_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
154 | + $thread_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
155 | 155 | |
156 | 156 | $sessionId = $this->get_session_id(); |
157 | 157 | $sessionCondition = api_get_session_condition($sessionId, true, false, 'session_id'); |
158 | 158 | |
159 | - $sql = 'SELECT thread_qualify_max |
|
159 | + $sql = 'SELECT thread_qualify_max |
|
160 | 160 | FROM '.Database :: get_course_table(TABLE_FORUM_THREAD)." |
161 | 161 | WHERE |
162 | 162 | c_id = ".$this->course_id." AND |
163 | 163 | thread_id = '".$this->get_ref_id()."' |
164 | 164 | $sessionCondition |
165 | 165 | "; |
166 | - $query = Database::query($sql); |
|
167 | - $assignment = Database::fetch_array($query); |
|
166 | + $query = Database::query($sql); |
|
167 | + $assignment = Database::fetch_array($query); |
|
168 | 168 | |
169 | - $sql = "SELECT * FROM $thread_qualify |
|
169 | + $sql = "SELECT * FROM $thread_qualify |
|
170 | 170 | WHERE |
171 | 171 | c_id = ".$this->course_id." AND |
172 | 172 | thread_id = ".$this->get_ref_id()." |
173 | 173 | $sessionCondition |
174 | 174 | "; |
175 | - if (isset($stud_id)) { |
|
176 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
177 | - } |
|
175 | + if (isset($stud_id)) { |
|
176 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
177 | + } |
|
178 | 178 | |
179 | - // order by id, that way the student's first attempt is accessed first |
|
180 | - $sql .= ' ORDER BY qualify_time DESC'; |
|
181 | - $scores = Database::query($sql); |
|
179 | + // order by id, that way the student's first attempt is accessed first |
|
180 | + $sql .= ' ORDER BY qualify_time DESC'; |
|
181 | + $scores = Database::query($sql); |
|
182 | 182 | |
183 | - // for 1 student |
|
184 | - if (isset($stud_id)) { |
|
183 | + // for 1 student |
|
184 | + if (isset($stud_id)) { |
|
185 | 185 | if ($threadInfo['thread_peer_qualify'] == 0) { |
186 | 186 | // Classic way of calculate score |
187 | 187 | if ($data = Database::fetch_array($scores)) { |
@@ -209,175 +209,175 @@ discard block |
||
209 | 209 | } |
210 | 210 | return [$score/$counter, $assignment['thread_qualify_max']]; |
211 | 211 | } |
212 | - } else { |
|
213 | - // All students -> get average |
|
214 | - $students = array(); // user list, needed to make sure we only |
|
215 | - // take first attempts into account |
|
216 | - $counter = 0; |
|
217 | - $sum = 0; |
|
218 | - $bestResult = 0; |
|
219 | - $weight = 0; |
|
220 | - $sumResult = 0; |
|
221 | - |
|
222 | - while ($data = Database::fetch_array($scores)) { |
|
223 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
224 | - if ($assignment['thread_qualify_max'] != 0) { |
|
225 | - $students[$data['user_id']] = $data['qualify']; |
|
226 | - $counter++; |
|
227 | - $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
228 | - $sumResult += $data['qualify']; |
|
229 | - if ($data['qualify'] > $bestResult) { |
|
230 | - $bestResult = $data['qualify']; |
|
231 | - } |
|
232 | - $weight = $assignment['thread_qualify_max']; |
|
233 | - } |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - if ($counter == 0) { |
|
238 | - return null; |
|
239 | - } else { |
|
240 | - switch ($type) { |
|
241 | - case 'best': |
|
242 | - return array($bestResult, $weight); |
|
243 | - break; |
|
244 | - case 'average': |
|
245 | - return array($sumResult/$counter, $weight); |
|
246 | - break; |
|
247 | - case 'ranking': |
|
248 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
249 | - break; |
|
250 | - default: |
|
251 | - return array($sum, $counter); |
|
252 | - break; |
|
253 | - } |
|
254 | - } |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Lazy load function to get the database table of the student publications |
|
260 | - */ |
|
261 | - private function get_forum_thread_table() |
|
262 | - { |
|
263 | - return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
264 | - } |
|
265 | - |
|
266 | - public function needs_name_and_description() |
|
267 | - { |
|
268 | - return false; |
|
269 | - } |
|
270 | - |
|
271 | - public function needs_max() |
|
272 | - { |
|
273 | - return false; |
|
274 | - } |
|
275 | - |
|
276 | - public function needs_results() |
|
277 | - { |
|
278 | - return false; |
|
279 | - } |
|
212 | + } else { |
|
213 | + // All students -> get average |
|
214 | + $students = array(); // user list, needed to make sure we only |
|
215 | + // take first attempts into account |
|
216 | + $counter = 0; |
|
217 | + $sum = 0; |
|
218 | + $bestResult = 0; |
|
219 | + $weight = 0; |
|
220 | + $sumResult = 0; |
|
221 | + |
|
222 | + while ($data = Database::fetch_array($scores)) { |
|
223 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
224 | + if ($assignment['thread_qualify_max'] != 0) { |
|
225 | + $students[$data['user_id']] = $data['qualify']; |
|
226 | + $counter++; |
|
227 | + $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
228 | + $sumResult += $data['qualify']; |
|
229 | + if ($data['qualify'] > $bestResult) { |
|
230 | + $bestResult = $data['qualify']; |
|
231 | + } |
|
232 | + $weight = $assignment['thread_qualify_max']; |
|
233 | + } |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + if ($counter == 0) { |
|
238 | + return null; |
|
239 | + } else { |
|
240 | + switch ($type) { |
|
241 | + case 'best': |
|
242 | + return array($bestResult, $weight); |
|
243 | + break; |
|
244 | + case 'average': |
|
245 | + return array($sumResult/$counter, $weight); |
|
246 | + break; |
|
247 | + case 'ranking': |
|
248 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
249 | + break; |
|
250 | + default: |
|
251 | + return array($sum, $counter); |
|
252 | + break; |
|
253 | + } |
|
254 | + } |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Lazy load function to get the database table of the student publications |
|
260 | + */ |
|
261 | + private function get_forum_thread_table() |
|
262 | + { |
|
263 | + return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
264 | + } |
|
265 | + |
|
266 | + public function needs_name_and_description() |
|
267 | + { |
|
268 | + return false; |
|
269 | + } |
|
270 | + |
|
271 | + public function needs_max() |
|
272 | + { |
|
273 | + return false; |
|
274 | + } |
|
275 | + |
|
276 | + public function needs_results() |
|
277 | + { |
|
278 | + return false; |
|
279 | + } |
|
280 | 280 | |
281 | 281 | /** |
282 | 282 | * @return string |
283 | 283 | */ |
284 | - public function get_name() |
|
285 | - { |
|
286 | - $this->get_exercise_data(); |
|
287 | - $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
288 | - $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
289 | - if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
290 | - return $this->exercise_data['thread_title_qualify']; |
|
291 | - } else { |
|
292 | - return $thread_title; |
|
293 | - } |
|
294 | - } |
|
284 | + public function get_name() |
|
285 | + { |
|
286 | + $this->get_exercise_data(); |
|
287 | + $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
288 | + $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
289 | + if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
290 | + return $this->exercise_data['thread_title_qualify']; |
|
291 | + } else { |
|
292 | + return $thread_title; |
|
293 | + } |
|
294 | + } |
|
295 | 295 | |
296 | 296 | /** |
297 | 297 | * @return string |
298 | 298 | */ |
299 | - public function get_description() |
|
300 | - { |
|
301 | - return '';//$this->exercise_data['description']; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Check if this still links to an exercise |
|
306 | - */ |
|
307 | - public function is_valid_link() |
|
308 | - { |
|
309 | - $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
299 | + public function get_description() |
|
300 | + { |
|
301 | + return '';//$this->exercise_data['description']; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Check if this still links to an exercise |
|
306 | + */ |
|
307 | + public function is_valid_link() |
|
308 | + { |
|
309 | + $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
310 | 310 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().''; |
311 | - $result = Database::query($sql); |
|
312 | - $number = Database::fetch_row($result); |
|
313 | - return ($number[0] != 0); |
|
314 | - } |
|
315 | - |
|
316 | - public function get_test_id() |
|
317 | - { |
|
318 | - return 'DEBUG:ID'; |
|
319 | - } |
|
320 | - |
|
321 | - public function get_link() |
|
322 | - { |
|
323 | - $sessionId = api_get_session_id(); |
|
324 | - //it was extracts the forum id |
|
325 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
311 | + $result = Database::query($sql); |
|
312 | + $number = Database::fetch_row($result); |
|
313 | + return ($number[0] != 0); |
|
314 | + } |
|
315 | + |
|
316 | + public function get_test_id() |
|
317 | + { |
|
318 | + return 'DEBUG:ID'; |
|
319 | + } |
|
320 | + |
|
321 | + public function get_link() |
|
322 | + { |
|
323 | + $sessionId = api_get_session_id(); |
|
324 | + //it was extracts the forum id |
|
325 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
326 | 326 | WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id = ".$sessionId.""; |
327 | - $result = Database::query($sql); |
|
328 | - $row = Database::fetch_array($result,'ASSOC'); |
|
329 | - $forum_id=$row['forum_id']; |
|
330 | - |
|
331 | - $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?'.api_get_cidreq_params($this->get_course_code(), $sessionId).'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
332 | - return $url; |
|
333 | - } |
|
334 | - |
|
335 | - private function get_exercise_data() |
|
336 | - { |
|
337 | - $session_id = api_get_session_id(); |
|
338 | - if ($session_id) { |
|
339 | - $session_condition = 'session_id='.api_get_session_id(); |
|
340 | - } else { |
|
341 | - $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
342 | - } |
|
343 | - |
|
344 | - if (!isset($this->exercise_data)) { |
|
345 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
327 | + $result = Database::query($sql); |
|
328 | + $row = Database::fetch_array($result,'ASSOC'); |
|
329 | + $forum_id=$row['forum_id']; |
|
330 | + |
|
331 | + $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?'.api_get_cidreq_params($this->get_course_code(), $sessionId).'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
332 | + return $url; |
|
333 | + } |
|
334 | + |
|
335 | + private function get_exercise_data() |
|
336 | + { |
|
337 | + $session_id = api_get_session_id(); |
|
338 | + if ($session_id) { |
|
339 | + $session_condition = 'session_id='.api_get_session_id(); |
|
340 | + } else { |
|
341 | + $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
342 | + } |
|
343 | + |
|
344 | + if (!isset($this->exercise_data)) { |
|
345 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
346 | 346 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND '.$session_condition; |
347 | - $query = Database::query($sql); |
|
348 | - $this->exercise_data = Database::fetch_array($query); |
|
349 | - } |
|
350 | - return $this->exercise_data; |
|
351 | - } |
|
352 | - |
|
353 | - public function get_icon_name() |
|
354 | - { |
|
355 | - return 'forum'; |
|
356 | - } |
|
357 | - |
|
358 | - function save_linked_data() |
|
359 | - { |
|
360 | - $weight = (float)$this->get_weight(); |
|
361 | - $ref_id = $this->get_ref_id(); |
|
362 | - |
|
363 | - if (!empty($ref_id)) { |
|
364 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
347 | + $query = Database::query($sql); |
|
348 | + $this->exercise_data = Database::fetch_array($query); |
|
349 | + } |
|
350 | + return $this->exercise_data; |
|
351 | + } |
|
352 | + |
|
353 | + public function get_icon_name() |
|
354 | + { |
|
355 | + return 'forum'; |
|
356 | + } |
|
357 | + |
|
358 | + function save_linked_data() |
|
359 | + { |
|
360 | + $weight = (float)$this->get_weight(); |
|
361 | + $ref_id = $this->get_ref_id(); |
|
362 | + |
|
363 | + if (!empty($ref_id)) { |
|
364 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
365 | 365 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
366 | - Database::query($sql); |
|
367 | - } |
|
368 | - } |
|
369 | - |
|
370 | - function delete_linked_data() |
|
371 | - { |
|
372 | - $ref_id = $this->get_ref_id(); |
|
373 | - if (!empty($ref_id)) { |
|
374 | - //Cleans forum |
|
375 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
366 | + Database::query($sql); |
|
367 | + } |
|
368 | + } |
|
369 | + |
|
370 | + function delete_linked_data() |
|
371 | + { |
|
372 | + $ref_id = $this->get_ref_id(); |
|
373 | + if (!empty($ref_id)) { |
|
374 | + //Cleans forum |
|
375 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
376 | 376 | thread_qualify_max = 0, |
377 | 377 | thread_weight = 0, |
378 | 378 | thread_title_qualify = "" |
379 | 379 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
380 | - Database::query($sql); |
|
381 | - } |
|
382 | - } |
|
380 | + Database::query($sql); |
|
381 | + } |
|
382 | + } |
|
383 | 383 | } |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | //Event::event_download($doc_url); |
24 | 24 | if (isset($_course['path'])) { |
25 | 25 | $course_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; |
26 | - $full_file_name = $course_path.Security::remove_XSS($doc_url); |
|
26 | + $full_file_name = $course_path.Security::remove_XSS($doc_url); |
|
27 | 27 | } else { |
28 | 28 | $course_path = api_get_path(SYS_COURSE_PATH).$cid.'/document'; |
29 | - $full_file_name = $course_path.Security::remove_XSS($doc_url); |
|
29 | + $full_file_name = $course_path.Security::remove_XSS($doc_url); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | if(!is_file($full_file_name)) { |
33 | - exit; |
|
33 | + exit; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | if (!Security::check_abs_path($full_file_name, $course_path.'/')) { |
@@ -41,16 +41,16 @@ discard block |
||
41 | 41 | $extension=strtolower($extension[sizeof($extension)-1]); |
42 | 42 | |
43 | 43 | switch($extension) { |
44 | - case 'gz': $content_type='application/x-gzip'; break; |
|
45 | - case 'zip': $content_type='application/zip'; break; |
|
46 | - case 'pdf': $content_type='application/pdf'; break; |
|
47 | - case 'png': $content_type='image/png'; break; |
|
48 | - case 'gif': $content_type='image/gif'; break; |
|
49 | - case 'jpg': $content_type='image/jpeg'; break; |
|
50 | - case 'txt': $content_type='text/plain'; break; |
|
51 | - case 'htm': $content_type='text/html'; break; |
|
52 | - case 'html': $content_type='text/html'; break; |
|
53 | - default: $content_type='application/octet-stream'; break; |
|
44 | + case 'gz': $content_type='application/x-gzip'; break; |
|
45 | + case 'zip': $content_type='application/zip'; break; |
|
46 | + case 'pdf': $content_type='application/pdf'; break; |
|
47 | + case 'png': $content_type='image/png'; break; |
|
48 | + case 'gif': $content_type='image/gif'; break; |
|
49 | + case 'jpg': $content_type='image/jpeg'; break; |
|
50 | + case 'txt': $content_type='text/plain'; break; |
|
51 | + case 'htm': $content_type='text/html'; break; |
|
52 | + case 'html': $content_type='text/html'; break; |
|
53 | + default: $content_type='application/octet-stream'; break; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | header('Content-disposition: filename='.$filename); |
@@ -68,30 +68,30 @@ discard block |
||
68 | 68 | */ |
69 | 69 | |
70 | 70 | if ($content_type == 'text/html') { |
71 | - $directory_name = dirname($full_file_name); |
|
71 | + $directory_name = dirname($full_file_name); |
|
72 | 72 | |
73 | - $dir=str_replace(array('\\',$_configuration['root_sys']."courses/".$_course['path'].'/document'),array('/',''),$directory_name); |
|
73 | + $dir=str_replace(array('\\',$_configuration['root_sys']."courses/".$_course['path'].'/document'),array('/',''),$directory_name); |
|
74 | 74 | |
75 | - if($dir[strlen($dir)-1] != '/') { |
|
76 | - $dir.='/'; |
|
77 | - } |
|
75 | + if($dir[strlen($dir)-1] != '/') { |
|
76 | + $dir.='/'; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | - //Parse whole file at one |
|
81 | - $fp = fopen($full_file_name, "r"); |
|
82 | - $file_content = fread ($fp, filesize ($full_file_name)); |
|
83 | - fclose($fp); |
|
80 | + //Parse whole file at one |
|
81 | + $fp = fopen($full_file_name, "r"); |
|
82 | + $file_content = fread ($fp, filesize ($full_file_name)); |
|
83 | + fclose($fp); |
|
84 | 84 | $exercisePath = api_get_self(); |
85 | - $exfile = explode('/',$exercisePath); |
|
86 | - $exfile = $exfile[sizeof($exfile)-1]; |
|
87 | - $exercisePath = substr($exercisePath,0,strpos($exercisePath,$exfile)); |
|
88 | - $exercisePath = $exercisePath; |
|
85 | + $exfile = explode('/',$exercisePath); |
|
86 | + $exfile = $exfile[sizeof($exfile)-1]; |
|
87 | + $exercisePath = substr($exercisePath,0,strpos($exercisePath,$exfile)); |
|
88 | + $exercisePath = $exercisePath; |
|
89 | 89 | |
90 | - $content = $file_content; |
|
91 | - $mit = "function Finish(){"; |
|
90 | + $content = $file_content; |
|
91 | + $mit = "function Finish(){"; |
|
92 | 92 | |
93 | - $js_content = "var SaveScoreVariable = 0; // This variable included by Dokeos System\n". |
|
94 | - "function mySaveScore() // This function included by Dokeos System\n". |
|
93 | + $js_content = "var SaveScoreVariable = 0; // This variable included by Dokeos System\n". |
|
94 | + "function mySaveScore() // This function included by Dokeos System\n". |
|
95 | 95 | "{\n". |
96 | 96 | " if (SaveScoreVariable==0)\n". |
97 | 97 | " {\n". |
@@ -109,23 +109,23 @@ discard block |
||
109 | 109 | "// Must be included \n". |
110 | 110 | "function Finish(){\n". |
111 | 111 | " mySaveScore();"; |
112 | - $newcontent = str_replace($mit,$js_content,$content); |
|
112 | + $newcontent = str_replace($mit,$js_content,$content); |
|
113 | 113 | |
114 | - $prehref="javascript:void(0);"; |
|
115 | - $posthref = api_get_path(WEB_CODE_PATH) . "main/exercise/Hpdownload.php?doc_url=".$doc_url."&cid=".$cid."&uid=".$uid; |
|
116 | - $newcontent = str_replace($prehref,$posthref,$newcontent); |
|
114 | + $prehref="javascript:void(0);"; |
|
115 | + $posthref = api_get_path(WEB_CODE_PATH) . "main/exercise/Hpdownload.php?doc_url=".$doc_url."&cid=".$cid."&uid=".$uid; |
|
116 | + $newcontent = str_replace($prehref,$posthref,$newcontent); |
|
117 | 117 | |
118 | 118 | |
119 | - $prehref="class=\"GridNum\" onclick="; |
|
120 | - $posthref="class=\"GridNum\" onMouseover="; |
|
121 | - $newcontent = str_replace($prehref,$posthref,$newcontent); |
|
119 | + $prehref="class=\"GridNum\" onclick="; |
|
120 | + $posthref="class=\"GridNum\" onMouseover="; |
|
121 | + $newcontent = str_replace($prehref,$posthref,$newcontent); |
|
122 | 122 | |
123 | 123 | |
124 | - header('Content-length: '.strlen($newcontent)); |
|
125 | - // Dipsp. |
|
126 | - echo $newcontent; |
|
124 | + header('Content-length: '.strlen($newcontent)); |
|
125 | + // Dipsp. |
|
126 | + echo $newcontent; |
|
127 | 127 | |
128 | - exit(); |
|
128 | + exit(); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | //normal case, all non-html files |
@@ -82,12 +82,12 @@ discard block |
||
82 | 82 | */ |
83 | 83 | interface WSCMErrorHandler |
84 | 84 | { |
85 | - /** |
|
86 | - * Handle method |
|
87 | - * |
|
88 | - * @param WSError Error |
|
89 | - */ |
|
90 | - public function handle($error); |
|
85 | + /** |
|
86 | + * Handle method |
|
87 | + * |
|
88 | + * @param WSError Error |
|
89 | + */ |
|
90 | + public function handle($error); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -95,57 +95,57 @@ discard block |
||
95 | 95 | */ |
96 | 96 | class WSCM |
97 | 97 | { |
98 | - /** |
|
99 | - * Chamilo configuration |
|
100 | - * |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - protected $_configuration; |
|
98 | + /** |
|
99 | + * Chamilo configuration |
|
100 | + * |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + protected $_configuration; |
|
104 | 104 | |
105 | - /** |
|
106 | - * Constructor |
|
107 | - */ |
|
108 | - public function __construct() |
|
105 | + /** |
|
106 | + * Constructor |
|
107 | + */ |
|
108 | + public function __construct() |
|
109 | 109 | { |
110 | - $this->_configuration = $GLOBALS['_configuration']; |
|
111 | - } |
|
110 | + $this->_configuration = $GLOBALS['_configuration']; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Verifies the API key |
|
115 | - * |
|
116 | - * @param string Secret key |
|
117 | - * @return mixed WSError in case of failure, null in case of success |
|
118 | - */ |
|
119 | - protected function verifyKey($secret_key) |
|
113 | + /** |
|
114 | + * Verifies the API key |
|
115 | + * |
|
116 | + * @param string Secret key |
|
117 | + * @return mixed WSError in case of failure, null in case of success |
|
118 | + */ |
|
119 | + protected function verifyKey($secret_key) |
|
120 | 120 | { |
121 | - $ip = trim($_SERVER['REMOTE_ADDR']); |
|
122 | - // if we are behind a reverse proxy, assume it will send the |
|
123 | - // HTTP_X_FORWARDED_FOR header and use this IP instead |
|
124 | - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
125 | - list($ip1,$ip2) = split(',',$_SERVER['HTTP_X_FORWARDED_FOR']); |
|
126 | - $ip = trim($ip1); |
|
127 | - } |
|
128 | - $security_key = $ip.$this->_configuration['security_key']; |
|
121 | + $ip = trim($_SERVER['REMOTE_ADDR']); |
|
122 | + // if we are behind a reverse proxy, assume it will send the |
|
123 | + // HTTP_X_FORWARDED_FOR header and use this IP instead |
|
124 | + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
125 | + list($ip1,$ip2) = split(',',$_SERVER['HTTP_X_FORWARDED_FOR']); |
|
126 | + $ip = trim($ip1); |
|
127 | + } |
|
128 | + $security_key = $ip.$this->_configuration['security_key']; |
|
129 | 129 | |
130 | - if(!api_is_valid_secret_key($secret_key, $security_key)) { |
|
131 | - return new WSCMError(1, "API key is invalid"); |
|
132 | - } else { |
|
133 | - return null; |
|
134 | - } |
|
135 | - } |
|
130 | + if(!api_is_valid_secret_key($secret_key, $security_key)) { |
|
131 | + return new WSCMError(1, "API key is invalid"); |
|
132 | + } else { |
|
133 | + return null; |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Verifies if the user is valid |
|
139 | - * |
|
140 | - * @param <String> $username of the user in chamilo |
|
141 | - * @param <String> $pass of the same user (in MD5 of SHA) |
|
142 | - * |
|
143 | - * return "valid" if username e password are correct! Else, return a message error |
|
144 | - */ |
|
145 | - public function verifyUserPass($username, $pass) |
|
137 | + /** |
|
138 | + * Verifies if the user is valid |
|
139 | + * |
|
140 | + * @param <String> $username of the user in chamilo |
|
141 | + * @param <String> $pass of the same user (in MD5 of SHA) |
|
142 | + * |
|
143 | + * return "valid" if username e password are correct! Else, return a message error |
|
144 | + */ |
|
145 | + public function verifyUserPass($username, $pass) |
|
146 | 146 | { |
147 | - $login = $username; |
|
148 | - $password = $pass; |
|
147 | + $login = $username; |
|
148 | + $password = $pass; |
|
149 | 149 | |
150 | 150 | $userRepo = UserManager::getRepository(); |
151 | 151 | /** @var User $uData */ |
@@ -178,17 +178,17 @@ discard block |
||
178 | 178 | } |
179 | 179 | } |
180 | 180 | return get_lang('InvalidId'); |
181 | - } |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Gets the real user id based on the user id field name and value. |
|
185 | - * Note that if the user id field name is "chamilo_user_id", it will use the user id |
|
186 | - * in the system database |
|
187 | - * |
|
188 | - * @param string User id field name |
|
189 | - * @param string User id value |
|
190 | - * @return mixed System user id if the user was found, WSError otherwise |
|
191 | - */ |
|
183 | + /** |
|
184 | + * Gets the real user id based on the user id field name and value. |
|
185 | + * Note that if the user id field name is "chamilo_user_id", it will use the user id |
|
186 | + * in the system database |
|
187 | + * |
|
188 | + * @param string User id field name |
|
189 | + * @param string User id value |
|
190 | + * @return mixed System user id if the user was found, WSError otherwise |
|
191 | + */ |
|
192 | 192 | protected function getUserId($user_id_field_name, $user_id_value) |
193 | 193 | { |
194 | 194 | if ($user_id_field_name == "chamilo_user_id") { |
@@ -210,16 +210,16 @@ discard block |
||
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
213 | - /** |
|
214 | - * Gets the real course id based on the course id field name and value. |
|
215 | - * Note that if the course id field name is "chamilo_course_id", it will use the course id |
|
216 | - * in the system database |
|
217 | - * |
|
218 | - * @param string Course id field name |
|
219 | - * @param string Course id value |
|
220 | - * @return mixed System course id if the course was found, WSError otherwise |
|
221 | - */ |
|
222 | - protected function getCourseId($course_id_field_name, $course_id_value) |
|
213 | + /** |
|
214 | + * Gets the real course id based on the course id field name and value. |
|
215 | + * Note that if the course id field name is "chamilo_course_id", it will use the course id |
|
216 | + * in the system database |
|
217 | + * |
|
218 | + * @param string Course id field name |
|
219 | + * @param string Course id value |
|
220 | + * @return mixed System course id if the course was found, WSError otherwise |
|
221 | + */ |
|
222 | + protected function getCourseId($course_id_field_name, $course_id_value) |
|
223 | 223 | { |
224 | 224 | if ($course_id_field_name == "chamilo_course_id") { |
225 | 225 | if (CourseManager::get_course_code_from_course_id($course_id_value) != null) { |
@@ -238,78 +238,78 @@ discard block |
||
238 | 238 | return $courseId; |
239 | 239 | } |
240 | 240 | } |
241 | - } |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * Gets the real session id based on the session id field name and value. |
|
245 | - * Note that if the session id field name is "chamilo_session_id", it will use the session id |
|
246 | - * in the system database |
|
247 | - * |
|
248 | - * @param string Session id field name |
|
249 | - * @param string Session id value |
|
250 | - * @return mixed System session id if the session was found, WSError otherwise |
|
251 | - */ |
|
252 | - protected function getSessionId($session_id_field_name, $session_id_value) |
|
253 | - { |
|
254 | - if ($session_id_field_name == "chamilo_session_id") { |
|
255 | - $session = SessionManager::fetch((int)$session_id_value); |
|
256 | - if(!empty($session)) { |
|
257 | - return intval($session_id_value); |
|
258 | - } else { |
|
259 | - return new WSCMError(300, "Session not found"); |
|
260 | - } |
|
261 | - } else { |
|
262 | - $session_id = SessionManager::getSessionIdFromOriginalId( |
|
263 | - $session_id_value, |
|
264 | - $session_id_field_name |
|
265 | - ); |
|
266 | - if($session_id == 0) { |
|
267 | - return new WSCMError(300, "Session not found"); |
|
268 | - } else { |
|
269 | - return $session_id; |
|
270 | - } |
|
271 | - } |
|
272 | - } |
|
243 | + /** |
|
244 | + * Gets the real session id based on the session id field name and value. |
|
245 | + * Note that if the session id field name is "chamilo_session_id", it will use the session id |
|
246 | + * in the system database |
|
247 | + * |
|
248 | + * @param string Session id field name |
|
249 | + * @param string Session id value |
|
250 | + * @return mixed System session id if the session was found, WSError otherwise |
|
251 | + */ |
|
252 | + protected function getSessionId($session_id_field_name, $session_id_value) |
|
253 | + { |
|
254 | + if ($session_id_field_name == "chamilo_session_id") { |
|
255 | + $session = SessionManager::fetch((int)$session_id_value); |
|
256 | + if(!empty($session)) { |
|
257 | + return intval($session_id_value); |
|
258 | + } else { |
|
259 | + return new WSCMError(300, "Session not found"); |
|
260 | + } |
|
261 | + } else { |
|
262 | + $session_id = SessionManager::getSessionIdFromOriginalId( |
|
263 | + $session_id_value, |
|
264 | + $session_id_field_name |
|
265 | + ); |
|
266 | + if($session_id == 0) { |
|
267 | + return new WSCMError(300, "Session not found"); |
|
268 | + } else { |
|
269 | + return $session_id; |
|
270 | + } |
|
271 | + } |
|
272 | + } |
|
273 | 273 | |
274 | - /** |
|
275 | - * Handles an error by calling the WSError error handler |
|
276 | - * |
|
277 | - * @param WSError Error |
|
278 | - */ |
|
279 | - protected function handleError($error) |
|
280 | - { |
|
281 | - $handler = WSCMError::getErrorHandler(); |
|
282 | - $handler->handle($error); |
|
283 | - } |
|
274 | + /** |
|
275 | + * Handles an error by calling the WSError error handler |
|
276 | + * |
|
277 | + * @param WSError Error |
|
278 | + */ |
|
279 | + protected function handleError($error) |
|
280 | + { |
|
281 | + $handler = WSCMError::getErrorHandler(); |
|
282 | + $handler->handle($error); |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * Gets a successful result |
|
287 | - * |
|
288 | - * @return array Array with a code of 0 and a message 'Operation was successful' |
|
289 | - */ |
|
290 | - protected function getSuccessfulResult() |
|
291 | - { |
|
292 | - return array('code' => 0, 'message' => 'Operation was successful'); |
|
293 | - } |
|
285 | + /** |
|
286 | + * Gets a successful result |
|
287 | + * |
|
288 | + * @return array Array with a code of 0 and a message 'Operation was successful' |
|
289 | + */ |
|
290 | + protected function getSuccessfulResult() |
|
291 | + { |
|
292 | + return array('code' => 0, 'message' => 'Operation was successful'); |
|
293 | + } |
|
294 | 294 | |
295 | - /** |
|
296 | - * Test function. Returns the string success |
|
297 | - * |
|
298 | - * @return string Success |
|
299 | - */ |
|
300 | - public function test() |
|
301 | - { |
|
302 | - return "success"; |
|
303 | - } |
|
295 | + /** |
|
296 | + * Test function. Returns the string success |
|
297 | + * |
|
298 | + * @return string Success |
|
299 | + */ |
|
300 | + public function test() |
|
301 | + { |
|
302 | + return "success"; |
|
303 | + } |
|
304 | 304 | |
305 | - /** |
|
306 | - * *Strictly* reverts PHP's nl2br() effects (whether it was used in XHTML mode or not) |
|
307 | - * @param <type> $string |
|
308 | - * @return <type> $string |
|
309 | - */ |
|
310 | - public function nl2br_revert($string) |
|
305 | + /** |
|
306 | + * *Strictly* reverts PHP's nl2br() effects (whether it was used in XHTML mode or not) |
|
307 | + * @param <type> $string |
|
308 | + * @return <type> $string |
|
309 | + */ |
|
310 | + public function nl2br_revert($string) |
|
311 | 311 | { |
312 | - return preg_replace('`<br(?: /)?>([\\n\\r])`', '$1', $string); |
|
313 | - } |
|
312 | + return preg_replace('`<br(?: /)?>([\\n\\r])`', '$1', $string); |
|
313 | + } |
|
314 | 314 | } |
315 | 315 |
@@ -13,21 +13,21 @@ discard block |
||
13 | 13 | |
14 | 14 | public function find_id_user($username, $password, $name) |
15 | 15 | { |
16 | - if ($this->verifyUserPass($username, $password) == "valid") { |
|
16 | + if ($this->verifyUserPass($username, $password) == "valid") { |
|
17 | 17 | $listResult = "#"; |
18 | 18 | |
19 | 19 | $listArrayResult = Array(); |
20 | 20 | $listArray = Array(); |
21 | 21 | |
22 | 22 | $list = $this->get_user_list_like_start(array('firstname'=>$name), array('firstname')); |
23 | - foreach ($list as $userData) { |
|
24 | - $listArray[] = $userData['user_id']; |
|
25 | - } |
|
23 | + foreach ($list as $userData) { |
|
24 | + $listArray[] = $userData['user_id']; |
|
25 | + } |
|
26 | 26 | |
27 | 27 | $list = $this->get_user_list_like_start(array('lastname'=>$name), array('firstname')); |
28 | - foreach ($list as $userData) { |
|
29 | - $listArray[] = $userData['user_id']; |
|
30 | - } |
|
28 | + foreach ($list as $userData) { |
|
29 | + $listArray[] = $userData['user_id']; |
|
30 | + } |
|
31 | 31 | |
32 | 32 | $list = $this->get_user_list_like_start(array('email'=>$name), array('firstname')); |
33 | 33 | foreach ($list as $userData) { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | { |
90 | 90 | global $charset; |
91 | 91 | if ($this->verifyUserPass($username, $password) == "valid") { |
92 | - $user_id = UserManager::get_user_id_from_username($username); |
|
92 | + $user_id = UserManager::get_user_id_from_username($username); |
|
93 | 93 | $message_title = get_lang('Invitation'); |
94 | 94 | $count_is_true = SocialManager::send_invitation_friend($user_id,$userfriend_id, $message_title, $content_message); |
95 | 95 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | |
130 | 130 | |
131 | 131 | /** |
132 | - * Get a list of users of which the given conditions match with a LIKE '%cond%' |
|
133 | - * @param array $conditions a list of condition (exemple : status=>STUDENT) |
|
134 | - * @param array $order_by a list of fields on which sort |
|
135 | - * @return array An array with all users of the platform. |
|
136 | - * @todo optional course code parameter, optional sorting parameters... |
|
132 | + * Get a list of users of which the given conditions match with a LIKE '%cond%' |
|
133 | + * @param array $conditions a list of condition (exemple : status=>STUDENT) |
|
134 | + * @param array $order_by a list of fields on which sort |
|
135 | + * @return array An array with all users of the platform. |
|
136 | + * @todo optional course code parameter, optional sorting parameters... |
|
137 | 137 | *@todo Use the UserManager class |
138 | 138 | * @todo security filter order by |
139 | - */ |
|
139 | + */ |
|
140 | 140 | private static function get_user_list_like_start($conditions = array(), $order_by = array()) |
141 | 141 | { |
142 | 142 | $user_table = Database :: get_main_table(TABLE_MAIN_USER); |
@@ -195,7 +195,7 @@ |
||
195 | 195 | $parentId = !$assignment ? 0 : $assignment->getId(); |
196 | 196 | |
197 | 197 | if (empty($session)) { |
198 | - $dql = 'SELECT a FROM ChamiloCourseBundle:CStudentPublication a |
|
198 | + $dql = 'SELECT a FROM ChamiloCourseBundle:CStudentPublication a |
|
199 | 199 | WHERE |
200 | 200 | a.cId = :course AND |
201 | 201 | a.active = :active AND |
@@ -9,365 +9,365 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class Evaluation implements GradebookItem |
11 | 11 | { |
12 | - private $id; |
|
13 | - private $name; |
|
14 | - private $description; |
|
15 | - private $user_id; |
|
16 | - private $course_code; |
|
17 | - /** @var Category */ |
|
18 | - private $category; |
|
19 | - private $created_at; |
|
20 | - private $weight; |
|
21 | - private $eval_max; |
|
22 | - private $visible; |
|
23 | - private $sessionId; |
|
24 | - public $studentList; |
|
25 | - |
|
26 | - /** |
|
27 | - * Construct |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return Category |
|
35 | - */ |
|
36 | - public function getCategory() |
|
37 | - { |
|
38 | - return $this->category; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @param Category $category |
|
43 | - */ |
|
44 | - public function setCategory($category) |
|
45 | - { |
|
46 | - $this->category = $category; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @return int |
|
51 | - */ |
|
52 | - public function get_category_id() |
|
53 | - { |
|
54 | - return $this->category->get_id(); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param int $category_id |
|
59 | - */ |
|
60 | - public function set_category_id($category_id) |
|
61 | - { |
|
62 | - $categories = Category::load($category_id); |
|
63 | - if (isset($categories[0])) { |
|
64 | - $this->setCategory($categories[0]); |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return int |
|
70 | - */ |
|
71 | - public function get_id() |
|
72 | - { |
|
73 | - return $this->id; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function get_name() |
|
80 | - { |
|
81 | - return $this->name; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function get_description() |
|
88 | - { |
|
89 | - return $this->description; |
|
90 | - } |
|
91 | - |
|
92 | - public function get_user_id() |
|
93 | - { |
|
94 | - return $this->user_id; |
|
95 | - } |
|
96 | - |
|
97 | - public function get_course_code() |
|
98 | - { |
|
99 | - return $this->course_code; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return int |
|
104 | - */ |
|
105 | - public function getSessionId() |
|
106 | - { |
|
107 | - return $this->sessionId; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @param int $sessionId |
|
112 | - */ |
|
113 | - public function setSessionId($sessionId) |
|
114 | - { |
|
115 | - $this->sessionId = intval($sessionId); |
|
116 | - } |
|
117 | - |
|
118 | - public function get_date() |
|
119 | - { |
|
120 | - return $this->created_at; |
|
121 | - } |
|
122 | - |
|
123 | - public function get_weight() |
|
124 | - { |
|
125 | - return $this->weight; |
|
126 | - } |
|
127 | - |
|
128 | - public function get_max() |
|
129 | - { |
|
130 | - return $this->eval_max; |
|
131 | - } |
|
132 | - |
|
133 | - public function get_type() |
|
134 | - { |
|
135 | - return $this->type; |
|
136 | - } |
|
137 | - |
|
138 | - public function is_visible() |
|
139 | - { |
|
140 | - return $this->visible; |
|
141 | - } |
|
142 | - |
|
143 | - public function get_locked() |
|
144 | - { |
|
145 | - return $this->locked; |
|
146 | - } |
|
147 | - |
|
148 | - public function is_locked() |
|
149 | - { |
|
150 | - return isset($this->locked) && $this->locked == 1 ? true : false; |
|
151 | - } |
|
152 | - |
|
153 | - public function set_id($id) |
|
154 | - { |
|
155 | - $this->id = $id; |
|
156 | - } |
|
157 | - |
|
158 | - public function set_name($name) |
|
159 | - { |
|
160 | - $this->name = $name; |
|
161 | - } |
|
162 | - |
|
163 | - public function set_description($description) |
|
164 | - { |
|
165 | - $this->description = $description; |
|
166 | - } |
|
167 | - |
|
168 | - public function set_user_id($user_id) |
|
169 | - { |
|
170 | - $this->user_id = $user_id; |
|
171 | - } |
|
172 | - |
|
173 | - public function set_course_code($course_code) |
|
174 | - { |
|
175 | - $this->course_code = $course_code; |
|
176 | - } |
|
177 | - |
|
178 | - public function set_date($date) |
|
179 | - { |
|
180 | - $this->created_at = $date; |
|
181 | - } |
|
182 | - |
|
183 | - public function set_weight($weight) |
|
184 | - { |
|
185 | - $this->weight = $weight; |
|
186 | - } |
|
187 | - |
|
188 | - public function set_max($max) |
|
189 | - { |
|
190 | - $this->eval_max = $max; |
|
191 | - } |
|
192 | - |
|
193 | - public function set_visible($visible) |
|
194 | - { |
|
195 | - $this->visible = $visible; |
|
196 | - } |
|
197 | - |
|
198 | - public function set_type($type) |
|
199 | - { |
|
200 | - $this->type = $type; |
|
201 | - } |
|
202 | - |
|
203 | - public function set_locked($locked) |
|
204 | - { |
|
205 | - $this->locked = $locked; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Retrieve evaluations and return them as an array of Evaluation objects |
|
210 | - * @param int $id evaluation id |
|
211 | - * @param int $user_id user id (evaluation owner) |
|
212 | - * @param string $course_code course code |
|
213 | - * @param int $category_id parent category |
|
214 | - * @param integer $visible visible |
|
215 | - */ |
|
216 | - public static function load( |
|
217 | - $id = null, |
|
218 | - $user_id = null, |
|
219 | - $course_code = null, |
|
220 | - $category_id = null, |
|
221 | - $visible = null, |
|
222 | - $locked = null |
|
223 | - ) { |
|
224 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
225 | - $sql = 'SELECT * FROM '.$tbl_grade_evaluations; |
|
226 | - $paramcount = 0; |
|
227 | - |
|
228 | - if (isset ($id)) { |
|
229 | - $sql.= ' WHERE id = '.intval($id); |
|
230 | - $paramcount ++; |
|
231 | - } |
|
232 | - |
|
233 | - if (isset($user_id)) { |
|
234 | - if ($paramcount != 0) $sql .= ' AND'; |
|
235 | - else $sql .= ' WHERE'; |
|
236 | - $sql .= ' user_id = '.intval($user_id); |
|
237 | - $paramcount ++; |
|
238 | - } |
|
239 | - |
|
240 | - if (isset($course_code) && $course_code <> '-1') { |
|
241 | - if ($paramcount != 0) $sql .= ' AND'; |
|
242 | - else $sql .= ' WHERE'; |
|
243 | - $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
|
244 | - $paramcount ++; |
|
245 | - } |
|
246 | - |
|
247 | - if (isset($category_id)) { |
|
248 | - if ($paramcount != 0) $sql .= ' AND'; |
|
249 | - else $sql .= ' WHERE'; |
|
250 | - $sql .= ' category_id = '.intval($category_id); |
|
251 | - $paramcount ++; |
|
252 | - } |
|
253 | - |
|
254 | - if (isset($visible)) { |
|
255 | - if ($paramcount != 0) $sql .= ' AND'; |
|
256 | - else $sql .= ' WHERE'; |
|
257 | - $sql .= ' visible = '.intval($visible); |
|
258 | - $paramcount ++; |
|
259 | - } |
|
260 | - |
|
261 | - if (isset($locked)) { |
|
262 | - if ($paramcount != 0) $sql .= ' AND'; |
|
263 | - else $sql .= ' WHERE'; |
|
264 | - $sql .= ' locked = '.intval($locked); |
|
265 | - } |
|
266 | - |
|
267 | - $result = Database::query($sql); |
|
268 | - $allEval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
269 | - |
|
270 | - return $allEval; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * @param array $result |
|
275 | - * @return array |
|
276 | - */ |
|
277 | - private static function create_evaluation_objects_from_sql_result($result) |
|
278 | - { |
|
279 | - $alleval = array(); |
|
280 | - if (Database::num_rows($result)) { |
|
281 | - while ($data = Database::fetch_array($result)) { |
|
282 | - $eval= new Evaluation(); |
|
283 | - $eval->set_id($data['id']); |
|
284 | - $eval->set_name($data['name']); |
|
285 | - $eval->set_description($data['description']); |
|
286 | - $eval->set_user_id($data['user_id']); |
|
287 | - $eval->set_course_code($data['course_code']); |
|
288 | - $eval->set_category_id($data['category_id']); |
|
289 | - $eval->set_date(api_get_local_time($data['created_at'])); |
|
290 | - $eval->set_weight($data['weight']); |
|
291 | - $eval->set_max($data['max']); |
|
292 | - $eval->set_visible($data['visible']); |
|
293 | - $eval->set_type($data['type']); |
|
294 | - $eval->set_locked($data['locked']); |
|
295 | - $eval->setSessionId(api_get_session_id()); |
|
296 | - |
|
297 | - $alleval[] = $eval; |
|
298 | - } |
|
299 | - } |
|
300 | - |
|
301 | - return $alleval; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Insert this evaluation into the database |
|
306 | - */ |
|
12 | + private $id; |
|
13 | + private $name; |
|
14 | + private $description; |
|
15 | + private $user_id; |
|
16 | + private $course_code; |
|
17 | + /** @var Category */ |
|
18 | + private $category; |
|
19 | + private $created_at; |
|
20 | + private $weight; |
|
21 | + private $eval_max; |
|
22 | + private $visible; |
|
23 | + private $sessionId; |
|
24 | + public $studentList; |
|
25 | + |
|
26 | + /** |
|
27 | + * Construct |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return Category |
|
35 | + */ |
|
36 | + public function getCategory() |
|
37 | + { |
|
38 | + return $this->category; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @param Category $category |
|
43 | + */ |
|
44 | + public function setCategory($category) |
|
45 | + { |
|
46 | + $this->category = $category; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @return int |
|
51 | + */ |
|
52 | + public function get_category_id() |
|
53 | + { |
|
54 | + return $this->category->get_id(); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param int $category_id |
|
59 | + */ |
|
60 | + public function set_category_id($category_id) |
|
61 | + { |
|
62 | + $categories = Category::load($category_id); |
|
63 | + if (isset($categories[0])) { |
|
64 | + $this->setCategory($categories[0]); |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return int |
|
70 | + */ |
|
71 | + public function get_id() |
|
72 | + { |
|
73 | + return $this->id; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function get_name() |
|
80 | + { |
|
81 | + return $this->name; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function get_description() |
|
88 | + { |
|
89 | + return $this->description; |
|
90 | + } |
|
91 | + |
|
92 | + public function get_user_id() |
|
93 | + { |
|
94 | + return $this->user_id; |
|
95 | + } |
|
96 | + |
|
97 | + public function get_course_code() |
|
98 | + { |
|
99 | + return $this->course_code; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return int |
|
104 | + */ |
|
105 | + public function getSessionId() |
|
106 | + { |
|
107 | + return $this->sessionId; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @param int $sessionId |
|
112 | + */ |
|
113 | + public function setSessionId($sessionId) |
|
114 | + { |
|
115 | + $this->sessionId = intval($sessionId); |
|
116 | + } |
|
117 | + |
|
118 | + public function get_date() |
|
119 | + { |
|
120 | + return $this->created_at; |
|
121 | + } |
|
122 | + |
|
123 | + public function get_weight() |
|
124 | + { |
|
125 | + return $this->weight; |
|
126 | + } |
|
127 | + |
|
128 | + public function get_max() |
|
129 | + { |
|
130 | + return $this->eval_max; |
|
131 | + } |
|
132 | + |
|
133 | + public function get_type() |
|
134 | + { |
|
135 | + return $this->type; |
|
136 | + } |
|
137 | + |
|
138 | + public function is_visible() |
|
139 | + { |
|
140 | + return $this->visible; |
|
141 | + } |
|
142 | + |
|
143 | + public function get_locked() |
|
144 | + { |
|
145 | + return $this->locked; |
|
146 | + } |
|
147 | + |
|
148 | + public function is_locked() |
|
149 | + { |
|
150 | + return isset($this->locked) && $this->locked == 1 ? true : false; |
|
151 | + } |
|
152 | + |
|
153 | + public function set_id($id) |
|
154 | + { |
|
155 | + $this->id = $id; |
|
156 | + } |
|
157 | + |
|
158 | + public function set_name($name) |
|
159 | + { |
|
160 | + $this->name = $name; |
|
161 | + } |
|
162 | + |
|
163 | + public function set_description($description) |
|
164 | + { |
|
165 | + $this->description = $description; |
|
166 | + } |
|
167 | + |
|
168 | + public function set_user_id($user_id) |
|
169 | + { |
|
170 | + $this->user_id = $user_id; |
|
171 | + } |
|
172 | + |
|
173 | + public function set_course_code($course_code) |
|
174 | + { |
|
175 | + $this->course_code = $course_code; |
|
176 | + } |
|
177 | + |
|
178 | + public function set_date($date) |
|
179 | + { |
|
180 | + $this->created_at = $date; |
|
181 | + } |
|
182 | + |
|
183 | + public function set_weight($weight) |
|
184 | + { |
|
185 | + $this->weight = $weight; |
|
186 | + } |
|
187 | + |
|
188 | + public function set_max($max) |
|
189 | + { |
|
190 | + $this->eval_max = $max; |
|
191 | + } |
|
192 | + |
|
193 | + public function set_visible($visible) |
|
194 | + { |
|
195 | + $this->visible = $visible; |
|
196 | + } |
|
197 | + |
|
198 | + public function set_type($type) |
|
199 | + { |
|
200 | + $this->type = $type; |
|
201 | + } |
|
202 | + |
|
203 | + public function set_locked($locked) |
|
204 | + { |
|
205 | + $this->locked = $locked; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Retrieve evaluations and return them as an array of Evaluation objects |
|
210 | + * @param int $id evaluation id |
|
211 | + * @param int $user_id user id (evaluation owner) |
|
212 | + * @param string $course_code course code |
|
213 | + * @param int $category_id parent category |
|
214 | + * @param integer $visible visible |
|
215 | + */ |
|
216 | + public static function load( |
|
217 | + $id = null, |
|
218 | + $user_id = null, |
|
219 | + $course_code = null, |
|
220 | + $category_id = null, |
|
221 | + $visible = null, |
|
222 | + $locked = null |
|
223 | + ) { |
|
224 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
225 | + $sql = 'SELECT * FROM '.$tbl_grade_evaluations; |
|
226 | + $paramcount = 0; |
|
227 | + |
|
228 | + if (isset ($id)) { |
|
229 | + $sql.= ' WHERE id = '.intval($id); |
|
230 | + $paramcount ++; |
|
231 | + } |
|
232 | + |
|
233 | + if (isset($user_id)) { |
|
234 | + if ($paramcount != 0) $sql .= ' AND'; |
|
235 | + else $sql .= ' WHERE'; |
|
236 | + $sql .= ' user_id = '.intval($user_id); |
|
237 | + $paramcount ++; |
|
238 | + } |
|
239 | + |
|
240 | + if (isset($course_code) && $course_code <> '-1') { |
|
241 | + if ($paramcount != 0) $sql .= ' AND'; |
|
242 | + else $sql .= ' WHERE'; |
|
243 | + $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
|
244 | + $paramcount ++; |
|
245 | + } |
|
246 | + |
|
247 | + if (isset($category_id)) { |
|
248 | + if ($paramcount != 0) $sql .= ' AND'; |
|
249 | + else $sql .= ' WHERE'; |
|
250 | + $sql .= ' category_id = '.intval($category_id); |
|
251 | + $paramcount ++; |
|
252 | + } |
|
253 | + |
|
254 | + if (isset($visible)) { |
|
255 | + if ($paramcount != 0) $sql .= ' AND'; |
|
256 | + else $sql .= ' WHERE'; |
|
257 | + $sql .= ' visible = '.intval($visible); |
|
258 | + $paramcount ++; |
|
259 | + } |
|
260 | + |
|
261 | + if (isset($locked)) { |
|
262 | + if ($paramcount != 0) $sql .= ' AND'; |
|
263 | + else $sql .= ' WHERE'; |
|
264 | + $sql .= ' locked = '.intval($locked); |
|
265 | + } |
|
266 | + |
|
267 | + $result = Database::query($sql); |
|
268 | + $allEval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
269 | + |
|
270 | + return $allEval; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * @param array $result |
|
275 | + * @return array |
|
276 | + */ |
|
277 | + private static function create_evaluation_objects_from_sql_result($result) |
|
278 | + { |
|
279 | + $alleval = array(); |
|
280 | + if (Database::num_rows($result)) { |
|
281 | + while ($data = Database::fetch_array($result)) { |
|
282 | + $eval= new Evaluation(); |
|
283 | + $eval->set_id($data['id']); |
|
284 | + $eval->set_name($data['name']); |
|
285 | + $eval->set_description($data['description']); |
|
286 | + $eval->set_user_id($data['user_id']); |
|
287 | + $eval->set_course_code($data['course_code']); |
|
288 | + $eval->set_category_id($data['category_id']); |
|
289 | + $eval->set_date(api_get_local_time($data['created_at'])); |
|
290 | + $eval->set_weight($data['weight']); |
|
291 | + $eval->set_max($data['max']); |
|
292 | + $eval->set_visible($data['visible']); |
|
293 | + $eval->set_type($data['type']); |
|
294 | + $eval->set_locked($data['locked']); |
|
295 | + $eval->setSessionId(api_get_session_id()); |
|
296 | + |
|
297 | + $alleval[] = $eval; |
|
298 | + } |
|
299 | + } |
|
300 | + |
|
301 | + return $alleval; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Insert this evaluation into the database |
|
306 | + */ |
|
307 | 307 | public function add() |
308 | - { |
|
309 | - if (isset($this->name) && |
|
310 | - isset($this->user_id) && |
|
311 | - isset($this->weight) && |
|
312 | - isset ($this->eval_max) && |
|
313 | - isset($this->visible) |
|
314 | - ) { |
|
315 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
316 | - |
|
317 | - $sql = 'INSERT INTO '.$tbl_grade_evaluations |
|
318 | - .' (name, user_id, weight, max, visible'; |
|
319 | - if (isset($this->description)) { |
|
320 | - $sql .= ',description'; |
|
321 | - } |
|
322 | - if (isset($this->course_code)) { |
|
323 | - $sql .= ', course_code'; |
|
324 | - } |
|
325 | - if (isset($this->category)) { |
|
326 | - $sql .= ', category_id'; |
|
327 | - } |
|
328 | - $sql .= ', created_at'; |
|
329 | - $sql .= ',type'; |
|
330 | - $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" |
|
331 | - .','.intval($this->get_user_id()) |
|
332 | - .','.floatval($this->get_weight()) |
|
333 | - .','.intval($this->get_max()) |
|
334 | - .','.intval($this->is_visible()); |
|
335 | - if (isset($this->description)) { |
|
336 | - $sql .= ",'".Database::escape_string($this->get_description())."'"; |
|
337 | - } |
|
338 | - if (isset($this->course_code)) { |
|
339 | - $sql .= ",'".Database::escape_string($this->get_course_code())."'"; |
|
340 | - } |
|
341 | - if (isset($this->category)) { |
|
342 | - $sql .= ','.intval($this->get_category_id()); |
|
343 | - } |
|
344 | - if (empty($this->type)) { |
|
345 | - $this->type = 'evaluation'; |
|
346 | - } |
|
347 | - $sql .= ", '".api_get_utc_datetime()."'"; |
|
348 | - $sql .= ',\''.Database::escape_string($this->type).'\''; |
|
349 | - $sql .= ")"; |
|
350 | - |
|
351 | - Database::query($sql); |
|
352 | - $this->set_id(Database::insert_id()); |
|
353 | - } else { |
|
354 | - die('Error in Evaluation add: required field empty'); |
|
355 | - } |
|
356 | - } |
|
357 | - |
|
358 | - /** |
|
359 | - * @param int $idevaluation |
|
360 | - */ |
|
361 | - public function add_evaluation_log($idevaluation) |
|
362 | - { |
|
363 | - if (!empty($idevaluation)) { |
|
364 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
365 | - $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
|
366 | - $eval = new Evaluation(); |
|
367 | - $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
368 | - $arreval = get_object_vars($dateobject[0]); |
|
369 | - if (!empty($arreval['id'])) { |
|
370 | - $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
|
308 | + { |
|
309 | + if (isset($this->name) && |
|
310 | + isset($this->user_id) && |
|
311 | + isset($this->weight) && |
|
312 | + isset ($this->eval_max) && |
|
313 | + isset($this->visible) |
|
314 | + ) { |
|
315 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
316 | + |
|
317 | + $sql = 'INSERT INTO '.$tbl_grade_evaluations |
|
318 | + .' (name, user_id, weight, max, visible'; |
|
319 | + if (isset($this->description)) { |
|
320 | + $sql .= ',description'; |
|
321 | + } |
|
322 | + if (isset($this->course_code)) { |
|
323 | + $sql .= ', course_code'; |
|
324 | + } |
|
325 | + if (isset($this->category)) { |
|
326 | + $sql .= ', category_id'; |
|
327 | + } |
|
328 | + $sql .= ', created_at'; |
|
329 | + $sql .= ',type'; |
|
330 | + $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" |
|
331 | + .','.intval($this->get_user_id()) |
|
332 | + .','.floatval($this->get_weight()) |
|
333 | + .','.intval($this->get_max()) |
|
334 | + .','.intval($this->is_visible()); |
|
335 | + if (isset($this->description)) { |
|
336 | + $sql .= ",'".Database::escape_string($this->get_description())."'"; |
|
337 | + } |
|
338 | + if (isset($this->course_code)) { |
|
339 | + $sql .= ",'".Database::escape_string($this->get_course_code())."'"; |
|
340 | + } |
|
341 | + if (isset($this->category)) { |
|
342 | + $sql .= ','.intval($this->get_category_id()); |
|
343 | + } |
|
344 | + if (empty($this->type)) { |
|
345 | + $this->type = 'evaluation'; |
|
346 | + } |
|
347 | + $sql .= ", '".api_get_utc_datetime()."'"; |
|
348 | + $sql .= ',\''.Database::escape_string($this->type).'\''; |
|
349 | + $sql .= ")"; |
|
350 | + |
|
351 | + Database::query($sql); |
|
352 | + $this->set_id(Database::insert_id()); |
|
353 | + } else { |
|
354 | + die('Error in Evaluation add: required field empty'); |
|
355 | + } |
|
356 | + } |
|
357 | + |
|
358 | + /** |
|
359 | + * @param int $idevaluation |
|
360 | + */ |
|
361 | + public function add_evaluation_log($idevaluation) |
|
362 | + { |
|
363 | + if (!empty($idevaluation)) { |
|
364 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
365 | + $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
|
366 | + $eval = new Evaluation(); |
|
367 | + $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
368 | + $arreval = get_object_vars($dateobject[0]); |
|
369 | + if (!empty($arreval['id'])) { |
|
370 | + $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
|
371 | 371 | WHERE id='.$arreval['id']; |
372 | 372 | $rs = Database::query($sql); |
373 | 373 | $row_old_weight = Database::fetch_array($rs, 'ASSOC'); |
@@ -383,426 +383,426 @@ discard block |
||
383 | 383 | 'user_id_log' => api_get_user_id() |
384 | 384 | ]; |
385 | 385 | Database::insert($tbl_grade_linkeval_log, $params); |
386 | - } |
|
387 | - } |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Update the properties of this evaluation in the database |
|
392 | - */ |
|
393 | - public function save() |
|
394 | - { |
|
395 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
396 | - $sql = 'UPDATE '.$tbl_grade_evaluations |
|
397 | - ." SET name = '".Database::escape_string($this->get_name())."'" |
|
398 | - .', description = '; |
|
399 | - if (isset($this->description)) { |
|
400 | - $sql .= "'".Database::escape_string($this->get_description())."'"; |
|
401 | - }else { |
|
402 | - $sql .= 'null'; |
|
403 | - } |
|
404 | - $sql .= ', user_id = '.intval($this->get_user_id()) |
|
405 | - .', course_code = '; |
|
406 | - if (isset($this->course_code)) { |
|
407 | - $sql .= "'".Database::escape_string($this->get_course_code())."'"; |
|
408 | - } else { |
|
409 | - $sql .= 'null'; |
|
410 | - } |
|
411 | - $sql .= ', category_id = '; |
|
412 | - if (isset($this->category)) { |
|
413 | - $sql .= intval($this->get_category_id()); |
|
414 | - } else { |
|
415 | - $sql .= 'null'; |
|
416 | - } |
|
417 | - $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" ' |
|
418 | - .', max = '.intval($this->get_max()) |
|
419 | - .', visible = '.intval($this->is_visible()) |
|
420 | - .' WHERE id = '.intval($this->id); |
|
421 | - //recorded history |
|
422 | - |
|
423 | - $eval_log = new Evaluation(); |
|
424 | - $eval_log->add_evaluation_log($this->id); |
|
425 | - Database::query($sql); |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Delete this evaluation from the database |
|
430 | - */ |
|
431 | - public function delete() |
|
432 | - { |
|
433 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
434 | - $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id); |
|
435 | - Database::query($sql); |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * Check if an evaluation name (with the same parent category) already exists |
|
440 | - * @param $name name to check (if not given, the name property of this object will be checked) |
|
441 | - * @param $parent parent category |
|
442 | - */ |
|
443 | - public function does_name_exist($name, $parent) |
|
444 | - { |
|
445 | - if (!isset ($name)) { |
|
446 | - $name = $this->name; |
|
447 | - $parent = $this->category; |
|
448 | - } |
|
449 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
450 | - $sql = 'SELECT count(id) AS number' |
|
451 | - .' FROM '.$tbl_grade_evaluations |
|
452 | - ." WHERE name = '".Database::escape_string($name)."'"; |
|
453 | - |
|
454 | - if (api_is_allowed_to_edit()) { |
|
455 | - $parent = Category::load($parent); |
|
456 | - $code = $parent[0]->get_course_code(); |
|
457 | - $courseInfo = api_get_course_info($code); |
|
458 | - $courseId = $courseInfo['real_id']; |
|
459 | - |
|
460 | - if (isset($code) && $code != '0') { |
|
461 | - $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
|
462 | - $sql .= ' AND user_id IN ( |
|
386 | + } |
|
387 | + } |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Update the properties of this evaluation in the database |
|
392 | + */ |
|
393 | + public function save() |
|
394 | + { |
|
395 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
396 | + $sql = 'UPDATE '.$tbl_grade_evaluations |
|
397 | + ." SET name = '".Database::escape_string($this->get_name())."'" |
|
398 | + .', description = '; |
|
399 | + if (isset($this->description)) { |
|
400 | + $sql .= "'".Database::escape_string($this->get_description())."'"; |
|
401 | + }else { |
|
402 | + $sql .= 'null'; |
|
403 | + } |
|
404 | + $sql .= ', user_id = '.intval($this->get_user_id()) |
|
405 | + .', course_code = '; |
|
406 | + if (isset($this->course_code)) { |
|
407 | + $sql .= "'".Database::escape_string($this->get_course_code())."'"; |
|
408 | + } else { |
|
409 | + $sql .= 'null'; |
|
410 | + } |
|
411 | + $sql .= ', category_id = '; |
|
412 | + if (isset($this->category)) { |
|
413 | + $sql .= intval($this->get_category_id()); |
|
414 | + } else { |
|
415 | + $sql .= 'null'; |
|
416 | + } |
|
417 | + $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" ' |
|
418 | + .', max = '.intval($this->get_max()) |
|
419 | + .', visible = '.intval($this->is_visible()) |
|
420 | + .' WHERE id = '.intval($this->id); |
|
421 | + //recorded history |
|
422 | + |
|
423 | + $eval_log = new Evaluation(); |
|
424 | + $eval_log->add_evaluation_log($this->id); |
|
425 | + Database::query($sql); |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Delete this evaluation from the database |
|
430 | + */ |
|
431 | + public function delete() |
|
432 | + { |
|
433 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
434 | + $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id); |
|
435 | + Database::query($sql); |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * Check if an evaluation name (with the same parent category) already exists |
|
440 | + * @param $name name to check (if not given, the name property of this object will be checked) |
|
441 | + * @param $parent parent category |
|
442 | + */ |
|
443 | + public function does_name_exist($name, $parent) |
|
444 | + { |
|
445 | + if (!isset ($name)) { |
|
446 | + $name = $this->name; |
|
447 | + $parent = $this->category; |
|
448 | + } |
|
449 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
450 | + $sql = 'SELECT count(id) AS number' |
|
451 | + .' FROM '.$tbl_grade_evaluations |
|
452 | + ." WHERE name = '".Database::escape_string($name)."'"; |
|
453 | + |
|
454 | + if (api_is_allowed_to_edit()) { |
|
455 | + $parent = Category::load($parent); |
|
456 | + $code = $parent[0]->get_course_code(); |
|
457 | + $courseInfo = api_get_course_info($code); |
|
458 | + $courseId = $courseInfo['real_id']; |
|
459 | + |
|
460 | + if (isset($code) && $code != '0') { |
|
461 | + $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
|
462 | + $sql .= ' AND user_id IN ( |
|
463 | 463 | SELECT user_id FROM '.$main_course_user_table.' |
464 | 464 | WHERE |
465 | 465 | c_id = '.$courseId.' AND |
466 | 466 | status = '.COURSEMANAGER.' |
467 | 467 | )'; |
468 | - } else { |
|
469 | - $sql .= ' AND user_id = '.api_get_user_id(); |
|
470 | - } |
|
471 | - |
|
472 | - }else { |
|
473 | - $sql .= ' AND user_id = '.api_get_user_id(); |
|
474 | - } |
|
475 | - |
|
476 | - if (!isset ($parent)) { |
|
477 | - $sql.= ' AND category_id is null'; |
|
478 | - } else { |
|
479 | - $sql.= ' AND category_id = '.intval($parent); |
|
480 | - } |
|
481 | - $result = Database::query($sql); |
|
482 | - $number=Database::fetch_row($result); |
|
483 | - |
|
484 | - return $number[0] != 0; |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * Are there any results for this evaluation yet ? |
|
489 | - * The 'max' property should not be changed then. |
|
490 | - */ |
|
491 | - public function has_results() |
|
492 | - { |
|
493 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
494 | - $sql = 'SELECT count(id) AS number |
|
468 | + } else { |
|
469 | + $sql .= ' AND user_id = '.api_get_user_id(); |
|
470 | + } |
|
471 | + |
|
472 | + }else { |
|
473 | + $sql .= ' AND user_id = '.api_get_user_id(); |
|
474 | + } |
|
475 | + |
|
476 | + if (!isset ($parent)) { |
|
477 | + $sql.= ' AND category_id is null'; |
|
478 | + } else { |
|
479 | + $sql.= ' AND category_id = '.intval($parent); |
|
480 | + } |
|
481 | + $result = Database::query($sql); |
|
482 | + $number=Database::fetch_row($result); |
|
483 | + |
|
484 | + return $number[0] != 0; |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * Are there any results for this evaluation yet ? |
|
489 | + * The 'max' property should not be changed then. |
|
490 | + */ |
|
491 | + public function has_results() |
|
492 | + { |
|
493 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
494 | + $sql = 'SELECT count(id) AS number |
|
495 | 495 | FROM '.$tbl_grade_results.' |
496 | 496 | WHERE evaluation_id = '.intval($this->id); |
497 | - $result = Database::query($sql); |
|
498 | - $number=Database::fetch_row($result); |
|
499 | - |
|
500 | - return ($number[0] != 0); |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Delete all results for this evaluation |
|
505 | - */ |
|
506 | - public function delete_results() |
|
507 | - { |
|
508 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
509 | - $sql = 'DELETE FROM '.$tbl_grade_results.' |
|
497 | + $result = Database::query($sql); |
|
498 | + $number=Database::fetch_row($result); |
|
499 | + |
|
500 | + return ($number[0] != 0); |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Delete all results for this evaluation |
|
505 | + */ |
|
506 | + public function delete_results() |
|
507 | + { |
|
508 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
509 | + $sql = 'DELETE FROM '.$tbl_grade_results.' |
|
510 | 510 | WHERE evaluation_id = '.intval($this->id); |
511 | - Database::query($sql); |
|
512 | - } |
|
513 | - |
|
514 | - /** |
|
515 | - * Delete this evaluation and all underlying results. |
|
516 | - */ |
|
517 | - public function delete_with_results() |
|
518 | - { |
|
519 | - $this->delete_results(); |
|
520 | - $this->delete(); |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Check if the given score is possible for this evaluation |
|
525 | - */ |
|
526 | - public function is_valid_score($score) |
|
527 | - { |
|
528 | - return is_numeric($score) && $score >= 0 && $score <= $this->eval_max; |
|
529 | - } |
|
530 | - |
|
531 | - /** |
|
532 | - * Calculate the score of this evaluation |
|
533 | - * @param int $stud_id (default: all students who have results for this eval - then the average is returned) |
|
534 | - * @param string $type (best, average, ranking) |
|
535 | - * @return array (score, max) if student is given |
|
536 | - * array (sum of scores, number of scores) otherwise |
|
537 | - * or null if no scores available |
|
538 | - */ |
|
539 | - public function calc_score($stud_id = null, $type = null) |
|
540 | - { |
|
511 | + Database::query($sql); |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * Delete this evaluation and all underlying results. |
|
516 | + */ |
|
517 | + public function delete_with_results() |
|
518 | + { |
|
519 | + $this->delete_results(); |
|
520 | + $this->delete(); |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Check if the given score is possible for this evaluation |
|
525 | + */ |
|
526 | + public function is_valid_score($score) |
|
527 | + { |
|
528 | + return is_numeric($score) && $score >= 0 && $score <= $this->eval_max; |
|
529 | + } |
|
530 | + |
|
531 | + /** |
|
532 | + * Calculate the score of this evaluation |
|
533 | + * @param int $stud_id (default: all students who have results for this eval - then the average is returned) |
|
534 | + * @param string $type (best, average, ranking) |
|
535 | + * @return array (score, max) if student is given |
|
536 | + * array (sum of scores, number of scores) otherwise |
|
537 | + * or null if no scores available |
|
538 | + */ |
|
539 | + public function calc_score($stud_id = null, $type = null) |
|
540 | + { |
|
541 | 541 | $useSession = true; |
542 | - if (isset($stud_id) && empty($type)) { |
|
543 | - $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id; |
|
544 | - $data = Session::read('calc_score'); |
|
542 | + if (isset($stud_id) && empty($type)) { |
|
543 | + $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id; |
|
544 | + $data = Session::read('calc_score'); |
|
545 | 545 | $results = isset($data[$key]) ? $data[$key] : null; |
546 | 546 | |
547 | 547 | if ($useSession == false) { |
548 | 548 | $results = null; |
549 | 549 | } |
550 | - if (empty($results)) { |
|
551 | - $results = Result::load(null, $stud_id, $this->id); |
|
552 | - Session::write('calc_score', array($key => $results)); |
|
553 | - } |
|
554 | - |
|
555 | - $score = 0; |
|
556 | - /** @var Result $res */ |
|
557 | - foreach ($results as $res) { |
|
558 | - $score = $res->get_score(); |
|
559 | - } |
|
560 | - |
|
561 | - return array($score, $this->get_max()); |
|
562 | - } else { |
|
563 | - |
|
564 | - $count = 0; |
|
565 | - $sum = 0; |
|
566 | - $bestResult = 0; |
|
567 | - $weight = 0; |
|
568 | - $sumResult = 0; |
|
569 | - |
|
570 | - $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id; |
|
550 | + if (empty($results)) { |
|
551 | + $results = Result::load(null, $stud_id, $this->id); |
|
552 | + Session::write('calc_score', array($key => $results)); |
|
553 | + } |
|
554 | + |
|
555 | + $score = 0; |
|
556 | + /** @var Result $res */ |
|
557 | + foreach ($results as $res) { |
|
558 | + $score = $res->get_score(); |
|
559 | + } |
|
560 | + |
|
561 | + return array($score, $this->get_max()); |
|
562 | + } else { |
|
563 | + |
|
564 | + $count = 0; |
|
565 | + $sum = 0; |
|
566 | + $bestResult = 0; |
|
567 | + $weight = 0; |
|
568 | + $sumResult = 0; |
|
569 | + |
|
570 | + $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id; |
|
571 | 571 | $data = Session::read('calc_score'); |
572 | 572 | $allResults = isset($data[$key]) ? $data[$key] : null; |
573 | 573 | if ($useSession == false) { |
574 | 574 | $allResults = null; |
575 | 575 | } |
576 | - if (empty($allResults)) { |
|
577 | - $allResults = Result::load(null, null, $this->id); |
|
578 | - Session::write($key, $allResults); |
|
579 | - } |
|
580 | - |
|
581 | - $students = array(); |
|
582 | - /** @var Result $res */ |
|
583 | - foreach ($allResults as $res) { |
|
584 | - $score = $res->get_score(); |
|
585 | - if (!empty($score) || $score == '0') { |
|
586 | - $count++; |
|
587 | - $sum += $score / $this->get_max(); |
|
588 | - $sumResult += $score; |
|
589 | - if ($score > $bestResult) { |
|
590 | - $bestResult = $score; |
|
591 | - } |
|
592 | - $weight = $this->get_max(); |
|
593 | - } |
|
594 | - $students[$res->get_user_id()] = $score; |
|
595 | - } |
|
596 | - |
|
597 | - if (empty($count)) { |
|
598 | - return null; |
|
599 | - } |
|
600 | - |
|
601 | - switch ($type) { |
|
602 | - case 'best': |
|
603 | - return array($bestResult, $weight); |
|
604 | - break; |
|
605 | - case 'average': |
|
606 | - return array($sumResult/$count, $weight); |
|
607 | - break; |
|
608 | - case 'ranking': |
|
576 | + if (empty($allResults)) { |
|
577 | + $allResults = Result::load(null, null, $this->id); |
|
578 | + Session::write($key, $allResults); |
|
579 | + } |
|
580 | + |
|
581 | + $students = array(); |
|
582 | + /** @var Result $res */ |
|
583 | + foreach ($allResults as $res) { |
|
584 | + $score = $res->get_score(); |
|
585 | + if (!empty($score) || $score == '0') { |
|
586 | + $count++; |
|
587 | + $sum += $score / $this->get_max(); |
|
588 | + $sumResult += $score; |
|
589 | + if ($score > $bestResult) { |
|
590 | + $bestResult = $score; |
|
591 | + } |
|
592 | + $weight = $this->get_max(); |
|
593 | + } |
|
594 | + $students[$res->get_user_id()] = $score; |
|
595 | + } |
|
596 | + |
|
597 | + if (empty($count)) { |
|
598 | + return null; |
|
599 | + } |
|
600 | + |
|
601 | + switch ($type) { |
|
602 | + case 'best': |
|
603 | + return array($bestResult, $weight); |
|
604 | + break; |
|
605 | + case 'average': |
|
606 | + return array($sumResult/$count, $weight); |
|
607 | + break; |
|
608 | + case 'ranking': |
|
609 | 609 | $students = array(); |
610 | 610 | /** @var Result $res */ |
611 | 611 | foreach ($allResults as $res) { |
612 | 612 | $score = $res->get_score(); |
613 | 613 | $students[$res->get_user_id()] = $score; |
614 | 614 | } |
615 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
616 | - break; |
|
617 | - default: |
|
618 | - return array($sum, $count); |
|
619 | - break; |
|
620 | - } |
|
621 | - } |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Generate an array of possible categories where this evaluation can be moved to. |
|
626 | - * Notice: its own parent will be included in the list: it's up to the frontend |
|
627 | - * to disable this element. |
|
628 | - * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
|
629 | - */ |
|
630 | - public function get_target_categories() |
|
631 | - { |
|
632 | - // - course independent evaluation |
|
633 | - // -> movable to root or other course independent categories |
|
634 | - // - evaluation inside a course |
|
635 | - // -> movable to root, independent categories or categories inside the course |
|
636 | - $user = (api_is_platform_admin() ? null : api_get_user_id()); |
|
637 | - $targets = array(); |
|
638 | - $level = 0; |
|
639 | - |
|
640 | - $root = array(0, get_lang('RootCat'), $level); |
|
641 | - $targets[] = $root; |
|
642 | - |
|
643 | - if (isset($this->course_code) && !empty($this->course_code)) { |
|
644 | - $crscats = Category::load(null,null,$this->course_code,0); |
|
645 | - foreach ($crscats as $cat) { |
|
646 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
647 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
648 | - } |
|
649 | - } |
|
650 | - |
|
651 | - $indcats = Category::load(null,$user,0,0); |
|
652 | - foreach ($indcats as $cat) { |
|
653 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
654 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
655 | - } |
|
656 | - |
|
657 | - return $targets; |
|
658 | - } |
|
659 | - |
|
660 | - /** |
|
661 | - * Internal function used by get_target_categories() |
|
662 | - * @param integer $level |
|
663 | - */ |
|
664 | - private function add_target_subcategories($targets, $level, $catid) |
|
665 | - { |
|
666 | - $subcats = Category::load(null,null,null,$catid); |
|
667 | - foreach ($subcats as $cat) { |
|
668 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
669 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
670 | - } |
|
671 | - return $targets; |
|
672 | - } |
|
673 | - |
|
674 | - /** |
|
675 | - * Move this evaluation to the given category. |
|
676 | - * If this evaluation moves from inside a course to outside, |
|
677 | - * its course code is also changed. |
|
678 | - */ |
|
679 | - public function move_to_cat($cat) |
|
680 | - { |
|
681 | - $this->set_category_id($cat->get_id()); |
|
682 | - if ($this->get_course_code() != $cat->get_course_code()) { |
|
683 | - $this->set_course_code($cat->get_course_code()); |
|
684 | - } |
|
685 | - $this->save(); |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * Retrieve evaluations where a student has results for |
|
690 | - * and return them as an array of Evaluation objects |
|
691 | - * @param int $cat_id parent category (use 'null' to retrieve them in all categories) |
|
692 | - * @param int $stud_id student id |
|
693 | - */ |
|
694 | - public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id) |
|
695 | - { |
|
696 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
697 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
698 | - |
|
699 | - $sql = 'SELECT * FROM '.$tbl_grade_evaluations.' |
|
615 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
616 | + break; |
|
617 | + default: |
|
618 | + return array($sum, $count); |
|
619 | + break; |
|
620 | + } |
|
621 | + } |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Generate an array of possible categories where this evaluation can be moved to. |
|
626 | + * Notice: its own parent will be included in the list: it's up to the frontend |
|
627 | + * to disable this element. |
|
628 | + * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
|
629 | + */ |
|
630 | + public function get_target_categories() |
|
631 | + { |
|
632 | + // - course independent evaluation |
|
633 | + // -> movable to root or other course independent categories |
|
634 | + // - evaluation inside a course |
|
635 | + // -> movable to root, independent categories or categories inside the course |
|
636 | + $user = (api_is_platform_admin() ? null : api_get_user_id()); |
|
637 | + $targets = array(); |
|
638 | + $level = 0; |
|
639 | + |
|
640 | + $root = array(0, get_lang('RootCat'), $level); |
|
641 | + $targets[] = $root; |
|
642 | + |
|
643 | + if (isset($this->course_code) && !empty($this->course_code)) { |
|
644 | + $crscats = Category::load(null,null,$this->course_code,0); |
|
645 | + foreach ($crscats as $cat) { |
|
646 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
647 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
648 | + } |
|
649 | + } |
|
650 | + |
|
651 | + $indcats = Category::load(null,$user,0,0); |
|
652 | + foreach ($indcats as $cat) { |
|
653 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
654 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
655 | + } |
|
656 | + |
|
657 | + return $targets; |
|
658 | + } |
|
659 | + |
|
660 | + /** |
|
661 | + * Internal function used by get_target_categories() |
|
662 | + * @param integer $level |
|
663 | + */ |
|
664 | + private function add_target_subcategories($targets, $level, $catid) |
|
665 | + { |
|
666 | + $subcats = Category::load(null,null,null,$catid); |
|
667 | + foreach ($subcats as $cat) { |
|
668 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
669 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
670 | + } |
|
671 | + return $targets; |
|
672 | + } |
|
673 | + |
|
674 | + /** |
|
675 | + * Move this evaluation to the given category. |
|
676 | + * If this evaluation moves from inside a course to outside, |
|
677 | + * its course code is also changed. |
|
678 | + */ |
|
679 | + public function move_to_cat($cat) |
|
680 | + { |
|
681 | + $this->set_category_id($cat->get_id()); |
|
682 | + if ($this->get_course_code() != $cat->get_course_code()) { |
|
683 | + $this->set_course_code($cat->get_course_code()); |
|
684 | + } |
|
685 | + $this->save(); |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * Retrieve evaluations where a student has results for |
|
690 | + * and return them as an array of Evaluation objects |
|
691 | + * @param int $cat_id parent category (use 'null' to retrieve them in all categories) |
|
692 | + * @param int $stud_id student id |
|
693 | + */ |
|
694 | + public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id) |
|
695 | + { |
|
696 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
697 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
698 | + |
|
699 | + $sql = 'SELECT * FROM '.$tbl_grade_evaluations.' |
|
700 | 700 | WHERE id IN ( |
701 | 701 | SELECT evaluation_id FROM '.$tbl_grade_results.' |
702 | 702 | WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL |
703 | 703 | )'; |
704 | - if (!api_is_allowed_to_edit()) { |
|
705 | - $sql .= ' AND visible = 1'; |
|
706 | - } |
|
707 | - if (isset($cat_id)) { |
|
708 | - $sql .= ' AND category_id = '.intval($cat_id); |
|
709 | - } else { |
|
710 | - $sql .= ' AND category_id >= 0'; |
|
711 | - } |
|
712 | - |
|
713 | - $result = Database::query($sql); |
|
714 | - $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
715 | - |
|
716 | - return $alleval; |
|
717 | - } |
|
718 | - |
|
719 | - /** |
|
720 | - * Get a list of students that do not have a result record for this evaluation |
|
721 | - */ |
|
722 | - public function get_not_subscribed_students($first_letter_user = '') |
|
723 | - { |
|
724 | - $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
725 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
726 | - |
|
727 | - $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user |
|
728 | - ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'" |
|
729 | - .' AND status = '.STUDENT |
|
730 | - .' AND user_id NOT IN' |
|
731 | - .' (SELECT user_id FROM '.$tbl_grade_results |
|
732 | - .' WHERE evaluation_id = '.intval($this->id) |
|
733 | - .' )' |
|
734 | - .' ORDER BY lastname'; |
|
735 | - |
|
736 | - $result = Database::query($sql); |
|
737 | - $users = Database::store_result($result); |
|
738 | - |
|
739 | - return $users; |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * Find evaluations by name |
|
744 | - * @param string $name_mask search string |
|
745 | - * @return array evaluation objects matching the search criterium |
|
746 | - * @todo can be written more efficiently using a new (but very complex) sql query |
|
747 | - */ |
|
748 | - public function find_evaluations($name_mask,$selectcat) |
|
749 | - { |
|
750 | - $rootcat = Category::load($selectcat); |
|
751 | - $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
|
752 | - $foundevals = array(); |
|
753 | - foreach ($evals as $eval) { |
|
754 | - if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) { |
|
755 | - $foundevals[] = $eval; |
|
756 | - } |
|
757 | - } |
|
758 | - return $foundevals; |
|
759 | - } |
|
760 | - |
|
761 | - public function get_item_type() |
|
762 | - { |
|
763 | - return 'E'; |
|
764 | - } |
|
765 | - |
|
766 | - public function get_icon_name() |
|
767 | - { |
|
768 | - return $this->has_results() ? 'evalnotempty' : 'evalempty'; |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Locks an evaluation, only one who can unlock it is the platform administrator. |
|
773 | - * @param int locked 1 or unlocked 0 |
|
774 | - * |
|
775 | - **/ |
|
776 | - function lock($locked) |
|
777 | - { |
|
778 | - $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
779 | - $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; |
|
780 | - Database::query($sql); |
|
781 | - } |
|
782 | - |
|
783 | - function check_lock_permissions() |
|
784 | - { |
|
785 | - if (api_is_platform_admin()) { |
|
786 | - return true; |
|
787 | - } else { |
|
788 | - if ($this->is_locked()) { |
|
789 | - api_not_allowed(); |
|
790 | - } |
|
791 | - } |
|
792 | - } |
|
793 | - |
|
794 | - function delete_linked_data() |
|
795 | - { |
|
796 | - |
|
797 | - } |
|
704 | + if (!api_is_allowed_to_edit()) { |
|
705 | + $sql .= ' AND visible = 1'; |
|
706 | + } |
|
707 | + if (isset($cat_id)) { |
|
708 | + $sql .= ' AND category_id = '.intval($cat_id); |
|
709 | + } else { |
|
710 | + $sql .= ' AND category_id >= 0'; |
|
711 | + } |
|
712 | + |
|
713 | + $result = Database::query($sql); |
|
714 | + $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
715 | + |
|
716 | + return $alleval; |
|
717 | + } |
|
718 | + |
|
719 | + /** |
|
720 | + * Get a list of students that do not have a result record for this evaluation |
|
721 | + */ |
|
722 | + public function get_not_subscribed_students($first_letter_user = '') |
|
723 | + { |
|
724 | + $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
725 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
726 | + |
|
727 | + $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user |
|
728 | + ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'" |
|
729 | + .' AND status = '.STUDENT |
|
730 | + .' AND user_id NOT IN' |
|
731 | + .' (SELECT user_id FROM '.$tbl_grade_results |
|
732 | + .' WHERE evaluation_id = '.intval($this->id) |
|
733 | + .' )' |
|
734 | + .' ORDER BY lastname'; |
|
735 | + |
|
736 | + $result = Database::query($sql); |
|
737 | + $users = Database::store_result($result); |
|
738 | + |
|
739 | + return $users; |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * Find evaluations by name |
|
744 | + * @param string $name_mask search string |
|
745 | + * @return array evaluation objects matching the search criterium |
|
746 | + * @todo can be written more efficiently using a new (but very complex) sql query |
|
747 | + */ |
|
748 | + public function find_evaluations($name_mask,$selectcat) |
|
749 | + { |
|
750 | + $rootcat = Category::load($selectcat); |
|
751 | + $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
|
752 | + $foundevals = array(); |
|
753 | + foreach ($evals as $eval) { |
|
754 | + if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) { |
|
755 | + $foundevals[] = $eval; |
|
756 | + } |
|
757 | + } |
|
758 | + return $foundevals; |
|
759 | + } |
|
760 | + |
|
761 | + public function get_item_type() |
|
762 | + { |
|
763 | + return 'E'; |
|
764 | + } |
|
765 | + |
|
766 | + public function get_icon_name() |
|
767 | + { |
|
768 | + return $this->has_results() ? 'evalnotempty' : 'evalempty'; |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Locks an evaluation, only one who can unlock it is the platform administrator. |
|
773 | + * @param int locked 1 or unlocked 0 |
|
774 | + * |
|
775 | + **/ |
|
776 | + function lock($locked) |
|
777 | + { |
|
778 | + $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
779 | + $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; |
|
780 | + Database::query($sql); |
|
781 | + } |
|
782 | + |
|
783 | + function check_lock_permissions() |
|
784 | + { |
|
785 | + if (api_is_platform_admin()) { |
|
786 | + return true; |
|
787 | + } else { |
|
788 | + if ($this->is_locked()) { |
|
789 | + api_not_allowed(); |
|
790 | + } |
|
791 | + } |
|
792 | + } |
|
793 | + |
|
794 | + function delete_linked_data() |
|
795 | + { |
|
796 | + |
|
797 | + } |
|
798 | 798 | |
799 | 799 | public function getStudentList() |
800 | 800 | { |
801 | 801 | return $this->studentList; |
802 | 802 | } |
803 | 803 | |
804 | - public function setStudentList($list) |
|
805 | - { |
|
806 | - $this->studentList = $list; |
|
807 | - } |
|
804 | + public function setStudentList($list) |
|
805 | + { |
|
806 | + $this->studentList = $list; |
|
807 | + } |
|
808 | 808 | } |