<?php
    spl_autoload_register(function($class){
        // \ mit / ersetzen
        $slashes = str_replace("\\", "/", $class);

        // Klasse in lib/namespace/klassenname.php suchen und ggf. reinladen
        $dir = dirname(__FILE__);
        $filename = $dir . '/lib/' . $slashes . '.php';

        if(file_exists($filename)){
            require_once($filename);
        }
    });

    
    if(basename($_SERVER['SCRIPT_NAME']) != "dbcheck.php" && basename($_SERVER['SCRIPT_NAME']) != "setup.php") \FOP\I18n::initialize();
    
    if(basename($_SERVER['SCRIPT_NAME']) != "dbcheck.php" && basename($_SERVER['SCRIPT_NAME']) != "setup.php") \FOP\Cron::initialize();
    
    if(basename($_SERVER['SCRIPT_NAME']) != "dbcheck.php" && basename($_SERVER['SCRIPT_NAME']) != "setup.php") \FOP\User::initialize();
    
?><?php function qi($s){return \FOP\Database::quoteIdent($s);} ?><!DOCTYPE html>
<html>
	<body>
		<script src="js/script_dependencies.js"></script>
		<?php if ($_GET['action'] == "popup") { ?>
			<?php if (isset($_GET['colinsert']) && isset($_GET['el']) && isset($_GET['colvalue'])) { ?>
				<script type="text/javascript">

					window.onload = function () { setTimeout(function () {
						var parent = (window.myparent || window.opener || window.parent)
						var input = parent.$('#<?php echo htmlspecialchars($_GET['el']); ?>', parent.document);
						var select = input.find('select');
						if (input[0] && input[0].dataset.callback) {
							// callback (and let the parent do the rest)
							parent[input[0].dataset.callback](<?php echo json_encode($_GET['colvalue']); ?>, <?php echo json_encode(\FOP\Types::renderString($_GET['type'], $_GET['colvalue'])); ?>);
						} else if (select.length) {
							select.parent().find('.fop-remove-after-change').remove();
							// if there is a select field: add option
							var o;
							o = select.find('option[value=<?php echo json_encode($_GET['colvalue']); ?>]');
							if (o.length == 0) {
								o = $('<option></option>').text(<?php echo json_encode(\FOP\Types::renderString($_GET['type'], $_GET['colvalue'])); ?>).val(<?php echo json_encode($_GET['colvalue']); ?>);
								select.append(o);
							}
							select.val(o.val());
							select.change();
						} else {
							// if there is no select field: text+hidden
							input.html('<?php if (isset($_GET['type'])) { ?><p>' + <?php echo json_encode(\FOP\Types::renderString($_GET['type'], $_GET['colvalue'])); ?> + '</p><?php } ?><input type="hidden" name="<?php echo htmlentities($_GET['colinsert']); ?>" value="<?php echo htmlentities($_GET['colvalue']); ?>">');
						}
						<?php if (isset($_GET['click'])) { ?>
							parent.$(<?php echo json_encode($_GET['click']); ?>, parent.document).click();
						<?php } ?>
						// schedule after load to wait for iframe window.close overload
						window.close();
						<?php
						if (isset($_GET['ng'])) {
							?>
							input.scope().<?php echo $_GET['ng']; ?> = <?php echo json_encode($_GET['colvalue']); ?>;
							input.scope().$apply();
							<?php
						}
						?>
					}, 0); }
				</script>
			<?php } else if (isset($_GET['close'])) { ?>
				<script type="text/javascript">
					// schedule after load to wait for iframe window.close overload
					document.body.onload = function () {
						setTimeout(function () {
							window.close();
						}, 0);
					};
			</script>
			<?php } else { ?>
				<script type="text/javascript">
				window.onload = function () { setTimeout(function () {
					if (window.myparent) {
						window.myparent.location.reload();
						window.close();
					} else if (window.opener) {
						window.opener.location.reload();
						window.close();
					} else if (window.parent != window) {
						window.parent.location.reload();
					}
				}, 0); }
			</script>
		<?php	}
		} ?>
	Sie können dieses Fenster schließen.
	</body>
</html>