<?php

namespace FOP;

class User {
  
  

    // --- Statische Eigenschaften ---
  
  static private $Columns_loaded = false;
  static private $superadmin ;
  static private $isFirstUser ;
  static private $isLoggedIn ;
  static private $isGuest ;
  static private $username ;
  static private $favorites ;
  static private $iD ;
  static private $wfcFopChatChatflow ;
  static private $admin ;
  static private $mitglied ;
  static private $gruppe ;
  static private $campaign ;
  static private $sammlung ;
  static private $buchhaltung ;
  static private $protokoll ;
  static private $dokument ;
  static private $badgeDoc ;
  static private $reminderMitgliedMitgliedGebtag ;
  static private $reminderMitgliedForderungen ;
  static private $reminderFopFintsBuchungForderungen ;
  static private $reminderAufgabeAssigned ;
  static private $reminderAufgabeNotAssigned ;

    // --- Statische Methoden ---
  
  public static function isOnLoginPage() { 
    
    
    // --- BLOCK: main ---
    global $_global_q; return strpos($_global_q, 'FOP/Login') == 0;
    
  }

  public static function updateColumns() { 
    
    
    // --- BLOCK: main ---
    
		$result = \FOP\Database::query('SELECT COUNT(*) AS cnt FROM '.qi('mitglied').'');
		$row = $result->fetch(\PDO::FETCH_ASSOC);
		if ($row && $row['cnt'] > 0) {
			// Es gibt User
			if (\FOP\User::getSessionUserID()) {
				// User-Credentials laden
				$sql = \FOP\Database::query('SELECT
					superadmin AS '.qi('superadmin').',
					fop_favorites AS '.qi('favorites').',
					'.qi('mitglied').'.'.qi('canAdmin').' AS '.qi('admin').',
					'.qi('mitglied').'.'.qi('canMitglied').' AS '.qi('mitglied').',
					'.qi('mitglied').'.'.qi('canGruppe').' AS '.qi('gruppe').',
					'.qi('mitglied').'.'.qi('canCampaign').' AS '.qi('campaign').',
					'.qi('mitglied').'.'.qi('canSammlung').' AS '.qi('sammlung').',
					'.qi('mitglied').'.'.qi('canBuchhaltung').' AS '.qi('buchhaltung').',
					'.qi('mitglied').'.'.qi('canProtokoll').' AS '.qi('protokoll').',
					'.qi('mitglied').'.'.qi('canDokument').' AS '.qi('dokument').',
					FALSE AS '.qi('isFirstUser').',
					TRUE AS '.qi('isLoggedIn').',
					FALSE AS '.qi('isGuest').',
					'.qi('ID').' AS '.qi('ID').',
					email AS '.qi('username').',
					(SELECT COUNT(*) FROM '.qi('fop_chat').' t  WHERE ('.qi('t').'.'.qi('ReportCount').') > (0)) AS '.qi('wfc_fop_chat_chatflow').'
				FROM '.qi('mitglied').' WHERE '.qi('ID').' = ' . \FOP\Database::quote(\FOP\User::getSessionUserID()));
				$result = $sql->fetch(\PDO::FETCH_ASSOC);
				if (!$result) {
					\FOP\User::logout(false);
					self::updateColumnsGuest();
				} else {
					self::$superadmin = ($result['superadmin']);
					self::$favorites = ($result['favorites']);
					self::$admin = (bool)($result['admin']);
					self::$mitglied = (bool)($result['mitglied']);
					self::$gruppe = (bool)($result['gruppe']);
					self::$campaign = (bool)($result['campaign']);
					self::$sammlung = (bool)($result['sammlung']);
					self::$buchhaltung = (bool)($result['buchhaltung']);
					self::$protokoll = (bool)($result['protokoll']);
					self::$dokument = (bool)($result['dokument']);
					self::$isFirstUser = ($result['isFirstUser']);
					self::$isLoggedIn = ($result['isLoggedIn']);
					self::$isGuest = ($result['isGuest']);
					self::$iD = ($result['ID']);
					self::$username = ($result['username']);
					self::$wfcFopChatChatflow = ($result['wfc_fop_chat_chatflow']);
					if (\FOP\Database::getDriver() == 'mysql') {
						\FOP\Database::query('SELECT @fop_user := ' . \FOP\Database::quote(\FOP\User::getID()));
					} else {
						\FOP\Database::query('SET SESSION "fop.user" = ' . \FOP\Database::quote(\FOP\User::getID()));
					}
				}
			} else {
				\FOP\User::logout(false);
			}
			if (!\FOP\User::getSessionUserID()) {
				// Gast-User
				self::updateColumnsGuest();
			}
		} else {
			// Default-User
			self::updateColumnsAdmin();
		}
		if (!self::isOnLoginPage() && !(!\FOP\User::getIsGuest())) {
			// Nicht ohne Login erlaubt
			header('Location: ' . \FOPRouter\Login::loginURL2(['from' => $_SERVER['REQUEST_URI']]));
			die();
		}
		
    
  }

  public static function updateColumnsAdmin() { 
    
    
    // --- BLOCK: main ---
    
		$sql = \FOP\Database::query('SELECT FALSE AS '.qi('superadmin').',
		\'[]\' AS '.qi('favorites').',
		TRUE AS '.qi('admin').',
		TRUE AS '.qi('mitglied').',
		TRUE AS '.qi('gruppe').',
		TRUE AS '.qi('campaign').',
		TRUE AS '.qi('sammlung').',
		TRUE AS '.qi('buchhaltung').',
		TRUE AS '.qi('protokoll').',
		TRUE AS '.qi('dokument').',
		TRUE AS '.qi('isFirstUser').',
		FALSE AS '.qi('isLoggedIn').',
		FALSE AS '.qi('isGuest').',
		NULL AS '.qi('ID').',
		NULL AS '.qi('username').',
		(SELECT COUNT(*) FROM '.qi('fop_chat').' t  WHERE ('.qi('t').'.'.qi('ReportCount').') > (0)) AS '.qi('wfc_fop_chat_chatflow').'');
		$result = $sql->fetch(\PDO::FETCH_ASSOC);
		self::$superadmin = ($result['superadmin']);
		self::$favorites = ($result['favorites']);
		self::$admin = (bool)($result['admin']);
		self::$mitglied = (bool)($result['mitglied']);
		self::$gruppe = (bool)($result['gruppe']);
		self::$campaign = (bool)($result['campaign']);
		self::$sammlung = (bool)($result['sammlung']);
		self::$buchhaltung = (bool)($result['buchhaltung']);
		self::$protokoll = (bool)($result['protokoll']);
		self::$dokument = (bool)($result['dokument']);
		self::$isFirstUser = ($result['isFirstUser']);
		self::$isLoggedIn = ($result['isLoggedIn']);
		self::$isGuest = ($result['isGuest']);
		self::$iD = ($result['ID']);
		self::$username = ($result['username']);
		self::$wfcFopChatChatflow = ($result['wfc_fop_chat_chatflow']);
	
    
  }

  public static function updateColumnsGuest() { 
    
    
    // --- BLOCK: main ---
    
		$sql = \FOP\Database::query('SELECT FALSE AS '.qi('superadmin').',
		\'[]\' AS '.qi('favorites').',
		FALSE AS '.qi('admin').',
		FALSE AS '.qi('mitglied').',
		FALSE AS '.qi('gruppe').',
		FALSE AS '.qi('campaign').',
		FALSE AS '.qi('sammlung').',
		FALSE AS '.qi('buchhaltung').',
		FALSE AS '.qi('protokoll').',
		FALSE AS '.qi('dokument').',
		FALSE AS '.qi('isFirstUser').',
		FALSE AS '.qi('isLoggedIn').',
		TRUE AS '.qi('isGuest').',
		NULL AS '.qi('ID').',
		NULL AS '.qi('username').',
		0 AS '.qi('wfc_fop_chat_chatflow').'');
		$result = $sql->fetch(\PDO::FETCH_ASSOC);
		self::$superadmin = ($result['superadmin']);
		self::$favorites = ($result['favorites']);
		self::$admin = (bool)($result['admin']);
		self::$mitglied = (bool)($result['mitglied']);
		self::$gruppe = (bool)($result['gruppe']);
		self::$campaign = (bool)($result['campaign']);
		self::$sammlung = (bool)($result['sammlung']);
		self::$buchhaltung = (bool)($result['buchhaltung']);
		self::$protokoll = (bool)($result['protokoll']);
		self::$dokument = (bool)($result['dokument']);
		self::$isFirstUser = ($result['isFirstUser']);
		self::$isLoggedIn = ($result['isLoggedIn']);
		self::$isGuest = ($result['isGuest']);
		self::$iD = ($result['ID']);
		self::$username = ($result['username']);
		self::$wfcFopChatChatflow = ($result['wfc_fop_chat_chatflow']);
	
    
  }

  public static function updateColumnExpressions() { 
    
    
    // --- BLOCK: main ---
    
		
		$usercount = \FOP\Database::query('SELECT COUNT(*) FROM '.qi('mitglied').'')->fetchColumn();
		if ($usercount > 0) {
			if (self::getSessionUserID()) {
				// logged-in user
				$sql = \FOP\Database::query('SELECT 1
				, (SELECT COUNT(1) FROM '.qi('doc').' '.qi('Oxiee09T').' WHERE TRUE AND (((((SELECT Tables_Doc_defaultDoctype FROM userconfig WHERE userconfig.'.qi('ID').' = 1 LIMIT 1)) IS NULL) AND (('.qi('Oxiee09T').'.'.qi('type').') IS NULL)) OR (('.qi('Oxiee09T').'.'.qi('type').') = ((SELECT Tables_Doc_defaultDoctype FROM userconfig WHERE userconfig.'.qi('ID').' = 1 LIMIT 1)))) LIMIT 1) AS '.qi('badgeDoc').'
				, (SELECT SUM(1) FROM '.qi('mitglied').' '.qi('sIymC3uL').' WHERE TRUE AND ('.(\FOP\Database::getDriver() == 'mysql' ? ''.qi('geburtsdatum').' IS NOT NULL AND (UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(0) + INTERVAL ('.qi('geburtsdatum').') SECOND, INTERVAL (GREATEST(0, (YEAR(NOW()) -  YEAR(FROM_UNIXTIME(0) + INTERVAL ('.qi('geburtsdatum').') SECOND)))) YEAR))) BETWEEN (UNIX_TIMESTAMP()-((7)*24*3600)) AND (UNIX_TIMESTAMP()+((7)*24*3600))' : 'FALSE').') AND ((CASE WHEN '.\FOP\Database::quote(\FOP\User::getGruppe()).' THEN TRUE ELSE NOT (('.qi('sIymC3uL').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getMitglied()).' THEN TRUE ELSE NOT ((('.qi('sIymC3uL').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) AND (NOT (EXISTS (SELECT (TRUE) FROM '.qi('gruppeItem').' '.qi('7sncgH3z').' WHERE '.qi('7sncgH3z').'.'.qi('item').' = '.qi('sIymC3uL').'.'.qi('ID').' AND (EXISTS (SELECT (TRUE) FROM '.qi('gruppeVerantwortlich').' '.qi('eHueOsQC').' WHERE '.qi('eHueOsQC').'.'.qi('gruppe').' = '.qi('7sncgH3z').'.'.qi('list').' AND (('.qi('eHueOsQC').'.'.qi('mitglied').') = ('.\FOP\Database::sessionVarSQL('user').')) LIMIT 1)) LIMIT 1)))) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getSuperadmin()).' THEN TRUE ELSE NOT ('.qi('sIymC3uL').'.'.qi('superadmin').') END)) LIMIT 1) AS '.qi('reminderMitgliedMitglied-gebtag').'
				, (SELECT SUM(1) FROM '.qi('mitglied').' '.qi('01xBBrRO').' WHERE TRUE AND (((SELECT SUM('.qi('rhU469mT').'.'.qi('betrag').') FROM '.qi('mitgliedBuchung').' '.qi('rhU469mT').' WHERE '.qi('rhU469mT').'.'.qi('mitglied').' = '.qi('01xBBrRO').'.'.qi('ID').' LIMIT 1)) < (0)) AND ((CASE WHEN '.\FOP\Database::quote(\FOP\User::getGruppe()).' THEN TRUE ELSE NOT (('.qi('01xBBrRO').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getMitglied()).' THEN TRUE ELSE NOT ((('.qi('01xBBrRO').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) AND (NOT (EXISTS (SELECT (TRUE) FROM '.qi('gruppeItem').' '.qi('7sncgH3z').' WHERE '.qi('7sncgH3z').'.'.qi('item').' = '.qi('01xBBrRO').'.'.qi('ID').' AND (EXISTS (SELECT (TRUE) FROM '.qi('gruppeVerantwortlich').' '.qi('eHueOsQC').' WHERE '.qi('eHueOsQC').'.'.qi('gruppe').' = '.qi('7sncgH3z').'.'.qi('list').' AND (('.qi('eHueOsQC').'.'.qi('mitglied').') = ('.\FOP\Database::sessionVarSQL('user').')) LIMIT 1)) LIMIT 1)))) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getSuperadmin()).' THEN TRUE ELSE NOT ('.qi('01xBBrRO').'.'.qi('superadmin').') END)) LIMIT 1) AS '.qi('reminderMitgliedForderungen').'
				, (SELECT SUM(1) FROM '.qi('fop_fints_buchung').' '.qi('kMu7e9od').' WHERE TRUE AND ((('.qi('kMu7e9od').'.'.qi('betrag').') > (0)) AND ((COALESCE('.qi('kMu7e9od').'.'.qi('forderungDone').', 0)) = (0)) AND (NOT (EXISTS (SELECT (TRUE) FROM '.qi('mitgliedBuchung').' '.qi('TNKirKfk').' WHERE '.qi('TNKirKfk').'.'.qi('bank').' = '.qi('kMu7e9od').'.'.qi('ID').' LIMIT 1)))) AND (('.\FOP\Database::quote(\FOP\User::getBuchhaltung()).') AND (COALESCE((SELECT ('.\FOP\Database::quote(\FOP\User::getBuchhaltung()).') FROM '.qi('fop_fints_konto').' '.qi('ztZvmiXX').' WHERE '.qi('ztZvmiXX').'.'.qi('ID').' = '.qi('kMu7e9od').'.'.qi('konto').' LIMIT 1), FALSE)) AND ('.\FOP\Database::quote(\FOP\User::getBuchhaltung()).')) LIMIT 1) AS '.qi('reminderFop_fints_buchungForderungen').'
				, (SELECT SUM(NOT ((SELECT ('.qi('6mXALToS').'.'.qi('final').') FROM '.qi('aufgabeState').' '.qi('6mXALToS').' WHERE '.qi('6mXALToS').'.'.qi('ID').' = '.qi('u7nPb11S').'.'.qi('state').' LIMIT 1))) FROM '.qi('aufgabe').' '.qi('u7nPb11S').' WHERE TRUE AND ((SELECT (('.qi('SHVgFwJG').'.'.qi('ID').') = ('.\FOP\Database::sessionVarSQL('user').')) FROM '.qi('mitglied').' '.qi('SHVgFwJG').' WHERE '.qi('SHVgFwJG').'.'.qi('ID').' = '.qi('u7nPb11S').'.'.qi('assigned').' LIMIT 1)) AND (TRUE) LIMIT 1) AS '.qi('reminderAufgabeAssigned').'
				, (SELECT SUM(NOT ((SELECT ('.qi('VKVZib8X').'.'.qi('final').') FROM '.qi('aufgabeState').' '.qi('VKVZib8X').' WHERE '.qi('VKVZib8X').'.'.qi('ID').' = '.qi('D2CM7zfY').'.'.qi('state').' LIMIT 1))) FROM '.qi('aufgabe').' '.qi('D2CM7zfY').' WHERE TRUE AND (('.qi('D2CM7zfY').'.'.qi('assigned').') IS NULL) AND (TRUE) LIMIT 1) AS '.qi('reminderAufgabeNot_assigned').' FROM '.qi('mitglied').' WHERE '.qi('ID').' = ' . \FOP\Database::quote(\FOP\User::getSessionUserId()));
			} else {
				// guest
				$sql = \FOP\Database::query('SELECT 1,
				(SELECT COUNT(1) FROM '.qi('doc').' '.qi('Oxiee09T').' WHERE TRUE AND (((((SELECT Tables_Doc_defaultDoctype FROM userconfig WHERE userconfig.'.qi('ID').' = 1 LIMIT 1)) IS NULL) AND (('.qi('Oxiee09T').'.'.qi('type').') IS NULL)) OR (('.qi('Oxiee09T').'.'.qi('type').') = ((SELECT Tables_Doc_defaultDoctype FROM userconfig WHERE userconfig.'.qi('ID').' = 1 LIMIT 1)))) LIMIT 1) AS '.qi('badgeDoc').',
				(SELECT SUM(1) FROM '.qi('mitglied').' '.qi('sIymC3uL').' WHERE TRUE AND ('.(\FOP\Database::getDriver() == 'mysql' ? ''.qi('geburtsdatum').' IS NOT NULL AND (UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(0) + INTERVAL ('.qi('geburtsdatum').') SECOND, INTERVAL (GREATEST(0, (YEAR(NOW()) -  YEAR(FROM_UNIXTIME(0) + INTERVAL ('.qi('geburtsdatum').') SECOND)))) YEAR))) BETWEEN (UNIX_TIMESTAMP()-((7)*24*3600)) AND (UNIX_TIMESTAMP()+((7)*24*3600))' : 'FALSE').') AND ((CASE WHEN '.\FOP\Database::quote(\FOP\User::getGruppe()).' THEN TRUE ELSE NOT (('.qi('sIymC3uL').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getMitglied()).' THEN TRUE ELSE NOT ((('.qi('sIymC3uL').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) AND (NOT (EXISTS (SELECT (TRUE) FROM '.qi('gruppeItem').' '.qi('7sncgH3z').' WHERE '.qi('7sncgH3z').'.'.qi('item').' = '.qi('sIymC3uL').'.'.qi('ID').' AND (EXISTS (SELECT (TRUE) FROM '.qi('gruppeVerantwortlich').' '.qi('eHueOsQC').' WHERE '.qi('eHueOsQC').'.'.qi('gruppe').' = '.qi('7sncgH3z').'.'.qi('list').' AND (('.qi('eHueOsQC').'.'.qi('mitglied').') = ('.\FOP\Database::sessionVarSQL('user').')) LIMIT 1)) LIMIT 1)))) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getSuperadmin()).' THEN TRUE ELSE NOT ('.qi('sIymC3uL').'.'.qi('superadmin').') END)) LIMIT 1) AS '.qi('reminderMitgliedMitglied-gebtag').',
				(SELECT SUM(1) FROM '.qi('mitglied').' '.qi('01xBBrRO').' WHERE TRUE AND (((SELECT SUM('.qi('rhU469mT').'.'.qi('betrag').') FROM '.qi('mitgliedBuchung').' '.qi('rhU469mT').' WHERE '.qi('rhU469mT').'.'.qi('mitglied').' = '.qi('01xBBrRO').'.'.qi('ID').' LIMIT 1)) < (0)) AND ((CASE WHEN '.\FOP\Database::quote(\FOP\User::getGruppe()).' THEN TRUE ELSE NOT (('.qi('01xBBrRO').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getMitglied()).' THEN TRUE ELSE NOT ((('.qi('01xBBrRO').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) AND (NOT (EXISTS (SELECT (TRUE) FROM '.qi('gruppeItem').' '.qi('7sncgH3z').' WHERE '.qi('7sncgH3z').'.'.qi('item').' = '.qi('01xBBrRO').'.'.qi('ID').' AND (EXISTS (SELECT (TRUE) FROM '.qi('gruppeVerantwortlich').' '.qi('eHueOsQC').' WHERE '.qi('eHueOsQC').'.'.qi('gruppe').' = '.qi('7sncgH3z').'.'.qi('list').' AND (('.qi('eHueOsQC').'.'.qi('mitglied').') = ('.\FOP\Database::sessionVarSQL('user').')) LIMIT 1)) LIMIT 1)))) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getSuperadmin()).' THEN TRUE ELSE NOT ('.qi('01xBBrRO').'.'.qi('superadmin').') END)) LIMIT 1) AS '.qi('reminderMitgliedForderungen').',
				(SELECT SUM(1) FROM '.qi('fop_fints_buchung').' '.qi('kMu7e9od').' WHERE TRUE AND ((('.qi('kMu7e9od').'.'.qi('betrag').') > (0)) AND ((COALESCE('.qi('kMu7e9od').'.'.qi('forderungDone').', 0)) = (0)) AND (NOT (EXISTS (SELECT (TRUE) FROM '.qi('mitgliedBuchung').' '.qi('TNKirKfk').' WHERE '.qi('TNKirKfk').'.'.qi('bank').' = '.qi('kMu7e9od').'.'.qi('ID').' LIMIT 1)))) AND (('.\FOP\Database::quote(\FOP\User::getBuchhaltung()).') AND (COALESCE((SELECT ('.\FOP\Database::quote(\FOP\User::getBuchhaltung()).') FROM '.qi('fop_fints_konto').' '.qi('ztZvmiXX').' WHERE '.qi('ztZvmiXX').'.'.qi('ID').' = '.qi('kMu7e9od').'.'.qi('konto').' LIMIT 1), FALSE)) AND ('.\FOP\Database::quote(\FOP\User::getBuchhaltung()).')) LIMIT 1) AS '.qi('reminderFop_fints_buchungForderungen').',
				(SELECT SUM(NOT ((SELECT ('.qi('6mXALToS').'.'.qi('final').') FROM '.qi('aufgabeState').' '.qi('6mXALToS').' WHERE '.qi('6mXALToS').'.'.qi('ID').' = '.qi('u7nPb11S').'.'.qi('state').' LIMIT 1))) FROM '.qi('aufgabe').' '.qi('u7nPb11S').' WHERE TRUE AND ((SELECT (('.qi('SHVgFwJG').'.'.qi('ID').') = ('.\FOP\Database::sessionVarSQL('user').')) FROM '.qi('mitglied').' '.qi('SHVgFwJG').' WHERE '.qi('SHVgFwJG').'.'.qi('ID').' = '.qi('u7nPb11S').'.'.qi('assigned').' LIMIT 1)) AND (TRUE) LIMIT 1) AS '.qi('reminderAufgabeAssigned').',
				(SELECT SUM(NOT ((SELECT ('.qi('VKVZib8X').'.'.qi('final').') FROM '.qi('aufgabeState').' '.qi('VKVZib8X').' WHERE '.qi('VKVZib8X').'.'.qi('ID').' = '.qi('D2CM7zfY').'.'.qi('state').' LIMIT 1))) FROM '.qi('aufgabe').' '.qi('D2CM7zfY').' WHERE TRUE AND (('.qi('D2CM7zfY').'.'.qi('assigned').') IS NULL) AND (TRUE) LIMIT 1) AS '.qi('reminderAufgabeNot_assigned').'');
			}
		} else {
			// Default user
			$sql = \FOP\Database::query('SELECT 1,
			(SELECT COUNT(1) FROM '.qi('doc').' '.qi('Oxiee09T').' WHERE TRUE AND (((((SELECT Tables_Doc_defaultDoctype FROM userconfig WHERE userconfig.'.qi('ID').' = 1 LIMIT 1)) IS NULL) AND (('.qi('Oxiee09T').'.'.qi('type').') IS NULL)) OR (('.qi('Oxiee09T').'.'.qi('type').') = ((SELECT Tables_Doc_defaultDoctype FROM userconfig WHERE userconfig.'.qi('ID').' = 1 LIMIT 1)))) LIMIT 1) AS '.qi('badgeDoc').',
			(SELECT SUM(1) FROM '.qi('mitglied').' '.qi('sIymC3uL').' WHERE TRUE AND ('.(\FOP\Database::getDriver() == 'mysql' ? ''.qi('geburtsdatum').' IS NOT NULL AND (UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(0) + INTERVAL ('.qi('geburtsdatum').') SECOND, INTERVAL (GREATEST(0, (YEAR(NOW()) -  YEAR(FROM_UNIXTIME(0) + INTERVAL ('.qi('geburtsdatum').') SECOND)))) YEAR))) BETWEEN (UNIX_TIMESTAMP()-((7)*24*3600)) AND (UNIX_TIMESTAMP()+((7)*24*3600))' : 'FALSE').') AND ((CASE WHEN '.\FOP\Database::quote(\FOP\User::getGruppe()).' THEN TRUE ELSE NOT (('.qi('sIymC3uL').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getMitglied()).' THEN TRUE ELSE NOT ((('.qi('sIymC3uL').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) AND (NOT (EXISTS (SELECT (TRUE) FROM '.qi('gruppeItem').' '.qi('7sncgH3z').' WHERE '.qi('7sncgH3z').'.'.qi('item').' = '.qi('sIymC3uL').'.'.qi('ID').' AND (EXISTS (SELECT (TRUE) FROM '.qi('gruppeVerantwortlich').' '.qi('eHueOsQC').' WHERE '.qi('eHueOsQC').'.'.qi('gruppe').' = '.qi('7sncgH3z').'.'.qi('list').' AND (('.qi('eHueOsQC').'.'.qi('mitglied').') = ('.\FOP\Database::sessionVarSQL('user').')) LIMIT 1)) LIMIT 1)))) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getSuperadmin()).' THEN TRUE ELSE NOT ('.qi('sIymC3uL').'.'.qi('superadmin').') END)) LIMIT 1) AS '.qi('reminderMitgliedMitglied-gebtag').',
			(SELECT SUM(1) FROM '.qi('mitglied').' '.qi('01xBBrRO').' WHERE TRUE AND (((SELECT SUM('.qi('rhU469mT').'.'.qi('betrag').') FROM '.qi('mitgliedBuchung').' '.qi('rhU469mT').' WHERE '.qi('rhU469mT').'.'.qi('mitglied').' = '.qi('01xBBrRO').'.'.qi('ID').' LIMIT 1)) < (0)) AND ((CASE WHEN '.\FOP\Database::quote(\FOP\User::getGruppe()).' THEN TRUE ELSE NOT (('.qi('01xBBrRO').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getMitglied()).' THEN TRUE ELSE NOT ((('.qi('01xBBrRO').'.'.qi('ID').') <> ('.\FOP\Database::sessionVarSQL('user').')) AND (NOT (EXISTS (SELECT (TRUE) FROM '.qi('gruppeItem').' '.qi('7sncgH3z').' WHERE '.qi('7sncgH3z').'.'.qi('item').' = '.qi('01xBBrRO').'.'.qi('ID').' AND (EXISTS (SELECT (TRUE) FROM '.qi('gruppeVerantwortlich').' '.qi('eHueOsQC').' WHERE '.qi('eHueOsQC').'.'.qi('gruppe').' = '.qi('7sncgH3z').'.'.qi('list').' AND (('.qi('eHueOsQC').'.'.qi('mitglied').') = ('.\FOP\Database::sessionVarSQL('user').')) LIMIT 1)) LIMIT 1)))) END) AND (CASE WHEN '.\FOP\Database::quote(\FOP\User::getSuperadmin()).' THEN TRUE ELSE NOT ('.qi('01xBBrRO').'.'.qi('superadmin').') END)) LIMIT 1) AS '.qi('reminderMitgliedForderungen').',
			(SELECT SUM(1) FROM '.qi('fop_fints_buchung').' '.qi('kMu7e9od').' WHERE TRUE AND ((('.qi('kMu7e9od').'.'.qi('betrag').') > (0)) AND ((COALESCE('.qi('kMu7e9od').'.'.qi('forderungDone').', 0)) = (0)) AND (NOT (EXISTS (SELECT (TRUE) FROM '.qi('mitgliedBuchung').' '.qi('TNKirKfk').' WHERE '.qi('TNKirKfk').'.'.qi('bank').' = '.qi('kMu7e9od').'.'.qi('ID').' LIMIT 1)))) AND (('.\FOP\Database::quote(\FOP\User::getBuchhaltung()).') AND (COALESCE((SELECT ('.\FOP\Database::quote(\FOP\User::getBuchhaltung()).') FROM '.qi('fop_fints_konto').' '.qi('ztZvmiXX').' WHERE '.qi('ztZvmiXX').'.'.qi('ID').' = '.qi('kMu7e9od').'.'.qi('konto').' LIMIT 1), FALSE)) AND ('.\FOP\Database::quote(\FOP\User::getBuchhaltung()).')) LIMIT 1) AS '.qi('reminderFop_fints_buchungForderungen').',
			(SELECT SUM(NOT ((SELECT ('.qi('6mXALToS').'.'.qi('final').') FROM '.qi('aufgabeState').' '.qi('6mXALToS').' WHERE '.qi('6mXALToS').'.'.qi('ID').' = '.qi('u7nPb11S').'.'.qi('state').' LIMIT 1))) FROM '.qi('aufgabe').' '.qi('u7nPb11S').' WHERE TRUE AND ((SELECT (('.qi('SHVgFwJG').'.'.qi('ID').') = ('.\FOP\Database::sessionVarSQL('user').')) FROM '.qi('mitglied').' '.qi('SHVgFwJG').' WHERE '.qi('SHVgFwJG').'.'.qi('ID').' = '.qi('u7nPb11S').'.'.qi('assigned').' LIMIT 1)) AND (TRUE) LIMIT 1) AS '.qi('reminderAufgabeAssigned').',
			(SELECT SUM(NOT ((SELECT ('.qi('VKVZib8X').'.'.qi('final').') FROM '.qi('aufgabeState').' '.qi('VKVZib8X').' WHERE '.qi('VKVZib8X').'.'.qi('ID').' = '.qi('D2CM7zfY').'.'.qi('state').' LIMIT 1))) FROM '.qi('aufgabe').' '.qi('D2CM7zfY').' WHERE TRUE AND (('.qi('D2CM7zfY').'.'.qi('assigned').') IS NULL) AND (TRUE) LIMIT 1) AS '.qi('reminderAufgabeNot_assigned').'');
		}
		$result = $sql->fetch(\PDO::FETCH_ASSOC);
		self::$badgeDoc = ($result['badgeDoc']);
		self::$reminderMitgliedMitgliedGebtag = ($result['reminderMitgliedMitglied-gebtag']);
		self::$reminderMitgliedForderungen = ($result['reminderMitgliedForderungen']);
		self::$reminderFopFintsBuchungForderungen = ($result['reminderFop_fints_buchungForderungen']);
		self::$reminderAufgabeAssigned = ($result['reminderAufgabeAssigned']);
		self::$reminderAufgabeNotAssigned = ($result['reminderAufgabeNot_assigned']);
		self::$Columns_loaded = true;
	
    
  }

  public static function getSuperUserName() { 
    
    
    // --- BLOCK: main ---
    return \FOP\Configuration::getFOPUserSuperUserName();
    
  }

  public static function getSuperUserPass() { 
    
    
    // --- BLOCK: main ---
    return \FOP\Configuration::getFOPUserSuperUserPass();
    
  }

  public static function getSessionUserID() { 
    
    
    // --- BLOCK: main ---
    
		return \FOP\Session::getUser();
    
  }

  public static function ensureIsLoaded() { 
    
    
    // --- BLOCK: main ---
    
  // Can be called to ensure class is loaded and initialized

    
  }

  public static function sendPassword($id) { 
    
    
    // --- BLOCK: main ---
    
		//Get Email and Username
		$user = \FOP\Database::query('SELECT '.qi('mitglied').'.'.qi('email').' AS email, '.qi('email').' AS name FROM '.qi('mitglied').' WHERE ID = ' . intval($id))->fetch(\PDO::FETCH_ASSOC);
		
		if ($user){
			//Generate Password
			$random = base64_encode((openssl_random_pseudo_bytes(12)));
			$pw = substr($random, 0, strlen($random) - 2);
			$encpw = password_hash($pw, PASSWORD_BCRYPT);

			ob_start();
			?>
Dein ERPL-Sport-Zugang ist da!
<br><br>


			<br><hr><b>Benutzer: </b><?php echo htmlentities($user['name']); ?><br><b>Ihr neues Passwort: </b><?php echo htmlentities($pw); ?><br>Sie können sich unter <a href="<?php echo htmlentities(\FOP\Configuration::getBaseurl()); ?>"><?php echo htmlentities(\FOP\Configuration::getBaseurl()); ?></a> anmelden.<hr>

			
Viel Spaß mit deinem Zugang.
<br><br>
<b>Dein Lieblingsverein</b>
<?php
			$message = ob_get_contents();
			ob_end_clean();

			// Send Email
			$mailer = \Mailer\Mails::getMailer();
			$mailer->addAddress($user['email']);
			$mailer->Subject = "Ihre Zugangsdaten";
			$mailer->msgHTML($message);

			if ($mailer->send()) {
				\FOP\Database::query('UPDATE '.qi('mitglied').' SET '.qi('password').' = ' . \FOP\Database::quote($encpw) . ' WHERE ID = ' . intval($id));
				return true;
			} else {
				return false;
			}
		}
		return false;
	
    
  }

  public static function logout($writeSession = true ) { 
    
    
    // --- BLOCK: main ---
    
		\FOP\Session::setUser(null, $writeSession);
		
    
  }

  public static function login($id, $writeSession = true ) { 
    
    
    // --- BLOCK: main ---
    
		/* Software-Contract zum Schreiben von Funktionen:

		1. Sobald der Wert von SessionUserID oder UserID gesetzt oder geändert wird, muss eine der folgendene Funktionen aufgerufen werden:
			- updateColumnsGuest()
			- updateColumnsAdmin()
			- updateColumns()
		2. Sobald man eine Aktion betritt, müssen die FOP-User-Felder befüllt sein
		3. Es muss möglich sein, verschachtelte User-IDs zu wechseln (zB. in delayedmethods)
		4. Ein Funktionsaufruf muss zum Ende mit dem selben Benutzer eingeloggt sein, wie am Anfang der Funktion (Ausnahme von login() und logout())
			=> Die Funktion muss den Benutzer selbst wiederherstellen

		Diese Regeln gelten für alle Entwickler und sind ohne Zustimmung wirksam

		*/

		
		\FOP\Session::setUser($id, $writeSession);
		
    
  }

  public static function getSuperadmin() { 
    
    
    // --- BLOCK: getter ---
    return self::$superadmin;
    
  }

  public static function getIsFirstUser() { 
    
    
    // --- BLOCK: getter ---
    return self::$isFirstUser;
    
  }

  public static function getIsLoggedIn() { 
    
    
    // --- BLOCK: getter ---
    return self::$isLoggedIn;
    
  }

  public static function getIsGuest() { 
    
    
    // --- BLOCK: getter ---
    return self::$isGuest;
    
  }

  public static function getUsername() { 
    
    
    // --- BLOCK: getter ---
    return self::$username;
    
  }

  public static function getBadgeDoc() { 
    
    
    // --- BLOCK: getter ---
    return self::$badgeDoc;
    
  }

  public static function getReminderMitgliedMitgliedGebtag() { 
    
    
    // --- BLOCK: getter ---
    return self::$reminderMitgliedMitgliedGebtag;
    
  }

  public static function getReminderMitgliedForderungen() { 
    
    
    // --- BLOCK: getter ---
    return self::$reminderMitgliedForderungen;
    
  }

  public static function getReminderFopFintsBuchungForderungen() { 
    
    
    // --- BLOCK: getter ---
    return self::$reminderFopFintsBuchungForderungen;
    
  }

  public static function getFavorites() { 
    
    
    // --- BLOCK: getter ---
    return self::$favorites;
    
  }

  public static function getID() { 
    
    
    // --- BLOCK: getter ---
    return self::$iD;
    
  }

  public static function getWfcFopChatChatflow() { 
    
    
    // --- BLOCK: getter ---
    return self::$wfcFopChatChatflow;
    
  }

  public static function getReminderAufgabeAssigned() { 
    
    
    // --- BLOCK: getter ---
    return self::$reminderAufgabeAssigned;
    
  }

  public static function getReminderAufgabeNotAssigned() { 
    
    
    // --- BLOCK: getter ---
    return self::$reminderAufgabeNotAssigned;
    
  }

  public static function getAdmin() { 
    
    
    // --- BLOCK: getter ---
    return self::$admin;
    
  }

  public static function getMitglied() { 
    
    
    // --- BLOCK: getter ---
    return self::$mitglied;
    
  }

  public static function getGruppe() { 
    
    
    // --- BLOCK: getter ---
    return self::$gruppe;
    
  }

  public static function getCampaign() { 
    
    
    // --- BLOCK: getter ---
    return self::$campaign;
    
  }

  public static function getSammlung() { 
    
    
    // --- BLOCK: getter ---
    return self::$sammlung;
    
  }

  public static function getBuchhaltung() { 
    
    
    // --- BLOCK: getter ---
    return self::$buchhaltung;
    
  }

  public static function getProtokoll() { 
    
    
    // --- BLOCK: getter ---
    return self::$protokoll;
    
  }

  public static function getDokument() { 
    
    
    // --- BLOCK: getter ---
    return self::$dokument;
    
  }

  public static function initialize() { 
    
    
    // --- BLOCK: init ---
    
		// hooks here
	
    // --- BLOCK: main ---
    
		self::updateColumns();
	
    
  }


  
  

  
  
}

\FOP\User::initialize(); 

