<div hidden>
	  <?php
        $fileField = 'pro_type_images';
        $title_text = 'Upload PDF';
        $types = '.png,.jpg,.jpeg';
        $maxFiles = '1';
        $maxFilesize = '100';
        $this->renderPartial('root.apps.frontend.views.place_an_ad._file_field_browse_single_new',compact('form','fileField','maxFilesize','types','maxFiles','model','title_text'));
	    ?>
	    </div>
		  <script>
		      
		      function uploadimg(k){
		          $('.upload_img').removeClass('active-c');
		      $(k).closest('.upload_img').addClass('active-c');
		       
		       $('#file_<?php echo $fileField;?>').click(); $('.active-c').find('.ldr').html('uploading....');
		      }
		  </script>
<div class="row form-group browse_type ">
	<style>
	.ldr{ display:none;}.active-c 	.ldr{ display:block;}
	#place_an_ad_create span.priceLbl, #place_an_ad_update span.priceLbl{display: inline-block;float: left;width: 40px;line-height: 28px;padding: 0px 5px;background: #fff;border-top: 1px solid #002f34;border-left: 1px solid #002f34;border-bottom: 1px solid #002f34;}
	#place_an_ad_preview_development span.priceLbl { display: inline-block;float: left;width: auto;line-height: 1.5;margin-right: 3px;}
	#place_an_ad_preview_development  .splinp.req { display: none;}
	#place_an_ad_preview_development  .spanuni.req { display: none;}
	input.splinp { float: left !important;min-width: initial !important;max-width: calc(100% - 40px) !important; }
	.col-lg-6 .col-sm-8 { float:left;}
	.col-lg-6 .col-sm-4 { float:left;}
	.no-padding-right{ padding-right:0px; }
	</style>
	<div class="col-sm-12">
 
<h3 class="subheading_font">Property Types</h3>
  <?php echo $form->error($model, 'add_property_types');?>
<table class="table   table-striped" id="proptype">
 
    <tbody>
      <?php
 
$fileField ='add_property_types';
$values = CHtml::listData(Category::model()->ListDataForJSON_ID_ByCountryNewDevelopment($model->country),'category_id','category_name');
$bed_values =  $model->bedrooms();
$bath_values =  $model->bathrooms();
$unit_values = array();
$price_values = array();
$html_option = '<option value="" >Select Property Type</option>';
$html_option_bed = '<option value="" >Select Beds</option>';
$html_option_bath = '<option value="" >Select Baths</option>';
$html_option_unit = '<option value="" >Select Unit</option>';
$html_option_price = '<option value="" >--</option>';
if($values ){ foreach($values as $k2=>$v2){ $html_option .= '<option value="'.$k2.'" >'.$v2.'</option>'; 	} }
if($bed_values ){ foreach($bed_values as $k2=>$v2){ $html_option_bed .= '<option value="'.$k2.'" >'.$v2.'</option>'; 	} }
if($bath_values ){ foreach($bath_values as $k2=>$v2){ $html_option_bath .= '<option value="'.$k2.'" >'.$v2.'</option>'; 	} }
if($unit_values ){ foreach($unit_values as $k2=>$v2){ $html_option_unit .= '<option value="'.$k2.'" >'.$v2.'</option>'; 	} }
if($price_values ){ foreach($price_values as $k2=>$v2){ $html_option_price .= '<option value="'.$k2.'" >'.$v2.'</option>'; 	} }
 
