<br class="space5" />

{if $columnsList}

	<table class="list" width="100%" style="margin:0px">

		{*****************************************************************************************}
		{********************************* TABLE HEADER ******************************************}
		{*****************************************************************************************}

		<tr>
			<th width="1%">#</th>
			<th width="1%" class="nowrap">{$_LANG.reportsManagement.admin.sorting.th.column}</th>
			<th width="1%" class="nowrap">
				{$_LANG.reportsManagement.admin.sorting.th.visible}
			</th>
			<th>{$_LANG.reportsManagement.admin.sorting.th.details}</th>
		</tr>

		{************************************ MAIN CRITERION *************************************}

		<tr class="{cycle values="odd,even"}">
			<td>1.</td>
			<td class="nowrap">
				<label for="mainCriterionVisible">{$_LANG.reportsManagement.admin.sorting.mainCriterion}</label>
			</td>
			<td class="center">
				<input id="mainCriterionVisible" type="checkbox" class="noBorder"
					name="mainCriterionVisible" value="1" {if $reportSorting.mainCriterionVisible}checked="1"{/if}
				/>
			</td>
			<td>
				<select name="mainCriterionColumn" size="1" class="sortColumn" id="mainCriterionColumn"
					onchange="
						if (this.value) {ldelim}
							$('mainCriterionOrderDirection').show();
							$('groupBy_main').removeClassName('criterionNotExists');
						{rdelim} else {ldelim}
							$('mainCriterionOrderDirection').hide();
							$('groupBy_main').addClassName('criterionNotExists');
							if ($F('groupBySelector')=='main')
								$('groupBySelector').value='';
						{rdelim}
					"
				>
					<option value="" {if !strlen($reportSorting.mainCriterionColumn)}selected="1"{/if}>{$_LANG.reportsManagement.admin.sorting.chooseCol}</option>
					{assign var=lastColCat value=''}{assign var=hasCats value=0}
					{foreach from=$columnsList name="colsLoop" key=col item=colDet}
						{assign var=thisColCat value=$columnsCfg[$col].cat}
						{if $thisColCat!=$lastColCat}
							{if !$smarty.foreach.colsLoop.first}</optgroup>{/if}
							<optgroup label="{$_LANG.reports.columnCategories[$reportSource][$thisColCat]}">
							{assign var=hasCats value=1}
						{/if}
						<option value="{$col}" {if $reportSorting.mainCriterionColumn==$col}selected="1"{/if}>{counter name="mainColumnOrdering"}. {$colDet.originalName}</option>
						{assign var=lastColCat value=$thisColCat}
					{/foreach}
					{* close the last option group - if opened *}
					{if $thisColCat or $hasCats}</optgroup>{/if}

					{* add custom columns *}
					{if $customColumnsList}
						<optgroup label="{$_LANG['reportsManagement']['admin']['customFilters']['tpl']['custColOptGrName']}">
							{foreach $customColumnsList as $custColIdx=>$custColDet}
								<option value="{$custColIdx}" {if is_numeric($reportSorting.mainCriterionColumn) and $reportSorting.mainCriterionColumn==$custColIdx}selected="1"{/if}>{counter name="mainColumnOrdering"}. {$custColDet.n|default:'-'}</option>
							{/foreach}
						</optgroup>
					{/if}

				</select>

				<select id="mainCriterionOrderDirection" size="1" name="mainCriterionOrderDirection" class="sortOrderDirection" {if !strlen($reportSorting.mainCriterionColumn)}style="display:none;"{/if}>
					<option value="ASC" {if $reportSorting.mainCriterionOrderDirection=="ASC"}selected="1"{/if}>{$_LANG.reportsManagement.admin.sorting.ascending}</option>
					<option value="DESC" {if $reportSorting.mainCriterionOrderDirection=="DESC"}selected="1"{/if}>{$_LANG.reportsManagement.admin.sorting.descending}</option>
				</select>
			</td>
		</tr>

		{************************************ SECONDARY CRITERION ********************************}

		<tr class="{cycle values="odd,even"}">
			<td>2.</td>
			<td class="nowrap">
				<label for="secCriterionVisible">{$_LANG.reportsManagement.admin.sorting.secCriterion}</label>
			</td>
			<td class="center">
				<input id="secCriterionVisible" type="checkbox" class="noBorder"
					name="secCriterionVisible" value="1"  {if $reportSorting.secCriterionVisible}checked="1"{/if}
				/>
			</td>
			<td>
				<select name="secCriterionColumn" size="1" class="sortColumn" id="secCriterionColumn"
					onchange="
						if (this.value) {ldelim}
							$('secCriterionOrderDirection').show();
							$('groupBy_sec').removeClassName('criterionNotExists');
						{rdelim} else {ldelim}
							$('secCriterionOrderDirection').hide();
							$('groupBy_sec').addClassName('criterionNotExists');
							if ($F('groupBySelector')=='sec')
								$('groupBySelector').value='';
						{rdelim}
					"
				>
					<option value="" {if strlen($reportSorting.secCriterionColumn)==0}selected="1"{/if}>{$_LANG.reportsManagement.admin.sorting.chooseCol}</option>
					{assign var=lastColCat value=''}{assign var=hasCats value=0}
					{foreach from=$columnsList name="colsLoop" key=col item=colDet}
						{assign var=thisColCat value=$columnsCfg[$col].cat}
						{if $thisColCat!=$lastColCat}
							{if !$smarty.foreach.colsLoop.first}</optgroup>{/if}
							<optgroup label="{$_LANG.reports.columnCategories[$reportSource][$thisColCat]}">
							{assign var=hasCats value=1}
						{/if}
						<option value="{$col}" {if $reportSorting.secCriterionColumn==$col}selected="1"{/if}>{counter name="secColumnOrdering"}. {$colDet.originalName}</option>
						{assign var=lastColCat value=$thisColCat}
					{/foreach}
					{* close the last option group - if opened *}
					{if $thisColCat or $hasCats}</optgroup>{/if}

					{* add custom columns *}
					{if $customColumnsList}
						<optgroup label="{$_LANG['reportsManagement']['admin']['customFilters']['tpl']['custColOptGrName']}">
							{foreach $customColumnsList as $custColIdx=>$custColDet}
								<option value="{$custColIdx}" {if is_numeric($reportSorting.secCriterionColumn) and $reportSorting.secCriterionColumn==$custColIdx}selected="1"{/if}>{counter name="secColumnOrdering"}. {$custColDet.n|default:'-'}</option>
							{/foreach}
						</optgroup>
					{/if}

				</select>

				<select id="secCriterionOrderDirection" size="1" name="secCriterionOrderDirection" class="sortOrderDirection" {if !strlen($reportSorting.secCriterionColumn)}style="display:none;"{/if}>
					<option value="ASC" {if $reportSorting.secCriterionOrderDirection=="ASC"}selected="1"{/if}>{$_LANG.reportsManagement.admin.sorting.ascending}</option>
					<option value="DESC" {if $reportSorting.secCriterionOrderDirection=="DESC"}selected="1"{/if}>{$_LANG.reportsManagement.admin.sorting.descending}</option>
				</select>
			</td>
		</tr>


		{************************************ THIRD CRITERION ************************************}

		<tr class="{cycle values="odd,even"}">
			<td>3.</td>
			<td class="nowrap">
				<label for="thirdCriterionVisible">{$_LANG.reportsManagement.admin.sorting.thirdCriterion}</label>
			</td>
			<td class="center">
				<input id="thirdCriterionVisible" type="checkbox" class="noBorder"
					name="thirdCriterionVisible" value="1"  {if $reportSorting.thirdCriterionVisible}checked="1"{/if}
				/>
			</td>
			<td>
				<select name="thirdCriterionColumn" size="1" class="sortColumn" id="thirdCriterionColumn"
					onchange="
						if (this.value) {ldelim}
							$('thirdCriterionOrderDirection').show();
							$('groupBy_third').removeClassName('criterionNotExists');
						{rdelim} else {ldelim}
							$('thirdCriterionOrderDirection').hide();
							$('groupBy_third').addClassName('criterionNotExists');
							if ($F('groupBySelector')=='third')
								$('groupBySelector').value='';
						{rdelim}
					"
				>
					<option value="" {if strlen($reportSorting.thirdCriterionColumn)==0}selected="1"{/if}>{$_LANG.reportsManagement.admin.sorting.chooseCol}</option>
					{assign var=lastColCat value=''}{assign var=hasCats value=0}
					{foreach from=$columnsList name="colsLoop" key=col item=colDet}
						{assign var=thisColCat value=$columnsCfg[$col].cat}
						{if $thisColCat!=$lastColCat}
							{if !$smarty.foreach.colsLoop.first}</optgroup>{/if}
							<optgroup label="{$_LANG.reports.columnCategories[$reportSource][$thisColCat]}">
							{assign var=hasCats value=1}
						{/if}
						<option value="{$col}" {if $reportSorting.thirdCriterionColumn==$col}selected="1"{/if}>{counter name="thirdColumnOrdering"}. {$colDet.originalName}</option>
						{assign var=lastColCat value=$thisColCat}
					{/foreach}
					{* close the last option group - if opened *}
					{if $thisColCat or $hasCats}</optgroup>{/if}

					{* add custom columns *}
					{if $customColumnsList}
						<optgroup label="{$_LANG['reportsManagement']['admin']['customFilters']['tpl']['custColOptGrName']}">
							{foreach $customColumnsList as $custColIdx=>$custColDet}
								<option value="{$custColIdx}" {if is_numeric($reportSorting.thirdCriterionColumn) and $reportSorting.thirdCriterionColumn==$custColIdx}selected="1"{/if}>{counter name="thirdColumnOrdering"}. {$custColDet.n|default:'-'}</option>
							{/foreach}
						</optgroup>
					{/if}

				</select>

				<select id="thirdCriterionOrderDirection" size="1" name="thirdCriterionOrderDirection" class="sortOrderDirection" {if !strlen($reportSorting.thirdCriterionColumn)}style="display:none;"{/if}>
					<option value="ASC" {if $reportSorting.thirdCriterionOrderDirection=="ASC"}selected="1"{/if}>{$_LANG.reportsManagement.admin.sorting.ascending}</option>
					<option value="DESC" {if $reportSorting.thirdCriterionOrderDirection=="DESC"}selected="1"{/if}>{$_LANG.reportsManagement.admin.sorting.descending}</option>
				</select>
			</td>
		</tr>


		{************************************ GROUP BY CRITERION *********************************}

		<tr class="{cycle values="odd,even"}">
			<td>4.</td>
			<td class="nowrap">
				<label for="groupByCriterionVisible"><b>{$_LANG.reportsManagement.admin.sorting.groupBy}</b></label>
			</td>
			<td class="center">
				<input id="groupByCriterionVisible" type="checkbox" class="noBorder"
					name="groupByCriterionVisible" value="1"  {if $reportSorting.groupByCriterionVisible}checked="1"{/if}
				/>
			</td>
			<td class="nowrap">
				<select id="groupBySelector" size="1" name="groupBy" class="sortColumn" onchange="changeSortingGroupBy();">
					<option value="" {if !$reportSorting.groupBy}selected="1"{/if}>{$_LANG.reportsManagement.admin.sorting.groupBy_no}</option>
					<option id="groupBy_main" value="main" {if $reportSorting.groupBy=='main'}selected="1"{/if}  {if !$reportSorting.mainCriterionColumn}class="criterionNotExists"{/if}>{$_LANG.reportsManagement.admin.sorting.groupBy_main}</option>
					<option id="groupBy_sec" value="sec" {if $reportSorting.groupBy=='sec'}selected="1"{/if} {if !$reportSorting.secCriterionColumn}class="criterionNotExists"{/if}>{$_LANG.reportsManagement.admin.sorting.groupBy_sec}</option>
					<option id="groupBy_third" value="third" {if $reportSorting.groupBy=='third'}selected="1"{/if} {if !$reportSorting.thirdCriterionColumn}class="criterionNotExists"{/if}>{$_LANG.reportsManagement.admin.sorting.groupBy_third}</option>
				</select>
			</td>
		</tr>


	</table>

{/if}