<?php
require_once __DIR__.'/inc/shared.php';

$GLOBALS['-acl'] = check_access();

if (!empty($_GET['tx'])) {
	require_once __DIR__.'/inc/paypal_pdt.php';
}
else if (!empty($_POST['txn_id'])) {
	require_once __DIR__.'/inc/paypal_ipn.php';
}
else if (strpos($_SERVER['REQUEST_URI'], '/terms') !== false) {
	require_once __DIR__.'/inc/terms.php';
}
else if (strpos($_SERVER['REQUEST_URI'], '/login') !== false) {
	require_once __DIR__.'/inc/login.php';
}
else if (strpos($_SERVER['REQUEST_URI'], '/receipt') !== false) {
	header('Location: https://store.gramtrans.com'.$_SERVER['REQUEST_URI'], true, 301);
	die();
}
else if (strpos($_SERVER['REQUEST_URI'], '/inspect') !== false) {
	require_once __DIR__.'/inc/inspect.php';
}
else if (strpos($_SERVER['REQUEST_URI'], '/clicks') !== false) {
	require_once __DIR__.'/inc/clicks.php';
}
else if (strpos($_SERVER['REQUEST_URI'], '/audit') !== false) {
	require_once __DIR__.'/inc/audit.php';
}
else if (strpos($_SERVER['REQUEST_URI'], '/trial-add') !== false) {
	require_once __DIR__.'/inc/trial-add.php';
}
else if (strpos($_SERVER['REQUEST_URI'], '/sdu') !== false) {
	require_once __DIR__.'/inc/sdu.php';
}
else if (strpos($_SERVER['REQUEST_URI'], '/help') !== false) {
	require_once __DIR__.'/inc/help.php';
}
else if (strpos($_SERVER['REQUEST_URI'], '/paypal') !== false) {
	require_once __DIR__.'/inc/pprest.php';
}
else if (strpos($_SERVER['REQUEST_URI'], '/rules') !== false) {
	serve_rules_pdf();
	die();
}
else {
	if ($GLOBALS['-acl']->has_caps()) {
		require_once __DIR__.'/inc/editor.php';
	}
	else {
		require_once __DIR__.'/inc/welcome.php';
	}
}

?>
<!DOCTYPE html>
<html lang="{l10n:META_LANG}" prefix="og: http://ogp.me/ns#">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="author" content="GrammarSoft ApS">
	<meta name="keywords" content="{l10n:META_KEYWORDS}">
	<meta name="description" content="{l10n:META_DESCRIPTION}">
	<link rel="icon" type="image/png" href="https://commatizer.com/static/logo-80.png" sizes="80x80">
	<link rel="alternate" hreflang="da" href="https://commatizer.com<?=$_SERVER['REQUEST_URI'];?>?ui=da">
	<link rel="alternate" hreflang="de" href="https://commatizer.com<?=$_SERVER['REQUEST_URI'];?>?ui=de">
	<link rel="alternate" hreflang="en" href="https://commatizer.com<?=$_SERVER['REQUEST_URI'];?>?ui=en">
	<link rel="alternate" hreflang="x-default" href="https://commatizer.com<?=$_SERVER['REQUEST_URI'];?>">
	<meta property="og:locale" content="{l10n:META_LOCALE}">
	<meta property="og:image" content="https://commatizer.com/static/og_image.png">
	<title><?=$GLOBALS['-site']['title'];?></title>

	<meta name="google-site-verification" content="UYVtyRkskD3vMCAhLHOfWMh5gBRudFfVa2YfVgnsK2g">

	<script src="/gas/comma-eng/1.0.0/vendor/jquery.js"></script>
	<script src="/gas/comma-eng/1.0.0/vendor/murmurhash3js.min.js"></script>
	<script src="static/tinymce/tinymce.min.js"></script>

	<link rel="stylesheet" href="static/bootstrap.min.css">
	<script src="static/bootstrap.min.js"></script>

	<link rel="stylesheet" href="static/shared.css?<?=filemtime(__DIR__.'/static/shared.css');?>">
	<link rel="stylesheet" href="static/local.css?<?=filemtime(__DIR__.'/static/local.css');?>">

	<script>
		window.PRODUCT_NAME = <?=json_encode($GLOBALS['-site']['title']);?>;
		window.PRODUCT_DOMAIN = <?=json_encode($GLOBALS['-site']['domain']);?>;
		window.SERVICE = <?=json_encode($GLOBALS['-site']['service']);?>;
		window.UILANG2 = <?=json_encode($GLOBALS['-l10n-lang2']);?>;
		window.CLIENT = 'web';
	</script>

	<script src="static/js.cookie.min.js"></script>
	<script src="static/jquery.scrollintoview.js?<?=filemtime(__DIR__.'/static/jquery.scrollintoview.js');?>"></script>
	<script src="/gas/comma-eng/1.0.0/js/impl.js"></script>
	<script src="static/l10n.js?<?=filemtime(__DIR__.'/static/l10n.js');?>"></script>
	<script src="/gas/comma-eng/1.0.0/js/shared.js"></script>
	<script src="/gas/comma-eng/1.0.0/js/mark-types.js"></script>
	<script src="static/shared.js?<?=filemtime(__DIR__.'/static/shared.js');?>"></script>
	<script src="static/tool.js?<?=filemtime(__DIR__.'/static/tool.js');?>"></script>
