<?php

session_start();

	// CHECK FOR SESSION
	include("engine/admin/inc/lib.inc.php");
	//list($schools_school_named)=get_schools($_SESSION['usergroup']);
		
	// GET FULL URL AND EXPLODE
	//$checkSlug = explode("/", $_SERVER["REQUEST_URI"]); //analyze rewritten url
	
	// id an edit happens rearrange the slug pulls
	$current_id = find_slug(1,"application");
	
	if(is_numeric($current_id)){
		$current_id = find_slug(3,"application");
		$action_name=find_slug(2,"application");
		$record_pull=find_slug(1,"application");
	}
	
	// IF NO PAGE CAN BE FOUND, THEN SIMPLY SHOW HOMEPAGE
	if($current_id=="" || $current_id=="application"){
		$current_id="home";	
	}
	
	$loginslug = find_slug(1);

	// if redirect is set remove login slug
	if($_GET['redirect']){
		$loginslug = "";
	}

	include("reg_index.php");// this page handles all the login and sessions
	
	if(!$_SESSION['school_logo']){
		//get the domain info for the subdomain
		$subdomain_logo=pull_field("form_schools",'db61',"WHERE db985='$subdomain'");
		$_SESSION['school_logo'] = strtolower($subdomain_logo); // ucas id to be used to get logo
	}
	
	#if($schools_tag==''){
		$schools_status= pull_field("form_schools",'db81',"WHERE id= $_SESSION[usergroup]");
list ($school_type, $school_name) = explode('|||',pull_field("form_schools","CONCAT(db30,'|||',db27)","WHERE id= $_SESSION[usergroup]"));
//offline message
$preferences_offline_message = pull_field("lead_preferences","db37354","WHERE usergroup=$_SESSION[usergroup]");



	#}

	// resolve tenant login logo, background image and favicon from portal media (uploaded in Theme settings)
	$login_logo_image = null;
	$login_background_image = null;
	$login_favicon_image = null;
	$hide_login_footer = false;
	// login colour options: null means keep the original splash.css look; set only when configured in Theme settings
	$login_header_bg = null;
	$login_button_bg = null;
	$login_button_text = null;
	if (!empty($_SESSION['subdomain'])) {
		$theme_media_dir = $_SERVER['DOCUMENT_ROOT'] . "/portal/media/" . $_SESSION['subdomain'] . "/images/";
		$logo_matches = glob($theme_media_dir . "logo.*");
		if (!empty($logo_matches)) {
			$login_logo_image = "/portal/media/" . $_SESSION['subdomain'] . "/images/" . basename($logo_matches[0]);
		}
		$background_matches = glob($theme_media_dir . "background.*");
		if (!empty($background_matches)) {
			$login_background_image = "/portal/media/" . $_SESSION['subdomain'] . "/images/" . basename($background_matches[0]);
		}
		$favicon_matches = glob($theme_media_dir . "favicon.*");
		if (!empty($favicon_matches)) {
			$login_favicon_image = "/portal/media/" . $_SESSION['subdomain'] . "/images/" . basename($favicon_matches[0]);
		}

		// theme setting: hide address/copyright text at bottom of login page (default: show)
		$theme_settings_file = $_SERVER['DOCUMENT_ROOT'] . "/portal/media/" . $_SESSION['subdomain'] . "/themesettings.set";
		if (file_exists($theme_settings_file)) {
			$theme_settings = json_decode(file_get_contents($theme_settings_file), true);
			$theme_colors = $theme_settings['colors'] ?? array();
			if (isset($theme_colors['hide_login_footer']) && $theme_colors['hide_login_footer'] === 'yes') {
				$hide_login_footer = true;
			}
			// use configured colours when available, otherwise keep defaults
			if (!empty($theme_colors['login_headerbg'])) {
				$login_header_bg = $theme_colors['login_headerbg'];
			}
			if (!empty($theme_colors['login_button_background'])) {
				$login_button_bg = $theme_colors['login_button_background'];
			}
			if (!empty($theme_colors['login_button_text_color'])) {
				$login_button_text = $theme_colors['login_button_text_color'];
			}
		}
	}
