<?php
	include_once('../config.php');   
                        
                  
    
	 
								
					if(isset($_POST['addCity_names']))
					{      
						  
						$stmt=$conn->prepare("select recDate  from myworks   where randNo=:randNo");     
						$stmt->bindValue(':randNo', $_POST['randNo'] , PDO::PARAM_STR);
						$stmt->execute();
						$randNo = $stmt->fetch(PDO::FETCH_OBJ);  
						$originalDate = $randNo->recDate;	   
						
						$dat = date('M-Y', strtotime($originalDate . ' -3 months')); 
						$stmt=$conn->prepare("select indexval,source  from pw__exclationtbl1   where commodity=:commodity and dateselect like '%$dat%' ");     
						$stmt->bindValue(':commodity', $_POST['commodity'] , PDO::PARAM_STR);
						$stmt->execute();
						$month = $stmt->fetchAll(PDO::FETCH_OBJ);
						
						$ival = 0;
						$sr=0; 
						
						foreach($month as $mpp)
						{	    
							 
							$ival +=$mpp->indexval;
							$sr++;
						}
						 
						
						$ary['ival1'] =  $ival/$sr;
						$ary['source1'] =  $mpp->source;  
						$ary['mon1'] =  $dat;
						
						$dat = date('M-Y', strtotime($originalDate . ' -2 months'));
						$stmt=$conn->prepare("select indexval,source from pw__exclationtbl1   where commodity=:commodity and dateselect like '%$dat%' ");     
						$stmt->bindValue(':commodity', $_POST['commodity'] , PDO::PARAM_STR);
						$stmt->execute();
						$month = $stmt->fetchAll(PDO::FETCH_OBJ);
						
						$ival = 0;
						$sr=0;
						foreach($month as $mpp)
						{	    
							$ival +=$mpp->indexval;
							$sr++;
						}
						
						$ary['ival2'] =  $ival/$sr;
						$ary['source2'] =  $mpp->source;  
						$ary['mon2'] =  $dat;
						
						$dat = date('M-Y', strtotime($originalDate . ' -1 months'));
						$stmt=$conn->prepare("select indexval,source  from pw__exclationtbl1   where commodity=:commodity and dateselect like '%$dat%' ");     
						$stmt->bindValue(':commodity', $_POST['commodity'] , PDO::PARAM_STR);
						$stmt->execute();
						$month = $stmt->fetchAll(PDO::FETCH_OBJ);
						$ival = 0;
						$sr=0;
						foreach($month as $mpp)
						{	    
							$ival +=$mpp->indexval;
							$sr++;
						} 
						
						$ary['ival3'] =  $ival/$sr;
						$ary['source3'] =  $mpp->source;  
						$ary['mon3'] =  $dat;
						 
						echo json_encode($ary);
						die;   
					}
	
    if(isset($_POST['delRecord']))
    { 
        $stmt=$conn->prepare("delete from   MyWorks where id=:id");     
        $stmt->bindValue(':id', $_POST['val'] , PDO::PARAM_STR);
        $stmt->execute();
        //$SysAllot = $stmt->fetch(PDO::FETCH_OBJ); 
    }    