{include file="header.tpl"}

<div class="main-content">
  <div class="page-content">
    <div class="row">
      <div class="col-xl-12">
        <div class="card">
          <div class="card-body">

            <h4 class="card-title">Your Referrals</h4>
            <br><br>

            {if $upline.email != ""}
              <p>Your upline is <a href="mailto:{$upline.email}">{$upline.name}</a></p>
            {/if}

            <table class="table table-sm">
              <tr>
                <td class="item">Referrals:</td>
                <td class="item">{$total_ref}</td>
              </tr>
              <tr>
                <td class="item">Active referrals:</td>
                <td class="item">{$active_ref}</td>
              </tr>
              <tr>
                <td class="item">Total referral commission:</td>
                <td class="item">{$currency_sign}{$commissions}</td>
              </tr>
            </table>
            <br>

            {if $settings.show_refstat}
              <h4 class="card-title">Referral Ins/Signups</h4>
              <br>
              <form method="post" name="opts">
                <input type="hidden" name="a" value="referals">
                <div class="row g-2 align-items-end">
                  <div class="col-md-auto">
                    <label class="form-label">From:</label>
                    <div class="d-flex gap-1">
                      <select name="month_from" class="form-control form-control-sm">
                        {section name=month_from loop=$month}
                          <option value="{$smarty.section.month_from.index+1}" {if $smarty.section.month_from.index+1 == $frm.month_from}selected{/if}>{$month[month_from]}</option>
                        {/section}
                      </select>
                      <select name="day_from" class="form-control form-control-sm">
                        {section name=day_from loop=$day}
                          <option value="{$smarty.section.day_from.index+1}" {if $smarty.section.day_from.index+1 == $frm.day_from}selected{/if}>{$day[day_from]}</option>
                        {/section}
                      </select>
                      <select name="year_from" class="form-control form-control-sm">
                        {section name=year_from loop=$year}
                          <option value="{$year[year_from]}" {if $year[year_from] == $frm.year_from}selected{/if}>{$year[year_from]}</option>
                        {/section}
                      </select>
                    </div>
                  </div>

                  <div class="col-md-auto">
                    <label class="form-label">To:</label>
                    <div class="d-flex gap-1">
                      <select name="month_to" class="form-control form-control-sm">
                        {section name=month_to loop=$month}
                          <option value="{$smarty.section.month_to.index+1}" {if $smarty.section.month_to.index+1 == $frm.month_to}selected{/if}>{$month[month_to]}</option>
                        {/section}
                      </select>
                      <select name="day_to" class="form-control form-control-sm">
                        {section name=day_to loop=$day}
                          <option value="{$smarty.section.day_to.index+1}" {if $smarty.section.day_to.index+1 == $frm.day_to}selected{/if}>{$day[day_to]}</option>
                        {/section}
                      </select>
                      <select name="year_to" class="form-control form-control-sm">
                        {section name=year_to loop=$year}
                          <option value="{$year[year_to]}" {if $year[year_to] == $frm.year_to}selected{/if}>{$year[year_to]}</option>
                        {/section}
                      </select>
                    </div>
                  </div>

                  <div class="col-md-auto">
                    <input type="submit" value="Go" class="btn btn-sm btn-primary">
                  </div>
                </div>
              </form>
              <br>

              <table class="table table-bordered table-sm">
                <thead>
                  <tr>
                    <th>Date</th>
                    <th>Ins</th>
                    <th>Signups</th>
                  </tr>
                </thead>
                <tbody>
                  {if $show_refstat}
                    {section name=s loop=$refstat}
                      <tr>
                        <td class="item text-center"><b>{$refstat[s].date}</b></td>
                        <td class="item text-end">{$refstat[s].income}</td>
                        <td class="item text-end">{$refstat[s].reg}</td>
                      </tr>
                    {/section}
                  {else}
                    <tr>
                      <td colspan="3" class="text-center">No statistics found for this period.</td>
                    </tr>
                  {/if}
                </tbody>
              </table>
            {/if}

            {if $settings.show_referals}
              {if $show_referals}
                <h4 class="card-title">Your Referrals</h4>
                <table class="table table-striped table-sm">
                  <thead>
                    <tr>
                      <th>Nickname</th>
                      <th>E-mail</th>
                      <th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
                    {section name=s loop=$referals}
                      <tr>
                        <td><b>{$referals[s].username}</b></td>
                        <td><a href="mailto:{$referals[s].email}">{$referals[s].email}</a></td>
                        <td>{if $referals[s].q_deposits > 0}Deposited{else}No deposit yet{/if}</td>
                      </tr>
                      {if $referals[s].ref_stats}
                        <tr>
                          <td colspan="3">
                            User referrals:
                            {section name=l loop=$referals[s].ref_stats}
                              <nobr>{$referals[s].ref_stats[l].cnt_active} active of {$referals[s].ref_stats[l].cnt} on level {$referals[s].ref_stats[l].level}{if !$smarty.section.l.last}; {/if}</nobr>
                            {/section}
                          </td>
                        </tr>
                      {/if}
                      {if $referals[s].came_from}
                        <tr>
                          <td colspan="3">
                            <a href="{$referals[s].came_from}" target="_blank">[User came from]</a>
                          </td>
                        </tr>
                      {/if}
                    {/section}
                    <tr><td colspan="3"></td></tr>
                    <tr>
                      <td colspan="3"><b>2–10 level referrals:</b> {$cnt_other}</td>
                    </tr>
                    <tr>
                      <td colspan="3"><b>2–10 level active referrals:</b> {$cnt_other_active}</td>
                    </tr>
                  </tbody>
                </table>
              {/if}
            {/if}

          </div>
        </div>
      </div>
    </div>
  </div>
</div>

{include file="footer.tpl"}
