<div class="uk-width-1">
<a href="<?php echo Yii::app()->request->baseUrl; ?>/merchant/FoodItem/Do/Add" class="uk-button"><i class="fa fa-plus"></i> <?php echo Yii::t("default","Add New")?></a>
<a href="<?php echo Yii::app()->request->baseUrl; ?>/merchant/FoodItem" class="uk-button"><i class="fa fa-list"></i> <?php echo Yii::t("default","List")?></a>
<a href="<?php echo Yii::app()->request->baseUrl; ?>/merchant/FoodItem/Do/Sort" class="uk-button"><i class="fa fa-sort-alpha-asc"></i> <?php echo Yii::t("default","Sort")?></a>
</div>


<div class="spacer"></div>

<div id="error-message-wrapper"></div>

<form class="uk-form uk-form-horizontal forms" id="forms">
<?php echo CHtml::hiddenField('action','FoodItemAdd')?>
<?php echo CHtml::hiddenField('id',isset($_GET['id'])?$_GET['id']:"");?>
<?php if (!isset($_GET['id'])):?>
<?php echo CHtml::hiddenField("redirect",Yii::app()->request->baseUrl."/merchant/FoodItem/Do/Add")?>
<?php endif;?>

<?php 
$addon_item='';
$price='';
$category='';
$cooking_ref_selected='';
$multi_option_Selected='';
$multi_option_value_selected='';
$ingredients_selected='';

if (isset($_GET['id'])){
	if (!$data=Yii::app()->functions->getFoodItem2($_GET['id'])){
		echo "<div class=\"uk-alert uk-alert-danger\">".
		Yii::t("default","Sorry but we cannot find what your are looking for.")."</div>";
		return ;
	}		
	$addon_item=isset($data['addon_item'])?(array)json_decode($data['addon_item']):false;		
	$category=isset($data['category'])?(array)json_decode($data['category']):false;
	$price=isset($data['price'])?(array)json_decode($data['price']):false;	
	$cooking_ref_selected=isset($data['cooking_ref'])?(array)json_decode($data['cooking_ref']):false;
	$multi_option_Selected=isset($data['multi_option'])?(array)json_decode($data['multi_option']):false;
	$multi_option_value_selected=isset($data['multi_option_value'])?(array)json_decode($data['multi_option_value']):false;	
	
	$ingredients_selected=isset($data['ingredients'])?(array)json_decode($data['ingredients']):false;
	
	$two_flavors_position=isset($data['two_flavors_position'])?(array)json_decode($data['two_flavors_position']):false;	
	//dump($two_flavors_position);
	
	$require_addon=isset($data['require_addon'])?(array)json_decode($data['require_addon']):false;		
}
?>                                 


