<div class="container-fluid">
    <div class="row">
    <h3><?php echo $text_settings; ?></h3>
    </div>
    <br />
    <div class="row">
        <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
            <h5><span class="required">*</span> <strong><?php echo $text_isense_db_cache_status; ?></strong></h5>
            <span class="help"><?php echo $text_isense_db_cache_status_helper; ?></span>
        </div>
        <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
             <select name="<?php echo $moduleName; ?>[status]" class="form-control">
                  <option value="1" <?php echo (!empty($moduleData['status']) && $moduleData['status'] == '1') ? 'selected=selected' : '' ?>><?php echo $text_enabled; ?></option>
                  <option value="0"  <?php echo (empty($moduleData['status']) || $moduleData['status'] == '0') ? 'selected=selected' : '' ?>><?php echo $text_disabled; ?></option>
             </select>
        </div>
        <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
			<h5><span class="required">*</span> <strong><?php echo $text_isense_db_cache_queries; ?></strong></h5>
			<span class="help"><?php echo $text_isense_db_cache_queries_helper; ?></span>
		</div>
        <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
            <div class="form-check">
                <input type="hidden" name="<?php echo $moduleName; ?>[cache_product_queries]" value="0" />
                <input id="ProductQueries" class="form-check-input" type="checkbox" name="<?php echo $moduleName; ?>[cache_product_queries]" value="1" <?php echo (!empty($moduleData['cache_product_queries']) && $moduleData['cache_product_queries'] !== '0') ? 'checked' : ''; ?> />
                <label class="form-check-label" for="ProductQueries"><?php echo $text_product_queries; ?></label>
            </div>
            <div class="form-check">
                <input type="hidden" name="<?php echo $moduleName; ?>[cache_category_queries]" value="0" />
                <input id="CategoryQueries" class="form-check-input" type="checkbox" name="<?php echo $moduleName; ?>[cache_category_queries]" value="1" <?php echo (!empty($moduleData['cache_category_queries']) && $moduleData['cache_category_queries'] !== '0') ? 'checked' : ''; ?> />
                <label class="form-check-label" for="CategoryQueries"><?php echo $text_category_queries; ?></label>
            </div>
            <div class="form-check">
                <input type="hidden" name="<?php echo $moduleName; ?>[cache_manufacturer_queries]" value="0" />
                <input id="ManufacturerQueries" class="form-check-input" type="checkbox" name="<?php echo $moduleName; ?>[cache_manufacturer_queries]" value="1" <?php echo (!empty($moduleData['cache_manufacturer_queries']) && $moduleData['cache_manufacturer_queries'] !== '0') ? 'checked' : ''; ?> />
                <label class="form-check-label" for="ManufacturerQueries"><?php echo $text_manufacturer_queries; ?></label>
            </div>
            <div class="form-check">
                <input type="hidden" name="<?php echo $moduleName; ?>[cache_information_queries]" value="0" />
                <input id="InformationQueries" class="form-check-input" type="checkbox" name="<?php echo $moduleName; ?>[cache_information_queries]" value="1" <?php echo (!empty($moduleData['cache_information_queries']) && $moduleData['cache_information_queries'] !== '0') ? 'checked' : ''; ?> />
                <label class="form-check-label" for="InformationQueries"><?php echo $text_information_queries; ?></label>
            </div>
            <div class="form-check">
                <input type="hidden" name="<?php echo $moduleName; ?>[cache_product_counts]" value="0" />
                <input id="ProductsCount" class="form-check-input" type="checkbox" name="<?php echo $moduleName; ?>[cache_product_counts]" value="1" <?php echo (!empty($moduleData['cache_product_counts']) && $moduleData['cache_product_counts'] !== '0') ? 'checked' : ''; ?> />
                <label class="form-check-label" for="ProductsCount"><?php echo $text_products_count; ?></label>
            </div>
            <div class="form-check">
                <input type="hidden" name="<?php echo $moduleName; ?>[cache_category_counts]" value="0" />
                <input id="CategoriesCount" class="form-check-input" type="checkbox" name="<?php echo $moduleName; ?>[cache_category_counts]" value="1" <?php echo (!empty($moduleData['cache_category_counts']) && $moduleData['cache_category_counts'] !== '0') ? 'checked' : ''; ?> />
                <label class="form-check-label" for="CategoriesCount"><?php echo $text_categories_count; ?></label>
            </div>
            <div class="form-check">
                <input type="hidden" name="<?php echo $moduleName; ?>[cache_manufacturer_counts]" value="0" />
                <input id="ManufacturersCount" class="form-check-input" type="checkbox" name="<?php echo $moduleName; ?>[cache_manufacturer_counts]" value="1" <?php echo (!empty($moduleData['cache_manufacturer_counts']) && $moduleData['cache_manufacturer_counts'] !== '0') ? 'checked' : ''; ?> />
                <label class="form-check-label" for="ManufacturersCount"><?php echo $text_manufacturer_count; ?></label>
            </div>
            <div class="form-check">
                <input type="hidden" name="<?php echo $moduleName; ?>[cache_information_counts]" value="0" />
                <input id="InformationCount" class="form-check-input" type="checkbox" name="<?php echo $moduleName; ?>[cache_information_counts]" value="1" <?php echo (!empty($moduleData['cache_information_counts']) && $moduleData['cache_information_counts'] !== '0') ? 'checked' : ''; ?> />
                <label class="form-check-label" for="InformationCount"><?php echo $text_information_count; ?></label>
            </div>
            <div class="form-check">
                <input type="hidden" name="<?php echo $moduleName; ?>[cache_seo_urls]" value="0" />
                <input id="SeoQueries" class="form-check-input" type="checkbox" name="<?php echo $moduleName; ?>[cache_seo_urls]" value="1" <?php echo !empty($moduleData['cache_seo_urls']) ? 'checked' : ''; ?>/>
                <label class="form-check-label" for="SeoQueries"><?php echo $text_seo_urls; ?></label>
            </div>
        </div>
	</div>
    <br/>
	<div class="row">
		<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
			<h5><span class="required">*</span> <strong><?php echo $text_isense_db_missing_orders; ?></strong></h5>
			<span class="help"><?php echo $text_isense_db_missing_orders_helper; ?></span>
		</div>
		<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
            <input class="form-control" type="text"  disabled value="<?php echo !empty($missing_orders_count) ?  $missing_orders_count : '0' ?>" />
		</div>
        <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
            <button type="button" onclick="clearMisingOrders();" id="clear_missing_orders" data-toggle="tooltip" title="<?php echo $text_isense_db_cache_button_clear_missing_orders; ?>" class="btn btn-primary" <?php echo $have_missing_order ? '' : 'disabled';?>><?php echo $text_isense_db_cache_button_clear_missing_orders; ?></button>
        </div>
	</div>
	<br/>
	<div class="row">
		<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
			<h5><span class="required">*</span> <strong><?php echo $text_isense_db_cache_engine; ?></strong></h5>
			<span class="help"><?php echo $text_isense_db_cache_engine_helper; ?></span>
		</div>
		<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
            <select name="<?php echo $moduleName; ?>[engine]" class="form-control">
                <option value="file" <?php echo (!empty($moduleData['engine']) && $moduleData['engine'] == 'file') ? 'selected=selected' : '' ?>><?php echo $text_file; ?></option>
                <option value="memcache" <?php echo (!empty($moduleData['engine']) && $moduleData['engine'] == 'memcache') ? 'selected=selected' : '' ?> <?php if (!class_exists('Memcache')) { echo 'disabled=disabled style="color:#aaa;"'; } ?>><?php echo $text_memcache; ?></option>
                <option value="memcached" <?php echo (!empty($moduleData['engine']) && $moduleData['engine'] == 'memcached') ? 'selected=selected' : '' ?> <?php if (!class_exists('Memcached')) { echo 'disabled=disabled style="color:#aaa;"'; } ?>><?php echo $text_memcached; ?></option>
                <option value="redis" <?php echo (!empty($moduleData['engine']) && $moduleData['engine'] == 'redis') ? 'selected=selected' : '' ?> <?php if (!class_exists('Redis')) { echo 'disabled=disabled style="color:#aaa;"'; } ?>><?php echo $text_redis; ?></option>
            </select>
		</div>
        <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
			<span class="help"><?php echo $text_isense_db_cache_button_clear_cache_helper; ?></span>
		</div>
        <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
            <button type="button" onclick="clearCache();" id="clearcache" data-toggle="tooltip" title="<?php echo $text_isense_db_cache_button_clear_cache; ?>" class="btn btn-primary"><?php echo $text_isense_db_cache_button_clear_cache; ?></button>
        </div>
	</div>
    <hr /><br />
    <div id="engine_dashboard"></div>
