<?php

ini_set('display_errors', 0);

ini_set('display_startup_errors', 0);

ini_set('buffer_output', 1);

//error_reporting(E_ALL | E_STRICT);

// This should be equal to: PATH_TO_VANGUARD_FOLDER/extra/auth.php

include('../extra/auth.php');

//require_once __DIR__ . '/extra/auth.php';

// Here we just check if user is not 

// logged in, and in that case we redirect

// the user to vanguard login page.

if (! Auth::check()) {

	

	redirectTo('login');



} 

$user = Auth::user();

$iduserlogin=$user->present()->id;

$nameuser=$user->present()->name;

$emailuser=$user->present()->email;

$idcompany=$user->present()->idcompany;

$langid=$user->present()->langid;

$privacyacc=$user->present()->privacyaccepted;

$loginusername=$user->present()->username;

$roleuser=$user->present()->role_id;

//$user = "1";

//$iduserlogin="1";

//$idcompany="1";

//$companyname="Company Name";

//$nameuser="Claudio";

//$emailuser="info@acscreativesolutions.com";

?>

<?php require_once('../Connections/cmctrfdb.php'); ?>

<?php require_once('../webassist/mysqli/rsobj.php'); ?>

<?php // require_once('@@RSObjectPath@@'); ?>

<?php  require_once('../webassist/mysqli/queryobj.php'); ?>

<?php // require_once("../webassist/form_validations/wavt_scripts_php.php"); ?>

<?php include('generalsettings.php'); ?>

<?php 

if (session_status() == PHP_SESSION_NONE) {

    session_start();

}

	if (!isset($_SESSION["idowneruser"])) {

		$_SESSION["iduserlogin"]=$iduserlogin;

	}

$iduserlog=$_SESSION["iduserlogin"];

$_SESSION["nameuser"]=$nameuser;

$_SESSION["compid"] = $idcompany;

$_SESSION["emailuser"]=$emailuser;

if (!isset($_SESSION["tempcode"])) {

$timestampnow=time();

$temporarycode=$iduserlog."-".$timestampnow;

$_SESSION["tempcode"]=$temporarycode;

$tempcode=$_SESSION["tempcode"];

	} else { $tempcode=$_SESSION["tempcode"]; }

?>

<?php  // session language

	

	// If present GET 'languageselect'

if(isset($_GET['languageselect']) && ($_GET['languageselect'] == 'it' || $_GET['languageselect'] == 'en')) {

    $_SESSION['langselect'] = $_GET['languageselect'];

} elseif (!isset($_SESSION['langselect'])) {

    // Use browser  language

    $browserLang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);

    

    if ($browserLang == 'en') {

        $_SESSION['langselect'] = 'en';

    } else {

        // Italian default

        $_SESSION['langselect'] = 'it';

    }

}

	

	

?>

<?php



// if undermanteinance

if ($undermanteinance == "yes" && $roleuser != 1 && $roleuser != 4 && $roleuser != 5) {

  header("Location: undermanteinance.php");

  exit();

}

?>

<?php 

//check privacy policy accepted

if (empty($privacyacc)) {

    header("location: privacyaccept.php");

die();

} 

    ?>

<?php 

if (isset($_GET['info'])) {

$infobox=$_GET['info'];

$_SESSION["infobox"]=$infobox;

} 

if (isset($_SESSION["infobox"])) {

	$infobox=$_SESSION["infobox"];

	} 

?>

<?php 

// Include files based on the language session

include('languages/' . $_SESSION['langselect'] . '/general.php');

include('languages/' . $_SESSION['langselect'] . '/questionaire.php'); 

?>

<!-- query languages -->

<?php

$langselect = new WA_MySQLi_RS("langselect",$cmctrfdb,1);

$langselect->setQuery("SELECT * FROM languages WHERE languages.idlanguages='$langid'");

$langselect->execute();

$lang=$langselect->getColumnVal("acronym_languages");

?>

<?php

$languageselection = new WA_MySQLi_RS("languageselection",$cmctrfdb,0);

$languageselection->setQuery("SELECT * FROM languages WHERE languages.active_languages='Y' ORDER BY languages.name_languages");

$languageselection->execute();

?>

<?php

$avat = new WA_MySQLi_RS("avat",$cmctrfdb,0);

$avat->setQuery("SELECT avatar,id FROM auth_users WHERE auth_users.id='$iduserlogin'");

$avat->execute();

$avatarname=$avat->getColumnVal("avatar");

?>

<?php

//$companydetails = new WA_MySQLi_RS("companydetails",$cmctrfdb,1);

//$companydetails->setQuery("SELECT * FROM company WHERE company.idcompany='1'");

//$companydetails->execute();

if (!isset($idcompany)) {

$InsertQuery = new WA_MySQLi_Query($cmctrfdb);

 $InsertQuery->Action = "insert";

 $InsertQuery->Table = "company";

 $InsertQuery->bindColumn("companyname_company", "s", "-", "WA_DEFAULT");

 $InsertQuery->saveInSession("");

 $InsertQuery->execute();

 $InsertGoTo = "";

$InsertQuery->redirect($InsertGoTo);



$lastcompany = new WA_MySQLi_RS("lastcompany",$cmctrfdb,1);

$lastcompany->setQuery("SELECT * FROM company ORDER BY company.idcompany DESC");

$lastcompany->execute();



   $lastcompanyid=$lastcompany->getColumnVal("idcompany");

    

$UpdateQuery = new WA_MySQLi_Query($cmctrfdb);

 $UpdateQuery->Action = "update";

 $UpdateQuery->Table = "auth_users";

 $UpdateQuery->bindColumn("idcompany", "i", "$lastcompanyid", "WA_DEFAULT");

 $UpdateQuery->addFilter("id", "=", "i", "".($iduserlogin)  ."");

 $UpdateQuery->execute();

 $UpdateGoTo = "";

$companyData["edited"]='N';

}

if (isset($idcompany)) {

$companydetails = mysqli_query($cmctrfdb, "SELECT * FROM company LEFT JOIN countries ON company.country_company=countries.idcountries WHERE company.idcompany='$idcompany'");

$companyData = mysqli_fetch_assoc($companydetails);

    $companyname=$companyData["companyname_company"];

	    $companyaddressfinal = $companyData["address_company"] . ' ' . $companyData["zip_company"] . '-' . $companyData["city_company"];

    $companylogo = $companyData["logoimage"];

//echo $companyData["companyname_company"];

	}

//security check only for USER

if (Auth::user()->hasRole('User')) :

include('securitycheck.php');

endif;

?>

<?php 

//check company profile filled

if ($companyData["edited"]!="Y") {

    

    header("location: companyprofile.php");

die();

}  

    

    ?>

<?php $titlepage = "TRF CIMAC"; ?>









