{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="button" data-toggle="tooltip" title="{{ button_filter }}" onclick="$('#filter-member').toggleClass('hidden-lg');" class="btn btn-default"><i class="fa fa-filter"></i></button>
        <a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa fa-plus"></i></a>
        <button type="button" data-toggle="tooltip" title="{{ button_delete }}" class="btn btn-danger" onclick="confirm('{{ text_confirm }}') ? $('#form-member').submit() : false;"><i class="fa fa-trash-o"></i></button>
        <button type="button" id="button-export" data-toggle="tooltip" title="{{ button_export }}" class="btn btn-info" style="background-color: darkgreen;"><i class="fa fa-file-excel-o"></i></button>
      </div>
      <h1>{{ heading_title }}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    {% if error_warning %}
    <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    {% endif %}
    {% if success %}
    <div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> {{ success }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    {% endif %}
    <div class="row">
      <div id="filter-member" class="col-sm-12 hidden-lg">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title"><i class="fa fa-filter"></i> {{ text_filter }}</h3>
          </div>
          <div class="panel-body">
            <div class="form-group">
              <label class="control-label" for="input-name">{{ entry_name }}</label>
              <input type="text" name="filter_name" value="{{ filter_name }}" placeholder="{{ entry_name }}" id="input-name" class="form-control" />
            </div>
            <div class="form-group">
              <label class="control-label" for="input-email">{{ entry_email }}</label>
              <input type="text" name="filter_email" value="{{ filter_email }}" placeholder="{{ entry_email }}" id="input-email" class="form-control" />
            </div>
             <div class="form-group">
              <label class="control-label" for="input-phone_no">{{ entry_phone_no }}</label>
              <input type="text" name="filter_phone_no" value="{{ filter_phone_no }}" placeholder="{{ entry_phone_no }}" id="input-phone_no" class="form-control" />
            </div>
            <div class="form-group">
              <label class="control-label" for="input-status">{{ entry_status }}</label>
              <select name="filter_status" id="input-status" class="form-control">
                <option value=""></option>
                {% if filter_status == '1' %}
                <option value="1" selected="selected">{{ text_active }}</option>
                {% else %}
                <option value="1">{{ text_active }}</option>
                {% endif %}
                {% if filter_status == '0' %}
                <option value="0" selected="selected">{{ text_inactive }}</option>
                {% else %}
                <option value="0">{{ text_inactive }}</option>
                {% endif %}
              </select>
            </div>
            <div class="form-group">
              <label class="control-label" for="input-date-added">{{ entry_date_added }}</label>
              <div class="input-group date">
                <input type="text" name="filter_date_added" value="{{ filter_date_added }}" placeholder="{{ entry_date_added }}" data-date-format="YYYY-MM-DD" id="input-date-added" class="form-control" />
                <span class="input-group-btn">
                <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                </span>
              </div>
            </div>
            <div class="form-group text-right">
              <button type="button" id="button-filter" class="btn btn-default"><i class="fa fa-filter"></i> {{ button_filter }}</button>
            </div>
          </div>
        </div>
      </div>
    <div class="col-sm-12">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h3 class="panel-title"><i class="fa fa-list"></i> {{ text_list }}</h3>
        </div>
        <div class="panel-body">
          <form action="{{ delete }}" method="post" enctype="multipart/form-data" id="form-member">
            <div class="table-responsive">
              <table id="tbl-tier" class="table table-bordered table-hover">
                <thead>
                  <tr>
                    <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
                    <td class="text-left">{% if sort == 'first_name ' %}
                      <a href="{{ sort_first_name  }}" class="{{ order|lower }}">{{ column_first_name }}</a>
                      {% else %}
                      <a href="{{ sort_first_name  }}">{{ column_first_name  }}</a>
                      {% endif %}</td>
                    <td class="text-left">{% if sort == 'last_name ' %}
                      <a href="{{ sort_last_name  }}" class="{{ order|lower }}">{{ column_last_name }}</a>
                      {% else %}
                      <a href="{{ sort_last_name  }}">{{ column_last_name  }}</a>
                      {% endif %}</td>
                    <td class="text-left">{{ column_email }}</td>
                    <td class="text-left">{{ column_phone_no }}</td>
                    <td class="text-left">{{ column_gender }}</td>
                    <td class="text-left">{{ column_date_of_birth }}</td>
                    <td class="text-left">{{ column_tier_level }}</td>
                    <td class="text-left">{{ column_tier_expiry_date }}</td>
                    <td class="text-left">{% if sort == 'total_available_point' %}
                      <a href="{{ sort_total_available_point }}" class="{{ order|lower }}">{{ column_total_available_point }}</a>
                      {% else %}
                      <a href="{{ sort_total_available_point }}">{{ column_total_available_point }}</a>
                      {% endif %}</td>
                    <td class="text-left">{{ column_total_tier_achieved_purchase}}</td>
                    <td class="text-left">{% if sort == 'status' %}
                      <a href="{{ sort_status }}" class="{{ order|lower }}">{{ column_status }}</a>
                      {% else %}
                      <a href="{{ sort_status }}">{{ column_status }}</a>
                      {% endif %}</td>
                    <td class="text-left">{% if sort == 'date_added' %}
                      <a href="{{ sort_date_added }}" class="{{ order|lower }}">{{ column_date_added }}</a>
                      {% else %}
                      <a href="{{ sort_date_added }}">{{ column_date_added }}</a>
                      {% endif %}</td>
                    <td class="text-right">{{ column_action }}</td>
                  </tr>
                </thead>
                <tbody>
                  {% if members %}
                  {% for member in members %}
                  <tr>
                    <td class="text-center">{% if member.member_id in selected %}
                      <input type="checkbox" name="selected[]" value="{{ member.member_id }}" checked="checked" />
                      {% else %}
                      <input type="checkbox" name="selected[]" value="{{ member.member_id }}" />
                      {% endif %}</td>
                    <td class="text-left">{{ member.first_name }}</td>
                    <td class="text-left">{{ member.last_name }}</td>
                    <td class="text-left" >{{ member.email }}</td>
                    <td class="text-left" >{{ member.phone_no }}</td>
                    <td class="text-left" >{{ member.gender }}</td>
                    <td class="text-left" >{{ member.date_of_birth }}</td>
                    <td class="text-left" >{{ member.tier_level  }}</td>
                    <td class="text-left" >{{ member.tier_expiry_date  }}</td>
                    <td class="text-left" >{{ member.total_available_point  }}</td>
                    <td class="text-left" >{{ member.total_tier_achieved_purchase  }}</td>
                    <td class="text-left">{{ member.status }}</td>
                    <td class="text-left">{{ member.date_added }}</td>
                    <td class="text-right">
                    <div class="btn-group" style="min-width: 65px;">
                        <a href="{{ member.edit }}" data-toggle="tooltip" title="{{ button_edit }}" class="btn btn-primary"><i class="fa fa-pencil"></i></a>
                        <button type="button" data-toggle="dropdown" class="btn btn-primary dropdown-toggle"><span class="caret"></span></button>
                        <ul class="dropdown-menu dropdown-menu-right">
                          <li class="dropdown-header">{{ text_option }}</li>
                          {% if member.add_reward  %}
                          <li><a href="{{ member.add_reward  }}"><i class="fa fa-gift"></i> {{ text_add_member_reward }}</a></li>
                          {% endif %}
                          <li role="separator" class="divider"></li>
                          <li><a href="{{ member.add_point }}"><i class="fa fa-plus-circle"></i> {{ text_add_member_point }}</a></li>
                        </ul>
                      </div>
                    </td>
                  </tr>
                  {% endfor %}
                  {% else %}
                  <tr>
                    <td class="text-center" colspan="14">{{ text_no_results }}</td>
                  </tr>
                  {% endif %}
                </tbody>
              </table>
            </div>
          </form>
          <div class="row">
            <div class="col-sm-6 text-left">{{ pagination }}</div>
            <div class="col-sm-6 text-right">{{ results }}</div>
          </div>
        </div>
      </div>
  </div>
  </div>
</div>
{{ footer }} 

<style>
#tbl-tier > tbody > tr > td {
    white-space: normal;
    word-wrap: break-word;
}

.row-fix-width
{
  max-width:100px;
}
</style>

<script type="text/javascript"><!--
  $('#button-filter').on('click', function() {
    url = 'index.php?route=member/member&user_token={{ user_token }}';
    var filter_name = $('input[name=\'filter_name\']').val();
    if (filter_name) {
      url += '&filter_name=' + encodeURIComponent(filter_name);
    }
    var filter_email = $('input[name=\'filter_email\']').val();
    if (filter_email) {
      url += '&filter_email=' + encodeURIComponent(filter_email);
    }
    var filter_phone_no = $('input[name=\'filter_phone_no\']').val();
    if (filter_phone_no) {
      url += '&filter_phone_no=' + encodeURIComponent(filter_phone_no);
    }
    var filter_status = $('select[name=\'filter_status\']').val();
    if (filter_status !== '') {
      url += '&filter_status=' + encodeURIComponent(filter_status); 
    }
    var filter_date_added = $('input[name=\'filter_date_added\']').val();
    if (filter_date_added) {
      url += '&filter_date_added=' + encodeURIComponent(filter_date_added);
    }
    location = url;
  });

  $('#button-export').on('click', function() {
    url = 'index.php?route=member/member/export&user_token={{ user_token }}';
    var filter_name = $('input[name=\'filter_name\']').val();
    if (filter_name) {
      url += '&filter_name=' + encodeURIComponent(filter_name);
    }
    var filter_email = $('input[name=\'filter_email\']').val();
    if (filter_email) {
      url += '&filter_email=' + encodeURIComponent(filter_email);
    }
    var filter_phone_no = $('input[name=\'filter_phone_no\']').val();
    if (filter_phone_no) {
      url += '&filter_phone_no=' + encodeURIComponent(filter_phone_no);
    }
    var filter_status = $('select[name=\'filter_status\']').val();
    if (filter_status !== '') {
      url += '&filter_status=' + encodeURIComponent(filter_status); 
    }
    var filter_date_added = $('input[name=\'filter_date_added\']').val();
    if (filter_date_added) {
      url += '&filter_date_added=' + encodeURIComponent(filter_date_added);
    }
    location = url;
  });
  //--></script>
  <script type="text/javascript"><!--
  $('.date').datetimepicker({
    language: '{{ datepicker }}',
    pickTime: false
  });
  //--></script>