</div>

<script type="text/javascript">

function clearCache() {

	var cache_engine = {
		'engine' : "<?php echo !empty($moduleData['engine']) ? $moduleData['engine'] : '' ?>",
        'status' : "<?php echo !empty($moduleData['status']) ? $moduleData['status'] : '' ?>"
	};

	$.ajax({
      url: 'index.php?route=<?php echo $modulePath; ?>/clearCache&token=' + token,
	  method: 'post',
	  data: cache_engine,
      success: function(json) {
            location.reload();
      }
    });
}

function clearMisingOrders() {

	$.ajax({
      url: 'index.php?route=<?php echo $modulePath; ?>/clearMissingOrders&token=' + token,
	  method: 'post',
      success: function(json) {
            location.reload();
      }
    });
}

$(document).ready(function(){
    $('select[name="<?php echo $moduleName; ?>[engine]"]').on('change', function(){
        engine = $(this).val();
        $("#engine_dashboard").html("Loading...");
        $.ajax({
          url: 'index.php?route=<?php echo $modulePath; ?>/loadEngineTemplates&token=' + token +'&engine=' + engine,
    	  method: 'get',
          dataType: 'html',
          success: function(data) {

            $("#engine_dashboard").html(data);
          }
        });
    });
    $('select[name="<?php echo $moduleName; ?>[engine]"]').trigger('change');

});
</script>
