<?php
include("../../db.php");
error_reporting(E_ALL);
header("Access-Control-Allow-Origin: * ");

	 
          
         $abc=$_POST['json'];
   // print_r($abc);
    
 $idata=json_decode($abc,true);

          $is_new_head = $idata['is_new_head'];
           $head_id = $idata['head_id'];
             $head = $idata['head'];
             $image_list=$idata['image_list'];
             $session= $idata['session'];
           $school_id= $idata['school_id'];
          
           $Added_by= $idata['added_by'];
           
            
          // $date=date("Y-m-d");
                  
if($is_new_head=="1")
{
    
 //echo $is_new_head;  
  $aryData=array(
		 "head"=>$head,
		 "status"=>1,
		 "school_id"=>$school_id,
		 "added_by"=>$Added_by
	            );
 	 	
  		$insert_complain=$db->insertAry("image_head",$aryData);
  
  //$last_id=mysql_query->insert_id();
//   $last_id= mysql_insert_id();

$last_id = $insert_complain;
  	
	foreach($image_list as $x => $x_value) {		
	  $aryData=array(
         "head"=>$last_id,
	 	 "image_name"=>$x_value
	            );
 	 	
	 	
  		$insert_complain=$db->insertAry("image_upload",$aryData);
  		
			}
				   
    
    
}


else

{

	foreach($image_list as $x => $x_value) {		
	  $aryData=array(
         "head"=>$head_id,
	 	 "image_name"=>$x_value
	            );
 	 	
	 	
 	 	//print_r($aryData);
  		$insert_complain=$db->insertAry("image_upload",$aryData);
  		
			}
			
}
  		 
  if($insert_complain>0){ 
  
  $msg="Gallery Added successfully.!";
  

  	  

  
  }
  
	
	if($msg!="")
	{  
		echo json_encode(array('status' => 1, 'msg'=>'Done', "data"=>$msg));    
			
	}
	else
	{		
	 	echo json_encode(array('status' => 0, 'msg'=>'Gallery not Added. Please try again later..!'));
	}
