<?php
    session_start();
	ob_start();

	$id_users = isset($_SESSION['id_users']) ? $_SESSION['id_users']: "";	
	$nome_user = isset($_SESSION['nome']) ? $_SESSION['nome']: "";	
	$email_users = isset($_SESSION['email']) ? $_SESSION['email']: "";	
	$pass_users = isset($_SESSION['pass']) ? $_SESSION['pass']: "";	
	$logado = isset($_SESSION['logado']) ? $_SESSION['logado']: "N";	

	if ($logado == "N" && $id_users == ""){	    
		echo  "<script type='text/javascript'>
					location.href='login.php'
				</script>";	
		exit();
	}
	
	require 'conexion.php';
    date_default_timezone_set('America/Sao_Paulo');
    $id = $_POST['id'];
    $id_oc = $_POST['id_oc'];	
    $ativo = $_POST['ativo'];
	$obs_grade = $_POST['obs_grade'];
	$atualizado_em = date('d-m-y H:i:s');
	$dir = $_POST['dir'];
    $tituloa1 = $_POST['tituloa1'];
    $tda1 = $_POST['tda1'];
    $tqa1 = $_POST['tqa1'];
    $tsa1 = $_POST['tsa1'];
    $toa1 = $_POST['toa1'];
    $qua1 = $_POST['qua1'];
    $qda1 = $_POST['qda1'];
    $qqa1 = $_POST['qqa1'];
    $qsa1 = $_POST['qsa1'];
    $qoa1 = $_POST['qoa1'];
    $cia1 = $_POST['cia1'];
    $cda1 = $_POST['cda1'];
    $subtotala1 = $_POST['subtotala1'];
    $tituloa2  = $_POST['tituloa2'];
    $tda2 = $_POST['tda2'];
    $tqa2 = $_POST['tqa2'];
    $tsa2 = $_POST['tsa2'];
    $toa2 = $_POST['toa2'];
    $qua2 = $_POST['qua2'];
    $qda2 = $_POST['qda2'];
    $qqa2 = $_POST['qqa2'];
    $qsa2 = $_POST['qsa2'];
    $qoa2 = $_POST['qoa2'];
    $cia2 = $_POST['cia2'];
    $cda2 = $_POST['cda2'];
    $subtotala2 = $_POST['subtotala2'];
    $tituloa3 = $_POST['tituloa3'];
    $tda3 = $_POST['tda3'];
    $tqa3 = $_POST['tqa3'];
    $tsa3 = $_POST['tsa3'];
    $toa3 = $_POST['toa3'];
    $qua3 = $_POST['qua3'];
    $qda3 = $_POST['qda3'];
    $qqa3 = $_POST['qqa3'];
    $qsa3 = $_POST['qsa3'];
    $qoa3 = $_POST['qoa3'];
    $cia3 = $_POST['cia3'];
    $cda3 = $_POST['cda3'];
    $subtotala3 = $_POST['subtotala3'];
    $tituloa4 = $_POST['tituloa4'];
    $tda4 = $_POST['tda4'];
    $tqa4 = $_POST['tqa4'];
    $tsa4 = $_POST['tsa4'];
    $toa4 = $_POST['toa4'];
    $qua4 = $_POST['qua4'];
    $qda4 = $_POST['qda4'];
    $qqa4 = $_POST['qqa4'];
    $qsa4 = $_POST['qsa4'];
    $qoa4 = $_POST['qoa4'];
    $cia4 = $_POST['cia4'];
    $cda4 = $_POST['cda4'];
    $subtotala4 = $_POST['subtotala4'];
    $tituloa5 = $_POST['tituloa5'];
    $tda5 = $_POST['tda5'];
    $tqa5 = $_POST['tqa5'];
    $tsa5 = $_POST['tsa5'];
    $toa5 = $_POST['toa5'];
    $qua5 = $_POST['qua5'];
    $qda5 = $_POST['qda5'];
    $qqa5 = $_POST['qqa5'];
    $qsa5 = $_POST['qsa5'];
    $qoa5 = $_POST['qoa5'];
    $cia5 = $_POST['cia5'];
    $cda5 = $_POST['cda5'];
    $subtotala5 = $_POST['subtotala5'];
    $tituloa6 = $_POST['tituloa6'];
    $tda6 = $_POST['tda6'];
    $tqa6 = $_POST['tqa6'];
    $tsa6 = $_POST['tsa6'];
    $toa6 = $_POST['toa6'];
    $qua6 = $_POST['qua6'];
    $qda6 = $_POST['qda6'];
    $qqa6 = $_POST['qqa6'];
    $qsa6 = $_POST['qsa6'];
    $qoa6 = $_POST['qoa6'];
    $cia6 = $_POST['cia6'];
    $cda6 = $_POST['cda6'];
    $subtotala6 = $_POST['subtotala6'];
    $tituloa7 = $_POST['tituloa7'];
    $tda7 = $_POST['tda7'];
    $tqa7 = $_POST['tqa7'];
    $tsa7 = $_POST['tsa7'];
    $toa7 = $_POST['toa7'];
    $qua7 = $_POST['qua7'];
    $qda7 = $_POST['qda7'];
    $qqa7 = $_POST['qqa7'];
    $qsa7 = $_POST['qsa7'];
    $qoa7 = $_POST['qoa7'];
    $cia7 = $_POST['cia7'];
    $cda7 = $_POST['cda7'];
    $subtotala7 = $_POST['subtotala7'];
    $tituloa8 = $_POST['tituloa8'];
    $tda8 = $_POST['tda8'];
    $tqa8 = $_POST['tqa8'];
    $tsa8 = $_POST['tsa8'];
    $toa8 = $_POST['toa8'];
    $qua8 = $_POST['qua8'];
    $qda8 = $_POST['qda8'];
    $qqa8 = $_POST['qqa8'];
    $qsa8 = $_POST['qsa8'];
    $qoa8 = $_POST['qoa8'];
    $cia8 = $_POST['cia8'];
    $cda8 = $_POST['cda8'];
    $subtotala8 = $_POST['subtotala8'];
    $tituloa9 = $_POST['tituloa9'];
    $tda9 = $_POST['tda9'];
    $tqa9 = $_POST['tqa9'];
    $tsa9 = $_POST['tsa9'];
    $toa9 = $_POST['toa9'];
    $qua9 = $_POST['qua9'];
    $qda9 = $_POST['qda9'];
    $qqa9 = $_POST['qqa9'];
    $qsa9 = $_POST['qsa9'];
    $qoa9 = $_POST['qoa9'];
    $cia9 = $_POST['cia9'];
    $cda9 = $_POST['cda9'];
    $subtotala9 = $_POST['subtotala9'];
    $somatda = $_POST['somatda'];
    $somatqa = $_POST['somatqa'];  
    $somatsa = $_POST['somatsa'];  
    $somatoa = $_POST['somatoa'];  
    $somaqua = $_POST['somaqua'];  
    $somaqda = $_POST['somaqda'];  
    $somaqqa = $_POST['somaqqa'];  
    $somaqsa = $_POST['somaqsa'];  
    $somaqoa = $_POST['somaqoa'];  
    $somacia = $_POST['somacia'];  
    $somacda = $_POST['somacda'];  
    $somagerala = $_POST['somagerala'];      

    $titulob1 = $_POST['titulob1'];
    $tdb1 = $_POST['tdb1'];
    $tqb1 = $_POST['tqb1'];
    $tsb1 = $_POST['tsb1'];
    $tob1 = $_POST['tob1'];
    $qub1 = $_POST['qub1'];
    $qdb1 = $_POST['qdb1'];
    $qqb1 = $_POST['qqb1'];
    $qsb1 = $_POST['qsb1'];
    $qob1 = $_POST['qob1'];
    $cib1 = $_POST['cib1'];
    $cdb1 = $_POST['cdb1'];
    $subtotalb1 = $_POST['subtotalb1'];
    $titulob2 = $_POST['titulob2'];
    $tdb2 = $_POST['tdb2'];
    $tqb2 = $_POST['tqb2'];
    $tsb2 = $_POST['tsb2'];
    $tob2 = $_POST['tob2'];
    $qub2 = $_POST['qub2'];
    $qdb2 = $_POST['qdb2'];
    $qqb2 = $_POST['qqb2'];
    $qsb2 = $_POST['qsb2'];
    $qob2 = $_POST['qob2'];
    $cib2 = $_POST['cib2'];
    $cdb2 = $_POST['cdb2'];
    $subtotalb2 = $_POST['subtotalb2'];
    $titulob3 = $_POST['titulob3'];
    $tdb3 = $_POST['tdb3'];
    $tqb3 = $_POST['tqb3'];
    $tsb3 = $_POST['tsb3'];
    $tob3 = $_POST['tob3'];
    $qub3 = $_POST['qub3'];
    $qdb3 = $_POST['qdb3'];
    $qqb3 = $_POST['qqb3'];
    $qsb3 = $_POST['qsb3'];
    $qob3 = $_POST['qob3'];
    $cib3 = $_POST['cib3'];
    $cdb3 = $_POST['cdb3'];
    $subtotalb3 = $_POST['subtotalb3'];
    $titulob4 = $_POST['titulob4'];
    $tdb4 = $_POST['tdb4'];
    $tqb4 = $_POST['tqb4'];
    $tsb4 = $_POST['tsb4'];
    $tob4 = $_POST['tob4'];
    $qub4 = $_POST['qub4'];
    $qdb4 = $_POST['qdb4'];
    $qqb4 = $_POST['qqb4'];
    $qsb4 = $_POST['qsb4'];
    $qob4 = $_POST['qob4'];
    $cib4 = $_POST['cib4'];
    $cdb4 = $_POST['cdb4'];
    $subtotalb4 = $_POST['subtotalb4'];
    $titulob5 = $_POST['titulob5'];
    $tdb5 = $_POST['tdb5'];
    $tqb5 = $_POST['tqb5'];
    $tsb5 = $_POST['tsb5'];
    $tob5 = $_POST['tob5'];
    $qub5 = $_POST['qub5'];
    $qdb5 = $_POST['qdb5'];
    $qqb5 = $_POST['qqb5'];
    $qsb5 = $_POST['qsb5'];
    $qob5 = $_POST['qob5'];
    $cib5 = $_POST['cib5'];
    $cdb5 = $_POST['cdb5'];
    $subtotalb5 = $_POST['subtotalb5'];
	
    $somatdb = $_POST['somatdb'];
    $somatqb = $_POST['somatqb'];  
    $somatsb = $_POST['somatsb'];  
    $somatob = $_POST['somatob'];  
    $somaqub = $_POST['somaqub'];  
    $somaqdb = $_POST['somaqdb'];  
    $somaqqb = $_POST['somaqqb'];  
    $somaqsb = $_POST['somaqsb'];  
    $somaqob = $_POST['somaqob'];  
    $somacib = $_POST['somacib'];  
    $somacdb = $_POST['somacdb'];  
    $somageralb = $_POST['somageralb'];
    
    $tituloc1 = $_POST['tituloc1'];
    $tdc1 = $_POST['tdc1'];
    $tqc1 = $_POST['tqc1'];
    $tsc1 = $_POST['tsc1'];
    $toc1 = $_POST['toc1'];
    $quc1 = $_POST['quc1'];
    $qdc1 = $_POST['qdc1'];
    $qqc1 = $_POST['qqc1'];
    $qsc1 = $_POST['qsc1'];
    $qoc1 = $_POST['qoc1'];
    $cic1 = $_POST['cic1'];
    $cdc1 = $_POST['cdc1'];
    $subtotalc1 = $_POST['subtotalc1'];
    $tituloc2 = $_POST['tituloc2'];
    $tdc2 = $_POST['tdc2'];
    $tqc2 = $_POST['tqc2'];
    $tsc2 = $_POST['tsc2'];
    $toc2 = $_POST['toc2'];
    $quc2 = $_POST['quc2'];
    $qdc2 = $_POST['qdc2'];
    $qqc2 = $_POST['qqc2'];
    $qsc2 = $_POST['qsc2'];
    $qoc2 = $_POST['qoc2'];
    $cic2 = $_POST['cic2'];
    $cdc2 = $_POST['cdc2'];
    $subtotalc2 = $_POST['subtotalc2'];
    $tituloc3 = $_POST['tituloc3'];
    $tdc3 = $_POST['tdc3'];
    $tqc3 = $_POST['tqc3'];
    $tsc3 = $_POST['tsc3'];
    $toc3 = $_POST['toc3'];
    $quc3 = $_POST['quc3'];
    $qdc3 = $_POST['qdc3'];
    $qqc3 = $_POST['qqc3'];
    $qsc3 = $_POST['qsc3'];
    $qoc3 = $_POST['qoc3'];
    $cic3 = $_POST['cic3'];
    $cdc3 = $_POST['cdc3'];
    $subtotalc3 = $_POST['subtotalc3'];
    $tituloc4 = $_POST['tituloc4'];
    $tdc4 = $_POST['tdc4'];
    $tqc4 = $_POST['tqc4'];
    $tsc4 = $_POST['tsc4'];
    $toc4 = $_POST['toc4'];
    $quc4 = $_POST['quc4'];
    $qdc4 = $_POST['qdc4'];
    $qqc4 = $_POST['qqc4'];
    $qsc4 = $_POST['qsc4'];
    $qoc4 = $_POST['qoc4'];
    $cic4 = $_POST['cic4'];
    $cdc4 = $_POST['cdc4'];
    $subtotalc4 = $_POST['subtotalc4'];  
    $tituloc5 = $_POST['tituloc5'];
    $tdc5 = $_POST['tdc5'];
    $tqc5 = $_POST['tqc5'];
    $tsc5 = $_POST['tsc5'];
    $toc5 = $_POST['toc5'];
    $quc5 = $_POST['quc5'];
    $qdc5 = $_POST['qdc5'];
    $qqc5 = $_POST['qqc5'];
    $qsc5 = $_POST['qsc5'];
    $qoc5 = $_POST['qoc5'];
    $cic5 = $_POST['cic5'];
    $cdc5 = $_POST['cdc5'];
    $subtotalc5 = $_POST['subtotalc5'];    
    $somatdc = $_POST['somatdcx'];
    $somatqc = $_POST['somatqcx'];  
    $somatsc = $_POST['somatscx'];  
    $somatoc = $_POST['somatocx'];  
    $somaquc = $_POST['somaqucx'];  
    $somaqdc = $_POST['somaqdcx'];  
    $somaqqc = $_POST['somaqqcx'];  
    $somaqsc = $_POST['somaqscx'];  
    $somaqoc = $_POST['somaqocx'];  
    $somacic = $_POST['somacicx'];  
    $somacdc = $_POST['somacdcx'];  
    $somageralc = $_POST['somageralcx'];                

    $titulod1 = $_POST['titulod1'];
    $tdd1 = $_POST['tdd1'];
    $tqd1 = $_POST['tqd1'];
    $tsd1 = $_POST['tsd1'];
    $tod1 = $_POST['tod1'];
    $qud1 = $_POST['qud1'];
    $qdd1 = $_POST['qdd1'];
    $qqd1 = $_POST['qqd1'];
    $qsd1 = $_POST['qsd1'];
    $qod1 = $_POST['qod1'];
    $cid1 = $_POST['cid1'];
    $cdd1 = $_POST['cdd1'];
    $subtotald1 = $_POST['subtotald1'];
    $titulod2 = $_POST['titulod2'];
    $tdd2 = $_POST['tdd2'];
    $tqd2 = $_POST['tqd2'];
    $tsd2 = $_POST['tsd2'];
    $tod2 = $_POST['tod2'];
    $qud2 = $_POST['qud2'];
    $qdd2 = $_POST['qdd2'];
    $qqd2 = $_POST['qqd2'];
    $qsd2 = $_POST['qsd2'];
    $qod2 = $_POST['qod2'];
    $cid2 = $_POST['cid2'];
    $cdd2 = $_POST['cdd2'];
    $subtotald2 = $_POST['subtotald2'];
    $titulod3 = $_POST['titulod3'];
    $tdd3 = $_POST['tdd3'];
    $tqd3 = $_POST['tqd3'];
    $tsd3 = $_POST['tsd3'];
    $tod3 = $_POST['tod3'];
    $qud3 = $_POST['qud3'];
    $qdd3 = $_POST['qdd3'];
    $qqd3 = $_POST['qqd3'];
    $qsd3 = $_POST['qsd3'];
    $qod3 = $_POST['qod3'];
    $cid3 = $_POST['cid3'];
    $cdd3 = $_POST['cdd3'];
    $subtotald3 = $_POST['subtotald3'];
    $titulod4 = $_POST['titulod4'];
    $tdd4 = $_POST['tdd4'];
    $tqd4 = $_POST['tqd4'];
    $tsd4 = $_POST['tsd4'];
    $tod4 = $_POST['tod4'];
    $qud4 = $_POST['qud4'];
    $qdd4 = $_POST['qdd4'];
    $qqd4 = $_POST['qqd4'];
    $qsd4 = $_POST['qsd4'];
    $qod4 = $_POST['qod4'];
    $cid4 = $_POST['cid4'];
    $cdd4 = $_POST['cdd4'];
    $subtotald4 = $_POST['subtotald4'];  
    $titulod5 = $_POST['titulod5'];
    $tdd5 = $_POST['tdd5'];
    $tqd5 = $_POST['tqd5'];
    $tsd5 = $_POST['tsd5'];
    $tod5 = $_POST['tod5'];
    $qud5 = $_POST['qud5'];
    $qdd5 = $_POST['qdd5'];
    $qqd5 = $_POST['qqd5'];
    $qsd5 = $_POST['qsd5'];
    $qod5 = $_POST['qod5'];
    $cid5 = $_POST['cid5'];
    $cdd5 = $_POST['cdd5'];
    $subtotald5 = $_POST['subtotald5'];
    $titulod6 = $_POST['titulod6'];
    $tdd6 = $_POST['tdd6'];
    $tqd6 = $_POST['tqd6'];
    $tsd6 = $_POST['tsd6'];
    $tod6 = $_POST['tod6'];
    $qud6 = $_POST['qud6'];
    $qdd6 = $_POST['qdd6'];
    $qqd6 = $_POST['qqd6'];
    $qsd6 = $_POST['qsd6'];
    $qod6 = $_POST['qod6'];
    $cid6 = $_POST['cid6'];
    $cdd6 = $_POST['cdd6'];
    $subtotald6 = $_POST['subtotald6'];    
    $titulod7 = $_POST['titulod7'];
    $tdd7 = $_POST['tdd7'];
    $tqd7 = $_POST['tqd7'];
    $tsd7 = $_POST['tsd7'];
    $tod7 = $_POST['tod7'];
    $qud7 = $_POST['qud7'];
    $qdd7 = $_POST['qdd7'];
    $qqd7 = $_POST['qqd7'];
    $qsd7 = $_POST['qsd7'];
    $qod7 = $_POST['qod7'];
    $cid7 = $_POST['cid7'];
    $cdd7 = $_POST['cdd7'];
    $subtotald7 = $_POST['subtotald7'];    
    
    $somatdd = $_POST['somatdd'];
    $somatqd = $_POST['somatqd'];  
    $somatsd = $_POST['somatsd'];  
    $somatod = $_POST['somatod'];  
    $somaqud = $_POST['somaqud'];  
    $somaqdd = $_POST['somaqdd'];  
    $somaqqd = $_POST['somaqqd'];  
    $somaqsd = $_POST['somaqsd'];  
    $somaqod = $_POST['somaqod'];  
    $somacid = $_POST['somacid'];  
    $somacdd = $_POST['somacdd'];  
    $somagerald = $_POST['somagerald'];                
    $obs_grade_fim = $_POST['obs_grade_fim'];
    
    $sql = "UPDATE grade SET obs_grade=(UPPER('$obs_grade')),ativo='$ativo', atualizado_em='$atualizado_em',tituloa1=(UPPER('$tituloa1')),tda1='$tda1',tqa1='$tqa1',tsa1='$tsa1',toa1='$toa1',qua1='$qua1',qda1='$qda1',qqa1='$qqa1',qsa1='$qsa1',qoa1='$qoa1',cia1='$cia1',cda1='$cda1',subtotala1='$subtotala1', tituloa2=(UPPER('$tituloa2')),tda2='$tda2',tqa2='$tqa2',tsa2='$tsa2',toa2='$toa2',qua2='$qua2',qda2='$qda2',qqa2='$qqa2',qsa2='$qsa2',qoa2='$qoa2',cia2='$cia2',cda2='$cda2',subtotala2='$subtotala2',tituloa3=(UPPER('$tituloa3')),tda3='$tda3',tqa3='$tqa3',tsa3='$tsa3',toa3='$toa3',qua3='$qua3',qda3='$qda3',qqa3='$qqa3',qsa3='$qsa3',qoa3='$qoa3',cia3='$cia3',cda3='$cda3',subtotala3='$subtotala3', tituloa4=(UPPER('$tituloa4')),tda4='$tda4',tqa4='$tqa4',tsa4='$tsa4',toa4='$toa4',qua4='$qua4',qda4='$qda4',qqa4='$qqa4',qsa4='$qsa4',qoa4='$qoa4',cia4='$cia4',cda4='$cda4',subtotala4='$subtotala4',tituloa5=(UPPER('$tituloa5')),tda5='$tda5',tqa5='$tqa5',tsa5='$tsa5',toa5='$toa5',qua5='$qua5',qda5='$qda5',qqa5='$qqa5',qsa5='$qsa5',qoa5='$qoa5',cia5='$cia5',cda5='$cda5',subtotala5='$subtotala5',tituloa6=(UPPER('$tituloa6')),tda6='$tda6',tqa6='$tqa6',tsa6='$tsa6',toa6='$toa6',qua6='$qua6',qda6='$qda6',qqa6='$qqa6',qsa6='$qsa6',qoa6='$qoa6',cia6='$cia6',cda6='$cda6',subtotala6='$subtotala6',tituloa7=(UPPER('$tituloa7')),tda7='$tda7',tqa7='$tqa7',tsa7='$tsa7',toa7='$toa7',qua7='$qua7',qda7='$qda7',qqa7='$qqa7',qsa7='$qsa7',qoa7='$qoa7',cia7='$cia7',cda7='$cda7',subtotala7='$subtotala7',tituloa8=(UPPER('$tituloa8')),tda8='$tda8',tqa8='$tqa8',tsa8='$tsa8',toa8='$toa8',qua8='$qua8',qda8='$qda8',qqa8='$qqa8',qsa8='$qsa8',qoa8='$qoa8',cia8='$cia8',cda8='$cda8',subtotala8='$subtotala8',tituloa9=(UPPER('$tituloa9')),tda9='$tda9',tqa9='$tqa9',tsa9='$tsa9',toa9='$toa9',qua9='$qua9',qda9='$qda9',qqa9='$qqa9',qsa9='$qsa9',qoa9='$qoa9',cia9='$cia9',cda9='$cda9',subtotala9='$subtotala9',titulob1=(UPPER('$titulob1')),tdb1='$tdb1',tqb1='$tqb1',tsb1='$tsb1',tob1='$tob1',qub1='$qub1',qdb1='$qdb1',qqb1='$qqb1',qsb1='$qsb1',qob1='$qob1',cib1='$cib1',cdb1='$cdb1',subtotalb1='$subtotalb1',titulob2=(UPPER('$titulob2')),tdb2='$tdb2',tqb2='$tqb2',tsb2='$tsb2',tob2='$tob2',qub2='$qub2',qdb2='$qdb2',qqb2='$qqb2',qsb2='$qsb2',qob2='$qob2',cib2='$cib2',cdb2='$cdb2',subtotalb2='$subtotalb2',titulob3=(UPPER('$titulob3')),tdb3='$tdb3',tqb3='$tqb3',tsb3='$tsb3',tob3='$tob3',qub3='$qub3',qdb3='$qdb3',qqb3='$qqb3',qsb3='$qsb3',qob3='$qob3',cib3='$cib3',cdb3='$cdb3',subtotalb3='$subtotalb3',titulob4=(UPPER('$titulob4')),tdb4='$tdb4',tqb4='$tqb4',tsb4='$tsb4',tob4='$tob4',qub4='$qub4',qdb4='$qdb4',qqb4='$qqb4',qsb4='$qsb4',qob4='$qob4',cib4='$cib4',cdb4='$cdb4',subtotalb4='$subtotalb4',titulob5=(UPPER('$titulob5')),tdb5='$tdb5',tqb5='$tqb5',tsb5='$tsb5',tob5='$tob5',qub5='$qub5',qdb5='$qdb5',qqb5='$qqb5',qsb5='$qsb5',qob5='$qob5',cib5='$cib5',cdb5='$cdb5',subtotalb5='$subtotalb5', tituloc1=(UPPER('$tituloc1')),tdc1='$tdc1',tqc1='$tqc1',tsc1='$tsc1',toc1='$toc1',quc1='$quc1',qdc1='$qdc1',qqc1='$qqc1',qsc1='$qsc1',qoc1='$qoc1',cic1='$cic1',cdc1='$cdc1',subtotalc1='$subtotalc1',tituloc2=(UPPER('$tituloc2')),tdc2='$tdc2',tqc2='$tqc2',tsc2='$tsc2',toc2='$toc2',quc2='$quc2',qdc2='$qdc2',qqc2='$qqc2',qsc2='$qsc2',qoc2='$qoc2',cic2='$cic2',cdc2='$cdc2',subtotalc2='$subtotalc2',tituloc3=(UPPER('$tituloc3')),tdc3='$tdc3',tqc3='$tqc3',tsc3='$tsc3',toc3='$toc3',quc3='$quc3',qdc3='$qdc3',qqc3='$qqc3',qsc3='$qsc3',qoc3='$qoc3',cic3='$cic3',cdc3='$cdc3',subtotalc3='$subtotalc3',tituloc4=(UPPER('$tituloc4')),tdc4='$tdc4',tqc4='$tqc4',tsc4='$tsc4',toc4='$toc4',quc4='$quc4',qdc4='$qdc4',qqc4='$qqc4',qsc4='$qsc4',qoc4='$qoc4',cic4='$cic4',cdc4='$cdc4',subtotalc4='$subtotalc4',tituloc5=(UPPER('$tituloc5')),tdc5='$tdc5',tqc5='$tqc5',tsc5='$tsc5',toc5='$toc5',quc5='$quc5',qdc5='$qdc5',qqc5='$qqc5',qsc5='$qsc5',qoc5='$qoc5',cic5='$cic5',cdc5='$cdc5',subtotalc5='$subtotalc5', titulod1=(UPPER('$titulod1')),tdd1='$tdd1',tqd1='$tqd1',tsd1='$tsd1',tod1='$tod1',qud1='$qud1',qdd1='$qdd1',qqd1='$qqd1',qsd1='$qsd1',qod1='$qod1',cid1='$cid1',cdd1='$cdd1',subtotald1='$subtotald1',titulod2=(UPPER('$titulod2')),tdd2='$tdd2',tqd2='$tqd2',tsd2='$tsd2',tod2='$tod2',qud2='$qud2',qdd2='$qdd2',qqd2='$qqd2',qsd2='$qsd2',qod2='$qod2',cid2='$cid2',cdd2='$cdd2',subtotald2='$subtotald2',titulod3=(UPPER('$titulod3')),tdd3='$tdd3',tqd3='$tqd3',tsd3='$tsd3',tod3='$tod3',qud3='$qud3',qdd3='$qdd3',qqd3='$qqd3',qsd3='$qsd3',qod3='$qod3',cid3='$cid3',cdd3='$cdd3',subtotald3='$subtotald3',titulod4=(UPPER('$titulod4')),tdd4='$tdd4',tqd4='$tqd4',tsd4='$tsd4',tod4='$tod4',qud4='$qud4',qdd4='$qdd4',qqd4='$qqd4',qsd4='$qsd4',qod4='$qod4',cid4='$cid4',cdd4='$cdd4',subtotald4='$subtotald4',titulod5=(UPPER('$titulod5')),tdd5='$tdd5',tqd5='$tqd5',tsd5='$tsd5',tod5='$tod5',qud5='$qud5',qdd5='$qdd5',qqd5='$qqd5',qsd5='$qsd5',qod5='$qod5',cid5='$cid5',cdd5='$cdd5',subtotald5='$subtotald5' ,somatda='$somatda',somatqa='$somatqa',somatsa='$somatsa',somatoa='$somatoa',somaqua='$somaqua',somaqda='$somaqda',somaqqa='$somaqqa',somaqsa='$somaqsa',somaqoa='$somaqoa',somacia='$somacia',somacda='$somacda',somagerala='$somagerala',somatdb='$somatdb',somatqb='$somatqb',somatsb='$somatsb',somatob='$somatob',somaqub='$somaqub',somaqdb='$somaqdb',somaqqb='$somaqqb',somaqsb='$somaqsb',somaqob='$somaqob',somacib='$somacib',somacdb='$somacdb',somageralb='$somageralb',somatdc='$somatdc',somatqc='$somatqc',somatsc='$somatsc',somatoc='$somatoc',somaquc='$somaquc',somaqdc='$somaqdc',somaqqc='$somaqqc',somaqsc='$somaqsc',somaqoc='$somaqoc',somacic='$somacic',somacdc='$somacdc',somageralc='$somageralc', somatdd='$somatdd',somatqd='$somatqd',somatsd='$somatsd',somatod='$somatod',somaqud='$somaqud',somaqdd='$somaqdd',somaqqd='$somaqqd',somaqsd='$somaqsd',somaqod='$somaqod',somacid='$somacid',somacdd='$somacdd',somagerald='$somagerald' WHERE grade.id_pedido='$id' and grade.dir='1'";
    $resultado = $mysqli->query($sql);

    $sql2 = "UPDATE grade_fim SET apontador='$nome_user', id_oc='$id_oc',obs_grade_fim='$obs_grade_fim',apontamento='$atualizado_em', titulod6='$titulod6', tdd6='$tdd6', tqd6='$tqd6', tsd6='$tsd6', tod6='$tod6', qud6='$qud6', qdd6='$qdd6', qqd6='$qqd6', qsd6='$qsd6', qod6='$qod6', cid6='$cid6', cdd6='$cdd6', subtotald6='$subtotald6', titulod7='$titulod7', tdd7='$tdd7', tqd7='$tqd7', tsd7='$tsd7', tod7='$tod7', qud7='$qud7', qdd7='$qdd7', qqd7='$qqd7', qsd7='$qsd7', qod7='$qod7', cid7='$cid7', cdd7='$cdd7', subtotald7='$subtotald7', somagerald='$somagerald', somacdd='$somacdd', somacid='$somacid', somaqod='$somaqod', somaqsd='$somaqsd', somaqqd='$somaqqd', somaqdd='$somaqdd', somaqud='$somaqud', somatod='$somatod', somatsd='$somatsd', somatqd='$somatqd', somatdd='$somatdd'  WHERE id_pedido='$id'";
	$resultado2 = $mysqli->query($sql2);	

	//echo $sql2;
