{assign var="appendBonusVar" value=0}
{assign var="appendBonusRootVar" value=1}
{assign var="appendBonusRootRelVarRoot" value=""}
{assign var="appendBonusRootRelVar" value=""}
<div class="form_listing promoBonusList">
	<ul class="levl-00 promoBonusRoot" rel="">
		<li class="clearfix">
        <h3><span>
		{$language.lblPromotionConditions}</span>
        {html->anchor 
                    caption="{$language.lblPromotionAddCondition}" 
                    class="promotionAddBonus grayBtn  sprite-bf fixing_right"}
		</h3>
        </li>
		<li class="clearfix promoBonusParent"> <div>
				{if isset($resDataBonus)}
					{assign var="resDataConditionsSet" value=$resDataBonus.set|default:''}
					{assign var="resDataConditionsset_value" value=$resDataBonus.set_value|default:''}
				{else}
					{assign var="resDataConditionsSet" value=""}
					{assign var="resDataConditionsset_value" value=""}
				{/if}
               
              {$language.lblPromotionConditionNote1}&nbsp;
				{form->select 
                    class = "width-100px"                            
                    customselect="Yes"
                    name="promotion_data[bonuses][set]" 
                    options="all->{$language.lblPromotionConditionAll}~*any->{$language.lblPromotionConditionAny}" 
                    value=$resDataConditionsSet
                }&nbsp;
               {$language.lblPromotionConditionNote2}&nbsp;
				{form->select 
                    class = "width-100px"                            
                    customselect="Yes"
                    name="promotion_data[bonuses][set_value]" 
                    options="1->{$language.lblPromotionConditionTrue}~*0->{$language.lblPromotionConditionFalse}" 
                    value=$resDataConditionsset_value
                 } &nbsp;
                 </div>
		</li>  	
		
		{*$resDataConditions['bonuses']|print_r*}
		{* define the function *}
		{function name=generateBonus}
			{foreach $data as $eachDataBonusKey => $eachDataBonus}			
				{assign var="appendBonusVar" value=$appendBonusVar+1}	
				<li class="clearfix promoBonusAppended" id="promoBonusAppended_{$appendBonusVar}">
					{if (isset($eachDataBonus['bonuses']) && (is_array($eachDataBonus['bonuses']))) || $eachDataBonus['bonus'] eq ''}
						{assign var="appendBonusRootVar" value=$appendBonusRootVar+1}	
						{assign var="appendBonusRootRelVarRoot" value=$appendBonusRootRelVarRoot|cat:"[bonuses]["|cat:$eachDataBonusKey|cat:"]"}
						{assign var="relForRoot" value=$relForRoot|cat:"[bonuses]["|cat:$eachDataBonusKey|cat:"]"}
						<ul class="levl-00 promoBonusRoot" rel="{$relForRoot}" id="promoRootBonusAppended_{$appendBonusRootVar}">
							<div>{html->anchor caption="{$language.lblPromotionAddCondition}" class="promotionAddBonus grayBtn  fixing_right sprite-bf"}
								{$language.lblPromotionConditionNote1}&nbsp;
								{form->select class="width-100px" name="promotion_data[bonuses]"|cat:{$relForRoot}|cat:"[set]" options="all->{$language.lblPromotionConditionAll}~*any->{$language.lblPromotionConditionAny}" value=$eachDataBonus['set']}&nbsp;
								{$language.lblPromotionConditionNote2}&nbsp;
								{form->select class="width-100px" name="promotion_data[bonuses]"|cat:{$relForRoot}|cat:"[set_value]"  options="1->{$language.lblPromotionConditionTrue}~*0->{$language.lblPromotionConditionFalse}" value=$eachDataBonus['set_value']}
								{html->anchor class="deleteGroupRow btn btn-default fixing_right delete-af sprite-af"    caption="X" title="{$language.lblDelete}"}
																
							</div>							
							{generateBonus data=$eachDataBonus['bonuses']}
							{assign var="appendBonusRootRelVarRoot" value=""}
							{assign var="relForRoot" value=""}
						</ul>
					{else}					
						{assign var="appendBonusRootRelVar" value=$appendBonusRootRelVarRoot|cat:"[bonuses]["|cat:$eachDataBonusKey|cat:"]"}
						{assign var="eachDataBonusSchema" value=$schemaUserData.conditions[$eachDataBonus['bonus']]}
						{assign var="dataCondition" value=$eachDataBonus['bonus']}						
						{if isset($eachDataBonusSchema.group)}
							{assign var="dataConditionSchemaGroupKey" value=$eachDataBonusSchema.group}			
						{else}
							{assign var="dataConditionSchemaGroupKey" value=''}			
						{/if}						
						<div class="bonusInd clearfix form-inline">	
							<div class="left2 clearfix">
                           <span class="spanBld">{$language[$eachDataBonusSchema.lang]}</span>
                            {form->hidden class="promotionBonus" 		name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[bonus]" value=$dataCondition}
							{if $dataConditionSchemaGroupKey}
								{form->hidden class="promotionBonusGroup" name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[bonus_group]" value=$dataConditionSchemaGroupKey}
							{/if}	
							{if $eachDataBonusSchema.type eq 'mixed'}
								{form->select 
                                class="width-136px form-control promotionBonusElement_$dataCondition requiredData" 
                                caption="->{$language.lblSelect}" 				 name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[condition_element]" options=$eachDataBonus['select_list'] value=$eachDataBonus['condition_element'] custom="true"} 
								{foreach from=$eachDataBonusSchema.operatorSelectors item="operatorSelectors" key="operatorKey"}
					{form->select 
                                    class="width-136px form-control mixedselectors hide" 
                                    mixedselector="{$operatorKey}" 			name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[operator]" 
                                    options='~*'|implode:$operatorSelectors value=$eachDataBonus['operator']}
								{/foreach}	
							{else}
								{form->select class="width-136px form-control promotionBonusOperator"  name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[operator]" options='~*'|implode:$eachDataBonusSchema.operators value=$eachDataBonus['operator']}
							{/if}							
							{if $eachDataBonusSchema.type eq 'input'}
								{form->textbox  
                                name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[value]" 
                                class="textbox form-control width-136px requiredData"  
                                maxlength="255" autocomplete="off" 
                                value=$eachDataBonus['value']}
							{else if $eachDataBonusSchema.type eq 'inputDate'}
							{form->textbox  
                            name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[valueFrom]" 			class="width-136px date_picker_field form-control requiredData enableDefaultDatePicker"  
                            maxlength="255" autocomplete="off" value=$eachDataBonus['valueFrom']}
							{form->textbox  name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[valueTo]" class="width-136px form-control date_picker_field requiredData enableDefaultDatePicker"  maxlength="255" autocomplete="off" value=$eachDataBonus['valueTo']}
							
							{else if $eachDataBonusSchema.type eq 'numberSelector'}
							{assign var="numberArray" value=''}							
							{assign var="cnt" value=0}
							{for $yl=$eachDataBonusSchema.fromVal to $eachDataBonusSchema.toVal}    
							{$numberArray[$cnt][0]=$yl}
							{$numberArray[$cnt][1]=$yl}
							{assign var="cnt" value=$cnt+1}
							{/for}
							{form->select caption="{$language.lblSelect}" name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[valueNum]" class="width-136px form-control requiredData" value=$eachDataBonus['valueNum'] options=$numberArray}
							{else if $eachDataBonusSchema.type eq 'picker'}
								{html->anchor class="deleteBonusRow btn btn-default fixing_right delete-af sprite-af"    caption="X" title="{$language.lblDelete}"}
                            </div>
							<div class="right2 clearfix mrgn_top2">
								{html->anchor href="{$eachDataBonusSchema.pickerLink}" class="popupPicker grayBtn  fixing_right sprite-bf" rel="{$dataCondition}" caption="{$language[$eachDataBonusSchema.popupLink]}" title="{$language[$eachDataBonusSchema.popupLink]}" popuptitle="{$language[$eachDataBonusSchema.popupLink]}"}
								<div class="grid_table00"> 
									<table width="100%" border="0" cellspacing="0" cellpadding="0" class="popupPickerDataList">	
									{form->hidden class="popupPickerDataValues requiredData" name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[value]" value=$eachDataBonus['value']}
										<tbody>											
											<tr class="noRecordsForPicker {if is_array($eachDataBonus['value_details'])} hide{/if}">
												<td class="rmv-pad-lft rmv-pad-rgt">
													<div class="noNoRecordInfo_2">
														{$language.msgNoRecords}
													</div>
												</td>
											</tr>
											{assign var=valueDetailsIds value=","|explode:$eachDataBonus['value']}
											{foreach $eachDataBonus['value_details'] as $valueDetailsKey => $valueDetails}
												{assign var="extractedproduct_id" value= $valueDetailsIds.$valueDetailsKey}
												<tr class="pickerDataList" rel="{$valueDetailsIds.$valueDetailsKey}">
													<td width="95%">
													{$valueDetails.detailTitle}													
													</td>
													<td align="right">
														{html->anchor class="deletePickerDataRow delete sprite icon" rel="{$valueDetailsIds.$valueDetailsKey}"   caption="X" title="{$language.lblDelete}"}
													</td>
												</tr>
											{/foreach}
										</tbody>
									</table>	
								</div>
							{/if}
							{if $eachDataBonusSchema.type eq 'mixed'}
								{if $eachDataBonus['value']!=''}
									{assign var="mixedTextBoxHide" value=""}
									{assign var="mixedSelectBoxHide" value="hide"}
								{else if $eachDataBonus['value_select']!=''}
									{assign var="mixedTextBoxHide" value="hide"}
									{assign var="mixedSelectBoxHide" value=""}
								{else}
									{assign var="mixedTextBoxHide" value=""}
									{assign var="mixedSelectBoxHide" value="hide"}	
								{/if}
								
								
								{if isset($eachDataBonus['option_list'])}
								{assign var="option_list" value=$eachDataBonus['option_list']}
							{else}
								{assign var="option_list" value=$eachDataBonus['option_list']|default:array()}
							{/if}
							{if isset($eachDataBonus['value_select'])}
								{assign var="value_select" value=$eachDataBonus['value_select']}
							{else}
								{assign var="value_select" value=$eachDataBonus['value_select']|default:array()}
							{/if}
							
								{form->textbox  name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[value]" class="width-136px form-control mixedTextBox {$mixedTextBoxHide}  requiredData form-select"  maxlength="255" autocomplete="off" value=$eachDataBonus['value']}
								{form->select class="width-136px form-control mixedSelectBox {$mixedSelectBoxHide}" name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[value_select]" options=$option_list value=$value_select}
							{/if}
							{if $eachDataBonusSchema.type neq 'picker'}
								{html->anchor class="deleteBonusRow btn btn-default fixing_right delete-af sprite-af"    caption="X" title="{$language.lblDelete}"}
							{/if}
							{if $eachDataBonusSchema.type eq 'select'}
								{if isset($eachDataBonusSchema.optionGroup) &&  $eachDataBonusSchema.optionGroup eq 'Yes'}
									{form->select 
										class="width-136px form-control requiredData" 
										optionGroup="Yes" 
										name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[value_select]" 
										options=$eachDataBonus['select_list'] 
										value=$eachDataBonus['value_select']}
							{else if isset($eachDataBonusSchema.options)}
									{form->select 
										class="width-136px form-control requiredData" 
										name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[value_select]" 
										options=$eachDataBonusSchema.options 
										value=$eachDataBonus['value_select']}											
								{else}
									{form->select 
										class="width-136px form-control requiredData" 
										name="promotion_data[bonuses]"|cat:{$appendBonusRootRelVar}|cat:"[value_select]" 
										options=$eachDataBonus['select_list'] 
										value=$eachDataBonus['value_select']}
								{/if}
							{/if}
						</div>	
						</div>
					{/if}
				</li>
			{/foreach}	
		{/function}
		{* call function generateBonus *}
		{if $resDataBonus['bonuses']|default:''}
			{generateBonus data=$resDataBonus['bonuses']|default:''}
		{/if}	
	</ul>
	<!--Firt time NoRecord found msg-->

	{assign var="bonusCount" value=0}
	{if $resDataBonus['bonuses']|default:''}
		{assign var="bonusCount" value=$resDataBonus['bonuses']|count}
	{/if}		
    <div id="noBonusData" class="noNoRecordInfo_1 {if $bonusCount gt 0} hide {/if}">
		{$language.msgNoRecords}
	</div>
    
    <ul class="promoBonusCopySource">
		{assign var="promoBonusCounter" value=0}
		{foreach from=$schemaUserData.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.$promoBonusCounter.0=$dataCondition}
				{$conditionDataArray.$dataConditionSchemaGroup.$promoBonusCounter.1=$language[$dataConditionSchema.lang]}
				{$conditionDataArray.$dataConditionSchemaGroup.$promoBonusCounter.2="datatype='{$dataConditionSchema.type}' optionGroup='{$dataConditionSchema.optionGroup}'"}
			{else}
				{$conditionDataArray.$promoBonusCounter.0=$dataCondition}
				{$conditionDataArray.$promoBonusCounter.1=$language[$dataConditionSchema.lang]}
				{$conditionDataArray.$promoBonusCounter.2="datatype='{$dataConditionSchema.type}' optionGroup='{$dataConditionSchemaoptionGroup}'"}
			{/if}
			{assign var="promoBonusCounter" value=$promoBonusCounter+1}
			<li class="promoBonus_{$dataCondition} clearfix hide">
				<div class="bonusInd clearfix form-inline">
					<div class="form-group">
						<label>{$language[$dataConditionSchema.lang]}</label>
						{if isset($dataConditionSchema.subtext) && $dataConditionSchema.subtext}
							<span class="sub-text">
								{$language[$dataConditionSchema.subtext]}
							</span>
						{/if}
                        {form->hidden class="promotionBonus" name="promotionBonus-" value=$dataCondition post_back="false"}
						{if $dataConditionSchemaGroup}
							{form->hidden class="promotionBonusGroup" name="promotionBonusGroup-" value=$dataConditionSchemaGroupKey post_back="false"}
						{/if}	
						{if $dataConditionSchema.type eq 'mixed'}
							{form->select class="width-136px form-control promotionBonusElement_$dataCondition requiredData" caption="->{$language.lblSelect}" name="promotionBonusElement-"} 	
							{foreach from=$dataConditionSchema.operatorSelectors item="operatorSelectors" key="operatorKey"}
								{form->select class="width-136px form-control mixedselectors hide" mixedselector="{$operatorKey}" name="promotionBonusOperator-" options='~*'|implode:$operatorSelectors}
							{/foreach}	
						{else}	
							{form->select class="width-136px form-control promotionBonusOperator"  name="promotionBonusOperator-" 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="promotionBonusValue-" class="textbox width-136px form-control {$customFieldClass} requiredData"  maxlength="255" autocomplete="off"}
						{else if $dataConditionSchema.type eq 'inputDate'}
						{form->textbox  name="promotionBonusValueFrom-" class="date_picker_field width-136px form-control {$customFieldClass} requiredData"  maxlength="255" autocomplete="off"}
						{form->textbox  name="promotionBonusValueTo-" class="date_picker_field width-136px 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="promotionBonusValueNum-" caption="{$language.lblSelect}" class="width-136px form-control {$customFieldClass} requiredData" options=$numberArray}
						{else if $dataConditionSchema.type eq 'picker'}
							{html->anchor class="deleteBonusRow btn btn-default fixing_right delete-af sprite-af"    caption="X" title="{$language.lblDelete}"}
					</div>
					<div class="right2 clearfix mrgn_top2">
							{html->anchor href="{$dataConditionSchema.pickerLink}" class="popupPicker grayBtn  fixing_right sprite-bf" rel="{$dataCondition}" caption="{$language[$dataConditionSchema.popupLink]}" title="{$language[$dataConditionSchema.popupLink]}" popuptitle="{$language[$dataConditionSchema.popupLink]}"}
							<div class="grid_table00"> 
								<table width="100%" border="0" cellspacing="0" cellpadding="0" class="popupPickerDataList">	
								{form->hidden class="popupPickerDataValues requiredData" name="promotionBonusValue-"}
									<tbody>
										<tr class="noRecordsForPicker">
											<td class="rmv-pad-lft rmv-pad-rgt">
												<div class="noNoRecordInfo_2">
													{$language.msgNoRecords}
												</div>
											</td>
										</tr>
									</tbody>
								</table>	
							</div>
						{/if}
						{if $dataConditionSchema.type eq 'mixed'}
							{form->textbox  name="promotionBonusValue-" class="textbox width-136px form-control form-select mixedTextBox requiredData"  maxlength="255" autocomplete="off"}
							{form->select class="width-136px form-control mixedSelectBox hide" name="promotionBonusValueSelect-"}
						{/if}
						{if $dataConditionSchema.type neq 'picker'}
							{html->anchor class="deleteBonusRow btn btn-default fixing_right delete-af sprite-af"    caption="X" title="{$language.lblDelete}"}
						{/if}
						{if $dataConditionSchema.type eq 'select'}
							{if $dataCondition eq 'usergroup' && $userGrpData|default:'' neq ''}
								{assign var="selectTypeOptions" value=$userGrpData|default:''}
							{else if ($dataCondition eq 'country' || $dataCondition eq 'billingcountry')  && $countryData|default:'' neq ''}
								{assign var="selectTypeOptions" value=$countryData|default:''}	
							{else if ($dataCondition eq 'state' || $dataCondition eq 'billingstate') && $stateData|default:'' neq ''}
								{assign var="selectTypeOptions" value=$stateData|default:''}	
							{else if $dataCondition eq 'payment_method' && $paymentMethodData|default:'' neq ''}
								{assign var="selectTypeOptions" value=$paymentMethodData|default:''}	
							{else if $dataConditionSchema.options|default:'' neq ''}	
							{assign var="selectTypeOptions" value=$dataConditionSchema.options|default:''}										
							{else}
								{assign var="selectTypeOptions" value=''}		
							{/if}
							{form->select class="width-136px form-control selectSelectBox_$dataCondition requiredData" name="promotionBonusValueSelect-" 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 promoRootBonusSelector hide">
			<!--<div class="left1">&nbsp;</div>-->
			<div class="left2">                    
				{form->select 
                class = "width-136px select-custom"                            
                customselect="Yes"
                setwidth="col25" 
                name="promoBonusRootSelector" 
                id="promoBonusRootSelector" 
                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="promotionBonusSet-" options="all->{$language.lblPromotionConditionAll}~*any->{$language.lblPromotionConditionAny}"}&nbsp;
				{$language.lblPromotionConditionNote2}&nbsp;
				{form->select class="width-100px" name="promotionBonusSetValue-" options="1->{$language.lblPromotionConditionTrue}~*0->{$language.lblPromotionConditionFalse}"}
				{html->anchor class="deleteGroupRow btn btn-default pull-right delete-af sprite-af"   caption="X" title="{$language.lblDelete}"}
				{html->anchor caption="{$language.lblPromotionAddCondition}" class="promotionAddCondition grayBtn  fixing_right sprite-bf"}
			</div>										
		</li> 
	</ul>	
</div>