</head>
<body>

<div id="container">
<div id="headbar">
<div id="logo">
	<div id="logo-wrap">
	<div id="logo-back">
		<div id="logo-back-left"></div>
		<a href="./"><span class="icon icon-logo"></span><span>Commatizer</span></a>
		<div id="logo-back-right"></div>
	</div>
	</div>
<div id="login" class="navbar-right">
<?php
if ($GLOBALS['-acl']->valid()) {
?>
<a class="btn btn-info" href="#" onclick="profile_open(); return false;">{l10n:BTN_PROFILE}</a>
<a class="btn btn-info" href="#" onclick="danproof_logout(); return false;">{l10n:BTN_LOGOUT_WEB}</a>
<?php
}
else {
?>
<a class="btn btn-success" href="./#subs">{l10n:BTN_SUBSCRIBE}</a>
<a class="btn btn-info" href="https://gramtrans.com/wp-login.php?lang=<?=$GLOBALS['-l10n-lang2'];?>&amp;redirect_to=<?=urlencode($GLOBALS['url_self'].'login');?>" target="_top">{l10n:BTN_LOGIN_WEB}</a>
<?php
}
?>
<div class="dropdown inline">
<button class="btn btn-sm btn-info" id="langs" data-bs-toggle="dropdown"><img src="static/icon-lang-white.png"></button>
<ul class="dropdown-menu" aria-labelledby="langs">
<?=$GLOBALS['-l10n-switch'];?>
</ul>
</div>
</div>
</div>
</div>

<div id="content">
<div id="warning" class="alert alert-warning"></div>
<div id="info" class="alert alert-info text-center"></div>
<?php \Impl\content(); ?>

<div class="container center pad-bottom">
<a class="btn btn-default" href="https://workspace.google.com/marketplace/app/commatizer/782393334830" target="_blank"><img src="static/frontend-google-editors-32.png"><br>Google Docs</a>
<a class="btn btn-default" href="https://appsource.microsoft.com/product/office/WA200002638" target="_blank"><img src="static/frontend-word-32.png"><br>Microsoft Word</a>
<a class="btn btn-default" href="https://appsource.microsoft.com/product/office/WA200003096" target="_blank"><img src="static/frontend-outlook-32.png"><br>Microsoft Outlook</a>
</div>

<div class="container center pad-bottom">
<a class="btn btn-default" href="https://retmig.dk/" target="_blank"><img src="https://retmig.dk/static/logo-80.png" height="20"> <b>{l10n:LBL_RETMIG}</b><br><small>{l10n:LBL_RETMIG_UNDER}</small></a>
<a class="btn btn-default" href="https://kommaer.dk/" target="_blank"><img src="https://kommaer.dk/static/logo-80.png" height="20"> <b>{l10n:LBL_KOMMAFORSLAG}</b><br><small>{l10n:LBL_KOMMAFORSLAG_UNDER}</small></a>
<a class="btn btn-default" href="https://kommatroll.com/" target="_blank"><img src="https://kommatroll.com/static/logo-80.png" height="20"> <b>{l10n:LBL_KOMMATROLL}</b><br><small>{l10n:LBL_KOMMATROLL_UNDER}</small></a>
</div>

