<?php




//////////////////////////// HTML FUNCTION ENDS (c) i2d Technologies ///////////////////////////////////////
if (!function_exists('make_search')) {
function make_search($values) {
if (array_key_exists('texts', $values)) {
   $text=$values['texts'];
   }
if (array_key_exists('dropdowns', $values)) {
   $dropdown=$values['dropdowns'];
   }
if (array_key_exists('dropdowns2', $values)) {
   $dropdown2=$values['dropdowns2'];
   }
if (array_key_exists('checkboxes', $values)) {
   $checkboxes=$values['checkboxes'];
   }

   if (array_key_exists('directfields', $values)) {
   $directfields=$values['directfields'];
   }

if (array_key_exists('dates', $values)) {
   $dates=$values['dates'];
   }
if (array_key_exists('alias', $values)) {
   $alias=$values['alias'];
   }
   if (array_key_exists('redirect', $values)) {
   $redirect=$values['redirect'];
   }
if (array_key_exists('redirect_adv', $values)) {
   $redirect2=$values['redirect_adv'];
   }
if (array_key_exists('form_heading', $values)) {
   $form_heading=$values['form_heading'];
   }
if (array_key_exists('form_table', $values)) {
   $form_table=$values['form_table'];
   }
if (array_key_exists('search_type', $values)) {
   $search_type=$values['search_type'];
   }
?>



<script type="text/javascript">
$(document).ready(function() {
  $(window).keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }
  });
});
</script>



<script type="text/javascript">
 $(document).ready(function() {
$("#subbtn").click(function(){
//$("#subbtn").text("Please Wait...");

	  });
	  
  });
  </script>

 <div id="page-right-content">

                    <div class="container">
                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="header-title m-t-0 m-b-20"><?php echo "Add New ".$form_heading; ?></h4>

<?php 
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
?>
	  </div>
                        </div> <!-- end row -->


                        <div class="row">
               <div class="col-12">



<form role="form" enctype="multipart/form-data" method="post">
<div class="p-20 m-b-20">
<div class="row">


</div>
<?php if(isset($search_type)){ ?>
<div class="row">
<?php
////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////
if(isset($dates) && !empty($dates)){
foreach ($dates as $dates1 => $datesval){
$datesarray1[] = $dates[$dates1]['fname'];

$date_setup=array(
'label'=>$dates[$dates1]['label'],
'fname'=>$dates[$dates1]['fname'],
'date'=>$dates[$dates1]['date'],
);

dater3($date_setup);
}
}
?>
</div>
<div class="row">
<p>&nbsp;</p>
<?php
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
if(isset($search_type) && $search_type=="expense_head"){ 
////////////////////////////////////////////////////////////////////////////////////////////////////////
if(isset($dropdown) && !empty($dropdown)){
foreach ($dropdown as $droploop => $valloop){
	
if(isset($edit) && $edit!="0"){	

$this_field1=db_ref($form_table,id_col,$lead_id,$dropdown[$droploop]['this_table_field']);

//helloworld($this_field1);

$db_settings3=array(
'table'=>$dropdown[$droploop]['table'],
'id'=>$this_field1,
'type'=>'0',
'to_find'=>$dropdown[$droploop]['remote_tbl_title_col']);


$drop3=db_fetch($db_settings3);

}
?>
<?php
if(isset($edit) && $edit!="0"){
$editing=array(
'editing'=>'1',
'selected_id'=>$this_field1,
'selected_text'=>$drop3);
}
else{
$editing=array(
'editing'=>'1');	
}
dynamicdrop_adv($dropdown[$droploop]['label'],$dropdown[$droploop]['encoding'],$editing,$dropdown[$droploop]['ref'],$dropdown[$droploop]['table'],$dropdown[$droploop]['table_title'],$dropdown[$droploop]['table_id_col'],$dropdown[$droploop]['add_new'],$dropdown[$droploop]['other_id_col']);
?> 
<?php
if(isset($_POST['add_item'])){
$dropfound=$dropdown[$droploop]['ref']."_dropname";
$dropfound2=$_POST[$dropfound];
$droparray[$dropdown[$droploop]['this_table_field']] = $dropfound2;
}


}
}
/////////////////////////////////////////////////////////
}
?>
</div>
<!------i2d Technologies v3.0 ----     ---------------->

<?php } ?>
<?php
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
if(isset($search_type) && $search_type=="expense_head"){ 
////////////////////////////////////////////
if(isset($dropdown2) && !empty($dropdown2)){
foreach ($dropdown2 as $droploop2 => $valloop2){
	
if(isset($edit) && $edit!="0"){

$this_field2=db_ref($dropdown2[$droploop2]['prim_table'],id_col,$lead_id,$dropdown2[$droploop2]['this_table_field']);

	
$db_settings32=array(
'table'=>$dropdown2[$droploop2]['sub_table'],
'id'=>$this_field2,
'type'=>'0',
'to_find'=>$dropdown2[$droploop2]['remote_tbl_title_col']);

$drop32=db_fetch($db_settings32);

//helloworld($drop32);

$this_field2b=db_ref($dropdown2[$droploop2]['prim_table'],id_col,$lead_id,$dropdown2[$droploop2]['this_table_field2']);

$db_settings42=array(
'table'=>$dropdown2[$droploop2]['sub_table'],
'id'=>$this_field2b,
'type'=>'0',
'to_find'=>$dropdown2[$droploop2]['remote_tbl_title_col']);

$drop42=db_fetch($db_settings42);

////////////////////////////////////////////


}
?>
<?php
if(isset($edit) && $edit!="0"){
$editing2=array(
'editing'=>'1',
'selected_id'=>$this_field2,
'selected_text'=>$drop32,
'selected_id2'=>$this_field2b,
'selected_text2'=>$drop42
);
}
else{
$editing2=array(
'editing'=>'0');	
}
dynamicdrop_adv_multi($dropdown2[$droploop2]['label'],$dropdown2[$droploop2]['encoding'],$editing2,$dropdown2[$droploop2]['ref'],$dropdown2[$droploop2]['ref2'],$dropdown2[$droploop2]['prim_table'],$dropdown2[$droploop2]['sub_table'],$dropdown2[$droploop2]['table_title'],$dropdown2[$droploop2]['table_id_col'],$dropdown2[$droploop2]['table_parent_col'],$dropdown2[$droploop2]['parent_add'],$dropdown2[$droploop2]['child_add'],$dropdown2[$droploop2]['label2']);
?> 
<?php
if(isset($_POST['add_item'])){
$dropfound22=$dropdown2[$droploop2]['ref']."_multi_dropname";
$dropfound222=$_POST[$dropfound22];
$droparray2[$dropdown2[$droploop2]['this_table_field']] = $dropfound222;

$dropfound22_sub=$dropdown2[$droploop2]['ref2']."_multi_dropname";
$dropfound222_sub=$_POST[$dropfound22_sub];
$droparray2_sub[$dropdown2[$droploop2]['this_table_field2']] = $dropfound222_sub;



}


}
}
////////////////////////////////////////
}
?>

