<?php echo $header; ?>
<style type="text/css">
.img-thumbnail {
    max-width: 50px !important;
}
.bmstore {
	max-height: 130px; overflow-y: auto;
}
.bmstore .checkbox input[type="checkbox"] {
	margin-right: 10px;
}
.bmgray {color:#bbb}
.errima {margin-bottom:0px!important}
td > a {outline:none!important}
</style>
<?php echo $column_left; ?>
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
		<span style="padding-right:20px;">
		<a href="https://www.opencart.com/index.php?route=marketplace/extension&filter_member=AlexDW" target="_blank" data-toggle="tooltip" title="Get more extensions" class="btn btn-info"><i class="fa fa-download"></i></a></span>
		<span style="padding-right:5px;">
        <button type="button" data-toggle="tooltip" title="<?php echo $button_enable_cat; ?>" class="btn btn-success" onclick="$('#form-category').attr('action', '<?php echo $enable_cat; ?>'); $('#form-category').submit();"><i class="fa fa-plus"></i></button>
        <button type="button" data-toggle="tooltip" title="<?php echo $button_disable_cat; ?>" class="btn btn-danger" onclick="$('#form-category').attr('action', '<?php echo $disable_cat; ?>'); $('#form-category').submit();"><i class="fa fa-minus"></i></button>
		</span>
		<span style="padding-right:10px;">
	  <a href="<?php echo $enable_all; ?>" data-toggle="tooltip" title="<?php echo $button_enable_all; ?>" class="btn btn-success" data-confirm="<?php echo $button_enable_all; ?>"><i class="fa fa-check fa"></i></a>
	  <a href="<?php echo $disable_all; ?>" data-toggle="tooltip" title="<?php echo $button_disable_all; ?>" class="btn btn-danger" data-confirm="<?php echo $button_disable_all; ?>"><i class="fa fa-power-off fa"></i></a>
		</span>

		<a href="<?php echo $add; ?>" data-toggle="tooltip" title="<?php echo $button_add; ?>" class="btn btn-primary"><i class="fa fa-plus"></i></a> <a href="<?php echo $repair; ?>" data-toggle="tooltip" title="<?php echo $button_rebuild; ?>" class="btn btn-default"><i class="fa fa-refresh"></i></a>
        <button type="button" data-toggle="tooltip" title="<?php echo $button_delete; ?>" class="btn btn-danger" onclick="confirm('<?php echo $text_confirm; ?>') ? $('#form-category').submit() : false;"><i class="fa fa-trash-o"></i></button>
      </div>
      <h1>CategoryManager 1.10en</h1>
      <ul class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
        <?php } ?>
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    <?php if ($error_warning) { ?>
    <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>
    <?php if ($success) { ?>
    <div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $success; ?>
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-list"></i> <?php echo $text_list; ?></h3>
      </div>
      <div class="panel-body">

        <div class="well">
          <div class="row">
            <div class="col-sm-3">
              <div class="form-group">
                <label class="control-label" for="input-id">ID</label>
                <input type="text" name="filter_id" value="<?php echo $filter_id; ?>" placeholder="ID" id="input-id" class="form-control" />
              </div>
              <div class="form-group">
                <label class="control-label" for="input-cat"><?php echo $entry_name; ?></label>
                <input type="text" name="filter_cat" value="<?php echo $filter_cat; ?>" placeholder="<?php echo $entry_name; ?>" id="input-cat" class="form-control" />
              </div>
            </div>
            <div class="col-sm-3">
              <div class="form-group">
                <label class="control-label" for="input-image"><?php echo $entry_img; ?></label>
                <select name="filter_image" id="input-image" class="form-control">
                  <option value="*"></option>
                  <?php if ($filter_image == 1) { ?>
                  <option value="1" selected="selected"><?php echo $text_yes; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_yes; ?></option>
                  <?php } ?>
                  <?php if ($filter_image == 2) { ?>
                  <option value="2" selected="selected"><?php echo $text_no; ?></option>
                  <?php } else { ?>
                  <option value="2"><?php echo $text_no; ?></option>
                  <?php } ?>
                </select>
              </div>
              <div class="form-group">
                <label class="control-label" for="input-top"><?php echo $entry_top; ?></label>
                <select name="filter_top" id="input-top" class="form-control">
                  <option value="*"></option>
                  <?php if ($filter_top == 1) { ?>
                  <option value="1" selected="selected"><?php echo $text_yes; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_yes; ?></option>
                  <?php } ?>
                  <?php if ($filter_top == 2) { ?>
                  <option value="2" selected="selected"><?php echo $text_no; ?></option>
                  <?php } else { ?>
                  <option value="2"><?php echo $text_no; ?></option>
                  <?php } ?>
                </select>
              </div>
            </div>
            <div class="col-sm-3">
              <div class="form-group">
                <label class="control-label" for="input-status"><?php echo $entry_status; ?></label>
                <select name="filter_status" id="input-status" class="form-control">
                  <option value="*"></option>
                  <?php if ($filter_status == 1) { ?>
                  <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_enabled; ?></option>
                  <?php } ?>
                  <?php if ($filter_status == 2) { ?>
                  <option value="2" selected="selected"><?php echo $text_disabled; ?></option>
                  <?php } else { ?>
                  <option value="2"><?php echo $text_disabled; ?></option>
                  <?php } ?>
                </select>
			  </div>	
			  <div class="form-group">
				<label class="control-label" for="input-subcat"><?php echo $entry_subcat; ?></label>
                <select name="filter_subcat" id="input-subcat" class="form-control">
                  <option value="*"></option>
                  <?php foreach ($subcat as $cat) { ?>
                  <?php if ($cat['category_id'] == $filter_subcat) { ?>
                  <option value="<?php echo $cat['category_id']; ?>" selected="selected"><?php echo $cat['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $cat['category_id']; ?>"><?php echo $cat['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select>
              </div>
            </div>

            <div class="col-sm-3">
			  <div class="form-group">
				<label class="control-label" for="input-store"><?php echo $entry_store; ?></label>
                <select name="filter_store" id="input-store" class="form-control">
                  <option value="*"></option>

                  <?php if ($filter_store == '**') { ?>
                  <option value="**" selected="selected"><?php echo $text_undefined; ?></option>
                  <?php } else { ?>
                  <option value="**"><?php echo $text_undefined; ?></option>
                  <?php } ?>

                  <?php if ($filter_store == '0') { ?>
                  <option value="0" selected="selected"><?php echo $text_default; ?></option>
                  <?php } else { ?>
                  <option value="0"><?php echo $text_default; ?></option>
                  <?php } ?>

                  <?php foreach ($stores as $store) { ?>
                  <?php if ($store['store_id'] == $filter_store) { ?>
                  <option value="<?php echo $store['store_id']; ?>" selected="selected"><?php echo $store['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $store['store_id']; ?>"><?php echo $store['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select>
              </div>
              <div class="form-group">
                <label class="control-label" for="input-seo"><?php echo $entry_keyword; ?></label>
                <select name="filter_seo" id="input-seo" class="form-control">
                  <option value="*"></option>
                  <?php if ($filter_seo == 1) { ?>
                  <option value="1" selected="selected"><?php echo $text_yes; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_yes; ?></option>
                  <?php } ?>
                  <?php if ($filter_seo == 2) { ?>
                  <option value="2" selected="selected"><?php echo $text_no; ?></option>
                  <?php } else { ?>
                  <option value="2"><?php echo $text_no; ?></option>
                  <?php } ?>
                </select>
              </div>
			  <div class="form-group">
				<div class="pull-right">
					<button type="button" id="button-clear" class="btn btn-info"><i class="fa fa-eraser"></i> <?php echo $txt_clear; ?></button>
					<button type="button" id="button-filter" class="btn btn-primary"><i class="fa fa-search"></i>  <?php echo $txt_filter; ?></button>
				</div>
			  </div>
			</div>

          </div>
		</div>

		<div class="row" style="padding-bottom:10px;">
			<div class="col-sm-6 text-left"><?php echo $pagination; ?></div>
			<div class="col-sm-6 text-right"><?php echo $results; ?></div>
		</div>

        <form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form-category">
          <div class="table-responsive">
			<table 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"><?php if ($sort == 'category_id') { ?>
					<a href="<?php echo $sort_id; ?>" class="<?php echo strtolower($order); ?>">ID</a>
					<?php } else { ?>
					<a href="<?php echo $sort_id; ?>">ID</a>
					<?php } ?>
				</td>
				<td class="text-center"><?php echo $entry_img ?></td>
				<td class="text-left"><?php if ($sort == 'name') { ?>
					<a href="<?php echo $sort_name; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_name; ?></a>
					<?php } else { ?>
					<a href="<?php echo $sort_name; ?>"><?php echo $column_name; ?></a>
					<?php } ?>
				</td>
				<td class="text-left"><?php echo $entry_keyword ?></td>
				<td class="text-left"><?php echo $entry_store ?></td>
				<td class="left"><?php if ($sort == 'date_added') { ?>
					<a href="<?php echo $sort_dadd; ?>" class="<?php echo strtolower($order); ?>"><?php echo $text_date_add; ?></a>
					<?php } else { ?>
					<a href="<?php echo $sort_dadd; ?>"><?php echo $text_date_add; ?></a>
					<?php } ?>
				</td>
				<td class="left"><?php if ($sort == 'date_modified') { ?>
					<a href="<?php echo $sort_dmod; ?>" class="<?php echo strtolower($order); ?>"><?php echo $text_date_mod; ?></a>
					<?php } else { ?>
					<a href="<?php echo $sort_dmod; ?>"><?php echo $text_date_mod; ?></a>
					<?php } ?>
				</td>
				<td class="text-right"><?php if ($sort == 'sort_order') { ?>
					<a href="<?php echo $sort_sort_order; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_sort_order; ?></a>
					<?php } else { ?>
					<a href="<?php echo $sort_sort_order; ?>"><?php echo $column_sort_order; ?></a>
					<?php } ?>
				</td>
				<td class="text-left"><?php echo $entry_top ?></td>
				<td class="text-left"><?php echo $entry_status ?></td>
				<td style="min-width: 110px;" class="text-right"><?php echo $column_action; ?></td>
                </tr>
              </thead>
			<tbody>
				<?php if ($categories) { ?>
				<?php foreach ($categories as $category) { ?>
			<tr>
				<td class="text-center"><?php if (in_array($category['category_id'], $selected)) { ?>
					<input type="checkbox" name="selected[]" value="<?php echo $category['category_id']; ?>" checked="checked" />
					<?php } else { ?>
					<input type="checkbox" name="selected[]" value="<?php echo $category['category_id']; ?>" />
					<?php } ?>
				</td>

				<td class="text-left"><?php echo $category['category_id']; ?></td>
				<td class="text-center"><a href="" id="thumb-image<?php echo $category['category_id']; ?>" data-toggle="imagebm">
                    <img src="<?php echo $category['image']; ?>" id="<?php echo $category['category_id']; ?>" alt="<?php echo $category['name']; ?>" class="img-thumbnail" /></a>
					<input type="hidden" name="image<?php echo $category['category_id']; ?>" value="" id="input-image<?php echo $category['category_id']; ?>" />
				</td>

				<td class="text-left">				
				  	<?php echo $category['cpname']; ?><a href="javascript:void(0);" data-toggle="name" ><?php echo $category['clname']; ?></a>
					<input type="hidden" name="name" id="<?php echo $category['category_id']; ?>" value="<?php echo $category['clname']; ?>" />
				</td>

				<td class="text-left">
<?php if ($category['keyword'] !='') { ?>
				  	<a href="javascript:void(0);" data-toggle="name" ><?php echo $category['keyword']; ?></a>
					<input type="hidden" name="keyword" id="<?php echo $category['category_id']; ?>" value="<?php echo $category['keyword']; ?>" />
<?php } else { ?>
					<a href="javascript:void(0);" data-toggle="name" ><i class="fa fa-pencil fa-lg bmgray"></i></a>
					<input type="hidden" name="keyword" id="<?php echo $category['category_id']; ?>" value="" />
<?php } ?>
				</td>

<?php if (empty($category['stores'])) { ?>
				<td class="text-left">
				  	<a href="javascript:void(0);" data-toggle="name" ><i class="fa fa-pencil fa-lg bmgray"></i></a>
					<input type="hidden" name="store" id="<?php echo $category['category_id']; ?>" value="" />
				</td>
<?php } else { ?>
				<td class="text-left">
                    <?php if (in_array(0, $category['stores'])) { ?>
                    <i style="color:#5BC0DE" class="fa fa-home fa-lg"></i> <a href="javascript:void(0);" data-toggle="name" ><?php echo $text_default; ?></a>
						<input type="hidden" name="store" id="<?php echo $category['category_id']; ?>" value="0" />
					</br>
                    <?php } ?>

                <?php foreach ($stores as $store) { ?>
                    <?php if (in_array($store['store_id'], $category['stores'])) { ?>
                    <i style="color:#5BC0DE" class="fa fa-home fa-lg"></i> <a href="javascript:void(0);" data-toggle="name" ><?php echo $store['name']; ?></a>
						<input type="hidden" name="store" id="<?php echo $category['category_id']; ?>" value="<?php echo $store['store_id']; ?>" />
					</br>
                    <?php } ?>
                <?php } ?>
				</td>
<?php } ?>

				<td class="left"><?php echo $category['date_add']; ?></td>
				<td class="left"><?php echo $category['date_mod']; ?></td>
				<td class="text-right">
				  	<a href="javascript:void(0);" data-toggle="name" ><?php echo $category['sort_order']; ?></a>
					<input type="hidden" name="sort_order" id="<?php echo $category['category_id']; ?>" value="<?php echo $category['sort_order']; ?>" />
				</td>

				<td class="text-left">
					<a href="" data-toggle="top">
					<?php if ($category['top'] > 0) { ?>
					<span class="btn btn-info btn-xs"><?php echo $text_yes; ?></span>
					<?php } else { ?>
					<span class="btn btn-default btn-xs"><?php echo $text_no; ?></span>
					<?php } ?>
					</a>
					<input type="hidden" name="top" id="<?php echo $category['category_id']; ?>" value="<?php echo $category['top']; ?>" />
				</td>

				<td class="text-left">
					<a href="" data-toggle="sta">
					<?php if ($category['status'] > 0) { ?>
					<span class="btn btn-success btn-xs"><?php echo $text_enabled; ?></span>
					<?php } else { ?>
					<span class="btn btn-warning btn-xs"><?php echo $text_disabled; ?></span>
					<?php } ?>
					</a>
					<input type="hidden" name="sta" id="<?php echo $category['category_id']; ?>" value="<?php echo $category['status']; ?>" />
				</td>

				<td class="text-right">
					<a href="<?php echo $category['view']; ?>" target="_blank" class="btn btn-info"><i class="fa fa-eye"></i></a>
					<a href="<?php echo $category['edit']; ?>" data-toggle="tooltip" title="<?php echo $button_edit; ?>" class="btn btn-primary"><i class="fa fa-pencil"></i></a>
				</td>
			</tr>
				<?php } ?>
				<?php } else { ?>
				<tr>
					<td class="text-center" colspan="12"><?php echo $text_no_results; ?></td>
				</tr>
				<?php } ?>
              </tbody>
			</table>
          </div>
		</form>
		<div class="row">
			<div class="col-sm-6 text-left"><?php echo $pagination; ?></div>
			<div class="col-sm-6 text-right"><?php echo $results; ?></div>
		</div>
      </div>
	</div>
  </div>

<script type="text/javascript"><!--
$(document).ready(function() {
	$('a[data-confirm]').click(function(ev) {
		var href = $(this).attr('href');
		if (!$('#dataConfirmModal').length) {
			$('body').append('<div id="dataConfirmModal" class="modal" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-body"></div><div class="modal-footer"><button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><?php echo $text_no; ?></button><a class="btn btn-danger" id="dataConfirmOK"><?php echo $text_yes; ?></a></div></div></div></div>');
		} 
		$('#dataConfirmModal').find('.modal-body').text($(this).attr('data-confirm')+' ?');
		$('#dataConfirmOK').attr('href', href);
		$('#dataConfirmModal').modal({show:true});
		return false;
	});
});

function getshops(shops) {
cont  = '<div class="bmstore">';
cont += '	<div class="checkbox">';
cont += '		<label>';
if (shops.indexOf('0') != -1) {
cont += '			<input type="checkbox" name="stores" value="0" checked="checked" /><?php echo $text_default; ?>';
} else {
cont += '			<input type="checkbox" name="stores" value="0" /><?php echo $text_default; ?>';
}
cont += '		</label>';
cont += '	</div>';

var stor = '';
	<?php foreach ($stores as $store) { ?>
	stor = '<?php echo $store['store_id']; ?>';
cont += '	<div class="checkbox">';
cont += '		<label>';
	if (shops.indexOf(stor) != -1) {
cont += '			<input type="checkbox" name="stores" value="<?php echo $store['store_id']; ?>" checked="checked" /><?php echo $store['name']; ?>';
	} else {
cont += '			<input type="checkbox" name="stores" value="<?php echo $store['store_id']; ?>" /><?php echo $store['name']; ?>';
	}
cont += '		</label>';
cont += '	</div>';
	<?php } ?>
cont += '</div>';
cont +='<div class="row input-group input-sm" id="forname"><span class="input-group-btn"><button id="button-stores" class="btn btn-primary btn-sm" type="button"> <i class="fa fa-check"></i></button></span><span class="input-group-btn"><button id="button-scancel" type="button" class="btn btn-default btn-sm"><i class="fa fa-times"></i></button></span></div>';
return cont;
}

	$(document).on('click', 'a[data-toggle=\'name\']', function(e) {
		var $element = $(this);
		var $popover = $element.data('bs.popover');
		var $bmtext = $element.parent().find('input').val();
		var mid = $element.parent().find('input').attr('id');
		var bmtype = $element.parent().find('input').attr('name');

		var shops = [];
			$('input[name*=\'store\'][id="' + mid + '"]').each(function () {
					shops.push($(this).val());
			});

		e.preventDefault();
		$('.popover').remove();
		$('a[data-toggle=\'imagebm\'],a[data-toggle=\'name\'],a[data-toggle=\'top\'],a[data-toggle=\'sta\']').popover('destroy');

		if ($popover) {
			return;
		}

		$element.popover({
			html: true,
			placement: 'bottom',
			trigger: 'manual',
			animation: false,
			content: function() {
				if (bmtype == 'store') {
					return getshops(shops);
				} else {
				return '<div class="row"><div class="input-group input-sm" id="forname"><input id="ssort" autocomplete="off" type="text" class="form-control input-sm" value="' + $bmtext + '"><span class="input-group-btn"><button id="button-schange" class="btn btn-primary btn-sm" type="button"> <i class="fa fa-check"></i></button></span><span class="input-group-btn"><button id="button-scancel" type="button" class="btn btn-default btn-sm"><i class="fa fa-times"></i></button></span></div></div>';
				}
			}
		});

		$element.popover('show');
		$('#forname .btn').css('outline', 'none')

		if (bmtype != 'store') {
		var input = document.querySelector("#ssort");
			input.focus();
			input.selectionStart= input.value.length;
		}

		$('#button-stores').on('click', function() {
			var setstore = [];
			var nosetstore = [];
			$('input[name*=\'stores\']').each(function () {
				if (this.checked) {
					setstore.push($(this).val());
				} else {
					nosetstore.push($(this).val());
				}
			});

			var text = JSON.parse("[" + setstore + "]");
				$.ajax({
				url: 'index.php?route=catalog/category/bmchangedata&token=' + getURLVar('token') + '&mid=' + mid + '&type=' + bmtype + '&text=' + encodeURIComponent(text),
				dataType: 'json',

				success: function(json) {
				$('#serror').remove();
				$('.adw-warn').remove();

				if (json['error']) {
					if (json['error']['warning']) { err = json['error']['warning']; }
					$('#forname').append('<div id="serror" class="alert alert-danger" style="display: table-caption;">' + err + '</div>');
				}

				if (json['success']) {


			var tmp = $element.parent().closest("td");
			tmp.empty();

	var ches ='';
	if (setstore.length == 0) {
		ches ='<a href="javascript:void(0);" data-toggle="name" ><i class="fa fa-pencil fa-lg bmgray"></i></a>';
		ches +='<input type="hidden" name="store" id="' + mid + '" value="" />';
	} else {
	if (setstore.indexOf('0') != -1) {
		ches += '			<i style="color:#5BC0DE" class="fa fa-home fa-lg"></i> <a href="javascript:void(0);" data-toggle="name" ><?php echo $text_default; ?></a>';
		ches += '			<input type="hidden" name="store" id="' + mid + '" value="0" />';
		ches += '			</br>';
	}
	<?php foreach ($stores as $store) { ?>
	var stor = '<?php echo $store['store_id']; ?>';
	if (setstore.indexOf(stor) != -1 && stor !='0') {
		ches += '			<i style="color:#5BC0DE" class="fa fa-home fa-lg"></i> <a href="javascript:void(0);" data-toggle="name" ><?php echo $store['name']; ?></a>';
		ches += '			<input type="hidden" name="store" id="' + mid + '" value="'+ stor +'" />';
		ches += '			</br>';
	}
	<?php } ?>
	}
		tmp.append(ches);

				$element.popover('destroy');

				}

				},
			error: function(xhr, ajaxOptions, thrownError) {
				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
			}
			});
		});

		$('#button-schange').on('click', function() {

			var text = ($element.parent().find('input').val());
			text = text.replace(/(^\s+)|(\s{2,})|(\s+$)/g, '');

			$.ajax({
				url: 'index.php?route=catalog/category/bmchangedata&token=' + getURLVar('token') + '&mid=' + mid + '&type=' + bmtype + '&text=' + encodeURIComponent(text),
				dataType: 'json',

				success: function(json) {
				$('#serror').remove();
				$('.adw-warn').remove();

				if (json['error']) {
					if (json['error']['name']) { err = json['error']['name']; }
					if (json['error']['keyword']) { err = json['error']['keyword']; }
					if (json['error']['warning']) { err = json['error']['warning']; }
					$('#forname').append('<div id="serror" class="alert alert-danger" style="display: table-caption;">' + err + '</div>');
				}

				if (json['success']) {
				$element.text('');
				text !='' ? $element.text(text) : $element.append('<i class="fa fa-pencil fa-lg bmgray"></i>');
				$element.parent().find('input').val(text);
				$element.popover('destroy');
				}

				},
			error: function(xhr, ajaxOptions, thrownError) {
				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
			}
			});

		});

		$('#button-scancel').on('click', function() {
			$element.popover('destroy');
		});
	});

	$(document).on('click', 'a[data-toggle=\'imagebm\']', function(e) {

		var $element = $(this);
		var $popover = $element.data('bs.popover');
		e.preventDefault();

		$('.popover').remove();
		$('a[data-toggle=\'imagebm\'],a[data-toggle=\'name\'],a[data-toggle=\'top\'],a[data-toggle=\'sta\']').popover('destroy');

		if ($popover) {
			return;
		}

					$.ajax({
						url: 'index.php?route=catalog/category/bmche&token=' + getURLVar('token'),
						dataType: 'json',
						success: function(json) {
						if (json['error']) {

						$element.popover({
							html: true,
							placement: 'right',
							trigger: 'manual',
							animation: false,
							content: function() {
							return '<div class="row errima alert alert-danger">' + json['error']['warning'] + '</div>';
							}
						});
							$element.popover('show');

						} else {

		$element.popover({
			html: true,
			placement: 'right',
			trigger: 'manual',
			content: function() {
				return '<div ><div id="forname"><button type="button" id="button-image" class="btn btn-primary"><i class="fa fa-pencil"></i></button> <button type="button" id="button-clr" class="btn btn-danger"><i class="fa fa-trash-o"></i></button></div></div>';
			}
		});

		$element.popover('show');

		$('#button-image').on('click', function() {
			var $button = $(this);
			var $icon   = $button.find('> i');

			$('#modal-image').remove();

			$.ajax({
				url: 'index.php?route=common/filemanager&token=' + getURLVar('token') + '&target=' + $element.parent().find('input').attr('id') + '&thumb=' + $element.attr('id'),
				dataType: 'html',
				beforeSend: function() {
					$button.prop('disabled', true);
					if ($icon.length) {
						$icon.attr('class', 'fa fa-circle-o-notch fa-spin');
					}
				},
				complete: function() {
					$button.prop('disabled', false);
					if ($icon.length) {
						$icon.attr('class', 'fa fa-pencil');
					}
				},
				success: function(html) {
					$('body').append('<div id="modal-image" class="modal">' + html + '</div>');
					$('#modal-image').modal('show');

									$('#modal-image').delegate('a.thumbnail', 'click', function(e) {
										e.preventDefault();

					var mid = $element.find('img').attr('id');
					var ipath = $element.parent().find('input').attr('value');

					$.ajax({
						url: 'index.php?route=catalog/category/bmchangeimage&token=' + getURLVar('token') + '&mid=' + mid + '&type=image' + '&ipath=' + ipath,
						dataType: 'json',
						success: function(json) {
						if (json['error']) {
							$('#forname').before('<div id="serror" class="alert alert-danger" style="display: table-caption;">' + json['error']['warning'] + '</div>');
						}
						},
					error: function(xhr, ajaxOptions, thrownError) {
					alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
					}
					});

										$('#modal-image').modal('hide');
									});

				}
			});

			$element.popover('destroy');

		});

		$('#button-clr').on('click', function() {
			var mid = $element.find('img').attr('id');
			var ipath = $element.find('img').attr('src');

			$.ajax({
				url: 'index.php?route=catalog/category/bmdeleteimage&token=' + getURLVar('token') + '&mid=' + mid + '&type=image',
				dataType: 'json',
				success: function(json) {

				if (json['error']) {
					$('#forname').append('<div id="serror" class="row alert alert-danger">' + json['error']['warning'] + '</div>');
				}

				if (json['success']) {
					$element.find('img').attr('src', '<?php echo $placeholder; ?>');
					$element.popover('destroy');
				}

				},
			error: function(xhr, ajaxOptions, thrownError) {
				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
			}
			});

		});

						}

						},
					error: function(xhr, ajaxOptions, thrownError) {
					alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
					}
					});

	});

function filter() {
	url = 'index.php?route=catalog/category&token=<?php echo $token; ?>';
	url += '&filter_cm=1';

	var filter_id = $('input[name=\'filter_id\']').val();
	
	if (filter_id) {
		url += '&filter_id=' + encodeURIComponent(filter_id);
	}

	var filter_status = $('select[name=\'filter_status\']').val();
	
	if (filter_status !='*') {
		url += '&filter_status=' + encodeURIComponent(filter_status);
	}

	var filter_top = $('select[name=\'filter_top\']').val();
	
	if (filter_top !='*') {
		url += '&filter_top=' + encodeURIComponent(filter_top);
	}

	var filter_cat = $('input[name=\'filter_cat\']').val();
	
	if (filter_cat) {
		url += '&filter_cat=' + encodeURIComponent(filter_cat);
	}

	var filter_subcat = $('select[name=\'filter_subcat\']').val();
	
	if (filter_subcat != '*') {
		url += '&filter_subcat=' + encodeURIComponent(filter_subcat);
	}

	var filter_store = $('select[name=\'filter_store\']').val();
	
	if (filter_store != '*') {
		url += '&filter_store=' + encodeURIComponent(filter_store);
	}

	var filter_seo = $('select[name=\'filter_seo\']').val();

	if (filter_seo !='*') {
		url += '&filter_seo=' + encodeURIComponent(filter_seo);
	}

	var filter_image = $('select[name=\'filter_image\']').val();
	
	if (filter_image !='*') {
		url += '&filter_image=' + encodeURIComponent(filter_image);
	}

	location = url;
}

function clear_filter() {
	$('select[class=\'form-control\']').val('*');
	$('input[class=\'form-control\']').val('');
	filter();
	return false;
}
//--></script>  
<script type="text/javascript"><!--
$('input[class=\'form-control\']').keydown(function(e) {
	if (e.keyCode == 13) {
		filter();
	}
});

$('#button-filter').on('click', function() {
		filter();
});

$('#button-clear').on('click', function() {
		clear_filter();
});

$(document).on('click', 'a[data-toggle=\'top\']', function(e) {
	var sta = $(this);
	var text = sta.parent().find('input');
	var span = sta.parent().find('span');
	var mid = text.attr('id');
	var top = (text.val())<1 ? 1 : 0;

	$('.popover').remove();
	$('a[data-toggle=\'imagebm\'],a[data-toggle=\'name\'],a[data-toggle=\'top\'],a[data-toggle=\'sta\']').popover('destroy');
	e.preventDefault();

	$.ajax({
		url: 'index.php?route=catalog/category/bmchangedata&token=' + getURLVar('token') + '&mid=' + mid + '&type=top' + '&text=' + top,
		dataType: 'json',
		success: function(json) {
			if (json['error']) {
				sta.popover({
					html: true,
					placement: 'left',
					trigger: 'manual',
					animation: false,
					content: function() {
					return '<div class="row errima alert alert-danger">' + json['error']['warning'] + '</div>';
					}
				});
				sta.popover('show');
			}

			if (json['success']) {
				if (text.val()<1) {
					span.removeClass('btn-default').addClass('btn-info');
					span.html('<?php echo $text_yes; ?>');
					text.val('1');
				} else {
					span.removeClass('btn-info').addClass('btn-default');
					span.html('<?php echo $text_no; ?>');
					text.val('0');
				}

			}

		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
});

$(document).on('click', 'a[data-toggle=\'sta\']', function(e) {
	var sta = $(this);
	var text = sta.parent().find('input');
	var span = sta.parent().find('span');
	var mid = text.attr('id');
	var top = (text.val())<1 ? 1 : 0;

	$('.popover').remove();
	$('a[data-toggle=\'imagebm\'],a[data-toggle=\'name\'],a[data-toggle=\'top\'],a[data-toggle=\'sta\']').popover('destroy');
	e.preventDefault();

	$.ajax({
		url: 'index.php?route=catalog/category/bmchangedata&token=' + getURLVar('token') + '&mid=' + mid + '&type=sta' + '&text=' + top,
		dataType: 'json',
		success: function(json) {
			if (json['error']) {
				sta.popover({
					html: true,
					placement: 'left',
					trigger: 'manual',
					animation: false,
					content: function() {
					return '<div class="row errima alert alert-danger">' + json['error']['warning'] + '</div>';
					}
				});
				sta.popover('show');
			}

			if (json['success']) {
				if (text.val()<1) {
					span.removeClass('btn-warning').addClass('btn-success');
					span.html('<?php echo $text_enabled; ?>');
					text.val('1');
				} else {
					span.removeClass('btn-success').addClass('btn-warning');
					span.html('<?php echo $text_disabled; ?>');
					text.val('0');
				}

			}

		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
});
//--></script></div>
<?php echo $footer; ?>