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

<?php
//important================================
include "config_form.php"; //important
//important================================
//important================================
include "config_view.php";
//important================================	



echo "<section class='view_toolbar'>";
    echo "<div class='view_toolbar_left' style='width:60%;'>";
		echo "<font size=5 ><span class='fa fa-plus-square fa-1x'></span> <b>Product - Addon Matrix</b></font>";

		echo "<br>";
	    
    echo "</div>";
    echo "<div class='view_toolbar_right'>";
	    
	  
	    
		    /*
		    echo "<div class='fa-stack fa-lg'  style='cursor:pointer;float:right;'  onclick=\"mon_refresh_tab(mon_current_selected_tab);\" >";
			    echo "<i class='fa fa-square fa-stack-2x color_red'   ></i><i class='fa fa-refresh fa-stack-1x color_white' ></i>";
		    echo "</div>";
			 */   
   
    echo "</div>";
echo "</section>";






echo "<form name='addon_matrix' style='float:left;width:100%;' >";

  echo "<section class='view_toolbar'>";
                    echo "<div class='view_toolbar_left' style='width:50%;'>";
						//echo "<span class='fa fa-plus-square'></span> Product-Addon Matrix ";
                    echo "</div>";
                    echo "<div class='view_toolbar_right' style='text-align:left;'>";	
    					
				//================================================================
			  echo "".$matrix_title.": <select name='".$matrix_key_id."' class='dropdown dropdown-l'  onchange=\"mon_send_get('".$this_url."','?".$matrix_key_id."='+this.value,'div_main')\" >";
		 
					echo "<option value='' >";
					    echo "--Select--";
					echo "</option>";
				 
					$query_data = "select * from ".$matrix_key_table."
							   ";
							   //where client_id = '".$CurrentUserID."'
							    
					$result_data = mysqli_query($dbconn,$query_data);
					while($line_data = mysqli_fetch_array($result_data,MYSQLI_ASSOC))
					{
					    
					    if($line_data[$matrix_key_id]==$_REQUEST[$matrix_key_id])
					    {
						   echo "<option value='".$line_data[$matrix_key_id]."' selected >";
					    }
					    else
					    {
						   echo "<option value='".$line_data[$matrix_key_id]."' >";
					    }
					    
					    
					    
						   echo $line_data[$matrix_key_code];
						   echo " - ";
						   echo $line_data[$matrix_key_name];
					    echo "</option>";    
					}
		 
			  echo "</select>";
			  
                            //================================================================
            
                    echo "</div>";
    echo "</section>";
    
    
    

     
?>





