<tal:block metal:use-macro="python:here.getFormsTool().getForm('site_admin_template').macros['page']">

<h1 metal:fill-slot="title" i18n:translate="">Portal statistics</h1>



<tal:block metal:fill-slot="section">
  <script type="text/javascript"
         src="http://localhost:8080/naaya/core_js"></script>
  <script type="text/javascript"
         src="http://localhost:8080/naaya/calendar_js"></script>
  <script type="text/javascript"
         src="http://localhost:8080/naaya/datetime_js"></script>
  <style type="text/css">
  blockquote {
    background:#F8F8F8;
    border:1px dashed #CCCCCC;
    margin:5px 0;
    padding:8px 12px 8px 36px;
    color: black;
  }
  </style>
  <script type="text/javascript">
    function emptyEndDate(){
      if (document.forms['frmAccount'].date_choice[0].checked == true)
        document.forms['frmAccount'].end_date_text.value = '';
    }
  </script>
  <div class="tabbedmenu">
    <ul>
      <li><a tal:attributes="href string:${here/absolute_url}/admin_stats" i18n:translate="">Statistics</a></li>
      <li class="currenttab"><a tal:attributes="href string:${here/absolute_url}/admin_account" i18n:translate="">Settings</a></li>
      <li><a tal:attributes="href string:${here/absolute_url}/admin_verify" i18n:translate="">Google Snippets</a></li>
    </ul>
  </div>

  <form method="post" name="frmAccount" id="frmAccount"
        tal:attributes="action string:${here/absolute_url}/admin_account_save">

    <tal:block condition="not: options/choose_profile">
      <p i18n:translate="">
        Current profile:
        <tal:block i18n:name="name" tal:content="options/profile_name" />
      </p>
    </tal:block>

    <tal:block condition="options/choose_profile">
    <p i18n:translate="">
      Select your website from the list below and save it as default account.
    </p>
    <div class="field-inline">
      <label for="account" i18n:translate="">Accounts</label>
      <select name="account">
        <option></option>
        <tal:block repeat="entry options/accounts">
        <option tal:define="tableId python:entry[0];
                  title python:entry[1];"
            tal:attributes="value tableId; selected python:tableId==here.account" 
            tal:content="title" />
        </tal:block>
      </select>
    </div>
    <div class="field-inline">
      <label for="profile-select" i18n:translate="">Sites in account</label>
      <span id="profile-select-box"></span>
      <input type="hidden" name="profile_code"
             tal:attributes="value here/profile_code" />
    </div>
    <script tal:define="url string:${here/absolute_url}/portal_statistics/getProfiles"
            tal:content="structure python:'var STATISTICS_PROFILES_URL = %s;'
                            % here.rstk['json_dumps'](url)"></script>
    <script>
      (function() {
          var old_profile_code = $('input[name=profile_code]').remove().val();
          var account_select = $('select[name=account]');
          var profile_select_box = $('#profile-select-box');
          account_select.change(function(evt) {
              update_profile_selection();
          });

          update_profile_selection();

          function update_profile_selection() {
              var value = account_select.val();
              if(! value) {
                  profile_select_box.text('(please select an account)');
                  return;
              }
              profile_select_box.text('loading...');
              $.get(STATISTICS_PROFILES_URL, {account: value}, function(data) {
                  var profile_select = $('<select name="profile_code">');
                  profile_select.attr('id', 'profile-select');
                  $.each(data['profiles'], function(i, item) {
                      var option = $('<option>').attr('value', item['code']);
                      if(item['code'] == old_profile_code) {
                          option.attr('selected', 'selected');
                      }
                      profile_select.append(option.text(item['name']));
                  });
                  profile_select_box.empty().append(profile_select);
              });
          };
      })();
    </script>
    </tal:block>

    <p i18n:translate="">
      By choosing below the start date for the statistics - either dynamic
      (last month/3 months/6 months/year) or a specific date, the statistics
      will be shown from that start date until today.
    </p>
    <div class="field">
      <label for="date_interval" i18n:translate="">Select a predefined start date</label>
      <select name="date_interval">
        <option></option>
        <tal:block repeat="interval here/get_intervals">
          <option tal:attributes="value interval/period; selected python:interval['period']==here.date_interval;" tal:content="interval/value" i18n:translate="" />
        </tal:block>
      </select>
    </div>
    <div class="field">
      <label for="start_date" i18n:translate="">or choose a specific start date</label>
      <input type="text" class="vDateField" name="start_date" tal:attributes="value here/start_date" maxlength="10" size="10" />
    </div>
    <p>
      <input type="submit" value="save" name="save" i18n:attributes="value" />
    </p>
  </form>

  <form method="post"
        tal:attributes="action string:${here/absolute_url}/admin_account_revoke">
    <p i18n:translate="">
      If you want to stop access to the Google Analytics statistics for your website choose 
      the <em i18n:name="revoke-access" i18n:translate="">Revoke access</em> button</p>
    <p>
      <input type="submit" value="Revoke access" i18n:attributes="value" />
    </p>
  </form>

</tal:block>
</tal:block>
