//Temporary content for coronavirus
require_once(__DIR__ . "/php/coronaVirusContent.php");
?>
//apache_request_headers workaround
if (!function_exists('apache_request_headers')) {
function apache_request_headers()
{
$arh = array();
$rx_http = '/\AHTTP_/';
foreach ($_SERVER as $key => $val) {
if (preg_match($rx_http, $key)) {
$arh_key = preg_replace($rx_http, '', $key);
$rx_matches = array();
// do some nasty string manipulations to restore the original letter case
// this should work in most cases
$rx_matches = explode('_', $arh_key);
if (count($rx_matches) > 0 and strlen($arh_key) > 2) {
foreach ($rx_matches as $ak_key => $ak_val)
$rx_matches[$ak_key] = ucfirst($ak_val);
$arh_key = implode('-', $rx_matches);
}
$arh[$arh_key] = $val;
}
}
return( $arh );
}
}
class Collections {
/*
This collection is used for partnerships, that have an GET parametrised link, which sets an ID at registration.
The cookie name is: "affiliate_partner_source"
The get parameter for the link is: "psrc"
The table links the value of "affiliate_partner_source" to an organisation ID
*/
public static $partner_ship_cookie_ids = [
"pslf" => 9, //psylife.de
"fb" => 12,
];
public static $partner_ship_cookie_name = "affiliate_partner_source";
//Localisation (at|de)
public static function getLocalisationAbbreviation(){
$header = apache_request_headers();
$arr = array("at");
if(array_key_exists("HOST", $header)) {
$arr = explode( '.', $header["HOST"]);
}
if(array_key_exists("Host", $header)) {
$arr = explode( '.', $header["Host"]);
}
return end($arr);
}
public static $localizationCode_Germany = "de";
public static $localizationCode_Austria = "at";
public static function getPhoneNumber(){
switch(Collections::getLocalisationAbbreviation()) {
case self::$localizationCode_Austria:
return "+43 664 97 62 617";
case self::$localizationCode_Germany:
return "+49 176 30 140 882";
default:
return "+43 664 97 62 617";
}
}
public static function getEmail(){
switch(Collections::getLocalisationAbbreviation()) {
case self::$localizationCode_Austria:
return "kontakt@therapsy.at";
break;
case self::$localizationCode_Germany:
return "kontakt@therapsy.de";
default:
return "kontakt@therapsy.at";
}
}
public static function getSupportUrl(){
return "https://therapsy-org.freshdesk.com/support/tickets/new";
}
public static function getSupportPageName(){
return "Fragen?";
}
public static function getHelpUrl(){
return "https://therapsy-org.freshdesk.com/support/solutions";
}
//API Call. Max 10_000/month
//all allowed countries: Polen;Tschchien;SLowakei;Ungarn;Slowenien;Italien;Frankreich;LichtenStein;Schweiz;Deutschland;Österreich;Luxemburg;Belgien;Niederlande;Dänemark
// country codes: PL;CZ;HU;SI;IT;FR;LI;CH;DE;AT;LU;BE;NL;DK
public static function CheckIfIPIsFromAllowedCountry(){
return true;
//
$ip = self::getUserIpAddr();
$json = file_get_contents("http://api.ipstack.com/$ip?access_key=9f30cd1917db30c15d5830748d0deae0&format=1");
$data = json_decode($json);
return in_array($data->country_code, array("PL", "CZ", "HU", "SI", "IT", "FR", "LI", "CH", "DE", "AT", "LU", "BE", "NL", "DK"));
}
public static function getUserIpAddr(){
if(!empty($_SERVER['HTTP_CLIENT_IP'])){
//ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
//ip pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
}
//if session handler is required once, then the global js variable testMode will be set!
require_once(dirname(__FILE__) . '/php/ConnectionFactory.php');
if(!isset($sessionHandlerSuppressOutput)){ //TODO: not really intuitive..
ConnectionFactory::InitTestModeInJS();
}
session_start();
if(isset($_SESSION["sessionid"])){
UpdateSQLSessionId();
}
//Updates the users webLastSessionActive param if the webSessionId is still valid
function UpdateSQLSessionId()
{
$con = ConnectionFactory::getFactory()->getConnection();
$sessionId = $_SESSION["sessionid"];
$stmt = $con->prepare("SELECT `webLastSessionActive` FROM `user` WHERE `user`.`webSessionId` = ?;");
$stmt->bind_param('s',$sessionId);
$stmt->execute();
$result = $stmt->get_result();
if($result === FALSE) {
echo 'unknown error
';
echo mysqli_error($con);
return;
}
$lastActive = mysqli_fetch_array($result)[0];
//echo "Last active is:";
//var_dump($lastActive);
$minLastActive = Date('Y-m-d H:i:s', strtotime("-1 day"));
//echo "
Must be younger than".$minLastActive;
if($lastActive < $minLastActive)
{
//Not okey
$_SESSION["inactive"]=1;
include "logout.php";
return;
}
//Update
$sessionLastActive = Date('Y-m-d H:i:s');
$sessionId = Sanitize($sessionId);
mysqli_query($con,"UPDATE `user` SET `webLastSessionActive` = '".$sessionLastActive."' WHERE `user`.`webSessionId` = '".$sessionId."';");
}
function GetSessionId()
{
if(isset($_SESSION["sessionid"]))
return $_SESSION["sessionid"];
else return 0;
}
function GoToIndex()
{
if(isset($_SESSION["sessionid"]))
return 0;
else return 1;
}
function IsLoggedIn(){
return !GoToIndex();
}
function GetUserData()
{
if(isset($_SESSION["sessionid"]) == false) return null;
$con = ConnectionFactory::getFactory()->getConnection();
$result = $con->query("SELECT name, stripeId, mail, org_id, affiliate_id, affiliate_src FROM `user` WHERE `user`.`webSessionId` = '".$_SESSION["sessionid"]."';");
if($result === FALSE) {
echo 'unknown error
';
echo mysqli_error($con);
return;
}
$res = $result->fetch_assoc();
//$res = mysqli_fetch_array($result);
//var_dump($res);
return $res;
}
//Helper Methods
function Sanitize($var)
{
//Strip tags, optionally strip or encode special characters.
return filter_var($var, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_BACKTICK || FILTER_FLAG_ENCODE_LOW || FILTER_FLAG_ENCODE_HIGH || FILTER_FLAG_ENCODE_AMP );
}
?>