<div class="uk-grid">
    <div class="uk-width-1-2">
    
	<div class="uk-form-row">
	<label class="uk-form-label"><?php echo Yii::t("default","Food Item Name")?></label>
	<?php echo CHtml::textField('item_name',
	isset($data['item_name'])?$data['item_name']:""
	,array(
	'class'=>'uk-form-width-large',
	'data-validation'=>"required"
	))?>
	</div>

	<div class="uk-form-row">
	<label class="uk-form-label"><?php echo Yii::t("default","Description")?></label>
	<?php echo CHtml::textArea('item_description',
	isset($data['item_description'])?$data['item_description']:""
	,array(
	'class'=>'uk-form-width-large big-textarea'	
	))?>
	</div>
	
	
    <div class="uk-form-row">
	  <label class="uk-form-label uk-h3"><?php echo Yii::t("default","Two Flavors")?></label>  
	  <div class="clear"></div>
	  <ul class="uk-list uk-list-striped">
	     <li>
	     <?php
		  echo CHtml::checkBox('two_flavors',
		  $data['two_flavors']==2?true:false
		  ,array(
		    'class'=>"two_flavors",
		    'value'=>2
		  ))
	     ?>
	     <?php echo t("Two Flavors")?>
	     </li>
	  </ul>
	</div>
    	
	<?php 
	Yii::app()->functions->data='list';
	$addon_list=Yii::app()->functions->getAddOnList(Yii::app()->functions->getMerchantID());		
	?>
	<?php if (is_array($addon_list) && count($addon_list)>=1):?>
	<h3 class="uk-h3"><?php echo Yii::t("default","AddOn")?></h3>
	<ul class="uk-list uk-list-striped">
	 <?php foreach ($addon_list as $val):?>
	 <?php $addonid=trim($val['addon_id']);?>
	 <?php 	 
	 if ( !$selected_item_array=getSelectedItemArray($addonid,$multi_option_Selected)){	 	
	 	$selected_item_array[]='one';
	 }	 
	 if ( !$multi_option_value_array=getSelectedItemArray($addonid,$multi_option_value_selected)){	 	
	 	$multi_option_value_array[]="";
	 }	
	 
	 if ( !$selected_flavors_pos=getSelectedItemArray($addonid,$two_flavors_position)){	 	
	 	$selected_flavors_pos[]='';
	 }	 
	 
	 if ( !$selected_require_addon=getSelectedItemArray($addonid,$require_addon)){	 	
	 	$selected_require_addon[]='';
	 }	 	 
	 ?>
	 <li>
	    <div class="uk-grid">
	      <div class="uk-width-1-3">
	      <?php echo ucwords($val['addon_item_name'])?>
	      </div>
	      <div class="uk-width-1-3">
	      <?php echo CHtml::dropDownList("multi_option[$addonid][]",$selected_item_array[0],(array)Yii::app()->functions->multiOptions(),array(
	        'class'=>"multi_option",
	        'data-id'=>$addonid
	      ) )?>
	      </div>
	      <div class="uk-width-1-3">
	      <?php $visible=!empty($multi_option_value_array[0])?"visible":"";?>
	      <?php echo CHtml::textField("multi_option_value[$addonid][]",$multi_option_value_array[0],array(
	        'class'=>"numeric_only multi_option_value $visible"
	      ))?>
	      </div>
	      	      	      
	      <div class="uk-width-1-3">
	       <?php echo CHtml::dropDownList("two_flavors_position[$addonid][]",$selected_flavors_pos[0],array(
	         ''=>"",
	         'left'=>"left",
	         'right'=>"Right"
	       ),array(
	        'class'=>'two_flavors_position',
	        'data-id'=>$addonid
	       ))?>
	      </div>
	    </div>
	 </li>
	 
	   <!--required add on-->	   
	   <li>
	   <?php echo t("Required")."? ";?>
	   <?php echo CHtml::checkBox("require_addon[$addonid][]",
	   in_array(2,$selected_require_addon)?true:false
	   ,array(
	     'class'=>"require_addon",
	     'value'=>2
	   ))?>
	   </li>
	   
	   <?php if (is_array($val['item']) && count($val['item'])>=1):?>
	    <ul class="uk-list uk-list-striped">
	     <?php foreach ($val['item'] as $item_id => $val_item):?>
	     <li>
	      <?php 	      	      	      	     	      
	      $selected_item_array=getSelectedItemArray($addonid,$addon_item);	      	      
	      ?>
	      <?php echo CHtml::checkBox("sub_item_id[$addonid][]",
	      in_array($item_id,(array)$selected_item_array)?true:false
	      ,array('value'=>$item_id))?>
	      <?php echo ucwords($val_item);?>
	     </li>
	     <?php endforeach;?>
	    </ul>
	   <?php endif;?>
	 <?php endforeach;?>
	</ul>
	<?php endif;?>
	
    </div> <!--END uk-width-1-2-->
    
    <div class="uk-width-1-2">
    
	<div class="uk-form-row">
	<label class="uk-form-label"><?php echo Yii::t("default","Status")?></label>
	<?php echo CHtml::dropDownList('status',
	isset($data['status'])?$data['status']:"",
	(array)statusList(),          
	array(
	'class'=>'uk-form-width-medium',
	'data-validation'=>"required"
	))?>
	</div>
	
	
	