$dropDown = '<select name="add_property_types[type_id][]" class="form-control req">[PROPERTY_TYPE]</select>';
$dropDown_bed = '<select name="add_property_types[bed][]" class="form-control">[BED]</select>';
$dropDown_bath = '<select name="add_property_types[bath][]" class="form-control">[BATH]</select>';
$dropDown_unit = '';
$dropDown_price = '';

      $thnl = '<tr class="textFields {i_class}"  >';
      $thnl .= '<td>';
       $thnl .= '<div class=""><div class="col-lg-6"><label class="no-ma-top">Property Type <span class="required">*</span></label>'.$dropDown.'</div><div class="col-lg-6"><label class="no-ma-top">Property Title <span class="required">*</span></label><input type="text" name="add_property_types[title][]"  value="{value_title}" class="form-control req"></div> </div> ' ;
      $thnl .= '<div></div><div class=""> <div class="col-lg-6"><div class="row">  <div class="col-sm-12"><label>Area/Size (SQFT) <span class="required">*</span></label><span class="hspanuni"></span><input type="text" class="form-control col-sm-12 nemeric spanuni req"  placeholder="Size *" pattern="[0-9.,]+" name="add_property_types[size][]" value="{value_size}" maxlength="10" /></div>  </div> </div>';
      $thnl .= '<div class="col-lg-6"><div class=" " ><label>Price <span class="required">*</span></label><span class="priceLbl">AED</span><span class="hsplinp"></span><input type="text" class="form-control col-sm-12 nemeric splinp req"  placeholder="Price *" pattern="[0-9.,]+"  name="add_property_types[from_price][]"   value="{value_from_price}"   maxlength="10" /> </div> </div> </div> ';
         $thnl .= '<div></div><div class=" "><div class="col-lg-6"><label class="">Beds</label>'.$dropDown_bed .'</div><div class="col-lg-6 hidden"><label class="">Baths</label>'.$dropDown_bath .'</div></div>';
     $thnl .= '<div class="clearfix"></div><div ><div style="height:10px;">&nbsp;</div><textarea class="form-control col-sm-12  " maxlength="250" placeholder="Description"  name="add_property_types[description][]"        >{value_description}</textarea></div>';
      $thnl .= '<div class="clearfix"></div><div style="height:10px;">&nbsp;</div><div class="upload_img"><div class="ldr"></div><div class="img1-div">{img}</div><input type="hidden" class="form-control col-sm-12  "  placeholder="Image"  name="add_property_types[image][]"  value="{value_image}"      > <a href="javascript:void(0)" onclick="uploadimg(this)">Upload/Change Image</a></div>';
    
      $thnl .= '</td><td width="100px" class="opt"><a href="javascript:void(0)" class="text-center blk"  onclick="removeAppendRow(this)"><i class="fa fa-remove"></i></a></td></tr>';
     $post = array();
     
     
      if(!Yii::app()->request->isPostRequest and !is_array($model->$fileField)){
				 
					$pTypes =  $model->pTypes ;
					if(!empty($pTypes )){
					foreach($pTypes as $pos){
						$post['type_id'][] =  $pos->type_id;
						$post['bed'][] =  $pos->bed;
						$post['bath'][] =  $pos->bath;
						$post['title'][] =  $pos->title;
						$post['size'][] =  $pos->size;
						$post['area_unit'][] =  $pos->area_unit;
						//$post['size_to'][] =  $pos->size_to;
						$post['from_price'][] =  $pos->from_price;
						$post['price_unit'][] =  $pos->price_unit;
							$post['description'][] =  $pos->description;
							$post['image'][] =  $pos->image;
						//$post['to_price'][] =  $pos->to_price;
					}
					}
					
					
					}
					else if(is_array($model->$fileField)){
					 
						$post = $model->$fileField;
						$model->$fileField =''; 
					}
					
					else{
					$post =  Yii::App()->request->getPost('add_property_types',array());
		}
		
      if(!empty($post)){ 
		 
		for($i= 0 ; $i< sizeOf($post['title']);$i++){
			$i_class = '';
				if(empty( $post['type_id'][$i]) || empty( $post['title'][$i]) ||  empty($post['area_unit'][$i])  ||  empty($post['size'][$i])   || empty($post['area_unit'][$i])   ||  empty($post['from_price'][$i]))
						{
							$i_class = 'error';
						
					}
					
					$html_option1 = '<option value="" >Select Property Type</option>';
					$html_option_bed1 = '<option value="" >Select Beds</option>';
					$html_option_bath1 = '<option value="" >Select Baths</option>';
					$html_option_unit1 = '<option value="" >Select Unit</option>';
					$html_option_price1 = '<option value="" >--</option>';
					$img_html = ''; 
					if($values ){ foreach($values as $k2=>$v2){  if($k2==$post['type_id'][$i]){ $selected='selected="true"'; }else{$selected='';  } $html_option1 .= '<option value="'.$k2.'" '.$selected.'>'.$v2.'</option>'; 	} }
					if($bed_values ){ foreach($bed_values as $k2=>$v2){ if($k2==$post['bed'][$i]){ $selected='selected="true"'; }else{$selected='';  } $html_option_bed1 .= '<option value="'.$k2.'"  '.$selected.' >'.$v2.'</option>'; 	} }
					if($bath_values ){ foreach($bath_values as $k2=>$v2){ if($k2==$post['bath'][$i]){ $selected='selected="true"'; }else{$selected='';  }  $html_option_bath1 .= '<option value="'.$k2.'"  '.$selected.' >'.$v2.'</option>'; 	} }
					if($unit_values ){ foreach($unit_values as $k2=>$v2){ if($k2==$post['area_unit'][$i]){ $selected='selected="true"'; }else{$selected='';  }  $html_option_unit1 .= '<option value="'.$k2.'"  '.$selected.' >'.$v2.'</option>'; 	} }
					if($price_values ){ foreach($price_values as $k2=>$v2){ if($k2==$post['price_unit'][$i]){ $selected='selected="true"'; }else{$selected='';  }  $html_option_price1 .= '<option value="'.$k2.'"  '.$selected.' >'.$v2.'</option>'; 	} }
                    if(isset($post['image'][$i]) and !empty($post['image'][$i])){
                        	$img_html = '<img src="'.Yii::app()->apps->getBaseUrl('uploads/images/'.$post['image'][$i]).'" style="width:50px;height:50px;object-fit: cover;height: 100%;">'; 
                    }
			
			echo  Yii::t('app',$thnl,array('{i_class}'=>$i_class , '[PUNIT]' => $html_option_price1 , '[UNIT]' => $html_option_unit1 , '[PROPERTY_TYPE]' => $html_option1 , '[BED]'=> $html_option_bed1 ,  '[BATH]'=> $html_option_bath1 ,'{value_description}'=> $post['description'][$i],'{img}'=>$img_html, '{value_image}'=> $post['image'][$i],  '{value_title}'=> $post['title'][$i],'{value_size}'=> $post['size'][$i],'{value_size_to}'=> @$post['size_to'][$i],'{value_from_price}'=> $post['from_price'][$i],'{value_to_price}'=> @$post['to_price'][$i]));
		};  
	  }
	  
	  ?>
      <tr id="append_row" style="background:#fff !important"><th colspan="100%" style="background:#fff !important ; padding-left:0px;" class="upload-btn-wrapper normal"><a href="javascript:void(0)" onclick="appendRowr(this)" style="height:auto;" class="btn   btn-info"><i class="fa fa-plus"></i> Add Property Types</a></th></tr>
	    
    </tbody>
  </table>
        <?php 
 
        echo $form->hiddenField($model, 'add_property_types'); ?>
      
              
