{assign var="appendConditionVar" value=0}
{assign var="appendConditionRootVar" value=1}
{assign var="appendRootRelVarRoot" value=""}
{assign var="appendRootRelVar" value=""}
<div class="form_listing promoConditionList">
	<ul class="levl-00 promoRoot" rel="">
		<li class="clearfix"><h3>
<span>{$language.lblPromotionConditions}</span>
</h3></li>
		<li class="clearfix promoConditionParent">
			<div>
				{if isset($resDataConditions)}
					{assign var="resDataConditionsSet" value=$resDataConditions.set|default:''}
					{assign var="resDataConditionsset_value" value=$resDataConditions.set_value|default:''}
				{else}
					{assign var="resDataConditionsSet" value=""}
					{assign var="resDataConditionsset_value" value=""}
				{/if}
				{$language.lblPromotionConditionNote1}&nbsp;
				{form->select class="width-100px" name="promotion_data[conditions][set]" options="all->{$language.lblPromotionConditionAll}~*any->{$language.lblPromotionConditionAny}" value=$resDataConditionsSet}&nbsp;
				{$language.lblPromotionConditionNote2}&nbsp;
				{form->select class="width-100px" name="promotion_data[conditions][set_value]" options="1->{$language.lblPromotionConditionTrue}~*0->{$language.lblPromotionConditionFalse}" value=$resDataConditionsset_value}
				{html->anchor caption="{$language.lblPromotionAddCondition}" class="promotionAddCondition grayBtn fixing_right"}
														
			</div>										
		</li> 	
		
		{*$resDataConditions['conditions']|print_r*}
		{* define the function *}
		{function name=generateConditions}
			{foreach $data as $eachDataConditionKey => $eachDataCondition}			
				{assign var="appendConditionVar" value=$appendConditionVar+1}	
				<li class="clearfix promoConditionAppended" id="promoConditionAppended_{$appendConditionVar}">
					{if (isset($eachDataCondition['conditions']) && (is_array($eachDataCondition['conditions']))) || $eachDataCondition['condition'] eq ''}
						{assign var="appendConditionRootVar" value=$appendConditionRootVar+1}	
						{assign var="appendRootRelVarRoot" value=$appendRootRelVarRoot|cat:"[conditions]["|cat:$eachDataConditionKey|cat:"]"}
						{assign var="relForRoot" value=$relForRoot|cat:"[conditions]["|cat:$eachDataConditionKey|cat:"]"}
						<ul class="levl-00 promoRoot" rel="{$relForRoot}" id="promoRootConditionAppended_{$appendConditionRootVar}">
							<div>{html->anchor caption="{$language.lblPromotionAddCondition}" class="promotionAddCondition grayBtn fixing_right"}
								{$language.lblPromotionConditionNote1}&nbsp;
								{form->select class="width-100px" name="promotion_data[conditions]"|cat:{$relForRoot}|cat:"[set]" options="all->{$language.lblPromotionConditionAll}~*any->{$language.lblPromotionConditionAny}" value=$eachDataCondition['set']}&nbsp;
								{$language.lblPromotionConditionNote2}&nbsp;
								{form->select class="width-100px" name="promotion_data[conditions]"|cat:{$relForRoot}|cat:"[set_value]"  options="1->{$language.lblPromotionConditionTrue}~*0->{$language.lblPromotionConditionFalse}" value=$eachDataCondition['set_value']}
								{html->anchor class="deleteGroupRow grayBtn" caption="X" title="{$language.lblDelete}"}
																
							</div>							
							{generateConditions data=$eachDataCondition['conditions']}
							{assign var="appendRootRelVarRoot" value=""}
							{assign var="relForRoot" value=""}
						</ul>
					{else}
						{assign var="appendRootRelVar" value=$appendRootRelVarRoot|cat:"[conditions]["|cat:$eachDataConditionKey|cat:"]"}
						{assign var="eachDataConditionSchema" value=$schemaData.conditions[$eachDataCondition['condition']]}
						{assign var="dataCondition" value=$eachDataCondition['condition']}						
						{if isset($eachDataConditionSchema.group)}
							{assign var="dataConditionSchemaGroupKey" value=$eachDataConditionSchema.group}			
						{else}
							{assign var="dataConditionSchemaGroupKey" value=''}			
						{/if}						
						<div class="conditionInd clearfix">	
							<div class="left2 clearfix">
                            <span class="spanBld">{$language[$eachDataConditionSchema.lang]}</span>
                            {form->hidden class="promotionCondtion" name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[condition]" value=$dataCondition}
							{if $dataConditionSchemaGroupKey}
								{form->hidden class="promotionCondtionGroup" name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[condition_group]" value=$dataConditionSchemaGroupKey}
							{/if}	
							{if $eachDataConditionSchema.type eq 'mixed'}
								{form->select class="width-136px promotionCondtionElement_$dataCondition requiredData" caption="->{$language.lblSelect}" name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[condition_element]" options=$eachDataCondition['select_list'] value=$eachDataCondition['condition_element'] custom="true"} 
								{foreach from=$eachDataConditionSchema.operatorSelectors item="operatorSelectors" key="operatorKey"}
									{form->select class="width-136px mixedselectors hide" mixedselector="{$operatorKey}" name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[operator]" options='~*'|implode:$operatorSelectors value=$eachDataCondition['operator']}
								{/foreach}	
							{else}
								{form->select class="width-136px promotionCondtionOperator"  name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[operator]" options='~*'|implode:$eachDataConditionSchema.operators value=$eachDataCondition['operator']}
							{/if}							
							{if $eachDataConditionSchema.type eq 'input'}
								{form->textbox  name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[value]" class="textbox width-136px  requiredData"  maxlength="255" autocomplete="off" value=$eachDataCondition['value']}
{else if $eachDataConditionSchema.type eq 'inputDate'}
							{form->textbox  
                            name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[valueFrom]" 			class="width-136px date_picker_field form-control requiredData enableDefaultDatePicker"  
                            maxlength="255" autocomplete="off" value=$eachDataCondition['valueFrom']}
							{form->textbox  name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[valueTo]" class="width-136px date_picker_field form-control requiredData enableDefaultDatePicker"  maxlength="255" autocomplete="off" value=$eachDataCondition['valueTo']}
							
							{else if $eachDataConditionSchema.type eq 'numberSelector'}
							{assign var="numberArray" value=''}							
							{assign var="cnt" value=0}
							{for $yl=$eachDataConditionSchema.fromVal to $eachDataConditionSchema.toVal}    
							{$numberArray[$cnt][0]=$yl}
							{$numberArray[$cnt][1]=$yl}
							{assign var="cnt" value=$cnt+1}
							{/for}
							{form->select caption="{$language.lblSelect}" name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[valueNum]" class="form-control requiredData" value=$eachDataCondition['valueNum'] options=$numberArray}
							{else if $eachDataConditionSchema.type eq 'picker'}
								{html->anchor class="deleteConditionRow fixing_right grayBtn" caption="X" title="{$language.lblDelete}"}
                            </div>
{if $eachDataCondition.condition=='products'  && $store_id|default:'' neq ''}
						{assign var="storeLink" value="sid/{$store_id|default:''}/"}
						{else}
						{assign var="storeLink" value=""}
						{/if}
							<div class="right2 clearfix mrgn_top2">
								{html->anchor href="{$eachDataConditionSchema.pickerLink}" class="popupPicker grayBtn no-magn" rel="{$dataCondition}" caption="{$language[$eachDataConditionSchema.popupLink]}" title="{$language[$eachDataConditionSchema.popupLink]}"}
								<br/><br/>
								<div class="grid_table00"> 
									<table width="100%" border="0" cellspacing="0" cellpadding="0" class="popupPickerDataList">	
									{form->hidden class="popupPickerDataValues requiredData" name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[value]" value=$eachDataCondition['value']}
										<tbody>											
											<tr class="noRecordsForPicker {if is_array($eachDataCondition['value_details'])} hide{/if}">
												<td>
													<div class="noNoRecordInfo_2">
														{$language.msgNoRecords}
													</div>
												</td>
											</tr>
											{assign var=valueDetailsIds value=","|explode:$eachDataCondition['value']}
											{foreach $eachDataCondition['value_details'] as $valueDetailsKey => $valueDetails}
												{assign var="extractedProductID" value= $valueDetailsIds.$valueDetailsKey}
												<tr class="pickerDataList" rel="{$valueDetailsIds.$valueDetailsKey}">
													<td width="95%">
													{$valueDetails.detailTitle}													
													</td>
													<td align="right">
														{html->anchor class="deletePickerDataRow" rel="{$valueDetailsIds.$valueDetailsKey}" title="{$language.lblDelete}" caption="X"}
													</td>
												</tr>
											{/foreach}
										</tbody>
									</table>	
								</div>
							{/if}
							{if $eachDataConditionSchema.type eq 'mixed'}
								{if $eachDataCondition['value']!=''}
									{assign var="mixedTextBoxHide" value=""}
									{assign var="mixedSelectBoxHide" value="hide"}
								{else if $eachDataCondition['value_select']!=''}
									{assign var="mixedTextBoxHide" value="hide"}
									{assign var="mixedSelectBoxHide" value=""}
								{else}
									{assign var="mixedTextBoxHide" value=""}
									{assign var="mixedSelectBoxHide" value="hide"}	
								{/if}
								
								
								{if isset($eachDataCondition['option_list'])}
								{assign var="option_list" value=$eachDataCondition['option_list']}
							{else}
								{assign var="option_list" value=$eachDataCondition['option_list']|default:array()}
							{/if}
							{if isset($eachDataCondition['value_select'])}
								{assign var="value_select" value=$eachDataCondition['value_select']}
							{else}
								{assign var="value_select" value=$eachDataCondition['value_select']|default:array()}
							{/if}
							
								{form->textbox  name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[value]" class="textbox width-136px  mixedTextBox {$mixedTextBoxHide}  requiredData form-select"  maxlength="255" autocomplete="off" value=$eachDataCondition['value']}
								{form->select class="width-136px mixedSelectBox {$mixedSelectBoxHide}" name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[value_select]" options=$option_list value=$value_select}
							{/if}
							{if $eachDataConditionSchema.type neq 'picker'}
								{html->anchor class="deleteConditionRow fixing_right grayBtn" caption="X" title="{$language.lblDelete}"}
							{/if}
							{if $eachDataConditionSchema.type eq 'select'}
								{if $eachDataConditionSchema.optionGroup|default:'' eq 'Yes'}
									{form->select 
										class="width-136px requiredData" 
										optionGroup="Yes" 
										name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[value_select]" 
										options=$eachDataCondition['select_list'] 
										value=$eachDataCondition['value_select']}
	{else if isset($eachDataConditionSchema.options)}
									{form->select 
										class="form-control requiredData" 
										name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[value_select]" 
										options=$eachDataConditionSchema.options 
										value=$eachDataCondition['value_select']}							
							
								{else}
									{form->select 
										class="width-136px requiredData" 
										name="promotion_data[conditions]"|cat:{$appendRootRelVar}|cat:"[value_select]" 
										options=$eachDataCondition['select_list'] 
										value=$eachDataCondition['value_select']}
								{/if}
							{/if}
						</div>	
						</div>
					{/if}
				</li>
			{/foreach}	
		{/function}
		{* call function generateConditions *}
		{if isset($resDataConditions)}
		{generateConditions data=$resDataConditions['conditions']}
		{/if}
	</ul>
	<!--Firt time NoRecord found msg-->
	{if isset($resDataConditions)}
		{assign var="conditionCount" value=$resDataConditions['conditions']|count}
	{else}
		{assign var="conditionCount" value='0'}
	{/if}	
    <div id="noConditionData" class="noNoRecordInfo_1 {if $conditionCount gt 0} hide {/if}">
		{$language.msgNoRecords}
	</div>
    
    <ul class="promoConditionCopySource">

		{assign var="conditionsDataCounter" value=0}
		{foreach from=$schemaData.conditions item="dataConditionSchema" key="dataCondition"}	
			{if isset($dataConditionSchema.groupLabel)}
				{assign var="dataConditionSchemaGroup" value=$language[$dataConditionSchema.groupLabel]}			
			{else}
				{assign var="dataConditionSchemaGroup" value=''}			
			{/if}
			
			{if isset($dataConditionSchema.group)}
				{assign var="dataConditionSchemaGroupKey" value=$dataConditionSchema.group}			
			{else}
				{assign var="dataConditionSchemaGroupKey" value=''}			
			{/if}
			
			{if isset($dataConditionSchema.optionGroup)}
				{assign var="dataConditionSchemaoptionGroup" value=$dataConditionSchema.optionGroup|default:''}	
			{else}
				{assign var="dataConditionSchemaoptionGroup" value=""}	
			{/if}			
			
			{if $dataConditionSchemaGroup}
				{$conditionDataArray.$dataConditionSchemaGroup.$conditionsDataCounter.0=$dataCondition}
				{$conditionDataArray.$dataConditionSchemaGroup.$conditionsDataCounter.1=$language[$dataConditionSchema.lang]}
				{$conditionDataArray.$dataConditionSchemaGroup.$conditionsDataCounter.2="datatype='{$dataConditionSchema.type}' optionGroup='{$dataConditionSchema.optionGroup}'"}
			{else}
				{$conditionDataArray.$conditionsDataCounter.0=$dataCondition}
				{$conditionDataArray.$conditionsDataCounter.1=$language[$dataConditionSchema.lang]}
				{$conditionDataArray.$conditionsDataCounter.2="datatype='{$dataConditionSchema.type}' optionGroup='{$dataConditionSchemaoptionGroup}'"}
			{/if}
			{assign var="conditionsDataCounter" value=$conditionsDataCounter+1}
			<li class="dataCondition_{$dataCondition} clearfix hide">
				<div class="conditionInd clearfix">
					<div class="left2 clearfix">
						<span class="spanBld">{$language[$dataConditionSchema.lang]}</span>
						{if isset($dataConditionSchema.subtext) && $dataConditionSchema.subtext}
							<span class="sub-text">
								{$language[$dataConditionSchema.subtext]}
							</span>
						{/if}
                        {form->hidden class="promotionCondtion" name="promotionCondtion-" value=$dataCondition post_back="false"}
						{if $dataConditionSchemaGroup}
							{form->hidden class="promotionCondtionGroup" name="promotionCondtionGroup-" value=$dataConditionSchemaGroupKey post_back="false"}
						{/if}	
						{if $dataConditionSchema.type eq 'mixed'}
							{form->select class="width-136px promotionCondtionElement_$dataCondition requiredData" caption="->{$language.lblSelect}" name="promotionCondtionElement-"} 	
							{foreach from=$dataConditionSchema.operatorSelectors item="operatorSelectors" key="operatorKey"}
                                                            
								{form->select class="width-136px mixedselectors hide" mixedselector="{$operatorKey}" name="promotionCondtionOperator-" options='~*'|implode:$operatorSelectors}
							{/foreach}	
						{else}	
							{form->select class="width-136px promotionCondtionOperator"  name="promotionCondtionOperator-" options='~*'|implode:$dataConditionSchema.operators}
						{/if}
						{if isset($dataConditionSchema.customFieldClass)}
								{assign var="customFieldClass" value=$dataConditionSchema.customFieldClass}
							{else}
								{assign var="customFieldClass" value=''}
							{/if}						
						{if $dataConditionSchema.type eq 'input'}
							{form->textbox  name="promotionCondtionValue-" class="textbox width-136px  {$customFieldClass} requiredData"  maxlength="255" autocomplete="off"}
{else if $dataConditionSchema.type eq 'inputDate'}
						{form->textbox  name="promotionCondtionValueFrom-" class="width-136px date_picker_field form-control {$customFieldClass} requiredData"  maxlength="255" autocomplete="off"}
						{form->textbox  name="promotionCondtionValueTo-" class="width-136px date_picker_field form-control {$customFieldClass} requiredData"  maxlength="255" autocomplete="off"}
						{else if $dataConditionSchema.type eq 'numberSelector'}
							{assign var="numberArray" value=''}							
							{assign var="cnt" value=0}
							{for $yl=$dataConditionSchema.fromVal to $dataConditionSchema.toVal}    
							{$numberArray[$cnt][0]=$yl}
							{$numberArray[$cnt][1]=$yl}
							{assign var="cnt" value=$cnt+1}
							{/for}
							{form->select  name="promotionCondtionValueNum-" caption="{$language.lblSelect}" class="form-control {$customFieldClass} requiredData" options=$numberArray}
						
						{else if $dataConditionSchema.type eq 'picker'}
							{html->anchor class="deleteConditionRow fixing_right grayBtn" caption="X" title="{$language.lblDelete}"}
					</div>
					<div class="right2 clearfix mrgn_top2">
						{if $dataCondition=='products' && $store_id|default:'' neq ''}
						{assign var="storeLink" value="sid/{$store_id|default:''}/"}
						{else}
						{assign var="storeLink" value=""}
						{/if}
							{html->anchor href="{$dataConditionSchema.pickerLink}" class="popupPicker grayBtn no-magn" rel="{$dataCondition}" caption="{$language[$dataConditionSchema.popupLink]}" title="{$language[$dataConditionSchema.popupLink]}"}
							<br/><br/>
							<div class="grid_table00"> 
								<table width="100%" border="0" cellspacing="0" cellpadding="0" class="popupPickerDataList">	
								{form->hidden class="popupPickerDataValues requiredData" name="promotionCondtionValue-"}
									<tbody>
										<tr class="noRecordsForPicker">
											<td>
												<div class="noNoRecordInfo_2">
													{$language.msgNoRecords}
												</div>
											</td>
										</tr>
									</tbody>
								</table>	
							</div>
						{/if}
						{if $dataConditionSchema.type eq 'mixed'}
							{form->textbox  name="promotionCondtionValue-" class="textbox form-select mixedTextBox requiredData"  maxlength="255" autocomplete="off"}
							{form->select class="width-136px mixedSelectBox hide" name="promotionCondtionValueSelect-"}
						{/if}
						{if $dataConditionSchema.type neq 'picker'}
							{html->anchor class="deleteConditionRow fixing_right grayBtn" caption="X" title="{$language.lblDelete}"}
						{/if}
						{if $dataConditionSchema.type eq 'select'}
							{if $dataCondition eq 'usergroup' && $userGrpData|default:'' neq ''}
								{assign var="selectTypeOptions" value=$userGrpData}
							{else if $dataCondition eq 'country' && $countryData|default:'' neq ''}
								{assign var="selectTypeOptions" value=$countryData}	
							{else if $dataCondition eq 'state' && $stateData|default:'' neq ''}
								{assign var="selectTypeOptions" value=$stateData}	
							{else if $dataCondition eq 'payment_method' && $paymentMethodData|default:'' neq ''}
								{assign var="selectTypeOptions" value=$paymentMethodData}	
		{else if $dataConditionSchema.options|default:'' neq ''}	
							{assign var="selectTypeOptions" value=$dataConditionSchema.options|default:''}								
							
							{else}
								{assign var="selectTypeOptions" value=''}		
							{/if}
							{form->select class="width-136px selectSelectBox_$dataCondition requiredData" name="promotionCondtionValueSelect-" options=$selectTypeOptions}
						{/if}
					</div>	
				</div>	
			</li>
		{/foreach}
		{*$conditionDataArray|print_r*}
		{assign var="optionGroupStatus" value="No"}
		{if $dataConditionSchemaGroup}
			{assign var="optionGroupStatus" value="Yes"}
		{/if}
		<li class="clearfix promoRootConditionSelector hide">
			<!--<div class="left1">&nbsp;</div>-->
			<div class="left2">                    
				{form->select class="width-136px" name="promoConditionRootSelector" id="promoConditionRootSelector" options=$conditionDataArray caption="->{$language.lblSelect}" custom="true" optionGroup=$optionGroupStatus} 	 
			</div>
		</li>	
		<li class="clearfix promoRootNode hide">
			<div>
				{$language.lblPromotionConditionNote1}&nbsp;
				{form->select class="width-100px" name="promotionCondtionSet-" options="all->{$language.lblPromotionConditionAll}~*any->{$language.lblPromotionConditionAny}"}&nbsp;
				{$language.lblPromotionConditionNote2}&nbsp;
				{form->select class="width-100px" name="promotionCondtionSetValue-" options="1->{$language.lblPromotionConditionTrue}~*0->{$language.lblPromotionConditionFalse}"}
				{html->anchor class="deleteGroupRow grayBtn" caption="X" title="{$language.lblDelete}"}
				{html->anchor caption="{$language.lblPromotionAddCondition}" class="promotionAddCondition grayBtn fixing_right"}
			</div>										
		</li> 
	</ul>	
</div>