<?php
//==================================GET THE LISTING=======================================================


	if ($_REQUEST["offset"]=="")
		{ $offset = 0;}
	else
		{ $offset=$_REQUEST["offset"]; }
		

		
	if ($_REQUEST["order_by"]=="")
		{ 
		
		$sql_order_by=" order by ".$form_key_id." desc  ";	
		//$order_by=1;
		}
	else
		{ 
		 $sql_order_by=" order by ".$listing_content[$_REQUEST["order_by"]]." "; 
		 $order_by=$_REQUEST["order_by"];
		}
  	
	if ($_REQUEST["sort_by"]=="")
		{ $sql_sort_by = " ";}
	else
		{ 
		 $sql_sort_by=" desc "; 
		 $sort_by=$_REQUEST["sort_by"];
		 }



	



	if ($_REQUEST["search_word"]=="")
		{ 
			$search_word = "";
			//$sql_search=" WHERE xxx=xxx ";	
			
		}
	else
		{
			$search_word = $_REQUEST["search_word"];
			$sql_search="";
			if(isset($listing_search_field))
			{
				foreach($listing_search_field as $field_to_search)
				{
					
					if($sql_search=="")
					{
						$sql_search="  ".$field_to_search." like '%".$_REQUEST["search_word"]."%' ";
					}
					else
					{
						$sql_search=$sql_search." OR  ".$field_to_search." like '%".$_REQUEST["search_word"]."%' ";	
					}
					
					
					
				}
			}
			
			
			if($field_to_search!="")
			{
				$sql_search	= " AND ( ".$sql_search." ) ";
			}
			
			
			
			
		}
	
		
	$query=$query.$sql_search;
	$query=$query.$sql_order_by." ".$sql_sort_by."  ";  
	$display_limit = " LIMIT " . $offset . "," . $limit.";";
    $extraurl=$relation_url."&".$matrix_key_id."=".$_REQUEST[$matrix_key_id]."&order_by=".$order_by."&sort_by=".$sort_by."&search_word=".$search_word."&search_field=".$_REQUEST["search_field"];
	
	$result = mysqli_query($dbconn,$query." ".$display_limit) or die("Listing failed- Err msg  ". mysqli_error($dbconn));
	$num_rows = mysqli_num_rows($result);
	
	
	
	
	
   
        
	
	echo "<section class='view_toolbar'>";
	
    
     if($_REQUEST[$matrix_key_id]=="")
    {
        

        echo "<center>";
            echo "<br>Please select ".$matrix_title."";
        echo "</center>";
        
    }
    else
    {
        
        
		echo "<div class='view_toolbar_search_field'>";
	
			//----search panel and navigation-----------------
			
			echo "<input type='text' class='textbox textbox-full' name=view_search id='matrix_".$matrix_key_id."search_word_".$form_key_id."_".$_REQUEST[$form_key_id]."' value='".$search_word."'> ";
			
			
		
			/*	
			echo "<select id='search_field_".$form_key_id."_".$_REQUEST[$form_key_id]."' class='dropdown dropdown-search'>";
			for($i=1;$i<=count($listing_search_label);$i++)
			{
			 	if($_REQUEST["search_field"]==$i)
			 	{echo "<option value='$i' selected>".$listing_search_label[$i]."</option>";}
			 	else
			 	{echo "<option value='$i' >".$listing_search_label[$i]."</option>";}
				
			}
		
			echo "</select> ";
			
			*/
			
		echo "</div>";
		echo "<div class='view_toolbar_search_button'>";
			
			//echo "<div class='fa-stack fa-lg'  style='cursor:pointer;' onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&search_word='+document.getElementById('matrix_".$matrix_key_id."search_word_".$form_key_id."_".$_REQUEST[$form_key_id]."').value+'&search_field='+document.getElementById('search_field_".$form_key_id."_".$_REQUEST[$form_key_id]."').value,'div_main')\">";
			echo "<div class='fa-stack fa-lg'  style='cursor:pointer;' onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&$matrix_key_id=".$_REQUEST[$matrix_key_id]."&search_word='+document.getElementById('matrix_".$matrix_key_id."search_word_".$form_key_id."_".$_REQUEST[$form_key_id]."').value,'div_main')\">";
				echo '<i class="fa fa-square fa-stack-2x color_blue"  ></i><i class="fa fa-search fa-stack-1x color_white" ></i>';
			echo "</div>";
				
			echo "<div class='fa-stack fa-lg'  style='cursor:pointer;' onclick=\"mon_send_get('".$this_url."','?offset=0".$relation_url."&$matrix_key_id=".$_REQUEST[$matrix_key_id]."','div_main')\">";
				echo '<i class="fa fa-square fa-stack-2x color_grey"  ></i><i class="fa fa-bars fa-stack-1x color_white" ></i>';
			echo "</div>";
			
			
		
		echo "</div>";
		echo "<div class='view_toolbar_action_button'>";
			
				
			
		if($action_cell)
		{
			if(isset($action_button))
			{
				foreach($action_button as $actbtton_id=>$action_button_name)
				{
					//echo "<input type=button  value='".$action_button_name."' class=button onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&search_word='+document.getElementById('matrix_".$matrix_key_id."search_word_".$form_key_id."_".$_REQUEST[$form_key_id]."').value+'&search_field='+document.getElementById('search_field_".$form_key_id."_".$_REQUEST[$form_key_id]."').value+'&action=ACTION".$actbtton_id."&ids='+document.getElementById('id_checbox_list_".$form_key_id."_".$_REQUEST[$form_key_id]."').value,'div_main')\"> ";
						
				}	
			}
					
						
						
			
  
		}
		echo "</div>";
				
	
    
    
    }


			
	echo "</section>";	
			
	    
	
	
	
	
	//=======================End of SYSTEM Script(DO NOT CHANGE)====================

?>

	
	
	
<?php

	//---------EDIT Panel (DO NOT CHANGE)---------------------------
	if(($_REQUEST[$form_key_id]!="")and($_REQUEST["action"]== 'MARK'))
	  		{
	  	
	  		 	$query_get="SELECT * FROM $form_table_name ";
	  		 	$query_get=$query_get." WHERE $form_key_id = '".$_REQUEST[$form_key_id]."';";
	  		 	$result_get=mysqli_query($dbconn,$query_get)or die("Get Data failed- Err msg  ". mysqli_error($dbconn));
	  		  	
	  		 	if($line_get=mysqli_fetch_array($result_get,MYSQLI_ASSOC))
	  		 	{
	  		 	 
					//echo "Addon: ".$_REQUEST[$matrix_key_id];
                    //echo "Product: ".$_REQUEST[$form_key_id];
                    
                    
                    
                    $query_assignment="select * from t_".$key_table_prefix."_addon_assignment
                                        where asg_addon_id = '".$_REQUEST[$matrix_key_id]."'
                                        and asg_product_id = '".$_REQUEST[$form_key_id]."'
                                        
                                        ";
								//and client_id = '".$CurrentUserID."'
                    $result_assignment = mysqli_query($dbconn,$query_assignment);
                    if($line_assignment = mysqli_fetch_array($result_assignment,MYSQLI_ASSOC))
                    {
                        $query_delete="delete from t_".$key_table_prefix."_addon_assignment 
				    			where asg_id = '".$line_assignment["asg_id"]."' ";
                        $result_delete = mysqli_query($dbconn,$query_delete);    
                    }
                    else
                    {
                        
                        
                        $query_insert=" insert into t_".$key_table_prefix."_addon_assignment
                                        (
                                        asg_addon_id,
                                        asg_product_id,
                                        client_id,
                                        created_date,
                                        modified_date
                                        )
                                        values
                                        (
                                        '".$_REQUEST[$matrix_key_id]."',
                                        '".$_REQUEST[$form_key_id]."',
                                        '".$client_id."',
                                        '".date("Y-m-d H:i:s")."',
                                        '".date("Y-m-d H:i:s")."'
                                        
                                        );
                        
                        
                                        ";
                        
                        $result_insert = mysqli_query($dbconn,$query_insert);
                        echo mysqli_error($dbconn);
                        
                        
                    }
                    
                    
                    
                        
						
				}
	  
		
			
			}