<script>
	var appendRowObj =  '<?php echo  Yii::t('app',$thnl,array('{value_title}'=>'' ,'[PUNIT]'=>$html_option_price,'[UNIT]'=>$html_option_unit,'[BED]'=>$html_option_bed , '[BATH]'=>$html_option_bath ,  '[PROPERTY_TYPE]' =>$html_option,'{value_description}'=>'', '{value_image}'=>'','{img}'=>'', '{value_size}'=>'' ,'{value_size_to}'=> '' ,'{value_from_price}'=>'' ,'{value_to_price}'=> '','\n'=>'','\s'=>''  ));;?>';
function appendRowr(k){
	$('#append_row').before(  appendRowObj );
	inputValidate()
}
function removeAppendRow(k){
 
	$(k).parent().parent().remove();
}
 
	function inputValidate(){
$('input.nemeric').on('change, keyup', function validateInpu() {
    var currentInput = $(this).val();
    var fixedInput = currentInput.replace(/[A-Za-z!@#$%^&*()]/g, '');
    $(this).val(fixedInput);
    console.log(fixedInput);
});
}
 
</script>
<style>.form-control.col-sm-6{ width:50% !important; } .textFields.error{ background: #F9E0EF; } </style>
</div>
<div class="clearfix"></div>
</div>