<div role="alert" class="alert alert-success alert-dismissible fade show">
	<button aria-label="Close" data-bs-dismiss="alert" class="btn-close" type="button"></button>
	Welcome to our new English comma checker! Existing <a href="https://kommaer.dk/">Kommaforslag</a> and <a href="https://retmig.dk/">RetMig</a> customers have free access until at least July 1st, 2021.
</div>
</div>

<div id="footbar">
<div id="footer">
<a href="https://bsky.app/profile/grammarsoft.com" target="_blank">Facebook</a>
<a href="https://bsky.app/profile/grammarsoft.com" target="_blank">Twitter</a>
<a href="mailto:mail@commatizer.com">{l10n:LBL_EMAIL}</a>
<a href="help">{l10n:LBL_SUPPORT_FAQ}</a>
<a href="terms">{l10n:LBL_TERMS}</a>
<a href="terms#privacy">{l10n:LBL_PRIVACY}</a>
<a href="https://grammarsoft.com/" target="_blank">© 2020-<?=date('Y');?> GrammarSoft ApS</a>
</div>
</div>

</div>

<div class="modal fade" id="dg_input" tabindex="-1" role="dialog">
  <div class="modal-dialog modal-sm" role="document">
    <div class="modal-content">
      <div class="modal-body">
        <div class="form-group">
          <label for="do_input_text">{l10n:BTN_EDIT}:</label>
          <input class="form-control" id="do_input_text" type="text" value=""><br>
        </div>
        <button class="btn btn-light" data-bs-dismiss="modal">{l10n:BTN_CLOSE}</button>
        <button class="btn btn-light" id="do_input_one">{l10n:BTN_EDIT}</button>
        <!-- <button class="btn btn-light" id="do_input_all">{l10n:BTN_EDIT_ALL}</button> -->
      </div>
    </div>
  </div>
</div>

<div id="working"><img src="static/ellipsis.gif"> <span>{l10n:MSG_WORKING}</span> <img src="static/ellipsis.gif"></div>

<div id="profile" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{PROFILE_NAME}</h4>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" onclick="profile_close(); return false;"></button>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="profile_close(); return false;">{l10n:BTN_SAVE_CLOSE}</button>
      </div>
    </div>
  </div>
</div>

<div id="redeem" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{l10n:BTN_COUPON_OPEN}</h4>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" onclick="redeem_close(); return false;"></button>
      </div>
      <div class="modal-body">
        <div class="form-group">
          <label for="redeem_email">{l10n:BTN_COUPON_EMAIL}</label>
          <input type="email" class="form-control" id="redeem_email" placeholder="mail@example.com">
        </div>
        <div class="form-group">
          <label for="redeem_email2">{l10n:BTN_COUPON_EMAIL2}</label>
          <input type="email" class="form-control" id="redeem_email2" placeholder="mail@example.com">
        </div>
        <div class="form-group">
          <label for="redeem_code">{l10n:BTN_COUPON_CODE}</label>
          <input type="text" class="form-control" id="redeem_code" placeholder="12345-abcde-67890">
        </div>
        <div class="checkbox">
        	<label><input name="consent" id="redeem_consent" type="checkbox"> <span>{l10n:LBL_TERMS_BOX}</span></label>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" onclick="redeem_do(); return false;">{l10n:BTN_COUPON_REDEEM}</button>
      </div>
    </div>
  </div>
</div>

<div id="options" class="modal fade" tabindex="-1" role="dialog" data-bs-backdrop="static">
  <div class="modal-dialog modal-dialog-centered modal-xl">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">{l10n:TITLE_OPTIONS}</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{l10n:BTN_CLOSE}</button>
      </div>
    </div>
  </div>
</div>

<script>
  var _paq = window._paq = window._paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    let u="//gramtrans.com/matomo/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '<?=$GLOBALS['-site']['matomo-sid'];?>']);
    let d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript><img src="//gramtrans.com/matomo/matomo.php?idsite=<?=$GLOBALS['-site']['matomo-sid'];?>&amp;rec=1" style="border:0;" alt="" /></noscript>

<script>
g_tool = 'Comma';
g_tools.comma = window.SERVICE;
</script>
<!-- Rendering time: <?=round(microtime(true)-$GLOBALS['-timer'], 3);?> -->
</body>
</html>
