<?php include "../../includes/start_ajax.php";?>
<?php include "config_form.php"; ?>

<?php


//------------------data display----------------------
echo "<div class='data_display_content'>";	
	
	
$query_display="SELECT * FROM $form_table_name ";
$query_display=$query_display." WHERE $form_key_id = '".$_REQUEST[$form_key_id]."';";
$result_display=mysqli_query($dbconn,$query_display)or die("Get Data failed- Err msg  ". mysqli_error($dbconn));
			
if($line_display=mysqli_fetch_array($result_display,MYSQLI_ASSOC))
{
	  	
	for($i=1;$i<=count($form_field);$i++)
	{
		
	
	
		if($form_field_separator[$i]!="")
		{
			echo "<div class='data_display_separator' >";
			echo "<font size=3><b>".$form_field_separator[$i]."</b></font>";
			echo "</div>";
		}

		
		
		
		
		echo "<div class='data_display_row'>";
		
			
			echo "<div class='data_display_label'>";
				echo $form_field_label[$i];
			echo "</div>";
		
			echo "<div class='data_display_value'>";
		
				if($form_field_type[$i]=="TEXT")
				{
					echo $line_display[$form_field[$i]]."";
				}
			
				if($form_field_type[$i]=="QUANTITY")
				{
					echo $line_display[$form_field[$i]]."";
				}
			
				if($form_field_type[$i]=="PRICE")
				{
					echo $line_display[$form_field[$i]]."";
				}
				
				if($form_field_type[$i]=="TIME")
				{
					echo $line_display[$form_field[$i]]."";
				}
				
				if($form_field_type[$i]=="DATE")
				{
					echo $line_display[$form_field[$i]]."";
				}
				
				if($form_field_type[$i]=="DATE_START")
				{
					echo $line_display[$form_field[$i]]."";
				}
				
				if($form_field_type[$i]=="DATE_END")
				{
					echo $line_display[$form_field[$i]]."";
				}
				
				if($form_field_type[$i]=="PASSWORD")
				{
					echo "******";
				}
					
				if($form_field_type[$i]=="TEXTAREA")
				{
					echo str_replace(chr(10),"<br>",$line_display[$form_field[$i]])."";
				}
				
				if($form_field_type[$i]=="DROPDOWN")
				{
				
					if($form_field_dropdown_option[$i]=="KEYWORD")
					{
					 
						echo "".$mon_keyword_list[$form_field_dropdown_option_values[$i]][$line_display[$form_field[$i]]]."";
					 
					
						
					}
					if($form_field_dropdown_option[$i]=="SQL")
					{
					 
						$query_select=$form_field_dropdown_option_values[$i];
						$query_select=$query_select." where ".$form_field_dropdown_option_values_key[$i]."='".$line_display[$form_field[$i]]."';";
						$result_select=mysqli_query($dbconn,$query_select) or die("Retrieval failed- Err msg  ". mysqli_error($dbconn));
						if($line_select=mysqli_fetch_array($result_select,MYSQLI_ASSOC))
						{
							echo "".$line_select["text"].""; 
						}
														
					}
				
				
				
				
					}
					
					if($form_field_type[$i]=="FILE_PHOTO")
					{
						$query_file="select fil_id, fil_storage_method from t_".$key_table_prefix."_file 
							where fil_mod='".$form_key_id."' 
							and fil_mod_id='".$_REQUEST[$form_key_id]."'
							and fil_mod_field='".$form_field[$i]."'
							";
			
						$result_file=mysqli_query($dbconn,$query_file) or die("Retrieval failed- Err msg  ". mysqli_error($dbconn));
						if($line_file=mysqli_fetch_array($result_file,MYSQLI_ASSOC))
						{
							if($line_file["fil_storage_method"]=="OS")
							{
								echo "<img width=250 src='".$file_storage_folder.$line_file["fil_id"].".jpg' >";	
							}
							else
							{
								echo "<img width=250 src='mod/uploader/file.php?id=".$line_file["fil_id"]."' >";	
							}
							
						} 
					}
					
					if($form_field_type[$i]=="FILE")
					{
						$query_file="select fil_name, fil_id, fil_storage_method from t_".$key_table_prefix."_file 
										where fil_mod='".$form_key_id."' 
										and fil_mod_id='".$_REQUEST[$form_key_id]."'
										and fil_mod_field='".$form_field[$i]."'
										";
						
						$result_file=mysqli_query($dbconn,$query_file) or die("Retrieval failed- Err msg  ". mysqli_error($dbconn));
						if($line_file=mysqli_fetch_array($result_file,MYSQLI_ASSOC))
						{
							$fileName_array=explode(".",$line_file["fil_name"]);
							$ext=$fileName_array[count($fileName_array)-1];
							if($line_file["fil_storage_method"]=="OS")
							{
								echo "<a href='".$file_storage_folder.$line_file["fil_id"].".".$ext."' target=_blank >".$line_file["fil_name"]."</a>";	
							}
							else
							{
								echo "<a href='mod/fuploader/file.php?id=".$line_file["fil_id"]."' >".$line_file["fil_name"]."</a>";	
							}
						} 
					}
		
				echo "</div>"; // end value division
				
				
				
		echo "</div>"; //end row division
	 
	}
	
	
	
	
	//========================================================================================================================
	echo "<div class='data_display_separator' >";
	echo "<font size=3><b>Payment Document</b></font>";
	echo "</div>";
	
		
		
		
		
	  //===Header Label =============
	  $listing_header[1]="Document No.";
	  $listing_header[2]="Amount Paid";
	  
	    
	  //===Database Fields==========
	  $listing_content[1]="coi_pay_doc_no";
	  $listing_content[2]="coi_pay_doc_amount";
	 
	 
	  
	  //===Column width==========
	  $listing_width[1]="200";
	  $listing_width[2]="200";
	  
	  
	  
	  
	  
		//===Column align==========
	  $listing_align[1]="left";
	  $listing_align[2]="right";
	  
	  
	  
	echo "<div class='view_list_title_row'>";
	
	
			echo "<div class='view_list_title_content'>";
				echo "<div style='min-width:20px;' class='view_list_title_row_count'  >";
					echo "#";
				echo "</div>";
				
				
				for($i=1;$i<=count($listing_header);$i++)
				{
					if($listing_content[$i]=="modified_date")
					{
						
					}
					else
					{
						echo "<div style='width:".$listing_width[$i]."px;text-align:".$listing_align[$i].";' class='view_list_title_content_object'  >";
							echo "".$listing_header[$i]."<br>";
						echo "</div>";
					}
					
				}
				
			echo "</div>";
	echo "</div>";
			
			
	
	$count=1;
	$query_coi = "select * 
				from t_".$key_table_prefix."_collection_item
				where coi_doc_no ='".$line_display["coh_doc_no"]."' 
				and device_id  ='".$line_display["device_id"]."' ";
	$result_coi = mysqli_query($dbconn,$query_coi);
	
	while($line_coi = mysqli_fetch_array($result_coi,MYSQLI_ASSOC))
	{
		
		echo "<div class='view_row'>";
		
		
			echo "<div style='min-width:20px;' class='view_row_count'  >";
			echo "".$count."";
			echo "</div>";
		
			for($i=1;$i<=count($listing_header);$i++)
			{
				
				echo "<div style='width:".$listing_width[$i]."px;text-align:".$listing_align[$i].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$listing_header[$i]."</font>";
				
				
					echo "<font class='view_row_content_text'>";
						$this_text=$line_coi[$listing_content[$i]];
						$this_text=str_replace(chr(10),"<br>",$this_text);
						$this_text = str_replace($search_word, "<span class='view_search_hightlight' >".$search_word."</span>", $this_text);
						echo "".$this_text."";
					echo "</font><br>";
				
				echo "</div>";
			
			}
		
		
		
		echo "</div>";
	
		$count++;
	}
		
		
						
}	
		
	
echo "</div>";
			echo "<div style='float:left;height:200px;'></div>";

?>




<?php include "../../includes/end_ajax.php";?>