<div class="uk-form-row"> 
 <label class="uk-form-label"><?php echo Yii::t('default',"Featured Image")?></label>
  <div style="display:inline-table;margin-left:1px;" class="button uk-button" id="photo"><?php echo Yii::t('default',"Browse")?></div>	  
  <DIV  style="display:none;" class="photo_chart_status" >
	<div id="percent_bar" class="photo_percent_bar"></div>
	<div id="progress_bar" class="photo_progress_bar">
	  <div id="status_bar" class="photo_status_bar"></div>
	</div>
  </DIV>		  
</div>

<?php if (!empty($data['photo'])):?>
<div class="uk-form-row"> 
<?php else :?>
<div class="input_block preview">
<?php endif;?>
<label><?php echo Yii::t('default',"Preview")?></label>
<div class="image_preview">
 <?php if (!empty($data['photo'])):?>
 <input type="hidden" name="photo" value="<?php echo $data['photo'];?>">
 <img class="uk-thumbnail uk-thumbnail-small" src="<?php echo Yii::app()->request->baseUrl."/upload/".$data['photo'];?>?>" alt="" title="">
 <?php endif;?>
</div>
</div>
	
	<?php 	
	Yii::app()->functions->data='list';
	$category_list=Yii::app()->functions->getCategoryList(Yii::app()->functions->getMerchantID());	
	?>
	<div class="uk-form-row">
	  <label class="uk-form-label uk-h3"><?php echo Yii::t("default","Food Category")?></label>  
	  <div class="clear"></div>
	  <?php if (is_array($category_list) && count($category_list)>=1):?>
	  <ul class="uk-list uk-list-striped">
	  <?php foreach ($category_list as $key=>$val):?>
	    <li>
	    <?php echo CHtml::checkBox('category[]',
	    in_array($key,(array)$category)?true:false,array(
	      'value'=>$key,
	      'data-validation'=>"checkbox_group",
	      'data-validation-qty'=>'min1'
	    ))?>
	    <?php echo ucwords($val);?>
	    </li>
	  <?php endforeach;?>
	  </ul>
	  <?php endif;?>
	</div>	
	
	<?php 
	$size_list=Yii::app()->functions->getSizeList(Yii::app()->functions->getMerchantID());	
	?>
	<?php if (is_array($size_list) && count($size_list)>=1):?>
	<ul class="uk-list uk-list-striped price_wrap_parent">
	<li>
	  <div class="uk-grid">
	    <div class="uk-width-1-2"><?php echo Yii::t("default","Size")?></div>
	    <div class="uk-width-1-2"><?php echo Yii::t("default","Price")?></div>
	  </div>
	</li>	
	
	<?php if ( is_array($price) && count($price)>=1):?>
	    <?php $x=1;?>
		<?php foreach ($price as $price_key=>$val_price):?>			
		<li class="<?php echo $x==count($price)?"price_wrap":"";?>">
		  <div class="uk-grid">
		     <div class="uk-width-1-3">
		    <?php echo CHtml::dropDownList('size[]',$price_key,$size_list,array('class'=>"uk-form-width-medium"))?>
		     </div>
		     <div class="uk-width-1-3">
		      <?php echo CHtml::textField('price[]',$val_price,
		      array('class'=>'uk-form-width-medium numeric_only'))?>
		    </div>
		    <div class="uk-width-1-3">
		    <a href="javascript:;" class="removeprice"><i class="fa fa-minus-square"></i></a>
		    </div>
		  </div>
	    </li>
		<?php $x++;?>
		<?php endforeach;?>
	<?php else :?>
	<li class="price_wrap">
	  <div class="uk-grid">
	     <div class="uk-width-1-3">
	    <?php echo CHtml::dropDownList('size[]','',$size_list,array('class'=>"uk-form-width-medium"))?>
	     </div>
	     <div class="uk-width-1-3">
	      <?php echo CHtml::textField('price[]','',
	      array('class'=>'uk-form-width-medium numeric_only'))?>
	    </div>
	    <div class="uk-width-1-3">
	    <a href="javascript:;" class="removeprice"><i class="fa fa-minus-square"></i></a>
	    </div>
	  </div>
    </li>
    <?php endif;?>
    
    <li>
      <a href="javascript:;" class="addnewprice"><i class="fa fa-plus-circle"></i></a>
    </li>
   
	</ul>
	<?php else :?>
	<p class="uk-text-danger"><?php echo Yii::t("default","Please add different size in order to add price.")?></p>
	<?php endif;?>
	
	<div class="uk-form-row">
	<label class="uk-form-label"><?php echo Yii::t("default","Discount (numeric value)")?></label>
	<?php echo CHtml::textField('discount',
	isset($data['discount'])?$data['discount']:""
	,array(
	'class'=>'uk-form-width-medium numeric_only'	
	))?>
	</div>
		
	<?php 
	$cooking_ref=Yii::app()->functions->getCookingRefList(Yii::app()->functions->getMerchantID());	
	?>
	<div class="uk-form-row">
	  <label class="uk-form-label uk-h3"><?php echo Yii::t("default","Cooking Reference")?></label>  
	  <div class="clear"></div>
	  <?php if (is_array($cooking_ref) && count($cooking_ref)>=1):?>
	  <ul class="uk-list uk-list-striped">
	  <?php foreach ($cooking_ref as $key=>$val):?>
	    <li>
	    <?php echo CHtml::checkBox('cooking_ref[]',
	    in_array($key,(array)$cooking_ref_selected)?true:false,array(
	      'value'=>$key
	    ))?>
	    <?php echo ucwords($val);?>
	    </li>
	  <?php endforeach;?>
	  </ul>
	  <?php endif;?>
	</div>	
	

    <?php 
	$ingredients=Yii::app()->functions->getIngredientsList(Yii::app()->functions->getMerchantID());	
	?>
	<?php if (is_array($ingredients) && count($ingredients)>=1):?>
	<div class="uk-form-row">
	  <label class="uk-form-label uk-h3"><?php echo Yii::t("default","Ingredients")?></label>  
	  <div class="clear"></div>
	  <?php if (is_array($ingredients) && count($ingredients)>=1):?>
	  <ul class="uk-list uk-list-striped">
	  <?php foreach ($ingredients as $key=>$val):?>
	    <li>
	    <?php echo CHtml::checkBox('ingredients[]',
	    in_array($key,(array)$ingredients_selected)?true:false,array(
	      'value'=>$key
	    ))?>
	    <?php echo ucwords($val);?>
	    </li>
	  <?php endforeach;?>
	  </ul>
	  <?php endif;?>
	</div>		
	<?php endif;?>
	
	
	<div class="uk-form-row">
	  <label class="uk-form-label uk-h3"><?php echo Yii::t("default","Spicy Dish")?></label>  
	  <div class="clear"></div>
	  <ul class="uk-list uk-list-striped">
	  <li><?php echo CHtml::checkBox('spicydish',
	  $data['spicydish']==2?true:false
	  ,array(
	   'class'=>"icheck",
	   'value'=>2
	  ))?>
	  <?php echo t("Spicy Dish")?>
	  </li>
	  </ul>
	</div> <!--end form uk-->
	
	
    </div><!-- END uk-width-1-2-->
</div> <!--END uk-grid-->

<div class="spacer"></div>


<div class="uk-form-row">
<label class="uk-form-label"></label>
<input type="submit" value="<?php echo Yii::t("default","Save")?>" class="uk-button uk-form-width-medium uk-button-success">
</div>

</form>