?>
<?php
	IF ($somagerald == 0 ) {
?>
    <META HTTP-EQUIV=REFRESH CONTENT = '0;URL=oc_index.php'>
<?php
	} ELSE {

	$fecha = "SELECT
				pedidos.id AS pedidoID,
				ordem_corte.id_oc AS ocID,
				producao.id_producao AS producaoID,
				grade.id_grade AS gradeID,
				grade.somagerala,
				grade.somageralb			
			FROM
				producao
				INNER JOIN ordem_corte ON producao.id_oc = ordem_corte.id_oc
				INNER JOIN pedidos ON ordem_corte.id_pedido = pedidos.id
				INNER JOIN grade ON pedidos.id = grade.id_pedido
			WHERE
				pedidos.id = '$id' AND producao.ativo = '1'";
						
		$res = $mysqli->query($fecha);
		$row = $res->fetch_array(MYSQLI_ASSOC);
		
		$idProd = $row['producaoID'];
		
		$totalizacaoGrade = (int)$row['somagerala'];
	
		IF ( $somagerald >= $totalizacaoGrade ) {										
			$upd = "UPDATE producao SET producao_fim = '$atualizado_em' WHERE id_producao = '$idProd'";
			$fim = $mysqli->query($upd);
		}
		
?>	
		<META HTTP-EQUIV=REFRESH CONTENT = '0;URL=apontamento_index.php?id=0&filter=1&route=0'>
<?php
	}
?>