?>
	
	
	
	
	
	
<?php


    if($_REQUEST[$matrix_key_id]=="")
    {
        
        
        
    }
    else
    {
        
        
        

	
	echo "<section class='view_content'>";
	
	
				//==================================first row=============================================================
				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;' class='view_list_title_content_object'  >";
									echo "".$listing_header[$i]."<br>";
								echo "</div>";
							}
							
						}
						
					echo "</div>";
					
					
					if($action_cell)
					{
						echo "<div class='view_list_title_content'>";
						echo "</div>";
					}	
				
				echo "</div>";
			
			
			
			
			
			
			
			
				
		//==================================Data row=============================================================	
		$count=$offset;
		while($line=mysqli_fetch_array($result,MYSQLI_ASSOC))
			{
				
		
	 	
				$count=$count+1;
				if($_REQUEST[$form_key_id]==$line[$form_key_id])
				{
					echo "<div class='view_row'>";
				}
				else
				{
					echo "<div class='view_row'>";
				}
				
				
				
					
				//======================================================================================	
					
					
				echo "<div class='view_row_content'>";
					
					
					echo "<div style='min-width:20px;' class='view_row_count'  >";
					echo "".$count."";
					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;' 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[$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>";
					
					
				//======================================================================================
				
				if($action_cell)
					{
						echo "<div class='view_row_button'>";
						
						
                            $query_assignment="select * from t_".$key_table_prefix."_addon_assignment
                                        where asg_addon_id = '".$_REQUEST[$matrix_key_id]."'
                                        and asg_product_id = '".$line[$form_key_id]."'
                                        

                                        ";
								//and client_id = '".$CurrentUserID."'
                            $result_assignment = mysqli_query($dbconn,$query_assignment);
                            if($line_assignment = mysqli_fetch_array($result_assignment,MYSQLI_ASSOC))
                            {
                                echo "<div class='fa-stack fa-lg'  style='cursor:pointer;' onclick=\"mon_next_focus_field='id_".$form_field[1]."';mon_send_get('$this_url','?$matrix_key_id=".$_REQUEST[$matrix_key_id]."&$form_key_id=".$line[$form_key_id]."&action=MARK&offset=".$offset.$extraurl."','div_main')\" >";
                                    echo '<i class="fa fa-square fa-stack-2x "  style="color:#16A085;"   ></i><i class="fa fa-check fa-stack-1x " style="color:#fff;" ></i>';
                                echo "</div>";
                            }
                            else
                            {
                                echo "<div class='fa-stack fa-lg'  style='cursor:pointer;' onclick=\"mon_next_focus_field='id_".$form_field[1]."';mon_send_get('$this_url','?$matrix_key_id=".$_REQUEST[$matrix_key_id]."&$form_key_id=".$line[$form_key_id]."&action=MARK&offset=".$offset.$extraurl."','div_main')\" >";
                                    echo '<i class="fa fa-square fa-stack-2x "  style="color:#DADFE1;"   ></i><i class="fa fa-check fa-stack-1x " style="color:#fff;" ></i>';
                                echo "</div>";
                            }

							

						
						
						/*
						echo "<br>";
						
						echo "<font class='view_row_button_info'>";
							echo "<span class='fa fa-calendar'></span> ".$line["modified_date_f"]." ";	
							//echo "<span class='fa fa-male'></span> <i>Cre: ".mon_get_userfullname($line["created_by"])."</i><br>";
							echo "<span class='fa fa-male'></span> ".mon_get_userfullname($line["modified_by"])."";
						echo "</font>";
						*/
                        
							
						echo "</div>";
					}	
				
				
				
				
				echo "</div>";
			
				
			} 
		
	
	
        
        echo "</section>";
        echo "<section class='view_pager'>";	
            if($count>0)
            {
                recordsetNav($query, $this_url, $offset, $limit, $tablewidth='100%', $verbiage=1, $displaytotal=1, $extraurl, $blocksize=10);
            }
            else
            {
                echo "<font color=#cccccc >No Record</font>";
             
            }
        
        echo "</section>";		
		 echo "<input type=hidden value='' name='checbox_list_".$form_key_id."_".$_REQUEST[$form_key_id]."' id='id_checbox_list_".$form_key_id."_".$_REQUEST[$form_key_id]."' >";
		//====================End of SYSTEM Script(DO NOT CHANGE):View Start==============================
        
        
    }
    
        
        
echo "</form>";
?>



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