| @@ 231-290 (lines=60) @@ | ||
| 228 | // Exercise auto-launch |
|
| 229 | $auto_launch = api_get_course_setting('enable_exercise_auto_launch'); |
|
| 230 | ||
| 231 | if (!empty($auto_launch)) { |
|
| 232 | $session_id = api_get_session_id(); |
|
| 233 | //Exercise list |
|
| 234 | if ($auto_launch == 2) { |
|
| 235 | if (api_is_platform_admin() || api_is_allowed_to_edit()) { |
|
| 236 | $showAutoLaunchExerciseWarning = true; |
|
| 237 | } else { |
|
| 238 | $session_key = 'exercise_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
|
| 239 | $sessionData = Session::read($session_key); |
|
| 240 | if (!isset($sessionData)) { |
|
| 241 | //redirecting to the Exercise |
|
| 242 | $url = api_get_path(WEB_CODE_PATH).'exercise/exercice.php?'.api_get_cidreq().'&id_session='.$session_id; |
|
| 243 | $_SESSION[$session_key] = true; |
|
| 244 | ||
| 245 | header("Location: $url"); |
|
| 246 | exit; |
|
| 247 | } |
|
| 248 | } |
|
| 249 | } else { |
|
| 250 | $table = \Database::get_course_table(TABLE_QUIZ_TEST); |
|
| 251 | $course_id = api_get_course_int_id(); |
|
| 252 | $condition = ''; |
|
| 253 | if (!empty($session_id)) { |
|
| 254 | $condition = api_get_session_condition($session_id); |
|
| 255 | $sql = "SELECT iid FROM $table |
|
| 256 | WHERE c_id = $course_id AND autolaunch = 1 $condition |
|
| 257 | LIMIT 1"; |
|
| 258 | $result = \Database::query($sql); |
|
| 259 | //If we found nothing in the session we just called the session_id = 0 autolaunch |
|
| 260 | if (\Database::num_rows($result) == 0) { |
|
| 261 | $condition = ''; |
|
| 262 | } else { |
|
| 263 | //great, there is an specific auto lunch for this session we leave the $condition |
|
| 264 | } |
|
| 265 | } |
|
| 266 | ||
| 267 | $sql = "SELECT iid FROM $table |
|
| 268 | WHERE c_id = $course_id AND autolaunch = 1 $condition |
|
| 269 | LIMIT 1"; |
|
| 270 | $result = \Database::query($sql); |
|
| 271 | if (\Database::num_rows($result) > 0) { |
|
| 272 | $data = \Database::fetch_array($result, 'ASSOC'); |
|
| 273 | if (!empty($data['iid'])) { |
|
| 274 | if (api_is_platform_admin() || api_is_allowed_to_edit()) { |
|
| 275 | $showAutoLaunchExerciseWarning = true; |
|
| 276 | } else { |
|
| 277 | $session_key = 'exercise_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
|
| 278 | if (!isset($_SESSION[$session_key])) { |
|
| 279 | //redirecting to the LP |
|
| 280 | $url = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.api_get_cidreq().'&exerciseId='.$data['iid']; |
|
| 281 | ||
| 282 | $_SESSION[$session_key] = true; |
|
| 283 | header("Location: $url"); |
|
| 284 | exit; |
|
| 285 | } |
|
| 286 | } |
|
| 287 | } |
|
| 288 | } |
|
| 289 | } |
|
| 290 | } |
|
| 291 | ||
| 292 | /* Auto launch code */ |
|
| 293 | $showAutoLaunchLpWarning = false; |
|
| @@ 295-350 (lines=56) @@ | ||
| 292 | /* Auto launch code */ |
|
| 293 | $showAutoLaunchLpWarning = false; |
|
| 294 | $auto_launch = api_get_course_setting('enable_lp_auto_launch'); |
|
| 295 | if (!empty($auto_launch)) { |
|
| 296 | $session_id = api_get_session_id(); |
|
| 297 | //LP list |
|
| 298 | if ($auto_launch == 2) { |
|
| 299 | if (api_is_platform_admin() || api_is_allowed_to_edit()) { |
|
| 300 | $showAutoLaunchLpWarning = true; |
|
| 301 | } else { |
|
| 302 | $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
|
| 303 | if (!isset($_SESSION[$session_key])) { |
|
| 304 | //redirecting to the LP |
|
| 305 | $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id; |
|
| 306 | $_SESSION[$session_key] = true; |
|
| 307 | header("Location: $url"); |
|
| 308 | exit; |
|
| 309 | } |
|
| 310 | } |
|
| 311 | } else { |
|
| 312 | $lp_table = \Database::get_course_table(TABLE_LP_MAIN); |
|
| 313 | $course_id = api_get_course_int_id(); |
|
| 314 | $condition = ''; |
|
| 315 | if (!empty($session_id)) { |
|
| 316 | $condition = api_get_session_condition($session_id); |
|
| 317 | $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1"; |
|
| 318 | $result = \Database::query($sql); |
|
| 319 | //If we found nothing in the session we just called the session_id = 0 autolunch |
|
| 320 | if (\Database::num_rows($result) == 0) { |
|
| 321 | $condition = ''; |
|
| 322 | } else { |
|
| 323 | //great, there is an specific auto lunch for this session we leave the $condition |
|
| 324 | } |
|
| 325 | } |
|
| 326 | ||
| 327 | $sql = "SELECT id FROM $lp_table |
|
| 328 | WHERE c_id = $course_id AND autolunch = 1 $condition |
|
| 329 | LIMIT 1"; |
|
| 330 | $result = \Database::query($sql); |
|
| 331 | if (\Database::num_rows($result) > 0) { |
|
| 332 | $lp_data = \Database::fetch_array($result, 'ASSOC'); |
|
| 333 | if (!empty($lp_data['id'])) { |
|
| 334 | if (api_is_platform_admin() || api_is_allowed_to_edit()) { |
|
| 335 | $showAutoLaunchLpWarning = true; |
|
| 336 | } else { |
|
| 337 | $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
|
| 338 | if (!isset($_SESSION[$session_key])) { |
|
| 339 | //redirecting to the LP |
|
| 340 | $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id']; |
|
| 341 | ||
| 342 | $_SESSION[$session_key] = true; |
|
| 343 | header("Location: $url"); |
|
| 344 | exit; |
|
| 345 | } |
|
| 346 | } |
|
| 347 | } |
|
| 348 | } |
|
| 349 | } |
|
| 350 | } |
|
| 351 | ||
| 352 | return array( |
|
| 353 | 'show_autolaunch_exercise_warning' => $showAutoLaunchExerciseWarning, |
|