{extends "../window.tpl"}

{block tabs}
   {windowTab id='flapCaches'}
   {windowTab id='flapImages'}
   {windowTab id='flapProducts'}
   {windowTab id='flapOrders'}
   {if $module.SEARCH}
      {windowTab id='flapFulltext'}
   {/if}
{/block}

{block tabsContent}
   {function name=cleaningButton acn='' hideOnLive=false}
         <button class="btn btn-block confirm" type="submit" name="acn" value="{$acn}" title="{$acn|translate}" {if $hideOnLive && isLive()}disabled{/if}>
            {$acn|translate}{if $counts[$acn]} - {$counts[$acn].count}{/if}
         </button>
         {foreach $counts[$acn].links as $name => $link}
            <a href="{$link}">{$name}</a>
         {/foreach}
   {/function}
   <div id="flapCaches" class="tab-pane fade active in boxStatic">
      {call cleaningButton acn='cacheSections'}
      {call cleaningButton acn='cacheTemplates'}
      {call cleaningButton acn='cacheStatic'}
      {call cleaningButton acn='cacheRuntime'}
      {call cleaningButton acn='cacheFeeds'}
      {call cleaningButton acn='cacheSitemap'}

      <h4>Vymazat cache obrázků</h4>
      {call cleaningButton acn='cacheImages'}
      <div style="display:flex; flex-wrap: wrap; margin: 0 -5px 5px;">
         {foreach $cfg.Photo.id_to_type as $id => $name}
            <a href="?s=cleaning.php&acn=cacheImagesType&type={$id}" class="btn confirm" style="flex-grow: 1; margin: 5px;">{$id}
               : {$name}</a>
         {/foreach}
      </div>
      {call cleaningButton acn='imageVersionUpgrade'}

      <h4>Cron</h4>
      {call cleaningButton acn='cronFrequent'}
      {call cleaningButton acn='cronNormal'}
      {call cleaningButton acn='cronExpensive'}
   </div>
   <div id="flapImages" class="tab-pane boxStatic">
      {*      {call cleaningButton acn='imagesUnused'}*}
      {call cleaningButton acn='imagesFiles'}
      {call cleaningButton acn='imagesCorrupted'}
      {call cleaningButton acn='imagesMissingMain'}
   </div>
   <div id="flapProducts" class="tab-pane boxStatic">
      <h4>Produkty</h4>
      {call cleaningButton acn='productsAll' hideOnLive=true}
      {call cleaningButton acn='productsHidden'}
      {call cleaningButton acn='productsUncategorized'}
      {call cleaningButton acn='productsAnnotation'}
      {call cleaningButton acn='productsDescriptions'}

      <h4>Varianty</h4>
      {call cleaningButton acn='variationsDuplicates'}
      {call cleaningButton acn='regenerateVariationsTitles'}

      <h4>Parametry</h4>
      {call cleaningButton acn='parameters' hideOnLive=true}
      {call cleaningButton acn='parametersValues' hideOnLive=true}

      <h4>Sekce</h4>
      {call cleaningButton acn='sections' hideOnLive=true}
      {call cleaningButton acn='sectionsEmpty'}

      <h4>Výrobci</h4>
      {call cleaningButton acn='producers' hideOnLive=true}

      <h4>Hodnocení</h4>
      {call cleaningButton acn='reviewsImport'}
      {call cleaningButton acn='reviewsAutoConfirm'}

      <h4>Jmenovky variant</h4>
      {call cleaningButton acn='labels' hideOnLive=true}
      {call cleaningButton acn='labelsEmpty'}

      <h4>Slevy</h4>
      {call cleaningButton acn='discounts'}
      {call cleaningButton acn='allDiscounts' hideOnLive=true}
   </div>
   <div id="flapOrders" class="tab-pane boxStatic">
      {call cleaningButton acn='orders' hideOnLive=true}
      {call cleaningButton acn='users'  hideOnLive=true}
      {call cleaningButton acn='articles' hideOnLive=true}
      <h4>Spustit script</h4>

      <div class="form-group">
         <div class="col-md-2 control-label"><label>Script</label></div>
         <div class="col-md-10">
            <select name="script" class="selecter">
               <option value="">------</option>
               {foreach $scripts as $id => $script}
                  <option value="{$id}" data-parameters="{$script.parameters|json_encode}">{$script.name}</option>
               {/foreach}
            </select>
         </div>
      </div>
      <div class="form-group">
         <div class="col-md-2 control-label"><label>Parametry</label></div>
         <div class="col-md-10">
            <textarea rows="10" class="form-control" name="script_parameters">{}</textarea>
         </div>
      </div>
      <div class="form-group">
         <div class="col-md-2 col-md-offset-10">
            <button type="submit" name="acn" value="RunScript" class="btn btn-primary btn-block">Spustit</button>
         </div>
      </div>


      <script>
         $(':input[name="script"]').change(function(e) {
            var parameters = $(this).find('option:selected').data('parameters');
            $(':input[name="script_parameters"]').val(JSON.stringify(parameters, null, 2));
         });
      </script>
   </div>
   {if $module.SEARCH}
      <div id="flapFulltext" class="tab-pane boxStatic">
          <div class="col-md-2 control-label">
             <label>Index</label>
          </div>
          <div class="col-md-2">
             {print_select var=['all' => 'all'] + $fulltext.indexes name="fulltext_index"}
          </div>
          <div class="col-md-2 control-label">
             <label>Jazyk</label>
          </div>
          <div class="col-md-2">
             <select class="selecter" data-autocomplete="languages" name="fulltext_language">
                <option value="">Všechny</option>
             </select>
          </div>
          <div class="col-md-3">
             {call cleaningButton acn='fulltextUpdate'}
          </div>
      </div>
   {/if}
{/block}

{block buttonsLeft}
   <div class="col-md-4">
   </div>
   <div class="col-md-2">
      <input type="submit" name="calculate" class="btn btn-primary btn-block" value="Zobrazit počty"/>
   </div>
{/block}