?><!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Sign in page">
	<?php if (isset($_SESSION['usergroup']) && $_SESSION['usergroup'] == 82): ?>
    <link rel="icon" href="https://togetherness.co.uk/wp-content/uploads/2025/09/cropped-together-favicon-32x32.png" sizes="32x32" />
    <link rel="icon" href="https://togetherness.co.uk/wp-content/uploads/2025/09/cropped-together-favicon-192x192.png" sizes="192x192" />
    <link rel="apple-touch-icon" href="https://togetherness.co.uk/wp-content/uploads/2025/09/cropped-together-favicon-180x180.png" />
    <?php elseif (!is_null($login_favicon_image)): ?>
    <link rel="icon" href="<?php echo $login_favicon_image; ?>"/>
    <link rel="shortcut icon" href="<?php echo $login_favicon_image; ?>"/>
    <?php else: ?>
    <link rel="icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <?php endif; ?>

    <title>Sign in</title>

    <!-- Custom Google Web Font -->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,700,600,300' rel='stylesheet' type='text/css'>
    
    <!-- Add custom CSS here -->
    <link href="/css/splash.css?v=2" rel="stylesheet">

    <style type="text/css">
        <?php if(!is_null($login_background_image)){ ?>
        /* tenant login background overrides the default .signin bkg.jpg */
        .signin {
            background: url('<?php echo $login_background_image; ?>') no-repeat center center fixed;
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
        }
        <?php } ?>
        /* Login page: keep the original look; only override when configured in Theme settings */
        .signin-header img {
            max-width: 100%;
            max-height: 150px;
            height: auto;
            width: auto;
            object-fit: contain;
        }
        <?php if(!is_null($login_header_bg)){ ?>
        .signin-header {
            background-color: <?php echo $login_header_bg; ?>;
        }
        <?php } ?>
        <?php if(!is_null($login_button_bg)){ ?>
        .orange-button.login,
        .orange-button.btn-default,
        .btn-default {
            background-color: <?php echo $login_button_bg; ?>;
            background-image: none;
            border-color: <?php echo $login_button_bg; ?>;
        }
        .orange-button.login:hover,
        .orange-button.btn-default:hover,
        .orange-button:hover {
            background-color: <?php echo $login_button_bg; ?>;
            border-color: <?php echo $login_button_bg; ?>;
        }
        <?php } ?>
        <?php if(!is_null($login_button_text)){ ?>
        .orange-button.login,
        .orange-button.btn-default,
        .btn-default,
        .orange-button.login:hover,
        .orange-button.btn-default:hover,
        .orange-button:hover {
            color: <?php echo $login_button_text; ?>;
        }
        <?php } ?>
    </style>
     <?php if ($_SESSION['usergroup'] == '52') {  ?>
        <meta name="google-site-verification" content="6VnHsyU6RlKpyMLtKZCoWCMP3N3v3q_1h-G_RtsyBzU" />
    <?php } ?>
   
</head>

<body class="bkg"<?php if(!is_null($login_background_image)){ echo ' style="background-image: url(\''.$login_background_image.'\'); background-size: cover; background-position: center; background-repeat: no-repeat; background-attachment: fixed;"'; } ?>>


  <div class="intro-header signin">
      <div class="container">
          <div class="signin-wrap">
              <div class="signin-header">
                  <?php if ($school_type == 12) { ?>
                      <h4 style="font-weight: bold;color: grey;"> <?php echo $school_name; ?> </h4>
                  <?php } elseif (!is_null($login_logo_image)) { ?>
                    <img src="<?php echo $login_logo_image; ?>" alt="LOGO" border="0" />
                  <?php } else { ?>
                    <img src="/images/signin-logo.png" alt="LOGO" border="0" />
                <?php } ?>
              </div>
              <div class="sigin-body">
                  <?php
				  	if($schools_status!=='7' && $schools_status!=='1'){
                        //log them out if they see this image
                        if($_SESSION['loggedin']=="yes"){
                        session_destroy();
                        }
                        if (!empty($preferences_offline_message)) {
                            echo '<div class=\"message\" align="center" style="text-align:center">'.translate($preferences_offline_message, $_SESSION['lang']).'</div>
                            <div class="clear"></div>';
                        }else{
                            echo'<div class=\"message\" align="center">Sorry, this platform have been deactivated. Please navigate to the main website for more information<br/></div>';

                        }
					}else{
						  if(!empty($login_status)){
							include("$login_status");
						  }
					}
				  ?>        
              </div>
            </div>
        </div>
    </div>

<?php if (!$hide_login_footer) { ?>
<div class="footer-msg clearfix text-center">
Action Starter Limited <br />
Birmingham Science Park Aston, Faraday Wharf, Holt Street, Birmingham, B7 4BB<br/>
© 2011 - <?php echo date('Y'); ?> Actionstarter Software...
</div>
<?php } ?>

</body>

</html>