<!------i2d Technologies v3.0 ----     ---------------->
<!------i2d Technologies v3.0 ----     ---------------->
<div class="row">
<?php
if(isset($text) && !empty($text)){
$parameters=array(
'text'=>$text,
'form_name'=>'fname',
'form_submit_id'=>'add_item',
'table'=>$etable,
'table_ref'=>$e_ref,
'edit'=>$edit,
'id'=>$lead_id
);

$text_fields=form_control($parameters);
}
?>
</div>
<div class="row">
<?php
////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
if(isset($checkboxes) && !empty($checkboxes)){
$parametersch=array(
'text'=>$checkboxes,
'form_name'=>'fname',
'form_submit_id'=>'add_item',
'edit'=>$edit,
'id'=>$lead_id
);
$checkbox_fields=form_check_box($parametersch);
}
?>
</div>

<div class="row">
<p>&nbsp;</p>
<div class="col-md-12 text-center gap-items-5">
                                                    <button type="reset" class="btn btn-lg btn-danger waves-effect m-l-5"
													onclick="history.go(-1);">
                                                        Cancel<label><i class="fa fa-tick"></i></label>
                                                    </button>
													<button type="submit" name="add_itembtn" id="subbtn" 
													class="btn btn-lg btn-primary waves-effect waves-light">
                                                        Start Search<label><i class="fa fa-tick"></i></label>
                                                    </button>

                                                    <input type="hidden" name="add_item" value="add_item">
                    <hr class="d-lg-none">
                    
                                                </div>


			
				  </div>
				  
				  
				  
				  
				  
				  
				  
				  
				  
				  </div>
				  <input type='submit' style="display: none;">
				  </form>
				  
				  
				  
				  
				  
				  </div>
				  </div>
				  
				  

				  <?php
///////////////////////////////////////////////////////////////////
if(isset($_POST['add_item'])){
	
	
if(isset($text_fields) && !empty($text_fields)){	
$text1=$text_fields['fields'];
$text2=$text_fields['posts'];
$text3=array_combine($text1, $text2);
}
if(isset($dates)  && !empty($dates)){
foreach ($dates as $dates1 => $datesval){
$datefound=$dates[$dates1]['fname'];
$datefound2=$_POST[$datefound];
$datefoundnewdate = strtotime($datefound2);
$datefoundnewdate = date("Y-m-d", $datefoundnewdate);
$datesarray2[] = $datefoundnewdate ;
}
$dates3=array_combine($datesarray1, $datesarray2);
}


$extra=array(status=>'Active',ref=>$alias);

$array_one=$extra;	


if(isset($directfields) && !empty($directfields)) {
foreach ($directfields as $d1 => $dvalue){
$direct1[] = $directfields[$d1]['fname'];
$direct2[] = $directfields[$d1]['value'];
}
	
$direct3=array_combine($direct1, $direct2);

}


$date_range=$_POST['dated'];

$date_split=explode("-",$date_range);    


//$date_split1=substr($date_range1, strpos($date_range1, "-") - 1);    
//$date_split2=substr($date_range2, strpos($date_range2, "-") + 1);    

//echo $date_split[0]."<br />".$date_split[1]; 


///////////////// this to be done at search end ////////////////


$date1=$date_split[0];
$date2=$date_split[1];

$date1=str_replace("/", "_", $date1);
$date2=str_replace("/", "_", $date2);

$date1=trim($date1);;
$date2=trim($date2);;


$account_id=$_POST['v_ac_type_dropname'];
$sub_account_id=$_POST['sub_type_multi_dropname'];

//helloworld($account_id);
//helloworld($sub_account_id);



//var_dump($_POST);

if(isset($redirect) && !empty($redirect)){
#app_redirect_adv($redirect);
echo "Inserted / updated ! ";
}
else{
echo "error";	
//$redirect2=$redirect2."/";
$link_date1="/net/list/dated/".$date1."/".$date2."/".$account_id."/".$sub_account_id;
//$link_date2="/net/print/dated/165/".$date1."/".$date2;
app_redirect_adv($link_date1);	
//app_redirect_adv($link_date2);	
}


}




?>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
<?php
    
} 
}
/////////////////////////// function ends /////////////////////////////////



























?>















